- updated some new lua commands

This commit is contained in:
Mark Vejvoda 2011-01-29 17:52:53 +00:00
parent 041289770e
commit a5a6cf76d6
4 changed files with 35 additions and 0 deletions

View File

@ -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());

View File

@ -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);

View File

@ -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);

View File

@ -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);