Author Topic: "Event driven" roguelike architecture question  (Read 13237 times)

mike3

  • Rogueliker
  • ***
  • Posts: 125
  • Karma: +0/-0
    • View Profile
    • Email
"Event driven" roguelike architecture question
« on: March 28, 2013, 10:09:39 PM »
Hi.

I'm curious about this: I notice that there are some roguelikes (such as JADE/ADOM II and Incursion) that use an "event-driven" architecture. I was wondering: how does one reconcile this kind of architecture with the turn-based nature of roguelikes? If you represent the game activity as a bunch of "events", what do you use to determine where one turn ends and where another begins, which happen on which turn, etc.?
« Last Edit: March 28, 2013, 11:08:04 PM by mike3 »

Eben

  • Rogueliker
  • ***
  • Posts: 339
  • Karma: +0/-0
  • Controversializer
    • View Profile
    • SquidPony!
Re: "Event driven" roguelike architecture question
« Reply #1 on: March 28, 2013, 11:08:22 PM »
Do you mean event driven as in the UI? In that case you can either queue up events or just not accept new ones until it's time for them. Either is pretty straight forward.

mike3

  • Rogueliker
  • ***
  • Posts: 125
  • Karma: +0/-0
    • View Profile
    • Email
Re: "Event driven" roguelike architecture question
« Reply #2 on: March 28, 2013, 11:17:01 PM »
I was referring to the actual game mechanism, not just the UI stuff.
« Last Edit: March 28, 2013, 11:18:59 PM by mike3 »

george

  • Rogueliker
  • ***
  • Posts: 201
  • Karma: +1/-1
    • View Profile
    • Email
Re: "Event driven" roguelike architecture question
« Reply #3 on: March 29, 2013, 02:13:02 AM »
Game world events are sort of independent of the time system. For example, take a typical over-engineered ( ;) ) speed-based time system. All things are in a queue and they each have a 'timer' on them that represents when they go next.

[ThingA->200, ThingB->350, ThingC->700]

If it is turn-based these timers are in 'speed units'. Each turn you can do some operation that decrements the speed units. A typical one is to subtract the amount of time the player action took then have all the things with a zeroed timer act. There are lots of variations. I even summarized a bunch once, http://kooneiform.wordpress.com/2009/04/14/roguelike-turn-based-time/ .

If it's realtime the timers can be in milliseconds and you just go about your business.

Now it should be clear that an 'event' is nothing more than a 'thing' (perhaps with no physical presence). So you just take it from there.

guest509

  • Guest
Re: "Event driven" roguelike architecture question
« Reply #4 on: March 29, 2013, 03:23:25 AM »
Gamemaker, the program I use, explicitly enforces an object - event - action format.

For example:
  Object: Player
  Event: Press 'i'
  Action: if it's the player's turn, then Goto 'I'nventory Window.

For the bad guys, depending on your timing system, it would go something like this.
  Object: Bad Guy
  Event: It has become their turn.
  Action: if they sense the player then goto 'attack mode'
             if they don't then goto 'wander mode'

Later
  Object: Bad Guy
  Event: It's their turn.
  Action: If they are in attack mode then go after the player
              If not then just move around.

That's sort of the idea. I dunno if it answers your question, but that's the basics of Gamemaker.

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: "Event driven" roguelike architecture question
« Reply #5 on: March 29, 2013, 06:11:07 AM »
Depends on how you represent time. ADOM uses something like 1000 ticks per turn IIRC. You would just put everything in a priority queue and simulate-- calling events as per a real-time system.

mike3

  • Rogueliker
  • ***
  • Posts: 125
  • Karma: +0/-0
    • View Profile
    • Email
Re: "Event driven" roguelike architecture question
« Reply #6 on: March 29, 2013, 09:07:47 AM »
Game world events are sort of independent of the time system. For example, take a typical over-engineered ( ;) ) speed-based time system. All things are in a queue and they each have a 'timer' on them that represents when they go next.

[ThingA->200, ThingB->350, ThingC->700]

If it is turn-based these timers are in 'speed units'. Each turn you can do some operation that decrements the speed units. A typical one is to subtract the amount of time the player action took then have all the things with a zeroed timer act. There are lots of variations. I even summarized a bunch once, http://kooneiform.wordpress.com/2009/04/14/roguelike-turn-based-time/ .

If it's realtime the timers can be in milliseconds and you just go about your business.

Now it should be clear that an 'event' is nothing more than a 'thing' (perhaps with no physical presence). So you just take it from there.

Hmm. However, what about the case where the monster's, or player's, speed changes? Like the player gets stat boosts, increasing his speed. Or the monster is hit with a "slow monster" spell or something like that (it exists in several games).

Also, am I right in guessing that the "entities" should be of a type "Actor" or something similar that is also the type for "event" objects (this is how it is in JADE, according to the "JavaDoc")?
« Last Edit: March 29, 2013, 10:14:57 AM by mike3 »

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: "Event driven" roguelike architecture question
« Reply #7 on: March 29, 2013, 02:57:06 PM »
Are you familiar with event-architecture at all? I mean, do you need an explanation of how it works or simply how it would work in a turn-based game?


george

  • Rogueliker
  • ***
  • Posts: 201
  • Karma: +1/-1
    • View Profile
    • Email
Re: "Event driven" roguelike architecture question
« Reply #8 on: March 29, 2013, 03:38:22 PM »
Hmm. However, what about the case where the monster's, or player's, speed changes? Like the player gets stat boosts, increasing his speed. Or the monster is hit with a "slow monster" spell or something like that (it exists in several games).

Also, am I right in guessing that the "entities" should be of a type "Actor" or something similar that is also the type for "event" objects (this is how it is in JADE, according to the "JavaDoc")?

How you design your types is completely up to you, and there are many ways of doing it. If you don't have strong ideas about it then I'd advise keeping it simple no matter what example you follow.

If a thing's speed changes it doesn't make much difference to the queue of things. You just see it in the next iteration. For example,

[Player->500, ThingA->600, ThingB->700]

Player picks up boots of speed +100. ThingA steps in slimy ooze (speed -100), ThingB gets feet stuck in trap (speed -500).

(note that speeds are how long until you can do something, so bonuses subtract and penalties add -- you can do it the other way too of course, depends on the system)

[Player->400, ThingA->700, ThingB->1200]

mike3

  • Rogueliker
  • ***
  • Posts: 125
  • Karma: +0/-0
    • View Profile
    • Email
Re: "Event driven" roguelike architecture question
« Reply #9 on: March 30, 2013, 12:20:08 AM »
Thanks. I think I can see how to do this now.