Skip to content

Commit

Permalink
Moved the unit type variation class to its own source/header files
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrettin committed Jan 10, 2019
1 parent 81a3027 commit e1a74d3
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 99 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ set(unit_SRCS
src/unit/unit_find.cpp
src/unit/unit_manager.cpp
src/unit/unit_save.cpp
src/unit/unit_type_variation.cpp
src/unit/unitptr.cpp
src/unit/unittype.cpp
)
Expand Down Expand Up @@ -636,6 +637,7 @@ set(stratagus_unit_HDRS
src/include/unit/unit_cache.h
src/include/unit/unit_find.h
src/include/unit/unit_manager.h
src/include/unit/unit_type_variation.h
src/include/unit/unitptr.h
src/include/unit/unittype.h
)
Expand Down
1 change: 1 addition & 0 deletions src/include/unit/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CUnitColors;
class CUnitPtr;
class CUnitStats;
class CUnitType;
class CUnitTypeVariation;
class CUpgrade;
class CVariable;
class CViewport;
Expand Down
108 changes: 108 additions & 0 deletions src/include/unit/unit_type_variation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
//
/**@name unit_type_variation.h - The unit type variation header file. */
//
// (c) Copyright 2014-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 __UNIT_TYPE_VARIATION_H__
#define __UNIT_TYPE_VARIATION_H__

/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/

#include "icons.h"
#include "unit/unittype.h" //for the image layers enum
#include "upgrade/upgrade_structs.h" //for the costs enum

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

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

class CAnimations;
class CConstruction;
class CGraphic;
class CPlayerColorGraphic;
class CSeason;
class CTerrainType;
class CUnitType;

class CUnitTypeVariation
{
public:
CUnitTypeVariation()
{
memset(LayerSprites, 0, sizeof(LayerSprites));
memset(SpriteWhenLoaded, 0, sizeof(SpriteWhenLoaded));
memset(SpriteWhenEmpty, 0, sizeof(SpriteWhenEmpty));
}

~CUnitTypeVariation();

int ID = -1; /// The variation's index within the appropriate variation vector of its unit type
std::string VariationId; /// Variation's name.
std::string TypeName; /// Type name.
std::string File; /// Variation's graphics.
std::string ShadowFile; /// Variation's shadow graphics.
std::string LightFile; /// Variation's light graphics.
int FrameWidth = 0;
int FrameHeight = 0;
int ResourceMin = 0;
int ResourceMax = 0;
int Weight = 1; /// The weight for when randomly choosing a variation
IconConfig Icon; /// Icon to display for this unit
CPlayerColorGraphic *Sprite = nullptr; /// The graphic corresponding to File.
CGraphic *ShadowSprite = nullptr; /// The graphic corresponding to ShadowFile.
CGraphic *LightSprite = nullptr; /// The graphic corresponding to LightFile.
CAnimations *Animations = nullptr; /// Animation scripts
CConstruction *Construction = nullptr; /// What is shown in construction phase

std::vector<const CUpgrade *> UpgradesRequired; /// Upgrades required by variation
std::vector<const CUpgrade *> UpgradesForbidden; /// If the player has one of these upgrades, the unit can't have this variation
std::vector<int> ItemClassesEquipped;
std::vector<int> ItemClassesNotEquipped;
std::vector<const CUnitType *> ItemsEquipped;
std::vector<const CUnitType *> ItemsNotEquipped;
std::vector<const CTerrainType *> Terrains;
std::vector<const CTerrainType *> TerrainsForbidden;
std::vector<const CSeason *> Seasons;
std::vector<const CSeason *> ForbiddenSeasons;

std::string LayerFiles[MaxImageLayers]; /// Variation's layer graphics.
std::string FileWhenLoaded[MaxCosts]; /// Change the graphic when the unit is loaded.
std::string FileWhenEmpty[MaxCosts]; /// Change the graphic when the unit is empty.
CPlayerColorGraphic *LayerSprites[MaxImageLayers]; /// The graphics corresponding to LayerFiles.
CPlayerColorGraphic *SpriteWhenLoaded[MaxCosts]; /// The graphic corresponding to FileWhenLoaded.
CPlayerColorGraphic *SpriteWhenEmpty[MaxCosts]; /// The graphic corresponding to FileWhenEmpty

std::map<int, IconConfig> ButtonIcons; /// icons for button actions
};

#endif
66 changes: 4 additions & 62 deletions src/include/unit/unittype.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#ifndef __UNITTYPE_H__
#define __UNITTYPE_H__

//@{

/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/
Expand All @@ -58,15 +56,15 @@
----------------------------------------------------------------------------*/

class CAnimations;
class CPlayerColorGraphic;
class CConstruction;
class MissileType;
class CFile;
class CPlayerColorGraphic;
class CUnitTypeVariation;
class MissileType;
//Wyrmgus start
class CButtonLevel;
class CFaction;
class CPlane;
class CSeason;
class CWorld;
class CTerrainType;
class CUniqueItem;
Expand Down Expand Up @@ -132,60 +130,6 @@ class ResourceInfo
CPlayerColorGraphic *SpriteWhenEmpty; /// The graphic corresponding to FileWhenEmpty
};

