Skip to content

Commit

Permalink
Fixed GIT issue #559: Profession Changes now also check available Bar…
Browse files Browse the repository at this point in the history
…racks Space.
  • Loading branch information
raystuttgart committed Apr 5, 2023
1 parent ad1aa9c commit dbf5910
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion Project Files/DLLSources/CvUnit.cpp
Expand Up @@ -11973,7 +11973,6 @@ bool CvUnit::canHaveProfession(ProfessionTypes eProfession, bool bBumpOther, con
///Tk end

CvProfessionInfo& kNewProfession = GC.getProfessionInfo(eProfession);

CvPlayer& kOwner = GET_PLAYER(getOwnerINLINE());

if (!kOwner.isProfessionValid(eProfession, getUnitType()))
Expand Down Expand Up @@ -12205,6 +12204,53 @@ bool CvUnit::canHaveProfession(ProfessionTypes eProfession, bool bBumpOther, con
}
}

// WTP, ray, Barracks System, check if there is still enough Barracks Space - START
// Comment: I am afraid to damage AI logc thus I will only check this for Human
int iBarracksSpaceChangeByProfessionChange = kNewProfession.getBarracksSpaceNeededChange();
if (pPlot != NULL && isHuman() && iBarracksSpaceChangeByProfessionChange > 0)
{
// Case real City
if (pPlot->getImprovementType() == NO_IMPROVEMENT)
{
// this is only checked for Colonial Cities, Native Villages can always be entered
CvCity* pCity = pPlot->getPlotCity();
if (pCity != NULL)
{
// here we ensure we check this only for the Owner of the Unit being Owner of the City
if(!pCity->isNative() && pCity->getOwnerINLINE() == getOwnerINLINE())
{
// this is how much the Unit without a Profession needs
// but we do not need to calculate it because it will not change
// int iBarracksSpaceNeededByUnit = getUnitInfo().getBarracksSpaceNeeded();

int iCurrentBarracksSpaceNeededByProfession = 0; // default case for No Profession
if (getProfession() != NO_PROFESSION)
{
iCurrentBarracksSpaceNeededByProfession = GC.getProfessionInfo(getProfession()).getBarracksSpaceNeededChange();
}

// So when changing the profession the new value will be added and the old will be substracted
int iAdditionalBarracksSpaceNeededForProfession = iBarracksSpaceChangeByProfessionChange - iCurrentBarracksSpaceNeededByProfession;

// Caclulating free Barracks Space in City
int iBarracksSpaceMaxInCity = pPlot->getPlotCity()->getCityBarracksSpace();
int iBarracksSpaceUsedInCity = pPlot->getPlotCity()->getCityBarracksSpaceUsed();
int iBarracksSpaceAvailableInCity = iBarracksSpaceMaxInCity - iBarracksSpaceUsedInCity;

if (iAdditionalBarracksSpaceNeededForProfession > iBarracksSpaceAvailableInCity)
{
return false;
}
}
}
}

// Case "actAsCity" Improvement does not need to be considered - already caught otherwise
// Profession changes like this are not allowed outside Cities
}
// WTP, ray, Barracks System, check if there is still enough Barracks Space - END


return true;
}

Expand Down

0 comments on commit dbf5910

Please sign in to comment.