MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / step

Method step

src/Savegame/Production.cpp:102–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102productionProgress_e Production::step(Base * b, SavedGame * g, const Ruleset *r)
103{
104 int done = getAmountProduced ();
105 _timeSpent += _engineers;
106 if (done < getAmountProduced ())
107 {
108 int produced = std::min(getAmountProduced(), _amount) - done; // std::min is required because we don't want to overproduce
109 int count = 0;
110 do
111 {
112 for (std::map<std::string,int>::const_iterator i = _rules->getProducedItems().begin(); i != _rules->getProducedItems().end(); ++i)
113 {
114 if (_rules->getCategory() == "STR_CRAFT")
115 {
116 Craft *craft = new Craft(r->getCraft(i->first), b, g->getId(i->first));
117 craft->setStatus("STR_REFUELLING");
118 b->getCrafts()->push_back(craft);
119 break;
120 }
121 else
122 {
123 // Check if it's ammo to reload a craft
124 if (r->getItem(i->first)->getBattleType() == BT_NONE)
125 {
126 for (std::vector<Craft*>::iterator c = b->getCrafts()->begin(); c != b->getCrafts()->end(); ++c)
127 {
128 if ((*c)->getStatus() != "STR_READY")
129 continue;
130 for (std::vector<CraftWeapon*>::iterator w = (*c)->getWeapons()->begin(); w != (*c)->getWeapons()->end(); ++w)
131 {
132 if ((*w) != 0 && (*w)->getRules()->getClipItem() == i->first && (*w)->getAmmo() < (*w)->getRules()->getAmmoMax())
133 {
134 (*w)->setRearming(true);
135 (*c)->setStatus("STR_REARMING");
136 }
137 }
138 }
139 }
140 // Check if it's fuel to refuel a craft
141 if (r->getItem(i->first)->getBattleType() == BT_NONE)
142 {
143 for (std::vector<Craft*>::iterator c = b->getCrafts()->begin(); c != b->getCrafts()->end(); ++c)
144 {
145 if ((*c)->getStatus() != "STR_READY")
146 continue;
147 if ((*c)->getRules()->getRefuelItem() == i->first && 100 > (*c)->getFuelPercentage())
148 (*c)->setStatus("STR_REFUELLING");
149 }
150 }
151 if (getSellItems())
152 g->setFunds(g->getFunds() + (r->getItem(i->first)->getSellCost() * i->second));
153 else
154 b->getItems()->addItem(i->first, i->second);
155 }
156 }
157 if (!Options::canManufactureMoreItemsPerHour) break;
158 count++;
159 if (count < produced)

Callers 2

time1HourMethod · 0.45
time1DayMethod · 0.45

Calls 15

getCategoryMethod · 0.80
getBattleTypeMethod · 0.80
getClipItemMethod · 0.80
getAmmoMaxMethod · 0.80
setRearmingMethod · 0.80
getRefuelItemMethod · 0.80
getFuelPercentageMethod · 0.80
setFundsMethod · 0.80
getFundsMethod · 0.80
getCraftMethod · 0.45
getIdMethod · 0.45
setStatusMethod · 0.45

Tested by

no test coverage detected