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/>.
22 (define-module (mudsync gameobj)
23 #:use-module (8sync systems actors)
24 #:use-module (8sync agenda)
25 #:use-module (oop goops)
40 ;;; Actions supported by all gameobj
41 (define gameobj-actions
43 (get-commands (wrap-apply gameobj-get-commands))
44 (get-container-commands (wrap-apply gameobj-get-container-commands))
45 (get-children (wrap-apply gameobj-get-children))
46 (add-occupant! (wrap-apply gameobj-add-child!))
47 (remove-occupant! (wrap-apply gameobj-remove-child!))
48 (set-loc! (wrap-apply gameobj-set-loc!))))
50 ;;; *all* game components that talk to players should somehow
51 ;;; derive from this class.
52 ;;; And all of them need a GM!
54 (define-class <gameobj> (<actor>)
57 #:accessor gameobj-loc)
59 ;; Uses a hash table like a set (values ignored)
60 (occupants #:init-thunk make-hash-table
61 #:accessor gameobj-occupants)
64 (gm #:init-keyword #:gm
66 ;; a name to be known by
67 (name #:init-keyword #:name
68 #:accessor gameobj-name)
71 #:init-keyword #:desc)
73 ;; how to print our name
74 (name-f #:init-keyword #:name-f
75 #:getter gameobj-name-f
76 #:init-value (wrap gameobj-simple-name-f))
79 (aliases #:init-keyword #:aliases
82 ;; Commands we can handle
83 (commands #:init-value '())
85 ;; Commands we can handle by being something's container
86 (container-commands #:init-value '())
89 (simple-dispatcher gameobj-actions)))
92 ;;; gameobj message handlers
93 ;;; ========================
95 (define-mhandler (gameobj-get-commands actor message verb)
96 (<-reply actor message #:commands (slot-ref actor 'commands)))
98 (define-mhandler (gameobj-get-container-commands actor message verb)
99 (<-reply actor message #:commands (slot-ref actor 'container-commands)))
101 (define-mhandler (gameobj-get-children actor message)
103 (hash-map->list (lambda (key val) key)
104 (gameobj-children actor)))
106 (<-reply actor message
107 #:children children))
109 (define-mhandler (gameobj-set-loc! player message id)
110 (format #t "DEBUG: Location set to ~s for player ~s\n"
111 id (actor-id-actor player))
112 (set! (gameobj-loc player) id))
115 (define (gameobj-simple-name-f gameobj)
116 "Simplest version: return ourselves for our name."
117 (gameobj-name gameobj))