File: GTerrainMap.h

package info (click to toggle)
spring 103.0%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,720 kB
  • ctags: 63,685
  • sloc: cpp: 368,283; ansic: 33,988; python: 12,417; java: 12,203; awk: 5,879; sh: 1,846; xml: 655; perl: 405; php: 211; objc: 194; makefile: 77; sed: 2
file content (195 lines) | stat: -rw-r--r-- 6,625 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// _____________________________________________________
//
// RAI - Skirmish AI for Spring
// Author: Reth / Michael Vadovszki
// _____________________________________________________

// NOTES:
// "position blocks" refers to the in-game units of meaturement
// A Map Preivew Block is 512x512 position blocks
// GetMapWidth(),GetMapHeight(),GetHeightMap() uses 8x8 position blocks
// GetMetalMap(),GetSlopeMap() uses 16x16 position blocks

#ifndef RAI_GLOBAL_TERRAIN_MAP_H
#define RAI_GLOBAL_TERRAIN_MAP_H

#include "LegacyCpp/IAICallback.h"
#include "LegacyCpp/UnitDef.h"
#include "LogFile.h"
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <string.h>
using namespace std;

//#include "GPathfinder.h"

struct TerrainMapArea;
struct TerrainMapAreaSector;
struct TerrainMapMobileType;
struct TerrainMapImmobileType;
struct TerrainMapSector;

struct TerrainMapAreaSector
{
	TerrainMapAreaSector()
	{
		S=NULL;
		area=NULL;
		areaClosest=NULL;
	};
	// NOTE: some of these values are loaded as they become needed, use GlobalTerrainMap functions
	TerrainMapSector *S;	// always valid
	TerrainMapArea* area;		// The TerrainMapArea this sector belongs to, otherwise = 0 until
	TerrainMapArea* areaClosest;// uninitialized, = the TerrainMapArea closest to this sector
	// Use this to find the closest sector useable by a unit with a different MoveType, the 0 pointer may be valid as a key index
	map<TerrainMapMobileType*,TerrainMapAreaSector*> sectorAlternativeM; // uninitialized
	map<TerrainMapImmobileType*,TerrainMapSector*> sectorAlternativeI; // uninitialized
};

struct TerrainMapArea
{
	TerrainMapArea(int areaIUSize, TerrainMapMobileType* TMMobileType)
	{
		index=areaIUSize;
		mobileType = TMMobileType;
		percentOfMap=0.0;
		areaUsable=0;
	};
	bool areaUsable; // Should units of this type be used in this area
	int index;
	TerrainMapMobileType* mobileType;
	map<int,TerrainMapAreaSector*> sector;			// key = sector index, a list of all sectors belonging to it
	map<int,TerrainMapAreaSector*> sectorClosest;	// key = sector indexes not in "sector", indicates the sector belonging to this map-area with the closest distance
												// NOTE: use GlobalTerrainMap->GetClosestSector: these values are not initialized but are instead loaded as they become needed
	float percentOfMap; // 0-100
};
#define MAP_AREA_LIST_SIZE 50
struct TerrainMapMobileType
{
	TerrainMapMobileType()
	{
		typeUsable = false;
		sector = 0;
		areaSize = 0;
		areaLargest = 0;
		udSize = 0;
		MD = NULL;
		canFloat = 0;
		canHover = 0;
		minElevation = 0.0;
		maxElevation = 0.0;
		maxSlope = 0.0;
		memset(area,0,MAP_AREA_LIST_SIZE);
		
	};
	~TerrainMapMobileType()
	{
		delete [] sector;
		for(int i=0; i<areaSize; i++)
			delete area[i];
	};
	bool typeUsable; // Should units of this type be used on this map
	TerrainMapAreaSector *sector;	// Each MoveType has it's own sector list, GlobalTerrainMap->GetSectorIndex() gives an index
	TerrainMapArea *area[MAP_AREA_LIST_SIZE];	// Each MoveType has it's own MapArea list
	TerrainMapArea *areaLargest;// Largest area usable by this type, otherwise = 0
	int areaSize;

