1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-30 08:57:00 +02:00
vcmi/server/battles/BattleResultProcessor.h
Ivan Savenko 0c07384293 Refactoring of serialization versioning handling
- Removed 'version' field from serialize() method
- Handler classes - Binary(De)Serializer now have 'version' field
- Serialization versioning now uses named enum

Save compatibility with 1.4.X saves should be intact
2024-01-20 20:34:51 +02:00

83 lines
2.3 KiB
C++

/*
* BattleProcessor.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "../../lib/GameConstants.h"
#include "../../lib/networkPacks/StackLocation.h"
#include "../../lib/networkPacks/ArtifactLocation.h"
VCMI_LIB_NAMESPACE_BEGIN
struct SideInBattle;
struct BattleResult;
class CBattleInfoCallback;
class CGHeroInstance;
VCMI_LIB_NAMESPACE_END
class CBattleQuery;
class BattleProcessor;
class CGameHandler;
struct CasualtiesAfterBattle
{
using TStackAndItsNewCount = std::pair<StackLocation, int>;
using TSummoned = std::map<CreatureID, TQuantity>;
const CArmedInstance * army;
std::vector<TStackAndItsNewCount> newStackCounts;
std::vector<ArtifactLocation> removedWarMachines;
TSummoned summoned;
ObjectInstanceID heroWithDeadCommander; //TODO: unify stack locations
CasualtiesAfterBattle(const CBattleInfoCallback & battle, uint8_t sideInBattle);
void updateArmy(CGameHandler * gh);
};
struct FinishingBattleHelper
{
FinishingBattleHelper(const CBattleInfoCallback & battle, const BattleResult & result, int RemainingBattleQueriesCount);
inline bool isDraw() const {return winnerSide == 2;}
const CGHeroInstance *winnerHero, *loserHero;
PlayerColor victor, loser;
ui8 winnerSide;
int remainingBattleQueriesCount;
template <typename Handler> void serialize(Handler &h)
{
h & winnerHero;
h & loserHero;
h & victor;
h & loser;
h & winnerSide;
h & remainingBattleQueriesCount;
}
};
class BattleResultProcessor : boost::noncopyable
{
// BattleProcessor * owner;
CGameHandler * gameHandler;
std::map<BattleID, std::unique_ptr<BattleResult>> battleResults;
std::map<BattleID, std::unique_ptr<FinishingBattleHelper>> finishingBattles;
public:
explicit BattleResultProcessor(BattleProcessor * owner);
void setGameHandler(CGameHandler * newGameHandler);
bool battleIsEnding(const CBattleInfoCallback & battle) const;
void setBattleResult(const CBattleInfoCallback & battle, EBattleResult resultType, int victoriusSide);
void endBattle(const CBattleInfoCallback & battle); //ends battle
void endBattleConfirm(const CBattleInfoCallback & battle);
void battleAfterLevelUp(const BattleID & battleID, const BattleResult & result);
};