1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-30 08:57:00 +02:00
vcmi/client/PlayerLocalState.h

112 lines
3.4 KiB
C
Raw Normal View History

/*
* PlayerLocalState.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
VCMI_LIB_NAMESPACE_BEGIN
class CGHeroInstance;
class CGTownInstance;
class CArmedInstance;
struct CGPath;
class int3;
VCMI_LIB_NAMESPACE_END
class CPlayerInterface;
/// Class that contains potentially serializeable state of a local player
class PlayerLocalState
{
CPlayerInterface & owner;
/// Currently selected object, can be town, hero or null
const CArmedInstance * currentSelection;
std::map<const CGHeroInstance *, CGPath> paths; //maps hero => selected path in adventure map
2023-04-17 12:26:28 +02:00
std::vector<const CGHeroInstance *> sleepingHeroes; //if hero is in here, he's sleeping
2023-04-17 14:17:15 +02:00
std::vector<const CGHeroInstance *> wanderingHeroes; //our heroes on the adventure map (not the garrisoned ones)
2023-04-17 14:32:18 +02:00
std::vector<const CGTownInstance *> ownedTowns; //our towns on the adventure map
void saveHeroPaths(std::map<const CGHeroInstance *, int3> & paths);
void loadHeroPaths(std::map<const CGHeroInstance *, int3> & paths);
2023-04-17 15:19:56 +02:00
public:
struct SpellbookLastSetting
{
//on which page we left spellbook
int spellbookLastPageBattle = 0;
int spellbokLastPageAdvmap = 0;
int spellbookLastTabBattle = 4;
int spellbookLastTabAdvmap = 4;
2023-04-17 15:19:56 +02:00
template<typename Handler>
void serialize(Handler & h, const int version)
{
h & spellbookLastPageBattle;
h & spellbokLastPageAdvmap;
h & spellbookLastTabBattle;
h & spellbookLastTabAdvmap;
}
} spellbookSettings;
explicit PlayerLocalState(CPlayerInterface & owner);
2023-04-17 12:26:28 +02:00
bool isHeroSleeping(const CGHeroInstance * hero) const;
void setHeroAsleep(const CGHeroInstance * hero);
void setHeroAwaken(const CGHeroInstance * hero);
2023-04-17 14:32:18 +02:00
const std::vector<const CGTownInstance *> & getOwnedTowns();
const CGTownInstance * getOwnedTown(size_t index);
void addOwnedTown(const CGTownInstance * hero);
void removeOwnedTown(const CGTownInstance * hero);
2023-04-17 14:17:15 +02:00
const std::vector<const CGHeroInstance *> & getWanderingHeroes();
const CGHeroInstance * getWanderingHero(size_t index);
2023-04-18 22:08:27 +02:00
const CGHeroInstance * getNextWanderingHero(const CGHeroInstance * hero);
2023-04-17 14:17:15 +02:00
void addWanderingHero(const CGHeroInstance * hero);
void removeWanderingHero(const CGHeroInstance * hero);
2023-04-17 15:19:56 +02:00
void setPath(const CGHeroInstance * h, const CGPath & path);
bool setPath(const CGHeroInstance * h, const int3 & destination);
2023-04-17 15:19:56 +02:00
const CGPath & getPath(const CGHeroInstance * h) const;
bool hasPath(const CGHeroInstance * h) const;
2023-04-17 15:19:56 +02:00
void removeLastNode(const CGHeroInstance * h);
void erasePath(const CGHeroInstance * h);
void verifyPath(const CGHeroInstance * h);
/// Returns currently selected object
const CGHeroInstance * getCurrentHero() const;
const CGTownInstance * getCurrentTown() const;
const CArmedInstance * getCurrentArmy() const;
/// Changes currently selected object
2023-04-18 22:08:27 +02:00
void setSelection(const CArmedInstance *sel);
2023-04-17 15:19:56 +02:00
template<typename Handler>
void serialize(Handler & h, int version)
{
//WARNING: this code is broken and not used. See CClient::loadGame
std::map<const CGHeroInstance *, int3> pathsMap; //hero -> dest
if(h.saving)
saveHeroPaths(pathsMap);
h & pathsMap;
if(!h.saving)
loadHeroPaths(pathsMap);
h & ownedTowns;
h & wanderingHeroes;
h & sleepingHeroes;
}
};