Skip to content
Permalink
Browse files

Let the ghosts of craft that ceased to be finally rest in peace.

  • Loading branch information...
SupSuper committed May 15, 2019
1 parent b86708f commit 724ecbea2b34db67a7d01c08c3b9deb0bd0cf354
@@ -455,6 +455,7 @@ void BaseView::draw()
}

// Draw crafts
(*i)->setCraft(0);
if ((*i)->getBuildTime() == 0 && (*i)->getRules()->getCrafts() > 0)
{
if (craft != _base->getCrafts()->end())
@@ -467,16 +468,8 @@ void BaseView::draw()
frame->blit(this);
(*i)->setCraft(*craft);
}
else
{
(*i)->setCraft(0);
}
++craft;
}
else
{
(*i)->setCraft(0);
}
}

// Draw time remaining
@@ -382,29 +382,7 @@ void SellState::btnOkClick(Action *)
break;
case TRANSFER_CRAFT:
craft = (Craft*)i->rule;

// Unload craft
craft->unload(_game->getMod());

// Clear hangar
for (std::vector<BaseFacility*>::iterator f = _base->getFacilities()->begin(); f != _base->getFacilities()->end(); ++f)
{
if ((*f)->getCraft() == craft)
{
(*f)->setCraft(0);
break;
}
}

// Remove craft
for (std::vector<Craft*>::iterator c = _base->getCrafts()->begin(); c != _base->getCrafts()->end(); ++c)
{
if (*c == craft)
{
_base->getCrafts()->erase(c);
break;
}
}
_base->removeCraft(craft, true);
delete craft;
break;
case TRANSFER_SCIENTIST:
@@ -342,10 +342,7 @@ void TransferItemsState::completeTransfer()
{
if (*s == i->rule)
{
if ((*s)->isInPsiTraining())
{
(*s)->setPsiTraining();
}
(*s)->setPsiTraining(false);
t = new Transfer(time);
t->setSoldier(*s);
_baseTo->getTransfers()->push_back(t);
@@ -361,8 +358,11 @@ void TransferItemsState::completeTransfer()
{
if ((*s)->getCraft() == craft)
{
if ((*s)->isInPsiTraining()) (*s)->setPsiTraining();
if (craft->getStatus() == "STR_OUT") _baseTo->getSoldiers()->push_back(*s);
(*s)->setPsiTraining(false);
if (craft->getStatus() == "STR_OUT")
{
_baseTo->getSoldiers()->push_back(*s);
}
else
{
t = new Transfer(time);
@@ -378,45 +378,28 @@ void TransferItemsState::completeTransfer()
}

// Transfer craft
for (std::vector<Craft*>::iterator c = _baseFrom->getCrafts()->begin(); c != _baseFrom->getCrafts()->end(); ++c)
_baseFrom->removeCraft(craft, false);
if (craft->getStatus() == "STR_OUT")
{
if (*c == craft)
bool returning = (craft->getDestination() == (Target*)craft->getBase());
_baseTo->getCrafts()->push_back(craft);
craft->setBase(_baseTo, false);
if (craft->getFuel() <= craft->getFuelLimit(_baseTo))
{
if (craft->getStatus() == "STR_OUT")
{
bool returning = (craft->getDestination() == (Target*)craft->getBase());
_baseTo->getCrafts()->push_back(craft);
craft->setBase(_baseTo, false);
if (craft->getFuel() <= craft->getFuelLimit(_baseTo))
{
craft->setLowFuel(true);
craft->returnToBase();
}
else if (returning)
{
craft->setLowFuel(false);
craft->returnToBase();
}
}
else
{
t = new Transfer(time);
t->setCraft(*c);
_baseTo->getTransfers()->push_back(t);
}
// Clear hangar
for (std::vector<BaseFacility*>::iterator f = _baseFrom->getFacilities()->begin(); f != _baseFrom->getFacilities()->end(); ++f)
{
if ((*f)->getCraft() == *c)
{
(*f)->setCraft(0);
break;
}
}

_baseFrom->getCrafts()->erase(c);
break;
craft->setLowFuel(true);
craft->returnToBase();
}
else if (returning)
{
craft->setLowFuel(false);
craft->returnToBase();
}
}
else
{
t = new Transfer(time);
t->setCraft(craft);
_baseTo->getTransfers()->push_back(t);
}
break;
case TRANSFER_SCIENTIST:
@@ -798,7 +798,6 @@ void DebriefingState::prepareDebriefing()
bool aborted = battle->isAborted();
bool success = !aborted || battle->allObjectivesDestroyed();
Craft *craft = 0;
std::vector<Craft*>::iterator craftIterator;
Base *base = 0;
std::string target;

@@ -872,7 +871,6 @@ void DebriefingState::prepareDebriefing()
}
craft = (*j);
base = (*i);
craftIterator = j;
if (craft->getDestination() != 0)
{
_missionStatistics->markerName = craft->getDestination()->getMarkerName();
@@ -1303,10 +1301,10 @@ void DebriefingState::prepareDebriefing()
// Since this is not a base defense mission, we can safely erase the craft,
// without worrying it's vehicles' destructor calling double (on base defense missions
// all vehicle object in the craft is also referenced by base->getVehicles() !!)
base->removeCraft(craft, false);
delete craft;
craft = 0; // To avoid a crash down there!!
lostCraft = true;
base->getCrafts()->erase(craftIterator);
playersSurvived = 0; // assuming you aborted and left everyone behind
success = false;
}
@@ -172,7 +172,7 @@ void AllocatePsiTrainingState::lstSoldiersClick(Action *action)
_lstSoldiers->setRowColor(_sel, _lstSoldiers->getSecondaryColor());
_labSpace--;
_txtRemaining->setText(tr("STR_REMAINING_PSI_LAB_CAPACITY").arg(_labSpace));
_base->getSoldiers()->at(_sel)->setPsiTraining();
_base->getSoldiers()->at(_sel)->setPsiTraining(true);
}
}
else
@@ -181,7 +181,7 @@ void AllocatePsiTrainingState::lstSoldiersClick(Action *action)
_lstSoldiers->setRowColor(_sel, _lstSoldiers->getColor());
_labSpace++;
_txtRemaining->setText(tr("STR_REMAINING_PSI_LAB_CAPACITY").arg(_labSpace));
_base->getSoldiers()->at(_sel)->setPsiTraining();
_base->getSoldiers()->at(_sel)->setPsiTraining(false);
}
}
}
@@ -815,8 +815,8 @@ void GeoscapeState::time5Seconds()
}
}
}
j = (*i)->removeCraft(*j, false);
delete *j;
j = (*i)->getCrafts()->erase(j);
continue;
}
if ((*j)->getDestination() != 0)
@@ -1635,7 +1635,7 @@ void Base::destroyFacility(std::vector<BaseFacility*>::iterator facility)
{
if ((*i)->isInPsiTraining())
{
(*i)->setPsiTraining();
(*i)->setPsiTraining(false);
--toRemove;
}
}
@@ -1768,4 +1768,39 @@ void Base::cleanupDefenses(bool reclaimItems)
}
}

