/** * Make sure our mission forget's us, and we only delete targets we own (waypoints). * */ Ufo::~Ufo() { for (std::vector<Target*>::iterator i = _followers.begin(); i != _followers.end();) { Craft *c = dynamic_cast<Craft*>(*i); if (c) { c->returnToBase(); i = _followers.begin(); } else { ++i; } } if (_mission) { _mission->decreaseLiveUfos(); } if (_dest) { Waypoint *wp = dynamic_cast<Waypoint*>(_dest); if (wp != 0) { delete _dest; _dest = 0; } } }
/** * Shows the selected soldier's info. * @param action Pointer to an action. */ void CraftSoldiersState::lstSoldiersClick(Action *action) { int row = _lstSoldiers->getSelectedRow(); Craft *c = _base->getCrafts()->at(_craft); Soldier *s = _base->getSoldiers()->at(_lstSoldiers->getSelectedRow()); Uint8 color = Palette::blockOffset(13)+10; if (s->getCraft() == c) { s->setCraft(0); _lstSoldiers->setCellText(row, 2, _game->getLanguage()->getString("STR_NONE_UC")); color = Palette::blockOffset(13)+10; } else if (c->getSpaceAvailable() > 0 && s->getWoundRecovery() == 0) { s->setCraft(c); _lstSoldiers->setCellText(row, 2, c->getName(_game->getLanguage())); color = Palette::blockOffset(13); } _lstSoldiers->setRowColor(row, color); std::wstringstream ss; ss << _game->getLanguage()->getString("STR_SPACE_AVAILABLE") << L'\x01' << c->getSpaceAvailable(); _txtAvailable->setText(ss.str()); std::wstringstream ss2; ss2 << _game->getLanguage()->getString("STR_SPACE_USED") << L'\x01' << c->getSpaceUsed(); _txtUsed->setText(ss2.str()); }
/** * Shows the soldiers in a list. */ void CraftSoldiersState::init() { State::init(); Craft *c = _base->getCrafts()->at(_craft); _lstSoldiers->clearList(); int row = 0; for (std::vector<Soldier*>::iterator i = _base->getSoldiers()->begin(); i != _base->getSoldiers()->end(); ++i) { _lstSoldiers->addRow(3, (*i)->getName(true, 19).c_str(), tr((*i)->getRankString()).c_str(), (*i)->getCraftString(_game->getLanguage()).c_str()); Uint8 color; if ((*i)->getCraft() == c) { color = Palette::blockOffset(13); } else if ((*i)->getCraft() != 0) { color = Palette::blockOffset(15)+6; } else { color = Palette::blockOffset(13)+10; } _lstSoldiers->setRowColor(row, color); row++; } _lstSoldiers->draw(); _txtAvailable->setText(tr("STR_SPACE_AVAILABLE").arg(c->getSpaceAvailable())); _txtUsed->setText(tr("STR_SPACE_USED").arg(c->getSpaceUsed())); }
ValuePtr sCountModules(EnvPtr env, ValuePtr args) { using SSM::Craft; Craft* station = Craft::getSingleton(); return new NumberValue(station->countUnits()); }
/** * Updates the displayed quantities of the * selected item on the list. */ void CraftEquipmentState::updateQuantity() { Craft *c = _base->getCrafts()->at(_craft); std::wstringstream ss, ss2; ss << _base->getItems()->getItem(_items[_sel]); ss2 << c->getItems()->getItem(_items[_sel]); Uint8 color; if (c->getItems()->getItem(_items[_sel]) == 0) { RuleItem *rule = _game->getRuleset()->getItem(_items[_sel]); if (rule->getBattleType() == BT_AMMO) { color = Palette::blockOffset(15)+6; } else { color = Palette::blockOffset(13)+10; } } else { color = Palette::blockOffset(13); } _lstEquipment->setRowColor(_sel, color); _lstEquipment->setCellText(_sel, 1, ss.str()); _lstEquipment->setCellText(_sel, 2, ss2.str()); }
/** * Pick a target for the selected craft. * @param action Pointer to an action. */ void InterceptState::lstCraftsClick(Action *) { Craft* c = _crafts[_lstCrafts->getSelectedRow()]; if (c->getStatus() != "STR_OUT" && (c->getStatus() == "STR_READY" || Options::getBool("craftLaunchAlways"))) { _game->popState(); _game->pushState(new SelectDestinationState(_game, c, _globe)); } }
/** * Returns to the previous screen. * @param action Pointer to an action. */ void CraftInfoState::btnOkClick(Action *) { Craft *c = _base->getCrafts()->at(_craft); if (c->getName(_game->getLanguage()) != _edtCraft->getText()) { c->setName(_edtCraft->getText()); } _game->popState(); }
/** * Centers on the selected craft. * @param action Pointer to an action. */ void InterceptState::lstCraftsRightClick(Action *) { Craft* c = _crafts[_lstCrafts->getSelectedRow()]; if (c->getStatus() == "STR_OUT") { _globe->center(c->getLongitude(), c->getLatitude()); _game->popState(); } }
/** * Resets the savegame when coming back from the inventory. */ void CraftEquipmentState::init() { State::init(); _game->getSavedGame()->setBattleGame(0); Craft *c = _base->getCrafts()->at(_craft); c->setInBattlescape(false); }
/** * 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(); }
/** * Moves the selected item to the craft. */ void CraftEquipmentState::moveRight() { Craft *c = _base->getCrafts()->at(_craft); if (_base->getItems()->getItem(_items[_sel]) > 0) { _base->getItems()->removeItem(_items[_sel]); c->getItems()->addItem(_items[_sel]); updateQuantity(); } }
/** * Resets the savegame when coming back from the inventory. */ void CraftEquipmentState::init() { // Set palette _game->setPalette(_game->getResourcePack()->getPalette("PALETTES.DAT_1")->getColors()); _game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(2)), Palette::backPos, 16); _game->getSavedGame()->setBattleGame(0); Craft *c = _base->getCrafts()->at(_craft); c->setInBattlescape(false); }
/** * Make sure no crafts are chasing this target. */ Target::~Target() { for (size_t i = 0; i < _followers.size(); ++i) { Craft *craft = dynamic_cast<Craft*>(_followers[i]); if (craft) { craft->returnToBase(); } } }
/** * 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(); }
/** * Moves the given number of items (selected) to the base. */ void CraftEquipmentState::moveLeft(int change) { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); int cQty = 0; if (item->isFixed()) cQty = c->getVehicleCount(_items[_sel]); else cQty = c->getItems()->getItem(_items[_sel]); if (0 >= change || 0 >= cQty) return; change = std::min(cQty, change); // Convert vehicle to item if (item->isFixed()) { if(item->getClipSize() != -1) { // First we remove all vehicles because we want to redistribute the ammo RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front()); for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ) { if ((*i)->getRules() == item) { _base->getItems()->addItem(ammo->getType(), (*i)->getAmmo()); delete (*i); i = c->getVehicles()->erase(i); } else ++i; } _base->getItems()->addItem(_items[_sel], cQty); // And now reAdd the count we want to keep in the craft (and redistribute the ammo among them) if (cQty > change) moveRight(cQty - change); } else { _base->getItems()->addItem(_items[_sel], change); for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ) { if ((*i)->getRules() == item) { delete (*i); i = c->getVehicles()->erase(i); if (0 >= --change) break; } else ++i; } } } else { c->getItems()->removeItem(_items[_sel], change); _base->getItems()->addItem(_items[_sel], change); } updateQuantity(); }
/** * Updates the displayed quantities of the * selected item on the list. */ void CraftEquipmentState::updateQuantity() { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); int cQty = 0; if (item->isFixed()) { cQty = c->getVehicleCount(_items[_sel]); } else { cQty = c->getItems()->getItem(_items[_sel]); } std::wstringstream ss, ss2; if (_game->getSavedGame()->getMonthsPassed() > -1) { ss << _base->getItems()->getItem(_items[_sel]); } else { ss << "-"; } ss2 << cQty; Uint8 color; if (cQty == 0) { RuleItem *rule = _game->getRuleset()->getItem(_items[_sel]); if (rule->getBattleType() == BT_AMMO) { color = Palette::blockOffset(15)+6; } else { color = Palette::blockOffset(13)+10; } } else { color = Palette::blockOffset(13); } _lstEquipment->setRowColor(_sel, color); _lstEquipment->setCellText(_sel, 1, ss.str()); _lstEquipment->setCellText(_sel, 2, ss2.str()); std::wstringstream ss3; ss3 << tr("STR_SPACE_AVAILABLE") << L'\x01' << c->getSpaceAvailable(); _txtAvailable->setText(ss3.str()); std::wstringstream ss4; ss4 << tr("STR_SPACE_USED") << L'\x01' << c->getSpaceUsed(); _txtUsed->setText(ss4.str()); }
/** * Changes the Craft name. * @param action Pointer to an action. */ void CraftInfoState::edtCraftKeyPress(Action *action) { if (action->getDetails()->key.keysym.sym == SDLK_RETURN || action->getDetails()->key.keysym.sym == SDLK_KP_ENTER) { Craft *c = _base->getCrafts()->at(_craft); if (c->getName(_game->getLanguage()) != _edtCraft->getText()) { c->setName(_edtCraft->getText()); _edtCraft->setText(c->getName(_game->getLanguage())); } } }
/** * Displays the inventory screen for the soldiers * inside the craft. * @param action Pointer to an action. */ void CraftEquipmentState::btnInventoryClick(Action *) { Craft *craft = _base->getCrafts()->at(_craft); if (craft->getNumSoldiers() != 0) { SavedBattleGame *bgame = new SavedBattleGame(); _game->getSavedGame()->setBattleGame(bgame); BattlescapeGenerator bgen = BattlescapeGenerator(_game); bgen.runInventory(craft); _game->getScreen()->clear(); _game->pushState(new InventoryState(false, 0)); } }
/** * Updates the displayed quantities of the * selected item on the list. */ void CraftEquipmentState::updateQuantity() { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getMod()->getItem(_items[_sel]); int cQty = 0; if (item->isFixed()) { cQty = c->getVehicleCount(_items[_sel]); } else { cQty = c->getItems()->getItem(_items[_sel]); } std::wostringstream ss, ss2; if (_game->getSavedGame()->getMonthsPassed() > -1) { ss << _base->getStorageItems()->getItem(_items[_sel]); } else { ss << "-"; } ss2 << cQty; Uint8 color; if (cQty == 0) { RuleItem *rule = _game->getMod()->getItem(_items[_sel]); if (rule->getBattleType() == BT_AMMO) { color = _ammoColor; } else { color = _lstEquipment->getColor(); } } else { color = _lstEquipment->getSecondaryColor(); } _lstEquipment->setRowColor(_sel, color); _lstEquipment->setCellText(_sel, 1, ss.str()); _lstEquipment->setCellText(_sel, 2, ss2.str()); _txtAvailable->setText(tr("STR_SPACE_AVAILABLE").arg(c->getSpaceAvailable())); _txtUsed->setText(tr("STR_SPACE_USED").arg(c->getSpaceUsed())); }
/** * Pick a target for the selected craft. * @param action Pointer to an action. */ void InterceptState::lstCraftsLeftClick(Action *) { Craft* c = _crafts[_lstCrafts->getSelectedRow()]; if (c->getStatus() == "STR_READY" || ((c->getStatus() == "STR_OUT" || Options::craftLaunchAlways) && !c->getLowFuel() && !c->getMissionComplete())) { _game->popState(); if (_target == 0) { _game->pushState(new SelectDestinationState(c, _globe)); } else { _game->pushState(new ConfirmDestinationState(c, _target)); } } }
/** * Gets the price of the currently selected item. * @return Price of the selected item. */ int SellState::getPrice() { // Personnel/craft aren't worth anything switch(getType(_sel)) { case SELL_SOLDIER: case SELL_ENGINEER: case SELL_SCIENTIST: return 0; case SELL_ITEM: return _game->getRuleset()->getItem(_items[getItemIndex(_sel)])->getSellCost(); case SELL_CRAFT: Craft *craft = _crafts[getCraftIndex(_sel)]; return craft->getRules()->getSellCost(); } return 0; }
ValuePtr sGetFlow(EnvPtr env, ValuePtr args) { using namespace SSM; if(sLength(args) == 1 && args->car()->isSymbol()) { Craft* station = Craft::getSingleton(); if(args->car()->vString() == "energy") { return new NumberValue(station->getFlow(ENERGY)); } else if(args->car()->vString() == "thermal-control") { return new NumberValue(station->getFlow(COOLING)); } else { return new NumberValue(station->getFlow(LIFE_SUPPORT)); } } return rsUndefined(); }
/** * Displays the inventory screen for the soldiers * inside the craft. * @param action Pointer to an action. */ void CraftEquipmentState::btnInventoryClick(Action *) { Craft *craft = _base->getCrafts()->at(_craft); if (craft->getNumSoldiers() == 0) { std::wstringstream ss; ss << craft->getName(_game->getLanguage()) << L'\n' << tr("STR_NO_CREW"); _game->pushState(new ErrorMessageState(_game, ss.str(), Palette::blockOffset(15)+1, "BACK04.SCR", 2)); } else { _game->setPalette(_game->getResourcePack()->getPalette("PALETTES.DAT_4")->getColors()); SavedBattleGame *bgame = new SavedBattleGame(); _game->getSavedGame()->setBattleGame(bgame); BattlescapeGenerator bgen = BattlescapeGenerator(_game); bgen.runInventory(craft); _game->pushState(new InventoryState(_game, false, 0)); } }
/** * Shows the selected soldier's info. * @param action Pointer to an action. */ void CraftSoldiersState::lstSoldiersClick(Action *action) { double mx = action->getAbsoluteXMouse(); if ( mx >= _lstSoldiers->getArrowsLeftEdge() && mx < _lstSoldiers->getArrowsRightEdge() ) { return; } int row = _lstSoldiers->getSelectedRow(); if (action->getDetails()->button.button == SDL_BUTTON_LEFT) { Craft *c = _base->getCrafts()->at(_craft); Soldier *s = _base->getSoldiers()->at(_lstSoldiers->getSelectedRow()); Uint8 color = Palette::blockOffset(13)+10; if (s->getCraft() == c) { s->setCraft(0); _lstSoldiers->setCellText(row, 2, tr("STR_NONE_UC")); color = Palette::blockOffset(13)+10; } else if (s->getCraft() && s->getCraft()->getStatus() == "STR_OUT") { color = Palette::blockOffset(15)+6; } else if (c->getSpaceAvailable() > 0 && s->getWoundRecovery() == 0) { s->setCraft(c); _lstSoldiers->setCellText(row, 2, c->getName(_game->getLanguage())); color = Palette::blockOffset(13); } _lstSoldiers->setRowColor(row, color); _txtAvailable->setText(tr("STR_SPACE_AVAILABLE").arg(c->getSpaceAvailable())); _txtUsed->setText(tr("STR_SPACE_USED").arg(c->getSpaceUsed())); } else if (action->getDetails()->button.button == SDL_BUTTON_RIGHT) { _game->pushState(new SoldierInfoState(_game, _base, row)); } }
/** * Make sure our mission forget's us, and we only delete targets we own (waypoints). * */ Ufo::~Ufo() { for (std::vector<Target*>::iterator i = _followers.begin(); i != _followers.end();) { Craft *c = dynamic_cast<Craft*>(*i); if (c) { c->returnToBase(); i = _followers.begin(); } else { ++i; } } if (_mission && !isEscort()) { _mission->decreaseLiveUfos(); } if (_dest) { Waypoint *wp = dynamic_cast<Waypoint*>(_dest); if (wp != 0) { delete _dest; _dest = 0; } } for (Ufo *escort : _escorts) { delete escort; } for (CraftWeapon *weapon : _weapons) { delete weapon; } }
/** * Moves all the items to the base on right-click. * @param action Pointer to an action. */ void CraftEquipmentState::lstEquipmentLeftArrowClick(Action *action) { if (action->getDetails()->button.button == SDL_BUTTON_RIGHT) { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); int cQty = 0; if (item->isFixed()) { cQty = c->getVehicleCount(_items[_sel]); if (cQty > 0) { while (cQty > 0) { RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front()); for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ++i) { if ((*i)->getRules() == item) { _base->getItems()->addItem(ammo->getType(), (*i)->getAmmo()); delete (*i); c->getVehicles()->erase(i); break; } } _base->getItems()->addItem(_items[_sel]); cQty = c->getVehicleCount(_items[_sel]); } updateQuantity(); } } else { cQty = c->getItems()->getItem(_items[_sel]); if (cQty > 0) { _base->getItems()->addItem(_items[_sel], cQty); c->getItems()->removeItem(_items[_sel], cQty); updateQuantity(); } } } }
/** * Moves the selected item to the base. */ void CraftEquipmentState::moveLeft() { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); int cQty = 0; if (item->isFixed()) { cQty = c->getVehicleCount(_items[_sel]); } else { cQty = c->getItems()->getItem(_items[_sel]); } if (cQty > 0) { RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); // Convert vehicle to item if (item->isFixed()) { RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front()); for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ++i) { if ((*i)->getRules() == item) { _base->getItems()->addItem(ammo->getType(), (*i)->getAmmo()); delete (*i); c->getVehicles()->erase(i); break; } } _base->getItems()->addItem(_items[_sel]); } else { _base->getItems()->addItem(_items[_sel]); c->getItems()->removeItem(_items[_sel]); } updateQuantity(); } }
/** * Moves all the items (as much as possible) to the craft on right-click. * @param action Pointer to an action. */ void CraftEquipmentState::lstEquipmentRightArrowClick(Action *action) { if (action->getDetails()->button.button == SDL_BUTTON_RIGHT) { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); int bqty = _base->getItems()->getItem(_items[_sel]); if (bqty > 0) { // Do we need to convert item to vehicle? if (item->isFixed()) { // Check if there's enough room int room = std::min(c->getRules()->getVehicles() - c->getNumVehicles(), c->getSpaceAvailable() / 4); if (room > 0) { RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front()); int baqty = _base->getItems()->getItem(ammo->getType()); int vehiclesCount = std::min(std::min(bqty, room), baqty); if (vehiclesCount > 0) { int newAmmoPerVehicle = std::min(baqty / vehiclesCount, ammo->getClipSize());; int remainder = baqty - (vehiclesCount * newAmmoPerVehicle); if (ammo->getClipSize() == newAmmoPerVehicle) remainder = 0; int newAmmo; for (int i=0; i < vehiclesCount; ++i) { newAmmo = newAmmoPerVehicle; if (i<remainder) ++newAmmo; c->getVehicles()->push_back(new Vehicle(item, newAmmo)); _base->getItems()->removeItem(ammo->getType(), newAmmo); _base->getItems()->removeItem(_items[_sel]); } } } } else { _base->getItems()->removeItem(_items[_sel],bqty); c->getItems()->addItem(_items[_sel],bqty); } updateQuantity(); } } }
/** * Moves the selected item to the craft. */ void CraftEquipmentState::moveRight() { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); if (_base->getItems()->getItem(_items[_sel]) > 0) { // Convert item to vehicle if (item->isFixed()) { // Check if there's enough room if (c->getNumVehicles() < c->getRules()->getVehicles() && c->getSpaceAvailable() >= 4) { RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front()); int qty = _base->getItems()->getItem(ammo->getType()); if (qty == 0) { std::wstringstream ss; ss << _game->getLanguage()->getString("STR_NOT_ENOUGH"); ss << _game->getLanguage()->getString(ammo->getType()); ss << _game->getLanguage()->getString("STR_TO_ARM_HWP"); _game->pushState(new ErrorMessageState(_game, ss.str(), Palette::blockOffset(15)+1, "BACK04.SCR", 2)); _timerRight->stop(); } else { int newAmmo = std::min(qty, ammo->getClipSize()); c->getVehicles()->push_back(new Vehicle(item, newAmmo)); _base->getItems()->removeItem(ammo->getType(), newAmmo); _base->getItems()->removeItem(_items[_sel]); } } } else { _base->getItems()->removeItem(_items[_sel]); c->getItems()->addItem(_items[_sel]); } updateQuantity(); } }
/** * Initializes all the elements in the Craft Equipment screen. * @param game Pointer to the core game. * @param base Pointer to the base to get info from. * @param craft ID of the selected craft. */ CraftEquipmentState::CraftEquipmentState(Game *game, Base *base, size_t craft) : State(game), _sel(0), _base(base), _craft(craft) { bool allowChangeListValuesByMouseWheel=Options::getBool("allowChangeListValuesByMouseWheel"); _changeValueByMouseWheel = Options::getInt("changeValueByMouseWheel"); // Create objects _window = new Window(this, 320, 200, 0, 0); _btnOk = new TextButton(288, 16, 16, 176); _txtTitle = new Text(300, 16, 16, 7); _txtItem = new Text(144, 9, 16, 32); _txtStores = new Text(150, 9, 160, 32); _txtAvailable = new Text(110, 9, 16, 24); _txtUsed = new Text(110, 9, 130, 24); _txtCrew = new Text(71, 9, 244, 24); _lstEquipment = new TextList(288, 128, 8, 40); // Set palette _game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(2)), Palette::backPos, 16); add(_window); add(_btnOk); add(_txtTitle); add(_txtItem); add(_txtStores); add(_txtAvailable); add(_txtUsed); add(_txtCrew); add(_lstEquipment); // Set up objects _window->setColor(Palette::blockOffset(15)+1); _window->setBackground(_game->getResourcePack()->getSurface("BACK04.SCR")); _btnOk->setColor(Palette::blockOffset(15)+1); _btnOk->setText(_game->getLanguage()->getString("STR_OK")); _btnOk->onMouseClick((ActionHandler)&CraftEquipmentState::btnOkClick); _txtTitle->setColor(Palette::blockOffset(15)+1); _txtTitle->setBig(); Craft *c = _base->getCrafts()->at(_craft); _txtTitle->setText(tr("STR_EQUIPMENT_FOR_craftname").arg(c->getName(_game->getLanguage()))); _txtItem->setColor(Palette::blockOffset(15)+1); _txtItem->setText(_game->getLanguage()->getString("STR_ITEM")); _txtStores->setColor(Palette::blockOffset(15)+1); _txtStores->setText(_game->getLanguage()->getString("STR_STORES")); _txtAvailable->setColor(Palette::blockOffset(15)+1); _txtAvailable->setSecondaryColor(Palette::blockOffset(13)); std::wstringstream ss; ss << _game->getLanguage()->getString("STR_SPACE_AVAILABLE") << L'\x01'<< c->getSpaceAvailable(); _txtAvailable->setText(ss.str()); _txtUsed->setColor(Palette::blockOffset(15)+1); _txtUsed->setSecondaryColor(Palette::blockOffset(13)); std::wstringstream ss2; ss2 << _game->getLanguage()->getString("STR_SPACE_USED") << L'\x01'<< c->getSpaceUsed(); _txtUsed->setText(ss2.str()); _txtCrew->setColor(Palette::blockOffset(15)+1); _txtCrew->setSecondaryColor(Palette::blockOffset(13)); std::wstringstream ss3; ss3 << _game->getLanguage()->getString("STR_SOLDIERS_UC") << ">" << L'\x01'<< c->getNumSoldiers(); _txtCrew->setText(ss3.str()); _lstEquipment->setColor(Palette::blockOffset(13)+10); _lstEquipment->setArrowColor(Palette::blockOffset(15)+1); _lstEquipment->setArrowColumn(203, ARROW_HORIZONTAL); _lstEquipment->setColumns(3, 154, 85, 41); _lstEquipment->setSelectable(true); _lstEquipment->setBackground(_window); _lstEquipment->setMargin(8); if (allowChangeListValuesByMouseWheel) _lstEquipment->setAllowScrollOnArrowButtons(false); _lstEquipment->onLeftArrowPress((ActionHandler)&CraftEquipmentState::lstEquipmentLeftArrowPress); _lstEquipment->onLeftArrowRelease((ActionHandler)&CraftEquipmentState::lstEquipmentLeftArrowRelease); _lstEquipment->onLeftArrowClick((ActionHandler)&CraftEquipmentState::lstEquipmentLeftArrowClick); _lstEquipment->onRightArrowPress((ActionHandler)&CraftEquipmentState::lstEquipmentRightArrowPress); _lstEquipment->onRightArrowRelease((ActionHandler)&CraftEquipmentState::lstEquipmentRightArrowRelease); _lstEquipment->onRightArrowClick((ActionHandler)&CraftEquipmentState::lstEquipmentRightArrowClick); if (allowChangeListValuesByMouseWheel) _lstEquipment->onMousePress((ActionHandler)&CraftEquipmentState::lstEquipmentMousePress); int row = 0; const std::vector<std::string> &items = _game->getRuleset()->getItemsList(); for (std::vector<std::string>::const_iterator i = items.begin(); i != items.end(); ++i) { // CHEAP HACK TO HIDE HWP AMMO if ((*i).substr(0, 8) == "STR_HWP_") continue; RuleItem *rule = _game->getRuleset()->getItem(*i); int cQty = 0; if (rule->isFixed()) { cQty = c->getVehicleCount(*i); } else { cQty = c->getItems()->getItem(*i); } if (rule->getBigSprite() > -1 && rule->getBattleType() != BT_NONE && rule->getBattleType() != BT_CORPSE && _game->getSavedGame()->isResearched(rule->getRequirements()) && (_base->getItems()->getItem(*i) > 0 || cQty > 0)) { _items.push_back(*i); std::wstringstream ss, ss2; ss << _base->getItems()->getItem(*i); ss2 << cQty; std::wstring s = _game->getLanguage()->getString(*i); if (rule->getBattleType() == BT_AMMO) { s.insert(0, L" "); } _lstEquipment->addRow(3, s.c_str(), ss.str().c_str(), ss2.str().c_str()); Uint8 color; if (cQty == 0) { if (rule->getBattleType() == BT_AMMO) { color = Palette::blockOffset(15)+6; } else { color = Palette::blockOffset(13)+10; } } else { color = Palette::blockOffset(13); } _lstEquipment->setRowColor(row, color); ++row; } } _timerLeft = new Timer(50); _timerLeft->onTimer((StateHandler)&CraftEquipmentState::moveLeft); _timerRight = new Timer(50); _timerRight->onTimer((StateHandler)&CraftEquipmentState::moveRight); }