本文整理汇总了C++中BattleUnit::getHeight方法的典型用法代码示例。如果您正苦于以下问题:C++ BattleUnit::getHeight方法的具体用法?C++ BattleUnit::getHeight怎么用?C++ BattleUnit::getHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BattleUnit
的用法示例。
在下文中一共展示了BattleUnit::getHeight方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculateThrow
/**
* Calculates the trajectory for a curved path.
* @param accuracy The unit's accuracy.
* @param doTestTrajectory
* @return True when a trajectory is possible.
*/
int Projectile::calculateThrow(double accuracy, bool doTestTrajectory)
{
Tile *targetTile = _save->getTile(_action.target);
Position originVoxel = _save->getTileEngine()->getOriginVoxel(_action, 0);
Position targetVoxel = _action.target * Position(16,16,24) + Position(8,8, (2 + -targetTile->getTerrainLevel()));
if (_action.type != BA_THROW)
{
BattleUnit *tu = targetTile->getUnit();
if (!tu && _action.target.z > 0 && targetTile->hasNoFloor(0))
tu = _save->getTile(_action.target - Position(0, 0, 1))->getUnit();
if (tu)
{
targetVoxel.z += ((tu->getHeight()/2) + tu->getFloatHeight()) - 2;
}
}
double curvature = 0.0;
int retVal = V_OUTOFBOUNDS;
if (_save->getTileEngine()->validateThrow(_action, originVoxel, targetVoxel, &curvature, &retVal))
{
if (doTestTrajectory)
{
return V_FLOOR; // retVal;
}
int test = V_OUTOFBOUNDS;
// finally do a line calculation and store this trajectory, make sure it's valid.
while (test == V_OUTOFBOUNDS)
{
Position deltas = targetVoxel;
// apply some accuracy modifiers
applyAccuracy(originVoxel, &deltas, accuracy, true, _save->getTile(_action.target), false); //calling for best flavor
deltas -= targetVoxel;
_trajectory.clear();
test = _save->getTileEngine()->calculateParabola(originVoxel, targetVoxel, true, &_trajectory, _action.actor, curvature, deltas);
Position endPoint = _trajectory.back();
endPoint.x /= 16;
endPoint.y /= 16;
endPoint.z /= 24;
Tile *endTile = _save->getTile(endPoint);
// check if the item would land on a tile with a blocking object
if (_action.type == BA_THROW
&& endTile
&& endTile->getMapData(MapData::O_OBJECT)
&& endTile->getMapData(MapData::O_OBJECT)->getTUCost(MT_WALK) == 255)
{
test = V_OUTOFBOUNDS;
}
}
return retVal;
}
return V_OUTOFBOUNDS;
}
示例2: think
//.........这里部分代码省略.........
// now open doors (if any)
if (dir < Pathfinding::DIR_UP)
{
int door = _terrain->unitOpensDoor(_unit, false, dir);
if (door == 3)
{
return; // don't start walking yet, wait for the ufo door to open
}
if (door == 0)
{
_parent->getMod()->getSoundByDepth(_parent->getDepth(), Mod::DOOR_OPEN)->play(-1, _parent->getMap()->getSoundAngle(_unit->getPosition())); // normal door
}
if (door == 1)
{
_parent->getMod()->getSoundByDepth(_parent->getDepth(), Mod::SLIDING_DOOR_OPEN)->play(-1, _parent->getMap()->getSoundAngle(_unit->getPosition())); // ufo door
return; // don't start walking yet, wait for the ufo door to open
}
}
for (int x = size; x >= 0; --x)
{
for (int y = size; y >= 0; --y)
{
BattleUnit* unitInMyWay = _parent->getSave()->getTile(destination + Position(x,y,0))->getUnit();
BattleUnit* unitBelowMyWay = 0;
Tile* belowDest = _parent->getSave()->getTile(destination + Position(x,y,-1));
if (belowDest)
{
unitBelowMyWay = belowDest->getUnit();
}
// can't walk into units in this tile, or on top of other units sticking their head into this tile
if (!_falling &&
((unitInMyWay && unitInMyWay != _unit)
|| (belowDest && unitBelowMyWay && unitBelowMyWay != _unit &&
(-belowDest->getTerrainLevel() + unitBelowMyWay->getFloatHeight() + unitBelowMyWay->getHeight())
>= 28))) // 4+ voxels poking into the tile above, we don't kick people in the head here at XCom.
{
_action.TU = 0;
_pf->abortPath();
_unit->setCache(0);
_parent->getMap()->cacheUnit(_unit);
_parent->popState();
return;
}
}
}
// now start moving
dir = _pf->dequeuePath();
if (_falling)
{
dir = Pathfinding::DIR_DOWN;
}
if (_unit->spendTimeUnits(tu))
{
if (_unit->spendEnergy(energy))
{
Tile *tileBelow = _parent->getSave()->getTile(_unit->getPosition() + Position(0,0,-1));
_unit->startWalking(dir, destination, tileBelow, onScreen);
_beforeFirstStep = false;
}
}
// make sure the unit sprites are up to date
if (onScreen)
{
if (_pf->getStrafeMove())
{
示例3: calculateThrow
/**
* calculateTrajectory.
* @return true when a trajectory is possible.
*/
bool Projectile::calculateThrow(double accuracy)
{
Position originVoxel, targetVoxel;
bool foundCurve = false;
// object blocking - can't throw here
if (_action.type == BA_THROW &&_save->getTile(_action.target) && _save->getTile(_action.target)->getMapData(MapData::O_OBJECT) && _save->getTile(_action.target)->getMapData(MapData::O_OBJECT)->getTUCost(MT_WALK) == 255)
{
return false;
}
originVoxel = Position(_origin.x*16 + 8, _origin.y*16 + 8, _origin.z*24);
originVoxel.z += -_save->getTile(_origin)->getTerrainLevel();
BattleUnit *bu = _save->getTile(_origin)->getUnit();
if(!bu)
bu = _save->getTile(Position(_origin.x, _origin.y, _origin.z-1))->getUnit();
originVoxel.z += bu->getHeight() + bu->getFloatHeight();
originVoxel.z -= 3;
if (originVoxel.z >= (_origin.z + 1)*24)
{
_origin.z++;
}
// determine the target voxel.
// aim at the center of the floor
targetVoxel = Position(_action.target.x*16 + 8, _action.target.y*16 + 8, _action.target.z*24 + 2);
// we try 4 different curvatures to try and reach our goal.
double curvature = 1.0;
while (!foundCurve && curvature < 5.0)
{
_save->getTileEngine()->calculateParabola(originVoxel, targetVoxel, false, &_trajectory, bu, curvature, 1.0);
if ((int)_trajectory.at(0).x/16 == (int)targetVoxel.x/16 && (int)_trajectory.at(0).y/16 == (int)targetVoxel.y/16 && (int)_trajectory.at(0).z/24 == (int)targetVoxel.z/24)
{
foundCurve = true;
}
else
{
curvature += 1.0;
}
_trajectory.clear();
}
if ( AreSame(curvature, 5.0) )
{
return false;
}
// apply some accuracy modifiers
if (accuracy > 1)
accuracy = 1;
static const double maxDeviation = 0.08;
static const double minDeviation = 0;
double baseDeviation = (maxDeviation - (maxDeviation * accuracy)) + minDeviation;
double deviation = RNG::boxMuller(0, baseDeviation);
_trajectory.clear();
// finally do a line calculation and store this trajectory.
_save->getTileEngine()->calculateParabola(originVoxel, targetVoxel, true, &_trajectory, bu, curvature, 1.0 + deviation);
Position endPoint = _trajectory.at(_trajectory.size() - 1);
endPoint.x /= 16;
endPoint.y /= 16;
endPoint.z /= 24;
// check if the item would land on a tile with a blocking object, if so then we let it fly without deviation, it must land on a valid tile in that case
if (_save->getTile(endPoint) && _save->getTile(endPoint)->getMapData(MapData::O_OBJECT) && _save->getTile(endPoint)->getMapData(MapData::O_OBJECT)->getTUCost(MT_WALK) == 255)
{
_trajectory.clear();
// finally do a line calculation and store this trajectory.
_save->getTileEngine()->calculateParabola(originVoxel, targetVoxel, true, &_trajectory, bu, curvature, 1.0);
}
return true;
}
示例4: 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)
{
//.........这里部分代码省略.........
示例5: 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;
int direction;
int dirYshift[8] = {1, 1, 8, 15, 15, 15, 8, 1 };
int dirXshift[8] = {8, 14, 15, 15, 8, 1, 1, 1 };
// large units : x2
originVoxel = Position(_origin.x*16, _origin.y*16, _origin.z*24);
originVoxel.z += -_save->getTile(_origin)->getTerrainLevel();
BattleUnit *bu = _save->getTile(_origin)->getUnit();
originVoxel.z += bu->getHeight();
originVoxel.z -= 3;
if (originVoxel.z >= (_origin.z + 1)*24)
{
_origin.z++;
}
direction = bu->getDirection();
originVoxel.x += dirXshift[direction];
originVoxel.y += dirYshift[direction];
// 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.
Tile *tile = _save->getTile(_action.target);
if (tile->getUnit() != 0)
{
if (_origin == _action.target)
{
// 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
{
// first try is at half the unit height
targetVoxel = Position(_action.target.x*16 + 8, _action.target.y*16 + 8, _action.target.z*24 + tile->getUnit()->getUnit()->getStandHeight()/2);
int test = _save->getTileEngine()->calculateLine(originVoxel, targetVoxel, false, &_trajectory, bu);
_trajectory.clear();
if (test != 4)
{
// did not hit a unit, try at different heights (for ex: unit behind a window can only be hit in the head)
targetVoxel = Position(_action.target.x*16 + 8, _action.target.y*16 + 8, _action.target.z*24 + (tile->getUnit()->getUnit()->getStandHeight()*3)/4);
test = _save->getTileEngine()->calculateLine(originVoxel, targetVoxel, false, &_trajectory, bu);
_trajectory.clear();
}
}
}
else if (tile->getMapData(MapData::O_OBJECT) != 0)
{
targetVoxel = Position(_action.target.x*16 + 8, _action.target.y*16 + 8, _action.target.z*24 + 10);
}
else if (tile->getMapData(MapData::O_NORTHWALL) != 0)
{
targetVoxel = Position(_action.target.x*16 + 8, _action.target.y*16, _action.target.z*24 + 10);
}
else if (tile->getMapData(MapData::O_WESTWALL) != 0)
{
targetVoxel = Position(_action.target.x*16, _action.target.y*16 + 8, _action.target.z*24 + 10);
}
else if (tile->getMapData(MapData::O_FLOOR) != 0)
{
targetVoxel = Position(_action.target.x*16 + 8, _action.target.y*16 + 8, _action.target.z*24);
}
else
{
return -1; // no line of fire
}
// apply some accuracy modifiers (todo: calculate this)
// This will results in a new target voxel
applyAccuracy(originVoxel, &targetVoxel, accuracy);
// finally do a line calculation and store this trajectory.
return _save->getTileEngine()->calculateLine(originVoxel, targetVoxel, true, &_trajectory, bu);
}