/**
* Removes the craft and all associations from the base (does not destroy it!).
* @param craft Pointer to craft.
* @param unload Unload craft contents before removing.
*/
std::vector<Craft*>::iterator Base::removeCraft(Craft *craft, bool unload)
{
// Unload craft
if (unload)
{
craft->unload(_mod);
}

// Clear hangar
for (std::vector<BaseFacility*>::iterator f = _facilities.begin(); f != _facilities.end(); ++f)
{
if ((*f)->getCraft() == craft)
{
(*f)->setCraft(0);
break;
}
}

// Remove craft
std::vector<Craft*>::iterator c;
for (c = _crafts.begin(); c != _crafts.end(); ++c)
{
if (*c == craft)
{
return _crafts.erase(c);
}
}
return c;
}

}
@@ -213,6 +213,8 @@ class Base : public Target
void destroyFacility(std::vector<BaseFacility*>::iterator facility);
/// Cleans up the defenses vector and optionally reclaims the tanks and their ammo.
void cleanupDefenses(bool reclaimItems);
/// Removes a craft from the base.
std::vector<Craft*>::iterator removeCraft(Craft *craft, bool unload);
};

}
@@ -196,21 +196,8 @@ void Production::startItem(Base * b, SavedGame * g, const Mod *m) const
{
if ((*c)->getRules()->getType() == iter->first)
{
// Unload craft
(*c)->unload(m);

// Clear hangar
for (std::vector<BaseFacility*>::iterator f = b->getFacilities()->begin(); f != b->getFacilities()->end(); ++f)
{
if ((*f)->getCraft() == (*c))
{
(*f)->setCraft(0);
break;
}
}

// Remove craft
b->getCrafts()->erase(c);
b->removeCraft(*c, true);
delete *c;
break;
}
}
@@ -571,11 +571,11 @@ bool Soldier::isInPsiTraining() const
}

/**
* toggles whether or not the unit is in psi training
* changes whether or not the unit is in psi training
*/
void Soldier::setPsiTraining()
void Soldier::setPsiTraining(bool psi)
{
_psiTraining = !_psiTraining;
_psiTraining = psi;
}

/**
@@ -131,7 +131,7 @@ class Soldier
/// Returns whether the unit is in psi training or not
bool isInPsiTraining() const;
/// set the psi training status
void setPsiTraining();
void setPsiTraining(bool psi);
/// returns this soldier's psionic skill improvement score for this month.
int getImprovement() const;
/// returns this soldier's psionic strength improvement score for this month.

0 comments on commit 724ecbe

Please sign in to comment.
You can’t perform that action at this time.