1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-14 02:33:51 +02:00

* refactoring

This commit is contained in:
mateuszb 2013-02-09 12:56:35 +00:00
parent a269b22741
commit d03dbf64a6
16 changed files with 65 additions and 61 deletions

View File

@ -1279,7 +1279,7 @@ bool VCAI::tryBuildStructure(const CGTownInstance * t, int building, unsigned in
BOOST_FOREACH(int buildID, toBuild) BOOST_FOREACH(int buildID, toBuild)
{ {
int canBuild = cb->canBuildStructure(t, buildID); EBuildingState::EBuildingState canBuild = cb->canBuildStructure(t, buildID);
if (canBuild == EBuildingState::HAVE_CAPITAL if (canBuild == EBuildingState::HAVE_CAPITAL
|| canBuild == EBuildingState::FORBIDDEN || canBuild == EBuildingState::FORBIDDEN
|| canBuild == EBuildingState::NO_WATER) || canBuild == EBuildingState::NO_WATER)
@ -1297,7 +1297,7 @@ bool VCAI::tryBuildStructure(const CGTownInstance * t, int building, unsigned in
{ {
const CBuilding *b = t->town->buildings[buildID]; const CBuilding *b = t->town->buildings[buildID];
int canBuild = cb->canBuildStructure(t, buildID); EBuildingState::EBuildingState canBuild = cb->canBuildStructure(t, buildID);
if(canBuild == EBuildingState::ALLOWED) if(canBuild == EBuildingState::ALLOWED)
{ {
if(!containsSavedRes(b->resources)) if(!containsSavedRes(b->resources))
@ -1962,14 +1962,14 @@ void VCAI::tryRealize(CGoal g)
break; break;
case COLLECT_RES: //TODO: use piles and mines? case COLLECT_RES: //TODO: use piles and mines?
if(cb->getResourceAmount(g.resID) >= g.value) if(cb->getResourceAmount(static_cast<Res::ERes>(g.resID)) >= g.value)
throw cannotFulfillGoalException("Goal is already fulfilled!"); throw cannotFulfillGoalException("Goal is already fulfilled!");
if(const CGObjectInstance *obj = cb->getObj(g.objid, false)) if(const CGObjectInstance *obj = cb->getObj(g.objid, false))
{ {
if(const IMarket *m = IMarket::castFrom(obj, false)) if(const IMarket *m = IMarket::castFrom(obj, false))
{ {
for (int i = 0; i < ACTUAL_RESOURCE_COUNT; i++) for (Res::ERes i = Res::WOOD; i <= Res::GOLD; vstd::advance(i, 1))
{ {
if(i == g.resID) continue; if(i == g.resID) continue;
int toGive, toGet; int toGive, toGet;
@ -1977,7 +1977,7 @@ void VCAI::tryRealize(CGoal g)
toGive = toGive * (cb->getResourceAmount(i) / toGive); toGive = toGive * (cb->getResourceAmount(i) / toGive);
//TODO trade only as much as needed //TODO trade only as much as needed
cb->trade(obj, EMarketMode::RESOURCE_RESOURCE, i, g.resID, toGive); cb->trade(obj, EMarketMode::RESOURCE_RESOURCE, i, g.resID, toGive);
if(cb->getResourceAmount(g.resID) >= g.value) if(cb->getResourceAmount(static_cast<Res::ERes>(g.resID)) >= g.value)
return; return;
} }
@ -2814,7 +2814,7 @@ TSubgoal CGoal::whatToDoToAchieve()
case EVictoryConditionType::CAPTURECITY: case EVictoryConditionType::CAPTURECITY:
return CGoal(GET_OBJ).setobjid(vc.obj->id); return CGoal(GET_OBJ).setobjid(vc.obj->id);
case EVictoryConditionType::GATHERRESOURCE: case EVictoryConditionType::GATHERRESOURCE:
return CGoal(COLLECT_RES).setresID(vc.objectId).setvalue(vc.count); return CGoal(COLLECT_RES).setresID(static_cast<Res::ERes>(vc.objectId)).setvalue(vc.count);
//TODO mines? piles? marketplace? //TODO mines? piles? marketplace?
//save? //save?
break; break;
@ -3168,7 +3168,7 @@ TSubgoal CGoal::whatToDoToAchieve()
const IMarket *m = markets.back(); const IMarket *m = markets.back();
//attempt trade at back (best prices) //attempt trade at back (best prices)
int howManyCanWeBuy = 0; int howManyCanWeBuy = 0;
for(int i = 0; i < ACTUAL_RESOURCE_COUNT; i++) for(Res::ERes i = Res::WOOD; i <= Res::GOLD; vstd::advance(i, 1))
{ {
if(i == resID) continue; if(i == resID) continue;
int toGive = -1, toReceive = -1; int toGive = -1, toReceive = -1;
@ -3177,7 +3177,7 @@ TSubgoal CGoal::whatToDoToAchieve()
howManyCanWeBuy += toReceive * (cb->getResourceAmount(i) / toGive); howManyCanWeBuy += toReceive * (cb->getResourceAmount(i) / toGive);
} }
if(howManyCanWeBuy + cb->getResourceAmount(resID) >= value) if(howManyCanWeBuy + cb->getResourceAmount(static_cast<Res::ERes>(resID)) >= value)
{ {
auto backObj = backOrNull(cb->getVisitableObjs(m->o->visitablePos())); //it'll be a hero if we have one there; otherwise marketplace auto backObj = backOrNull(cb->getVisitableObjs(m->o->visitablePos())); //it'll be a hero if we have one there; otherwise marketplace
assert(backObj); assert(backObj);

View File

@ -758,7 +758,7 @@ void CInfoBar::CVisibleInfo::loadGameStatus()
//generate list of allies and enemies //generate list of allies and enemies
for(int i = 0; i < GameConstants::PLAYER_LIMIT; i++) for(int i = 0; i < GameConstants::PLAYER_LIMIT; i++)
{ {
if(LOCPLINT->cb->getPlayerStatus(i) == PlayerState::INGAME) if(LOCPLINT->cb->getPlayerStatus(i) == EPlayerStatus::INGAME)
{ {
if (LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, i) != PlayerRelations::ENEMIES) if (LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, i) != PlayerRelations::ENEMIES)
allies.push_back(i); allies.push_back(i);

View File

@ -335,7 +335,7 @@ CResDataBar::~CResDataBar()
void CResDataBar::draw(SDL_Surface * to) void CResDataBar::draw(SDL_Surface * to)
{ {
blitAt(bg,pos.x,pos.y,to); blitAt(bg,pos.x,pos.y,to);
for (int i=0;i<7;i++) for (auto i=Res::WOOD; i<=Res::GOLD; vstd::advance(i, 1))
{ {
std::string text = boost::lexical_cast<std::string>(LOCPLINT->cb->getResourceAmount(i)); std::string text = boost::lexical_cast<std::string>(LOCPLINT->cb->getResourceAmount(i));

View File

@ -2067,7 +2067,7 @@ void CPlayerInterface::gameOver(ui8 player, bool victory )
else else
{ {
if(!victory && cb->getPlayerStatus(playerID) == PlayerState::INGAME) //enemy has lost if(!victory && cb->getPlayerStatus(playerID) == EPlayerStatus::INGAME) //enemy has lost
{ {
std::string txt = CGI->generaltexth->allTexts[5]; //%s has been vanquished! std::string txt = CGI->generaltexth->allTexts[5]; //%s has been vanquished!
boost::algorithm::replace_first(txt, "%s", CGI->generaltexth->capColors[player]); boost::algorithm::replace_first(txt, "%s", CGI->generaltexth->capColors[player]);

View File

@ -1753,7 +1753,7 @@ void CMinorResDataBar::show(SDL_Surface * to)
void CMinorResDataBar::showAll(SDL_Surface * to) void CMinorResDataBar::showAll(SDL_Surface * to)
{ {
blitAt(bg,pos.x,pos.y,to); blitAt(bg,pos.x,pos.y,to);
for (int i=0;i<7;i++) for (Res::ERes i=Res::WOOD; i<=Res::GOLD; vstd::advance(i, 1))
{ {
std::string text = boost::lexical_cast<std::string>(LOCPLINT->cb->getResourceAmount(i)); std::string text = boost::lexical_cast<std::string>(LOCPLINT->cb->getResourceAmount(i));
@ -2361,7 +2361,7 @@ std::vector<int> *CTradeWindow::getItemsIds(bool Left)
case PLAYER: case PLAYER:
ids = new std::vector<int>; ids = new std::vector<int>;
for(int i = 0; i < GameConstants::PLAYER_LIMIT; i++) for(int i = 0; i < GameConstants::PLAYER_LIMIT; i++)
if(i != LOCPLINT->playerID && LOCPLINT->cb->getPlayerStatus(i) == PlayerState::INGAME) if(i != LOCPLINT->playerID && LOCPLINT->cb->getPlayerStatus(i) == EPlayerStatus::INGAME)
ids->push_back(i); ids->push_back(i);
break; break;
@ -2426,7 +2426,7 @@ void CTradeWindow::initSubs(bool Left)
t->subtitle = boost::lexical_cast<std::string>(hero->getStackCount(t->serial)); t->subtitle = boost::lexical_cast<std::string>(hero->getStackCount(t->serial));
break; break;
case RESOURCE: case RESOURCE:
t->subtitle = boost::lexical_cast<std::string>(LOCPLINT->cb->getResourceAmount(t->serial)); t->subtitle = boost::lexical_cast<std::string>(LOCPLINT->cb->getResourceAmount(static_cast<Res::ERes>(t->serial)));
break; break;
} }
} }
@ -2756,7 +2756,7 @@ void CMarketplaceWindow::selectionChanged(bool side)
{ {
int newAmount = -1; int newAmount = -1;
if(itemsType[1] == RESOURCE) if(itemsType[1] == RESOURCE)
newAmount = LOCPLINT->cb->getResourceAmount(soldItemId); newAmount = LOCPLINT->cb->getResourceAmount(static_cast<Res::ERes>(soldItemId));
else if(itemsType[1] == CREATURE) else if(itemsType[1] == CREATURE)
newAmount = hero->getStackCount(hLeft->serial) - (hero->Slots().size() == 1 && hero->needsLastStack()); newAmount = hero->getStackCount(hLeft->serial) - (hero->Slots().size() == 1 && hero->needsLastStack());
else else
@ -2769,7 +2769,7 @@ void CMarketplaceWindow::selectionChanged(bool side)
} }
else if(itemsType[1] == RESOURCE) //buying -> check if we can afford transaction else if(itemsType[1] == RESOURCE) //buying -> check if we can afford transaction
{ {
deal->block(LOCPLINT->cb->getResourceAmount(soldItemId) < r1); deal->block(LOCPLINT->cb->getResourceAmount(static_cast<Res::ERes>(soldItemId)) < r1);
} }
else else
deal->block(false); deal->block(false);
@ -3672,7 +3672,7 @@ CTavernWindow::CTavernWindow(const CGObjectInstance *TavernObj):
recruit = new CAdventureMapButton("", "", boost::bind(&CTavernWindow::recruitb, this), 272, 355, "TPTAV01.DEF", SDLK_RETURN); recruit = new CAdventureMapButton("", "", boost::bind(&CTavernWindow::recruitb, this), 272, 355, "TPTAV01.DEF", SDLK_RETURN);
thiefGuild = new CAdventureMapButton(CGI->generaltexth->tavernInfo[5],"", boost::bind(&CTavernWindow::thievesguildb, this), 22, 428, "TPTAV02.DEF", SDLK_t); thiefGuild = new CAdventureMapButton(CGI->generaltexth->tavernInfo[5],"", boost::bind(&CTavernWindow::thievesguildb, this), 22, 428, "TPTAV02.DEF", SDLK_t);
if(LOCPLINT->cb->getResourceAmount(6) < 2500) //not enough gold if(LOCPLINT->cb->getResourceAmount(Res::GOLD) < 2500) //not enough gold
{ {
recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[0]; //Cannot afford a Hero recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[0]; //Cannot afford a Hero
recruit->block(2); recruit->block(2);
@ -5204,7 +5204,7 @@ CShipyardWindow::CShipyardWindow(const std::vector<si32> &cost, int state, int b
build = new CAdventureMapButton(CGI->generaltexth->allTexts[598], "", boost::bind(&CShipyardWindow::close, this), 42, 312, "IBUY30", SDLK_RETURN); build = new CAdventureMapButton(CGI->generaltexth->allTexts[598], "", boost::bind(&CShipyardWindow::close, this), 42, 312, "IBUY30", SDLK_RETURN);
build->callback += onBuy; build->callback += onBuy;
for(size_t i = 0; i < cost.size(); i++) for(Res::ERes i = Res::WOOD; i <= Res::GOLD; vstd::advance(i, 1))
{ {
if(cost[i] > LOCPLINT->cb->getResourceAmount(i)) if(cost[i] > LOCPLINT->cb->getResourceAmount(i))
{ {
@ -5384,7 +5384,7 @@ void CUniversityWindow::CItem::clickLeft(tribool down, bool previousState)
{ {
if ( state() != 2 ) if ( state() != 2 )
return; return;
CUnivConfirmWindow *win = new CUnivConfirmWindow(parent, ID, LOCPLINT->cb->getResourceAmount(6) >= 2000); CUnivConfirmWindow *win = new CUnivConfirmWindow(parent, ID, LOCPLINT->cb->getResourceAmount(Res::GOLD) >= 2000);
GH.pushInt(win); GH.pushInt(win);
} }
} }

View File

@ -299,7 +299,7 @@ int CBattleInfoEssentials::battleCastSpells(ui8 side) const
return getBattle()->castSpells[side]; return getBattle()->castSpells[side];
} }
ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(int player, ECastingMode::ECastingMode mode) const ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(TPlayerColor player, ECastingMode::ECastingMode mode) const
{ {
RETURN_IF_NOT_BATTLE(ESpellCastProblem::INVALID); RETURN_IF_NOT_BATTLE(ESpellCastProblem::INVALID);
const ui8 side = playerToSide(player); const ui8 side = playerToSide(player);
@ -1535,7 +1535,7 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleIsImmune(const C
return ESpellCastProblem::OK; return ESpellCastProblem::OK;
} }
ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell( int player, const CSpell * spell, ECastingMode::ECastingMode mode ) const ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell( TPlayerColor player, const CSpell * spell, ECastingMode::ECastingMode mode ) const
{ {
RETURN_IF_NOT_BATTLE(ESpellCastProblem::INVALID); RETURN_IF_NOT_BATTLE(ESpellCastProblem::INVALID);
const ui8 side = playerToSide(player); const ui8 side = playerToSide(player);
@ -1735,7 +1735,7 @@ ui32 CBattleInfoCallback::battleGetSpellCost(const CSpell * sp, const CGHeroInst
return ret - manaReduction + manaIncrease; return ret - manaReduction + manaIncrease;
} }
ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpellHere( int player, const CSpell * spell, ECastingMode::ECastingMode mode, BattleHex dest ) const ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpellHere( TPlayerColor player, const CSpell * spell, ECastingMode::ECastingMode mode, BattleHex dest ) const
{ {
RETURN_IF_NOT_BATTLE(ESpellCastProblem::INVALID); RETURN_IF_NOT_BATTLE(ESpellCastProblem::INVALID);
ESpellCastProblem::ESpellCastProblem moreGeneralProblem = battleCanCastThisSpell(player, spell, mode); ESpellCastProblem::ESpellCastProblem moreGeneralProblem = battleCanCastThisSpell(player, spell, mode);

View File

@ -250,9 +250,9 @@ public:
//*** MAGIC //*** MAGIC
si8 battleMaxSpellLevel() const; //calculates minimum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, 0 is returned si8 battleMaxSpellLevel() const; //calculates minimum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, 0 is returned
ui32 battleGetSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //returns cost of given spell ui32 battleGetSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //returns cost of given spell
ESpellCastProblem::ESpellCastProblem battleCanCastSpell(int player, ECastingMode::ECastingMode mode) const; //returns true if there are no general issues preventing from casting a spell ESpellCastProblem::ESpellCastProblem battleCanCastSpell(TPlayerColor player, ECastingMode::ECastingMode mode) const; //returns true if there are no general issues preventing from casting a spell
ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(int player, const CSpell * spell, ECastingMode::ECastingMode mode) const; //checks if given player can cast given spell ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(TPlayerColor player, const CSpell * spell, ECastingMode::ECastingMode mode) const; //checks if given player can cast given spell
ESpellCastProblem::ESpellCastProblem battleCanCastThisSpellHere(int player, const CSpell * spell, ECastingMode::ECastingMode mode, BattleHex dest) const; //checks if given player can cast given spell at given tile in given mode ESpellCastProblem::ESpellCastProblem battleCanCastThisSpellHere(TPlayerColor player, const CSpell * spell, ECastingMode::ECastingMode mode, BattleHex dest) const; //checks if given player can cast given spell at given tile in given mode
ESpellCastProblem::ESpellCastProblem battleCanCreatureCastThisSpell(const CSpell * spell, BattleHex destination) const; //determines if creature can cast a spell here ESpellCastProblem::ESpellCastProblem battleCanCreatureCastThisSpell(const CSpell * spell, BattleHex destination) const; //determines if creature can cast a spell here
std::vector<BattleHex> battleGetPossibleTargets(int player, const CSpell *spell) const; std::vector<BattleHex> battleGetPossibleTargets(int player, const CSpell *spell) const;
ui32 calculateSpellBonus(ui32 baseDamage, const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature) const; ui32 calculateSpellBonus(ui32 baseDamage, const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature) const;

View File

@ -2352,7 +2352,7 @@ ui8 CGameState::checkForStandardWin() const
TPlayerColor supposedWinner = 255, winnerTeam = 255; TPlayerColor supposedWinner = 255, winnerTeam = 255;
for(auto i = players.begin(); i != players.end(); i++) for(auto i = players.begin(); i != players.end(); i++)
{ {
if(i->second.status == PlayerState::INGAME && i->first < GameConstants::PLAYER_LIMIT) if(i->second.status == EPlayerStatus::INGAME && i->first < GameConstants::PLAYER_LIMIT)
{ {
if(supposedWinner == 255) if(supposedWinner == 255)
{ {
@ -2760,7 +2760,7 @@ void CGPath::convert( ui8 mode )
PlayerState::PlayerState() PlayerState::PlayerState()
: color(-1), currentSelection(0xffffffff), enteredWinningCheatCode(0), : color(-1), currentSelection(0xffffffff), enteredWinningCheatCode(0),
enteredLosingCheatCode(0), status(INGAME), daysWithoutCastle(0) enteredLosingCheatCode(0), status(EPlayerStatus::INGAME), daysWithoutCastle(0)
{ {
setNodeType(PLAYER); setNodeType(PLAYER);
} }

View File

@ -163,9 +163,8 @@ struct DLL_LINKAGE SThievesGuildInfo
struct DLL_LINKAGE PlayerState : public CBonusSystemNode struct DLL_LINKAGE PlayerState : public CBonusSystemNode
{ {
public: public:
enum EStatus {WRONG = -1, INGAME, LOSER, WINNER};
TPlayerColor color; TPlayerColor color;
ui8 human; //true if human controlled player, false for AI bool human; //true if human controlled player, false for AI
ui32 currentSelection; //id of hero/town, 0xffffffff if none ui32 currentSelection; //id of hero/town, 0xffffffff if none
ui8 team; ui8 team;
TResources resources; TResources resources;
@ -175,8 +174,8 @@ public:
std::vector<ConstTransitivePtr<CGDwelling> > dwellings; //used for town growth std::vector<ConstTransitivePtr<CGDwelling> > dwellings; //used for town growth
std::vector<QuestInfo> quests; //store info about all received quests std::vector<QuestInfo> quests; //store info about all received quests
ui8 enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
EStatus status; EPlayerStatus::EStatus status;
ui8 daysWithoutCastle; ui8 daysWithoutCastle;
PlayerState(); PlayerState();

View File

@ -442,7 +442,7 @@ void CGObjectInstance::hideTiles(int ourplayer, int radius) const
if ( !vstd::contains(i->second.players, ourplayer ))//another team if ( !vstd::contains(i->second.players, ourplayer ))//another team
{ {
for (auto j = i->second.players.begin(); j != i->second.players.end(); j++) for (auto j = i->second.players.begin(); j != i->second.players.end(); j++)
if ( cb->getPlayer(*j)->status == PlayerState::INGAME )//seek for living player (if any) if ( cb->getPlayer(*j)->status == EPlayerStatus::INGAME )//seek for living player (if any)
{ {
FoWChange fw; FoWChange fw;
fw.mode = 0; fw.mode = 0;
@ -2694,7 +2694,7 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
} }
else else
{ {
ui32 res; Res::ERes res;
si32 resval; si32 resval;
if(ttype==1) if(ttype==1)
{ {
@ -2748,7 +2748,7 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
case Obj::SCHOOL_OF_WAR: case Obj::SCHOOL_OF_WAR:
{ {
int skill = (ID==Obj::SCHOOL_OF_MAGIC ? 2 : 0); int skill = (ID==Obj::SCHOOL_OF_MAGIC ? 2 : 0);
if(cb->getResource(cb->getOwner(heroID),6) < 1000) //not enough resources if(cb->getResource(cb->getOwner(heroID), Res::GOLD) < 1000) //not enough resources
{ {
showInfoDialog(heroID,ot+2,sound); showInfoDialog(heroID,ot+2,sound);
} }
@ -3259,7 +3259,7 @@ void CGCreature::joinDecision(const CGHeroInstance *h, int cost, ui32 accept) co
} }
else //accepted else //accepted
{ {
if (cb->getResource(h->tempOwner,6) < cost) //player don't have enough gold! if (cb->getResource(h->tempOwner, Res::GOLD) < cost) //player don't have enough gold!
{ {
InfoWindow iw; InfoWindow iw;
iw.player = h->tempOwner; iw.player = h->tempOwner;
@ -4154,7 +4154,7 @@ bool CQuest::checkQuest (const CGHeroInstance * h) const
} }
return true; return true;
case MISSION_RESOURCES: case MISSION_RESOURCES:
for (int i = 0; i < 7; ++i) //including Mithril ? for (Res::ERes i = Res::WOOD; i <= Res::GOLD; vstd::advance(i, +1)) //including Mithril ?
{ //Quest has no direct access to callback { //Quest has no direct access to callback
if (h->cb->getResource (h->tempOwner, i) < m7resources[i]) if (h->cb->getResource (h->tempOwner, i) < m7resources[i])
return false; return false;
@ -6013,7 +6013,7 @@ void CBank::newTurn() const
cb->setObjProperty (id, 11, 1); //daycounter++ cb->setObjProperty (id, 11, 1); //daycounter++
} }
} }
bool CBank::wasVisited (ui8 player) const bool CBank::wasVisited (TPlayerColor player) const
{ {
return !bc; return !bc;
} }
@ -6642,7 +6642,7 @@ void CCartographer::onHeroVisit( const CGHeroInstance * h ) const
{ {
if (!wasVisited (h->getOwner()) ) //if hero has not visited yet this cartographer if (!wasVisited (h->getOwner()) ) //if hero has not visited yet this cartographer
{ {
if (cb->getResource(h->tempOwner, 6) >= 1000) //if he can afford a map if (cb->getResource(h->tempOwner, Res::GOLD) >= 1000) //if he can afford a map
{ {
//ask if he wants to buy one //ask if he wants to buy one
int text=0; int text=0;

View File

@ -1210,7 +1210,7 @@ class DLL_LINKAGE CBank : public CArmedInstance
void initialize() const; void initialize() const;
void reset(ui16 var1); void reset(ui16 var1);
void newTurn() const override; void newTurn() const override;
bool wasVisited (ui8 player) const override; bool wasVisited (TPlayerColor player) const override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
virtual void fightGuards (const CGHeroInstance *h, ui32 accept) const; virtual void fightGuards (const CGHeroInstance *h, ui32 accept) const;

View File

@ -195,7 +195,7 @@ namespace EBuildingState
enum EBuildingState enum EBuildingState
{ {
HAVE_CAPITAL, NO_WATER, FORBIDDEN, ADD_MAGES_GUILD, ALREADY_PRESENT, CANT_BUILD_TODAY, HAVE_CAPITAL, NO_WATER, FORBIDDEN, ADD_MAGES_GUILD, ALREADY_PRESENT, CANT_BUILD_TODAY,
NO_RESOURCES, ALLOWED, PREREQUIRES, BUILDING_ERROR NO_RESOURCES, ALLOWED, PREREQUIRES, BUILDING_ERROR, TOWN_NOT_OWNED
}; };
} }
@ -479,6 +479,11 @@ namespace BFieldType
}; };
} }
namespace EPlayerStatus
{
enum EStatus {WRONG = -1, INGAME, LOSER, WINNER};
}
namespace PlayerRelations namespace PlayerRelations
{ {
enum PlayerRelations {ENEMIES, ALLIES, SAME_PLAYER}; enum PlayerRelations {ENEMIES, ALLIES, SAME_PLAYER};

View File

@ -48,7 +48,7 @@ int CGameInfoCallback::getOwner(int heroID) const
return gs->map->objects[heroID]->tempOwner; return gs->map->objects[heroID]->tempOwner;
} }
int CGameInfoCallback::getResource(int Player, int which) const int CGameInfoCallback::getResource(TPlayerColor Player, Res::ERes which) const
{ {
const PlayerState *p = getPlayer(Player); const PlayerState *p = getPlayer(Player);
ERROR_RET_VAL_IF(!p, "No player info!", -1); ERROR_RET_VAL_IF(!p, "No player info!", -1);
@ -56,7 +56,7 @@ int CGameInfoCallback::getResource(int Player, int which) const
return p->resources[which]; return p->resources[which];
} }
const CGHeroInstance* CGameInfoCallback::getSelectedHero( int Player ) const const CGHeroInstance* CGameInfoCallback::getSelectedHero( TPlayerColor Player ) const
{ {
const PlayerState *p = getPlayer(Player); const PlayerState *p = getPlayer(Player);
ERROR_RET_VAL_IF(!p, "No player info!", NULL); ERROR_RET_VAL_IF(!p, "No player info!", NULL);
@ -68,7 +68,7 @@ const CGHeroInstance* CGameInfoCallback::getSelectedHero() const
return getSelectedHero(gs->currentPlayer); return getSelectedHero(gs->currentPlayer);
} }
const PlayerSettings * CGameInfoCallback::getPlayerSettings(int color) const const PlayerSettings * CGameInfoCallback::getPlayerSettings(TPlayerColor color) const
{ {
return &gs->scenarioOps->getIthPlayersSettings(color); return &gs->scenarioOps->getIthPlayersSettings(color);
} }
@ -224,7 +224,7 @@ inline TerrainTile * CNonConstInfoCallback::getTile( int3 pos )
return &gs->map->getTile(pos); return &gs->map->getTile(pos);
} }
const PlayerState * CGameInfoCallback::getPlayer(int color, bool verbose) const const PlayerState * CGameInfoCallback::getPlayer(TPlayerColor color, bool verbose) const
{ {
ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!hasAccess(color), verbose, "Cannot access player " << color << "info!", NULL); ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!hasAccess(color), verbose, "Cannot access player " << color << "info!", NULL);
ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!vstd::contains(gs->players,color), verbose, "Cannot find player " << color << "info!", NULL); ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!vstd::contains(gs->players,color), verbose, "Cannot find player " << color << "info!", NULL);
@ -524,9 +524,9 @@ const TerrainTile * CGameInfoCallback::getTile( int3 tile, bool verbose) const
return &gs->map->getTile(tile); return &gs->map->getTile(tile);
} }
int CGameInfoCallback::canBuildStructure( const CGTownInstance *t, int ID ) EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTownInstance *t, int ID )
{ {
ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", -1); ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", EBuildingState::TOWN_NOT_OWNED);
CBuilding * pom = t->town->buildings[ID]; CBuilding * pom = t->town->buildings[ID];
@ -561,7 +561,7 @@ int CGameInfoCallback::canBuildStructure( const CGTownInstance *t, int ID )
if (notAllBuilt) if (notAllBuilt)
return EBuildingState::PREREQUIRES; return EBuildingState::PREREQUIRES;
if(ID == 13) //capitol if(ID == EBuilding::CAPITOL)
{ {
const PlayerState *ps = getPlayer(t->tempOwner); const PlayerState *ps = getPlayer(t->tempOwner);
if(ps) if(ps)
@ -575,7 +575,7 @@ int CGameInfoCallback::canBuildStructure( const CGTownInstance *t, int ID )
} }
} }
} }
else if(ID == 6) //shipyard else if(ID == EBuilding::SHIPYARD)
{ {
const TerrainTile *tile = getTile(t->bestLocation(), false); const TerrainTile *tile = getTile(t->bestLocation(), false);
@ -630,10 +630,10 @@ bool CGameInfoCallback::hasAccess(int playerId) const
return player < 0 || gs->getPlayerRelations( playerId, player ) != PlayerRelations::ENEMIES; return player < 0 || gs->getPlayerRelations( playerId, player ) != PlayerRelations::ENEMIES;
} }
int CGameInfoCallback::getPlayerStatus(int player) const EPlayerStatus::EStatus CGameInfoCallback::getPlayerStatus(TPlayerColor player) const
{ {
const PlayerState *ps = gs->getPlayer(player, false); const PlayerState *ps = gs->getPlayer(player, false);
ERROR_RET_VAL_IF(!ps, "No such player!", -1); ERROR_RET_VAL_IF(!ps, "No such player!", EPlayerStatus::WRONG);
return ps->status; return ps->status;
} }
@ -836,7 +836,7 @@ const CGTownInstance* CPlayerSpecificInfoCallback::getTownBySerial(int serialId)
return p->towns[serialId]; return p->towns[serialId];
} }
int CPlayerSpecificInfoCallback::getResourceAmount(int type) const int CPlayerSpecificInfoCallback::getResourceAmount(Res::ERes type) const
{ {
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
ERROR_RET_VAL_IF(player == -1, "Applicable only for player callbacks", -1); ERROR_RET_VAL_IF(player == -1, "Applicable only for player callbacks", -1);

View File

@ -80,15 +80,15 @@ public:
bool isAllowed(int type, int id); //type: 0 - spell; 1- artifact; 2 - secondary skill bool isAllowed(int type, int id); //type: 0 - spell; 1- artifact; 2 - secondary skill
//player //player
const PlayerState * getPlayer(int color, bool verbose = true) const; const PlayerState * getPlayer(TPlayerColor color, bool verbose = true) const;
int getResource(int Player, int which) const; int getResource(TPlayerColor Player, Res::ERes which) const;
bool isVisible(int3 pos) const; bool isVisible(int3 pos) const;
PlayerRelations::PlayerRelations getPlayerRelations(TPlayerColor color1, TPlayerColor color2) const; PlayerRelations::PlayerRelations getPlayerRelations(TPlayerColor color1, TPlayerColor color2) const;
void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object
int getPlayerStatus(int player) const; //-1 if no such player EPlayerStatus::EStatus getPlayerStatus(TPlayerColor player) const; //-1 if no such player
int getCurrentPlayer() const; //player that currently makes move // TODO synchronous turns int getCurrentPlayer() const; //player that currently makes move // TODO synchronous turns
virtual int getLocalPlayer() const; //player that is currently owning given client (if not a client, then returns current player) virtual int getLocalPlayer() const; //player that is currently owning given client (if not a client, then returns current player)
const PlayerSettings * getPlayerSettings(int color) const; const PlayerSettings * getPlayerSettings(TPlayerColor color) const;
//armed object //armed object
@ -101,7 +101,7 @@ public:
bool getHeroInfo(const CGObjectInstance *hero, InfoAboutHero &dest) const; bool getHeroInfo(const CGObjectInstance *hero, InfoAboutHero &dest) const;
int getSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //when called during battle, takes into account creatures' spell cost reduction int getSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //when called during battle, takes into account creatures' spell cost reduction
int estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg int estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg
const CGHeroInstance* getSelectedHero(int player) const; //NULL if no hero is selected const CGHeroInstance* getSelectedHero(TPlayerColor player) const; //NULL if no hero is selected
const CGHeroInstance* getSelectedHero() const; //of current (active) player const CGHeroInstance* getSelectedHero() const; //of current (active) player
//objects //objects
@ -127,7 +127,7 @@ public:
const CGTownInstance * getTownInfo(int val, bool mode)const; //mode = 0 -> val = player town serial; mode = 1 -> val = object id (serial) const CGTownInstance * getTownInfo(int val, bool mode)const; //mode = 0 -> val = player town serial; mode = 1 -> val = object id (serial)
std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const; //heroes that can be recruited std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const; //heroes that can be recruited
std::string getTavernGossip(const CGObjectInstance * townOrTavern) const; std::string getTavernGossip(const CGObjectInstance * townOrTavern) const;
int canBuildStructure(const CGTownInstance *t, int ID);//// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements EBuildingState::EBuildingState canBuildStructure(const CGTownInstance *t, int ID);//// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
std::set<int> getBuildingRequiments(const CGTownInstance *t, int ID); std::set<int> getBuildingRequiments(const CGTownInstance *t, int ID);
virtual bool getTownInfo(const CGObjectInstance *town, InfoAboutTown &dest) const; virtual bool getTownInfo(const CGObjectInstance *town, InfoAboutTown &dest) const;
const CTown *getNativeTown(int color) const; const CTown *getNativeTown(int color) const;
@ -136,7 +136,7 @@ public:
const TeamState *getTeam(ui8 teamID) const; const TeamState *getTeam(ui8 teamID) const;
const TeamState *getPlayerTeam(ui8 color) const; const TeamState *getPlayerTeam(ui8 color) const;
std::set<int> getBuildingRequiments(const CGTownInstance *t, int ID) const; std::set<int> getBuildingRequiments(const CGTownInstance *t, int ID) const;
int canBuildStructure(const CGTownInstance *t, int ID) const;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements EBuildingState::EBuildingState canBuildStructure(const CGTownInstance *t, int ID) const;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
}; };
@ -157,7 +157,7 @@ public:
std::vector <const CGObjectInstance * > getMyObjects() const; //returns all objects flagged by belonging player std::vector <const CGObjectInstance * > getMyObjects() const; //returns all objects flagged by belonging player
std::vector <QuestInfo> getMyQuests() const; std::vector <QuestInfo> getMyQuests() const;
int getResourceAmount(int type)const; int getResourceAmount(Res::ERes type) const;
TResources getResourceAmount() const; TResources getResourceAmount() const;
const std::vector< std::vector< std::vector<ui8> > > & getVisibilityMap()const; //returns visibility map const std::vector< std::vector< std::vector<ui8> > > & getVisibilityMap()const; //returns visibility map
const PlayerSettings * getPlayerSettings(int color) const; const PlayerSettings * getPlayerSettings(int color) const;

View File

@ -248,7 +248,7 @@ DLL_LINKAGE void ChangeObjPos::applyGs( CGameState *gs )
DLL_LINKAGE void PlayerEndsGame::applyGs( CGameState *gs ) DLL_LINKAGE void PlayerEndsGame::applyGs( CGameState *gs )
{ {
PlayerState *p = gs->getPlayer(player); PlayerState *p = gs->getPlayer(player);
p->status = victory ? PlayerState::WINNER : PlayerState::LOSER; p->status = victory ? EPlayerStatus::WINNER : EPlayerStatus::LOSER;
} }
DLL_LINKAGE void RemoveBonus::applyGs( CGameState *gs ) DLL_LINKAGE void RemoveBonus::applyGs( CGameState *gs )

View File

@ -3162,7 +3162,7 @@ bool CGameHandler::transformInUndead(const IMarket *market, const CGHeroInstance
bool CGameHandler::sendResources(ui32 val, TPlayerColor player, Res::ERes r1, TPlayerColor r2) bool CGameHandler::sendResources(ui32 val, TPlayerColor player, Res::ERes r1, TPlayerColor r2)
{ {
const PlayerState *p2 = gs->getPlayer(r2, false); const PlayerState *p2 = gs->getPlayer(r2, false);
if(!p2 || p2->status != PlayerState::INGAME) if(!p2 || p2->status != EPlayerStatus::INGAME)
{ {
complain("Dest player must be in game!"); complain("Dest player must be in game!");
return false; return false;