| 832 | } |
| 833 | |
| 834 | std::vector<CreatureActionType> Player::getWorkerPreferredActions(Creature& worker) const |
| 835 | { |
| 836 | std::vector<CreatureActionType> ret; |
| 837 | // We want to have more or less 40% workers digging, 40% claiming ground tiles and 20% claiming wall tiles |
| 838 | // Concerning carrying stuff, most workers should try unless more than 20% are already carrying. |
| 839 | uint32_t nbWorkersDigging = getNbWorkersDoing(CreatureActionType::searchTileToDig); |
| 840 | uint32_t nbWorkersClaimingGround = getNbWorkersDoing(CreatureActionType::searchGroundTileToClaim); |
| 841 | uint32_t nbWorkersClaimingWall = getNbWorkersDoing(CreatureActionType::searchWallTileToClaim); |
| 842 | uint32_t nbWorkersCarrying = getNbWorkersDoing(CreatureActionType::searchEntityToCarry); |
| 843 | // For the total number of workers, we consider only those doing something in the wanted list (and not |
| 844 | // the ones fighting or having nothing to do) + the one we are considering |
| 845 | uint32_t nbWorkersTotal = nbWorkersDigging + nbWorkersClaimingGround |
| 846 | + nbWorkersClaimingWall + nbWorkersCarrying + 1; |
| 847 | |
| 848 | double percent; |
| 849 | bool isCarryAdded = false; |
| 850 | percent = static_cast<double>(nbWorkersCarrying) / static_cast<double>(nbWorkersTotal); |
| 851 | if(percent <= 0.2) |
| 852 | { |
| 853 | isCarryAdded = true; |
| 854 | ret.push_back(CreatureActionType::searchEntityToCarry); |
| 855 | } |
| 856 | |
| 857 | bool isClaimWallAdded = false; |
| 858 | percent = static_cast<double>(nbWorkersDigging + nbWorkersClaimingGround) / static_cast<double>(nbWorkersTotal); |
| 859 | if(percent > 0.8) |
| 860 | { |
| 861 | isClaimWallAdded = true; |
| 862 | ret.push_back(CreatureActionType::searchWallTileToClaim); |
| 863 | } |
| 864 | |
| 865 | bool digTileFirst = false; |
| 866 | if(nbWorkersDigging < nbWorkersClaimingGround) |
| 867 | digTileFirst = true; |
| 868 | else if(nbWorkersDigging == nbWorkersClaimingGround) |
| 869 | digTileFirst = (Random::Uint(0,1) == 0); |
| 870 | |
| 871 | if(digTileFirst) |
| 872 | { |
| 873 | ret.push_back(CreatureActionType::searchTileToDig); |
| 874 | ret.push_back(CreatureActionType::searchGroundTileToClaim); |
| 875 | } |
| 876 | else |
| 877 | { |
| 878 | ret.push_back(CreatureActionType::searchGroundTileToClaim); |
| 879 | ret.push_back(CreatureActionType::searchTileToDig); |
| 880 | } |
| 881 | |
| 882 | if(!isClaimWallAdded) |
| 883 | ret.push_back(CreatureActionType::searchWallTileToClaim); |
| 884 | if(!isCarryAdded) |
| 885 | ret.push_back(CreatureActionType::searchEntityToCarry); |
| 886 | |
| 887 | return ret; |
| 888 | } |
no test coverage detected