1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-17 20:58:07 +02:00

Merge pull request #5105 from Xilmi/develop

AI is now able to deal with Coven and Factory special building-behavior's.
This commit is contained in:
Ivan Savenko 2024-12-21 15:57:50 +02:00 committed by GitHub
commit c401eca7c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 5 deletions

View File

@ -36,7 +36,7 @@ void BuildAnalyzer::updateTownDwellings(TownDevelopmentInfo & developmentInfo)
logAi->trace("Checking dwelling level %d", level);
BuildingInfo nextToBuild = BuildingInfo();
for(int upgradeIndex : {1, 0})
for(int upgradeIndex : {2, 1, 0})
{
BuildingID building = BuildingID(BuildingID::getDwellingFromLevel(level, upgradeIndex));
if(!vstd::contains(buildings, building))
@ -212,7 +212,7 @@ BuildingInfo BuildAnalyzer::getBuildingOrPrerequisite(
int creatureLevel = -1;
int creatureUpgrade = 0;
if(BuildingID::DWELL_FIRST <= toBuild && toBuild <= BuildingID::DWELL_UP_LAST)
if(toBuild.IsDwelling())
{
creatureLevel = BuildingID::getLevelFromDwelling(toBuild);
creatureUpgrade = BuildingID::getUpgradedFromDwelling(toBuild);
@ -271,7 +271,7 @@ BuildingInfo BuildAnalyzer::getBuildingOrPrerequisite(
auto otherDwelling = [](const BuildingID & id) -> bool
{
return BuildingID::DWELL_FIRST <= id && id <= BuildingID::DWELL_UP_LAST;
return id.IsDwelling();
};
if(vstd::contains_if(missingBuildings, otherDwelling))
@ -420,7 +420,7 @@ BuildingInfo::BuildingInfo(
}
else
{
if(BuildingID::DWELL_FIRST <= id && id <= BuildingID::DWELL_UP_LAST)
if(id.IsDwelling())
{
creatureGrows = creature->getGrowth();

View File

@ -97,6 +97,10 @@ Goals::TGoalVec RecruitHeroBehavior::decompose(const Nullkiller * ai) const
for(auto hero : availableHeroes)
{
if ((town->visitingHero || town->garrisonHero)
&& closestThreat < 1
&& hero->getArmyCost() < GameConstants::HERO_GOLD_COST / 3.0)
continue;
auto score = ai->heroManager->evaluateHero(hero);
if(score > minScoreToHireMain)
{

View File

@ -306,6 +306,7 @@ public:
DWELL_LVL_7_UP = DWELL_UP_LAST,
DWELL_UP2_FIRST = DWELL_LVL_7_UP + 1,
DWELL_LVL_1_UP2 = DWELL_UP2_FIRST, DWELL_LVL_2_UP2, DWELL_LVL_3_UP2, DWELL_LVL_4_UP2, DWELL_LVL_5_UP2, DWELL_LVL_6_UP2, DWELL_LVL_7_UP2, DWELL_LVL_8_UP2,
// //Special buildings for towns.
CASTLE_GATE = SPECIAL_3, //Inferno
@ -319,7 +320,8 @@ private:
{
std::vector<Type> dwellings = { DWELL_LVL_1, DWELL_LVL_2, DWELL_LVL_3, DWELL_LVL_4, DWELL_LVL_5, DWELL_LVL_6, DWELL_LVL_7, DWELL_LVL_8 };
std::vector<Type> dwellingsUp = { DWELL_LVL_1_UP, DWELL_LVL_2_UP, DWELL_LVL_3_UP, DWELL_LVL_4_UP, DWELL_LVL_5_UP, DWELL_LVL_6_UP, DWELL_LVL_7_UP, DWELL_LVL_8_UP };
return {dwellings, dwellingsUp};
std::vector<Type> dwellingsUp2 = { DWELL_UP2_FIRST, DWELL_LVL_2_UP2, DWELL_LVL_3_UP2, DWELL_LVL_4_UP2, DWELL_LVL_5_UP2 , DWELL_LVL_6_UP2 , DWELL_LVL_7_UP2, DWELL_LVL_8_UP2 };
return {dwellings, dwellingsUp, dwellingsUp2 };
}
public:
@ -339,6 +341,8 @@ public:
}
if(dwelling >= BuildingIDBase::DWELL_LVL_8 && dwelling < BuildingIDBase::DWELL_LVL_8 + 5)
return 7;
else if (dwelling >= BuildingIDBase::DWELL_UP2_FIRST)
return (dwelling - DWELL_UP2_FIRST) % (GameConstants::CREATURES_PER_TOWN - 1);
else
return (dwelling - DWELL_FIRST) % (GameConstants::CREATURES_PER_TOWN - 1);
}
@ -354,6 +358,8 @@ public:
}
if(dwelling >= BuildingIDBase::DWELL_LVL_8 && dwelling < BuildingIDBase::DWELL_LVL_8 + 5)
return dwelling - BuildingIDBase::DWELL_LVL_8;
else if (dwelling >= BuildingIDBase::DWELL_UP2_FIRST)
return (dwelling - DWELL_UP2_FIRST) / (GameConstants::CREATURES_PER_TOWN - 1);
else
return (dwelling - DWELL_FIRST) / (GameConstants::CREATURES_PER_TOWN - 1);
}
@ -366,6 +372,11 @@ public:
dwelling.advance(GameConstants::CREATURES_PER_TOWN - 1);
}
bool IsDwelling() const
{
return (DWELL_FIRST <= num && num <= DWELL_UP_LAST) || (DWELL_LVL_8 <= num && num <= DWELL_LVL_8_UP) || (num >= DWELL_UP2_FIRST && num < DWELL_LVL_8);
}
bool IsSpecialOrGrail() const
{
return num == SPECIAL_1 || num == SPECIAL_2 || num == SPECIAL_3 || num == SPECIAL_4 || num == GRAIL;