comparison TurnEngine.cpp @ 1448:5a5d0c713d47

some turn engine renaming
author Gloval
date Tue, 06 Aug 2013 00:52:46 +0400
parents e33188605eeb
children 8ff3c675a726
comparison
equal deleted inserted replaced
1369:6b4a1c44a56f 1448:5a5d0c713d47
42 { 42 {
43 pActors[p_id].uAttributes |= 0x80u; 43 pActors[p_id].uAttributes |= 0x80u;
44 if ( !pActors[p_id].CanAct() ) 44 if ( !pActors[p_id].CanAct() )
45 { 45 {
46 --active_actors; 46 --active_actors;
47 pQueue[i].field_4 = 1001; 47 pQueue[i].actor_initiative = 1001;
48 pActors[p_id].uAttributes &= ~0x80; 48 pActors[p_id].uAttributes &= ~0x80;
49 } 49 }
50 } 50 }
51 else if ( p_type == OBJECT_Player) 51 else if ( p_type == OBJECT_Player)
52 { 52 {
53 if ( !pParty->pPlayers[p_id].CanAct() ) 53 if ( !pParty->pPlayers[p_id].CanAct() )
54 { 54 {
55 --active_actors; 55 --active_actors;
56 pQueue[i].field_4 = 1001; 56 pQueue[i].actor_initiative = 1001;
57 } 57 }
58 } 58 }
59 } 59 }
60 //sort 60 //sort
61 if (uActorQueueSize>0) 61 if (uActorQueueSize>0)
64 { 64 {
65 v7=&pQueue[i]; 65 v7=&pQueue[i];
66 for(j=i+1; j<uActorQueueSize;++j ) 66 for(j=i+1; j<uActorQueueSize;++j )
67 { 67 {
68 v8=&pQueue[j]; 68 v8=&pQueue[j];
69 if ( v8->field_4 < v7->field_4 || 69 if ( v8->actor_initiative < v7->actor_initiative ||
70 ((v8->field_4 == v7->field_4) && 70 ((v8->actor_initiative == v7->actor_initiative) &&
71 ( 71 (
72 ((PID_TYPE(v8->uPackedID) == OBJECT_Player) && (PID_TYPE(v7->uPackedID) == OBJECT_Actor)) || 72 ((PID_TYPE(v8->uPackedID) == OBJECT_Player) && (PID_TYPE(v7->uPackedID) == OBJECT_Actor)) ||
73 ((PID_TYPE(v8->uPackedID) == PID_TYPE(v7->uPackedID)) && (PID_ID(v8->uPackedID) < PID_ID(v7->uPackedID))) 73 ((PID_TYPE(v8->uPackedID) == PID_TYPE(v7->uPackedID)) && (PID_ID(v8->uPackedID) < PID_ID(v7->uPackedID)))
74 ) 74 )
75 ) 75 )
94 field_18 &= ~TE_PLAYER_TURN; 94 field_18 &= ~TE_PLAYER_TURN;
95 } 95 }
96 for(i=0; i<uActorQueueSize; ++i) 96 for(i=0; i<uActorQueueSize; ++i)
97 { 97 {
98 if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) 98 if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player)
99 pParty->pPlayers[PID_ID(pQueue[i].uPackedID)].uTimeToRecovery = (signed __int64)((double)pQueue[i].field_4 * 0.46875); 99 pParty->pPlayers[PID_ID(pQueue[i].uPackedID)].uTimeToRecovery = (signed __int64)((double)pQueue[i].actor_initiative * 0.46875);
100 } 100 }
101 101
102 102
103 } 103 }
104 104
105 //----- (0040471C) -------------------------------------------------------- 105 //----- (0040471C) --------------------------------------------------------
106 void stru262_TurnBased::_40471C() 106 void stru262_TurnBased::ApplyPlayerAction()
107 { 107 {
108 if ( pParty->bTurnBasedModeOn == 1 ) 108 if ( pParty->bTurnBasedModeOn == 1 )
109 { 109 {
110 if ( pTurnEngine->turn_stage == 2 ) 110 if ( pTurnEngine->turn_stage == 2 )
111 _406457(0); 111 _406457(0);
139 pAudioPlayer->PlaySound(SOUND_207, 0, 0, -1, 0, 0, 0, 0); 139 pAudioPlayer->PlaySound(SOUND_207, 0, 0, -1, 0, 0, 0, 0);
140 pPlayer = pParty->pPlayers; 140 pPlayer = pParty->pPlayers;
141 dword_50C998_turnbased_icon_1A = 8 * pIconsFrameTable->pIcons[uIconID_TurnStart].uAnimLength; 141 dword_50C998_turnbased_icon_1A = 8 * pIconsFrameTable->pIcons[uIconID_TurnStart].uAnimLength;
142 dword_50C994 = 0; 142 dword_50C994 = 0;
143 143
144 this->field_10 = 100; 144 this->turn_initiative = 100;
145 this->field_0 = 0; 145 this->turns_count = 0;
146 this->field_8 = 64; 146 this->ai_turn_timer = 64;
147 this->turn_stage = 1; 147 this->turn_stage = 1;
148 this->uActorQueueSize = 0; 148 this->uActorQueueSize = 0;
149 149
150 for ( v3 = 0; v3 < 4 ; ++v3 ) 150 for ( v3 = 0; v3 < 4 ; ++v3 )
151 { 151 {
189 { 189 {
190 if ( pPlayers[PID_ID(this->pQueue[v40b].uPackedID) + 1]->uTimeToRecovery != 0 ) 190 if ( pPlayers[PID_ID(this->pQueue[v40b].uPackedID) + 1]->uTimeToRecovery != 0 )
191 { 191 {
192 //v33 = pPlayers[(this->pQueue[0].uPackedID >> 3) + 1]->uTimeToRecovery; 192 //v33 = pPlayers[(this->pQueue[0].uPackedID >> 3) + 1]->uTimeToRecovery;
193 v16 = (signed int)((double)pPlayers[PID_ID(this->pQueue[v40b].uPackedID) + 1]->uTimeToRecovery * 0.46875); 193 v16 = (signed int)((double)pPlayers[PID_ID(this->pQueue[v40b].uPackedID) + 1]->uTimeToRecovery * 0.46875);
194 this->pQueue[v40b].field_4 = v16; 194 this->pQueue[v40b].actor_initiative = v16;
195 } 195 }
196 else 196 else
197 { 197 {
198 activ_players[a_players_count] = v40b; 198 activ_players[a_players_count] = v40b;
199 ++a_players_count; 199 ++a_players_count;
201 } 201 }
202 else if ( PID_TYPE(this->pQueue[v40b].uPackedID) == OBJECT_Actor ) 202 else if ( PID_TYPE(this->pQueue[v40b].uPackedID) == OBJECT_Actor )
203 { 203 {
204 v17 = rand() % 99; 204 v17 = rand() % 99;
205 if ( v17 < 33 ) 205 if ( v17 < 33 )
206 this->pQueue[v40b].field_4 = 1; 206 this->pQueue[v40b].actor_initiative = 1;
207 else 207 else
208 this->pQueue[v40b].field_4= (v17 >= 66)? 5 : 3; 208 this->pQueue[v40b].actor_initiative= (v17 >= 66)? 5 : 3;
209 } 209 }
210 else 210 else
211 { 211 {
212 this->pQueue[v40b].field_4 = 666; 212 this->pQueue[v40b].actor_initiative = 666;
213 } 213 }
214 this->pQueue[v40b].field_4 += 16; 214 this->pQueue[v40b].actor_initiative += 16;
215 } 215 }
216 216
217 if ( a_players_count > 0 ) 217 if ( a_players_count > 0 )
218 { 218 {
219 for (i=0; i<a_players_count; ++i) 219 for (i=0; i<a_players_count; ++i)
236 } 236 }
237 } 237 }
238 238
239 for (i=0; i<a_players_count; ++i) 239 for (i=0; i<a_players_count; ++i)
240 { 240 {
241 this->pQueue[activ_players[i]].field_4 = i+2; 241 this->pQueue[activ_players[i]].actor_initiative = i+2;
242 } 242 }
243 } 243 }
244 this->SortTurnQueue(); 244 this->SortTurnQueue();
245 } 245 }
246 246
272 { 272 {
273 objType = (ObjectType)PID_TYPE(pQueue[i].uPackedID); 273 objType = (ObjectType)PID_TYPE(pQueue[i].uPackedID);
274 objID = PID_ID(pQueue[i].uPackedID); 274 objID = PID_ID(pQueue[i].uPackedID);
275 if ( objType == OBJECT_Player ) 275 if ( objType == OBJECT_Player )
276 { 276 {
277 pPlayers[objID + 1]->uTimeToRecovery = (signed __int64)((double)pQueue[i].field_4 * 2.133333333333333); 277 pPlayers[objID + 1]->uTimeToRecovery = (signed __int64)((double)pQueue[i].actor_initiative * 2.133333333333333);
278 } 278 }
279 else if ( objType == OBJECT_Actor ) 279 else if ( objType == OBJECT_Actor )
280 { 280 {
281 pActors[objID].pMonsterInfo.uRecoveryTime = (signed __int64)((double)pQueue[i].field_4 * 2.133333333333333); 281 pActors[objID].pMonsterInfo.uRecoveryTime = (signed __int64)((double)pQueue[i].actor_initiative * 2.133333333333333);
282 } 282 }
283 } 283 }
284 284
285 pAudioPlayer->StopChannels(-1, -1); 285 pAudioPlayer->StopChannels(-1, -1);
286 if ( bPlaySound != 0 ) 286 if ( bPlaySound != 0 )
292 } 292 }
293 // 50C994: using guessed type int dword_50C994; 293 // 50C994: using guessed type int dword_50C994;
294 // 50C998: using guessed type int dword_50C998_turnbased_icon_1A; 294 // 50C998: using guessed type int dword_50C998_turnbased_icon_1A;
295 295
296 //----- (00405E14) -------------------------------------------------------- 296 //----- (00405E14) --------------------------------------------------------
297 void stru262_TurnBased::_405E14() 297 void stru262_TurnBased::AITurnBasedAction()
298 { 298 {
299 AIDirection *v6; // esi@21 299 AIDirection *v6; // esi@21
300 int v7; // eax@21 300 int v7; // eax@21
301 AIDirection a3; // [sp+4h] [bp-68h]@21 301 AIDirection a3; // [sp+4h] [bp-68h]@21
302 AIDirection v14; // [sp+20h] [bp-4Ch]@21 302 AIDirection v14; // [sp+20h] [bp-4Ch]@21
346 } 346 }
347 } 347 }
348 348
349 if ( turn_stage == 1 ) 349 if ( turn_stage == 1 )
350 { 350 {
351 if ( field_8 == 64 ) 351 if ( ai_turn_timer == 64 )
352 { 352 {
353 _406A63(); 353 ActorAIDoMainAction();
354 } 354 }
355 else if ( field_8 > 0 ) 355 else if ( ai_turn_timer > 0 )
356 { 356 {
357 _406B9F(); 357 ActorAIDoAdditionAction();
358 } 358 }
359 else 359 else
360 { 360 {
361 _406AFE(); 361 ActorAISetLastAction();
362 field_10 = 100; 362 turn_initiative = 100;
363 } 363 }
364 field_8 -= pEventTimer->uTimeElapsed; 364 ai_turn_timer -= pEventTimer->uTimeElapsed;
365 } 365 }
366 else if ( turn_stage == 2 ) 366 else if ( turn_stage == 2 )
367 { 367 {
368 if ( !(field_18 & TE_FLAG_1) ) 368 if ( field_18 == TE_FLAG_1)
369 { 369 {
370 if ( field_10 == 100 ) 370 if ( turn_initiative == 100 )
371 { 371 {
372 StartTurn(); 372 StartTurn();
373 _40652A(); 373 SetAIRecoveryTimes();
374 } 374 return;
375 if ( field_10 > 0 || pQueue[0].field_4 <= 0 ) 375 }
376 if ( turn_initiative > 0 || pQueue[0].actor_initiative <= 0 )
376 { 377 {
377 _4065B0(); 378 _4065B0();
378 _40652A(); 379 SetAIRecoveryTimes();
379 } 380 }
381 }
382 NextTurn();
383 }
384 else if ( turn_stage == 3 )
385 {
386 if ( (uActionPointsLeft > 0) && (field_18 == TE_FLAG_8) )
387 {
388 _406FA8();
380 } 389 }
381 else 390 else
382 NextTurn(); 391 {
383 }
384 else if ( turn_stage == 3 )
385 {
386 if ( uActionPointsLeft <= 0 || field_18 & TE_FLAG_8 )
387 {
388 field_18 &= ~TE_FLAG_8; 392 field_18 &= ~TE_FLAG_8;
389 turn_stage = 1; 393 turn_stage = 1;
390 field_8 = 64; 394 ai_turn_timer = 64;
391 } 395
392 else
393 {
394 _406FA8();
395 } 396 }
396 } 397 }
397 } 398 }
398 399
399 400
414 } 415 }
415 } 416 }
416 if (j==uActorQueueSize ) 417 if (j==uActorQueueSize )
417 { 418 {
418 pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Player,player_num); 419 pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Player,player_num);
419 pQueue[uActorQueueSize].field_4 = 100; 420 pQueue[uActorQueueSize].actor_initiative = 100;
420 pQueue[uActorQueueSize].uActionLength = 0; 421 pQueue[uActorQueueSize].uActionLength = 0;
421 pQueue[uActorQueueSize].field_C = 0; 422 pQueue[uActorQueueSize].field_C = 0;
422 ++uActorQueueSize; 423 ++uActorQueueSize;
423 } 424 }
424 } 425 }
432 break; 433 break;
433 } 434 }
434 if (j==uActorQueueSize ) 435 if (j==uActorQueueSize )
435 { 436 {
436 pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[actor_num]); 437 pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[actor_num]);
437 pQueue[uActorQueueSize].field_4 = 1; 438 pQueue[uActorQueueSize].actor_initiative = 1;
438 pQueue[uActorQueueSize].uActionLength = 0; 439 pQueue[uActorQueueSize].uActionLength = 0;
439 pQueue[uActorQueueSize].field_C = 0; 440 pQueue[uActorQueueSize].field_C = 0;
440 ++uActorQueueSize; 441 ++uActorQueueSize;
441 } 442 }
442 } 443 }
443 444
444 ++field_0; 445 ++turns_count;
445 field_10 = 100; 446 turn_initiative = 100;
446 447
447 for(i=0; i<uActorQueueSize; ++i) 448 for(i=0; i<uActorQueueSize; ++i)
448 { 449 {
449 if (pQueue[i].field_4 == 0 ) 450 if (pQueue[i].actor_initiative == 0 )
450 pQueue[i].field_4 = 100; 451 pQueue[i].actor_initiative = 100;
451 } 452 }
452 453
453 _4063A1(); 454 StepTurnQueue();
454 for(i=0; i<uActorQueueSize; ++i) 455 for(i=0; i<uActorQueueSize; ++i)
455 { 456 {
456 if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)||(pQueue[i].field_4 > 0)) 457 if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)||(pQueue[i].actor_initiative > 0))
457 break; 458 break;
458 _40680F(i); 459 _40680F(i);
459 } 460 }
460 } 461 }
461 // 4F75D8: using guessed type int ai_arrays_size; 462 // 4F75D8: using guessed type int ai_arrays_size;
462 463
463 //----- (004061CA) -------------------------------------------------------- 464 //----- (004061CA) --------------------------------------------------------
464 void stru262_TurnBased::NextTurn() 465 void stru262_TurnBased::NextTurn()
481 { 482 {
482 pTurnEngine->field_18 |= TE_FLAG_2; 483 pTurnEngine->field_18 |= TE_FLAG_2;
483 return; 484 return;
484 } 485 }
485 pTurnEngine->field_18 &= ~TE_FLAG_2; 486 pTurnEngine->field_18 &= ~TE_FLAG_2;
486 if ( pQueue[0].field_4 <= 0 ) 487 if ( pQueue[0].actor_initiative <= 0 )
487 return; 488 return;
488 489
489 v13 = 0; 490 v13 = 0;
490 if (uActorQueueSize > 0 ) 491 if (uActorQueueSize > 0 )
491 { 492 {
550 _494035_timed_effects__water_walking_damage__etc(); 551 _494035_timed_effects__water_walking_damage__etc();
551 uActionPointsLeft = 130; 552 uActionPointsLeft = 130;
552 } 553 }
553 554
554 //----- (004063A1) -------------------------------------------------------- 555 //----- (004063A1) --------------------------------------------------------
555 int stru262_TurnBased::_4063A1() 556 int stru262_TurnBased::StepTurnQueue()
556 { 557 {
557 int v9; // dx@12 558 int v9; // dx@12
558 int j; 559 int j;
559 560
560 SortTurnQueue(); 561 SortTurnQueue();
561 viewparams->bRedrawGameUI = 1; 562 viewparams->bRedrawGameUI = 1;
562 if ( pQueue[0].field_4 ) 563 if ( pQueue[0].actor_initiative!=0 )
563 { 564 {
564 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) 565 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
565 { 566 {
566 do 567 do
567 { 568 {
568 for (j=0; j<uActorQueueSize; ++j ) 569 for (j=0; j<uActorQueueSize; ++j )
569 { 570 {
570 --pQueue[j].field_4; 571 --pQueue[j].actor_initiative;
571 } 572 }
572 --field_10; 573 --turn_initiative;
573 if (field_10 == 0) 574 if (turn_initiative == 0)
574 return 1; 575 return 1;
575 } 576 }
576 while (pQueue[0].field_4 > 0); 577 while (pQueue[0].actor_initiative != 0);
577 } 578 }
578 else 579 else
579 { 580 {
581 if ( pQueue[0].actor_initiative>0 )
582 {
580 v9 = pActors[PID_ID(pQueue[0].uPackedID)].uAIState; 583 v9 = pActors[PID_ID(pQueue[0].uPackedID)].uAIState;
581 if (!(v9 == AIState::Dying || v9 == AIState::Dead || 584 if (!(v9 == AIState::Dying || v9 == AIState::Dead ||
582 v9 == AIState::Disabled || v9 == AIState::Removed)) 585 v9 == AIState::Disabled || v9 == AIState::Removed))
583 { 586 {
584 do 587 do
585 { 588 {
586 for (j=0; j<uActorQueueSize; ++j ) 589 for (j=0; j<uActorQueueSize; ++j )
587 { 590 {
588 --pQueue[j].field_4; 591 --pQueue[j].actor_initiative;
589 if (pQueue[j].field_4 == 1) 592 if (pQueue[j].actor_initiative == 0)
590 pQueue[j].uActionLength = 0; 593 pQueue[j].uActionLength = 0;
591 } 594 }
592 --field_10; 595 --turn_initiative;
593 if (field_10 == 0) 596 if (turn_initiative == 0)
594 return 1; 597 return 1;
595 } 598 }
596 while (pQueue[0].field_4 > 0); 599 while (pQueue[0].actor_initiative > 0);
600 }
597 } 601 }
598 } 602 }
599 } 603 }
600 return 0; 604 return 0;
601 } 605 }
611 int result; // eax@11 615 int result; // eax@11
612 int v8; // edx@13 616 int v8; // edx@13
613 int v9; // ecx@14 617 int v9; // ecx@14
614 char v10; // zf@15 618 char v10; // zf@15
615 int i; 619 int i;
616 620 v6=0;
617 if ( PID_TYPE(pQueue[a2].uPackedID) == OBJECT_Player) 621 if ( PID_TYPE(pQueue[a2].uPackedID) == OBJECT_Player)
618 { 622 {
619 v4 = PID_ID(pQueue[a2].uPackedID); 623 v4 = PID_ID(pQueue[a2].uPackedID);
620 if ( pParty->pTurnBasedPlayerRecoveryTimes[v4] ) 624 if ( pParty->pTurnBasedPlayerRecoveryTimes[v4] )
621 pParty->pTurnBasedPlayerRecoveryTimes[v4] = 0; 625 pParty->pTurnBasedPlayerRecoveryTimes[v4] = 0;
627 else 631 else
628 { 632 {
629 v6 = pMonsterStats->pInfos[pActors[PID_ID(pQueue[a2].uPackedID)].pMonsterInfo.uID].uRecoveryTime; 633 v6 = pMonsterStats->pInfos[pActors[PID_ID(pQueue[a2].uPackedID)].pMonsterInfo.uID].uRecoveryTime;
630 } 634 }
631 635
632 pQueue[a2].field_4 = v6; 636 pQueue[a2].actor_initiative = v6;
633 SortTurnQueue(); 637 SortTurnQueue();
634 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) 638 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
635 uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1; 639 uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
636 else 640 else
637 uActiveCharacter = 0; 641 uActiveCharacter = 0;
638 viewparams->bRedrawGameUI = 1; 642 viewparams->bRedrawGameUI = 1;
639 if (pQueue[0].field_4 > 0) 643 if (pQueue[0].actor_initiative > 0)
640 { 644 {
641 while(field_10 > 0) 645 while(turn_initiative > 0)
642 { 646 {
643 for (i=0; i<uActorQueueSize; ++i) 647 for (i=0; i<uActorQueueSize; ++i)
644 { 648 {
645 --pQueue[i].field_4; 649 --pQueue[i].actor_initiative;
646 if (pQueue[i].field_4==0) 650 if (pQueue[i].actor_initiative==0)
647 pQueue[i].uActionLength=0; 651 pQueue[i].uActionLength=0;
648 } 652 }
649 --field_10; 653 --turn_initiative;
650 } 654 }
651 } 655 }
652 } 656 }
653 657
654 //----- (0040652A) -------------------------------------------------------- 658 //----- (0040652A) --------------------------------------------------------
655 void stru262_TurnBased::_40652A() 659 void stru262_TurnBased::SetAIRecoveryTimes()
656 { 660 {
657 int i; 661 int i;
658 int monster_ai_state; 662 int monster_ai_state;
659 Actor *monster; // eax@5 663 Actor *monster; // eax@5
660 664
661 for (i=0; i<uActorQueueSize; ++i ) 665 for (i=0; i<uActorQueueSize; ++i )
662 { 666 {
663 if (pQueue[i].field_4 == 0) 667 if (pQueue[i].actor_initiative == 0)
664 { 668 {
665 if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) 669 if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player)
666 break; 670 break;
667 monster=&pActors[PID_ID(pQueue[i].uPackedID)]; 671 monster=&pActors[PID_ID(pQueue[i].uPackedID)];
668 monster_ai_state=monster->uAIState; 672 monster_ai_state=monster->uAIState;
669 if (monster_ai_state == AIState::Standing || 673 if (monster_ai_state == AIState::Standing ||
670 monster_ai_state == AIState::Fleeing || 674 monster_ai_state == AIState::Fleeing ||
671 monster_ai_state == AIState::Fidgeting) 675 monster_ai_state == AIState::Fidgeting)
672 { 676 {
673 pQueue[i].field_4 = pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime; 677 pQueue[i].actor_initiative = pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime;
674 if (monster->pActorBuffs[7].uExpireTime > 0) 678 if (monster->pActorBuffs[7].uExpireTime > 0)
675 pQueue[i].field_4*=2; 679 pQueue[i].actor_initiative*=2;
676 } 680 }
677 } 681 }
678 } 682 }
679 } 683 }
680 684
682 void stru262_TurnBased::_4065B0() 686 void stru262_TurnBased::_4065B0()
683 { 687 {
684 int i; 688 int i;
685 689
686 SortTurnQueue(); 690 SortTurnQueue();
687 if (pQueue[0].field_4 <= 0) 691 if (pQueue[0].actor_initiative <= 0)
688 { 692 {
689 for (i=0; i<uActorQueueSize; ++i ) 693 for (i=0; i<uActorQueueSize; ++i )
690 { 694 {
691 if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)|| (pQueue[i].field_4 > 0) ) 695 if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)|| (pQueue[i].actor_initiative > 0) )
692 break; 696 break;
693 if ((pQueue[i].uActionLength<=0) && (PID_TYPE(pQueue[i].uPackedID)==OBJECT_Actor)) 697 if ((pQueue[i].uActionLength<=0) && (PID_TYPE(pQueue[i].uPackedID)==OBJECT_Actor))
694 _40680F(i); 698 _40680F(i);
695 } 699 }
696 } 700 }
697 else 701 else
698 { 702 {
699 _4063A1(); 703 StepTurnQueue();
700 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) 704 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
701 uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1; 705 uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
702 else 706 else
703 uActiveCharacter = 0; 707 uActiveCharacter = 0;
704 viewparams->bRedrawGameUI = 1; 708 viewparams->bRedrawGameUI = 1;
705 } 709 }
706 710
707 for (i=0; i<uActorQueueSize; ++i ) 711 for (i=0; i<uActorQueueSize; ++i )
708 AIRangedAttacks(i); 712 AIAttacks(i);
709 } 713 }
710 714
711 //----- (00406648) -------------------------------------------------------- 715 //----- (00406648) --------------------------------------------------------
712 void stru262_TurnBased::AIRangedAttacks( unsigned int queue_index ) 716 void stru262_TurnBased::AIAttacks( unsigned int queue_index )
713 { 717 {
714 TurnBased_QueueElem *v1; // ecx@1 718 TurnBased_QueueElem *v1; // ecx@1
715 int v3; // eax@1 719 int v3; // eax@1
716 unsigned int v4; // ebx@2 720 unsigned int v4; // ebx@2
717 Actor *v5; // esi@2 721 Actor *v5; // esi@2
938 } 942 }
939 } 943 }
940 } 944 }
941 945
942 //----- (00406A63) -------------------------------------------------------- 946 //----- (00406A63) --------------------------------------------------------
943 void stru262_TurnBased::_406A63() 947 void stru262_TurnBased::ActorAIDoMainAction()
944 { 948 {
945 949
946 AIDirection a3; // [sp+8h] [bp-44h]@5 950 AIDirection a3; // [sp+8h] [bp-44h]@5
947 AIDirection v7; // [sp+24h] [bp-28h]@5 951 AIDirection v7; // [sp+24h] [bp-28h]@5
948 unsigned int target_pid; // [sp+40h] [bp-Ch]@5 952 unsigned int target_pid; // [sp+40h] [bp-Ch]@5
949 int i; 953 int i;
950 954
951 this->field_8 = 64; 955 this->ai_turn_timer = 64;
952 dword_50C994 = 0; 956 dword_50C994 = 0;
953 uActiveCharacter = 0; 957 uActiveCharacter = 0;
954 for (i=0; i<uActorQueueSize; ++i ) 958 for (i=0; i<uActorQueueSize; ++i )
955 { 959 {
956 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) 960 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
963 } 967 }
964 } 968 }
965 // 50C994: using guessed type int dword_50C994; 969 // 50C994: using guessed type int dword_50C994;
966 970
967 //----- (00406AFE) -------------------------------------------------------- 971 //----- (00406AFE) --------------------------------------------------------
968 void stru262_TurnBased::_406AFE() 972 void stru262_TurnBased::ActorAISetLastAction()
969 { 973 {
970 AIDirection a3; // [sp+4h] [bp-48h]@5 974 AIDirection a3; // [sp+4h] [bp-48h]@5
971 AIDirection v7; // [sp+20h] [bp-2Ch]@5 975 AIDirection v7; // [sp+20h] [bp-2Ch]@5
972 unsigned int target_pid; 976 unsigned int target_pid;
973 int i; 977 int i;
982 pQueue[i].field_C = 0; 986 pQueue[i].field_C = 0;
983 pQueue[i].uActionLength = 0; 987 pQueue[i].uActionLength = 0;
984 } 988 }
985 } 989 }
986 turn_stage = 2; 990 turn_stage = 2;
987 field_8 = 100; 991 ai_turn_timer = 100;
988 992
989 } 993 }
990 994
991 //----- (00406B9F) -------------------------------------------------------- 995 //----- (00406B9F) --------------------------------------------------------
992 void stru262_TurnBased::_406B9F() 996 void stru262_TurnBased::ActorAIDoAdditionAction()
993 { 997 {
994 Actor *v6; // ebx@5 998 Actor *v6; // ebx@5
995 AIDirection a3; // [sp+0h] [bp-50h]@15 999 AIDirection a3; // [sp+0h] [bp-50h]@15
996 AIDirection v9; // [sp+1Ch] [bp-34h]@15 1000 AIDirection v9; // [sp+1Ch] [bp-34h]@15
997 unsigned int v13; // [sp+44h] [bp-Ch]@8 1001 unsigned int v13; // [sp+44h] [bp-Ch]@8
1043 int *v6; // esi@7 1047 int *v6; // esi@7
1044 TurnBased_QueueElem *v7; // edi@7 1048 TurnBased_QueueElem *v7; // edi@7
1045 int v8; // eax@7 1049 int v8; // eax@7
1046 AIDirection *v9; // esi@10 1050 AIDirection *v9; // esi@10
1047 int v10; // eax@10 1051 int v10; // eax@10
1048 unsigned int v11; // ecx@10 1052 int v11; // ecx@10
1049 unsigned __int8 pHostileType; // al@12 1053 unsigned __int8 pHostileType; // al@12
1050 unsigned __int8 v13; // sf@16 1054 unsigned __int8 v13; // sf@16
1051 unsigned __int8 v14; // of@16 1055 unsigned __int8 v14; // of@16
1052 unsigned int v15; // edx@22 1056 unsigned int v15; // edx@22
1053 unsigned int v16; // ecx@23 1057 unsigned int v16; // ecx@23
1055 double v18; // st7@33 1059 double v18; // st7@33
1056 double v19; // st6@33 1060 double v19; // st6@33
1057 AIDirection a3; // [sp+Ch] [bp-48h]@10 1061 AIDirection a3; // [sp+Ch] [bp-48h]@10
1058 AIDirection pDir; // [sp+28h] [bp-2Ch]@10 1062 AIDirection pDir; // [sp+28h] [bp-2Ch]@10
1059 int v27; // [sp+44h] [bp-10h]@33 1063 int v27; // [sp+44h] [bp-10h]@33
1060 unsigned int v28; // [sp+48h] [bp-Ch]@10 1064 int v28; // [sp+48h] [bp-Ch]@10
1061 TurnBased_QueueElem *v29; // [sp+4Ch] [bp-8h]@7 1065 TurnBased_QueueElem *v29; // [sp+4Ch] [bp-8h]@7
1062 unsigned int uActorID; // [sp+50h] [bp-4h]@2 1066 unsigned int uActorID; // [sp+50h] [bp-4h]@2
1063 unsigned int a2a; // [sp+5Ch] [bp+8h]@7 1067 unsigned int a2a; // [sp+5Ch] [bp+8h]@7
1064 1068
1065 // __debugbreak();//срабатывает при пошаговом режиме после пяти шагов 1069 // __debugbreak();//срабатывает при пошаговом режиме после пяти шагов
1068 return 0; 1072 return 0;
1069 uActorID = PID_ID(v2); 1073 uActorID = PID_ID(v2);
1070 //uActorID = v3; 1074 //uActorID = v3;
1071 actor = &pActors[uActorID]; 1075 actor = &pActors[uActorID];
1072 //v5 = v4->uAIState; 1076 //v5 = v4->uAIState;
1073 if ( actor->uAIState == 5 || actor->uAIState == 4 || actor->uAIState == 11 || actor->uAIState == 19 || actor->uAIState == 17 ) 1077 if ( actor->uAIState == AIState::Dead || actor->uAIState == AIState::Dying ||
1078 actor->uAIState == AIState::Removed|| actor->uAIState == AIState::Disabled ||
1079 actor->uAIState == AIState::Summoned )
1074 return 1; 1080 return 1;
1075 v6 = &ai_near_actors_targets_pid[uActorID]; 1081 v6 = &ai_near_actors_targets_pid[uActorID];
1076 v7 = &pTurnEngine->pQueue[a2]; 1082 v7 = &pTurnEngine->pQueue[a2];
1077 v8 = *v6; 1083 v8 = *v6;
1078 v29 = &pTurnEngine->pQueue[a2]; 1084 v29 = &pTurnEngine->pQueue[a2];
1080 Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true); 1086 Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true);
1081 if ( actor->pMonsterInfo.uHostilityType && !*v6 ) 1087 if ( actor->pMonsterInfo.uHostilityType && !*v6 )
1082 actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly; 1088 actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
1083 v9 = Actor::GetDirectionInfo(v7->uPackedID, a2a, &a3, 0); 1089 v9 = Actor::GetDirectionInfo(v7->uPackedID, a2a, &a3, 0);
1084 v10 = actor->uActorRadius; 1090 v10 = actor->uActorRadius;
1085 memcpy(&a3, v9, sizeof(a3)); 1091 memcpy(&a3, v9, sizeof(AIDirection));
1086 memcpy(&pDir, &a3, sizeof(pDir)); 1092 memcpy(&pDir, &a3, sizeof(AIDirection));
1087 v11 = a3.uDistance - v10; 1093 v11 = a3.uDistance - v10;
1088 v28 = a3.uDistance - v10; 1094 v28 = a3.uDistance - v10;
1089 if ( ((a3.uDistance - v10) & 0x80000000u) != 0 ) 1095 if ( v28 < 0 )
1090 { 1096 {
1091 v11 = 0; 1097 v11 = 0;
1092 v28 = 0; 1098 v28 = 0;
1093 } 1099 }
1094 pHostileType = actor->pMonsterInfo.uHostilityType; 1100 pHostileType = actor->pMonsterInfo.uHostilityType;
1095 if ( pHostileType == 1 ) 1101
1096 { 1102
1097 if ( (double)(signed int)v28 >= 307.2 ) 1103 switch (pHostileType)
1098 goto LABEL_21; 1104 {
1099 actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; 1105 case 1:
1100 goto LABEL_21; 1106 if ( (double)v28 < 307.2 )
1101 } 1107 actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
1102 if ( pHostileType == 2 ) 1108 break;
1103 { 1109 case 2:
1104 v14 = __OFSUB__(v11, 1024); 1110 if ( v28 < 1024 )
1105 v13 = ((v11 - 1024) & 0x80000000u) != 0; 1111 actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
1106 } 1112 break;
1107 else 1113 case 3:
1108 { 1114 if ( v28 < 2560 )
1109 if ( pHostileType != 3 ) 1115 actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
1110 goto LABEL_21; 1116 break;
1111 v14 = __OFSUB__(v11, 2560); 1117 }
1112 v13 = ((v11 - 2560) & 0x80000000u) != 0; 1118
1113 } 1119 if ( actor->pActorBuffs[4].uExpireTime > 0 )
1114 if ( v13 ^ v14 ) 1120 {
1115 { 1121 if (v11 < 10240 )
1116 actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
1117 }
1118 LABEL_21:
1119 if ( (signed __int64)actor->pActorBuffs[4].uExpireTime > 0 )
1120 {
1121 if ( (signed int)v11 < 10240 )
1122 { 1122 {
1123 Actor::AI_Flee(uActorID, a2a, 0, &pDir); 1123 Actor::AI_Flee(uActorID, a2a, 0, &pDir);
1124 v29->field_C = 4;
1125 }
1126 else
1127 {
1128 Actor::AI_4032B2(uActorID, a2a, 1024, 0);
1129 v29->field_C = 2;
1130 }
1131
1132 v29->uActionLength = actor->uCurrentActionLength;
1133 return 1;
1134 }
1135
1136 if ( actor->pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Long )
1137 {
1138 if ( !(actor->uAttributes & 0x020000) || actor->pMonsterInfo.uAIType == 1 )
1139 {
1140 if ( actor->pMonsterInfo.uAIType == 1 )
1141 {
1142 if ( actor->pMonsterInfo.uMovementType == 5 )
1143 Actor::AI_Stand(uActorID, a2a, 32, 0);
1144 else
1145 Actor::AI_Flee(uActorID, a2a, 32, 0);
1124 v29->field_C = 4; 1146 v29->field_C = 4;
1125 v29->uActionLength = actor->uCurrentActionLength; 1147 v29->uActionLength = actor->uCurrentActionLength;
1126 return 1; 1148 return 1;
1127 } 1149 }
1128 Actor::AI_4032B2(uActorID, a2a, 1024, 0); 1150 if ( actor->pMonsterInfo.uAIType == 2 )
1129 v29->field_C = 2; 1151 {
1130 v29->uActionLength = actor->uCurrentActionLength; 1152
1131 return 1; 1153 if (((double)actor->pMonsterInfo.uHP * 0.2) > (double)actor->sCurrentHP && (v11 < 10240 ) )
1132 } 1154 {
1133 if ( actor->pMonsterInfo.uHostilityType != 4 ) 1155 if ( actor->pMonsterInfo.uMovementType == 5 )
1134 goto LABEL_46; 1156 Actor::AI_Stand(uActorID, a2a, 32, 0);
1135 if ( !(actor->uAttributes & 0x020000) || actor->pMonsterInfo.uAIType == 1 ) 1157 else
1136 { 1158 Actor::AI_Flee(uActorID, a2a, 32, 0);
1137 if ( actor->pMonsterInfo.uAIType == 1 )
1138 {
1139 if ( actor->pMonsterInfo.uMovementType == 5 )
1140 {
1141 Actor::AI_Stand(uActorID, a2a, 32, 0);
1142 v29->field_C = 4; 1159 v29->field_C = 4;
1143 v29->uActionLength = actor->uCurrentActionLength; 1160 v29->uActionLength = actor->uCurrentActionLength;
1144 return 1; 1161 return 1;
1145 } 1162 }
1146 Actor::AI_Flee(uActorID, a2a, 32, 0); 1163 }
1147 v29->field_C = 4; 1164 if ( actor->pMonsterInfo.uAIType == 3 )
1148 v29->uActionLength = actor->uCurrentActionLength; 1165 {
1149 return 1; 1166
1150 } 1167 if ( ((double)actor->pMonsterInfo.uHP * 0.1) > (double)actor->sCurrentHP && (v11 < 10240 ))
1151 if ( actor->pMonsterInfo.uAIType == 2 )
1152 {
1153 v27 = actor->sCurrentHP;
1154 v18 = (double)v27;
1155 v19 = (double)(signed int)actor->pMonsterInfo.uHP * 0.2;
1156 if ( v19 > v18 && (signed int)v11 < 10240 )
1157 { 1168 {
1158 if ( actor->pMonsterInfo.uMovementType == 5 ) 1169 if ( actor->pMonsterInfo.uMovementType == 5 )
1159 {
1160 Actor::AI_Stand(uActorID, a2a, 32, 0); 1170 Actor::AI_Stand(uActorID, a2a, 32, 0);
1161 v29->field_C = 4; 1171 else
1162 v29->uActionLength = actor->uCurrentActionLength; 1172 Actor::AI_Flee(uActorID, a2a, 32, 0);
1163 return 1;
1164 }
1165 Actor::AI_Flee(uActorID, a2a, 32, 0);
1166 v29->field_C = 4; 1173 v29->field_C = 4;
1167 v29->uActionLength = actor->uCurrentActionLength; 1174 v29->uActionLength = actor->uCurrentActionLength;
1168 return 1; 1175 return 1;
1169 } 1176 }
1170 goto LABEL_39; 1177
1171 } 1178 }
1172 if ( actor->pMonsterInfo.uAIType == 3 ) 1179 }
1173 { 1180
1174 v27 = actor->sCurrentHP;
1175 v18 = (double)v27;
1176 v19 = (double)(signed int)actor->pMonsterInfo.uHP * 0.1;
1177 if ( v19 > v18 && (signed int)v11 < 10240 )
1178 {
1179 if ( actor->pMonsterInfo.uMovementType == 5 )
1180 {
1181 Actor::AI_Stand(uActorID, a2a, 32, 0);
1182 v29->field_C = 4;
1183 v29->uActionLength = actor->uCurrentActionLength;
1184 return 1;
1185 }
1186 Actor::AI_Flee(uActorID, a2a, 32, 0);
1187 v29->field_C = 4;
1188 v29->uActionLength = actor->uCurrentActionLength;
1189 return 1;
1190 }
1191 goto LABEL_39;
1192 }
1193 }
1194 LABEL_39:
1195 if ( (double)(signed int)v28 < 307.2 ) 1181 if ( (double)(signed int)v28 < 307.2 )
1196 return 0; 1182 return 0;
1197 if ( (signed int)v11 < 5120 ) 1183 if ( (signed int)v11 < 5120 )
1198 { 1184 {
1199 if ( actor->pMonsterInfo.uMissleAttack1Type && (signed int)v11 < 1024 ) 1185 if ( actor->pMonsterInfo.uMissleAttack1Type && (signed int)v11 < 1024 )
1202 Actor::AI_Pursue2(uActorID, a2a, 32, &pDir, 307); 1188 Actor::AI_Pursue2(uActorID, a2a, 32, &pDir, 307);
1203 v29->field_C = 2; 1189 v29->field_C = 2;
1204 v29->uActionLength = actor->uCurrentActionLength; 1190 v29->uActionLength = actor->uCurrentActionLength;
1205 return 1; 1191 return 1;
1206 } 1192 }
1207 LABEL_46: 1193 }
1208 if ( actor->pMonsterInfo.uMovementType == 0 ) 1194 switch(actor->pMonsterInfo.uMovementType)
1209 { 1195 {
1210 Actor::AI_4032B2(uActorID, a2a, 1024, 32); 1196 case 0:
1211 v29->field_C = 2; 1197 Actor::AI_4032B2(uActorID, a2a, 1024, 32);
1212 v29->uActionLength = actor->uCurrentActionLength; 1198 break;
1213 return 1; 1199 case 1:
1214 } 1200 Actor::AI_4032B2(uActorID, a2a, 2560, 32);
1215 if ( actor->pMonsterInfo.uMovementType == 1 ) 1201 break;
1216 { 1202 case 2:
1217 Actor::AI_4032B2(uActorID, a2a, 2560, 32); 1203 Actor::AI_4032B2(uActorID, a2a, 5120, 32);
1218 v29->field_C = 2; 1204 break;
1219 v29->uActionLength = actor->uCurrentActionLength; 1205 case 4:
1220 return 1; 1206 Actor::AI_4032B2(uActorID, a2a, 10240, 32);
1221 } 1207 break;
1222 if ( actor->pMonsterInfo.uMovementType == 2 ) 1208 case 5:
1223 { 1209 Actor::AI_Stand(uActorID, a2a, 32, 0);
1224 Actor::AI_4032B2(uActorID, a2a, 5120, 32); 1210 break;
1225 v29->field_C = 2; 1211 default:
1226 v29->uActionLength = actor->uCurrentActionLength; 1212 return 1;
1227 return 1; 1213 }
1228 } 1214 v29->field_C = 2;
1229 if ( actor->pMonsterInfo.uMovementType == 4 ) 1215 v29->uActionLength = actor->uCurrentActionLength;
1230 {
1231 Actor::AI_4032B2(uActorID, a2a, 10240, 32);
1232 v29->field_C = 2;
1233 v29->uActionLength = actor->uCurrentActionLength;
1234 return 1;
1235 }
1236 if ( actor->pMonsterInfo.uMovementType == 5 )
1237 {
1238 Actor::AI_Stand(uActorID, a2a, 32, 0);
1239 v29->field_C = 2;
1240 v29->uActionLength = actor->uCurrentActionLength;
1241 return 1;
1242 }
1243 return 1; 1216 return 1;
1244 } 1217 }
1245 1218
1246 //----- (00406FA8) -------------------------------------------------------- 1219 //----- (00406FA8) --------------------------------------------------------
1247 void stru262_TurnBased::_406FA8() 1220 void stru262_TurnBased::_406FA8()