Changeset - r10499:570896340d7a
[Not reviewed]
master
! ! !
rubidium - 15 years ago 2008-12-28 14:37:19
rubidium@openttd.org
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
67 files changed with 373 insertions and 430 deletions:
0 comments (0 inline, 0 general)
src/ai/ai.cpp
Show inline comments
 
@@ -37,27 +37,26 @@ static void AI_DequeueCommands(CompanyID
 
	_ai_company[company].queue_tail = NULL;
 

	
 
	/* Dequeue all commands */
 
	while ((com = entry_com) != NULL) {
 
		_current_company = company;
 

	
 
		_cmd_text = com->text;
 
		DoCommandP(com->tile, com->p1, com->p2, com->callback, com->procc);
 
		DoCommandP(com->tile, com->p1, com->p2, com->cmd, com->callback, com->text);
 

	
 
		/* Free item */
 
		entry_com = com->next;
 
		free(com->text);
 
		free(com);
 
	}
 
}
 

	
 
/**
 
 * Needed for SP; we need to delay DoCommand with 1 tick, because else events
 
 *  will make infinite loops (AIScript).
 
 */
 
static void AI_PutCommandInQueue(CompanyID company, TileIndex tile, uint32 p1, uint32 p2, uint32 procc, CommandCallback* callback)
 
static void AI_PutCommandInQueue(CompanyID company, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback* callback, const char *text = NULL)
 
{
 
	AICommand *com;
 

	
 
	if (_ai_company[company].queue_tail == NULL) {
 
		/* There is no item in the queue yet, create the queue */
 
		_ai_company[company].queue = MallocT<AICommand>(1);
 
@@ -72,79 +71,66 @@ static void AI_PutCommandInQueue(Company
 
	com = _ai_company[company].queue_tail;
 

	
 
	/* Assign the info */
 
	com->tile  = tile;
 
	com->p1    = p1;
 
	com->p2    = p2;
 
	com->procc = procc;
 
	com->cmd = cmd;
 
	com->callback = callback;
 
	com->next  = NULL;
 
	com->text  = NULL;
 

	
 
	/* Copy the cmd_text, if needed */
 
	if (_cmd_text != NULL) {
 
		com->text = strdup(_cmd_text);
 
		_cmd_text = NULL;
 
	}
 
	com->text  = text == NULL ? NULL : strdup(text);
 
}
 

	
 
/**
 
 * Executes a raw DoCommand for the AI.
 
 */
 
CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 procc, CommandCallback* callback)
 
CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 cmd, CommandCallback* callback, const char *text)
 
{
 
	CompanyID old_local_company;
 
	CommandCost res;
 
	const char* tmp_cmdtext;
 

	
 
	/* If you enable DC_EXEC with DC_QUERY_COST you are a really strange
 
	 *   person.. should we check for those funny jokes?
 
	 */
 

	
 
	/* The test already resets _cmd_text, so backup the pointer */
 
	tmp_cmdtext = _cmd_text;
 

	
 
	/* First, do a test-run to see if we can do this */
 
	res = DoCommand(tile, p1, p2, flags & ~DC_EXEC, procc);
 
	res = DoCommand(tile, p1, p2, flags & ~DC_EXEC, cmd, text);
 
	/* The command failed, or you didn't want to execute, or you are quering, return */
 
	if (CmdFailed(res) || !(flags & DC_EXEC) || (flags & DC_QUERY_COST)) {
 
		return res;
 
	}
 

	
 
	/* Restore _cmd_text */
 
	_cmd_text = tmp_cmdtext;
 

	
 
	/* NetworkSend_Command needs _local_company to be set correctly, so
 
	 * adjust it, and put it back right after the function */
 
	old_local_company = _local_company;
 
	_local_company = _current_company;
 

	
 
#ifdef ENABLE_NETWORK
 
	/* Send the command */
 
	if (_networking) {
 
		/* Network is easy, send it to his handler */
 
		NetworkSend_Command(tile, p1, p2, procc, callback);
 
		NetworkSend_Command(tile, p1, p2, cmd, callback, text);
 
	} else {
 
#else
 
	{
 
#endif
 
		/* If we execute BuildCommands directly in SP, we have a big problem with events
 
		 *  so we need to delay is for 1 tick */
 
		AI_PutCommandInQueue(_current_company, tile, p1, p2, procc, callback);
 
		AI_PutCommandInQueue(_current_company, tile, p1, p2, cmd, callback, text);
 
	}
 

	
 
	/* Set _local_company back */
 
	_local_company = old_local_company;
 

	
 
	return res;
 
}
 

	
 

	
 
CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 procc)
 
CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 cmd, const char *text)
 
{
 
	return AI_DoCommandCc(tile, p1, p2, flags, procc, NULL);
 
	return AI_DoCommandCc(tile, p1, p2, flags, cmd, NULL, text);
 
}
 

	
 

	
 
/**
 
 * Run 1 tick of the AI. Don't overdo it, keep it realistic.
 
 */
src/ai/ai.h
Show inline comments
 
@@ -12,13 +12,13 @@
 

	
 
/* How DoCommands look like for an AI */
 
struct AICommand {
 
	uint32 tile;
 
	uint32 p1;
 
	uint32 p2;
 
	uint32 procc;
 
	uint32 cmd;
 
	CommandCallback *callback;
 

	
 
	char *text;
 
	uint uid;
 

	
 
	AICommand *next;
 
@@ -44,14 +44,14 @@ extern AICompany _ai_company[MAX_COMPANI
 
// ai.c
 
void AI_StartNewAI(CompanyID company);
 
void AI_CompanyDied(CompanyID company);
 
void AI_RunGameLoop();
 
void AI_Initialize();
 
void AI_Uninitialize();
 
CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
 
CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback);
 
CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, const char *text = NULL);
 
CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback, const char *text = NULL);
 

	
 
/** Is it allowed to start a new AI.
 
 * This function checks some boundries to see if we should launch a new AI.
 
 * @return True if we can start a new AI.
 
 */
 
static inline bool AI_AllowNewAI()
src/ai/default/default.cpp
Show inline comments
 
@@ -317,13 +317,13 @@ static void AiHandleGotoDepot(Company *c
 

	
 
static void AiRestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak)
 
{
 
	if (bak->order == NULL) return;
 

	
 
	for (uint i = 0; !bak->order[i].IsType(OT_NOTHING); i++) {
 
		if (!DoCommandP(0, v->index + (i << 16), bak->order[i].Pack(), NULL, CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK))
 
		if (!DoCommandP(0, v->index + (i << 16), bak->order[i].Pack(), CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK))
 
			break;
 
	}
 
}
 

	
 
static void AiHandleReplaceTrain(Company *c)
 
{
src/aircraft_cmd.cpp
Show inline comments
 
@@ -261,13 +261,13 @@ uint16 AircraftDefaultCargoCapacity(Carg
 
 * @param tile tile of depot where aircraft is built
 
 * @param flags for command
 
 * @param p1 aircraft type being built (engine)
 
 * @param p2 unused
 
 * return result of operation.  Could be cost, error
 
 */
 
CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsEngineBuildable(p1, VEH_AIRCRAFT, _current_company)) return_cmd_error(STR_AIRCRAFT_NOT_AVAILABLE);
 

	
 
	const AircraftVehicleInfo *avi = AircraftVehInfo(p1);
 
	CommandCost value = EstimateAircraftCost(p1, avi);
 

	
 
@@ -464,13 +464,13 @@ CommandCost CmdBuildAircraft(TileIndex t
 
 * @param tile unused
 
 * @param flags for command type
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 * @return result of operation.  Error or sold value
 
 */
 
CommandCost CmdSellAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSellAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
 
@@ -512,13 +512,13 @@ bool Aircraft::FindClosestDepot(TileInde
 
 * @param p1 vehicle ID to send to the hangar
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 * @return o if everything went well
 
 */
 
CommandCost CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p2 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
 
		return SendAllVehiclesToDepot(VEH_AIRCRAFT, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
 
	}
 
@@ -540,13 +540,13 @@ CommandCost CmdSendAircraftToHangar(Tile
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle (ignored)
 
 * @return cost of refit or error
 
 */
 
CommandCost CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	byte new_subtype = GB(p2, 8, 8);
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
src/airport_gui.cpp
Show inline comments
 
@@ -37,13 +37,13 @@ void CcBuildAirport(bool success, TileIn
 
		ResetObjectToPlace();
 
	}
 
}
 

	
 
static void PlaceAirport(TileIndex tile)
 
{
 
	DoCommandP(tile, _selected_airport_type, _ctrl_pressed, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE));
 
	DoCommandP(tile, _selected_airport_type, _ctrl_pressed, CMD_BUILD_AIRPORT | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE), CcBuildAirport);
 
}
 

	
 

	
 
enum {
 
	ATW_AIRPORT  = 3,
 
	ATW_DEMOLISH = 4
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -327,15 +327,13 @@ static CommandCost CopyHeadSpecificThing
 
	}
 

	
 
	/* Last do those things which do never fail (resp. we do not care about), but which are not undo-able */
 
	if (cost.Succeeded() && old_head != new_head && (flags & DC_EXEC) != 0) {
 
		/* Copy vehicle name */
 
		if (old_head->name != NULL) {
 
			_cmd_text = old_head->name;
 
			DoCommand(0, new_head->index, 0, DC_EXEC | DC_AUTOREPLACE, CMD_RENAME_VEHICLE);
 
			_cmd_text = NULL;
 
			DoCommand(0, new_head->index, 0, DC_EXEC | DC_AUTOREPLACE, CMD_RENAME_VEHICLE, old_head->name);
 
		}
 

	
 
		/* Copy other things which cannot be copied by a command and which shall not stay resetted from the build vehicle command */
 
		new_head->CopyVehicleConfigAndStatistics(old_head);
 

	
 
		/* Switch vehicle windows to the new vehicle, so they are not closed when the old vehicle is sold */
 
@@ -604,13 +602,13 @@ static CommandCost ReplaceChain(Vehicle 
 
 * Trains are replaced as a whole chain, free wagons in depot are replaced on their own
 
 * @param tile not used
 
 * @param flags type of operation
 
 * @param p1 Index of vehicle
 
 * @param p2 not used
 
 */
 
CommandCost CmdAutoreplaceVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdAutoreplaceVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0);
 
	bool nothing_to_do = true;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
	Vehicle *v = GetVehicle(p1);
src/autoreplace_gui.cpp
Show inline comments
 
@@ -367,25 +367,25 @@ public:
 
				}
 
				ShowDropDownList(this, list, sel_railtype, RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN);
 
				break;
 
			}
 

	
 
			case RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE: /* toggle renew_keep_length */
 
				DoCommandP(0, 5, GetCompany(_local_company)->renew_keep_length ? 0 : 1, NULL, CMD_SET_AUTOREPLACE);
 
				DoCommandP(0, 5, GetCompany(_local_company)->renew_keep_length ? 0 : 1, CMD_SET_AUTOREPLACE);
 
				break;
 

	
 
			case RVW_WIDGET_START_REPLACE: { /* Start replacing */
 
				EngineID veh_from = this->sel_engine[0];
 
				EngineID veh_to = this->sel_engine[1];
 
				DoCommandP(0, 3 + (this->sel_group << 16) , veh_from + (veh_to << 16), NULL, CMD_SET_AUTOREPLACE);
 
				DoCommandP(0, 3 + (this->sel_group << 16) , veh_from + (veh_to << 16), CMD_SET_AUTOREPLACE);
 
				this->SetDirty();
 
			} break;
 

	
 
			case RVW_WIDGET_STOP_REPLACE: { /* Stop replacing */
 
				EngineID veh_from = this->sel_engine[0];
 
				DoCommandP(0, 3 + (this->sel_group << 16), veh_from + (INVALID_ENGINE << 16), NULL, CMD_SET_AUTOREPLACE);
 
				DoCommandP(0, 3 + (this->sel_group << 16), veh_from + (INVALID_ENGINE << 16), CMD_SET_AUTOREPLACE);
 
				this->SetDirty();
 
			} break;
 

	
 
			case RVW_WIDGET_LEFT_MATRIX:
 
			case RVW_WIDGET_RIGHT_MATRIX: {
 
				uint i = (pt.y - 14) / this->resize.step_height;
src/bridge_gui.cpp
Show inline comments
 
@@ -91,13 +91,13 @@ private:
 
		return a->spec->speed - b->spec->speed;
 
	}
 

	
 
	void BuildBridge(uint8 i)
 
	{
 
		DoCommandP(this->end_tile, this->start_tile, this->type | this->bridges->Get(i)->index,
 
				CcBuildBridge, CMD_BUILD_BRIDGE | CMD_MSG(STR_5015_CAN_T_BUILD_BRIDGE_HERE));
 
					CMD_BUILD_BRIDGE | CMD_MSG(STR_5015_CAN_T_BUILD_BRIDGE_HERE), CcBuildBridge);
 
	}
 

	
 
	/** Sort the builable bridges */
 
	void SortBridgeList()
 
	{
 
		this->bridges->Sort();
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -1052,23 +1052,24 @@ struct BuildVehicleWindow : Window {
 
			case BUILD_VEHICLE_WIDGET_BUILD: {
 
				EngineID sel_eng = this->sel_engine;
 
				if (sel_eng != INVALID_ENGINE) {
 
					switch (this->vehicle_type) {
 
						default: NOT_REACHED();
 
						case VEH_TRAIN:
 
							DoCommandP(this->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco,
 
										CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
 
							DoCommandP(this->window_number, sel_eng, 0,
 
									CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE),
 
									(RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco);
 
							break;
 
						case VEH_ROAD:
 
							DoCommandP(this->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
 
							DoCommandP(this->window_number, sel_eng, 0, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE), CcBuildRoadVeh);
 
							break;
 
						case VEH_SHIP:
 
							DoCommandP(this->window_number, sel_eng, 0, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
 
							DoCommandP(this->window_number, sel_eng, 0, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP), CcBuildShip);
 
							break;
 
						case VEH_AIRCRAFT:
 
							DoCommandP(this->window_number, sel_eng, 0, CcBuildAircraft, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
 
							DoCommandP(this->window_number, sel_eng, 0, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT), CcBuildAircraft);
 
							break;
 
					}
 
				}
 
				break;
 
			}
 

	
 
@@ -1148,21 +1149,20 @@ struct BuildVehicleWindow : Window {
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		if (str == NULL) return;
 

	
 
		StringID err_str = STR_NULL;
 
		_cmd_text = str;
 
		switch (this->vehicle_type) {
 
			default: NOT_REACHED();
 
			case VEH_TRAIN:    err_str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break;
 
			case VEH_ROAD:     err_str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE;  break;
 
			case VEH_SHIP:     err_str = STR_9839_CAN_T_RENAME_SHIP_TYPE;     break;
 
			case VEH_AIRCRAFT: err_str = STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE; break;
 
		}
 
		DoCommandP(0, this->rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(err_str));
 
		DoCommandP(0, this->rename_engine, 0, CMD_RENAME_ENGINE | CMD_MSG(err_str), NULL, str);
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		if (this->sort_criteria != index) {
 
			this->sort_criteria = index;
src/cheat_gui.cpp
Show inline comments
 
@@ -31,13 +31,13 @@
 
 * code requires to be able to write to the variable it is not constified.
 
 */
 
static int32 _money_cheat_amount = 10000000;
 

	
 
static int32 ClickMoneyCheat(int32 p1, int32 p2)
 
{
 
	DoCommandP(0, (uint32)(p2 * _money_cheat_amount), 0, NULL, CMD_MONEY_CHEAT);
 
	DoCommandP(0, (uint32)(p2 * _money_cheat_amount), 0, CMD_MONEY_CHEAT);
 
	return _money_cheat_amount;
 
}
 

	
 
/**
 
 * @param p1 company to set to
 
 * @param p2 is -1 or +1 (down/up)
src/command.cpp
Show inline comments
 
@@ -21,25 +21,24 @@
 
#include "company_func.h"
 
#include "company_base.h"
 
#include "signal_func.h"
 

	
 
#include "table/strings.h"
 

	
 
const char *_cmd_text = NULL;
 
StringID _error_message;
 

	
 
/**
 
 * Helper macro to define the header of all command handler macros.
 
 *
 
 * This macro create the function header for a given command handler function, as
 
 * all command handler functions got the parameters from the #CommandProc callback
 
 * type.
 
 *
 
 * @param yyyy The desired function name of the new command handler function.
 
 */
 
#define DEF_COMMAND(yyyy) CommandCost yyyy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
#define DEF_COMMAND(yyyy) CommandCost yyyy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 

	
 
DEF_COMMAND(CmdBuildRailroadTrack);
 
DEF_COMMAND(CmdRemoveRailroadTrack);
 
DEF_COMMAND(CmdBuildSingleRail);
 
DEF_COMMAND(CmdRemoveSingleRail);
 

	
 
@@ -379,35 +378,32 @@ static int _docommand_recursive = 0;
 
 * Depending on the flags parameter it execute or test a command.
 
 *
 
 * @param tile The tile to apply the command on (for the #CommandProc)
 
 * @param p1 Additional data for the command (for the #CommandProc)
 
 * @param p2 Additional data for the command (for the #CommandProc)
 
 * @param flags Flags for the command and how to execute the command
 
 * @param procc The command-id to execute (a value of the CMD_* enums)
 
 * @param cmd The command-id to execute (a value of the CMD_* enums)
 
 * @see CommandProc
 
 */
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 procc)
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 cmd, const char *text)
 
{
 
	CommandCost res;
 

	
 
	/* Do not even think about executing out-of-bounds tile-commands */
 
	if (!IsValidTile(tile)) {
 
		_cmd_text = NULL;
 
		return CMD_ERROR;
 
	}
 
	if (!IsValidTile(tile)) return CMD_ERROR;
 

	
 
	CommandProc *proc = _command_proc_table[procc].proc;
 
	CommandProc *proc = _command_proc_table[cmd].proc;
 

	
 
	if (_docommand_recursive == 0) _error_message = INVALID_STRING_ID;
 

	
 
	_docommand_recursive++;
 

	
 
	/* only execute the test call if it's toplevel, or we're not execing. */
 
	if (_docommand_recursive == 1 || !(flags & DC_EXEC) ) {
 
		SetTownRatingTestMode(true);
 
		res = proc(tile, flags & ~DC_EXEC, p1, p2);
 
		res = proc(tile, flags & ~DC_EXEC, p1, p2, text);
 
		SetTownRatingTestMode(false);
 
		if (CmdFailed(res)) {
 
			res.SetGlobalErrorMessage();
 
			goto error;
 
		}
 

	
 
@@ -418,38 +414,35 @@ CommandCost DoCommand(TileIndex tile, ui
 
				!CheckCompanyHasMoney(res)) {
 
			goto error;
 
		}
 

	
 
		if (!(flags & DC_EXEC)) {
 
			_docommand_recursive--;
 
			_cmd_text = NULL;
 
			return res;
 
		}
 
	}
 

	
 
	/* Execute the command here. All cost-relevant functions set the expenses type
 
	 * themselves to the cost object at some point */
 
	res = proc(tile, flags, p1, p2);
 
	res = proc(tile, flags, p1, p2, text);
 
	if (CmdFailed(res)) {
 
		res.SetGlobalErrorMessage();
 
error:
 
		_docommand_recursive--;
 
		_cmd_text = NULL;
 
		return CMD_ERROR;
 
	}
 

	
 
	/* if toplevel, subtract the money. */
 
	if (--_docommand_recursive == 0 && !(flags & DC_BANKRUPT)) {
 
		SubtractMoneyFromCompany(res);
 
		/* XXX - Old AI hack which doesn't use DoCommandDP; update last build coord of company */
 
		/* XXX - Old AI hack which doesn't use DoCommandP; update last build coord of company */
 
		if (tile != 0 && IsValidCompanyID(_current_company)) {
 
			GetCompany(_current_company)->last_build_coordinate = tile;
 
		}
 
	}
 

	
 
	_cmd_text = NULL;
 
	return res;
 
}
 

	
 
/*!
 
 * This functions returns the money which can be used to execute a command.
 
 * This is either the money of the current company or INT64_MAX if there
 
@@ -470,58 +463,52 @@ Money GetAvailableMoneyForCommand()
 
 * tile, p1 and p2 are from the #CommandProc function. The paramater cmd is the command to execute.
 
 * The parameter my_cmd is used to indicate if the command is from a company or the server.
 
 *
 
 * @param tile The tile to perform a command on (see #CommandProc)
 
 * @param p1 Additional data for the command (see #CommandProc)
 
 * @param p2 Additional data for the command (see #CommandProc)
 
 * @param cmd The command to execute (a CMD_* value)
 
 * @param callback A callback function to call after the command is finished
 
 * @param cmd The command to execute (a CMD_* value)
 
 * @param text The text to pass
 
 * @param my_cmd indicator if the command is from a company or server (to display error messages for a user)
 
 * @return true if the command succeeded, else false
 
 */
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd, bool my_cmd)
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd)
 
{
 
	CommandCost res, res2;
 
	CommandProc *proc;
 
	uint32 flags;
 
	bool notest;
 
	StringID error_part1;
 

	
 
	int x = TileX(tile) * TILE_SIZE;
 
	int y = TileY(tile) * TILE_SIZE;
 

	
 
	/* Do not even think about executing out-of-bounds tile-commands */
 
	if (!IsValidTile(tile)) {
 
		_cmd_text = NULL;
 
		return false;
 
	}
 
	if (!IsValidTile(tile)) return false;
 

	
 
	assert(_docommand_recursive == 0);
 

	
 
	_error_message = INVALID_STRING_ID;
 
	error_part1 = GB(cmd, 16, 16);
 
	_additional_cash_required = 0;
 

	
 
	/** Spectator has no rights except for the (dedicated) server which
 
	 * is/can be a spectator but as the server it can do anything */
 
	if (_current_company == COMPANY_SPECTATOR && !_network_server) {
 
		if (my_cmd) ShowErrorMessage(_error_message, error_part1, x, y);
 
		_cmd_text = NULL;
 
		return false;
 
	}
 

	
 
	flags = 0;
 
	if (cmd & CMD_NO_WATER) flags |= DC_NO_WATER;
 

	
 
	/* get pointer to command handler */
 
	assert((cmd & 0xFF) < lengthof(_command_proc_table));
 
	proc = _command_proc_table[cmd & 0xFF].proc;
 
	if (proc == NULL) {
 
		_cmd_text = NULL;
 
		return false;
 
	}
 
	if (proc == NULL) return false;
 

	
 
	if (GetCommandFlags(cmd) & CMD_AUTO) flags |= DC_AUTO;
 

	
 
	/* Some commands have a different output in dryrun than the realrun
 
	 *  e.g.: if you demolish a whole town, the dryrun would say okay.
 
	 *  but by really destroying, your rating drops and at a certain point
 
@@ -547,32 +534,31 @@ bool DoCommandP(TileIndex tile, uint32 p
 
			_shift_pressed &&
 
			IsLocalCompany() &&
 
			!(cmd & (CMD_NETWORK_COMMAND | CMD_SHOW_NO_ERROR)) &&
 
			(cmd & 0xFF) != CMD_PAUSE) {
 
		/* estimate the cost. */
 
		SetTownRatingTestMode(true);
 
		res = proc(tile, flags, p1, p2);
 
		res = proc(tile, flags, p1, p2, text);
 
		SetTownRatingTestMode(false);
 
		if (CmdFailed(res)) {
 
			res.SetGlobalErrorMessage();
 
			ShowErrorMessage(_error_message, error_part1, x, y);
 
		} else {
 
			ShowEstimatedCostOrIncome(res.GetCost(), x, y);
 
		}
 

	
 
		_docommand_recursive = 0;
 
		_cmd_text = NULL;
 
		ClearStorageChanges(false);
 
		return false;
 
	}
 

	
 

	
 
	if (!((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) {
 
		/* first test if the command can be executed. */
 
		SetTownRatingTestMode(true);
 
		res = proc(tile, flags, p1, p2);
 
		res = proc(tile, flags, p1, p2, text);
 
		SetTownRatingTestMode(false);
 
		if (CmdFailed(res)) {
 
			res.SetGlobalErrorMessage();
 
			goto show_error;
 
		}
 
		/* no money? Only check if notest is off */
 
@@ -587,30 +573,29 @@ bool DoCommandP(TileIndex tile, uint32 p
 
	 * We also need to do this if the server's company has gone bankrupt
 
	 * @todo Rewrite (dedicated) server to something more than a dirty hack!
 
	 */
 
	if (_networking && !(cmd & CMD_NETWORK_COMMAND)) {
 
		CompanyID bck = _local_company;
 
		if (_network_dedicated || (_network_server && bck == COMPANY_SPECTATOR)) _local_company = COMPANY_FIRST;
 
		NetworkSend_Command(tile, p1, p2, cmd, callback);
 
		NetworkSend_Command(tile, p1, p2, cmd, callback, text);
 
		if (_network_dedicated || (_network_server && bck == COMPANY_SPECTATOR)) _local_company = bck;
 
		_docommand_recursive = 0;
 
		_cmd_text = NULL;
 
		ClearStorageChanges(false);
 
		return true;
 
	}
 
#endif /* ENABLE_NETWORK */
 
	DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)_current_company, tile, p1, p2, cmd, _cmd_text);
 
	DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)_current_company, tile, p1, p2, cmd, text);
 

	
 
	/* update last build coordinate of company. */
 
	if (tile != 0 && IsValidCompanyID(_current_company)) {
 
		GetCompany(_current_company)->last_build_coordinate = tile;
 
	}
 

	
 
	/* Actually try and execute the command. If no cost-type is given
 
	 * use the construction one */
 
	res2 = proc(tile, flags | DC_EXEC, p1, p2);
 
	res2 = proc(tile, flags | DC_EXEC, p1, p2, text);
 

	
 
	/* If notest is on, it means the result of the test can be different than
 
	 *  the real command.. so ignore the test */
 
	if (!notest && !((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) {
 
		assert(res.GetCost() == res2.GetCost() && CmdFailed(res) == CmdFailed(res2)); // sanity check
 
	} else {
 
@@ -634,13 +619,12 @@ bool DoCommandP(TileIndex tile, uint32 p
 
		}
 
	}
 

	
 
	_docommand_recursive = 0;
 

	
 
	if (callback) callback(true, tile, p1, p2);
 
	_cmd_text = NULL;
 
	ClearStorageChanges(true);
 
	return true;
 

	
 
show_error:
 
	/* show error message if the command fails? */
 
	if (IsLocalCompany() && error_part1 != 0 && my_cmd) {
 
@@ -648,13 +632,12 @@ show_error:
 
	}
 

	
 
callb_err:
 
	_docommand_recursive = 0;
 

	
 
	if (callback) callback(false, tile, p1, p2);
 
	_cmd_text = NULL;
 
	ClearStorageChanges(false);
 
	return false;
 
}
 

	
 

	
 
CommandCost CommandCost::AddCost(CommandCost ret)
src/command_func.h
Show inline comments
 
@@ -50,35 +50,27 @@ static const CommandCost CMD_ERROR = Com
 
 */
 
#define return_cmd_error(errcode) return CommandCost(errcode);
 

	
 
/**
 
 * Execute a command
 
 */
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 procc);
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 cmd, const char *text = NULL);
 

	
 
/**
 
 * Execute a network safe DoCommand function
 
 */
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd, bool my_cmd = true);
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = NULL, const char *text = NULL, bool my_cmd = true);
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
/**
 
 * Send a command over the network
 
 */
 
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback);
 
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text);
 
#endif /* ENABLE_NETWORK */
 

	
 
/**
 
 * Text, which gets sent with a command
 
 *
 
 * This variable contains a string (be specific a pointer of the first
 
 * char of this string) which will be send with a command. This is
 
 * used for user input data like names or chat messages.
 
 */
 
extern const char *_cmd_text;
 
extern Money _additional_cash_required;
 
extern StringID _error_message;
 

	
 
/**
 
 * Checks if a integer value belongs to a command.
 
 */
src/command_type.h
Show inline comments
 
@@ -353,15 +353,16 @@ enum {
 
 * the usage of these parameters.
 
 *
 
 * @param tile The tile to apply a command on
 
 * @param flags Flags for the command, from the DC_* enumeration
 
 * @param p1 Additional data for the command
 
 * @param p2 Additional data for the command
 
 * @param text Additional text
 
 * @return The CommandCost of the command, which can be succeeded or failed.
 
 */
 
typedef CommandCost CommandProc(TileIndex tile, uint32 flags, uint32 p1, uint32 p2);
 
typedef CommandCost CommandProc(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text);
 

	
 
/**
 
 * Define a command with the flags which belongs to it.
 
 *
 
 * This struct connect a command handler function with the flags created with
 
 * the #CMD_AUTO, #CMD_OFFLINE and #CMD_SERVER values.
src/company_cmd.cpp
Show inline comments
 
@@ -561,13 +561,13 @@ static void MaybeStartNewCompany()
 
			n < (_network_server ?
 
				InteractiveRandomRange(_settings_game.difficulty.max_no_competitors + 2) :
 
				RandomRange(_settings_game.difficulty.max_no_competitors + 2)
 
			)) {
 
		/* Send a command to all clients to start up a new AI.
 
		 * Works fine for Multiplayer and Singleplayer */
 
		DoCommandP(0, 1, 0, NULL, CMD_COMPANY_CTRL);
 
		DoCommandP(0, 1, 0, CMD_COMPANY_CTRL);
 
	}
 

	
 
	/* The next AI starts like the difficulty setting said, with +2 month max */
 
	_next_competitor_start = _settings_game.difficulty.competitor_start_time * 90 * DAY_TICKS + 1;
 
	_next_competitor_start += _network_server ? InteractiveRandomRange(60 * DAY_TICKS) : RandomRange(60 * DAY_TICKS);
 
}
 
@@ -642,13 +642,13 @@ void CompaniesYearlyLoop()
 
 * - p1 bit     15 = enable engine renewal
 
 * - p1 bits 16-31 = months left before engine expires to replace it
 
 * - p2 bits  0-31 = minimum amount of money available
 
 * if p1 = 5, then
 
 * - p2 = enable renew_keep_length
 
 */
 
CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidCompanyID(_current_company)) return CMD_ERROR;
 

	
 
	Company *c = GetCompany(_current_company);
 
	switch (GB(p1, 0, 3)) {
 
		case 0:
 
@@ -785,13 +785,13 @@ void CompanyNewsInformation::FillData(co
 
 * p2. This parameter is passed in at function DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
 
 * on the server itself. First of all this is unbelievably ugly; second of all, well,
 
 * it IS ugly! <b>Someone fix this up :)</b> So where to fix?@n
 
 * @arg - network_server.c:838 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)@n
 
 * @arg - network_client.c:536 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) from where the map has been received
 
 */
 
CommandCost CmdCompanyCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdCompanyCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (flags & DC_EXEC) _current_company = OWNER_NONE;
 

	
 
	InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0);
 

	
 
	switch (p1) {
 
@@ -845,12 +845,13 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
				/* Now that we have a new company, broadcast our autorenew settings to
 
				* all clients so everything is in sync */
 
				NetworkSend_Command(0,
 
					(_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4,
 
					_settings_client.gui.autorenew_money,
 
					CMD_SET_AUTOREPLACE,
 
					NULL,
 
					NULL
 
				);
 

	
 
				MarkWholeScreenDirty();
 
			}
 

	
 
@@ -873,15 +874,14 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
					* (eg. only yourself can change your name/company), we 'cheat' by
 
					* impersonation _local_company as the server. Not the best solution;
 
					* but it works.
 
					* TODO: Perhaps this could be improved by when the client is ready
 
					* with joining to let it send itself the command, and not the server?
 
					* For example in network_client.c:534? */
 
					_cmd_text = ci->client_name;
 
					_local_company = ci->client_playas;
 
					NetworkSend_Command(0, 0, 0, CMD_RENAME_PRESIDENT, NULL);
 
					NetworkSend_Command(0, 0, 0, CMD_RENAME_PRESIDENT, NULL, ci->client_name);
 
					_local_company = company_backup;
 
				}
 
			}
 
#endif /* ENABLE_NETWORK */
 
		} break;
 

	
src/company_gui.cpp
Show inline comments
 
@@ -212,17 +212,17 @@ struct CompanyFinancesWindow : Window {
 
				/* Open up the (toggled size) Finance window at the same position as the previous */
 
				DoShowCompanyFinances(company, new_mode, stickied, oldtop, oldleft);
 
			}
 
			break;
 

	
 
			case CFW_WIDGET_INCREASE_LOAN: /* increase loan */
 
				DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_INCREASE_LOAN | CMD_MSG(STR_702C_CAN_T_BORROW_ANY_MORE_MONEY));
 
				DoCommandP(0, 0, _ctrl_pressed, CMD_INCREASE_LOAN | CMD_MSG(STR_702C_CAN_T_BORROW_ANY_MORE_MONEY));
 
				break;
 

	
 
			case CFW_WIDGET_REPAY_LOAN: /* repay loan */
 
				DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
 
				DoCommandP(0, 0, _ctrl_pressed, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
 
				break;
 
		}
 
	}
 
};
 

	
 
static const WindowDesc _company_finances_desc = {
 
@@ -482,13 +482,13 @@ public:
 
					if (scheme >= LS_END) return;
 
				}
 
				if (j >= LS_END) return;
 

	
 
				/* If clicking on the left edge, toggle using the livery */
 
				if (pt.x < 10) {
 
					DoCommandP(0, j | (2 << 8), !GetCompany((CompanyID)this->window_number)->livery[j].in_use, NULL, CMD_SET_COMPANY_COLOR);
 
					DoCommandP(0, j | (2 << 8), !GetCompany((CompanyID)this->window_number)->livery[j].in_use, CMD_SET_COMPANY_COLOR);
 
				}
 

	
 
				if (_ctrl_pressed) {
 
					ToggleBit(this->sel, j);
 
				} else {
 
					this->sel = 1 << j;
 
@@ -500,13 +500,13 @@ public:
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
 
			if (HasBit(this->sel, scheme)) {
 
				DoCommandP(0, scheme | (widget == SCLW_WIDGET_PRI_COL_DROPDOWN ? 0 : 256), index, NULL, CMD_SET_COMPANY_COLOR);
 
				DoCommandP(0, scheme | (widget == SCLW_WIDGET_PRI_COL_DROPDOWN ? 0 : 256), index, CMD_SET_COMPANY_COLOR);
 
			}
 
		}
 
	}
 

	
 
	virtual void OnInvalidateData(int data = 0)
 
	{
 
@@ -876,13 +876,13 @@ public:
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			/* Toggle size, advanced/simple face selection */
 
			case SCMFW_WIDGET_TOGGLE_LARGE_SMALL:
 
			case SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON: {
 
				DoCommandP(0, 0, this->face, NULL, CMD_SET_COMPANY_MANAGER_FACE);
 
				DoCommandP(0, 0, this->face, CMD_SET_COMPANY_MANAGER_FACE);
 

	
 
				/* Backup some data before deletion */
 
				int oldtop = this->top;     ///< current top position of the window before closing it
 
				int oldleft = this->left;   ///< current top position of the window before closing it
 
				bool adv = !this->advanced;
 
				Window *parent = this->parent;
 
@@ -893,13 +893,13 @@ public:
 
				DoSelectCompanyManagerFace(parent, adv, oldtop, oldleft);
 
			} break;
 

	
 

	
 
			/* OK button */
 
			case SCMFW_WIDGET_ACCEPT:
 
				DoCommandP(0, 0, this->face, NULL, CMD_SET_COMPANY_MANAGER_FACE);
 
				DoCommandP(0, 0, this->face, CMD_SET_COMPANY_MANAGER_FACE);
 
				/* Fall-Through */
 

	
 
			/* Cancel button */
 
			case SCMFW_WIDGET_CANCEL:
 
				delete this;
 
				break;
 
@@ -1284,17 +1284,17 @@ struct CompanyWindow : Window
 
				SetTileSelectSize(2, 2);
 
				this->LowerWidget(CW_WIDGET_RELOCATE_HQ);
 
				this->InvalidateWidget(CW_WIDGET_RELOCATE_HQ);
 
				break;
 

	
 
			case CW_WIDGET_BUY_SHARE:
 
				DoCommandP(0, this->window_number, 0, NULL, CMD_BUY_SHARE_IN_COMPANY | CMD_MSG(STR_707B_CAN_T_BUY_25_SHARE_IN_THIS));
 
				DoCommandP(0, this->window_number, 0, CMD_BUY_SHARE_IN_COMPANY | CMD_MSG(STR_707B_CAN_T_BUY_25_SHARE_IN_THIS));
 
				break;
 

	
 
			case CW_WIDGET_SELL_SHARE:
 
				DoCommandP(0, this->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN));
 
				DoCommandP(0, this->window_number, 0, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN));
 
				break;
 

	
 
#ifdef ENABLE_NETWORK
 
			case CW_WIDGET_COMPANY_PASSWORD:
 
				if (this->window_number == _local_company) ShowNetworkCompanyPasswordWindow(this);
 
				break;
 
@@ -1307,13 +1307,13 @@ struct CompanyWindow : Window
 
		/* redraw the window every now and then */
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnPlaceObject(Point pt, TileIndex tile)
 
	{
 
		if (DoCommandP(tile, 0, 0, NULL, CMD_BUILD_COMPANY_HQ | CMD_NO_WATER | CMD_MSG(STR_7071_CAN_T_BUILD_COMPANY_HEADQUARTERS)))
 
		if (DoCommandP(tile, 0, 0, CMD_BUILD_COMPANY_HQ | CMD_NO_WATER | CMD_MSG(STR_7071_CAN_T_BUILD_COMPANY_HEADQUARTERS)))
 
			ResetObjectToPlace();
 
			this->widget[CW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; // this button can now behave as a normal push button
 
			this->RaiseButtons();
 
	}
 

	
 
	virtual void OnPlaceObjectAbort()
 
@@ -1322,22 +1322,21 @@ struct CompanyWindow : Window
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		if (str == NULL) return;
 

	
 
		_cmd_text = str;
 
		switch (this->query_widget) {
 
			default: NOT_REACHED();
 

	
 
			case CW_WIDGET_PRESIDENT_NAME:
 
				DoCommandP(0, 0, 0, NULL, CMD_RENAME_PRESIDENT | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT));
 
				DoCommandP(0, 0, 0, CMD_RENAME_PRESIDENT | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT), NULL, str);
 
				break;
 

	
 
			case CW_WIDGET_COMPANY_NAME:
 
				DoCommandP(0, 0, 0, NULL, CMD_RENAME_COMPANY | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME));
 
				DoCommandP(0, 0, 0, CMD_RENAME_COMPANY | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME), NULL, str);
 
				break;
 
		}
 
	}
 
};
 

	
 
static const WindowDesc _company_desc = {
 
@@ -1381,13 +1380,13 @@ struct BuyCompanyWindow : Window {
 
		switch (widget) {
 
			case 3:
 
				delete this;
 
				break;
 

	
 
			case 4:
 
				DoCommandP(0, this->window_number, 0, NULL, CMD_BUY_COMPANY | CMD_MSG(STR_7060_CAN_T_BUY_COMPANY));
 
				DoCommandP(0, this->window_number, 0, CMD_BUY_COMPANY | CMD_MSG(STR_7060_CAN_T_BUY_COMPANY));
 
				break;
 
		}
 
	}
 
};
 

	
 
static const Widget _buy_company_widgets[] = {
 
@@ -1453,13 +1452,13 @@ struct EndGameHighScoreBaseWindow : Wind
 

	
 
/** End game window shown at the end of the game */
 
struct EndGameWindow : EndGameHighScoreBaseWindow {
 
	EndGameWindow(const WindowDesc *desc) : EndGameHighScoreBaseWindow(desc)
 
	{
 
		/* Pause in single-player to have a look at the highscore at your own leisure */
 
		if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
 
		if (!_networking) DoCommandP(0, 1, 0, CMD_PAUSE);
 

	
 
		this->background_img = SPR_TYCOON_IMG1_BEGIN;
 

	
 
		if (_local_company != COMPANY_SPECTATOR) {
 
			const Company *c = GetCompany(_local_company);
 
			if (c->old_economy[0].performance_history == SCORE_MAX) {
 
@@ -1481,13 +1480,13 @@ struct EndGameWindow : EndGameHighScoreB
 

	
 
		MarkWholeScreenDirty();
 
	}
 

	
 
	~EndGameWindow()
 
	{
 
		if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause
 
		if (!_networking) DoCommandP(0, 0, 0, CMD_PAUSE); // unpause
 
		ShowHighscoreTable(this->window_number, this->rank);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		const Company *c;
 
@@ -1515,13 +1514,13 @@ struct EndGameWindow : EndGameHighScoreB
 

	
 
struct HighScoreWindow : EndGameHighScoreBaseWindow
 
{
 
	HighScoreWindow(const WindowDesc *desc, int difficulty, int8 ranking) : EndGameHighScoreBaseWindow(desc)
 
	{
 
		/* pause game to show the chart */
 
		if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
 
		if (!_networking) DoCommandP(0, 1, 0, CMD_PAUSE);
 

	
 
		/* Close all always on-top windows to get a clean screen */
 
		if (_game_mode != GM_MENU) HideVitalWindows();
 

	
 
		MarkWholeScreenDirty();
 
		this->window_number = difficulty; // show highscore chart for difficulty...
 
@@ -1530,13 +1529,13 @@ struct HighScoreWindow : EndGameHighScor
 
	}
 

	
 
	~HighScoreWindow()
 
	{
 
		if (_game_mode != GM_MENU) ShowVitalWindows();
 

	
 
		if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause
 
		if (!_networking) DoCommandP(0, 0, 0, CMD_PAUSE); // unpause
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		const HighScore *hs = _highscore_table[this->window_number];
 
		uint x, y;
src/console_cmds.cpp
Show inline comments
 
@@ -480,13 +480,13 @@ DEF_CONSOLE_CMD(ConPauseGame)
 
	if (argc == 0) {
 
		IConsoleHelp("Pause a network game. Usage: 'pause'");
 
		return true;
 
	}
 

	
 
	if (_pause_game == 0) {
 
		DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
 
		DoCommandP(0, 1, 0, CMD_PAUSE);
 
		IConsolePrint(CC_DEFAULT, "Game paused.");
 
	} else {
 
		IConsolePrint(CC_DEFAULT, "Game is already paused.");
 
	}
 

	
 
	return true;
 
@@ -497,13 +497,13 @@ DEF_CONSOLE_CMD(ConUnPauseGame)
 
	if (argc == 0) {
 
		IConsoleHelp("Unpause a network game. Usage: 'unpause'");
 
		return true;
 
	}
 

	
 
	if (_pause_game != 0) {
 
		DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
 
		DoCommandP(0, 0, 0, CMD_PAUSE);
 
		IConsolePrint(CC_DEFAULT, "Game unpaused.");
 
	} else {
 
		IConsolePrint(CC_DEFAULT, "Game is already unpaused.");
 
	}
 

	
 
	return true;
 
@@ -628,13 +628,13 @@ DEF_CONSOLE_CMD(ConResetCompany)
 
	if (ci->client_playas == index) {
 
		IConsoleError("Cannot remove company: the server is connected to that company.");
 
		return true;
 
	}
 

	
 
	/* It is safe to remove this company */
 
	DoCommandP(0, 2, index, NULL, CMD_COMPANY_CTRL);
 
	DoCommandP(0, 2, index, CMD_COMPANY_CTRL);
 
	IConsolePrint(CC_DEFAULT, "Company deleted.");
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConNetworkClients)
src/depot_gui.cpp
Show inline comments
 
@@ -162,13 +162,13 @@ static void TrainDepotMoveVehicle(const 
 
		wagon = wagon->Previous();
 
		if (wagon == NULL) return;
 
	}
 

	
 
	if (wagon == v) return;
 

	
 
	DoCommandP(v->tile, v->index + ((wagon == NULL ? INVALID_VEHICLE : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE));
 
	DoCommandP(v->tile, v->index + ((wagon == NULL ? INVALID_VEHICLE : wagon->index) << 16), _ctrl_pressed ? 1 : 0, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE));
 
}
 

	
 
/* Array to hold the block sizes
 
 * First part is the vehicle type, while the last is 0 = x, 1 = y */
 
uint _block_sizes[4][2];
 

	
 
@@ -542,13 +542,13 @@ struct DepotWindow : Window {
 
					case VEH_TRAIN:    command = CMD_START_STOP_VEHICLE | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN);        break;
 
					case VEH_ROAD:     command = CMD_START_STOP_VEHICLE | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE); break;
 
					case VEH_SHIP:     command = CMD_START_STOP_VEHICLE | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP);         break;
 
					case VEH_AIRCRAFT: command = CMD_START_STOP_VEHICLE | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT);     break;
 
					default: NOT_REACHED(); command = 0;
 
				}
 
				DoCommandP(v->tile, v->index, 0, NULL, command);
 
				DoCommandP(v->tile, v->index, 0, command);
 
			} break;
 

	
 
			default: NOT_REACHED();
 
		}
 
	}
 

	
 
