-
Notifications
You must be signed in to change notification settings - Fork 279
/
map.h
315 lines (182 loc) · 8.85 KB
/
map.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#ifndef MAP_H_INCLUDED
#define MAP_H_INCLUDED
#include "minorGems/system/Time.h"
#include "../gameSource/GridPos.h"
#include "../gameSource/transitionBank.h"
#include "minorGems/game/doublePair.h"
typedef struct ChangePosition {
int x, y;
// true if update should be sent to everyone regardless
// of distance (like position of a new player in the world,
// or the removal of a player).
char global;
int responsiblePlayerID;
// for movement changes
int oldX, oldY;
float speed;
} ChangePosition;
#include "minorGems/util/SimpleVector.h"
// returns true on success
char initMap();
void freeMap( char inSkipCleanup = false );
// loads seed from file, or generates a new one and saves it to file
void reseedMap( char inForceFresh );
// can only be called before initMap or after freeMap
// deletes the underlying .db files for the map
void wipeMapFiles();
// make Eve placement radius bigger
void doubleEveRadius();
// return Eve placement radius to starting value
void resetEveRadius();
// gets new Eve position on outskirts of civilization
// if inAllowRespawn, this player's last Eve old-age-death will be
// considered.
void getEvePosition( const char *inEmail, int inID, int *outX, int *outY,
SimpleVector<GridPos> *inOtherPeoplePos,
char inAllowRespawn = true );
// save recent placements on Eve's death so that this player can spawn
// near them if they are ever Eve again
void mapEveDeath( const char *inEmail, double inAge, GridPos inDeathMapPos );
// returns properly formatted chunk message for chunk in rectangle shape
// with bottom-left corner at x,y
// coordinates in message will be relative to inRelativeToPos
// note that inStartX,Y are absolute world coordinates
unsigned char *getChunkMessage( int inStartX, int inStartY,
int inWidth, int inHeight,
GridPos inRelativeToPos,
int *outMessageLength );
// sets the player responsible for subsequent map changes
// meant to track who set down an object
// should be set to -1 (default) except for object set-down
void setResponsiblePlayer( int inPlayerID );
int getMapObject( int inX, int inY );
char isMapSpotBlocking( int inX, int inY );
// is the object returned by getMapObject still in motion with
// destination inX, inY
char isMapObjectInTransit( int inX, int inY );
void setMapObject( int inX, int inY, int inID );
void setEtaDecay( int inX, int inY, timeSec_t inAbsoluteTimeInSeconds,
TransRecord *inApplicableTrans = NULL );
timeSec_t getEtaDecay( int inX, int inY );
// for all these calls, inSubCont indexes the main container (when 0)
// or sub-containers (when > 0).
// So, if inSubCont=3 and inSlot=2, we get information about the 2nd
// slot in the 3rd sub-container (the 3rd slot in the main container)
// for container slots
void setSlotEtaDecay( int inX, int inY, int inSlot,
timeSec_t inAbsoluteTimeInSeconds, int inSubCont = 0 );
timeSec_t getSlotEtaDecay( int inX, int inY, int inSlot, int inSubCont = 0 );
// adds to top of stack
// negative elements indicate sub-containers
void addContained( int inX, int inY, int inContainedID,
timeSec_t inEtaDecay, int inSubCont = 0 );
int getNumContained( int inX, int inY, int inSubCont = 0 );
// destroyed by caller, returns NULL if empty
// negative elements indicate sub-containers
int *getContained( int inX, int inY, int *outNumContained, int inSubCont = 0 );
timeSec_t *getContainedEtaDecay( int inX, int inY, int *outNumContained,
int inSubCont = 0 );
// gets contained item from specified slot, or from top of stack
// if inSlot is -1
// negative elements indicate sub-containers
int getContained( int inX, int inY, int inSlot, int inSubCont = 0 );
// setting negative elements indicates sub containers
void setContained( int inX, int inY, int inNumContained, int *inContained,
int inSubCont = 0 );
void setContainedEtaDecay( int inX, int inY, int inNumContained,
timeSec_t *inContainedEtaDecay,
int inSubCont = 0 );
// removes contained item from specified slot, or remove from top of stack
// if inSlot is -1
// if inSubCont = 0, then sub-container in that slot is cleared by this call
int removeContained( int inX, int inY, int inSlot, timeSec_t *outEtaDecay,
int inSubCont = 0 );
// if inSubCont is 0, container and all sub-containers are cleared
// otherwise, clears only a specific sub-container
void clearAllContained( int inX, int inY, int inSubCont = 0 );
// if inNumNewSlots less than number contained, the excess are discarded
void shrinkContainer( int inX, int inY, int inNumNewSlots, int inSubCont = 0 );
// unlike normal objects, there is no live tracking of floors and when
// they will decay in stepMap
// Decay of floors only applied on next call to getMapFloor
// Thus, short-term floor decay isn't supported (e.g., burning floor that
// finishes burning while player still has it on the screen).
int getMapFloor( int inX, int inY );
void setMapFloor( int inX, int inY, int inID );
void setFloorEtaDecay( int inX, int inY, timeSec_t inAbsoluteTimeInSeconds );
timeSec_t getFloorEtaDecay( int inX, int inY );
typedef struct MapChangeRecord {
char *formatString;
int absoluteX, absoluteY;
char oldCoordsUsed;
int absoluteOldX, absoluteOldY;
} MapChangeRecord;
// formatString in returned record destroyed by caller
MapChangeRecord getMapChangeRecord( ChangePosition inPos );
// line for a map change message
char *getMapChangeLineString( ChangePosition inPos );
char *getMapChangeLineString( MapChangeRecord *inRecord,
int inRelativeToX, int inRelativeToY );
// returns number of seconds from now until when next decay is supposed
// to happen
// returns -1 if no decay pending
int getNextDecayDelta();
// marks region as looked at, so that live decay tracking continues
// there
void lookAtRegion( int inXStart, int inYStart, int inXEnd, int inYEnd );
// any change lines resulting from step are appended to inMapChanges
// any change positions are added to end of inChangePosList
void stepMap( SimpleVector<MapChangeRecord> *inMapChanges,
SimpleVector<ChangePosition> *inChangePosList );
void restretchDecays( int inNumDecays, timeSec_t *inDecayEtas,
int inOldContainerID, int inNewContainerID );
void restretchMapContainedDecays( int inX, int inY,
int inOldContainerID, int inNewContainerID,
int inSubCont = 0 );
int getMapBiome( int inX, int inY );
typedef struct {
unsigned int uniqueLoadID;
char *mapFileName;
char fileOpened;
FILE *file;
int x, y;
double startTime;
int stepCount;
} TutorialLoadProgress;
// returns true on success
// example:
// loadTutorial( newPlayer.tutorialLoad, "tutorialA.txt", 10000, 10000 )
char loadTutorialStart( TutorialLoadProgress *inTutorialLoad,
const char *inMapFileName, int inX, int inY );
// returns true if more steps are needed
// false if done
char loadTutorialStep( TutorialLoadProgress *inTutorialLoad,
double inTimeLimitSec );
#define MAP_METADATA_LENGTH 128
// inBuffer must be at least MAP_METADATA_LENGTH bytes
// returns true if metadata found
char getMetadata( int inMapID, unsigned char *inBuffer );
// returns full map ID with embedded metadata ID for new metadata record
int addMetadata( int inObjectID, unsigned char *inBuffer );
// gets speech pipe indices for IN pipes at or adjacent to inX,inY
// vector passed in through outIndicies will be filled with indices
void getSpeechPipesIn( int inX, int inY, SimpleVector<int> *outIndicies );
// returned vector NOT destroyed or modified by caller
SimpleVector<GridPos> *getSpeechPipesOut( int inIndex );
// for performance reasons, when the true decayed version of the object
// doesn't matter, this skips some expensive steps
int getMapObjectRaw( int inX, int inY );
// next landing strip in line, in round-the-world circuit across all
// landing positions
// radius limit limits flights from inside that square radius
// from leaving (though flights from outside are unrestriced)
GridPos getNextFlightLandingPos( int inCurrentX, int inCurrentY,
doublePair inDir,
int inRadiusLimit = -1 );
// get and set player ID for grave on map
// returns 0 if not found
int getGravePlayerID( int inX, int inY );
void setGravePlayerID( int inX, int inY, int inPlayerID );
// culling regions of map that haven't been seen in a long time
void stepMapLongTermCulling( int inNumCurrentPlayers );
#endif