1
0
Fork 0

Compare commits

..

3 Commits

Author SHA1 Message Date
Tyler Trahan f3cd0bdf2f
Merge 1e1b2c8037 into 7c8759552a 2025-07-28 04:50:33 +00:00
Tyler Trahan 1e1b2c8037 Change: Convert house placer protection buttons to a single toggle 2025-07-21 14:18:29 -04:00
Tyler Trahan 632029e277 Feature: House placer mode to overbuild existing houses 2025-07-21 14:18:29 -04:00
5 changed files with 18 additions and 18 deletions

View File

@ -2862,8 +2862,8 @@ STR_HOUSE_PICKER_CLASS_ZONE5 :Town centre
STR_HOUSE_PICKER_PROTECT :Prevent upgrades
STR_HOUSE_PICKER_PROTECT_TOOLTIP :Choose whether this house will be protected from replacement as the town grows
STR_HOUSE_PICKER_REPLACE :Replace existing
STR_HOUSE_PICKER_REPLACE_TOOLTIP :Choose whether to automatically remove an existing house on the tile where this house is placed
STR_HOUSE_PICKER_OVERBUILD :Overbuild existing
STR_HOUSE_PICKER_OVERBUILD_TOOLTIP :Choose whether to automatically remove an existing house on the tile where this house is placed
STR_STATION_CLASS_DFLT :Default
STR_STATION_CLASS_DFLT_STATION :Default station

View File