@@ -574,13 +574,13 @@ struct DepotWindow : Window {
 
			case VEH_ROAD:     error_str = CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE);     break;
 
			case VEH_SHIP:     error_str = CMD_MSG(STR_980D_CAN_T_BUILD_SHIP);             break;
 
			case VEH_AIRCRAFT: error_str = CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT);         break;
 
			default: return;
 
		}
 

	
 
		DoCommandP(this->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneVehicle, CMD_CLONE_VEHICLE | error_str);
 
		DoCommandP(this->window_number, v->index, _ctrl_pressed ? 1 : 0, CMD_CLONE_VEHICLE | error_str, CcCloneVehicle);
 

	
 
		ResetObjectToPlace();
 
	}
 

	
 
	void ResizeDepotButtons(Window *w)
 
	{
 
@@ -799,13 +799,13 @@ struct DepotWindow : Window {
 
					ScrollMainWindowToTile(this->window_number);
 
				}
 
				break;
 

	
 
			case DEPOT_WIDGET_STOP_ALL:
 
			case DEPOT_WIDGET_START_ALL:
 
				DoCommandP(this->window_number, 0, this->type | (widget == DEPOT_WIDGET_START_ALL ? (1 << 5) : 0), NULL, CMD_MASS_START_STOP);
 
				DoCommandP(this->window_number, 0, this->type | (widget == DEPOT_WIDGET_START_ALL ? (1 << 5) : 0), CMD_MASS_START_STOP);
 
				break;
 

	
 
			case DEPOT_WIDGET_SELL_ALL:
 
				/* Only open the confimation window if there are anything to sell */
 
				if (this->vehicle_list.Length() != 0 || this->wagon_list.Length() != 0) {
 
					static const StringID confirm_captions[] = {
 
@@ -829,13 +829,13 @@ struct DepotWindow : Window {
 

	
 
			case DEPOT_WIDGET_VEHICLE_LIST:
 
				ShowVehicleListWindow(GetTileOwner(this->window_number), this->type, (TileIndex)this->window_number);
 
				break;
 

	
 
			case DEPOT_WIDGET_AUTOREPLACE:
 
				DoCommandP(this->window_number, this->type, 0, NULL, CMD_DEPOT_MASS_AUTOREPLACE);
 
				DoCommandP(this->window_number, this->type, 0, CMD_DEPOT_MASS_AUTOREPLACE);
 
				break;
 

	
 
		}
 
	}
 

	
 
	virtual void OnRightClick(Point pt, int widget)
 
@@ -948,13 +948,13 @@ struct DepotWindow : Window {
 
				if (this->type == VEH_TRAIN) {
 
					GetDepotVehiclePtData gdvp = { NULL, NULL };
 

	
 
					if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE &&
 
						sel != INVALID_VEHICLE) {
 
						if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) {
 
							DoCommandP(GetVehicle(sel)->tile, GetVehicle(sel)->index, true, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_9033_CAN_T_MAKE_VEHICLE_TURN));
 
							DoCommandP(GetVehicle(sel)->tile, GetVehicle(sel)->index, true, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_9033_CAN_T_MAKE_VEHICLE_TURN));
 
						} else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) {
 
							TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
 
						} else if (gdvp.head != NULL && IsFrontEngine(gdvp.head)) {
 
							ShowVehicleViewWindow(gdvp.head);
 
						}
 
					}
 
@@ -993,13 +993,13 @@ struct DepotWindow : Window {
 
						case VEH_ROAD:     command = CMD_SELL_ROAD_VEH | CMD_MSG(STR_9014_CAN_T_SELL_ROAD_VEHICLE);       break;
 
						case VEH_SHIP:     command = CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP);                   break;
 
						case VEH_AIRCRAFT: command = CMD_SELL_AIRCRAFT | CMD_MSG(STR_A01C_CAN_T_SELL_AIRCRAFT);           break;
 
						default: NOT_REACHED(); command = 0;
 
					}
 

	
 
					if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, command) && is_engine) _backup_orders_tile = 0;
 
					if (!DoCommandP(v->tile, v->index, sell_cmd, command) && is_engine) _backup_orders_tile = 0;
 
				}
 
				break;
 
			default:
 
				this->sel = INVALID_VEHICLE;
 
				this->SetDirty();
 
		}
 
@@ -1029,13 +1029,13 @@ struct DepotWindow : Window {
 
static void DepotSellAllConfirmationCallback(Window *win, bool confirmed)
 
{
 
	if (confirmed) {
 
		DepotWindow *w = (DepotWindow*)win;
 
		TileIndex tile = w->window_number;
 
		byte vehtype = w->type;
 
		DoCommandP(tile, vehtype, 0, NULL, CMD_DEPOT_SELL_ALL_VEHICLES);
 
		DoCommandP(tile, vehtype, 0, CMD_DEPOT_SELL_ALL_VEHICLES);
 
	}
 
}
 

	
 
/** Opens a depot window
 
 * @param tile The tile where the depot/hangar is located
 
 * @param type The type of vehicles in the depot
src/dock_gui.cpp
Show inline comments
 
@@ -44,33 +44,33 @@ void CcBuildCanal(bool success, TileInde
 
	if (success) SndPlayTileFx(SND_02_SPLAT, tile);
 
}
 

	
 

	
 
static void PlaceDocks_Dock(TileIndex tile)
 
{
 
	DoCommandP(tile, _ctrl_pressed, 0, CcBuildDocks, CMD_BUILD_DOCK | CMD_MSG(STR_9802_CAN_T_BUILD_DOCK_HERE));
 
	DoCommandP(tile, _ctrl_pressed, 0, CMD_BUILD_DOCK | CMD_MSG(STR_9802_CAN_T_BUILD_DOCK_HERE), CcBuildDocks);
 
}
 

	
 
static void PlaceDocks_Depot(TileIndex tile)
 
{
 
	DoCommandP(tile, _ship_depot_direction, 0, CcBuildDocks, CMD_BUILD_SHIP_DEPOT | CMD_MSG(STR_3802_CAN_T_BUILD_SHIP_DEPOT));
 
	DoCommandP(tile, _ship_depot_direction, 0, CMD_BUILD_SHIP_DEPOT | CMD_MSG(STR_3802_CAN_T_BUILD_SHIP_DEPOT), CcBuildDocks);
 
}
 

	
 
static void PlaceDocks_Buoy(TileIndex tile)
 
{
 
	DoCommandP(tile, 0, 0, CcBuildDocks, CMD_BUILD_BUOY | CMD_MSG(STR_9835_CAN_T_POSITION_BUOY_HERE));
 
	DoCommandP(tile, 0, 0, CMD_BUILD_BUOY | CMD_MSG(STR_9835_CAN_T_POSITION_BUOY_HERE), CcBuildDocks);
 
}
 

	
 
static void PlaceDocks_BuildCanal(TileIndex tile)
 
{
 
	VpStartPlaceSizing(tile, (_game_mode == GM_EDITOR) ? VPM_X_AND_Y : VPM_X_OR_Y, DDSP_CREATE_WATER);
 
}
 

	
 
static void PlaceDocks_BuildLock(TileIndex tile)
 
{
 
	DoCommandP(tile, 0, 0, CcBuildDocks, CMD_BUILD_LOCK | CMD_MSG(STR_CANT_BUILD_LOCKS));
 
	DoCommandP(tile, 0, 0, CMD_BUILD_LOCK | CMD_MSG(STR_CANT_BUILD_LOCKS), CcBuildDocks);
 
}
 

	
 
static void PlaceDocks_BuildRiver(TileIndex tile)
 
{
 
	VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_RIVER);
 
}
 
@@ -214,22 +214,22 @@ struct BuildDocksToolbarWindow : Window 
 
	{
 
		if (pt.x != -1) {
 
			switch (select_proc) {
 
				case DDSP_BUILD_BRIDGE:
 
					ResetObjectToPlace();
 
					extern void CcBuildBridge(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
					DoCommandP(end_tile, start_tile, TRANSPORT_WATER << 15, CcBuildBridge, CMD_BUILD_BRIDGE | CMD_MSG(STR_CAN_T_BUILD_AQUEDUCT_HERE));
 
					DoCommandP(end_tile, start_tile, TRANSPORT_WATER << 15, CMD_BUILD_BRIDGE | CMD_MSG(STR_CAN_T_BUILD_AQUEDUCT_HERE), CcBuildBridge);
 

	
 
				case DDSP_DEMOLISH_AREA:
 
					GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
 
					break;
 
				case DDSP_CREATE_WATER:
 
					DoCommandP(end_tile, start_tile, (_game_mode == GM_EDITOR ? _ctrl_pressed : 0), CcBuildCanal, CMD_BUILD_CANAL | CMD_MSG(STR_CANT_BUILD_CANALS));
 
					DoCommandP(end_tile, start_tile, (_game_mode == GM_EDITOR ? _ctrl_pressed : 0), CMD_BUILD_CANAL | CMD_MSG(STR_CANT_BUILD_CANALS), CcBuildCanal);
 
					break;
 
				case DDSP_CREATE_RIVER:
 
					DoCommandP(end_tile, start_tile, 2, CcBuildCanal, CMD_BUILD_CANAL | CMD_MSG(STR_CANT_PLACE_RIVERS));
 
					DoCommandP(end_tile, start_tile, 2, CMD_BUILD_CANAL | CMD_MSG(STR_CANT_PLACE_RIVERS), CcBuildCanal);
 
					break;
 

	
 
				default: break;
 
			}
 
		}
 
	}
src/economy.cpp
Show inline comments
 
@@ -1883,13 +1883,13 @@ extern int GetAmountOwnedBy(const Compan
 
/** Acquire shares in an opposing company.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 company to buy the shares from
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_OTHER);
 

	
 
	/* Check if buying shares is allowed (protection against modified clients) */
 
	/* Cannot buy own shares */
 
	if (!IsValidCompanyID((CompanyID)p1) || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
 
@@ -1928,13 +1928,13 @@ CommandCost CmdBuyShareInCompany(TileInd
 
/** Sell shares in an opposing company.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 company to sell the shares from
 
 * @param p2 unused
 
 */
 
CommandCost CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Check if selling shares is allowed (protection against modified clients) */
 
	/* Cannot sell own shares */
 
	if (!IsValidCompanyID((CompanyID)p1) || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
 

	
 
	Company *c = GetCompany((CompanyID)p1);
 
@@ -1961,13 +1961,13 @@ CommandCost CmdSellShareInCompany(TileIn
 
 * @todo currently this only works for AI companies
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 company to buy up
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CompanyID cid = (CompanyID)p1;
 

	
 
	/* Disable takeovers in multiplayer games */
 
	if (!IsValidCompanyID(cid) || _networking) return CMD_ERROR;
 

	
src/engine.cpp
Show inline comments
 
@@ -375,13 +375,13 @@ void EnginesDailyLoop()
 
 * changes while you are waiting to accept the offer? Then it becomes invalid
 
 * @param tile unused
 
 * @param flags operation to perfom
 
 * @param p1 engine-prototype offered
 
 * @param p2 unused
 
 */
 
CommandCost CmdWantEnginePreview(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdWantEnginePreview(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Engine *e;
 

	
 
	if (!IsEngineIndex(p1)) return CMD_ERROR;
 
	e = GetEngine(p1);
 
	if (GetBestCompany(e->preview_company_rank) != _current_company) return CMD_ERROR;
 
@@ -490,21 +490,21 @@ static bool IsUniqueEngineName(const cha
 
/** Rename an engine.
 
 * @param tile unused
 
 * @param flags operation to perfom
 
 * @param p1 engine ID to rename
 
 * @param p2 unused
 
 */
 
CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsEngineIndex(p1)) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(_cmd_text);
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(_cmd_text) >= MAX_LENGTH_ENGINE_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
		if (strlen(text) >= MAX_LENGTH_ENGINE_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueEngineName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Engine *e = GetEngine(p1);
 
		free(e->name);
 

	
 
@@ -516,13 +516,13 @@ CommandCost CmdRenameEngine(TileIndex ti
 
				if (e->name != NULL) {
 
					_vehicle_design_names |= 1;
 
					break;
 
				}
 
			}
 
		} else {
 
			e->name = strdup(_cmd_text);
 
			e->name = strdup(text);
 
			_vehicle_design_names |= 3;
 
		}
 

	
 
		MarkWholeScreenDirty();
 
	}
 

	
src/engine_gui.cpp
Show inline comments
 
@@ -88,13 +88,13 @@ struct EnginePreviewWindow : Window {
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case 4:
 
				DoCommandP(0, this->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW);
 
				DoCommandP(0, this->window_number, 0, CMD_WANT_ENGINE_PREVIEW);
 
				/* Fallthrough */
 
			case 3:
 
				delete this;
 
				break;
 
		}
 
	}
src/genworld.cpp
Show inline comments
 
@@ -161,13 +161,13 @@ static void _GenerateWorld(void *arg)
 

	
 
		DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0);
 
		MarkWholeScreenDirty();
 

	
 
		if (_network_dedicated) DEBUG(net, 0, "Map generated, starting game");
 

	
 
		if (_settings_client.gui.pause_on_newgame && _game_mode == GM_NORMAL) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
 
		if (_settings_client.gui.pause_on_newgame && _game_mode == GM_NORMAL) DoCommandP(0, 1, 0, CMD_PAUSE);
 
	} catch (...) {
 
		_generating_world = false;
 
		throw;
 
	}
 
}
 

	
src/group_cmd.cpp
Show inline comments
 
@@ -77,13 +77,13 @@ void InitializeGroup(void)
 
/**
 
 * Create a new vehicle group.
 
 * @param tile unused
 
 * @param p1   vehicle type
 
 * @param p2   unused
 
 */
 
CommandCost CmdCreateGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdCreateGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleType vt = (VehicleType)p1;
 
	if (!IsCompanyBuildableVehicleType(vt)) return CMD_ERROR;
 

	
 
	if (!Group::CanAllocateItem()) return CMD_ERROR;
 

	
 
@@ -103,13 +103,13 @@ CommandCost CmdCreateGroup(TileIndex til
 
 * Add all vehicles in the given group to the default group and then deletes the group.
 
 * @param tile unused
 
 * @param p1   index of array group
 
 *      - p1 bit 0-15 : GroupID
 
 * @param p2   unused
 
 */
 
CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidGroupID(p1)) return CMD_ERROR;
 

	
 
	Group *g = GetGroup(p1);
 
	if (g->owner != _current_company) return CMD_ERROR;
 

	
 
@@ -165,31 +165,31 @@ static bool IsUniqueGroupName(const char
 
 * Rename a group
 
 * @param tile unused
 
 * @param p1   index of array group
 
 *   - p1 bit 0-15 : GroupID
 
 * @param p2   unused
 
 */
 
CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidGroupID(p1)) return CMD_ERROR;
 

	
 
	Group *g = GetGroup(p1);
 
	if (g->owner != _current_company) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(_cmd_text);
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(_cmd_text) >= MAX_LENGTH_GROUP_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
		if (strlen(text) >= MAX_LENGTH_GROUP_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueGroupName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Delete the old name */
 
		free(g->name);
 
		/* Assign the new one */
 
		g->name = reset ? NULL : strdup(_cmd_text);
 
		g->name = reset ? NULL : strdup(text);
 

	
 
		InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_company);
 
	}
 

	
 
	return CommandCost();
 
}
 
@@ -200,13 +200,13 @@ CommandCost CmdRenameGroup(TileIndex til
 
 * @param tile unused
 
 * @param p1   index of array group
 
 *   - p1 bit 0-15 : GroupID
 
 * @param p2   vehicle to add to a group
 
 *   - p2 bit 0-15 : VehicleID
 
 */
 
CommandCost CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	GroupID new_g = p1;
 

	
 
	if (!IsValidVehicleID(p2) || (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p2);
 
@@ -247,13 +247,13 @@ CommandCost CmdAddVehicleGroup(TileIndex
 
 * Add all shared vehicles of all vehicles from a group
 
 * @param tile unused
 
 * @param p1   index of group array
 
 *  - p1 bit 0-15 : GroupID
 
 * @param p2   type of vehicles
 
 */
 
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleType type = (VehicleType)p2;
 
	if (!IsValidGroupID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Vehicle *v;
 
@@ -265,13 +265,13 @@ CommandCost CmdAddSharedVehicleGroup(Til
 
		FOR_ALL_VEHICLES(v) {
 
			if (v->type == type && v->IsPrimaryVehicle()) {
 
				if (v->group_id != id_g) continue;
 

	
 
				/* For each shared vehicles add it to the group */
 
				for (Vehicle *v2 = v->FirstShared(); v2 != NULL; v2 = v2->NextShared()) {
 
					if (v2->group_id != id_g) CmdAddVehicleGroup(tile, flags, id_g, v2->index);
 
					if (v2->group_id != id_g) CmdAddVehicleGroup(tile, flags, id_g, v2->index, text);
 
				}
 
			}
 
		}
 

	
 
		InvalidateWindowData(GetWindowClassForVehicleType(type), (type << 11) | VLW_GROUP_LIST | _current_company);
 
	}
 
@@ -284,13 +284,13 @@ CommandCost CmdAddSharedVehicleGroup(Til
 
 * Remove all vehicles from a group
 
 * @param tile unused
 
 * @param p1   index of group array
 
 * - p1 bit 0-15 : GroupID
 
 * @param p2   type of vehicles
 
 */
 
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleType type = (VehicleType)p2;
 
	if (!IsValidGroupID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
 

	
 
	Group *g = GetGroup(p1);
 
	if (g->owner != _current_company) return CMD_ERROR;
 
@@ -302,13 +302,13 @@ CommandCost CmdRemoveAllVehiclesGroup(Ti
 
		/* Find each Vehicle that belongs to the group old_g and add it to the default group */
 
		FOR_ALL_VEHICLES(v) {
 
			if (v->type == type && v->IsPrimaryVehicle()) {
 
				if (v->group_id != old_g) continue;
 

	
 
				/* Add The Vehicle to the default group */
 
				CmdAddVehicleGroup(tile, flags, DEFAULT_GROUP, v->index);
 
				CmdAddVehicleGroup(tile, flags, DEFAULT_GROUP, v->index, text);
 
			}
 
		}
 

	
 
		InvalidateWindowData(GetWindowClassForVehicleType(type), (type << 11) | VLW_GROUP_LIST | _current_company);
 
	}
 

	
 
@@ -321,13 +321,13 @@ CommandCost CmdRemoveAllVehiclesGroup(Ti
 
 * @param tile unused
 
 * @param p1   index of group array
 
 * - p1 bit 0-15 : GroupID
 
 * @param p2
 
 * - p2 bit 0    : 1 to set or 0 to clear protection.
 
 */
 
CommandCost CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidGroupID(p1)) return CMD_ERROR;
 

	
 
	Group *g = GetGroup(p1);
 
	if (g->owner != _current_company) return CMD_ERROR;
 

	
src/group_gui.cpp
Show inline comments
 
@@ -510,20 +510,20 @@ public:
 

	
 
				this->SetDirty();
 
				break;
 
			}
 

	
 
			case GRP_WIDGET_CREATE_GROUP: // Create a new group
 
				DoCommandP(0, this->vehicle_type, 0, NULL, CMD_CREATE_GROUP | CMD_MSG(STR_GROUP_CAN_T_CREATE));
 
				DoCommandP(0, this->vehicle_type, 0, CMD_CREATE_GROUP | CMD_MSG(STR_GROUP_CAN_T_CREATE));
 
				break;
 

	
 
			case GRP_WIDGET_DELETE_GROUP: { // Delete the selected group
 
				GroupID group = this->group_sel;
 
				this->group_sel = ALL_GROUP;
 

	
 
				DoCommandP(0, group, 0, NULL, CMD_DELETE_GROUP | CMD_MSG(STR_GROUP_CAN_T_DELETE));
 
				DoCommandP(0, group, 0, CMD_DELETE_GROUP | CMD_MSG(STR_GROUP_CAN_T_DELETE));
 
				break;
 
			}
 

	
 
			case GRP_WIDGET_RENAME_GROUP: { // Rename the selected roup
 
				assert(IsValidGroupID(this->group_sel));
 

	
 
@@ -544,33 +544,33 @@ public:
 

	
 
			case GRP_WIDGET_START_ALL:
 
			case GRP_WIDGET_STOP_ALL: { // Start/stop all vehicles of the list
 
				DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK)
 
													| (1 << 6)
 
													| (widget == GRP_WIDGET_START_ALL ? (1 << 5) : 0)
 
													| this->vehicle_type, NULL, CMD_MASS_START_STOP);
 
													| this->vehicle_type, CMD_MASS_START_STOP);
 

	
 
				break;
 
			}
 

	
 
			case GRP_WIDGET_REPLACE_PROTECTION:
 
				if (IsValidGroupID(this->group_sel)) {
 
					const Group *g = GetGroup(this->group_sel);
 

	
 
					DoCommandP(0, this->group_sel, !g->replace_protection, NULL, CMD_SET_GROUP_REPLACE_PROTECTION);
 
					DoCommandP(0, this->group_sel, !g->replace_protection, CMD_SET_GROUP_REPLACE_PROTECTION);
 
				}
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnDragDrop(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case GRP_WIDGET_ALL_VEHICLES: // All vehicles
 
			case GRP_WIDGET_DEFAULT_VEHICLES: // Ungrouped vehicles
 
				DoCommandP(0, DEFAULT_GROUP, this->vehicle_sel, NULL, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE));
 
				DoCommandP(0, DEFAULT_GROUP, this->vehicle_sel, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE));
 

	
 
				this->vehicle_sel = INVALID_VEHICLE;
 

	
 
				this->SetDirty();
 

	
 
				break;
 
@@ -586,13 +586,13 @@ public:
 
				if (id_g >= this->vscroll2.cap) return;
 

	
 
				id_g += this->vscroll2.pos;
 

	
 
				if (id_g >= this->groups.Length()) return;
 

	
 
				DoCommandP(0, this->groups[id_g]->index, vindex, NULL, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE));
 
				DoCommandP(0, this->groups[id_g]->index, vindex, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE));
 

	
 
				break;
 
			}
 

	
 
			case GRP_WIDGET_LIST_VEHICLE: { // Maxtrix vehicle
 
				uint32 id_v = (pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / (int)this->resize.step_height;
 
@@ -622,14 +622,13 @@ public:
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		if (str == NULL) return;
 

	
 
		_cmd_text = str;
 
		DoCommandP(0, this->group_sel, 0, NULL, CMD_RENAME_GROUP | CMD_MSG(STR_GROUP_CAN_T_RENAME));
 
		DoCommandP(0, this->group_sel, 0, CMD_RENAME_GROUP | CMD_MSG(STR_GROUP_CAN_T_RENAME), NULL, str);
 
	}
 

	
 
	virtual void OnResize(Point new_size, Point delta)
 
	{
 
		this->vscroll2.cap += delta.y / PLY_WND_PRC__SIZE_OF_ROW_TINY;
 
		this->vscroll.cap += delta.y / (int)this->resize.step_height;
 
@@ -652,27 +651,27 @@ public:
 
					case GALF_REPLACE: // Replace window
 
						ShowReplaceGroupVehicleWindow(this->group_sel, this->vehicle_type);
 
						break;
 
					case GALF_SERVICE: // Send for servicing
 
						DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK)
 
									| DEPOT_MASS_SEND
 
									| DEPOT_SERVICE, NULL, GetCmdSendToDepot(this->vehicle_type));
 
									| DEPOT_SERVICE, GetCmdSendToDepot(this->vehicle_type));
 
						break;
 
					case GALF_DEPOT: // Send to Depots
 
						DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK)
 
									| DEPOT_MASS_SEND, NULL, GetCmdSendToDepot(this->vehicle_type));
 
									| DEPOT_MASS_SEND, GetCmdSendToDepot(this->vehicle_type));
 
						break;
 
					case GALF_ADD_SHARED: // Add shared Vehicles
 
						assert(IsValidGroupID(this->group_sel));
 

	
 
						DoCommandP(0, this->group_sel, this->vehicle_type, NULL, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_SHARED_VEHICLE));
 
						DoCommandP(0, this->group_sel, this->vehicle_type, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_SHARED_VEHICLE));
 
						break;
 
					case GALF_REMOVE_ALL: // Remove all Vehicles from the selected group
 
						assert(IsValidGroupID(this->group_sel));
 

	
 
						DoCommandP(0, this->group_sel, this->vehicle_type, NULL, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_GROUP_CAN_T_REMOVE_ALL_VEHICLES));
 
						DoCommandP(0, this->group_sel, this->vehicle_type, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_GROUP_CAN_T_REMOVE_ALL_VEHICLES));
 
						break;
 
					default: NOT_REACHED();
 
				}
 
				break;
 

	
 
			default: NOT_REACHED();
src/industry_cmd.cpp
Show inline comments
 
