Changeset - r6943:a727ca1f1062
[Not reviewed]
src/ai/ai.cpp
Show inline comments
 
@@ -78,16 +78,16 @@ static void AI_PutCommandInQueue(PlayerI
 
	}
 
}
 

	
 
/**
 
 * Executes a raw DoCommand for the AI.
 
 */
 
int32 AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback)
 
CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback)
 
{
 
	PlayerID old_lp;
 
	int32 res = 0;
 
	CommandCost res = 0;
 
	const char* tmp_cmdtext;
 

	
 
	/* If you enable DC_EXEC with DC_QUERY_COST you are a really strange
 
	 *   person.. should we check for those funny jokes?
 
	 */
 

	
 
@@ -132,13 +132,13 @@ int32 AI_DoCommandCc(TileIndex tile, uin
 
	_local_player = old_lp;
 

	
 
	return res;
 
}
 

	
 

	
 
int32 AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
 
CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
 
{
 
	return AI_DoCommandCc(tile, p1, p2, flags, procc, NULL);
 
}
 

	
 

	
 
/**
src/ai/ai.h
Show inline comments
 
@@ -40,14 +40,14 @@ VARDEF AIPlayer _ai_player[MAX_PLAYERS];
 
// ai.c
 
void AI_StartNewAI(PlayerID player);
 
void AI_PlayerDied(PlayerID player);
 
void AI_RunGameLoop();
 
void AI_Initialize();
 
void AI_Uninitialize();
 
int32 AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
 
int32 AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback);
 
CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
 
CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback);
 

	
 
/** Is it allowed to start a new AI.
 
 * This function checks some boundries to see if we should launch a new AI.
 
 * @return True if we can start a new AI.
 
 */
 
static inline bool AI_AllowNewAI()
src/ai/default/default.cpp
Show inline comments
 
@@ -133,13 +133,13 @@ static void AiStateVehLoop(Player *p)
 
}
 

	
 
static EngineID AiChooseTrainToBuild(RailType railtype, int32 money, byte flag, TileIndex tile)
 
