Mercurial > mm7
annotate MapInfo.cpp @ 2476:faf21e357a83
mistake in goto cleaning
author | zipi |
---|---|
date | Thu, 21 Aug 2014 21:26:47 +0100 |
parents | 104fdbea0386 |
children | 5abd8fc8f1c6 |
rev | line source |
---|---|
2415 | 1 #define _CRTDBG_MAP_ALLOC |
2 #include <stdlib.h> | |
3 #include <crtdbg.h> | |
4 | |
2259 | 5 #include "MapInfo.h" |
6 #include "LOD.h" | |
7 #include "ErrorHandling.h" | |
8 #include "mm7_data.h" | |
9 #include "texts.h" | |
10 #include "ObjectList.h" | |
11 #include "SpriteObject.h" | |
12 #include "Indoor.h" | |
2464 | 13 |
2259 | 14 |
2463 | 15 #include "Level/Decoration.h" |
16 #include "DecorationList.h" | |
17 #include "Party.h" | |
18 #include "OurMath.h" | |
19 | |
20 | |
2259 | 21 |
22 //----- (00453F62) -------------------------------------------------------- | |
23 void MapStats::Initialize() | |
24 { | |
25 char work_str[32]; // [sp+Ch] [bp-34h]@3 | |
26 int work_str_pos; | |
27 int work_str_len; | |
28 int i; | |
29 char* test_string; | |
30 unsigned char c; | |
31 bool break_loop; | |
32 unsigned int temp_str_len; | |
33 char* tmp_pos; | |
34 int decode_step; | |
2334 | 35 // int item_counter; |
2259 | 36 |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2334
diff
changeset
|
37 free(pMapStatsTXT_Raw); |
2259 | 38 pMapStatsTXT_Raw = (char *)pEvents_LOD->LoadRaw("MapStats.txt", 0); |
39 strtok(pMapStatsTXT_Raw, "\r"); | |
40 strtok(NULL, "\r"); | |
41 strtok(NULL, "\r"); | |
42 | |
43 for (i=1; i<77; ++i) | |
44 { | |
45 test_string = strtok(NULL, "\r") + 1; | |
46 break_loop = false; | |
47 decode_step=0; | |
48 do | |
49 { | |
50 c = *(unsigned char*)test_string; | |
51 temp_str_len = 0; | |
52 while((c!='\t')&&(c>0)) | |
53 { | |
54 ++temp_str_len; | |
55 c=test_string[temp_str_len]; | |
56 } | |
57 tmp_pos=test_string+temp_str_len; | |
58 if (*tmp_pos == 0) | |
59 break_loop = true; | |
60 *tmp_pos = 0; | |
61 if (temp_str_len) | |
62 { | |
63 switch (decode_step) | |
64 { | |
65 case 1: | |
66 pInfos[i].pName = RemoveQuotes(test_string); | |
67 break; | |
68 case 2: | |
69 pInfos[i].pFilename = RemoveQuotes(test_string); | |
70 break; | |
71 case 3: | |
72 pInfos[i].uNumResets = atoi(test_string); | |
73 break; | |
74 case 4: | |
75 pInfos[i].uFirstVisitedAt = atoi(test_string); | |
76 break; | |
77 case 5: | |
78 pInfos[i]._per = atoi(test_string); | |
79 break; | |
80 case 6: | |
81 pInfos[i].uRespawnIntervalDays = atoi(test_string); | |
82 break; | |
83 case 7: | |
84 pInfos[i]._alert_days = atoi(test_string); | |
85 break; | |
86 case 8: | |
87 pInfos[i]._steal_perm = atoi(test_string); | |
88 break; | |
89 case 9: | |
90 pInfos[i].LockX5 = atoi(test_string); | |
91 break; | |
92 case 10: | |
93 pInfos[i].Trap_D20 = atoi(test_string); | |
94 break; | |
95 case 11: | |
96 pInfos[i].Treasure_prob = atoi(test_string); | |
97 break; | |
98 case 12: | |
99 pInfos[i].Encounter_percent = atoi(test_string); | |
100 break; | |
101 case 13: | |
102 pInfos[i].EncM1percent = atoi(test_string); | |
103 break; | |
104 case 14: | |
105 pInfos[i].EncM2percent = atoi(test_string); | |
106 break; | |
107 case 15: | |
108 pInfos[i].EncM3percent = atoi(test_string); | |
109 break; | |
110 case 16: | |
111 pInfos[i].pEncounterMonster1Texture = RemoveQuotes(test_string); | |
112 break; | |
113 case 18: | |
114 pInfos[i].Dif_M1 = atoi(test_string); | |
115 break; | |
116 case 19: | |
117 pInfos[i].uEncounterMonster1AtLeast = 1; | |
118 pInfos[i].uEncounterMonster1AtMost = 1; | |
119 strcpy(work_str, test_string); | |
120 work_str_pos = 0; | |
121 work_str_len=strlen(work_str); | |
122 if (work_str_len ) | |
123 { | |
124 while (work_str[work_str_pos] != '-' ) | |
125 { | |
126 ++work_str_pos; | |
127 if (work_str_pos >= work_str_len ) | |
128 break; | |
129 } | |
130 work_str[work_str_pos] = 0; | |
131 pInfos[i].uEncounterMonster1AtLeast = atoi(work_str); | |
132 if ( work_str_pos < work_str_len ) | |
133 pInfos[i].uEncounterMonster1AtMost = atoi(&work_str[work_str_pos + 1]); | |
134 else | |
135 pInfos[i].uEncounterMonster1AtMost = pInfos[i].uEncounterMonster1AtLeast; | |
136 } | |
137 break; | |
138 case 20: | |
139 pInfos[i].pEncounterMonster2Texture = RemoveQuotes(test_string); | |
140 break; | |
141 case 22: | |
142 pInfos[i].Dif_M2 = atoi(test_string); | |
143 break; | |
144 case 23: | |
145 pInfos[i].uEncounterMonster2AtLeast = 1; | |
146 pInfos[i].uEncounterMonster2AtMost = 1; | |
147 strcpy(work_str, test_string); | |
148 work_str_pos = 0; | |
149 work_str_len=strlen(work_str); | |
150 if (work_str_len ) | |
151 { | |
152 while (work_str[work_str_pos] != '-' ) | |
153 { | |
154 ++work_str_pos; | |
155 if (work_str_pos >= work_str_len ) | |
156 break; | |
157 } | |
158 work_str[work_str_pos] = 0; | |
159 pInfos[i].uEncounterMonster2AtLeast = atoi(work_str); | |
160 if ( work_str_pos < work_str_len ) | |
161 pInfos[i].uEncounterMonster2AtMost = atoi(&work_str[work_str_pos + 1]); | |
162 else | |
163 pInfos[i].uEncounterMonster2AtMost = pInfos[i].uEncounterMonster2AtLeast; | |
164 } | |
165 break; | |
166 case 24: | |
167 pInfos[i].pEncounterMonster3Texture = RemoveQuotes(test_string); | |
168 break; | |
169 case 26: | |
170 pInfos[i].Dif_M3 = atoi(test_string); | |
171 break; | |
172 case 27: | |
173 pInfos[i].uEncounterMonster3AtLeast = 1; | |
174 pInfos[i].uEncounterMonster3AtMost = 1; | |
175 strcpy(work_str, test_string); | |
176 work_str_pos = 0; | |
177 work_str_len=strlen(work_str); | |
178 if (work_str_len ) | |
179 { | |
180 while (work_str[work_str_pos] != '-' ) | |
181 { | |
182 ++work_str_pos; | |
183 if (work_str_pos >= work_str_len ) | |
184 break; | |
185 } | |
186 work_str[work_str_pos] = 0; | |
187 pInfos[i].uEncounterMonster3AtLeast = atoi(work_str); | |
188 if ( work_str_pos < work_str_len ) | |
189 pInfos[i].uEncounterMonster3AtMost = atoi(&work_str[work_str_pos + 1]); | |
190 else | |
191 pInfos[i].uEncounterMonster3AtMost = pInfos[i].uEncounterMonster3AtLeast; | |
192 } | |
193 break; | |
194 case 28: | |
195 pInfos[i].uRedbookTrackID = atoi(test_string); | |
196 break; | |
197 case 29: | |
198 { | |
199 if ( !strcmp(test_string, "CAVE") ) | |
200 { | |
201 pInfos[i].uEAXEnv = 8; | |
202 break; | |
203 } | |
204 if ( !strcmp(test_string, "STONEROOM") ) | |
205 { | |
206 pInfos[i].uEAXEnv = 5; | |
207 break; | |
208 } | |
209 if ( !strcmp(test_string, "MOUNTAINS") ) | |
210 { | |
211 pInfos[i].uEAXEnv = 17; | |
212 break; | |
213 } | |
214 if ( !strcmp(test_string, "PLAIN") ) | |
215 { | |
216 pInfos[i].uEAXEnv = 19; | |
217 break; | |
218 } | |
219 if ( !strcmp(test_string, "FOREST") ) | |
220 { | |
221 pInfos[i].uEAXEnv = 15; | |
222 break; | |
223 } | |
224 if ( !strcmp(test_string, "CITY") ) | |
225 { | |
226 pInfos[i].uEAXEnv = 16; | |
227 break; | |
228 } | |
229 if ( !strcmp(test_string, "UNDERWATER") ) | |
230 { | |
231 pInfos[i].uEAXEnv = 22; | |
232 break; | |
233 } | |
234 if ( !strcmp(test_string, "ARENA") ) | |
235 { | |
236 pInfos[i].uEAXEnv = 9; | |
237 break; | |
238 } | |
239 if ( !strcmp(test_string, "GENERIC") ) | |
240 { | |
241 pInfos[i].uEAXEnv = 0; | |
242 break; | |
243 } | |
244 if ( !strcmp(test_string, "PADDEDCELL") ) | |
245 { | |
246 pInfos[i].uEAXEnv = 1; | |
247 break; | |
248 } | |
249 if ( !strcmp(test_string, "ROOM") ) | |
250 { | |
251 pInfos[i].uEAXEnv = 2; | |
252 break; | |
253 } | |
254 if ( !strcmp(test_string, "BATHROOM") ) | |
255 { | |
256 pInfos[i].uEAXEnv = 3; | |
257 break; | |
258 } | |
259 if ( !strcmp(test_string, "LIVINGROOM") ) | |
260 { | |
261 pInfos[i].uEAXEnv = 4; | |
262 break; | |
263 } | |
264 if ( !strcmp(test_string, "AUDITORIUM") ) | |
265 { | |
266 pInfos[i].uEAXEnv = 6; | |
267 break; | |
268 } | |
269 if ( !strcmp(test_string, "CONCERTHALL") ) | |
270 { | |
271 pInfos[i].uEAXEnv = 7; | |
272 break; | |
273 } | |
274 if ( !strcmp(test_string, "HANGAR") ) | |
275 { | |
276 pInfos[i].uEAXEnv = 10; | |
277 break; | |
278 } | |
279 if ( !strcmp(test_string, "CARPETEDHALLWAY") ) | |
280 { | |
281 pInfos[i].uEAXEnv = 11; | |
282 break; | |
283 } | |
284 if ( !strcmp(test_string, "HALLWAY") ) | |
285 { | |
286 pInfos[i].uEAXEnv = 12; | |
287 break; | |
288 } | |
289 if ( !strcmp(test_string, "STONECORRIDOR") ) | |
290 { | |
291 pInfos[i].uEAXEnv = 13; | |
292 break; | |
293 } | |
294 if ( !strcmp(test_string, "ALLEY") ) | |
295 { | |
296 pInfos[i].uEAXEnv = 14; | |
297 break; | |
298 } | |
299 if ( !strcmp(test_string, "QUARRY") ) | |
300 { | |
301 pInfos[i].uEAXEnv = 18; | |
302 break; | |
303 } | |
304 if ( !strcmp(test_string, "PARKINGLOT") ) | |
305 { | |
306 pInfos[i].uEAXEnv = 20; | |
307 break; | |
308 } | |
309 if ( !strcmp(test_string, "SEWERPIPE") ) | |
310 { | |
311 pInfos[i].uEAXEnv = 21; | |
312 break; | |
313 } | |
314 if ( !strcmp(test_string, "DRUGGED") ) | |
315 { | |
316 pInfos[i].uEAXEnv = 23; | |
317 break; | |
318 } | |
319 if ( !strcmp(test_string, "DIZZY") ) | |
320 { | |
321 pInfos[i].uEAXEnv = 24; | |
322 break; | |
323 } | |
324 if ( !strcmp(test_string, "PSYCHOTIC") ) | |
325 { | |
326 pInfos[i].uEAXEnv = 25; | |
327 break; | |
328 } | |
329 pInfos[i].uEAXEnv = 26; | |
330 | |
331 } | |
332 break; | |
333 } | |
334 } | |
335 else | |
336 { | |
337 break_loop = true; | |
338 } | |
339 ++decode_step; | |
340 test_string=tmp_pos+1; | |
341 } while ((decode_step<31)&&!break_loop); | |
342 } | |
343 | |
344 uNumMaps = 77; | |
345 } | |
346 // 453F62: using guessed type char Str[32]; | |
347 | |
348 //----- (00410D99) -------------------------------------------------------- | |
349 int MapStats::sub_410D99_get_map_index(int a1) | |
350 { | |
351 for (int i = 1; i <= pMapStats->uNumMaps; i++) | |
352 { | |
353 if (_stricmp(pMapStats->pInfos[i].pFilename, pGames_LOD->pSubIndices[a1].pFilename) ) | |
354 return i; | |
355 } | |
356 Error("Map not found"); | |
357 return -1; | |
358 } | |
359 | |
360 //----- (004547A3) -------------------------------------------------------- | |
361 MAP_TYPE MapStats::GetMapInfo(const char *Str2) | |
362 { | |
363 Assert(uNumMaps >= 2); | |
364 | |
365 for (uint i = 1; i < uNumMaps; ++i) | |
366 if (!_stricmp(pInfos[i].pFilename, Str2)) | |
367 return (MAP_TYPE)i; | |
368 | |
369 Error("Map not found!"); | |
370 return (MAP_TYPE)-1; | |
371 } | |
372 | |
373 | |
374 //----- (0044FFD8) -------------------------------------------------------- | |
375 int MapInfo::SpawnRandomTreasure(SpawnPointMM7 *a2) | |
376 { | |
377 //MapInfo *v2; // ebx@1 | |
378 //SpawnPointMM7 *v3; // esi@1 | |
379 //int v4; // eax@1 | |
380 int v5; // edx@1 | |
2334 | 381 // int v6; // eax@1 |
2259 | 382 int v7; // ecx@1 |
383 int v8; // ebx@1 | |
384 int v9; // eax@1 | |
385 signed int v10; // ebx@1 | |
386 signed int result; // eax@1 | |
387 signed __int64 v12; // qtt@1 | |
388 int v13; // ebx@1 | |
389 int v14; // edx@10 | |
390 signed int v15; // ebx@20 | |
391 unsigned __int16 v16; // dx@20 | |
2334 | 392 // ObjectDesc *v17; // ecx@21 |
2259 | 393 unsigned __int16 v18; // ax@24 |
394 int v19; // ST0C_4@27 | |
395 int v20; // ST08_4@27 | |
396 int v21; // ST04_4@27 | |
397 int v22; // eax@27 | |
398 signed int v23; // ebx@29 | |
399 unsigned __int16 v24; // dx@29 | |
2334 | 400 // ObjectDesc *v25; // ecx@30 |
2259 | 401 unsigned __int16 v26; // ax@33 |
402 //int v27; // ecx@35 | |
403 //int v28; // eax@35 | |
404 //int v29; // esi@35 | |
405 //__int16 v30; // ax@35 | |
406 SpriteObject a1a; // [sp+Ch] [bp-7Ch]@1 | |
407 //int v32; // [sp+7Ch] [bp-Ch]@1 | |
408 //int v33; // [sp+80h] [bp-8h]@1 | |
409 int v34; // [sp+84h] [bp-4h]@1 | |
410 | |
411 //auto a1 = this; | |
412 //v2 = a1; | |
413 //v3 = a2; | |
414 //v4 = rand(); | |
415 v34 = 0; | |
416 v5 = rand() % 100; | |
417 // v6 = 2 * (v2->Treasure_prob + 7 * v3->uIndex) - 14; | |
418 v7 = (unsigned __int8)byte_4E8168[a2->uIndex - 1][2 * Treasure_prob]; | |
419 v8 = (unsigned __int8)byte_4E8168[a2->uIndex - 1][2 * Treasure_prob + 1]; | |
420 //v32 = v5; | |
421 //v33 = v7; | |
422 v9 = rand(); | |
423 v10 = v8 - v7 + 1; | |
424 v12 = v9; | |
425 result = v9 / v10; | |
426 v13 = v7 + (unsigned __int64)(v12 % v10); | |
427 if ( v13 < 7 ) | |
428 { | |
429 if ( v5 < 20 ) | |
430 return result; | |
431 if ( v5 >= 60 ) | |
432 { | |
433 v19 = a2->vPosition.z; | |
434 v20 = a2->vPosition.y; | |
435 v21 = a2->vPosition.x; | |
436 v22 = rand(); | |
437 return sub_450521_ProllyDropItemAt(v13, v22 % 27 + 20, v21, v20, v19, 0); | |
438 } | |
439 if ( a2->uIndex == 1 ) | |
440 { | |
441 v14 = rand() % 51 + 50; | |
442 a1a.stru_24.uItemID = 197; | |
443 v34 = v14; | |
444 } | |
445 else if ( a2->uIndex == 2 ) | |
446 { | |
447 v14 = rand() % 101 + 100; | |
448 a1a.stru_24.uItemID = 197; | |
449 v34 = v14; | |
450 } | |
451 else if ( a2->uIndex == 3 ) | |
452 { | |
453 v14 = rand() % 301 + 200; | |
454 a1a.stru_24.uItemID = 198; | |
455 v34 = v14; | |
456 } | |
457 else if ( a2->uIndex == 4 ) | |
458 { | |
459 v14 = rand() % 501 + 500; | |
460 a1a.stru_24.uItemID = 198; | |
461 v34 = v14; | |
462 } | |
463 else if ( a2->uIndex == 5 ) | |
464 { | |
465 v14 = rand() % 1001 + 1000; | |
466 a1a.stru_24.uItemID = 199; | |
467 v34 = v14; | |
468 } | |
469 else if ( a2->uIndex == 6 ) | |
470 { | |
471 v14 = rand() % 3001 + 2000; | |
472 a1a.stru_24.uItemID = 199; | |
473 v34 = v14; | |
474 } | |
475 v15 = 0; | |
476 v16 = pItemsTable->pItems[a1a.stru_24.uItemID].uSpriteID; | |
477 a1a.uType = pItemsTable->pItems[a1a.stru_24.uItemID].uSpriteID; | |
478 v18 = 0; | |
479 for( int i = 0; i < pObjectList->uNumObjects; i++ ) | |
480 { | |
481 if ( pObjectList->pObjects[i].uObjectID == v16 ) | |
482 { | |
483 v18 = i; | |
484 break; | |
485 } | |
486 } | |
487 a1a.stru_24.SetIdentified(); | |
488 a1a.uObjectDescID = v18; | |
489 a1a.stru_24.uSpecEnchantmentType = v34; | |
490 } | |
491 else | |
492 { | |
493 result = a1a.stru_24.GenerateArtifact(); | |
494 if ( !result ) | |
495 return result; | |
496 v23 = 0; | |
497 v24 = pItemsTable->pItems[a1a.stru_24.uItemID].uSpriteID; | |
498 a1a.uType = pItemsTable->pItems[a1a.stru_24.uItemID].uSpriteID; | |
499 v26 = 0; | |
500 for( int i = 0; i < pObjectList->uNumObjects; i++ ) | |
501 { | |
502 if( v24 == pObjectList->pObjects[i].uObjectID ) | |
503 { | |
504 v26 = i; | |
505 break; | |
506 } | |
507 } | |
508 a1a.uObjectDescID = v26; | |
509 a1a.stru_24.Reset(); | |
510 } | |
511 a1a.vPosition.y = a2->vPosition.y; | |
512 a1a.uAttributes = 0; | |
513 a1a.uSoundID = 0; | |
514 a1a.uFacing = 0; | |
515 a1a.vPosition.z = a2->vPosition.z; | |
516 a1a.vPosition.x = a2->vPosition.x; | |
517 a1a.spell_skill = 0; | |
518 a1a.spell_level = 0; | |
519 a1a.spell_id = 0; | |
520 a1a.spell_target_pid = 0; | |
521 a1a.spell_caster_pid = 0; | |
522 a1a.uSpriteFrameID = 0; | |
523 a1a.uSectorID = pIndoor->GetSector(a2->vPosition.x, a2->vPosition.y, a2->vPosition.z);; | |
524 return a1a.Create(0, 0, 0, 0); | |
525 } | |
526 | |
2463 | 527 //----- (004498D5) -------------------------------------------------------- |
528 void TeleportToStartingPoint(MapStartPoint point) | |
529 { | |
530 const char *model_name; // [sp-4h] [bp-84h]@6 | |
531 char pName[128]; // [sp+8h] [bp-78h]@11 | |
532 | |
533 switch (point) | |
534 { | |
535 case MapStartPoint_Party: model_name = "Party Start"; break; | |
536 case MapStartPoint_North: model_name = "North Start"; break; | |
537 case MapStartPoint_South: model_name = "South Start"; break; | |
538 case MapStartPoint_East: model_name = "East Start"; break; | |
539 case MapStartPoint_West: model_name = "West Start"; break; | |
540 default: | |
541 Error("Invalid enum value: %u", point); | |
542 } | |
543 | |
544 strcpy(pName, model_name); | |
545 if (pDecorationList->GetDecorIdByName(pName)) | |
546 { | |
547 | |
548 if ((signed int)uNumLevelDecorations > 0) | |
549 { | |
550 for (uint i = 0; i < (signed int)uNumLevelDecorations; ++i) | |
551 { | |
552 if (pLevelDecorations[i].uDecorationDescID == (signed __int16)pDecorationList->GetDecorIdByName(pName)) | |
553 { | |
554 pParty->vPosition.x = pLevelDecorations[i].vPosition.x; | |
555 pParty->vPosition.y = pLevelDecorations[i].vPosition.y; | |
556 pParty->vPosition.z = pLevelDecorations[i].vPosition.z; | |
557 pParty->uFallStartY = pParty->vPosition.z; | |
558 pParty->sRotationY = (signed int)(stru_5C6E00->uIntegerHalfPi * pLevelDecorations[i].field_1A) / 90; | |
559 if (pLevelDecorations[i].field_10_y_rot) | |
560 pParty->sRotationY = pLevelDecorations[i].field_10_y_rot; | |
561 pParty->sRotationX = 0; | |
562 pParty->uFallSpeed = 0; | |
563 } | |
564 } | |
565 } | |
566 if (dword_5B65C0) | |
567 { | |
568 if (_5B65A8_npcdata_uflags_or_other) | |
569 pParty->vPosition.x = _5B65A8_npcdata_uflags_or_other; | |
570 if (_5B65AC_npcdata_fame_or_other) | |
571 pParty->vPosition.y = _5B65AC_npcdata_fame_or_other; | |
572 if (_5B65B0_npcdata_rep_or_other) | |
573 { | |
574 pParty->vPosition.z = _5B65B0_npcdata_rep_or_other; | |
575 pParty->uFallStartY = _5B65B0_npcdata_rep_or_other; | |
576 } | |
577 if (_5B65B4_npcdata_loword_house_or_other != -1) | |
578 pParty->sRotationY = _5B65B4_npcdata_loword_house_or_other; | |
579 if (_5B65B8_npcdata_hiword_house_or_other) | |
580 pParty->sRotationX = _5B65B8_npcdata_hiword_house_or_other; | |
581 if (dword_5B65BC) | |
582 pParty->uFallSpeed = dword_5B65BC; | |
583 } | |
584 _5B65B4_npcdata_loword_house_or_other = -1; | |
585 dword_5B65C0 = 0; | |
586 dword_5B65BC = 0; | |
587 _5B65B8_npcdata_hiword_house_or_other = 0; | |
588 _5B65B0_npcdata_rep_or_other = 0; | |
589 _5B65AC_npcdata_fame_or_other = 0; | |
590 _5B65A8_npcdata_uflags_or_other = 0; | |
591 } | |
592 } |