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; }
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); } }
productionProgress_e Production::step(Base * b, SavedGame * g, const Mod *m) { int done = getAmountProduced(); _timeSpent += _engineers; if (done < getAmountProduced()) { int produced; if (!getInfiniteAmount()) { produced = std::min(getAmountProduced(), _amount) - done; // std::min is required because we don't want to overproduce } else { produced = getAmountProduced() - done; } int count = 0; do { for (std::map<std::string,int>::const_iterator i = _rules->getProducedItems().begin(); i != _rules->getProducedItems().end(); ++i) { if (_rules->getCategory() == "STR_CRAFT") { Craft *craft = new Craft(m->getCraft(i->first, true), b, g->getId(i->first)); craft->setStatus("STR_REFUELLING"); b->getCrafts()->push_back(craft); break; } else { if (m->getItem(i->first, true)->getBattleType() == BT_NONE) { for (std::vector<Craft*>::iterator c = b->getCrafts()->begin(); c != b->getCrafts()->end(); ++c) { (*c)->reuseItem(i->first); } } if (getSellItems()) g->setFunds(g->getFunds() + (m->getItem(i->first, true)->getSellCost() * i->second)); else b->getStorageItems()->addItem(i->first, i->second); } } 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, m)) return PROGRESS_NOT_ENOUGH_MATERIALS; startItem(b, g, m); } } while (count < produced); } if (getAmountProduced() >= _amount && !getInfiniteAmount()) 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, m)) return PROGRESS_NOT_ENOUGH_MATERIALS; startItem(b, g, m); } return PROGRESS_NOT_COMPLETE; }
productionProgress_e Production::step(Base * b, SavedGame * g, const Mod *m, Language *lang) { int done = getAmountProduced(); _timeSpent += _engineers; if (done < getAmountProduced()) { int produced; if (!getInfiniteAmount()) { produced = std::min(getAmountProduced(), _amount) - done; // std::min is required because we don't want to overproduce } else { produced = getAmountProduced() - done; } int count = 0; do { for (std::map<std::string,int>::const_iterator i = _rules->getProducedItems().begin(); i != _rules->getProducedItems().end(); ++i) { if (_rules->getCategory() == "STR_CRAFT") { Craft *craft = new Craft(m->getCraft(i->first, true), b, g->getId(i->first)); craft->setStatus("STR_REFUELLING"); b->getCrafts()->push_back(craft); break; } else if (_rules->getCategory() == "STR_VEHICLE") { Soldier *soldier = m->genSoldier(g, i->first); b->getSoldiers()->push_back(soldier); break; } else { if (m->getItem(i->first, true)->getBattleType() == BT_NONE) { for (std::vector<Craft*>::iterator c = b->getCrafts()->begin(); c != b->getCrafts()->end(); ++c) { (*c)->reuseItem(i->first); } } if (getSellItems()) g->setFunds(g->getFunds() + (m->getItem(i->first, true)->getSellCost() * i->second)); else b->getStorageItems()->addItem(i->first, i->second); } } // Spawn persons (soldiers, engineers, scientists, ...) const std::string &spawnedPersonType = _rules->getSpawnedPersonType(); if (spawnedPersonType != "") { if (spawnedPersonType == "STR_SCIENTIST") { Transfer *t = new Transfer(24); t->setScientists(1); b->getTransfers()->push_back(t); } else if (spawnedPersonType == "STR_ENGINEER") { Transfer *t = new Transfer(24); t->setEngineers(1); b->getTransfers()->push_back(t); } else { RuleSoldier *rule = m->getSoldier(spawnedPersonType); if (rule != 0) { Transfer *t = new Transfer(24); Soldier *s = m->genSoldier(g, rule->getType()); if (_rules->getSpawnedPersonName() != "") { s->setName(lang->getString(_rules->getSpawnedPersonName())); } t->setSoldier(s); b->getTransfers()->push_back(t); } } } 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, m)) return PROGRESS_NOT_ENOUGH_MATERIALS; startItem(b, g, m); } } while (count < produced); } if (getAmountProduced() >= _amount && !getInfiniteAmount()) 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 (!haveEnoughLivingSpaceForOneMoreUnit(b)) return PROGRESS_NOT_ENOUGH_LIVING_SPACE; if (!haveEnoughMaterialsForOneMoreUnit(b, m)) return PROGRESS_NOT_ENOUGH_MATERIALS; startItem(b, g, m); } return PROGRESS_NOT_COMPLETE; }
productionProgress_e Production::step(Base * b, SavedGame * g, const Ruleset *r) { int done = getAmountProduced(); _timeSpent += _engineers; if (!Options::canManufactureMoreItemsPerHour && done < getAmountProduced()) { // enforce pre-TFTD manufacturing rules: extra hours are wasted _timeSpent = (done + 1) * _rules->getManufactureTime(); } if (done < getAmountProduced()) { int produced; if (!getInfiniteAmount()) { produced = std::min(getAmountProduced(), _amount) - done; // std::min is required because we don't want to overproduce } else { produced = getAmountProduced() - done; } int count = 0; do { for (std::map<std::string,int>::const_iterator i = _rules->getProducedItems().begin(); i != _rules->getProducedItems().end(); ++i) { if (_rules->getCategory() == "STR_CRAFT") { Craft *craft = new Craft(r->getCraft(i->first), b, g->getId(i->first)); craft->setStatus("STR_REFUELLING"); b->getCrafts()->push_back(craft); break; } else { // Check if it's ammo to reload a craft if (r->getItem(i->first)->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() == i->first && (*w)->getAmmo() < (*w)->getRules()->getAmmoMax()) { (*w)->setRearming(true); (*c)->setStatus("STR_REARMING"); } } } } // Check if it's fuel to refuel a craft if (r->getItem(i->first)->getBattleType() == BT_NONE) { for (std::vector<Craft*>::iterator c = b->getCrafts()->begin(); c != b->getCrafts()->end(); ++c) { if ((*c)->getStatus() != "STR_READY") continue; if ((*c)->getRules()->getRefuelItem() == i->first && 100 > (*c)->getFuelPercentage()) (*c)->setStatus("STR_REFUELLING"); } } if (getSellItems()) g->setFunds(g->getFunds() + (r->getItem(i->first)->getSellCost() * i->second)); else b->getItems()->addItem(i->first, i->second); } } 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 && !getInfiniteAmount()) 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; }