- attempt to fix lua code to properly get unit's killer:

lastDeadUnitKillerName
lastDeadUnitKiller
This commit is contained in:
Mark Vejvoda 2011-11-18 15:43:05 +00:00
parent 93f0813033
commit f626ebbe45
3 changed files with 58 additions and 1 deletions

View File

@ -148,6 +148,8 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
luaScript.registerFunction(getLastDeadUnitName, "lastDeadUnitName");
luaScript.registerFunction(getLastDeadUnitId, "lastDeadUnit");
luaScript.registerFunction(getLastDeadUnitCauseOfDeath, "lastDeadUnitCauseOfDeath");
luaScript.registerFunction(getLastDeadUnitKillerName, "lastDeadUnitKillerName");
luaScript.registerFunction(getLastDeadUnitKillerId, "lastDeadUnitKiller");
luaScript.registerFunction(getLastAttackedUnitName, "lastAttackedUnitName");
luaScript.registerFunction(getLastAttackedUnitId, "lastAttackedUnit");
@ -174,8 +176,11 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
//last created unit
lastCreatedUnitId= -1;
lastDeadUnitName = "";
lastDeadUnitId= -1;
lastDeadUnitCauseOfDeath = ucodNone;
lastDeadUnitKillerName = "";
lastDeadUnitKillerId= -1;
lastAttackedUnitName = "";
lastAttackedUnitId = -1;
@ -231,6 +236,25 @@ void ScriptManager::onUnitCreated(const Unit* unit){
void ScriptManager::onUnitDied(const Unit* unit){
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(unit->getLastAttackerUnitId() >= 0) {
Unit *killer = world->findUnitById(unit->getLastAttackerUnitId());
if(killer != NULL) {
lastAttackingUnitName= killer->getType()->getName();
lastAttackingUnitId= killer->getId();
lastDeadUnitKillerName= killer->getType()->getName();
lastDeadUnitKillerId= killer->getId();
}
else {
lastDeadUnitKillerName= "";
lastDeadUnitKillerId= -1;
}
}
lastAttackedUnitName= unit->getType()->getName();
lastAttackedUnitId= unit->getId();
lastDeadUnitName= unit->getType()->getName();
lastDeadUnitId= unit->getId();
lastDeadUnitCauseOfDeath = unit->getCauseOfDeath();
@ -939,6 +963,18 @@ int ScriptManager::getLastDeadUnitCauseOfDeath() {
return lastDeadUnitCauseOfDeath;
}
const string &ScriptManager::getLastDeadUnitKillerName() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return lastDeadUnitKillerName;
}
int ScriptManager::getLastDeadUnitKillerId() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return lastDeadUnitKillerId;
}
const string &ScriptManager::getLastAttackedUnitName() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
ScriptManager_STREFLOP_Wrapper streflopWrapper;
@ -1385,6 +1421,18 @@ int ScriptManager::getLastDeadUnitCauseOfDeath(LuaHandle* luaHandle){
return luaArguments.getReturnCount();
}
int ScriptManager::getLastDeadUnitKillerName(LuaHandle* luaHandle){
LuaArguments luaArguments(luaHandle);
luaArguments.returnString(thisScriptManager->getLastDeadUnitKillerName());
return luaArguments.getReturnCount();
}
int ScriptManager::getLastDeadUnitKillerId(LuaHandle* luaHandle){
LuaArguments luaArguments(luaHandle);
luaArguments.returnInt(thisScriptManager->getLastDeadUnitKillerId());
return luaArguments.getReturnCount();
}
int ScriptManager::getLastAttackedUnitName(LuaHandle* luaHandle) {
LuaArguments luaArguments(luaHandle);
luaArguments.returnString(thisScriptManager->getLastAttackedUnitName());

View File

@ -130,6 +130,10 @@ private:
int lastDeadUnitId;
int lastDeadUnitCauseOfDeath;
//last dead unit's killer
string lastDeadUnitKillerName;
int lastDeadUnitKillerId;
//last attacked unit
string lastAttackedUnitName;
int lastAttackedUnitId;
@ -253,7 +257,8 @@ private:
const string &getLastDeadUnitName();
int getLastDeadUnitId();
int getLastDeadUnitCauseOfDeath();
const string &getLastDeadUnitKillerName();
int getLastDeadUnitKillerId();
const string &getLastAttackedUnitName();
int getLastAttackedUnitId();
@ -337,6 +342,8 @@ private:
static int getLastDeadUnitName(LuaHandle* luaHandle);
static int getLastDeadUnitId(LuaHandle* luaHandle);
static int getLastDeadUnitCauseOfDeath(LuaHandle* luaHandle);
static int getLastDeadUnitKillerName(LuaHandle* luaHandle);
static int getLastDeadUnitKillerId(LuaHandle* luaHandle);
static int getLastAttackedUnitName(LuaHandle* luaHandle);
static int getLastAttackedUnitId(LuaHandle* luaHandle);

View File

@ -2063,6 +2063,8 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
default:
throw runtime_error("detected unsupported pathfinder type!");
}
attacked->setCauseOfDeath(ucodAttacked);
scriptManager->onUnitDied(attacked);
}