2011-12-14 00:23:17 +03:00
# pragma once
2012-09-02 13:33:41 +03:00
# include "ConstTransitivePtr.h"
# include "ResourceSet.h"
2011-12-14 00:23:17 +03:00
# include "int3.h"
2012-09-26 16:13:39 +03:00
# include "GameConstants.h"
2009-04-16 14:14:13 +03:00
2009-04-15 17:03:31 +03:00
/*
* CTownHandler . 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
*
2009-04-16 14:14:13 +03:00
*/
2012-09-02 13:33:41 +03:00
class CLegacyConfigParser ;
class JsonNode ;
2009-04-16 14:14:13 +03:00
2012-09-02 13:33:41 +03:00
/// a typical building encountered in every castle ;]
/// this is structure available to both client and server
/// contains all mechanics-related data about town structures
class DLL_LINKAGE CBuilding
{
2012-09-05 15:49:23 +03:00
typedef si32 BuildingType ; //TODO: replace int with pointer?
2012-09-02 13:33:41 +03:00
std : : string name ;
std : : string description ;
2009-04-16 14:14:13 +03:00
2012-09-02 13:33:41 +03:00
public :
2012-09-26 16:13:39 +03:00
TFaction tid ;
si32 bid ; //town ID and structure ID
2012-09-02 13:33:41 +03:00
TResources resources ;
2012-09-05 15:49:23 +03:00
std : : set < BuildingType > requirements ; /// set of required buildings, includes upgradeOf;
BuildingType upgrade ; /// indicates that building "upgrade" can be improved by this, -1 = empty
enum EBuildMode
{
BUILD_NORMAL , // 0 - normal, default
BUILD_AUTO , // 1 - auto - building appears when all requirements are built
BUILD_SPECIAL , // 2 - special - building can not be built normally
BUILD_GRAIL // 3 - grail - building reqires grail to be built
} ;
ui32 mode ;
2009-04-16 14:14:13 +03:00
2012-09-02 13:33:41 +03:00
const std : : string & Name ( ) const ;
const std : : string & Description ( ) const ;
2009-04-16 14:14:13 +03:00
2012-09-05 15:49:23 +03:00
//return base of upgrade(s) or this
BuildingType getBase ( ) const ;
// returns how many times build has to be upgraded to become build
si32 getDistance ( BuildingType build ) const ;
2009-04-16 14:14:13 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-09-05 15:49:23 +03:00
h & tid & bid & resources & name & description & requirements & upgrade & mode ;
2009-04-16 14:14:13 +03:00
}
2012-09-02 13:33:41 +03:00
friend class CTownHandler ;
2009-04-16 14:14:13 +03:00
} ;
2012-09-02 13:33:41 +03:00
/// This is structure used only by client
/// Consists of all gui-related data about town structures
2012-09-05 15:49:23 +03:00
/// Should be moved from lib to client
2012-09-02 13:33:41 +03:00
struct DLL_LINKAGE CStructure
2009-04-16 14:14:13 +03:00
{
2012-09-05 15:49:23 +03:00
CBuilding * building ; // base building. If null - this structure will be always present on screen
CBuilding * buildable ; // building that will be used to determine built building and visible cost. Usually same as "building"
bool hiddenUpgrade ; // used only if "building" is upgrade, if true - structure on town screen will behave exactly like parent (mouse clicks, hover texts, etc)
2009-04-16 14:14:13 +03:00
int3 pos ;
2012-09-02 13:33:41 +03:00
std : : string defName , borderName , areaName ;
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-09-05 15:49:23 +03:00
h & pos & defName & borderName & areaName & building & buildable ;
2012-09-02 13:33:41 +03:00
}
} ;
class DLL_LINKAGE CTown
{
2012-10-05 16:11:26 +03:00
public :
TFaction typeID ; //same as CFaction::factionID
2012-09-05 15:49:23 +03:00
2012-09-02 13:33:41 +03:00
std : : vector < std : : string > names ; //names of the town instances
/// level -> list of creatures on this tier
2012-09-05 15:49:23 +03:00
// TODO: replace with pointers to CCreature
2012-09-26 16:13:39 +03:00
std : : vector < std : : vector < TCreature > > creatures ;
2012-09-02 13:33:41 +03:00
bmap < int , ConstTransitivePtr < CBuilding > > buildings ;
2012-12-19 19:35:58 +03:00
std : : vector < std : : string > dwellings ; //defs for adventure map dwellings for new towns, [0] means tier 1 creatures etc.
std : : vector < std : : string > dwellingNames ;
2012-09-02 13:33:41 +03:00
// should be removed at least from configs in favour of auto-detection
std : : map < int , int > hordeLvl ; //[0] - first horde building creature level; [1] - second horde building (-1 if not present)
ui32 mageLevel ; //max available mage guild level
ui16 primaryRes , warMachine ;
// Client-only data. Should be moved away from lib
struct ClientInfo
{
2012-12-13 16:07:56 +03:00
struct Point
{
si32 x ;
si32 y ;
template < typename Handler > void serialize ( Handler & h , const int version )
{ h & x & y ; }
} ;
2012-10-05 21:03:49 +03:00
2012-09-22 18:10:15 +03:00
//icons [fort is present?][build limit reached?] -> index of icon in def files
int icons [ 2 ] [ 2 ] ;
2012-09-05 15:49:23 +03:00
std : : string musicTheme ;
std : : string townBackground ;
std : : string guildWindow ;
std : : string buildingsIcons ;
2012-09-02 13:33:41 +03:00
std : : string hallBackground ;
2012-09-05 15:49:23 +03:00
/// vector[row][column] = list of buildings in this slot
std : : vector < std : : vector < std : : vector < int > > > hallSlots ;
/// list of town screen structures.
/// NOTE: index in vector is meaningless. Vector used instead of list for a bit faster access
std : : vector < ConstTransitivePtr < CStructure > > structures ;
2012-09-02 13:33:41 +03:00
2012-10-05 22:57:28 +03:00
std : : string advMapVillage ;
std : : string advMapCastle ;
std : : string advMapCapitol ;
2012-10-05 21:03:49 +03:00
std : : string siegePrefix ;
std : : vector < Point > siegePositions ;
TCreature siegeShooter ; // shooter creature ID
si32 siegeShooterCropHeight ; //trim height for shooters in turrets
2012-09-02 13:33:41 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-09-22 18:10:15 +03:00
h & icons & musicTheme & townBackground & guildWindow & buildingsIcons & hallBackground & hallSlots & structures ;
2012-12-13 16:07:56 +03:00
h & advMapVillage & advMapCastle & advMapCapitol ;
h & siegePrefix & siegePositions & siegeShooter & siegeShooterCropHeight ;
2012-09-02 13:33:41 +03:00
}
} clientInfo ;
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-12-19 19:35:58 +03:00
h & names & typeID & creatures & dwellings & dwellingNames & buildings & hordeLvl & mageLevel
2012-09-02 13:33:41 +03:00
& primaryRes & warMachine & clientInfo ;
}
2009-04-16 14:14:13 +03:00
} ;
2012-09-21 00:28:18 +03:00
struct DLL_LINKAGE SPuzzleInfo
{
ui16 number ; //type of puzzle
si16 x , y ; //position
ui16 whenUncovered ; //determines the sequnce of discovering (the lesser it is the sooner puzzle will be discovered)
std : : string filename ; //file with graphic of this puzzle
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & number & x & y & whenUncovered & filename ;
}
} ;
2012-09-05 15:49:23 +03:00
class CFaction
{
public :
2012-10-05 16:11:26 +03:00
std : : string name ; //town name, by default - from TownName.txt
2012-09-26 16:13:39 +03:00
TFaction factionID ;
2012-09-05 15:49:23 +03:00
2012-10-05 16:11:26 +03:00
ui8 nativeTerrain ;
ui8 alignment ; // uses EAlignment enum
2012-09-05 15:49:23 +03:00
2012-12-19 19:35:58 +03:00
TCreature commander ;
2012-09-05 15:49:23 +03:00
std : : string creatureBg120 ;
std : : string creatureBg130 ;
2012-09-21 00:28:18 +03:00
std : : vector < SPuzzleInfo > puzzleMap ;
2012-09-05 15:49:23 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-09-21 00:28:18 +03:00
h & name & factionID & nativeTerrain & creatureBg120 & creatureBg130 & puzzleMap ;
2012-09-05 15:49:23 +03:00
}
} ;
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CTownHandler
2009-04-16 14:14:13 +03:00
{
2012-09-02 13:33:41 +03:00
/// loads CBuilding's into town
void loadBuilding ( CTown & town , const JsonNode & source ) ;
void loadBuildings ( CTown & town , const JsonNode & source ) ;
/// loads CStructure's into town
void loadStructure ( CTown & town , const JsonNode & source ) ;
void loadStructures ( CTown & town , const JsonNode & source ) ;
/// loads town hall vector (hallSlots)
void loadTownHall ( CTown & town , const JsonNode & source ) ;
2012-10-05 21:03:49 +03:00
void loadSiegeScreen ( CTown & town , const JsonNode & source ) ;
2012-09-02 13:33:41 +03:00
2012-09-05 15:49:23 +03:00
void loadClientData ( CTown & town , const JsonNode & source ) ;
void loadTown ( CTown & town , const JsonNode & source ) ;
2012-09-02 13:33:41 +03:00
2012-09-21 00:28:18 +03:00
void loadPuzzle ( CFaction & faction , const JsonNode & source ) ;
2012-09-02 13:33:41 +03:00
/// load all available data from h3 txt(s) into json structure using format similar to vcmi configs
/// returns 2d array [townID] [buildID] of buildings
void loadLegacyData ( JsonNode & dest ) ;
2012-09-05 15:49:23 +03:00
2009-04-16 14:14:13 +03:00
public :
2012-09-26 16:13:39 +03:00
std : : map < TFaction , CTown > towns ;
std : : map < TFaction , CFaction > factions ;
2009-04-16 14:14:13 +03:00
2012-09-02 13:33:41 +03:00
CTownHandler ( ) ; //c-tor, set pointer in VLC to this
2012-09-23 17:32:49 +03:00
/// main loading function for mods, accepts merged JSON source and add all entries from it into game
/// all entries in JSON should be checked for validness before using this function
2012-11-13 14:52:23 +03:00
void load ( const JsonNode & source ) ;
2012-09-23 17:32:49 +03:00
/// "entry point" for loading of OH3 town.
2012-09-02 13:33:41 +03:00
/// reads legacy txt's from H3 + vcmi json, merges them
/// and loads resulting structure to game using loadTowns method
void load ( ) ;
2009-04-16 14:14:13 +03:00
2012-11-20 20:53:45 +03:00
/**
* Gets a list of default allowed factions . OH3 factions are in the range of 0 to 8.
*
* TODO Proposal for town modding : Replace faction id with a unique machine readable town name
* and create a JSON config file or merge it with other configs which describes which
* towns can be used for random map generation / map editor ( default map settings ) .
*
* @ return a list of allowed factions , the index which is unique is the faction id
*/
2012-12-02 15:21:44 +03:00
std : : set < TFaction > getDefaultAllowedFactions ( ) const ;
2012-11-20 20:53:45 +03:00
2009-04-16 14:14:13 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-09-05 15:49:23 +03:00
h & towns & factions ;
2009-04-16 14:14:13 +03:00
}
} ;