Simplify the structWallScan function; patch by Zarel. This closes ticket #55.

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5985 4a71c877-e1ca-e34f-864e-861f7616d084
master
Freddie Witherden 2008-09-10 11:30:19 +00:00
parent 6088fca5af
commit 7fc3b92682
1 changed files with 9 additions and 48 deletions

View File

@ -1280,62 +1280,23 @@ BOOL structSetManufacture(STRUCTURE *psStruct, DROID_TEMPLATE *psTempl, UBYTE qu
*/
// look at where other walls are to decide what type of wall to build
static SDWORD structWallScan(BOOL aWallPresent[5][5], SDWORD x,SDWORD y)
static SDWORD structWallScan(BOOL aWallPresent[5][5], SDWORD x, SDWORD y)
{
SDWORD cx,cy, numWalls;
numWalls = 0;
for(cx = x-1; cx <= x+1; cx += 1)
if (aWallPresent[x-1][y] || aWallPresent[x+1][y])
{
for(cy = y-1; cy <= y+1; cy += 1)
{
// do not look at walls diagonally from this wall
if (((cx == x && cy != y) ||
(cx != x && cy == y))
&& aWallPresent[cx][cy])
{
numWalls += 1;
}
}
}
// Now decide what type of wall is needed
if (numWalls == 1)
{
if (aWallPresent[x-1][y] || aWallPresent[x+1][y])
{
// there is a wall horizontally adjacent
return WALL_HORIZ;
}
else
{
return WALL_VERT;
}
}
else if (numWalls == 2)
{
if (aWallPresent[x-1][y] && aWallPresent[x+1][y])
{
// there is a wall horizontally adjacent
return WALL_HORIZ;
}
else if (aWallPresent[x][y-1] && aWallPresent[x][y+1])
{
// there is a wall vertically adjacent
return WALL_VERT;
}
else
if (aWallPresent[x][y-1] || aWallPresent[x][y+1])
{
return WALL_CORNER;
}
else
{
return WALL_HORIZ;
}
}
else if (numWalls > 2)
else
{
// definately need a corner wall
return WALL_CORNER;
return WALL_VERT;
}
return WALL_VERT;
}
// Choose a type of wall for a location - and update any neighbouring walls