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-861f7616d084master
parent
a128c9df88
commit
496d6592b5
|
@ -1178,8 +1178,8 @@ extern SWORD map_Height(int x, int y)
|
||||||
ASSERT(x >= 0, "map_Height: Negative x value");
|
ASSERT(x >= 0, "map_Height: Negative x value");
|
||||||
ASSERT(y >= 0, "map_Height: Negative y value");
|
ASSERT(y >= 0, "map_Height: Negative y value");
|
||||||
|
|
||||||
x = x >= world_coord(mapWidth) ? world_coord(mapWidth - 1) : x;
|
x = (x >= world_coord(mapWidth) ? world_coord(mapWidth - 1) : x);
|
||||||
y = y >= world_coord(mapHeight) ? world_coord(mapHeight - 1) : y;
|
y = (y >= world_coord(mapHeight) ? world_coord(mapHeight - 1) : y);
|
||||||
|
|
||||||
/* Turn into tile coordinates */
|
/* Turn into tile coordinates */
|
||||||
tileX = map_coord(x);
|
tileX = map_coord(x);
|
||||||
|
|
|
@ -46,9 +46,8 @@ typedef struct {
|
||||||
void rayCast(Vector3i src, Vector3i direction, int length,
|
void rayCast(Vector3i src, Vector3i direction, int length,
|
||||||
RAY_CALLBACK callback, void * data)
|
RAY_CALLBACK callback, void * data)
|
||||||
{
|
{
|
||||||
unsigned int distSq = (length == RAY_MAXLEN ? RAY_MAXLEN : length*length);
|
unsigned int lengthSq = (length == RAY_MAXLEN ? RAY_MAXLEN : length*length), currLengthSq;
|
||||||
unsigned int currDistSq;
|
Vector3i curr = src, diff;
|
||||||
Vector3i diff, curr = src;
|
|
||||||
Vector3i step = Vector3f_To3i(
|
Vector3i step = Vector3f_To3i(
|
||||||
Vector3f_Mult(
|
Vector3f_Mult(
|
||||||
Vector3f_Normalise(Vector3i_To3f(direction)),
|
Vector3f_Normalise(Vector3i_To3f(direction)),
|
||||||
|
@ -58,8 +57,8 @@ void rayCast(Vector3i src, Vector3i direction, int length,
|
||||||
|
|
||||||
while (curr = Vector3i_Add(curr, step),
|
while (curr = Vector3i_Add(curr, step),
|
||||||
diff = Vector3i_Sub(curr, src),
|
diff = Vector3i_Sub(curr, src),
|
||||||
currDistSq = Vector3i_ScalarP(diff, diff),
|
currLengthSq = Vector3i_ScalarP(diff, diff),
|
||||||
currDistSq < distSq)
|
currLengthSq < lengthSq)
|
||||||
{
|
{
|
||||||
// stop at the edge of the map
|
// stop at the edge of the map
|
||||||
if (curr.x < 0 || curr.x >= world_coord(mapWidth) ||
|
if (curr.x < 0 || curr.x >= world_coord(mapWidth) ||
|
||||||
|
@ -68,7 +67,7 @@ void rayCast(Vector3i src, Vector3i direction, int length,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!callback(curr, currDistSq, data))
|
if (!callback(curr, currLengthSq, data))
|
||||||
{
|
{
|
||||||
// callback doesn't want any more points so return
|
// callback doesn't want any more points so return
|
||||||
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..
|
// 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.
|
// there is a tall structure on the current tile and the current tile is not the starting tile.
|
||||||
/* Get height at this intersection point */
|
/* 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;
|
float newPitch;
|
||||||
|
|
||||||
if (HasTallStructure)
|
if (HasTallStructure)
|
||||||
|
@ -130,15 +129,15 @@ static bool getTileHeightCallback(Vector3i pos, int dist, void* data)
|
||||||
|
|
||||||
if (height <= help->height)
|
if (height <= help->height)
|
||||||
{
|
{
|
||||||
heightDif = 0;
|
heightDiff = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
heightDif = height - help->height;
|
heightDiff = height - help->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Work out the angle to this point from start point */
|
/* 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? */
|
/* Is this the steepest we've found? */
|
||||||
if (newPitch > help->pitch)
|
if (newPitch > help->pitch)
|
||||||
|
|
|
@ -34,7 +34,10 @@
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* The raycast intersection callback.
|
* 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);
|
typedef bool (*RAY_CALLBACK)(Vector3i pos, int dist, void* data);
|
||||||
|
|
||||||
|
|
102
src/visibility.c
102
src/visibility.c
|
@ -104,35 +104,26 @@ void visUpdateLevel(void)
|
||||||
visLevelDecAcc -= visLevelDec;
|
visLevelDecAcc -= visLevelDec;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDWORD visObjHeight(const BASE_OBJECT * const psObject)
|
static int visObjHeight(const BASE_OBJECT * psObject)
|
||||||
{
|
{
|
||||||
SDWORD height;
|
|
||||||
|
|
||||||
switch (psObject->type)
|
switch (psObject->type)
|
||||||
{
|
{
|
||||||
case OBJ_DROID:
|
case OBJ_DROID:
|
||||||
height = 80;
|
// return psObject->sDisplay.imd->pos.max.y;
|
||||||
// height = psObject->sDisplay.imd->pos.max.y;
|
return 80;
|
||||||
break;
|
|
||||||
case OBJ_STRUCTURE:
|
case OBJ_STRUCTURE:
|
||||||
height = psObject->sDisplay.imd->max.y;
|
|
||||||
break;
|
|
||||||
case OBJ_FEATURE:
|
case OBJ_FEATURE:
|
||||||
height = psObject->sDisplay.imd->max.y;
|
return psObject->sDisplay.imd->max.y;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
ASSERT( false,"visObjHeight: unknown object type" );
|
ASSERT( false,"visObjHeight: unknown object type" );
|
||||||
height = 0;
|
return 0;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The terrain revealing ray callback */
|
/* The terrain revealing ray callback */
|
||||||
bool rayTerrainCallback(Vector3i pos, int dist, void * data)
|
bool rayTerrainCallback(Vector3i pos, int dist, void * data)
|
||||||
{
|
{
|
||||||
SDWORD newH, newG; // The new gradient
|
int newH, newG; // The new gradient
|
||||||
MAPTILE *psTile;
|
MAPTILE *psTile;
|
||||||
|
|
||||||
ASSERT(pos.x >= 0 && pos.x < world_coord(mapWidth)
|
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;
|
newH = psTile->height * ELEVATION_SCALE;
|
||||||
newG = (newH - startH) * GRAD_MUL / (SDWORD)dist;
|
newG = (newH - startH) * GRAD_MUL / dist;
|
||||||
if (newG >= currG)
|
if (newG >= currG)
|
||||||
{
|
{
|
||||||
currG = newG;
|
currG = newG;
|
||||||
|
@ -184,8 +175,6 @@ bool rayTerrainCallback(Vector3i pos, int dist, void * data)
|
||||||
static bool rayLOSCallback(Vector3i pos, int dist, void *data)
|
static bool rayLOSCallback(Vector3i pos, int dist, void *data)
|
||||||
{
|
{
|
||||||
int newG; // The new gradient
|
int newG; // The new gradient
|
||||||
int distSq = dist*dist;
|
|
||||||
MAPTILE *psTile;
|
|
||||||
|
|
||||||
ASSERT(pos.x >= 0 && pos.x < world_coord(mapWidth)
|
ASSERT(pos.x >= 0 && pos.x < world_coord(mapWidth)
|
||||||
&& pos.y >= 0 && pos.y < world_coord(mapHeight),
|
&& 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);
|
lastH = map_Height(pos.x, pos.y);
|
||||||
|
|
||||||
// See if the ray has reached the target
|
// See if the ray has reached the target
|
||||||
if (distSq >= tarDist)
|
if (dist >= tarDist)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (blockingWall)
|
||||||
{
|
{
|
||||||
// Store the height at this tile for next time round
|
// Store the height at this tile for next time round
|
||||||
Vector2i tile = { map_coord(pos.x), map_coord(pos.y) };
|
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))
|
if (TileHasWall(psTile) && !TileHasSmallStructure(psTile))
|
||||||
{
|
{
|
||||||
lastH = 2*UBYTE_MAX * ELEVATION_SCALE;
|
lastH = 2*UBYTE_MAX * ELEVATION_SCALE;
|
||||||
numWalls += 1;
|
|
||||||
wallX = pos.x;
|
wallX = pos.x;
|
||||||
wallY = pos.y;
|
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 */
|
/* Find out what can see this object */
|
||||||
void processVisibility(BASE_OBJECT *psObj)
|
void processVisibility(BASE_OBJECT *psObj)
|
||||||
{
|
{
|
||||||
UDWORD i;
|
|
||||||
BOOL prevVis[MAX_PLAYERS], currVis[MAX_PLAYERS];
|
BOOL prevVis[MAX_PLAYERS], currVis[MAX_PLAYERS];
|
||||||
SDWORD visLevel;
|
SDWORD visLevel;
|
||||||
BASE_OBJECT *psViewer;
|
BASE_OBJECT *psViewer;
|
||||||
MESSAGE *psMessage;
|
MESSAGE *psMessage;
|
||||||
UDWORD player, ally;
|
unsigned int player;
|
||||||
|
|
||||||
// initialise the visibility array
|
// 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)
|
if (psObj->type == OBJ_DROID)
|
||||||
{
|
{
|
||||||
memset (currVis, 0, sizeof(BOOL) * MAX_PLAYERS);
|
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
|
// 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
|
// Make sure allies can see us
|
||||||
if (bMultiPlayer && game.alliance == ALLIANCES_TEAMS)
|
if (bMultiPlayer && game.alliance == ALLIANCES_TEAMS)
|
||||||
{
|
{
|
||||||
|
unsigned int player;
|
||||||
for (player = 0; player < MAX_PLAYERS; player++)
|
for (player = 0; player < MAX_PLAYERS; player++)
|
||||||
{
|
{
|
||||||
if(player!=psObj->player)
|
if (player != psObj->player && aiCheckAlliances(player, psObj->player))
|
||||||
{
|
|
||||||
if(aiCheckAlliances(player,psObj->player))
|
|
||||||
{
|
{
|
||||||
currVis[player] = true;
|
currVis[player] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// if a player has a SAT_UPLINK structure, they can see everything!
|
// if a player has a SAT_UPLINK structure, they can see everything!
|
||||||
for (player = 0; player < MAX_PLAYERS; player++)
|
for (player = 0; player < MAX_PLAYERS; player++)
|
||||||
|
@ -514,8 +503,7 @@ void processVisibility(BASE_OBJECT *psObj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
psViewer = gridIterate();
|
while (psViewer = gridIterate(), psViewer != NULL)
|
||||||
while (psViewer != NULL)
|
|
||||||
{
|
{
|
||||||
// If we've got ranged line of sight...
|
// If we've got ranged line of sight...
|
||||||
if ( (psViewer->type != OBJ_FEATURE) &&
|
if ( (psViewer->type != OBJ_FEATURE) &&
|
||||||
|
@ -526,7 +514,6 @@ void processVisibility(BASE_OBJECT *psObj)
|
||||||
currVis[psViewer->player] = true;
|
currVis[psViewer->player] = true;
|
||||||
if (!prevVis[psViewer->player])
|
if (!prevVis[psViewer->player])
|
||||||
{
|
{
|
||||||
|
|
||||||
if (psObj->visible[psViewer->player] == 0)
|
if (psObj->visible[psViewer->player] == 0)
|
||||||
{
|
{
|
||||||
psObj->visible[psViewer->player] = 1;
|
psObj->visible[psViewer->player] = 1;
|
||||||
|
@ -537,17 +524,16 @@ void processVisibility(BASE_OBJECT *psObj)
|
||||||
clustObjectSeen(psObj, psViewer);
|
clustObjectSeen(psObj, psViewer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
psViewer = gridIterate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//forward out vision to our allies
|
//forward out vision to our allies
|
||||||
if (bMultiPlayer && game.alliance == ALLIANCES_TEAMS)
|
if (bMultiPlayer && game.alliance == ALLIANCES_TEAMS)
|
||||||
{
|
{
|
||||||
|
unsigned int player;
|
||||||
for (player = 0; player < MAX_PLAYERS; player++)
|
for (player = 0; player < MAX_PLAYERS; player++)
|
||||||
{
|
{
|
||||||
|
unsigned int ally;
|
||||||
for (ally = 0; ally < MAX_PLAYERS; ally++)
|
for (ally = 0; ally < MAX_PLAYERS; ally++)
|
||||||
{
|
{
|
||||||
if (currVis[player] && aiCheckAlliances(player, ally))
|
if (currVis[player] && aiCheckAlliances(player, ally))
|
||||||
|
@ -559,53 +545,50 @@ void processVisibility(BASE_OBJECT *psObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the visibility levels
|
// 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
|
// owner can always see it fully
|
||||||
psObj->visible[i] = UBYTE_MAX;
|
psObj->visible[player] = UBYTE_MAX;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
visLevel = 0;
|
visLevel = (currVis[player] ? UBYTE_MAX : 0);
|
||||||
if (currVis[i])
|
|
||||||
{
|
|
||||||
visLevel = UBYTE_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( (visLevel < psObj->visible[i]) &&
|
// Droids can vanish from view, other objects will stay
|
||||||
|
if ( (visLevel < psObj->visible[player]) &&
|
||||||
(psObj->type == OBJ_DROID) )
|
(psObj->type == OBJ_DROID) )
|
||||||
{
|
{
|
||||||
if (psObj->visible[i] <= visLevelDec)
|
if (psObj->visible[player] <= visLevelDec)
|
||||||
{
|
{
|
||||||
psObj->visible[i] = 0;
|
psObj->visible[player] = 0;
|
||||||
}
|
}
|
||||||
else
|
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
|
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 */
|
/* 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) &&
|
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);
|
debug(LOG_MSG, "Added message for oil well, pViewData=%p", psMessage->pViewData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (((FEATURE *)psObj)->psStats->subType == FEAT_GEN_ARTE)
|
||||||
if (((FEATURE *)psObj)->psStats->subType == FEAT_GEN_ARTE)
|
|
||||||
{
|
{
|
||||||
psMessage = addMessage(MSG_PROXIMITY, true, selectedPlayer);
|
psMessage = addMessage(MSG_PROXIMITY, true, selectedPlayer);
|
||||||
if (psMessage)
|
if (psMessage)
|
||||||
|
@ -735,7 +717,7 @@ void updateSensorDisplay()
|
||||||
|
|
||||||
bool scrRayTerrainCallback(Vector3i pos, int dist, void *data)
|
bool scrRayTerrainCallback(Vector3i pos, int dist, void *data)
|
||||||
{
|
{
|
||||||
SDWORD newH, newG; // The new gradient
|
int newH, newG; // The new gradient
|
||||||
MAPTILE *psTile;
|
MAPTILE *psTile;
|
||||||
|
|
||||||
ASSERT(pos.x >= 0 && pos.x < world_coord(mapWidth)
|
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;
|
newH = psTile->height * ELEVATION_SCALE;
|
||||||
newG = (newH - startH) * GRAD_MUL / (SDWORD)dist;
|
newG = (newH - startH) * GRAD_MUL / dist;
|
||||||
if (newG >= currG)
|
if (newG >= currG)
|
||||||
{
|
{
|
||||||
currG = newG;
|
currG = newG;
|
||||||
|
|
Loading…
Reference in New Issue