Mercurial > mm7
comparison TurnEngine.cpp @ 1341:67e47fc3133d
TE refactiring continue
author | Gloval |
---|---|
date | Sat, 06 Jul 2013 23:00:24 +0400 |
parents | 22cb507446a4 |
children | bdf0cc8620ad |
comparison
equal
deleted
inserted
replaced
1340:22cb507446a4 | 1341:67e47fc3133d |
---|---|
429 } | 429 } |
430 } | 430 } |
431 | 431 |
432 | 432 |
433 //----- (00406051) -------------------------------------------------------- | 433 //----- (00406051) -------------------------------------------------------- |
434 __int16 stru262_TurnBased::StartTurn() | 434 void stru262_TurnBased::StartTurn() |
435 { | 435 { |
436 stru262_TurnBased *v1; // esi@1 | 436 int player_num, actor_num, i, j; |
437 int v2; // ecx@1 | 437 |
438 int v3; // ebx@1 | 438 field_1C = 0; |
439 char *v4; // edi@1 | 439 for(player_num=0; player_num<4; ++player_num) |
440 int v5; // eax@4 | 440 { |
441 int v6; // eax@12 | 441 for(j=0; j<uActorQueueSize; ++j) |
442 char *v7; // eax@15 | 442 { |
443 TurnBased_QueueElem *v8; // edi@17 | 443 if (PID_TYPE(pQueue[j].uPackedID)== OBJECT_Player) |
444 unsigned int v9; // edx@23 | 444 { |
445 char *v10; // eax@26 | 445 if (pPlayers[PID_ID(pQueue[j].uPackedID) + 1]->CanAct() && (player_num != PID_ID(pQueue[j].uPackedID)) ) |
446 int v11; // eax@30 | 446 break; |
447 int v12; // ebx@30 | 447 } |
448 char *v13; // edi@31 | 448 } |
449 int v15; // [sp+Ch] [bp-10h]@5 | 449 if (j==uActorQueueSize ) |
450 TurnBased_QueueElem *v16; // [sp+10h] [bp-Ch]@3 | 450 { |
451 int v17; // [sp+14h] [bp-8h]@2 | 451 pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Player,player_num); |
452 int v18; // [sp+14h] [bp-8h]@16 | 452 pQueue[uActorQueueSize].field_4 = 100; |
453 signed int v19; // [sp+18h] [bp-4h]@1 | 453 pQueue[uActorQueueSize].uActionLength = 0; |
454 int v20; // [sp+18h] [bp-4h]@14 | 454 pQueue[uActorQueueSize].field_C = 0; |
455 | 455 ++uActorQueueSize; |
456 v1 = this; | 456 } |
457 v2 = 0; | 457 } |
458 v19 = 0; | 458 |
459 v3 = v1->uActorQueueSize; | 459 for(actor_num=0; actor_num<ai_arrays_size; ++actor_num) |
460 v1->field_1C = 0; | 460 { |
461 v4 = (char *)&v1->pQueue[v3].field_4; | 461 for(j=0; j<uActorQueueSize; ++j) |
462 do | 462 { |
463 { | 463 if ((PID_TYPE(pQueue[j].uPackedID)== OBJECT_Actor)&& |
464 v17 = v2; | 464 ai_near_actors_ids[actor_num] == PID_ID(pQueue[j].uPackedID)) |
465 if ( v1->uActorQueueSize <= v2 ) | 465 break; |
466 goto LABEL_11; | 466 } |
467 v16 = v1->pQueue; | 467 if (j==uActorQueueSize ) |
468 while ( 1 ) | 468 { |
469 { | 469 pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[actor_num]); |
470 v5 = v16->uPackedID; | 470 pQueue[uActorQueueSize].field_4 = 1; |
471 if ( PID_TYPE(v16->uPackedID) == OBJECT_Player) | 471 pQueue[uActorQueueSize].uActionLength = 0; |
472 pQueue[uActorQueueSize].field_C = 0; | |
473 ++uActorQueueSize; | |
474 } | |
475 } | |
476 | |
477 ++field_0; | |
478 field_10 = 100; | |
479 | |
480 for(i=0; i<uActorQueueSize; ++i) | |
481 { | |
482 if (pQueue[i].field_4 == 0 ) | |
483 pQueue[i].field_4 = 100; | |
484 } | |
485 | |
486 _4063A1(); | |
487 for(i=0; i<uActorQueueSize; ++i) | |
488 { | |
489 if ((PID_TYPE(pQueue[i].uPackedID)==OBJECT_Player)||(pQueue[i].field_4 > 0)) | |
472 break; | 490 break; |
473 LABEL_8: | 491 _40680F(i); |
474 ++v17; | 492 } |
475 ++v16; | |
476 if ( v17 >= v1->uActorQueueSize ) | |
477 goto LABEL_11; | |
478 } | |
479 v15 = PID_ID(v5); | |
480 if ( !pPlayers[(PID_ID(v5)) + 1]->CanAct() || v19 != v15 ) | |
481 { | |
482 v2 = 0; | |
483 goto LABEL_8; | |
484 } | |
485 v2 = 0; | |
486 LABEL_11: | |
487 if ( v17 == v1->uActorQueueSize ) | |
488 { | |
489 *(int *)v4 = 100; | |
490 v6 = 8 * v19; | |
491 LOBYTE(v6) = PID(OBJECT_Player,v19); | |
492 *((int *)v4 + 2) = v2; | |
493 *((int *)v4 - 1) = v6; | |
494 *((int *)v4 + 1) = v2; | |
495 ++v3; | |
496 v4 += 16; | |
497 } | |
498 ++v19; | |
499 } | |
500 while ( v19 < 4 ); | |
501 v1->uActorQueueSize = v3; | |
502 v20 = v2; | |
503 if ( ai_arrays_size > v2 ) | |
504 { | |
505 v7 = (char *)&v1->pQueue[v3].field_4; | |
506 do | |
507 { | |
508 v18 = v2; | |
509 if ( v1->uActorQueueSize > v2 ) | |
510 { | |
511 v8 = v1->pQueue; | |
512 do | |
513 { | |
514 if ( PID_TYPE(v8->uPackedID) == OBJECT_Actor && ai_near_actors_ids[v20] == PID_ID(v8->uPackedID) ) | |
515 break; | |
516 ++v18; | |
517 ++v8; | |
518 } | |
519 while ( v18 < v1->uActorQueueSize ); | |
520 v2 = 0; | |
521 } | |
522 if ( v18 == v1->uActorQueueSize ) | |
523 { | |
524 v9 = ai_near_actors_ids[v20]; | |
525 *(int *)v7 = 1; | |
526 *((int *)v7 + 2) = v2; | |
527 *((int *)v7 - 1) = PID(OBJECT_Actor,v9); | |
528 *((int *)v7 + 1) = v2; | |
529 ++v3; | |
530 v7 += 16; | |
531 } | |
532 ++v20; | |
533 } | |
534 while ( v20 < ai_arrays_size ); | |
535 } | |
536 ++v1->field_0; | |
537 v1->uActorQueueSize = v3; | |
538 v1->field_10 = 100; | |
539 if ( v3 > 0 ) | |
540 { | |
541 v10 = (char *)&v1->pQueue[0].field_4; | |
542 do | |
543 { | |
544 if ( *(int *)v10 <= 0 ) | |
545 *(int *)v10 = 100; | |
546 ++v2; | |
547 v10 += 16; | |
548 } | |
549 while ( v2 < v1->uActorQueueSize ); | |
550 } | |
551 LOWORD(v11) = v1->_4063A1(); | |
552 v12 = 0; | |
553 if ( v1->uActorQueueSize > 0 ) | |
554 { | |
555 v13 = (char *)&v1->pQueue[0].field_4; | |
556 do | |
557 { | |
558 v11 = PID_TYPE(*((int *)v13 - 1)); | |
559 if ( (char)v11 == 4 ) | |
560 break; | |
561 if ( *(int *)v13 > 0 ) | |
562 break; | |
563 LOWORD(v11) = v1->_40680F(v12++); | |
564 v13 += 16; | |
565 } | |
566 while ( v12 < v1->uActorQueueSize ); | |
567 } | |
568 return v11; | |
569 } | 493 } |
570 // 4F75D8: using guessed type int ai_arrays_size; | 494 // 4F75D8: using guessed type int ai_arrays_size; |
571 | 495 |
572 //----- (004061CA) -------------------------------------------------------- | 496 //----- (004061CA) -------------------------------------------------------- |
573 void stru262_TurnBased::NextTurn() | 497 void stru262_TurnBased::NextTurn() |
574 { | 498 { |
575 stru262_TurnBased *v1; // esi@1 | 499 Actor *curr_actor; // eax@9 |
576 TurnBased_QueueElem *v2; // ebp@1 | 500 int ai_state; // ecx@9 |
577 int v3; // ebx@1 | 501 int v13; // [sp+10h] [bp-4h]@7 |
578 int v4; // edi@7 | 502 int i; |
579 Actor *v5; // eax@9 | 503 int monster_ai_state; |
580 int v6; // ecx@9 | 504 int monster; // eax@5 |
581 signed int v7; // ebx@17 | 505 |
582 int v8; // ebp@27 | 506 SortTurnQueue(); |
583 TurnBased_QueueElem *v9; // edi@28 | 507 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) |
584 int v10; // ecx@30 | 508 uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1; |
585 unsigned __int16 v11; // ax@30 | 509 else |
586 signed int v12; // edx@35 | 510 uActiveCharacter = 0; |
587 signed int v13; // [sp+10h] [bp-4h]@7 | 511 viewparams->bRedrawGameUI = 1; |
588 | 512 |
589 v1 = this; | 513 if ( field_1C ) |
590 SortTurnQueue(); | 514 { |
591 v2 = v1->pQueue; | 515 pTurnEngine->field_18 |= TE_FLAG_2; |
592 v3 = 0; | 516 return; |
593 if (PID_TYPE(v1->pQueue[0].uPackedID) == OBJECT_Player) | 517 } |
594 uActiveCharacter = PID_ID(v1->pQueue[0].uPackedID) + 1; | 518 pTurnEngine->field_18 &= ~TE_FLAG_2; |
595 else | 519 if ( pQueue[0].field_4 <= 0 ) |
596 uActiveCharacter = 0; | 520 return; |
597 viewparams->bRedrawGameUI = 1; | 521 |
598 if ( v1->field_1C ) | 522 v13 = 0; |
599 { | 523 if (uActorQueueSize > 0 ) |
600 pTurnEngine->field_18 |= TE_FLAG_2; | 524 { |
601 return; | 525 |
602 } | 526 for (i=0; i<uActorQueueSize; ++i ) |
603 pTurnEngine->field_18 &= ~TE_FLAG_2; | 527 { |
604 if ( v1->pQueue[0].field_4 <= 0 ) | 528 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) |
605 return; | 529 { |
606 v4 = 0; | 530 curr_actor = &pActors[PID_ID(pQueue[i].uPackedID)]; |
607 v13 = 0; | 531 ai_state = curr_actor->uAIState; |
608 if ( v1->uActorQueueSize <= 0 ) | 532 if ( (ai_state == Dying) || (ai_state == Stunned) || (ai_state == AttackingMelee) || |
609 goto LABEL_27; | 533 (ai_state == AttackingRanged1) || (ai_state == AttackingRanged2) || |
610 do | 534 (ai_state == AttackingRanged3) || (ai_state == AttackingRanged4) || (ai_state ==Summoned)) |
611 { | 535 { |
612 if (PID_TYPE(v2->uPackedID) != OBJECT_Player) | 536 curr_actor->uCurrentActionTime += pEventTimer->uTimeElapsed; |
613 { | 537 if ( curr_actor->uCurrentActionTime < curr_actor->uCurrentActionLength ) |
614 v5 = &pActors[PID_ID(v2->uPackedID)]; | 538 { |
615 LOWORD(v6) = v5->uAIState; | 539 v13 = 1; |
616 if ( (short)v6 == 4 | 540 } |
617 || (short)v6 == 8 | 541 else if ( ai_state == 4 )// Dying |
618 || (short)v6 == 2 | 542 { |
619 || (short)v6 == 3 | 543 curr_actor->uAIState = Dead; |
620 || (short)v6 == 12 | 544 curr_actor->uCurrentActionTime = 0; |
621 || (short)v6 == 13 | 545 curr_actor->uCurrentActionLength = 0; |
622 || (short)v6 == 18 | 546 curr_actor->UpdateAnimation(); |
623 || (short)v6 == 17 ) | 547 } |
624 { | 548 else |
625 v7 = v5->uCurrentActionLength; | 549 { |
626 v5->uCurrentActionTime += pEventTimer->uTimeElapsed; | 550 if ( ai_state == 8 ) //Stunned |
627 if ( (signed int)v5->uCurrentActionTime < v7 ) | 551 Actor::AI_StandOrBored(PID_ID(pQueue[i].uPackedID), ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)], 32, 0); |
628 { | 552 } |
629 v13 = 1; | 553 } |
630 LABEL_19: | 554 } |
631 v3 = 0; | 555 } |
632 goto LABEL_20; | 556 if ( v13 != 0 ) |
633 } | 557 { |
634 v6 = (signed __int16)v6; | 558 field_18 |= TE_FLAG_1; |
635 if ( (signed __int16)v6 == 4 ) | 559 return; |
636 { | 560 } |
637 v3 = 0; | 561 } |
638 v5->uAIState = Dead; | 562 |
639 v5->uCurrentActionTime = 0; | 563 field_18 &= ~TE_FLAG_1; |
640 v5->uCurrentActionLength = 0; | 564 for (i=0; i<uActorQueueSize; ++i ) |
641 v5->UpdateAnimation(); | 565 { |
642 } | 566 if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) |
643 else | 567 { |
644 { | 568 monster=PID_ID(pQueue[i].uPackedID); |
645 if ( v6 != 8 ) | 569 monster_ai_state=pActors[monster].uAIState; |
646 goto LABEL_19; | 570 if ((monster_ai_state != Dead) && |
647 v3 = 0; | 571 (monster_ai_state != Dying) && |
648 Actor::AI_StandOrBored(PID_ID(v2->uPackedID), ai_near_actors_targets_pid[PID_ID(v2->uPackedID)], 32, 0); | 572 (monster_ai_state != Removed) && |
649 } | 573 (monster_ai_state != Summoned) && |
650 } | 574 (monster_ai_state != Disabled)) |
651 } | 575 { |
652 LABEL_20: | 576 pQueue[i].uActionLength = 0; |
653 ++v4; | 577 Actor::AI_StandOrBored(monster, ai_near_actors_targets_pid[monster], 32, nullptr); |
654 ++v2; | 578 } |
655 } | 579 } |
656 while ( v4 < v1->uActorQueueSize ); | 580 } |
657 | 581 turn_stage = 3; |
658 if ( v13 != v3 ) | 582 pParty->uTimePlayed += 213i64; |
659 { | 583 _494035_timed_effects__water_walking_damage__etc(); |
660 v1->field_18 |= TE_FLAG_1; | 584 uActionPointsLeft = 130; |
661 return; | 585 } |
662 } | |
663 LABEL_27: | |
664 v1->field_18 &= ~TE_FLAG_1; | |
665 v8 = 0; | |
666 if ( v1->uActorQueueSize > v3 ) | |
667 { | |
668 v9 = v1->pQueue; | |
669 do | |
670 { | |
671 if (PID_TYPE(v9->uPackedID) != OBJECT_Player) | |
672 { | |
673 v10 = PID_ID(v9->uPackedID); | |
674 v11 = pActors[v10].uAIState; | |
675 if ( v11 != 5 ) | |
676 { | |
677 if ( v11 != 4 && v11 != 11 && v11 != 19 ) | |
678 { | |
679 if ( v11 != 17 ) | |
680 { | |
681 v12 = ai_near_actors_targets_pid[v10]; | |
682 v9->uActionLength = v3; | |
683 Actor::AI_StandOrBored(v10, v12, 32, (AIDirection *)v3); | |
684 } | |
685 } | |
686 } | |
687 } | |
688 ++v8; | |
689 ++v9; | |
690 } | |
691 while ( v8 < v1->uActorQueueSize ); | |
692 } | |
693 v1->turn_stage = 3; | |
694 pParty->uTimePlayed += __PAIR__(v3, 213); | |
695 _494035_timed_effects__water_walking_damage__etc(); | |
696 v1->uActionPointsLeft = 130; | |
697 } | |
698 | 586 |
699 //----- (004063A1) -------------------------------------------------------- | 587 //----- (004063A1) -------------------------------------------------------- |
700 int stru262_TurnBased::_4063A1() | 588 int stru262_TurnBased::_4063A1() |
701 { | 589 { |
702 stru262_TurnBased *v1; // esi@1 | 590 stru262_TurnBased *v1; // esi@1 |
753 if ( v4 > 0 ) | 641 if ( v4 > 0 ) |
754 { | 642 { |
755 do | 643 do |
756 { | 644 { |
757 v9 = v8->uAIState; | 645 v9 = v8->uAIState; |
758 if ( v9 == 5 ) | 646 if (( v9 == 5 )|| ( v9 == 4 || v9 == 19 || v9 == 11 )) |
759 break; | |
760 if ( v9 == 4 || v9 == 19 || v9 == 11 ) | |
761 break; | 647 break; |
762 v10 = 0; | 648 v10 = 0; |
763 if ( v1->uActorQueueSize > 0 ) | 649 if ( v1->uActorQueueSize > 0 ) |
764 { | 650 { |
765 v11 = (int)&v1->pQueue[0].field_4; | 651 v11 = (int)&v1->pQueue[0].field_4; |
854 monster_ai_state=monster->uAIState; | 740 monster_ai_state=monster->uAIState; |
855 if (monster_ai_state == Standing || | 741 if (monster_ai_state == Standing || |
856 monster_ai_state == Fleeing || | 742 monster_ai_state == Fleeing || |
857 monster_ai_state == Fidgeting) | 743 monster_ai_state == Fidgeting) |
858 { | 744 { |
859 pQueue[i].field_4 == pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime; | 745 pQueue[i].field_4 = pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime; |
860 if (monster->pActorBuffs[7].uExpireTime > 0) | 746 if (monster->pActorBuffs[7].uExpireTime > 0) |
861 pQueue[i].field_4*=2; | 747 pQueue[i].field_4*=2; |
862 } | 748 } |
863 } | 749 } |
864 } | 750 } |
923 AIDirection a3; // [sp+Ch] [bp-3Ch]@2 | 809 AIDirection a3; // [sp+Ch] [bp-3Ch]@2 |
924 AIDirection a4; // [sp+28h] [bp-20h]@2 | 810 AIDirection a4; // [sp+28h] [bp-20h]@2 |
925 TurnBased_QueueElem *v28; // [sp+44h] [bp-4h]@1 | 811 TurnBased_QueueElem *v28; // [sp+44h] [bp-4h]@1 |
926 unsigned int a2a; // [sp+50h] [bp+8h]@2 | 812 unsigned int a2a; // [sp+50h] [bp+8h]@2 |
927 | 813 |
928 v1 = (TurnBased_QueueElem *)((char *)this + 16 * (a2 + 2)); | 814 v1 = &pQueue[a2]; |
929 v28 = v1; | 815 v28 = v1; |
930 v3 = v1->uPackedID; | 816 v3 = v1->uPackedID; |
931 if (PID_TYPE(v1->uPackedID) != OBJECT_Player) | 817 if (PID_TYPE(v1->uPackedID) != OBJECT_Player) |
932 { | 818 { |
933 v4 = PID_ID(v3); | 819 v4 = PID_ID(v3); |
1059 int a2a; // [sp+44h] [bp-Ch]@2 | 945 int a2a; // [sp+44h] [bp-Ch]@2 |
1060 unsigned int v20; // [sp+48h] [bp-8h]@10 | 946 unsigned int v20; // [sp+48h] [bp-8h]@10 |
1061 TurnBased_QueueElem *v21; // [sp+4Ch] [bp-4h]@1 | 947 TurnBased_QueueElem *v21; // [sp+4Ch] [bp-4h]@1 |
1062 signed int v22; // [sp+58h] [bp+8h]@10 | 948 signed int v22; // [sp+58h] [bp+8h]@10 |
1063 | 949 |
1064 v2 = (TurnBased_QueueElem *)((char *)this + 16 * (a2 + 2)); | 950 v2 = &pQueue[a2]; |
1065 v21 = v2; | 951 v21 = v2; |
1066 v2->uActionLength = 0; | 952 v2->uActionLength = 0; |
1067 v3 = v2->uPackedID; | 953 v3 = v2->uPackedID; |
1068 if ( (unsigned __int8)v3 & 3 ) | 954 if ( (unsigned __int8)v3 & 3 ) |
1069 { | 955 { |
1354 TurnBased_QueueElem *v29; // [sp+4Ch] [bp-8h]@7 | 1240 TurnBased_QueueElem *v29; // [sp+4Ch] [bp-8h]@7 |
1355 unsigned int uActorID; // [sp+50h] [bp-4h]@2 | 1241 unsigned int uActorID; // [sp+50h] [bp-4h]@2 |
1356 unsigned int a2a; // [sp+5Ch] [bp+8h]@7 | 1242 unsigned int a2a; // [sp+5Ch] [bp+8h]@7 |
1357 | 1243 |
1358 // __debugbreak();//срабатывает при пошаговом режиме после пяти шагов | 1244 // __debugbreak();//срабатывает при пошаговом режиме после пяти шагов |
1359 v2 = *(&this->field_0 + 4 * (a2 + 2)); | 1245 v2 = pQueue[a2].uPackedID; |
1360 if (PID_TYPE(v2) == OBJECT_Player) | 1246 if (PID_TYPE(v2) == OBJECT_Player) |
1361 return 0; | 1247 return 0; |
1362 uActorID = PID_ID(v2); | 1248 uActorID = PID_ID(v2); |
1363 //uActorID = v3; | 1249 //uActorID = v3; |
1364 actor = &pActors[uActorID]; | 1250 actor = &pActors[uActorID]; |