(desc #:init-value #f
#:init-keyword #:desc)
+ ;; @@: Maybe commands should be renamed to verbs, I dunno
;; Commands we can handle
(commands #:allocation #:each-subclass
#:init-thunk (build-commands
(build-commands
("drop" ((direct-command cmd-drop #:obvious? #f)))))
+ ;; The extremely squishy concept of "props"... properties!
+ ;; These are flags, etc etc of various types. This is a hashq table.
+ ;; These have upsides and downsides, but the big upside is that you can
+ ;; query a "prop" of a prospective gameobj without knowing what type of
+ ;; gameobj that is, and not fear some kind of breakage.
+ ;;
+ ;; props by default only have a 'get-prop read-only action handler;
+ ;; any coordination of setting a prop between actors must be
+ ;; added to that actor, to keep things from getting out of control.
+ (props #:init-thunk make-hash-table)
+ ;; gameobjs may inherit an initial list of these via the
+ ;; initial-props slot, which must always have its
+ ;; #:allocation #:each-subclass and use (wrap-rmeta-slot).
+ ;; The vanilla gameobj has no props, on purpose.
+ (initial-props #:allocation #:each-subclass
+ #:init-thunk (build-rmeta-slot '()))
+
;; Most objects are generally visible by default
(invisible? #:init-value #f
#:init-keyword #:invisible?)
(get-name gameobj-get-name)
(set-name! gameobj-act-set-name!)
(get-desc gameobj-get-desc)
+ (get-prop gameobj-act-get-prop)
(goes-by gameobj-act-goes-by)
(visible-name gameobj-visible-name)
(self-destruct gameobj-act-self-destruct)
(replace-step actor occupants))
replace-steps))))
-;; @@: This could be kind of a messy way of doing gameobj-act-init
-;; stuff. If only we had generic methods :(
+(define (gameobj-setup-props gameobj)
+ (define class (class-of gameobj))
+ (define props (slot-ref gameobj 'props))
+ (maybe-build-rmeta-slot-cache! class 'initial-props
+ eq? hashq-set! hashq-ref)
+ (hash-for-each
+ (lambda (key value)
+ (hashq-set! props key value))
+ (rmeta-slot-table (class-slot-ref class 'initial-props))))
+
+;; TODO: Use the *init* action?
+;; We could also use a generic method if they didn't have
+;; what I'm pretty sure is O(n) dispatch in GOOPS...
(define* (gameobj-act-init actor message #:key replace)
- "Your most basic game object init procedure.
-Assists in its replacement of occupants if necessary and nothing else."
+ "Your most basic game object init procedure."
+ (gameobj-setup-props actor)
(run-replacement actor replace gameobj-replace-steps*))
+(define* (gameobj-get-prop actor key #:optional dflt)
+ (hashq-ref (slot-ref gameobj 'props) key dflt))
+
+(define* (gameobj-set-prop! actor key val)
+ (hashq-set! (slot-ref gameobj 'props) key val))
+
+(define* (gameobj-act-get-prop actor message key #:optional dflt)
+ (gameobj-get-prop actor key dflt))
+
(define (gameobj-goes-by gameobj)
"Find the name we go by. Defaults to #:name if nothing else provided."
(cond ((slot-ref gameobj 'goes-by) =>
(define* (gameobj-act-set-name! actor message val)
(slot-set! actor 'name val))
+(define* (gameobj-desc actor #:key whos-looking)
+ (match (slot-ref actor 'desc)
+ ((? procedure? desc-proc)
+ (desc-proc actor whos-looking))
+ (desc desc)))
+
(define* (gameobj-get-desc actor message #:key whos-looking)
- (define desc-text
- (match (slot-ref actor 'desc)
- ((? procedure? desc-proc)
- (desc-proc actor whos-looking))
- (desc desc)))
- (<-reply message desc-text))
+ "This is the action equivalent of the gameobj-desc getter"
+ (<-reply message (gameobj-desc actor #:whos-looking whos-looking)))
(define (gameobj-visible-to-player? gameobj whos-looking)
"Check to see whether we're visible to the player or not.