- bugfix for AI not losing HP when food is out
- added new LUA commands (for Tiger): giveAttackCommand disableAi enableAi disableHunger enableHunger
This commit is contained in:
parent
4bc00cbf73
commit
dc5bf0f850
|
@ -47,8 +47,9 @@ public:
|
|||
// =====================================================
|
||||
|
||||
PlayerModifiers::PlayerModifiers(){
|
||||
winner= false;
|
||||
aiEnabled= true;
|
||||
winner = false;
|
||||
aiEnabled = true;
|
||||
hungerEnabled = true;
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
|
@ -76,8 +77,12 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
|
|||
luaScript.registerFunction(giveResource, "giveResource");
|
||||
luaScript.registerFunction(givePositionCommand, "givePositionCommand");
|
||||
luaScript.registerFunction(giveProductionCommand, "giveProductionCommand");
|
||||
luaScript.registerFunction(giveAttackCommand, "giveAttackCommand");
|
||||
luaScript.registerFunction(giveUpgradeCommand, "giveUpgradeCommand");
|
||||
luaScript.registerFunction(disableAi, "disableAi");
|
||||
luaScript.registerFunction(enableAi, "enableAi");
|
||||
luaScript.registerFunction(disableHunger, "disableHunger");
|
||||
luaScript.registerFunction(enableHunger, "enableHunger");
|
||||
luaScript.registerFunction(setPlayerAsWinner, "setPlayerAsWinner");
|
||||
luaScript.registerFunction(endGame, "endGame");
|
||||
|
||||
|
@ -211,6 +216,11 @@ void ScriptManager::givePositionCommand(int unitId, const string &commandName, c
|
|||
world->givePositionCommand(unitId, commandName, pos);
|
||||
}
|
||||
|
||||
void ScriptManager::giveAttackCommand(int unitId, int unitToAttackId) {
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
world->giveAttackCommand(unitId, unitToAttackId);
|
||||
}
|
||||
|
||||
void ScriptManager::giveProductionCommand(int unitId, const string &producedName){
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
world->giveProductionCommand(unitId, producedName);
|
||||
|
@ -228,6 +238,27 @@ void ScriptManager::disableAi(int factionIndex){
|
|||
}
|
||||
}
|
||||
|
||||
void ScriptManager::enableAi(int factionIndex){
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
if(factionIndex<GameConstants::maxPlayers){
|
||||
playerModifiers[factionIndex].enableAi();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptManager::disableHunger(int factionIndex){
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
if(factionIndex<GameConstants::maxPlayers){
|
||||
playerModifiers[factionIndex].disableHunger();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptManager::enableHunger(int factionIndex){
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
if(factionIndex<GameConstants::maxPlayers){
|
||||
playerModifiers[factionIndex].enableHunger();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptManager::setPlayerAsWinner(int factionIndex){
|
||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||
if(factionIndex<GameConstants::maxPlayers){
|
||||
|
@ -344,6 +375,13 @@ int ScriptManager::givePositionCommand(LuaHandle* luaHandle){
|
|||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::giveAttackCommand(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
thisScriptManager->giveAttackCommand(
|
||||
luaArguments.getInt(-2),
|
||||
luaArguments.getInt(-1));
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::giveProductionCommand(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
|
@ -367,6 +405,24 @@ int ScriptManager::disableAi(LuaHandle* luaHandle){
|
|||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::enableAi(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
thisScriptManager->enableAi(luaArguments.getInt(-1));
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::disableHunger(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
thisScriptManager->disableHunger(luaArguments.getInt(-1));
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::enableHunger(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
thisScriptManager->enableHunger(luaArguments.getInt(-1));
|
||||
return luaArguments.getReturnCount();
|
||||
}
|
||||
|
||||
int ScriptManager::setPlayerAsWinner(LuaHandle* luaHandle){
|
||||
LuaArguments luaArguments(luaHandle);
|
||||
thisScriptManager->setPlayerAsWinner(luaArguments.getInt(-1));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2005 Martiño Figueroa
|
||||
// Copyright (C) 2001-2005 Martio Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
|
@ -52,14 +52,22 @@ public:
|
|||
PlayerModifiers();
|
||||
|
||||
void disableAi() {aiEnabled= false;}
|
||||
void enableAi() {aiEnabled= true;}
|
||||
|
||||
void setAsWinner() {winner= true;}
|
||||
|
||||
bool getWinner() const {return winner;}
|
||||
bool getAiEnabled() const {return aiEnabled;}
|
||||
void disableHunger() {hungerEnabled= false;}
|
||||
void enableHunger() {hungerEnabled= true;}
|
||||
|
||||
bool getWinner() const {return winner;}
|
||||
|
||||
bool getAiEnabled() const {return aiEnabled;}
|
||||
bool getHungerEnabled() const {return hungerEnabled;}
|
||||
|
||||
private:
|
||||
bool winner;
|
||||
bool aiEnabled;
|
||||
bool hungerEnabled;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
@ -132,8 +140,12 @@ private:
|
|||
void giveResource(const string &resourceName, int factionIndex, int amount);
|
||||
void givePositionCommand(int unitId, const string &producedName, const Vec2i &pos);
|
||||
void giveProductionCommand(int unitId, const string &producedName);
|
||||
void giveAttackCommand(int unitId, int unitToAttackId);
|
||||
void giveUpgradeCommand(int unitId, const string &upgradeName);
|
||||
void disableAi(int factionIndex);
|
||||
void enableAi(int factionIndex);
|
||||
void disableHunger(int factionIndex);
|
||||
void enableHunger(int factionIndex);
|
||||
void setPlayerAsWinner(int factionIndex);
|
||||
void endGame();
|
||||
|
||||
|
@ -158,8 +170,12 @@ private:
|
|||
static int giveResource(LuaHandle* luaHandle);
|
||||
static int givePositionCommand(LuaHandle* luaHandle);
|
||||
static int giveProductionCommand(LuaHandle* luaHandle);
|
||||
static int giveAttackCommand(LuaHandle* luaHandle);
|
||||
static int giveUpgradeCommand(LuaHandle* luaHandle);
|
||||
static int disableAi(LuaHandle* luaHandle);
|
||||
static int enableAi(LuaHandle* luaHandle);
|
||||
static int disableHunger(LuaHandle* luaHandle);
|
||||
static int enableHunger(LuaHandle* luaHandle);
|
||||
static int setPlayerAsWinner(LuaHandle* luaHandle);
|
||||
static int endGame(LuaHandle* luaHandle);
|
||||
|
||||
|
|
|
@ -364,7 +364,8 @@ void Faction::applyCostsOnInterval(){
|
|||
|
||||
//decrement consumables
|
||||
if((getCpuControl() == false) ||
|
||||
(getCpuControl() == true && scriptManager->getPlayerModifiers(this->thisFaction)->getAiEnabled() == false))
|
||||
(getCpuControl() == true &&
|
||||
scriptManager->getPlayerModifiers(this->index)->getAiEnabled() == true))
|
||||
{
|
||||
for(int j=0; j<getUnitCount(); ++j){
|
||||
Unit *unit= getUnit(j);
|
||||
|
@ -375,8 +376,11 @@ void Faction::applyCostsOnInterval(){
|
|||
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());
|
||||
|
||||
//decrease unit hp
|
||||
if(getResource(resource->getType())->getAmount()<0){
|
||||
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){
|
||||
|
|
|
@ -655,6 +655,22 @@ void World::givePositionCommand(int unitId, const string &commandName, const Vec
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void World::giveAttackCommand(int unitId, int unitToAttackId) {
|
||||
Unit* unit= findUnitById(unitId);
|
||||
if(unit != NULL){
|
||||
Unit* targetUnit = findUnitById(unitToAttackId);
|
||||
if(targetUnit != NULL) {
|
||||
const CommandType *ct= unit->getType()->getFirstAttackCommand(targetUnit->getCurrField());
|
||||
if(ct != NULL) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Unit [%s] is attacking [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->getFullName().c_str(),targetUnit->getFullName().c_str());
|
||||
unit->giveCommand(new Command(ct,targetUnit));
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void World::giveProductionCommand(int unitId, const string &producedName){
|
||||
Unit *unit= findUnitById(unitId);
|
||||
if(unit!=NULL){
|
||||
|
|
|
@ -183,6 +183,7 @@ public:
|
|||
//scripting interface
|
||||
void createUnit(const string &unitName, int factionIndex, const Vec2i &pos);
|
||||
void givePositionCommand(int unitId, const string &commandName, const Vec2i &pos);
|
||||
void giveAttackCommand(int unitId, int unitToAttackId);
|
||||
void giveProductionCommand(int unitId, const string &producedName);
|
||||
void giveUpgradeCommand(int unitId, const string &upgradeName);
|
||||
void giveResource(const string &resourceName, int factionIndex, int amount);
|
||||
|
|
Loading…
Reference in New Issue
Block a user