void Production::load(const YAML::Node &node) { setAssignedEngineers(node["assigned"].as<int>(getAssignedEngineers())); setTimeSpent(node["spent"].as<int>(getTimeSpent())); setAmountTotal(node["amount"].as<int>(getAmountTotal())); setInfiniteAmount(node["infinite"].as<bool>(getInfiniteAmount())); setSellItems(node["sell"].as<bool>(getSellItems())); // backwards compatibility if (getAmountTotal() == INT_MAX) { setAmountTotal(999); setInfiniteAmount(true); setSellItems(true); } }
void Production::save(YAML::Emitter &out) { out << YAML::BeginMap; out << YAML::Key << "item" << YAML::Value << getRules ()->getName (); out << YAML::Key << "assigned" << YAML::Value << getAssignedEngineers (); out << YAML::Key << "spent" << YAML::Value << getTimeSpent (); out << YAML::Key << "amount" << YAML::Value << getAmountTotal (); out << YAML::EndMap; }
YAML::Node Production::save() const { YAML::Node node; node["item"] = getRules ()->getName (); node["assigned"] = getAssignedEngineers (); node["spent"] = getTimeSpent (); node["amount"] = getAmountTotal (); return node; }
YAML::Node Production::save() const { YAML::Node node; node["item"] = getRules()->getName(); node["assigned"] = getAssignedEngineers(); node["spent"] = getTimeSpent(); node["amount"] = getAmountTotal(); node["infinite"] = getInfiniteAmount(); if (getSellItems()) node["sell"] = getSellItems(); return node; }
productionProgress_e Production::step(Base * b, SavedGame * g, const Ruleset *r) { int done = getAmountProduced (); _timeSpent += _engineers; if (done < getAmountProduced ()) { bool allowAutoSellProduction = Options::getBool("allowAutoSellProduction"); bool canManufactureMoreItemsPerHour = Options::getBool("canManufactureMoreItemsPerHour"); int produced = std::min(getAmountProduced(), _amount) - done; // std::min is required because we don't want to overproduce int count = 0; do { if (_rules->getCategory() == "STR_CRAFT") { Craft *craft = new Craft(r->getCraft(_rules->getName()), b, g->getId(_rules->getName())); craft->setStatus("STR_REFUELLING"); b->getCrafts()->push_back(craft); } else { // Check if it's ammo to reload a craft if (r->getItem(_rules->getName())->getBattleType() == BT_NONE) { for (std::vector<Craft*>::iterator c = b->getCrafts()->begin(); c != b->getCrafts()->end(); ++c) { if ((*c)->getStatus() != "STR_READY") continue; for (std::vector<CraftWeapon*>::iterator w = (*c)->getWeapons()->begin(); w != (*c)->getWeapons()->end(); ++w) { if ((*w) != 0 && (*w)->getRules()->getClipItem() == _rules->getName() && (*w)->getAmmo() < (*w)->getRules()->getAmmoMax()) { (*w)->setRearming(true); (*c)->setStatus("STR_REARMING"); } } } } if (allowAutoSellProduction && getAmountTotal() == std::numeric_limits<int>::max()) g->setFunds(g->getFunds() + r->getItem(_rules->getName())->getSellCost()); else b->getItems()->addItem(_rules->getName(), 1); } if (!canManufactureMoreItemsPerHour) break; count++; if (count < produced) { // We need to ensure that player has enough cash/item to produce a new unit if (!haveEnoughMoneyForOneMoreUnit(g)) return PROGRESS_NOT_ENOUGH_MONEY; if (!haveEnoughMaterialsForOneMoreUnit(b)) return PROGRESS_NOT_ENOUGH_MATERIALS; startItem(b,g); } } while (count < produced); } if (getAmountProduced () >= _amount) return PROGRESS_COMPLETE; if (done < getAmountProduced ()) { // We need to ensure that player has enough cash/item to produce a new unit if (!haveEnoughMoneyForOneMoreUnit(g)) return PROGRESS_NOT_ENOUGH_MONEY; if (!haveEnoughMaterialsForOneMoreUnit(b)) return PROGRESS_NOT_ENOUGH_MATERIALS; startItem(b,g); } return PROGRESS_NOT_COMPLETE; }