Changeset - r14220:2b66d13ca715
[Not reviewed]
master
0 25 0
rubidium - 15 years ago 2010-01-11 18:46:09
rubidium@openttd.org
(svn r18781) -Codechange: pass the CommandCost to the callback instead of whether it succeeded or not.
-Fix: AIs did update their last cost incorrectly in network games if the cost of the DC_EXEC phase differed from the ~DC_EXEC phase.
25 files changed with 137 insertions and 150 deletions:
0 comments (0 inline, 0 general)
src/ai/ai.hpp
Show inline comments
 
@@ -11,26 +11,24 @@
 

	
 
#ifndef AI_HPP
 
#define AI_HPP
 

	
 
#include "api/ai_event_types.hpp"
 
#include "../date_type.h"
 
#include "../core/string_compare_type.hpp"
 
#include <map>
 

	
 
typedef std::map<const char *, class AIInfo *, StringCompare> AIInfoList;
 

	
 

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

	
 
class AI {
 
public:
 
	/**
 
	 * The default months AIs start after eachother.
 
	 */
 
	enum StartNext {
 
		START_NEXT_EASY   = DAYS_IN_YEAR * 2,
 
		START_NEXT_MEDIUM = DAYS_IN_YEAR,
 
		START_NEXT_HARD   = DAYS_IN_YEAR / 2,
 
		START_NEXT_MIN    = 1,
 
		START_NEXT_MAX    = 3600,
 
		START_NEXT_DEVIATION = 60,
src/ai/ai_core.cpp
Show inline comments
 
@@ -209,32 +209,33 @@
 
		event->Release();
 
		return;
 
	}
 

	
 
	/* Try to send the event to all AIs */
 
	for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
		if (c != skip_company) AI::NewEvent(c, event);
 
	}
 

	
 
	event->Release();
 
}
 

	
 
void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	AIObject::SetLastCommandRes(success);
 
	AIObject::SetLastCommandRes(result.Succeeded());
 

	
 
	if (!success) {
 
		AIObject::SetLastError(AIError::StringToError(_error_message));
 
	if (result.Failed()) {
 
		AIObject::SetLastError(AIError::StringToError(result.GetErrorMessage()));
 
	} else {
 
		AIObject::IncreaseDoCommandCosts(AIObject::GetLastCost());
 
		AIObject::IncreaseDoCommandCosts(result.GetCost());
 
		AIObject::SetLastCost(result.GetCost());
 
	}
 

	
 
	Company::Get(_current_company)->ai_instance->Continue();
 
}
 

	
 
/* static */ void AI::Save(CompanyID company)
 
