/** * Decreases the quantity of the selected item to sell by "change". */ void SellState::decrease(int change) { if (0 >= change || 0 >= _qtys[_sel]) return; change = std::min(_qtys[_sel], change); _qtys[_sel] -= change; _total -= getPrice() * change; updateItemStrings(); }
/** * Increases the quantity of the selected item to sell by "change". * @param change how much we want to add */ void SellState::increase(int change) { if (0 >= change || getQuantity() <=_qtys[_sel]) return; change = std::min(getQuantity() - _qtys[_sel], change); _qtys[_sel] += change; _total += getPrice() * change; updateItemStrings(); }
/** * Increases or decreases the quantity of the selected item to sell. * @param change How much we want to add or remove. * @param dir Direction to change, +1 to increase or -1 to decrease. */ void SellState::changeByValue(int change, int dir) { if (dir > 0) { if (0 >= change || getRow().qtySrc <= getRow().amount) return; change = std::min(getRow().qtySrc - getRow().amount, change); } else { if (0 >= change || 0 >= getRow().amount) return; change = std::min(getRow().amount, change); } getRow().amount += dir * change; _total += dir * getRow().cost * change; // Calculate the change in storage space. Craft *craft; Soldier *soldier; RuleItem *armor, *item, *weapon, *ammo; double total = 0.0; switch (getRow().type) { case TRANSFER_SOLDIER: soldier = (Soldier*)getRow().rule; if (soldier->getArmor()->getStoreItem() != Armor::NONE) { armor = _game->getMod()->getItem(soldier->getArmor()->getStoreItem(), true); _spaceChange += dir * armor->getSize(); } break; case TRANSFER_CRAFT: craft = (Craft*)getRow().rule; for (std::vector<CraftWeapon*>::iterator w = craft->getWeapons()->begin(); w != craft->getWeapons()->end(); ++w) { if (*w) { weapon = _game->getMod()->getItem((*w)->getRules()->getLauncherItem(), true); total += weapon->getSize(); ammo = _game->getMod()->getItem((*w)->getRules()->getClipItem()); if (ammo) total += ammo->getSize() * (*w)->getClipsLoaded(_game->getMod()); } } _spaceChange += dir * total; break; case TRANSFER_ITEM: item = (RuleItem*)getRow().rule; _spaceChange -= dir * change * item->getSize(); break; default: //TRANSFER_SCIENTIST and TRANSFER_ENGINEER do not own anything that takes storage break; } updateItemStrings(); }
/** * Increases or decreases the quantity of the selected item to sell. * @param change How much we want to add or remove. * @param dir Direction to change, +1 to increase or -1 to decrease. */ void SellState::changeByValue(int change, int dir) { if (dir > 0) { if (0 >= change || getQuantity() <=_qtys[_sel]) return; change = std::min(getQuantity() - _qtys[_sel], change); } else { if (0 >= change || 0 >= _qtys[_sel]) return; change = std::min(_qtys[_sel], change); } _qtys[_sel] += dir * change; _total += dir * getPrice() * change; // Calculate the change in storage space. Craft *craft; RuleItem *armor, *item, *weapon, *ammo; double total = 0.0; switch (getType(_sel)) { case SELL_SOLDIER: if (_soldiers[_sel]->getArmor()->getStoreItem() != "STR_NONE") { armor = _game->getRuleset()->getItem(_soldiers[_sel]->getArmor()->getStoreItem()); _spaceChange += dir * armor->getSize(); } break; case SELL_CRAFT: craft = _crafts[getCraftIndex(_sel)]; for (std::vector<CraftWeapon*>::iterator w = craft->getWeapons()->begin(); w != craft->getWeapons()->end(); ++w) { if (*w) { weapon = _game->getRuleset()->getItem((*w)->getRules()->getLauncherItem()); total += weapon->getSize(); ammo = _game->getRuleset()->getItem((*w)->getRules()->getClipItem()); if (ammo) total += ammo->getSize() * (*w)->getClipsLoaded(_game->getRuleset()); } } _spaceChange += dir * total; break; case SELL_ITEM: item = _game->getRuleset()->getItem(_items[getItemIndex(_sel)]); _spaceChange -= dir * change * item->getSize(); break; default: break; } updateItemStrings(); }