Fix building placement, and filter flags for building placement
This commit is contained in:
parent
f436ffa30a
commit
9a9822ff39
5 changed files with 44 additions and 9 deletions
src
|
@ -364,6 +364,8 @@ extern void MarkDrawEntireMap(void);
|
|||
//
|
||||
// in map_fog.c
|
||||
//
|
||||
/// Filter map flags through fog
|
||||
extern int MapFogFilterFlags(Player* player, int x, int y, int mask);
|
||||
/// Mark a tile for normal sight
|
||||
extern void MapMarkTileSight(const Player* player, int x, int y);
|
||||
/// Unmark a tile for normal sight
|
||||
|
|
|
@ -225,6 +225,36 @@ global unsigned char IsTileVisible(const Player* player, int x, int y)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
** Find out what the tile flags are a tile is covered by fog
|
||||
**
|
||||
** @param player player who is doing operation
|
||||
** @param x X map location
|
||||
** @param y Y map location
|
||||
** @param mask input mask to filter
|
||||
**
|
||||
** @return Filtered mask after taking fog into account
|
||||
*/
|
||||
global int MapFogFilterFlags(Player* player, int x, int y, int mask)
|
||||
{
|
||||
int nunits;
|
||||
int unitcount;
|
||||
int fogmask;
|
||||
Unit* table[UnitMax];
|
||||
|
||||
// Calculate Mask for tile with fog
|
||||
nunits = UnitCacheOnTile(x, y, table);
|
||||
fogmask = -1;
|
||||
unitcount = 0;
|
||||
while (unitcount < nunits) {
|
||||
if (!UnitVisibleAsGoal(table[unitcount], player)) {
|
||||
fogmask &= ~table[unitcount]->Type->FieldFlags;
|
||||
}
|
||||
++unitcount;
|
||||
}
|
||||
return mask & fogmask;
|
||||
}
|
||||
|
||||
/**
|
||||
** Mark a tile's sight. (Explore and make visible.)
|
||||
**
|
||||
|
|
|
@ -124,7 +124,7 @@ global void DoRightButton(int sx, int sy)
|
|||
// Unit selected isn't owned by the player.
|
||||
// You can't select your own units + foreign unit(s).
|
||||
//
|
||||
if (!CanSelectMultipleUnits(Selected[0]->Player)) {
|
||||
if (!CanSelectMultipleUnits(Selected[0]->Player) && 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1448,7 +1448,7 @@ global void UIHandleButtonDown(unsigned button)
|
|||
}
|
||||
}
|
||||
if (CanBuildUnitTypeMask(Selected[0], CursorBuilding, x, y,
|
||||
Selected[0]->Type->MovementMask & ~(MapFieldBuilding | MapFieldLandUnit | MapFieldSeaUnit)) &&
|
||||
Selected[0]->Type->MovementMask) &&
|
||||
(explored || ReplayRevealMap)) {
|
||||
PlayGameSound(GameSounds.PlacementSuccess.Sound,
|
||||
MaxSampleVolume);
|
||||
|
|
|
@ -2106,6 +2106,7 @@ global int CanBuildUnitTypeMask(const Unit* unit, const UnitType* type, int x, i
|
|||
int w;
|
||||
int h;
|
||||
int j;
|
||||
int testmask;
|
||||
Player* player;
|
||||
|
||||
// Terrain Flags don't matter.
|
||||
|
@ -2209,7 +2210,12 @@ global int CanBuildUnitTypeMask(const Unit* unit, const UnitType* type, int x, i
|
|||
|
||||
for (h = type->TileHeight; h--;) {
|
||||
for (w = type->TileWidth; w--;) {
|
||||
if (!CanBuildOn(x + w, y + h, mask)) {
|
||||
if (player) {
|
||||
testmask = MapFogFilterFlags(player, x + w, y + h, mask);
|
||||
} else {
|
||||
testmask = mask;
|
||||
}
|
||||
if (!CanBuildOn(x + w, y + h, testmask)) {
|
||||
if (unit) {
|
||||
TheMap.Fields[unit->X + unit->Y * TheMap.Width].Flags |= j;
|
||||
}
|
||||
|
|
|
@ -545,14 +545,11 @@ local void DrawBuildingCursor(void)
|
|||
while (h--) {
|
||||
w = w0;
|
||||
while (w--) {
|
||||
|
||||
if (f && (CursorBuilding->MustBuildOnTop ||
|
||||
CanBuildOn(mx + w, my + h, mask & ((NumSelected &&
|
||||
!CursorBuilding->BuilderOutside &&
|
||||
CanBuildOn(mx + w, my + h, MapFogFilterFlags(ThisPlayer, mx + w, my + h,
|
||||
mask & ((NumSelected && !CursorBuilding->BuilderOutside &&
|
||||
Selected[0]->X == mx + w && Selected[0]->Y == my + h) ?
|
||||
~(MapFieldLandUnit | MapFieldSeaUnit) : -1) &
|
||||
(IsTileVisible(ThisPlayer, mx + w, my + h) == 1 ?
|
||||
~(MapFieldLandUnit | MapFieldSeaUnit | MapFieldBuilding) : -1)))
|
||||
~(MapFieldLandUnit | MapFieldSeaUnit) : -1))))
|
||||
&& IsMapFieldExplored(ThisPlayer, mx + w, my + h)) {
|
||||
color = ColorGreen;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue