本文整理汇总了C++中BattleUnit::getTurretDirection方法的典型用法代码示例。如果您正苦于以下问题:C++ BattleUnit::getTurretDirection方法的具体用法?C++ BattleUnit::getTurretDirection怎么用?C++ BattleUnit::getTurretDirection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BattleUnit
的用法示例。
在下文中一共展示了BattleUnit::getTurretDirection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculateTrajectory
/**
* calculateTrajectory.
* @return the objectnumber(0-3) or unit(4) or out of map (5) or -1(no line of fire)
*/
int Projectile::calculateTrajectory(double accuracy)
{
Position originVoxel, targetVoxel;
Tile *targetTile = 0;
int direction;
int dirYshift[24] = {1, 3, 9, 15, 15, 13, 7, 1, 1, 1, 7, 13, 15, 15, 9, 3, 1, 2, 8, 14, 15, 14, 8, 2};
int dirXshift[24] = {9, 15, 15, 13, 8, 1, 1, 3, 7, 13, 15, 15, 9, 3, 1, 1, 8, 14, 15, 14, 8, 2, 1, 2};
int offset = 0;
originVoxel = Position(_origin.x*16, _origin.y*16, _origin.z*24);
BattleUnit *bu = _action.actor;
if (bu->getArmor()->getSize() > 1)
{
offset = 16;
}
else if(_action.weapon == _action.weapon->getOwner()->getItem("STR_LEFT_HAND") && !_action.weapon->getRules()->isTwoHanded())
{
offset = 8;
}
// take into account soldier height and terrain level if the projectile is launched from a soldier
if (_action.actor->getPosition() == _origin)
{
// calculate offset of the starting point of the projectile
originVoxel.z += -_save->getTile(_origin)->getTerrainLevel();
originVoxel.z += bu->getHeight() + bu->getFloatHeight();
originVoxel.z -= 4;
if (originVoxel.z >= (_origin.z + 1)*24)
{
_origin.z++;
}
direction = bu->getDirection();
if (bu->getTurretType() != -1)
direction = bu->getTurretDirection();
originVoxel.x += dirXshift[direction+offset]*bu->getArmor()->getSize();
originVoxel.y += dirYshift[direction+offset]*bu->getArmor()->getSize();
}
else
{
// don't take into account soldier height and terrain level if the projectile is not launched from a soldier(from a waypoint)
originVoxel.x += 8;
originVoxel.y += 8;
originVoxel.z += 12;
}
if (_action.type == BA_LAUNCH || (SDL_GetModState() & KMOD_CTRL) != 0)
{
// target nothing, targets the middle of the tile
targetVoxel = Position(_action.target.x*16 + 8, _action.target.y*16 + 8, _action.target.z*24 + 12);
}
else
{
// determine the target voxel.
// aim at the center of the unit, the object, the walls or the floor (in that priority)
// if there is no LOF to the center, try elsewhere (more outward).
// Store this target voxel.
targetTile = _save->getTile(_action.target);
Position hitPos;
int test = -1;
if (targetTile->getUnit() != 0)
{
if (_origin == _action.target || targetTile->getUnit() == _action.actor)
{
// don't shoot at yourself but shoot at the floor
targetVoxel = Position(_action.target.x*16 + 8, _action.target.y*16 + 8, _action.target.z*24);
}
else
{
_save->getTileEngine()->canTargetUnit(&originVoxel, targetTile, &targetVoxel, bu);
}
}
else if (targetTile->getMapData(MapData::O_OBJECT) != 0)
{
if (!_save->getTileEngine()->canTargetTile(&originVoxel, targetTile, MapData::O_OBJECT, &targetVoxel, bu))
{
targetVoxel = Position(_action.target.x*16 + 8, _action.target.y*16 + 8, _action.target.z*24 + 10);
}
}
else if (targetTile->getMapData(MapData::O_NORTHWALL) != 0)
{
if (!_save->getTileEngine()->canTargetTile(&originVoxel, targetTile, MapData::O_NORTHWALL, &targetVoxel, bu))
{
targetVoxel = Position(_action.target.x*16 + 8, _action.target.y*16, _action.target.z*24 + 9);
}
}
else if (targetTile->getMapData(MapData::O_WESTWALL) != 0)
{
if (!_save->getTileEngine()->canTargetTile(&originVoxel, targetTile, MapData::O_WESTWALL, &targetVoxel, bu))
{
targetVoxel = Position(_action.target.x*16, _action.target.y*16 + 8, _action.target.z*24 + 9);
}
}
else if (targetTile->getMapData(MapData::O_FLOOR) != 0)
{
//.........这里部分代码省略.........