1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* JsonReader can convert to enums

* refactoring
This commit is contained in:
mateuszb 2013-02-03 21:05:44 +00:00
parent 1fca96257d
commit 8769f67c5d
38 changed files with 312 additions and 248 deletions

View File

@ -723,7 +723,7 @@ void CBattleAI::attemptCastingSpell()
LOGFL("Best spell is %s. Will cast.", castToPerform.spell->name);
BattleAction spellcast;
spellcast.actionType = BattleAction::HERO_SPELL;
spellcast.actionType = Battle::HERO_SPELL;
spellcast.additionalInfo = castToPerform.spell->id;
spellcast.destinationTile = castToPerform.dest;
spellcast.side = side;

View File

@ -106,7 +106,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack )
BattleAction attack;
static const int wallHexes[] = {50, 183, 182, 130, 62, 29, 12, 95};
attack.destinationTile = wallHexes[ rand()%ARRAY_COUNT(wallHexes) ];
attack.actionType = BattleAction::CATAPULT;
attack.actionType = Battle::CATAPULT;
attack.additionalInfo = 0;
attack.side = side;
attack.stackNumber = stack->ID;

View File

@ -393,7 +393,7 @@ ui64 evaluateDanger(crint3 tile, const CGHeroInstance *visitor)
ui64 evaluateDanger(const CGObjectInstance *obj)
{
if(obj->tempOwner < GameConstants::PLAYER_LIMIT && cb->getPlayerRelations(obj->tempOwner, ai->playerID)) //owned or allied objects don't pose any threat
if(obj->tempOwner < GameConstants::PLAYER_LIMIT && cb->getPlayerRelations(obj->tempOwner, ai->playerID) != PlayerRelations::ENEMIES) //owned or allied objects don't pose any threat
return 0;
switch(obj->ID)
@ -1454,7 +1454,7 @@ std::vector<const CGObjectInstance *> VCAI::getPossibleDestinations(HeroPtr h)
const CGObjectInstance *topObj = cb->getVisitableObjs(pos).back(); //it may be hero visiting this obj
//we don't try visiting object on which allied or owned hero stands
// -> it will just trigger exchange windows and AI will be confused that obj behind doesn't get visited
if(topObj->ID == Obj::HERO && cb->getPlayerRelations(h->tempOwner, topObj->tempOwner) != 0)
if(topObj->ID == Obj::HERO && cb->getPlayerRelations(h->tempOwner, topObj->tempOwner) != PlayerRelations::ENEMIES)
return true;
return false;
@ -2929,7 +2929,7 @@ TSubgoal CGoal::whatToDoToAchieve()
}
auto topObj = backOrNull(cb->getVisitableObjs(tileToHit));
if(topObj && topObj->ID == Obj::HERO && cb->getPlayerRelations(h->tempOwner, topObj->tempOwner) != 0)
if(topObj && topObj->ID == Obj::HERO && cb->getPlayerRelations(h->tempOwner, topObj->tempOwner) != PlayerRelations::ENEMIES)
{
std::string problem = boost::str(boost::format("%s stands in the way of %s.\n") % topObj->getHoverText() % h->getHoverText());
throw cannotFulfillGoalException(problem);
@ -3276,7 +3276,7 @@ TSubgoal CGoal::whatToDoToAchieve()
erase_if(objs, [&](const CGObjectInstance *obj)
{
return (obj->ID != Obj::TOWN && obj->ID != Obj::HERO) //not town/hero
|| cb->getPlayerRelations(ai->playerID, obj->tempOwner) != 0; //not enemy
|| cb->getPlayerRelations(ai->playerID, obj->tempOwner) != PlayerRelations::ENEMIES;
});
if (objs.empty()) //experiment - try to conquer dwellings and mines, it should pay off
@ -3285,7 +3285,7 @@ TSubgoal CGoal::whatToDoToAchieve()
erase_if(objs, [&](const CGObjectInstance *obj)
{
return (obj->ID != Obj::CREATURE_GENERATOR1 && obj->ID != Obj::MINE) //not dwelling or mine
|| cb->getPlayerRelations(ai->playerID, obj->tempOwner) != 0; //not enemy
|| cb->getPlayerRelations(ai->playerID, obj->tempOwner) != PlayerRelations::ENEMIES;
});
}

View File

