Mercurial > mm7
annotate ObjectList.cpp @ 1783:a3e86ec5d3ce
Player.cpp cosmetics
author | Grumpy7 |
---|---|
date | Thu, 03 Oct 2013 06:38:20 +0200 |
parents | 75fafd8ced59 |
children | c1c74df0a33e |
rev | line source |
---|---|
1296 | 1 #include "ObjectList.h" |
2 #include "mm7_data.h" | |
3 #include "Sprites.h" | |
4 #include "FrameTableInc.h" | |
1545 | 5 #include "ErrorHandling.h" |
1296 | 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 ) | |
1545 | 52 Error("Unable to save dobjlist.bin!"); |
1296 | 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; |
1545 | 66 Assert(uNumObjects); |
67 Assert(!num_mm8_objs); | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1306
diff
changeset
|
68 |
1583 | 69 pObjects = (ObjectDesc *)malloc(uNumObjects * sizeof(ObjectDesc)); |
1477
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; | |
1583 | 144 free(this->pObjects); |
1296 | 145 v3 = 0; |
146 v2->pObjects = 0; | |
147 v2->uNumObjects = 0; | |
148 v4 = fopen(Args, "r"); | |
149 File = v4; | |
150 if ( !v4 ) | |
1545 | 151 Error("ObjectDescriptionList::load - Unable to open file: %s."); |
152 | |
1296 | 153 v5 = 0; |
154 Argsa = 0; | |
155 if ( fgets(&Buf, 490, v4) ) | |
156 { | |
157 do | |
158 { | |
159 *strchr(&Buf, 10) = 0; | |
160 memcpy(&v45, frame_table_txt_parser(&Buf, &v44), sizeof(v45)); | |
161 if ( v45.uPropCount && *v45.pProperties[0] != '/' ) | |
162 ++Argsa; | |
163 } | |
164 while ( fgets(&Buf, 490, File) ); | |
165 v5 = Argsa; | |
166 v3 = 0; | |
167 } | |
168 v2->uNumObjects = v5; | |
1583 | 169 v6 = malloc(56 * v5); |
1296 | 170 v2->pObjects = (ObjectDesc *)v6; |
171 if ( v6 == (void *)v3 ) | |
1545 | 172 Error("ObjectDescriptionList::load - Out of Memory!"); |
173 | |
1296 | 174 memset(v6, v3, 56 * v2->uNumObjects); |
175 v7 = File; | |
176 v2->uNumObjects = v3; | |
177 fseek(v7, v3, v3); | |
178 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
179 { | |
180 *strchr(&Buf, 10) = 0; | |
181 memcpy(&v45, frame_table_txt_parser(&Buf, &v41), sizeof(v45)); | |
182 if ( v45.uPropCount && *v45.pProperties[0] != 47 ) | |
183 { | |
184 strcpy(v2->pObjects[v2->uNumObjects].field_0, v45.pProperties[0]); | |
185 v9 = pSpriteFrameTable->FastFindSprite((char *)v45.pProperties[1]); | |
186 v10 = v45.pProperties[2]; | |
187 v2->pObjects[v2->uNumObjects].uSpriteID = v9; | |
188 v11 = atoi(v10); | |
189 v12 = v45.pProperties[3]; | |
190 v2->pObjects[v2->uNumObjects].uObjectID = v11; | |
191 v13 = atoi(v12); | |
192 v14 = v45.pProperties[4]; | |
193 v2->pObjects[v2->uNumObjects].uRadius = v13; | |
194 v15 = atoi(v14); | |
195 v16 = v45.pProperties[5]; | |
196 v2->pObjects[v2->uNumObjects].uHeight = v15; | |
197 v17 = atoi(v16); | |
198 v18 = v45.pProperties[6]; | |
199 v2->pObjects[v2->uNumObjects].uLifetime = v17; | |
200 v19 = atoi(v18); | |
201 v20 = v45.pProperties[7]; | |
202 v2->pObjects[v2->uNumObjects].uSpeed = v19; | |
203 strcpy(&Dest, v20); | |
204 memcpy(&v44, frame_table_txt_parser(&Dest, &v40), sizeof(v44)); | |
205 if ( v45.uPropCount > 7 ) | |
206 { | |
207 for ( Argsb = 0; Argsb < v44.uPropCount; ++Argsb ) | |
208 { | |
209 v21 = Argsb; | |
210 v22 = v44.pProperties[Argsb]; | |
211 if ( !_stricmp(v44.pProperties[Argsb], "NoDraw") ) | |
212 { | |
213 v23 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
214 *(char *)v23 |= 1u; | |
215 } | |
216 if ( !_stricmp(v22, "Lifetime") ) | |
217 { | |
218 v24 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
219 *(char *)v24 |= 4u; | |
220 } | |
221 if ( !_stricmp(v22, "FTLifetime") ) | |
222 { | |
223 v25 = (int)&v2->pObjects[v2->uNumObjects]; | |
224 *(short *)(v25 + 42) = 8 * pSpriteFrameTable->pSpriteSFrames[*(short *)(v25 + 40)].uAnimLength; | |
225 v26 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
226 *(char *)v26 |= 8u; | |
227 v27 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
228 *(char *)v27 |= 4u; | |
229 } | |
230 if ( !_stricmp(v22, "NoPickup") ) | |
231 { | |
232 v28 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
233 *(char *)v28 |= 0x10u; | |
234 } | |
235 if ( !_stricmp(v22, "NoGravity") ) | |
236 { | |
237 v29 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
238 *(char *)v29 |= 0x20u; | |
239 } | |
240 if ( !_stricmp(v22, "FlagOnIntercept") ) | |
241 { | |
242 v30 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
243 *(char *)v30 |= 0x40u; | |
244 } | |
245 if ( !_stricmp(v22, "Bounce") ) | |
246 { | |
247 v31 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
248 *(char *)v31 |= 0x80u; | |
249 } | |
250 v32 = v45.pProperties[v21]; | |
251 if ( !_stricmp(v45.pProperties[v21], "Fire") ) | |
252 HIBYTE(v2->pObjects[v2->uNumObjects].uFlags) |= 2u; | |
253 if ( !_stricmp(v32, "Lines") ) | |
254 HIBYTE(v2->pObjects[v2->uNumObjects].uFlags) |= 4u; | |
255 if ( !_stricmp(v44.pProperties[v21], "bits") ) | |
256 { | |
257 v33 = v44.pProperties[v21 + 1]; | |
258 v34 = (int)&v2->pObjects[v2->uNumObjects].uFlags; | |
259 *(char *)(v34 + 1) |= 1u; | |
260 v35 = atoi(v33); | |
261 v36 = v44.pProperties[v21 + 2]; | |
262 v2->pObjects[v2->uNumObjects].uParticleTrailColorR = v35; | |
263 v37 = atoi(v36); | |
264 v38 = v44.pProperties[v21 + 3]; | |
265 v2->pObjects[v2->uNumObjects].uParticleTrailColorG = v37; | |
266 v2->pObjects[v2->uNumObjects].uParticleTrailColorB = atoi(v38); | |
267 } | |
268 } | |
269 } | |
270 ++v2->uNumObjects; | |
271 } | |
272 } | |
273 fclose(File); | |
274 return 1; | |
275 } |