@@ -1650,13 +1650,13 @@ static Industry *CreateNewIndustryHelper
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 - 15) - industry type see build_industry.h and see industry.h
 
 * - p1 = (bit 16 - 31) - first layout to try
 
 * @param p2 seed to use for variable 8F
 
 * @return index of the newly create industry, or CMD_ERROR if it failed
 
 */
 
CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	const IndustrySpec *indspec = GetIndustrySpec(GB(p1, 0, 16));
 
	const Industry *ind = NULL;
 

	
 
	/* Check if the to-be built/founded industry is available for this climate. */
 
	if (!indspec->enabled) {
src/industry_gui.cpp
Show inline comments
 
@@ -325,13 +325,13 @@ public:
 
						extern void GenerateIndustries();
 
						_generating_world = true;
 
						GenerateIndustries();
 
						_generating_world = false;
 
					}
 
				} else if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && GetIndustrySpec(this->selected_type)->IsRawIndustry()) {
 
					DoCommandP(0, this->selected_type, InteractiveRandom(), NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
 
					DoCommandP(0, this->selected_type, InteractiveRandom(), CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
 
					this->HandleButtonClick(DPIW_FUND_WIDGET);
 
				} else {
 
					HandlePlacePushButton(this, DPIW_FUND_WIDGET, SPR_CURSOR_INDUSTRY, VHM_RECT, NULL);
 
				}
 
			} break;
 
		}
 
@@ -359,22 +359,22 @@ public:
 
				return;
 
			}
 

	
 
			_current_company = OWNER_NONE;
 
			_generating_world = true;
 
			_ignore_restrictions = true;
 
			success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 16) | this->selected_type, seed, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
 
			success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 16) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
 
			if (!success) {
 
				SetDParam(0, indsp->name);
 
				ShowErrorMessage(_error_message, STR_0285_CAN_T_BUILD_HERE, pt.x, pt.y);
 
			}
 

	
 
			_ignore_restrictions = false;
 
			_generating_world = false;
 
		} else {
 
			success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 16) | this->selected_type, seed, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
 
			success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 16) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
 
		}
 

	
 
		/* If an industry has been built, just reset the cursor and the system */
 
		if (success) ResetObjectToPlace();
 
	}
 

	
src/landscape.cpp
Show inline comments
 
@@ -593,24 +593,24 @@ void ClearSnowLine(void)
 
/** Clear a piece of landscape
 
 * @param tile tile to clear
 
 * @param flags of operation to conduct
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
CommandCost CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
 
}
 

	
 
/** Clear a big piece of landscape
 
 * @param tile end tile of area dragging
 
 * @param p1 start tile of area dragging
 
 * @param flags of operation to conduct
 
 * @param p2 unused
 
 */
 
CommandCost CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	/* make sure sx,sy are smaller than ex,ey */
 
	int ex = TileX(tile);
 
	int ey = TileY(tile);
src/main_gui.cpp
Show inline comments
 
@@ -60,24 +60,22 @@ void CcGiveMoney(bool success, TileIndex
 
	}
 
#endif /* ENABLE_NETWORK */
 
}
 

	
 
void HandleOnEditText(const char *str)
 
{
 
	_cmd_text = str;
 

	
 
	switch (_rename_what) {
 
#ifdef ENABLE_NETWORK
 
	case 3: { // Give money, you can only give money in excess of loan
 
		const Company *c = GetCompany(_current_company);
 
		Money money = min(c->money - c->current_loan, (Money)(atoi(str) / _currency->rate));
 

	
 
		uint32 money_c = Clamp(ClampToI32(money), 0, 20000000); // Clamp between 20 million and 0
 

	
 
		/* Give 'id' the money, and substract it from ourself */
 
		DoCommandP(0, money_c, _rename_id, CcGiveMoney, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS));
 
		DoCommandP(0, money_c, _rename_id, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS), CcGiveMoney, str);
 
	} break;
 
#endif /* ENABLE_NETWORK */
 
		default: NOT_REACHED();
 
	}
 

	
 
	_rename_id = _rename_what = -1;
 
@@ -268,13 +266,13 @@ struct MainWindow : Window
 

	
 
			case '1' | WKC_ALT: // Gimme money
 
				/* Server can not cheat in advertise mode either! */
 
#ifdef ENABLE_NETWORK
 
				if (!_networking || !_network_server || !_settings_client.network.server_advertise)
 
#endif /* ENABLE_NETWORK */
 
					DoCommandP(0, 10000000, 0, NULL, CMD_MONEY_CHEAT);
 
					DoCommandP(0, 10000000, 0, CMD_MONEY_CHEAT);
 
				break;
 

	
 
			case '2' | WKC_ALT: // Update the coordinates of all station signs
 
				UpdateAllStationVirtCoord();
 
				break;
 
#endif
src/misc_cmd.cpp
Show inline comments
 
@@ -28,13 +28,13 @@
 
/** Change the company manager's face.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 face bitmasked
 
 */
 
CommandCost CmdSetCompanyManagerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSetCompanyManagerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CompanyManagerFace cmf = (CompanyManagerFace)p2;
 

	
 
	if (!IsValidCompanyManagerFace(cmf)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
@@ -49,13 +49,13 @@ CommandCost CmdSetCompanyManagerFace(Til
 
 * @param flags operation to perform
 
 * @param p1 bitstuffed:
 
 * p1 bits 0-7 scheme to set
 
 * p1 bits 8-9 set in use state or first/second colour
 
 * @param p2 new colour for vehicles, property, etc.
 
 */
 
CommandCost CmdSetCompanyColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSetCompanyColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p2 >= 16) return CMD_ERROR; // max 16 colours
 

	
 
	byte colour = p2;
 

	
 
	LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
 
@@ -129,13 +129,13 @@ CommandCost CmdSetCompanyColor(TileIndex
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 when 0: loans LOAN_INTERVAL
 
 *           when 1: loans the maximum loan permitting money (press CTRL),
 
 */
 
CommandCost CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Company *c = GetCompany(_current_company);
 

	
 
	if (c->current_loan >= _economy.max_loan) {
 
		SetDParam(0, _economy.max_loan);
 
		return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN);
 
@@ -168,13 +168,13 @@ CommandCost CmdIncreaseLoan(TileIndex ti
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 when 0: pays back LOAN_INTERVAL
 
 *           when 1: pays back the maximum loan permitting money (press CTRL),
 
 */
 
CommandCost CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Company *c = GetCompany(_current_company);
 

	
 
	if (c->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED);
 

	
 
	Money loan;
 
@@ -219,25 +219,25 @@ static bool IsUniqueCompanyName(const ch
 
/** Change the name of the company.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
CommandCost CmdRenameCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool reset = StrEmpty(_cmd_text);
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(_cmd_text) >= MAX_LENGTH_COMPANY_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueCompanyName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
		if (strlen(text) >= MAX_LENGTH_COMPANY_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueCompanyName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Company *c = GetCompany(_current_company);
 
		free(c->name);
 
		c->name = reset ? NULL : strdup(_cmd_text);
 
		c->name = reset ? NULL : strdup(text);
 
		MarkWholeScreenDirty();
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
@@ -258,36 +258,35 @@ static bool IsUniquePresidentName(const 
 
/** Change the name of the president.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
CommandCost CmdRenamePresident(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenamePresident(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool reset = StrEmpty(_cmd_text);
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(_cmd_text) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniquePresidentName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
		if (strlen(text) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniquePresidentName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Company *c = GetCompany(_current_company);
 
		free(c->president_name);
 

	
 
		if (reset) {
 
			c->president_name = NULL;
 
		} else {
 
			c->president_name = strdup(_cmd_text);
 
			c->president_name = strdup(text);
 

	
 
			if (c->name_1 == STR_SV_UNNAMED && c->name == NULL) {
 
				char buf[80];
 

	
 
				snprintf(buf, lengthof(buf), "%s Transport", _cmd_text);
 
				_cmd_text = buf;
 
				DoCommand(0, 0, 0, DC_EXEC, CMD_RENAME_COMPANY);
 
				snprintf(buf, lengthof(buf), "%s Transport", text);
 
				DoCommand(0, 0, 0, DC_EXEC, CMD_RENAME_COMPANY, buf);
 
			}
 
		}
 

	
 
		MarkWholeScreenDirty();
 
	}
 

	
 
@@ -299,25 +298,25 @@ CommandCost CmdRenamePresident(TileIndex
 
 * user to confirm that it might crash.
 
 * @param w         unused
 
 * @param confirmed whether the user confirms his/her action
 
 */
 
static void AskUnsafeUnpauseCallback(Window *w, bool confirmed)
 
{
 
	DoCommandP(0, confirmed ? 0 : 1, 0, NULL, CMD_PAUSE);
 
	DoCommandP(0, confirmed ? 0 : 1, 0, CMD_PAUSE);
 
}
 

	
 
/** Pause/Unpause the game (server-only).
 
 * Increase or decrease the pause counter. If the counter is zero,
 
 * the game is unpaused. A counter is used instead of a boolean value
 
 * to have more control over the game when saving/loading, etc.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 0 = decrease pause counter; 1 = increase pause counter
 
 * @param p2 unused
 
 */
 
CommandCost CmdPause(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdPause(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (flags & DC_EXEC) {
 
		_pause_game += (p1 == 0) ? -1 : 1;
 

	
 
		switch (_pause_game) {
 
			case -4:
 
@@ -347,13 +346,13 @@ CommandCost CmdPause(TileIndex tile, uin
 
 * build, you can cheat (to test).
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the amount of money to receive (if negative), or spend (if positive)
 
 * @param p2 unused
 
 */
 
CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
#ifndef _DEBUG
 
	if (_networking) return CMD_ERROR;
 
#endif
 
	return CommandCost(EXPENSES_OTHER, -(int32)p1);
 
}
 
@@ -364,13 +363,13 @@ CommandCost CmdMoneyCheat(TileIndex tile
 
 * given the fact that you have more money than loan).
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the amount of money to transfer; max 20.000.000
 
 * @param p2 the company to transfer the money to
 
 */
 
CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!_settings_game.economy.give_money) return CMD_ERROR;
 

	
 
	const Company *c = GetCompany(_current_company);
 
	CommandCost amount(EXPENSES_OTHER, min((Money)p1, (Money)20000000LL));
 

	
src/misc_gui.cpp
Show inline comments
 
@@ -1464,13 +1464,13 @@ struct SaveLoadWindow : public QueryStri
 
		this->afilter = CS_ALPHANUMERAL;
 
		InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 240);
 

	
 
		/* pause is only used in single-player, non-editor mode, non-menu mode. It
 
		 * will be unpaused in the WE_DESTROY event handler. */
 
		if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) {
 
			if (_pause_game >= 0) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
 
			if (_pause_game >= 0) DoCommandP(0, 1, 0, CMD_PAUSE);
 
		}
 

	
 
		BuildFileList();
 

	
 
		ResetObjectToPlace();
 

	
 
@@ -1502,13 +1502,13 @@ struct SaveLoadWindow : public QueryStri
 
	}
 

	
 
	virtual ~SaveLoadWindow()
 
	{
 
		/* pause is only used in single-player, non-editor mode, non menu mode */
 
		if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
 
			if (_pause_game >= 0) DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
 
			if (_pause_game >= 0) DoCommandP(0, 0, 0, CMD_PAUSE);
 
		}
 
		FiosFreeSavegameList();
 
	}
 

	
 
	virtual void OnPaint()
 
	{
src/network/network.cpp
Show inline comments
 
@@ -372,19 +372,19 @@ void CheckMinActiveClients()
 
	if (!_network_dedicated) return;
 

	
 
	if (NetworkCountActiveClients() < _settings_client.network.min_active_clients) {
 
		if (_min_active_clients_paused) return;
 

	
 
		_min_active_clients_paused = true;
 
		DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
 
		DoCommandP(0, 1, 0, CMD_PAUSE);
 
		NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (not enough players)", CLIENT_ID_SERVER);
 
	} else {
 
		if (!_min_active_clients_paused) return;
 

	
 
		_min_active_clients_paused = false;
 
		DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
 
		DoCommandP(0, 0, 0, CMD_PAUSE);
 
		NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (enough players)", CLIENT_ID_SERVER);
 
	}
 
}
 

	
 
/** Converts a string to ip/port/company
 
 *  Format: IP#company:port
 
@@ -467,13 +467,13 @@ void NetworkCloseClient(NetworkClientSoc
 
			}
 
		}
 
	}
 

	
 
	/* When the client was PRE_ACTIVE, the server was in pause mode, so unpause */
 
	if (cs->status == STATUS_PRE_ACTIVE && _settings_client.network.pause_on_join) {
 
		DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
 
		DoCommandP(0, 0, 0, CMD_PAUSE);
 
		NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused", CLIENT_ID_SERVER);
 
	}
 

	
 
	if (_network_server) {
 
		// We just lost one client :(
 
		if (cs->status >= STATUS_AUTH) _network_game_info.clients_on--;
 
@@ -1054,14 +1054,13 @@ void NetworkGameLoop()
 
			next_date = 1;
 
		}
 

	
 
		while (f != NULL && !feof(f)) {
 
			if (cp != NULL && _date == next_date && _date_fract == next_date_fract) {
 
				_current_company = cp->company;
 
				_cmd_text = cp->text;
 
				DoCommandP(cp->tile, cp->p1, cp->p2, NULL, cp->cmd);
 
				DoCommandP(cp->tile, cp->p1, cp->p2, cp->cmd, NULL, cp->text);
 
				free(cp);
 
				cp = NULL;
 
			}
 

	
 
			if (cp != NULL) break;
 

	
src/network/network_client.cpp
Show inline comments
 
@@ -617,13 +617,13 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 

	
 
			if (_network_playas != COMPANY_SPECTATOR) {
 
				/* We have arrived and ready to start playing; send a command to make a new company;
 
				 * the server will give us a client-id and let us in */
 
				_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
 
				ShowJoinStatusWindow();
 
				NetworkSend_Command(0, 0, 0, CMD_COMPANY_CTRL, NULL);
 
				NetworkSend_Command(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL);
 
			}
 
		} else {
 
			// take control over an existing company
 
			SetLocalCompany(_network_playas);
 
		}
 
	}
src/network/network_data.cpp
Show inline comments
 
@@ -29,13 +29,13 @@ void NetworkAddCommandQueue(NetworkClien
 
		while (c->next != NULL) c = c->next;
 
		c->next = new_cp;
 
	}
 
}
 

	
 
// Prepare a DoCommand to be send over the network
 
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback)
 
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text)
 
{
 
	CommandPacket c;
 

	
 
	c.company = _local_company;
 
	c.next    = NULL;
 
	c.tile    = tile;
 
@@ -50,13 +50,13 @@ void NetworkSend_Command(TileIndex tile,
 

	
 
	if (c.callback == _callback_table_count) {
 
		DEBUG(net, 0, "Unknown callback. (Pointer: %p) No callback sent", callback);
 
		c.callback = 0; // _callback_table[0] == NULL
 
	}
 

	
 
	strecpy(c.text, (_cmd_text != NULL) ? _cmd_text : "", lastof(c.text));
 
	strecpy(c.text, (text != NULL) ? text : "", lastof(c.text));
 

	
 
	if (_network_server) {
 
		/* If we are the server, we queue the command in our 'special' queue.
 
		 *   In theory, we could execute the command right away, but then the
 
		 *   client on the server can do everything 1 tick faster than others.
 
		 *   So to keep the game fair, we delay the command with 1 tick
 
@@ -93,19 +93,18 @@ void NetworkSend_Command(TileIndex tile,
 
}
 

	
 
// Execute a DoCommand we received from the network
 
void NetworkExecuteCommand(CommandPacket *cp)
 
{
 
	_current_company = cp->company;
 
	_cmd_text = cp->text;
 
	/* cp->callback is unsigned. so we don't need to do lower bounds checking. */
 
	if (cp->callback > _callback_table_count) {
 
		DEBUG(net, 0, "Received out-of-bounds callback (%d)", cp->callback);
 
		cp->callback = 0;
 
	}
 

	
 
	DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)cp->company, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text);
 

	
 
	DoCommandP(cp->tile, cp->p1, cp->p2, _callback_table[cp->callback], cp->cmd | CMD_NETWORK_COMMAND, cp->my_cmd);
 
	DoCommandP(cp->tile, cp->p1, cp->p2, cp->cmd | CMD_NETWORK_COMMAND, _callback_table[cp->callback], cp->text, cp->my_cmd);
 
}
 

	
 
#endif /* ENABLE_NETWORK */
src/network/network_server.cpp
Show inline comments
 
@@ -801,13 +801,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
				SEND_COMMAND(PACKET_SERVER_JOIN)(new_cs, cs->client_id);
 
			}
 
		}
 

	
 
		if (_settings_client.network.pause_on_join) {
 
			/* Now pause the game till the client is in sync */
 
			DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
 
			DoCommandP(0, 1, 0, CMD_PAUSE);
 

	
 
			NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (incoming client)", CLIENT_ID_SERVER);
 
		}
 
	} else {
 
		// Wrong status for this packet, give a warning to client, and close connection
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED);
 
@@ -1027,13 +1027,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
		if (frame + DAY_TICKS < _frame_counter) return;
 

	
 
		/* Now he is! Unpause the game */
 
		cs->status = STATUS_ACTIVE;
 

	
 
		if (_settings_client.network.pause_on_join) {
 
			DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
 
			DoCommandP(0, 0, 0, CMD_PAUSE);
 
			NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (client connected)", CLIENT_ID_SERVER);
 
		}
 

	
 
		CheckMinActiveClients();
 

	
 
		/* Execute script for, e.g. MOTD */
 
@@ -1389,13 +1389,13 @@ static void NetworkAutoCleanCompanies()
 
			/* The company is empty for one month more */
 
			_network_company_states[c->index].months_empty++;
 

	
 
			/* Is the company empty for autoclean_unprotected-months, and is there no protection? */
 
			if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && StrEmpty(_network_company_states[c->index].password)) {
 
				/* Shut the company down */
 
				DoCommandP(0, 2, c->index, NULL, CMD_COMPANY_CTRL);
 
				DoCommandP(0, 2, c->index, CMD_COMPANY_CTRL);
 
				IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d", c->index + 1);
 
			}
 
			/* Is the company empty for autoclean_protected-months, and there is a protection? */
 
			if (_settings_client.network.autoclean_protected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_protected && !StrEmpty(_network_company_states[c->index].password)) {
 
				/* Unprotect the company */
 
				_network_company_states[c->index].password[0] = '\0';
src/openttd.cpp
Show inline comments
 
@@ -734,13 +734,13 @@ static void MakeNewGameDone()
 

	
 
	/* Create a single company */
 
	DoStartupNewCompany(false);
 

	
 
	SetLocalCompany(COMPANY_FIRST);
 
	_current_company = _local_company;
 
	DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
 
	DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, CMD_SET_AUTOREPLACE);
 

	
 
	InitializeRailGUI();
 

	
 
#ifdef ENABLE_NETWORK
 
	/* We are the server, we start a new company (not dedicated),
 
	 * so set the default password *if* needed. */
 
@@ -826,13 +826,13 @@ static void StartScenario()
 
	StartupCompanies();
 
	StartupEngines();
 
	StartupDisasters();
 

	
 
	SetLocalCompany(COMPANY_FIRST);
 
	_current_company = _local_company;
 
	DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
 
	DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, CMD_SET_AUTOREPLACE);
 

	
 
	MarkWholeScreenDirty();
 
}
 

	
 
/** Load the specified savegame but on error do different things.
 
 * If loading fails due to corrupt savegame, bad version, etc. go back to
 
@@ -934,13 +934,13 @@ void SwitchMode(int new_mode)
 
					StartupEngines();
 
				}
 
				/* Update the local company for a loaded game. It is either always
 
				* company #1 (eg 0) or in the case of a dedicated server a spectator */
 
				SetLocalCompany(_network_dedicated ? COMPANY_SPECTATOR : COMPANY_FIRST);
 
				/* Decrease pause counter (was increased from opening load dialog) */
 
				DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
 
				DoCommandP(0, 0, 0, CMD_PAUSE);
 
#ifdef ENABLE_NETWORK
 
				if (_network_server) {
 
					snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
 
				}
 
#endif /* ENABLE_NETWORK */
 
			}
src/order_cmd.cpp
Show inline comments
 
