added a bunch of new lua methods for Tigers new scenario to montior changes to a unit
This commit is contained in:
parent
93caf14362
commit
7ee5d2b300
|
@ -214,6 +214,9 @@ ScriptManager::ScriptManager() {
|
||||||
currentCellTriggeredEventAreaExitUnitId = 0;
|
currentCellTriggeredEventAreaExitUnitId = 0;
|
||||||
lastDayNightTriggerStatus = 0;
|
lastDayNightTriggerStatus = 0;
|
||||||
registeredDayNightEvent = false;
|
registeredDayNightEvent = false;
|
||||||
|
|
||||||
|
lastUnitTriggerEventUnitId = -1;
|
||||||
|
lastUnitTriggerEventType = utet_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptManager::~ScriptManager() {
|
ScriptManager::~ScriptManager() {
|
||||||
|
@ -389,6 +392,13 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro
|
||||||
luaScript.registerFunction(registerDayNightEvent, "registerDayNightEvent");
|
luaScript.registerFunction(registerDayNightEvent, "registerDayNightEvent");
|
||||||
luaScript.registerFunction(unregisterDayNightEvent, "unregisterDayNightEvent");
|
luaScript.registerFunction(unregisterDayNightEvent, "unregisterDayNightEvent");
|
||||||
|
|
||||||
|
luaScript.registerFunction(registerUnitTriggerEvent, "registerUnitTriggerEvent");
|
||||||
|
luaScript.registerFunction(unregisterUnitTriggerEvent, "unregisterUnitTriggerEvent");
|
||||||
|
luaScript.registerFunction(getLastUnitTriggerEventUnitId, "lastUnitTriggerEventUnit");
|
||||||
|
luaScript.registerFunction(getLastUnitTriggerEventType, "lastUnitTriggerEventType");
|
||||||
|
luaScript.registerFunction(getUnitProperty, "getUnitProperty");
|
||||||
|
luaScript.registerFunction(getUnitPropertyName, "getUnitPropertyName");
|
||||||
|
|
||||||
//load code
|
//load code
|
||||||
for(int i= 0; i<scenario->getScriptCount(); ++i){
|
for(int i= 0; i<scenario->getScriptCount(); ++i){
|
||||||
const Script* script= scenario->getScript(i);
|
const Script* script= scenario->getScript(i);
|
||||||
|
@ -1792,6 +1802,106 @@ bool ScriptManager::getAttackWarningsEnabled() {
|
||||||
return world->getAttackWarningsEnabled();
|
return world->getAttackWarningsEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptManager::registerUnitTriggerEvent(int unitId) {
|
||||||
|
UnitTriggerEventList[unitId]=utet_None;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptManager::unregisterUnitTriggerEvent(int unitId) {
|
||||||
|
UnitTriggerEventList.erase(unitId);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScriptManager::getLastUnitTriggerEventUnitId() {
|
||||||
|
return lastUnitTriggerEventUnitId;
|
||||||
|
}
|
||||||
|
UnitTriggerEventType ScriptManager::getLastUnitTriggerEventType() {
|
||||||
|
return lastUnitTriggerEventType;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScriptManager::getUnitProperty(int unitId, UnitTriggerEventType type) {
|
||||||
|
int result = -1;
|
||||||
|
Unit *unit= world->findUnitById(unitId);
|
||||||
|
if(unit != NULL) {
|
||||||
|
switch(type) {
|
||||||
|
case utet_None:
|
||||||
|
result = -2;
|
||||||
|
break;
|
||||||
|
case utet_HPChanged:
|
||||||
|
result = unit->getHp();
|
||||||
|
break;
|
||||||
|
case utet_EPChanged:
|
||||||
|
result = unit->getEp();
|
||||||
|
break;
|
||||||
|
case utet_LevelChanged:
|
||||||
|
result = -3;
|
||||||
|
if(unit->getLevel() != NULL) {
|
||||||
|
result = unit->getLevel()->getKills();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case utet_FieldChanged:
|
||||||
|
result = unit->getCurrField();
|
||||||
|
break;
|
||||||
|
case utet_SkillChanged:
|
||||||
|
result = -4;
|
||||||
|
if(unit->getCurrSkill() != NULL) {
|
||||||
|
result = unit->getCurrSkill()->getClass();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result = -1000;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
const string ScriptManager::getUnitPropertyName(int unitId, UnitTriggerEventType type) {
|
||||||
|
string result = "";
|
||||||
|
Unit *unit= world->findUnitById(unitId);
|
||||||
|
if(unit != NULL) {
|
||||||
|
switch(type) {
|
||||||
|
case utet_None:
|
||||||
|
result = "";
|
||||||
|
break;
|
||||||
|
case utet_HPChanged:
|
||||||
|
result = "";
|
||||||
|
break;
|
||||||
|
case utet_EPChanged:
|
||||||
|
result = "";
|
||||||
|
break;
|
||||||
|
case utet_LevelChanged:
|
||||||
|
result = "";
|
||||||
|
if(unit->getLevel() != NULL) {
|
||||||
|
result = unit->getLevel()->getName(false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case utet_FieldChanged:
|
||||||
|
result = "";
|
||||||
|
break;
|
||||||
|
case utet_SkillChanged:
|
||||||
|
result = "";
|
||||||
|
if(unit->getCurrSkill() != NULL) {
|
||||||
|
result = unit->getCurrSkill()->getName();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result = "???";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptManager::onUnitTriggerEvent(const Unit *unit, UnitTriggerEventType event) {
|
||||||
|
if(UnitTriggerEventList.empty() == false) {
|
||||||
|
std::map<int,UnitTriggerEventType>::iterator iterFind = UnitTriggerEventList.find(unit->getId());
|
||||||
|
if(iterFind != UnitTriggerEventList.end()) {
|
||||||
|
lastUnitTriggerEventUnitId = unit->getId();
|
||||||
|
lastUnitTriggerEventType = event;
|
||||||
|
|
||||||
|
luaScript.beginCall("unitTriggerEvent");
|
||||||
|
luaScript.endCall();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptManager::registerDayNightEvent() {
|
void ScriptManager::registerDayNightEvent() {
|
||||||
registeredDayNightEvent = true;
|
registeredDayNightEvent = true;
|
||||||
|
@ -2917,6 +3027,41 @@ int ScriptManager::unregisterDayNightEvent(LuaHandle* luaHandle) {
|
||||||
return luaArguments.getReturnCount();
|
return luaArguments.getReturnCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ScriptManager::registerUnitTriggerEvent(LuaHandle* luaHandle) {
|
||||||
|
LuaArguments luaArguments(luaHandle);
|
||||||
|
thisScriptManager->registerUnitTriggerEvent(luaArguments.getInt(-1));
|
||||||
|
return luaArguments.getReturnCount();
|
||||||
|
}
|
||||||
|
int ScriptManager::unregisterUnitTriggerEvent(LuaHandle* luaHandle) {
|
||||||
|
LuaArguments luaArguments(luaHandle);
|
||||||
|
thisScriptManager->unregisterUnitTriggerEvent(luaArguments.getInt(-1));
|
||||||
|
return luaArguments.getReturnCount();
|
||||||
|
}
|
||||||
|
int ScriptManager::getLastUnitTriggerEventUnitId(LuaHandle* luaHandle) {
|
||||||
|
LuaArguments luaArguments(luaHandle);
|
||||||
|
luaArguments.returnInt(thisScriptManager->getLastUnitTriggerEventUnitId());
|
||||||
|
return luaArguments.getReturnCount();
|
||||||
|
}
|
||||||
|
int ScriptManager::getLastUnitTriggerEventType(LuaHandle* luaHandle) {
|
||||||
|
LuaArguments luaArguments(luaHandle);
|
||||||
|
luaArguments.returnInt(thisScriptManager->getLastUnitTriggerEventType());
|
||||||
|
return luaArguments.getReturnCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScriptManager::getUnitProperty(LuaHandle* luaHandle) {
|
||||||
|
LuaArguments luaArguments(luaHandle);
|
||||||
|
int value = thisScriptManager->getUnitProperty(luaArguments.getInt(-2),static_cast<UnitTriggerEventType>(luaArguments.getInt(-1)));
|
||||||
|
luaArguments.returnInt(value);
|
||||||
|
return luaArguments.getReturnCount();
|
||||||
|
}
|
||||||
|
int ScriptManager::getUnitPropertyName(LuaHandle* luaHandle) {
|
||||||
|
LuaArguments luaArguments(luaHandle);
|
||||||
|
const string unitname = thisScriptManager->getUnitPropertyName(luaArguments.getInt(-2),static_cast<UnitTriggerEventType>(luaArguments.getInt(-1)));
|
||||||
|
luaArguments.returnString(unitname);
|
||||||
|
return luaArguments.getReturnCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptManager::saveGame(XmlNode *rootNode) {
|
void ScriptManager::saveGame(XmlNode *rootNode) {
|
||||||
std::map<string,string> mapTagReplacements;
|
std::map<string,string> mapTagReplacements;
|
||||||
XmlNode *scriptManagerNode = rootNode->addChild("ScriptManager");
|
XmlNode *scriptManagerNode = rootNode->addChild("ScriptManager");
|
||||||
|
@ -3022,6 +3167,16 @@ void ScriptManager::saveGame(XmlNode *rootNode) {
|
||||||
scriptManagerNode->addAttribute("registeredDayNightEvent",intToStr(registeredDayNightEvent), mapTagReplacements);
|
scriptManagerNode->addAttribute("registeredDayNightEvent",intToStr(registeredDayNightEvent), mapTagReplacements);
|
||||||
scriptManagerNode->addAttribute("lastDayNightTriggerStatus",intToStr(lastDayNightTriggerStatus), mapTagReplacements);
|
scriptManagerNode->addAttribute("lastDayNightTriggerStatus",intToStr(lastDayNightTriggerStatus), mapTagReplacements);
|
||||||
|
|
||||||
|
for(std::map<int,UnitTriggerEventType>::iterator iterMap = UnitTriggerEventList.begin();
|
||||||
|
iterMap != UnitTriggerEventList.end(); ++iterMap) {
|
||||||
|
XmlNode *unitTriggerEventListNode = scriptManagerNode->addChild("UnitTriggerEventList");
|
||||||
|
|
||||||
|
unitTriggerEventListNode->addAttribute("unitId",intToStr(iterMap->first), mapTagReplacements);
|
||||||
|
unitTriggerEventListNode->addAttribute("evenType",intToStr(iterMap->second), mapTagReplacements);
|
||||||
|
}
|
||||||
|
scriptManagerNode->addAttribute("lastUnitTriggerEventUnitId",intToStr(lastUnitTriggerEventUnitId), mapTagReplacements);
|
||||||
|
scriptManagerNode->addAttribute("lastUnitTriggerEventType",intToStr(lastUnitTriggerEventType), mapTagReplacements);
|
||||||
|
|
||||||
luaScript.saveGame(scriptManagerNode);
|
luaScript.saveGame(scriptManagerNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3139,6 +3294,21 @@ void ScriptManager::loadGame(const XmlNode *rootNode) {
|
||||||
lastDayNightTriggerStatus = scriptManagerNode->getAttribute("lastDayNightTriggerStatus")->getIntValue();
|
lastDayNightTriggerStatus = scriptManagerNode->getAttribute("lastDayNightTriggerStatus")->getIntValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<XmlNode *> unitTriggerEventListNodeList = scriptManagerNode->getChildList("UnitTriggerEventList");
|
||||||
|
for(unsigned int i = 0; i < unitTriggerEventListNodeList.size(); ++i) {
|
||||||
|
XmlNode *node = unitTriggerEventListNodeList[i];
|
||||||
|
|
||||||
|
int unitId = node->getAttribute("unitId")->getIntValue();
|
||||||
|
UnitTriggerEventType evenType = static_cast<UnitTriggerEventType>(node->getAttribute("eventType")->getIntValue());
|
||||||
|
UnitTriggerEventList[unitId] = evenType;
|
||||||
|
}
|
||||||
|
if(scriptManagerNode->hasAttribute("lastUnitTriggerEventUnitId") == true) {
|
||||||
|
lastUnitTriggerEventUnitId = scriptManagerNode->getAttribute("lastUnitTriggerEventUnitId")->getIntValue();
|
||||||
|
}
|
||||||
|
if(scriptManagerNode->hasAttribute("lastUnitTriggerEventType") == true) {
|
||||||
|
lastUnitTriggerEventType = static_cast<UnitTriggerEventType>(scriptManagerNode->getAttribute("lastUnitTriggerEventType")->getIntValue());
|
||||||
|
}
|
||||||
|
|
||||||
luaScript.loadGame(scriptManagerNode);
|
luaScript.loadGame(scriptManagerNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,15 @@ private:
|
||||||
// class ScriptManager
|
// class ScriptManager
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
|
enum UnitTriggerEventType {
|
||||||
|
utet_None = 0,
|
||||||
|
utet_HPChanged = 1,
|
||||||
|
utet_EPChanged,
|
||||||
|
utet_LevelChanged,
|
||||||
|
utet_FieldChanged,
|
||||||
|
utet_SkillChanged
|
||||||
|
};
|
||||||
|
|
||||||
enum CellTriggerEventType {
|
enum CellTriggerEventType {
|
||||||
ctet_Unit,
|
ctet_Unit,
|
||||||
ctet_UnitPos,
|
ctet_UnitPos,
|
||||||
|
@ -200,6 +209,10 @@ private:
|
||||||
bool registeredDayNightEvent;
|
bool registeredDayNightEvent;
|
||||||
int lastDayNightTriggerStatus;
|
int lastDayNightTriggerStatus;
|
||||||
|
|
||||||
|
std::map<int,UnitTriggerEventType> UnitTriggerEventList;
|
||||||
|
int lastUnitTriggerEventUnitId;
|
||||||
|
UnitTriggerEventType lastUnitTriggerEventType;
|
||||||
|
|
||||||
RandomGen random;
|
RandomGen random;
|
||||||
const XmlNode *rootNode;
|
const XmlNode *rootNode;
|
||||||
|
|
||||||
|
@ -234,6 +247,7 @@ public:
|
||||||
void onCellTriggerEvent(Unit *movingUnit);
|
void onCellTriggerEvent(Unit *movingUnit);
|
||||||
void onTimerTriggerEvent();
|
void onTimerTriggerEvent();
|
||||||
void onDayNightTriggerEvent();
|
void onDayNightTriggerEvent();
|
||||||
|
void onUnitTriggerEvent(const Unit *unit, UnitTriggerEventType event);
|
||||||
|
|
||||||
bool getGameWon() const;
|
bool getGameWon() const;
|
||||||
bool getIsGameOver() const;
|
bool getIsGameOver() const;
|
||||||
|
@ -391,6 +405,13 @@ private:
|
||||||
void registerDayNightEvent();
|
void registerDayNightEvent();
|
||||||
void unregisterDayNightEvent();
|
void unregisterDayNightEvent();
|
||||||
|
|
||||||
|
void registerUnitTriggerEvent(int unitId);
|
||||||
|
void unregisterUnitTriggerEvent(int unitId);
|
||||||
|
int getLastUnitTriggerEventUnitId();
|
||||||
|
UnitTriggerEventType getLastUnitTriggerEventType();
|
||||||
|
int getUnitProperty(int unitId, UnitTriggerEventType type);
|
||||||
|
const string getUnitPropertyName(int unitId, UnitTriggerEventType type);
|
||||||
|
|
||||||
//callbacks, commands
|
//callbacks, commands
|
||||||
static int networkShowMessageForFaction(LuaHandle* luaHandle);
|
static int networkShowMessageForFaction(LuaHandle* luaHandle);
|
||||||
static int networkShowMessageForTeam(LuaHandle* luaHandle);
|
static int networkShowMessageForTeam(LuaHandle* luaHandle);
|
||||||
|
@ -544,6 +565,13 @@ private:
|
||||||
static int registerDayNightEvent(LuaHandle* luaHandle);
|
static int registerDayNightEvent(LuaHandle* luaHandle);
|
||||||
static int unregisterDayNightEvent(LuaHandle* luaHandle);
|
static int unregisterDayNightEvent(LuaHandle* luaHandle);
|
||||||
|
|
||||||
|
static int registerUnitTriggerEvent(LuaHandle* luaHandle);
|
||||||
|
static int unregisterUnitTriggerEvent(LuaHandle* luaHandle);
|
||||||
|
static int getLastUnitTriggerEventUnitId(LuaHandle* luaHandle);
|
||||||
|
static int getLastUnitTriggerEventType(LuaHandle* luaHandle);
|
||||||
|
static int getUnitProperty(LuaHandle* luaHandle);
|
||||||
|
static int getUnitPropertyName(LuaHandle* luaHandle);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -633,6 +633,15 @@ void Unit::setModelFacing(CardinalDir value) {
|
||||||
lastRotation = targetRotation = rotation = value * 90.f;
|
lastRotation = targetRotation = rotation = value * 90.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Unit::setCurrField(Field currField) {
|
||||||
|
Field original_field = this->currField;
|
||||||
|
|
||||||
|
this->currField = currField;
|
||||||
|
|
||||||
|
if(original_field != this->currField) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_FieldChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
// ====================================== get ======================================
|
// ====================================== get ======================================
|
||||||
|
|
||||||
Vec2i Unit::getCenteredPos() const {
|
Vec2i Unit::getCenteredPos() const {
|
||||||
|
@ -824,10 +833,10 @@ const Level *Unit::getNextLevel() const{
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(level==NULL && type->getLevelCount()>0){
|
if(level == NULL && type->getLevelCount() > 0) {
|
||||||
return type->getLevel(0);
|
return type->getLevel(0);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
for(int i=1; i<type->getLevelCount(); ++i){
|
for(int i=1; i<type->getLevelCount(); ++i){
|
||||||
if(type->getLevel(i-1)==level){
|
if(type->getLevel(i-1)==level){
|
||||||
return type->getLevel(i);
|
return type->getLevel(i);
|
||||||
|
@ -1073,7 +1082,12 @@ void Unit::setCurrSkill(const SkillType *currSkill) {
|
||||||
this->lastModelIndexForCurrSkillType = -1;
|
this->lastModelIndexForCurrSkillType = -1;
|
||||||
this->animationRandomCycleCount = 0;
|
this->animationRandomCycleCount = 0;
|
||||||
}
|
}
|
||||||
|
const SkillType *original_skill = this->currSkill;
|
||||||
this->currSkill= currSkill;
|
this->currSkill= currSkill;
|
||||||
|
|
||||||
|
if(original_skill != this->currSkill) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_SkillChanged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::setCurrSkill(SkillClass sc) {
|
void Unit::setCurrSkill(SkillClass sc) {
|
||||||
|
@ -1651,7 +1665,11 @@ void Unit::born(const CommandType *ct) {
|
||||||
setCurrSkill(scStop);
|
setCurrSkill(scStop);
|
||||||
|
|
||||||
checkItemInVault(&this->hp,this->hp);
|
checkItemInVault(&this->hp,this->hp);
|
||||||
hp= type->getMaxHp();
|
int original_hp = this->hp;
|
||||||
|
this->hp= type->getMaxHp();
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
|
}
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2353,7 +2371,11 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) {
|
||||||
|
|
||||||
checkItemInVault(&this->hp,this->hp);
|
checkItemInVault(&this->hp,this->hp);
|
||||||
//hp += boost->boostUpgrade.getMaxHp();
|
//hp += boost->boostUpgrade.getMaxHp();
|
||||||
hp += (totalUpgrade.getMaxHp() - prevMaxHp);
|
int original_hp = this->hp;
|
||||||
|
this->hp += (totalUpgrade.getMaxHp() - prevMaxHp);
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
|
}
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
//regenerate hp upgrade / or boost
|
//regenerate hp upgrade / or boost
|
||||||
|
@ -2361,8 +2383,11 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) {
|
||||||
checkItemInVault(&this->hp,this->hp);
|
checkItemInVault(&this->hp,this->hp);
|
||||||
|
|
||||||
//printf("BEFORE Apply Hp Regen max = %d, prev = %d, hp = %d\n",totalUpgrade.getMaxHpRegeneration(),prevMaxHpRegen,hp);
|
//printf("BEFORE Apply Hp Regen max = %d, prev = %d, hp = %d\n",totalUpgrade.getMaxHpRegeneration(),prevMaxHpRegen,hp);
|
||||||
|
int original_hp = this->hp;
|
||||||
hp += (totalUpgrade.getMaxHpRegeneration() - prevMaxHpRegen);
|
this->hp += (totalUpgrade.getMaxHpRegeneration() - prevMaxHpRegen);
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
|
}
|
||||||
//if(hp > type->getTotalMaxHp(&totalUpgrade)) {
|
//if(hp > type->getTotalMaxHp(&totalUpgrade)) {
|
||||||
// hp = type->getTotalMaxHp(&totalUpgrade);
|
// hp = type->getTotalMaxHp(&totalUpgrade);
|
||||||
//}
|
//}
|
||||||
|
@ -2398,14 +2423,15 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) {
|
||||||
if(wasAlive == true) {
|
if(wasAlive == true) {
|
||||||
//startDamageParticles
|
//startDamageParticles
|
||||||
|
|
||||||
if(originalHp > hp) {
|
if(originalHp > this->hp) {
|
||||||
startDamageParticles();
|
startDamageParticles();
|
||||||
}
|
}
|
||||||
|
|
||||||
//stop DamageParticles on death
|
//stop DamageParticles on death
|
||||||
if(hp <= 0) {
|
if(this->hp <= 0) {
|
||||||
alive= false;
|
this->alive= false;
|
||||||
hp=0;
|
this->hp=0;
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
checkModelStateInfoForNewHpValue();
|
checkModelStateInfoForNewHpValue();
|
||||||
|
|
||||||
|
@ -2450,8 +2476,12 @@ void Unit::deapplyAttackBoost(const AttackBoost *boost, const Unit *source) {
|
||||||
totalUpgrade.deapply(&boost->boostUpgrade, this);
|
totalUpgrade.deapply(&boost->boostUpgrade, this);
|
||||||
|
|
||||||
checkItemInVault(&this->hp,this->hp);
|
checkItemInVault(&this->hp,this->hp);
|
||||||
|
int original_hp = this->hp;
|
||||||
//hp -= boost->boostUpgrade.getMaxHp();
|
//hp -= boost->boostUpgrade.getMaxHp();
|
||||||
hp -= (prevMaxHp - totalUpgrade.getMaxHp());
|
this->hp -= (prevMaxHp - totalUpgrade.getMaxHp());
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
|
}
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
//regenerate hp upgrade / or boost
|
//regenerate hp upgrade / or boost
|
||||||
|
@ -2459,8 +2489,11 @@ void Unit::deapplyAttackBoost(const AttackBoost *boost, const Unit *source) {
|
||||||
checkItemInVault(&this->hp,this->hp);
|
checkItemInVault(&this->hp,this->hp);
|
||||||
|
|
||||||
//printf("BEFORE DeApply Hp Regen max = %d, prev = %d, hp = %d\n",totalUpgrade.getMaxHpRegeneration(),prevMaxHpRegen,hp);
|
//printf("BEFORE DeApply Hp Regen max = %d, prev = %d, hp = %d\n",totalUpgrade.getMaxHpRegeneration(),prevMaxHpRegen,hp);
|
||||||
|
int original_hp = this->hp;
|
||||||
hp -= (totalUpgrade.getMaxHpRegeneration() - prevMaxHpRegen);
|
this->hp -= (totalUpgrade.getMaxHpRegeneration() - prevMaxHpRegen);
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
|
}
|
||||||
//if(hp > totalUpgrade.getMaxHp()) {
|
//if(hp > totalUpgrade.getMaxHp()) {
|
||||||
// hp = totalUpgrade.getMaxHp();
|
// hp = totalUpgrade.getMaxHp();
|
||||||
//}
|
//}
|
||||||
|
@ -2477,14 +2510,15 @@ void Unit::deapplyAttackBoost(const AttackBoost *boost, const Unit *source) {
|
||||||
//printf("DE-APPLYING ATTACK BOOST wasalive = true to unit [%s - %d] from unit [%s - %d]\n",this->getType()->getName().c_str(),this->getId(),source->getType()->getName().c_str(),source->getId());
|
//printf("DE-APPLYING ATTACK BOOST wasalive = true to unit [%s - %d] from unit [%s - %d]\n",this->getType()->getName().c_str(),this->getId(),source->getType()->getName().c_str(),source->getId());
|
||||||
|
|
||||||
//startDamageParticles
|
//startDamageParticles
|
||||||
if(originalHp > hp) {
|
if(originalHp > this->hp) {
|
||||||
startDamageParticles();
|
startDamageParticles();
|
||||||
}
|
}
|
||||||
|
|
||||||
//stop DamageParticles on death
|
//stop DamageParticles on death
|
||||||
if(hp <= 0) {
|
if(this->hp <= 0) {
|
||||||
alive= false;
|
this->alive= false;
|
||||||
hp=0;
|
this->hp=0;
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
checkModelStateInfoForNewHpValue();
|
checkModelStateInfoForNewHpValue();
|
||||||
|
@ -2543,9 +2577,13 @@ void Unit::tick() {
|
||||||
if( currSkill->getClass() != scBeBuilt){
|
if( currSkill->getClass() != scBeBuilt){
|
||||||
if(type->getTotalMaxHpRegeneration(&totalUpgrade) >= 0) {
|
if(type->getTotalMaxHpRegeneration(&totalUpgrade) >= 0) {
|
||||||
checkItemInVault(&this->hp,this->hp);
|
checkItemInVault(&this->hp,this->hp);
|
||||||
hp += type->getTotalMaxHpRegeneration(&totalUpgrade);
|
int original_hp = this->hp;
|
||||||
if(hp > type->getTotalMaxHp(&totalUpgrade)) {
|
this->hp += type->getTotalMaxHpRegeneration(&totalUpgrade);
|
||||||
hp = type->getTotalMaxHp(&totalUpgrade);
|
if(this->hp > type->getTotalMaxHp(&totalUpgrade)) {
|
||||||
|
this->hp = type->getTotalMaxHp(&totalUpgrade);
|
||||||
|
}
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
}
|
}
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
|
@ -2575,10 +2613,13 @@ void Unit::tick() {
|
||||||
if(type->getHpRegeneration() >= 0) {
|
if(type->getHpRegeneration() >= 0) {
|
||||||
if( currSkill->getClass() != scBeBuilt){
|
if( currSkill->getClass() != scBeBuilt){
|
||||||
checkItemInVault(&this->hp,this->hp);
|
checkItemInVault(&this->hp,this->hp);
|
||||||
|
int original_hp = this->hp;
|
||||||
hp += type->getHpRegeneration();
|
this->hp += type->getHpRegeneration();
|
||||||
if(hp > type->getTotalMaxHp(&totalUpgrade)) {
|
if(this->hp > type->getTotalMaxHp(&totalUpgrade)) {
|
||||||
hp = type->getTotalMaxHp(&totalUpgrade);
|
this->hp = type->getTotalMaxHp(&totalUpgrade);
|
||||||
|
}
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
}
|
}
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
|
@ -2618,9 +2659,13 @@ void Unit::tick() {
|
||||||
//regenerate ep upgrade / or boost
|
//regenerate ep upgrade / or boost
|
||||||
checkItemInVault(&this->ep,this->ep);
|
checkItemInVault(&this->ep,this->ep);
|
||||||
//regenerate ep
|
//regenerate ep
|
||||||
ep += type->getTotalMaxEpRegeneration(&totalUpgrade);
|
int original_ep = this->ep;
|
||||||
if(ep > type->getTotalMaxEp(&totalUpgrade)){
|
this->ep += type->getTotalMaxEpRegeneration(&totalUpgrade);
|
||||||
ep = type->getTotalMaxEp(&totalUpgrade);
|
if(this->ep > type->getTotalMaxEp(&totalUpgrade)){
|
||||||
|
this->ep = type->getTotalMaxEp(&totalUpgrade);
|
||||||
|
}
|
||||||
|
if(original_ep != this->ep) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_EPChanged);
|
||||||
}
|
}
|
||||||
addItemToVault(&this->ep,this->ep);
|
addItemToVault(&this->ep,this->ep);
|
||||||
|
|
||||||
|
@ -2641,13 +2686,17 @@ bool Unit::computeEp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//if not enough ep
|
//if not enough ep
|
||||||
if(ep - currSkill->getEpCost() < 0) {
|
if(this->ep - currSkill->getEpCost() < 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkItemInVault(&this->ep,this->ep);
|
checkItemInVault(&this->ep,this->ep);
|
||||||
|
int original_ep = this->ep;
|
||||||
//decrease ep
|
//decrease ep
|
||||||
ep -= currSkill->getEpCost();
|
this->ep -= currSkill->getEpCost();
|
||||||
|
if(original_ep != this->ep) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_EPChanged);
|
||||||
|
}
|
||||||
addItemToVault(&this->ep,this->ep);
|
addItemToVault(&this->ep,this->ep);
|
||||||
|
|
||||||
if(getType() == NULL) {
|
if(getType() == NULL) {
|
||||||
|
@ -2656,8 +2705,12 @@ bool Unit::computeEp() {
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ep > getType()->getTotalMaxEp(&totalUpgrade)){
|
if(this->ep > getType()->getTotalMaxEp(&totalUpgrade)){
|
||||||
ep = getType()->getTotalMaxEp(&totalUpgrade);
|
int original_ep = this->ep;
|
||||||
|
this->ep = getType()->getTotalMaxEp(&totalUpgrade);
|
||||||
|
if(original_ep != this->ep) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_EPChanged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
addItemToVault(&this->ep,this->ep);
|
addItemToVault(&this->ep,this->ep);
|
||||||
|
|
||||||
|
@ -2674,12 +2727,19 @@ bool Unit::repair(){
|
||||||
|
|
||||||
//increase hp
|
//increase hp
|
||||||
checkItemInVault(&this->hp,this->hp);
|
checkItemInVault(&this->hp,this->hp);
|
||||||
hp += getType()->getMaxHp()/type->getProductionTime() + 1;
|
int original_hp = this->hp;
|
||||||
if(hp > (getType()->getTotalMaxHp(&totalUpgrade))) {
|
this->hp += getType()->getMaxHp()/type->getProductionTime() + 1;
|
||||||
hp = getType()->getTotalMaxHp(&totalUpgrade);
|
if(this->hp > (getType()->getTotalMaxHp(&totalUpgrade))) {
|
||||||
|
this->hp = getType()->getTotalMaxHp(&totalUpgrade);
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
|
}
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
|
}
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
checkModelStateInfoForNewHpValue();
|
checkModelStateInfoForNewHpValue();
|
||||||
|
@ -2692,12 +2752,16 @@ bool Unit::repair(){
|
||||||
|
|
||||||
//decrements HP and returns if dead
|
//decrements HP and returns if dead
|
||||||
bool Unit::decHp(int i) {
|
bool Unit::decHp(int i) {
|
||||||
if(hp == 0) {
|
if(this->hp == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkItemInVault(&this->hp,this->hp);
|
checkItemInVault(&this->hp,this->hp);
|
||||||
hp -= i;
|
int original_hp = this->hp;
|
||||||
|
this->hp -= i;
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
|
}
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
checkModelStateInfoForNewHpValue();
|
checkModelStateInfoForNewHpValue();
|
||||||
|
@ -2712,9 +2776,10 @@ bool Unit::decHp(int i) {
|
||||||
startDamageParticles();
|
startDamageParticles();
|
||||||
|
|
||||||
//stop DamageParticles on death
|
//stop DamageParticles on death
|
||||||
if(hp <= 0) {
|
if(this->hp <= 0) {
|
||||||
alive= false;
|
this->alive = false;
|
||||||
hp=0;
|
this->hp = 0;
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
checkModelStateInfoForNewHpValue();
|
checkModelStateInfoForNewHpValue();
|
||||||
|
@ -2852,8 +2917,12 @@ void Unit::applyUpgrade(const UpgradeType *upgradeType){
|
||||||
totalUpgrade.sum(upgradeType, this);
|
totalUpgrade.sum(upgradeType, this);
|
||||||
|
|
||||||
checkItemInVault(&this->hp,this->hp);
|
checkItemInVault(&this->hp,this->hp);
|
||||||
hp += upgradeType->getMaxHp();
|
int original_hp = this->hp;
|
||||||
hp = max(0,hp);
|
this->hp += upgradeType->getMaxHp();
|
||||||
|
this->hp = max(0,this->hp);
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
|
}
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
checkModelStateInfoForNewHpValue();
|
checkModelStateInfoForNewHpValue();
|
||||||
|
@ -2875,13 +2944,19 @@ void Unit::incKills(int team) {
|
||||||
|
|
||||||
void Unit::checkUnitLevel() {
|
void Unit::checkUnitLevel() {
|
||||||
const Level *nextLevel= getNextLevel();
|
const Level *nextLevel= getNextLevel();
|
||||||
if(nextLevel != NULL && enemyKills >= nextLevel->getKills()) {
|
if(nextLevel != NULL && this->enemyKills >= nextLevel->getKills()) {
|
||||||
level= nextLevel;
|
this->level= nextLevel;
|
||||||
int maxHp= totalUpgrade.getMaxHp();
|
|
||||||
|
int maxHp= this->totalUpgrade.getMaxHp();
|
||||||
totalUpgrade.incLevel(type);
|
totalUpgrade.incLevel(type);
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_LevelChanged);
|
||||||
|
|
||||||
checkItemInVault(&this->hp,this->hp);
|
checkItemInVault(&this->hp,this->hp);
|
||||||
hp += totalUpgrade.getMaxHp() - maxHp;
|
int original_hp = this->hp;
|
||||||
|
this->hp += totalUpgrade.getMaxHp() - maxHp;
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
|
}
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
checkModelStateInfoForNewHpValue();
|
checkModelStateInfoForNewHpValue();
|
||||||
|
@ -2948,23 +3023,33 @@ bool Unit::morph(const MorphCommandType *mct) {
|
||||||
|
|
||||||
|
|
||||||
checkItemInVault(&this->hp,this->hp);
|
checkItemInVault(&this->hp,this->hp);
|
||||||
hp += morphUnitType->getMaxHp() - type->getMaxHp();
|
int original_hp = this->hp;
|
||||||
|
this->hp += morphUnitType->getMaxHp() - type->getMaxHp();
|
||||||
|
if(original_hp != this->hp) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
|
||||||
|
}
|
||||||
addItemToVault(&this->hp,this->hp);
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
checkModelStateInfoForNewHpValue();
|
checkModelStateInfoForNewHpValue();
|
||||||
|
|
||||||
preMorph_type = type;
|
this->preMorph_type = this->type;
|
||||||
type= morphUnitType;
|
this->type= morphUnitType;
|
||||||
currField=morphUnitField;
|
Field original_field = this->currField;
|
||||||
|
this->currField=morphUnitField;
|
||||||
computeTotalUpgrade();
|
computeTotalUpgrade();
|
||||||
map->putUnitCells(this, pos);
|
map->putUnitCells(this, this->pos);
|
||||||
faction->applyDiscount(morphUnitType, mct->getDiscount());
|
this->faction->applyDiscount(morphUnitType, mct->getDiscount());
|
||||||
faction->addStore(type);
|
this->faction->addStore(this->type);
|
||||||
faction->applyStaticProduction(morphUnitType,mct);
|
this->faction->applyStaticProduction(morphUnitType,mct);
|
||||||
|
|
||||||
level= NULL;
|
this->level= NULL;
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_LevelChanged);
|
||||||
checkUnitLevel();
|
checkUnitLevel();
|
||||||
|
|
||||||
|
if(original_field != this->currField) {
|
||||||
|
game->getScriptManager()->onUnitTriggerEvent(this,utet_FieldChanged);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
|
@ -582,7 +582,7 @@ public:
|
||||||
bool isInteresting(InterestingUnitType iut) const;
|
bool isInteresting(InterestingUnitType iut) const;
|
||||||
|
|
||||||
//set
|
//set
|
||||||
inline void setCurrField(Field currField) {this->currField= currField;}
|
void setCurrField(Field currField);
|
||||||
void setCurrSkill(const SkillType *currSkill);
|
void setCurrSkill(const SkillType *currSkill);
|
||||||
void setCurrSkill(SkillClass sc);
|
void setCurrSkill(SkillClass sc);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user