当前位置: 首页>>代码示例>>C++>>正文


C++ BattleItem::setUnit方法代码示例

本文整理汇总了C++中BattleItem::setUnit方法的典型用法代码示例。如果您正苦于以下问题:C++ BattleItem::setUnit方法的具体用法?C++ BattleItem::setUnit怎么用?C++ BattleItem::setUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BattleItem的用法示例。


在下文中一共展示了BattleItem::setUnit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: convertUnitToCorpse

/*
 * 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++;
			}
		}
	}

}
开发者ID:arirahikkala,项目名称:OpenXcom,代码行数:51,代码来源:UnitDieBState.cpp

示例2: convertUnitToCorpse

/*
 * 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++;
			}
		}
	}
}
开发者ID:yoyko,项目名称:OpenXcom,代码行数:47,代码来源:UnitDieBState.cpp

示例3: convertUnitToCorpse

/**
 * 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++;
			}
		}
	}
}
开发者ID:stavrossk,项目名称:OpenXcom,代码行数:74,代码来源:UnitDieBState.cpp

示例4: convertUnitToCorpse

/**
 * 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++;
			}
		}
	}

}
开发者ID:keeper,项目名称:OpenXcom,代码行数:70,代码来源:UnitDieBState.cpp


注:本文中的BattleItem::setUnit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。