Skip to content

Commit

Permalink
walls: Show hardpoint blueprints even over walls.
Browse files Browse the repository at this point in the history
Refs ticket:1173.
  • Loading branch information
Cyp committed Nov 18, 2011
1 parent 2a4a8a6 commit a0aaaa9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
21 changes: 14 additions & 7 deletions src/display3d.cpp
Expand Up @@ -1466,6 +1466,12 @@ void displayStaticObjects( void )
pie_SetDepthOffset(0.0f);
}

static bool tileHasIncompatibleStructure(MAPTILE const *tile, STRUCTURE_STATS const *stats)
{
STRUCTURE *psStruct = castStructure(tile->psObject);
return psStruct != NULL && (!isWall(psStruct->pStructureType->type) || !isBuildableOnWalls(stats->type));
}

static void drawLineBuild(STRUCTURE_STATS *psStats, int left, int right, int up, int down, uint16_t direction, STRUCT_STATES state)
{
if (left != right && up != down)
Expand All @@ -1478,7 +1484,7 @@ static void drawLineBuild(STRUCTURE_STATS *psStats, int left, int right, int up,
{
for (int j = up; j <= down; ++j)
{
if (TileHasStructure(mapTile(i,j)))
if (tileHasIncompatibleStructure(mapTile(i,j), psStats))
{
continue; // construction has started
}
Expand All @@ -1489,9 +1495,10 @@ static void drawLineBuild(STRUCTURE_STATS *psStats, int left, int right, int up,
}
}

static void renderBuildOrder(int32_t order, BASE_STATS *stats, int32_t x, int32_t y, int32_t x2, int32_t y2, uint16_t dir, STRUCT_STATES state)
static void renderBuildOrder(int32_t order, STRUCTURE_STATS *stats, int32_t x, int32_t y, int32_t x2, int32_t y2, uint16_t dir, STRUCT_STATES state)
{
if (!stats) return;

//draw the current build site if its a line of structures
if (order == DORDER_LINEBUILD)
{
Expand All @@ -1503,11 +1510,11 @@ static void renderBuildOrder(int32_t order, BASE_STATS *stats, int32_t x, int32_
up = MIN(map_coord(y), map_coord(y2));
down = MAX(map_coord(y), map_coord(y2));

drawLineBuild((STRUCTURE_STATS *)stats, left, right, up, down, dir, state);
drawLineBuild(stats, left, right, up, down, dir, state);
}
else if (order == DORDER_BUILD && !TileHasStructure(mapTile(map_coord(x), map_coord(y))))
else if (order == DORDER_BUILD && !tileHasIncompatibleStructure(mapTile(map_coord(x), map_coord(y)), stats))
{
Blueprint blueprint((STRUCTURE_STATS *)stats, Vector2i(x, y), dir, state);
Blueprint blueprint(stats, Vector2i(x, y), dir, state);
blueprints.push_back(blueprint);
}
}
Expand Down Expand Up @@ -1604,12 +1611,12 @@ void displayBlueprints(void)
{
if (psDroid->droidType == DROID_CONSTRUCT || psDroid->droidType == DROID_CYBORG_CONSTRUCT)
{
renderBuildOrder(psDroid->order, psDroid->psTarStats, psDroid->orderX, psDroid->orderY, psDroid->orderX2, psDroid->orderY2, psDroid->orderDirection, state);
renderBuildOrder(psDroid->order, (STRUCTURE_STATS *)psDroid->psTarStats, psDroid->orderX, psDroid->orderY, psDroid->orderX2, psDroid->orderY2, psDroid->orderDirection, state);
//now look thru' the list of orders to see if more building sites
for (int order = psDroid->listPendingBegin; order < (int)psDroid->asOrderList.size(); order++)
{
OrderListEntry const *o = &psDroid->asOrderList[order];
renderBuildOrder(o->order, (BASE_STATS *)o->psOrderTarget, o->x, o->y, o->x2, o->y2, o->direction, state);
renderBuildOrder(o->order, (STRUCTURE_STATS *)o->psOrderTarget, o->x, o->y, o->x2, o->y2, o->direction, state);
}
}
}
Expand Down
26 changes: 19 additions & 7 deletions src/structure.cpp
Expand Up @@ -1145,11 +1145,23 @@ static WallOrientation structWallScan(bool aWallPresent[5][5], int x, int y)

static bool isWallCombiningStructureType(STRUCTURE_STATS *pStructureType)
{
return pStructureType->type == REF_WALL ||
pStructureType->type == REF_GATE ||
pStructureType->type == REF_WALLCORNER ||
(pStructureType->type == REF_DEFENSE && pStructureType->strength == STRENGTH_HARD) ||
(pStructureType->type == REF_BLASTDOOR && pStructureType->strength == STRENGTH_HARD); // fortresses
STRUCTURE_TYPE type = pStructureType->type;
STRUCT_STRENGTH strength = pStructureType->strength;
return type == REF_WALL ||
type == REF_GATE ||
type == REF_WALLCORNER ||
(type == REF_DEFENSE && strength == STRENGTH_HARD) ||
(type == REF_BLASTDOOR && strength == STRENGTH_HARD); // fortresses
}

bool isWall(STRUCTURE_TYPE type)
{
return type == REF_WALL || type == REF_WALLCORNER;
}

bool isBuildableOnWalls(STRUCTURE_TYPE type)
{
return type == REF_DEFENSE || type == REF_GATE;
}

static void structFindWalls(unsigned player, int mapX, int mapY, bool aWallPresent[5][5], STRUCTURE *apsStructs[5][5])
Expand Down Expand Up @@ -1507,13 +1519,13 @@ STRUCTURE* buildStructureDir(STRUCTURE_STATS *pStructureType, UDWORD x, UDWORD y

/* Remove any walls underneath the building. You can build defense buildings on top
* of walls, you see. This is not the place to test whether we own it! */
if ((pStructureType->type == REF_DEFENSE || pStructureType->type == REF_GATE) && TileHasWall(psTile))
if (isBuildableOnWalls(pStructureType->type) && TileHasWall(psTile))
{
removeStruct((STRUCTURE *)psTile->psObject, true);
}

// don't really think this should be done here, but dont know otherwise.alexl
if(pStructureType->type == REF_WALLCORNER || pStructureType->type == REF_WALL)
if (isWall(pStructureType->type))
{
if (TileHasStructure(mapTile(map.x + width, map.y + breadth)))
{
Expand Down
3 changes: 3 additions & 0 deletions src/structure.h
Expand Up @@ -145,6 +145,9 @@ extern UDWORD fillStructureList(STRUCTURE_STATS **ppList, UDWORD selectedPlayer,
x and y in tile-coords*/
extern bool validLocation(BASE_STATS *psStats, unsigned x, unsigned y, uint16_t direction, unsigned player, bool bCheckBuildQueue);

bool isWall(STRUCTURE_TYPE type); ///< Structure is a wall. Not completely sure it handles all cases.
bool isBuildableOnWalls(STRUCTURE_TYPE type); ///< Structure can be built on walls. Not completely sure it handles all cases.

/* for a new structure, find a location along an edge which the droid can get
to and return this as the destination for the droid */
//extern bool getDroidDestination(STRUCTURE_STATS *psPositionStats, UDWORD structX,
Expand Down

0 comments on commit a0aaaa9

Please sign in to comment.