Skip to content
Permalink
Browse files

.stash multiple hangar types

  • Loading branch information...
Yankes committed Aug 6, 2018
1 parent 22e1f34 commit 08bc53208f0e9dabdfccc323f5c6ac1a4c826bf9
@@ -424,7 +424,7 @@ void ManufactureInfoState::lessEngineerClick(Action *action)
void ManufactureInfoState::moreUnit(int change)
{
if (change <= 0) return;
if (_production->getRules()->getProducedCraft() && _base->getAvailableHangars() - _base->getUsedHangars() <= 0)
if (!_base->addHangarCraftProduction(_production))
{
_timerMoreUnit->stop();
_game->pushState(new ErrorMessageState(tr("STR_NO_FREE_HANGARS_FOR_CRAFT_PRODUCTION"), _palette, _game->getMod()->getInterface("basescape")->getElement("errorMessage")->color, "BACK17.SCR", _game->getMod()->getInterface("basescape")->getElement("errorPalette")->color));
@@ -172,7 +172,7 @@ void ManufactureStartState::btnCancelClick(Action *)
*/
void ManufactureStartState::btnStartClick(Action *)
{
if (_item->getProducedCraft() && _base->getAvailableHangars() - _base->getUsedHangars() <= 0)
if (!_base->haveHangarForCrafrType(_item->getProducedCraft()))
{
_game->pushState(new ErrorMessageState(tr("STR_NO_FREE_HANGARS_FOR_CRAFT_PRODUCTION"), _palette, _game->getMod()->getInterface("basescape")->getElement("errorMessage")->color, "BACK17.SCR", _game->getMod()->getInterface("basescape")->getElement("errorPalette")->color));
}
@@ -38,6 +38,7 @@
#include "../Mod/RuleCraft.h"
#include "../Mod/RuleItem.h"
#include "../Savegame/Base.h"
#include "../Savegame/HangarAllocation.h"
#include "../Engine/Action.h"
#include "../Savegame/Craft.h"
#include "../Savegame/ItemContainer.h"
@@ -69,6 +70,7 @@ PurchaseState::PurchaseState(Base *base) : _base(base), _sel(0), _total(0), _pQt
_txtQuantity = new Text(60, 9, 256, 44);
_cbxCategory = new ComboBox(this, 120, 16, 10, 36);
_lstItems = new TextList(287, 120, 8, 54);
_hangarAllocation = new HangarAllocation(_base);

// Set palette
setInterface("buyMenu");
@@ -232,6 +234,7 @@ PurchaseState::~PurchaseState()
{
delete _timerInc;
delete _timerDec;
delete _hangarAllocation;
}

/**
@@ -359,14 +362,16 @@ void PurchaseState::btnOkClick(Action *)
_base->getTransfers()->push_back(t);
break;
case TRANSFER_CRAFT:
for (int c = 0; c < i->amount; c++)
{
RuleCraft *rule = (RuleCraft*)i->rule;
t = new Transfer(rule->getTransferTime());
Craft *craft = new Craft(rule, _base, _game->getSavedGame()->getId(rule->getType()));
craft->setStatus("STR_REFUELLING");
t->setCraft(craft);
_base->getTransfers()->push_back(t);
for (int c = 0; c < i->amount; c++)
{
t = new Transfer(rule->getTransferTime());
Craft *craft = new Craft(rule, _base, _game->getSavedGame()->getId(rule->getType()));
craft->setStatus("STR_REFUELLING");
t->setCraft(craft);
_base->getTransfers()->push_back(t);
}
}
break;
case TRANSFER_ITEM:
@@ -380,6 +385,7 @@ void PurchaseState::btnOkClick(Action *)
}
}
}
_base->initHangars();
_game->popState();
}

@@ -522,7 +528,6 @@ void PurchaseState::increaseByValue(int change)
}
else
{
RuleItem *rule = nullptr;
switch (getRow().type)
{
case TRANSFER_SOLDIER:
@@ -534,18 +539,27 @@ void PurchaseState::increaseByValue(int change)
}
break;
case TRANSFER_CRAFT:
if (_cQty + 1 > _base->getAvailableHangars() - _base->getUsedHangars())
{
errorMessage = tr("STR_NO_FREE_HANGARS_FOR_PURCHASE");
RuleCraft *rule = (RuleCraft*)getRow().rule;
if (_cQty + 1 > _base->getAvailableHangars() - _base->getUsedHangars())
{
errorMessage = tr("STR_NO_FREE_HANGARS_FOR_PURCHASE");
}
else if (!_hangarAllocation->addCraftType(rule))
{
errorMessage = tr("STR_NO_FREE_HANGARS_FOR_PURCHASE");
}
break;
}
break;
case TRANSFER_ITEM:
rule = (RuleItem*)getRow().rule;
if (_iQty + rule->getSize() > _base->getAvailableStores() - _base->getUsedStores())
{
errorMessage = tr("STR_NOT_ENOUGH_STORE_SPACE");
RuleItem *rule = (RuleItem*)getRow().rule;
if (_iQty + rule->getSize() > _base->getAvailableStores() - _base->getUsedStores())
{
errorMessage = tr("STR_NOT_ENOUGH_STORE_SPACE");
}
break;
}
break;
}
}

@@ -567,24 +581,24 @@ void PurchaseState::increaseByValue(int change)
break;
case TRANSFER_CRAFT:
{
int maxByHangars = _base->getAvailableHangars() - _base->getUsedHangars() - _cQty;
int maxByHangars = 1; //alwas 1 becasue we need check each craft
change = std::min(maxByHangars, change);
_cQty += change;
}
break;
case TRANSFER_ITEM:
{
RuleItem *rule = (RuleItem*)getRow().rule;
double storesNeededPerItem = rule->getSize();
double freeStores = _base->getAvailableStores() - _base->getUsedStores() - _iQty;
double maxByStores = (double)(INT_MAX);
if (!AreSame(storesNeededPerItem, 0.0))
{
maxByStores = (freeStores + 0.05) / storesNeededPerItem;
RuleItem *rule = (RuleItem*)getRow().rule;
double storesNeededPerItem = rule->getSize();
double freeStores = _base->getAvailableStores() - _base->getUsedStores() - _iQty;
double maxByStores = (double)(INT_MAX);
if (!AreSame(storesNeededPerItem, 0.0))
{
maxByStores = (freeStores + 0.05) / storesNeededPerItem;
}
change = std::min((int)maxByStores, change);
_iQty += change * storesNeededPerItem;
}
change = std::min((int)maxByStores, change);
_iQty += change * storesNeededPerItem;
}
break;
}
getRow().amount += change;
@@ -618,7 +632,6 @@ void PurchaseState::decreaseByValue(int change)
if (0 >= change || 0 >= getRow().amount) return;
change = std::min(getRow().amount, change);

RuleItem *rule = nullptr;
switch (getRow().type)
{
case TRANSFER_SOLDIER:
@@ -627,11 +640,20 @@ void PurchaseState::decreaseByValue(int change)
_pQty -= change;
break;
case TRANSFER_CRAFT:
_cQty -= change;
{
RuleCraft *rule = (RuleCraft*)getRow().rule;
_cQty -= change;
for (int i = 0; i < change; ++i)
{
_hangarAllocation->removeCraftType(rule);
}
}
break;
case TRANSFER_ITEM:
rule = (RuleItem*)getRow().rule;
_iQty -= rule->getSize() * change;
{
RuleItem *rule = (RuleItem*)getRow().rule;
_iQty -= rule->getSize() * change;
}
break;
}
getRow().amount -= change;
@@ -33,6 +33,7 @@ class TextList;
class ComboBox;
class Timer;
class Base;
class HangarAllocation;

/**
* Purchase/Hire screen that lets the player buy
@@ -48,6 +49,8 @@ class PurchaseState : public State
Text *_txtTitle, *_txtFunds, *_txtPurchases, *_txtCost, *_txtQuantity, *_txtSpaceUsed;
ComboBox *_cbxCategory;
TextList *_lstItems;
HangarAllocation *_hangarAllocation;

std::vector<TransferRow> _items;
std::vector<int> _rows;
std::vector<std::string> _cats;
@@ -33,6 +33,7 @@
#include "../Savegame/BaseFacility.h"
#include "../Savegame/SavedGame.h"
#include "../Savegame/Base.h"
#include "../Savegame/HangarAllocation.h"
#include "../Savegame/Soldier.h"
#include "../Savegame/Craft.h"
#include "../Savegame/ItemContainer.h"
@@ -68,6 +69,7 @@ TransferItemsState::TransferItemsState(Base *baseFrom, Base *baseTo) : _baseFrom
_txtAmountDestination = new Text(60, 17, 260, 24);
_cbxCategory = new ComboBox(this, 120, 16, 10, 24);
_lstItems = new TextList(287, 128, 8, 44);
_hangarAllocation = new HangarAllocation(_baseTo);

// Set palette
setInterface("transferMenu");
@@ -221,6 +223,7 @@ TransferItemsState::~TransferItemsState()
{
delete _timerInc;
delete _timerDec;
delete _hangarAllocation;
}

/**
@@ -359,13 +362,17 @@ void TransferItemsState::completeTransfer()
break;
case TRANSFER_CRAFT:
craft = (Craft*)i->rule;
craft->setHangar(nullptr);
// Transfer soldiers inside craft
for (std::vector<Soldier*>::iterator s = _baseFrom->getSoldiers()->begin(); s != _baseFrom->getSoldiers()->end();)
{
if ((*s)->getCraft() == craft)
{
if ((*s)->isInPsiTraining()) (*s)->setPsiTraining();
if (craft->getStatus() == "STR_OUT") _baseTo->getSoldiers()->push_back(*s);
if (craft->getStatus() == "STR_OUT")
{
_baseTo->getSoldiers()->push_back(*s);
}
else
{
t = new Transfer(time);
@@ -443,6 +450,7 @@ void TransferItemsState::completeTransfer()
}
}
}
_baseTo->initHangars();
}

/**
@@ -597,6 +605,10 @@ void TransferItemsState::increaseByValue(int change)
{
errorMessage = tr("STR_NO_FREE_HANGARS_FOR_TRANSFER");
}
else if (_hangarAllocation->addCraftType(craft->getRules()))
{
errorMessage = tr("STR_NO_FREE_HANGARS_FOR_TRANSFER");
}
else if (_pQty + craft->getNumSoldiers() > _baseTo->getAvailableQuarters() - _baseTo->getUsedQuarters())
{
errorMessage = tr("STR_NO_FREE_ACCOMODATION_CREW");
@@ -672,7 +684,7 @@ void TransferItemsState::increaseByValue(int change)
{
_timerInc->stop();
RuleInterface *menuInterface = _game->getMod()->getInterface("transferMenu");
_game->pushState(new ErrorMessageState(errorMessage, _palette, menuInterface->getElement("errorMessage")->color, "BACK13.SCR", menuInterface->getElement("errorPalette")->color));
_game->pushState(new ErrorMessageState(errorMessage, _palette, menuInterface->getElement("errorMessage")->color, "BACK13.SCR", menuInterface->getElement("errorPalette")->color));
}
}

@@ -695,7 +707,7 @@ void TransferItemsState::decreaseByValue(int change)
if (0 >= change || 0 >= getRow().amount) return;
Craft *craft = 0;
change = std::min(getRow().amount, change);

switch (getRow().type)
{
case TRANSFER_SOLDIER:
@@ -705,6 +717,7 @@ void TransferItemsState::decreaseByValue(int change)
break;
case TRANSFER_CRAFT:
craft = (Craft*)getRow().rule;
_hangarAllocation->removeCraftType(craft->getRules());
_cQty--;
_pQty -= craft->getNumSoldiers();
_iQty -= craft->getItems()->getTotalSize(_game->getMod());
@@ -33,6 +33,7 @@ class TextList;
class ComboBox;
class Timer;
class Base;
class HangarAllocation;

/**
* Transfer screen that lets the player pick
@@ -42,11 +43,14 @@ class TransferItemsState : public State
{
private:
Base *_baseFrom, *_baseTo;

TextButton *_btnOk, *_btnCancel;
Window *_window;
Text *_txtTitle, *_txtQuantity, *_txtAmountTransfer, *_txtAmountDestination;
ComboBox *_cbxCategory;
TextList *_lstItems;
HangarAllocation *_hangarAllocation;

std::vector<TransferRow> _items;
std::vector<int> _rows;
std::vector<std::string> _cats;

0 comments on commit 08bc532

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