(svn r20328) -Codechange: unify the unmovable related commands and make building lighthouses/transmitters actually happen via a command

This commit is contained in:
rubidium 2010-08-02 22:10:05 +00:00
parent f2d71c1196
commit 49cee72fa4
7 changed files with 62 additions and 32 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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();
}

View File

@ -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...

View File

@ -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)

View File

@ -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);
@ -163,6 +163,52 @@ CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1,
return cost;
}
/**
* 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
@ -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! */