mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
* minor cleanup
This commit is contained in:
parent
ea03273c8e
commit
efedb1a55a
@ -41,7 +41,7 @@ ui8 side; //who made this action: false - left, true - right player
|
||||
/**
|
||||
* Implementation of CBattleLogic class.
|
||||
*/
|
||||
CBattleLogic::CBattleLogic(ICallback *cb, const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side) :
|
||||
CBattleLogic::CBattleLogic(ICallback *cb, const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side) :
|
||||
m_iCurrentTurn(-2),
|
||||
m_bIsAttacker(!side),
|
||||
m_cb(cb),
|
||||
|
@ -63,7 +63,7 @@ private:
|
||||
int leftHitPoint_for_min; // scenario
|
||||
};
|
||||
public:
|
||||
CBattleLogic(ICallback *cb, const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side);
|
||||
CBattleLogic(ICallback *cb, const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side);
|
||||
~CBattleLogic();
|
||||
|
||||
void SetCurrentTurn(int turn);
|
||||
@ -80,8 +80,8 @@ private:
|
||||
const CCreatureSet *m_army1;
|
||||
const CCreatureSet *m_army2;
|
||||
int3 m_tile;
|
||||
CGHeroInstance *m_hero1;
|
||||
CGHeroInstance *m_hero2;
|
||||
const CGHeroInstance *m_hero1;
|
||||
const CGHeroInstance *m_hero2;
|
||||
bool m_side;
|
||||
|
||||
// statistics
|
||||
|
@ -1253,7 +1253,7 @@ void CGeniusAI::battleStacksAttacked(std::set<BattleStackAttacked>& bsa)
|
||||
/**
|
||||
* called by engine when battle starts; side=0 - left, side=1 - right
|
||||
*/
|
||||
void CGeniusAI::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side)
|
||||
void CGeniusAI::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side)
|
||||
{
|
||||
// TODO: Battle logic what...
|
||||
assert(!m_battleLogic);
|
||||
@ -1331,11 +1331,11 @@ void CGeniusAI::battleSpellCast(BattleSpellCast *sc)
|
||||
/**
|
||||
* called when battlefield is prepared, prior the battle beginning
|
||||
*/
|
||||
void CGeniusAI::battlefieldPrepared(int battlefieldType,
|
||||
std::vector<CObstacle*> obstacles)
|
||||
{
|
||||
DbgBox("CGeniusAI::battlefieldPrepared");
|
||||
}
|
||||
// void CGeniusAI::battlefieldPrepared(int battlefieldType,
|
||||
// std::vector<CObstacle*> obstacles)
|
||||
// {
|
||||
// DbgBox("CGeniusAI::battlefieldPrepared");
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
|
@ -207,8 +207,8 @@ public:
|
||||
virtual void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
|
||||
virtual void battleStackMoved(int ID, int dest, int distance, bool end);
|
||||
virtual void battleSpellCast(BattleSpellCast *sc);
|
||||
virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right
|
||||
virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
|
||||
virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right
|
||||
//virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
|
||||
//
|
||||
virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving);
|
||||
virtual void battleStackAttacking(int ID, int dest);
|
||||
|
@ -120,8 +120,8 @@ public:
|
||||
virtual void battleStackMoved(int ID, int dest, int distance, bool end){};
|
||||
virtual void battleSpellCast(BattleSpellCast *sc){};
|
||||
virtual void battleStacksEffectsSet(SetStackEffect & sse){};//called when a specific effect is set to stacks
|
||||
virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right
|
||||
virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles){}; //called when battlefield is prepared, prior the battle beginning
|
||||
virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right
|
||||
//virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles){}; //called when battlefield is prepared, prior the battle beginning
|
||||
virtual void battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks, bool lifeDrain, si32 lifeDrainFrom){}; //called when stacks are healed / resurrected first element of pair - stack id, second - healed hp
|
||||
virtual void battleNewStackAppeared(int stackID){}; //not called at the beginning of a battle or by resurrection; called eg. when elemental is summoned
|
||||
virtual void battleObstaclesRemoved(const std::set<si32> & removedObstacles){}; //called when a certain set of obstacles is removed from batlefield; IDs of them are given
|
||||
|
@ -2819,7 +2819,7 @@ void CBattleInterface::battleStacksEffectsSet(const SetStackEffect & sse)
|
||||
void CBattleInterface::castThisSpell(int spellID)
|
||||
{
|
||||
BattleAction * ba = new BattleAction;
|
||||
ba->actionType = 1;
|
||||
ba->actionType = BattleAction::HERO_SPELL;
|
||||
ba->additionalInfo = spellID; //spell number
|
||||
ba->destinationTile = -1;
|
||||
ba->stackNumber = (attackingHeroInstance->tempOwner == curInt->playerID) ? -1 : -2;
|
||||
@ -3009,7 +3009,7 @@ void CBattleInterface::showAliveStack(int ID, const std::map<int, CStack> & stac
|
||||
if(curStack.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 != 6 || curStack.position != curInt->curAction->additionalInfo) //nor if it's an object of attack
|
||||
&& (curInt->curAction->actionType != BattleAction::WALK_AND_ATTACK || curStack.position != curInt->curAction->additionalInfo) //nor if it's an object of attack
|
||||
&& (curInt->curAction->destinationTile != curStack.position) //nor if it's on destination tile for current action
|
||||
)
|
||||
)
|
||||
@ -3227,18 +3227,18 @@ void CBattleInterface::endAction(const BattleAction* action)
|
||||
// {
|
||||
// activate();
|
||||
// }
|
||||
if(action->actionType == 1)
|
||||
if(action->actionType == BattleAction::HERO_SPELL)
|
||||
{
|
||||
if(action->side)
|
||||
defendingHero->setPhase(0);
|
||||
else
|
||||
attackingHero->setPhase(0);
|
||||
}
|
||||
if(action->actionType == 2 && creAnims[action->stackNumber]->getType() != 2) //walk or walk & attack
|
||||
if(action->actionType == BattleAction::WALK && creAnims[action->stackNumber]->getType() != 2) //walk or walk & attack
|
||||
{
|
||||
pendingAnims.push_back(std::make_pair(new CBattleMoveEnd(this, action->stackNumber, action->destinationTile), false));
|
||||
}
|
||||
if(action->actionType == 9) //catapult
|
||||
if(action->actionType == BattleAction::CATAPULT) //catapult
|
||||
{
|
||||
}
|
||||
queue->update();
|
||||
@ -3280,11 +3280,11 @@ void CBattleInterface::startAction(const BattleAction* action)
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(action->actionType == 1); //only cast spell is valid action without acting stack number
|
||||
assert(action->actionType == BattleAction::HERO_SPELL); //only cast spell is valid action without acting stack number
|
||||
}
|
||||
|
||||
if(action->actionType == 2
|
||||
|| (action->actionType == 6 && action->destinationTile != stack->position))
|
||||
if(action->actionType == BattleAction::WALK
|
||||
|| (action->actionType == BattleAction::WALK_AND_ATTACK && action->destinationTile != stack->position))
|
||||
{
|
||||
moveStarted = true;
|
||||
if(creAnims[action->stackNumber]->framesInGroup(20))
|
||||
@ -3298,7 +3298,7 @@ void CBattleInterface::startAction(const BattleAction* action)
|
||||
|
||||
char txt[400];
|
||||
|
||||
if(action->actionType == 1) //when hero casts spell
|
||||
if(action->actionType == BattleAction::HERO_SPELL) //when hero casts spell
|
||||
{
|
||||
if(action->side)
|
||||
defendingHero->setPhase(4);
|
||||
@ -3339,7 +3339,7 @@ void CBattleInterface::startAction(const BattleAction* action)
|
||||
}
|
||||
|
||||
//displaying heal animation
|
||||
if (action->actionType == 12)
|
||||
if (action->actionType == BattleAction::STACK_HEAL)
|
||||
{
|
||||
displayEffect(50, action->destinationTile);
|
||||
}
|
||||
|
@ -537,7 +537,7 @@ void CPlayerInterface::buildChanged(const CGTownInstance *town, int buildingID,
|
||||
}
|
||||
}
|
||||
|
||||
void CPlayerInterface::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side)
|
||||
void CPlayerInterface::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side)
|
||||
{
|
||||
if(LOCPLINT != this)
|
||||
{ //another local interface should do this
|
||||
@ -552,9 +552,6 @@ void CPlayerInterface::battleStart(const CCreatureSet *army1, const CCreatureSet
|
||||
GH.pushInt(battleInt);
|
||||
}
|
||||
|
||||
void CPlayerInterface::battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles) //called when battlefield is prepared, prior the battle beginning
|
||||
{
|
||||
}
|
||||
|
||||
void CPlayerInterface::battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks, bool lifeDrain, si32 lifeDrainFrom)
|
||||
{
|
||||
|
@ -212,8 +212,7 @@ public:
|
||||
void battleSpellCast(BattleSpellCast *sc);
|
||||
void battleStacksEffectsSet(SetStackEffect & sse); //called when a specific effect is set to stacks
|
||||
void battleStacksAttacked(std::vector<BattleStackAttacked> & bsa);
|
||||
void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right
|
||||
void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
|
||||
void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right
|
||||
void battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks, bool lifeDrain, si32 lifeDrainFrom); //called when stacks are healed / resurrected
|
||||
void battleNewStackAppeared(int stackID); //not called at the beginning of a battle or by resurrection; called eg. when elemental is summoned
|
||||
void battleObstaclesRemoved(const std::set<si32> & removedObstacles); //called when a certain set of obstacles is removed from batlefield; IDs of them are given
|
||||
|
@ -15,6 +15,10 @@ struct BattleAction
|
||||
{
|
||||
ui8 side; //who made this action: false - left, true - right player
|
||||
ui32 stackNumber;//stack ID, -1 left hero, -2 right hero,
|
||||
enum ActionType
|
||||
{
|
||||
NO_ACTION = 0, HERO_SPELL, WALK, DEFEND, RETREAT, SURRENDER, WALK_AND_ATTACK, SHOOT, WAIT, CATAPULT, MONSTER_SPELL, BAD_MORALE, STACK_HEAL
|
||||
};
|
||||
ui8 actionType; // 0 = No action; 1 = Hero cast a spell 2 = Walk 3 = Defend 4 = Retreat from the battle
|
||||
//5 = Surrender 6 = Walk and Attack 7 = Shoot 8 = Wait 9 = Catapult
|
||||
//10 = Monster casts a spell (i.e. Faerie Dragons) 11 - Bad morale freeze 12 - stacks heals another stack
|
||||
|
@ -901,18 +901,20 @@ DLL_EXPORT void StartAction::applyGs( CGameState *gs )
|
||||
{
|
||||
CStack *st = gs->curB->getStack(ba.stackNumber);
|
||||
|
||||
if(ba.actionType != 1) //don't check for stack if it's custom action by hero
|
||||
if(ba.actionType != BattleAction::HERO_SPELL) //don't check for stack if it's custom action by hero
|
||||
assert(st);
|
||||
|
||||
switch(ba.actionType)
|
||||
{
|
||||
case 3:
|
||||
case BattleAction::DEFEND:
|
||||
st->state.insert(DEFENDING);
|
||||
break;
|
||||
case 8:
|
||||
case BattleAction::WAIT:
|
||||
st->state.insert(WAITING);
|
||||
return;
|
||||
case 0: case 2: case 6: case 7: case 9: case 10: case 11: case 12:
|
||||
case BattleAction::NO_ACTION: case BattleAction::WALK: case BattleAction::WALK_AND_ATTACK:
|
||||
case BattleAction::SHOOT: case BattleAction::CATAPULT: case BattleAction::MONSTER_SPELL:
|
||||
case BattleAction::BAD_MORALE: case BattleAction::STACK_HEAL:
|
||||
st->state.insert(MOVED);
|
||||
break;
|
||||
}
|
||||
|
@ -347,16 +347,15 @@ void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance
|
||||
setupBattle(curB, tile, army1, army2, hero1, hero2, creatureBank, town); //initializes stacks, places creatures on battlefield, blocks and informs player interfaces
|
||||
}
|
||||
|
||||
NEW_ROUND;
|
||||
//TODO: pre-tactic stuff, call scripts etc.
|
||||
|
||||
//tactic round
|
||||
{
|
||||
NEW_ROUND;
|
||||
if( (hero1 && hero1->getSecSkillLevel(19)>0) ||
|
||||
( hero2 && hero2->getSecSkillLevel(19)>0) )//someone has tactics
|
||||
{
|
||||
//TODO: tactic round (round -1)
|
||||
NEW_ROUND;
|
||||
}
|
||||
}
|
||||
|
||||
@ -402,7 +401,7 @@ void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance
|
||||
{
|
||||
//unit loses its turn - empty freeze action
|
||||
BattleAction ba;
|
||||
ba.actionType = 11;
|
||||
ba.actionType = BattleAction::BAD_MORALE;
|
||||
ba.additionalInfo = 1;
|
||||
ba.side = !next->attackerOwned;
|
||||
ba.stackNumber = next->ID;
|
||||
@ -419,7 +418,7 @@ void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance
|
||||
if(attackInfo.first != NULL)
|
||||
{
|
||||
BattleAction attack;
|
||||
attack.actionType = 6;
|
||||
attack.actionType = BattleAction::WALK_AND_ATTACK;
|
||||
attack.side = !next->attackerOwned;
|
||||
attack.stackNumber = next->ID;
|
||||
|
||||
@ -430,6 +429,10 @@ void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance
|
||||
|
||||
checkForBattleEnd(stacks);
|
||||
}
|
||||
else
|
||||
{
|
||||
makeStackDoNothing(next);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -439,7 +442,7 @@ void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance
|
||||
|| (next->type->idNumber == 146 && (!curOwner || curOwner->getSecSkillLevel(20) == 0))) //ballista, hero has no artillery
|
||||
{
|
||||
BattleAction attack;
|
||||
attack.actionType = 7;
|
||||
attack.actionType = BattleAction::SHOOT;
|
||||
attack.side = !next->attackerOwned;
|
||||
attack.stackNumber = next->ID;
|
||||
|
||||
@ -464,7 +467,7 @@ void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance
|
||||
static const int wallHexes[] = {50, 183, 182, 130, 62, 29, 12, 95};
|
||||
|
||||
attack.destinationTile = wallHexes[ rand()%ARRAY_COUNT(wallHexes) ];
|
||||
attack.actionType = 9;
|
||||
attack.actionType = BattleAction::CATAPULT;
|
||||
attack.additionalInfo = 0;
|
||||
attack.side = !next->attackerOwned;
|
||||
attack.stackNumber = next->ID;
|
||||
@ -490,21 +493,15 @@ void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance
|
||||
if(possibleStacks.size() == 0)
|
||||
{
|
||||
//nothing to heal
|
||||
BattleAction doNothing;
|
||||
doNothing.actionType = 0;
|
||||
doNothing.additionalInfo = 0;
|
||||
doNothing.destinationTile = -1;
|
||||
doNothing.side = !next->attackerOwned;
|
||||
doNothing.stackNumber = next->ID;
|
||||
sendAndApply(&StartAction(doNothing));
|
||||
sendAndApply(&EndAction());
|
||||
makeStackDoNothing(next);
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
//heal random creature
|
||||
const CStack * toBeHealed = possibleStacks[ rand()%possibleStacks.size() ];
|
||||
heal.actionType = 12;
|
||||
heal.actionType = BattleAction::STACK_HEAL;
|
||||
heal.additionalInfo = 0;
|
||||
heal.destinationTile = toBeHealed->position;
|
||||
heal.side = !next->attackerOwned;
|
||||
@ -5317,3 +5314,15 @@ bool CGameHandler::sacrificeArtifact(const IMarket * m, const CGHeroInstance * h
|
||||
changePrimSkill(hero->id, 4, expToGive);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CGameHandler::makeStackDoNothing(const CStack * next)
|
||||
{
|
||||
BattleAction doNothing;
|
||||
doNothing.actionType = 0;
|
||||
doNothing.additionalInfo = 0;
|
||||
doNothing.destinationTile = -1;
|
||||
doNothing.side = !next->attackerOwned;
|
||||
doNothing.stackNumber = next->ID;
|
||||
sendAndApply(&StartAction(doNothing));
|
||||
sendAndApply(&EndAction());
|
||||
}
|
||||
|
@ -76,6 +76,8 @@ public:
|
||||
|
||||
class CGameHandler : public IGameCallback
|
||||
{
|
||||
private:
|
||||
void makeStackDoNothing(const CStack * next);
|
||||
public:
|
||||
CVCMIServer *s;
|
||||
std::map<int,CConnection*> connections; //player color -> connection to client with interface of that player
|
||||
@ -229,3 +231,5 @@ public:
|
||||
};
|
||||
|
||||
#endif // __CGAMEHANDLER_H__
|
||||
|
||||
void makeStackDoNothing();
|
Loading…
Reference in New Issue
Block a user