/* * Convert unit to corpse(item). */ void UnitDieBState::convertUnitToCorpse() { // in case the unit was unconscious _parent->getSave()->removeUnconsciousBodyItem(_unit); int size = _unit->getArmor()->getSize() - 1; // move inventory from unit to the ground for non-large units if (size == 0) { for (std::vector<BattleItem*>::iterator i = _unit->getInventory()->begin(); i != _unit->getInventory()->end(); ++i) { _parent->dropItem(_unit->getPosition(), (*i)); } } _unit->getInventory()->clear(); // remove unit-tile link _unit->setTile(0); if (size == 0) { BattleItem *corpse = new BattleItem(_parent->getRuleset()->getItem(_unit->getArmor()->getCorpseItem()),_parent->getSave()->getCurrentItemId()); corpse->setUnit(_unit); _parent->dropItem(_unit->getPosition(), corpse, true); _parent->getSave()->getTile(_unit->getPosition())->setUnit(0); } else { Position p = _unit->getPosition(); int i = 1; for (int y = 0; y <= size; y++) { for (int x = 0; x <= size; x++) { std::stringstream ss; ss << _unit->getArmor()->getCorpseItem() << i; BattleItem *corpse = new BattleItem(_parent->getRuleset()->getItem(ss.str()),_parent->getSave()->getCurrentItemId()); corpse->setUnit(_unit); // no need for this, because large units never can be revived as they don't go unconscious // yes there freaking is because yes they freaking do, nerf their consciousness elswhere, // because we need to recover live reapers and i need this kept track of for corpse recovery. also i hate reapers. _parent->dropItem(p + Position(x,y,0), corpse, true); _parent->getSave()->getTile(p + Position(x,y,0))->setUnit(0); i++; } } } }
/* * Convert unit to corpse(item). * @param unit * @param terrain */ void UnitDieBState::convertUnitToCorpse(BattleUnit *unit, TileEngine *terrain) { int size = _unit->getUnit()->getArmor()->getSize() - 1; // move inventory from unit to the ground for non-large units if (size == 0) { for (std::vector<BattleItem*>::iterator i = _unit->getInventory()->begin(); i != _unit->getInventory()->end(); ++i) { _parent->dropItem(_unit->getPosition(), (*i)); } } _unit->getInventory()->clear(); // remove unit-tile link _unit->setTile(0); if (size == 0) { _parent->getGame()->getSavedGame()->getBattleGame()->getTile(_unit->getPosition())->setUnit(0); BattleItem *corpse = new BattleItem(_parent->getGame()->getRuleset()->getItem(_unit->getUnit()->getArmor()->getCorpseItem()),_parent->getGame()->getSavedGame()->getBattleGame()->getCurrentItemId()); corpse->setUnit(unit); _parent->dropItem(_unit->getPosition(), corpse, true); } else { int i = 1; for (int y = 0; y <= size; y++) { for (int x = 0; x <= size; x++) { _parent->getGame()->getSavedGame()->getBattleGame()->getTile(_unit->getPosition() + Position(x,y,0))->setUnit(0); std::stringstream ss; ss << _unit->getUnit()->getArmor()->getCorpseItem() << i; BattleItem *corpse = new BattleItem(_parent->getGame()->getRuleset()->getItem(ss.str()),_parent->getGame()->getSavedGame()->getBattleGame()->getCurrentItemId()); //corpse->setUnit(unit); // no need for this, because large units never can be revived as they don't go unconscious _parent->dropItem(_unit->getPosition() + Position(x,y,0), corpse, true); i++; } } } }
/** * Converts unit to a corpse (item). */ void UnitDieBState::convertUnitToCorpse() { _parent->getSave()->getBattleState()->showPsiButton(false); Position lastPosition = _unit->getPosition(); // remove the unconscious body item corresponding to this unit, and if it was being carried, keep track of what slot it was in if (lastPosition != Position(-1,-1,-1)) { _parent->getSave()->removeUnconsciousBodyItem(_unit); } int size = _unit->getArmor()->getSize(); BattleItem *itemToKeep = 0; bool dropItems = !Options::weaponSelfDestruction || (_unit->getOriginalFaction() != FACTION_HOSTILE || _unit->getStatus() == STATUS_UNCONSCIOUS); // move inventory from unit to the ground for non-large units if (size == 1 && dropItems) { for (std::vector<BattleItem*>::iterator i = _unit->getInventory()->begin(); i != _unit->getInventory()->end(); ++i) { _parent->dropItem(lastPosition, (*i)); if (!(*i)->getRules()->isFixed()) { (*i)->setOwner(0); } else { itemToKeep = *i; } } } _unit->getInventory()->clear(); if (itemToKeep != 0) { _unit->getInventory()->push_back(itemToKeep); } // remove unit-tile link _unit->setTile(0); if (lastPosition == Position(-1,-1,-1)) // we're being carried { // replace the unconscious body item with a corpse in the carrying unit's inventory for (std::vector<BattleItem*>::iterator it = _parent->getSave()->getItems()->begin(); it != _parent->getSave()->getItems()->end(); ) { if ((*it)->getUnit() == _unit) { RuleItem *corpseRules = _parent->getRuleset()->getItem(_unit->getArmor()->getCorpseBattlescape()[0]); // we're in an inventory, so we must be a 1x1 unit (*it)->convertToCorpse(corpseRules); break; } ++it; } } else { int i = 0; for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { BattleItem *corpse = new BattleItem(_parent->getRuleset()->getItem(_unit->getArmor()->getCorpseBattlescape()[i]), _parent->getSave()->getCurrentItemId()); corpse->setUnit(_unit); if (_parent->getSave()->getTile(lastPosition + Position(x,y,0))->getUnit() == _unit) // check in case unit was displaced by another unit { _parent->getSave()->getTile(lastPosition + Position(x,y,0))->setUnit(0); } _parent->dropItem(lastPosition + Position(x,y,0), corpse, true); i++; } } } }
/** * Converts unit to a corpse (item). */ void UnitDieBState::convertUnitToCorpse() { _parent->getSave()->getBattleState()->showPsiButton(false); // in case the unit was unconscious _parent->getSave()->removeUnconsciousBodyItem(_unit); Position lastPosition = _unit->getPosition(); int size = _unit->getArmor()->getSize() - 1; BattleItem *itemToKeep = 0; bool dropItems = !Options::getBool("weaponSelfDestruction") || (_unit->getOriginalFaction() != FACTION_HOSTILE || _unit->getStatus() == STATUS_UNCONSCIOUS); // move inventory from unit to the ground for non-large units if (size == 0 && dropItems) { for (std::vector<BattleItem*>::iterator i = _unit->getInventory()->begin(); i != _unit->getInventory()->end(); ++i) { _parent->dropItem(_unit->getPosition(), (*i)); if (!(*i)->getRules()->isFixed()) { (*i)->setOwner(0); } else { itemToKeep = *i; } } } _unit->getInventory()->clear(); if (itemToKeep != 0) { _unit->getInventory()->push_back(itemToKeep); } // remove unit-tile link _unit->setTile(0); if (size == 0) { BattleItem *corpse = new BattleItem(_parent->getRuleset()->getItem(_unit->getArmor()->getCorpseItem()),_parent->getSave()->getCurrentItemId()); corpse->setUnit(_unit); _parent->dropItem(_unit->getPosition(), corpse, true); if (_parent->getSave()->getTile(lastPosition)->getUnit() == _unit) // check in case unit was displaced by another unit { _parent->getSave()->getTile(lastPosition)->setUnit(0); } } else { int i = 1; for (int y = 0; y <= size; y++) { for (int x = 0; x <= size; x++) { std::ostringstream ss; ss << _unit->getArmor()->getCorpseItem() << i; BattleItem *corpse = new BattleItem(_parent->getRuleset()->getItem(ss.str()),_parent->getSave()->getCurrentItemId()); corpse->setUnit(_unit); if (_parent->getSave()->getTile(lastPosition + Position(x,y,0))->getUnit() == _unit) // check in case unit was displaced by another unit { _parent->getSave()->getTile(lastPosition + Position(x,y,0))->setUnit(0); } _parent->dropItem(lastPosition + Position(x,y,0), corpse, true); i++; } } } }