Permalink
Browse files

Merge pull request #325 from redv/fix_living_quarters

fixed living quarters counting
  • Loading branch information...
JonnyH committed Dec 22, 2017
2 parents 3c7e42e + b90a275 commit e7facb5c4c627e1eb3fe31ed2ce8fb45ceafe2e9
Showing with 17 additions and 7 deletions.
  1. +7 −6 game/state/city/base.cpp
  2. +10 −1 game/ui/base/recruitscreen.cpp
View
@@ -534,14 +534,15 @@ int Base::getUsage(GameState &state, sp<Facility> facility, int delta) const
int Base::getUsage(GameState &state, FacilityType::Capacity type, int delta) const
{
if (getCapacityTotal(type) == 0)
int used = getCapacityUsed(state, type) + delta;
int total = getCapacityTotal(type);
if (total == 0)
{
return getCapacityUsed(state, type) + delta > 0 ? 999 : 0;
return used > 0 ? 999 : 0;
}
float usage = 0.0f;
usage = (float)getCapacityUsed(state, type) + (float)delta;
usage /= getCapacityTotal(type);
return std::min(999, static_cast<int>(ceilf(usage * 100.0f)));
// + total / 2 due to rounding
return std::min(999, (100 * used + total / 2) / total);
}
sp<Base> Base::get(const GameState &state, const UString &id)
@@ -113,6 +113,15 @@ RecruitScreen::RecruitScreen(sp<GameState> state)
agentLists[leftIndex].begin(), agentLists[leftIndex].end(), agentControl));
agentLists[rightIndex].push_back(agentControl);
}
else if (this->state->current_base->getUsage(
*(this->state), FacilityType::Capacity::Quarters, lqDelta + 1) > 100)
{
fw().stageQueueCommand(
{StageCmd::Command::PUSH,
mksp<MessageBox>(tr("Accomodation exceeded"),
tr("Transfer limited by available accommodation."),
MessageBox::ButtonOptions::Ok)});
}
else
{
listRight->removeItem(agentControl);
@@ -575,7 +584,7 @@ void RecruitScreen::closeScreen(bool confirmed)
moneyDelta -= hireCost.at(agent->type->role);
}
// Moved away from his base to this base
if (bases[agent->homeBuilding->base.id] != i)
else if (bases[agent->homeBuilding->base.id] != i)
{
vecLqDelta[bases[agent->homeBuilding->base.id]]--;
vecLqDelta[i]++;

0 comments on commit e7facb5

Please sign in to comment.