Skip to content

Commit

Permalink
The current algorithm for matching a defensive structure to terrain l…
Browse files Browse the repository at this point in the history
…ooks at the higher corner of a tile. This new algorithm looks instead at the higher position on a tile where a vertex in the model would intersect the terrain if it were level with the ground. This makes defensive structures match up with the terrain much closer, avoiding the 'jutting out of the terrain' effect of building defensive structures on uneven terrain. This closes ticket:2299
  • Loading branch information
perim committed Nov 9, 2010
1 parent 268f2d0 commit 77fb642
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/structure.c
Expand Up @@ -1530,7 +1530,6 @@ static void buildFlatten(STRUCTURE *pStructure, UDWORD x, UDWORD y, UDWORD h)

void alignStructure(STRUCTURE *psBuilding)
{
int width, breadth;
int x = psBuilding->pos.x;
int y = psBuilding->pos.y;
unsigned sWidth = getStructureWidth(psBuilding);
Expand All @@ -1548,17 +1547,18 @@ void alignStructure(STRUCTURE *psBuilding)
}
else
{
iIMDShape *strImd = psBuilding->sDisplay.imd;
int i, pointHeight;

psBuilding->pos.z = TILE_MIN_HEIGHT;

/* Set it at the higher coord */
for (width = 0; width < sWidth; width++)
// Now we got through the shape looking for vertices on the edge
for (i = 0; i < strImd->npoints; i++)
{
for (breadth = 0; breadth < sBreadth; breadth++)
pointHeight = map_Height(psBuilding->pos.x + strImd->points[i].x, psBuilding->pos.y - strImd->points[i].z);
if (pointHeight > psBuilding->pos.z)
{
UDWORD tmpMax, tmpMin;

getTileMaxMin(map_coord(x) + width, map_coord(y) + breadth, &tmpMax, &tmpMin);
psBuilding->pos.z = MAX(tmpMax, psBuilding->pos.z);
psBuilding->pos.z = pointHeight;
}
}
}
Expand Down

0 comments on commit 77fb642

Please sign in to comment.