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