{
 
	if (!_networking || _network_server) {
 
		Company *c = Company::GetIfValid(company);
 
		assert(c != NULL && c->ai_instance != NULL);
 

	
 
		CompanyID old_company = _current_company;
src/ai/api/ai_object.hpp
Show inline comments
 
@@ -27,25 +27,25 @@ typedef void (AISuspendCallbackProc)(cla
 
/**
 
 * The callback function for Mode-classes.
 
 */
 
typedef bool (AIModeProc)();
 

	
 
/**
 
 * Uper-parent object of all API classes. You should never use this class in
 
 *   your AI, as it doesn't publish any public functions. It is used
 
 *   internally to have a common place to handle general things, like internal
 
 *   command processing, and command-validation checks.
 
 */
 
class AIObject : public SimpleCountedObject {
 
friend void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
friend void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
 
friend class AIInstance;
 
protected:
 
	/**
 
	 * Executes a raw DoCommand for the AI.
 
	 */
 
	static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text = NULL, AISuspendCallbackProc *callback = NULL);
 

	
 
	/**
 
	 * Sets the DoCommand costs counter to a value.
 
	 */
 
	static void SetDoCommandCosts(Money value);
 

	
src/airport_gui.cpp
Show inline comments
 
@@ -22,30 +22,30 @@
 
#include "company_func.h"
 
#include "tilehighlight_func.h"
 
#include "company_base.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 

	
 
static byte _selected_airport_type;
 

	
 
static void ShowBuildAirportPicker(Window *parent);
 

	
 

	
 
void CcBuildAirport(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildAirport(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
		SndPlayTileFx(SND_1F_SPLAT, tile);
 
		if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	}
 
	if (result.Failed()) return;
 

	
 
	SndPlayTileFx(SND_1F_SPLAT, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
}
 

	
 
static void PlaceAirport(TileIndex tile)
 
{
 
	uint32 p2 = _ctrl_pressed;
 
	SB(p2, 16, 16, INVALID_STATION); // no station to join
 

	
 
	CommandContainer cmdcont = { tile, _selected_airport_type, p2, CMD_BUILD_AIRPORT | CMD_MSG(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE), CcBuildAirport, "" };
 
	ShowSelectStationIfNeeded(cmdcont, TileArea(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE));
 
}
 

	
 
/** Widget number of the airport build window. */
src/bridge_gui.cpp
Show inline comments
 
@@ -35,32 +35,32 @@ static BridgeType _last_roadbridge_type 
 
 */
 
struct BuildBridgeData {
 
	BridgeType index;
 
	const BridgeSpec *spec;
 
	Money cost;
 
};
 

	
 
typedef GUIList<BuildBridgeData> GUIBridgeList;
 

	
 
/**
 
 * Callback executed after a build Bridge CMD has been called
 
 *
 
 * @param success True if the build succeded
 
 * @param result Whether the build succeded
 
 * @param tile The tile where the command has been executed
 
 * @param p1 not used
 
 * @param p2 not used
 
 */
 
void CcBuildBridge(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildBridge(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) SndPlayTileFx(SND_27_BLACKSMITH_ANVIL, tile);
 
	if (result.Succeeded()) SndPlayTileFx(SND_27_BLACKSMITH_ANVIL, tile);
 
}
 

	
 
/* Names of the build bridge selection window */
 
enum BuildBridgeSelectionWidgets {
 
	BBSW_CAPTION,
 
	BBSW_DROPDOWN_ORDER,
 
	BBSW_DROPDOWN_CRITERIA,
 
	BBSW_BRIDGE_LIST,
 
	BBSW_SCROLLBAR,
 
};
 

	
 
class BuildBridgeWindow : public Window {
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -1025,25 +1025,25 @@ struct BuildVehicleWindow : Window {
 

	
 
			case BUILD_VEHICLE_WIDGET_SORT_DROPDOWN: // Select sorting criteria dropdown menu
 
				ShowDropDownMenu(this, _sort_listing[this->vehicle_type], this->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0);
 
				break;
 

	
 
			case BUILD_VEHICLE_WIDGET_CARGO_FILTER_DROPDOWN: // Select cargo filtering criteria dropdown menu
 
				ShowDropDownMenu(this, this->cargo_filter_texts, this->cargo_filter_criteria, BUILD_VEHICLE_WIDGET_CARGO_FILTER_DROPDOWN, 0, 0);
 
				break;
 

	
 
			case BUILD_VEHICLE_WIDGET_BUILD: {
 
				EngineID sel_eng = this->sel_engine;
 
				if (sel_eng != INVALID_ENGINE) {
 
					CommandCallback *callback = (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildPrimaryVehicle;
 
					CommandCallback *callback = (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? NULL : CcBuildPrimaryVehicle;
 
					DoCommandP(this->window_number, sel_eng, 0, GetCmdBuildVeh(this->vehicle_type), callback);
 
				}
 
				break;
 
			}
 

	
 
			case BUILD_VEHICLE_WIDGET_RENAME: {
 
				EngineID sel_eng = this->sel_engine;
 
				if (sel_eng != INVALID_ENGINE) {
 
					this->rename_engine = sel_eng;
 
					SetDParam(0, sel_eng);
 
					ShowQueryString(STR_ENGINE_NAME, STR_QUERY_RENAME_TRAIN_TYPE_CAPTION + this->vehicle_type, MAX_LENGTH_ENGINE_NAME_BYTES, MAX_LENGTH_ENGINE_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
 
				}
src/callback_table.cpp
Show inline comments
 
@@ -2,76 +2,30 @@
 

	
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file callback_table.cpp All command callbacks. */
 

	
 
#include "stdafx.h"
 
#include "callback_table.h"
 
#include "command_type.h"
 
#include "command_func.h"
 

	
 
/* If you add a callback for DoCommandP, also add the callback in here
 
 *   see below for the full list!
 
 * If you don't do it, it won't work across the network!! */
 

	
 
/* ai/ai_core.cpp */
 
CommandCallback CcAI;
 

	
 
/* airport_gui.cpp */
 
CommandCallback CcBuildAirport;
 

	
 
/* bridge_gui.cpp */
 
CommandCallback CcBuildBridge;
 

	
 
/* dock_gui.cpp */
 
CommandCallback CcBuildDocks;
 
CommandCallback CcBuildCanal;
 

	
 
/* depot_gui.cpp */
 
CommandCallback CcCloneVehicle;
 

	
 
/* group_gui.cpp */
 
CommandCallback CcCreateGroup;
 

	
 
/* main_gui.cpp */
 
CommandCallback CcPlaySound10;
 
CommandCallback CcPlaceSign;
 
CommandCallback CcTerraform;
 
CommandCallback CcGiveMoney;
 

	
 
/* rail_gui.cpp */
 
CommandCallback CcPlaySound1E;
 
CommandCallback CcRailDepot;
 
CommandCallback CcStation;
 
CommandCallback CcBuildRailTunnel;
 

	
 
/* road_gui.cpp */
 
CommandCallback CcPlaySound1D;
 
CommandCallback CcBuildRoadTunnel;
 
CommandCallback CcRoadDepot;
 

	
 
/* train_gui.cpp */
 
CommandCallback CcBuildWagon;
 

	
 
/* town_gui.cpp */
 
CommandCallback CcFoundTown;
 
CommandCallback CcFoundRandomTown;
 

	
 
/* vehicle_gui.cpp */
 
CommandCallback CcBuildPrimaryVehicle;
 

	
 
CommandCallback * const _callback_table[] = {
 
	/* 0x00 */ NULL,
 
	/* 0x01 */ CcBuildPrimaryVehicle,
 
	/* 0x02 */ CcBuildAirport,
 
	/* 0x03 */ CcBuildBridge,
 
	/* 0x04 */ CcBuildCanal,
 
	/* 0x05 */ CcBuildDocks,
 
	/* 0x06 */ CcFoundTown,
 
	/* 0x07 */ CcBuildRoadTunnel,
 
	/* 0x08 */ CcBuildRailTunnel,
 
	/* 0x09 */ CcBuildWagon,
 
	/* 0x0A */ CcRoadDepot,
src/command.cpp
Show inline comments
 
@@ -626,38 +626,38 @@ bool DoCommandP(TileIndex tile, uint32 p
 

	
 
	if (IsLocalCompany() && _game_mode != GM_EDITOR) {
 
		if (res2.GetCost() != 0 && tile != 0) ShowCostOrIncomeAnimation(x, y, GetSlopeZ(x, y), res2.GetCost());
 
		if (_additional_cash_required != 0) {
 
			SetDParam(0, _additional_cash_required);
 
			if (my_cmd) ShowErrorMessage(error_part1, STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY, x, y);
 
			if (res2.GetCost() == 0) goto callb_err;
 
		}
 
	}
 

	
 
	_docommand_recursive = 0;
 

	
 
	if (callback) callback(true, tile, p1, p2);
 
	if (callback) callback(res2, tile, p1, p2);
 
	ClearStorageChanges(true);
 
	return true;
 

	
 
show_error:
 
	/* show error message if the command fails? */
 
	if (IsLocalCompany() && error_part1 != 0 && my_cmd) {
 
		ShowErrorMessage(error_part1, _error_message, x, y);
 
	}
 

	
 
callb_err:
 
	_docommand_recursive = 0;
 

	
 
	if (callback) callback(false, tile, p1, p2);
 
	if (callback) callback(CMD_ERROR, tile, p1, p2);
 
	ClearStorageChanges(false);
 
	return false;
 
}
 

	
 

	
 
CommandCost CommandCost::AddCost(CommandCost ret)
 
{
 
	this->AddCost(ret.cost);
 
	if (this->success && !ret.success) {
 
		this->message = ret.message;
 
		this->success = false;
 
	}
src/command_func.h
Show inline comments
 
@@ -98,15 +98,61 @@ Money GetAvailableMoneyForCommand();
 
 * @param cmd_flags Flags from GetCommandFlags
 
 * @return flags for DoCommand
 
 */
 
static inline DoCommandFlag CommandFlagsToDCFlags(uint cmd_flags)
 
{
 
	DoCommandFlag flags = DC_NONE;
 
	if (cmd_flags & CMD_NO_WATER) flags |= DC_NO_WATER;
 
	if (cmd_flags & CMD_AUTO) flags |= DC_AUTO;
 
	if (cmd_flags & CMD_ALL_TILES) flags |= DC_ALL_TILES;
 
	return flags;
 
}
 

	
 
/*** All command callbacks that exist ***/
 

	
 
/* ai/ai_core.cpp */
 
CommandCallback CcAI;
 

	
 
/* airport_gui.cpp */
 
CommandCallback CcBuildAirport;
 

	
 
/* bridge_gui.cpp */
 
CommandCallback CcBuildBridge;
 

	
 
/* dock_gui.cpp */
 
CommandCallback CcBuildDocks;
 
CommandCallback CcBuildCanal;
 

	
 
/* depot_gui.cpp */
 
CommandCallback CcCloneVehicle;
 

	
 
/* group_gui.cpp */
 
CommandCallback CcCreateGroup;
 

	
 
/* main_gui.cpp */
 
CommandCallback CcPlaySound10;
 
CommandCallback CcPlaceSign;
 
CommandCallback CcTerraform;
 
CommandCallback CcGiveMoney;
 

	
 
/* rail_gui.cpp */
 
CommandCallback CcPlaySound1E;
 
CommandCallback CcRailDepot;
 
CommandCallback CcStation;
 
CommandCallback CcBuildRailTunnel;
 

	
 
/* road_gui.cpp */
 
CommandCallback CcPlaySound1D;
 
CommandCallback CcBuildRoadTunnel;
 
CommandCallback CcRoadDepot;
 

	
 
/* train_gui.cpp */
 
CommandCallback CcBuildWagon;
 

	
 
/* town_gui.cpp */
 
CommandCallback CcFoundTown;
 
CommandCallback CcFoundRandomTown;
 

	
 
/* vehicle_gui.cpp */
 
CommandCallback CcBuildPrimaryVehicle;
 

	
 
#endif /* COMMAND_FUNC_H */
src/command_type.h
Show inline comments
 
@@ -383,31 +383,31 @@ typedef CommandCost CommandProc(TileInde
 
struct Command {
 
	CommandProc *proc;
 
	byte flags;
 
};
 

	
 
/**
 
 * Define a callback function for the client, after the command is finished.
 
 *
 
 * Functions of this type are called after the command is finished. The parameters
 
 * are from the #CommandProc callback type. The boolean parameter indicates if the
 
 * command succeeded or failed.
 
 *
 
 * @param success If the command succeeded or not.
 
 * @param result The result of the executed command
 
 * @param tile The tile of the command action
 
 * @param p1 Additional data of the command
 
 * @param p1 Additional data of the command
 
 * @see CommandProc
 
 */
 
typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
 

	
 
/**
 
 * Structure for buffering the build command when selecting a station to join.
 
 */
 
struct CommandContainer {
 
	TileIndex tile;            ///< tile command being executed on
 
	uint32 p1;                 ///< parameter p1
 
	uint32 p2;                 ///< parameter p2
 
	uint32 cmd;                ///< command being executed
 
	CommandCallback *callback; ///< any callback function executed upon successful completion of the command
 
	char text[80];             ///< possible text sent for name changes etc
 
};
src/depot_gui.cpp
Show inline comments
 
@@ -112,32 +112,32 @@ static const WindowDesc _ship_depot_desc
 

	
 
static const WindowDesc _aircraft_depot_desc(
 
	WDP_AUTO, 332, 99,
 
	WC_VEHICLE_DEPOT, WC_NONE,
 
	WDF_UNCLICK_BUTTONS,
 
	_nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
 
);
 

	
 
extern void DepotSortList(VehicleList *list);
 

	
 
/**
 
 * This is the Callback method after the cloning attempt of a vehicle
 
 * @param success indicates completion (or not) of the operation
 
 * @param result the result of the cloning command
 
 * @param tile unused
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcCloneVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (!success) return;
 
	if (result.Failed()) return;
 

	
 
	const Vehicle *v = Vehicle::Get(_new_vehicle_id);
 

	
 
	ShowVehicleViewWindow(v);
 
}
 

	
 
static void TrainDepotMoveVehicle(const Vehicle *wagon, VehicleID sel, const Vehicle *head)
 
{
 
	const Vehicle *v = Vehicle::Get(sel);
 

	
 
	if (v == wagon) return;
 

	
src/dock_gui.cpp
Show inline comments
 
@@ -26,35 +26,35 @@
 
#include "slope_func.h"
 
#include "tilehighlight_func.h"
 
#include "company_base.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 

	
 
static void ShowBuildDockStationPicker(Window *parent);
 
static void ShowBuildDocksDepotPicker(Window *parent);
 

	
 
static Axis _ship_depot_direction;
 

	
 
void CcBuildDocks(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildDocks(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
		SndPlayTileFx(SND_02_SPLAT, tile);
 
		if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	}
 
	if (result.Failed()) return;
 

	
 
	SndPlayTileFx(SND_02_SPLAT, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
}
 

	
 
void CcBuildCanal(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildCanal(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) SndPlayTileFx(SND_02_SPLAT, tile);
 
	if (result.Succeeded()) SndPlayTileFx(SND_02_SPLAT, tile);
 
}
 

	
 

	
 
static void PlaceDocks_Dock(TileIndex tile)
 
{
 
	uint32 p2 = (uint32)INVALID_STATION << 16; // no station to join
 

	
 
	/* tile is always the land tile, so need to evaluate _thd.pos */
 
	CommandContainer cmdcont = { tile, _ctrl_pressed, p2, CMD_BUILD_DOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_DOCK_HERE), CcBuildDocks, "" };
 
	ShowSelectStationIfNeeded(cmdcont, TileArea(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE));
 
}
 

	
 
@@ -209,25 +209,24 @@ struct BuildDocksToolbarWindow : Window 
 

	
 
	virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
 
	{
 
		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) {
 
			switch (select_proc) {
 
				case DDSP_BUILD_BRIDGE:
 
					if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
					extern void CcBuildBridge(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
					DoCommandP(end_tile, start_tile, TRANSPORT_WATER << 15, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_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), CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_BUILD_CANALS), CcBuildCanal);
 
					break;
 
				case DDSP_CREATE_RIVER:
 
					DoCommandP(end_tile, start_tile, 2, CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_PLACE_RIVERS), CcBuildCanal);
 
					break;
 

	
src/group_gui.cpp
Show inline comments
 
@@ -476,25 +476,24 @@ public:
 
				const Vehicle *v = this->vehicles[id_v];
 

	
 
				this->vehicle_sel = v->index;
 

	
 
				SetObjectToPlaceWnd(v->GetImage(DIR_W), GetVehiclePalette(v), HT_DRAG, this);
 
				_cursor.vehchain = true;
 

	
 
				this->SetDirty();
 
				break;
 
			}
 

	
 
			case GRP_WIDGET_CREATE_GROUP: { // Create a new group
 
				extern void CcCreateGroup(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
				DoCommandP(0, this->vehicle_type, 0, CMD_CREATE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE), CcCreateGroup);
 
				break;
 
			}
 

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

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

	
 
@@ -716,27 +715,27 @@ static inline VehicleGroupWindow *FindVe
 
{
 
	return (VehicleGroupWindow *)FindWindowById(GetWindowClassForVehicleType(vt), (vt << 11) | VLW_GROUP_LIST | owner);
 
}
 

	
 
/**
 
 * Opens a 'Rename group' window for newly created group
 
 * @param success did command succeed?
 
 * @param tile unused
 
 * @param p1 vehicle type
 
 * @param p2 unused
 
 * @see CmdCreateGroup
 
 */
 
void CcCreateGroup(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (!success) return;
 
	if (result.Failed()) return;
 
	assert(p1 <= VEH_AIRCRAFT);
 

	
 
	VehicleGroupWindow *w = FindVehicleGroupWindow((VehicleType)p1, _current_company);
 
	if (w != NULL) w->ShowRenameGroupWindow(_new_group_id);
 
}
 

	
 
/**
 
 * Removes the highlight of a vehicle in a group window
 
 * @param *v Vehicle to remove all highlights from
 
 */
 
void DeleteGroupHighlightOfVehicle(const Vehicle *v)
 
{
src/gui.h
Show inline comments
 
@@ -12,26 +12,24 @@
 
#ifndef GUI_H
 
#define GUI_H
 

	
 
#include "window_type.h"
 
#include "vehicle_type.h"
 
#include "gfx_type.h"
 
#include "economy_type.h"
 
#include "tile_type.h"
 
#include "strings_type.h"
 
#include "transport_type.h"
 

	
 
/* main_gui.cpp */
 
void CcPlaySound10(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
void CcBuildCanal(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
void HandleOnEditText(const char *str);
 
void InitializeGUI();
 

	
 
/* settings_gui.cpp */
 
void ShowGameOptions();
 
void ShowGameDifficulty();
 
void ShowGameSettings();
 
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right);
 

	
 
/* graph_gui.cpp */
 
void ShowOperatingProfitGraph();
 
void ShowIncomeGraph();
src/main_gui.cpp
Show inline comments
 
@@ -34,28 +34,28 @@
 

	
 
#include "network/network.h"
 
#include "network/network_func.h"
 
#include "network/network_gui.h"
 
#include "network/network_base.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 

	
 
static int _rename_id = 1;
 
static int _rename_what = -1;
 

	
 
void CcGiveMoney(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcGiveMoney(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
#ifdef ENABLE_NETWORK
 
	if (!success || !_settings_game.economy.give_money) return;
 
	if (result.Failed() || !_settings_game.economy.give_money) return;
 

	
 
	/* Inform the company of the action of one of it's clients (controllers). */
 
	char msg[64];
 
	SetDParam(0, p2);
 
	GetString(msg, STR_COMPANY_NAME, lastof(msg));
 

	
 
	if (!_network_server) {
 
		NetworkClientSendChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, p1);
 
	} else {
 
		NetworkServerSendChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, CLIENT_ID_SERVER, p1);
 
	}
 
#endif /* ENABLE_NETWORK */
 
@@ -103,27 +103,27 @@ bool HandlePlacePushButton(Window *w, in
 
	if (w->IsWidgetLowered(widget)) {
 
		ResetObjectToPlace();
 
		return false;
 
	}
 

	
 
	SetObjectToPlace(cursor, PAL_NONE, mode, w->window_class, w->window_number);
 
	w->LowerWidget(widget);
 
	_place_proc = placeproc;
 
	return true;
 
}
 

	
 

	
 
void CcPlaySound10(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcPlaySound10(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) SndPlayTileFx(SND_12_EXPLOSION, tile);
 
	if (result.Succeeded()) SndPlayTileFx(SND_12_EXPLOSION, tile);
 
}
 

	
 
#ifdef ENABLE_NETWORK
 
void ShowNetworkGiveMoneyWindow(CompanyID company)
 
{
 
	_rename_id = company;
 
	_rename_what = 3;
 
	ShowQueryString(STR_EMPTY, STR_NETWORK_GIVE_MONEY_CAPTION, 30, 180, NULL, CS_NUMERAL, QSF_NONE);
 
}
 
#endif /* ENABLE_NETWORK */
 

	
 

	
src/rail_gui.cpp
Show inline comments
 
@@ -57,27 +57,27 @@ struct RailStationGUISettings {
 
	byte station_type;                ///< Station type within the currently selected custom station class (if newstations is \c true )
 
	byte station_count;               ///< Number of custom stations (if newstations is \c true )
 
};
 
static RailStationGUISettings _railstation; ///< Settings of the station builder GUI
 

	
 

	
 
static void HandleStationPlacement(TileIndex start, TileIndex end);
 
static void ShowBuildTrainDepotPicker(Window *parent);
 
static void ShowBuildWaypointPicker(Window *parent);
 
static void ShowStationBuilder(Window *parent);
 
static void ShowSignalBuilder(Window *parent);
 

	
 
void CcPlaySound1E(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcPlaySound1E(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) SndPlayTileFx(SND_20_SPLAT_2, tile);
 
	if (result.Succeeded()) SndPlayTileFx(SND_20_SPLAT_2, tile);
 
}
 

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

	
 
@@ -119,39 +119,39 @@ static void PlaceExtraDepotRail(TileInde
 

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

	
 
/** 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
 
	0x2203, 0x0904, 0x0A05, 0x1103,  // Third additional track
 
};
 

	
 

	
 
void CcRailDepot(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcRailDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
		DiagDirection dir = (DiagDirection)p2;
 
	if (result.Failed()) return;
 

	
 
		SndPlayTileFx(SND_20_SPLAT_2, tile);
 
		if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	DiagDirection dir = (DiagDirection)p2;
 

	
 
		tile += TileOffsByDiagDir(dir);
 
	SndPlayTileFx(SND_20_SPLAT_2, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 

	
 
	tile += TileOffsByDiagDir(dir);
 

	
 
		if (IsTileType(tile, MP_RAILWAY)) {
 
			PlaceExtraDepotRail(tile, _place_depot_extra[dir]);
 
			PlaceExtraDepotRail(tile, _place_depot_extra[dir + 4]);
 
			PlaceExtraDepotRail(tile, _place_depot_extra[dir + 8]);
 
		}
 
	if (IsTileType(tile, MP_RAILWAY)) {
 
		PlaceExtraDepotRail(tile, _place_depot_extra[dir]);
 
		PlaceExtraDepotRail(tile, _place_depot_extra[dir + 4]);
 
		PlaceExtraDepotRail(tile, _place_depot_extra[dir + 8]);
 
	}
 
}
 

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

	
 
static void PlaceRail_Waypoint(TileIndex tile)
 
{
 
@@ -162,31 +162,31 @@ static void PlaceRail_Waypoint(TileIndex
 

	
 
	Axis axis = GetAxisForNewWaypoint(tile);
 
	if (IsValidAxis(axis)) {
 
		/* Valid tile for waypoints */
 
		VpStartPlaceSizing(tile, axis == AXIS_X ? VPM_FIX_X : VPM_FIX_Y, DDSP_BUILD_STATION);
 
	} else {
 
		/* Tile where we can't build rail waypoints. This is always going to fail,
 
		 * but provides the user with a proper error message. */
 
		DoCommandP(tile, 1 << 8 | 1 << 16, STAT_CLASS_WAYP | INVALID_STATION << 16, CMD_BUILD_RAIL_WAYPOINT | CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT));
 
	}
 
}
 

	
 
void CcStation(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcStation(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
		SndPlayTileFx(SND_20_SPLAT_2, tile);
 
		/* Only close the station builder window if the default station and non persistent building is chosen. */
 
		if (_railstation.station_class == STAT_CLASS_DFLT && _railstation.station_type == 0 && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	}
 
	if (result.Failed()) return;
 

	
 
	SndPlayTileFx(SND_20_SPLAT_2, tile);
 
	/* Only close the station builder window if the default station and non persistent building is chosen. */
 
	if (_railstation.station_class == STAT_CLASS_DFLT && _railstation.station_type == 0 && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
}
 

	
 
static void PlaceRail_Station(TileIndex tile)
 
{
 
	if (_remove_button_clicked) {
 
		VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_REMOVE_STATION);
 
		VpSetPlaceSizingLimit(-1);
 
	} else if (_settings_client.gui.station_dragdrop) {
 
		VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_BUILD_STATION);
 
		VpSetPlaceSizingLimit(_settings_game.station.station_spread);
 
	} else {
 
		uint32 p1 = _cur_railtype | _railstation.orientation << 4 | _settings_client.gui.station_numtracks << 8 | _settings_client.gui.station_platlength << 16 | _ctrl_pressed << 24;
 
@@ -249,27 +249,27 @@ static void GenericPlaceSignals(TileInde
 
		DoCommandP(tile, p1, 0, CMD_BUILD_SIGNALS |
 
			CMD_MSG((w != NULL && _convert_signal_button) ? STR_ERROR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE : STR_ERROR_CAN_T_BUILD_SIGNALS_HERE),
 
			CcPlaySound1E);
 
	}
 
}
 

	
 
static void PlaceRail_Bridge(TileIndex tile)
 
{
 
	VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_BUILD_BRIDGE);
 
}
 

	
 
/** Command callback for building a tunnel */
 
void CcBuildRailTunnel(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildRailTunnel(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
	if (result.Succeeded()) {
 
		SndPlayTileFx(SND_20_SPLAT_2, tile);
 
		if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	} else {
 
		SetRedErrorSquare(_build_tunnel_endtile);
 
	}
 
}
 

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

	
src/road_gui.cpp
Show inline comments
 
@@ -53,27 +53,27 @@ enum RoadFlags {
 
	RF_START_HALFROAD_X = 0x08,    // The start tile in X-dir should have only a half road
 
	RF_END_HALFROAD_X   = 0x10,    // The end tile in X-dir should have only a half road
 
};
 
DECLARE_ENUM_AS_BIT_SET(RoadFlags);
 

	
 
static RoadFlags _place_road_flag;
 

	
 
static RoadType _cur_roadtype;
 

	
 
static DiagDirection _road_depot_orientation;
 
static DiagDirection _road_station_picker_orientation;
 

	
 
void CcPlaySound1D(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcPlaySound1D(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) SndPlayTileFx(SND_1F_SPLAT, tile);
 
	if (result.Succeeded()) SndPlayTileFx(SND_1F_SPLAT, tile);
 
}
 

	
 
/**
 
 * Set the initial flags for the road constuction.
 
 * The flags are:
 
 * @li The direction is the X-dir
 
 * @li The first tile has a partitial RoadBit (true or false)
 
 *
 
 * @param tile The start tile
 
 */
 
static void PlaceRoad_X_Dir(TileIndex tile)
 
{
 
@@ -110,27 +110,27 @@ static void PlaceRoad_AutoRoad(TileIndex
 
	_place_road_flag = RF_NONE;
 
	if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X;
 
	if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y;
 
	VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_PLACE_AUTOROAD);
 
}
 

	
 
static void PlaceRoad_Bridge(TileIndex tile)
 
{
 
	VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_BUILD_BRIDGE);
 
}
 

	
 

	
 
void CcBuildRoadTunnel(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildRoadTunnel(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
	if (result.Succeeded()) {
 
		SndPlayTileFx(SND_20_SPLAT_2, tile);
 
		if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	} else {
 
		SetRedErrorSquare(_build_tunnel_endtile);
 
	}
 
}
 

	
 
/** Structure holding information per roadtype for several functions */
 
struct RoadTypeInfo {
 
	StringID err_build_road;        ///< Building a normal piece of road
 
	StringID err_remove_road;       ///< Removing a normal piece of road
 
	StringID err_depot;             ///< Building a depot
 
@@ -182,34 +182,34 @@ static void PlaceRoad_Tunnel(TileIndex t
 

	
 
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, CMD_BUILD_ROAD);
 
		}
 
	}
 
}
 

	
 
void CcRoadDepot(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcRoadDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
		DiagDirection dir = (DiagDirection)GB(p1, 0, 2);
 
		SndPlayTileFx(SND_1F_SPLAT, tile);
 
		if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
		BuildRoadOutsideStation(tile, dir);
 
		/* For a drive-through road stop build connecting road for other entrance */
 
		if (HasBit(p2, 1)) BuildRoadOutsideStation(tile, ReverseDiagDir(dir));
 
	}
 
	if (result.Failed()) return;
 

	
 
	DiagDirection dir = (DiagDirection)GB(p1, 0, 2);
 
	SndPlayTileFx(SND_1F_SPLAT, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	BuildRoadOutsideStation(tile, dir);
 
	/* For a drive-through road stop build connecting road for other entrance */
 
	if (HasBit(p2, 1)) BuildRoadOutsideStation(tile, ReverseDiagDir(dir));
 
}
 

	
 
static void PlaceRoad_Depot(TileIndex tile)
 
{
 
	DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0, CMD_BUILD_ROAD_DEPOT | 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;
 
	SB(p2, 16, 16, INVALID_STATION); // no station to join
 

	
src/signs_cmd.cpp
Show inline comments
 
@@ -96,35 +96,35 @@ CommandCost CmdRenameSign(TileIndex tile
 
			si->sign.MarkDirty();
 
			delete si;
 

	
 
			InvalidateWindowData(WC_SIGN_LIST, 0, 0);
 
		}
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Callback function that is called after a sign is placed
 
 * @param success of the operation
 
 * @param result of the operation
 
 * @param tile unused
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
void CcPlaceSign(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcPlaceSign(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
		ShowRenameSignWindow(Sign::Get(_new_sign_id));
 
		ResetObjectToPlace();
 
	}
 
	if (result.Failed()) return;
 

	
 
	ShowRenameSignWindow(Sign::Get(_new_sign_id));
 
	ResetObjectToPlace();
 
}
 

	
 
/**
 
 *
 
 * 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, CMD_PLACE_SIGN | CMD_MSG(STR_ERROR_CAN_T_PLACE_SIGN_HERE), CcPlaceSign);
 
}
src/terraform_gui.cpp
Show inline comments
 
@@ -27,27 +27,27 @@
 
#include "base_station_base.h"
 
#include "unmovable_map.h"
 
#include "textbuf_gui.h"
 
#include "genworld.h"
 
#include "tree_map.h"
 
#include "landscape_type.h"
 
#include "tilehighlight_func.h"
 
#include "strings_func.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 

	
 
void CcTerraform(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcTerraform(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
	if (result.Succeeded()) {
 
		SndPlayTileFx(SND_1F_SPLAT, tile);
 
	} else {
 
		extern TileIndex _terraform_err_tile;
 
		SetRedErrorSquare(_terraform_err_tile);
 
	}
 
}
 

	
 

	
 
/** Scenario editor command that generates desert areas */
 
static void GenerateDesertArea(TileIndex end, TileIndex start)
 
{
 
	if (_game_mode != GM_EDITOR) return;
 
@@ -136,26 +136,24 @@ bool GUIPlaceProcDragXY(ViewportDragDrop
 
typedef void OnButtonClick(Window *w);
 

	
 
static const uint16 _terraform_keycodes[] = {
 
	'Q',
 
	'W',
 
	'E',
 
	'D',
 
	'U',
 
	'I',
 
	'O',
 
};
 

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

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

	
 
void PlaceProc_DemolishArea(TileIndex tile)
 
{
 
	VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_DEMOLISH_AREA);
 
}
 

	
 
static void PlaceProc_RaiseLand(TileIndex tile)
 
{
src/terraform_gui.h
Show inline comments
 
@@ -5,20 +5,18 @@
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file terraform_gui.h GUI stuff related to terraforming. */
 

	
 
#ifndef TERRAFORM_GUI_H
 
#define TERRAFORM_GUI_H
 

	
 
#include "window_type.h"
 

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

	
 
Window *ShowTerraformToolbar(Window *link = NULL);
 
void ShowTerraformToolbarWithTool(uint16 key, uint16 keycode);
 
Window *ShowEditorTerraformToolbar();
 
void ShowEditorTerraformToolbarWithTool(uint16 key, uint16 keycode);
 

	
 
#endif /* GUI_H */
src/town_gui.cpp
Show inline comments
 
@@ -876,35 +876,35 @@ static const WindowDesc _town_directory_
 
	WDP_AUTO, 208, 202,
 
	WC_TOWN_DIRECTORY, WC_NONE,
 
	WDF_UNCLICK_BUTTONS,
 
	_nested_town_directory_widgets, lengthof(_nested_town_directory_widgets)
 
);
 

	
 
void ShowTownDirectory()
 
{
 
	if (BringWindowToFrontById(WC_TOWN_DIRECTORY, 0)) return;
 
	new TownDirectoryWindow(&_town_directory_desc);
 
}
 

	
 
void CcFoundTown(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcFoundTown(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
		SndPlayTileFx(SND_1F_SPLAT, tile);
 
		if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	}
 
	if (result.Failed()) return;
 

	
 
	SndPlayTileFx(SND_1F_SPLAT, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
}
 

	
 
void CcFoundRandomTown(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcFoundRandomTown(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) ScrollMainWindowToTile(Town::Get(_new_town_id)->xy);
 
	if (result.Succeeded()) ScrollMainWindowToTile(Town::Get(_new_town_id)->xy);
 
}
 

	
 
/** Widget numbers of town scenario editor window. */
 
enum TownScenarioEditorWidgets {
 
	TSEW_BACKGROUND,
 
	TSEW_NEWTOWN,
 
	TSEW_RANDOMTOWN,
 
	TSEW_MANYRANDOMTOWNS,
 
	TSEW_TOWNNAME_TEXT,
 
	TSEW_TOWNNAME_EDITBOX,
 
	TSEW_TOWNNAME_RANDOM,
 
	TSEW_TOWNSIZE,
src/train.h
Show inline comments
 
@@ -35,26 +35,24 @@ enum VehicleRailFlags {
 
	VRF_NO_PATH_TO_DESTINATION = 5,
 

	
 
	/* used to mark that electric train engine is allowed to run on normal rail */
 
	VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL = 6,
 

	
 
	/* used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle only) */
 
	VRF_TOGGLE_REVERSE = 7,
 

	
 
	/* used to mark a train that can't get a path reservation */
 
	VRF_TRAIN_STUCK    = 8,
 
};
 

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

	
 
byte FreightWagonMult(CargoID cargo);
 

	
 
void UpdateTrainAcceleration(Train *v);
 
void CheckTrainsLengths();
 

	
 
void FreeTrainTrackReservation(const Train *v, TileIndex origin = INVALID_TILE, Trackdir orig_td = INVALID_TRACKDIR);
 
bool TryPathReserve(Train *v, bool mark_as_stuck = false, bool first_tile_okay = false);
 

	
 
int GetTrainStopLocation(StationID station_id, TileIndex tile, const Train *v, int *station_ahead, int *station_length);
 

	
 
void TrainConsistChanged(Train *v, bool same_length);
 
void TrainPowerChanged(Train *v);
src/train_gui.cpp
Show inline comments
 
@@ -14,27 +14,27 @@
 
#include "gfx_func.h"
 
#include "command_func.h"
 
#include "vehicle_gui.h"
 
#include "train.h"
 
#include "strings_func.h"
 
#include "vehicle_func.h"
 
#include "engine_base.h"
 
#include "window_func.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 

	
 
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildWagon(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (!success) return;
 
	if (result.Failed()) return;
 

	
 
	/* find a locomotive in the depot. */
 
	const Vehicle *found = NULL;
 
	const Train *t;
 
	FOR_ALL_TRAINS(t) {
 
		if (t->IsFrontEngine() && t->tile == tile &&
 
				t->track == TRACK_BIT_DEPOT) {
 
			if (found != NULL) return; // must be exactly one.
 
			found = t;
 
		}
 
	}
 

	
src/vehicle_func.h
Show inline comments
 
@@ -56,26 +56,24 @@ void AgeVehicle(Vehicle *v);
 
void VehicleEnteredDepotThisTick(Vehicle *v);
 

	
 
void VehicleMove(Vehicle *v, bool update_viewport);
 
void MarkSingleVehicleDirty(const Vehicle *v);
 

	
 
UnitID GetFreeUnitNumber(VehicleType type);
 

	
 
CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id);
 
void VehicleEnterDepot(Vehicle *v);
 

	
 
bool CanBuildVehicleInfrastructure(VehicleType type);
 

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

	
 
/** Position information of a vehicle after it moved */
 
struct GetNewVehiclePosResult {
 
	int x, y;  ///< x and y position of the vehicle after moving
 
	TileIndex old_tile; ///< Current tile of the vehicle
 
	TileIndex new_tile; ///< Tile of the vehicle after moving
 
};
 

	
 
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
 
Direction GetDirectionTowards(const Vehicle *v, int x, int y);
 

	
 
static inline bool IsCompanyBuildableVehicleType(VehicleType type)
 
{
src/vehicle_gui.cpp
Show inline comments
 
@@ -2136,28 +2136,28 @@ void ShowVehicleViewWindow(const Vehicle
 
void StopGlobalFollowVehicle(const Vehicle *v)
 
{
 
	Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
 
	if (w != NULL && w->viewport->follow_vehicle == v->index) {
 
		ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos, true); // lock the main view on the vehicle's last position
 
		w->viewport->follow_vehicle = INVALID_VEHICLE;
 
	}
 
}
 

	
 

	
 
/**
 
 * This is the Callback method after the construction attempt of a primary vehicle
 
 * @param success indicates completion (or not) of the operation
 
 * @param result indicates completion (or not) of the operation
 
 * @param tile unused
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
void CcBuildPrimaryVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildPrimaryVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (!success) return;
 
	if (result.Failed()) return;
 

	
 
	const Vehicle *v = Vehicle::Get(_new_vehicle_id);
 
	if (v->tile == _backup_orders_tile) {
 
		_backup_orders_tile = 0;
 
		RestoreVehicleOrders(v);
 
	}
 
	ShowVehicleViewWindow(v);
 
}
0 comments (0 inline, 0 general)