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

Moved all object-related files to lib/mapObjects directory.

Renamed some classes to more readable names
This commit is contained in:
Ivan Savenko 2014-06-05 14:19:47 +03:00
parent 1d5d4e3248
commit 0afdfa529c
68 changed files with 560 additions and 516 deletions

View File

@ -3,7 +3,7 @@
#include "VCAI.h"
#include "../../lib/UnlockGuard.h"
#include "../../lib/CObjectHandler.h"
#include "../../lib/mapObjects/CObjectHandler.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CHeroHandler.h"

View File

@ -5,7 +5,7 @@
#include "../../lib/CCreatureHandler.h"
#include "../../lib/CTownHandler.h"
#include "../../lib/CSpellHandler.h"
#include "../../lib/CObjectHandler.h"
#include "../../lib/mapObjects/CObjectHandler.h"
#include "../../lib/Connection.h"
#include "../../lib/CGameState.h"
#include "../../lib/mapping/CMap.h"

View File

@ -2,7 +2,7 @@
#include "Fuzzy.h"
#include <limits>
#include "../../lib/CObjectHandler.h"
#include "../../lib/mapObjects/CObjectHandler.h"
#include "../../lib/CCreatureHandler.h"
#include "../../lib/VCMI_Lib.h"
#include "../../CCallback.h"

View File

@ -1,7 +1,7 @@
#pragma once
#include "../../lib/VCMI_Lib.h"
#include "../../lib/CObjectHandler.h"
#include "../../lib/mapObjects/CObjectHandler.h"
#include "../../lib/CBuildingHandler.h"
#include "../../lib/CCreatureHandler.h"
#include "../../lib/CTownHandler.h"

View File

@ -2,8 +2,8 @@
#include "VCAI.h"
#include "Goals.h"
#include "../../lib/UnlockGuard.h"
#include "../../lib/CObjectHandler.h"
#include "../../lib/CObjectWithReward.h"
#include "../../lib/mapObjects/CObjectHandler.h"
#include "../../lib/mapObjects/CRewardableObject.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CHeroHandler.h"

View File

@ -4,7 +4,7 @@
#include "Goals.h"
#include "../../lib/AI_Base.h"
#include "../../CCallback.h"
#include "../../lib/CObjectClassesHandler.h"
#include "../../lib/mapObjects/CObjectClassesHandler.h"
#include "../../lib/CThreadHelper.h"
@ -14,7 +14,7 @@
#include "../../lib/CCreatureHandler.h"
#include "../../lib/CTownHandler.h"
#include "../../lib/CSpellHandler.h"
#include "../../lib/CObjectHandler.h"
#include "../../lib/mapObjects/CObjectHandler.h"
#include "../../lib/Connection.h"
#include "../../lib/CGameState.h"
#include "../../lib/mapping/CMap.h"

View File

@ -9,10 +9,10 @@
#include "client/Client.h"
#include "lib/mapping/CMap.h"
#include "lib/CBuildingHandler.h"
#include "lib/CObjectClassesHandler.h"
#include "lib/mapObjects/CObjectClassesHandler.h"
#include "lib/CGeneralTextHandler.h"
#include "lib/CHeroHandler.h"
#include "lib/CObjectHandler.h"
#include "lib/mapObjects/CObjectHandler.h"
#include "lib/Connection.h"
#include "lib/NetPacks.h"
#include "client/mapHandler.h"

View File

@ -6,7 +6,7 @@
#include "../lib/filesystem/Filesystem.h"
#include "../lib/mapping/CMap.h"
#include "../lib/CModHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/CGameState.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CTownHandler.h"

View File

@ -17,7 +17,7 @@
#include "CDefHandler.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/CTownHandler.h"
#include "../lib/mapping/CMap.h"
#include "../lib/JsonNode.h"

View File

@ -7,7 +7,7 @@
#include "../lib/CCreatureHandler.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CModHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/CSpellHandler.h"
#include "../lib/CTownHandler.h"
#include "CAdvmapInterface.h"

View File

@ -20,7 +20,7 @@
#include "CDefHandler.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/NetPacksBase.h"
#include "gui/CGuiHandler.h"

View File

@ -5,7 +5,7 @@
#include "../lib/CCreatureHandler.h" //creatures name for objects list
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CModHandler.h" //for buildings per turn
#include "../lib/CObjectHandler.h" //Hero/Town objects
#include "../lib/mapObjects/CObjectHandler.h" //Hero/Town objects
#include "../lib/CHeroHandler.h" // only for calculating required xp? worth it?
#include "../lib/CTownHandler.h"
#include "CAnimation.h" //CAnimImage

View File

@ -34,7 +34,7 @@
#include "CMessage.h"
#include "../lib/CModHandler.h"
#include "../lib/CTownHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/CArtHandler.h"
#include "../lib/CScriptingModule.h"
#include "../lib/GameConstants.h"
@ -44,7 +44,7 @@
#ifdef _WIN32
#include "SDL_syswm.h"
#endif
#include "../lib/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/UnlockGuard.h"
#include "CMT.h"

View File

@ -1,5 +1,5 @@
#include "StdInc.h"
#include "../lib/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "CAdvmapInterface.h"
#include "battle/CBattleInterface.h"
#include "battle/CBattleInterfaceClasses.h"
@ -21,7 +21,7 @@
#include "../lib/CArtHandler.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/Connection.h"
#include "../lib/CSpellHandler.h"
#include "../lib/CTownHandler.h"

View File

@ -11,11 +11,11 @@
#include "gui/CCursorHandler.h"
#include "CAnimation.h"
#include "CDefHandler.h"
#include "../lib/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CTownHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/mapping/CCampaignHandler.h"
#include "../lib/CCreatureHandler.h"
#include "../lib/JsonNode.h"

View File

@ -16,7 +16,7 @@
#include "../lib/CGameState.h"
#include "../lib/CArtHandler.h"
#include "../lib/NetPacksBase.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "gui/CGuiHandler.h"
#include "gui/CIntObjectClasses.h"

View File

@ -3,7 +3,7 @@
#include "Graphics.h"
#include "CDefHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/CSpellHandler.h"
#include "../lib/CGeneralTextHandler.h"
#include "CVideoHandler.h"

View File

@ -11,11 +11,11 @@
#include "../lib/BattleState.h"
#include "../lib/CModHandler.h"
#include "../lib/CArtHandler.h"
#include "../lib/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CTownHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/CBuildingHandler.h"
#include "../lib/CSpellHandler.h"
#include "../lib/Connection.h"

View File

@ -24,7 +24,7 @@
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CModHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/CSpellHandler.h"
#include "../lib/CTownHandler.h"
#include "../lib/CondSh.h"

View File

@ -12,13 +12,13 @@
#include "../CCallback.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CTownHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CCreatureHandler.h"
#include "CBitmapHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/CSpellHandler.h"
#include "../lib/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/CGameState.h"
#include "../lib/JsonNode.h"
#include "../lib/vcmi_endian.h"

View File

@ -9,9 +9,9 @@
#include "CGameInfo.h"
#include "../lib/Connection.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/VCMI_Lib.h"
#include "../lib/mapping/CMap.h"
#include "../lib/VCMIDirs.h"

View File

@ -6,7 +6,7 @@
#include "../CAdvmapInterface.h"
#include "../CAnimation.h"
#include "../CBitmapHandler.h"
#include "../../lib/CObjectHandler.h"
#include "../../lib/mapObjects/CObjectHandler.h"
#include "../../lib/CHeroHandler.h"
# include "../CDefHandler.h"
#include "../../lib/CSpellHandler.h"

View File

@ -16,7 +16,7 @@
#include "../../lib/CGeneralTextHandler.h"
#include "../../lib/NetPacks.h"
#include "../../lib/CCreatureHandler.h"
#include "../../lib/CObjectHandler.h"
#include "../../lib/mapObjects/CObjectHandler.h"
#include "../../lib/BattleState.h"
#include "../CMusicHandler.h"
#include "../CVideoHandler.h"

