1 | /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ |
2 | /* If you are missing that file, acquire a complete release at teeworlds.com. */ |
3 | #ifndef GAME_MAPITEMS_H |
4 | #define GAME_MAPITEMS_H |
5 | |
6 | #include <base/vmath.h> |
7 | |
8 | // layer types |
9 | enum |
10 | { |
11 | LAYERTYPE_INVALID = 0, |
12 | LAYERTYPE_GAME, // unused |
13 | LAYERTYPE_TILES, |
14 | LAYERTYPE_QUADS, |
15 | LAYERTYPE_FRONT, |
16 | LAYERTYPE_TELE, |
17 | LAYERTYPE_SPEEDUP, |
18 | LAYERTYPE_SWITCH, |
19 | LAYERTYPE_TUNE, |
20 | LAYERTYPE_SOUNDS_DEPRECATED, // deprecated! do not use this, this is just for compatibility reasons |
21 | LAYERTYPE_SOUNDS, |
22 | |
23 | MAPITEMTYPE_VERSION = 0, |
24 | MAPITEMTYPE_INFO, |
25 | MAPITEMTYPE_IMAGE, |
26 | MAPITEMTYPE_ENVELOPE, |
27 | MAPITEMTYPE_GROUP, |
28 | MAPITEMTYPE_LAYER, |
29 | MAPITEMTYPE_ENVPOINTS, |
30 | MAPITEMTYPE_SOUND, |
31 | // High map item type numbers suggest that they use the alternate |
32 | // format with UUIDs. See src/engine/shared/datafile.cpp for some of |
33 | // the implementation. |
34 | |
35 | CURVETYPE_STEP = 0, |
36 | CURVETYPE_LINEAR, |
37 | CURVETYPE_SLOW, |
38 | CURVETYPE_FAST, |
39 | CURVETYPE_SMOOTH, |
40 | CURVETYPE_BEZIER, |
41 | NUM_CURVETYPES, |
42 | |
43 | // game layer tiles |
44 | // TODO define which Layer uses which tiles (needed for mapeditor) |
45 | ENTITY_NULL = 0, |
46 | ENTITY_SPAWN, |
47 | ENTITY_SPAWN_RED, |
48 | ENTITY_SPAWN_BLUE, |
49 | ENTITY_FLAGSTAND_RED, |
50 | ENTITY_FLAGSTAND_BLUE, |
51 | ENTITY_ARMOR_1, |
52 | ENTITY_HEALTH_1, |
53 | ENTITY_WEAPON_SHOTGUN, |
54 | ENTITY_WEAPON_GRENADE, |
55 | ENTITY_POWERUP_NINJA, |
56 | ENTITY_WEAPON_LASER, |
57 | //DDRace - Main Lasers |
58 | ENTITY_LASER_FAST_CCW, |
59 | ENTITY_LASER_NORMAL_CCW, |
60 | ENTITY_LASER_SLOW_CCW, |
61 | ENTITY_LASER_STOP, |
62 | ENTITY_LASER_SLOW_CW, |
63 | ENTITY_LASER_NORMAL_CW, |
64 | ENTITY_LASER_FAST_CW, |
65 | //DDRace - Laser Modifiers |
66 | ENTITY_LASER_SHORT, |
67 | ENTITY_LASER_MEDIUM, |
68 | ENTITY_LASER_LONG, |
69 | ENTITY_LASER_C_SLOW, |
70 | ENTITY_LASER_C_NORMAL, |
71 | ENTITY_LASER_C_FAST, |
72 | ENTITY_LASER_O_SLOW, |
73 | ENTITY_LASER_O_NORMAL, |
74 | ENTITY_LASER_O_FAST, |
75 | //DDRace - Plasma |
76 | ENTITY_PLASMAE = 29, |
77 | ENTITY_PLASMAF, |
78 | ENTITY_PLASMA, |
79 | ENTITY_PLASMAU, |
80 | //DDRace - Shotgun |
81 | ENTITY_CRAZY_SHOTGUN_EX, |
82 | ENTITY_CRAZY_SHOTGUN, |
83 | //DDNet - Removing specific weapon |
84 | ENTITY_ARMOR_SHOTGUN, |
85 | ENTITY_ARMOR_GRENADE, |
86 | ENTITY_ARMOR_NINJA, |
87 | ENTITY_ARMOR_LASER, |
88 | //DDRace - Draggers |
89 | ENTITY_DRAGGER_WEAK = 42, |
90 | ENTITY_DRAGGER_NORMAL, |
91 | ENTITY_DRAGGER_STRONG, |
92 | //Draggers Behind Walls |
93 | ENTITY_DRAGGER_WEAK_NW, |
94 | ENTITY_DRAGGER_NORMAL_NW, |
95 | ENTITY_DRAGGER_STRONG_NW, |
96 | //Doors |
97 | ENTITY_DOOR = 49, |
98 | //End Of Lower Tiles |
99 | NUM_ENTITIES, |
100 | //Start From Top Left |
101 | //Tile Controllers |
102 | TILE_AIR = 0, |
103 | TILE_SOLID, |
104 | TILE_DEATH, |
105 | TILE_NOHOOK, |
106 | TILE_NOLASER, |
107 | TILE_THROUGH_CUT, |
108 | TILE_THROUGH, |
109 | TILE_JUMP, |
110 | TILE_FREEZE = 9, |
111 | TILE_TELEINEVIL, |
112 | TILE_UNFREEZE, |
113 | TILE_DFREEZE, |
114 | TILE_DUNFREEZE, |
115 | TILE_TELEINWEAPON, |
116 | TILE_TELEINHOOK, |
117 | TILE_WALLJUMP = 16, |
118 | TILE_EHOOK_ENABLE, |
119 | TILE_EHOOK_DISABLE, |
120 | TILE_HIT_ENABLE, |
121 | TILE_HIT_DISABLE, |
122 | TILE_SOLO_ENABLE, |
123 | TILE_SOLO_DISABLE, |
124 | //Switches |
125 | TILE_SWITCHTIMEDOPEN = 22, |
126 | TILE_SWITCHTIMEDCLOSE, |
127 | TILE_SWITCHOPEN, |
128 | TILE_SWITCHCLOSE, |
129 | TILE_TELEIN, |
130 | TILE_TELEOUT, |
131 | TILE_BOOST, |
132 | TILE_TELECHECK, |
133 | TILE_TELECHECKOUT, |
134 | TILE_TELECHECKIN, |
135 | TILE_REFILL_JUMPS = 32, |
136 | TILE_START, |
137 | TILE_FINISH, |
138 | TILE_TIME_CHECKPOINT_FIRST = 35, |
139 | TILE_TIME_CHECKPOINT_LAST = 59, |
140 | TILE_STOP = 60, |
141 | TILE_STOPS, |
142 | TILE_STOPA, |
143 | TILE_TELECHECKINEVIL, |
144 | TILE_CP, |
145 | TILE_CP_F, |
146 | TILE_THROUGH_ALL, |
147 | TILE_THROUGH_DIR, |
148 | TILE_TUNE, |
149 | TILE_OLDLASER = 71, |
150 | TILE_NPC, |
151 | TILE_EHOOK, |
152 | TILE_NOHIT, |
153 | TILE_NPH, |
154 | TILE_UNLOCK_TEAM, |
155 | TILE_ADD_TIME = 79, |
156 | TILE_NPC_DISABLE = 88, |
157 | TILE_UNLIMITED_JUMPS_DISABLE, |
158 | TILE_JETPACK_DISABLE, |
159 | TILE_NPH_DISABLE, |
160 | TILE_SUBTRACT_TIME = 95, |
161 | TILE_TELE_GUN_ENABLE = 96, |
162 | TILE_TELE_GUN_DISABLE = 97, |
163 | TILE_ALLOW_TELE_GUN = 98, |
164 | TILE_ALLOW_BLUE_TELE_GUN = 99, |
165 | TILE_NPC_ENABLE = 104, |
166 | TILE_UNLIMITED_JUMPS_ENABLE, |
167 | TILE_JETPACK_ENABLE, |
168 | TILE_NPH_ENABLE, |
169 | TILE_TELE_GRENADE_ENABLE = 112, |
170 | TILE_TELE_GRENADE_DISABLE = 113, |
171 | TILE_TELE_LASER_ENABLE = 128, |
172 | TILE_TELE_LASER_DISABLE = 129, |
173 | TILE_CREDITS_1 = 140, |
174 | TILE_CREDITS_2 = 141, |
175 | TILE_CREDITS_3 = 142, |
176 | TILE_CREDITS_4 = 143, |
177 | TILE_LFREEZE = 144, |
178 | TILE_LUNFREEZE = 145, |
179 | TILE_CREDITS_5 = 156, |
180 | TILE_CREDITS_6 = 157, |
181 | TILE_CREDITS_7 = 158, |
182 | TILE_CREDITS_8 = 159, |
183 | TILE_ENTITIES_OFF_1 = 190, |
184 | TILE_ENTITIES_OFF_2, |
185 | //End of higher tiles |
186 | //Layers |
187 | LAYER_GAME = 0, |
188 | LAYER_FRONT, |
189 | LAYER_TELE, |
190 | LAYER_SPEEDUP, |
191 | LAYER_SWITCH, |
192 | LAYER_TUNE, |
193 | NUM_LAYERS, |
194 | //Flags |
195 | TILEFLAG_XFLIP = 1, |
196 | TILEFLAG_YFLIP = 2, |
197 | TILEFLAG_OPAQUE = 4, |
198 | TILEFLAG_ROTATE = 8, |
199 | //Rotation |
200 | ROTATION_0 = 0, |
201 | ROTATION_90 = TILEFLAG_ROTATE, |
202 | ROTATION_180 = (TILEFLAG_XFLIP | TILEFLAG_YFLIP), |
203 | ROTATION_270 = (TILEFLAG_XFLIP | TILEFLAG_YFLIP | TILEFLAG_ROTATE), |
204 | |
205 | LAYERFLAG_DETAIL = 1, |
206 | TILESLAYERFLAG_GAME = 1, |
207 | TILESLAYERFLAG_TELE = 2, |
208 | TILESLAYERFLAG_SPEEDUP = 4, |
209 | TILESLAYERFLAG_FRONT = 8, |
210 | TILESLAYERFLAG_SWITCH = 16, |
211 | TILESLAYERFLAG_TUNE = 32, |
212 | |
213 | ENTITY_OFFSET = 255 - 16 * 4, |
214 | }; |
215 | |
216 | static constexpr size_t MAX_MAPIMAGES = 64; |
217 | static constexpr size_t MAX_MAPSOUNDS = 64; |
218 | |
219 | typedef ivec2 CPoint; // 22.10 fixed point |
220 | typedef ivec4 CColor; |
221 | |
222 | struct CQuad |
223 | { |
224 | CPoint m_aPoints[5]; |
225 | CColor m_aColors[4]; |
226 | CPoint m_aTexcoords[4]; |
227 | |
228 | int m_PosEnv; |
229 | int m_PosEnvOffset; |
230 | |
231 | int m_ColorEnv; |
232 | int m_ColorEnvOffset; |
233 | }; |
234 | |
235 | class CTile |
236 | { |
237 | public: |
238 | unsigned char m_Index; |
239 | unsigned char m_Flags; |
240 | unsigned char m_Skip; |
241 | unsigned char m_Reserved; |
242 | }; |
243 | |
244 | struct CMapItemInfo |
245 | { |
246 | int m_Version; |
247 | int m_Author; |
248 | int m_MapVersion; |
249 | int m_Credits; |
250 | int m_License; |
251 | }; |
252 | |
253 | struct CMapItemInfoSettings : CMapItemInfo |
254 | { |
255 | int m_Settings; |
256 | }; |
257 | |
258 | struct CMapItemImage_v1 |
259 | { |
260 | enum |
261 | { |
262 | CURRENT_VERSION = 1, |
263 | }; |
264 | |
265 | int m_Version; |
266 | int m_Width; |
267 | int m_Height; |
268 | int m_External; |
269 | int m_ImageName; |
270 | int m_ImageData; |
271 | }; |
272 | |
273 | struct CMapItemImage_v2 : public CMapItemImage_v1 |
274 | { |
275 | enum |
276 | { |
277 | CURRENT_VERSION = 2, |
278 | }; |
279 | |
280 | int m_MustBe1; |
281 | }; |
282 | |
283 | typedef CMapItemImage_v1 CMapItemImage; |
284 | |
285 | struct CMapItemGroup_v1 |
286 | { |
287 | int m_Version; |
288 | int m_OffsetX; |
289 | int m_OffsetY; |
290 | int m_ParallaxX; |
291 | int m_ParallaxY; |
292 | |
293 | int m_StartLayer; |
294 | int m_NumLayers; |
295 | }; |
296 | |
297 | struct CMapItemGroup : public CMapItemGroup_v1 |
298 | { |
299 | enum |
300 | { |
301 | CURRENT_VERSION = 3 |
302 | }; |
303 | |
304 | int m_UseClipping; |
305 | int m_ClipX; |
306 | int m_ClipY; |
307 | int m_ClipW; |
308 | int m_ClipH; |
309 | |
310 | int m_aName[3]; |
311 | }; |
312 | |
313 | struct CMapItemLayer |
314 | { |
315 | int m_Version; |
316 | int m_Type; |
317 | int m_Flags; |
318 | }; |
319 | |
320 | struct CMapItemLayerTilemap |
321 | { |
322 | enum |
323 | { |
324 | CURRENT_VERSION = 3, |
325 | TILE_SKIP_MIN_VERSION = 4, // supported for loading but not saving |
326 | }; |
327 | |
328 | CMapItemLayer m_Layer; |
329 | int m_Version; |
330 | |
331 | int m_Width; |
332 | int m_Height; |
333 | int m_Flags; |
334 | |
335 | CColor m_Color; |
336 | int m_ColorEnv; |
337 | int m_ColorEnvOffset; |
338 | |
339 | int m_Image; |
340 | int m_Data; |
341 | |
342 | int m_aName[3]; |
343 | |
344 | // DDRace |
345 | |
346 | int m_Tele; |
347 | int m_Speedup; |
348 | int m_Front; |
349 | int m_Switch; |
350 | int m_Tune; |
351 | }; |
352 | |
353 | struct CMapItemLayerQuads |
354 | { |
355 | CMapItemLayer m_Layer; |
356 | int m_Version; |
357 | |
358 | int m_NumQuads; |
359 | int m_Data; |
360 | int m_Image; |
361 | |
362 | int m_aName[3]; |
363 | }; |
364 | |
365 | struct CMapItemVersion |
366 | { |
367 | enum |
368 | { |
369 | CURRENT_VERSION = 1 |
370 | }; |
371 | |
372 | int m_Version; |
373 | }; |
374 | |
375 | // Represents basic information about envelope points. |
376 | // In upstream Teeworlds, this is only used if all CMapItemEnvelope are version 1 or 2. |
377 | struct CEnvPoint |
378 | { |
379 | enum |
380 | { |
381 | MAX_CHANNELS = 4, |
382 | }; |
383 | |
384 | int m_Time; // in ms |
385 | int m_Curvetype; // CURVETYPE_* constants, any unknown value behaves like CURVETYPE_LINEAR |
386 | int m_aValues[MAX_CHANNELS]; // 1-4 depending on envelope (22.10 fixed point) |
387 | |
388 | bool operator<(const CEnvPoint &Other) const { return m_Time < Other.m_Time; } |
389 | }; |
390 | |
391 | // Represents additional envelope point information for CURVETYPE_BEZIER. |
392 | // In DDNet, these are stored separately in an UUID-based map item. |
393 | // In upstream Teeworlds, CEnvPointBezier_upstream is used instead. |
394 | struct CEnvPointBezier |
395 | { |
396 | // DeltaX in ms and DeltaY as 22.10 fxp |
397 | int m_aInTangentDeltaX[CEnvPoint::MAX_CHANNELS]; |
398 | int m_aInTangentDeltaY[CEnvPoint::MAX_CHANNELS]; |
399 | int m_aOutTangentDeltaX[CEnvPoint::MAX_CHANNELS]; |
400 | int m_aOutTangentDeltaY[CEnvPoint::MAX_CHANNELS]; |
401 | }; |
402 | |
403 | // Written to maps on upstream Teeworlds for envelope points including bezier information instead of the basic |
404 | // CEnvPoint items, if at least one CMapItemEnvelope with version 3 or higher exists in the map. |
405 | struct CEnvPointBezier_upstream : public CEnvPoint |
406 | { |
407 | CEnvPointBezier m_Bezier; |
408 | }; |
409 | |
410 | // Used to represent all envelope point information at runtime in editor. |
411 | // (Can eventually be different than CEnvPointBezier_upstream) |
412 | struct CEnvPoint_runtime : public CEnvPoint |
413 | { |
414 | CEnvPointBezier m_Bezier; |
415 | }; |
416 | |
417 | struct CMapItemEnvelope_v1 |
418 | { |
419 | enum |
420 | { |
421 | CURRENT_VERSION = 1, |
422 | }; |
423 | |
424 | int m_Version; |
425 | int m_Channels; |
426 | int m_StartPoint; |
427 | int m_NumPoints; |
428 | int m_aName[8]; |
429 | }; |
430 | |
431 | struct CMapItemEnvelope_v2 : public CMapItemEnvelope_v1 |
432 | { |
433 | enum |
434 | { |
435 | CURRENT_VERSION = 2, |
436 | }; |
437 | |
438 | int m_Synchronized; |
439 | }; |
440 | |
441 | // Only written to maps in upstream Teeworlds. |
442 | // If at least one of these exists in a map, the envelope points |
443 | // are represented by CEnvPointBezier_upstream instead of CEnvPoint. |
444 | struct CMapItemEnvelope_v3 : public CMapItemEnvelope_v2 |
445 | { |
446 | enum |
447 | { |
448 | CURRENT_VERSION = 3, |
449 | }; |
450 | }; |
451 | |
452 | typedef CMapItemEnvelope_v2 CMapItemEnvelope; |
453 | |
454 | struct CSoundShape |
455 | { |
456 | enum |
457 | { |
458 | SHAPE_RECTANGLE = 0, |
459 | SHAPE_CIRCLE, |
460 | NUM_SHAPES, |
461 | }; |
462 | |
463 | struct CRectangle |
464 | { |
465 | int m_Width, m_Height; // fxp 22.10 |
466 | }; |
467 | |
468 | struct CCircle |
469 | { |
470 | int m_Radius; |
471 | }; |
472 | |
473 | int m_Type; |
474 | |
475 | union |
476 | { |
477 | CRectangle m_Rectangle; |
478 | CCircle m_Circle; |
479 | }; |
480 | }; |
481 | |
482 | struct CSoundSource |
483 | { |
484 | CPoint m_Position; |
485 | int m_Loop; |
486 | int m_Pan; // 0 - no panning, 1 - panning |
487 | int m_TimeDelay; // in s |
488 | int m_Falloff; // [0,255] // 0 - No falloff, 255 - full |
489 | |
490 | int m_PosEnv; |
491 | int m_PosEnvOffset; |
492 | int m_SoundEnv; |
493 | int m_SoundEnvOffset; |
494 | |
495 | CSoundShape m_Shape; |
496 | }; |
497 | |
498 | struct CMapItemLayerSounds |
499 | { |
500 | enum |
501 | { |
502 | CURRENT_VERSION = 2 |
503 | }; |
504 | |
505 | CMapItemLayer m_Layer; |
506 | int m_Version; |
507 | |
508 | int m_NumSources; |
509 | int m_Data; |
510 | int m_Sound; |
511 | |
512 | int m_aName[3]; |
513 | }; |
514 | |
515 | struct CMapItemSound |
516 | { |
517 | int m_Version; |
518 | |
519 | int m_External; |
520 | |
521 | int m_SoundName; |
522 | int m_SoundData; |
523 | // Deprecated. Do not read this value, it could be wrong. |
524 | // Use GetDataSize instead, which returns the de facto size. |
525 | // Value must still be written for compatibility. |
526 | int m_SoundDataSize; |
527 | }; |
528 | |
529 | // DDRace |
530 | |
531 | class CTeleTile |
532 | { |
533 | public: |
534 | unsigned char m_Number; |
535 | unsigned char m_Type; |
536 | }; |
537 | |
538 | class CSpeedupTile |
539 | { |
540 | public: |
541 | unsigned char m_Force; |
542 | unsigned char m_MaxSpeed; |
543 | unsigned char m_Type; |
544 | short m_Angle; |
545 | }; |
546 | |
547 | class CSwitchTile |
548 | { |
549 | public: |
550 | unsigned char m_Number; |
551 | unsigned char m_Type; |
552 | unsigned char m_Flags; |
553 | unsigned char m_Delay; |
554 | }; |
555 | |
556 | class CDoorTile |
557 | { |
558 | public: |
559 | unsigned char m_Index; |
560 | unsigned char m_Flags; |
561 | int m_Number; |
562 | }; |
563 | |
564 | class CTuneTile |
565 | { |
566 | public: |
567 | unsigned char m_Number; |
568 | unsigned char m_Type; |
569 | }; |
570 | |
571 | bool IsValidGameTile(int Index); |
572 | bool IsValidFrontTile(int Index); |
573 | bool IsValidTeleTile(int Index); |
574 | bool IsTeleTileCheckpoint(int Index); // Assumes that Index is a valid tele tile index |
575 | bool IsTeleTileNumberUsed(int Index, bool Checkpoint); // Assumes that Index is a valid tele tile index |
576 | bool IsTeleTileNumberUsedAny(int Index); // Does not check for checkpoint only |
577 | bool IsValidSpeedupTile(int Index); |
578 | bool IsValidSwitchTile(int Index); |
579 | bool IsSwitchTileFlagsUsed(int Index); // Assumes that Index is a valid switch tile index |
580 | bool IsSwitchTileNumberUsed(int Index); // Assumes that Index is a valid switch tile index |
581 | bool IsSwitchTileDelayUsed(int Index); // Assumes that Index is a valid switch tile index |
582 | bool IsValidTuneTile(int Index); |
583 | bool IsValidEntity(int Index); |
584 | bool IsRotatableTile(int Index); |
585 | bool IsCreditsTile(int TileIndex); |
586 | int PackColor(CColor Color); |
587 | |
588 | #endif |
589 | |