src/station_cmd.cpp
branchgamebalance
changeset 9908 0fa543611bbe
parent 9907 3b068c3a1c74
child 9909 dce9a6923bb7
equal deleted inserted replaced
9907:3b068c3a1c74 9908:0fa543611bbe
     7 #include "aircraft.h"
     7 #include "aircraft.h"
     8 #include "bridge_map.h"
     8 #include "bridge_map.h"
     9 #include "cmd_helper.h"
     9 #include "cmd_helper.h"
    10 #include "debug.h"
    10 #include "debug.h"
    11 #include "functions.h"
    11 #include "functions.h"
       
    12 #include "landscape.h"
    12 #include "station_map.h"
    13 #include "station_map.h"
    13 #include "table/sprites.h"
    14 #include "table/sprites.h"
    14 #include "table/strings.h"
    15 #include "table/strings.h"
    15 #include "map.h"
    16 #include "map.h"
    16 #include "tile.h"
    17 #include "tile.h"
   116 
   117 
   117 #define CHECK_STATIONS_ERR ((Station*)-1)
   118 #define CHECK_STATIONS_ERR ((Station*)-1)
   118 
   119 
   119 static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest_station)
   120 static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest_station)
   120 {
   121 {
   121 	// check around to see if there's any stations there
   122 	/* check around to see if there's any stations there */
   122 	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
   123 	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
   123 		if (IsTileType(tile_cur, MP_STATION)) {
   124 		if (IsTileType(tile_cur, MP_STATION)) {
   124 			StationID t = GetStationIndex(tile_cur);
   125 			StationID t = GetStationIndex(tile_cur);
   125 
   126 
   126 			if (closest_station == INVALID_STATION) {
   127 			if (closest_station == INVALID_STATION) {
  1188 	/* Saveguard the parameters */
  1189 	/* Saveguard the parameters */
  1189 	if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR;
  1190 	if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR;
  1190 	/* If it is a drive-through stop check for valid axis */
  1191 	/* If it is a drive-through stop check for valid axis */
  1191 	if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR;
  1192 	if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR;
  1192 	/* Road bits in the wrong direction */
  1193 	/* Road bits in the wrong direction */
  1193 	if (build_over_road && (GetRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return CMD_ERROR;
  1194 	if (build_over_road && (GetRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_DRIVE_THROUGH_ERROR_DIRECTION);
  1194 	/* Not allowed to build over this road */
  1195 	/* Not allowed to build over this road */
  1195 	if (build_over_road && !IsTileOwner(tile, _current_player) && !(IsTileOwner(tile, OWNER_TOWN) && _patches.road_stop_on_town_road)) return CMD_ERROR;
  1196 	if (build_over_road) {
       
  1197 		if (IsTileOwner(tile, OWNER_TOWN) && !_patches.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD);
       
  1198 		if (!IsTileOwner(tile, OWNER_TOWN) && !CheckOwnership(GetTileOwner(tile))) return CMD_ERROR;
       
  1199 	}
  1196 
  1200 
  1197 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
  1201 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
  1198 
  1202 
  1199 	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
  1203 	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
  1200 		return CMD_ERROR;
  1204 		return CMD_ERROR;
  1598 	int w = afc->size_x;
  1602 	int w = afc->size_x;
  1599 	int h = afc->size_y;
  1603 	int h = afc->size_y;
  1600 
  1604 
  1601 	int32 cost = w * h * _eco->GetPrice(CEconomy::REMOVE_AIRPORT);
  1605 	int32 cost = w * h * _eco->GetPrice(CEconomy::REMOVE_AIRPORT);
  1602 
  1606 
       
  1607 	Vehicle *v;
       
  1608 	FOR_ALL_VEHICLES(v) {
       
  1609 		if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue;
       
  1610 
       
  1611 		if (v->u.air.targetairport == st->index && v->u.air.state != FLYING) return CMD_ERROR;
       
  1612 	}
       
  1613 
  1603 	BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
  1614 	BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
  1604 		if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR;
  1615 		if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR;
  1605 
  1616 
  1606 		if (flags & DC_EXEC) {
  1617 		if (flags & DC_EXEC) {
  1607 			DeleteAnimatedTile(tile_cur);
  1618 			DeleteAnimatedTile(tile_cur);
  1947 		} else {
  1958 		} else {
  1948 			image += relocation;
  1959 			image += relocation;
  1949 		}
  1960 		}
  1950 
  1961 
  1951 		SpriteID pal;
  1962 		SpriteID pal;
  1952 		if (_display_opt & DO_TRANS_BUILDINGS) {
  1963 		if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
  1953 			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
  1964 			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
  1954 			pal = PALETTE_TO_TRANSPARENT;
  1965 			pal = PALETTE_TO_TRANSPARENT;
  1955 		} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
  1966 		} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
  1956 			pal = palette;
  1967 			pal = palette;
  1957 		} else {
  1968 		} else {