-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisasterHelper.h
199 lines (162 loc) · 6.73 KB
/
DisasterHelper.h
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
196
197
198
199
#pragma once
// Disaster Helper Version: 1.0
#include "OP2Helper/OP2Helper.h"
#include "Outpost2DLL/Outpost2DLL.h"
#include <climits>
#include <cmath>
#include <vector>
#include <array>
// DisasterHelper simplifies adding random disasters to a map. The default
// settings should be ideal for a basic Last One Standing Map. Many features are
// customizable such as ratio of occuring disasters, disaster duration, and disaster strength.
// USAGE: Pass the function CreateRandomDisaster to an Outpost 2 time trigger. You will have
// to wrap CreateRandomDisaster in an Export function since you cannot use the
// TYPEDEF Export on functions within C++ classes. Set the time interval on the
// trigger for the frequency you want disasters to appear. When a disaster is called
// for, it will not occur until about 10-15 marks later to allow time for disaster
// warnings/watches in game if they are researched by the player. Inidiviual functions
// exist to call for Vortex, Meteor, Storm, or Earthquake using the DisasterHelper's
// settings if desired over a random disaster.
// MAP LOCATIONS: Ensure all map coordinates passed into DisasterHelper are pre-corrected
// for the proper offset. East-West wrap map (x - 1, y - 1). Non wrap (x + 31, y - 1).
// WARNINGS: DisasterHelper can produce warning messages by using the Outpost 2 built in
// multiplayer chat pane. For these warnings to appear, the code must be compiled
// in debug mode. For final production code, you should compile in Release mode
// which will keep the warnings from occuring.
class DisasterHelper
{
public:
//Tile width and tile height of map.
//DisasterHelper uses the setting wrapsEastWest to set proper map coordinate offsets.
void SetMapProperties(int mapWidth, int mapHeight, bool wrapsEastWest);
void CreateRandomDisaster();
void CreateStorm();
//Medium and Large meteors are created outside SafeAreas if at least one SafeArea is set.
void CreateMeteor();
//Earthquakes are created outside of SafeAreas if at least one SafeArea is set.
void CreateEarthquake();
//Vortices are created inside VortexCorridors. If no corridors are set, no vortex will be created.
void CreateVortex();
//If percent values do not sum to 100, no changes will be made.
//Set percent values as a whole number (ie 10 = 10 percent).
//For including Vortexes, recommended starting percentages are: noDisasterPercent(15),
// meteorPercent(35), earthquakePercent(20), stormPercent(20), vortexPercent(10)
void SetDisasterPercents(int noDisasterPercent, int meteorPercent,
int earthquakePercent, int stormPercent, int vortexPercent);
//If percent values do not sum to 100, no changes will be made.
//Set percent values as a whole number (ie 10 = 10 percent).
void SetMeteorSizePercents(int smallMeteorPercent, int mediumMeteorPercent, int largeMeteorPercent);
//Min earthquake strength is 0.
void SetEarthquakeStrength(int minStrength, int maxStrength)
{
if (minStrength > maxStrength || minStrength < 0)
{
return;
}
this->minQuakeStrength = minStrength;
this->maxQuakeStrength = maxStrength;
}
//Duration is represented by number of marks
void SetVortexDuration(int minDuration, int maxDuration)
{
if (minDuration > maxDuration || minDuration < 0)
{
return;
}
this->minVortexDuration = minDuration;
this->maxVortexDuration = maxDuration;
}
//Duration is represented by number of marks
void SetStormDuration(int minDuration, int maxDuration)
{
if (minDuration > maxDuration || minDuration < 0)
{
return;
}
this->minStormDuration = minDuration;
this->maxStormDuration = maxDuration;
}
//Sets a timer value in marks where base safeZones expire, allowing more dangerous disasters to hit bases.
//To make SafeZones never expire, set timeInMarks to the const TimerNeverExpires.
//To disable SafeZones without clearing them from DisasterHelper, set timeInMarks <= 0
void SetSafeZoneExpirationTimer(int timeInMarks)
{
this->safeZoneTimer = timeInMarks;
}
void ClearSafeRects()
{
safeRects.clear();
}
//Add a MAP_RECT where no earthquakes or large meteors will be created.
//This is designed to protect starting locations from powerful disasters.
void AddSafeRect(const MAP_RECT& safeRect)
{
safeRects.push_back(safeRect);
}
//Add a c style array of MAP_RECTs where no earthquakes or large meteors will be created.
//This is designed to protect starting locations from powerful disasters.
void AddSafeRects(int arraySize, MAP_RECT safeRects[])
{
for (int i = 0; i < arraySize; i++)
{
this->safeRects.push_back(safeRects[i]);
}
}
template<typename MAP_RECT, size_t N>
void AddSafeRects(const std::array<MAP_RECT, N>& safeRects)
{
this->safeRects.insert(this->safeRects.end(), safeRects.begin(), safeRects.end());
}
void AddSafeRects(const std::vector<MAP_RECT>& safeRects)
{
this->safeRects.insert(this->safeRects.end(), safeRects.begin(), safeRects.end());
}
void ClearVortexCorridors()
{
vortexRects.clear();
}
//corridorWeight represents how often the corridor is chosen randomly.
//IE: adding one corridor with a weight of 1 and one corridor with a weight of 2
// means the second vortex corridor will be used twice as often.
//Vortex corridors will produce vortices within Safe Areas if they overlap on the map.
//Small vortex corridors will force the vortex to not travel very far, but stay mostly stationary.
//Min vortex corridor width is 5 and height is 5.
void AddVortexCorridor(const MAP_RECT& mapRect, int corridorWeight);
// Attempts to return a LOCATION that exists outside any declared safe areas.
// If unable to find a valid LOCATION, reports a warning in debug mode and returns (0,0).
LOCATION GetRandLocOutsideSafeAreas();
bool MapPropertiesSet()
{
return mapWidth != 0;
}
static const int TimerNeverExpires = INT_MAX;
static const int TimerDefaultValue = 250; //In Marks
private:
int xOffset = 31;
int yOffset = -1;
int mapWidth;
int mapHeight;
int noDisasterPercent = 15;
int meteorPercent = 40;
int earthquakePercent = 22;
int stormPercent = 23;
int vortexPercent = 0;
int smallMeteorPercent = 60;
int mediumMeteorPercent = 25;
int largeMeteorPercent = 15;
int minQuakeStrength = 0;
int maxQuakeStrength = 3;
int minVortexDuration = 5;
int maxVortexDuration = 20;
int minStormDuration = 10;
int maxStormDuration = 55;
int safeZoneTimer = TimerDefaultValue;
std::vector<MAP_RECT> safeRects;
std::vector<MAP_RECT> vortexRects;
LOCATION GetRandMapLoc();
double DistanceBetweenPoints(LOCATION loc1, LOCATION loc2);
bool IsLocInSafeArea(LOCATION& loc);
LOCATION FindVortexEndLoc(const MAP_RECT& vortexCorridor,
const LOCATION& startLoc, double minPercentHypotenuseTravel);
void SendDebugMessage(const char* message);
};