1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-25 21:38:59 +02:00

fix upgrade

This commit is contained in:
Laserlicht 2024-08-06 23:28:45 +02:00
parent 758617e2df
commit 14bcfad7b0
6 changed files with 48 additions and 33 deletions

View File

@ -40,7 +40,7 @@ void BuildAnalyzer::updateTownDwellings(TownDevelopmentInfo & developmentInfo)
for(bool prefix : prefixes)
{
BuildingID building = BuildingID(BuildingID::getDwelling(level, prefix));
BuildingID building = BuildingID(BuildingID::getDwellingFromLevel(level, prefix));
if(!vstd::contains(buildings, building))
continue; // no such building in town
@ -209,10 +209,10 @@ BuildingInfo BuildAnalyzer::getBuildingOrPrerequisite(
int creatureLevel = -1;
int creatureUpgrade = 0;
if(BuildingID::getLevel(toBuild) != -1)
if(BuildingID::getLevelFromDwelling(toBuild) != -1)
{
creatureLevel = BuildingID::getLevel(toBuild) % GameConstants::CREATURES_PER_TOWN;
creatureUpgrade = BuildingID::getLevel(toBuild) / GameConstants::CREATURES_PER_TOWN;
creatureLevel = BuildingID::getLevelFromDwelling(toBuild);
creatureUpgrade = BuildingID::getUpgradedFromDwelling(toBuild);
}
else if(toBuild == BuildingID::HORDE_1 || toBuild == BuildingID::HORDE_1_UPGR)
{
@ -262,7 +262,7 @@ BuildingInfo BuildAnalyzer::getBuildingOrPrerequisite(
auto otherDwelling = [](const BuildingID & id) -> bool
{
return BuildingID::getLevel(id) != -1;
return BuildingID::getLevelFromDwelling(id) != -1;
};
if(vstd::contains_if(missingBuildings, otherDwelling))
@ -405,7 +405,7 @@ BuildingInfo::BuildingInfo(
}
else
{
if(BuildingID::getLevel(id) != -1)
if(BuildingID::getLevelFromDwelling(id) != -1)
{
creatureGrows = creature->getGrowth();

View File

@ -163,7 +163,7 @@ void CBuildingRect::showPopupWindow(const Point & cursorPosition)
}
else
{
int level = BuildingID::getLevel(bid) % bld->town->creatures.size();
int level = BuildingID::getLevelFromDwelling(bid);
GH.windows().createAndPushWindow<CDwellingInfoBox>(parent->pos.x+parent->pos.w / 2, parent->pos.y+parent->pos.h /2, town, level);
}
}
@ -688,7 +688,7 @@ void CCastleBuildings::buildingClicked(BuildingID building, BuildingSubID::EBuil
if (building >= BuildingID::DWELL_FIRST)
{
enterDwelling((BuildingID::getLevel(building))%town->town->creatures.size());
enterDwelling((BuildingID::getLevelFromDwelling(building)));
}
else
{
@ -1771,12 +1771,12 @@ CFortScreen::CFortScreen(const CGTownInstance * town):
BuildingID buildingID;
if(fortSize == town->town->creatures.size())
{
BuildingID dwelling = BuildingID::getDwelling(i, true);
BuildingID dwelling = BuildingID::getDwellingFromLevel(i, true);
if(vstd::contains(town->builtBuildings, dwelling))
buildingID = BuildingID(BuildingID::getDwelling(i, true));
buildingID = BuildingID(BuildingID::getDwellingFromLevel(i, true));
else
buildingID = BuildingID(BuildingID::getDwelling(i));
buildingID = BuildingID(BuildingID::getDwellingFromLevel(i));
}
else
{
@ -1878,7 +1878,7 @@ const CCreature * CFortScreen::RecruitArea::getMyCreature()
const CBuilding * CFortScreen::RecruitArea::getMyBuilding()
{
BuildingID myID = BuildingID(BuildingID::getDwelling(level));
BuildingID myID = BuildingID(BuildingID::getDwellingFromLevel(level));
if (level == town->town->creatures.size())
return town->town->getSpecialBuilding(BuildingSubID::PORTAL_OF_SUMMONING);

View File

@ -298,7 +298,7 @@ public:
HORDE_2_UPGR, GRAIL, EXTRA_TOWN_HALL, EXTRA_CITY_HALL, EXTRA_CAPITOL,
DWELL_FIRST=30, DWELL_LVL_2, DWELL_LVL_3, DWELL_LVL_4, DWELL_LVL_5, DWELL_LVL_6, DWELL_LAST=36,
DWELL_UP_FIRST=37, DWELL_LVL_2_UP, DWELL_LVL_3_UP, DWELL_LVL_4_UP, DWELL_LVL_5_UP,
DWELL_LVL_6_UP, DWELL_UP_LAST=43, DWELL_LVL_8, DWELL_LVL_8_UP,
DWELL_LVL_6_UP, DWELL_UP_LAST=43, DWELL_LVL_8=50, DWELL_LVL_8_UP=57,
DWELL_LVL_1 = DWELL_FIRST,
DWELL_LVL_7 = DWELL_LAST,
@ -314,26 +314,41 @@ public:
};
static Type getDwelling(int level, bool up = false)
private:
static std::vector<std::vector<Type>> getDwellings()
{
const 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 };
const 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 up ? dwellingsUp[level] : dwellings[level];
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};
}
static int getLevel(BuildingIDBase level)
public:
static Type getDwellingFromLevel(int level, bool up = false)
{
const 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 };
const 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 getDwellings()[up ? 1 : 0][level];
}
auto it = std::find(dwellings.begin(), dwellings.end(), level);
if (it != dwellings.end())
return std::distance(dwellings.begin(), it);
it = std::find(dwellingsUp.begin(), dwellingsUp.end(), level);
if (it != dwellingsUp.end())
return std::distance(dwellingsUp.begin(), it);
static int getLevelFromDwelling(BuildingIDBase dwelling)
{
for(int i = 0; i < 2; i++)
{
auto tmp = getDwellings()[i];
auto it = std::find(tmp.begin(), tmp.end(), dwelling);
if (it != tmp.end())
return std::distance(tmp.begin(), it);
}
return -1;
}
static int getUpgradedFromDwelling(BuildingIDBase dwelling)
{
for(int i = 0; i < 2; i++)
{
auto tmp = getDwellings()[i];
auto it = std::find(tmp.begin(), tmp.end(), dwelling);
if (it != tmp.end())
return i;
}
return -1;
}

View File

@ -56,7 +56,7 @@ BuildingID CBuildingHandler::campToERMU(int camp, FactionID townType, const std:
{
if (hordeLvlsPerTType[townType.getNum()][0] == i)
{
BuildingID dwellingID(BuildingID::getDwelling(hordeLvlsPerTType[townType.getNum()][0], true));
BuildingID dwellingID(BuildingID::getDwellingFromLevel(hordeLvlsPerTType[townType.getNum()][0], true));
if(vstd::contains(builtBuildings, dwellingID)) //if upgraded dwelling is built
return BuildingID::HORDE_1_UPGR;
@ -67,7 +67,7 @@ BuildingID CBuildingHandler::campToERMU(int camp, FactionID townType, const std:
{
if(hordeLvlsPerTType[townType.getNum()].size() > 1)
{
BuildingID dwellingID(BuildingID::getDwelling(hordeLvlsPerTType[townType.getNum()][1], true));
BuildingID dwellingID(BuildingID::getDwellingFromLevel(hordeLvlsPerTType[townType.getNum()][1], true));
if(vstd::contains(builtBuildings, dwellingID)) //if upgraded dwelling is built
return BuildingID::HORDE_2_UPGR;

View File

@ -520,7 +520,7 @@ void CGTownInstance::initObj(vstd::RNG & rand) ///initialize town structures
for (int level = 0; level < town->creatures.size(); level++)
{
BuildingID buildID = BuildingID(BuildingID::getDwelling(level));
BuildingID buildID = BuildingID(BuildingID::getDwellingFromLevel(level));
int upgradeNum = 0;
for (; town->buildings.count(buildID); upgradeNum++, buildID.advance(town->creatures.size()))

View File

@ -2360,10 +2360,10 @@ bool CGameHandler::buildStructure(ObjectInstanceID tid, BuildingID requestedID,
//Performs stuff that has to be done before new building is built
auto processBeforeBuiltStructure = [t, this](const BuildingID buildingID)
{
if(BuildingID::getLevel(buildingID) > -1) //dwelling
if(BuildingID::getLevelFromDwelling(buildingID) > -1) //dwelling
{
int level = BuildingID::getLevel(buildingID) % t->town->creatures.size();
int upgradeNumber = BuildingID::getLevel(buildingID) / t->town->creatures.size();
int level = BuildingID::getLevelFromDwelling(buildingID);
int upgradeNumber = BuildingID::getUpgradedFromDwelling(buildingID);
if(upgradeNumber >= t->town->creatures.at(level).size())
{