@ -178,7 +178,7 @@ bool CCallback::buildBuilding(const CGTownInstance *town, si32 buildingID)
int CBattleCallback::battleMakeAction(BattleAction* action)
{
assert(action->actionType == BattleAction::HERO_SPELL);
assert(action->actionType == Battle::HERO_SPELL);
MakeCustomAction mca(*action);
sendRequest(&mca);
return 0;

View File

@ -20,6 +20,11 @@
*
*/
#ifdef _MSC_VER
#pragma warning (disable : 4800 ) /* disable conversion to bool warning -- I think it's intended in all places */
#endif //_MSC_VER
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <cstdio>
#include <stdio.h>

View File

@ -760,7 +760,7 @@ void CInfoBar::CVisibleInfo::loadGameStatus()
{
if(LOCPLINT->cb->getPlayerStatus(i) == PlayerState::INGAME)
{
if (LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, i) > 0)
if (LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, i) != PlayerRelations::ENEMIES)
allies.push_back(i);
else
enemies.push_back(i);

View File

@ -1245,7 +1245,7 @@ void CBattleInterface::bFleef()
void CBattleInterface::reallyFlee()
{
giveCommand(BattleAction::RETREAT,0,0);
giveCommand(Battle::RETREAT,0,0);
CCS->curh->changeGraphic(ECursor::ADVENTURE, 0);
}
@ -1257,7 +1257,7 @@ void CBattleInterface::reallySurrender()
}
else
{
giveCommand(BattleAction::SURRENDER,0,0);
giveCommand(Battle::SURRENDER,0,0);
CCS->curh->changeGraphic(ECursor::ADVENTURE, 0);
}
}
@ -1312,7 +1312,7 @@ void CBattleInterface::bWaitf()
return;
if(activeStack != NULL)
giveCommand(8,0,activeStack->ID);
giveCommand(Battle::WAIT,0,activeStack->ID);
}
void CBattleInterface::bDefencef()
@ -1321,7 +1321,7 @@ void CBattleInterface::bDefencef()
return;
if(activeStack != NULL)
giveCommand(3,0,activeStack->ID);
giveCommand(Battle::DEFEND,0,activeStack->ID);
}
void CBattleInterface::bConsoleUpf()
@ -1476,10 +1476,10 @@ void CBattleInterface::newRound(int number)
}
void CBattleInterface::giveCommand(ui8 action, BattleHex tile, ui32 stackID, si32 additional, si32 selected)
void CBattleInterface::giveCommand(Battle::ActionType action, BattleHex tile, ui32 stackID, si32 additional, si32 selected)
{
const CStack *stack = curInt->cb->battleGetStackByID(stackID);
if(!stack && action != BattleAction::HERO_SPELL && action != BattleAction::RETREAT && action != BattleAction::SURRENDER)
if(!stack && action != Battle::HERO_SPELL && action != Battle::RETREAT && action != Battle::SURRENDER)
{
return;
}
@ -1498,11 +1498,11 @@ void CBattleInterface::giveCommand(ui8 action, BattleHex tile, ui32 stackID, si3
//some basic validations
switch(action)
{
case BattleAction::WALK_AND_ATTACK:
case Battle::WALK_AND_ATTACK:
assert(curInt->cb->battleGetStackByPos(additional)); //stack to attack must exist
case BattleAction::WALK:
case BattleAction::SHOOT:
case BattleAction::CATAPULT:
case Battle::WALK:
case Battle::SHOOT:
case Battle::CATAPULT:
assert(tile < GameConstants::BFIELD_SIZE);
break;
}
@ -1905,7 +1905,7 @@ void CBattleInterface::battleStacksEffectsSet(const SetStackEffect & sse)
void CBattleInterface::castThisSpell(int spellID)
{
BattleAction * ba = new BattleAction;
ba->actionType = BattleAction::HERO_SPELL;
ba->actionType = Battle::HERO_SPELL;
ba->additionalInfo = spellID; //spell number
ba->destinationTile = -1;
ba->stackNumber = (attackingHeroInstance->tempOwner == curInt->playerID) ? -1 : -2;
@ -2230,7 +2230,7 @@ void CBattleInterface::showAliveStack(const CStack *stack, SDL_Surface * to)
if(stack->count > 0 //don't print if stack is not alive
&& (!curInt->curAction
|| (curInt->curAction->stackNumber != ID //don't print if stack is currently taking an action
&& (curInt->curAction->actionType != BattleAction::WALK_AND_ATTACK || stack->position != curInt->curAction->additionalInfo) //nor if it's an object of attack
&& (curInt->curAction->actionType != Battle::WALK_AND_ATTACK || stack->position != curInt->curAction->additionalInfo) //nor if it's an object of attack
&& (curInt->curAction->destinationTile != stack->position) //nor if it's on destination tile for current action
)
)
@ -2514,7 +2514,7 @@ void CBattleInterface::endAction(const BattleAction* action)
// {
// activate();
// }
if(action->actionType == BattleAction::HERO_SPELL)
if(action->actionType == Battle::HERO_SPELL)
{
if(action->side)
defendingHero->setPhase(0);
@ -2522,12 +2522,12 @@ void CBattleInterface::endAction(const BattleAction* action)
attackingHero->setPhase(0);
}
if(stack && action->actionType == BattleAction::WALK &&
if(stack && action->actionType == Battle::WALK &&
creAnims[action->stackNumber]->getType() != CCreatureAnim::HOLDING) //walk or walk & attack
{
pendingAnims.push_back(std::make_pair(new CMovementEndAnimation(this, stack, action->destinationTile), false));
}
if(action->actionType == BattleAction::CATAPULT) //catapult
if(action->actionType == Battle::CATAPULT) //catapult
{
}
@ -2551,7 +2551,7 @@ void CBattleInterface::endAction(const BattleAction* action)
if(tacticsMode) //stack ended movement in tactics phase -> select the next one
bTacticNextStack(stack);
if( action->actionType == BattleAction::HERO_SPELL) //we have activated next stack after sending request that has been just realized -> blockmap due to movement has changed
if( action->actionType == Battle::HERO_SPELL) //we have activated next stack after sending request that has been just realized -> blockmap due to movement has changed
redrawBackgroundWithHexes(activeStack);
}
@ -2585,7 +2585,7 @@ void CBattleInterface::showQueue()
void CBattleInterface::startAction(const BattleAction* action)
{
if(action->actionType == BattleAction::END_TACTIC_PHASE)
if(action->actionType == Battle::END_TACTIC_PHASE)
{
SDL_FreeSurface(menu);
menu = BitmapHandler::loadBitmap("CBAR.bmp");
@ -2616,11 +2616,11 @@ void CBattleInterface::startAction(const BattleAction* action)
}
else
{
assert(action->actionType == BattleAction::HERO_SPELL); //only cast spell is valid action without acting stack number
assert(action->actionType == Battle::HERO_SPELL); //only cast spell is valid action without acting stack number
}
if(action->actionType == BattleAction::WALK
|| (action->actionType == BattleAction::WALK_AND_ATTACK && action->destinationTile != stack->position))
if(action->actionType == Battle::WALK
|| (action->actionType == Battle::WALK_AND_ATTACK && action->destinationTile != stack->position))
{
moveStarted = true;
if(creAnims[action->stackNumber]->framesInGroup(CCreatureAnim::MOVE_START))
@ -2635,7 +2635,7 @@ void CBattleInterface::startAction(const BattleAction* action)
char txt[400];
if (action->actionType == BattleAction::HERO_SPELL) //when hero casts spell
if (action->actionType == Battle::HERO_SPELL) //when hero casts spell
{
if(action->side)
defendingHero->setPhase(4);
@ -2652,10 +2652,10 @@ void CBattleInterface::startAction(const BattleAction* action)
int txtid = 0;
switch(action->actionType)
{
case BattleAction::WAIT:
case Battle::WAIT:
txtid = 136;
break;
case BattleAction::BAD_MORALE:
case Battle::BAD_MORALE:
txtid = -34; //negative -> no separate singular/plural form
displayEffect(30,stack->position);
break;
@ -2675,7 +2675,7 @@ void CBattleInterface::startAction(const BattleAction* action)
//displaying special abilities
switch (action->actionType)
{
case BattleAction::STACK_HEAL:
case Battle::STACK_HEAL:
displayEffect(74, action->destinationTile);
CCS->soundh->playSound(soundBase::REGENER);
break;
@ -3011,13 +3011,13 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
std::vector<BattleHex> acc = curInt->cb->battleGetAvailableHexes(activeStack, false);
int shiftedDest = myNumber + (activeStack->attackerOwned ? 1 : -1);
if(vstd::contains(acc, myNumber))
giveCommand (BattleAction::WALK ,myNumber, activeStack->ID);
giveCommand (Battle::WALK ,myNumber, activeStack->ID);
else if(vstd::contains(acc, shiftedDest))
giveCommand (BattleAction::WALK, shiftedDest, activeStack->ID);
giveCommand (Battle::WALK, shiftedDest, activeStack->ID);
}
else
{
giveCommand (BattleAction::WALK, myNumber, activeStack->ID);
giveCommand (Battle::WALK, myNumber, activeStack->ID);
}
};
break;
@ -3032,7 +3032,7 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
BattleHex attackFromHex = fromWhichHexAttack(myNumber);
if (attackFromHex >= 0) //we can be in this line when unreachable creature is L - clicked (as of revision 1308)
{
giveCommand(BattleAction::WALK_AND_ATTACK, attackFromHex, activeStack->ID, myNumber);
giveCommand(Battle::WALK_AND_ATTACK, attackFromHex, activeStack->ID, myNumber);
}
};
@ -3047,7 +3047,7 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
else
cursorFrame = ECursor::COMBAT_SHOOT;
realizeAction = [=] {giveCommand(BattleAction::SHOOT, myNumber, activeStack->ID);};
realizeAction = [=] {giveCommand(Battle::SHOOT, myNumber, activeStack->ID);};
std::string estDmgText = formatDmgRange(curInt->cb->battleEstimateDamage(sactive, shere)); //calculating estimated dmg
//printing - Shoot %s (%d shots left, %s damage)
consoleMsg = (boost::format(CGI->generaltexth->allTexts[296]) % shere->getName() % sactive->shots % estDmgText).str();
@ -3101,15 +3101,15 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
case HEAL:
cursorFrame = ECursor::COMBAT_HEAL;
consoleMsg = (boost::format(CGI->generaltexth->allTexts[419]) % shere->getName()).str(); //Apply first aid to the %s
realizeAction = [=]{ giveCommand(BattleAction::STACK_HEAL, myNumber, activeStack->ID); }; //command healing
realizeAction = [=]{ giveCommand(Battle::STACK_HEAL, myNumber, activeStack->ID); }; //command healing
break;
case RISE_DEMONS:
cursorType = ECursor::SPELLBOOK;
realizeAction = [=]{ giveCommand(BattleAction::DAEMON_SUMMONING, myNumber, activeStack->ID); };
realizeAction = [=]{ giveCommand(Battle::DAEMON_SUMMONING, myNumber, activeStack->ID); };
break;
case CATAPULT:
cursorFrame = ECursor::COMBAT_SHOOT_CATAPULT;
realizeAction = [=]{ giveCommand(BattleAction::CATAPULT, myNumber, activeStack->ID); };
realizeAction = [=]{ giveCommand(Battle::CATAPULT, myNumber, activeStack->ID); };
break;
case CREATURE_INFO:
{
@ -3194,11 +3194,11 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
{
if (sp)
{
giveCommand(BattleAction::MONSTER_SPELL, myNumber, sactive->ID, creatureSpellToCast);
giveCommand(Battle::MONSTER_SPELL, myNumber, sactive->ID, creatureSpellToCast);
}
else //unknown random spell
{
giveCommand(BattleAction::MONSTER_SPELL, myNumber, sactive->ID, curInt->cb->battleGetRandomStackSpell(shere, CBattleInfoCallback::RANDOM_GENIE));
giveCommand(Battle::MONSTER_SPELL, myNumber, sactive->ID, curInt->cb->battleGetRandomStackSpell(shere, CBattleInfoCallback::RANDOM_GENIE));
}
}
else

View File

@ -47,6 +47,7 @@ struct ProjectileInfo;
class CClickableHex;
struct BattleHex;
struct InfoAboutHero;
class BattleAction;
/// Class which manages the locked hex fields that are blocked e.g. by obstacles
class CBattleObstacle
@ -171,7 +172,7 @@ private:
std::list<ProjectileInfo> projectiles; //projectiles flying on battlefield
void projectileShowHelper(SDL_Surface * to); //prints projectiles present on the battlefield
void giveCommand(ui8 action, BattleHex tile, ui32 stackID, si32 additional=-1, si32 selectedStack = -1);
void giveCommand(Battle::ActionType action, BattleHex tile, ui32 stackID, si32 additional=-1, si32 selectedStack = -1);
bool isTileAttackable(const BattleHex & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles
bool isCatapultAttackable(BattleHex hex) const; //returns true if given tile can be attacked by catapult

View File

@ -1269,7 +1269,7 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
{
if(objAtTile)
{
if(objAtTile->ID == Obj::TOWN && LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, objAtTile->tempOwner))
if(objAtTile->ID == Obj::TOWN && LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, objAtTile->tempOwner) != PlayerRelations::ENEMIES)
CCS->curh->changeGraphic(ECursor::ADVENTURE, 3);
else if(objAtTile->ID == Obj::HERO && objAtTile->tempOwner == LOCPLINT->playerID)
CCS->curh->changeGraphic(ECursor::ADVENTURE, 2);

View File

@ -844,7 +844,7 @@ void CPlayerInterface::battleStacksAttacked(const std::vector<BattleStackAttacke
if (defender && !i->isSecondary())
battleInt->displayEffect(i->effect, defender->position);
}
bool shooting = (LOCPLINT->curAction ? LOCPLINT->curAction->actionType == BattleAction::SHOOT : false); //FIXME: why action is deleted during enchanter cast?
bool shooting = (LOCPLINT->curAction ? LOCPLINT->curAction->actionType == Battle::SHOOT : false); //FIXME: why action is deleted during enchanter cast?
StackAttackedInfo to_put = {defender, i->damageAmount, i->killedAmount, attacker, shooting, i->killed(), i->willRebirth(), i->cloneKilled()};
arg.push_back(to_put);
}

View File

@ -112,7 +112,7 @@ CClient::~CClient(void)
delete applier;
}
void CClient::waitForMoveAndSend(int color)
void CClient::waitForMoveAndSend(TPlayerColor color)
{
try
{
@ -362,7 +362,7 @@ void CClient::newGame( CConnection *con, StartInfo *si )
for(auto it = gs->scenarioOps->playerInfos.begin();
it != gs->scenarioOps->playerInfos.end(); ++it)//initializing interfaces for players
{
ui8 color = it->first;
TPlayerColor color = it->first;
gs->currentPlayer = color;
if(!vstd::contains(myPlayers, color))
continue;
@ -667,7 +667,7 @@ void CClient::invalidatePaths(const CGHeroInstance *h /*= NULL*/)
pathInfo->isValid = false;
}
int CClient::sendRequest(const CPack *request, int player)
int CClient::sendRequest(const CPack *request, TPlayerColor player)
{
static ui32 requestCounter = 0;

View File

@ -113,12 +113,12 @@ class CClient : public IGameCallback
{
public:
CCallback *cb;
std::map<ui8,shared_ptr<CCallback> > callbacks; //callbacks given to player interfaces
std::map<ui8,shared_ptr<CBattleCallback> > battleCallbacks; //callbacks given to player interfaces
std::map<TPlayerColor,shared_ptr<CCallback> > callbacks; //callbacks given to player interfaces
std::map<TPlayerColor,shared_ptr<CBattleCallback> > battleCallbacks; //callbacks given to player interfaces
std::vector<IGameEventsReceiver*> privilagedGameEventReceivers; //scripting modules, spectator interfaces
std::vector<IBattleEventsReceiver*> privilagedBattleEventReceivers; //scripting modules, spectator interfaces
std::map<ui8,CGameInterface *> playerint;
std::map<ui8,CBattleGameInterface *> battleints;
std::map<TPlayerColor,CGameInterface *> playerint;
std::map<TPlayerColor,CBattleGameInterface *> battleints;
bool hotSeat;
CConnection *serv;
BattleAction *curbaction;
@ -133,7 +133,7 @@ public:
std::queue<CPack *> packs;
boost::mutex packsM;
void waitForMoveAndSend(int color);
void waitForMoveAndSend(TPlayerColor color);
//void sendRequest(const CPackForServer *request, bool waitForRealization);
CClient(void);
CClient(CConnection *con, StartInfo *si);
@ -215,7 +215,7 @@ public:
friend class CBattleCallback; //handling players actions
friend void processCommand(const std::string &message, CClient *&client); //handling console
int sendRequest(const CPack *request, int player); //returns ID given to that request
int sendRequest(const CPack *request, TPlayerColor player); //returns ID given to that request
void handlePack( CPack * pack ); //applies the given pack and deletes it
void battleStarted(const BattleInfo * info);

View File

@ -160,7 +160,7 @@ void FoWChange::applyCl( CClient *cl )
{
BOOST_FOREACH(auto &i, cl->playerint)
if(cl->getPlayerRelations(i.first, player) > 0) //ally or the same player
if(cl->getPlayerRelations(i.first, player) != PlayerRelations::ENEMIES)
{
if(mode)
i.second->tileRevealed(tiles);
@ -376,7 +376,7 @@ void TryMoveHero::applyCl( CClient *cl )
int player = h->tempOwner;
BOOST_FOREACH(auto &i, cl->playerint)
if(cl->getPlayerRelations(i.first, player) > 0) //ally or the same player
if(cl->getPlayerRelations(i.first, player) != PlayerRelations::ENEMIES)
i.second->tileRevealed(fowRevealed);
//notify interfaces about move

View File

@ -45,7 +45,7 @@
{
"id" : 3,
"allowedTerrain" : [0, 5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 2,
"height" : 1,
"blockedTiles" : [0, 1],
@ -55,7 +55,7 @@
{
"id" : 4,
"allowedTerrain" : [0, 5, 6],
"specialBattlefields" : [0, 2],
"specialBattlefields" : [0, 1],
"width" : 2,
"height" : 1,
"blockedTiles" : [0, 1],
@ -135,7 +135,7 @@
{
"id" : 12,
"allowedTerrain" : [0, 5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 3,
"height" : 3,
"blockedTiles" : [0, 1, 2, 3],
@ -145,7 +145,7 @@
{
"id" : 13,
"allowedTerrain" : [0, 5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 3,
"height" : 2,
"blockedTiles" : [1, 2, -15],
@ -155,7 +155,7 @@
{
"id" : 14,
"allowedTerrain" : [0, 5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 3,
"height" : 2,
"blockedTiles" : [2, -15, -16],
@ -165,7 +165,7 @@
{
"id" : 15,
"allowedTerrain" : [0, 5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 3,
"height" : 3,
"blockedTiles" : [1, -16, -33],
@ -215,7 +215,7 @@
{
"id" : 20,
"allowedTerrain" : [2, 4],
"specialBattlefields" : [1],
"specialBattlefields" : [2],
"width" : 2,
"height" : 2,
"blockedTiles" : [0, 1],
@ -235,7 +235,7 @@
{
"id" : 22,
"allowedTerrain" : [2],
"specialBattlefields" : [1],
"specialBattlefields" : [2],
"width" : 6,
"height" : 2,
"blockedTiles" : [1, 2, 3, 4, -13, -14, -15, -16],
@ -415,7 +415,7 @@
{
"id" : 40,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 2,
"height" : 2,
"blockedTiles" : [0, 1, -16],
@ -425,7 +425,7 @@
{
"id" : 41,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 4,
"height" : 3,
"blockedTiles" : [-14, -15, -16, -32, -33],
@ -435,7 +435,7 @@
{
"id" : 42,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 3,
"height" : 2,
"blockedTiles" : [1, 2, -15, -16],
@ -445,7 +445,7 @@
{
"id" : 43,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 3,
"height" : 3,
"blockedTiles" : [-16, -32, -33],
@ -455,7 +455,7 @@
{
"id" : 44,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 3,
"height" : 3,
"blockedTiles" : [-15, -16, -32],
@ -1053,7 +1053,7 @@
{
"id" : 14,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 186,
"height" : 212,
"blockedTiles" : [55, 72, 90, 107, 125, 126, 127, 128, 129, 130, 131, 132],
@ -1062,7 +1062,7 @@
{
"id" : 15,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 347,
"height" : 174,
"blockedTiles" : [41, 59, 76, 94, 111, 129, 143, 144, 145],
@ -1071,7 +1071,7 @@
{
"id" : 16,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 294,
"height" : 169,
"blockedTiles" : [40, 41, 42, 43, 58, 75, 93, 110, 128, 145],
@ -1080,7 +1080,7 @@
{
"id" : 17,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 165,
"height" : 257,
"blockedTiles" : [72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 89, 105],
@ -1089,7 +1089,7 @@
{
"id" : 18,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 208,
"height" : 268,
"blockedTiles" : [72, 73, 74, 75, 76, 77, 78, 79, 80, 90, 91, 92, 93, 94, 95, 96, 97],
@ -1098,7 +1098,7 @@
{
"id" : 19,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 252,
"height" : 254,
"blockedTiles" : [73, 74, 75, 76, 77, 78, 91, 92, 93, 94],
@ -1107,7 +1107,7 @@
{
"id" : 20,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 278,
"height" : 128,
"blockedTiles" : [23, 40, 58, 75, 93, 110, 128, 145, 163],
@ -1116,7 +1116,7 @@
{
"id" : 21,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 208,
"height" : 268,
"blockedTiles" : [72, 73, 74, 75, 76, 77, 78, 79, 80, 90, 91, 92, 93, 94, 95, 96, 97],
@ -1125,7 +1125,7 @@
{
"id" : 22,
"allowedTerrain" : [5],
"specialBattlefields" : [2],
"specialBattlefields" : [1],
"width" : 168,
"height" : 212,
"blockedTiles" : [73, 74, 75, 76, 77, 78, 79, 90, 91, 92, 93, 94, 95, 96, 97, 106, 107, 108, 109, 110, 111, 112],

View File

@ -13,6 +13,8 @@
*
*/
using namespace Battle;
BattleAction::BattleAction()
{
side = -1;

View File

@ -20,12 +20,7 @@ struct DLL_LINKAGE BattleAction
{
ui8 side; //who made this action: false - left, true - right player
ui32 stackNumber;//stack ID, -1 left hero, -2 right hero,
enum ActionType
{
END_TACTIC_PHASE = -2, INVALID = -1, NO_ACTION = 0, HERO_SPELL, WALK, DEFEND, RETREAT, SURRENDER, WALK_AND_ATTACK, SHOOT, WAIT, CATAPULT, MONSTER_SPELL, BAD_MORALE,
STACK_HEAL, DAEMON_SUMMONING
};
si8 actionType; //use ActionType enum for values
Battle::ActionType actionType; //use ActionType enum for values
BattleHex destinationTile;
si32 additionalInfo; // e.g. spell number if type is 1 || 10; tile to attack if type is 6
si32 selectedStack; //spell subject for teleport / sacrifice

View File

@ -343,7 +343,7 @@ struct RangeGenerator
boost::function<int()> myRand;
};
BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int battlefieldType, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town )
BattleInfo * BattleInfo::setupBattle( int3 tile, ETerrainType::ETerrainType terrain, BFieldType::BFieldType battlefieldType, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town )
{
CMP_stack cmpst;
BattleInfo *curB = new BattleInfo;
@ -599,23 +599,23 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int battlefieldTyp
int bonusSubtype = -1;
switch(battlefieldType)
{
case 9: //magic plains
case BFieldType::MAGIC_PLAINS:
{
bonusSubtype = 0;
}
case 14: //fiery fields
case BFieldType::FIERY_FIELDS:
{
if(bonusSubtype == -1) bonusSubtype = 1;
}
case 15: //rock lands
case BFieldType::ROCKLANDS:
{
if(bonusSubtype == -1) bonusSubtype = 8;
}
case 16: //magic clouds
case BFieldType::MAGIC_CLOUDS:
{
if(bonusSubtype == -1) bonusSubtype = 2;
}
case 17: //lucid pools
case BFieldType::LUCID_POOLS:
{
if(bonusSubtype == -1) bonusSubtype = 4;
}
@ -625,24 +625,24 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int battlefieldTyp
break;
}
case 18: //holy ground
case BFieldType::HOLY_GROUND:
{
curB->addNewBonus(makeFeature(Bonus::MORALE, Bonus::ONE_BATTLE, 0, +1, Bonus::TERRAIN_OVERLAY)->addLimiter(make_shared<CreatureAlignmentLimiter>(EAlignment::GOOD)));
curB->addNewBonus(makeFeature(Bonus::MORALE, Bonus::ONE_BATTLE, 0, -1, Bonus::TERRAIN_OVERLAY)->addLimiter(make_shared<CreatureAlignmentLimiter>(EAlignment::EVIL)));
break;
}
case 19: //clover field
case BFieldType::CLOVER_FIELD:
{ //+2 luck bonus for neutral creatures
curB->addNewBonus(makeFeature(Bonus::LUCK, Bonus::ONE_BATTLE, 0, +2, Bonus::TERRAIN_OVERLAY)->addLimiter(make_shared<CreatureFactionLimiter>(-1)));
break;
}
case 20: //evil fog
case BFieldType::EVIL_FOG:
{
curB->addNewBonus(makeFeature(Bonus::MORALE, Bonus::ONE_BATTLE, 0, -1, Bonus::TERRAIN_OVERLAY)->addLimiter(make_shared<CreatureAlignmentLimiter>(EAlignment::GOOD)));
curB->addNewBonus(makeFeature(Bonus::MORALE, Bonus::ONE_BATTLE, 0, +1, Bonus::TERRAIN_OVERLAY)->addLimiter(make_shared<CreatureAlignmentLimiter>(EAlignment::EVIL)));
break;
}
case 22: //cursed ground
case BFieldType::CURSED_GROUND:
{
curB->addNewBonus(makeFeature(Bonus::NO_MORALE, Bonus::ONE_BATTLE, 0, 0, Bonus::TERRAIN_OVERLAY));
curB->addNewBonus(makeFeature(Bonus::NO_LUCK, Bonus::ONE_BATTLE, 0, 0, Bonus::TERRAIN_OVERLAY));
@ -705,7 +705,7 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int battlefieldTyp
return curB;
}
const CGHeroInstance * BattleInfo::getHero( int player ) const
const CGHeroInstance * BattleInfo::getHero( TPlayerColor player ) const
{
assert(sides[0] == player || sides[1] == player);
if(heroes[0] && heroes[0]->getOwner() == player)
@ -763,12 +763,12 @@ std::vector<ui32> BattleInfo::calculateResistedStacks(const CSpell * sp, const C
return ret;
}
int BattleInfo::theOtherPlayer(int player) const
TPlayerColor BattleInfo::theOtherPlayer(TPlayerColor player) const
{
return sides[!whatSide(player)];
}
ui8 BattleInfo::whatSide(int player) const
ui8 BattleInfo::whatSide(TPlayerColor player) const
{
for(int i = 0; i < ARRAY_COUNT(sides); i++)
if(sides[i] == player)
@ -801,13 +801,20 @@ shared_ptr<CObstacleInstance> BattleInfo::getObstacleOnTile(BattleHex tile) cons
return shared_ptr<CObstacleInstance>();
}
int BattleInfo::battlefieldTypeToBI(int bfieldType)
BattlefieldBI::BattlefieldBI BattleInfo::battlefieldTypeToBI(BFieldType::BFieldType bfieldType)
{
static const std::map<int, int> theMap = boost::assign::map_list_of(19, BattlefieldBI::CLOVER_FIELD)
(22, BattlefieldBI::CURSED_GROUND)(20, BattlefieldBI::EVIL_FOG)(21, BattlefieldBI::NONE)
(14, BattlefieldBI::FIERY_FIELDS)(18, BattlefieldBI::HOLY_GROUND)(17, BattlefieldBI::LUCID_POOLS)
(16, BattlefieldBI::MAGIC_CLOUDS)(9, BattlefieldBI::MAGIC_PLAINS)(15, BattlefieldBI::ROCKLANDS)
(1, BattlefieldBI::COASTAL);
static const std::map<BFieldType::BFieldType, BattlefieldBI::BattlefieldBI> theMap = boost::assign::map_list_of
(BFieldType::CLOVER_FIELD, BattlefieldBI::CLOVER_FIELD)
(BFieldType::CURSED_GROUND, BattlefieldBI::CURSED_GROUND)
(BFieldType::EVIL_FOG, BattlefieldBI::EVIL_FOG)
(BFieldType::FAVOURABLE_WINDS, BattlefieldBI::NONE)
(BFieldType::FIERY_FIELDS, BattlefieldBI::FIERY_FIELDS)
(BFieldType::HOLY_GROUND, BattlefieldBI::HOLY_GROUND)
(BFieldType::LUCID_POOLS, BattlefieldBI::LUCID_POOLS)
(BFieldType::MAGIC_CLOUDS, BattlefieldBI::MAGIC_CLOUDS)
(BFieldType::MAGIC_PLAINS, BattlefieldBI::MAGIC_PLAINS)
(BFieldType::ROCKLANDS, BattlefieldBI::ROCKLANDS)
(BFieldType::SAND_SHORE, BattlefieldBI::COASTAL);
auto itr = theMap.find(bfieldType);
if(itr != theMap.end())

View File

@ -45,7 +45,7 @@ struct DLL_LINKAGE SiegeInfo
struct DLL_LINKAGE BattleInfo : public CBonusSystemNode, public CBattleInfoCallback
{
ui8 sides[2]; //sides[0] - attacker, sides[1] - defender
TPlayerColor sides[2]; //sides[0] - attacker, sides[1] - defender
si32 round, activeStack, selectedStack;
CGTownInstance::EFortLevel siege;
const CGTownInstance * town; //used during town siege - id of attacked town; -1 if not town defence
@ -59,8 +59,8 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode, public CBattleInfoCallb
si16 enchanterCounter[2]; //tends to pass through 0, so sign is needed
SiegeInfo si;
si32 battlefieldType; //like !!BA:B
int terrainType; //used for some stack nativity checks (not the bonus limiters though that have their own copy)
BFieldType::BFieldType battlefieldType; //like !!BA:B
ETerrainType::ETerrainType terrainType; //used for some stack nativity checks (not the bonus limiters though that have their own copy)
ui8 tacticsSide; //which side is requested to play tactics phase
ui8 tacticDistance; //how many hexes we can go forward (1 = only hexes adjacent to margin line)
@ -115,7 +115,7 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode, public CBattleInfoCallb
ui32 calculateHealedHP(const CSpell * spell, int usedSpellPower, int spellSchoolLevel, const CStack * stack) const; //unused
bool resurrects(TSpell spellid) const; //TODO: move it to spellHandler?
const CGHeroInstance * getHero(int player) const; //returns fighting hero that belongs to given player
const CGHeroInstance * getHero(TPlayerColor player) const; //returns fighting hero that belongs to given player
std::vector<ui32> calculateResistedStacks(const CSpell * sp, const CGHeroInstance * caster, const CGHeroInstance * hero2, const std::set<const CStack*> affectedCreatures, int casterSideOwner, ECastingMode::ECastingMode mode, int usedSpellPower, int spellLevel) const;
@ -125,13 +125,13 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode, public CBattleInfoCallb
void localInit();
void localInitStack(CStack * s);
static BattleInfo * setupBattle( int3 tile, int terrain, int battlefieldType, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town );
static BattleInfo * setupBattle( int3 tile, ETerrainType::ETerrainType terrain, BFieldType::BFieldType battlefieldType, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town );
//bool hasNativeStack(ui8 side) const;
int theOtherPlayer(int player) const;
ui8 whatSide(int player) const;
TPlayerColor theOtherPlayer(TPlayerColor player) const;
ui8 whatSide(TPlayerColor player) const;
static int battlefieldTypeToBI(int bfieldType); //converts above to ERM BI format
static BattlefieldBI::BattlefieldBI battlefieldTypeToBI(BFieldType::BFieldType bfieldType); //converts above to ERM BI format
static int battlefieldTypeToTerrain(int bfieldType); //converts above to ERM BI format
};
@ -143,8 +143,9 @@ public:
ui32 ID; //unique ID of stack
ui32 baseAmount;
ui32 firstHPleft; //HP of first creature in stack
ui8 owner, slot; //owner - player colour (255 for neutrals), slot - position in garrison (may be 255 for neutrals/called creatures)
ui8 attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle)
TPlayerColor owner;
ui8 slot; //owner - player colour (255 for neutrals), slot - position in garrison (may be 255 for neutrals/called creatures)
bool attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle)
BattleHex position; //position on battlefield; -2 - keep, -3 - lower tower, -4 - upper tower
ui8 counterAttacks; //how many counter attacks can be performed more in this turn (by default set at the beginning of the round to 1)
si16 shots; //how many shots left

View File

@ -124,15 +124,15 @@ int CCallbackBase::getPlayerID() const
return player;
}
ui8 CBattleInfoEssentials::battleTerrainType() const
ETerrainType::ETerrainType CBattleInfoEssentials::battleTerrainType() const
{
RETURN_IF_NOT_BATTLE(-1);
RETURN_IF_NOT_BATTLE(ETerrainType::WRONG);
return getBattle()->terrainType;
}
int CBattleInfoEssentials::battleGetBattlefieldType() const
BFieldType::BFieldType CBattleInfoEssentials::battleGetBattlefieldType() const
{
RETURN_IF_NOT_BATTLE(-1);
RETURN_IF_NOT_BATTLE(BFieldType::NONE);
return getBattle()->battlefieldType;
}
@ -347,7 +347,7 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(int
return ESpellCastProblem::OK;
}
bool CBattleInfoEssentials::battleCanFlee(int player) const
bool CBattleInfoEssentials::battleCanFlee(TPlayerColor player) const
{
RETURN_IF_NOT_BATTLE(false);
ui8 mySide = playerToSide(player);
@ -372,7 +372,7 @@ bool CBattleInfoEssentials::battleCanFlee(int player) const
return true;
}
ui8 CBattleInfoEssentials::playerToSide(int player) const
ui8 CBattleInfoEssentials::playerToSide(TPlayerColor player) const
{
RETURN_IF_NOT_BATTLE(-1);
int ret = vstd::find_pos(getBattle()->sides, player);
@ -388,7 +388,7 @@ ui8 CBattleInfoEssentials::battleGetSiegeLevel() const
return getBattle()->siege;
}
bool CBattleInfoEssentials::battleCanSurrender(int player) const
bool CBattleInfoEssentials::battleCanSurrender(TPlayerColor player) const
{
RETURN_IF_NOT_BATTLE(false);
//conditions like for fleeing + enemy must have a hero
@ -2148,7 +2148,7 @@ TSpell CBattleInfoCallback::getRandomCastedSpell(const CStack * caster) const
return -1;
}
int CBattleInfoCallback::battleGetSurrenderCost(int Player) const
int CBattleInfoCallback::battleGetSurrenderCost(TPlayerColor Player) const
{
RETURN_IF_NOT_BATTLE(-3);
if(!battleCanSurrender(Player))

View File

@ -164,8 +164,8 @@ public:
BattlePerspective::BattlePerspective battleGetMySide() const;
ui8 battleTerrainType() const;
int battleGetBattlefieldType() const; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
ETerrainType::ETerrainType battleTerrainType() const;
BFieldType::BFieldType battleGetBattlefieldType() const;
std::vector<shared_ptr<const CObstacleInstance> > battleGetAllObstacles(boost::optional<BattlePerspective::BattlePerspective> perspective = boost::none) const; //returns all obstacles on the battlefield
TStacks battleGetAllStacks() const; //returns all stacks, alive or dead or undead or mechanical :)
bool battleHasNativeStack(ui8 side) const;
@ -175,9 +175,9 @@ public:
const CStack *battleActiveStack() const;
si8 battleTacticDist() const; //returns tactic distance in current tactics phase; 0 if not in tactics phase
si8 battleGetTacticsSide() const; //returns which side is in tactics phase, undefined if none (?)
bool battleCanFlee(int player) const;
bool battleCanSurrender(int player) const;
ui8 playerToSide(int player) const;
bool battleCanFlee(TPlayerColor player) const;
bool battleCanSurrender(TPlayerColor player) const;
ui8 playerToSide(TPlayerColor player) const;
ui8 battleGetSiegeLevel() const; //returns 0 when there is no siege, 1 if fort, 2 is citadel, 3 is castle
bool battleHasHero(ui8 side) const;
int battleCastSpells(ui8 side) const; //how many spells has given side casted
@ -227,7 +227,7 @@ public:
std::vector<BattleHex> battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector<BattleHex> * attackable = NULL) const; //returns hexes reachable by creature with id ID (valid movement destinations), DOES contain stack current position
int battleGetSurrenderCost(int Player) const; //returns cost of surrendering battle, -1 if surrendering is not possible
int battleGetSurrenderCost(TPlayerColor Player) const; //returns cost of surrendering battle, -1 if surrendering is not possible
ReachabilityInfo::TDistances battleGetDistances(const CStack * stack, BattleHex hex = BattleHex::INVALID, BattleHex * predecessors = NULL) const; //returns vector of distances to [dest hex number]
std::set<BattleHex> battleGetAttackedHexes(const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos = BattleHex::INVALID) const;
bool battleCanShoot(const CStack * stack, BattleHex dest) const; //determines if stack with given ID shoot at the selected destination

View File

@ -113,7 +113,7 @@ CScriptingModule * CDynLibHandler::getNewScriptingModule(std::string dllname)
BattleAction CGlobalAI::activeStack( const CStack * stack )
{
BattleAction ba; ba.actionType = BattleAction::DEFEND;
BattleAction ba; ba.actionType = Battle::DEFEND;
ba.stackNumber = stack->ID;
return ba;
}

View File

@ -773,11 +773,11 @@ CGameState::~CGameState()
BattleInfo * CGameState::setupBattle(int3 tile, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town)
{
const TerrainTile &t = map->getTile(tile);
int terrain = t.terType;
ETerrainType::ETerrainType terrain = t.terType;
if(t.isCoastal() && !t.isWater())
terrain = ETerrainType::SAND;
int terType = battleGetBattlefieldType(tile);
BFieldType::BFieldType terType = battleGetBattlefieldType(tile);
return BattleInfo::setupBattle(tile, terrain, terType, armies, heroes, creatureBank, town);
}
@ -1679,23 +1679,23 @@ void CGameState::initDuel()
}
}
curB = BattleInfo::setupBattle(int3(), dp.bfieldType, dp.terType, armies, heroes, false, town);
curB = BattleInfo::setupBattle(int3(), dp.terType, dp.bfieldType, armies, heroes, false, town);
curB->obstacles = dp.obstacles;
curB->localInit();
return;
}
int CGameState::battleGetBattlefieldType(int3 tile) const
BFieldType::BFieldType CGameState::battleGetBattlefieldType(int3 tile) const
{
if(tile==int3() && curB)
tile = curB->tile;
else if(tile==int3() && !curB)
return -1;
return BFieldType::NONE;
const TerrainTile &t = map->getTile(tile);
//fight in mine -> subterranean
if(dynamic_cast<const CGMine *>(t.visitableObjects.front()))
return 12;
return BFieldType::SUBTERRANEAN;
BOOST_FOREACH(auto &obj, map->objects)
{
@ -1707,55 +1707,55 @@ int CGameState::battleGetBattlefieldType(int3 tile) const
switch(obj->ID)
{
case Obj::CLOVER_FIELD:
return 19;
return BFieldType::CLOVER_FIELD;
case Obj::CURSED_GROUND1: case Obj::CURSED_GROUND2:
return 22;
return BFieldType::CURSED_GROUND;
case Obj::EVIL_FOG:
return 20;
return BFieldType::EVIL_FOG;
case Obj::FAVORABLE_WINDS:
return 21;
return BFieldType::FAVOURABLE_WINDS;
case Obj::FIERY_FIELDS:
return 14;
return BFieldType::FIERY_FIELDS;
case Obj::HOLY_GROUNDS:
return 18;
return BFieldType::HOLY_GROUND;
case Obj::LUCID_POOLS:
return 17;
return BFieldType::LUCID_POOLS;
case Obj::MAGIC_CLOUDS:
return 16;
return BFieldType::MAGIC_CLOUDS;
case Obj::MAGIC_PLAINS1: case Obj::MAGIC_PLAINS2:
return 9;
return BFieldType::MAGIC_PLAINS;
case Obj::ROCKLANDS:
return 15;
return BFieldType::ROCKLANDS;
}
}
if(!t.isWater() && t.isCoastal())
return 1; //sand/beach
return BFieldType::SAND_SHORE;
switch(t.terType)
{
case ETerrainType::DIRT:
return rand()%3+3;
return static_cast<BFieldType::BFieldType>(rand()%3+3);
case ETerrainType::SAND:
return 2; //TODO: coast support
return BFieldType::SAND_MESAS; //TODO: coast support
case ETerrainType::GRASS:
return rand()%2+6;
return static_cast<BFieldType::BFieldType>(rand()%2+6);
case ETerrainType::SNOW:
return rand()%2+10;
return static_cast<BFieldType::BFieldType>(rand()%2+10);
case ETerrainType::SWAMP:
return 13;
return BFieldType::SWAMP_TREES;
case ETerrainType::ROUGH:
return 23;
return BFieldType::ROUGH;
case ETerrainType::SUBTERRANEAN:
return 12;
return BFieldType::SUBTERRANEAN;
case ETerrainType::LAVA:
return 8;
return BFieldType::LAVA;
case ETerrainType::WATER:
return 25;
return BFieldType::SHIP;
case ETerrainType::ROCK:
return 15;
return BFieldType::ROCKLANDS;
default:
return -1;
return BFieldType::NONE;
}
}
@ -1820,17 +1820,17 @@ UpgradeInfo CGameState::getUpgradeInfo(const CStackInstance &stack)
return ret;
}
int CGameState::getPlayerRelations( ui8 color1, ui8 color2 )
PlayerRelations::PlayerRelations CGameState::getPlayerRelations( TPlayerColor color1, TPlayerColor color2 )
{
if ( color1 == color2 )
return 2;
if(color1 == 255 || color2 == 255) //neutral player has no friends
return 0;
return PlayerRelations::SAME_PLAYER;
if(color1 == GameConstants::NEUTRAL_PLAYER || color2 == GameConstants::NEUTRAL_PLAYER) //neutral player has no friends
return PlayerRelations::ENEMIES;
const TeamState * ts = getPlayerTeam(color1);
if (ts && vstd::contains(ts->players, color2))
return 1;
return 0;
return PlayerRelations::ALLIES;
return PlayerRelations::ENEMIES;
}
void CGameState::getNeighbours(const TerrainTile &srct, int3 tile, std::vector<int3> &vec, const boost::logic::tribool &onLand, bool limitCoastSailing)
@ -2293,7 +2293,7 @@ ui8 CGameState::checkForStandardWin() const
return supposedWinner;
}
bool CGameState::checkForStandardLoss( ui8 player ) const
bool CGameState::checkForStandardLoss( TPlayerColor player ) const
{
//std loss condition is: player lost all towns and heroes
const PlayerState &p = *CGameInfoCallback::getPlayer(player);
@ -2496,7 +2496,7 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
#undef FILL_FIELD
}
int CGameState::lossCheck( ui8 player ) const
int CGameState::lossCheck( TPlayerColor player ) const
{
const PlayerState *p = CGameInfoCallback::getPlayer(player);
//if(map->lossCondition.typeOfLossCon == lossStandard)
@ -2900,7 +2900,7 @@ DuelParameters::SideSettings::SideSettings()
DuelParameters::DuelParameters()
{
terType = ETerrainType::DIRT;
bfieldType = 15;
bfieldType = BFieldType::ROCKLANDS;
}
DuelParameters DuelParameters::fromJSON(const std::string &fname)
@ -2908,8 +2908,8 @@ DuelParameters DuelParameters::fromJSON(const std::string &fname)
DuelParameters ret;
const JsonNode duelData(ResourceID("DATA/" + fname, EResType::TEXT));
ret.terType = duelData["terType"].Float();
ret.bfieldType = duelData["bfieldType"].Float();
ret.terType = static_cast<ETerrainType::ETerrainType>((int)duelData["terType"].Float());
ret.bfieldType = static_cast<BFieldType::BFieldType>((int)duelData["bfieldType"].Float());
BOOST_FOREACH(const JsonNode &n, duelData["sides"].Vector())
{
SideSettings &ss = ret.sides[(int)n["side"].Float()];

View File

@ -286,7 +286,8 @@ struct DLL_LINKAGE CPathsInfo
struct DLL_EXPORT DuelParameters
{
si32 terType, bfieldType;
ETerrainType::ETerrainType terType;
BFieldType::BFieldType bfieldType;
struct DLL_EXPORT SideSettings
{
struct DLL_EXPORT StackSettings
@ -415,19 +416,19 @@ public:
void giveHeroArtifact(CGHeroInstance *h, int aid);
void apply(CPack *pack);
int battleGetBattlefieldType(int3 tile) const;// 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
BFieldType::BFieldType battleGetBattlefieldType(int3 tile) const;
UpgradeInfo getUpgradeInfo(const CStackInstance &stack);
int getPlayerRelations(ui8 color1, ui8 color2);// 0 = enemy, 1 = ally, 2 = same player
PlayerRelations::PlayerRelations getPlayerRelations(TPlayerColor color1, TPlayerColor color2);
bool checkForVisitableDir(const int3 & src, const int3 & dst) const; //check if src tile is visitable from dst tile
bool checkForVisitableDir(const int3 & src, const TerrainTile *pom, const int3 & dst) const; //check if src tile is visitable from dst tile
bool getPath(int3 src, int3 dest, const CGHeroInstance * hero, CPath &ret); //calculates path between src and dest; returns pointer to newly allocated CPath or NULL if path does not exists
void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int3 src = int3(-1,-1,-1), int movement = -1); //calculates possible paths for hero, by default uses current hero position and movement left; returns pointer to newly allocated CPath or NULL if path does not exists
int3 guardingCreaturePosition (int3 pos) const;
std::vector<CGObjectInstance*> guardingCreatures (int3 pos) const;
int victoryCheck(ui8 player) const; //checks if given player is winner; -1 if std victory, 1 if special victory, 0 else
int lossCheck(ui8 player) const; //checks if given player is loser; -1 if std loss, 1 if special, 0 else
int victoryCheck(TPlayerColor player) const; //checks if given player is winner; -1 if std victory, 1 if special victory, 0 else
int lossCheck(TPlayerColor player) const; //checks if given player is loser; -1 if std loss, 1 if special, 0 else
ui8 checkForStandardWin() const; //returns color of player that accomplished standard victory conditions or 255 if no winner
bool checkForStandardLoss(ui8 player) const; //checks if given player lost the game
bool checkForStandardLoss(TPlayerColor player) const; //checks if given player lost the game
void obtainPlayersStats(SThievesGuildInfo & tgi, int level); //fills tgi with info about other players that is available at given level of thieves' guild
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns
BattleInfo * setupBattle(int3 tile, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town);

View File

@ -70,7 +70,7 @@ std::vector<BattleHex> CObstacleInfo::getBlocked(BattleHex hex) const
return ret;
}
bool CObstacleInfo::isAppropriate(int terrainType, int specialBattlefield /*= -1*/) const
bool CObstacleInfo::isAppropriate(ETerrainType::ETerrainType terrainType, int specialBattlefield /*= -1*/) const
{
if(specialBattlefield != -1)
return vstd::contains(allowedSpecialBfields, specialBattlefield);
@ -366,8 +366,8 @@ void CHeroHandler::loadObstacles()
obi.defName = obs["defname"].String();
obi.width = obs["width"].Float();
obi.height = obs["height"].Float();
obi.allowedTerrains = obs["allowedTerrain"].convertTo<std::vector<ui8> >();
obi.allowedSpecialBfields = obs["specialBattlefields"].convertTo<std::vector<ui8> >();
obi.allowedTerrains = obs["allowedTerrain"].convertTo<std::vector<ETerrainType::ETerrainType> >();
obi.allowedSpecialBfields = obs["specialBattlefields"].convertTo<std::vector<BFieldType::BFieldType> >();
obi.blockedTiles = obs["blockedTiles"].convertTo<std::vector<si16> >();
obi.isAbsoluteObstacle = absolute;
}

View File

@ -131,8 +131,8 @@ struct DLL_LINKAGE CObstacleInfo
{
si32 ID;
std::string defName;
std::vector<ui8> allowedTerrains;
std::vector<ui8> allowedSpecialBfields;
std::vector<ETerrainType::ETerrainType> allowedTerrains;
std::vector<BFieldType::BFieldType> allowedSpecialBfields;
ui8 isAbsoluteObstacle; //there may only one such obstacle in battle and its position is always the same
si32 width, height; //how much space to the right and up is needed to place obstacle (affects only placement algorithm)
@ -140,7 +140,7 @@ struct DLL_LINKAGE CObstacleInfo
std::vector<BattleHex> getBlocked(BattleHex hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex'
bool isAppropriate(int terrainType, int specialBattlefield = -1) const;
bool isAppropriate(ETerrainType::ETerrainType terrainType, int specialBattlefield = -1) const;
template <typename Handler> void serialize(Handler &h, const int version)
{

View File

@ -525,7 +525,8 @@ void CTownHandler::load(const JsonNode &source)
faction.creatureBg120 = node.second["creatureBackground"]["120px"].String();
faction.creatureBg130 = node.second["creatureBackground"]["130px"].String();
faction.nativeTerrain = vstd::find_pos(GameConstants::TERRAIN_NAMES, node.second["nativeTerrain"].String());
faction.nativeTerrain = static_cast<ETerrainType::ETerrainType>(vstd::find_pos(GameConstants::TERRAIN_NAMES,
node.second["nativeTerrain"].String()));
int alignment = vstd::find_pos(EAlignment::names, node.second["alignment"].String());
if (alignment == -1)
faction.alignment = EAlignment::NEUTRAL;

View File

@ -173,7 +173,7 @@ public:
TFaction factionID;
ui8 nativeTerrain;
ETerrainType::ETerrainType nativeTerrain;
EAlignment::EAlignment alignment;
TCreature commander;

View File

@ -242,7 +242,7 @@ CPack * CConnection::retreivePack()
return ret;
}
void CConnection::sendPackToServer(const CPack &pack, ui8 player, ui32 requestID)
void CConnection::sendPackToServer(const CPack &pack, TPlayerColor player, ui32 requestID)
{
boost::unique_lock<boost::mutex> lock(*wmx);
tlog5 << "Sending to server a pack of type " << typeid(pack).name() << std::endl;

View File

@ -1172,7 +1172,7 @@ public:
virtual ~CConnection(void);
CPack *retreivePack(); //gets from server next pack (allocates it with new)
void sendPackToServer(const CPack &pack, ui8 player, ui32 requestID);
void sendPackToServer(const CPack &pack, TPlayerColor player, ui32 requestID);
void disableStackSendingByID();
void enableStackSendingByID();

View File

@ -401,17 +401,16 @@ namespace SecSkillLevel
};
}
//follows ERM BI (battle image) format
namespace BattlefieldBI
{
enum
enum BattlefieldBI
{
NONE = -1,
COASTAL,
//Discrepency from ERM BI description - we have magic plains and cursed gronds swapped
MAGIC_PLAINS,
CURSED_GROUND,
//
MAGIC_PLAINS,
HOLY_GROUND,
EVIL_FOG,
CLOVER_FIELD,
@ -434,6 +433,44 @@ namespace Date
};
}
namespace Battle
{
enum ActionType
{
END_TACTIC_PHASE = -2, INVALID = -1, NO_ACTION = 0, HERO_SPELL, WALK, DEFEND, RETREAT, SURRENDER, WALK_AND_ATTACK, SHOOT, WAIT, CATAPULT, MONSTER_SPELL, BAD_MORALE,
STACK_HEAL, DAEMON_SUMMONING
};
}
namespace ETerrainType
{
enum ETerrainType
{
WRONG = -2, BORDER = -1, DIRT, SAND, GRASS, SNOW, SWAMP,
ROUGH, SUBTERRANEAN, LAVA, WATER, ROCK
};
}
namespace BFieldType
{
// 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines
//8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields
//15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog
//21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
enum BFieldType {NONE = -1, NONE2, SAND_SHORE, SAND_MESAS, DIRT_BIRCHES, DIRT_HILLS, DIRT_PINES, GRASS_HILLS,
GRASS_PINES, LAVA, MAGIC_PLAINS, SNOW_MOUNTAINS, SNOW_TREES, SUBTERRANEAN, SWAMP_TREES, FIERY_FIELDS,
ROCKLANDS, MAGIC_CLOUDS, LUCID_POOLS, HOLY_GROUND, CLOVER_FIELD, EVIL_FOG, FAVOURABLE_WINDS, CURSED_GROUND,
ROUGH, SHIP_TO_SHIP, SHIP
};
}
namespace PlayerRelations
{
enum PlayerRelations {ENEMIES, ALLIES, SAME_PLAYER};
}
// Typedef declarations
typedef si8 TFaction;
typedef si64 TExpType;

View File

@ -651,14 +651,14 @@ const CMapHeader * CGameInfoCallback::getMapHeader() const
bool CGameInfoCallback::hasAccess(int playerId) const
{
return player < 0 || gs->getPlayerRelations( playerId, player );
return player < 0 || gs->getPlayerRelations( playerId, player ) != PlayerRelations::ENEMIES;
}
int CGameInfoCallback::getPlayerStatus(int player) const
{
const PlayerState *ps = gs->getPlayer(player, false);
if(!ps)
return -1;
ERROR_RET_VAL_IF(!ps, "No such player!", -1);
return ps->status;
}
@ -667,7 +667,7 @@ std::string CGameInfoCallback::getTavernGossip(const CGObjectInstance * townOrTa
return "GOSSIP TEST";
}
int CGameInfoCallback::getPlayerRelations( ui8 color1, ui8 color2 ) const
PlayerRelations::PlayerRelations CGameInfoCallback::getPlayerRelations( TPlayerColor color1, TPlayerColor color2 ) const
{
return gs->getPlayerRelations(color1, color2);
}

View File

@ -83,7 +83,7 @@ public:
const PlayerState * getPlayer(int color, bool verbose = true) const;
int getResource(int Player, int which) const;
bool isVisible(int3 pos) const;
int getPlayerRelations(ui8 color1, ui8 color2) const;// 0 = enemy, 1 = ally, 2 = same player
PlayerRelations::PlayerRelations getPlayerRelations(TPlayerColor color1, TPlayerColor color2) const;
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
int getCurrentPlayer() const; //player that currently makes move // TODO synchronous turns

View File

@ -151,14 +151,37 @@ namespace JsonUtils
namespace JsonDetail
{
// convertion helpers for JsonNode::convertTo (partial template function instantiation is illegal in c++)
template <typename T, int arithm>
struct JsonConvImpl;
template <typename T>
struct JsonConvImpl<T, 0>
{
static T convertImpl(const JsonNode & node)
{
return (T)(int)node.Float();
}
};
template <typename T>
struct JsonConvImpl<T, 1>
{
static T convertImpl(const JsonNode & node)
{
return node.Float();
}
};
template<typename Type>
struct JsonConverter
{
static Type convert(const JsonNode & node)
{
///this should be triggered only for numeric types
static_assert(std::is_arithmetic<Type>::value, "Unsupported type for JsonNode::convertTo()!");
return node.Float();
///this should be triggered only for numeric types and enums
static_assert(boost::mpl::or_<std::is_arithmetic<Type>, std::is_enum<Type> >::value, "Unsupported type for JsonNode::convertTo()!");
return JsonConvImpl<Type, std::is_arithmetic<Type>::value>::convertImpl(node);
}
};

View File

@ -380,15 +380,6 @@ public:
}
};
namespace ETerrainType
{
enum ETerrainType
{
BORDER = -1, DIRT, SAND, GRASS, SNOW, SWAMP,
ROUGH, SUBTERRANEAN, LAVA, WATER, ROCK
};
}
namespace ERiverType
{
enum ERiverType

View File

@ -1180,7 +1180,7 @@ DLL_LINKAGE void StartAction::applyGs( CGameState *gs )
{
CStack *st = gs->curB->getStack(ba.stackNumber);
if(ba.actionType == BattleAction::END_TACTIC_PHASE)
if(ba.actionType == Battle::END_TACTIC_PHASE)
{
gs->curB->tacticDistance = 0;
return;
@ -1193,7 +1193,7 @@ DLL_LINKAGE void StartAction::applyGs( CGameState *gs )
return;
}
if(ba.actionType != BattleAction::HERO_SPELL) //don't check for stack if it's custom action by hero
if(ba.actionType != Battle::HERO_SPELL) //don't check for stack if it's custom action by hero
{
assert(st);
}
@ -1204,13 +1204,13 @@ DLL_LINKAGE void StartAction::applyGs( CGameState *gs )
switch(ba.actionType)
{
case BattleAction::DEFEND:
case Battle::DEFEND:
st->state.insert(EBattleStackState::DEFENDING);
break;
case BattleAction::WAIT:
case Battle::WAIT:
st->state.insert(EBattleStackState::WAITING);
return;
case BattleAction::HERO_SPELL: //no change in current stack state
case Battle::HERO_SPELL: //no change in current stack state
return;
default: //any active stack action - attack, catapult, heal, spell...
st->state.insert(EBattleStackState::MOVED);

View File

@ -3253,15 +3253,15 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
switch(ba.actionType)
{
case BattleAction::WALK: //walk
case BattleAction::DEFEND: //defend
case BattleAction::WAIT: //wait
case BattleAction::WALK_AND_ATTACK: //walk or attack
case BattleAction::SHOOT: //shoot
case BattleAction::CATAPULT: //catapult
case BattleAction::STACK_HEAL: //healing with First Aid Tent
case BattleAction::DAEMON_SUMMONING:
case BattleAction::MONSTER_SPELL:
case Battle::WALK: //walk
case Battle::DEFEND: //defend
case Battle::WAIT: //wait
case Battle::WALK_AND_ATTACK: //walk or attack
case Battle::SHOOT: //shoot
case Battle::CATAPULT: //catapult
case Battle::STACK_HEAL: //healing with First Aid Tent
case Battle::DAEMON_SUMMONING:
case Battle::MONSTER_SPELL:
if(!stack)
{
@ -3292,16 +3292,16 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
switch(ba.actionType)
{
case BattleAction::END_TACTIC_PHASE: //wait
case BattleAction::BAD_MORALE:
case BattleAction::NO_ACTION:
case Battle::END_TACTIC_PHASE: //wait
case Battle::BAD_MORALE:
case Battle::NO_ACTION:
{
StartAction start_action(ba);
sendAndApply(&start_action);
sendAndApply(&end_action);
break;
}
case BattleAction::WALK: //walk
case Battle::WALK:
{
StartAction start_action(ba);
sendAndApply(&start_action); //start movement
@ -3312,7 +3312,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
sendAndApply(&end_action);
break;
}
case BattleAction::DEFEND: //defend
case Battle::DEFEND:
{
//defensive stance //TODO: remove this bonus when stack becomes active
SetStackEffect sse;
@ -3324,14 +3324,14 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
//don't break - we share code with next case
}
case BattleAction::WAIT: //wait
case Battle::WAIT:
{
StartAction start_action(ba);
sendAndApply(&start_action);
sendAndApply(&end_action);
break;
}
case BattleAction::RETREAT: //retreat/flee
case Battle::RETREAT: //retreat/flee
{
if(!gs->curB->battleCanFlee(gs->curB->sides[ba.side]))
complain("Cannot retreat!");
@ -3339,7 +3339,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
setBattleResult(1, !ba.side); //surrendering side loses
break;
}
case BattleAction::SURRENDER:
case Battle::SURRENDER:
{
int player = gs->curB->sides[ba.side];
int cost = gs->curB->battleGetSurrenderCost(player);
@ -3355,7 +3355,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
break;
}
break;
case BattleAction::WALK_AND_ATTACK: //walk or attack
case Battle::WALK_AND_ATTACK: //walk or attack
{
StartAction start_action(ba);
sendAndApply(&start_action); //start movement and attack
@ -3451,7 +3451,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
sendAndApply(&end_action);
break;
}
case BattleAction::SHOOT: //shoot
case Battle::SHOOT:
{
const CStack *destStack= gs->curB->battleGetStackByPos(ba.destinationTile);
if( !gs->curB->battleCanShoot(stack, ba.destinationTile) )
@ -3497,7 +3497,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
sendAndApply(&end_action);
break;
}
case BattleAction::CATAPULT: //catapult
case Battle::CATAPULT:
{
StartAction start_action(ba);
sendAndApply(&start_action);
@ -3600,7 +3600,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
sendAndApply(&end_action);
break;
}
case BattleAction::STACK_HEAL: //healing with First Aid Tent
case Battle::STACK_HEAL: //healing with First Aid Tent
{
StartAction start_action(ba);
sendAndApply(&start_action);
@ -3641,7 +3641,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
sendAndApply(&end_action);
break;
}
case BattleAction::DAEMON_SUMMONING:
case Battle::DAEMON_SUMMONING:
//TODO: From Strategija:
//Summon Demon is a level 2 spell.
{
@ -3679,7 +3679,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
sendAndApply(&end_action);
break;
}
case BattleAction::MONSTER_SPELL:
case Battle::MONSTER_SPELL:
{
StartAction start_action(ba);
sendAndApply(&start_action);
@ -3721,7 +3721,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
return ok;
}
void CGameHandler::playerMessage( ui8 player, const std::string &message )
void CGameHandler::playerMessage( TPlayerColor player, const std::string &message )
{
bool cheated=true;
PlayerMessage temp_message(player,message);
@ -3865,7 +3865,7 @@ void CGameHandler::playerMessage( ui8 player, const std::string &message )
}
}
void CGameHandler::handleSpellCasting( int spellID, int spellLvl, BattleHex destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero,
void CGameHandler::handleSpellCasting( int spellID, int spellLvl, BattleHex destination, ui8 casterSide, TPlayerColor casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero,
int usedSpellPower, ECastingMode::ECastingMode mode, const CStack * stack, si32 selectedStack)
{
const CSpell *spell = VLC->spellh->spells[spellID];
@ -4376,7 +4376,7 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
{
switch(ba.actionType)
{
case BattleAction::HERO_SPELL: //hero casts spell
case Battle::HERO_SPELL:
{
const CGHeroInstance *h = gs->curB->heroes[ba.side];
const CGHeroInstance *secondHero = gs->curB->heroes[!ba.side];
@ -4995,7 +4995,7 @@ void CGameHandler::checkLossVictory( ui8 player )
sendAndApply(&iw);
peg.player = i->first;
peg.victory = gameState()->getPlayerRelations(player, i->first) == 1; // ally of winner
peg.victory = gameState()->getPlayerRelations(player, i->first) == PlayerRelations::ALLIES; // ally of winner
sendAndApply(&peg);
}
}
@ -5599,7 +5599,7 @@ bool CGameHandler::sacrificeArtifact(const IMarket * m, const CGHeroInstance * h
void CGameHandler::makeStackDoNothing(const CStack * next)
{
BattleAction doNothing;
doNothing.actionType = BattleAction::NO_ACTION;
doNothing.actionType = Battle::NO_ACTION;
doNothing.additionalInfo = 0;
doNothing.destinationTile = -1;
doNothing.side = !next->attackerOwned;
@ -5818,7 +5818,7 @@ void CGameHandler::runBattle()
{
//unit loses its turn - empty freeze action
BattleAction ba;
ba.actionType = BattleAction::BAD_MORALE;
ba.actionType = Battle::BAD_MORALE;
ba.additionalInfo = 1;
ba.side = !next->attackerOwned;
ba.stackNumber = next->ID;
@ -5834,7 +5834,7 @@ void CGameHandler::runBattle()
if(attackInfo.first != NULL)
{
BattleAction attack;
attack.actionType = BattleAction::WALK_AND_ATTACK;
attack.actionType = Battle::WALK_AND_ATTACK;
attack.side = !next->attackerOwned;
attack.stackNumber = next->ID;
attack.additionalInfo = attackInfo.first->position;
@ -5855,7 +5855,7 @@ void CGameHandler::runBattle()
&& (!curOwner || curOwner->getSecSkillLevel(CGHeroInstance::ARTILLERY) == 0)) //hero has no artillery
{
BattleAction attack;
attack.actionType = BattleAction::SHOOT;
attack.actionType = Battle::SHOOT;
attack.side = !next->attackerOwned;
attack.stackNumber = next->ID;
@ -5878,7 +5878,7 @@ void CGameHandler::runBattle()
static const int wallHexes[] = {50, 183, 182, 130, 62, 29, 12, 95};
attack.destinationTile = wallHexes[ rand()%ARRAY_COUNT(wallHexes) ];
attack.actionType = BattleAction::CATAPULT;
attack.actionType = Battle::CATAPULT;
attack.additionalInfo = 0;
attack.side = !next->attackerOwned;
attack.stackNumber = next->ID;
@ -5909,7 +5909,7 @@ void CGameHandler::runBattle()
const CStack * toBeHealed = possibleStacks.front();
BattleAction heal;
heal.actionType = BattleAction::STACK_HEAL;
heal.actionType = Battle::STACK_HEAL;
heal.additionalInfo = 0;
heal.destinationTile = toBeHealed->position;
heal.side = !next->attackerOwned;

View File

@ -195,10 +195,10 @@ public:
void handleConnection(std::set<int> players, CConnection &c);
int getPlayerAt(CConnection *c) const;
void playerMessage( ui8 player, const std::string &message);
void playerMessage( TPlayerColor player, const std::string &message);
bool makeBattleAction(BattleAction &ba);
bool makeAutomaticAction(const CStack *stack, BattleAction &ba); //used when action is taken by stack without volition of player (eg. unguided catapult attack)
void handleSpellCasting(int spellID, int spellLvl, BattleHex destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero,
void handleSpellCasting(int spellID, int spellLvl, BattleHex destination, ui8 casterSide, TPlayerColor casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero,
int usedSpellPower, ECastingMode::ECastingMode mode, const CStack * stack, si32 selectedStack = -1);
bool makeCustomAction(BattleAction &ba);
void stackTurnTrigger(const CStack * stack);

View File

@ -246,8 +246,8 @@ bool MakeAction::applyGh( CGameHandler *gh )
if(b->tacticDistance)
{
if(ba.actionType != BattleAction::WALK && ba.actionType != BattleAction::END_TACTIC_PHASE
&& ba.actionType != BattleAction::RETREAT && ba.actionType != BattleAction::SURRENDER)
if(ba.actionType != Battle::WALK && ba.actionType != Battle::END_TACTIC_PHASE
&& ba.actionType != Battle::RETREAT && ba.actionType != Battle::SURRENDER)
ERROR_AND_RETURN;
if(gh->connections[b->sides[b->tacticsSide]] != c)
ERROR_AND_RETURN;
@ -266,7 +266,7 @@ bool MakeCustomAction::applyGh( CGameHandler *gh )
const CStack *active = GS(gh)->curB->battleGetStackByID(GS(gh)->curB->activeStack);
if(!active) ERROR_AND_RETURN;
if(gh->connections[active->owner] != c) ERROR_AND_RETURN;
if(ba.actionType != BattleAction::HERO_SPELL) ERROR_AND_RETURN;
if(ba.actionType != Battle::HERO_SPELL) ERROR_AND_RETURN;
return gh->makeCustomAction(ba);
}