From 5c0090d48844d3805f33b902ddf06fb6146bb844 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 10 Oct 2012 19:56:52 +0000 Subject: [PATCH] - bug fixes for free cell lua functions --- source/glest_game/game/script_manager.cpp | 35 ++++++++++++++++------- source/glest_game/game/script_manager.h | 4 +-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index 25cfcce45..abcf2118a 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -1386,7 +1386,11 @@ Vec2i ScriptManager::getStartLocation(int factionIndex) { Vec2i ScriptManager::getUnitPosition(int unitId) { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); ScriptManager_STREFLOP_Wrapper streflopWrapper; - return world->getUnitPosition(unitId); + Vec2i result = world->getUnitPosition(unitId); + + printf("In [%s] unitId = %d, pos [%s]\n",__FUNCTION__,unitId,result.getString().c_str()); + + return result; } void ScriptManager::setUnitPosition(int unitId, Vec2i pos) { @@ -1587,20 +1591,27 @@ int ScriptManager::getUnitCurrentField(int unitId) { return world->getUnitCurrentField(unitId); } -bool ScriptManager::isFreeCellsOrHasUnit(Vec2i pos, int field, int unitId) { +int ScriptManager::isFreeCellsOrHasUnit(int field, int unitId, Vec2i pos) { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); ScriptManager_STREFLOP_Wrapper streflopWrapper; Unit* unit= world->findUnitById(unitId); + int result = world->getMap()->isFreeCellsOrHasUnit(pos,unit->getType()->getSize(),static_cast(field),unit,NULL,true); - return world->getMap()->isFreeCellsOrHasUnit(pos,unit->getType()->getSize(),static_cast(field),unit,NULL,true); + 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().c_str(),pos.getString().c_str(),field,result); + + return result; } -bool ScriptManager::isFreeCells(Vec2i pos, int unitSize, int field) { +int ScriptManager::isFreeCells(int unitSize, int field, Vec2i pos) { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); ScriptManager_STREFLOP_Wrapper streflopWrapper; - return world->getMap()->isFreeCellsOrHasUnit(pos,unitSize,static_cast(field),NULL,NULL,true); + int result = world->getMap()->isFreeCellsOrHasUnit(pos,unitSize,static_cast(field),NULL,NULL,true); + + 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; } // ========================== lua callbacks =============================================== @@ -2522,10 +2533,11 @@ int ScriptManager::getIsUnitAlive(LuaHandle* luaHandle) { int ScriptManager::isFreeCellsOrHasUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - bool result= thisScriptManager->isFreeCellsOrHasUnit( - luaArguments.getVec2i(-3), + int result= thisScriptManager->isFreeCellsOrHasUnit( + luaArguments.getInt(-3), luaArguments.getInt(-2), - luaArguments.getInt(-1)); + luaArguments.getVec2i(-1)); + luaArguments.returnInt(result); return luaArguments.getReturnCount(); } @@ -2533,10 +2545,11 @@ int ScriptManager::isFreeCellsOrHasUnit(LuaHandle* luaHandle) { int ScriptManager::isFreeCells(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - bool result= thisScriptManager->isFreeCells( - luaArguments.getVec2i(-3), + int result= thisScriptManager->isFreeCells( + luaArguments.getInt(-3), luaArguments.getInt(-2), - luaArguments.getInt(-1)); + luaArguments.getVec2i(-1)); + luaArguments.returnInt(result); return luaArguments.getReturnCount(); } diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index 7fc1e06fb..a336b9f5f 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -358,8 +358,8 @@ private: void loadScenario(const string &name, bool keepFactions); - bool isFreeCellsOrHasUnit(Vec2i pos, int field, int unitId); - bool isFreeCells(Vec2i pos, int unitSize, int field); + int isFreeCellsOrHasUnit(int field, int unitId,Vec2i pos); + int isFreeCells(int unitSize, int field,Vec2i pos); //callbacks, commands