Skip to content

Commit

Permalink
Added data type base class for unit types, upgrades and etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrettin committed Jan 11, 2019
1 parent 398645a commit acb718d
Show file tree
Hide file tree
Showing 49 changed files with 319 additions and 411 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/include/age.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
-- Includes
----------------------------------------------------------------------------*/

#include "data_type.h"

#include <map>
#include <string>
#include <vector>
Expand All @@ -42,11 +44,10 @@
-- Declarations
----------------------------------------------------------------------------*/

class CConfigData;
class CGraphic;
class CUpgrade;

class CAge
class CAge : public CDataType
{
public:
~CAge();
Expand All @@ -61,10 +62,9 @@ class CAge
static std::map<std::string, CAge *> 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;
Expand Down
43 changes: 19 additions & 24 deletions src/include/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,12 +30,12 @@
#ifndef __ANIMATIONS_H__
#define __ANIMATIONS_H__

//@{
#include "data_type.h"
#include "upgrade/upgrade_structs.h" // MaxCost

#include <string>
#include <map>

#include "upgrade/upgrade_structs.h" // MaxCost
#define ANIMATIONS_DEATHTYPES 40

class CFile;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
};

/*----------------------------------------------------------------------------
Expand Down Expand Up @@ -186,6 +183,4 @@ extern void FreeAnimations();
extern std::map<std::string, CAnimations *> AnimationMap;
//Wyrmgus end

//@}

#endif // !__ANIMATIONS_H__
#endif
7 changes: 3 additions & 4 deletions src/include/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
-- Includes
----------------------------------------------------------------------------*/

#include "data_type.h"
#include "icons.h"
#include "item.h"
#include "time/date.h"
Expand All @@ -49,7 +50,6 @@

class CCalendar;
class CCivilization;
class CConfigData;
class CDeity;
class CDeityDomain;
class CFaction;
Expand Down Expand Up @@ -108,7 +108,7 @@ enum CharacterTitles {
MaxCharacterTitles
};

class CCharacter
class CCharacter : public CDataType
{
public:
CCharacter()
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/include/currency.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
-- Includes
----------------------------------------------------------------------------*/

#include "data_type.h"

#include <map>
#include <string>
#include <vector>
Expand All @@ -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);
Expand All @@ -54,10 +54,9 @@ class CCurrency
static std::vector<CCurrency *> Currencies;
static std::map<std::string, CCurrency *> CurrenciesByIdent;

void ProcessConfigData(const CConfigData *config_data);
virtual void ProcessConfigData(const CConfigData *config_data) override;

public:
std::string Ident;
std::string Name;
};

Expand Down
54 changes: 54 additions & 0 deletions src/include/data_type.h
Original file line number Diff line number Diff line change
@@ -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 <string>

/*----------------------------------------------------------------------------
-- Declarations
----------------------------------------------------------------------------*/

class CConfigData;

class CDataType
{
public:
virtual void ProcessConfigData(const CConfigData *config_data) = 0;

public:
std::string Ident; /// String identifier of the instance
};

#endif
26 changes: 10 additions & 16 deletions src/include/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/*----------------------------------------------------------------------------
Expand Down
6 changes: 1 addition & 5 deletions src/include/map/historical_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#ifndef __HISTORICAL_LOCATION_H__
#define __HISTORICAL_LOCATION_H__

//@{

/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/
Expand All @@ -58,6 +56,4 @@ class CHistoricalLocation
CSite *Site = nullptr; //the historical location's site (if any)
};

//@}

#endif // !__HISTORICAL_LOCATION_H__
#endif
15 changes: 7 additions & 8 deletions src/include/map/map_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@
-- Includes
----------------------------------------------------------------------------*/

#include <map>
#include <string>
#include <vector>

#include "data_type.h"
#include "map/tile.h"
#include "time/date.h"
#include "vec2i.h"

#include <map>
#include <string>
#include <vector>

/*----------------------------------------------------------------------------
-- Declarations
----------------------------------------------------------------------------*/

class CCharacter;
class CConfigData;
class CFaction;
class CHistoricalLocation;
class CMapField;
Expand Down Expand Up @@ -77,7 +77,7 @@ class CGeneratedTerrain
std::vector<const CTerrainType *> TargetTerrainTypes; //the terrain types over which the terrain is to be generated
};

class CMapTemplate
class CMapTemplate : public CDataType
{
public:
CMapTemplate() :
Expand All @@ -94,7 +94,7 @@ class CMapTemplate
static std::vector<CMapTemplate *> MapTemplates; /// Map templates
static std::map<std::string, CMapTemplate *> 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;
Expand All @@ -106,7 +106,6 @@ class CMapTemplate
const CMapTemplate *GetTopMapTemplate() const;
Vec2i GetBestLocationMapPosition(const std::vector<CHistoricalLocation *> &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;
Expand Down
Loading

0 comments on commit acb718d

Please sign in to comment.