View File

@ -14,12 +14,12 @@
#include "CBitmapHandler.h"
#include "gui/SDL_Extensions.h"
#include "CGameInfo.h"
#include "../lib/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/CGameState.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CTownHandler.h"
#include "Graphics.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/mapping/CMap.h"
#include "CDefHandler.h"
#include "../lib/CConfigHandler.h"

View File

@ -13,7 +13,7 @@
#include <numeric>
#include "VCMI_Lib.h"
#include "CObjectHandler.h"
#include "mapObjects/CObjectHandler.h"
#include "CHeroHandler.h"
#include "CCreatureHandler.h"
#include "CSpellHandler.h"

View File

@ -4,7 +4,7 @@
#include "BattleHex.h"
#include "HeroBonus.h"
#include "CCreatureSet.h"
#include "CObjectHandler.h"
#include "mapObjects/CObjectHandler.h"
#include "CCreatureHandler.h"
#include "CObstacleInstance.h"
#include "ConstTransitivePtr.h"

View File

@ -16,7 +16,7 @@
#include "VCMI_Lib.h"
#include "CModHandler.h"
#include "CSpellHandler.h"
#include "CObjectHandler.h"
#include "mapObjects/CObjectHandler.h"
#include "NetPacksBase.h"
#include "GameConstants.h"
#include "CRandomGenerator.h"

View File

@ -4,7 +4,7 @@
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "CModHandler.h"
#include "CObjectHandler.h"
#include "mapObjects/CObjectHandler.h"
#include "IGameCallback.h"
#include "CGameState.h"
#include "CGeneralTextHandler.h"

View File

@ -12,7 +12,7 @@
#include "CGameInfoCallback.h"
#include "CGameState.h" // PlayerState
#include "CObjectHandler.h" // for CGObjectInstance
#include "mapObjects/CObjectHandler.h" // for CGObjectInstance
#include "StartInfo.h" // for StartInfo
#include "BattleState.h" // for BattleInfo
#include "NetPacks.h" // for InfoWindow

View File

@ -2,14 +2,14 @@
#include "CGameState.h"
#include "mapping/CCampaignHandler.h"
#include "CObjectClassesHandler.h"
#include "mapObjects/CObjectClassesHandler.h"
#include "CArtHandler.h"
#include "CBuildingHandler.h"
#include "CGeneralTextHandler.h"
#include "CTownHandler.h"
#include "CSpellHandler.h"
#include "CHeroHandler.h"
#include "CObjectHandler.h"
#include "mapObjects/CObjectHandler.h"
#include "CCreatureHandler.h"
#include "CModHandler.h"
#include "VCMI_Lib.h"

View File

