Skip to content

Commit

Permalink
Merge pull request #1184 from MeridianOXC/yankes-fixes
Browse files Browse the repository at this point in the history
Yankes fixes
  • Loading branch information
SupSuper committed May 10, 2018
2 parents 8d59578 + a7a8790 commit 57a10ae
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 27 deletions.
6 changes: 4 additions & 2 deletions src/Basescape/PurchaseState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ void PurchaseState::increaseByValue(int change)
}
else
{
RuleItem *rule = (RuleItem*)getRow().rule;
RuleItem *rule = 0;
switch (getRow().type)
{
case TRANSFER_SOLDIER:
Expand All @@ -535,6 +535,7 @@ void PurchaseState::increaseByValue(int change)
}
break;
case TRANSFER_ITEM:
rule = (RuleItem*)getRow().rule;
if (_iQty + rule->getSize() > _base->getAvailableStores() - _base->getUsedStores())
{
errorMessage = tr("STR_NOT_ENOUGH_STORE_SPACE");
Expand Down Expand Up @@ -612,7 +613,7 @@ void PurchaseState::decreaseByValue(int change)
if (0 >= change || 0 >= getRow().amount) return;
change = std::min(getRow().amount, change);

RuleItem *rule = (RuleItem*)getRow().rule;
RuleItem *rule = 0;
switch (getRow().type)
{
case TRANSFER_SOLDIER:
Expand All @@ -624,6 +625,7 @@ void PurchaseState::decreaseByValue(int change)
_cQty -= change;
break;
case TRANSFER_ITEM:
rule = (RuleItem*)getRow().rule;
_iQty -= rule->getSize() * change;
break;
}
Expand Down
5 changes: 0 additions & 5 deletions src/Basescape/ResearchInfoState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ void ResearchInfoState::btnOkClick(Action *)
*/
void ResearchInfoState::btnCancelClick(Action *)
{
const RuleResearch *ruleResearch = _rule ? _rule : _project->getRules();
if (ruleResearch->needItem() && ruleResearch->destroyItem())
{
_base->getStorageItems()->addItem(ruleResearch->getName(), 1);
}
_base->removeResearch(_project);
_game->popState();
}
Expand Down
1 change: 0 additions & 1 deletion src/Basescape/ResearchState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ ResearchState::ResearchState(Base *base) : _base(base)
_lstResearch->setMargin(2);
_lstResearch->setWordWrap(true);
_lstResearch->onMouseClick((ActionHandler)&ResearchState::onSelectProject);
fillProjectList();
}

/**
Expand Down
17 changes: 9 additions & 8 deletions src/Geoscape/GeoscapeState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,8 +1461,8 @@ void GeoscapeState::time1Hour()
{
if (j->second > PROGRESS_NOT_COMPLETE)
{
(*i)->removeProduction (j->first);
popup(new ProductionCompleteState((*i), tr(j->first->getRules()->getName()), this, j->second));
(*i)->removeProduction(j->first);
}
}

Expand Down Expand Up @@ -1565,19 +1565,22 @@ void GeoscapeState::time1Day()
_game->getSavedGame()->getAvailableResearchProjects(before, _game->getMod(), *i);
}
// 3. add finished research, including lookups and getonefrees (up to 4x)
for (std::vector<ResearchProject*>::const_iterator iter = finished.begin(); iter != finished.end(); ++iter)
for (std::vector<ResearchProject*>::iterator iter = finished.begin(); iter != finished.end(); ++iter)
{
const RuleResearch *bonus = 0;
const RuleResearch *research = (*iter)->getRules();

// 3a. remove finished research from the base where it was researched
(*i)->removeResearch(*iter);
// 3b. handle interrogations
RuleResearch * bonus = 0;
const RuleResearch * research = (*iter)->getRules();
(*iter) = 0;

// 3b. handle interrogation
if (Options::retainCorpses && research->destroyItem() && _game->getMod()->getUnit(research->getName()))
{
(*i)->getStorageItems()->addItem(_game->getMod()->getArmor(_game->getMod()->getUnit(research->getName())->getArmor(), true)->getCorpseGeoscape());
}
// 3c. handle getonefrees (topic+lookup)
if (!(*iter)->getRules()->getGetOneFree().empty())
if (!research->getGetOneFree().empty())
{
std::vector<std::string> possibilities;
for (std::vector<std::string>::const_iterator f = research->getGetOneFree().begin(); f != research->getGetOneFree().end(); ++f)
Expand Down Expand Up @@ -1681,8 +1684,6 @@ void GeoscapeState::time1Day()
}
}
}
// 3k. remove processed item from the list (and continue with the next item)
delete(*iter);
}

// Handle soldier wounds
Expand Down
23 changes: 17 additions & 6 deletions src/Savegame/Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,20 +1095,31 @@ void Base::removeResearch(ResearchProject * project)
{
_research.erase(iter);
}

const RuleResearch *ruleResearch = project->getRules();
if (!project->isFinished())
{
if (ruleResearch->needItem() && ruleResearch->destroyItem())
{
getStorageItems()->addItem(ruleResearch->getName(), 1);
}
}
delete project;
}

/**
* Remove a Production from the Base
* @param p A pointer to a Production
*/
void Base::removeProduction (Production * p)
void Base::removeProduction(Production * p)
{
_engineers += p->getAssignedEngineers();
std::vector<Production *>::iterator iter = std::find (_productions.begin(), _productions.end(), p);
if (iter != _productions.end())
{
_productions.erase(iter);
}
delete p;
}

/**
Expand Down Expand Up @@ -1618,7 +1629,7 @@ void Base::destroyFacility(std::vector<BaseFacility*>::iterator facility)
}
}
}
else if ((*facility)->getRules()->getPsiLaboratories() > 0)
if ((*facility)->getRules()->getPsiLaboratories() > 0)
{
// psi lab destruction: remove any soldiers over the maximum allowable from psi training.
int toRemove = (*facility)->getRules()->getPsiLaboratories() - getFreePsiLabs();
Expand All @@ -1631,7 +1642,7 @@ void Base::destroyFacility(std::vector<BaseFacility*>::iterator facility)
}
}
}
else if ((*facility)->getRules()->getLaboratories())
if ((*facility)->getRules()->getLaboratories())
{
// lab destruction: enforce lab space limits. take scientists off projects until
// it all evens out. research is not cancelled.
Expand All @@ -1653,7 +1664,7 @@ void Base::destroyFacility(std::vector<BaseFacility*>::iterator facility)
}
}
}
else if ((*facility)->getRules()->getWorkshops())
if ((*facility)->getRules()->getWorkshops())
{
// workshop destruction: similar to lab destruction, but we'll lay off engineers instead
// in this case, however, production IS cancelled, as it takes up space in the workshop.
Expand All @@ -1675,7 +1686,7 @@ void Base::destroyFacility(std::vector<BaseFacility*>::iterator facility)
}
}
}
else if ((*facility)->getRules()->getStorage())
if ((*facility)->getRules()->getStorage())
{
// we won't destroy the items physically AT the base,
// but any items in transit will end up at the dead letter office.
Expand All @@ -1695,7 +1706,7 @@ void Base::destroyFacility(std::vector<BaseFacility*>::iterator facility)
}
}
}
else if ((*facility)->getRules()->getPersonnel())
if ((*facility)->getRules()->getPersonnel())
{
// as above, we won't actually fire people, but we'll block any new ones coming in.
if ((getAvailableQuarters() - getUsedQuarters()) - (*facility)->getRules()->getPersonnel() < 0 && !_transfers.empty())
Expand Down
5 changes: 5 additions & 0 deletions src/Savegame/Craft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,8 @@ void Craft::unload(const Mod *mod)
{
_base->getStorageItems()->addItem((*w)->getRules()->getLauncherItem());
_base->getStorageItems()->addItem((*w)->getRules()->getClipItem(), (*w)->getClipsLoaded(mod));
delete (*w);
(*w) = 0;
}
}

Expand All @@ -1012,7 +1014,10 @@ void Craft::unload(const Mod *mod)
{
_base->getStorageItems()->addItem((*v)->getRules()->getCompatibleAmmo()->front(), (*v)->getAmmo());
}
delete (*v);
(*v) = 0;
}
_vehicles.clear();

// Remove soldiers
for (std::vector<Soldier*>::iterator s = _base->getSoldiers()->begin(); s != _base->getSoldiers()->end(); ++s)
Expand Down
14 changes: 9 additions & 5 deletions src/Savegame/ResearchProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ ResearchProject::ResearchProject(RuleResearch * p, int c) : _project(p), _assign
bool ResearchProject::step()
{
_spent += _assigned;
if (_spent >= getCost())
{
return true;
}
return false;
return isFinished();
}

/**
* gets state of project.
*/
bool ResearchProject::isFinished()
{
return _spent >= getCost();
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Savegame/ResearchProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class ResearchProject
ResearchProject(RuleResearch * p, int c = 0);
/// Game logic. Called every new day to compute time spent.
bool step();
/// gets state of project.
bool isFinished();
/// set the number of scientist assigned to this ResearchProject
void setAssigned (int nb);
/// get the number of scientist assigned to this ResearchProject
Expand Down

0 comments on commit 57a10ae

Please sign in to comment.