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
*/
2017-07-13 10:26:03 +02:00
# pragma once
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
# include <vcmi/Faction.h>
# include <vcmi/FactionService.h>
2017-07-13 10:26:03 +02:00
# include "ConstTransitivePtr.h"
# include "ResourceSet.h"
# include "int3.h"
# include "GameConstants.h"
# include "IHandlerBase.h"
# include "LogicalExpression.h"
# include "battle/BattleHex.h"
2023-05-01 19:29:53 +02:00
# include "bonuses/Bonus.h"
2023-04-30 19:34:25 +02:00
# include "bonuses/BonusList.h"
2023-01-17 22:18:34 +02:00
# include "Point.h"
2023-06-02 20:47:37 +02:00
# include "rewardable/Info.h"
2009-04-16 14:14:13 +03:00
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_BEGIN
2012-09-02 13:33:41 +03:00
class CLegacyConfigParser ;
class JsonNode ;
2013-04-21 15:49:26 +03:00
class CTown ;
2013-04-22 16:23:53 +03:00
class CFaction ;
2016-01-06 11:53:40 +02:00
struct BattleHex ;
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
class JsonSerializeFormat ;
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
2014-04-26 17:23:35 +03:00
2012-09-02 13:33:41 +03:00
class DLL_LINKAGE CBuilding
{
2023-01-04 15:17:50 +02:00
std : : string modScope ;
std : : string identifier ;
2009-04-16 14:14:13 +03:00
2012-09-02 13:33:41 +03:00
public :
2023-04-17 23:11:16 +02:00
using TRequired = LogicalExpression < BuildingID > ;
2013-12-02 14:58:02 +03:00
2013-04-21 15:49:26 +03:00
CTown * town ; // town this building belongs to
2012-09-02 13:33:41 +03:00
TResources resources ;
2014-04-26 17:23:35 +03:00
TResources produce ;
2013-12-02 14:58:02 +03:00
TRequired requirements ;
2012-09-05 15:49:23 +03:00
2013-12-02 14:58:02 +03:00
BuildingID bid ; //structure ID
2013-02-11 22:11:34 +03:00
BuildingID upgrade ; /// indicates that building "upgrade" can be improved by this, -1 = empty
2020-10-02 23:55:46 +02:00
BuildingSubID : : EBuildingSubID subId ; /// subtype for special buildings, -1 = the building is not special
2021-01-14 00:02:13 +02:00
std : : set < BuildingID > overrideBids ; /// the building which bonuses should be overridden with bonuses of the current building
BonusList buildingBonuses ;
BonusList onVisitBonuses ;
2023-04-30 01:58:43 +02:00
2023-04-30 20:34:41 +02:00
Rewardable : : Info rewardableObjectInfo ; ///configurable rewards for special buildings
2012-09-05 15:49:23 +03:00
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
2013-02-11 22:11:34 +03:00
} mode ;
2009-04-16 14:14:13 +03:00
2020-10-02 23:55:46 +02:00
enum ETowerHeight // for lookup towers and some grails
{
HEIGHT_NO_TOWER = 5 , // building has not 'lookout tower' ability
HEIGHT_LOW = 10 , // low lookout tower, but castle without lookout tower gives radius 5
HEIGHT_AVERAGE = 15 ,
HEIGHT_HIGH = 20 , // such tower is in the Tower town
HEIGHT_SKYSHIP = std : : numeric_limits < int > : : max ( ) // grail, open entire map
} height ;
2020-10-07 14:12:32 +02:00
static const std : : map < std : : string , CBuilding : : EBuildMode > MODES ;
static const std : : map < std : : string , CBuilding : : ETowerHeight > TOWER_TYPES ;
CBuilding ( ) : town ( nullptr ) , mode ( BUILD_NORMAL ) { } ;
2016-11-27 21:07:01 +02:00
2023-01-04 15:17:50 +02:00
std : : string getJsonKey ( ) const ;
std : : string getNameTranslated ( ) const ;
std : : string getDescriptionTranslated ( ) const ;
std : : string getNameTextID ( ) const ;
std : : string getDescriptionTextID ( ) const ;
2009-04-16 14:14:13 +03:00
2012-09-05 15:49:23 +03:00
//return base of upgrade(s) or this
2013-02-11 22:11:34 +03:00
BuildingID getBase ( ) const ;
2012-09-05 15:49:23 +03:00
// returns how many times build has to be upgraded to become build
2023-03-13 23:26:44 +02:00
si32 getDistance ( const BuildingID & build ) const ;
2020-10-15 14:03:01 +02:00
STRONG_INLINE
bool IsTradeBuilding ( ) const
{
return bid = = BuildingID : : MARKETPLACE | | subId = = BuildingSubID : : ARTIFACT_MERCHANT | | subId = = BuildingSubID : : FREELANCERS_GUILD ;
}
2020-10-19 21:38:06 +02:00
STRONG_INLINE
bool IsWeekBonus ( ) const
{
return subId = = BuildingSubID : : STABLES | | subId = = BuildingSubID : : MANA_VORTEX ;
}
STRONG_INLINE
bool IsVisitingBonus ( ) const
{
return subId = = BuildingSubID : : ATTACK_VISITING_BONUS | |
2021-01-14 00:02:13 +02:00
subId = = BuildingSubID : : DEFENSE_VISITING_BONUS | |
2020-10-19 21:38:06 +02:00
subId = = BuildingSubID : : SPELL_POWER_VISITING_BONUS | |
subId = = BuildingSubID : : KNOWLEDGE_VISITING_BONUS | |
2021-01-14 00:02:13 +02:00
subId = = BuildingSubID : : EXPERIENCE_VISITING_BONUS | |
subId = = BuildingSubID : : CUSTOM_VISITING_BONUS ;
2020-10-19 21:38:06 +02:00
}
2023-03-13 23:26:44 +02:00
void addNewBonus ( const std : : shared_ptr < Bonus > & b , BonusList & bonusList ) const ;
2012-09-05 15:49:23 +03:00
2009-04-16 14:14:13 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2023-01-04 15:17:50 +02:00
h & modScope ;
2017-07-31 15:35:42 +02:00
h & identifier ;
h & town ;
h & bid ;
h & resources ;
h & produce ;
h & requirements ;
h & upgrade ;
h & mode ;
2022-06-20 16:39:50 +02:00
h & subId ;
h & height ;
h & overrideBids ;
h & buildingBonuses ;
h & onVisitBonuses ;
2023-04-30 01:58:43 +02:00
h & rewardableObjectInfo ;
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"
2009-04-16 14:14:13 +03:00
int3 pos ;
2013-12-02 14:58:02 +03:00
std : : string defName , borderName , areaName , identifier ;
2012-09-02 13:33:41 +03:00
2013-12-02 14:58:02 +03:00
bool hiddenUpgrade ; // used only if "building" is upgrade, if true - structure on town screen will behave exactly like parent (mouse clicks, hover texts, etc)
2012-09-02 13:33:41 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2017-07-31 15:35:42 +02:00
h & pos ;
h & defName ;
h & borderName ;
h & areaName ;
h & identifier ;
h & building ;
h & buildable ;
h & hiddenUpgrade ;
2012-09-02 13:33:41 +03:00
}
} ;
2013-04-21 15:49:26 +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 )
{
2017-07-31 15:35:42 +02:00
h & number ;
h & x ;
h & y ;
h & whenUncovered ;
h & filename ;
2013-04-21 15:49:26 +03:00
}
} ;
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
class DLL_LINKAGE CFaction : public Faction
2013-04-21 15:49:26 +03:00
{
2023-01-04 15:17:50 +02:00
friend class CTownHandler ;
2023-01-18 23:56:01 +02:00
friend class CBuilding ;
friend class CTown ;
2023-01-19 00:23:02 +02:00
std : : string modScope ;
2013-12-02 14:58:02 +03:00
std : : string identifier ;
2013-04-21 15:49:26 +03:00
2023-04-09 17:26:32 +02:00
FactionID index = FactionID : : NEUTRAL ;
2013-04-21 15:49:26 +03:00
2023-04-05 02:50:29 +02:00
FactionID getFaction ( ) const override ; //This function should not be used
2023-01-04 15:17:50 +02:00
public :
2022-09-29 11:44:46 +02:00
TerrainId nativeTerrain ;
2023-04-04 12:36:42 +02:00
EAlignment alignment = EAlignment : : NEUTRAL ;
2023-03-13 23:26:44 +02:00
bool preferUndergroundPlacement = false ;
2013-04-21 15:49:26 +03:00
2023-03-13 23:26:44 +02:00
CTown * town = nullptr ; //NOTE: can be null
2013-04-21 15:49:26 +03:00
std : : string creatureBg120 ;
std : : string creatureBg130 ;
2016-02-14 13:22:46 +02:00
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
std : : vector < SPuzzleInfo > puzzleMap ;
2016-02-14 13:22:46 +02:00
2023-03-13 23:26:44 +02:00
CFaction ( ) = default ;
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
~ CFaction ( ) ;
2013-04-21 15:49:26 +03:00
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
int32_t getIndex ( ) const override ;
int32_t getIconIndex ( ) const override ;
2023-01-18 23:56:01 +02:00
std : : string getJsonKey ( ) const override ;
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
void registerIcons ( const IconRegistar & cb ) const override ;
FactionID getId ( ) const override ;
2023-01-04 15:17:50 +02:00
std : : string getNameTranslated ( ) const override ;
std : : string getNameTextID ( ) const override ;
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
bool hasTown ( ) const override ;
2023-04-02 02:07:39 +02:00
TerrainId getNativeTerrain ( ) const override ;
2023-04-04 12:36:42 +02:00
EAlignment getAlignment ( ) const override ;
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
void updateFrom ( const JsonNode & data ) ;
void serializeJson ( JsonSerializeFormat & handler ) ;
2013-04-21 15:49:26 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2023-01-04 15:17:50 +02:00
h & modScope ;
2017-07-31 15:35:42 +02:00
h & identifier ;
h & index ;
h & nativeTerrain ;
h & alignment ;
h & town ;
h & creatureBg120 ;
h & creatureBg130 ;
h & puzzleMap ;
2013-04-21 15:49:26 +03:00
}
} ;
2012-09-02 13:33:41 +03:00
class DLL_LINKAGE CTown
{
2023-01-04 15:17:50 +02:00
friend class CTownHandler ;
2023-03-13 23:26:44 +02:00
size_t namesCount = 0 ;
2023-01-04 15:17:50 +02:00
2012-10-05 16:11:26 +03:00
public :
2013-04-21 17:08:46 +03:00
CTown ( ) ;
~ CTown ( ) ;
2016-11-13 12:38:42 +02:00
std : : string getBuildingScope ( ) const ;
std : : set < si32 > getAllBuildings ( ) const ;
2020-10-15 14:03:01 +02:00
const CBuilding * getSpecialBuilding ( BuildingSubID : : EBuildingSubID subID ) const ;
2023-03-13 23:26:44 +02:00
std : : string getGreeting ( BuildingSubID : : EBuildingSubID subID ) const ;
void setGreeting ( BuildingSubID : : EBuildingSubID subID , const std : : string & message ) const ; //may affect only mutable field
2020-10-15 14:03:01 +02:00
BuildingID : : EBuildingID getBuildingType ( BuildingSubID : : EBuildingSubID subID ) const ;
2016-11-13 12:38:42 +02:00
2023-01-04 15:17:50 +02:00
std : : string getRandomNameTranslated ( size_t index ) const ;
std : : string getRandomNameTextID ( size_t index ) const ;
size_t getRandomNamesCount ( ) const ;
2016-02-14 13:22:46 +02:00
2023-01-04 15:17:50 +02:00
CFaction * faction ;
2012-09-02 13:33:41 +03:00
/// level -> list of creatures on this tier
2013-12-02 14:58:02 +03:00
// TODO: replace with pointers to CCreature
std : : vector < std : : vector < CreatureID > > creatures ;
std : : map < BuildingID , ConstTransitivePtr < CBuilding > > buildings ;
std : : vector < std : : string > dwellings ; //defs for adventure map dwellings for new towns, [0] means tier 1 creatures etc.
std : : vector < std : : string > dwellingNames ;
// should be removed at least from configs in favor 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
2023-04-05 02:26:29 +02:00
GameResID primaryRes ;
2013-12-02 14:58:02 +03:00
ArtifactID warMachine ;
2023-03-20 13:02:09 +02:00
SpellID moatAbility ;
2013-11-03 15:07:23 +03:00
// default chance for hero of specific class to appear in tavern, if field "tavern" was not set
// resulting chance = sqrt(town.chance * heroClass.chance)
ui32 defaultTavernChance ;
2012-09-02 13:33:41 +03:00
// Client-only data. Should be moved away from lib
struct ClientInfo
{
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 ] ;
2013-04-22 22:51:22 +03:00
std : : string iconSmall [ 2 ] [ 2 ] ; /// icon names used during loading
std : : string iconLarge [ 2 ] [ 2 ] ;
2014-04-24 22:36:10 +03:00
std : : string tavernVideo ;
2012-09-05 15:49:23 +03:00
std : : string musicTheme ;
std : : string townBackground ;
2014-04-24 22:36:10 +03:00
std : : string guildBackground ;
2012-09-05 15:49:23 +03:00
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
2013-02-11 22:11:34 +03:00
std : : vector < std : : vector < std : : vector < BuildingID > > > hallSlots ;
2012-09-05 15:49:23 +03:00
/// 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 21:03:49 +03:00
std : : string siegePrefix ;
std : : vector < Point > siegePositions ;
2013-02-11 02:24:57 +03:00
CreatureID siegeShooter ; // shooter creature ID
2022-11-29 14:47:51 +02:00
std : : string towerIconSmall ;
std : : string towerIconLarge ;
2012-10-05 21:03:49 +03:00
2012-09-02 13:33:41 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2017-07-31 15:35:42 +02:00
h & icons ;
h & iconSmall ;
h & iconLarge ;
h & tavernVideo ;
h & musicTheme ;
h & townBackground ;
h & guildBackground ;
h & guildWindow ;
h & buildingsIcons ;
h & hallBackground ;
h & hallSlots ;
h & structures ;
h & siegePrefix ;
h & siegePositions ;
h & siegeShooter ;
2022-11-29 14:47:51 +02:00
h & towerIconSmall ;
h & towerIconLarge ;
2012-09-02 13:33:41 +03:00
}
} clientInfo ;
template < typename Handler > void serialize ( Handler & h , const int version )
{
2023-01-04 15:17:50 +02:00
h & namesCount ;
2017-07-31 15:35:42 +02:00
h & faction ;
h & creatures ;
h & dwellings ;
h & dwellingNames ;
h & buildings ;
h & hordeLvl ;
h & mageLevel ;
h & primaryRes ;
h & warMachine ;
h & clientInfo ;
2023-03-20 13:02:09 +02:00
h & moatAbility ;
2016-01-28 00:35:01 +02:00
h & defaultTavernChance ;
2012-09-02 13:33:41 +03:00
}
2020-10-25 00:04:34 +02:00
private :
///generated bonusing buildings messages for all towns of this type.
mutable std : : map < BuildingSubID : : EBuildingSubID , const std : : string > specialMessages ; //may be changed by CGTownBuilding::getVisitingBonusGreeting() const
2009-04-16 14:14:13 +03:00
} ;
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
class DLL_LINKAGE CTownHandler : public CHandlerBase < FactionID , Faction , CFaction , FactionService >
2009-04-16 14:14:13 +03:00
{
2013-12-02 14:58:02 +03:00
struct BuildingRequirementsHelper
{
JsonNode json ;
CBuilding * building ;
2016-11-13 12:38:42 +02:00
CTown * town ;
2013-12-02 14:58:02 +03:00
} ;
2018-07-16 14:16:55 +02:00
std : : map < CTown * , JsonNode > warMachinesToLoad ;
2013-12-02 14:58:02 +03:00
std : : vector < BuildingRequirementsHelper > requirementsToLoad ;
2021-01-14 00:02:13 +02:00
std : : vector < BuildingRequirementsHelper > overriddenBidsToLoad ; //list of buildings, which bonuses should be overridden.
2020-09-24 09:10:32 +02:00
2021-02-05 00:56:21 +02:00
static TPropagatorPtr & emptyPropagator ( ) ;
2021-01-14 00:02:13 +02:00
2013-12-02 14:58:02 +03:00
void initializeRequirements ( ) ;
2021-01-14 00:02:13 +02:00
void initializeOverridden ( ) ;
2018-07-16 14:16:55 +02:00
void initializeWarMachines ( ) ;
2013-12-02 14:58:02 +03:00
2012-09-02 13:33:41 +03:00
/// loads CBuilding's into town
2023-03-13 23:26:44 +02:00
void loadBuildingRequirements ( CBuilding * building , const JsonNode & source , std : : vector < BuildingRequirementsHelper > & bidsToLoad ) const ;
2016-11-13 12:38:42 +02:00
void loadBuilding ( CTown * town , const std : : string & stringID , const JsonNode & source ) ;
void loadBuildings ( CTown * town , const JsonNode & source ) ;
2012-09-02 13:33:41 +03:00
2023-05-01 00:20:01 +02:00
std : : shared_ptr < Bonus > createBonus ( CBuilding * build , BonusType type , int val , int subtype = - 1 ) const ;
std : : shared_ptr < Bonus > createBonus ( CBuilding * build , BonusType type , int val , TPropagatorPtr & prop , int subtype = - 1 ) const ;
2023-03-13 23:26:44 +02:00
std : : shared_ptr < Bonus > createBonusImpl ( const BuildingID & building ,
2023-05-01 00:20:01 +02:00
BonusType type ,
2023-03-13 23:26:44 +02:00
int val ,
TPropagatorPtr & prop ,
const std : : string & description ,
int subtype = - 1 ) const ;
2021-01-14 00:02:13 +02:00
2012-09-02 13:33:41 +03:00
/// loads CStructure's into town
2023-03-13 23:26:44 +02:00
void loadStructure ( CTown & town , const std : : string & stringID , const JsonNode & source ) const ;
void loadStructures ( CTown & town , const JsonNode & source ) const ;
2012-09-02 13:33:41 +03:00
/// loads town hall vector (hallSlots)
2023-03-13 23:26:44 +02:00
void loadTownHall ( CTown & town , const JsonNode & source ) const ;
void loadSiegeScreen ( CTown & town , const JsonNode & source ) const ;
2012-09-02 13:33:41 +03:00
2023-03-13 23:26:44 +02:00
void loadClientData ( CTown & town , const JsonNode & source ) const ;
2012-09-05 15:49:23 +03:00
2018-07-16 14:16:55 +02:00
void loadTown ( CTown * town , const JsonNode & source ) ;
2012-09-02 13:33:41 +03:00
2023-03-13 23:26:44 +02:00
void loadPuzzle ( CFaction & faction , const JsonNode & source ) const ;
2012-09-21 00:28:18 +03:00
2016-11-13 12:38:42 +02:00
void loadRandomFaction ( ) ;
2020-10-02 23:55:46 +02:00
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
2020-10-07 14:12:32 +02:00
public :
template < typename R , typename K >
static R getMappedValue ( const K key , const R defval , const std : : map < K , R > & map , bool required = true ) ;
2020-10-02 23:55:46 +02:00
template < typename R >
2020-10-07 14:12:32 +02:00
static R getMappedValue ( const JsonNode & node , const R defval , const std : : map < std : : string , R > & map , bool required = true ) ;
2020-10-02 23:55:46 +02:00
2016-11-13 12:38:42 +02:00
CTown * randomTown ;
2023-01-04 15:17:50 +02:00
CFaction * randomFaction ;
2016-11-13 12:38:42 +02:00
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
CTownHandler ( ) ;
2013-04-21 19:38:31 +03:00
~ CTownHandler ( ) ;
2012-09-02 13:33:41 +03:00
2023-03-15 21:34:29 +02:00
std : : vector < JsonNode > loadLegacyData ( ) override ;
2013-04-21 15:49:26 +03:00
void loadObject ( std : : string scope , std : : string name , const JsonNode & data ) override ;
void loadObject ( std : : string scope , std : : string name , const JsonNode & data , size_t index ) override ;
2023-03-13 23:26:44 +02:00
void addBonusesForVanilaBuilding ( CBuilding * building ) const ;
2013-04-21 15:49:26 +03:00
2016-11-13 12:38:42 +02:00
void loadCustom ( ) override ;
2013-12-02 14:58:02 +03:00
void afterLoadFinalization ( ) override ;
2013-04-21 15:49:26 +03:00
std : : vector < bool > getDefaultAllowed ( ) const override ;
2023-04-09 17:26:32 +02:00
std : : set < FactionID > getAllowedFactions ( bool withTown = true ) const ;
2012-11-20 20:53:45 +03:00
2021-01-14 00:02:13 +02:00
static void loadSpecialBuildingBonuses ( const JsonNode & source , BonusList & bonusList , CBuilding * building ) ;
2016-02-14 13:22:46 +02:00
2009-04-16 14:14:13 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
h & objects ;
2022-06-20 16:39:50 +02:00
h & randomTown ;
2009-04-16 14:14:13 +03:00
}
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
protected :
const std : : vector < std : : string > & getTypeNames ( ) const override ;
CFaction * loadFromJson ( const std : : string & scope , const JsonNode & data , const std : : string & identifier , size_t index ) override ;
2009-04-16 14:14:13 +03:00
} ;
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_END