//Wyrmgus start
//unit variations
class CUnitTypeVariation
{
public:
CUnitTypeVariation()
{
memset(LayerSprites, 0, sizeof(LayerSprites));
memset(SpriteWhenLoaded, 0, sizeof(SpriteWhenLoaded));
memset(SpriteWhenEmpty, 0, sizeof(SpriteWhenEmpty));
}

~CUnitTypeVariation();

int ID = -1; /// The variation's index within the appropriate variation vector of its unit type
std::string VariationId; /// Variation's name.
std::string TypeName; /// Type name.
std::string File; /// Variation's graphics.
std::string ShadowFile; /// Variation's shadow graphics.
std::string LightFile; /// Variation's light graphics.
int FrameWidth = 0;
int FrameHeight = 0;
int ResourceMin = 0;
int ResourceMax = 0;
int Weight = 1; /// The weight for when randomly choosing a variation
IconConfig Icon; /// Icon to display for this unit
CPlayerColorGraphic *Sprite = nullptr; /// The graphic corresponding to File.
CGraphic *ShadowSprite = nullptr; /// The graphic corresponding to ShadowFile.
CGraphic *LightSprite = nullptr; /// The graphic corresponding to LightFile.
CAnimations *Animations = nullptr; /// Animation scripts
CConstruction *Construction = nullptr; /// What is shown in construction phase

std::vector<const CUpgrade *> UpgradesRequired; /// Upgrades required by variation
std::vector<const CUpgrade *> UpgradesForbidden; /// If the player has one of these upgrades, the unit can't have this variation
std::vector<int> ItemClassesEquipped;
std::vector<int> ItemClassesNotEquipped;
std::vector<const CUnitType *> ItemsEquipped;
std::vector<const CUnitType *> ItemsNotEquipped;
std::vector<const CTerrainType *> Terrains;
std::vector<const CTerrainType *> TerrainsForbidden;
std::vector<const CSeason *> Seasons;
std::vector<const CSeason *> ForbiddenSeasons;

std::string LayerFiles[MaxImageLayers]; /// Variation's layer graphics.
std::string FileWhenLoaded[MaxCosts]; /// Change the graphic when the unit is loaded.
std::string FileWhenEmpty[MaxCosts]; /// Change the graphic when the unit is empty.
CPlayerColorGraphic *LayerSprites[MaxImageLayers]; /// The graphics corresponding to LayerFiles.
CPlayerColorGraphic *SpriteWhenLoaded[MaxCosts]; /// The graphic corresponding to FileWhenLoaded.
CPlayerColorGraphic *SpriteWhenEmpty[MaxCosts]; /// The graphic corresponding to FileWhenEmpty

std::map<int, IconConfig> ButtonIcons; /// icons for button actions
};
//Wyrmgus end

/**
** User defined variable type.
**
Expand Down Expand Up @@ -1351,6 +1295,4 @@ extern int GetImageLayerIdByName(const std::string &image_layer);
extern std::map<std::string, CUnitType *> UnitTypeMap;
//Wyrmgus end

//@}

#endif // !__UNITTYPE_H__
#endif
1 change: 1 addition & 0 deletions src/sound/unitsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "sound_server.h"
#include "unit/unit.h"
#include "unit/unittype.h"
#include "unit/unit_type_variation.h"
#include "video.h"

/*----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/stratagus/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "spells.h"
#include "time/calendar.h"
#include "unit/unit.h"
#include "unit/unit_type_variation.h"
#include "upgrade/upgrade.h"
#include "upgrade/upgrade_modifier.h"

Expand Down
1 change: 1 addition & 0 deletions src/ui/botpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include "unit/unit_manager.h"
//Wyrmgus end
#include "unit/unittype.h"
#include "unit/unit_type_variation.h"
#include "upgrade/depend.h"
#include "upgrade/upgrade.h"
#include "video.h"
Expand Down
1 change: 1 addition & 0 deletions src/ui/mainscr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "ui/ui.h"
#include "unit/unit.h"
#include "unit/unittype.h"
#include "unit/unit_type_variation.h"
#include "unitsound.h"
//Wyrmgus start
#include "util.h"
Expand Down
1 change: 1 addition & 0 deletions src/unit/script_unittype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "ui/ui.h"
#include "unit/unit.h"
#include "unit/unit_manager.h"
#include "unit/unit_type_variation.h"
#include "unitsound.h"
//Wyrmgus start
#include "upgrade/upgrade.h"
Expand Down
1 change: 1 addition & 0 deletions src/unit/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#include "unit/unit_find.h"
#include "unit/unit_manager.h"
#include "unit/unittype.h"
#include "unit/unit_type_variation.h"
#include "unitsound.h"
#include "upgrade/depend.h" //for using dependency checks
#include "upgrade/upgrade.h"
Expand Down
1 change: 1 addition & 0 deletions src/unit/unit_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "unit/unit.h"
#include "unit/unit_find.h"
#include "unit/unittype.h"
#include "unit/unit_type_variation.h"
#include "unitsound.h"
#include "video.h"

Expand Down
68 changes: 68 additions & 0 deletions src/unit/unit_type_variation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
//
/**@name unit_type_variation.cpp - The unit type variation source file. */
//
// (c) Copyright 2014-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.
//

/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/

#include "stratagus.h"

#include "unit/unit_type_variation.h"

#include "video.h"

/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/

CUnitTypeVariation::~CUnitTypeVariation()
{
if (this->Sprite) {
CGraphic::Free(this->Sprite);
}
if (this->ShadowSprite) {
CGraphic::Free(this->ShadowSprite);
}
if (this->LightSprite) {
CGraphic::Free(this->LightSprite);
}
for (int i = 0; i < MaxImageLayers; ++i) {
if (this->LayerSprites[i]) {
CGraphic::Free(this->LayerSprites[i]);
}
}
for (int res = 0; res < MaxCosts; ++res) {
if (this->SpriteWhenLoaded[res]) {
CGraphic::Free(this->SpriteWhenLoaded[res]);
}
if (this->SpriteWhenEmpty[res]) {
CGraphic::Free(this->SpriteWhenEmpty[res]);
}
}
}
Loading

0 comments on commit e1a74d3

Please sign in to comment.