{
 
	EngineID best_veh_index = INVALID_ENGINE;
 
	byte best_veh_score = 0;
 
	int32 ret;
 
	CommandCost ret;
 
	EngineID i;
 

	
 
	for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
 
		const RailVehicleInfo *rvi = RailVehInfo(i);
 
		const Engine* e = GetEngine(i);
 

	
 
@@ -169,13 +169,13 @@ static EngineID AiChooseRoadVehToBuild(C
 
	EngineID end = i + NUM_ROAD_ENGINES;
 

	
 
	for (; i != end; i++) {
 
		const RoadVehicleInfo *rvi = RoadVehInfo(i);
 
		const Engine* e = GetEngine(i);
 
		int32 rating;
 
		int32 ret;
 
		CommandCost ret;
 

	
 
		if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D) {
 
			continue;
 
		}
 

	
 
		/* Skip vehicles which can't take our cargo type */
 
@@ -204,13 +204,13 @@ static EngineID AiChooseAircraftToBuild(
 
	EngineID best_veh_index = INVALID_ENGINE;
 
	int32 best_veh_cost = 0;
 
	EngineID i;
 

	
 
	for (i = AIRCRAFT_ENGINES_INDEX; i != AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; i++) {
 
		const Engine* e = GetEngine(i);
 
		int32 ret;
 
		CommandCost ret;
 

	
 
		if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D) {
 
			continue;
 
		}
 

	
 
		if ((AircraftVehInfo(i)->subtype & AIR_CTOL) != flag) continue;
 
@@ -1635,16 +1635,16 @@ static bool AiCheckTrackResources(TileIn
 
		}
 
	}
 

	
 
	return true;
 
}
 

	
 
static int32 AiDoBuildDefaultRailTrack(TileIndex tile, const AiDefaultBlockData* p, RailType railtype, byte flag)
 
static CommandCost AiDoBuildDefaultRailTrack(TileIndex tile, const AiDefaultBlockData* p, RailType railtype, byte flag)
 
{
 
	int32 ret;
 
	int32 total_cost = 0;
 
	CommandCost ret;
 
	CommandCost total_cost = 0;
 
	Town *t = NULL;
 
	int rating = 0;
 
	int i, j, k;
 

	
 
	for (;;) {
 
		// This will seldomly overflow for valid reasons. Mask it to be on the safe side.
 
@@ -1731,13 +1731,13 @@ clear_town_stuff:;
 
	}
 

	
 
	return total_cost;
 
}
 

	
 
// Returns rule and cost
 
static int AiBuildDefaultRailTrack(TileIndex tile, byte p0, byte p1, byte p2, byte p3, byte dir, byte cargo, RailType railtype, int32* cost)
 
static int AiBuildDefaultRailTrack(TileIndex tile, byte p0, byte p1, byte p2, byte p3, byte dir, byte cargo, RailType railtype, CommandCost* cost)
 
{
 
	int i;
 
	const AiDefaultRailBlock *p;
 

	
 
	for (i = 0; (p = _default_rail_track_data[i]) != NULL; i++) {
 
		if (p->p0 == p0 && p->p1 == p1 && p->p2 == p2 && p->p3 == p3 &&
 
@@ -1818,13 +1818,13 @@ static void AiDoTerraformLand(TileIndex 
 
static void AiStateBuildDefaultRailBlocks(Player *p)
 
{
 
	uint i;
 
	int j;
 
	AiBuildRec *aib;
 
	int rule;
 
	int32 cost;
 
	CommandCost cost;
 

	
 
	// time out?
 
	if (++p->ai.timeout_counter == 1388) {
 
		p->ai.state = AIS_DELETE_RAIL_BLOCKS;
 
		return;
 
	}
 
@@ -2064,13 +2064,13 @@ static inline void AiCheckBuildRailBridg
 

	
 
static inline void AiCheckBuildRailTunnelHere(AiRailFinder *arf, TileIndex tile, const byte *p)
 
{
 
	uint z;
 

	
 
	if (GetTileSlope(tile, &z) == _dir_table_2[p[0] & 3] && z != 0) {
 
		int32 cost = DoCommand(tile, arf->player->ai.railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL);
 
		CommandCost cost = DoCommand(tile, arf->player->ai.railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL);
 

	
 
		if (!CmdFailed(cost) && cost <= (arf->player->player_money >> 4)) {
 
			AiBuildRailRecursive(arf, _build_tunnel_endtile, p[0] & 3);
 
			if (arf->depth == 1) AiCheckRailPathBetter(arf, p);
 
		}
 
	}
 
@@ -2462,13 +2462,13 @@ static void AiStateBuildRailVeh(Player *
 
{
 
	const AiDefaultBlockData *ptr;
 
	TileIndex tile;
 
	EngineID veh;
 
	int i;
 
	CargoID cargo;
 
	int32 cost;
 
	CommandCost cost;
 
	Vehicle *v;
 
	VehicleID loco_id;
 

	
 
	ptr = _default_rail_track_data[p->ai.src.cur_building_rule]->data;
 
	while (ptr->mode != 0) ptr++;
 

	
 
@@ -2602,16 +2602,16 @@ static bool AiCheckRoadResources(TileInd
 
			}
 
		}
 
	}
 
}
 

	
 
static bool _want_road_truck_station;
 
static int32 AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag);
 
static CommandCost AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag);
 

	
 
// Returns rule and cost
 
static int AiFindBestDefaultRoadBlock(TileIndex tile, byte direction, byte cargo, int32 *cost)
 
static int AiFindBestDefaultRoadBlock(TileIndex tile, byte direction, byte cargo, CommandCost *cost)
 
{
 
	int i;
 
	const AiDefaultRoadBlock *p;
 

	
 
	_want_road_truck_station = (cargo & 0x7F) != CT_PASSENGERS;
 

	
 
@@ -2623,16 +2623,16 @@ static int AiFindBestDefaultRoadBlock(Ti
 
		}
 
	}
 

	
 
	return -1;
 
}
 

	
 
static int32 AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
 
static CommandCost AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
 
{
 
	int32 ret;
 
	int32 total_cost = 0;
 
	CommandCost ret;
 
	CommandCost total_cost = 0;
 
	Town *t = NULL;
 
	int rating = 0;
 
	int roadflag = 0;
 

	
 
	for (;p->mode != 4;p++) {
 
		TileIndex c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs));
 
@@ -2718,13 +2718,13 @@ static bool AiCheckBlockDistances(Player
 
static void AiStateBuildDefaultRoadBlocks(Player *p)
 
{
 
	uint i;
 
	int j;
 
	AiBuildRec *aib;
 
	int rule;
 
	int32 cost;
 
	CommandCost cost;
 

	
 
	// time out?
 
	if (++p->ai.timeout_counter == 1388) {
 
		p->ai.state = AIS_DELETE_RAIL_BLOCKS;
 
		return;
 
	}
 
@@ -2755,13 +2755,13 @@ static void AiStateBuildDefaultRoadBlock
 
				// also try the other terraform direction
 
				if (++p->ai.state_counter >= 1000) {
 
					p->ai.state_counter = 0;
 
					p->ai.state_mode = -p->ai.state_mode;
 
				}
 
			} else if (CheckPlayerHasMoney(cost) && AiCheckBlockDistances(p, aib->use_tile)) {
 
				int32 r;
 
				CommandCost r;
 

	
 
				// player has money, build it.
 
				aib->cur_building_rule = rule;
 

	
 
				r = AiDoBuildDefaultRoadBlock(
 
					aib->use_tile,
 
@@ -2964,13 +2964,13 @@ static inline void AiCheckBuildRoadBridg
 

	
 
static inline void AiCheckBuildRoadTunnelHere(AiRoadFinder *arf, TileIndex tile, const byte *p)
 
{
 
	uint z;
 

	
 
	if (GetTileSlope(tile, &z) == _dir_table_2[p[0] & 3] && z != 0) {
 
		int32 cost = DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
 
		CommandCost cost = DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
 

	
 
		if (!CmdFailed(cost) && cost <= (arf->player->player_money >> 4)) {
 
			AiBuildRoadRecursive(arf, _build_tunnel_endtile, p[0] & 3);
 
			if (arf->depth == 1)  AiCheckRoadPathBetter(arf, p);
 
		}
 
	}
 
@@ -3098,13 +3098,13 @@ do_some_terraform:
 
		 * start with best bridge, then go down to worse and worse bridges
 
		 * unnecessary to check for worse bridge (i=0), since AI will always build that.
 
		 *AI is so fucked up that fixing this small thing will probably not solve a thing
 
		 */
 
		for (i = 10; i != 0; i--) {
 
			if (CheckBridge_Stuff(i, bridge_len)) {
 
				int32 cost = DoCommand(tile, p->ai.cur_tile_a, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE);
 
				CommandCost cost = DoCommand(tile, p->ai.cur_tile_a, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE);
 
				if (!CmdFailed(cost) && cost < (p->player_money >> 5)) break;
 
			}
 
		}
 

	
 
		// Build it
 
		DoCommand(tile, p->ai.cur_tile_a, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO | DC_EXEC, CMD_BUILD_BRIDGE);
 
@@ -3384,16 +3384,16 @@ static void AiStateAirportStuff(Player *
 

	
 
	p->ai.state = AIS_BUILD_DEFAULT_AIRPORT_BLOCKS;
 
	p->ai.state_mode = 255;
 
	p->ai.state_counter = 0;
 
}
 

	
 
static int32 AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
 
static CommandCost AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
 
{
 
	uint32 avail_airports = GetValidAirports();
 
	int32 total_cost = 0, ret;
 
	CommandCost total_cost = 0, ret;
 

	
 
	for (; p->mode == 0; p++) {
 
		if (!HASBIT(avail_airports, p->attr)) return CMD_ERROR;
 
		ret = DoCommand(TILE_MASK(tile + ToTileIndexDiff(p->tileoffs)), p->attr, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_AIRPORT);
 
		if (CmdFailed(ret)) return CMD_ERROR;
 
		total_cost += ret;
 
@@ -3421,13 +3421,13 @@ static bool AiCheckAirportResources(Tile
 
			return values[cargo] >= 8;
 
		}
 
	}
 
	return true;
 
}
 

	
 
static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli, int32 *cost)
 
static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli, CommandCost *cost)
 
{
 
	const AiDefaultBlockData *p;
 
	uint i;
 

	
 
	for (i = 0; (p = _airport_default_block_data[i]) != NULL; i++) {
 
		// If we are doing a helicopter service, avoid building
 
@@ -3443,13 +3443,13 @@ static int AiFindBestDefaultAirportBlock
 

	
 
static void AiStateBuildDefaultAirportBlocks(Player *p)
 
{
 
	int i, j;
 
	AiBuildRec *aib;
 
	int rule;
 
	int32 cost;
 
	CommandCost cost;
 

	
 
	// time out?
 
	if (++p->ai.timeout_counter == 1388) {
 
		p->ai.state = AIS_0;
 
		return;
 
	}
 
@@ -3482,13 +3482,13 @@ static void AiStateBuildDefaultAirportBl
 
				if (++p->ai.state_counter >= 1000) {
 
					p->ai.state_counter = 0;
 
					p->ai.state_mode = -p->ai.state_mode;
 
				}
 
			} else if (CheckPlayerHasMoney(cost) && AiCheckBlockDistances(p, aib->use_tile)) {
 
				// player has money, build it.
 
				int32 r;
 
				CommandCost r;
 

	
 
				aib->cur_building_rule = rule;
 

	
 
				r = AiDoBuildDefaultAirportBlock(
 
					aib->use_tile,
 
					_airport_default_block_data[rule],
src/ai/trolly/build.cpp
Show inline comments
 
@@ -33,13 +33,13 @@ bool AiNew_Build_CompanyHQ(Player *p, Ti
 
//    type : AI_TRAIN/AI_BUS/AI_TRUCK : indicates the type of station
 
//    tile : tile where station is going to be build
 
//    length : in case of AI_TRAIN: length of station
 
//    numtracks : in case of AI_TRAIN: tracks of station
 
//    direction : the direction of the station
 
//    flag : flag passed to DoCommand (normally 0 to get the cost or DC_EXEC to build it)
 
int AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag)
 
CommandCost AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag)
 
{
 
	if (type == AI_TRAIN)
 
		return AI_DoCommand(tile, direction + (numtracks << 8) + (length << 16), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_RAILROAD_STATION);
 

	
 
	if (type == AI_BUS)
 
		return AI_DoCommand(tile, direction, ROADTYPES_ROAD << 2 | RoadStop::BUS, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_STOP);
 
@@ -50,13 +50,13 @@ int AiNew_Build_Station(Player *p, byte 
 

	
 
// Builds a brdige. The second best out of the ones available for this player
 
//  Params:
 
//   tile_a : starting point
 
//   tile_b : end point
 
//   flag : flag passed to DoCommand
 
int AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag)
 
CommandCost AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag)
 
{
 
	int bridge_type, bridge_len, type, type2;
 

	
 
	// Find a good bridgetype (the best money can buy)
 
	bridge_len = GetBridgeLength(tile_a, tile_b);
 
	type = type2 = 0;
 
@@ -87,21 +87,21 @@ int AiNew_Build_Bridge(Player *p, TileIn
 
//
 
//  Params:
 
//   PathFinderInfo : Pointer to the PathFinderInfo used for AiPathFinder
 
//   part : Which part we need to build
 
//
 
// TODO: skip already builded road-pieces (e.g.: cityroad)
 
int AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag)
 
CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag)
 
{
 
	int part = PathFinderInfo->position;
 
	byte *route_extra = PathFinderInfo->route_extra;
 
	TileIndex *route = PathFinderInfo->route;
 
	int dir;
 
	int old_dir = -1;
 
	int cost = 0;
 
	int res;
 
	CommandCost cost = 0;
 
	CommandCost res;
 
	// We need to calculate the direction with the parent of the parent.. so we skip
 
	//  the first pieces and the last piece
 
	if (part < 1) part = 1;
 
	// When we are done, stop it
 
	if (part >= PathFinderInfo->route_length - 1) {
 
		PathFinderInfo->position = -2;
 
@@ -240,13 +240,13 @@ EngineID AiNew_PickVehicle(Player *p)
 

	
 
		/* Loop through all road vehicles */
 
		for (i = start; i != end; i++) {
 
			const RoadVehicleInfo *rvi = RoadVehInfo(i);
 
			const Engine* e = GetEngine(i);
 
			int32 rating;
 
			int32 ret;
 
			CommandCost ret;
 

	
 
			/* Skip vehicles which can't take our cargo type */
 
			if (rvi->cargo_type != p->ainew.cargo && !CanRefitTo(i, p->ainew.cargo)) continue;
 

	
 
			// Is it availiable?
 
			// Also, check if the reliability of the vehicle is above the AI_VEHICLE_MIN_RELIABILTY
 
@@ -290,13 +290,13 @@ void CcAI(bool success, TileIndex tile, 
 
		p->ainew.state = AI_STATE_NOTHING;
 
	}
 
}
 

	
 

	
 
// Builds the best vehicle possible
 
int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag)
 
CommandCost AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag)
 
{
 
	EngineID i = AiNew_PickVehicle(p);
 

	
 
	if (i == INVALID_ENGINE) return CMD_ERROR;
 
	if (p->ainew.tbt == AI_TRAIN) return CMD_ERROR;
 

	
 
@@ -304,15 +304,15 @@ int AiNew_Build_Vehicle(Player *p, TileI
 
		return AI_DoCommandCc(tile, i, 0, flag, CMD_BUILD_ROAD_VEH, CcAI);
 
	} else {
 
		return AI_DoCommand(tile, i, 0, flag, CMD_BUILD_ROAD_VEH);
 
	}
 
}
 

	
 
int AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag)
 
CommandCost AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag)
 
{
 
	int ret, ret2;
 
	CommandCost ret, ret2;
 
	if (p->ainew.tbt == AI_TRAIN) {
 
		return AI_DoCommand(tile, 0, direction, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_TRAIN_DEPOT);
 
	} else {
 
		ret = AI_DoCommand(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_DEPOT);
 
		if (CmdFailed(ret)) return ret;
 
		// Try to build the road from the depot
src/ai/trolly/pathfinder.cpp
Show inline comments
 
@@ -20,13 +20,13 @@
 
// TODO: make it train compatible
 
static bool TestCanBuildStationHere(TileIndex tile, byte dir)
 
{
 
	Player *p = GetPlayer(_current_player);
 

	
 
	if (dir == TEST_STATION_NO_DIR) {
 
		int32 ret;
 
		CommandCost ret;
 
		// TODO: currently we only allow spots that can be access from al 4 directions...
 
		//  should be fixed!!!
 
		for (dir = 0; dir < 4; dir++) {
 
			ret = AiNew_Build_Station(p, p->ainew.tbt, tile, 1, 1, dir, DC_QUERY_COST);
 
			if (!CmdFailed(ret)) return true;
 
		}
 
@@ -211,13 +211,13 @@ static void AyStar_AiPathFinder_FoundEnd
 
}
 

	
 

	
 
// What tiles are around us.
 
static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *current)
 
{
 
	int ret;
 
	CommandCost ret;
 
	int dir;
 

	
 
	Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
 

	
 
	aystar->num_neighbours = 0;
 

	
src/ai/trolly/trolly.cpp
Show inline comments
 
@@ -639,13 +639,13 @@ static void AiNew_State_FindStation(Play
 
		p->ainew.state = AI_STATE_NOTHING;
 
		return;
 
	}
 

	
 
	if (new_tile == 0 && p->ainew.tbt == AI_BUS) {
 
		uint x, y, i = 0;
 
		int r;
 
		CommandCost r;
 
		uint best;
 
		uint accepts[NUM_CARGO];
 
		TileIndex found_spot[AI_FINDSTATION_TILE_RANGE*AI_FINDSTATION_TILE_RANGE * 4];
 
		uint found_best[AI_FINDSTATION_TILE_RANGE*AI_FINDSTATION_TILE_RANGE * 4];
 
		// To find a good spot we scan a range from the center, a get the point
 
		//  where we get the most cargo and where it is buildable.
 
@@ -785,13 +785,14 @@ static void AiNew_State_FindDepot(Player
 
{
 
	// To place the depot, we walk through the route, and if we find a lovely spot (MP_CLEAR, MP_TREES), we place it there..
 
	// Simple, easy, works!
 
	// To make the depot stand in the middle of the route, we start from the center..
 
	// But first we walk through the route see if we can find a depot that is ours
 
	//  this keeps things nice ;)
 
	int g, i, r;
 
	int g, i;
 
	CommandCost r;
 
	DiagDirection j;
 
	TileIndex tile;
 
	assert(p->ainew.state == AI_STATE_FIND_DEPOT);
 

	
 
	p->ainew.depot_tile = 0;
 

	
 
@@ -981,13 +982,13 @@ static void AiNew_State_VerifyRoute(Play
 
}
 

	
 

	
 
// Build the stations
 
static void AiNew_State_BuildStation(Player *p)
 
{
 
	int res = 0;
 
	CommandCost res = 0;
 
	assert(p->ainew.state == AI_STATE_BUILD_STATION);
 
	if (p->ainew.temp == 0) {
 
		if (!IsTileType(p->ainew.from_tile, MP_STATION))
 
			res = AiNew_Build_Station(p, p->ainew.tbt, p->ainew.from_tile, 0, 0, p->ainew.from_direction, DC_EXEC);
 
	} else {
 
		if (!IsTileType(p->ainew.to_tile, MP_STATION))
 
@@ -1034,14 +1035,14 @@ static void AiNew_State_BuildPath(Player
 

	
 
		if (p->ainew.tbt == AI_TRUCK && !_patches.roadveh_queue) {
 
			// If they not queue, they have to go up and down to try again at a station...
 
			// We don't want that, so try building some road left or right of the station
 
			int dir1, dir2, dir3;
 
			TileIndex tile;
 
			int i, ret;
 
			for (i=0;i<2;i++) {
 
			CommandCost ret;
 
			for (int i = 0; i < 2; i++) {
 
				if (i == 0) {
 
					tile = p->ainew.from_tile + TileOffsByDiagDir(p->ainew.from_direction);
 
					dir1 = p->ainew.from_direction - 1;
 
					if (dir1 < 0) dir1 = 3;
 
					dir2 = p->ainew.from_direction + 1;
 
					if (dir2 > 3) dir2 = 0;
 
@@ -1099,13 +1100,13 @@ static void AiNew_State_BuildPath(Player
 
}
 

	
 

	
 
// Builds the depot
 
static void AiNew_State_BuildDepot(Player *p)
 
{
 
	int res = 0;
 
	CommandCost res = 0;
 
	assert(p->ainew.state == AI_STATE_BUILD_DEPOT);
 

	
 
	if (IsTileType(p->ainew.depot_tile, MP_STREET) && GetRoadTileType(p->ainew.depot_tile) == ROAD_TILE_DEPOT) {
 
		if (IsTileOwner(p->ainew.depot_tile, _current_player)) {
 
			// The depot is already built
 
			p->ainew.state = AI_STATE_BUILD_VEHICLE;
 
@@ -1134,13 +1135,13 @@ static void AiNew_State_BuildDepot(Playe
 
}
 

	
 

	
 
// Build vehicles
 
static void AiNew_State_BuildVehicle(Player *p)
 
{
 
	int res;
 
	CommandCost res;
 
	assert(p->ainew.state == AI_STATE_BUILD_VEHICLE);
 

	
 
	// Check if we need to build a vehicle
 
	if (p->ainew.amount_veh == 0) {
 
		// Nope, we are done!
 
		// This means: we are all done! The route is open.. go back to NOTHING
 
@@ -1274,13 +1275,13 @@ static void AiNew_CheckVehicle(Player *p
 
				}
 
				return;
 
			}
 

	
 
			if (!AiNew_SetSpecialVehicleFlag(p, v, AI_VEHICLEFLAG_SELL)) return;
 
			{
 
				int ret = 0;
 
				CommandCost ret = 0;
 
				if (v->type == VEH_ROAD)
 
					ret = AI_DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_ROADVEH_TO_DEPOT);
 
				// This means we can not find a depot :s
 
				//				if (CmdFailed(ret))
 
			}
 
		}
src/ai/trolly/trolly.h
Show inline comments
 
@@ -249,14 +249,14 @@ int AiNew_GetRoadDirection(TileIndex til
 
DiagDirection AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b);
 
bool AiNew_SetSpecialVehicleFlag(Player *p, Vehicle *v, uint flag);
 
uint AiNew_GetSpecialVehicleFlag(Player *p, Vehicle *v);
 

	
 
// ai_build.c
 
bool AiNew_Build_CompanyHQ(Player *p, TileIndex tile);
 
int AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag);
 
int AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag);
 
int AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag);
 
CommandCost AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag);
 
CommandCost AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag);
 
CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag);
 
EngineID AiNew_PickVehicle(Player *p);
 
int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag);
 
int AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag);
 
CommandCost AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag);
 
CommandCost AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag);
 

	
 
#endif /* AI_TROLLY_H */
src/aircraft_cmd.cpp
Show inline comments
 
@@ -224,13 +224,13 @@ void GetAircraftSpriteSize(EngineID engi
 
	const Sprite *spr = GetSprite(sprite);
 

	
 
	width  = spr->width ;
 
	height = spr->height;
 
}
 

	
 
static int32 EstimateAircraftCost(EngineID engine, const AircraftVehicleInfo *avi)
 
static CommandCost EstimateAircraftCost(EngineID engine, const AircraftVehicleInfo *avi)
 
{
 
	return GetEngineProperty(engine, 0x0B, avi->base_cost) * (_price.aircraft_base >> 3) >> 5;
 
}
 

	
 

	
 
/**
 
@@ -262,18 +262,18 @@ uint16 AircraftDefaultCargoCapacity(Carg
 
 * @param tile tile of depot where aircraft is built
 
 * @param flags for command
 
 * @param p1 aircraft type being built (engine)
 
 * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
 
 * return result of operation.  Could be cost, error
 
 */
 
int32 CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (!IsEngineBuildable(p1, VEH_AIRCRAFT, _current_player)) return_cmd_error(STR_AIRCRAFT_NOT_AVAILABLE);
 

	
 
	const AircraftVehicleInfo *avi = AircraftVehInfo(p1);
 
	int32 value = EstimateAircraftCost(p1, avi);
 
	CommandCost value = EstimateAircraftCost(p1, avi);
 

	
 
	/* to just query the cost, it is not neccessary to have a valid tile (automation/AI) */
 
	if (flags & DC_QUERY_COST) return value;
 

	
 
	if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR;
 

	
 
@@ -473,13 +473,13 @@ static void DoDeleteAircraft(Vehicle *v)
 
 * @param tile unused
 
 * @param flags for command type
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 * @return result of operation.  Error or sold value
 
 */
 
int32 CmdSellAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSellAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
 
@@ -500,13 +500,13 @@ int32 CmdSellAircraft(TileIndex tile, ui
 
 * @param tile unused
 
 * @param flags for command type
 
 * @param p1 aircraft ID to start/stop
 
 * @param p2 unused
 
 * @return result of operation.  Nothing if everything went well
 
 */
 
int32 CmdStartStopAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdStartStopAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
 
@@ -543,13 +543,13 @@ int32 CmdStartStopAircraft(TileIndex til
 
 * @param p1 vehicle ID to send to the hangar
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 * @return o if everything went well
 
 */
 
int32 CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (p2 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
 
		return SendAllVehiclesToDepot(VEH_AIRCRAFT, flags, p2 & DEPOT_SERVICE, _current_player, (p2 & VLW_MASK), p1);
 
	}
 
@@ -620,13 +620,13 @@ int32 CmdSendAircraftToHangar(TileIndex 
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle (ignored)
 
 * @return cost of refit or error
 
 */
 
int32 CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	byte new_subtype = GB(p2, 8, 8);
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 
@@ -665,13 +665,13 @@ int32 CmdRefitAircraft(TileIndex tile, u
 
		pass = AircraftDefaultCargoCapacity(new_cid, avi);
 
	} else {
 
		pass = callback;
 
	}
 
	_returned_refit_capacity = pass;
 

	
 
	int32 cost = 0;
 
	CommandCost cost = 0;
 
	if (IsHumanPlayer(v->owner) && new_cid != v->cargo_type) {
 
		cost = GetRefitCost(v->engine_type);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		v->cargo_cap = pass;
 
@@ -741,13 +741,13 @@ void OnNewDay_Aircraft(Vehicle *v)
 
	CheckVehicleBreakdown(v);
 
	AgeVehicle(v);
 
	CheckIfAircraftNeedsService(v);
 

	
 
	if (v->vehstatus & VS_STOPPED) return;
 

	
 
	int32 cost = GetVehicleProperty(v, 0x0E, AircraftVehInfo(v->engine_type)->running_cost) * _price.aircraft_running / 364;
 
	CommandCost cost = GetVehicleProperty(v, 0x0E, AircraftVehInfo(v->engine_type)->running_cost) * _price.aircraft_running / 364;
 

	
 
	v->profit_this_year -= cost >> 8;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN);
 
	SubtractMoneyFromPlayerFract(v->owner, cost);
 

	
 
@@ -1376,13 +1376,13 @@ static void ProcessAircraftOrder(Vehicle
 
		 *    example a depot. However, when we have a current order to
 
		 *    go to a depot, we have to keep that order so the aircraft
 
		 *    actually stops.
 
		 */
 
		const Station *st = GetStation(v->u.air.targetairport);
 
		if (!st->IsValid() || st->airport_tile == 0) {
 
			int32 ret;
 
			CommandCost ret;
 
			PlayerID old_player = _current_player;
 

	
 
			_current_player = v->owner;
 
			ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
 
			_current_player = old_player;
 

	
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -121,16 +121,16 @@ static CargoID GetNewCargoTypeForReplace
 
 * This function is only called from MaybeReplaceVehicle()
 
 * Must be called with _current_player set to the owner of the vehicle
 
 * @param w Vehicle to replace
 
 * @param flags is the flags to use when calling DoCommand(). Mainly DC_EXEC counts
 
 * @return value is cost of the replacement or CMD_ERROR
 
 */
 
static int32 ReplaceVehicle(Vehicle **w, byte flags, int32 total_cost)
 
static CommandCost ReplaceVehicle(Vehicle **w, byte flags, int32 total_cost)
 
{
 
	int32 cost;
 
	int32 sell_value;
 
	CommandCost cost;
 
	CommandCost sell_value;
 
	Vehicle *old_v = *w;
 
	const Player *p = GetPlayer(old_v->owner);
 
	EngineID new_engine_type;
 
	const UnitID cached_unitnumber = old_v->unitnumber;
 
	bool new_front = false;
 
	Vehicle *new_v = NULL;
 
@@ -170,13 +170,13 @@ static int32 ReplaceVehicle(Vehicle **w,
 
		SubtractMoneyFromPlayer(-sell_value); // Take back the money we just gave the player
 
		return cost;
 
	}
 

	
 
	if (replacement_cargo_type != CT_NO_REFIT) {
 
		/* add refit cost */
 
		int32 refit_cost = GetRefitCost(new_engine_type);
 
		CommandCost refit_cost = GetRefitCost(new_engine_type);
 
		if (old_v->type == VEH_TRAIN && IsMultiheaded(old_v)) refit_cost += refit_cost; // pay for both ends
 
		cost += refit_cost;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		new_v = GetVehicle(_new_vehicle_id);
 
@@ -243,13 +243,13 @@ static int32 ReplaceVehicle(Vehicle **w,
 
		if (!IsCustomName(old_v->string_id)) {
 
			vehicle_name[0] = '\0';
 
		} else {
 
			GetName(vehicle_name, old_v->string_id & 0x7FF, lastof(vehicle_name));
 
		}
 
	} else { // flags & DC_EXEC not set
 
		int32 tmp_move = 0;
 
		CommandCost tmp_move = 0;
 
		if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v) && old_v->next != NULL) {
 
			/* Verify that the wagons can be placed on the engine in question.
 
			 * This is done by building an engine, test if the wagons can be added and then sell the test engine. */
 
			DoCommand(old_v->tile, new_engine_type, 3, DC_EXEC, GetCmdBuildVeh(old_v));
 
			Vehicle *temp = GetVehicle(_new_vehicle_id);
 
			tmp_move = DoCommand(0, (temp->index << 16) | old_v->next->index, 1, 0, CMD_MOVE_RAIL_VEHICLE);
 
@@ -292,18 +292,18 @@ static int32 ReplaceVehicle(Vehicle **w,
 
 * @param v The vehicle to replace
 
 * if the vehicle is a train, v needs to be the front engine
 
 * @param check Checks if the replace is valid. No action is done at all
 
 * @param display_costs If set, a cost animation is shown (only if check is false)
 
 * @return CMD_ERROR if something went wrong. Otherwise the price of the replace
 
 */
 
int32 MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs)
 
CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs)
 
{
 
	Vehicle *w;
 
	const Player *p = GetPlayer(v->owner);
 
	byte flags = 0;
 
	int32 cost, temp_cost = 0;
 
	CommandCost cost, temp_cost = 0;
 
	bool stopped;
 

	
 
	/* Remember the length in case we need to trim train later on
 
	 * If it's not a train, the value is unused
 
	 * round up to the length of the tiles used for the train instead of the train length instead
 
	 * Useful when newGRF uses custom length */
src/bridge_gui.cpp
Show inline comments
 
@@ -110,13 +110,13 @@ static const WindowDesc _build_road_brid
 
};
 

	
 

	
 
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, byte bridge_type)
 
{
 
	uint j = 0;
 
	int32 ret;
 
	CommandCost ret;
 
	StringID errmsg;
 

	
 
	DeleteWindowById(WC_BUILD_BRIDGE, 0);
 

	
 
	_bridgedata.type = bridge_type;
 
	_bridgedata.start_tile = start;
src/clear_cmd.cpp
Show inline comments
 
@@ -33,13 +33,13 @@ struct TerraformerState {
 
	uint32 flags;
 

	
 
	int direction;
 
	int modheight_count;
 
	int tile_table_count;
 

	
 
	int32 cost;
 
	CommandCost cost;
 

	
 
	TileIndex *tile_table;
 
	TerraformerHeightMod *modheight;
 

	
 
};
 

	
 
@@ -94,13 +94,13 @@ static void TerraformAddDirtyTileAround(
 
	TerraformAddDirtyTile(ts, tile);
 
}
 

	
 
static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode)
 
{
 
	int r;
 
	int32 ret;
 
	CommandCost ret;
 

	
 
	assert(tile < MapSize());
 

	
 
	r = TerraformAllowTileProcess(ts, tile);
 
	if (r <= 0) return r;
 

	
 
@@ -229,13 +229,13 @@ static bool TerraformTileHeight(Terrafor
 
 * @param tile tile to terraform
 
 * @param flags for this command type
 
 * @param p1 corners to terraform.
 
 * @param p2 direction; eg up or down
 
 * @return error or cost of terraforming
 
 */
 
int32 CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TerraformerState ts;
 
	TileIndex t;
 
	int direction;
 

	
 
	TerraformerHeightMod modheight_data[576];
 
@@ -354,20 +354,22 @@ int32 CmdTerraformLand(TileIndex tile, u
 
 * @param tile end tile of area-drag
 
 * @param flags for this command type
 
 * @param p1 start tile of area drag
 
 * @param p2 unused
 
 * @return  error or cost of terraforming
 
 */
 
int32 CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int size_x, size_y;
 
	int ex;
 
	int ey;
 
	int sx, sy;
 
	uint h, curh;
 
	int32 ret, cost, money;
 
	int32 money;
 
	CommandCost ret;
 
	CommandCost cost;
 

	
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	/* remember level height */
 
@@ -415,15 +417,15 @@ int32 CmdLevelLand(TileIndex tile, uint3
 
 * @param tile the tile the player is purchasing
 
 * @param flags for this command type
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @return error of cost of operation
 
 */
 
int32 CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 cost;
 
	CommandCost cost;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
	if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) {
 
@@ -439,24 +441,24 @@ int32 CmdPurchaseLandArea(TileIndex tile
 
	}
 

	
 
	return cost + _price.purchase_land * 10;
 
}
 

	
 

	
 
static int32 ClearTile_Clear(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Clear(TileIndex tile, byte flags)
 
{
 
	static const int32* clear_price_table[] = {
 
		&_price.clear_1,
 
		&_price.purchase_land,
 
		&_price.clear_2,
 
		&_price.clear_3,
 
		&_price.purchase_land,
 
		&_price.purchase_land,
 
		&_price.clear_2, // XXX unused?
 
	};
 
	int32 price;
 
	CommandCost price;
 

	
 
	if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) == 0) {
 
		price = 0;
 
	} else {
 
		price = *clear_price_table[GetClearGround(tile)];
 
	}
 
@@ -471,13 +473,13 @@ static int32 ClearTile_Clear(TileIndex t
 
 * @param tile the tile the player is selling
 
 * @param flags for this command type
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @return error or cost of operation
 
 */
 
int32 CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	if (!IsOwnedLandTile(tile)) return CMD_ERROR;
 
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
 

	
src/command.cpp
Show inline comments
 
@@ -14,13 +14,13 @@
 
#include "network/network.h"
 
#include "variables.h"
 
#include "genworld.h"
 

	
 
const char* _cmd_text = NULL;
 

	
 
#define DEF_COMMAND(yyyy) int32 yyyy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
#define DEF_COMMAND(yyyy) CommandCost yyyy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 

	
 
DEF_COMMAND(CmdBuildRailroadTrack);
 
DEF_COMMAND(CmdRemoveRailroadTrack);
 
DEF_COMMAND(CmdBuildSingleRail);
 
DEF_COMMAND(CmdRemoveSingleRail);
 

	
 
@@ -348,15 +348,15 @@ byte GetCommandFlags(uint cmd)
 
	return _command_proc_table[cmd & 0xFF].flags;
 
}
 

	
 

	
 
static int _docommand_recursive;
 

	
 
int32 DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
 
{
 
	int32 res;
 
	CommandCost res;
 
	CommandProc *proc;
 

	
 
	/* Do not even think about executing out-of-bounds tile-commands */
 
	if (tile >= MapSize() || IsTileType(tile, MP_VOID)) {
 
		_cmd_text = NULL;
 
		return CMD_ERROR;
 
@@ -422,13 +422,13 @@ int32 GetAvailableMoneyForCommand()
 
}
 

	
 
/* toplevel network safe docommand function for the current player. must not be called recursively.
 
 * the callback is called when the command succeeded or failed. */
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd)
 
{
 
	int32 res = 0, res2;
 
	CommandCost res = 0, res2;
 
	CommandProc *proc;
 
	uint32 flags;
 
	bool notest;
 
	StringID error_part1;
 

	
 
	int x = TileX(tile) * TILE_SIZE;
src/command.h
Show inline comments
 
@@ -181,13 +181,13 @@ enum {
 
/** Command flags for the command table _command_proc_table */
 
enum {
 
	CMD_SERVER  = 0x1, ///< the command can only be initiated by the server
 
	CMD_OFFLINE = 0x2, ///< the command cannot be executed in a multiplayer game; single-player only
 
};
 

	
 
typedef int32 CommandProc(TileIndex tile, uint32 flags, uint32 p1, uint32 p2);
 
typedef CommandCost CommandProc(TileIndex tile, uint32 flags, uint32 p1, uint32 p2);
 

	
 
struct Command {
 
	CommandProc *proc;
 
	byte flags;
 
};
 

	
 
@@ -196,21 +196,21 @@ struct Command {
 

	
 
/**
 
 * Check the return value of a DoCommand*() function
 
 * @param res the resulting value from the command to be checked
 
 * @return Return true if the command failed, false otherwise
 
 */
 
static inline bool CmdFailed(int32 res)
 
static inline bool CmdFailed(CommandCost res)
 
{
 
	/* lower 16bits are the StringID of the possible error */
 
	return res <= (CMD_ERROR | INVALID_STRING_ID);
 
}
 

	
 
/* command.cpp */
 
typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
int32 DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd);
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback);
 
#endif /* ENABLE_NETWORK */
src/dummy_land.cpp
Show inline comments
 
@@ -23,13 +23,13 @@ static uint GetSlopeZ_Dummy(TileIndex ti
 

	
 
static Slope GetSlopeTileh_Dummy(TileIndex tile, Slope tileh)
 
{
 
	return SLOPE_FLAT;
 
}
 

	
 
static int32 ClearTile_Dummy(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Dummy(TileIndex tile, byte flags)
 
{
 
	return_cmd_error(STR_0001_OFF_EDGE_OF_MAP);
 
}
 

	
 

	
 
static void GetAcceptedCargo_Dummy(TileIndex tile, AcceptedCargo ac)
src/economy.cpp
Show inline comments
 
@@ -256,13 +256,13 @@ void ChangeOwnershipOfPlayerItems(Player
 
		/* See if the old_player had shares in other companies */
 
		_current_player = old_player;
 
		FOR_ALL_PLAYERS(p) {
 
			for (i = 0; i < 4; i++) {
 
				if (p->share_owners[i] == old_player) {
 
					/* Sell his shares */
 
					int32 res = DoCommand(0, p->index, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
 
					CommandCost res = DoCommand(0, p->index, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
 
					/* Because we are in a DoCommand, we can't just execute an other one and
 
					 *  expect the money to be removed. We need to do it ourself! */
 
					SubtractMoneyFromPlayer(res);
 
				}
 
			}
 
		}
 
@@ -270,13 +270,13 @@ void ChangeOwnershipOfPlayerItems(Player
 
		/* Sell all the shares that people have on this company */
 
		p = GetPlayer(old_player);
 
		for (i = 0; i < 4; i++) {
 
			_current_player = p->share_owners[i];
 
			if (_current_player != PLAYER_SPECTATOR) {
 
				/* Sell the shares */
 
				int32 res = DoCommand(0, old_player, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
 
				CommandCost res = DoCommand(0, old_player, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
 
				/* Because we are in a DoCommand, we can't just execute an other one and
 
				 *  expect the money to be removed. We need to do it ourself! */
 
				SubtractMoneyFromPlayer(res);
 
			}
 
		}
 
	}
 
@@ -1805,16 +1805,16 @@ extern int GetAmountOwnedBy(const Player
 
/** Acquire shares in an opposing company.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 player to buy the shares from
 
 * @param p2 unused
 
 */
 
int32 CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Player *p;
 
	int64 cost;
 
	CommandCost cost;
 

	
 
	/* Check if buying shares is allowed (protection against modified clients */
 
	if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares) return CMD_ERROR;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
 
	p = GetPlayer((PlayerID)p1);
 
@@ -1851,13 +1851,13 @@ int32 CmdBuyShareInCompany(TileIndex til
 
/** Sell shares in an opposing company.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 player to sell the shares from
 
 * @param p2 unused
 
 */
 
int32 CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Player *p;
 
	int64 cost;
 

	
 
	/* Check if buying shares is allowed (protection against modified clients */
 
	if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares) return CMD_ERROR;
 
@@ -1887,13 +1887,13 @@ int32 CmdSellShareInCompany(TileIndex ti
 
 * @todo currently this only works for AI players
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 player/company to buy up
 
 * @param p2 unused
 
 */
 
int32 CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Player *p;
 
	PlayerID pid = (PlayerID)p1;
 

	
 
	/* Disable takeovers in multiplayer games */
 
	if (!IsValidPlayer(pid) || _networking) return CMD_ERROR;
src/engine.cpp
Show inline comments
 
@@ -263,13 +263,13 @@ void EnginesDailyLoop()
 
 * changes while you are waiting to accept the offer? Then it becomes invalid
 
 * @param tile unused
 
 * @param flags operation to perfom
 
 * @param p1 engine-prototype offered
 
 * @param p2 unused
 
 */
 
int32 CmdWantEnginePreview(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdWantEnginePreview(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Engine *e;
 

	
 
	if (!IsEngineIndex(p1)) return CMD_ERROR;
 
	e = GetEngine(p1);
 
	if (GetBestPlayer(e->preview_player) != _current_player) return CMD_ERROR;
 
@@ -371,13 +371,13 @@ void EnginesMonthlyLoop()
 
/** Rename an engine.
 
 * @param tile unused
 
 * @param flags operation to perfom
 
 * @param p1 engine ID to rename
 
 * @param p2 unused
 
 */
 
int32 CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	StringID str;
 

	
 
	if (!IsEngineIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
 

	
 
	str = AllocateNameUnique(_cmd_text, 0);
 
@@ -530,13 +530,13 @@ void RemoveAllEngineReplacement(EngineRe
 
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group)
 
{
 
	const EngineRenew *er = GetEngineReplacement(erl, engine, group);
 
	return er == NULL ? INVALID_ENGINE : er->to;
 
}
 

	
 
int32 AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags)
 
CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags)
 
{
 
	EngineRenew *er;
 

	
 
	/* Check if the old vehicle is already in the list */
 
	er = GetEngineReplacement(*erl, old_engine, group);
 
	if (er != NULL) {
 
@@ -557,13 +557,13 @@ int32 AddEngineReplacement(EngineRenewLi
 
		*erl = (EngineRenewList)er;
 
	}
 

	
 
	return 0;
 
}
 

	
 
int32 RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags)
 
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags)
 
{
 
	EngineRenew *er = (EngineRenew *)(*erl);
 
	EngineRenew *prev = NULL;
 

	
 
	while (er)
 
	{
src/engine.h
Show inline comments
 
@@ -325,22 +325,22 @@ EngineID EngineReplacement(EngineRenewLi
 
 * @param erl The renewlist to add to.
 
 * @param old_engine The original engine type.
 
 * @param new_engine The replacement engine type.
 
 * @param flags The calling command flags.
 
 * @return 0 on success, CMD_ERROR on failure.
 
 */
 
int32 AddEngineReplacement(EngineRenewList* erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags);
 
CommandCost AddEngineReplacement(EngineRenewList* erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags);
 

	
 
/**
 
 * Remove an engine replacement from a given renewlist.
 
 * @param erl The renewlist from which to remove the replacement
 
 * @param engine The original engine type.
 
 * @param flags The calling command flags.
 
 * @return 0 on success, CMD_ERROR on failure.
 
 */
 
int32 RemoveEngineReplacement(EngineRenewList* erl, EngineID engine, GroupID group, uint32 flags);
 
CommandCost RemoveEngineReplacement(EngineRenewList* erl, EngineID engine, GroupID group, uint32 flags);
 

	
 
/** When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
 
 * @param type The type of engine
 
 */
 
void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type);
 

	
src/functions.h
Show inline comments
 
@@ -17,15 +17,15 @@ void TileLoopClearHelper(TileIndex tile)
 

	
 
/* water_land.cpp */
 
void DrawShipDepotSprite(int x, int y, int image);
 
void TileLoop_Water(TileIndex tile);
 

	
 
/* players.cpp */
 
bool CheckPlayerHasMoney(int32 cost);
 
void SubtractMoneyFromPlayer(int32 cost);
 
void SubtractMoneyFromPlayerFract(PlayerID player, int32 cost);
 
bool CheckPlayerHasMoney(CommandCost cost);
 
void SubtractMoneyFromPlayer(CommandCost cost);
 
void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cost);
 
bool CheckOwnership(Owner owner);
 
bool CheckTileOwnership(TileIndex tile);
 
StringID GetPlayerNameString(PlayerID player, uint index);
 

	
 
/* standard */
 
void ShowInfo(const char *str);
src/group_cmd.cpp
Show inline comments
 
@@ -90,13 +90,13 @@ static WindowClass GetWCForVT(VehicleTyp
 
/**
 
 * Add a vehicle to a group
 
 * @param tile unused
 
 * @param p1   vehicle type
 
 * @param p2   unused
 
 */
 
int32 CmdCreateGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdCreateGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	VehicleType vt = (VehicleType)p1;
 
	if (!IsPlayerBuildableVehicleType(vt)) return CMD_ERROR;
 

	
 
	Group *g = AllocateGroup();
 
	if (g == NULL) return CMD_ERROR;
 
@@ -118,13 +118,13 @@ int32 CmdCreateGroup(TileIndex tile, uin
 
 * Add a vehicle to a group
 
 * @param tile unused
 
 * @param p1   index of array group
 
 *      - p1 bit 0-15 : GroupID
 
 * @param p2   unused
 
 */
 
int32 CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (!IsValidGroupID(p1)) return CMD_ERROR;
 

	
 
	Group *g = GetGroup(p1);
 
	if (g->owner != _current_player) return CMD_ERROR;
 

	
 
@@ -164,13 +164,13 @@ int32 CmdDeleteGroup(TileIndex tile, uin
 
 * Rename a group
 
 * @param tile unused
 
 * @param p1   index of array group
 
 *   - p1 bit 0-15 : GroupID
 
 * @param p2   unused
 
 */
 
int32 CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (!IsValidGroupID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR;
 

	
 
	Group *g = GetGroup(p1);
 
	if (g->owner != _current_player) return CMD_ERROR;
 

	
 
@@ -196,13 +196,13 @@ int32 CmdRenameGroup(TileIndex tile, uin
 
 * @param tile unused
 
 * @param p1   index of array group
 
 *   - p1 bit 0-15 : GroupID
 
 * @param p2   vehicle to add to a group
 
 *   - p2 bit 0-15 : VehicleID
 
 */
 
int32 CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	GroupID new_g = p1;
 

	
 
	if (!IsValidVehicleID(p2) || (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
 

	
 
	if (IsValidGroupID(new_g)) {
 
@@ -242,13 +242,13 @@ int32 CmdAddVehicleGroup(TileIndex tile,
 
 * Add all shared vehicles of all vehicles from a group
 
 * @param tile unused
 
 * @param p1   index of group array
 
 *  - p1 bit 0-15 : GroupID
 
 * @param p2   type of vehicles
 
 */
 
int32 CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	VehicleType type = (VehicleType)p2;
 
	if (!IsValidGroupID(p1) || !IsPlayerBuildableVehicleType(type)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Vehicle *v;
 
@@ -279,13 +279,13 @@ int32 CmdAddSharedVehicleGroup(TileIndex
 
 * Remove all vehicles from a group
 
 * @param tile unused
 
 * @param p1   index of group array
 
 * - p1 bit 0-15 : GroupID
 
 * @param p2   type of vehicles
 
 */
 
int32 CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	VehicleType type = (VehicleType)p2;
 
	if (!IsValidGroupID(p1) || !IsPlayerBuildableVehicleType(type)) return CMD_ERROR;
 

	
 
	Group *g = GetGroup(p1);
 
	if (g->owner != _current_player) return CMD_ERROR;
 
@@ -316,13 +316,13 @@ int32 CmdRemoveAllVehiclesGroup(TileInde
 
 * @param tile unused
 
 * @param p1   index of group array
 
 * - p1 bit 0-15 : GroupID
 
 * @param p2
 
 * - p2 bit 0    : 1 to set or 0 to clear protection.
 
 */
 
int32 CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (!IsValidGroupID(p1)) return CMD_ERROR;
 

	
 
	Group *g = GetGroup(p1);
 
	if (g->owner != _current_player) return CMD_ERROR;
 

	
src/industry_cmd.cpp
Show inline comments
 
@@ -333,13 +333,13 @@ static void GetTileDesc_Industry(TileInd
 
	if (!IsIndustryCompleted(tile)) {
 
		SetDParamX(td->dparam, 0, td->str);
 
		td->str = STR_2058_UNDER_CONSTRUCTION;
 
	}
 
}
 

	
 
static int32 ClearTile_Industry(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Industry(TileIndex tile, byte flags)
 
{
 
	Industry *i = GetIndustryByTile(tile);
 
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
 

	
 
	/* water can destroy industries
 
	 * in editor you can bulldoze industries
 
@@ -1466,13 +1466,13 @@ static Industry *CreateNewIndustryHelper
 
 * @param tile tile where industry is built
 
 * @param flags of operations to conduct
 
 * @param p1 industry type see build_industry.h and see industry.h
 
 * @param p2 unused
 
 * @return index of the newly create industry, or CMD_ERROR if it failed
 
 */
 
int32 CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int num;
 
	const IndustryTileTable * const *itt;
 
	const IndustryTileTable *it;
 
	const IndustrySpec *indspec;
 

	
src/landscape.cpp
Show inline comments
 
@@ -364,28 +364,28 @@ void ClearSnowLine(void)
 
/** Clear a piece of landscape
 
 * @param tile tile to clear
 
 * @param flags of operation to conduct
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
int32 CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
 
}
 

	
 
/** Clear a big piece of landscape
 
 * @param tile end tile of area dragging
 
 * @param p1 start tile of area dragging
 
 * @param flags of operation to conduct
 
 * @param p2 unused
 
 */
 
int32 CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 cost, ret, money;
 
	CommandCost cost, ret, money;
 
	int ex;
 
	int ey;
 
	int sx, sy;
 
	int x, y;
 
	bool success = false;
 

	
src/misc_cmd.cpp
Show inline comments
 
@@ -21,13 +21,13 @@
 
/** Change the player's face.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 face bitmasked
 
 */
 
int32 CmdSetPlayerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSetPlayerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	PlayerFace pf = (PlayerFace)p2;
 

	
 
	if (!IsValidPlayerFace(pf)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
@@ -42,13 +42,13 @@ int32 CmdSetPlayerFace(TileIndex tile, u
 
 * @param flags operation to perform
 
 * @param p1 bitstuffed:
 
 * p1 bits 0-7 scheme to set
 
 * p1 bits 8-9 set in use state or first/second colour
 
 * @param p2 new colour for vehicles, property, etc.
 
 */
 
int32 CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Player *p, *pp;
 
	byte colour;
 
	LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
 
	byte state = GB(p1, 8, 2);
 

	
 
@@ -121,13 +121,13 @@ int32 CmdSetPlayerColor(TileIndex tile, 
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 when 0: loans LOAN_INTERVAL
 
 *           when 1: loans the maximum loan permitting money (press CTRL),
 
 */
 
int32 CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Player *p = GetPlayer(_current_player);
 

	
 
	if (p->current_loan >= _economy.max_loan) {
 
		SetDParam(0, _economy.max_loan);
 
		return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN);
 
@@ -158,13 +158,13 @@ int32 CmdIncreaseLoan(TileIndex tile, ui
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 when 0: pays back LOAN_INTERVAL
 
 *           when 1: pays back the maximum loan permitting money (press CTRL),
 
 */
 
int32 CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Player *p = GetPlayer(_current_player);
 

	
 
	if (p->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED);
 

	
 
	int32 loan;
 
@@ -196,13 +196,13 @@ int32 CmdDecreaseLoan(TileIndex tile, ui
 
/** Change the name of the company.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
int32 CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	StringID str;
 
	Player *p;
 

	
 
	if (_cmd_text[0] == '\0') return CMD_ERROR;
 

	
 
@@ -224,13 +224,13 @@ int32 CmdChangeCompanyName(TileIndex til
 
/** Change the name of the president.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
int32 CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	StringID str;
 
	Player *p;
 

	
 
	if (_cmd_text[0] == '\0') return CMD_ERROR;
 

	
 
@@ -263,13 +263,13 @@ int32 CmdChangePresidentName(TileIndex t
 
 * to have more control over the game when saving/loading, etc.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 0 = decrease pause counter; 1 = increase pause counter
 
 * @param p2 unused
 
 */
 
int32 CmdPause(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdPause(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (flags & DC_EXEC) {
 
		_pause_game += (p1 == 1) ? 1 : -1;
 
		if (_pause_game == (byte)-1) _pause_game = 0;
 
		InvalidateWindow(WC_STATUS_BAR, 0);
 
		InvalidateWindow(WC_MAIN_TOOLBAR, 0);
 
@@ -282,13 +282,13 @@ int32 CmdPause(TileIndex tile, uint32 fl
 
 * build, you can cheat (to test).
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the amount of money to receive (if negative), or spend (if positive)
 
 * @param p2 unused
 
 */
 
int32 CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
#ifndef _DEBUG
 
	if (_networking) return CMD_ERROR;
 
#endif
 
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
 
	return -(int32)p1;
 
@@ -300,16 +300,16 @@ int32 CmdMoneyCheat(TileIndex tile, uint
 
 * given the fact that you have more money than loan).
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the amount of money to transfer; max 20.000.000
 
 * @param p2 the player to transfer the money to
 
 */
 
int32 CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	const Player *p = GetPlayer(_current_player);
 
	int32 amount = min((int32)p1, 20000000);
 
	CommandCost amount = min((int32)p1, 20000000);
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
 

	
 
	/* You can only transfer funds that is in excess of your loan */
 
	if (p->money64 - p->current_loan < amount || amount <= 0) return CMD_ERROR;
 
	if (!_networking || !IsValidPlayer((PlayerID)p2)) return CMD_ERROR;
 
@@ -333,13 +333,13 @@ int32 CmdGiveMoney(TileIndex tile, uint3
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the difficulty setting being changed. If it is -1, the difficulty level
 
 *           itself is changed. The new value is inside p2
 
 * @param p2 new value for a difficulty setting or difficulty level
 
 */
 
int32 CmdChangeDifficultyLevel(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdChangeDifficultyLevel(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (p1 != (uint32)-1L && ((int32)p1 >= GAME_DIFFICULTY_NUM || (int32)p1 < 0)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		if (p1 != (uint32)-1L) {
 
			((int*)&_opt_ptr->diff)[p1] = p2;
src/openttd.h
Show inline comments
 
@@ -64,12 +64,13 @@ typedef uint16 DepotID;
 
typedef uint16 WaypointID;
 
typedef uint16 OrderID;
 
typedef uint16 SignID;
 
typedef uint16 GroupID;
 
typedef uint16 EngineRenewID;
 
typedef uint16 DestinationID;
 
typedef int32 CommandCost;
 

	
 
/* DestinationID must be at least as large as every these below, because it can
 
 * be any of them
 
 */
 
assert_compile(sizeof(DestinationID) == sizeof(DepotID));
 
assert_compile(sizeof(DestinationID) == sizeof(WaypointID));
src/order_cmd.cpp
Show inline comments
 
@@ -187,13 +187,13 @@ static TileIndex GetOrderLocation(const 
 
 * - p1 = (bit  0 - 15) - ID of the vehicle
 
 * - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
 
 *                        the order will be inserted before that one
 
 *                        only the first 8 bits used currently (bit 16 - 23) (max 255)
 
 * @param p2 packed order to insert
 
 */
 
int32 CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	VehicleID veh   = GB(p1,  0, 16);
 
	VehicleOrderID sel_ord = GB(p1, 16, 16);
 
	Order new_order = UnpackOrder(p2);
 

	
 
@@ -445,13 +445,13 @@ int32 CmdInsertOrder(TileIndex tile, uin
 
}
 

	
 
/** Declone an order-list
 
 * @param *dst delete the orders of this vehicle
 
 * @param flags execution flags
 
 */
 
static int32 DecloneOrder(Vehicle *dst, uint32 flags)
 
static CommandCost DecloneOrder(Vehicle *dst, uint32 flags)
 
{
 
	if (flags & DC_EXEC) {
 
		DeleteVehicleOrders(dst);
 
		InvalidateVehicleOrder(dst);
 
		RebuildVehicleLists();
 
	}
 
@@ -480,13 +480,13 @@ static void RemoveSharedOrderVehicleList
 
/** Delete an order from the orderlist of a vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the ID of the vehicle
 
 * @param p2 the order to delete (max 255)
 
 */
 
int32 CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v, *u;
 
	VehicleID veh_id = p1;
 
	VehicleOrderID sel_ord = p2;
 
	Order *order;
 

	
 
@@ -560,13 +560,13 @@ int32 CmdDeleteOrder(TileIndex tile, uin
 
/** Goto order of order-list.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 The ID of the vehicle which order is skipped
 
 * @param p2 the selected order to which we want to skip
 
 */
 
int32 CmdSkipToOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSkipToOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	VehicleID veh_id = p1;
 
	VehicleOrderID sel_ord = p2;
 

	
 
	if (!IsValidVehicleID(veh_id)) return CMD_ERROR;
 
@@ -605,13 +605,13 @@ int32 CmdSkipToOrder(TileIndex tile, uin
 
 * @param p2 order to move and target
 
 *           bit 0-15  : the order to move
 
 *           bit 16-31 : the target order
 
 * @note The target order will move one place down in the orderlist
 
 *  if you move the order upwards else it'll move it one place down
 
 */
 
int32 CmdMoveOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdMoveOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	VehicleID veh = p1;
 
	VehicleOrderID moving_order = GB(p2,  0, 16);
 
	VehicleOrderID target_order = GB(p2, 16, 16);
 

	
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 
@@ -691,13 +691,13 @@ int32 CmdMoveOrder(TileIndex tile, uint3
 
 * - p1 = (bit  0 - 15) - ID of the vehicle
 
 * - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
 
 *                        the order will be inserted before that one
 
 *                        only the first 8 bits used currently (bit 16 - 23) (max 255)
 
 * @param p2 mode to change the order to (always set)
 
 */
 
int32 CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	Order *order;
 
	VehicleOrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
 
	VehicleID veh   = GB(p1,  0, 16);
 

	
 
@@ -771,13 +771,13 @@ int32 CmdModifyOrder(TileIndex tile, uin
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0-15) - destination vehicle to clone orders to (p1 & 0xFFFF)
 
 * - p1 = (bit 16-31) - source vehicle to clone orders from, if any (none for CO_UNSHARE)
 
 * @param p2 mode of cloning: CO_SHARE, CO_COPY, or CO_UNSHARE
 
 */
 
int32 CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *dst;
 
	VehicleID veh_src = GB(p1, 16, 16);
 
	VehicleID veh_dst = GB(p1,  0, 16);
 

	
 
	if (!IsValidVehicleID(veh_dst)) return CMD_ERROR;
 
@@ -905,13 +905,13 @@ int32 CmdCloneOrder(TileIndex tile, uint
 
 * @param p1 VehicleIndex of the vehicle having the order
 
 * @param p2 bitmask
 
 *   - bit 0-7 CargoID
 
 *   - bit 8-15 Cargo subtype
 
 *   - bit 16-23 number of order to modify
 
 */
 
int32 CmdOrderRefit(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdOrderRefit(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	const Vehicle *v;
 
	Order *order;
 
	VehicleID veh = GB(p1, 0, 16);
 
	VehicleOrderID order_number  = GB(p2, 16, 8);
 
	CargoID cargo = GB(p2, 0, 8);
 
@@ -1036,13 +1036,13 @@ void RestoreVehicleOrders(const Vehicle*
 
 * as far as I can see. We can store it in BackuppedOrders, and restore it, but
 
 * but we have no way of seeing it has been tampered with or not, as we have no
 
 * legit way of knowing what that ID was.@n
 
 * If we do want to backup/restore it, just add UnitID uid to BackuppedOrders, and
 
 * restore it as parameter 'y' (ugly hack I know) for example. "v->unitnumber = y;"
 
 */
 
int32 CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	VehicleOrderID cur_ord = GB(p2,  0, 16);
 
	uint16 serv_int = GB(p2, 16, 16);
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
src/player.h
Show inline comments
 
@@ -334,22 +334,22 @@ static inline bool EngineHasReplacementF
 
 * @param p Player.
 
 * @param old_engine The original engine type.
 
 * @param new_engine The replacement engine type.
 
 * @param flags The calling command flags.
 
 * @return 0 on success, CMD_ERROR on failure.
 
 */
 
static inline int32 AddEngineReplacementForPlayer(Player *p, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags) { return AddEngineReplacement(&p->engine_renew_list, old_engine, new_engine, group, flags); }
 
static inline CommandCost AddEngineReplacementForPlayer(Player *p, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags) { return AddEngineReplacement(&p->engine_renew_list, old_engine, new_engine, group, flags); }
 

	
 
/**
 
 * Remove an engine replacement for the player.
 
 * @param p Player.
 
 * @param engine The original engine type.
 
 * @param flags The calling command flags.
 
 * @return 0 on success, CMD_ERROR on failure.
 
 */
 
static inline int32 RemoveEngineReplacementForPlayer(Player *p, EngineID engine, GroupID group, uint32 flags) {return RemoveEngineReplacement(&p->engine_renew_list, engine, group, flags); }
 
static inline CommandCost RemoveEngineReplacementForPlayer(Player *p, EngineID engine, GroupID group, uint32 flags) {return RemoveEngineReplacement(&p->engine_renew_list, engine, group, flags); }
 

	
 
/**
 
 * Reset the livery schemes to the player's primary colour.
 
 * This is used on loading games without livery information and on new player start up.
 
 * @param p Player to reset.
 
 */
src/players.cpp
Show inline comments
 
@@ -170,26 +170,26 @@ void InvalidatePlayerWindows(const Playe
 
	PlayerID pid = p->index;
 

	
 
	if (pid == _local_player) InvalidateWindow(WC_STATUS_BAR, 0);
 
	InvalidateWindow(WC_FINANCES, pid);
 
}
 

	
 
bool CheckPlayerHasMoney(int32 cost)
 
bool CheckPlayerHasMoney(CommandCost cost)
 
{
 
	if (cost > 0) {
 
		PlayerID pid = _current_player;
 
		if (IsValidPlayer(pid) && cost > GetPlayer(pid)->player_money) {
 
			SetDParam(0, cost);
 
			_error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES;
 
			return false;
 
		}
 
	}
 
	return true;
 
}
 

	
 
static void SubtractMoneyFromAnyPlayer(Player *p, int32 cost)
 
static void SubtractMoneyFromAnyPlayer(Player *p, CommandCost cost)
 
{
 
	p->money64 -= cost;
 
	UpdatePlayerMoney32(p);
 

	
 
	p->yearly_expenses[0][_yearly_expenses_type] += cost;
 

	
 
@@ -207,20 +207,20 @@ static void SubtractMoneyFromAnyPlayer(P
 
		p->cur_economy.expenses -= cost;
 
	}
 

	
 
	InvalidatePlayerWindows(p);
 
}
 

	
 
void SubtractMoneyFromPlayer(int32 cost)
 
void SubtractMoneyFromPlayer(CommandCost cost)
 
{
 
	PlayerID pid = _current_player;
 

	
 
	if (IsValidPlayer(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
 
}
 

	
 
void SubtractMoneyFromPlayerFract(PlayerID player, int32 cost)
 
void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cost)
 
{
 
	Player *p = GetPlayer(player);
 
	byte m = p->player_money_fraction;
 

	
 
	p->player_money_fraction = m - (byte)cost;
 
	cost >>= 8;
 
@@ -673,13 +673,13 @@ static void DeletePlayerStuff(PlayerID p
 
 * - p1 bit     15 = enable engine renewal
 
 * - p1 bits 16-31 = months left before engine expires to replace it
 
 * - p2 bits  0-31 = minimum amount of money available
 
 * if p1 = 5, then
 
 * - p2 = enable renew_keep_length
 
 */
 
int32 CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Player *p;
 
	if (!IsValidPlayer(_current_player)) return CMD_ERROR;
 

	
 
	p = GetPlayer(_current_player);
 
	switch (GB(p1, 0, 3)) {
 
@@ -720,13 +720,13 @@ int32 CmdSetAutoReplace(TileIndex tile, 
 
			}
 
			break;
 
		case 3: {
 
			EngineID old_engine_type = GB(p2, 0, 16);
 
			EngineID new_engine_type = GB(p2, 16, 16);
 
			GroupID id_g = GB(p1, 16, 16);
 
			int32 cost;
 
			CommandCost cost;
 

	
 
			if (!IsValidGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR;
 
			if (new_engine_type != INVALID_ENGINE) {
 
				/* First we make sure that it's a valid type the user requested
 
				 * check that it's an engine that is in the engine array */
 
				if (!IsEngineIndex(new_engine_type))
 
@@ -802,13 +802,13 @@ int32 CmdSetAutoReplace(TileIndex tile, 
 
 * p2. This parameter is passed in at function DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
 
 * on the server itself. First of all this is unbelievably ugly; second of all, well,
 
 * it IS ugly! <b>Someone fix this up :)</b> So where to fix?@n
 
 * @arg - network_server.c:838 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)@n
 
 * @arg - network_client.c:536 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) from where the map has been received
 
 */
 
int32 CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (flags & DC_EXEC) _current_player = OWNER_NONE;
 

	
 
	switch (p1) {
 
	case 0: { /* Create a new player */
 
		/* Joining Client:
src/rail_cmd.cpp
Show inline comments
 
@@ -186,13 +186,13 @@ uint GetRailFoundation(Slope tileh, Trac
 
		default: return 0;
 
	}
 
	return i + 15;
 
}
 

	
 

	
 
static uint32 CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
 
static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
 
{
 
	if (IsSteepSlope(tileh)) {
 
		if (_patches.build_on_slopes && existing == 0) {
 
			TrackBits valid = TRACK_BIT_CROSS | (HASBIT(1 << SLOPE_STEEP_W | 1 << SLOPE_STEEP_E, tileh) ? TRACK_BIT_VERT : TRACK_BIT_HORZ);
 
			if (valid & rail_bits) return _price.terraform;
 
		}
 
@@ -228,20 +228,20 @@ static inline bool ValParamTrackOrientat
 
/** Build a single piece of rail
 
 * @param tile tile  to build on
 
 * @param flags operation to perform
 
 * @param p1 railtype of being built piece (normal, mono, maglev)
 
 * @param p2 rail track to build
 
 */
 
int32 CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Slope tileh;
 
	RailType railtype;
 
	Track track;
 
	TrackBits trackbit;
 
	int32 cost = 0;
 
	int32 ret;
 
	CommandCost cost = 0;
 
	CommandCost ret;
 

	
 
	if (!ValParamRailtype(p1) || !ValParamTrackOrientation((Track)p2)) return CMD_ERROR;
 
	railtype = (RailType)p1;
 
	track = (Track)p2;
 

	
 
	tileh = GetTileSlope(tile, NULL);
 
@@ -352,17 +352,17 @@ int32 CmdBuildSingleRail(TileIndex tile,
 
/** Remove a single piece of track
 
 * @param tile tile to remove track from
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 rail orientation
 
 */
 
int32 CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Track track = (Track)p2;
 
	TrackBits trackbit;
 
	int32 cost = _price.remove_rail;
 
	CommandCost cost = _price.remove_rail;
 
	bool crossing = false;
 

	
 
	if (!ValParamTrackOrientation((Track)p2)) return CMD_ERROR;
 
	trackbit = TrackToTrackBits(track);
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
@@ -441,13 +441,13 @@ static const TileIndexDiffC _trackdelta[
 
	{  1,  0 }, {  0, -1 }, {  0, -1 }, {  1,  0 }, {  0, -1 }, { -1,  0 },
 
	{  0,  0 },
 
	{  0,  0 }
 
};
 

	
 

	
 
static int32 ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileIndex end)
 
static CommandCost ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileIndex end)
 
{
 
	int x = TileX(start);
 
	int y = TileY(start);
 
	int ex = TileX(end);
 
	int ey = TileY(end);
 
	int dx, dy, trdx, trdy;
 
@@ -501,15 +501,15 @@ static int32 ValidateAutoDrag(Trackdir *
 
 * @param p1 end tile of drag
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
 
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
 
 */
 
static int32 CmdRailTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
static CommandCost CmdRailTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 ret, total_cost = 0;
 
	CommandCost ret, total_cost = 0;
 
	Track track = (Track)GB(p2, 4, 3);
 
	Trackdir trackdir;
 
	byte mode = HASBIT(p2, 7);
 
	RailType railtype = (RailType)GB(p2, 0, 4);
 
	TileIndex end_tile;
 

	
 
@@ -553,13 +553,13 @@ static int32 CmdRailTrackHelper(TileInde
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
 
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
 
 * @see CmdRailTrackHelper
 
 */
 
int32 CmdBuildRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	return CmdRailTrackHelper(tile, flags, p1, CLRBIT(p2, 7));
 
}
 

	
 
/** Build rail on a stretch of track.
 
 * Stub for the unified rail builder/remover
 
@@ -569,13 +569,13 @@ int32 CmdBuildRailroadTrack(TileIndex ti
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
 
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
 
 * @see CmdRailTrackHelper
 
 */
 
int32 CmdRemoveRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	return CmdRailTrackHelper(tile, flags, p1, SETBIT(p2, 7));
 
}
 

	
 
/** Build a train depot
 
 * @param tile position of the train depot
 
@@ -583,16 +583,16 @@ int32 CmdRemoveRailroadTrack(TileIndex t
 
 * @param p1 rail type
 
 * @param p2 bit 0..1 entrance direction (DiagDirection)
 
 *
 
 * @todo When checking for the tile slope,
 
 * distingush between "Flat land required" and "land sloped in wrong direction"
 
 */
 
int32 CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Depot *d;
 
	int32 cost, ret;
 
	CommandCost cost, ret;
 
	Slope tileh;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	/* check railtype and valid direction for depot (0 through 3), 4 in total */
 
	if (!ValParamRailtype(p1)) return CMD_ERROR;
 
@@ -650,18 +650,18 @@ int32 CmdBuildTrainDepot(TileIndex tile,
 
 * - p1 = (bit 0-2) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p1 = (bit 3)   - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
 
 * - p1 = (bit 4)   - 0 = signals, 1 = semaphores
 
 * @param p2 used for CmdBuildManySignals() to copy direction of first signal
 
 * TODO: p2 should be replaced by two bits for "along" and "against" the track.
 
 */
 
int32 CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Track track = (Track)GB(p1, 0, 3);
 
	bool pre_signal = HASBIT(p1, 3);
 
	SignalVariant sigvar = (pre_signal ^ HASBIT(p1, 4)) ? SIG_SEMAPHORE : SIG_ELECTRIC;
 
	int32 cost;
 
	CommandCost cost;
 

	
 
	if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicleOnGround(tile))
 
		return CMD_ERROR;
 

	
 
	/* Protect against invalid signal copying */
 
	if (p2 != 0 && (p2 & SignalOnTrack(track)) == 0) return CMD_ERROR;
 
@@ -747,15 +747,16 @@ int32 CmdBuildSingleSignal(TileIndex til
 
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
 
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
 
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
 
 * - p2 = (bit 24-31) - user defined signals_density
 
 */
 
static int32 CmdSignalTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
static CommandCost CmdSignalTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 ret, total_cost, signal_ctr;
 
	CommandCost ret, total_cost;
 
	int signal_ctr;
 
	byte signals;
 
	bool error = true;
 
	TileIndex end_tile;
 

	
 
	Track track = (Track)GB(p2, 0, 3);
 
	bool mode = HASBIT(p2, 3);
 
@@ -837,13 +838,13 @@ static int32 CmdSignalTrackHelper(TileIn
 
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
 
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
 
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
 
 * - p2 = (bit 24-31) - user defined signals_density
 
 * @see CmdSignalTrackHelper
 
 */
 
int32 CmdBuildSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	return CmdSignalTrackHelper(tile, flags, p1, p2);
 
}
 

	
 
/** Remove signals
 
 * @param tile coordinates where signal is being deleted from
 
@@ -851,13 +852,13 @@ int32 CmdBuildSignalTrack(TileIndex tile
 
 * @param p1 various bitstuffed elements, only track information is used
 
 *           - (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
 
 *           - (bit  3)    - override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
 
 *           - (bit  4)    - 0 = signals, 1 = semaphores
 
 * @param p2 unused
 
 */
 
int32 CmdRemoveSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Track track = (Track)GB(p1, 0, 3);
 

	
 
	if (!ValParamTrackOrientation(track) ||
 
			!IsTileType(tile, MP_RAILWAY) ||
 
			!EnsureNoVehicleOnGround(tile) ||
 
@@ -900,30 +901,30 @@ int32 CmdRemoveSingleSignal(TileIndex ti
 
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
 
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
 
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
 
 * - p2 = (bit 24-31) - user defined signals_density
 
 * @see CmdSignalTrackHelper
 
 */
 
int32 CmdRemoveSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	return CmdSignalTrackHelper(tile, flags, p1, SETBIT(p2, 5)); // bit 5 is remove bit
 
}
 

	
 
typedef int32 DoConvertRailProc(TileIndex tile, RailType totype, bool exec);
 
typedef CommandCost DoConvertRailProc(TileIndex tile, RailType totype, bool exec);
 

	
 
/**
 
 * Switches the rail type.
 
 * Railtypes are stored on a per-tile basis, not on a per-track basis, so
 
 * all the tracks in the given tile will be converted.
 
 * @param tile        The tile on which the railtype is to be convert.
 
 * @param totype      The railtype we want to convert to
 
 * @param exec        Switches between test and execute mode
 
 * @return            The cost and state of the operation
 
 * @retval CMD_ERROR  An error occured during the operation.
 
 */
 
static int32 DoConvertRail(TileIndex tile, RailType totype, bool exec)
 
static CommandCost DoConvertRail(TileIndex tile, RailType totype, bool exec)
 
{
 
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
	if (GetRailType(tile) == totype) return CMD_ERROR;
 

	
 
	if (!EnsureNoVehicleOnGround(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
 
@@ -957,26 +958,27 @@ static int32 DoConvertRail(TileIndex til
 
		}
 
	}
 

	
 
	return _price.build_rail / 2;
 
}
 

	
 
extern int32 DoConvertStationRail(TileIndex tile, RailType totype, bool exec);
 
extern int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec);
 
extern int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec);
 
extern CommandCost DoConvertStationRail(TileIndex tile, RailType totype, bool exec);
 
extern CommandCost DoConvertStreetRail(TileIndex tile, RailType totype, bool exec);
 
extern CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec);
 

	
 
/** Convert one rail type to the other. You can convert normal rail to
 
 * monorail/maglev easily or vice-versa.
 
 * @param tile end tile of rail conversion drag
 
 * @param flags operation to perform
 
 * @param p1 start tile of drag
 
 * @param p2 new railtype to convert to
 
 */
 
int32 CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 ret, cost, money;
 
	CommandCost ret, cost;
 
	int32 money;
 
	int ex;
 
	int ey;
 
	int sx, sy, x, y;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
@@ -1023,13 +1025,13 @@ int32 CmdConvertRail(TileIndex tile, uin
 
		}
 
	}
 

	
 
	return (cost == 0) ? ret : cost;
 
}
 

	
 
static int32 RemoveTrainDepot(TileIndex tile, uint32 flags)
 
static CommandCost RemoveTrainDepot(TileIndex tile, uint32 flags)
 
{
 
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
 
		return CMD_ERROR;
 

	
 
	if (!EnsureNoVehicleOnGround(tile))
 
		return CMD_ERROR;
 
@@ -1042,16 +1044,16 @@ static int32 RemoveTrainDepot(TileIndex 
 
		YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
 
	}
 

	
 
	return _price.remove_train_depot;
 
}
 

	
 
static int32 ClearTile_Track(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Track(TileIndex tile, byte flags)
 
{
 
	int32 cost;
 
	int32 ret;
 
	CommandCost cost;
 
	CommandCost ret;
 

	
 
	if (flags & DC_AUTO) {
 
		if (!IsTileOwner(tile, _current_player))
 
			return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
 

	
 
		if (IsPlainRailTile(tile)) {
src/road_cmd.cpp
Show inline comments
 
@@ -104,13 +104,13 @@ static bool CheckAllowRemoveRoad(TileInd
 
 *                    yet when removing the road bits when not actually doing
 
 *                    it. Makes it possible to test whether the road bits can
 
 *                    be removed from a level crossing without physically
 
 *                    removing the tram bits before the test.
 
 * @param p2 unused
 
 */
 
int32 CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	/* cost for removing inner/edge -roads */
 
	static const uint16 road_remove_cost[2] = {50, 18};
 

	
 
	Town *t;
 
	/* true if the roadpiece was always removeable,
 
@@ -163,13 +163,13 @@ int32 CmdRemoveRoad(TileIndex tile, uint
 
	if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR;
 

	
 
	if (!IsTileType(tile, MP_STREET)) {
 
		/* If it's the last roadtype, just clear the whole tile */
 
		if (rts == RoadTypeToRoadTypes(rt)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 

	
 
		int32 cost;
 
		CommandCost cost;
 
		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
			TileIndex other_end = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
 
			/* Pay for *every* tile of the bridge or tunnel */
 
			cost = (DistanceManhattan(IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile), tile) + 1) * _price.remove_road;
 
			if (flags & DC_EXEC) {
 
				SetRoadTypes(other_end, GetRoadTypes(other_end) & ~RoadTypeToRoadTypes(rt));
 
@@ -298,13 +298,13 @@ static const RoadBits _valid_tileh_slope
 
		ROAD_ALL,
 
		ROAD_ALL
 
	},
 
};
 

	
 

	
 
static uint32 CheckRoadSlope(Slope tileh, RoadBits* pieces, RoadBits existing)
 
static CommandCost CheckRoadSlope(Slope tileh, RoadBits* pieces, RoadBits existing)
 
{
 
	RoadBits road_bits;
 

	
 
	if (IsSteepSlope(tileh)) {
 
		if (existing == 0) {
 
			/* force full pieces. */
 
@@ -343,16 +343,16 @@ static uint32 CheckRoadSlope(Slope tileh
 
 * @param flags operation to perform
 
 * @param p1 bit 0..3 road pieces to build (RoadBits)
 
 *           bit 4..5 road type
 
 *           bit 6..7 disallowed directions to toggle
 
 * @param p2 the town that is building the road (0 if not applicable)
 
 */
 
int32 CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 cost = 0;
 
	int32 ret;
 
	CommandCost cost = 0;
 
	CommandCost ret;
 
	RoadBits existing = ROAD_NONE;
 
	RoadBits all_bits = ROAD_NONE;
 
	Slope tileh;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
@@ -550,13 +550,13 @@ do_clear:;
 
 * @param tile        The tile on which the railtype is to be convert.
 
 * @param totype      The railtype we want to convert to
 
 * @param exec        Switches between test and execute mode
 
 * @return            The cost and state of the operation
 
 * @retval CMD_ERROR  An error occured during the operation.
 
 */
 
int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec)
 
CommandCost DoConvertStreetRail(TileIndex tile, RailType totype, bool exec)
 
{
 
	/* not a railroad crossing? */
 
	if (!IsLevelCrossing(tile)) return CMD_ERROR;
 

	
 
	/* not owned by me? */
 
	if (!CheckTileOwnership(tile) || !EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
@@ -584,16 +584,16 @@ int32 DoConvertStreetRail(TileIndex tile
 
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
 
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
 
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
 
 * - p2 = (bit 3 + 4) - road type
 
 * - p2 = (bit 5) - set road direction
 
 */
 
int32 CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TileIndex start_tile, tile;
 
	int32 cost, ret;
 
	CommandCost cost, ret;
 
	bool had_bridge = false;
 
	bool had_success = false;
 
	DisallowedRoadDirections drd = DRD_NORTHBOUND;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
@@ -664,16 +664,16 @@ int32 CmdBuildLongRoad(TileIndex end_til
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
 
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
 
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
 
 * - p2 = (bit 3 + 4) - road type
 
 */
 
int32 CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TileIndex start_tile, tile;
 
	int32 cost, ret;
 
	CommandCost cost, ret;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	start_tile = p1;
 
@@ -722,15 +722,15 @@ int32 CmdRemoveLongRoad(TileIndex end_ti
 
 *           bit 2..3 road type
 
 * @param p2 unused
 
 *
 
 * @todo When checking for the tile slope,
 
 * distingush between "Flat land required" and "land sloped in wrong direction"
 
 */
 
int32 CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 cost;
 
	CommandCost cost;
 
	Depot *dep;
 
	Slope tileh;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	DiagDirection dir = Extract<DiagDirection, 0>(p1);
 
@@ -762,25 +762,25 @@ int32 CmdBuildRoadDepot(TileIndex tile, 
 
		MakeRoadDepot(tile, _current_player, dir, rt);
 
		MarkTileDirtyByTile(tile);
 
	}
 
	return cost + _price.build_road_depot;
 
}
 

	
 
static int32 RemoveRoadDepot(TileIndex tile, uint32 flags)
 
static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags)
 
{
 
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
 
		return CMD_ERROR;
 

	
 
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) DeleteDepot(GetDepotByTile(tile));
 

	
 
	return _price.remove_road_depot;
 
}
 

	
 
static int32 ClearTile_Road(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Road(TileIndex tile, byte flags)
 
{
 
	switch (GetRoadTileType(tile)) {
 
		case ROAD_TILE_NORMAL: {
 
			RoadBits b = GetAllRoadBits(tile);
 

	
 
#define M(x) (1 << (x))
 
@@ -788,37 +788,37 @@ static int32 ClearTile_Road(TileIndex ti
 
			 * to clear town road OR we are not using the DC_AUTO flag */
 
			if ((M(b) & (M(ROAD_NW) | M(ROAD_SW) | M(ROAD_SE) | M(ROAD_NE))) ||
 
			    ((flags & DC_AI_BUILDING) && IsTileOwner(tile, OWNER_TOWN)) ||
 
			    !(flags & DC_AUTO)
 
				) {
 
				RoadTypes rts = GetRoadTypes(tile);
 
				int32 ret = 0;
 
				CommandCost ret = 0;
 
				for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
 
					if (HASBIT(rts, rt)) {
 
						int32 tmp_ret = DoCommand(tile, rt << 4 | GetRoadBits(tile, rt), 0, flags, CMD_REMOVE_ROAD);
 
						CommandCost tmp_ret = DoCommand(tile, rt << 4 | GetRoadBits(tile, rt), 0, flags, CMD_REMOVE_ROAD);
 
						if (CmdFailed(tmp_ret)) return tmp_ret;
 
						ret += tmp_ret;
 
					}
 
				}
 
				return ret;
 
			}
 
			return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
 
		}
 
#undef M
 

	
 
		case ROAD_TILE_CROSSING: {
 
			RoadTypes rts = GetRoadTypes(tile);
 
			int32 ret = 0;
 
			CommandCost ret = 0;
 

	
 
			if (flags & DC_AUTO) return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
 

	
 
			/* Must iterate over the roadtypes in a reverse manner because
 
			 * tram tracks must be removed before the road bits. */
 
			for (RoadType rt = ROADTYPE_HWAY; rt >= ROADTYPE_ROAD; rt--) {
 
				if (HASBIT(rts, rt)) {
 
					int32 tmp_ret = DoCommand(tile, 1 << 6 | rt << 4 | GetCrossingRoadBits(tile), 0, flags, CMD_REMOVE_ROAD);
 
					CommandCost tmp_ret = DoCommand(tile, 1 << 6 | rt << 4 | GetCrossingRoadBits(tile), 0, flags, CMD_REMOVE_ROAD);
 
					if (CmdFailed(tmp_ret)) return tmp_ret;
 
					ret += tmp_ret;
 
				}
 
			}
 

	
 
			if (flags & DC_EXEC) {
src/roadveh_cmd.cpp
Show inline comments
 
@@ -113,13 +113,13 @@ void DrawRoadVehEngine(int x, int y, Eng
 
		}
 
		spritenum = orig_road_vehicle_info[engine - ROAD_ENGINES_INDEX].image_index;
 
	}
 
	DrawSprite(6 + _roadveh_images[spritenum], pal, x, y);
 
}
 

	
 
static int32 EstimateRoadVehCost(EngineID engine_type)
 
static CommandCost EstimateRoadVehCost(EngineID engine_type)
 
{
 
	return ((_price.roadveh_base >> 3) * GetEngineProperty(engine_type, 0x11, RoadVehInfo(engine_type)->base_cost)) >> 5;
 
}
 

	
 
byte GetRoadVehLength(const Vehicle *v)
 
{
 
@@ -153,15 +153,15 @@ void RoadVehUpdateCache(Vehicle *v)
 
/** Build a road vehicle.
 
 * @param tile tile of depot where road vehicle is built
 
 * @param flags operation to perform
 
 * @param p1 bus/truck type being built (engine)
 
 * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
 
 */
 
int32 CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 cost;
 
	CommandCost cost;
 
	Vehicle *v;
 
	UnitID unit_num;
 
	Engine *e;
 

	
 
	if (!IsEngineBuildable(p1, VEH_ROAD, _current_player)) return_cmd_error(STR_ROAD_VEHICLE_NOT_AVAILABLE);
 

	
 
@@ -279,13 +279,13 @@ int32 CmdBuildRoadVeh(TileIndex tile, ui
 
/** Start/Stop a road vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 road vehicle ID to start/stop
 
 * @param p2 unused
 
 */
 
int32 CmdStartStopRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdStartStopRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	uint16 callback;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
@@ -344,13 +344,13 @@ static bool CheckRoadVehInDepotStopped(c
 
/** Sell a road vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 */
 
int32 CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 
@@ -444,13 +444,13 @@ static const Depot* FindClosestRoadDepot
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to send to the depot
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 */
 
int32 CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	const Depot *dep;
 

	
 
	if (p2 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
@@ -517,13 +517,13 @@ int32 CmdSendRoadVehToDepot(TileIndex ti
 
/** Turn a roadvehicle around.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to turn
 
 * @param p2 unused
 
 */
 
int32 CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 
@@ -1883,13 +1883,13 @@ static void CheckIfRoadVehNeedsService(V
 
	v->dest_tile = depot->xy;
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 
}
 

	
 
void OnNewDay_RoadVeh(Vehicle *v)
 
{
 
	int32 cost;
 
	CommandCost cost;
 

	
 
	if (!IsRoadVehFront(v)) return;
 

	
 
	if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v);
 
	if (v->u.road.blocked_ctr == 0) CheckVehicleBreakdown(v);
 

	
 
@@ -1998,16 +1998,16 @@ void RoadVehiclesYearlyLoop()
 
 * @param p2 Bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle (ignored)
 
 * @return cost of refit or error
 
 */
 
int32 CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	int32 cost;
 
	CommandCost cost;
 
	CargoID new_cid = GB(p2, 0, 8);
 
	byte new_subtype = GB(p2, 8, 8);
 
	uint16 capacity = CALLBACK_FAILED;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
src/settings.cpp
Show inline comments
 
@@ -1763,13 +1763,13 @@ static const SettingDesc *GetSettingDesc
 
 * @param flags operation to perform
 
 * @param p1 the index of the patch in the SettingDesc array which identifies it
 
 * @param p2 the new value for the patch
 
 * The new value is properly clamped to its minimum/maximum when setting
 
 * @see _patch_settings
 
 */
 
int32 CmdChangePatchSetting(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdChangePatchSetting(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	const SettingDesc *sd = GetSettingDescription(p1);
 

	
 
	if (sd == NULL) return CMD_ERROR;
 
	if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) return CMD_ERROR;
 

	
src/settings_gui.cpp
Show inline comments
 
@@ -248,13 +248,13 @@ static void GameOptionsWndProc(Window *w
 
/** Change the side of the road vehicles drive on (server only).
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the side of the road; 0 = left side and 1 = right side
 
 * @param p2 unused
 
 */
 
int32 CmdSetRoadDriveSide(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSetRoadDriveSide(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	/* Check boundaries and you can only change this if NO vehicles have been built yet,
 
	 * except in the intro-menu where of course it's always possible to do so. */
 
	if (p1 > 1 || (_game_mode != GM_MENU && RoadVehiclesAreBuilt())) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
src/ship_cmd.cpp
Show inline comments
 
@@ -172,13 +172,13 @@ static void CheckIfShipNeedsService(Vehi
 
	v->dest_tile = depot->xy;
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 
}
 

	
 
void OnNewDay_Ship(Vehicle *v)
 
{
 
	int32 cost;
 
	CommandCost cost;
 

	
 
	if ((++v->day_counter & 7) == 0)
 
		DecreaseVehicleValue(v);
 

	
 
	CheckVehicleBreakdown(v);
 
	AgeVehicle(v);
 
@@ -400,15 +400,15 @@ static bool ShipAccelerate(Vehicle *v)
 

	
 
	v->progress = (t = v->progress) - (byte)spd;
 

	
 
	return (t < v->progress);
 
}
 

	
 
static int32 EstimateShipCost(EngineID engine_type)
 
static CommandCost EstimateShipCost(EngineID engine_type)
 
{
 
	return GetEngineProperty(engine_type, 0x0A, ShipVehInfo(engine_type)->base_cost) * (_price.ship_base>>3)>>5;
 
	return GetEngineProperty(engine_type, 0x0A, ShipVehInfo(engine_type)->base_cost) * (_price.ship_base >> 3) >> 5;
 
}
 

	
 
static void ShipArrivesAt(const Vehicle* v, Station* st)
 
{
 
	/* Check if station was ever visited before */
 
	if (!(st->had_vehicle_of_type & HVOT_SHIP)) {
 
@@ -806,15 +806,15 @@ void ShipsYearlyLoop()
 
/** Build a ship.
 
 * @param tile tile of depot where ship is built
 
 * @param flags type of operation
 
 * @param p1 ship type being built (engine)
 
 * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
 
 */
 
int32 CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 value;
 
	CommandCost value;
 
	Vehicle *v;
 
	UnitID unit_num;
 
	Engine *e;
 

	
 
	if (!IsEngineBuildable(p1, VEH_SHIP, _current_player)) return_cmd_error(STR_SHIP_NOT_AVAILABLE);
 

	
 
@@ -901,13 +901,13 @@ int32 CmdBuildShip(TileIndex tile, uint3
 
/** Sell a ship.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 */
 
int32 CmdSellShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSellShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 
@@ -935,13 +935,13 @@ int32 CmdSellShip(TileIndex tile, uint32
 
/** Start/Stop a ship.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 ship ID to start/stop
 
 * @param p2 unused
 
 */
 
int32 CmdStartStopShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdStartStopShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	uint16 callback;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
@@ -976,13 +976,13 @@ int32 CmdStartStopShip(TileIndex tile, u
 
 * @param flags type of operation
 
 * @param p1 vehicle ID to send to the depot
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 */
 
int32 CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	const Depot *dep;
 

	
 
	if (p2 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
@@ -1053,16 +1053,16 @@ int32 CmdSendShipToDepot(TileIndex tile,
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle (ignored)
 
 * @return cost of refit or error
 
 */
 
int32 CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	int32 cost;
 
	CommandCost cost;
 
	CargoID new_cid = GB(p2, 0, 8); //gets the cargo number
 
	byte new_subtype = GB(p2, 8, 8);
 
	uint16 capacity = CALLBACK_FAILED;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
src/signs.cpp
Show inline comments
 
@@ -119,13 +119,13 @@ void DestroySign(Sign *si)
 
 * but everybody is able to rename/remove it.
 
 * @param tile tile to place sign at
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
int32 CmdPlaceSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdPlaceSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Sign *si;
 

	
 
	/* Try to locate a new sign */
 
	si = AllocateSign();
 
	if (si == NULL) return_cmd_error(STR_2808_TOO_MANY_SIGNS);
 
@@ -156,13 +156,13 @@ int32 CmdPlaceSign(TileIndex tile, uint3
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 index of the sign to be renamed/removed
 
 * @param p2 unused
 
 * @return 0 if succesfull, otherwise CMD_ERROR
 
 */
 
int32 CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (!IsValidSignID(p1)) return CMD_ERROR;
 

	
 
	/* If _cmd_text 0 means the new text for the sign is non-empty.
 
	 * So rename the sign. If it is empty, it has no name, so delete it */
 
	if (_cmd_text[0] != '\0') {
src/station_cmd.cpp
Show inline comments
 
@@ -609,19 +609,19 @@ static void DeleteStationIfEmpty(Station
 
		InvalidateWindow(WC_STATION_LIST, st->owner);
 
	}
 
	/* station remains but it probably lost some parts - station sign should stay in the station boundaries */
 
	UpdateStationSignCoord(st);
 
}
 

	
 
static int32 ClearTile_Station(TileIndex tile, byte flags);
 
static CommandCost ClearTile_Station(TileIndex tile, byte flags);
 

	
 
// Tries to clear the given area. Returns the cost in case of success.
 
// Or an error code if it failed.
 
int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station, bool check_clear = true)
 
CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station, bool check_clear = true)
 
{
 
	int32 cost = 0;
 
	CommandCost cost = 0;
 
	int allowed_z = -1;
 

	
 
	BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
 
		if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) {
 
			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
 
		}
 
@@ -677,13 +677,13 @@ int32 CheckFlatLandBelow(TileIndex tile,
 
					*station = st;
 
				} else if (*station != st) {
 
					return_cmd_error(STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING);
 
				}
 
			}
 
		} else if (check_clear) {
 
			int32 ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			CommandCost ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			if (CmdFailed(ret)) return ret;
 
			cost += ret;
 
		}
 
	} END_TILE_LOOP(tile_cur, w, h, tile)
 

	
 
	return cost;
 
@@ -798,16 +798,16 @@ static void GetStationLayout(byte *layou
 
 * - p1 = (bit 24)    - allow stations directly adjacent to other stations.
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 3) - railtype (p2 & 0xF)
 
 * - p2 = (bit  8-15) - custom station class
 
 * - p2 = (bit 16-23) - custom station id
 
 */
 
int32 CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int w_org, h_org;
 
	int32 ret;
 
	CommandCost ret;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	/* Does the authority allow this? */
 
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR;
 
	if (!ValParamRailtype(p2 & 0xF)) return CMD_ERROR;
 
@@ -835,13 +835,13 @@ int32 CmdBuildRailroadStation(TileIndex 
 
	// Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station)
 
	StationID est = INVALID_STATION;
 
	// If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug
 
	//  for detail info, see: https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365
 
	ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL);
 
	if (CmdFailed(ret)) return ret;
 
	int32 cost = ret + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len;
 
	CommandCost cost = ret + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len;
 

	
 
	Station *st = NULL;
 
	bool check_surrounding = true;
 

	
 
	if (_patches.adjacent_stations) {
 
		if (est != INVALID_STATION) {
 
@@ -1051,13 +1051,13 @@ restart:
 
 * This allows for custom-built station with holes and weird layouts
 
 * @param tile tile of station piece to remove
 
 * @param flags operation to perform
 
 * @param p1 start_tile
 
 * @param p2 unused
 
 */
 
int32 CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TileIndex start = p1 == 0 ? tile : p1;
 

	
 
	/* Count of the number of tiles removed */
 
	int quantity = 0;
 

	
 
@@ -1122,13 +1122,13 @@ int32 CmdRemoveFromRailroadStation(TileI
 
	if (quantity == 0) return CMD_ERROR;
 

	
 
	return _price.remove_rail_station * quantity;
 
}
 

	
 

	
 
static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
 
static CommandCost RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
 
{
 
	/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */
 
	if (_current_player == OWNER_WATER && _patches.nonuniform_stations)
 
		return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION);
 

	
 
	/* Current player owns the station? */
 
@@ -1139,13 +1139,13 @@ static int32 RemoveRailroadStation(Stati
 
	tile = st->train_tile;
 
	int w = st->trainst_w;
 
	int h = st->trainst_h;
 

	
 
	assert(w != 0 && h != 0);
 

	
 
	int32 cost = 0;
 
	CommandCost cost = 0;
 
	/* clear all areas of the station */
 
	do {
 
		int w_bak = w;
 
		do {
 
			// for nonuniform stations, only remove tiles that are actually train station tiles
 
			if (st->TileBelongsToRailStation(tile)) {
 
@@ -1188,13 +1188,13 @@ static int32 RemoveRailroadStation(Stati
 
 * @param tile        The tile on which the railtype is to be convert.
 
 * @param totype      The railtype we want to convert to
 
 * @param exec        Switches between test and execute mode
 
 * @return            The cost and state of the operation
 
 * @retval CMD_ERROR  An error occured during the operation.
 
 */
 
int32 DoConvertStationRail(TileIndex tile, RailType totype, bool exec)
 
CommandCost DoConvertStationRail(TileIndex tile, RailType totype, bool exec)
 
{
 
	const Station* st = GetStationByTile(tile);
 

	
 
	if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
	// tile is not a railroad station?
 
@@ -1240,13 +1240,13 @@ static RoadStop **FindRoadStopSpot(bool 
 
 * @param p1 entrance direction (DiagDirection)
 
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
 
 *           bit 1: 0 for normal, 1 for drive-through
 
 *           bit 2..4: the roadtypes
 
 *           bit 5: allow stations directly adjacent to other stations.
 
 */
 
int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	bool type = HASBIT(p2, 0);
 
	bool is_drive_through = HASBIT(p2, 1);
 
	bool build_over_road  = is_drive_through && IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL;
 
	bool town_owned_road  = build_over_road && IsTileOwner(tile, OWNER_TOWN);
 
	RoadTypes rts = (RoadTypes)GB(p2, 2, 3);
 
@@ -1264,13 +1264,13 @@ int32 CmdBuildRoadStop(TileIndex tile, u
 
	if (build_over_road && (GetAllRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_DRIVE_THROUGH_ERROR_DIRECTION);
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
 

	
 
	int32 cost = 0;
 
	CommandCost cost = 0;
 

	
 
	/* Not allowed to build over this road */
 
	if (build_over_road) {
 
		if (IsTileOwner(tile, OWNER_TOWN) && !_patches.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD);
 
		if (GetRoadTileType(tile) != ROAD_TILE_NORMAL) return CMD_ERROR;
 

	
 
@@ -1368,13 +1368,13 @@ int32 CmdBuildRoadStop(TileIndex tile, u
 
		rs_auto_delete.Release();
 
	}
 
	return cost;
 
}
 

	
 
// Remove a bus station
 
static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile)
 
static CommandCost RemoveRoadStop(Station *st, uint32 flags, TileIndex tile)
 
{
 
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) {
 
		return CMD_ERROR;
 
	}
 

	
 
	bool is_truck = IsTruckStop(tile);
 
@@ -1422,26 +1422,26 @@ static int32 RemoveRoadStop(Station *st,
 
/** Remove a bus or truck stop
 
 * @param tile tile to remove the stop from
 
 * @param flags operation to perform
 
 * @param p1 not used
 
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
 
 */
 
int32 CmdRemoveRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	/* Make sure the specified tile is a road stop of the correct type */
 
	if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile) || (uint32)GetRoadStopType(tile) != p2) return CMD_ERROR;
 
	Station *st = GetStationByTile(tile);
 
	/* Save the stop info before it is removed */
 
	bool is_drive_through = IsDriveThroughStopTile(tile);
 
	RoadTypes rts = GetRoadTypes(tile);
 
	RoadBits road_bits = IsDriveThroughStopTile(tile) ?
 
			((GetRoadStopDir(tile) == DIAGDIR_NE) ? ROAD_X : ROAD_Y) :
 
			DiagDirToRoadBits(GetRoadStopDir(tile));
 
	bool is_towns_road = is_drive_through && GetStopBuiltOnTownRoad(tile);
 

	
 
	int32 ret = RemoveRoadStop(st, flags, tile);
 
	CommandCost ret = RemoveRoadStop(st, flags, tile);
 

	
 
	/* If the stop was a drive-through stop replace the road */
 
	if ((flags & DC_EXEC) && !CmdFailed(ret) && is_drive_through) {
 
		/* Rebuild the drive throuhg road stop. As a road stop can only be
 
		 * removed by the owner of the roadstop, _current_player is the
 
		 * owner of the road stop. */
 
@@ -1547,13 +1547,13 @@ static const byte * const _airport_secti
 
/** Place an Airport.
 
 * @param tile tile where airport will be built
 
 * @param flags operation to perform
 
 * @param p1 airport type, @see airport.h
 
 * @param p2 (bit 0) - allow airports directly adjacent to other airports.
 
 */
 
int32 CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	bool airport_upgrade = true;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	/* Check if a valid, buildable airport was chosen for construction */
 
@@ -1579,15 +1579,15 @@ int32 CmdBuildAirport(TileIndex tile, ui
 
	}
 

	
 
	const AirportFTAClass *afc = GetAirport(p1);
 
	int w = afc->size_x;
 
	int h = afc->size_y;
 

	
 
	int32 ret = CheckFlatLandBelow(tile, w, h, flags, 0, NULL);
 
	CommandCost ret = CheckFlatLandBelow(tile, w, h, flags, 0, NULL);
 
	if (CmdFailed(ret)) return ret;
 
	int32 cost = ret;
 
	CommandCost cost = ret;
 

	
 
	Station *st = NULL;
 

	
 
	if (!_patches.adjacent_stations || !HASBIT(p2, 0)) {
 
		st = GetStationAround(tile, w, h, INVALID_STATION);
 
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
 
@@ -1673,24 +1673,24 @@ int32 CmdBuildAirport(TileIndex tile, ui
 
		st_auto_delete.Release();
 
	}
 

	
 
	return cost;
 
}
 

	
 
static int32 RemoveAirport(Station *st, uint32 flags)
 
static CommandCost RemoveAirport(Station *st, uint32 flags)
 
{
 
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
 
		return CMD_ERROR;
 

	
 
	TileIndex tile = st->airport_tile;
 

	
 
	const AirportFTAClass *afc = st->Airport();
 
	int w = afc->size_x;
 
	int h = afc->size_y;
 

	
 
	int32 cost = w * h * _price.remove_airport;
 
	CommandCost cost = w * h * _price.remove_airport;
 

	
 
	Vehicle *v;
 
	FOR_ALL_VEHICLES(v) {
 
		if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue;
 

	
 
		if (v->u.air.targetairport == st->index && v->u.air.state != FLYING) return CMD_ERROR;
 
@@ -1727,13 +1727,13 @@ static int32 RemoveAirport(Station *st, 
 
/** Build a buoy.
 
 * @param tile tile where to place the bouy
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
int32 CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	if (!IsClearWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE);
 
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
@@ -1786,13 +1786,13 @@ static bool CheckShipsOnBuoy(Station *st
 
			}
 
		}
 
	}
 
	return false;
 
}
 

	
 
static int32 RemoveBuoy(Station *st, uint32 flags)
 
static CommandCost RemoveBuoy(Station *st, uint32 flags)
 
{
 
	/* XXX: strange stuff */
 
	if (!IsValidPlayer(_current_player))  return_cmd_error(INVALID_STRING_ID);
 

	
 
	TileIndex tile = st->dock_tile;
 

	
 
@@ -1836,15 +1836,15 @@ static const byte _dock_h_chk[4] = { 1, 
 
/** Build a dock/haven.
 
 * @param tile tile where dock will be built
 
 * @param flags operation to perform
 
 * @param p1 (bit 0) - allow docks directly adjacent to other docks.
 
 * @param p2 unused
 
 */
 
int32 CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 cost;
 
	CommandCost cost;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	DiagDirection direction;
 
	switch (GetTileSlope(tile, NULL)) {
 
		case SLOPE_SW: direction = DIAGDIR_NE; break;
 
@@ -1935,13 +1935,13 @@ int32 CmdBuildDock(TileIndex tile, uint3
 
		/* success, so don't delete the new station */
 
		st_auto_delete.Release();
 
	}
 
	return _price.build_dock;
 
}
 

	
 
static int32 RemoveDock(Station *st, uint32 flags)
 
static CommandCost RemoveDock(Station *st, uint32 flags)
 
{
 
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
 

	
 
	TileIndex tile1 = st->dock_tile;
 
	TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
 

	
 
@@ -2491,13 +2491,13 @@ static void UpdateStationWaiting(Station
 
/** Rename a station
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 station ID that is to be renamed
 
 * @param p2 unused
 
 */
 
int32 CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (!IsValidStationID(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
 
	Station *st = GetStation(p1);
 

	
 
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
 

	
 
@@ -2745,13 +2745,13 @@ static bool CanRemoveRoadWithStop(TileIn
 

	
 
	bool edge_road;
 
	return CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_ROAD), OWNER_TOWN, &edge_road, ROADTYPE_ROAD) &&
 
				CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_TRAM), OWNER_TOWN, &edge_road, ROADTYPE_TRAM);
 
}
 

	
 
static int32 ClearTile_Station(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Station(TileIndex tile, byte flags)
 
{
 
	if (flags & DC_AUTO) {
 
		switch (GetStationType(tile)) {
 
			case STATION_RAIL:    return_cmd_error(STR_300B_MUST_DEMOLISH_RAILROAD);
 
			case STATION_AIRPORT: return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST);
 
			case STATION_TRUCK:   return_cmd_error(HASBIT(GetRoadTypes(tile), ROADTYPE_TRAM) ? STR_3047_MUST_DEMOLISH_CARGO_TRAM_STATION : STR_3047_MUST_DEMOLISH_TRUCK_STATION);
src/town_cmd.cpp
Show inline comments
 
@@ -475,16 +475,16 @@ static void TileLoop_Town(TileIndex tile
 
 */
 
static void ClickTile_Town(TileIndex tile)
 
{
 
	/* not used */
 
}
 

	
 
static int32 ClearTile_Town(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Town(TileIndex tile, byte flags)
 
{
 
	int rating;
 
	int32 cost;
 
	CommandCost cost;
 
	Town *t;
 
	HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
 

	
 
	if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
 
	if (!CanDeleteHouse(tile)) return CMD_ERROR;
 

	
 
@@ -705,13 +705,13 @@ no_slope:
 
		 * maybe terraform some. */
 
		k = (dir & 1) ? SLOPE_NE : SLOPE_NW;
 
		if (k != slope && ComplementSlope(k) != slope) {
 
			uint32 r = Random();
 

	
 
			if (CHANCE16I(1, 8, r) && !_generating_world) {
 
				int32 res;
 
				CommandCost res;
 

	
 
				if (CHANCE16I(1, 16, r)) {
 
					res = DoCommand(tile, slope, 0, DC_EXEC | DC_AUTO | DC_NO_WATER,
 
					                      CMD_TERRAFORM_LAND);
 
				} else {
 
					res = DoCommand(tile, slope ^ 0xF, 1, DC_EXEC | DC_AUTO | DC_NO_WATER,
 
@@ -727,13 +727,13 @@ no_slope:
 
		return true;
 
	}
 
}
 

	
 
static bool TerraformTownTile(TileIndex tile, int edges, int dir)
 
{
 
	int32 r;
 
	CommandCost r;
 

	
 
	TILE_ASSERT(tile);
 

	
 
	r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
 
	if (CmdFailed(r) || r >= 126 * 16) return false;
 
	DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND);
 
@@ -1461,13 +1461,13 @@ static Town *AllocateTown()
 
 * as it might be possible in the future to fund your own town :)
 
 * @param tile coordinates where town is built
 
 * @param flags type of operation
 
 * @param p1 size of the town (0 = small, 1 = medium, 2 = large)
 
 * @param p2 size mode (@see TownSizeMode)
 
 */
 
int32 CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Town *t;
 
	uint32 townnameparts;
 

	
 
	/* Only in the scenario editor */
 
	if (_game_mode != GM_EDITOR) return CMD_ERROR;
 
@@ -1767,13 +1767,13 @@ static void DoBuildTownHouse(Town *t, Ti
 
		MakeTownHouse(tile, t->index, construction_counter, construction_stage, house, VehicleRandomBits());
 
	}
 
}
 

	
 
static bool BuildTownHouse(Town *t, TileIndex tile)
 
{
 
	int32 r;
 
	CommandCost r;
 

	
 
	if (IsSteepSlope(GetTileSlope(tile, NULL))) return false;
 
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false;
 

	
 
	r = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(r)) return false;
 
@@ -1843,13 +1843,13 @@ void ClearTownHouse(Town *t, TileIndex t
 
/** Rename a town (server-only).
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 town ID to rename
 
 * @param p2 unused
 
 */
 
int32 CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	StringID str;
 
	Town *t;
 

	
 
	if (!IsValidTownID(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
 

	
 
@@ -1929,13 +1929,13 @@ static void TownActionRoadRebuild(Town* 
 
		NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_GENERAL, 0), t->xy, 0);
 
}
 

	
 
static bool DoBuildStatueOfCompany(TileIndex tile, TownID town_id)
 
{
 
	PlayerID old;
 
	int32 r;
 
	CommandCost r;
 

	
 
	if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return false;
 

	
 
	if (!IsTileType(tile, MP_HOUSE) &&
 
			!IsTileType(tile, MP_CLEAR) &&
 
			!IsTileType(tile, MP_TREES)) {
 
@@ -2047,15 +2047,15 @@ extern uint GetMaskOfTownActions(int *nu
 
 * but also bribing the town-council
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 town to do the action at
 
 * @param p2 action to perform, @see _town_action_proc for the list of available actions
 
 */
 
int32 CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 cost;
 
	CommandCost cost;
 
	Town *t;
 

	
 
	if (!IsValidTownID(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR;
 

	
 
	t = GetTown(p1);
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -499,18 +499,18 @@ void DrawTrainEngine(int x, int y, Engin
 
				_engine_sprite_base[img + 1];
 
		}
 
	}
 
	DrawSprite(image, pal, x, y);
 
}
 

	
 
static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
 
static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
 
{
 
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 

	
 
	const RailVehicleInfo *rvi = RailVehInfo(engine);
 
	int32 value = (GetEngineProperty(engine, 0x17, rvi->base_cost) * _price.build_railwagon) >> 8;
 
	CommandCost value = (GetEngineProperty(engine, 0x17, rvi->base_cost) * _price.build_railwagon) >> 8;
 

	
 
	uint num_vehicles = 1 + CountArticulatedParts(engine);
 

	
 
	if (!(flags & DC_QUERY_COST)) {
 
		Vehicle *vl[11]; // Allow for wagon and upto 10 artic parts.
 

	
 
@@ -608,13 +608,13 @@ static void NormalizeTrainVehInDepot(con
 
					CMD_MOVE_RAIL_VEHICLE)))
 
				break;
 
		}
 
	}
 
}
 

	
 
static int32 EstimateTrainCost(EngineID engine, const RailVehicleInfo* rvi)
 
static CommandCost EstimateTrainCost(EngineID engine, const RailVehicleInfo* rvi)
 
{
 
	return GetEngineProperty(engine, 0x17, rvi->base_cost) * (_price.build_railvehicle >> 3) >> 5;
 
}
 

	
 
static void AddRearEngineToMultiheadedTrain(Vehicle* v, Vehicle* u, bool building)
 
{
 
@@ -648,13 +648,13 @@ static void AddRearEngineToMultiheadedTr
 
 * @param tile tile of the depot where rail-vehicle is built
 
 * @param flags type of operation
 
 * @param p1 engine type id
 
 * @param p2 bit 0 when set, the train will get number 0, otherwise it will get a free number
 
 *           bit 1 prevents any free cars from being added to the train
 
 */
 
int32 CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	/* Check if the engine-type is valid (for the player) */
 
	if (!IsEngineBuildable(p1, VEH_TRAIN, _current_player)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE);
 

	
 
	/* Check if the train is actually being built in a depot belonging
 
	 * to the player. Doesn't matter if only the cost is queried */
 
@@ -670,13 +670,13 @@ int32 CmdBuildRailVehicle(TileIndex tile
 
	/* Check if depot and new engine uses the same kind of tracks */
 
	/* We need to see if the engine got power on the tile to avoid eletric engines in non-electric depots */
 
	if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
 

	
 
	if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, flags);
 

	
 
	int32 value = EstimateTrainCost(p1, rvi);
 
	CommandCost value = EstimateTrainCost(p1, rvi);
 

	
 
	uint num_vehicles =
 
		(rvi->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) +
 
		CountArticulatedParts(p1);
 

	
 
	if (!(flags & DC_QUERY_COST)) {
 
@@ -906,13 +906,13 @@ static void NormaliseTrainConsist(Vehicl
 
 * @param flags type of operation
 
 * @param p1 various bitstuffed elements
 
 * - p1 (bit  0 - 15) source vehicle index
 
 * - p1 (bit 16 - 31) what wagon to put the source wagon AFTER, XXX - INVALID_VEHICLE to make a new line
 
 * @param p2 (bit 0) move all vehicles following the source vehicle
 
 */
 
int32 CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	VehicleID s = GB(p1, 0, 16);
 
	VehicleID d = GB(p1, 16, 16);
 

	
 
	if (!IsValidVehicleID(s)) return CMD_ERROR;
 

	
 
@@ -1159,13 +1159,13 @@ int32 CmdMoveRailVehicle(TileIndex tile,
 
/** Start/Stop a train.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 train to start/stop
 
 * @param p2 unused
 
 */
 
int32 CmdStartStopTrain(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdStartStopTrain(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
 
@@ -1200,13 +1200,13 @@ int32 CmdStartStopTrain(TileIndex tile, 
 
 * - p2 = 0: only sell the single dragged wagon/engine (and any belonging rear-engines)
 
 * - p2 = 1: sell the vehicle and all vehicles following it in the chain
 
             if the wagon is dragged, don't delete the possibly belonging rear-engine to some front
 
 * - p2 = 2: when selling attached locos, rearrange all vehicles after it to separate lines;
 
 *           all wagons of the same type will go on the same line. Used by the AI currently
 
 */
 
int32 CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	/* Check if we deleted a vehicle window */
 
	Window *w = NULL;
 

	
 
	if (!IsValidVehicleID(p1) || p2 > 2) return CMD_ERROR;
 

	
 
@@ -1232,13 +1232,13 @@ int32 CmdSellRailWagon(TileIndex tile, u
 
			if (w != NULL) DeleteWindow(w);
 
		}
 
		InvalidateWindow(WC_VEHICLE_DEPOT, first->tile);
 
		RebuildVehicleLists();
 
	}
 

	
 
	int32 cost = 0;
 
	CommandCost cost = 0;
 
	switch (p2) {
 
		case 0: case 2: { /* Delete given wagon */
 
			bool switch_engine = false;    // update second wagon to engine?
 
			byte ori_subtype = v->subtype; // backup subtype of deleted wagon in case DeleteVehicle() changes
 

	
 
			/* 1. Delete the engine, if it is dualheaded also delete the matching
 
@@ -1613,13 +1613,13 @@ static void ReverseTrainDirection(Vehicl
 
/** Reverse train.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 train to reverse
 
 * @param p2 if true, reverse a unit in a train (needs to be in a depot)
 
 */
 
int32 CmdReverseTrainDirection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdReverseTrainDirection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
 
@@ -1662,13 +1662,13 @@ int32 CmdReverseTrainDirection(TileIndex
 
/** Force a train through a red signal
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 train to ignore the red signal
 
 * @param p2 unused
 
 */
 
int32 CmdForceTrainProceed(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdForceTrainProceed(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
 
@@ -1685,13 +1685,13 @@ int32 CmdForceTrainProceed(TileIndex til
 
 * param p2 various bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle
 
 * @return cost of refit or error
 
 */
 
int32 CmdRefitRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRefitRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	CargoID new_cid = GB(p2, 0, 8);
 
	byte new_subtype = GB(p2, 8, 8);
 
	bool only_this = HASBIT(p2, 16);
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
@@ -1703,13 +1703,13 @@ int32 CmdRefitRailVehicle(TileIndex tile
 

	
 
	/* Check cargo */
 
	if (new_cid >= NUM_CARGO) return CMD_ERROR;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_TRAIN_RUN);
 

	
 
	int32 cost = 0;
 
	CommandCost cost = 0;
 
	uint num = 0;
 

	
 
	do {
 
		/* XXX: We also refit all the attached wagons en-masse if they
 
		 * can be refitted. This is how TTDPatch does it.  TODO: Have
 
		 * some nice [Refit] button near each wagon. --pasky */
 
@@ -1869,13 +1869,13 @@ static TrainFindDepotData FindClosestTra
 
 * @param flags type of operation
 
 * @param p1 train to send to the depot
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 */
 
int32 CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (p2 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
 
		return SendAllVehiclesToDepot(VEH_TRAIN, flags, p2 & DEPOT_SERVICE, _current_player, (p2 & VLW_MASK), p1);
 
	}
 
@@ -3386,13 +3386,13 @@ void OnNewDay_Train(Vehicle *v)
 
			TileIndex tile = GetStation(v->current_order.dest)->train_tile;
 
			if (tile != 0) v->dest_tile = tile;
 
		}
 

	
 
		if ((v->vehstatus & VS_STOPPED) == 0) {
 
			/* running costs */
 
			int32 cost = GetTrainRunningCost(v) / 364;
 
			CommandCost cost = GetTrainRunningCost(v) / 364;
 

	
 
			v->profit_this_year -= cost >> 8;
 

	
 
			SET_EXPENSES_TYPE(EXPENSES_TRAIN_RUN);
 
			SubtractMoneyFromPlayerFract(v->owner, cost);
 

	
src/tree_cmd.cpp
Show inline comments
 
@@ -210,16 +210,16 @@ void GenerateTrees()
 
/** Plant a tree.
 
 * @param tile start tile of area-drag of tree plantation
 
 * @param flags type of operation
 
 * @param p1 tree type, -1 means random.
 
 * @param p2 end tile of area-drag
 
 */
 
int32 CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	StringID msg = INVALID_STRING_ID;
 
	int32 cost;
 
	CommandCost cost;
 
	int ex;
 
	int ey;
 
	int sx, sy, x, y;
 

	
 
	if (p2 >= MapSize()) return CMD_ERROR;
 
	/* Check the tree type. It can be random or some valid value within the current climate */
 
@@ -425,13 +425,13 @@ static uint GetSlopeZ_Trees(TileIndex ti
 

	
 
static Slope GetSlopeTileh_Trees(TileIndex tile, Slope tileh)
 
{
 
	return tileh;
 
}
 

	
 
static int32 ClearTile_Trees(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Trees(TileIndex tile, byte flags)
 
{
 
	uint num;
 

	
 
	if ((flags & DC_EXEC) && IsValidPlayer(_current_player)) {
 
		Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
 
		if (t != NULL)
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -107,13 +107,13 @@ static inline byte GetBridgeFlags(int in
 
/** Check the slope at the bridge ramps in three easy steps:
 
 * - valid slopes without foundation
 
 * - valid slopes with foundation
 
 * - rest is invalid
 
 */
 
#define M(x) (1 << (x))
 
static int32 CheckBridgeSlopeNorth(Axis axis, Slope tileh)
 
static CommandCost CheckBridgeSlopeNorth(Axis axis, Slope tileh)
 
{
 
	uint32 valid;
 

	
 
	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_NE) : M(SLOPE_NW));
 
	if (HASBIT(valid, tileh)) return 0;
 

	
 
@@ -122,13 +122,13 @@ static int32 CheckBridgeSlopeNorth(Axis 
 
		(axis == AXIS_X ? M(SLOPE_E) | M(SLOPE_STEEP_E) : M(SLOPE_W) | M(SLOPE_STEEP_W));
 
	if (HASBIT(valid, tileh)) return _price.terraform;
 

	
 
	return CMD_ERROR;
 
}
 

	
 
static int32 CheckBridgeSlopeSouth(Axis axis, Slope tileh)
 
static CommandCost CheckBridgeSlopeSouth(Axis axis, Slope tileh)
 
{
 
	uint32 valid;
 

	
 
	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_SW) : M(SLOPE_SE));
 
	if (HASBIT(valid, tileh)) return 0;
 

	
 
@@ -172,13 +172,13 @@ bool CheckBridge_Stuff(byte bridge_type,
 
 * @param p1 packed start tile coords (~ dx)
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0- 7) - bridge type (hi bh)
 
 * - p2 = (bit 8-..) - rail type or road types.
 
 * - p2 = (bit 15  ) - set means road bridge.
 
 */
 
int32 CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	uint bridge_type;
 
	RailType railtype;
 
	RoadTypes roadtypes;
 
	uint x;
 
	uint y;
 
@@ -191,13 +191,13 @@ int32 CmdBuildBridge(TileIndex end_tile,
 
	uint z_start;
 
	uint z_end;
 
	TileIndex tile;
 
	TileIndexDiff delta;
 
	uint bridge_len;
 
	Axis direction;
 
	int32 cost, terraformcost, ret;
 
	CommandCost cost, terraformcost, ret;
 
	bool allow_on_slopes;
 
	bool replace_bridge = false;
 
	uint replaced_bridge_type;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
@@ -450,23 +450,23 @@ not_valid_below:;
 
/** Build Tunnel.
 
 * @param start_tile start tile of tunnel
 
 * @param flags type of operation
 
 * @param p1 railtype or roadtypes. bit 9 set means road tunnel
 
 * @param p2 unused
 
 */
 
int32 CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TileIndexDiff delta;
 
	TileIndex end_tile;
 
	DiagDirection direction;
 
	Slope start_tileh;
 
	Slope end_tileh;
 
	uint start_z;
 
	uint end_z;
 
	int32 cost;
 
	int32 ret;
 
	CommandCost cost;
 
	CommandCost ret;
 

	
 
	_build_tunnel_endtile = 0;
 
	if (!HASBIT(p1, 9)) {
 
		if (!ValParamRailtype(p1)) return CMD_ERROR;
 
	} else if (!AreValidRoadTypes((RoadTypes)GB(p1, 0, 3))) {
 
		return CMD_ERROR;
 
@@ -575,13 +575,13 @@ static inline bool CheckAllowRemoveTunne
 
	if (CheckTileOwnership(tile) || IsTileOwner(tile, OWNER_NONE)) return true;
 
	/* Otherwise we can only remove town-owned stuff with extra patch-settings, or cheat */
 
	if (IsTileOwner(tile, OWNER_TOWN) && (_patches.extra_dynamite || _cheats.magic_bulldozer.value)) return true;
 
	return false;
 
}
 

	
 
static int32 DoClearTunnel(TileIndex tile, uint32 flags)
 
static CommandCost DoClearTunnel(TileIndex tile, uint32 flags)
 
{
 
	Town *t = NULL;
 
	TileIndex endtile;
 
	uint length;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
@@ -635,13 +635,13 @@ static bool IsVehicleOnBridge(TileIndex 
 
			return true;
 
		}
 
	}
 
	return false;
 
}
 

	
 
static int32 DoClearBridge(TileIndex tile, uint32 flags)
 
static CommandCost DoClearBridge(TileIndex tile, uint32 flags)
 
{
 
	DiagDirection direction;
 
	TileIndexDiff delta;
 
	TileIndex endtile;
 
	Town *t = NULL;
 

	
 
@@ -695,13 +695,13 @@ static int32 DoClearBridge(TileIndex til
 
		YapfNotifyTrackLayoutChange(endtile, track);
 
	}
 

	
 
	return (DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge;
 
}
 

	
 
static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags)
 
static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
 
{
 
	if (IsTunnel(tile)) {
 
		if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
 
		return DoClearTunnel(tile, flags);
 
	} else if (IsBridge(tile)) { // XXX Is this necessary?
 
		if (flags & DC_AUTO) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
 
@@ -718,13 +718,13 @@ static int32 ClearTile_TunnelBridge(Tile
 
 * @param tile        The tile on which the railtype is to be convert.
 
 * @param totype      The railtype we want to convert to
 
 * @param exec        Switches between test and execute mode
 
 * @return            The cost and state of the operation
 
 * @retval CMD_ERROR  An error occured during the operation.
 
 */
 
int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
 
CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
 
{
 
	TileIndex endtile;
 

	
 
	if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
 
		uint length;
 

	
src/unmovable_cmd.cpp
Show inline comments
 
@@ -28,13 +28,13 @@
 
 * During normal gameplay you can only implicitely destroy a HQ when you are
 
 * rebuilding it. Otherwise, only water can destroy it.
 
 * @param pid Player requesting the destruction of his HQ
 
 * @param flags docommand flags of calling function
 
 * @return cost of the operation
 
 */
 
static int32 DestroyCompanyHQ(PlayerID pid, uint32 flags)
 
static CommandCost DestroyCompanyHQ(PlayerID pid, uint32 flags)
 
{
 
	Player* p = GetPlayer(pid);
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
 

	
 
	if (flags & DC_EXEC) {
 
@@ -70,25 +70,25 @@ void UpdateCompanyHQ(Player *p, uint sco
 
	MarkTileDirtyByTile(tile + TileDiffXY(0, 0));
 
	MarkTileDirtyByTile(tile + TileDiffXY(0, 1));
 
	MarkTileDirtyByTile(tile + TileDiffXY(1, 0));
 
	MarkTileDirtyByTile(tile + TileDiffXY(1, 1));
 
}
 

	
 
extern int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station, bool check_clear = true);
 
extern CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station, bool check_clear = true);
 

	
 
/** Build or relocate the HQ. This depends if the HQ is already built or not
 
 * @param tile tile where the HQ will be built or relocated to
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
int32 CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Player *p = GetPlayer(_current_player);
 
	int cost;
 
	int32 ret;
 
	CommandCost cost;
 
	CommandCost ret;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
 

	
 
	ret = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL);
 
	if (CmdFailed(ret)) return ret;
 
	cost = ret;
 
@@ -213,13 +213,13 @@ static uint GetSlopeZ_Unmovable(TileInde
 

	
 
static Slope GetSlopeTileh_Unmovable(TileIndex tile, Slope tileh)
 
{
 
	return IsOwnedLand(tile) ? tileh : SLOPE_FLAT;
 
}
 

	
 
static int32 ClearTile_Unmovable(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Unmovable(TileIndex tile, byte flags)
 
{
 
	if (IsCompanyHQ(tile)) {
 
		if (_current_player == OWNER_WATER) {
 
			return DestroyCompanyHQ(GetTileOwner(tile), DC_EXEC);
 
		} else {
 
			return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);
src/vehicle.cpp
Show inline comments
 
@@ -842,15 +842,15 @@ CargoID FindFirstRefittableCargo(EngineI
 
}
 

	
 
/** Learn the price of refitting a certain engine
 
* @param engine_type Which engine to refit
 
* @return Price for refitting
 
*/
 
int32 GetRefitCost(EngineID engine_type)
 
CommandCost GetRefitCost(EngineID engine_type)
 
{
 
	int32 base_cost = 0;
 
	CommandCost base_cost = 0;
 

	
 
	switch (GetEngine(engine_type)->type) {
 
		case VEH_SHIP: base_cost = _price.ship_base; break;
 
		case VEH_ROAD: base_cost = _price.roadveh_base; break;
 
		case VEH_AIRCRAFT: base_cost = _price.aircraft_base; break;
 
		case VEH_TRAIN:
 
@@ -1676,18 +1676,18 @@ void AgeVehicle(Vehicle *v)
 
 * @param p2 bitmask
 
 *   - bit 0-4 Vehicle type
 
 *   - bit 5 false = start vehicles, true = stop vehicles
 
 *   - bit 6 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case
 
 *   - bit 8-11 Vehicle List Window type (ignored unless bit 1 is set)
 
 */
 
int32 CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle **vl = NULL;
 
	uint16 engine_list_length = 0;
 
	uint16 engine_count = 0;
 
	int32 return_value = CMD_ERROR;
 
	CommandCost return_value = CMD_ERROR;
 
	uint i;
 
	uint stop_command;
 
	VehicleType vehicle_type = (VehicleType)GB(p2, 0, 5);
 
	bool start_stop = HASBIT(p2, 5);
 
	bool vehicle_list_window = HASBIT(p2, 6);
 

	
 
@@ -1708,13 +1708,13 @@ int32 CmdMassStartStopVehicle(TileIndex 
 
		/* Get the list of vehicles in the depot */
 
		BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL);
 
	}
 

	
 
	for (i = 0; i < engine_count; i++) {
 
		const Vehicle *v = vl[i];
 
		int32 ret;
 
		CommandCost ret;
 

	
 
		if (!!(v->vehstatus & VS_STOPPED) != start_stop) continue;
 

	
 
		if (!vehicle_list_window) {
 
			if (vehicle_type == VEH_TRAIN) {
 
				if (CheckTrainInDepot(v, false) == -1) continue;
 
@@ -1740,22 +1740,22 @@ int32 CmdMassStartStopVehicle(TileIndex 
 
/** Sells all vehicles in a depot
 
 * @param tile Tile of the depot where the depot is
 
 * @param flags type of operation
 
 * @param p1 Vehicle type
 
 * @param p2 unused
 
 */
 
int32 CmdDepotSellAllVehicles(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdDepotSellAllVehicles(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle **engines = NULL;
 
	Vehicle **wagons = NULL;
 
	uint16 engine_list_length = 0;
 
	uint16 engine_count = 0;
 
	uint16 wagon_list_length = 0;
 
	uint16 wagon_count = 0;
 

	
 
	int32 cost = 0;
 
	CommandCost cost = 0;
 
	uint i, sell_command, total_number_vehicles;
 
	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
 

	
 
	switch (vehicle_type) {
 
		case VEH_TRAIN:    sell_command = CMD_SELL_RAIL_WAGON; break;
 
		case VEH_ROAD:     sell_command = CMD_SELL_ROAD_VEH;   break;
 
@@ -1768,13 +1768,13 @@ int32 CmdDepotSellAllVehicles(TileIndex 
 
	BuildDepotVehicleList(vehicle_type, tile, &engines, &engine_list_length, &engine_count,
 
						                      &wagons,  &wagon_list_length,  &wagon_count);
 

	
 
	total_number_vehicles = engine_count + wagon_count;
 
	for (i = 0; i < total_number_vehicles; i++) {
 
		const Vehicle *v;
 
		int32 ret;
 
		CommandCost ret;
 

	
 
		if (i < engine_count) {
 
			v = engines[i];
 
		} else {
 
			v = wagons[i - engine_count];
 
		}
 
@@ -1793,31 +1793,31 @@ int32 CmdDepotSellAllVehicles(TileIndex 
 
/** Autoreplace all vehicles in the depot
 
 * @param tile Tile of the depot where the vehicles are
 
 * @param flags type of operation
 
 * @param p1 Type of vehicle
 
 * @param p2 Unused
 
 */
 
int32 CmdDepotMassAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdDepotMassAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle **vl = NULL;
 
	uint16 engine_list_length = 0;
 
	uint16 engine_count = 0;
 
	uint i, x = 0, y = 0, z = 0;
 
	int32 cost = 0;
 
	CommandCost cost = 0;
 
	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
 

	
 
	if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
 

	
 
	/* Get the list of vehicles in the depot */
 
	BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL);
 

	
 

	
 
	for (i = 0; i < engine_count; i++) {
 
		Vehicle *v = vl[i];
 
		bool stopped = !(v->vehstatus & VS_STOPPED);
 
		int32 ret;
 
		CommandCost ret;
 

	
 
		/* Ensure that the vehicle completely in the depot */
 
		if (!IsVehicleInDepot(v)) continue;
 

	
 
		x = v->x_pos;
 
		y = v->y_pos;
 
@@ -1859,17 +1859,17 @@ int32 CmdDepotMassAutoReplace(TileIndex 
 
/** Clone a vehicle. If it is a train, it will clone all the cars too
 
 * @param tile tile of the depot where the cloned vehicle is build
 
 * @param flags type of operation
 
 * @param p1 the original vehicle's index
 
 * @param p2 1 = shared orders, else copied orders
 
 */
 
int32 CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v_front, *v;
 
	Vehicle *w_front, *w, *w_rear;
 
	int32 cost, total_cost = 0;
 
	CommandCost cost, total_cost = 0;
 
	uint32 build_argument = 2;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
	v = GetVehicle(p1);
 
	v_front = v;
 
	w = NULL;
 
@@ -1923,13 +1923,13 @@ int32 CmdCloneVehicle(TileIndex tile, ui
 
				SETBIT(w->u.rail.flags, VRF_REVERSE_DIRECTION);
 
			}
 

	
 
			if (v->type == VEH_TRAIN && !IsFrontEngine(v)) {
 
				/* this s a train car
 
				 * add this unit to the end of the train */
 
				int32 result = DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE);
 
				CommandCost result = DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE);
 
				if (CmdFailed(result)) {
 
					/* The train can't be joined to make the same consist as the original.
 
					 * Sell what we already made (clean up) and return an error.           */
 
					DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front));
 
					DoCommand(w_front->tile, w->index,       1, flags, GetCmdSellVeh(w));
 
					return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE
 
@@ -2220,24 +2220,24 @@ uint GenerateVehicleSortList(const Vehic
 
 * @param flags the flags used for DoCommand()
 
 * @param service should the vehicles only get service in the depots
 
 * @param owner PlayerID of owner of the vehicles to send
 
 * @param vlw_flag tells what kind of list requested the goto depot
 
 * @return 0 for success and CMD_ERROR if no vehicle is able to go to depot
 
 */
 
int32 SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id)
 
CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id)
 
{
 
	const Vehicle **sort_list = NULL;
 
	uint n, i;
 
	uint16 array_length = 0;
 

	
 
	n = GenerateVehicleSortList(&sort_list, &array_length, type, owner, id, vlw_flag);
 

	
 
	/* Send all the vehicles to a depot */
 
	for (i = 0; i < n; i++) {
 
		const Vehicle *v = sort_list[i];
 
		int32 ret = DoCommand(v->tile, v->index, (service ? 1 : 0) | DEPOT_DONT_CANCEL, flags, GetCmdSendToDepot(type));
 
		CommandCost ret = DoCommand(v->tile, v->index, (service ? 1 : 0) | DEPOT_DONT_CANCEL, flags, GetCmdSendToDepot(type));
 

	
 
		/* Return 0 if DC_EXEC is not set this is a valid goto depot command)
 
			* In this case we know that at least one vehicle can be sent to a depot
 
			* and we will issue the command. We can now safely quit the loop, knowing
 
			* it will succeed at least once. With DC_EXEC we really need to send them to the depot */
 
		if (!CmdFailed(ret) && !(flags & DC_EXEC)) {
 
@@ -2311,13 +2311,13 @@ void VehicleEnterDepot(Vehicle *v)
 

	
 
		t = v->current_order;
 
		v->current_order.type = OT_DUMMY;
 
		v->current_order.flags = 0;
 

	
 
		if (t.refit_cargo < NUM_CARGO) {
 
			int32 cost;
 
			CommandCost cost;
 

	
 
			_current_player = v->owner;
 
			cost = DoCommand(v->tile, v->index, t.refit_cargo | t.refit_subtype << 8, DC_EXEC, GetCmdRefitVeh(v));
 

	
 
			if (CmdFailed(cost)) {
 
				v->leave_depot_instantly = false; // We ensure that the vehicle stays in the depot
 
@@ -2359,13 +2359,13 @@ void VehicleEnterDepot(Vehicle *v)
 
/** Give a custom name to your vehicle
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID to name
 
 * @param p2 unused
 
 */
 
int32 CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	StringID str;
 

	
 
	if (!IsValidVehicleID(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
 

	
 
@@ -2393,13 +2393,13 @@ int32 CmdNameVehicle(TileIndex tile, uin
 
/** Change the service interval of a vehicle
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID that is being service-interval-changed
 
 * @param p2 new service interval
 
 */
 
int32 CmdChangeServiceInt(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdChangeServiceInt(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle* v;
 
	uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */
 

	
 
	if (serv_int != p2 || !IsValidVehicleID(p1)) return CMD_ERROR;
 

	
src/vehicle.h
Show inline comments
 
@@ -506,13 +506,13 @@ Vehicle *FindVehicleOnTileZ(TileIndex ti
 
void InitializeTrains();
 
byte VehicleRandomBits();
 
void ResetVehiclePosHash();
 

	
 
bool CanRefitTo(EngineID engine_type, CargoID cid_to);
 
CargoID FindFirstRefittableCargo(EngineID engine_type);
 
int32 GetRefitCost(EngineID engine_type);
 
CommandCost GetRefitCost(EngineID engine_type);
 

	
 
void ViewportAddVehicles(DrawPixelInfo *dpi);
 

	
 
/* train_cmd.h */
 
int GetTrainImage(const Vehicle* v, Direction direction);
 
int GetAircraftImage(const Vehicle* v, Direction direction);
 
@@ -553,19 +553,19 @@ int32 GetTrainRunningCost(const Vehicle 
 
int CheckTrainStoppedInDepot(const Vehicle *v);
 

	
 
bool VehicleNeedsService(const Vehicle *v);
 

	
 
uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type);
 
void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count);
 
int32 SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id);
 
CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id);
 
bool IsVehicleInDepot(const Vehicle *v);
 
void VehicleEnterDepot(Vehicle *v);
 

	
 
void InvalidateAutoreplaceWindow(EngineID e);
 

	
 
int32 MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs);
 
CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs);
 

	
 
/* Flags to add to p2 for goto depot commands */
 
/* Note: bits 8-10 are used for VLW flags */
 
enum {
 
	DEPOT_SERVICE       = (1 << 0), // The vehicle will leave the depot right after arrival (serivce only)
 
	DEPOT_MASS_SEND     = (1 << 1), // Tells that it's a mass send to depot command (type in VLW flag)
src/vehicle_gui.cpp
Show inline comments
 
@@ -335,13 +335,13 @@ static void VehicleRefitWndProc(Window *
 
			SetDParam(1, v->unitnumber);
 
			DrawWindowWidgets(w);
 

	
 
			WP(w, refit_d).cargo = DrawVehicleRefitWindow(WP(w, refit_d).list, WP(w, refit_d).sel, w->vscroll.pos, w->vscroll.cap, w->resize.step_height);
 

	
 
			if (WP(w, refit_d).cargo != NULL) {
 
				int32 cost;
 
				CommandCost cost;
 

	
 
				cost = DoCommand(v->tile, v->index, WP(w, refit_d).cargo->cargo | WP(w, refit_d).cargo->subtype << 8,
 
								 DC_QUERY_COST, GetCmdRefitVeh(GetVehicle(w->window_number)->type));
 

	
 
				if (!CmdFailed(cost)) {
 
					SetDParam(0, WP(w, refit_d).cargo->cargo);
src/water_cmd.cpp
Show inline comments
 
@@ -53,17 +53,17 @@ static void FloodVehicle(Vehicle *v);
 
/** Build a ship depot.
 
 * @param tile tile where ship depot is built
 
 * @param flags type of operation
 
 * @param p1 bit 0 depot orientation (Axis)
 
 * @param p2 unused
 
 */
 
int32 CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TileIndex tile2;
 

	
 
	int32 cost, ret;
 
	CommandCost cost, ret;
 
	Depot *depot;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
@@ -98,13 +98,13 @@ int32 CmdBuildShipDepot(TileIndex tile, 
 
		MarkTileDirtyByTile(tile2);
 
	}
 

	
 
	return cost + _price.build_ship_depot;
 
}
 

	
 
static int32 RemoveShipDepot(TileIndex tile, uint32 flags)
 
static CommandCost RemoveShipDepot(TileIndex tile, uint32 flags)
 
{
 
	TileIndex tile2;
 

	
 
	if (!IsShipDepot(tile)) return CMD_ERROR;
 
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 
@@ -124,15 +124,15 @@ static int32 RemoveShipDepot(TileIndex t
 
	}
 

	
 
	return _price.remove_ship_depot;
 
}
 

	
 
/** build a shiplift */
 
static int32 DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags)
 
static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags)
 
{
 
	int32 ret;
 
	CommandCost ret;
 
	int delta;
 

	
 
	/* middle tile */
 
	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(ret)) return CMD_ERROR;
 

	
 
@@ -164,13 +164,13 @@ static int32 DoBuildShiplift(TileIndex t
 
		MarkTileDirtyByTile(tile + delta);
 
	}
 

	
 
	return _price.clear_water * 22 >> 3;
 
}
 

	
 
static int32 RemoveShiplift(TileIndex tile, uint32 flags)
 
static CommandCost RemoveShiplift(TileIndex tile, uint32 flags)
 
{
 
	TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
 

	
 
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
	/* make sure no vehicle is on the tile. */
 
@@ -197,13 +197,13 @@ static void MarkTilesAroundDirty(TileInd
 
/** Builds a lock (ship-lift)
 
 * @param tile tile where to place the lock
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
int32 CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	DiagDirection dir;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	switch (GetTileSlope(tile, NULL)) {
 
@@ -219,15 +219,15 @@ int32 CmdBuildLock(TileIndex tile, uint3
 
/** Build a piece of canal.
 
 * @param tile end tile of stretch-dragging
 
 * @param flags type of operation
 
 * @param p1 start tile of stretch-dragging
 
 * @param p2 ctrl pressed - toggles ocean / canals at sealevel (ocean only allowed in the scenario editor)
 
 */
 
int32 CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 cost;
 
	CommandCost cost;
 
	int size_x, size_y;
 
	int x;
 
	int y;
 
	int sx, sy;
 

	
 
	if (p1 >= MapSize()) return CMD_ERROR;
 
@@ -248,13 +248,13 @@ int32 CmdBuildCanal(TileIndex tile, uint
 

	
 
	/* Outside the editor you can only drag canals, and not areas */
 
	if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR;
 

	
 
	cost = 0;
 
	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
 
		int32 ret;
 
		CommandCost ret;
 

	
 
		if (GetTileSlope(tile, NULL) != SLOPE_FLAT) {
 
			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
 
		}
 

	
 
		/* can't make water of water! */
 
@@ -281,13 +281,13 @@ int32 CmdBuildCanal(TileIndex tile, uint
 
		return_cmd_error(STR_1007_ALREADY_BUILT);
 
	} else {
 
		return cost;
 
	}
 
}
 

	
 
static int32 ClearTile_Water(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Water(TileIndex tile, byte flags)
 
{
 
	switch (GetWaterTileType(tile)) {
 
		case WATER_TILE_CLEAR:
 
			if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
 

	
 
			/* Make sure no vehicle is on the tile */
src/waypoint.cpp
Show inline comments
 
@@ -198,13 +198,13 @@ void AfterLoadWaypoints()
 
 * @param p1 graphics for waypoint type, 0 indicates standard graphics
 
 * @param p2 unused
 
 *
 
 * @todo When checking for the tile slope,
 
 * distingush between "Flat land required" and "land sloped in wrong direction"
 
 */
 
int32 CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Waypoint *wp;
 
	Slope tileh;
 
	Axis axis;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
@@ -292,13 +292,13 @@ void WaypointsDailyLoop()
 
 * Remove a waypoint
 
 * @param tile from which to remove waypoint
 
 * @param flags type of operation
 
 * @param justremove will indicate if it is removed from rail or if rails are removed too
 
 * @return cost of operation or error
 
 */
 
int32 RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove)
 
CommandCost RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove)
 
{
 
	Waypoint *wp;
 

	
 
	/* Make sure it's a waypoint */
 
	if (!IsTileType(tile, MP_RAILWAY) ||
 
			!IsRailWaypoint(tile) ||
 
@@ -332,13 +332,13 @@ int32 RemoveTrainWaypoint(TileIndex tile
 
 * @param tile tile where waypoint is to be deleted
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @return cost of operation or error
 
 */
 
int32 CmdRemoveTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
	return RemoveTrainWaypoint(tile, flags, true);
 
}
 

	
 
/**
 
@@ -346,13 +346,13 @@ int32 CmdRemoveTrainWaypoint(TileIndex t
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 id of waypoint
 
 * @param p2 unused
 
 * @return cost of operation or error
 
 */
 
int32 CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Waypoint *wp;
 

	
 
	if (!IsValidWaypointID(p1)) return CMD_ERROR;
 

	
 
	if (_cmd_text[0] != '\0') {
src/waypoint.h
Show inline comments
 
@@ -63,13 +63,13 @@ static inline void DeleteWaypoint(Waypoi
 
static inline Waypoint *GetWaypointByTile(TileIndex tile)
 
{
 
	assert(IsTileType(tile, MP_RAILWAY) && IsRailWaypoint(tile));
 
	return GetWaypoint(GetWaypointIndex(tile));
 
}
 

	
 
int32 RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove);
 
CommandCost RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove);
 
Station *ComposeWaypointStation(TileIndex tile);
 
void ShowRenameWaypointWindow(const Waypoint *cp);
 
void DrawWaypointSprite(int x, int y, int image, RailType railtype);
 
void FixOldWaypoints();
 
void UpdateAllWaypointSigns();
 
void AfterLoadWaypoints();
0 comments (0 inline, 0 general)