Codechange: Un-bitstuff the remaining on-map commands.

This commit is contained in:
Michael Lutz 2021-11-21 23:03:44 +01:00
parent c6d7b98808
commit 58cff7b081
24 changed files with 80 additions and 96 deletions

View File

@ -2618,7 +2618,7 @@ struct CompanyWindow : Window
void OnPlaceObject(Point pt, TileIndex tile) override
{
if (Command<CMD_BUILD_OBJECT>::Post(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS, tile, OBJECT_HQ, 0, {}) && !_shift_pressed) {
if (Command<CMD_BUILD_OBJECT>::Post(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS, tile, OBJECT_HQ, 0) && !_shift_pressed) {
ResetObjectToPlace();
this->RaiseButtons();
}

View File

@ -1977,17 +1977,14 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do
* Build/Fund an industry
* @param flags of operations to conduct
* @param tile tile where industry is built
* @param p1 various bitstuffed elements
* - p1 = (bit 0 - 7) - industry type see build_industry.h and see industry.h
* - p1 = (bit 8 - 15) - first layout to try
* - p1 = (bit 16 ) - 0 = prospect, 1 = fund (only valid if current company is DEITY)
* @param p2 seed to use for desyncfree randomisations
* @param text unused
* @param it industry type see build_industry.h and see industry.h
* @param first_layout first layout to try
* @param fund false = prospect, true = fund (only valid if current company is DEITY)
* @param seed seed to use for desyncfree randomisations
* @return the cost of this operation or an error
*/
CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, IndustryType it, uint32 first_layout, bool fund, uint32 seed)
{
IndustryType it = GB(p1, 0, 8);
if (it >= NUM_INDUSTRYTYPES) return CMD_ERROR;
const IndustrySpec *indspec = GetIndustrySpec(it);
@ -2006,12 +2003,12 @@ CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, uint32 p1, uin
}
Randomizer randomizer;
randomizer.SetSeed(p2);
uint16 random_initial_bits = GB(p2, 0, 16);
randomizer.SetSeed(seed);
uint16 random_initial_bits = GB(seed, 0, 16);
uint32 random_var8f = randomizer.Next();
size_t num_layouts = indspec->layouts.size();
CommandCost ret = CommandCost(STR_ERROR_SITE_UNSUITABLE);
const bool deity_prospect = _current_company == OWNER_DEITY && !HasBit(p1, 16);
const bool deity_prospect = _current_company == OWNER_DEITY && !fund;
Industry *ind = nullptr;
if (deity_prospect || (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry())) {
@ -2041,7 +2038,7 @@ CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, uint32 p1, uin
cur_company.Restore();
}
} else {
size_t layout = GB(p1, 8, 8);
size_t layout = first_layout;
if (layout >= num_layouts) return CMD_ERROR;
/* Check subsequently each layout, starting with the given layout in p1 */
@ -2065,40 +2062,31 @@ CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, uint32 p1, uin
/**
* Change industry properties
* @param flags Type of operation.
* @param tile Unused.
* @param p1 IndustryID
* @param p2 various bitstuffed elements
* - p2 = (bit 0 - 7) - IndustryAction to perform
* - p2 = (bit 8 - 15) - IndustryControlFlags
* (only used with set control flags)
* - p2 = (bit 16 - 23) - CompanyID to set or INVALID_OWNER (available to everyone) or
* OWNER_NONE (neutral stations only) or OWNER_DEITY (no one)
* (only used with set exclusive supplier / consumer)
* @param ind_id IndustryID
* @param action IndustryAction to perform
* @param ctlflags IndustryControlFlags (only used with set control flags)
* @param company_id CompanyID to set or INVALID_OWNER (available to everyone) or
* OWNER_NONE (neutral stations only) or OWNER_DEITY (no one)
* (only used with set exclusive supplier / consumer)
* @param text - Additional industry text (only used with set text action)
* @return Empty cost or an error.
*/
CommandCost CmdIndustryCtrl(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
CommandCost CmdIndustryCtrl(DoCommandFlag flags, IndustryID ind_id, IndustryAction action, IndustryControlFlags ctlflags, Owner company_id, const std::string &text)
{
if (_current_company != OWNER_DEITY) return CMD_ERROR;
Industry *ind = Industry::GetIfValid(p1);
Industry *ind = Industry::GetIfValid(ind_id);
if (ind == nullptr) return CMD_ERROR;
auto action = static_cast<IndustryAction>(GB(p2, 0, 8));
switch (action) {
case IndustryAction::SetControlFlags: {
IndustryControlFlags ctlflags = (IndustryControlFlags)GB(p2, 8, 8) & INDCTL_MASK;
if (flags & DC_EXEC) ind->ctlflags = ctlflags;
if (flags & DC_EXEC) ind->ctlflags = ctlflags & INDCTL_MASK;
break;
}
case IndustryAction::SetExclusiveSupplier:
case IndustryAction::SetExclusiveConsumer: {
Owner company_id = (Owner)GB(p2, 16, 8);
if (company_id != OWNER_NONE && company_id != INVALID_OWNER && company_id != OWNER_DEITY
&& !Company::IsValidID(company_id)) return CMD_ERROR;

View File

@ -11,9 +11,14 @@
#define INDUSTRY_CMD_H
#include "command_type.h"
#include "company_type.h"
#include "industry_type.h"
CommandProc CmdBuildIndustry;
CommandProc CmdIndustryCtrl;
enum class IndustryAction : byte;
enum IndustryControlFlags : byte;
CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, IndustryType it, uint32 first_layout, bool fund, uint32 seed);
CommandCost CmdIndustryCtrl(DoCommandFlag flags, IndustryID ind_id, IndustryAction action, IndustryControlFlags ctlflags, Owner company_id, const std::string &text);
DEF_CMD_TRAIT(CMD_BUILD_INDUSTRY, CmdBuildIndustry, CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION)
DEF_CMD_TRAIT(CMD_INDUSTRY_CTRL, CmdIndustryCtrl, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT)

View File

@ -228,8 +228,7 @@ void CcBuildIndustry(Commands cmd, const CommandCost &result, TileIndex tile, co
{
if (result.Succeeded()) return;
auto [tile_, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_INDUSTRY>::Args>(data);
uint8 indtype = GB(p1, 0, 8);
auto [tile_, indtype, first_layout, fund, seed] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_INDUSTRY>::Args>(data);
if (indtype < NUM_INDUSTRYTYPES) {
const IndustrySpec *indsp = GetIndustrySpec(indtype);
if (indsp->enabled) {
@ -679,7 +678,7 @@ public:
case WID_DPI_FUND_WIDGET: {
if (this->selected_type != INVALID_INDUSTRYTYPE) {
if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && GetIndustrySpec(this->selected_type)->IsRawIndustry()) {
Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, 0, this->selected_type, InteractiveRandom(), {});
Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, 0, this->selected_type, 0, false, InteractiveRandom());
this->HandleButtonClick(WID_DPI_FUND_WIDGET);
} else {
HandlePlacePushButton(this, WID_DPI_FUND_WIDGET, SPR_CURSOR_INDUSTRY, HT_RECT);
@ -716,13 +715,13 @@ public:
Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
_ignore_restrictions = true;
Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, &CcBuildIndustry, tile, (layout_index << 8) | this->selected_type, seed, {});
Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, &CcBuildIndustry, tile, this->selected_type, layout_index, false, seed);
cur_company.Restore();
old_generating_world.Restore();
_ignore_restrictions = false;
} else {
success = Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, tile, (layout_index << 8) | this->selected_type, seed, {});
success = Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, tile, this->selected_type, layout_index, false, seed);
}
/* If an industry has been built, just reset the cursor and the system */

View File

@ -199,18 +199,15 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags);
* Build an object object
* @param flags type of operation
* @param tile tile where the object will be located
* @param p1 the object type to build
* @param p2 the view for the object
* @param text unused
* @param type the object type to build
* @param view the view for the object
* @return the cost of this operation or an error
*/
CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type, uint8 view)
{
CommandCost cost(EXPENSES_CONSTRUCTION);
ObjectType type = (ObjectType)GB(p1, 0, 16);
if (type >= NUM_OBJECTS) return CMD_ERROR;
uint8 view = GB(p2, 0, 2);
const ObjectSpec *spec = ObjectSpec::Get(type);
if (_game_mode == GM_NORMAL && !spec->IsAvailable() && !_generating_world) return CMD_ERROR;
if ((_game_mode == GM_EDITOR || _generating_world) && !spec->WasEverAvailable()) return CMD_ERROR;
@ -777,7 +774,7 @@ void GenerateObjects()
default:
uint8 view = RandomRange(spec->views);
if (CmdBuildObject(DC_EXEC | DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, RandomTile(), i, view, {}).Succeeded()) amount--;
if (CmdBuildObject(DC_EXEC | DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, RandomTile(), i, view).Succeeded()) amount--;
break;
}
}

View File

@ -11,8 +11,9 @@
#define OBJECT_CMD_H
#include "command_type.h"
#include "object_type.h"
CommandProc CmdBuildObject;
CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type, uint8 view);
DEF_CMD_TRAIT(CMD_BUILD_OBJECT, CmdBuildObject, CMD_DEITY | CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION)

