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