comparison NPC.cpp @ 251:48f21f569328

Npc related stuff separated
author Gloval
date Mon, 18 Feb 2013 08:47:21 +0400
parents
children f1218b9d67f1
comparison
equal deleted inserted replaced
247:fb8a876f41e1 251:48f21f569328
1 #include <string.h>
2 #include <stdlib.h>
3
4 #include "Allocator.h"
5 #include "texts.h"
6 #include "Party.h"
7 #include "LOD.h"
8 #include "Autonotes.h"
9 #include "Awards.h"
10 #include "mm7_data.h"
11 #include "MM7.h"
12 #include "NPC.h"
13
14
15 void InitializeAwards();
16 void InitializeScrolls();
17 void InitializeMerchants();
18 void InitializeTransitions();
19 void InitializeAutonotes();
20 void InitializeQuests();
21
22
23 //----- (00476977) --------------------------------------------------------
24 void NPCStats::Initialize2()
25 {
26 int i;
27 char* test_string;
28 unsigned char c;
29 bool break_loop;
30 unsigned int temp_str_len;
31 char* tmp_pos;
32 int decode_step;
33
34 if (pNPCTextTXT_Raw)
35 pAllocator->FreeChunk(pNPCTextTXT_Raw);
36 pNPCTextTXT_Raw =NULL;
37 pNPCTextTXT_Raw = (char *)pEvents_LOD->LoadRaw("npctext.txt", 0);
38 strtok(pNPCTextTXT_Raw, "\r");
39
40 for (i=0; i<789; ++i)
41 {
42 test_string = strtok(NULL, "\r") + 1;
43 break_loop = false;
44 decode_step=0;
45 do
46 {
47 c = *(unsigned char*)test_string;
48 temp_str_len = 0;
49 while((c!='\t')&&(c>0))
50 {
51 ++temp_str_len;
52 c=test_string[temp_str_len];
53 }
54 tmp_pos=test_string+temp_str_len;
55 if (*tmp_pos == 0)
56 break_loop = true;
57 *tmp_pos = 0;
58 if (temp_str_len)
59 {
60 if ( decode_step == 1)
61 pNPCTopics[i].pText =RemoveQuotes(test_string);
62 }
63 else
64 {
65 break_loop = true;
66 }
67 ++decode_step;
68 test_string=tmp_pos+1;
69 } while ((decode_step<2)&&!break_loop);
70 }
71
72 if (pNPCTopicTXT_Raw)
73 pAllocator->FreeChunk(pNPCTopicTXT_Raw);
74 pNPCTopicTXT_Raw =NULL;
75 pNPCTopicTXT_Raw = (char *)pEvents_LOD->LoadRaw("npctopic.txt", 0);
76 strtok(pNPCTopicTXT_Raw, "\r");
77
78 for (i=0; i<579; ++i)
79 {
80 test_string = strtok(NULL, "\r") + 1;
81 break_loop = false;
82 decode_step=0;
83 do
84 {
85 c = *(unsigned char*)test_string;
86 temp_str_len = 0;
87 while((c!='\t')&&(c>0))
88 {
89 ++temp_str_len;
90 c=test_string[temp_str_len];
91 }
92 tmp_pos=test_string+temp_str_len;
93 if (*tmp_pos == 0)
94 break_loop = true;
95 *tmp_pos = 0;
96 if (temp_str_len)
97 {
98 if ( decode_step == 1)
99 pNPCTopics[i].pTopic = RemoveQuotes(test_string);
100 }
101 else
102 {
103 break_loop = true;
104 }
105 ++decode_step;
106 test_string=tmp_pos+1;
107 } while ((decode_step<2)&&!break_loop);
108 }
109
110 if (pNPCDistTXT_Raw)
111 pAllocator->FreeChunk(pNPCDistTXT_Raw);
112 pNPCDistTXT_Raw = NULL;
113 pNPCDistTXT_Raw = (char *)pEvents_LOD->LoadRaw("npcdist.txt", 0);
114 strtok(pNPCDistTXT_Raw, "\r");
115 strtok(NULL, "\r");
116
117 for (i=1; i<59; ++i)
118 {
119 test_string = strtok(NULL, "\r") + 1;
120 break_loop = false;
121 decode_step=0;
122 do
123 {
124 c = *(unsigned char*)test_string;
125 temp_str_len = 0;
126 while((c!='\t')&&(c>0))
127 {
128 ++temp_str_len;
129 c=test_string[temp_str_len];
130 }
131 tmp_pos=test_string+temp_str_len;
132 if (*tmp_pos == 0)
133 break_loop = true;
134 *tmp_pos = 0;
135 if (temp_str_len)
136 {
137 if ((decode_step>0)&&(decode_step<77))
138 {
139 array_16544[decode_step].field_4[i]=atoi(test_string);
140 }
141 else if (decode_step==0)
142 {
143 array_16544[0].field_4[i]=10;
144 }
145 }
146 else
147 {
148 break_loop = true;
149 }
150 ++decode_step;
151 test_string=tmp_pos+1;
152 } while ((decode_step<78)&&!break_loop);
153 }
154
155 for (i=0; i<78; ++i)
156 {
157 array_16544[i].field_0=0;
158 for (int ii=1; ii<59; ++ii)
159 {
160 array_16544[i].field_0+=array_16544[i].field_4[ii];
161 }
162 }
163
164 if (pNPCDistTXT_Raw)
165 {
166 pAllocator->FreeChunk(pNPCDistTXT_Raw);
167 pNPCDistTXT_Raw = NULL;
168 }
169 }
170
171 //----- (00476C60) --------------------------------------------------------
172 void NPCStats::_476C60()
173 {
174 for (unsigned int i = 1; i < uNumNewNPCs; ++i)
175 pNewNPCData[i].pName = pNPCNames2[i - 1];
176
177 if (pParty->pHirelings[0].pName)
178 pParty->pHirelings[0].pName = pParty->pHireling1Name;
179 if (pParty->pHirelings[1].pName)
180 pParty->pHirelings[1].pName = pParty->pHireling2Name;
181 }
182
183 //----- (00476CB5) --------------------------------------------------------
184 void NPCStats::Initialize1()
185 {
186 NPCStats *pNPCStats; // esi@1
187 char *pRaw; // eax@1
188 char *pHouse; // edi@1
189 char *v4; // eax@2
190 char v5; // dl@3
191 int v6; // ecx@3
192 char *v7; // eax@11
193 char *v8; // eax@26
194 char *v9; // ecx@27
195 char v10; // dl@28
196 int v11; // eax@28
197 int v12; // edi@32
198 char *v13; // eax@42
199 char *v14; // eax@43
200 char v15; // dl@44
201 int v16; // ecx@44
202 int v17; // edi@48
203 char *v18; // eax@56
204 char *v19; // eax@57
205 char v20; // cl@58
206 int v21; // edi@58
207 int v22; // esi@62
208 int v23; // [sp+Ch] [bp-14h]@7
209 signed int v24; // [sp+10h] [bp-10h]@1
210 signed int v25; // [sp+10h] [bp-10h]@26
211 signed int v26; // [sp+10h] [bp-10h]@42
212 signed int v27; // [sp+10h] [bp-10h]@56
213 char *Str; // [sp+14h] [bp-Ch]@1
214 NPCGreeting *pGreetings; // [sp+14h] [bp-Ch]@26
215 unsigned __int16 *pGroups; // [sp+14h] [bp-Ch]@42
216 char **pCatchPhrase; // [sp+14h] [bp-Ch]@56
217 signed int v32; // [sp+18h] [bp-8h]@2
218 signed int v33; // [sp+18h] [bp-8h]@27
219 signed int v34; // [sp+18h] [bp-8h]@43
220 signed int v35; // [sp+18h] [bp-8h]@57
221 signed int v36; // [sp+1Ch] [bp-4h]@2
222 signed int v37; // [sp+1Ch] [bp-4h]@27
223 signed int v38; // [sp+1Ch] [bp-4h]@43
224 signed int v39; // [sp+1Ch] [bp-4h]@57
225
226 pNPCStats = this;
227 pRaw = (char *)pEvents_LOD->LoadRaw("npcdata.txt", 0);
228 pNPCStats->pNPCDataTXT_Raw = pRaw;
229 strtok(pRaw, "\r");
230 strtok(0, "\r");
231 pHouse = (char *)&pNPCStats->pNPCData[1].house;
232 Str = (char *)pNPCStats->pNPCNames2;
233 v24 = 500;
234 do
235 {
236 v32 = 0;
237 v4 = strtok(0, "\r") + 1;
238 v36 = -1;
239 do
240 {
241 v5 = *v4;
242 v6 = 0;
243 while ( v5 != 9 && v5 )
244 {
245 ++v6;
246 v5 = v4[v6];
247 }
248 v23 = (int)&v4[v6];
249 if ( !v4[v6] )
250 v32 = 1;
251 v4[v6] = 0;
252 if ( v6 )
253 {
254 switch ( v36 )
255 {
256 case 0:
257 v7 = RemoveQuotes(v4);
258 *((int *)pHouse - 5) = (int)v7;
259 *(int *)Str = (int)v7;
260 break;
261 case 1:
262 *((int *)pHouse - 4) = atoi(v4);
263 break;
264 case 5:
265 *(int *)pHouse = atoi(v4);
266 break;
267 case 6:
268 *((int *)pHouse + 1) = atoi(v4);
269 break;
270 case 7:
271 *((int *)pHouse + 2) = atoi(v4);
272 break;
273 case 8:
274 *((int *)pHouse + 3) = *v4 == 121;
275 break;
276 case 9:
277 *((int *)pHouse + 5) = atoi(v4);
278 break;
279 case 10:
280 *((int *)pHouse + 6) = atoi(v4);
281 break;
282 case 11:
283 *((int *)pHouse + 7) = atoi(v4);
284 break;
285 case 12:
286 *((int *)pHouse + 8) = atoi(v4);
287 break;
288 case 13:
289 *((int *)pHouse + 9) = atoi(v4);
290 break;
291 case 14:
292 *((int *)pHouse + 10) = atoi(v4);
293 break;
294 default:
295 break;
296 }
297 }
298 ++v36;
299 v4 = (char *)(v23 + 1);
300 }
301 while ( v36 + 1 <= 15 && !v32 );
302 Str += 4;
303 pHouse += 76;
304 --v24;
305 }
306 while ( v24 );
307 pNPCStats->uNumNewNPCs = 501;
308 v8 = (char *)pEvents_LOD->LoadRaw("npcgreet.txt", 0);
309 pNPCStats->pNPCGreetTXT_Raw = v8;
310 strtok(v8, "\r");
311 pGreetings = pNPCStats->pNPCGreetings;
312 v25 = 205;
313 do
314 {
315 v37 = 0;
316 v33 = 0;
317 v9 = strtok(0, "\r") + 1;
318 do
319 {
320 v10 = *v9;
321 v11 = 0;
322 while ( v10 != 9 && v10 )
323 {
324 ++v11;
325 v10 = v9[v11];
326 }
327 v12 = (int)&v9[v11];
328 if ( !v9[v11] )
329 v33 = 1;
330 *(char *)v12 = 0;
331 if ( v11 )
332 {
333 if ( v37 == 1 )
334 {
335 pGreetings->pGreeting1 = (char *)RemoveQuotes(v9);
336 }
337 else
338 {
339 if ( v37 == 2 )
340 pGreetings->pGreeting2 = (char *)RemoveQuotes(v9);
341 }
342 }
343 ++v37;
344 v9 = (char *)(v12 + 1);
345 }
346 while ( v37 <= 2 && !v33 );
347 ++pGreetings;
348 --v25;
349 }
350 while ( v25 );
351 v13 = (char *)pEvents_LOD->LoadRaw("npcgroup.txt", 0);
352 pNPCStats->pNCPGroupTXT_Raw = v13;
353 strtok(v13, "\r");
354 pGroups = pNPCStats->pGroups;
355 v26 = 51;
356 do
357 {
358 v14 = strtok(0, "\r") + 1;
359 v38 = 0;
360 v34 = 0;
361 do
362 {
363 v15 = *v14;
364 v16 = 0;
365 while ( v15 != 9 && v15 )
366 {
367 ++v16;
368 v15 = v14[v16];
369 }
370 v17 = (int)&v14[v16];
371 if ( !v14[v16] )
372 v34 = 1;
373 *(char *)v17 = 0;
374 if ( v16 && v38 == 1 )
375 *pGroups = atoi(v14);
376 ++v38;
377 v14 = (char *)(v17 + 1);
378 }
379 while ( v38 <= 1 && !v34 );
380 ++pGroups;
381 --v26;
382 }
383 while ( v26 );
384 v18 = (char *)pEvents_LOD->LoadRaw("npcnews.txt", 0);
385 pNPCStats->pNPCNewsTXT_Raw = v18;
386 strtok(v18, "\r");
387 pCatchPhrase = pNPCStats->pCatchPhrases;
388 v27 = 51;
389 do
390 {
391 v19 = strtok(0, "\r") + 1;
392 v39 = 0;
393 v35 = 0;
394 do
395 {
396 v20 = *v19;
397 v21 = 0;
398 while ( v20 != 9 && v20 )
399 {
400 ++v21;
401 v20 = v19[v21];
402 }
403 v22 = (int)&v19[v21];
404 if ( !v19[v21] )
405 v35 = 1;
406 *(char *)v22 = 0;
407 if ( v21 && v39 == 1 )
408 *pCatchPhrase = (char *)RemoveQuotes(v19);
409 ++v39;
410 v19 = (char *)(v22 + 1);
411 }
412 while ( v39 <= 1 && !v35 );
413 ++pCatchPhrase;
414 --v27;
415 }
416 while ( v27 );
417 }
418
419 //----- (0047702F) --------------------------------------------------------
420 void NPCStats::Initialize()
421 {
422 //NPCStats *v1; // edi@1
423 char *v2; // ebx@1
424 //char *v3; // eax@1
425 char *v4; // ebx@3
426 char v5; // al@4
427 int v6; // ecx@4
428 //char *v7; // eax@18
429 char *v8; // ebx@18
430 char *v9; // ecx@19
431 char v10; // dl@20
432 int v11; // eax@20
433 char v12; // zf@41
434 signed int v13; // [sp+Ch] [bp-14h]@18
435 int v14; // [sp+10h] [bp-10h]@4
436 int v15; // [sp+10h] [bp-10h]@24
437 char *v16; // [sp+14h] [bp-Ch]@1
438 signed int v17; // [sp+14h] [bp-Ch]@19
439 unsigned int v18; // [sp+18h] [bp-8h]@1
440 char *v19; // [sp+18h] [bp-8h]@18
441 signed int v20; // [sp+1Ch] [bp-4h]@3
442 signed int v21; // [sp+1Ch] [bp-4h]@19
443 //v1 = this;
444
445 Initialize1();
446 Initialize2();
447
448 InitializeQuests();
449 InitializeAutonotes();
450 InitializeAwards();
451 InitializeTransitions();
452 InitializeMerchants();
453 InitializeScrolls();
454 v2 = 0;
455 field_17FC0 = 0;
456 pNPCNamesTXT_Raw = 0;
457 //v3 = (char *)pEvents_LOD->LoadRaw("npcnames.txt", 0);
458 pNPCNamesTXT_Raw = (char *)pEvents_LOD->LoadRaw("npcnames.txt", 0);
459 strtok(pNPCNamesTXT_Raw, "\r");
460 v18 = 0;
461 v16 = (char *)pNPCNames;
462 while ( 1 )
463 {
464 v4 = strtok(v2, "\r") + 1;
465 v20 = 0;
466 do
467 {
468 v5 = *v4;
469 v6 = 0;
470 v14 = 0;
471 if ( *v4 == 9 )
472 goto LABEL_45;
473 do
474 {
475 if ( !v5 )
476 break;
477 if ( v5 == 10 )
478 break;
479 ++v6;
480 v14 = v6;
481 v5 = v4[v6];
482 }
483 while ( v5 != 9 );
484 if ( v6 )
485 {
486 v4[v6] = 0;
487 if ( v20 )
488 {
489 if ( v20 == 1 )
490 *((int *)v16 + 1) = (int)RemoveQuotes(v4);
491 }
492 else
493 {
494 *(int *)v16 = (int)RemoveQuotes(v4);
495 }
496 }
497 else
498 {
499 LABEL_45:
500 if ( v20 == 1 && !uNumNPCNames[1] )
501 uNumNPCNames[1] = v18;
502 }
503 ++v20;
504 v4 += v14 + 1;
505 }
506 while ( v20 <= 1 );
507 ++v18;
508 v16 += 8;
509 if ( (signed int)v18 >= 540 )
510 break;
511 v2 = 0;
512 }
513 pNPCProfTXT_Raw = 0;
514 uNumNPCNames[0] = v18;
515 //v7 = (char *)pEvents_LOD->LoadRaw("npcprof.txt", 0);
516 pNPCProfTXT_Raw = (char *)pEvents_LOD->LoadRaw("npcprof.txt", 0);
517 strtok(pNPCProfTXT_Raw, "\r");
518 strtok(0, "\r");
519 strtok(0, "\r");
520 strtok(0, "\r");
521 v8 = (char *)&pProfessions[0].pJoinText;
522 v19 = (char *)&pProfessions[0].pJoinText;
523 v13 = 58;
524 do
525 {
526 v21 = 0;
527 v9 = strtok(0, "\r") + 1;
528 v17 = 0;
529 do
530 {
531 v10 = *v9;
532 v11 = 0;
533 if ( *v9 != 9 )
534 {
535 do
536 {
537 if ( !v10 )
538 break;
539 ++v11;
540 v10 = v9[v11];
541 }
542 while ( v10 != 9 );
543 v8 = v19;
544 }
545 v15 = (int)&v9[v11];
546 if ( !v9[v11] )
547 v17 = 1;
548 *(char *)v15 = 0;
549 if ( v11 )
550 {
551 switch ( v21 )
552 {
553 case 2:
554 *((int *)v8 - 3) = atoi(v9);
555 break;
556 case 3:
557 *((int *)v8 - 1) = (int)RemoveQuotes(v9);
558 break;
559 case 4:
560 *((int *)v8 - 2) = (int)RemoveQuotes(v9);
561 break;
562 case 5:
563 *(int *)v8 = (int)RemoveQuotes(v9);
564 break;
565 case 6:
566 *((int *)v8 + 1) = (int)RemoveQuotes(v9);
567 break;
568 }
569 }
570 else
571 {
572 if ( !v21 )
573 v17 = 1;
574 }
575 ++v21;
576 v9 = (char *)(v15 + 1);
577 }
578 while ( v21 <= 6 && !v17 );
579 v8 += 20;
580 v12 = v13-- == 1;
581 v19 = v8;
582 }
583 while ( !v12 );
584 uNumNPCProfessions = 59;
585 }
586
587 //----- (00477266) --------------------------------------------------------
588 void NPCStats::Release()
589 {
590 NPCStats *v1; // esi@1
591 void *v2; // ST00_4@1
592 int v3; // ebx@1
593
594 v1 = this;
595 pAllocator->FreeChunk(this->pNPCTopicTXT_Raw);
596 v2 = v1->pNPCTextTXT_Raw;
597 v1->pNPCNewsTXT_Raw = 0;
598 pAllocator->FreeChunk(v2);
599 v1->pNPCNewsTXT_Raw = 0;
600 pAllocator->FreeChunk(0);
601 v1->pNPCNewsTXT_Raw = 0;
602 pAllocator->FreeChunk(v1->pNPCProfTXT_Raw);
603 v1->pNPCProfTXT_Raw = 0;
604 pAllocator->FreeChunk(v1->pNPCNamesTXT_Raw);
605 v1->pNPCNamesTXT_Raw = 0;
606 pAllocator->FreeChunk(v1->pNPCDataTXT_Raw);
607 v1->pNPCDataTXT_Raw = 0;
608 pAllocator->FreeChunk(v1->pNPCDistTXT_Raw);
609 v1->pNPCDistTXT_Raw = 0;
610 v3 = (int)&v1->pNPCGreetTXT_Raw;
611 pAllocator->FreeChunk(v1->pNPCGreetTXT_Raw);
612 v1 = (NPCStats *)((char *)v1 + 98296);
613 *(int *)v3 = 0;
614 pAllocator->FreeChunk(v1->pNPCData[0].pName);
615 v1->pNPCData[0].pName = 0;
616 }
617
618 //----- (0047730C) --------------------------------------------------------
619 int __fastcall const_1(int a1, int)
620 {
621 return 1;
622 }
623 // 47730C: using guessed type int __stdcall const_1(int);
624
625 //----- (0047732C) --------------------------------------------------------
626 bool NPCStats::InitializeAdditionalNPCs(NPCData *a2, int a3, int a4, int a5)
627 {
628 //NPCStats *v5; // ebx@1
629 signed __int64 v6; // qax@1
630 int v7; // esi@1
631 int v8; // edx@1
632 NPCData *v9; // edi@1
633 int v10; // eax@1
634 //int v11; // eax@23
635 int v12; // ecx@23
636 int v13; // edx@28
637 int v14; // esi@37
638 int v15; // edx@37
639 int v16; // ecx@37
640 int v17; // eax@37
641 int v18; // edx@37
642 signed int result; // eax@39
643 int v20; // [sp+Ch] [bp-Ch]@1
644 signed int v21; // [sp+10h] [bp-8h]@1
645 signed int v22; // [sp+14h] [bp-4h]@1
646 int v23; // [sp+24h] [bp+Ch]@1
647
648
649 v23 = a3 - 1;
650 //v5 = this;
651 v6 = (signed __int64)((double)v23 * -0.33333334);
652 v7 = (unsigned __int8)byte_4E8394[-(_DWORD)v6 + 28];
653 v20 = (unsigned __int8)byte_4E8394[-(_DWORD)v6 + 116];
654 v8 = rand() % uNumNPCNames[v7];
655 v9 = a2;
656 a2->uSex = v7;
657 a2->pName = pNPCNames[v8][v7];
658 v10 = 0;
659 v22 = 0;
660 v21 = 0;
661
662 while ( 1 )
663 {
664 if ( v20 == v10 )
665 {
666 if ( v7 == v10 )
667 {
668 v23 = 2;
669 a2 = (NPCData *)100;
670 }
671 else
672 {
673 if ( v7 - v10 == 1 )
674 {
675 v23 = 201;
676 a2 = (NPCData *)250;
677 }
678 }
679 }
680 else
681 {
682 switch ( v20 - v10 )
683 {
684 case 1:
685 if ( v7 == v10 )
686 {
687 v23 = 400;
688 a2 = (NPCData *)430;
689 }
690 else
691 {
692 if ( v7 - v10 == 1 )
693 {
694 v23 = 460;
695 a2 = (NPCData *)490;
696 }
697 }
698 break;
699 case 2:
700 if ( v7 == v10 )
701 {
702 v23 = 500;
703 a2 = (NPCData *)520;
704 }
705 else
706 {
707 if ( v7 - v10 == 1 )
708 {
709 v23 = 530;
710 a2 = (NPCData *)550;
711 }
712 }
713 break;
714 case 3:
715 if ( v7 == v10 )
716 {
717 v23 = 300;
718 a2 = (NPCData *)330;
719 }
720 else
721 {
722 if ( v7 - v10 == 1 )
723 {
724 v23 = 360;
725 a2 = (NPCData *)387;
726 }
727 }
728 break;
729 }
730 }
731 v12 = v23 + rand() % ((int)a2 - v23 + 1);
732 if ( const_1(v12, v7) == 1 )
733 v21 = 1;
734 ++v22;
735 if ( v22 >= 4 )
736 {
737 v12 = v23;
738 v21 = 1;
739 }
740 if ( v21 )
741 break;
742 v10 = 0;
743 }
744
745 v9->uPortraitID = v12;
746 v9->uFlags = 0;
747 v9->fame = 0;
748 v13 = rand() % 100 + 1;
749
750 if ( v13 >= 60 )
751 {
752 if ( v13 >= 90 )
753 {
754 if ( v13 >= 95 )
755 {
756 if ( v13 >= 98 )
757 v9->rep = -600;
758 else
759 v9->rep = 400;
760 }
761 else
762 {
763 v9->rep = -300;
764 }
765 }
766 else
767 {
768 v9->rep = 200;
769 }
770 }
771 else
772 {
773 v9->rep = 0;
774 }
775
776 //v14 = (int)((char *)v5 + 64 * a5);
777 //v15 = rand() % *(_DWORD *)(v14 + 91460);
778 v15 = rand() % array_16544[a5].field_0;
779 v16 = 0;
780 v17 = 0;
781 v18 = v15 + 1;
782
783 if ( v18 > 0 )
784 {
785 do
786 //v14 += *(char *)(v14 + v17++ + 0x16548);
787 v16 += array_16544[a5].field_4[v17++];
788 while ( v16 < v18 );
789 }
790 v9->uProfession = v17 - 1;
791 v9->house = a4;
792 v9->field_24 = 1;
793 v9->joins = 1;
794 return true;
795 }
796
797
798 //----- (00476387) --------------------------------------------------------
799 bool __cdecl sub_476387()
800 {
801 return (pNPCStats->pNewNPCData[57].uFlags & 0x80) != 0;
802 }
803
804 //----- (00476395) --------------------------------------------------------
805 //0x26 Wizard eye at skill level 2
806 bool __thiscall CheckHiredNPCSpeciality(unsigned int uProfession)
807 {
808 bool result; // eax@2
809 signed int v2; // esi@3
810 char *v3; // eax@4
811
812 if ( bNoNPCHiring == 1 )
813 return 0;
814 v2 = 0;
815 if ( (signed int)pNPCStats->uNumNewNPCs <= 0 )
816 {
817 LABEL_8:
818 result = 0;
819 if ( pParty->pHirelings[0].uProfession != uProfession )
820 {
821 LOBYTE(result) = pParty->pHirelings[1].uProfession == uProfession;
822 return result;
823 }
824 }
825 else
826 {
827 v3 = (char *)&pNPCStats->pNewNPCData[0].uFlags;
828 while ( *((int *)v3 + 4) != uProfession || !(*v3 & 0x80) )
829 {
830 ++v2;
831 v3 += 76;
832 if ( v2 >= (signed int)pNPCStats->uNumNewNPCs )
833 goto LABEL_8;
834 }
835 result = 0;
836 }
837 ++result;
838 return result;
839 }
840 // 6BE3C5: using guessed type char bNoNPCHiring;
841
842 //----- (004763E0) --------------------------------------------------------
843 void InitializeAwards()
844 {
845
846 int i;
847 char* test_string;
848 unsigned char c;
849 bool break_loop;
850 unsigned int temp_str_len;
851 char* tmp_pos;
852 int decode_step;
853 int item_counter;
854
855 if ( pAwardsTXT_Raw )
856 pAllocator->FreeChunk(pAwardsTXT_Raw);
857 pAwardsTXT_Raw = NULL;
858 pAwardsTXT_Raw = (char *)pEvents_LOD->LoadRaw("awards.txt", 0);
859 strtok(pAwardsTXT_Raw, "\r");
860
861 for (i=1; i<104; ++i)
862 {
863 test_string = strtok(NULL, "\r") + 1;
864 break_loop = false;
865 decode_step=0;
866 do
867 {
868 c = *(unsigned char*)test_string;
869 temp_str_len = 0;
870 while((c!='\t')&&(c>0))
871 {
872 ++temp_str_len;
873 c=test_string[temp_str_len];
874 }
875 tmp_pos=test_string+temp_str_len;
876 if (*tmp_pos == 0)
877 break_loop = true;
878 *tmp_pos = 0;
879 if (temp_str_len)
880 {
881 if (decode_step==1)
882 pAwards[i].pText=RemoveQuotes(test_string);
883 else if (decode_step==2)
884 pAwards[i].uSort=atoi(test_string);
885 }
886 else
887 {
888 break_loop = true;
889 }
890 ++decode_step;
891 test_string=tmp_pos+1;
892 } while ((decode_step<3)&&!break_loop);
893 }
894
895 }
896 // 7241C8: using guessed type int dword_7241C8;
897
898 //----- (004764C2) --------------------------------------------------------
899 void InitializeScrolls()
900 {
901
902 int i;
903 char* test_string;
904 unsigned char c;
905 bool break_loop;
906 unsigned int temp_str_len;
907 char* tmp_pos;
908 int decode_step;
909 int item_counter;
910
911 if ( pScrollsTXT_Raw )
912 pAllocator->FreeChunk(pScrollsTXT_Raw);
913 pScrollsTXT_Raw = NULL;
914 pScrollsTXT_Raw = (char *)pEvents_LOD->LoadRaw("scroll.txt", 0);
915 strtok(pScrollsTXT_Raw, "\r");
916 for (i=0; i<82; ++i)
917 {
918 test_string = strtok(NULL, "\r") + 1;
919 break_loop = false;
920 decode_step=0;
921 do
922 {
923 c = *(unsigned char*)test_string;
924 temp_str_len = 0;
925 while((c!='\t')&&(c>0))
926 {
927 ++temp_str_len;
928 c=test_string[temp_str_len];
929 }
930 tmp_pos=test_string+temp_str_len;
931 if (*tmp_pos == 0)
932 break_loop = true;
933 *tmp_pos = 0;
934 if (temp_str_len)
935 {
936 if ( decode_step == 1)
937 pScrolls[i]=RemoveQuotes(test_string);
938 }
939 else
940 {
941 break_loop = true;
942 }
943 ++decode_step;
944 test_string=tmp_pos+1;
945 } while ((decode_step<2)&&!break_loop);
946 }
947 }
948
949
950 //----- (00476590) --------------------------------------------------------
951 void InitializeMerchants()
952 {
953 int i;
954 char* test_string;
955 unsigned char c;
956 bool break_loop;
957 unsigned int temp_str_len;
958 char* tmp_pos;
959 int decode_step;
960 int item_counter;
961
962 if ( pMerchantsTXT_Raw )
963 pAllocator->FreeChunk(pMerchantsTXT_Raw);
964 pMerchantsTXT_Raw = NULL;
965 pMerchantsTXT_Raw = (char *)pEvents_LOD->LoadRaw("merchant.txt", 0);
966 strtok(pMerchantsTXT_Raw, "\r");
967
968 for (i=0; i<7; ++i)
969 {
970 test_string = strtok(NULL, "\r") + 1;
971 break_loop = false;
972 decode_step=0;
973 do
974 {
975 c = *(unsigned char*)test_string;
976 temp_str_len = 0;
977 while((c!='\t')&&(c>0))
978 {
979 ++temp_str_len;
980 c=test_string[temp_str_len];
981 }
982 tmp_pos=test_string+temp_str_len;
983 if (*tmp_pos == 0)
984 break_loop = true;
985 *tmp_pos = 0;
986 if (temp_str_len)
987 {
988 switch (decode_step)
989 {
990 case 1:
991 pMerchantsBuyPhrases[i]=RemoveQuotes(test_string);
992 break;
993 case 2:
994 pMerchantsSellPhrases[i]=RemoveQuotes(test_string);
995 break;
996 case 3:
997 pMerchantsRepairPhrases[i]=RemoveQuotes(test_string);
998 break;
999 case 4:
1000 pMerchantsIdentifyPhrases[i]=RemoveQuotes(test_string);
1001 break;
1002 }
1003 }
1004 else
1005 {
1006 break_loop = true;
1007 }
1008 ++decode_step;
1009 test_string=tmp_pos+1;
1010 } while ((decode_step<5)&&!break_loop);
1011 }
1012
1013 }
1014
1015 //----- (00476682) --------------------------------------------------------
1016 void InitializeTransitions()
1017 {
1018 int i;
1019 char* test_string;
1020 unsigned char c;
1021 bool break_loop;
1022 unsigned int temp_str_len;
1023 char* tmp_pos;
1024 int decode_step;
1025 int item_counter;
1026
1027 if ( pTransitionsTXT_Raw )
1028 pAllocator->FreeChunk(pTransitionsTXT_Raw);
1029 pTransitionsTXT_Raw = NULL;
1030 pTransitionsTXT_Raw = (char *)pEvents_LOD->LoadRaw("trans.txt", 0);
1031 strtok(pTransitionsTXT_Raw, "\r");
1032
1033 for (i=0; i<464; ++i)
1034 {
1035 test_string = strtok(NULL, "\r") + 1;
1036 break_loop = false;
1037 decode_step=0;
1038 do
1039 {
1040 c = *(unsigned char*)test_string;
1041 temp_str_len = 0;
1042 while((c!='\t')&&(c>0))
1043 {
1044 ++temp_str_len;
1045 c=test_string[temp_str_len];
1046 }
1047 tmp_pos=test_string+temp_str_len;
1048 if (*tmp_pos == 0)
1049 break_loop = true;
1050 *tmp_pos = 0;
1051 if (temp_str_len)
1052 {
1053 if ( decode_step == 1)
1054 pTransitionStrings[i]=RemoveQuotes(test_string);
1055 }
1056 else
1057 {
1058 break_loop = true;
1059 }
1060 ++decode_step;
1061 test_string=tmp_pos+1;
1062 } while ((decode_step<2)&&!break_loop);
1063 }
1064 }
1065
1066 //----- (00476750) --------------------------------------------------------
1067 void __cdecl InitializeAutonotes()
1068 {
1069 int i;
1070 char* test_string;
1071 unsigned char c;
1072 bool break_loop;
1073 unsigned int temp_str_len;
1074 char* tmp_pos;
1075 int decode_step;
1076 int item_counter;
1077
1078 if ( pAutonoteTXT_Raw )
1079 pAllocator->FreeChunk(pAutonoteTXT_Raw);
1080 pAutonoteTXT_Raw = 0;
1081 pAutonoteTXT_Raw = (char *)pEvents_LOD->LoadRaw("autonote.txt", 0);
1082 strtok(pAutonoteTXT_Raw, "\r");
1083
1084 for (i=0; i<195; ++i)
1085 {
1086 test_string = strtok(NULL, "\r") + 1;
1087 break_loop = false;
1088 decode_step=0;
1089 do
1090 {
1091 c = *(unsigned char*)test_string;
1092 temp_str_len = 0;
1093 while((c!='\t')&&(c>0))
1094 {
1095 ++temp_str_len;
1096 c=test_string[temp_str_len];
1097 }
1098 tmp_pos=test_string+temp_str_len;
1099 if (*tmp_pos == 0)
1100 break_loop = true;
1101 *tmp_pos = 0;
1102 if (temp_str_len)
1103 {
1104 switch (decode_step)
1105 {
1106 case 1:
1107 pAutonoteTxt[i].pText=RemoveQuotes(test_string);
1108 break;
1109 case 2:
1110 {
1111 if ( !_strcmpi(test_string, "potion"))
1112 {
1113 pAutonoteTxt[i].eType = AUTONOTE_POTION_RECEPIE;
1114 break;
1115 }
1116 if ( !_strcmpi(test_string, "stat") )
1117 {
1118 pAutonoteTxt[i].eType = AUTONOTE_STAT_HINT;
1119 break;
1120 }
1121 if ( !_strcmpi(test_string, "seer") )
1122 {
1123 pAutonoteTxt[i].eType = AUTONOTE_SEER;
1124 break;
1125 }
1126 if ( !_strcmpi(test_string, "obelisk") )
1127 {
1128 pAutonoteTxt[i].eType = AUTONOTE_OBELISK;
1129 break;
1130 }
1131 if ( !_strcmpi(test_string, "teacher") )
1132 {
1133 pAutonoteTxt[i].eType = AUTONOTE_TEACHER;
1134 break;
1135 }
1136 pAutonoteTxt[i].eType =AUTONOTE_MISC;
1137 break;
1138 }
1139 }
1140 }
1141 else
1142 {
1143 break_loop = true;
1144 }
1145 ++decode_step;
1146 test_string=tmp_pos+1;
1147 } while ((decode_step<3)&&!break_loop);
1148 }
1149 }
1150
1151
1152 //----- (004768A9) --------------------------------------------------------
1153 void __cdecl InitializeQuests()
1154 {
1155 int i;
1156 char* test_string;
1157 unsigned char c;
1158 bool break_loop;
1159 unsigned int temp_str_len;
1160 char* tmp_pos;
1161 int decode_step;
1162 int item_counter;
1163
1164 if ( pQuestsTXT_Raw )
1165 pAllocator->FreeChunk(pQuestsTXT_Raw);
1166 pQuestsTXT_Raw = NULL;
1167 pQuestsTXT_Raw = (char *)pEvents_LOD->LoadRaw("quests.txt", 0);
1168 strtok(pQuestsTXT_Raw, "\r");
1169
1170 for (i=0; i<512; ++i)
1171 {
1172 test_string = strtok(NULL, "\r") + 1;
1173 break_loop = false;
1174 decode_step=0;
1175 do
1176 {
1177 c = *(unsigned char*)test_string;
1178 temp_str_len = 0;
1179 while((c!='\t')&&(c>0))
1180 {
1181 ++temp_str_len;
1182 c=test_string[temp_str_len];
1183 }
1184 tmp_pos=test_string+temp_str_len;
1185 if (*tmp_pos == 0)
1186 break_loop = true;
1187 *tmp_pos = 0;
1188 if (temp_str_len)
1189 {
1190 if ( decode_step == 1)
1191 pQuestTable[i] =RemoveQuotes(test_string);
1192 }
1193 else
1194 {
1195 break_loop = true;
1196 }
1197 ++decode_step;
1198 test_string=tmp_pos+1;
1199 } while ((decode_step<2)&&!break_loop);
1200 }
1201 }
1202