1 ;;; Mudsync --- Live hackable MUD
2 ;;; Copyright © 2016 Christopher Allan Webber <cwebber@dustycloud.org>
4 ;;; This file is part of Mudsync.
6 ;;; Mudsync is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or
9 ;;; (at your option) any later version.
11 ;;; Mudsync is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;; General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with Mudsync. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (mudsync command)
20 #:use-module (mudsync parser)
21 #:use-module (8sync systems actors)
22 #:use-module (srfi srfi-1)
23 #:use-module (srfi srfi-9)
24 #:use-module (ice-9 control)
25 #:use-module (ice-9 match)
36 indir-as-direct-command
42 player-gather-command-handlers
48 (define %low-priority 0)
49 (define %default-priority 1)
50 (define %high-priority 2)
52 ;; ;;; Avoiding some annoying issues crossing the continuation barrier
53 ;; ;;; and the "@@" special form
54 ;; (define (make-command verbs matcher should-handle action priority)
55 ;; (list '*command* verbs matcher should-handle action priority))
57 ;; (define command-verbs second)
58 ;; (define command-matcher third)
59 ;; (define command-should-handle fourth)
60 ;; (define command-action fifth)
61 ;; (define command-priority sixth)
63 (define-record-type <command>
64 (make-command verbs matcher should-handle action priority)
67 (matcher command-matcher)
68 (should-handle command-should-handle)
69 (action command-action)
70 (priority command-priority))
73 (define (direct-command verbs action)
76 ;; @@: Should we allow fancier matching than this?
77 ;; Let the actor itself pass along this whole method?
78 (lambda* (goes-by #:key direct-obj)
79 (member direct-obj goes-by))
83 (define (loose-direct-command verbs action)
86 ;; @@: Should we allow fancier matching than this?
87 ;; Let the actor itself pass along this whole method?
93 (define* (indir-command verbs action #:optional prepositions)
96 (lambda* (goes-by #:key direct-obj indir-obj preposition)
99 (member indir-obj goes-by)
100 (member preposition prepositions))
101 (member indir-obj goes-by)))
105 (define* (indir-as-direct-command verbs action #:optional prepositions)
108 (lambda* (goes-by #:key direct-obj indir-obj preposition)
111 (member direct-obj goes-by)
112 (member preposition prepositions))
113 (member direct-obj goes-by)))
117 (define* (loose-indir-command verbs action #:optional prepositions)
125 (define (empty-command verbs action)
132 (define (greedy-command verbs action)
139 (define (direct-greedy-command verbs action)
140 "greedy commands but which match the direct object"
142 cmatch-direct-obj-greedy
143 (lambda* (goes-by #:key direct-obj rest)
144 (member direct-obj goes-by))
148 ;; @@: We should probably ONLY allow these to go to users!
149 (define* (custom-command verbs matcher should-handle action
150 #:optional (priority %default-priority))
151 "Full-grained customizable command."
152 (make-command verbs matcher should-handle action priority))