src/tunnelbridge_cmd.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
equal deleted inserted replaced
9912:1ac8aac92385 9913:e79cd19772dd
   108  * - valid slopes without foundation
   108  * - valid slopes without foundation
   109  * - valid slopes with foundation
   109  * - valid slopes with foundation
   110  * - rest is invalid
   110  * - rest is invalid
   111  */
   111  */
   112 #define M(x) (1 << (x))
   112 #define M(x) (1 << (x))
   113 static int32 CheckBridgeSlopeNorth(Axis axis, Slope tileh)
   113 static CommandCost CheckBridgeSlopeNorth(Axis axis, Slope tileh)
   114 {
   114 {
   115 	uint32 valid;
   115 	uint32 valid;
   116 
   116 
   117 	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_NE) : M(SLOPE_NW));
   117 	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_NE) : M(SLOPE_NW));
   118 	if (HASBIT(valid, tileh)) return 0;
   118 	if (HASBIT(valid, tileh)) return 0;
   123 	if (HASBIT(valid, tileh)) return _eco->GetPrice(CEconomy::TERRAFORM);
   123 	if (HASBIT(valid, tileh)) return _eco->GetPrice(CEconomy::TERRAFORM);
   124 
   124 
   125 	return CMD_ERROR;
   125 	return CMD_ERROR;
   126 }
   126 }
   127 
   127 
   128 static int32 CheckBridgeSlopeSouth(Axis axis, Slope tileh)
   128 static CommandCost CheckBridgeSlopeSouth(Axis axis, Slope tileh)
   129 {
   129 {
   130 	uint32 valid;
   130 	uint32 valid;
   131 
   131 
   132 	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_SW) : M(SLOPE_SE));
   132 	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_SW) : M(SLOPE_SE));
   133 	if (HASBIT(valid, tileh)) return 0;
   133 	if (HASBIT(valid, tileh)) return 0;
   173  * @param p2 various bitstuffed elements
   173  * @param p2 various bitstuffed elements
   174  * - p2 = (bit 0- 7) - bridge type (hi bh)
   174  * - p2 = (bit 0- 7) - bridge type (hi bh)
   175  * - p2 = (bit 8-..) - rail type or road types.
   175  * - p2 = (bit 8-..) - rail type or road types.
   176  * - p2 = (bit 15  ) - set means road bridge.
   176  * - p2 = (bit 15  ) - set means road bridge.
   177  */
   177  */
   178 int32 CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   178 CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   179 {
   179 {
   180 	uint bridge_type;
   180 	uint bridge_type;
   181 	RailType railtype;
   181 	RailType railtype;
   182 	RoadTypes roadtypes;
   182 	RoadTypes roadtypes;
   183 	uint x;
   183 	uint x;
   192 	uint z_end;
   192 	uint z_end;
   193 	TileIndex tile;
   193 	TileIndex tile;
   194 	TileIndexDiff delta;
   194 	TileIndexDiff delta;
   195 	uint bridge_len;
   195 	uint bridge_len;
   196 	Axis direction;
   196 	Axis direction;
   197 	int32 cost, terraformcost, ret;
   197 	CommandCost cost, terraformcost, ret;
   198 	bool allow_on_slopes;
   198 	bool allow_on_slopes;
   199 	bool replace_bridge = false;
   199 	bool replace_bridge = false;
   200 	uint replaced_bridge_type;
   200 	uint replaced_bridge_type;
   201 
   201 
   202 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   202 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   451  * @param start_tile start tile of tunnel
   451  * @param start_tile start tile of tunnel
   452  * @param flags type of operation
   452  * @param flags type of operation
   453  * @param p1 railtype or roadtypes. bit 9 set means road tunnel
   453  * @param p1 railtype or roadtypes. bit 9 set means road tunnel
   454  * @param p2 unused
   454  * @param p2 unused
   455  */
   455  */
   456 int32 CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2)
   456 CommandCost CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2)
   457 {
   457 {
   458 	TileIndexDiff delta;
   458 	TileIndexDiff delta;
   459 	TileIndex end_tile;
   459 	TileIndex end_tile;
   460 	DiagDirection direction;
   460 	DiagDirection direction;
   461 	Slope start_tileh;
   461 	Slope start_tileh;
   462 	Slope end_tileh;
   462 	Slope end_tileh;
   463 	uint start_z;
   463 	uint start_z;
   464 	uint end_z;
   464 	uint end_z;
   465 	int32 cost;
   465 	CommandCost cost;
   466 	int32 ret;
   466 	CommandCost ret;
   467 
   467 
   468 	_build_tunnel_endtile = 0;
   468 	_build_tunnel_endtile = 0;
   469 	if (!HASBIT(p1, 9)) {
   469 	if (!HASBIT(p1, 9)) {
   470 		if (!ValParamRailtype(p1)) return CMD_ERROR;
   470 		if (!ValParamRailtype(p1)) return CMD_ERROR;
   471 	} else if (!AreValidRoadTypes((RoadTypes)GB(p1, 0, 3))) {
   471 	} else if (!AreValidRoadTypes((RoadTypes)GB(p1, 0, 3))) {
   576 	/* Otherwise we can only remove town-owned stuff with extra patch-settings, or cheat */
   576 	/* Otherwise we can only remove town-owned stuff with extra patch-settings, or cheat */
   577 	if (IsTileOwner(tile, OWNER_TOWN) && (_patches.extra_dynamite || _cheats.magic_bulldozer.value)) return true;
   577 	if (IsTileOwner(tile, OWNER_TOWN) && (_patches.extra_dynamite || _cheats.magic_bulldozer.value)) return true;
   578 	return false;
   578 	return false;
   579 }
   579 }
   580 
   580 
   581 static int32 DoClearTunnel(TileIndex tile, uint32 flags)
   581 static CommandCost DoClearTunnel(TileIndex tile, uint32 flags)
   582 {
   582 {
   583 	Town *t = NULL;
   583 	Town *t = NULL;
   584 	TileIndex endtile;
   584 	TileIndex endtile;
   585 	uint length;
   585 	uint length;
   586 
   586 
   636 		}
   636 		}
   637 	}
   637 	}
   638 	return false;
   638 	return false;
   639 }
   639 }
   640 
   640 
   641 static int32 DoClearBridge(TileIndex tile, uint32 flags)
   641 static CommandCost DoClearBridge(TileIndex tile, uint32 flags)
   642 {
   642 {
   643 	DiagDirection direction;
   643 	DiagDirection direction;
   644 	TileIndexDiff delta;
   644 	TileIndexDiff delta;
   645 	TileIndex endtile;
   645 	TileIndex endtile;
   646 	Town *t = NULL;
   646 	Town *t = NULL;
   696 	}
   696 	}
   697 
   697 
   698 	return (DistanceManhattan(tile, endtile) + 1) * _eco->GetPrice(CEconomy::CLEAR_BRIDGE);
   698 	return (DistanceManhattan(tile, endtile) + 1) * _eco->GetPrice(CEconomy::CLEAR_BRIDGE);
   699 }
   699 }
   700 
   700 
   701 static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags)
   701 static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
   702 {
   702 {
   703 	if (IsTunnel(tile)) {
   703 	if (IsTunnel(tile)) {
   704 		if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
   704 		if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
   705 		return DoClearTunnel(tile, flags);
   705 		return DoClearTunnel(tile, flags);
   706 	} else if (IsBridge(tile)) { // XXX Is this necessary?
   706 	} else if (IsBridge(tile)) { // XXX Is this necessary?
   719  * @param totype      The railtype we want to convert to
   719  * @param totype      The railtype we want to convert to
   720  * @param exec        Switches between test and execute mode
   720  * @param exec        Switches between test and execute mode
   721  * @return            The cost and state of the operation
   721  * @return            The cost and state of the operation
   722  * @retval CMD_ERROR  An error occured during the operation.
   722  * @retval CMD_ERROR  An error occured during the operation.
   723  */
   723  */
   724 int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
   724 CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
   725 {
   725 {
   726 	TileIndex endtile;
   726 	TileIndex endtile;
   727 
   727 
   728 	if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
   728 	if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
   729 		uint length;
   729 		uint length;