diff options
author | rubidium <rubidium@openttd.org> | 2010-08-02 22:10:05 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-08-02 22:10:05 +0000 |
commit | 49cee72fa4af41abd2d4a3c19928fcce36b7c10d (patch) | |
tree | 1fa3703d3d95293570a1da622e487f1bc9e0140d /src | |
parent | f2d71c1196f0fcd19b54ba9c02b59369b1853508 (diff) | |
download | openttd-49cee72fa4af41abd2d4a3c19928fcce36b7c10d.tar.xz |
(svn r20328) -Codechange: unify the unmovable related commands and make building lighthouses/transmitters actually happen via a command
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/api/ai_company.cpp | 3 | ||||
-rw-r--r-- | src/command.cpp | 7 | ||||
-rw-r--r-- | src/command_type.h | 6 | ||||
-rw-r--r-- | src/company_gui.cpp | 3 | ||||
-rw-r--r-- | src/lang/english.txt | 1 | ||||
-rw-r--r-- | src/terraform_gui.cpp | 20 | ||||
-rw-r--r-- | src/unmovable_cmd.cpp | 54 |
7 files changed, 62 insertions, 32 deletions
diff --git a/src/ai/api/ai_company.cpp b/src/ai/api/ai_company.cpp index f6fe91878..f9c352d9d 100644 --- a/src/ai/api/ai_company.cpp +++ b/src/ai/api/ai_company.cpp @@ -20,6 +20,7 @@ #include "../../tile_map.h" #include "../../string_func.h" #include "../../settings_func.h" +#include "../../unmovable_type.h" #include "table/strings.h" /* static */ AICompany::CompanyID AICompany::ResolveCompanyID(AICompany::CompanyID company) @@ -162,7 +163,7 @@ { EnforcePrecondition(false, ::IsValidTile(tile)); - return AIObject::DoCommand(tile, 0, 0, CMD_BUILD_COMPANY_HQ); + return AIObject::DoCommand(tile, UNMOVABLE_HQ, 0, CMD_BUILD_UNMOVABLE); } /* static */ TileIndex AICompany::GetCompanyHQ(CompanyID company) diff --git a/src/command.cpp b/src/command.cpp index 068f8bf44..3821b37cf 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -48,7 +48,7 @@ CommandProc CmdRemoveSingleSignal; CommandProc CmdTerraformLand; -CommandProc CmdPurchaseLandArea; +CommandProc CmdBuildUnmovable; CommandProc CmdSellLandArea; CommandProc CmdBuildTunnel; @@ -95,7 +95,6 @@ CommandProc CmdRestoreOrderIndex; CommandProc CmdBuildIndustry; -CommandProc CmdBuildCompanyHQ; CommandProc CmdSetCompanyManagerFace; CommandProc CmdSetCompanyColour; @@ -210,8 +209,7 @@ static const Command _command_proc_table[] = { DEF_CMD(CmdBuildSingleSignal, CMD_AUTO), // CMD_BUILD_SIGNALS DEF_CMD(CmdRemoveSingleSignal, CMD_AUTO), // CMD_REMOVE_SIGNALS DEF_CMD(CmdTerraformLand, CMD_ALL_TILES | CMD_AUTO), // CMD_TERRAFORM_LAND - DEF_CMD(CmdPurchaseLandArea, CMD_NO_WATER | CMD_AUTO), // CMD_PURCHASE_LAND_AREA - DEF_CMD(CmdSellLandArea, 0), // CMD_SELL_LAND_AREA + DEF_CMD(CmdBuildUnmovable, CMD_NO_WATER | CMD_AUTO), // CMD_BUILD_UNMOVABLE DEF_CMD(CmdBuildTunnel, CMD_AUTO), // CMD_BUILD_TUNNEL DEF_CMD(CmdRemoveFromRailStation, 0), // CMD_REMOVE_FROM_RAIL_STATION DEF_CMD(CmdConvertRail, 0), // CMD_CONVERT_RAILD @@ -247,7 +245,6 @@ static const Command _command_proc_table[] = { DEF_CMD(CmdChangeServiceInt, 0), // CMD_CHANGE_SERVICE_INT DEF_CMD(CmdBuildIndustry, 0), // CMD_BUILD_INDUSTRY - DEF_CMD(CmdBuildCompanyHQ, CMD_NO_WATER | CMD_AUTO), // CMD_BUILD_COMPANY_HQ DEF_CMD(CmdSetCompanyManagerFace, 0), // CMD_SET_COMPANY_MANAGER_FACE DEF_CMD(CmdSetCompanyColour, 0), // CMD_SET_COMPANY_COLOUR diff --git a/src/command_type.h b/src/command_type.h index 82f5ada91..57c917b38 100644 --- a/src/command_type.h +++ b/src/command_type.h @@ -151,8 +151,7 @@ enum Commands { CMD_BUILD_SIGNALS, ///< build a signal CMD_REMOVE_SIGNALS, ///< remove a signal CMD_TERRAFORM_LAND, ///< terraform a tile - CMD_PURCHASE_LAND_AREA, ///< purchase a tile - CMD_SELL_LAND_AREA, ///< sell a bought tile before + CMD_BUILD_UNMOVABLE, ///< build something unmovable CMD_BUILD_TUNNEL, ///< build a tunnel CMD_REMOVE_FROM_RAIL_STATION, ///< remove a (rectangle of) tiles from a rail station @@ -196,9 +195,8 @@ enum Commands { CMD_BUILD_INDUSTRY, ///< build a new industry - CMD_BUILD_COMPANY_HQ, ///< build the company headquarter CMD_SET_COMPANY_MANAGER_FACE, ///< set the manager's face of the company - CMD_SET_COMPANY_COLOUR, ///< set the colour of the company + CMD_SET_COMPANY_COLOUR, ///< set the colour of the company CMD_INCREASE_LOAN, ///< increase the loan from the bank CMD_DECREASE_LOAN, ///< decrease the loan from the bank diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 745bef62b..dc8ecfc22 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -30,6 +30,7 @@ #include "sprite.h" #include "company_base.h" #include "core/geometry_func.hpp" +#include "unmovable.h" #include "table/strings.h" @@ -2012,7 +2013,7 @@ struct CompanyWindow : Window virtual void OnPlaceObject(Point pt, TileIndex tile) { - if (DoCommandP(tile, 0, 0, CMD_BUILD_COMPANY_HQ | CMD_MSG(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS))) { + if (DoCommandP(tile, UNMOVABLE_HQ, 0, CMD_BUILD_UNMOVABLE | CMD_MSG(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS))) { ResetObjectToPlace(); this->RaiseButtons(); } diff --git a/src/lang/english.txt b/src/lang/english.txt index c2bc3f748..f4e73b01c 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3619,6 +3619,7 @@ STR_ERROR_TUNNEL_THROUGH_MAP_BORDER :{WHITE}Tunnel w STR_ERROR_UNABLE_TO_EXCAVATE_LAND :{WHITE}Unable to excavate land for other end of tunnel # Unmovable related errors +STR_ERROR_CAN_T_BUILD_OBJECT :{WHITE}Can't build object... STR_ERROR_OBJECT_IN_THE_WAY :{WHITE}Object in the way STR_ERROR_COMPANY_HEADQUARTERS_IN :{WHITE}... company headquarters in the way STR_ERROR_CAN_T_PURCHASE_THIS_LAND :{WHITE}Can't purchase this land area... diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index 6d38bad7e..abad08e85 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -135,7 +135,7 @@ typedef void OnButtonClick(Window *w); static void PlaceProc_BuyLand(TileIndex tile) { - DoCommandP(tile, 0, 0, CMD_PURCHASE_LAND_AREA | CMD_MSG(STR_ERROR_CAN_T_PURCHASE_THIS_LAND), CcPlaySound1E); + DoCommandP(tile, UNMOVABLE_OWNED_LAND, 0, CMD_BUILD_UNMOVABLE | CMD_MSG(STR_ERROR_CAN_T_PURCHASE_THIS_LAND), CcPlaySound1E); } void PlaceProc_DemolishArea(TileIndex tile) @@ -433,26 +433,12 @@ static void PlaceProc_RockyArea(TileIndex tile) static void PlaceProc_LightHouse(TileIndex tile) { - /* not flat || not(trees || clear without bridge above) */ - if (GetTileSlope(tile, NULL) != SLOPE_FLAT || !(IsTileType(tile, MP_TREES) || (IsTileType(tile, MP_CLEAR) && !IsBridgeAbove(tile)))) { - return; - } - - MakeLighthouse(tile); - MarkTileDirtyByTile(tile); - SndPlayTileFx(SND_1F_SPLAT, tile); + DoCommandP(tile, UNMOVABLE_LIGHTHOUSE, 0, CMD_BUILD_UNMOVABLE | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform); } static void PlaceProc_Transmitter(TileIndex tile) { - /* not flat || not(trees || clear without bridge above) */ - if (GetTileSlope(tile, NULL) != SLOPE_FLAT || !(IsTileType(tile, MP_TREES) || (IsTileType(tile, MP_CLEAR) && !IsBridgeAbove(tile)))) { - return; - } - - MakeTransmitter(tile); - MarkTileDirtyByTile(tile); - SndPlayTileFx(SND_1F_SPLAT, tile); + DoCommandP(tile, UNMOVABLE_TRANSMITTER, 0, CMD_BUILD_UNMOVABLE | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform); } static void PlaceProc_DesertArea(TileIndex tile) diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp index 403c00419..79e1a9ef5 100644 --- a/src/unmovable_cmd.cpp +++ b/src/unmovable_cmd.cpp @@ -107,7 +107,7 @@ extern CommandCost CheckFlatLand(TileArea tile_area, DoCommandFlag flags); * @param text unused * @return the cost of this operation or an error */ -CommandCost CmdBuildCompanyHQ(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) +static CommandCost CmdBuildCompanyHQ(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { Company *c = Company::Get(_current_company); CommandCost cost(EXPENSES_PROPERTY); @@ -143,7 +143,7 @@ CommandCost CmdBuildCompanyHQ(TileIndex tile, DoCommandFlag flags, uint32 p1, ui * @param text unused * @return the cost of this operation or an error */ -CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) +static CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { CommandCost cost(EXPENSES_CONSTRUCTION); @@ -164,6 +164,52 @@ CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, } /** + * Build an unmovable object + * @param tile tile where the object will be located + * @param flags type of operation + * @param p1 the object type to build + * @param p2 unused + * @param text unused + * @return the cost of this operation or an error + */ +CommandCost CmdBuildUnmovable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) +{ + CommandCost cost(EXPENSES_PROPERTY); + + UnmovableType type = (UnmovableType)GB(p1, 0, 8); + switch (type) { + case UNMOVABLE_LIGHTHOUSE: + case UNMOVABLE_TRANSMITTER: + if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED); + cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); + if (cost.Failed()) return cost; + + if (_game_mode != GM_EDITOR) return CMD_ERROR; + + if (flags & DC_EXEC) { + MakeUnmovable(tile, type, OWNER_NONE); + MarkTileDirtyByTile(tile); + } + break; + + case UNMOVABLE_OWNED_LAND: + cost = CmdPurchaseLandArea(tile, flags, 0, 0, NULL); + break; + + case UNMOVABLE_HQ: { + cost = CmdBuildCompanyHQ(tile, flags, 0, 0, NULL); + break; + } + + case UNMOVABLE_STATUE: // Statues have their own construction due to their town reference. + default: return CMD_ERROR; + } + + return cost; +} + + +/** * Sell a land area. Actually you only sell one tile, so * the name is a bit confusing ;p * @param tile the tile the company is selling @@ -173,7 +219,7 @@ CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, * @param text unused * @return the cost of this operation or an error */ -CommandCost CmdSellLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) +static CommandCost CmdSellLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { if (!IsOwnedLandTile(tile)) return CMD_ERROR; if (_current_company != OWNER_WATER) { @@ -283,7 +329,7 @@ static CommandCost ClearTile_Unmovable(TileIndex tile, DoCommandFlag flags) } if (IsOwnedLand(tile)) { - return DoCommand(tile, 0, 0, flags, CMD_SELL_LAND_AREA); + return CmdSellLandArea(tile, flags, 0, 0, NULL); } /* Water can remove everything! */ |