summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/table/unmovable_land.h10
-rw-r--r--src/unmovable_cmd.cpp127
2 files changed, 53 insertions, 84 deletions
diff --git a/src/table/unmovable_land.h b/src/table/unmovable_land.h
index 5acc8ca11..e91e9dfc4 100644
--- a/src/table/unmovable_land.h
+++ b/src/table/unmovable_land.h
@@ -125,9 +125,9 @@ static const DrawTileSprites _unmovable_hq[] = {
/** Specification of the original unmovable structures. */
static const UnmovableSpec _original_unmovable[] = {
- { STR_LAI_UNMOVABLE_DESCRIPTION_TRANSMITTER, 0x11, 1, 1, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_REQUIRE_FLAT },
- { STR_LAI_UNMOVABLE_DESCRIPTION_LIGHTHOUSE, 0x11, 1, 1, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_REQUIRE_FLAT },
- { STR_TOWN_BUILDING_NAME_STATUE_1, 0x11, 1, 1, OBJECT_FLAG_CANNOT_REMOVE },
- { STR_LAI_UNMOVABLE_DESCRIPTION_COMPANY_OWNED_LAND, 0x11, 10, 2, OBJECT_FLAG_AUTOREMOVE | OBJECT_FLAG_CLEAR_INCOME | OBJECT_FLAG_HAS_NO_FOUNDATION | OBJECT_FLAG_ALLOW_UNDER_BRIDGE },
- { STR_LAI_UNMOVABLE_DESCRIPTION_COMPANY_HEADQUARTERS, 0x22, 1, 1, OBJECT_FLAG_CANNOT_REMOVE },
+ { STR_LAI_UNMOVABLE_DESCRIPTION_TRANSMITTER, 0x11, 1, 1, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_REQUIRE_FLAT | OBJECT_FLAG_ONLY_IN_SCENEDIT },
+ { STR_LAI_UNMOVABLE_DESCRIPTION_LIGHTHOUSE, 0x11, 1, 1, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_REQUIRE_FLAT | OBJECT_FLAG_ONLY_IN_SCENEDIT },
+ { STR_TOWN_BUILDING_NAME_STATUE_1, 0x11, 1, 1, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_ONLY_IN_GAME | OBJECT_FLAG_ONLY_IN_SCENEDIT }, // Yes, we disallow building this everywhere. Happens in "special" case!
+ { STR_LAI_UNMOVABLE_DESCRIPTION_COMPANY_OWNED_LAND, 0x11, 10, 2, OBJECT_FLAG_AUTOREMOVE | OBJECT_FLAG_ONLY_IN_GAME | OBJECT_FLAG_CLEAR_INCOME | OBJECT_FLAG_HAS_NO_FOUNDATION | OBJECT_FLAG_ALLOW_UNDER_BRIDGE },
+ { STR_LAI_UNMOVABLE_DESCRIPTION_COMPANY_HEADQUARTERS, 0x22, 1, 1, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_ONLY_IN_GAME },
};
diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp
index d83e2c843..ec08b4096 100644
--- a/src/unmovable_cmd.cpp
+++ b/src/unmovable_cmd.cpp
@@ -128,112 +128,81 @@ void UpdateCompanyHQ(TileIndex tile, uint score)
extern CommandCost CheckFlatLand(TileArea tile_area, DoCommandFlag flags);
/**
- * 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
+ * Build an unmovable object
+ * @param tile tile where the object will be located
* @param flags type of operation
- * @param p1 unused
+ * @param p1 the object type to build
* @param p2 unused
* @param text unused
* @return the cost of this operation or an error
*/
-static CommandCost CmdBuildCompanyHQ(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
+CommandCost CmdBuildUnmovable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- Company *c = Company::Get(_current_company);
CommandCost cost(EXPENSES_PROPERTY);
- cost = CheckFlatLand(TileArea(tile, 2, 2), flags);
- if (cost.Failed()) return cost;
-
- if (c->location_of_HQ != INVALID_TILE) { // Moving HQ
- cost.AddCost(DestroyCompanyHQ(_current_company, flags));
- }
-
- if (flags & DC_EXEC) {
- int score = UpdateCompanyRatingAndValue(c, false);
+ UnmovableType type = (UnmovableType)GB(p1, 0, 8);
+ if (type >= UNMOVABLE_MAX) return CMD_ERROR;
- c->location_of_HQ = tile;
+ const UnmovableSpec *spec = UnmovableSpec::Get(type);
+ if (spec->flags & OBJECT_FLAG_ONLY_IN_SCENEDIT && _game_mode != GM_EDITOR) return CMD_ERROR;
+ if (spec->flags & OBJECT_FLAG_ONLY_IN_GAME && (_game_mode != GM_NORMAL || _current_company > MAX_COMPANIES)) return CMD_ERROR;
- BuildUnmovable(UNMOVABLE_HQ, tile, _current_company);
+ int size_x = GB(spec->size, 0, 4);
+ int size_y = GB(spec->size, 4, 4);
+ TileArea ta(tile, size_x, size_y);
- UpdateCompanyHQ(tile, score);
- SetWindowDirty(WC_COMPANY, c->index);
+ if (spec->flags & OBJECT_FLAG_REQUIRE_FLAT) {
+ TILE_AREA_LOOP(tile_cur, ta) {
+ if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
+ }
}
- return cost;
-}
-
-/**
- * Purchase a land area. Actually you only purchase one tile, so
- * the name is a bit confusing ;p
- * @param tile the tile the company is purchasing
- * @param flags for this command type
- * @param p1 unused
- * @param p2 unused
- * @param text unused
- * @return the cost of this operation or an error
- */
-static CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
-{
- CommandCost cost(EXPENSES_CONSTRUCTION);
-
- if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_company)) {
- return_cmd_error(STR_ERROR_YOU_ALREADY_OWN_IT);
+ /* If we require flat land, we've already tested that.
+ * So we only need to check for clear land. */
+ if (spec->flags & (OBJECT_FLAG_HAS_NO_FOUNDATION | OBJECT_FLAG_REQUIRE_FLAT)) {
+ TILE_AREA_LOOP(tile_cur, ta) {
+ cost.AddCost(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR));
+ }
+ } else {
+ cost.AddCost(CheckFlatLand(ta, flags));
}
-
- cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (cost.Failed()) return cost;
- if (flags & DC_EXEC) {
- BuildUnmovable(UNMOVABLE_OWNED_LAND, tile, _current_company);
- MarkTileDirtyByTile(tile);
- }
-
- cost.AddCost(UnmovableSpec::Get(UNMOVABLE_OWNED_LAND)->GetBuildCost());
- 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);
+ int hq_score = 0;
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;
+ case UNMOVABLE_OWNED_LAND:
+ if (IsTileType(tile, MP_UNMOVABLE) &&
+ IsTileOwner(tile, _current_company) &&
+ IsOwnedLand(tile)) {
+ return_cmd_error(STR_ERROR_YOU_ALREADY_OWN_IT);
+ }
+ break;
- if (_game_mode != GM_EDITOR) return CMD_ERROR;
+ case UNMOVABLE_HQ: {
+ Company *c = Company::Get(_current_company);
+ if (c->location_of_HQ != INVALID_TILE) { // Moving HQ
+ cost.AddCost(DestroyCompanyHQ(_current_company, flags));
+ }
if (flags & DC_EXEC) {
- BuildUnmovable(type, tile);
- MarkTileDirtyByTile(tile);
+ hq_score = UpdateCompanyRatingAndValue(c, false);
+ c->location_of_HQ = tile;
+ SetWindowDirty(WC_COMPANY, c->index);
}
break;
+ }
- case UNMOVABLE_OWNED_LAND:
- cost = CmdPurchaseLandArea(tile, flags, 0, 0, NULL);
- break;
+ default: break;
+ }
- case UNMOVABLE_HQ: {
- cost = CmdBuildCompanyHQ(tile, flags, 0, 0, NULL);
- break;
- }
+ if (flags & DC_EXEC) {
+ BuildUnmovable(type, tile);
- case UNMOVABLE_STATUE: // Statues have their own construction due to their town reference.
- default: return CMD_ERROR;
+ /* Make sure the HQ starts at the right size. */
+ if (type == UNMOVABLE_HQ) UpdateCompanyHQ(tile, hq_score);
}
+ cost.AddCost(UnmovableSpec::Get(type)->GetBuildCost() * size_x * size_y);
return cost;
}