comparison mm7_4.cpp @ 0:8b8875f5b359

Initial commit
author Nomad
date Fri, 05 Oct 2012 16:07:14 +0200
parents
children ac0fb48cd27a
comparison
equal deleted inserted replaced
-1:000000000000 0:8b8875f5b359
1 #include <io.h>
2 #include <direct.h>
3
4 #include "MapInfo.h"
5 #include "Game.h"
6 #include "GUIWindow.h"
7 #include "GUIButton.h"
8 #include "GUIFont.h"
9 #include "Party.h"
10 #include "AudioPlayer.h"
11 #include "Outdoor.h"
12 #include "IndoorCamera.h"
13 #include "Overlays.h"
14 #include "Monsters.h"
15 #include "Arcomage.h"
16 #include "LOD.h"
17 #include "Actor.h"
18 #include "Allocator.h"
19 #include "Events.h"
20 #include "Viewport.h"
21 #include "FrameTableInc.h"
22 #include "Math.h"
23 #include "LayingItem.h"
24 #include "ObjectList.h"
25 #include "Chest.h"
26 #include "PaletteManager.h"
27 #include "DecorationList.h"
28 #include "SaveLoad.h"
29 #include "stru123.h"
30 #include "stru287.h"
31 #include "Time.h"
32 #include "IconFrameTable.h"
33 #include "GUIProgressBar.h"
34 #include "stru157.h"
35 #include "Bink_Smacker.h"
36 #include "TileFrameTable.h"
37 #include "PlayerFrameTable.h"
38 #include "Awards.h"
39 #include "Autonotes.h"
40 #include "stru160.h"
41 #include "stru279.h"
42 #include "TurnEngine.h"
43 #include "FactionTable.h"
44 #include "StorylineTextTable.h"
45 #include "Random.h"
46 #include "stru277.h"
47 #include "stru298.h"
48 #include "stru12.h"
49 #include "stru351.h"
50 #include "Events2D.h"
51 #include "stru159.h"
52 #include "Log.h"
53
54 #include "mm7_data.h"
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 //----- (0046CC4B) --------------------------------------------------------
71 void __cdecl _46CC4B_check_event_triggers()
72 {
73 int v0; // eax@1
74 LevelDecoration *v1; // esi@2
75 signed int v2; // edi@2
76 int v3; // ebx@2
77 int v4; // eax@3
78 int v5; // ebx@3
79 unsigned int v6; // ecx@3
80 unsigned int v7; // edx@6
81 unsigned int v8; // edx@8
82 char *v9; // edi@13
83 int v10; // ebx@14
84 int v11; // eax@14
85 int v12; // ebx@14
86 unsigned int v13; // ecx@14
87 int v14; // edx@15
88 unsigned int v15; // edx@17
89 unsigned int v16; // edx@19
90 char *v17; // edi@25
91 int v18; // ebx@26
92 int v19; // eax@26
93 int v20; // ebx@26
94 unsigned int v21; // ecx@26
95 int v22; // edx@27
96 unsigned int v23; // edx@29
97 unsigned int v24; // edx@31
98 int v25; // [sp+0h] [bp-24h]@3
99 int v26; // [sp+0h] [bp-24h]@14
100 int v27; // [sp+0h] [bp-24h]@26
101 int v28; // [sp+4h] [bp-20h]@3
102 int v29; // [sp+4h] [bp-20h]@14
103 int v30; // [sp+4h] [bp-20h]@26
104 signed int v31; // [sp+8h] [bp-1Ch]@2
105 int v32; // [sp+Ch] [bp-18h]@2
106 int v33; // [sp+10h] [bp-14h]@2
107 int i; // [sp+14h] [bp-10h]@1
108 int v35; // [sp+18h] [bp-Ch]@2
109 int v36; // [sp+1Ch] [bp-8h]@3
110 signed int v37; // [sp+1Ch] [bp-8h]@12
111 signed int v38; // [sp+20h] [bp-4h]@24
112
113 v0 = 0;
114 for ( i = 0; i < _6836C8_num_decorations_6807E8; ++i )
115 {
116 v1 = &pLevelDecorations[_6807E8_level_decorations_ids[v0]];
117 v2 = v1->field_18;
118 v3 = v1->vPosition.y;
119 v33 = v1->vPosition.x;
120 v32 = v1->vPosition.y;
121 v35 = v1->vPosition.z;
122 v31 = v1->field_18;
123 if ( v1->field_2 & 1 )
124 {
125 v36 = abs(v1->vPosition.x - pParty->vPosition.x);
126 v25 = abs(v3 - pParty->vPosition.z);
127 v28 = abs(v35 - pParty->vPosition.y);
128 v4 = v36;
129 v5 = v25;
130 v6 = v28;
131 if ( v36 < v25 )
132 {
133 v4 = v25;
134 v5 = v36;
135 }
136 if ( v4 < v28 )
137 {
138 v7 = v4;
139 v4 = v28;
140 v6 = v7;
141 }
142 if ( v5 < (signed int)v6 )
143 {
144 v8 = v6;
145 v6 = v5;
146 v5 = v8;
147 }
148 if ( (signed int)(((unsigned int)(11 * v5) >> 5) + (v6 >> 2) + v4) < v2 )
149 EventProcessor(v1->field_16_event_id, 8 * i | 5, 1);
150 }
151 if ( v1->field_2 & 2 )
152 {
153 v37 = 0;
154 if ( (signed int)uNumActors > 0 )
155 {
156 v9 = (char *)&pActors[0].vPosition.y;
157 do
158 {
159 v10 = abs(v33 - *((short *)v9 - 1));
160 v29 = abs(v32 - *(short *)v9);
161 v26 = abs(v35 - *((short *)v9 + 1));
162 v11 = v10;
163 v12 = v29;
164 v13 = v26;
165 if ( v11 < v29 )
166 {
167 v14 = v11;
168 v11 = v29;
169 v12 = v14;
170 }
171 if ( v11 < v26 )
172 {
173 v15 = v11;
174 v11 = v26;
175 v13 = v15;
176 }
177 if ( v12 < (signed int)v13 )
178 {
179 v16 = v13;
180 v13 = v12;
181 v12 = v16;
182 }
183 if ( (signed int)(((unsigned int)(11 * v12) >> 5) + (v13 >> 2) + v11) < v31 )
184 EventProcessor(v1->field_16_event_id, 0, 1);
185 ++v37;
186 v9 += 836;
187 }
188 while ( v37 < (signed int)uNumActors );
189 }
190 }
191 if ( v1->field_2 & 4 )
192 {
193 v38 = 0;
194 if ( (signed int)uNumLayingItems > 0 )
195 {
196 v17 = (char *)&pLayingItems[0].vPosition.y;
197 do
198 {
199 v18 = abs(v33 - *((int *)v17 - 1));
200 v30 = abs(v32 - *(int *)v17);
201 v27 = abs(v35 - *((int *)v17 + 1));
202 v19 = v18;
203 v20 = v30;
204 v21 = v27;
205 if ( v19 < v30 )
206 {
207 v22 = v19;
208 v19 = v30;
209 v20 = v22;
210 }
211 if ( v19 < v27 )
212 {
213 v23 = v19;
214 v19 = v27;
215 v21 = v23;
216 }
217 if ( v20 < (signed int)v21 )
218 {
219 v24 = v21;
220 v21 = v20;
221 v20 = v24;
222 }
223 if ( (signed int)(((unsigned int)(11 * v20) >> 5) + (v21 >> 2) + v19) < v31 )
224 EventProcessor(v1->field_16_event_id, 0, 1);
225 ++v38;
226 v17 += 112;
227 }
228 while ( v38 < (signed int)uNumLayingItems );
229 }
230 }
231 v0 = i + 1;
232 }
233 }
234 // 6836C8: using guessed type int 6836C8_num_decorations_6807E8;
235
236 //----- (0046CEC3) --------------------------------------------------------
237 int __fastcall _46CEC3_get_floor_level(signed int a1, signed int a2, int a3, unsigned int uSectorID, int *a5)
238 {
239 BLVSector *v5; // edi@1
240 int v6; // ecx@1
241 Vec3_short_ *v7; // edx@1
242 BLVFace *v8; // esi@2
243 int v9; // eax@8
244 int v10; // edi@8
245 int v11; // eax@10
246 int v12; // ecx@10
247 int v13; // ecx@13
248 signed int v14; // ebx@14
249 int v15; // eax@16
250 int v16; // edx@19
251 int v17; // ST18_4@19
252 signed int v18; // edx@19
253 signed __int64 v19; // qtt@19
254 PolygonType v20; // al@25
255 int v21; // eax@27
256 int v22; // ecx@29
257 BLVFace *v23; // eax@33
258 int v24; // esi@39
259 int v25; // edi@39
260 int v26; // esi@41
261 int v27; // ecx@43
262 signed int v28; // eax@45
263 int v29; // ebx@47
264 int v30; // edx@49
265 int v31; // ST10_4@49
266 signed int v32; // edx@49
267 signed __int64 v33; // qtt@49
268 signed int v34; // eax@54
269 signed int v35; // esi@56
270 int result; // eax@57
271 int v37; // edi@61
272 int v38; // edx@62
273 int v39; // [sp+Ch] [bp-34h]@1
274 int v40; // [sp+10h] [bp-30h]@2
275 int v41; // [sp+14h] [bp-2Ch]@12
276 unsigned __int16 *v42; // [sp+18h] [bp-28h]@1
277 BLVSector *v43; // [sp+1Ch] [bp-24h]@1
278 int v44; // [sp+20h] [bp-20h]@10
279 int v45; // [sp+24h] [bp-1Ch]@10
280 signed int v46; // [sp+24h] [bp-1Ch]@38
281 bool v47; // [sp+24h] [bp-1Ch]@43
282 bool v48; // [sp+28h] [bp-18h]@10
283 bool v49; // [sp+28h] [bp-18h]@41
284 bool v50; // [sp+2Ch] [bp-14h]@12
285 int v51; // [sp+2Ch] [bp-14h]@41
286 signed int v52; // [sp+30h] [bp-10h]@7
287 signed int v53; // [sp+30h] [bp-10h]@10
288 signed int v54; // [sp+30h] [bp-10h]@41
289 signed int v55; // [sp+34h] [bp-Ch]@1
290 signed int v56; // [sp+38h] [bp-8h]@1
291 signed int v57; // [sp+3Ch] [bp-4h]@1
292 int uSectorIDa; // [sp+4Ch] [bp+Ch]@1
293 signed int uSectorIDb; // [sp+4Ch] [bp+Ch]@32
294
295 v5 = &pIndoor->pSectors[uSectorID];
296 v57 = a2;
297 v56 = a1;
298 v6 = 0;
299 v55 = 0;
300 v43 = v5;
301 v42 = v5->pFloors;
302 v7 = pIndoor->pVertices;
303 v39 = v5->field_4;
304 for ( uSectorIDa = 0; uSectorIDa < v39; ++uSectorIDa )
305 {
306 v40 = (int)&v42[v6];
307 v8 = &pIndoor->pFaces[*(short *)v40];
308 if ( !(BYTE3(v8->uAttributes) & 0x20)
309 && v56 <= v8->pBounding.x2
310 && v56 >= v8->pBounding.x1
311 && v57 <= v8->pBounding.y2
312 && v57 >= v8->pBounding.y1 )
313 {
314 v52 = 0;
315 if ( v8->uNumVertices )
316 {
317 do
318 {
319 v9 = v52;
320 v10 = 2 * v52;
321 word_721460[2 * v52] = v8->pXInterceptDisplacements[v52] + v7[v8->pVertexIDs[v52]].x;
322 word_721390[2 * v52] = v8->pYInterceptDisplacements[v9] + v7[v8->pVertexIDs[v9]].y;
323 word_721460[2 * v52++ + 1] = v8->pXInterceptDisplacements[v9] + v7[v8->pVertexIDs[v9 + 1]].x;
324 word_721390[v10 + 1] = v8->pYInterceptDisplacements[v9] + v7[v8->pVertexIDs[v9 + 1]].y;
325 }
326 while ( v52 < v8->uNumVertices );
327 v5 = v43;
328 }
329 v44 = 2 * v8->uNumVertices;
330 v11 = 2 * v8->uNumVertices;
331 word_721460[v11] = word_721460[0];
332 word_721390[v11] = word_721390[0];
333 v48 = word_721390[0] >= v57;
334 v12 = 0;
335 v53 = 0;
336 v45 = 0;
337 if ( v44 > 0 )
338 {
339 do
340 {
341 if ( v53 >= 2 )
342 break;
343 v41 = word_721390[v12 + 1];
344 v50 = word_721390[v12 + 1] >= v57;
345 if ( v48 == v50 )
346 {
347 v13 = v45;
348 }
349 else
350 {
351 v13 = v45;
352 if ( word_721460[v45 + 1] >= v56 )
353 v14 = 0;
354 else
355 v14 = 2;
356 v15 = v14 | word_721460[v45] < v56;
357 if ( v15 != 3 )
358 {
359 if ( !v15
360 || (v16 = word_721390[v45],
361 v17 = v41 - v16,
362 v18 = v57 - v16,
363 LODWORD(v19) = v18 << 16,
364 HIDWORD(v19) = v18 >> 16,
365 v7 = pIndoor->pVertices,
366 (signed int)(((unsigned __int64)(((signed int)word_721460[v45 + 1] - (signed int)word_721460[v45])
367 * v19
368 / v17) >> 16)
369 + word_721460[v45]) >= v56) )
370 ++v53;
371 }
372 }
373 v12 = v13 + 1;
374 v48 = v50;
375 v45 = v12;
376 }
377 while ( v12 < v44 );
378 if ( v53 == 1 )
379 {
380 if ( v55 >= 50 )
381 break;
382 v20 = v8->uPolygonType;
383 if ( v20 == 3 || v20 == 5 )
384 {
385 v21 = v7[*v8->pVertexIDs].z;
386 }
387 else
388 {
389 v7 = pIndoor->pVertices;
390 v21 = ((unsigned __int64)(v8->zCalc1 * (signed __int64)v56) >> 16)
391 + ((unsigned __int64)(v8->zCalc2 * (signed __int64)v57) >> 16)
392 + HIWORD(v8->zCalc3);
393 }
394 v22 = v55++;
395 dword_7212C8[v22] = v21;
396 dword_721200[v22] = *(short *)v40;
397 }
398 }
399 }
400 v6 = uSectorIDa + 1;
401 }
402 if ( v5->field_0 & 8 )
403 {
404 for ( uSectorIDb = 0; uSectorIDb < v5->uNumPortals; ++uSectorIDb )
405 {
406 v23 = &pIndoor->pFaces[v5->pPortals[uSectorIDb]];
407 if ( v23->uPolygonType == 3
408 && v56 <= v23->pBounding.x2
409 && v56 >= v23->pBounding.x1
410 && v57 <= v23->pBounding.y2
411 && v57 >= v23->pBounding.y1 )
412 {
413 v46 = 0;
414 if ( v23->uNumVertices )
415 {
416 do
417 {
418 v24 = v46;
419 v25 = 2 * v46;
420 word_721460[2 * v46] = v23->pXInterceptDisplacements[v46] + v7[v23->pVertexIDs[v46]].x;
421 word_721390[2 * v46] = v23->pYInterceptDisplacements[v24] + v7[v23->pVertexIDs[v24]].y;
422 word_721460[2 * v46++ + 1] = v23->pXInterceptDisplacements[v24 + 1] + v7[v23->pVertexIDs[v24 + 1]].x;
423 word_721390[v25 + 1] = v23->pYInterceptDisplacements[v24 + 1] + v7[v23->pVertexIDs[v24 + 1]].y;
424 }
425 while ( v46 < v23->uNumVertices );
426 v5 = v43;
427 }
428 v26 = 2 * v23->uNumVertices;
429 word_721460[2 * v23->uNumVertices] = word_721460[0];
430 word_721390[v26] = word_721390[0];
431 v54 = 0;
432 v51 = 0;
433 v49 = word_721390[0] >= v57;
434 if ( v26 > 0 )
435 {
436 do
437 {
438 if ( v54 >= 2 )
439 break;
440 v27 = v51;
441 v47 = word_721390[v51 + 1] >= v57;
442 if ( v49 != v47 )
443 {
444 if ( word_721460[v27 + 1] >= v56 )
445 v28 = 0;
446 else
447 v28 = 2;
448 v29 = v28 | word_721460[v27] < v56;
449 if ( v29 != 3 )
450 {
451 if ( !v29
452 || (v30 = word_721390[v27],
453 v31 = word_721390[v51 + 1] - v30,
454 v32 = v57 - v30,
455 LODWORD(v33) = v32 << 16,
456 HIDWORD(v33) = v32 >> 16,
457 v7 = pIndoor->pVertices,
458 (signed int)(((unsigned __int64)(((signed int)word_721460[v27 + 1] - (signed int)word_721460[v27])
459 * v33
460 / v31) >> 16)
461 + word_721460[v27]) >= v56) )
462 ++v54;
463 }
464 }
465 ++v51;
466 v49 = v47;
467 }
468 while ( v51 < v26 );
469 if ( v54 == 1 )
470 {
471 if ( v55 >= 50 )
472 break;
473 v34 = v55++;
474 dword_7212C8[v34] = -29000;
475 dword_721200[v34] = v5->pPortals[uSectorIDb];
476 }
477 }
478 }
479 }
480 }
481 v35 = 1;
482 if ( v55 == 1 )
483 {
484 *a5 = dword_721200[0];
485 return dword_7212C8[0];
486 }
487 if ( !v55 )
488 return -30000;
489 *a5 = dword_721200[0];
490 result = dword_7212C8[0];
491 if ( v55 > 1 )
492 {
493 v37 = a3 + 5;
494 while ( 1 )
495 {
496 v38 = dword_7212C8[v35];
497 if ( result <= v37 )
498 break;
499 if ( v38 < result )
500 goto LABEL_67;
501 LABEL_68:
502 ++v35;
503 if ( v35 >= v55 )
504 return result;
505 }
506 if ( v38 <= result || v38 > v37 )
507 goto LABEL_68;
508 LABEL_67:
509 result = dword_7212C8[v35];
510 *a5 = dword_721200[v35];
511 goto LABEL_68;
512 }
513 return result;
514 }
515
516 //----- (0046D49E) --------------------------------------------------------
517 int __fastcall sub_46D49E_prolly_get_world_y_under_party(int a1, signed int a2, int a3, int a4, int *a5, int *a6, int a7)
518 {
519 signed int v7; // edi@1
520 int v8; // ebx@1
521 int v9; // eax@1
522 BSPModel *v10; // esi@4
523 ODMFace *v11; // ecx@11
524 unsigned __int8 v12; // al@11
525 char *v13; // eax@19
526 int v14; // edx@20
527 int v15; // eax@22
528 int v16; // edx@22
529 int v17; // edi@24
530 signed int v18; // edx@26
531 int v19; // eax@28
532 int v20; // edx@30
533 int v21; // ST1C_4@30
534 signed int v22; // edx@30
535 signed __int64 v23; // qtt@30
536 int v24; // eax@36
537 signed int v25; // ecx@38
538 int result; // eax@42
539 signed int v27; // ecx@43
540 int v28; // edi@44
541 signed int v29; // edx@44
542 int v30; // esi@45
543 int v31; // eax@45
544 ODMFace *v32; // eax@57
545 int v33; // ecx@59
546 int v34; // [sp+Ch] [bp-34h]@8
547 int v35; // [sp+10h] [bp-30h]@22
548 int v36; // [sp+14h] [bp-2Ch]@24
549 int v37; // [sp+18h] [bp-28h]@22
550 int v38; // [sp+1Ch] [bp-24h]@2
551 int v39; // [sp+20h] [bp-20h]@9
552 int v40; // [sp+24h] [bp-1Ch]@1
553 signed int v41; // [sp+28h] [bp-18h]@1
554 int v42; // [sp+2Ch] [bp-14h]@8
555 bool v43; // [sp+30h] [bp-10h]@22
556 bool v44; // [sp+34h] [bp-Ch]@24
557 signed int v45; // [sp+38h] [bp-8h]@1
558 signed int v46; // [sp+3Ch] [bp-4h]@1
559 signed int v47; // [sp+58h] [bp+18h]@18
560 signed int v48; // [sp+58h] [bp+18h]@22
561 signed int v49; // [sp+58h] [bp+18h]@43
562
563 v7 = a2;
564 v8 = a1;
565 v45 = a2;
566 v40 = a1;
567 v46 = 1;
568 v9 = GetTerrainHeightsAroundParty2(a1, a2, a5, a7);
569 dword_721160[0] = -1;
570 dword_721110[0] = -1;
571 dword_7211B0[0] = v9;
572 v41 = 0;
573 if ( (signed int)pOutdoor->uNumBModels <= 0 )
574 goto LABEL_63;
575 v38 = 0;
576 while ( 1 )
577 {
578 v10 = &pOutdoor->pBModels[v38];
579 if ( v8 <= pOutdoor->pBModels[v38].sMaxX )
580 {
581 if ( v8 >= v10->sMinX )
582 {
583 if ( v7 <= v10->sMaxY )
584 {
585 if ( v7 >= v10->sMinY )
586 {
587 v42 = 0;
588 v34 = v10->uNumFaces;
589 if ( (signed int)v10->uNumFaces > 0 )
590 {
591 v39 = 0;
592 while ( 1 )
593 {
594 v11 = &v10->pFaces[v39];
595 v12 = v11->uPolygonType;
596 if ( (v12 == 3 || v12 == 4)
597 && !(BYTE3(v11->uFaceAttributes) & 0x20)
598 && v8 <= v11->pBoundingBox.x2
599 && v8 >= v11->pBoundingBox.x1
600 && v7 <= v11->pBoundingBox.y2
601 && v7 >= v11->pBoundingBox.y1 )
602 {
603 v47 = 0;
604 if ( v11->uNumVertices )
605 {
606 v13 = (char *)v11->pXInterceptDisplacements;
607 do
608 {
609 v14 = 2 * v47;
610 word_721040[2 * v47] = *(short *)v13 + LOWORD(v10->pVertices.pVertices[*((short *)v13 - 60)].x);
611 word_720F70[2 * v47] = *((short *)v13 + 20)
612 + LOWORD(v10->pVertices.pVertices[*((short *)v13 - 60)].y);
613 word_721040[2 * v47++ + 1] = *(short *)v13
614 + LOWORD(v10->pVertices.pVertices[*((short *)v13 - 59)].x);
615 word_720F70[v14 + 1] = *((short *)v13 + 20)
616 + LOWORD(v10->pVertices.pVertices[*((short *)v13 - 59)].y);
617 v13 += 2;
618 }
619 while ( v47 < v11->uNumVertices );
620 v8 = v40;
621 }
622 v15 = 2 * v11->uNumVertices;
623 word_721040[2 * v11->uNumVertices] = word_721040[0];
624 word_720F70[v15] = word_720F70[0];
625 v35 = v15;
626 v16 = 0;
627 v43 = word_720F70[0] >= v45;
628 v48 = 0;
629 v37 = 0;
630 if ( v15 > 0 )
631 {
632 do
633 {
634 if ( v48 >= 2 )
635 break;
636 v17 = v16;
637 v8 = v40;
638 v36 = word_720F70[v16 + 1];
639 v44 = word_720F70[v16 + 1] >= v45;
640 if ( v43 != v44 )
641 {
642 v18 = word_721040[v17 + 1] >= v40 ? 0 : 2;
643 v19 = v18 | word_721040[v17] < v40;
644 if ( v19 != 3 )
645 {
646 if ( !v19
647 || (v20 = word_720F70[v17],
648 v21 = v36 - v20,
649 v22 = v45 - v20,
650 LODWORD(v23) = v22 << 16,
651 HIDWORD(v23) = v22 >> 16,
652 (signed int)(((unsigned __int64)(((signed int)word_721040[v17 + 1]
653 - (signed int)word_721040[v17])
654 * v23
655 / v21) >> 16)
656 + word_721040[v17]) >= v40) )
657 ++v48;
658 }
659 }
660 v16 = v37 + 1;
661 v43 = v44;
662 ++v37;
663 }
664 while ( v37 < v35 );
665 if ( v48 == 1 )
666 {
667 if ( v46 >= 20 )
668 break;
669 if ( v11->uPolygonType == 3 )
670 v24 = v10->pVertices.pVertices[v11->pVertexIDs[0]].z;
671 else
672 v24 = ((unsigned __int64)(v11->zCalc1 * (signed __int64)v8) >> 16)
673 + ((unsigned __int64)(v11->zCalc2 * (signed __int64)v45) >> 16)
674 + HIWORD(v11->zCalc3);
675 v25 = v46++;
676 dword_7211B0[v25] = v24;
677 dword_721160[v25] = v41;
678 dword_721110[v25] = v42;
679 }
680 }
681 }
682 ++v42;
683 ++v39;
684 if ( v42 >= v34 )
685 break;
686 v7 = v45;
687 }
688 }
689 }
690 }
691 }
692 }
693 ++v41;
694 ++v38;
695 if ( v41 >= (signed int)pOutdoor->uNumBModels )
696 break;
697 v7 = v45;
698 }
699 if ( v46 == 1 )
700 {
701 LABEL_63:
702 *a6 = 0;
703 return dword_7211B0[0];
704 }
705 v27 = 0;
706 v49 = 1;
707 if ( v46 <= 1 )
708 {
709 LABEL_55:
710 *a6 = 0;
711 goto LABEL_56;
712 }
713 v28 = 0;
714 v29 = 1;
715 do
716 {
717 v30 = dword_7211B0[v29];
718 v31 = *(int *)((char *)dword_7211B0 + v28);
719 if ( v30 == v31 )
720 goto LABEL_51;
721 if ( v31 > a3 + 5 )
722 {
723 if ( v30 >= v31 )
724 goto LABEL_52;
725 LABEL_51:
726 v27 = v49;
727 v28 = v29 * 4;
728 goto LABEL_52;
729 }
730 if ( v30 > v31 && v30 <= a3 + 5 )
731 goto LABEL_51;
732 LABEL_52:
733 ++v49;
734 ++v29;
735 }
736 while ( v49 < v46 );
737 if ( !v27 )
738 goto LABEL_55;
739 *a6 = dword_721110[v27] | (dword_721160[v27] << 6);
740 LABEL_56:
741 if ( v27 )
742 {
743 v32 = &pOutdoor->pBModels[dword_721160[v27]].pFaces[dword_721110[v27]];
744 *a5 = 0;
745 if ( v32->uFaceAttributes & 0x10 )
746 *a5 = 1;
747 }
748 v33 = dword_7211B0[v27];
749 result = dword_7211B0[0];
750 if ( v33 >= dword_7211B0[0] )
751 result = v33;
752 return result;
753 }
754
755 //----- (0046D8E3) --------------------------------------------------------
756 int __fastcall sub_46D8E3(int a1, signed int a2, int a3, int a4)
757 {
758 int v4; // ebx@1
759 unsigned int v5; // ecx@1
760 BSPModel *v6; // edi@3
761 ODMFace *v7; // esi@10
762 unsigned __int8 v8; // al@10
763 unsigned __int16 *v9; // eax@18
764 int v10; // edx@19
765 int v11; // ecx@21
766 int v12; // ecx@23
767 signed int v13; // eax@25
768 int v14; // edx@27
769 int v15; // edx@29
770 int v16; // ST18_4@29
771 signed int v17; // edx@29
772 signed __int64 v18; // qtt@29
773 int v19; // eax@35
774 signed int v20; // ecx@37
775 signed int v22; // ebx@42
776 unsigned int v23; // esi@43
777 int v24; // edx@44
778 int v25; // eax@44
779 int v26; // [sp+Ch] [bp-38h]@7
780 int v27; // [sp+10h] [bp-34h]@21
781 int v28; // [sp+18h] [bp-2Ch]@21
782 int v29; // [sp+1Ch] [bp-28h]@2
783 unsigned int v30; // [sp+20h] [bp-24h]@8
784 signed int v31; // [sp+24h] [bp-20h]@1
785 signed int v32; // [sp+28h] [bp-1Ch]@1
786 int v33; // [sp+2Ch] [bp-18h]@7
787 bool v34; // [sp+30h] [bp-14h]@21
788 bool v35; // [sp+34h] [bp-10h]@23
789 signed int v36; // [sp+38h] [bp-Ch]@17
790 signed int v37; // [sp+38h] [bp-Ch]@21
791 signed int v38; // [sp+38h] [bp-Ch]@42
792 signed int v39; // [sp+3Ch] [bp-8h]@1
793 signed int v40; // [sp+40h] [bp-4h]@1
794
795 dword_720ED0[0] = -1;
796 dword_720E80[0] = -1;
797 v4 = a1;
798 v5 = 0;
799 v40 = a2;
800 v31 = v4;
801 v39 = 1;
802 dword_720F20[0] = 10000;
803 v32 = 0;
804 if ( (signed int)pOutdoor->uNumBModels > 0 )
805 {
806 v29 = 0;
807 do
808 {
809 v6 = &pOutdoor->pBModels[v29];
810 if ( v4 <= pOutdoor->pBModels[v29].sMaxX )
811 {
812 if ( v4 >= v6->sMinX )
813 {
814 if ( v40 <= v6->sMaxY )
815 {
816 if ( v40 >= v6->sMinY )
817 {
818 v33 = v5;
819 v26 = v6->uNumFaces;
820 if ( (signed int)v6->uNumFaces > (signed int)v5 )
821 {
822 v30 = v5;
823 while ( 1 )
824 {
825 v7 = (ODMFace *)((char *)v6->pFaces + v30);
826 v8 = v7->uPolygonType;
827 if ( (v8 == 5 || v8 == 6)
828 && !(BYTE3(v7->uFaceAttributes) & 0x20)
829 && v4 <= v7->pBoundingBox.x2
830 && v4 >= v7->pBoundingBox.x1
831 && v40 <= v7->pBoundingBox.y2
832 && v40 >= v7->pBoundingBox.y1 )
833 {
834 v36 = v5;
835 if ( v7->uNumVertices )
836 {
837 v9 = v7->pXInterceptDisplacements;
838 do
839 {
840 v10 = 2 * v36;
841 word_720DB0_xs[2 * v36] = *v9 + LOWORD(v6->pVertices.pVertices[*(v9 - 60)].x);
842 word_720CE0_ys[2 * v36] = v9[20] + LOWORD(v6->pVertices.pVertices[*(v9 - 60)].y);
843 word_720DB0_xs[2 * v36++ + 1] = *v9 + LOWORD(v6->pVertices.pVertices[*(v9 - 59)].x);
844 word_720CE0_ys[v10 + 1] = v9[20] + LOWORD(v6->pVertices.pVertices[*(v9 - 59)].y);
845 ++v9;
846 }
847 while ( v36 < v7->uNumVertices );
848 v4 = v31;
849 }
850 v27 = 2 * v7->uNumVertices;
851 word_720DB0_xs[2 * v7->uNumVertices] = word_720DB0_xs[0];
852 word_720CE0_ys[v27] = word_720CE0_ys[0];
853 v11 = 0;
854 v34 = word_720CE0_ys[0] >= v40;
855 v37 = 0;
856 v28 = 0;
857 if ( v27 > 0 )
858 {
859 do
860 {
861 if ( v37 >= 2 )
862 break;
863 v12 = v11;
864 v4 = v31;
865 v35 = word_720CE0_ys[v12 + 1] >= v40;
866 if ( v34 != v35 )
867 {
868 v13 = word_720DB0_xs[v12 + 1] >= v31 ? 0 : 2;
869 v14 = v13 | word_720DB0_xs[v12] < v31;
870 if ( v14 != 3 )
871 {
872 if ( !v14
873 || (v15 = word_720CE0_ys[v12],
874 v16 = word_720CE0_ys[v12 + 1] - v15,
875 v17 = v40 - v15,
876 LODWORD(v18) = v17 << 16,
877 HIDWORD(v18) = v17 >> 16,
878 (signed int)(((unsigned __int64)(((signed int)word_720DB0_xs[v12 + 1]
879 - (signed int)word_720DB0_xs[v12])
880 * v18
881 / v16) >> 16)
882 + word_720DB0_xs[v12]) >= v31) )
883 ++v37;
884 }
885 }
886 v11 = v28 + 1;
887 v34 = v35;
888 ++v28;
889 }
890 while ( v28 < v27 );
891 if ( v37 == 1 )
892 {
893 if ( v39 >= 20 )
894 break;
895 if ( v7->uPolygonType == 5 )
896 v19 = v6->pVertices.pVertices[v7->pVertexIDs[0]].z;
897 else
898 v19 = ((unsigned __int64)(v7->zCalc1 * (signed __int64)v4) >> 16)
899 + ((unsigned __int64)(v7->zCalc2 * (signed __int64)v40) >> 16)
900 + HIWORD(v7->zCalc3);
901 v20 = v39++;
902 dword_720F20[v20] = v19;
903 dword_720ED0[v20] = v32;
904 dword_720E80[v20] = v33;
905 }
906 }
907 }
908 ++v33;
909 v30 += 308;
910 if ( v33 >= v26 )
911 break;
912 v5 = 0;
913 }
914 }
915 }
916 }
917 }
918 }
919 ++v32;
920 ++v29;
921 v5 = 0;
922 }
923 while ( v32 < (signed int)pOutdoor->uNumBModels );
924 if ( !v39 )
925 {
926 *(int *)a4 = 0;
927 return dword_720F20[0];
928 }
929 }
930 v22 = 0;
931 v38 = v5;
932 if ( v39 <= (signed int)v5 )
933 goto LABEL_54;
934 v23 = 0;
935 do
936 {
937 v24 = dword_720F20[v5 / 4];
938 v25 = *(int *)((char *)dword_720F20 + v23);
939 if ( v24 == v25 )
940 goto LABEL_50;
941 if ( v25 > a3 + 15 )
942 {
943 if ( v24 >= v25 )
944 goto LABEL_51;
945 LABEL_50:
946 v22 = v38;
947 v23 = v5;
948 goto LABEL_51;
949 }
950 if ( v24 > v25 && v24 <= a3 + 15 )
951 goto LABEL_50;
952 LABEL_51:
953 ++v38;
954 v5 += 4;
955 }
956 while ( v38 < v39 );
957 if ( v22 )
958 {
959 *(int *)a4 = dword_720E80[v22] | (dword_720ED0[v22] << 6);
960 return dword_720F20[v22];
961 }
962 LABEL_54:
963 *(int *)a4 = 0;
964 return dword_720F20[v22];
965 }
966
967 //----- (0046DCC8) --------------------------------------------------------
968 signed __int64 __fastcall _46DCC8_get_gravity_direction_outdoor(int a1, int a2, Vec3_int_ *a3)
969 {
970 int v3; // ebx@1
971 int v4; // ST4C_4@1
972 unsigned int v5; // ST54_4@1
973 unsigned int v6; // edi@1
974 unsigned int v7; // ST50_4@1
975 int v8; // edi@1
976 int v9; // esi@1
977 int v10; // ebx@1
978 int v11; // ecx@2
979 int v12; // eax@2
980 int v13; // edx@2
981 int v14; // ebx@2
982 double v15; // st7@4
983 double v16; // st6@4
984 double v17; // st5@4
985 float v18; // ST44_4@4
986 float v19; // ST54_4@4
987 double v20; // st4@4
988 double v21; // st5@4
989 float v22; // ST44_4@6
990 double v23; // st7@4
991 double v24; // st7@6
992 signed __int64 result; // qax@6
993 int v26; // [sp+14h] [bp-44h]@1
994 int v27; // [sp+18h] [bp-40h]@1
995 int v28; // [sp+20h] [bp-38h]@1
996 int v29; // [sp+24h] [bp-34h]@1
997 int v30; // [sp+28h] [bp-30h]@1
998 int v31; // [sp+2Ch] [bp-2Ch]@1
999 int v32; // [sp+30h] [bp-28h]@1
1000 int v33; // [sp+34h] [bp-24h]@1
1001 int v34; // [sp+38h] [bp-20h]@1
1002 int v35; // [sp+3Ch] [bp-1Ch]@1
1003 int v36; // [sp+40h] [bp-18h]@1
1004 int v37; // [sp+4Ch] [bp-Ch]@2
1005 float v38; // [sp+4Ch] [bp-Ch]@4
1006 int v39; // [sp+50h] [bp-8h]@2
1007 float v40; // [sp+50h] [bp-8h]@4
1008 int v41; // [sp+54h] [bp-4h]@2
1009
1010 v3 = a1;
1011 v4 = a2;
1012 v5 = WorldPosToGridCellX(a1);
1013 v6 = WorldPosToGridCellZ(v4) - 1;
1014 v33 = GridCellToWorldPosX(v5);
1015 v34 = GridCellToWorldPosX(v5 + 1);
1016 v35 = GridCellToWorldPosX(v5 + 1);
1017 v36 = GridCellToWorldPosX(v5);
1018 v29 = GridCellToWorldPosZ(v6);
1019 v30 = GridCellToWorldPosZ(v6);
1020 v7 = v6 + 1;
1021 v31 = GridCellToWorldPosZ(v6 + 1);
1022 v32 = GridCellToWorldPosZ(v6 + 1);
1023 v26 = pOutdoor->DoGetHeightOnTerrain(v5, v6);
1024 v27 = pOutdoor->DoGetHeightOnTerrain(v5 + 1, v6);
1025 v8 = pOutdoor->DoGetHeightOnTerrain(v5 + 1, v6 + 1);
1026 v28 = pOutdoor->DoGetHeightOnTerrain(v5, v7);
1027 v9 = v29;
1028 v10 = abs(v3 - v33);
1029 if ( abs(v29 - v4) >= v10 )
1030 {
1031 v11 = v33;
1032 v37 = v28;
1033 v39 = v36;
1034 v12 = v35;
1035 v41 = v32;
1036 v13 = v31;
1037 v14 = v8;
1038 v8 = v26;
1039 }
1040 else
1041 {
1042 v11 = v35;
1043 v41 = v30;
1044 v39 = v34;
1045 v12 = v33;
1046 v13 = v29;
1047 v9 = v31;
1048 v37 = v27;
1049 v14 = v26;
1050 }
1051 v15 = (double)(v12 - v39);
1052 v16 = (double)(v13 - v41);
1053 v17 = (double)(v14 - v37);
1054 v18 = (double)(v11 - v39);
1055 v19 = (double)(v9 - v41);
1056 v20 = (double)(v8 - v37);
1057 v38 = v20 * v16 - v19 * v17;
1058 v40 = v18 * v17 - v20 * v15;
1059 v21 = v19 * v15 - v18 * v16;
1060 v23 = sqrt(v21 * v21 + v40 * v40 + v38 * v38);
1061 if ( v23 == 0.0 )
1062 {
1063 a3->y = 0;
1064 a3->x = 0;
1065 a3->z = 65536;
1066 }
1067 v24 = 1.0 / v23;
1068 a3->x = (signed __int64)(v24 * v38 * 65536.0);
1069 a3->y = (signed __int64)(v24 * v40 * 65536.0);
1070 v22 = v21;
1071 result = (signed __int64)(v24 * v22 * 65536.0);
1072 a3->z = result;
1073 return result;
1074 }
1075 // 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
1076 // 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);
1077 // 47F469: using guessed type int __stdcall GridCellToWorldPosX(int);
1078 // 47F476: using guessed type int __stdcall GridCellToWorldPosZ(int);
1079
1080 //----- (0046DEF2) --------------------------------------------------------
1081 unsigned int __fastcall sub_46DEF2(signed int a2, unsigned int uLayingItemID)
1082 {
1083 unsigned int result; // eax@1
1084
1085 result = uLayingItemID;
1086 if ( pObjectList->pObjects[pLayingItems[uLayingItemID].uObjectDescID].uFlags & 0x10 )
1087 result = _46BFFA_check_object_intercept(uLayingItemID, a2);
1088 return result;
1089 }
1090
1091 //----- (0046DF1A) --------------------------------------------------------
1092 signed int __fastcall _46DF1A_collide_against_actor(int a1, int a2)
1093 {
1094 Actor *v2; // edi@1
1095 unsigned __int16 v3; // ax@1
1096 int v4; // esi@6
1097 int v5; // ecx@8
1098 int v6; // eax@10
1099 int v7; // edx@12
1100 int v8; // ecx@14
1101 int v9; // eax@14
1102 int v10; // ebx@14
1103 int v11; // esi@14
1104 int v12; // ebx@15
1105 int v13; // ebx@17
1106 unsigned int v14; // eax@20
1107 signed int result; // eax@21
1108 int v16; // [sp+Ch] [bp-10h]@1
1109 int v17; // [sp+10h] [bp-Ch]@14
1110 int v18; // [sp+14h] [bp-8h]@14
1111 int v19; // [sp+18h] [bp-4h]@14
1112
1113 v16 = a1;
1114 v2 = &pActors[a1];
1115 v3 = v2->uAIState;
1116 if ( v3 == 11 || v3 == 4 || v3 == 19 || v3 == 5 || v3 == 17 )
1117 goto LABEL_25;
1118 v4 = v2->uActorRadius;
1119 if ( a2 )
1120 v4 = a2;
1121 v5 = v2->vPosition.x;
1122 if ( stru_721530.sMaxX > v5 + v4
1123 || stru_721530.sMinX < v5 - v4
1124 || (v6 = v2->vPosition.y, stru_721530.sMaxY > v6 + v4)
1125 || stru_721530.sMinY < v6 - v4
1126 || (v7 = v2->vPosition.z, stru_721530.sMaxZ > v7 + v2->uActorHeight)
1127 || stru_721530.sMinZ < v7
1128 || (v8 = v5 - stru_721530.normal.x,
1129 v9 = v6 - stru_721530.normal.y,
1130 v10 = stru_721530.prolly_normal_d + v4,
1131 v17 = stru_721530.prolly_normal_d + v4,
1132 v11 = (v8 * stru_721530.field_58.y - v9 * stru_721530.field_58.x) >> 16,
1133 v18 = v8,
1134 v19 = v9,
1135 abs((v8 * stru_721530.field_58.y - v9 * stru_721530.field_58.x) >> 16) > v10)
1136 || (v12 = (v18 * stru_721530.field_58.x + v19 * stru_721530.field_58.y) >> 16, v12 <= 0)
1137 || (signed int)(((unsigned __int64)(stru_721530.field_58.z * (signed __int64)v12) >> 16) + stru_721530.normal.z) < v2->vPosition.z )
1138 {
1139 LABEL_25:
1140 result = 0;
1141 }
1142 else
1143 {
1144 v13 = v12 - sub_452A9E(v17 * v17 - v11 * v11);
1145 if ( v13 < 0 )
1146 v13 = 0;
1147 if ( v13 < stru_721530.field_7C )
1148 {
1149 stru_721530.field_7C = v13;
1150 v14 = 8 * v16;
1151 LOBYTE(v14) = 8 * v16 | 3;
1152 stru_721530.uFaceID = v14;
1153 }
1154 result = 1;
1155 }
1156 return result;
1157 }
1158 // 46DF1A: using guessed type int __fastcall 46DF1A_collide_against_actor(int, int);
1159
1160 //----- (0046E0B2) --------------------------------------------------------
1161 void __cdecl _46E0B2_collide_against_decorations()
1162 {
1163 BLVSector *v0; // ebp@1
1164 LevelDecoration *v1; // edi@2
1165 DecorationDesc *v2; // esi@3
1166 int v3; // edx@4
1167 int v4; // eax@4
1168 int v5; // ecx@6
1169 int v6; // ebx@8
1170 int v7; // esi@8
1171 int v8; // ebx@10
1172 int v9; // esi@11
1173 int v10; // edi@12
1174 int v11; // eax@12
1175 int v12; // esi@14
1176 unsigned int v13; // eax@17
1177 signed int i; // [sp+4h] [bp-14h]@1
1178 int v15; // [sp+8h] [bp-10h]@10
1179 int v16; // [sp+Ch] [bp-Ch]@10
1180 int v17; // [sp+10h] [bp-8h]@10
1181 int v18; // [sp+14h] [bp-4h]@8
1182
1183 v0 = &pIndoor->pSectors[stru_721530.uSectorID];
1184 for ( i = 0; i < v0->uNumDecorations; ++i )
1185 {
1186 v1 = &pLevelDecorations[v0->pDecorationIDs[i]];
1187 if ( !(v1->field_2 & 0x20) )
1188 {
1189 v2 = &pDecorationList->pDecorations[v1->uDecorationDescID];
1190 if ( !(v2->uFlags & 1) )
1191 {
1192 v3 = v2->uRadius;
1193 v4 = v1->vPosition.x;
1194 if ( stru_721530.sMaxX <= v4 + v3 )
1195 {
1196 if ( stru_721530.sMinX >= v4 - v3 )
1197 {
1198 v5 = v1->vPosition.y;
1199 if ( stru_721530.sMaxY <= v5 + v3 )
1200 {
1201 if ( stru_721530.sMinY >= v5 - v3 )
1202 {
1203 v6 = v2->uDecorationHeight;
1204 v7 = v1->vPosition.z;
1205 v18 = v6;
1206 if ( stru_721530.sMaxZ <= v7 + v6 )
1207 {
1208 if ( stru_721530.sMinZ >= v7 )
1209 {
1210 v16 = v4 - stru_721530.normal.x;
1211 v15 = v5 - stru_721530.normal.y;
1212 v8 = stru_721530.prolly_normal_d + v3;
1213 v17 = ((v4 - stru_721530.normal.x) * stru_721530.field_58.y
1214 - (v5 - stru_721530.normal.y) * stru_721530.field_58.x) >> 16;
1215 if ( abs(v17) <= stru_721530.prolly_normal_d + v3 )
1216 {
1217 v9 = (v16 * stru_721530.field_58.x + v15 * stru_721530.field_58.y) >> 16;
1218 if ( v9 > 0 )
1219 {
1220 v10 = v1->vPosition.z;
1221 v11 = stru_721530.normal.z
1222 + ((unsigned __int64)(stru_721530.field_58.z * (signed __int64)v9) >> 16);
1223 if ( v11 >= v10 )
1224 {
1225 if ( v11 <= v18 + v10 )
1226 {
1227 v12 = v9 - sub_452A9E(v8 * v8 - v17 * v17);
1228 if ( v12 < 0 )
1229 v12 = 0;
1230 if ( v12 < stru_721530.field_7C )
1231 {
1232 stru_721530.field_7C = v12;
1233 v13 = 8 * v0->pDecorationIDs[i];
1234 LOBYTE(v13) = v13 | 5;
1235 stru_721530.uFaceID = v13;
1236 }
1237 }
1238 }
1239 }
1240 }
1241 }
1242 }
1243 }
1244 }
1245 }
1246 }
1247 }
1248 }
1249 }
1250 }
1251
1252 //----- (0046E26D) --------------------------------------------------------
1253 void __fastcall _46E26D_collide_against_sprites(signed int a1, signed int a2)
1254 {
1255 int v2; // edx@5
1256 unsigned __int16 *v3; // eax@5
1257 unsigned __int16 v4; // ax@6
1258 LevelDecoration *v5; // edi@7
1259 DecorationDesc *v6; // esi@8
1260 int v7; // edx@9
1261 int v8; // eax@9
1262 int v9; // ecx@11
1263 int v10; // ebx@13
1264 int v11; // esi@13
1265 int v12; // ebp@15
1266 int v13; // ebx@15
1267 int v14; // esi@16
1268 int v15; // edi@17
1269 int v16; // eax@17
1270 int v17; // esi@19
1271 char v18; // zf@23
1272 int v19; // [sp+0h] [bp-10h]@15
1273 unsigned __int16 *v20; // [sp+4h] [bp-Ch]@5
1274 int v21; // [sp+8h] [bp-8h]@15
1275 int v22; // [sp+Ch] [bp-4h]@13
1276
1277 if ( a1 >= 0 )
1278 {
1279 if ( a1 <= 127 )
1280 {
1281 if ( a2 >= 0 )
1282 {
1283 if ( a2 <= 127 )
1284 {
1285 v2 = a1 + (a2 << 7);
1286 v3 = &pOutdoor->pFaceIDLIST[pOutdoor->pOMAP[v2]];
1287 v20 = &pOutdoor->pFaceIDLIST[pOutdoor->pOMAP[v2]];
1288 if ( v3 )
1289 {
1290 do
1291 {
1292 v4 = *v3;
1293 if ( (v4 & 7) == 5 )
1294 {
1295 v5 = &pLevelDecorations[(signed __int16)v4 >> 3];
1296 if ( !(v5->field_2 & 0x20) )
1297 {
1298 v6 = &pDecorationList->pDecorations[v5->uDecorationDescID];
1299 if ( !(v6->uFlags & 1) )
1300 {
1301 v7 = v6->uRadius;
1302 v8 = v5->vPosition.x;
1303 if ( stru_721530.sMaxX <= v8 + v7 )
1304 {
1305 if ( stru_721530.sMinX >= v8 - v7 )
1306 {
1307 v9 = v5->vPosition.y;
1308 if ( stru_721530.sMaxY <= v9 + v7 )
1309 {
1310 if ( stru_721530.sMinY >= v9 - v7 )
1311 {
1312 v10 = v6->uDecorationHeight;
1313 v11 = v5->vPosition.z;
1314 v22 = v10;
1315 if ( stru_721530.sMaxZ <= v11 + v10 )
1316 {
1317 if ( stru_721530.sMinZ >= v11 )
1318 {
1319 v12 = v8 - stru_721530.normal.x;
1320 v19 = v9 - stru_721530.normal.y;
1321 v13 = stru_721530.prolly_normal_d + v7;
1322 v21 = ((v8 - stru_721530.normal.x) * stru_721530.field_58.y
1323 - (v9 - stru_721530.normal.y) * stru_721530.field_58.x) >> 16;
1324 if ( abs(v21) <= stru_721530.prolly_normal_d + v7 )
1325 {
1326 v14 = (v12 * stru_721530.field_58.x + v19 * stru_721530.field_58.y) >> 16;
1327 if ( v14 > 0 )
1328 {
1329 v15 = v5->vPosition.z;
1330 v16 = stru_721530.normal.z
1331 + ((unsigned __int64)(stru_721530.field_58.z * (signed __int64)v14) >> 16);
1332 if ( v16 >= v15 )
1333 {
1334 if ( v16 <= v22 + v15 )
1335 {
1336 v17 = v14 - sub_452A9E(v13 * v13 - v21 * v21);
1337 if ( v17 < 0 )
1338 v17 = 0;
1339 if ( v17 < stru_721530.field_7C )
1340 {
1341 stru_721530.field_7C = v17;
1342 stru_721530.uFaceID = (signed __int16)*v20;
1343 }
1344 }
1345 }
1346 }
1347 }
1348 }
1349 }
1350 }
1351 }
1352 }
1353 }
1354 }
1355 }
1356 }
1357 v3 = v20 + 1;
1358 v18 = *v20 == 0;
1359 ++v20;
1360 }
1361 while ( !v18 );
1362 }
1363 }
1364 }
1365 }
1366 }
1367 }
1368
1369 //----- (00486F92) --------------------------------------------------------
1370 void __cdecl sr_sub_486F92_MessWithEdgesAndSpans()
1371 {
1372 Span *v0; // ebx@1
1373 int v1; // eax@2
1374 Edge *v2; // ecx@3
1375 Edge *v3; // edx@3
1376 Edge *v4; // esi@6
1377 Edge *v5; // eax@7
1378 Edge *v6; // ecx@8
1379 Surf *v7; // esi@11
1380 double v8; // st7@13
1381 Surf *v9; // edi@13
1382 double v10; // st6@13
1383 double v11; // st7@14
1384 signed __int64 v12; // qax@14
1385 stru148 *v13; // eax@15
1386 Span *v14; // ecx@17
1387 double v15; // st7@28
1388 signed __int64 v16; // qax@28
1389 stru148 *v17; // eax@29
1390 Span *v18; // ecx@31
1391 Edge *i; // eax@40
1392 Edge *v20; // ecx@43
1393 Edge *v21; // esi@44
1394 double v22; // st7@45
1395 Edge *v23; // edx@48
1396 unsigned int v24; // [sp+10h] [bp-10h]@2
1397 float v25; // [sp+14h] [bp-Ch]@3
1398 Edge *v26; // [sp+18h] [bp-8h]@8
1399 unsigned int v27; // [sp+1Ch] [bp-4h]@1
1400
1401 v0 = pSpans;
1402 stru_80C9D8.pSurf = &stru_80C980;
1403 stru_80C9D8.field_0 = (double)(signed int)pViewport->uViewportX;
1404 stru_80C9A4.pSurf = &stru_80C980;
1405 stru_80C980.pPrev = &stru_80C980;
1406 stru_80C980.pNext = &stru_80C980;
1407 stru_80C9A4.field_0 = (double)(signed int)pViewport->uViewportZ;
1408 stru_80C980.field_8 = 0.0;
1409 stru_80C980.field_4 = 0.0;
1410 stru_80C9D8.pNext = &stru_80C9A4;
1411 stru_80C9D8.pPrev = 0;
1412 stru_80C9D8.field_8 = 1;
1413 stru_80C9A4.pNext = 0;
1414 stru_80C9A4.pPrev = &stru_80C9D8;
1415 stru_80C9A4.field_8 = 0;
1416 LODWORD(stru_80C980.field_0) = 0xC97423F0u;
1417 v27 = pViewport->uViewportY;
1418 if ( (signed int)pViewport->uViewportY > (signed int)pViewport->uViewportW )
1419 {
1420 LABEL_51:
1421 v0->field_8 = -1;
1422 }
1423 else
1424 {
1425 v1 = 52 * pViewport->uViewportY;
1426 v24 = 52 * pViewport->uViewportY;
1427 while ( 1 )
1428 {
1429 v2 = *(Edge **)((char *)&pNewEdges->pNext + v1);
1430 v3 = &stru_80C9D8;
1431 v25 = (double)(signed int)v27;
1432 if ( v2 != &defaultEdge )
1433 {
1434 do
1435 {
1436 while ( 1 )
1437 {
1438 v4 = v3->pNext;
1439 if ( v2->field_0 <= (double)v4->field_0 )
1440 break;
1441 v3 = v3->pNext;
1442 }
1443 v5 = v2->pNext;
1444 v2->pNext = v4;
1445 v2->pPrev = v3;
1446 v3->pNext->pPrev = v2;
1447 v3->pNext = v2;
1448 v3 = v2;
1449 v2 = v5;
1450 }
1451 while ( v5 != &defaultEdge );
1452 }
1453 v6 = stru_80C9D8.pNext;
1454 stru_80C980.field_20 = 0;
1455 stru_80C980.field_22 = 1;
1456 v26 = stru_80C9D8.pNext;
1457 if ( stru_80C9D8.pNext )
1458 {
1459 while ( 1 )
1460 {
1461 v7 = v6->pSurf;
1462 if ( v6->field_8 )
1463 {
1464 ++v7->field_22;
1465 if ( v7->field_22 == 1 )
1466 {
1467 v8 = v6->field_0 + 2.0;
1468 v9 = stru_80C980.pNext;
1469 v10 = (v8 - v7->field_C) * v7->field_4 + (v25 - v7->field_10) * v7->field_8 + v7->field_0;
1470 if ( v10 <= (v8 - stru_80C980.pNext->field_C) * stru_80C980.pNext->field_4
1471 + (v25 - stru_80C980.pNext->field_10) * stru_80C980.pNext->field_8
1472 + stru_80C980.pNext->field_0 )
1473 {
1474 do
1475 v9 = v9->pNext;
1476 while ( v10 <= (v8 - v9->field_C) * v9->field_4 + (v25 - v9->field_10) * v9->field_8 + v9->field_0 );
1477 v7->pNext = v9;
1478 v7->pPrev = v9->pPrev;
1479 v9->pPrev->pNext = v7;
1480 v9->pPrev = v7;
1481 }
1482 else
1483 {
1484 v11 = v6->field_0 + 0.5;
1485 v12 = (signed __int64)(v11 - (double)stru_80C980.pNext->field_20);
1486 v0->field_C = v12;
1487 if ( (signed __int16)v12 > 0 )
1488 {
1489 v0->field_A = v27;
1490 v0->field_8 = v9->field_20;
1491 v13 = v9->pParent;
1492 v0->pParent = v13;
1493 if ( v13 )
1494 {
1495 if ( v13->prolly_head )
1496 {
1497 v14 = v13->prolly_tail;
1498 if ( !v14 )
1499 return;
1500 v14->pNext = v0;
1501 }
1502 else
1503 {
1504 v13->prolly_head = v0;
1505 }
1506 v13->prolly_tail = v0;
1507 }
1508 if ( (signed int)pOutdoorCamera->uNumSpans >= 12499 )
1509 return;
1510 ++v0;
1511 ++pOutdoorCamera->uNumSpans;
1512 }
1513 v6 = v26;
1514 v7->field_20 = (signed __int64)v11;
1515 v7->pNext = v9;
1516 v9->pPrev = v7;
1517 stru_80C980.pNext = v7;
1518 v7->pPrev = &stru_80C980;
1519 }
1520 }
1521 }
1522 else
1523 {
1524 --v7->field_22;
1525 if ( !v7->field_22 )
1526 {
1527 if ( stru_80C980.pNext == v7 )
1528 {
1529 v15 = v6->field_0 + 0.5;
1530 v16 = (signed __int64)(v15 - (double)v7->field_20);
1531 v0->field_C = v16;
1532 if ( (signed __int16)v16 > 0 )
1533 {
1534 v0->field_A = v27;
1535 v0->field_8 = v7->field_20;
1536 v17 = v7->pParent;
1537 v0->pParent = v17;
1538 if ( v17 )
1539 {
1540 if ( v17->prolly_head )
1541 {
1542 v18 = v17->prolly_tail;
1543 if ( !v18 )
1544 return;
1545 v18->pNext = v0;
1546 }
1547 else
1548 {
1549 v17->prolly_head = v0;
1550 }
1551 v17->prolly_tail = v0;
1552 }
1553 if ( (signed int)pOutdoorCamera->uNumSpans >= 12499 )
1554 return;
1555 ++v0;
1556 ++pOutdoorCamera->uNumSpans;
1557 }
1558 v7->pNext->field_20 = (signed __int64)v15;
1559 v6 = v26;
1560 }
1561 v7->pNext->pPrev = v7->pPrev;
1562 v7->pPrev->pNext = v7->pNext;
1563 }
1564 }
1565 v26 = v6->pNext;
1566 if ( !v26 )
1567 break;
1568 v6 = v6->pNext;
1569 }
1570 }
1571 for ( i = ptr_80CA10[v27]; i; i = i->ptr_18 )
1572 {
1573 i->pPrev->pNext = i->pNext;
1574 i->pNext->pPrev = i->pPrev;
1575 }
1576 v20 = stru_80C9D8.pNext;
1577 if ( stru_80C9D8.pNext != &stru_80C9A4 )
1578 break;
1579 LABEL_50:
1580 ++v27;
1581 v1 = v24 + 52;
1582 v24 += 52;
1583 if ( (signed int)v27 > (signed int)pViewport->uViewportW )
1584 goto LABEL_51;
1585 }
1586 while ( 1 )
1587 {
1588 v21 = v20->pNext;
1589 if ( !v21 )
1590 break;
1591 v22 = v20->field_4 + v20->field_0;
1592 v20->field_0 = v22;
1593 if ( v22 < stru_80C9D8.field_0 )
1594 v20->field_0 = stru_80C9D8.field_0 + 0.0000001;
1595 while ( 1 )
1596 {
1597 v23 = v20->pPrev;
1598 if ( v20->field_0 >= (double)v23->field_0 )
1599 break;
1600 v23->pNext = v20->pNext;
1601 v20->pNext->pPrev = v23;
1602 v23->pPrev->pNext = v20;
1603 v20->pPrev = v23->pPrev;
1604 v20->pNext = v23;
1605 v23->pPrev = v20;
1606 }
1607 v20 = v21;
1608 if ( v21 == &stru_80C9A4 )
1609 goto LABEL_50;
1610 }
1611 }
1612 }
1613 // 4EC3EC: using guessed type Edge defaultEdge;
1614
1615
1616
1617 //----- (00487355) --------------------------------------------------------
1618 bool OutdoorCamera::_487355()
1619 {
1620 int v0; // esi@1
1621 stru148 *v1; // edi@2
1622 bool result; // eax@3
1623
1624 v0 = 0;
1625 if ( pOutdoorCamera->numStru148s > 0 )
1626 {
1627 v1 = array_77EC08;
1628 do
1629 {
1630 result = pGame->pLightmapBuilder->_45D3C7(v1);
1631 ++v0;
1632 ++v1;
1633 }
1634 while ( v0 < pOutdoorCamera->numStru148s );
1635 }
1636 return result;
1637 }
1638
1639
1640
1641 //----- (00487DA9) --------------------------------------------------------
1642 void __cdecl sub_487DA9()
1643 {
1644 char *v0; // eax@1
1645
1646 v0 = &array_77EC08[0].field_108;
1647 do
1648 {
1649 *v0 = 0;
1650 v0 += 268;
1651 }
1652 while ( (signed int)v0 < (signed int)&pVerticesSR_801A10[4] );
1653 }
1654
1655 //----- (00487DBE) --------------------------------------------------------
1656 void Software_ResetNewEdges()
1657 {
1658 int v0; // ecx@1
1659 Edge **v1; // eax@1
1660 signed int v2; // eax@3
1661
1662 v0 = 0;
1663 v1 = ptr_80CA10;
1664 do
1665 {
1666 ++v0;
1667 *((int *)&pNewEdges[v0] - 9) = (int)&defaultEdge;
1668 *v1 = 0;
1669 ++v1;
1670 }
1671 while ( (signed int)v1 < (signed int)&unk_80D190 );
1672 v2 = 2000;
1673 do
1674 {
1675 pSurfs->field_22 = 0;
1676 --v2;
1677 }
1678 while ( v2 );
1679 }
1680 // 4EC3EC: using guessed type Edge defaultEdge;
1681
1682
1683
1684
1685 //----- (00487E1D) --------------------------------------------------------
1686 TileTable::~TileTable()
1687 {
1688 if ( this->pTiles )
1689 {
1690 pAllocator->FreeChunk(this->pTiles);
1691 pTiles = nullptr;
1692 }
1693 uNumTiles = 0;
1694 }
1695
1696 //----- (00487E3B) --------------------------------------------------------
1697 TileDesc *TileTable::GetTileById(unsigned int uTileID)
1698 {
1699 TileDesc *result; // eax@3
1700
1701 if ( (uTileID & 0x80000000u) != 0 || (signed int)uTileID > (signed int)(this->uNumTiles - 1) )
1702 result = this->pTiles;
1703 else
1704 result = &this->pTiles[uTileID];
1705 return result;
1706 }
1707
1708 //----- (00487E58) --------------------------------------------------------
1709 void TileTable::InitializeTileset(int uTerrainType)
1710 {
1711 TileTable *v2; // edi@1
1712 int v3; // ebx@1
1713 TileDesc *v4; // eax@2
1714 signed int i; // [sp+8h] [bp-4h]@1
1715
1716 v2 = this;
1717 v3 = 0;
1718 for ( i = 0; i < (signed int)v2->uNumTiles; ++v3 )
1719 {
1720 v4 = &v2->pTiles[v3];
1721 if ( uTerrainType == v4->uTerrainType && v4->pTileName[0] )
1722 {
1723 v2->pTiles[v3].uBitmapID = pBitmaps_LOD->LoadTexture(v4->pTileName);
1724 if ( v2->pTiles[v3].uBitmapID != -1 )
1725 HIWORD(pBitmaps_LOD->pTextures[v2->pTiles[v3].uBitmapID].palette) = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v2->pTiles[v3].uBitmapID].palette);
1726 }
1727 ++i;
1728 }
1729 }
1730
1731 //----- (00487ED6) --------------------------------------------------------
1732 int TileTable::method_487ED6(signed int a1, int a2)
1733 {
1734 int v3; // esi@1
1735 TileTable *v4; // edi@1
1736 int v5; // edx@3
1737 int v6; // edx@11
1738 unsigned int v8; // [sp-4h] [bp-10h]@4
1739
1740 v3 = 0;
1741 v4 = this;
1742 if ( a1 > 8 )
1743 {
1744 v8 = 0;
1745 return v4->GetTileId(a1, v8);
1746 }
1747 if ( a2 || (v5 = rand() % 50, v5 < 20) )
1748 {
1749 v8 = 0;
1750 return v4->GetTileId(a1, v8);
1751 }
1752 if ( v5 < 30 )
1753 {
1754 v8 = 1;
1755 return v4->GetTileId(a1, v8);
1756 }
1757 if ( v5 < 40 )
1758 {
1759 v8 = 2;
1760 return v4->GetTileId(a1, v8);
1761 }
1762 if ( v5 < 48 )
1763 {
1764 v8 = 3;
1765 return v4->GetTileId(a1, v8);
1766 }
1767 v6 = rand() % 8;
1768 if ( !v6 )
1769 {
1770 v8 = 4;
1771 return v4->GetTileId(a1, v8);
1772 }
1773 if ( v6 == 1 )
1774 {
1775 v8 = 5;
1776 return v4->GetTileId(a1, v8);
1777 }
1778 if ( v6 == 2 )
1779 {
1780 v8 = 6;
1781 return v4->GetTileId(a1, v8);
1782 }
1783 if ( v6 == 3 )
1784 {
1785 v8 = 7;
1786 return v4->GetTileId(a1, v8);
1787 }
1788 if ( v6 == 4 )
1789 {
1790 v8 = 8;
1791 return v4->GetTileId(a1, v8);
1792 }
1793 if ( v6 == 5 )
1794 {
1795 v8 = 9;
1796 return v4->GetTileId(a1, v8);
1797 }
1798 if ( v6 == 6 )
1799 {
1800 v8 = 10;
1801 return v4->GetTileId(a1, v8);
1802 }
1803 if ( v6 == 7 )
1804 {
1805 v8 = 11;
1806 return v4->GetTileId(a1, v8);
1807 }
1808 return v3;
1809 }
1810
1811 //----- (00487F84) --------------------------------------------------------
1812 unsigned int TileTable::GetTileId(unsigned int uTerrainType, unsigned int uSection)
1813 {
1814 unsigned int v3; // edx@1
1815 unsigned int result; // eax@1
1816 unsigned __int16 *v5; // ecx@2
1817
1818 v3 = this->uNumTiles;
1819 result = 0;
1820 if ( (signed int)this->uNumTiles <= 0 )
1821 {
1822 LABEL_6:
1823 result = 0;
1824 }
1825 else
1826 {
1827 v5 = &this->pTiles->uSection;
1828 while ( (signed __int16)*(v5 - 1) != uTerrainType || (signed __int16)*v5 != uSection )
1829 {
1830 ++result;
1831 v5 += 13;
1832 if ( (signed int)result >= (signed int)v3 )
1833 goto LABEL_6;
1834 }
1835 }
1836 return result;
1837 }
1838
1839 //----- (00487FB4) --------------------------------------------------------
1840 void TileTable::ToFile()
1841 {
1842 TileTable *v1; // esi@1
1843 FILE *v2; // eax@1
1844 FILE *v3; // edi@1
1845
1846 auto Str = this;
1847
1848 v1 = Str;
1849 v2 = fopen("data\\dtile.bin", "wb");
1850 v3 = v2;
1851 if ( !v2 )
1852 Abortf("Unable to save dtile.bin!");
1853 fwrite(v1, 4u, 1u, v2);
1854 fwrite(v1->pTiles, 0x1Au, v1->uNumTiles, v3);
1855 fclose(v3);
1856 }
1857
1858 //----- (00488000) --------------------------------------------------------
1859 void TileTable::FromFile(void *pSerialized)
1860 {
1861 uNumTiles = *(int *)pSerialized;
1862 pTiles = (TileDesc *)pAllocator->AllocNamedChunk(pTiles, 26 * uNumTiles, "Tile Descrip");
1863 memcpy(pTiles, (char *)pSerialized + 4, 26 * uNumTiles);
1864 }
1865
1866 //----- (00488047) --------------------------------------------------------
1867 int TileTable::FromFileTxt(const char *pFilename)
1868 {
1869 TileTable *v2; // ebp@1
1870 FILE *v3; // eax@1
1871 unsigned int v4; // ebx@3
1872 void *v5; // eax@9
1873 unsigned __int16 v6; // ax@14
1874 const char *v7; // ST14_4@14
1875 unsigned __int16 v8; // ax@14
1876 const char *v9; // esi@14
1877 int v10; // eax@17
1878 int v11; // eax@20
1879 int v12; // eax@22
1880 int v13; // eax@24
1881 int v14; // eax@26
1882 int v15; // eax@28
1883 int v16; // eax@30
1884 int v17; // eax@32
1885 int v18; // eax@34
1886 int v19; // eax@36
1887 int v20; // eax@38
1888 int v21; // eax@40
1889 int v22; // eax@42
1890 int v23; // eax@44
1891 int v24; // eax@46
1892 int v25; // eax@48
1893 int v26; // eax@50
1894 int v27; // eax@52
1895 int v28; // eax@54
1896 int v29; // eax@56
1897 int v30; // eax@58
1898 int v31; // eax@60
1899 int v32; // eax@62
1900 int v33; // eax@64
1901 int v34; // eax@66
1902 const char *v35; // esi@67
1903 int v36; // eax@70
1904 int v37; // eax@73
1905 int v38; // eax@75
1906 int v39; // eax@77
1907 int v40; // eax@79
1908 int v41; // eax@81
1909 int v42; // eax@83
1910 int v43; // eax@85
1911 int v44; // eax@87
1912 int v45; // eax@89
1913 int v46; // eax@91
1914 int v47; // eax@93
1915 int v48; // eax@108
1916 int v49; // eax@110
1917 int v50; // eax@112
1918 int v51; // eax@114
1919 int v52; // eax@116
1920 int v53; // eax@118
1921 int v54; // eax@120
1922 int v55; // eax@122
1923 int v56; // eax@124
1924 int v57; // eax@126
1925 int v58; // eax@128
1926 int v59; // eax@130
1927 int v60; // eax@132
1928 int v61; // eax@134
1929 int v62; // eax@136
1930 int v63; // eax@138
1931 int v64; // eax@140
1932 int v65; // eax@142
1933 int v66; // eax@144
1934 int v67; // eax@146
1935 int v68; // eax@148
1936 int v69; // eax@150
1937 int v70; // eax@151
1938 int j; // edi@152
1939 const char *v72; // esi@153
1940 int v73; // eax@154
1941 int v74; // eax@156
1942 int v75; // eax@160
1943 int v76; // eax@162
1944 int v77; // eax@164
1945 int v78; // eax@166
1946 int v79; // eax@168
1947 int v80; // eax@170
1948 FILE *i; // [sp-10h] [bp-304h]@3
1949 FILE *File; // [sp+4h] [bp-2F0h]@1
1950 FrameTableTxtLine v84; // [sp+8h] [bp-2ECh]@4
1951 FrameTableTxtLine v85; // [sp+84h] [bp-270h]@4
1952 char Buf; // [sp+100h] [bp-1F4h]@4
1953
1954 v2 = this;
1955 v3 = fopen(pFilename, "r");
1956 File = v3;
1957 if ( !v3 )
1958 Abortf("TileTable::load - Unable to open file: %s.");
1959 v4 = 0;
1960 for ( i = v3; fgets(&Buf, 490, i); i = File )
1961 {
1962 *strchr(&Buf, 10) = 0;
1963 memcpy(&v84, texture_frame_table_txt_parser(&Buf, &v85), sizeof(v84));
1964 if ( v84.field_0 && *v84.pProperties[0] != 47 )
1965 ++v4;
1966 }
1967 v2->uNumTiles = v4;
1968 v5 = pAllocator->AllocNamedChunk(v2->pTiles, 26 * v4, "Tile Descrip");
1969 v2->pTiles = (TileDesc *)v5;
1970 if ( !v5 )
1971 Abortf("TileTable::Load - Out of Memory!");
1972 memset(v5, 0, 26 * v2->uNumTiles);
1973 v2->uNumTiles = 0;
1974 fseek(File, 0, 0);
1975 if ( fgets(&Buf, 490, File) )
1976 {
1977 while ( 1 )
1978 {
1979 *strchr(&Buf, 10) = 0;
1980 memcpy(&v84, texture_frame_table_txt_parser(&Buf, &v85), sizeof(v84));
1981 if ( v84.field_0 )
1982 {
1983 if ( *v84.pProperties[0] != 47 )
1984 break;
1985 }
1986 LABEL_173:
1987 if ( !fgets(&Buf, 490, File) )
1988 goto LABEL_174;
1989 }
1990 strcpy(v2->pTiles[v2->uNumTiles].pTileName, v84.pProperties[0]);
1991 v6 = atoi(v84.pProperties[1]);
1992 v7 = v84.pProperties[2];
1993 v2->pTiles[v2->uNumTiles].uTileID = v6;
1994 v8 = atoi(v7);
1995 v9 = v84.pProperties[3];
1996 v2->pTiles[v2->uNumTiles].uBitmapID = v8;
1997 v2->pTiles[v2->uNumTiles].uTerrainType = 0;
1998 if ( _strcmpi(v9, "TTtype_NULL") )
1999 {
2000 if ( _strcmpi(v9, "TTtype_Start") )
2001 {
2002 if ( _strcmpi(v9, "TTtype_Grass") )
2003 {
2004 if ( _strcmpi(v9, "TTtype_Cracked") )
2005 {
2006 if ( _strcmpi(v9, "TTtype_Snow") )
2007 {
2008 if ( _strcmpi(v9, "TTtype_Sand") )
2009 {
2010 if ( _strcmpi(v9, "TTtype_Volcano") )
2011 {
2012 if ( _strcmpi(v9, "TTtype_Dirt") )
2013 {
2014 if ( _strcmpi(v9, "TTtype_Water") )
2015 {
2016 if ( _strcmpi(v9, "TTtype_Tropical") )
2017 {
2018 if ( _strcmpi(v9, "TTtype_Swamp") )
2019 {
2020 if ( _strcmpi(v9, "TTtype_City") )
2021 {
2022 if ( _strcmpi(v9, "TTtype_RoadGrassCobble") )
2023 {
2024 if ( _strcmpi(v9, "TTtype_RoadGrassDirt") )
2025 {
2026 if ( _strcmpi(v9, "TTtype_RoadCrackedCobble") )
2027 {
2028 if ( _strcmpi(v9, "TTtype_RoadCrackedDirt") )
2029 {
2030 if ( _strcmpi(v9, "TTtype_RoadSandCobble") )
2031 {
2032 if ( _strcmpi(v9, "TTtype_RoadSandDirt") )
2033 {
2034 if ( _strcmpi(v9, "TTtype_RoadVolcanoCobble") )
2035 {
2036 if ( _strcmpi(v9, "TTtype_RoadVolcanoDirt") )
2037 {
2038 if ( _strcmpi(v9, "TTtype_RoadSwampCobble") )
2039 {
2040 if ( _strcmpi(v9, "TTtype_RoadSwampDirt") )
2041 {
2042 if ( _strcmpi(v9, "TTtype_RoadTropicalCobble") )
2043 {
2044 if ( _strcmpi(v9, "TTtype_RoadTropicalDirt") )
2045 {
2046 if ( _strcmpi(v9, "TTtype_RoadSnowCobble") )
2047 {
2048 if ( _strcmpi(v9, "TTtype_RoadSnowDirt") )
2049 {
2050 if ( !_strcmpi(v9, "TTtype_RoadCityStone") )
2051 {
2052 v34 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2053 *(char *)v34 |= 0x1Cu;
2054 }
2055 }
2056 else
2057 {
2058 v33 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2059 *(char *)v33 |= 0xDu;
2060 }
2061 }
2062 else
2063 {
2064 v32 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2065 *(char *)v32 |= 0xCu;
2066 }
2067 }
2068 else
2069 {
2070 v31 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2071 *(char *)v31 |= 0x1Bu;
2072 }
2073 }
2074 else
2075 {
2076 v30 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2077 *(char *)v30 |= 0x1Au;
2078 }
2079 }
2080 else
2081 {
2082 v29 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2083 *(char *)v29 |= 0x19u;
2084 }
2085 }
2086 else
2087 {
2088 v28 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2089 *(char *)v28 |= 0x18u;
2090 }
2091 }
2092 else
2093 {
2094 v27 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2095 *(char *)v27 |= 0x11u;
2096 }
2097 }
2098 else
2099 {
2100 v26 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2101 *(char *)v26 |= 0x10u;
2102 }
2103 }
2104 else
2105 {
2106 v25 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2107 *(char *)v25 |= 0xFu;
2108 }
2109 }
2110 else
2111 {
2112 v24 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2113 *(char *)v24 |= 0xEu;
2114 }
2115 }
2116 else
2117 {
2118 v23 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2119 *(char *)v23 |= 0x17u;
2120 }
2121 }
2122 else
2123 {
2124 v22 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2125 *(char *)v22 |= 0x16u;
2126 }
2127 }
2128 else
2129 {
2130 v21 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2131 *(char *)v21 |= 0xBu;
2132 }
2133 }
2134 else
2135 {
2136 v20 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2137 *(char *)v20 |= 0xAu;
2138 }
2139 }
2140 else
2141 {
2142 v19 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2143 *(char *)v19 |= 9u;
2144 }
2145 }
2146 else
2147 {
2148 v18 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2149 *(char *)v18 |= 7u;
2150 }
2151 }
2152 else
2153 {
2154 v17 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2155 *(char *)v17 |= 8u;
2156 }
2157 }
2158 else
2159 {
2160 v16 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2161 *(char *)v16 |= 5u;
2162 }
2163 }
2164 else
2165 {
2166 v15 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2167 *(char *)v15 |= 4u;
2168 }
2169 }
2170 else
2171 {
2172 v14 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2173 *(char *)v14 |= 3u;
2174 }
2175 }
2176 else
2177 {
2178 v13 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2179 *(char *)v13 |= 2u;
2180 }
2181 }
2182 else
2183 {
2184 v12 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2185 *(char *)v12 |= 1u;
2186 }
2187 }
2188 else
2189 {
2190 v11 = (int)&v2->pTiles[v2->uNumTiles].uTerrainType;
2191 *(char *)v11 |= 6u;
2192 }
2193 }
2194 }
2195 else
2196 {
2197 v10 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2198 *(char *)v10 |= 0xFEu;
2199 }
2200 }
2201 else
2202 {
2203 LOBYTE(v2->pTiles[v2->uNumTiles].uTerrainType) = -1;
2204 }
2205 v35 = v84.pProperties[4];
2206 v2->pTiles[v2->uNumTiles].uSection = 0;
2207 v2->pTiles[v2->uNumTiles].uAttributes = 0;
2208 if ( !_strcmpi(v35, "TTsect_NULL") )
2209 {
2210 LOBYTE(v2->pTiles[v2->uNumTiles].uSection) = -1;
2211 LABEL_152:
2212 for ( j = 5; j < v84.field_0; ++j )
2213 {
2214 v72 = v84.pProperties[j];
2215 if ( _strcmpi(v84.pProperties[j], "TTattr_Burn") )
2216 {
2217 if ( _strcmpi(v72, "TTattr_Water") )
2218 {
2219 if ( _strcmpi(v72, "TTattr_Water2") )
2220 {
2221 if ( _strcmpi(v72, "TTattr_Block") )
2222 {
2223 if ( _strcmpi(v72, "TTattr_Repulse") )
2224 {
2225 if ( _strcmpi(v72, "TTattr_Flat") )
2226 {
2227 if ( _strcmpi(v72, "TTattr_Wave") )
2228 {
2229 if ( _strcmpi(v72, "TTattr_NoDraw") )
2230 {
2231 if ( !_strcmpi(v72, "TTattr_Transition") )
2232 {
2233 v80 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
2234 *(short *)v80 |= 0x200u;
2235 }
2236 }
2237 else
2238 {
2239 v79 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
2240 *(char *)v79 |= 0x40u;
2241 }
2242 }
2243 else
2244 {
2245 v78 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
2246 *(char *)v78 |= 0x20u;
2247 }
2248 }
2249 else
2250 {
2251 v77 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
2252 *(char *)v77 |= 0x10u;
2253 }
2254 }
2255 else
2256 {
2257 v76 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
2258 *(char *)v76 |= 8u;
2259 }
2260 }
2261 else
2262 {
2263 v75 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
2264 *(char *)v75 |= 4u;
2265 }
2266 }
2267 else
2268 {
2269 HIBYTE(v2->pTiles[v2->uNumTiles].uAttributes) |= 1u;
2270 }
2271 }
2272 else
2273 {
2274 v74 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
2275 *(char *)v74 |= 2u;
2276 }
2277 }
2278 else
2279 {
2280 v73 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
2281 *(char *)v73 |= 1u;
2282 }
2283 }
2284 ++v2->uNumTiles;
2285 goto LABEL_173;
2286 }
2287 if ( !_strcmpi(v35, "TTsect_Start") )
2288 {
2289 v36 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2290 *(char *)v36 |= 0xFEu;
2291 goto LABEL_152;
2292 }
2293 if ( !_strcmpi(v35, "TTsect_Base1") )
2294 goto LABEL_152;
2295 if ( !_strcmpi(v35, "TTsect_Base2") )
2296 {
2297 v37 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2298 *(char *)v37 |= 1u;
2299 goto LABEL_152;
2300 }
2301 if ( !_strcmpi(v35, "TTsect_Base3") )
2302 {
2303 v38 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2304 *(char *)v38 |= 2u;
2305 goto LABEL_152;
2306 }
2307 if ( !_strcmpi(v35, "TTsect_Base4") )
2308 {
2309 v39 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2310 *(char *)v39 |= 3u;
2311 goto LABEL_152;
2312 }
2313 if ( !_strcmpi(v35, "TTsect_Special1") )
2314 {
2315 v40 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2316 *(char *)v40 |= 4u;
2317 goto LABEL_152;
2318 }
2319 if ( !_strcmpi(v35, "TTsect_Special2") )
2320 {
2321 v41 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2322 *(char *)v41 |= 5u;
2323 goto LABEL_152;
2324 }
2325 if ( !_strcmpi(v35, "TTsect_Special3") )
2326 {
2327 v42 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2328 *(char *)v42 |= 6u;
2329 goto LABEL_152;
2330 }
2331 if ( !_strcmpi(v35, "TTsect_Special4") )
2332 {
2333 v43 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2334 *(char *)v43 |= 7u;
2335 goto LABEL_152;
2336 }
2337 if ( !_strcmpi(v35, "TTsect_Special5") )
2338 {
2339 v44 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2340 *(char *)v44 |= 8u;
2341 goto LABEL_152;
2342 }
2343 if ( !_strcmpi(v35, "TTsect_Special6") )
2344 {
2345 v45 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2346 *(char *)v45 |= 9u;
2347 goto LABEL_152;
2348 }
2349 if ( !_strcmpi(v35, "TTsect_Special7") )
2350 {
2351 v46 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2352 *(char *)v46 |= 0xAu;
2353 goto LABEL_152;
2354 }
2355 if ( !_strcmpi(v35, "TTsect_Special8") )
2356 {
2357 v47 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2358 *(char *)v47 |= 0xBu;
2359 goto LABEL_152;
2360 }
2361 if ( !_strcmpi(v35, "TTsect_NE1") )
2362 goto LABEL_130;
2363 if ( !_strcmpi(v35, "TTsect_NW1") )
2364 goto LABEL_134;
2365 if ( !_strcmpi(v35, "TTsect_SE1") )
2366 goto LABEL_130;
2367 if ( !_strcmpi(v35, "TTsect_SW1") )
2368 goto LABEL_134;
2369 if ( !_strcmpi(v35, "TTsect_E1") )
2370 goto LABEL_138;
2371 if ( !_strcmpi(v35, "TTsect_W1") )
2372 goto LABEL_140;
2373 if ( !_strcmpi(v35, "TTsect_N1") )
2374 goto LABEL_142;
2375 if ( !_strcmpi(v35, "TTsect_S1") )
2376 goto LABEL_144;
2377 if ( !_strcmpi(v35, "TTsect_XNE1") )
2378 goto LABEL_146;
2379 if ( _strcmpi(v35, "TTsect_XNW1") )
2380 {
2381 if ( !_strcmpi(v35, "TTsect_XSE1") )
2382 goto LABEL_146;
2383 if ( _strcmpi(v35, "TTsect_XSW1") )
2384 {
2385 if ( !_strcmpi(v35, "TTsect_CROS") )
2386 {
2387 LABEL_151:
2388 v70 = (int)&v2->pTiles[v2->uNumTiles].uAttributes;
2389 *(short *)v70 |= 0x200u;
2390 goto LABEL_152;
2391 }
2392 if ( !_strcmpi(v35, "TTsect_NS") )
2393 {
2394 v48 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2395 *(char *)v48 |= 1u;
2396 goto LABEL_151;
2397 }
2398 if ( !_strcmpi(v35, "TTsect_EW") )
2399 {
2400 v49 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2401 *(char *)v49 |= 2u;
2402 goto LABEL_151;
2403 }
2404 if ( !_strcmpi(v35, "TTsect_N_E") )
2405 {
2406 v50 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2407 *(char *)v50 |= 3u;
2408 goto LABEL_151;
2409 }
2410 if ( !_strcmpi(v35, "TTsect_N_W") )
2411 {
2412 v51 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2413 *(char *)v51 |= 4u;
2414 goto LABEL_151;
2415 }
2416 if ( !_strcmpi(v35, "TTsect_S_E") )
2417 {
2418 v52 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2419 *(char *)v52 |= 5u;
2420 goto LABEL_151;
2421 }
2422 if ( !_strcmpi(v35, "TTsect_S_W") )
2423 {
2424 v53 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2425 *(char *)v53 |= 6u;
2426 goto LABEL_151;
2427 }
2428 if ( !_strcmpi(v35, "TTsect_NS_E") )
2429 {
2430 v54 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2431 *(char *)v54 |= 7u;
2432 goto LABEL_151;
2433 }
2434 if ( !_strcmpi(v35, "TTsect_NS_W") )
2435 {
2436 v55 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2437 *(char *)v55 |= 8u;
2438 goto LABEL_151;
2439 }
2440 if ( !_strcmpi(v35, "TTsect_EW_N") )
2441 {
2442 v56 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2443 *(char *)v56 |= 9u;
2444 goto LABEL_151;
2445 }
2446 if ( !_strcmpi(v35, "TTsect_EW_S") )
2447 {
2448 v57 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2449 *(char *)v57 |= 0xAu;
2450 goto LABEL_151;
2451 }
2452 if ( !_strcmpi(v35, "TTsect_NCAP") )
2453 {
2454 v58 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2455 *(char *)v58 |= 0xBu;
2456 goto LABEL_151;
2457 }
2458 if ( !_strcmpi(v35, "TTsect_ECAP") )
2459 {
2460 LABEL_130:
2461 v59 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2462 *(char *)v59 |= 0xCu;
2463 goto LABEL_151;
2464 }
2465 if ( !_strcmpi(v35, "TTsect_SCAP") )
2466 {
2467 v60 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2468 *(char *)v60 |= 0xDu;
2469 goto LABEL_151;
2470 }
2471 if ( !_strcmpi(v35, "TTsect_WCAP") )
2472 {
2473 LABEL_134:
2474 v61 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2475 *(char *)v61 |= 0xEu;
2476 goto LABEL_151;
2477 }
2478 if ( !_strcmpi(v35, "TTsect_DN") )
2479 {
2480 v62 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2481 *(char *)v62 |= 0xFu;
2482 goto LABEL_151;
2483 }
2484 if ( !_strcmpi(v35, "TTsect_DS") )
2485 {
2486 LABEL_138:
2487 v63 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2488 *(char *)v63 |= 0x10u;
2489 goto LABEL_151;
2490 }
2491 if ( !_strcmpi(v35, "TTsect_DW") )
2492 {
2493 LABEL_140:
2494 v64 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2495 *(char *)v64 |= 0x11u;
2496 goto LABEL_151;
2497 }
2498 if ( !_strcmpi(v35, "TTsect_DE") )
2499 {
2500 LABEL_142:
2501 v65 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2502 *(char *)v65 |= 0x12u;
2503 goto LABEL_151;
2504 }
2505 if ( !_strcmpi(v35, "TTsect_DSW") )
2506 {
2507 LABEL_144:
2508 v66 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2509 *(char *)v66 |= 0x13u;
2510 goto LABEL_151;
2511 }
2512 if ( !_strcmpi(v35, "TTsect_DNE") )
2513 {
2514 LABEL_146:
2515 v67 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2516 *(char *)v67 |= 0x14u;
2517 goto LABEL_151;
2518 }
2519 if ( !_strcmpi(v35, "TTsect_DSE") )
2520 {
2521 v68 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2522 *(char *)v68 |= 0x15u;
2523 goto LABEL_151;
2524 }
2525 if ( _strcmpi(v35, "TTsect_DNW") )
2526 goto LABEL_152;
2527 }
2528 }
2529 v69 = (int)&v2->pTiles[v2->uNumTiles].uSection;
2530 *(char *)v69 |= 0x16u;
2531 goto LABEL_151;
2532 }
2533 LABEL_174:
2534 fclose(File);
2535 return 1;
2536 }
2537
2538
2539
2540 //----- (0048958E) --------------------------------------------------------
2541 stru12_MemoryBlock::stru12_MemoryBlock(int a2)
2542 {
2543 stru12_MemoryBlock *v2; // esi@1
2544 void *v3; // eax@1
2545 void *v4; // ecx@1
2546 stru12_MemoryBlock *result; // eax@1
2547
2548 v2 = this;
2549 v3 = operator new(8 * a2 + 16);
2550 v2->pBlockBase = v3;
2551 v4 = (char *)v3 + (-(signed int)v3 & 7);
2552 result = v2;
2553 v2->pAlignedBlock = v4;
2554 }
2555
2556 //----- (004895B7) --------------------------------------------------------
2557 stru12::stru12(stru11 *pStru11)
2558 {
2559 stru12 *v2; // esi@1
2560
2561 v2 = this;
2562 this->field_44 = 0x41000000u;
2563 this->field_4C = 0x46000000u;
2564 //this->vdestructor_ptr = stru12::_4898E6;
2565 this->field_48 = 0;
2566 this->field_50 = 0;
2567 this->field_54 = 0x33D6BF95u;
2568 this->field_58 = 0;
2569
2570 for (int i = 0; i < 12; ++i)
2571 v2->pMemBlocks[i] = new stru12_MemoryBlock(640);
2572 /*
2573 v3 = (stru12_MemoryBlock *)operator new(8u);
2574 if ( v3 )
2575 v4 = AllocAlignedMem(v3, 640);
2576 else
2577 v4 = 0;
2578 v2->pMemBlocks[0] = v4;
2579 /*v5 = (stru12_MemoryBlock *)operator new(8u);
2580 if ( v5 )
2581 v6 = AllocAlignedMem(v5, 640);
2582 else
2583 v6 = 0;
2584 v2->pMemBlocks[1] = v6;
2585 v7 = (stru12_MemoryBlock *)operator new(8u);
2586 if ( v7 )
2587 v8 = AllocAlignedMem(v7, 640);
2588 else
2589 v8 = 0;
2590 v2->pMemBlocks[2] = v8;
2591 v9 = (stru12_MemoryBlock *)operator new(8u);
2592 if ( v9 )
2593 v10 = AllocAlignedMem(v9, 640);
2594 else
2595 v10 = 0;
2596 v2->pMemBlocks[3] = v10;
2597 v11 = (stru12_MemoryBlock *)operator new(8u);
2598 if ( v11 )
2599 v12 = AllocAlignedMem(v11, 640);
2600 else
2601 v12 = 0;
2602 v2->pMemBlocks[4] = v12;
2603 v13 = (stru12_MemoryBlock *)operator new(8u);
2604 if ( v13 )
2605 v14 = AllocAlignedMem(v13, 640);
2606 else
2607 v14 = 0;
2608 v2->pMemBlocks[5] = v14;
2609 v15 = (stru12_MemoryBlock *)operator new(8u);
2610 if ( v15 )
2611 v16 = AllocAlignedMem(v15, 640);
2612 else
2613 v16 = 0;
2614 v2->pMemBlocks[6] = v16;
2615 v17 = (stru12_MemoryBlock *)operator new(8u);
2616 if ( v17 )
2617 v18 = AllocAlignedMem(v17, 640);
2618 else
2619 v18 = 0;
2620 v2->pMemBlocks[7] = v18;
2621 v19 = (stru12_MemoryBlock *)operator new(8u);
2622 if ( v19 )
2623 v20 = AllocAlignedMem(v19, 640);
2624 else
2625 v20 = 0;
2626 v2->pMemBlocks[8] = v20;
2627 v21 = (stru12_MemoryBlock *)operator new(8u);
2628 if ( v21 )
2629 v22 = AllocAlignedMem(v21, 640);
2630 else
2631 v22 = 0;
2632 v2->pMemBlocks[9] = v22;
2633 v23 = (stru12_MemoryBlock *)operator new(8u);
2634 if ( v23 )
2635 v24 = AllocAlignedMem(v23, 640);
2636 else
2637 v24 = 0;
2638 v2->pMemBlocks[10] = v24;
2639 v25 = (stru12_MemoryBlock *)operator new(8u);
2640 if ( v25 )
2641 v26 = AllocAlignedMem(v25, 640);
2642 else
2643 v26 = 0;
2644 v2->field_8C = 0;
2645 v2->pMemBlocks[11] = v26;*/
2646 }
2647
2648 //----- (00489810) --------------------------------------------------------
2649 stru12::~stru12()
2650 {
2651 for (int i = 0; i < 12; ++i)
2652 delete pMemBlocks[i];
2653 /*if ( v2 )
2654 stru12_MemoryBlock::dtor(v2, 1);
2655 v3 = v1->pMemBlocks[1];
2656 if ( v3 )
2657 stru12_MemoryBlock::dtor(v3, 1);
2658 v4 = v1->pMemBlocks[2];
2659 if ( v4 )
2660 stru12_MemoryBlock::dtor(v4, 1);
2661 v5 = v1->pMemBlocks[3];
2662 if ( v5 )
2663 stru12_MemoryBlock::dtor(v5, 1);
2664 v6 = v1->pMemBlocks[4];
2665 if ( v6 )
2666 stru12_MemoryBlock::dtor(v6, 1);
2667 v7 = v1->pMemBlocks[5];
2668 if ( v7 )
2669 stru12_MemoryBlock::dtor(v7, 1);
2670 v8 = v1->pMemBlocks[6];
2671 if ( v8 )
2672 stru12_MemoryBlock::dtor(v8, 1);
2673 v9 = v1->pMemBlocks[7];
2674 if ( v9 )
2675 stru12_MemoryBlock::dtor(v9, 1);
2676 v10 = v1->pMemBlocks[8];
2677 if ( v10 )
2678 stru12_MemoryBlock::dtor(v10, 1);
2679 v11 = v1->pMemBlocks[9];
2680 if ( v11 )
2681 stru12_MemoryBlock::dtor(v11, 1);
2682 v12 = v1->pMemBlocks[10];
2683 if ( v12 )
2684 stru12_MemoryBlock::dtor(v12, 1);
2685 v13 = v1->pMemBlocks[11];
2686 if ( v13 )
2687 stru12_MemoryBlock::dtor(v13, 1);*/
2688 }
2689
2690 //----- (004898BF) --------------------------------------------------------
2691 stru12_MemoryBlock::~stru12_MemoryBlock()
2692 {
2693 stru12_MemoryBlock *v2; // esi@1
2694 void *v3; // ST00_4@1
2695
2696 v2 = this;
2697 v3 = this->pBlockBase;
2698 this->pAlignedBlock = 0;
2699 free(v3);
2700 v2->pBlockBase = 0;
2701 /*if ( a2 & 1 )
2702 free(v2);*/
2703 }
2704
2705 //----- (004898E6) --------------------------------------------------------
2706 void stru12::_4898E6()
2707 {
2708 void *v1; // eax@1
2709 void *v2; // edx@1
2710 char *v3; // edi@2
2711 double v4; // st7@2
2712 char *v5; // ebx@2
2713 double v6; // st6@3
2714 double v7; // st5@3
2715 double v8; // st4@3
2716 int v9; // esi@3
2717 double v10; // st3@3
2718 float v11; // ST34_4@5
2719 double v12; // st6@10
2720 double v13; // ST0C_8@10
2721 char *v14; // [sp+14h] [bp-44h]@2
2722 char *v15; // [sp+18h] [bp-40h]@2
2723 char *v16; // [sp+1Ch] [bp-3Ch]@2
2724 char *v17; // [sp+20h] [bp-38h]@2
2725 char *v18; // [sp+24h] [bp-34h]@2
2726 float v19; // [sp+30h] [bp-28h]@3
2727 float v20; // [sp+38h] [bp-20h]@3
2728 char *v21; // [sp+3Ch] [bp-1Ch]@2
2729 int v22; // [sp+40h] [bp-18h]@1
2730 char *v23; // [sp+44h] [bp-14h]@2
2731 char *v24; // [sp+48h] [bp-10h]@2
2732 int v25; // [sp+4Ch] [bp-Ch]@2
2733 float v26; // [sp+50h] [bp-8h]@3
2734 float v27; // [sp+54h] [bp-4h]@3
2735
2736 v22 = 0;
2737 v1 = this->pMemBlocks[1]->pAlignedBlock;
2738 v2 = this->pMemBlocks[6]->pAlignedBlock;
2739 if ( this->field_8C > 0 )
2740 {
2741 v24 = (char *)((char *)pMemBlocks[0]->pAlignedBlock - v1);
2742 v23 = (char *)((char *)pMemBlocks[2]->pAlignedBlock - v1);
2743 v18 = (char *)((char *)pMemBlocks[7]->pAlignedBlock - v2);
2744 v17 = (char *)((char *)pMemBlocks[8]->pAlignedBlock - v2);
2745 v25 = (int)v1 - (int)v2;
2746 v16 = (char *)((char *)pMemBlocks[9]->pAlignedBlock - v2);
2747 v3 = (char *)((char *)pMemBlocks[4]->pAlignedBlock - v2);
2748 v15 = (char *)((char *)pMemBlocks[10]->pAlignedBlock - v2);
2749 v4 = 1.0;
2750 v5 = (char *)((char *)pMemBlocks[5]->pAlignedBlock - v2);
2751 v21 = (char *)((char *)pMemBlocks[3]->pAlignedBlock - v2);
2752 v14 = (char *)((char *)pMemBlocks[11]->pAlignedBlock - v2);
2753 do
2754 {
2755 v26 = *(float *)&v24[(int)((char *)v2 + v25)] - (double)pIndoorCamera->pos.x;
2756 v27 = *(float *)((char *)v2 + v25) - (double)pIndoorCamera->pos.y;
2757 v6 = *(float *)&v23[(int)((char *)v2 + v25)] - (double)pIndoorCamera->pos.z;
2758 v7 = pIndoorCamera->fRotationYCosine;
2759 v8 = pIndoorCamera->fRotationYSine;
2760 v20 = pIndoorCamera->fRotationXCosine;
2761 v19 = pIndoorCamera->fRotationXSine;
2762 v9 = (int)((char *)v2 + (int)v21);
2763 v10 = v27 * pIndoorCamera->fRotationYSine + pIndoorCamera->fRotationYCosine * v26;
2764 if ( pIndoorCamera->sRotationX )
2765 {
2766 v11 = v10;
2767 *(float *)v9 = v11 * pIndoorCamera->fRotationXCosine + pIndoorCamera->fRotationXSine * v6;
2768 *(float *)((char *)v2 + (int)v3) = v7 * v27 - v8 * v26;
2769 *(float *)((char *)v2 + (int)v5) = v20 * v6 - v11 * v19;
2770 }
2771 else
2772 {
2773 *(float *)v9 = v10;
2774 *(float *)((char *)v2 + (int)v3) = v7 * v27 - v8 * v26;
2775 *(float *)((char *)v2 + (int)v5) = v6;
2776 }
2777 if ( *(float *)v9 >= 8.0 )
2778 {
2779 if ( (double)pOutdoorCamera->shading_dist_mist >= *(float *)v9 )
2780 {
2781 *(int *)v2 = 0;
2782 v12 = v4 / (*(float *)v9 + 0.0000001) * (double)pOutdoorCamera->int_fov_rad;
2783 *(float *)((char *)v2 + (int)v18) = (double)pViewport->uScreenCenterX
2784 - v12 * *(float *)((char *)v2 + (int)v3);
2785 *(float *)((char *)v2 + (int)v17) = (double)pViewport->uScreenCenterY
2786 - v12 * *(float *)((char *)v2 + (int)v5);
2787 *(float *)((char *)v2 + (int)v16) = v4
2788 - v4 / (*(float *)v9 * 1000.0 / (double)pOutdoorCamera->shading_dist_mist);
2789 *(float *)((char *)v2 + (int)v15) = v4 / (*(float *)v9 + 0.0000001);
2790 v13 = *(float *)v9 + 6.7553994e15;
2791 v4 = 1.0;
2792 *(int *)((char *)v2 + (int)v14) = LODWORD(v13);
2793 }
2794 else
2795 {
2796 *(int *)v2 = 2;
2797 }
2798 }
2799 else
2800 {
2801 *(int *)v2 = 1;
2802 }
2803 ++v22;
2804 v2 = (char *)v2 + 4;
2805 }
2806 while ( v22 < this->field_8C );
2807 }
2808 this->field_8C = 0;
2809 }
2810
2811
2812
2813
2814
2815 //----- (0048A959) --------------------------------------------------------
2816 unsigned int sub_48A959(int _this, float a2, float a3, float a4)
2817 {
2818 int v4; // esi@1
2819 double v5; // st6@1
2820 double v6; // st6@1
2821 __int64 v8; // [sp+14h] [bp-20h]@1
2822 double v9; // [sp+1Ch] [bp-18h]@1
2823 int a6; // [sp+24h] [bp-10h]@1
2824 float v11; // [sp+28h] [bp-Ch]@1
2825 float v12; // [sp+2Ch] [bp-8h]@1
2826 float a1; // [sp+30h] [bp-4h]@1
2827 float a2a; // [sp+3Ch] [bp+8h]@7
2828 float a2b; // [sp+3Ch] [bp+8h]@7
2829 float a2c; // [sp+3Ch] [bp+8h]@7
2830 int a3a; // [sp+40h] [bp+Ch]@7
2831
2832 v4 = _this;
2833 v8 = ((unsigned int)_this >> 16) & 0xFFi64;
2834 v5 = (double)v8 * 0.0039215689;
2835 v8 = (unsigned __int16)_this >> 8;
2836 a1 = v5;
2837 v6 = (double)v8;
2838 v8 = _this & 0xFFi64;
2839 v12 = v6 * 0.0039215689;
2840 v11 = (double)v8 * 0.0039215689;
2841 RGB2HSV((float *)&v8 + 1, (float *)&v9 + 1, a1, v12, v11, (float *)&a6);
2842 if ( a2 != -1.0 )
2843 HIDWORD(v8) = LODWORD(a2);
2844 if ( a3 != -1.0 )
2845 HIDWORD(v9) = LODWORD(a3);
2846 if ( a4 != -1.0 )
2847 a6 = LODWORD(a4);
2848 HSV2RGB(&a1, &v12, &v11, *((float *)&v8 + 1), *((float *)&v9 + 1), *(float *)&a6);
2849 a2a = a1 * 255.0;
2850 *(double *)&v8 = a2a + 6.7553994e15;
2851 a3a = v8;
2852 a2b = v12 * 255.0;
2853 *(double *)&v8 = a2b + 6.7553994e15;
2854 a2c = v11 * 255.0;
2855 v9 = a2c + 6.7553994e15;
2856 return LODWORD(v9) | v4 & 0xFF000000 | (((unsigned int)v8 | (a3a << 8)) << 8);
2857 }
2858
2859
2860 //----- (0048B561) --------------------------------------------------------
2861 int _48B561_mess_with_scaling_along_z(/*int a1, */float a2)
2862 {
2863 float v2; // ST08_4@1
2864 double v3; // ST00_8@1
2865 int v4; // ST0C_4@1
2866 double v5; // ST00_8@1
2867 float v7; // [sp+18h] [bp+8h]@1
2868
2869 __debugbreak(); // check parameters carefully
2870
2871 v2 = a2 - 0.5;
2872 v3 = v2 + 6.7553994e15;
2873 v4 = LODWORD(v3);
2874 v7 = (a2 - (double)SLODWORD(v3)) * 65536.0;
2875 v5 = v7 + 6.7553994e15;
2876 return LODWORD(v5) | (v4 << 16);
2877 }
2878
2879
2880
2881
2882 //----- (004908DE) --------------------------------------------------------
2883 signed int __cdecl sub_4908DE()
2884 {
2885 char *v0; // esi@1
2886 signed int v1; // edx@2
2887 char *v2; // eax@2
2888 signed int v3; // ecx@2
2889
2890 v0 = (char *)pParty->pPlayers[0].pActiveSkills;
2891 while ( 1 )
2892 {
2893 v1 = 0;
2894 v2 = v0;
2895 v3 = 37;
2896 do
2897 {
2898 if ( *(short *)v2 )
2899 ++v1;
2900 v2 += 2;
2901 --v3;
2902 }
2903 while ( v3 );
2904 if ( v1 < 4 )
2905 break;
2906 v0 += 6972;
2907 if ( (signed int)v0 >= (signed int)&pParty->field_777C[18] )
2908 return 1;
2909 }
2910 return 0;
2911 }
2912
2913
2914
2915
2916 //----- (00491CB5) --------------------------------------------------------
2917 void __cdecl LoadPlayerPortraintsAndVoices()
2918 {
2919 Texture **v0; // ebx@1
2920 int v1; // eax@2
2921 int v2; // edi@3
2922 char *v3; // esi@5
2923 char *v4; // [sp+10h] [bp-4h]@1
2924
2925 pIcons_LOD->dword_011BA0 = pIcons_LOD->uNumLoadedFiles;
2926 v0 = (Texture **)pTextures_PlayerFaces;
2927 v4 = (char *)&pParty->pPlayers[0].uFace;
2928 do
2929 {
2930 v1 = 0;
2931 do
2932 {
2933 v2 = v1 + 1;
2934 sprintfex(pTmpBuf, "%s%02d", pPlayerPortraitsNames[*v4], v1 + 1);
2935 *v0 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE)];
2936 v1 = v2;
2937 ++v0;
2938 }
2939 while ( v2 < 56 );
2940 v4 += 6972;
2941 }
2942 while ( (signed int)v4 < (signed int)((char *)&pParty->pPickedItem.uExpireTime + 6) );
2943 pTexture_PlayerFaceEradicated = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("ERADCATE", TEXTURE_16BIT_PALETTE)];
2944 pTexture_PlayerFaceDead = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("DEAD", TEXTURE_16BIT_PALETTE)];
2945 v3 = (char *)&pParty->pPlayers[0].uVoiceID;
2946 pTexture_PlayerFaceMask = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("FACEMASK", TEXTURE_16BIT_PALETTE)];
2947 do
2948 {
2949 if ( byte_4ED498 )
2950 {
2951 pSoundList->_4A9A67(2 * ((unsigned __int8)byte_4ED498 + 50 * *(int *)v3) + 4998, 0);
2952 pSoundList->_4A9A67(2 * ((unsigned __int8)byte_4ED498 + 50 * *(int *)v3) + 4999, 0);
2953 }
2954 v3 += 6972;
2955 }
2956 while ( (signed int)v3 < (signed int)&pParty->field_871C[560] );
2957 }
2958 // 4ED498: using guessed type char byte_4ED498;
2959
2960 //----- (00491DE7) --------------------------------------------------------
2961 int __fastcall ReloadPlayerPortraits(int a1, int a2)
2962 {
2963 int result; // eax@1
2964 char **v3; // ebp@1
2965 Texture **v4; // ebx@1
2966 int v5; // esi@2
2967
2968 result = 0;
2969 v3 = &pPlayerPortraitsNames[a2];
2970 v4 = pTextures_PlayerFaces[a1];
2971 do
2972 {
2973 v5 = result + 1;
2974 sprintfex(pTmpBuf, "%s%02d", *v3, result + 1);
2975 pIcons_LOD->ReloadTexture(*v4, pTmpBuf, 2);
2976 result = v5;
2977 ++v4;
2978 }
2979 while ( v5 < 56 );
2980 return result;
2981 }
2982 // 491DE7: using guessed type int __fastcall ReloadPlayerPortraits(int, int);
2983
2984 //----- (00491E3A) --------------------------------------------------------
2985 void __cdecl sub_491E3A()
2986 {
2987 Player *v0; // ebx@1
2988 signed int v1; // esi@3
2989 char *v2; // eax@4
2990 unsigned int v3; // eax@7
2991 unsigned int v4; // edx@8
2992 char *v5; // ecx@9
2993 int v6; // edi@17
2994 Texture *v7; // ebx@18
2995 struct IDirect3DTexture2 **v8; // eax@19
2996 struct IDirect3DTexture2 *v9; // eax@20
2997 struct IDirectDrawSurface **v10; // eax@22
2998 struct IDirectDrawSurface *v11; // eax@23
2999 int v12; // eax@26
3000
3001 v0 = pParty->pPlayers;
3002 do
3003 {
3004 if ( byte_4ED498 )
3005 {
3006 v1 = 0;
3007 if ( (signed int)pSoundList->uNumSounds <= 0 )
3008 {
3009 LABEL_7:
3010 v3 = 0;
3011 }
3012 else
3013 {
3014 v2 = (char *)&pSoundList->pSounds->uSoundID;
3015 while ( *(int *)v2 != 2 * ((unsigned __int8)byte_4ED498 + 50 * v0->uVoiceID) + 4998 )
3016 {
3017 ++v1;
3018 v2 += 120;
3019 if ( v1 >= (signed int)pSoundList->uNumSounds )
3020 goto LABEL_7;
3021 }
3022 v3 = v1;
3023 }
3024 pSoundList->_4A9DCD(v3, 1);
3025 v4 = 0;
3026 if ( (signed int)pSoundList->uNumSounds <= 0 )
3027 {
3028 LABEL_12:
3029 v4 = 0;
3030 }
3031 else
3032 {
3033 v5 = (char *)&pSoundList->pSounds->uSoundID;
3034 while ( *(int *)v5 != 2 * ((unsigned __int8)byte_4ED498 + 50 * v0->uVoiceID) + 4999 )
3035 {
3036 ++v4;
3037 v5 += 120;
3038 if ( (signed int)v4 >= (signed int)pSoundList->uNumSounds )
3039 goto LABEL_12;
3040 }
3041 }
3042 pSoundList->_4A9DCD(v4, 1);
3043 }
3044 ++v0;
3045 }
3046 while ( (signed int)v0 < (signed int)pParty->pHirelings );
3047 v6 = pIcons_LOD->uNumLoadedFiles - 1;
3048 if ( v6 >= pIcons_LOD->dword_011BA0 )
3049 {
3050 v7 = &pIcons_LOD->pTextures[v6];
3051 do
3052 {
3053 v7->Release();
3054 v8 = pIcons_LOD->pHardwareTextures;
3055 if ( v8 )
3056 {
3057 v9 = v8[v6];
3058 if ( v9 )
3059 {
3060 v9->Release();
3061 pIcons_LOD->pHardwareTextures[v6] = 0;
3062 }
3063 }
3064 v10 = pIcons_LOD->pHardwareSurfaces;
3065 if ( v10 )
3066 {
3067 v11 = v10[v6];
3068 if ( v11 )
3069 {
3070 v11->Release();
3071 pIcons_LOD->pHardwareSurfaces[v6] = 0;
3072 }
3073 }
3074 --v6;
3075 --v7;
3076 }
3077 while ( v6 >= pIcons_LOD->dword_011BA0 );
3078 }
3079 v12 = pIcons_LOD->dword_011BA0;
3080 pIcons_LOD->dword_011BA0 = 0;
3081 pIcons_LOD->uNumLoadedFiles = v12;
3082 }
3083 // 4ED498: using guessed type char byte_4ED498;
3084
3085 //----- (00491F87) --------------------------------------------------------
3086 void __cdecl DrawHiredNPCs()
3087 {
3088 int v0; // ecx@2
3089 char *v1; // eax@2
3090 int v2; // edx@4
3091 signed int v3; // ebx@6
3092 char *v4; // esi@7
3093 int v5; // ecx@13
3094 int v6; // eax@15
3095 char v7; // al@17
3096 unsigned int v8; // eax@18
3097 int v9; // esi@18
3098 int v10; // eax@18
3099 unsigned int v11; // eax@19
3100 unsigned int v12; // esi@19
3101 unsigned int v13; // eax@23
3102 IconFrame *v14; // eax@24
3103 unsigned int v15; // eax@26
3104 char pContainer; // [sp+Ch] [bp-30h]@18
3105 unsigned int v17; // [sp+20h] [bp-1Ch]@19
3106 signed int uFrameID; // [sp+24h] [bp-18h]@19
3107 int i; // [sp+28h] [bp-14h]@15
3108 unsigned int v20; // [sp+2Ch] [bp-10h]@20
3109 unsigned int v21; // [sp+30h] [bp-Ch]@19
3110 int v22; // [sp+34h] [bp-8h]@2
3111 unsigned __int8 v23; // [sp+3Bh] [bp-1h]@2
3112
3113 if ( bNoNPCHiring != 1 )
3114 {
3115 v23 = 0;
3116 v22 = 0;
3117 v0 = 0;
3118 v1 = (char *)pParty->pHirelings;
3119 do
3120 {
3121 if ( *(int *)v1 )
3122 {
3123 v2 = v22++;
3124 pTmpBuf[v2] = v0;
3125 }
3126 v1 += 76;
3127 ++v0;
3128 }
3129 while ( (signed int)v1 < (signed int)&pParty->pPickedItem );
3130 v3 = 0;
3131 if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
3132 {
3133 v4 = (char *)pNPCStats->pNewNPCData;
3134 do
3135 {
3136 if ( v4[8] & 0x80 && (!pParty->pHirelings[0].pName || strcmp(*(const char **)v4, pParty->pHirelings[0].pName)) )
3137 {
3138 if ( !pParty->pHirelings[1].pName || strcmp(*(const char **)v4, pParty->pHirelings[1].pName) )
3139 {
3140 v5 = v22++;
3141 pTmpBuf[v5] = v3 + 2;
3142 }
3143 }
3144 ++v3;
3145 v4 += 76;
3146 }
3147 while ( v3 < (signed int)pNPCStats->uNumNewNPCs );
3148 }
3149 v6 = (unsigned __int8)pParty->field_709;
3150 for ( i = (unsigned __int8)pParty->field_709; i < v22; v6 = i++ + 1 )
3151 {
3152 if ( v23 >= 2u )
3153 break;
3154 v7 = pTmpBuf[v6];
3155 if ( (unsigned __int8)v7 >= 2u )
3156 {
3157 sprintfex(&pContainer, "NPC%03d", pNPCStats->pNPCData[(unsigned __int8)v7 + 499].uPortraitID);
3158 v15 = pIcons_LOD->LoadTexture(&pContainer, TEXTURE_16BIT_PALETTE);
3159 pRenderer->DrawTextureIndexed(
3160 pHiredNPCsIconsOffsetsX[v23],
3161 pHiredNPCsIconsOffsetsY[v23],
3162 (Texture *)(v15 != -1 ? 72 * v15 + 7145548 : 0));
3163 }
3164 else
3165 {
3166 sprintfex(&pContainer, "NPC%03d", pParty->pHirelings[(unsigned __int8)v7].uPortraitID);
3167 v8 = pIcons_LOD->LoadTexture(&pContainer, TEXTURE_16BIT_PALETTE);
3168 v9 = v23;
3169 pRenderer->DrawTextureIndexed(
3170 pHiredNPCsIconsOffsetsX[v9],
3171 pHiredNPCsIconsOffsetsY[v9],
3172 (Texture *)(v8 != -1 ? (int)&pIcons_LOD->pTextures[v8] : 0));
3173 v10 = (unsigned __int8)pTmpBuf[i];
3174 if ( pParty->pHirelings[v10].bDrawSomeAnim == 1 )
3175 {
3176 uFrameID = pParty->pHirelings[v10].evtb;
3177 v11 = pHiredNPCsIconsOffsetsX[v9];
3178 v12 = pHiredNPCsIconsOffsetsY[v9];
3179 v17 = v11;
3180 v21 = 0;
3181 if ( (signed int)pIconsFrameTable->uNumIcons <= 0 )
3182 {
3183 LABEL_23:
3184 v13 = 0;
3185 }
3186 else
3187 {
3188 v20 = 0;
3189 while ( _strcmpi("spell96", pIconsFrameTable->pIcons[v20 / 0x20].pAnimationName) )
3190 {
3191 ++v21;
3192 v20 += 32;
3193 if ( (signed int)v21 >= (signed int)pIconsFrameTable->uNumIcons )
3194 goto LABEL_23;
3195 }
3196 v13 = v21;
3197 }
3198 v14 = pIconsFrameTable->GetFrame(v13, uFrameID);
3199 pRenderer->DrawTextureTransparent(v17, v12, &pIcons_LOD->pTextures[v14->uTextureID]);
3200 }
3201 }
3202 ++v23;
3203 }
3204 }
3205 }
3206 // 6BE3C5: using guessed type char bNoNPCHiring;
3207
3208
3209
3210 //----- (004921C1) --------------------------------------------------------
3211 void GameUI_DrawPortraits(unsigned int _this)
3212 {
3213 signed int v1; // ebx@2
3214 int v2; // ebp@7
3215 char *v3; // esi@7
3216 Texture *v4; // eax@10
3217 signed int v5; // edx@13
3218 PlayerFrame *v6; // eax@14
3219 unsigned int v7; // eax@17
3220 PlayerFrame *v8; // eax@21
3221 unsigned int v9; // eax@27
3222 bool v10; // eax@33
3223 bool v11; // edi@40
3224 bool v12; // edx@43
3225 bool v13; // ecx@46
3226 int v14; // esi@54
3227 char *v15; // edi@55
3228 int v16; // eax@57
3229 __int16 *v17; // esi@59
3230 char *v18; // edi@59
3231 int v19; // eax@62
3232 Texture *v20; // [sp-4h] [bp-1Ch]@27
3233 signed int v21; // [sp+10h] [bp-8h]@7
3234 unsigned int v22; // [sp+14h] [bp-4h]@1
3235
3236 v22 = _this;
3237 if ( qword_A750D8 )
3238 {
3239 qword_A750D8 -= (signed int)pMiscTimer->uTimeElapsed;
3240 v1 = 0;
3241 if ( qword_A750D8 <= 0 )
3242 {
3243 if ( pPlayers[word_A750E2]->CanAct() )
3244 pPlayers[word_A750E2]->PlaySound(word_A750E0, 0);
3245 qword_A750D8 = 0i64;
3246 }
3247 }
3248 else
3249 {
3250 v1 = 0;
3251 }
3252 v2 = 0;
3253 v21 = v1;
3254 v3 = (char *)&pParty->pPlayers[0].pConditions[14];
3255 while ( 1 )
3256 {
3257 if ( *((_QWORD *)v3 + 2) )
3258 {
3259 v4 = pTexture_PlayerFaceEradicated;
3260 LABEL_27:
3261 v20 = v4;
3262 v9 = pPlayerPortraitsXCoords_For_PlayerBuffAnimsDrawing[v2];
3263 if ( pParty->pPartyBuffs[11].uExpireTime )
3264 pRenderer->_4A6E7E(v9, 0x183u, v20);
3265 else
3266 pRenderer->DrawTextureTransparent(v9 + 1, 0x184u, v20);
3267 v10 = *((int *)v3 + 1541) >= v1 && (*((int *)v3 + 1541) > v1 || *((int *)v3 + 1540) > (unsigned int)v1);
3268 if ( *((int *)v3 + 1489) >= v1 && (*((int *)v3 + 1489) > v1 || *((int *)v3 + 1488) > (unsigned int)v1) )
3269 v1 = 1;
3270 v11 = *((_QWORD *)v3 + 758) > 0i64;
3271 v12 = *((_QWORD *)v3 + 756) > 0i64;
3272 v13 = *((_QWORD *)v3 + 768) > 0i64;
3273 if ( v13 | v12 | v11 | v1 | v10 )
3274 sub_441A4E(v2);
3275 goto LABEL_50;
3276 }
3277 if ( *(_QWORD *)v3 )
3278 {
3279 v4 = pTexture_PlayerFaceDead;
3280 goto LABEL_27;
3281 }
3282 v5 = 0;
3283 if ( (signed int)pPlayerFrameTable->uNumFrames <= v1 )
3284 {
3285 LABEL_17:
3286 v7 = 0;
3287 }
3288 else
3289 {
3290 v6 = pPlayerFrameTable->pFrames;
3291 while ( v6->uSequenceID != *((short *)v3 + 3350) )
3292 {
3293 ++v5;
3294 ++v6;
3295 if ( v5 >= (signed int)pPlayerFrameTable->uNumFrames )
3296 goto LABEL_17;
3297 }
3298 v7 = v5;
3299 }
3300 if ( v7 == v1 )
3301 v7 = 1;
3302 if ( *((short *)v3 + 3350) == 21 )
3303 v8 = pPlayerFrameTable->GetFrameBy_y(
3304 (int *)v3 + 1678,
3305 (int *)v3 + 1677,
3306 pMiscTimer->uTimeElapsed);
3307 else
3308 v8 = pPlayerFrameTable->GetFrameBy_x(v7, *((short *)v3 + 3351));
3309 if ( *((short *)v3 + 3353) != v8->uTextureID - 1 || v22 )
3310 {
3311 *((short *)v3 + 3353) = v8->uTextureID - 1;
3312 v1 = 0;
3313 v4 = (Texture *)A74CEC_player_faces_minus1_indexing[v21 + v8->uTextureID];
3314 goto LABEL_27;
3315 }
3316 LABEL_50:
3317 v21 += 56;
3318 v3 += 6972;
3319 ++v2;
3320 if ( (signed int)v3 >= (signed int)&pParty->pHirelings[1].field_24 )
3321 break;
3322 v1 = 0;
3323 }
3324 if ( pParty->bTurnBasedModeOn == 1 )
3325 {
3326 if ( pTurnEngine->field_4 != 1 )
3327 {
3328 if ( (pTurnEngine->pQueue[0].uPackedID & 7) == 4 )
3329 {
3330 v14 = 0;
3331 if ( pTurnEngine->uActorQueueSize > 0 )
3332 {
3333 v15 = (char *)pTurnEngine->pQueue;
3334 do
3335 {
3336 if ( (*v15 & 7) != 4 )
3337 break;
3338 v16 = dword_5079D0;
3339 if ( pParty->uFlags & 0x10 )
3340 {
3341 v16 = dword_5079CC;
3342 }
3343 else
3344 {
3345 if ( pParty->uFlags & 0x20 )
3346 v16 = dword_5079C8;
3347 }
3348 pRenderer->DrawTextureTransparent(
3349 pPlayerPortraitsXCoords_For_PlayerBuffAnimsDrawing[*(int *)v15 >> 3] - 4,
3350 0x181u,
3351 (Texture *)(v16 != -1 ? (int)&pIcons_LOD->pTextures[v16] : 0));
3352 ++v14;
3353 v15 += 16;
3354 }
3355 while ( v14 < pTurnEngine->uActorQueueSize );
3356 }
3357 }
3358 }
3359 }
3360 else
3361 {
3362 v17 = pPlayerPortraitsXCoords_For_PlayerBuffAnimsDrawing;
3363 v18 = (char *)pParty->pPlayers;
3364 do
3365 {
3366 if ( ((Player *)v18)->CanAct() && !*((short *)v18 + 3226) )
3367 {
3368 v19 = dword_5079D0;
3369 if ( pParty->uFlags & 0x10 )
3370 {
3371 v19 = dword_5079CC;
3372 }
3373 else
3374 {
3375 if ( pParty->uFlags & 0x20 )
3376 v19 = dword_5079C8;
3377 }
3378 pRenderer->DrawTextureTransparent(
3379 *v17 - 4,
3380 0x181u,
3381 (Texture *)(v19 != -1 ? (int)&pIcons_LOD->pTextures[v19] : 0));
3382 }
3383 v18 += 6972;
3384 ++v17;
3385 }
3386 while ( (signed int)v18 < (signed int)pParty->pHirelings );
3387 }
3388 }
3389
3390
3391 //----- (0049387A) --------------------------------------------------------
3392 int CycleCharacter(unsigned int _this)
3393 {
3394 signed int result; // eax@1
3395 signed int v2; // ecx@2
3396 signed int v3; // ecx@8
3397
3398 result = uActiveCharacter;
3399 if ( _this )
3400 {
3401 v2 = 0;
3402 while ( 1 )
3403 {
3404 --result;
3405 if ( result < 1 )
3406 result = 4;
3407 if ( !pPlayers[result]->uTimeToRecovery )
3408 break;
3409 ++v2;
3410 if ( v2 >= 4 )
3411 return uActiveCharacter;
3412 }
3413 }
3414 else
3415 {
3416 v3 = 0;
3417 while ( 1 )
3418 {
3419 ++result;
3420 if ( result > 4 )
3421 result = 1;
3422 if ( !pPlayers[result]->uTimeToRecovery )
3423 break;
3424 ++v3;
3425 if ( v3 >= 4 )
3426 return uActiveCharacter;
3427 }
3428 }
3429 return result;
3430 }
3431
3432 //----- (004938D1) --------------------------------------------------------
3433 void __fastcall Rest(unsigned int uHoursToSleep)
3434 {
3435 unsigned int v1; // esi@1
3436 double v2; // st7@3
3437 Player **v3; // esi@3
3438
3439 v1 = uHoursToSleep;
3440 if ( uHoursToSleep > 240 )
3441 UpdateActors();
3442 v2 = (double)(7680 * v1) * 0.033333335;
3443 pParty->uTimePlayed += (signed __int64)v2;
3444 v3 = &pPlayers[1];
3445 do
3446 {
3447 (*v3)->Recover((signed __int64)v2);
3448 ++v3;
3449 }
3450 while ( (signed int)v3 <= (signed int)&pPlayers[4] );
3451 _494035_timed_effects__water_walking_damage__etc();
3452 }
3453
3454 //----- (00493938) --------------------------------------------------------
3455 int __cdecl _493938_regenerate()
3456 {
3457 int v0; // edi@1
3458 signed __int64 v1; // qax@1
3459 int v2; // ecx@1
3460 int result; // eax@1
3461 int v4; // eax@2
3462 int v5; // edi@5
3463 char *v6; // ecx@5
3464 char v7; // sf@5
3465 char *v8; // ecx@10
3466 int v9; // edi@15
3467 signed int v10; // eax@15
3468 __int16 *v11; // edx@16
3469 int v12; // eax@20
3470 int v13; // ebx@20
3471 unsigned int *v14; // esi@21
3472 unsigned int v15; // ecx@21
3473 unsigned int v16; // eax@21
3474 int v17; // edx@21
3475 int v18; // eax@21
3476 signed int v19; // eax@21
3477 signed int v20; // ebx@25
3478 Player *v21; // esi@25
3479 ITEM_EQUIP_TYPE v22; // edi@30
3480 int v23; // edx@31
3481 signed int v24; // ecx@32
3482 signed int v25; // eax@33
3483 int v26; // eax@35
3484 int v27; // eax@36
3485 int v28; // eax@37
3486 int v29; // eax@40
3487 int v30; // eax@41
3488 signed int v31; // ecx@53
3489 char *v32; // eax@53
3490 char *v33; // edi@82
3491 int v34; // ecx@88
3492 int v35; // eax@88
3493 char *v36; // edi@99
3494 int v37; // edi@104
3495 int v38; // edi@106
3496 int v39; // edi@111
3497 int v40; // ecx@113
3498 char v41[400]; // [sp+4h] [bp-22Ch]@20
3499 LayingItem a1; // [sp+194h] [bp-9Ch]@15
3500 Vec3_int_ a3; // [sp+204h] [bp-2Ch]@15
3501 int v44; // [sp+210h] [bp-20h]@22
3502 int v45; // [sp+214h] [bp-1Ch]@25
3503 int v46; // [sp+218h] [bp-18h]@25
3504 int v47; // [sp+21Ch] [bp-14h]@25
3505 int v48; // [sp+220h] [bp-10h]@25
3506 int v49; // [sp+224h] [bp-Ch]@24
3507 int v50; // [sp+228h] [bp-8h]@25
3508 int v51; // [sp+22Ch] [bp-4h]@2
3509
3510 v0 = (signed int)(signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60;
3511 v1 = (signed __int64)((double)pParty->uLastRegenerationTime * 0.234375);
3512 v2 = (signed int)v1 / 60;
3513 result = (signed int)v1 / 60 + 5;
3514 if ( v0 >= result )
3515 {
3516 v51 = 0;
3517 v4 = (v0 - v2) / 5;
3518 if ( (signed __int64)pParty->pPartyBuffs[7].uExpireTime > 0 )
3519 {
3520 if ( pParty->bFlying )
3521 {
3522 if ( !(pParty->pPartyBuffs[7].uFlags & 1) )
3523 {
3524 v5 = v4 * pParty->pPartyBuffs[7].uPower;
3525 v6 = &stru_AA1058[4].pSounds[6972 * pParty->pPartyBuffs[7].uCaster + 2000];
3526 v7 = *(int *)v6 - v5 < 0;
3527 *(int *)v6 -= v5;
3528 if ( v7 )
3529 {
3530 *(int *)v6 = 0;
3531 pParty->uFlags &= 0xFFFFFFBFu;
3532 pParty->bFlying = 0;
3533 v51 = 1;
3534 }
3535 }
3536 }
3537 }
3538 if ( (signed __int64)pParty->pPartyBuffs[18].uExpireTime > 0 )
3539 {
3540 if ( pParty->uFlags & 0x80 )
3541 {
3542 if ( !(pParty->pPartyBuffs[18].uFlags & 1) )
3543 {
3544 v8 = &stru_AA1058[4].pSounds[6972 * pParty->pPartyBuffs[18].uCaster + 2000];
3545 v7 = *(int *)v8 - v4 < 0;
3546 *(int *)v8 -= v4;
3547 if ( v7 )
3548 {
3549 *(int *)v8 = 0;
3550 LOBYTE(pParty->uFlags) &= 0x7Fu;
3551 v51 = 1;
3552 }
3553 }
3554 }
3555 }
3556 if ( SHIDWORD(pParty->pPartyBuffs[10].uExpireTime) >= 0
3557 && (SHIDWORD(pParty->pPartyBuffs[10].uExpireTime) > 0 || LODWORD(pParty->pPartyBuffs[10].uExpireTime)) )
3558 {
3559 //LayingItem::LayingItem(&a1);
3560 v9 = 0;
3561 a3.z = 0;
3562 a3.y = 0;
3563 a3.x = 0;
3564 a1.stru_24.Reset();
3565 a1.field_4C = pParty->pPartyBuffs[10].uPower;
3566 a1.field_50 = pParty->pPartyBuffs[10].uSkill;
3567 v10 = 0;
3568 a1.uItemType = 1070;
3569 a1.field_48 = 8;
3570 if ( (signed int)pObjectList->uNumObjects <= 0 )
3571 {
3572 LABEL_19:
3573 LOWORD(v10) = 0;
3574 }
3575 else
3576 {
3577 v11 = &pObjectList->pObjects->uObjectID;
3578 while ( stru_4E3ACC[8].uItemType != *v11 )
3579 {
3580 ++v10;
3581 v11 += 28;
3582 if ( v10 >= (signed int)pObjectList->uNumObjects )
3583 goto LABEL_19;
3584 }
3585 }
3586 a1.uObjectDescID = v10;
3587 a1.field_60_distance_related_prolly_lod = 0;
3588 v12 = 8 * pParty->pPartyBuffs[10].uCaster;
3589 LOBYTE(v12) = v12 | 4;
3590 a1.uAttributes = 0;
3591 a1.uSectorID = 0;
3592 a1.uSpriteFrameID = 0;
3593 a1.field_58 = v12;
3594 a1.uFacing = 0;
3595 a1.uSoundID = 0;
3596 v13 = sub_46A89E((int)v41, 100, 307);
3597 if ( v13 > 0 )
3598 {
3599 do
3600 {
3601 v14 = (unsigned int *)&v41[4 * v9];
3602 v15 = *v14;
3603 v16 = *v14;
3604 a1.vPosition.x = pActors[v16].vPosition.x;
3605 v17 = pActors[v16].vPosition.y;
3606 a1.vPosition.z = pActors[v16].vPosition.z;
3607 v18 = 8 * v15;
3608 LOBYTE(v18) = 8 * v15 | 3;
3609 a1.vPosition.y = v17;
3610 a1.field_5C = v18;
3611 v19 = a1.Create(0, 0, 0, 0);
3612 DamageMonsterFromParty(8 * v19 | 2, *v14, &a3);
3613 ++v9;
3614 }
3615 while ( v9 < v13 );
3616 }
3617 }
3618 v44 = 0;
3619 if ( sub_476387() == 1 )
3620 v44 = 1;
3621 v49 = 0;
3622 LABEL_25:
3623 v20 = 0;
3624 v21 = &pParty->pPlayers[v49];
3625 v50 = 0;
3626 v47 = 0;
3627 v45 = 0;
3628 v48 = 0;
3629 v46 = 0;
3630 if ( v44 && v21->uClass == 31 )
3631 v50 = 1;
3632 if ( v21->uClass == 35 )
3633 v48 = 1;
3634 v22 = (ITEM_EQUIP_TYPE)0;
3635 while ( 1 )
3636 {
3637 if ( v21->HasItemEquipped(v22) )
3638 {
3639 v24 = *(int *)&v21->pDarkSpellbook.bIsSpellAvailable[36 * *(int *)v23 + 5];
3640 if ( v24 > 134 )
3641 {
3642 if ( v24 == 529 )
3643 goto LABEL_43;
3644 if ( v24 == 535 )
3645 goto LABEL_44;
3646 if ( v24 == 515 )
3647 {
3648 v47 = 1;
3649 }
3650 else
3651 {
3652 if ( v24 == 532 )
3653 goto LABEL_50;
3654 }
3655 }
3656 else
3657 {
3658 v25 = *(int *)&v21->field_1F5[36 * *(int *)v23 + 7];
3659 if ( v25 <= 50 )
3660 {
3661 if ( v25 != 50 )
3662 {
3663 v26 = v25 - 37;
3664 if ( v26 )
3665 {
3666 v27 = v26 - 1;
3667 if ( !v27 )
3668 goto LABEL_50;
3669 v28 = v27 - 6;
3670 if ( v28 )
3671 {
3672 if ( v28 != 3 )
3673 goto LABEL_51;
3674 LABEL_50:
3675 v50 = 1;
3676 goto LABEL_51;
3677 }
3678 }
3679 }
3680 LABEL_44:
3681 v20 = 1;
3682 goto LABEL_51;
3683 }
3684 v29 = v25 - 54;
3685 if ( !v29 )
3686 goto LABEL_44;
3687 v30 = v29 - 1;
3688 if ( !v30 )
3689 goto LABEL_50;
3690 if ( v30 == 11 )
3691 {
3692 LABEL_43:
3693 v20 = 1;
3694 v50 = 1;
3695 goto LABEL_51;
3696 }
3697 }
3698 }
3699 LABEL_51:
3700 v22 = (ITEM_EQUIP_TYPE)((int)v22 + 1);
3701 if ( (signed int)v22 >= 16 )
3702 {
3703 if ( v48 )
3704 {
3705 v31 = 0;
3706 v32 = (char *)v21->pInventoryItems;
3707 while ( *(int *)v32 != 601 || (unsigned __int8)v32[26] != v49 + 1 )
3708 {
3709 ++v31;
3710 v32 += 36;
3711 if ( v31 >= 138 )
3712 goto LABEL_59;
3713 }
3714 v48 = 0;
3715 v45 = 1;
3716 }
3717 LABEL_59:
3718 if ( v21->pConditions[17] )
3719 v46 = 1;
3720 if ( v20 && !v21->pConditions[14] && !v21->pConditions[16] )
3721 {
3722 ++v21->sHealth;
3723 if ( v21->sHealth > v21->GetMaxHealth() )
3724 v21->sHealth = v21->GetMaxHealth();
3725 if ( v21->pConditions[13] && v21->sHealth > 0 )
3726 {
3727 LODWORD(v21->pConditions[13]) = 0;
3728 HIDWORD(v21->pConditions[13]) = 0;
3729 }
3730 v51 = 1;
3731 }
3732 if ( SHIDWORD(v21->pPlayerBuffs[12].uExpireTime) >= 0
3733 && (SHIDWORD(v21->pPlayerBuffs[12].uExpireTime) > 0 || LODWORD(v21->pPlayerBuffs[12].uExpireTime))
3734 && !v21->pConditions[14]
3735 && !v21->pConditions[16] )
3736 {
3737 v21->sHealth += 5 * v21->pPlayerBuffs[12].uPower;
3738 if ( v21->sHealth > v21->GetMaxHealth() )
3739 v21->sHealth = v21->GetMaxHealth();
3740 if ( v21->pConditions[13] && v21->sHealth > 0 )
3741 {
3742 LODWORD(v21->pConditions[13]) = 0;
3743 HIDWORD(v21->pConditions[13]) = 0;
3744 }
3745 v51 = 1;
3746 }
3747 if ( v50 )
3748 {
3749 v33 = (char *)&v21->sMana;
3750 ++*(int *)v33;
3751 if ( v21->sMana > v21->GetMaxMana() )
3752 *(int *)v33 = v21->GetMaxMana();
3753 v51 = 1;
3754 }
3755 if ( v47 && !v21->pConditions[14] && !v21->pConditions[16] )
3756 {
3757 v34 = LODWORD(v21->pConditions[13]);
3758 --v21->sHealth;
3759 v35 = v21->sHealth;
3760 if ( !(HIDWORD(v21->pConditions[13]) | v34) && v35 < 0 )
3761 v21->pConditions[13] = pParty->uTimePlayed;
3762 if ( v35 < 1 )
3763 {
3764 if ( v21->sHealth + v21->uEndurance + v21->GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE, 0) >= 1
3765 || (signed __int64)v21->pPlayerBuffs[11].uExpireTime > 0 )
3766 {
3767 v21->pConditions[13] = pParty->uTimePlayed;
3768 }
3769 else
3770 {
3771 if ( !v21->pConditions[14] )
3772 v21->pConditions[14] = pParty->uTimePlayed;
3773 }
3774 }
3775 v51 = 1;
3776 }
3777 if ( v45 )
3778 {
3779 v36 = (char *)&v21->sMana;
3780 ++*(int *)v36;
3781 if ( v21->sMana > v21->GetMaxMana() )
3782 *(int *)v36 = v21->GetMaxMana();
3783 }
3784 if ( v48 && !v21->pConditions[14] && !v21->pConditions[16] )
3785 {
3786 v37 = v21->sHealth;
3787 if ( v37 > v21->GetMaxHealth() / 2 )
3788 v21->sHealth = v37 - 2;
3789 v38 = v21->sMana;
3790 if ( v38 > v21->GetMaxMana() / 2 )
3791 v21->sMana = v38 - 2;
3792 }
3793 if ( v46 && !v21->pConditions[14] && !v21->pConditions[16] )
3794 {
3795 v39 = v21->sHealth;
3796 if ( v39 > v21->GetMaxHealth() / 2 )
3797 v21->sHealth = v39 - 1;
3798 v40 = v21->sMana;
3799 if ( v40 > 0 )
3800 v21->sMana = v40 - 1;
3801 }
3802 ++v49;
3803 if ( v49 >= 4 )
3804 {
3805 result = HIDWORD(pParty->uTimePlayed);
3806 pParty->uLastRegenerationTime = pParty->uTimePlayed;
3807 if ( !viewparams->bRedrawGameUI )
3808 {
3809 result = v51;
3810 viewparams->bRedrawGameUI = v51;
3811 }
3812 return result;
3813 }
3814 goto LABEL_25;
3815 }
3816 }
3817 }
3818 return result;
3819 }
3820 // 493938: using guessed type char var_22C[400];
3821
3822
3823
3824 //----- (00493F79) --------------------------------------------------------
3825 int sub_493F79(stru351 *_this, __int64 a2)
3826 {
3827 signed __int64 v2; // ST2C_8@1
3828 signed __int64 v3; // qax@1
3829 signed __int64 v4; // ST1C_8@1
3830 unsigned __int64 v5; // qax@1
3831 unsigned int v6; // ebx@1
3832 int result; // eax@1
3833
3834 v2 = (signed __int64)((double)a2 * 0.234375);
3835 v3 = v2 / 60 / 60;
3836 v4 = v3;
3837 v5 = (unsigned int)v3 / 0x18;
3838 v6 = (unsigned int)(v5 / 7) >> 2;
3839 _this->field_0 = v2 % 60;
3840 _this->field_4 = v2 / 60 % 60;
3841 _this->field_8 = v4 % 24;
3842 _this->field_10 = v5 / 7 & 3;
3843 _this->field_C = (unsigned int)v5 % 0x1C;
3844 result = v6 / 0xC + 1168;
3845 _this->field_14 = v6 % 0xC;
3846 _this->field_18 = result;
3847 return result;
3848 }
3849
3850
3851
3852
3853
3854 //----- (00494035) --------------------------------------------------------
3855 void __cdecl _494035_timed_effects__water_walking_damage__etc()
3856 {
3857 signed __int64 v0; // qax@1
3858 signed __int64 v1; // ST30_8@1
3859 signed __int64 v2; // ST38_8@1
3860 unsigned __int64 v3; // qax@1
3861 unsigned int v4; // edi@1
3862 signed int v5; // eax@4
3863 char *v6; // ecx@5
3864 Player *v7; // esi@8
3865 char *v8; // ecx@12
3866 Player *pPlayer; // esi@15
3867 void *v10; // esi@25
3868 unsigned int v11; // ecx@27
3869 signed int v12; // edi@29
3870 Player *v13; // ecx@30
3871 Player *v14; // esi@35
3872 double v15; // st7@35
3873 Player **v16; // esi@43
3874 Player *v17; // edi@44
3875 double v18; // st7@44
3876 float v19; // ST28_4@48
3877 double v20; // ST38_8@48
3878 Player *v21; // esi@51
3879 signed int v22; // edi@53
3880 int v23; // eax@59
3881 int v24; // ecx@60
3882 int v25; // eax@63
3883 int v26; // ecx@64
3884 int v27; // eax@67
3885 int v28; // ecx@68
3886 int v29; // eax@71
3887 int v30; // ecx@72
3888 int v31; // eax@75
3889 int v32; // ecx@76
3890 int v33; // eax@79
3891 int v34; // ecx@80
3892 int v35; // eax@83
3893 int v36; // ecx@84
3894 int v37; // eax@87
3895 int v38; // ecx@88
3896 int v39; // eax@91
3897 int v40; // ecx@92
3898 int v41; // eax@95
3899 int v42; // ecx@96
3900 bool v43; // ebx@102
3901 SpellBuff *v44; // edi@104
3902 signed int v45; // ebp@104
3903 bool v46; // edi@111
3904 SpellBuff *v47; // esi@113
3905 Player **v48; // esi@119
3906 signed int v49; // edi@121
3907 char *v50; // esi@122
3908 signed int v51; // edx@128
3909 signed int v52; // ecx@130
3910 int v53; // eax@131
3911 Player *v54; // eax@141
3912 unsigned int v55; // [sp-8h] [bp-38h]@18
3913 unsigned int v56; // [sp-8h] [bp-38h]@55
3914 int v57; // [sp-4h] [bp-34h]@18
3915 int v58; // [sp-4h] [bp-34h]@33
3916 int v59; // [sp-4h] [bp-34h]@55
3917 unsigned int v60; // [sp+10h] [bp-20h]@1
3918 unsigned int v61; // [sp+14h] [bp-1Ch]@1
3919 Player **v62; // [sp+14h] [bp-1Ch]@50
3920 unsigned int a2; // [sp+18h] [bp-18h]@1
3921 signed int a2a; // [sp+18h] [bp-18h]@47
3922 signed int v65; // [sp+1Ch] [bp-14h]@47
3923
3924 a2 = pParty->uCurrentHour;
3925 v61 = pParty->uDaysPlayed;
3926 v60 = pEventTimer->uTimeElapsed;
3927 pParty->uTimePlayed += (signed int)pEventTimer->uTimeElapsed;
3928 v0 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60;
3929 v1 = v0;
3930 v0 /= 60i64;
3931 v2 = v0;
3932 v3 = (unsigned int)v0 / 0x18;
3933 v4 = (unsigned int)(v3 / 7) >> 2;
3934 pParty->uCurrentTimeSecond = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) % 60;
3935 pParty->uCurrentMinute = v1 % 60;
3936 pParty->uCurrentMonthWeek = v3 / 7 & 3;
3937 pParty->uCurrentHour = v2 % 24;
3938 pParty->uDaysPlayed = (unsigned int)v3 % 0x1C;
3939 pParty->uCurrentMonth = v4 % 0xC;
3940 pParty->uCurrentYear = v4 / 0xC + 1168;
3941 if ( pParty->uCurrentHour >= 3 && ((signed int)a2 < 3 || (unsigned int)v3 % 0x1C > v61) )
3942 {
3943 v5 = 0;
3944 pParty->pHirelings[0].bHasUsedTheAbility = 0;
3945 pParty->pHirelings[1].bHasUsedTheAbility = 0;
3946 if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
3947 {
3948 v6 = (char *)&pNPCStats->pNewNPCData[0].bHasUsedTheAbility;
3949 do
3950 {
3951 *(int *)v6 = 0;
3952 ++v5;
3953 v6 += 76;
3954 }
3955 while ( v5 < (signed int)pNPCStats->uNumNewNPCs );
3956 }
3957 ++pParty->field_764;
3958 if ( pParty->field_764 > 1u )
3959 {
3960 v7 = pParty->pPlayers;
3961 do
3962 {
3963 v7->SetCondition(1u, 0);
3964 ++v7;
3965 }
3966 while ( (signed int)v7 < (signed int)pParty->pHirelings );
3967 if ( pParty->uNumFoodRations )
3968 {
3969 Party::TakeFood(1u);
3970 }
3971 else
3972 {
3973 v8 = (char *)&pParty->pPlayers[0].sHealth;
3974 do
3975 {
3976 *(int *)v8 = *(int *)v8 / ((unsigned __int8)pParty->field_764 + 1) + 1;
3977 v8 += 6972;
3978 }
3979 while ( (signed int)v8 < (signed int)&pParty->field_871C[567] );
3980 }
3981 if ( pParty->field_764 > 3u )
3982 {
3983 pPlayer = pParty->pPlayers;
3984 do
3985 {
3986 pPlayer->Zero();
3987 if ( !(pPlayer->pConditions[15] | pPlayer->pConditions[16] | pPlayer->pConditions[14]) )
3988 {
3989 if ( rand() % 100 < 5 * (unsigned __int8)pParty->field_764 )
3990 {
3991 v57 = 0;
3992 v55 = 14;
3993 LABEL_21:
3994 pPlayer->SetCondition(v55, v57);
3995 goto LABEL_22;
3996 }
3997 if ( rand() % 100 < 10 * (unsigned __int8)pParty->field_764 )
3998 {
3999 v57 = 0;
4000 v55 = 5;
4001 goto LABEL_21;
4002 }
4003 }
4004 LABEL_22:
4005 ++pPlayer;
4006 }
4007 while ( (signed int)pPlayer < (signed int)pParty->pHirelings );
4008 }
4009 }
4010 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
4011 pOutdoor->SetFog();
4012 v10 = &pParty->pPlayers[0].uNumDivineInterventionCastsThisDay;
4013 do
4014 {
4015 memset(v10, 0, 4u);
4016 v10 = (char *)v10 + 6972;
4017 }
4018 while ( (signed int)v10 < (signed int)&pParty->field_871C[694] );
4019 }
4020 v11 = LODWORD(pParty->uTimePlayed);
4021 if ( pParty->uFlags & 4 && pParty->field_6FC < (signed __int64)pParty->uTimePlayed )
4022 {
4023 v12 = 1;
4024 pParty->field_6FC = LODWORD(pParty->uTimePlayed) + 128;
4025 viewparams->bRedrawGameUI = 1;
4026 while ( 1 )
4027 {
4028 if ( pPlayers[v12]->WearsItem(516, 3)
4029 || v13->HasEnchantedItemEquipped(71)
4030 || (signed __int64)v13->pPlayerBuffs[23].uExpireTime > 0 )
4031 {
4032 v58 = 0;
4033 }
4034 else
4035 {
4036 v58 = 0;
4037 if ( !sub_43EE77_ProbablyIfUnderwaterSuitIsEquipped(v12) )
4038 {
4039 v14 = pPlayers[v12];
4040 v15 = (double)pPlayers[v12]->GetMaxHealth() * 0.1;
4041 v14->ReceiveDamage((signed __int64)v15, 0);
4042 if ( pParty->uFlags & 4 )
4043 {
4044 strcpy(GameUI_StatusBar_TimedString, pGlobalTXT_LocalizationStrings[660]);
4045 GameUI_StatusBar_TimedStringTimeLeft = 128;
4046 }
4047 goto LABEL_39;
4048 }
4049 v13 = pPlayers[v12];
4050 }
4051 v13->PlayEmotion(37, v58);
4052 LABEL_39:
4053 ++v12;
4054 if ( v12 > 4 )
4055 {
4056 v11 = LODWORD(pParty->uTimePlayed);
4057 break;
4058 }
4059 }
4060 }
4061 if ( pParty->uFlags & 0x200 && pParty->field_6FC < (signed __int64)__PAIR__(HIDWORD(pParty->uTimePlayed), v11) )
4062 {
4063 viewparams->bRedrawGameUI = 1;
4064 pParty->field_6FC = v11 + 128;
4065 v16 = &pPlayers[1];
4066 do
4067 {
4068 v17 = *v16;
4069 v18 = (double)(*v16)->GetMaxHealth() * 0.1;
4070 v17->ReceiveDamage((signed __int64)v18, 0);
4071 if ( pParty->uFlags & 0x200 )
4072 {
4073 strcpy(GameUI_StatusBar_TimedString, pGlobalTXT_LocalizationStrings[661]);
4074 GameUI_StatusBar_TimedStringTimeLeft = 128;
4075 }
4076 ++v16;
4077 }
4078 while ( (signed int)v16 <= (signed int)&pPlayers[4] );
4079 }
4080 _493938_regenerate();
4081 v65 = 4;
4082 a2a = v60;
4083 if ( pParty->uFlags2 & 2 )
4084 {
4085 v19 = (double)(signed int)v60 * 0.5;
4086 v20 = v19 + 6.7553994e15;
4087 a2a = LODWORD(v20);
4088 if ( SLODWORD(v20) <= 0 )
4089 a2a = 1;
4090 }
4091 v62 = &pPlayers[1];
4092 do
4093 {
4094 v21 = *v62;
4095 if ( (*v62)->uTimeToRecovery )
4096 v21->Recover(a2a);
4097 v22 = v21->sHealth;
4098 if ( v21->GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE, 0) + v22 + v21->uEndurance >= 1
4099 || (signed __int64)v21->pPlayerBuffs[11].uExpireTime > 0 )
4100 {
4101 if ( v22 >= 1 )
4102 goto LABEL_59;
4103 v59 = 0;
4104 v56 = 13;
4105 }
4106 else
4107 {
4108 v59 = 0;
4109 v56 = 14;
4110 }
4111 v21->SetCondition(v56, v59);
4112 LABEL_59:
4113 v23 = (int)&v21->field_E0;
4114 if ( v21->field_E0 )
4115 {
4116 v24 = *(int *)v23 - v60;
4117 if ( v24 > 0 )
4118 {
4119 *(int *)v23 = v24;
4120 }
4121 else
4122 {
4123 *(int *)v23 = 0;
4124 viewparams->bRedrawGameUI = 1;
4125 }
4126 }
4127 v25 = (int)&v21->field_E4;
4128 if ( v21->field_E4 )
4129 {
4130 v26 = *(int *)v25 - v60;
4131 if ( v26 > 0 )
4132 {
4133 *(int *)v25 = v26;
4134 }
4135 else
4136 {
4137 *(int *)v25 = 0;
4138 viewparams->bRedrawGameUI = 1;
4139 }
4140 }
4141 v27 = (int)&v21->field_E8;
4142 if ( v21->field_E8 )
4143 {
4144 v28 = *(int *)v27 - v60;
4145 if ( v28 > 0 )
4146 {
4147 *(int *)v27 = v28;
4148 }
4149 else
4150 {
4151 *(int *)v27 = 0;
4152 viewparams->bRedrawGameUI = 1;
4153 }
4154 }
4155 v29 = (int)&v21->field_EC;
4156 if ( v21->field_EC )
4157 {
4158 v30 = *(int *)v29 - v60;
4159 if ( v30 > 0 )
4160 {
4161 *(int *)v29 = v30;
4162 }
4163 else
4164 {
4165 *(int *)v29 = 0;
4166 viewparams->bRedrawGameUI = 1;
4167 }
4168 }
4169 v31 = (int)&v21->field_F0;
4170 if ( v21->field_F0 )
4171 {
4172 v32 = *(int *)v31 - v60;
4173 if ( v32 > 0 )
4174 {
4175 *(int *)v31 = v32;
4176 }
4177 else
4178 {
4179 *(int *)v31 = 0;
4180 viewparams->bRedrawGameUI = 1;
4181 }
4182 }
4183 v33 = (int)&v21->field_F4;
4184 if ( v21->field_F4 )
4185 {
4186 v34 = *(int *)v33 - v60;
4187 if ( v34 > 0 )
4188 {
4189 *(int *)v33 = v34;
4190 }
4191 else
4192 {
4193 *(int *)v33 = 0;
4194 viewparams->bRedrawGameUI = 1;
4195 }
4196 }
4197 v35 = (int)&v21->field_F8;
4198 if ( v21->field_F8 )
4199 {
4200 v36 = *(int *)v35 - v60;
4201 if ( v36 > 0 )
4202 {
4203 *(int *)v35 = v36;
4204 }
4205 else
4206 {
4207 *(int *)v35 = 0;
4208 viewparams->bRedrawGameUI = 1;
4209 }
4210 }
4211 v37 = (int)&v21->field_FC;
4212 if ( v21->field_FC )
4213 {
4214 v38 = *(int *)v37 - v60;
4215 if ( v38 > 0 )
4216 {
4217 *(int *)v37 = v38;
4218 }
4219 else
4220 {
4221 *(int *)v37 = 0;
4222 viewparams->bRedrawGameUI = 1;
4223 }
4224 }
4225 v39 = (int)&v21->field_100;
4226 if ( v21->field_100 )
4227 {
4228 v40 = *(int *)v39 - v60;
4229 if ( v40 > 0 )
4230 {
4231 *(int *)v39 = v40;
4232 }
4233 else
4234 {
4235 *(int *)v39 = 0;
4236 viewparams->bRedrawGameUI = 1;
4237 }
4238 }
4239 v41 = (int)&v21->field_104;
4240 if ( v21->field_104 )
4241 {
4242 v42 = *(int *)v41 - v60;
4243 if ( v42 > 0 )
4244 {
4245 *(int *)v41 = v42;
4246 }
4247 else
4248 {
4249 *(int *)v41 = 0;
4250 viewparams->bRedrawGameUI = 1;
4251 }
4252 }
4253 if ( v21->pConditions[2] | v21->pConditions[12] | v21->pConditions[13] | v21->pConditions[14] | v21->pConditions[15] | v21->pConditions[16] )
4254 --v65;
4255 v43 = (signed __int64)v21->pPlayerBuffs[7].uExpireTime > 0;
4256 v44 = v21->pPlayerBuffs;
4257 v45 = 24;
4258 do
4259 {
4260 v44->_4585CA(pParty->uTimePlayed);
4261 ++v44;
4262 --v45;
4263 }
4264 while ( v45 );
4265 if ( v43 && (signed __int64)v21->pPlayerBuffs[7].uExpireTime <= 0 )
4266 v21->SetCondition(1u, 0);
4267 ++v62;
4268 }
4269 while ( (signed int)v62 <= (signed int)&pPlayers[4] );
4270 v46 = (signed __int64)pParty->pPartyBuffs[8].uExpireTime > 0;
4271 v47 = pParty->pPartyBuffs;
4272 do
4273 {
4274 if ( v47->_4585CA(pParty->uTimePlayed) == 1 )
4275 viewparams->bRedrawGameUI = 1;
4276 ++v47;
4277 }
4278 while ( (signed int)v47 < (signed int)pParty->pPlayers );
4279 if ( v46 && (signed __int64)pParty->pPartyBuffs[8].uExpireTime <= 0 )
4280 {
4281 v48 = &pPlayers[1];
4282 do
4283 {
4284 (*v48)->SetCondition(1u, 0);
4285 ++v48;
4286 }
4287 while ( (signed int)v48 <= (signed int)&pPlayers[4] );
4288 }
4289 v49 = (signed int)dword_4EE07C;
4290 do
4291 {
4292 v50 = (char *)&pParty->pPartyBuffs[*(int *)v49];
4293 if ( *(_QWORD *)v50 > 0i64 )
4294 {
4295 if ( !(v50[15] & 1) )
4296 {
4297 if ( !pPlayers[(unsigned __int8)v50[14]]->CanAct() )
4298 {
4299 ((SpellBuff *)v50)->Reset();
4300 if ( *(int *)v49 == 7 )
4301 pParty->bFlying = 0;
4302 }
4303 }
4304 }
4305 v49 += 4;
4306 }
4307 while ( v49 < (signed int)&unk_4EE084 );
4308 v51 = v65;
4309 if ( v65 )
4310 goto LABEL_135;
4311 if ( uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions != 5 )
4312 {
4313 v52 = (signed int)&pPlayers[1];
4314 while ( 1 )
4315 {
4316 v53 = *(int *)v52;
4317 if ( *(_QWORD *)(*(int *)v52 + 16) )
4318 break;
4319 v52 += 4;
4320 if ( v52 > (signed int)&pPlayers[4] )
4321 goto LABEL_135;
4322 }
4323 *(int *)(v53 + 16) = 0;
4324 *(int *)(v53 + 20) = 0;
4325 v51 = 1;
4326 LABEL_135:
4327 if ( uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions != 5
4328 && (!v51 || dword_5C35C0) )
4329 uGameState = 8;
4330 }
4331 if ( uActiveCharacter )
4332 {
4333 if ( uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions != 5 )
4334 {
4335 v54 = pPlayers[uActiveCharacter];
4336 if ( v54->pConditions[2]
4337 || v54->pConditions[12]
4338 || v54->pConditions[13]
4339 || v54->pConditions[14]
4340 || v54->pConditions[15]
4341 || v54->pConditions[16] )
4342 {
4343 viewparams->bRedrawGameUI = 1;
4344 uActiveCharacter = pParty->GetNextActiveCharacter();
4345 }
4346 }
4347 }
4348 }
4349
4350 //----- (00494820) --------------------------------------------------------
4351 unsigned int __fastcall sub_494820(unsigned int a1)
4352 {
4353 signed int v1; // eax@1
4354
4355 v1 = 5;
4356 if ( a1 % 0x18 >= 5 )
4357 v1 = 29;
4358 return v1 - a1 % 0x18;
4359 }
4360
4361 //----- (00494836) --------------------------------------------------------
4362 int stru339_spell_sound::_494836(int uSoundID, int a6)
4363 {
4364 int v3; // esi@1
4365 int result; // eax@1
4366 stru339_spell_sound *v5; // ebx@1
4367 int *v6; // edi@2
4368 unsigned int v7; // eax@3
4369 int v8; // [sp+Ch] [bp-8h]@3
4370 int v9; // [sp+10h] [bp-4h]@2
4371 int a2a; // [sp+1Ch] [bp+8h]@1
4372
4373 v3 = 0;
4374 result = word_4EE088_sound_ids[uSoundID];
4375 v5 = this;
4376 a2a = word_4EE088_sound_ids[uSoundID];
4377 if ( result )
4378 {
4379 v9 = 0;
4380 v6 = this->pSoundsOffsets;
4381 do
4382 {
4383 v7 = a2a++;
4384 result = pSoundList->LoadSound(v7, (char *)v5 + v3, 44744 - v3, &v8, a6);
4385 if ( !result )
4386 break;
4387 a6 += 4;
4388 result = v8 + 256;
4389 *v6 = v3;
4390 v3 += result;
4391 ++v9;
4392 *(v6 - 2) = result;
4393 ++v6;
4394 }
4395 while ( v9 < 2 );
4396 }
4397 return result;
4398 }
4399 // 4EE088: using guessed type __int16 word_4EE088_sound_ids[];
4400
4401
4402
4403 //----- (00494AED) --------------------------------------------------------
4404 unsigned int PlayerFrameTable::GetFrameIdBy_field0(int uField0)
4405 {
4406 unsigned int _uNumFrames; // edx@1
4407 unsigned int result; // eax@1
4408 PlayerFrame *v4; // ecx@2
4409
4410 _uNumFrames = this->uNumFrames;
4411 result = 0;
4412 if ( (signed int)this->uNumFrames <= 0 )
4413 {
4414 LABEL_5:
4415 result = 0;
4416 }
4417 else
4418 {
4419 v4 = this->pFrames;
4420 while ( v4->uSequenceID != uField0 )
4421 {
4422 ++result;
4423 ++v4;
4424 if ( (signed int)result >= (signed int)_uNumFrames )
4425 goto LABEL_5;
4426 }
4427 }
4428 return result;
4429 }
4430
4431 //----- (00494B10) --------------------------------------------------------
4432 PlayerFrame *PlayerFrameTable::GetFrameBy_x(unsigned int uFramesetID, unsigned int uFrameID)
4433 {
4434 unsigned int v3; // esi@1
4435 PlayerFrame *v4; // edi@1
4436 PlayerFrame *v5; // ecx@1
4437 __int16 v6; // dx@2
4438 int v7; // edx@3
4439 char *i; // eax@3
4440 int v9; // ecx@5
4441 PlayerFrame *result; // eax@6
4442
4443 v3 = uFramesetID;
4444 v4 = this->pFrames;
4445 v5 = &v4[uFramesetID];
4446 if ( v5->uFlags & 1 && (v6 = v5->uAnimLength) != 0 )
4447 {
4448 v7 = ((signed int)uFrameID >> 3) % (unsigned __int16)v6;
4449 for ( i = (char *)&v5->uAnimTime; ; i += 10 )
4450 {
4451 v9 = *(short *)i;
4452 if ( v7 <= v9 )
4453 break;
4454 v7 -= v9;
4455 ++v3;
4456 }
4457 result = &v4[v3];
4458 }
4459 else
4460 {
4461 result = &v4[uFramesetID];
4462 }
4463 return result;
4464 }
4465
4466 //----- (00494B5E) --------------------------------------------------------
4467 PlayerFrame *PlayerFrameTable::GetFrameBy_y(int *a2, int *a3, int a4)
4468 {
4469 PlayerFrameTable *v4; // edi@1
4470 int v5; // esi@1
4471 int v6; // eax@2
4472
4473 v4 = this;
4474 v5 = a4 + *a3;
4475 if ( v5 < 8 * this->pFrames[*a2].uAnimTime )
4476 {
4477 *a3 = v5;
4478 }
4479 else
4480 {
4481 v6 = rand() % 4 + 21;
4482 *a2 = v6;
4483 *a3 = 8 * v5 % v4->pFrames[v6].uAnimTime;
4484 }
4485 return &v4->pFrames[*a2];
4486 }
4487
4488 //----- (00494BC3) --------------------------------------------------------
4489 void PlayerFrameTable::ToFile()
4490 {
4491 PlayerFrameTable *v1; // esi@1
4492 FILE *v2; // eax@1
4493 FILE *v3; // edi@1
4494
4495 auto Str = this;
4496
4497 v1 = Str;
4498 v2 = fopen("data\\dpft.bin", "wb");
4499 v3 = v2;
4500 if ( !v2 )
4501 Abortf("Unable to save dpft.bin!");
4502 fwrite(v1, 4u, 1u, v2);
4503 fwrite(v1->pFrames, 0xAu, v1->uNumFrames, v3);
4504 fclose(v3);
4505 }
4506
4507 //----- (00494C0F) --------------------------------------------------------
4508 void PlayerFrameTable::FromFile(void *pSerialized)
4509 {
4510 uNumFrames = *(int *)pSerialized;
4511 pFrames = (PlayerFrame *)pAllocator->AllocNamedChunk(pFrames, 10 * uNumFrames, "P Frames");
4512 memcpy(pFrames, (char *)pSerialized + 4, 10 * uNumFrames);
4513 }
4514
4515 //----- (00494C5A) --------------------------------------------------------
4516 int PlayerFrameTable::FromFileTxt(const char *Args)
4517 {
4518 PlayerFrameTable *v2; // ebx@1
4519 FILE *v3; // eax@1
4520 int v4; // esi@3
4521 void *v5; // eax@10
4522 FILE *v6; // ST0C_4@12
4523 char *i; // eax@12
4524 __int16 v8; // ax@15
4525 const char *v9; // ST10_4@15
4526 unsigned __int16 v10; // ax@15
4527 const char *v11; // ST0C_4@15
4528 int j; // esi@15
4529 int v13; // eax@17
4530 int v14; // edx@22
4531 int v15; // ecx@23
4532 int v16; // eax@24
4533 signed int k; // eax@27
4534 PlayerFrame *v18; // edx@28
4535 int v19; // esi@28
4536 int l; // ecx@29
4537 char Buf; // [sp+Ch] [bp-2F8h]@3
4538 FrameTableTxtLine v23; // [sp+200h] [bp-104h]@4
4539 FrameTableTxtLine v24; // [sp+27Ch] [bp-88h]@4
4540 int v25; // [sp+2F8h] [bp-Ch]@3
4541 int v26; // [sp+2FCh] [bp-8h]@3
4542 FILE *File; // [sp+300h] [bp-4h]@1
4543 int Argsa; // [sp+30Ch] [bp+8h]@28
4544
4545 v2 = this;
4546 //TileTable::dtor((TileTable *)this);
4547 v3 = fopen(Args, "r");
4548 File = v3;
4549 if ( !v3 )
4550 Abortf("PlayerFrameTable::load - Unable to open file: %s.", Args);
4551 v4 = 0;
4552 v25 = 0;
4553 v26 = 1;
4554 if ( fgets(&Buf, 490, v3) )
4555 {
4556 do
4557 {
4558 *strchr(&Buf, 10) = 0;
4559 memcpy(&v24, texture_frame_table_txt_parser(&Buf, &v23), sizeof(v24));
4560 if ( v24.field_0 && *v24.pProperties[0] != 47 )
4561 {
4562 if ( v24.field_0 < 3 )
4563 Abortf("PlayerFrameTable::load, too few arguments, %s line %i.", Args, v26);
4564 ++v25;
4565 }
4566 ++v26;
4567 }
4568 while ( fgets(&Buf, 490, File) );
4569 v4 = v25;
4570 }
4571 v2->uNumFrames = v4;
4572 v5 = pAllocator->AllocNamedChunk(v2->pFrames, 10 * v4, "P Frames");
4573 v2->pFrames = (PlayerFrame *)v5;
4574 if ( !v5 )
4575 Abortf("PlayerFrameTable::load - Out of Memory!");
4576 v6 = File;
4577 v2->uNumFrames = 0;
4578 fseek(v6, 0, 0);
4579 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
4580 {
4581 *strchr(&Buf, 10) = 0;
4582 memcpy(&v24, texture_frame_table_txt_parser(&Buf, &v23), sizeof(v24));
4583 if ( v24.field_0 && *v24.pProperties[0] != 47 )
4584 {
4585 v8 = atoi(v24.pProperties[0]);
4586 v9 = v24.pProperties[1];
4587 v2->pFrames[v2->uNumFrames].uSequenceID = v8;
4588 v10 = atoi(v9);
4589 v11 = v24.pProperties[2];
4590 v2->pFrames[v2->uNumFrames].uTextureID = v10;
4591 v2->pFrames[v2->uNumFrames].uAnimTime = atoi(v11);
4592 v2->pFrames[v2->uNumFrames].uAnimLength = 0;
4593 v2->pFrames[v2->uNumFrames].uFlags = 0;
4594 for ( j = 3; j < v24.field_0; ++j )
4595 {
4596 if ( !_strcmpi(v24.pProperties[j], "New") )
4597 {
4598 v13 = (int)&v2->pFrames[v2->uNumFrames].uFlags;
4599 *(char *)v13 |= 4u;
4600 }
4601 }
4602 ++v2->uNumFrames;
4603 }
4604 }
4605 fclose(File);
4606 v14 = 0;
4607 if ( (signed int)(v2->uNumFrames - 1) > 0 )
4608 {
4609 v15 = 0;
4610 do
4611 {
4612 v16 = (int)&v2->pFrames[v15];
4613 if ( !(*(char *)(v16 + 18) & 4) )
4614 *(char *)(v16 + 8) |= 1u;
4615 ++v14;
4616 ++v15;
4617 }
4618 while ( v14 < (signed int)(v2->uNumFrames - 1) );
4619 }
4620 for ( k = 0; k < (signed int)v2->uNumFrames; *(short *)(Argsa + 6) = v19 )
4621 {
4622 v18 = v2->pFrames;
4623 Argsa = (int)&v18[k];
4624 v19 = *(short *)(Argsa + 4);
4625 if ( *(char *)(Argsa + 8) & 1 )
4626 {
4627 ++k;
4628 for ( l = (int)&v18[k]; *(char *)(l + 8) & 1; l += 10 )
4629 {
4630 v19 += *(short *)(l + 4);
4631 ++k;
4632 }
4633 LOWORD(v19) = v18[k].uAnimTime + v19;
4634 }
4635 ++k;
4636 }
4637 return 1;
4638 }
4639
4640 //----- (00494F3A) --------------------------------------------------------
4641 unsigned int IconFrameTable::FindIcon(const char *pIconName)
4642 {
4643 IconFrameTable *v2; // esi@1
4644 int v3; // ebx@1
4645 unsigned int uID; // edi@1
4646 unsigned int result; // eax@4
4647
4648 v2 = this;
4649 v3 = 0;
4650 uID = 0;
4651 if ( (signed int)this->uNumIcons <= 0 )
4652 {
4653 LABEL_4:
4654 result = 0;
4655 }
4656 else
4657 {
4658 while ( _strcmpi(pIconName, v2->pIcons[v3].pAnimationName) )
4659 {
4660 ++uID;
4661 ++v3;
4662 if ( (signed int)uID >= (signed int)v2->uNumIcons )
4663 goto LABEL_4;
4664 }
4665 result = uID;
4666 }
4667 return result;
4668 }
4669
4670 //----- (00494F70) --------------------------------------------------------
4671 IconFrame *IconFrameTable::GetFrame(unsigned int uIconID, unsigned int uFrameID)
4672 {
4673 IconFrame *v3; // edi@1
4674 IconFrame *v4; // ecx@1
4675 __int16 v5; // dx@2
4676 int v6; // edx@3
4677 unsigned int v7; // eax@3
4678 char *i; // ecx@3
4679 int v9; // esi@5
4680 IconFrame *result; // eax@6
4681
4682 v3 = this->pIcons;
4683 v4 = &v3[uIconID];
4684 if ( v4->uFlags & 1 && (v5 = v4->uAnimLength) != 0 )
4685 {
4686 v6 = ((signed int)uFrameID >> 3) % (unsigned __int16)v5;
4687 v7 = uIconID;
4688 for ( i = (char *)&v4->uAnimTime; ; i += 32 )
4689 {
4690 v9 = *(short *)i;
4691 if ( v6 <= v9 )
4692 break;
4693 v6 -= v9;
4694 ++v7;
4695 }
4696 result = &v3[v7];
4697 }
4698 else
4699 {
4700 result = &v3[uIconID];
4701 }
4702 return result;
4703 }
4704
4705 //----- (00494FBF) --------------------------------------------------------
4706 void IconFrameTable::InitializeAnimation(unsigned int uIconID)
4707 {
4708 IconFrameTable *v2; // esi@1
4709 unsigned int v3; // edi@3
4710 const char *i; // eax@3
4711 IconFrame *v5; // eax@5
4712
4713 v2 = this;
4714 if ( (signed int)uIconID <= (signed int)this->uNumIcons && (uIconID & 0x80000000u) == 0 )
4715 {
4716 v3 = uIconID;
4717 for ( i = this->pIcons[uIconID].pTextureName; ; i = v5[v3].pTextureName )
4718 {
4719 v2->pIcons[v3].uTextureID = pIcons_LOD->LoadTexture(i, TEXTURE_16BIT_PALETTE);
4720 v5 = v2->pIcons;
4721 if ( !(v5[v3].uFlags & 1) )
4722 break;
4723 ++v3;
4724 }
4725 }
4726 }
4727
4728 //----- (0049500A) --------------------------------------------------------
4729 void IconFrameTable::ToFile()
4730 {
4731 IconFrameTable *v1; // esi@1
4732 FILE *v2; // eax@1
4733 FILE *v3; // edi@1
4734
4735 auto Str = this;
4736
4737 v1 = Str;
4738 v2 = fopen("data\\dift.bin", "wb");
4739 v3 = v2;
4740 if ( !v2 )
4741 Abortf("Unable to save dift.bin!");
4742 fwrite(v1, 4u, 1u, v2);
4743 fwrite(v1->pIcons, 0x20u, v1->uNumIcons, v3);
4744 fclose(v3);
4745 }
4746
4747 //----- (00495056) --------------------------------------------------------
4748 void IconFrameTable::FromFile(void *pSerialized)
4749 {
4750 uNumIcons = *(int *)pSerialized;
4751 pIcons = (IconFrame *)pAllocator->AllocNamedChunk(pIcons, 32 * uNumIcons, "I Frames");
4752 memcpy(pIcons, (char *)pSerialized + 4, 32 * uNumIcons);
4753 }
4754
4755 //----- (0049509D) --------------------------------------------------------
4756 int IconFrameTable::FromFileTxt(const char *Args)
4757 {
4758 IconFrameTable *v2; // ebx@1
4759 FILE *v3; // eax@1
4760 int v4; // esi@3
4761 void *v5; // eax@10
4762 FILE *v6; // ST0C_4@12
4763 char *i; // eax@12
4764 const char *v8; // ST00_4@15
4765 int v9; // eax@16
4766 int v10; // edx@20
4767 int v11; // ecx@21
4768 int v12; // eax@22
4769 signed int j; // edx@25
4770 IconFrame *v14; // ecx@26
4771 int v15; // esi@26
4772 int k; // eax@27
4773 signed int result; // eax@11
4774 char Buf; // [sp+Ch] [bp-2F8h]@3
4775 FrameTableTxtLine v19; // [sp+200h] [bp-104h]@4
4776 FrameTableTxtLine v20; // [sp+27Ch] [bp-88h]@4
4777 int v21; // [sp+2F8h] [bp-Ch]@3
4778 int v22; // [sp+2FCh] [bp-8h]@3
4779 FILE *File; // [sp+300h] [bp-4h]@1
4780 int Argsa; // [sp+30Ch] [bp+8h]@26
4781
4782 v2 = this;
4783 //TileTable::dtor((TileTable *)this);
4784 v3 = fopen(Args, "r");
4785 File = v3;
4786 if ( !v3 )
4787 Abortf("IconFrameTable::load - Unable to open file: %s.", Args);
4788 v4 = 0;
4789 v21 = 0;
4790 v22 = 1;
4791 if ( fgets(&Buf, 490, v3) )
4792 {
4793 do
4794 {
4795 *strchr(&Buf, 10) = 0;
4796 memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20));
4797 if ( v20.field_0 && *v20.pProperties[0] != 47 )
4798 {
4799 if ( v20.field_0 < 3 )
4800 Abortf("IconFrameTable::loadText, too few arguments, %s line %i.", Args, v22);
4801 ++v21;
4802 }
4803 ++v22;
4804 }
4805 while ( fgets(&Buf, 490, File) );
4806 v4 = v21;
4807 }
4808 v2->uNumIcons = v4;
4809 v5 = pAllocator->AllocNamedChunk(v2->pIcons, 32 * v4, "I Frames");
4810 v2->pIcons = (IconFrame *)v5;
4811 if ( v5 )
4812 {
4813 v6 = File;
4814 v2->uNumIcons = 0;
4815 fseek(v6, 0, 0);
4816 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
4817 {
4818 *strchr(&Buf, 10) = 0;
4819 memcpy(&v20, frame_table_txt_parser(&Buf, &v19), sizeof(v20));
4820 if ( v20.field_0 && *v20.pProperties[0] != 47 )
4821 {
4822 strcpy(v2->pIcons[v2->uNumIcons].pAnimationName, v20.pProperties[0]);
4823 strcpy(v2->pIcons[v2->uNumIcons].pTextureName, v20.pProperties[1]);
4824 v8 = v20.pProperties[2];
4825 v2->pIcons[v2->uNumIcons].uFlags = 0;
4826 if ( !_strcmpi(v8, "new") )
4827 {
4828 v9 = (int)&v2->pIcons[v2->uNumIcons].uFlags;
4829 *(char *)v9 |= 4u;
4830 }
4831 v2->pIcons[v2->uNumIcons].uAnimTime = atoi(v20.pProperties[3]);
4832 v2->pIcons[v2->uNumIcons].uAnimLength = 0;
4833 v2->pIcons[v2->uNumIcons++].uTextureID = 0;
4834 }
4835 }
4836 fclose(File);
4837 v10 = 0;
4838 if ( (signed int)(v2->uNumIcons - 1) > 0 )
4839 {
4840 v11 = 0;
4841 do
4842 {
4843 v12 = (int)&v2->pIcons[v11];
4844 if ( !(*(char *)(v12 + 60) & 4) )
4845 *(char *)(v12 + 28) |= 1u;
4846 ++v10;
4847 ++v11;
4848 }
4849 while ( v10 < (signed int)(v2->uNumIcons - 1) );
4850 }
4851 for ( j = 0; j < (signed int)v2->uNumIcons; *(short *)(Argsa + 26) = v15 )
4852 {
4853 v14 = v2->pIcons;
4854 Argsa = (int)&v14[j];
4855 v15 = *(short *)(Argsa + 24);
4856 if ( *(char *)(Argsa + 28) & 1 )
4857 {
4858 ++j;
4859 for ( k = (int)&v14[j]; *(char *)(k + 28) & 1; k += 32 )
4860 {
4861 v15 += *(short *)(k + 24);
4862 ++j;
4863 }
4864 LOWORD(v15) = v14[j].uAnimTime + v15;
4865 }
4866 ++j;
4867 }
4868 result = 1;
4869 }
4870 else
4871 {
4872 fclose(File);
4873 result = 0;
4874 }
4875 return result;
4876 }
4877
4878
4879
4880 //----- (00495366) --------------------------------------------------------
4881 char *__fastcall sub_495366(unsigned __int8 a1, unsigned __int8 a2)
4882 {
4883 int v2; // edi@1
4884 int v3; // edx@2
4885 int v4; // esi@3
4886 int v5; // ebx@5
4887 signed int v7; // [sp+Ch] [bp-14h]@1
4888 signed int v8; // [sp+10h] [bp-10h]@1
4889 int **v9; // [sp+14h] [bp-Ch]@4
4890 signed int v10; // [sp+18h] [bp-8h]@3
4891 unsigned __int8 v11; // [sp+1Ch] [bp-4h]@1
4892
4893 v2 = a1;
4894 v11 = a2;
4895 v8 = 0;
4896 v7 = 0;
4897 if ( dword_AE336C == a1 )
4898 {
4899 v3 = dword_AE3370;
4900 }
4901 else
4902 {
4903 v4 = a2;
4904 dword_AE336C = a1;
4905 v10 = 0;
4906 if ( (signed int)pNPCStats->uNumNPCNames[v4] <= 0 )
4907 goto LABEL_17;
4908 v9 = (int **)((char *)pNPCStats->pNPCNames + v4 * 4);
4909 do
4910 {
4911 v5 = tolower(*(char *)*v9);
4912 if ( v5 == tolower(v2) )
4913 {
4914 if ( v8 )
4915 v7 = v10;
4916 else
4917 v8 = v10;
4918 }
4919 ++v10;
4920 v9 += 2;
4921 }
4922 while ( v10 < (signed int)pNPCStats->uNumNPCNames[v4] );
4923 if ( v8 && v8 != v7 )
4924 v3 = v8 + rand() % (v7 - v8);
4925 else
4926 LABEL_17:
4927 v3 = rand() % (signed int)pNPCStats->uNumNPCNames[v4];
4928 }
4929 dword_AE3370 = v3;
4930 return pNPCStats->pNPCNames[0][v11 + 2 * v3];
4931 }
4932 // AE336C: using guessed type int dword_AE336C;
4933 // AE3370: using guessed type int dword_AE3370;
4934
4935 //----- (00495430) --------------------------------------------------------
4936 char *__fastcall GetReputationString(signed int a1)
4937 {
4938 char *result; // eax@2
4939
4940 if ( a1 < 25 )
4941 {
4942 if ( a1 < 6 )
4943 {
4944 if ( a1 < -5 )
4945 {
4946 result = pGlobalTXT_LocalizationStrings[402];
4947 if ( a1 < -24 )
4948 result = pGlobalTXT_LocalizationStrings[434];
4949 }
4950 else
4951 {
4952 result = pGlobalTXT_LocalizationStrings[399];
4953 }
4954 }
4955 else
4956 {
4957 result = pGlobalTXT_LocalizationStrings[392];
4958 }
4959 }
4960 else
4961 {
4962 result = pGlobalTXT_LocalizationStrings[379];
4963 }
4964 return result;
4965 }
4966
4967 //----- (00495461) --------------------------------------------------------
4968 char *__fastcall sub_495461(char *lpsz, unsigned __int8 uPlayerID, ItemGen *a3, char *a4, int a5, __int64 *a6)
4969 {
4970 unsigned __int8 v6; // bl@1
4971 Player *pPlayer; // ebx@3
4972 NPCData *v9; // eax@4
4973 size_t v10; // eax@6
4974 char *v11; // esi@7
4975 int v12; // edx@7
4976 ItemGen *v13; // edi@7
4977 char v14; // cl@8
4978 char *v15; // ecx@10
4979 int v16; // edx@10
4980 int v17; // eax@10
4981 signed __int64 v18; // qax@18
4982 unsigned int v19; // edi@32
4983 unsigned __int8 *v20; // ebx@32
4984 int v21; // ecx@34
4985 __int16 v22; // ax@34
4986 int v23; // edx@39
4987 int v24; // eax@39
4988 int v25; // eax@45
4989 float *v26; // esi@68
4990 float v27; // ST18_4@68
4991 signed int v28; // eax@68
4992 int v29; // eax@68
4993 float v30; // ST18_4@72
4994 signed int v31; // eax@72
4995 float v32; // ST18_4@74
4996 signed int v33; // eax@74
4997 double v34; // st7@75
4998 float v35; // ST18_4@76
4999 signed int v36; // eax@76
5000 float *v37; // esi@78
5001 float v38; // ST18_4@78
5002 int v39; // eax@78
5003 float v40; // ST18_4@82
5004 int v41; // eax@82
5005 float v42; // ST18_4@83
5006 int v43; // eax@83
5007 float v44; // ST18_4@85
5008 int v45; // eax@85
5009 const char *v46; // eax@86
5010 unsigned int v47; // eax@87
5011 float v48; // ST18_4@97
5012 __int64 v49; // ST14_8@107
5013 int v50; // eax@107
5014 int v51; // eax@108
5015 Player *v52; // eax@109
5016 int v53; // [sp-4h] [bp-13Ch]@107
5017 int v54; // [sp+0h] [bp-138h]@107
5018 __int16 v55[56]; // [sp+10h] [bp-128h]@34
5019 stru351 v56; // [sp+80h] [bp-B8h]@107
5020 stru351 v57; // [sp+9Ch] [bp-9Ch]@115
5021 char a1[100]; // [sp+B8h] [bp-80h]@3
5022 unsigned int v59; // [sp+11Ch] [bp-1Ch]@3
5023 size_t v60; // [sp+120h] [bp-18h]@3
5024 Player *v61; // [sp+124h] [bp-14h]@3
5025 char *Str; // [sp+128h] [bp-10h]@1
5026 int v63; // [sp+12Ch] [bp-Ch]@32
5027 int v64; // [sp+130h] [bp-8h]@6
5028 NPCData *v65; // [sp+134h] [bp-4h]@6
5029
5030 v6 = uPlayerID;
5031 Str = lpsz;
5032 if ( IsBadStringPtrA(lpsz, 1u) )
5033 return "Invalid String Passed";
5034 v60 = strlen(Str);
5035 a1[0] = 0;
5036 pPlayer = &pParty->pPlayers[v6];
5037 v59 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
5038 v61 = pPlayer;
5039 memset(pTmpBuf2, 0, 0x7D0u);
5040 if ( dword_5C35D4 )
5041 v9 = array_5913D8[(unsigned int)((char *)array_5913D8[6] + -(dword_591080 != 0) - 1)];
5042 else
5043 v9 = GetNPCData(uDialogue_SpeakingActorNPC_ID);
5044 v65 = v9;
5045 v10 = 0;
5046 v64 = 0;
5047 if ( (signed int)v60 > 0 )
5048 {
5049 v11 = a4;
5050 v12 = v64;
5051 v13 = a3;
5052 while ( 1 )
5053 {
5054 v14 = Str[v12];
5055 if ( v14 == 37 )
5056 break;
5057 pTmpBuf2[v10++] = v14;
5058 LABEL_119:
5059 ++v12;
5060 v64 = v12;
5061 if ( v12 >= (signed int)v60 )
5062 return pTmpBuf2;
5063 }
5064 v15 = &Str[v12 + 1];
5065 v16 = (unsigned __int8)Str[v12 + 2];
5066 v17 = v16 + 10 * (unsigned __int8)*v15 - 528;
5067 if ( v17 <= 15 )
5068 {
5069 if ( v17 != 15 )
5070 {
5071 switch ( v16 + 10 * (unsigned __int8)*v15 )
5072 {
5073 case 0x211:
5074 v11 = v65->pName;
5075 goto LABEL_118;
5076 case 0x212:
5077 v11 = pPlayer->pName;
5078 goto LABEL_118;
5079 case 0x213:
5080 case 0x219:
5081 if ( v65->uSex )
5082 v11 = pGlobalTXT_LocalizationStrings[384];// "her"
5083 else
5084 v11 = pGlobalTXT_LocalizationStrings[383];// "his"
5085 goto LABEL_118;
5086 case 0x215:
5087 v18 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60 / 60 % 24;
5088 v11 = pGlobalTXT_LocalizationStrings[397];// "evening"
5089 if ( SHIDWORD(v18) <= 0 && SHIDWORD(v18) >= 0 && (unsigned int)v18 >= 5 && SHIDWORD(v18) <= 0 )
5090 {
5091 if ( SHIDWORD(v18) >= 0 && (unsigned int)v18 >= 0xB )
5092 {
5093 if ( v18 < 20 )
5094 v11 = pGlobalTXT_LocalizationStrings[396];// "day"
5095 }
5096 else
5097 {
5098 v11 = pGlobalTXT_LocalizationStrings[395];// "morning"
5099 }
5100 }
5101 goto LABEL_118;
5102 case 0x216:
5103 if ( pPlayer->uSex )
5104 v11 = pGlobalTXT_LocalizationStrings[387];// "lady"
5105 else
5106 v11 = pGlobalTXT_LocalizationStrings[385];// "sir"
5107 goto LABEL_118;
5108 case 0x217:
5109 if ( pPlayer->uSex )
5110 goto LABEL_43;
5111 v11 = pGlobalTXT_LocalizationStrings[386];// "Sir"
5112 goto LABEL_118;
5113 case 0x218:
5114 v19 = 0;
5115 v63 = 0;
5116 v20 = (unsigned __int8 *)v61->field_152;
5117 do
5118 {
5119 if ( (unsigned __int16)_449B57_test_bit(v20, word_4EE150[v19]) )
5120 {
5121 v21 = v63;
5122 v22 = word_4EE150[v19];
5123 ++v63;
5124 v55[v21] = v22;
5125 }
5126 ++v19;
5127 }
5128 while ( v19 < 28 );
5129 if ( v63 )
5130 {
5131 v23 = rand() % v63;
5132 v24 = dword_A74CDC;
5133 if ( dword_A74CDC == -1 )
5134 {
5135 v24 = v23;
5136 dword_A74CDC = v23;
5137 }
5138 v11 = (char *)dword_723E80_award_related[2 * v55[v24]];
5139 }
5140 else
5141 {
5142 v11 = (char *)dword_721824;
5143 }
5144 pPlayer = v61;
5145 v13 = a3;
5146 goto LABEL_118;
5147 case 0x21A:
5148 if ( pPlayer->uSex )
5149 LABEL_43:
5150 v11 = pGlobalTXT_LocalizationStrings[389];// "Lady"
5151 else
5152 v11 = pGlobalTXT_LocalizationStrings[388];// "Lord"
5153 goto LABEL_118;
5154 case 0x21B:
5155 v25 = GetPartyReputation();
5156 goto LABEL_46;
5157 case 0x21C:
5158 v25 = v65->rep;
5159 LABEL_46:
5160 if ( v25 >= 25 )
5161 {
5162 v11 = pGlobalTXT_LocalizationStrings[379];
5163 }
5164 else
5165 {
5166 if ( v25 < 6 )
5167 {
5168 if ( v25 >= -5 )
5169 {
5170 v11 = pGlobalTXT_LocalizationStrings[399];
5171 }
5172 else
5173 {
5174 if ( v25 < -24 )
5175 v11 = pGlobalTXT_LocalizationStrings[434];
5176 else
5177 v11 = pGlobalTXT_LocalizationStrings[402];
5178 }
5179 }
5180 else
5181 {
5182 v11 = pGlobalTXT_LocalizationStrings[392];
5183 }
5184 }
5185 goto LABEL_118;
5186 case 0x21D:
5187 v11 = sub_495366(pPlayer->pName[0], pPlayer->uSex);
5188 goto LABEL_118;
5189 case 0x21E:
5190 goto LABEL_93;
5191 case 0x214:
5192 goto LABEL_117;
5193 default:
5194 goto LABEL_108;
5195 }
5196 goto LABEL_108;
5197 }
5198 v11 = pGlobalTXT_LocalizationStrings[393];// "daughter"
5199 LABEL_118:
5200 strcat(pTmpBuf2, v11);
5201 v10 = strlen(pTmpBuf2);
5202 v64 += 2;
5203 v12 = v64;
5204 goto LABEL_119;
5205 }
5206 if ( v17 <= 29 )
5207 {
5208 if ( v17 == 29 )
5209 {
5210 //v34 = p2DEvents_minus1__20[13 * (signed int)a4];
5211 v34 = p2DEvents[(signed int)a4 - 1].fPriceMultiplier;
5212 }
5213 else
5214 {
5215 if ( v16 + 10 * (unsigned __int8)*v15 == 544 )
5216 {
5217 LABEL_93:
5218 if ( v65->uSex )
5219 v11 = pGlobalTXT_LocalizationStrings[391];// "sister"
5220 else
5221 v11 = pGlobalTXT_LocalizationStrings[390];// "brother"
5222 goto LABEL_118;
5223 }
5224 if ( v16 + 10 * (unsigned __int8)*v15 == 545 )
5225 {
5226 v29 = *(&pNPCStats->field_13A58 + 5 * v65->uProfession) / 100;
5227 goto LABEL_91;
5228 }
5229 if ( v16 + 10 * (unsigned __int8)*v15 == 551 )
5230 {
5231 v47 = pMapStats->GetMapInfo(pCurrentMapName);
5232 if ( v47 )
5233 v11 = pMapStats->pInfos[v47].pName;
5234 else
5235 v11 = pGlobalTXT_LocalizationStrings[394];// "Unknown"
5236 goto LABEL_118;
5237 }
5238 if ( v16 + 10 * (unsigned __int8)*v15 == 552 )
5239 {
5240 v46 = v13->GetDisplayName();
5241 sprintfex(a1, format_4E2D80, v59, v46);
5242 LABEL_117:
5243 v11 = a1;
5244 goto LABEL_118;
5245 }
5246 if ( v16 + 10 * (unsigned __int8)*v15 == 553 )
5247 {
5248 //v37 = &p2DEvents_minus1__20[13 * (signed int)a4];
5249 v37 = &p2DEvents[(signed int)a4 - 1].fPriceMultiplier;
5250 v38 = *v37;
5251 v39 = v13->GetValue();
5252 v29 = pPlayer->_4B8233(v39, v38);
5253 switch ( a5 )
5254 {
5255 case 3:
5256 v44 = *v37;
5257 v45 = v13->GetValue();
5258 v29 = pPlayer->_4B8213(v45, v44);
5259 break;
5260 case 4:
5261 v29 = pPlayer->_4B824B(*v37);
5262 break;
5263 case 5:
5264 v42 = *v37;
5265 v43 = v13->GetValue();
5266 v29 = pPlayer->_4B8265(v43, v42);
5267 break;
5268 case 6:
5269 v40 = *v37;
5270 v41 = v13->GetValue();
5271 v29 = pPlayer->_4B8213(v41, v40) / 2;
5272 break;
5273 }
5274 goto LABEL_98;
5275 }
5276 if ( v16 + 10 * (unsigned __int8)*v15 != 555 )
5277 {
5278 if ( v16 + 10 * (unsigned __int8)*v15 == 556 )
5279 {
5280 //v11 = (char *)p2DEvents_minus1__10[13 * (signed int)a4];
5281 v11 = (char *)p2DEvents[(signed int)a4 - 1].pProprieterTitle;
5282 goto LABEL_118;
5283 }
5284 LABEL_108:
5285 strncpy(a1, v15, 2u);
5286 v51 = atoi(a1);
5287 sprintfex(a1, "%lu", v51);
5288 goto LABEL_117;
5289 }
5290 v26 = &p2DEvents[(signed int)a4 - 1].fPriceMultiplier;
5291 v27 = *v26;
5292 v28 = v13->GetValue();
5293 v29 = pPlayer->_4B8142(v28, v27);
5294 if ( a5 == 3 )
5295 {
5296 v35 = *v26;
5297 v36 = v13->GetValue();
5298 v29 = pPlayer->_4B8102(v36, v35);
5299 if ( v13->uAttributtes & 2 )
5300 {
5301 LABEL_77:
5302 v29 = 1;
5303 goto LABEL_98;
5304 }
5305 goto LABEL_98;
5306 }
5307 if ( a5 != 4 )
5308 {
5309 if ( a5 == 5 )
5310 {
5311 v32 = *v26;
5312 v33 = v13->GetValue();
5313 v29 = pPlayer->_4B81C3(v33, v32);
5314 }
5315 else
5316 {
5317 if ( a5 == 6 )
5318 {
5319 v30 = *v26;
5320 v31 = v13->GetValue();
5321 v29 = pPlayer->_4B8102(v31, v30) / 2;
5322 if ( v13->uAttributtes & 2 )
5323 v29 = 1;
5324 LABEL_91:
5325 if ( v29 >= 1 )
5326 goto LABEL_98;
5327 goto LABEL_77;
5328 }
5329 }
5330 LABEL_98:
5331 sprintfex(a1, "%lu", v29);
5332 goto LABEL_117;
5333 }
5334 v34 = *v26;
5335 }
5336 v48 = v34;
5337 v29 = pPlayer->_4B8179(v48);
5338 goto LABEL_98;
5339 }
5340 if ( v17 != 30 )
5341 {
5342 switch ( v17 )
5343 {
5344 case 31:
5345 v52 = pPlayers[1];
5346 break;
5347 case 32:
5348 v52 = pPlayers[2];
5349 break;
5350 case 33:
5351 v52 = pPlayers[3];
5352 break;
5353 default:
5354 if ( v17 != 34 )
5355 {
5356 if ( v17 <= 50 || v17 > 70 )
5357 goto LABEL_108;
5358 if ( v16 + 10 * (unsigned __int8)*v15 - 579 >= 20 )
5359 goto LABEL_118;
5360 HIDWORD(v49) = pParty->field_3C.field_440[2 * v17 + 1];
5361 LODWORD(v49) = pParty->field_3C.field_440[2 * v17];
5362 sub_493F79(&v56, v49);
5363 v54 = v56.field_18;
5364 v53 = v56.field_C + 1;
5365 v50 = v56.field_14;
5366 LABEL_116:
5367 sprintfex(a1, pGlobalTXT_LocalizationStrings[378], aMonthNames[v50], v53, v54);
5368 goto LABEL_117;
5369 }
5370 v52 = pPlayers[4];
5371 break;
5372 }
5373 v11 = v52->pName;
5374 goto LABEL_118;
5375 }
5376 if ( !a6 )
5377 goto LABEL_118;
5378 sub_493F79(&v57, *a6);
5379 v54 = v57.field_18;
5380 v53 = v57.field_C + 1;
5381 v50 = v57.field_14;
5382 goto LABEL_116;
5383 }
5384 return pTmpBuf2;
5385 }
5386
5387 //----- (00495B39) --------------------------------------------------------
5388 void __cdecl PlayerCreationUI_Draw()
5389 {
5390 Texture *v0; // edi@1
5391 const char *v1; // ST10_4@3
5392 int v2; // eax@3
5393 IconFrame *v3; // eax@3
5394 int v4; // ecx@7
5395 GUIButton *v5; // edi@12
5396 int v6; // esi@14
5397 int v7; // eax@14
5398 char v8; // al@17
5399 int v9; // ecx@17
5400 char v10; // sf@17
5401 int v11; // ecx@19
5402 void *v12; // eax@20
5403 int v13; // ecx@21
5404 int v14; // ecx@22
5405 char *v15; // ST14_4@24
5406 size_t v16; // eax@28
5407 int v17; // eax@33
5408 enum CHARACTER_RACE v18; // eax@35
5409 int v19; // eax@36
5410 int v20; // eax@37
5411 int v21; // ST0C_4@44
5412 int v22; // eax@44
5413 int v23; // eax@44
5414 unsigned int v24; // eax@44
5415 int v25; // eax@44
5416 unsigned int v26; // eax@44
5417 int v27; // eax@44
5418 unsigned int v28; // eax@44
5419 int v29; // eax@44
5420 unsigned int v30; // eax@44
5421 int v31; // eax@44
5422 unsigned int v32; // eax@44
5423 int v33; // eax@44
5424 unsigned int v34; // eax@44
5425 int v35; // eax@44
5426 unsigned int v36; // eax@44
5427 enum PLAYER_SKILL_TYPE v37; // eax@44
5428 int v38; // eax@44
5429 enum PLAYER_SKILL_TYPE v39; // eax@44
5430 int v40; // eax@44
5431 enum PLAYER_SKILL_TYPE v41; // eax@44
5432 const char *v42; // edx@44
5433 char *v43; // ST1C_4@44
5434 int v44; // eax@44
5435 int v45; // eax@44
5436 enum PLAYER_SKILL_TYPE v46; // eax@46
5437 const char *v47; // edx@46
5438 char *v48; // ST1C_4@46
5439 int v49; // eax@46
5440 int v50; // eax@46
5441 int v51; // eax@49
5442 char *v52; // edi@52
5443 char v53; // al@52
5444 int v54; // edi@53
5445 int v55; // ST0C_4@53
5446 int v56; // eax@53
5447 int v57; // eax@53
5448 const char *v58; // ST10_4@55
5449 unsigned int v59; // ST0C_4@55
5450 int v60; // eax@55
5451 int v61; // ecx@55
5452 const char *v62; // ST10_4@57
5453 unsigned int v63; // ST0C_4@57
5454 int v64; // ST08_4@57
5455 int v65; // eax@57
5456 int v66; // ecx@57
5457 const char *v67; // ST10_4@59
5458 unsigned int v68; // ST0C_4@59
5459 int v69; // ST08_4@59
5460 int v70; // eax@59
5461 int v71; // eax@59
5462 const char *v72; // ST10_4@61
5463 unsigned int v73; // ST0C_4@61
5464 int v74; // eax@61
5465 int v75; // eax@61
5466 const char *v76; // ST10_4@63
5467 unsigned int v77; // ST0C_4@63
5468 int v78; // ST08_4@63
5469 int v79; // eax@63
5470 int v80; // eax@63
5471 const char *v81; // ST10_4@65
5472 unsigned int v82; // ST0C_4@65
5473 int v83; // ST08_4@65
5474 int v84; // eax@65
5475 int v85; // eax@65
5476 const char *v86; // ST10_4@67
5477 unsigned int v87; // ST0C_4@67
5478 int v88; // eax@67
5479 int v89; // eax@67
5480 const char *v90; // ST10_4@69
5481 unsigned int v91; // ST0C_4@69
5482 int v92; // ST08_4@69
5483 int v93; // eax@69
5484 int v94; // eax@69
5485 const char *v95; // ST10_4@71
5486 unsigned int v96; // ST0C_4@71
5487 int v97; // ST08_4@71
5488 int v98; // eax@71
5489 const char *v99; // ST10_4@71
5490 int v100; // ST0C_4@71
5491 int v101; // eax@71
5492 enum PLAYER_SKILL_TYPE v102; // edi@72
5493 size_t v103; // eax@72
5494 signed int v104; // ecx@72
5495 int v105; // ecx@79
5496 int v106; // edi@81
5497 unsigned int v107; // ST0C_4@81
5498 int v108; // ST08_4@81
5499 int v109; // eax@81
5500 const char *v110; // ST10_4@82
5501 int v111; // ST0C_4@82
5502 int v112; // eax@82
5503 signed int v113; // edi@82
5504 int v114; // ST0C_4@82
5505 int v115; // eax@82
5506 const char *v116; // [sp+0h] [bp-170h]@39
5507 char Str1[200]; // [sp+10h] [bp-160h]@14
5508 GUIWindow v118; // [sp+D8h] [bp-98h]@83
5509 int v119; // [sp+12Ch] [bp-44h]@18
5510 size_t v120; // [sp+130h] [bp-40h]@25
5511 int uY; // [sp+134h] [bp-3Ch]@18
5512 int v122; // [sp+138h] [bp-38h]@18
5513 int v123; // [sp+13Ch] [bp-34h]@11
5514 void *v124; // [sp+140h] [bp-30h]@18
5515 int uColor1; // [sp+144h] [bp-2Ch]@1
5516 int v126; // [sp+148h] [bp-28h]@25
5517 int uColorGreen; // [sp+14Ch] [bp-24h]@1
5518 int v128; // [sp+150h] [bp-20h]@14
5519 int v129; // [sp+154h] [bp-1Ch]@18
5520 int uColorTeal; // [sp+158h] [bp-18h]@1
5521 int uColorWhite; // [sp+15Ch] [bp-14h]@1
5522 int uX; // [sp+160h] [bp-10h]@18
5523 unsigned int v133; // [sp+164h] [bp-Ch]@25
5524 int v134; // [sp+168h] [bp-8h]@14
5525 char *Str; // [sp+16Ch] [bp-4h]@18
5526
5527 uColor1 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xD1u, 0xBBu, 0x61u);
5528 uColorTeal = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0, 0xF7u, 0xF7u);
5529 uColorGreen = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0, 0xFFu, 0);
5530 uColorWhite = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
5531 pRenderer->BeginScene();
5532 pRenderer->DrawTextureRGB(0, 0, &stru_506F20);
5533 v0 = pTexture_MAKESKY;
5534 pRenderer->DrawTextureIndexed(uPlayerCreationUI_SkySliderPos, 2u, pTexture_MAKESKY);
5535 pRenderer->DrawTextureIndexed(uPlayerCreationUI_SkySliderPos++ - 640, 2u, v0);
5536 if ( (signed int)uPlayerCreationUI_SkySliderPos > 640 )
5537 uPlayerCreationUI_SkySliderPos = 0;
5538 pRenderer->DrawTextureTransparent(0, 0, pTexture_MAKETOP);
5539 v1 = pGlobalTXT_LocalizationStrings[51];
5540 uPlayerCreationUI_SelectedCharacter = (pGUIWindow_CurrentMenu->field_2C_focus_id - pGUIWindow_CurrentMenu->field_38)
5541 / 7;
5542 v2 = pFontCChar->AlignText_Center(0x280u, pGlobalTXT_LocalizationStrings[51]);
5543 pGUIWindow_CurrentMenu->DrawText(pFontCChar, v2 + 1, 0, 0, v1, 0, 0, 0);
5544 pRenderer->DrawTextureTransparent(17u, 35u, pPlayerPortraits[(char)pParty->pPlayers[0].uFace]);
5545 pRenderer->DrawTextureTransparent(176u, 35u, pPlayerPortraits[(char)pParty->pPlayers[1].uFace]);
5546 pRenderer->DrawTextureTransparent(335u, 35u, pPlayerPortraits[(char)pParty->pPlayers[2].uFace]);
5547 pRenderer->DrawTextureTransparent(494u, 35u, pPlayerPortraits[(char)pParty->pPlayers[3].uFace]);
5548 v3 = pIconsFrameTable->GetFrame(uIconID_CharacterFrame, pEventTimer->uStartTime);
5549 if ( uPlayerCreationUI_SelectedCharacter )
5550 {
5551 switch ( uPlayerCreationUI_SelectedCharacter )
5552 {
5553 case 1u:
5554 v4 = 171;
5555 break;
5556 case 2u:
5557 v4 = 329;
5558 break;
5559 case 3u:
5560 v4 = 488;
5561 break;
5562 default:
5563 v4 = v123;
5564 break;
5565 }
5566 }
5567 else
5568 {
5569 v4 = 12;
5570 }
5571 pRenderer->DrawTextureTransparent(v4, 0x1Du, &pIcons_LOD->pTextures[v3->uTextureID]);
5572 v5 = pGUIWindow_CurrentMenu->GetControl(pGUIWindow_CurrentMenu->field_2C_focus_id);
5573 pRenderer->DrawTextureTransparent(v5->uZ - 4, v5->uY, pTextures_arrowl[uPlayerCreationUI_ArrowAnim + 1]);
5574 pRenderer->DrawTextureTransparent(v5->uX - 12, v5->uY, pTextures_arrowr[uPlayerCreationUI_ArrowAnim-- + 1]);
5575 if ( uPlayerCreationUI_ArrowAnim < 0 )
5576 uPlayerCreationUI_ArrowAnim = 18;
5577 v6 = LOBYTE(pFontCreate->uFontHeight) - 2;
5578 v128 = LOBYTE(pFontCreate->uFontHeight) - 2;
5579 strcpy(Str1, pGlobalTXT_LocalizationStrings[205]);// "Skills"
5580 v7 = strlen(Str1) - 1;
5581 v134 = v7;
5582 if ( v7 >= 0 )
5583 {
5584 while ( 1 )
5585 {
5586 v8 = toupper((unsigned __int8)Str1[v7]);
5587 v9 = v134;
5588 v10 = v134-- - 1 < 0;
5589 Str1[v9] = v8;
5590 if ( v10 )
5591 break;
5592 v7 = v134;
5593 }
5594 }
5595 v134 = 18;
5596 v124 = 0;
5597 uX = 32;
5598 uY = 3 * v6 + 169;
5599 v122 = 5 * v6 + 169;
5600 v123 = 3 * v6 + 311;
5601 v129 = 493;
5602 Str = pParty->pPlayers[0].pName;
5603 v119 = 6 * v6 + 169;
5604 do
5605 {
5606 pGUIWindow_CurrentMenu->DrawText(
5607 pFontCreate,
5608 v134 + 73,
5609 100,
5610 0,
5611 pClassNames[(unsigned __int8)Str[17]],
5612 0,
5613 0,
5614 0);
5615 pRenderer->DrawTextureTransparent(
5616 v134 + 77,
5617 50u,
5618 *(&pTexture_IC_KNIGHT + ((unsigned int)(unsigned __int8)Str[17] >> 2)));
5619 v11 = pGUIWindow_CurrentMenu->field_40;
5620 if ( v11 && (v12 = pGUIWindow_CurrentMenu->ptr_1C, v12 == v124) )
5621 {
5622 v13 = v11 - 1;
5623 if ( v13 )
5624 {
5625 v14 = v13 - 1;
5626 if ( v14 )
5627 {
5628 if ( v14 == 1 )
5629 {
5630 v15 = Str;
5631 pGUIWindow_CurrentMenu->field_40 = 0;
5632 pGUIWindow_CurrentMenu->DrawTextInRect(pFontCreate, v134, 124u, 0, v15, 130, 0);
5633 SetCurrentMenuID(7u);
5634 }
5635 }
5636 else
5637 {
5638 pGUIWindow_CurrentMenu->field_40 = 0;
5639 v120 = strlen((const char *)pKeyActionMap->pPressedKeysBuffer);
5640 v126 = 0;
5641 v133 = 0;
5642 if ( strlen((const char *)pKeyActionMap->pPressedKeysBuffer) )
5643 {
5644 do
5645 {
5646 if ( pKeyActionMap->pPressedKeysBuffer[v133] == ' ' )
5647 ++v126;
5648 ++v133;
5649 v16 = strlen((const char *)pKeyActionMap->pPressedKeysBuffer);
5650 }
5651 while ( v133 < v16 );
5652 }
5653 if ( v120 && v126 != v120 )
5654 strcpy(Str, (const char *)pKeyActionMap->pPressedKeysBuffer);
5655 pGUIWindow_CurrentMenu->DrawTextInRect(pFontCreate, v134, 0x7Cu, 0, Str, 130, 0);
5656 *((short *)Str + 3323) = 1;
5657 }
5658 }
5659 else
5660 {
5661 v17 = pGUIWindow_CurrentMenu->DrawTextInRect(
5662 pFontCreate,
5663 159 * (int)v12 + 18,
5664 0x7Cu,
5665 0,
5666 (const char *)pKeyActionMap->pPressedKeysBuffer,
5667 120,
5668 1);
5669 pGUIWindow_CurrentMenu->DrawFlashingInputCursor(
5670 159 * (unsigned int)pGUIWindow_CurrentMenu->ptr_1C + v17 + 20,
5671 124,
5672 pFontCreate);
5673 }
5674 }
5675 else
5676 {
5677 pGUIWindow_CurrentMenu->DrawTextInRect(pFontCreate, v134, 0x7Cu, 0, Str, 130, 0);
5678 }
5679 v18 = ((Player *)(Str - 168))->GetRace();
5680 if ( v18 )
5681 {
5682 v19 = v18 - 1;
5683 if ( v19 )
5684 {
5685 v20 = v19 - 1;
5686 if ( v20 )
5687 {
5688 if ( v20 != 1 )
5689 goto LABEL_44;
5690 v116 = pGlobalTXT_LocalizationStrings[101];// "Dwarf"
5691 }
5692 else
5693 {
5694 v116 = pGlobalTXT_LocalizationStrings[106];// "Goblin"
5695 }
5696 }
5697 else
5698 {
5699 v116 = pGlobalTXT_LocalizationStrings[103];// "Elf"
5700 }
5701 }
5702 else
5703 {
5704 v116 = pGlobalTXT_LocalizationStrings[99];// "Human"
5705 }
5706 strcpy(pTmpBuf, v116);
5707 LABEL_44:
5708 pGUIWindow_CurrentMenu->DrawTextInRect(pFontCreate, v134 + 72, v128 + 12, 0, pTmpBuf, 130, 0);
5709 v21 = uColor1;
5710 v22 = pFontCreate->AlignText_Center(0x96u, Str1);
5711 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v22 + uX - 24, 291, v21, Str1, 0, 0, 0);
5712 v23 = ((Player *)(Str - 168))->GetActualMight();
5713 sprintfex(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[144], v129, v23);// "Might"
5714 LOWORD(v24) = ((Player *)(Str - 168))->GetStatColor(0);
5715 pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, 169, v24, pTmpBuf, 0, 0, 0);
5716 v25 = ((Player *)(Str - 168))->GetActualIntelligence();
5717 sprintfex(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[116], v129, v25);// "Intellect"
5718 LOWORD(v26) = ((Player *)(Str - 168))->GetStatColor(1u);
5719 pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, v128 + 169, v26, pTmpBuf, 0, 0, 0);
5720 v27 = ((Player *)(Str - 168))->GetActualWillpower();
5721 sprintfex(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[163], v129, v27);// "Personality"
5722 LOWORD(v28) = ((Player *)(Str - 168))->GetStatColor(2u);
5723 pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, 2 * v128 + 169, v28, pTmpBuf, 0, 0, 0);
5724 v29 = ((Player *)(Str - 168))->GetActualEndurance();
5725 sprintfex(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[75], v129, v29);// "Endurance"
5726 LOWORD(v30) = ((Player *)(Str - 168))->GetStatColor(3u);
5727 pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, uY, v30, pTmpBuf, 0, 0, 0);
5728 v31 = ((Player *)(Str - 168))->GetActualAccuracy();
5729 sprintfex(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[1], v129, v31);// "Accuracy"
5730 LOWORD(v32) = ((Player *)(Str - 168))->GetStatColor(4u);
5731 pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, 4 * v128 + 169, v32, pTmpBuf, 0, 0, 0);
5732 v33 = ((Player *)(Str - 168))->GetActualSpeed();
5733 sprintfex(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[211], v129, v33);// "Speed"
5734 LOWORD(v34) = ((Player *)(Str - 168))->GetStatColor(5u);
5735 pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, v122, v34, pTmpBuf, 0, 0, 0);
5736 v35 = ((Player *)(Str - 168))->GetActualLuck();
5737 sprintfex(pTmpBuf, "%s\r%03d%d", pGlobalTXT_LocalizationStrings[136], v129, v35);// "Luck"
5738 LOWORD(v36) = ((Player *)(Str - 168))->GetStatColor(6u);
5739 pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX, v119, v36, pTmpBuf, 0, 0, 0);
5740 v37 = ((Player *)(Str - 168))->GetSkillIdxByOrder(0);
5741 v38 = pFontCreate->AlignText_Center(0x96u, pSkillNames[v37]);
5742 sprintfex(pTmpBuf, "\t%03u%s", v38);
5743 pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX - 24, 311, uColorWhite, pTmpBuf, 0, 0, 0);
5744 v39 = ((Player *)(Str - 168))->GetSkillIdxByOrder(1);
5745 v40 = pFontCreate->AlignText_Center(0x96u, pSkillNames[v39]);
5746 sprintfex(pTmpBuf, "\t%03u%s", v40);
5747 pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX - 24, v128 + 311, uColorWhite, pTmpBuf, 0, 0, 0);
5748 v41 = ((Player *)(Str - 168))->GetSkillIdxByOrder(2);
5749 v42 = pSkillNames[v41];
5750 v43 = pSkillNames[v41];
5751 v133 = v41;
5752 v44 = pFontCreate->AlignText_Center(150u, v42);
5753 sprintfex(pTmpBuf, "\t%03u%s", v44, v43);
5754 v45 = uColorGreen;
5755 if ( (signed int)v133 >= 37 )
5756 v45 = uColorTeal;
5757 pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX - 24, 2 * v128 + 311, v45, pTmpBuf, 0, 0, 0);
5758 v46 = ((Player *)(Str - 168))->GetSkillIdxByOrder(3);
5759 v47 = pSkillNames[v46];
5760 v48 = pSkillNames[v46];
5761 v133 = v46;
5762 v49 = pFontCreate->AlignText_Center(150u, v47);
5763 sprintfex(pTmpBuf, "\t%03u%s", v49, v48);
5764 v50 = uColorGreen;
5765 if ( (signed int)v133 >= 37 )
5766 v50 = uColorTeal;
5767 pGUIWindow_CurrentMenu->DrawText(pFontCreate, uX - 24, v123, v50, pTmpBuf, 0, 0, 0);
5768 Str += 6972;
5769 v124 = (char *)v124 + 1;
5770 v134 += 159;
5771 v129 -= 158;
5772 uX += 158;
5773 }
5774 while ( (signed int)Str < (signed int)&pParty->pPickedItem.uNumCharges );
5775 strcpy(Str1, pGlobalTXT_LocalizationStrings[41]);// "Class"
5776 v51 = strlen(Str1) - 1;
5777 v134 = v51;
5778 if ( v51 >= 0 )
5779 {
5780 while ( 1 )
5781 {
5782 v52 = &Str1[v51];
5783 v53 = toupper((unsigned __int8)Str1[v51]);
5784 v10 = v134-- - 1 < 0;
5785 *v52 = v53;
5786 if ( v10 )
5787 break;
5788 v51 = v134;
5789 }
5790 }
5791 v54 = pParty->pPlayers[uPlayerCreationUI_SelectedCharacter].uClass;
5792 v55 = uColor1;
5793 v133 = pParty->pPlayers[uPlayerCreationUI_SelectedCharacter].uClass;
5794 v56 = pFontCreate->AlignText_Center(193u, Str1);
5795 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v56 + 324, 395, v55, Str1, 0, 0, 0);
5796 v57 = uColorTeal;
5797 if ( v54 )
5798 v57 = uColorWhite;
5799 v58 = pClassNames[0];
5800 v59 = v57;
5801 v60 = pFontCreate->AlignText_Center(65u, pClassNames[0]);
5802 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v60 + 323, 417, v59, v58, 0, 0, 0);
5803 v61 = uColorTeal;
5804 if ( v133 != 12 )
5805 v61 = uColorWhite;
5806 v62 = pClassNames[12];
5807 v63 = v61;
5808 v64 = v128 + 417;
5809 uColorGreen = v128 + 417;
5810 v65 = pFontCreate->AlignText_Center(65u, pClassNames[12]);
5811 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v65 + 323, v64, v63, v62, 0, 0, 0);
5812 v66 = uColorTeal;
5813 if ( v133 != 20 )
5814 v66 = uColorWhite;
5815 v67 = pClassNames[20];
5816 v68 = v66;
5817 v69 = 2 * v128 + 417;
5818 v126 = 2 * v128 + 417;
5819 v70 = pFontCreate->AlignText_Center(65u, pClassNames[20]);
5820 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v70 + 323, v69, v68, v67, 0, 0, 0);
5821 v71 = uColorTeal;
5822 if ( v133 != PLAYER_CLASS_CLERIC )
5823 v71 = uColorWhite;
5824 v72 = pClassNames[24];
5825 v73 = v71;
5826 v74 = pFontCreate->AlignText_Center(65u, pClassNames[24]);
5827 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v74 + 388, 417, v73, v72, 0, 0, 0);
5828 v75 = uColorTeal;
5829 if ( v133 != 28 )
5830 v75 = uColorWhite;
5831 v76 = pClassNames[28];
5832 v77 = v75;
5833 v78 = uColorGreen;
5834 v79 = pFontCreate->AlignText_Center(65u, pClassNames[28]);
5835 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v79 + 388, v78, v77, v76, 0, 0, 0);
5836 v80 = uColorTeal;
5837 if ( v133 != PLAYER_CLASS_SORCERER )
5838 v80 = uColorWhite;
5839 v81 = pClassNames[32];
5840 v82 = v80;
5841 v83 = v126;
5842 v84 = pFontCreate->AlignText_Center(65u, pClassNames[32]);
5843 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v84 + 388, v83, v82, v81, 0, 0, 0);
5844 v85 = uColorTeal;
5845 if ( v133 != 16 )
5846 v85 = uColorWhite;
5847 v86 = pClassNames[16];
5848 v87 = v85;
5849 v88 = pFontCreate->AlignText_Center(65u, pClassNames[16]);
5850 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v88 + 453, 417, v87, v86, 0, 0, 0);
5851 v89 = uColorTeal;
5852 if ( v133 != 8 )
5853 v89 = uColorWhite;
5854 v90 = pClassNames[8];
5855 v91 = v89;
5856 v92 = uColorGreen;
5857 v93 = pFontCreate->AlignText_Center(65u, pClassNames[8]);
5858 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v93 + 453, v92, v91, v90, 0, 0, 0);
5859 v94 = uColorTeal;
5860 if ( v133 != 4 )
5861 v94 = uColorWhite;
5862 v95 = pClassNames[4];
5863 v96 = v94;
5864 v97 = v126;
5865 v98 = pFontCreate->AlignText_Center(65u, pClassNames[4]);
5866 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v98 + 453, v97, v96, v95, 0, 0, 0);
5867 v99 = pGlobalTXT_LocalizationStrings[20]; // "Available Skills"
5868 v100 = uColor1;
5869 v101 = pFontCreate->AlignText_Center(0xECu, pGlobalTXT_LocalizationStrings[20]);
5870 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v101 + 37, 395, v100, v99, 0, 0, 0);
5871 v134 = 0;
5872 do
5873 {
5874 v102 = pParty->pPlayers[uPlayerCreationUI_SelectedCharacter].GetSkillIdxByOrder(v134 + 4);
5875 strcpy(Str1, pSkillNames[v102]);
5876 v103 = strlen(Str1);
5877 v104 = 0;
5878 if ( (signed int)v103 > 0 )
5879 {
5880 while ( Str1[v104] != 32 )
5881 {
5882 ++v104;
5883 if ( v104 >= (signed int)v103 )
5884 goto LABEL_77;
5885 }
5886 Str1[v104] = 0;
5887 }
5888 LABEL_77:
5889 uColorGreen = -5;
5890 if ( (signed int)v124 <= 3 )
5891 uColorGreen = 0;
5892 v105 = uColorTeal;
5893 if ( !pParty->pPlayers[0].pActiveSkills[v102 + 3486 * uPlayerCreationUI_SelectedCharacter] )
5894 v105 = uColorWhite;
5895 v106 = v134 / 3;
5896 v107 = v105;
5897 v108 = v128 * v134 % 3 + 417;
5898 v109 = pFontCreate->AlignText_Center(100u, Str1);
5899 pGUIWindow_CurrentMenu->DrawText(
5900 pFontCreate,
5901 100 * v106 + v109 + uColorGreen + 17,
5902 v108,
5903 v107,
5904 Str1,
5905 0,
5906 0,
5907 0);
5908 ++v134;
5909 }
5910 while ( v134 < 9 );
5911 v110 = pGlobalTXT_LocalizationStrings[30]; // "Bonus"
5912 v111 = uColor1;
5913 v112 = pFontCreate->AlignText_Center(0x5Cu, pGlobalTXT_LocalizationStrings[30]);
5914 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v112 + 533, 394, v111, v110, 0, 0, 0);
5915 v113 = PlayerCreation_ComputeAttributeBonus();
5916 sprintfex(pTmpBuf, "%d", v113);
5917 v114 = uColorWhite;
5918 v115 = pFontCreate->AlignText_Center(84u, pTmpBuf);
5919 pGUIWindow_CurrentMenu->DrawText(pFontCreate, v115 + 530, 410, v114, pTmpBuf, 0, 0, 0);
5920 if ( GameUI_StatusBar_TimedStringTimeLeft > GetTickCount() )
5921 {
5922 v118.str_48 = pGlobalTXT_LocalizationStrings[412];// "Create Party cannot be completed unless you have assigned all characters 2 extra skills and have spent all of your bonus points."
5923 if ( v113 < 0 )
5924 v118.str_48 = pGlobalTXT_LocalizationStrings[413];// "You can't spend more than 50 points."
5925 v118.uFrameWidth = 300;
5926 v118.uFrameHeight = 100;
5927 v118.uFrameX = 170;
5928 v118.uFrameY = 140;
5929 v118.uFrameZ = 469;
5930 v118.uFrameW = 239;
5931 v118._415551(0);
5932 }
5933 pRenderer->EndScene();
5934 }
5935
5936 //----- (0049695A) --------------------------------------------------------
5937 void __cdecl PlayerCreationUI_Initialize()
5938 {
5939 unsigned int v0; // ebx@5
5940 unsigned int v1; // eax@6
5941 int v2; // ecx@6
5942 unsigned int v3; // eax@8
5943 signed int v4; // ecx@8
5944 signed int uControlParam; // [sp+10h] [bp-Ch]@7
5945 unsigned int uControlParama; // [sp+10h] [bp-Ch]@9
5946 unsigned int uControlParamb; // [sp+10h] [bp-Ch]@11
5947 unsigned int uControlParamc; // [sp+10h] [bp-Ch]@13
5948 signed int uControlParamd; // [sp+10h] [bp-Ch]@15
5949 signed int uX; // [sp+14h] [bp-8h]@5
5950 unsigned int uXa; // [sp+14h] [bp-8h]@9
5951 unsigned int uXb; // [sp+14h] [bp-8h]@11
5952 unsigned int uXc; // [sp+14h] [bp-8h]@13
5953 signed int uXd; // [sp+14h] [bp-8h]@16
5954
5955 if ( pMessageQueue_50CBD0->uNumMessages )
5956 pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
5957 pAudioPlayer->SetMusicVolume((signed __int64)(pSoundVolumeLevels[(char)uMusicVolimeMultiplier] * 64.0));
5958 ++pIcons_LOD->uTexturePacksCount;
5959 if ( !pIcons_LOD->uNumPrevLoadedFiles )
5960 pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
5961 uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 21;
5962 uPlayerCreationUI_ArrowAnim = 0;
5963 uPlayerCreationUI_SkySliderPos = 0;
5964 uPlayerCreationUI_SelectedCharacter = 0;
5965 v0 = LOBYTE(pFontCreate->uFontHeight) - 2;
5966 pTexture_IC_KNIGHT = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("IC_KNIGHT", TEXTURE_16BIT_PALETTE)];
5967 pTexture_IC_THIEF = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("IC_THIEF", TEXTURE_16BIT_PALETTE)];
5968 pTexture_IC_MONK = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("IC_MONK", TEXTURE_16BIT_PALETTE)];
5969 pTexture_IC_PALAD = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("IC_PALAD", TEXTURE_16BIT_PALETTE)];
5970 pTexture_IC_ARCH = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("IC_ARCH", TEXTURE_16BIT_PALETTE)];
5971 pTexture_IC_RANGER = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("IC_RANGER", TEXTURE_16BIT_PALETTE)];
5972 pTexture_IC_CLER = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("IC_CLER", TEXTURE_16BIT_PALETTE)];
5973 pTexture_IC_DRUID = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("IC_DRUID", TEXTURE_16BIT_PALETTE)];
5974 pTexture_IC_SORC = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("IC_SORC", TEXTURE_16BIT_PALETTE)];
5975 pTexture_MAKETOP = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("MAKETOP", TEXTURE_16BIT_PALETTE)];
5976 uX = 0;
5977 pTexture_MAKESKY = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("MAKESKY", TEXTURE_16BIT_PALETTE)];
5978 do
5979 {
5980 sprintfex(pTmpBuf, "%s01", pPlayerPortraitsNames[uX]);
5981 v1 = pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE);
5982 v2 = uX * 4;
5983 ++uX;
5984 *(Texture **)((char *)pPlayerPortraits + v2) = &pIcons_LOD->pTextures[v1];
5985 }
5986 while ( uX < 22 );
5987 pTexture_PlayerFaceMask = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("FACEMASK", TEXTURE_16BIT_PALETTE)];
5988 pTexture_buttminu = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("buttminu", TEXTURE_16BIT_PALETTE)];
5989 pTexture_buttplus = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("buttplus", TEXTURE_16BIT_PALETTE)];
5990 pTexture_pressrigh = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("presrigh", TEXTURE_16BIT_PALETTE)];
5991 pTexture_presleft = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("presleft", TEXTURE_16BIT_PALETTE)];
5992 uControlParam = 1;
5993 do
5994 {
5995 sprintfex(pTmpBuf, "arrowl%d", uControlParam);
5996 pTextures_arrowl[uControlParam] = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE)];
5997 sprintfex(pTmpBuf, "arrowr%d", uControlParam);
5998 v3 = pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE);
5999 v4 = uControlParam++;
6000 pTextures_arrowr[v4] = &pIcons_LOD->pTextures[v3];
6001 }
6002 while ( uControlParam < 20 );
6003 pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640u, 480u, WINDOW_Credits, 0, 0);
6004 uControlParama = 0;
6005 uXa = 8;
6006 do
6007 {
6008 pGUIWindow_CurrentMenu->CreateButton(uXa, 120u, 145u, 25u, 1, 0, 0x3Cu, uControlParama, 0, nullstring, 0);
6009 uXa += 158;
6010 ++uControlParama;
6011 }
6012 while ( (signed int)uXa < 640 );
6013 pCreationUI_BtnPressLeft[0] = pGUIWindow_CurrentMenu->CreateButton(
6014 10u,
6015 32u,
6016 11u,
6017 13u,
6018 1,
6019 0,
6020 0xABu,
6021 0,
6022 0,
6023 nullstring,
6024 pTexture_presleft,
6025 0);
6026 pCreationUI_BtnPressLeft[1] = pGUIWindow_CurrentMenu->CreateButton(
6027 169u,
6028 32u,
6029 11u,
6030 13u,
6031 1,
6032 0,
6033 0xABu,
6034 1u,
6035 0,
6036 nullstring,
6037 pTexture_presleft,
6038 0);
6039 pCreationUI_BtnPressLeft[2] = pGUIWindow_CurrentMenu->CreateButton(
6040 327u,
6041 32u,
6042 11u,
6043 13u,
6044 1,
6045 0,
6046 0xABu,
6047 2u,
6048 0,
6049 nullstring,
6050 pTexture_presleft,
6051 0);
6052 pCreationUI_BtnPressLeft[3] = pGUIWindow_CurrentMenu->CreateButton(
6053 486u,
6054 32u,
6055 11u,
6056 13u,
6057 1,
6058 0,
6059 0xABu,
6060 3u,
6061 0,
6062 nullstring,
6063 pTexture_presleft,
6064 0);
6065 pCreationUI_BtnPressRight[0] = pGUIWindow_CurrentMenu->CreateButton(
6066 74u,
6067 32u,
6068 11u,
6069 13u,
6070 1,
6071 0,
6072 0xACu,
6073 0,
6074 0,
6075 nullstring,
6076 pTexture_pressrigh,
6077 0);
6078 pCreationUI_BtnPressRight[1] = pGUIWindow_CurrentMenu->CreateButton(
6079 233u,
6080 32u,
6081 11u,
6082 13u,
6083 1,
6084 0,
6085 0xACu,
6086 1u,
6087 0,
6088 nullstring,
6089 pTexture_pressrigh,
6090 0);
6091 pCreationUI_BtnPressRight[2] = pGUIWindow_CurrentMenu->CreateButton(
6092 391u,
6093 32u,
6094 11u,
6095 13u,
6096 1,
6097 0,
6098 0xACu,
6099 2u,
6100 0,
6101 nullstring,
6102 pTexture_pressrigh,
6103 0);
6104 pCreationUI_BtnPressRight[3] = pGUIWindow_CurrentMenu->CreateButton(
6105 549u,
6106 32u,
6107 11u,
6108 13u,
6109 1,
6110 0,
6111 0xACu,
6112 3u,
6113 0,
6114 nullstring,
6115 pTexture_pressrigh,
6116 0);
6117 pCreationUI_BtnPressLeft2[0] = pGUIWindow_CurrentMenu->CreateButton(
6118 10u,
6119 103u,
6120 11u,
6121 13u,
6122 1,
6123 0,
6124 0x90u,
6125 0,
6126 0,
6127 nullstring,
6128 pTexture_presleft,
6129 0);
6130 pCreationUI_BtnPressLeft2[1] = pGUIWindow_CurrentMenu->CreateButton(
6131 169u,
6132 103u,
6133 11u,
6134 13u,
6135 1,
6136 0,
6137 0x90u,
6138 1u,
6139 0,
6140 nullstring,
6141 pTexture_presleft,
6142 0);
6143 pCreationUI_BtnPressLeft2[2] = pGUIWindow_CurrentMenu->CreateButton(
6144 327u,
6145 103u,
6146 11u,
6147 13u,
6148 1,
6149 0,
6150 0x90u,
6151 2u,
6152 0,
6153 nullstring,
6154 pTexture_presleft,
6155 0);
6156 pCreationUI_BtnPressLeft2[3] = pGUIWindow_CurrentMenu->CreateButton(
6157 486u,
6158 103u,
6159 11u,
6160 13u,
6161 1,
6162 0,
6163 0x90u,
6164 3u,
6165 0,
6166 nullstring,
6167 pTexture_presleft,
6168 0);
6169 pCreationUI_BtnPressRight2[0] = pGUIWindow_CurrentMenu->CreateButton(
6170 74u,
6171 103u,
6172 11u,
6173 13u,
6174 1,
6175 0,
6176 0x91u,
6177 0,
6178 0,
6179 nullstring,
6180 pTexture_pressrigh,
6181 0);
6182 pCreationUI_BtnPressRight2[1] = pGUIWindow_CurrentMenu->CreateButton(
6183 233u,
6184 103u,
6185 11u,
6186 13u,
6187 1,
6188 0,
6189 0x91u,
6190 1u,
6191 0,
6192 nullstring,
6193 pTexture_pressrigh,
6194 0);
6195 pCreationUI_BtnPressRight2[2] = pGUIWindow_CurrentMenu->CreateButton(
6196 391u,
6197 103u,
6198 11u,
6199 13u,
6200 1,
6201 0,
6202 0x91u,
6203 2u,
6204 0,
6205 nullstring,
6206 pTexture_pressrigh,
6207 0);
6208 pCreationUI_BtnPressRight2[3] = pGUIWindow_CurrentMenu->CreateButton(
6209 549u,
6210 103u,
6211 11u,
6212 13u,
6213 1,
6214 0,
6215 0x91u,
6216 3u,
6217 0,
6218 nullstring,
6219 pTexture_pressrigh,
6220 0);
6221 uControlParamb = 0;
6222 uXb = 8;
6223 do
6224 {
6225 pGUIWindow_CurrentMenu->CreateButton(uXb, 308u, 150u, v0, 1, 0, 0x48u, uControlParamb, 0, nullstring, 0);
6226 pGUIWindow_CurrentMenu->CreateButton(
6227 uXb,
6228 v0 + 308,
6229 150u,
6230 v0,
6231 1,
6232 0,
6233 0x49u,
6234 uControlParamb,
6235 0,
6236 nullstring,
6237 0);
6238 pGUIWindow_CurrentMenu->CreateButton(
6239 uXb,
6240 2 * v0 + 308,
6241 150u,
6242 v0,
6243 1,
6244 0,
6245 0x4Au,
6246 uControlParamb,
6247 0,
6248 nullstring,
6249 0);
6250 pGUIWindow_CurrentMenu->CreateButton(
6251 uXb,
6252 3 * v0 + 308,
6253 150u,
6254 v0,
6255 1,
6256 0,
6257 0x4Bu,
6258 uControlParamb,
6259 0,
6260 nullstring,
6261 0);
6262 uXb += 158;
6263 ++uControlParamb;
6264 }
6265 while ( (signed int)uXb < 640 );
6266 pGUIWindow_CurrentMenu->CreateButton(5u, 21u, 0x99u, 0x16Du, 1, 0, 0x76u, 0, 0x31u, nullstring, 0);
6267 pGUIWindow_CurrentMenu->CreateButton(163u, 21u, 0x99u, 0x16Du, 1, 0, 0x76u, 1u, 0x32u, nullstring, 0);
6268 pGUIWindow_CurrentMenu->CreateButton(321u, 21u, 0x99u, 0x16Du, 1, 0, 0x76u, 2u, 0x33u, nullstring, 0);
6269 pGUIWindow_CurrentMenu->CreateButton(479u, 21u, 0x99u, 0x16Du, 1, 0, 0x76u, 3u, 0x34u, nullstring, 0);
6270 uXc = 23;
6271 uControlParamc = 2;
6272 do
6273 {
6274 pGUIWindow_CurrentMenu->CreateButton(uXc, 169u, 120u, 20u, 1, 0, 0, uControlParamc - 2, 0, nullstring, 0);
6275 pGUIWindow_CurrentMenu->CreateButton(
6276 uXc,
6277 v0 + 169,
6278 120u,
6279 20u,
6280 1,
6281 0,
6282 0,
6283 uControlParamc - 1,
6284 0,
6285 nullstring,
6286 0);
6287 pGUIWindow_CurrentMenu->CreateButton(
6288 uXc,
6289 2 * v0 + 169,
6290 120u,
6291 20u,
6292 1,
6293 0,
6294 0,
6295 uControlParamc,
6296 0,
6297 nullstring,
6298 0);
6299 pGUIWindow_CurrentMenu->CreateButton(
6300 uXc,
6301 3 * v0 + 169,
6302 120u,
6303 20u,
6304 1,
6305 0,
6306 0,
6307 uControlParamc + 1,
6308 0,
6309 nullstring,
6310 0);
6311 pGUIWindow_CurrentMenu->CreateButton(
6312 uXc,
6313 4 * v0 + 169,
6314 120u,
6315 20u,
6316 1,
6317 0,
6318 0,
6319 uControlParamc + 2,
6320 0,
6321 nullstring,
6322 0);
6323 pGUIWindow_CurrentMenu->CreateButton(
6324 uXc,
6325 5 * v0 + 169,
6326 120u,
6327 20u,
6328 1,
6329 0,
6330 0,
6331 uControlParamc + 3,
6332 0,
6333 nullstring,
6334 0);
6335 pGUIWindow_CurrentMenu->CreateButton(
6336 uXc,
6337 6 * v0 + 169,
6338 120u,
6339 20u,
6340 1,
6341 0,
6342 0,
6343 uControlParamc + 4,
6344 0,
6345 nullstring,
6346 0);
6347 uControlParamc += 7;
6348 uXc += 158;
6349 }
6350 while ( (signed int)uControlParamc < 30 );
6351 pGUIWindow_CurrentMenu->_41D08F(28, 0, 7, 40);
6352 pGUIWindow_CurrentMenu->CreateButton(323u, 417u, 65u, v0, 1, 0, 0x41u, 0, 0, nullstring, 0);
6353 pGUIWindow_CurrentMenu->CreateButton(323u, v0 + 417, 65u, v0, 1, 0, 0x41u, 0xCu, 0, nullstring, 0);
6354 pGUIWindow_CurrentMenu->CreateButton(323u, 2 * v0 + 417, 65u, v0, 1, 0, 0x41u, 0x14u, 0, nullstring, 0);
6355 pGUIWindow_CurrentMenu->CreateButton(388u, 417u, 65u, v0, 1, 0, 0x41u, 0x18u, 0, nullstring, 0);
6356 pGUIWindow_CurrentMenu->CreateButton(388u, v0 + 417, 65u, v0, 1, 0, 0x41u, 0x1Cu, 0, nullstring, 0);
6357 pGUIWindow_CurrentMenu->CreateButton(388u, 2 * v0 + 417, 65u, v0, 1, 0, 0x41u, 0x20u, 0, nullstring, 0);
6358 pGUIWindow_CurrentMenu->CreateButton(453u, 417u, 65u, v0, 1, 0, 0x41u, 0x10u, 0, nullstring, 0);
6359 pGUIWindow_CurrentMenu->CreateButton(453u, v0 + 417, 65u, v0, 1, 0, 0x41u, 8u, 0, nullstring, 0);
6360 pGUIWindow_CurrentMenu->CreateButton(453u, 2 * v0 + 417, 65u, v0, 1, 0, 0x41u, 4u, 0, nullstring, 0);
6361 uControlParamd = 0;
6362 do
6363 {
6364 uXd = -5;
6365 if ( uControlParamd <= 3 )
6366 uXd = 0;
6367 pGUIWindow_CurrentMenu->CreateButton(
6368 100 * uControlParamd / 3 + uXd + 17,
6369 v0 * uControlParamd % 3 + 417,
6370 100u,
6371 v0,
6372 1,
6373 0,
6374 0x40u,
6375 uControlParamd,
6376 0,
6377 nullstring,
6378 0);
6379 ++uControlParamd;
6380 }
6381 while ( uControlParamd < 9 );
6382 pPlayerCreationUI_BtnOK = pGUIWindow_CurrentMenu->CreateButton(
6383 580u,
6384 431u,
6385 51u,
6386 39u,
6387 1,
6388 0,
6389 0x42u,
6390 0,
6391 0xDu,
6392 nullstring,
6393 (Texture *)(uTextureID_BUTTMAKE != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTMAKE] : 0),
6394 0);
6395 pPlayerCreationUI_BtnReset = pGUIWindow_CurrentMenu->CreateButton(
6396 527u,
6397 431u,
6398 51u,
6399 39u,
6400 1,
6401 0,
6402 0x43u,
6403 0,
6404 0x43u,
6405 nullstring,
6406 (Texture *)(uTextureID_BUTTMAKE2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTMAKE2] : 0),
6407 0);
6408 pPlayerCreationUI_BtnMinus = pGUIWindow_CurrentMenu->CreateButton(
6409 523u,
6410 393u,
6411 20u,
6412 35u,
6413 1,
6414 0,
6415 0x3Fu,
6416 0,
6417 0x2Du,
6418 nullstring,
6419 pTexture_buttminu,
6420 0);
6421 pPlayerCreationUI_BtnPlus = pGUIWindow_CurrentMenu->CreateButton(
6422 613u,
6423 393u,
6424 20u,
6425 35u,
6426 1,
6427 0,
6428 0x3Eu,
6429 1u,
6430 0x2Bu,
6431 nullstring,
6432 pTexture_buttplus,
6433 0);
6434 pFontCChar = LoadFont("cchar.fnt", "FONTPAL", 0);
6435 }
6436 // 4E28F8: using guessed type int uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions;
6437
6438 //----- (0049750E) --------------------------------------------------------
6439 void __cdecl DeleteCCharFont()
6440 {
6441 pAllocator->FreeChunk(pFontCChar);
6442 pFontCChar = 0;
6443 }
6444
6445 //----- (00497526) --------------------------------------------------------
6446 bool __cdecl PlayerCreationUI_Loop()
6447 {
6448 RGBTexture *v0; // ebx@1
6449 UINT v1; // esi@1
6450 unsigned int v2; // ecx@3
6451 LONG uMouseX; // edi@6
6452 LONG uMouseY; // eax@6
6453 GUIButton *v5; // edx@6
6454 unsigned int v6; // ecx@7
6455 int v7; // esi@12
6456 signed int v8; // edi@30
6457 int v9; // edx@31
6458 char *v10; // ebx@37
6459 int v11; // esi@38
6460 signed int v12; // ecx@40
6461 int v13; // eax@40
6462 signed int v14; // eax@45
6463 int v15; // eax@70
6464 signed int v16; // ecx@70
6465 unsigned int v18; // [sp-4h] [bp-84h]@48
6466 ItemGen item; // [sp+Ch] [bp-74h]@37
6467 char v20; // [sp+30h] [bp-50h]@29
6468 char v21; // [sp+31h] [bp-4Fh]@29
6469 __int16 v22; // [sp+4Dh] [bp-33h]@29
6470 char v23; // [sp+4Fh] [bp-31h]@29
6471 MSG Msg; // [sp+50h] [bp-30h]@17
6472 POINT v25; // [sp+6Ch] [bp-14h]@6
6473 bool v26; // [sp+74h] [bp-Ch]@1
6474 POINT v24; // [sp+78h] [bp-8h]@6
6475
6476 v0 = &stru_506F20;
6477 v1 = 0;
6478 v26 = 0;
6479 stru_506F20.Release();
6480 stru_506F20.Load("makeme.pcx", 0);
6481 if ( pAsyncMouse )
6482 pAsyncMouse->Resume();
6483 v2 = 6;
6484 pGUIWindow_CurrentMenu->field_40 = 0;
6485 LABEL_27:
6486 SetCurrentMenuID(v2);
6487 while ( GetCurrentMenuID() == MENU_CREATEPARTY )
6488 {
6489 if ( pAsyncMouse != (void *)v1 )
6490 pAsyncMouse->_46B736_consume_click_lists(1);
6491 uMouseX = pMouse->GetCursorPos(&v24)->x;
6492 uMouseY = pMouse->GetCursorPos(&v25)->y;
6493 v5 = pGUIWindow_CurrentMenu->pControlsHead;
6494 if ( v5 != (GUIButton *)v1 )
6495 {
6496 v6 = pMessageQueue_50CBD0->uNumMessages;
6497 do
6498 {
6499 if ( uMouseX >= (signed int)v5->uX
6500 && uMouseX <= (signed int)v5->uZ
6501 && uMouseY >= (signed int)v5->uY
6502 && uMouseY <= (signed int)v5->uW )
6503 {
6504 v7 = v5->uControlParam;
6505 if ( (signed int)v6 < 40 )
6506 {
6507 pMessageQueue_50CBD0->pMessages[v6].eType = (UIMessageType)v5->field_1C;
6508 v0 = &stru_506F20;
6509 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v7;
6510 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
6511 v6 = pMessageQueue_50CBD0->uNumMessages + 1;
6512 ++pMessageQueue_50CBD0->uNumMessages;
6513 }
6514 v1 = 0;
6515 }
6516 v5 = v5->pNext;
6517 }
6518 while ( v5 != (GUIButton *)v1 );
6519 }
6520 while ( PeekMessageA(&Msg, (HWND)v1, v1, v1, PM_REMOVE) )
6521 {
6522 if ( Msg.message == WM_QUIT )
6523 Game_DeinitializeAndTerminate(0);
6524 TranslateMessage(&Msg);
6525 DispatchMessageA(&Msg);
6526 }
6527 if ( BYTE1(dword_6BE364_game_settings_1) & 1 )
6528 {
6529 WaitMessage();
6530 }
6531 else
6532 {
6533 PlayerCreationUI_Draw();
6534 GUI_MainMenuMessageProc();
6535 pRenderer->BeginScene();
6536 GUI_UpdateWindows();
6537 pRenderer->EndScene();
6538 pRenderer->Present();
6539 if ( uGameState == 1 )
6540 {
6541 v26 = 1;
6542 v2 = 0;
6543 goto LABEL_27;
6544 }
6545 if ( uGameState == 6 )
6546 {
6547 uGameState = v1;
6548 v2 = 1;
6549 goto LABEL_27;
6550 }
6551 }
6552 }
6553 v0->Release();
6554 pGUIWindow_CurrentMenu->Release();
6555 pIcons_LOD->_4114F2();
6556 v20 = 0;
6557 memset(&v21, 0, 0x1Cu);
6558 v22 = 0;
6559 v23 = 0;
6560 do
6561 {
6562 v8 = 0;
6563 do
6564 {
6565 v9 = rand() % 32;
6566 if ( !*(&v20 + v9) )
6567 break;
6568 ++v8;
6569 }
6570 while ( v8 < 10 );
6571 if ( v8 == 10 )
6572 {
6573 v9 = 0;
6574 if ( v20 )
6575 {
6576 do
6577 ++v9;
6578 while ( *(&v20 + v9) );
6579 }
6580 }
6581 pParty->field_854[v1++] = v9;
6582 *(&v20 + v9) = 1;
6583 }
6584 while ( (signed int)v1 < 32 );
6585 item.Reset();
6586 v10 = (char *)&pParty->pPlayers[0].sResMagicBase;
6587 do
6588 {
6589 v11 = (int)(v10 - 6014);
6590 if ( !*(v10 - 5829) )
6591 *(short *)v10 = 10;
6592 *((short *)v10 + 400) = 0;
6593 v12 = 0;
6594 v13 = (int)(v10 - 5726);
6595 while ( !*(short *)v13 )
6596 {
6597 ++v12;
6598 v13 += 2;
6599 if ( v12 >= 9 )
6600 goto LABEL_45;
6601 }
6602 *(char *)(v11 + 6734) = v12;
6603 LABEL_45:
6604 pItemsTable->GenerateItem(2, 40, &item);
6605 ((Player *)(v10 - 6014))->AddItem2(0xFFFFFFFFu, &item);
6606 v14 = 0;
6607 v24.y = 0;
6608 do
6609 {
6610 if ( *(short *)(v11 + 2 * v14 + 264) )
6611 {
6612 switch ( v14 )
6613 {
6614 case 0:
6615 v18 = 61;
6616 goto LABEL_69;
6617 case 1:
6618 v18 = 1;
6619 goto LABEL_69;
6620 case 2:
6621 v18 = 15;
6622 goto LABEL_69;
6623 case 3:
6624 v18 = 23;
6625 goto LABEL_69;
6626 case 4:
6627 v18 = 31;
6628 goto LABEL_69;
6629 case 5:
6630 v18 = 47;
6631 goto LABEL_69;
6632 case 6:
6633 v18 = 50;
6634 goto LABEL_69;
6635 case 8:
6636 v18 = 84;
6637 goto LABEL_69;
6638 case 9:
6639 v18 = 66;
6640 goto LABEL_69;
6641 case 10:
6642 v18 = 71;
6643 goto LABEL_69;
6644 case 11:
6645 v18 = 76;
6646 goto LABEL_69;
6647 case 12:
6648 ((Player *)(v10 - 6014))->AddItem(0xFFFFFFFFu, 0x191u);
6649 *(char *)(v11 + 402) = 1;
6650 break;
6651 case 13:
6652 ((Player *)(v10 - 6014))->AddItem(0xFFFFFFFFu, 0x19Cu);
6653 *(char *)(v11 + 413) = 1;
6654 break;
6655 case 14:
6656 ((Player *)(v10 - 6014))->AddItem(0xFFFFFFFFu, 0x1A7u);
6657 *(char *)(v11 + 424) = 1;
6658 break;
6659 case 15:
6660 ((Player *)(v10 - 6014))->AddItem(0xFFFFFFFFu, 0x1B2u);
6661 *(char *)(v11 + 435) = 1;
6662 break;
6663 case 16:
6664 ((Player *)(v10 - 6014))->AddItem(0xFFFFFFFFu, 0x1BDu);
6665 *(char *)(v11 + 446) = 1;
6666 break;
6667 case 17:
6668 ((Player *)(v10 - 6014))->AddItem(0xFFFFFFFFu, 0x1C8u);
6669 *(char *)(v11 + 457) = 1;
6670 break;
6671 case 18:
6672 ((Player *)(v10 - 6014))->AddItem(0xFFFFFFFFu, 0x1D3u);
6673 *(char *)(v11 + 468) = 1;
6674 break;
6675 case 21:
6676 case 23:
6677 case 25:
6678 case 26:
6679 case 29:
6680 case 36:
6681 ((Player *)(v10 - 6014))->AddItem(0xFFFFFFFFu, 0xDCu);
6682 v18 = 5 * (rand() % 3 + 40);
6683 goto LABEL_69;
6684 case 30:
6685 v18 = 115;
6686 goto LABEL_69;
6687 case 31:
6688 v18 = 110;
6689 LABEL_69:
6690 ((Player *)(v10 - 6014))->AddItem(0xFFFFFFFFu, v18);
6691 break;
6692 default:
6693 break;
6694 }
6695 v15 = v11 + 552;
6696 v16 = 138;
6697 do
6698 {
6699 if ( *(int *)(v15 - 20) )
6700 *(int *)v15 |= 1u;
6701 v15 += 36;
6702 --v16;
6703 }
6704 while ( v16 );
6705 *(int *)(v11 + 6460) = ((Player *)(v10 - 6014))->GetMaxHealth();
6706 *(int *)(v11 + 6464) = ((Player *)(v10 - 6014))->GetMaxMana();
6707 v14 = v24.y;
6708 }
6709 ++v14;
6710 v24.y = v14;
6711 }
6712 while ( v14 < 37 );
6713 v10 += 6972;
6714 }
6715 while ( (signed int)v10 < (signed int)((char *)&pParty->field_871C[455] + 2) );
6716 pAudioPlayer->StopChannels(-1, -1);
6717 if ( pAsyncMouse )
6718 pAsyncMouse->Suspend();
6719 return v26;
6720 }
6721
6722
6723
6724
6725 //----- (004979D2) --------------------------------------------------------
6726 MENU_STATE __cdecl CreditsMenu__Loop()
6727 {
6728 char *v0; // eax@5
6729 char *v1; // edi@5
6730 FILE *v2; // eax@5
6731 unsigned int v3; // esi@7
6732 GUIFont *v4; // edx@9
6733 GUIFont *v5; // ecx@9
6734 __int16 v6; // ax@9
6735 void *v7; // eax@9
6736 unsigned int v8; // ST2C_4@9
6737 unsigned int v9; // eax@9
6738 unsigned int v10; // ST2C_4@19
6739 unsigned int teal; // eax@19
6740 //Texture v12; // [sp+Ch] [bp-130h]@5
6741 //RGBTexture v16; // [sp+54h] [bp-E8h]@1
6742 double v15; // [sp+7Ch] [bp-C0h]@9
6743 MSG Msg; // [sp+84h] [bp-B8h]@10
6744 int v17; // [sp+A0h] [bp-9Ch]@9
6745 int a2; // [sp+A4h] [bp-98h]@9
6746 unsigned int a3; // [sp+A8h] [bp-94h]@9
6747 int v20; // [sp+ACh] [bp-90h]@9
6748 int a4; // [sp+B0h] [bp-8Ch]@9
6749 int a8; // [sp+F8h] [bp-44h]@9
6750 int a7; // [sp+FCh] [bp-40h]@9
6751 //RGBTexture v21; // [sp+100h] [bp-3Ch]@1
6752 int a5; // [sp+128h] [bp-14h]@1
6753 char *pString; // [sp+12Ch] [bp-10h]@9
6754 char *ptr; // [sp+130h] [bp-Ch]@5
6755 GUIFont *pFontQuick; // [sp+134h] [bp-8h]@1
6756 GUIFont *pFontCChar; // [sp+138h] [bp-4h]@1
6757
6758 RGBTexture v16; // [sp+54h] [bp-E8h]@1
6759 //RGBTexture::RGBTexture(&v16);
6760 RGBTexture v21; // [sp+100h] [bp-3Ch]@1
6761 //RGBTexture::RGBTexture(&v21);
6762
6763 a5 = 0;
6764 pFontQuick = LoadFont("quick.fnt", "FONTPAL", 0);
6765 pFontCChar = LoadFont("cchar.fnt", "FONTPAL", 0);
6766 if ( pMessageQueue_50CBD0->uNumMessages )
6767 pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
6768 ++pIcons_LOD->uTexturePacksCount;
6769 if ( !pIcons_LOD->uNumPrevLoadedFiles )
6770 pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
6771 dword_A74C88 = 0;
6772 pAudioPlayer->PlayMusicTrack(0xFu);
6773 v16.Load("mm6title.pcx", 0);
6774 v0 = (char *)pEvents_LOD->LoadRaw("credits.txt", 0);
6775 v1 = v0;
6776 ptr = v0;
6777
6778 Texture v12; // [sp+Ch] [bp-130h]@5
6779 //Texture::Texture(&v12);
6780
6781 v2 = pEvents_LOD->FindContainer("credits.txt", 0);
6782 if ( !v2 )
6783 Abortf(pGlobalTXT_LocalizationStrings[63]); // "Might and Magic VII is having trouble loading files.
6784 // Please re-install to fix this problem. Note: Re-installing will not destroy your save games."
6785 fread(&v12, 1u, 0x30u, v2);
6786 v3 = v12.uDecompressedSize;
6787 if ( !v12.uDecompressedSize )
6788 v3 = v12.uTextureSize;
6789 memset(&v12, 0, 0x48u);
6790 v4 = pFontCChar;
6791 v5 = pFontQuick;
6792 v1[v3] = 0;
6793 v20 = 250;
6794 a4 = 440;
6795 a2 = 389;
6796 a3 = 19;
6797 v21.uWidth = 250;
6798 v6 = v5->GetStringHeight2(v4, v1, (int)&a2, 0, 1);
6799 v21.uHeight = v6 + 2 * a4;
6800 v21.uNumPixels = (signed __int16)v21.uWidth * (signed __int16)v21.uHeight;
6801 v7 = pAllocator->AllocNamedChunk(v21.pPixels, 2 * v21.uNumPixels, "scrollermap");
6802 v8 = v21.uNumPixels;
6803 v21.pPixels = (unsigned __int16 *)v7;
6804 v9 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0, 0xFFu, 0xFFu);
6805 fill_pixels_fast(v9, v21.pPixels, v8);
6806 *(int *)&v21.field_20 = 0;
6807 a7 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0x70u, 0x8Fu, 0xFEu);
6808 a8 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xECu, 0xE6u, 0x9Cu);
6809 pString = (char *)operator new(2 * v3);
6810 strncpy(pString, ptr, v3);
6811 pFontQuick->_44D2FD_prolly_draw_credits_entry(
6812 pFontCChar,
6813 1,
6814 a4 + 1,
6815 (signed __int16)v21.uWidth,
6816 (signed __int16)v21.uHeight,
6817 1u,
6818 1u,
6819 pString,
6820 v21.pPixels,
6821 (signed __int16)v21.uWidth);
6822 strncpy(pString, ptr, v3);
6823 pFontQuick->_44D2FD_prolly_draw_credits_entry(
6824 pFontCChar,
6825 0,
6826 a4,
6827 (signed __int16)v21.uWidth,
6828 (signed __int16)v21.uHeight,
6829 a7,
6830 a8,
6831 pString,
6832 v21.pPixels,
6833 (signed __int16)v21.uWidth);
6834 free(pString);
6835 pWindow_Credits = GUIWindow::Create(0, 0, 640u, 480u, WINDOW_Credits, 0, (int)ptr);
6836 pWindow_Credits->CreateButton(0, 0, 0, 0, 1, 0, 0x71u, 0, 0x1Bu, nullstring, 0);
6837 uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 9;
6838 SetCurrentMenuID(8u);
6839 pRenderer->BeginScene();
6840 pRenderer->DrawTextureRGB(0, 0, &v16);
6841 pRenderer->Clip(a2, a3, a2 + v20, a3 + a4);
6842 pRenderer->_4A5D33(a2, a3, 0, 0, &v21);
6843 pRenderer->ResetClip();
6844 pRenderer->EndScene();
6845 pString = (char *)0x447A0000;
6846 v15 = 1000.0 + 6.7553994e15;
6847 v17 = LODWORD(v15);
6848 GetTickCount();
6849 pRenderer->Present();
6850 do
6851 {
6852 while ( PeekMessageA(&Msg, 0, 0, 0, 1u) )
6853 {
6854 if ( Msg.message == 18 )
6855 Game_DeinitializeAndTerminate(0);
6856 TranslateMessage(&Msg);
6857 DispatchMessageA(&Msg);
6858 }
6859 if ( BYTE1(dword_6BE364_game_settings_1) & 1 )
6860 {
6861 WaitMessage();
6862 }
6863 else
6864 {
6865 if ( pAsyncMouse )
6866 pAsyncMouse->_46B736_consume_click_lists(1);
6867 if ( dword_A74C88 )
6868 {
6869 v16.Load("mm6title.pcx", 1);
6870 v10 = v21.uNumPixels;
6871 teal = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0, 0xFFu, 0xFFu);
6872 fill_pixels_fast(teal, v21.pPixels, v10);
6873 strncpy(pTmpBuf, ptr, 0x7D0u);
6874 pFontQuick->_44D2FD_prolly_draw_credits_entry(
6875 pFontCChar,
6876 1,
6877 a4 + 1,
6878 (signed __int16)v21.uWidth,
6879 (signed __int16)v21.uHeight,
6880 1u,
6881 1u,
6882 pTmpBuf,
6883 v21.pPixels,
6884 (signed __int16)v21.uWidth);
6885 strncpy(pTmpBuf, ptr, 0x7D0u);
6886 pFontQuick->_44D2FD_prolly_draw_credits_entry(
6887 pFontCChar,
6888 0,
6889 a4,
6890 (signed __int16)v21.uWidth,
6891 (signed __int16)v21.uHeight,
6892 a7,
6893 a8,
6894 pTmpBuf,
6895 v21.pPixels,
6896 (signed __int16)v21.uWidth);
6897 dword_A74C88 = 0;
6898 pRenderer->BeginScene();
6899 pRenderer->DrawTextureRGB(0, 0, &v16);
6900 pRenderer->Clip(a2, a3, a2 + v20, a2 + a4);
6901 pRenderer->_4A5D33(a2, a3, 0, a5, &v21);
6902 pRenderer->ResetClip();
6903 pRenderer->EndScene();
6904 pRenderer->Present();
6905 }
6906 timeGetTime();
6907 pRenderer->BeginScene();
6908 pRenderer->DrawTextureRGB(0, 0, &v16);
6909 pRenderer->Clip(a2, a3, a2 + v20, a3 + a4);
6910 pRenderer->_4A5D33(a2, a3, 0, a5, &v21);
6911 pRenderer->ResetClip();
6912 pRenderer->EndScene();
6913 ++a5;
6914 if ( a5 >= (signed __int16)v21.uHeight )
6915 SetCurrentMenuID(0);
6916 timeGetTime();
6917 pRenderer->Present();
6918 GUI_MainMenuMessageProc();
6919 }
6920 }
6921 while ( GetCurrentMenuID() == MENU_Credits );
6922 GUI_MainMenuMessageProc();
6923 pRenderer->BeginScene();
6924 GUI_UpdateWindows();
6925 pRenderer->EndScene();
6926 pRenderer->Present();
6927 pAudioPlayer->_4AA258(1);
6928 pAllocator->FreeChunk(ptr);
6929 pAllocator->FreeChunk(pFontQuick);
6930 pAllocator->FreeChunk(pFontCChar);
6931 pWindow_Credits->Release();
6932 pIcons_LOD->_4114F2();
6933 v16.Release();
6934 v21.Release();
6935 return (MENU_STATE)(GetCurrentMenuID() - (int)MENU_Credits); // return MENU_Main
6936 }
6937
6938
6939
6940
6941 //----- (0049B04D) --------------------------------------------------------
6942 int stru154::_49B04D(ODMFace *a2, BSPVertexBuffer *a3)
6943 {
6944 stru154 *v3; // edi@1
6945 signed int v4; // eax@1
6946 signed int result; // eax@9
6947 signed int v6; // [sp-8h] [bp-18h]@8
6948 Vec3_float_ v; // [sp+4h] [bp-Ch]@1
6949
6950 v.x = 0.0;
6951 v3 = this;
6952 v.y = 0.0;
6953 v.z = 0.0;
6954 _49B13D(a2, a3, &v, (float *)&a3);
6955 v4 = 2;
6956 if ( a2->pFacePlane.vNormal.z )
6957 {
6958 if ( !a2->pFacePlane.vNormal.x && !a2->pFacePlane.vNormal.y )
6959 v4 = 1;
6960 }
6961 else
6962 {
6963 v4 = 0;
6964 }
6965 if ( v4 )
6966 {
6967 if ( v4 == 1 )
6968 v6 = 3;
6969 else
6970 v6 = 4;
6971 result = v6;
6972 }
6973 else
6974 {
6975 result = 1;
6976 }
6977 v3->vNormal.x = v.x;
6978 v3->vNormal.y = v.y;
6979 v3->vNormal.z = v.z;
6980 v3->field_10 = *(float *)&a3;
6981 v3->field_14 = result;
6982 return result;
6983 }
6984
6985 //----- (0049B0C9) --------------------------------------------------------
6986 int stru154::_49B0C9(Vec3_float_ *pNormal, float a3)
6987 {
6988 signed int v3; // esi@1
6989 signed int result; // eax@9
6990 double v5; // st7@12
6991 double v6; // st6@12
6992 double v7; // st5@12
6993 signed int v8; // [sp+0h] [bp-4h]@8
6994
6995 v3 = 2;
6996 if ( pNormal->z == 0.0 )
6997 {
6998 v3 = 0;
6999 }
7000 else
7001 {
7002 if ( pNormal->x == 0.0 && pNormal->y == 0.0 )
7003 v3 = 1;
7004 }
7005 if ( v3 )
7006 {
7007 if ( v3 == 1 )
7008 v8 = 3;
7009 else
7010 v8 = 4;
7011 result = v8;
7012 }
7013 else
7014 {
7015 result = 1;
7016 }
7017 v5 = pNormal->z;
7018 v6 = pNormal->y;
7019 v7 = pNormal->x;
7020 this->field_14 = result;
7021 this->vNormal.x = v7;
7022 this->field_10 = a3;
7023 this->vNormal.y = v6;
7024 this->vNormal.z = v5;
7025 return result;
7026 }
7027
7028 //----- (0049B13D) --------------------------------------------------------
7029 int stru154::_49B13D(ODMFace *pFace, BSPVertexBuffer *pVertices, Vec3_float_ *a3, float *a4)
7030 {
7031 ODMFace *v5; // ebx@1
7032 int v6; // eax@1
7033 unsigned __int16 *v7; // ebx@2
7034 Vec3_int_ *v8; // eax@3
7035 Vec3_int_ *v9; // ecx@3
7036 double v10; // st7@3
7037 int v11; // ecx@3
7038 Vec3_int_ *v12; // ecx@3
7039 double v13; // st7@3
7040 double v14; // st6@3
7041 double v15; // st5@3
7042 int v16; // ecx@3
7043 Vec3_int_ *v17; // eax@3
7044 double v18; // st5@3
7045 Vec3_float_ *v19; // eax@3
7046 int result; // eax@8
7047 float v21; // ecx@10
7048 double v22; // st7@10
7049 double v23; // st6@10
7050 Vec3_float_ v2; // [sp+4h] [bp-64h]@3
7051 float v25; // [sp+18h] [bp-50h]@3
7052 float v26; // [sp+1Ch] [bp-4Ch]@3
7053 float v27; // [sp+20h] [bp-48h]@3
7054 float v28; // [sp+24h] [bp-44h]@3
7055 float v29; // [sp+2Ch] [bp-3Ch]@3
7056 float v30; // [sp+30h] [bp-38h]@3
7057 float v31; // [sp+34h] [bp-34h]@3
7058 float v32; // [sp+38h] [bp-30h]@3
7059 float v33; // [sp+3Ch] [bp-2Ch]@3
7060 Vec3_float_ v1; // [sp+40h] [bp-28h]@1
7061 float v35; // [sp+4Ch] [bp-1Ch]@3
7062 float v36; // [sp+50h] [bp-18h]@3
7063 float v37; // [sp+54h] [bp-14h]@3
7064 Vec3_float_ v38; // [sp+58h] [bp-10h]@3
7065 int v39; // [sp+64h] [bp-4h]@1
7066
7067 v39 = 0;
7068 v1.x = 0.0;
7069 v5 = pFace;
7070 v6 = pFace->uNumVertices;
7071 v1.y = 0.0;
7072 v1.z = 0.0;
7073 if ( v6 - 1 <= 0 )
7074 {
7075 LABEL_8:
7076 a3->x = (double)(v5->pFacePlane.vNormal.x & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.vNormal.x >> 16);
7077 a3->y = (double)(v5->pFacePlane.vNormal.y & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.vNormal.y >> 16);
7078 a3->z = (double)(v5->pFacePlane.vNormal.z & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.vNormal.z >> 16);
7079 result = (int)a4;
7080 *a4 = (double)(v5->pFacePlane.dist & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.dist >> 16);
7081 }
7082 else
7083 {
7084 v7 = &pFace->pVertexIDs[1];
7085 while ( 1 )
7086 {
7087 v8 = pVertices->pVertices;
7088 v9 = &v8[*(v7 - 1)];
7089 v35 = (double)v9->x;
7090 v36 = (double)v9->y;
7091 v10 = (double)v9->z;
7092 v11 = *v7;
7093 v37 = v10;
7094 v12 = &v8[v11];
7095 v13 = (double)v12->x;
7096 v14 = (double)v12->y;
7097 v15 = (double)v12->z;
7098 v16 = v7[1];
7099 v25 = v15;
7100 v17 = &v8[v16];
7101 v18 = (double)v17->x;
7102 v29 = (double)v17->y;
7103 v30 = (double)v17->z;
7104 v31 = v13 - v35;
7105 v32 = v14 - v36;
7106 v33 = v25 - v37;
7107 v1.x = v31;
7108 v26 = v18 - v13;
7109 v1.y = v32;
7110 v27 = v29 - v14;
7111 v1.z = v33;
7112 v28 = v30 - v25;
7113 v19 = Vec3_float_::Cross(&v1, &v2, v26, v27, v28);
7114 v38.x = v19->x;
7115 v38.y = v19->y;
7116 v38.z = v19->z;
7117 if ( v38.x != 0.0 )
7118 break;
7119 if ( v38.y != 0.0 || v38.z != 0.0 )
7120 break;
7121 ++v39;
7122 ++v7;
7123 if ( v39 >= pFace->uNumVertices - 1 )
7124 {
7125 v5 = pFace;
7126 goto LABEL_8;
7127 }
7128 }
7129 v38.Normalize();
7130 v21 = v38.y;
7131 a3->x = v38.x;
7132 v22 = v37 * v38.z;
7133 v23 = v36 * v38.y;
7134 a3->y = v21;
7135 a3->z = v38.z;
7136 result = (int)a4;
7137 *a4 = -(v22 + v23 + v35 * v38.x);
7138 }
7139 return result;
7140 }
7141
7142
7143
7144
7145
7146 //----- (0049D700) --------------------------------------------------------
7147 unsigned int __fastcall GetMaxMipLevels(unsigned int uDim)
7148 {
7149 unsigned int v1; // eax@1
7150 int v2; // ecx@1
7151 unsigned int v3; // eax@1
7152
7153 v1 = uDim;
7154 v2 = 0;
7155 v3 = v1 - 1;
7156 while ( v3 & 1 )
7157 {
7158 v3 >>= 1;
7159 ++v2;
7160 }
7161 return v3 == 0 ? v2 : 0;
7162 }
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173 //----- (004A19D8) --------------------------------------------------------
7174 int __fastcall sub_4A19D8(unsigned int a1, unsigned int a2)
7175 {
7176 signed __int64 v2; // ST10_8@1
7177 double v3; // st7@1
7178 float v4; // ST24_4@1
7179 double v5; // ST10_8@1
7180 int v6; // ST1C_4@1
7181 float v7; // ST24_4@1
7182 double v8; // ST10_8@1
7183 unsigned __int8 v9; // ST20_1@1
7184 float v10; // ST24_4@1
7185 double v11; // ST10_8@1
7186 float v12; // ST24_4@1
7187 double v13; // ST08_8@1
7188
7189 v2 = a1 >> 24;
7190 v3 = (double)v2 * 0.0039215689;
7191 LODWORD(v2) = a2 >> 24;
7192 v4 = v3 * (double)v2 * 0.0039215689 * 255.0;
7193 v5 = v4 + 6.7553994e15;
7194 v6 = LODWORD(v5);
7195 v7 = (double)((a1 >> 16) & 0xFFi64) * 0.0039215689 * (double)((a2 >> 16) & 0xFF) * 0.0039215689 * 255.0;
7196 v8 = v7 + 6.7553994e15;
7197 v9 = LOBYTE(v8);
7198 v10 = (double)((unsigned __int16)a1 >> 8) * 0.0039215689 * (double)((unsigned __int16)a2 >> 8) * 0.0039215689 * 255.0;
7199 v11 = v10 + 6.7553994e15;
7200 v12 = (double)(a1 & 0xFFi64) * 0.0039215689 * (double)(unsigned __int8)a2 * 0.0039215689 * 255.0;
7201 v13 = v12 + 6.7553994e15;
7202 return LOBYTE(v13) | ((LOBYTE(v11) | (((v6 << 8) | v9) << 8)) << 8);
7203 }
7204
7205
7206 //----- (004A1C1E) --------------------------------------------------------
7207 void __cdecl DoRenderBillboards_D3D()
7208 {
7209 signed int v0; // ebp@1
7210 signed int *v1; // esi@2
7211 //IDirect3DDevice3Vtbl *v2; // esi@7
7212 unsigned int v3; // eax@7
7213 unsigned int v4; // [sp+58h] [bp-4h]@2
7214
7215 v0 = -1;
7216 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 3u));
7217 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
7218 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0));
7219 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1u));
7220 if ( ((pRenderer->uNumBillboardsToDraw - 1) & 0x80000000u) == 0 )
7221 {
7222 v1 = (signed int *)&pRenderer->pBillboardRenderListD3D[pRenderer->uNumBillboardsToDraw - 1].bOpaque;
7223 v4 = pRenderer->uNumBillboardsToDraw;
7224 do
7225 {
7226 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(
7227 0,
7228 (IDirect3DTexture2 *)*(v1 - 35)));
7229 if ( *v1 != v0 )
7230 {
7231 v0 = *v1;
7232 SetBillboardBlendOptions(*v1);
7233 }
7234 ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(
7235 D3DPT_TRIANGLEFAN,
7236 452,
7237 v1 - 33,
7238 *(v1 - 34),
7239 24));
7240 v1 -= 39;
7241 --v4;
7242 }
7243 while ( v4 );
7244 }
7245 if ( pRenderer->turnFogOn )
7246 {
7247 pRenderer->turnFogOn = 0;
7248 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1u));
7249 //v2 = pRenderer->pRenderD3D->pDevice->lpVtbl;
7250 v3 = GetLevelFogColor();
7251 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, v3 & 0xFFFFFF));
7252 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0));
7253 }
7254 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 2u));
7255 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
7256 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
7257 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
7258 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
7259 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u));
7260 }
7261
7262 //----- (004A1DA8) --------------------------------------------------------
7263 void __fastcall SetBillboardBlendOptions(signed int a1)
7264 {
7265 //IDirect3DDevice3Vtbl *v1; // edi@9
7266 unsigned int v2; // eax@9
7267 int v3; // [sp+0h] [bp-4h]@0
7268
7269 if ( !a1 )
7270 {
7271 if ( pRenderer->turnFogOn )
7272 {
7273 pRenderer->turnFogOn = 0;
7274 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1u));
7275 //v1 = pRenderer->pRenderD3D->pDevice->lpVtbl;
7276 v2 = GetLevelFogColor();
7277 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, v2 & 0xFFFFFF));
7278 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0));
7279 }
7280 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 5));
7281 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 6u));
7282 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1));
7283 return;
7284 }
7285 if ( a1 > 0 && a1 <= 3 )
7286 {
7287 if ( pRenderer->bUsingSpecular )
7288 {
7289 if ( !pRenderer->turnFogOn )
7290 {
7291 pRenderer->turnFogOn = 1;
7292 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0));
7293 }
7294 }
7295 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
7296 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u));
7297 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0));
7298 }
7299 }
7300
7301
7302
7303
7304
7305
7306
7307 //----- (004A46E6) --------------------------------------------------------
7308 int __fastcall sub_4A46E6(unsigned int x, signed int y, signed int a3, int a4, unsigned int a5)
7309 {
7310 int v5; // eax@1
7311 int z; // eax@1
7312 unsigned int v7; // eax@9
7313 unsigned int v8; // ecx@9
7314 int v9; // eax@9
7315 unsigned int v10; // eax@10
7316 int *v11; // esi@10
7317 int *v12; // edi@10
7318 int v13; // ecx@10
7319 int v14; // edx@10
7320 unsigned int v15; // eax@22
7321 int *v16; // esi@22
7322 int *v17; // edi@22
7323 int v18; // ecx@22
7324 int v19; // edx@22
7325 unsigned __int16 *pTarget; // [sp+Ch] [bp-8h]@9
7326 int *pTargetZ; // [sp+10h] [bp-4h]@9
7327 unsigned int v22; // [sp+1Ch] [bp+8h]@9
7328 signed int v23; // [sp+20h] [bp+Ch]@1
7329
7330 v5 = a4;
7331 v23 = a3 >> 16;
7332 z = x + v5;
7333 if ( z >= (signed int)pViewport->uViewportX
7334 && (signed int)x <= (signed int)pViewport->uViewportZ
7335 && y >= (signed int)pViewport->uViewportY
7336 && y <= (signed int)pViewport->uViewportW )
7337 {
7338 if ( (signed int)x < (signed int)pViewport->uViewportX )
7339 x = pViewport->uViewportX;
7340 if ( z > (signed int)pViewport->uViewportZ )
7341 z = pViewport->uViewportZ;
7342 pTarget = &pRenderer->pTargetSurface[x + y * pRenderer->uTargetSurfacePitch];
7343 v22 = z - x;
7344 pTargetZ = &pRenderer->pActiveZBuffer[x + 640 * y];
7345 v7 = a5 >> 3;
7346 v8 = a5 & 0xF0;
7347 v9 = v7 & 0x1E0000;
7348 if ( pRenderer->uTargetGBits == 5 )
7349 {
7350 v10 = (v8 | (((unsigned __int16)(a5 & 0xF000) | (unsigned int)v9) >> 3)) >> 4;
7351 v11 = (int *)pTarget;
7352 v12 = pTargetZ;
7353 v13 = v22;
7354 v14 = (v10 << 16) | v10;
7355 z = (unsigned __int8)pTarget & 2;
7356 if ( (unsigned __int8)pTarget & 2 )
7357 {
7358 z = (unsigned int)*pTargetZ >> 16;
7359 if ( z > v23 )
7360 {
7361 z = v14 + ((*pTarget & 0x7BDEu) >> 1);
7362 *pTarget = z;
7363 }
7364 v13 = v22 - 1;
7365 v11 = (int *)(pTarget + 1);
7366 v12 = pTargetZ + 1;
7367 }
7368 while ( v13 != 1 )
7369 {
7370 if ( v13 < 1 )
7371 return z;
7372 z = (unsigned int)*v12 >> 16;
7373 if ( z <= v23 )
7374 {
7375 v13 -= 2;
7376 ++v11;
7377 v12 += 2;
7378 }
7379 else
7380 {
7381 v12 += 2;
7382 z = v14 + ((*v11 & 0x7BDE7BDEu) >> 1);
7383 v13 -= 2;
7384 *v11 = z;
7385 ++v11;
7386 }
7387 }
7388 z = (unsigned int)*v12 >> 16;
7389 if ( z > v23 )
7390 {
7391 z = v14 + ((*(short *)v11 & 0x7BDEu) >> 1);
7392 *(short *)v11 = z;
7393 }
7394 }
7395 else
7396 {
7397 v15 = (v8 | (((unsigned __int16)(a5 & 0xF800) | (unsigned int)v9) >> 2)) >> 4;
7398 v16 = (int *)pTarget;
7399 v17 = pTargetZ;
7400 v18 = v22;
7401 v19 = (v15 << 16) | v15;
7402 z = (unsigned __int8)pTarget & 2;
7403 if ( (unsigned __int8)pTarget & 2 )
7404 {
7405 z = (unsigned int)*pTargetZ >> 16;
7406 if ( z > v23 )
7407 {
7408 z = v19 + ((*pTarget & 0xF7DEu) >> 1);
7409 *pTarget = z;
7410 }
7411 v18 = v22 - 1;
7412 v16 = (int *)(pTarget + 1);
7413 v17 = pTargetZ + 1;
7414 }
7415 while ( v18 != 1 )
7416 {
7417 if ( v18 < 1 )
7418 return z;
7419 z = (unsigned int)*v17 >> 16;
7420 if ( z <= v23 )
7421 {
7422 v18 -= 2;
7423 ++v16;
7424 v17 += 2;
7425 }
7426 else
7427 {
7428 v17 += 2;
7429 z = v19 + ((*v16 & 0xF7DEF7DEu) >> 1);
7430 v18 -= 2;
7431 *v16 = z;
7432 ++v16;
7433 }
7434 }
7435 z = (unsigned int)*v17 >> 16;
7436 if ( z > v23 )
7437 {
7438 z = v19 + ((*(short *)v16 & 0xF7DEu) >> 1);
7439 *(short *)v16 = z;
7440 }
7441 }
7442 }
7443 return z;
7444 }
7445
7446
7447 //----- (004A57E9) --------------------------------------------------------
7448 void __cdecl Present_ColorKey()
7449 {
7450 HRESULT v0; // eax@3
7451 HRESULT v1; // eax@3
7452 HRESULT v2; // eax@3
7453 HRESULT v3; // eax@3
7454 HRESULT v4; // eax@3
7455 RECT a2; // [sp+4h] [bp-14h]@3
7456 //CheckHRESULT_stru0 this; // [sp+14h] [bp-4h]@3
7457
7458 if ( !pRenderer->uNumSceneBegins )
7459 {
7460 if ( pRenderer->field_40110 )
7461 {
7462 a2.bottom = pViewport->uViewportY;
7463 a2.left = 0;
7464 a2.top = 0;
7465 a2.right = 640;
7466 ErrD3D(pRenderer->pBackBuffer4->BltFast(0, 0, pRenderer->pColorKeySurface4, &a2, 16u));
7467 a2.right = 640;
7468 a2.left = 0;
7469 a2.top = pViewport->uViewportW + 1;
7470 a2.bottom = 480;
7471 ErrD3D(pRenderer->pBackBuffer4->BltFast(
7472 0,
7473 pViewport->uViewportW + 1,
7474 pRenderer->pColorKeySurface4,
7475 &a2,
7476 16u));
7477 a2.right = pViewport->uViewportX;
7478 a2.bottom = pViewport->uViewportW + 1;
7479 a2.left = 0;
7480 a2.top = pViewport->uViewportY;
7481 ErrD3D(pRenderer->pBackBuffer4->BltFast(
7482 0,
7483 pViewport->uViewportY,
7484 pRenderer->pColorKeySurface4,
7485 &a2,
7486 16u));
7487 a2.left = pViewport->uViewportZ;
7488 a2.top = pViewport->uViewportY;
7489 a2.right = 640;
7490 a2.bottom = pViewport->uViewportW + 1;
7491 ErrD3D(pRenderer->pBackBuffer4->BltFast(
7492 pViewport->uViewportZ,
7493 pViewport->uViewportY,
7494 pRenderer->pColorKeySurface4,
7495 &a2,
7496 16u));
7497 a2.right = pViewport->uViewportZ;
7498 a2.bottom = pViewport->uViewportW + 1;
7499 a2.left = pViewport->uViewportX;
7500 a2.top = pViewport->uViewportY;
7501 ErrD3D(pRenderer->pBackBuffer4->BltFast(
7502 pViewport->uViewportX,
7503 pViewport->uViewportY,
7504 pRenderer->pColorKeySurface4,
7505 &a2,
7506 17u));
7507 }
7508 }
7509 }
7510
7511 //----- (004A597D) --------------------------------------------------------
7512 void __cdecl Present_NoColorKey()
7513 {
7514 //unsigned __int16 *v0; // eax@4
7515 unsigned __int16 *v1; // esi@4
7516 void *v2; // edi@4
7517 //signed int v4; // ebx@4
7518 //signed int v5; // ebx@6
7519 //void *v6; // edi@7
7520 //const void *v7; // esi@7
7521 signed int v8; // ebx@8
7522 int v9; // eax@10
7523 unsigned int v10; // esi@10
7524 unsigned __int32 v11; // edi@10
7525 //int v12; // ecx@10
7526 unsigned int v13; // ebx@10
7527 int v14; // eax@11
7528 int v15; // eax@13
7529 int v16; // eax@14
7530 int v17; // eax@16
7531 HRESULT v18; // eax@22
7532 DDSURFACEDESC2 Dst; // [sp+Ch] [bp-98h]@3
7533 int v20; // [sp+88h] [bp-1Ch]@10
7534 int v21; // [sp+8Ch] [bp-18h]@10
7535 __int32 v22; // [sp+90h] [bp-14h]@10
7536 //unsigned __int32 v23; // [sp+94h] [bp-10h]@10
7537 unsigned int v24; // [sp+98h] [bp-Ch]@4
7538 //unsigned int _this; // [sp+9Ch] [bp-8h]@10
7539 //LPVOID v26; // [sp+A0h] [bp-4h]@4
7540
7541 if ( !pRenderer->uNumSceneBegins )
7542 {
7543 if ( pRenderer->field_40110 )
7544 {
7545 memset(&Dst, 0, 0x7Cu);
7546 Dst.dwSize = 124;
7547 if ( pRenderer->LockSurface_DDraw4(pRenderer->pBackBuffer4, &Dst, 1u) )
7548 {
7549 //v26 = Dst.lpSurface;
7550 pRenderer->pCurrentlyLockedSurfaceDataPtr = (unsigned __int16 *)Dst.lpSurface;
7551 v24 = pRenderer->uTargetGMask | pRenderer->uTargetBMask |
7552 ((pRenderer->uTargetGMask | pRenderer->uTargetBMask) << 16);
7553 pRenderer->pCurrentlyLockedSoftSurface = pRenderer->pTargetSurface;
7554 pRenderer->uCurrentlyLockedSurfacePitch = Dst.lPitch;
7555 v1 = pRenderer->pTargetSurface;
7556 v2 = Dst.lpSurface;
7557
7558 //memset(pRenderer->pTargetSurface, 128, 640 * 2 * 320);
7559
7560 auto pSrc = pRenderer->pTargetSurface;
7561 auto pDst = (__int16 *)Dst.lpSurface;
7562
7563 for (uint y = 0; y < 8; ++y)
7564 memcpy(pDst + y * 640,
7565 pSrc + y * 640, 640 * sizeof(__int16));
7566
7567 for (uint y = 8; y < 352; ++y)
7568 {
7569 memcpy(pDst + y * 640,
7570 pSrc + y * 640, 8 * sizeof(__int16));
7571 memcpy(pDst + y * 640 + 8 + 460/*462*/,
7572 pSrc + y * 640 + 8 + 460/*462*/, 174/*172*/ * sizeof(__int16));
7573 }
7574
7575 for (uint y = 351/*352*/; y < 480; ++y)
7576 memcpy(pDst + y * 640,
7577 pSrc + y * 640, 640 * sizeof(__int16));
7578
7579
7580 auto pSrc_x1y1 = pSrc + 640 * pViewport->uViewportY + pViewport->uViewportX;
7581 //_this = (unsigned int)&pSrc[2 * (((signed int)pViewport->uViewportX >> 1) + 320 * pViewport->uViewportY)];
7582 auto pDst_x1y1 = pDst + Dst.lPitch * pViewport->uViewportY + pViewport->uViewportX;
7583 //v23 = (unsigned __int32)((char *)v26 + 4 * (((signed int)pViewport->uViewportX >> 1) + (Dst.lPitch >> 2) * pViewport->uViewportY));
7584 v9 = ((signed int)pViewport->uViewportX >> 1) - ((signed int)pViewport->uViewportZ >> 1);
7585 //v20 = ((signed int)pViewport->uViewportZ >> 1) - ((signed int)pViewport->uViewportX >> 1);
7586 v22 = 4 * ((Dst.lPitch / 4) + v9);
7587 v21 = 4 * v9 + 1280;
7588
7589 auto uNumLines = pViewport->uViewportW - pViewport->uViewportY + 1;
7590 //v26 = (LPVOID)(pViewport->uViewportW - pViewport->uViewportY + 1);
7591 v10 = (int)pSrc_x1y1;
7592 v11 = (int)pDst_x1y1;
7593 auto uHalfWidth = v20 = (pViewport->uViewportZ - pViewport->uViewportX) / 2;
7594 v13 = v24;
7595
7596 for (uint y = pViewport->uViewportY; y < pViewport->uViewportW; ++y)
7597 memcpy(pDst + 640 * y + pViewport->uViewportX,
7598 pSrc + 640 * y + pViewport->uViewportX, (pViewport->uViewportZ - pViewport->uViewportX) * sizeof(__int16));
7599
7600 ErrD3D(pRenderer->pBackBuffer4->Unlock(0));
7601
7602 /* while ( 1 )
7603 {
7604 while ( 1 )
7605 {
7606 v14 = *(int *)v10;
7607 v10 += 4;
7608 if ( v14 == v13 )
7609 break;
7610 if ( (short)v14 == (short)v13 )
7611 {
7612 *(int *)v11 = *(int *)v11 & 0xFFFF | v14 & 0xFFFF0000;
7613 v11 += 4;
7614 --uHalfWidth;
7615 if ( !uHalfWidth )
7616 goto LABEL_21;
7617 }
7618 else
7619 {
7620 v15 = __ROL__(v14, 16);
7621 if ( (short)v15 == (short)v13 )
7622 {
7623 v17 = __ROR__(v15, 16);
7624 *(int *)v11 = *(int *)v11 & 0xFFFF0000 | (unsigned __int16)v17;
7625 v11 += 4;
7626 --uHalfWidth;
7627 if ( !uHalfWidth )
7628 goto LABEL_21;
7629 }
7630 else
7631 {
7632 v16 = __ROR__(v15, 16);
7633 *(int *)v11 = v16;
7634 v11 += 4;
7635 --uHalfWidth;
7636 if ( !uHalfWidth )
7637 goto LABEL_21;
7638 }
7639 }
7640 }
7641 v11 += 4;
7642 --uHalfWidth;
7643 if ( !uHalfWidth )
7644 {
7645 LABEL_21:
7646 v10 += v21;
7647 v11 += v22;
7648 uHalfWidth = v20;
7649 if ( !--uNumLines )
7650 {
7651 ErrD3D(pRenderer->pBackBuffer4->Unlock(0));
7652 return;
7653 }
7654 }
7655 }*/
7656 }
7657 }
7658 }
7659 }
7660
7661
7662
7663 //----- (004A7063) --------------------------------------------------------
7664 int __thiscall sub_4A7063(unsigned int uDiffuse, float a2)
7665 {
7666 float v2; // ST1C_4@1
7667 double v3; // ST14_8@1
7668 signed int v4; // ebx@1
7669 float v5; // ST1C_4@1
7670 double v6; // ST14_8@1
7671 signed int v7; // edi@1
7672 double v8; // ST0C_8@1
7673 signed int v9; // esi@1
7674 signed int v10; // ecx@1
7675 double v12; // [sp+8h] [bp-18h]@1
7676 unsigned __int64 v13; // [sp+18h] [bp-8h]@1
7677
7678 v2 = (double)(uDiffuse >> 24) * a2;
7679 v3 = v2 + 6.7553994e15;
7680 v4 = LODWORD(v3);
7681 v5 = (double)((uDiffuse >> 16) & 0xFF) * a2;
7682 v6 = v5 + 6.7553994e15;
7683 v7 = LODWORD(v6);
7684 *((float *)&v6 + 1) = (double)((unsigned __int16)uDiffuse >> 8) * a2;
7685 v8 = *((float *)&v6 + 1) + 6.7553994e15;
7686 v13 = __PAIR__(LODWORD(v6), LODWORD(v8));
7687 v9 = LODWORD(v8);
7688 *((float *)&v6 + 1) = (double)(unsigned __int8)uDiffuse * a2;
7689 v12 = *((float *)&v6 + 1) + 6.7553994e15;
7690 v10 = LODWORD(v12);
7691 if ( v4 > 255 )
7692 v4 = 255;
7693 if ( v4 < 0 )
7694 v4 = 0;
7695 if ( SHIDWORD(v13) > 255 )
7696 v7 = 255;
7697 if ( v7 < 0 )
7698 v7 = 0;
7699 if ( (signed int)v13 > 255 )
7700 v9 = 255;
7701 if ( v9 < 0 )
7702 v9 = 0;
7703 if ( SLODWORD(v12) > 255 )
7704 v10 = 255;
7705 if ( v10 < 0 )
7706 v10 = 0;
7707 return v10 | ((v9 | ((v7 | (v4 << 8)) << 8)) << 8);
7708 }
7709
7710
7711
7712
7713
7714 //----- (004AC1C9) --------------------------------------------------------
7715 int __thiscall sub_4AC1C9(unsigned int _this, Vec4_int_ *a2)
7716 {
7717 unsigned int v2; // esi@1
7718 __int16 v3; // di@1
7719 signed int v4; // ebx@1
7720 int v5; // ecx@3
7721 Vec4_int_ *v6; // eax@10
7722 Vec4_int_ *v7; // esi@14
7723 int result; // eax@16
7724 char *v9; // esi@16
7725 Vec4_int_ a1; // [sp+Ch] [bp-34h]@10
7726 Vec4_int_ v11; // [sp+1Ch] [bp-24h]@14
7727 Vec4_int_ Dst; // [sp+2Ch] [bp-14h]@1
7728 int v13; // [sp+3Ch] [bp-4h]@1
7729
7730 v2 = _this;
7731 v3 = sub_4382BC(_this);
7732 v13 = sub_4383ED();
7733 v4 = 0;
7734 memset(&Dst, 0, 0x10u);
7735 if ( v3 < 0 )
7736 goto LABEL_19;
7737 if ( (signed int)v2 > 0 )
7738 {
7739 if ( (signed int)v2 > 150 )
7740 {
7741 v5 = (int)a2;
7742 }
7743 else
7744 {
7745 v5 = 4000 * v2;
7746 v4 = 1;
7747 }
7748 }
7749 else
7750 {
7751 v5 = 4000 * dword_4F031C[(unsigned __int16)v3];
7752 }
7753 if ( v13 & 0x10 && !v4 )
7754 {
7755 if ( v2 )
7756 v6 = sub_4AC4FD_get_cpu_clocks_rdtsc(v5, &a1);
7757 else
7758 v6 = sub_4AC33A_get_cpu_clocks_QPC(v5, &a1);
7759 goto LABEL_14;
7760 }
7761 if ( (unsigned __int16)v3 < 3u )
7762 {
7763 LABEL_19:
7764 v7 = &Dst;
7765 goto LABEL_16;
7766 }
7767 v6 = sub_4AC277(v5, &a1);
7768 LABEL_14:
7769 v11.x = v6->x;
7770 v11.y = v6->y;
7771 v11.z = v6->z;
7772 v11.w = v6->w;
7773 v7 = &v11;
7774 LABEL_16:
7775 result = (int)a2;
7776 a2->x = v7->x;
7777 v9 = (char *)&v7->y;
7778 a2->y = *(int *)v9;
7779 v9 += 4;
7780 a2->z = *(int *)v9;
7781 a2->w = *((int *)v9 + 1);
7782 return result;
7783 }
7784 // 4F031C: using guessed type int dword_4F031C[];
7785
7786 //----- (004AC277) --------------------------------------------------------
7787 Vec4_int_ *__thiscall sub_4AC277(unsigned int _this, Vec4_int_ *a2)
7788 {
7789 __debugbreak();
7790 return 0;
7791 /*signed int v2; // esi@1
7792 signed __int16 v4; // bx@3
7793 int v10; // esi@8
7794 int v11; // eax@10
7795 Vec4_int_ *result; // eax@13
7796 Vec4_int_ Dst; // [sp+8h] [bp-30h]@1
7797 LARGE_INTEGER Frequency; // [sp+18h] [bp-20h]@1
7798 LARGE_INTEGER PerformanceCount; // [sp+20h] [bp-18h]@3
7799 LARGE_INTEGER v16; // [sp+28h] [bp-10h]@5
7800 int v17; // [sp+30h] [bp-8h]@1
7801 int v18; // [sp+34h] [bp-4h]@2
7802
7803 v17 = _this;
7804 v2 = -1;
7805 memset(&Dst, 0, 0x10u);
7806 if ( QueryPerformanceFrequency(&Frequency) )
7807 {
7808 v18 = 10;
7809 do
7810 {
7811 QueryPerformanceCounter(&PerformanceCount);
7812 _EAX = -2147483648;
7813 v4 = 4000;
7814 do
7815 {
7816 __asm { bsf ecx, eax }
7817 --v4;
7818 }
7819 while ( v4 );
7820 QueryPerformanceCounter(&v16);
7821 if ( (signed int)v16.s.LowPart - (signed int)PerformanceCount.s.LowPart < (unsigned int)v2 )
7822 v2 = v16.s.LowPart - PerformanceCount.s.LowPart;
7823 --v18;
7824 }
7825 while ( v18 );
7826 v10 = 100000 * v2 / (Frequency.s.LowPart / 0xA);
7827 if ( v10 % Frequency.s.LowPart > Frequency.s.LowPart >> 1 )
7828 ++v10;
7829 v11 = v17 / (unsigned int)v10;
7830 Dst.z = v17 / (unsigned int)v10;
7831 if ( v17 % (unsigned int)v10 > (unsigned int)v10 >> 1 )
7832 ++v11;
7833 Dst.x = v17;
7834 Dst.y = v10;
7835 Dst.w = v11;
7836 }
7837 result = a2;
7838 a2->x = Dst.x;
7839 a2->y = Dst.y;
7840 a2->z = Dst.z;
7841 a2->w = Dst.w;
7842 return result;*/
7843 }
7844
7845 //----- (004AC33A) --------------------------------------------------------
7846 Vec4_int_ *__thiscall sub_4AC33A_get_cpu_clocks_QPC(int _this, Vec4_int_ *a1)
7847 {
7848 __debugbreak();
7849 return 0;
7850 /*int v2; // esi@1
7851 int v3; // ebx@1
7852 unsigned __int64 v4; // qax@4
7853 unsigned __int64 v5; // qax@7
7854 DWORD v6; // edi@7
7855 DWORD v7; // eax@7
7856 unsigned int v8; // ecx@10
7857 unsigned __int64 v9; // qax@10
7858 unsigned int v10; // edi@10
7859 int v11; // eax@14
7860 unsigned int v12; // ecx@19
7861 Vec4_int_ *result; // eax@24
7862 int Dst; // [sp+Ch] [bp-4Ch]@1
7863 int v15; // [sp+10h] [bp-48h]@23
7864 int v16; // [sp+14h] [bp-44h]@21
7865 int v17; // [sp+18h] [bp-40h]@21
7866 LARGE_INTEGER Frequency; // [sp+1Ch] [bp-3Ch]@1
7867 LARGE_INTEGER PerformanceCount; // [sp+24h] [bp-34h]@2
7868 LARGE_INTEGER v20; // [sp+2Ch] [bp-2Ch]@2
7869 int v21; // [sp+34h] [bp-24h]@2
7870 int v22; // [sp+38h] [bp-20h]@2
7871 int v23; // [sp+3Ch] [bp-1Ch]@4
7872 int v24; // [sp+40h] [bp-18h]@7
7873 int nPriority; // [sp+44h] [bp-14h]@2
7874 unsigned int v26; // [sp+48h] [bp-10h]@1
7875 unsigned int v27; // [sp+4Ch] [bp-Ch]@1
7876 HANDLE hThread; // [sp+50h] [bp-8h]@1
7877 int v29; // [sp+54h] [bp-4h]@1
7878
7879 v2 = 0;
7880 v3 = 0;
7881 v29 = 0;
7882 v27 = 0;
7883 v26 = 0;
7884 hThread = GetCurrentThread();
7885 memset(&Dst, 0, 0x10u);
7886 if ( QueryPerformanceFrequency(&Frequency) )
7887 {
7888 do
7889 {
7890 ++v29;
7891 v22 = v2;
7892 v21 = v3;
7893 QueryPerformanceCounter(&PerformanceCount);
7894 v20 = PerformanceCount;
7895 nPriority = GetThreadPriority(hThread);
7896 if ( nPriority != 2147483647 )
7897 SetThreadPriority(hThread, 15);
7898 while ( v20.s.LowPart - PerformanceCount.s.LowPart < 0x32 )
7899 {
7900 QueryPerformanceCounter(&v20);
7901 v4 = __rdtsc();
7902 v23 = v4;
7903 }
7904 PerformanceCount = v20;
7905 do
7906 {
7907 QueryPerformanceCounter(&v20);
7908 v5 = __rdtsc();
7909 v24 = v5;
7910 v6 = v20.s.LowPart;
7911 v7 = PerformanceCount.s.LowPart;
7912 }
7913 while ( v20.s.LowPart - PerformanceCount.s.LowPart < 0x3E8 );
7914 if ( nPriority != 2147483647 )
7915 {
7916 SetThreadPriority(hThread, nPriority);
7917 v7 = PerformanceCount.s.LowPart;
7918 v6 = v20.s.LowPart;
7919 }
7920 v8 = v24 - v23;
7921 v27 += v24 - v23;
7922 v9 = (100000 * v6 - 100000 * v7) / (Frequency.s.LowPart / 0xA);
7923 v10 = v9;
7924 v26 += v9;
7925 if ( v9 % Frequency.s.LowPart > Frequency.s.LowPart >> 1 )
7926 v10 = v9 + 1;
7927 v3 = v8 / v10;
7928 if ( v8 % v10 > v10 >> 1 )
7929 v3 = v8 / v10 + 1;
7930 v2 = v21;
7931 v11 = v3 + v22 + v21;
7932 }
7933 while ( v29 < 3
7934 || v29 < 20
7935 && ((unsigned int)(3 * v3 - v11) > 3 || (unsigned int)(3 * v21 - v11) > 3 || (unsigned int)(3 * v22 - v11) > 3) );
7936 v12 = 10 * v27 / v26;
7937 if ( 100 * v27 / v26 - 10 * v12 >= 6 )
7938 ++v12;
7939 v16 = v27 / v26;
7940 v17 = v27 / v26;
7941 if ( v12 - 10 * v27 / v26 >= 6 )
7942 v17 = v27 / v26 + 1;
7943 v15 = v26;
7944 Dst = v27;
7945 }
7946 result = a1;
7947 a1->x = Dst;
7948 a1->y = v15;
7949 a1->z = v16;
7950 a1->w = v17;
7951 return result;*/
7952 }
7953
7954 //----- (004AC4FD) --------------------------------------------------------
7955 Vec4_int_ *__thiscall sub_4AC4FD_get_cpu_clocks_rdtsc(int _this, Vec4_int_ *a1)
7956 {
7957 __debugbreak();
7958 return 0;
7959 /*int v2; // eax@1
7960 int v3; // eax@4
7961 bool v4; // eax@5
7962 unsigned __int64 v5; // kr00_8@8
7963 int v6; // edi@9
7964 int v7; // eax@9
7965 bool v8; // eax@10
7966 unsigned __int64 v9; // kr08_8@13
7967 unsigned int v10; // eax@15
7968 Vec4_int_ *result; // eax@17
7969 int Dst; // [sp+Ch] [bp-2Ch]@1
7970 int v13; // [sp+10h] [bp-28h]@17
7971 int v14; // [sp+14h] [bp-24h]@15
7972 int v15; // [sp+18h] [bp-20h]@17
7973 unsigned int v16; // [sp+1Ch] [bp-1Ch]@8
7974 unsigned int v17; // [sp+20h] [bp-18h]@8
7975 unsigned int v18; // [sp+24h] [bp-14h]@13
7976 int nPriority; // [sp+28h] [bp-10h]@1
7977 __int64 v20; // [sp+2Ch] [bp-Ch]@1
7978 int v21; // [sp+34h] [bp-4h]@3
7979
7980 HIDWORD(v20) = GetCurrentThread();
7981 memset(&Dst, 0, 0x10u);
7982 v2 = GetThreadPriority(HIDWORD(v20));
7983 nPriority = v2;
7984 if ( v2 != 0x7FFFFFFF )
7985 SetThreadPriority(HIDWORD(v20), v2 + 1);
7986 __outbyte(0x70u, 0);
7987 v21 = __inbyte(0x71u);
7988 do
7989 {
7990 __outbyte(0x70u, 0);
7991 LODWORD(v20) = __inbyte(0x71u);
7992 v3 = v20 - v21;
7993 if ( (signed int)v20 >= v21 )
7994 v4 = v3 > 0;
7995 else
7996 v4 = v3 + 10;
7997 }
7998 while ( !v4 );
7999 v5 = __rdtsc();
8000 v16 = HIDWORD(v5);
8001 v17 = v5;
8002 do
8003 {
8004 __outbyte(0x70u, 0);
8005 v21 = __inbyte(0x71u);
8006 v6 = v21;
8007 v7 = v21 - v20;
8008 if ( v21 >= (signed int)v20 )
8009 v8 = v7 > 0;
8010 else
8011 v8 = v7 + 10;
8012 }
8013 while ( !v8 );
8014 v9 = __rdtsc();
8015 v18 = HIDWORD(v9);
8016 v21 = v9;
8017 if ( nPriority != 0x7FFFFFFF )
8018 SetThreadPriority(HIDWORD(v20), nPriority);
8019 nPriority = v21;
8020 *(__int64 *)((char *)&v20 + 4) = __PAIR__(v18, v21) - __PAIR__(v16, v17);
8021 Dst = HIDWORD(v20);
8022 v10 = HIDWORD(v20) / 0xF4240;
8023 v14 = HIDWORD(v20) / 0xF4240;
8024 if ( HIDWORD(v20) / 0x186A0 - 10 * HIDWORD(v20) / 0xF4240 >= 6 )
8025 ++v10;
8026 v15 = v10;
8027 result = a1;
8028 v13 = 1000000 * v6 - 1000000 * v20;
8029 a1->x = Dst;
8030 a1->y = v13;
8031 a1->z = v14;
8032 a1->w = v15;
8033 return result;*/
8034 }
8035
8036
8037
8038 //----- (004AD504) --------------------------------------------------------
8039 int __fastcall sub_4AD504(unsigned int uFaceID)
8040 {
8041 int result; // eax@1
8042 unsigned int v2; // ebx@1
8043 BLVFace *v3; // esi@3
8044 Texture *v4; // edi@6
8045 int v5; // eax@7
8046 int v6; // edx@7
8047 int v7; // ecx@7
8048 int v8; // ebx@8
8049 int v9; // eax@8
8050 int v10; // ebx@8
8051 unsigned int v11; // ebx@9
8052 int v12; // esi@10
8053 int v13; // eax@13
8054 unsigned __int16 *v14; // eax@13
8055 unsigned int v15; // eax@14
8056 unsigned __int16 *v16; // ebx@14
8057 int v17; // eax@15
8058 int v18; // ebx@15
8059 int v19; // esi@15
8060 int v20; // ecx@15
8061 int v21; // eax@15
8062 stru193_math *v22; // ebx@15
8063 int v23; // eax@15
8064 char *v24; // esi@16
8065 int v25; // eax@18
8066 int v26; // eax@18
8067 int v27; // eax@20
8068 signed int v28; // esi@20
8069 signed int v29; // edx@20
8070 signed int v30; // esi@20
8071 signed int v31; // edi@20
8072 int v32; // esi@20
8073 int v33; // eax@26
8074 int *v34; // esi@27
8075 unsigned __int16 *v35; // edi@27
8076 unsigned int v36; // edx@27
8077 int v37; // ebx@27
8078 char v38; // cl@27
8079 char v39; // ch@27
8080 int v40; // ebx@29
8081 int v41; // edx@29
8082 unsigned int v42; // ebx@30
8083 int v43; // edx@30
8084 int v44; // eax@33
8085 int *v45; // esi@34
8086 unsigned __int16 *v46; // edi@34
8087 unsigned int v47; // edx@34
8088 int v48; // ebx@34
8089 char v49; // cl@34
8090 char v50; // ch@34
8091 int v51; // ebx@36
8092 int v52; // edx@36
8093 unsigned __int16 v53; // bx@37
8094 int v54; // edx@37
8095 int v55; // eax@40
8096 int v56; // eax@41
8097 int *v57; // esi@42
8098 unsigned __int16 *v58; // edi@42
8099 unsigned int v59; // edx@42
8100 int v60; // ebx@42
8101 char v61; // cl@42
8102 char v62; // ch@42
8103 unsigned int v63; // ebx@44
8104 int v64; // edx@44
8105 unsigned int v65; // ebx@44
8106 int v66; // edx@44
8107 unsigned int v67; // ebx@45
8108 int v68; // edx@45
8109 int v69; // ebx@45
8110 int v70; // edx@45
8111 int v71; // eax@48
8112 int *v72; // esi@49
8113 unsigned __int16 *v73; // edi@49
8114 unsigned int v74; // edx@49
8115 int v75; // ebx@49
8116 char v76; // cl@49
8117 char v77; // ch@49
8118 unsigned int v78; // ebx@51
8119 int v79; // edx@51
8120 unsigned int v80; // ebx@51
8121 int v81; // edx@51
8122 unsigned int v82; // ebx@52
8123 int v83; // edx@52
8124 int v84; // ebx@52
8125 int v85; // edx@52
8126 unsigned __int8 *v86; // [sp+Ch] [bp-98h]@9
8127 unsigned __int8 *v87; // [sp+10h] [bp-94h]@9
8128 unsigned __int8 *v88; // [sp+14h] [bp-90h]@9
8129 unsigned __int8 *v89; // [sp+18h] [bp-8Ch]@9
8130 int v90; // [sp+1Ch] [bp-88h]@20
8131 BLVFace *v91; // [sp+20h] [bp-84h]@3
8132 int v92; // [sp+24h] [bp-80h]@7
8133 int i; // [sp+28h] [bp-7Ch]@7
8134 unsigned __int16 *v94; // [sp+2Ch] [bp-78h]@9
8135 unsigned int v95; // [sp+30h] [bp-74h]@1
8136 Texture *v96; // [sp+34h] [bp-70h]@6
8137 int v97; // [sp+38h] [bp-6Ch]@15
8138 unsigned int v98; // [sp+3Ch] [bp-68h]@9
8139 int v99; // [sp+40h] [bp-64h]@9
8140 int v100; // [sp+44h] [bp-60h]@24
8141 int v101; // [sp+48h] [bp-5Ch]@10
8142 int v102; // [sp+4Ch] [bp-58h]@20
8143 int v103; // [sp+50h] [bp-54h]@20
8144 int v104; // [sp+54h] [bp-50h]@9
8145 unsigned __int8 *v105; // [sp+58h] [bp-4Ch]@20
8146 int v106; // [sp+5Ch] [bp-48h]@24
8147 int v107; // [sp+60h] [bp-44h]@20
8148 int v108; // [sp+64h] [bp-40h]@20
8149 int v109; // [sp+68h] [bp-3Ch]@20
8150 int v110; // [sp+6Ch] [bp-38h]@15
8151 int v111; // [sp+70h] [bp-34h]@20
8152 int a1; // [sp+74h] [bp-30h]@12
8153 int a2; // [sp+78h] [bp-2Ch]@9
8154 int *v114; // [sp+7Ch] [bp-28h]@16
8155 int v115; // [sp+80h] [bp-24h]@18
8156 int v116; // [sp+84h] [bp-20h]@7
8157 unsigned int v117; // [sp+88h] [bp-1Ch]@15
8158 unsigned int v118; // [sp+8Ch] [bp-18h]@24
8159 int *v119; // [sp+90h] [bp-14h]@13
8160 int v120; // [sp+94h] [bp-10h]@15
8161 unsigned int v121; // [sp+98h] [bp-Ch]@15
8162 unsigned __int16 *v122; // [sp+9Ch] [bp-8h]@15
8163 unsigned int v123; // [sp+A0h] [bp-4h]@13
8164
8165 result = pRenderer->uTargetSurfacePitch;
8166 v2 = uFaceID;
8167 v95 = pRenderer->uTargetSurfacePitch;
8168 if ( (uFaceID & 0x80000000u) == 0 )
8169 {
8170 if ( (signed int)uFaceID < (signed int)pIndoor->uNumFaces )
8171 {
8172 v3 = &pIndoor->pFaces[uFaceID];
8173 v91 = &pIndoor->pFaces[uFaceID];
8174 if ( !pRenderer->pRenderD3D )
8175 {
8176 result = sub_423B5D(uFaceID);
8177 if ( result )
8178 {
8179 result = sub_424829(result, &stru_F8A590, pBLVRenderParams->field_7C, v2);
8180 if ( result )
8181 {
8182 result = (int)v3->GetTexture();
8183 v4 = (Texture *)result;
8184 v96 = (Texture *)result;
8185 if ( result )
8186 {
8187 v5 = *(short *)(result + 38);
8188 LOBYTE(v3->uAttributes) |= 0x80u;
8189 v92 = v5;
8190 sub_4AE5F1(v2);
8191 ++pBLVRenderParams->field_84;
8192 v6 = stru_F8AD28.pDeltaUV[0];
8193 v116 = stru_F8AD28.pDeltaUV[1];
8194 v7 = 0;
8195 for ( i = bUseLoResSprites; v7 < stru_F8AD28.field_AC; *(int *)v9 = v10 )
8196 {
8197 v8 = v116;
8198 stru_F8AD28._blv_lights_xs[v7] += v6;
8199 v9 = 4 * v7 + 16297672;
8200 v10 = v8 - stru_F8AD28._blv_lights_ys[v7++];
8201 }
8202 v94 = sr_sub_47C24C_get_palette(v3, v92, 0, 1);
8203 result = stru_F8A590._viewport_space_y;
8204 a2 = stru_F8A590._viewport_space_y;
8205 v11 = stru_F8A590._viewport_space_y * pRenderer->uTargetSurfacePitch;
8206 v99 = 640 * stru_F8A590._viewport_space_y;
8207 v86 = v4->pLevelOfDetail0;
8208 v87 = v4->pLevelOfDetail1;
8209 v88 = v4->pLevelOfDetail2;
8210 v89 = v4->pLevelOfDetail3;
8211 v98 = stru_F8A590._viewport_space_y * pRenderer->uTargetSurfacePitch;
8212 v104 = 2 * pBLVRenderParams->field_0_timer_;
8213 if ( stru_F8A590._viewport_space_y <= stru_F8A590.field_4 )
8214 {
8215 v12 = 2 * stru_F8A590._viewport_space_y;
8216 v101 = 2 * stru_F8A590._viewport_space_y;
8217 while ( 1 )
8218 {
8219 a1 = *(__int16 *)((char *)stru_F8A590.array_18 + v12);
8220 sub_4AE313(a1, result, &stru_F81018.field_0);
8221 if ( LOBYTE(viewparams->field_20) )
8222 {
8223 v15 = v95 * (v12 - pBLVRenderParams->uViewportY);
8224 v119 = &pBLVRenderParams->pTargetZBuffer[2
8225 * (*(__int16 *)((char *)stru_F8A590.array_18 + v12)
8226 + 320 * (v12 - pBLVRenderParams->uViewportY))
8227 - pBLVRenderParams->uViewportX];
8228 v16 = &pBLVRenderParams->pRenderTarget[v15
8229 + 2 * *(__int16 *)((char *)stru_F8A590.array_18 + v12)
8230 - pBLVRenderParams->uViewportX];
8231 v14 = &pBLVRenderParams->pRenderTarget[v15
8232 + 2 * *(__int16 *)((char *)stru_F8A590.array_3D8 + v12)
8233 - pBLVRenderParams->uViewportX];
8234 v123 = (unsigned int)v16;
8235 }
8236 else
8237 {
8238 v13 = *(__int16 *)((char *)stru_F8A590.array_18 + v12);
8239 v119 = &pBLVRenderParams->pTargetZBuffer[v13 + v99];
8240 v123 = (unsigned int)&pBLVRenderParams->pRenderTarget[v13 + v11];
8241 v14 = &pBLVRenderParams->pRenderTarget[v11 + *(__int16 *)((char *)stru_F8A590.array_3D8 + v12)];
8242 }
8243 v117 = (unsigned int)v14;
8244 HIWORD(v17) = HIWORD(stru_F81018.field_0.field_0);
8245 v18 = stru_F81018.field_0.field_10;
8246 LOWORD(v17) = 0;
8247 v97 = stru_F8AD28.field_0 | v17;
8248 v110 = sub_4AE491(SHIWORD(stru_F81018.field_0.field_4), SHIWORD(stru_F81018.field_0.field_8));
8249 v19 = stru_F81018.field_0.field_4 >> i;
8250 v20 = 11 - v18;
8251 v116 = stru_F81018.field_0.field_8 >> i;
8252 v21 = stru_F81018.field_0.field_8 >> i >> (11 - v18);
8253 v22 = stru_5C6E00;
8254 v122 = (unsigned __int16 *)v20;
8255 v121 = (stru_F81018.field_0.field_4 >> i) + 4 * stru_5C6E00->SinCos(v104 + v21);
8256 v23 = stru_5C6E00->SinCos(v104 + (v19 >> (char)v122) - stru_5C6E00->uIntegerHalfPi);
8257 v120 = v116 + 4 * v23;
8258 if ( v123 < v117 )
8259 {
8260 v24 = (char *)&stru_F81018.field_34.field_8;
8261 v114 = &stru_F81018.field_34.field_8;
8262 a1 += 16;
8263 while ( 1 )
8264 {
8265 sub_4AE313(a1, a2, (stru337_stru0 *)(v24 - 8));
8266 v25 = *((int *)v24 - 2);
8267 LOWORD(v25) = 0;
8268 v115 = v97;
8269 v26 = stru_F8AD28.field_0 | v25;
8270 if ( v97 <= (unsigned int)v26 )
8271 v115 = v26;
8272 v97 = v26;
8273 v27 = *((int *)v24 - 11);
8274 v28 = *((int *)v24 - 1);
8275 v105 = (&v86)[4 * v27];
8276 v111 = v27 + 16;
8277 v29 = v4->uWidthMinus1;
8278 v109 = v27 + v27 + 16 - v4->uWidthLn2;
8279 v107 = v29 >> v27;
8280 v30 = v28 >> i;
8281 v102 = v4->uHeightMinus1 >> v27 << (v27 + 16);
8282 v31 = *v114 >> i;
8283 v122 = (unsigned __int16 *)(11 - v27);
8284 v116 = v30 + 4 * stru_5C6E00->SinCos(v104 + (v31 >> (11 - v27)));
8285 v90 = v31 + 4 * stru_5C6E00->SinCos(v104 + (v30 >> (char)v122) - stru_5C6E00->uIntegerHalfPi);
8286 v108 = (signed int)(v116 - v121) >> 4;
8287 v103 = (v90 - v120) >> 4;
8288 v32 = v123 + 32;
8289 if ( LOBYTE(viewparams->field_20) )
8290 v32 = v123 + 64;
8291 if ( v32 > v117 )
8292 v32 = v117;
8293 v118 = v32;
8294 v100 = sub_4AE491(*((short *)v114 - 1), *((short *)v114 + 1));
8295 v106 = (signed int)(v32 - v123) >> 1;
8296 if ( v110 >> 16 == v100 >> 16 )
8297 {
8298 v122 = sr_sub_47C24C_get_palette(v91, v92, v110 >> 16, 1);
8299 if ( LOBYTE(viewparams->field_20) )
8300 {
8301 v44 = v123;
8302 if ( v123 < v118 )
8303 {
8304 v45 = v119;
8305 v46 = v122;
8306 v47 = v121;
8307 v48 = v120;
8308 v49 = v111;
8309 v50 = v109;
8310 if ( v106 & 2 )
8311 {
8312 *v119 = v115;
8313 v45 -= 2;
8314 v44 = v123 + 4;
8315 goto LABEL_37;
8316 }
8317 do
8318 {
8319 v44 += 8;
8320 v51 = *(&v105[v107 & (v47 >> v49)] + ((v102 & (unsigned int)v48) >> v50));
8321 v52 = v115;
8322 LOWORD(v51) = v46[v51];
8323 *v45 = v115;
8324 v45[1] = v52;
8325 v45[640] = v52;
8326 v45[641] = v52;
8327 *(short *)(v44 - 8) = v51;
8328 *(short *)(v44 - 6) = v51;
8329 *(short *)(v44 + 1272) = v51;
8330 *(short *)(v44 + 1274) = v51;
8331 v45[2] = v52;
8332 v45[3] = v52;
8333 v45[642] = v52;
8334 v45[643] = v52;
8335 v121 += v108;
8336 v120 += v103;
8337 v47 = v121;
8338 v48 = v120;
8339 LABEL_37:
8340 v45 += 4;
8341 v53 = v46[*(&v105[v107 & (v47 >> v49)] + ((v102 & (unsigned int)v48) >> v50))];
8342 v54 = v108;
8343 *(short *)(v44 - 4) = v53;
8344 *(short *)(v44 - 2) = v53;
8345 *(short *)(v44 + 1276) = v53;
8346 *(short *)(v44 + 1278) = v53;
8347 v121 += v54;
8348 v120 += v103;
8349 v47 = v121;
8350 v48 = v120;
8351 }
8352 while ( v44 < v118 );
8353 v123 = v44;
8354 v119 = v45;
8355 }
8356 }
8357 else
8358 {
8359 v33 = v123;
8360 if ( v123 < v118 )
8361 {
8362 v34 = v119;
8363 v35 = v122;
8364 v36 = v121;
8365 v37 = v120;
8366 v38 = v111;
8367 v39 = v109;
8368 if ( v106 & 1 )
8369 {
8370 *v119 = v115;
8371 --v34;
8372 v33 = v123 + 2;
8373 goto LABEL_30;
8374 }
8375 do
8376 {
8377 v33 += 4;
8378 v40 = *(&v105[v107 & (v36 >> v38)] + ((v102 & (unsigned int)v37) >> v39));
8379 v41 = v115;
8380 LOWORD(v40) = v35[v40];
8381 *v34 = v115;
8382 *(short *)(v33 - 4) = v40;
8383 v34[1] = v41;
8384 v121 += v108;
8385 v120 += v103;
8386 v36 = v121;
8387 v37 = v120;
8388 LABEL_30:
8389 v42 = (unsigned int)(&v105[v107 & (v36 >> v38)] + ((v102 & (unsigned int)v37) >> v39));
8390 v34 += 2;
8391 v43 = v108;
8392 *(short *)(v33 - 2) = v35[*(char *)v42];
8393 v121 += v43;
8394 v120 += v103;
8395 v36 = v121;
8396 v37 = v120;
8397 }
8398 while ( v33 < v118 );
8399 v123 = v33;
8400 v119 = v34;
8401 }
8402 }
8403 }
8404 else
8405 {
8406 v55 = v110 - ((v100 - v110) >> 4);
8407 v110 = (v100 - v110) >> 4;
8408 v122 = (unsigned __int16 *)v55;
8409 if ( LOBYTE(viewparams->field_20) )
8410 {
8411 v71 = v123;
8412 if ( v123 < v118 )
8413 {
8414 v72 = v119;
8415 v73 = v94;
8416 v74 = v121;
8417 v75 = v120;
8418 v76 = v111;
8419 v77 = v109;
8420 if ( v106 & 2 )
8421 {
8422 *v119 = v115;
8423 v72 += 2;
8424 v71 = v123 + 4;
8425 goto LABEL_52;
8426 }
8427 do
8428 {
8429 v78 = (v107 & (v74 >> v76)) + ((v102 & (unsigned int)v75) >> v77);
8430 v79 = (int)((char *)v122 + v110);
8431 v71 += 8;
8432 v122 = (unsigned __int16 *)v79;
8433 v80 = ((v79 & 0xFFFF0000u) >> 8) + v105[v78];
8434 v81 = v115;
8435 LOWORD(v80) = v73[v80];
8436 *v72 = v115;
8437 v72[1] = v81;
8438 v72[640] = v81;
8439 v72[641] = v81;
8440 *(short *)(v71 - 8) = v80;
8441 *(short *)(v71 - 6) = v80;
8442 *(short *)(v71 + 1272) = v80;
8443 *(short *)(v71 + 1274) = v80;
8444 v72[2] = v81;
8445 v72[3] = v81;
8446 v72[642] = v81;
8447 v72[643] = v81;
8448 v121 += v108;
8449 v120 += v103;
8450 v74 = v121;
8451 v75 = v120;
8452 v72 += 4;
8453 LABEL_52:
8454 v82 = (v107 & (v74 >> v76)) + ((v102 & (unsigned int)v75) >> v77);
8455 v83 = (int)((char *)v122 + v110);
8456 v84 = v105[v82];
8457 v122 = (unsigned __int16 *)v83;
8458 LOWORD(v84) = v73[((v83 & 0xFFFF0000u) >> 8) + v84];
8459 v85 = v108;
8460 *(short *)(v71 - 4) = v84;
8461 *(short *)(v71 - 2) = v84;
8462 *(short *)(v71 + 1276) = v84;
8463 *(short *)(v71 + 1278) = v84;
8464 v121 += v85;
8465 v120 += v103;
8466 v74 = v121;
8467 v75 = v120;
8468 }
8469 while ( v71 < v118 );
8470 v123 = v71;
8471 v119 = v72;
8472 }
8473 }
8474 else
8475 {
8476 v56 = v123;
8477 if ( v123 < v118 )
8478 {
8479 v57 = v119;
8480 v58 = v94;
8481 v59 = v121;
8482 v60 = v120;
8483 v61 = v111;
8484 v62 = v109;
8485 if ( v106 & 1 )
8486 {
8487 *v119 = v115;
8488 ++v57;
8489 v56 = v123 + 2;
8490 goto LABEL_45;
8491 }
8492 do
8493 {
8494 v63 = (v107 & (v59 >> v61)) + ((v102 & (unsigned int)v60) >> v62);
8495 v64 = (int)((char *)v122 + v110);
8496 v56 += 4;
8497 v122 = (unsigned __int16 *)v64;
8498 v65 = ((v64 & 0xFFFF0000u) >> 8) + v105[v63];
8499 v66 = v115;
8500 LOWORD(v65) = v58[v65];
8501 *v57 = v115;
8502 *(short *)(v56 - 4) = v65;
8503 v57[1] = v66;
8504 v121 += v108;
8505 v120 += v103;
8506 v59 = v121;
8507 v60 = v120;
8508 v57 += 2;
8509 LABEL_45:
8510 v67 = (v107 & (v59 >> v61)) + ((v102 & (unsigned int)v60) >> v62);
8511 v68 = (int)((char *)v122 + v110);
8512 v69 = v105[v67];
8513 v122 = (unsigned __int16 *)v68;
8514 LOWORD(v69) = v58[((v68 & 0xFFFF0000u) >> 8) + v69];
8515 v70 = v108;
8516 *(short *)(v56 - 2) = v69;
8517 v121 += v70;
8518 v120 += v103;
8519 v59 = v121;
8520 v60 = v120;
8521 }
8522 while ( v56 < v118 );
8523 v123 = v56;
8524 v119 = v57;
8525 }
8526 }
8527 }
8528 v114 += 13;
8529 v110 = v100;
8530 a1 += 16;
8531 v4 = v96;
8532 v121 = v116;
8533 v120 = v90;
8534 if ( v123 >= v117 )
8535 break;
8536 v24 = (char *)v114;
8537 v22 = stru_5C6E00;
8538 }
8539 }
8540 ++a2;
8541 v98 += v95;
8542 result = a2;
8543 v101 += 2;
8544 v99 += 640;
8545 if ( a2 > stru_F8A590.field_4 )
8546 break;
8547 v12 = v101;
8548 result = a2;
8549 v11 = v98;
8550 }
8551 }
8552 }
8553 }
8554 }
8555 }
8556 }
8557 }
8558 return result;
8559 }
8560 // 4AE491: using guessed type int __fastcall sub_4AE491(int, int);
8561
8562 //----- (004ADD1D) --------------------------------------------------------
8563 void __fastcall sub_4ADD1D(int uFaceID)
8564 {
8565 int v1; // edi@1
8566 BLVFace *v2; // esi@3
8567 signed int v3; // ebx@4
8568 Texture *v4; // edi@9
8569 signed int v5; // eax@9
8570 char *v6; // edi@12
8571 signed int v7; // eax@15
8572 unsigned int v8; // eax@16
8573 __int16 v9; // cx@19
8574 unsigned __int8 *v10; // eax@19
8575 unsigned __int16 *v11; // eax@19
8576 int v12; // edi@19
8577 int v13; // ebx@20
8578 stru352 *v14; // esi@20
8579 DWORD v15; // eax@22
8580 signed int v16; // ecx@22
8581 signed int v17; // ST68_4@22
8582 int v18; // eax@22
8583 int v19; // ecx@22
8584 unsigned int v20; // esi@23
8585 int v21; // edi@23
8586 int v22; // eax@23
8587 int *v23; // ebx@24
8588 int v24; // edx@24
8589 int v25; // ebx@25
8590 unsigned __int16 v26; // cx@25
8591 int v27; // edx@26
8592 unsigned __int16 v28; // cx@26
8593 unsigned __int8 v29; // sf@27
8594 unsigned __int8 v30; // of@27
8595 unsigned int v31; // esi@29
8596 int v32; // edi@29
8597 unsigned __int16 *v33; // eax@29
8598 int *v34; // ebx@30
8599 int v35; // edx@30
8600 int v36; // ebx@31
8601 unsigned __int16 v37; // cx@31
8602 int v38; // edx@32
8603 unsigned __int16 v39; // cx@32
8604 Texture *v40; // [sp-10h] [bp-6Ch]@16
8605 int v41; // [sp-Ch] [bp-68h]@15
8606 unsigned int v42; // [sp+10h] [bp-4Ch]@1
8607 signed int v43; // [sp+14h] [bp-48h]@12
8608 signed int v44; // [sp+14h] [bp-48h]@22
8609 int v45; // [sp+1Ch] [bp-40h]@22
8610 int v46; // [sp+20h] [bp-3Ch]@22
8611 int v47; // [sp+24h] [bp-38h]@19
8612 char v48; // [sp+28h] [bp-34h]@19
8613 int v49; // [sp+2Ch] [bp-30h]@19
8614 unsigned __int8 *v50; // [sp+30h] [bp-2Ch]@19
8615 unsigned __int16 *v51; // [sp+34h] [bp-28h]@19
8616 int v52; // [sp+38h] [bp-24h]@22
8617 int v53; // [sp+3Ch] [bp-20h]@22
8618 signed int v54; // [sp+40h] [bp-1Ch]@12
8619 int v55; // [sp+40h] [bp-1Ch]@20
8620 int v56; // [sp+44h] [bp-18h]@20
8621 stru352 *i; // [sp+48h] [bp-14h]@20
8622 unsigned __int16 *v58; // [sp+4Ch] [bp-10h]@23
8623 int v59; // [sp+50h] [bp-Ch]@4
8624 int v60; // [sp+50h] [bp-Ch]@19
8625 int v61; // [sp+54h] [bp-8h]@22
8626 int *v62; // [sp+58h] [bp-4h]@23
8627 int *v63; // [sp+58h] [bp-4h]@29
8628
8629 v1 = uFaceID;
8630 v42 = pRenderer->uTargetSurfacePitch;
8631 if ( uFaceID >= 0 && uFaceID < (signed int)pIndoor->uNumFaces )
8632 {
8633 v2 = &pIndoor->pFaces[uFaceID];
8634 if ( pRenderer->pRenderD3D )
8635 {
8636 v3 = sub_424579(uFaceID, &stru_F8AD28);
8637 v59 = v3;
8638 }
8639 else
8640 {
8641 v59 = sub_423B5D(uFaceID);
8642 v3 = v59;
8643 }
8644 if ( v3 && (pRenderer->pRenderD3D || sub_424829(v3, &stru_F8A590, pBLVRenderParams->field_7C, v1)) )
8645 {
8646 v4 = v2->GetTexture();
8647 v5 = 0;
8648 if ( v4 )
8649 {
8650 if ( pRenderer->pRenderD3D )
8651 {
8652 if ( v3 > 0 )
8653 {
8654 v54 = v3;
8655 v43 = v3;
8656 v6 = (char *)&array_507D30[0].v;
8657 do
8658 {
8659 *((float *)v6 - 1) = (double)((GetTickCount() >> 5) - pBLVRenderParams->vPartyPos.x) + *((float *)v6 - 1);
8660 *(float *)v6 = (double)(pBLVRenderParams->vPartyPos.y + (GetTickCount() >> 5)) + *(float *)v6;
8661 v6 += 48;
8662 --v54;
8663 }
8664 while ( v54 );
8665 v3 = v59;
8666 v5 = v43;
8667 }
8668 v7 = v5;
8669 v41 = stru_F8AD28.field_0;
8670 array_507D30[v7].u = array_507D30[v7].u * 0.25;
8671 array_507D30[v7].v = array_507D30[v7].v * 0.25;
8672 if ( BYTE1(v2->uAttributes) & 0x40 )
8673 {
8674 v40 = v2->GetTexture();
8675 v8 = pTextureFrameTable->GetFrameTexture(v2->uBitmapID, pBLVRenderParams->field_0_timer_);
8676 }
8677 else
8678 {
8679 v40 = v2->GetTexture();
8680 v8 = v2->uBitmapID;
8681 }
8682 pRenderer->DrawIndoorPolygon(v3, v2, pBitmaps_LOD->pHardwareTextures[v8], v40, v41, -1, 0);
8683 }
8684 else
8685 {
8686 v49 = v4->uWidthMinus1;
8687 v47 = v4->uHeightMinus1 << 16;
8688 v9 = 16 - v4->uWidthLn2;
8689 v10 = v4->pLevelOfDetail0;
8690 LOBYTE(v2->uAttributes) |= 0x80u;
8691 v48 = v9;
8692 v50 = v10;
8693 sub_4AF412();
8694 ++pBLVRenderParams->field_80;
8695 v11 = sr_sub_47C24C_get_palette(v2, HIWORD(v4->palette), 0, 1);
8696 v12 = stru_F8A590._viewport_space_y;
8697 v51 = v11;
8698 v60 = stru_F8A590._viewport_space_y;
8699 if ( stru_F8A590._viewport_space_y <= stru_F8A590.field_4 )
8700 {
8701 v13 = 2 * stru_F8A590._viewport_space_y;
8702 v14 = &stru_F83B80[stru_F8A590._viewport_space_y];
8703 v55 = 2 * stru_F8A590._viewport_space_y;
8704 v56 = 640 * stru_F8A590._viewport_space_y;
8705 for ( i = &stru_F83B80[stru_F8A590._viewport_space_y]; ; v14 = i )
8706 {
8707 sub_4AE1E7(v12, *(__int16 *)((char *)stru_F8A590.array_18 + v13), v12);
8708 v14->field_0 += (GetTickCount() << 11) - (pBLVRenderParams->vPartyPos.x << 16);
8709 v15 = GetTickCount();
8710 v16 = v14->field_0;
8711 v14->field_4 += (32 * pBLVRenderParams->vPartyPos.y + v15) << 11;
8712 v45 = v14->field_4 >> 3;
8713 v44 = v16 >> 3;
8714 v17 = (signed int)((unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)v14->field_28) >> 16) >> 3;
8715 v52 = (unsigned __int64)(v17 * (signed __int64)-pBLVRenderParams->sSineY) >> 16;
8716 v53 = (unsigned __int64)(v17 * (signed __int64)pBLVRenderParams->sCosineY) >> 16;
8717 v18 = v14->field_28;
8718 v19 = *(__int16 *)((char *)stru_F8A590.array_18 + v13);
8719 LOWORD(v18) = 0;
8720 v46 = stru_F8AD28.field_0 | v18;
8721 v61 = *(__int16 *)((char *)stru_F8A590.array_3D8 + v13) - v19;
8722 if ( LOBYTE(viewparams->field_20) )
8723 {
8724 v63 = &pBLVRenderParams->pTargetZBuffer[2 * (v19 + 320 * (v13 - pBLVRenderParams->uViewportY))
8725 - pBLVRenderParams->uViewportX];
8726 v31 = v44;
8727 v32 = v45;
8728 v33 = &pBLVRenderParams->pRenderTarget[v42 * (v13 - pBLVRenderParams->uViewportY)
8729 + 2 * v19
8730 - pBLVRenderParams->uViewportX];
8731 if ( v61 & 1 )
8732 {
8733 --v61;
8734 v33 = &pBLVRenderParams->pRenderTarget[v42 * (v13 - pBLVRenderParams->uViewportY)
8735 + 2 * v19
8736 - pBLVRenderParams->uViewportX
8737 - 2];
8738 v34 = &pBLVRenderParams->pTargetZBuffer[2 * (v19 + 320 * (v13 - pBLVRenderParams->uViewportY))
8739 - pBLVRenderParams->uViewportX];
8740 v35 = v46;
8741 v63 += 2;
8742 goto LABEL_32;
8743 }
8744 while ( 1 )
8745 {
8746 v30 = __OFSUB__(v61, 2);
8747 v29 = v61 - 2 < 0;
8748 v61 -= 2;
8749 if ( v29 ^ v30 )
8750 break;
8751 v36 = *(&v50[v49 & (v31 >> 16)] + ((v47 & (unsigned int)v32) >> v48));
8752 v31 += v52;
8753 v37 = v51[v36];
8754 v32 += v53;
8755 v34 = v63;
8756 v35 = v46;
8757 *v33 = v37;
8758 v33[1] = v37;
8759 v33[640] = v37;
8760 v33[641] = v37;
8761 v63 += 4;
8762 v34[2] = v46;
8763 v34[3] = v46;
8764 v34[642] = v46;
8765 v34[643] = v46;
8766 LABEL_32:
8767 *v34 = v35;
8768 v34[1] = v35;
8769 v34[640] = v35;
8770 v34[641] = v35;
8771 v38 = v49 & (v31 >> 16);
8772 v33 += 4;
8773 v31 += v52;
8774 v39 = v51[*(&v50[v38] + ((v47 & (unsigned int)v32) >> v48))];
8775 v32 += v53;
8776 *(v33 - 2) = v39;
8777 *(v33 - 1) = v39;
8778 v33[638] = v39;
8779 v33[639] = v39;
8780 }
8781 }
8782 else
8783 {
8784 v58 = &pBLVRenderParams->pRenderTarget[v19 + v12 * pRenderer->uTargetSurfacePitch];
8785 v62 = &pBLVRenderParams->pTargetZBuffer[v56 + v19];
8786 v20 = v44;
8787 v21 = v45;
8788 v22 = (int)v58;
8789 if ( v61 & 1 )
8790 {
8791 --v61;
8792 v22 = (int)(v58 - 1);
8793 v23 = &pBLVRenderParams->pTargetZBuffer[v56 + v19];
8794 v24 = v46;
8795 ++v62;
8796 goto LABEL_26;
8797 }
8798 while ( 1 )
8799 {
8800 v30 = __OFSUB__(v61, 2);
8801 v29 = v61 - 2 < 0;
8802 v61 -= 2;
8803 if ( v29 ^ v30 )
8804 break;
8805 v25 = *(&v50[v49 & (v20 >> 16)] + ((v47 & (unsigned int)v21) >> v48));
8806 v20 += v52;
8807 v26 = v51[v25];
8808 v21 += v53;
8809 v23 = v62;
8810 v24 = v46;
8811 *(short *)v22 = v26;
8812 v62 += 2;
8813 v23[1] = v46;
8814 LABEL_26:
8815 *v23 = v24;
8816 v27 = v49 & (v20 >> 16);
8817 v22 += 4;
8818 v20 += v52;
8819 v28 = v51[*(&v50[v27] + ((v47 & (unsigned int)v21) >> v48))];
8820 v21 += v53;
8821 *(short *)(v22 - 2) = v28;
8822 }
8823 }
8824 ++v60;
8825 ++i;
8826 v56 += 640;
8827 v55 += 2;
8828 if ( v60 > stru_F8A590.field_4 )
8829 break;
8830 v13 = v55;
8831 v12 = v60;
8832 }
8833 }
8834 }
8835 }
8836 }
8837 }
8838 }
8839
8840 //----- (004AE1E7) --------------------------------------------------------
8841 int __fastcall sub_4AE1E7(int a1, int a2, int a3)
8842 {
8843 int v3; // ebx@1
8844 int v4; // edi@1
8845 int v5; // esi@1
8846 signed __int64 v6; // qtt@3
8847 int v7; // esi@3
8848 int v8; // eax@5
8849 int result; // eax@5
8850 int v10; // edx@5
8851 int v11; // [sp+Ch] [bp-8h]@1
8852 int v12; // [sp+1Ch] [bp+8h]@2
8853
8854 v3 = pBLVRenderParams->uViewportCenterY - a3;
8855 v4 = pBLVRenderParams->uViewportCenterX - a2;
8856 v11 = a1;
8857 v5 = (pBLVRenderParams->uViewportCenterY - a3) * stru_F8AD28.vec_80.y
8858 + stru_F8AD28.field_7C
8859 + (pBLVRenderParams->uViewportCenterX - a2) * stru_F8AD28.vec_80.x;
8860 if ( v5 && (v12 = abs(stru_F8AD28.vec_80.z) >> 14, v12 <= abs(v5)) )
8861 {
8862 LODWORD(v6) = stru_F8AD28.vec_80.z << 16;
8863 HIDWORD(v6) = stru_F8AD28.vec_80.z >> 16;
8864 v7 = v6 / (v3 * stru_F8AD28.vec_80.y + stru_F8AD28.field_7C + v4 * stru_F8AD28.vec_80.x);
8865 }
8866 else
8867 {
8868 v7 = 1073741824;
8869 }
8870 v8 = stru_F8AD28.vec_9C.z;
8871 stru_F83B80[v11].field_0 = ((unsigned __int64)((v3 * stru_F8AD28.vec_8C.z
8872 + stru_F8AD28.vec_8C.x
8873 + v4 * stru_F8AD28.vec_8C.y)
8874 * (signed __int64)v7) >> 16)
8875 + stru_F8AD28.field_98;
8876 result = (unsigned __int64)((v3 * v8 + stru_F8AD28.vec_9C.x + v4 * stru_F8AD28.vec_9C.y) * (signed __int64)v7) >> 16;
8877 v10 = result + stru_F8AD28.field_A8;
8878 stru_F83B80[v11].field_28 = v7;
8879 stru_F83B80[v11].field_4 = v10;
8880 return result;
8881 }
8882
8883 //----- (004AE313) --------------------------------------------------------
8884 int __fastcall sub_4AE313(int viewport_space_x, int viewport_space_y, stru337_stru0 *p)
8885 {
8886 int _dy; // ebx@1
8887 int _dx; // edi@1
8888 int v5; // ecx@1
8889 int v6; // esi@1
8890 int v7; // ST18_4@2
8891 signed __int64 v8; // qtt@3
8892 unsigned int v9; // ecx@3
8893 int result; // eax@8
8894 int v11; // [sp+Ch] [bp-8h]@1
8895
8896 _dy = pBLVRenderParams->uViewportCenterY - viewport_space_y;
8897 _dx = pBLVRenderParams->uViewportCenterX - viewport_space_x;
8898 ++pBLVRenderParams->field_88;
8899 v5 = (pBLVRenderParams->uViewportCenterY - viewport_space_y) * stru_F8AD28.vec_80.y + stru_F8AD28.field_7C;
8900 v6 = v5 + _dx * stru_F8AD28.vec_80.x;
8901 v11 = v5 + _dx * stru_F8AD28.vec_80.x;
8902 if ( v5 + _dx * stru_F8AD28.vec_80.x && (v7 = abs(stru_F8AD28.vec_80.z) >> 14, v7 <= abs(v6)) )
8903 {
8904 LODWORD(v8) = stru_F8AD28.vec_80.z << 16;
8905 HIDWORD(v8) = stru_F8AD28.vec_80.z >> 16;
8906 v9 = v8 / v11;
8907 }
8908 else
8909 {
8910 v9 = 0x40000000u;
8911 }
8912 if ( (signed int)v9 >= stru_F8AD28.field_34 )
8913 p->field_0 = v9;
8914 else
8915 p->field_0 = stru_F8AD28.field_34;
8916 p->field_4 = ((unsigned __int64)((_dy * stru_F8AD28.vec_8C.z + stru_F8AD28.vec_8C.x + _dx * stru_F8AD28.vec_8C.y)
8917 * (signed __int64)(signed int)v9) >> 16)
8918 + stru_F8AD28.field_98
8919 + (stru_F8AD28.pDeltaUV[0] << 16);
8920 p->field_8 = ((unsigned __int64)((_dy * stru_F8AD28.vec_9C.z + stru_F8AD28.vec_9C.x + _dx * stru_F8AD28.vec_9C.y)
8921 * (signed __int64)(signed int)v9) >> 16)
8922 + stru_F8AD28.field_A8
8923 + (stru_F8AD28.pDeltaUV[1] << 16);
8924 result = abs((__int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)(signed int)v9) >> 16);
8925 if ( result < 369620 || bUseLoResSprites )
8926 {
8927 if ( result < 184810 )
8928 p->field_10 = result > 92405;
8929 else
8930 p->field_10 = 2;
8931 }
8932 else
8933 {
8934 p->field_10 = 3;
8935 }
8936 return result;
8937 }
8938
8939 //----- (004AE491) --------------------------------------------------------
8940 int __fastcall sub_4AE491(signed int a1, signed int a2)
8941 {
8942 signed int v2; // eax@1
8943 signed int v3; // edi@1
8944 int v4; // ecx@1
8945 int v5; // esi@2
8946 int v6; // eax@2
8947 int v7; // ebx@2
8948 unsigned int v8; // ecx@2
8949 int v9; // edx@5
8950 int v10; // edx@7
8951 unsigned int v11; // eax@8
8952 int v13; // [sp+4h] [bp-18h]@2
8953 int v14; // [sp+8h] [bp-14h]@2
8954 signed int v15; // [sp+Ch] [bp-10h]@1
8955 int v16; // [sp+14h] [bp-8h]@1
8956 int v17; // [sp+18h] [bp-4h]@1
8957
8958 v2 = a1 >> SLOBYTE(stru_F8AD28.field_38);
8959 v3 = a2 >> SLOBYTE(stru_F8AD28.field_38);
8960 v17 = stru_F8AD28.field_2C;
8961 v4 = 0;
8962 v15 = v2;
8963 v16 = 0;
8964 if ( stru_F8AD28.field_AC > 0 )
8965 {
8966 do
8967 {
8968 v5 = v16;
8969 v13 = abs(v2 - stru_F8AD28._blv_lights_xs[v16]);
8970 v14 = abs(v3 - stru_F8AD28._blv_lights_ys[v16]);
8971 v6 = stru_F8AD28._blv_lights_light_dot_faces[v16];
8972 v7 = v13;
8973 v8 = v14;
8974 if ( v6 < v13 )
8975 {
8976 v6 = v13;
8977 v7 = stru_F8AD28._blv_lights_light_dot_faces[v16];
8978 }
8979 if ( v6 < v14 )
8980 {
8981 v9 = v6;
8982 v6 = v14;
8983 v8 = v9;
8984 }
8985 if ( v7 < (signed int)v8 )
8986 {
8987 v10 = v8;
8988 v8 = v7;
8989 v7 = v10;
8990 }
8991 v11 = ((unsigned int)(11 * v7) >> 5) + (v8 >> 2) + v6;
8992 if ( (signed int)v11 < stru_F8AD28._blv_lights_radii[v5] )
8993 v17 += 30 * (v11 * stru_F8AD28._blv_lights_inv_radii[v5] - 65536);
8994 ++v16;
8995 v2 = v15;
8996 }
8997 while ( v16 < stru_F8AD28.field_AC );
8998 v4 = 0;
8999 }
9000 if ( stru_F8AD28.field_3E4 != v4 )
9001 v17 -= stru_F8AD28.field_3E8 * (v2 - stru_F8AD28.field_3F0) + stru_F8AD28.field_3EC * (v3 - stru_F8AD28.field_3F4);
9002 if ( v17 >= v4 )
9003 {
9004 if ( v17 > 2031616 )
9005 v17 = 2031616;
9006 }
9007 else
9008 {
9009 v17 = v4;
9010 }
9011 ++pBLVRenderParams->field_8C;
9012 return v17;
9013 }
9014 // 4AE491: using guessed type int __fastcall sub_4AE491(int, int);
9015
9016
9017
9018
9019 //----- (004AE5F1) --------------------------------------------------------
9020 void __fastcall sub_4AE5F1(unsigned int uFaceID)
9021 {
9022 BLVFace *v1; // esi@1
9023 BLVFaceExtra *v2; // ebx@1
9024 int v3; // eax@1
9025 int v4; // edi@1
9026 Texture *v5; // edi@1
9027 int v6; // eax@1
9028 unsigned int v7; // eax@1
9029 unsigned int v8; // ecx@1
9030 unsigned int v9; // eax@1
9031 unsigned int v10; // ecx@5
9032 int v11; // edi@10
9033 int v12; // ecx@10
9034 int v13; // eax@10
9035 int v14; // edx@10
9036 int v15; // ebx@12
9037 double v16; // st7@16
9038 int v17; // eax@16
9039 char *v18; // ebx@17
9040 int v19; // ecx@19
9041 int v20; // eax@19
9042 int v21; // edx@21
9043 int v22; // eax@23
9044 int v23; // ST04_4@26
9045 int v24; // edi@26
9046 double v25; // st6@26
9047 int v26; // eax@26
9048 double v27; // st6@26
9049 int v28; // ecx@26
9050 char v29; // al@26
9051 int v30; // edx@28
9052 int v31; // ecx@28
9053 BLVLightMM7 *v32; // ecx@32
9054 int v33; // edi@33
9055 int v34; // edx@33
9056 int v35; // eax@33
9057 int v36; // edi@35
9058 int v37; // edx@37
9059 int v38; // ebx@39
9060 int v39; // edi@42
9061 int v40; // eax@42
9062 char *v41; // ebx@45
9063 signed int v42; // ecx@47
9064 int v43; // edi@47
9065 int v44; // eax@49
9066 int v45; // edx@51
9067 int v46; // eax@53
9068 int v47; // ST04_4@55
9069 int v48; // edi@55
9070 double v49; // st6@55
9071 int v50; // eax@55
9072 double v51; // st6@55
9073 int v52; // eax@55
9074 int v53; // ecx@57
9075 int v54; // ecx@58
9076 int v55; // ecx@59
9077 int v56; // edx@62
9078 int v57; // ecx@62
9079 int v58; // eax@63
9080 int v59; // edx@64
9081 int v60; // ecx@67
9082 int v61; // edx@67
9083 int v62; // eax@68
9084 int v63; // edx@69
9085 signed int v64; // ecx@72
9086 double v65; // st7@75
9087 Vec3_int_ v66; // [sp+Ch] [bp-34h]@9
9088 Vec3_int_ v67; // [sp+18h] [bp-28h]@9
9089 BLVFaceExtra *v68; // [sp+24h] [bp-1Ch]@1
9090 int v69; // [sp+28h] [bp-18h]@10
9091 int v70; // [sp+2Ch] [bp-14h]@10
9092 int X; // [sp+30h] [bp-10h]@10
9093 int v72; // [sp+34h] [bp-Ch]@10
9094 int v73; // [sp+38h] [bp-8h]@10
9095 int v74; // [sp+3Ch] [bp-4h]@10
9096
9097 v1 = &pIndoor->pFaces[uFaceID];
9098 v2 = &pIndoor->pFaceExtras[v1->uFaceExtraID];
9099 v3 = v1->uBitmapID;
9100 v4 = v1->uBitmapID;
9101 v68 = v2;
9102 v5 = (Texture *)(v4 != -1 ? (int)&pBitmaps_LOD->pTextures[v3] : 0);
9103 v6 = 8 * uFaceID;
9104 LOBYTE(v6) = 8 * uFaceID | 6;
9105 stru_F8AD28.field_0 = v6;
9106 stru_F8AD28.plane_4.vNormal.x = v1->pFacePlane_old.vNormal.x;
9107 stru_F8AD28.plane_4.vNormal.y = v1->pFacePlane_old.vNormal.y;
9108 stru_F8AD28.plane_4.vNormal.z = v1->pFacePlane_old.vNormal.z;
9109 stru_F8AD28.plane_4.dist = v1->pFacePlane_old.dist;
9110 stru_F8AD28.pDeltaUV[0] = v2->sTextureDeltaU;
9111 stru_F8AD28.pDeltaUV[1] = v2->sTextureDeltaV;
9112 v7 = GetTickCount();
9113 v8 = v1->uAttributes;
9114 v9 = v7 >> 3;
9115 if ( v8 & 4 )
9116 {
9117 stru_F8AD28.pDeltaUV[1] -= v9 & v5->uHeightMinus1;
9118 }
9119 else
9120 {
9121 if ( v8 & 0x20 )
9122 stru_F8AD28.pDeltaUV[1] += v9 & v5->uHeightMinus1;
9123 }
9124 v10 = v1->uAttributes;
9125 if ( BYTE1(v10) & 8 )
9126 {
9127 stru_F8AD28.pDeltaUV[0] -= v9 & v5->uWidthMinus1;
9128 }
9129 else
9130 {
9131 if ( v10 & 0x40 )
9132 stru_F8AD28.pDeltaUV[0] += v9 & v5->uWidthMinus1;
9133 }
9134 v1->_get_normals(&v67, &v66);
9135 stru_F8AD28.vec_14.x = v67.x;
9136 stru_F8AD28.vec_14.y = v67.y;
9137 stru_F8AD28.vec_14.z = v67.z;
9138 stru_F8AD28.vec_20.x = v66.x;
9139 stru_F8AD28.vec_20.y = v66.y;
9140 stru_F8AD28.vec_20.z = v66.z;
9141 stru_F8AD28.field_3F8 = v2->field_22;
9142 if ( pBLVRenderParams->sPartyRotX )
9143 {
9144 v74 = (unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)pBLVRenderParams->sSineY) >> 16;
9145 v74 = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16) - v74;
9146 X = (unsigned __int64)(stru_F8AD28.plane_4.vNormal.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16;
9147 stru_F8AD28.rotated_normal.x = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16) - X;
9148 stru_F8AD28.rotated_normal.y = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
9149 * (signed __int64)pBLVRenderParams->sSineY) >> 16)
9150 + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
9151 * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
9152 stru_F8AD28.rotated_normal.z = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
9153 + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.z
9154 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
9155 v70 = (unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sSineY) >> 16;
9156 v74 = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16) - v70;
9157 v70 = (unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16;
9158 stru_F8AD28.vec_60.y = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16) - v70;
9159 stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
9160 + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
9161 stru_F8AD28.field_6C = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
9162 + ((unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
9163 v70 = (unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sSineY) >> 16;
9164 v74 = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16) - v70;
9165 X = (unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sSineY) >> 16;
9166 v72 = (unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16;
9167 v70 = (unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16;
9168 stru_F8AD28.vec_70.x = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16) - v70;
9169 stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
9170 + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
9171 stru_F8AD28.vec_70.z = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
9172 + ((unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
9173 v74 = pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.y
9174 - pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.x;
9175 v11 = -(pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.y
9176 + pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.x);
9177 v73 = -65536 * pBLVRenderParams->vPartyPos.z;
9178 v70 = (unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16;
9179 v12 = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16) - v70;
9180 v69 = (unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16;
9181 v13 = pBLVRenderParams->vPartyPos.y;
9182 v70 = ((unsigned __int64)(v74 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
9183 + ((unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
9184 v14 = pBLVRenderParams->vPartyPos.x;
9185 }
9186 else
9187 {
9188 v70 = (unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)pBLVRenderParams->sSineY) >> 16;
9189 stru_F8AD28.rotated_normal.x = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
9190 * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
9191 - v70;
9192 stru_F8AD28.rotated_normal.z = stru_F8AD28.plane_4.vNormal.z;
9193 stru_F8AD28.rotated_normal.y = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
9194 * (signed __int64)pBLVRenderParams->sSineY) >> 16)
9195 + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
9196 * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
9197 v70 = (unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sSineY) >> 16;
9198 stru_F8AD28.vec_60.y = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
9199 - v70;
9200 stru_F8AD28.field_6C = stru_F8AD28.vec_14.z;
9201 stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
9202 + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
9203 v70 = (unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sSineY) >> 16;
9204 stru_F8AD28.vec_70.x = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
9205 - v70;
9206 v69 = (unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sSineY) >> 16;
9207 v14 = pBLVRenderParams->vPartyPos.x;
9208 stru_F8AD28.vec_70.z = stru_F8AD28.vec_20.z;
9209 v13 = pBLVRenderParams->vPartyPos.y;
9210 stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
9211 + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
9212 v12 = pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.y
9213 - pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.x;
9214 v11 = -(pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.y
9215 + pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.x);
9216 v70 = -65536 * pBLVRenderParams->vPartyPos.z;
9217 }
9218 stru_F8AD28.field_7C = stru_F8AD28.rotated_normal.x;
9219 stru_F8AD28.vec_60.x = stru_F8AD28.plane_4.vNormal.z * pBLVRenderParams->vPartyPos.z
9220 + stru_F8AD28.plane_4.dist
9221 + stru_F8AD28.plane_4.vNormal.y * v13
9222 + stru_F8AD28.plane_4.vNormal.x * v14;
9223 stru_F8AD28.vec_80.x = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44)
9224 * (signed __int64)stru_F8AD28.rotated_normal.y) >> 16;
9225 stru_F8AD28.vec_80.y = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44)
9226 * (signed __int64)stru_F8AD28.rotated_normal.z) >> 16;
9227 stru_F8AD28.vec_80.z = -stru_F8AD28.vec_60.x;
9228 stru_F8AD28.vec_8C.x = stru_F8AD28.vec_60.y;
9229 stru_F8AD28.vec_8C.y = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.vec_60.z) >> 16;
9230 stru_F8AD28.vec_8C.z = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.field_6C) >> 16;
9231 X = (unsigned __int64)(stru_F8AD28.vec_60.y * (signed __int64)v12) >> 16;
9232 v15 = v70;
9233 v70 = (unsigned __int64)(stru_F8AD28.field_6C * (signed __int64)v70) >> 16;
9234 stru_F8AD28.vec_9C.x = stru_F8AD28.vec_70.x;
9235 stru_F8AD28.field_98 = -(X + ((unsigned __int64)(stru_F8AD28.vec_60.z * (signed __int64)v11) >> 16) + v70);
9236 stru_F8AD28.vec_9C.y = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.vec_70.y) >> 16;
9237 stru_F8AD28.vec_9C.z = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.vec_70.z) >> 16;
9238 X = (unsigned __int64)(stru_F8AD28.vec_70.x * (signed __int64)v12) >> 16;
9239 v69 = (unsigned __int64)(stru_F8AD28.vec_70.y * (signed __int64)v11) >> 16;
9240 v70 = (unsigned __int64)(stru_F8AD28.vec_70.z * (signed __int64)v15) >> 16;
9241 stru_F8AD28.field_38 = 0;
9242 stru_F8AD28.field_A8 = -(X
9243 + ((unsigned __int64)(stru_F8AD28.vec_70.y * (signed __int64)v11) >> 16)
9244 + ((unsigned __int64)(stru_F8AD28.vec_70.z * (signed __int64)v15) >> 16));
9245 if ( *(int *)&v68->field_4 || *(int *)&v68->field_8 )
9246 {
9247 stru_F8AD28.field_3E4 = 1;
9248 stru_F8AD28.field_3E8 = *(int *)&v68->field_4;
9249 stru_F8AD28.field_3EC = *(int *)&v68->field_8;
9250 stru_F8AD28.field_3F0 = v68->field_1E;
9251 stru_F8AD28.field_3F4 = v68->field_20;
9252 }
9253 else
9254 {
9255 stru_F8AD28.field_3E4 = 0;
9256 }
9257 v16 = 0.0039215689;
9258 v17 = 116 * v1->uSectorID;
9259 v69 = v17;
9260 v74 = 0;
9261 v73 = 0;
9262 stru_F8AD28.field_2C = (stru_F8AD28.field_3F8 + *(__int16 *)((char *)&pIndoor->pSectors->uMinAmbientLightLevel + v17)) << 16;
9263 v70 = uNumMobileLightsApplied;
9264 if ( uNumMobileLightsApplied > 0 )
9265 {
9266 v18 = (char *)&pMobileLights[0].vPosition.y;
9267 do
9268 {
9269 if ( v74 >= 20 )
9270 break;
9271 v19 = *((short *)v18 + 2);
9272 v20 = *((short *)v18 - 1);
9273 if ( v20 > v1->pBounding.x1 - v19 )
9274 {
9275 if ( v20 < v19 + v1->pBounding.x2 )
9276 {
9277 v21 = *(short *)v18;
9278 if ( v21 > v1->pBounding.y1 - v19 )
9279 {
9280 if ( v21 < v19 + v1->pBounding.y2 )
9281 {
9282 v22 = *((short *)v18 + 1);
9283 if ( v22 > v1->pBounding.z1 - v19 )
9284 {
9285 if ( v22 < v19 + v1->pBounding.z2 )
9286 {
9287 X = (v1->pFacePlane_old.dist
9288 + *((short *)v18 + 1) * v1->pFacePlane_old.vNormal.z
9289 + v21 * v1->pFacePlane_old.vNormal.y
9290 + *((short *)v18 - 1) * v1->pFacePlane_old.vNormal.x) >> 16;
9291 if ( X <= v19 )
9292 {
9293 v23 = X;
9294 v24 = v74;
9295 stru_F8AD28._blv_lights_radii[v74] = v19;
9296 stru_F8AD28._blv_lights_inv_radii[v24] = 65536 / v19;
9297 *(int *)((char *)&stru_F8AD28.field_240 + v24 * 4) = *((short *)v18 + 5) << 16;
9298 stru_F8AD28._blv_lights_xs[v24] = *((short *)v18 - 1);
9299 stru_F8AD28._blv_lights_ys[v24] = *(short *)v18;
9300 stru_F8AD28._blv_lights_zs[v24] = *((short *)v18 + 1);
9301 v68 = (BLVFaceExtra *)(unsigned __int8)v18[6];
9302 v25 = (double)(signed int)v68 * v16;
9303 v68 = (BLVFaceExtra *)(unsigned __int8)v18[7];
9304 v26 = (unsigned __int8)v18[8];
9305 *(float *)(v24 * 4 + 16297992) = v25;
9306 v27 = (double)(signed int)v68;
9307 v68 = (BLVFaceExtra *)v26;
9308 *(float *)(v24 * 4 + 16298072) = v27 * v16;
9309 *(float *)(v24 * 4 + 16298152) = (double)(signed int)v68 * v16;
9310 v16 = 0.0039215689;
9311 stru_F8AD28._blv_lights_light_dot_faces[v24] = abs(v23);
9312 v28 = v74;
9313 v29 = v18[9];
9314 ++v74;
9315 stru_F8AD28._blv_lights_smthngs[v28] = v29;
9316 }
9317 }
9318 }
9319 }
9320 }
9321 }
9322 }
9323 ++v73;
9324 v18 += 18;
9325 v17 = v69;
9326 }
9327 while ( v73 < v70 );
9328 }
9329 v30 = 0;
9330 v73 = 0;
9331 v31 = *(__int16 *)((char *)&pIndoor->pSectors->uNumLights + v17);
9332 v70 = *(__int16 *)((char *)&pIndoor->pSectors->uNumLights + v17);
9333 if ( v31 > 0 )
9334 {
9335 while ( v74 < 20 )
9336 {
9337 v32 = &pIndoor->pLights[*(&(*(BLVLightMM7 **)((char *)&pIndoor->pSectors->pLights + v17))->vPosition.x + v30)];
9338 if ( !(v32->uAtributes & 8) )
9339 {
9340 v33 = v1->pBounding.x1;
9341 v34 = v32->vPosition.x;
9342 X = v32->uBrightness;
9343 v35 = v32->uRadius;
9344 v68 = (BLVFaceExtra *)v32->uRadius;
9345 if ( v34 > v33 - v35 )
9346 {
9347 if ( v34 < v35 + v1->pBounding.x2 )
9348 {
9349 v36 = v32->vPosition.y;
9350 if ( v36 > v1->pBounding.y1 - v35 )
9351 {
9352 if ( v36 < v35 + v1->pBounding.y2 )
9353 {
9354 v37 = v32->vPosition.z;
9355 if ( v37 > v1->pBounding.z1 - v35 )
9356 {
9357 if ( v37 < v35 + v1->pBounding.z2 )
9358 {
9359 v38 = (v1->pFacePlane_old.dist
9360 + v32->vPosition.x * v1->pFacePlane_old.vNormal.x
9361 + v37 * v1->pFacePlane_old.vNormal.z
9362 + v36 * v1->pFacePlane_old.vNormal.y) >> 16;
9363 if ( v38 >= 0 )
9364 {
9365 if ( v38 <= v35 && v35 )
9366 {
9367 v39 = v74;
9368 stru_F8AD28._blv_lights_radii[v74] = v35;
9369 stru_F8AD28._blv_lights_inv_radii[v39] = 65536 / (signed int)v68;
9370 *(int *)((char *)&stru_F8AD28.field_240 + v39 * 4) = X << 16;
9371 stru_F8AD28._blv_lights_xs[v39] = v32->vPosition.x;
9372 stru_F8AD28._blv_lights_ys[v39] = v32->vPosition.y;
9373 stru_F8AD28._blv_lights_zs[v39] = v32->vPosition.z;
9374 v68 = (BLVFaceExtra *)v32->uRed;
9375 stru_F8AD28._blv_lights_rs[v39] = (double)(signed int)v68 * v16;
9376 v68 = (BLVFaceExtra *)v32->uGreen;
9377 stru_F8AD28._blv_lights_gs[v39] = (double)(signed int)v68 * v16;
9378 v68 = (BLVFaceExtra *)v32->uBlue;
9379 stru_F8AD28._blv_lights_bs[v39] = (double)(signed int)v68 * v16;
9380 v16 = 0.0039215689;
9381 stru_F8AD28._blv_lights_light_dot_faces[v39] = abs(v38);
9382 v40 = v74++;
9383 stru_F8AD28._blv_lights_smthngs[v40] = 1;
9384 }
9385 }
9386 }
9387 }
9388 }
9389 }
9390 }
9391 }
9392 }
9393 v30 = v73++ + 1;
9394 if ( v73 >= v70 )
9395 break;
9396 v17 = v69;
9397 }
9398 }
9399 v73 = 0;
9400 if ( uNumStationaryLightsApplied > 0 )
9401 {
9402 v41 = (char *)&pStationaryLights[0].vPosition.y;
9403 do
9404 {
9405 if ( v74 >= 20 )
9406 break;
9407 v42 = *((short *)v41 + 2);
9408 v43 = *((short *)v41 - 1);
9409 if ( v43 > v1->pBounding.x1 - v42 )
9410 {
9411 if ( v43 < v42 + v1->pBounding.x2 )
9412 {
9413 v44 = *(short *)v41;
9414 if ( v44 > v1->pBounding.y1 - v42 )
9415 {
9416 if ( v44 < v42 + v1->pBounding.y2 )
9417 {
9418 v45 = *((short *)v41 + 1);
9419 if ( v45 > v1->pBounding.z1 - v42 )
9420 {
9421 if ( v45 < v42 + v1->pBounding.z2 )
9422 {
9423 v46 = (v1->pFacePlane_old.dist
9424 + *(short *)v41 * v1->pFacePlane_old.vNormal.y
9425 + v43 * v1->pFacePlane_old.vNormal.x
9426 + v45 * v1->pFacePlane_old.vNormal.z) >> 16;
9427 v69 = v46;
9428 if ( v46 >= 0 )
9429 {
9430 if ( v46 <= v42 )
9431 {
9432 v47 = v69;
9433 v48 = v74;
9434 stru_F8AD28._blv_lights_radii[v74] = v42;
9435 stru_F8AD28._blv_lights_inv_radii[v48] = 65536 / v42;
9436 stru_F8AD28._blv_lights_xs[v48] = *((short *)v41 - 1);
9437 stru_F8AD28._blv_lights_ys[v48] = *(short *)v41;
9438 stru_F8AD28._blv_lights_zs[v48] = *((short *)v41 + 1);
9439 v68 = (BLVFaceExtra *)(unsigned __int8)v41[6];
9440 v49 = (double)(signed int)v68 * v16;
9441 v68 = (BLVFaceExtra *)(unsigned __int8)v41[7];
9442 v50 = (unsigned __int8)v41[8];
9443 stru_F8AD28._blv_lights_rs[v48] = v49;
9444 v51 = (double)(signed int)v68;
9445 v68 = (BLVFaceExtra *)v50;
9446 stru_F8AD28._blv_lights_gs[v48] = v51 * v16;
9447 stru_F8AD28._blv_lights_bs[v48] = (double)(signed int)v68 * v16;
9448 v16 = 0.0039215689;
9449 stru_F8AD28._blv_lights_light_dot_faces[v48] = abs(v47);
9450 v52 = v74++;
9451 stru_F8AD28._blv_lights_smthngs[v52] = 1;
9452 }
9453 }
9454 }
9455 }
9456 }
9457 }
9458 }
9459 }
9460 ++v73;
9461 v41 += 12;
9462 }
9463 while ( v73 < uNumStationaryLightsApplied );
9464 }
9465 stru_F8AD28.field_AC = v74;
9466 v53 = v1->pBounding.x2;
9467 if ( pBLVRenderParams->vPartyPos.x <= v53 )
9468 {
9469 v55 = v1->pBounding.x1;
9470 if ( pBLVRenderParams->vPartyPos.x >= v55 )
9471 v54 = 0;
9472 else
9473 v54 = v55 - pBLVRenderParams->vPartyPos.x;
9474 }
9475 else
9476 {
9477 v54 = pBLVRenderParams->vPartyPos.x - v53;
9478 }
9479 v56 = v1->pBounding.y2;
9480 v57 = v54 * v54;
9481 if ( pBLVRenderParams->vPartyPos.y <= v56 )
9482 {
9483 v59 = v1->pBounding.y1;
9484 if ( pBLVRenderParams->vPartyPos.y >= v59 )
9485 v58 = 0;
9486 else
9487 v58 = v59 - pBLVRenderParams->vPartyPos.y;
9488 }
9489 else
9490 {
9491 v58 = pBLVRenderParams->vPartyPos.y - v56;
9492 }
9493 v60 = v58 * v58 + v57;
9494 v61 = v1->pBounding.z2;
9495 if ( pBLVRenderParams->vPartyPos.z <= v61 )
9496 {
9497 v63 = v1->pBounding.z1;
9498 if ( pBLVRenderParams->vPartyPos.z >= v63 )
9499 v62 = 0;
9500 else
9501 v62 = v63 - pBLVRenderParams->vPartyPos.z;
9502 }
9503 else
9504 {
9505 v62 = pBLVRenderParams->vPartyPos.z - v61;
9506 }
9507 v64 = v62 * v62 + v60;
9508 if ( v64 )
9509 stru_F8AD28.field_34 = sub_452A9E(v64) << 16;
9510 else
9511 stru_F8AD28.field_34 = 0;
9512 v68 = (BLVFaceExtra *)abs(stru_F8AD28.rotated_normal.y);
9513 v65 = (double)(signed int)v68;
9514 if ( v65 >= 655.36 )
9515 {
9516 if ( v65 >= 26214.4 )
9517 {
9518 if ( v65 >= 45875.2 )
9519 {
9520 stru_F8AD28.field_44 = 8;
9521 stru_F8AD28.field_48 = 3;
9522 }
9523 else
9524 {
9525 stru_F8AD28.field_44 = 16;
9526 stru_F8AD28.field_48 = 4;
9527 }
9528 }
9529 else
9530 {
9531 stru_F8AD28.field_44 = 32;
9532 stru_F8AD28.field_48 = 5;
9533 }
9534 }
9535 else
9536 {
9537 stru_F8AD28.field_44 = 64;
9538 stru_F8AD28.field_48 = 6;
9539 }
9540 }
9541 // 519AB4: using guessed type int uNumStationaryLightsApplied;
9542
9543 //----- (004AF412) --------------------------------------------------------
9544 int __cdecl sub_4AF412()
9545 {
9546 int v0; // ST20_4@2
9547 int v1; // ST20_4@2
9548 int v2; // ST20_4@2
9549 int v3; // esi@2
9550 int v4; // ST20_4@2
9551 int v5; // ecx@2
9552 int v6; // ebx@2
9553 int v7; // edi@2
9554 int v8; // edx@2
9555 int v9; // eax@2
9556 int result; // eax@4
9557
9558 stru_F8AD28.plane_4.vNormal.z = -65536;
9559 stru_F8AD28.vec_20.y = -65536;
9560 stru_F8AD28.plane_4.vNormal.x = 0;
9561 stru_F8AD28.plane_4.vNormal.y = 0;
9562 stru_F8AD28.plane_4.dist = (pBLVRenderParams->vPartyPos.z + 800) << 16;
9563 stru_F8AD28.vec_14.x = 65536;
9564 stru_F8AD28.vec_14.y = 0;
9565 stru_F8AD28.vec_14.z = 0;
9566 stru_F8AD28.vec_20.x = 0;
9567 stru_F8AD28.vec_20.z = 0;
9568 stru_F8AD28.field_3F8 = 0;
9569 if ( pBLVRenderParams->sPartyRotX )
9570 {
9571 v0 = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
9572 - ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)pBLVRenderParams->sSineY) >> 16);
9573 stru_F8AD28.rotated_normal.x = ((unsigned __int64)(v0 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16)
9574 - ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.z
9575 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16);
9576 stru_F8AD28.rotated_normal.y = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
9577 * (signed __int64)pBLVRenderParams->sSineY) >> 16)
9578 + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
9579 * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
9580 stru_F8AD28.rotated_normal.z = ((unsigned __int64)(v0 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
9581 + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.z
9582 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
9583 v1 = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
9584 - ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sSineY) >> 16);
9585 stru_F8AD28.vec_60.y = ((unsigned __int64)(v1 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16)
9586 - ((unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16);
9587 stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
9588 + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
9589 stru_F8AD28.field_6C = ((unsigned __int64)(v1 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
9590 + ((unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
9591 v2 = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
9592 - ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sSineY) >> 16);
9593 stru_F8AD28.vec_70.x = ((unsigned __int64)(v2 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16)
9594 - ((unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16);
9595 stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
9596 + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
9597 stru_F8AD28.vec_70.z = ((unsigned __int64)(v2 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16)
9598 + ((unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16);
9599 v3 = -(pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.y
9600 + pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.x);
9601 v4 = pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.y
9602 - pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.x;
9603 v5 = ((unsigned __int64)(v4 * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16)
9604 - ((unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pBLVRenderParams->sSineNegX) >> 16);
9605 v6 = pBLVRenderParams->vPartyPos.z;
9606 v7 = ((unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pBLVRenderParams->sCosineNegX) >> 16)
9607 + ((unsigned __int64)(v4 * (signed __int64)pBLVRenderParams->sSineNegX) >> 16);
9608 v8 = pBLVRenderParams->vPartyPos.y;
9609 v9 = pBLVRenderParams->vPartyPos.x;
9610 }
9611 else
9612 {
9613 stru_F8AD28.rotated_normal.x = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
9614 * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
9615 - ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
9616 * (signed __int64)pBLVRenderParams->sSineY) >> 16);
9617 stru_F8AD28.rotated_normal.z = stru_F8AD28.plane_4.vNormal.z;
9618 stru_F8AD28.rotated_normal.y = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
9619 * (signed __int64)pBLVRenderParams->sSineY) >> 16)
9620 + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
9621 * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
9622 stru_F8AD28.vec_60.y = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
9623 - ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sSineY) >> 16);
9624 stru_F8AD28.field_6C = stru_F8AD28.vec_14.z;
9625 stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
9626 + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
9627 stru_F8AD28.vec_70.x = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
9628 - ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sSineY) >> 16);
9629 v8 = pBLVRenderParams->vPartyPos.y;
9630 stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
9631 + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
9632 stru_F8AD28.vec_70.z = stru_F8AD28.vec_20.z;
9633 v9 = pBLVRenderParams->vPartyPos.x;
9634 v5 = pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.y
9635 - pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.x;
9636 v6 = pBLVRenderParams->vPartyPos.z;
9637 v3 = -(pBLVRenderParams->sCosineY * pBLVRenderParams->vPartyPos.y
9638 + pBLVRenderParams->sSineY * pBLVRenderParams->vPartyPos.x);
9639 v7 = -65536 * pBLVRenderParams->vPartyPos.z;
9640 }
9641 stru_F8AD28.field_7C = stru_F8AD28.rotated_normal.x;
9642 stru_F8AD28.vec_60.x = stru_F8AD28.plane_4.vNormal.y * v8
9643 + stru_F8AD28.plane_4.dist
9644 + stru_F8AD28.plane_4.vNormal.x * v9
9645 + stru_F8AD28.plane_4.vNormal.z * v6;
9646 stru_F8AD28.vec_80.x = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44)
9647 * (signed __int64)stru_F8AD28.rotated_normal.y) >> 16;
9648 stru_F8AD28.vec_80.y = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44)
9649 * (signed __int64)stru_F8AD28.rotated_normal.z) >> 16;
9650 stru_F8AD28.vec_80.z = -stru_F8AD28.vec_60.x;
9651 stru_F8AD28.vec_8C.x = stru_F8AD28.vec_60.y;
9652 stru_F8AD28.vec_8C.y = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.vec_60.z) >> 16;
9653 stru_F8AD28.vec_8C.z = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.field_6C) >> 16;
9654 stru_F8AD28.vec_9C.x = stru_F8AD28.vec_70.x;
9655 stru_F8AD28.field_98 = -(((unsigned __int64)(stru_F8AD28.vec_60.y * (signed __int64)v5) >> 16)
9656 + ((unsigned __int64)(stru_F8AD28.vec_60.z * (signed __int64)v3) >> 16)
9657 + ((unsigned __int64)(stru_F8AD28.field_6C * (signed __int64)v7) >> 16));
9658 stru_F8AD28.vec_9C.y = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.vec_70.y) >> 16;
9659 stru_F8AD28.vec_9C.z = (unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)stru_F8AD28.vec_70.z) >> 16;
9660 result = 0;
9661 stru_F8AD28.field_A8 = -(((unsigned __int64)(stru_F8AD28.vec_70.x * (signed __int64)v5) >> 16)
9662 + ((unsigned __int64)(stru_F8AD28.vec_70.y * (signed __int64)v3) >> 16)
9663 + ((unsigned __int64)(stru_F8AD28.vec_70.z * (signed __int64)v7) >> 16));
9664 stru_F8AD28.field_38 = 0;
9665 stru_F8AD28.field_3E4 = 0;
9666 stru_F8AD28.field_2C = 0;
9667 stru_F8AD28.field_AC = 0;
9668 stru_F8AD28.field_34 = 0;
9669 return result;
9670 }
9671
9672
9673
9674
9675
9676
9677 //----- (004B1447) --------------------------------------------------------
9678 Player *__fastcall sub_4B1447_party_fine(int a1, int a2, int a3)
9679 {
9680 signed int v3; // esi@1
9681 char v4; // sf@8
9682 int v5; // eax@8
9683 unsigned __int64 v6; // qax@12
9684 DDM_DLV_Header *v7; // eax@14
9685 Player **v8; // edi@18
9686 Player *result; // eax@19
9687 char *v10; // esi@20
9688
9689 v3 = 0;
9690 if ( a2 )
9691 {
9692 if ( a2 != 1 )
9693 {
9694 if ( a2 == 2 )
9695 v3 = 2;
9696 goto LABEL_13;
9697 }
9698 v3 = 2;
9699 }
9700 else
9701 {
9702 v3 = 1;
9703 }
9704 if ( pParty->uFine < 4000000 )
9705 {
9706 v4 = a3 + pParty->uFine < 0;
9707 v5 = a3 + pParty->uFine;
9708 pParty->uFine += a3;
9709 if ( v4 )
9710 {
9711 v5 = 0;
9712 pParty->uFine = 0;
9713 }
9714 if ( v5 > 4000000 )
9715 pParty->uFine = 4000000;
9716 }
9717 v6 = pParty->uTimePlayed + 368640;
9718 pParty->field_3C._shop_ban_times[2 * a1] = LODWORD(pParty->uTimePlayed) + 368640;
9719 pParty->field_3C._shop_ban_times[2 * a1 + 1] = HIDWORD(v6);
9720 LABEL_13:
9721 *(int *)&pParty->field_16154[4 * a1] = 1;
9722 if ( v3 )
9723 {
9724 v7 = &pOutdoor->ddm;
9725 if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
9726 v7 = &pIndoor->dlv;
9727 v7->uReputation += v3;
9728 if ( v7->uReputation > 10000 )
9729 v7->uReputation = 10000;
9730 }
9731 v8 = &pPlayers[1];
9732 do
9733 {
9734 result = *v8;
9735 if ( pParty->uFine )
9736 {
9737 v10 = result->field_152;
9738 result = (Player *)_449B57_test_bit((unsigned __int8 *)result->field_152, 1);
9739 if ( !(short)result )
9740 result = (Player *)_449B7E_toggle_bit(v10, 1, 1u);
9741 }
9742 ++v8;
9743 }
9744 while ( (signed int)v8 <= (signed int)&pPlayers[4] );
9745 return result;
9746 }
9747
9748 //----- (004B1523) --------------------------------------------------------
9749 char *__thiscall sub_4B1523(int *_this)
9750 {
9751 int v1; // esi@1
9752 int v2; // edx@1
9753 unsigned int v3; // eax@2
9754 int v4; // eax@4
9755 LONG v5; // ecx@4
9756 int v6; // eax@10
9757 char *v7; // ST44_4@12
9758 unsigned __int16 v8; // ax@12
9759 GUIWindow a1; // [sp+Ch] [bp-68h]@4
9760 unsigned int v11; // [sp+60h] [bp-14h]@1
9761 POINT a2; // [sp+64h] [bp-10h]@1
9762 int v13; // [sp+6Ch] [bp-8h]@4
9763 int v14; // [sp+70h] [bp-4h]@4
9764
9765 v1 = *_this - 399;
9766 v2 = (*_this - 400) % 11 + 1;
9767 v11 = 4 * (*_this - 400) / 11;
9768 sprintfex(pTmpBuf, "%s%03d", spellbook_texture_filename_suffices[v11 / 4], v2);
9769 if ( pMouse->GetCursorPos(&a2)->y <= 320 )
9770 v3 = pMouse->GetCursorPos(&a2)->y + 30;
9771 else
9772 v3 = 30;
9773 a1.str_48 = 0;
9774 a1.uFrameY = v3;
9775 a1.uFrameWidth = 328;
9776 a1.uFrameHeight = 68;
9777 a1.uFrameX = 90;
9778 a1.uFrameZ = 417;
9779 a1.uFrameW = v3 + 67;
9780 a2.y = pFontSmallnum->GetLineWidth(pGlobalTXT_LocalizationStrings[431]);
9781 v14 = pFontSmallnum->GetLineWidth(pGlobalTXT_LocalizationStrings[433]);
9782 v13 = pFontSmallnum->GetLineWidth(pGlobalTXT_LocalizationStrings[432]);
9783 v4 = pFontSmallnum->GetLineWidth(pGlobalTXT_LocalizationStrings[96]);
9784 v5 = a2.y;
9785 if ( v14 > a2.y )
9786 v5 = v14;
9787 if ( v13 > v5 )
9788 v5 = v13;
9789 if ( v4 > v5 )
9790 v5 = v4;
9791 sprintfex(
9792 pTmpBuf2,
9793 "%s\n\n%s\t%03d:\t%03d%s\t000\n%s\t%03d:\t%03d%s\t000\n%s\t%03d:\t%03d%s\t000\n%s\t%03d:\t%03d%s",
9794 pSpellStats->pInfos[v1].pDescription,
9795 pGlobalTXT_LocalizationStrings[431], // "Normal"
9796 v5 + 3,
9797 v5 + 10,
9798 pSpellStats->pInfos[v1].pBasicSkillDesc,
9799 pGlobalTXT_LocalizationStrings[433], // "Expert"
9800 v5 + 3,
9801 v5 + 10,
9802 pSpellStats->pInfos[v1].pExpertSkillDesc,
9803 pGlobalTXT_LocalizationStrings[432], // "Master"
9804 v5 + 3,
9805 v5 + 10,
9806 pSpellStats->pInfos[v1].pMasterSkillDesc,
9807 pGlobalTXT_LocalizationStrings[96], // "Grand"
9808 v5 + 3,
9809 v5 + 10,
9810 pSpellStats->pInfos[v1].pGrandmasterSkillDesc);
9811 v6 = pFontSmallnum->CalcTextHeight(pTmpBuf2, &a1, 0, 0);
9812 a1.uFrameHeight += v6;
9813 if ( (signed int)a1.uFrameHeight < 150 )
9814 a1.uFrameHeight = 150;
9815 a1.uFrameWidth = 460;
9816 a1._415551(0);
9817 a1.uFrameWidth -= 12;
9818 a1.uFrameHeight -= 12;
9819 v7 = pSpellStats->pInfos[v1].pName;
9820 a1.uFrameZ = a1.uFrameX + a1.uFrameWidth - 1;
9821 a1.uFrameW = a1.uFrameHeight + a1.uFrameY - 1;
9822 v8 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
9823 a1.DrawText2(pFontArrus, 0x78u, 0xCu, v8, v7, 3u);
9824 a1.DrawText(pFontSmallnum, 120, 44, 0, pTmpBuf2, 0, 0, 0);
9825 a1.uFrameZ = a1.uFrameX + 107;
9826 a1.uFrameWidth = 108;
9827 a1.DrawText2(pFontComic, 0xCu, 0x4Bu, 0, pSkillNames[v11 / 4 + 12], 3u);
9828 sprintfex(pTmpBuf, "%s\n%d", pGlobalTXT_LocalizationStrings[522], *(&pSpellDatas[0].uNormalLevelMana + 10 * v1));
9829 return a1.DrawText2(
9830 pFontComic,
9831 0xCu,
9832 a1.uFrameHeight - LOBYTE(pFontComic->uFontHeight) - 16,
9833 0,
9834 pTmpBuf,
9835 3u);
9836 }
9837
9838
9839 //----- (004B1784) --------------------------------------------------------
9840 bool __cdecl sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win()
9841 {
9842 Player *pPlayer; // ebx@1
9843 bool result; // eax@2
9844 unsigned __int16 v2; // ST0C_2@3
9845 int v3; // eax@3
9846 GUIWindow v4; // [sp+4h] [bp-54h]@3
9847
9848 pPlayer = pPlayers[uActiveCharacter];
9849 if ( pPlayer->CanAct() )
9850 {
9851 pDialogueWindow->field_28 = dword_F8B1E0;
9852 result = 1;
9853 }
9854 else
9855 {
9856 pDialogueWindow->field_28 = 0;
9857 memcpy(&v4, pGUIWindow0, sizeof(v4));
9858 v4.uFrameX = 483;
9859 v4.uFrameWidth = 148;
9860 v4.uFrameZ = 334;
9861 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[427], pPlayer->pName, pGlobalTXT_LocalizationStrings[562]);//
9862 // "%s is in no condition to %s"
9863 // "do anything"
9864 v2 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
9865 v3 = pFontArrus->CalcTextHeight(pTmpBuf, &v4, 0, 0);
9866 v4.DrawText2(pFontArrus, 0, (212 - v3) / 2 + 101, v2, pTmpBuf, 3u);
9867 result = 0;
9868 }
9869 return result;
9870 }
9871 // F8B1E0: using guessed type int dword_F8B1E0;
9872
9873
9874
9875 //----- (004B1A2D) --------------------------------------------------------
9876 void __cdecl sub_4B1A2D()
9877 {
9878 Player *v0; // edi@1
9879 POINT *v1; // esi@5
9880 unsigned int v2; // eax@5
9881 int v3; // ecx@5
9882 POINT *v4; // esi@12
9883 int v5; // eax@12
9884 unsigned int v6; // eax@13
9885 ItemGen *v7; // ecx@13
9886 signed int v8; // esi@17
9887 unsigned int v9; // eax@19
9888 char v10; // [sp+8h] [bp-44h]@12
9889 char v11; // [sp+10h] [bp-3Ch]@12
9890 char v12; // [sp+18h] [bp-34h]@18
9891 char v13; // [sp+20h] [bp-2Ch]@17
9892 char v14; // [sp+28h] [bp-24h]@17
9893 char v15; // [sp+30h] [bp-1Ch]@17
9894 char v16; // [sp+38h] [bp-14h]@5
9895 POINT a2; // [sp+40h] [bp-Ch]@5
9896 int v18; // [sp+48h] [bp-4h]@5
9897
9898 v0 = pPlayers[uActiveCharacter];
9899 if ( dword_F8B198 <= 0 )
9900 return;
9901 if ( dword_F8B198 <= 4 )
9902 {
9903 if ( dword_F8B19C != 2 )
9904 {
9905 if ( dword_F8B19C <= 2 )
9906 return;
9907 if ( dword_F8B19C <= 5 || dword_F8B19C == 94 )
9908 {
9909 v8 = pMouse->GetCursorPos((POINT *)&v15)->x - 14;
9910 v18 = (v8 >> 5) + 14 * ((pMouse->GetCursorPos((POINT *)&v14)->y - 17) >> 5);
9911 if ( pMouse->GetCursorPos((POINT *)&v13)->x <= 13
9912 || pMouse->GetCursorPos((POINT *)&v12)->x >= 462
9913 || (v9 = v0->GetItemIDAtInventoryIndex(&v18)) == 0 )
9914 return;
9915 v7 = (ItemGen *)&v0->pDarkSpellbook.bIsSpellAvailable[36 * v9 + 5];
9916 LABEL_15:
9917 GameUI_DrawItemInfo(v7);
9918 return;
9919 }
9920 if ( dword_F8B19C != 95 )
9921 return;
9922 }
9923 v4 = pMouse->GetCursorPos((POINT *)&v11);
9924 v5 = pRenderer->pActiveZBuffer[v4->x + pSRZBufferLineOffsets[pMouse->GetCursorPos((POINT *)&v10)->y]] & 0xFFFF;
9925 v18 = v5;
9926 if ( !v5 )
9927 return;
9928 v6 = 9 * (v5 + 12 * (unsigned int)ptr_507BC0->ptr_1C);
9929 v7 = (ItemGen *)((char *)&pParty->pPickedItem + 4 * v6 + 4);
9930 if ( dword_F8B19C != 2 )
9931 v7 = (ItemGen *)&pParty->field_C59C[v6 + 715];
9932 goto LABEL_15;
9933 }
9934 if ( dword_F8B198 <= 16 && dword_F8B19C == 18 )
9935 {
9936 v1 = pMouse->GetCursorPos(&a2);
9937 v2 = v1->x + pSRZBufferLineOffsets[pMouse->GetCursorPos((POINT *)&v16)->y];
9938 v3 = pRenderer->pActiveZBuffer[v2] & 0xFFFF;
9939 v18 = pRenderer->pActiveZBuffer[v2] & 0xFFFF;
9940 if ( v18 )
9941 sub_4B1523((int *)&pParty->pPlayers[1].uExpressionTimeLength + 9 * (v3 + 12 * (unsigned int)ptr_507BC0->ptr_1C));
9942 }
9943 }
9944 // F8B198: using guessed type int dword_F8B198;
9945 // F8B19C: using guessed type int dword_F8B19C;
9946
9947 //----- (004B1BDB) --------------------------------------------------------
9948 void __stdcall RestAndHeal(__int64 uNumMinutes)
9949 {
9950 signed __int64 v1; // ST2C_8@1
9951 signed __int64 v2; // qax@1
9952 signed __int64 v3; // ST1C_8@1
9953 unsigned __int64 v4; // qax@1
9954 unsigned int v5; // ebx@1
9955 void *v6; // ebx@1
9956
9957 pParty->pHirelings[0].bHasUsedTheAbility = 0;
9958 pParty->pHirelings[1].bHasUsedTheAbility = 0;
9959 pParty->uTimePlayed += (signed __int64)((double)(7680 * uNumMinutes) * 0.033333335);
9960 v1 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375);
9961 v2 = v1 / 60 / 60;
9962 v3 = v2;
9963 v4 = (unsigned int)v2 / 0x18;
9964 v5 = (unsigned int)(v4 / 7) >> 2;
9965 pParty->uCurrentTimeSecond = v1 % 60;
9966 pParty->uCurrentMinute = v1 / 60 % 60;
9967 pParty->uCurrentHour = v3 % 24;
9968 pParty->uCurrentMonthWeek = v4 / 7 & 3;
9969 pParty->uDaysPlayed = (unsigned int)v4 % 0x1C;
9970 pParty->uCurrentMonth = v5 % 0xC;
9971 pParty->uCurrentYear = v5 / 0xC + 1168;
9972 pParty->RestAndHeal();
9973 dword_507B94 = 1;
9974 v6 = &pParty->pPlayers[0].uNumDivineInterventionCastsThisDay;
9975 do
9976 {
9977 *((short *)v6 - 258) = 0;
9978 memset(v6, 0, 4u);
9979 v6 = (char *)v6 + 6972;
9980 }
9981 while ( (signed int)v6 < (signed int)&pParty->field_871C[694] );
9982 pParty->_4909F4();
9983 }
9984 // 507B94: using guessed type int dword_507B94;
9985
9986 //----- (004B1D27) --------------------------------------------------------
9987 void __cdecl sub_4B1D27()
9988 {
9989 int v0; // edx@2
9990 unsigned int v1; // ecx@7
9991 signed int v2; // edi@10
9992 int v3; // esi@10
9993 __int16 v4; // ax@15
9994 signed int v5; // edi@20
9995 int v6; // esi@20
9996 int v7[4]; // [sp+Ch] [bp-10h]@12
9997
9998 if ( dword_F8B198 > 0 )
9999 {
10000 v0 = 3;
10001 if ( dword_F8B198 > 3 )
10002 {
10003 if ( dword_F8B198 == 22 )
10004 {
10005 if ( !dword_F8B1E4 )
10006 return;
10007 }
10008 else
10009 {
10010 if ( dword_F8B198 != 23 )
10011 return;
10012 }
10013 v1 = (unsigned int)ptr_507BC0->ptr_1C;
10014 LABEL_28:
10015 HousePlaySomeSound(v1, v0);
10016 return;
10017 }
10018 v1 = (unsigned int)ptr_507BC0->ptr_1C;
10019 if ( (signed __int64)__PAIR__(pParty->field_3C._shop_ban_times[2 * v1 + 1], pParty->field_3C._shop_ban_times[2 * v1]) <= (signed __int64)pParty->uTimePlayed )
10020 {
10021 if ( pParty->uNumGold <= 0x2710 )
10022 {
10023 if ( !dword_F8B1E4 )
10024 return;
10025 v0 = 4;
10026 goto LABEL_28;
10027 }
10028 HousePlaySomeSound(v1, dword_F8B1E4 + 3);
10029 if ( !dword_F8B1E4 && !qword_A750D8 )
10030 {
10031 v5 = 0;
10032 v6 = 1;
10033 do
10034 {
10035 if ( pPlayers[v6]->CanAct() )
10036 v7[v5++] = v6;
10037 ++v6;
10038 }
10039 while ( v6 <= 4 );
10040 if ( v5 )
10041 {
10042 qword_A750D8 = 256i64;
10043 word_A750E0 = 80;
10044 v4 = LOWORD(v7[rand() % v5]);
10045 goto LABEL_16;
10046 }
10047 }
10048 }
10049 else
10050 {
10051 if ( !qword_A750D8 )
10052 {
10053 v2 = 0;
10054 v3 = 1;
10055 do
10056 {
10057 if ( pPlayers[v3]->CanAct() )
10058 v7[v2++] = v3;
10059 ++v3;
10060 }
10061 while ( v3 <= 4 );
10062 if ( v2 )
10063 {
10064 qword_A750D8 = 256i64;
10065 word_A750E0 = 80;
10066 v4 = LOWORD(v7[rand() % v2]);
10067 LABEL_16:
10068 word_A750E2 = v4;
10069 return;
10070 }
10071 }
10072 }
10073 }
10074 }
10075
10076 //----- (004B1E92) --------------------------------------------------------
10077 void __fastcall HousePlaySomeSound(unsigned int uHouseID, int a2)
10078 {
10079 //if ( BYTE1(pAnimatedRooms[p2DEvents_minus1___02[26 * uHouseID]].field_C) )
10080 if ( BYTE1(pAnimatedRooms[p2DEvents[uHouseID - 1].uAnimationID].field_C) )
10081 pAudioPlayer->PlaySound(
10082 //(SoundID)(a2 + 100 * (BYTE1(pAnimatedRooms[p2DEvents_minus1___02[26 * uHouseID]].field_C) + 300)),
10083 (SoundID)(a2 + 100 * (BYTE1(pAnimatedRooms[p2DEvents[uHouseID - 1].uAnimationID].field_C) + 300)),
10084 806,
10085 0,
10086 -1,
10087 0,
10088 0,
10089 0,
10090 0);
10091 }
10092
10093 //----- (004B1ECE) --------------------------------------------------------
10094 void __cdecl sub_4B1ECE()
10095 {
10096 __int16 *v0; // edi@1
10097 int v1; // ebx@3
10098 Player *v2; // esi@3
10099 int v3; // eax@4
10100 signed int v4; // eax@9
10101 int v5; // ebx@11
10102 char *v6; // esi@13
10103 char *v7; // eax@14
10104 signed int v8; // edi@14
10105 int v9; // [sp+Ch] [bp-Ch]@11
10106 signed int v10; // [sp+10h] [bp-8h]@13
10107 int v11; // [sp+14h] [bp-4h]@1
10108 char *v12; // [sp+14h] [bp-4h]@11
10109
10110 dword_F8B1A8 = 0;
10111 v11 = 0;
10112 uDialogueType = 84;
10113 ptr_F8B1E8 = (char *)dword_722B44;
10114 v0 = _4F0882_evt_VAR_PlayerItemInHands_vals;
10115 while ( 1 )
10116 {
10117 if ( (unsigned __int16)_449B57_test_bit(pParty->_award_bits, *(v0 - 1)) )
10118 {
10119 v1 = 0;
10120 v2 = pParty->pPlayers;
10121 do
10122 {
10123 LOBYTE(v3) = v2->CompareVariable(VAR_PlayerItemInHands, *v0);
10124 if ( v3 )
10125 break;
10126 ++v2;
10127 ++v1;
10128 }
10129 while ( (signed int)v2 < (signed int)pParty->pHirelings );
10130 if ( v1 == 4 )
10131 break;
10132 }
10133 ++v11;
10134 v0 += 2;
10135 if ( (signed int)v0 >= (signed int)((char *)dword_4F08EC + 2) )
10136 goto LABEL_10;
10137 }
10138 ptr_F8B1E8 = (char *)dword_722B3C;
10139 v4 = _4F0882_evt_VAR_PlayerItemInHands_vals[2 * v11];
10140 dword_F8B1A8 = _4F0882_evt_VAR_PlayerItemInHands_vals[2 * v11];
10141 pParty->pPlayers[0].AddVariable(VAR_PlayerItemInHands, v4);
10142 LABEL_10:
10143 if ( dword_F8B1A8 == 601 )
10144 {
10145 v5 = 0;
10146 v12 = (char *)&pParty->pPlayers[0].uClass;
10147 v9 = 0;
10148 while ( 1 )
10149 {
10150 if ( *v12 == 35 )
10151 {
10152 v10 = 0;
10153 v6 = &pParty->pPlayers[0].pInventoryItems[0].field_1A;
10154 do
10155 {
10156 v7 = v6;
10157 v8 = 138;
10158 do
10159 {
10160 if ( *(int *)(v7 - 26) == 601 )
10161 {
10162 if ( !*v7 )
10163 v9 = (int)(v7 - 26);
10164 if ( (unsigned __int8)*v7 == v5 )
10165 v10 = 1;
10166 }
10167 v7 += 36;
10168 --v8;
10169 }
10170 while ( v8 );
10171 v6 += 6972;
10172 }
10173 while ( (signed int)v6 < (signed int)((char *)&pParty->field_777C[91] + 2) );
10174 if ( !v10 )
10175 break;
10176 }
10177 v12 += 6972;
10178 ++v5;
10179 if ( (signed int)v12 >= (signed int)((char *)&pParty->pPickedItem.uExpireTime + 5) )
10180 return;
10181 }
10182 if ( v9 )
10183 *(char *)(v9 + 26) = v5;
10184 }
10185 }
10186 // 4F08EC: using guessed type int dword_4F08EC[];
10187 // 722B3C: using guessed type int dword_722B3C;
10188 // 722B44: using guessed type int dword_722B44;
10189 // F8B1A8: using guessed type int dword_F8B1A8;
10190
10191 //----- (004B2001) --------------------------------------------------------
10192 void __fastcall sub_4B2001(signed int a1)
10193 {
10194 signed int v1; // eax@1
10195 NPCData *v2; // ebp@1
10196 int v3; // ecx@8
10197 Player *v4; // esi@20
10198 int v5; // eax@28
10199 int v6; // eax@31
10200 int v7; // eax@34
10201 int v8; // eax@37
10202 int v9; // eax@40
10203 unsigned int v10; // eax@43
10204 unsigned int v11; // eax@48
10205 char *v12; // eax@53
10206 char *v13; // eax@56
10207 char *v14; // eax@57
10208 char *v15; // eax@58
10209 unsigned int v16; // ebp@62
10210 char *v17; // ecx@63
10211 char *v18; // eax@65
10212 const char *v19; // ecx@68
10213 unsigned int v20; // eax@69
10214 unsigned int v21; // ecx@70
10215 char *v22; // [sp-Ch] [bp-18h]@73
10216 int v23; // [sp-8h] [bp-14h]@49
10217 char *v24; // [sp-8h] [bp-14h]@73
10218 int v25; // [sp-4h] [bp-10h]@49
10219
10220 v1 = a1;
10221 uDialogueType = a1 + 1;
10222 v2 = array_5913D8[(unsigned int)((char *)array_5913D8[6] + -(dword_591080 != 0) - 1)];
10223 if ( a1 <= 23 )
10224 {
10225 if ( a1 == 23 )
10226 {
10227 v3 = v2->evte;
10228 }
10229 else
10230 {
10231 if ( a1 == 13 )
10232 {
10233 ptr_F8B1E8 = (char *)*(&pNPCStats->field_13A64 + 5 * v2->uProfession);
10234 ptr_F8B1E8 = sub_495461(ptr_F8B1E8, uActiveCharacter - 1, 0, 0, 0, 0);
10235 sub_4B40E6();
10236 byte_F8B1EC = 0;
10237 goto _return;
10238 }
10239 switch ( a1 )
10240 {
10241 case 19:
10242 v3 = v2->bDrawSomeAnim;
10243 break;
10244 case 20:
10245 v3 = v2->evtb;
10246 break;
10247 case 21:
10248 v3 = v2->evtc;
10249 break;
10250 default:
10251 if ( a1 != 22 )
10252 goto _return;
10253 v3 = v2->evtd;
10254 break;
10255 }
10256 }
10257 goto LABEL_84;
10258 }
10259 if ( a1 == 24 )
10260 {
10261 v3 = v2->evtf;
10262 LABEL_84:
10263 if ( v3 < 200 || v3 > 310 )
10264 {
10265 if ( v3 < 400 || v3 > 410 )
10266 {
10267 if ( v3 == 139 )
10268 {
10269 sub_4B1ECE();
10270 }
10271 else
10272 {
10273 if ( v3 == 311 )
10274 {
10275 sub_4BBA85_bounties();
10276 }
10277 else
10278 {
10279 ptr_F8B1E8 = 0;
10280 _5C3420_pDecoration = (LevelDecoration *)1;
10281 EventProcessor(v3, 0, 1);
10282 _5C3420_pDecoration = 0;
10283 }
10284 }
10285 }
10286 else
10287 {
10288 dword_F8B1D8 = v1;
10289 sub_4B3EF0(v3 - 400);
10290 }
10291 }
10292 else
10293 {
10294 sub_4B3FE5(v3);
10295 }
10296 goto _return;
10297 }
10298 if ( a1 != 76 )
10299 {
10300 if ( a1 == 77 )
10301 {
10302 v16 = v2->uProfession;
10303 if ( byte_F8B1EC )
10304 v17 = (char *)*(&pNPCStats->field_13A64 + 5 * v16);
10305 else
10306 v17 = (char *)*(&pNPCStats->field_13A5C + 5 * v16);
10307 ptr_F8B1E8 = v17;
10308 v18 = sub_495461(v17, uActiveCharacter - 1, 0, 0, 0, 0);
10309 byte_F8B1EC ^= 1u;
10310 ptr_F8B1E8 = v18;
10311 }
10312 else
10313 {
10314 if ( a1 == 79 )
10315 {
10316 if ( dword_F8B1A8 )
10317 {
10318 Party::TakeGold(dword_F8B1B4);
10319 if ( uActiveCharacter )
10320 {
10321 v12 = (char *)&pPlayers[uActiveCharacter]->pActiveSkills[dword_F8B1AC_something_todo_with_awards];
10322 *(short *)v12 &= 0x3Fu;
10323 switch ( dword_F8B1B0 )
10324 {
10325 case 2:
10326 v15 = (char *)&pPlayers[uActiveCharacter]->pActiveSkills[dword_F8B1AC_something_todo_with_awards];
10327 *v15 |= 0x40u;
10328 break;
10329 case 3:
10330 v14 = (char *)&pPlayers[uActiveCharacter]->pActiveSkills[dword_F8B1AC_something_todo_with_awards];
10331 *v14 |= 0x80u;
10332 break;
10333 case 4:
10334 v13 = (char *)&pPlayers[uActiveCharacter]->pActiveSkills[dword_F8B1AC_something_todo_with_awards];
10335 v13[1] |= 1u;
10336 break;
10337 }
10338 pPlayers[uActiveCharacter]->PlaySound(85, 0);
10339 }
10340 if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
10341 {
10342 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
10343 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
10344 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
10345 ++pMessageQueue_50CBD0->uNumMessages;
10346 }
10347 }
10348 }
10349 else
10350 {
10351 if ( a1 == 82 && dword_F8B1A8 )
10352 {
10353 Party::TakeGold(dword_F8B1B4);
10354 v4 = pParty->pPlayers;
10355 do
10356 {
10357 v4->SetVariable(VAR_Award, dword_F8B1AC_something_todo_with_awards);
10358 ++v4;
10359 }
10360 while ( (signed int)v4 < (signed int)pParty->pHirelings );
10361 switch ( dword_F8B1D8 )
10362 {
10363 case 19:
10364 v10 = v2->bDrawSomeAnim;
10365 if ( (signed int)v10 >= 400 && (signed int)v10 <= 416 )
10366 v2->bDrawSomeAnim = 0;
10367 break;
10368 case 20:
10369 v9 = v2->evtb;
10370 if ( v9 >= 400 && v9 <= 416 )
10371 v2->evtb = 0;
10372 break;
10373 case 21:
10374 v8 = v2->evtc;
10375 if ( v8 >= 400 && v8 <= 416 )
10376 v2->evtc = 0;
10377 break;
10378 case 22:
10379 v7 = v2->evtd;
10380 if ( v7 >= 400 && v7 <= 416 )
10381 v2->evtd = 0;
10382 break;
10383 case 23:
10384 v6 = v2->evte;
10385 if ( v6 >= 400 && v6 <= 416 )
10386 v2->evte = 0;
10387 break;
10388 case 24:
10389 v5 = v2->evtf;
10390 if ( v5 >= 400 )
10391 {
10392 if ( v5 <= 416 )
10393 v2->evtf = 0;
10394 }
10395 break;
10396 }
10397 if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
10398 {
10399 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
10400 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
10401 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
10402 ++pMessageQueue_50CBD0->uNumMessages;
10403 }
10404 v11 = uActiveCharacter;
10405 if ( uActiveCharacter )
10406 {
10407 v25 = 0;
10408 v23 = 86;
10409 LABEL_50:
10410 pPlayers[v11]->PlaySound(v23, v25);
10411 goto _return;
10412 }
10413 }
10414 }
10415 }
10416 goto _return;
10417 }
10418 if ( pParty->pHirelings[0].pName && pParty->pHirelings[1].pName )
10419 {
10420 v19 = pGlobalTXT_LocalizationStrings[533]; // ""I cannot join you, you're party is full""
10421 LABEL_77:
10422 ShowStatusBarString(v19, 2u);
10423 goto _return;
10424 }
10425 v20 = v2->uProfession;
10426 if ( v20 != 51 )
10427 {
10428 v21 = *(&pNPCStats->field_13A58 + 5 * v20);
10429 if ( pParty->uNumGold < v21 )
10430 {
10431 ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
10432 byte_F8B1EC = 0;
10433 uDialogueType = 13;
10434 ptr_F8B1E8 = (char *)*(&pNPCStats->field_13A64 + 5 * v2->uProfession);
10435 ptr_F8B1E8 = sub_495461(ptr_F8B1E8, uActiveCharacter - 1, 0, 0, 0, 0);
10436 if ( uActiveCharacter )
10437 pPlayers[uActiveCharacter]->PlaySound(38, 0);
10438 v19 = pGlobalTXT_LocalizationStrings[155];
10439 goto LABEL_77;
10440 }
10441 Party::TakeGold(v21);
10442 }
10443 LOBYTE(v2->uFlags) |= 0x80u;
10444 pParty->field_709 = 0;
10445 sub_44A56A();
10446 if ( pParty->pHirelings[0].pName )
10447 {
10448 memcpy(&pParty->pHirelings[1], v2, sizeof(pParty->pHirelings[1]));
10449 v24 = v2->pName;
10450 v22 = pParty->pHireling2Name;
10451 }
10452 else
10453 {
10454 memcpy(pParty->pHirelings, v2, 0x4Cu);
10455 v24 = v2->pName;
10456 v22 = pParty->pHireling1Name;
10457 }
10458 strcpy(v22, v24);
10459 pParty->field_709 = 0;
10460 sub_44A56A();
10461 PrepareHouse((unsigned int)ptr_507BC0->ptr_1C);
10462 dword_F8B19C = 1;
10463 if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
10464 {
10465 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
10466 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
10467 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
10468 ++pMessageQueue_50CBD0->uNumMessages;
10469 }
10470 v11 = uActiveCharacter;
10471 if ( uActiveCharacter )
10472 {
10473 v25 = 0;
10474 v23 = 61;
10475 goto LABEL_50;
10476 }
10477 _return:
10478 pVideoPlayer->_4BF5B2();
10479 }
10480 // 591080: using guessed type int dword_591080;
10481 // F8B19C: using guessed type int dword_F8B19C;
10482 // F8B1A8: using guessed type int dword_F8B1A8;
10483 // F8B1B0: using guessed type int dword_F8B1B0;
10484 // F8B1B4: using guessed type int dword_F8B1B4;
10485 // F8B1D8: using guessed type int dword_F8B1D8;
10486 // F8B1EC: using guessed type char byte_F8B1EC;
10487
10488 //----- (004B254D) --------------------------------------------------------
10489 char *__thiscall _4B254D_SkillMasteryTeacher(int _this)
10490 {
10491 Player *v1; // esi@1
10492 int v2; // edx@1
10493 int v3; // ecx@1
10494 int v4; // edi@1
10495 int v5; // eax@7
10496 int v6; // eax@7
10497 int v7; // ebx@7
10498 int v8; // ebx@8
10499 signed int v9; // esi@8
10500 int v10; // eax@8
10501 char *v11; // ecx@8
10502 int v12; // edi@9
10503 char *v13; // edx@9
10504 signed int v14; // edi@10
10505 unsigned int v16; // eax@29
10506 int v17; // eax@36
10507 char v18; // cl@46
10508 __int16 v19; // dx@56
10509 int v20; // eax@60
10510 char *v21; // [sp-Ch] [bp-38h]@82
10511 const char *v22; // [sp-8h] [bp-34h]@21
10512 unsigned int v23; // [sp-8h] [bp-34h]@38
10513 char *v24; // [sp-8h] [bp-34h]@82
10514 char *v25; // [sp-4h] [bp-30h]@14
10515 int v26; // [sp-4h] [bp-30h]@38
10516 int v27; // [sp-4h] [bp-30h]@82
10517 char v28[4]; // [sp+Ch] [bp-20h]@9
10518 int v29; // [sp+10h] [bp-1Ch]@13
10519 int v30; // [sp+14h] [bp-18h]@15
10520 int v31; // [sp+18h] [bp-14h]@16
10521 unsigned __int16 a1[2]; // [sp+1Ch] [bp-10h]@7
10522 int v33; // [sp+20h] [bp-Ch]@7
10523 int v34; // [sp+24h] [bp-8h]@7
10524 char *v35; // [sp+28h] [bp-4h]@1
10525
10526 v1 = pPlayers[uActiveCharacter];
10527 dword_F8B1A8 = 0;
10528 v2 = (_this - 200) % 3;
10529 v3 = (_this - 200) / 3;
10530 v4 = v2;
10531 v35 = (char *)dword_721A64;
10532 dword_F8B1AC_something_todo_with_awards = v3;
10533 if ( v2 )
10534 {
10535 if ( v2 == 1 )
10536 {
10537 dword_F8B1B4 = 5000;
10538 dword_F8B1B0 = 3;
10539 }
10540 else
10541 {
10542 if ( v2 == 2 )
10543 {
10544 dword_F8B1B4 = 8000;
10545 dword_F8B1B0 = 4;
10546 }
10547 }
10548 }
10549 else
10550 {
10551 dword_F8B1B4 = 2000;
10552 dword_F8B1B0 = 2;
10553 }
10554 v5 = v1->uClass;
10555 v33 = v5;
10556 v6 = byte_4ED970_skill_learn_ability_by_class_table[v5][v3];
10557 *(int *)a1 = v1->pActiveSkills[v3];
10558 v7 = a1[0] & 0x3F;
10559 v34 = v2 + 2;
10560 if ( v6 < v2 + 2 )
10561 {
10562 v8 = v33;
10563 v9 = 0;
10564 v10 = v33 - v33 % 4;
10565 v11 = &byte_4ED970_skill_learn_ability_by_class_table[v33 - v33 % 4][v3];
10566 do
10567 {
10568 v12 = (unsigned __int8)*v11;
10569 v13 = &v28[4 * v9];
10570 *(int *)v13 = 0;
10571 if ( v12 < v34 )
10572 {
10573 v14 = 1;
10574 }
10575 else
10576 {
10577 v14 = 1;
10578 *(int *)v13 = 1;
10579 }
10580 ++v9;
10581 v11 += 37;
10582 }
10583 while ( v9 < 4 );
10584 if ( v29 == v14 )
10585 {
10586 v25 = pClassNames[v10 + 1];
10587 }
10588 else
10589 {
10590 if ( v30 == v14 )
10591 {
10592 if ( v31 == v14 )
10593 {
10594 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[634], pClassNames[v10 + 2], pClassNames[v10 + 3]);
10595 return pTmpBuf;
10596 }
10597 v25 = pClassNames[v10 + 2];
10598 }
10599 else
10600 {
10601 if ( v31 != v14 )
10602 {
10603 v25 = pClassNames[v8];
10604 v22 = pGlobalTXT_LocalizationStrings[632];
10605 goto LABEL_23;
10606 }
10607 v25 = pClassNames[v10 + 3];
10608 }
10609 }
10610 v22 = pGlobalTXT_LocalizationStrings[633];
10611 LABEL_23:
10612 sprintfex(pTmpBuf, v22, v25);
10613 return pTmpBuf;
10614 }
10615 if ( !v1->CanAct() )
10616 return _721A3C_npc_text;
10617 if ( !v7 )
10618 return (char *)_721A84_npc_text;
10619 v16 = SkillToMastery(a1[0]);
10620 if ( (signed int)v16 > v4 + 1 )
10621 return (char *)_721A6C_npc_text[2 * v4];
10622 if ( v34 != 2 )
10623 {
10624 if ( v34 == 3 )
10625 {
10626 if ( (signed int)v16 >= 2 && v7 >= 7 )
10627 {
10628 v17 = dword_F8B1AC_something_todo_with_awards;
10629 switch ( dword_F8B1AC_something_todo_with_awards )
10630 {
10631 default:
10632 goto LABEL_41;
10633 case 12:
10634 case 13:
10635 case 14:
10636 case 15:
10637 case 16:
10638 case 17:
10639 case 18:
10640 dword_F8B1B4 = 4000;
10641 goto LABEL_42;
10642 case 19:
10643 v19 = 114;
10644 goto LABEL_57;
10645 case 20:
10646 v19 = 110;
10647 LABEL_57:
10648 if ( !(unsigned __int16)_449B57_test_bit(pParty->_award_bits, v19) )
10649 return v35;
10650 goto LABEL_40;
10651 case 22:
10652 v20 = v1->GetBaseWillpower();
10653 goto LABEL_61;
10654 case 24:
10655 dword_F8B1B4 = 2500;
10656 v20 = v1->GetBaseEndurance();
10657 goto LABEL_61;
10658 case 36:
10659 v20 = v1->GetBaseIntelligence();
10660 LABEL_61:
10661 if ( v20 < 50 )
10662 return v35;
10663 goto LABEL_40;
10664 case 21:
10665 case 23:
10666 case 25:
10667 case 26:
10668 case 29:
10669 case 32:
10670 case 34:
10671 case 35:
10672 dword_F8B1B4 = 2500;
10673 goto LABEL_42;
10674 case 8:
10675 case 9:
10676 case 10:
10677 case 11:
10678 dword_F8B1B4 = 3000;
10679 goto LABEL_42;
10680 case 7:
10681 goto LABEL_67;
10682 }
10683 goto LABEL_67;
10684 }
10685 }
10686 else
10687 {
10688 if ( v34 != 4 )
10689 {
10690 LABEL_40:
10691 v17 = dword_F8B1AC_something_todo_with_awards;
10692 goto LABEL_41;
10693 }
10694 if ( (signed int)v16 >= 3 && v7 >= 10 )
10695 {
10696 v17 = dword_F8B1AC_something_todo_with_awards;
10697 switch ( dword_F8B1AC_something_todo_with_awards )
10698 {
10699 case 19:
10700 if ( v1->_49327B(0x22u, 1) == 1 )
10701 goto LABEL_40;
10702 v26 = 1;
10703 v23 = 26;
10704 goto LABEL_39;
10705 default:
10706 goto LABEL_41;
10707 case 20:
10708 if ( v1->_49327B(0x23u, 1) == 1 )
10709 goto LABEL_40;
10710 v26 = 1;
10711 v23 = 27;
10712 LABEL_39:
10713 if ( v1->_49327B(v23, v26) == 1 )
10714 goto LABEL_40;
10715 return v35;
10716 case 30:
10717 v18 = LOBYTE(v1->pActiveSkills[31]);
10718 goto LABEL_47;
10719 case 31:
10720 v18 = LOBYTE(v1->pActiveSkills[30]);
10721 LABEL_47:
10722 if ( (v18 & 0x3Fu) < 0xA )
10723 return v35;
10724 goto LABEL_41;
10725 case 21:
10726 case 23:
10727 case 24:
10728 case 25:
10729 case 26:
10730 case 29:
10731 case 32:
10732 case 34:
10733 case 35:
10734 dword_F8B1B4 = 6000;
10735 goto LABEL_42;
10736 case 8:
10737 case 9:
10738 case 10:
10739 case 11:
10740 dword_F8B1B4 = 7000;
10741 goto LABEL_42;
10742 case 7:
10743 break;
10744 }
10745 LABEL_67:
10746 dword_F8B1B4 = 0;
10747 goto LABEL_41;
10748 }
10749 }
10750 return v35;
10751 }
10752 if ( v7 < 4 )
10753 return v35;
10754 v17 = dword_F8B1AC_something_todo_with_awards;
10755 if ( dword_F8B1AC_something_todo_with_awards > 27 )
10756 {
10757 if ( dword_F8B1AC_something_todo_with_awards != 29
10758 && dword_F8B1AC_something_todo_with_awards != 32
10759 && (dword_F8B1AC_something_todo_with_awards <= 33 || dword_F8B1AC_something_todo_with_awards > 35) )
10760 {
10761 LABEL_41:
10762 if ( !dword_F8B1B4 )
10763 goto LABEL_79;
10764 goto LABEL_42;
10765 }
10766 LABEL_87:
10767 dword_F8B1B4 = 500;
10768 goto LABEL_41;
10769 }
10770 if ( dword_F8B1AC_something_todo_with_awards >= 23 )
10771 goto LABEL_87;
10772 if ( dword_F8B1AC_something_todo_with_awards == 7 )
10773 {
10774 dword_F8B1B4 = 0;
10775 goto LABEL_79;
10776 }
10777 if ( dword_F8B1AC_something_todo_with_awards <= 7 )
10778 goto LABEL_41;
10779 if ( dword_F8B1AC_something_todo_with_awards > 18 )
10780 {
10781 if ( dword_F8B1AC_something_todo_with_awards != 21 )
10782 goto LABEL_41;
10783 goto LABEL_87;
10784 }
10785 dword_F8B1B4 = 1000;
10786 LABEL_42:
10787 if ( dword_F8B1B4 > pParty->uNumGold )
10788 return (char *)dword_721A4C;
10789 LABEL_79:
10790 dword_F8B1A8 = 1;
10791 if ( v34 == 2 )
10792 {
10793 v27 = dword_F8B1B4;
10794 v24 = pSkillNames[v17];
10795 v21 = pGlobalTXT_LocalizationStrings[433];
10796 goto LABEL_90;
10797 }
10798 if ( v34 == 3 )
10799 {
10800 v27 = dword_F8B1B4;
10801 v24 = pSkillNames[v17];
10802 v21 = pGlobalTXT_LocalizationStrings[432];
10803 goto LABEL_90;
10804 }
10805 if ( v34 == 4 )
10806 {
10807 v27 = dword_F8B1B4;
10808 v24 = pSkillNames[v17];
10809 v21 = pGlobalTXT_LocalizationStrings[225];
10810 LABEL_90:
10811 sprintfex(pTmpBuf2, pGlobalTXT_LocalizationStrings[534], v21, v24, v27);
10812 }
10813 return pTmpBuf2;
10814 }
10815
10816
10817
10818 //----- (004B29F2) --------------------------------------------------------
10819 int __fastcall sub_4B29F2(int a1)
10820 {
10821 int v1; // esi@1
10822 Player *v2; // edi@1
10823 int v3; // eax@1
10824 Player *v4; // ecx@1
10825 int result; // eax@2
10826
10827 v1 = a1;
10828 dword_F8B1A8 = 0;
10829 v2 = pPlayers[uActiveCharacter];
10830 v3 = a1 + 50;
10831 v4 = pPlayers[uActiveCharacter];
10832 dword_F8B1AC_something_todo_with_awards = v3;
10833 dword_F8B1B4 = dword_4F08EC[v1];
10834 if ( v4->CanAct() )
10835 {
10836 if ( (unsigned __int16)_449B57_test_bit((unsigned __int8 *)v2->field_152, dword_F8B1AC_something_todo_with_awards) )
10837 {
10838 result = dword_721A44;
10839 }
10840 else
10841 {
10842 if ( dword_F8B1B4 <= pParty->uNumGold )
10843 {
10844 result = dword_7219DC[2 * v1];
10845 dword_F8B1A8 = 1;
10846 }
10847 else
10848 {
10849 result = dword_721A4C;
10850 }
10851 }
10852 }
10853 else
10854 {
10855 result = (int)_721A3C_npc_text;
10856 }
10857 return result;
10858 }
10859
10860
10861 //----- (004B2A74) --------------------------------------------------------
10862 char __cdecl sub_4B2A74()
10863 {
10864 char *v0; // esi@3
10865 char *v1; // ST1C_4@3
10866 char *v2; // eax@3
10867 const char *v3; // ST1C_4@5
10868 int v4; // eax@5
10869 unsigned int i; // eax@5
10870 NPCData *v6; // esi@6
10871 unsigned __int16 v7; // bx@6
10872 unsigned int v8; // eax@6
10873 int v9; // eax@11
10874 unsigned int v10; // ecx@12
10875 int v11; // eax@12
10876 int v12; // esi@12
10877 char *v13; // eax@12
10878 GUIWindow *v14; // ebx@13
10879 char *v15; // esi@14
10880 GUIButton *v16; // eax@15
10881 unsigned int v17; // ecx@15
10882 int v18; // ecx@17
10883 int v19; // ecx@18
10884 int v20; // ecx@19
10885 int v21; // ecx@20
10886 int v22; // ecx@21
10887 unsigned int v23; // ecx@23
10888 int v24; // ecx@35
10889 int v25; // ecx@36
10890 int v26; // ecx@37
10891 int v27; // ecx@38
10892 int v28; // ecx@39
10893 char *v29; // esi@42
10894 unsigned int v30; // ST20_4@42
10895 int v31; // ST1C_4@42
10896 unsigned int v32; // eax@42
10897 char *v33; // eax@43
10898 int v34; // esi@51
10899 int v35; // eax@51
10900 unsigned int v36; // edi@51
10901 GUIButton *v37; // eax@52
10902 int v38; // eax@52
10903 signed int v39; // ecx@54
10904 int v40; // edi@57
10905 GUIButton *v41; // eax@60
10906 GUIButton *v42; // esi@60
10907 const char *v43; // ebx@60
10908 int v44; // eax@60
10909 unsigned int v45; // ecx@60
10910 unsigned __int16 v46; // ax@60
10911 GUIFont *v47; // ebx@64
10912 int v48; // esi@64
10913 char *v49; // eax@66
10914 GUIWindow w; // [sp+Ch] [bp-110h]@64
10915 GUIWindow v52; // [sp+60h] [bp-BCh]@13
10916 GUIWindow a1; // [sp+B4h] [bp-68h]@1
10917 unsigned int v54; // [sp+108h] [bp-14h]@14
10918 int v55; // [sp+10Ch] [bp-10h]@6
10919 int v56; // [sp+110h] [bp-Ch]@13
10920 char *pInString; // [sp+114h] [bp-8h]@12
10921 NPCData *v58; // [sp+118h] [bp-4h]@6
10922
10923 memcpy(&a1, pDialogueWindow, sizeof(a1));
10924 if ( array_5913D8[6] == (NPCData *)uNumDialogueNPCPortraits && uHouse_ExitPic )
10925 {
10926 v0 = pMapStats->pInfos[uHouse_ExitPic].pName;
10927 v1 = pMapStats->pInfos[uHouse_ExitPic].pName;
10928 a1.uFrameX = 493;
10929 a1.uFrameWidth = 126;
10930 a1.uFrameZ = 366;
10931 a1.DrawText2(pFontCreate, 0, 2u, 0, v1, 3u);
10932 a1.uFrameX = 483;
10933 a1.uFrameWidth = 148;
10934 a1.uFrameZ = 334;
10935 v2 = (&off_4EB080)[4 * uHouse_ExitPic];
10936 if ( !v2 )
10937 {
10938 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[411], v0);
10939 v2 = pTmpBuf;
10940 }
10941 v3 = v2;
10942 v4 = pFontCreate->CalcTextHeight(v2, &a1, 0, 0);
10943 LOBYTE(i) = (unsigned int)a1.DrawText2(pFontCreate, 0, (212 - v4) / 2 + 101, 0, v3, 3u);
10944 return i;
10945 }
10946 a1.uFrameWidth -= 10;
10947 a1.uFrameZ -= 10;
10948 v58 = array_5913D8[(unsigned int)((char *)array_5913D8[6] + -(dword_591080 != 0) - 1)];
10949 v6 = v58;
10950 v55 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xE1u, 0xCDu, 0x23u);
10951 v7 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0x15u, 0x99u, 0xE9u);
10952 v8 = v6->uProfession;
10953 if ( v8 )
10954 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[429], v6->pName, aNPCProfessionNames[v8]);
10955 else
10956 strcpy(pTmpBuf, v6->pName);
10957 a1.DrawText2(pFontCreate, 0x1E3u, 0x71u, v7, pTmpBuf, 3u);
10958 if ( !dword_591080 )
10959 {
10960 if ( !uDialogueType )
10961 {
10962 v9 = v6->greet;
10963 if ( v9 )
10964 {
10965 v10 = v6->uFlags;
10966 a1.uFrameWidth = 460;
10967 a1.uFrameZ = 452;
10968 pInString = (char *)*(&pNPCStats->field_17884 + ((v10 & 3) == 2) + 2 * v9);
10969 v11 = pFontArrus->CalcTextHeight(pInString, &a1, 13, 0);
10970 v12 = v11 + 7;
10971 pRenderer->_4A6A68(
10972 8u,
10973 352 - (v11 + 7),
10974 (Texture *)(uTextureID_Leather != -1 ? &pIcons_LOD->pTextures[uTextureID_Leather] : 0),
10975 (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - (v11 + 7));
10976 pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
10977 v13 = FitTextInAWindow(pInString, pFontArrus, &a1, 0xDu, 0);
10978 pDialogueWindow->DrawText(pFontArrus, 13, 354 - v12, 0, v13, 0, 0, 0);
10979 }
10980 }
10981 }
10982 v14 = pDialogueWindow;
10983 memcpy(&v52, pDialogueWindow, sizeof(v52));
10984 v52.uFrameX = 483;
10985 v52.uFrameWidth = 148;
10986 v52.uFrameZ = 334;
10987 v56 = v52.field_38;
10988 if ( v52.field_38 < v52.field_38 + v52.field_28 )
10989 {
10990 v15 = (char *)v54;
10991 while ( 1 )
10992 {
10993 v16 = v52.GetControl(v56);
10994 v17 = v16->uControlParam;
10995 pInString = (char *)v16;
10996 if ( (signed int)v17 > 24 )
10997 {
10998 v24 = v17 - 76;
10999 if ( !v24 )
11000 {
11001 v15 = pGlobalTXT_LocalizationStrings[406];
11002 goto LABEL_49;
11003 }
11004 v25 = v24 - 1;
11005 if ( !v25 )
11006 {
11007 v15 = pGlobalTXT_LocalizationStrings[407];
11008 goto LABEL_49;
11009 }
11010 v26 = v25 - 2;
11011 if ( !v26 )
11012 {
11013 v33 = _4B254D_SkillMasteryTeacher((int)v52.ptr_1C);
11014 LABEL_44:
11015 v15 = v33;
11016 LABEL_45:
11017 v16 = (GUIButton *)pInString;
11018 goto LABEL_49;
11019 }
11020 v27 = v26 - 3;
11021 if ( !v27 )
11022 {
11023 v33 = (char *)sub_4B29F2((int)v52.ptr_1C);
11024 goto LABEL_44;
11025 }
11026 v28 = v27 - 1;
11027 if ( !v28 )
11028 {
11029 v29 = (char *)&pMonsterStats + 88 * word_F8B1A0;
11030 v30 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
11031 v31 = *(int *)v29;
11032 v32 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
11033 sprintfex(pTmpBuf, &byte_4F0F98, v32, v31, v30);
11034 sprintfex(pTmpBuf2, dword_F8B1A4, pTmpBuf, 100 * (unsigned __int8)v29[8]);
11035 ptr_F8B1E8 = pTmpBuf2;
11036 v15 = nullstring;
11037 goto LABEL_45;
11038 }
11039 if ( v28 != 10 )
11040 goto LABEL_41;
11041 }
11042 else
11043 {
11044 if ( v17 == 24 )
11045 {
11046 v23 = v58->evtf;
11047 LABEL_33:
11048 v15 = (&dword_721660)[8 * v23];
11049 if ( !v15 )
11050 {
11051 v16->uControlParam = 0;
11052 v15 = nullstring;
11053 }
11054 goto LABEL_49;
11055 }
11056 v18 = v17 - 13;
11057 if ( v18 )
11058 {
11059 v19 = v18 - 6;
11060 if ( !v19 )
11061 {
11062 v23 = v58->bDrawSomeAnim;
11063 goto LABEL_33;
11064 }
11065 v20 = v19 - 1;
11066 if ( !v20 )
11067 {
11068 v15 = (&dword_721660)[8 * v58->evtb];
11069 if ( !v15 )
11070 {
11071 v16->uControlParam = 0;
11072 v15 = nullstring;
11073 }
11074 if ( uDialogueType != 84 )
11075 goto LABEL_49;
11076 sprintfex(pTmpBuf, format_4E2D80, v55, pItemsTable->pItems[dword_F8B1A8].pUnidentifiedName);
11077 sprintfex(pTmpBuf2, ptr_F8B1E8, pTmpBuf);
11078 ptr_F8B1E8 = pTmpBuf2;
11079 goto LABEL_45;
11080 }
11081 v21 = v20 - 1;
11082 if ( !v21 )
11083 {
11084 v23 = v58->evtc;
11085 goto LABEL_33;
11086 }
11087 v22 = v21 - 1;
11088 if ( !v22 )
11089 {
11090 v23 = v58->evtd;
11091 goto LABEL_33;
11092 }
11093 if ( v22 == 1 )
11094 {
11095 v23 = v58->evte;
11096 goto LABEL_33;
11097 }
11098 LABEL_41:
11099 v15 = nullstring;
11100 goto LABEL_49;
11101 }
11102 v15 = pGlobalTXT_LocalizationStrings[122];
11103 }
11104 LABEL_49:
11105 strcpy(v16->pButtonName, v15);
11106 ++v56;
11107 if ( v56 >= v52.field_38 + v52.field_28 )
11108 {
11109 v14 = pDialogueWindow;
11110 break;
11111 }
11112 }
11113 }
11114 v34 = 0;
11115 v54 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
11116 v35 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xE1u, 0xCDu, 0x23u);
11117 v36 = v14->field_38;
11118 v55 = v35;
11119 for ( i = v36 + v14->field_28; (signed int)v36 < (signed int)i; i = pDialogueWindow->field_28
11120 + pDialogueWindow->field_38 )
11121 {
11122 v37 = v14->GetControl(v36);
11123 v38 = pFontArrus->CalcTextHeight(v37->pButtonName, &v52, 0, 0);
11124 v14 = pDialogueWindow;
11125 v34 += v38;
11126 ++v36;
11127 }
11128 v39 = v14->field_28;
11129 if ( v39 )
11130 {
11131 v58 = (NPCData *)((174 - v34) / v39);
11132 if ( (signed int)v58 > 32 )
11133 v58 = (NPCData *)32;
11134 pInString = (char *)2;
11135 v40 = (174 - (signed int)v58 * v39 - v34) / 2 - (signed int)v58 / 2 + 138;
11136 v56 = v14->field_38;
11137 i = v56;
11138 if ( (signed int)i < (signed int)(i + v39) )
11139 {
11140 while ( 1 )
11141 {
11142 v41 = v14->GetControl(i);
11143 v42 = v41;
11144 v43 = v41->pButtonName;
11145 v41->uY = (unsigned int)((char *)v58 + v40);
11146 v44 = pFontArrus->CalcTextHeight(v41->pButtonName, &v52, 0, 0);
11147 v45 = v42->uY;
11148 v42->uHeight = v44;
11149 v40 = v45 + v44 - 1;
11150 v42->uW = v40;
11151 v46 = v55;
11152 if ( (char *)pDialogueWindow->field_2C_focus_id != pInString )
11153 v46 = v54;
11154 v52.DrawText2(pFontArrus, 0, v45, v46, v43, 3u);
11155 v14 = pDialogueWindow;
11156 ++pInString;
11157 ++v56;
11158 i = pDialogueWindow->field_28 + pDialogueWindow->field_38;
11159 if ( v56 >= (signed int)i )
11160 break;
11161 i = v56;
11162 }
11163 }
11164 }
11165 if ( ptr_F8B1E8 )
11166 {
11167 w.uFrameWidth = 458;
11168 w.uFrameZ = 457;
11169 v47 = pFontArrus;
11170 v48 = pFontArrus->CalcTextHeight(ptr_F8B1E8, &w, 13, 0) + 7;
11171 if ( 352 - v48 < 8 )
11172 {
11173 v47 = pFontCreate;
11174 v48 = pFontCreate->CalcTextHeight(ptr_F8B1E8, &w, 13, 0) + 7;
11175 }
11176 pRenderer->_4A6A68(
11177 8u,
11178 352 - v48,
11179 (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
11180 (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v48);
11181 pRenderer->DrawTextureIndexed(8u, 347 - v48, pTexture_591428);
11182 v49 = FitTextInAWindow(ptr_F8B1E8, v47, &w, 0xDu, 0);
11183 LOBYTE(i) = a1.DrawText(v47, 13, 354 - v48, 0, v49, 0, 0, 0);
11184 }
11185 return i;
11186 }
11187
11188
11189
11190
11191
11192 //----- (004B36CC) --------------------------------------------------------
11193 GUIButton *__fastcall sub_4B36CC(int a1, unsigned int a2)
11194 {
11195 return pDialogueWindow->CreateButton(
11196 0x1E0u,
11197 30 * a1 + 146,
11198 0x8Cu,
11199 0x1Eu,
11200 1,
11201 0,
11202 0x195u,
11203 a2,
11204 0,
11205 nullstring,
11206 0);
11207 }
11208
11209 //----- (004B3703) --------------------------------------------------------
11210 int __thiscall sub_4B3703(void *_this)
11211 {
11212 signed int v1; // edi@1
11213 int v2; // eax@1
11214 char *v3; // ecx@1
11215 signed int v4; // ebx@1
11216 int v5; // ecx@2
11217 int v6; // ecx@3
11218 int v7; // ecx@4
11219 int v8; // ecx@5
11220 int v9; // ecx@6
11221 signed int v10; // ebx@13
11222 signed int v11; // edi@14
11223 signed int v12; // esi@15
11224 unsigned int v13; // ecx@16
11225 int v14; // ecx@16
11226 int v15; // ecx@17
11227 int v16; // ecx@19
11228 int v17; // ecx@20
11229 int v18; // ecx@21
11230 signed int v19; // esi@32
11231 char *v20; // ecx@33
11232 int v21; // ecx@34
11233 int v22; // ecx@36
11234 int v23; // ecx@37
11235 int v24; // ecx@38
11236 int v25; // ecx@39
11237 int v26; // ecx@40
11238 int v27; // ecx@41
11239 int *v28; // esi@54
11240 unsigned int v29; // edx@56
11241 char *v30; // ecx@65
11242 int v31; // ecx@106
11243 int result; // eax@107
11244 int v33; // [sp-4h] [bp-2Ch]@23
11245 int v34; // [sp-4h] [bp-2Ch]@43
11246 int v35[5]; // [sp+Ch] [bp-1Ch]@8
11247 int a2; // [sp+20h] [bp-8h]@1
11248 int v37; // [sp+24h] [bp-4h]@1
11249
11250 v1 = 0;
11251 v2 = 0;
11252 v3 = (char *)_this - 1;
11253 a2 = 0;
11254 v37 = 0;
11255 dword_F8B1DC = 0;
11256 v4 = 2;
11257 if ( !v3 )
11258 {
11259 while ( 1 )
11260 {
11261 v19 = 1;
11262 do
11263 {
11264 v20 = (char *)ptr_507BC0->ptr_1C + 4 * (unsigned int)ptr_507BC0->ptr_1C + v19;
11265 if ( v1 )
11266 v21 = word_4F063E[(signed int)v20];
11267 else
11268 v21 = word_4F03FE[(signed int)v20];
11269 v22 = v21 - 23;
11270 if ( v22 )
11271 {
11272 v23 = v22 - 1;
11273 if ( v23 )
11274 {
11275 v24 = v23 - 1;
11276 if ( v24 )
11277 {
11278 v25 = v24 - 1;
11279 if ( v25 )
11280 {
11281 v26 = v25 - 1;
11282 if ( v26 )
11283 {
11284 v27 = v26 - 1;
11285 if ( v27 )
11286 {
11287 if ( v27 != v4 )
11288 goto LABEL_51;
11289 v34 = 36;
11290 }
11291 else
11292 {
11293 v34 = 42;
11294 }
11295 }
11296 else
11297 {
11298 v34 = 41;
11299 }
11300 }
11301 else
11302 {
11303 v34 = 40;
11304 }
11305 }
11306 else
11307 {
11308 v34 = 39;
11309 }
11310 }
11311 else
11312 {
11313 v34 = 38;
11314 }
11315 }
11316 else
11317 {
11318 v34 = 37;
11319 }
11320 v37 = sub_4BE571(v34, v35, v37, 5);
11321 v2 = dword_F8B1DC;
11322 v4 = 2;
11323 LABEL_51:
11324 ++v19;
11325 }
11326 while ( v19 <= 4 );
11327 ++v1;
11328 if ( v1 >= v4 )
11329 goto LABEL_53;
11330 }
11331 }
11332 v5 = (int)(v3 - 1);
11333 if ( !v5 )
11334 {
11335 v10 = 0;
11336 while ( 1 )
11337 {
11338 v11 = 0;
11339 do
11340 {
11341 v12 = 1;
11342 do
11343 {
11344 v13 = v11 + 2 * (unsigned int)ptr_507BC0->ptr_1C - 30;
11345 v14 = v12 + 4 * v13 + v13;
11346 if ( v10 )
11347 v15 = word_4F06D8[v14];
11348 else
11349 v15 = word_4F0498[v14];
11350 v16 = v15 - 31;
11351 if ( v16 )
11352 {
11353 v17 = v16 - 1;
11354 if ( v17 )
11355 {
11356 v18 = v17 - 1;
11357 if ( v18 )
11358 {
11359 if ( v18 != 1 )
11360 goto LABEL_28;
11361 v33 = 44;
11362 }
11363 else
11364 {
11365 v33 = 47;
11366 }
11367 }
11368 else
11369 {
11370 v33 = 46;
11371 }
11372 }
11373 else
11374 {
11375 v33 = 45;
11376 }
11377 v37 = sub_4BE571(v33, v35, v37, 5);
11378 v2 = dword_F8B1DC;
11379 LABEL_28:
11380 ++v12;
11381 }
11382 while ( v12 <= 4 );
11383 ++v11;
11384 }
11385 while ( v11 < 2 );
11386 ++v10;
11387 if ( v10 >= 2 )
11388 goto LABEL_53;
11389 }
11390 }
11391 v6 = v5 - 1;
11392 if ( v6 )
11393 {
11394 v7 = v6 - 1;
11395 if ( v7 )
11396 {
11397 v8 = v7 - 17;
11398 if ( v8 )
11399 {
11400 v9 = v8 - 2;
11401 if ( v9 )
11402 {
11403 if ( v9 == 7 )
11404 {
11405 v37 = 2;
11406 v35[0] = 69;
11407 v35[1] = 60;
11408 }
11409 }
11410 else
11411 {
11412 v37 = 3;
11413 v35[0] = 67;
11414 v35[1] = 66;
11415 v35[2] = 58;
11416 }
11417 }
11418 else
11419 {
11420 v37 = 3;
11421 v35[0] = 70;
11422 v35[1] = 65;
11423 v35[2] = 62;
11424 }
11425 }
11426 else
11427 {
11428 v37 = 2;
11429 v35[0] = 71;
11430 v35[1] = 68;
11431 }
11432 }
11433 else
11434 {
11435 v37 = 2;
11436 v35[0] = 57;
11437 v35[1] = 59;
11438 }
11439 LABEL_53:
11440 if ( v37 > 0 )
11441 {
11442 v28 = v35;
11443 while ( 1 )
11444 {
11445 v29 = *v28;
11446 if ( *v28 <= 47 )
11447 break;
11448 if ( (signed int)v29 <= 66 )
11449 {
11450 if ( v29 == 66 )
11451 {
11452 v30 = pSkillNames[30];
11453 goto LABEL_106;
11454 }
11455 if ( v29 == 57 )
11456 {
11457 v30 = pSkillNames[21];
11458 goto LABEL_106;
11459 }
11460 if ( v29 == 58 )
11461 {
11462 v30 = pSkillNames[22];
11463 goto LABEL_106;
11464 }
11465 if ( v29 == 60 )
11466 {
11467 v30 = pSkillNames[24];
11468 goto LABEL_106;
11469 }
11470 if ( v29 == 62 )
11471 {
11472 v30 = pSkillNames[26];
11473 goto LABEL_106;
11474 }
11475 if ( v29 == 65 )
11476 {
11477 v30 = pSkillNames[29];
11478 goto LABEL_106;
11479 }
11480 goto LABEL_100;
11481 }
11482 switch ( v29 )
11483 {
11484 case 0x43u:
11485 v30 = pSkillNames[31];
11486 break;
11487 case 0x44u:
11488 v30 = pSkillNames[32];
11489 break;
11490 case 0x45u:
11491 v30 = pSkillNames[33];
11492 break;
11493 case 0x46u:
11494 v30 = pSkillNames[34];
11495 break;
11496 default:
11497 if ( v29 != 71 )
11498 goto LABEL_100;
11499 v30 = pSkillNames[35];
11500 break;
11501 }
11502 LABEL_106:
11503 pShopOptions[v2] = v30;
11504 v31 = a2++;
11505 dword_F8B1DC = v2 + 1;
11506 sub_4B36CC(v31, v29);
11507 ++v28;
11508 if ( a2 >= v37 )
11509 goto LABEL_107;
11510 v2 = dword_F8B1DC;
11511 }
11512 if ( *v28 == 47 )
11513 {
11514 v30 = pSkillNames[11];
11515 goto LABEL_106;
11516 }
11517 if ( (signed int)v29 > 40 )
11518 {
11519 if ( v29 == 41 )
11520 {
11521 v30 = pSkillNames[5];
11522 goto LABEL_106;
11523 }
11524 if ( v29 == 42 )
11525 {
11526 v30 = pSkillNames[6];
11527 goto LABEL_106;
11528 }
11529 if ( v29 == 44 )
11530 {
11531 v30 = pSkillNames[8];
11532 goto LABEL_106;
11533 }
11534 if ( v29 == 45 )
11535 {
11536 v30 = pSkillNames[9];
11537 goto LABEL_106;
11538 }
11539 if ( v29 == 46 )
11540 {
11541 v30 = pSkillNames[10];
11542 goto LABEL_106;
11543 }
11544 }
11545 else
11546 {
11547 if ( v29 == 40 )
11548 {
11549 v30 = pSkillNames[4];
11550 goto LABEL_106;
11551 }
11552 if ( v29 == 5 )
11553 {
11554 v30 = pSkillNames[23];
11555 goto LABEL_106;
11556 }
11557 if ( v29 == 36 )
11558 {
11559 v30 = pSkillNames[0];
11560 goto LABEL_106;
11561 }
11562 if ( v29 == 37 )
11563 {
11564 v30 = pSkillNames[1];
11565 goto LABEL_106;
11566 }
11567 if ( v29 == 38 )
11568 {
11569 v30 = pSkillNames[2];
11570 goto LABEL_106;
11571 }
11572 if ( v29 == 39 )
11573 {
11574 v30 = pSkillNames[3];
11575 goto LABEL_106;
11576 }
11577 }
11578 LABEL_100:
11579 v30 = pGlobalTXT_LocalizationStrings[127];
11580 goto LABEL_106;
11581 }
11582 LABEL_107:
11583 pDialogueWindow->_41D08F(a2, 1, 0, 2);
11584 result = pDialogueWindow->field_28;
11585 dword_F8B1E0 = pDialogueWindow->field_28;
11586 return result;
11587 }
11588
11589
11590 //----- (004B3A72) --------------------------------------------------------
11591 int __thiscall sub_4B3A72(int a1)
11592 {
11593 int v1; // esi@1
11594 int result; // eax@4
11595
11596 v1 = 0;
11597 if ( a1 == 21 )
11598 {
11599 sub_4B36CC(0, 0x66u);
11600 v1 = 2;
11601 sub_4B36CC(1, 0x67u);
11602 if ( pParty->HasItem(0x28Bu) )
11603 {
11604 v1 = 3;
11605 sub_4B36CC(2, 0x68u);
11606 }
11607 }
11608 pDialogueWindow->_41D08F(v1, 1, 0, 2);
11609 result = pDialogueWindow->field_28;
11610 dword_F8B1E0 = pDialogueWindow->field_28;
11611 return result;
11612 }
11613 // F8B1E0: using guessed type int dword_F8B1E0;
11614
11615 //----- (004B3AD4) --------------------------------------------------------
11616 int __fastcall sub_4B3AD4(signed int a1)
11617 {
11618 int result; // eax@7
11619 int v2; // [sp-10h] [bp-10h]@4
11620 int v3; // [sp-Ch] [bp-Ch]@4
11621 int v4; // [sp-8h] [bp-8h]@4
11622 int v5; // [sp-4h] [bp-4h]@4
11623
11624 if ( a1 > 0 )
11625 {
11626 if ( a1 <= 3 )
11627 {
11628 sub_4B36CC(0, 3u);
11629 sub_4B36CC(1, 4u);
11630 sub_4B36CC(2, 5u);
11631 v5 = 2;
11632 v4 = 0;
11633 v3 = 1;
11634 v2 = 3;
11635 goto LABEL_6;
11636 }
11637 if ( a1 == 4 )
11638 {
11639 sub_4B36CC(0, 3u);
11640 sub_4B36CC(1, 4u);
11641 v5 = 2;
11642 v4 = 0;
11643 v3 = 1;
11644 v2 = 2;
11645 LABEL_6:
11646 pDialogueWindow->_41D08F(v2, v3, v4, v5);
11647 goto LABEL_7;
11648 }
11649 }
11650 LABEL_7:
11651 result = pDialogueWindow->field_28;
11652 dword_F8B1E0 = pDialogueWindow->field_28;
11653 return result;
11654 }
11655 // F8B1E0: using guessed type int dword_F8B1E0;
11656
11657 //----- (004B3B42) --------------------------------------------------------
11658 int __fastcall sub_4B3B42(signed int a1)
11659 {
11660 int v1; // ecx@18
11661 int v2; // ecx@19
11662 int v3; // ecx@20
11663 signed int v4; // esi@22
11664 signed int v5; // eax@22
11665 unsigned int v6; // edx@24
11666 int v7; // ecx@24
11667 int result; // eax@43
11668 int v9; // [sp-10h] [bp-14h]@28
11669 int v10; // [sp-Ch] [bp-10h]@28
11670 int v11; // [sp-8h] [bp-Ch]@28
11671 unsigned int v12; // [sp-4h] [bp-8h]@4
11672 unsigned int v13; // [sp-4h] [bp-8h]@5
11673 unsigned int v14; // [sp-4h] [bp-8h]@9
11674 unsigned int v15; // [sp-4h] [bp-8h]@10
11675 unsigned int v16; // [sp-4h] [bp-8h]@14
11676 int v17; // [sp-4h] [bp-8h]@28
11677
11678 if ( a1 > 13 )
11679 {
11680 if ( a1 > 22 )
11681 {
11682 if ( a1 == 23 )
11683 {
11684 sub_4B36CC(0, 0xAu);
11685 sub_4B36CC(1, 0xBu);
11686 v14 = 96;
11687 LABEL_41:
11688 sub_4B36CC(2, v14);
11689 v17 = 2;
11690 v11 = 0;
11691 v10 = 1;
11692 v9 = 3;
11693 goto LABEL_42;
11694 }
11695 if ( a1 <= 26 )
11696 goto LABEL_43;
11697 if ( a1 > 28 )
11698 {
11699 if ( a1 != 30 )
11700 goto LABEL_43;
11701 sub_4B36CC(0, 0x11u);
11702 v16 = 96;
11703 goto LABEL_37;
11704 }
11705 sub_4B36CC(0, 0x69u);
11706 sub_4B36CC(1, 0x6Au);
11707 sub_4B36CC(2, 0x6Bu);
11708 v12 = 108;
11709 }
11710 else
11711 {
11712 if ( a1 == 22 )
11713 {
11714 sub_4B36CC(0, 7u);
11715 v16 = 8;
11716 goto LABEL_37;
11717 }
11718 v1 = a1 - 14;
11719 if ( !v1 )
11720 {
11721 sub_4B36CC(0, 0x12u);
11722 sub_4B36CC(1, 0x30u);
11723 sub_4B36CC(2, 0x31u);
11724 sub_4B36CC(3, 0x32u);
11725 sub_4B36CC(4, 0x33u);
11726 v17 = 2;
11727 v11 = 0;
11728 v10 = 1;
11729 v9 = 5;
11730 goto LABEL_42;
11731 }
11732 v2 = v1 - 1;
11733 if ( v2 )
11734 {
11735 v3 = v2 - 2;
11736 if ( v3 )
11737 {
11738 if ( v3 != 4 )
11739 goto LABEL_43;
11740 sub_4B36CC(0, 0xFu);
11741 sub_4B36CC(1, 0x10u);
11742 v4 = 3;
11743 sub_4B36CC(2, 0x60u);
11744 v5 = (signed int)ptr_507BC0->ptr_1C;
11745 if ( v5 < 108 || v5 > 120 )
11746 goto LABEL_28;
11747 v4 = 4;
11748 v6 = 101;
11749 v7 = 3;
11750 }
11751 else
11752 {
11753 v4 = 1;
11754 sub_4B36CC(0, 0x63u);
11755 if ( !pParty->uFine )
11756 {
11757 LABEL_28:
11758 v17 = 2;
11759 v11 = 0;
11760 v10 = 1;
11761 v9 = v4;
11762 LABEL_42:
11763 pDialogueWindow->_41D08F(v9, v10, v11, v17);
11764 goto LABEL_43;
11765 }
11766 v4 = 2;
11767 v7 = 1;
11768 v6 = 100;
11769 }
11770 sub_4B36CC(v7, v6);
11771 goto LABEL_28;
11772 }
11773 sub_4B36CC(0, 0x12u);
11774 sub_4B36CC(1, 0x34u);
11775 sub_4B36CC(2, 0x35u);
11776 v12 = 54;
11777 }
11778 LABEL_39:
11779 sub_4B36CC(3, v12);
11780 v17 = 2;
11781 v11 = 0;
11782 v10 = 1;
11783 v9 = 4;
11784 goto LABEL_42;
11785 }
11786 if ( a1 == 13 )
11787 {
11788 sub_4B36CC(0, 0x12u);
11789 v16 = 56;
11790 LABEL_37:
11791 sub_4B36CC(1, v16);
11792 v17 = 2;
11793 v11 = 0;
11794 v10 = 1;
11795 v9 = 2;
11796 goto LABEL_42;
11797 }
11798 switch ( a1 )
11799 {
11800 case 1:
11801 case 2:
11802 case 3:
11803 case 4:
11804 sub_4B36CC(0, 2u);
11805 sub_4B36CC(1, 0x5Fu);
11806 sub_4B36CC(2, 0x5Eu);
11807 v12 = 96;
11808 goto LABEL_39;
11809 case 5:
11810 sub_4B36CC(0, 0x12u);
11811 v13 = 48;
11812 goto LABEL_9;
11813 case 6:
11814 sub_4B36CC(0, 0x12u);
11815 v13 = 49;
11816 goto LABEL_9;
11817 case 7:
11818 sub_4B36CC(0, 0x12u);
11819 v13 = 50;
11820 goto LABEL_9;
11821 case 8:
11822 sub_4B36CC(0, 0x12u);
11823 v13 = 51;
11824 LABEL_9:
11825 sub_4B36CC(1, v13);
11826 v14 = 72;
11827 goto LABEL_41;
11828 case 9:
11829 sub_4B36CC(0, 0x12u);
11830 v15 = 52;
11831 goto LABEL_13;
11832 case 10:
11833 sub_4B36CC(0, 0x12u);
11834 v15 = 53;
11835 goto LABEL_13;
11836 case 11:
11837 sub_4B36CC(0, 0x12u);
11838 v15 = 54;
11839 LABEL_13:
11840 sub_4B36CC(1, v15);
11841 v14 = 61;
11842 goto LABEL_41;
11843 case 12:
11844 sub_4B36CC(0, 0x12u);
11845 v16 = 55;
11846 goto LABEL_37;
11847 default:
11848 break;
11849 }
11850 LABEL_43:
11851 result = pDialogueWindow->field_28;
11852 dword_F8B1E0 = pDialogueWindow->field_28;
11853 return result;
11854 }
11855 // F8B1E0: using guessed type int dword_F8B1E0;
11856
11857 //----- (004B3E1E) --------------------------------------------------------
11858 void __cdecl sub_4B3E1E()
11859 {
11860 NPCData *v0; // ST40_4@1
11861 signed int v1; // edi@1
11862 GUIWindow *v2; // ecx@1
11863
11864 v0 = GetNPCData(uDialogue_SpeakingActorNPC_ID);
11865 v1 = 0;
11866 pDialogueWindow->uWindowType = 1;
11867 pDialogueWindow->Release();
11868 v2 = GUIWindow::Create(0, 0, 0x280u, 0x1E0u, (enum WindowType)10, 1, 0);
11869 pDialogueWindow = v2;
11870 if ( *(&pNPCStats->field_13A5C + 5 * v0->uProfession) )
11871 {
11872 v2->CreateButton(
11873 0x1E0u,
11874 0xA0u,
11875 0x8Cu,
11876 0x1Eu,
11877 1,
11878 0,
11879 0x88u,
11880 0x4Du,
11881 0,
11882 pGlobalTXT_LocalizationStrings[407],
11883 0);
11884 v1 = 1;
11885 }
11886 pDialogueWindow->CreateButton(
11887 0x1E0u,
11888 30 * v1 + 160,
11889 0x8Cu,
11890 0x1Eu,
11891 1,
11892 0,
11893 0x88u,
11894 0x4Cu,
11895 0,
11896 pGlobalTXT_LocalizationStrings[406],
11897 0);
11898 pDialogueWindow->_41D08F(v1 + 1, 1, 0, 1);
11899 }
11900
11901 //----- (004B3EF0) --------------------------------------------------------
11902 void __fastcall sub_4B3EF0(int a4)
11903 {
11904 int v1; // edi@1
11905
11906 v1 = a4;
11907 uDialogueType = 81;
11908 ptr_F8B1E8 = (char *)dword_721984[2 * a4];
11909 sub_4B29F2(a4);
11910 pDialogueWindow->Release();
11911 pDialogueWindow = GUIWindow::Create(0, 0, 0x280u, 0x15Eu, WINDOW_Credits, v1, 0);
11912 ptr_5076F4 = pDialogueWindow->CreateButton(
11913 0x1D7u,
11914 0x1BDu,
11915 0xA9u,
11916 0x23u,
11917 1,
11918 0,
11919 0x71u,
11920 0,
11921 0,
11922 pGlobalTXT_LocalizationStrings[34],
11923 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0),
11924 0);
11925 pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, 0x51u, 0, 0, nullstring, 0);
11926 pDialogueWindow->CreateButton(
11927 0x1E0u,
11928 0xA0u,
11929 0x8Cu,
11930 0x1Eu,
11931 1,
11932 0,
11933 0xAFu,
11934 0x52u,
11935 0,
11936 pGlobalTXT_LocalizationStrings[122],
11937 0);
11938 pDialogueWindow->_41D08F(1, 1, 0, 2);
11939 dword_F8B19C = -1;
11940 }
11941 // F8B19C: using guessed type int dword_F8B19C;
11942
11943 //----- (004B3FE5) --------------------------------------------------------
11944 void __fastcall sub_4B3FE5(int a4)
11945 {
11946 int v1; // edi@1
11947 char *v2; // edi@1
11948
11949 v1 = a4;
11950 uDialogueType = 78;
11951 ptr_F8B1E8 = (char *)dword_721BAC[2 * a4];
11952 _4B254D_SkillMasteryTeacher(a4);
11953 pDialogueWindow->Release();
11954 pDialogueWindow = GUIWindow::Create(0, 0, 0x280u, 0x15Eu, WINDOW_Credits, v1, 0);
11955 v2 = nullstring;
11956 ptr_5076F4 = pDialogueWindow->CreateButton(
11957 0x1D7u,
11958 0x1BDu,
11959 0xA9u,
11960 0x23u,
11961 1,
11962 0,
11963 0x71u,
11964 0,
11965 0,
11966 pGlobalTXT_LocalizationStrings[34],
11967 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0),
11968 0);
11969 pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, 0x51u, 0, 0, nullstring, 0);
11970 if ( dword_F8B1A8 )
11971 v2 = pGlobalTXT_LocalizationStrings[535];
11972 pDialogueWindow->CreateButton(0x1E0u, 0xA0u, 0x8Cu, 0x1Eu, 1, 0, 0xAFu, 0x4Fu, 0, v2, 0);
11973 pDialogueWindow->_41D08F(1, 1, 0, 2);
11974 dword_F8B19C = -1;
11975 }
11976 // F8B19C: using guessed type int dword_F8B19C;
11977 // F8B1A8: using guessed type int dword_F8B1A8;
11978
11979 //----- (004B40E6) --------------------------------------------------------
11980 void __cdecl sub_4B40E6()
11981 {
11982 signed int v0; // ebx@1
11983 NPCData *v1; // edi@1
11984
11985 v0 = 0;
11986 v1 = array_5913D8[(unsigned int)((char *)array_5913D8[6] + -(dword_591080 != 0) - 1)];
11987 pDialogueWindow->Release();
11988 pDialogueWindow = GUIWindow::Create(0, 0, 0x280u, 0x15Eu, WINDOW_Credits, 0, 0);
11989 ptr_5076F4 = pDialogueWindow->CreateButton(
11990 0x1D7u,
11991 0x1BDu,
11992 0xA9u,
11993 0x23u,
11994 1,
11995 0,
11996 0x71u,
11997 0,
11998 0,
11999 pGlobalTXT_LocalizationStrings[34],
12000 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0),
12001 0);
12002 pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, 0x51u, 0, 0, nullstring, 0);
12003 if ( *(&pNPCStats->field_13A5C + 5 * v1->uProfession) )
12004 {
12005 pDialogueWindow->CreateButton(
12006 0x1E0u,
12007 0xA0u,
12008 0x8Cu,
12009 0x1Eu,
12010 1,
12011 0,
12012 0xAFu,
12013 0x4Du,
12014 0,
12015 pGlobalTXT_LocalizationStrings[407],
12016 0);
12017 v0 = 1;
12018 }
12019 pDialogueWindow->CreateButton(
12020 0x1E0u,
12021 30 * v0 + 160,
12022 0x8Cu,
12023 0x1Eu,
12024 1,
12025 0,
12026 0xAFu,
12027 0x4Cu,
12028 0,
12029 pGlobalTXT_LocalizationStrings[406],
12030 0);
12031 pDialogueWindow->_41D08F(v0 + 1, 1, 0, 2);
12032 dword_F8B19C = -1;
12033 }
12034
12035
12036 //----- (004B4224) --------------------------------------------------------
12037 GUIButton *_4B4224_UpdateNPCTopics(int _this)
12038 {
12039 int v1; // ebx@1
12040 GUIButton *result; // eax@3
12041 int i; // ebp@5
12042 signed int v4; // ebp@9
12043 void *v5; // ecx@14
12044 bool v6; // eax@16
12045 void *v7; // ecx@19
12046 bool v8; // eax@21
12047 void *v9; // ecx@24
12048 bool v10; // eax@26
12049 void *v11; // ecx@29
12050 bool v12; // eax@31
12051 void *v13; // ecx@34
12052 bool v14; // eax@36
12053 void *v15; // ecx@39
12054 bool v16; // eax@41
12055 NPCData *v17; // [sp+10h] [bp-4h]@4
12056
12057 v1 = 0;
12058 array_5913D8[6] = (NPCData *)(_this + 1);
12059 if ( _this + 1 == uNumDialogueNPCPortraits && uHouse_ExitPic )
12060 {
12061 pDialogueWindow->Release();
12062 pDialogueWindow = GUIWindow::Create(0, 0, 0x280u, 0x1E0u, WINDOW_Credits, 0, 0);
12063 sprintfex(byte_591098, pGlobalTXT_LocalizationStrings[411], pMapStats->pInfos[uHouse_ExitPic].pName);
12064 ptr_5076F4 = pDialogueWindow->CreateButton(
12065 0x236u,
12066 0x1BDu,
12067 0x4Bu,
12068 0x21u,
12069 1,
12070 0,
12071 0x71u,
12072 0,
12073 0x4Eu,
12074 pGlobalTXT_LocalizationStrings[34],// "Cancel"
12075 (Texture *)(uTextureID_BUTTDESC2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTDESC2] : 0),
12076 0);
12077 ptr_5076FC = pDialogueWindow->CreateButton(
12078 486u,
12079 445u,
12080 75u,
12081 33u,
12082 1,
12083 0,
12084 0xBFu,
12085 1u,
12086 0x59u,
12087 byte_591098,
12088 (Texture *)(uTextureID_BUTTYES2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTYES2] : 0),
12089 0);
12090 pDialogueWindow->CreateButton(
12091 _4E5E50_transui_x,
12092 _4E5EE0_transui_y,
12093 63u,
12094 73u,
12095 1,
12096 0,
12097 0xBFu,
12098 1u,
12099 0x20u,
12100 byte_591098,
12101 0);
12102 result = pDialogueWindow->CreateButton(8u, 8u, 460u, 344u, 1, 0, 0xBFu, 1u, 0x59u, byte_591098, 0);
12103 }
12104 else
12105 {
12106 v17 = array_5913D8[_this + 1 - ((dword_591080 != 0) + 1)];
12107 if ( dword_F8B19C == -1 )
12108 {
12109 pDialogueWindow->Release();
12110 }
12111 else
12112 {
12113 for ( i = 0; i < uNumDialogueNPCPortraits; ++i )
12114 GUIButton::_41D0D8((GUIButton *)array_5913D8[i + 7]);
12115 }
12116 v4 = 1;
12117 pDialogueWindow = GUIWindow::Create(0, 0, 0x280u, 0x159u, WINDOW_Credits, 0, 0);
12118 ptr_5076F4 = pDialogueWindow->CreateButton(
12119 471u,
12120 445u,
12121 169u,
12122 35u,
12123 1,
12124 0,
12125 0x71u,
12126 0,
12127 0,
12128 pGlobalTXT_LocalizationStrings[74],// "End Conversation"
12129 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0),
12130 0);
12131 pDialogueWindow->CreateButton(8u, 8u, 0x1C2u, 0x140u, 1, 0, 0x51u, 0, 0, nullstring, 0);
12132 if ( array_5913D8[6] == (NPCData *)1 && dword_591080 )
12133 {
12134 result = (GUIButton *)sub_4B3B42(dword_F8B198);
12135 }
12136 else
12137 {
12138 if ( v17->joins )
12139 {
12140 v1 = 1;
12141 pDialogueWindow->CreateButton(480u, 160u, 140u, 30u, 1, 0, 0xAFu, 0xDu, 0, nullstring, 0);
12142 }
12143 v5 = (void *)v17->bDrawSomeAnim;
12144 if ( v5 )
12145 {
12146 if ( v1 < 4 )
12147 {
12148 v6 = sub_4466C4(v5);
12149 if ( v6 == 1 || v6 == 2 )
12150 pDialogueWindow->CreateButton(
12151 480u,
12152 30 * v1++ + 160,
12153 140u,
12154 30u,
12155 1,
12156 0,
12157 0xAFu,
12158 0x13u,
12159 0,
12160 nullstring,
12161 0);
12162 }
12163 }
12164 v7 = (void *)v17->evtb;
12165 if ( v7 )
12166 {
12167 if ( v1 < 4 )
12168 {
12169 v8 = sub_4466C4(v7);
12170 if ( v8 == 1 || v8 == 2 )
12171 pDialogueWindow->CreateButton(
12172 480u,
12173 30 * v1++ + 160,
12174 140u,
12175 30u,
12176 1,
12177 0,
12178 0xAFu,
12179 0x14u,
12180 0,
12181 nullstring,
12182 0);
12183 }
12184 }
12185 v9 = (void *)v17->evtc;
12186 if ( v9 )
12187 {
12188 if ( v1 < 4 )
12189 {
12190 v10 = sub_4466C4(v9);
12191 if ( v10 == 1 || v10 == 2 )
12192 pDialogueWindow->CreateButton(
12193 480u,
12194 30 * v1++ + 160,
12195 140u,
12196 30u,
12197 1,
12198 0,
12199 0xAFu,
12200 0x15u,
12201 0,
12202 nullstring,
12203 0);
12204 }
12205 }
12206 v11 = (void *)v17->evtd;
12207 if ( v11 )
12208 {
12209 if ( v1 < 4 )
12210 {
12211 v12 = sub_4466C4(v11);
12212 if ( v12 == 1 || v12 == 2 )
12213 pDialogueWindow->CreateButton(
12214 0x1E0u,
12215 30 * v1++ + 160,
12216 0x8Cu,
12217 0x1Eu,
12218 1,
12219 0,
12220 0xAFu,
12221 0x16u,
12222 0,
12223 nullstring,
12224 0);
12225 }
12226 }
12227 v13 = (void *)v17->evte;
12228 if ( v13 )
12229 {
12230 if ( v1 < 4 )
12231 {
12232 v14 = sub_4466C4(v13);
12233 if ( v14 == 1 || v14 == 2 )
12234 pDialogueWindow->CreateButton(
12235 0x1E0u,
12236 30 * v1++ + 160,
12237 0x8Cu,
12238 0x1Eu,
12239 1,
12240 0,
12241 0xAFu,
12242 0x17u,
12243 0,
12244 nullstring,
12245 0);
12246 }
12247 }
12248 v15 = (void *)v17->evtf;
12249 if ( v15 )
12250 {
12251 if ( v1 < 4 )
12252 {
12253 v16 = sub_4466C4(v15);
12254 if ( v16 == 1 || v16 == 2 )
12255 pDialogueWindow->CreateButton(
12256 0x1E0u,
12257 30 * v1++ + 160,
12258 0x8Cu,
12259 0x1Eu,
12260 1,
12261 0,
12262 0xAFu,
12263 0x18u,
12264 0,
12265 nullstring,
12266 0);
12267 }
12268 }
12269 pDialogueWindow->_41D08F(v1, 1, 0, 2);
12270 v4 = 1;
12271 result = (GUIButton *)pDialogueWindow->field_28;
12272 dword_F8B1E0 = pDialogueWindow->field_28;
12273 }
12274 dword_F8B19C = v4;
12275 }
12276 return result;
12277 }
12278
12279
12280
12281 //----- (004B46A5) --------------------------------------------------------
12282 char __fastcall sub_4B46A5(const char *Str, int a5)
12283 {
12284 const char *v2; // esi@1
12285 int v3; // edi@1
12286 int v4; // eax@1
12287
12288 v2 = Str;
12289 v3 = a5;
12290 pRenderer->DrawTextureRGB(0, 0x160u, pTexture_StatusBar);
12291 v4 = pFontLucida->AlignText_Center(0x1C2u, v2);
12292 return pGUIWindow0->DrawText(pFontLucida, v4 + 11, 357, v3, v2, 0, 0, 0);
12293 }
12294
12295 //----- (004B46F8) --------------------------------------------------------
12296 int __fastcall sub_4B46F8(int a1)
12297 {
12298 int v1; // eax@1
12299 int i; // edx@1
12300
12301 v1 = 0;
12302 for ( i = 0; i < a1; ++i )
12303 v1 += i + 1;
12304 return 1000 * v1;
12305 }
12306
12307 //----- (004B4710) --------------------------------------------------------
12308 int __cdecl ui_training()
12309 {
12310 Player *v0; // ebx@1
12311 int color2; // eax@1
12312 unsigned int v2; // ecx@1
12313 int v3; // eax@1
12314 signed int v4; // edx@1
12315 int v5; // edi@3
12316 unsigned int v6; // esi@3
12317 void *v7; // ecx@3
12318 int v8; // edx@4
12319 double v9; // st7@6
12320 signed int v10; // esi@6
12321 int v11; // ecx@6
12322 int result; // eax@9
12323 GUIWindow *v13; // edi@14
12324 signed int v14; // esi@14
12325 unsigned int v15; // esi@16
12326 int v16; // eax@16
12327 unsigned int v17; // eax@17
12328 int v18; // eax@19
12329 int v19; // ecx@24
12330 GUIButton *v20; // eax@26
12331 GUIButton *v21; // esi@26
12332 int v22; // eax@26
12333 const char *v23; // eax@28
12334 int v24; // eax@28
12335 unsigned int v25; // ecx@28
12336 int v26; // eax@28
12337 unsigned __int16 v27; // ax@28
12338 int v28; // eax@32
12339 unsigned __int16 v29; // ST14_2@34
12340 int v30; // eax@34
12341 const char *v31; // ST18_4@36
12342 unsigned __int16 v32; // ST14_2@36
12343 int v33; // eax@36
12344 int v34; // eax@37
12345 unsigned int v35; // edi@38
12346 unsigned int v36; // eax@38
12347 int v37; // ecx@41
12348 char *v38; // eax@41
12349 int *v39; // eax@45
12350 unsigned int v40; // eax@46
12351 void *v41; // ecx@46
12352 unsigned int v42; // eax@46
12353 GUIWindow *v43; // ecx@59
12354 int v44; // edx@59
12355 char **v45; // esi@60
12356 int v46; // eax@62
12357 int v47; // eax@68
12358 int v48; // edx@69
12359 int v49; // ebx@69
12360 unsigned __int8 v50; // sf@69
12361 char **v51; // edi@70
12362 GUIButton *v52; // eax@71
12363 GUIButton *v53; // esi@71
12364 int v54; // eax@71
12365 unsigned int v55; // ecx@71
12366 int v56; // eax@71
12367 unsigned __int16 v57; // ax@71
12368 unsigned __int16 v58; // [sp-Ch] [bp-90h]@38
12369 const char *v59; // [sp-Ch] [bp-90h]@63
12370 char *v60; // [sp-8h] [bp-8Ch]@38
12371 char *v61; // [sp-8h] [bp-8Ch]@63
12372 unsigned int v62; // [sp-4h] [bp-88h]@38
12373 int v63; // [sp-4h] [bp-88h]@52
12374 char *v64; // [sp-4h] [bp-88h]@63
12375 GUIWindow v65; // [sp+Ch] [bp-78h]@1
12376 __int64 v66; // [sp+60h] [bp-24h]@3
12377 unsigned int white; // [sp+68h] [bp-1Ch]@1
12378 int v68; // [sp+6Ch] [bp-18h]@3
12379 int v69; // [sp+70h] [bp-14h]@6
12380 unsigned int i; // [sp+74h] [bp-10h]@1
12381 int v71; // [sp+78h] [bp-Ch]@1
12382 int v72; // [sp+7Ch] [bp-8h]@16
12383 int v73; // [sp+80h] [bp-4h]@14
12384
12385 v0 = pPlayers[uActiveCharacter];
12386 memcpy(&v65, ptr_507BC0, sizeof(v65));
12387 v65.uFrameX = 483;
12388 v65.uFrameWidth = 148;
12389 v65.uFrameZ = 334;
12390 white = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
12391 color2 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xE1u, 0xCDu, 0x23u);
12392 v2 = v0->uLevel;
12393 v71 = color2;
12394 v3 = 0;
12395 v4 = 0;
12396 for ( i = v2; v4 < (signed int)v2; ++v4 )
12397 v3 += v4 + 1;
12398 v5 = 1000 * v3;
12399 v6 = HIDWORD(v0->uExperience);
12400 v7 = ptr_507BC0->ptr_1C;
12401 v68 = (unsigned __int16)word_4F0866[(signed int)v7];
12402 v66 = 1000 * v3;
12403 if ( (signed __int64)__PAIR__(v6, LODWORD(v0->uExperience)) >= v66 )
12404 {
12405 v8 = v0->uClass % 4 + 1;
12406 if ( v8 == 4 )
12407 v8 = 3;
12408 v9 = (double)(signed int)i;
12409 i = 0;
12410 v69 = v8;
12411 //v10 = (signed __int64)(v9 * p2DEvents_minus1__20[13 * (signed int)v7] * (double)v8);
12412 v10 = (signed __int64)(v9 * p2DEvents[(signed int)v7 - 1].fPriceMultiplier * (double)v8);
12413 v11 = v10 * (100 - v0->GetMerchant()) / 100;
12414 if ( v11 < v10 / 3 )
12415 v11 = v10 / 3;
12416 i = v11;
12417 }
12418 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
12419 if ( result )
12420 {
12421 if ( dword_F8B19C != 1 )
12422 {
12423 if ( dword_F8B19C != 17 )
12424 {
12425 result = dword_F8B19C - 96;
12426 if ( dword_F8B19C == 96 )
12427 {
12428 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
12429 if ( result )
12430 {
12431 i = 0;
12432 v13 = pDialogueWindow;
12433 //v14 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (unsigned int)ptr_507BC0->ptr_1C] * 500.0);
12434 v14 = (signed __int64)(p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].flt_24 * 500.0);
12435 v73 = v14 * (100 - v0->GetMerchant()) / 100;
12436 if ( v73 < v14 / 3 )
12437 v73 = v14 / 3;
12438 v15 = v13->field_38;
12439 v16 = v13->field_28;
12440 v72 = 0;
12441 if ( (signed int)v15 >= (signed int)(v15 + v16) )
12442 goto LABEL_76;
12443 do
12444 {
12445 v17 = v13->GetControl(v15)->uControlParam - 36;
12446 if ( byte_4ED970_skill_learn_ability_by_class_table[v0->uClass][v17] && !v0->pActiveSkills[v17] )
12447 {
12448 v18 = pFontArrus->CalcTextHeight(pSkillNames[v17], &v65, 0, 0);
12449 i += v18;
12450 ++v72;
12451 }
12452 ++v15;
12453 }
12454 while ( (signed int)v15 < v13->field_28 + v13->field_38 );
12455 if ( v72 )
12456 {
12457 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[401], v73);// "Skill Cost: %lu"
12458 v65.DrawText2(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
12459 v73 = (signed int)(149 - i) / v72;
12460 if ( v73 > 32 )
12461 v73 = 32;
12462 result = v13->field_38;
12463 v19 = (signed int)(149 - v72 * v73 - i) / 2 - v73 / 2 + 162;
12464 i = result;
12465 v68 = v19;
12466 if ( result < result + v13->field_28 )
12467 {
12468 v72 = 2;
12469 do
12470 {
12471 v20 = v13->GetControl(i);
12472 v21 = v20;
12473 v22 = v20->uControlParam - 36;
12474 if ( !byte_4ED970_skill_learn_ability_by_class_table[v0->uClass][v22] || v0->pActiveSkills[v22] )
12475 {
12476 v21->uW = 0;
12477 v21->uHeight = 0;
12478 v21->uY = 0;
12479 }
12480 else
12481 {
12482 v23 = pSkillNames[v22];
12483 v21->uY = v73 + v68;
12484 HIDWORD(v66) = (int)v23;
12485 v24 = pFontArrus->CalcTextHeight(v23, &v65, 0, 0);
12486 v25 = v21->uY;
12487 v21->uHeight = v24;
12488 v26 = v25 + v24 - 1;
12489 v21->uW = v26;
12490 v68 = v26;
12491 v27 = v71;
12492 if ( pDialogueWindow->field_2C_focus_id != v72 )
12493 v27 = white;
12494 v65.DrawText2(pFontArrus, 0, v25, v27, (char *)HIDWORD(v66), 3u);
12495 }
12496 v28 = v13->field_38;
12497 ++i;
12498 result = v13->field_28 + v28;
12499 ++v72;
12500 }
12501 while ( (signed int)i < result );
12502 }
12503 }
12504 else
12505 {
12506 LABEL_76:
12507 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[544], v0->pName, pClassNames[v0->uClass]);//
12508 // "Seek knowledge elsewhere %s the %s"
12509 strcat(pTmpBuf, "\n \n");
12510 strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);// "I can offer you nothing further."
12511 v29 = v71;
12512 v30 = pFontArrus->CalcTextHeight(pTmpBuf, &v65, 0, 0);
12513 result = (int)v65.DrawText2(pFontArrus, 0, (174 - v30) / 2 + 138, v29, pTmpBuf, 3u);
12514 }
12515 }
12516 }
12517 return result;
12518 }
12519 if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
12520 {
12521 v31 = _721A3C_npc_text;
12522 v32 = v71;
12523 v33 = pFontArrus->CalcTextHeight(_721A3C_npc_text, &v65, 0, 0);
12524 v65.DrawText2(pFontArrus, 0, (212 - v33) / 2 + 101, v32, v31, 3u);
12525 result = (int)pDialogueWindow;
12526 pDialogueWindow->field_28 = 0;
12527 return result;
12528 }
12529 v34 = v0->uLevel;
12530 if ( v34 < v68 )
12531 {
12532 if ( (signed __int64)v0->uExperience >= v66 )
12533 {
12534 if ( pParty->uNumGold >= i )
12535 {
12536 Party::TakeGold(i);
12537 HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, 2);
12538 ++v0->uLevel;
12539 v0->uSkillPoints += v0->uLevel / 10 + 5;
12540 v0->sHealth = v0->GetMaxHealth();
12541 v0->sMana = v0->GetMaxMana();
12542 v37 = 0;
12543 v38 = byte_F8B148;
12544 do
12545 {
12546 if ( *(int *)v38 > v37 )
12547 v37 = *(int *)v38;
12548 v38 += 4;
12549 }
12550 while ( (signed int)v38 < (signed int)word_F8B158 );
12551 v39 = &dword_F8B144 + uActiveCharacter;
12552 ++*v39;
12553 if ( *v39 > v37 )
12554 {
12555 v40 = sub_494820(pParty->uCurrentHour);
12556 v41 = ptr_507BC0->ptr_1C;
12557 v42 = 60 * (v40 + 4) - pParty->uCurrentMinute;
12558 if ( v41 == (void *)94 || v41 == (void *)95 )
12559 v42 += 720;
12560 RestAndHeal((signed int)(v42 + 10080));
12561 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
12562 pOutdoor->SetFog();
12563 }
12564 v0->PlaySound(87, 0);
12565 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[430], v0->pName, v0->uLevel, v0->uLevel / 10 + 5);//
12566 // "%s is now Level %lu and has earned %lu Skill Points!"
12567 ShowStatusBarString(pTmpBuf, 2u);
12568 goto LABEL_56;
12569 }
12570 ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);// "You don't have enough gold"
12571 v63 = 4;
12572 LABEL_55:
12573 HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, v63);
12574 LABEL_56:
12575 result = pMessageQueue_50CBD0->uNumMessages;
12576 if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
12577 {
12578 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
12579 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
12580 result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
12581 *(&pMessageQueue_50CBD0->uNumMessages + result) = 0;
12582 ++pMessageQueue_50CBD0->uNumMessages;
12583 }
12584 return result;
12585 }
12586 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[538], v5 - LODWORD(v0->uExperience), v34 + 1);//
12587 // "You need %d more experience to train to level %d"
12588 v35 = 0;
12589 v62 = 3;
12590 v60 = pTmpBuf;
12591 v58 = v71;
12592 v36 = (212 - pFontArrus->CalcTextHeight(pTmpBuf, &v65, 0, 0)) / 2 + 88;
12593 }
12594 else
12595 {
12596 sprintfex(pTmpBuf, "%s\n \n%s", pGlobalTXT_LocalizationStrings[536], pGlobalTXT_LocalizationStrings[529]);//
12597 // ""With your skills, you should be working here as a teacher.""
12598 // ""Sorry, but we are unable to train you.""
12599 v35 = 0;
12600 v62 = 3;
12601 v60 = pTmpBuf;
12602 v58 = v71;
12603 v36 = (212 - pFontArrus->CalcTextHeight(pTmpBuf, &v65, 0, 0)) / 2 + 101;
12604 }
12605 v65.DrawText2(pFontArrus, v35, v36, v58, v60, v62);
12606 v63 = 3;
12607 goto LABEL_55;
12608 }
12609 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
12610 if ( result )
12611 {
12612 v43 = pDialogueWindow;
12613 v72 = 0;
12614 pShopOptions[0] = pTmpBuf;
12615 pShopOptions[1] = pGlobalTXT_LocalizationStrings[160];// "Learn Skills"
12616 v44 = pDialogueWindow->field_28;
12617 v73 = pDialogueWindow->field_38;
12618 if ( v73 < v73 + v44 )
12619 {
12620 v45 = pShopOptions;
12621 do
12622 {
12623 if ( v43->GetControl(v73)->uControlParam == 17 )
12624 {
12625 v46 = v0->uLevel;
12626 if ( v46 < v68 )
12627 {
12628 if ( (signed __int64)v0->uExperience < v66 )
12629 {
12630 v64 = (char *)(v46 + 1);
12631 v61 = (char *)(v5 - LODWORD(v0->uExperience));
12632 v59 = pGlobalTXT_LocalizationStrings[538];// "You need %d more experience to train to level %d"
12633 }
12634 else
12635 {
12636 v64 = (char *)i;
12637 v61 = (char *)(v46 + 1);
12638 v59 = pGlobalTXT_LocalizationStrings[537];// "Train to level %d for %d gold"
12639 }
12640 }
12641 else
12642 {
12643 v64 = pGlobalTXT_LocalizationStrings[529];// ""Sorry, but we are unable to train you.""
12644 v61 = pGlobalTXT_LocalizationStrings[536];// ""With your skills, you should be working here as a teacher.""
12645 v59 = "%s\n \n%s";
12646 }
12647 sprintfex(*v45, v59, v61, v64);
12648 }
12649 v47 = pFontArrus->CalcTextHeight(*v45, &v65, 0, 0);
12650 v43 = pDialogueWindow;
12651 v72 += v47;
12652 ++v45;
12653 ++v73;
12654 }
12655 while ( v73 < pDialogueWindow->field_28 + pDialogueWindow->field_38 );
12656 }
12657 HIDWORD(v66) = (174 - v72) / 2;
12658 result = v43->field_38;
12659 v48 = result + v43->field_28;
12660 v49 = (2 * (87 - (174 - v72) / 2) - v72) / 2 - (174 - v72) / 2 / 2 + 138;
12661 v50 = -v43->field_28 < 0;
12662 v73 = v43->field_38;
12663 if ( v50 ^ __OFSUB__(result, v48) )
12664 {
12665 i = 2;
12666 v51 = pShopOptions;
12667 do
12668 {
12669 v52 = v43->GetControl(v73);
12670 v53 = v52;
12671 v52->uY = HIDWORD(v66) + v49;
12672 v54 = pFontArrus->CalcTextHeight(*v51, &v65, 0, 0);
12673 v55 = v53->uY;
12674 v53->uHeight = v54;
12675 v56 = v54 + v55 - 1;
12676 v53->uW = v56;
12677 v49 = v56;
12678 v57 = v71;
12679 if ( pDialogueWindow->field_2C_focus_id != i )
12680 v57 = white;
12681 v65.DrawText2(pFontArrus, 0, v55, v57, *v51, 3u);
12682 v43 = pDialogueWindow;
12683 ++i;
12684 ++v51;
12685 ++v73;
12686 result = pDialogueWindow->field_28 + pDialogueWindow->field_38;
12687 }
12688 while ( v73 < result );
12689 }
12690 }
12691 }
12692 return result;
12693 }
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703 //----- (004B4FCF) --------------------------------------------------------
12704 int __cdecl ui_shop_teachers()
12705 {
12706 Player *v0; // ebx@1
12707 int result; // eax@6
12708 signed int v2; // esi@8
12709 unsigned int v3; // ebx@10
12710 char *v4; // eax@11
12711 char *v5; // eax@12
12712 unsigned int v6; // eax@12
12713 int v7; // ST08_4@14
12714 int v8; // eax@14
12715 unsigned __int8 v9; // dl@14
12716 char *v10; // ecx@14
12717 signed int v11; // esi@16
12718 int v12; // ST08_4@19
12719 int v13; // eax@19
12720 int v14; // edi@21
12721 char **v15; // esi@21
12722 int v16; // eax@22
12723 GUIWindow *v17; // ecx@23
12724 int v18; // edx@23
12725 int v19; // edi@23
12726 unsigned __int8 v20; // sf@23
12727 GUIButton *v21; // esi@25
12728 const char **v22; // eax@25
12729 int v23; // eax@25
12730 unsigned int v24; // ecx@25
12731 const char **v25; // edx@25
12732 unsigned __int16 v26; // ax@25
12733 signed int v27; // esi@30
12734 int v28; // ST08_4@34
12735 int v29; // eax@34
12736 char *v30; // edx@35
12737 GUIWindow *v31; // edi@40
12738 void *v32; // eax@40
12739 signed int v33; // esi@40
12740 unsigned int v34; // esi@42
12741 int v35; // eax@42
12742 unsigned int v36; // eax@43
12743 int v37; // eax@45
12744 int v38; // ecx@50
12745 GUIButton *v39; // eax@52
12746 GUIButton *v40; // esi@52
12747 int v41; // eax@52
12748 char *v42; // eax@54
12749 int v43; // eax@54
12750 unsigned int v44; // ecx@54
12751 int v45; // edx@54
12752 int v46; // eax@54
12753 unsigned __int16 v47; // ax@54
12754 int v48; // eax@58
12755 signed int v49; // esi@62
12756 Texture *v50; // ecx@64
12757 unsigned int v51; // edi@64
12758 unsigned int v52; // esi@66
12759 int v53; // edx@70
12760 Texture *v54; // ecx@76
12761 unsigned int v55; // edi@76
12762 unsigned int v56; // esi@76
12763 int v57; // edx@80
12764 Texture *v58; // ecx@86
12765 unsigned int v59; // edi@86
12766 unsigned int v60; // esi@88
12767 int v61; // edx@92
12768 Texture *v62; // ecx@98
12769 unsigned int v63; // edi@98
12770 unsigned int v64; // esi@100
12771 int v65; // edx@104
12772 signed int v66; // ecx@109
12773 SHORT v67; // di@117
12774 bool v68; // eax@117
12775 const char *v69; // ecx@119
12776 POINT *v70; // esi@124
12777 int v71; // ecx@125
12778 int v72; // eax@125
12779 int v73; // ecx@125
12780 ItemGen *v74; // esi@125
12781 int v75; // eax@130
12782 int v76; // esi@131
12783 char **v77; // edi@131
12784 int v78; // eax@132
12785 GUIWindow *v79; // ecx@133
12786 int v80; // edx@133
12787 int v81; // edi@133
12788 GUIButton *v82; // esi@135
12789 const char **v83; // eax@135
12790 int v84; // eax@135
12791 unsigned int v85; // ecx@135
12792 int v86; // edx@135
12793 unsigned __int16 v87; // ax@135
12794 GUIWindow *v88; // [sp-18h] [bp-110h]@35
12795 int v89; // [sp-14h] [bp-10Ch]@35
12796 ItemGen *v90; // [sp-10h] [bp-108h]@14
12797 int v91; // [sp-10h] [bp-108h]@35
12798 unsigned __int16 v92; // [sp-Ch] [bp-104h]@12
12799 void *v93; // [sp-Ch] [bp-104h]@14
12800 int v94; // [sp-8h] [bp-100h]@11
12801 char *v95; // [sp-8h] [bp-100h]@12
12802 __int64 *v96; // [sp-4h] [bp-FCh]@11
12803 unsigned int v97; // [sp-4h] [bp-FCh]@12
12804 POINT v98; // [sp+Ch] [bp-ECh]@8
12805 POINT v99; // [sp+14h] [bp-E4h]@16
12806 POINT v100; // [sp+1Ch] [bp-DCh]@124
12807 POINT v101; // [sp+24h] [bp-D4h]@17
12808 POINT v102; // [sp+2Ch] [bp-CCh]@124
12809 POINT v103; // [sp+34h] [bp-C4h]@9
12810 POINT v104; // [sp+3Ch] [bp-BCh]@31
12811 POINT v105; // [sp+44h] [bp-B4h]@16
12812 POINT v106; // [sp+4Ch] [bp-ACh]@30
12813 POINT v107; // [sp+54h] [bp-A4h]@16
12814 POINT v108; // [sp+5Ch] [bp-9Ch]@30
12815 POINT a2; // [sp+64h] [bp-94h]@8
12816 POINT v110; // [sp+6Ch] [bp-8Ch]@30
12817 POINT v111; // [sp+74h] [bp-84h]@8
12818 GUIWindow v112; // [sp+7Ch] [bp-7Ch]@1
12819 char *Str; // [sp+D0h] [bp-28h]@54
12820 int v114; // [sp+D4h] [bp-24h]@23
12821 unsigned int color2; // [sp+D8h] [bp-20h]@1
12822 unsigned int white; // [sp+DCh] [bp-1Ch]@1
12823 __int32 v117; // [sp+E0h] [bp-18h]@8
12824 int v118; // [sp+E4h] [bp-14h]@40
12825 const char **v119; // [sp+E8h] [bp-10h]@24
12826 Player *_this; // [sp+ECh] [bp-Ch]@1
12827 unsigned __int8 uPlayerID; // [sp+F3h] [bp-5h]@14
12828 int v122; // [sp+F4h] [bp-4h]@23
12829
12830 v0 = pPlayers[uActiveCharacter];
12831 _this = pPlayers[uActiveCharacter];
12832 memcpy(&v112, ptr_507BC0, sizeof(v112));
12833 v112.uFrameX = 483;
12834 v112.uFrameWidth = 148;
12835 v112.uFrameZ = 334;
12836 white = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
12837 color2 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xE1u, 0xCDu, 0x23u);
12838 if ( dword_F8B19C > 5 )
12839 {
12840 if ( dword_F8B19C == 94 )
12841 {
12842 draw_leather();
12843 CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
12844 pShopOptions[0] = pGlobalTXT_LocalizationStrings[200];// "Sell"
12845 pShopOptions[1] = pGlobalTXT_LocalizationStrings[113];// "Identify"
12846 pShopOptions[2] = pGlobalTXT_LocalizationStrings[179];// "Repair"
12847 v76 = 0;
12848 v77 = pShopOptions;
12849 do
12850 {
12851 v78 = pFontArrus->CalcTextHeight(*v77, &v112, 0, 0);
12852 ++v77;
12853 v76 += v78;
12854 }
12855 while ( (signed int)v77 < (signed int)&pShopOptions[3] );
12856 v79 = pDialogueWindow;
12857 _this = (Player *)((174 - v76) / 3);
12858 result = pDialogueWindow->field_38;
12859 v80 = result + pDialogueWindow->field_28;
12860 v81 = (3 * (58 - (signed int)_this) - v76) / 2 - (174 - v76) / 3 / 2 + 138;
12861 v20 = -pDialogueWindow->field_28 < 0;
12862 v118 = pDialogueWindow->field_38;
12863 if ( v20 ^ __OFSUB__(result, v80) )
12864 {
12865 v122 = 2;
12866 v119 = (const char **)pShopOptions;
12867 do
12868 {
12869 v82 = v79->GetControl(v118);
12870 v83 = v119;
12871 v82->uY = (unsigned int)((char *)_this + v81);
12872 v84 = pFontArrus->CalcTextHeight(*v83, &v112, 0, 0);
12873 v85 = v82->uY;
12874 v86 = v122;
12875 v82->uHeight = v84;
12876 v81 = v84 + v85 - 1;
12877 v82->uW = v81;
12878 v87 = color2;
12879 if ( pDialogueWindow->field_2C_focus_id != v86 )
12880 v87 = white;
12881 v112.DrawText2(pFontArrus, 0, v85, v87, *v119, 3u);
12882 v79 = pDialogueWindow;
12883 ++v122;
12884 ++v119;
12885 ++v118;
12886 result = pDialogueWindow->field_28 + pDialogueWindow->field_38;
12887 }
12888 while ( v118 < result );
12889 }
12890 return result;
12891 }
12892 if ( dword_F8B19C != 95 )
12893 {
12894 result = dword_F8B19C - 96;
12895 if ( dword_F8B19C == 96 )
12896 {
12897 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
12898 if ( result )
12899 {
12900 v31 = pDialogueWindow;
12901 v3 = 0;
12902 v32 = ptr_507BC0->ptr_1C;
12903 v118 = 0;
12904 //v33 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (signed int)v32] * 500.0);
12905 v33 = (signed __int64)(p2DEvents[(signed int)v32 - 1].flt_24 * 500.0);
12906 v119 = (const char **)(v33 * (100 - _this->GetMerchant()) / 100);
12907 if ( (signed int)v119 < v33 / 3 )
12908 v119 = (const char **)(v33 / 3);
12909 v34 = v31->field_38;
12910 v35 = v34 + v31->field_28;
12911 v122 = 0;
12912 if ( (signed int)v34 >= v35 )
12913 goto LABEL_140;
12914 do
12915 {
12916 v36 = v31->GetControl(v34)->uControlParam - 36;
12917 if ( byte_4ED970_skill_learn_ability_by_class_table[_this->uClass][v36] && !_this->pActiveSkills[v36] )
12918 {
12919 v37 = pFontArrus->CalcTextHeight(pSkillNames[v36], &v112, 0, 0);
12920 v118 += v37;
12921 ++v122;
12922 }
12923 ++v34;
12924 }
12925 while ( (signed int)v34 < v31->field_28 + v31->field_38 );
12926 if ( !v122 )
12927 {
12928 LABEL_140:
12929 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[544], _this->pName, pClassNames[_this->uClass]);//
12930 // "Seek knowledge elsewhere %s the %s"
12931 strcat(pTmpBuf, "\n \n");
12932 strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);// "I can offer you nothing further."
12933 v30 = pTmpBuf;
12934 v97 = 3;
12935 v95 = pTmpBuf;
12936 v92 = color2;
12937 v91 = 0;
12938 v89 = 0;
12939 v88 = &v112;
12940 goto LABEL_61;
12941 }
12942 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[401], v119);// "Skill Cost: %lu"
12943 v112.DrawText2(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
12944 v119 = (const char **)((149 - v118) / v122);
12945 if ( (149 - v118) / v122 > 32 )
12946 v119 = (const char **)32;
12947 result = v31->field_38;
12948 v38 = (149 - v122 * (signed int)v119 - v118) / 2 - (signed int)v119 / 2 + 162;
12949 v118 = result;
12950 v114 = v38;
12951 if ( result < result + v31->field_28 )
12952 {
12953 v122 = 2;
12954 do
12955 {
12956 v39 = v31->GetControl(v118);
12957 v40 = v39;
12958 v41 = v39->uControlParam - 36;
12959 if ( !byte_4ED970_skill_learn_ability_by_class_table[_this->uClass][v41] || _this->pActiveSkills[v41] )
12960 {
12961 v40->uW = 0;
12962 v40->uHeight = 0;
12963 v40->uY = 0;
12964 }
12965 else
12966 {
12967 v42 = pSkillNames[v41];
12968 v40->uY = (unsigned int)((char *)v119 + v114);
12969 Str = v42;
12970 v43 = pFontArrus->CalcTextHeight(v42, &v112, 0, 0);
12971 v44 = v40->uY;
12972 v45 = v122;
12973 v40->uHeight = v43;
12974 v46 = v44 + v43 - 1;
12975 v40->uW = v46;
12976 v114 = v46;
12977 v47 = color2;
12978 if ( pDialogueWindow->field_2C_focus_id != v45 )
12979 v47 = white;
12980 v112.DrawText2(pFontArrus, 0, v44, v47, Str, 3u);
12981 }
12982 v48 = v31->field_38;
12983 ++v118;
12984 result = v31->field_28 + v48;
12985 ++v122;
12986 }
12987 while ( v118 < result );
12988 }
12989 }
12990 }
12991 return result;
12992 }
12993 }
12994 else
12995 {
12996 if ( dword_F8B19C == 5 )
12997 {
12998 draw_leather();
12999 CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
13000 sub_4B46A5(pGlobalTXT_LocalizationStrings[198], 0);// "Select the Item to Repair"
13001 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
13002 if ( !result
13003 || (v27 = pMouse->GetCursorPos(&v110)->x - 14,
13004 v117 = (v27 >> 5) + 14 * ((pMouse->GetCursorPos(&v108)->y - 17) >> 5),
13005 result = (int)pMouse->GetCursorPos(&v106),
13006 *(int *)result <= 13)
13007 || (result = (int)pMouse->GetCursorPos(&v104), *(int *)result >= 462)
13008 || (result = v0->GetItemIDAtInventoryIndex((int *)&v117), v3 = 0, !result)
13009 || (result *= 9, !(_this->field_1F5[4 * result + 15] & 2)) )
13010 return result;
13011 v96 = 0;
13012 v94 = 5;
13013 v93 = ptr_507BC0->ptr_1C;
13014 v90 = (ItemGen *)&_this->pDarkSpellbook.bIsSpellAvailable[4 * result + 5];
13015 v28 = (int)ptr_507BC0->ptr_1C;
13016 uPlayerID = uActiveCharacter - 1;
13017 v29 = _this->_490EEE((ItemGen *)&_this->pDarkSpellbook.bIsSpellAvailable[4 * result + 5], 3, v28, 5);
13018 v9 = uPlayerID;
13019 v10 = (char *)pMerchantsRepairPhrases[v29];
13020 goto LABEL_35;
13021 }
13022 if ( dword_F8B19C == 1 )
13023 {
13024 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
13025 if ( result )
13026 {
13027 pShopOptions[0] = pGlobalTXT_LocalizationStrings[134];// "Buy Standard"
13028 pShopOptions[1] = pGlobalTXT_LocalizationStrings[152];// "Buy Special"
13029 pShopOptions[2] = pGlobalTXT_LocalizationStrings[159];// "Display Inventory"
13030 v14 = 0;
13031 pShopOptions[3] = pGlobalTXT_LocalizationStrings[160];// "Learn Skills"
13032 v15 = pShopOptions;
13033 do
13034 {
13035 v16 = pFontArrus->CalcTextHeight(*v15, &v112, 0, 0);
13036 ++v15;
13037 v14 += v16;
13038 }
13039 while ( (signed int)v15 < (signed int)&unk_F8B1C8 );
13040 v17 = pDialogueWindow;
13041 v114 = (174 - v14) / 4;
13042 result = pDialogueWindow->field_38;
13043 v18 = result + pDialogueWindow->field_28;
13044 v19 = (174 - 4 * (174 - v14) / 4 - v14) / 2 - (174 - v14) / 4 / 2 + 138;
13045 v20 = -pDialogueWindow->field_28 < 0;
13046 v122 = pDialogueWindow->field_38;
13047 if ( v20 ^ __OFSUB__(result, v18) )
13048 {
13049 v119 = (const char **)2;
13050 _this = (Player *)pShopOptions;
13051 do
13052 {
13053 v21 = v17->GetControl(v122);
13054 v22 = (const char **)_this;
13055 v21->uY = v114 + v19;
13056 v23 = pFontArrus->CalcTextHeight(*v22, &v112, 0, 0);
13057 v24 = v21->uY;
13058 v25 = v119;
13059 v21->uHeight = v23;
13060 v19 = v24 + v23 - 1;
13061 v21->uW = v19;
13062 v26 = color2;
13063 if ( (const char **)pDialogueWindow->field_2C_focus_id != v25 )
13064 v26 = white;
13065 v112.DrawText2(pFontArrus, 0, v24, v26, (const char *)LODWORD(_this->pConditions[0]), 3u);
13066 v17 = pDialogueWindow;
13067 v119 = (const char **)((char *)v119 + 1);
13068 _this = (Player *)((char *)_this + 4);
13069 ++v122;
13070 result = pDialogueWindow->field_28 + pDialogueWindow->field_38;
13071 }
13072 while ( v122 < result );
13073 }
13074 }
13075 return result;
13076 }
13077 if ( dword_F8B19C != 2 )
13078 {
13079 if ( dword_F8B19C != 3 )
13080 {
13081 result = dword_F8B19C - 4;
13082 if ( dword_F8B19C == 4 )
13083 {
13084 draw_leather();
13085 CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
13086 sub_4B46A5(pGlobalTXT_LocalizationStrings[197], 0);// "Select the Item to Identify"
13087 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
13088 if ( result )
13089 {
13090 v2 = pMouse->GetCursorPos(&a2)->x - 14;
13091 v117 = (v2 >> 5) + 14 * ((pMouse->GetCursorPos(&v98)->y - 17) >> 5);
13092 result = (int)pMouse->GetCursorPos(&v111);
13093 if ( *(int *)result > 13 )
13094 {
13095 result = (int)pMouse->GetCursorPos(&v103);
13096 if ( *(int *)result < 462 )
13097 {
13098 result = v0->GetItemIDAtInventoryIndex((int *)&v117);
13099 v3 = 0;
13100 if ( result )
13101 {
13102 v96 = 0;
13103 v94 = 4;
13104 v4 = &_this->pDarkSpellbook.bIsSpellAvailable[36 * result + 5];
13105 if ( v4[20] & 1 )
13106 {
13107 v5 = sub_495461("%24", uActiveCharacter - 1, (ItemGen *)v4, (char *)ptr_507BC0->ptr_1C, 4, 0);
13108 v97 = 3;
13109 v95 = v5;
13110 v92 = white;
13111 v6 = (212 - pFontArrus->CalcTextHeight(v5, &v112, 0, 0)) / 2 + 101;
13112 return (int)v112.DrawText2(pFontArrus, v3, v6, v92, v95, v97);
13113 }
13114 v93 = ptr_507BC0->ptr_1C;
13115 v90 = (ItemGen *)v4;
13116 v7 = (int)ptr_507BC0->ptr_1C;
13117 uPlayerID = uActiveCharacter - 1;
13118 v8 = ((Player *)_this)->_490EEE((ItemGen *)v4, 3, v7, 4);
13119 v9 = uPlayerID;
13120 v10 = (char *)pMerchantsIdentifyPhrases[v8];
13121 goto LABEL_35;
13122 }
13123 }
13124 }
13125 }
13126 }
13127 return result;
13128 }
13129 draw_leather();
13130 CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
13131 sub_4B46A5(pGlobalTXT_LocalizationStrings[199], 0);// "Select the Item to Sell"
13132 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
13133 if ( !result
13134 || (v11 = pMouse->GetCursorPos(&v107)->x - 14,
13135 v117 = (v11 >> 5) + 14 * ((pMouse->GetCursorPos(&v99)->y - 17) >> 5),
13136 result = (int)pMouse->GetCursorPos(&v105),
13137 *(int *)result <= 13)
13138 || (result = (int)pMouse->GetCursorPos(&v101), *(int *)result >= 462)
13139 || (result = v0->GetItemIDAtInventoryIndex((int *)&v117), v3 = 0, !result) )
13140 return result;
13141 v96 = 0;
13142 v94 = 3;
13143 v93 = ptr_507BC0->ptr_1C;
13144 v90 = (ItemGen *)&_this->pDarkSpellbook.bIsSpellAvailable[36 * result + 5];
13145 v12 = (int)ptr_507BC0->ptr_1C;
13146 uPlayerID = uActiveCharacter - 1;
13147 v13 = _this->_490EEE(v90, 3, v12, 3);
13148 v9 = uPlayerID;
13149 v10 = (char *)pMerchantsSellPhrases[v13];
13150 LABEL_35:
13151 v30 = sub_495461(v10, v9, v90, (char *)v93, v94, v96);
13152 v97 = 3;
13153 v95 = v30;
13154 v92 = white;
13155 v91 = v3;
13156 v89 = v3;
13157 v88 = &v112;
13158 LABEL_61:
13159 v6 = (174 - pFontArrus->CalcTextHeight(v30, v88, v89, v91)) / 2 + 138;
13160 return (int)v112.DrawText2(pFontArrus, v3, v6, v92, v95, v97);
13161 }
13162 }
13163 pRenderer->DrawTextureIndexed(8u, 8u, dword_F8B164);
13164 v3 = 0;
13165 v49 = 0;
13166 v122 = 0;
13167 if ( dword_F8B19C == 2 )
13168 {
13169 do
13170 {
13171 if ( pParty->field_777C[9 * (v49 + 12 * (unsigned int)ptr_507BC0->ptr_1C)] )
13172 {
13173 v50 = dword_F8B168[v49];
13174 v51 = 152 - v50->uTextureHeight;
13175 if ( (signed int)v51 < 1 )
13176 v51 = 0;
13177 v52 = 75 * v49 - v50->uTextureWidth / 2 + 40;
13178 if ( v122 )
13179 {
13180 if ( v122 == 5 )
13181 {
13182 v53 = dword_F8B168[5]->uTextureWidth;
13183 if ( (signed int)v52 > 457 - v53 )
13184 v52 = 457 - v53;
13185 }
13186 }
13187 else
13188 {
13189 if ( (signed int)v52 < 18 )
13190 v52 = 18;
13191 }
13192 pRenderer->DrawTextureTransparent(v52, v51, v50);
13193 sub_40F92A(&pRenderer->pActiveZBuffer[v52 + 640 * v51], dword_F8B168[v122], v122 + 1);
13194 v49 = v122;
13195 }
13196 ++v49;
13197 v122 = v49;
13198 }
13199 while ( v49 < 6 );
13200 v122 = 0;
13201 do
13202 {
13203 if ( pParty->field_777C[9 * (v122 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 54] )
13204 {
13205 v54 = dword_F8B168[v122 + 6];
13206 v55 = 306 - v54->uTextureHeight;
13207 v56 = 75 * v122 - v54->uTextureWidth / 2 + 40;
13208 if ( v122 )
13209 {
13210 if ( v122 == 5 )
13211 {
13212 v57 = dword_F8B168[11]->uTextureWidth;
13213 if ( (signed int)v56 > 457 - v57 )
13214 v56 = 457 - v57;
13215 }
13216 }
13217 else
13218 {
13219 if ( (signed int)v56 < 18 )
13220 v56 = 18;
13221 }
13222 pRenderer->DrawTextureTransparent(v56, v55, v54);
13223 sub_40F92A(&pRenderer->pActiveZBuffer[v56 + 640 * v55], dword_F8B168[v122 + 6], v122 + 7);
13224 }
13225 ++v122;
13226 }
13227 while ( v122 < 6 );
13228 }
13229 else
13230 {
13231 do
13232 {
13233 if ( pParty->field_C59C[9 * (v49 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 724] )
13234 {
13235 v58 = dword_F8B168[v49];
13236 v59 = 152 - v58->uTextureHeight;
13237 if ( (signed int)v59 < 1 )
13238 v59 = 0;
13239 v60 = 75 * v49 - v58->uTextureWidth / 2 + 40;
13240 if ( v122 )
13241 {
13242 if ( v122 == 5 )
13243 {
13244 v61 = dword_F8B168[5]->uTextureWidth;
13245 if ( (signed int)v60 > 457 - v61 )
13246 v60 = 457 - v61;
13247 }
13248 }
13249 else
13250 {
13251 if ( (signed int)v60 < 18 )
13252 v60 = 18;
13253 }
13254 pRenderer->DrawTextureTransparent(v60, v59, v58);
13255 sub_40F92A(&pRenderer->pActiveZBuffer[v60 + 640 * v59], dword_F8B168[v122], v122 + 1);
13256 v49 = v122;
13257 }
13258 ++v49;
13259 v122 = v49;
13260 }
13261 while ( v49 < 6 );
13262 v122 = 0;
13263 do
13264 {
13265 if ( pParty->field_C59C[9 * (v122 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 778] )
13266 {
13267 v62 = dword_F8B168[v122 + 6];
13268 v63 = 306 - v62->uTextureHeight;
13269 if ( (signed int)v63 < 1 )
13270 v63 = 0;
13271 v64 = 75 * v122 - v62->uTextureWidth / 2 + 40;
13272 if ( v122 )
13273 {
13274 if ( v122 == 5 )
13275 {
13276 v65 = dword_F8B168[11]->uTextureWidth;
13277 if ( (signed int)v64 > 457 - v65 )
13278 v64 = 457 - v65;
13279 }
13280 }
13281 else
13282 {
13283 if ( (signed int)v64 < 18 )
13284 v64 = 18;
13285 }
13286 pRenderer->DrawTextureTransparent(v64, v63, v62);
13287 sub_40F92A(&pRenderer->pActiveZBuffer[v64 + 640 * v63], dword_F8B168[v122 + 6], v122 + 7);
13288 }
13289 ++v122;
13290 }
13291 while ( v122 < 6 );
13292 }
13293 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
13294 if ( result )
13295 {
13296 v66 = 0;
13297 v117 = 0;
13298 if ( dword_F8B19C == 2 )
13299 {
13300 do
13301 {
13302 if ( pParty->field_777C[9 * (v66 + 12 * (unsigned int)ptr_507BC0->ptr_1C)] )
13303 ++v117;
13304 ++v66;
13305 }
13306 while ( v66 < 12 );
13307 }
13308 else
13309 {
13310 do
13311 {
13312 if ( pParty->field_C59C[9 * (v66 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 724] )
13313 ++v117;
13314 ++v66;
13315 }
13316 while ( v66 < 12 );
13317 }
13318 v67 = GetAsyncKeyState(VK_CONTROL);
13319 v68 = _this->CanSteal();
13320 Str = (char *)v68;
13321 if ( v67 && v68 )
13322 {
13323 v69 = pGlobalTXT_LocalizationStrings[185];// "Steal item"
13324 }
13325 else
13326 {
13327 v69 = pGlobalTXT_LocalizationStrings[195];// "Select the Item to Buy"
13328 if ( dword_F8B19C != 2 )
13329 v69 = pGlobalTXT_LocalizationStrings[196];// "Select the Special Item to Buy"
13330 }
13331 sub_4B46A5(v69, 0);
13332 if ( !v117 )
13333 return (int)v112._4B1854(
13334 __PAIR__(
13335 pParty->field_3C.field_50[2 * (unsigned int)ptr_507BC0->ptr_1C + 1],
13336 pParty->field_3C.field_50[2 * (unsigned int)ptr_507BC0->ptr_1C])
13337 - pParty->uTimePlayed);
13338 v70 = pMouse->GetCursorPos(&v102);
13339 result = v70->x + pSRZBufferLineOffsets[pMouse->GetCursorPos(&v100)->y];
13340 if ( pRenderer->pActiveZBuffer[result] & 0xFFFF )
13341 {
13342 v71 = (pRenderer->pActiveZBuffer[result] & 0xFFFF) - 1;
13343 v117 = v71;
13344 v72 = (int)ptr_507BC0->ptr_1C;
13345 v73 = 9 * (v71 + 12 * v72);
13346 v74 = (ItemGen *)&pParty->field_777C[v73];
13347 if ( dword_F8B19C != 2 )
13348 v74 = (ItemGen *)&pParty->field_C59C[v73 + 724];
13349 if ( v67 && Str )
13350 {
13351 v10 = pGlobalTXT_LocalizationStrings[181];// "Steal %24"
13352 v96 = 0;
13353 v94 = 2;
13354 v93 = ptr_507BC0->ptr_1C;
13355 v90 = v74;
13356 v9 = uActiveCharacter - 1;
13357 }
13358 else
13359 {
13360 v96 = 0;
13361 v94 = 2;
13362 v93 = ptr_507BC0->ptr_1C;
13363 v90 = v74;
13364 uPlayerID = uActiveCharacter - 1;
13365 v75 = _this->_490EEE(v74, 3, v72, 2);
13366 v9 = uPlayerID;
13367 v10 = (char *)pMerchantsBuyPhrases[v75];
13368 }
13369 goto LABEL_35;
13370 }
13371 }
13372 return result;
13373 }
13374
13375 //----- (004BC49B) --------------------------------------------------------
13376 void __thiscall sub_4BC49B(unsigned int _this)
13377 {
13378 unsigned int v1; // esi@1
13379 NPCData *v2; // ebp@1
13380 unsigned int v3; // eax@1
13381 int v4; // ecx@10
13382 signed int v5; // edi@14
13383 char *v6; // esi@15
13384 const char *v7; // ecx@22
13385 signed int v8; // edi@37
13386 unsigned int v9; // eax@56
13387 unsigned int v10; // ecx@57
13388 void *v11; // [sp-Ch] [bp-1Ch]@46
13389 int v12; // [sp-8h] [bp-18h]@46
13390 char *v13; // [sp-8h] [bp-18h]@60
13391 size_t v14; // [sp-4h] [bp-14h]@46
13392 const char *v15; // [sp-4h] [bp-14h]@60
13393
13394 v1 = _this;
13395 v2 = GetNPCData(uDialogue_SpeakingActorNPC_ID);
13396 v3 = v1;
13397 uDialogueType = v1;
13398 if ( !v2->uFlags )
13399 {
13400 v2->uFlags = 1;
13401 v3 = uDialogueType;
13402 }
13403 if ( (signed int)v3 > 22 )
13404 {
13405 if ( v3 == 23 )
13406 {
13407 v4 = v2->evte;
13408 goto LABEL_74;
13409 }
13410 if ( v3 == 24 )
13411 {
13412 v4 = v2->evtf;
13413 goto LABEL_74;
13414 }
13415 if ( v3 != 76 )
13416 {
13417 if ( v3 == 77 )
13418 {
13419 byte_F8B1EC ^= 1u;
13420 }
13421 else
13422 {
13423 if ( (signed int)v3 > 84 && (signed int)v3 <= 88 )
13424 {
13425 ArenaFight();
13426 return;
13427 }
13428 }
13429 goto LABEL_87;
13430 }
13431 if ( v2->uFlags & 0x80 )
13432 {
13433 v8 = 0;
13434 if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
13435 {
13436 v6 = (char *)pNPCStats->pNewNPCData;
13437 while ( !(v6[8] & 0x80) || strcmp(v2->pName, *(const char **)v6) )
13438 {
13439 ++v8;
13440 v6 += 76;
13441 if ( v8 >= (signed int)pNPCStats->uNumNewNPCs )
13442 goto LABEL_44;
13443 }
13444 goto LABEL_43;
13445 }
13446 LABEL_44:
13447 if ( !pParty->pHirelings[0].pName || _strcmpi(pParty->pHirelings[0].pName, v2->pName) )
13448 {
13449 if ( !pParty->pHirelings[1].pName || _strcmpi(pParty->pHirelings[1].pName, v2->pName) )
13450 {
13451 LABEL_51:
13452 pParty->field_709 = 0;
13453 sub_44A56A();
13454 dword_591084 = 0;
13455 if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
13456 {
13457 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
13458 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
13459 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
13460 ++pMessageQueue_50CBD0->uNumMessages;
13461 }
13462 goto LABEL_89;
13463 }
13464 v14 = 76;
13465 v12 = 0;
13466 v11 = &pParty->pHirelings[1];
13467 }
13468 else
13469 {
13470 v14 = 76;
13471 v12 = 0;
13472 v11 = pParty->pHirelings;
13473 }
13474 memset(v11, v12, v14);
13475 goto LABEL_51;
13476 }
13477 if ( pParty->pHirelings[0].pName && pParty->pHirelings[1].pName )
13478 {
13479 v7 = pGlobalTXT_LocalizationStrings[533]; // ""I cannot join you, you're party is full""
13480 LABEL_64:
13481 ShowStatusBarString(v7, 2u);
13482 goto LABEL_87;
13483 }
13484 v9 = v2->uProfession;
13485 if ( v9 != 51 )
13486 {
13487 v10 = *(&pNPCStats->field_13A58 + 5 * v9);
13488 if ( pParty->uNumGold < v10 )
13489 {
13490 ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);// "You don't have enough gold"
13491 byte_F8B1EC = 0;
13492 uDialogueType = 13;
13493 if ( uActiveCharacter )
13494 pPlayers[uActiveCharacter]->PlaySound(38, 0);
13495 v7 = pGlobalTXT_LocalizationStrings[155];
13496 goto LABEL_64;
13497 }
13498 Party::TakeGold(v10);
13499 }
13500 LOBYTE(v2->uFlags) |= 0x80u;
13501 if ( pParty->pHirelings[0].pName )
13502 {
13503 memcpy(&pParty->pHirelings[1], v2, sizeof(pParty->pHirelings[1]));
13504 v15 = v2->pName;
13505 v13 = pParty->pHireling2Name;
13506 }
13507 else
13508 {
13509 memcpy(pParty->pHirelings, v2, 0x4Cu);
13510 v15 = v2->pName;
13511 v13 = pParty->pHireling1Name;
13512 }
13513 strcpy(v13, v15);
13514 pParty->field_709 = 0;
13515 sub_44A56A();
13516 if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
13517 {
13518 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
13519 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
13520 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
13521 ++pMessageQueue_50CBD0->uNumMessages;
13522 }
13523 if ( (uDialogue_SpeakingActorNPC_ID & 0x80000000u) == 0 )
13524 pDialogue_SpeakingActor->uAIState = 11;
13525 if ( uActiveCharacter )
13526 pPlayers[uActiveCharacter]->PlaySound(61, 0);
13527 goto LABEL_87;
13528 }
13529 if ( v3 == 22 )
13530 {
13531 v4 = v2->evtd;
13532 goto LABEL_74;
13533 }
13534 if ( v3 == 9 )
13535 {
13536 if ( !sub_4BB756(v2->uProfession) )
13537 {
13538 if ( v2->uProfession != 41 )
13539 v2->bHasUsedTheAbility = 1;
13540 if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
13541 {
13542 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
13543 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
13544 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
13545 ++pMessageQueue_50CBD0->uNumMessages;
13546 }
13547 goto LABEL_87;
13548 }
13549 v7 = pGlobalTXT_LocalizationStrings[140];
13550 goto LABEL_64;
13551 }
13552 if ( v3 == 13 )
13553 {
13554 if ( !(v2->uFlags & 0x80) )
13555 {
13556 sub_4B3E1E();
13557 byte_F8B1EC = 0;
13558 goto LABEL_87;
13559 }
13560 v5 = 0;
13561 if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
13562 {
13563 v6 = (char *)pNPCStats->pNewNPCData;
13564 while ( !(v6[8] & 0x80) || strcmp(v2->pName, *(const char **)v6) )
13565 {
13566 ++v5;
13567 v6 += 76;
13568 if ( v5 >= (signed int)pNPCStats->uNumNewNPCs )
13569 goto LABEL_44;
13570 }
13571 LABEL_43:
13572 v6[8] &= 0x7Fu;
13573 goto LABEL_44;
13574 }
13575 goto LABEL_44;
13576 }
13577 if ( v3 == 19 )
13578 {
13579 v4 = v2->bDrawSomeAnim;
13580 goto LABEL_74;
13581 }
13582 if ( v3 == 20 )
13583 {
13584 v4 = v2->evtb;
13585 goto LABEL_74;
13586 }
13587 if ( v3 == 21 )
13588 {
13589 v4 = v2->evtc;
13590 LABEL_74:
13591 if ( v4 < 200 || v4 > 310 )
13592 {
13593 if ( v4 < 400 || v4 > 410 )
13594 {
13595 switch ( v4 )
13596 {
13597 case 139:
13598 sub_4B1ECE();
13599 break;
13600 case 311:
13601 sub_4BBA85_bounties();
13602 break;
13603 case 399:
13604 sub_4BBCDD();
13605 break;
13606 default:
13607 _5C3420_pDecoration = (LevelDecoration *)1;
13608 ptr_F8B1E8 = 0;
13609 EventProcessor(v4, 0, 1);
13610 _5C3420_pDecoration = 0;
13611 break;
13612 }
13613 }
13614 else
13615 {
13616 dword_F8B1D8 = v3;
13617 sub_4B3EF0(v4 - 400);
13618 }
13619 }
13620 else
13621 {
13622 sub_4B3FE5(v4);
13623 }
13624 }
13625 LABEL_87:
13626 if ( !dword_7241C8 )
13627 pGame->Draw();
13628 LABEL_89:
13629 dword_7241C8 = 0;
13630 }
13631
13632
13633
13634 //----- (004BDAAF) --------------------------------------------------------
13635 bool __fastcall sub_4BDAAF(ItemGen *a1, int _2da_idx)
13636 {
13637 int v2; // edx@1
13638 unsigned int v3; // esi@1
13639 unsigned int v4; // eax@1
13640 signed int v5; // edi@1
13641 int v6; // edx@8
13642 int v7; // edx@9
13643 int v8; // edx@10
13644 unsigned __int8 v9; // zf@16
13645 char v10; // sf@16
13646 unsigned __int8 v11; // of@16
13647
13648 auto a2 = _2da_idx;
13649 //v2 = p2DEvents_minus1___00[26 * a2];
13650 v2 = p2DEvents[a2 - 1].uType;
13651 v3 = a1->uItemID;
13652 v4 = a1->uItemID;
13653 v5 = pItemsTable->pItems[v4].uEquipType;
13654 if ( (v2 != 4 || (signed int)v3 < 740 || (signed int)v3 > 771)
13655 && ((signed int)v3 >= 600 || (signed int)v3 >= 529 && (signed int)v3 <= 599)
13656 || BYTE1(a1->uAttributtes) & 1 )
13657 return 0;
13658 v6 = v2 - 1;
13659 if ( !v6 )
13660 {
13661 v11 = __OFSUB__(v5, 2);
13662 v9 = v5 == 2;
13663 v10 = v5 - 2 < 0;
13664 goto LABEL_23;
13665 }
13666 v7 = v6 - 1;
13667 if ( v7 )
13668 {
13669 v8 = v7 - 1;
13670 if ( !v8 )
13671 {
13672 if ( pItemsTable->pItems[v4].uSkillType != 38 )
13673 return v5 == 16;
13674 return 1;
13675 }
13676 if ( v8 != 1 || v5 < 13 )
13677 return 0;
13678 if ( v5 <= 14 )
13679 return 1;
13680 if ( v5 != 17 || (signed int)v3 < 740 )
13681 return 0;
13682 v11 = __OFSUB__(v3, 771);
13683 v9 = v3 == 771;
13684 v10 = ((v3 - 771) & 0x80000000u) != 0;
13685 LABEL_23:
13686 if ( !((unsigned __int8)(v10 ^ v11) | v9) )
13687 return 0;
13688 return 1;
13689 }
13690 if ( v5 >= 3 )
13691 {
13692 v11 = __OFSUB__(v5, 9);
13693 v9 = v5 == 9;
13694 v10 = v5 - 9 < 0;
13695 goto LABEL_23;
13696 }
13697 return 0;
13698 }
13699
13700
13701
13702 //----- (004B5D7C) --------------------------------------------------------
13703 int __cdecl sub_4B5D7C()
13704 {
13705 GUIWindow *v0; // ebx@1
13706 Player *v1; // edi@1
13707 signed int v2; // ebx@1
13708 int v3; // edi@6
13709 int result; // eax@11
13710 unsigned int v5; // ebx@13
13711 int v6; // esi@13
13712 signed int v7; // esi@17
13713 int v8; // esi@22
13714 signed int v9; // ecx@22
13715 char *v10; // eax@22
13716 const char *v11; // ecx@26
13717 POINT *v12; // esi@30
13718 int v13; // ecx@30
13719 void *v14; // ST1C_4@31
13720 ItemGen *v15; // ST18_4@31
13721 int v16; // ST10_4@31
13722 int v17; // eax@31
13723 char *v18; // edx@31
13724 int v19; // eax@32
13725 GUIWindow *v20; // edi@35
13726 int v21; // esi@35
13727 int v22; // eax@35
13728 unsigned int v23; // eax@36
13729 int v24; // eax@39
13730 int v25; // eax@40
13731 int v26; // ecx@47
13732 GUIButton *v27; // eax@49
13733 GUIButton *v28; // esi@49
13734 unsigned int v29; // eax@49
13735 char *v30; // eax@52
13736 int v31; // eax@55
13737 unsigned int v32; // ecx@55
13738 int v33; // eax@55
13739 unsigned __int16 v34; // ax@55
13740 int v35; // eax@58
13741 const char *v36; // ST20_4@61
13742 unsigned __int16 v37; // ST1C_2@61
13743 int v38; // eax@61
13744 GUIWindow *v39; // [sp-18h] [bp-304h]@31
13745 int v40; // [sp-14h] [bp-300h]@31
13746 int v41; // [sp-10h] [bp-2FCh]@31
13747 unsigned __int16 v42; // [sp-Ch] [bp-2F8h]@31
13748 char *v43; // [sp-8h] [bp-2F4h]@31
13749 unsigned int v44; // [sp-4h] [bp-2F0h]@31
13750 char Dest[100]; // [sp+Ch] [bp-2E0h]@3
13751 char v46[100]; // [sp+70h] [bp-27Ch]@3
13752 char v47[100]; // [sp+D4h] [bp-218h]@3
13753 char v48[100]; // [sp+138h] [bp-1B4h]@3
13754 char v49[100]; // [sp+19Ch] [bp-150h]@3
13755 POINT v50; // [sp+264h] [bp-88h]@30
13756 POINT v51; // [sp+26Ch] [bp-80h]@30
13757 GUIWindow v52; // [sp+274h] [bp-78h]@1
13758 signed int v53; // [sp+27Ch] [bp-70h]@1
13759 signed int v54; // [sp+284h] [bp-68h]@1
13760 int v55; // [sp+2C8h] [bp-24h]@47
13761 int v56; // [sp+2CCh] [bp-20h]@1
13762 int v57; // [sp+2D0h] [bp-1Ch]@1
13763 Player *v58; // [sp+2D4h] [bp-18h]@1
13764 unsigned __int8 uPlayerID; // [sp+2DBh] [bp-11h]@31
13765 char *Str; // [sp+2DCh] [bp-10h]@35
13766 int v61; // [sp+2E0h] [bp-Ch]@35
13767 unsigned int v62; // [sp+2E4h] [bp-8h]@13
13768 int v63; // [sp+2E8h] [bp-4h]@1
13769
13770 v0 = ptr_507BC0;
13771 memcpy(&v52, ptr_507BC0, sizeof(v52));
13772 v58 = pPlayers[uActiveCharacter];
13773 v1 = v58;
13774 v52.uFrameX = 483;
13775 v53 = 148;
13776 v54 = 334;
13777 v56 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
13778 v57 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
13779 //v2 = (signed __int64)(p2DEvents_minus1__20[13 * (unsigned int)v0->ptr_1C] * 500.0);
13780 v2 = (signed __int64)(p2DEvents[(unsigned int)v0->ptr_1C - 1].fPriceMultiplier * 500.0);
13781 v63 = v2 * (100 - v1->GetMerchant()) / 100;
13782 if ( v63 < v2 / 3 )
13783 v63 = v2 / 3;
13784 strcpy(Dest, nullstring);
13785 strcpy(v46, nullstring);
13786 strcpy(v47, nullstring);
13787 strcpy(v48, nullstring);
13788 strcpy(v49, nullstring);
13789 if ( dword_F8B19C != 1 )
13790 {
13791 if ( dword_F8B19C != 18 )
13792 {
13793 if ( sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
13794 {
13795 v3 = (int)(&v1->uIntelligence + dword_F8B19C);
13796 if ( *(short *)v3 )
13797 {
13798 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[403], pClassNames[dword_F8B19C + 20]);
13799 ShowStatusBarString(pTmpBuf, 2u);
13800 pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
13801 }
13802 else
13803 {
13804 if ( pParty->uNumGold < v63 )
13805 {
13806 ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
13807 HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, 2);
13808 }
13809 else
13810 {
13811 Party::TakeGold(v63);
13812 *(short *)v3 = 1;
13813 }
13814 }
13815 }
13816 result = pMessageQueue_50CBD0->uNumMessages;
13817 if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
13818 {
13819 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
13820 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
13821 result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
13822 *(&pMessageQueue_50CBD0->uNumMessages + result) = 0;
13823 ++pMessageQueue_50CBD0->uNumMessages;
13824 }
13825 return result;
13826 }
13827 pRenderer->DrawTextureIndexed(8u, 8u, dword_F8B164);
13828 v5 = 0;
13829 v6 = 0;
13830 v62 = 0;
13831 v63 = 32;
13832 do
13833 {
13834 if ( *(&pParty->pPlayers[1].pInstalledBeacons[0].field_18 + 9 * (v6 + 12 * (unsigned int)ptr_507BC0->ptr_1C)) )
13835 {
13836 pRenderer->DrawTextureTransparent(v63, 0x5Au, dword_F8B168[v6]);
13837 ZBuffer_DoFill((int *)((char *)pRenderer->pActiveZBuffer + v62 + 230528), dword_F8B168[v6], v6 + 1);
13838 v1 = v58;
13839 }
13840 v63 += 70;
13841 v62 += 280;
13842 ++v6;
13843 }
13844 while ( v63 < 452 );
13845 v62 = 1680;
13846 v7 = 6;
13847 v63 = 32;
13848 do
13849 {
13850 if ( *(&pParty->pPlayers[1].pInstalledBeacons[0].field_18 + 9 * (v7 + 12 * (unsigned int)ptr_507BC0->ptr_1C)) )
13851 {
13852 pRenderer->DrawTextureTransparent(v63, 0xFAu, dword_F8B168[v7]);
13853 ZBuffer_DoFill((int *)((char *)pRenderer->pActiveZBuffer + v62 + 638448), dword_F8B168[v7], v7 + 1);
13854 v1 = v58;
13855 }
13856 v63 += 70;
13857 v62 += 280;
13858 ++v7;
13859 }
13860 while ( v63 < 452 );
13861 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
13862 if ( result )
13863 {
13864 v8 = 0;
13865 v9 = 12;
13866 v10 = (char *)(&pParty->pPlayers[1].pInstalledBeacons[0].field_18 + 108 * (unsigned int)ptr_507BC0->ptr_1C);
13867 do
13868 {
13869 if ( *(int *)v10 )
13870 ++v8;
13871 v10 += 36;
13872 --v9;
13873 }
13874 while ( v9 );
13875 GetAsyncKeyState(17);
13876 v11 = pGlobalTXT_LocalizationStrings[195];
13877 if ( dword_F8B19C != 2 )
13878 v11 = pGlobalTXT_LocalizationStrings[196];
13879 sub_4B46A5(v11, 0);
13880 if ( !v8 )
13881 return (int)v52._4B1854(
13882 __PAIR__(
13883 *(int *)&stru_AA1058[3].pSounds[8 * (unsigned int)ptr_507BC0->ptr_1C + 44472],
13884 *(int *)&stru_AA1058[3].pSounds[8 * (unsigned int)ptr_507BC0->ptr_1C + 44468])
13885 - pParty->uTimePlayed);
13886 v12 = pMouse->GetCursorPos(&v51);
13887 result = v12->x + pSRZBufferLineOffsets[pMouse->GetCursorPos(&v50)->y];
13888 v13 = pRenderer->pActiveZBuffer[result] & 0xFFFF;
13889 if ( pRenderer->pActiveZBuffer[result] & 0xFFFF )
13890 {
13891 v14 = ptr_507BC0->ptr_1C;
13892 v15 = (ItemGen *)(&pParty->pPlayers[1].uExpressionTimeLength + 18 * (v13 + 12 * (int)v14));
13893 v16 = (int)ptr_507BC0->ptr_1C;
13894 uPlayerID = uActiveCharacter - 1;
13895 v17 = v1->_490EEE(
13896 (ItemGen *)&pParty->pPlayers[1].uExpressionTimeLength + v13 + 12 * (int)v14,
13897 3,
13898 v16,
13899 2);
13900 v18 = sub_495461((char *)pMerchantsBuyPhrases[v17], uPlayerID, v15, (char *)v14, 2, 0);
13901 v44 = 3;
13902 v43 = v18;
13903 v42 = v56;
13904 v41 = 0;
13905 v40 = 0;
13906 v39 = &v52;
13907 LABEL_32:
13908 v19 = pFontArrus->CalcTextHeight(v18, v39, v40, v41);
13909 return (int)v52.DrawText2(pFontArrus, v5, (174 - v19) / 2 + 138, v42, v43, v44);
13910 }
13911 }
13912 return result;
13913 }
13914 if ( !(unsigned __int16)_449B57_test_bit(
13915 (unsigned __int8 *)v1->field_152,
13916 word_4F0704[2 * (unsigned int)ptr_507BC0->ptr_1C]) )
13917 {
13918 v36 = dword_721A34;
13919 v37 = v57;
13920 v38 = pFontArrus->CalcTextHeight(dword_721A34, &v52, 0, 0);
13921 v52.DrawText2(pFontArrus, 0, (212 - v38) / 2 + 101, v37, v36, 3u);
13922 result = (int)pDialogueWindow;
13923 pDialogueWindow->field_28 = 0;
13924 return result;
13925 }
13926 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
13927 if ( !result )
13928 return result;
13929 v20 = pDialogueWindow;
13930 v5 = 0;
13931 v62 = 0;
13932 Str = 0;
13933 v21 = pDialogueWindow->field_38;
13934 v22 = v21 + pDialogueWindow->field_28;
13935 v61 = 0;
13936 if ( v21 >= v22 )
13937 goto LABEL_64;
13938 do
13939 {
13940 v23 = v20->GetControl(v21)->uControlParam;
13941 if ( v23 == 18 )
13942 {
13943 v25 = pFontArrus->CalcTextHeight(pGlobalTXT_LocalizationStrings[400], &v52, 0, 0);
13944 v62 += v25;
13945 ++v61;
13946 }
13947 else
13948 {
13949 if ( *(&byte_4ED94C[37 * v58->uClass] + v23) && !*(&v58->uIntelligence + v23) )
13950 {
13951 v24 = pFontArrus->CalcTextHeight(pClassNames[v23 + 20], &v52, 0, 0);
13952 v62 += v24;
13953 ++v61;
13954 ++Str;
13955 }
13956 }
13957 ++v21;
13958 }
13959 while ( v21 < v20->field_28 + v20->field_38 );
13960 if ( !v61 )
13961 {
13962 LABEL_64:
13963 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[544], v58->pName, pClassNames[v58->uClass]);
13964 strcat(pTmpBuf, "\n \n");
13965 strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);
13966 v18 = pTmpBuf;
13967 v44 = 3;
13968 v43 = pTmpBuf;
13969 v42 = v57;
13970 v41 = 0;
13971 v40 = 0;
13972 v39 = &v52;
13973 goto LABEL_32;
13974 }
13975 if ( Str )
13976 {
13977 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[401], v63);
13978 v52.DrawText2(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
13979 }
13980 v63 = (signed int)(149 - v62) / v61;
13981 if ( v63 > 32 )
13982 v63 = 32;
13983 result = v20->field_38;
13984 v26 = (signed int)(149 - v61 * v63 - v62) / 2 - v63 / 2 + 162;
13985 v62 = result;
13986 v55 = v26;
13987 if ( result < result + v20->field_28 )
13988 {
13989 v61 = 2;
13990 while ( 1 )
13991 {
13992 v27 = v20->GetControl(v62);
13993 v28 = v27;
13994 v29 = v27->uControlParam;
13995 if ( v29 == 18 )
13996 break;
13997 if ( *(&byte_4ED94C[37 * v58->uClass] + v29) && !*(&v58->uIntelligence + v29) )
13998 {
13999 v30 = pClassNames[v29 + 20];
14000 LABEL_55:
14001 Str = v30;
14002 v28->uY = v63 + v55;
14003 v31 = pFontArrus->CalcTextHeight(v30, &v52, 0, 0);
14004 v32 = v28->uY;
14005 v28->uHeight = v31;
14006 v33 = v32 + v31 - 1;
14007 v28->uW = v33;
14008 v55 = v33;
14009 v34 = v57;
14010 if ( pDialogueWindow->field_2C_focus_id != v61 )
14011 v34 = v56;
14012 v52.DrawText2(pFontArrus, 0, v32, v34, Str, 3u);
14013 goto LABEL_58;
14014 }
14015 v28->uW = 0;
14016 v28->uHeight = 0;
14017 v28->uY = 0;
14018 LABEL_58:
14019 v35 = v20->field_38;
14020 ++v62;
14021 result = v20->field_28 + v35;
14022 ++v61;
14023 if ( (signed int)v62 >= result )
14024 return result;
14025 }
14026 v30 = pGlobalTXT_LocalizationStrings[400];
14027 goto LABEL_55;
14028 }
14029 return result;
14030 }
14031
14032
14033
14034 //----- (004B705E) --------------------------------------------------------
14035 int __cdecl sub_4B705E()
14036 {
14037 GUIWindow *v0; // ebx@1
14038 Player *v1; // esi@1
14039 int v2; // edi@1
14040 int result; // eax@4
14041 GUIWindow *v4; // edi@6
14042 void *v5; // eax@6
14043 int v6; // eax@6
14044 unsigned int v7; // eax@8
14045 int v8; // ecx@8
14046 unsigned int v9; // eax@9
14047 int v10; // eax@11
14048 int v11; // eax@12
14049 GUIWindow *v12; // ecx@16
14050 int v13; // edx@16
14051 GUIButton *v14; // eax@19
14052 GUIButton *v15; // edi@19
14053 int v16; // eax@19
14054 const char *v17; // eax@21
14055 int v18; // eax@21
14056 unsigned int v19; // ecx@21
14057 int v20; // eax@21
14058 unsigned __int16 v21; // ax@21
14059 unsigned __int16 v22; // ST14_2@27
14060 int v23; // eax@27
14061 double v24; // st7@28
14062 unsigned int v25; // ebx@28
14063 DDM_DLV_Header *v26; // edi@29
14064 int v27; // eax@31
14065 int v28; // eax@32
14066 unsigned int v29; // ecx@34
14067 unsigned int v30; // edx@36
14068 unsigned int v31; // edx@38
14069 unsigned int v32; // edx@40
14070 unsigned int v33; // edx@42
14071 unsigned int v34; // edx@44
14072 int v35; // edi@50
14073 signed int v36; // eax@50
14074 unsigned __int8 v37; // al@54
14075 int v38; // ecx@54
14076 GUIWindow *v39; // eax@56
14077 unsigned __int8 v40; // al@61
14078 GUIButton *v41; // edi@64
14079 int v42; // esi@66
14080 GUIWindow *v43; // ecx@66
14081 int v44; // edi@66
14082 int v45; // eax@68
14083 signed int v46; // edi@69
14084 int v47; // edi@71
14085 GUIButton *v48; // eax@73
14086 const char *v49; // edx@73
14087 GUIButton *v50; // esi@73
14088 int v51; // eax@73
14089 unsigned int v52; // ecx@73
14090 unsigned __int16 v53; // ax@73
14091 char a1[100]; // [sp+10h] [bp-1B4h]@64
14092 char Dest; // [sp+74h] [bp-150h]@66
14093 char v56; // [sp+D8h] [bp-ECh]@66
14094 GUIWindow v57; // [sp+13Ch] [bp-88h]@1
14095 __int64 v58; // [sp+190h] [bp-34h]@1
14096 __int64 v59; // [sp+198h] [bp-2Ch]@1
14097 __int64 v60; // [sp+1A0h] [bp-24h]@1
14098 GUIWindow *v61; // [sp+1ACh] [bp-18h]@6
14099 unsigned int v62; // [sp+1B0h] [bp-14h]@8
14100 unsigned __int8 v63; // [sp+1B7h] [bp-Dh]@64
14101 int v64; // [sp+1B8h] [bp-Ch]@6
14102 unsigned int v65; // [sp+1BCh] [bp-8h]@6
14103 DDM_DLV_Header *v66; // [sp+1C0h] [bp-4h]@6
14104
14105 v0 = ptr_507BC0;
14106 memcpy(&v57, ptr_507BC0, sizeof(v57));
14107 v57.uFrameX = 483;
14108 v57.uFrameWidth = 148;
14109 v57.uFrameZ = 334;
14110 HIDWORD(v58) = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
14111 HIDWORD(v59) = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
14112 v1 = pPlayers[uActiveCharacter];
14113 //v2 = pPlayers[uActiveCharacter]->_4B807C(p2DEvents_minus1__20[13 * (unsigned int)v0->ptr_1C]);
14114 v2 = pPlayers[uActiveCharacter]->_4B807C(p2DEvents[(unsigned int)v0->ptr_1C - 1].fPriceMultiplier);
14115 HIDWORD(v60) = v2;
14116 if ( dword_F8B19C != 1 )
14117 {
14118 if ( dword_F8B19C != 10 )
14119 {
14120 if ( dword_F8B19C != 11 )
14121 {
14122 result = dword_F8B19C - 96;
14123 if ( dword_F8B19C == 96 )
14124 {
14125 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
14126 if ( result )
14127 {
14128 v4 = pDialogueWindow;
14129 v61 = pDialogueWindow;
14130 v5 = ptr_507BC0->ptr_1C;
14131 v66 = 0;
14132 //v65 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (signed int)v5] * 500.0);
14133 v65 = (signed __int64)(p2DEvents[(signed int)v5 - 1].flt_24 * 500.0);
14134 v6 = v1->GetMerchant();
14135 v64 = (signed int)(v65 * (100 - v6)) / 100;
14136 if ( v64 < (signed int)v65 / 3 )
14137 v64 = (signed int)v65 / 3;
14138 v7 = v4->field_38;
14139 v8 = v7 + v4->field_28;
14140 v65 = 0;
14141 v62 = v7;
14142 if ( (signed int)v7 >= v8 )
14143 goto LABEL_78;
14144 do
14145 {
14146 v9 = v4->GetControl(v62)->uControlParam - 36;
14147 if ( byte_4ED970_skill_learn_ability_by_class_table[v1->uClass][v9] && !v1->pActiveSkills[v9] )
14148 {
14149 v10 = pFontArrus->CalcTextHeight(pSkillNames[v9], &v57, 0, 0);
14150 v66 = (DDM_DLV_Header *)((char *)v66 + v10);
14151 ++v65;
14152 }
14153 v11 = v4->field_38;
14154 ++v62;
14155 }
14156 while ( (signed int)v62 < v4->field_28 + v11 );
14157 if ( v65 )
14158 {
14159 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[401], v64);
14160 v57.DrawText2(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
14161 v64 = (149 - (signed int)v66) / (signed int)v65;
14162 if ( v64 > 32 )
14163 v64 = 32;
14164 v65 = (signed int)(149 - v65 * v64 - (int)v66) / 2 - v64 / 2 + 162;
14165 v12 = v61;
14166 result = v61->field_38;
14167 v13 = result + v61->field_28;
14168 v62 = v61->field_38;
14169 if ( result < v13 )
14170 {
14171 v66 = (DDM_DLV_Header *)2;
14172 while ( 1 )
14173 {
14174 v14 = v12->GetControl(v62);
14175 v15 = v14;
14176 v16 = v14->uControlParam - 36;
14177 if ( !byte_4ED970_skill_learn_ability_by_class_table[v1->uClass][v16] || v1->pActiveSkills[v16] )
14178 {
14179 v15->uW = 0;
14180 v15->uHeight = 0;
14181 v15->uY = 0;
14182 }
14183 else
14184 {
14185 v17 = pSkillNames[v16];
14186 v15->uY = v64 + v65;
14187 HIDWORD(v60) = (uint32)v17;
14188 v18 = pFontArrus->CalcTextHeight(v17, &v57, 0, 0);
14189 v19 = v15->uY;
14190 v15->uHeight = v18;
14191 v20 = v19 + v18 - 1;
14192 v15->uW = v20;
14193 v65 = v20;
14194 v21 = WORD2(v59);
14195 if ( (DDM_DLV_Header *)pDialogueWindow->field_2C_focus_id != v66 )
14196 v21 = WORD2(v58);
14197 v57.DrawText2(pFontArrus, 0, v19, v21, (const char *)HIDWORD(v60), 3u);
14198 }
14199 result = (int)v61;
14200 ++v62;
14201 v66 = (DDM_DLV_Header *)((char *)v66 + 1);
14202 if ( (signed int)v62 >= v61->field_28 + v61->field_38 )
14203 break;
14204 v12 = v61;
14205 }
14206 }
14207 }
14208 else
14209 {
14210 LABEL_78:
14211 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[544], v1->pName, pClassNames[v1->uClass]);
14212 strcat(pTmpBuf, "\n \n");
14213 strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);
14214 v22 = WORD2(v59);
14215 v23 = pFontArrus->CalcTextHeight(pTmpBuf, &v57, 0, 0);
14216 result = (int)v57.DrawText2(pFontArrus, 0, (174 - v23) / 2 + 138, v22, pTmpBuf, 3u);
14217 }
14218 }
14219 }
14220 return result;
14221 }
14222 //v24 = p2DEvents_minus1__20[13 * (unsigned int)ptr_507BC0->ptr_1C];
14223 v24 = p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].fPriceMultiplier;
14224 v25 = 0;
14225 if ( pParty->uNumGold >= (unsigned int)(signed __int64)v24 )
14226 {
14227 Party::TakeGold((signed __int64)v24);
14228 v26 = &pOutdoor->ddm;
14229 if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
14230 v26 = &pIndoor->dlv;
14231 v27 = v26->uReputation;
14232 v66 = v26;
14233 if ( v27 > -5 )
14234 {
14235 v28 = v27 - 1;
14236 v26->uReputation = v28;
14237 if ( v28 < -5 )
14238 v26->uReputation = -5;
14239 }
14240 v29 = uActiveCharacter;
14241 if ( (unsigned __int8)byte_F8B1EF[uActiveCharacter] == pParty->uDaysPlayed % 7 )
14242 {
14243 if ( v26->uReputation <= -5 )
14244 {
14245 v30 = pParty->uDaysPlayed % 7 + 1;
14246 LOBYTE(v30) = v30 | 0x80;
14247 _42777D_CastSpell_UseWand_ShootArrow(12, uActiveCharacter - 1, v30, 48, 0);
14248 v29 = uActiveCharacter;
14249 }
14250 if ( v26->uReputation <= -10 )
14251 {
14252 v31 = pParty->uDaysPlayed % 7 + 1;
14253 LOBYTE(v31) = v31 | 0x80;
14254 _42777D_CastSpell_UseWand_ShootArrow(50, v29 - 1, v31, 48, 0);
14255 v29 = uActiveCharacter;
14256 v26 = v66;
14257 }
14258 if ( v26->uReputation <= -15 )
14259 {
14260 v32 = pParty->uDaysPlayed % 7 + 1;
14261 LOBYTE(v32) = v32 | 0x80;
14262 _42777D_CastSpell_UseWand_ShootArrow(75, v29 - 1, v32, 48, 0);
14263 v29 = uActiveCharacter;
14264 v26 = v66;
14265 }
14266 if ( v26->uReputation <= -20 )
14267 {
14268 v33 = pParty->uDaysPlayed % 7 + 1;
14269 LOBYTE(v33) = v33 | 0x80;
14270 _42777D_CastSpell_UseWand_ShootArrow(86, v29 - 1, v33, 48, 0);
14271 v29 = uActiveCharacter;
14272 v26 = v66;
14273 }
14274 if ( v26->uReputation <= -25 )
14275 {
14276 v34 = pParty->uDaysPlayed % 7 + 1;
14277 LOBYTE(v34) = v34 | 0x80;
14278 _42777D_CastSpell_UseWand_ShootArrow(85, v29 - 1, v34, 48, 0);
14279 v29 = uActiveCharacter;
14280 }
14281 }
14282 ++byte_F8B1EF[v29];
14283 v1->PlaySound(83, 0);
14284 ShowStatusBarString(pGlobalTXT_LocalizationStrings[527], 2u);
14285 goto LABEL_46;
14286 }
14287 goto LABEL_55;
14288 }
14289 result = v1->_4B6FF9();
14290 if ( !result )
14291 return result;
14292 v25 = 0;
14293 if ( pParty->uNumGold < v2 )
14294 {
14295 LABEL_55:
14296 ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
14297 HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, 2);
14298 goto LABEL_46;
14299 }
14300 Party::TakeGold(v2);
14301 v35 = LODWORD(v1->pConditions[17]);
14302 v59 = v1->pConditions[14];
14303 v58 = v1->pConditions[15];
14304 v60 = v1->pConditions[16];
14305 v61 = (GUIWindow *)HIDWORD(v1->pConditions[17]);
14306 memset(v1, 0, 0xA0u);
14307 v1->sHealth = v1->GetMaxHealth();
14308 v1->sMana = v1->GetMaxMana();
14309 v36 = (signed int)ptr_507BC0->ptr_1C;
14310 if ( v36 != 78 && (v36 <= 80 || v36 > 82) )
14311 {
14312 if ( (unsigned int)v61 | v35 )
14313 {
14314 v37 = LOBYTE(v1->field_1928);
14315 v38 = v1->field_1924;
14316 v1->uFace = v37;
14317 v1->uVoiceID = v38;
14318 ReloadPlayerPortraits(uActiveCharacter - 1, (char)v37);
14319 }
14320 goto LABEL_63;
14321 }
14322 v39 = v61;
14323 if ( (unsigned int)v61 | v35 )
14324 {
14325 LODWORD(v1->pConditions[17]) = v35;
14326 }
14327 else
14328 {
14329 if ( !v60 && !v58 && !v59 )
14330 goto LABEL_63;
14331 v1->field_1928 = v1->uFace;
14332 v1->field_1924 = v1->uVoiceID;
14333 v1->SetCondition(0x11u, 1);
14334 v1->uVoiceID = (v1->GetSexByVoice() != 0) + 23;
14335 v40 = (v1->GetSexByVoice() != 0) + 23;
14336 v1->uFace = v40;
14337 ReloadPlayerPortraits(uActiveCharacter - 1, (char)v40);
14338 LODWORD(v1->pConditions[17]) = LODWORD(pParty->uTimePlayed);
14339 v39 = (GUIWindow *)HIDWORD(pParty->uTimePlayed);
14340 }
14341 HIDWORD(v1->pConditions[17]) = (int)v39;
14342 LABEL_63:
14343 pAudioPlayer->PlaySound((SoundID)(SOUND_GoldReceived|0x2), -1, 0, -1, 0, 0, 0, 0);
14344 v1->PlaySound(82, 0);
14345 pOtherOverlayList->_4418B1(20, uActiveCharacter + 99, 0, 65536);
14346 LABEL_46:
14347 result = pMessageQueue_50CBD0->uNumMessages;
14348 if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
14349 {
14350 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
14351 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
14352 result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
14353 *(&pMessageQueue_50CBD0->uNumMessages + result) = v25;
14354 ++pMessageQueue_50CBD0->uNumMessages;
14355 }
14356 return result;
14357 }
14358 v63 = 1;
14359 v41 = pDialogueWindow->GetControl(pDialogueWindow->field_38);
14360 strcpy(a1, nullstring);
14361 v41->uHeight = 0;
14362 v41->uY = 0;
14363 if ( v1->_4B6FF9() )
14364 {
14365 sprintfex(a1, "%s %d %s", pGlobalTXT_LocalizationStrings[104], HIDWORD(v60), pGlobalTXT_LocalizationStrings[97]);
14366 v63 = 0;
14367 }
14368 strcpy(&Dest, pGlobalTXT_LocalizationStrings[68]);
14369 strcpy(&v56, pGlobalTXT_LocalizationStrings[160]);
14370 v42 = v63;
14371 v43 = pDialogueWindow;
14372 v44 = v63;
14373 v66 = 0;
14374 if ( v63 < pDialogueWindow->field_28 )
14375 {
14376 v61 = (GUIWindow *)&a1[100 * v63];
14377 do
14378 {
14379 v45 = pFontArrus->CalcTextHeight((const char *)v61, &v57, 0, 0);
14380 v66 = (DDM_DLV_Header *)((char *)v66 + v45);
14381 v43 = pDialogueWindow;
14382 v61 = (GUIWindow *)((char *)v61 + 100);
14383 ++v44;
14384 }
14385 while ( v44 < pDialogueWindow->field_28 );
14386 }
14387 v46 = v43->field_28 - v42;
14388 v64 = (174 - (signed int)v66) / v46;
14389 if ( v64 > 32 )
14390 v64 = 32;
14391 result = v43->field_38;
14392 v47 = (174 - v64 * v46 - (signed int)v66) / 2 - v64 / 2 + 138;
14393 v65 = v42 + result;
14394 if ( v42 + result < result + v43->field_28 )
14395 {
14396 v61 = (GUIWindow *)(v42 + 2);
14397 v66 = (DDM_DLV_Header *)&a1[100 * v42];
14398 do
14399 {
14400 v48 = v43->GetControl(v65);
14401 v49 = (const char *)v66;
14402 v50 = v48;
14403 v48->uY = v64 + v47;
14404 v51 = pFontArrus->CalcTextHeight(v49, &v57, 0, 0);
14405 v52 = v50->uY;
14406 v50->uHeight = v51;
14407 v47 = v52 + v51 - 1;
14408 v50->uW = v47;
14409 v53 = WORD2(v59);
14410 if ( (GUIWindow *)pDialogueWindow->field_2C_focus_id != v61 )
14411 v53 = WORD2(v58);
14412 v57.DrawText2(pFontArrus, 0, v52, v53, (const char *)v66, 3u);
14413 v43 = pDialogueWindow;
14414 v66 = (DDM_DLV_Header *)((char *)v66 + 100);
14415 v61 = (GUIWindow *)((char *)v61 + 1);
14416 ++v65;
14417 result = pDialogueWindow->field_28 + pDialogueWindow->field_38;
14418 }
14419 while ( (signed int)v65 < result );
14420 }
14421 return result;
14422 }
14423
14424
14425
14426 //----- (004B8F94) --------------------------------------------------------
14427 void *__cdecl sub_4B8F94()
14428 {
14429 GUIWindow *v0; // edi@1
14430 signed int v1; // ebp@1
14431 int v2; // ebx@1
14432 signed int v3; // esi@1
14433 int v4; // eax@3
14434 int v5; // ebx@3
14435 int v6; // ecx@3
14436 bool v7; // eax@5
14437 bool v8; // ST1C_4@5
14438 int v9; // eax@5
14439 int v10; // eax@10
14440 void *result; // eax@15
14441 signed int v12; // [sp-4h] [bp-18h]@7
14442
14443 v0 = ptr_507BC0;
14444 v1 = 0;
14445 v2 = (int)&ptr_507BC0->ptr_1C;
14446 v3 = (signed int)ptr_507BC0->ptr_1C;
14447 //if ( _4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)ptr_507BC0->ptr_1C]] )
14448 if ( _4F063C_smthn_by_2da_uType[p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].uType] )
14449 {
14450 while ( v3 > 14 )
14451 {
14452 if ( v3 <= 28 )
14453 {
14454 v7 = v1 > 3;
14455 v8 = v7;
14456 v9 = 5 * (v7 + 2 * v3 - 30);
14457 v3 = (signed int)v0->ptr_1C;
14458 v5 = word_4F06D8[v9];
14459 v6 = word_4F05AE[5 * (v8 + 2 * v3) + rand() % 4];
14460 goto LABEL_13;
14461 }
14462 if ( v3 <= 41 )
14463 {
14464 v5 = word_4F07B6[v3];
14465 v12 = 22;
14466 goto LABEL_12;
14467 }
14468 if ( v3 <= 53 )
14469 {
14470 if ( v1 >= 6 )
14471 {
14472 v5 = word_4F07B6[v3 + 1];
14473 v12 = 44;
14474 LABEL_12:
14475 v6 = v12;
14476 LABEL_13:
14477 pItemsTable->GenerateItem(v5, v6, (ItemGen *)&pParty->field_C59C[9 * (v1 + 12 * v3) + 724]);
14478 v0 = ptr_507BC0;
14479 v2 = (int)&ptr_507BC0->ptr_1C;
14480 pParty->field_C59C[9 * (v1 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 729] = 1;
14481 goto LABEL_14;
14482 }
14483 auto _a = (ItemGen *)&pParty->field_C59C[9 * (v1 + 12 * v3) + 724];
14484 _a->Reset();
14485 v2 = (int)&v0->ptr_1C;
14486 v10 = rand();
14487 v0 = ptr_507BC0;
14488 pParty->field_C59C[9 * (v1 + 12 * *(int *)v2) + 724] = v10 % 32 + 740;
14489 }
14490 LABEL_14:
14491 v3 = *(int *)v2;
14492 ++v1;
14493 //if ( v1 >= (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * *(int *)v2]] )
14494 if ( v1 >= (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents[*(int *)v2 - 1].uType] )
14495 goto LABEL_15;
14496 }
14497 v4 = 5 * v3;
14498 v3 = (signed int)v0->ptr_1C;
14499 v5 = word_4F063E[v4];
14500 v6 = word_4F063E[5 * v3 + rand() % 4 + 1];
14501 goto LABEL_13;
14502 }
14503 LABEL_15:
14504 result = v0->ptr_1C;
14505 *(int *)&pParty->field_16154[4 * (int)result] = 0;
14506 return result;
14507 }
14508
14509
14510 //----- (004B6478) --------------------------------------------------------
14511 int __cdecl sub_4B6478()
14512 {
14513 GUIWindow *v0; // ebx@1
14514 Player *v1; // edi@1
14515 unsigned int v2; // eax@1
14516 signed int v3; // esi@1
14517 int v4; // ebx@1
14518 unsigned int v5; // esi@5
14519 int v6; // edi@6
14520 int result; // eax@13
14521 GUIWindow *v8; // ebx@17
14522 int v9; // eax@17
14523 int v10; // ecx@17
14524 unsigned int v11; // ecx@18
14525 int v12; // eax@20
14526 int v13; // eax@21
14527 GUIButton *v14; // esi@27
14528 int v15; // ecx@27
14529 unsigned int v16; // eax@28
14530 const char *v17; // ebx@29
14531 int v18; // eax@29
14532 unsigned int v19; // ecx@29
14533 int v20; // eax@29
14534 unsigned __int16 v21; // ax@29
14535 unsigned __int16 v22; // ST14_2@36
14536 int v23; // eax@36
14537 const char *v24; // ST18_4@37
14538 unsigned __int16 v25; // ST14_2@37
14539 int v26; // eax@37
14540 int v27; // [sp-4h] [bp-80h]@8
14541 GUIWindow v28; // [sp+Ch] [bp-70h]@1
14542 GUIWindow *v29; // [sp+60h] [bp-1Ch]@17
14543 unsigned int v30; // [sp+64h] [bp-18h]@1
14544 int v31; // [sp+68h] [bp-14h]@1
14545 int v32; // [sp+6Ch] [bp-10h]@1
14546 int v33; // [sp+70h] [bp-Ch]@17
14547 int v34; // [sp+74h] [bp-8h]@17
14548 int v35; // [sp+78h] [bp-4h]@17
14549
14550 v0 = ptr_507BC0;
14551 memcpy(&v28, ptr_507BC0, sizeof(v28));
14552 v1 = pPlayers[uActiveCharacter];
14553 v28.uFrameX = 483;
14554 v28.uFrameWidth = 148;
14555 v28.uFrameZ = 334;
14556 v30 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
14557 v31 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
14558 v2 = 52 * (unsigned int)v0->ptr_1C;
14559 //v32 = (unsigned __int8)(((p2DEvents_minus1___00[v2 / 2] != 18) - 1) & 0x96) + 100;
14560 v32 = (unsigned __int8)(((p2DEvents[(unsigned int)v0->ptr_1C - 1].uType != 18) - 1) & 0x96) + 100;
14561 //v3 = (signed __int64)((double)v32 * p2DEvents_minus1__20[v2 / 4]);
14562 v3 = (signed __int64)((double)v32 * p2DEvents[(unsigned int)v0->ptr_1C - 1].fPriceMultiplier);
14563 v4 = v3 * (100 - v1->GetMerchant()) / 100;
14564 v32 = v4;
14565 if ( v4 < v3 / 3 )
14566 {
14567 v4 = v3 / 3;
14568 v32 = v3 / 3;
14569 }
14570 if ( dword_F8B19C != 1 )
14571 {
14572 if ( sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
14573 {
14574 v5 = 0;
14575 if ( !*(&byte_4ED94C[37 * v1->uClass / 3] + dword_F8B19C)
14576 || (v6 = (int)(&v1->uIntelligence + dword_F8B19C), *(short *)v6) )
14577 {
14578 pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
14579 }
14580 else
14581 {
14582 if ( pParty->uNumGold < v4 )
14583 {
14584 ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
14585 v27 = 4;
14586 }
14587 else
14588 {
14589 Party::TakeGold(v4);
14590 *(short *)v6 = 1;
14591 v27 = 2;
14592 }
14593 HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, v27);
14594 }
14595 }
14596 else
14597 {
14598 v5 = 0;
14599 }
14600 result = pMessageQueue_50CBD0->uNumMessages;
14601 if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
14602 {
14603 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
14604 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
14605 result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
14606 *(&pMessageQueue_50CBD0->uNumMessages + result) = v5;
14607 ++pMessageQueue_50CBD0->uNumMessages;
14608 }
14609 return result;
14610 }
14611 if ( !(unsigned __int16)_449B57_test_bit(
14612 (unsigned __int8 *)v1->field_152,
14613 word_4F0754[2 * (unsigned int)ptr_507BC0->ptr_1C]) )
14614 {
14615 v24 = dword_721BC4;
14616 v25 = v31;
14617 v26 = pFontArrus->CalcTextHeight(dword_721BC4, &v28, 0, 0);
14618 v28.DrawText2(pFontArrus, 0, (212 - v26) / 2 + 101, v25, v24, 3u);
14619 result = (int)pDialogueWindow;
14620 pDialogueWindow->field_28 = 0;
14621 return result;
14622 }
14623 result = sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
14624 if ( !result )
14625 return result;
14626 v8 = pDialogueWindow;
14627 v33 = 0;
14628 v34 = 0;
14629 v29 = pDialogueWindow;
14630 v9 = pDialogueWindow->field_38;
14631 v10 = v9 + pDialogueWindow->field_28;
14632 v35 = pDialogueWindow->field_38;
14633 if ( v9 >= v10 )
14634 goto LABEL_40;
14635 do
14636 {
14637 v11 = v8->GetControl(v35)->uControlParam - 36;
14638 if ( byte_4ED970_skill_learn_ability_by_class_table[v1->uClass / 3][v11] && !v1->pActiveSkills[v11] )
14639 {
14640 v12 = pFontArrus->CalcTextHeight(pSkillNames[v11], &v28, 0, 0);
14641 v33 += v12;
14642 ++v34;
14643 }
14644 v13 = v8->field_38;
14645 ++v35;
14646 }
14647 while ( v35 < v8->field_28 + v13 );
14648 if ( !v34 )
14649 {
14650 LABEL_40:
14651 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[544], v1->pName, pClassNames[v1->uClass]);
14652 strcat(pTmpBuf, "\n \n");
14653 strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);
14654 v22 = v31;
14655 v23 = pFontArrus->CalcTextHeight(pTmpBuf, &v28, 0, 0);
14656 return (int)v28.DrawText2(pFontArrus, 0, (174 - v23) / 2 + 138, v22, pTmpBuf, 3u);
14657 }
14658 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[401], v32);
14659 v28.DrawText2(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
14660 v32 = (149 - v33) / v34;
14661 if ( (149 - v33) / v34 > 32 )
14662 v32 = 32;
14663 result = v8->field_38;
14664 v35 = result;
14665 v34 = (149 - v34 * v32 - v33) / 2 - v32 / 2 + 162;
14666 if ( result < result + v8->field_28 )
14667 {
14668 v33 = 2;
14669 do
14670 {
14671 v14 = v8->GetControl(v35);
14672 v15 = v14->uControlParam - 36;
14673 if ( byte_4ED970_skill_learn_ability_by_class_table[v1->uClass / 3][v15] )
14674 {
14675 v16 = 0;
14676 if ( !v1->pActiveSkills[v15] )
14677 {
14678 v17 = pSkillNames[v15];
14679 v14->uY = v32 + v34;
14680 v18 = pFontArrus->CalcTextHeight(v17, &v28, 0, 0);
14681 v19 = v14->uY;
14682 v14->uHeight = v18;
14683 v20 = v19 + v18 - 1;
14684 v14->uW = v20;
14685 v34 = v20;
14686 v21 = v31;
14687 if ( pDialogueWindow->field_2C_focus_id != v33 )
14688 v21 = v30;
14689 v28.DrawText2(pFontArrus, 0, v19, v21, v17, 3u);
14690 goto LABEL_34;
14691 }
14692 }
14693 else
14694 {
14695 v16 = 0;
14696 }
14697 v14->uW = v16;
14698 v14->uHeight = v16;
14699 v14->uY = v16;
14700 LABEL_34:
14701 v8 = v29;
14702 ++v35;
14703 ++v33;
14704 result = v29->field_28 + v29->field_38;
14705 }
14706 while ( v35 < result );
14707 }
14708 return result;
14709 }
14710
14711
14712
14713 //----- (004B6943) --------------------------------------------------------
14714 void __cdecl TravelByTransport()
14715 {
14716 GUIWindow *v0; // ebx@1
14717 Player *v1; // esi@1
14718 signed int v2; // edi@1
14719 unsigned int v3; // eax@1
14720 signed int v4; // ebx@1
14721 char *v5; // esi@7
14722 int v6; // eax@9
14723 int v7; // eax@9
14724 int v8; // eax@12
14725 int v9; // edi@12
14726 int v10; // edx@12
14727 int v11; // ecx@12
14728 signed int v12; // esi@13
14729 signed int v13; // edi@14
14730 DWORD v14; // eax@26
14731 DWORD v15; // edi@26
14732 GUIWindow *v16; // ebx@36
14733 int v17; // esi@36
14734 int v18; // eax@36
14735 int v19; // ecx@36
14736 int v20; // esi@36
14737 int v21; // eax@36
14738 void *v22; // eax@39
14739 Player *v23; // esi@39
14740 GUIButton *v24; // ebx@39
14741 signed int v25; // eax@41
14742 int v26; // esi@44
14743 const char *v27; // eax@46
14744 char *v28; // eax@62
14745 int v29; // eax@62
14746 unsigned int v30; // ecx@62
14747 char *v31; // eax@63
14748 char v32; // [sp-3Ch] [bp-2CCh]@62
14749 int v33; // [sp-38h] [bp-2C8h]@62
14750 int v34; // [sp-34h] [bp-2C4h]@62
14751 int v35; // [sp-30h] [bp-2C0h]@62
14752 int v36; // [sp-2Ch] [bp-2BCh]@62
14753 int v37; // [sp-28h] [bp-2B8h]@62
14754 int v38; // [sp-24h] [bp-2B4h]@62
14755 int v39; // [sp-20h] [bp-2B0h]@62
14756 int v40; // [sp-1Ch] [bp-2ACh]@62
14757 int v41; // [sp-18h] [bp-2A8h]@62
14758 int v42; // [sp-14h] [bp-2A4h]@62
14759 char *v43; // [sp-10h] [bp-2A0h]@62
14760 char *v44; // [sp-Ch] [bp-29Ch]@62
14761 unsigned int v45; // [sp-8h] [bp-298h]@62
14762 char *v46; // [sp-4h] [bp-294h]@62
14763 const char *v47[5]; // [sp+0h] [bp-290h]@7
14764 char v48; // [sp+14h] [bp-27Ch]@37
14765 char v49; // [sp+78h] [bp-218h]@68
14766 char v50; // [sp+DCh] [bp-1B4h]@68
14767 char v51; // [sp+140h] [bp-150h]@68
14768 char Dest; // [sp+1A4h] [bp-ECh]@36
14769 GUIWindow v53; // [sp+208h] [bp-88h]@1
14770 int v54; // [sp+25Ch] [bp-34h]@36
14771 int v55; // [sp+260h] [bp-30h]@36
14772 unsigned int v56; // [sp+264h] [bp-2Ch]@1
14773 __int16 v57[2]; // [sp+268h] [bp-28h]@1
14774 Player *v58; // [sp+26Ch] [bp-24h]@36
14775 GUIWindow *v59; // [sp+270h] [bp-20h]@1
14776 unsigned int v60; // [sp+274h] [bp-1Ch]@36
14777 Player *v61; // [sp+278h] [bp-18h]@1
14778 int v62; // [sp+27Ch] [bp-14h]@36
14779 int v63; // [sp+280h] [bp-10h]@14
14780 char *a1; // [sp+284h] [bp-Ch]@37
14781 unsigned int s1; // [sp+288h] [bp-8h]@1
14782 int v66; // [sp+28Ch] [bp-4h]@48
14783
14784 v0 = ptr_507BC0;
14785 memcpy(&v53, ptr_507BC0, sizeof(v53));
14786 v2 = 255;
14787 v61 = pPlayers[uActiveCharacter];
14788 v1 = v61;
14789 v53.uFrameX = 483;
14790 v53.uFrameWidth = 148;
14791 v53.uFrameZ = 334;
14792 *(int *)v57 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
14793 v56 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
14794 v3 = 52 * (unsigned int)v0->ptr_1C;
14795 //v59 = (GUIWindow *)((((p2DEvents_minus1___00[v3 / 2] != 27) - 1) & 0xFFFFFFE7) + 50);
14796 v59 = (GUIWindow *)((((p2DEvents[(unsigned int)v0->ptr_1C - 1].uType != 27) - 1) & 0xFFFFFFE7) + 50);
14797 //v4 = (signed __int64)((double)(signed int)v59 * p2DEvents_minus1__20[v3 / 4]);
14798 v4 = (signed __int64)((double)(signed int)v59 * p2DEvents[(unsigned int)v0->ptr_1C - 1].fPriceMultiplier);
14799 s1 = v4 * (100 - v1->GetMerchant()) / 100;
14800 if ( (signed int)s1 < v4 / 3 )
14801 s1 = v4 / 3;
14802 if ( dword_F8B19C == 1 )
14803 {
14804 if ( sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
14805 {
14806 v16 = pDialogueWindow;
14807 v58 = (Player *)-1;
14808 v62 = 0;
14809 v17 = LOBYTE(pFontArrus->uFontHeight) - 3;
14810 v59 = pDialogueWindow;
14811 v54 = v17;
14812 strcpy(&Dest, nullstring);
14813 sprintfex(pTmpBuf2, pGlobalTXT_LocalizationStrings[405], s1);
14814 v18 = pFontArrus->CalcTextHeight(pTmpBuf2, &v53, 0, 0);
14815 v19 = v16->field_28;
14816 v20 = v18 + v17 + 146;
14817 v21 = v16->field_38;
14818 v63 = v20;
14819 v55 = v20;
14820 v60 = v21;
14821 if ( v21 >= v21 + v19 )
14822 goto LABEL_71;
14823 s1 = 2;
14824 a1 = &v48;
14825 while ( 1 )
14826 {
14827 v47[1] = (const char *)v60;
14828 v22 = ptr_507BC0->ptr_1C;
14829 v23 = (Player *)(unsigned __int8)*(&_4F0D38_TravelInfo[4 * (signed int)v22] + v62);
14830 v61 = (Player *)(unsigned __int8)*(&_4F0D38_TravelInfo[4 * (signed int)v22] + v62);
14831 v24 = v16->GetControl(v60);
14832 if ( v23 != v58
14833 && ((signed int)s1 >= 6 ? (v25 = 1) : (v25 = (unsigned __int8)*(&byte_4F09B1[32 * (int)v23]
14834 + pParty->uDaysPlayed % 7)),
14835 v25
14836 && ((v26 = 8 * (int)v23, !dword_4F09CC[v26])
14837 || (unsigned __int16)_449B57_test_bit(pParty->_award_bits, LOWORD(dword_4F09CC[v26])))) )
14838 {
14839 v58 = v61;
14840 v27 = (const char *)v56;
14841 if ( pDialogueWindow->field_2C_focus_id != s1 )
14842 v27 = *(const char **)v57;
14843 v47[1] = v27;
14844 sprintfex(a1, format_4E2DC8, v27);
14845 v66 = (unsigned __int8)byte_4F09B8[v26 * 4];
14846 if ( (signed int)ptr_507BC0->ptr_1C >= 63 )
14847 {
14848 if ( CheckHiredNPCSpeciality(8u) )
14849 v66 -= 2;
14850 if ( CheckHiredNPCSpeciality(9u) )
14851 v66 -= 3;
14852 v47[1] = (const char *)45;
14853 }
14854 else
14855 {
14856 v47[1] = (const char *)35;
14857 }
14858 if ( CheckHiredNPCSpeciality((unsigned int)v47[1]) )
14859 v66 -= 2;
14860 if ( CheckHiredNPCSpeciality(0x2Cu) )
14861 --v66;
14862 if ( v66 < 1 )
14863 v66 = 1;
14864 if ( v61 != (Player *)v2 )
14865 {
14866 memcpy(&v32, (char *)&pMapStats + 68 * (unsigned __int8)byte_4F09B0[v26 * 4], 0x44u);
14867 sprintfex(
14868 pTmpBuf,
14869 pGlobalTXT_LocalizationStrings[404],
14870 v66,
14871 *(int *)&v32,
14872 v33,
14873 v34,
14874 v35,
14875 v36,
14876 v37,
14877 v38,
14878 v39,
14879 v40,
14880 v41,
14881 v42,
14882 v43,
14883 v44,
14884 v45,
14885 v46,
14886 *(_QWORD *)v47);
14887 strcat(a1, pTmpBuf);
14888 v28 = a1;
14889 a1 += 100;
14890 ++v62;
14891 ++s1;
14892 strcat(v28, "\n \n");
14893 v24->uY = v63;
14894 v29 = pFontArrus->CalcTextHeight(pTmpBuf, &v53, 0, 0);
14895 v30 = v24->uY;
14896 v24->uHeight = v29;
14897 v2 = 255;
14898 v24->uW = v30 + v29 - 1;
14899 v63 += v54 + v29;
14900 }
14901 }
14902 else
14903 {
14904 v31 = a1;
14905 ++v62;
14906 ++s1;
14907 a1 += 100;
14908 strcpy(v31, nullstring);
14909 if ( v24 )
14910 {
14911 v24->uW = 0;
14912 v24->uHeight = 0;
14913 v24->uY = 0;
14914 }
14915 }
14916 ++v60;
14917 if ( (signed int)v60 >= v59->field_28 + v59->field_38 )
14918 break;
14919 v16 = v59;
14920 }
14921 if ( v63 != v55 )
14922 {
14923 v47[1] = &Dest;
14924 v47[0] = &v51;
14925 v46 = &v50;
14926 v45 = (unsigned int)&v49;
14927 v44 = &v48;
14928 v43 = pTmpBuf2;
14929 sprintfex(pTmpBuf, "%s\n \n%s%s%s%s%s", pTmpBuf2, &v48, &v49, &v50, &v51, &Dest);
14930 v53.DrawText2(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
14931 }
14932 else
14933 {
14934 LABEL_71:
14935 v47[1] = (const char *)3;
14936 v47[0] = pGlobalTXT_LocalizationStrings[561];
14937 v46 = *(char **)v57;
14938 v45 = (174 - pFontArrus->CalcTextHeight(pGlobalTXT_LocalizationStrings[561], &v53, 0, 0)) / 2 + 138;
14939 v53.DrawText2(pFontArrus, 0, v45, (unsigned __int16)v46, v47[0], (unsigned int)v47[1]);
14940 pAudioPlayer->StopChannels(-1, -1);
14941 }
14942 }
14943 }
14944 else
14945 {
14946 if ( dword_F8B19C > 104 && dword_F8B19C <= 108 )
14947 {
14948 if ( pParty->uNumGold < s1 )
14949 {
14950 ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
14951 HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, 3);
14952 if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
14953 return;
14954 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
14955 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
14956 goto LABEL_33;
14957 }
14958 Party::TakeGold(s1);
14959 v47[1] = (const char *)7;
14960 v5 = &byte_4F09B0[32 * (unsigned __int8)*(&byte_4F0CCF[4 * (unsigned int)ptr_507BC0->ptr_1C] + dword_F8B19C)];
14961 if ( v5[pParty->uDaysPlayed % 7 + 1] )
14962 {
14963 if ( _strcmpi(pCurrentMapName, pMapStats->pInfos[(unsigned __int8)*v5].pFilename) )
14964 {
14965 SaveGame(1, 0);
14966 strcpy(pCurrentMapName, pMapStats->pInfos[(unsigned __int8)*v5].pFilename);
14967 v8 = *((int *)v5 + 6);
14968 v9 = *((int *)v5 + 5);
14969 v10 = *((int *)v5 + 4);
14970 dword_6BE364_game_settings_1 |= 1u;
14971 _5B65B8_npcdata_hiword_house_or_other = 0;
14972 dword_5B65BC = 0;
14973 _5B65B4_npcdata_loword_house_or_other = v8;
14974 v11 = *((int *)v5 + 3);
14975 uGameState = 2;
14976 _5B65A8_npcdata_uflags_or_other = v11;
14977 _5B65AC_npcdata_fame_or_other = v10;
14978 _5B65B0_npcdata_rep_or_other = v9;
14979 dword_5B65C0 = v11 | v10 | v9 | v8;
14980 }
14981 else
14982 {
14983 v6 = *((int *)v5 + 3);
14984 pParty->sRotationX = 0;
14985 pParty->vPosition.x = v6;
14986 v7 = *((int *)v5 + 4);
14987 pIndoorCamera->sRotationY = 0;
14988 pParty->uFlags |= 2u;
14989 pParty->vPosition.z = v7;
14990 pParty->vPosition.y = *((int *)v5 + 5);
14991 pParty->uFallStartY = pParty->vPosition.y;
14992 pParty->sRotationY = *((int *)v5 + 6);
14993 }
14994 HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, 2);
14995 v12 = (unsigned __int8)v5[8];
14996 if ( (signed int)ptr_507BC0->ptr_1C >= 63 )
14997 {
14998 v63 = 72;
14999 v13 = 2500;
15000 if ( CheckHiredNPCSpeciality(8u) )
15001 v12 -= 2;
15002 if ( CheckHiredNPCSpeciality(9u) )
15003 v12 -= 3;
15004 v47[1] = (const char *)45;
15005 }
15006 else
15007 {
15008 v63 = 71;
15009 v13 = 1500;
15010 v47[1] = (const char *)35;
15011 }
15012 if ( CheckHiredNPCSpeciality((unsigned int)v47[1]) )
15013 v12 -= 2;
15014 if ( CheckHiredNPCSpeciality(0x2Cu) )
15015 --v12;
15016 if ( v12 < 1 )
15017 v12 = 1;
15018 RestAndHeal(1440 * v12);
15019 v61->PlaySound(v63, 0);
15020 v14 = GetTickCount();
15021 v15 = v14 + v13;
15022 if ( v15 < v14 )
15023 v15 = v14;
15024 while ( GetTickCount() < v15 )
15025 sqrt(3.1415926);
15026 while ( sub_4BD8B5() )
15027 ;
15028 if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
15029 {
15030 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
15031 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
15032 LABEL_33:
15033 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
15034 ++pMessageQueue_50CBD0->uNumMessages;
15035 return;
15036 }
15037 }
15038 else
15039 {
15040 dword_F8B19C = 1;
15041 pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
15042 }
15043 }
15044 }
15045 }
15046
15047
15048
15049
15050
15051 //----- (00405CFF) --------------------------------------------------------
15052 void stru262_TurnBased::End(unsigned int bPlaySound)
15053 {
15054 stru262_TurnBased *v2; // edi@1
15055 int v3; // ebx@1
15056 int v4; // esi@1
15057 unsigned __int8 v5; // zf@1
15058 unsigned __int8 v6; // sf@1
15059 TurnBased_QueueElem *v7; // ecx@2
15060 unsigned __int16 *pAttributes; // ecx@7
15061 size_t v9; // edx@7
15062 unsigned __int16 v10; // ax@8
15063 TurnBased_QueueElem *v11; // ebx@12
15064 ObjectType objType; // eax@13
15065 int objID; // esi@13
15066 int v14; // [sp+Ch] [bp-4h]@11
15067
15068 v2 = this;
15069 v3 = 0;
15070 v4 = 0;
15071 v5 = this->uActorQueueSize == 0;
15072 v6 = this->uActorQueueSize < 0;
15073 this->field_4 = 0;
15074 if ( !(v6 | v5) )
15075 {
15076 v7 = this->pQueue;
15077 do
15078 {
15079 if ( (v7->uPackedID & 7) == OBJECT_Actor )
15080 LOBYTE(pActors[v7->uPackedID >> 3].uAttributes) &= 0x7Fu;
15081 ++v4;
15082 ++v7;
15083 }
15084 while ( v4 < v2->uActorQueueSize );
15085 }
15086 if ( (signed int)uNumLayingItems > 0 )
15087 {
15088 pAttributes = &pLayingItems[0].uAttributes;
15089 v9 = uNumLayingItems;
15090 do
15091 {
15092 v10 = *pAttributes;
15093 if ( *pAttributes & 4 )
15094 {
15095 LOBYTE(v10) = v10 & 0xFB;
15096 *pAttributes = v10;
15097 }
15098 pAttributes += 56;
15099 --v9;
15100 }
15101 while ( v9 );
15102 }
15103 v14 = 0;
15104 if ( v2->uActorQueueSize > 0 )
15105 {
15106 v11 = v2->pQueue;
15107 do
15108 {
15109 objType = (ObjectType)(v11->uPackedID & 7);
15110 objID = v11->uPackedID >> 3;
15111 if ( objType == OBJECT_Player )
15112 {
15113 pPlayers[objID + 1]->uTimeToRecovery = (signed __int64)((double)v11->field_4 * 2.133333333333333);
15114 }
15115 else
15116 {
15117 if ( objType == OBJECT_Actor )
15118 pActors[objID].pMonsterInfo.uRecoveryTime = (signed __int64)((double)v11->field_4 * 2.133333333333333);
15119 }
15120 ++v14;
15121 ++v11;
15122 }
15123 while ( v14 < v2->uActorQueueSize );
15124 v3 = 0;
15125 }
15126 pAudioPlayer->StopChannels(-1, -1);
15127 if ( bPlaySound != v3 )
15128 pAudioPlayer->PlaySound((SoundID)(SOUND_GoldReceived|SOUND_EnteringAHouse), v3, v3, -1, v3, v3, v3, v3);
15129 pTurnEngine->field_18 &= 0xFFFFFFFDu;
15130 pEventTimer->StopGameTime();
15131 dword_50C994 = v3;
15132 dword_50C998_turnbased_icon_1A = v3;
15133 }
15134 // 50C994: using guessed type int dword_50C994;
15135 // 50C998: using guessed type int dword_50C998_turnbased_icon_1A;
15136
15137 //----- (00405E14) --------------------------------------------------------
15138 void stru262_TurnBased::_405E14()
15139 {
15140 stru262_TurnBased *v1; // esi@1
15141 int v2; // ecx@1
15142 SpellBuff *v3; // edi@2
15143 Actor *v4; // ebx@3
15144 signed int v5; // edx@20
15145 AIDirection *v6; // esi@21
15146 int v7; // eax@21
15147 int v8; // eax@21
15148 int v9; // eax@22
15149 int v10; // eax@23
15150 int v11; // eax@37
15151 int v12; // eax@44
15152 AIDirection a3; // [sp+4h] [bp-68h]@21
15153 AIDirection v14; // [sp+20h] [bp-4Ch]@21
15154 AIDirection v15; // [sp+3Ch] [bp-30h]@21
15155 SpellBuff *v16; // [sp+58h] [bp-14h]@2
15156 int v17; // [sp+5Ch] [bp-10h]@6
15157 stru262_TurnBased *v18; // [sp+60h] [bp-Ch]@1
15158 int v19; // [sp+64h] [bp-8h]@8
15159 unsigned int v20; // [sp+68h] [bp-4h]@1
15160
15161 v1 = this;
15162 v2 = 0;
15163 v18 = v1;
15164 v20 = 0;
15165 if ( (signed int)uNumActors > 0 )
15166 {
15167 v3 = pActors[0].pActorBuffs;
15168 v16 = pActors[0].pActorBuffs;
15169 do
15170 {
15171 v4 = (Actor *)((char *)&v3[-13] - 4);
15172 if ( SHIDWORD(v3[3].uExpireTime) < v2 || SHIDWORD(v3[3].uExpireTime) <= v2 && LODWORD(v3[3].uExpireTime) <= v2 )
15173 v17 = v2;
15174 else
15175 v17 = 1;
15176 v19 = v2;
15177 do
15178 {
15179 if ( v19 != 10 )
15180 {
15181 v3->_4585CA(pParty->uTimePlayed);
15182 v2 = 0;
15183 }
15184 ++v19;
15185 ++v3;
15186 }
15187 while ( v19 < 22 );
15188 if ( v17 != v2
15189 && SHIDWORD(v4->pActorBuffs[3].uExpireTime) <= v2
15190 && (SHIDWORD(v4->pActorBuffs[3].uExpireTime) < v2 || LODWORD(v4->pActorBuffs[3].uExpireTime) <= v2) )
15191 v4->uActorHeight = pMonsterList->pMonsters[v4->pMonsterInfo.uID - 1].uMonsterHeight;
15192 if ( !(v4->uAttributes & 0x80) )
15193 {
15194 if ( !v4->pActorBuffs[5].uExpireTime )
15195 {
15196 if ( !v4->pActorBuffs[6].uExpireTime )
15197 {
15198 v5 = v4->uCurrentActionLength;
15199 v4->uCurrentActionTime += pMiscTimer->uTimeElapsed;
15200 if ( (signed int)v4->uCurrentActionTime >= v5 )
15201 {
15202 v17 = dword_4F6E08[v20];
15203 v6 = Actor::GetDirectionInfo(8 * v20 | 3, v17, &a3, v2);
15204 v7 = v4->uAIState;
15205 memcpy(&v15, v6, sizeof(v15));
15206 v8 = v7 - 4;
15207 memcpy(&v14, &v15, sizeof(v14));
15208 if ( v8 )
15209 {
15210 v9 = v8 - 1;
15211 if ( v9 )
15212 {
15213 v10 = v9 - 6;
15214 if ( v10 )
15215 {
15216 if ( v10 != 8 )
15217 Actor::_403F58(v20, v17, 32, &v14);
15218 }
15219 }
15220 }
15221 else
15222 {
15223 v4->uCurrentActionTime = 0;
15224 v4->uCurrentActionLength = 0;
15225 v4->uAIState = 5;
15226 v4->UpdateAnimation();
15227 }
15228 v1 = v18;
15229 v2 = 0;
15230 }
15231 }
15232 }
15233 }
15234 ++v20;
15235 v3 = (SpellBuff *)((char *)v16 + 836);
15236 v16 = (SpellBuff *)((char *)v16 + 836);
15237 }
15238 while ( (signed int)v20 < (signed int)uNumActors );
15239 }
15240 if ( v1->field_4 == 1 )
15241 {
15242 v12 = v1->field_8;
15243 if ( v12 == 64 )
15244 {
15245 v1->_406A63();
15246 }
15247 else
15248 {
15249 if ( v12 > v2 )
15250 {
15251 v1->_406B9F();
15252 }
15253 else
15254 {
15255 v1->_406AFE();
15256 v1->field_10 = 100;
15257 }
15258 }
15259 v1->field_8 -= pEventTimer->uTimeElapsed;
15260 return;
15261 }
15262 if ( v1->field_4 == 2 )
15263 {
15264 if ( !(v1->field_18 & 1) )
15265 {
15266 v11 = v1->field_10;
15267 if ( v11 == 100 )
15268 {
15269 v1->StartTurn();
15270 LABEL_39:
15271 v1->_40652A();
15272 return;
15273 }
15274 if ( v11 > v2 || v1->pQueue[0].field_4 <= v2 )
15275 {
15276 v1->_4065B0();
15277 goto LABEL_39;
15278 }
15279 }
15280 v1->NextTurn();
15281 return;
15282 }
15283 if ( v1->field_4 == 3 )
15284 {
15285 if ( v1->uActionPointsLeft <= v2 || v1->field_18 & 8 )
15286 {
15287 v1->field_18 &= 0xFFFFFFF7u;
15288 v1->field_4 = 1;
15289 v1->field_8 = 64;
15290 }
15291 else
15292 {
15293 v1->_406FA8();
15294 }
15295 }
15296 }
15297
15298
15299
15300
15301 //----- (0043FDED) --------------------------------------------------------
15302 unsigned int __cdecl PrepareActorRenderList_BLV()
15303 {
15304 RenderBillboard *v0; // esi@0
15305 unsigned int result; // eax@1
15306 char *v2; // edi@2
15307 unsigned __int16 v3; // ax@3
15308 unsigned int v4; // eax@5
15309 unsigned __int16 v5; // cx@5
15310 int v6; // esi@5
15311 unsigned int v7; // eax@7
15312 int v8; // eax@10
15313 SpriteFrame *v9; // eax@16
15314 SpriteFrame *v10; // ebx@18
15315 int *v11; // eax@18
15316 int v12; // ecx@28
15317 Actor *v13; // ecx@35
15318 IndoorCameraD3D **v14; // eax@36
15319 double v15; // st7@36
15320 float v16; // eax@36
15321 double v17; // ST30_8@36
15322 signed __int64 v18; // qtt@36
15323 int v19; // ST5C_4@36
15324 signed __int64 v20; // qtt@37
15325 int v21; // ST5C_4@37
15326 signed __int16 v22; // cx@39
15327 int v23; // ST50_4@40
15328 signed int v24; // ecx@40
15329 int v25; // edx@44
15330 __int16 v26; // ax@44
15331 MonsterDesc *v27; // edx@44
15332 int v28; // ecx@44
15333 unsigned __int8 v29; // zf@44
15334 unsigned __int8 v30; // sf@44
15335 unsigned int v31; // [sp-8h] [bp-5Ch]@15
15336 int v32; // [sp+1Ch] [bp-38h]@5
15337 int a3; // [sp+20h] [bp-34h]@5
15338 int a2; // [sp+24h] [bp-30h]@5
15339 int a1a; // [sp+28h] [bp-2Ch]@5
15340 __int16 a5; // [sp+2Ch] [bp-28h]@5
15341 int a5a; // [sp+2Ch] [bp-28h]@36
15342 int a5b; // [sp+2Ch] [bp-28h]@40
15343 unsigned int v39; // [sp+30h] [bp-24h]@1
15344 int v40; // [sp+34h] [bp-20h]@2
15345 __int16 v41; // [sp+3Ch] [bp-18h]@18
15346 int a6; // [sp+40h] [bp-14h]@34
15347 int v43; // [sp+44h] [bp-10h]@34
15348 int z; // [sp+48h] [bp-Ch]@32
15349 signed int y; // [sp+4Ch] [bp-8h]@32
15350 int x; // [sp+50h] [bp-4h]@32
15351
15352 result = 0;
15353 v39 = 0;
15354 if ( (signed int)uNumActors > 0 )
15355 {
15356 v40 = 0;
15357 v2 = (char *)&pActors[0].uAttributes;
15358 while ( 1 )
15359 {
15360 v3 = *((_WORD *)v2 + 70);
15361 *(_DWORD *)v2 &= 0xFFFFFFF7u;
15362 if ( v3 != 11 )
15363 {
15364 if ( v3 != 19 )
15365 break;
15366 }
15367 LABEL_48:
15368 ++v39;
15369 v40 += 32;
15370 result = v39;
15371 v2 += 836;
15372 if ( (signed int)v39 >= (signed int)uNumActors )
15373 return result;
15374 }
15375 a5 = *((_WORD *)v2 + 61);
15376 a2 = *((_WORD *)v2 + 54);
15377 a1a = *((_WORD *)v2 + 53);
15378 a3 = *((_WORD *)v2 + 55);
15379 v4 = stru_5C6E00->Atan2(a1a - pBLVRenderParams->vPartyPos.x, a2 - pBLVRenderParams->vPartyPos.y);
15380 LOWORD(v0) = *((_WORD *)v2 + 59);
15381 v5 = *((_WORD *)v2 + 71);
15382 v6 = ((signed int)((char *)v0 + ((signed int)stru_5C6E00->uIntegerPi >> 3) - v4 + stru_5C6E00->uIntegerPi) >> 8) & 7;
15383 v32 = v6;
15384 if ( pParty->bTurnBasedModeOn )
15385 {
15386 if ( v5 == 1 )
15387 {
15388 v7 = pMiscTimer->uTotalGameTimeElapsed;
15389 goto LABEL_10;
15390 }
15391 }
15392 else
15393 {
15394 if ( v5 == 1 )
15395 {
15396 v7 = pBLVRenderParams->field_0_timer_;
15397 LABEL_10:
15398 v8 = v40 + v7;
15399 goto LABEL_12;
15400 }
15401 }
15402 v8 = *((_DWORD *)v2 + 37);
15403 LABEL_12:
15404 if ( *((_QWORD *)v2 + 32) > 0i64 || *((_QWORD *)v2 + 34) > 0i64 )
15405 v8 = 0;
15406 v31 = *(_WORD *)&v2[2 * (signed __int16)v5 + 152];
15407 if ( *((_WORD *)v2 + 70) == 16 )
15408 v9 = pSpriteFrameTable->GetFrameBy_x(v31, v8);
15409 else
15410 v9 = pSpriteFrameTable->GetFrame(v31, v8);
15411 v41 = 0;
15412 v10 = v9;
15413 v11 = (int *)v9->uFlags;
15414 if ( (unsigned __int8)v11 & 2 )
15415 v41 = 2;
15416 if ( (unsigned int)v11 & 0x40000 )
15417 v41 |= 0x40u;
15418 if ( (unsigned int)v11 & 0x20000 )
15419 LOBYTE(v41) = v41 | 0x80;
15420 v0 = (RenderBillboard *)(256 << v6);
15421 if ( (unsigned int)v0 & (unsigned int)v11 )
15422 v41 |= 4u;
15423 if ( v10->uGlowRadius )
15424 {
15425 LOBYTE(v11) = byte_4E94D3;
15426 pMobileLightsStack->AddLight(
15427 a1a,
15428 a2,
15429 a3,
15430 a5,
15431 v10->uGlowRadius,
15432 0xFFu,
15433 0xFFu,
15434 0xFFu,
15435 v11);
15436 }
15437 v12 = 0;
15438 if ( pStru170->field_53730 <= 0 )
15439 goto LABEL_48;
15440 while ( pStru170->pSectorIDs_toDrawDecorationsFrom[v12] != *((_WORD *)v2 + 61) )
15441 {
15442 ++v12;
15443 if ( v12 >= pStru170->field_53730 )
15444 goto LABEL_48;
15445 }
15446 if ( !pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible(a1a, a2, a3, &x, &y, &z, 1)
15447 || (v0 = (RenderBillboard *)abs(x), (signed int)v0 < abs(y)) )
15448 goto LABEL_48;
15449 pGame->pIndoorCameraD3D->Project(x, y, z, &v43, &a6);
15450 result = uNumBillboardsToDraw;
15451 v0 = &pBillboardRenderList[uNumBillboardsToDraw];
15452 if ( (signed int)uNumBillboardsToDraw >= 500 )
15453 return result;
15454 ++uNumBillboardsToDraw;
15455 ++uNumSpritesDrawnThisFrame;
15456 v13 = (Actor *)(v2 - 36);
15457 *(_DWORD *)v2 |= 8u;
15458 v29 = pRenderer->pRenderD3D == 0;
15459 v0->uHwSpriteID = v10->pHwSpriteIDs[v32];
15460 v0->uPalette = v10->uPaletteIndex;
15461 v0->uIndoorSectorID = a5;
15462 if ( v29 )
15463 {
15464 LODWORD(v20) = pBLVRenderParams->field_40 << 16;
15465 HIDWORD(v20) = pBLVRenderParams->field_40 >> 16;
15466 v21 = v20 / x;
15467 v0->field_0 = (unsigned __int64)(v10->scale * v20 / x) >> 16;
15468 a5a = (unsigned __int64)(v10->scale * (signed __int64)v21) >> 16;
15469 }
15470 else
15471 {
15472 v14 = &pGame->pIndoorCameraD3D;
15473 v0->flt_8 = pGame->pIndoorCameraD3D->flt_D0;
15474 v15 = (*v14)->flt_D4;
15475 v16 = v0->flt_8;
15476 v0->flt_C = v15;
15477 v17 = v16 + 6.7553994e15;
15478 LODWORD(v18) = 0;
15479 HIDWORD(v18) = SLOWORD(v17);
15480 v19 = v18 / x;
15481 v0->field_0 = (unsigned __int64)(v10->scale * v18 / x) >> 16;
15482 a5a = (unsigned __int64)(v10->scale * (signed __int64)v19) >> 16;
15483 }
15484 v0->field_4 = a5a;
15485 if ( (signed __int64)v13->pActorBuffs[3].uExpireTime <= 0 )
15486 {
15487 if ( (signed __int64)v13->pActorBuffs[10].uExpireTime > 0 )
15488 {
15489 a5b = (unsigned __int64)(pGame->pStru6Instance->_4A806F((Actor *)(v2 - 36)) * (signed __int64)v0->field_4) >> 16;
15490 goto LABEL_43;
15491 }
15492 }
15493 else
15494 {
15495 v22 = v13->pActorBuffs[3].uPower;
15496 if ( v22 )
15497 {
15498 v23 = (unsigned __int64)(65536 / (unsigned __int16)v22 * (signed __int64)v0->field_0) >> 16;
15499 v24 = *((_WORD *)v2 + 116);
15500 v0->field_0 = v23;
15501 a5b = (unsigned __int64)(65536 / v24 * (signed __int64)v0->field_4) >> 16;
15502 LABEL_43:
15503 v0->field_4 = a5b;
15504 goto LABEL_44;
15505 }
15506 }
15507 LABEL_44:
15508 HIWORD(v25) = HIWORD(x);
15509 v0->field_20 = a1a;
15510 v0->field_22 = a2;
15511 v0->field_24 = a3;
15512 v0->field_26 = v43;
15513 v0->field_28 = a6;
15514 LOWORD(v25) = 0;
15515 LOBYTE(v26) = v41;
15516 v0->sZValue = v25 + (8 * v39 | 3);
15517 v27 = pMonsterList->pMonsters;
15518 v28 = *((_WORD *)v2 + 30);
15519 v29 = *((_DWORD *)v2 + 65) == 0;
15520 v30 = *((_DWORD *)v2 + 65) < 0;
15521 v0->field_1E = v41;
15522 v0->pSpriteFrame = v10;
15523 v0->field_2C_prolly_tint = *((_DWORD *)&v27[v28] - 36);
15524 if ( !v30 && (!(v30 | v29) || *((_DWORD *)v2 + 64)) )
15525 {
15526 HIBYTE(v26) = HIBYTE(v41) | 1;
15527 v0->field_1E = v26;
15528 }
15529 goto LABEL_48;
15530 }
15531 return result;
15532 }
15533
15534
15535
15536
15537
15538 //----- (00444732) --------------------------------------------------------
15539 char *_444732_GetEventHintString(unsigned int uEventID)
15540 {
15541 signed int v1; // edx@1
15542 char *v2; // eax@2
15543 int v3; // ebx@4
15544 int v4; // esi@4
15545 char *result; // eax@6
15546 int v6; // eax@9
15547 char *i; // esi@11
15548 int v8; // edx@12
15549
15550 v1 = 0;
15551 if ( (signed int)uLevelEVT_NumEvents <= 0 )
15552 {
15553 LABEL_6:
15554 result = 0;
15555 }
15556 else
15557 {
15558 v2 = (char *)&pLevelEVT_Events[0].uEventOffsetInEVT;
15559 while ( 1 )
15560 {
15561 if ( *((int *)v2 - 2) == uEventID )
15562 {
15563 v3 = *(int *)v2;
15564 v4 = *((int *)v2 + 3);
15565 if ( pLevelEVT[*(int *)v2 + 4] == 4 )
15566 break;
15567 }
15568 ++v1;
15569 v2 += 12;
15570 if ( v1 >= (signed int)uLevelEVT_NumEvents )
15571 goto LABEL_6;
15572 }
15573 if ( pLevelEVT[v4 + 4] == 2 )
15574 {
15575 v6 = (unsigned __int8)pLevelEVT[v4 + 5]
15576 + (((unsigned __int8)pLevelEVT[v4 + 6]
15577 + (((unsigned __int8)pLevelEVT[v4 + 7] + ((unsigned __int8)pLevelEVT[v4 + 8] << 8)) << 8)) << 8);
15578 LABEL_10:
15579 //result = (char *)p2DEvents_minus1_::04[13 * v6];
15580 result = (char *)p2DEvents[v6 - 1].pName;
15581 }
15582 else
15583 {
15584 for ( i = (char *)pLevelEVT_Events + 4 * (3 * v1 + 3); *(int *)i == uEventID; i += 12 )
15585 {
15586 v8 = *((int *)i + 2);
15587 if ( pLevelEVT[v8 + 4] == 2 )
15588 {
15589 v6 = (unsigned __int8)pLevelEVT[v8 + 5]
15590 + (((unsigned __int8)pLevelEVT[v8 + 6]
15591 + (((unsigned __int8)pLevelEVT[v8 + 7] + ((unsigned __int8)pLevelEVT[v8 + 8] << 8)) << 8)) << 8);
15592 if ( (unsigned int)v6 < 0x258 )
15593 goto LABEL_10;
15594 }
15595 }
15596 result = &pLevelStr[pLevelStrOffsets[(unsigned __int8)pLevelEVT[v3 + 5]]];
15597 }
15598 }
15599 return result;
15600 }
15601
15602
15603
15604
15605 //----- (00444839) --------------------------------------------------------
15606 unsigned int __fastcall sub_444839_move_map(unsigned int a1, int a2, int x, int y, int z, int directiony, int directionx, int a8, const char *pLocationName)
15607 {
15608 unsigned int v9; // ebx@1
15609 int v10; // edi@1
15610 signed int v11; // eax@1
15611 unsigned int v12; // eax@6
15612 const char *v13; // ST0C_4@6
15613 unsigned int v14; // eax@8
15614 const char *v15; // eax@14
15615 unsigned int v16; // eax@16
15616 unsigned int result; // eax@26
15617 const char *v18; // [sp-8h] [bp-40h]@9
15618 const char *v19; // [sp-4h] [bp-3Ch]@2
15619 char *v20; // [sp-4h] [bp-3Ch]@9
15620 const char *v21; // [sp-4h] [bp-3Ch]@11
15621 char pContainer[40]; // [sp+Ch] [bp-2Ch]@1
15622 unsigned int v23; // [sp+34h] [bp-4h]@1
15623
15624 v9 = a1;
15625 v10 = a2;
15626 v23 = IndoorLocation::GetLocationIndex(pLocationName);
15627 dword_59117C_teleportx = x;
15628 dword_591178_teleporty = y;
15629 dword_591174_teleportz = z;
15630 dword_591170_teleport_directiony = directiony;
15631 dword_59116C_teleport_directionx = directionx;
15632 dword_591168_teleport_speedz = a8;
15633 dword_591164_teleport_map_name = (char *)pLocationName;
15634 uCurrentHouse_Animation = v9;
15635 pEventTimer->Pause();
15636 pAudioPlayer->StopChannels(-1, -1);
15637 v11 = const_2();
15638 sprintfex(pContainer, "evt%02d", v11);
15639 if ( pParty->uAlignment )
15640 {
15641 if ( pParty->uAlignment != 2 )
15642 goto LABEL_6;
15643 v19 = "-c";
15644 }
15645 else
15646 {
15647 v19 = "-b";
15648 }
15649 strcat(pContainer, v19);
15650 LABEL_6:
15651 v12 = pIcons_LOD->LoadTexture(pContainer, TEXTURE_16BIT_PALETTE);
15652 v13 = pHouse_ExitPictures[v10];
15653 pTexture_Dialogue_Background = &pIcons_LOD->pTextures[v12];
15654 pTexture_outside = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture(v13, TEXTURE_16BIT_PALETTE)];
15655 if ( v9 )
15656 {
15657 if ( !v23 )
15658 //pVideoPlayer->_4BF28F(pAnimatedRooms[p2DEvents_minus1___02[26 * v9]].field_0, 1u);
15659 pVideoPlayer->_4BF28F(pAnimatedRooms[p2DEvents[v9 - 1].uAnimationID].field_0, 1u);
15660 }
15661 else
15662 {
15663 if ( !v23 )
15664 {
15665 v14 = pMapStats->GetMapInfo(pCurrentMapName);
15666 if ( v14 )
15667 {
15668 v20 = pMapStats->pInfos[v14].pName;
15669 v18 = pGlobalTXT_LocalizationStrings[410];
15670 LABEL_10:
15671 sprintfex(byte_591098, v18, v20);
15672 goto LABEL_20;
15673 }
15674 v21 = pGlobalTXT_LocalizationStrings[79];
15675 goto LABEL_19;
15676 }
15677 }
15678 v15 = pLocationName;
15679 if ( *pLocationName == 48 )
15680 v15 = pCurrentMapName;
15681 v16 = pMapStats->GetMapInfo(v15);
15682 if ( v16 )
15683 {
15684 v20 = pMapStats->pInfos[v16].pName;
15685 v18 = pGlobalTXT_LocalizationStrings[411];
15686 goto LABEL_10;
15687 }
15688 v21 = pGlobalTXT_LocalizationStrings[73];
15689 LABEL_19:
15690 strcpy(byte_591098, v21);
15691 LABEL_20:
15692 pDialogueWindow = GUIWindow::Create(0, 0, 0x280u, 0x1E0u, (enum WindowType)26, 0, (int)byte_591098);
15693 //if ( BYTE1(pAnimatedRooms[p2DEvents_minus1___02[26 * v9]].field_C) )
15694 if ( BYTE1(pAnimatedRooms[p2DEvents[v9 - 1].uAnimationID].field_C) )
15695 HousePlaySomeSound(v9, 1);
15696 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor && uActiveCharacter && pParty->uFlags & 0x30 )
15697 pPlayers[uActiveCharacter]->PlaySound(47, 0);
15698 result = v23;
15699 if ( v23 )
15700 uCurrentHouse_Animation = v23;
15701 return result;
15702 }
15703
15704
15705 //----- (0044606A) --------------------------------------------------------
15706 int __fastcall PrepareHouse(unsigned int uHouseID)
15707 {
15708 unsigned int v1; // ebx@1
15709 signed int v2; // esi@1
15710 int uExitPic; // edi@1
15711 __int16 uExitMapID; // ax@2
15712 int result; // eax@5
15713 unsigned int *v6; // ecx@8
15714 int v7; // ebx@11
15715 int v8; // esi@16
15716 unsigned int v9; // eax@16
15717 unsigned int v10; // eax@19
15718 int v11; // ecx@19
15719 char pContainer[36]; // [sp+Ch] [bp-54h]@16
15720 int v13; // [sp+30h] [bp-30h]@11
15721 int Dst[6]; // [sp+34h] [bp-2Ch]@1
15722 unsigned int v15; // [sp+4Ch] [bp-14h]@1
15723 int uAnimationID; // [sp+50h] [bp-10h]@1
15724 unsigned int *v17; // [sp+54h] [bp-Ch]@3
15725 unsigned int v18; // [sp+58h] [bp-8h]@1
15726 int v19; // [sp+5Ch] [bp-4h]@7
15727
15728 v15 = uHouseID;
15729 v1 = 52 * uHouseID;
15730 //uAnimationID = p2DEvents_minus1___02[26 * uHouseID];
15731 uAnimationID = p2DEvents[uHouseID - 1].uAnimationID;
15732 v2 = 0;
15733 v18 = 52 * uHouseID;
15734 memset(Dst, 0, 0x18u);
15735 //uExitPic = *(__int16 *)((char *)p2DEvents_minus1_::2C + v1);
15736 uExitPic = p2DEvents[uHouseID - 1].uExitPicID;
15737 uNumDialogueNPCPortraits = 0;
15738 uHouse_ExitPic = uExitPic;
15739 if ( uExitPic )
15740 {
15741 //uExitMapID = *(__int16 *)((char *)p2DEvents_minus1_::30 + v1);
15742 uExitMapID = p2DEvents[uHouseID - 1]._quest_related;
15743 if ( uExitMapID > 0 )
15744 {
15745 v17 = (unsigned int *)(uExitMapID - 1);
15746 if ( !((unsigned __int8)(0x80u >> (signed int)v17 % 8) & pParty->_award_bits[(uExitMapID - 1) >> 3]) )
15747 {
15748 uExitPic = 0;
15749 uHouse_ExitPic = 0;
15750 }
15751 }
15752 }
15753 dword_591080 = pAnimatedRooms[uAnimationID].field_8;
15754 result = dword_591080;
15755 if ( dword_591080 )
15756 {
15757 v2 = 1;
15758 Dst[0] = dword_591080;
15759 uNumDialogueNPCPortraits = 1;
15760 }
15761 v19 = 1;
15762 if ( (signed int)pNPCStats->uNumNewNPCs > 1 )
15763 {
15764 v6 = &pNPCStats->pNewNPCData[1].uFlags;
15765 v17 = &pNPCStats->pNewNPCData[1].uFlags;
15766 do
15767 {
15768 if ( v6[3] == v15 )
15769 {
15770 if ( !(*(char *)v6 & 0x80) )
15771 {
15772 v7 = v2++ - (result != 0);
15773 array_5913D8[v7] = (NPCData *)(v6 - 2);
15774 v6 = v17;
15775 *(&v13 + v2) = *(v17 - 1);
15776 v1 = v18;
15777 if ( (*v6 & 3) != 2 )
15778 ++*v6;
15779 }
15780 }
15781 ++v19;
15782 v6 += 19;
15783 v17 = v6;
15784 }
15785 while ( v19 < (signed int)pNPCStats->uNumNewNPCs );
15786 uNumDialogueNPCPortraits = v2;
15787 }
15788 v19 = 0;
15789 if ( v2 > 0 )
15790 {
15791 do
15792 {
15793 v8 = v19;
15794 sprintfex(pContainer, "npc%03u", Dst[v19]);
15795 v9 = pIcons_LOD->LoadTexture(pContainer, TEXTURE_16BIT_PALETTE);
15796 ++v19;
15797 pDialogueNPCPortraits[v8] = &pIcons_LOD->pTextures[v9];
15798 result = v19;
15799 }
15800 while ( v19 < uNumDialogueNPCPortraits );
15801 uExitPic = uHouse_ExitPic;
15802 }
15803 if ( uExitPic )
15804 {
15805 v10 = pIcons_LOD->LoadTexture(pHouse_ExitPictures[uExitPic], TEXTURE_16BIT_PALETTE);
15806 v11 = uNumDialogueNPCPortraits++;
15807 pDialogueNPCPortraits[v11] = &pIcons_LOD->pTextures[v10];
15808 //result = *(__int16 *)((char *)p2DEvents_minus1_::2E + v1);
15809 result = p2DEvents[uHouseID - 1].uExitMapID;
15810 uHouse_ExitPic = result;
15811 }
15812 return result;
15813 }
15814
15815
15816
15817
15818
15819 //----- (0044622E) --------------------------------------------------------
15820 bool __fastcall EnterHouse(enum HOUSE_TYPE uHouseID)
15821 {
15822 enum HOUSE_TYPE v1; // edi@1
15823 int v2; // edi@5
15824 unsigned int uOpenTime; // eax@5
15825 int uCloseTime; // esi@5
15826 unsigned int v5; // esi@5
15827 int v6; // edx@5
15828 signed int v7; // ecx@10
15829 signed int v8; // eax@10
15830 int v9; // esi@10
15831 unsigned int v10; // esi@16
15832 int v11; // ecx@17
15833 unsigned int v12; // kr00_4@25
15834 void *v13; // esi@25
15835 int v14; // eax@25
15836 Player *v15; // esi@27
15837 signed int v16; // eax@32
15838 unsigned int v17; // eax@37
15839 signed int v18; // edi@37
15840 signed int v19; // edi@41
15841 unsigned int v20; // ecx@41
15842 const char *v22; // [sp-4h] [bp-40h]@33
15843 char pContainer[40]; // [sp+Ch] [bp-30h]@32
15844 unsigned int v24; // [sp+34h] [bp-8h]@5
15845 enum HOUSE_TYPE v25; // [sp+38h] [bp-4h]@1
15846
15847 v1 = uHouseID;
15848 v25 = uHouseID;
15849 GameUI_StatusBar_TimedString[0] = 0;
15850 pStatusBarString[0] = 0;
15851 ShowStatusBarString(nullstring, 2u);
15852 if ( pMessageQueue_50CBD0->uNumMessages )
15853 pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
15854 viewparams->bRedrawGameUI = 1;
15855 uDialogueType = 0;
15856 pKeyActionMap->_459ED1(3);
15857 pKeyActionMap->ResetKeys();
15858 if ( v1 == 600 || v1 == 601 )
15859 {
15860 GameOverMenu(0);
15861 return 0;
15862 }
15863 v2 = 26 * v1;
15864 //uOpenTime = p2DEvents_minus1_::uOpenTime[v2];
15865 uOpenTime = p2DEvents[v1 - 1].uOpenTime;
15866 //uCloseTime = p2DEvents_minus1_::uCloseTime[v2];
15867 uCloseTime = p2DEvents[v1 - 1].uCloseTime;
15868 ptr_F8B1E8 = 0;
15869 v24 = uOpenTime;
15870 v5 = uCloseTime - 1;
15871 dword_F8B1E4 = 0;
15872 dword_F8B1F4 = 0;
15873 memset(byte_F8B1F0, 0, 4u);
15874 memset(byte_F8B148, 0, 0x10u);
15875 pRenderer->ClearZBuffer(0, 479);
15876 v6 = v24;
15877 if ( (signed int)v5 <= (signed int)v24 )
15878 {
15879 if ( pParty->uCurrentHour >= v24 )
15880 goto LABEL_16;
15881 }
15882 else
15883 {
15884 if ( pParty->uCurrentHour < v24 )
15885 {
15886 LABEL_10:
15887 v7 = 0;
15888 v8 = 0;
15889 v9 = v5 + 1;
15890 if ( (signed int)v24 > 12 )
15891 {
15892 v6 = v24 - 12;
15893 v7 = 1;
15894 }
15895 if ( v9 > 12 )
15896 {
15897 v9 -= 12;
15898 v8 = 1;
15899 }
15900 sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[414], v6, aAMPMNames[v7], v9, aAMPMNames[v8]);
15901 ShowStatusBarString(pTmpBuf, 2u);
15902 if ( uActiveCharacter )
15903 pPlayers[uActiveCharacter]->PlaySound(3, 0);
15904 return 0;
15905 }
15906 }
15907 if ( pParty->uCurrentHour > v5 )
15908 goto LABEL_10;
15909 LABEL_16:
15910 v10 = v25;
15911 if ( (signed int)v25 >= 53 )
15912 goto LABEL_21;
15913 v11 = pParty->field_3C._shop_ban_times[2 * v25 + 1];
15914 if ( !(v11 | pParty->field_3C._shop_ban_times[2 * v25])
15915 || (signed __int64)__PAIR__(v11, pParty->field_3C._shop_ban_times[2 * v25]) <= (signed __int64)pParty->uTimePlayed )
15916 {
15917 pParty->field_3C._shop_ban_times[2 * v25] = 0;
15918 pParty->field_3C._shop_ban_times[2 * v10 + 1] = 0;
15919 LABEL_21:
15920 if ( !dword_597F18 )
15921 pAudioPlayer->StopChannels(-1, -1);
15922 //uCurrentHouse_Animation = p2DEvents_minus1___02[v2];
15923 uCurrentHouse_Animation = p2DEvents[v2 / sizeof(_2devent) - 1].uAnimationID;
15924 dword_F8B198 = LOBYTE(pAnimatedRooms[uCurrentHouse_Animation].field_C);
15925 if ( dword_F8B198 == 20 && pParty->uFine )
15926 {
15927 uCurrentHouse_Animation = (signed __int16)p2DEvents[186].uAnimationID;
15928 v25 = (HOUSE_TYPE)187;
15929 v12 = LODWORD(pParty->uTimePlayed);
15930 LODWORD(pParty->uTimePlayed) += 0x7620000u;
15931 v13 = &pParty->pPlayers[0].uNumDivineInterventionCastsThisDay;
15932 v14 = LOBYTE(pAnimatedRooms[(signed __int16)p2DEvents[186].uAnimationID].field_C);
15933 pParty->uTimePlayed = __PAIR__(HIDWORD(pParty->uTimePlayed), v12) + 0x7620000;
15934 dword_F8B198 = v14;
15935 do
15936 {
15937 *((short *)v13 - 258) = 0;
15938 memset(v13, 0, 4u);
15939 v13 = (char *)v13 + 6972;
15940 }
15941 while ( (signed int)v13 < (signed int)&pParty->field_871C[694] );
15942 ++pParty->uNumPrisonTerms;
15943 pParty->uFine = 0;
15944 v15 = pParty->pPlayers;
15945 do
15946 {
15947 v15->SetVariable(VAR_Award, 87);
15948 ++v15;
15949 }
15950 while ( (signed int)v15 < (signed int)pParty->pHirelings );
15951 v10 = v25;
15952 }
15953 ++pIcons_LOD->uTexturePacksCount;
15954 if ( !pIcons_LOD->uNumPrevLoadedFiles )
15955 pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
15956 v16 = const_2();
15957 sprintfex(pContainer, "evt%02d", v16);
15958 if ( pParty->uAlignment )
15959 {
15960 if ( pParty->uAlignment != 2 )
15961 goto LABEL_37;
15962 v22 = "-c";
15963 }
15964 else
15965 {
15966 v22 = "-b";
15967 }
15968 strcat(pContainer, v22);
15969 LABEL_37:
15970 v17 = pIcons_LOD->LoadTexture(pContainer, TEXTURE_16BIT_PALETTE);
15971 array_5913D8[6] = 0;
15972 pTexture_Dialogue_Background = &pIcons_LOD->pTextures[v17];
15973 uTextureID_507B04 = uTextureID_right_panel;
15974 PrepareHouse(v10);
15975 v18 = 1;
15976 uTextureID_507B04 = uTextureID_right_panel;
15977 if ( uNumDialogueNPCPortraits == 1 )
15978 array_5913D8[6] = (NPCData *)1;
15979 pVideoPlayer->_4BF28F(pAnimatedRooms[uCurrentHouse_Animation].field_0, 1u);
15980 if ( (signed int)v10 < 139 || (signed int)v10 > 172 )
15981 {
15982 if ( (signed int)v10 >= 54 && (signed int)v10 <= 73 && !sub_4B68EA(v10 - 54) )
15983 goto LABEL_49;
15984 v20 = v10;
15985 }
15986 else
15987 {
15988 v19 = word_4F0704[2 * v10] - 1;
15989 v20 = v10;
15990 if ( !((unsigned __int8)(0x80u >> v19 % 8) & pPlayers[uActiveCharacter]->field_152[v19 >> 3]) )
15991 {
15992 HousePlaySomeSound(v10, 3);
15993 v18 = 1;
15994 LABEL_49:
15995 dword_5C35D4 = v18;
15996 return v18;
15997 }
15998 v18 = 1;
15999 }
16000 HousePlaySomeSound(v20, v18);
16001 goto LABEL_49;
16002 }
16003 ShowStatusBarString(pGlobalTXT_LocalizationStrings[191], 2u);// "You've been banned from this shop!"
16004 return 0;
16005 }