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