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

Method init

src/Battlescape/InventoryState.cpp:213–296  ·  view source on GitHub ↗

* Updates all soldier stats when the soldier changes. */

Source from the content-addressed store, hash-verified

211 * Updates all soldier stats when the soldier changes.
212 */
213void InventoryState::init()
214{
215 State::init();
216 BattleUnit *unit = _battleGame->getSelectedUnit();
217
218 // no selected unit, close inventory
219 if (unit == 0)
220 {
221 btnOkClick(0);
222 return;
223 }
224 // skip to the first unit with inventory
225 if (!unit->hasInventory())
226 {
227 if (_parent)
228 {
229 _parent->selectNextPlayerUnit(false, false, true);
230 }
231 else
232 {
233 _battleGame->selectNextPlayerUnit(false, false, true);
234 }
235 // no available unit, close inventory
236 if (_battleGame->getSelectedUnit() == 0 || !_battleGame->getSelectedUnit()->hasInventory())
237 {
238 // starting a mission with just vehicles
239 btnOkClick(0);
240 return;
241 }
242 else
243 {
244 unit = _battleGame->getSelectedUnit();
245 }
246 }
247
248 if (_parent)
249 _parent->getMap()->getCamera()->centerOnPosition(unit->getPosition(), false);
250
251 unit->setCache(0);
252 _soldier->clear();
253 _btnRank->clear();
254
255 _txtName->setBig();
256 _txtName->setText(unit->getName(_game->getLanguage()));
257 _inv->setSelectedUnit(unit);
258 Soldier *s = _game->getSavedGame()->getSoldier(unit->getId());
259 if (s)
260 {
261 SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK");
262 texture->getFrame(s->getRankSprite())->setX(0);
263 texture->getFrame(s->getRankSprite())->setY(0);
264 texture->getFrame(s->getRankSprite())->blit(_btnRank);
265
266 std::string look = s->getArmor()->getSpriteInventory();
267 if (s->getGender() == GENDER_MALE)
268 look += "M";
269 else
270 look += "F";

Callers

nothing calls this directly

Calls 15

initFunction · 0.85
fileExistsFunction · 0.85
getDataFileFunction · 0.85
getSelectedUnitMethod · 0.80
hasInventoryMethod · 0.80
centerOnPositionMethod · 0.80
getCameraMethod · 0.80
setCacheMethod · 0.80
getLanguageMethod · 0.80
getSavedGameMethod · 0.80
getSurfaceSetMethod · 0.80
getFrameMethod · 0.80

Tested by

no test coverage detected