Changeset - r9298:06e4a9703da1
[Not reviewed]
master
0 2 0
rubidium - 16 years ago 2008-05-18 17:40:13
rubidium@openttd.org
(svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
2 files changed with 32 insertions and 31 deletions:
0 comments (0 inline, 0 general)
src/road_cmd.cpp
Show inline comments
 
@@ -34,24 +34,55 @@
 
#include "sound_func.h"
 
#include "road_func.h"
 
#include "tunnelbridge.h"
 
#include "cheat_func.h"
 
#include "functions.h"
 
#include "effectvehicle_func.h"
 
#include "elrail_func.h"
 
#include "oldpool_func.h"
 

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

	
 

	
 
bool RoadVehiclesAreBuilt()
 
{
 
	const Vehicle* v;
 

	
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_ROAD) return true;
 
	}
 
	return false;
 
}
 

	
 
/**
 
 * 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)
 
{
 
	/* 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) {
 
		_opt_ptr->road_side = p1;
 
		InvalidateWindow(WC_GAME_OPTIONS, 0);
 
	}
 
	return CommandCost();
 
}
 

	
 
#define M(x) (1 << (x))
 
/* Level crossings may only be built on these slopes */
 
static const uint32 VALID_LEVEL_CROSSING_SLOPES = (M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT));
 
#undef M
 

	
 
/* Invalid RoadBits on slopes  */
 
static const RoadBits _invalid_tileh_slopes_road[2][15] = {
 
	/* The inverse of the mixable RoadBits on a leveled slope */
 
	{
 
		ROAD_NONE,         // SLOPE_FLAT
 
		ROAD_NE | ROAD_SE, // SLOPE_W
 
		ROAD_NE | ROAD_NW, // SLOPE_S
src/settings_gui.cpp
Show inline comments
 
@@ -11,25 +11,24 @@
 
#include "command_func.h"
 
#include "engine_func.h"
 
#include "screenshot.h"
 
#include "newgrf.h"
 
#include "network/network.h"
 
#include "town.h"
 
#include "variables.h"
 
#include "settings_internal.h"
 
#include "newgrf_townname.h"
 
#include "strings_func.h"
 
#include "functions.h"
 
#include "window_func.h"
 
#include "vehicle_base.h"
 
#include "core/alloc_func.hpp"
 
#include "string_func.h"
 
#include "gfx_func.h"
 
#include "waypoint.h"
 
#include "widgets/dropdown_type.h"
 
#include "widgets/dropdown_func.h"
 
#include "station_func.h"
 

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

	
 
static const StringID _units_dropdown[] = {
 
@@ -93,35 +92,24 @@ static int GetCurRes()
 
{
 
	int i;
 

	
 
	for (i = 0; i != _num_resolutions; i++) {
 
		if (_resolutions[i][0] == _screen.width &&
 
				_resolutions[i][1] == _screen.height) {
 
			break;
 
		}
 
	}
 
	return i;
 
}
 

	
 
static inline bool RoadVehiclesAreBuilt()
 
{
 
	const Vehicle* v;
 

	
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_ROAD) return true;
 
	}
 
	return false;
 
}
 

	
 

	
 
enum GameOptionsWidgets {
 
	GAMEOPT_CURRENCY_BTN    =  4,
 
	GAMEOPT_DISTANCE_BTN    =  6,
 
	GAMEOPT_ROADSIDE_BTN    =  8,
 
	GAMEOPT_TOWNNAME_BTN    = 10,
 
	GAMEOPT_AUTOSAVE_BTN    = 12,
 
	GAMEOPT_VEHICLENAME_BTN = 14,
 
	GAMEOPT_VEHICLENAME_SAVE,
 
	GAMEOPT_LANG_BTN        = 17,
 
	GAMEOPT_RESOLUTION_BTN  = 19,
 
	GAMEOPT_FULLSCREEN,
 
	GAMEOPT_SCREENSHOT_BTN  = 22,
 
@@ -190,24 +178,25 @@ struct GameOptionsWindow : Window {
 
	{
 
		switch (widget) {
 
			case GAMEOPT_CURRENCY_BTN: // Setup currencies dropdown
 
				ShowDropDownMenu(this, BuildCurrencyDropdown(), _opt_ptr->currency, GAMEOPT_CURRENCY_BTN, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);
 
				break;
 

	
 
			case GAMEOPT_DISTANCE_BTN: // Setup distance unit dropdown
 
				ShowDropDownMenu(this, _units_dropdown, _opt_ptr->units, GAMEOPT_DISTANCE_BTN, 0, 0);
 
				break;
 

	
 
			case GAMEOPT_ROADSIDE_BTN: { // Setup road-side dropdown
 
				int i = 0;
 
				extern bool RoadVehiclesAreBuilt();
 

	
 
				/* You can only change the drive side if you are in the menu or ingame with
 
				 * no vehicles present. In a networking game only the server can change it */
 
				if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !_network_server)) {
 
					i = (-1) ^ (1 << _opt_ptr->road_side); // disable the other value
 
				}
 

	
 
				ShowDropDownMenu(this, _driveside_dropdown, _opt_ptr->road_side, GAMEOPT_ROADSIDE_BTN, i, 0);
 
			} break;
 

	
 
			case GAMEOPT_TOWNNAME_BTN: // Setup townname dropdown
 
				ShowTownnameDropdown(this, _opt_ptr->town_name);
 
@@ -314,43 +303,24 @@ struct GameOptionsWindow : Window {
 
					this->SetDirty();
 
				}
 
				break;
 

	
 
			case GAMEOPT_SCREENSHOT_BTN: // Change screenshot format
 
				SetScreenshotFormat(index);
 
				this->SetDirty();
 
				break;
 
		}
 
	}
 
};
 

	
 
/** 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)
 
{
 
	/* 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) {
 
		_opt_ptr->road_side = p1;
 
		InvalidateWindow(WC_GAME_OPTIONS, 0);
 
	}
 
	return CommandCost();
 
}
 

	
 
static const Widget _game_options_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                          STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   369,     0,    13, STR_00B1_GAME_OPTIONS,             STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   369,    14,   238, 0x0,                               STR_NULL},
 
{      WWT_FRAME,   RESIZE_NONE,    14,    10,   179,    20,    55, STR_02E0_CURRENCY_UNITS,           STR_NULL},
 
{ WWT_DROPDOWNIN,   RESIZE_NONE,    14,    20,   169,    34,    45, STR_02E1,                          STR_02E2_CURRENCY_UNITS_SELECTION},
 
{      WWT_FRAME,   RESIZE_NONE,    14,   190,   359,    20,    55, STR_MEASURING_UNITS,               STR_NULL},
 
{ WWT_DROPDOWNIN,   RESIZE_NONE,    14,   200,   349,    34,    45, STR_02E4,                          STR_MEASURING_UNITS_SELECTION},
 
{      WWT_FRAME,   RESIZE_NONE,    14,    10,   179,    62,    97, STR_02E6_ROAD_VEHICLES,            STR_NULL},
 
{ WWT_DROPDOWNIN,   RESIZE_NONE,    14,    20,   169,    76,    87, STR_02E7,                          STR_02E8_SELECT_SIDE_OF_ROAD_FOR},
 
{      WWT_FRAME,   RESIZE_NONE,    14,   190,   359,    62,    97, STR_02EB_TOWN_NAMES,               STR_NULL},
 
{ WWT_DROPDOWNIN,   RESIZE_NONE,    14,   200,   349,    76,    87, STR_02EC,                          STR_02ED_SELECT_STYLE_OF_TOWN_NAMES},
0 comments (0 inline, 0 general)