2010-03-25 13:15:10 +01:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2011-12-14 08:40:48 +01:00
|
|
|
// Copyright (C) 2001-2008 Martiño Figueroa
|
2010-03-25 13:15:10 +01:00
|
|
|
//
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#ifndef _GLEST_GAME_UNITTYPE_H_
|
|
|
|
#define _GLEST_GAME_UNITTYPE_H_
|
|
|
|
|
2012-04-20 03:04:05 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <winsock.h>
|
|
|
|
#endif
|
|
|
|
|
2010-03-25 13:15:10 +01:00
|
|
|
#include "element_type.h"
|
|
|
|
#include "command_type.h"
|
|
|
|
#include "damage_multiplier.h"
|
|
|
|
#include "sound_container.h"
|
|
|
|
#include "checksum.h"
|
|
|
|
#include "game_constants.h"
|
2011-01-15 00:51:15 +01:00
|
|
|
#include "platform_common.h"
|
2010-09-07 07:25:40 +02:00
|
|
|
#include "leak_dumper.h"
|
2010-03-25 13:15:10 +01:00
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
using Shared::Sound::StaticSound;
|
|
|
|
using Shared::Util::Checksum;
|
2011-01-15 00:51:15 +01:00
|
|
|
using Shared::PlatformCommon::ValueCheckerVault;
|
2010-03-25 13:15:10 +01:00
|
|
|
|
|
|
|
class UpgradeType;
|
|
|
|
class UnitType;
|
|
|
|
class UnitParticleSystemType;
|
|
|
|
class ResourceType;
|
|
|
|
class TechTree;
|
|
|
|
class FactionType;
|
2010-10-02 03:11:59 +02:00
|
|
|
class Faction;
|
2010-03-25 13:15:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
// ===============================
|
|
|
|
// class Level
|
|
|
|
// ===============================
|
|
|
|
|
2011-01-15 00:51:15 +01:00
|
|
|
class Level {
|
2010-03-25 13:15:10 +01:00
|
|
|
private:
|
|
|
|
string name;
|
|
|
|
int kills;
|
|
|
|
|
|
|
|
public:
|
2011-12-02 17:07:59 +01:00
|
|
|
Level() {
|
|
|
|
kills = 0;
|
|
|
|
}
|
2010-03-25 13:15:10 +01:00
|
|
|
void init(string name, int kills);
|
|
|
|
|
2013-01-16 22:16:59 +01:00
|
|
|
string getName(bool translatedValue=false) const;
|
2010-03-25 13:15:10 +01:00
|
|
|
int getKills() const {return kills;}
|
2012-03-10 04:27:25 +01:00
|
|
|
|
|
|
|
void saveGame(XmlNode *rootNode) const ;
|
2012-03-13 16:21:25 +01:00
|
|
|
static const Level * loadGame(const XmlNode *rootNode, const UnitType *ut);
|
2010-03-25 13:15:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// ===============================
|
|
|
|
// class UnitType
|
|
|
|
//
|
|
|
|
/// A unit or building type
|
|
|
|
// ===============================
|
|
|
|
|
2011-01-15 00:51:15 +01:00
|
|
|
enum UnitClass {
|
2010-03-25 13:15:10 +01:00
|
|
|
ucWarrior,
|
|
|
|
ucWorker,
|
|
|
|
ucBuilding
|
|
|
|
};
|
|
|
|
|
2011-07-01 23:47:54 +02:00
|
|
|
typedef vector<UnitParticleSystemType*> DamageParticleSystemTypes;
|
2010-03-25 13:15:10 +01:00
|
|
|
|
2012-05-03 22:25:35 +02:00
|
|
|
enum UnitCountsInVictoryConditions {
|
|
|
|
ucvcNotSet,
|
|
|
|
ucvcTrue,
|
|
|
|
ucvcFalse
|
|
|
|
};
|
|
|
|
|
2011-01-15 00:51:15 +01:00
|
|
|
class UnitType: public ProducibleType, public ValueCheckerVault {
|
2010-03-25 13:15:10 +01:00
|
|
|
public:
|
2011-01-15 00:51:15 +01:00
|
|
|
enum Property {
|
2010-03-25 13:15:10 +01:00
|
|
|
pBurnable,
|
|
|
|
pRotatedClimb,
|
|
|
|
|
|
|
|
pCount
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *propertyNames[];
|
|
|
|
DamageParticleSystemTypes damageParticleSystemTypes;
|
|
|
|
private:
|
|
|
|
typedef vector<SkillType*> SkillTypes;
|
|
|
|
typedef vector<CommandType*> CommandTypes;
|
|
|
|
typedef vector<Resource> StoredResources;
|
|
|
|
typedef vector<Level> Levels;
|
|
|
|
|
|
|
|
private:
|
|
|
|
//basic
|
|
|
|
int id;
|
|
|
|
int maxHp;
|
|
|
|
int hpRegeneration;
|
|
|
|
int maxEp;
|
|
|
|
int epRegeneration;
|
2010-08-22 23:09:35 +02:00
|
|
|
int maxUnitCount;
|
2011-01-09 05:49:21 +01:00
|
|
|
|
|
|
|
|
2012-11-12 05:55:33 +01:00
|
|
|
// remove fields, multiple fields are not supported by the engine
|
2010-07-11 20:31:02 +02:00
|
|
|
bool fields[fieldCount]; //fields: land, sea or air
|
|
|
|
Field field;
|
|
|
|
|
2010-03-25 13:15:10 +01:00
|
|
|
bool properties[pCount]; //properties
|
|
|
|
int armor; //armor
|
|
|
|
const ArmorType *armorType;
|
|
|
|
bool light;
|
|
|
|
Vec3f lightColor;
|
|
|
|
bool multiSelect;
|
|
|
|
int sight;
|
|
|
|
int size; //size in cells
|
|
|
|
int height;
|
2013-10-02 22:22:10 +02:00
|
|
|
float rotatedBuildPos;
|
2010-03-27 04:09:11 +01:00
|
|
|
bool rotationAllowed;
|
2010-03-25 13:15:10 +01:00
|
|
|
|
|
|
|
//cellmap
|
|
|
|
bool *cellMap;
|
2010-10-30 10:54:00 +02:00
|
|
|
bool allowEmptyCellMap;
|
2010-03-25 13:15:10 +01:00
|
|
|
|
|
|
|
//sounds
|
|
|
|
SoundContainer selectionSounds;
|
|
|
|
SoundContainer commandSounds;
|
|
|
|
|
|
|
|
//info
|
|
|
|
SkillTypes skillTypes;
|
|
|
|
CommandTypes commandTypes;
|
|
|
|
StoredResources storedResources;
|
|
|
|
Levels levels;
|
|
|
|
|
|
|
|
//meeting point
|
|
|
|
bool meetingPoint;
|
|
|
|
Texture2D *meetingPointImage;
|
|
|
|
|
2012-03-31 01:38:05 +02:00
|
|
|
// for dummy units and units used as shots and so on ....
|
|
|
|
bool countUnitDeathInStats;
|
|
|
|
bool countUnitProductionInStats;
|
|
|
|
bool countUnitKillInStats;
|
2012-03-31 12:14:42 +02:00
|
|
|
bool countKillForUnitUpgrade;
|
2012-03-31 01:38:05 +02:00
|
|
|
|
2010-03-25 13:15:10 +01:00
|
|
|
//OPTIMIZATION: store first command type and skill type of each class
|
|
|
|
const CommandType *firstCommandTypeOfClass[ccCount];
|
|
|
|
const SkillType *firstSkillTypeOfClass[scCount];
|
|
|
|
|
2012-05-03 22:25:35 +02:00
|
|
|
UnitCountsInVictoryConditions countInVictoryConditions;
|
|
|
|
|
2013-02-12 09:44:12 +01:00
|
|
|
static auto_ptr<CommandType> ctHarvestEmergencyReturnCommandType;
|
|
|
|
|
2010-03-25 13:15:10 +01:00
|
|
|
public:
|
|
|
|
//creation and loading
|
|
|
|
UnitType();
|
|
|
|
virtual ~UnitType();
|
|
|
|
void preLoad(const string &dir);
|
2012-01-17 02:34:50 +01:00
|
|
|
void loaddd(int id, const string &dir, const TechTree *techTree,const string &techTreePath,
|
2011-03-15 16:30:28 +01:00
|
|
|
const FactionType *factionType, Checksum* checksum,
|
2011-05-06 09:47:31 +02:00
|
|
|
Checksum* techtreeChecksum, std::map<string,vector<pair<string, string> > > &loadedFileList);
|
2010-03-25 13:15:10 +01:00
|
|
|
|
2012-05-02 23:00:57 +02:00
|
|
|
virtual string getName(bool translatedValue=false) const;
|
|
|
|
|
2012-05-03 22:25:35 +02:00
|
|
|
UnitCountsInVictoryConditions getCountInVictoryConditions() const { return countInVictoryConditions; }
|
2010-03-25 13:15:10 +01:00
|
|
|
//get
|
2012-04-17 17:25:31 +02:00
|
|
|
inline int getId() const {return id;}
|
|
|
|
inline int getMaxHp() const {return maxHp;}
|
|
|
|
inline int getHpRegeneration() const {return hpRegeneration;}
|
|
|
|
inline int getMaxEp() const {return maxEp;}
|
|
|
|
inline int getEpRegeneration() const {return epRegeneration;}
|
|
|
|
inline int getMaxUnitCount() const {return maxUnitCount;}
|
|
|
|
inline bool getField(Field field) const {return fields[field];}
|
|
|
|
inline Field getField() const {return field;}
|
|
|
|
inline bool getProperty(Property property) const {return properties[property];}
|
|
|
|
inline int getArmor() const {return armor;}
|
|
|
|
inline const ArmorType *getArmorType() const {return armorType;}
|
|
|
|
inline const SkillType *getSkillType(int i) const {return skillTypes[i];}
|
2010-06-08 09:40:32 +02:00
|
|
|
const CommandType *getCommandType(int i) const;
|
2012-04-17 17:25:31 +02:00
|
|
|
inline const Level *getLevel(int i) const {return &levels[i];}
|
2012-03-13 16:21:25 +01:00
|
|
|
const Level *getLevel(string name) const;
|
2013-11-02 12:04:52 +01:00
|
|
|
inline int getSkillTypeCount() const {return (int)skillTypes.size();}
|
|
|
|
inline int getCommandTypeCount() const {return (int)commandTypes.size();}
|
|
|
|
inline int getLevelCount() const {return (int)levels.size();}
|
2012-04-17 17:25:31 +02:00
|
|
|
inline bool getLight() const {return light;}
|
|
|
|
inline bool getRotationAllowed() const {return rotationAllowed;}
|
|
|
|
inline Vec3f getLightColor() const {return lightColor;}
|
|
|
|
inline bool getMultiSelect() const {return multiSelect;}
|
|
|
|
inline int getSight() const {return sight;}
|
|
|
|
inline int getSize() const {return size;}
|
2010-03-25 13:15:10 +01:00
|
|
|
int getHeight() const {return height;}
|
2013-11-02 12:04:52 +01:00
|
|
|
int getStoredResourceCount() const {return (int)storedResources.size();}
|
2012-04-17 17:25:31 +02:00
|
|
|
inline const Resource *getStoredResource(int i) const {return &storedResources[i];}
|
2010-03-25 13:15:10 +01:00
|
|
|
bool getCellMapCell(int x, int y, CardinalDir facing) const;
|
2012-04-17 17:25:31 +02:00
|
|
|
inline bool getMeetingPoint() const {return meetingPoint;}
|
|
|
|
inline bool getCountUnitDeathInStats() const {return countUnitDeathInStats;}
|
|
|
|
inline bool getCountUnitProductionInStats() const {return countUnitProductionInStats;}
|
|
|
|
inline bool getCountUnitKillInStats() const {return countUnitKillInStats;}
|
|
|
|
inline bool getCountKillForUnitUpgrade() const {return countKillForUnitUpgrade;}
|
|
|
|
inline bool isMobile() const {return (firstSkillTypeOfClass[scMove] != NULL);}
|
|
|
|
inline Texture2D *getMeetingPointImage() const {return meetingPointImage;}
|
|
|
|
inline StaticSound *getSelectionSound() const {return selectionSounds.getRandSound();}
|
|
|
|
inline StaticSound *getCommandSound() const {return commandSounds.getRandSound();}
|
|
|
|
|
|
|
|
inline const SoundContainer & getSelectionSounds() const { return selectionSounds; }
|
|
|
|
inline const SoundContainer & getCommandSounds() const { return commandSounds; }
|
2011-04-09 05:14:05 +02:00
|
|
|
|
2010-03-25 13:15:10 +01:00
|
|
|
int getStore(const ResourceType *rt) const;
|
|
|
|
const SkillType *getSkillType(const string &skillName, SkillClass skillClass) const;
|
|
|
|
const SkillType *getFirstStOfClass(SkillClass skillClass) const;
|
|
|
|
const CommandType *getFirstCtOfClass(CommandClass commandClass) const;
|
2010-10-02 03:11:59 +02:00
|
|
|
const HarvestCommandType *getFirstHarvestCommand(const ResourceType *resourceType,const Faction *faction) const;
|
2013-02-12 09:44:12 +01:00
|
|
|
const HarvestEmergencyReturnCommandType *getFirstHarvestEmergencyReturnCommand() const;
|
2010-03-25 13:15:10 +01:00
|
|
|
const AttackCommandType *getFirstAttackCommand(Field field) const;
|
2011-03-28 23:04:47 +02:00
|
|
|
const AttackStoppedCommandType *getFirstAttackStoppedCommand(Field field) const;
|
2010-03-25 13:15:10 +01:00
|
|
|
const RepairCommandType *getFirstRepairCommand(const UnitType *repaired) const;
|
|
|
|
|
|
|
|
//get totals
|
|
|
|
int getTotalMaxHp(const TotalUpgrade *totalUpgrade) const;
|
2011-07-22 09:05:47 +02:00
|
|
|
int getTotalMaxHpRegeneration(const TotalUpgrade *totalUpgrade) const;
|
2010-03-25 13:15:10 +01:00
|
|
|
int getTotalMaxEp(const TotalUpgrade *totalUpgrade) const;
|
2011-07-22 09:05:47 +02:00
|
|
|
int getTotalMaxEpRegeneration(const TotalUpgrade *totalUpgrade) const;
|
2010-03-25 13:15:10 +01:00
|
|
|
int getTotalArmor(const TotalUpgrade *totalUpgrade) const;
|
|
|
|
int getTotalSight(const TotalUpgrade *totalUpgrade) const;
|
|
|
|
|
|
|
|
//has
|
|
|
|
bool hasCommandType(const CommandType *commandType) const;
|
2012-04-21 05:42:25 +02:00
|
|
|
inline bool hasCommandClass(CommandClass commandClass) const {
|
|
|
|
return firstCommandTypeOfClass[commandClass]!=NULL;
|
|
|
|
}
|
2010-03-25 13:15:10 +01:00
|
|
|
bool hasSkillType(const SkillType *skillType) const;
|
|
|
|
bool hasSkillClass(SkillClass skillClass) const;
|
2012-04-17 17:25:31 +02:00
|
|
|
inline bool hasCellMap() const {return cellMap!=NULL;}
|
|
|
|
inline bool getAllowEmptyCellMap() const {return allowEmptyCellMap;}
|
2010-10-30 10:54:00 +02:00
|
|
|
bool hasEmptyCellMap() const;
|
2011-05-01 07:36:04 +02:00
|
|
|
Vec2i getFirstOccupiedCellInCellMap(Vec2i currentPos) const;
|
2010-03-25 13:15:10 +01:00
|
|
|
|
|
|
|
//is
|
|
|
|
bool isOfClass(UnitClass uc) const;
|
|
|
|
|
|
|
|
//find
|
|
|
|
const CommandType* findCommandTypeById(int id) const;
|
2010-04-20 04:19:37 +02:00
|
|
|
string getCommandTypeListDesc() const;
|
2010-03-25 13:15:10 +01:00
|
|
|
|
2013-10-02 22:22:10 +02:00
|
|
|
inline float getRotatedBuildPos() { return rotatedBuildPos; }
|
|
|
|
inline void setRotatedBuildPos(float value) { rotatedBuildPos = value; }
|
2010-03-25 13:15:10 +01:00
|
|
|
|
2010-08-22 23:09:35 +02:00
|
|
|
//other
|
2013-06-13 10:55:48 +02:00
|
|
|
virtual string getReqDesc(bool translatedValue) const;
|
2011-01-09 05:49:21 +01:00
|
|
|
|
2010-05-18 05:53:57 +02:00
|
|
|
std::string toString() const;
|
|
|
|
|
2010-03-25 13:15:10 +01:00
|
|
|
private:
|
|
|
|
void computeFirstStOfClass();
|
|
|
|
void computeFirstCtOfClass();
|
|
|
|
};
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|