/** * Equips the weapon on the craft and returns to the previous screen. * @param action Pointer to an action. */ void CraftWeaponsState::lstWeaponsClick(Action *) { CraftWeapon *current = _base->getCrafts()->at(_craft)->getWeapons()->at(_weapon); // Remove current weapon if (current != 0) { _base->getStorageItems()->addItem(current->getRules()->getLauncherItem()); _base->getStorageItems()->addItem(current->getRules()->getClipItem(), current->getClipsLoaded(_game->getMod())); delete current; _base->getCrafts()->at(_craft)->getWeapons()->at(_weapon) = 0; } // Equip new weapon if (_weapons[_lstWeapons->getSelectedRow()] != 0) { CraftWeapon *sel = new CraftWeapon(_weapons[_lstWeapons->getSelectedRow()], 0); sel->setRearming(true); _base->getStorageItems()->removeItem(sel->getRules()->getLauncherItem()); _base->getCrafts()->at(_craft)->getWeapons()->at(_weapon) = sel; if (_base->getCrafts()->at(_craft)->getStatus() == "STR_READY") { _base->getCrafts()->at(_craft)->setStatus("STR_REARMING"); } } _game->popState(); }
/** * Equips the weapon on the craft and returns to the previous screen. * @note Ammo consumption currently disabled for testing purposes. * @param action Pointer to an action. */ void CraftWeaponsState::lstWeaponsClick(Action *action) { CraftWeapon *current = _base->getCrafts()->at(_craft)->getWeapons()->at(_weapon); // Remove current weapon if (current != 0) { _base->getItems()->addItem(current->getRules()->getLauncherItem()); _base->getItems()->addItem(current->getRules()->getClipItem()), (int)floor((double)current->getAmmo() / current->getRules()->getRearmRate()); delete current; _base->getCrafts()->at(_craft)->getWeapons()->at(_weapon) = 0; } // Equip new weapon if (_weapons[_lstWeapons->getSelectedRow()] != 0) { CraftWeapon *sel = new CraftWeapon(_weapons[_lstWeapons->getSelectedRow()], 0); _base->getItems()->removeItem(sel->getRules()->getLauncherItem()); _base->getCrafts()->at(_craft)->getWeapons()->at(_weapon) = sel; if (_base->getCrafts()->at(_craft)->getStatus() == "STR_READY") { _base->getCrafts()->at(_craft)->setStatus("STR_REARMING"); } } _game->popState(); }
/** * 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); size_t 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>(); if (type != "0" && mod->getCraftWeapon(type)) { CraftWeapon *w = new CraftWeapon(mod->getCraftWeapon(type), 0); w->load(*i); _weapons[j] = w; } 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); }