| 644 | } |
| 645 | |
| 646 | void KeeperAI::handleDefense() |
| 647 | { |
| 648 | if(mCooldownDefense > 0) |
| 649 | { |
| 650 | --mCooldownDefense; |
| 651 | return; |
| 652 | } |
| 653 | mCooldownDefense = Random::Int(mCooldownDefenseMin, mCooldownDefenseMax); |
| 654 | |
| 655 | Seat* seat = mPlayer.getSeat(); |
| 656 | // We drop creatures nearby owned or allied attacked creatures |
| 657 | std::vector<Creature*> creatures = mGameMap.getCreaturesByAlliedSeat(seat); |
| 658 | for(Creature* creature : creatures) |
| 659 | { |
| 660 | // We check if a creature is fighting near a claimed tile. If yes, we drop a creature nearby |
| 661 | if(!creature->isActionInList(CreatureActionType::fight)) |
| 662 | continue; |
| 663 | |
| 664 | Tile* tile = creature->getPositionTile(); |
| 665 | if(tile == nullptr) |
| 666 | continue; |
| 667 | |
| 668 | // We look for a healthy creature not already fighting |
| 669 | Creature* creatureToDrop = nullptr; |
| 670 | for(Creature* creature2 : mGameMap.getCreaturesBySeat(seat)) |
| 671 | { |
| 672 | if(creature2->getDefinition()->isWorker()) |
| 673 | continue; |
| 674 | if(creature2->getHP() < (creature2->getMaxHp() * 0.5)) |
| 675 | continue; |
| 676 | if(creature2->isActionInList(CreatureActionType::fight)) |
| 677 | continue; |
| 678 | if((creatureToDrop != nullptr) && (creatureToDrop->getLevel() >= creature2->getLevel())) |
| 679 | continue; |
| 680 | |
| 681 | creatureToDrop = creature2; |
| 682 | } |
| 683 | if(creatureToDrop == nullptr) |
| 684 | continue; |
| 685 | |
| 686 | if(!creatureToDrop->tryPickup(seat)) |
| 687 | continue; |
| 688 | |
| 689 | for(Tile* neigh : tile->getAllNeighbors()) |
| 690 | { |
| 691 | if(creatureToDrop->tryDrop(seat, neigh)) |
| 692 | { |
| 693 | mPlayer.pickUpEntity(creatureToDrop); |
| 694 | mPlayer.dropHand(neigh); |
| 695 | return; |
| 696 | } |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | bool KeeperAI::handleWorkers() |
| 702 | { |
nothing calls this directly
no test coverage detected