Style cleanups, fix typos, make follow-up bugfix patch smaller

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5270 4a71c877-e1ca-e34f-864e-861f7616d084
master
Dennis Schridde 2008-06-18 22:22:26 +00:00
parent a128c9df88
commit 496d6592b5
4 changed files with 86 additions and 102 deletions

View File

@ -1178,8 +1178,8 @@ extern SWORD map_Height(int x, int y)
ASSERT(x >= 0, "map_Height: Negative x value");
ASSERT(y >= 0, "map_Height: Negative y value");
x = x >= world_coord(mapWidth) ? world_coord(mapWidth - 1) : x;
y = y >= world_coord(mapHeight) ? world_coord(mapHeight - 1) : y;
x = (x >= world_coord(mapWidth) ? world_coord(mapWidth - 1) : x);
y = (y >= world_coord(mapHeight) ? world_coord(mapHeight - 1) : y);
/* Turn into tile coordinates */
tileX = map_coord(x);

View File

@ -46,9 +46,8 @@ typedef struct {
void rayCast(Vector3i src, Vector3i direction, int length,
RAY_CALLBACK callback, void * data)
{
unsigned int distSq = (length == RAY_MAXLEN ? RAY_MAXLEN : length*length);
unsigned int currDistSq;
Vector3i diff, curr = src;
unsigned int lengthSq = (length == RAY_MAXLEN ? RAY_MAXLEN : length*length), currLengthSq;
Vector3i curr = src, diff;
Vector3i step = Vector3f_To3i(
Vector3f_Mult(
Vector3f_Normalise(Vector3i_To3f(direction)),
@ -58,8 +57,8 @@ void rayCast(Vector3i src, Vector3i direction, int length,
while (curr = Vector3i_Add(curr, step),
diff = Vector3i_Sub(curr, src),
currDistSq = Vector3i_ScalarP(diff, diff),
currDistSq < distSq)
currLengthSq = Vector3i_ScalarP(diff, diff),
currLengthSq < lengthSq)
{
// stop at the edge of the map
if (curr.x < 0 || curr.x >= world_coord(mapWidth) ||
@ -68,7 +67,7 @@ void rayCast(Vector3i src, Vector3i direction, int length,
return;
}
if (!callback(curr, currDistSq, data))
if (!callback(curr, currLengthSq, data))
{
// callback doesn't want any more points so return
return;
@ -120,7 +119,7 @@ static bool getTileHeightCallback(Vector3i pos, int dist, void* data)
// Only do it the current tile is > TILE_UNITS away from the starting tile. Or..
// there is a tall structure on the current tile and the current tile is not the starting tile.
/* Get height at this intersection point */
int height = map_Height(pos.x, pos.y), heightDif;
int height = map_Height(pos.x, pos.y), heightDiff;
float newPitch;
if (HasTallStructure)
@ -130,15 +129,15 @@ static bool getTileHeightCallback(Vector3i pos, int dist, void* data)
if (height <= help->height)
{
heightDif = 0;
heightDiff = 0;
}
else
{
heightDif = height - help->height;
heightDiff = height - help->height;
}
/* Work out the angle to this point from start point */
newPitch = rad2degf(atan2f(heightDif, dist));
newPitch = rad2degf(atan2f(heightDiff, dist));
/* Is this the steepest we've found? */
if (newPitch > help->pitch)

View File

@ -34,7 +34,10 @@
/*!
* The raycast intersection callback.
* \return false if no more points are required, true otherwise
* \param pos Current position
* \param dist Current distance from start
* \param data Payload (store intermediate results here)
* \return true if ore points are required, false otherwise
*/
typedef bool (*RAY_CALLBACK)(Vector3i pos, int dist, void* data);

View File

@ -104,35 +104,26 @@ void visUpdateLevel(void)
visLevelDecAcc -= visLevelDec;
}
static SDWORD visObjHeight(const BASE_OBJECT * const psObject)
static int visObjHeight(const BASE_OBJECT * psObject)
{
SDWORD height;
switch (psObject->type)
{
case OBJ_DROID:
height = 80;
// height = psObject->sDisplay.imd->pos.max.y;
break;
// return psObject->sDisplay.imd->pos.max.y;
return 80;
case OBJ_STRUCTURE:
height = psObject->sDisplay.imd->max.y;
break;
case OBJ_FEATURE:
height = psObject->sDisplay.imd->max.y;
break;
return psObject->sDisplay.imd->max.y;
default:
ASSERT( false,"visObjHeight: unknown object type" );
height = 0;
break;
return 0;
}
return height;
}
/* The terrain revealing ray callback */
bool rayTerrainCallback(Vector3i pos, int dist, void * data)
{
SDWORD newH, newG; // The new gradient
int newH, newG; // The new gradient
MAPTILE *psTile;
ASSERT(pos.x >= 0 && pos.x < world_coord(mapWidth)
@ -150,7 +141,7 @@ bool rayTerrainCallback(Vector3i pos, int dist, void * data)
}
newH = psTile->height * ELEVATION_SCALE;
newG = (newH - startH) * GRAD_MUL / (SDWORD)dist;
newG = (newH - startH) * GRAD_MUL / dist;
if (newG >= currG)
{
currG = newG;
@ -184,8 +175,6 @@ bool rayTerrainCallback(Vector3i pos, int dist, void * data)
static bool rayLOSCallback(Vector3i pos, int dist, void *data)
{
int newG; // The new gradient
int distSq = dist*dist;
MAPTILE *psTile;
ASSERT(pos.x >= 0 && pos.x < world_coord(mapWidth)
&& pos.y >= 0 && pos.y < world_coord(mapHeight),
@ -209,24 +198,25 @@ static bool rayLOSCallback(Vector3i pos, int dist, void *data)
lastH = map_Height(pos.x, pos.y);
// See if the ray has reached the target
if (distSq >= tarDist)
if (dist >= tarDist)
{
return false;
}
if (blockingWall)
{
// Store the height at this tile for next time round
Vector2i tile = { map_coord(pos.x), map_coord(pos.y) };
if (blockingWall && !((tile.x == finalX) && (tile.y == finalY)))
if (!((tile.x == finalX) && (tile.y == finalY)))
{
psTile = mapTile(tile.x, tile.y);
MAPTILE *psTile = mapTile(tile.x, tile.y);
if (TileHasWall(psTile) && !TileHasSmallStructure(psTile))
{
lastH = 2*UBYTE_MAX * ELEVATION_SCALE;
numWalls += 1;
wallX = pos.x;
wallY = pos.y;
numWalls++;
}
}
}
@ -459,18 +449,19 @@ STRUCTURE* visGetBlockingWall(const BASE_OBJECT* psViewer, const BASE_OBJECT* ps
/* Find out what can see this object */
void processVisibility(BASE_OBJECT *psObj)
{
UDWORD i;
BOOL prevVis[MAX_PLAYERS], currVis[MAX_PLAYERS];
SDWORD visLevel;
BASE_OBJECT *psViewer;
MESSAGE *psMessage;
UDWORD player, ally;
unsigned int player;
// initialise the visibility array
for (i=0; i<MAX_PLAYERS; i++)
for (player = 0; player < MAX_PLAYERS; player++)
{
prevVis[i] = psObj->visible[i] != 0;
prevVis[player] = (psObj->visible[player] != 0);
}
// Droids can vanish from view, other objects will stay
if (psObj->type == OBJ_DROID)
{
memset (currVis, 0, sizeof(BOOL) * MAX_PLAYERS);
@ -484,22 +475,20 @@ void processVisibility(BASE_OBJECT *psObj)
}
// get all the objects from the grid the droid is in
gridStartIterate((SDWORD)psObj->pos.x, (SDWORD)psObj->pos.y);
gridStartIterate(psObj->pos.x, psObj->pos.y);
// Make sure allies can see us
if (bMultiPlayer && game.alliance == ALLIANCES_TEAMS)
{
unsigned int player;
for (player = 0; player < MAX_PLAYERS; player++)
{
if(player!=psObj->player)
{
if(aiCheckAlliances(player,psObj->player))
if (player != psObj->player && aiCheckAlliances(player, psObj->player))
{
currVis[player] = true;
}
}
}
}
// if a player has a SAT_UPLINK structure, they can see everything!
for (player = 0; player < MAX_PLAYERS; player++)
@ -514,8 +503,7 @@ void processVisibility(BASE_OBJECT *psObj)
}
}
psViewer = gridIterate();
while (psViewer != NULL)
while (psViewer = gridIterate(), psViewer != NULL)
{
// If we've got ranged line of sight...
if ( (psViewer->type != OBJ_FEATURE) &&
@ -526,7 +514,6 @@ void processVisibility(BASE_OBJECT *psObj)
currVis[psViewer->player] = true;
if (!prevVis[psViewer->player])
{
if (psObj->visible[psViewer->player] == 0)
{
psObj->visible[psViewer->player] = 1;
@ -537,17 +524,16 @@ void processVisibility(BASE_OBJECT *psObj)
clustObjectSeen(psObj, psViewer);
}
}
}
psViewer = gridIterate();
}
//forward out vision to our allies
if (bMultiPlayer && game.alliance == ALLIANCES_TEAMS)
{
unsigned int player;
for (player = 0; player < MAX_PLAYERS; player++)
{
unsigned int ally;
for (ally = 0; ally < MAX_PLAYERS; ally++)
{
if (currVis[player] && aiCheckAlliances(player, ally))
@ -559,53 +545,50 @@ void processVisibility(BASE_OBJECT *psObj)
}
// update the visibility levels
for(i=0; i<MAX_PLAYERS; i++)
for (player = 0; player < MAX_PLAYERS; player++)
{
if (i == psObj->player)
if (player == psObj->player)
{
// owner can always see it fully
psObj->visible[i] = UBYTE_MAX;
psObj->visible[player] = UBYTE_MAX;
continue;
}
visLevel = 0;
if (currVis[i])
{
visLevel = UBYTE_MAX;
}
visLevel = (currVis[player] ? UBYTE_MAX : 0);
if ( (visLevel < psObj->visible[i]) &&
// Droids can vanish from view, other objects will stay
if ( (visLevel < psObj->visible[player]) &&
(psObj->type == OBJ_DROID) )
{
if (psObj->visible[i] <= visLevelDec)
if (psObj->visible[player] <= visLevelDec)
{
psObj->visible[i] = 0;
psObj->visible[player] = 0;
}
else
{
psObj->visible[i] = (UBYTE)(psObj->visible[i] - visLevelDec);
psObj->visible[player] -= visLevelDec;
}
}
else if (visLevel > psObj->visible[i])
else if (visLevel > psObj->visible[player])
{
if (psObj->visible[i] + visLevelInc >= UBYTE_MAX)
if (psObj->visible[player] + visLevelInc >= UBYTE_MAX)
{
psObj->visible[i] = UBYTE_MAX;
psObj->visible[player] = UBYTE_MAX;
}
else
{
psObj->visible[i] = (UBYTE)(psObj->visible[i] + visLevelInc);
psObj->visible[player] += visLevelInc;
}
}
}
/* Make sure all tiles under a feature/structure become visible when you see it */
for(i=0; i<MAX_PLAYERS; i++)
for (player = 0; player < MAX_PLAYERS; player++)
{
if ( (psObj->type == OBJ_STRUCTURE || psObj->type == OBJ_FEATURE) &&
(!prevVis[i] && psObj->visible[i]) )
!prevVis[player] && psObj->visible[player] )
{
setUnderTilesVis(psObj,i);
setUnderTilesVis(psObj, player);
}
}
@ -633,8 +616,7 @@ void processVisibility(BASE_OBJECT *psObj)
debug(LOG_MSG, "Added message for oil well, pViewData=%p", psMessage->pViewData);
}
}
if (((FEATURE *)psObj)->psStats->subType == FEAT_GEN_ARTE)
else if (((FEATURE *)psObj)->psStats->subType == FEAT_GEN_ARTE)
{
psMessage = addMessage(MSG_PROXIMITY, true, selectedPlayer);
if (psMessage)
@ -735,7 +717,7 @@ void updateSensorDisplay()
bool scrRayTerrainCallback(Vector3i pos, int dist, void *data)
{
SDWORD newH, newG; // The new gradient
int newH, newG; // The new gradient
MAPTILE *psTile;
ASSERT(pos.x >= 0 && pos.x < world_coord(mapWidth)
@ -755,7 +737,7 @@ bool scrRayTerrainCallback(Vector3i pos, int dist, void *data)
}
newH = psTile->height * ELEVATION_SCALE;
newG = (newH - startH) * GRAD_MUL / (SDWORD)dist;
newG = (newH - startH) * GRAD_MUL / dist;
if (newG >= currG)
{
currG = newG;