mirror of
https://github.com/glest/glest-source.git
synced 2025-02-24 19:52:25 +01:00
- added more LUA functions:
int registerCellTriggerEventForUnitToUnit(int sourceUnitId, int destUnitId); int registerCellTriggerEventForUnitToLocation(int sourceUnitId, const Vec2i &pos); int registerCellTriggerEventForFactionToUnit(int sourceFactionId, int destUnitId); int registerCellTriggerEventForFactionToLocation(int sourceFactionId, const Vec2i &pos); int getCellTriggerEventCount(int eventId); void unregisterCellTriggerEvent(int eventId); int startTimerEvent(); int stopTimerEvent(int eventId); int timerEventSecondsElapsed(int eventId); int triggeredCellEventId(); int triggeredTimerEventId(); LUA events: timerTriggerEvent cellTriggerEvent
This commit is contained in:
parent
03848fc84f
commit
5ae0430928
@ -69,6 +69,10 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
|
||||
//set static instance
|
||||
thisScriptManager= this;
|
||||
|
||||
currentEventId = 1;
|
||||
CellTriggerEventList.clear();
|
||||
TimerTriggerEventList.clear();
|
||||
|
||||
//register functions
|
||||
luaScript.registerFunction(showMessage, "showMessage");
|
||||
luaScript.registerFunction(setDisplayText, "setDisplayText");
|
||||
@ -94,6 +98,18 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
|
||||
luaScript.registerFunction(endPerformanceTimer, "endPerformanceTimer");
|
||||
luaScript.registerFunction(getPerformanceTimerResults, "getPerformanceTimerResults");
|
||||
|
||||
luaScript.registerFunction(registerCellTriggerEventForUnitToUnit, "registerCellTriggerEventForUnitToUnit");
|
||||
luaScript.registerFunction(registerCellTriggerEventForUnitToLocation, "registerCellTriggerEventForUnitToLocation");
|
||||
luaScript.registerFunction(registerCellTriggerEventForFactionToUnit, "registerCellTriggerEventForFactionToUnit");
|
||||
luaScript.registerFunction(registerCellTriggerEventForFactionToLocation, "registerCellTriggerEventForFactionToLocation");
|
||||
luaScript.registerFunction(getCellTriggerEventCount, "getCellTriggerEventCount");
|
||||
luaScript.registerFunction(unregisterCellTriggerEvent, "unregisterCellTriggerEvent");
|
||||
luaScript.registerFunction(startTimerEvent, "startTimerEvent");
|
||||
luaScript.registerFunction(stopTimerEvent, "stopTimerEvent");
|
||||
luaScript.registerFunction(getTimerEventSecondsElapsed, "timerEventSecondsElapsed");
|
||||
luaScript.registerFunction(getCellTriggeredEventId, "triggeredCellEventId");
|
||||
luaScript.registerFunction(getTimerTriggeredEventId, "triggeredTimerEventId");
|
||||
|
||||
luaScript.registerFunction(getStartLocation, "startLocation");
|
||||
luaScript.registerFunction(getUnitPosition, "unitPosition");
|
||||
luaScript.registerFunction(getUnitFaction, "unitFaction");
|
||||
@ -105,7 +121,7 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
|
||||
luaScript.registerFunction(getUnitCount, "unitCount");
|
||||
luaScript.registerFunction(getUnitCountOfType, "unitCountOfType");
|
||||
|
||||
luaScript.registerFunction(getLastCreatedUnitName, "gameWon");
|
||||
luaScript.registerFunction(getGameWon, "gameWon");
|
||||
|
||||
//load code
|
||||
for(int i= 0; i<scenario->getScriptCount(); ++i){
|
||||
@ -163,12 +179,130 @@ void ScriptManager::onUnitDied(const Unit* unit){
|
||||
luaScript.endCall();
|
||||
}
|
||||
|
||||
void ScriptManager::onGameOver(bool won){
|
||||
void ScriptManager::onGameOver(bool won) {
|
||||
gameWon = won;
|
||||
luaScript.beginCall("gameOver");
|
||||
luaScript.endCall();
|
||||
}
|
||||
|
||||
void ScriptManager::onTimerTriggerEvent() {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] TimerTriggerEventList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,TimerTriggerEventList.size());
|
||||
if(TimerTriggerEventList.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(std::map<int,TimerTriggerEvent>::iterator iterMap = TimerTriggerEventList.begin();
|
||||
iterMap != TimerTriggerEventList.end(); iterMap++) {
|
||||
|
||||
TimerTriggerEvent &event = iterMap->second;
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] event.running = %d, event.startTime = %lld, event.endTime = %lld, diff = %f\n",
|
||||
__FILE__,__FUNCTION__,__LINE__,event.running,(long long int)event.startTime,(long long int)event.endTime,difftime(event.endTime,event.startTime));
|
||||
|
||||
if(event.running == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
currentTimerTriggeredEventId = iterMap->first;
|
||||
luaScript.beginCall("timerTriggerEvent");
|
||||
luaScript.endCall();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptManager::onCellTriggerEvent(Unit *movingUnit) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] movingUnit = %p, CellTriggerEventList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,movingUnit,CellTriggerEventList.size());
|
||||
if(CellTriggerEventList.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(movingUnit != NULL) {
|
||||
for(std::map<int,CellTriggerEvent>::iterator iterMap = CellTriggerEventList.begin();
|
||||
iterMap != CellTriggerEventList.end(); iterMap++) {
|
||||
|
||||
bool triggerEvent = false;
|
||||
CellTriggerEvent &event = iterMap->second;
|
||||
|
||||
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",
|
||||
__FILE__,__FUNCTION__,__LINE__,movingUnit->getId(),event.type,movingUnit->getPos().getString().c_str(), event.sourceId,event.destId,event.destPos.getString().c_str());
|
||||
|
||||
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());
|
||||
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",
|
||||
__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) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
triggerEvent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ctet_UnitPos:
|
||||
{
|
||||
if(movingUnit->getId() == event.sourceId) {
|
||||
bool srcInDst = world->getMap()->isInUnitTypeCells(0, event.destPos,movingUnit->getPos());
|
||||
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,event.destPos.getString().c_str(),srcInDst);
|
||||
|
||||
if(srcInDst == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
triggerEvent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
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());
|
||||
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,event.destPos.getString().c_str(),srcInDst);
|
||||
|
||||
if(srcInDst == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
triggerEvent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ctet_FactionPos:
|
||||
{
|
||||
if(movingUnit->getFactionIndex() == event.sourceId &&
|
||||
world->getMap()->isInUnitTypeCells(0, event.destPos,movingUnit->getPos())) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
triggerEvent = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if(triggerEvent == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
currentCellTriggeredEventId = iterMap->first;
|
||||
event.triggerCount++;
|
||||
luaScript.beginCall("cellTriggerEvent");
|
||||
luaScript.endCall();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========================== lua wrappers ===============================================
|
||||
|
||||
string ScriptManager::wrapString(const string &str, int wrapCount){
|
||||
@ -234,7 +368,7 @@ void ScriptManager::setCameraPosition(const Vec2i &pos){
|
||||
}
|
||||
|
||||
void ScriptManager::createUnit(const string &unitName, int factionIndex, Vec2i pos){
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,unitName.c_str(),factionIndex);
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,unitName.c_str(),factionIndex);
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
world->createUnit(unitName, factionIndex, pos);
|
||||
}
|
||||
@ -306,6 +440,120 @@ bool ScriptManager::getHungerEnabled(int factionIndex){
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] Unit: %d will trigger cell event when reaching unit: %d, eventId = %d\n",__FILE__,__FUNCTION__,__LINE__,sourceUnitId,destUnitId,eventId);
|
||||
|
||||
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;
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] Unit: %d will trigger cell event when reaching pos: %s, eventId = %d\n",__FILE__,__FUNCTION__,__LINE__,sourceUnitId,pos.getString().c_str(),eventId);
|
||||
|
||||
return eventId;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] Faction: %d will trigger cell event when reaching unit: %d, eventId = %d\n",__FILE__,__FUNCTION__,__LINE__,sourceFactionId,destUnitId,eventId);
|
||||
|
||||
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;
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]Faction: %d will trigger cell event when reaching pos: %s, eventId = %d\n",__FILE__,__FUNCTION__,__LINE__,sourceFactionId,pos.getString().c_str(),eventId);
|
||||
|
||||
return eventId;
|
||||
}
|
||||
|
||||
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()) {
|
||||
CellTriggerEventList.erase(eventId);
|
||||
}
|
||||
}
|
||||
|
||||
int ScriptManager::startTimerEvent() {
|
||||
TimerTriggerEvent trigger;
|
||||
trigger.running = true;
|
||||
trigger.startTime = time(NULL);
|
||||
trigger.endTime = 0;
|
||||
|
||||
int eventId = currentEventId++;
|
||||
TimerTriggerEventList[eventId] = trigger;
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] TimerTriggerEventList.size() = %d, eventId = %d, trigger.startTime = %lld, trigger.endTime = %lld\n",__FILE__,__FUNCTION__,__LINE__,TimerTriggerEventList.size(),eventId,(long long int)trigger.startTime,(long long int)trigger.endTime);
|
||||
|
||||
return eventId;
|
||||
}
|
||||
|
||||
int ScriptManager::stopTimerEvent(int eventId) {
|
||||
int result = 0;
|
||||
if(TimerTriggerEventList.find(eventId) != TimerTriggerEventList.end()) {
|
||||
TimerTriggerEvent &trigger = TimerTriggerEventList[eventId];
|
||||
trigger.endTime = time(NULL);
|
||||
trigger.running = false;
|
||||
result = getTimerEventSecondsElapsed(eventId);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] TimerTriggerEventList.size() = %d, eventId = %d, trigger.startTime = %lld, trigger.endTime = %lld, result = %d\n",__FILE__,__FUNCTION__,__LINE__,TimerTriggerEventList.size(),eventId,(long long int)trigger.startTime,(long long int)trigger.endTime,result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int ScriptManager::getTimerEventSecondsElapsed(int eventId) {
|
||||
int result = 0;
|
||||
if(TimerTriggerEventList.find(eventId) != TimerTriggerEventList.end()) {
|
||||
TimerTriggerEvent &trigger = TimerTriggerEventList[eventId];
|
||||
if(trigger.running) {
|
||||
result = (int)difftime(time(NULL),trigger.startTime);
|
||||
}
|
||||
else {
|
||||
result = (int)difftime(trigger.endTime,trigger.startTime);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ScriptManager::setPlayerAsWinner(int factionIndex){
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
if(factionIndex<GameConstants::maxPlayers){
|
||||
@ -370,6 +618,16 @@ const string &ScriptManager::getLastCreatedUnitName(){
|
||||
return lastCreatedUnitName;
|
||||
}
|
||||
|
||||
int ScriptManager::getCellTriggeredEventId() {
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
return currentCellTriggeredEventId;
|
||||
}
|
||||
|
||||
int ScriptManager::getTimerTriggeredEventId() {
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
return currentTimerTriggeredEventId;
|
||||
}
|
||||
|
||||
bool ScriptManager::getGameWon() {
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
return gameWon;
|
||||
@ -429,7 +687,7 @@ int ScriptManager::setCameraPosition(LuaHandle* luaHandle){
|
||||
int ScriptManager::createUnit(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-3).c_str(),luaArguments.getInt(-2));
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-3).c_str(),luaArguments.getInt(-2));
|
||||
|
||||
thisScriptManager->createUnit(
|
||||
luaArguments.getString(-3),
|
||||
@ -515,6 +773,68 @@ int ScriptManager::getHungerEnabled(LuaHandle* luaHandle){
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::registerCellTriggerEventForUnitToUnit(LuaHandle* luaHandle) {
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
int result = thisScriptManager->registerCellTriggerEventForUnitToUnit(luaArguments.getInt(-2),luaArguments.getInt(-1));
|
||||
luaArguments.returnInt(result);
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::registerCellTriggerEventForUnitToLocation(LuaHandle* luaHandle) {
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
int result = thisScriptManager->registerCellTriggerEventForUnitToLocation(luaArguments.getInt(-2),luaArguments.getVec2i(-1));
|
||||
luaArguments.returnInt(result);
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::registerCellTriggerEventForFactionToUnit(LuaHandle* luaHandle) {
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
int result = thisScriptManager->registerCellTriggerEventForFactionToUnit(luaArguments.getInt(-2),luaArguments.getInt(-1));
|
||||
luaArguments.returnInt(result);
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::registerCellTriggerEventForFactionToLocation(LuaHandle* luaHandle) {
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
int result = thisScriptManager->registerCellTriggerEventForFactionToLocation(luaArguments.getInt(-2),luaArguments.getVec2i(-1));
|
||||
luaArguments.returnInt(result);
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::getCellTriggerEventCount(LuaHandle* luaHandle) {
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
int result = thisScriptManager->getCellTriggerEventCount(luaArguments.getInt(-1));
|
||||
luaArguments.returnInt(result);
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::unregisterCellTriggerEvent(LuaHandle* luaHandle) {
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
thisScriptManager->unregisterCellTriggerEvent(luaArguments.getInt(-1));
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::startTimerEvent(LuaHandle* luaHandle) {
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
int result = thisScriptManager->startTimerEvent();
|
||||
luaArguments.returnInt(result);
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::stopTimerEvent(LuaHandle* luaHandle) {
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
int result = thisScriptManager->stopTimerEvent(luaArguments.getInt(-1));
|
||||
luaArguments.returnInt(result);
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::getTimerEventSecondsElapsed(LuaHandle* luaHandle) {
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
int result = thisScriptManager->getTimerEventSecondsElapsed(luaArguments.getInt(-1));
|
||||
luaArguments.returnInt(result);
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::setPlayerAsWinner(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
thisScriptManager->setPlayerAsWinner(luaArguments.getInt(-1));
|
||||
@ -585,6 +905,18 @@ int ScriptManager::getLastCreatedUnitId(LuaHandle* luaHandle){
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::getCellTriggeredEventId(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
luaArguments.returnInt(thisScriptManager->getCellTriggeredEventId());
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::getTimerTriggeredEventId(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
luaArguments.returnInt(thisScriptManager->getTimerTriggeredEventId());
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::getLastDeadUnitName(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
luaArguments.returnString(thisScriptManager->getLastDeadUnitName());
|
||||
@ -623,7 +955,7 @@ int ScriptManager::DisplayFormattedText(LuaHandle* luaHandle) {
|
||||
//va_list argList;
|
||||
//va_start(argList, fmt.c_str() );
|
||||
|
||||
printf("\nDisplayFormattedText args = %d!\n",args);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"DisplayFormattedText args = %d!\n",args);
|
||||
|
||||
if(args == 1) {
|
||||
thisScriptManager->DisplayFormattedText(fmt.c_str());
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "components.h"
|
||||
#include "game_constants.h"
|
||||
#include <map>
|
||||
|
||||
using std::string;
|
||||
using std::queue;
|
||||
@ -74,6 +75,30 @@ private:
|
||||
// class ScriptManager
|
||||
// =====================================================
|
||||
|
||||
enum CellTriggerEventType {
|
||||
ctet_Unit,
|
||||
ctet_UnitPos,
|
||||
ctet_Faction,
|
||||
ctet_FactionPos
|
||||
};
|
||||
|
||||
class CellTriggerEvent {
|
||||
public:
|
||||
CellTriggerEventType type;
|
||||
int sourceId;
|
||||
int destId;
|
||||
Vec2i destPos;
|
||||
|
||||
int triggerCount;
|
||||
};
|
||||
|
||||
class TimerTriggerEvent {
|
||||
public:
|
||||
bool running;
|
||||
time_t startTime;
|
||||
time_t endTime;
|
||||
};
|
||||
|
||||
class ScriptManager{
|
||||
private:
|
||||
typedef queue<ScriptManagerMessage> MessageQueue;
|
||||
@ -106,6 +131,12 @@ private:
|
||||
bool gameWon;
|
||||
PlayerModifiers playerModifiers[GameConstants::maxPlayers];
|
||||
|
||||
int currentTimerTriggeredEventId;
|
||||
int currentCellTriggeredEventId;
|
||||
int currentEventId;
|
||||
std::map<int,CellTriggerEvent> CellTriggerEventList;
|
||||
std::map<int,TimerTriggerEvent> TimerTriggerEventList;
|
||||
|
||||
private:
|
||||
static ScriptManager* thisScriptManager;
|
||||
|
||||
@ -130,6 +161,8 @@ public:
|
||||
void onUnitCreated(const Unit* unit);
|
||||
void onUnitDied(const Unit* unit);
|
||||
void onGameOver(bool won);
|
||||
void onCellTriggerEvent(Unit *movingUnit);
|
||||
void onTimerTriggerEvent();
|
||||
|
||||
private:
|
||||
string wrapString(const string &str, int wrapCount);
|
||||
@ -151,6 +184,18 @@ private:
|
||||
void disableHunger(int factionIndex);
|
||||
void enableHunger(int factionIndex);
|
||||
|
||||
int registerCellTriggerEventForUnitToUnit(int sourceUnitId, int destUnitId);
|
||||
int registerCellTriggerEventForUnitToLocation(int sourceUnitId, const Vec2i &pos);
|
||||
int registerCellTriggerEventForFactionToUnit(int sourceFactionId, int destUnitId);
|
||||
int registerCellTriggerEventForFactionToLocation(int sourceFactionId, const Vec2i &pos);
|
||||
int getCellTriggerEventCount(int eventId);
|
||||
void unregisterCellTriggerEvent(int eventId);
|
||||
int startTimerEvent();
|
||||
int stopTimerEvent(int eventId);
|
||||
int getTimerEventSecondsElapsed(int eventId);
|
||||
int getCellTriggeredEventId();
|
||||
int getTimerTriggeredEventId();
|
||||
|
||||
bool getAiEnabled(int factionIndex);
|
||||
bool getHungerEnabled(int factionIndex);
|
||||
|
||||
@ -187,14 +232,29 @@ private:
|
||||
static int giveProductionCommand(LuaHandle* luaHandle);
|
||||
static int giveAttackCommand(LuaHandle* luaHandle);
|
||||
static int giveUpgradeCommand(LuaHandle* luaHandle);
|
||||
|
||||
static int disableAi(LuaHandle* luaHandle);
|
||||
static int enableAi(LuaHandle* luaHandle);
|
||||
|
||||
static int disableHunger(LuaHandle* luaHandle);
|
||||
static int enableHunger(LuaHandle* luaHandle);
|
||||
|
||||
static int getAiEnabled(LuaHandle* luaHandle);
|
||||
static int getHungerEnabled(LuaHandle* luaHandle);
|
||||
|
||||
static int registerCellTriggerEventForUnitToUnit(LuaHandle* luaHandle);
|
||||
static int registerCellTriggerEventForUnitToLocation(LuaHandle* luaHandle);
|
||||
static int registerCellTriggerEventForFactionToUnit(LuaHandle* luaHandle);
|
||||
static int registerCellTriggerEventForFactionToLocation(LuaHandle* luaHandle);
|
||||
static int getCellTriggerEventCount(LuaHandle* luaHandle);
|
||||
static int unregisterCellTriggerEvent(LuaHandle* luaHandle);
|
||||
static int startTimerEvent(LuaHandle* luaHandle);
|
||||
static int stopTimerEvent(LuaHandle* luaHandle);
|
||||
static int getTimerEventSecondsElapsed(LuaHandle* luaHandle);
|
||||
|
||||
static int getCellTriggeredEventId(LuaHandle* luaHandle);
|
||||
static int getTimerTriggeredEventId(LuaHandle* luaHandle);
|
||||
|
||||
static int setPlayerAsWinner(LuaHandle* luaHandle);
|
||||
static int endGame(LuaHandle* luaHandle);
|
||||
|
||||
|
@ -560,6 +560,7 @@ int glestMain(int argc, char** argv){
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled = config.getBool("DebugWorldSynch","false");
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled = config.getBool("DebugUnitCommands","false");
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled = config.getBool("DebugPathFinder","false");
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled = config.getBool("DebugLUA","false");
|
||||
|
||||
string debugLogFile = config.getString("DebugLogFile","");
|
||||
if(getGameReadWritePath() != "") {
|
||||
@ -585,22 +586,28 @@ int glestMain(int argc, char** argv){
|
||||
if(debugUnitCommandsLogFile == "") {
|
||||
debugUnitCommandsLogFile = debugLogFile;
|
||||
}
|
||||
string debugLUALogFile = config.getString("DebugLogFileLUA","");
|
||||
if(debugLUALogFile == "") {
|
||||
debugLUALogFile = debugLogFile;
|
||||
}
|
||||
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugSystem).debugLogFileName = debugLogFile;
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).debugLogFileName = debugNetworkLogFile;
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).debugLogFileName = debugPerformanceLogFile;
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).debugLogFileName = debugWorldSynchLogFile;
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).debugLogFileName = debugUnitCommandsLogFile;
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).debugLogFileName = debugPathFinderLogFile;
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).debugLogFileName = debugUnitCommandsLogFile;
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).debugLogFileName = debugPathFinderLogFile;
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugLUA).debugLogFileName = debugLUALogFile;
|
||||
|
||||
if(haveSpecialOutputCommandLineOption == false) {
|
||||
printf("Startup settings are: debugSystem [%d], debugNetwork [%d], debugPerformance [%d], debugWorldSynch [%d], debugUnitCommands[%d], debugPathFinder[%d]\n",
|
||||
printf("Startup settings are: debugSystem [%d], debugNetwork [%d], debugPerformance [%d], debugWorldSynch [%d], debugUnitCommands[%d], debugPathFinder[%d], debugLUA [%d]\n",
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled,
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled,
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled,
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled,
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled,
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled);
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled,
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled);
|
||||
}
|
||||
|
||||
NetworkInterface::setDisplayMessageFunction(ExceptionHandler::DisplayMessage);
|
||||
|
@ -439,7 +439,7 @@ bool Map::aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) c
|
||||
}
|
||||
}
|
||||
|
||||
//put a units into the cells
|
||||
// is testPos in the cells of unitType where unitType's position is pos
|
||||
bool Map::isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos) {
|
||||
|
||||
assert(ut!=NULL);
|
||||
|
@ -243,6 +243,7 @@ void World::loadScenario(const string &path, Checksum *checksum){
|
||||
// ==================== misc ====================
|
||||
|
||||
void World::updateAllFactionUnits() {
|
||||
scriptManager->onTimerTriggerEvent();
|
||||
//units
|
||||
for(int i=0; i<getFactionCount(); ++i) {
|
||||
for(int j=0; j<getFaction(i)->getUnitCount(); ++j) {
|
||||
@ -539,6 +540,8 @@ void World::moveUnitCells(Unit *unit){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scriptManager->onCellTriggerEvent(unit);
|
||||
}
|
||||
|
||||
//returns the nearest unit that can store a type of resource given a position and a faction
|
||||
|
@ -41,7 +41,8 @@ public:
|
||||
debugPerformance,
|
||||
debugWorldSynch,
|
||||
debugUnitCommands,
|
||||
debugPathFinder
|
||||
debugPathFinder,
|
||||
debugLUA,
|
||||
};
|
||||
|
||||
class SystemFlagsType
|
||||
|
@ -156,6 +156,7 @@ void SystemFlags::init(bool haveSpecialOutputCommandLineOption) {
|
||||
SystemFlags::debugLogFileList[SystemFlags::debugPerformance] = SystemFlags::SystemFlagsType(SystemFlags::debugPerformance);
|
||||
SystemFlags::debugLogFileList[SystemFlags::debugWorldSynch] = SystemFlags::SystemFlagsType(SystemFlags::debugWorldSynch);
|
||||
SystemFlags::debugLogFileList[SystemFlags::debugUnitCommands] = SystemFlags::SystemFlagsType(SystemFlags::debugUnitCommands);
|
||||
SystemFlags::debugLogFileList[SystemFlags::debugLUA] = SystemFlags::SystemFlagsType(SystemFlags::debugLUA);
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
@ -361,7 +362,8 @@ void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) {
|
||||
|
||||
if (type != debugPathFinder) {
|
||||
(*currentDebugLog.fileStream) << "[" << szBuf2 << "] " << szBuf;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
(*currentDebugLog.fileStream) << szBuf;
|
||||
}
|
||||
(*currentDebugLog.fileStream).flush();
|
||||
@ -372,7 +374,8 @@ void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) {
|
||||
else {
|
||||
if (type != debugPathFinder) {
|
||||
printf("[%s] %s", szBuf2, szBuf);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printf("%s", szBuf);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user