summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clear_cmd.c39
-rw-r--r--command.c2
-rw-r--r--rail_cmd.c43
-rw-r--r--rail_gui.c2
-rw-r--r--station_cmd.c44
-rw-r--r--tunnelbridge_cmd.c36
-rw-r--r--waypoint.c32
7 files changed, 109 insertions, 89 deletions
diff --git a/clear_cmd.c b/clear_cmd.c
index f12f37ff1..a854b3985 100644
--- a/clear_cmd.c
+++ b/clear_cmd.c
@@ -212,7 +212,7 @@ static bool TerraformTileHeight(TerraformerState *ts, uint tile, int height)
/** Terraform land
* @param x,y coordinates to terraform
- * @param p1 corners to terraform. Human user only north, towns more
+ * @param p1 corners to terraform.
* @param p2 direction; eg up or down
*/
int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2)
@@ -224,9 +224,6 @@ int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2)
TerraformerHeightMod modheight_data[576];
TileIndex tile_table_data[625];
- /* A normal user can only terraform one corner, the northern one; p1 & 8 */
- if (_current_player < MAX_PLAYERS && p1 != 8) return CMD_ERROR;
-
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
_error_message = INVALID_STRING_ID;
@@ -380,31 +377,28 @@ int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
return cost;
}
-/* Purchase a land area
- * p1 = unused
- * p2 = unused
+/** Purchase a land area. Actually you only purchase one tile, so
+ * the name is a bit confusing ;p
+ * @param x,y the tile the player is purchasing
+ * @param p1 unused
+ * @param p2 unused
*/
-
int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
- uint tile;
+ TileIndex tile;
int32 cost;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
tile = TILE_FROM_XY(x,y);
- if (!EnsureNoVehicle(tile))
- return CMD_ERROR;
+ if (!EnsureNoVehicle(tile)) return CMD_ERROR;
- if (IsTileType(tile, MP_UNMOVABLE) &&
- _map5[tile] == 3 &&
- _map_owner[tile] == _current_player)
+ if (IsTileType(tile, MP_UNMOVABLE) && _map5[tile] == 3 && _map_owner[tile] == _current_player)
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
- if (cost == CMD_ERROR)
- return CMD_ERROR;
+ if (CmdFailed(cost)) return CMD_ERROR;
if (flags & DC_EXEC) {
ModifyTile(tile,
@@ -439,9 +433,15 @@ static int32 ClearTile_Clear(uint tile, byte flags)
return *price;
}
+/** Sell a land area. Actually you only sell one tile, so
+ * the name is a bit confusing ;p
+ * @param x,y the tile the player is selling
+ * @param p1 unused
+ * @param p2 unused
+ */
int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
- uint tile;
+ TileIndex tile;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
@@ -450,13 +450,12 @@ int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
return CMD_ERROR;
- if (!EnsureNoVehicle(tile))
- return CMD_ERROR;
+ if (!EnsureNoVehicle(tile)) return CMD_ERROR;
if (flags & DC_EXEC)
DoClearSquare(tile);
- return - _price.purchase_land*2;
+ return - _price.purchase_land * 2;
}
diff --git a/command.c b/command.c
index f7c0f5cc1..e3aec261c 100644
--- a/command.c
+++ b/command.c
@@ -177,7 +177,6 @@ static CommandProc * const _command_proc_table[] = {
CmdBuildSingleSignal, /* 8 */
CmdRemoveSingleSignal, /* 9 */
CmdTerraformLand, /* 10 */
- /***************************************************/
CmdPurchaseLandArea, /* 11 */
CmdSellLandArea, /* 12 */
CmdBuildTunnel, /* 13 */
@@ -190,6 +189,7 @@ static CommandProc * const _command_proc_table[] = {
NULL, /* 20 */
CmdBuildRoadStop, /* 21 */
NULL, /* 22 */
+ /***************************************************/
CmdBuildLongRoad, /* 23 */
CmdRemoveLongRoad, /* 24 */
CmdBuildRoad, /* 25 */
diff --git a/rail_cmd.c b/rail_cmd.c
index 59eac26d6..624a1d9fe 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -971,15 +971,22 @@ extern int32 DoConvertStationRail(uint tile, uint totype, bool exec);
extern int32 DoConvertStreetRail(uint tile, uint totype, bool exec);
extern int32 DoConvertTunnelBridgeRail(uint tile, uint totype, bool exec);
-// p1 = start tile
-// p2 = new railtype
+/** Convert one rail type to the other. You can convert normal rail to
+ * monorail/maglev easily or vice-versa.
+ * @param ex,ey end tile of rail conversion drag
+ * @param p1 start tile of drag
+ * @param p2 new railtype to convert to
+ */
int32 CmdConvertRail(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
{
int32 ret, cost, money;
- int sx,sy,x,y;
+ int sx, sy, x, y;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
+ if (!ValParamRailtype(p2)) return CMD_ERROR;
+ if (p1 > MapSize()) return CMD_ERROR;
+
// make sure sx,sy are smaller than ex,ey
sx = TileX(p1) * 16;
sy = TileY(p1) * 16;
@@ -987,31 +994,31 @@ int32 CmdConvertRail(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
if (ey < sy) intswap(ey, sy);
money = GetAvailableMoneyForCommand();
- ret = false;
cost = 0;
- for(x=sx; x<=ex; x+=16) {
- for(y=sy; y<=ey; y+=16) {
- uint tile = TILE_FROM_XY(x,y);
- DoConvertRailProc *p;
-
- if (IsTileType(tile, MP_RAILWAY)) p = DoConvertRail;
- else if (IsTileType(tile, MP_STATION)) p = DoConvertStationRail;
- else if (IsTileType(tile, MP_STREET)) p = DoConvertStreetRail;
- else if (IsTileType(tile, MP_TUNNELBRIDGE)) p = DoConvertTunnelBridgeRail;
+
+ for (x = sx; x <= ex; x += 16) {
+ for (y = sy; y <= ey; y += 16) {
+ TileIndex tile = TILE_FROM_XY(x,y);
+ DoConvertRailProc *proc;
+
+ if (IsTileType(tile, MP_RAILWAY)) proc = DoConvertRail;
+ else if (IsTileType(tile, MP_STATION)) proc = DoConvertStationRail;
+ else if (IsTileType(tile, MP_STREET)) proc = DoConvertStreetRail;
+ else if (IsTileType(tile, MP_TUNNELBRIDGE)) proc = DoConvertTunnelBridgeRail;
else continue;
- ret = p(tile, p2, false);
- if (ret == CMD_ERROR) continue;
+ ret = proc(tile, p2, false);
+ if (CmdFailed(ret)) continue;
cost += ret;
if (flags & DC_EXEC) {
if ( (money -= ret) < 0) { _additional_cash_required = ret; return cost - ret; }
- p(tile, p2, true);
+ proc(tile, p2, true);
}
}
}
- if (cost == 0) cost = CMD_ERROR;
- return cost;
+
+ return (cost == 0) ? CMD_ERROR : cost;
}
static int32 RemoveTrainDepot(uint tile, uint32 flags)
diff --git a/rail_gui.c b/rail_gui.c
index 3a6d5a61e..f4f5e4f15 100644
--- a/rail_gui.c
+++ b/rail_gui.c
@@ -121,7 +121,7 @@ static void PlaceRail_Depot(uint tile)
static void PlaceRail_Waypoint(uint tile)
{
if (!_remove_button_clicked) {
- DoCommandP(tile, _waypoint_count > 0 ? (0x100 + _cur_waypoint_type) : 0, 0, CcPlaySound1E, CMD_BUILD_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_BUILD_TRAIN_WAYPOINT));
+ DoCommandP(tile, (_waypoint_count > 0) ? (0x100 + _cur_waypoint_type) : 0, 0, CcPlaySound1E, CMD_BUILD_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_BUILD_TRAIN_WAYPOINT));
} else {
DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_REMOVE_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_REMOVE_TRAIN_WAYPOINT));
}
diff --git a/station_cmd.c b/station_cmd.c
index 3b13c0fdb..2784d6568 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -1116,10 +1116,15 @@ restart:
st->train_tile = tile;
}
-// remove a single tile from a railroad station
+/** Remove a single tile from a railroad station.
+ * This allows for custom-built station with holes and weird layouts
+ * @param x,y tile coordinates to remove
+ * @param p1 unused
+ * @param p2 unused
+ */
int32 CmdRemoveFromRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
- uint tile = TILE_FROM_XY(x, y);
+ TileIndex tile = TILE_FROM_XY(x, y);
Station *st;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
@@ -1386,9 +1391,7 @@ static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
int32 DoConvertStationRail(uint tile, uint totype, bool exec)
{
- Station *st;
-
- st = GetStation(_map2[tile]);
+ const Station *st = GetStation(_map2[tile]);
if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR;
// tile is not a railroad station?
@@ -1427,26 +1430,23 @@ void FindRoadStationSpot(bool truck_station, Station *st, RoadStop ***currstop,
}
}
-/* Build a bus station
- * direction - direction of the stop exit
- * type - 0 for Bus stops, 1 for truck stops
+/** Build a bus station
+ * @param x,y coordinates to build bus station at
+ * @param p1 direction the busstop exit is pointing towards
+ * @param p2 0 for Bus stops, 1 for truck stops
*/
-
-int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 direction, uint32 type)
+int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
+ Station *st;
RoadStop *road_stop;
RoadStop **currstop;
RoadStop *prev = NULL;
- uint tile;
+ TileIndex tile;
int32 cost;
- Station *st;
- //Bus stops have a _map5 value of 0x47 + direction
- //Truck stops have 0x43 + direction
- byte gfxbase = (type) ? 0x43 : 0x47;
+ bool type = !!p2;
- //saveguard the parameters
- if (direction > 3 || type > 1)
- return CMD_ERROR;
+ /* Saveguard the parameters */
+ if (p1 > 3) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
@@ -1455,7 +1455,7 @@ int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 direction, uint32 type
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
return CMD_ERROR;
- cost = CheckFlatLandBelow(tile, 1, 1, flags, 1 << direction, NULL);
+ cost = CheckFlatLandBelow(tile, 1, 1, flags, 1 << p1, NULL);
if (cost == CMD_ERROR)
return CMD_ERROR;
@@ -1526,8 +1526,10 @@ int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 direction, uint32 type
ModifyTile(tile,
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
MP_MAP2 | MP_MAP5 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,
- st->index, /* map2 parameter */
- gfxbase + direction /* map5 parameter */
+ st->index, /* map2 parameter */
+ /* XXX - Truck stops have 0x43 _map5[] value + direction
+ * XXX - Bus stops have a _map5 value of 0x47 + direction */
+ ((type) ? 0x43 : 0x47) + p1 /* map5 parameter */
);
UpdateStationVirtCoordDirty(st);
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index d04ad1a70..6cc1f946e 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -433,7 +433,7 @@ static byte _build_tunnel_railtype;
static int32 DoBuildTunnel(int x, int y, int x2, int y2, uint32 flags, uint exc_tile)
{
- uint end_tile;
+ TileIndex end_tile;
int direction;
int32 cost, ret;
TileInfo ti;
@@ -472,8 +472,7 @@ static int32 DoBuildTunnel(int x, int y, int x2, int y2, uint32 flags, uint exc_
if ( (direction ? 9U : 12U) != ti.tileh)
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
- if (ret == CMD_ERROR)
- return CMD_ERROR;
+ if (CmdFailed(ret)) return CMD_ERROR;
cost += ret;
}
cost += _price.build_tunnel;
@@ -507,8 +506,7 @@ static int32 DoBuildTunnel(int x, int y, int x2, int y2, uint32 flags, uint exc_
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
- if (ret == CMD_ERROR)
- return CMD_ERROR;
+ if (CmdFailed(ret)) return CMD_ERROR;
cost += ret;
}
@@ -533,10 +531,10 @@ static int32 DoBuildTunnel(int x, int y, int x2, int y2, uint32 flags, uint exc_
return cost + _price.build_tunnel;
}
-/* Build Tunnel
- * x,y - start tile coord
- * p1 - railtype
- * p2 - ptr to uint that recieves end tile
+/** Build Tunnel.
+ * @param x,y start tile coord of tunnel
+ * @param p1 railtype
+ * @param p2 unused (XXX - ptr to uint that recieves end tile; wtf?????)
*/
int32 CmdBuildTunnel(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
@@ -545,10 +543,12 @@ int32 CmdBuildTunnel(int x, int y, uint32 flags, uint32 p1, uint32 p2)
uint z;
static const int8 _build_tunnel_coord_mod[4+1] = { -16, 0, 16, 0, -16 };
static const byte _build_tunnel_tileh[4] = {3, 9, 12, 6};
- uint excavated_tile;
+ TileIndex excavated_tile;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
+ if (!ValParamRailtype(p1)) return CMD_ERROR;
+
_build_tunnel_railtype = (byte)(p1 & 0xFF);
_build_tunnel_bh = (byte)(p1 >> 8);
@@ -579,19 +579,14 @@ int32 CmdBuildTunnel(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return CMD_ERROR;
if (ti.tileh != _build_tunnel_tileh[direction]) {
- if (DoCommandByTile(ti.tile, ti.tileh & ~_build_tunnel_tileh[direction], 0, flags, CMD_TERRAFORM_LAND) == CMD_ERROR)
+ if (CmdFailed(DoCommandByTile(ti.tile, ti.tileh & ~_build_tunnel_tileh[direction], 0, flags, CMD_TERRAFORM_LAND)))
return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
excavated_tile = 1;
}
- if (flags & DC_EXEC && DoBuildTunnel(x,y,tiorg.x,tiorg.y,flags&~DC_EXEC,excavated_tile) == CMD_ERROR)
- return CMD_ERROR;
-
- return DoBuildTunnel(x,y,tiorg.x, tiorg.y,flags,excavated_tile);
+ return DoBuildTunnel(x, y, tiorg.x, tiorg.y, flags, excavated_tile);
}
-static const byte _updsignals_tunnel_dir[4] = { 5, 7, 1, 3};
-
TileIndex CheckTunnelBusy(TileIndex tile, uint *length)
{
uint z = GetTileZ(tile);
@@ -625,8 +620,9 @@ TileIndex CheckTunnelBusy(TileIndex tile, uint *length)
static int32 DoClearTunnel(uint tile, uint32 flags)
{
Town *t;
- uint endtile;
+ TileIndex endtile;
uint length;
+ static const byte _updsignals_tunnel_dir[4] = { 5, 7, 1, 3};
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
@@ -835,7 +831,7 @@ static int32 ClearTile_TunnelBridge(uint tile, byte flags) {
int32 DoConvertTunnelBridgeRail(uint tile, uint totype, bool exec)
{
- uint endtile;
+ TileIndex endtile;
uint length;
Vehicle *v;
@@ -870,7 +866,7 @@ int32 DoConvertTunnelBridgeRail(uint tile, uint totype, bool exec)
}
return _price.build_rail >> 1;
} else if ((_map5[tile]&0xC6) == 0x80) {
- uint starttile;
+ TileIndex starttile;
int32 cost;
uint z = TilePixelHeight(tile);
diff --git a/waypoint.c b/waypoint.c
index 47170df65..4d5225b61 100644
--- a/waypoint.c
+++ b/waypoint.c
@@ -147,16 +147,24 @@ static Waypoint *FindDeletedWaypointCloseTo(uint tile)
return best;
}
-/* Convert existing rail to waypoint */
+/** Convert existing rail to waypoint. Eg build a waypoint station over
+ * piece of rail
+ * @param x,y coordinates where waypoint will be built
+ * @param p1 graphics for waypoint type, bit 8 signifies custom waypoint gfx (& 0x100)
+ * @param p2 unused
+ */
int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
- TileIndex tile = TILE_FROM_XY(x,y);
+ TileIndex tile = TILE_FROM_XY(x, y);
Waypoint *wp;
uint tileh;
uint dir;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
+ /* if custom gfx are used, make sure it is within bounds */
+ if ((int)p1 > 0x100 + GetCustomStationsCount(STAT_CLASS_WAYP)) return CMD_ERROR;
+
if (!IsTileType(tile, MP_RAILWAY) || ((dir = 0, _map5[tile] != 1) && (dir = 1, _map5[tile] != 2)))
return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK);
@@ -175,8 +183,7 @@ int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2)
wp = FindDeletedWaypointCloseTo(tile);
if (wp == NULL) {
wp = AllocateWaypoint();
- if (wp == NULL)
- return CMD_ERROR;
+ if (wp == NULL) return CMD_ERROR;
wp->town_index = 0;
wp->string = STR_NULL;
@@ -271,21 +278,30 @@ int32 RemoveTrainWaypoint(uint tile, uint32 flags, bool justremove)
return _price.remove_train_depot;
}
-/* Command call to remove a waypoint */
+/** Delete a waypoint
+ * @param x,y coordinates where waypoint is to be deleted
+ * @param p1 unused
+ * @param p2 unused
+ */
int32 CmdRemoveTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
- uint tile = TILE_FROM_XY(x,y);
+ TileIndex tile = TILE_FROM_XY(x,y);
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
return RemoveTrainWaypoint(tile, flags, true);
}
-/* Rename a waypoint
- * p1 = id of waypoint */
+/** Rename a waypoint.
+ * @param x,y unused
+ * @param p1 id of waypoint
+ * @param p2 unused
+ */
int32 CmdRenameWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
Waypoint *wp;
StringID str;
+ if (!IsWaypointIndex(p1)) return CMD_ERROR;
+
if (_decode_parameters[0] != 0) {
str = AllocateNameUnique((const char*)_decode_parameters, 0);
if (str == 0)