View File

@ -544,7 +544,7 @@ public:
{
ObjectClass *objclass = ObjectClass::Get(_selected_object_class);
Command<CMD_BUILD_OBJECT>::Post(STR_ERROR_CAN_T_BUILD_OBJECT, CcTerraform,
tile, objclass->GetSpec(_selected_object_index)->Index(), _selected_object_view, {});
tile, objclass->GetSpec(_selected_object_index)->Index(), _selected_object_view);
}
void OnPlaceObjectAbort() override

View File

@ -252,7 +252,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, ::IsValidTile(tile));
return ScriptObject::Command<CMD_BUILD_OBJECT>::Do(tile, OBJECT_HQ, 0, {});
return ScriptObject::Command<CMD_BUILD_OBJECT>::Do(tile, OBJECT_HQ, 0);
}
/* static */ TileIndex ScriptCompany::GetCompanyHQ(CompanyID company)

View File

@ -60,7 +60,7 @@
}
EnforcePrecondition(false, IsValidIndustry(industry_id));
return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(0, industry_id, static_cast<uint32>(IndustryAction::SetText), std::string{ encoded_text ? encoded_text : "" });
return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(industry_id, IndustryAction::SetText, INDCTL_NONE, INVALID_OWNER, std::string{ encoded_text ? encoded_text : "" });
}
/* static */ ScriptIndustry::CargoAcceptState ScriptIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id)
@ -258,7 +258,7 @@ bool ScriptIndustry::SetControlFlags(IndustryID industry_id, uint32 control_flag
if (ScriptObject::GetCompany() != OWNER_DEITY) return false;
if (!IsValidIndustry(industry_id)) return false;
return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(0, industry_id, 0 | ((control_flags & ::INDCTL_MASK) << 8), {});
return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(industry_id, IndustryAction::SetControlFlags, (::IndustryControlFlags)control_flags & ::INDCTL_MASK, INVALID_OWNER, {});
}
/* static */ ScriptCompany::CompanyID ScriptIndustry::GetExclusiveSupplier(IndustryID industry_id)
@ -277,7 +277,7 @@ bool ScriptIndustry::SetControlFlags(IndustryID industry_id, uint32 control_flag
auto company = ScriptCompany::ResolveCompanyID(company_id);
::Owner owner = (company == ScriptCompany::COMPANY_INVALID ? ::INVALID_OWNER : (::Owner)company);
return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(0, industry_id, 1 | (((uint8)owner) << 16), {});
return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(industry_id, IndustryAction::SetExclusiveSupplier, INDCTL_NONE, owner, {});
}
/* static */ ScriptCompany::CompanyID ScriptIndustry::GetExclusiveConsumer(IndustryID industry_id)
@ -296,5 +296,5 @@ bool ScriptIndustry::SetControlFlags(IndustryID industry_id, uint32 control_flag
auto company = ScriptCompany::ResolveCompanyID(company_id);
::Owner owner = (company == ScriptCompany::COMPANY_INVALID ? ::INVALID_OWNER : (::Owner)company);
return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(0, industry_id, 2 | (((uint8)owner) << 16), {});
return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(industry_id, IndustryAction::SetExclusiveConsumer, INDCTL_NONE, owner, {});
}

