/** * Initializes a UFO of the specified type. * @param rules Pointer to ruleset. */ Ufo::Ufo(const RuleUfo *rules, bool createEscorts, int escortId) : MovingTarget(), _rules(rules), _id(0), _crashId(0), _landId(0), _damage(0), _direction("STR_NORTH"), _altitude("STR_HIGH_UC"), _status(FLYING), _secondsRemaining(0), _inBattlescape(false), _mission(0), _trajectory(0), _trajectoryPoint(0), _detected(false), _hyperDetected(false), _processedIntercept(false), _shootingAt(0), _hitFrame(0), _fireCountdown(0), _escapeCountdown(0), _stats(), _shield(-1), _shieldRechargeHandle(0), _tractorBeamSlowdown(0), _retreating(false), _escorting(nullptr), _escortId(escortId), _weapons() { _stats = rules->getStats(); for (const std::string &weaponType : rules->getWeapons()) { RuleCraftWeapon *weaponRule = Game::getMod()->getCraftWeapon(weaponType, true); _weapons.push_back(new CraftWeapon(weaponRule, weaponRule->getAmmoMax())); } if(createEscorts) { int escortId = 1; for (const std::string &escortType : rules->getEscorts()) { _escorts.push_back(new Ufo(Game::getMod()->getUfo(escortType, true), false, escortId)); ++escortId; } } }
ArticleStateTFTDCraftWeapon::ArticleStateTFTDCraftWeapon(ArticleDefinitionTFTD *defs) : ArticleStateTFTD(defs) { RuleCraftWeapon *weapon = _game->getMod()->getCraftWeapon(defs->id, true); _lstInfo = new TextList(150, 50, 168, 126); add(_lstInfo); _lstInfo->setColor(Palette::blockOffset(0)+2); _lstInfo->setColumns(2, 100, 68); // deliberately making this wider than the original to account for finnish. _lstInfo->setDot(true); _lstInfo->addRow(2, tr("STR_DAMAGE").c_str(), Text::formatNumber(weapon->getDamage()).c_str()); _lstInfo->setCellColor(0, 1, Palette::blockOffset(15)+4); _lstInfo->addRow(2, tr("STR_RANGE").c_str(), tr("STR_KILOMETERS").arg(weapon->getRange()).c_str()); _lstInfo->setCellColor(1, 1, Palette::blockOffset(15)+4); _lstInfo->addRow(2, tr("STR_ACCURACY").c_str(), Text::formatPercentage(weapon->getAccuracy()).c_str()); _lstInfo->setCellColor(2, 1, Palette::blockOffset(15)+4); _lstInfo->addRow(2, tr("STR_RE_LOAD_TIME").c_str(), tr("STR_SECONDS").arg(weapon->getStandardReload()).c_str()); _lstInfo->setCellColor(3, 1, Palette::blockOffset(15)+4); centerAllSurfaces(); }
ArticleStateCraftWeapon::ArticleStateCraftWeapon(ArticleDefinitionCraftWeapon *defs) : ArticleState(defs->id) { RuleCraftWeapon *weapon = _game->getMod()->getCraftWeapon(defs->id); // add screen elements _txtTitle = new Text(200, 32, 5, 24); // Set palette setPalette("PAL_BATTLEPEDIA"); ArticleState::initLayout(); // add other elements add(_txtTitle); // Set up objects _game->getMod()->getSurface(defs->image_id)->blit(_bg); _btnOk->setColor(Palette::blockOffset(1)); _btnPrev->setColor(Palette::blockOffset(1)); _btnNext->setColor(Palette::blockOffset(1)); _txtTitle->setColor(Palette::blockOffset(14)+15); _txtTitle->setBig(); _txtTitle->setWordWrap(true); _txtTitle->setText(tr(defs->title)); _txtInfo = new Text(310, 32, 5, 160); add(_txtInfo); _txtInfo->setColor(Palette::blockOffset(14)+15); _txtInfo->setWordWrap(true); _txtInfo->setText(tr(defs->text)); _lstInfo = new TextList(250, 111, 5, 80); add(_lstInfo); _lstInfo->setColor(Palette::blockOffset(14)+15); _lstInfo->setColumns(2, 180, 70); _lstInfo->setDot(true); _lstInfo->setBig(); _lstInfo->addRow(2, tr("STR_DAMAGE").c_str(), Text::formatNumber(weapon->getDamage()).c_str()); _lstInfo->setCellColor(0, 1, Palette::blockOffset(15)+4); _lstInfo->addRow(2, tr("STR_RANGE").c_str(), tr("STR_KILOMETERS").arg(weapon->getRange()).c_str()); _lstInfo->setCellColor(1, 1, Palette::blockOffset(15)+4); _lstInfo->addRow(2, tr("STR_ACCURACY").c_str(), Text::formatPercentage(weapon->getAccuracy()).c_str()); _lstInfo->setCellColor(2, 1, Palette::blockOffset(15)+4); _lstInfo->addRow(2, tr("STR_RE_LOAD_TIME").c_str(), tr("STR_SECONDS").arg(weapon->getStandardReload()).c_str()); _lstInfo->setCellColor(3, 1, Palette::blockOffset(15)+4); _lstInfo->addRow(2, tr("STR_ROUNDS").c_str(), Text::formatNumber(weapon->getAmmoMax()).c_str()); _lstInfo->setCellColor(4, 1, Palette::blockOffset(15)+4); centerAllSurfaces(); }
/** * Initializes all the elements in the Craft Weapons window. * @param game Pointer to the core game. * @param base Pointer to the base to get info from. * @param craft ID of the selected craft. * @param weapon ID of the selected weapon. */ CraftWeaponsState::CraftWeaponsState(Base *base, size_t craft, size_t weapon) : _base(base), _craft(craft), _weapon(weapon) { _screen = false; // Create objects _window = new Window(this, 220, 160, 50, 20, POPUP_BOTH); _btnCancel = new TextButton(140, 16, 90, 156); _txtTitle = new Text(208, 17, 56, 28); _txtArmament = new Text(76, 9, 66, 52); _txtQuantity = new Text(50, 9, 140, 52); _txtAmmunition = new Text(68, 17, 200, 44); _lstWeapons = new TextList(188, 80, 58, 68); // Set palette setInterface("craftWeapons"); add(_window, "window", "craftWeapons"); add(_btnCancel, "button", "craftWeapons"); add(_txtTitle, "text", "craftWeapons"); add(_txtArmament, "text", "craftWeapons"); add(_txtQuantity, "text", "craftWeapons"); add(_txtAmmunition, "text", "craftWeapons"); add(_lstWeapons, "list", "craftWeapons"); centerAllSurfaces(); // Set up objects _window->setBackground(_game->getMod()->getSurface("BACK14.SCR")); _btnCancel->setText(tr("STR_CANCEL_UC")); _btnCancel->onMouseClick((ActionHandler)&CraftWeaponsState::btnCancelClick); _btnCancel->onKeyboardPress((ActionHandler)&CraftWeaponsState::btnCancelClick, Options::keyCancel); _txtTitle->setBig(); _txtTitle->setAlign(ALIGN_CENTER); _txtTitle->setText(tr("STR_SELECT_ARMAMENT")); _txtArmament->setText(tr("STR_ARMAMENT")); _txtQuantity->setText(tr("STR_QUANTITY_UC")); _txtAmmunition->setText(tr("STR_AMMUNITION_AVAILABLE")); _txtAmmunition->setWordWrap(true); _txtAmmunition->setVerticalAlign(ALIGN_BOTTOM); _lstWeapons->setColumns(3, 94, 50, 36); _lstWeapons->setSelectable(true); _lstWeapons->setBackground(_window); _lstWeapons->setMargin(8); _lstWeapons->addRow(1, tr("STR_NONE_UC").c_str()); _weapons.push_back(0); const std::vector<std::string> &weapons = _game->getMod()->getCraftWeaponsList(); for (std::vector<std::string>::const_iterator i = weapons.begin(); i != weapons.end(); ++i) { RuleCraftWeapon *w = _game->getMod()->getCraftWeapon(*i); if (_base->getStorageItems()->getItem(w->getLauncherItem()) > 0) { _weapons.push_back(w); std::ostringstream ss, ss2; ss << _base->getStorageItems()->getItem(w->getLauncherItem()); if (!w->getClipItem().empty()) { ss2 << _base->getStorageItems()->getItem(w->getClipItem()); } else { ss2 << tr("STR_NOT_AVAILABLE"); } _lstWeapons->addRow(3, tr(w->getType()).c_str(), ss.str().c_str(), ss2.str().c_str()); } } _lstWeapons->onMouseClick((ActionHandler)&CraftWeaponsState::lstWeaponsClick); }
/** * Loads a ruleset's contents from a YAML file. * Rules that match pre-existing rules overwrite them. * @param filename YAML filename. */ void Ruleset::loadFile(const std::string &filename) { YAML::Node doc = YAML::LoadFile(filename); for (YAML::const_iterator i = doc["countries"].begin(); i != doc["countries"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); RuleCountry *rule; if (_countries.find(type) != _countries.end()) { rule = _countries[type]; } else { rule = new RuleCountry(type); _countries[type] = rule; _countriesIndex.push_back(type); } rule->load(*i); } for (YAML::const_iterator i = doc["regions"].begin(); i != doc["regions"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); RuleRegion *rule; if (_regions.find(type) != _regions.end()) { rule = _regions[type]; } else { rule = new RuleRegion(type); _regions[type] = rule; _regionsIndex.push_back(type); } rule->load(*i); } for (YAML::const_iterator i = doc["facilities"].begin(); i != doc["facilities"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); RuleBaseFacility *rule; if (_facilities.find(type) != _facilities.end()) { rule = _facilities[type]; } else { rule = new RuleBaseFacility(type); _facilities[type] = rule; _facilitiesIndex.push_back(type); } _facilityListOrder += 100; rule->load(*i, _modIndex, _facilityListOrder); } for (YAML::const_iterator i = doc["crafts"].begin(); i != doc["crafts"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); RuleCraft *rule; if (_crafts.find(type) != _crafts.end()) { rule = _crafts[type]; } else { rule = new RuleCraft(type); _crafts[type] = rule; _craftsIndex.push_back(type); } _craftListOrder += 100; rule->load(*i, this, _modIndex, _craftListOrder); } for (YAML::const_iterator i = doc["craftWeapons"].begin(); i != doc["craftWeapons"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); RuleCraftWeapon *rule; if (_craftWeapons.find(type) != _craftWeapons.end()) { rule = _craftWeapons[type]; } else { rule = new RuleCraftWeapon(type); _craftWeapons[type] = rule; _craftWeaponsIndex.push_back(type); } rule->load(*i, _modIndex); } for (YAML::const_iterator i = doc["items"].begin(); i != doc["items"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); RuleItem *rule; if (_items.find(type) != _items.end()) { rule = _items[type]; } else { rule = new RuleItem(type); _items[type] = rule; _itemsIndex.push_back(type); } _itemListOrder += 100; rule->load(*i, _modIndex, _itemListOrder); } for (YAML::const_iterator i = doc["ufos"].begin(); i != doc["ufos"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); RuleUfo *rule; if (_ufos.find(type) != _ufos.end()) { rule = _ufos[type]; } else { rule = new RuleUfo(type); _ufos[type] = rule; _ufosIndex.push_back(type); } rule->load(*i, this); } for (YAML::const_iterator i = doc["invs"].begin(); i != doc["invs"].end(); ++i) { std::string type = (*i)["id"].as<std::string>(); RuleInventory *rule; if (_invs.find(type) != _invs.end()) { rule = _invs[type]; } else { rule = new RuleInventory(type); _invs[type] = rule; } rule->load(*i); } for (YAML::const_iterator i = doc["terrains"].begin(); i != doc["terrains"].end(); ++i) { std::string type = (*i)["name"].as<std::string>(); RuleTerrain *rule; if (_terrains.find(type) != _terrains.end()) { rule = _terrains[type]; } else { rule = new RuleTerrain(type); _terrains[type] = rule; _terrainIndex.push_back(type); } rule->load(*i, this); } for (YAML::const_iterator i = doc["armors"].begin(); i != doc["armors"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); Armor *rule; if (_armors.find(type) != _armors.end()) { rule = _armors[type]; } else { rule = new Armor(type, "", 0); _armors[type] = rule; _armorsIndex.push_back(type); } rule->load(*i); } for (YAML::const_iterator i = doc["soldiers"].begin(); i != doc["soldiers"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); RuleSoldier *rule; if (_soldiers.find(type) != _soldiers.end()) { rule = _soldiers[type]; } else { rule = new RuleSoldier(type); _soldiers[type] = rule; } rule->load(*i); } for (YAML::const_iterator i = doc["units"].begin(); i != doc["units"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); Unit *rule; if (_units.find(type) != _units.end()) { rule = _units[type]; } else { rule = new Unit(type, "", ""); _units[type] = rule; } rule->load(*i); } for (YAML::const_iterator i = doc["alienRaces"].begin(); i != doc["alienRaces"].end(); ++i) { std::string type = (*i)["id"].as<std::string>(); AlienRace *rule; if (_alienRaces.find(type) != _alienRaces.end()) { rule = _alienRaces[type]; } else { rule = new AlienRace(type); _alienRaces[type] = rule; _aliensIndex.push_back(type); } rule->load(*i); } for (YAML::const_iterator i = doc["alienDeployments"].begin(); i != doc["alienDeployments"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); AlienDeployment *rule; if (_alienDeployments.find(type) != _alienDeployments.end()) { rule = _alienDeployments[type]; } else { rule = new AlienDeployment(type); _alienDeployments[type] = rule; _deploymentsIndex.push_back(type); } rule->load(*i); } for (YAML::const_iterator i = doc["research"].begin(); i != doc["research"].end(); ++i) { std::string type = (*i)["name"].as<std::string>(); RuleResearch *rule; if (_research.find(type) != _research.end()) { rule = _research[type]; } else { rule = new RuleResearch(type); _research[type] = rule; _researchIndex.push_back(type); } _researchListOrder += 100; rule->load(*i, _researchListOrder); } for (YAML::const_iterator i = doc["manufacture"].begin(); i != doc["manufacture"].end(); ++i) { std::string type = (*i)["name"].as<std::string>(); RuleManufacture *rule; if (_manufacture.find(type) != _manufacture.end()) { rule = _manufacture[type]; } else { rule = new RuleManufacture(type); _manufacture[type] = rule; _manufactureIndex.push_back(type); } _manufactureListOrder += 100; rule->load(*i, _manufactureListOrder); } for (YAML::const_iterator i = doc["ufopaedia"].begin(); i != doc["ufopaedia"].end(); ++i) { std::string id = (*i)["id"].as<std::string>(); ArticleDefinition *rule; if (_ufopaediaArticles.find(id) != _ufopaediaArticles.end()) { rule = _ufopaediaArticles[id]; } else { UfopaediaTypeId type = (UfopaediaTypeId)(*i)["type_id"].as<int>(); switch (type) { case UFOPAEDIA_TYPE_CRAFT: rule = new ArticleDefinitionCraft(); break; case UFOPAEDIA_TYPE_CRAFT_WEAPON: rule = new ArticleDefinitionCraftWeapon(); break; case UFOPAEDIA_TYPE_VEHICLE: rule = new ArticleDefinitionVehicle(); break; case UFOPAEDIA_TYPE_ITEM: rule = new ArticleDefinitionItem(); break; case UFOPAEDIA_TYPE_ARMOR: rule = new ArticleDefinitionArmor(); break; case UFOPAEDIA_TYPE_BASE_FACILITY: rule = new ArticleDefinitionBaseFacility(); break; case UFOPAEDIA_TYPE_TEXTIMAGE: rule = new ArticleDefinitionTextImage(); break; case UFOPAEDIA_TYPE_TEXT: rule = new ArticleDefinitionText(); break; case UFOPAEDIA_TYPE_UFO: rule = new ArticleDefinitionUfo(); break; default: rule = 0; break; } _ufopaediaArticles[id] = rule; _ufopaediaIndex.push_back(id); } _ufopaediaListOrder += 100; rule->load(*i, _ufopaediaListOrder); } //_startingBase->load(i->second, 0); if (doc["startingBase"]) _startingBase = YAML::Node(doc["startingBase"]); _startingTime.load(doc["startingTime"]); _costSoldier = doc["costSoldier"].as<int>(_costSoldier); _costEngineer = doc["costEngineer"].as<int>(_costEngineer); _costScientist = doc["costScientist"].as<int>(_costScientist); _timePersonnel = doc["timePersonnel"].as<int>(_timePersonnel); for (YAML::const_iterator i = doc["ufoTrajectories"].begin(); i != doc["ufoTrajectories"].end(); ++i) { std::string id = (*i)["id"].as<std::string>(); if (_ufoTrajectories.find(id) != _ufoTrajectories.end()) { _ufoTrajectories[id]->load(*i); } else { std::auto_ptr<UfoTrajectory> rule(new UfoTrajectory); rule->load(*i); _ufoTrajectories[id] = rule.release(); } } for (YAML::const_iterator i = doc["alienMissions"].begin(); i != doc["alienMissions"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); if (_alienMissions.find(type) != _alienMissions.end()) { _alienMissions[type]->load(*i); } else { std::auto_ptr<RuleAlienMission> rule(new RuleAlienMission()); rule->load(*i); _alienMissions[type] = rule.release(); _alienMissionsIndex.push_back(type); } } _alienItemLevels.clear(); for (YAML::const_iterator i = doc["alienItemLevels"].begin(); i != doc["alienItemLevels"].end(); ++i) { std::vector<int> type = (*i).as< std::vector<int> >(); _alienItemLevels.push_back(type); } for (YAML::const_iterator i = doc["MCDPatches"].begin(); i != doc["MCDPatches"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); if (_MCDPatches.find(type) != _MCDPatches.end()) { _MCDPatches[type]->load(*i); } else { std::auto_ptr<MCDPatch> patch(new MCDPatch()); patch->load(*i); _MCDPatches[type] = patch.release(); _MCDPatchesIndex.push_back(type); } } for (YAML::const_iterator i = doc["extraSprites"].begin(); i != doc["extraSprites"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); std::auto_ptr<ExtraSprites> extraSprites(new ExtraSprites()); extraSprites->load(*i, _modIndex); _extraSprites.push_back(std::make_pair(type, extraSprites.release())); _extraSpritesIndex.push_back(type); } for (YAML::const_iterator i = doc["extraSounds"].begin(); i != doc["extraSounds"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); std::auto_ptr<ExtraSounds> extraSounds(new ExtraSounds()); extraSounds->load(*i, _modIndex); _extraSounds.push_back(std::make_pair(type, extraSounds.release())); _extraSoundsIndex.push_back(type); } for (YAML::const_iterator i = doc["extraStrings"].begin(); i != doc["extraStrings"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); if (_extraStrings.find(type) != _extraStrings.end()) { _extraStrings[type]->load(*i); } else { std::auto_ptr<ExtraStrings> extraStrings(new ExtraStrings()); extraStrings->load(*i); _extraStrings[type] = extraStrings.release(); _extraStringsIndex.push_back(type); } } _modIndex += 1000; }
/** * Initializes all the elements in the Sell/Sack screen. * @param game Pointer to the core game. * @param base Pointer to the base to get info from. * @param origin Game section that originated this state. */ SellState::SellState(Base *base, OptionsOrigin origin) : _base(base), _sel(0), _total(0), _spaceChange(0), _origin(origin) { bool overfull = Options::storageLimitsEnforced && _base->storesOverfull(); // Create objects _window = new Window(this, 320, 200, 0, 0); _btnOk = new TextButton(overfull? 288:148, 16, overfull? 16:8, 176); _btnCancel = new TextButton(148, 16, 164, 176); _txtTitle = new Text(310, 17, 5, 8); _txtSales = new Text(150, 9, 10, 24); _txtFunds = new Text(150, 9, 160, 24); _txtSpaceUsed = new Text(150, 9, 160, 34); _txtQuantity = new Text(54, 9, 136, 44); _txtSell = new Text(96, 9, 190, 44); _txtValue = new Text(40, 9, 270, 44); _cbxCategory = new ComboBox(this, 120, 16, 10, 36); _lstItems = new TextList(287, 120, 8, 54); // Set palette setInterface("sellMenu"); _ammoColor = _game->getMod()->getInterface("sellMenu")->getElement("ammoColor")->color; add(_window, "window", "sellMenu"); add(_btnOk, "button", "sellMenu"); add(_btnCancel, "button", "sellMenu"); add(_txtTitle, "text", "sellMenu"); add(_txtSales, "text", "sellMenu"); add(_txtFunds, "text", "sellMenu"); add(_txtSpaceUsed, "text", "sellMenu"); add(_txtQuantity, "text", "sellMenu"); add(_txtSell, "text", "sellMenu"); add(_txtValue, "text", "sellMenu"); add(_lstItems, "list", "sellMenu"); add(_cbxCategory, "text", "sellMenu"); centerAllSurfaces(); // Set up objects _window->setBackground(_game->getMod()->getSurface("BACK13.SCR")); _btnOk->setText(tr("STR_SELL_SACK")); _btnOk->onMouseClick((ActionHandler)&SellState::btnOkClick); _btnOk->onKeyboardPress((ActionHandler)&SellState::btnOkClick, Options::keyOk); _btnCancel->setText(tr("STR_CANCEL")); _btnCancel->onMouseClick((ActionHandler)&SellState::btnCancelClick); _btnCancel->onKeyboardPress((ActionHandler)&SellState::btnCancelClick, Options::keyCancel); if (overfull) { _btnCancel->setVisible(false); _btnOk->setVisible(false); } _txtTitle->setBig(); _txtTitle->setAlign(ALIGN_CENTER); _txtTitle->setText(tr("STR_SELL_ITEMS_SACK_PERSONNEL")); _txtSales->setText(tr("STR_VALUE_OF_SALES").arg(Unicode::formatFunding(_total))); _txtFunds->setText(tr("STR_FUNDS").arg(Unicode::formatFunding(_game->getSavedGame()->getFunds()))); _txtSpaceUsed->setVisible(Options::storageLimitsEnforced); std::ostringstream ss; ss << _base->getUsedStores() << ":" << _base->getAvailableStores(); _txtSpaceUsed->setText(ss.str()); _txtSpaceUsed->setText(tr("STR_SPACE_USED").arg(ss.str())); _txtQuantity->setText(tr("STR_QUANTITY_UC")); _txtSell->setText(tr("STR_SELL_SACK")); _txtValue->setText(tr("STR_VALUE")); _lstItems->setArrowColumn(182, ARROW_VERTICAL); _lstItems->setColumns(4, 156, 54, 24, 53); _lstItems->setSelectable(true); _lstItems->setBackground(_window); _lstItems->setMargin(2); _lstItems->onLeftArrowPress((ActionHandler)&SellState::lstItemsLeftArrowPress); _lstItems->onLeftArrowRelease((ActionHandler)&SellState::lstItemsLeftArrowRelease); _lstItems->onLeftArrowClick((ActionHandler)&SellState::lstItemsLeftArrowClick); _lstItems->onRightArrowPress((ActionHandler)&SellState::lstItemsRightArrowPress); _lstItems->onRightArrowRelease((ActionHandler)&SellState::lstItemsRightArrowRelease); _lstItems->onRightArrowClick((ActionHandler)&SellState::lstItemsRightArrowClick); _lstItems->onMousePress((ActionHandler)&SellState::lstItemsMousePress); _cats.push_back("STR_ALL_ITEMS"); const std::vector<std::string> &cw = _game->getMod()->getCraftWeaponsList(); for (std::vector<std::string>::const_iterator i = cw.begin(); i != cw.end(); ++i) { RuleCraftWeapon *rule = _game->getMod()->getCraftWeapon(*i); _craftWeapons.insert(rule->getLauncherItem()); _craftWeapons.insert(rule->getClipItem()); } const std::vector<std::string> &ar = _game->getMod()->getArmorsList(); for (std::vector<std::string>::const_iterator i = ar.begin(); i != ar.end(); ++i) { Armor *rule = _game->getMod()->getArmor(*i); _armors.insert(rule->getStoreItem()); } for (std::vector<Soldier*>::iterator i = _base->getSoldiers()->begin(); i != _base->getSoldiers()->end(); ++i) { if ((*i)->getCraft() == 0) { TransferRow row = { TRANSFER_SOLDIER, (*i), (*i)->getName(true), 0, 1, 0, 0 }; _items.push_back(row); std::string cat = getCategory(_items.size() - 1); if (std::find(_cats.begin(), _cats.end(), cat) == _cats.end()) { _cats.push_back(cat); } } } for (std::vector<Craft*>::iterator i = _base->getCrafts()->begin(); i != _base->getCrafts()->end(); ++i) { if ((*i)->getStatus() != "STR_OUT") { TransferRow row = { TRANSFER_CRAFT, (*i), (*i)->getName(_game->getLanguage()), (*i)->getRules()->getSellCost(), 1, 0, 0 }; _items.push_back(row); std::string cat = getCategory(_items.size() - 1); if (std::find(_cats.begin(), _cats.end(), cat) == _cats.end()) { _cats.push_back(cat); } } } if (_base->getAvailableScientists() > 0) { TransferRow row = { TRANSFER_SCIENTIST, 0, tr("STR_SCIENTIST"), 0, _base->getAvailableScientists(), 0, 0 }; _items.push_back(row); std::string cat = getCategory(_items.size() - 1); if (std::find(_cats.begin(), _cats.end(), cat) == _cats.end()) { _cats.push_back(cat); } } if (_base->getAvailableEngineers() > 0) { TransferRow row = { TRANSFER_ENGINEER, 0, tr("STR_ENGINEER"), 0, _base->getAvailableEngineers(), 0, 0 }; _items.push_back(row); std::string cat = getCategory(_items.size() - 1); if (std::find(_cats.begin(), _cats.end(), cat) == _cats.end()) { _cats.push_back(cat); } } const std::vector<std::string> &items = _game->getMod()->getItemsList(); for (std::vector<std::string>::const_iterator i = items.begin(); i != items.end(); ++i) { int qty = _base->getStorageItems()->getItem(*i); if (Options::storageLimitsEnforced && _origin == OPT_BATTLESCAPE) { for (std::vector<Transfer*>::iterator j = _base->getTransfers()->begin(); j != _base->getTransfers()->end(); ++j) { if ((*j)->getItems() == *i) { qty += (*j)->getQuantity(); } } for (std::vector<Craft*>::iterator j = _base->getCrafts()->begin(); j != _base->getCrafts()->end(); ++j) { qty += (*j)->getItems()->getItem(*i); } } RuleItem *rule = _game->getMod()->getItem(*i, true); if (qty > 0 && (Options::canSellLiveAliens || !rule->isAlien())) { TransferRow row = { TRANSFER_ITEM, rule, tr(*i), rule->getSellCost(), qty, 0, 0 }; _items.push_back(row); std::string cat = getCategory(_items.size() - 1); if (std::find(_cats.begin(), _cats.end(), cat) == _cats.end()) { _cats.push_back(cat); } } } _cbxCategory->setOptions(_cats, true); _cbxCategory->onChange((ActionHandler)&SellState::cbxCategoryChange); updateList(); _timerInc = new Timer(250); _timerInc->onTimer((StateHandler)&SellState::increase); _timerDec = new Timer(250); _timerDec->onTimer((StateHandler)&SellState::decrease); }
/** * Loads the craft from a YAML file. * @param node YAML node. * @param mod Mod for the saved game. * @param save Pointer to the saved game. */ void Craft::load(const YAML::Node &node, const Mod *mod, SavedGame *save) { MovingTarget::load(node); _id = node["id"].as<int>(_id); _fuel = node["fuel"].as<int>(_fuel); _damage = node["damage"].as<int>(_damage); int j = 0; for (YAML::const_iterator i = node["weapons"].begin(); i != node["weapons"].end(); ++i) { if (_rules->getWeapons() > j) { std::string type = (*i)["type"].as<std::string>(); RuleCraftWeapon* weapon = mod->getCraftWeapon(type); if (type != "0" && weapon) { CraftWeapon *w = new CraftWeapon(weapon, 0); w->load(*i); _weapons[j] = w; _stats += weapon->getBonusStats(); } else { _weapons[j] = 0; } j++; } } _items->load(node["items"]); for (std::map<std::string, int>::iterator i = _items->getContents()->begin(); i != _items->getContents()->end();) { if (std::find(mod->getItemsList().begin(), mod->getItemsList().end(), i->first) == mod->getItemsList().end()) { _items->getContents()->erase(i++); } else { ++i; } } for (YAML::const_iterator i = node["vehicles"].begin(); i != node["vehicles"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); if (mod->getItem(type)) { Vehicle *v = new Vehicle(mod->getItem(type), 0, 4); v->load(*i); _vehicles.push_back(v); } } _status = node["status"].as<std::string>(_status); _lowFuel = node["lowFuel"].as<bool>(_lowFuel); _mission = node["mission"].as<bool>(_mission); _interceptionOrder = node["interceptionOrder"].as<int>(_interceptionOrder); if (const YAML::Node name = node["name"]) { _name = Language::utf8ToWstr(name.as<std::string>()); } if (const YAML::Node &dest = node["dest"]) { std::string type = dest["type"].as<std::string>(); int id = dest["id"].as<int>(); if (type == "STR_BASE") { returnToBase(); } else if (type == "STR_UFO") { for (std::vector<Ufo*>::iterator i = save->getUfos()->begin(); i != save->getUfos()->end(); ++i) { if ((*i)->getId() == id) { setDestination(*i); break; } } } else if (type == "STR_WAYPOINT") { for (std::vector<Waypoint*>::iterator i = save->getWaypoints()->begin(); i != save->getWaypoints()->end(); ++i) { if ((*i)->getId() == id) { setDestination(*i); break; } } } else if (type == "STR_ALIEN_BASE") { for (std::vector<AlienBase*>::iterator i = save->getAlienBases()->begin(); i != save->getAlienBases()->end(); ++i) { if ((*i)->getId() == id) { setDestination(*i); break; } } } else { // Backwards compatibility if (type == "STR_ALIEN_TERROR") type = "STR_TERROR_SITE"; for (std::vector<MissionSite*>::iterator i = save->getMissionSites()->begin(); i != save->getMissionSites()->end(); ++i) { if ((*i)->getId() == id && (*i)->getDeployment()->getMarkerName() == type) { setDestination(*i); break; } } } } _takeoff = node["takeoff"].as<int>(_takeoff); _inBattlescape = node["inBattlescape"].as<bool>(_inBattlescape); if (_inBattlescape) setSpeed(0); }
/** * Initializes all the elements in the Craft Weapons window. * @param game Pointer to the core game. * @param base Pointer to the base to get info from. * @param craft ID of the selected craft. * @param weapon ID of the selected weapon. */ CraftWeaponsState::CraftWeaponsState(Game *game, Base *base, size_t craft, size_t weapon) : State(game), _base(base), _craft(craft), _weapon(weapon), _weapons() { _screen = false; // Create objects _window = new Window(this, 220, 160, 50, 20, POPUP_BOTH); _btnCancel = new TextButton(140, 16, 90, 156); _txtTitle = new Text(208, 17, 56, 28); _txtArmament = new Text(76, 9, 66, 52); _txtQuantity = new Text(50, 9, 140, 52); _txtAmmunition = new Text(68, 17, 200, 44); _lstWeapons = new TextList(188, 80, 58, 68); // Set palette _game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(4)), Palette::backPos, 16); add(_window); add(_btnCancel); add(_txtTitle); add(_txtArmament); add(_txtQuantity); add(_txtAmmunition); add(_lstWeapons); centerAllSurfaces(); // Set up objects _window->setColor(Palette::blockOffset(15)+6); _window->setBackground(_game->getResourcePack()->getSurface("BACK14.SCR")); _btnCancel->setColor(Palette::blockOffset(15)+6); _btnCancel->setText(tr("STR_CANCEL_UC")); _btnCancel->onMouseClick((ActionHandler)&CraftWeaponsState::btnCancelClick); _btnCancel->onKeyboardPress((ActionHandler)&CraftWeaponsState::btnCancelClick, (SDLKey)Options::getInt("keyCancel")); _txtTitle->setColor(Palette::blockOffset(15)+6); _txtTitle->setBig(); _txtTitle->setAlign(ALIGN_CENTER); _txtTitle->setText(tr("STR_SELECT_ARMAMENT")); _txtArmament->setColor(Palette::blockOffset(15)+6); _txtArmament->setText(tr("STR_ARMAMENT")); _txtQuantity->setColor(Palette::blockOffset(15)+6); _txtQuantity->setText(tr("STR_QUANTITY_UC")); _txtAmmunition->setColor(Palette::blockOffset(15)+6); _txtAmmunition->setText(tr("STR_AMMUNITION_AVAILABLE")); _txtAmmunition->setWordWrap(true); _lstWeapons->setColor(Palette::blockOffset(13)+10); _lstWeapons->setArrowColor(Palette::blockOffset(15)+6); _lstWeapons->setColumns(3, 94, 50, 36); _lstWeapons->setSelectable(true); _lstWeapons->setBackground(_window); _lstWeapons->setMargin(8); _lstWeapons->addRow(1, tr("STR_NONE_UC").c_str()); _weapons.push_back(0); const std::vector<std::string> &weapons = _game->getRuleset()->getCraftWeaponsList(); for (std::vector<std::string>::const_iterator i = weapons.begin(); i != weapons.end(); ++i) { RuleCraftWeapon *w = _game->getRuleset()->getCraftWeapon(*i); if (_base->getItems()->getItem(w->getLauncherItem()) > 0) { _weapons.push_back(w); std::wstringstream ss, ss2; ss << _base->getItems()->getItem(w->getLauncherItem()); if (w->getClipItem() != "") { ss2 << _base->getItems()->getItem(w->getClipItem()); } else { ss2 << tr("STR_NOT_AVAILABLE"); } _lstWeapons->addRow(3, tr(w->getType()).c_str(), ss.str().c_str(), ss2.str().c_str()); } } _lstWeapons->onMouseClick((ActionHandler)&CraftWeaponsState::lstWeaponsClick); }