Mercurial > mm7
annotate Sprites.cpp @ 2156:eaaaa50d34e9
GetItemBonusEnchantment
author | Ritor1 |
---|---|
date | Fri, 10 Jan 2014 17:42:37 +0600 |
parents | d28d3c006077 |
children | ff8920a40c21 |
rev | line source |
---|---|
0 | 1 #include <string.h> |
1017 | 2 #include <algorithm> |
0 | 3 |
4 #include "Sprites.h" | |
5 #include "PaletteManager.h" | |
6 #include "LOD.h" | |
7 #include "FrameTableInc.h" | |
8 | |
9 #include "mm7_data.h" | |
2152 | 10 #include "mm7_unsorted_subs.h" |
1295 | 11 #include "Outdoor.h" |
12 #include "DecorationList.h" | |
13 #include "MM7.h" | |
14 #include "Actor.h" | |
1828
35c1e4ff6ba7
party_finds_gold to Party::PartyFindsGold, cleaned up, moved Level/Decoration.h reference out of Indoor.h
Grumpy7
parents:
1583
diff
changeset
|
15 #include "Level/Decoration.h" |
0 | 16 |
17 | |
18 | |
19 | |
20 struct SpriteFrameTable *pSpriteFrameTable; | |
21 | |
22 | |
23 | |
24 | |
25 //----- (0044D4D8) -------------------------------------------------------- | |
26 void SpriteFrameTable::ReleaseSFrames() | |
27 { | |
28 SpriteFrameTable *v1; // esi@1 | |
29 | |
30 v1 = this; | |
31 if ( this->pSpriteSFrames ) | |
32 { | |
1583 | 33 free(this->pSpriteSFrames); |
0 | 34 v1->pSpriteSFrames = 0; |
35 } | |
36 v1->uNumSpriteFrames = 0; | |
37 } | |
38 | |
39 //----- (0044D4F6) -------------------------------------------------------- | |
40 void SpriteFrameTable::ResetSomeSpriteFlags() | |
41 { | |
42 int v1; // esi@1 | |
43 signed int i; // edx@1 | |
44 char *v3; // eax@2 | |
45 | |
46 v1 = 0; | |
47 for ( i = 0; i < (signed int)this->uNumSpriteFrames; ++i ) | |
48 { | |
49 v3 = (char *)&this->pSpriteSFrames[v1].uFlags; | |
50 ++v1; | |
51 *v3 &= 0x7Fu; | |
52 } | |
53 } | |
54 | |
55 //----- (0044D513) -------------------------------------------------------- | |
670 | 56 void SpriteFrameTable::InitializeSprite( signed int uSpriteID ) |
700
1d05543f522d
Some occasional crashes in PaletteManager and sprite loading fixed.
Nomad
parents:
670
diff
changeset
|
57 { |
670 | 58 //SpriteFrameTable *v2; // esi@1 |
59 unsigned int v3; // ebx@3 | |
60 //char *v4; // edx@3 | |
61 //int v5; // eax@3 | |
62 SpriteFrame *v6; // ecx@5 | |
63 int v7; // eax@5 | |
64 __int16 v8; // ax@6 | |
65 //signed int v9; // edx@6 | |
66 //int v10; // ecx@6 | |
67 signed int v11; // edi@10 | |
68 __int16 v12; // ax@16 | |
69 int v13; // ecx@16 | |
70 size_t v14; // eax@19 | |
71 signed int v15; // edi@19 | |
72 __int16 v16; // ax@27 | |
73 int v17; // ecx@27 | |
74 signed int v18; // edi@29 | |
75 SpriteFrame *v19; // eax@30 | |
76 __int16 v20; // ax@45 | |
77 int v21; // ecx@45 | |
0 | 78 |
670 | 79 char Str[32]; // [sp+Ch] [bp-3Ch]@19 |
80 char sprite_name[20]; // [sp+2Ch] [bp-1Ch]@15 | |
81 char Source[4]; // [sp+40h] [bp-8h]@19 | |
0 | 82 |
83 | |
670 | 84 //v2 = this; |
85 if ( uSpriteID <= this->uNumSpriteFrames ) | |
0 | 86 { |
670 | 87 if ( uSpriteID >= 0 ) |
0 | 88 { |
670 | 89 v3 = uSpriteID; |
90 | |
1980 | 91 int uFlags = pSpriteSFrames[v3].uFlags; |
670 | 92 if (!(uFlags & 0x0080)) //not loaded |
93 { | |
94 pSpriteSFrames[v3].uFlags |= 0x80; //set loaded | |
95 while ( 1 ) | |
96 { | |
97 pSpriteSFrames[v3].uPaletteIndex = pPaletteManager->LoadPalette(pSpriteSFrames[v3].uPaletteID); | |
98 if ( uFlags & 0x10 ) //single frame per frame sequence | |
99 { | |
100 v8 = pSprites_LOD->LoadSprite(pSpriteSFrames[v3].pTextureName, pSpriteSFrames[v3].uPaletteID); | |
101 for (uint i = 0; i < 8; ++i) | |
102 { | |
103 | |
104 pSpriteSFrames[v3].pHwSpriteIDs[i] = v8; | |
105 } | |
106 | |
107 } | |
108 else if ( uFlags & 0x10000 ) | |
109 { | |
110 for (uint i = 0; i < 8; ++i) | |
111 { | |
112 switch ( i ) | |
113 { | |
114 case 3: | |
115 case 4: | |
116 case 5: | |
117 sprintf(sprite_name, "%s4", pSpriteSFrames[v3].pTextureName); | |
118 break; | |
119 case 2: | |
120 case 6: | |
121 sprintf(sprite_name, "%s2", pSpriteSFrames[v3].pTextureName); | |
122 break; | |
123 case 0: | |
124 case 1: | |
125 case 7: | |
126 sprintf(sprite_name, "%s0", pSpriteSFrames[v3].pTextureName); | |
127 break; | |
128 } | |
129 v12 = pSprites_LOD->LoadSprite(sprite_name, pSpriteSFrames[v3].uPaletteID); | |
130 | |
131 pSpriteSFrames[v3].pHwSpriteIDs[i]=v12; | |
132 } | |
133 | |
134 } | |
135 else if ( uFlags & 0x40 ) //part of monster fidgeting seq | |
136 { | |
137 strcpy(Source, "stA"); | |
138 strcpy(Str, pSpriteSFrames[v3].pTextureName); | |
139 v14 = strlen(Str); | |
140 strcpy(&Str[v14-3], Source); | |
141 for (uint i = 0; i < 8; ++i) | |
142 { | |
143 switch ( i ) | |
144 { | |
145 case 0: | |
146 sprintf(sprite_name, "%s0", pSpriteSFrames[v3].pTextureName); | |
147 break; | |
148 case 4: | |
149 sprintf(sprite_name, "%s4",&Str ); | |
150 break; | |
151 case 3: | |
152 case 5: | |
153 sprintf(sprite_name, "%s3",&Str ); | |
154 break; | |
155 case 2: | |
156 case 6: | |
157 sprintf(sprite_name, "%s2", pSpriteSFrames[v3].pTextureName); | |
158 break; | |
159 case 1: | |
160 case 7: | |
161 sprintf(sprite_name, "%s1", pSpriteSFrames[v3].pTextureName); | |
162 break; | |
163 } | |
164 v12 = pSprites_LOD->LoadSprite(sprite_name, pSpriteSFrames[v3].uPaletteID); | |
165 pSpriteSFrames[v3].pHwSpriteIDs[i]=v12; | |
166 } | |
167 } | |
168 | |
169 else | |
170 { | |
171 for (uint i = 0; i < 8; ++i) | |
172 | |
173 { | |
174 | |
175 if (((0x0100 << i) & pSpriteSFrames[v3].uFlags) ) //mirrors | |
176 { | |
177 switch ( i ) | |
178 { | |
179 case 1: | |
180 sprintf(sprite_name, "%s7", pSpriteSFrames[v3].pTextureName); | |
181 break; | |
182 case 2: | |
183 sprintf(sprite_name, "%s6", pSpriteSFrames[v3].pTextureName); | |
184 break; | |
185 case 3: | |
186 sprintf(sprite_name, "%s5", pSpriteSFrames[v3].pTextureName); | |
187 break; | |
188 case 4: | |
189 sprintf(sprite_name, "%s4", pSpriteSFrames[v3].pTextureName); | |
190 break; | |
191 | |
192 case 5: | |
193 sprintf(sprite_name, "%s3", pSpriteSFrames[v3].pTextureName); | |
194 break; | |
195 | |
196 case 6: | |
197 sprintf(sprite_name, "%s2", pSpriteSFrames[v3].pTextureName); | |
198 break; | |
199 case 7: | |
200 sprintf(sprite_name, "%s1", pSpriteSFrames[v3].pTextureName); | |
201 break; | |
202 } | |
203 } | |
204 else | |
205 { | |
206 sprintf(sprite_name, "%s%i", pSpriteSFrames[v3].pTextureName, i); | |
207 | |
208 } | |
209 v12 = pSprites_LOD->LoadSprite(sprite_name, pSpriteSFrames[v3].uPaletteID); | |
210 pSpriteSFrames[v3].pHwSpriteIDs[i]=v12; | |
211 | |
212 } | |
213 } | |
214 | |
215 if ( !(pSpriteSFrames[v3].uFlags & 1) ) | |
216 return; | |
217 ++v3; | |
218 } | |
219 } | |
220 } | |
0 | 221 } |
222 } | |
223 | |
224 //----- (0044D813) -------------------------------------------------------- | |
670 | 225 signed int SpriteFrameTable::FastFindSprite( char *pSpriteName ) |
1017 | 226 { |
670 | 227 signed int result; // eax@2 |
0 | 228 |
1017 | 229 int searchResult = BinarySearch(pSpriteName); |
230 if ( searchResult < 0 ) | |
0 | 231 result = 0; |
232 else | |
1017 | 233 result = this->pSpriteEFrames[searchResult]; |
0 | 234 return result; |
235 } | |
236 | |
237 //----- (0044D83A) -------------------------------------------------------- | |
1017 | 238 int SpriteFrameTable::BinarySearch( const char *pSpriteName ) |
0 | 239 { |
1017 | 240 int startPos = 0; |
241 int endPos = uNumEFrames; | |
242 while ( 1 ) | |
0 | 243 { |
1017 | 244 int searchRange = endPos - startPos; |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
245 int middleFrameIndex = startPos + (endPos - startPos) / 2; |
1017 | 246 int comparisonResult = _stricmp(pSpriteName, this->pSpritePFrames[middleFrameIndex]->pIconName); |
247 if ( !comparisonResult ) | |
0 | 248 { |
1017 | 249 return middleFrameIndex; |
250 } | |
251 if ( startPos == endPos ) | |
252 { | |
253 return -1; | |
0 | 254 } |
1017 | 255 if ( comparisonResult >= 0 ) |
256 { | |
257 startPos += max(((endPos - startPos) / 2), 1); | |
258 } | |
259 else{ | |
260 endPos = max(((endPos - startPos) / 2), 1) + startPos; | |
261 } | |
0 | 262 } |
263 } | |
264 | |
265 //----- (0044D8D0) -------------------------------------------------------- | |
639 | 266 SpriteFrame *SpriteFrameTable::GetFrame(unsigned int uSpriteID, unsigned int uTime) |
0 | 267 { |
639 | 268 //SpriteFrame *v3; // edi@1 |
0 | 269 SpriteFrame *v4; // ecx@1 |
639 | 270 //__int16 v5; // dx@2 |
271 //int v6; // edx@3 | |
272 //unsigned int v7; // eax@3 | |
273 //char *i; // ecx@3 | |
274 //int v9; // esi@5 | |
275 //SpriteFrame *result; // eax@6 | |
0 | 276 |
639 | 277 v4 = &pSpriteSFrames[uSpriteID]; |
278 if (~v4->uFlags & 1 || !v4->uAnimLength) | |
279 return pSpriteSFrames + uSpriteID; | |
280 | |
281 for (uint t = (uTime / 8) % v4->uAnimLength; t > v4->uAnimTime; ++v4) | |
282 t -= v4->uAnimTime; | |
283 return v4; | |
284 | |
285 /*for (v4; v4->uAnimTime <= t; ++v4) | |
286 | |
287 v6 = (uTime / 8) % v4->uAnimLength; | |
288 //v7 = uSpriteID; | |
0 | 289 for ( i = (char *)&v4->uAnimTime; ; i += 60 ) |
290 { | |
291 v9 = *(short *)i; | |
292 if ( v6 <= v9 ) | |
293 break; | |
294 v6 -= v9; | |
295 ++v7; | |
296 } | |
639 | 297 return &pSpriteSFrames[v7];*/ |
298 | |
0 | 299 } |
300 | |
301 //----- (0044D91F) -------------------------------------------------------- | |
302 SpriteFrame *SpriteFrameTable::GetFrameBy_x(unsigned int uSpriteID, signed int a3) | |
303 { | |
304 SpriteFrame *v3; // edi@1 | |
305 SpriteFrame *v4; // esi@1 | |
306 __int16 v5; // ax@2 | |
307 int v6; // ecx@3 | |
308 int v7; // edx@3 | |
309 unsigned int v8; // eax@3 | |
310 int v9; // ecx@3 | |
311 char *i; // edx@3 | |
312 int v11; // esi@5 | |
313 SpriteFrame *result; // eax@6 | |
314 | |
315 v3 = this->pSpriteSFrames; | |
316 v4 = &v3[uSpriteID]; | |
317 if ( v4->uFlags & 1 && (v5 = v4->uAnimLength) != 0 ) | |
318 { | |
319 v6 = v5; | |
320 v7 = a3 % v5; | |
321 v8 = uSpriteID; | |
322 v9 = v6 - v7; | |
323 for ( i = (char *)&v4->uAnimTime; ; i += 60 ) | |
324 { | |
325 v11 = *(short *)i; | |
326 if ( v9 <= v11 ) | |
327 break; | |
328 v9 -= v11; | |
329 ++v8; | |
330 } | |
331 result = &v3[v8]; | |
332 } | |
333 else | |
334 { | |
335 result = &v3[uSpriteID]; | |
336 } | |
337 return result; | |
338 } | |
339 | |
340 //----- (0044D96D) -------------------------------------------------------- | |
341 void SpriteFrameTable::ToFile() | |
342 { | |
343 SpriteFrameTable *v1; // esi@1 | |
344 FILE *v2; // eax@1 | |
345 FILE *v3; // edi@1 | |
346 | |
347 v1 = this; | |
348 v2 = fopen("data\\dsft.bin", "wb"); | |
349 v3 = v2; | |
350 if ( !v2 ) | |
1545 | 351 Error("Unable to save dsft.bin!"); |
0 | 352 fwrite(v1, 4u, 1u, v2); |
353 fwrite(&v1->uNumEFrames, 4u, 1u, v3); | |
354 fwrite(v1->pSpriteSFrames, 0x3Cu, v1->uNumSpriteFrames, v3); | |
355 fwrite(v1->pSpriteEFrames, 2u, v1->uNumEFrames, v3); | |
356 fclose(v3); | |
357 } | |
358 | |
359 //----- (0044D9D7) -------------------------------------------------------- | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
360 void SpriteFrameTable::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) |
0 | 361 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
362 uint num_mm6_frames = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
363 uint num_mm6_eframes = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
364 if (data_mm6) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
365 { |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
366 num_mm6_frames = *(int *)data_mm6; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
367 num_mm6_eframes = *((int *)data_mm6 + 1); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
368 } |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
369 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
370 uint num_mm7_frames = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
371 uint num_mm7_eframes = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
372 if (data_mm7) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
373 { |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
374 num_mm7_frames = *(int *)data_mm7; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
375 num_mm7_eframes = *((int *)data_mm7 + 1); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
376 } |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
377 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
378 uint num_mm8_frames = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
379 uint num_mm8_eframes = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
380 if (data_mm8) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
381 { |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
382 num_mm8_frames = *(int *)data_mm8; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
383 num_mm8_eframes = *((int *)data_mm8 + 1); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
384 } |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
385 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
386 uNumSpriteFrames = num_mm6_frames + num_mm7_frames + num_mm8_frames; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
387 uNumEFrames = num_mm6_eframes + num_mm7_eframes + num_mm8_eframes; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
388 |
1583 | 389 pSpriteSFrames = (SpriteFrame *)malloc(uNumSpriteFrames * sizeof(SpriteFrame)); |
390 pSpriteEFrames = (__int16 *)malloc(uNumSpriteFrames * sizeof(short)); | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
391 |
1583 | 392 pSpritePFrames = (SpriteFrame **)malloc(4 * uNumSpriteFrames); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
393 |
1980 | 394 uint mm7_frames_size = num_mm7_frames * sizeof(SpriteFrame); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
395 memcpy(pSpriteSFrames, (char *)data_mm7 + 8, mm7_frames_size); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
396 memcpy(pSpriteEFrames, (char *)data_mm7 + 8 + mm7_frames_size, 2 * num_mm7_eframes); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
397 |
1980 | 398 uint mm6_frames_size = num_mm6_frames * sizeof(SpriteFrame_mm6); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
399 for (uint i = 0; i < num_mm6_frames; ++i) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
400 { |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
401 memcpy(pSpriteSFrames + num_mm7_frames + i, (char *)data_mm6 + 8 + i * sizeof(SpriteFrame_mm6), sizeof(SpriteFrame_mm6)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
402 pSpriteSFrames[num_mm7_frames + i].uAnimLength = 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
403 } |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
404 memcpy(pSpriteEFrames + num_mm7_frames, (char *)data_mm6 + 8 + mm6_frames_size, 2 * num_mm6_eframes); |
1541 | 405 |
1980 | 406 uint mm8_frames_size = num_mm8_frames * sizeof(SpriteFrame); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
407 memcpy(pSpriteSFrames + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 8, mm8_frames_size); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
408 memcpy(pSpriteEFrames + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 8 + mm8_frames_size, 2 * num_mm8_eframes); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
409 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
410 for (uint i = 0; i < num_mm7_frames; ++i) |
0 | 411 pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i]]; |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
412 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
413 for (uint i = num_mm7_frames; i < num_mm6_frames + num_mm7_frames; ++i) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
414 pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i] + num_mm7_frames]; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
415 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
416 for (uint i = num_mm6_frames + num_mm7_frames; i < num_mm6_frames + num_mm7_frames + num_mm8_frames; ++i) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
417 pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i] + num_mm6_frames + num_mm7_frames]; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
418 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
419 //for (uint i = 0; i < uNumSpriteFrames; ++i) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1295
diff
changeset
|
420 // pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i]]; |
0 | 421 } |
422 | |
423 //----- (0044DA92) -------------------------------------------------------- | |
424 bool SpriteFrameTable::FromFileTxt(const char *Args) | |
425 { | |
426 SpriteFrameTable *v2; // ebx@1 | |
427 FILE *v3; // eax@1 | |
428 unsigned int v4; // esi@3 | |
429 signed int result; // eax@10 | |
430 FILE *v6; // ST18_4@11 | |
431 char *i; // eax@11 | |
432 const char *v8; // ST20_4@14 | |
433 __int16 v9; // ax@14 | |
434 const char *v10; // ST0C_4@14 | |
435 double v11; // st7@14 | |
436 int v12; // eax@14 | |
437 const char *v13; // ST04_4@14 | |
438 __int16 v14; // ax@14 | |
439 const char *v15; // ST00_4@14 | |
440 int v16; // eax@14 | |
441 int v17; // eax@17 | |
442 int v18; // eax@23 | |
443 int v19; // eax@24 | |
444 int v20; // eax@25 | |
445 int v21; // eax@28 | |
446 int v22; // eax@29 | |
447 int j; // edi@30 | |
448 const char *v24; // esi@31 | |
449 int v25; // eax@32 | |
450 int v26; // edx@53 | |
451 int v27; // ecx@54 | |
452 int v28; // eax@55 | |
453 signed int k; // edx@58 | |
454 SpriteFrame *v30; // ecx@59 | |
455 int v31; // esi@59 | |
456 int l; // eax@60 | |
457 signed int v33; // eax@65 | |
458 int v34; // edi@66 | |
459 int v35; // esi@66 | |
460 SpriteFrame **v36; // eax@69 | |
461 int v37; // ecx@69 | |
462 SpriteFrame *v38; // edx@69 | |
463 __int16 *v39; // eax@69 | |
464 int v40; // ecx@69 | |
465 char Buf[500]; // [sp+Ch] [bp-2F0h]@3 | |
466 FrameTableTxtLine v42; // [sp+200h] [bp-FCh]@4 | |
467 FrameTableTxtLine v43; // [sp+27Ch] [bp-80h]@4 | |
468 FILE *File; // [sp+2F8h] [bp-4h]@1 | |
469 unsigned int Argsa; // [sp+304h] [bp+8h]@3 | |
470 int Argsb; // [sp+304h] [bp+8h]@59 | |
471 FILE *Argsc; // [sp+304h] [bp+8h]@67 | |
472 | |
473 v2 = this; | |
474 ReleaseSFrames(); | |
475 v3 = fopen(Args, "r"); | |
476 File = v3; | |
477 if ( !v3 ) | |
1545 | 478 Error("CSpriteFrameTable::load - Unable to open file: %s.", Args); |
479 | |
0 | 480 v4 = 0; |
481 Argsa = 0; | |
482 if ( fgets(Buf, 490, v3) ) | |
483 { | |
484 do | |
485 { | |
486 *strchr(Buf, '\n') = 0; | |
487 memcpy(&v43, frame_table_txt_parser(Buf, &v42), sizeof(v43)); | |
701 | 488 if ( v43.uPropCount && *v43.pProperties[0] != '/' ) |
0 | 489 ++Argsa; |
490 } | |
491 while ( fgets(Buf, 490, File) ); | |
492 v4 = Argsa; | |
493 } | |
494 v2->uNumSpriteFrames = v4; | |
1583 | 495 v2->pSpriteSFrames = (SpriteFrame *)malloc(60 * v4); |
496 v2->pSpriteEFrames = (__int16 *)malloc(2 * v2->uNumSpriteFrames); | |
497 v2->pSpritePFrames = (SpriteFrame **)malloc(4 * v2->uNumSpriteFrames); | |
0 | 498 if ( v2->pSpriteSFrames ) |
499 { | |
500 v6 = File; | |
501 v2->uNumSpriteFrames = 0; | |
502 fseek(v6, 0, 0); | |
503 for ( i = fgets(Buf, 490, File); i; i = fgets(Buf, 490, File) ) | |
504 { | |
505 *strchr(Buf, 10) = 0; | |
506 memcpy(&v43, frame_table_txt_parser(Buf, &v42), sizeof(v43)); | |
701 | 507 if ( v43.uPropCount && *v43.pProperties[0] != '/' ) |
0 | 508 { |
509 v8 = v43.pProperties[0]; | |
510 v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags = 0; | |
511 v2->pSpriteSFrames[v2->uNumSpriteFrames].uPaletteIndex = 0; | |
512 strcpy(v2->pSpriteSFrames[v2->uNumSpriteFrames].pIconName, v8); | |
513 strcpy(v2->pSpriteSFrames[v2->uNumSpriteFrames].pTextureName, v43.pProperties[1]); | |
514 v9 = atoi(v43.pProperties[3]); | |
515 v10 = v43.pProperties[4]; | |
516 v2->pSpriteSFrames[v2->uNumSpriteFrames].uPaletteID = v9; | |
517 v11 = atof(v10) * 65536.0; | |
518 v12 = abs((signed __int64)v11); | |
519 v13 = v43.pProperties[5]; | |
520 v2->pSpriteSFrames[v2->uNumSpriteFrames].scale = v12; | |
521 v14 = atoi(v13); | |
522 v15 = v43.pProperties[6]; | |
523 v2->pSpriteSFrames[v2->uNumSpriteFrames].uGlowRadius = v14; | |
524 v2->pSpriteSFrames[v2->uNumSpriteFrames].uAnimTime = atoi(v15); | |
525 v16 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames]; | |
526 if ( *(short *)(v16 + 48) ) | |
527 *(int *)(v16 + 44) |= 2u; | |
1104 | 528 if ( !_stricmp(v43.pProperties[2], "new") ) |
0 | 529 { |
530 v17 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
531 *(int *)v17 |= 4u; | |
532 v2->pSpritePFrames[v2->uNumEFrames] = &v2->pSpriteSFrames[v2->uNumSpriteFrames]; | |
533 v2->pSpriteEFrames[v2->uNumEFrames++] = LOWORD(v2->uNumSpriteFrames); | |
534 } | |
1104 | 535 if ( !_stricmp(v43.pProperties[10], "1") ) |
0 | 536 BYTE2(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 4u; |
1104 | 537 if ( !_stricmp(v43.pProperties[11], "1") ) |
0 | 538 BYTE2(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 2u; |
1104 | 539 if ( !_stricmp(v43.pProperties[12], "1") ) |
0 | 540 { |
541 v18 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
542 *(int *)v18 |= 0x20u; | |
543 } | |
544 v19 = atoi(v43.pProperties[7]) - 1; | |
545 if ( v19 ) | |
546 { | |
547 v20 = v19 - 2; | |
548 if ( v20 ) | |
549 { | |
550 if ( v20 == 2 ) | |
551 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0xE0u; | |
552 } | |
553 else | |
554 { | |
555 v21 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
556 *(int *)v21 |= 0x1E000u; | |
557 } | |
558 } | |
559 else | |
560 { | |
561 v22 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
562 *(int *)v22 |= 0x10u; | |
563 } | |
701 | 564 for ( j = 13; j < v43.uPropCount; ++j ) |
0 | 565 { |
566 v24 = v43.pProperties[j]; | |
1104 | 567 if ( _stricmp(v43.pProperties[j], "Luminous") ) |
0 | 568 { |
1104 | 569 if ( _stricmp(v24, "Mirror0") ) |
0 | 570 { |
1104 | 571 if ( _stricmp(v24, "Mirror1") ) |
0 | 572 { |
1104 | 573 if ( _stricmp(v24, "Mirror2") ) |
0 | 574 { |
1104 | 575 if ( _stricmp(v24, "Mirror3") ) |
0 | 576 { |
1104 | 577 if ( _stricmp(v24, "Mirror4") ) |
0 | 578 { |
1104 | 579 if ( _stricmp(v24, "Mirror5") ) |
0 | 580 { |
1104 | 581 if ( _stricmp(v24, "Mirror6") ) |
0 | 582 { |
1104 | 583 if ( !_stricmp(v24, "Mirror7") ) |
0 | 584 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x80u; |
585 } | |
586 else | |
587 { | |
588 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x40u; | |
589 } | |
590 } | |
591 else | |
592 { | |
593 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x20u; | |
594 } | |
595 } | |
596 else | |
597 { | |
598 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 0x10u; | |
599 } | |
600 } | |
601 else | |
602 { | |
603 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 8u; | |
604 } | |
605 } | |
606 else | |
607 { | |
608 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 4u; | |
609 } | |
610 } | |
611 else | |
612 { | |
613 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 2u; | |
614 } | |
615 } | |
616 else | |
617 { | |
618 BYTE1(v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags) |= 1u; | |
619 } | |
620 } | |
621 else | |
622 { | |
623 v25 = (int)&v2->pSpriteSFrames[v2->uNumSpriteFrames].uFlags; | |
624 *(int *)v25 |= 2u; | |
625 } | |
626 } | |
627 ++v2->uNumSpriteFrames; | |
628 } | |
629 } | |
630 fclose(File); | |
631 v26 = 0; | |
632 if ( (signed int)(v2->uNumSpriteFrames - 1) > 0 ) | |
633 { | |
634 v27 = 0; | |
635 do | |
636 { | |
637 v28 = (int)&v2->pSpriteSFrames[v27]; | |
638 if ( !(*(char *)(v28 + 104) & 4) ) | |
639 *(int *)(v28 + 44) |= 1u; | |
640 ++v26; | |
641 ++v27; | |
642 } | |
643 while ( v26 < (signed int)(v2->uNumSpriteFrames - 1) ); | |
644 } | |
645 for ( k = 0; k < (signed int)v2->uNumSpriteFrames; *(short *)(Argsb + 56) = v31 ) | |
646 { | |
647 v30 = v2->pSpriteSFrames; | |
648 Argsb = (int)&v30[k]; | |
649 v31 = *(short *)(Argsb + 54); | |
650 if ( *(char *)(Argsb + 44) & 1 ) | |
651 { | |
652 ++k; | |
653 for ( l = (int)&v30[k]; *(char *)(l + 44) & 1; l += 60 ) | |
654 { | |
655 v31 += *(short *)(l + 54); | |
656 ++k; | |
657 } | |
658 LOWORD(v31) = v30[k].uAnimTime + v31; | |
659 } | |
660 ++k; | |
661 } | |
662 v33 = v2->uNumEFrames; | |
663 if ( v33 > 0 ) | |
664 { | |
665 v34 = 0; | |
666 v35 = 0; | |
667 File = (FILE *)1; | |
668 do | |
669 { | |
670 Argsc = File; | |
671 if ( (signed int)File < v33 ) | |
672 { | |
673 do | |
674 { | |
1104 | 675 if ( _stricmp(v2->pSpritePFrames[(int)Argsc]->pIconName, v2->pSpritePFrames[v35]->pIconName) < 0 ) |
0 | 676 { |
677 v36 = v2->pSpritePFrames; | |
678 v37 = (int)&v36[(int)Argsc]; | |
679 v38 = *(SpriteFrame **)v37; | |
680 *(int *)v37 = (int)v36[v35]; | |
681 v2->pSpritePFrames[v35] = v38; | |
682 v39 = v2->pSpriteEFrames; | |
683 v40 = (int)&v39[(int)Argsc]; | |
684 LOWORD(v38) = *(short *)v40; | |
685 *(short *)v40 = v39[v34]; | |
686 v2->pSpriteEFrames[v34] = (signed __int16)v38; | |
687 } | |
688 Argsc = (FILE *)((char *)Argsc + 1); | |
689 } | |
690 while ( (signed int)Argsc < v2->uNumEFrames ); | |
691 } | |
692 File = (FILE *)((char *)File + 1); | |
693 v33 = v2->uNumEFrames; | |
694 ++v35; | |
695 ++v34; | |
696 } | |
697 while ( (signed int)((char *)File - 1) < v33 ); | |
698 } | |
699 result = 1; | |
700 } | |
701 else | |
702 { | |
703 MessageBoxW(nullptr, L"CSpriteFrameTable::load - Out of Memory!", nullptr, 0); | |
704 fclose(File); | |
705 result = 0; | |
706 } | |
707 return result; | |
1295 | 708 } |
709 //----- (0046E26D) -------------------------------------------------------- | |
710 void __fastcall _46E26D_collide_against_sprites(signed int a1, signed int a2) | |
711 { | |
712 int v2; // edx@5 | |
713 unsigned __int16 *v3; // eax@5 | |
714 unsigned __int16 v4; // ax@6 | |
715 LevelDecoration *v5; // edi@7 | |
716 DecorationDesc *v6; // esi@8 | |
717 int v7; // edx@9 | |
718 int v8; // eax@9 | |
719 int v9; // ecx@11 | |
720 int v10; // ebx@13 | |
721 int v11; // esi@13 | |
722 int v12; // ebp@15 | |
723 int v13; // ebx@15 | |
724 int v14; // esi@16 | |
725 int v15; // edi@17 | |
726 int v16; // eax@17 | |
727 int v17; // esi@19 | |
728 char v18; // zf@23 | |
729 int v19; // [sp+0h] [bp-10h]@15 | |
730 unsigned __int16 *v20; // [sp+4h] [bp-Ch]@5 | |
731 int v21; // [sp+8h] [bp-8h]@15 | |
732 int v22; // [sp+Ch] [bp-4h]@13 | |
733 | |
734 if ( a1 >= 0 ) | |
735 { | |
736 if ( a1 <= 127 ) | |
737 { | |
738 if ( a2 >= 0 ) | |
739 { | |
740 if ( a2 <= 127 ) | |
741 { | |
742 v2 = a1 + (a2 << 7); | |
743 v3 = &pOutdoor->pFaceIDLIST[pOutdoor->pOMAP[v2]]; | |
744 v20 = &pOutdoor->pFaceIDLIST[pOutdoor->pOMAP[v2]]; | |
745 if ( v3 ) | |
746 { | |
747 do | |
748 { | |
749 v4 = *v3; | |
750 if ( PID_TYPE(v4) == OBJECT_Decoration) | |
751 { | |
752 v5 = &pLevelDecorations[(signed __int16)v4 >> 3]; | |
1489 | 753 if (!(v5->uFlags & LEVEL_DECORATION_INVISIBLE)) |
1295 | 754 { |
755 v6 = &pDecorationList->pDecorations[v5->uDecorationDescID]; | |
756 if (!v6->CanMoveThrough()) | |
757 { | |
758 v7 = v6->uRadius; | |
759 v8 = v5->vPosition.x; | |
760 if ( stru_721530.sMaxX <= v8 + v7 ) | |
761 { | |
762 if ( stru_721530.sMinX >= v8 - v7 ) | |
763 { | |
764 v9 = v5->vPosition.y; | |
765 if ( stru_721530.sMaxY <= v9 + v7 ) | |
766 { | |
767 if ( stru_721530.sMinY >= v9 - v7 ) | |
768 { | |
769 v10 = v6->uDecorationHeight; | |
770 v11 = v5->vPosition.z; | |
771 v22 = v10; | |
772 if ( stru_721530.sMaxZ <= v11 + v10 ) | |
773 { | |
774 if ( stru_721530.sMinZ >= v11 ) | |
775 { | |
776 v12 = v8 - stru_721530.normal.x; | |
777 v19 = v9 - stru_721530.normal.y; | |
778 v13 = stru_721530.prolly_normal_d + v7; | |
1546 | 779 v21 = ((v8 - stru_721530.normal.x) * stru_721530.direction.y |
780 - (v9 - stru_721530.normal.y) * stru_721530.direction.x) >> 16; | |
1295 | 781 if ( abs(v21) <= stru_721530.prolly_normal_d + v7 ) |
782 { | |
1546 | 783 v14 = (v12 * stru_721530.direction.x + v19 * stru_721530.direction.y) >> 16; |
1295 | 784 if ( v14 > 0 ) |
785 { | |
786 v15 = v5->vPosition.z; | |
787 v16 = stru_721530.normal.z | |
1546 | 788 + ((unsigned __int64)(stru_721530.direction.z * (signed __int64)v14) >> 16); |
1295 | 789 if ( v16 >= v15 ) |
790 { | |
791 if ( v16 <= v22 + v15 ) | |
792 { | |
793 v17 = v14 - integer_sqrt(v13 * v13 - v21 * v21); | |
794 if ( v17 < 0 ) | |
795 v17 = 0; | |
796 if ( v17 < stru_721530.field_7C ) | |
797 { | |
798 stru_721530.field_7C = v17; | |
799 stru_721530.uFaceID = (signed __int16)*v20; | |
800 } | |
801 } | |
802 } | |
803 } | |
804 } | |
805 } | |
806 } | |
807 } | |
808 } | |
809 } | |
810 } | |
811 } | |
812 } | |
813 } | |
814 v3 = v20 + 1; | |
815 v18 = *v20 == 0; | |
816 ++v20; | |
817 } | |
818 while ( !v18 ); | |
819 } | |
820 } | |
821 } | |
822 } | |
823 } | |
824 } |