@@ -329,13 +329,13 @@ static uint GetOrderDistance(const Order
 
 * - p1 = (bit  0 - 15) - ID of the vehicle
 
 * - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
 
 *                        the order will be inserted before that one
 
 *                        only the first 8 bits used currently (bit 16 - 23) (max 255)
 
 * @param p2 packed order to insert
 
 */
 
CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	VehicleID veh   = GB(p1,  0, 16);
 
	VehicleOrderID sel_ord = GB(p1, 16, 16);
 
	Order new_order(p2);
 

	
 
@@ -610,13 +610,13 @@ static CommandCost DecloneOrder(Vehicle 
 
/** Delete an order from the orderlist of a vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the ID of the vehicle
 
 * @param p2 the order to delete (max 255)
 
 */
 
CommandCost CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	VehicleID veh_id = p1;
 
	VehicleOrderID sel_ord = p2;
 
	Order *order;
 

	
 
@@ -700,13 +700,13 @@ CommandCost CmdDeleteOrder(TileIndex til
 
/** Goto order of order-list.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 The ID of the vehicle which order is skipped
 
 * @param p2 the selected order to which we want to skip
 
 */
 
CommandCost CmdSkipToOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSkipToOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	VehicleID veh_id = p1;
 
	VehicleOrderID sel_ord = p2;
 

	
 
	if (!IsValidVehicleID(veh_id)) return CMD_ERROR;
 
@@ -740,13 +740,13 @@ CommandCost CmdSkipToOrder(TileIndex til
 
 * @param p2 order to move and target
 
 *           bit 0-15  : the order to move
 
 *           bit 16-31 : the target order
 
 * @note The target order will move one place down in the orderlist
 
 *  if you move the order upwards else it'll move it one place down
 
 */
 
CommandCost CmdMoveOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdMoveOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleID veh = p1;
 
	VehicleOrderID moving_order = GB(p2,  0, 16);
 
	VehicleOrderID target_order = GB(p2, 16, 16);
 

	
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 
@@ -844,13 +844,13 @@ CommandCost CmdMoveOrder(TileIndex tile,
 
 *                        the order will be inserted before that one
 
 *                        only the first 8 bits used currently (bit 16 - 23) (max 255)
 
 * @param p2 various bitstuffed elements
 
 *  - p2 = (bit 0 -  3) - what data to modify (@see ModifyOrderFlags)
 
 *  - p2 = (bit 4 - 15) - the data to modify
 
 */
 
CommandCost CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleOrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
 
	VehicleID veh          = GB(p1,  0, 16);
 
	ModifyOrderFlags mof   = (ModifyOrderFlags)GB(p2,  0,  4);
 
	uint16 data             = GB(p2, 4, 11);
 

	
 
@@ -1061,13 +1061,13 @@ CommandCost CmdModifyOrder(TileIndex til
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0-15) - destination vehicle to clone orders to (p1 & 0xFFFF)
 
 * - p1 = (bit 16-31) - source vehicle to clone orders from, if any (none for CO_UNSHARE)
 
 * @param p2 mode of cloning: CO_SHARE, CO_COPY, or CO_UNSHARE
 
 */
 
CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *dst;
 
	VehicleID veh_src = GB(p1, 16, 16);
 
	VehicleID veh_dst = GB(p1,  0, 16);
 

	
 
	if (!IsValidVehicleID(veh_dst)) return CMD_ERROR;
 
@@ -1187,13 +1187,13 @@ CommandCost CmdCloneOrder(TileIndex tile
 
 * @param p1 VehicleIndex of the vehicle having the order
 
 * @param p2 bitmask
 
 *   - bit 0-7 CargoID
 
 *   - bit 8-15 Cargo subtype
 
 *   - bit 16-23 number of order to modify
 
 */
 
CommandCost CmdOrderRefit(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdOrderRefit(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	const Vehicle *v;
 
	Order *order;
 
	VehicleID veh = GB(p1, 0, 16);
 
	VehicleOrderID order_number  = GB(p2, 16, 8);
 
	CargoID cargo = GB(p2, 0, 8);
 
@@ -1282,60 +1282,57 @@ void BackupVehicleOrders(const Vehicle *
 
 * Restore vehicle orders that are backupped via BackupVehicleOrders
 
 *
 
 */
 
void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *bak)
 
{
 
	/* If we have a custom name, process that */
 
	if (bak->name != NULL) {
 
		_cmd_text = bak->name;
 
		DoCommandP(0, v->index, 0, NULL, CMD_RENAME_VEHICLE);
 
	}
 
	if (bak->name != NULL) DoCommandP(0, v->index, 0, CMD_RENAME_VEHICLE, NULL, bak->name);
 

	
 
	/* If we had shared orders, recover that */
 
	if (bak->clone != INVALID_VEHICLE) {
 
		DoCommandP(0, v->index | (bak->clone << 16), CO_SHARE, NULL, CMD_CLONE_ORDER);
 
		DoCommandP(0, v->index | (bak->clone << 16), CO_SHARE, CMD_CLONE_ORDER);
 
	} else {
 

	
 
		/* CMD_NO_TEST_IF_IN_NETWORK is used here, because CMD_INSERT_ORDER checks if the
 
		 *  order number is one more than the current amount of orders, and because
 
		 *  in network the commands are queued before send, the second insert always
 
		 *  fails in test mode. By bypassing the test-mode, that no longer is a problem. */
 
		for (uint i = 0; bak->order[i].IsValid(); i++) {
 
			Order o = bak->order[i];
 
			/* Conditional orders need to have their destination to be valid on insertion. */
 
			if (o.IsType(OT_CONDITIONAL)) o.SetConditionSkipToOrder(0);
 

	
 
			if (!DoCommandP(0, v->index + (i << 16), o.Pack(), NULL,
 
			if (!DoCommandP(0, v->index + (i << 16), o.Pack(),
 
					CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) {
 
				break;
 
			}
 

	
 
			/* Copy timetable if enabled */
 
			if (_settings_game.order.timetabling && !DoCommandP(0, v->index | (i << 16) | (1 << 25),
 
					o.wait_time << 16 | o.travel_time, NULL,
 
					o.wait_time << 16 | o.travel_time,
 
					CMD_CHANGE_TIMETABLE | CMD_NO_TEST_IF_IN_NETWORK)) {
 
				break;
 
			}
 
		}
 

	
 
			/* Fix the conditional orders' destination. */
 
		for (uint i = 0; bak->order[i].IsValid(); i++) {
 
			if (!bak->order[i].IsType(OT_CONDITIONAL)) continue;
 

	
 
			if (!DoCommandP(0, v->index + (i << 16), MOF_LOAD | (bak->order[i].GetConditionSkipToOrder() << 4), NULL,
 
			if (!DoCommandP(0, v->index + (i << 16), MOF_LOAD | (bak->order[i].GetConditionSkipToOrder() << 4),
 
					CMD_MODIFY_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) {
 
				break;
 
			}
 
		}
 
	}
 

	
 
	/* Restore vehicle order-index and service interval */
 
	DoCommandP(0, v->index, bak->orderindex | (bak->service_interval << 16) , NULL, CMD_RESTORE_ORDER_INDEX);
 
	DoCommandP(0, v->index, bak->orderindex | (bak->service_interval << 16) , CMD_RESTORE_ORDER_INDEX);
 

	
 
	/* Restore vehicle group */
 
	DoCommandP(0, bak->group, v->index, NULL, CMD_ADD_VEHICLE_GROUP);
 
	DoCommandP(0, bak->group, v->index, CMD_ADD_VEHICLE_GROUP);
 
}
 

	
 
/** Restore the current order-index of a vehicle and sets service-interval.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the ID of the vehicle
 
@@ -1346,13 +1343,13 @@ void RestoreVehicleOrders(const Vehicle 
 
 * as far as I can see. We can store it in BackuppedOrders, and restore it, but
 
 * but we have no way of seeing it has been tampered with or not, as we have no
 
 * legit way of knowing what that ID was.@n
 
 * If we do want to backup/restore it, just add UnitID uid to BackuppedOrders, and
 
 * restore it as parameter 'y' (ugly hack I know) for example. "v->unitnumber = y;"
 
 */
 
CommandCost CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	VehicleOrderID cur_ord = GB(p2,  0, 16);
 
	uint16 serv_int = GB(p2, 16, 16);
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
src/order_gui.cpp
Show inline comments
 
@@ -432,13 +432,13 @@ private:
 
		}
 

	
 
		/* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet
 
		 * obviously if you press CTRL on a non-empty orders vehicle you know what you are doing */
 
		if (this->vehicle->num_orders != 0 && _ctrl_pressed == 0) return false;
 

	
 
		if (DoCommandP(this->vehicle->tile, this->vehicle->index | (u->index << 16), _ctrl_pressed ? CO_SHARE : CO_COPY, NULL,
 
		if (DoCommandP(this->vehicle->tile, this->vehicle->index | (u->index << 16), _ctrl_pressed ? CO_SHARE : CO_COPY,
 
			_ctrl_pressed ? CMD_CLONE_ORDER | CMD_MSG(STR_CANT_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_CANT_COPY_ORDER_LIST))) {
 
			this->selected_order = -1;
 
			ResetObjectToPlace();
 
		}
 

	
 
		return true;
 
@@ -475,13 +475,13 @@ private:
 

	
 
		if (order == NULL || order->GetLoadType() == load_type) return;
 

	
 
		if (load_type < 0) {
 
			load_type = order->GetLoadType() == OLF_LOAD_IF_POSSIBLE ? OLF_FULL_LOAD_ANY : OLF_LOAD_IF_POSSIBLE;
 
		}
 
		DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_LOAD | (load_type << 4), NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
		DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_LOAD | (load_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
	}
 

	
 
	/**
 
	 * Handle the click on the service.
 
	 *
 
	 * @param w current window
 
@@ -492,13 +492,13 @@ private:
 

	
 
		if (i < 0) {
 
			const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
 
			if (order == NULL) return;
 
			i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
 
		}
 
		DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_DEPOT_ACTION | (i << 4), NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
		DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_DEPOT_ACTION | (i << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
	}
 

	
 
	/**
 
	 * Handle the click on the service in nearest depot button.
 
	 *
 
	 * @param w current window
 
@@ -508,13 +508,13 @@ private:
 
		Order order;
 
		order.next = NULL;
 
		order.index = 0;
 
		order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS);
 
		order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
 

	
 
		DoCommandP(w->vehicle->tile, w->vehicle->index + (w->OrderGetSel() << 16), order.Pack(), NULL, CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER));
 
		DoCommandP(w->vehicle->tile, w->vehicle->index + (w->OrderGetSel() << 16), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER));
 
	}
 

	
 
	/**
 
	 * Handle the click on the conditional order button.
 
	 *
 
	 * @param w current window
 
@@ -540,13 +540,13 @@ private:
 
		if (order == NULL || order->GetUnloadType() == unload_type) return;
 

	
 
		if (unload_type < 0) {
 
			unload_type = order->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE ? OUFB_UNLOAD : OUF_UNLOAD_IF_POSSIBLE;
 
		}
 

	
 
		DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_UNLOAD | (unload_type << 4), NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
		DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_UNLOAD | (unload_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
	}
 

	
 
	/**
 
	 * Handle the click on the nonstop button.
 
	 *
 
	 * @param w current window
 
@@ -562,13 +562,13 @@ private:
 
		/* Keypress if negative, so 'toggle' to the next */
 
		if (non_stop < 0) {
 
			non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
 
		}
 

	
 
		w->InvalidateWidget(ORDER_WIDGET_NON_STOP);
 
		DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_NON_STOP | non_stop << 4,  NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
		DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_NON_STOP | non_stop << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
	}
 

	
 
	/**
 
	 * Handle the click on the skip button.
 
	 * If ctrl is pressed skip to selected order.
 
	 *  Else skip to current order + 1
 
@@ -579,26 +579,26 @@ private:
 
	{
 
		/* Don't skip when there's nothing to skip */
 
		if (_ctrl_pressed && w->vehicle->cur_order_index == w->OrderGetSel()) return;
 
		if (w->vehicle->num_orders <= 1) return;
 

	
 
		DoCommandP(w->vehicle->tile, w->vehicle->index, _ctrl_pressed ? w->OrderGetSel() : ((w->vehicle->cur_order_index + 1) % w->vehicle->num_orders),
 
				NULL, CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_CAN_T_SKIP_TO_ORDER : STR_CAN_T_SKIP_ORDER));
 
				CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_CAN_T_SKIP_TO_ORDER : STR_CAN_T_SKIP_ORDER));
 
	}
 

	
 
	/**
 
	 * Handle the click on the delete button.
 
	 *
 
	 * @param w current window
 
	 */
 
	static void OrderClick_Delete(OrdersWindow *w, int i)
 
	{
 
		/* When networking, move one order lower */
 
		int selected = w->selected_order + (int)_networking;
 

	
 
		if (DoCommandP(w->vehicle->tile, w->vehicle->index, w->OrderGetSel(), NULL, CMD_DELETE_ORDER | CMD_MSG(STR_8834_CAN_T_DELETE_THIS_ORDER))) {
 
		if (DoCommandP(w->vehicle->tile, w->vehicle->index, w->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_8834_CAN_T_DELETE_THIS_ORDER))) {
 
			w->selected_order = selected >= w->vehicle->num_orders ? -1 : selected;
 
		}
 
	}
 

	
 
	/**
 
	 * Handle the click on the refit button.
 
@@ -608,13 +608,13 @@ private:
 
	 * @param w current window
 
	 */
 
	static void OrderClick_Refit(OrdersWindow *w, int i)
 
	{
 
		if (_ctrl_pressed) {
 
			/* Cancel refitting */
 
			DoCommandP(w->vehicle->tile, w->vehicle->index, (w->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, NULL, CMD_ORDER_REFIT);
 
			DoCommandP(w->vehicle->tile, w->vehicle->index, (w->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
 
		} else {
 
			ShowVehicleRefitWindow(w->vehicle, w->OrderGetSel(), w);
 
		}
 
	}
 
	typedef void Handler(OrdersWindow*, int);
 
	struct KeyToEvent {
 
@@ -970,13 +970,13 @@ public:
 
				case OCV_LOAD_PERCENTAGE:
 
					value = Clamp(value, 0, 100);
 

	
 
				default:
 
					break;
 
			}
 
			DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 16), MOF_COND_VALUE | Clamp(value, 0, 2047) << 4, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
			DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 16), MOF_COND_VALUE | Clamp(value, 0, 2047) << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
		}
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		switch (widget) {
 
@@ -1003,30 +1003,30 @@ public:
 

	
 
			case ORDER_WIDGET_SERVICE_DROPDOWN:
 
				OrderClick_Service(this, index);
 
				break;
 

	
 
			case ORDER_WIDGET_COND_VARIABLE:
 
				DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), MOF_COND_VARIABLE | index << 4,  NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
				DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), MOF_COND_VARIABLE | index << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
				break;
 

	
 
			case ORDER_WIDGET_COND_COMPARATOR:
 
				DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), MOF_COND_COMPARATOR | index << 4,  NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
				DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), MOF_COND_COMPARATOR | index << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnDragDrop(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case ORDER_WIDGET_ORDER_LIST: {
 
				int from_order = this->OrderGetSel();
 
				int to_order = this->GetOrderFromPt(pt.y);
 

	
 
				if (!(from_order == to_order || from_order == INVALID_ORDER || from_order > this->vehicle->num_orders || to_order == INVALID_ORDER || to_order > this->vehicle->num_orders) &&
 
						DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), NULL, CMD_MOVE_ORDER | CMD_MSG(STR_CAN_T_MOVE_THIS_ORDER))) {
 
						DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_CAN_T_MOVE_THIS_ORDER))) {
 
					this->selected_order = -1;
 
				}
 
			} break;
 

	
 
			case ORDER_WIDGET_DELETE:
 
				OrderClick_Delete(this, 0);
 
@@ -1066,13 +1066,13 @@ public:
 
			const Vehicle *v = CheckMouseOverVehicle();
 
			if (v != NULL && this->HandleOrderVehClick(v)) return;
 

	
 
			const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
 
			if (!cmd.IsValid()) return;
 

	
 
			if (DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), cmd.Pack(), NULL, CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER))) {
 
			if (DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), cmd.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER))) {
 
				ResetObjectToPlace();
 
			}
 
		}
 
	}
 

	
 
	virtual void OnPlaceObjectAbort()
 
@@ -1087,13 +1087,13 @@ public:
 
				if (order_id != INVALID_ORDER) {
 
					Order order;
 
					order.next = NULL;
 
					order.index = 0;
 
					order.MakeConditional(order_id);
 

	
 
					DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), order.Pack(), NULL, CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER));
 
					DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER));
 
				}
 
			}
 
		}
 
		this->RaiseWidget(ORDER_WIDGET_GOTO);
 
		this->InvalidateWidget(ORDER_WIDGET_GOTO);
 
	}
src/rail_cmd.cpp
Show inline comments
 
@@ -322,13 +322,13 @@ static inline bool ValParamTrackOrientat
 
/** Build a single piece of rail
 
 * @param tile tile  to build on
 
 * @param flags operation to perform
 
 * @param p1 railtype of being built piece (normal, mono, maglev)
 
 * @param p2 rail track to build
 
 */
 
CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Slope tileh;
 
	RailType railtype = (RailType)p1;
 
	Track track = (Track)p2;
 
	TrackBits trackbit;
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
@@ -461,13 +461,13 @@ CommandCost CmdBuildSingleRail(TileIndex
 
/** Remove a single piece of track
 
 * @param tile tile to remove track from
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 rail orientation
 
 */
 
CommandCost CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Track track = (Track)p2;
 
	TrackBits trackbit;
 
	CommandCost cost(EXPENSES_CONSTRUCTION, _price.remove_rail );
 
	bool crossing = false;
 

	
 
@@ -687,13 +687,13 @@ static CommandCost ValidateAutoDrag(Trac
 
 * @param p1 end tile of drag
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
 
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
 
 */
 
static CommandCost CmdRailTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
static CommandCost CmdRailTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
 
	Track track = (Track)GB(p2, 4, 3);
 
	Trackdir trackdir;
 
	byte mode = HasBit(p2, 7);
 
	RailType railtype = (RailType)GB(p2, 0, 4);
 
@@ -737,15 +737,15 @@ static CommandCost CmdRailTrackHelper(Ti
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
 
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
 
 * @see CmdRailTrackHelper
 
 */
 
CommandCost CmdBuildRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return CmdRailTrackHelper(tile, flags, p1, ClrBit(p2, 7));
 
	return CmdRailTrackHelper(tile, flags, p1, ClrBit(p2, 7), text);
 
}
 

	
 
/** Build rail on a stretch of track.
 
 * Stub for the unified rail builder/remover
 
 * @param tile start tile of drag
 
 * @param flags operation to perform
 
@@ -753,27 +753,27 @@ CommandCost CmdBuildRailroadTrack(TileIn
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
 
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
 
 * @see CmdRailTrackHelper
 
 */
 
CommandCost CmdRemoveRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return CmdRailTrackHelper(tile, flags, p1, SetBit(p2, 7));
 
	return CmdRailTrackHelper(tile, flags, p1, SetBit(p2, 7), text);
 
}
 

	
 
/** Build a train depot
 
 * @param tile position of the train depot
 
 * @param flags operation to perform
 
 * @param p1 rail type
 
 * @param p2 bit 0..1 entrance direction (DiagDirection)
 
 *
 
 * @todo When checking for the tile slope,
 
 * distingush between "Flat land required" and "land sloped in wrong direction"
 
 */
 
CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Slope tileh;
 

	
 
	/* check railtype and valid direction for depot (0 through 3), 4 in total */
 
	if (!ValParamRailtype((RailType)p1)) return CMD_ERROR;
 

	
 
@@ -833,13 +833,13 @@ CommandCost CmdBuildTrainDepot(TileIndex
 
 * - p1 = (bit 9-11)- start cycle from this signal type
 
 * - p1 = (bit 12-14)-wrap around after this signal type
 
 * - p1 = (bit 15-16)-cycle the signal direction this many times
 
 * @param p2 used for CmdBuildManySignals() to copy direction of first signal
 
 * TODO: p2 should be replaced by two bits for "along" and "against" the track.
 
 */
 
CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Track track = (Track)GB(p1, 0, 3);
 
	bool ctrl_pressed = HasBit(p1, 3); // was the CTRL button pressed
 
	SignalVariant sigvar = (ctrl_pressed ^ HasBit(p1, 4)) ? SIG_SEMAPHORE : SIG_ELECTRIC; // the signal variant of the new signal
 
	SignalType sigtype = (SignalType)GB(p1, 5, 3); // the signal type of the new signal
 
	bool convert_signal = HasBit(p1, 8); // convert button pressed
 
@@ -1045,13 +1045,13 @@ static bool CheckSignalAutoFill(TileInde
 
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
 
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
 
 * - p2 = (bit  6)    - 0 = selected stretch, 1 = auto fill
 
 * - p2 = (bit  7- 9) - default signal type
 
 * - p2 = (bit 24-31) - user defined signals_density
 
 */
 
static CommandCost CmdSignalTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
static CommandCost CmdSignalTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
 
	int signal_ctr;
 
	byte signals;
 
	bool error = true;
 
	TileIndex end_tile;
 
@@ -1171,27 +1171,27 @@ static CommandCost CmdSignalTrackHelper(
 
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
 
 * - p2 = (bit  6)    - 0 = selected stretch, 1 = auto fill
 
 * - p2 = (bit  7- 9) - default signal type
 
 * - p2 = (bit 24-31) - user defined signals_density
 
 * @see CmdSignalTrackHelper
 
 */
 
CommandCost CmdBuildSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return CmdSignalTrackHelper(tile, flags, p1, p2);
 
	return CmdSignalTrackHelper(tile, flags, p1, p2,text);
 
}
 

	
 
/** Remove signals
 
 * @param tile coordinates where signal is being deleted from
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements, only track information is used
 
 *           - (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
 
 *           - (bit  3)    - override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
 
 *           - (bit  4)    - 0 = signals, 1 = semaphores
 
 * @param p2 unused
 
 */
 
CommandCost CmdRemoveSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Track track = (Track)GB(p1, 0, 3);
 

	
 
	if (!ValParamTrackOrientation(track) ||
 
			!IsTileType(tile, MP_RAILWAY) ||
 
			!HasTrack(tile, track) ||
 
@@ -1240,15 +1240,15 @@ CommandCost CmdRemoveSingleSignal(TileIn
 
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
 
 * - p2 = (bit  6)    - 0 = selected stretch, 1 = auto fill
 
 * - p2 = (bit  7- 9) - default signal type
 
 * - p2 = (bit 24-31) - user defined signals_density
 
 * @see CmdSignalTrackHelper
 
 */
 
CommandCost CmdRemoveSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return CmdSignalTrackHelper(tile, flags, p1, SetBit(p2, 5)); // bit 5 is remove bit
 
	return CmdSignalTrackHelper(tile, flags, p1, SetBit(p2, 5), text); // bit 5 is remove bit
 
}
 

	
 
/** Update power of train under which is the railtype being converted */
 
Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
 
{
 
	/* Similiar checks as in TrainPowerChanged() */
 
@@ -1265,13 +1265,13 @@ Vehicle *UpdateTrainPowerProc(Vehicle *v
 
 * monorail/maglev easily or vice-versa.
 
 * @param tile end tile of rail conversion drag
 
 * @param flags operation to perform
 
 * @param p1 start tile of drag
 
 * @param p2 new railtype to convert to
 
 */
 
CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	RailType totype = (RailType)p2;
 

	
 
	if (!ValParamRailtype(totype)) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
src/rail_gui.cpp
Show inline comments
 
@@ -79,16 +79,17 @@ void CcPlaySound1E(bool success, TileInd
 
{
 
	if (success) SndPlayTileFx(SND_20_SPLAT_2, tile);
 
}
 

	
 
static void GenericPlaceRail(TileIndex tile, int cmd)
 
{
 
	DoCommandP(tile, _cur_railtype, cmd, CcPlaySound1E,
 
	DoCommandP(tile, _cur_railtype, cmd,
 
		_remove_button_clicked ?
 
		CMD_REMOVE_SINGLE_RAIL | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) | CMD_NO_WATER :
 
		CMD_BUILD_SINGLE_RAIL | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK) | CMD_NO_WATER
 
		CMD_BUILD_SINGLE_RAIL | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK) | CMD_NO_WATER,
 
		CcPlaySound1E
 
	);
 
}
 

	
 
static void PlaceRail_N(TileIndex tile)
 
{
 
	int cmd = _tile_fract_coords.x > _tile_fract_coords.y ? 4 : 5;
 
@@ -124,13 +125,13 @@ static void PlaceRail_AutoRail(TileIndex
 
 */
 
static void PlaceExtraDepotRail(TileIndex tile, uint16 extra)
 
{
 
	if (GetRailTileType(tile) != RAIL_TILE_NORMAL) return;
 
	if ((GetTrackBits(tile) & GB(extra, 8, 8)) == 0) return;
 

	
 
	DoCommandP(tile, _cur_railtype, extra & 0xFF, NULL, CMD_BUILD_SINGLE_RAIL | CMD_NO_WATER);
 
	DoCommandP(tile, _cur_railtype, extra & 0xFF, CMD_BUILD_SINGLE_RAIL | CMD_NO_WATER);
 
}
 

	
 
/** Additional pieces of track to add at the entrance of a depot. */
 
static const uint16 _place_depot_extra[12] = {
 
	0x0604, 0x2102, 0x1202, 0x0505,  // First additional track for directions 0..3
 
	0x2400, 0x2801, 0x1800, 0x1401,  // Second additional track
 
@@ -155,22 +156,23 @@ void CcRailDepot(bool success, TileIndex
 
		}
 
	}
 
}
 

	
 
static void PlaceRail_Depot(TileIndex tile)
 
{
 
	DoCommandP(tile, _cur_railtype, _build_depot_direction, CcRailDepot,
 
		CMD_BUILD_TRAIN_DEPOT | CMD_NO_WATER | CMD_MSG(STR_100E_CAN_T_BUILD_TRAIN_DEPOT));
 
	DoCommandP(tile, _cur_railtype, _build_depot_direction,
 
		CMD_BUILD_TRAIN_DEPOT | CMD_NO_WATER | CMD_MSG(STR_100E_CAN_T_BUILD_TRAIN_DEPOT),
 
		CcRailDepot);
 
}
 

	
 
static void PlaceRail_Waypoint(TileIndex tile)
 
{
 
	if (_remove_button_clicked) {
 
		DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_REMOVE_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_REMOVE_TRAIN_WAYPOINT));
 
		DoCommandP(tile, 0, 0, CMD_REMOVE_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_REMOVE_TRAIN_WAYPOINT), CcPlaySound1E);
 
	} else {
 
		DoCommandP(tile, _cur_waypoint_type, 0, CcPlaySound1E, CMD_BUILD_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_BUILD_TRAIN_WAYPOINT));
 
		DoCommandP(tile, _cur_waypoint_type, 0, CMD_BUILD_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_BUILD_TRAIN_WAYPOINT), CcPlaySound1E);
 
	}
 
}
 

	
 
void CcStation(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
@@ -188,14 +190,14 @@ static void PlaceRail_Station(TileIndex 
 
	} else if (_railstation.dragdrop) {
 
		VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_BUILD_STATION);
 
		VpSetPlaceSizingLimit(_settings_game.station.station_spread);
 
	} else {
 
		DoCommandP(tile,
 
				_railstation.orientation | (_railstation.numtracks << 8) | (_railstation.platlength << 16) | (_ctrl_pressed << 24),
 
				_cur_railtype | (_railstation.station_class << 8) | (_railstation.station_type << 16), CcStation,
 
				CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
 
				_cur_railtype | (_railstation.station_class << 8) | (_railstation.station_type << 16),
 
				CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION), CcStation);
 
	}
 
}
 

	
 
