Mercurial > mm7
annotate NPC.cpp @ 1395:8d4ec56416ef
Fix to ticket #69 array_50A2B0 being accessed outside of bounds
author | Nomad |
---|---|
date | Thu, 18 Jul 2013 17:07:49 +0200 |
parents | ae6c8e1ddef4 |
children | 38df78aba732 |
rev | line source |
---|---|
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
1 #ifdef _MSC_VER |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
2 #define _CRT_SECURE_NO_WARNINGS |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
3 #endif |
251 | 4 |
5 #include "Allocator.h" | |
6 #include "texts.h" | |
7 #include "LOD.h" | |
8 #include "Autonotes.h" | |
9 #include "Awards.h" | |
10 #include "mm7_data.h" | |
11 #include "MM7.h" | |
1016 | 12 #include "Party.h" |
251 | 13 #include "NPC.h" |
1295 | 14 #include "GUIWindow.h" |
15 #include "VideoPlayer.h" | |
16 #include "Events.h" | |
1299 | 17 #include "UI\UIHouses.h" |
1295 | 18 #include "Indoor.h" |
19 #include "MapInfo.h" | |
251 | 20 |
629 | 21 int pDialogueNPCCount; |
1206
ab6560001f5b
arrays to std::arrays phase 2 - some more arrays converted
Grumpy7
parents:
1165
diff
changeset
|
22 std::array<struct Texture *, 6> pDialogueNPCPortraits; |
629 | 23 int uNumDialogueNPCPortraits; // weak |
24 struct NPCStats *pNPCStats = nullptr; | |
25 | |
251 | 26 void InitializeAwards(); |
27 void InitializeScrolls(); | |
28 void InitializeMerchants(); | |
29 void InitializeTransitions(); | |
30 void InitializeAutonotes(); | |
31 void InitializeQuests(); | |
307 | 32 bool CheckPortretAgainstSex(int portret_num, int sex); |
251 | 33 |
781 | 34 //----- (004459F9) -------------------------------------------------------- |
35 NPCData *__fastcall GetNPCData(signed int npcid) | |
36 { | |
37 unsigned int v1; // esi@1 | |
38 NPCData *result; // eax@5 | |
39 int v3; // esi@9 | |
40 int v4; // ecx@9 | |
41 //int v5; // edx@9 | |
42 //NPCData *v6; // eax@9 | |
43 char *v7; // ebx@14 | |
44 NPCData *v8; // edi@14 | |
45 char v9; // al@22 | |
46 char v10; | |
47 //std::string v10; // [sp-18h] [bp-2Ch]@4 | |
48 int v11; | |
49 //const char *v11; // [sp-8h] [bp-1Ch]@4 | |
50 int v12; // [sp-4h] [bp-18h]@4 | |
51 int v13; | |
52 char *v14; | |
53 //std::string *v13; // [sp+Ch] [bp-8h]@4 | |
54 int a3; // [sp+13h] [bp-1h]@4 | |
55 int i; | |
56 | |
57 /*v1 = npcid; | |
58 if ( (npcid & 0x80000000u) == 0 ) | |
59 { | |
60 if ( (signed int)npcid < 5000 ) | |
61 { | |
62 if ( (signed int)npcid >= 501 ) | |
63 { | |
64 MessageBoxW(nullptr, L"NPC id exceeds MAX_DATA!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Events.cpp:1984", 0); | |
65 } | |
66 return &pNPCStats->pNewNPCData[v1]; | |
67 } | |
68 return &pNPCStats->array_13EF4[npcid - 5000]; | |
69 } | |
70 if ( (signed int)npcid >= 5000 ) | |
71 return &pNPCStats->array_13EF4[npcid - 5000]; | |
72 if ( (sDialogue_SpeakingActorNPC_ID & 0x80000000u) == 0 ) | |
73 { | |
74 result = 0; | |
75 } | |
76 else | |
77 { | |
78 v3 = abs((int)sDialogue_SpeakingActorNPC_ID) - 1; | |
79 v4 = 0; | |
80 v5 = 0; | |
81 v6 = pParty->pHirelings; | |
82 do | |
83 { | |
84 if ( v6->pName ) | |
85 pTmpBuf[v4++] = v5; | |
86 ++v6; | |
87 ++v5; | |
88 } | |
89 while ( (signed int)v6 < (signed int)&pParty->pPickedItem ); | |
90 v13 = 0; | |
91 if ( (signed int)pNPCStats->uNumNewNPCs > 0 ) | |
92 { | |
93 v7 = &pTmpBuf[v4]; | |
94 v8 = pNPCStats->pNewNPCData; | |
95 do | |
96 { | |
97 if ( v8->uFlags & 0x80 | |
98 && (!pParty->pHirelings[0].pName || strcmp(v8->pName, pParty->pHirelings[0].pName)) | |
99 && (!pParty->pHirelings[1].pName || strcmp(v8->pName, pParty->pHirelings[1].pName)) ) | |
100 *v7++ = (char)v13 + 2; | |
101 v13 = (std::string *)((char *)v13 + 1); | |
102 ++v8; | |
103 } | |
104 while ( (signed int)v13 < (signed int)pNPCStats->uNumNewNPCs ); | |
105 } | |
106 v9 = pTmpBuf[v3]; | |
107 if ( (unsigned __int8)v9 >= 2u ) | |
108 result = &pNPCStats->pNPCData[(unsigned __int8)v9 + 499]; | |
109 else | |
110 result = &pParty->pHirelings[(unsigned __int8)v9]; | |
111 } | |
112 return result;*/ | |
113 v1 = npcid; | |
114 if ( npcid >= 0 ) | |
115 { | |
116 if ( npcid < 5000 ) | |
117 { | |
118 if ( npcid >= 501 ) | |
119 { | |
120 MessageBoxW(nullptr, L"NPC id exceeds MAX_DATA!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Events.cpp:1984", 0); | |
121 } | |
122 return &pNPCStats->pNewNPCData[v1];// - 1]; | |
123 } | |
124 return &pNPCStats->pAdditionalNPC[npcid - 5000]; | |
125 } | |
126 | |
127 | |
128 if ( npcid >= 5000 ) | |
129 return &pNPCStats->pAdditionalNPC[npcid - 5000]; | |
130 if (sDialogue_SpeakingActorNPC_ID >= 0) | |
131 { | |
132 result = 0; | |
133 } | |
134 else | |
135 { | |
136 v3 = abs(sDialogue_SpeakingActorNPC_ID) - 1; | |
137 v4 = 0; | |
138 | |
139 for (i = 0; i < 2; ++i) | |
140 { | |
141 if (pParty->pHirelings[i].pName) | |
142 pTmpBuf[v4++] = i; | |
143 } | |
144 | |
145 if (pNPCStats->uNumNewNPCs > 0) | |
146 { | |
147 for (i = 0; i < pNPCStats->uNumNewNPCs; ++i) | |
148 { | |
149 if (pNPCStats->pNewNPCData[i].Hired()) | |
150 { | |
151 if (!pParty->pHirelings[0].pName || strcmp((char *)pNPCStats->pNewNPCData[i].pName, (char *)pParty->pHirelings[0].pName)) | |
152 { | |
153 if (!pParty->pHirelings[1].pName || strcmp((char *)pNPCStats->pNewNPCData[i].pName, (char *)pParty->pHirelings[1].pName)) | |
154 pTmpBuf[v4++] = i + 2; | |
155 } | |
156 } | |
157 } | |
158 } | |
159 | |
160 v9 = pTmpBuf[v3]; | |
161 if ( v9 >= 2 ) | |
162 result = &pNPCStats->pNPCData[499 + v9]; | |
163 else | |
164 result = &pParty->pHirelings[v9]; | |
165 } | |
1099 | 166 return result; |
781 | 167 } |
168 | |
169 //----- (00445B2C) -------------------------------------------------------- | |
1094 | 170 struct NPCData * GetNewNPCData( signed int npcid, int* npc_indx ) |
171 { | |
172 | |
173 int* v3; // edi@1 | |
781 | 174 NPCData *result; // eax@5 |
175 int v5; // esi@9 | |
176 int v6; // ecx@9 | |
177 char v11; // al@23 | |
178 | |
1094 | 179 v3 = npc_indx; |
781 | 180 if ( npcid >= 0 ) |
181 { | |
182 if ( npcid < 5000 ) | |
183 { | |
184 if ( npcid >= 501 ) | |
185 { | |
1094 | 186 MessageBoxW(nullptr, L"NPC id exceeds MAX_DATA!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Events.cpp:2040", 0); |
781 | 187 } |
1094 | 188 *v3 = npcid; |
189 return &pNPCStats->pNewNPCData[npcid]; | |
781 | 190 } |
1094 | 191 *npc_indx = npcid - 5000; |
781 | 192 return &pNPCStats->pAdditionalNPC[npcid - 5000]; |
193 } | |
194 if ( npcid >= 5000 ) | |
1094 | 195 { |
196 *npc_indx = npcid - 5000; | |
197 return &pNPCStats->pAdditionalNPC[npcid - 5000]; | |
198 } | |
781 | 199 if ( sDialogue_SpeakingActorNPC_ID >= 0 ) |
200 { | |
1094 | 201 *npc_indx = 0; |
202 result = NULL; | |
781 | 203 } |
204 else | |
205 { | |
1094 | 206 v5 = abs(sDialogue_SpeakingActorNPC_ID) - 1; |
781 | 207 v6 = 0; |
1094 | 208 for (int i=0; i<2; ++i) |
781 | 209 { |
1094 | 210 if ( pParty->pHirelings[i].pName ) |
211 pTmpBuf[v6++] = i; | |
212 | |
213 } | |
214 for (int i=0; i< pNPCStats->uNumNewNPCs; ++i) | |
781 | 215 { |
1094 | 216 if ( pNPCStats->pNewNPCData[i].Hired() |
217 && (!pParty->pHirelings[0].pName || strcmp(pNPCStats->pNewNPCData[i].pName, pParty->pHirelings[0].pName)) | |
218 && (!pParty->pHirelings[1].pName || strcmp(pNPCStats->pNewNPCData[i].pName, pParty->pHirelings[1].pName)) ) | |
219 { | |
220 pTmpBuf[v6++]=i+2; | |
221 } | |
781 | 222 } |
223 v11 = pTmpBuf[v5]; | |
1094 | 224 |
225 if ( v11 >= 2u ) | |
781 | 226 { |
1094 | 227 *v3 = v11 - 2; |
228 result = &pNPCStats->pNewNPCData[v11 - 2]; | |
781 | 229 } |
230 else | |
231 { | |
1094 | 232 *v3 = v11; |
233 result = &pParty->pHirelings[v11]; | |
781 | 234 } |
235 } | |
236 return result; | |
237 } | |
238 | |
251 | 239 //----- (00476977) -------------------------------------------------------- |
291 | 240 void NPCStats::InitializeNPCText() |
251 | 241 { |
242 int i; | |
243 char* test_string; | |
244 unsigned char c; | |
245 bool break_loop; | |
246 unsigned int temp_str_len; | |
247 char* tmp_pos; | |
248 int decode_step; | |
249 | |
250 if (pNPCTextTXT_Raw) | |
251 pAllocator->FreeChunk(pNPCTextTXT_Raw); | |
252 pNPCTextTXT_Raw =NULL; | |
253 pNPCTextTXT_Raw = (char *)pEvents_LOD->LoadRaw("npctext.txt", 0); | |
254 strtok(pNPCTextTXT_Raw, "\r"); | |
255 | |
256 for (i=0; i<789; ++i) | |
257 { | |
258 test_string = strtok(NULL, "\r") + 1; | |
259 break_loop = false; | |
260 decode_step=0; | |
261 do | |
262 { | |
263 c = *(unsigned char*)test_string; | |
264 temp_str_len = 0; | |
265 while((c!='\t')&&(c>0)) | |
266 { | |
267 ++temp_str_len; | |
268 c=test_string[temp_str_len]; | |
269 } | |
270 tmp_pos=test_string+temp_str_len; | |
271 if (*tmp_pos == 0) | |
272 break_loop = true; | |
273 *tmp_pos = 0; | |
274 if (temp_str_len) | |
275 { | |
276 if ( decode_step == 1) | |
277 pNPCTopics[i].pText =RemoveQuotes(test_string); | |
278 } | |
279 else | |
280 { | |
281 break_loop = true; | |
282 } | |
283 ++decode_step; | |
284 test_string=tmp_pos+1; | |
285 } while ((decode_step<2)&&!break_loop); | |
286 } | |
287 | |
288 if (pNPCTopicTXT_Raw) | |
289 pAllocator->FreeChunk(pNPCTopicTXT_Raw); | |
290 pNPCTopicTXT_Raw =NULL; | |
291 pNPCTopicTXT_Raw = (char *)pEvents_LOD->LoadRaw("npctopic.txt", 0); | |
292 strtok(pNPCTopicTXT_Raw, "\r"); | |
293 | |
294 for (i=0; i<579; ++i) | |
295 { | |
296 test_string = strtok(NULL, "\r") + 1; | |
297 break_loop = false; | |
298 decode_step=0; | |
299 do | |
300 { | |
301 c = *(unsigned char*)test_string; | |
302 temp_str_len = 0; | |
303 while((c!='\t')&&(c>0)) | |
304 { | |
305 ++temp_str_len; | |
306 c=test_string[temp_str_len]; | |
307 } | |
308 tmp_pos=test_string+temp_str_len; | |
309 if (*tmp_pos == 0) | |
310 break_loop = true; | |
311 *tmp_pos = 0; | |
312 if (temp_str_len) | |
313 { | |
314 if ( decode_step == 1) | |
315 pNPCTopics[i].pTopic = RemoveQuotes(test_string); | |
316 } | |
317 else | |
318 { | |
319 break_loop = true; | |
320 } | |
321 ++decode_step; | |
322 test_string=tmp_pos+1; | |
323 } while ((decode_step<2)&&!break_loop); | |
324 } | |
325 | |
326 if (pNPCDistTXT_Raw) | |
327 pAllocator->FreeChunk(pNPCDistTXT_Raw); | |
328 pNPCDistTXT_Raw = NULL; | |
329 pNPCDistTXT_Raw = (char *)pEvents_LOD->LoadRaw("npcdist.txt", 0); | |
330 strtok(pNPCDistTXT_Raw, "\r"); | |
331 strtok(NULL, "\r"); | |
332 | |
333 for (i=1; i<59; ++i) | |
334 { | |
335 test_string = strtok(NULL, "\r") + 1; | |
336 break_loop = false; | |
337 decode_step=0; | |
338 do | |
339 { | |
340 c = *(unsigned char*)test_string; | |
341 temp_str_len = 0; | |
342 while((c!='\t')&&(c>0)) | |
343 { | |
344 ++temp_str_len; | |
345 c=test_string[temp_str_len]; | |
346 } | |
347 tmp_pos=test_string+temp_str_len; | |
348 if (*tmp_pos == 0) | |
349 break_loop = true; | |
350 *tmp_pos = 0; | |
351 if (temp_str_len) | |
352 { | |
353 if ((decode_step>0)&&(decode_step<77)) | |
354 { | |
291 | 355 pProfessionChance[decode_step].professionChancePerArea[i]=atoi(test_string); |
251 | 356 } |
357 else if (decode_step==0) | |
358 { | |
291 | 359 pProfessionChance[0].professionChancePerArea[i]=10; |
251 | 360 } |
361 } | |
362 else | |
363 { | |
364 break_loop = true; | |
365 } | |
366 ++decode_step; | |
367 test_string=tmp_pos+1; | |
368 } while ((decode_step<78)&&!break_loop); | |
369 } | |
370 | |
825 | 371 for ( i = 0; i < 77; ++i ) |
251 | 372 { |
291 | 373 pProfessionChance[i].uTotalprofChance=0; |
825 | 374 for ( int ii = 1; ii < 59; ++ii ) |
251 | 375 { |
291 | 376 pProfessionChance[i].uTotalprofChance+=pProfessionChance[i].professionChancePerArea[ii]; |
251 | 377 } |
293 | 378 pProfessionChance[i].professionChancePerArea[0]=0; |
379 pProfessionChance[i].professionChancePerArea[59]=0; | |
251 | 380 } |
381 | |
382 if (pNPCDistTXT_Raw) | |
383 { | |
384 pAllocator->FreeChunk(pNPCDistTXT_Raw); | |
385 pNPCDistTXT_Raw = NULL; | |
386 } | |
387 } | |
388 | |
389 //----- (00476C60) -------------------------------------------------------- | |
390 void NPCStats::_476C60() | |
391 { | |
392 for (unsigned int i = 1; i < uNumNewNPCs; ++i) | |
291 | 393 pNewNPCData[i].pName = pNPCUnicNames[i - 1]; |
251 | 394 |
395 if (pParty->pHirelings[0].pName) | |
396 pParty->pHirelings[0].pName = pParty->pHireling1Name; | |
397 if (pParty->pHirelings[1].pName) | |
398 pParty->pHirelings[1].pName = pParty->pHireling2Name; | |
399 } | |
400 | |
401 //----- (00476CB5) -------------------------------------------------------- | |
291 | 402 void NPCStats::InitializeNPCData() |
251 | 403 { |
291 | 404 int i; |
405 char* test_string; | |
406 unsigned char c; | |
407 bool break_loop; | |
408 unsigned int temp_str_len; | |
409 char* tmp_pos; | |
410 int decode_step; | |
411 | |
412 pNPCDataTXT_Raw = (char *)pEvents_LOD->LoadRaw("npcdata.txt", 0); | |
413 strtok(pNPCDataTXT_Raw, "\r"); | |
414 strtok(NULL, "\r"); | |
251 | 415 |
291 | 416 for (i=0; i<500; ++i) |
251 | 417 { |
291 | 418 test_string = strtok(NULL, "\r") + 1; |
419 break_loop = false; | |
420 decode_step=0; | |
421 do | |
251 | 422 { |
291 | 423 c = *(unsigned char*)test_string; |
424 temp_str_len = 0; | |
425 while((c!='\t')&&(c>0)) | |
251 | 426 { |
291 | 427 ++temp_str_len; |
428 c=test_string[temp_str_len]; | |
429 } | |
430 tmp_pos=test_string+temp_str_len; | |
431 if (*tmp_pos == 0) | |
432 break_loop = true; | |
433 *tmp_pos = 0; | |
434 if (temp_str_len) | |
435 { //i+1 | |
436 switch (decode_step) | |
251 | 437 { |
291 | 438 case 1: |
439 pNPCUnicNames[i] = RemoveQuotes(test_string); | |
440 pNPCData[i+1].pName=pNPCUnicNames[i]; | |
251 | 441 break; |
291 | 442 case 2: |
443 pNPCData[i+1].uPortraitID = atoi(test_string); | |
251 | 444 break; |
445 case 6: | |
291 | 446 pNPCData[i+1].Location2D = atoi(test_string); |
251 | 447 break; |
448 case 7: | |
291 | 449 pNPCData[i+1].uProfession = atoi(test_string); |
251 | 450 break; |
451 case 8: | |
291 | 452 pNPCData[i+1].greet = atoi(test_string); |
251 | 453 break; |
454 case 9: | |
291 | 455 pNPCData[i+1].joins = (*test_string == 'y')?1:0; |
251 | 456 break; |
457 case 10: | |
291 | 458 pNPCData[i+1].evt_A = atoi(test_string); |
251 | 459 break; |
460 case 11: | |
291 | 461 pNPCData[i+1].evt_B = atoi(test_string); |
251 | 462 break; |
463 case 12: | |
291 | 464 pNPCData[i+1].evt_C = atoi(test_string); |
251 | 465 break; |
466 case 13: | |
291 | 467 pNPCData[i+1].evt_D = atoi(test_string); |
251 | 468 break; |
469 case 14: | |
291 | 470 pNPCData[i+1].evt_E = atoi(test_string); |
251 | 471 break; |
291 | 472 case 15: |
473 pNPCData[i+1].evt_F = atoi(test_string); | |
251 | 474 break; |
475 } | |
476 } | |
291 | 477 ++decode_step; |
478 test_string=tmp_pos+1; | |
479 } while ((decode_step<16)&&!break_loop); | |
251 | 480 } |
291 | 481 uNumNewNPCs = 501; |
482 pNPCGreetTXT_Raw = (char*)pEvents_LOD->LoadRaw("npcgreet.txt", 0); | |
483 strtok(pNPCGreetTXT_Raw, "\r"); | |
484 for (i=0; i<205; ++i) | |
485 { | |
486 test_string = strtok(NULL, "\r") + 1; | |
487 break_loop = false; | |
488 decode_step=0; | |
489 do | |
251 | 490 { |
291 | 491 c = *(unsigned char*)test_string; |
492 temp_str_len = 0; | |
493 while((c!='\t')&&(c>0)) | |
251 | 494 { |
291 | 495 ++temp_str_len; |
496 c=test_string[temp_str_len]; | |
497 } | |
498 tmp_pos=test_string+temp_str_len; | |
499 if (*tmp_pos == 0) | |
500 break_loop = true; | |
501 *tmp_pos = 0; | |
502 if (temp_str_len) | |
503 { //i+1 | |
504 switch (decode_step) | |
251 | 505 { |
291 | 506 case 1: |
507 pNPCGreetings[i].pGreeting1 = RemoveQuotes(test_string); | |
508 break; | |
509 case 2: | |
510 pNPCGreetings[i].pGreeting2 = RemoveQuotes(test_string); | |
511 break; | |
251 | 512 } |
513 } | |
291 | 514 ++decode_step; |
515 test_string=tmp_pos+1; | |
516 } while ((decode_step<3)&&!break_loop); | |
517 } | |
518 | |
519 pNCPGroupTXT_Raw = (char*)pEvents_LOD->LoadRaw("npcgroup.txt", 0); | |
520 strtok(pNCPGroupTXT_Raw, "\r"); | |
521 | |
522 for (i=0; i<51; ++i) | |
523 { | |
524 test_string = strtok(NULL, "\r") + 1; | |
525 break_loop = false; | |
526 decode_step=0; | |
527 do | |
528 { | |
529 c = *(unsigned char*)test_string; | |
530 temp_str_len = 0; | |
531 while((c!='\t')&&(c>0)) | |
532 { | |
533 ++temp_str_len; | |
534 c=test_string[temp_str_len]; | |
535 } | |
536 tmp_pos=test_string+temp_str_len; | |
537 if (*tmp_pos == 0) | |
538 break_loop = true; | |
539 *tmp_pos = 0; | |
540 if (temp_str_len) | |
541 { //i+1 | |
542 if (decode_step==1) | |
251 | 543 { |
291 | 544 pGroups[i] = atoi(test_string); |
251 | 545 } |
291 | 546 } |
547 ++decode_step; | |
548 test_string=tmp_pos+1; | |
549 } while ((decode_step<2)&&!break_loop); | |
550 } | |
551 | |
552 pNPCNewsTXT_Raw = (char*)pEvents_LOD->LoadRaw("npcnews.txt", 0); | |
553 strtok(pNPCNewsTXT_Raw, "\r"); | |
554 | |
555 | |
556 for (i=0; i<51; ++i) | |
557 { | |
558 test_string = strtok(NULL, "\r") + 1; | |
559 break_loop = false; | |
560 decode_step=0; | |
561 do | |
562 { | |
563 c = *(unsigned char*)test_string; | |
564 temp_str_len = 0; | |
565 while((c!='\t')&&(c>0)) | |
566 { | |
567 ++temp_str_len; | |
568 c=test_string[temp_str_len]; | |
569 } | |
570 tmp_pos=test_string+temp_str_len; | |
571 if (*tmp_pos == 0) | |
572 break_loop = true; | |
573 *tmp_pos = 0; | |
574 if (temp_str_len) | |
575 { //i+1 | |
576 if (decode_step==1) | |
577 pCatchPhrases[i] = RemoveQuotes(test_string); | |
578 } | |
579 ++decode_step; | |
580 test_string=tmp_pos+1; | |
581 } while ((decode_step<2)&&!break_loop); | |
582 } | |
251 | 583 } |
584 | |
585 //----- (0047702F) -------------------------------------------------------- | |
586 void NPCStats::Initialize() | |
291 | 587 { |
588 int i; | |
589 char* test_string; | |
590 unsigned char c; | |
591 bool break_loop; | |
592 unsigned int temp_str_len; | |
593 char* tmp_pos; | |
594 int decode_step; | |
251 | 595 |
291 | 596 InitializeNPCData(); |
597 InitializeNPCText(); | |
598 InitializeQuests(); | |
599 InitializeAutonotes(); | |
600 InitializeAwards(); | |
601 InitializeTransitions(); | |
602 InitializeMerchants(); | |
603 InitializeScrolls(); | |
251 | 604 |
291 | 605 pNPCNamesTXT_Raw = NULL; |
606 pNPCNamesTXT_Raw = (char *)pEvents_LOD->LoadRaw("npcnames.txt", 0); | |
607 strtok(pNPCNamesTXT_Raw, "\r"); | |
608 | |
609 uNewlNPCBufPos = 0; | |
610 | |
611 for (i=0; i<540; ++i) | |
251 | 612 { |
291 | 613 test_string = strtok(NULL, "\r") + 1; |
614 break_loop = false; | |
615 decode_step=0; | |
616 do | |
251 | 617 { |
291 | 618 c = *(unsigned char*)test_string; |
619 temp_str_len = 0; | |
620 if (c=='\t') | |
251 | 621 { |
291 | 622 if ( (decode_step == 1)&&(!uNumNPCNames[1])) |
623 uNumNPCNames[1]=i; | |
251 | 624 } |
625 else | |
626 { | |
291 | 627 while((c!='\n')&&(c!='\t')&&(c>0)) |
628 { | |
629 ++temp_str_len; | |
630 c=test_string[temp_str_len]; | |
631 } | |
632 tmp_pos=test_string+temp_str_len; | |
633 if (*tmp_pos == 0) | |
634 break_loop = true; | |
635 | |
636 if (temp_str_len) | |
637 { | |
638 *tmp_pos = 0; | |
639 if ( decode_step == 0) | |
640 pNPCNames[i][0] =RemoveQuotes(test_string); | |
641 else if ( decode_step == 1) | |
642 pNPCNames[i][1] =RemoveQuotes(test_string); | |
643 } | |
644 else | |
645 { | |
646 if ( (decode_step == 1)&&(!uNumNPCNames[1])) | |
647 uNumNPCNames[1]=i; | |
648 } | |
251 | 649 } |
291 | 650 ++decode_step; |
651 test_string=tmp_pos+1; | |
652 } while ((decode_step<2)&&!break_loop); | |
653 } | |
654 uNumNPCNames[0] = i; | |
655 | |
656 pNPCProfTXT_Raw = NULL; | |
657 pNPCProfTXT_Raw = (char *)pEvents_LOD->LoadRaw("npcprof.txt", 0); | |
658 strtok(pNPCProfTXT_Raw, "\r"); | |
659 strtok(NULL, "\r"); | |
660 strtok(NULL, "\r"); | |
661 strtok(NULL, "\r"); | |
662 | |
663 for (i=1; i<59; ++i) | |
664 { | |
665 test_string = strtok(NULL, "\r") + 1; | |
666 break_loop = false; | |
667 decode_step=0; | |
668 do | |
251 | 669 { |
667 | 670 //while (*test_string == '\t') // some steps are separated by multiple \t's |
671 //++test_string; | |
652 | 672 |
291 | 673 c = *(unsigned char*)test_string; |
674 temp_str_len = 0; | |
675 while((c!='\t')&&(c>0)) | |
251 | 676 { |
291 | 677 ++temp_str_len; |
678 c=test_string[temp_str_len]; | |
679 } | |
680 tmp_pos=test_string+temp_str_len; | |
681 if (*tmp_pos == 0) | |
682 break_loop = true; | |
683 *tmp_pos = 0; | |
684 if (temp_str_len) | |
685 { | |
686 switch(decode_step) | |
687 { | |
688 case 2: | |
689 pProfessions[i].uHirePrice = atoi(test_string); | |
690 break; | |
691 case 3: | |
692 pProfessions[i].pActionText = RemoveQuotes(test_string); | |
693 break; | |
694 case 4: | |
695 pProfessions[i].pBenefits= RemoveQuotes(test_string); | |
696 break; | |
697 case 5: | |
698 pProfessions[i].pJoinText = RemoveQuotes(test_string); | |
699 break; | |
700 case 6: | |
701 pProfessions[i].pDismissText = RemoveQuotes(test_string); | |
702 } | |
251 | 703 } |
291 | 704 else |
705 { | |
667 | 706 if (!decode_step) |
291 | 707 break_loop = true; |
708 } | |
709 ++decode_step; | |
710 test_string=tmp_pos+1; | |
711 } while ((decode_step<7)&&!break_loop); | |
251 | 712 } |
291 | 713 uNumNPCProfessions = 59; |
251 | 714 } |
715 | |
716 //----- (00477266) -------------------------------------------------------- | |
717 void NPCStats::Release() | |
718 { | |
291 | 719 pAllocator->FreeChunk(pNPCTopicTXT_Raw); |
720 pNPCTopicTXT_Raw = NULL; | |
721 pAllocator->FreeChunk(pNPCTextTXT_Raw); | |
722 pNPCTextTXT_Raw = NULL; | |
723 pAllocator->FreeChunk(pNPCNewsTXT_Raw); | |
724 pNPCNewsTXT_Raw = NULL; | |
725 pAllocator->FreeChunk(pNPCProfTXT_Raw); | |
726 pNPCProfTXT_Raw = NULL; | |
727 pAllocator->FreeChunk(pNPCNamesTXT_Raw); | |
728 pNPCNamesTXT_Raw = NULL; | |
729 pAllocator->FreeChunk(pNPCDataTXT_Raw); | |
730 pNPCDataTXT_Raw = NULL; | |
731 pAllocator->FreeChunk(pNPCDistTXT_Raw); | |
732 pNPCDistTXT_Raw = NULL; | |
733 pAllocator->FreeChunk(pNPCGreetTXT_Raw); | |
734 pNPCGreetTXT_Raw = NULL; | |
735 pAllocator->FreeChunk(pNCPGroupTXT_Raw); | |
736 pNCPGroupTXT_Raw = NULL; | |
251 | 737 } |
738 | |
739 //----- (0047730C) -------------------------------------------------------- | |
307 | 740 bool CheckPortretAgainstSex(int a1, int) |
251 | 741 { |
291 | 742 return true; |
251 | 743 } |
744 // 47730C: using guessed type int __stdcall const_1(int); | |
745 | |
746 //----- (0047732C) -------------------------------------------------------- | |
291 | 747 void NPCStats::InitializeAdditionalNPCs(NPCData *pNPCDataBuff, int npc_uid, int uLocation2D, int uMapId) |
251 | 748 { |
292 | 749 int rep_gen; |
291 | 750 int uNPCSex; // esi@1 |
751 int uGeneratedPortret; // ecx@23 | |
752 int test_prof_summ; // ecx@37 | |
753 int gen_profession; // eax@37 | |
754 int max_prof_cap; // edx@37 | |
251 | 755 signed int result; // eax@39 |
291 | 756 int uRace; // [sp+Ch] [bp-Ch]@1 |
757 bool break_gen; // [sp+10h] [bp-8h]@1 | |
758 signed int gen_attempts; // [sp+14h] [bp-4h]@1 | |
759 int uPortretMin; // [sp+24h] [bp+Ch]@1 | |
760 int uPortretMax; | |
761 | |
762 static const unsigned __int8 NPCSexGenTable[86] ={ | |
293 | 763 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
764 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, | |
765 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, | |
766 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
767 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }; | |
768 static const unsigned __int8 NPCRaceGenTable[86] ={ | |
769 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 1, 1, | |
770 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
771 0, 0, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, | |
772 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
773 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0}; | |
251 | 774 |
307 | 775 unsigned __int8 seed = (unsigned __int8)((double)(npc_uid - 1)/3.0); |
291 | 776 uNPCSex = NPCSexGenTable[seed]; |
777 uRace = NPCRaceGenTable[seed]; | |
778 pNPCDataBuff->uSex = uNPCSex; | |
779 pNPCDataBuff->pName = pNPCNames[rand() % uNumNPCNames[uNPCSex]][uNPCSex]; | |
780 | |
781 gen_attempts = 0; | |
782 break_gen = false; | |
251 | 783 |
291 | 784 do |
251 | 785 { |
293 | 786 switch ( uRace ) |
787 { | |
788 case 0: | |
789 if ( uNPCSex == 0 ) | |
291 | 790 { |
791 uPortretMin = 2; | |
792 uPortretMax = 100; | |
251 | 793 } |
794 else | |
795 { | |
293 | 796 uPortretMin = 201; |
797 uPortretMax = 250; | |
798 } | |
799 case 1: | |
800 if ( uNPCSex == 0 ) | |
801 { | |
802 uPortretMin = 400; | |
803 uPortretMax = 430; | |
804 } | |
805 else | |
806 { | |
807 uPortretMin = 460; | |
808 uPortretMax = 490; | |
809 } | |
810 break; | |
811 case 2: | |
812 if ( uNPCSex == 0 ) | |
813 { | |
814 uPortretMin = 500; | |
815 uPortretMax = 520; | |
816 } | |
817 else | |
818 { | |
819 uPortretMin = 530; | |
820 uPortretMax = 550; | |
821 } | |
822 break; | |
823 case 3: | |
824 if ( uNPCSex == 0 ) | |
825 { | |
826 uPortretMin = 300; | |
827 uPortretMax = 330; | |
828 } | |
829 else | |
830 { | |
831 uPortretMin = 360; | |
832 uPortretMax = 387; | |
251 | 833 } |
291 | 834 |
293 | 835 break; |
836 } | |
837 | |
291 | 838 uGeneratedPortret = uPortretMin + rand() % (uPortretMax - uPortretMin + 1); |
307 | 839 if ( CheckPortretAgainstSex(uGeneratedPortret, uNPCSex)) |
291 | 840 break_gen = true; |
841 ++gen_attempts; | |
842 if ( gen_attempts >= 4 ) | |
251 | 843 { |
291 | 844 uGeneratedPortret = uPortretMin; |
845 break_gen = true; | |
251 | 846 } |
847 } | |
291 | 848 while(!break_gen); |
251 | 849 |
293 | 850 pNPCDataBuff->uPortraitID = uGeneratedPortret; |
851 pNPCDataBuff->uFlags = 0; | |
852 pNPCDataBuff->fame = 0; | |
853 //generate reputation | |
854 rep_gen = rand() % 100 + 1; | |
251 | 855 |
293 | 856 if ( rep_gen >= 60 ) |
251 | 857 { |
293 | 858 if ( rep_gen >= 90 ) |
251 | 859 { |
293 | 860 if ( rep_gen >= 95 ) |
861 { | |
862 if ( rep_gen >= 98 ) | |
863 pNPCDataBuff->rep = -600; | |
864 else | |
865 pNPCDataBuff->rep = 400; | |
866 } | |
251 | 867 else |
293 | 868 pNPCDataBuff->rep = -300; |
251 | 869 } |
870 else | |
293 | 871 pNPCDataBuff->rep = 200; |
251 | 872 } |
873 else | |
293 | 874 pNPCDataBuff->rep = 0; |
291 | 875 |
293 | 876 max_prof_cap = rand() % pProfessionChance[uMapId].uTotalprofChance+1; |
877 test_prof_summ = 0; | |
878 gen_profession = 0; | |
251 | 879 |
293 | 880 if ( max_prof_cap > 0 ) |
881 { | |
882 do | |
883 test_prof_summ += pProfessionChance[uMapId].professionChancePerArea[gen_profession++]; | |
884 while ( test_prof_summ < max_prof_cap ); | |
885 } | |
886 pNPCDataBuff->uProfession = gen_profession - 1; | |
887 pNPCDataBuff->Location2D = uLocation2D; | |
888 pNPCDataBuff->field_24 = 1; | |
889 pNPCDataBuff->joins = 1; | |
659 | 890 pNPCDataBuff->evt_A = 0; |
891 pNPCDataBuff->evt_B = 0; | |
892 pNPCDataBuff->evt_C = 0; | |
893 pNPCDataBuff->evt_D = 0; | |
894 pNPCDataBuff->evt_E = 0; | |
895 pNPCDataBuff->evt_F = 0; | |
251 | 896 } |
897 | |
257 | 898 //----- (00476387) -------------------------------------------------------- |
899 bool PartyHasDragon() | |
900 { | |
901 return pNPCStats->pNewNPCData[57].Hired(); | |
902 } | |
251 | 903 |
904 //----- (00476395) -------------------------------------------------------- | |
905 //0x26 Wizard eye at skill level 2 | |
906 bool __thiscall CheckHiredNPCSpeciality(unsigned int uProfession) | |
1094 | 907 { |
908 | |
909 if ( bNoNPCHiring == 1 ) | |
910 return 0; | |
251 | 911 |
1094 | 912 for (int i=0; i<pNPCStats->uNumNewNPCs; ++i ) |
913 { | |
914 if ( pNPCStats->pNewNPCData[i].uProfession == uProfession && | |
915 (pNPCStats->pNewNPCData[i].uFlags & 0x80) ) | |
916 return true; | |
917 } | |
918 if ( pParty->pHirelings[0].uProfession == uProfession || | |
919 pParty->pHirelings[1].uProfession == uProfession) | |
920 return true; | |
921 else | |
922 return false; | |
923 | |
924 } | |
251 | 925 // 6BE3C5: using guessed type char bNoNPCHiring; |
926 | |
927 //----- (004763E0) -------------------------------------------------------- | |
928 void InitializeAwards() | |
949 | 929 { |
251 | 930 int i; |
931 char* test_string; | |
932 unsigned char c; | |
933 bool break_loop; | |
934 unsigned int temp_str_len; | |
935 char* tmp_pos; | |
936 int decode_step; | |
937 | |
938 if ( pAwardsTXT_Raw ) | |
939 pAllocator->FreeChunk(pAwardsTXT_Raw); | |
940 pAwardsTXT_Raw = NULL; | |
941 pAwardsTXT_Raw = (char *)pEvents_LOD->LoadRaw("awards.txt", 0); | |
942 strtok(pAwardsTXT_Raw, "\r"); | |
943 | |
949 | 944 for (i=1; i<105; ++i) |
251 | 945 { |
946 test_string = strtok(NULL, "\r") + 1; | |
947 break_loop = false; | |
948 decode_step=0; | |
949 do | |
950 { | |
951 c = *(unsigned char*)test_string; | |
952 temp_str_len = 0; | |
953 while((c!='\t')&&(c>0)) | |
954 { | |
955 ++temp_str_len; | |
956 c=test_string[temp_str_len]; | |
957 } | |
958 tmp_pos=test_string+temp_str_len; | |
959 if (*tmp_pos == 0) | |
960 break_loop = true; | |
961 *tmp_pos = 0; | |
962 if (temp_str_len) | |
963 { | |
964 if (decode_step==1) | |
965 pAwards[i].pText=RemoveQuotes(test_string); | |
966 else if (decode_step==2) | |
949 | 967 pAwards[i].uPriority = atoi(test_string); |
251 | 968 } |
969 else | |
970 { | |
971 break_loop = true; | |
972 } | |
973 ++decode_step; | |
974 test_string=tmp_pos+1; | |
975 } while ((decode_step<3)&&!break_loop); | |
976 } | |
977 } | |
978 // 7241C8: using guessed type int dword_7241C8; | |
979 | |
980 //----- (004764C2) -------------------------------------------------------- | |
981 void InitializeScrolls() | |
982 { | |
983 | |
984 int i; | |
985 char* test_string; | |
986 unsigned char c; | |
987 bool break_loop; | |
988 unsigned int temp_str_len; | |
989 char* tmp_pos; | |
990 int decode_step; | |
991 | |
992 if ( pScrollsTXT_Raw ) | |
993 pAllocator->FreeChunk(pScrollsTXT_Raw); | |
994 pScrollsTXT_Raw = NULL; | |
995 pScrollsTXT_Raw = (char *)pEvents_LOD->LoadRaw("scroll.txt", 0); | |
996 strtok(pScrollsTXT_Raw, "\r"); | |
997 for (i=0; i<82; ++i) | |
998 { | |
999 test_string = strtok(NULL, "\r") + 1; | |
1000 break_loop = false; | |
1001 decode_step=0; | |
1002 do | |
1003 { | |
1004 c = *(unsigned char*)test_string; | |
1005 temp_str_len = 0; | |
1006 while((c!='\t')&&(c>0)) | |
1007 { | |
1008 ++temp_str_len; | |
1009 c=test_string[temp_str_len]; | |
1010 } | |
1011 tmp_pos=test_string+temp_str_len; | |
1012 if (*tmp_pos == 0) | |
1013 break_loop = true; | |
1014 *tmp_pos = 0; | |
1015 if (temp_str_len) | |
1016 { | |
1017 if ( decode_step == 1) | |
1018 pScrolls[i]=RemoveQuotes(test_string); | |
1019 } | |
1020 else | |
1021 { | |
1022 break_loop = true; | |
1023 } | |
1024 ++decode_step; | |
1025 test_string=tmp_pos+1; | |
1026 } while ((decode_step<2)&&!break_loop); | |
1027 } | |
1028 } | |
1029 | |
1030 //----- (00476590) -------------------------------------------------------- | |
1031 void InitializeMerchants() | |
1032 { | |
1033 int i; | |
1034 char* test_string; | |
1035 unsigned char c; | |
1036 bool break_loop; | |
1037 unsigned int temp_str_len; | |
1038 char* tmp_pos; | |
1039 int decode_step; | |
1040 | |
1041 if ( pMerchantsTXT_Raw ) | |
1042 pAllocator->FreeChunk(pMerchantsTXT_Raw); | |
1043 pMerchantsTXT_Raw = NULL; | |
1044 pMerchantsTXT_Raw = (char *)pEvents_LOD->LoadRaw("merchant.txt", 0); | |
1045 strtok(pMerchantsTXT_Raw, "\r"); | |
1046 | |
1047 for (i=0; i<7; ++i) | |
1048 { | |
1049 test_string = strtok(NULL, "\r") + 1; | |
1050 break_loop = false; | |
1051 decode_step=0; | |
1052 do | |
1053 { | |
1054 c = *(unsigned char*)test_string; | |
1055 temp_str_len = 0; | |
1056 while((c!='\t')&&(c>0)) | |
1057 { | |
1058 ++temp_str_len; | |
1059 c=test_string[temp_str_len]; | |
1060 } | |
1061 tmp_pos=test_string+temp_str_len; | |
1062 if (*tmp_pos == 0) | |
1063 break_loop = true; | |
1064 *tmp_pos = 0; | |
1065 if (temp_str_len) | |
1066 { | |
1067 switch (decode_step) | |
1068 { | |
1069 case 1: | |
1070 pMerchantsBuyPhrases[i]=RemoveQuotes(test_string); | |
1071 break; | |
1072 case 2: | |
1073 pMerchantsSellPhrases[i]=RemoveQuotes(test_string); | |
1074 break; | |
1075 case 3: | |
1076 pMerchantsRepairPhrases[i]=RemoveQuotes(test_string); | |
1077 break; | |
1078 case 4: | |
1079 pMerchantsIdentifyPhrases[i]=RemoveQuotes(test_string); | |
1080 break; | |
1081 } | |
1082 } | |
1083 else | |
1084 { | |
1085 break_loop = true; | |
1086 } | |
1087 ++decode_step; | |
1088 test_string=tmp_pos+1; | |
1089 } while ((decode_step<5)&&!break_loop); | |
1090 } | |
1091 | |
1092 } | |
1093 | |
1094 //----- (00476682) -------------------------------------------------------- | |
1095 void InitializeTransitions() | |
1096 { | |
1097 int i; | |
1098 char* test_string; | |
1099 unsigned char c; | |
1100 bool break_loop; | |
1101 unsigned int temp_str_len; | |
1102 char* tmp_pos; | |
1103 int decode_step; | |
1104 | |
1105 if ( pTransitionsTXT_Raw ) | |
1106 pAllocator->FreeChunk(pTransitionsTXT_Raw); | |
1107 pTransitionsTXT_Raw = NULL; | |
1108 pTransitionsTXT_Raw = (char *)pEvents_LOD->LoadRaw("trans.txt", 0); | |
1109 strtok(pTransitionsTXT_Raw, "\r"); | |
1110 | |
1111 for (i=0; i<464; ++i) | |
1112 { | |
1113 test_string = strtok(NULL, "\r") + 1; | |
1114 break_loop = false; | |
1115 decode_step=0; | |
1116 do | |
1117 { | |
1118 c = *(unsigned char*)test_string; | |
1119 temp_str_len = 0; | |
1120 while((c!='\t')&&(c>0)) | |
1121 { | |
1122 ++temp_str_len; | |
1123 c=test_string[temp_str_len]; | |
1124 } | |
1125 tmp_pos=test_string+temp_str_len; | |
1126 if (*tmp_pos == 0) | |
1127 break_loop = true; | |
1128 *tmp_pos = 0; | |
1129 if (temp_str_len) | |
1130 { | |
1131 if ( decode_step == 1) | |
434 | 1132 pTransitionStrings[i + 1]=RemoveQuotes(test_string); |
251 | 1133 } |
1134 else | |
1135 { | |
1136 break_loop = true; | |
1137 } | |
1138 ++decode_step; | |
1139 test_string=tmp_pos+1; | |
1140 } while ((decode_step<2)&&!break_loop); | |
1141 } | |
1142 } | |
1143 | |
1144 //----- (00476750) -------------------------------------------------------- | |
1145 void __cdecl InitializeAutonotes() | |
1146 { | |
1147 int i; | |
1148 char* test_string; | |
1149 unsigned char c; | |
1150 bool break_loop; | |
1151 unsigned int temp_str_len; | |
1152 char* tmp_pos; | |
1153 int decode_step; | |
1154 | |
1155 if ( pAutonoteTXT_Raw ) | |
1156 pAllocator->FreeChunk(pAutonoteTXT_Raw); | |
1157 pAutonoteTXT_Raw = 0; | |
1158 pAutonoteTXT_Raw = (char *)pEvents_LOD->LoadRaw("autonote.txt", 0); | |
1159 strtok(pAutonoteTXT_Raw, "\r"); | |
1160 | |
1161 for (i=0; i<195; ++i) | |
1162 { | |
1163 test_string = strtok(NULL, "\r") + 1; | |
1164 break_loop = false; | |
1165 decode_step=0; | |
1166 do | |
1167 { | |
1168 c = *(unsigned char*)test_string; | |
1169 temp_str_len = 0; | |
1170 while((c!='\t')&&(c>0)) | |
1171 { | |
1172 ++temp_str_len; | |
1173 c=test_string[temp_str_len]; | |
1174 } | |
1175 tmp_pos=test_string+temp_str_len; | |
1176 if (*tmp_pos == 0) | |
1177 break_loop = true; | |
1178 *tmp_pos = 0; | |
1179 if (temp_str_len) | |
1180 { | |
1181 switch (decode_step) | |
1182 { | |
1183 case 1: | |
1310 | 1184 pAutonoteTxt[i+1].pText=RemoveQuotes(test_string); |
251 | 1185 break; |
1186 case 2: | |
1187 { | |
1104 | 1188 if ( !_stricmp(test_string, "potion")) |
251 | 1189 { |
1310 | 1190 pAutonoteTxt[i+1].eType = AUTONOTE_POTION_RECEPIE; |
251 | 1191 break; |
1192 } | |
1104 | 1193 if ( !_stricmp(test_string, "stat") ) |
251 | 1194 { |
1310 | 1195 pAutonoteTxt[i+1].eType = AUTONOTE_STAT_HINT; |
251 | 1196 break; |
1197 } | |
1104 | 1198 if ( !_stricmp(test_string, "seer") ) |
251 | 1199 { |
1310 | 1200 pAutonoteTxt[i+1].eType = AUTONOTE_SEER; |
251 | 1201 break; |
1202 } | |
1104 | 1203 if ( !_stricmp(test_string, "obelisk") ) |
251 | 1204 { |
1310 | 1205 pAutonoteTxt[i+1].eType = AUTONOTE_OBELISK; |
251 | 1206 break; |
1207 } | |
1104 | 1208 if ( !_stricmp(test_string, "teacher") ) |
251 | 1209 { |
1310 | 1210 pAutonoteTxt[i+1].eType = AUTONOTE_TEACHER; |
251 | 1211 break; |
1212 } | |
1310 | 1213 pAutonoteTxt[i+1].eType =AUTONOTE_MISC; |
251 | 1214 break; |
1215 } | |
1216 } | |
1217 } | |
1218 else | |
1219 { | |
1220 break_loop = true; | |
1221 } | |
1222 ++decode_step; | |
1223 test_string=tmp_pos+1; | |
1224 } while ((decode_step<3)&&!break_loop); | |
1225 } | |
1226 } | |
1227 | |
1228 | |
1229 //----- (004768A9) -------------------------------------------------------- | |
1230 void __cdecl InitializeQuests() | |
1231 { | |
1232 int i; | |
1233 char* test_string; | |
1234 unsigned char c; | |
1235 bool break_loop; | |
1236 unsigned int temp_str_len; | |
1237 char* tmp_pos; | |
1238 int decode_step; | |
1239 | |
1240 if ( pQuestsTXT_Raw ) | |
1241 pAllocator->FreeChunk(pQuestsTXT_Raw); | |
1242 pQuestsTXT_Raw = NULL; | |
1243 pQuestsTXT_Raw = (char *)pEvents_LOD->LoadRaw("quests.txt", 0); | |
1244 strtok(pQuestsTXT_Raw, "\r"); | |
1310 | 1245 memset(pQuestTable.data(),0, sizeof(pQuestTable)); |
251 | 1246 for (i=0; i<512; ++i) |
1247 { | |
1248 test_string = strtok(NULL, "\r") + 1; | |
1249 break_loop = false; | |
1250 decode_step=0; | |
1251 do | |
1252 { | |
1253 c = *(unsigned char*)test_string; | |
1254 temp_str_len = 0; | |
1255 while((c!='\t')&&(c>0)) | |
1256 { | |
1257 ++temp_str_len; | |
1258 c=test_string[temp_str_len]; | |
1259 } | |
1260 tmp_pos=test_string+temp_str_len; | |
1261 if (*tmp_pos == 0) | |
1262 break_loop = true; | |
1263 *tmp_pos = 0; | |
1264 if (temp_str_len) | |
1265 { | |
1266 if ( decode_step == 1) | |
1310 | 1267 pQuestTable[i+1] =RemoveQuotes(test_string); |
251 | 1268 } |
1269 else | |
1270 { | |
1271 break_loop = true; | |
1272 } | |
1273 ++decode_step; | |
1274 test_string=tmp_pos+1; | |
1275 } while ((decode_step<2)&&!break_loop); | |
1276 } | |
1277 } | |
1278 | |
1295 | 1279 //----- (004B2001) -------------------------------------------------------- |
1280 void __fastcall ClickNPCTopic(signed int uMessageParam) | |
1281 { | |
1282 //signed int v1; // eax@1 | |
1283 NPCData *pCurrentNPCInfo; // ebp@1 | |
1284 int pEventNumber; // ecx@8 | |
1285 Player *v4; // esi@20 | |
1286 //int v5; // eax@28 | |
1287 //int v6; // eax@31 | |
1288 //int v7; // eax@34 | |
1289 //int v8; // eax@37 | |
1290 //int v9; // eax@40 | |
1291 //unsigned int v10; // eax@43 | |
1292 char *v12; // eax@53 | |
1293 char *v13; // eax@56 | |
1294 char *v14; // eax@57 | |
1295 char *v15; // eax@58 | |
1296 //unsigned int v16; // ebp@62 | |
1297 char *v17; // ecx@63 | |
1298 char *v18; // eax@65 | |
1299 const char *v19; // ecx@68 | |
1300 //unsigned int v20; // eax@69 | |
1301 signed int pPrice; // ecx@70 | |
1302 char *v22; // [sp-Ch] [bp-18h]@73 | |
1303 //int v23; // [sp-8h] [bp-14h]@49 | |
1304 char *v24; // [sp-8h] [bp-14h]@73 | |
1305 //int v25; // [sp-4h] [bp-10h]@49 | |
1306 | |
1307 uDialogueType = uMessageParam + 1; | |
1313 | 1308 pCurrentNPCInfo = HouseNPCData[pDialogueNPCCount -((dword_591080 != 0)?1:0 )];//- 1 |
1295 | 1309 if ( uMessageParam <= 24 ) |
1310 { | |
1311 switch ( uMessageParam ) | |
1312 { | |
1313 case 13: | |
1314 current_npc_text = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession].pJoinText;//(char *)*(&pNPCStats->field_13A64 + 5 * v2->uProfession); | |
1315 current_npc_text = BuilDialogueString((char *)current_npc_text, uActiveCharacter - 1, 0, 0, 0, 0); | |
1316 NPCHireableDialogPrepare(); | |
1317 dialogue_show_profession_details = false; | |
1318 goto _return; | |
1319 case 19: | |
1320 pEventNumber = pCurrentNPCInfo->evt_A; | |
1321 break; | |
1322 case 20: | |
1323 pEventNumber = pCurrentNPCInfo->evt_B; | |
1324 break; | |
1325 case 21: | |
1326 pEventNumber = pCurrentNPCInfo->evt_C; | |
1327 break; | |
1328 case 22: | |
1329 pEventNumber = pCurrentNPCInfo->evt_D; | |
1330 break; | |
1331 case 23: | |
1332 pEventNumber = pCurrentNPCInfo->evt_E; | |
1333 break; | |
1334 case 24: | |
1335 pEventNumber = pCurrentNPCInfo->evt_F; | |
1336 break; | |
1337 default: | |
1338 goto _return; | |
1339 } | |
1340 /*switch ( pEventNumber ) | |
1341 { | |
1342 case 139: | |
1343 sub_4B1ECE(); | |
1344 goto _return; | |
1345 case 311: | |
1346 sub_4BBA85_bounties(); | |
1347 goto _return; | |
1348 }*/ | |
1349 if ( pEventNumber < 200 || pEventNumber > 310 ) | |
1350 { | |
1351 if ( pEventNumber < 400 || pEventNumber > 410 ) | |
1352 { | |
1353 if ( pEventNumber == 139 ) | |
1354 { | |
1355 sub_4B1ECE(); | |
1356 } | |
1357 else | |
1358 { | |
1359 if ( pEventNumber == 311 ) | |
1360 { | |
1361 sub_4BBA85_bounties(); | |
1362 } | |
1363 else | |
1364 { | |
1365 current_npc_text = 0; | |
1366 activeLevelDecoration = (LevelDecoration*)1; | |
1367 EventProcessor(pEventNumber, 0, 1); | |
1368 activeLevelDecoration = NULL; | |
1369 } | |
1370 } | |
1371 } | |
1372 else | |
1373 { | |
1374 dword_F8B1D8 = uMessageParam; | |
1375 DrawJoinGuildWindow(pEventNumber - 400); | |
1376 } | |
1377 } | |
1378 else | |
1379 { | |
1380 sub_4B3FE5(pEventNumber); | |
1381 } | |
1382 goto _return; | |
1383 } | |
1384 if ( uMessageParam != 76 ) | |
1385 { | |
1386 if ( uMessageParam == 77 ) | |
1387 { | |
1388 //v16 = pCurrentNPCInfo->uProfession; | |
1389 if (dialogue_show_profession_details) | |
1390 v17 = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession - 1].pJoinText; | |
1391 else | |
1392 v17 = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession - 1].pBenefits; | |
1393 current_npc_text = v17; | |
1394 v18 = BuilDialogueString(v17, uActiveCharacter - 1, 0, 0, 0, 0); | |
1395 dialogue_show_profession_details = ~dialogue_show_profession_details; | |
1396 current_npc_text = v18; | |
1397 } | |
1398 else | |
1399 { | |
1400 if ( uMessageParam == 79 ) | |
1401 { | |
1402 if ( contract_approved ) | |
1403 { | |
1404 Party::TakeGold(gold_transaction_amount); | |
1405 if ( uActiveCharacter ) | |
1406 { | |
1407 v12 = (char *)&pPlayers[uActiveCharacter]->pActiveSkills[dword_F8B1AC_award_bit_number]; | |
1408 *(short *)v12 &= 0x3Fu; | |
1409 switch ( dword_F8B1B0 ) | |
1410 { | |
1411 case 2: | |
1412 v15 = (char *)&pPlayers[uActiveCharacter]->pActiveSkills[dword_F8B1AC_award_bit_number]; | |
1413 *v15 |= 0x40u; | |
1414 break; | |
1415 case 3: | |
1416 v14 = (char *)&pPlayers[uActiveCharacter]->pActiveSkills[dword_F8B1AC_award_bit_number]; | |
1417 *v14 |= 0x80u; | |
1418 break; | |
1419 case 4: | |
1420 v13 = (char *)&pPlayers[uActiveCharacter]->pActiveSkills[dword_F8B1AC_award_bit_number]; | |
1421 v13[1] |= 1u; | |
1422 break; | |
1423 } | |
1424 pPlayers[uActiveCharacter]->PlaySound(SPEECH_85, 0); | |
1425 } | |
1426 pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0); | |
1427 /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 ) | |
1428 { | |
1429 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape; | |
1430 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1; | |
1431 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0; | |
1432 ++pMessageQueue_50CBD0->uNumMessages; | |
1433 }*/ | |
1434 } | |
1435 } | |
1436 else | |
1437 { | |
1438 if ( uMessageParam == 82 && contract_approved ) //join guild | |
1439 { | |
1440 Party::TakeGold(gold_transaction_amount); | |
1441 v4 = pParty->pPlayers; | |
1442 do | |
1443 { | |
1444 v4->SetVariable(VAR_Award, dword_F8B1AC_award_bit_number); | |
1445 ++v4; | |
1446 } | |
1447 while ( (signed int)v4 < (signed int)pParty->pHirelings ); | |
1448 switch ( dword_F8B1D8 ) | |
1449 { | |
1450 case 19: | |
1451 pEventNumber = pCurrentNPCInfo->evt_A; | |
1452 if ( pEventNumber >= 400 && pEventNumber <= 416 ) | |
1453 pCurrentNPCInfo->evt_A = 0; | |
1454 break; | |
1455 case 20: | |
1456 pEventNumber = pCurrentNPCInfo->evt_B; | |
1457 if ( pEventNumber >= 400 && pEventNumber <= 416 ) | |
1458 pCurrentNPCInfo->evt_B = 0; | |
1459 break; | |
1460 case 21: | |
1461 pEventNumber = pCurrentNPCInfo->evt_C; | |
1462 if ( pEventNumber >= 400 && pEventNumber <= 416 ) | |
1463 pCurrentNPCInfo->evt_C = 0; | |
1464 break; | |
1465 case 22: | |
1466 pEventNumber = pCurrentNPCInfo->evt_D; | |
1467 if ( pEventNumber >= 400 && pEventNumber <= 416 ) | |
1468 pCurrentNPCInfo->evt_D = 0; | |
1469 break; | |
1470 case 23: | |
1471 pEventNumber = pCurrentNPCInfo->evt_E; | |
1472 if ( pEventNumber >= 400 && pEventNumber <= 416 ) | |
1473 pCurrentNPCInfo->evt_E = 0; | |
1474 break; | |
1475 case 24: | |
1476 pEventNumber = pCurrentNPCInfo->evt_F; | |
1477 if ( pEventNumber >= 400 && pEventNumber <= 416) | |
1478 pCurrentNPCInfo->evt_F = 0; | |
1479 break; | |
1480 } | |
1481 pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0); | |
1482 /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 ) | |
1483 { | |
1484 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape; | |
1485 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1; | |
1486 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0; | |
1487 ++pMessageQueue_50CBD0->uNumMessages; | |
1488 }*/ | |
1489 //v11 = uActiveCharacter; | |
1490 if ( uActiveCharacter ) | |
1491 { | |
1492 pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)SPEECH_86, 0); | |
1493 goto _return; | |
1494 } | |
1495 } | |
1496 } | |
1497 } | |
1498 goto _return; | |
1499 } | |
1500 if ( pParty->pHirelings[0].pName && pParty->pHirelings[1].pName ) | |
1501 { | |
1502 ShowStatusBarString(pGlobalTXT_LocalizationStrings[533], 2);// ""I cannot join you, you're party is full"" | |
1503 goto _return; | |
1504 } | |
1505 if ( pCurrentNPCInfo->uProfession != 51 ) | |
1506 { | |
1507 pPrice = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession - 1].uHirePrice; | |
1508 if ( pParty->uNumGold < pPrice ) | |
1509 { | |
1510 ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2); | |
1511 dialogue_show_profession_details = false; | |
1512 uDialogueType = 13; | |
1513 current_npc_text = pNPCStats->pProfessions[pCurrentNPCInfo->uProfession - 1].pJoinText; | |
1514 current_npc_text = BuilDialogueString((char *)current_npc_text, uActiveCharacter - 1, 0, 0, 0, 0); | |
1515 if ( uActiveCharacter ) | |
1516 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NotEnoughGold, 0); | |
1517 ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2); | |
1518 goto _return; | |
1519 } | |
1520 Party::TakeGold(pPrice); | |
1521 } | |
1522 //LOBYTE(v2->uFlags) |= 0x80u; | |
1523 pCurrentNPCInfo->uFlags |= 128; | |
1524 pParty->field_709 = 0; | |
1525 pParty->CountHirelings(); | |
1526 if ( pParty->pHirelings[0].pName ) | |
1527 { | |
1528 memcpy(&pParty->pHirelings[1], pCurrentNPCInfo, sizeof(pParty->pHirelings[1])); | |
1529 v24 = pCurrentNPCInfo->pName; | |
1530 v22 = pParty->pHireling2Name; | |
1531 } | |
1532 else | |
1533 { | |
1534 memcpy(pParty->pHirelings, pCurrentNPCInfo, 0x4Cu); | |
1535 v24 = pCurrentNPCInfo->pName; | |
1536 v22 = pParty->pHireling1Name; | |
1537 } | |
1538 strcpy(v22, v24); | |
1539 pParty->field_709 = 0; | |
1540 pParty->CountHirelings(); | |
1541 PrepareHouse((HOUSE_ID)(int)window_SpeakInHouse->ptr_1C); | |
1542 dialog_menu_id = HOUSE_DIALOGUE_MAIN; | |
1543 | |
1544 pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0); | |
1545 /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 ) | |
1546 { | |
1547 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape; | |
1548 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1; | |
1549 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0; | |
1550 ++pMessageQueue_50CBD0->uNumMessages; | |
1551 }*/ | |
1552 if ( uActiveCharacter ) | |
1553 pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)61, 0); | |
1554 _return: | |
1555 pVideoPlayer->_4BF5B2();//HouseVideo | |
1556 } | |
1557 //----- (004B29F2) -------------------------------------------------------- | |
1558 const char * ContractSelectText( int pEventCode ) | |
1559 { | |
1560 static const int dialogue_base=110; | |
1561 contract_approved = 0; | |
1562 dword_F8B1AC_award_bit_number = pEventCode + 50; | |
1563 gold_transaction_amount = price_for_membership[pEventCode]; | |
1564 if ( pPlayers[uActiveCharacter]->CanAct() ) | |
1565 { | |
1566 if ( (unsigned __int16)_449B57_test_bit((unsigned __int8 *)pPlayers[uActiveCharacter]->_guilds_member_bits, dword_F8B1AC_award_bit_number) ) | |
1567 { | |
1568 return pNPCTopics[dialogue_base+13].pText; | |
1569 } | |
1570 else | |
1571 { | |
1572 if ( gold_transaction_amount <= pParty->uNumGold ) | |
1573 { | |
1574 contract_approved = 1; | |
1575 return pNPCTopics[pEventCode + dialogue_base].pText; | |
1576 } | |
1577 else | |
1578 { | |
1579 return pNPCTopics[dialogue_base+14].pText; | |
1580 } | |
1581 } | |
1582 } | |
1583 else | |
1584 { | |
1585 return pNPCTopics[dialogue_base+12].pText; | |
1586 } | |
1587 } | |
1588 //----- (004B40E6) -------------------------------------------------------- | |
1589 void NPCHireableDialogPrepare() | |
1590 { | |
1591 signed int v0; // ebx@1 | |
1592 NPCData *v1; // edi@1 | |
1593 | |
1594 v0 = 0; | |
1595 v1 = HouseNPCData[(unsigned int)((char *)pDialogueNPCCount + -(dword_591080 != 0) )];//- 1 | |
1596 pDialogueWindow->Release(); | |
1597 pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x15Eu, WINDOW_MainMenu, 0, 0); | |
1598 pBtn_ExitCancel = pDialogueWindow->CreateButton( 0x1D7u, 0x1BDu, 0xA9u, 0x23u, 1, 0, UIMSG_Escape, 0, 0, | |
1599 pGlobalTXT_LocalizationStrings[34], //"Cancel" | |
1600 pIcons_LOD->GetTexture(uExitCancelTextureId), | |
1601 0); | |
1602 pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", 0); | |
1603 if ( pNPCStats->pProfessions[v1->uProfession].pBenefits)//*(&pNPCStats->field_13A5C + 5 * v1->uProfession) ) | |
1604 { | |
1605 pDialogueWindow->CreateButton( 0x1E0u, 0xA0u, 0x8Cu, 0x1Eu, 1, 0, UIMSG_ClickNPCTopic, 0x4Du, 0, | |
1606 pGlobalTXT_LocalizationStrings[407], 0);//"More Information" | |
1607 v0 = 1; | |
1608 } | |
1609 pDialogueWindow->CreateButton( 0x1E0u, 30 * v0 + 160, 0x8Cu, 0x1Eu, 1, 0, UIMSG_ClickNPCTopic, 0x4Cu, 0, | |
1610 pGlobalTXT_LocalizationStrings[406], 0); //"Hire" | |
1611 pDialogueWindow->_41D08F_set_keyboard_control_group(v0 + 1, 1, 0, 2); | |
1612 dialog_menu_id = HOUSE_DIALOGUE_OTHER; | |
1613 } | |
1614 | |
1615 //----- (004B4224) -------------------------------------------------------- | |
1616 void _4B4224_UpdateNPCTopics( int _this ) | |
1617 { | |
1618 int num_menu_buttons; // ebx@1 | |
1619 int i; // ebp@5 | |
1620 // signed int v4; // ebp@9 | |
1621 int v6; // eax@16 | |
1622 int v8; // eax@21 | |
1623 int v10; // eax@26 | |
1624 int v12; // eax@31 | |
1625 int v14; // eax@36 | |
1626 int v16; // eax@41 | |
1627 NPCData *v17; // [sp+10h] [bp-4h]@4 | |
1628 | |
1629 num_menu_buttons = 0; | |
1630 pDialogueNPCCount = (_this + 1); | |
1631 if ( _this + 1 == uNumDialogueNPCPortraits && uHouse_ExitPic ) | |
1632 { | |
1633 pDialogueWindow->Release(); | |
1634 pDialogueWindow = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0); | |
1635 sprintfex(sHouseName.data(), pGlobalTXT_LocalizationStrings[LOCSTR_ENTER_S], pMapStats->pInfos[uHouse_ExitPic].pName); | |
1636 pBtn_ExitCancel = pDialogueWindow->CreateButton(566, 445, 75, 33, 1, 0, UIMSG_Escape, 0, 'N', pGlobalTXT_LocalizationStrings[34], pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0);// "Cancel" | |
1637 pBtn_YES = pDialogueWindow->CreateButton(486, 445, 75, 33, 1, 0, UIMSG_BF, 1, 'Y', sHouseName.data(), pIcons_LOD->GetTexture(uTextureID_BUTTYES2), 0); | |
1638 pDialogueWindow->CreateButton( pNPCPortraits_x[0][0], pNPCPortraits_y[0][0], 63u, 73u, 1, 0, UIMSG_BF, 1u, 0x20u, sHouseName.data(), 0); | |
1639 pDialogueWindow->CreateButton(8, 8, 460, 344, 1, 0, UIMSG_BF, 1, 0x59u, sHouseName.data(), 0); | |
1640 } | |
1641 else | |
1642 { | |
1313 | 1643 v17 = HouseNPCData[_this + 1 - ((dword_591080 != 0)?1:0 )];//+ 1 |
1295 | 1644 if ( dialog_menu_id == HOUSE_DIALOGUE_OTHER ) |
1645 { | |
1646 pDialogueWindow->Release(); | |
1647 } | |
1648 else | |
1649 { | |
1650 for ( i = 0; i < uNumDialogueNPCPortraits; ++i ) | |
1651 dword_5913F4[i]->Release(); | |
1652 } | |
1653 pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x159u, WINDOW_MainMenu, 0, 0); | |
1654 pBtn_ExitCancel = pDialogueWindow->CreateButton( 471u, 445u, 169u, 35u, 1, 0, UIMSG_Escape, 0, 0, | |
1655 pGlobalTXT_LocalizationStrings[74],// "End Conversation" | |
1656 pIcons_LOD->GetTexture(uExitCancelTextureId), 0); | |
1657 pDialogueWindow->CreateButton(8u, 8u, 0x1C2u, 0x140u, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", 0); | |
1658 if ( pDialogueNPCCount == 1 && dword_591080 ) | |
1659 { | |
1660 sub_4B3B42(in_current_building_type); | |
1661 } | |
1662 else | |
1663 { | |
1664 if ( v17->joins ) | |
1665 { | |
1666 num_menu_buttons = 1; | |
1667 pDialogueWindow->CreateButton(480u, 160u, 140u, 30, 1, 0, UIMSG_ClickNPCTopic, 0xDu, 0, "", 0); | |
1668 } | |
1669 if ( v17->evt_A) | |
1670 { | |
1671 if ( num_menu_buttons < 4 ) | |
1672 { | |
1673 v6 = NPC_EventProcessor(v17->evt_A); | |
1674 if ( v6 == 1 || v6 == 2 ) | |
1675 pDialogueWindow->CreateButton( 480u, 30 * num_menu_buttons++ + 160, 140u, 30u, 1, 0, UIMSG_ClickNPCTopic, 0x13u, 0, "", 0); | |
1676 } | |
1677 } | |
1678 if ( v17->evt_B ) | |
1679 { | |
1680 if ( num_menu_buttons < 4 ) | |
1681 { | |
1682 v8 = NPC_EventProcessor(v17->evt_B); | |
1683 if ( v8 == 1 || v8 == 2 ) | |
1684 pDialogueWindow->CreateButton( 480u, 30 * num_menu_buttons++ + 160, 140u, 30u, 1, 0, UIMSG_ClickNPCTopic, 0x14u, 0, "", 0); | |
1685 } | |
1686 } | |
1687 if ( v17->evt_C ) | |
1688 { | |
1689 if ( num_menu_buttons < 4 ) | |
1690 { | |
1691 v10 = NPC_EventProcessor(v17->evt_C); | |
1692 if ( v10 == 1 || v10 == 2 ) | |
1693 pDialogueWindow->CreateButton( 480u, 30 * num_menu_buttons++ + 160, 140u, 30u, 1, 0, UIMSG_ClickNPCTopic, 0x15u, 0, "", 0); | |
1694 } | |
1695 } | |
1696 | |
1697 if ( v17->evt_D ) | |
1698 { | |
1699 if ( num_menu_buttons < 4 ) | |
1700 { | |
1701 v12 = NPC_EventProcessor(v17->evt_D); | |
1702 if ( v12 == 1 || v12 == 2 ) | |
1703 pDialogueWindow->CreateButton( 0x1E0u, 30 * num_menu_buttons++ + 160, 0x8Cu, 0x1Eu, 1, 0, UIMSG_ClickNPCTopic, 0x16u, 0, "", 0); | |
1704 } | |
1705 } | |
1706 if ( v17->evt_E ) | |
1707 { | |
1708 if ( num_menu_buttons < 4 ) | |
1709 { | |
1710 v14 = NPC_EventProcessor(v17->evt_E); | |
1711 if ( v14 == 1 || v14 == 2 ) | |
1712 pDialogueWindow->CreateButton( 0x1E0u, 30 * num_menu_buttons++ + 160, 0x8Cu, 0x1Eu, 1, 0, UIMSG_ClickNPCTopic, 0x17u, 0, "", 0); | |
1713 } | |
1714 } | |
1715 if ( v17->evt_F ) | |
1716 { | |
1717 if ( num_menu_buttons < 4 ) | |
1718 { | |
1719 v16 = NPC_EventProcessor(v17->evt_F); | |
1720 if ( v16 == 1 || v16 == 2 ) | |
1721 pDialogueWindow->CreateButton( 0x1E0u, 30 * num_menu_buttons++ + 160, 0x8Cu, 0x1Eu, 1, 0, UIMSG_ClickNPCTopic, 0x18u, 0, "", 0); | |
1722 } | |
1723 } | |
1724 pDialogueWindow->_41D08F_set_keyboard_control_group(num_menu_buttons, 1, 0, 2); | |
1725 dword_F8B1E0 = pDialogueWindow->pNumPresenceButton; | |
1726 } | |
1727 dialog_menu_id = HOUSE_DIALOGUE_MAIN; | |
1728 } | |
1729 | |
1730 } | |
1731 //----- (004466C4) -------------------------------------------------------- | |
1732 int NPC_EventProcessor(int npc_event_id, int entry_line) | |
1733 { | |
1734 signed int event_index; // ebp@1 | |
1735 int evt_seq_num; // esi@3 | |
1736 bool ready_to_exit; // [sp+Ch] [bp-Ch]@3 | |
1737 signed int npc_activity; // [sp+10h] [bp-8h]@3 | |
1738 int result; | |
1739 | |
1740 event_index = 0; | |
1741 if ( !npc_event_id ) | |
1742 return 0; | |
1743 evt_seq_num = entry_line; | |
1744 pSomeOtherEVT = pGlobalEVT.data(); | |
1745 uSomeOtherEVT_NumEvents = uGlobalEVT_NumEvents; | |
1746 memcpy(pSomeOtherEVT_Events.data(), pGlobalEVT_Index.data(), sizeof(EventIndex)*4400); | |
1747 npc_activity = 1; | |
1748 ready_to_exit = false; | |
1749 if ( uSomeOtherEVT_NumEvents <= 0 ) | |
1750 return 2; | |
1751 do | |
1752 { | |
1753 if ( (pSomeOtherEVT_Events[event_index].uEventID == npc_event_id) && (pSomeOtherEVT_Events[event_index].event_sequence_num == evt_seq_num) ) | |
1754 { | |
1755 _evt_raw *_evt = (_evt_raw *)&pSomeOtherEVT[pSomeOtherEVT_Events[event_index].uEventOffsetInEVT]; | |
1756 switch(_evt->_e_type) | |
1757 { | |
1758 case EVENT_Exit: | |
1759 //exit | |
1760 if ( ready_to_exit ) | |
1761 result = npc_activity != 0; | |
1762 else | |
1763 result = 2; | |
1764 return result; | |
1765 break; | |
1766 case EVENT_OnCanShowDialogItemCmp: | |
1767 ready_to_exit = true; | |
1768 //v8 = (unsigned __int8)v7[7] + (((unsigned __int8)v7[8] + (((unsigned __int8)v7[9] + ((unsigned __int8)v7[10] << 8)) << 8)) << 8); | |
1769 for(int i=0; i<4; ++i) | |
1770 { | |
1771 // if (pParty->pPlayers[i].CompareVariable((enum VariableType)((unsigned __int8)pSomeOtherEVT[v6 + 5] + ((unsigned __int8)pSomeOtherEVT[v6 + 6] << 8)), | |
1772 // v8)) | |
1773 if (pParty->pPlayers[i].CompareVariable((enum VariableType)EVT_WORD(_evt->v5), EVT_DWORD(_evt->v7))) | |
1774 { | |
1775 event_index = -1; | |
1776 evt_seq_num = EVT_BYTE(_evt->v11)-1;//(unsigned __int8)pSomeOtherEVT[v6 + 11] - 1; | |
1777 break; | |
1778 } | |
1779 } | |
1780 break; | |
1781 case EVENT_EndCanShowDialogItem : | |
1782 if ( ready_to_exit ) | |
1783 result = npc_activity != 0; | |
1784 else | |
1785 result = 2; | |
1786 return result; | |
1787 break; | |
1788 case EVENT_SetCanShowDialogItem : | |
1789 ready_to_exit = true; | |
1790 npc_activity = EVT_BYTE(_evt->v5); //(unsigned __int8)v7[5]; | |
1791 break; | |
1792 case EVENT_IsActorAssasinated : | |
1793 // if (IsActorAlive( (unsigned __int8)v7[5], | |
1794 // (unsigned __int8)v7[6] + (((unsigned __int8)v7[7] + (((unsigned __int8)v7[8] + ((unsigned __int8)v7[9] << 8)) << 8)) << 8), | |
1795 // (unsigned __int8)v7[10]) ) | |
1796 if (IsActorAlive( EVT_BYTE(_evt->v5), EVT_DWORD(_evt->v6), EVT_BYTE(_evt->v10))) | |
1797 { // drop linear sequense, going to new seq | |
1798 event_index = -1; | |
1799 evt_seq_num = EVT_BYTE(_evt->v11)-1;//(unsigned __int8)pSomeOtherEVT[v6 + 11] - 1; | |
1800 } | |
1801 break; | |
1802 } | |
1803 ++evt_seq_num; | |
1804 } | |
1805 ++event_index; | |
1806 } | |
1807 while ( event_index < uSomeOtherEVT_NumEvents ); | |
1808 if ( ready_to_exit ) | |
1809 result = npc_activity != 0; | |
1810 else | |
1811 result = 2; | |
1812 return result; | |
1813 } | |
1814 //----- (00445C8B) -------------------------------------------------------- | |
1815 int __fastcall GetGreetType(signed int SpeakingNPC_ID) | |
1816 { | |
1817 signed int v1; // ebx@1 | |
1818 int v3; // edi@6 | |
1819 int v4; // ecx@6 | |
1820 int v5; // edx@6 | |
1821 NPCData *v6; // eax@6 | |
1822 char *v7; // ebp@11 | |
1823 NPCData *v8; // esi@11 | |
1824 | |
1825 v1 = 0; | |
1826 if ( SpeakingNPC_ID >= 0 ) | |
1827 { | |
1828 if ( SpeakingNPC_ID < 5000 ) | |
1829 return 1;//QuestNPC_greet | |
1830 return 2;//HiredNPC_greet | |
1831 } | |
1832 if ( SpeakingNPC_ID >= 5000 ) | |
1833 return 2; | |
1834 v3 = abs((int)sDialogue_SpeakingActorNPC_ID) - 1; | |
1835 v4 = 0; | |
1836 v5 = 0; | |
1837 v6 = pParty->pHirelings; | |
1838 do | |
1839 { | |
1840 if ( v6->pName ) | |
1841 pTmpBuf[v4++] = v5; | |
1842 ++v6; | |
1843 ++v5; | |
1844 } | |
1845 while ( (signed int)v6 < (signed int)&pParty->pPickedItem ); | |
1846 if ( (signed int)pNPCStats->uNumNewNPCs > 0 ) | |
1847 { | |
1848 v7 = &pTmpBuf[v4]; | |
1849 v8 = pNPCStats->pNewNPCData; | |
1850 do | |
1851 { | |
1852 if (v8->Hired() && (!pParty->pHirelings[0].pName || strcmp(v8->pName, pParty->pHirelings[0].pName)) ) | |
1853 { | |
1854 if ( !pParty->pHirelings[1].pName || strcmp(v8->pName, pParty->pHirelings[1].pName) ) | |
1855 *v7++ = v1 + 2; | |
1856 } | |
1857 ++v1; | |
1858 ++v8; | |
1859 } | |
1860 while ( v1 < (signed int)pNPCStats->uNumNewNPCs ); | |
1861 } | |
1862 return ((unsigned __int8)pTmpBuf[v3] < 2) + 1; | |
1863 } | |
1864 //----- (00445308) -------------------------------------------------------- | |
1865 const char *GetProfessionActionText(int a1) | |
1866 { | |
1867 if ( a1 == 10 | |
1868 || a1 == 11 | |
1869 || a1 == 12 | |
1870 || a1 == 33 | |
1871 || a1 == 34 | |
1872 || a1 == 39 | |
1873 || a1 == 40 | |
1874 || a1 == 41 | |
1875 || a1 == 42 | |
1876 || a1 == 43 | |
1877 || a1 == 52 ) | |
1878 return pNPCStats->pProfessions[a1 - 1].pActionText; | |
1879 else | |
1880 return pNPCTopics[407].pTopic; | |
1881 } |