Skip to content

Commit

Permalink
Fix bug with all units' voxels flipped relative to Y axis (OpenXcom#1423
Browse files Browse the repository at this point in the history
)

* Fix bug with all units' voxels flipped relative Y axis

Center of inverted unit become (7,8) and Volutar deducted that empirically and made dirty fix in commit#757d674 which (fix, not the whole commit) can now be reverted. Big units loftemps loading logic was inverted too, and I've added quick workaround to not break anything
  • Loading branch information
narical committed Sep 9, 2023
1 parent 2145081 commit 1c188b9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Battlescape/TileEngine.cpp
Expand Up @@ -355,15 +355,15 @@ bool TileEngine::calculateFOV(BattleUnit *unit)
}

/**
* Gets the origin voxel of a unit's eyesight (from just one eye or something? Why is it x+7??
* Gets the origin voxel of a unit's eyesight
* @param currentUnit The watcher.
* @return Approximately an eyeball voxel.
*/
Position TileEngine::getSightOriginVoxel(BattleUnit *currentUnit)
{
// determine the origin and target voxels for the raytrace
Position originVoxel;
originVoxel = Position((currentUnit->getPosition().x * 16) + 7, (currentUnit->getPosition().y * 16) + 8, currentUnit->getPosition().z*24);
originVoxel = Position((currentUnit->getPosition().x * 16) + 8, (currentUnit->getPosition().y * 16) + 8, currentUnit->getPosition().z*24);
originVoxel.z += -_save->getTile(currentUnit->getPosition())->getTerrainLevel();
originVoxel.z += currentUnit->getHeight() + currentUnit->getFloatHeight() - 1; //one voxel lower (eye level)
Tile *tileAbove = _save->getTile(currentUnit->getPosition() + Position(0,0,1));
Expand Down Expand Up @@ -459,7 +459,7 @@ bool TileEngine::visible(BattleUnit *currentUnit, Tile *tile)
*/
int TileEngine::checkVoxelExposure(Position *originVoxel, Tile *tile, BattleUnit *excludeUnit, BattleUnit *excludeAllBut)
{
Position targetVoxel = Position((tile->getPosition().x * 16) + 7, (tile->getPosition().y * 16) + 8, tile->getPosition().z * 24);
Position targetVoxel = Position((tile->getPosition().x * 16) + 8, (tile->getPosition().y * 16) + 8, tile->getPosition().z * 24);
Position scanVoxel;
std::vector<Position> _trajectory;
BattleUnit *otherUnit = tile->getUnit();
Expand Down Expand Up @@ -538,7 +538,7 @@ int TileEngine::checkVoxelExposure(Position *originVoxel, Tile *tile, BattleUnit
*/
bool TileEngine::canTargetUnit(Position *originVoxel, Tile *tile, Position *scanVoxel, BattleUnit *excludeUnit, bool rememberObstacles, BattleUnit *potentialUnit)
{
Position targetVoxel = Position((tile->getPosition().x * 16) + 7, (tile->getPosition().y * 16) + 8, tile->getPosition().z * 24);
Position targetVoxel = Position((tile->getPosition().x * 16) + 8, (tile->getPosition().y * 16) + 8, tile->getPosition().z * 24);
std::vector<Position> _trajectory;
bool hypothetical = potentialUnit != 0;
if (potentialUnit == 0)
Expand Down Expand Up @@ -2612,13 +2612,14 @@ VoxelType TileEngine::voxelCheck(Position voxel, BattleUnit *excludeUnit, bool e
int tz = unitpos.z*24 + unit->getFloatHeight() - terrainHeight; //bottom most voxel, terrain heights are negative, so we subtract.
if ((voxel.z > tz) && (voxel.z <= tz + unit->getHeight()) )
{
int x = voxel.x%16;
int x = 15 - voxel.x%16;
int y = voxel.y%16;
int part = 0;
if (unit->getArmor()->getSize() > 1)
{
tilepos = tile->getPosition();
part = tilepos.x - unitpos.x + (tilepos.y - unitpos.y)*2;
const static int parts[] = {1,0,3,2}; // Change order 0,1,2,3 -> 1,0,3,2 (read commit description)
part = parts[tilepos.x - unitpos.x + (tilepos.y - unitpos.y)*2];
}
int idx = (unit->getLoftemps(part) * 16) + y;
if (_voxelData->at(idx) & (1 << x))
Expand Down

0 comments on commit 1c188b9

Please sign in to comment.