From acb718d503abf297d132b11dae57c26557e3f42f Mon Sep 17 00:00:00 2001 From: Andrettin Date: Fri, 11 Jan 2019 07:50:46 +0100 Subject: [PATCH] Added data type base class for unit types, upgrades and etc. --- CMakeLists.txt | 1 + src/include/age.h | 8 ++-- src/include/animation.h | 43 ++++++++---------- src/include/character.h | 7 ++- src/include/currency.h | 9 ++-- src/include/data_type.h | 54 +++++++++++++++++++++++ src/include/item.h | 26 +++++------ src/include/map/historical_location.h | 6 +-- src/include/map/map_template.h | 15 +++---- src/include/map/site.h | 13 +++--- src/include/map/terrain_type.h | 49 +++++++++----------- src/include/missile.h | 12 ++--- src/include/plane.h | 7 +-- src/include/religion/deity.h | 11 +++-- src/include/religion/deity_domain.h | 8 ++-- src/include/religion/pantheon.h | 9 ++-- src/include/resource.h | 8 ++-- src/include/school_of_magic.h | 8 ++-- src/include/spell/spell_adjustvariable.h | 2 +- src/include/spell/spell_adjustvital.h | 2 +- src/include/spell/spell_areaadjustvital.h | 13 +++--- src/include/spell/spell_areabombardment.h | 2 +- src/include/spell/spell_capture.h | 2 +- src/include/spell/spell_demolish.h | 2 +- src/include/spell/spell_luacallback.h | 2 +- src/include/spell/spell_polymorph.h | 17 +++---- src/include/spell/spell_retrain.h | 2 +- src/include/spell/spell_spawnmissile.h | 2 +- src/include/spell/spell_spawnportal.h | 2 +- src/include/spell/spell_summon.h | 2 +- src/include/spell/spell_teleport.h | 2 +- src/include/spells.h | 12 ++--- src/include/time/calendar.h | 48 ++++++-------------- src/include/time/season.h | 14 +++--- src/include/time/season_schedule.h | 30 ++++--------- src/include/time/time_of_day.h | 32 +++++--------- src/include/time/time_of_day_schedule.h | 27 +++--------- src/include/time/time_period_schedule.h | 19 +++----- src/include/time/timeline.h | 23 +++------- src/include/trigger.h | 8 ++-- src/include/trigger_effect.h | 4 +- src/include/ui/button_level.h | 20 +++------ src/include/unit/historical_unit.h | 13 ++---- src/include/unit/unittype.h | 39 +++++++--------- src/include/upgrade/upgrade_structs.h | 53 +++++++++++----------- src/include/world.h | 27 ++++-------- src/missile/missile.cpp | 3 +- src/spell/spells.cpp | 4 +- src/upgrade/upgrade.cpp | 8 ++-- 49 files changed, 319 insertions(+), 411 deletions(-) create mode 100644 src/include/data_type.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9001f06ae..1aff6d63e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -670,6 +670,7 @@ set(stratagus_generic_HDRS src/include/construct.h src/include/currency.h src/include/cursor.h + src/include/data_type.h src/include/dialogue.h src/include/editor.h src/include/font.h diff --git a/src/include/age.h b/src/include/age.h index b3c583df3..c363ca2f8 100644 --- a/src/include/age.h +++ b/src/include/age.h @@ -34,6 +34,8 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" + #include #include #include @@ -42,11 +44,10 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; class CGraphic; class CUpgrade; -class CAge +class CAge : public CDataType { public: ~CAge(); @@ -61,10 +62,9 @@ class CAge static std::map AgesByIdent; static CAge *CurrentAge; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; public: - std::string Ident; std::string Name; CGraphic *G = nullptr; int Priority = 0; diff --git a/src/include/animation.h b/src/include/animation.h index 71c9c5440..1723f9097 100644 --- a/src/include/animation.h +++ b/src/include/animation.h @@ -8,9 +8,9 @@ // T H E W A R B E G I N S // Stratagus - A free fantasy real time strategy game engine // -/**@name animation.h - The animations headerfile. */ +/**@name animation.h - The animations header file. */ // -// (c) Copyright 2005-2007 by Jimmy Salmon +// (c) Copyright 2005-2019 by Jimmy Salmon and Andrettin // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -30,12 +30,12 @@ #ifndef __ANIMATIONS_H__ #define __ANIMATIONS_H__ -//@{ +#include "data_type.h" +#include "upgrade/upgrade_structs.h" // MaxCost #include #include -#include "upgrade/upgrade_structs.h" // MaxCost #define ANIMATIONS_DEATHTYPES 40 class CFile; @@ -104,12 +104,10 @@ class CAnimation CAnimation *Next; }; -class CAnimations +class CAnimations : public CDataType { public: - CAnimations() : Attack(nullptr), RangedAttack(nullptr), Build(nullptr), Move(nullptr), Repair(nullptr), - Research(nullptr), SpellCast(nullptr), Start(nullptr), Still(nullptr), - Train(nullptr), Upgrade(nullptr) + CAnimations() { memset(Death, 0, sizeof(Death)); memset(Harvest, 0, sizeof(Harvest)); @@ -141,23 +139,22 @@ class CAnimations static void LoadUnitAnim(lua_State *l, CUnit &unit, int luaIndex); static void LoadWaitUnitAnim(lua_State *l, CUnit &unit, int luaIndex); - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; public: - std::string Ident; - CAnimation *Attack; - CAnimation *RangedAttack; - CAnimation *Build; + CAnimation *Attack = nullptr; + CAnimation *RangedAttack = nullptr; + CAnimation *Build = nullptr; CAnimation *Death[ANIMATIONS_DEATHTYPES + 1]; CAnimation *Harvest[MaxCosts]; - CAnimation *Move; - CAnimation *Repair; - CAnimation *Research; - CAnimation *SpellCast; - CAnimation *Start; - CAnimation *Still; - CAnimation *Train; - CAnimation *Upgrade; + CAnimation *Move = nullptr; + CAnimation *Repair = nullptr; + CAnimation *Research = nullptr; + CAnimation *SpellCast = nullptr; + CAnimation *Start = nullptr; + CAnimation *Still = nullptr; + CAnimation *Train = nullptr; + CAnimation *Upgrade = nullptr; }; /*---------------------------------------------------------------------------- @@ -186,6 +183,4 @@ extern void FreeAnimations(); extern std::map AnimationMap; //Wyrmgus end -//@} - -#endif // !__ANIMATIONS_H__ +#endif diff --git a/src/include/character.h b/src/include/character.h index 954067363..e83894c07 100644 --- a/src/include/character.h +++ b/src/include/character.h @@ -36,6 +36,7 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" #include "icons.h" #include "item.h" #include "time/date.h" @@ -49,7 +50,6 @@ class CCalendar; class CCivilization; -class CConfigData; class CDeity; class CDeityDomain; class CFaction; @@ -108,7 +108,7 @@ enum CharacterTitles { MaxCharacterTitles }; -class CCharacter +class CCharacter : public CDataType { public: CCharacter() @@ -127,7 +127,7 @@ class CCharacter ~CCharacter(); - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; void GenerateHistory(); void ResetHistory(); void SaveHistory(); @@ -162,7 +162,6 @@ class CCharacter bool ViolentDeath = false; /// If historical death was violent bool Custom = false; /// Whether this character is a custom hero bool Initialized = false; /// Whether the character has already been initialized - std::string Ident; /// Ident of the character std::string Name; /// Given name of the character std::string ExtraName; /// Extra given names of the character (used if necessary to differentiate from existing heroes) std::string FamilyName; /// Name of the character's family diff --git a/src/include/currency.h b/src/include/currency.h index 9ac163a6e..8e1e4fe68 100644 --- a/src/include/currency.h +++ b/src/include/currency.h @@ -34,6 +34,8 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" + #include #include #include @@ -42,9 +44,7 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; - -class CCurrency +class CCurrency : CDataType { public: static CCurrency *GetCurrency(const std::string &ident, const bool should_find = true); @@ -54,10 +54,9 @@ class CCurrency static std::vector Currencies; static std::map CurrenciesByIdent; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; public: - std::string Ident; std::string Name; }; diff --git a/src/include/data_type.h b/src/include/data_type.h new file mode 100644 index 000000000..c7c557d07 --- /dev/null +++ b/src/include/data_type.h @@ -0,0 +1,54 @@ +// _________ __ __ +// / _____// |_____________ _/ |______ ____ __ __ ______ +// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ +// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | +// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > +// \/ \/ \//_____/ \/ +// ______________________ ______________________ +// T H E W A R B E G I N S +// Stratagus - A free fantasy real time strategy game engine +// +/**@name data_type.h - The data type header file. */ +// +// (c) Copyright 2019 by Andrettin +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; only version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// + +#ifndef __DATA_TYPE_H__ +#define __DATA_TYPE_H__ + +/*---------------------------------------------------------------------------- +-- Includes +----------------------------------------------------------------------------*/ + +#include + +/*---------------------------------------------------------------------------- +-- Declarations +----------------------------------------------------------------------------*/ + +class CConfigData; + +class CDataType +{ +public: + virtual void ProcessConfigData(const CConfigData *config_data) = 0; + +public: + std::string Ident; /// String identifier of the instance +}; + +#endif diff --git a/src/include/item.h b/src/include/item.h index 6df296a9f..a53d3cb34 100644 --- a/src/include/item.h +++ b/src/include/item.h @@ -138,25 +138,19 @@ class CUniqueItem class CPersistentItem { public: - CPersistentItem() : - Bound(false), Identified(true), - Type(nullptr), Prefix(nullptr), Suffix(nullptr), Spell(nullptr), Work(nullptr), Elixir(nullptr), Unique(nullptr), Owner(nullptr) - { - } - void ProcessConfigData(const CConfigData *config_data); std::string Name; - bool Bound; /// Whether the item is bound to its owner and can't be dropped - bool Identified; /// Whether the item has been identified - CUnitType *Type; /// Item type of the item - CUpgrade *Prefix; - CUpgrade *Suffix; - CSpell *Spell; - CUpgrade *Work; - CUpgrade *Elixir; - CUniqueItem *Unique; - CCharacter *Owner; + bool Bound = false; /// Whether the item is bound to its owner and can't be dropped + bool Identified = true; /// Whether the item has been identified + CUnitType *Type = nullptr; /// Item type of the item + CUpgrade *Prefix = nullptr; + CUpgrade *Suffix = nullptr; + CSpell *Spell = nullptr; + CUpgrade *Work = nullptr; + CUpgrade *Elixir = nullptr; + CUniqueItem *Unique = nullptr; + CCharacter *Owner = nullptr; }; /*---------------------------------------------------------------------------- diff --git a/src/include/map/historical_location.h b/src/include/map/historical_location.h index 1c66570db..d94f13a58 100644 --- a/src/include/map/historical_location.h +++ b/src/include/map/historical_location.h @@ -30,8 +30,6 @@ #ifndef __HISTORICAL_LOCATION_H__ #define __HISTORICAL_LOCATION_H__ -//@{ - /*---------------------------------------------------------------------------- -- Includes ----------------------------------------------------------------------------*/ @@ -58,6 +56,4 @@ class CHistoricalLocation CSite *Site = nullptr; //the historical location's site (if any) }; -//@} - -#endif // !__HISTORICAL_LOCATION_H__ +#endif diff --git a/src/include/map/map_template.h b/src/include/map/map_template.h index e052743c2..80be20d56 100644 --- a/src/include/map/map_template.h +++ b/src/include/map/map_template.h @@ -34,20 +34,20 @@ -- Includes ----------------------------------------------------------------------------*/ -#include -#include -#include - +#include "data_type.h" #include "map/tile.h" #include "time/date.h" #include "vec2i.h" +#include +#include +#include + /*---------------------------------------------------------------------------- -- Declarations ----------------------------------------------------------------------------*/ class CCharacter; -class CConfigData; class CFaction; class CHistoricalLocation; class CMapField; @@ -77,7 +77,7 @@ class CGeneratedTerrain std::vector TargetTerrainTypes; //the terrain types over which the terrain is to be generated }; -class CMapTemplate +class CMapTemplate : public CDataType { public: CMapTemplate() : @@ -94,7 +94,7 @@ class CMapTemplate static std::vector MapTemplates; /// Map templates static std::map MapTemplatesByIdent; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; void ApplyTerrainFile(bool overlay, Vec2i template_start_pos, Vec2i map_start_pos, int z) const; void ApplyTerrainImage(bool overlay, Vec2i template_start_pos, Vec2i map_start_pos, int z) const; void Apply(Vec2i template_start_pos, Vec2i map_start_pos, int z) const; @@ -106,7 +106,6 @@ class CMapTemplate const CMapTemplate *GetTopMapTemplate() const; Vec2i GetBestLocationMapPosition(const std::vector &historical_location_list, bool &in_another_map_template, const Vec2i &template_start_pos, const Vec2i &map_start_pos, const bool random) const; - std::string Ident; std::string Name; std::string TerrainFile; std::string OverlayTerrainFile; diff --git a/src/include/map/site.h b/src/include/map/site.h index eb395407f..3857b3ed5 100644 --- a/src/include/map/site.h +++ b/src/include/map/site.h @@ -34,19 +34,19 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" +#include "time/date.h" +#include "vec2i.h" + #include #include #include -#include "time/date.h" -#include "vec2i.h" - /*---------------------------------------------------------------------------- -- Declarations ----------------------------------------------------------------------------*/ class CCivilization; -class CConfigData; class CFaction; class CMapTemplate; class CRegion; @@ -54,7 +54,7 @@ class CUnit; class CUnitType; class CUniqueItem; -class CSite +class CSite : public CDataType { public: static CSite *GetSite(const std::string &ident); @@ -64,10 +64,9 @@ class CSite static std::vector Sites; /// Sites static std::map SitesByIdent; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; std::string GetCulturalName(const CCivilization *civilization) const; - std::string Ident; std::string Name; bool Major = false; /// Whether the site is a major one; major sites have settlement sites, and as such can have town halls Vec2i Position = Vec2i(-1, -1); /// Position of the site in its map template diff --git a/src/include/map/terrain_type.h b/src/include/map/terrain_type.h index d22ab8ad4..3c2b054b9 100644 --- a/src/include/map/terrain_type.h +++ b/src/include/map/terrain_type.h @@ -30,37 +30,31 @@ #ifndef __TERRAIN_TYPE_H__ #define __TERRAIN_TYPE_H__ -//@{ - /*---------------------------------------------------------------------------- -- Includes ----------------------------------------------------------------------------*/ +#include "color.h" +#include "data_type.h" + #include #include #include #include -#include "color.h" - /*---------------------------------------------------------------------------- -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; class CGraphic; class CPlayerColorGraphic; class CSeason; class CUnitType; -class CTerrainType +class CTerrainType : public CDataType { public: - CTerrainType() : - ID(-1), Flags(0), SolidAnimationFrames(0), Resource(-1), - Overlay(false), Buildable(false), AllowSingle(false), Hidden(false), - PixelTileSize(32, 32), - UnitType(nullptr), Graphics(nullptr), ElevationGraphics(nullptr), PlayerColorGraphics(nullptr) + CTerrainType() { Color.R = 0; Color.G = 0; @@ -81,29 +75,28 @@ class CTerrainType static std::map TerrainTypesByCharacter; static std::map, CTerrainType *> TerrainTypesByColor; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; CGraphic *GetGraphics(const CSeason *season = nullptr) const; - std::string Ident; std::string Name; std::string Character; CColor Color; - int ID; - int SolidAnimationFrames; - int Resource; - unsigned long Flags; - bool Overlay; /// Whether this terrain type belongs to the overlay layer - bool Buildable; - bool AllowSingle; /// Whether this terrain type has transitions for single tiles - bool Hidden; - PixelSize PixelTileSize; - CUnitType *UnitType; + int ID = -1; + int SolidAnimationFrames = 0; + int Resource = -1; + unsigned long Flags = 0; + bool Overlay = false; /// Whether this terrain type belongs to the overlay layer + bool Buildable = false; /// Whether structures can be built upon this terrain type + bool AllowSingle = false; /// Whether this terrain type has transitions for single tiles + bool Hidden = false; + PixelSize PixelTileSize = PixelSize(32, 32); + CUnitType *UnitType = nullptr; //private: - CGraphic *Graphics; + CGraphic *Graphics = nullptr; std::map SeasonGraphics; /// Graphics to be displayed instead of the normal ones during particular seasons public: - CGraphic *ElevationGraphics; /// Semi-transparent elevation graphics, separated so that borders look better - CPlayerColorGraphic *PlayerColorGraphics; + CGraphic *ElevationGraphics = nullptr; /// Semi-transparent elevation graphics, separated so that borders look better + CPlayerColorGraphic *PlayerColorGraphics = nullptr; std::vector BaseTerrainTypes; /// Possible base terrain types for this terrain type (if it is an overlay terrain) std::vector BorderTerrains; /// Terrain types which this one can border std::vector InnerBorderTerrains; /// Terrain types which this one can border, and which "enter" this tile type in transitions @@ -115,6 +108,4 @@ class CTerrainType std::map, std::vector> AdjacentTransitionTiles; /// Transition graphics for the tiles adjacent to this terrain type, mapped to the tile type (-1 means any tile) and the transition type (i.e. northeast outer) }; -//@} - -#endif // !__TERRAIN_TYPE_H__ +#endif diff --git a/src/include/missile.h b/src/include/missile.h index 1f914ce50..5f318d2e4 100644 --- a/src/include/missile.h +++ b/src/include/missile.h @@ -30,8 +30,6 @@ #ifndef __MISSILE_H__ #define __MISSILE_H__ -//@{ - /*---------------------------------------------------------------------------- -- Documentation ----------------------------------------------------------------------------*/ @@ -295,6 +293,7 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" #include "missileconfig.h" #include "script.h" #include "unit/unitptr.h" @@ -340,7 +339,7 @@ enum { }; /// Base structure of missile-types -class MissileType +class MissileType : public CDataType { public: explicit MissileType(const std::string &ident); @@ -348,7 +347,7 @@ class MissileType static const char *MissileClassNames[]; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; /// load the graphics for a missile type void LoadMissileSprite(); @@ -361,7 +360,6 @@ class MissileType int Height() const { return size.y; } //private: - std::string Ident; /// missile name int Transparency; /// missile transparency PixelSize size; /// missile size in pixels int DrawLevel; /// Level to draw missile at @@ -668,6 +666,4 @@ extern void CleanMissiles(); extern void FreeBurningBuildingFrames(); -//@} - -#endif // !__MISSILE_H__ +#endif diff --git a/src/include/plane.h b/src/include/plane.h index 99caa3adb..37455fd43 100644 --- a/src/include/plane.h +++ b/src/include/plane.h @@ -36,6 +36,8 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" + #include #include #include @@ -44,14 +46,13 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; class CDeityDomain; class CSchoolOfMagic; class CSeasonSchedule; class CSpecies; class CTimeOfDaySchedule; -class CPlane +class CPlane : public CDataType { public: CPlane() : @@ -66,7 +67,7 @@ class CPlane static std::vector Planes; /// Planes static std::map PlanesByIdent; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; int ID; /// ID of this plane std::string Ident; diff --git a/src/include/religion/deity.h b/src/include/religion/deity.h index 7da6c3c49..4224786da 100644 --- a/src/include/religion/deity.h +++ b/src/include/religion/deity.h @@ -34,18 +34,18 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" +#include "icons.h" + #include #include #include -#include "icons.h" - /*---------------------------------------------------------------------------- -- Declarations ----------------------------------------------------------------------------*/ class CCivilization; -class CConfigData; class CDeityDomain; class CFaction; class CPantheon; @@ -56,7 +56,7 @@ class CUpgrade; #define MAJOR_DEITY_DOMAIN_MAX 3 // major deities can only have up to three domains #define MINOR_DEITY_DOMAIN_MAX 1 // minor deities can only have one domain -class CDeity +class CDeity : public CDataType { public: static CDeity *GetDeity(const std::string &ident, const bool should_find = true); @@ -68,13 +68,12 @@ class CDeity static std::map DeitiesByIdent; static std::map DeitiesByUpgrade; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; std::string GetCulturalName(const CCivilization *civilization) const; int Gender = 0; /// Deity's gender bool Major = false; /// Whether the deity is a major one or not - std::string Ident; /// Ident of the deity std::string Name; /// Name of the deity std::string Description; std::string Background; diff --git a/src/include/religion/deity_domain.h b/src/include/religion/deity_domain.h index 31e98b7b9..d10be7511 100644 --- a/src/include/religion/deity_domain.h +++ b/src/include/religion/deity_domain.h @@ -34,6 +34,8 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" + #include #include #include @@ -42,10 +44,9 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; class CUpgrade; -class CDeityDomain +class CDeityDomain : public CDataType { public: static CDeityDomain *GetDeityDomain(const std::string &ident, bool should_find = true); @@ -57,9 +58,8 @@ class CDeityDomain static std::map DeityDomainsByIdent; static std::map DeityDomainsByUpgrade; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; - std::string Ident; /// Ident of the domain std::string Name; /// Name of the domain std::string Description; /// Description of the deity domain from an in-game universe perspective std::string Background; /// Description of the deity domain from a perspective outside of the game's universe diff --git a/src/include/religion/pantheon.h b/src/include/religion/pantheon.h index c4ea1fe63..7d2fbe4ef 100644 --- a/src/include/religion/pantheon.h +++ b/src/include/religion/pantheon.h @@ -34,6 +34,8 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" + #include #include #include @@ -42,9 +44,7 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; - -class CPantheon +class CPantheon : public CDataType { public: static CPantheon *GetPantheon(const std::string &ident, const bool should_find = true); @@ -54,9 +54,8 @@ class CPantheon static std::vector Pantheons; /// Pantheons static std::map PantheonsByIdent; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; - std::string Ident; /// Ident of the pantheon std::string Name; /// Name of the pantheon std::string Description; std::string Background; diff --git a/src/include/resource.h b/src/include/resource.h index 0abf539a5..81765df47 100644 --- a/src/include/resource.h +++ b/src/include/resource.h @@ -35,6 +35,8 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" + #include #include #include @@ -43,7 +45,6 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; struct lua_State; /** @@ -83,7 +84,7 @@ enum CostType { #define ManaResCost (MaxCosts + 2) #define FreeWorkersCount (MaxCosts + 3) -class CResource +class CResource : public CDataType { public: static CResource *GetResource(const std::string &ident, const bool should_find = true); @@ -93,10 +94,9 @@ class CResource static std::vector Resources; static std::map ResourcesByIdent; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; bool IsMineResource() const; - std::string Ident; std::string Name; std::string ActionName; int ID = -1; diff --git a/src/include/school_of_magic.h b/src/include/school_of_magic.h index bc5eadcde..6edec1bf0 100644 --- a/src/include/school_of_magic.h +++ b/src/include/school_of_magic.h @@ -34,6 +34,8 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" + #include #include #include @@ -42,10 +44,9 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; class CUpgrade; -class CSchoolOfMagic +class CSchoolOfMagic : public CDataType { public: static CSchoolOfMagic *GetSchoolOfMagic(const std::string &ident, bool should_find = true); @@ -57,9 +58,8 @@ class CSchoolOfMagic static std::map SchoolsOfMagicByIdent; static std::map SchoolsOfMagicByUpgrade; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; - std::string Ident; /// Ident of the school of magic std::string Name; /// Name of the school of magic std::string Description; /// Description of the school of magic from an in-game universe perspective std::string Background; /// Description of the school of magic from a perspective outside of the game's universe diff --git a/src/include/spell/spell_adjustvariable.h b/src/include/spell/spell_adjustvariable.h index 7c18f5c6b..da49f611b 100644 --- a/src/include/spell/spell_adjustvariable.h +++ b/src/include/spell/spell_adjustvariable.h @@ -68,7 +68,7 @@ class Spell_AdjustVariable : public SpellActionType public: Spell_AdjustVariable() : Var(nullptr) {}; ~Spell_AdjustVariable() { delete [](this->Var); }; - virtual void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *l, int startIndex, int endIndex); diff --git a/src/include/spell/spell_adjustvital.h b/src/include/spell/spell_adjustvital.h index f24f8d292..0c573b23e 100644 --- a/src/include/spell/spell_adjustvital.h +++ b/src/include/spell/spell_adjustvital.h @@ -40,7 +40,7 @@ class Spell_AdjustVital : public SpellActionType { public: Spell_AdjustVital() : SpellActionType(1), HP(0), Mana(0), Shield(0), MaxMultiCast(0) {}; - virtual void ProcessConfigData(const CConfigData *config_data) {} + virtual void ProcessConfigData(const CConfigData *config_data) override {} virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *l, int startIndex, int endIndex); diff --git a/src/include/spell/spell_areaadjustvital.h b/src/include/spell/spell_areaadjustvital.h index 53452aff4..f4e787c87 100644 --- a/src/include/spell/spell_areaadjustvital.h +++ b/src/include/spell/spell_areaadjustvital.h @@ -39,18 +39,17 @@ class Spell_AreaAdjustVital : public SpellActionType { public: - Spell_AreaAdjustVital() : HP(0), Mana(0), Shield(0), Range(1), UseMana(false) {}; - virtual void ProcessConfigData(const CConfigData *config_data) {} + virtual void ProcessConfigData(const CConfigData *config_data) override {} virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *l, int startIndex, int endIndex); private: - int HP; /// Target HP gain.(can be negative) - int Mana; /// Target Mana gain.(can be negative) - int Shield; /// Target SP gain.(can be negative) - int Range; /// Range of spell - bool UseMana; /// If true, use mana for spell cast + int HP = 0; /// Target HP gain.(can be negative) + int Mana = 0; /// Target Mana gain.(can be negative) + int Shield = 0; /// Target SP gain.(can be negative) + int Range = 1; /// Range of spell + bool UseMana = false; /// If true, use mana for spell cast }; #endif diff --git a/src/include/spell/spell_areabombardment.h b/src/include/spell/spell_areabombardment.h index 72a45d99a..8364d3843 100644 --- a/src/include/spell/spell_areabombardment.h +++ b/src/include/spell/spell_areabombardment.h @@ -41,7 +41,7 @@ class Spell_AreaBombardment : public SpellActionType public: Spell_AreaBombardment() : Fields(0), Shards(0), Damage(0), StartOffsetX(0), StartOffsetY(0), Missile(nullptr) {}; - virtual void ProcessConfigData(const CConfigData *config_data) {} + virtual void ProcessConfigData(const CConfigData *config_data) override {} virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *l, int startIndex, int endIndex); diff --git a/src/include/spell/spell_capture.h b/src/include/spell/spell_capture.h index 81897b4d7..9cc62f27b 100644 --- a/src/include/spell/spell_capture.h +++ b/src/include/spell/spell_capture.h @@ -40,7 +40,7 @@ class Spell_Capture : public SpellActionType { public: Spell_Capture() : SacrificeEnable(false), JoinToAIForce(false), Damage(0), DamagePercent(0) {}; - virtual void ProcessConfigData(const CConfigData *config_data) {}; + virtual void ProcessConfigData(const CConfigData *config_data) override {}; virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *l, int startIndex, int endIndex); diff --git a/src/include/spell/spell_demolish.h b/src/include/spell/spell_demolish.h index 6979e4c15..f8634d648 100644 --- a/src/include/spell/spell_demolish.h +++ b/src/include/spell/spell_demolish.h @@ -39,7 +39,7 @@ class Spell_Demolish : public SpellActionType { public: - virtual void ProcessConfigData(const CConfigData *config_data) {}; + virtual void ProcessConfigData(const CConfigData *config_data) override {}; virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *l, int startIndex, int endIndex); diff --git a/src/include/spell/spell_luacallback.h b/src/include/spell/spell_luacallback.h index 25e1f3e0d..52e6bae47 100644 --- a/src/include/spell/spell_luacallback.h +++ b/src/include/spell/spell_luacallback.h @@ -42,7 +42,7 @@ class Spell_LuaCallback : public SpellActionType public: Spell_LuaCallback() : Func(nullptr) {}; ~Spell_LuaCallback() { delete Func; }; - virtual void ProcessConfigData(const CConfigData *config_data) {} + virtual void ProcessConfigData(const CConfigData *config_data) override {} virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *l, int startIndex, int endIndex); diff --git a/src/include/spell/spell_polymorph.h b/src/include/spell/spell_polymorph.h index 6cc9e075d..e26648c4b 100644 --- a/src/include/spell/spell_polymorph.h +++ b/src/include/spell/spell_polymorph.h @@ -39,22 +39,19 @@ class Spell_Polymorph : public SpellActionType { public: - //Wyrmgus start -// Spell_Polymorph() : SpellActionType(1), NewForm(nullptr), PlayerNeutral(0) {}; - Spell_Polymorph() : SpellActionType(1), NewForm(nullptr), PlayerNeutral(0), Civilization(-1), Faction(-1), Detachment(false) {}; - //Wyrmgus end - virtual void ProcessConfigData(const CConfigData *config_data) {} + Spell_Polymorph() : SpellActionType(1) {}; + virtual void ProcessConfigData(const CConfigData *config_data) override {} virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *l, int startIndex, int endIndex); private: - CUnitType *NewForm; /// The new form - int PlayerNeutral; /// Convert the unit to the neutral player, or to the caster's player. + CUnitType *NewForm = nullptr; /// The new form + int PlayerNeutral = 0; /// Convert the unit to the neutral player, or to the caster's player. //Wyrmgus start - int Civilization; /// For using with the Faction value. - int Faction; /// If the unit should be transformed in its faction equivalent. - bool Detachment; /// If the unit should be transformed from its faction-specific type to the generic civilization equivalent. + int Civilization = -1; /// For using with the Faction value. + int Faction = -1; /// If the unit should be transformed in its faction equivalent. + bool Detachment = false; /// If the unit should be transformed from its faction-specific type to the generic civilization equivalent. //Wyrmgus end // TODO: temporary polymorphs would be awesome, but hard to implement }; diff --git a/src/include/spell/spell_retrain.h b/src/include/spell/spell_retrain.h index 793f09e17..0c7635f4f 100644 --- a/src/include/spell/spell_retrain.h +++ b/src/include/spell/spell_retrain.h @@ -39,7 +39,7 @@ class Spell_Retrain : public SpellActionType { public: - virtual void ProcessConfigData(const CConfigData *config_data) {} + virtual void ProcessConfigData(const CConfigData *config_data) override {} virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *l, int startIndex, int endIndex); diff --git a/src/include/spell/spell_spawnmissile.h b/src/include/spell/spell_spawnmissile.h index f2110e7d7..8a7e14a3c 100644 --- a/src/include/spell/spell_spawnmissile.h +++ b/src/include/spell/spell_spawnmissile.h @@ -69,7 +69,7 @@ class Spell_SpawnMissile : public SpellActionType public: Spell_SpawnMissile() : StartPoint(LocBaseCaster), EndPoint(LocBaseTarget) {} - virtual void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *lua, int startIndex, int endIndex); diff --git a/src/include/spell/spell_spawnportal.h b/src/include/spell/spell_spawnportal.h index dc3fa4cfe..10441d114 100644 --- a/src/include/spell/spell_spawnportal.h +++ b/src/include/spell/spell_spawnportal.h @@ -42,7 +42,7 @@ class Spell_SpawnPortal : public SpellActionType { public: Spell_SpawnPortal() : PortalType(0), TTL(0), CurrentPlayer(false) {}; - virtual void ProcessConfigData(const CConfigData *config_data) {} + virtual void ProcessConfigData(const CConfigData *config_data) override {} virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *l, int startIndex, int endIndex); diff --git a/src/include/spell/spell_summon.h b/src/include/spell/spell_summon.h index 89fa08cfa..0c802f8f1 100644 --- a/src/include/spell/spell_summon.h +++ b/src/include/spell/spell_summon.h @@ -41,7 +41,7 @@ class Spell_Summon : public SpellActionType public: Spell_Summon() : SpellActionType(1), UnitType(nullptr), TTL(0), RequireCorpse(false), JoinToAiForce(false) {}; - virtual void ProcessConfigData(const CConfigData *config_data) {} + virtual void ProcessConfigData(const CConfigData *config_data) override {} virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *l, int startIndex, int endIndex); diff --git a/src/include/spell/spell_teleport.h b/src/include/spell/spell_teleport.h index 8a8bc5358..d4b1367c1 100644 --- a/src/include/spell/spell_teleport.h +++ b/src/include/spell/spell_teleport.h @@ -39,7 +39,7 @@ class Spell_Teleport : public SpellActionType { public: Spell_Teleport() : SpellActionType(0) {} - virtual void ProcessConfigData(const CConfigData *config_data) {} + virtual void ProcessConfigData(const CConfigData *config_data) override {} virtual int Cast(CUnit &caster, const CSpell &spell, CUnit *target, const Vec2i &goalPos, int z, int modifier); virtual void Parse(lua_State *l, int startIndex, int endIndex); diff --git a/src/include/spells.h b/src/include/spells.h index b1d39d4a3..403f1dd76 100644 --- a/src/include/spells.h +++ b/src/include/spells.h @@ -31,12 +31,11 @@ #ifndef __SPELLS_H__ #define __SPELLS_H__ -//@{ - /*---------------------------------------------------------------------------- -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" #include "luacallback.h" #include "unitsound.h" #include "vec2i.h" @@ -228,7 +227,7 @@ class AutoCastInfo /** ** Base structure of a spell type. */ -class CSpell +class CSpell : public CDataType { public: CSpell(int slot, const std::string &ident); @@ -242,7 +241,7 @@ class CSpell static std::vector Spells; static std::map SpellsByIdent; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; /// return 1 if spell is available, 0 if not (must upgrade) bool IsAvailableForUnit(const CUnit &unit) const; const AutoCastInfo *GetAutoCastInfo(const bool ai) const; @@ -251,7 +250,6 @@ class CSpell std::vector GetPotentialAutoCastTargets(const CUnit &caster, const AutoCastInfo *autocast) const; // Identification stuff - std::string Ident; /// Spell unique identifier (spell-holy-vision) std::string Name; /// Spell name shown by the engine std::string Description; /// Spell description int Slot; /// Spell numeric identifier @@ -317,6 +315,4 @@ extern int AutoCastSpell(CUnit &caster, const CSpell &spell); /// return 0, 1, 2 for true, only, false. extern char Ccl2Condition(lua_State *l, const char *value); -//@} - -#endif // !__SPELLS_H__ +#endif diff --git a/src/include/time/calendar.h b/src/include/time/calendar.h index b6ff2f8ab..dfbc3266b 100644 --- a/src/include/time/calendar.h +++ b/src/include/time/calendar.h @@ -30,63 +30,46 @@ #ifndef __CALENDAR_H__ #define __CALENDAR_H__ -//@{ - /*---------------------------------------------------------------------------- -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" +#include "time/date.h" + #include #include #include -#include "time/date.h" - /*---------------------------------------------------------------------------- -- Declarations ----------------------------------------------------------------------------*/ class CCalendar; -class CConfigData; class CDayOfTheWeek { public: - CDayOfTheWeek() : - ID(-1), Calendar(nullptr) - { - } - void ProcessConfigData(const CConfigData *config_data); std::string Ident; std::string Name; - int ID; - CCalendar *Calendar; + int ID = -1; + CCalendar *Calendar = nullptr; }; class CMonth { public: - CMonth() : - Days(0) - { - } - void ProcessConfigData(const CConfigData *config_data); std::string Name; - int Days; + int Days = 0; }; -class CCalendar +class CCalendar : public CDataType { public: - CCalendar() : - Initialized(false), HoursPerDay(DEFAULT_HOURS_PER_DAY), DaysPerYear(0), BaseDayOfTheWeek(nullptr), CurrentDayOfTheWeek(-1) - { - } - ~CCalendar(); static CCalendar *GetCalendar(const std::string &ident, const bool should_find = true); @@ -97,7 +80,7 @@ class CCalendar static std::map CalendarsByIdent; static CCalendar *BaseCalendar; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; private: CDayOfTheWeek *GetDayOfTheWeekByIdent(const std::string &ident); void AddChronologicalIntersection(CCalendar *intersecting_calendar, const CDate &date, const CDate &intersecting_date); @@ -105,16 +88,15 @@ class CCalendar public: std::pair GetBestChronologicalIntersectionForDate(CCalendar *calendar, const CDate &date) const; - std::string Ident; std::string Name; - bool Initialized; - int HoursPerDay; - int DaysPerYear; + bool Initialized = false; + int HoursPerDay = DEFAULT_HOURS_PER_DAY; + int DaysPerYear = 0; std::string YearLabel; /// label used for years (e.g. AD) std::string NegativeYearLabel; /// label used for "negative" years (e.g. BC) - CDayOfTheWeek *BaseDayOfTheWeek; /// the day of the week for the first day of the year in the calendar + CDayOfTheWeek *BaseDayOfTheWeek = nullptr; /// the day of the week for the first day of the year in the calendar CDate CurrentDate; /// the current date in this calendar within a game - int CurrentDayOfTheWeek; /// the current day of the week in this calendar within a game + int CurrentDayOfTheWeek = -1; /// the current day of the week in this calendar within a game std::vector DaysOfTheWeek; /// the days of the week in the calendar std::vector Months; /// the months in the calendar private: @@ -122,6 +104,4 @@ class CCalendar std::map> ChronologicalIntersections; /// chronological intersection points between this calendar and other calendars }; -//@} - -#endif // !__CALENDAR_H__ +#endif diff --git a/src/include/time/season.h b/src/include/time/season.h index 0529b8be2..9c857feef 100644 --- a/src/include/time/season.h +++ b/src/include/time/season.h @@ -30,12 +30,12 @@ #ifndef __SEASON_H__ #define __SEASON_H__ -//@{ - /*---------------------------------------------------------------------------- -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" + #include #include #include @@ -44,10 +44,9 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; class CGraphic; -class CSeason +class CSeason : public CDataType { public: static CSeason *GetSeason(const std::string &ident, const bool should_find = true); @@ -57,13 +56,10 @@ class CSeason static std::vector Seasons; /// Seasons static std::map SeasonsByIdent; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; - std::string Ident; /// Ident of the season std::string Name; /// Name of the season CGraphic *G = nullptr; }; -//@} - -#endif // !__SEASON_H__ +#endif diff --git a/src/include/time/season_schedule.h b/src/include/time/season_schedule.h index a8dec3b2e..144f60c8b 100644 --- a/src/include/time/season_schedule.h +++ b/src/include/time/season_schedule.h @@ -46,32 +46,21 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; class CSeason; class CSeasonSchedule; class CScheduledSeason { public: - CScheduledSeason() : - ID(0), Season(nullptr), Hours(0), Schedule(nullptr) - { - } - - unsigned ID; /// the scheduled season's ID within the season schedule - CSeason *Season; /// the season that is scheduled - unsigned Hours; /// the amount of hours the scheduled season lasts - CSeasonSchedule *Schedule; /// the schedule to which this season belongs + unsigned ID = 0; /// the scheduled season's ID within the season schedule + CSeason *Season = nullptr; /// the season that is scheduled + unsigned Hours = 0; /// the amount of hours the scheduled season lasts + CSeasonSchedule *Schedule = nullptr; /// the schedule to which this season belongs }; class CSeasonSchedule : public CTimePeriodSchedule { public: - CSeasonSchedule() : - HoursPerDay(DEFAULT_HOURS_PER_DAY) - { - } - ~CSeasonSchedule(); static CSeasonSchedule *GetSeasonSchedule(const std::string &ident, const bool should_find = true); @@ -82,16 +71,13 @@ class CSeasonSchedule : public CTimePeriodSchedule static std::map SeasonSchedulesByIdent; static CSeasonSchedule *DefaultSeasonSchedule; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; virtual unsigned long GetDefaultTotalHours() const; virtual int GetDefaultHourMultiplier() const; - std::string Ident; /// Ident of the season schedules - std::string Name; /// Name of the season schedules - unsigned HoursPerDay; /// The hours per each day for this season schedule + std::string Name; /// Name of the season schedule + unsigned HoursPerDay = DEFAULT_HOURS_PER_DAY; /// The hours per each day for this season schedule std::vector ScheduledSeasons; /// The seasons that are scheduled }; -//@} - -#endif // !__SEASON_SCHEDULE_H__ +#endif diff --git a/src/include/time/time_of_day.h b/src/include/time/time_of_day.h index 8f23d76d4..fc8666d9b 100644 --- a/src/include/time/time_of_day.h +++ b/src/include/time/time_of_day.h @@ -30,33 +30,26 @@ #ifndef __TIME_OF_DAY_H__ #define __TIME_OF_DAY_H__ -//@{ - /*---------------------------------------------------------------------------- -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" +#include "color.h" + #include #include #include -#include "color.h" - /*---------------------------------------------------------------------------- -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; class CGraphic; -class CTimeOfDay +class CTimeOfDay : public CDataType { public: - CTimeOfDay() : - ID(-1), Dawn(false), Day(false), Dusk(false), Night(false) - { - } - static CTimeOfDay *GetTimeOfDay(const std::string &ident, const bool should_find = true); static CTimeOfDay *GetOrAddTimeOfDay(const std::string &ident); static void ClearTimesOfDay(); @@ -64,20 +57,17 @@ class CTimeOfDay static std::vector TimesOfDay; /// Times of day static std::map TimesOfDayByIdent; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; bool HasColorModification() const; - std::string Ident; /// Ident of the time of day std::string Name; /// Name of the time of day - int ID; /// The ID of this time of day - bool Dawn; /// Whether this is a dawn time of day - bool Day; /// Whether this is a day time of day - bool Dusk; /// Whether this is a dusk time of day - bool Night; /// Whether this is a night time of day + int ID = -1; /// The ID of this time of day + bool Dawn = false; /// Whether this is a dawn time of day + bool Day = false; /// Whether this is a day time of day + bool Dusk = false; /// Whether this is a dusk time of day + bool Night = false; /// Whether this is a night time of day CColor ColorModification; /// The color modification applied to graphics when the time of day is active CGraphic *G = nullptr; }; -//@} - -#endif // !__TIME_OF_DAY_H__ +#endif diff --git a/src/include/time/time_of_day_schedule.h b/src/include/time/time_of_day_schedule.h index 7e40807ed..672c8d69b 100644 --- a/src/include/time/time_of_day_schedule.h +++ b/src/include/time/time_of_day_schedule.h @@ -30,12 +30,11 @@ #ifndef __TIME_OF_DAY_SCHEDULE_H__ #define __TIME_OF_DAY_SCHEDULE_H__ -//@{ - /*---------------------------------------------------------------------------- -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" #include "time/time_period_schedule.h" #include @@ -54,30 +53,21 @@ class CTimeOfDaySchedule; class CScheduledTimeOfDay { public: - CScheduledTimeOfDay() : - ID(0), TimeOfDay(nullptr), Hours(0), Schedule(nullptr) - { - } - void ProcessConfigData(const CConfigData *config_data); int GetHours(const CSeason *season = nullptr) const; - unsigned ID; /// the scheduled time of day's ID within the time of day schedule - CTimeOfDay *TimeOfDay; /// the time of day that is scheduled + unsigned ID = 0; /// the scheduled time of day's ID within the time of day schedule + CTimeOfDay *TimeOfDay = nullptr; /// the time of day that is scheduled private: - int Hours; /// the amount of hours the scheduled time of day lasts + int Hours = 0; /// the amount of hours the scheduled time of day lasts public: - CTimeOfDaySchedule *Schedule; /// the schedule to which this time of day belongs + CTimeOfDaySchedule *Schedule = nullptr; /// the schedule to which this time of day belongs std::map SeasonHours; /// the amount of hours the scheduled time of day lasts in a given season }; class CTimeOfDaySchedule : public CTimePeriodSchedule { public: - CTimeOfDaySchedule() - { - } - ~CTimeOfDaySchedule(); static CTimeOfDaySchedule *GetTimeOfDaySchedule(const std::string &ident, const bool should_find = true); @@ -88,15 +78,12 @@ class CTimeOfDaySchedule : public CTimePeriodSchedule static std::map TimeOfDaySchedulesByIdent; static CTimeOfDaySchedule *DefaultTimeOfDaySchedule; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; virtual unsigned long GetDefaultTotalHours() const; virtual int GetDefaultHourMultiplier() const; - std::string Ident; /// Ident of the time of day schedules std::string Name; /// Name of the time of day schedules std::vector ScheduledTimesOfDay; /// The times of day that are scheduled }; -//@} - -#endif // !__TIME_OF_DAY_SCHEDULE_H__ +#endif diff --git a/src/include/time/time_period_schedule.h b/src/include/time/time_period_schedule.h index 868b9707f..673353cf0 100644 --- a/src/include/time/time_period_schedule.h +++ b/src/include/time/time_period_schedule.h @@ -30,12 +30,12 @@ #ifndef __TIME_PERIOD_SCHEDULE_H__ #define __TIME_PERIOD_SCHEDULE_H__ -//@{ - /*---------------------------------------------------------------------------- -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" + #include #include #include @@ -44,22 +44,15 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CTimePeriodSchedule +class CTimePeriodSchedule : public CDataType { public: - CTimePeriodSchedule() : - TotalHours(0), HourMultiplier(1) - { - } - virtual unsigned long GetDefaultTotalHours() const = 0; virtual int GetDefaultHourMultiplier() const = 0; void CalculateHourMultiplier(); - unsigned long TotalHours; /// The total amount of hours this time period schedule contains - int HourMultiplier; /// The amount of hours that pass for this schedule for each in-game hour + unsigned long TotalHours = 0; /// The total amount of hours this time period schedule contains + int HourMultiplier = 1; /// The amount of hours that pass for this schedule for each in-game hour }; -//@} - -#endif // !__TIME_PERIOD_SCHEDULE_H__ +#endif diff --git a/src/include/time/timeline.h b/src/include/time/timeline.h index e7d5c7178..99f5b9ebb 100644 --- a/src/include/time/timeline.h +++ b/src/include/time/timeline.h @@ -36,26 +36,20 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" +#include "time/date.h" + #include #include #include -#include "time/date.h" - /*---------------------------------------------------------------------------- -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; - -class CTimeline +class CTimeline : public CDataType { public: - CTimeline() : - ID(-1) - { - } - static CTimeline *GetTimeline(const std::string &ident); static CTimeline *GetOrAddTimeline(const std::string &ident); static void ClearTimelines(); @@ -63,14 +57,11 @@ class CTimeline static std::vector Timelines; static std::map TimelinesByIdent; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; - int ID; - std::string Ident; + int ID = -1; std::string Name; CDate PointOfDivergence; /// The point of divergence for this timeline }; -//@} - -#endif // !__TIMELINE_H__ +#endif diff --git a/src/include/trigger.h b/src/include/trigger.h index 075c2b214..ca65a0f44 100644 --- a/src/include/trigger.h +++ b/src/include/trigger.h @@ -34,6 +34,8 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" + #include #include @@ -41,7 +43,6 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; class CFaction; class CFile; class CTriggerEffect; @@ -73,7 +74,7 @@ class CTimer unsigned long LastUpdate = 0; /// GameCycle of last update }; -class CTrigger +class CTrigger : public CDataType { public: enum class TriggerType @@ -96,9 +97,8 @@ class CTrigger ~CTrigger(); - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; - std::string Ident; TriggerType Type = TriggerType::GlobalTrigger; bool Local = false; bool OnlyOnce = false; /// Whether the trigger should occur only once in a game diff --git a/src/include/trigger_effect.h b/src/include/trigger_effect.h index 52f28bafe..bc6d6a519 100644 --- a/src/include/trigger_effect.h +++ b/src/include/trigger_effect.h @@ -55,7 +55,7 @@ class CTriggerEffect class CCallDialogueTriggerEffect : public CTriggerEffect { public: - virtual void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; virtual void Do(CPlayer *player) const; /// Performs the trigger effect CDialogue *Dialogue = nullptr; /// Dialogue to be called @@ -65,7 +65,7 @@ class CCallDialogueTriggerEffect : public CTriggerEffect class CCreateUnitTriggerEffect : public CTriggerEffect { public: - virtual void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; virtual void Do(CPlayer *player) const; /// Performs the trigger effect int Quantity = 1; /// Quantity of units created diff --git a/src/include/ui/button_level.h b/src/include/ui/button_level.h index bc6c5ef49..ca9630c97 100644 --- a/src/include/ui/button_level.h +++ b/src/include/ui/button_level.h @@ -36,6 +36,8 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" + #include #include #include @@ -44,16 +46,9 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; - -class CButtonLevel +class CButtonLevel : public CDataType { public: - CButtonLevel() : - ID(-1) - { - } - static CButtonLevel *GetButtonLevel(const std::string &ident, const bool should_find = true); static CButtonLevel *GetOrAddButtonLevel(const std::string &ident); static void ClearButtonLevels(); @@ -63,12 +58,9 @@ class CButtonLevel static CButtonLevel *CancelButtonLevel; static CButtonLevel *InventoryButtonLevel; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; - std::string Ident; /// Ident of the button level - int ID; /// ID of the button level (starting at 1) + int ID = -1; /// ID of the button level (starting at 1) }; -//@} - -#endif // !__BUTTON_LEVEL_H__ +#endif diff --git a/src/include/unit/historical_unit.h b/src/include/unit/historical_unit.h index 6cc94b64b..7c3964812 100644 --- a/src/include/unit/historical_unit.h +++ b/src/include/unit/historical_unit.h @@ -30,12 +30,11 @@ #ifndef __HISTORICAL_UNIT_H__ #define __HISTORICAL_UNIT_H__ -//@{ - /*---------------------------------------------------------------------------- -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" #include "time/date.h" #include @@ -46,12 +45,11 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; class CFaction; class CHistoricalLocation; class CUnitType; -class CHistoricalUnit +class CHistoricalUnit : public CDataType { public: ~CHistoricalUnit(); @@ -63,10 +61,9 @@ class CHistoricalUnit static std::vector HistoricalUnits; static std::map HistoricalUnitsByIdent; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; public: - std::string Ident; //the unit's string identifier std::string Name; //the unit's name CUnitType *UnitType = nullptr; //the unit's unit type CFaction *Faction = nullptr; //the unit's faction @@ -76,6 +73,4 @@ class CHistoricalUnit std::vector HistoricalLocations; //historical locations for the unit }; -//@} - -#endif // !__HISTORICAL_UNIT_H__ +#endif diff --git a/src/include/unit/unittype.h b/src/include/unit/unittype.h index 434bea809..ce2d1ca93 100644 --- a/src/include/unit/unittype.h +++ b/src/include/unit/unittype.h @@ -34,19 +34,20 @@ -- Includes ----------------------------------------------------------------------------*/ -#include -#include -#include -#include -#include - #include "color.h" +#include "data_type.h" #include "icons.h" #include "missileconfig.h" #include "unitsound.h" #include "upgrade/upgrade_structs.h" #include "vec2i.h" +#include +#include +#include +#include +#include + #ifdef __MORPHOS__ #undef Enable #endif @@ -789,30 +790,23 @@ class CSpeciesGenus class CSpecies { public: - CSpecies() : - Era(-1), - Sapient(false), Prehistoric(false), - Genus(nullptr), HomePlane(nullptr), Homeworld(nullptr), Type(nullptr) - { - } - bool CanEvolveToAUnitType(CTerrainType *terrain = nullptr, bool sapient_only = false); CSpecies *GetRandomEvolution(CTerrainType *terrain); - int Era; /// Era ID - bool Sapient; /// Whether the species is sapient - bool Prehistoric; /// Whether the species is prehistoric or not + int Era = -1; /// Era ID + bool Sapient = false; /// Whether the species is sapient + bool Prehistoric = false; /// Whether the species is prehistoric or not std::string Ident; /// Ident of the species std::string Name; /// Name of the species std::string Description; /// Description of the species std::string Quote; /// Quote pertaining to the species std::string Background; /// Background of the species - CSpeciesGenus *Genus; + CSpeciesGenus *Genus = nullptr; std::string Species; std::string ChildUpgrade; /// Which individual upgrade the children of this species get - CPlane *HomePlane; - CWorld *Homeworld; - CUnitType *Type; + CPlane *HomePlane = nullptr; + CWorld *Homeworld = nullptr; + CUnitType *Type = nullptr; std::vector Terrains; /// in which terrains does this species live std::vector EvolvesFrom; /// from which species this one can evolve std::vector EvolvesTo; /// to which species this one can evolve @@ -821,13 +815,13 @@ class CSpecies /// Base structure of unit-type /// @todo n0body: AutoBuildRate not implemented. -class CUnitType +class CUnitType : public CDataType { public: CUnitType(); ~CUnitType(); - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; Vec2i GetTileSize() const; Vec2i GetHalfTileSize() const; @@ -863,7 +857,6 @@ class CUnitType //Wyrmgus end public: - std::string Ident; /// Identifier std::string Name; /// Pretty name shown from the engine bool Initialized = false; CUnitType *Parent; /// Parent unit type diff --git a/src/include/upgrade/upgrade_structs.h b/src/include/upgrade/upgrade_structs.h index d2bcb516c..86eb6f83d 100644 --- a/src/include/upgrade/upgrade_structs.h +++ b/src/include/upgrade/upgrade_structs.h @@ -35,13 +35,14 @@ -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" //Wyrmgus start #include "item.h" //Wyrmgus end #include "resource.h" - #include + /*---------------------------------------------------------------------------- -- Defines ----------------------------------------------------------------------------*/ @@ -51,7 +52,6 @@ ----------------------------------------------------------------------------*/ class CCharacter; -class CConfigData; class CDeityDomain; class CIcon; class CSchoolOfMagic; @@ -97,7 +97,7 @@ class CUnitStats /** ** The main useable upgrades. */ -class CUpgrade +class CUpgrade : public CDataType { public: CUpgrade(const std::string &ident); @@ -106,47 +106,46 @@ class CUpgrade static CUpgrade *New(const std::string &ident); static CUpgrade *Get(const std::string &ident); - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; void SetIcon(CIcon *icon); - std::string Ident; /// identifier std::string Name; /// upgrade label //Wyrmgus start - int Class; /// upgrade class (i.e. siege weapon projectile I) - int Civilization; /// which civilization this upgrade belongs to, if any - int Faction; /// which faction this upgrade belongs to, if any + int Class = -1; /// upgrade class (i.e. siege weapon projectile I) + int Civilization = -1; /// which civilization this upgrade belongs to, if any + int Faction = -1; /// which faction this upgrade belongs to, if any std::string Description; /// Description of the upgrade std::string Quote; /// Quote of the upgrade std::string Background; /// Encyclopedia entry for the upgrade std::string EffectsString; /// Effects string of the upgrade std::string RequirementsString; /// Requirements string of the upgrade - bool Ability; - bool Weapon; - bool Shield; - bool Boots; - bool Arrows; - bool MagicPrefix; - bool MagicSuffix; - bool RunicAffix; - bool UniqueOnly; /// Whether (if this is a literary work) this should appear only on unique items (used, for instance, if a book has no copies of its text) + bool Ability = false; + bool Weapon = false; + bool Shield = false; + bool Boots = false; + bool Arrows = false; + bool MagicPrefix = false; + bool MagicSuffix = false; + bool RunicAffix = false; + bool UniqueOnly = false; /// Whether (if this is a literary work) this should appear only on unique items (used, for instance, if a book has no copies of its text) bool ItemPrefix[MaxItemClasses]; bool ItemSuffix[MaxItemClasses]; bool IncompatibleAffixes[UpgradeMax]; std::vector WeaponClasses; /// If isn't empty, one of these weapon classes will need to be equipped for the upgrade to be applied std::vector Epithets; /// Epithets when a character has a certain trait - CUnitType *Item; + CUnitType *Item = nullptr; //Wyrmgus end - int ID; /// numerical id - int Costs[MaxCosts]; /// costs for the upgrade - int ScaledCosts[MaxCosts]; /// scaled costs for the upgrade + int ID = 0; /// numerical id + int Costs[MaxCosts]; /// costs for the upgrade + int ScaledCosts[MaxCosts]; /// scaled costs for the upgrade //Wyrmgus start int GrandStrategyProductionEfficiencyModifier[MaxCosts]; /// Production modifier for a particular resource for grand strategy mode - int MaxLimit; /// Maximum amount of times this upgrade can be acquired as an individual upgrade - int MagicLevel; /// Magic level of an affix - int Work; /// Form in which was inscribed (i.e. scroll or book), if is a literary work - int Year; /// Year of publication, if is a literary work - CCharacter *Author; /// Author of this literary work (if it is one) + int MaxLimit = 1; /// Maximum amount of times this upgrade can be acquired as an individual upgrade + int MagicLevel = 0; /// Magic level of an affix + int Work = -1; /// Form in which was inscribed (i.e. scroll or book), if is a literary work + int Year = 0; /// Year of publication, if is a literary work + CCharacter *Author = nullptr; /// Author of this literary work (if it is one) std::vector UpgradeModifiers; /// Upgrade modifiers for this upgrade std::vector UniqueItems; /// Unique items who form a part of this set upgrade std::vector ScaledCostUnits; /// Units for which the upgrade's costs are scaled @@ -155,7 +154,7 @@ class CUpgrade std::vector Characters; /// Characters who appear in this literary work (if it is one) //Wyrmgus end // TODO: not used by buttons - CIcon *Icon; /// icon to display to the user + CIcon *Icon = nullptr; /// icon to display to the user }; /** diff --git a/src/include/world.h b/src/include/world.h index bf73a29cb..d15d47fee 100644 --- a/src/include/world.h +++ b/src/include/world.h @@ -30,12 +30,12 @@ #ifndef __WORLD_H__ #define __WORLD_H__ -//@{ - /*---------------------------------------------------------------------------- -- Includes ----------------------------------------------------------------------------*/ +#include "data_type.h" + #include #include #include @@ -44,7 +44,6 @@ -- Declarations ----------------------------------------------------------------------------*/ -class CConfigData; class CPlane; class CProvince; class CSeasonSchedule; @@ -52,14 +51,9 @@ class CSpecies; class CTerrainFeature; class CTimeOfDaySchedule; -class CWorld +class CWorld : public CDataType { public: - CWorld() : - ID(-1), Plane(nullptr), TimeOfDaySchedule(nullptr), SeasonSchedule(nullptr) - { - } - static CWorld *GetWorld(const std::string &ident, const bool should_find = true); static CWorld *GetOrAddWorld(const std::string &ident); static void ClearWorlds(); @@ -67,22 +61,19 @@ class CWorld static std::vector Worlds; /// Worlds static std::map WorldsByIdent; - void ProcessConfigData(const CConfigData *config_data); + virtual void ProcessConfigData(const CConfigData *config_data) override; - int ID; /// ID of this world - std::string Ident; + int ID = -1; /// ID of this world std::string Name; std::string Description; std::string Background; std::string Quote; - CPlane *Plane; - CTimeOfDaySchedule *TimeOfDaySchedule; /// this world's time of day schedule - CSeasonSchedule *SeasonSchedule; /// this world's season schedule + CPlane *Plane = nullptr; + CTimeOfDaySchedule *TimeOfDaySchedule = nullptr; /// this world's time of day schedule + CSeasonSchedule *SeasonSchedule = nullptr; /// this world's season schedule std::vector Provinces; /// Provinces in this world std::vector TerrainFeatures; /// Terrain features in this world std::vector Species; /// Species in this world }; -//@} - -#endif // !__WORLD_H__ +#endif diff --git a/src/missile/missile.cpp b/src/missile/missile.cpp index 762eeef90..95d952125 100644 --- a/src/missile/missile.cpp +++ b/src/missile/missile.cpp @@ -2067,7 +2067,7 @@ void InitMissileTypes() ** Constructor. */ MissileType::MissileType(const std::string &ident) : - Ident(ident), Transparency(0), DrawLevel(0), + Transparency(0), DrawLevel(0), SpriteFrames(0), NumDirections(1), ChangeVariable(-1), ChangeAmount(0), ChangeMax(false), //Wyrmgus start // CorrectSphashDamage(false), Flip(false), CanHitOwner(false), FriendlyFire(false), @@ -2086,6 +2086,7 @@ MissileType::MissileType(const std::string &ident) : ImpactParticle(nullptr), SmokeParticle(nullptr), OnImpact(nullptr), G(nullptr) { + this->Ident = ident; size.x = 0; size.y = 0; } diff --git a/src/spell/spells.cpp b/src/spell/spells.cpp index 58e5456a1..0702f4fc0 100644 --- a/src/spell/spells.cpp +++ b/src/spell/spells.cpp @@ -289,11 +289,13 @@ class AutoCastPrioritySort ** @brief Spell constructor. */ CSpell::CSpell(int slot, const std::string &ident) : - Ident(ident), Slot(slot), Target(), Action(), + Slot(slot), Target(), Action(), Range(0), ManaCost(0), RepeatCast(0), Stackable(true), CoolDown(0), DependencyId(-1), Condition(nullptr), AutoCast(nullptr), AICast(nullptr), ForceUseAnimation(false) { + this->Ident = ident; + memset(Costs, 0, sizeof(Costs)); //Wyrmgus start memset(ItemSpell, 0, sizeof(ItemSpell)); diff --git a/src/upgrade/upgrade.cpp b/src/upgrade/upgrade.cpp index 64c838ce2..f5cfc7d2a 100644 --- a/src/upgrade/upgrade.cpp +++ b/src/upgrade/upgrade.cpp @@ -213,12 +213,10 @@ void CUnitStats::ChangeUnitStock(CUnitType *unit_type, int quantity) this->SetUnitStock(unit_type, this->GetUnitStock(unit_type) + quantity); } -CUpgrade::CUpgrade(const std::string &ident) : - //Wyrmgus start -// Ident(ident), ID(0) - Ident(ident), ID(0), Class(-1), Civilization(-1), Faction(-1), Ability(false), Weapon(false), Shield(false), Boots(false), Arrows(false), MagicPrefix(false), MagicSuffix(false), RunicAffix(false),UniqueOnly(false), Work(-1), Icon(nullptr), Item(nullptr), MaxLimit(1), MagicLevel(0), Year(0), Author(nullptr) - //Wyrmgus end +CUpgrade::CUpgrade(const std::string &ident) { + this->Ident = ident; + memset(this->Costs, 0, sizeof(this->Costs)); //Wyrmgus start memset(this->ScaledCosts, 0, sizeof(this->ScaledCosts));