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 {
|
652
|
459 while (*test_string == '\t') // some steps are separated by multiple \t's
|
|
460 ++test_string;
|
|
461
|
291
|
462 c = *(unsigned char*)test_string;
|
|
463 temp_str_len = 0;
|
|
464 while((c!='\t')&&(c>0))
|
251
|
465 {
|
291
|
466 ++temp_str_len;
|
|
467 c=test_string[temp_str_len];
|
|
468 }
|
|
469 tmp_pos=test_string+temp_str_len;
|
|
470 if (*tmp_pos == 0)
|
|
471 break_loop = true;
|
|
472 *tmp_pos = 0;
|
|
473 if (temp_str_len)
|
|
474 {
|
|
475 switch(decode_step)
|
|
476 {
|
|
477 case 2:
|
|
478 pProfessions[i].uHirePrice = atoi(test_string);
|
|
479 break;
|
|
480 case 3:
|
|
481 pProfessions[i].pActionText = RemoveQuotes(test_string);
|
|
482 break;
|
|
483 case 4:
|
|
484 pProfessions[i].pBenefits= RemoveQuotes(test_string);
|
|
485 break;
|
|
486 case 5:
|
|
487 pProfessions[i].pJoinText = RemoveQuotes(test_string);
|
|
488 break;
|
|
489 case 6:
|
|
490 pProfessions[i].pDismissText = RemoveQuotes(test_string);
|
|
491 }
|
251
|
492 }
|
291
|
493 else
|
|
494 {
|
570
|
495 if (decode_step)
|
291
|
496 break_loop = true;
|
|
497 }
|
|
498 ++decode_step;
|
|
499 test_string=tmp_pos+1;
|
|
500 } while ((decode_step<7)&&!break_loop);
|
251
|
501 }
|
291
|
502 uNumNPCProfessions = 59;
|
251
|
503 }
|
|
504
|
|
505 //----- (00477266) --------------------------------------------------------
|
|
506 void NPCStats::Release()
|
|
507 {
|
291
|
508 pAllocator->FreeChunk(pNPCTopicTXT_Raw);
|
|
509 pNPCTopicTXT_Raw = NULL;
|
|
510 pAllocator->FreeChunk(pNPCTextTXT_Raw);
|
|
511 pNPCTextTXT_Raw = NULL;
|
|
512 pAllocator->FreeChunk(pNPCNewsTXT_Raw);
|
|
513 pNPCNewsTXT_Raw = NULL;
|
|
514 pAllocator->FreeChunk(pNPCProfTXT_Raw);
|
|
515 pNPCProfTXT_Raw = NULL;
|
|
516 pAllocator->FreeChunk(pNPCNamesTXT_Raw);
|
|
517 pNPCNamesTXT_Raw = NULL;
|
|
518 pAllocator->FreeChunk(pNPCDataTXT_Raw);
|
|
519 pNPCDataTXT_Raw = NULL;
|
|
520 pAllocator->FreeChunk(pNPCDistTXT_Raw);
|
|
521 pNPCDistTXT_Raw = NULL;
|
|
522 pAllocator->FreeChunk(pNPCGreetTXT_Raw);
|
|
523 pNPCGreetTXT_Raw = NULL;
|
|
524 pAllocator->FreeChunk(pNCPGroupTXT_Raw);
|
|
525 pNCPGroupTXT_Raw = NULL;
|
251
|
526 }
|
|
527
|
|
528 //----- (0047730C) --------------------------------------------------------
|
307
|
529 bool CheckPortretAgainstSex(int a1, int)
|
251
|
530 {
|
291
|
531 return true;
|
251
|
532 }
|
|
533 // 47730C: using guessed type int __stdcall const_1(int);
|
|
534
|
|
535 //----- (0047732C) --------------------------------------------------------
|
291
|
536 void NPCStats::InitializeAdditionalNPCs(NPCData *pNPCDataBuff, int npc_uid, int uLocation2D, int uMapId)
|
251
|
537 {
|
292
|
538 int rep_gen;
|
291
|
539 int uNPCSex; // esi@1
|
|
540 int uGeneratedPortret; // ecx@23
|
|
541 int test_prof_summ; // ecx@37
|
|
542 int gen_profession; // eax@37
|
|
543 int max_prof_cap; // edx@37
|
251
|
544 signed int result; // eax@39
|
291
|
545 int uRace; // [sp+Ch] [bp-Ch]@1
|
|
546 bool break_gen; // [sp+10h] [bp-8h]@1
|
|
547 signed int gen_attempts; // [sp+14h] [bp-4h]@1
|
|
548 int uPortretMin; // [sp+24h] [bp+Ch]@1
|
|
549 int uPortretMax;
|
|
550
|
|
551 static const unsigned __int8 NPCSexGenTable[86] ={
|
293
|
552 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
553 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
|
|
554 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0,
|
|
555 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
556 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 };
|
|
557 static const unsigned __int8 NPCRaceGenTable[86] ={
|
|
558 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 1, 1,
|
|
559 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
560 0, 0, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
|
|
561 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
562 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0};
|
251
|
563
|
307
|
564 unsigned __int8 seed = (unsigned __int8)((double)(npc_uid - 1)/3.0);
|
291
|
565 uNPCSex = NPCSexGenTable[seed];
|
|
566 uRace = NPCRaceGenTable[seed];
|
|
567 pNPCDataBuff->uSex = uNPCSex;
|
|
568 pNPCDataBuff->pName = pNPCNames[rand() % uNumNPCNames[uNPCSex]][uNPCSex];
|
|
569
|
|
570 gen_attempts = 0;
|
|
571 break_gen = false;
|
251
|
572
|
291
|
573 do
|
251
|
574 {
|
293
|
575 switch ( uRace )
|
|
576 {
|
|
577 case 0:
|
|
578 if ( uNPCSex == 0 )
|
291
|
579 {
|
|
580 uPortretMin = 2;
|
|
581 uPortretMax = 100;
|
251
|
582 }
|
|
583 else
|
|
584 {
|
293
|
585 uPortretMin = 201;
|
|
586 uPortretMax = 250;
|
|
587 }
|
|
588 case 1:
|
|
589 if ( uNPCSex == 0 )
|
|
590 {
|
|
591 uPortretMin = 400;
|
|
592 uPortretMax = 430;
|
|
593 }
|
|
594 else
|
|
595 {
|
|
596 uPortretMin = 460;
|
|
597 uPortretMax = 490;
|
|
598 }
|
|
599 break;
|
|
600 case 2:
|
|
601 if ( uNPCSex == 0 )
|
|
602 {
|
|
603 uPortretMin = 500;
|
|
604 uPortretMax = 520;
|
|
605 }
|
|
606 else
|
|
607 {
|
|
608 uPortretMin = 530;
|
|
609 uPortretMax = 550;
|
|
610 }
|
|
611 break;
|
|
612 case 3:
|
|
613 if ( uNPCSex == 0 )
|
|
614 {
|
|
615 uPortretMin = 300;
|
|
616 uPortretMax = 330;
|
|
617 }
|
|
618 else
|
|
619 {
|
|
620 uPortretMin = 360;
|
|
621 uPortretMax = 387;
|
251
|
622 }
|
291
|
623
|
293
|
624 break;
|
|
625 }
|
|
626
|
291
|
627 uGeneratedPortret = uPortretMin + rand() % (uPortretMax - uPortretMin + 1);
|
307
|
628 if ( CheckPortretAgainstSex(uGeneratedPortret, uNPCSex))
|
291
|
629 break_gen = true;
|
|
630 ++gen_attempts;
|
|
631 if ( gen_attempts >= 4 )
|
251
|
632 {
|
291
|
633 uGeneratedPortret = uPortretMin;
|
|
634 break_gen = true;
|
251
|
635 }
|
|
636 }
|
291
|
637 while(!break_gen);
|
251
|
638
|
293
|
639 pNPCDataBuff->uPortraitID = uGeneratedPortret;
|
|
640 pNPCDataBuff->uFlags = 0;
|
|
641 pNPCDataBuff->fame = 0;
|
|
642 //generate reputation
|
|
643 rep_gen = rand() % 100 + 1;
|
251
|
644
|
293
|
645 if ( rep_gen >= 60 )
|
251
|
646 {
|
293
|
647 if ( rep_gen >= 90 )
|
251
|
648 {
|
293
|
649 if ( rep_gen >= 95 )
|
|
650 {
|
|
651 if ( rep_gen >= 98 )
|
|
652 pNPCDataBuff->rep = -600;
|
|
653 else
|
|
654 pNPCDataBuff->rep = 400;
|
|
655 }
|
251
|
656 else
|
293
|
657 pNPCDataBuff->rep = -300;
|
251
|
658 }
|
|
659 else
|
293
|
660 pNPCDataBuff->rep = 200;
|
251
|
661 }
|
|
662 else
|
293
|
663 pNPCDataBuff->rep = 0;
|
291
|
664
|
293
|
665 max_prof_cap = rand() % pProfessionChance[uMapId].uTotalprofChance+1;
|
|
666 test_prof_summ = 0;
|
|
667 gen_profession = 0;
|
251
|
668
|
293
|
669 if ( max_prof_cap > 0 )
|
|
670 {
|
|
671 do
|
|
672 test_prof_summ += pProfessionChance[uMapId].professionChancePerArea[gen_profession++];
|
|
673 while ( test_prof_summ < max_prof_cap );
|
|
674 }
|
|
675 pNPCDataBuff->uProfession = gen_profession - 1;
|
|
676 pNPCDataBuff->Location2D = uLocation2D;
|
|
677 pNPCDataBuff->field_24 = 1;
|
|
678 pNPCDataBuff->joins = 1;
|
251
|
679 }
|
|
680
|
257
|
681 //----- (00476387) --------------------------------------------------------
|
|
682 bool PartyHasDragon()
|
|
683 {
|
|
684 return pNPCStats->pNewNPCData[57].Hired();
|
|
685 }
|
251
|
686
|
|
687 //----- (00476395) --------------------------------------------------------
|
|
688 //0x26 Wizard eye at skill level 2
|
|
689 bool __thiscall CheckHiredNPCSpeciality(unsigned int uProfession)
|
353
|
690 {
|
251
|
691 bool result; // eax@2
|
|
692 signed int v2; // esi@3
|
|
693 char *v3; // eax@4
|
|
694
|
|
695 if ( bNoNPCHiring == 1 )
|
|
696 return 0;
|
|
697 v2 = 0;
|
|
698 if ( (signed int)pNPCStats->uNumNewNPCs <= 0 )
|
|
699 {
|
|
700 LABEL_8:
|
|
701 result = 0;
|
|
702 if ( pParty->pHirelings[0].uProfession != uProfession )
|
|
703 {
|
|
704 LOBYTE(result) = pParty->pHirelings[1].uProfession == uProfession;
|
|
705 return result;
|
|
706 }
|
|
707 }
|
|
708 else
|
|
709 {
|
|
710 v3 = (char *)&pNPCStats->pNewNPCData[0].uFlags;
|
|
711 while ( *((int *)v3 + 4) != uProfession || !(*v3 & 0x80) )
|
|
712 {
|
|
713 ++v2;
|
|
714 v3 += 76;
|
|
715 if ( v2 >= (signed int)pNPCStats->uNumNewNPCs )
|
|
716 goto LABEL_8;
|
|
717 }
|
|
718 result = 0;
|
|
719 }
|
|
720 ++result;
|
|
721 return result;
|
|
722 }
|
|
723 // 6BE3C5: using guessed type char bNoNPCHiring;
|
|
724
|
|
725 //----- (004763E0) --------------------------------------------------------
|
|
726 void InitializeAwards()
|
|
727 {
|
|
728
|
|
729 int i;
|
|
730 char* test_string;
|
|
731 unsigned char c;
|
|
732 bool break_loop;
|
|
733 unsigned int temp_str_len;
|
|
734 char* tmp_pos;
|
|
735 int decode_step;
|
|
736
|
|
737 if ( pAwardsTXT_Raw )
|
|
738 pAllocator->FreeChunk(pAwardsTXT_Raw);
|
|
739 pAwardsTXT_Raw = NULL;
|
|
740 pAwardsTXT_Raw = (char *)pEvents_LOD->LoadRaw("awards.txt", 0);
|
|
741 strtok(pAwardsTXT_Raw, "\r");
|
|
742
|
|
743 for (i=1; i<104; ++i)
|
|
744 {
|
|
745 test_string = strtok(NULL, "\r") + 1;
|
|
746 break_loop = false;
|
|
747 decode_step=0;
|
|
748 do
|
|
749 {
|
|
750 c = *(unsigned char*)test_string;
|
|
751 temp_str_len = 0;
|
|
752 while((c!='\t')&&(c>0))
|
|
753 {
|
|
754 ++temp_str_len;
|
|
755 c=test_string[temp_str_len];
|
|
756 }
|
|
757 tmp_pos=test_string+temp_str_len;
|
|
758 if (*tmp_pos == 0)
|
|
759 break_loop = true;
|
|
760 *tmp_pos = 0;
|
|
761 if (temp_str_len)
|
|
762 {
|
|
763 if (decode_step==1)
|
|
764 pAwards[i].pText=RemoveQuotes(test_string);
|
|
765 else if (decode_step==2)
|
|
766 pAwards[i].uSort=atoi(test_string);
|
|
767 }
|
|
768 else
|
|
769 {
|
|
770 break_loop = true;
|
|
771 }
|
|
772 ++decode_step;
|
|
773 test_string=tmp_pos+1;
|
|
774 } while ((decode_step<3)&&!break_loop);
|
|
775 }
|
|
776
|
|
777 }
|
|
778 // 7241C8: using guessed type int dword_7241C8;
|
|
779
|
|
780 //----- (004764C2) --------------------------------------------------------
|
|
781 void InitializeScrolls()
|
|
782 {
|
|
783
|
|
784 int i;
|
|
785 char* test_string;
|
|
786 unsigned char c;
|
|
787 bool break_loop;
|
|
788 unsigned int temp_str_len;
|
|
789 char* tmp_pos;
|
|
790 int decode_step;
|
|
791
|
|
792 if ( pScrollsTXT_Raw )
|
|
793 pAllocator->FreeChunk(pScrollsTXT_Raw);
|
|
794 pScrollsTXT_Raw = NULL;
|
|
795 pScrollsTXT_Raw = (char *)pEvents_LOD->LoadRaw("scroll.txt", 0);
|
|
796 strtok(pScrollsTXT_Raw, "\r");
|
|
797 for (i=0; i<82; ++i)
|
|
798 {
|
|
799 test_string = strtok(NULL, "\r") + 1;
|
|
800 break_loop = false;
|
|
801 decode_step=0;
|
|
802 do
|
|
803 {
|
|
804 c = *(unsigned char*)test_string;
|
|
805 temp_str_len = 0;
|
|
806 while((c!='\t')&&(c>0))
|
|
807 {
|
|
808 ++temp_str_len;
|
|
809 c=test_string[temp_str_len];
|
|
810 }
|
|
811 tmp_pos=test_string+temp_str_len;
|
|
812 if (*tmp_pos == 0)
|
|
813 break_loop = true;
|
|
814 *tmp_pos = 0;
|
|
815 if (temp_str_len)
|
|
816 {
|
|
817 if ( decode_step == 1)
|
|
818 pScrolls[i]=RemoveQuotes(test_string);
|
|
819 }
|
|
820 else
|
|
821 {
|
|
822 break_loop = true;
|
|
823 }
|
|
824 ++decode_step;
|
|
825 test_string=tmp_pos+1;
|
|
826 } while ((decode_step<2)&&!break_loop);
|
|
827 }
|
|
828 }
|
|
829
|
|
830 //----- (00476590) --------------------------------------------------------
|
|
831 void InitializeMerchants()
|
|
832 {
|
|
833 int i;
|
|
834 char* test_string;
|
|
835 unsigned char c;
|
|
836 bool break_loop;
|
|
837 unsigned int temp_str_len;
|
|
838 char* tmp_pos;
|
|
839 int decode_step;
|
|
840
|
|
841 if ( pMerchantsTXT_Raw )
|
|
842 pAllocator->FreeChunk(pMerchantsTXT_Raw);
|
|
843 pMerchantsTXT_Raw = NULL;
|
|
844 pMerchantsTXT_Raw = (char *)pEvents_LOD->LoadRaw("merchant.txt", 0);
|
|
845 strtok(pMerchantsTXT_Raw, "\r");
|
|
846
|
|
847 for (i=0; i<7; ++i)
|
|
848 {
|
|
849 test_string = strtok(NULL, "\r") + 1;
|
|
850 break_loop = false;
|
|
851 decode_step=0;
|
|
852 do
|
|
853 {
|
|
854 c = *(unsigned char*)test_string;
|
|
855 temp_str_len = 0;
|
|
856 while((c!='\t')&&(c>0))
|
|
857 {
|
|
858 ++temp_str_len;
|
|
859 c=test_string[temp_str_len];
|
|
860 }
|
|
861 tmp_pos=test_string+temp_str_len;
|
|
862 if (*tmp_pos == 0)
|
|
863 break_loop = true;
|
|
864 *tmp_pos = 0;
|
|
865 if (temp_str_len)
|
|
866 {
|
|
867 switch (decode_step)
|
|
868 {
|
|
869 case 1:
|
|
870 pMerchantsBuyPhrases[i]=RemoveQuotes(test_string);
|
|
871 break;
|
|
872 case 2:
|
|
873 pMerchantsSellPhrases[i]=RemoveQuotes(test_string);
|
|
874 break;
|
|
875 case 3:
|
|
876 pMerchantsRepairPhrases[i]=RemoveQuotes(test_string);
|
|
877 break;
|
|
878 case 4:
|
|
879 pMerchantsIdentifyPhrases[i]=RemoveQuotes(test_string);
|
|
880 break;
|
|
881 }
|
|
882 }
|
|
883 else
|
|
884 {
|
|
885 break_loop = true;
|
|
886 }
|
|
887 ++decode_step;
|
|
888 test_string=tmp_pos+1;
|
|
889 } while ((decode_step<5)&&!break_loop);
|
|
890 }
|
|
891
|
|
892 }
|
|
893
|
|
894 //----- (00476682) --------------------------------------------------------
|
|
895 void InitializeTransitions()
|
|
896 {
|
|
897 int i;
|
|
898 char* test_string;
|
|
899 unsigned char c;
|
|
900 bool break_loop;
|
|
901 unsigned int temp_str_len;
|
|
902 char* tmp_pos;
|
|
903 int decode_step;
|
|
904
|
|
905 if ( pTransitionsTXT_Raw )
|
|
906 pAllocator->FreeChunk(pTransitionsTXT_Raw);
|
|
907 pTransitionsTXT_Raw = NULL;
|
|
908 pTransitionsTXT_Raw = (char *)pEvents_LOD->LoadRaw("trans.txt", 0);
|
|
909 strtok(pTransitionsTXT_Raw, "\r");
|
|
910
|
|
911 for (i=0; i<464; ++i)
|
|
912 {
|
|
913 test_string = strtok(NULL, "\r") + 1;
|
|
914 break_loop = false;
|
|
915 decode_step=0;
|
|
916 do
|
|
917 {
|
|
918 c = *(unsigned char*)test_string;
|
|
919 temp_str_len = 0;
|
|
920 while((c!='\t')&&(c>0))
|
|
921 {
|
|
922 ++temp_str_len;
|
|
923 c=test_string[temp_str_len];
|
|
924 }
|
|
925 tmp_pos=test_string+temp_str_len;
|
|
926 if (*tmp_pos == 0)
|
|
927 break_loop = true;
|
|
928 *tmp_pos = 0;
|
|
929 if (temp_str_len)
|
|
930 {
|
|
931 if ( decode_step == 1)
|
434
|
932 pTransitionStrings[i + 1]=RemoveQuotes(test_string);
|
251
|
933 }
|
|
934 else
|
|
935 {
|
|
936 break_loop = true;
|
|
937 }
|
|
938 ++decode_step;
|
|
939 test_string=tmp_pos+1;
|
|
940 } while ((decode_step<2)&&!break_loop);
|
|
941 }
|
|
942 }
|
|
943
|
|
944 //----- (00476750) --------------------------------------------------------
|
|
945 void __cdecl InitializeAutonotes()
|
|
946 {
|
|
947 int i;
|
|
948 char* test_string;
|
|
949 unsigned char c;
|
|
950 bool break_loop;
|
|
951 unsigned int temp_str_len;
|
|
952 char* tmp_pos;
|
|
953 int decode_step;
|
|
954
|
|
955 if ( pAutonoteTXT_Raw )
|
|
956 pAllocator->FreeChunk(pAutonoteTXT_Raw);
|
|
957 pAutonoteTXT_Raw = 0;
|
|
958 pAutonoteTXT_Raw = (char *)pEvents_LOD->LoadRaw("autonote.txt", 0);
|
|
959 strtok(pAutonoteTXT_Raw, "\r");
|
|
960
|
|
961 for (i=0; i<195; ++i)
|
|
962 {
|
|
963 test_string = strtok(NULL, "\r") + 1;
|
|
964 break_loop = false;
|
|
965 decode_step=0;
|
|
966 do
|
|
967 {
|
|
968 c = *(unsigned char*)test_string;
|
|
969 temp_str_len = 0;
|
|
970 while((c!='\t')&&(c>0))
|
|
971 {
|
|
972 ++temp_str_len;
|
|
973 c=test_string[temp_str_len];
|
|
974 }
|
|
975 tmp_pos=test_string+temp_str_len;
|
|
976 if (*tmp_pos == 0)
|
|
977 break_loop = true;
|
|
978 *tmp_pos = 0;
|
|
979 if (temp_str_len)
|
|
980 {
|
|
981 switch (decode_step)
|
|
982 {
|
|
983 case 1:
|
|
984 pAutonoteTxt[i].pText=RemoveQuotes(test_string);
|
|
985 break;
|
|
986 case 2:
|
|
987 {
|
|
988 if ( !_strcmpi(test_string, "potion"))
|
|
989 {
|
|
990 pAutonoteTxt[i].eType = AUTONOTE_POTION_RECEPIE;
|
|
991 break;
|
|
992 }
|
|
993 if ( !_strcmpi(test_string, "stat") )
|
|
994 {
|
|
995 pAutonoteTxt[i].eType = AUTONOTE_STAT_HINT;
|
|
996 break;
|
|
997 }
|
|
998 if ( !_strcmpi(test_string, "seer") )
|
|
999 {
|
|
1000 pAutonoteTxt[i].eType = AUTONOTE_SEER;
|
|
1001 break;
|
|
1002 }
|
|
1003 if ( !_strcmpi(test_string, "obelisk") )
|
|
1004 {
|
|
1005 pAutonoteTxt[i].eType = AUTONOTE_OBELISK;
|
|
1006 break;
|
|
1007 }
|
|
1008 if ( !_strcmpi(test_string, "teacher") )
|
|
1009 {
|
|
1010 pAutonoteTxt[i].eType = AUTONOTE_TEACHER;
|
|
1011 break;
|
|
1012 }
|
|
1013 pAutonoteTxt[i].eType =AUTONOTE_MISC;
|
|
1014 break;
|
|
1015 }
|
|
1016 }
|
|
1017 }
|
|
1018 else
|
|
1019 {
|
|
1020 break_loop = true;
|
|
1021 }
|
|
1022 ++decode_step;
|
|
1023 test_string=tmp_pos+1;
|
|
1024 } while ((decode_step<3)&&!break_loop);
|
|
1025 }
|
|
1026 }
|
|
1027
|
|
1028
|
|
1029 //----- (004768A9) --------------------------------------------------------
|
|
1030 void __cdecl InitializeQuests()
|
|
1031 {
|
|
1032 int i;
|
|
1033 char* test_string;
|
|
1034 unsigned char c;
|
|
1035 bool break_loop;
|
|
1036 unsigned int temp_str_len;
|
|
1037 char* tmp_pos;
|
|
1038 int decode_step;
|
|
1039
|
|
1040 if ( pQuestsTXT_Raw )
|
|
1041 pAllocator->FreeChunk(pQuestsTXT_Raw);
|
|
1042 pQuestsTXT_Raw = NULL;
|
|
1043 pQuestsTXT_Raw = (char *)pEvents_LOD->LoadRaw("quests.txt", 0);
|
|
1044 strtok(pQuestsTXT_Raw, "\r");
|
|
1045
|
|
1046 for (i=0; i<512; ++i)
|
|
1047 {
|
|
1048 test_string = strtok(NULL, "\r") + 1;
|
|
1049 break_loop = false;
|
|
1050 decode_step=0;
|
|
1051 do
|
|
1052 {
|
|
1053 c = *(unsigned char*)test_string;
|
|
1054 temp_str_len = 0;
|
|
1055 while((c!='\t')&&(c>0))
|
|
1056 {
|
|
1057 ++temp_str_len;
|
|
1058 c=test_string[temp_str_len];
|
|
1059 }
|
|
1060 tmp_pos=test_string+temp_str_len;
|
|
1061 if (*tmp_pos == 0)
|
|
1062 break_loop = true;
|
|
1063 *tmp_pos = 0;
|
|
1064 if (temp_str_len)
|
|
1065 {
|
|
1066 if ( decode_step == 1)
|
|
1067 pQuestTable[i] =RemoveQuotes(test_string);
|
|
1068 }
|
|
1069 else
|
|
1070 {
|
|
1071 break_loop = true;
|
|
1072 }
|
|
1073 ++decode_step;
|
|
1074 test_string=tmp_pos+1;
|
|
1075 } while ((decode_step<2)&&!break_loop);
|
|
1076 }
|
|
1077 }
|
|
1078
|