File: faction_type.h

package info (click to toggle)
megaglest 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 12,904 kB
  • ctags: 18,215
  • sloc: cpp: 144,232; ansic: 11,860; sh: 2,949; perl: 1,899; python: 1,751; objc: 142; asm: 42; makefile: 24
file content (164 lines) | stat: -rw-r--r-- 6,184 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// ==============================================================
//	This file is part of Glest (www.glest.org)
//
//	Copyright (C) 2001-2008 MartiƱo Figueroa
//
//	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_FACTIONTYPE_H_
#define _GLEST_GAME_FACTIONTYPE_H_

#ifdef WIN32
    #include <winsock2.h>
    #include <winsock.h>
#endif

#include "unit_type.h"
#include "upgrade_type.h"
#include "sound.h"
#include <map>
#include <string>
#include "util.h"
#include "leak_dumper.h"

using Shared::Sound::StrSound;

namespace Glest{ namespace Game{
// =====================================================
// 	class FactionType
//
///	Each of the possible factions the user can select
// =====================================================

enum AIBehaviorUnitCategory {
	aibcWorkerUnits,
	aibcWarriorUnits,
	aibcResourceProducerUnits,
	aibcBuildingUnits
};

enum AIBehaviorStaticValueCategory {
	aibsvcMaxBuildRadius,
	aibsvcMinMinWarriors,
	aibsvcMinMinWarriorsExpandCpuEasy,
	aibsvcMinMinWarriorsExpandCpuMega,
	aibsvcMinMinWarriorsExpandCpuUltra,
	aibsvcMinMinWarriorsExpandCpuNormal,
	aibsvcMaxMinWarriors,
	aibsvcMaxExpansions,
	aibsvcVillageRadius,
	aibsvcMinStaticResourceCount,
	aibsvcScoutResourceRange,
	aibsvcMinWorkerAttackersHarvesting,
	aibsvcMinBuildSpacing
};
template <>
inline EnumParser<AIBehaviorStaticValueCategory>::EnumParser() {
	enumMap["MaxBuildRadius"]				= aibsvcMaxBuildRadius;
	enumMap["MinMinWarriors"]				= aibsvcMinMinWarriors;
	enumMap["MinMinWarriorsExpandCpuEasy"]	= aibsvcMinMinWarriorsExpandCpuEasy;
	enumMap["MinMinWarriorsExpandCpuMega"]	= aibsvcMinMinWarriorsExpandCpuMega;
	enumMap["MinMinWarriorsExpandCpuUltra"]	= aibsvcMinMinWarriorsExpandCpuUltra;
	enumMap["MinMinWarriorsExpandCpuNormal"]= aibsvcMinMinWarriorsExpandCpuNormal;
	enumMap["MaxMinWarriors"]				= aibsvcMaxMinWarriors;
	enumMap["MaxExpansions"]				= aibsvcMaxExpansions;
	enumMap["VillageRadius"]				= aibsvcVillageRadius;
	enumMap["MinStaticResourceCount"]		= aibsvcMinStaticResourceCount;
	enumMap["ScoutResourceRange"]			= aibsvcScoutResourceRange;
	enumMap["MinWorkerAttackersHarvesting"]	= aibsvcMinWorkerAttackersHarvesting;
	enumMap["MinBuildSpacing"]				= aibsvcMinBuildSpacing;
}

class FactionType {
public:
	typedef pair<const UnitType*, int> PairPUnitTypeInt;
	typedef vector<UnitType> UnitTypes;
	typedef vector<UpgradeType> UpgradeTypes;
	typedef vector<PairPUnitTypeInt> StartingUnits;
	typedef vector<Resource> Resources;

private:
    string name;
    UnitTypes unitTypes;
    UpgradeTypes upgradeTypes;
	StartingUnits startingUnits;
	Resources startingResources;
	StrSound *music;
	FactionPersonalityType personalityType;

	std::map<AIBehaviorUnitCategory, std::vector<PairPUnitTypeInt> > mapAIBehaviorUnitCategories;
	std::vector<const UpgradeType*> vctAIBehaviorUpgrades;
	std::map<AIBehaviorStaticValueCategory, int > mapAIBehaviorStaticOverrideValues;

	bool isLinked;

	float healthbarheight;
	float healthbarthickness;
	int healthbarVisible;
	bool healthbarBorderTextureEnabled;
	bool healthbarBackgroundTextureEnabled;
	bool healthbarLineBorder;
	Texture2D *healthbarTexture;
	Texture2D *healthbarBackgroundTexture;
	bool flatParticlePositions;

public:
	//init
	FactionType();
    void load(const string &factionName, const TechTree *techTree, Checksum* checksum,
    		Checksum *techtreeChecksum,
    		std::map<string,vector<pair<string, string> > > &loadedFileList,
    		bool validationMode=false);
	virtual ~FactionType();

	const std::vector<FactionType::PairPUnitTypeInt> getAIBehaviorUnits(AIBehaviorUnitCategory category) const;
	const std::vector<const UpgradeType*> getAIBehaviorUpgrades() const { return vctAIBehaviorUpgrades; };
	int getAIBehaviorStaticOverideValue(AIBehaviorStaticValueCategory type) const;

    //get
	bool getIsLinked() const { return isLinked; }
	int getUnitTypeCount() const						{return (int)unitTypes.size();}
	int getUpgradeTypeCount() const						{return (int)upgradeTypes.size();}
	virtual string getName(bool translatedValue=false) const;
	const UnitType *getUnitType(int i) const			{return &unitTypes[i];}
	const UpgradeType *getUpgradeType(int i) const		{return &upgradeTypes[i];}
	StrSound *getMusic() const							{return music;}
	int getStartingUnitCount() const					{return (int)startingUnits.size();}
	const UnitType *getStartingUnit(int i) const		{return startingUnits[i].first;}
	int getStartingUnitAmount(int i) const				{return startingUnits[i].second;}
	inline float getHealthbarHeight() const							{return healthbarheight;}
	inline float getHealthbarThickness() const							{return healthbarthickness;}
	inline int getHealthbarVisible() const							{return healthbarVisible;}
	inline bool isHealthbarBorderTextureEnabled() const	{return healthbarBorderTextureEnabled;}
	inline bool isHealthbarBackgroundTextureEnabled() const	{return healthbarBackgroundTextureEnabled;}
	inline bool isHealthbarLineBorder() const	{return healthbarLineBorder;}
	Texture2D *getHealthbarTexture() const				{return healthbarTexture;}
	Texture2D *getHealthbarBackgroundTexture() const				{return healthbarBackgroundTexture;}
	bool isFlatParticlePositions() const				{return flatParticlePositions;}


	const UnitType *getUnitType(const string &name) const;
	const UnitType *getUnitTypeById(int id) const;
	const UpgradeType *getUpgradeType(const string &name) const;
	int getStartingResourceAmount(const ResourceType *resourceType) const;

	FactionPersonalityType getPersonalityType() const { return personalityType;}
	void setPersonalityType(FactionPersonalityType value) { personalityType = value;}

	std::string toString() const;
	std::vector<std::string> validateFactionType();
	std::vector<std::string> validateFactionTypeResourceTypes(vector<ResourceType> &resourceTypes);
	std::vector<std::string> validateFactionTypeUpgradeTypes();

	void deletePixels();
	bool factionUsesResourceType(const ResourceType *rt) const;

};

}}//end namespace

#endif