_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

trigger.cpp File Reference
#include "stratagus.h"
#include "trigger.h"
#include "interface.h"
#include "iolib.h"
#include "map.h"
#include "player.h"
#include "results.h"
#include "script.h"
#include "unit.h"
#include "unit_find.h"
#include "unittype.h"

trigger.cpp - The trigger handling.

typedef int(* CompareFunction) (int, int)
 
CTimer GameTimer
 
static int Trigger
 The game timer. More...
 
static bool * ActiveTriggers
 
TriggerDataType TriggerData
 Some data accessible for script during the game. More...
 
int TriggerGetPlayer (lua_State *l)
 
const CUnitTypeTriggerGetUnitType (lua_State *l)
 get player number. More...
 
static int CompareEq (int a, int b)
 
static int CompareNEq (int a, int b)
 
static int CompareGrEq (int a, int b)
 
static int CompareGr (int a, int b)
 
static int CompareLeEq (int a, int b)
 
static int CompareLe (int a, int b)
 
static CompareFunction GetCompareFunction (const char *op)
 
static int CclGetNumUnitsAt (lua_State *l)
 
static int CclIfNearUnit (lua_State *l)
 
static int CclIfRescuedNearUnit (lua_State *l)
 
int GetNumOpponents (int player)
 
int GetTimer ()
 
void StopGame (GameResults result)
 Outcome of the game. More...
 
void ActionVictory ()
 
void ActionDefeat ()
 
void ActionDraw ()
 
void ActionSetTimer (int cycles, bool increasing)
 
void ActionStartTimer ()
 
void ActionStopTimer ()
 
static int CclAddTrigger (lua_State *l)
 
void SetTrigger (int trigger)
 
static int CclSetActiveTriggers (lua_State *l)
 
static int TriggerExecuteAction (int script)
 
static void TriggerRemoveTrigger (int trig)
 
void TriggersEachCycle ()
 get the unit-type More...
 
void TriggerCclRegister ()
 test triggers More...
 
void SaveTriggers (CFile &file)
 Register ccl features. More...
 
void InitTriggers ()
 Save the trigger module. More...
 
void CleanTriggers ()
 Setup triggers. More...
 

Typedef Documentation

◆ CompareFunction

typedef int(* CompareFunction) (int, int)

Function Documentation

◆ ActionDefeat()

void ActionDefeat ( )

Action condition player lose.

◆ ActionDraw()

void ActionDraw ( )

Action condition player draw.

◆ ActionSetTimer()

void ActionSetTimer ( int  cycles,
bool  increasing 
)

Action set timer

◆ ActionStartTimer()

void ActionStartTimer ( )

Action start timer

◆ ActionStopTimer()

void ActionStopTimer ( )

Action stop timer

◆ ActionVictory()

void ActionVictory ( )

Action condition player wins.

◆ CclAddTrigger()

static int CclAddTrigger ( lua_State *  l)
static

Description

Add a trigger.

Example:

AddTrigger( function() return (GetPlayerData(1,"UnitTypesCount","unit-farm") >= 4) end, function() return ActionVictory() end )

◆ CclGetNumUnitsAt()

static int CclGetNumUnitsAt ( lua_State *  l)
static

Description

Return the number of units of a given unit-type and player at a location.

Example:

– Get the number of knights from player 1 from position 0,0 to 20,15 num_units = GetNumUnitsAt(1,"unit-knight",{0,0},{20,15}) print(num_units)

◆ CclIfNearUnit()

static int CclIfNearUnit ( lua_State *  l)
static

Description

Player has the quantity of unit-type near to unit-type.

Example:

AddTrigger( function() return IfNearUnit(0,">",1,"unit-peasant","unit-town-hall") end, function() AddMessage("Player 0 has more than 1 peasant near the Town Hall") return false end )

◆ CclIfRescuedNearUnit()

static int CclIfRescuedNearUnit ( lua_State *  l)
static

Description

Player has the quantity of rescued unit-type near to unit-type.

Example:

IfRescuedNearUnit("this", ">=", 1, "unit-archer", "unit-circle-of-power")

◆ CclSetActiveTriggers()

static int CclSetActiveTriggers ( lua_State *  l)
static

Set the active triggers

◆ CleanTriggers()

void CleanTriggers ( )

Setup triggers.

Clean up the trigger module.

◆ CompareEq()

static int CompareEq ( int  a,
int  b 
)
static

◆ CompareGr()

static int CompareGr ( int  a,
int  b 
)
static

◆ CompareGrEq()

static int CompareGrEq ( int  a,
int  b 
)
static

◆ CompareLe()

static int CompareLe ( int  a,
int  b 
)
static

◆ CompareLeEq()

static int CompareLeEq ( int  a,
int  b 
)
static

◆ CompareNEq()

static int CompareNEq ( int  a,
int  b 
)
static

◆ GetCompareFunction()

static CompareFunction GetCompareFunction ( const char *  op)
static

Returns a function pointer to the comparison function

Parameters
opThe operation
Returns
Function pointer to the compare function

◆ GetNumOpponents()

int GetNumOpponents ( int  player)

Description

Returns the number of opponents of a given player.

◆ GetTimer()

int GetTimer ( )

Check the timer value

◆ InitTriggers()

void InitTriggers ( )

Save the trigger module.

Initialize the trigger module.

◆ SaveTriggers()

void SaveTriggers ( CFile file)

Register ccl features.

Save the trigger module.

Parameters
fileOpen file to print to

◆ SetTrigger()

void SetTrigger ( int  trigger)

Set the trigger values

◆ StopGame()

void StopGame ( GameResults  result)

Outcome of the game.

Stop the running game with a given result

◆ TriggerCclRegister()

void TriggerCclRegister ( )

test triggers

Register CCL features for triggers.

◆ TriggerExecuteAction()

static int TriggerExecuteAction ( int  script)
static

Execute a trigger action

Parameters
scriptScript to execute
Returns
1 if the trigger should be removed

◆ TriggerGetPlayer()

int TriggerGetPlayer ( lua_State *  l)

Get player number.

Parameters
lLua state.
Returns
The player number, -1 matches any.

◆ TriggerGetUnitType()

const CUnitType* TriggerGetUnitType ( lua_State *  l)

get player number.

Get the unit-type.

Parameters
lLua state.
Returns
The unit-type pointer.

◆ TriggerRemoveTrigger()

static void TriggerRemoveTrigger ( int  trig)
static

Remove a trigger

Parameters
trigCurrent trigger

◆ TriggersEachCycle()

void TriggersEachCycle ( )

get the unit-type

Check trigger each game cycle.

Variable Documentation

◆ ActiveTriggers

bool* ActiveTriggers
static

◆ GameTimer

CTimer GameTimer

◆ Trigger

int Trigger
static

The game timer.

◆ TriggerData

TriggerDataType TriggerData

Some data accessible for script during the game.

the game timer

(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.