Mercurial > mm7
annotate ObjectList.cpp @ 1495:990fadbaac18
Cleanup of LevelDecoration. (2)
author | yoctozepto |
---|---|
date | Sun, 01 Sep 2013 11:57:07 +0200 |
parents | 7ef4b64f6329 |
children | c4ab816fcc5e |
rev | line source |
---|---|
1296 | 1 #include "ObjectList.h" |
2 #include "mm7_data.h" | |
3 #include "Sprites.h" | |
4 #include "FrameTableInc.h" | |
5 #include "Allocator.h" | |
6 | |
7 //----- (0042EB42) -------------------------------------------------------- | |
8 __int16 ObjectList::ObjectIDByItemID(unsigned __int16 uItemID) | |
9 { | |
10 unsigned int v2; // edx@1 | |
11 signed int v3; // eax@1 | |
12 char *v4; // ecx@2 | |
13 | |
14 v2 = this->uNumObjects; | |
15 v3 = 0; | |
16 if ( (signed int)this->uNumObjects <= 0 ) | |
17 { | |
18 LABEL_5: | |
19 LOWORD(v3) = 0; | |
20 } | |
21 else | |
22 { | |
23 v4 = (char *)&this->pObjects->uObjectID; | |
24 while ( uItemID != *(short *)v4 ) | |
25 { | |
26 ++v3; | |
27 v4 += 56; | |
28 if ( v3 >= (signed int)v2 ) | |
29 goto LABEL_5; | |
30 } | |
31 } | |
32 return v3; | |
33 } | |
34 //----- (00459064) -------------------------------------------------------- | |
35 void ObjectList::InitializeSprites() | |
36 { | |
37 for (uint i = 0; i < uNumObjects; ++i) | |
38 pSpriteFrameTable->InitializeSprite(pObjects[i].uSpriteID); | |
39 } | |
40 | |
41 //----- (00459090) -------------------------------------------------------- | |
42 void ObjectList::ToFile() | |
43 { | |
44 ObjectList *v1; // esi@1 | |
45 FILE *v2; // eax@1 | |
46 FILE *v3; // edi@1 | |
47 | |
48 v1 = this; | |
49 v2 = fopen("data\\dobjlist.bin", "wb"); | |
50 v3 = v2; | |
51 if ( !v2 ) | |
52 Abortf("Unable to save dobjlist.bin!"); | |
53 fwrite(v1, 4u, 1u, v2); | |
54 fwrite(v1->pObjects, 0x38u, v1->uNumObjects, v3); | |
55 fclose(v3); | |
56 } | |
57 | |
58 //----- (004590DC) -------------------------------------------------------- | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
59 void ObjectList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) |
1296 | 60 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
61 uint num_mm6_objs = data_mm6 ? *(int *)data_mm6 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
62 num_mm7_objs = data_mm7 ? *(int *)data_mm7 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
63 num_mm8_objs = data_mm8 ? *(int *)data_mm8 : 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
64 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
65 uNumObjects = num_mm6_objs + num_mm7_objs + num_mm8_objs; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
66 assert(uNumObjects); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
67 assert(!num_mm8_objs); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
68 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
69 pObjects = (ObjectDesc *)pAllocator->AllocNamedChunk(pObjects, uNumObjects * sizeof(ObjectDesc), "Obj Descrip"); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
70 memcpy(pObjects, (char *)data_mm7 + 4, num_mm7_objs * sizeof(ObjectDesc)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
71 for (uint i = 0; i < num_mm6_objs; ++i) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
72 { |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
73 auto src = (ObjectDesc_mm6 *)((char *)data_mm6 + 4) + i; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
74 auto dst = pObjects + num_mm7_objs + i; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
75 memcpy(dst->field_0, src->field_0, sizeof(dst->field_0)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
76 dst->uObjectID = src->uObjectID; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
77 dst->uRadius = src->uRadius; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
78 dst->uHeight = src->uHeight; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
79 dst->uFlags = src->uFlags; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
80 dst->uSpriteID = src->uSpriteID; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
81 dst->uLifetime = src->uLifetime; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
82 dst->uParticleTrailColor = src->uParticleTrailColor; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
83 dst->uSpeed = src->uSpeed; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
84 dst->uParticleTrailColorR = src->uParticleTrailColorR; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
85 dst->uParticleTrailColorG = src->uParticleTrailColorG; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
86 dst->uParticleTrailColorB = src->uParticleTrailColorB; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
87 dst->field_35_clr = src->field_35_clr; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
88 dst->field_36_clr = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
89 dst->field_37_clr = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
90 } |
1296 | 91 } |
92 | |
93 //----- (00459123) -------------------------------------------------------- | |
94 bool ObjectList::FromFileTxt(const char *Args) | |
95 { | |
96 ObjectList *v2; // ebx@1 | |
97 __int32 v3; // edi@1 | |
98 FILE *v4; // eax@1 | |
99 unsigned int v5; // esi@3 | |
100 void *v6; // eax@9 | |
101 FILE *v7; // ST0C_4@11 | |
102 char *i; // eax@11 | |
103 unsigned __int16 v9; // ax@14 | |
104 const char *v10; // ST20_4@14 | |
105 __int16 v11; // ax@14 | |
106 const char *v12; // ST1C_4@14 | |
107 __int16 v13; // ax@14 | |
108 const char *v14; // ST18_4@14 | |
109 __int16 v15; // ax@14 | |
110 const char *v16; // ST14_4@14 | |
111 __int16 v17; // ax@14 | |
112 const char *v18; // ST10_4@14 | |
113 __int16 v19; // ax@14 | |
114 const char *v20; // ST0C_4@14 | |
115 int v21; // esi@16 | |
116 const char *v22; // edi@16 | |
117 int v23; // eax@17 | |
118 int v24; // eax@19 | |
119 int v25; // eax@21 | |
120 int v26; // eax@21 | |
121 int v27; // eax@21 | |
122 int v28; // eax@23 | |
123 int v29; // eax@25 | |
124 int v30; // eax@27 | |
125 int v31; // eax@29 | |
126 const char *v32; // edi@30 | |
127 const char *v33; // ST20_4@35 | |
128 int v34; // eax@35 | |
129 char v35; // al@35 | |
130 const char *v36; // ST1C_4@35 | |
131 char v37; // al@35 | |
132 const char *v38; // ST18_4@35 | |
133 FrameTableTxtLine v40; // [sp+8h] [bp-460h]@14 | |
134 FrameTableTxtLine v41; // [sp+84h] [bp-3E4h]@12 | |
135 char Dest; // [sp+100h] [bp-368h]@14 | |
136 char Buf; // [sp+178h] [bp-2F0h]@3 | |
137 FrameTableTxtLine v44; // [sp+36Ch] [bp-FCh]@4 | |
138 FrameTableTxtLine v45; // [sp+3E8h] [bp-80h]@4 | |
139 FILE *File; // [sp+464h] [bp-4h]@1 | |
140 unsigned int Argsa; // [sp+470h] [bp+8h]@3 | |
141 int Argsb; // [sp+470h] [bp+8h]@15 | |
142 | |
143 v2 = this; | |
144 pAllocator->FreeChunk(this->pObjects); | |
145 v3 = 0; | |
146 v2->pObjects = 0; | |
147 v2->uNumObjects = 0; | |
148 v4 = fopen(Args, "r"); | |
149 File = v4; | |
150 if ( !v4 ) | |
151 Abortf("ObjectDescriptionList::load - Unable to open file: %s."); | |
152 v5 = 0; | |
153 Argsa = 0; | |
154 if ( fgets(&Buf, 490, v4) ) | |
155 { | |
156 do | |
157 { | |
158 *strchr(&Buf, 10) = 0; | |
159 memcpy(&v45, frame_table_txt_parser(&Buf, &v44), sizeof(v45)); | |
160 if ( v45.uPropCount && *v45.pProperties[0] != '/' ) | |
161 ++Argsa; | |
162 } | |
163 while ( fgets(&Buf, 490, File) ); | |
164 v5 = Argsa; | |
165 v3 = 0; | |
166 } | |
167 v2->uNumObjects = v5; | |
168 v6 = pAllocator->AllocNamedChunk(v2->pObjects, 56 * v5, "Obj Descrip"); | |
169 v2->pObjects = (ObjectDesc *)v6; | |
170 if ( v6 == (void *)v3 ) | |
171 Abortf("ObjectDescriptionList::load - Out of Memory!"); | |
172 memset(v6, v3, 56 * v2->uNumObjects); | |
173 v7 = File; | |
174 v2->uNumObjects = v3; | |
175 fseek(v7, v3, v3); | |
176 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
177 { | |
178 *strchr(&Buf, 10) = 0; | |
179 memcpy(&v45, frame_table_txt_parser(&Buf, &v41), sizeof(v45)); | |
180 if ( v45.uPropCount && *v45.pProperties[0] != 47 ) | |
181 { | |
182 strcpy(v2->pObjects[v2->uNumObjects].field_0, v45.pProperties[0]); | |
183 v9 = pSpriteFrameTable->FastFindSprite((char *)v45.pProperties[1]); | |
184 v10 = v45.pProperties[2]; | |
185 v2->pObjects[v2->uNumObjects].uSpriteID = v9; | |
186 v11 = atoi(v10); | |
187 v12 = v45.pProperties[3]; | |
188 v2->pObjects[v2->uNumObjects].uObjectID = v11; | |
189 v13 = atoi(v12); | |
190 v14 = v45.pProperties[4]; | |
191 v2->pObjects[v2->uNumObjects].uRadius = v13; | |
192 v15 = atoi(v14); | |
193 v16 = v45.pProperties[5]; | |
194 v2->pObjects[v2->uNumObjects].uHeight = v15; | |
195 v17 = atoi(v16); | |
196 v18 = v45.pProperties[6]; | |
197 v2->pObjects[v2->uNumObjects].uLifetime = v17; | |
198 v19 = atoi(v18); | |
199 v20 = v45.pProperties[7]; | |
200 v2->pObjects[v2->uNumObjects].uSpeed = v19; | |
201 strcpy(&Dest, v20); | |
202 memcpy(&v44, frame_table_txt_parser(&Dest, &v40), sizeof(v44)); | |
203 if ( v45.uPropCount > 7 ) | |
204 { | |
205 for ( Argsb = 0; Argsb < v44.uPropCount; ++Argsb ) | |
206 { | |
207 v21 = Argsb; | |
208 v22 = v44.pProperties[Argsb]; | |
209 if ( !_stricmp(v44.pProperties[Argsb], "NoDraw") ) | |
210 { | |
211 v23 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
212 *(char *)v23 |= 1u; | |
213 } | |
214 if ( !_stricmp(v22, "Lifetime") ) | |
215 { | |
216 v24 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
217 *(char *)v24 |= 4u; | |
218 } | |
219 if ( !_stricmp(v22, "FTLifetime") ) | |
220 { | |
221 v25 = (int)&v2->pObjects[v2->uNumObjects]; | |
222 *(short *)(v25 + 42) = 8 * pSpriteFrameTable->pSpriteSFrames[*(short *)(v25 + 40)].uAnimLength; | |
223 v26 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
224 *(char *)v26 |= 8u; | |
225 v27 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
226 *(char *)v27 |= 4u; | |
227 } | |
228 if ( !_stricmp(v22, "NoPickup") ) | |
229 { | |
230 v28 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
231 *(char *)v28 |= 0x10u; | |
232 } | |
233 if ( !_stricmp(v22, "NoGravity") ) | |
234 { | |
235 v29 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
236 *(char *)v29 |= 0x20u; | |
237 } | |
238 if ( !_stricmp(v22, "FlagOnIntercept") ) | |
239 { | |
240 v30 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
241 *(char *)v30 |= 0x40u; | |
242 } | |
243 if ( !_stricmp(v22, "Bounce") ) | |
244 { | |
245 v31 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
246 *(char *)v31 |= 0x80u; | |
247 } | |
248 v32 = v45.pProperties[v21]; | |
249 if ( !_stricmp(v45.pProperties[v21], "Fire") ) | |
250 HIBYTE(v2->pObjects[v2->uNumObjects].uFlags) |= 2u; | |
251 if ( !_stricmp(v32, "Lines") ) | |
252 HIBYTE(v2->pObjects[v2->uNumObjects].uFlags) |= 4u; | |
253 if ( !_stricmp(v44.pProperties[v21], "bits") ) | |
254 { | |
255 v33 = v44.pProperties[v21 + 1]; | |
256 v34 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
257 *(char *)(v34 + 1) |= 1u; | |
258 v35 = atoi(v33); | |
259 v36 = v44.pProperties[v21 + 2]; | |
260 v2->pObjects[v2->uNumObjects].uParticleTrailColorR = v35; | |
261 v37 = atoi(v36); | |
262 v38 = v44.pProperties[v21 + 3]; | |
263 v2->pObjects[v2->uNumObjects].uParticleTrailColorG = v37; | |
264 v2->pObjects[v2->uNumObjects].uParticleTrailColorB = atoi(v38); | |
265 } | |
266 } | |
267 } | |
268 ++v2->uNumObjects; | |
269 } | |
270 } | |
271 fclose(File); | |
272 return 1; | |
273 } |