Skip to content

Commit

Permalink
Make VTOL rearming pads stay above ground.
Browse files Browse the repository at this point in the history
VTOL rearming pads no longer think that they are submarines. The corners of the pad
(baseplate) may still go below ground, but the centre square of the rearming pad
floats above ground. VTOL rearming pads no longer flatten the terrain under them.
Structures that flatten terrain re-float nearby pads and defenses.

STRUCTURE::pos.z is no longer mysteriously ignored when rendering most structures.

Fixes ticket:702.
  • Loading branch information
Cyp committed Mar 13, 2012
1 parent 9161456 commit 071d08f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
9 changes: 2 additions & 7 deletions src/display3d.cpp
Expand Up @@ -2240,12 +2240,7 @@ void renderStructure(STRUCTURE *psStructure)

dv.x = structX - player.p.x;
dv.z = -(structY - player.p.z);
if (defensive || structureIsBlueprint(psStructure))
{
dv.y = psStructure->pos.z;
} else {
dv.y = map_TileHeight(map_coord(structX), map_coord(structY));
}
dv.y = psStructure->pos.z;
/* Push the indentity matrix */
pie_MatBegin();

Expand Down Expand Up @@ -2654,7 +2649,7 @@ static bool renderWallSection(STRUCTURE *psStructure)
/* Establish where it is in the world */
dv.x = structX - player.p.x;
dv.z = -(structY - player.p.z);
dv.y = map_Height(structX, structY);
dv.y = psStructure->pos.z;

if (psStructure->pStructureType->type == REF_GATE && psStructure->state == SAS_OPEN)
{
Expand Down
24 changes: 22 additions & 2 deletions src/structure.cpp
Expand Up @@ -1273,16 +1273,36 @@ static void buildFlatten(STRUCTURE *pStructure, int h)
}
}

static bool isPulledToTerrain(STRUCTURE const *psBuilding)
{
STRUCTURE_TYPE type = psBuilding->pStructureType->type;
return type == REF_DEFENSE || type == REF_GATE || type == REF_WALL || type == REF_WALLCORNER || type == REF_REARM_PAD;
}

void alignStructure(STRUCTURE *psBuilding)
{
/* DEFENSIVE structures are pulled to the terrain */
if (psBuilding->pStructureType->type != REF_DEFENSE && psBuilding->pStructureType->type != REF_GATE && psBuilding->pStructureType->type != REF_WALL && psBuilding->pStructureType->type != REF_WALLCORNER)
if (!isPulledToTerrain(psBuilding))
{
int mapH = foundationHeight(psBuilding);

buildFlatten(psBuilding, mapH);
psBuilding->pos.z = mapH;
psBuilding->foundationDepth = 0.0f;
psBuilding->foundationDepth = psBuilding->pos.z;

// Align surrounding structures.
StructureBounds b = getStructureBounds(psBuilding);
for (int breadth = -1; breadth <= b.size.y; ++breadth)
{
for (int width = -1; width <= b.size.x; ++width)
{
STRUCTURE *neighbourStructure = castStructure(mapTile(b.map.x + width, b.map.y + breadth)->psObject);
if (neighbourStructure != NULL && isPulledToTerrain(neighbourStructure))
{
alignStructure(neighbourStructure); // Recursive call, but will go to the else case, so will not re-recurse.
}
}
}
}
else
{
Expand Down

0 comments on commit 071d08f

Please sign in to comment.