2009-04-15 17:03:31 +03:00
|
|
|
/*
|
2012-11-03 16:30:47 +03:00
|
|
|
* CMap.h, part of VCMI engine
|
2009-04-15 17:03:31 +03:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-11-03 16:30:47 +03:00
|
|
|
#pragma once
|
|
|
|
|
2023-05-24 00:14:06 +02:00
|
|
|
#include "CMapHeader.h"
|
2023-09-27 23:22:45 +02:00
|
|
|
#include "../MetaString.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
#include "../mapObjects/MiscObjects.h" // To serialize static props
|
|
|
|
#include "../mapObjects/CQuest.h" // To serialize static props
|
|
|
|
#include "../mapObjects/CGTownInstance.h" // To serialize static props
|
2015-12-02 21:05:10 +02:00
|
|
|
#include "CMapDefines.h"
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2010-12-17 20:47:07 +02:00
|
|
|
class CArtifactInstance;
|
2008-12-27 03:01:59 +02:00
|
|
|
class CGObjectInstance;
|
|
|
|
class CGHeroInstance;
|
2012-04-22 20:38:36 +03:00
|
|
|
class CCommanderInstance;
|
2010-02-02 19:05:03 +02:00
|
|
|
class CGCreature;
|
2008-12-27 03:01:59 +02:00
|
|
|
class CQuest;
|
|
|
|
class CGTownInstance;
|
2010-11-10 02:06:25 +02:00
|
|
|
class IModableArt;
|
2012-09-16 16:34:01 +03:00
|
|
|
class IQuestObject;
|
2012-09-26 16:13:39 +03:00
|
|
|
class CInputStream;
|
2013-04-19 14:43:11 +03:00
|
|
|
class CMapEditManager;
|
2023-05-24 00:14:06 +02:00
|
|
|
class JsonSerializeFormat;
|
|
|
|
struct TeleportChannel;
|
2009-01-06 20:42:20 +02:00
|
|
|
|
2013-04-16 16:16:58 +03:00
|
|
|
/// The rumor struct consists of a rumor name and text.
|
2011-12-14 00:23:17 +03:00
|
|
|
struct DLL_LINKAGE Rumor
|
2008-12-27 03:01:59 +02:00
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
std::string name;
|
2023-09-27 23:22:45 +02:00
|
|
|
MetaString text;
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
Rumor() = default;
|
|
|
|
~Rumor() = default;
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
template <typename Handler>
|
|
|
|
void serialize(Handler & h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & name;
|
|
|
|
h & text;
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2016-11-13 12:38:42 +02:00
|
|
|
|
|
|
|
void serializeJson(JsonSerializeFormat & handler);
|
2008-12-27 03:01:59 +02:00
|
|
|
};
|
|
|
|
|
2013-04-16 16:16:58 +03:00
|
|
|
/// The disposed hero struct describes which hero can be hired from which player.
|
2011-12-14 00:23:17 +03:00
|
|
|
struct DLL_LINKAGE DisposedHero
|
2008-12-27 03:01:59 +02:00
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
DisposedHero();
|
|
|
|
|
2023-07-11 14:16:02 +02:00
|
|
|
HeroTypeID heroId;
|
2023-07-12 11:29:05 +02:00
|
|
|
HeroTypeID portrait; /// The portrait id of the hero, -1 is default.
|
2012-11-11 15:23:31 +03:00
|
|
|
std::string name;
|
2023-08-25 20:40:19 +02:00
|
|
|
std::set<PlayerColor> players; /// Who can hire this hero (bitfield).
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
template <typename Handler>
|
|
|
|
void serialize(Handler & h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & heroId;
|
|
|
|
h & portrait;
|
|
|
|
h & name;
|
|
|
|
h & players;
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2008-12-27 03:01:59 +02:00
|
|
|
};
|
|
|
|
|
2013-04-16 16:16:58 +03:00
|
|
|
/// The map contains the map header, the tiles of the terrain, objects, heroes, towns, rumors...
|
2012-10-26 20:51:05 +03:00
|
|
|
class DLL_LINKAGE CMap : public CMapHeader
|
2008-12-27 03:01:59 +02:00
|
|
|
{
|
2012-10-26 20:51:05 +03:00
|
|
|
public:
|
2012-11-11 15:23:31 +03:00
|
|
|
CMap();
|
|
|
|
~CMap();
|
2013-04-16 16:16:58 +03:00
|
|
|
void initTerrain();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2013-04-19 14:43:11 +03:00
|
|
|
CMapEditManager * getEditManager();
|
2012-11-11 15:23:31 +03:00
|
|
|
TerrainTile & getTile(const int3 & tile);
|
|
|
|
const TerrainTile & getTile(const int3 & tile) const;
|
2015-08-15 20:46:28 +02:00
|
|
|
bool isCoastalTile(const int3 & pos) const;
|
2012-11-11 15:23:31 +03:00
|
|
|
bool isInTheMap(const int3 & pos) const;
|
|
|
|
bool isWaterTile(const int3 & pos) const;
|
2015-08-15 20:46:28 +02:00
|
|
|
|
2016-12-21 11:10:37 +02:00
|
|
|
bool canMoveBetween(const int3 &src, const int3 &dst) const;
|
2023-02-11 18:30:06 +02:00
|
|
|
bool checkForVisitableDir(const int3 & src, const TerrainTile * pom, const int3 & dst) const;
|
2014-04-01 14:53:28 +03:00
|
|
|
int3 guardingCreaturePosition (int3 pos) const;
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2013-04-16 16:16:58 +03:00
|
|
|
void addBlockVisTiles(CGObjectInstance * obj);
|
|
|
|
void removeBlockVisTiles(CGObjectInstance * obj, bool total = false);
|
2014-04-01 14:53:28 +03:00
|
|
|
void calculateGuardingGreaturePositions();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2023-09-17 17:40:14 +02:00
|
|
|
void addNewArtifactInstance(ConstTransitivePtr<CArtifactInstance> art);
|
2013-04-16 16:16:58 +03:00
|
|
|
void eraseArtifactInstance(CArtifactInstance * art);
|
2016-09-08 13:24:28 +02:00
|
|
|
|
2017-05-28 15:23:42 +02:00
|
|
|
void addNewQuestInstance(CQuest * quest);
|
2022-09-17 13:04:01 +02:00
|
|
|
void removeQuestInstance(CQuest * quest);
|
2017-05-28 15:23:42 +02:00
|
|
|
|
2022-09-17 13:04:01 +02:00
|
|
|
void setUniqueInstanceName(CGObjectInstance * obj);
|
2017-05-28 15:23:42 +02:00
|
|
|
///Use only this method when creating new map object instances
|
2016-02-22 18:26:42 +02:00
|
|
|
void addNewObject(CGObjectInstance * obj);
|
2022-09-17 13:04:01 +02:00
|
|
|
void moveObject(CGObjectInstance * obj, const int3 & dst);
|
|
|
|
void removeObject(CGObjectInstance * obj);
|
|
|
|
|
2023-07-09 11:16:36 +02:00
|
|
|
bool isWaterMap() const;
|
|
|
|
bool calculateWaterContent();
|
2023-07-17 17:21:28 +02:00
|
|
|
void banWaterArtifacts();
|
|
|
|
void banWaterHeroes();
|
|
|
|
void banHero(const HeroTypeID& id);
|
|
|
|
void banWaterSpells();
|
2023-07-18 10:54:36 +02:00
|
|
|
void banWaterSkills();
|
2023-07-17 17:21:28 +02:00
|
|
|
void banWaterContent();
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2013-12-29 14:27:38 +03:00
|
|
|
/// Gets object of specified type on requested position
|
2023-08-19 19:48:28 +02:00
|
|
|
const CGObjectInstance * getObjectiveObjectFrom(const int3 & pos, Obj type);
|
2013-04-16 16:16:58 +03:00
|
|
|
CGHeroInstance * getHero(int heroId);
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2013-04-16 16:16:58 +03:00
|
|
|
/// Sets the victory/loss condition objectives ??
|
|
|
|
void checkForObjectives();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
void resetStaticData();
|
|
|
|
|
2013-04-16 16:16:58 +03:00
|
|
|
ui32 checksum;
|
2012-11-11 15:23:31 +03:00
|
|
|
std::vector<Rumor> rumors;
|
|
|
|
std::vector<DisposedHero> disposedHeroes;
|
|
|
|
std::vector<ConstTransitivePtr<CGHeroInstance> > predefinedHeroes;
|
2023-07-17 17:21:28 +02:00
|
|
|
std::vector<bool> allowedSpells;
|
2013-02-05 00:58:42 +03:00
|
|
|
std::vector<bool> allowedArtifact;
|
|
|
|
std::vector<bool> allowedAbilities;
|
2013-02-19 01:37:22 +03:00
|
|
|
std::list<CMapEvent> events;
|
2012-11-11 15:23:31 +03:00
|
|
|
int3 grailPos;
|
2016-01-31 17:01:58 +02:00
|
|
|
int grailRadius;
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2013-05-19 01:30:48 +03:00
|
|
|
//Central lists of items in game. Position of item in the vectors below is their (instance) id.
|
2012-11-11 15:23:31 +03:00
|
|
|
std::vector< ConstTransitivePtr<CGObjectInstance> > objects;
|
|
|
|
std::vector< ConstTransitivePtr<CGTownInstance> > towns;
|
|
|
|
std::vector< ConstTransitivePtr<CArtifactInstance> > artInstances;
|
|
|
|
std::vector< ConstTransitivePtr<CQuest> > quests;
|
2013-05-19 01:30:48 +03:00
|
|
|
std::vector< ConstTransitivePtr<CGHeroInstance> > allHeroes; //indexed by [hero_type_id]; on map, disposed, prisons, etc.
|
|
|
|
|
|
|
|
//Helper lists
|
2013-12-23 18:59:37 +03:00
|
|
|
std::vector< ConstTransitivePtr<CGHeroInstance> > heroesOnMap;
|
2015-12-29 04:43:33 +02:00
|
|
|
std::map<TeleportChannelID, std::shared_ptr<TeleportChannel> > teleportChannels;
|
2013-12-23 18:59:37 +03:00
|
|
|
|
|
|
|
/// associative list to identify which hero/creature id belongs to which object id(index for objects)
|
|
|
|
std::map<si32, ObjectInstanceID> questIdentifierToId;
|
|
|
|
|
2015-12-29 04:43:33 +02:00
|
|
|
std::unique_ptr<CMapEditManager> editManager;
|
2023-06-06 15:32:26 +02:00
|
|
|
boost::multi_array<int3, 3> guardingCreaturePositions;
|
2014-04-01 14:53:28 +03:00
|
|
|
|
2016-02-22 18:26:42 +02:00
|
|
|
std::map<std::string, ConstTransitivePtr<CGObjectInstance> > instanceNames;
|
|
|
|
|
2023-07-09 11:16:36 +02:00
|
|
|
bool waterMap;
|
|
|
|
|
2013-04-19 14:43:11 +03:00
|
|
|
private:
|
2013-12-21 20:34:59 +03:00
|
|
|
/// a 3-dimensional array of terrain tiles, access is as follows: x, y, level. where level=1 is underground
|
2023-06-06 15:32:26 +02:00
|
|
|
boost::multi_array<TerrainTile, 3> terrain;
|
|
|
|
|
2022-09-17 13:04:01 +02:00
|
|
|
si32 uidCounter; //TODO: initialize when loading an old map
|
2013-04-19 14:43:11 +03:00
|
|
|
|
|
|
|
public:
|
2012-11-11 15:23:31 +03:00
|
|
|
template <typename Handler>
|
|
|
|
void serialize(Handler &h, const int formatVersion)
|
|
|
|
{
|
|
|
|
h & static_cast<CMapHeader&>(*this);
|
2022-10-02 23:48:03 +02:00
|
|
|
h & triggeredEvents; //from CMapHeader
|
2017-07-31 15:35:42 +02:00
|
|
|
h & rumors;
|
2023-07-17 17:21:28 +02:00
|
|
|
h & allowedSpells;
|
2017-07-31 15:35:42 +02:00
|
|
|
h & allowedAbilities;
|
|
|
|
h & allowedArtifact;
|
|
|
|
h & events;
|
|
|
|
h & grailPos;
|
|
|
|
h & artInstances;
|
|
|
|
h & quests;
|
|
|
|
h & allHeroes;
|
2012-11-11 15:23:31 +03:00
|
|
|
h & questIdentifierToId;
|
|
|
|
|
|
|
|
//TODO: viccondetails
|
2023-06-06 15:32:26 +02:00
|
|
|
h & terrain;
|
|
|
|
h & guardingCreaturePositions;
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2014-01-03 02:48:38 +03:00
|
|
|
h & objects;
|
2017-07-31 15:35:42 +02:00
|
|
|
h & heroesOnMap;
|
|
|
|
h & teleportChannels;
|
|
|
|
h & towns;
|
|
|
|
h & artInstances;
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
// static members
|
|
|
|
h & CGKeys::playerKeyMap;
|
|
|
|
h & CGMagi::eyelist;
|
2017-07-31 15:35:42 +02:00
|
|
|
h & CGObelisk::obeliskCount;
|
|
|
|
h & CGObelisk::visited;
|
2012-11-11 15:23:31 +03:00
|
|
|
h & CGTownInstance::merchantArtifacts;
|
2012-12-13 16:07:56 +03:00
|
|
|
h & CGTownInstance::universitySkills;
|
2016-02-22 18:26:42 +02:00
|
|
|
|
2022-06-20 16:39:50 +02:00
|
|
|
h & instanceNames;
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2008-12-27 03:01:59 +02:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|