comparison Engine/Objects/ObjectList.cpp @ 2498:92eeeb5200f2

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