Events (or at least the framework for supporting them) are here! And it took me less than 4 months this time…

I basically followed my plan from my post on NPCs and Events, but I will elaborate.

The event system has two major prototype objects: the Event, and the EventSource, the goal being that different kinds of events and event sources can be defined much like entities, items and tiles.

Event Sources

Event Sources are actually actors in our ROT.js engine. Every turn they maintain any active events that they have spawned (see if they need to be removed from the active queue based on a win or lose state), and see if they should spawn a new event. They have both a ‘spawn chance’ (percent chance to spawn an event) and a ‘spawn condition’. E.g., an event source might only spawn an event once every 100 turns or so, but only if the crime meter is above 50. Right now, I have a ‘crime’ event source defined in city.js, that can spawn a single event type with a percent chance every round.

All the event source does is say “Can I spawn an event? If yes, create a random event from the types I’m allowed to spawn, start it, then add it to my queue of active events and my map’s queue of active events, and finally, notify my map’s player with the event’s designated start message.”

The idea is that I could have a crime event source that will spawn events based on one set of criteria, and a super-villain event queue that will spawn events based on another set of criteria, etc. If I want to generate a series of events based on a particular set of criteria, all I have to do is quickly define a new source in the same manner that we define entities, tiles and items. Pretty nifty (if I do say so myself (time will tell if this is actually nifty)).

Events

Events are objects that maintain logic for a few things:

  1. A number of potential spawn locations (which right now are items)
  2. The type of entities that it can spawn when started, as well as min and max numbers of entities
  3. Win and lose conditions, as well as the effects of what happens on win or on lose
  4. A number of ‘hooks’ which can be called on various events

Events get their own repository, much like entities, items and tiles. Currently, all events behave the same way when their ‘start’ method is invoked:

  1. Pick a random spawn location based on the item types listed in the spawnLocations array property of the event definition
  2. Spawn a random number of entities in random empty floor tiles in a radius around the spawn location, each of a random type as specified in the entityTypes array property of the event definition. Each of these entities is assigned a reference to this event (which could be accessed by entity.getEvent())
  3. Trigger the event’s onEntitySpawn function

Event entities have a special mixin called EventParticipant which, among other things, raises their assigned event’s ‘hooks’ whenever various things happen to them. I.e., event entities pipe events that happen to them to their event, so that the event can keep track of various things, like how many event entities have died or been hurt, or been interacted with.

Creating New Events

It is a goal of mine to have as much of the content of this game as data as possible, so that different items.js files, or entities.js files, or events.js files could be swapped out with others written in the same manner, and you could have different games. It also means that I’m separating content from function. That being said, there is a bit of a process to creating new events:

  1. Define a new entry in events.js. This will mainly consist of spawn locations, entity types, win/lose conditions and effects, and event hooks for what happens when an entity dies or his attacked etc.
  2. Put this event type in an event source, or create a new event source. An event source could be very simply defined with only a name, an array of spawn locations and entity types, and a max number of active events at a time. Optionally you can specify the spawnChance and the spawnCondition
  3. Optionally, define some event NPCs. You’ll notice that most of the actual behavior of the ‘robbery’ event is actually carried out by those entities executing their ‘robbery’ job. I said this step is optional, but I think that every new event will (at this point) require new entity definitions, job definitions, and task definitions. Important: Event NPCs MUST have the entity-mixin EventParticpant.

Additionally, especially during the early stages of content creation, new lot types, buildings, and items will need to be created. For instance, the safe item and the bank lot and building didn’t exist before the ‘robbery’ event, and had to be created. Luckily this wasn’t very hard, but I think any technical limitations that I’ve baked into my various systems will start to become painful as more specific events require more specific buildings and items etc.

What’s Next

Powers! I’m going to start fleshing out the UI and mechanics for selecting powers at the start screen, and the mechanics of building them out. This will be exciting in part because I’ll get to utilize the HERO System mechanics on the back end, which I think make for extremely flexible and creative powers. If I do it right, it will be very easy to add cool ‘ready made’ powers using some of the HERO System ideas.