Game Event Help

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
crancran
Greenskin
Posts: 125
Joined: Wed May 05, 2010 3:36 pm
x 2

Game Event Help

Post by crancran » Sat Oct 29, 2011 6:10 pm

In designing my event notification framework for my Component-based entity system, I primarily focused on inter-communication among the components of a single entity. I decided to leverage the boost signal2 library so that I could create signals, connect my components to a signal of a specific event type and then subscribe from the entity's signal queue when that component was detached from the entity. I then realized that I was only scratching the surface of what my event system truly needs to represent, particularly when we start to consider full scale level design where an entity reacts to another entities' conditions.

For example, we could design a small level where there is a hallway that leads to a room. Right before the room, there is a door that is open by default. Inside the room exists a big bad boss and a door behind the boss that is initially closed. In this scenario, the entry door will want to subscribe to the bosses' ENTER_COMBAT and LEAVE_COMBAT events to trigger closing/opening the door. Similarly, the exit door will want to subscribe to a DEATH event triggered by the boss when he dies, so that the exit door will open under that condition.

In the above example, the exit door's DoorOpenTriggerComponent would have some code that resembles this:

Code: Select all

void CDoorOpenTriggerComponent::OnInitialize() {
  EventSystem::getSingleton().addListener(EventSystem::E_DEATH, &CDoorOpenTriggerComponent::OnDeath);
}
void CDoorOpenTriggerComponent::OnDeath(GameEvent& evt) {
  if(evt.senderEntityId == bossEntityId) { // how would we get boss' entity id???
    m_doorState = OPEN_STATE;
  }
}
Lets add a bit more complexity to the above scenario. Every 60 seconds our boss spawns a minion randomly in the room while it is alive. The player must kill this minion or else they'll continue to spawn and overwhelm the player. But if the boss dies while a minion is still alive, we have two options. Either the minion would despawn with the death event or the minion must continue to be killed.

Under the first scenario (despawn); the above open door trigger logic would still continue to work. However, under the second scenario, the logic would need to be a bit more complex because not only should the door open when the boss dies; but when the boss and all his spawned minions have been killed too.

How would that second scenario work? And how would others support one entity getting the entity information from another spawned entity that it cares about in the relationship of a fight scenario such as this? Would entities have a parent/child relationship such that the boss is the parent with the two doors and all spawned minions being children of the boss?
0 x

User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am

Re: Game Event Help

Post by johnhpus » Sat Mar 03, 2012 3:23 am

I would recommend that you make all or most messages available to any interested message subscriber, and do subscription setup and event handling in external scripts.

Something like...

MyDoorObject.script

Code: Select all


subscribeToEvent( REGULAR_ENEMY_SPAWNED, onEnemySpawned );
subscribeToEvent( REGULAR_ENEMY_DIED, onEnemyDied );
subscribeToEvent( BOSS_ENEMY_DIED, onBossDied );

int enemy_count;

function onEnemySpawned()
{
  increase enemy count;
}

function onEnemyDied()
{
   decrease enemy count;
}

function onBossDied()
{
   if enemy count > 0 ...
   else ...
}
I wouldn't think too much about specific reactions for your game objects, but instead make generic objects that use scripts for their most specific behaviors. Imagine that you're in your level editor, you right-click on an enemy and start editing his script. You would put AI, etc. in there as well.
0 x

Post Reply