View File

@ -123,7 +123,7 @@
uint32 seed = ::InteractiveRandom();
uint32 layout_index = ::InteractiveRandomRange((uint32)::GetIndustrySpec(industry_type)->layouts.size());
return ScriptObject::Command<CMD_BUILD_INDUSTRY>::Do(tile, (1 << 16) | (layout_index << 8) | industry_type, seed, {});
return ScriptObject::Command<CMD_BUILD_INDUSTRY>::Do(tile, industry_type, layout_index, true, seed);
}
/* static */ bool ScriptIndustryType::ProspectIndustry(IndustryType industry_type)
@ -131,7 +131,7 @@
EnforcePrecondition(false, CanProspectIndustry(industry_type));
uint32 seed = ::InteractiveRandom();
return ScriptObject::Command<CMD_BUILD_INDUSTRY>::Do(0, industry_type, seed, {});
return ScriptObject::Command<CMD_BUILD_INDUSTRY>::Do(0, industry_type, 0, false, seed);
}
/* static */ bool ScriptIndustryType::IsBuiltOnWater(IndustryType industry_type)

View File

@ -42,5 +42,5 @@
EnforcePrecondition(false, IsValidObjectType(object_type));
EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
return ScriptObject::Command<CMD_BUILD_OBJECT>::Do(tile, object_type, view, {});
return ScriptObject::Command<CMD_BUILD_OBJECT>::Do(tile, object_type, view);
}