/**
 
 * Build a new signal or edit/remove a present signal, use CmdBuildSingleSignal() or CmdRemoveSingleSignal() in rail_cmd.cpp
 
 *
 
@@ -213,14 +215,13 @@ static void GenericPlaceSignals(TileInde
 
		trackbits = (_tile_fract_coords.x + _tile_fract_coords.y <= 15) ? TRACK_BIT_UPPER : TRACK_BIT_LOWER;
 
	}
 

	
 
	Track track = FindFirstTrack(trackbits);
 

	
 
	if (_remove_button_clicked) {
 
		DoCommandP(tile, track, 0, CcPlaySound1E,
 
			CMD_REMOVE_SIGNALS | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM));
 
		DoCommandP(tile, track, 0, CMD_REMOVE_SIGNALS | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM), CcPlaySound1E);
 
	} else {
 
		const Window *w = FindWindowById(WC_BUILD_SIGNAL, 0);
 

	
 
		/* Map _patches.cycle_signal_types to the lower and upper allowed signal type. */
 
		static const uint cycle_bounds[] = {SIGTYPE_NORMAL | (SIGTYPE_LAST_NOPBS << 3), SIGTYPE_PBS | (SIGTYPE_LAST << 3), SIGTYPE_NORMAL | (SIGTYPE_LAST << 3)};
 

	
 
@@ -239,14 +240,15 @@ static void GenericPlaceSignals(TileInde
 
			SB(p1, 4, 1, (_cur_year < _settings_client.gui.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC));
 
			SB(p1, 5, 3, _default_signal_type[_settings_client.gui.default_signal_type]);
 
			SB(p1, 8, 1, 0);
 
			SB(p1, 9, 6, cycle_bounds[_settings_client.gui.cycle_signal_types]);
 
		}
 

	
 
		DoCommandP(tile, p1, 0, CcPlaySound1E, CMD_BUILD_SIGNALS |
 
			CMD_MSG((w != NULL && _convert_signal_button) ? STR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE : STR_1010_CAN_T_BUILD_SIGNALS_HERE));
 
		DoCommandP(tile, p1, 0, CMD_BUILD_SIGNALS |
 
			CMD_MSG((w != NULL && _convert_signal_button) ? STR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE : STR_1010_CAN_T_BUILD_SIGNALS_HERE),
 
			CcPlaySound1E);
 
	}
 
}
 

	
 
static void PlaceRail_Bridge(TileIndex tile)
 
{
 
	VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_BUILD_BRIDGE);
 
@@ -262,14 +264,13 @@ void CcBuildRailTunnel(bool success, Til
 
		SetRedErrorSquare(_build_tunnel_endtile);
 
	}
 
}
 

	
 
static void PlaceRail_Tunnel(TileIndex tile)
 
{
 
	DoCommandP(tile, _cur_railtype, 0, CcBuildRailTunnel,
 
		CMD_BUILD_TUNNEL | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE));
 
	DoCommandP(tile, _cur_railtype, 0, CMD_BUILD_TUNNEL | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE), CcBuildRailTunnel);
 
}
 

	
 
static void PlaceRail_ConvertRail(TileIndex tile)
 
{
 
	VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CONVERT_RAIL);
 
}
 
@@ -511,13 +512,13 @@ static void BuildRailClick_Convert(Windo
 
	HandlePlacePushButton(w, RTW_CONVERT_RAIL, GetRailTypeInfo(_cur_railtype)->cursor.convert, VHM_RECT, PlaceRail_ConvertRail);
 
}
 

	
 

	
 
static void DoRailroadTrack(int mode)
 
{
 
	DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), _cur_railtype | (mode << 4), NULL,
 
	DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), _cur_railtype | (mode << 4),
 
		_remove_button_clicked ?
 
		CMD_REMOVE_RAILROAD_TRACK | CMD_NO_WATER | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) :
 
		CMD_BUILD_RAILROAD_TRACK  | CMD_NO_WATER | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK)
 
	);
 
}
 

	
 
@@ -570,17 +571,16 @@ static void HandleAutoSignalPlacement()
 
	/* _settings_client.gui.drag_signals_density is given as a parameter such that each user
 
	 * in a network game can specify his/her own signal density */
 
	DoCommandP(
 
		TileVirtXY(thd->selstart.x, thd->selstart.y),
 
		TileVirtXY(thd->selend.x, thd->selend.y),
 
		p2,
 
		CcPlaySound1E,
 
		_remove_button_clicked ?
 
			CMD_REMOVE_SIGNAL_TRACK | CMD_NO_WATER | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM) :
 
			CMD_BUILD_SIGNAL_TRACK  | CMD_NO_WATER | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE)
 
	);
 
			CMD_BUILD_SIGNAL_TRACK  | CMD_NO_WATER | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE),
 
		CcPlaySound1E);
 
}
 

	
 

	
 
typedef void OnButtonClick(Window *w);
 

	
 
/** Data associated with a push button in the build rail toolbar window */
 
@@ -724,19 +724,19 @@ struct BuildRailToolbarWindow : Window {
 

	
 
				case DDSP_DEMOLISH_AREA:
 
					GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
 
					break;
 

	
 
				case DDSP_CONVERT_RAIL:
 
					DoCommandP(end_tile, start_tile, _cur_railtype, CcPlaySound10, CMD_CONVERT_RAIL | CMD_MSG(STR_CANT_CONVERT_RAIL));
 
					DoCommandP(end_tile, start_tile, _cur_railtype, CMD_CONVERT_RAIL | CMD_MSG(STR_CANT_CONVERT_RAIL), CcPlaySound10);
 
					break;
 

	
 
				case DDSP_REMOVE_STATION:
 
				case DDSP_BUILD_STATION:
 
					if (_remove_button_clicked) {
 
						DoCommandP(end_tile, start_tile, 0, CcPlaySound1E, CMD_REMOVE_FROM_RAILROAD_STATION | CMD_MSG(STR_CANT_REMOVE_PART_OF_STATION));
 
						DoCommandP(end_tile, start_tile, 0, CMD_REMOVE_FROM_RAILROAD_STATION | CMD_MSG(STR_CANT_REMOVE_PART_OF_STATION), CcPlaySound1E);
 
						break;
 
					}
 
					HandleStationPlacement(start_tile, end_tile);
 
					break;
 

	
 
				case DDSP_PLACE_RAIL_NE:
 
@@ -877,14 +877,14 @@ static void HandleStationPlacement(TileI
 
	w = ex - sx + 1;
 
	h = ey - sy + 1;
 
	if (_railstation.orientation == AXIS_X) Swap(w, h);
 

	
 
	DoCommandP(TileXY(sx, sy),
 
			_railstation.orientation | (w << 8) | (h << 16) | (_ctrl_pressed << 24),
 
			_cur_railtype | (_railstation.station_class << 8) | (_railstation.station_type << 16), CcStation,
 
			CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
 
			_cur_railtype | (_railstation.station_class << 8) | (_railstation.station_type << 16),
 
			CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION), CcStation);
 
}
 

	
 
struct BuildRailStationWindow : public PickerWindowBase {
 
private:
 
	/** Enum referring to the widgets of the rail stations window */
 
	enum BuildRailStationWidgets {
src/road_cmd.cpp
Show inline comments
 
@@ -62,13 +62,13 @@ bool RoadVehiclesAreBuilt()
 
 * Change the side of the road vehicles drive on (server only).
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the side of the road; 0 = left side and 1 = right side
 
 * @param p2 unused
 
 */
 
CommandCost CmdSetRoadDriveSide(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSetRoadDriveSide(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Check boundaries and you can only change this if NO vehicles have been built yet,
 
	 * except in the intro-menu where of course it's always possible to do so. */
 
	if (p1 > 1 || (_game_mode != GM_MENU && RoadVehiclesAreBuilt())) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
@@ -379,13 +379,13 @@ static CommandCost RemoveRoad(TileIndex 
 
 * @param tile tile where to remove road from
 
 * @param flags operation to perform
 
 * @param p1 bit 0..3 road pieces to remove (RoadBits)
 
 *           bit 4..5 road type
 
 * @param p2 unused
 
 */
 
CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	RoadType rt = (RoadType)GB(p1, 4, 2);
 
	if (!IsValidRoadType(rt)) return CMD_ERROR;
 

	
 
	RoadBits pieces = Extract<RoadBits, 0>(p1);
 

	
 
@@ -473,13 +473,13 @@ static CommandCost CheckRoadSlope(Slope 
 
 * @param flags operation to perform
 
 * @param p1 bit 0..3 road pieces to build (RoadBits)
 
 *           bit 4..5 road type
 
 *           bit 6..7 disallowed directions to toggle
 
 * @param p2 the town that is building the road (0 if not applicable)
 
 */
 
CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	RoadBits existing = ROAD_NONE;
 
	RoadBits other_bits = ROAD_NONE;
 

	
 
@@ -716,13 +716,13 @@ do_clear:;
 
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
 
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
 
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
 
 * - p2 = (bit 3 + 4) - road type
 
 * - p2 = (bit 5) - set road direction
 
 */
 
CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	bool had_bridge = false;
 
	bool had_tunnel = false;
 
	bool had_success = false;
 
	DisallowedRoadDirections drd = DRD_NORTHBOUND;
 
@@ -802,13 +802,13 @@ CommandCost CmdBuildLongRoad(TileIndex e
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
 
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
 
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
 
 * - p2 = (bit 3 + 4) - road type
 
 */
 
CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	TileIndex start_tile = p1;
 
@@ -867,13 +867,13 @@ CommandCost CmdRemoveLongRoad(TileIndex 
 
 *           bit 2..3 road type
 
 * @param p2 unused
 
 *
 
 * @todo When checking for the tile slope,
 
 * distingush between "Flat land required" and "land sloped in wrong direction"
 
 */
 
CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	DiagDirection dir = Extract<DiagDirection, 0>(p1);
 
	RoadType rt = (RoadType)GB(p1, 2, 2);
 

	
 
	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
 

	
src/road_gui.cpp
Show inline comments
 
@@ -169,22 +169,22 @@ static const RoadTypeInfo _road_type_inf
 
		SPR_CURSOR_AUTOTRAM,
 
	},
 
};
 

	
 
static void PlaceRoad_Tunnel(TileIndex tile)
 
{
 
	DoCommandP(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, CcBuildRoadTunnel, CMD_BUILD_TUNNEL | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE));
 
	DoCommandP(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, CMD_BUILD_TUNNEL | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE), CcBuildRoadTunnel);
 
}
 

	
 
static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction)
 
{
 
	tile += TileOffsByDiagDir(direction);
 
	/* if there is a roadpiece just outside of the station entrance, build a connecting route */
 
	if (IsNormalRoadTile(tile)) {
 
		if (GetRoadBits(tile, _cur_roadtype) != ROAD_NONE) {
 
			DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, NULL, CMD_BUILD_ROAD);
 
			DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, CMD_BUILD_ROAD);
 
		}
 
	}
 
}
 

	
 
void CcRoadDepot(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
@@ -197,39 +197,39 @@ void CcRoadDepot(bool success, TileIndex
 
		if (HasBit(p2, 1)) BuildRoadOutsideStation(tile, ReverseDiagDir(dir));
 
	}
 
}
 

	
 
static void PlaceRoad_Depot(TileIndex tile)
 
{
 
	DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0, CcRoadDepot, CMD_BUILD_ROAD_DEPOT | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_depot));
 
	DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0, CMD_BUILD_ROAD_DEPOT | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_depot), CcRoadDepot);
 
}
 

	
 
static void PlaceRoadStop(TileIndex tile, uint32 p2, uint32 cmd)
 
{
 
	uint32 p1 = _road_station_picker_orientation;
 

	
 
	if (p1 >= DIAGDIR_END) {
 
		SetBit(p2, 1); // It's a drive-through stop
 
		p1 -= DIAGDIR_END; // Adjust picker result to actual direction
 
	}
 
	DoCommandP(tile, p1, p2, CcRoadDepot, cmd);
 
	DoCommandP(tile, p1, p2, cmd, CcRoadDepot);
 
}
 

	
 
static void PlaceRoad_BusStation(TileIndex tile)
 
{
 
	if (_remove_button_clicked) {
 
		DoCommandP(tile, 0, ROADSTOP_BUS, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_BUS]));
 
		DoCommandP(tile, 0, ROADSTOP_BUS, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_BUS]), CcPlaySound1D);
 
	} else {
 
		PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_BUS, CMD_BUILD_ROAD_STOP | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_BUS]));
 
	}
 
}
 

	
 
static void PlaceRoad_TruckStation(TileIndex tile)
 
{
 
	if (_remove_button_clicked) {
 
		DoCommandP(tile, 0, ROADSTOP_TRUCK, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_TRUCK]));
 
		DoCommandP(tile, 0, ROADSTOP_TRUCK, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_TRUCK]), CcPlaySound1D);
 
	} else {
 
		PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_TRUCK, CMD_BUILD_ROAD_STOP | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_TRUCK]));
 
	}
 
}
 

	
 
/** Enum referring to the widgets of the build road toolbar */
 
@@ -593,16 +593,16 @@ struct BuildRoadToolbarWindow : Window {
 
					/* Flag description:
 
					* Use the first three bits (0x07) if dir == Y
 
					* else use the last 2 bits (X dir has
 
					* not the 3rd bit set) */
 
					_place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
 

	
 
					DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5), CcPlaySound1D,
 
					DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5),
 
						(_ctrl_pressed || _remove_button_clicked) ?
 
						CMD_REMOVE_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
 
						CMD_BUILD_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road));
 
						CMD_BUILD_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road), CcPlaySound1D);
 
					break;
 
			}
 
		}
 
	}
 

	
 
	virtual void OnPlacePresize(Point pt, TileIndex tile)
src/roadveh_cmd.cpp
Show inline comments
 
@@ -170,13 +170,13 @@ void RoadVehUpdateCache(Vehicle *v)
 
/** Build a road vehicle.
 
 * @param tile tile of depot where road vehicle is built
 
 * @param flags operation to perform
 
 * @param p1 bus/truck type being built (engine)
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost;
 
	Vehicle *v;
 
	UnitID unit_num;
 
	Engine *e;
 

	
 
@@ -322,13 +322,13 @@ bool RoadVehicle::IsStoppedInDepot() con
 
/** Sell a road vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 */
 
