From a5a6cf76d610b8e4d67d59704a9ab35d03036518 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 29 Jan 2011 17:52:53 +0000 Subject: [PATCH] - updated some new lua commands --- source/glest_game/game/script_manager.cpp | 16 ++++++++++++++++ source/glest_game/game/script_manager.h | 2 ++ source/glest_game/world/world.cpp | 16 ++++++++++++++++ source/glest_game/world/world.h | 1 + 4 files changed, 35 insertions(+) diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index b2d0e994..21536021 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -84,6 +84,7 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){ luaScript.registerFunction(createUnit, "createUnit"); luaScript.registerFunction(destroyUnit, "destroyUnit"); luaScript.registerFunction(morphToUnit, "morphToUnit"); + luaScript.registerFunction(moveToUnit, "moveToUnit"); luaScript.registerFunction(playStaticSound, "playStaticSound"); luaScript.registerFunction(playStreamingSound, "playStreamingSound"); luaScript.registerFunction(stopStreamingSound, "stopStreamingSound"); @@ -461,6 +462,12 @@ void ScriptManager::morphToUnit(int unitId,const string &morphName, int ignoreRe world->morphToUnit(unitId,morphName,(ignoreRequirements == 1)); } +void ScriptManager::moveToUnit(int unitId,int destUnitId) { + SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] destUnitId [%d]\n",__FILE__,__FUNCTION__,__LINE__,unitId,destUnitId); + ScriptManager_STREFLOP_Wrapper streflopWrapper; + world->moveToUnit(unitId,destUnitId); +} + void ScriptManager::giveResource(const string &resourceName, int factionIndex, int amount){ SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); ScriptManager_STREFLOP_Wrapper streflopWrapper; @@ -865,6 +872,15 @@ int ScriptManager::morphToUnit(LuaHandle* luaHandle) { return luaArguments.getReturnCount(); } +int ScriptManager::moveToUnit(LuaHandle* luaHandle) { + LuaArguments luaArguments(luaHandle); + + SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] dest unit [%d]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getInt(-2),luaArguments.getInt(-1)); + + thisScriptManager->moveToUnit(luaArguments.getInt(-2),luaArguments.getInt(-1)); + return luaArguments.getReturnCount(); +} + int ScriptManager::playStaticSound(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index a9d07a31..f8fc9a73 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -179,6 +179,7 @@ private: void destroyUnit(int unitId); void morphToUnit(int unitId,const string &morphName, int ignoreRequirements); + void moveToUnit(int unitId,int destUnitId); void giveAttackStoppedCommand(int unitId, const string &valueName,int ignoreRequirements); void playStaticSound(const string &playSound); void playStreamingSound(const string &playSound); @@ -243,6 +244,7 @@ private: static int destroyUnit(LuaHandle* luaHandle); static int morphToUnit(LuaHandle* luaHandle); + static int moveToUnit(LuaHandle* luaHandle); static int giveAttackStoppedCommand(LuaHandle* luaHandle); static int playStaticSound(LuaHandle* luaHandle); static int playStreamingSound(LuaHandle* luaHandle); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 0b89270b..1e9030b9 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -918,6 +918,22 @@ void World::stopAllSound() { soundRenderer.stopAllSounds(); } +void World::moveToUnit(int unitId, int destUnitId) { + Unit* unit= findUnitById(unitId); + if(unit != NULL) { + CommandClass cc= ccMove; + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] cc = %d Unit [%s]\n",__FILE__,__FUNCTION__,__LINE__,cc,unit->getFullName().c_str()); + Unit* destUnit = findUnitById(destUnitId); + if(destUnit != NULL) { + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] cc = %d Unit [%s] destUnit [%s]\n",__FILE__,__FUNCTION__,__LINE__,cc,unit->getFullName().c_str(),destUnit->getFullName().c_str()); + unit->giveCommand(new Command( unit->getType()->getFirstCtOfClass(cc), destUnit)); + SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + } + } + else { + throw runtime_error("Invalid unitId index in followUnit: " + intToStr(unitId)); + } +} void World::giveUpgradeCommand(int unitId, const string &upgradeName) { Unit *unit= findUnitById(unitId); diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index bf1eda6b..35b5a93e 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -201,6 +201,7 @@ public: void playStreamingSound(const string &playSound); void stopStreamingSound(const string &playSound); void stopAllSound(); + void moveToUnit(int unitId, int destUnitId); void giveResource(const string &resourceName, int factionIndex, int amount); int getResourceAmount(const string &resourceName, int factionIndex);