1 #include "Debug.h"
2 #include "FileMan.h"
3 #include "LoadSaveBullet.h"
4 #include "LoadSaveData.h"
5 #include "Overhead.h"
6 
7 
ExtractBulletFromFile(HWFILE const file,BULLET * const b)8 void ExtractBulletFromFile(HWFILE const file, BULLET* const b)
9 {
10 	BYTE src[128];
11 	DataReader s{src};
12 
13 	FileRead(file, src, sizeof(src));
14 
15 	EXTR_SKIP(s, 4)
16 	EXTR_SOLDIER(s, b->pFirer)
17 	EXTR_SOLDIER(s, b->target)
18 	EXTR_I8(s, b->bStartCubesAboveLevelZ)
19 	EXTR_I8(s, b->bEndCubesAboveLevelZ)
20 	EXTR_U32(s, b->sGridNo)
21 	EXTR_SKIP(s, 2)
22 	EXTR_U16(s, b->usLastStructureHit)
23 	EXTR_I32(s, b->qCurrX)
24 	EXTR_I32(s, b->qCurrY)
25 	EXTR_I32(s, b->qCurrZ)
26 	EXTR_I32(s, b->qIncrX)
27 	EXTR_I32(s, b->qIncrY)
28 	EXTR_I32(s, b->qIncrZ)
29 	EXTR_DOUBLE(s, b->ddHorizAngle)
30 	EXTR_I32(s, b->iCurrTileX)
31 	EXTR_I32(s, b->iCurrTileY)
32 	EXTR_I8(s, b->bLOSIndexX)
33 	EXTR_I8(s, b->bLOSIndexY)
34 	EXTR_BOOL(s, b->fCheckForRoof)
35 	EXTR_SKIP(s, 1)
36 	EXTR_I32(s, b->iCurrCubesZ)
37 	EXTR_I32(s, b->iLoop)
38 	EXTR_BOOL(s, b->fAllocated)
39 	EXTR_BOOL(s, b->fToDelete)
40 	EXTR_BOOL(s, b->fLocated)
41 	EXTR_BOOL(s, b->fReal)
42 	EXTR_BOOL(s, b->fAimed)
43 	EXTR_SKIP(s, 3)
44 	EXTR_U32(s, b->uiLastUpdate)
45 	EXTR_U8(s, b->ubTilesPerUpdate)
46 	EXTR_SKIP(s, 1)
47 	EXTR_U16(s, b->usClockTicksPerUpdate)
48 	EXTR_SKIP(s, 4)
49 	EXTR_U32(s, b->sTargetGridNo)
50 	EXTR_I16(s, b->sHitBy)
51 	EXTR_SKIP(s, 2)
52 	EXTR_I32(s, b->iImpact)
53 	EXTR_I32(s, b->iImpactReduction)
54 	EXTR_I32(s, b->iRange)
55 	EXTR_I32(s, b->iDistanceLimit)
56 	EXTR_U16(s, b->usFlags)
57 	EXTR_SKIP(s, 2)
58 	EXTR_PTR(s, b->pAniTile)
59 	EXTR_PTR(s, b->pShadowAniTile)
60 	EXTR_U8(s, b->ubItemStatus)
61 	EXTR_SKIP(s, 3)
62 	Assert(s.getConsumed() == lengthof(src));
63 }
64 
65 
InjectBulletIntoFile(HWFILE const file,BULLET const * b)66 void InjectBulletIntoFile(HWFILE const file, BULLET const* b)
67 {
68 	BYTE dst[128];
69 	DataWriter d{dst};
70 
71 	INJ_SKIP(d, 4)
72 	INJ_SOLDIER(d, b->pFirer)
73 	INJ_SOLDIER(d, b->target)
74 	INJ_I8(d, b->bStartCubesAboveLevelZ)
75 	INJ_I8(d, b->bEndCubesAboveLevelZ)
76 	INJ_U32(d, b->sGridNo)
77 	INJ_SKIP(d, 2)
78 	INJ_U16(d, b->usLastStructureHit)
79 	INJ_I32(d, b->qCurrX)
80 	INJ_I32(d, b->qCurrY)
81 	INJ_I32(d, b->qCurrZ)
82 	INJ_I32(d, b->qIncrX)
83 	INJ_I32(d, b->qIncrY)
84 	INJ_I32(d, b->qIncrZ)
85 	INJ_DOUBLE(d, b->ddHorizAngle)
86 	INJ_I32(d, b->iCurrTileX)
87 	INJ_I32(d, b->iCurrTileY)
88 	INJ_I8(d, b->bLOSIndexX)
89 	INJ_I8(d, b->bLOSIndexY)
90 	INJ_BOOL(d, b->fCheckForRoof)
91 	INJ_SKIP(d, 1)
92 	INJ_I32(d, b->iCurrCubesZ)
93 	INJ_I32(d, b->iLoop)
94 	INJ_BOOL(d, b->fAllocated)
95 	INJ_BOOL(d, b->fToDelete)
96 	INJ_BOOL(d, b->fLocated)
97 	INJ_BOOL(d, b->fReal)
98 	INJ_BOOL(d, b->fAimed)
99 	INJ_SKIP(d, 3)
100 	INJ_U32(d, b->uiLastUpdate)
101 	INJ_U8(d, b->ubTilesPerUpdate)
102 	INJ_SKIP(d, 1)
103 	INJ_U16(d, b->usClockTicksPerUpdate)
104 	INJ_SKIP(d, 4)
105 	INJ_U32(d, b->sTargetGridNo)
106 	INJ_I16(d, b->sHitBy)
107 	INJ_SKIP(d, 2)
108 	INJ_I32(d, b->iImpact)
109 	INJ_I32(d, b->iImpactReduction)
110 	INJ_I32(d, b->iRange)
111 	INJ_I32(d, b->iDistanceLimit)
112 	INJ_U16(d, b->usFlags)
113 	INJ_SKIP(d, 2)
114 	INJ_PTR(d, b->pAniTile)
115 	INJ_PTR(d, b->pShadowAniTile)
116 	INJ_U8(d, b->ubItemStatus)
117 	INJ_SKIP(d, 3)
118 	Assert(d.getConsumed() == lengthof(dst));
119 
120 	FileWrite(file, dst, sizeof(dst));
121 }
122