//Androrc Multiple Professions per Building
void CvCity::alterUnitWorkingBuilding(BuildingTypes eBuilding, int iUnitId, bool bAskProfession)
{
FAssertMsg(eBuilding >= 0, "eBuilding expected to be >= 0");
FAssertMsg(eBuilding < GC.getNumBuildingInfos(), "eBuilding expected to be < GC.getNumBuildingInfos()");
//shouldn't be used for the AI at least for now; it can already handle multiple professions in a building
if (!isHuman())
{
return;
}
if (!isHasBuilding(eBuilding))
{
return;
}
CvUnit* pUnit = NULL;
if (iUnitId != -1)
{
pUnit = getPopulationUnitById(iUnitId);
if (pUnit == NULL)
{
pUnit = GET_PLAYER(getOwnerINLINE()).getUnit(iUnitId);
if (pUnit != NULL)
{
if (!pUnit->canJoinCity(plot()))
{
return;
}
addPopulationUnit(pUnit, NO_PROFESSION);
}
}
}
if (isAvailableBuildingSlot(eBuilding, pUnit))
{
if (pUnit != NULL)
{
pUnit->setColonistLocked(true);
}
//code based on the one in setUnitWorkingPlot()
FAssert(pUnit->isColonistLocked());
[COLOR="Red"] ProfessionTypes eBestProfession = NO_PROFESSION; //transferred from below[/COLOR]
if (pUnit->isColonistLocked())
{
//assign profession that produces yields
int iBestYieldAmount = 0;
for(int i=0;i<GC.getNumProfessionInfos();i++)
{
ProfessionTypes eLoopProfession = (ProfessionTypes) i;
[COLOR="Red"] if (GET_PLAYER(getOwnerINLINE()).isProfessionValid(eLoopProfession, pUnit->getUnitType()) && pUnit->canHaveProfession(eLoopProfession, true))
[/COLOR] {
if(GC.getProfessionInfo(eLoopProfession).getSpecialBuilding() == GC.getBuildingInfo(eBuilding).getSpecialBuildingType())
{
int iLoopYieldAmount = getProfessionOutput(eLoopProfession, pUnit);
if (GC.getProfessionInfo(eLoopProfession).getYieldConsumed() != NO_YIELD)
{
int iUnproducedAmount = (getYieldStored((YieldTypes) GC.getProfessionInfo(eLoopProfession).getYieldConsumed()) + getYieldRate((YieldTypes) GC.getProfessionInfo(eLoopProfession).getYieldConsumed())) - getProfessionInput(eLoopProfession, pUnit);
if (iUnproducedAmount < 0)
{
iLoopYieldAmount += (iUnproducedAmount / (getProfessionInput(eLoopProfession, pUnit) / getProfessionOutput(eLoopProfession, pUnit)));
//Androrc Multiple Professions per Building 1.3 Start
if (iLoopYieldAmount < 0)
{
iLoopYieldAmount = 0;
}
//Androrc Multiple Professions per Building 1.3 End
}
}
if(iLoopYieldAmount >= iBestYieldAmount)
{
eBestProfession = eLoopProfession;
iBestYieldAmount = iLoopYieldAmount;
}
}
}
}
[COLOR="Red"] //deleted assert here that no longer served a purpose[/COLOR]
if(eBestProfession != NO_PROFESSION)
{
pUnit->setProfession(eBestProfession);
}
[COLOR="Red"] else
{
pUnit->setColonistLocked(false);
}[/COLOR]
}
[COLOR="Red"] if (isHuman() && bAskProfession && eBestProfession != NO_PROFESSION)[/COLOR]
{
if (pUnit != NULL)
{
CvPopupInfo* pInfo = new CvPopupInfo(BUTTONPOPUP_CHOOSE_PROFESSION, getID(), pUnit->getID(), 2);
gDLL->getInterfaceIFace()->addPopup(pInfo, getOwnerINLINE(), true, true);
}
}
}
}
//Androrc End