renamed/fixed lua function enableHunger to enableConsume and disableAI now disables consume too ( to stay somehow compatible with the former behaviour )
This commit is contained in:
parent
1a9ec91eeb
commit
8552f76798
|
@ -50,7 +50,7 @@ public:
|
|||
PlayerModifiers::PlayerModifiers(){
|
||||
winner = false;
|
||||
aiEnabled = true;
|
||||
hungerEnabled = true;
|
||||
consumeEnabled = true;
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
|
@ -88,9 +88,9 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
|
|||
luaScript.registerFunction(disableAi, "disableAi");
|
||||
luaScript.registerFunction(enableAi, "enableAi");
|
||||
luaScript.registerFunction(getAiEnabled, "getAiEnabled");
|
||||
luaScript.registerFunction(disableHunger, "disableHunger");
|
||||
luaScript.registerFunction(enableHunger, "enableHunger");
|
||||
luaScript.registerFunction(getHungerEnabled, "getHungerEnabled");
|
||||
luaScript.registerFunction(disableConsume, "disableConsume");
|
||||
luaScript.registerFunction(enableConsume, "enableConsume");
|
||||
luaScript.registerFunction(getConsumeEnabled, "getConsumeEnabled");
|
||||
luaScript.registerFunction(setPlayerAsWinner, "setPlayerAsWinner");
|
||||
luaScript.registerFunction(endGame, "endGame");
|
||||
|
||||
|
@ -420,6 +420,7 @@ void ScriptManager::disableAi(int factionIndex){
|
|||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
if(factionIndex<GameConstants::maxPlayers){
|
||||
playerModifiers[factionIndex].disableAi();
|
||||
disableConsume(factionIndex); // by this we stay somehow compatible with old behaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -437,24 +438,24 @@ bool ScriptManager::getAiEnabled(int factionIndex){
|
|||
}
|
||||
}
|
||||
|
||||
void ScriptManager::disableHunger(int factionIndex){
|
||||
void ScriptManager::disableConsume(int factionIndex){
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
if(factionIndex<GameConstants::maxPlayers){
|
||||
playerModifiers[factionIndex].disableHunger();
|
||||
playerModifiers[factionIndex].disableConsume();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptManager::enableHunger(int factionIndex){
|
||||
void ScriptManager::enableConsume(int factionIndex){
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
if(factionIndex<GameConstants::maxPlayers){
|
||||
playerModifiers[factionIndex].enableHunger();
|
||||
playerModifiers[factionIndex].enableConsume();
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptManager::getHungerEnabled(int factionIndex){
|
||||
bool ScriptManager::getConsumeEnabled(int factionIndex){
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
if(factionIndex<GameConstants::maxPlayers){
|
||||
return playerModifiers[factionIndex].getHungerEnabled();
|
||||
return playerModifiers[factionIndex].getConsumeEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -804,21 +805,21 @@ int ScriptManager::getAiEnabled(LuaHandle* luaHandle){
|
|||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::disableHunger(LuaHandle* luaHandle){
|
||||
int ScriptManager::disableConsume(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
thisScriptManager->disableHunger(luaArguments.getInt(-1));
|
||||
thisScriptManager->disableConsume(luaArguments.getInt(-1));
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::enableHunger(LuaHandle* luaHandle){
|
||||
int ScriptManager::enableConsume(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
thisScriptManager->enableHunger(luaArguments.getInt(-1));
|
||||
thisScriptManager->enableConsume(luaArguments.getInt(-1));
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::getHungerEnabled(LuaHandle* luaHandle){
|
||||
int ScriptManager::getConsumeEnabled(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
bool result = thisScriptManager->getHungerEnabled(luaArguments.getInt(-1));
|
||||
bool result = thisScriptManager->getConsumeEnabled(luaArguments.getInt(-1));
|
||||
luaArguments.returnInt(result);
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
|
|
@ -57,18 +57,18 @@ public:
|
|||
|
||||
void setAsWinner() {winner= true;}
|
||||
|
||||
void disableHunger() {hungerEnabled= false;}
|
||||
void enableHunger() {hungerEnabled= true;}
|
||||
void disableConsume() {consumeEnabled= false;}
|
||||
void enableConsume() {consumeEnabled= true;}
|
||||
|
||||
bool getWinner() const {return winner;}
|
||||
|
||||
bool getAiEnabled() const {return aiEnabled;}
|
||||
bool getHungerEnabled() const {return hungerEnabled;}
|
||||
bool getConsumeEnabled() const {return consumeEnabled;}
|
||||
|
||||
private:
|
||||
bool winner;
|
||||
bool aiEnabled;
|
||||
bool hungerEnabled;
|
||||
bool consumeEnabled;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
@ -183,8 +183,8 @@ private:
|
|||
void giveUpgradeCommand(int unitId, const string &upgradeName);
|
||||
void disableAi(int factionIndex);
|
||||
void enableAi(int factionIndex);
|
||||
void disableHunger(int factionIndex);
|
||||
void enableHunger(int factionIndex);
|
||||
void disableConsume(int factionIndex);
|
||||
void enableConsume(int factionIndex);
|
||||
|
||||
int registerCellTriggerEventForUnitToUnit(int sourceUnitId, int destUnitId);
|
||||
int registerCellTriggerEventForUnitToLocation(int sourceUnitId, const Vec2i &pos);
|
||||
|
@ -200,7 +200,7 @@ private:
|
|||
int getTimerTriggeredEventId();
|
||||
|
||||
bool getAiEnabled(int factionIndex);
|
||||
bool getHungerEnabled(int factionIndex);
|
||||
bool getConsumeEnabled(int factionIndex);
|
||||
|
||||
void setPlayerAsWinner(int factionIndex);
|
||||
void endGame();
|
||||
|
@ -239,11 +239,11 @@ private:
|
|||
static int disableAi(LuaHandle* luaHandle);
|
||||
static int enableAi(LuaHandle* luaHandle);
|
||||
|
||||
static int disableHunger(LuaHandle* luaHandle);
|
||||
static int enableHunger(LuaHandle* luaHandle);
|
||||
static int disableConsume(LuaHandle* luaHandle);
|
||||
static int enableConsume(LuaHandle* luaHandle);
|
||||
|
||||
static int getAiEnabled(LuaHandle* luaHandle);
|
||||
static int getHungerEnabled(LuaHandle* luaHandle);
|
||||
static int getConsumeEnabled(LuaHandle* luaHandle);
|
||||
|
||||
static int registerCellTriggerEventForUnitToUnit(LuaHandle* luaHandle);
|
||||
static int registerCellTriggerEventForUnitToLocation(LuaHandle* luaHandle);
|
||||
|
|
|
@ -363,34 +363,29 @@ void Faction::applyCostsOnInterval(){
|
|||
}
|
||||
|
||||
//decrement consumables
|
||||
if((getCpuControl() == false) ||
|
||||
(getCpuControl() == true &&
|
||||
scriptManager->getPlayerModifiers(this->index)->getAiEnabled() == true))
|
||||
{
|
||||
for(int j=0; j<getUnitCount(); ++j){
|
||||
Unit *unit= getUnit(j);
|
||||
assert(unit != NULL);
|
||||
if(unit->isOperative()){
|
||||
for(int k=0; k<unit->getType()->getCostCount(); ++k){
|
||||
const Resource *resource= unit->getType()->getCost(k);
|
||||
if(resource->getType()->getClass()==rcConsumable && resource->getAmount()>0){
|
||||
incResourceAmount(resource->getType(), -resource->getAmount());
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] hunger setting for faction index = %d, hunger = %d, getResource(resource->getType())->getAmount() = %d\n",__FILE__,__FUNCTION__,__LINE__,this->index,scriptManager->getPlayerModifiers(this->index)->getHungerEnabled(),getResource(resource->getType())->getAmount());
|
||||
for(int j=0; j<getUnitCount(); ++j){
|
||||
Unit *unit= getUnit(j);
|
||||
assert(unit != NULL);
|
||||
if(unit->isOperative()){
|
||||
for(int k=0; k<unit->getType()->getCostCount(); ++k){
|
||||
const Resource *resource= unit->getType()->getCost(k);
|
||||
if(resource->getType()->getClass()==rcConsumable && resource->getAmount()>0){
|
||||
incResourceAmount(resource->getType(), -resource->getAmount());
|
||||
|
||||
//decrease unit hp
|
||||
if(scriptManager->getPlayerModifiers(this->index)->getHungerEnabled() == true &&
|
||||
getResource(resource->getType())->getAmount() < 0) {
|
||||
resetResourceAmount(resource->getType());
|
||||
bool decHpResult=unit->decHp(unit->getType()->getMaxHp()/3);
|
||||
if(decHpResult){
|
||||
world->getStats()->die(unit->getFactionIndex());
|
||||
scriptManager->onUnitDied(unit);
|
||||
}
|
||||
StaticSound *sound= unit->getType()->getFirstStOfClass(scDie)->getSound();
|
||||
if(sound!=NULL && thisFaction){
|
||||
SoundRenderer::getInstance().playFx(sound);
|
||||
}
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] consume setting for faction index = %d, consume = %d, getResource(resource->getType())->getAmount() = %d\n",__FILE__,__FUNCTION__,__LINE__,this->index,scriptManager->getPlayerModifiers(this->index)->getConsumeEnabled(),getResource(resource->getType())->getAmount());
|
||||
|
||||
//decrease unit hp
|
||||
if(scriptManager->getPlayerModifiers(this->index)->getConsumeEnabled() == true &&
|
||||
getResource(resource->getType())->getAmount() < 0) {
|
||||
resetResourceAmount(resource->getType());
|
||||
bool decHpResult=unit->decHp(unit->getType()->getMaxHp()/3);
|
||||
if(decHpResult){
|
||||
world->getStats()->die(unit->getFactionIndex());
|
||||
scriptManager->onUnitDied(unit);
|
||||
}
|
||||
StaticSound *sound= unit->getType()->getFirstStOfClass(scDie)->getSound();
|
||||
if(sound!=NULL && thisFaction){
|
||||
SoundRenderer::getInstance().playFx(sound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue