mirror of https://github.com/OpenTTD/OpenTTD
(svn r4073) Add functions to make and test for (most) unmovable tiles
parent
6d4e7d565d
commit
541703a2f6
13
clear_cmd.c
13
clear_cmd.c
|
@ -13,6 +13,7 @@
|
||||||
#include "tunnel_map.h"
|
#include "tunnel_map.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
|
#include "unmovable_map.h"
|
||||||
|
|
||||||
typedef struct TerraformerHeightMod {
|
typedef struct TerraformerHeightMod {
|
||||||
TileIndex tile;
|
TileIndex tile;
|
||||||
|
@ -379,18 +380,16 @@ int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
||||||
|
|
||||||
if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 3 &&
|
if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) {
|
||||||
IsTileOwner(tile, _current_player))
|
|
||||||
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
|
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
|
||||||
|
}
|
||||||
|
|
||||||
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
if (CmdFailed(cost)) return CMD_ERROR;
|
if (CmdFailed(cost)) return CMD_ERROR;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
ModifyTile(tile,
|
MakeOwnedLand(tile, _current_player);
|
||||||
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5,
|
MarkTileDirtyByTile(tile);
|
||||||
3 /* map5 */
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cost + _price.purchase_land * 10;
|
return cost + _price.purchase_land * 10;
|
||||||
|
@ -435,7 +434,7 @@ int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
tile = TileVirtXY(x, y);
|
tile = TileVirtXY(x, y);
|
||||||
|
|
||||||
if (!IsTileType(tile, MP_UNMOVABLE) || _m[tile].m5 != 3) return CMD_ERROR;
|
if (!IsOwnedLandTile(tile)) return CMD_ERROR;
|
||||||
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
|
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "waypoint.h"
|
#include "waypoint.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
#include "train.h"
|
#include "train.h"
|
||||||
|
#include "unmovable_map.h"
|
||||||
|
|
||||||
#include "network_data.h"
|
#include "network_data.h"
|
||||||
#include "network_client.h"
|
#include "network_client.h"
|
||||||
|
@ -1207,7 +1208,8 @@ static void PlaceProc_LightHouse(TileIndex tile)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModifyTile(tile, MP_SETTYPE(MP_UNMOVABLE) | MP_MAP5, 1);
|
MakeLighthouse(tile);
|
||||||
|
MarkTileDirtyByTile(tile);
|
||||||
SndPlayTileFx(SND_1F_SPLAT, tile);
|
SndPlayTileFx(SND_1F_SPLAT, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1217,7 +1219,8 @@ static void PlaceProc_Transmitter(TileIndex tile)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModifyTile(tile, MP_SETTYPE(MP_UNMOVABLE) | MP_MAP5, 0);
|
MakeTransmitter(tile);
|
||||||
|
MarkTileDirtyByTile(tile);
|
||||||
SndPlayTileFx(SND_1F_SPLAT, tile);
|
SndPlayTileFx(SND_1F_SPLAT, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "saveload.h"
|
#include "saveload.h"
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
#include "unmovable_map.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -1577,9 +1578,8 @@ static bool DoBuildStatueOfCompany(TileIndex tile)
|
||||||
|
|
||||||
if (CmdFailed(r)) return false;
|
if (CmdFailed(r)) return false;
|
||||||
|
|
||||||
ModifyTile(tile, MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5,
|
MakeStatue(tile, _current_player);
|
||||||
2 /* map5 */
|
MarkTileDirtyByTile(tile);
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
#include "town.h"
|
#include "town.h"
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
|
#include "unmovable_map.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
|
|
||||||
/** Destroy a HQ.
|
/** Destroy a HQ.
|
||||||
|
@ -184,7 +185,7 @@ static void DrawTile_Unmovable(TileInfo *ti)
|
||||||
|
|
||||||
static uint GetSlopeZ_Unmovable(const TileInfo* ti)
|
static uint GetSlopeZ_Unmovable(const TileInfo* ti)
|
||||||
{
|
{
|
||||||
if (_m[ti->tile].m5 == 3) {
|
if (IsOwnedLand(ti->tile)) {
|
||||||
return ti->z + GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh);
|
return ti->z + GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh);
|
||||||
} else {
|
} else {
|
||||||
return ti->z + (ti->tileh == 0 ? 0 : 8);
|
return ti->z + (ti->tileh == 0 ? 0 : 8);
|
||||||
|
@ -193,20 +194,19 @@ static uint GetSlopeZ_Unmovable(const TileInfo* ti)
|
||||||
|
|
||||||
static uint GetSlopeTileh_Unmovable(const TileInfo *ti)
|
static uint GetSlopeTileh_Unmovable(const TileInfo *ti)
|
||||||
{
|
{
|
||||||
return _m[ti->tile].m5 == 3 ? ti->tileh : 0;
|
return IsOwnedLand(ti->tile) ? ti->tileh : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32 ClearTile_Unmovable(TileIndex tile, byte flags)
|
static int32 ClearTile_Unmovable(TileIndex tile, byte flags)
|
||||||
{
|
{
|
||||||
byte m5 = _m[tile].m5;
|
if (_m[tile].m5 & 0x80) {
|
||||||
|
|
||||||
if (m5 & 0x80) {
|
|
||||||
if (_current_player == OWNER_WATER) return DestroyCompanyHQ(tile, DC_EXEC);
|
if (_current_player == OWNER_WATER) return DestroyCompanyHQ(tile, DC_EXEC);
|
||||||
return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);
|
return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m5 == 3) // company owned land
|
if (IsOwnedLand(tile)) {
|
||||||
return DoCommandByTile(tile, 0, 0, flags, CMD_SELL_LAND_AREA);
|
return DoCommandByTile(tile, 0, 0, flags, CMD_SELL_LAND_AREA);
|
||||||
|
}
|
||||||
|
|
||||||
// checks if you're allowed to remove unmovable things
|
// checks if you're allowed to remove unmovable things
|
||||||
if (_game_mode != GM_EDITOR && _current_player != OWNER_WATER && ((flags & DC_AUTO || !_cheats.magic_bulldozer.value)) )
|
if (_game_mode != GM_EDITOR && _current_player != OWNER_WATER && ((flags & DC_AUTO || !_cheats.magic_bulldozer.value)) )
|
||||||
|
@ -245,19 +245,16 @@ static void GetAcceptedCargo_Unmovable(TileIndex tile, AcceptedCargo ac)
|
||||||
ac[CT_MAIL] = max(1, level / 2);
|
ac[CT_MAIL] = max(1, level / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const StringID _unmovable_tile_str[] = {
|
|
||||||
STR_5803_COMPANY_HEADQUARTERS,
|
|
||||||
STR_5801_TRANSMITTER,
|
|
||||||
STR_5802_LIGHTHOUSE,
|
|
||||||
STR_2016_STATUE,
|
|
||||||
STR_5805_COMPANY_OWNED_LAND,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void GetTileDesc_Unmovable(TileIndex tile, TileDesc *td)
|
static void GetTileDesc_Unmovable(TileIndex tile, TileDesc *td)
|
||||||
{
|
{
|
||||||
int i = _m[tile].m5;
|
switch (GetUnmovableType(tile)) {
|
||||||
if (i & 0x80) i = -1;
|
case UNMOVABLE_TRANSMITTER: td->str = STR_5801_TRANSMITTER; break;
|
||||||
td->str = _unmovable_tile_str[i + 1];
|
case UNMOVABLE_LIGHTHOUSE: td->str = STR_5802_LIGHTHOUSE; break;
|
||||||
|
case UNMOVABLE_STATUE: td->str = STR_2016_STATUE; break;
|
||||||
|
case UNMOVABLE_OWNED_LAND: td->str = STR_5805_COMPANY_OWNED_LAND; break;
|
||||||
|
default: td->str = STR_5803_COMPANY_HEADQUARTERS; break;
|
||||||
|
}
|
||||||
td->owner = GetTileOwner(tile);
|
td->owner = GetTileOwner(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,9 +318,7 @@ static bool checkRadioTowerNearby(TileIndex tile)
|
||||||
TileIndex tile_s = tile - TileDiffXY(4, 4);
|
TileIndex tile_s = tile - TileDiffXY(4, 4);
|
||||||
|
|
||||||
BEGIN_TILE_LOOP(tile, 9, 9, tile_s)
|
BEGIN_TILE_LOOP(tile, 9, 9, tile_s)
|
||||||
// already a radio tower here?
|
if (IsTransmitterTile(tile)) return false;
|
||||||
if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 0)
|
|
||||||
return false;
|
|
||||||
END_TILE_LOOP(tile, 9, 9, tile_s)
|
END_TILE_LOOP(tile, 9, 9, tile_s)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -345,9 +340,7 @@ void GenerateUnmovables(void)
|
||||||
tile = RandomTile();
|
tile = RandomTile();
|
||||||
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h >= 32) {
|
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h >= 32) {
|
||||||
if (!checkRadioTowerNearby(tile)) continue;
|
if (!checkRadioTowerNearby(tile)) continue;
|
||||||
SetTileType(tile, MP_UNMOVABLE);
|
MakeTransmitter(tile);
|
||||||
SetTileOwner(tile, OWNER_NONE);
|
|
||||||
_m[tile].m5 = 0;
|
|
||||||
if (--j == 0) break;
|
if (--j == 0) break;
|
||||||
}
|
}
|
||||||
} while (--i);
|
} while (--i);
|
||||||
|
@ -380,9 +373,7 @@ restart:
|
||||||
|
|
||||||
assert(tile == TILE_MASK(tile));
|
assert(tile == TILE_MASK(tile));
|
||||||
|
|
||||||
SetTileType(tile, MP_UNMOVABLE);
|
MakeLighthouse(tile);
|
||||||
SetTileOwner(tile, OWNER_NONE);
|
|
||||||
_m[tile].m5 = 1;
|
|
||||||
} while (--i);
|
} while (--i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
typedef enum UnmovableType {
|
||||||
|
UNMOVABLE_TRANSMITTER = 0,
|
||||||
|
UNMOVABLE_LIGHTHOUSE = 1,
|
||||||
|
UNMOVABLE_STATUE = 2,
|
||||||
|
UNMOVABLE_OWNED_LAND = 3
|
||||||
|
} UnmovableType;
|
||||||
|
|
||||||
|
|
||||||
|
static inline UnmovableType GetUnmovableType(TileIndex t)
|
||||||
|
{
|
||||||
|
return _m[t].m5;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline bool IsTransmitterTile(TileIndex t)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
IsTileType(t, MP_UNMOVABLE) &&
|
||||||
|
GetUnmovableType(t) == UNMOVABLE_TRANSMITTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline bool IsOwnedLand(TileIndex t)
|
||||||
|
{
|
||||||
|
return GetUnmovableType(t) == UNMOVABLE_OWNED_LAND;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool IsOwnedLandTile(TileIndex t)
|
||||||
|
{
|
||||||
|
return IsTileType(t, MP_UNMOVABLE) && IsOwnedLand(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void MakeUnmovable(TileIndex t, UnmovableType u, Owner o)
|
||||||
|
{
|
||||||
|
SetTileType(t, MP_UNMOVABLE);
|
||||||
|
SetTileOwner(t, o);
|
||||||
|
_m[t].m2 = 0;
|
||||||
|
_m[t].m3 = 0;
|
||||||
|
_m[t].m4 = 0;
|
||||||
|
_m[t].m5 = u;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void MakeTransmitter(TileIndex t)
|
||||||
|
{
|
||||||
|
MakeUnmovable(t, UNMOVABLE_TRANSMITTER, OWNER_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void MakeLighthouse(TileIndex t)
|
||||||
|
{
|
||||||
|
MakeUnmovable(t, UNMOVABLE_LIGHTHOUSE, OWNER_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void MakeStatue(TileIndex t, Owner o)
|
||||||
|
{
|
||||||
|
MakeUnmovable(t, UNMOVABLE_STATUE, o);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void MakeOwnedLand(TileIndex t, Owner o)
|
||||||
|
{
|
||||||
|
MakeUnmovable(t, UNMOVABLE_OWNED_LAND, o);
|
||||||
|
}
|
Loading…
Reference in New Issue