1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 2010-2019 EDuke32 developers and contributors
4 Copyright (C) 2019 Nuke.YKT
5 
6 This file is part of NBlood.
7 
8 NBlood is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License version 2
10 as published by the Free Software Foundation.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 See the GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 */
22 //-------------------------------------------------------------------------
23 #pragma once
24 
25 #define kMaxXSprites 16384
26 #define kMaxXWalls 512
27 #define kMaxXSectors 512
28 
29 #ifdef NOONE_EXTENSIONS
30 extern bool gModernMap;
31 #endif // NOONE_EXTENSIONS
32 
33 
34 
35 // by NoOne: functions to quckly check range of specifical arrays
xspriRangeIsFine(int nXindex)36 inline bool xspriRangeIsFine(int nXindex) {
37     return (nXindex >= 0 && nXindex < kMaxXSprites);
38 }
39 
xsectRangeIsFine(int nXindex)40 inline bool xsectRangeIsFine(int nXindex) {
41     return (nXindex >= 0 && nXindex < kMaxXSectors);
42 }
43 
xwallRangeIsFine(int nXindex)44 inline bool xwallRangeIsFine(int nXindex) {
45     return (nXindex >= 0 && nXindex < kMaxXWalls);
46 }
47 #pragma pack(push, 1)
48 
49 struct AISTATE;
50 
51 struct XSPRITE {
52     unsigned int unused1 : 2;           // additional dude flags in modern maps
53     unsigned int unused2 : 1;           // unused
54     unsigned int unused3 : 2;           // unused
55     unsigned int unused4 : 6;           // unused
56 
57     signed   int reference : 15;
58     unsigned int state : 1;             // State 0
59     unsigned int busy : 17;
60     unsigned int txID : 10;             // TX ID
61     unsigned int rxID : 10;             // RX ID
62     unsigned int command : 8;           // Cmd
63     unsigned int triggerOn : 1;         // going ON
64     unsigned int triggerOff : 1;        // going OFF
65     unsigned int busyTime : 12;         // busyTime
66     unsigned int waitTime : 12;         // waitTime
67     unsigned int restState : 1;         // restState
68     unsigned int Interrutable : 1;      // Interruptable
69 
70     unsigned int respawnPending : 2;    // respawnPending
71 
72     unsigned int dropMsg : 8;           // Drop Item
73     unsigned int Decoupled : 1;         // Decoupled
74     unsigned int triggerOnce : 1;       // 1-shot
75     unsigned int isTriggered : 1;       // works in case if triggerOnce selected
76 
77     unsigned int key : 3;               // Key
78     unsigned int wave : 2;              // Wave
79     unsigned int Push : 1;              // Push
80     unsigned int Vector : 1;            // Vector
81     unsigned int Impact : 1;            // Impact
82     unsigned int Pickup : 1;            // Pickup
83     unsigned int Touch : 1;             // Touch
84     unsigned int Sight : 1;             // Sight
85     unsigned int Proximity : 1;         // Proximity
86     unsigned int lSkill : 5;            // Launch 12345
87     unsigned int lS : 1;                // Single
88     unsigned int lB : 1;                // Bloodbath
89     unsigned int lT : 1;                // Launch Team
90     unsigned int lC : 1;                // Coop
91     unsigned int DudeLockout : 1;       // DudeLockout
92     signed   int data1 : 16;            // Data 1
93     signed   int data2 : 16;            // Data 2
94     signed   int data3 : 16;            // Data 3
95     unsigned int data4 : 16;            // Data 4
96     unsigned int locked : 1;            // Locked
97     unsigned int medium : 2;            // medium
98     unsigned int respawn : 2;           // Respawn option
99     unsigned int lockMsg : 8;           // Lock msg
100     unsigned int health : 20;
101     unsigned int dudeDeaf : 1;          // dudeDeaf
102     unsigned int dudeAmbush : 1;        // dudeAmbush
103     unsigned int dudeGuard : 1;         // dudeGuard
104     unsigned int dudeFlag4 : 1;         // unused
105     signed   int target : 16;           // target sprite
106     signed   int targetX : 32;          // target x
107     signed   int targetY : 32;          // target y
108     signed   int targetZ : 32;          // target z
109     unsigned int goalAng : 11;          // Dude goal ang
110     signed   int dodgeDir : 2;          // Dude dodge direction
111     unsigned int burnTime : 16;
112     signed   int burnSource : 16;
113     unsigned int height : 16;
114     unsigned int stateTimer : 16;       // ai timer
115     AISTATE* aiState;                   // ai
116     #ifdef NOONE_EXTENSIONS
117     signed int sysData1: 32;            // used to keep here various system data, so user can't change it in map editor
118     signed int sysData2: 32;            //
119     unsigned int physAttr : 32;         // currently used by additional physics sprites to keep it's attributes.
120     #endif
121     signed int scale;                   // used for scaling SEQ size on sprites
122 
123 };
124 
125 struct XSECTOR {
126     signed int reference : 14;
127     unsigned int state : 1;             // State
128     unsigned int busy : 17;
129     unsigned int data : 16;             // Data
130     unsigned int txID : 10;             // TX ID
131     unsigned int rxID : 10;             // RX ID
132     unsigned int busyWaveA : 3;         // OFF->ON wave
133     unsigned int busyWaveB : 3;         // ON->OFF wave
134 
135     unsigned int command : 8;           // Cmd
136     unsigned int triggerOn : 1;         // Send at ON
137     unsigned int triggerOff : 1;        // Send at OFF
138     unsigned int busyTimeA : 12;        // OFF->ON busyTime
139     unsigned int waitTimeA : 12;        // OFF->ON waitTime
140     unsigned int restState : 1;
141     unsigned int interruptable : 1;     // Interruptable
142 
143     unsigned int reTriggerA : 1;        // OFF->ON wait
144     unsigned int reTriggerB : 1;        // ON->OFF wait
145     signed int amplitude : 8;           // Lighting amplitude
146     unsigned int freq : 8;              // Lighting freq
147     unsigned int phase : 8;             // Lighting phase
148     unsigned int wave : 4;              // Lighting wave
149     unsigned int shadeAlways : 1;       // Lighting shadeAlways
150     unsigned int shadeFloor : 1;        // Lighting floor
151     unsigned int shadeCeiling : 1;      // Lighting ceiling
152     unsigned int shadeWalls : 1;        // Lighting walls
153     signed int shade : 8;               // Lighting value
154     unsigned int panAlways : 1;         // Pan always
155     unsigned int panFloor : 1;          // Pan floor
156     unsigned int panCeiling : 1;        // Pan ceiling
157     unsigned int Drag : 1;              // Pan drag
158     unsigned int panVel : 8;            // Motion speed
159     unsigned int panAngle : 11;         // Motion angle
160     unsigned int Underwater : 1;        // Underwater
161     unsigned int Depth : 3;             // Depth
162     unsigned int unused1 : 1;
163     unsigned int decoupled : 1;         // Decoupled
164     unsigned int triggerOnce : 1;       // 1-shot
165     unsigned int isTriggered : 1;
166     unsigned int Key : 3;               // Key
167     unsigned int Push : 1;              // Push
168     unsigned int Vector : 1;            // Vector
169     unsigned int Reserved : 1;          // Reserved
170     unsigned int Enter : 1;             // Enter
171     unsigned int Exit : 1;              // Exit
172     unsigned int Wallpush : 1;          // WallPush
173     unsigned int color : 1;             // Color Lights
174     unsigned int unused2 : 1;
175     unsigned int busyTimeB : 12;        // ON->OFF busyTime
176     unsigned int waitTimeB : 12;        // ON->OFF waitTime
177     unsigned int stopOn : 1;
178     unsigned int stopOff : 1;
179     unsigned int ceilpal : 4;           // Ceil pal2
180     signed int offCeilZ : 32;
181     signed int onCeilZ : 32;
182     signed int offFloorZ : 32;
183     signed int onFloorZ : 32;
184     unsigned int marker0 : 16;
185     unsigned int marker1 : 16;
186     unsigned int Crush : 1;             // Crush
187     unsigned int ceilXPanFrac : 8;      // Ceiling x panning frac
188     unsigned int ceilYPanFrac : 8;      // Ceiling y panning frac
189     unsigned int floorXPanFrac : 8;     // Floor x panning frac
190     unsigned int damageType : 3;        // DamageType
191     unsigned int floorpal : 4;          // Floor pal2
192     unsigned int floorYPanFrac : 8;     // Floor y panning frac
193     unsigned int locked : 1;            // Locked
194     #ifdef NOONE_EXTENSIONS
195     unsigned int windVel : 32;          // Wind vel (changed from 10 bit to use higher velocity values)
196     #else
197     unsigned int windVel : 10;
198     #endif
199     unsigned int windAng : 11;          // Wind ang
200     unsigned int windAlways : 1;        // Wind always
201     unsigned int dudeLockout : 1;
202     unsigned int bobTheta : 11;         // Motion Theta
203     unsigned int bobZRange : 5;         // Motion Z range
204     signed int bobSpeed : 12;           // Motion speed
205     unsigned int bobAlways : 1;         // Motion always
206     unsigned int bobFloor : 1;          // Motion bob floor
207     unsigned int bobCeiling : 1;        // Motion bob ceiling
208     unsigned int bobRotate : 1;         // Motion rotate
209 };
210 
211 struct XWALL {
212     signed int reference : 15;
213     unsigned int state : 1;             // State
214     unsigned int busy : 17;
215     signed int data : 16;               // Data
216     unsigned int txID : 10;             // TX ID
217     unsigned int unused1 : 6;           // unused
218     unsigned int rxID : 10;             // RX ID
219     unsigned int command : 8;           // Cmd
220     unsigned int triggerOn : 1;         // going ON
221     unsigned int triggerOff : 1;        // going OFF
222     unsigned int busyTime : 12;         // busyTime
223     unsigned int waitTime : 12;         // waitTime
224     unsigned int restState : 1;         // restState
225     unsigned int interruptable : 1;     // Interruptable
226     unsigned int panAlways : 1;         // panAlways
227     signed   int panXVel : 8;           // panX
228     signed   int panYVel : 8;           // panY
229     unsigned int decoupled : 1;         // Decoupled
230     unsigned int triggerOnce : 1;       // 1-shot
231     unsigned int isTriggered : 1;
232     unsigned int key : 3;               // Key
233     unsigned int triggerPush : 1;       // Push
234     unsigned int triggerVector : 1;     // Vector
235     unsigned int triggerTouch : 1;      // by NoOne: renamed from Reserved to Touch as it works with Touch now.
236     unsigned int unused2 : 2;           // unused
237     unsigned int xpanFrac : 8;          // x panning frac
238     unsigned int ypanFrac : 8;          // y panning frac
239     unsigned int locked : 1;            // Locked
240     unsigned int dudeLockout : 1;       // DudeLockout
241     unsigned int unused3 : 4;           // unused;
242     unsigned int unused4 : 32;          // unused
243 };
244 
245 struct MAPSIGNATURE {
246     char signature[4];
247     short version;
248 };
249 
250 struct MAPHEADER  {
251     int at0; // x
252     int at4; // y
253     int at8; // z
254     short atc; // ang
255     short ate; // sect
256     short at10; // pskybits
257     int at12; // visibility
258     int at16; // song id, Matt
259     char at1a; // parallaxtype
260     int at1b; // map revision
261     short at1f; // numsectors
262     short at21; // numwalls
263     short at23; // numsprites
264 };
265 
266 struct MAPHEADER2 {
267     char at0[64];
268     int at40; // xsprite size
269     int at44; // xwall size
270     int at48; // xsector size
271     char pad[52];
272 };
273 
274 struct SPRITEHIT {
275     int hit, ceilhit, florhit;
276 };
277 
278 #pragma pack(pop)
279 
280 extern unsigned short gStatCount[kMaxStatus + 1];;
281 
282 extern bool byte_1A76C6, byte_1A76C7, byte_1A76C8;
283 extern MAPHEADER2 byte_19AE44;
284 
285 extern XSPRITE xsprite[kMaxXSprites];
286 extern XSECTOR xsector[kMaxXSectors];
287 extern XWALL xwall[kMaxXWalls];
288 
289 extern SPRITEHIT gSpriteHit[kMaxXSprites];
290 
291 extern char qsprite_filler[kMaxSprites], qsector_filler[kMaxSectors];
292 
293 extern int xvel[kMaxSprites], yvel[kMaxSprites], zvel[kMaxSprites];
294 
295 extern int gVisibility;
296 extern int gMapRev, gSongId, gSkyCount;
297 extern const char *gItemText[];
298 extern const char *gAmmoText[];
299 extern const char *gWeaponText[];
300 
301 extern unsigned short nextXSprite[kMaxXSprites];
302 extern unsigned short nextXWall[kMaxXWalls];
303 extern unsigned short nextXSector[kMaxXSectors];
304 
305 #ifdef YAX_ENABLE
yax_hasnextwall(int nWall)306 static inline bool yax_hasnextwall(int nWall)
307 {
308     return yax_getnextwall(nWall, YAX_CEILING) >= 0 || yax_getnextwall(nWall, YAX_FLOOR) >= 0;
309 }
310 #endif
311 
GetWallType(int nWall)312 static inline int GetWallType(int nWall)
313 {
314 #ifdef YAX_ENABLE
315     if (yax_hasnextwall(nWall))
316         return 0;
317 #endif
318     return wall[nWall].type;
319 }
320 
GetSpriteExtents(T const * const pSprite,int * top,int * bottom)321 template<typename T> void GetSpriteExtents(T const * const pSprite, int *top, int *bottom)
322 {
323     *top = *bottom = pSprite->z;
324     if ((pSprite->cstat & 0x30) != 0x20)
325     {
326         int height = tilesiz[pSprite->picnum].y;
327         int center = height / 2 + picanm[pSprite->picnum].yofs;
328         *top -= (pSprite->yrepeat << 2)*center;
329         *bottom += (pSprite->yrepeat << 2)*(height - center);
330     }
331 }
332 
333 #ifdef POLYMER
334 #pragma pack(push, 1)
335 struct PolymerLight_t {
336     int16_t lightId, lightmaxrange;
337     _prlight* lightptr;
338     uint8_t lightcount;
339 };
340 #pragma pack(pop)
341 
342 extern PolymerLight_t gPolymerLight[kMaxSprites];
343 
344 void DeleteLight(int32_t s);
345 
346 #endif
347 
348 void InsertSpriteSect(int nSprite, int nSector);
349 void RemoveSpriteSect(int nSprite);
350 void InsertSpriteStat(int nSprite, int nStat);
351 void RemoveSpriteStat(int nSprite);
352 void qinitspritelists(void);
353 int InsertSprite(int nSector, int nStat);
354 int qinsertsprite(short nSector, short nStat);
355 int DeleteSprite(int nSprite);
356 int qdeletesprite(short nSprite);
357 int ChangeSpriteSect(int nSprite, int nSector);
358 int qchangespritesect(short nSprite, short nSector);
359 int ChangeSpriteStat(int nSprite, int nStatus);
360 int qchangespritestat(short nSprite, short nStatus);
361 void InitFreeList(unsigned short *pList, int nCount);
362 void InsertFree(unsigned short *pList, int nIndex);
363 unsigned short dbInsertXSprite(int nSprite);
364 void dbDeleteXSprite(int nXSprite);
365 unsigned short dbInsertXWall(int nWall);
366 void dbDeleteXWall(int nXWall);
367 unsigned short dbInsertXSector(int nSector);
368 void dbDeleteXSector(int nXSector);
369 void dbXSpriteClean(void);
370 void dbXWallClean(void);
371 void dbXSectorClean(void);
372 void dbInit(void);
373 void PropagateMarkerReferences(void);
374 unsigned int dbReadMapCRC(const char *pPath);
375 int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short *pSector, unsigned int *pCRC);
376