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