From c3c1251235d094a4281ab6d2aef274ba553f4fac Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Fri, 4 Feb 2022 21:05:29 -0600 Subject: Add: first iteration of events --- mafia.org | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/mafia.org b/mafia.org index 67a78cc..3772e96 100644 --- a/mafia.org +++ b/mafia.org @@ -1,5 +1,5 @@ * Murder Mystery Game Prototype - +** Summary ideally a small city/village simulator where there are many independent actors all doing their routines. one of them gets triggered by something and commits a murder. they will continue to murder any time their pattern is triggered until @@ -447,6 +447,106 @@ its ~death-countown~, but I'm not quite prepared for that at this moment. (setf status 'dead))) #+end_src +* Events +** Summary + +Rather than logging every single thing that happens in the sim, perhaps we can +emit Events when something significant happens. As devs wanting to inspec the +simulation, it might be nice to see every action one of the actors takes. Thus, +we can emit an event when an actor changes targets, but don't have to do anything +if they keep looking at the same one. + +Its relatively the same to how the log function in the code (as i write this) +is only logging when the killer winks, someone dies, or target switches. + +But this is data! It makes up the timeline of the simulation, and one list of +events can describe a whole game. It could be visualized by stepping through it +or perhaps showing it all laid out as one with certain events highlighted. + +Giving some structure to this fact rather than just logging it into a buffer +gives us some more flexibility to displaying it down the road. + +So we should ad a slot to ~mafia-game~ to be a list of ~mafia-event~ objects. +Each event could have a reference to the actor who caused it, the current ~tick~ +or ~round~ when it happened (gotta clear up this time model), and some message +or other data. Specializing event types could allow us to use some generic +function like ~mafia-display-event~ and each type could use the base behavior or +something more specialized as needed. + +** ~mafia-event~ classes + +#+name: mafia-event-class +#+begin_src emacs-lisp + (defclass mafia-event nil + ((tick + :initarg :tick + :custom number + :label "Time of occurance" + :documentation "The tick of the parent game when the event happened") + (actor-id + :initarg :actor-id + :custom number + :label "Actor ID" + :documentation "The id of the actor who caused event.") + (message + :initarg :message + :custom string + :label "Event message" + :documentation "Freeform text string for an event message")) + "Base class for events that happen during a mafia simulation.") + + (defclass mafia-retarget-event (mafia-event) + ((old + :initarg :old + :custom number + :label "ID of previous target") + (new + :initarg :new + :custom number + :label "ID of new target"))) +#+end_src + +#+RESULTS: mafia-event-class +: mafia-retarget-event + +** ~mafia-event-log~ methods + +The base method handles formatting the log string and sticking in all the relevant +data from the event object. The ~&rest extra~ in the argument list lets this method +take an unspecified number of optional extra parameters. We can pass down additional +pre-formatted strings from specialized methods and log all of those with +~(apply #'mafia-log extra-strings)~. The log string will look something like this +(subject to change): + + =000389: mafia-event actor 3 --- msg: pooop= + +#+name: base-mafia-log-event +#+begin_src emacs-lisp + (cl-defmethod mafia-log-event ((event mafia-event) &rest extra-strings) + (with-slots (tick actor-id message) event + (let ((format-string "%06d: %s actor %d --- msg: %s") + (event-type (eieio-object-class event))) + (mafia-log format-string tick event-type actor-id + (propertize message 'face 'font-lock-string-face)) + (when extra-strings (apply #'mafia-log extra-strings))))) +#+end_src + +Lets specialize for the retarget event class, and we can ~cl-call-next-method~ +to pass control to the base ~mafia-log-event~ method. + +#+name: retarget-mafia-log-event +#+begin_src emacs-lisp + (cl-defmethod mafia-log-event ((event mafia-retarget-event)) + (with-slots (actor-id old new) event + (cl-call-next-method event (format "%02d focuses from %02d to %02d" actor-id old new)))) +#+end_src + +#+begin_src emacs-lisp + (mafia-log-event + (mafia-retarget-event + :tick 389 :actor-id 3 :message "foo" :old 2 :new 8)) +#+end_src + * Emacs "UI" we can use an emacs buffer and all of the ways we have to manipulate text to -- cgit v1.2.3