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
|
|
15 void InitializeAwards();
|
|
16 void InitializeScrolls();
|
|
17 void InitializeMerchants();
|
|
18 void InitializeTransitions();
|
|
19 void InitializeAutonotes();
|
|
20 void InitializeQuests();
|
291
|
21 bool CheckPortretAgainsSex(int portret_num, int sex);
|
251
|
22
|
|
23 //----- (00476977) --------------------------------------------------------
|
291
|
24 void NPCStats::InitializeNPCText()
|
251
|
25 {
|
|
26 int i;
|
|
27 char* test_string;
|
|
28 unsigned char c;
|
|
29 bool break_loop;
|
|
30 unsigned int temp_str_len;
|
|
31 char* tmp_pos;
|
|
32 int decode_step;
|
|
33
|
|
34 if (pNPCTextTXT_Raw)
|
|
35 pAllocator->FreeChunk(pNPCTextTXT_Raw);
|
|
36 pNPCTextTXT_Raw =NULL;
|
|
37 pNPCTextTXT_Raw = (char *)pEvents_LOD->LoadRaw("npctext.txt", 0);
|
|
38 strtok(pNPCTextTXT_Raw, "\r");
|
|
39
|
|
40 for (i=0; i<789; ++i)
|
|
41 {
|
|
42 test_string = strtok(NULL, "\r") + 1;
|
|
43 break_loop = false;
|
|
44 decode_step=0;
|
|
45 do
|
|
46 {
|
|
47 c = *(unsigned char*)test_string;
|
|
48 temp_str_len = 0;
|
|
49 while((c!='\t')&&(c>0))
|
|
50 {
|
|
51 ++temp_str_len;
|
|
52 c=test_string[temp_str_len];
|
|
53 }
|
|
54 tmp_pos=test_string+temp_str_len;
|
|
55 if (*tmp_pos == 0)
|
|
56 break_loop = true;
|
|
57 *tmp_pos = 0;
|
|
58 if (temp_str_len)
|
|
59 {
|
|
60 if ( decode_step == 1)
|
|
61 pNPCTopics[i].pText =RemoveQuotes(test_string);
|
|
62 }
|
|
63 else
|
|
64 {
|
|
65 break_loop = true;
|
|
66 }
|
|
67 ++decode_step;
|
|
68 test_string=tmp_pos+1;
|
|
69 } while ((decode_step<2)&&!break_loop);
|
|
70 }
|
|
71
|
|
72 if (pNPCTopicTXT_Raw)
|
|
73 pAllocator->FreeChunk(pNPCTopicTXT_Raw);
|
|
74 pNPCTopicTXT_Raw =NULL;
|
|
75 pNPCTopicTXT_Raw = (char *)pEvents_LOD->LoadRaw("npctopic.txt", 0);
|
|
76 strtok(pNPCTopicTXT_Raw, "\r");
|
|
77
|
|
78 for (i=0; i<579; ++i)
|
|
79 {
|
|
80 test_string = strtok(NULL, "\r") + 1;
|
|
81 break_loop = false;
|
|
82 decode_step=0;
|
|
83 do
|
|
84 {
|
|
85 c = *(unsigned char*)test_string;
|
|
86 temp_str_len = 0;
|
|
87 while((c!='\t')&&(c>0))
|
|
88 {
|
|
89 ++temp_str_len;
|
|
90 c=test_string[temp_str_len];
|
|
91 }
|
|
92 tmp_pos=test_string+temp_str_len;
|
|
93 if (*tmp_pos == 0)
|
|
94 break_loop = true;
|
|
95 *tmp_pos = 0;
|
|
96 if (temp_str_len)
|
|
97 {
|
|
98 if ( decode_step == 1)
|
|
99 pNPCTopics[i].pTopic = RemoveQuotes(test_string);
|
|
100 }
|
|
101 else
|
|
102 {
|
|
103 break_loop = true;
|
|
104 }
|
|
105 ++decode_step;
|
|
106 test_string=tmp_pos+1;
|
|
107 } while ((decode_step<2)&&!break_loop);
|
|
108 }
|
|
109
|
|
110 if (pNPCDistTXT_Raw)
|
|
111 pAllocator->FreeChunk(pNPCDistTXT_Raw);
|
|
112 pNPCDistTXT_Raw = NULL;
|
|
113 pNPCDistTXT_Raw = (char *)pEvents_LOD->LoadRaw("npcdist.txt", 0);
|
|
114 strtok(pNPCDistTXT_Raw, "\r");
|
|
115 strtok(NULL, "\r");
|
|
116
|
|
117 for (i=1; i<59; ++i)
|
|
118 {
|
|
119 test_string = strtok(NULL, "\r") + 1;
|
|
120 break_loop = false;
|
|
121 decode_step=0;
|
|
122 do
|
|
123 {
|
|
124 c = *(unsigned char*)test_string;
|
|
125 temp_str_len = 0;
|
|
126 while((c!='\t')&&(c>0))
|
|
127 {
|
|
128 ++temp_str_len;
|
|
129 c=test_string[temp_str_len];
|
|
130 }
|
|
131 tmp_pos=test_string+temp_str_len;
|
|
132 if (*tmp_pos == 0)
|
|
133 break_loop = true;
|
|
134 *tmp_pos = 0;
|
|
135 if (temp_str_len)
|
|
136 {
|
|
137 if ((decode_step>0)&&(decode_step<77))
|
|
138 {
|
291
|
139 pProfessionChance[decode_step].professionChancePerArea[i]=atoi(test_string);
|
251
|
140 }
|
|
141 else if (decode_step==0)
|
|
142 {
|
291
|
143 pProfessionChance[0].professionChancePerArea[i]=10;
|
251
|
144 }
|
|
145 }
|
|
146 else
|
|
147 {
|
|
148 break_loop = true;
|
|
149 }
|
|
150 ++decode_step;
|
|
151 test_string=tmp_pos+1;
|
|
152 } while ((decode_step<78)&&!break_loop);
|
|
153 }
|
|
154
|
|
155 for (i=0; i<78; ++i)
|
|
156 {
|
291
|
157 pProfessionChance[i].uTotalprofChance=0;
|
251
|
158 for (int ii=1; ii<59; ++ii)
|
|
159 {
|
291
|
160 pProfessionChance[i].uTotalprofChance+=pProfessionChance[i].professionChancePerArea[ii];
|
251
|
161 }
|
|
162 }
|
|
163
|
|
164 if (pNPCDistTXT_Raw)
|
|
165 {
|
|
166 pAllocator->FreeChunk(pNPCDistTXT_Raw);
|
|
167 pNPCDistTXT_Raw = NULL;
|
|
168 }
|
|
169 }
|
|
170
|
|
171 //----- (00476C60) --------------------------------------------------------
|
|
172 void NPCStats::_476C60()
|
|
173 {
|
|
174 for (unsigned int i = 1; i < uNumNewNPCs; ++i)
|
291
|
175 pNewNPCData[i].pName = pNPCUnicNames[i - 1];
|
251
|
176
|
|
177 if (pParty->pHirelings[0].pName)
|
|
178 pParty->pHirelings[0].pName = pParty->pHireling1Name;
|
|
179 if (pParty->pHirelings[1].pName)
|
|
180 pParty->pHirelings[1].pName = pParty->pHireling2Name;
|
|
181 }
|
|
182
|
|
183 //----- (00476CB5) --------------------------------------------------------
|
291
|
184 void NPCStats::InitializeNPCData()
|
251
|
185 {
|
291
|
186 int i;
|
|
187 char* test_string;
|
|
188 unsigned char c;
|
|
189 bool break_loop;
|
|
190 unsigned int temp_str_len;
|
|
191 char* tmp_pos;
|
|
192 int decode_step;
|
|
193
|
|
194 pNPCDataTXT_Raw = (char *)pEvents_LOD->LoadRaw("npcdata.txt", 0);
|
|
195 strtok(pNPCDataTXT_Raw, "\r");
|
|
196 strtok(NULL, "\r");
|
251
|
197
|
291
|
198 for (i=0; i<500; ++i)
|
251
|
199 {
|
291
|
200 test_string = strtok(NULL, "\r") + 1;
|
|
201 break_loop = false;
|
|
202 decode_step=0;
|
|
203 do
|
251
|
204 {
|
291
|
205 c = *(unsigned char*)test_string;
|
|
206 temp_str_len = 0;
|
|
207 while((c!='\t')&&(c>0))
|
251
|
208 {
|
291
|
209 ++temp_str_len;
|
|
210 c=test_string[temp_str_len];
|
|
211 }
|
|
212 tmp_pos=test_string+temp_str_len;
|
|
213 if (*tmp_pos == 0)
|
|
214 break_loop = true;
|
|
215 *tmp_pos = 0;
|
|
216 if (temp_str_len)
|
|
217 { //i+1
|
|
218 switch (decode_step)
|
251
|
219 {
|
291
|
220 case 1:
|
|
221 pNPCUnicNames[i] = RemoveQuotes(test_string);
|
|
222 pNPCData[i+1].pName=pNPCUnicNames[i];
|
251
|
223 break;
|
291
|
224 case 2:
|
|
225 pNPCData[i+1].uPortraitID = atoi(test_string);
|
251
|
226 break;
|
|
227 case 6:
|
291
|
228 pNPCData[i+1].Location2D = atoi(test_string);
|
251
|
229 break;
|
|
230 case 7:
|
291
|
231 pNPCData[i+1].uProfession = atoi(test_string);
|
251
|
232 break;
|
|
233 case 8:
|
291
|
234 pNPCData[i+1].greet = atoi(test_string);
|
251
|
235 break;
|
|
236 case 9:
|
291
|
237 pNPCData[i+1].joins = (*test_string == 'y')?1:0;
|
251
|
238 break;
|
|
239 case 10:
|
291
|
240 pNPCData[i+1].evt_A = atoi(test_string);
|
251
|
241 break;
|
|
242 case 11:
|
291
|
243 pNPCData[i+1].evt_B = atoi(test_string);
|
251
|
244 break;
|
|
245 case 12:
|
291
|
246 pNPCData[i+1].evt_C = atoi(test_string);
|
251
|
247 break;
|
|
248 case 13:
|
291
|
249 pNPCData[i+1].evt_D = atoi(test_string);
|
251
|
250 break;
|
|
251 case 14:
|
291
|
252 pNPCData[i+1].evt_E = atoi(test_string);
|
251
|
253 break;
|
291
|
254 case 15:
|
|
255 pNPCData[i+1].evt_F = atoi(test_string);
|
251
|
256 break;
|
|
257 }
|
|
258 }
|
291
|
259 ++decode_step;
|
|
260 test_string=tmp_pos+1;
|
|
261 } while ((decode_step<16)&&!break_loop);
|
251
|
262 }
|
291
|
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
|
251
|
272 {
|
291
|
273 c = *(unsigned char*)test_string;
|
|
274 temp_str_len = 0;
|
|
275 while((c!='\t')&&(c>0))
|
251
|
276 {
|
291
|
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)
|
251
|
287 {
|
291
|
288 case 1:
|
|
289 pNPCGreetings[i].pGreeting1 = RemoveQuotes(test_string);
|
|
290 break;
|
|
291 case 2:
|
|
292 pNPCGreetings[i].pGreeting2 = RemoveQuotes(test_string);
|
|
293 break;
|
251
|
294 }
|
|
295 }
|
291
|
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
|
|
324 if (decode_step==1)
|
251
|
325 {
|
291
|
326 pGroups[i] = atoi(test_string);
|
251
|
327 }
|
291
|
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 }
|
251
|
365 }
|
|
366
|
|
367 //----- (0047702F) --------------------------------------------------------
|
|
368 void NPCStats::Initialize()
|
291
|
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;
|
251
|
377
|
291
|
378 InitializeNPCData();
|
|
379 InitializeNPCText();
|
|
380 InitializeQuests();
|
|
381 InitializeAutonotes();
|
|
382 InitializeAwards();
|
|
383 InitializeTransitions();
|
|
384 InitializeMerchants();
|
|
385 InitializeScrolls();
|
251
|
386
|
291
|
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)
|
251
|
394 {
|
291
|
395 test_string = strtok(NULL, "\r") + 1;
|
|
396 break_loop = false;
|
|
397 decode_step=0;
|
|
398 do
|
251
|
399 {
|
291
|
400 c = *(unsigned char*)test_string;
|
|
401 temp_str_len = 0;
|
|
402 if (c=='\t')
|
251
|
403 {
|
291
|
404 if ( (decode_step == 1)&&(!uNumNPCNames[1]))
|
|
405 uNumNPCNames[1]=i;
|
251
|
406 }
|
|
407 else
|
|
408 {
|
291
|
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 }
|
251
|
431 }
|
291
|
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
|
251
|
451 {
|
291
|
452 c = *(unsigned char*)test_string;
|
|
453 temp_str_len = 0;
|
|
454 while((c!='\t')&&(c>0))
|
251
|
455 {
|
291
|
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 }
|
251
|
482 }
|
291
|
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);
|
251
|
491 }
|
291
|
492 uNumNPCProfessions = 59;
|
251
|
493 }
|
|
494
|
|
495 //----- (00477266) --------------------------------------------------------
|
|
496 void NPCStats::Release()
|
|
497 {
|
291
|
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;
|
251
|
516 }
|
|
517
|
|
518 //----- (0047730C) --------------------------------------------------------
|
291
|
519 bool CheckPortretAgainsSex(int a1, int)
|
251
|
520 {
|
291
|
521 return true;
|
251
|
522 }
|
|
523 // 47730C: using guessed type int __stdcall const_1(int);
|
|
524
|
|
525 //----- (0047732C) --------------------------------------------------------
|
291
|
526 void NPCStats::InitializeAdditionalNPCs(NPCData *pNPCDataBuff, int npc_uid, int uLocation2D, int uMapId)
|
251
|
527 {
|
292
|
528 int rep_gen;
|
291
|
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
|
251
|
534 signed int result; // eax@39
|
291
|
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,
|
292
|
552 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0};
|
251
|
553
|
|
554
|
291
|
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;
|
251
|
563
|
291
|
564 do
|
251
|
565 {
|
291
|
566 switch ( uRace )
|
251
|
567 {
|
291
|
568 case 0:
|
|
569 if ( uNPCSex == 0 )
|
|
570 {
|
|
571 uPortretMin = 2;
|
|
572 uPortretMax = 100;
|
251
|
573 }
|
|
574 else
|
|
575 {
|
291
|
576 uPortretMin = 201;
|
|
577 uPortretMax = 250;
|
251
|
578 }
|
291
|
579
|
251
|
580 case 1:
|
291
|
581 if ( uNPCSex == 0 )
|
251
|
582 {
|
291
|
583 uPortretMin = 400;
|
|
584 uPortretMax = 430;
|
251
|
585 }
|
|
586 else
|
|
587 {
|
291
|
588 uPortretMin = 460;
|
|
589 uPortretMax = 490;
|
251
|
590 }
|
|
591 break;
|
|
592 case 2:
|
291
|
593 if ( uNPCSex == 0 )
|
251
|
594 {
|
291
|
595 uPortretMin = 500;
|
|
596 uPortretMax = 520;
|
251
|
597 }
|
|
598 else
|
|
599 {
|
291
|
600 uPortretMin = 530;
|
|
601 uPortretMax = 550;
|
251
|
602 }
|
|
603 break;
|
|
604 case 3:
|
291
|
605 if ( uNPCSex == 0 )
|
251
|
606 {
|
291
|
607 uPortretMin = 300;
|
|
608 uPortretMax = 330;
|
251
|
609 }
|
|
610 else
|
|
611 {
|
291
|
612 uPortretMin = 360;
|
|
613 uPortretMax = 387;
|
251
|
614 }
|
291
|
615
|
251
|
616 break;
|
|
617 }
|
291
|
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 )
|
251
|
624 {
|
291
|
625 uGeneratedPortret = uPortretMin;
|
|
626 break_gen = true;
|
251
|
627 }
|
|
628 }
|
291
|
629 while(!break_gen);
|
251
|
630
|
291
|
631 pNPCDataBuff->uPortraitID = uGeneratedPortret;
|
|
632 pNPCDataBuff->uFlags = 0;
|
|
633 pNPCDataBuff->fame = 0;
|
|
634 //generate reputation
|
292
|
635 rep_gen = rand() % 100 + 1;
|
251
|
636
|
292
|
637 if ( rep_gen >= 60 )
|
251
|
638 {
|
292
|
639 if ( rep_gen >= 90 )
|
251
|
640 {
|
292
|
641 if ( rep_gen >= 95 )
|
251
|
642 {
|
292
|
643 if ( rep_gen >= 98 )
|
291
|
644 pNPCDataBuff->rep = -600;
|
251
|
645 else
|
291
|
646 pNPCDataBuff->rep = 400;
|
251
|
647 }
|
|
648 else
|
291
|
649 pNPCDataBuff->rep = -300;
|
251
|
650 }
|
|
651 else
|
291
|
652 pNPCDataBuff->rep = 200;
|
|
653
|
251
|
654 }
|
|
655 else
|
291
|
656 pNPCDataBuff->rep = 0;
|
251
|
657
|
291
|
658 max_prof_cap = rand() % pProfessionChance[uMapId].uTotalprofChance+1;
|
|
659 test_prof_summ = 0;
|
|
660 gen_profession = 0;
|
251
|
661
|
291
|
662 if ( max_prof_cap > 0 )
|
251
|
663 {
|
|
664 do
|
291
|
665 test_prof_summ += pProfessionChance[uMapId].professionChancePerArea[gen_profession++];
|
|
666 while ( test_prof_summ < max_prof_cap );
|
251
|
667 }
|
291
|
668 pNPCDataBuff->uProfession = gen_profession - 1;
|
|
669 pNPCDataBuff->Location2D = uLocation2D;
|
|
670 pNPCDataBuff->field_24 = 1;
|
|
671 pNPCDataBuff->joins = 1;
|
251
|
672 }
|
|
673
|
|
674
|
257
|
675 //----- (00476387) --------------------------------------------------------
|
|
676 bool PartyHasDragon()
|
|
677 {
|
|
678 return pNPCStats->pNewNPCData[57].Hired();
|
|
679 }
|
251
|
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()
|
|
721 {
|
|
722
|
|
723 int i;
|
|
724 char* test_string;
|
|
725 unsigned char c;
|
|
726 bool break_loop;
|
|
727 unsigned int temp_str_len;
|
|
728 char* tmp_pos;
|
|
729 int decode_step;
|
|
730
|
|
731 if ( pAwardsTXT_Raw )
|
|
732 pAllocator->FreeChunk(pAwardsTXT_Raw);
|
|
733 pAwardsTXT_Raw = NULL;
|
|
734 pAwardsTXT_Raw = (char *)pEvents_LOD->LoadRaw("awards.txt", 0);
|
|
735 strtok(pAwardsTXT_Raw, "\r");
|
|
736
|
|
737 for (i=1; i<104; ++i)
|
|
738 {
|
|
739 test_string = strtok(NULL, "\r") + 1;
|
|
740 break_loop = false;
|
|
741 decode_step=0;
|
|
742 do
|
|
743 {
|
|
744 c = *(unsigned char*)test_string;
|
|
745 temp_str_len = 0;
|
|
746 while((c!='\t')&&(c>0))
|
|
747 {
|
|
748 ++temp_str_len;
|
|
749 c=test_string[temp_str_len];
|
|
750 }
|
|
751 tmp_pos=test_string+temp_str_len;
|
|
752 if (*tmp_pos == 0)
|
|
753 break_loop = true;
|
|
754 *tmp_pos = 0;
|
|
755 if (temp_str_len)
|
|
756 {
|
|
757 if (decode_step==1)
|
|
758 pAwards[i].pText=RemoveQuotes(test_string);
|
|
759 else if (decode_step==2)
|
|
760 pAwards[i].uSort=atoi(test_string);
|
|
761 }
|
|
762 else
|
|
763 {
|
|
764 break_loop = true;
|
|
765 }
|
|
766 ++decode_step;
|
|
767 test_string=tmp_pos+1;
|
|
768 } while ((decode_step<3)&&!break_loop);
|
|
769 }
|
|
770
|
|
771 }
|
|
772 // 7241C8: using guessed type int dword_7241C8;
|
|
773
|
|
774 //----- (004764C2) --------------------------------------------------------
|
|
775 void InitializeScrolls()
|
|
776 {
|
|
777
|
|
778 int i;
|
|
779 char* test_string;
|
|
780 unsigned char c;
|
|
781 bool break_loop;
|
|
782 unsigned int temp_str_len;
|
|
783 char* tmp_pos;
|
|
784 int decode_step;
|
|
785
|
|
786 if ( pScrollsTXT_Raw )
|
|
787 pAllocator->FreeChunk(pScrollsTXT_Raw);
|
|
788 pScrollsTXT_Raw = NULL;
|
|
789 pScrollsTXT_Raw = (char *)pEvents_LOD->LoadRaw("scroll.txt", 0);
|
|
790 strtok(pScrollsTXT_Raw, "\r");
|
|
791 for (i=0; i<82; ++i)
|
|
792 {
|
|
793 test_string = strtok(NULL, "\r") + 1;
|
|
794 break_loop = false;
|
|
795 decode_step=0;
|
|
796 do
|
|
797 {
|
|
798 c = *(unsigned char*)test_string;
|
|
799 temp_str_len = 0;
|
|
800 while((c!='\t')&&(c>0))
|
|
801 {
|
|
802 ++temp_str_len;
|
|
803 c=test_string[temp_str_len];
|
|
804 }
|
|
805 tmp_pos=test_string+temp_str_len;
|
|
806 if (*tmp_pos == 0)
|
|
807 break_loop = true;
|
|
808 *tmp_pos = 0;
|
|
809 if (temp_str_len)
|
|
810 {
|
|
811 if ( decode_step == 1)
|
|
812 pScrolls[i]=RemoveQuotes(test_string);
|
|
813 }
|
|
814 else
|
|
815 {
|
|
816 break_loop = true;
|
|
817 }
|
|
818 ++decode_step;
|
|
819 test_string=tmp_pos+1;
|
|
820 } while ((decode_step<2)&&!break_loop);
|
|
821 }
|
|
822 }
|
|
823
|
|
824
|
|
825 //----- (00476590) --------------------------------------------------------
|
|
826 void InitializeMerchants()
|
|
827 {
|
|
828 int i;
|
|
829 char* test_string;
|
|
830 unsigned char c;
|
|
831 bool break_loop;
|
|
832 unsigned int temp_str_len;
|
|
833 char* tmp_pos;
|
|
834 int decode_step;
|
|
835
|
|
836 if ( pMerchantsTXT_Raw )
|
|
837 pAllocator->FreeChunk(pMerchantsTXT_Raw);
|
|
838 pMerchantsTXT_Raw = NULL;
|
|
839 pMerchantsTXT_Raw = (char *)pEvents_LOD->LoadRaw("merchant.txt", 0);
|
|
840 strtok(pMerchantsTXT_Raw, "\r");
|
|
841
|
|
842 for (i=0; i<7; ++i)
|
|
843 {
|
|
844 test_string = strtok(NULL, "\r") + 1;
|
|
845 break_loop = false;
|
|
846 decode_step=0;
|
|
847 do
|
|
848 {
|
|
849 c = *(unsigned char*)test_string;
|
|
850 temp_str_len = 0;
|
|
851 while((c!='\t')&&(c>0))
|
|
852 {
|
|
853 ++temp_str_len;
|
|
854 c=test_string[temp_str_len];
|
|
855 }
|
|
856 tmp_pos=test_string+temp_str_len;
|
|
857 if (*tmp_pos == 0)
|
|
858 break_loop = true;
|
|
859 *tmp_pos = 0;
|
|
860 if (temp_str_len)
|
|
861 {
|
|
862 switch (decode_step)
|
|
863 {
|
|
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 }
|
|
877 }
|
|
878 else
|
|
879 {
|
|
880 break_loop = true;
|
|
881 }
|
|
882 ++decode_step;
|
|
883 test_string=tmp_pos+1;
|
|
884 } while ((decode_step<5)&&!break_loop);
|
|
885 }
|
|
886
|
|
887 }
|
|
888
|
|
889 //----- (00476682) --------------------------------------------------------
|
|
890 void InitializeTransitions()
|
|
891 {
|
|
892 int i;
|
|
893 char* test_string;
|
|
894 unsigned char c;
|
|
895 bool break_loop;
|
|
896 unsigned int temp_str_len;
|
|
897 char* tmp_pos;
|
|
898 int decode_step;
|
|
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;
|
|
949
|
|
950 if ( pAutonoteTXT_Raw )
|
|
951 pAllocator->FreeChunk(pAutonoteTXT_Raw);
|
|
952 pAutonoteTXT_Raw = 0;
|
|
953 pAutonoteTXT_Raw = (char *)pEvents_LOD->LoadRaw("autonote.txt", 0);
|
|
954 strtok(pAutonoteTXT_Raw, "\r");
|
|
955
|
|
956 for (i=0; i<195; ++i)
|
|
957 {
|
|
958 test_string = strtok(NULL, "\r") + 1;
|
|
959 break_loop = false;
|
|
960 decode_step=0;
|
|
961 do
|
|
962 {
|
|
963 c = *(unsigned char*)test_string;
|
|
964 temp_str_len = 0;
|
|
965 while((c!='\t')&&(c>0))
|
|
966 {
|
|
967 ++temp_str_len;
|
|
968 c=test_string[temp_str_len];
|
|
969 }
|
|
970 tmp_pos=test_string+temp_str_len;
|
|
971 if (*tmp_pos == 0)
|
|
972 break_loop = true;
|
|
973 *tmp_pos = 0;
|
|
974 if (temp_str_len)
|
|
975 {
|
|
976 switch (decode_step)
|
|
977 {
|
|
978 case 1:
|
|
979 pAutonoteTxt[i].pText=RemoveQuotes(test_string);
|
|
980 break;
|
|
981 case 2:
|
|
982 {
|
|
983 if ( !_strcmpi(test_string, "potion"))
|
|
984 {
|
|
985 pAutonoteTxt[i].eType = AUTONOTE_POTION_RECEPIE;
|
|
986 break;
|
|
987 }
|
|
988 if ( !_strcmpi(test_string, "stat") )
|
|
989 {
|
|
990 pAutonoteTxt[i].eType = AUTONOTE_STAT_HINT;
|
|
991 break;
|
|
992 }
|
|
993 if ( !_strcmpi(test_string, "seer") )
|
|
994 {
|
|
995 pAutonoteTxt[i].eType = AUTONOTE_SEER;
|
|
996 break;
|
|
997 }
|
|
998 if ( !_strcmpi(test_string, "obelisk") )
|
|
999 {
|
|
1000 pAutonoteTxt[i].eType = AUTONOTE_OBELISK;
|
|
1001 break;
|
|
1002 }
|
|
1003 if ( !_strcmpi(test_string, "teacher") )
|
|
1004 {
|
|
1005 pAutonoteTxt[i].eType = AUTONOTE_TEACHER;
|
|
1006 break;
|
|
1007 }
|
|
1008 pAutonoteTxt[i].eType =AUTONOTE_MISC;
|
|
1009 break;
|
|
1010 }
|
|
1011 }
|
|
1012 }
|
|
1013 else
|
|
1014 {
|
|
1015 break_loop = true;
|
|
1016 }
|
|
1017 ++decode_step;
|
|
1018 test_string=tmp_pos+1;
|
|
1019 } while ((decode_step<3)&&!break_loop);
|
|
1020 }
|
|
1021 }
|
|
1022
|
|
1023
|
|
1024 //----- (004768A9) --------------------------------------------------------
|
|
1025 void __cdecl InitializeQuests()
|
|
1026 {
|
|
1027 int i;
|
|
1028 char* test_string;
|
|
1029 unsigned char c;
|
|
1030 bool break_loop;
|
|
1031 unsigned int temp_str_len;
|
|
1032 char* tmp_pos;
|
|
1033 int decode_step;
|
|
1034
|
|
1035 if ( pQuestsTXT_Raw )
|
|
1036 pAllocator->FreeChunk(pQuestsTXT_Raw);
|
|
1037 pQuestsTXT_Raw = NULL;
|
|
1038 pQuestsTXT_Raw = (char *)pEvents_LOD->LoadRaw("quests.txt", 0);
|
|
1039 strtok(pQuestsTXT_Raw, "\r");
|
|
1040
|
|
1041 for (i=0; i<512; ++i)
|
|
1042 {
|
|
1043 test_string = strtok(NULL, "\r") + 1;
|
|
1044 break_loop = false;
|
|
1045 decode_step=0;
|
|
1046 do
|
|
1047 {
|
|
1048 c = *(unsigned char*)test_string;
|
|
1049 temp_str_len = 0;
|
|
1050 while((c!='\t')&&(c>0))
|
|
1051 {
|
|
1052 ++temp_str_len;
|
|
1053 c=test_string[temp_str_len];
|
|
1054 }
|
|
1055 tmp_pos=test_string+temp_str_len;
|
|
1056 if (*tmp_pos == 0)
|
|
1057 break_loop = true;
|
|
1058 *tmp_pos = 0;
|
|
1059 if (temp_str_len)
|
|
1060 {
|
|
1061 if ( decode_step == 1)
|
|
1062 pQuestTable[i] =RemoveQuotes(test_string);
|
|
1063 }
|
|
1064 else
|
|
1065 {
|
|
1066 break_loop = true;
|
|
1067 }
|
|
1068 ++decode_step;
|
|
1069 test_string=tmp_pos+1;
|
|
1070 } while ((decode_step<2)&&!break_loop);
|
|
1071 }
|
|
1072 }
|
|
1073
|