@ -14,7 +14,7 @@
#include "IGameCallback.h"
#include "ResourceSet.h"
#include "int3.h"
#include "CObjectHandler.h"
#include "mapObjects/CObjectHandler.h"
#include "CRandomGenerator.h"
/*
@ -167,7 +167,7 @@ public:
ObjectInstanceID currentSelection; //id of hero/town, 0xffffffff if none
TeamID team;
TResources resources;
std::set<ObjectInstanceID> visitedObjects; // as a std::set, since most accesses here will be from visited status checks
std::set<ObjectInstanceID> visitedObjects; // as a std::set, since most accesses here will be from visited status checks
std::vector<ConstTransitivePtr<CGHeroInstance> > heroes;
std::vector<ConstTransitivePtr<CGTownInstance> > towns;
std::vector<ConstTransitivePtr<CGHeroInstance> > availableHeroes; //heroes available in taverns
@ -184,7 +184,7 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & color & human & currentSelection & team & resources & status;
h & heroes & towns & availableHeroes & dwellings & visitedObjects;
h & heroes & towns & availableHeroes & dwellings & visitedObjects;
h & getBonusList(); //FIXME FIXME FIXME
h & status & daysWithoutCastle;
h & enteredLosingCheatCode & enteredWinningCheatCode;

View File

@ -10,7 +10,7 @@
#include "CCreatureHandler.h"
#include "CModHandler.h"
#include "CTownHandler.h"
#include "CObjectHandler.h" //for hero specialty
#include "mapObjects/CObjectHandler.h" //for hero specialty
#include <math.h>
/*

View File

@ -9,7 +9,6 @@ set(lib_SRCS
IGameCallback.cpp
CGameInfoCallback.cpp
CGameState.cpp
CObjectHandler.cpp
Connection.cpp
NetPacksLib.cpp
@ -33,6 +32,12 @@ set(lib_SRCS
filesystem/Filesystem.cpp
filesystem/ResourceID.cpp
mapObjects/CObjectClassesHandler.cpp
mapObjects/CObjectHandler.cpp
mapObjects/CRewardableConstructor.cpp
mapObjects/CRewardableObject.cpp
mapObjects/ObjectTemplate.cpp
logging/CBasicLogConfigurator.cpp
logging/CLogger.cpp
@ -63,14 +68,11 @@ set(lib_SRCS
CConsoleHandler.cpp
CCreatureHandler.cpp
CCreatureSet.cpp
CObjectClassesHandler.cpp
CGameInterface.cpp
CGeneralTextHandler.cpp
CHeroHandler.cpp
CModHandler.cpp
CObstacleInstance.cpp
CObjectConstructor.cpp
CObjectWithReward.cpp
CRandomGenerator.cpp
CSpellHandler.cpp
CThreadHelper.cpp

View File

@ -1,6 +1,6 @@
#include "StdInc.h"
#include "CModHandler.h"
#include "CObjectClassesHandler.h"
#include "mapObjects/CObjectClassesHandler.h"
#include "JsonNode.h"
#include "filesystem/Filesystem.h"
#include "filesystem/AdapterLoaders.h"
@ -10,7 +10,7 @@
#include "CArtHandler.h"
#include "CTownHandler.h"
#include "CHeroHandler.h"
#include "CObjectHandler.h"
#include "mapObjects/CObjectHandler.h"
#include "StringConstants.h"
#include "CStopWatch.h"
#include "IHandlerBase.h"

View File

@ -11,8 +11,8 @@
#include "CArtHandler.h"
#include "CSpellHandler.h"
#include "filesystem/Filesystem.h"
#include "CObjectClassesHandler.h"
#include "CObjectHandler.h"
#include "mapObjects/CObjectClassesHandler.h"
#include "mapObjects/CObjectHandler.h"
/*
* CTownHandler.cpp, part of VCMI engine

View File

@ -24,7 +24,7 @@
#include "ConstTransitivePtr.h"
#include "CCreatureSet.h" //for CStackInstance
#include "CObjectHandler.h" //for CArmedInstance
#include "mapObjects/CObjectHandler.h" //for CArmedInstance
#include "mapping/CCampaignHandler.h" //for CCampaignState
#include "rmg/CMapGenerator.h" // for CMapGenOptions

View File

@ -13,7 +13,7 @@
#include "StdInc.h"
#include "VCMI_Lib.h"
#include "CObjectClassesHandler.h"
#include "mapObjects/CObjectClassesHandler.h"
#include "CArtHandler.h"
#include "CCreatureHandler.h"
#include "CSpellHandler.h"

View File

@ -2,10 +2,10 @@
#include "NetPacks.h"
#include "CGeneralTextHandler.h"
#include "CObjectClassesHandler.h"
#include "mapObjects/CObjectClassesHandler.h"
#include "CArtHandler.h"
#include "CHeroHandler.h"
#include "CObjectHandler.h"
#include "mapObjects/CObjectHandler.h"
#include "CModHandler.h"
#include "VCMI_Lib.h"
#include "mapping/CMap.h"

View File

@ -14,9 +14,9 @@
#include "CArtHandler.h"
#include "CBonusTypeHandler.h"
#include "CCreatureHandler.h"
#include "CObjectClassesHandler.h"
#include "mapObjects/CObjectClassesHandler.h"
#include "CHeroHandler.h"
#include "CObjectHandler.h"
#include "mapObjects/CObjectHandler.h"
#include "CTownHandler.h"
#include "CBuildingHandler.h"
#include "CSpellHandler.h"

View File

@ -11,7 +11,7 @@
#include "CModHandler.h"
#include "JsonNode.h"
#include "CObjectConstructor.h"
#include "CRewardableConstructor.h"
/*
* CObjectClassesHandler.cpp, part of VCMI engine
@ -23,314 +23,6 @@
*
*/
static bool isVisitableFromTop(int identifier, int type)
{
if(type == 2 || type == 3 || type == 4 || type == 5) //creature, hero, artifact, resource
return true;
static const Obj visitableFromTop[] =
{Obj::FLOTSAM,
Obj::SEA_CHEST,
Obj::SHIPWRECK_SURVIVOR,
Obj::BUOY,
Obj::OCEAN_BOTTLE,
Obj::BOAT,
Obj::WHIRLPOOL,
Obj::GARRISON,
Obj::GARRISON2,
Obj::SCHOLAR,
Obj::CAMPFIRE,
Obj::BORDERGUARD,
Obj::BORDER_GATE,
Obj::QUEST_GUARD,
Obj::CORPSE
};
if (vstd::find_pos(visitableFromTop, identifier) != -1)
return true;
return false;
}
ObjectTemplate::ObjectTemplate():
visitDir(8|16|32|64|128), // all but top
id(Obj::NO_OBJ),
subid(0),
printPriority(0)
{
}
void ObjectTemplate::readTxt(CLegacyConfigParser & parser)
{
std::string data = parser.readString();
std::vector<std::string> strings;
boost::split(strings, data, boost::is_any_of(" "));
assert(strings.size() == 9);
animationFile = strings[0];
stringID = strings[0];
std::string & blockStr = strings[1]; //block map, 0 = blocked, 1 = unblocked
std::string & visitStr = strings[2]; //visit map, 1 = visitable, 0 = not visitable
assert(blockStr.size() == 6*8);
assert(visitStr.size() == 6*8);
setSize(8, 6);
for (size_t i=0; i<6; i++) // 6 rows
{
for (size_t j=0; j<8; j++) // 8 columns
{
auto & tile = usedTiles[i][j];
tile |= VISIBLE; // assume that all tiles are visible
if (blockStr[i*8 + j] == '0')
tile |= BLOCKED;
if (visitStr[i*8 + j] == '1')
tile |= VISITABLE;
}
}
// strings[3] most likely - terrains on which this object can be placed in editor.
// e.g. Whirpool can be placed manually only on water while mines can be placed everywhere despite terrain-specific gfx
// so these two fields can be interpreted as "strong affinity" and "weak affinity" towards terrains
std::string & terrStr = strings[4]; // allowed terrains, 1 = object can be placed on this terrain
assert(terrStr.size() == 9); // all terrains but rock
for (size_t i=0; i<9; i++)
{
if (terrStr[8-i] == '1')
allowedTerrains.insert(ETerrainType(i));
}
id = Obj(boost::lexical_cast<int>(strings[5]));
subid = boost::lexical_cast<int>(strings[6]);
int type = boost::lexical_cast<int>(strings[7]);
printPriority = boost::lexical_cast<int>(strings[8]) * 100; // to have some space in future
if (isVisitableFromTop(id, type))
visitDir = 0xff;
else
visitDir = (8|16|32|64|128);
readMsk();
}
void ObjectTemplate::readMsk()
{
ResourceID resID("SPRITES/" + animationFile, EResType::MASK);
if (CResourceHandler::get()->existsResource(resID))
{
auto msk = CResourceHandler::get()->load(resID)->readAll();
setSize(msk.first.get()[0], msk.first.get()[1]);
}
else //maximum possible size of H3 object //TODO: remove hardcode and move this data into modding system
{
setSize(8, 6);
}
}
void ObjectTemplate::readMap(CBinaryReader & reader)
{
animationFile = reader.readString();
setSize(8, 6);
ui8 blockMask[6];
ui8 visitMask[6];
for(auto & byte : blockMask)
byte = reader.readUInt8();
for(auto & byte : visitMask)
byte = reader.readUInt8();
for (size_t i=0; i<6; i++) // 6 rows
{
for (size_t j=0; j<8; j++) // 8 columns
{
auto & tile = usedTiles[5 - i][7 - j];
tile |= VISIBLE; // assume that all tiles are visible
if (((blockMask[i] >> j) & 1 ) == 0)
tile |= BLOCKED;
if (((visitMask[i] >> j) & 1 ) != 0)
tile |= VISITABLE;
}
}
reader.readUInt16();
ui16 terrMask = reader.readUInt16();
for (size_t i=0; i<9; i++)
{
if (((terrMask >> i) & 1 ) != 0)
allowedTerrains.insert(ETerrainType(i));
}
id = Obj(reader.readUInt32());
subid = reader.readUInt32();
int type = reader.readUInt8();
printPriority = reader.readUInt8() * 100; // to have some space in future
if (isVisitableFromTop(id, type))
visitDir = 0xff;
else
visitDir = (8|16|32|64|128);
reader.skip(16);
readMsk();
if (id == Obj::EVENT)
{
setSize(1,1);
usedTiles[0][0] = VISITABLE;
}
}
void ObjectTemplate::readJson(const JsonNode &node)
{
//id = Obj(node["basebase"].Float()); // temporary, should be removed and determined indirectly via object type parent (e.g. base->base)
//subid = node["base"].Float();
animationFile = node["animation"].String();
const JsonVector & visitDirs = node["visitableFrom"].Vector();
if (!visitDirs.empty())
{
if (visitDirs[0].String()[0] == '+') visitDir |= 1;
if (visitDirs[0].String()[1] == '+') visitDir |= 2;
if (visitDirs[0].String()[2] == '+') visitDir |= 4;
if (visitDirs[1].String()[2] == '+') visitDir |= 8;
if (visitDirs[2].String()[2] == '+') visitDir |= 16;
if (visitDirs[2].String()[1] == '+') visitDir |= 32;
if (visitDirs[2].String()[0] == '+') visitDir |= 64;
if (visitDirs[1].String()[0] == '+') visitDir |= 128;
}
else
visitDir = 0x00;
if (!node["allowedTerrains"].isNull())
{
for (auto & entry : node["allowedTerrains"].Vector())
allowedTerrains.insert(ETerrainType(vstd::find_pos(GameConstants::TERRAIN_NAMES, entry.String())));
}
else
{
for (size_t i=0; i< GameConstants::TERRAIN_TYPES; i++)
allowedTerrains.insert(ETerrainType(i));
}
auto charToTile = [&](const char & ch) -> ui8
{
switch (ch)
{
case ' ' : return 0;
case '0' : return 0;
case 'V' : return VISIBLE;
case 'B' : return VISIBLE | BLOCKED;
case 'H' : return BLOCKED;
case 'A' : return VISIBLE | BLOCKED | VISITABLE;
case 'T' : return BLOCKED | VISITABLE;
default:
logGlobal->errorStream() << "Unrecognized char " << ch << " in template mask";
return 0;
}
};
const JsonVector & mask = node["mask"].Vector();
size_t height = mask.size();
size_t width = 0;
for (auto & line : mask)
vstd::amax(width, line.String().size());
setSize(width, height);
for (size_t i=0; i<mask.size(); i++)
{
const std::string & line = mask[i].String();
for (size_t j=0; j < line.size(); j++)
usedTiles[mask.size() - 1 - i][line.size() - 1 - j] = charToTile(line[j]);
}
printPriority = node["zIndex"].Float();
}
ui32 ObjectTemplate::getWidth() const
{
return usedTiles.empty() ? 0 : usedTiles.front().size();
}
ui32 ObjectTemplate::getHeight() const
{
return usedTiles.size();
}
void ObjectTemplate::setSize(ui32 width, ui32 height)
{
usedTiles.resize(height);
for (auto & line : usedTiles)
line.resize(width, 0);
}
bool ObjectTemplate::isVisitable() const
{
for (auto & line : usedTiles)
for (auto & tile : line)
if (tile & VISITABLE)
return true;
return false;
}
bool ObjectTemplate::isWithin(si32 X, si32 Y) const
{
if (X < 0 || Y < 0)
return false;
if (X >= getWidth() || Y >= getHeight())
return false;
return true;
}
bool ObjectTemplate::isVisitableAt(si32 X, si32 Y) const
{
if (isWithin(X, Y))
return usedTiles[Y][X] & VISITABLE;
return false;
}
bool ObjectTemplate::isVisibleAt(si32 X, si32 Y) const
{
if (isWithin(X, Y))
return usedTiles[Y][X] & VISIBLE;
return false;
}
bool ObjectTemplate::isBlockedAt(si32 X, si32 Y) const
{
if (isWithin(X, Y))
return usedTiles[Y][X] & BLOCKED;
return false;
}
bool ObjectTemplate::isVisitableFrom(si8 X, si8 Y) const
{
// visitDir uses format
// 1 2 3
// 8 4
// 7 6 5
int dirMap[3][3] =
{
{ visitDir & 1, visitDir & 2, visitDir & 4 },
{ visitDir & 128, 1 , visitDir & 8 },
{ visitDir & 64, visitDir & 32, visitDir & 16 }
};
// map input values to range 0..2
int dx = X < 0 ? 0 : X == 0 ? 1 : 2;
int dy = Y < 0 ? 0 : Y == 0 ? 1 : 2;
return dirMap[dy][dx] != 0;
}
bool ObjectTemplate::canBePlacedAt(ETerrainType terrain) const
{
return allowedTerrains.count(terrain) != 0;
}
CObjectClassesHandler::CObjectClassesHandler()
{
#define SET_HANDLER_CLASS(STRING, CLASSNAME) handlerConstructors[STRING] = std::make_shared<CLASSNAME>;
@ -338,7 +30,7 @@ CObjectClassesHandler::CObjectClassesHandler()
// list of all known handlers, hardcoded for now since the only way to add new objects is via C++ code
//WARNING: should be in sync with registerTypesMapObjectTypes function
SET_HANDLER_CLASS("configurable", CObjectWithRewardConstructor);
SET_HANDLER_CLASS("configurable", CRewardableConstructor);
SET_HANDLER("", CGObjectInstance);
SET_HANDLER("generic", CGObjectInstance);

View File

@ -3,6 +3,7 @@
#include "GameConstants.h"
#include "../lib/ConstTransitivePtr.h"
#include "IHandlerBase.h"
#include "ObjectTemplate.h"
/*
* CObjectClassesHandler.h, part of VCMI engine
@ -14,72 +15,9 @@
*
*/
class CBinaryReader;
class CLegacyConfigParser;
class JsonNode;
class CRandomGenerator;
class DLL_LINKAGE ObjectTemplate
{
enum EBlockMapBits
{
VISIBLE = 1,
VISITABLE = 2,
BLOCKED = 4
};
/// tiles that are covered by this object, uses EBlockMapBits enum as flags
std::vector<std::vector<ui8>> usedTiles;
/// directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7)
ui8 visitDir;
/// list of terrains on which this object can be placed
std::set<ETerrainType> allowedTerrains;
public:
/// H3 ID/subID of this object
Obj id;
si32 subid;
/// print priority, objects with higher priority will be print first, below everything else
si32 printPriority;
/// animation file that should be used to display object
std::string animationFile;
/// string ID, equals to def base name for h3m files (lower case, no extension) or specified in mod data
std::string stringID;
ui32 getWidth() const;
ui32 getHeight() const;
void setSize(ui32 width, ui32 height);
bool isVisitable() const;
// Checks object used tiles
// Position is relative to bottom-right corner of the object, can not be negative
bool isWithin(si32 X, si32 Y) const;
bool isVisitableAt(si32 X, si32 Y) const;
bool isVisibleAt(si32 X, si32 Y) const;
bool isBlockedAt(si32 X, si32 Y) const;
// Checks if object is visitable from certain direction. X and Y must be between -1..+1
bool isVisitableFrom(si8 X, si8 Y) const;
// Checks if object can be placed on specific terrain
bool canBePlacedAt(ETerrainType terrain) const;
ObjectTemplate();
void readTxt(CLegacyConfigParser & parser);
void readMsk();
void readMap(CBinaryReader & reader);
void readJson(const JsonNode & node);
template <typename Handler> void serialize(Handler &h, const int version)
{
h & usedTiles & allowedTerrains & animationFile & stringID;
h & id & subid & printPriority & visitDir;
}
};
class IObjectInfo
{
public:

View File

@ -2,7 +2,7 @@
#include "../lib/CCreatureSet.h"
#include "../lib/CTownHandler.h"
#include "../lib/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "CArtHandler.h"
#include "../lib/ConstTransitivePtr.h"
#include "int3.h"

View File

@ -1,5 +1,5 @@
#include "StdInc.h"
#include "CObjectConstructor.h"
#include "CRewardableConstructor.h"
#include "CRandomGenerator.h"
#include "StringConstants.h"
@ -136,7 +136,7 @@ void CRandomRewardObjectInfo::init(const JsonNode & objectConfig)
parameters = objectConfig;
}
void CRandomRewardObjectInfo::configureObject(CObjectWithReward * object, CRandomGenerator & rng) const
void CRandomRewardObjectInfo::configureObject(CRewardableObject * object, CRandomGenerator & rng) const
{
std::map<si32, si32> thrownDice;
@ -262,29 +262,29 @@ bool CRandomRewardObjectInfo::givesBonuses() const
return testForKey(parameters, "bonuses");
}
CObjectWithRewardConstructor::CObjectWithRewardConstructor()
CRewardableConstructor::CRewardableConstructor()
{
}
void CObjectWithRewardConstructor::init(const JsonNode & config)
void CRewardableConstructor::init(const JsonNode & config)
{
AObjectTypeHandler::init(config);
objectInfo.init(config);
}
CGObjectInstance * CObjectWithRewardConstructor::create(ObjectTemplate tmpl) const
CGObjectInstance * CRewardableConstructor::create(ObjectTemplate tmpl) const
{
auto ret = new CObjectWithReward();
auto ret = new CRewardableObject();
ret->appearance = tmpl;
return ret;
}
void CObjectWithRewardConstructor::configureObject(CGObjectInstance * object, CRandomGenerator & rng) const
void CRewardableConstructor::configureObject(CGObjectInstance * object, CRandomGenerator & rng) const
{
objectInfo.configureObject(dynamic_cast<CObjectWithReward*>(object), rng);
objectInfo.configureObject(dynamic_cast<CRewardableObject*>(object), rng);
}
const IObjectInfo * CObjectWithRewardConstructor::getObjectInfo(ObjectTemplate tmpl) const
const IObjectInfo * CRewardableConstructor::getObjectInfo(ObjectTemplate tmpl) const
{
return &objectInfo;
}

View File

@ -1,6 +1,6 @@
#pragma once
#include "CObjectWithReward.h"
#include "mapObjects/CRewardableObject.h"
#include "CObjectClassesHandler.h"
#include "JsonNode.h"
@ -33,7 +33,7 @@ public:
bool givesBonuses() const override;
void configureObject(CObjectWithReward * object, CRandomGenerator & rng) const;
void configureObject(CRewardableObject * object, CRandomGenerator & rng) const;
CRandomRewardObjectInfo()
{}
@ -41,12 +41,12 @@ public:
void init(const JsonNode & objectConfig);
};
class CObjectWithRewardConstructor : public AObjectTypeHandler
class CRewardableConstructor : public AObjectTypeHandler
{
CRandomRewardObjectInfo objectInfo;
public:
CObjectWithRewardConstructor();
CRewardableConstructor();
void init(const JsonNode & config) override;
CGObjectInstance * create(ObjectTemplate tmpl) const override;

View File

@ -1,5 +1,5 @@
/*
* CObjectWithReward.cpp, part of VCMI engine
* CRewardableObject.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
@ -9,7 +9,7 @@
*/
#include "StdInc.h"
#include "CObjectWithReward.h"
#include "CRewardableObject.h"
#include "CHeroHandler.h"
#include "CGeneralTextHandler.h"
#include "../client/CSoundBase.h"
@ -63,7 +63,7 @@ bool CRewardLimiter::heroAllowed(const CGHeroInstance * hero) const
return true;
}
std::vector<ui32> CObjectWithReward::getAvailableRewards(const CGHeroInstance * hero) const
std::vector<ui32> CRewardableObject::getAvailableRewards(const CGHeroInstance * hero) const
{
std::vector<ui32> ret;
@ -79,7 +79,7 @@ std::vector<ui32> CObjectWithReward::getAvailableRewards(const CGHeroInstance *
return ret;
}
void CObjectWithReward::onHeroVisit(const CGHeroInstance *h) const
void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
{
auto grantRewardWithMessage = [&](int index) -> void
{
@ -161,12 +161,12 @@ void CObjectWithReward::onHeroVisit(const CGHeroInstance *h) const
}
}
void CObjectWithReward::heroLevelUpDone(const CGHeroInstance *hero) const
void CRewardableObject::heroLevelUpDone(const CGHeroInstance *hero) const
{
grantRewardAfterLevelup(info[selectedReward], hero);
}
void CObjectWithReward::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
void CRewardableObject::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
{
if (answer == 0)
return; // player refused
@ -183,12 +183,12 @@ void CObjectWithReward::blockingDialogAnswered(const CGHeroInstance *hero, ui32
}
}
void CObjectWithReward::onRewardGiven(const CGHeroInstance * hero) const
void CRewardableObject::onRewardGiven(const CGHeroInstance * hero) const
{
// no implementation, virtual function for overrides
}
void CObjectWithReward::grantReward(ui32 rewardID, const CGHeroInstance * hero) const
void CRewardableObject::grantReward(ui32 rewardID, const CGHeroInstance * hero) const
{
ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD, id, hero->id);
cb->sendAndApply(&cov);
@ -197,7 +197,7 @@ void CObjectWithReward::grantReward(ui32 rewardID, const CGHeroInstance * hero)
grantRewardBeforeLevelup(info[rewardID], hero);
}
void CObjectWithReward::grantRewardBeforeLevelup(const CVisitInfo & info, const CGHeroInstance * hero) const
void CRewardableObject::grantRewardBeforeLevelup(const CVisitInfo & info, const CGHeroInstance * hero) const
{
assert(hero);
assert(hero->tempOwner.isValidPlayer());
@ -234,7 +234,7 @@ void CObjectWithReward::grantRewardBeforeLevelup(const CVisitInfo & info, const
}
}
void CObjectWithReward::grantRewardAfterLevelup(const CVisitInfo & info, const CGHeroInstance * hero) const
void CRewardableObject::grantRewardAfterLevelup(const CVisitInfo & info, const CGHeroInstance * hero) const
{
if (info.reward.manaDiff || info.reward.manaPercentage >= 0)
{
@ -290,7 +290,7 @@ void CObjectWithReward::grantRewardAfterLevelup(const CVisitInfo & info, const C
cb->removeObject(this);
}
bool CObjectWithReward::wasVisited (PlayerColor player) const
bool CRewardableObject::wasVisited (PlayerColor player) const
{
switch (visitMode)
{
@ -311,7 +311,7 @@ bool CObjectWithReward::wasVisited (PlayerColor player) const
}
}
bool CObjectWithReward::wasVisited (const CGHeroInstance * h) const
bool CRewardableObject::wasVisited (const CGHeroInstance * h) const
{
switch (visitMode)
{
@ -372,7 +372,7 @@ static std::string & visitedTxt(const bool visited)
return VLC->generaltexth->allTexts[id];
}
const std::string & CObjectWithReward::getHoverText() const
const std::string & CRewardableObject::getHoverText() const
{
const CGHeroInstance *h = cb->getSelectedHero(cb->getCurrentPlayer());
hoverName = VLC->objtypeh->getObjectName(ID);
@ -387,7 +387,7 @@ const std::string & CObjectWithReward::getHoverText() const
return hoverName;
}
void CObjectWithReward::setPropertyDer(ui8 what, ui32 val)
void CRewardableObject::setPropertyDer(ui8 what, ui32 val)
{
switch (what)
{
@ -402,13 +402,13 @@ void CObjectWithReward::setPropertyDer(ui8 what, ui32 val)
}
}
void CObjectWithReward::newTurn() const
void CRewardableObject::newTurn() const
{
if (resetDuration != 0 && cb->getDate(Date::DAY) % resetDuration == 0)
cb->setObjProperty(id, ObjProperty::REWARD_RESET, 0);
}
CObjectWithReward::CObjectWithReward():
CRewardableObject::CRewardableObject():
soundID(soundBase::invalid),
selectMode(0),
selectedReward(0),
@ -417,7 +417,7 @@ CObjectWithReward::CObjectWithReward():
{}
///////////////////////////////////////////////////////////////////////////////////////////////////
/// END OF CODE FOR COBJECTWITHREWARD AND RELATED CLASSES ///
/// END OF CODE FOR CREWARDABLEOBJECT AND RELATED CLASSES ///
///////////////////////////////////////////////////////////////////////////////////////////////////
/// Helper, selects random art class based on weights

View File

@ -4,7 +4,7 @@
#include "NetPacksBase.h"
/*
* CObjectWithReward.h, part of VCMI engine
* CRewardableObject.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
@ -153,7 +153,7 @@ public:
/// Base class that can handle granting rewards to visiting heroes.
/// Inherits from CArmedInstance for proper trasfer of armies
class DLL_LINKAGE CObjectWithReward : public CArmedInstance
class DLL_LINKAGE CRewardableObject : public CArmedInstance
{
/// function that must be called if hero got level-up during grantReward call
void grantRewardAfterLevelup(const CVisitInfo & reward, const CGHeroInstance * hero) const;
@ -228,7 +228,7 @@ public:
/// function that will be called once reward is fully granted to hero
virtual void onRewardGiven(const CGHeroInstance * hero) const;
CObjectWithReward();
CRewardableObject();
template <typename Handler> void serialize(Handler &h, const int version)
{
@ -242,7 +242,7 @@ public:
friend class CRandomRewardObjectInfo;
};
class DLL_LINKAGE CGPickable : public CObjectWithReward //campfire, treasure chest, Flotsam, Shipwreck Survivor, Sea Chest
class DLL_LINKAGE CGPickable : public CRewardableObject //campfire, treasure chest, Flotsam, Shipwreck Survivor, Sea Chest
{
public:
void initObj() override;
@ -251,11 +251,11 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CObjectWithReward&>(*this);
h & static_cast<CRewardableObject&>(*this);
}
};
class DLL_LINKAGE CGBonusingObject : public CObjectWithReward //objects giving bonuses to luck/morale/movement
class DLL_LINKAGE CGBonusingObject : public CRewardableObject //objects giving bonuses to luck/morale/movement
{
public:
void initObj() override;
@ -268,7 +268,7 @@ public:
}
};
class DLL_LINKAGE CGOnceVisitable : public CObjectWithReward // wagon, corpse, lean to, warriors tomb
class DLL_LINKAGE CGOnceVisitable : public CRewardableObject // wagon, corpse, lean to, warriors tomb
{
public:
void initObj() override;
@ -277,11 +277,11 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CObjectWithReward&>(*this);
h & static_cast<CRewardableObject&>(*this);
}
};
class DLL_LINKAGE CGVisitableOPH : public CObjectWithReward //objects visitable only once per hero
class DLL_LINKAGE CGVisitableOPH : public CRewardableObject //objects visitable only once per hero
{
public:
void initObj() override;
@ -290,11 +290,11 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CObjectWithReward&>(*this);
h & static_cast<CRewardableObject&>(*this);
}
};
class DLL_LINKAGE CGVisitableOPW : public CObjectWithReward //objects visitable once per week
class DLL_LINKAGE CGVisitableOPW : public CRewardableObject //objects visitable once per week
{
public:
void initObj() override;
@ -303,7 +303,7 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CObjectWithReward&>(*this);
h & static_cast<CRewardableObject&>(*this);
}
};

View File

@ -0,0 +1,333 @@
#include "StdInc.h"
#include "CObjectClassesHandler.h"
#include "filesystem/Filesystem.h"
#include "filesystem/CBinaryReader.h"
#include "../lib/VCMI_Lib.h"
#include "GameConstants.h"
#include "StringConstants.h"
#include "CGeneralTextHandler.h"
#include "CObjectHandler.h"
#include "CModHandler.h"
#include "JsonNode.h"
#include "CRewardableConstructor.h"
/*
* ObjectTemplate.cpp, 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
*
*/
static bool isVisitableFromTop(int identifier, int type)
{
if(type == 2 || type == 3 || type == 4 || type == 5) //creature, hero, artifact, resource
return true;
static const Obj visitableFromTop[] =
{Obj::FLOTSAM,
Obj::SEA_CHEST,
Obj::SHIPWRECK_SURVIVOR,
Obj::BUOY,
Obj::OCEAN_BOTTLE,
Obj::BOAT,
Obj::WHIRLPOOL,
Obj::GARRISON,
Obj::GARRISON2,
Obj::SCHOLAR,
Obj::CAMPFIRE,
Obj::BORDERGUARD,
Obj::BORDER_GATE,
Obj::QUEST_GUARD,
Obj::CORPSE
};
if (vstd::find_pos(visitableFromTop, identifier) != -1)
return true;
return false;
}
ObjectTemplate::ObjectTemplate():
visitDir(8|16|32|64|128), // all but top
id(Obj::NO_OBJ),
subid(0),
printPriority(0)
{
}
void ObjectTemplate::readTxt(CLegacyConfigParser & parser)
{
std::string data = parser.readString();
std::vector<std::string> strings;
boost::split(strings, data, boost::is_any_of(" "));
assert(strings.size() == 9);
animationFile = strings[0];
stringID = strings[0];
std::string & blockStr = strings[1]; //block map, 0 = blocked, 1 = unblocked
std::string & visitStr = strings[2]; //visit map, 1 = visitable, 0 = not visitable
assert(blockStr.size() == 6*8);
assert(visitStr.size() == 6*8);
setSize(8, 6);
for (size_t i=0; i<6; i++) // 6 rows
{
for (size_t j=0; j<8; j++) // 8 columns
{
auto & tile = usedTiles[i][j];
tile |= VISIBLE; // assume that all tiles are visible
if (blockStr[i*8 + j] == '0')
tile |= BLOCKED;
if (visitStr[i*8 + j] == '1')
tile |= VISITABLE;
}
}
// strings[3] most likely - terrains on which this object can be placed in editor.
// e.g. Whirpool can be placed manually only on water while mines can be placed everywhere despite terrain-specific gfx
// so these two fields can be interpreted as "strong affinity" and "weak affinity" towards terrains
std::string & terrStr = strings[4]; // allowed terrains, 1 = object can be placed on this terrain
assert(terrStr.size() == 9); // all terrains but rock
for (size_t i=0; i<9; i++)
{
if (terrStr[8-i] == '1')
allowedTerrains.insert(ETerrainType(i));
}
id = Obj(boost::lexical_cast<int>(strings[5]));
subid = boost::lexical_cast<int>(strings[6]);
int type = boost::lexical_cast<int>(strings[7]);
printPriority = boost::lexical_cast<int>(strings[8]) * 100; // to have some space in future
if (isVisitableFromTop(id, type))
visitDir = 0xff;
else
visitDir = (8|16|32|64|128);
readMsk();
}
void ObjectTemplate::readMsk()
{
ResourceID resID("SPRITES/" + animationFile, EResType::MASK);
if (CResourceHandler::get()->existsResource(resID))
{
auto msk = CResourceHandler::get()->load(resID)->readAll();
setSize(msk.first.get()[0], msk.first.get()[1]);
}
else //maximum possible size of H3 object //TODO: remove hardcode and move this data into modding system
{
setSize(8, 6);
}
}
void ObjectTemplate::readMap(CBinaryReader & reader)
{
animationFile = reader.readString();
setSize(8, 6);
ui8 blockMask[6];
ui8 visitMask[6];
for(auto & byte : blockMask)
byte = reader.readUInt8();
for(auto & byte : visitMask)
byte = reader.readUInt8();
for (size_t i=0; i<6; i++) // 6 rows
{
for (size_t j=0; j<8; j++) // 8 columns
{
auto & tile = usedTiles[5 - i][7 - j];
tile |= VISIBLE; // assume that all tiles are visible
if (((blockMask[i] >> j) & 1 ) == 0)
tile |= BLOCKED;
if (((visitMask[i] >> j) & 1 ) != 0)
tile |= VISITABLE;
}
}
reader.readUInt16();
ui16 terrMask = reader.readUInt16();
for (size_t i=0; i<9; i++)
{
if (((terrMask >> i) & 1 ) != 0)
allowedTerrains.insert(ETerrainType(i));
}
id = Obj(reader.readUInt32());
subid = reader.readUInt32();
int type = reader.readUInt8();
printPriority = reader.readUInt8() * 100; // to have some space in future
if (isVisitableFromTop(id, type))
visitDir = 0xff;
else
visitDir = (8|16|32|64|128);
reader.skip(16);
readMsk();
if (id == Obj::EVENT)
{
setSize(1,1);
usedTiles[0][0] = VISITABLE;
}
}
void ObjectTemplate::readJson(const JsonNode &node)
{
//id = Obj(node["basebase"].Float()); // temporary, should be removed and determined indirectly via object type parent (e.g. base->base)
//subid = node["base"].Float();
animationFile = node["animation"].String();
const JsonVector & visitDirs = node["visitableFrom"].Vector();
if (!visitDirs.empty())
{
if (visitDirs[0].String()[0] == '+') visitDir |= 1;
if (visitDirs[0].String()[1] == '+') visitDir |= 2;
if (visitDirs[0].String()[2] == '+') visitDir |= 4;
if (visitDirs[1].String()[2] == '+') visitDir |= 8;
if (visitDirs[2].String()[2] == '+') visitDir |= 16;
if (visitDirs[2].String()[1] == '+') visitDir |= 32;
if (visitDirs[2].String()[0] == '+') visitDir |= 64;
if (visitDirs[1].String()[0] == '+') visitDir |= 128;
}
else
visitDir = 0x00;
if (!node["allowedTerrains"].isNull())
{
for (auto & entry : node["allowedTerrains"].Vector())
allowedTerrains.insert(ETerrainType(vstd::find_pos(GameConstants::TERRAIN_NAMES, entry.String())));
}
else
{
for (size_t i=0; i< GameConstants::TERRAIN_TYPES; i++)
allowedTerrains.insert(ETerrainType(i));
}
auto charToTile = [&](const char & ch) -> ui8
{
switch (ch)
{
case ' ' : return 0;
case '0' : return 0;
case 'V' : return VISIBLE;
case 'B' : return VISIBLE | BLOCKED;
case 'H' : return BLOCKED;
case 'A' : return VISIBLE | BLOCKED | VISITABLE;
case 'T' : return BLOCKED | VISITABLE;
default:
logGlobal->errorStream() << "Unrecognized char " << ch << " in template mask";
return 0;
}
};
const JsonVector & mask = node["mask"].Vector();
size_t height = mask.size();
size_t width = 0;
for (auto & line : mask)
vstd::amax(width, line.String().size());
setSize(width, height);
for (size_t i=0; i<mask.size(); i++)
{
const std::string & line = mask[i].String();
for (size_t j=0; j < line.size(); j++)
usedTiles[mask.size() - 1 - i][line.size() - 1 - j] = charToTile(line[j]);
}
printPriority = node["zIndex"].Float();
}
ui32 ObjectTemplate::getWidth() const
{
return usedTiles.empty() ? 0 : usedTiles.front().size();
}
ui32 ObjectTemplate::getHeight() const
{
return usedTiles.size();
}
void ObjectTemplate::setSize(ui32 width, ui32 height)
{
usedTiles.resize(height);
for (auto & line : usedTiles)
line.resize(width, 0);
}
bool ObjectTemplate::isVisitable() const
{
for (auto & line : usedTiles)
for (auto & tile : line)
if (tile & VISITABLE)
return true;
return false;
}
bool ObjectTemplate::isWithin(si32 X, si32 Y) const
{
if (X < 0 || Y < 0)
return false;
if (X >= getWidth() || Y >= getHeight())
return false;
return true;
}
bool ObjectTemplate::isVisitableAt(si32 X, si32 Y) const
{
if (isWithin(X, Y))
return usedTiles[Y][X] & VISITABLE;
return false;
}
bool ObjectTemplate::isVisibleAt(si32 X, si32 Y) const
{
if (isWithin(X, Y))
return usedTiles[Y][X] & VISIBLE;
return false;
}
bool ObjectTemplate::isBlockedAt(si32 X, si32 Y) const
{
if (isWithin(X, Y))
return usedTiles[Y][X] & BLOCKED;
return false;
}
bool ObjectTemplate::isVisitableFrom(si8 X, si8 Y) const
{
// visitDir uses format
// 1 2 3
// 8 4
// 7 6 5
int dirMap[3][3] =
{
{ visitDir & 1, visitDir & 2, visitDir & 4 },
{ visitDir & 128, 1 , visitDir & 8 },
{ visitDir & 64, visitDir & 32, visitDir & 16 }
};
// map input values to range 0..2
int dx = X < 0 ? 0 : X == 0 ? 1 : 2;
int dy = Y < 0 ? 0 : Y == 0 ? 1 : 2;
return dirMap[dy][dx] != 0;
}
bool ObjectTemplate::canBePlacedAt(ETerrainType terrain) const
{
return allowedTerrains.count(terrain) != 0;
}

View File

@ -0,0 +1,79 @@
#pragma once
#include "GameConstants.h"
/*
* ObjectTemplate.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
*
*/
class CBinaryReader;
class CLegacyConfigParser;
class JsonNode;
class DLL_LINKAGE ObjectTemplate
{
enum EBlockMapBits
{
VISIBLE = 1,
VISITABLE = 2,
BLOCKED = 4
};
/// tiles that are covered by this object, uses EBlockMapBits enum as flags
std::vector<std::vector<ui8>> usedTiles;
/// directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7)
ui8 visitDir;
/// list of terrains on which this object can be placed
std::set<ETerrainType> allowedTerrains;
public:
/// H3 ID/subID of this object
Obj id;
si32 subid;
/// print priority, objects with higher priority will be print first, below everything else
si32 printPriority;
/// animation file that should be used to display object
std::string animationFile;
/// string ID, equals to def base name for h3m files (lower case, no extension) or specified in mod data
std::string stringID;
ui32 getWidth() const;
ui32 getHeight() const;
void setSize(ui32 width, ui32 height);
bool isVisitable() const;
// Checks object used tiles
// Position is relative to bottom-right corner of the object, can not be negative
bool isWithin(si32 X, si32 Y) const;
bool isVisitableAt(si32 X, si32 Y) const;
bool isVisibleAt(si32 X, si32 Y) const;
bool isBlockedAt(si32 X, si32 Y) const;
// Checks if object is visitable from certain direction. X and Y must be between -1..+1
bool isVisitableFrom(si8 X, si8 Y) const;
// Checks if object can be placed on specific terrain
bool canBePlacedAt(ETerrainType terrain) const;
ObjectTemplate();
void readTxt(CLegacyConfigParser & parser);
void readMsk();
void readMap(CBinaryReader & reader);
void readJson(const JsonNode & node);
template <typename Handler> void serialize(Handler &h, const int version)
{
h & usedTiles & allowedTerrains & animationFile & stringID;
h & id & subid & printPriority & visitDir;
}
};

View File

@ -10,7 +10,7 @@
#include "../CGeneralTextHandler.h"
#include "../StartInfo.h"
#include "../CArtHandler.h" //for hero crossover
#include "../CObjectHandler.h" //for hero crossover
#include "../mapObjects/CObjectHandler.h" //for hero crossover
#include "../CHeroHandler.h"
#include "CMapService.h"
#include "CMap.h"

View File

@ -6,7 +6,7 @@
#include "../CCreatureHandler.h"
#include "../CTownHandler.h"
#include "../CHeroHandler.h"
#include "../CObjectClassesHandler.h"
#include "../mapObjects/CObjectClassesHandler.h"
#include "../CGeneralTextHandler.h"
#include "../CSpellHandler.h"
#include "CMapEditManager.h"

View File

@ -12,7 +12,7 @@
#pragma once
#include "../ConstTransitivePtr.h"
#include "../CObjectHandler.h"
#include "../mapObjects/CObjectHandler.h"
#include "../ResourceSet.h"
#include "../int3.h"
#include "../GameConstants.h"

View File

@ -3,7 +3,7 @@
#include "../JsonNode.h"
#include "../filesystem/Filesystem.h"
#include "../CObjectClassesHandler.h"
#include "../mapObjects/CObjectClassesHandler.h"
#include "../VCMI_Lib.h"
MapRect::MapRect() : x(0), y(0), z(0), width(0), height(0)

View File

@ -20,9 +20,9 @@
#include "../CCreatureHandler.h"
#include "../CGeneralTextHandler.h"
#include "../CHeroHandler.h"
#include "../CObjectHandler.h"
#include "../CObjectWithReward.h"
#include "../CObjectClassesHandler.h"
#include "../mapObjects/CObjectHandler.h"
#include "../mapObjects/CRewardableObject.h"
#include "../mapObjects/CObjectClassesHandler.h"
#include "../VCMI_Lib.h"
#include "../NetPacksBase.h"

View File

@ -14,7 +14,7 @@
#include "CMapService.h"
#include "../GameConstants.h"
#include "../ResourceSet.h"
#include "../CObjectClassesHandler.h"
#include "../mapObjects/CObjectClassesHandler.h"
#include "../int3.h"

View File

@ -8,7 +8,7 @@
#include "../CGameState.h"
#include "../mapping/CMap.h"
#include "../CModHandler.h"
#include "../CObjectHandler.h"
#include "../mapObjects/CObjectHandler.h"
#include "../CCreatureHandler.h"
#include "../VCMI_Lib.h"
#include "../CArtHandler.h"
@ -17,7 +17,7 @@
#include "../CTownHandler.h"
#include "../mapping/CCampaignHandler.h"
#include "../NetPacks.h"
#include "../CObjectClassesHandler.h"
#include "../mapObjects/CObjectClassesHandler.h"
// For reference: peak memory usage by gcc during compilation of register type templates
// registerTypesMapObjects: 1.9 Gb

View File

@ -4,14 +4,14 @@
#include "../NetPacks.h"
#include "../VCMI_Lib.h"
#include "../CArtHandler.h"
#include "../CObjectHandler.h"
#include "../CObjectWithReward.h"
#include "../mapObjects/CObjectHandler.h"
#include "../mapObjects/CRewardableObject.h"
#include "../CGameState.h"
#include "../CHeroHandler.h"
#include "../CTownHandler.h"
#include "../CModHandler.h" //needed?
#include "../CObjectClassesHandler.h"
#include "../CObjectConstructor.h"
#include "../mapObjects/CObjectClassesHandler.h"
#include "../mapObjects/CRewardableConstructor.h"
/*
* RegisterTypes.h, part of VCMI engine
@ -77,7 +77,7 @@ void registerTypesMapObjects1(Serializer &s)
template<typename Serializer>
void registerTypesMapObjectTypes(Serializer &s)
{
s.template registerType<AObjectTypeHandler, CObjectWithRewardConstructor>();
s.template registerType<AObjectTypeHandler, CRewardableConstructor>();
#define REGISTER_GENERIC_HANDLER(TYPENAME) s.template registerType<AObjectTypeHandler, CDefaultObjectTypeHandler<TYPENAME> >()
@ -137,11 +137,11 @@ void registerTypesMapObjects2(Serializer &s)
s.template registerType<CGTownBuilding, CTownBonus>();
s.template registerType<CGTownBuilding, COPWBonus>();
s.template registerType<CGObjectInstance, CObjectWithReward>();
s.template registerType<CObjectWithReward, CGPickable>();
s.template registerType<CObjectWithReward, CGVisitableOPH>();
s.template registerType<CObjectWithReward, CGVisitableOPW>();
s.template registerType<CObjectWithReward, CGOnceVisitable>();
s.template registerType<CGObjectInstance, CRewardableObject>();
s.template registerType<CRewardableObject, CGPickable>();
s.template registerType<CRewardableObject, CGVisitableOPH>();
s.template registerType<CRewardableObject, CGVisitableOPW>();
s.template registerType<CRewardableObject, CGOnceVisitable>();
s.template registerType<CGVisitableOPW, CGMagicSpring>();
s.template registerType<CGObjectInstance, CPlayersVisited>();

View File

@ -7,7 +7,7 @@
#include "../CGameState.h"
#include "../mapping/CMap.h"
#include "../CModHandler.h"
#include "../CObjectHandler.h"
#include "../mapObjects/CObjectHandler.h"
#include "../CCreatureHandler.h"
#include "../VCMI_Lib.h"
#include "../CArtHandler.h"
@ -16,7 +16,7 @@
#include "../CTownHandler.h"
#include "../mapping/CCampaignHandler.h"
#include "../NetPacks.h"
#include "../CObjectClassesHandler.h"
#include "../mapObjects/CObjectClassesHandler.h"
template void registerTypesClientPacks1<CISer<CConnection>>(CISer<CConnection>& s);

View File

@ -7,7 +7,7 @@
#include "../CGameState.h"
#include "../mapping/CMap.h"
#include "../CModHandler.h"
#include "../CObjectHandler.h"
#include "../mapObjects/CObjectHandler.h"
#include "../CCreatureHandler.h"
#include "../VCMI_Lib.h"
#include "../CArtHandler.h"
@ -16,7 +16,7 @@
#include "../CTownHandler.h"
#include "../mapping/CCampaignHandler.h"
#include "../NetPacks.h"
#include "../CObjectClassesHandler.h"
#include "../mapObjects/CObjectClassesHandler.h"
template void registerTypesClientPacks2<CISer<CConnection>>(CISer<CConnection>& s);

View File

@ -7,7 +7,7 @@
#include "../CGameState.h"
#include "../mapping/CMap.h"
#include "../CModHandler.h"
#include "../CObjectHandler.h"
#include "../mapObjects/CObjectHandler.h"
#include "../CCreatureHandler.h"
#include "../VCMI_Lib.h"
#include "../CArtHandler.h"
@ -16,7 +16,7 @@
#include "../CTownHandler.h"
#include "../mapping/CCampaignHandler.h"
#include "../NetPacks.h"
#include "../CObjectClassesHandler.h"
#include "../mapObjects/CObjectClassesHandler.h"
template void registerTypesMapObjectTypes<CISer<CConnection>>(CISer<CConnection>& s);
template void registerTypesMapObjectTypes<COSer<CConnection>>(COSer<CConnection>& s);

View File

@ -7,7 +7,7 @@
#include "../CGameState.h"
#include "../mapping/CMap.h"
#include "../CModHandler.h"
#include "../CObjectHandler.h"
#include "../mapObjects/CObjectHandler.h"
#include "../CCreatureHandler.h"
#include "../VCMI_Lib.h"
#include "../CArtHandler.h"
@ -16,7 +16,7 @@
#include "../CTownHandler.h"
#include "../mapping/CCampaignHandler.h"
#include "../NetPacks.h"
#include "../CObjectClassesHandler.h"
#include "../mapObjects/CObjectClassesHandler.h"
template void registerTypesMapObjects2<CISer<CConnection>>(CISer<CConnection>& s);

View File

@ -7,7 +7,7 @@
#include "../CGameState.h"
#include "../mapping/CMap.h"
#include "../CModHandler.h"
#include "../CObjectHandler.h"
#include "../mapObjects/CObjectHandler.h"
#include "../CCreatureHandler.h"
#include "../VCMI_Lib.h"
#include "../CArtHandler.h"
@ -16,7 +16,7 @@
#include "../CTownHandler.h"
#include "../mapping/CCampaignHandler.h"
#include "../NetPacks.h"
#include "../CObjectClassesHandler.h"
#include "../mapObjects/CObjectClassesHandler.h"
template void registerTypesPregamePacks<CISer<CConnection>>(CISer<CConnection>& s);
template void registerTypesPregamePacks<COSer<CConnection>>(COSer<CConnection>& s);

View File

@ -7,7 +7,7 @@
#include "../CGameState.h"
#include "../mapping/CMap.h"
#include "../CModHandler.h"
#include "../CObjectHandler.h"
#include "../mapObjects/CObjectHandler.h"
#include "../CCreatureHandler.h"
#include "../VCMI_Lib.h"
#include "../CArtHandler.h"
@ -16,7 +16,7 @@
#include "../CTownHandler.h"
#include "../mapping/CCampaignHandler.h"
#include "../NetPacks.h"
#include "../CObjectClassesHandler.h"
#include "../mapObjects/CObjectClassesHandler.h"
template void registerTypesServerPacks<CISer<CConnection>>(CISer<CConnection>& s);
template void registerTypesServerPacks<COSer<CConnection>>(COSer<CConnection>& s);

View File

@ -5,8 +5,8 @@
#include "../VCMI_Lib.h"
#include "../CGeneralTextHandler.h"
#include "../mapping/CMapEditManager.h"
#include "../CObjectHandler.h"
#include "../CObjectClassesHandler.h"
#include "../mapObjects/CObjectHandler.h"
#include "../mapObjects/CObjectClassesHandler.h"
#include "../CTownHandler.h"
#include "../StringConstants.h"
#include "../filesystem/Filesystem.h"

View File

@ -15,7 +15,7 @@
#include "../CRandomGenerator.h"
#include "CMapGenOptions.h"
#include "CRmgTemplateZone.h"
#include "../CObjectHandler.h"
#include "../mapObjects/CObjectHandler.h"
#include "../int3.h"
class CMap;

View File

@ -8,9 +8,9 @@
#include "../lib/CModHandler.h"
#include "../lib/CArtHandler.h"
#include "../lib/CBuildingHandler.h"
#include "../lib/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/CSpellHandler.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CTownHandler.h"

View File

@ -8,7 +8,7 @@
#include "../lib/Connection.h"
#include "../lib/CModHandler.h"
#include "../lib/CArtHandler.h"
#include "../lib/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CTownHandler.h"
@ -26,7 +26,7 @@
#include "../lib/VCMIDirs.h"
#include "CGameHandler.h"
#include "../lib/mapping/CMapInfo.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/GameConstants.h"
#include "../lib/logging/CBasicLogConfigurator.h"
#include "../lib/CConfigHandler.h"

View File

@ -2,7 +2,7 @@
#include "../lib/NetPacks.h"
#include "CGameHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/IGameCallback.h"
#include "../lib/mapping/CMap.h"
#include "../lib/CGameState.h"