@ -2894,10 +2894,10 @@ static bool TryBuildTownHouse(Town *t, TileIndex tile, TownExpandModes modes)
* @param tile Tile on which to place the house.
* @param HouseID The HouseID of the house spec.
* @param is_protected Whether the house is protected from the town upgrading it.
* @param replace Whether to automatically demolish an existing house on this tile, if present.
* @param overbuild Whether to automatically demolish an existing house on this tile, if present.
* @return Empty cost or an error.
*/
CommandCost CmdPlaceHouse(DoCommandFlags flags, TileIndex tile, HouseID house, bool is_protected, bool replace)
CommandCost CmdPlaceHouse(DoCommandFlags flags, TileIndex tile, HouseID house, bool is_protected, bool overbuild)
{
if (_game_mode != GM_EDITOR && _settings_game.economy.place_houses == PH_FORBIDDEN) return CMD_ERROR;
@ -2930,16 +2930,16 @@ CommandCost CmdPlaceHouse(DoCommandFlags flags, TileIndex tile, HouseID house, b
/* All tiles of a multi-tile house must have the same z-level. */
if (GetTileMaxZ(subtile) != maxz) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
/* We might be replacing an existing house, otherwise check if we can clear land. */
if (!(replace && GetTileType(subtile) == MP_HOUSE)) {
/* We might be overbuilding an existing house, otherwise check if we can clear land. */
if (!(overbuild && GetTileType(subtile) == MP_HOUSE)) {
CommandCost cost = Command<CMD_LANDSCAPE_CLEAR>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, subtile);
if (!cost.Succeeded()) return cost;
}
}
if (flags.Test(DoCommandFlag::Execute)) {
/* If replacing, clear any existing houses first. */
if (replace) {
/* If overbuilding, clear any existing houses first. */
if (overbuild) {
for (const TileIndex &subtile : ta) {
if (GetTileType(subtile) == MP_HOUSE) ClearTownHouse(Town::GetByTile(subtile), subtile);
}

View File

@ -27,7 +27,7 @@ CommandCost CmdTownCargoGoal(DoCommandFlags flags, TownID town_id, TownAcceptanc
CommandCost CmdTownSetText(DoCommandFlags flags, TownID town_id, const EncodedString &text);
CommandCost CmdExpandTown(DoCommandFlags flags, TownID town_id, uint32_t grow_amount, TownExpandModes modes);
CommandCost CmdDeleteTown(DoCommandFlags flags, TownID town_id);
CommandCost CmdPlaceHouse(DoCommandFlags flags, TileIndex tile, HouseID house, bool house_protected, bool replace);
CommandCost CmdPlaceHouse(DoCommandFlags flags, TileIndex tile, HouseID house, bool house_protected, bool overbuild);
DEF_CMD_TRAIT(CMD_FOUND_TOWN, CmdFoundTown, CommandFlags({CommandFlag::Deity, CommandFlag::NoTest}), CMDT_LANDSCAPE_CONSTRUCTION) // founding random town can fail only in exec run
DEF_CMD_TRAIT(CMD_RENAME_TOWN, CmdRenameTown, CommandFlags({CommandFlag::Deity, CommandFlag::Server}), CMDT_OTHER_MANAGEMENT)

View File

@ -1629,7 +1629,7 @@ static CargoTypes GetProducedCargoOfHouse(const HouseSpec *hs)
struct BuildHouseWindow : public PickerWindow {
std::string house_info{};
static inline bool house_protected;
static inline bool replace;
static inline bool overbuild;
BuildHouseWindow(WindowDesc &desc, Window *parent) : PickerWindow(desc, parent, 0, HousePickerCallbacks::instance)
{
@ -1738,13 +1738,13 @@ struct BuildHouseWindow : public PickerWindow {
BuildHouseWindow::house_protected = !BuildHouseWindow::house_protected;
this->SetWidgetLoweredState(WID_BH_PROTECT_TOGGLE, BuildHouseWindow::house_protected);
SndClickBeep();
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
this->SetDirty();
break;
case WID_BH_REPLACE_TOGGLE:
BuildHouseWindow::replace = !BuildHouseWindow::replace;
this->SetWidgetLoweredState(WID_BH_REPLACE_TOGGLE, BuildHouseWindow::replace);
case WID_BH_OVERBUILD_TOGGLE:
BuildHouseWindow::overbuild = !BuildHouseWindow::overbuild;
this->SetWidgetLoweredState(WID_BH_OVERBUILD_TOGGLE, BuildHouseWindow::overbuild);
SndClickBeep();
this->SetDirty();
@ -1774,7 +1774,7 @@ struct BuildHouseWindow : public PickerWindow {
if (hasflag) BuildHouseWindow::house_protected = true;
this->SetWidgetLoweredState(WID_BH_PROTECT_TOGGLE, BuildHouseWindow::house_protected);
this->SetWidgetLoweredState(WID_BH_REPLACE_TOGGLE, BuildHouseWindow::replace);
this->SetWidgetLoweredState(WID_BH_OVERBUILD_TOGGLE, BuildHouseWindow::overbuild);
this->SetWidgetDisabledState(WID_BH_PROTECT_TOGGLE, hasflag);
}
@ -1782,7 +1782,7 @@ struct BuildHouseWindow : public PickerWindow {
void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
{
const HouseSpec *spec = HouseSpec::Get(HousePickerCallbacks::sel_type);
Command<CMD_PLACE_HOUSE>::Post(STR_ERROR_CAN_T_BUILD_HOUSE, CcPlaySound_CONSTRUCTION_OTHER, tile, spec->Index(), BuildHouseWindow::house_protected, BuildHouseWindow::replace);
Command<CMD_PLACE_HOUSE>::Post(STR_ERROR_CAN_T_BUILD_HOUSE, CcPlaySound_CONSTRUCTION_OTHER, tile, spec->Index(), BuildHouseWindow::house_protected, BuildHouseWindow::overbuild);
}
const IntervalTimer<TimerWindow> view_refresh_interval = {std::chrono::milliseconds(2500), [this](auto) {
@ -1813,7 +1813,7 @@ static constexpr NWidgetPart _nested_build_house_widgets[] = {
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_picker, 0), SetPadding(WidgetDimensions::unscaled.picker),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BH_INFO), SetFill(1, 1), SetMinimalTextLines(10, 0),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BH_PROTECT_TOGGLE), SetMinimalSize(60, 12), SetStringTip(STR_HOUSE_PICKER_PROTECT, STR_HOUSE_PICKER_PROTECT_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BH_REPLACE_TOGGLE), SetMinimalSize(60, 12), SetStringTip(STR_HOUSE_PICKER_REPLACE, STR_HOUSE_PICKER_REPLACE_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BH_OVERBUILD_TOGGLE), SetMinimalSize(60, 12), SetStringTip(STR_HOUSE_PICKER_OVERBUILD, STR_HOUSE_PICKER_OVERBUILD_TOOLTIP),
EndContainer(),
EndContainer(),
EndContainer(),

View File

@ -78,7 +78,7 @@ enum TownFoundingWidgets : WidgetID {
enum BuildHouseWidgets : WidgetID {
WID_BH_INFO, ///< Information panel of selected house.
WID_BH_PROTECT_TOGGLE, ///< Button to toggle protecting the next house built.
WID_BH_REPLACE_TOGGLE, ///< Button to toggle replacing existing houses.
WID_BH_OVERBUILD_TOGGLE, ///< Button to toggle overbuilding existing houses.
};
#endif /* WIDGETS_TOWN_WIDGET_H */