View File

@ -42,7 +42,7 @@
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
return ScriptObject::Command<CMD_RENAME_SIGN>::Do(0, sign_id, 0, text);
return ScriptObject::Command<CMD_RENAME_SIGN>::Do(sign_id, text);
}
/* static */ char *ScriptSign::GetName(SignID sign_id)
@ -64,7 +64,7 @@
/* static */ bool ScriptSign::RemoveSign(SignID sign_id)
{
EnforcePrecondition(false, IsValidSign(sign_id));
return ScriptObject::Command<CMD_RENAME_SIGN>::Do(0, sign_id, 0, "");
return ScriptObject::Command<CMD_RENAME_SIGN>::Do(sign_id, "");
}
/* static */ SignID ScriptSign::BuildSign(TileIndex location, Text *name)
@ -77,7 +77,7 @@
EnforcePreconditionEncodedText(INVALID_SIGN, text);
EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
if (!ScriptObject::Command<CMD_PLACE_SIGN>::Do(&ScriptInstance::DoCommandReturnSignID, location, 0, 0, text)) return INVALID_SIGN;
if (!ScriptObject::Command<CMD_PLACE_SIGN>::Do(&ScriptInstance::DoCommandReturnSignID, location, text)) return INVALID_SIGN;
/* In case of test-mode, we return SignID 0 */
return 0;

View File

@ -287,7 +287,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, ::IsValidTile(tile));
return ScriptObject::Command<CMD_PLANT_TREE>::Do(tile, TREE_INVALID, tile, {});
return ScriptObject::Command<CMD_PLANT_TREE>::Do(tile, tile, TREE_INVALID);
}
/* static */ bool ScriptTile::PlantTreeRectangle(TileIndex tile, uint width, uint height)
@ -298,7 +298,7 @@
EnforcePrecondition(false, height >= 1 && height <= 20);
TileIndex end_tile = tile + ::TileDiffXY(width - 1, height - 1);
return ScriptObject::Command<CMD_PLANT_TREE>::Do(tile, TREE_INVALID, end_tile, {});
return ScriptObject::Command<CMD_PLANT_TREE>::Do(tile, end_tile, TREE_INVALID);
}
/* static */ bool ScriptTile::IsWithinTownInfluence(TileIndex tile, TownID town_id)

View File

@ -31,7 +31,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
return ScriptObject::Command<CMD_SCROLL_VIEWPORT>::Do(tile, VST_EVERYONE, 0, {});
return ScriptObject::Command<CMD_SCROLL_VIEWPORT>::Do(tile, VST_EVERYONE, 0);
}
/* static */ bool ScriptViewport::ScrollCompanyClientsTo(ScriptCompany::CompanyID company, TileIndex tile)
@ -42,7 +42,7 @@
company = ScriptCompany::ResolveCompanyID(company);
EnforcePrecondition(false, company != ScriptCompany::COMPANY_INVALID);
return ScriptObject::Command<CMD_SCROLL_VIEWPORT>::Do(tile, VST_COMPANY, company, {});
return ScriptObject::Command<CMD_SCROLL_VIEWPORT>::Do(tile, VST_COMPANY, company);
}
/* static */ bool ScriptViewport::ScrollClientTo(ScriptClient::ClientID client, TileIndex tile)
@ -54,5 +54,5 @@
client = ScriptClient::ResolveClientID(client);
EnforcePrecondition(false, client != ScriptClient::CLIENT_INVALID);
return ScriptObject::Command<CMD_SCROLL_VIEWPORT>::Do(tile, VST_CLIENT, client, {});
return ScriptObject::Command<CMD_SCROLL_VIEWPORT>::Do(tile, VST_CLIENT, client);
}

