comparison NPC.cpp @ 291:0ea5fbd16edb

NPC mostly done
author Gloval
date Tue, 19 Feb 2013 00:34:15 +0400
parents 96f3a1177b37
children 5586bb4e8395
comparison
equal deleted inserted replaced
290:4776715a964b 291:0ea5fbd16edb
16 void InitializeScrolls(); 16 void InitializeScrolls();
17 void InitializeMerchants(); 17 void InitializeMerchants();
18 void InitializeTransitions(); 18 void InitializeTransitions();
19 void InitializeAutonotes(); 19 void InitializeAutonotes();
20 void InitializeQuests(); 20 void InitializeQuests();
21 21 bool CheckPortretAgainsSex(int portret_num, int sex);
22 22
23 //----- (00476977) -------------------------------------------------------- 23 //----- (00476977) --------------------------------------------------------
24 void NPCStats::Initialize2() 24 void NPCStats::InitializeNPCText()
25 { 25 {
26 int i; 26 int i;
27 char* test_string; 27 char* test_string;
28 unsigned char c; 28 unsigned char c;
29 bool break_loop; 29 bool break_loop;
134 *tmp_pos = 0; 134 *tmp_pos = 0;
135 if (temp_str_len) 135 if (temp_str_len)
136 { 136 {
137 if ((decode_step>0)&&(decode_step<77)) 137 if ((decode_step>0)&&(decode_step<77))
138 { 138 {
139 array_16544[decode_step].field_4[i]=atoi(test_string); 139 pProfessionChance[decode_step].professionChancePerArea[i]=atoi(test_string);
140 } 140 }
141 else if (decode_step==0) 141 else if (decode_step==0)
142 { 142 {
143 array_16544[0].field_4[i]=10; 143 pProfessionChance[0].professionChancePerArea[i]=10;
144 } 144 }
145 } 145 }
146 else 146 else
147 { 147 {
148 break_loop = true; 148 break_loop = true;
152 } while ((decode_step<78)&&!break_loop); 152 } while ((decode_step<78)&&!break_loop);
153 } 153 }
154 154
155 for (i=0; i<78; ++i) 155 for (i=0; i<78; ++i)
156 { 156 {
157 array_16544[i].field_0=0; 157 pProfessionChance[i].uTotalprofChance=0;
158 for (int ii=1; ii<59; ++ii) 158 for (int ii=1; ii<59; ++ii)
159 { 159 {
160 array_16544[i].field_0+=array_16544[i].field_4[ii]; 160 pProfessionChance[i].uTotalprofChance+=pProfessionChance[i].professionChancePerArea[ii];
161 } 161 }
162 } 162 }
163 163
164 if (pNPCDistTXT_Raw) 164 if (pNPCDistTXT_Raw)
165 { 165 {
170 170
171 //----- (00476C60) -------------------------------------------------------- 171 //----- (00476C60) --------------------------------------------------------
172 void NPCStats::_476C60() 172 void NPCStats::_476C60()
173 { 173 {
174 for (unsigned int i = 1; i < uNumNewNPCs; ++i) 174 for (unsigned int i = 1; i < uNumNewNPCs; ++i)
175 pNewNPCData[i].pName = pNPCNames2[i - 1]; 175 pNewNPCData[i].pName = pNPCUnicNames[i - 1];
176 176
177 if (pParty->pHirelings[0].pName) 177 if (pParty->pHirelings[0].pName)
178 pParty->pHirelings[0].pName = pParty->pHireling1Name; 178 pParty->pHirelings[0].pName = pParty->pHireling1Name;
179 if (pParty->pHirelings[1].pName) 179 if (pParty->pHirelings[1].pName)
180 pParty->pHirelings[1].pName = pParty->pHireling2Name; 180 pParty->pHirelings[1].pName = pParty->pHireling2Name;
181 } 181 }
182 182
183 //----- (00476CB5) -------------------------------------------------------- 183 //----- (00476CB5) --------------------------------------------------------
184 void NPCStats::Initialize1() 184 void NPCStats::InitializeNPCData()
185 { 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 PartyHasDragon()
800 {
801 return pNPCStats->pNewNPCData[57].Hired();
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; 186 int i;
847 char* test_string; 187 char* test_string;
848 unsigned char c; 188 unsigned char c;
849 bool break_loop; 189 bool break_loop;
850 unsigned int temp_str_len; 190 unsigned int temp_str_len;
851 char* tmp_pos; 191 char* tmp_pos;
852 int decode_step; 192 int decode_step;
853 int item_counter; 193
854 194 pNPCDataTXT_Raw = (char *)pEvents_LOD->LoadRaw("npcdata.txt", 0);
855 if ( pAwardsTXT_Raw ) 195 strtok(pNPCDataTXT_Raw, "\r");
856 pAllocator->FreeChunk(pAwardsTXT_Raw); 196 strtok(NULL, "\r");
857 pAwardsTXT_Raw = NULL; 197
858 pAwardsTXT_Raw = (char *)pEvents_LOD->LoadRaw("awards.txt", 0); 198 for (i=0; i<500; ++i)
859 strtok(pAwardsTXT_Raw, "\r"); 199 {
860 200 test_string = strtok(NULL, "\r") + 1;
861 for (i=1; i<104; ++i) 201 break_loop = false;
862 { 202 decode_step=0;
863 test_string = strtok(NULL, "\r") + 1; 203 do
864 break_loop = false; 204 {
865 decode_step=0; 205 c = *(unsigned char*)test_string;
866 do 206 temp_str_len = 0;
867 { 207 while((c!='\t')&&(c>0))
868 c = *(unsigned char*)test_string; 208 {
869 temp_str_len = 0; 209 ++temp_str_len;
870 while((c!='\t')&&(c>0)) 210 c=test_string[temp_str_len];
871 { 211 }
872 ++temp_str_len; 212 tmp_pos=test_string+temp_str_len;
873 c=test_string[temp_str_len]; 213 if (*tmp_pos == 0)
874 } 214 break_loop = true;
875 tmp_pos=test_string+temp_str_len; 215 *tmp_pos = 0;
876 if (*tmp_pos == 0) 216 if (temp_str_len)
877 break_loop = true; 217 { //i+1
878 *tmp_pos = 0; 218 switch (decode_step)
879 if (temp_str_len) 219 {
880 { 220 case 1:
221 pNPCUnicNames[i] = RemoveQuotes(test_string);
222 pNPCData[i+1].pName=pNPCUnicNames[i];
223 break;
224 case 2:
225 pNPCData[i+1].uPortraitID = atoi(test_string);
226 break;
227 case 6:
228 pNPCData[i+1].Location2D = atoi(test_string);
229 break;
230 case 7:
231 pNPCData[i+1].uProfession = atoi(test_string);
232 break;
233 case 8:
234 pNPCData[i+1].greet = atoi(test_string);
235 break;
236 case 9:
237 pNPCData[i+1].joins = (*test_string == 'y')?1:0;
238 break;
239 case 10:
240 pNPCData[i+1].evt_A = atoi(test_string);
241 break;
242 case 11:
243 pNPCData[i+1].evt_B = atoi(test_string);
244 break;
245 case 12:
246 pNPCData[i+1].evt_C = atoi(test_string);
247 break;
248 case 13:
249 pNPCData[i+1].evt_D = atoi(test_string);
250 break;
251 case 14:
252 pNPCData[i+1].evt_E = atoi(test_string);
253 break;
254 case 15:
255 pNPCData[i+1].evt_F = atoi(test_string);
256 break;
257 }
258 }
259 ++decode_step;
260 test_string=tmp_pos+1;
261 } while ((decode_step<16)&&!break_loop);
262 }
263 uNumNewNPCs = 501;
264 pNPCGreetTXT_Raw = (char*)pEvents_LOD->LoadRaw("npcgreet.txt", 0);
265 strtok(pNPCGreetTXT_Raw, "\r");
266 for (i=0; i<205; ++i)
267 {
268 test_string = strtok(NULL, "\r") + 1;
269 break_loop = false;
270 decode_step=0;
271 do
272 {
273 c = *(unsigned char*)test_string;
274 temp_str_len = 0;
275 while((c!='\t')&&(c>0))
276 {
277 ++temp_str_len;
278 c=test_string[temp_str_len];
279 }
280 tmp_pos=test_string+temp_str_len;
281 if (*tmp_pos == 0)
282 break_loop = true;
283 *tmp_pos = 0;
284 if (temp_str_len)
285 { //i+1
286 switch (decode_step)
287 {
288 case 1:
289 pNPCGreetings[i].pGreeting1 = RemoveQuotes(test_string);
290 break;
291 case 2:
292 pNPCGreetings[i].pGreeting2 = RemoveQuotes(test_string);
293 break;
294 }
295 }
296 ++decode_step;
297 test_string=tmp_pos+1;
298 } while ((decode_step<3)&&!break_loop);
299 }
300
301 pNCPGroupTXT_Raw = (char*)pEvents_LOD->LoadRaw("npcgroup.txt", 0);
302 strtok(pNCPGroupTXT_Raw, "\r");
303
304 for (i=0; i<51; ++i)
305 {
306 test_string = strtok(NULL, "\r") + 1;
307 break_loop = false;
308 decode_step=0;
309 do
310 {
311 c = *(unsigned char*)test_string;
312 temp_str_len = 0;
313 while((c!='\t')&&(c>0))
314 {
315 ++temp_str_len;
316 c=test_string[temp_str_len];
317 }
318 tmp_pos=test_string+temp_str_len;
319 if (*tmp_pos == 0)
320 break_loop = true;
321 *tmp_pos = 0;
322 if (temp_str_len)
323 { //i+1
881 if (decode_step==1) 324 if (decode_step==1)
882 pAwards[i].pText=RemoveQuotes(test_string); 325 {
883 else if (decode_step==2) 326 pGroups[i] = atoi(test_string);
884 pAwards[i].uSort=atoi(test_string); 327 }
328 }
329 ++decode_step;
330 test_string=tmp_pos+1;
331 } while ((decode_step<2)&&!break_loop);
332 }
333
334 pNPCNewsTXT_Raw = (char*)pEvents_LOD->LoadRaw("npcnews.txt", 0);
335 strtok(pNPCNewsTXT_Raw, "\r");
336
337
338 for (i=0; i<51; ++i)
339 {
340 test_string = strtok(NULL, "\r") + 1;
341 break_loop = false;
342 decode_step=0;
343 do
344 {
345 c = *(unsigned char*)test_string;
346 temp_str_len = 0;
347 while((c!='\t')&&(c>0))
348 {
349 ++temp_str_len;
350 c=test_string[temp_str_len];
351 }
352 tmp_pos=test_string+temp_str_len;
353 if (*tmp_pos == 0)
354 break_loop = true;
355 *tmp_pos = 0;
356 if (temp_str_len)
357 { //i+1
358 if (decode_step==1)
359 pCatchPhrases[i] = RemoveQuotes(test_string);
360 }
361 ++decode_step;
362 test_string=tmp_pos+1;
363 } while ((decode_step<2)&&!break_loop);
364 }
365 }
366
367 //----- (0047702F) --------------------------------------------------------
368 void NPCStats::Initialize()
369 {
370 int i;
371 char* test_string;
372 unsigned char c;
373 bool break_loop;
374 unsigned int temp_str_len;
375 char* tmp_pos;
376 int decode_step;
377
378 InitializeNPCData();
379 InitializeNPCText();
380 InitializeQuests();
381 InitializeAutonotes();
382 InitializeAwards();
383 InitializeTransitions();
384 InitializeMerchants();
385 InitializeScrolls();
386
387 pNPCNamesTXT_Raw = NULL;
388 pNPCNamesTXT_Raw = (char *)pEvents_LOD->LoadRaw("npcnames.txt", 0);
389 strtok(pNPCNamesTXT_Raw, "\r");
390
391 uNewlNPCBufPos = 0;
392
393 for (i=0; i<540; ++i)
394 {
395 test_string = strtok(NULL, "\r") + 1;
396 break_loop = false;
397 decode_step=0;
398 do
399 {
400 c = *(unsigned char*)test_string;
401 temp_str_len = 0;
402 if (c=='\t')
403 {
404 if ( (decode_step == 1)&&(!uNumNPCNames[1]))
405 uNumNPCNames[1]=i;
406 }
407 else
408 {
409 while((c!='\n')&&(c!='\t')&&(c>0))
410 {
411 ++temp_str_len;
412 c=test_string[temp_str_len];
413 }
414 tmp_pos=test_string+temp_str_len;
415 if (*tmp_pos == 0)
416 break_loop = true;
417
418 if (temp_str_len)
419 {
420 *tmp_pos = 0;
421 if ( decode_step == 0)
422 pNPCNames[i][0] =RemoveQuotes(test_string);
423 else if ( decode_step == 1)
424 pNPCNames[i][1] =RemoveQuotes(test_string);
425 }
426 else
427 {
428 if ( (decode_step == 1)&&(!uNumNPCNames[1]))
429 uNumNPCNames[1]=i;
430 }
431 }
432 ++decode_step;
433 test_string=tmp_pos+1;
434 } while ((decode_step<2)&&!break_loop);
435 }
436 uNumNPCNames[0] = i;
437
438 pNPCProfTXT_Raw = NULL;
439 pNPCProfTXT_Raw = (char *)pEvents_LOD->LoadRaw("npcprof.txt", 0);
440 strtok(pNPCProfTXT_Raw, "\r");
441 strtok(NULL, "\r");
442 strtok(NULL, "\r");
443 strtok(NULL, "\r");
444
445 for (i=1; i<59; ++i)
446 {
447 test_string = strtok(NULL, "\r") + 1;
448 break_loop = false;
449 decode_step=0;
450 do
451 {
452 c = *(unsigned char*)test_string;
453 temp_str_len = 0;
454 while((c!='\t')&&(c>0))
455 {
456 ++temp_str_len;
457 c=test_string[temp_str_len];
458 }
459 tmp_pos=test_string+temp_str_len;
460 if (*tmp_pos == 0)
461 break_loop = true;
462 *tmp_pos = 0;
463 if (temp_str_len)
464 {
465 switch(decode_step)
466 {
467 case 2:
468 pProfessions[i].uHirePrice = atoi(test_string);
469 break;
470 case 3:
471 pProfessions[i].pActionText = RemoveQuotes(test_string);
472 break;
473 case 4:
474 pProfessions[i].pBenefits= RemoveQuotes(test_string);
475 break;
476 case 5:
477 pProfessions[i].pJoinText = RemoveQuotes(test_string);
478 break;
479 case 6:
480 pProfessions[i].pDismissText = RemoveQuotes(test_string);
481 }
482 }
483 else
484 {
485 if (!decode_step)
486 break_loop = true;
487 }
488 ++decode_step;
489 test_string=tmp_pos+1;
490 } while ((decode_step<7)&&!break_loop);
491 }
492 uNumNPCProfessions = 59;
493 }
494
495 //----- (00477266) --------------------------------------------------------
496 void NPCStats::Release()
497 {
498 pAllocator->FreeChunk(pNPCTopicTXT_Raw);
499 pNPCTopicTXT_Raw = NULL;
500 pAllocator->FreeChunk(pNPCTextTXT_Raw);
501 pNPCTextTXT_Raw = NULL;
502 pAllocator->FreeChunk(pNPCNewsTXT_Raw);
503 pNPCNewsTXT_Raw = NULL;
504 pAllocator->FreeChunk(pNPCProfTXT_Raw);
505 pNPCProfTXT_Raw = NULL;
506 pAllocator->FreeChunk(pNPCNamesTXT_Raw);
507 pNPCNamesTXT_Raw = NULL;
508 pAllocator->FreeChunk(pNPCDataTXT_Raw);
509 pNPCDataTXT_Raw = NULL;
510 pAllocator->FreeChunk(pNPCDistTXT_Raw);
511 pNPCDistTXT_Raw = NULL;
512 pAllocator->FreeChunk(pNPCGreetTXT_Raw);
513 pNPCGreetTXT_Raw = NULL;
514 pAllocator->FreeChunk(pNCPGroupTXT_Raw);
515 pNCPGroupTXT_Raw = NULL;
516 }
517
518 //----- (0047730C) --------------------------------------------------------
519 bool CheckPortretAgainsSex(int a1, int)
520 {
521 return true;
522 }
523 // 47730C: using guessed type int __stdcall const_1(int);
524
525 //----- (0047732C) --------------------------------------------------------
526 void NPCStats::InitializeAdditionalNPCs(NPCData *pNPCDataBuff, int npc_uid, int uLocation2D, int uMapId)
527 {
528
529 int uNPCSex; // esi@1
530 int uGeneratedPortret; // ecx@23
531 int test_prof_summ; // ecx@37
532 int gen_profession; // eax@37
533 int max_prof_cap; // edx@37
534 signed int result; // eax@39
535 int uRace; // [sp+Ch] [bp-Ch]@1
536 bool break_gen; // [sp+10h] [bp-8h]@1
537 signed int gen_attempts; // [sp+14h] [bp-4h]@1
538 int uPortretMin; // [sp+24h] [bp+Ch]@1
539 int uPortretMax;
540
541 static const unsigned __int8 NPCSexGenTable[86] ={
542 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
543 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
544 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0,
545 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
546 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 };
547 static const unsigned __int8 NPCRaceGenTable[86] ={
548 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 1, 1,
549 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
550 0, 0, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
551 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
552 , 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0};
553
554
555 unsigned __int8 seed = (unsigned __int8)((double)(npc_uid - 1) * 0.33333334);
556 uNPCSex = NPCSexGenTable[seed];
557 uRace = NPCRaceGenTable[seed];
558 pNPCDataBuff->uSex = uNPCSex;
559 pNPCDataBuff->pName = pNPCNames[rand() % uNumNPCNames[uNPCSex]][uNPCSex];
560
561 gen_attempts = 0;
562 break_gen = false;
563
564 do
565 {
566 switch ( uRace )
567 {
568 case 0:
569 if ( uNPCSex == 0 )
570 {
571 uPortretMin = 2;
572 uPortretMax = 100;
885 } 573 }
886 else 574 else
887 { 575 {
888 break_loop = true; 576 uPortretMin = 201;
889 } 577 uPortretMax = 250;
890 ++decode_step; 578 }
891 test_string=tmp_pos+1; 579
892 } while ((decode_step<3)&&!break_loop); 580 case 1:
893 } 581 if ( uNPCSex == 0 )
894 582 {
895 } 583 uPortretMin = 400;
896 // 7241C8: using guessed type int dword_7241C8; 584 uPortretMax = 430;
897 585 }
898 //----- (004764C2) -------------------------------------------------------- 586 else
899 void InitializeScrolls() 587 {
588 uPortretMin = 460;
589 uPortretMax = 490;
590 }
591 break;
592 case 2:
593 if ( uNPCSex == 0 )
594 {
595 uPortretMin = 500;
596 uPortretMax = 520;
597 }
598 else
599 {
600 uPortretMin = 530;
601 uPortretMax = 550;
602 }
603 break;
604 case 3:
605 if ( uNPCSex == 0 )
606 {
607 uPortretMin = 300;
608 uPortretMax = 330;
609 }
610 else
611 {
612 uPortretMin = 360;
613 uPortretMax = 387;
614 }
615
616 break;
617 }
618
619 uGeneratedPortret = uPortretMin + rand() % (uPortretMax - uPortretMin + 1);
620 if ( CheckPortretAgainsSex(uGeneratedPortret, uNPCSex))
621 break_gen = true;
622 ++gen_attempts;
623 if ( gen_attempts >= 4 )
624 {
625 uGeneratedPortret = uPortretMin;
626 break_gen = true;
627 }
628 }
629 while(!break_gen);
630
631 pNPCDataBuff->uPortraitID = uGeneratedPortret;
632 pNPCDataBuff->uFlags = 0;
633 pNPCDataBuff->fame = 0;
634 //generate reputation
635 v13 = rand() % 100 + 1;
636
637 if ( v13 >= 60 )
638 {
639 if ( v13 >= 90 )
640 {
641 if ( v13 >= 95 )
642 {
643 if ( v13 >= 98 )
644 pNPCDataBuff->rep = -600;
645 else
646 pNPCDataBuff->rep = 400;
647 }
648 else
649 pNPCDataBuff->rep = -300;
650 }
651 else
652 pNPCDataBuff->rep = 200;
653
654 }
655 else
656 pNPCDataBuff->rep = 0;
657
658 max_prof_cap = rand() % pProfessionChance[uMapId].uTotalprofChance+1;
659 test_prof_summ = 0;
660 gen_profession = 0;
661
662 if ( max_prof_cap > 0 )
663 {
664 do
665 test_prof_summ += pProfessionChance[uMapId].professionChancePerArea[gen_profession++];
666 while ( test_prof_summ < max_prof_cap );
667 }
668 pNPCDataBuff->uProfession = gen_profession - 1;
669 pNPCDataBuff->Location2D = uLocation2D;
670 pNPCDataBuff->field_24 = 1;
671 pNPCDataBuff->joins = 1;
672 }
673
674
675 //----- (00476387) --------------------------------------------------------
676 bool PartyHasDragon()
677 {
678 return pNPCStats->pNewNPCData[57].Hired();
679 }
680
681 //----- (00476395) --------------------------------------------------------
682 //0x26 Wizard eye at skill level 2
683 bool __thiscall CheckHiredNPCSpeciality(unsigned int uProfession)
684 {
685 bool result; // eax@2
686 signed int v2; // esi@3
687 char *v3; // eax@4
688
689 if ( bNoNPCHiring == 1 )
690 return 0;
691 v2 = 0;
692 if ( (signed int)pNPCStats->uNumNewNPCs <= 0 )
693 {
694 LABEL_8:
695 result = 0;
696 if ( pParty->pHirelings[0].uProfession != uProfession )
697 {
698 LOBYTE(result) = pParty->pHirelings[1].uProfession == uProfession;
699 return result;
700 }
701 }
702 else
703 {
704 v3 = (char *)&pNPCStats->pNewNPCData[0].uFlags;
705 while ( *((int *)v3 + 4) != uProfession || !(*v3 & 0x80) )
706 {
707 ++v2;
708 v3 += 76;
709 if ( v2 >= (signed int)pNPCStats->uNumNewNPCs )
710 goto LABEL_8;
711 }
712 result = 0;
713 }
714 ++result;
715 return result;
716 }
717 // 6BE3C5: using guessed type char bNoNPCHiring;
718
719 //----- (004763E0) --------------------------------------------------------
720 void InitializeAwards()
900 { 721 {
901 722
902 int i; 723 int i;
903 char* test_string; 724 char* test_string;
904 unsigned char c; 725 unsigned char c;
905 bool break_loop; 726 bool break_loop;
906 unsigned int temp_str_len; 727 unsigned int temp_str_len;
907 char* tmp_pos; 728 char* tmp_pos;
908 int decode_step; 729 int decode_step;
909 int item_counter; 730
910 731 if ( pAwardsTXT_Raw )
911 if ( pScrollsTXT_Raw ) 732 pAllocator->FreeChunk(pAwardsTXT_Raw);
912 pAllocator->FreeChunk(pScrollsTXT_Raw); 733 pAwardsTXT_Raw = NULL;
913 pScrollsTXT_Raw = NULL; 734 pAwardsTXT_Raw = (char *)pEvents_LOD->LoadRaw("awards.txt", 0);
914 pScrollsTXT_Raw = (char *)pEvents_LOD->LoadRaw("scroll.txt", 0); 735 strtok(pAwardsTXT_Raw, "\r");
915 strtok(pScrollsTXT_Raw, "\r"); 736
916 for (i=0; i<82; ++i) 737 for (i=1; i<104; ++i)
917 { 738 {
918 test_string = strtok(NULL, "\r") + 1; 739 test_string = strtok(NULL, "\r") + 1;
919 break_loop = false; 740 break_loop = false;
920 decode_step=0; 741 decode_step=0;
921 do 742 do
922 { 743 {
923 c = *(unsigned char*)test_string; 744 c = *(unsigned char*)test_string;
924 temp_str_len = 0; 745 temp_str_len = 0;
925 while((c!='\t')&&(c>0)) 746 while((c!='\t')&&(c>0))
926 { 747 {
927 ++temp_str_len; 748 ++temp_str_len;
928 c=test_string[temp_str_len]; 749 c=test_string[temp_str_len];
929 } 750 }
930 tmp_pos=test_string+temp_str_len; 751 tmp_pos=test_string+temp_str_len;
931 if (*tmp_pos == 0) 752 if (*tmp_pos == 0)
932 break_loop = true; 753 break_loop = true;
933 *tmp_pos = 0; 754 *tmp_pos = 0;
934 if (temp_str_len) 755 if (temp_str_len)
935 { 756 {
936 if ( decode_step == 1) 757 if (decode_step==1)
937 pScrolls[i]=RemoveQuotes(test_string); 758 pAwards[i].pText=RemoveQuotes(test_string);
759 else if (decode_step==2)
760 pAwards[i].uSort=atoi(test_string);
938 } 761 }
939 else 762 else
940 { 763 {
941 break_loop = true; 764 break_loop = true;
942 } 765 }
943 ++decode_step; 766 ++decode_step;
944 test_string=tmp_pos+1; 767 test_string=tmp_pos+1;
945 } while ((decode_step<2)&&!break_loop); 768 } while ((decode_step<3)&&!break_loop);
946 } 769 }
947 } 770
948 771 }
949 772 // 7241C8: using guessed type int dword_7241C8;
950 //----- (00476590) -------------------------------------------------------- 773
951 void InitializeMerchants() 774 //----- (004764C2) --------------------------------------------------------
952 { 775 void InitializeScrolls()
776 {
777
953 int i; 778 int i;
954 char* test_string; 779 char* test_string;
955 unsigned char c; 780 unsigned char c;
956 bool break_loop; 781 bool break_loop;
957 unsigned int temp_str_len; 782 unsigned int temp_str_len;
958 char* tmp_pos; 783 char* tmp_pos;
959 int decode_step; 784 int decode_step;
960 int item_counter; 785
961 786 if ( pScrollsTXT_Raw )
962 if ( pMerchantsTXT_Raw ) 787 pAllocator->FreeChunk(pScrollsTXT_Raw);
963 pAllocator->FreeChunk(pMerchantsTXT_Raw); 788 pScrollsTXT_Raw = NULL;
964 pMerchantsTXT_Raw = NULL; 789 pScrollsTXT_Raw = (char *)pEvents_LOD->LoadRaw("scroll.txt", 0);
965 pMerchantsTXT_Raw = (char *)pEvents_LOD->LoadRaw("merchant.txt", 0); 790 strtok(pScrollsTXT_Raw, "\r");
966 strtok(pMerchantsTXT_Raw, "\r"); 791 for (i=0; i<82; ++i)
967 792 {
968 for (i=0; i<7; ++i) 793 test_string = strtok(NULL, "\r") + 1;
969 { 794 break_loop = false;
970 test_string = strtok(NULL, "\r") + 1; 795 decode_step=0;
971 break_loop = false; 796 do
972 decode_step=0; 797 {
973 do 798 c = *(unsigned char*)test_string;
974 { 799 temp_str_len = 0;
975 c = *(unsigned char*)test_string; 800 while((c!='\t')&&(c>0))
976 temp_str_len = 0; 801 {
977 while((c!='\t')&&(c>0)) 802 ++temp_str_len;
978 { 803 c=test_string[temp_str_len];
979 ++temp_str_len; 804 }
980 c=test_string[temp_str_len]; 805 tmp_pos=test_string+temp_str_len;
981 } 806 if (*tmp_pos == 0)
982 tmp_pos=test_string+temp_str_len; 807 break_loop = true;
983 if (*tmp_pos == 0) 808 *tmp_pos = 0;
984 break_loop = true; 809 if (temp_str_len)
985 *tmp_pos = 0; 810 {
986 if (temp_str_len) 811 if ( decode_step == 1)
987 { 812 pScrolls[i]=RemoveQuotes(test_string);
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 } 813 }
1004 else 814 else
1005 { 815 {
1006 break_loop = true; 816 break_loop = true;
1007 } 817 }
1008 ++decode_step; 818 ++decode_step;
1009 test_string=tmp_pos+1; 819 test_string=tmp_pos+1;
1010 } while ((decode_step<5)&&!break_loop); 820 } while ((decode_step<2)&&!break_loop);
1011 } 821 }
1012 822 }
1013 } 823
1014 824
1015 //----- (00476682) -------------------------------------------------------- 825 //----- (00476590) --------------------------------------------------------
1016 void InitializeTransitions() 826 void InitializeMerchants()
1017 { 827 {
1018 int i; 828 int i;
1019 char* test_string; 829 char* test_string;
1020 unsigned char c; 830 unsigned char c;
1021 bool break_loop; 831 bool break_loop;
1022 unsigned int temp_str_len; 832 unsigned int temp_str_len;
1023 char* tmp_pos; 833 char* tmp_pos;
1024 int decode_step; 834 int decode_step;
1025 int item_counter; 835
1026 836 if ( pMerchantsTXT_Raw )
1027 if ( pTransitionsTXT_Raw ) 837 pAllocator->FreeChunk(pMerchantsTXT_Raw);
1028 pAllocator->FreeChunk(pTransitionsTXT_Raw); 838 pMerchantsTXT_Raw = NULL;
1029 pTransitionsTXT_Raw = NULL; 839 pMerchantsTXT_Raw = (char *)pEvents_LOD->LoadRaw("merchant.txt", 0);
1030 pTransitionsTXT_Raw = (char *)pEvents_LOD->LoadRaw("trans.txt", 0); 840 strtok(pMerchantsTXT_Raw, "\r");
1031 strtok(pTransitionsTXT_Raw, "\r"); 841
1032 842 for (i=0; i<7; ++i)
1033 for (i=0; i<464; ++i) 843 {
1034 { 844 test_string = strtok(NULL, "\r") + 1;
1035 test_string = strtok(NULL, "\r") + 1; 845 break_loop = false;
1036 break_loop = false; 846 decode_step=0;
1037 decode_step=0; 847 do
1038 do 848 {
1039 { 849 c = *(unsigned char*)test_string;
1040 c = *(unsigned char*)test_string; 850 temp_str_len = 0;
1041 temp_str_len = 0; 851 while((c!='\t')&&(c>0))
1042 while((c!='\t')&&(c>0)) 852 {
1043 { 853 ++temp_str_len;
1044 ++temp_str_len; 854 c=test_string[temp_str_len];
1045 c=test_string[temp_str_len]; 855 }
1046 } 856 tmp_pos=test_string+temp_str_len;
1047 tmp_pos=test_string+temp_str_len; 857 if (*tmp_pos == 0)
1048 if (*tmp_pos == 0) 858 break_loop = true;
1049 break_loop = true; 859 *tmp_pos = 0;
1050 *tmp_pos = 0; 860 if (temp_str_len)
1051 if (temp_str_len) 861 {
1052 { 862 switch (decode_step)
1053 if ( decode_step == 1) 863 {
1054 pTransitionStrings[i]=RemoveQuotes(test_string); 864 case 1:
865 pMerchantsBuyPhrases[i]=RemoveQuotes(test_string);
866 break;
867 case 2:
868 pMerchantsSellPhrases[i]=RemoveQuotes(test_string);
869 break;
870 case 3:
871 pMerchantsRepairPhrases[i]=RemoveQuotes(test_string);
872 break;
873 case 4:
874 pMerchantsIdentifyPhrases[i]=RemoveQuotes(test_string);
875 break;
876 }
1055 } 877 }
1056 else 878 else
1057 { 879 {
1058 break_loop = true; 880 break_loop = true;
1059 } 881 }
1060 ++decode_step; 882 ++decode_step;
1061 test_string=tmp_pos+1; 883 test_string=tmp_pos+1;
1062 } while ((decode_step<2)&&!break_loop); 884 } while ((decode_step<5)&&!break_loop);
1063 } 885 }
1064 } 886
1065 887 }
1066 //----- (00476750) -------------------------------------------------------- 888
1067 void __cdecl InitializeAutonotes() 889 //----- (00476682) --------------------------------------------------------
890 void InitializeTransitions()
1068 { 891 {
1069 int i; 892 int i;
1070 char* test_string; 893 char* test_string;
1071 unsigned char c; 894 unsigned char c;
1072 bool break_loop; 895 bool break_loop;
1073 unsigned int temp_str_len; 896 unsigned int temp_str_len;
1074 char* tmp_pos; 897 char* tmp_pos;
1075 int decode_step; 898 int decode_step;
1076 int item_counter; 899
900 if ( pTransitionsTXT_Raw )
901 pAllocator->FreeChunk(pTransitionsTXT_Raw);
902 pTransitionsTXT_Raw = NULL;
903 pTransitionsTXT_Raw = (char *)pEvents_LOD->LoadRaw("trans.txt", 0);
904 strtok(pTransitionsTXT_Raw, "\r");
905
906 for (i=0; i<464; ++i)
907 {
908 test_string = strtok(NULL, "\r") + 1;
909 break_loop = false;
910 decode_step=0;
911 do
912 {
913 c = *(unsigned char*)test_string;
914 temp_str_len = 0;
915 while((c!='\t')&&(c>0))
916 {
917 ++temp_str_len;
918 c=test_string[temp_str_len];
919 }
920 tmp_pos=test_string+temp_str_len;
921 if (*tmp_pos == 0)
922 break_loop = true;
923 *tmp_pos = 0;
924 if (temp_str_len)
925 {
926 if ( decode_step == 1)
927 pTransitionStrings[i]=RemoveQuotes(test_string);
928 }
929 else
930 {
931 break_loop = true;
932 }
933 ++decode_step;
934 test_string=tmp_pos+1;
935 } while ((decode_step<2)&&!break_loop);
936 }
937 }
938
939 //----- (00476750) --------------------------------------------------------
940 void __cdecl InitializeAutonotes()
941 {
942 int i;
943 char* test_string;
944 unsigned char c;
945 bool break_loop;
946 unsigned int temp_str_len;
947 char* tmp_pos;
948 int decode_step;
1077 949
1078 if ( pAutonoteTXT_Raw ) 950 if ( pAutonoteTXT_Raw )
1079 pAllocator->FreeChunk(pAutonoteTXT_Raw); 951 pAllocator->FreeChunk(pAutonoteTXT_Raw);
1080 pAutonoteTXT_Raw = 0; 952 pAutonoteTXT_Raw = 0;
1081 pAutonoteTXT_Raw = (char *)pEvents_LOD->LoadRaw("autonote.txt", 0); 953 pAutonoteTXT_Raw = (char *)pEvents_LOD->LoadRaw("autonote.txt", 0);
1157 unsigned char c; 1029 unsigned char c;
1158 bool break_loop; 1030 bool break_loop;
1159 unsigned int temp_str_len; 1031 unsigned int temp_str_len;
1160 char* tmp_pos; 1032 char* tmp_pos;
1161 int decode_step; 1033 int decode_step;
1162 int item_counter;
1163 1034
1164 if ( pQuestsTXT_Raw ) 1035 if ( pQuestsTXT_Raw )
1165 pAllocator->FreeChunk(pQuestsTXT_Raw); 1036 pAllocator->FreeChunk(pQuestsTXT_Raw);
1166 pQuestsTXT_Raw = NULL; 1037 pQuestsTXT_Raw = NULL;
1167 pQuestsTXT_Raw = (char *)pEvents_LOD->LoadRaw("quests.txt", 0); 1038 pQuestsTXT_Raw = (char *)pEvents_LOD->LoadRaw("quests.txt", 0);