2011-01-20 16:56:30 +01:00
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2005 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
# include "script_manager.h"
# include "world.h"
# include "lang.h"
# include "game_camera.h"
# include "game.h"
2011-10-06 20:04:59 +02:00
# include "config.h"
2011-01-20 16:56:30 +01:00
# include "leak_dumper.h"
using namespace Shared : : Platform ;
using namespace Shared : : Lua ;
using namespace Shared : : Util ;
namespace Glest { namespace Game {
2012-10-20 09:15:13 +02:00
ScriptManagerMessage : : ScriptManagerMessage ( ) : text ( " " ) , header ( " " ) {
2013-12-30 17:17:05 +01:00
this - > factionIndex = - 1 ;
this - > teamIndex = - 1 ;
this - > messageNotTranslated = true ;
2012-03-26 08:48:58 +02:00
}
2017-10-10 04:09:36 +02:00
ScriptManagerMessage : : ScriptManagerMessage ( const string & textIn , const string & headerIn ,
2013-12-30 17:17:05 +01:00
int factionIndex , int teamIndex , bool messageNotTranslated ) :
text ( textIn ) , header ( headerIn ) {
this - > factionIndex = factionIndex ;
this - > teamIndex = teamIndex ;
this - > messageNotTranslated = messageNotTranslated ;
2012-03-26 08:48:58 +02:00
}
void ScriptManagerMessage : : saveGame ( XmlNode * rootNode ) {
std : : map < string , string > mapTagReplacements ;
XmlNode * scriptManagerMessageNode = rootNode - > addChild ( " ScriptManagerMessage " ) ;
//string text;
scriptManagerMessageNode - > addAttribute ( " text " , text , mapTagReplacements ) ;
//string header;
scriptManagerMessageNode - > addAttribute ( " header " , header , mapTagReplacements ) ;
2012-03-30 07:53:33 +02:00
scriptManagerMessageNode - > addAttribute ( " factionIndex " , intToStr ( factionIndex ) , mapTagReplacements ) ;
scriptManagerMessageNode - > addAttribute ( " teamIndex " , intToStr ( teamIndex ) , mapTagReplacements ) ;
2013-12-30 17:17:05 +01:00
scriptManagerMessageNode - > addAttribute ( " messageNotTranslated " , intToStr ( messageNotTranslated ) , mapTagReplacements ) ;
2012-03-26 08:48:58 +02:00
}
void ScriptManagerMessage : : loadGame ( const XmlNode * rootNode ) {
const XmlNode * scriptManagerMessageNode = rootNode ;
text = scriptManagerMessageNode - > getAttribute ( " text " ) - > getValue ( ) ;
header = scriptManagerMessageNode - > getAttribute ( " header " ) - > getValue ( ) ;
2012-03-30 07:53:33 +02:00
factionIndex = scriptManagerMessageNode - > getAttribute ( " factionIndex " ) - > getIntValue ( ) ;
2012-03-31 22:33:56 +02:00
teamIndex = scriptManagerMessageNode - > getAttribute ( " teamIndex " ) - > getIntValue ( ) ;
2013-12-30 17:17:05 +01:00
messageNotTranslated = true ;
if ( scriptManagerMessageNode - > hasAttribute ( " messageNotTranslated " ) = = true ) {
messageNotTranslated = ( scriptManagerMessageNode - > getAttribute ( " messageNotTranslated " ) - > getIntValue ( ) ! = 0 ) ;
}
2012-03-26 08:48:58 +02:00
}
2011-01-20 16:56:30 +01:00
// =====================================================
// class PlayerModifiers
// =====================================================
PlayerModifiers : : PlayerModifiers ( ) {
winner = false ;
aiEnabled = true ;
consumeEnabled = true ;
}
2012-03-26 08:48:58 +02:00
void PlayerModifiers : : saveGame ( XmlNode * rootNode ) {
std : : map < string , string > mapTagReplacements ;
XmlNode * playerModifiersNode = rootNode - > addChild ( " PlayerModifiers " ) ;
//bool winner;
playerModifiersNode - > addAttribute ( " winner " , intToStr ( winner ) , mapTagReplacements ) ;
//bool aiEnabled;
playerModifiersNode - > addAttribute ( " aiEnabled " , intToStr ( aiEnabled ) , mapTagReplacements ) ;
//bool consumeEnabled;
playerModifiersNode - > addAttribute ( " consumeEnabled " , intToStr ( consumeEnabled ) , mapTagReplacements ) ;
}
void PlayerModifiers : : loadGame ( const XmlNode * rootNode ) {
const XmlNode * playerModifiersNode = rootNode ;
2012-04-16 22:15:57 +02:00
winner = playerModifiersNode - > getAttribute ( " winner " ) - > getIntValue ( ) ! = 0 ;
aiEnabled = playerModifiersNode - > getAttribute ( " aiEnabled " ) - > getIntValue ( ) ! = 0 ;
consumeEnabled = playerModifiersNode - > getAttribute ( " consumeEnabled " ) - > getIntValue ( ) ! = 0 ;
2012-03-26 08:48:58 +02:00
}
CellTriggerEvent : : CellTriggerEvent ( ) {
type = ctet_Unit ;
sourceId = 0 ;
destId = 0 ;
//Vec2i destPos;
triggerCount = 0 ;
}
void CellTriggerEvent : : saveGame ( XmlNode * rootNode ) {
std : : map < string , string > mapTagReplacements ;
XmlNode * cellTriggerEventNode = rootNode - > addChild ( " CellTriggerEvent " ) ;
// CellTriggerEventType type;
cellTriggerEventNode - > addAttribute ( " type " , intToStr ( type ) , mapTagReplacements ) ;
// int sourceId;
cellTriggerEventNode - > addAttribute ( " sourceId " , intToStr ( sourceId ) , mapTagReplacements ) ;
// int destId;
cellTriggerEventNode - > addAttribute ( " destId " , intToStr ( destId ) , mapTagReplacements ) ;
// Vec2i destPos;
cellTriggerEventNode - > addAttribute ( " destPos " , destPos . getString ( ) , mapTagReplacements ) ;
// int triggerCount;
cellTriggerEventNode - > addAttribute ( " triggerCount " , intToStr ( triggerCount ) , mapTagReplacements ) ;
2012-05-02 08:07:11 +02:00
// Vec2i destPosEnd;
cellTriggerEventNode - > addAttribute ( " destPosEnd " , destPosEnd . getString ( ) , mapTagReplacements ) ;
2012-03-26 08:48:58 +02:00
}
void CellTriggerEvent : : loadGame ( const XmlNode * rootNode ) {
const XmlNode * cellTriggerEventNode = rootNode - > getChild ( " CellTriggerEvent " ) ;
type = static_cast < CellTriggerEventType > ( cellTriggerEventNode - > getAttribute ( " type " ) - > getIntValue ( ) ) ;
sourceId = cellTriggerEventNode - > getAttribute ( " sourceId " ) - > getIntValue ( ) ;
destId = cellTriggerEventNode - > getAttribute ( " destId " ) - > getIntValue ( ) ;
destPos = Vec2i : : strToVec2 ( cellTriggerEventNode - > getAttribute ( " destPos " ) - > getValue ( ) ) ;
triggerCount = cellTriggerEventNode - > getAttribute ( " triggerCount " ) - > getIntValue ( ) ;
2012-05-02 08:07:11 +02:00
if ( cellTriggerEventNode - > hasAttribute ( " destPosEnd " ) = = true ) {
destPosEnd = Vec2i : : strToVec2 ( cellTriggerEventNode - > getAttribute ( " destPosEnd " ) - > getValue ( ) ) ;
}
2012-03-26 08:48:58 +02:00
}
TimerTriggerEvent : : TimerTriggerEvent ( ) {
running = false ;
startFrame = 0 ;
endFrame = 0 ;
2012-03-27 08:42:55 +02:00
triggerSecondsElapsed = 0 ;
2012-03-26 08:48:58 +02:00
}
void TimerTriggerEvent : : saveGame ( XmlNode * rootNode ) {
std : : map < string , string > mapTagReplacements ;
XmlNode * timerTriggerEventNode = rootNode - > addChild ( " TimerTriggerEvent " ) ;
// bool running;
timerTriggerEventNode - > addAttribute ( " running " , intToStr ( running ) , mapTagReplacements ) ;
// //time_t startTime;
// //time_t endTime;
// int startFrame;
timerTriggerEventNode - > addAttribute ( " startFrame " , intToStr ( startFrame ) , mapTagReplacements ) ;
// int endFrame;
timerTriggerEventNode - > addAttribute ( " endFrame " , intToStr ( endFrame ) , mapTagReplacements ) ;
2012-03-27 08:42:55 +02:00
if ( triggerSecondsElapsed > 0 ) {
timerTriggerEventNode - > addAttribute ( " triggerSecondsElapsed " , intToStr ( triggerSecondsElapsed ) , mapTagReplacements ) ;
}
2012-03-26 08:48:58 +02:00
}
void TimerTriggerEvent : : loadGame ( const XmlNode * rootNode ) {
const XmlNode * timerTriggerEventNode = rootNode - > getChild ( " TimerTriggerEvent " ) ;
2012-04-16 22:15:57 +02:00
running = timerTriggerEventNode - > getAttribute ( " running " ) - > getIntValue ( ) ! = 0 ;
2012-03-26 08:48:58 +02:00
startFrame = timerTriggerEventNode - > getAttribute ( " startFrame " ) - > getIntValue ( ) ;
endFrame = timerTriggerEventNode - > getAttribute ( " endFrame " ) - > getIntValue ( ) ;
2012-03-27 08:42:55 +02:00
if ( timerTriggerEventNode - > hasAttribute ( " triggerSecondsElapsed " ) = = true ) {
triggerSecondsElapsed = timerTriggerEventNode - > getAttribute ( " triggerSecondsElapsed " ) - > getIntValue ( ) ;
}
2012-03-26 08:48:58 +02:00
}
2011-01-20 16:56:30 +01:00
// =====================================================
// class ScriptManager
// =====================================================
2012-05-02 08:07:11 +02:00
ScriptManager * ScriptManager : : thisScriptManager = NULL ;
2015-02-06 01:07:34 +01:00
const int ScriptManager : : messageWrapCount = 35 ;
2012-05-02 08:07:11 +02:00
const int ScriptManager : : displayTextWrapCount = 64 ;
2011-01-20 16:56:30 +01:00
2011-10-06 20:04:59 +02:00
ScriptManager : : ScriptManager ( ) {
2011-12-02 17:07:59 +01:00
world = NULL ;
gameCamera = NULL ;
lastCreatedUnitId = - 1 ;
lastDeadUnitId = 0 ;
lastDeadUnitCauseOfDeath = 0 ;
lastDeadUnitKillerId = 0 ;
lastAttackedUnitId = 0 ;
lastAttackingUnitId = 0 ;
gameOver = false ;
gameWon = false ;
currentTimerTriggeredEventId = 0 ;
currentCellTriggeredEventId = 0 ;
2012-10-13 07:06:53 +02:00
currentCellTriggeredEventUnitId = 0 ;
2011-12-02 17:07:59 +01:00
currentEventId = 0 ;
inCellTriggerEvent = false ;
2012-03-26 08:48:58 +02:00
rootNode = NULL ;
2012-10-10 07:44:14 +02:00
currentCellTriggeredEventAreaEntryUnitId = 0 ;
currentCellTriggeredEventAreaExitUnitId = 0 ;
2013-05-25 22:46:36 +02:00
lastDayNightTriggerStatus = 0 ;
registeredDayNightEvent = false ;
2016-11-28 01:45:00 +01:00
errorCount = 0 ;
2013-05-28 02:59:44 +02:00
lastUnitTriggerEventUnitId = - 1 ;
lastUnitTriggerEventType = utet_None ;
2011-10-06 20:04:59 +02:00
}
ScriptManager : : ~ ScriptManager ( ) {
}
2012-03-26 08:48:58 +02:00
void ScriptManager : : init ( World * world , GameCamera * gameCamera , const XmlNode * rootNode ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
2013-12-30 11:01:47 +01:00
//printf("In [%s::%s Line: %d] rootNode [%p][%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,rootNode,(rootNode != NULL ? rootNode->getName().c_str() : "none"));
2012-03-26 08:48:58 +02:00
this - > rootNode = rootNode ;
2011-01-20 16:56:30 +01:00
const Scenario * scenario = world - > getScenario ( ) ;
this - > world = world ;
this - > gameCamera = gameCamera ;
//set static instance
thisScriptManager = this ;
2013-12-30 11:01:47 +01:00
//printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2011-01-20 16:56:30 +01:00
currentEventId = 1 ;
CellTriggerEventList . clear ( ) ;
TimerTriggerEventList . clear ( ) ;
2013-12-30 11:01:47 +01:00
//printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-03-26 08:48:58 +02:00
2011-01-20 16:56:30 +01:00
//register functions
2012-03-30 07:53:33 +02:00
luaScript . registerFunction ( networkShowMessageForFaction , " networkShowMessageForFaction " ) ;
luaScript . registerFunction ( networkShowMessageForTeam , " networkShowMessageForTeam " ) ;
2012-10-10 20:28:55 +02:00
luaScript . registerFunction ( networkSetCameraPositionForFaction , " networkSetCameraPositionForFaction " ) ;
luaScript . registerFunction ( networkSetCameraPositionForTeam , " networkSetCameraPositionForTeam " ) ;
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( showMessage , " showMessage " ) ;
luaScript . registerFunction ( setDisplayText , " setDisplayText " ) ;
2011-03-19 13:19:22 +01:00
luaScript . registerFunction ( addConsoleText , " addConsoleText " ) ;
2011-11-15 18:39:49 +01:00
luaScript . registerFunction ( addConsoleLangText , " addConsoleLangText " ) ;
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( DisplayFormattedText , " DisplayFormattedText " ) ;
2011-11-03 18:04:49 +01:00
luaScript . registerFunction ( DisplayFormattedText , " displayFormattedText " ) ;
2011-11-03 19:24:02 +01:00
luaScript . registerFunction ( DisplayFormattedLangText , " DisplayFormattedLangText " ) ;
luaScript . registerFunction ( DisplayFormattedLangText , " displayFormattedLangText " ) ;
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( clearDisplayText , " clearDisplayText " ) ;
luaScript . registerFunction ( setCameraPosition , " setCameraPosition " ) ;
2014-02-04 21:21:06 +01:00
luaScript . registerFunction ( shakeCamera , " shakeCamera " ) ;
luaScript . registerFunction ( shakeCameraOnUnit , " shakeCameraOnUnit " ) ;
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( createUnit , " createUnit " ) ;
2012-02-21 22:56:20 +01:00
luaScript . registerFunction ( createUnitNoSpacing , " createUnitNoSpacing " ) ;
2014-11-12 15:14:52 +01:00
luaScript . registerFunction ( setLockedUnitForFaction , " setLockedUnitForFaction " ) ;
2011-01-29 13:42:18 +01:00
luaScript . registerFunction ( destroyUnit , " destroyUnit " ) ;
2011-11-16 22:38:12 +01:00
luaScript . registerFunction ( giveKills , " giveKills " ) ;
2011-01-29 13:42:18 +01:00
luaScript . registerFunction ( morphToUnit , " morphToUnit " ) ;
2011-01-29 18:52:53 +01:00
luaScript . registerFunction ( moveToUnit , " moveToUnit " ) ;
2012-05-22 08:17:56 +02:00
2011-01-29 13:42:18 +01:00
luaScript . registerFunction ( playStaticSound , " playStaticSound " ) ;
luaScript . registerFunction ( playStreamingSound , " playStreamingSound " ) ;
luaScript . registerFunction ( stopStreamingSound , " stopStreamingSound " ) ;
luaScript . registerFunction ( stopAllSound , " stopAllSound " ) ;
2011-01-30 00:50:21 +01:00
luaScript . registerFunction ( togglePauseGame , " togglePauseGame " ) ;
2012-05-22 08:17:56 +02:00
luaScript . registerFunction ( playStaticVideo , " playStaticVideo " ) ;
//luaScript.registerFunction(playStreamingVideo, "playStreamingVideo");
//luaScript.registerFunction(stopStreamingVideo, "stopStreamingVideo");
luaScript . registerFunction ( stopAllVideo , " stopAllVideo " ) ;
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( giveResource , " giveResource " ) ;
luaScript . registerFunction ( givePositionCommand , " givePositionCommand " ) ;
luaScript . registerFunction ( giveProductionCommand , " giveProductionCommand " ) ;
luaScript . registerFunction ( giveAttackCommand , " giveAttackCommand " ) ;
luaScript . registerFunction ( giveUpgradeCommand , " giveUpgradeCommand " ) ;
2011-01-29 13:42:18 +01:00
luaScript . registerFunction ( giveAttackStoppedCommand , " giveAttackStoppedCommand " ) ;
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( disableAi , " disableAi " ) ;
luaScript . registerFunction ( enableAi , " enableAi " ) ;
luaScript . registerFunction ( getAiEnabled , " getAiEnabled " ) ;
luaScript . registerFunction ( disableConsume , " disableConsume " ) ;
luaScript . registerFunction ( enableConsume , " enableConsume " ) ;
luaScript . registerFunction ( getConsumeEnabled , " getConsumeEnabled " ) ;
luaScript . registerFunction ( setPlayerAsWinner , " setPlayerAsWinner " ) ;
luaScript . registerFunction ( endGame , " endGame " ) ;
luaScript . registerFunction ( startPerformanceTimer , " startPerformanceTimer " ) ;
luaScript . registerFunction ( endPerformanceTimer , " endPerformanceTimer " ) ;
luaScript . registerFunction ( getPerformanceTimerResults , " getPerformanceTimerResults " ) ;
luaScript . registerFunction ( registerCellTriggerEventForUnitToUnit , " registerCellTriggerEventForUnitToUnit " ) ;
luaScript . registerFunction ( registerCellTriggerEventForUnitToLocation , " registerCellTriggerEventForUnitToLocation " ) ;
luaScript . registerFunction ( registerCellTriggerEventForFactionToUnit , " registerCellTriggerEventForFactionToUnit " ) ;
luaScript . registerFunction ( registerCellTriggerEventForFactionToLocation , " registerCellTriggerEventForFactionToLocation " ) ;
2012-05-02 08:07:11 +02:00
luaScript . registerFunction ( registerCellAreaTriggerEventForUnitToLocation , " registerCellAreaTriggerEventForUnitToLocation " ) ;
luaScript . registerFunction ( registerCellAreaTriggerEventForFactionToLocation , " registerCellAreaTriggerEventForFactionToLocation " ) ;
2012-10-10 07:44:14 +02:00
luaScript . registerFunction ( registerCellAreaTriggerEvent , " registerCellAreaTriggerEvent " ) ;
2012-05-02 08:07:11 +02:00
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( getCellTriggerEventCount , " getCellTriggerEventCount " ) ;
luaScript . registerFunction ( unregisterCellTriggerEvent , " unregisterCellTriggerEvent " ) ;
luaScript . registerFunction ( startTimerEvent , " startTimerEvent " ) ;
2012-03-27 08:42:55 +02:00
luaScript . registerFunction ( startEfficientTimerEvent , " startEfficientTimerEvent " ) ;
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( resetTimerEvent , " resetTimerEvent " ) ;
luaScript . registerFunction ( stopTimerEvent , " stopTimerEvent " ) ;
luaScript . registerFunction ( getTimerEventSecondsElapsed , " timerEventSecondsElapsed " ) ;
luaScript . registerFunction ( getCellTriggeredEventId , " triggeredCellEventId " ) ;
luaScript . registerFunction ( getTimerTriggeredEventId , " triggeredTimerEventId " ) ;
2012-10-10 07:44:14 +02:00
luaScript . registerFunction ( getCellTriggeredEventAreaEntryUnitId , " triggeredEventAreaEntryUnitId " ) ;
luaScript . registerFunction ( getCellTriggeredEventAreaExitUnitId , " triggeredEventAreaExitUnitId " ) ;
2012-10-13 07:06:53 +02:00
luaScript . registerFunction ( getCellTriggeredEventUnitId , " triggeredCellEventUnitId " ) ;
2012-03-27 09:05:07 +02:00
luaScript . registerFunction ( setRandomGenInit , " setRandomGenInit " ) ;
luaScript . registerFunction ( getRandomGen , " getRandomGen " ) ;
luaScript . registerFunction ( getWorldFrameCount , " getWorldFrameCount " ) ;
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( getStartLocation , " startLocation " ) ;
2012-03-31 22:17:19 +02:00
luaScript . registerFunction ( getIsUnitAlive , " isUnitAlive " ) ;
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( getUnitPosition , " unitPosition " ) ;
2012-04-11 07:41:40 +02:00
luaScript . registerFunction ( setUnitPosition , " setUnitPosition " ) ;
2012-09-25 09:05:52 +02:00
luaScript . registerFunction ( addCellMarker , " addCellMarker " ) ;
luaScript . registerFunction ( removeCellMarker , " removeCellMarker " ) ;
2012-10-13 07:06:53 +02:00
luaScript . registerFunction ( showMarker , " showMarker " ) ;
2012-09-25 09:05:52 +02:00
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( getUnitFaction , " unitFaction " ) ;
2012-05-21 22:15:37 +02:00
luaScript . registerFunction ( getUnitName , " unitName " ) ;
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( getResourceAmount , " resourceAmount " ) ;
2011-11-16 22:38:12 +01:00
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( getLastCreatedUnitName , " lastCreatedUnitName " ) ;
luaScript . registerFunction ( getLastCreatedUnitId , " lastCreatedUnit " ) ;
2011-11-16 22:38:12 +01:00
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( getLastDeadUnitName , " lastDeadUnitName " ) ;
luaScript . registerFunction ( getLastDeadUnitId , " lastDeadUnit " ) ;
2011-11-16 22:43:19 +01:00
luaScript . registerFunction ( getLastDeadUnitCauseOfDeath , " lastDeadUnitCauseOfDeath " ) ;
2011-11-18 16:43:05 +01:00
luaScript . registerFunction ( getLastDeadUnitKillerName , " lastDeadUnitKillerName " ) ;
luaScript . registerFunction ( getLastDeadUnitKillerId , " lastDeadUnitKiller " ) ;
2011-11-16 22:38:12 +01:00
luaScript . registerFunction ( getLastAttackedUnitName , " lastAttackedUnitName " ) ;
luaScript . registerFunction ( getLastAttackedUnitId , " lastAttackedUnit " ) ;
luaScript . registerFunction ( getLastAttackingUnitName , " lastAttackingUnitName " ) ;
luaScript . registerFunction ( getLastAttackingUnitId , " lastAttackingUnit " ) ;
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( getUnitCount , " unitCount " ) ;
luaScript . registerFunction ( getUnitCountOfType , " unitCountOfType " ) ;
2012-03-30 16:48:54 +02:00
luaScript . registerFunction ( getIsGameOver , " isGameOver " ) ;
2011-01-20 16:56:30 +01:00
luaScript . registerFunction ( getGameWon , " gameWon " ) ;
2012-01-05 01:04:55 +01:00
luaScript . registerFunction ( getSystemMacroValue , " getSystemMacroValue " ) ;
2012-01-05 21:01:22 +01:00
luaScript . registerFunction ( scenarioDir , " scenarioDir " ) ;
2012-01-05 01:45:17 +01:00
luaScript . registerFunction ( getPlayerName , " getPlayerName " ) ;
2012-01-05 21:01:22 +01:00
luaScript . registerFunction ( getPlayerName , " playerName " ) ;
2012-01-05 01:04:55 +01:00
2011-10-06 20:04:59 +02:00
luaScript . registerFunction ( loadScenario , " loadScenario " ) ;
2012-03-30 09:10:14 +02:00
luaScript . registerFunction ( getUnitsForFaction , " getUnitsForFaction " ) ;
luaScript . registerFunction ( getUnitCurrentField , " getUnitCurrentField " ) ;
2012-10-09 22:03:09 +02:00
luaScript . registerFunction ( isFreeCellsOrHasUnit , " isFreeCellsOrHasUnit " ) ;
luaScript . registerFunction ( isFreeCells , " isFreeCells " ) ;
2012-10-13 07:06:53 +02:00
luaScript . registerFunction ( getHumanFactionId , " humanFaction " ) ;
2012-10-13 09:33:33 +02:00
luaScript . registerFunction ( highlightUnit , " highlightUnit " ) ;
luaScript . registerFunction ( unhighlightUnit , " unhighlightUnit " ) ;
2012-10-17 22:15:50 +02:00
luaScript . registerFunction ( giveStopCommand , " giveStopCommand " ) ;
luaScript . registerFunction ( selectUnit , " selectUnit " ) ;
luaScript . registerFunction ( unselectUnit , " unselectUnit " ) ;
luaScript . registerFunction ( addUnitToGroupSelection , " addUnitToGroupSelection " ) ;
luaScript . registerFunction ( recallGroupSelection , " recallGroupSelection " ) ;
luaScript . registerFunction ( removeUnitFromGroupSelection , " removeUnitFromGroupSelection " ) ;
luaScript . registerFunction ( setAttackWarningsEnabled , " setAttackWarningsEnabled " ) ;
luaScript . registerFunction ( getAttackWarningsEnabled , " getAttackWarningsEnabled " ) ;
2013-05-25 22:46:36 +02:00
luaScript . registerFunction ( getIsDayTime , " getIsDayTime " ) ;
luaScript . registerFunction ( getIsNightTime , " getIsNightTime " ) ;
luaScript . registerFunction ( getTimeOfDay , " getTimeOfDay " ) ;
luaScript . registerFunction ( registerDayNightEvent , " registerDayNightEvent " ) ;
luaScript . registerFunction ( unregisterDayNightEvent , " unregisterDayNightEvent " ) ;
2013-05-28 02:59:44 +02:00
luaScript . registerFunction ( registerUnitTriggerEvent , " registerUnitTriggerEvent " ) ;
luaScript . registerFunction ( unregisterUnitTriggerEvent , " unregisterUnitTriggerEvent " ) ;
luaScript . registerFunction ( getLastUnitTriggerEventUnitId , " lastUnitTriggerEventUnit " ) ;
luaScript . registerFunction ( getLastUnitTriggerEventType , " lastUnitTriggerEventType " ) ;
luaScript . registerFunction ( getUnitProperty , " getUnitProperty " ) ;
luaScript . registerFunction ( getUnitPropertyName , " getUnitPropertyName " ) ;
2013-11-07 06:18:21 +01:00
luaScript . registerFunction ( disableSpeedChange , " disableSpeedChange " ) ;
luaScript . registerFunction ( enableSpeedChange , " enableSpeedChange " ) ;
luaScript . registerFunction ( getSpeedChangeEnabled , " getSpeedChangeEnabled " ) ;
2013-05-28 02:59:44 +02:00
2013-12-30 21:55:59 +01:00
luaScript . registerFunction ( storeSaveGameData , " storeSaveGameData " ) ;
luaScript . registerFunction ( loadSaveGameData , " loadSaveGameData " ) ;
2014-01-04 18:34:49 +01:00
luaScript . registerFunction ( getFactionPlayerType , " getFactionPlayerType " ) ;
2011-01-20 16:56:30 +01:00
//load code
for ( int i = 0 ; i < scenario - > getScriptCount ( ) ; + + i ) {
const Script * script = scenario - > getScript ( i ) ;
luaScript . loadCode ( " function " + script - > getName ( ) + " () " + script - > getCode ( ) + " end \n " , script - > getName ( ) ) ;
}
2012-06-30 21:11:54 +02:00
//!!!
// string data_path= getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
// if(data_path != ""){
// endPathWithSlash(data_path);
// }
// string sandboxScriptFilename = data_path + "data/core/scripts/sandbox.lua";
// string sandboxLuaCode = getFileTextContents(sandboxScriptFilename);
//
// //luaScript.loadCode(sandboxLuaCode + "\n", "megaglest_lua_sandbox");
// luaScript.setSandboxWrapperFunctionName("runsandboxed");
// luaScript.setSandboxCode(sandboxLuaCode);
// luaScript.runCode(sandboxLuaCode);
// // Setup the lua security sandbox here
// luaScript.beginCall("megaglest_lua_sandbox");
// luaScript.endCall();
2011-01-20 16:56:30 +01:00
//setup message box
2013-10-29 07:13:38 +01:00
messageBox . init ( Lang : : getInstance ( ) . getString ( " Ok " ) ) ;
2011-01-20 16:56:30 +01:00
messageBox . setEnabled ( false ) ;
2016-11-26 15:46:32 +01:00
//messageBox.setAutoWordWrap(false);
2011-01-20 16:56:30 +01:00
//last created unit
lastCreatedUnitId = - 1 ;
2011-11-18 16:43:05 +01:00
lastDeadUnitName = " " ;
2011-01-20 16:56:30 +01:00
lastDeadUnitId = - 1 ;
2011-11-16 22:43:19 +01:00
lastDeadUnitCauseOfDeath = ucodNone ;
2011-11-18 16:43:05 +01:00
lastDeadUnitKillerName = " " ;
lastDeadUnitKillerId = - 1 ;
2011-11-16 22:38:12 +01:00
lastAttackedUnitName = " " ;
lastAttackedUnitId = - 1 ;
lastAttackingUnitName = " " ;
lastAttackingUnitId = - 1 ;
2011-01-20 16:56:30 +01:00
gameOver = false ;
gameWon = false ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
2012-10-11 07:17:37 +02:00
try {
// Setup global functions and vars here
luaScript . beginCall ( " global " ) ;
2012-03-26 08:48:58 +02:00
luaScript . endCall ( ) ;
2012-10-11 07:17:37 +02:00
//call startup function
if ( this - > rootNode = = NULL ) {
luaScript . beginCall ( " startup " ) ;
luaScript . endCall ( ) ;
}
else {
loadGame ( this - > rootNode ) ;
this - > rootNode = NULL ;
2013-12-30 21:55:59 +01:00
2013-12-30 23:00:04 +01:00
if ( LuaScript : : getDebugModeEnabled ( ) = = true ) printf ( " Calling onLoad luaSavedGameData.size() = %d \n " , ( int ) luaSavedGameData . size ( ) ) ;
2013-12-30 21:55:59 +01:00
luaScript . beginCall ( " onLoad " ) ;
luaScript . endCall ( ) ;
2012-10-11 07:17:37 +02:00
}
2012-03-26 08:48:58 +02:00
}
2012-10-11 07:17:37 +02:00
catch ( const megaglest_runtime_error & ex ) {
2012-10-18 10:16:47 +02:00
//string sErrBuf = "";
2012-10-11 07:17:37 +02:00
//if(ex.wantStackTrace() == true) {
2012-10-18 10:16:47 +02:00
char szErrBuf [ 8096 ] = " " ;
2016-11-26 15:46:32 +01:00
//snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
string sErrBuf = string ( szErrBuf ) + string ( " The game may no longer be stable! \n \n \t [ " ) + string ( ex . what ( ) ) + string ( " ] \n " ) ;
2012-10-11 07:17:37 +02:00
//}
SystemFlags : : OutputDebug ( SystemFlags : : debugError , sErrBuf . c_str ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , sErrBuf . c_str ( ) ) ;
2013-12-30 17:17:05 +01:00
thisScriptManager - > addMessageToQueue ( ScriptManagerMessage ( sErrBuf . c_str ( ) , " error " , - 1 , - 1 , true ) ) ;
2013-12-30 11:01:47 +01:00
thisScriptManager - > onMessageBoxOk ( false ) ;
2012-03-26 08:48:58 +02:00
}
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
}
// ========================== events ===============================================
2012-03-31 02:52:43 +02:00
void ScriptManager : : onMessageBoxOk ( bool popFront ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2013-12-30 17:17:05 +01:00
for ( int index = 0 ; messageQueue . empty ( ) = = false ; + + index ) {
2012-03-31 02:52:43 +02:00
//printf("i = %d messageQueue.size() = %d popFront = %d\n",i,messageQueue.size(),popFront);
if ( popFront = = true ) {
messageQueue . pop_front ( ) ;
}
2012-03-26 08:48:58 +02:00
if ( messageQueue . empty ( ) = = false ) {
2012-03-30 07:53:33 +02:00
// printf("onMessageBoxOk [%s] factionIndex = %d [%d] teamIndex = %d [%d][%d]\n",
// wrapString(lang.getScenarioString(messageQueue.front().getText()), messageWrapCount).c_str(),
// messageQueue.front().getFactionIndex(), this->world->getThisFactionIndex(),
// messageQueue.front().getTeamIndex(),this->world->getThisTeamIndex(),this->world->getThisFaction()->getTeam());
if ( ( messageQueue . front ( ) . getFactionIndex ( ) < 0 & & messageQueue . front ( ) . getTeamIndex ( ) < 0 ) | |
messageQueue . front ( ) . getFactionIndex ( ) = = this - > world - > getThisFactionIndex ( ) | |
messageQueue . front ( ) . getTeamIndex ( ) = = this - > world - > getThisTeamIndex ( ) ) {
2013-12-30 17:17:05 +01:00
2012-03-31 02:52:43 +02:00
messageBox . setEnabled ( true ) ;
2013-12-30 17:17:05 +01:00
2016-11-26 15:46:32 +01:00
string msgText = messageQueue . front ( ) . getText ( ) ;
2013-12-30 17:17:05 +01:00
string msgHeader = messageQueue . front ( ) . getHeader ( ) ;
if ( messageQueue . front ( ) . getMessageNotTranslated ( ) = = false ) {
2013-12-30 18:28:25 +01:00
2016-11-26 15:46:32 +01:00
msgText = lang . getScenarioString ( messageQueue . front ( ) . getText ( ) ) ;
2013-12-30 17:17:05 +01:00
msgHeader = lang . getScenarioString ( messageQueue . front ( ) . getHeader ( ) ) ;
}
2013-12-30 18:28:25 +01:00
messageBox . setText ( msgText ) ;
2013-12-30 17:17:05 +01:00
messageBox . setHeader ( msgHeader ) ;
2012-03-30 07:53:33 +02:00
break ;
}
2012-03-31 02:52:43 +02:00
popFront = true ;
2011-01-20 16:56:30 +01:00
}
}
}
void ScriptManager : : onResourceHarvested ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
2012-03-26 08:48:58 +02:00
if ( this - > rootNode = = NULL ) {
luaScript . beginCall ( " resourceHarvested " ) ;
luaScript . endCall ( ) ;
}
2011-01-20 16:56:30 +01:00
}
void ScriptManager : : onUnitCreated ( const Unit * unit ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
2012-03-26 08:48:58 +02:00
if ( this - > rootNode = = NULL ) {
2013-06-13 10:55:48 +02:00
lastCreatedUnitName = unit - > getType ( ) - > getName ( false ) ;
2012-03-26 08:48:58 +02:00
lastCreatedUnitId = unit - > getId ( ) ;
luaScript . beginCall ( " unitCreated " ) ;
luaScript . endCall ( ) ;
luaScript . beginCall ( " unitCreatedOfType_ " + unit - > getType ( ) - > getName ( ) ) ;
luaScript . endCall ( ) ;
}
2011-01-20 16:56:30 +01:00
}
void ScriptManager : : onUnitDied ( const Unit * unit ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
2012-03-26 08:48:58 +02:00
if ( this - > rootNode = = NULL ) {
if ( unit - > getLastAttackerUnitId ( ) > = 0 ) {
Unit * killer = world - > findUnitById ( unit - > getLastAttackerUnitId ( ) ) ;
2011-11-18 16:43:05 +01:00
2012-03-26 08:48:58 +02:00
if ( killer ! = NULL ) {
2013-06-13 10:55:48 +02:00
lastAttackingUnitName = killer - > getType ( ) - > getName ( false ) ;
2012-03-26 08:48:58 +02:00
lastAttackingUnitId = killer - > getId ( ) ;
2011-11-18 16:43:05 +01:00
2013-06-13 10:55:48 +02:00
lastDeadUnitKillerName = killer - > getType ( ) - > getName ( false ) ;
2012-03-26 08:48:58 +02:00
lastDeadUnitKillerId = killer - > getId ( ) ;
}
else {
lastDeadUnitKillerName = " " ;
lastDeadUnitKillerId = - 1 ;
}
2011-11-18 16:43:05 +01:00
}
2013-06-13 10:55:48 +02:00
lastAttackedUnitName = unit - > getType ( ) - > getName ( false ) ;
2012-03-26 08:48:58 +02:00
lastAttackedUnitId = unit - > getId ( ) ;
2011-11-18 16:43:05 +01:00
2013-06-13 10:55:48 +02:00
lastDeadUnitName = unit - > getType ( ) - > getName ( false ) ;
2012-03-26 08:48:58 +02:00
lastDeadUnitId = unit - > getId ( ) ;
lastDeadUnitCauseOfDeath = unit - > getCauseOfDeath ( ) ;
2011-11-16 22:43:19 +01:00
2012-03-26 08:48:58 +02:00
luaScript . beginCall ( " unitDied " ) ;
luaScript . endCall ( ) ;
}
2011-01-20 16:56:30 +01:00
}
2011-11-16 22:38:12 +01:00
void ScriptManager : : onUnitAttacked ( const Unit * unit ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-11-16 22:38:12 +01:00
2012-03-26 08:48:58 +02:00
if ( this - > rootNode = = NULL ) {
2013-06-13 10:55:48 +02:00
lastAttackedUnitName = unit - > getType ( ) - > getName ( false ) ;
2012-03-26 08:48:58 +02:00
lastAttackedUnitId = unit - > getId ( ) ;
luaScript . beginCall ( " unitAttacked " ) ;
luaScript . endCall ( ) ;
}
2011-11-16 22:38:12 +01:00
}
void ScriptManager : : onUnitAttacking ( const Unit * unit ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-11-16 22:38:12 +01:00
2012-03-26 08:48:58 +02:00
if ( this - > rootNode = = NULL ) {
2013-06-13 10:55:48 +02:00
lastAttackingUnitName = unit - > getType ( ) - > getName ( false ) ;
2012-03-26 08:48:58 +02:00
lastAttackingUnitId = unit - > getId ( ) ;
luaScript . beginCall ( " unitAttacking " ) ;
luaScript . endCall ( ) ;
}
2011-11-16 22:38:12 +01:00
}
2011-01-20 16:56:30 +01:00
void ScriptManager : : onGameOver ( bool won ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
gameWon = won ;
luaScript . beginCall ( " gameOver " ) ;
luaScript . endCall ( ) ;
}
void ScriptManager : : onTimerTriggerEvent ( ) {
2012-03-27 08:42:55 +02:00
if ( TimerTriggerEventList . empty ( ) = = true ) {
2011-01-20 16:56:30 +01:00
return ;
}
2012-03-26 08:48:58 +02:00
if ( this - > rootNode ! = NULL ) {
return ;
}
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] TimerTriggerEventList.size() = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , TimerTriggerEventList . size ( ) ) ;
2011-01-20 16:56:30 +01:00
for ( std : : map < int , TimerTriggerEvent > : : iterator iterMap = TimerTriggerEventList . begin ( ) ;
2011-09-01 01:10:43 +02:00
iterMap ! = TimerTriggerEventList . end ( ) ; + + iterMap ) {
2011-01-20 16:56:30 +01:00
TimerTriggerEvent & event = iterMap - > second ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] event.running = %d, event.startTime = %lld, event.endTime = %lld, diff = %f \n " ,
2011-07-16 05:58:52 +02:00
__FILE__ , __FUNCTION__ , __LINE__ , event . running , ( long long int ) event . startFrame , ( long long int ) event . endFrame , ( event . endFrame - event . startFrame ) ) ;
2011-01-20 16:56:30 +01:00
if ( event . running = = true ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
2012-03-27 08:42:55 +02:00
// If using an efficient timer, check if its time to trigger
// on the elapsed check
if ( event . triggerSecondsElapsed > 0 ) {
int elapsed = ( world - > getFrameCount ( ) - event . startFrame ) / GameConstants : : updateFps ;
if ( elapsed < event . triggerSecondsElapsed ) {
continue ;
}
}
2011-01-20 16:56:30 +01:00
currentTimerTriggeredEventId = iterMap - > first ;
luaScript . beginCall ( " timerTriggerEvent " ) ;
luaScript . endCall ( ) ;
2012-03-27 21:28:16 +02:00
if ( event . triggerSecondsElapsed > 0 ) {
int timerId = iterMap - > first ;
stopTimerEvent ( timerId ) ;
}
2011-01-20 16:56:30 +01:00
}
}
}
void ScriptManager : : onCellTriggerEvent ( Unit * movingUnit ) {
2012-03-27 08:42:55 +02:00
if ( CellTriggerEventList . empty ( ) = = true ) {
2011-01-20 16:56:30 +01:00
return ;
}
2012-03-26 08:48:58 +02:00
if ( this - > rootNode ! = NULL ) {
return ;
}
2011-01-20 16:56:30 +01:00
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] movingUnit = %p, CellTriggerEventList.size() = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , movingUnit , CellTriggerEventList . size ( ) ) ;
2011-01-20 16:56:30 +01:00
// remove any delayed removals
unregisterCellTriggerEvent ( - 1 ) ;
inCellTriggerEvent = true ;
if ( movingUnit ! = NULL ) {
2011-10-06 22:44:55 +02:00
//ScenarioInfo scenarioInfoStart = world->getScenario()->getInfo();
2011-10-06 20:04:59 +02:00
2011-01-20 16:56:30 +01:00
for ( std : : map < int , CellTriggerEvent > : : iterator iterMap = CellTriggerEventList . begin ( ) ;
2011-10-06 20:04:59 +02:00
iterMap ! = CellTriggerEventList . end ( ) ; + + iterMap ) {
2011-01-20 16:56:30 +01:00
CellTriggerEvent & event = iterMap - > second ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s \n " ,
2011-01-20 16:56:30 +01:00
__FILE__ , __FUNCTION__ , __LINE__ , movingUnit - > getId ( ) , event . type , movingUnit - > getPos ( ) . getString ( ) . c_str ( ) , event . sourceId , event . destId , event . destPos . getString ( ) . c_str ( ) ) ;
bool triggerEvent = false ;
2012-10-10 07:44:14 +02:00
currentCellTriggeredEventAreaEntryUnitId = 0 ;
currentCellTriggeredEventAreaExitUnitId = 0 ;
2012-10-13 07:06:53 +02:00
currentCellTriggeredEventUnitId = 0 ;
2011-01-20 16:56:30 +01:00
switch ( event . type ) {
case ctet_Unit :
{
Unit * destUnit = world - > findUnitById ( event . destId ) ;
if ( destUnit ! = NULL ) {
if ( movingUnit - > getId ( ) = = event . sourceId ) {
bool srcInDst = world - > getMap ( ) - > isInUnitTypeCells ( destUnit - > getType ( ) , destUnit - > getPos ( ) , movingUnit - > getPos ( ) ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s, destUnit->getPos() = %s, srcInDst = %d \n " ,
2011-01-20 16:56:30 +01:00
__FILE__ , __FUNCTION__ , __LINE__ , movingUnit - > getId ( ) , event . type , movingUnit - > getPos ( ) . getString ( ) . c_str ( ) , event . sourceId , event . destId , event . destPos . getString ( ) . c_str ( ) , destUnit - > getPos ( ) . getString ( ) . c_str ( ) , srcInDst ) ;
if ( srcInDst = = true ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
}
else {
srcInDst = world - > getMap ( ) - > isNextToUnitTypeCells ( destUnit - > getType ( ) , destUnit - > getPos ( ) , movingUnit - > getPos ( ) ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s, destUnit->getPos() = %s, srcInDst = %d \n " ,
2011-01-20 16:56:30 +01:00
__FILE__ , __FUNCTION__ , __LINE__ , movingUnit - > getId ( ) , event . type , movingUnit - > getPos ( ) . getString ( ) . c_str ( ) , event . sourceId , event . destId , event . destPos . getString ( ) . c_str ( ) , destUnit - > getPos ( ) . getString ( ) . c_str ( ) , srcInDst ) ;
}
triggerEvent = srcInDst ;
2012-10-13 07:06:53 +02:00
if ( triggerEvent = = true ) {
currentCellTriggeredEventUnitId = movingUnit - > getId ( ) ;
}
2011-01-20 16:56:30 +01:00
}
}
}
break ;
case ctet_UnitPos :
{
if ( movingUnit - > getId ( ) = = event . sourceId ) {
2011-09-14 01:25:13 +02:00
bool srcInDst = world - > getMap ( ) - > isInUnitTypeCells ( movingUnit - > getType ( ) , event . destPos , movingUnit - > getPos ( ) ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s, srcInDst = %d \n " ,
2011-01-20 16:56:30 +01:00
__FILE__ , __FUNCTION__ , __LINE__ , movingUnit - > getId ( ) , event . type , movingUnit - > getPos ( ) . getString ( ) . c_str ( ) , event . sourceId , event . destId , event . destPos . getString ( ) . c_str ( ) , srcInDst ) ;
if ( srcInDst = = true ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
}
triggerEvent = srcInDst ;
2012-10-13 07:06:53 +02:00
if ( triggerEvent = = true ) {
currentCellTriggeredEventUnitId = movingUnit - > getId ( ) ;
}
2011-01-20 16:56:30 +01:00
}
}
break ;
2012-05-02 08:07:11 +02:00
case ctet_UnitAreaPos :
{
if ( movingUnit - > getId ( ) = = event . sourceId ) {
bool srcInDst = false ;
2012-10-13 09:33:33 +02:00
// Cache area lookup so for each unitsize and pos its done only once
bool foundInCache = false ;
std : : map < int , std : : map < Vec2i , bool > > : : iterator iterFind1 = event . eventLookupCache . find ( movingUnit - > getType ( ) - > getSize ( ) ) ;
if ( iterFind1 ! = event . eventLookupCache . end ( ) ) {
std : : map < Vec2i , bool > : : iterator iterFind2 = iterFind1 - > second . find ( movingUnit - > getPos ( ) ) ;
if ( iterFind2 ! = iterFind1 - > second . end ( ) ) {
foundInCache = true ;
srcInDst = iterFind2 - > second ;
2012-05-02 08:07:11 +02:00
}
}
2012-10-13 09:33:33 +02:00
if ( foundInCache = = false ) {
for ( int x = event . destPos . x ; srcInDst = = false & & x < = event . destPosEnd . x ; + + x ) {
for ( int y = event . destPos . y ; srcInDst = = false & & y < = event . destPosEnd . y ; + + y ) {
srcInDst = world - > getMap ( ) - > isInUnitTypeCells ( movingUnit - > getType ( ) , Vec2i ( x , y ) , movingUnit - > getPos ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s, srcInDst = %d \n " ,
__FILE__ , __FUNCTION__ , __LINE__ , movingUnit - > getId ( ) , event . type , movingUnit - > getPos ( ) . getString ( ) . c_str ( ) , event . sourceId , event . destId , Vec2i ( x , y ) . getString ( ) . c_str ( ) , srcInDst ) ;
}
}
event . eventLookupCache [ movingUnit - > getType ( ) - > getSize ( ) ] [ movingUnit - > getPos ( ) ] = srcInDst ;
}
2012-05-02 08:07:11 +02:00
if ( srcInDst = = true ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-05-02 08:07:11 +02:00
}
triggerEvent = srcInDst ;
2012-10-13 07:06:53 +02:00
if ( triggerEvent = = true ) {
currentCellTriggeredEventUnitId = movingUnit - > getId ( ) ;
}
2012-05-02 08:07:11 +02:00
}
}
break ;
2011-01-20 16:56:30 +01:00
case ctet_Faction :
{
Unit * destUnit = world - > findUnitById ( event . destId ) ;
if ( destUnit ! = NULL & &
movingUnit - > getFactionIndex ( ) = = event . sourceId ) {
bool srcInDst = world - > getMap ( ) - > isInUnitTypeCells ( destUnit - > getType ( ) , destUnit - > getPos ( ) , movingUnit - > getPos ( ) ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s, srcInDst = %d \n " ,
2011-01-20 16:56:30 +01:00
__FILE__ , __FUNCTION__ , __LINE__ , movingUnit - > getId ( ) , event . type , movingUnit - > getPos ( ) . getString ( ) . c_str ( ) , event . sourceId , event . destId , event . destPos . getString ( ) . c_str ( ) , srcInDst ) ;
if ( srcInDst = = true ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
}
else {
srcInDst = world - > getMap ( ) - > isNextToUnitTypeCells ( destUnit - > getType ( ) , destUnit - > getPos ( ) , movingUnit - > getPos ( ) ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s, destUnit->getPos() = %s, srcInDst = %d \n " ,
2011-01-20 16:56:30 +01:00
__FILE__ , __FUNCTION__ , __LINE__ , movingUnit - > getId ( ) , event . type , movingUnit - > getPos ( ) . getString ( ) . c_str ( ) , event . sourceId , event . destId , event . destPos . getString ( ) . c_str ( ) , destUnit - > getPos ( ) . getString ( ) . c_str ( ) , srcInDst ) ;
}
triggerEvent = srcInDst ;
2012-10-13 07:06:53 +02:00
if ( triggerEvent = = true ) {
currentCellTriggeredEventUnitId = movingUnit - > getId ( ) ;
}
2011-01-20 16:56:30 +01:00
}
}
break ;
case ctet_FactionPos :
{
if ( movingUnit - > getFactionIndex ( ) = = event . sourceId ) {
2011-09-14 01:20:26 +02:00
//printf("ctet_FactionPos event.destPos = [%s], movingUnit->getPos() [%s]\n",event.destPos.getString().c_str(),movingUnit->getPos().getString().c_str());
bool srcInDst = world - > getMap ( ) - > isInUnitTypeCells ( movingUnit - > getType ( ) , event . destPos , movingUnit - > getPos ( ) ) ;
2011-01-20 16:56:30 +01:00
if ( srcInDst = = true ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
}
triggerEvent = srcInDst ;
2012-10-13 07:06:53 +02:00
if ( triggerEvent = = true ) {
currentCellTriggeredEventUnitId = movingUnit - > getId ( ) ;
}
2011-01-20 16:56:30 +01:00
}
}
break ;
2012-05-02 08:07:11 +02:00
case ctet_FactionAreaPos :
{
if ( movingUnit - > getFactionIndex ( ) = = event . sourceId ) {
2012-10-13 07:06:53 +02:00
//if(event.sourceId == 1) printf("ctet_FactionPos event.destPos = [%s], movingUnit->getPos() [%s] Unit id = %d\n",event.destPos.getString().c_str(),movingUnit->getPos().getString().c_str(),movingUnit->getId());
2012-05-02 08:07:11 +02:00
bool srcInDst = false ;
2012-10-13 09:33:33 +02:00
// Cache area lookup so for each unitsize and pos its done only once
bool foundInCache = false ;
std : : map < int , std : : map < Vec2i , bool > > : : iterator iterFind1 = event . eventLookupCache . find ( movingUnit - > getType ( ) - > getSize ( ) ) ;
if ( iterFind1 ! = event . eventLookupCache . end ( ) ) {
std : : map < Vec2i , bool > : : iterator iterFind2 = iterFind1 - > second . find ( movingUnit - > getPos ( ) ) ;
if ( iterFind2 ! = iterFind1 - > second . end ( ) ) {
foundInCache = true ;
srcInDst = iterFind2 - > second ;
}
}
if ( foundInCache = = false ) {
for ( int x = event . destPos . x ; srcInDst = = false & & x < = event . destPosEnd . x ; + + x ) {
for ( int y = event . destPos . y ; srcInDst = = false & & y < = event . destPosEnd . y ; + + y ) {
srcInDst = world - > getMap ( ) - > isInUnitTypeCells ( movingUnit - > getType ( ) , Vec2i ( x , y ) , movingUnit - > getPos ( ) ) ;
if ( srcInDst = = true ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-10-13 09:33:33 +02:00
}
2012-05-02 08:07:11 +02:00
}
}
2012-10-13 09:33:33 +02:00
event . eventLookupCache [ movingUnit - > getType ( ) - > getSize ( ) ] [ movingUnit - > getPos ( ) ] = srcInDst ;
2012-05-02 08:07:11 +02:00
}
2012-10-13 09:33:33 +02:00
2012-05-02 08:07:11 +02:00
triggerEvent = srcInDst ;
2012-10-13 07:06:53 +02:00
if ( triggerEvent = = true ) {
//printf("!!!UNIT IN AREA!!! Faction area pos, moving unit faction= %d, trigger faction = %d, unit id = %d\n",movingUnit->getFactionIndex(),event.sourceId,movingUnit->getId());
currentCellTriggeredEventUnitId = movingUnit - > getId ( ) ;
}
2012-05-02 08:07:11 +02:00
}
}
break ;
2012-10-10 07:44:14 +02:00
case ctet_AreaPos :
{
// Is the unit already in the cell range? If no check if they are entering it
if ( event . eventStateInfo . find ( movingUnit - > getId ( ) ) = = event . eventStateInfo . end ( ) ) {
//printf("ctet_FactionPos event.destPos = [%s], movingUnit->getPos() [%s]\n",event.destPos.getString().c_str(),movingUnit->getPos().getString().c_str());
bool srcInDst = false ;
for ( int x = event . destPos . x ; srcInDst = = false & & x < = event . destPosEnd . x ; + + x ) {
for ( int y = event . destPos . y ; srcInDst = = false & & y < = event . destPosEnd . y ; + + y ) {
srcInDst = world - > getMap ( ) - > isInUnitTypeCells ( movingUnit - > getType ( ) , Vec2i ( x , y ) , movingUnit - > getPos ( ) ) ;
if ( srcInDst = = true ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-10-10 07:44:14 +02:00
currentCellTriggeredEventAreaEntryUnitId = movingUnit - > getId ( ) ;
event . eventStateInfo [ movingUnit - > getId ( ) ] = Vec2i ( x , y ) . getString ( ) ;
}
}
}
triggerEvent = srcInDst ;
2012-10-13 07:06:53 +02:00
if ( triggerEvent = = true ) {
currentCellTriggeredEventUnitId = movingUnit - > getId ( ) ;
}
2012-10-10 07:44:14 +02:00
}
// If unit is already in cell range check if they are leaving?
else {
bool srcInDst = false ;
for ( int x = event . destPos . x ; srcInDst = = false & & x < = event . destPosEnd . x ; + + x ) {
for ( int y = event . destPos . y ; srcInDst = = false & & y < = event . destPosEnd . y ; + + y ) {
srcInDst = world - > getMap ( ) - > isInUnitTypeCells ( movingUnit - > getType ( ) , Vec2i ( x , y ) , movingUnit - > getPos ( ) ) ;
if ( srcInDst = = true ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-10-10 07:44:14 +02:00
//event.eventStateInfo[movingUnit->getId()] = Vec2i(x,y);
}
}
}
triggerEvent = ( srcInDst = = false ) ;
2012-10-13 07:06:53 +02:00
if ( triggerEvent = = true ) {
currentCellTriggeredEventUnitId = movingUnit - > getId ( ) ;
}
2012-10-10 07:44:14 +02:00
if ( triggerEvent = = true ) {
currentCellTriggeredEventAreaExitUnitId = movingUnit - > getId ( ) ;
event . eventStateInfo . erase ( movingUnit - > getId ( ) ) ;
}
}
}
break ;
2011-01-20 16:56:30 +01:00
}
if ( triggerEvent = = true ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
currentCellTriggeredEventId = iterMap - > first ;
event . triggerCount + + ;
luaScript . beginCall ( " cellTriggerEvent " ) ;
luaScript . endCall ( ) ;
}
2011-10-06 20:04:59 +02:00
2011-10-06 22:44:55 +02:00
// ScenarioInfo scenarioInfoEnd = world->getScenario()->getInfo();
// if(scenarioInfoStart.file != scenarioInfoEnd.file) {
// break;
// }
2011-01-20 16:56:30 +01:00
}
}
inCellTriggerEvent = false ;
}
// ========================== lua wrappers ===============================================
2013-11-19 07:14:06 +01:00
string ScriptManager : : wrapString ( const string & str , int wrapCount ) {
2011-01-20 16:56:30 +01:00
string returnString ;
int letterCount = 0 ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) str . size ( ) ; + + i ) {
if ( letterCount > wrapCount & & str [ i ] = = ' ' ) {
returnString + = ' \n ' ;
2011-01-20 16:56:30 +01:00
letterCount = 0 ;
}
else
{
2013-11-19 07:14:06 +01:00
returnString + = str [ i ] ;
2011-01-20 16:56:30 +01:00
}
+ + letterCount ;
}
return returnString ;
}
2012-03-30 07:53:33 +02:00
void ScriptManager : : networkShowMessageForFaction ( const string & text , const string & header , int factionIndex ) {
messageQueue . push_back ( ScriptManagerMessage ( text , header , factionIndex ) ) ;
2013-12-30 11:01:47 +01:00
thisScriptManager - > onMessageBoxOk ( false ) ;
2012-03-30 07:53:33 +02:00
}
void ScriptManager : : networkShowMessageForTeam ( const string & text , const string & header , int teamIndex ) {
// Team indexes are 0 based internally (but 1 based in the lua script) so convert
teamIndex - - ;
messageQueue . push_back ( ScriptManagerMessage ( text , header , - 1 , teamIndex ) ) ;
2013-12-30 11:01:47 +01:00
thisScriptManager - > onMessageBoxOk ( false ) ;
2012-03-30 07:53:33 +02:00
}
2012-10-10 20:28:55 +02:00
void ScriptManager : : networkSetCameraPositionForFaction ( int factionIndex , const Vec2i & pos ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-10-10 20:28:55 +02:00
if ( factionIndex = = this - > world - > getThisFactionIndex ( ) ) {
gameCamera - > centerXZ ( pos . x , pos . y ) ;
}
}
void ScriptManager : : networkSetCameraPositionForTeam ( int teamIndex , const Vec2i & pos ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-10-10 20:28:55 +02:00
if ( teamIndex = = this - > world - > getThisTeamIndex ( ) ) {
gameCamera - > centerXZ ( pos . x , pos . y ) ;
}
}
2011-01-20 16:56:30 +01:00
void ScriptManager : : showMessage ( const string & text , const string & header ) {
2012-03-26 08:48:58 +02:00
messageQueue . push_back ( ScriptManagerMessage ( text , header ) ) ;
2013-12-30 11:01:47 +01:00
thisScriptManager - > onMessageBoxOk ( false ) ;
2011-01-20 16:56:30 +01:00
}
void ScriptManager : : clearDisplayText ( ) {
displayText = " " ;
}
void ScriptManager : : setDisplayText ( const string & text ) {
displayText = wrapString ( Lang : : getInstance ( ) . getScenarioString ( text ) , displayTextWrapCount ) ;
}
2011-03-19 13:19:22 +01:00
void ScriptManager : : addConsoleText ( const string & text ) {
world - > addConsoleText ( text ) ;
}
2011-11-15 18:39:49 +01:00
void ScriptManager : : addConsoleLangText ( const char * fmt , . . . ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-11-15 18:39:49 +01:00
va_list argList ;
va_start ( argList , fmt ) ;
const int max_debug_buffer_size = 8096 ;
char szBuf [ max_debug_buffer_size ] = " " ;
vsnprintf ( szBuf , max_debug_buffer_size - 1 , fmt , argList ) ;
world - > addConsoleTextWoLang ( szBuf ) ;
va_end ( argList ) ;
}
2011-03-19 13:19:22 +01:00
2011-01-20 16:56:30 +01:00
void ScriptManager : : DisplayFormattedText ( const char * fmt , . . . ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
va_list argList ;
va_start ( argList , fmt ) ;
const int max_debug_buffer_size = 8096 ;
char szBuf [ max_debug_buffer_size ] = " " ;
vsnprintf ( szBuf , max_debug_buffer_size - 1 , fmt , argList ) ;
displayText = szBuf ;
va_end ( argList ) ;
}
2011-11-03 19:24:02 +01:00
void ScriptManager : : DisplayFormattedLangText ( const char * fmt , . . . ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-11-03 19:24:02 +01:00
va_list argList ;
va_start ( argList , fmt ) ;
const int max_debug_buffer_size = 8096 ;
char szBuf [ max_debug_buffer_size ] = " " ;
vsnprintf ( szBuf , max_debug_buffer_size - 1 , fmt , argList ) ;
displayText = szBuf ;
2011-01-20 16:56:30 +01:00
2011-11-03 19:24:02 +01:00
va_end ( argList ) ;
}
2011-01-20 16:56:30 +01:00
void ScriptManager : : setCameraPosition ( const Vec2i & pos ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
gameCamera - > centerXZ ( pos . x , pos . y ) ;
}
2014-02-04 21:21:06 +01:00
void ScriptManager : : shakeCamera ( int shakeIntensity , int shakeDuration , bool cameraDistanceAffected , int unitId ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
if ( cameraDistanceAffected ) {
Unit * unit = world - > findUnitById ( unitId ) ;
2014-12-01 00:30:02 +01:00
if ( unit ) {
gameCamera - > shake ( shakeDuration , shakeIntensity , cameraDistanceAffected , unit - > getCurrMidHeightVector ( ) ) ;
}
}
else {
2014-02-04 21:21:06 +01:00
gameCamera - > shake ( shakeDuration , shakeIntensity , cameraDistanceAffected , Vec3f ( 0.f , 0.f , 0.f ) ) ;
}
}
2011-01-20 16:56:30 +01:00
void ScriptManager : : createUnit ( const string & unitName , int factionIndex , Vec2i pos ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%s] factionIndex = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , unitName . c_str ( ) , factionIndex ) ;
2011-01-20 16:56:30 +01:00
world - > createUnit ( unitName , factionIndex , pos ) ;
}
2012-02-21 22:56:20 +01:00
void ScriptManager : : createUnitNoSpacing ( const string & unitName , int factionIndex , Vec2i pos ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%s] factionIndex = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , unitName . c_str ( ) , factionIndex ) ;
2012-02-21 22:56:20 +01:00
world - > createUnit ( unitName , factionIndex , pos , false ) ;
}
2014-11-12 15:14:52 +01:00
void ScriptManager : : setLockedUnitForFaction ( const string & unitName , int factionIndex , bool lock ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%s] factionIndex = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , unitName . c_str ( ) , factionIndex ) ;
if ( world - > getFactionCount ( ) > factionIndex ) {
const UnitType * ut = world - > getFaction ( factionIndex ) - > getType ( ) - > getUnitType ( unitName ) ;
world - > getFaction ( factionIndex ) - > setLockedUnitForFaction ( ut , lock ) ;
} else {
throw megaglest_runtime_error ( " Invalid faction index in setLockedUnitForFaction: " + intToStr ( factionIndex ) , true ) ;
}
}
2011-01-29 13:42:18 +01:00
void ScriptManager : : destroyUnit ( int unitId ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , unitId ) ;
2011-01-29 13:42:18 +01:00
Unit * unit = world - > findUnitById ( unitId ) ;
if ( unit ! = NULL ) {
// Make sure they die
2013-12-18 02:35:51 +01:00
bool unit_dead = unit - > decHp ( unit - > getHp ( ) * unit - > getHp ( ) ) ;
if ( unit_dead = = false ) {
2013-12-30 16:57:51 +01:00
throw megaglest_runtime_error ( " unit_dead == false " , true ) ;
2013-12-18 02:35:51 +01:00
}
2011-01-29 13:42:18 +01:00
unit - > kill ( ) ;
// If called from an existing die event we get a stack overflow
//onUnitDied(unit);
}
}
2011-11-16 22:38:12 +01:00
void ScriptManager : : giveKills ( int unitId , int amount ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , unitId ) ;
2011-11-16 22:38:12 +01:00
Unit * unit = world - > findUnitById ( unitId ) ;
if ( unit ! = NULL ) {
2013-12-30 16:57:51 +01:00
for ( int index = 1 ; index < = amount ; + + index ) {
unit - > incKills ( - 1 ) ;
2011-11-16 22:38:12 +01:00
}
}
}
2011-01-29 13:42:18 +01:00
void ScriptManager : : playStaticSound ( const string & playSound ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] playSound [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , playSound . c_str ( ) ) ;
2011-01-29 13:42:18 +01:00
world - > playStaticSound ( playSound ) ;
}
void ScriptManager : : playStreamingSound ( const string & playSound ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] playSound [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , playSound . c_str ( ) ) ;
2011-01-29 13:42:18 +01:00
world - > playStreamingSound ( playSound ) ;
}
void ScriptManager : : stopStreamingSound ( const string & playSound ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] playSound [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , playSound . c_str ( ) ) ;
2011-01-29 13:42:18 +01:00
world - > stopStreamingSound ( playSound ) ;
}
void ScriptManager : : stopAllSound ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-29 13:42:18 +01:00
world - > stopAllSound ( ) ;
}
2012-05-22 08:17:56 +02:00
void ScriptManager : : playStaticVideo ( const string & playVideo ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] playVideo [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , playVideo . c_str ( ) ) ;
2012-05-22 08:17:56 +02:00
world - > playStaticVideo ( playVideo ) ;
}
void ScriptManager : : playStreamingVideo ( const string & playVideo ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] playVideo [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , playVideo . c_str ( ) ) ;
2012-05-22 08:17:56 +02:00
world - > playStreamingVideo ( playVideo ) ;
}
void ScriptManager : : stopStreamingVideo ( const string & playVideo ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] playVideo [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , playVideo . c_str ( ) ) ;
2012-05-22 08:17:56 +02:00
world - > stopStreamingVideo ( playVideo ) ;
}
void ScriptManager : : stopAllVideo ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-05-22 08:17:56 +02:00
world - > stopAllVideo ( ) ;
}
2011-01-30 00:50:21 +01:00
void ScriptManager : : togglePauseGame ( int pauseStatus ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] pauseStatus = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , pauseStatus ) ;
2011-12-28 08:26:16 +01:00
world - > togglePauseGame ( ( pauseStatus ! = 0 ) , true ) ;
2011-01-30 00:50:21 +01:00
}
2011-01-29 13:42:18 +01:00
void ScriptManager : : morphToUnit ( int unitId , const string & morphName , int ignoreRequirements ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%d] morphName [%s] forceUpgradesIfRequired = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , unitId , morphName . c_str ( ) , ignoreRequirements ) ;
2013-10-03 07:44:50 +02:00
2011-01-29 18:42:34 +01:00
world - > morphToUnit ( unitId , morphName , ( ignoreRequirements = = 1 ) ) ;
2011-01-29 13:42:18 +01:00
}
2011-01-29 18:52:53 +01:00
void ScriptManager : : moveToUnit ( int unitId , int destUnitId ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%d] destUnitId [%d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , unitId , destUnitId ) ;
2013-10-03 07:44:50 +02:00
2011-01-29 18:52:53 +01:00
world - > moveToUnit ( unitId , destUnitId ) ;
}
2011-01-20 16:56:30 +01:00
void ScriptManager : : giveResource ( const string & resourceName , int factionIndex , int amount ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
world - > giveResource ( resourceName , factionIndex , amount ) ;
}
void ScriptManager : : givePositionCommand ( int unitId , const string & commandName , const Vec2i & pos ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
world - > givePositionCommand ( unitId , commandName , pos ) ;
}
void ScriptManager : : giveAttackCommand ( int unitId , int unitToAttackId ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
world - > giveAttackCommand ( unitId , unitToAttackId ) ;
}
void ScriptManager : : giveProductionCommand ( int unitId , const string & producedName ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
world - > giveProductionCommand ( unitId , producedName ) ;
}
void ScriptManager : : giveUpgradeCommand ( int unitId , const string & producedName ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
world - > giveUpgradeCommand ( unitId , producedName ) ;
}
2011-01-29 13:42:18 +01:00
void ScriptManager : : giveAttackStoppedCommand ( int unitId , const string & itemName , int ignoreRequirements ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-29 18:42:34 +01:00
world - > giveAttackStoppedCommand ( unitId , itemName , ( ignoreRequirements = = 1 ) ) ;
2011-01-29 13:42:18 +01:00
}
2011-01-20 16:56:30 +01:00
void ScriptManager : : disableAi ( int factionIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2013-12-30 16:57:51 +01:00
if ( factionIndex > = 0 & & factionIndex < GameConstants : : maxPlayers ) {
2011-01-20 16:56:30 +01:00
playerModifiers [ factionIndex ] . disableAi ( ) ;
disableConsume ( factionIndex ) ; // by this we stay somehow compatible with old behaviour
}
}
void ScriptManager : : enableAi ( int factionIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2013-12-30 16:57:51 +01:00
if ( factionIndex > = 0 & & factionIndex < GameConstants : : maxPlayers ) {
2011-01-20 16:56:30 +01:00
playerModifiers [ factionIndex ] . enableAi ( ) ;
}
}
2013-12-30 16:57:51 +01:00
bool ScriptManager : : getAiEnabled ( int factionIndex ) {
2013-10-03 07:44:50 +02:00
2013-12-30 16:57:51 +01:00
if ( factionIndex > = 0 & & factionIndex < GameConstants : : maxPlayers ) {
2011-01-20 16:56:30 +01:00
return playerModifiers [ factionIndex ] . getAiEnabled ( ) ;
}
return false ;
}
2013-12-30 16:57:51 +01:00
void ScriptManager : : disableConsume ( int factionIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2013-12-30 16:57:51 +01:00
if ( factionIndex > = 0 & & factionIndex < GameConstants : : maxPlayers ) {
2011-01-20 16:56:30 +01:00
playerModifiers [ factionIndex ] . disableConsume ( ) ;
}
}
2013-12-30 16:57:51 +01:00
void ScriptManager : : enableConsume ( int factionIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2013-12-30 16:57:51 +01:00
if ( factionIndex > = 0 & & factionIndex < GameConstants : : maxPlayers ) {
2011-01-20 16:56:30 +01:00
playerModifiers [ factionIndex ] . enableConsume ( ) ;
}
}
2013-12-30 16:57:51 +01:00
bool ScriptManager : : getConsumeEnabled ( int factionIndex ) {
2013-10-03 07:44:50 +02:00
2013-12-30 16:57:51 +01:00
if ( factionIndex > = 0 & & factionIndex < GameConstants : : maxPlayers ) {
2011-01-20 16:56:30 +01:00
return playerModifiers [ factionIndex ] . getConsumeEnabled ( ) ;
}
return false ;
}
int ScriptManager : : registerCellTriggerEventForUnitToUnit ( int sourceUnitId , int destUnitId ) {
CellTriggerEvent trigger ;
trigger . type = ctet_Unit ;
trigger . sourceId = sourceUnitId ;
trigger . destId = destUnitId ;
int eventId = currentEventId + + ;
CellTriggerEventList [ eventId ] = trigger ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] Unit: %d will trigger cell event when reaching unit: %d, eventId = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , sourceUnitId , destUnitId , eventId ) ;
2011-01-20 16:56:30 +01:00
return eventId ;
}
int ScriptManager : : registerCellTriggerEventForUnitToLocation ( int sourceUnitId , const Vec2i & pos ) {
CellTriggerEvent trigger ;
trigger . type = ctet_UnitPos ;
trigger . sourceId = sourceUnitId ;
trigger . destPos = pos ;
int eventId = currentEventId + + ;
CellTriggerEventList [ eventId ] = trigger ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] Unit: %d will trigger cell event when reaching pos: %s, eventId = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , sourceUnitId , pos . getString ( ) . c_str ( ) , eventId ) ;
2011-01-20 16:56:30 +01:00
return eventId ;
}
2012-05-02 08:07:11 +02:00
int ScriptManager : : registerCellAreaTriggerEventForUnitToLocation ( int sourceUnitId , const Vec4i & pos ) {
CellTriggerEvent trigger ;
trigger . type = ctet_UnitAreaPos ;
trigger . sourceId = sourceUnitId ;
trigger . destPos . x = pos . x ;
trigger . destPos . y = pos . y ;
trigger . destPosEnd . x = pos . z ;
trigger . destPosEnd . y = pos . w ;
int eventId = currentEventId + + ;
CellTriggerEventList [ eventId ] = trigger ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] Unit: %d will trigger cell event when reaching pos: %s, eventId = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , sourceUnitId , pos . getString ( ) . c_str ( ) , eventId ) ;
2012-05-02 08:07:11 +02:00
return eventId ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : registerCellTriggerEventForFactionToUnit ( int sourceFactionId , int destUnitId ) {
CellTriggerEvent trigger ;
trigger . type = ctet_Faction ;
trigger . sourceId = sourceFactionId ;
trigger . destId = destUnitId ;
int eventId = currentEventId + + ;
CellTriggerEventList [ eventId ] = trigger ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] Faction: %d will trigger cell event when reaching unit: %d, eventId = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , sourceFactionId , destUnitId , eventId ) ;
2011-01-20 16:56:30 +01:00
return eventId ;
}
int ScriptManager : : registerCellTriggerEventForFactionToLocation ( int sourceFactionId , const Vec2i & pos ) {
CellTriggerEvent trigger ;
trigger . type = ctet_FactionPos ;
trigger . sourceId = sourceFactionId ;
trigger . destPos = pos ;
int eventId = currentEventId + + ;
CellTriggerEventList [ eventId ] = trigger ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d]Faction: %d will trigger cell event when reaching pos: %s, eventId = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , sourceFactionId , pos . getString ( ) . c_str ( ) , eventId ) ;
2011-01-20 16:56:30 +01:00
return eventId ;
}
2012-05-02 08:07:11 +02:00
int ScriptManager : : registerCellAreaTriggerEventForFactionToLocation ( int sourceFactionId , const Vec4i & pos ) {
CellTriggerEvent trigger ;
trigger . type = ctet_FactionAreaPos ;
trigger . sourceId = sourceFactionId ;
trigger . destPos . x = pos . x ;
trigger . destPos . y = pos . y ;
trigger . destPosEnd . x = pos . z ;
trigger . destPosEnd . y = pos . w ;
int eventId = currentEventId + + ;
CellTriggerEventList [ eventId ] = trigger ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d]Faction: %d will trigger cell event when reaching pos: %s, eventId = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , sourceFactionId , pos . getString ( ) . c_str ( ) , eventId ) ;
2012-05-02 08:07:11 +02:00
return eventId ;
}
2012-10-10 07:44:14 +02:00
int ScriptManager : : registerCellAreaTriggerEvent ( const Vec4i & pos ) {
CellTriggerEvent trigger ;
trigger . type = ctet_AreaPos ;
trigger . sourceId = - 1 ;
trigger . destPos . x = pos . x ;
trigger . destPos . y = pos . y ;
trigger . destPosEnd . x = pos . z ;
trigger . destPosEnd . y = pos . w ;
int eventId = currentEventId + + ;
CellTriggerEventList [ eventId ] = trigger ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] trigger cell event when reaching pos: %s, eventId = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , pos . getString ( ) . c_str ( ) , eventId ) ;
2012-10-10 07:44:14 +02:00
return eventId ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : getCellTriggerEventCount ( int eventId ) {
int result = 0 ;
if ( CellTriggerEventList . find ( eventId ) ! = CellTriggerEventList . end ( ) ) {
result = CellTriggerEventList [ eventId ] . triggerCount ;
}
return result ;
}
void ScriptManager : : unregisterCellTriggerEvent ( int eventId ) {
if ( CellTriggerEventList . find ( eventId ) ! = CellTriggerEventList . end ( ) ) {
if ( inCellTriggerEvent = = false ) {
CellTriggerEventList . erase ( eventId ) ;
}
else {
unRegisterCellTriggerEventList . push_back ( eventId ) ;
}
}
if ( inCellTriggerEvent = = false ) {
2011-09-01 01:10:43 +02:00
if ( unRegisterCellTriggerEventList . empty ( ) = = false ) {
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) unRegisterCellTriggerEventList . size ( ) ; + + i ) {
2011-01-20 16:56:30 +01:00
int delayedEventId = unRegisterCellTriggerEventList [ i ] ;
2017-10-10 04:09:36 +02:00
CellTriggerEventList . erase ( delayedEventId ) ;
2011-01-20 16:56:30 +01:00
}
unRegisterCellTriggerEventList . clear ( ) ;
}
}
}
int ScriptManager : : startTimerEvent ( ) {
TimerTriggerEvent trigger ;
trigger . running = true ;
2011-07-16 05:58:52 +02:00
//trigger.startTime = time(NULL);
trigger . startFrame = world - > getFrameCount ( ) ;
//trigger.endTime = 0;
trigger . endFrame = 0 ;
2011-01-20 16:56:30 +01:00
int eventId = currentEventId + + ;
TimerTriggerEventList [ eventId ] = trigger ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] TimerTriggerEventList.size() = %d, eventId = %d, trigger.startTime = %lld, trigger.endTime = %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , TimerTriggerEventList . size ( ) , eventId , ( long long int ) trigger . startFrame , ( long long int ) trigger . endFrame ) ;
2011-01-20 16:56:30 +01:00
return eventId ;
}
2012-03-27 08:42:55 +02:00
int ScriptManager : : startEfficientTimerEvent ( int triggerSecondsElapsed ) {
TimerTriggerEvent trigger ;
trigger . running = true ;
//trigger.startTime = time(NULL);
trigger . startFrame = world - > getFrameCount ( ) ;
//trigger.endTime = 0;
trigger . endFrame = 0 ;
trigger . triggerSecondsElapsed = triggerSecondsElapsed ;
int eventId = currentEventId + + ;
TimerTriggerEventList [ eventId ] = trigger ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] TimerTriggerEventList.size() = %d, eventId = %d, trigger.startTime = %lld, trigger.endTime = %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , TimerTriggerEventList . size ( ) , eventId , ( long long int ) trigger . startFrame , ( long long int ) trigger . endFrame ) ;
2012-03-27 08:42:55 +02:00
return eventId ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : resetTimerEvent ( int eventId ) {
int result = 0 ;
if ( TimerTriggerEventList . find ( eventId ) ! = TimerTriggerEventList . end ( ) ) {
TimerTriggerEvent & trigger = TimerTriggerEventList [ eventId ] ;
result = getTimerEventSecondsElapsed ( eventId ) ;
2011-07-16 05:58:52 +02:00
//trigger.startTime = time(NULL);
trigger . startFrame = world - > getFrameCount ( ) ;
//trigger.endTime = 0;
trigger . endFrame = 0 ;
2011-01-20 16:56:30 +01:00
trigger . running = true ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] TimerTriggerEventList.size() = %d, eventId = %d, trigger.startTime = %lld, trigger.endTime = %lld, result = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , TimerTriggerEventList . size ( ) , eventId , ( long long int ) trigger . startFrame , ( long long int ) trigger . endFrame , result ) ;
2011-01-20 16:56:30 +01:00
}
return result ;
}
int ScriptManager : : stopTimerEvent ( int eventId ) {
int result = 0 ;
if ( TimerTriggerEventList . find ( eventId ) ! = TimerTriggerEventList . end ( ) ) {
TimerTriggerEvent & trigger = TimerTriggerEventList [ eventId ] ;
2011-07-16 05:58:52 +02:00
//trigger.endTime = time(NULL);
trigger . endFrame = world - > getFrameCount ( ) ;
2011-01-20 16:56:30 +01:00
trigger . running = false ;
result = getTimerEventSecondsElapsed ( eventId ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] TimerTriggerEventList.size() = %d, eventId = %d, trigger.startTime = %lld, trigger.endTime = %lld, result = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , TimerTriggerEventList . size ( ) , eventId , ( long long int ) trigger . startFrame , ( long long int ) trigger . endFrame , result ) ;
2011-01-20 16:56:30 +01:00
}
return result ;
}
int ScriptManager : : getTimerEventSecondsElapsed ( int eventId ) {
int result = 0 ;
if ( TimerTriggerEventList . find ( eventId ) ! = TimerTriggerEventList . end ( ) ) {
TimerTriggerEvent & trigger = TimerTriggerEventList [ eventId ] ;
if ( trigger . running ) {
2011-07-16 05:58:52 +02:00
//result = (int)difftime(time(NULL),trigger.startTime);
result = ( world - > getFrameCount ( ) - trigger . startFrame ) / GameConstants : : updateFps ;
2011-01-20 16:56:30 +01:00
}
else {
2011-07-16 05:58:52 +02:00
//result = (int)difftime(trigger.endTime,trigger.startTime);
result = ( trigger . endFrame - trigger . startFrame ) / GameConstants : : updateFps ;
2011-01-20 16:56:30 +01:00
}
2011-07-16 05:58:52 +02:00
//printf("Timer event id = %d seconmds elapsed = %d\n",eventId,result);
2011-01-20 16:56:30 +01:00
}
return result ;
}
void ScriptManager : : setPlayerAsWinner ( int factionIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
2013-10-03 07:44:50 +02:00
2013-12-30 16:57:51 +01:00
if ( factionIndex > = 0 & & factionIndex < GameConstants : : maxPlayers ) {
2011-01-20 16:56:30 +01:00
playerModifiers [ factionIndex ] . setAsWinner ( ) ;
}
}
void ScriptManager : : endGame ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
gameOver = true ;
}
void ScriptManager : : startPerformanceTimer ( ) {
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
if ( world - > getGame ( ) = = NULL ) {
2013-12-30 16:57:51 +01:00
throw megaglest_runtime_error ( " #1 world->getGame() = = NULL " ,true) ;
2011-01-20 16:56:30 +01:00
}
world - > getGame ( ) - > startPerformanceTimer ( ) ;
}
void ScriptManager : : endPerformanceTimer ( ) {
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
if ( world - > getGame ( ) = = NULL ) {
2013-12-30 16:57:51 +01:00
throw megaglest_runtime_error ( " #2 world->getGame() = = NULL " ,true) ;
2011-01-20 16:56:30 +01:00
}
world - > getGame ( ) - > endPerformanceTimer ( ) ;
}
Vec2i ScriptManager : : getPerformanceTimerResults ( ) {
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
if ( world - > getGame ( ) = = NULL ) {
2013-12-30 16:57:51 +01:00
throw megaglest_runtime_error ( " #3 world->getGame() = = NULL " ,true) ;
2011-01-20 16:56:30 +01:00
}
return world - > getGame ( ) - > getPerformanceTimerResults ( ) ;
}
Vec2i ScriptManager : : getStartLocation ( int factionIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
return world - > getStartLocation ( factionIndex ) ;
}
Vec2i ScriptManager : : getUnitPosition ( int unitId ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-10 21:56:52 +02:00
Vec2i result = world - > getUnitPosition ( unitId ) ;
2012-10-11 08:10:21 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s] unitId = %d, pos [%s] \n " , __FUNCTION__ , unitId , result . getString ( ) . c_str ( ) ) ;
2012-10-10 21:56:52 +02:00
return result ;
2011-01-20 16:56:30 +01:00
}
2012-04-11 07:41:40 +02:00
void ScriptManager : : setUnitPosition ( int unitId , Vec2i pos ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2020-12-13 13:22:04 +01:00
world - > setUnitPosition ( unitId , pos ) ;
2012-04-11 07:41:40 +02:00
}
2012-09-25 09:05:52 +02:00
void ScriptManager : : addCellMarker ( Vec2i pos , int factionIndex , const string & note , const string & textureFile ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2013-02-05 23:00:50 +01:00
world - > addCellMarker ( pos , factionIndex , note , textureFile ) ;
2012-09-25 09:05:52 +02:00
}
void ScriptManager : : removeCellMarker ( Vec2i pos , int factionIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2020-12-13 13:22:04 +01:00
world - > removeCellMarker ( pos , factionIndex ) ;
2012-09-25 09:05:52 +02:00
}
2012-10-13 07:06:53 +02:00
void ScriptManager : : showMarker ( Vec2i pos , int factionIndex , const string & note , const string & textureFile , int flashCount ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2013-02-05 23:00:50 +01:00
world - > showMarker ( pos , factionIndex , note , textureFile , flashCount ) ;
2012-10-13 07:06:53 +02:00
}
2012-03-31 22:17:19 +02:00
int ScriptManager : : getIsUnitAlive ( int unitId ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-03-31 22:17:19 +02:00
return world - > getIsUnitAlive ( unitId ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : getUnitFaction ( int unitId ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
return world - > getUnitFactionIndex ( unitId ) ;
}
2012-05-21 22:15:37 +02:00
const string ScriptManager : : getUnitName ( int unitId ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2014-12-01 00:30:02 +01:00
string result = " " ;
Unit * unit = world - > findUnitById ( unitId ) ;
if ( unit ) {
result = world - > findUnitById ( unitId ) - > getType ( ) - > getName ( false ) ;
}
return result ;
2014-08-09 00:48:04 +02:00
}
const string ScriptManager : : getUnitDisplayName ( int unitId ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-05-21 22:15:37 +02:00
return world - > getUnitName ( unitId ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : getResourceAmount ( const string & resourceName , int factionIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
return world - > getResourceAmount ( resourceName , factionIndex ) ;
}
const string & ScriptManager : : getLastCreatedUnitName ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
return lastCreatedUnitName ;
}
int ScriptManager : : getCellTriggeredEventId ( ) {
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
return currentCellTriggeredEventId ;
}
int ScriptManager : : getTimerTriggeredEventId ( ) {
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
return currentTimerTriggeredEventId ;
}
2012-10-10 07:44:14 +02:00
int ScriptManager : : getCellTriggeredEventAreaEntryUnitId ( ) {
2013-10-03 07:44:50 +02:00
2012-10-10 07:44:14 +02:00
return currentCellTriggeredEventAreaEntryUnitId ;
}
int ScriptManager : : getCellTriggeredEventAreaExitUnitId ( ) {
2013-10-03 07:44:50 +02:00
2012-10-10 07:44:14 +02:00
return currentCellTriggeredEventAreaExitUnitId ;
}
2012-10-13 07:06:53 +02:00
int ScriptManager : : getCellTriggeredEventUnitId ( ) {
2013-10-03 07:44:50 +02:00
2012-10-13 07:06:53 +02:00
return currentCellTriggeredEventUnitId ;
}
2012-10-10 07:44:14 +02:00
2012-03-27 09:05:07 +02:00
void ScriptManager : : setRandomGenInit ( int seed ) {
2013-10-03 07:44:50 +02:00
2012-03-27 09:05:07 +02:00
random . init ( seed ) ;
}
int ScriptManager : : getRandomGen ( int minVal , int maxVal ) {
2013-10-03 07:44:50 +02:00
2012-03-27 09:05:07 +02:00
return random . randRange ( minVal , maxVal ) ;
}
int ScriptManager : : getWorldFrameCount ( ) {
2013-10-03 07:44:50 +02:00
2012-03-27 09:05:07 +02:00
return world - > getFrameCount ( ) ;
}
2012-03-30 16:48:54 +02:00
bool ScriptManager : : getGameWon ( ) const {
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
return gameWon ;
}
2012-03-30 16:48:54 +02:00
bool ScriptManager : : getIsGameOver ( ) const {
2013-10-03 07:44:50 +02:00
2012-03-30 16:48:54 +02:00
return gameOver ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : getLastCreatedUnitId ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
return lastCreatedUnitId ;
}
const string & ScriptManager : : getLastDeadUnitName ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
return lastDeadUnitName ;
}
int ScriptManager : : getLastDeadUnitId ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
return lastDeadUnitId ;
}
2011-11-16 22:43:19 +01:00
int ScriptManager : : getLastDeadUnitCauseOfDeath ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-11-16 22:43:19 +01:00
return lastDeadUnitCauseOfDeath ;
}
2011-11-18 16:43:05 +01:00
const string & ScriptManager : : getLastDeadUnitKillerName ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-11-18 16:43:05 +01:00
return lastDeadUnitKillerName ;
}
int ScriptManager : : getLastDeadUnitKillerId ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-11-18 16:43:05 +01:00
return lastDeadUnitKillerId ;
}
2011-11-16 22:38:12 +01:00
const string & ScriptManager : : getLastAttackedUnitName ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-11-16 22:38:12 +01:00
return lastAttackedUnitName ;
}
int ScriptManager : : getLastAttackedUnitId ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-11-16 22:38:12 +01:00
return lastAttackedUnitId ;
}
const string & ScriptManager : : getLastAttackingUnitName ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-11-16 22:38:12 +01:00
return lastAttackingUnitName ;
}
int ScriptManager : : getLastAttackingUnitId ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-11-16 22:38:12 +01:00
return lastAttackingUnitId ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : getUnitCount ( int factionIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
return world - > getUnitCount ( factionIndex ) ;
}
int ScriptManager : : getUnitCountOfType ( int factionIndex , const string & typeName ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-01-20 16:56:30 +01:00
return world - > getUnitCountOfType ( factionIndex , typeName ) ;
}
2012-01-05 01:04:55 +01:00
const string ScriptManager : : getSystemMacroValue ( const string & key ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-01-05 01:04:55 +01:00
return world - > getSystemMacroValue ( key ) ;
}
2012-01-05 01:45:17 +01:00
const string ScriptManager : : getPlayerName ( int factionIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-01-05 01:45:17 +01:00
return world - > getPlayerName ( factionIndex ) ;
}
2011-10-06 22:44:55 +02:00
void ScriptManager : : loadScenario ( const string & name , bool keepFactions ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-10-06 20:04:59 +02:00
2011-10-06 22:44:55 +02:00
world - > setQueuedScenario ( name , keepFactions ) ;
2012-03-30 09:10:14 +02:00
}
2011-10-06 20:04:59 +02:00
2012-03-30 09:10:14 +02:00
vector < int > ScriptManager : : getUnitsForFaction ( int factionIndex , const string & commandTypeName , int field ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-10-06 20:04:59 +02:00
2012-03-30 09:10:14 +02:00
return world - > getUnitsForFaction ( factionIndex , commandTypeName , field ) ;
}
2011-10-06 20:04:59 +02:00
2012-03-30 09:10:14 +02:00
int ScriptManager : : getUnitCurrentField ( int unitId ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2011-10-06 20:04:59 +02:00
2012-03-30 09:10:14 +02:00
return world - > getUnitCurrentField ( unitId ) ;
2011-10-06 20:04:59 +02:00
}
2012-10-10 21:56:52 +02:00
int ScriptManager : : isFreeCellsOrHasUnit ( int field , int unitId , Vec2i pos ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-09 22:03:09 +02:00
Unit * unit = world - > findUnitById ( unitId ) ;
2013-12-14 08:04:12 +01:00
if ( unit = = NULL ) {
2013-12-30 16:57:51 +01:00
throw megaglest_runtime_error ( " unit == NULL " , true ) ;
2013-12-14 08:04:12 +01:00
}
2015-01-14 22:58:19 +01:00
int result = world - > getMap ( ) - > isFreeCellsOrHasUnit ( pos , unit - > getType ( ) - > getSize ( ) , static_cast < Field > ( field ) , unit ) ;
2012-10-09 22:03:09 +02:00
2013-06-13 10:55:48 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s] unitId = %d, [%s] pos [%s] field = %d result = %d \n " , __FUNCTION__ , unitId , unit - > getType ( ) - > getName ( false ) . c_str ( ) , pos . getString ( ) . c_str ( ) , field , result ) ;
2012-10-10 21:56:52 +02:00
return result ;
2012-10-09 22:03:09 +02:00
}
2012-10-10 21:56:52 +02:00
int ScriptManager : : isFreeCells ( int unitSize , int field , Vec2i pos ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2015-01-14 22:58:19 +01:00
int result = world - > getMap ( ) - > isFreeCellsOrHasUnit ( pos , unitSize , static_cast < Field > ( field ) , NULL ) ;
2012-10-10 21:56:52 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s] unitSize = %d, pos [%s] field = %d result = %d \n " , __FUNCTION__ , unitSize , pos . getString ( ) . c_str ( ) , field , result ) ;
return result ;
2012-10-09 22:03:09 +02:00
}
2012-10-13 07:06:53 +02:00
int ScriptManager : : getHumanFactionId ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-13 07:06:53 +02:00
return this - > world - > getThisFactionIndex ( ) ;
}
2012-10-13 09:33:33 +02:00
void ScriptManager : : highlightUnit ( int unitId , float radius , float thickness , Vec4f color ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-13 09:33:33 +02:00
world - > highlightUnit ( unitId , radius , thickness , color ) ;
}
void ScriptManager : : unhighlightUnit ( int unitId ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-13 09:33:33 +02:00
world - > unhighlightUnit ( unitId ) ;
}
2012-10-17 22:15:50 +02:00
void ScriptManager : : giveStopCommand ( int unitId ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-17 22:15:50 +02:00
world - > giveStopCommand ( unitId ) ;
}
bool ScriptManager : : selectUnit ( int unitId ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-17 22:15:50 +02:00
return world - > selectUnit ( unitId ) ;
}
void ScriptManager : : unselectUnit ( int unitId ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-17 22:15:50 +02:00
world - > unselectUnit ( unitId ) ;
}
void ScriptManager : : addUnitToGroupSelection ( int unitId , int groupIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-17 22:15:50 +02:00
world - > addUnitToGroupSelection ( unitId , groupIndex ) ;
}
void ScriptManager : : recallGroupSelection ( int groupIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-17 22:15:50 +02:00
world - > recallGroupSelection ( groupIndex ) ;
}
void ScriptManager : : removeUnitFromGroupSelection ( int unitId , int groupIndex ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-17 22:15:50 +02:00
world - > removeUnitFromGroupSelection ( unitId , groupIndex ) ;
}
void ScriptManager : : setAttackWarningsEnabled ( bool enabled ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-17 22:15:50 +02:00
world - > setAttackWarningsEnabled ( enabled ) ;
}
bool ScriptManager : : getAttackWarningsEnabled ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2012-10-17 22:15:50 +02:00
return world - > getAttackWarningsEnabled ( ) ;
}
2013-05-28 02:59:44 +02:00
void ScriptManager : : registerUnitTriggerEvent ( int unitId ) {
UnitTriggerEventList [ unitId ] = utet_None ;
}
void ScriptManager : : unregisterUnitTriggerEvent ( int unitId ) {
UnitTriggerEventList . erase ( unitId ) ;
}
int ScriptManager : : getLastUnitTriggerEventUnitId ( ) {
return lastUnitTriggerEventUnitId ;
}
UnitTriggerEventType ScriptManager : : getLastUnitTriggerEventType ( ) {
return lastUnitTriggerEventType ;
}
int ScriptManager : : getUnitProperty ( int unitId , UnitTriggerEventType type ) {
int result = - 1 ;
2013-05-28 08:07:35 +02:00
//printf("File: %s line: %d type: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,type);
2013-05-28 02:59:44 +02:00
Unit * unit = world - > findUnitById ( unitId ) ;
if ( unit ! = NULL ) {
switch ( type ) {
case utet_None :
result = - 2 ;
break ;
case utet_HPChanged :
result = unit - > getHp ( ) ;
break ;
case utet_EPChanged :
result = unit - > getEp ( ) ;
break ;
case utet_LevelChanged :
result = - 3 ;
if ( unit - > getLevel ( ) ! = NULL ) {
result = unit - > getLevel ( ) - > getKills ( ) ;
}
break ;
case utet_FieldChanged :
result = unit - > getCurrField ( ) ;
break ;
case utet_SkillChanged :
result = - 4 ;
if ( unit - > getCurrSkill ( ) ! = NULL ) {
result = unit - > getCurrSkill ( ) - > getClass ( ) ;
}
break ;
default :
result = - 1000 ;
break ;
}
}
2013-05-28 08:07:35 +02:00
//printf("File: %s line: %d result: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,result);
2013-05-28 02:59:44 +02:00
return result ;
}
const string ScriptManager : : getUnitPropertyName ( int unitId , UnitTriggerEventType type ) {
string result = " " ;
Unit * unit = world - > findUnitById ( unitId ) ;
if ( unit ! = NULL ) {
switch ( type ) {
case utet_None :
result = " " ;
break ;
case utet_HPChanged :
result = " " ;
break ;
case utet_EPChanged :
result = " " ;
break ;
case utet_LevelChanged :
result = " " ;
if ( unit - > getLevel ( ) ! = NULL ) {
result = unit - > getLevel ( ) - > getName ( false ) ;
}
break ;
case utet_FieldChanged :
result = " " ;
break ;
case utet_SkillChanged :
result = " " ;
if ( unit - > getCurrSkill ( ) ! = NULL ) {
result = unit - > getCurrSkill ( ) - > getName ( ) ;
}
break ;
default :
result = " ??? " ;
break ;
}
}
return result ;
}
void ScriptManager : : onUnitTriggerEvent ( const Unit * unit , UnitTriggerEventType event ) {
2013-05-28 08:07:35 +02:00
//static bool inEvent = false;
//if(inEvent == true) {
// printf("\n\n!!!!!!!!!!!!!!! File: %s line: %d unit [%d - %s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,unit->getId(),unit->getType()->getName().c_str());
// return;
//}
//inEvent = true;
//printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
2013-05-28 02:59:44 +02:00
if ( UnitTriggerEventList . empty ( ) = = false ) {
2013-05-28 08:07:35 +02:00
//printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
2013-05-28 02:59:44 +02:00
std : : map < int , UnitTriggerEventType > : : iterator iterFind = UnitTriggerEventList . find ( unit - > getId ( ) ) ;
if ( iterFind ! = UnitTriggerEventList . end ( ) ) {
2013-05-28 08:07:35 +02:00
//printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
2013-05-28 02:59:44 +02:00
lastUnitTriggerEventUnitId = unit - > getId ( ) ;
lastUnitTriggerEventType = event ;
2013-05-28 08:07:35 +02:00
//printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
2013-05-28 02:59:44 +02:00
luaScript . beginCall ( " unitTriggerEvent " ) ;
luaScript . endCall ( ) ;
2013-05-28 08:07:35 +02:00
//printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
2013-05-28 02:59:44 +02:00
}
}
2013-05-28 08:07:35 +02:00
//inEvent = false;
//printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
2013-05-28 02:59:44 +02:00
}
2013-05-25 22:46:36 +02:00
void ScriptManager : : registerDayNightEvent ( ) {
registeredDayNightEvent = true ;
}
void ScriptManager : : unregisterDayNightEvent ( ) {
registeredDayNightEvent = false ;
}
void ScriptManager : : onDayNightTriggerEvent ( ) {
if ( registeredDayNightEvent = = true ) {
2013-06-04 06:36:00 +02:00
bool isDay = ( this - > getIsDayTime ( ) = = 1 ) ;
2013-05-25 22:46:36 +02:00
if ( ( lastDayNightTriggerStatus ! = 1 & & isDay = = true ) | |
( lastDayNightTriggerStatus ! = 2 & & isDay = = false ) ) {
if ( isDay = = true ) {
lastDayNightTriggerStatus = 1 ;
}
else {
lastDayNightTriggerStatus = 2 ;
}
printf ( " Triggering daynight event isDay: %d [%f] \n " , isDay , getTimeOfDay ( ) ) ;
luaScript . beginCall ( " dayNightTriggerEvent " ) ;
luaScript . endCall ( ) ;
}
}
}
int ScriptManager : : getIsDayTime ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2013-05-25 22:46:36 +02:00
const TimeFlow * tf = world - > getTimeFlow ( ) ;
if ( tf = = NULL ) {
2013-12-30 16:57:51 +01:00
throw megaglest_runtime_error ( " #1 tf == NULL " , true ) ;
2013-05-25 22:46:36 +02:00
}
return tf - > isDay ( ) ;
}
int ScriptManager : : getIsNightTime ( ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2013-05-25 22:46:36 +02:00
const TimeFlow * tf = world - > getTimeFlow ( ) ;
if ( tf = = NULL ) {
2013-12-30 16:57:51 +01:00
throw megaglest_runtime_error ( " #2 tf == NULL " , true ) ;
2013-05-25 22:46:36 +02:00
}
return tf - > isNight ( ) ;
}
float ScriptManager : : getTimeOfDay ( ) {
2013-05-28 08:07:35 +02:00
//printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-10-03 07:44:50 +02:00
2013-05-25 22:46:36 +02:00
const TimeFlow * tf = world - > getTimeFlow ( ) ;
if ( tf = = NULL ) {
2013-12-30 16:57:51 +01:00
throw megaglest_runtime_error ( " #3 tf == NULL " , true ) ;
2013-05-25 22:46:36 +02:00
}
2013-05-28 08:07:35 +02:00
//printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
2013-05-25 22:46:36 +02:00
return tf - > getTime ( ) ;
}
2013-11-07 06:18:21 +01:00
void ScriptManager : : disableSpeedChange ( ) {
if ( world - > getGame ( ) = = NULL ) {
2013-12-30 16:57:51 +01:00
throw megaglest_runtime_error ( " #4 world->getGame() = = NULL " ) ;
2013-11-07 06:18:21 +01:00
}
world - > getGame ( ) - > setDisableSpeedChange ( true ) ;
}
void ScriptManager : : enableSpeedChange ( ) {
if ( world - > getGame ( ) = = NULL ) {
2013-12-30 16:57:51 +01:00
throw megaglest_runtime_error ( " #5 world->getGame() = = NULL " ) ;
2013-11-07 06:18:21 +01:00
}
world - > getGame ( ) - > setDisableSpeedChange ( false ) ;
}
bool ScriptManager : : getSpeedChangeEnabled ( ) {
if ( world - > getGame ( ) = = NULL ) {
2013-12-30 16:57:51 +01:00
throw megaglest_runtime_error ( " #6 world->getGame() = = NULL " ) ;
2013-11-07 06:18:21 +01:00
}
return world - > getGame ( ) - > getDisableSpeedChange ( ) ;
}
2013-12-30 11:01:47 +01:00
void ScriptManager : : addMessageToQueue ( ScriptManagerMessage msg ) {
messageQueue . push_back ( msg ) ;
}
2013-12-30 21:55:59 +01:00
void ScriptManager : : storeSaveGameData ( string name , string value ) {
2013-12-30 23:00:04 +01:00
if ( LuaScript : : getDebugModeEnabled ( ) = = true ) printf ( " storeSaveGameData name [%s] value [%s] \n " , name . c_str ( ) , value . c_str ( ) ) ;
2013-12-30 21:55:59 +01:00
luaSavedGameData [ name ] = value ;
}
string ScriptManager : : loadSaveGameData ( string name ) {
2013-12-30 23:00:04 +01:00
string value = luaSavedGameData [ name ] ;
if ( LuaScript : : getDebugModeEnabled ( ) = = true ) printf ( " loadSaveGameData result name [%s] value [%s] \n " , name . c_str ( ) , value . c_str ( ) ) ;
return value ;
2013-12-30 21:55:59 +01:00
}
2014-01-04 18:34:49 +01:00
ControlType ScriptManager : : getFactionPlayerType ( int factionIndex ) {
Faction * faction = world - > getFaction ( factionIndex ) ;
if ( faction ! = NULL ) {
return faction - > getControlType ( ) ;
}
return ctClosed ;
}
2011-01-20 16:56:30 +01:00
// ========================== lua callbacks ===============================================
int ScriptManager : : showMessage ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
thisScriptManager - > showMessage ( luaArguments . getString ( - 2 ) , luaArguments . getString ( - 1 ) ) ;
return luaArguments . getReturnCount ( ) ;
}
2012-03-30 07:53:33 +02:00
int ScriptManager : : networkShowMessageForFaction ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > networkShowMessageForFaction ( luaArguments . getString ( - 3 ) , luaArguments . getString ( - 2 ) , luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-03-30 07:53:33 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : networkShowMessageForTeam ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > networkShowMessageForTeam ( luaArguments . getString ( - 3 ) , luaArguments . getString ( - 2 ) , luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-03-30 07:53:33 +02:00
return luaArguments . getReturnCount ( ) ;
}
2012-10-10 20:28:55 +02:00
int ScriptManager : : networkSetCameraPositionForFaction ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > networkSetCameraPositionForFaction ( luaArguments . getInt ( - 2 ) , luaArguments . getVec2i ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-10 20:28:55 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : networkSetCameraPositionForTeam ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > networkSetCameraPositionForTeam ( luaArguments . getInt ( - 2 ) , luaArguments . getVec2i ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-10 20:28:55 +02:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : setDisplayText ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > setDisplayText ( luaArguments . getString ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-03-19 13:19:22 +01:00
int ScriptManager : : addConsoleText ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > addConsoleText ( luaArguments . getString ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-03-19 13:19:22 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : clearDisplayText ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > clearDisplayText ( ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : setCameraPosition ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > setCameraPosition ( Vec2i ( luaArguments . getVec2i ( - 1 ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2014-02-04 21:21:06 +01:00
}
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : shakeCamera ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
try {
thisScriptManager - > shakeCamera ( luaArguments . getInt ( - 2 ) , luaArguments . getInt ( - 1 ) , false , 0 ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2014-02-04 21:21:06 +01:00
}
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : shakeCameraOnUnit ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
try {
thisScriptManager - > shakeCamera ( luaArguments . getInt ( - 3 ) , luaArguments . getInt ( - 2 ) , true , luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-29 13:42:18 +01:00
int ScriptManager : : createUnit ( LuaHandle * luaHandle ) {
2011-01-20 16:56:30 +01:00
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%s] factionIndex = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getString ( - 3 ) . c_str ( ) , luaArguments . getInt ( - 2 ) ) ;
try {
thisScriptManager - > createUnit (
luaArguments . getString ( - 3 ) ,
luaArguments . getInt ( - 2 ) ,
luaArguments . getVec2i ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
2013-12-30 11:01:47 +01:00
2016-11-26 15:46:32 +01:00
return luaArguments . getReturnCount ( ) ;
}
2013-12-30 11:01:47 +01:00
2016-11-26 15:46:32 +01:00
void ScriptManager : : error ( LuaHandle * luaHandle , const megaglest_runtime_error * mgErr , const char * file , const char * function , int line ) {
char szErrBuf [ 8096 ] = " " ;
2016-11-27 19:17:56 +01:00
char szErrBuf2 [ 8096 ] = " " ;
2016-11-26 15:46:32 +01:00
int luaLine = - 1 ;
2016-11-27 19:17:56 +01:00
const char * luaSource = " " ;
2016-11-26 15:46:32 +01:00
if ( luaHandle ! = NULL ) {
lua_Debug ar ;
lua_getstack ( luaHandle , 1 , & ar ) ;
lua_getinfo ( luaHandle , " nSl " , & ar ) ;
2016-11-27 19:17:56 +01:00
2016-11-26 15:46:32 +01:00
luaLine = ar . currentline ;
2016-11-27 19:17:56 +01:00
luaSource = ar . source ;
2013-12-30 11:01:47 +01:00
}
2016-11-26 15:46:32 +01:00
snprintf ( szErrBuf , 8096 , " in %s::%s %d " , extractFileFromDirectoryPath ( file ) . c_str ( ) , function , line ) ;
2016-11-27 19:17:56 +01:00
snprintf ( szErrBuf2 , 8096 , " Lua: tag=<%s> line=%d " , luaSource , luaLine - 1 ) ;
2016-11-26 15:46:32 +01:00
string sErrBuf = string ( " Error! The game may no longer be stable! \n \n " )
2016-11-27 19:17:56 +01:00
+ string ( szErrBuf ) + " \n " + string ( szErrBuf2 ) + " \n \n "
2016-11-26 15:46:32 +01:00
+ string ( mgErr - > what ( ) ) ;
2011-01-20 16:56:30 +01:00
2016-11-26 15:46:32 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , sErrBuf . c_str ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , sErrBuf . c_str ( ) ) ;
2016-11-28 01:45:00 +01:00
thisScriptManager - > addMessageToQueue ( ScriptManagerMessage ( sErrBuf . c_str ( ) , " error " + intToStr ( thisScriptManager - > errorCount ) , - 1 , - 1 , true ) ) ;
thisScriptManager - > errorCount + + ;
2016-11-26 15:46:32 +01:00
thisScriptManager - > onMessageBoxOk ( false ) ;
2011-01-20 16:56:30 +01:00
}
2012-02-21 22:56:20 +01:00
int ScriptManager : : createUnitNoSpacing ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%s] factionIndex = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getString ( - 3 ) . c_str ( ) , luaArguments . getInt ( - 2 ) ) ;
try {
thisScriptManager - > createUnitNoSpacing (
luaArguments . getString ( - 3 ) ,
luaArguments . getInt ( - 2 ) ,
luaArguments . getVec2i ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-02-21 22:56:20 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-29 13:42:18 +01:00
int ScriptManager : : destroyUnit ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getInt ( - 1 ) ) ;
try {
thisScriptManager - > destroyUnit ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-29 13:42:18 +01:00
return luaArguments . getReturnCount ( ) ;
}
2014-11-12 15:14:52 +01:00
int ScriptManager : : setLockedUnitForFaction ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%s] factionIndex = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getString ( - 3 ) . c_str ( ) , luaArguments . getInt ( - 2 ) ) ;
try {
thisScriptManager - > setLockedUnitForFaction (
luaArguments . getString ( - 3 ) ,
luaArguments . getInt ( - 2 ) ,
( luaArguments . getInt ( - 1 ) = = 0 ? false : true ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2014-11-12 15:14:52 +01:00
}
return luaArguments . getReturnCount ( ) ;
}
2011-11-16 22:38:12 +01:00
int ScriptManager : : giveKills ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getInt ( - 1 ) ) ;
try {
thisScriptManager - > giveKills ( luaArguments . getInt ( - 2 ) , luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-11-16 22:38:12 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-29 13:42:18 +01:00
int ScriptManager : : morphToUnit ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%d] morphName [%s] forceUpgrade = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getInt ( - 3 ) , luaArguments . getString ( - 2 ) . c_str ( ) , luaArguments . getInt ( - 1 ) ) ;
try {
thisScriptManager - > morphToUnit ( luaArguments . getInt ( - 3 ) , luaArguments . getString ( - 2 ) , luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-29 13:42:18 +01:00
return luaArguments . getReturnCount ( ) ;
2011-01-29 18:52:53 +01:00
}
int ScriptManager : : moveToUnit ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] unit [%d] dest unit [%d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getInt ( - 2 ) , luaArguments . getInt ( - 1 ) ) ;
try {
thisScriptManager - > moveToUnit ( luaArguments . getInt ( - 2 ) , luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-29 18:52:53 +01:00
return luaArguments . getReturnCount ( ) ;
2011-01-29 13:42:18 +01:00
}
int ScriptManager : : playStaticSound ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] sound [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getString ( - 1 ) . c_str ( ) ) ;
try {
thisScriptManager - > playStaticSound ( luaArguments . getString ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-29 13:42:18 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : playStreamingSound ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] sound [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getString ( - 1 ) . c_str ( ) ) ;
try {
thisScriptManager - > playStreamingSound ( luaArguments . getString ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-29 13:42:18 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : stopStreamingSound ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] sound [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getString ( - 1 ) . c_str ( ) ) ;
try {
thisScriptManager - > stopStreamingSound ( luaArguments . getString ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-29 13:42:18 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : stopAllSound ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
try {
thisScriptManager - > stopAllSound ( ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-05-22 08:17:56 +02:00
2013-12-30 11:01:47 +01:00
return luaArguments . getReturnCount ( ) ;
}
2012-05-22 08:17:56 +02:00
int ScriptManager : : playStaticVideo ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] sound [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getString ( - 1 ) . c_str ( ) ) ;
try {
thisScriptManager - > playStaticVideo ( luaArguments . getString ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-05-22 08:17:56 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : playStreamingVideo ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] sound [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getString ( - 1 ) . c_str ( ) ) ;
try {
thisScriptManager - > playStreamingVideo ( luaArguments . getString ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-05-22 08:17:56 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : stopStreamingVideo ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] sound [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getString ( - 1 ) . c_str ( ) ) ;
try {
thisScriptManager - > stopStreamingVideo ( luaArguments . getString ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-05-22 08:17:56 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : stopAllVideo ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
try {
thisScriptManager - > stopAllVideo ( ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
return luaArguments . getReturnCount ( ) ;
}
2012-05-22 08:17:56 +02:00
2011-01-30 00:50:21 +01:00
int ScriptManager : : togglePauseGame ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] value = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , luaArguments . getInt ( - 1 ) ) ;
try {
thisScriptManager - > togglePauseGame ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-30 00:50:21 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : giveResource ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > giveResource ( luaArguments . getString ( - 3 ) , luaArguments . getInt ( - 2 ) , luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : givePositionCommand ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > givePositionCommand (
luaArguments . getInt ( - 3 ) ,
luaArguments . getString ( - 2 ) ,
luaArguments . getVec2i ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : giveAttackCommand ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > giveAttackCommand (
luaArguments . getInt ( - 2 ) ,
luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : giveProductionCommand ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > giveProductionCommand (
luaArguments . getInt ( - 2 ) ,
luaArguments . getString ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : giveUpgradeCommand ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > giveUpgradeCommand (
luaArguments . getInt ( - 2 ) ,
luaArguments . getString ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-29 13:42:18 +01:00
int ScriptManager : : giveAttackStoppedCommand ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > giveAttackStoppedCommand (
luaArguments . getInt ( - 3 ) ,
luaArguments . getString ( - 2 ) ,
luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-29 13:42:18 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : disableAi ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > disableAi ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : enableAi ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > enableAi ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getAiEnabled ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
bool result = thisScriptManager - > getAiEnabled ( luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : disableConsume ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > disableConsume ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
2013-12-30 11:01:47 +01:00
2016-11-26 15:46:32 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : enableConsume ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > enableConsume ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getConsumeEnabled ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
bool result = thisScriptManager - > getConsumeEnabled ( luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : registerCellTriggerEventForUnitToUnit ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > registerCellTriggerEventForUnitToUnit ( luaArguments . getInt ( - 2 ) , luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : registerCellTriggerEventForUnitToLocation ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > registerCellTriggerEventForUnitToLocation ( luaArguments . getInt ( - 2 ) , luaArguments . getVec2i ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
2012-05-02 08:07:11 +02:00
int ScriptManager : : registerCellAreaTriggerEventForUnitToLocation ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > registerCellAreaTriggerEventForUnitToLocation ( luaArguments . getInt ( - 2 ) , luaArguments . getVec4i ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-05-02 08:07:11 +02:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : registerCellTriggerEventForFactionToUnit ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > registerCellTriggerEventForFactionToUnit ( luaArguments . getInt ( - 2 ) , luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : registerCellTriggerEventForFactionToLocation ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > registerCellTriggerEventForFactionToLocation ( luaArguments . getInt ( - 2 ) , luaArguments . getVec2i ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
2012-05-02 08:07:11 +02:00
int ScriptManager : : registerCellAreaTriggerEventForFactionToLocation ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > registerCellAreaTriggerEventForFactionToLocation ( luaArguments . getInt ( - 2 ) , luaArguments . getVec4i ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-05-02 08:07:11 +02:00
return luaArguments . getReturnCount ( ) ;
}
2012-10-10 07:44:14 +02:00
int ScriptManager : : registerCellAreaTriggerEvent ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > registerCellAreaTriggerEvent ( luaArguments . getVec4i ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-10 07:44:14 +02:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : getCellTriggerEventCount ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > getCellTriggerEventCount ( luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : unregisterCellTriggerEvent ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > unregisterCellTriggerEvent ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : startTimerEvent ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > startTimerEvent ( ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
2012-03-27 08:42:55 +02:00
int ScriptManager : : startEfficientTimerEvent ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > startEfficientTimerEvent ( luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-03-27 08:42:55 +02:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : stopTimerEvent ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > stopTimerEvent ( luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : resetTimerEvent ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > resetTimerEvent ( luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getTimerEventSecondsElapsed ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > getTimerEventSecondsElapsed ( luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : setPlayerAsWinner ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > setPlayerAsWinner ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : endGame ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > endGame ( ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : startPerformanceTimer ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > startPerformanceTimer ( ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : endPerformanceTimer ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > endPerformanceTimer ( ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getPerformanceTimerResults ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
Vec2i results = thisScriptManager - > getPerformanceTimerResults ( ) ;
luaArguments . returnVec2i ( results ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getStartLocation ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
Vec2i pos = thisScriptManager - > getStartLocation ( luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnVec2i ( pos ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getUnitPosition ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
Vec2i pos = thisScriptManager - > getUnitPosition ( luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnVec2i ( pos ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
2012-04-11 07:41:40 +02:00
int ScriptManager : : setUnitPosition ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > setUnitPosition ( luaArguments . getInt ( - 2 ) , luaArguments . getVec2i ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-04-11 07:41:40 +02:00
return luaArguments . getReturnCount ( ) ;
}
2012-09-25 09:05:52 +02:00
int ScriptManager : : addCellMarker ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
//printf("LUA addCellMarker --> START\n");
int factionIndex = luaArguments . getInt ( - 4 ) ;
//printf("LUA addCellMarker --> START 1\n");
2012-09-25 09:05:52 +02:00
2013-12-30 11:01:47 +01:00
Vec2i pos = luaArguments . getVec2i ( - 1 ) ;
2012-09-25 09:05:52 +02:00
2013-12-30 11:01:47 +01:00
//printf("LUA addCellMarker --> START 2\n");
2012-09-25 09:05:52 +02:00
2013-12-30 11:01:47 +01:00
string note = luaArguments . getString ( - 3 ) ;
2012-09-25 09:05:52 +02:00
2013-12-30 11:01:47 +01:00
//printf("LUA addCellMarker --> START 3\n");
2012-09-25 09:05:52 +02:00
2013-12-30 11:01:47 +01:00
string texture = luaArguments . getString ( - 2 ) ;
2012-09-25 09:05:52 +02:00
2013-12-30 11:01:47 +01:00
//printf("LUA addCellMarker --> faction [%d] pos [%s] note [%s] texture [%s]\n",factionIndex,pos.getString().c_str(),note.c_str(),texture.c_str());
2012-09-25 09:05:52 +02:00
2013-12-30 11:01:47 +01:00
thisScriptManager - > addCellMarker ( pos , factionIndex , note , texture ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-09-25 09:05:52 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : removeCellMarker ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int factionIndex = luaArguments . getInt ( - 2 ) ;
Vec2i pos = luaArguments . getVec2i ( - 1 ) ;
thisScriptManager - > removeCellMarker ( pos , factionIndex ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-09-25 09:05:52 +02:00
return luaArguments . getReturnCount ( ) ;
}
2012-10-13 07:06:53 +02:00
int ScriptManager : : showMarker ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int flashCount = luaArguments . getInt ( - 5 ) ;
//printf("LUA addCellMarker --> START\n");
int factionIndex = luaArguments . getInt ( - 4 ) ;
2012-10-13 07:06:53 +02:00
2013-12-30 11:01:47 +01:00
//printf("LUA addCellMarker --> START 1\n");
2012-10-13 07:06:53 +02:00
2013-12-30 11:01:47 +01:00
Vec2i pos = luaArguments . getVec2i ( - 1 ) ;
2012-10-13 07:06:53 +02:00
2013-12-30 11:01:47 +01:00
//printf("LUA addCellMarker --> START 2\n");
2012-10-13 07:06:53 +02:00
2013-12-30 11:01:47 +01:00
string note = luaArguments . getString ( - 3 ) ;
2012-10-13 07:06:53 +02:00
2013-12-30 11:01:47 +01:00
//printf("LUA addCellMarker --> START 3\n");
2012-10-13 07:06:53 +02:00
2013-12-30 11:01:47 +01:00
string texture = luaArguments . getString ( - 2 ) ;
//printf("LUA addCellMarker --> faction [%d] pos [%s] note [%s] texture [%s]\n",factionIndex,pos.getString().c_str(),note.c_str(),texture.c_str());
thisScriptManager - > showMarker ( pos , factionIndex , note , texture , flashCount ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-13 07:06:53 +02:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : getUnitFaction ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int factionIndex = thisScriptManager - > getUnitFaction ( luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnInt ( factionIndex ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
2014-08-09 00:48:04 +02:00
2012-05-21 22:15:37 +02:00
int ScriptManager : : getUnitName ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
const string unitname = thisScriptManager - > getUnitName ( luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnString ( unitname ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-05-21 22:15:37 +02:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
2014-08-09 00:48:04 +02:00
int ScriptManager : : getUnitDisplayName ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
try {
const string unitname = thisScriptManager - > getUnitDisplayName ( luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnString ( unitname ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2014-08-09 00:48:04 +02:00
}
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : getResourceAmount ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getResourceAmount ( luaArguments . getString ( - 2 ) , luaArguments . getInt ( - 1 ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getLastCreatedUnitName ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnString ( thisScriptManager - > getLastCreatedUnitName ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getLastCreatedUnitId ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getLastCreatedUnitId ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getCellTriggeredEventId ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getCellTriggeredEventId ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getTimerTriggeredEventId ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getTimerTriggeredEventId ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
2012-10-10 07:44:14 +02:00
int ScriptManager : : getCellTriggeredEventAreaEntryUnitId ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getCellTriggeredEventAreaEntryUnitId ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
2013-12-30 11:01:47 +01:00
2012-10-10 07:44:14 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getCellTriggeredEventAreaExitUnitId ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getCellTriggeredEventAreaExitUnitId ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-10 07:44:14 +02:00
return luaArguments . getReturnCount ( ) ;
}
2012-10-13 07:06:53 +02:00
int ScriptManager : : getCellTriggeredEventUnitId ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getCellTriggeredEventUnitId ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-13 07:06:53 +02:00
return luaArguments . getReturnCount ( ) ;
}
2012-03-27 09:05:07 +02:00
int ScriptManager : : setRandomGenInit ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > setRandomGenInit ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-03-27 09:05:07 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getRandomGen ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getRandomGen ( luaArguments . getInt ( - 2 ) , luaArguments . getInt ( - 1 ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-03-27 09:05:07 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getWorldFrameCount ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getWorldFrameCount ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-03-27 09:05:07 +02:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : getLastDeadUnitName ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnString ( thisScriptManager - > getLastDeadUnitName ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getLastDeadUnitId ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getLastDeadUnitId ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-11-16 22:43:19 +01:00
int ScriptManager : : getLastDeadUnitCauseOfDeath ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getLastDeadUnitCauseOfDeath ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-11-16 22:43:19 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-11-18 16:43:05 +01:00
int ScriptManager : : getLastDeadUnitKillerName ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnString ( thisScriptManager - > getLastDeadUnitKillerName ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-11-18 16:43:05 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getLastDeadUnitKillerId ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getLastDeadUnitKillerId ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-11-18 16:43:05 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-11-16 22:38:12 +01:00
int ScriptManager : : getLastAttackedUnitName ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnString ( thisScriptManager - > getLastAttackedUnitName ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-11-16 22:38:12 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getLastAttackedUnitId ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getLastAttackedUnitId ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-11-16 22:38:12 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getLastAttackingUnitName ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnString ( thisScriptManager - > getLastAttackingUnitName ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-11-16 22:38:12 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getLastAttackingUnitId ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getLastAttackingUnitId ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-11-16 22:38:12 +01:00
return luaArguments . getReturnCount ( ) ;
}
2013-12-30 11:01:47 +01:00
int ScriptManager : : getSystemMacroValue ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
try {
luaArguments . returnString ( thisScriptManager - > getSystemMacroValue ( luaArguments . getString ( - 1 ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-01-05 01:04:55 +01:00
return luaArguments . getReturnCount ( ) ;
2012-01-05 21:01:22 +01:00
}
int ScriptManager : : scenarioDir ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnString ( thisScriptManager - > getSystemMacroValue ( " $SCENARIO_PATH " ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-01-05 21:01:22 +01:00
return luaArguments . getReturnCount ( ) ;
2012-01-05 01:04:55 +01:00
}
2012-01-05 01:45:17 +01:00
int ScriptManager : : getPlayerName ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnString ( thisScriptManager - > getPlayerName ( luaArguments . getInt ( - 1 ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-01-05 01:45:17 +01:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
int ScriptManager : : getUnitCount ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getUnitCount ( luaArguments . getInt ( - 1 ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getUnitCountOfType ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getUnitCountOfType ( luaArguments . getInt ( - 2 ) , luaArguments . getString ( - 1 ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : DisplayFormattedText ( LuaHandle * luaHandle ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-20 16:56:30 +01:00
2013-12-30 11:01:47 +01:00
try {
//const char *ret;
//lua_lock(luaHandle);
//luaC_checkGC(luaHandle);
int args = lua_gettop ( luaHandle ) ;
if ( lua_checkstack ( luaHandle , args + 1 ) ) {
LuaArguments luaArguments ( luaHandle ) ;
string fmt = luaArguments . getString ( - args ) ;
//va_list argList;
//va_start(argList, fmt.c_str() );
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " DisplayFormattedText args = %d! \n " , args ) ;
const int max_args_allowed = 8 ;
if ( args = = 1 ) {
thisScriptManager - > DisplayFormattedText ( fmt . c_str ( ) ) ;
}
else if ( args = = 2 ) {
thisScriptManager - > DisplayFormattedText ( fmt . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ) ;
}
else if ( args = = 3 ) {
thisScriptManager - > DisplayFormattedText ( fmt . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ) ;
}
else if ( args = = 4 ) {
thisScriptManager - > DisplayFormattedText ( fmt . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ) ;
}
else if ( args = = 5 ) {
thisScriptManager - > DisplayFormattedText ( fmt . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ,
luaArguments . getGenericData ( - args + 4 ) ) ;
}
else if ( args = = 6 ) {
thisScriptManager - > DisplayFormattedText ( fmt . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ,
luaArguments . getGenericData ( - args + 4 ) ,
luaArguments . getGenericData ( - args + 5 ) ) ;
}
else if ( args = = 7 ) {
thisScriptManager - > DisplayFormattedText ( fmt . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ,
luaArguments . getGenericData ( - args + 4 ) ,
luaArguments . getGenericData ( - args + 5 ) ,
luaArguments . getGenericData ( - args + 6 ) ) ;
}
else if ( args = = max_args_allowed ) {
thisScriptManager - > DisplayFormattedText ( fmt . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ,
luaArguments . getGenericData ( - args + 4 ) ,
luaArguments . getGenericData ( - args + 5 ) ,
luaArguments . getGenericData ( - args + 6 ) ,
luaArguments . getGenericData ( - args + 7 ) ) ;
}
else {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Invalid parameter count in method [%s] args = %d [argument count must be between 1 and %d] " , __FUNCTION__ , args , max_args_allowed ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
2011-01-20 16:56:30 +01:00
2013-12-30 11:01:47 +01:00
//va_end(argList);
}
//lua_unlock(luaHandle);
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
2013-12-30 11:01:47 +01:00
return 1 ;
2011-01-20 16:56:30 +01:00
/*
int args = lua_gettop ( luaHandle ) ;
if ( lua_checkstack ( luaHandle , args + 1 ) )
{
va_list argList ;
int i ;
//lua_getfield(luaHandle, LUA_GLOBALSINDEX, "print");
for ( i = 1 ; i < = args ; i + + ) {
lua_pushvalue ( luaHandle , i ) ;
}
lua_call ( luaHandle , args , 0 ) ;
}
else
{
return luaL_error ( luaHandle , " cannot grow stack " ) ;
}
*/
/*
luax_getfunction ( L , mod , fn ) ;
for ( int i = 0 ; i < n ; i + + ) {
lua_pushvalue ( L , idxs [ i ] ) ; // The arguments.
}
lua_call ( L , n , 1 ) ; // Call the function, n args, one return value.
lua_replace ( L , idxs [ 0 ] ) ; // Replace the initial argument with the new object.
return 0 ;
*/
2011-11-15 18:39:49 +01:00
}
2013-12-30 11:01:47 +01:00
int ScriptManager : : addConsoleLangText ( LuaHandle * luaHandle ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-11-15 18:39:49 +01:00
2013-12-30 11:01:47 +01:00
try {
//const char *ret;
//lua_lock(luaHandle);
//luaC_checkGC(luaHandle);
int args = lua_gettop ( luaHandle ) ;
if ( lua_checkstack ( luaHandle , args + 1 ) ) {
LuaArguments luaArguments ( luaHandle ) ;
string fmt = luaArguments . getString ( - args ) ;
//va_list argList;
//va_start(argList, fmt.c_str() );
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " DisplayFormattedText args = %d! \n " , args ) ;
const int max_args_allowed = 8 ;
if ( args = = 1 ) {
thisScriptManager - > addConsoleLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ) ;
}
else if ( args = = 2 ) {
thisScriptManager - > addConsoleLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ) ;
}
else if ( args = = 3 ) {
thisScriptManager - > addConsoleLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ) ;
}
else if ( args = = 4 ) {
thisScriptManager - > addConsoleLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ) ;
}
else if ( args = = 5 ) {
thisScriptManager - > addConsoleLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ,
luaArguments . getGenericData ( - args + 4 ) ) ;
}
else if ( args = = 6 ) {
thisScriptManager - > addConsoleLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ,
luaArguments . getGenericData ( - args + 4 ) ,
luaArguments . getGenericData ( - args + 5 ) ) ;
}
else if ( args = = 7 ) {
thisScriptManager - > addConsoleLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ,
luaArguments . getGenericData ( - args + 4 ) ,
luaArguments . getGenericData ( - args + 5 ) ,
luaArguments . getGenericData ( - args + 6 ) ) ;
}
else if ( args = = max_args_allowed ) {
thisScriptManager - > addConsoleLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ,
luaArguments . getGenericData ( - args + 4 ) ,
luaArguments . getGenericData ( - args + 5 ) ,
luaArguments . getGenericData ( - args + 6 ) ,
luaArguments . getGenericData ( - args + 7 ) ) ;
}
else {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Invalid parameter count in method [%s] args = %d [argument count must be between 1 and %d] " , __FUNCTION__ , args , max_args_allowed ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
2011-11-15 18:39:49 +01:00
2013-12-30 11:01:47 +01:00
//va_end(argList);
2011-11-15 18:39:49 +01:00
}
2013-12-30 11:01:47 +01:00
//lua_unlock(luaHandle);
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-11-15 18:39:49 +01:00
2013-12-30 11:01:47 +01:00
return 1 ;
2011-01-20 16:56:30 +01:00
}
2013-12-30 11:01:47 +01:00
2011-11-03 19:24:02 +01:00
int ScriptManager : : DisplayFormattedLangText ( LuaHandle * luaHandle ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-11-03 19:24:02 +01:00
2013-12-30 11:01:47 +01:00
try {
//const char *ret;
//lua_lock(luaHandle);
//luaC_checkGC(luaHandle);
int args = lua_gettop ( luaHandle ) ;
if ( lua_checkstack ( luaHandle , args + 1 ) ) {
LuaArguments luaArguments ( luaHandle ) ;
string fmt = luaArguments . getString ( - args ) ;
//va_list argList;
//va_start(argList, fmt.c_str() );
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " DisplayFormattedText args = %d! \n " , args ) ;
const int max_args_allowed = 8 ;
if ( args = = 1 ) {
thisScriptManager - > DisplayFormattedLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ) ;
}
else if ( args = = 2 ) {
thisScriptManager - > DisplayFormattedLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ) ;
}
else if ( args = = 3 ) {
thisScriptManager - > DisplayFormattedLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ) ;
}
else if ( args = = 4 ) {
thisScriptManager - > DisplayFormattedLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ) ;
}
else if ( args = = 5 ) {
thisScriptManager - > DisplayFormattedLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ,
luaArguments . getGenericData ( - args + 4 ) ) ;
}
else if ( args = = 6 ) {
thisScriptManager - > DisplayFormattedLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ,
luaArguments . getGenericData ( - args + 4 ) ,
luaArguments . getGenericData ( - args + 5 ) ) ;
}
else if ( args = = 7 ) {
thisScriptManager - > DisplayFormattedLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ,
luaArguments . getGenericData ( - args + 4 ) ,
luaArguments . getGenericData ( - args + 5 ) ,
luaArguments . getGenericData ( - args + 6 ) ) ;
}
else if ( args = = max_args_allowed ) {
thisScriptManager - > DisplayFormattedLangText ( Lang : : getInstance ( ) . getScenarioString ( fmt ) . c_str ( ) ,
luaArguments . getGenericData ( - args + 1 ) ,
luaArguments . getGenericData ( - args + 2 ) ,
luaArguments . getGenericData ( - args + 3 ) ,
luaArguments . getGenericData ( - args + 4 ) ,
luaArguments . getGenericData ( - args + 5 ) ,
luaArguments . getGenericData ( - args + 6 ) ,
luaArguments . getGenericData ( - args + 7 ) ) ;
}
else {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Invalid parameter count in method [%s] args = %d [argument count must be between 1 and %d] " , __FUNCTION__ , args , max_args_allowed ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
2011-11-03 19:24:02 +01:00
2013-12-30 11:01:47 +01:00
//va_end(argList);
}
//lua_unlock(luaHandle);
2011-11-03 19:24:02 +01:00
2013-12-30 11:01:47 +01:00
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
2013-12-30 11:01:47 +01:00
return 1 ;
2011-11-03 19:24:02 +01:00
}
2013-12-30 11:01:47 +01:00
2011-01-20 16:56:30 +01:00
int ScriptManager : : getGameWon ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getGameWon ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-01-20 16:56:30 +01:00
return luaArguments . getReturnCount ( ) ;
}
2012-03-30 16:48:54 +02:00
int ScriptManager : : getIsGameOver ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getIsGameOver ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-03-30 16:48:54 +02:00
return luaArguments . getReturnCount ( ) ;
}
2011-10-06 20:04:59 +02:00
int ScriptManager : : loadScenario ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > loadScenario ( luaArguments . getString ( - 2 ) , luaArguments . getInt ( - 1 ) ! = 0 ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2011-10-06 20:04:59 +02:00
return luaArguments . getReturnCount ( ) ;
}
2011-01-20 16:56:30 +01:00
2012-03-30 09:10:14 +02:00
int ScriptManager : : getUnitsForFaction ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
vector < int > units = thisScriptManager - > getUnitsForFaction ( luaArguments . getInt ( - 3 ) , luaArguments . getString ( - 2 ) , luaArguments . getInt ( - 1 ) ) ;
luaArguments . returnVectorInt ( units ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-03-30 09:10:14 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getUnitCurrentField ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getUnitCurrentField ( luaArguments . getInt ( - 1 ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-03-30 09:10:14 +02:00
return luaArguments . getReturnCount ( ) ;
}
2012-03-31 22:17:19 +02:00
int ScriptManager : : getIsUnitAlive ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getIsUnitAlive ( luaArguments . getInt ( - 1 ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-03-31 22:17:19 +02:00
return luaArguments . getReturnCount ( ) ;
}
2012-10-09 22:03:09 +02:00
int ScriptManager : : isFreeCellsOrHasUnit ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > isFreeCellsOrHasUnit (
luaArguments . getInt ( - 3 ) ,
luaArguments . getInt ( - 2 ) ,
luaArguments . getVec2i ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-10 21:56:52 +02:00
2012-10-09 22:03:09 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : isFreeCells ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int result = thisScriptManager - > isFreeCells (
luaArguments . getInt ( - 3 ) ,
luaArguments . getInt ( - 2 ) ,
luaArguments . getVec2i ( - 1 ) ) ;
luaArguments . returnInt ( result ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-10 21:56:52 +02:00
2012-10-09 22:03:09 +02:00
return luaArguments . getReturnCount ( ) ;
}
2012-10-13 07:06:53 +02:00
int ScriptManager : : getHumanFactionId ( LuaHandle * luaHandle ) {
2013-12-30 11:01:47 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugLUA , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-10-13 07:06:53 +02:00
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getHumanFactionId ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-13 07:06:53 +02:00
return luaArguments . getReturnCount ( ) ;
}
2013-12-30 11:01:47 +01:00
int ScriptManager : : highlightUnit ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
try {
thisScriptManager - > highlightUnit ( luaArguments . getInt ( - 4 ) , luaArguments . getFloat ( - 3 ) , luaArguments . getFloat ( - 2 ) , luaArguments . getVec4f ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-13 09:33:33 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : unhighlightUnit ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > unhighlightUnit ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-13 09:33:33 +02:00
return luaArguments . getReturnCount ( ) ;
}
2012-10-17 22:15:50 +02:00
int ScriptManager : : giveStopCommand ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > giveStopCommand ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-17 22:15:50 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : selectUnit ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > selectUnit ( luaArguments . getInt ( - 1 ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-17 22:15:50 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : unselectUnit ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > unselectUnit ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-17 22:15:50 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : addUnitToGroupSelection ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > addUnitToGroupSelection ( luaArguments . getInt ( - 2 ) , luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-17 22:15:50 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : recallGroupSelection ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > recallGroupSelection ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-17 22:15:50 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : removeUnitFromGroupSelection ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > removeUnitFromGroupSelection ( luaArguments . getInt ( - 2 ) , luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-17 22:15:50 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : setAttackWarningsEnabled ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > setAttackWarningsEnabled ( ( luaArguments . getInt ( - 1 ) = = 0 ? false : true ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-17 22:15:50 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getAttackWarningsEnabled ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getAttackWarningsEnabled ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2012-10-17 22:15:50 +02:00
return luaArguments . getReturnCount ( ) ;
}
2013-05-25 22:46:36 +02:00
int ScriptManager : : getIsDayTime ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getIsDayTime ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-05-25 22:46:36 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getIsNightTime ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getIsNightTime ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-05-25 22:46:36 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getTimeOfDay ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnFloat ( thisScriptManager - > getTimeOfDay ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-05-25 22:46:36 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : registerDayNightEvent ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > registerDayNightEvent ( ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-05-25 22:46:36 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : unregisterDayNightEvent ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > unregisterDayNightEvent ( ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-05-25 22:46:36 +02:00
return luaArguments . getReturnCount ( ) ;
}
2013-05-28 02:59:44 +02:00
int ScriptManager : : registerUnitTriggerEvent ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > registerUnitTriggerEvent ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-05-28 02:59:44 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : unregisterUnitTriggerEvent ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > unregisterUnitTriggerEvent ( luaArguments . getInt ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-05-28 02:59:44 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getLastUnitTriggerEventUnitId ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getLastUnitTriggerEventUnitId ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-05-28 02:59:44 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getLastUnitTriggerEventType ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( static_cast < int > ( thisScriptManager - > getLastUnitTriggerEventType ( ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-05-28 02:59:44 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getUnitProperty ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
int value = thisScriptManager - > getUnitProperty ( luaArguments . getInt ( - 2 ) , static_cast < UnitTriggerEventType > ( luaArguments . getInt ( - 1 ) ) ) ;
luaArguments . returnInt ( value ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-05-28 02:59:44 +02:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getUnitPropertyName ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
const string unitname = thisScriptManager - > getUnitPropertyName ( luaArguments . getInt ( - 2 ) , static_cast < UnitTriggerEventType > ( luaArguments . getInt ( - 1 ) ) ) ;
luaArguments . returnString ( unitname ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-05-28 02:59:44 +02:00
return luaArguments . getReturnCount ( ) ;
}
2013-11-07 06:18:21 +01:00
int ScriptManager : : disableSpeedChange ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > disableSpeedChange ( ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-11-07 06:18:21 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : enableSpeedChange ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
thisScriptManager - > enableSpeedChange ( ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-11-07 06:18:21 +01:00
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : getSpeedChangeEnabled ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
2013-12-30 11:01:47 +01:00
try {
luaArguments . returnInt ( thisScriptManager - > getSpeedChangeEnabled ( ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 11:01:47 +01:00
}
2013-11-07 06:18:21 +01:00
return luaArguments . getReturnCount ( ) ;
}
2013-05-28 02:59:44 +02:00
2013-12-30 21:55:59 +01:00
int ScriptManager : : storeSaveGameData ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
try {
thisScriptManager - > storeSaveGameData ( luaArguments . getString ( - 2 ) , luaArguments . getString ( - 1 ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 21:55:59 +01:00
}
return luaArguments . getReturnCount ( ) ;
}
int ScriptManager : : loadSaveGameData ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
try {
luaArguments . returnString ( thisScriptManager - > loadSaveGameData ( luaArguments . getString ( - 1 ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-12-30 21:55:59 +01:00
}
return luaArguments . getReturnCount ( ) ;
}
2014-01-04 18:34:49 +01:00
int ScriptManager : : getFactionPlayerType ( LuaHandle * luaHandle ) {
LuaArguments luaArguments ( luaHandle ) ;
try {
luaArguments . returnInt ( thisScriptManager - > getFactionPlayerType ( luaArguments . getInt ( - 1 ) ) ) ;
}
catch ( const megaglest_runtime_error & ex ) {
2016-11-26 15:46:32 +01:00
error ( luaHandle , & ex , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2014-01-04 18:34:49 +01:00
}
return luaArguments . getReturnCount ( ) ;
}
2013-12-30 21:55:59 +01:00
2012-03-26 08:48:58 +02:00
void ScriptManager : : saveGame ( XmlNode * rootNode ) {
std : : map < string , string > mapTagReplacements ;
XmlNode * scriptManagerNode = rootNode - > addChild ( " ScriptManager " ) ;
//lua
// string code;
scriptManagerNode - > addAttribute ( " code " , code , mapTagReplacements ) ;
// LuaScript luaScript;
2013-12-30 21:55:59 +01:00
luaScript . beginCall ( " onSave " ) ;
luaScript . endCall ( ) ;
2013-12-30 23:00:04 +01:00
if ( LuaScript : : getDebugModeEnabled ( ) = = true ) printf ( " After onSave luaSavedGameData.size() = %d \n " , ( int ) luaSavedGameData . size ( ) ) ;
2013-12-30 21:55:59 +01:00
for ( std : : map < string , string > : : iterator iterMap = luaSavedGameData . begin ( ) ;
iterMap ! = luaSavedGameData . end ( ) ; + + iterMap ) {
XmlNode * savedGameDataItemNode = scriptManagerNode - > addChild ( " SavedGameDataItem " ) ;
savedGameDataItemNode - > addAttribute ( " key " , iterMap - > first , mapTagReplacements ) ;
savedGameDataItemNode - > addAttribute ( " value " , iterMap - > second , mapTagReplacements ) ;
}
2012-03-26 08:48:58 +02:00
// //world
// World *world;
// GameCamera *gameCamera;
//
// //misc
// MessageQueue messageQueue;
for ( std : : list < ScriptManagerMessage > : : iterator it = messageQueue . begin ( ) ; it ! = messageQueue . end ( ) ; + + it ) {
( * it ) . saveGame ( scriptManagerNode ) ;
}
2012-03-30 03:48:41 +02:00
//printf("==== ScriptManager Savegame messageBox [%d][%s][%s] displayText [%s]\n",messageBox.getEnabled(),messageBox.getText().c_str(),messageBox.getHeader().c_str(),displayText.c_str());
2012-03-26 08:48:58 +02:00
// GraphicMessageBox messageBox;
scriptManagerNode - > addAttribute ( " messageBox_enabled " , intToStr ( messageBox . getEnabled ( ) ) , mapTagReplacements ) ;
scriptManagerNode - > addAttribute ( " messageBox_text " , messageBox . getText ( ) , mapTagReplacements ) ;
scriptManagerNode - > addAttribute ( " messageBox_header " , messageBox . getHeader ( ) , mapTagReplacements ) ;
// string displayText;
scriptManagerNode - > addAttribute ( " displayText " , displayText , mapTagReplacements ) ;
//
// //last created unit
// string lastCreatedUnitName;
scriptManagerNode - > addAttribute ( " lastCreatedUnitName " , lastCreatedUnitName , mapTagReplacements ) ;
// int lastCreatedUnitId;
scriptManagerNode - > addAttribute ( " lastCreatedUnitId " , intToStr ( lastCreatedUnitId ) , mapTagReplacements ) ;
//
// //last dead unit
// string lastDeadUnitName;
scriptManagerNode - > addAttribute ( " lastDeadUnitName " , lastDeadUnitName , mapTagReplacements ) ;
// int lastDeadUnitId;
scriptManagerNode - > addAttribute ( " lastDeadUnitId " , intToStr ( lastDeadUnitId ) , mapTagReplacements ) ;
// int lastDeadUnitCauseOfDeath;
scriptManagerNode - > addAttribute ( " lastDeadUnitCauseOfDeath " , intToStr ( lastDeadUnitCauseOfDeath ) , mapTagReplacements ) ;
//
// //last dead unit's killer
// string lastDeadUnitKillerName;
scriptManagerNode - > addAttribute ( " lastDeadUnitKillerName " , lastDeadUnitKillerName , mapTagReplacements ) ;
// int lastDeadUnitKillerId;
scriptManagerNode - > addAttribute ( " lastDeadUnitKillerId " , intToStr ( lastDeadUnitKillerId ) , mapTagReplacements ) ;
//
// //last attacked unit
// string lastAttackedUnitName;
scriptManagerNode - > addAttribute ( " lastAttackedUnitName " , lastAttackedUnitName , mapTagReplacements ) ;
// int lastAttackedUnitId;
scriptManagerNode - > addAttribute ( " lastAttackedUnitId " , intToStr ( lastAttackedUnitId ) , mapTagReplacements ) ;
//
// //last attacking unit
// string lastAttackingUnitName;
scriptManagerNode - > addAttribute ( " lastAttackingUnitName " , lastAttackingUnitName , mapTagReplacements ) ;
// int lastAttackingUnitId;
scriptManagerNode - > addAttribute ( " lastAttackingUnitId " , intToStr ( lastAttackingUnitId ) , mapTagReplacements ) ;
//
// // end game state
// bool gameOver;
scriptManagerNode - > addAttribute ( " gameOver " , intToStr ( gameOver ) , mapTagReplacements ) ;
// bool gameWon;
scriptManagerNode - > addAttribute ( " gameWon " , intToStr ( gameWon ) , mapTagReplacements ) ;
// PlayerModifiers playerModifiers[GameConstants::maxPlayers];
2013-11-19 07:42:32 +01:00
for ( unsigned int i = 0 ; i < ( unsigned int ) GameConstants : : maxPlayers ; + + i ) {
2012-03-26 08:48:58 +02:00
PlayerModifiers & player = playerModifiers [ i ] ;
player . saveGame ( scriptManagerNode ) ;
}
// int currentTimerTriggeredEventId;
scriptManagerNode - > addAttribute ( " currentTimerTriggeredEventId " , intToStr ( currentTimerTriggeredEventId ) , mapTagReplacements ) ;
// int currentCellTriggeredEventId;
scriptManagerNode - > addAttribute ( " currentCellTriggeredEventId " , intToStr ( currentCellTriggeredEventId ) , mapTagReplacements ) ;
// int currentEventId;
scriptManagerNode - > addAttribute ( " currentEventId " , intToStr ( currentEventId ) , mapTagReplacements ) ;
// std::map<int,CellTriggerEvent> CellTriggerEventList;
for ( std : : map < int , CellTriggerEvent > : : iterator iterMap = CellTriggerEventList . begin ( ) ;
iterMap ! = CellTriggerEventList . end ( ) ; + + iterMap ) {
XmlNode * cellTriggerEventListNode = scriptManagerNode - > addChild ( " CellTriggerEventList " ) ;
cellTriggerEventListNode - > addAttribute ( " key " , intToStr ( iterMap - > first ) , mapTagReplacements ) ;
iterMap - > second . saveGame ( cellTriggerEventListNode ) ;
}
// std::map<int,TimerTriggerEvent> TimerTriggerEventList;
for ( std : : map < int , TimerTriggerEvent > : : iterator iterMap = TimerTriggerEventList . begin ( ) ;
iterMap ! = TimerTriggerEventList . end ( ) ; + + iterMap ) {
XmlNode * timerTriggerEventListNode = scriptManagerNode - > addChild ( " TimerTriggerEventList " ) ;
timerTriggerEventListNode - > addAttribute ( " key " , intToStr ( iterMap - > first ) , mapTagReplacements ) ;
iterMap - > second . saveGame ( timerTriggerEventListNode ) ;
}
// bool inCellTriggerEvent;
scriptManagerNode - > addAttribute ( " inCellTriggerEvent " , intToStr ( inCellTriggerEvent ) , mapTagReplacements ) ;
// std::vector<int> unRegisterCellTriggerEventList;
for ( unsigned int i = 0 ; i < unRegisterCellTriggerEventList . size ( ) ; + + i ) {
XmlNode * unRegisterCellTriggerEventListNode = scriptManagerNode - > addChild ( " unRegisterCellTriggerEventList " ) ;
unRegisterCellTriggerEventListNode - > addAttribute ( " eventId " , intToStr ( unRegisterCellTriggerEventList [ i ] ) , mapTagReplacements ) ;
}
2013-05-26 00:44:39 +02:00
scriptManagerNode - > addAttribute ( " registeredDayNightEvent " , intToStr ( registeredDayNightEvent ) , mapTagReplacements ) ;
scriptManagerNode - > addAttribute ( " lastDayNightTriggerStatus " , intToStr ( lastDayNightTriggerStatus ) , mapTagReplacements ) ;
2013-05-28 02:59:44 +02:00
for ( std : : map < int , UnitTriggerEventType > : : iterator iterMap = UnitTriggerEventList . begin ( ) ;
iterMap ! = UnitTriggerEventList . end ( ) ; + + iterMap ) {
XmlNode * unitTriggerEventListNode = scriptManagerNode - > addChild ( " UnitTriggerEventList " ) ;
unitTriggerEventListNode - > addAttribute ( " unitId " , intToStr ( iterMap - > first ) , mapTagReplacements ) ;
2013-11-04 20:16:28 +01:00
unitTriggerEventListNode - > addAttribute ( " eventType " , intToStr ( iterMap - > second ) , mapTagReplacements ) ;
2013-05-28 02:59:44 +02:00
}
scriptManagerNode - > addAttribute ( " lastUnitTriggerEventUnitId " , intToStr ( lastUnitTriggerEventUnitId ) , mapTagReplacements ) ;
scriptManagerNode - > addAttribute ( " lastUnitTriggerEventType " , intToStr ( lastUnitTriggerEventType ) , mapTagReplacements ) ;
2012-03-26 08:48:58 +02:00
luaScript . saveGame ( scriptManagerNode ) ;
}
void ScriptManager : : loadGame ( const XmlNode * rootNode ) {
const XmlNode * scriptManagerNode = rootNode - > getChild ( " ScriptManager " ) ;
// string code;
code = scriptManagerNode - > getAttribute ( " code " ) - > getValue ( ) ;
// LuaScript luaScript;
2013-12-30 21:55:59 +01:00
vector < XmlNode * > savedGameDataItemNodeList = scriptManagerNode - > getChildList ( " SavedGameDataItem " ) ;
2013-12-30 23:00:04 +01:00
if ( LuaScript : : getDebugModeEnabled ( ) = = true ) printf ( " In loadGame savedGameDataItemNodeList.size() = %d \n " , ( int ) savedGameDataItemNodeList . size ( ) ) ;
2013-12-30 21:55:59 +01:00
for ( unsigned int i = 0 ; i < savedGameDataItemNodeList . size ( ) ; + + i ) {
XmlNode * node = savedGameDataItemNodeList [ i ] ;
string key = node - > getAttribute ( " key " ) - > getValue ( ) ;
string value = node - > getAttribute ( " value " ) - > getValue ( ) ;
luaSavedGameData [ key ] = value ;
}
2012-03-26 08:48:58 +02:00
// //world
// World *world;
// GameCamera *gameCamera;
//
// //misc
// MessageQueue messageQueue;
messageQueue . clear ( ) ;
vector < XmlNode * > messageQueueNodeList = scriptManagerNode - > getChildList ( " ScriptManagerMessage " ) ;
for ( unsigned int i = 0 ; i < messageQueueNodeList . size ( ) ; + + i ) {
XmlNode * node = messageQueueNodeList [ i ] ;
ScriptManagerMessage msg ;
msg . loadGame ( node ) ;
messageQueue . push_back ( msg ) ;
}
// GraphicMessageBox messageBox;
2012-04-16 22:15:57 +02:00
messageBox . setEnabled ( scriptManagerNode - > getAttribute ( " messageBox_enabled " ) - > getIntValue ( ) ! = 0 ) ;
2016-11-26 15:46:32 +01:00
messageBox . setText ( scriptManagerNode - > getAttribute ( " messageBox_text " ) - > getValue ( ) ) ;
2012-03-26 08:48:58 +02:00
messageBox . setHeader ( scriptManagerNode - > getAttribute ( " messageBox_header " ) - > getValue ( ) ) ;
// string displayText;
displayText = scriptManagerNode - > getAttribute ( " displayText " ) - > getValue ( ) ;
//
// //last created unit
// string lastCreatedUnitName;
lastCreatedUnitName = scriptManagerNode - > getAttribute ( " lastCreatedUnitName " ) - > getValue ( ) ;
// int lastCreatedUnitId;
lastCreatedUnitId = scriptManagerNode - > getAttribute ( " lastCreatedUnitId " ) - > getIntValue ( ) ;
//
// //last dead unit
// string lastDeadUnitName;
lastDeadUnitName = scriptManagerNode - > getAttribute ( " lastDeadUnitName " ) - > getValue ( ) ;
// int lastDeadUnitId;
lastDeadUnitId = scriptManagerNode - > getAttribute ( " lastDeadUnitId " ) - > getIntValue ( ) ;
// int lastDeadUnitCauseOfDeath;
lastDeadUnitCauseOfDeath = scriptManagerNode - > getAttribute ( " lastDeadUnitCauseOfDeath " ) - > getIntValue ( ) ;
//
// //last dead unit's killer
// string lastDeadUnitKillerName;
lastDeadUnitKillerName = scriptManagerNode - > getAttribute ( " lastDeadUnitKillerName " ) - > getValue ( ) ;
// int lastDeadUnitKillerId;
lastDeadUnitKillerId = scriptManagerNode - > getAttribute ( " lastDeadUnitKillerId " ) - > getIntValue ( ) ;
//
// //last attacked unit
// string lastAttackedUnitName;
lastAttackedUnitName = scriptManagerNode - > getAttribute ( " lastAttackedUnitName " ) - > getValue ( ) ;
// int lastAttackedUnitId;
lastAttackedUnitId = scriptManagerNode - > getAttribute ( " lastAttackedUnitId " ) - > getIntValue ( ) ;
//
// //last attacking unit
// string lastAttackingUnitName;
lastAttackingUnitName = scriptManagerNode - > getAttribute ( " lastAttackingUnitName " ) - > getValue ( ) ;
// int lastAttackingUnitId;
lastAttackingUnitId = scriptManagerNode - > getAttribute ( " lastAttackingUnitId " ) - > getIntValue ( ) ;
//
// // end game state
// bool gameOver;
2012-04-16 22:15:57 +02:00
gameOver = scriptManagerNode - > getAttribute ( " gameOver " ) - > getIntValue ( ) ! = 0 ;
2012-03-26 08:48:58 +02:00
// bool gameWon;
2012-04-16 22:15:57 +02:00
gameWon = scriptManagerNode - > getAttribute ( " gameWon " ) - > getIntValue ( ) ! = 0 ;
2012-03-26 08:48:58 +02:00
// PlayerModifiers playerModifiers[GameConstants::maxPlayers];
vector < XmlNode * > playerModifiersNodeList = scriptManagerNode - > getChildList ( " PlayerModifiers " ) ;
for ( unsigned int i = 0 ; i < playerModifiersNodeList . size ( ) ; + + i ) {
XmlNode * node = playerModifiersNodeList [ i ] ;
playerModifiers [ i ] . loadGame ( node ) ;
}
// int currentTimerTriggeredEventId;
currentTimerTriggeredEventId = scriptManagerNode - > getAttribute ( " currentTimerTriggeredEventId " ) - > getIntValue ( ) ;
// int currentCellTriggeredEventId;
currentCellTriggeredEventId = scriptManagerNode - > getAttribute ( " currentCellTriggeredEventId " ) - > getIntValue ( ) ;
// int currentEventId;
currentEventId = scriptManagerNode - > getAttribute ( " currentEventId " ) - > getIntValue ( ) ;
// std::map<int,CellTriggerEvent> CellTriggerEventList;
vector < XmlNode * > cellTriggerEventListNodeList = scriptManagerNode - > getChildList ( " CellTriggerEventList " ) ;
for ( unsigned int i = 0 ; i < cellTriggerEventListNodeList . size ( ) ; + + i ) {
XmlNode * node = cellTriggerEventListNodeList [ i ] ;
CellTriggerEvent event ;
event . loadGame ( node ) ;
CellTriggerEventList [ node - > getAttribute ( " key " ) - > getIntValue ( ) ] = event ;
}
// std::map<int,TimerTriggerEvent> TimerTriggerEventList;
vector < XmlNode * > timerTriggerEventListNodeList = scriptManagerNode - > getChildList ( " TimerTriggerEventList " ) ;
for ( unsigned int i = 0 ; i < timerTriggerEventListNodeList . size ( ) ; + + i ) {
XmlNode * node = timerTriggerEventListNodeList [ i ] ;
TimerTriggerEvent event ;
event . loadGame ( node ) ;
TimerTriggerEventList [ node - > getAttribute ( " key " ) - > getIntValue ( ) ] = event ;
}
// bool inCellTriggerEvent;
2012-04-16 22:15:57 +02:00
inCellTriggerEvent = scriptManagerNode - > getAttribute ( " inCellTriggerEvent " ) - > getIntValue ( ) ! = 0 ;
2012-03-26 08:48:58 +02:00
// std::vector<int> unRegisterCellTriggerEventList;
vector < XmlNode * > unRegisterCellTriggerEventListNodeList = scriptManagerNode - > getChildList ( " unRegisterCellTriggerEventList " ) ;
for ( unsigned int i = 0 ; i < unRegisterCellTriggerEventListNodeList . size ( ) ; + + i ) {
XmlNode * node = unRegisterCellTriggerEventListNodeList [ i ] ;
unRegisterCellTriggerEventList . push_back ( node - > getAttribute ( " eventId " ) - > getIntValue ( ) ) ;
}
2013-05-26 00:44:39 +02:00
if ( scriptManagerNode - > hasAttribute ( " registeredDayNightEvent " ) = = true ) {
registeredDayNightEvent = scriptManagerNode - > getAttribute ( " registeredDayNightEvent " ) - > getIntValue ( ) ! = 0 ;
}
if ( scriptManagerNode - > hasAttribute ( " lastDayNightTriggerStatus " ) = = true ) {
lastDayNightTriggerStatus = scriptManagerNode - > getAttribute ( " lastDayNightTriggerStatus " ) - > getIntValue ( ) ;
}
2013-05-28 02:59:44 +02:00
vector < XmlNode * > unitTriggerEventListNodeList = scriptManagerNode - > getChildList ( " UnitTriggerEventList " ) ;
for ( unsigned int i = 0 ; i < unitTriggerEventListNodeList . size ( ) ; + + i ) {
XmlNode * node = unitTriggerEventListNodeList [ i ] ;
2013-11-04 20:16:28 +01:00
UnitTriggerEventType eventType = utet_None ;
2013-05-28 02:59:44 +02:00
int unitId = node - > getAttribute ( " unitId " ) - > getIntValue ( ) ;
2013-11-04 20:16:28 +01:00
if ( node - > hasAttribute ( " eventType " ) = = true ) {
eventType = static_cast < UnitTriggerEventType > ( node - > getAttribute ( " eventType " ) - > getIntValue ( ) ) ;
}
else if ( node - > hasAttribute ( " evenType " ) = = true ) {
eventType = static_cast < UnitTriggerEventType > ( node - > getAttribute ( " evenType " ) - > getIntValue ( ) ) ;
}
UnitTriggerEventList [ unitId ] = eventType ;
2013-05-28 02:59:44 +02:00
}
if ( scriptManagerNode - > hasAttribute ( " lastUnitTriggerEventUnitId " ) = = true ) {
lastUnitTriggerEventUnitId = scriptManagerNode - > getAttribute ( " lastUnitTriggerEventUnitId " ) - > getIntValue ( ) ;
}
if ( scriptManagerNode - > hasAttribute ( " lastUnitTriggerEventType " ) = = true ) {
lastUnitTriggerEventType = static_cast < UnitTriggerEventType > ( scriptManagerNode - > getAttribute ( " lastUnitTriggerEventType " ) - > getIntValue ( ) ) ;
}
2012-03-26 08:48:58 +02:00
luaScript . loadGame ( scriptManagerNode ) ;
}
2011-01-20 16:56:30 +01:00
} } //end namespace