Advertisement

RTS Triggers

Started by October 10, 2000 12:06 AM
1 comment, last by DarkMage139 24 years, 2 months ago
Just wondering... what''s the structure\algorithm for an RTS trigger? Something like in StarCraft or Age of Empires II. A general idea or some details would be nice. -Thanks in advance- - DarkMage139 ++++++++++++++++ "Shut up and give me the freakin code" -unknown "Ask and you will be shot" -snes16bit "Not again!" -SHilbert (upon being assimilated) "Nazrix is cool." - Nazrix "You've only seen the beginning" -The Dark Lord of RPGs "I'm gonna go get high on Squaresoft games" - ILoveNataliePortman
- DarkMage139
When building my trigger/event system it seemed like the best way to go was to have each trigger have a condition to execute or not execute on, with generally some condition values. Then you have events, which are lists of actions. So for example a simple trigger/event might look as follows:

If (numUnits equals 0) for (Player 2)
{
DisplayText "You Win!",80,20
FadeOut 5
ShowMenuScreen
}

So the trigger is the if statement and the event is the list of actions inside of the {}'s. For my system for each new action/trigger I derived a new class. So it might look somewhat like the following:

            class Trigger{  virtual bool CheckTrigger();  virtual void SetElements(void **elements);  virtual void **GetElements();};class Action{  virtual bool DoAction();  virtual void SetElements(void **elements);  virtual void **GetElements();};class Event{  void Check() // Called every frame or when the event is active  {    if (m_trigger.CheckTrigger()==true)    {      // Do all the actions    }  }  Trigger *m_trigger;  Action **m_actions;};[/source]Then when implementing individual triggers or actions you would just derive new classes, as follows:[source]class Trigger_PlayerUnits : public Trigger{  bool CheckTrigger()  {    if (m_checkState==0) // Player Units == numUnits      if (player[m_playerNum].m_numUnits==m_numUnits) return true;      else return false;  }  void SetElements(void **elements)  {    m_playerNum = (int*)(elements)[0];    ...  }  int m_playerNum,m_numUnits;  int m_checkState;};class Action_DisplayText : public Action{  void DoAction()  {    DisplayText(m_string,m_x,m_y);  }  char *m_string;  int m_x,m_y;};    


This system allows you to set up your variables at run-time or in a saved file and allows for a good amount of flexibility. Any comments/critiques are welcomed .

PreManDrake

(something is wrong with the source formatting tag...)

Edited by - Premandrake on October 10, 2000 2:01:47 PM
Advertisement
Yeah, thanks.

- DarkMage139
++++++++++++++++
"Shut up and give me the freakin code" -unknown
"Ask and you will be shot" -snes16bit
"Not again!" -SHilbert (upon being assimilated)
"Nazrix is cool." - Nazrix
"You've only seen the beginning" -The Dark Lord of RPGs
"I'm gonna go get high on Squaresoft games" - ILoveNataliePortman
- DarkMage139

This topic is closed to new replies.

Advertisement