CommandCost CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 
@@ -427,13 +427,13 @@ bool RoadVehicle::FindClosestDepot(TileI
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to send to the depot
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 */
 
CommandCost CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p2 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
 
		return SendAllVehiclesToDepot(VEH_ROAD, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
 
	}
 
@@ -450,13 +450,13 @@ CommandCost CmdSendRoadVehToDepot(TileIn
 
/** Turn a roadvehicle around.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to turn
 
 * @param p2 unused
 
 */
 
CommandCost CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 
@@ -2002,13 +2002,13 @@ void RoadVehiclesYearlyLoop()
 
 * @param p2 Bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle
 
 * @return cost of refit or error
 
 */
 
CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	CommandCost cost(EXPENSES_ROADVEH_RUN);
 
	CargoID new_cid = GB(p2, 0, 8);
 
	byte new_subtype = GB(p2, 8, 8);
 
	bool only_this = HasBit(p2, 16);
src/settings.cpp
Show inline comments
 
@@ -923,25 +923,25 @@ static int32 CheckInterval(int32 p1)
 

	
 
	return InValidateDetailsWindow(0);
 
}
 

	
 
static int32 EngineRenewUpdate(int32 p1)
 
{
 
	DoCommandP(0, 0, _settings_client.gui.autorenew, NULL, CMD_SET_AUTOREPLACE);
 
	DoCommandP(0, 0, _settings_client.gui.autorenew, CMD_SET_AUTOREPLACE);
 
	return 0;
 
}
 

	
 
static int32 EngineRenewMonthsUpdate(int32 p1)
 
{
 
	DoCommandP(0, 1, _settings_client.gui.autorenew_months, NULL, CMD_SET_AUTOREPLACE);
 
	DoCommandP(0, 1, _settings_client.gui.autorenew_months, CMD_SET_AUTOREPLACE);
 
	return 0;
 
}
 

	
 
static int32 EngineRenewMoneyUpdate(int32 p1)
 
{
 
	DoCommandP(0, 2, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
 
	DoCommandP(0, 2, _settings_client.gui.autorenew_money, CMD_SET_AUTOREPLACE);
 
	return 0;
 
}
 

	
 
static int32 RealisticAccelerationChanged(int32 p1)
 
{
 
	Vehicle *v;
 
@@ -1854,13 +1854,13 @@ static const SettingDesc *GetSettingDesc
 
 * @param flags operation to perform
 
 * @param p1 the index of the patch in the SettingDesc array which identifies it
 
 * @param p2 the new value for the patch
 
 * The new value is properly clamped to its minimum/maximum when setting
 
 * @see _patch_settings
 
 */
 
CommandCost CmdChangePatchSetting(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdChangePatchSetting(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	const SettingDesc *sd = GetSettingDescription(p1);
 

	
 
	if (sd == NULL) return CMD_ERROR;
 
	if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) return CMD_ERROR;
 

	
 
@@ -1918,13 +1918,13 @@ bool SetPatchValue(uint index, int32 val
 
		InvalidateWindow(WC_GAME_OPTIONS, 0);
 
		return true;
 
	}
 

	
 
	/* send non-company-based settings over the network */
 
	if (!_networking || (_networking && _network_server)) {
 
		return DoCommandP(0, index, value, NULL, CMD_CHANGE_PATCH_SETTING);
 
		return DoCommandP(0, index, value, CMD_CHANGE_PATCH_SETTING);
 
	}
 
	return false;
 
}
 

	
 
/**
 
 * Set a patch value with a string.
src/settings_gui.cpp
Show inline comments
 
@@ -274,13 +274,13 @@ struct GameOptionsWindow : Window {
 
				this->opt->locale.units = index;
 
				MarkWholeScreenDirty();
 
				break;
 

	
 
			case GAMEOPT_ROADSIDE_BTN: // Road side
 
				if (this->opt->vehicle.road_side != index) { // only change if setting changed
 
					DoCommandP(0, index, 0, NULL, CMD_SET_ROAD_DRIVE_SIDE | CMD_MSG(STR_00B4_CAN_T_DO_THIS));
 
					DoCommandP(0, index, 0, CMD_SET_ROAD_DRIVE_SIDE | CMD_MSG(STR_00B4_CAN_T_DO_THIS));
 
					MarkWholeScreenDirty();
 
				}
 
				break;
 

	
 
			case GAMEOPT_TOWNNAME_BTN: // Town names
 
				if (_game_mode == GM_MENU || GetNumTowns() == 0) {
 
@@ -544,18 +544,18 @@ public:
 
				const SettingDesc *sd = GetPatchFromName("difficulty.max_no_competitors", &i);
 
				for (uint btn = 0; btn != GAME_DIFFICULTY_NUM; btn++, sd++) {
 
					int32 new_val = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
 
					int32 cur_val = (int32)ReadValue(GetVariableAddress(opt_ptr, &sd->save), sd->save.conv);
 
					/* if setting has changed, change it */
 
					if (new_val != cur_val) {
 
						DoCommandP(0, i + btn, new_val, NULL, CMD_CHANGE_PATCH_SETTING);
 
						DoCommandP(0, i + btn, new_val, CMD_CHANGE_PATCH_SETTING);
 
					}
 
				}
 

	
 
				GetPatchFromName("difficulty.diff_level", &i);
 
				DoCommandP(0, i, this->opt_mod_temp.difficulty.diff_level, NULL, CMD_CHANGE_PATCH_SETTING);
 
				DoCommandP(0, i, this->opt_mod_temp.difficulty.diff_level, CMD_CHANGE_PATCH_SETTING);
 
				delete this;
 
				/* If we are in the editor, we should reload the economy.
 
				 * This way when you load a game, the max loan and interest rate
 
				 * are loaded correctly. */
 
				if (_game_mode == GM_EDITOR) StartupEconomy();
 
				break;
src/ship_cmd.cpp
Show inline comments
 
@@ -748,13 +748,13 @@ void ShipsYearlyLoop()
 
/** Build a ship.
 
 * @param tile tile of depot where ship is built
 
 * @param flags type of operation
 
 * @param p1 ship type being built (engine)
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost value;
 
	UnitID unit_num;
 
	Engine *e;
 

	
 
	if (!IsEngineBuildable(p1, VEH_SHIP, _current_company)) return_cmd_error(STR_SHIP_NOT_AVAILABLE);
 
@@ -841,13 +841,13 @@ CommandCost CmdBuildShip(TileIndex tile,
 
/** Sell a ship.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 */
 
CommandCost CmdSellShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSellShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 
@@ -886,13 +886,13 @@ bool Ship::FindClosestDepot(TileIndex *l
 
 * @param flags type of operation
 
 * @param p1 vehicle ID to send to the depot
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 */
 
CommandCost CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p2 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
 
		return SendAllVehiclesToDepot(VEH_SHIP, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
 
	}
 
@@ -914,13 +914,13 @@ CommandCost CmdSendShipToDepot(TileIndex
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle (ignored)
 
 * @return cost of refit or error
 
 */
 
CommandCost CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	CommandCost cost(EXPENSES_SHIP_RUN);
 
	CargoID new_cid = GB(p2, 0, 8); //gets the cargo number
 
	byte new_subtype = GB(p2, 8, 8);
 
	uint16 capacity = CALLBACK_FAILED;
src/signs.cpp
Show inline comments
 
@@ -95,13 +95,13 @@ static void MarkSignDirty(Sign *si)
 
 * 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
 
 */
 
CommandCost CmdPlaceSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdPlaceSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Try to locate a new sign */
 
	if (!Sign::CanAllocateItem()) return_cmd_error(STR_2808_TOO_MANY_SIGNS);
 

	
 
	/* When we execute, really make the sign */
 
	if (flags & DC_EXEC) {
 
@@ -127,28 +127,27 @@ CommandCost CmdPlaceSign(TileIndex tile,
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 index of the sign to be renamed/removed
 
 * @param p2 unused
 
 * @return 0 if succesfull, otherwise CMD_ERROR
 
 */
 
CommandCost CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidSignID(p1)) return CMD_ERROR;
 

	
 
	/* If _cmd_text 0 means the new text for the sign is non-empty.
 
	 * So rename the sign. If it is empty, it has no name, so delete it */
 
	if (!StrEmpty(_cmd_text)) {
 
		if (strlen(_cmd_text) >= MAX_LENGTH_SIGN_NAME_BYTES) return CMD_ERROR;
 
	/* Rename the signs when empty, otherwise remove it */
 
	if (!StrEmpty(text)) {
 
		if (strlen(text) >= MAX_LENGTH_SIGN_NAME_BYTES) return CMD_ERROR;
 

	
 
		if (flags & DC_EXEC) {
 
			Sign *si = GetSign(p1);
 

	
 
			/* Delete the old name */
 
			free(si->name);
 
			/* Assign the new one */
 
			si->name = strdup(_cmd_text);
 
			si->name = strdup(text);
 
			si->owner = _current_company;
 

	
 
			/* Update; mark sign dirty twice, because it can either becom longer, or shorter */
 
			MarkSignDirty(si);
 
			UpdateSignVirtCoords(si);
 
			MarkSignDirty(si);
 
@@ -188,13 +187,13 @@ void CcPlaceSign(bool success, TileIndex
 
 * PlaceProc function, called when someone pressed the button if the
 
 *  sign-tool is selected
 
 * @param tile on which to place the sign
 
 */
 
void PlaceProc_Sign(TileIndex tile)
 
{
 
	DoCommandP(tile, 0, 0, CcPlaceSign, CMD_PLACE_SIGN | CMD_MSG(STR_2809_CAN_T_PLACE_SIGN_HERE));
 
	DoCommandP(tile, 0, 0, CMD_PLACE_SIGN | CMD_MSG(STR_2809_CAN_T_PLACE_SIGN_HERE), CcPlaceSign);
 
}
 

	
 
/**
 
 *
 
 * Initialize the signs
 
 *
src/signs_gui.cpp
Show inline comments
 
@@ -177,14 +177,13 @@ void ShowSignList()
 
 * @param text  the new name.
 
 * @return true if the window will already be removed after returning.
 
 */
 
static bool RenameSign(SignID index, const char *text)
 
{
 
	bool remove = StrEmpty(text);
 
	_cmd_text = text;
 
	DoCommandP(0, index, 0, NULL, CMD_RENAME_SIGN | (StrEmpty(text) ? CMD_MSG(STR_CAN_T_DELETE_SIGN) : CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME)));
 
	DoCommandP(0, index, 0, CMD_RENAME_SIGN | (StrEmpty(text) ? CMD_MSG(STR_CAN_T_DELETE_SIGN) : CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME)), NULL, text);
 
	return remove;
 
}
 

	
 
enum QueryEditSignWidgets {
 
	QUERY_EDIT_SIGN_WIDGET_TEXT = 3,
 
	QUERY_EDIT_SIGN_WIDGET_OK,
src/station_cmd.cpp
Show inline comments
 
@@ -910,13 +910,13 @@ static void GetStationLayout(byte *layou
 
 * - p1 = (bit 24)    - allow stations directly adjacent to other stations.
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 3) - railtype (p2 & 0xF)
 
 * - p2 = (bit  8-15) - custom station class
 
 * - p2 = (bit 16-23) - custom station id
 
 */
 
CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Does the authority allow this? */
 
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR;
 
	if (!ValParamRailtype((RailType)(p2 & 0xF))) return CMD_ERROR;
 

	
 
	/* unpack parameters */
 
@@ -1189,13 +1189,13 @@ restart:
 
 * This allows for custom-built station with holes and weird layouts
 
 * @param tile tile of station piece to remove
 
 * @param flags operation to perform
 
 * @param p1 start_tile
 
 * @param p2 unused
 
 */
 
CommandCost CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	TileIndex start = p1 == 0 ? tile : p1;
 

	
 
	/* Count of the number of tiles removed */
 
	int quantity = 0;
 

	
 
@@ -1391,13 +1391,13 @@ static RoadStop **FindRoadStopSpot(bool 
 
 * @param p1 entrance direction (DiagDirection)
 
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
 
 *           bit 1: 0 for normal, 1 for drive-through
 
 *           bit 2..4: the roadtypes
 
 *           bit 5: allow stations directly adjacent to other stations.
 
 */
 
CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool type = HasBit(p2, 0);
 
	bool is_drive_through = HasBit(p2, 1);
 
	bool build_over_road  = is_drive_through && IsNormalRoadTile(tile);
 
	bool town_owned_road  = false;
 
	RoadTypes rts = (RoadTypes)GB(p2, 2, 3);
 
@@ -1605,13 +1605,13 @@ static CommandCost RemoveRoadStop(Statio
 
/** Remove a bus or truck stop
 
 * @param tile tile to remove the stop from
 
 * @param flags operation to perform
 
 * @param p1 not used
 
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
 
 */
 
CommandCost CmdRemoveRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Make sure the specified tile is a road stop of the correct type */
 
	if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile) || (uint32)GetRoadStopType(tile) != GB(p2, 0, 1)) return CMD_ERROR;
 
	Station *st = GetStationByTile(tile);
 
	/* Save the stop info before it is removed */
 
	bool is_drive_through = IsDriveThroughStopTile(tile);
 
@@ -1813,13 +1813,13 @@ void UpdateAirportsNoise()
 
/** Place an Airport.
 
 * @param tile tile where airport will be built
 
 * @param flags operation to perform
 
 * @param p1 airport type, @see airport.h
 
 * @param p2 (bit 0) - allow airports directly adjacent to other airports.
 
 */
 
CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool airport_upgrade = true;
 

	
 
	/* Check if a valid, buildable airport was chosen for construction */
 
	if (p1 > lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
 

	
 
@@ -2010,13 +2010,13 @@ static CommandCost RemoveAirport(Station
 
/** Build a buoy.
 
 * @param tile tile where to place the bouy
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE);
 
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return_cmd_error(STR_304B_SITE_UNSUITABLE);
 

	
 
@@ -2120,13 +2120,13 @@ static const byte _dock_h_chk[4] = { 1, 
 
/** Build a dock/haven.
 
 * @param tile tile where dock will be built
 
 * @param flags operation to perform
 
 * @param p1 (bit 0) - allow docks directly adjacent to other docks.
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
 
	if (direction == INVALID_DIAGDIR) return_cmd_error(STR_304B_SITE_UNSUITABLE);
 
	direction = ReverseDiagDir(direction);
 

	
 
	/* Docks cannot be placed on rapids */
 
@@ -2862,29 +2862,29 @@ static bool IsUniqueStationName(const ch
 
/** Rename a station
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 station ID that is to be renamed
 
 * @param p2 unused
 
 */
 
CommandCost CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidStationID(p1)) return CMD_ERROR;
 

	
 
	Station *st = GetStation(p1);
 
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(_cmd_text);
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(_cmd_text) >= MAX_LENGTH_STATION_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueStationName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
		if (strlen(text) >= MAX_LENGTH_STATION_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueStationName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		free(st->name);
 
		st->name = reset ? NULL : strdup(_cmd_text);
 
		st->name = reset ? NULL : strdup(text);
 

	
 
		UpdateStationVirtCoord(st);
 
		InvalidateWindowData(WC_STATION_LIST, st->owner, 1);
 
		MarkWholeScreenDirty();
 
	}
 

	
src/station_gui.cpp
Show inline comments
 
@@ -946,14 +946,13 @@ struct StationViewWindow : public Window
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		if (str == NULL) return;
 

	
 
		_cmd_text = str;
 
		DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
 
		DoCommandP(0, this->window_number, 0, CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION), NULL, str);
 
	}
 

	
 
	virtual void OnResize(Point new_size, Point delta)
 
	{
 
		if (delta.x != 0) ResizeButtons(this, SVW_LOCATION, SVW_RENAME);
 
		this->vscroll.cap += delta.y / (int)this->resize.step_height;
src/terraform_cmd.cpp
Show inline comments
 
@@ -220,13 +220,13 @@ static CommandCost TerraformTileHeight(T
 
 * @param tile tile to terraform
 
 * @param flags for this command type
 
 * @param p1 corners to terraform (SLOPE_xxx)
 
 * @param p2 direction; eg up (non-zero) or down (zero)
 
 * @return error or cost of terraforming
 
 */
 
CommandCost CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Make an extra check for map-bounds cause we add tiles to the originating tile */
 
	if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR;
 

	
 
	_terraform_err_tile = INVALID_TILE;
 

	
 
@@ -344,13 +344,13 @@ CommandCost CmdTerraformLand(TileIndex t
 
 * @param tile end tile of area-drag
 
 * @param flags for this command type
 
 * @param p1 start tile of area drag
 
 * @param p2 height difference; eg raise (+1), lower (-1) or level (0)
 
 * @return  error or cost of terraforming
 
 */
 
CommandCost CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	/* remember level height */
 
	uint oldh = TileHeight(p1);
 

	
src/terraform_gui.cpp
Show inline comments
 
@@ -57,13 +57,13 @@ static void GenerateDesertArea(TileIndex
 
	size_y = (ey - sy) + 1;
 

	
 
	_generating_world = true;
 
	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
 
		if (GetTileType(tile) != MP_WATER) {
 
			SetTropicZone(tile, (_ctrl_pressed) ? TROPICZONE_NORMAL : TROPICZONE_DESERT);
 
			DoCommandP(tile, 0, 0, NULL, CMD_LANDSCAPE_CLEAR);
 
			DoCommandP(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
 
			MarkTileDirtyByTile(tile);
 
		}
 
	} END_TILE_LOOP(tile, size_x, size_y, 0);
 
	_generating_world = false;
 
}
 

	
 
@@ -111,22 +111,22 @@ static void GenerateRockyArea(TileIndex 
 
 * of convertrail which belongs in rail_gui.cpp and not terraform_gui.cpp
 
 **/
 
bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
 
{
 
	switch (proc) {
 
		case DDSP_DEMOLISH_AREA:
 
			DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
 
			DoCommandP(end_tile, start_tile, 0, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA), CcPlaySound10);
 
			break;
 
		case DDSP_RAISE_AND_LEVEL_AREA:
 
			DoCommandP(end_tile, start_tile, 1, CcTerraform, CMD_LEVEL_LAND | CMD_MSG(STR_0808_CAN_T_RAISE_LAND_HERE));
 
			DoCommandP(end_tile, start_tile, 1, CMD_LEVEL_LAND | CMD_MSG(STR_0808_CAN_T_RAISE_LAND_HERE), CcTerraform);
 
			break;
 
		case DDSP_LOWER_AND_LEVEL_AREA:
 
			DoCommandP(end_tile, start_tile, (uint32)-1, CcTerraform, CMD_LEVEL_LAND | CMD_MSG(STR_0809_CAN_T_LOWER_LAND_HERE));
 
			DoCommandP(end_tile, start_tile, (uint32)-1, CMD_LEVEL_LAND | CMD_MSG(STR_0809_CAN_T_LOWER_LAND_HERE), CcTerraform);
 
			break;
 
		case DDSP_LEVEL_AREA:
 
			DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_LEVEL_LAND | CMD_MSG(STR_CAN_T_LEVEL_LAND_HERE));
 
			DoCommandP(end_tile, start_tile, 0, CMD_LEVEL_LAND | CMD_MSG(STR_CAN_T_LEVEL_LAND_HERE), CcPlaySound10);
 
			break;
 
		case DDSP_CREATE_ROCKS:
 
			GenerateRockyArea(end_tile, start_tile);
 
			break;
 
		case DDSP_CREATE_DESERT:
 
			GenerateDesertArea(end_tile, start_tile);
 
@@ -151,13 +151,13 @@ static const uint16 _terraform_keycodes[
 
};
 

	
 
void CcPlaySound1E(bool success, TileIndex tile, uint32 p1, uint32 p2);
 

	
 
static void PlaceProc_BuyLand(TileIndex tile)
 
{
 
	DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_PURCHASE_LAND_AREA | CMD_NO_WATER | CMD_MSG(STR_5806_CAN_T_PURCHASE_THIS_LAND));
 
	DoCommandP(tile, 0, 0, CMD_PURCHASE_LAND_AREA | CMD_NO_WATER | CMD_MSG(STR_5806_CAN_T_PURCHASE_THIS_LAND), CcPlaySound1E);
 
}
 

	
 
void PlaceProc_DemolishArea(TileIndex tile)
 
{
 
	VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_DEMOLISH_AREA);
 
}
 
@@ -357,13 +357,13 @@ static void CommonRaiseLowerBigLand(Tile
 
	uint h;
 

	
 
	if (_terraform_size == 1) {
 
		StringID msg =
 
			mode ? STR_0808_CAN_T_RAISE_LAND_HERE : STR_0809_CAN_T_LOWER_LAND_HERE;
 

	
 
		DoCommandP(tile, SLOPE_N, (uint32)mode, CcTerraform, CMD_TERRAFORM_LAND | CMD_MSG(msg));
 
		DoCommandP(tile, SLOPE_N, (uint32)mode, CMD_TERRAFORM_LAND | CMD_MSG(msg), CcTerraform);
 
	} else {
 
		assert(_terraform_size != 0);
 
		/* check out for map overflows */
 
		sizex = min(MapSizeX() - TileX(tile) - 1, _terraform_size);
 
		sizey = min(MapSizeY() - TileY(tile) - 1, _terraform_size);
 

	
 
@@ -384,13 +384,13 @@ static void CommonRaiseLowerBigLand(Tile
 
				h = max(h, TileHeight(tile2));
 
			} END_TILE_LOOP(tile2, sizex, sizey, tile)
 
		}
 

	
 
		BEGIN_TILE_LOOP(tile2, sizex, sizey, tile) {
 
			if (TileHeight(tile2) == h) {
 
				DoCommandP(tile2, SLOPE_N, (uint32)mode, NULL, CMD_TERRAFORM_LAND);
 
				DoCommandP(tile2, SLOPE_N, (uint32)mode, CMD_TERRAFORM_LAND);
 
			}
 
		} END_TILE_LOOP(tile2, sizex, sizey, tile)
 
	}
 
}
 

	
 
static void PlaceProc_RaiseBigLand(TileIndex tile)
src/timetable_cmd.cpp
Show inline comments
 
@@ -48,13 +48,13 @@ static void ChangeTimetable(Vehicle *v, 
 
 * - p1 = (bit    25) - Whether p2 contains waiting and travelling time.
 
 * @param p2 The amount of time to wait.
 
 * - p2 = (bit  0-15) - Waiting or travelling time as specified by p1 bit 24 if p1 bit 25 is not set,
 
 *                      Travelling time if p1 bit 25 is set.
 
 * - p2 = (bit 16-31) - Waiting time if p1 bit 25 is set
 
 */
 
CommandCost CmdChangeTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdChangeTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!_settings_game.order.timetabling) return CMD_ERROR;
 

	
 
	VehicleID veh = GB(p1, 0, 16);
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 

	
 
@@ -106,13 +106,13 @@ CommandCost CmdChangeTimetable(TileIndex
 
 * Clear the lateness counter to make the vehicle on time.
 
 * @param tile Not used.
 
 * @param flags Operation to perform.
 
 * @param p1 Various bitstuffed elements
 
 * - p1 = (bit  0-15) - Vehicle with the orders to change.
 
 */
 
CommandCost CmdSetVehicleOnTime(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSetVehicleOnTime(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!_settings_game.order.timetabling) return CMD_ERROR;
 

	
 
	VehicleID veh = GB(p1, 0, 16);
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 

	
 
@@ -134,13 +134,13 @@ CommandCost CmdSetVehicleOnTime(TileInde
 
 * @param flags Operation to perform.
 
 * @param p1 Vehicle index.
 
 * @param p2 Various bitstuffed elements
 
 * - p2 = (bit 0) - Set to 1 to enable, 0 to disable autofill.
 
 * - p2 = (bit 1) - Set to 1 to preserve waiting times in non-destructive mode
 
 */
 
CommandCost CmdAutofillTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdAutofillTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!_settings_game.order.timetabling) return CMD_ERROR;
 

	
 
	VehicleID veh = GB(p1, 0, 16);
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 

	
src/timetable_gui.cpp
Show inline comments
 
@@ -291,24 +291,24 @@ struct TimetableWindow : Window {
 

	
 
				ShowQueryString(current, STR_TIMETABLE_CHANGE_TIME, 31, 150, this, CS_NUMERAL, QSF_NONE);
 
			} break;
 

	
 
			case TTV_CLEAR_TIME: { /* Clear waiting time button. */
 
				uint32 p1 = PackTimetableArgs(v, this->sel_index);
 
				DoCommandP(0, p1, 0, NULL, CMD_CHANGE_TIMETABLE | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE));
 
				DoCommandP(0, p1, 0, CMD_CHANGE_TIMETABLE | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE));
 
			} break;
 

	
 
			case TTV_RESET_LATENESS: /* Reset the vehicle's late counter. */
 
				DoCommandP(0, v->index, 0, NULL, CMD_SET_VEHICLE_ON_TIME | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE));
 
				DoCommandP(0, v->index, 0, CMD_SET_VEHICLE_ON_TIME | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE));
 
				break;
 

	
 
			case TTV_AUTOFILL: { /* Autofill the timetable. */
 
				uint32 p2 = 0;
 
				if (!HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) SetBit(p2, 0);
 
				if (_ctrl_pressed) SetBit(p2, 1);
 
				DoCommandP(0, v->index, p2, NULL, CMD_AUTOFILL_TIMETABLE | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE));
 
				DoCommandP(0, v->index, p2, CMD_AUTOFILL_TIMETABLE | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE));
 
			} break;
 
		}
 

	
 
		this->SetDirty();
 
	}
 

	
 
@@ -322,13 +322,13 @@ struct TimetableWindow : Window {
 

	
 
		uint64 time = StrEmpty(str) ? 0 : strtoul(str, NULL, 10);
 
		if (!_settings_client.gui.timetable_in_ticks) time *= DAY_TICKS;
 

	
 
		uint32 p2 = minu(time, UINT16_MAX);
 

	
 
		DoCommandP(0, p1, p2, NULL, CMD_CHANGE_TIMETABLE | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE));
 
		DoCommandP(0, p1, p2, CMD_CHANGE_TIMETABLE | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE));
 
	}
 

	
 
	virtual void OnResize(Point new_size, Point delta)
 
	{
 
		/* Update the scroll + matrix */
 
		this->vscroll.cap = (this->widget[TTV_TIMETABLE_PANEL].bottom - this->widget[TTV_TIMETABLE_PANEL].top) / 10;
src/toolbar_gui.cpp
Show inline comments
 
@@ -235,13 +235,13 @@ static void SelectSignTool()
 
/* --- Pausing --- */
 

	
 
static void ToolbarPauseClick(Window *w)
 
{
 
	if (_networking && !_network_server) return; // only server can pause the game
 

	
 
	if (DoCommandP(0, _pause_game ? 0 : 1, 0, NULL, CMD_PAUSE)) SndPlayFx(SND_15_BEEP);
 
	if (DoCommandP(0, _pause_game ? 0 : 1, 0, CMD_PAUSE)) SndPlayFx(SND_15_BEEP);
 
}
 

	
 
/* --- Fast forwarding --- */
 

	
 
static void ToolbarFastForwardClick(Window *w)
 
{
src/town_cmd.cpp
Show inline comments
 
@@ -1531,13 +1531,13 @@ static void DoCreateTown(Town *t, TileIn
 
 * as it might be possible in the future to fund your own town :)
 
 * @param tile coordinates where town is built
 
 * @param flags type of operation
 
 * @param p1 size of the town (0 = small, 1 = medium, 2 = large)
 
 * @param p2 size mode (@see TownSizeMode)
 
 */
 
CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Only in the scenario editor */
 
	if (_game_mode != GM_EDITOR) return CMD_ERROR;
 
	if (p2 > TSM_CITY) return CMD_ERROR;
 

	
 
	/* Check if too close to the edge of map */
 
@@ -2107,28 +2107,28 @@ static bool IsUniqueTownName(const char 
 
/** Rename a town (server-only).
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 town ID to rename
 
 * @param p2 unused
 
 */
 
CommandCost CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidTownID(p1)) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(_cmd_text);
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(_cmd_text) >= MAX_LENGTH_TOWN_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueTownName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
		if (strlen(text) >= MAX_LENGTH_TOWN_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueTownName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Town *t = GetTown(p1);
 

	
 
		free(t->name);
 
		t->name = reset ? NULL : strdup(_cmd_text);
 
		t->name = reset ? NULL : strdup(text);
 

	
 
		UpdateTownVirtCoord(t);
 
		InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1);
 
		UpdateAllStationVirtCoord();
 
		UpdateAllWaypointSigns();
 
		MarkWholeScreenDirty();
 
@@ -2311,13 +2311,13 @@ extern uint GetMaskOfTownActions(int *nu
 
 * but also bribing the town-council
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 town to do the action at
 
 * @param p2 action to perform, @see _town_action_proc for the list of available actions
 
 */
 
CommandCost CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidTownID(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR;
 

	
 
	Town *t = GetTown(p1);
 

	
 
	if (!HasBit(GetMaskOfTownActions(NULL, _current_company, t), p2)) return CMD_ERROR;
src/town_gui.cpp
Show inline comments
 
@@ -251,13 +251,13 @@ public:
 
				}
 
				/* Fall through to clicking in case we are double-clicked */
 
				if (!double_click || y < 0) break;
 
			}
 

	
 
			case TWA_EXECUTE:
 
				DoCommandP(this->town->xy, this->window_number, this->sel_index, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS));
 
				DoCommandP(this->town->xy, this->window_number, this->sel_index, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS));
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnHundredthTick()
 
	{
 
@@ -401,14 +401,13 @@ public:
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		if (str == NULL) return;
 

	
 
		_cmd_text = str;
 
		DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN));
 
		DoCommandP(0, this->window_number, 0, CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN), NULL, str);
 
	}
 
};
 

	
 

	
 
static const Widget _town_view_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_BROWN,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
 
@@ -664,13 +663,13 @@ void CcBuildTown(bool success, TileIndex
 
}
 

	
 
static void PlaceProc_Town(TileIndex tile)
 
{
 
	uint32 size = min(_scengen_town_size, (int)TSM_CITY);
 
	uint32 mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
 
	DoCommandP(tile, size, mode, CcBuildTown, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE));
 
	DoCommandP(tile, size, mode, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE), CcBuildTown);
 
}
 

	
 
static const Widget _scen_edit_town_gen_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,    0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,   RESIZE_NONE,  COLOUR_DARK_GREEN,   11,   147,     0,    13, STR_0233_TOWN_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,  148,   159,     0,    13, 0x0,                      STR_STICKY_BUTTON},
src/train_cmd.cpp
Show inline comments
 
@@ -754,13 +754,13 @@ static void AddRearEngineToMultiheadedTr
 
/** Build a railroad vehicle.
 
 * @param tile tile of the depot where rail-vehicle is built
 
 * @param flags type of operation
 
 * @param p1 engine type id
 
 * @param p2 bit 1 prevents any free cars from being added to the train
 
 */
 
CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Check if the engine-type is valid (for the company) */
 
	if (!IsEngineBuildable(p1, VEH_TRAIN, _current_company)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE);
 

	
 
	/* Check if the train is actually being built in a depot belonging
 
	 * to the company. Doesn't matter if only the cost is queried */
 
@@ -1015,13 +1015,13 @@ static void NormaliseTrainConsist(Vehicl
 
 *              Note: DC_AUTOREPLACE is set when autoreplace tries to undo its modifications or moves vehicles to temporary locations inside the depot.
 
 * @param p1 various bitstuffed elements
 
 * - p1 (bit  0 - 15) source vehicle index
 
 * - p1 (bit 16 - 31) what wagon to put the source wagon AFTER, XXX - INVALID_VEHICLE to make a new line
 
 * @param p2 (bit 0) move all vehicles following the source vehicle
 
 */
 
CommandCost CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleID s = GB(p1, 0, 16);
 
	VehicleID d = GB(p1, 16, 16);
 

	
 
	if (!IsValidVehicleID(s)) return CMD_ERROR;
 

	
 
@@ -1321,13 +1321,13 @@ CommandCost CmdMoveRailVehicle(TileIndex
 
		 * To do this, CmdMoveRailVehicle must be called once more
 
		 * we can't loop forever here because next time we reach this line we will have a front engine */
 
		if (src_head != NULL && !IsFrontEngine(src_head) && IsTrainEngine(src_head)) {
 
			/* As in CmdMoveRailVehicle src_head->group_id will be equal to DEFAULT_GROUP
 
			 * we need to save the group and reaffect it to src_head */
 
			const GroupID tmp_g = src_head->group_id;
 
			CmdMoveRailVehicle(0, flags, src_head->index | (INVALID_VEHICLE << 16), 1);
 
			CmdMoveRailVehicle(0, flags, src_head->index | (INVALID_VEHICLE << 16), 1, text);
 
			SetTrainGroupID(src_head, tmp_g);
 
			src_head = NULL; // don't do anything more to this train since the new call will do it
 
		}
 

	
 
		if (src_head != NULL) {
 
			NormaliseTrainConsist(src_head);
 
@@ -1369,13 +1369,13 @@ CommandCost CmdMoveRailVehicle(TileIndex
 
 * - p2 = 0: only sell the single dragged wagon/engine (and any belonging rear-engines)
 
 * - p2 = 1: sell the vehicle and all vehicles following it in the chain
 
 *           if the wagon is dragged, don't delete the possibly belonging rear-engine to some front
 
 * - p2 = 2: when selling attached locos, rearrange all vehicles after it to separate lines;
 
 *           all wagons of the same type will go on the same line. Used by the AI currently
 
 */
 
CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Check if we deleted a vehicle window */
 
	Window *w = NULL;
 

	
 
	if (!IsValidVehicleID(p1) || p2 > 2) return CMD_ERROR;
 

	
 
@@ -1937,13 +1937,13 @@ static void ReverseTrainDirection(Vehicl
 
/** Reverse train.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 train to reverse
 
 * @param p2 if true, reverse a unit in a train (needs to be in a depot)
 
 */
 
CommandCost CmdReverseTrainDirection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdReverseTrainDirection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
 
@@ -1987,13 +1987,13 @@ CommandCost CmdReverseTrainDirection(Til
 
/** Force a train through a red signal
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 train to ignore the red signal
 
 * @param p2 unused
 
 */
 
CommandCost CmdForceTrainProceed(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdForceTrainProceed(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
 
@@ -2010,13 +2010,13 @@ CommandCost CmdForceTrainProceed(TileInd
 
 * param p2 various bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle
 
 * @return cost of refit or error
 
 */
 
CommandCost CmdRefitRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRefitRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CargoID new_cid = GB(p2, 0, 8);
 
	byte new_subtype = GB(p2, 8, 8);
 
	bool only_this = HasBit(p2, 16);
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
@@ -2214,13 +2214,13 @@ bool Train::FindClosestDepot(TileIndex *
 
 * @param flags type of operation
 
 * @param p1 train to send to the depot
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 */
 
CommandCost CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p2 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
 
		return SendAllVehiclesToDepot(VEH_TRAIN, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
 
	}
src/train_gui.cpp
Show inline comments
 
@@ -40,13 +40,13 @@ void CcBuildWagon(bool success, TileInde
 
	}
 

	
 
	/* if we found a loco, */
 
	if (found != NULL) {
 
		found = GetLastVehicleInChain(found);
 
		/* put the new wagon at the end of the loco. */
 
		DoCommandP(0, _new_vehicle_id | (found->index << 16), 0, NULL, CMD_MOVE_RAIL_VEHICLE);
 
		DoCommandP(0, _new_vehicle_id | (found->index << 16), 0, CMD_MOVE_RAIL_VEHICLE);
 
		InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
 
	}
 
}
 

	
 
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
{
src/tree_cmd.cpp
Show inline comments
 
@@ -320,13 +320,13 @@ void GenerateTrees()
 
/** Plant a tree.
 
 * @param tile start tile of area-drag of tree plantation
 
 * @param flags type of operation
 
 * @param p1 tree type, -1 means random.
 
 * @param p2 end tile of area-drag
 
 */
 
CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	StringID msg = INVALID_STRING_ID;
 
	CommandCost cost(EXPENSES_OTHER);
 
	int ex;
 
	int ey;
 
	int sx, sy, x, y;
src/tree_gui.cpp
Show inline comments
 
@@ -130,13 +130,13 @@ public:
 
		VpSelectTilesWithMethod(pt.x, pt.y, select_method);
 
	}
 

	
 
	virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
 
	{
 
		if (pt.x != -1 && select_proc == DDSP_PLANT_TREES) {
 
			DoCommandP(end_tile, this->tree_to_plant, start_tile, NULL,
 
			DoCommandP(end_tile, this->tree_to_plant, start_tile,
 
				CMD_PLANT_TREE | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE));
 
		}
 
	}
 

	
 
	virtual void OnTimeout()
 
	{
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -183,13 +183,13 @@ bool CheckBridge_Stuff(BridgeType bridge
 
 * @param p1 packed start tile coords (~ dx)
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 7) - bridge type (hi bh)
 
 * - p2 = (bit  8-14) - rail type or road types.
 
 * - p2 = (bit 15-16) - transport type.
 
 */
 
CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	BridgeType bridge_type;
 
	RailType railtype = INVALID_RAILTYPE;
 
	RoadTypes roadtypes = ROADTYPES_NONE;
 
	uint x;
 
	uint y;
 
@@ -470,13 +470,13 @@ not_valid_below:;
 
/** Build Tunnel.
 
 * @param start_tile start tile of tunnel
 
 * @param flags type of operation
 
 * @param p1 railtype or roadtypes. bit 9 set means road tunnel
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	TileIndexDiff delta;
 
	TileIndex end_tile;
 
	DiagDirection direction;
 
	Slope start_tileh;
 
	Slope end_tileh;
src/unmovable_cmd.cpp
Show inline comments
 
@@ -85,13 +85,13 @@ extern CommandCost CheckFlatLandBelow(Ti
 
/** 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
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Company *c = GetCompany(_current_company);
 
	CommandCost cost(EXPENSES_PROPERTY);
 

	
 
	cost = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL);
 
	if (CmdFailed(cost)) return cost;
 
@@ -119,13 +119,13 @@ CommandCost CmdBuildCompanyHQ(TileIndex 
 
 * @param tile the tile the company is purchasing
 
 * @param flags for this command type
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @return error of cost of operation
 
 */
 
CommandCost CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_company)) {
 
		return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
 
	}
 
@@ -146,13 +146,13 @@ CommandCost CmdPurchaseLandArea(TileInde
 
 * @param tile the tile the company is selling
 
 * @param flags for this command type
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @return error or cost of operation
 
 */
 
CommandCost CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsOwnedLandTile(tile)) return CMD_ERROR;
 
	if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER) return CMD_ERROR;
 

	
 
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 

	
src/vehicle.cpp
Show inline comments
 
@@ -1078,13 +1078,13 @@ void AgeVehicle(Vehicle *v)
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle to start/stop
 
 * @param p2 bit 0: Shall the start/stop newgrf callback be evaluated (only valid with DC_AUTOREPLACE for network safety)
 
 * @return result of operation.  Nothing if everything went well
 
 */
 
CommandCost CmdStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Disable the effect of p2 bit 0, when DC_AUTOREPLACE is not set */
 
	if ((flags & DC_AUTOREPLACE) == 0) SetBit(p2, 0);
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
@@ -1151,13 +1151,13 @@ CommandCost CmdStartStopVehicle(TileInde
 
 * @param p2 bitmask
 
 *   - bit 0-4 Vehicle type
 
 *   - bit 5 false = start vehicles, true = stop vehicles
 
 *   - bit 6 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case
 
 *   - bit 8-11 Vehicle List Window type (ignored unless bit 1 is set)
 
 */
 
CommandCost CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleList list;
 
	CommandCost return_value = CMD_ERROR;
 
	VehicleType vehicle_type = (VehicleType)GB(p2, 0, 5);
 
	bool start_stop = HasBit(p2, 5);
 
	bool vehicle_list_window = HasBit(p2, 6);
 
@@ -1201,13 +1201,13 @@ CommandCost CmdMassStartStopVehicle(Tile
 
/** Sells all vehicles in a depot
 
 * @param tile Tile of the depot where the depot is
 
 * @param flags type of operation
 
 * @param p1 Vehicle type
 
 * @param p2 unused
 
 */
 
CommandCost CmdDepotSellAllVehicles(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdDepotSellAllVehicles(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleList list;
 

	
 
	CommandCost cost(EXPENSES_NEW_VEHICLES);
 
	uint sell_command;
 
	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
 
@@ -1238,13 +1238,13 @@ CommandCost CmdDepotSellAllVehicles(Tile
 
 * estimation can't predict wagon removal so it presumes worst case which is no income from selling wagons.
 
 * @param tile Tile of the depot where the vehicles are
 
 * @param flags type of operation
 
 * @param p1 Type of vehicle
 
 * @param p2 If bit 0 is set, then either replace all or nothing (instead of replacing until money runs out)
 
 */
 
CommandCost CmdDepotMassAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdDepotMassAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleList list;
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES);
 
	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
 
	bool all_or_nothing = HasBit(p2, 0);
 

	
 
@@ -1290,13 +1290,13 @@ CommandCost CmdDepotMassAutoReplace(Tile
 
/** Clone a vehicle. If it is a train, it will clone all the cars too
 
 * @param tile tile of the depot where the cloned vehicle is build
 
 * @param flags type of operation
 
 * @param p1 the original vehicle's index
 
 * @param p2 1 = shared orders, else copied orders
 
 */
 
CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost total_cost(EXPENSES_NEW_VEHICLES);
 
	uint32 build_argument = 2;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
@@ -1663,29 +1663,29 @@ static bool IsUniqueVehicleName(const ch
 
/** Give a custom name to your vehicle
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID to name
 
 * @param p2 unused
 
 */
 
CommandCost CmdRenameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(_cmd_text);
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(_cmd_text) >= MAX_LENGTH_VEHICLE_NAME_BYTES) return CMD_ERROR;
 
		if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
		if (strlen(text) >= MAX_LENGTH_VEHICLE_NAME_BYTES) return CMD_ERROR;
 
		if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		free(v->name);
 
		v->name = reset ? NULL : strdup(_cmd_text);
 
		v->name = reset ? NULL : strdup(text);
 
		InvalidateWindowClassesData(WC_TRAINS_LIST, 1);
 
		MarkWholeScreenDirty();
 
	}
 

	
 
	return CommandCost();
 
}
 
@@ -1694,13 +1694,13 @@ CommandCost CmdRenameVehicle(TileIndex t
 
/** Change the service interval of a vehicle
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID that is being service-interval-changed
 
 * @param p2 new service interval
 
 */
 
CommandCost CmdChangeServiceInt(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdChangeServiceInt(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */
 

	
 
	if (serv_int != p2 || !IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
src/vehicle_gui.cpp
Show inline comments
 
@@ -390,15 +390,15 @@ struct RefitWindow : public Window {
 
							default: NOT_REACHED();
 
							case VEH_TRAIN:    command = CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE);  break;
 
							case VEH_ROAD:     command = CMD_REFIT_ROAD_VEH     | CMD_MSG(STR_REFIT_ROAD_VEHICLE_CAN_T);  break;
 
							case VEH_SHIP:     command = CMD_REFIT_SHIP         | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP);     break;
 
							case VEH_AIRCRAFT: command = CMD_REFIT_AIRCRAFT     | CMD_MSG(STR_A042_CAN_T_REFIT_AIRCRAFT); break;
 
						}
 
						if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8, NULL, command)) delete this;
 
						if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8, command)) delete this;
 
					} else {
 
						if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8 | this->order << 16, NULL, CMD_ORDER_REFIT)) delete this;
 
						if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8 | this->order << 16, CMD_ORDER_REFIT)) delete this;
 
					}
 
				}
 
				break;
 
		}
 
	}
 

	
 
@@ -1060,13 +1060,13 @@ struct VehicleListWindow : public BaseVe
 
				ShowDropDownMenu(this, action_str, 0, VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN, 0, (this->window_number & VLW_MASK) == VLW_STANDARD ? 0 : 1);
 
				break;
 
			}
 

	
 
			case VLW_WIDGET_STOP_ALL:
 
			case VLW_WIDGET_START_ALL:
 
				DoCommandP(0, GB(this->window_number, 16, 16), (this->window_number & VLW_MASK) | (1 << 6) | (widget == VLW_WIDGET_START_ALL ? (1 << 5) : 0) | this->vehicle_type, NULL, CMD_MASS_START_STOP);
 
				DoCommandP(0, GB(this->window_number, 16, 16), (this->window_number & VLW_MASK) | (1 << 6) | (widget == VLW_WIDGET_START_ALL ? (1 << 5) : 0) | this->vehicle_type, CMD_MASS_START_STOP);
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
@@ -1081,19 +1081,17 @@ struct VehicleListWindow : public BaseVe
 
					case 0: /* Replace window */
 
						ShowReplaceGroupVehicleWindow(DEFAULT_GROUP, this->vehicle_type);
 
						break;
 
					case 1: /* Send for servicing */
 
						DoCommandP(0, GB(this->window_number, 16, 16) /* StationID or OrderID (depending on VLW) */,
 
							(this->window_number & VLW_MASK) | DEPOT_MASS_SEND | DEPOT_SERVICE,
 
							NULL,
 
							GetCmdSendToDepot(this->vehicle_type));
 
						break;
 
					case 2: /* Send to Depots */
 
						DoCommandP(0, GB(this->window_number, 16, 16) /* StationID or OrderID (depending on VLW) */,
 
							(this->window_number & VLW_MASK) | DEPOT_MASS_SEND,
 
							NULL,
 
							GetCmdSendToDepot(this->vehicle_type));
 
						break;
 

	
 
					default: NOT_REACHED();
 
				}
 
				break;
 
@@ -1494,13 +1492,13 @@ struct VehicleDetailsWindow : Window {
 
				const Vehicle *v = GetVehicle(this->window_number);
 

	
 
				mod = (widget == VLD_WIDGET_DECREASE_SERVICING_INTERVAL) ? -mod : mod;
 
				mod = GetServiceIntervalClamped(mod + v->service_interval);
 
				if (mod == v->service_interval) return;
 

	
 
				DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
 
				DoCommandP(v->tile, v->index, mod, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
 
			} break;
 

	
 
			case VLD_WIDGET_DETAILS_CARGO_CARRIED:
 
			case VLD_WIDGET_DETAILS_TRAIN_VEHICLES:
 
			case VLD_WIDGET_DETAILS_CAPACITY_OF_EACH:
 
			case VLD_WIDGET_DETAILS_TOTAL_CARGO:
 
@@ -1527,14 +1525,13 @@ struct VehicleDetailsWindow : Window {
 
			STR_9832_CAN_T_NAME_SHIP,
 
			STR_A031_CAN_T_NAME_AIRCRAFT
 
		};
 

	
 
		if (str == NULL) return;
 

	
 
		_cmd_text = str;
 
		DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_VEHICLE | CMD_MSG(_name_vehicle_error[GetVehicle(this->window_number)->type]));
 
		DoCommandP(0, this->window_number, 0, CMD_RENAME_VEHICLE | CMD_MSG(_name_vehicle_error[GetVehicle(this->window_number)->type]), NULL, str);
 
	}
 

	
 
	virtual void OnResize(Point new_size, Point delta)
 
	{
 
		if (delta.x != 0) ResizeButtons(this, VLD_WIDGET_DETAILS_CARGO_CARRIED, VLD_WIDGET_DETAILS_TOTAL_CARGO);
 
		if (delta.y == 0) return;
 
@@ -1949,13 +1946,13 @@ struct VehicleViewWindow : Window {
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		const Vehicle *v = GetVehicle(this->window_number);
 

	
 
		switch (widget) {
 
			case VVW_WIDGET_START_STOP_VEH: // start stop
 
				DoCommandP(v->tile, v->index, 0, NULL,
 
				DoCommandP(v->tile, v->index, 0,
 
										_vehicle_command_translation_table[VCT_CMD_START_STOP][v->type]);
 
				break;
 
			case VVW_WIDGET_CENTER_MAIN_VIEH: {/* center main view */
 
				const Window *mainwindow = FindWindowById(WC_MAIN_WINDOW, 0);
 
				/* code to allow the main window to 'follow' the vehicle if the ctrl key is pressed */
 
				if (_ctrl_pressed && mainwindow->viewport->zoom == ZOOM_LVL_NORMAL) {
 
@@ -1963,13 +1960,13 @@ struct VehicleViewWindow : Window {
 
				} else {
 
					ScrollMainWindowTo(v->x_pos, v->y_pos);
 
				}
 
			} break;
 

	
 
			case VVW_WIDGET_GOTO_DEPOT: // goto hangar
 
				DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL,
 
				DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0,
 
					_vehicle_command_translation_table[VCT_CMD_GOTO_DEPOT][v->type]);
 
				break;
 
			case VVW_WIDGET_REFIT_VEH: // refit
 
				ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID, this);
 
				break;
 
			case VVW_WIDGET_SHOW_ORDERS: // show orders
 
@@ -1980,23 +1977,24 @@ struct VehicleViewWindow : Window {
 
				}
 
				break;
 
			case VVW_WIDGET_SHOW_DETAILS: // show details
 
				ShowVehicleDetailsWindow(v);
 
				break;
 
			case VVW_WIDGET_CLONE_VEH: // clone vehicle
 
				DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneVehicle,
 
										_vehicle_command_translation_table[VCT_CMD_CLONE_VEH][v->type]);
 
				DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0,
 
										_vehicle_command_translation_table[VCT_CMD_CLONE_VEH][v->type],
 
										CcCloneVehicle);
 
				break;
 
			case VVW_WIDGET_TURN_AROUND: // turn around
 
				assert(v->type == VEH_TRAIN || v->type == VEH_ROAD);
 
				DoCommandP(v->tile, v->index, 0, NULL,
 
				DoCommandP(v->tile, v->index, 0,
 
										_vehicle_command_translation_table[VCT_CMD_TURN_AROUND][v->type]);
 
				break;
 
			case VVW_WIDGET_FORCE_PROCEED: // force proceed
 
				assert(v->type == VEH_TRAIN);
 
				DoCommandP(v->tile, v->index, 0, NULL, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_8862_CAN_T_MAKE_TRAIN_PASS_SIGNAL));
 
				DoCommandP(v->tile, v->index, 0, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_8862_CAN_T_MAKE_TRAIN_PASS_SIGNAL));
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnResize(Point new_size, Point delta)
 
	{
src/water_cmd.cpp
Show inline comments
 
@@ -187,13 +187,13 @@ void SetWaterClassDependingOnSurrounding
 
/** Build a ship depot.
 
 * @param tile tile where ship depot is built
 
 * @param flags type of operation
 
 * @param p1 bit 0 depot orientation (Axis)
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	TileIndex tile2;
 

	
 
	CommandCost ret;
 

	
 
	Axis axis = Extract<Axis, 0>(p1);
 
@@ -351,13 +351,13 @@ static CommandCost RemoveShiplift(TileIn
 
/** Builds a lock (ship-lift)
 
 * @param tile tile where to place the lock
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
 
	if (dir == INVALID_DIAGDIR) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 

	
 
	/* Disallow building of locks on river rapids */
 
	if (IsWaterTile(tile)) return_cmd_error(STR_0239_SITE_UNSUITABLE);
 
@@ -368,13 +368,13 @@ CommandCost CmdBuildLock(TileIndex tile,
 
/** Build a piece of canal.
 
 * @param tile end tile of stretch-dragging
 
 * @param flags type of operation
 
 * @param p1 start tile of stretch-dragging
 
 * @param p2 specifies canal (0), water (1) or river (2); last two can only be built in scenario editor
 
 */
 
CommandCost CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	int size_x, size_y;
 
	int x;
 
	int y;
 
	int sx, sy;
src/waypoint.cpp
Show inline comments
 
@@ -187,13 +187,13 @@ void AfterLoadWaypoints()
 
 * @param p1 graphics for waypoint type, 0 indicates standard graphics
 
 * @param p2 unused
 
 *
 
 * @todo When checking for the tile slope,
 
 * distingush between "Flat land required" and "land sloped in wrong direction"
 
 */
 
CommandCost CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Waypoint *wp;
 
	Slope tileh;
 
	Axis axis;
 

	
 
	/* if custom gfx are used, make sure it is within bounds */
 
@@ -349,13 +349,13 @@ CommandCost RemoveTrainWaypoint(TileInde
 
 * @param tile tile where waypoint is to be deleted
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @return cost of operation or error
 
 */
 
CommandCost CmdRemoveTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRemoveTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return RemoveTrainWaypoint(tile, flags, true);
 
}
 

	
 
static bool IsUniqueWaypointName(const char *name)
 
{
 
@@ -376,33 +376,33 @@ static bool IsUniqueWaypointName(const c
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 id of waypoint
 
 * @param p2 unused
 
 * @return cost of operation or error
 
 */
 
CommandCost CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
CommandCost CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidWaypointID(p1)) return CMD_ERROR;
 

	
 
	Waypoint *wp = GetWaypoint(p1);
 
	if (!CheckOwnership(wp->owner)) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(_cmd_text);
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(_cmd_text) >= MAX_LENGTH_WAYPOINT_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueWaypointName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
		if (strlen(text) >= MAX_LENGTH_WAYPOINT_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueWaypointName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		free(wp->name);
 

	
 
		if (reset) {
 
			MakeDefaultWaypointName(wp); // sets wp->name = NULL
 
		} else {
 
			wp->name = strdup(_cmd_text);
 
			wp->name = strdup(text);
 
		}
 

	
 
		UpdateWaypointSign(wp);
 
		MarkWholeScreenDirty();
 
	}
 
	return CommandCost();
src/waypoint_gui.cpp
Show inline comments
 
@@ -91,14 +91,13 @@ public:
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		if (str == NULL) return;
 

	
 
		_cmd_text = str;
 
		DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME));
 
		DoCommandP(0, this->window_number, 0, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME), NULL, str);
 
	}
 

	
 
};
 

	
 
static const Widget _waypoint_view_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},                 // WAYPVW_CLOSEBOX
0 comments (0 inline, 0 general)