	float maxSlope;		// = MoveData*->maxSlope
	float maxElevation; // = -ud->minWaterDepth
	float minElevation; // = -MoveData*->depth
	bool canHover;
	bool canFloat;
	MoveData* MD;
	int udSize;
//	GlobalPathfinder *PF; // unused
};

struct TerrainMapSector
{
	TerrainMapSector()
	{
		percentLand = 0.0;
		maxSlope = 0.0;
		maxElevation = 0.0;
		minElevation = 0.0;
		isWater = 0;
	};

	bool isWater;		// (Water = true) (Land = false)
	float3 position;	// center of the sector, same as unit positions

	// only used during initialization
	float percentLand; // 0-100
	float minElevation; // 0 or less for water
	float maxElevation;
	float maxSlope;		// 0 or higher
};

struct TerrainMapImmobileType
{
	TerrainMapImmobileType()
	{
		udSize = 0;
		canFloat = 0;
		canHover = 0;
		minElevation = 0.0;
		maxElevation = 0.0;
		typeUsable = 0;
		
	};

	bool typeUsable; // Should units of this type be used on this map
	map<int,TerrainMapSector*> sector;			// a list of sectors useable by these units
	map<int,TerrainMapSector*> sectorClosest;	// key = sector indexes not in "sector", indicates the closest sector in "sector"
	float minElevation;
	float maxElevation;
	bool canHover;
	bool canFloat;
	int udSize;
};

class GlobalTerrainMap
{
public:
	GlobalTerrainMap(IAICallback* cb, cLogFile* logfile);
	~GlobalTerrainMap();

	bool CanMoveToPos(TerrainMapArea *area, const float3& destination);
	TerrainMapAreaSector* GetSectorList(TerrainMapArea* sourceArea=0);
	TerrainMapAreaSector* GetClosestSector(TerrainMapArea* sourceArea, const int& destinationSIndex);
	TerrainMapSector* GetClosestSector(TerrainMapImmobileType* sourceIT, const int& destinationSIndex);
	TerrainMapAreaSector* GetAlternativeSector(TerrainMapArea* sourceArea, const int& sourceSIndex, TerrainMapMobileType* destinationMT);
	TerrainMapSector* GetAlternativeSector(TerrainMapArea* destinationArea, const int& sourceSIndex, TerrainMapImmobileType* destinationIT); // can return 0
	int GetSectorIndex(const float3& position); // use IsSectorValid() to insure the index is valid
	bool IsSectorValid(const int& sIndex);

	list<TerrainMapMobileType> mobileType;			// Used for mobile units, not all movedatas are used
	map<int,TerrainMapMobileType*> udMobileType;	// key = ud->id, Used to find a TerrainMapMobileType for a unit
	list<TerrainMapImmobileType> immobileType;		// Used for immobile units
	map<int,TerrainMapImmobileType*> udImmobileType;// key = ud->id, Used to find a TerrainMapImmobileType for a unit
	TerrainMapAreaSector *sectorAirType;	// used for flying units, GetSectorIndex gives an index
	TerrainMapSector *sector;				// global sector data, GetSectorIndex gives an index
	TerrainMapImmobileType *landSectorType;	// 0 to the sky
	TerrainMapImmobileType *waterSectorType;// minElevation to 0

	bool waterIsHarmful;	// Units are damaged by it (Lava/Acid map)
	bool waterIsAVoid;		// (Space map)
	float minElevation;		// 0 or less (used by cRAIUnitDefHandler, builder start selecter)
	float percentLand;		// 0 to 100 (used by cRAIUnitDefHandler)

	int sectorXSize;
	int sectorZSize;
	int convertStoP; // Sector to Position: times this value for convertion, divide for the reverse

private:
	int GetFileValue(int &fileSize, char *&file, string entry);
	typedef pair<int,TerrainMapAreaSector*> iasPair;
	typedef pair<int,TerrainMapSector*> isdPair;
	typedef pair<TerrainMapMobileType*,TerrainMapAreaSector*> msPair;
	typedef pair<TerrainMapImmobileType*,TerrainMapSector*> isPair;
//	cLogFile *l; // Debugging only
};

#endif