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)
41 player-gather-command-handlers
47 (define %low-priority 0)
48 (define %default-priority 1)
49 (define %high-priority 2)
51 ;; ;;; Avoiding some annoying issues crossing the continuation barrier
52 ;; ;;; and the "@@" special form
53 ;; (define (make-command verbs matcher should-handle action priority)
54 ;; (list '*command* verbs matcher should-handle action priority))
56 ;; (define command-verbs second)
57 ;; (define command-matcher third)
58 ;; (define command-should-handle fourth)
59 ;; (define command-action fifth)
60 ;; (define command-priority sixth)
62 (define-record-type <command>
63 (make-command verbs matcher should-handle action priority)
66 (matcher command-matcher)
67 (should-handle command-should-handle)
68 (action command-action)
69 (priority command-priority))
72 (define (direct-command verbs action)
75 ;; @@: Should we allow fancier matching than this?
76 ;; Let the actor itself pass along this whole method?
77 (lambda* (goes-by #:key direct-obj)
78 (member direct-obj goes-by))
82 (define (loose-direct-command verbs action)
85 ;; @@: Should we allow fancier matching than this?
86 ;; Let the actor itself pass along this whole method?
92 (define* (indir-command verbs action #:optional prepositions)
95 (lambda* (goes-by #:key direct-obj indir-obj preposition)
98 (member indir-obj goes-by)
99 (member preposition prepositions))
100 (member indir-obj goes-by)))
104 (define* (loose-indir-command verbs action #:optional prepositions)
112 (define (empty-command verbs action)
119 (define (greedy-command verbs action)
126 (define (direct-greedy-command verbs action)
127 "greedy commands but which match the direct object"
129 cmatch-direct-obj-greedy
130 (lambda* (goes-by #:key direct-obj rest)
131 (member direct-obj goes-by))
135 ;; @@: We should probably ONLY allow these to go to users!
136 (define* (custom-command verbs matcher should-handle action
137 #:optional (priority %default-priority))
138 "Full-grained customizable command."
139 (make-command verbs matcher should-handle action priority))