View File

@ -32,12 +32,10 @@ SignID _new_sign_id;
* but everybody is able to rename/remove it.
* @param tile tile to place sign at
* @param flags type of operation
* @param p1 unused
* @param p2 unused
* @param text unused
* @param text contents of the sign
* @return the cost of this operation or an error
*/
CommandCost CmdPlaceSign(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
CommandCost CmdPlaceSign(DoCommandFlag flags, TileIndex tile, const std::string &text)
{
/* Try to locate a new sign */
if (!Sign::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_SIGNS);
@ -69,16 +67,14 @@ CommandCost CmdPlaceSign(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
* Rename a sign. If the new name of the sign is empty, we assume
* the user wanted to delete it. So delete it. Ownership of signs
* has no meaning/effect whatsoever except for eyecandy
* @param tile unused
* @param flags type of operation
* @param p1 index of the sign to be renamed/removed
* @param p2 unused
* @param sign_id index of the sign to be renamed/removed
* @param text the new name or an empty string when resetting to the default
* @return the cost of this operation or an error
*/
CommandCost CmdRenameSign(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
CommandCost CmdRenameSign(DoCommandFlag flags, SignID sign_id, const std::string &text)
{
Sign *si = Sign::GetIfValid(p1);
Sign *si = Sign::GetIfValid(sign_id);
if (si == nullptr) return CMD_ERROR;
if (!CompanyCanRenameSign(si)) return CMD_ERROR;
@ -132,5 +128,5 @@ void CcPlaceSign(Commands cmd, const CommandCost &result, TileIndex tile, const
*/
void PlaceProc_Sign(TileIndex tile)
{
Command<CMD_PLACE_SIGN>::Post(STR_ERROR_CAN_T_PLACE_SIGN_HERE, CcPlaceSign, tile, 0, 0, {});
Command<CMD_PLACE_SIGN>::Post(STR_ERROR_CAN_T_PLACE_SIGN_HERE, CcPlaceSign, tile, {});
}

View File

@ -11,9 +11,10 @@
#define SIGNS_CMD_H
#include "command_type.h"
#include "signs_type.h"
CommandProc CmdPlaceSign;
CommandProc CmdRenameSign;
CommandCost CmdPlaceSign(DoCommandFlag flags, TileIndex tile, const std::string &text);
CommandCost CmdRenameSign(DoCommandFlag flags, SignID sign_id, const std::string &text);
DEF_CMD_TRAIT(CMD_PLACE_SIGN, CmdPlaceSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT)
DEF_CMD_TRAIT(CMD_RENAME_SIGN, CmdRenameSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT)

View File

@ -414,7 +414,7 @@ Window *ShowSignList()
static bool RenameSign(SignID index, const char *text)
{
bool remove = StrEmpty(text);
Command<CMD_RENAME_SIGN>::Post(StrEmpty(text) ? STR_ERROR_CAN_T_DELETE_SIGN : STR_ERROR_CAN_T_CHANGE_SIGN_NAME, 0, index, 0, text);
Command<CMD_RENAME_SIGN>::Post(StrEmpty(text) ? STR_ERROR_CAN_T_DELETE_SIGN : STR_ERROR_CAN_T_CHANGE_SIGN_NAME, index, text);
return remove;
}

View File

@ -243,7 +243,7 @@ struct TerraformToolbarWindow : Window {
break;
case WID_TT_BUY_LAND: // Buy land button
Command<CMD_BUILD_OBJECT>::Post(STR_ERROR_CAN_T_PURCHASE_THIS_LAND, CcPlaySound_CONSTRUCTION_RAIL, tile, OBJECT_OWNED_LAND, 0, {});
Command<CMD_BUILD_OBJECT>::Post(STR_ERROR_CAN_T_PURCHASE_THIS_LAND, CcPlaySound_CONSTRUCTION_RAIL, tile, OBJECT_OWNED_LAND, 0);
break;
case WID_TT_PLACE_SIGN: // Place sign button

View File

@ -382,25 +382,23 @@ void GenerateTrees()
* Plant a tree.
* @param flags type of operation
* @param tile end tile of area-drag
* @param p1 tree type, TREE_INVALID means random.
* @param p2 start tile of area-drag of tree plantation
* @param text unused
* @param start_tile start tile of area-drag of tree plantation
* @param tree_to_plant tree type, TREE_INVALID means random.
* @return the cost of this operation or an error
*/
CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, byte tree_to_plant)
{
StringID msg = INVALID_STRING_ID;
CommandCost cost(EXPENSES_OTHER);
const byte tree_to_plant = GB(p1, 0, 8); // We cannot use Extract as min and max are climate specific.
if (p2 >= MapSize()) return CMD_ERROR;
if (start_tile >= MapSize()) return CMD_ERROR;
/* Check the tree type within the current climate */
if (tree_to_plant != TREE_INVALID && !IsInsideBS(tree_to_plant, _tree_base_by_landscape[_settings_game.game_creation.landscape], _tree_count_by_landscape[_settings_game.game_creation.landscape])) return CMD_ERROR;
Company *c = (_game_mode != GM_EDITOR) ? Company::GetIfValid(_current_company) : nullptr;
int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16));
TileArea ta(tile, (TileIndex)p2);
TileArea ta(tile, start_tile);
for (TileIndex current_tile : ta) {
switch (GetTileType(current_tile)) {
case MP_TREES:

View File

@ -12,7 +12,7 @@
#include "command_type.h"
CommandProc CmdPlantTree;
CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, byte tree_to_plant);
DEF_CMD_TRAIT(CMD_PLANT_TREE, CmdPlantTree, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION)

View File

@ -231,7 +231,7 @@ public:
TileIndex tile = TileVirtXY(pt.x, pt.y);
if (this->mode == PM_NORMAL) {
Command<CMD_PLANT_TREE>::Post(tile, this->tree_to_plant, tile, {});
Command<CMD_PLANT_TREE>::Post(tile, tile, this->tree_to_plant);
} else {
this->DoPlantForest(tile);
}
@ -241,7 +241,7 @@ public:
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
{
if (_game_mode != GM_EDITOR && this->mode == PM_NORMAL && pt.x != -1 && select_proc == DDSP_PLANT_TREES) {
Command<CMD_PLANT_TREE>::Post(STR_ERROR_CAN_T_PLANT_TREE_HERE, end_tile, this->tree_to_plant, start_tile, {});
Command<CMD_PLANT_TREE>::Post(STR_ERROR_CAN_T_PLANT_TREE_HERE, end_tile, start_tile, this->tree_to_plant);
}
}

View File

@ -3468,23 +3468,21 @@ void InitializeSpriteSorter()
* Scroll players main viewport.
* @param flags type of operation
* @param tile tile to center viewport on
* @param p1 ViewportScrollTarget of scroll target
* @param p2 company or client id depending on the target
* @param text unused
* @param target ViewportScrollTarget of scroll target
* @param ref company or client id depending on the target
* @return the cost of this operation or an error
*/
CommandCost CmdScrollViewport(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
CommandCost CmdScrollViewport(DoCommandFlag flags, TileIndex tile, ViewportScrollTarget target, uint32 ref)
{
if (_current_company != OWNER_DEITY) return CMD_ERROR;
ViewportScrollTarget target = (ViewportScrollTarget)p1;
switch (target) {
case VST_EVERYONE:
break;
case VST_COMPANY:
if (_local_company != (CompanyID)p2) return CommandCost();
if (_local_company != (CompanyID)ref) return CommandCost();
break;
case VST_CLIENT:
if (_network_own_client_id != (ClientID)p2) return CommandCost();
if (_network_own_client_id != (ClientID)ref) return CommandCost();
break;
default:
return CMD_ERROR;

View File

@ -11,8 +11,9 @@
#define VIEWPORT_CMD_H
#include "command_type.h"
#include "viewport_type.h"
CommandProc CmdScrollViewport;
CommandCost CmdScrollViewport(DoCommandFlag flags, TileIndex tile, ViewportScrollTarget target, uint32 ref);
DEF_CMD_TRAIT(CMD_SCROLL_VIEWPORT, CmdScrollViewport, CMD_DEITY, CMDT_OTHER_MANAGEMENT)

View File

@ -146,7 +146,7 @@ enum ViewportDragDropSelectionProcess {
/**
* Target of the viewport scrolling GS method
*/
enum ViewportScrollTarget {
enum ViewportScrollTarget : byte {
VST_EVERYONE, ///< All players
VST_COMPANY, ///< All players in specific company
VST_CLIENT, ///< Single player