src/town_cmd.cpp
changeset 8230 64f28fe2d5c8
parent 8224 c5a64d87cc54
child 8232 a4883a0598db
equal deleted inserted replaced
8229:00e7467ceeee 8230:64f28fe2d5c8
   500 }
   500 }
   501 
   501 
   502 static CommandCost ClearTile_Town(TileIndex tile, byte flags)
   502 static CommandCost ClearTile_Town(TileIndex tile, byte flags)
   503 {
   503 {
   504 	int rating;
   504 	int rating;
   505 	CommandCost cost;
   505 	CommandCost cost(EXPENSES_CONSTRUCTION);
   506 	Town *t;
   506 	Town *t;
   507 	HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
   507 	HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
   508 
   508 
   509 	if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
   509 	if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
   510 	if (!CanDeleteHouse(tile)) return CMD_ERROR;
   510 	if (!CanDeleteHouse(tile)) return CMD_ERROR;
  1494 
  1494 
  1495 	/* Only in the scenario editor */
  1495 	/* Only in the scenario editor */
  1496 	if (_game_mode != GM_EDITOR) return CMD_ERROR;
  1496 	if (_game_mode != GM_EDITOR) return CMD_ERROR;
  1497 	if (p2 > TSM_CITY) return CMD_ERROR;
  1497 	if (p2 > TSM_CITY) return CMD_ERROR;
  1498 
  1498 
  1499 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
       
  1500 
       
  1501 	/* Check if too close to the edge of map */
  1499 	/* Check if too close to the edge of map */
  1502 	if (DistanceFromEdge(tile) < 12)
  1500 	if (DistanceFromEdge(tile) < 12)
  1503 		return_cmd_error(STR_0237_TOO_CLOSE_TO_EDGE_OF_MAP);
  1501 		return_cmd_error(STR_0237_TOO_CLOSE_TO_EDGE_OF_MAP);
  1504 
  1502 
  1505 	/* Can only build on clear flat areas, possibly with trees. */
  1503 	/* Can only build on clear flat areas, possibly with trees. */
  2095  * @param p1 town to do the action at
  2093  * @param p1 town to do the action at
  2096  * @param p2 action to perform, @see _town_action_proc for the list of available actions
  2094  * @param p2 action to perform, @see _town_action_proc for the list of available actions
  2097  */
  2095  */
  2098 CommandCost CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  2096 CommandCost CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  2099 {
  2097 {
  2100 	CommandCost cost;
       
  2101 	Town *t;
  2098 	Town *t;
  2102 
  2099 
  2103 	if (!IsValidTownID(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR;
  2100 	if (!IsValidTownID(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR;
  2104 
  2101 
  2105 	t = GetTown(p1);
  2102 	t = GetTown(p1);
  2106 
  2103 
  2107 	if (!HasBit(GetMaskOfTownActions(NULL, _current_player, t), p2)) return CMD_ERROR;
  2104 	if (!HasBit(GetMaskOfTownActions(NULL, _current_player, t), p2)) return CMD_ERROR;
  2108 
  2105 
  2109 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
  2106 	CommandCost cost(EXPENSES_OTHER, (_price.build_industry >> 8) * _town_action_costs[p2]);
  2110 
       
  2111 	cost.AddCost((_price.build_industry >> 8) * _town_action_costs[p2]);
       
  2112 
  2107 
  2113 	if (flags & DC_EXEC) {
  2108 	if (flags & DC_EXEC) {
  2114 		_town_action_proc[p2](t);
  2109 		_town_action_proc[p2](t);
  2115 		InvalidateWindow(WC_TOWN_AUTHORITY, p1);
  2110 		InvalidateWindow(WC_TOWN_AUTHORITY, p1);
  2116 	}
  2111 	}
  2362 		HouseID house = GetHouseType(tile);
  2357 		HouseID house = GetHouseType(tile);
  2363 		HouseSpec *hs = GetHouseSpecs(house);
  2358 		HouseSpec *hs = GetHouseSpecs(house);
  2364 
  2359 
  2365 		/* Here we differ from TTDP by checking TILE_NOT_SLOPED */
  2360 		/* Here we differ from TTDP by checking TILE_NOT_SLOPED */
  2366 		if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) &&
  2361 		if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) &&
  2367 			(GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) return _price.terraform;
  2362 			(GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
  2368 	}
  2363 	}
  2369 
  2364 
  2370 	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
  2365 	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
  2371 }
  2366 }
  2372 
  2367