Changeset - r15610:623a23fb6560
[Not reviewed]
master
! ! !
frosch - 14 years ago 2010-08-01 19:22:34
frosch@openttd.org
(svn r20283) -Codechange: Unify start of doygen comments.
118 files changed:
Changeset was too big and was cut off... Show full diff anyway
0 comments (0 inline, 0 general)
src/ai/api/ai_changelog.hpp
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 ai_changelog.hpp Lists all changes / additions to the API.
 
/**
 
 * @file ai_changelog.hpp Lists all changes / additions to the API.
 
 *
 
 * Only new / renamed / deleted api functions will be listed here. A list of
 
 * bug fixes can be found in the normal changelog. Note that removed API
 
 * functions may still be available if you return an older API version
 
 * in GetAPIVersion() in info.nut.
 
 *
src/ai/api/ai_types.hpp
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 ai_types.hpp Defines all the types of the game, like IDs of various objects.
 
/**
 
 * @file ai_types.hpp Defines all the types of the game, like IDs of various objects.
 
 *
 
 * IDs are used to identify certain objects. They are only unique within the object type, so for example a vehicle may have VehicleID 2009,
 
 * while a station has StationID 2009 at the same time. Also IDs are assigned arbitrary, you cannot assume them to be consecutive.
 
 * Also note, that some IDs are static and never change, while others are allocated dynamically and might be
 
 * reused for other objects once they are released. So be careful, which IDs you store for which purpose and whether they stay valid all the time.
 
 *
src/aircraft.h
Show inline comments
 
@@ -23,31 +23,34 @@ enum AircraftSubType {
 
	AIR_AIRCRAFT   = 2, ///< an airplane
 
	AIR_SHADOW     = 4, ///< shadow of the aircraft
 
	AIR_ROTOR      = 6  ///< rotor of an helicopter
 
};
 

	
 

	
 
/** Handle Aircraft specific tasks when a an Aircraft enters a hangar
 
/**
 
 * Handle Aircraft specific tasks when a an Aircraft enters a hangar
 
 * @param *v Vehicle that enters the hangar
 
 */
 
void HandleAircraftEnterHangar(Aircraft *v);
 

	
 
/** Get the size of the sprite of an aircraft sprite heading west (used for lists)
 
/**
 
 * Get the size of the sprite of an aircraft sprite heading west (used for lists)
 
 * @param engine The engine to get the sprite from
 
 * @param width The width of the sprite
 
 * @param height The height of the sprite
 
 */
 
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height);
 

	
 
/**
 
 * Updates the status of the Aircraft heading or in the station
 
 * @param st Station been updated
 
 */
 
void UpdateAirplanesOnNewStation(const Station *st);
 

	
 
/** Update cached values of an aircraft.
 
/**
 
 * Update cached values of an aircraft.
 
 * Currently caches callback 36 max speed.
 
 * @param v Vehicle
 
 */
 
void UpdateAircraftCache(Aircraft *v);
 

	
 
void AircraftLeaveHangar(Aircraft *v);
src/aircraft_cmd.cpp
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 aircraft_cmd.cpp
 
/**
 
 * @file aircraft_cmd.cpp
 
 * This file deals with aircraft and airport movements functionalities */
 

	
 
#include "stdafx.h"
 
#include "aircraft.h"
 
#include "debug.h"
 
#include "landscape.h"
 
@@ -67,13 +68,14 @@ void Aircraft::UpdateDeltaXY(Direction d
 
	this->y_offs        = GB(x,  8, 8);
 
	this->x_extent      = GB(x, 16, 8);
 
	this->y_extent      = GB(x, 24, 8);
 
}
 

	
 

	
 
/** this maps the terminal to its corresponding state and block flag
 
/**
 
 * this maps the terminal to its corresponding state and block flag
 
 *  currently set for 10 terms, 4 helipads */
 
static const byte _airport_terminal_state[] = {2, 3, 4, 5, 6, 7, 19, 20, 0, 0, 8, 9, 21, 22};
 
static const byte _airport_terminal_flag[] =  {0, 1, 2, 3, 4, 5, 22, 23, 0, 0, 6, 7, 24, 25};
 

	
 
static bool AirportMove(Aircraft *v, const AirportFTAClass *apc);
 
static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc);
 
@@ -97,13 +99,14 @@ enum HelicopterRotorStates {
 
	HRS_ROTOR_STOPPED,
 
	HRS_ROTOR_MOVING_1,
 
	HRS_ROTOR_MOVING_2,
 
	HRS_ROTOR_MOVING_3,
 
};
 

	
 
/** Find the nearest hangar to v
 
/**
 
 * Find the nearest hangar to v
 
 * INVALID_STATION is returned, if the company does not have any suitable
 
 * airports (like helipads only)
 
 * @param v vehicle looking for a hangar
 
 * @return the StationID if one is found, otherwise, INVALID_STATION
 
 */
 
static StationID FindNearestHangar(const Aircraft *v)
 
@@ -134,13 +137,14 @@ static StationID FindNearestHangar(const
 
		}
 
	}
 
	return index;
 
}
 

	
 
#if 0
 
/** Check if given vehicle has a goto hangar in his orders
 
/**
 
 * Check if given vehicle has a goto hangar in his orders
 
 * @param v vehicle to inquiry
 
 * @return true if vehicle v has an airport in the schedule, that has a hangar */
 
static bool HaveHangarInOrderList(Aircraft *v)
 
{
 
	const Order *order;
 

	
 
@@ -210,26 +214,28 @@ void DrawAircraftEngine(int left, int ri
 
		SpriteID rotor_sprite = GetCustomRotorIcon(engine);
 
		if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
 
		DrawSprite(rotor_sprite, PAL_NONE, preferred_x, y - 5);
 
	}
 
}
 

	
 
/** Get the size of the sprite of an aircraft sprite heading west (used for lists)
 
/**
 
 * Get the size of the sprite of an aircraft sprite heading west (used for lists)
 
 * @param engine The engine to get the sprite from
 
 * @param width The width of the sprite
 
 * @param height The height of the sprite
 
 */
 
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height)
 
{
 
	const Sprite *spr = GetSprite(GetAircraftIcon(engine), ST_NORMAL);
 

	
 
	width  = spr->width;
 
	height = spr->height;
 
}
 

	
 
/** Build an aircraft.
 
/**
 
 * Build an aircraft.
 
 * @param tile tile of depot where aircraft is built
 
 * @param flags for command
 
 * @param p1 aircraft type being built (engine)
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -380,13 +386,14 @@ CommandCost CmdBuildAircraft(TileIndex t
 
	}
 

	
 
	return value;
 
}
 

	
 

	
 
/** Sell an aircraft.
 
/**
 
 * Sell an aircraft.
 
 * @param tile unused
 
 * @param flags for command type
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -428,13 +435,14 @@ bool Aircraft::FindClosestDepot(TileInde
 
	if (location    != NULL) *location    = st->xy;
 
	if (destination != NULL) *destination = st->index;
 

	
 
	return true;
 
}
 

	
 
/** Send an aircraft to the hangar.
 
/**
 
 * Send an aircraft to the hangar.
 
 * @param tile unused
 
 * @param flags for command type
 
 * @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)
 
@@ -453,13 +461,14 @@ CommandCost CmdSendAircraftToHangar(Tile
 
	if (v == NULL) return CMD_ERROR;
 

	
 
	return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK));
 
}
 

	
 

	
 
/** Refits an aircraft to the specified cargo type.
 
/**
 
 * Refits an aircraft to the specified cargo type.
 
 * @param tile unused
 
 * @param flags for command type
 
 * @param p1 vehicle ID of the aircraft to refit
 
 * @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
 
@@ -631,13 +640,14 @@ void SetAircraftPosition(Aircraft *v, in
 
		u->z_pos = z + 5;
 

	
 
		VehicleMove(u, true);
 
	}
 
}
 

	
 
/** Handle Aircraft specific tasks when a an Aircraft enters a hangar
 
/**
 
 * Handle Aircraft specific tasks when a an Aircraft enters a hangar
 
 * @param *v Vehicle that enters the hangar
 
 */
 
void HandleAircraftEnterHangar(Aircraft *v)
 
{
 
	v->subspeed = 0;
 
	v->progress = 0;
 
@@ -1949,13 +1959,14 @@ bool Aircraft::Tick()
 
	}
 

	
 
	return true;
 
}
 

	
 

	
 
/** Returns aircraft's target station if v->target_airport
 
/**
 
 * Returns aircraft's target station if v->target_airport
 
 * is a valid station with airport.
 
 * @param v vehicle to get target airport for
 
 * @return pointer to target station, NULL if invalid
 
 */
 
Station *GetTargetAirportIfValid(const Aircraft *v)
 
{
src/airport.cpp
Show inline comments
 
@@ -224,13 +224,14 @@ AirportFTAClass::~AirportFTAClass()
 
			current = next;
 
		};
 
	}
 
	free(layout);
 
}
 

	
 
/** Get the number of elements of a source Airport state automata
 
/**
 
 * Get the number of elements of a source Airport state automata
 
 * Since it is actually just a big array of AirportFTA types, we only
 
 * know one element from the other by differing 'position' identifiers */
 
static uint16 AirportGetNofElements(const AirportFTAbuildup *apFA)
 
{
 
	uint16 nofelements = 0;
 
	int temp = apFA[0].position;
 
@@ -242,13 +243,14 @@ static uint16 AirportGetNofElements(cons
 
		}
 
		if (apFA[i].position == MAX_ELEMENTS) break;
 
	}
 
	return nofelements;
 
}
 

	
 
/** We calculate the terminal/helipod count based on the data passed to us
 
/**
 
 * We calculate the terminal/helipod count based on the data passed to us
 
 * This data (terminals) contains an index as a first element as to how many
 
 * groups there are, and then the number of terminals for each group */
 
static byte AirportGetTerminalCount(const byte *terminals, byte *groups)
 
{
 
	byte nof_terminals = 0;
 
	*groups = 0;
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -27,13 +27,14 @@
 
#include "table/strings.h"
 

	
 
extern void ChangeVehicleViewports(VehicleID from_index, VehicleID to_index);
 
extern void ChangeVehicleNews(VehicleID from_index, VehicleID to_index);
 
extern void ChangeVehicleViewWindow(VehicleID from_index, VehicleID to_index);
 

	
 
/** Figure out if two engines got at least one type of cargo in common (refitting if needed)
 
/**
 
 * Figure out if two engines got at least one type of cargo in common (refitting if needed)
 
 * @param engine_a one of the EngineIDs
 
 * @param engine_b the other EngineID
 
 * @param type the type of the engines
 
 * @return true if they can both carry the same type of cargo (or at least one of them got no capacity at all)
 
 */
 
static bool EnginesHaveCargoInCommon(EngineID engine_a, EngineID engine_b)
 
@@ -88,13 +89,14 @@ bool CheckAutoreplaceValidity(EngineID f
 
	}
 

	
 
	/* the engines needs to be able to carry the same cargo */
 
	return EnginesHaveCargoInCommon(from, to);
 
}
 

	
 
/** Transfer cargo from a single (articulated )old vehicle to the new vehicle chain
 
/**
 
 * Transfer cargo from a single (articulated )old vehicle to the new vehicle chain
 
 * @param old_veh Old vehicle that will be sold
 
 * @param new_head Head of the completely constructed new vehicle chain
 
 * @param part_of_chain The vehicle is part of a train
 
 */
 
static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chain)
 
{
 
@@ -207,13 +209,14 @@ static CargoID GetNewCargoTypeForReplace
 
		}
 

	
 
		return CT_NO_REFIT;
 
	}
 
}
 

	
 
/** Get the EngineID of the replacement for a vehicle
 
/**
 
 * Get the EngineID of the replacement for a vehicle
 
 * @param v The vehicle to find a replacement for
 
 * @param c The vehicle's owner (it's faster to forward the pointer than refinding it)
 
 * @return the EngineID of the replacement. INVALID_ENGINE if no buildable replacement is found
 
 */
 
static EngineID GetNewEngineType(const Vehicle *v, const Company *c)
 
{
 
@@ -235,13 +238,14 @@ static EngineID GetNewEngineType(const V
 
		return v->engine_type;
 
	}
 

	
 
	return INVALID_ENGINE;
 
}
 

	
 
/** Builds and refits a replacement vehicle
 
/**
 
 * Builds and refits a replacement vehicle
 
 * Important: The old vehicle is still in the original vehicle chain (used for determining the cargo when the old vehicle did not carry anything, but the new one does)
 
 * @param old_veh A single (articulated/multiheaded) vehicle that shall be replaced.
 
 * @param new_vehicle Returns the newly build and refittet vehicle
 
 * @param part_of_chain The vehicle is part of a train
 
 * @return cost or error
 
 */
 
@@ -281,35 +285,38 @@ static CommandCost BuildReplacementVehic
 
		DoCommand(0, new_veh->index, true, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
 
	}
 

	
 
	return cost;
 
}
 

	
 
/** Issue a start/stop command
 
/**
 
 * Issue a start/stop command
 
 * @param v a vehicle
 
 * @param evaluate_callback shall the start/stop callback be evaluated?
 
 * @return success or error
 
 */
 
static inline CommandCost StartStopVehicle(const Vehicle *v, bool evaluate_callback)
 
{
 
	return DoCommand(0, v->index, evaluate_callback ? 1 : 0, DC_EXEC | DC_AUTOREPLACE, CMD_START_STOP_VEHICLE);
 
}
 

	
 
/** Issue a train vehicle move command
 
/**
 
 * Issue a train vehicle move command
 
 * @param v The vehicle to move
 
 * @param after The vehicle to insert 'v' after, or NULL to start new chain
 
 * @param flags the command flags to use
 
 * @param whole_chain move all vehicles following 'v' (true), or only 'v' (false)
 
 * @return success or error
 
 */
 
static inline CommandCost MoveVehicle(const Vehicle *v, const Vehicle *after, DoCommandFlag flags, bool whole_chain)
 
{
 
	return DoCommand(0, v->index | (after != NULL ? after->index : INVALID_VEHICLE) << 16, whole_chain ? 1 : 0, flags, CMD_MOVE_RAIL_VEHICLE);
 
}
 

	
 
/** Copy head specific things to the new vehicle chain after it was successfully constructed
 
/**
 
 * Copy head specific things to the new vehicle chain after it was successfully constructed
 
 * @param old_head The old front vehicle (no wagons attached anymore)
 
 * @param new_head The new head of the completely replaced vehicle chain
 
 * @param flags the command flags to use
 
 */
 
static CommandCost CopyHeadSpecificThings(Vehicle *old_head, Vehicle *new_head, DoCommandFlag flags)
 
{
 
@@ -347,13 +354,14 @@ static CommandCost CopyHeadSpecificThing
 
		ChangeVehicleNews(old_head->index, new_head->index);
 
	}
 

	
 
	return cost;
 
}
 

	
 
/** Replace a single unit in a free wagon chain
 
/**
 
 * Replace a single unit in a free wagon chain
 
 * @param single_unit vehicle to let autoreplace/renew operator on
 
 * @param flags command flags
 
 * @param nothing_to_do is set to 'false' when something was done (only valid when not failed)
 
 * @return cost or error
 
 */
 
static CommandCost ReplaceFreeUnit(Vehicle **single_unit, DoCommandFlag flags, bool *nothing_to_do)
 
@@ -395,13 +403,14 @@ static CommandCost ReplaceFreeUnit(Vehic
 
		}
 
	}
 

	
 
	return cost;
 
}
 

	
 
/** Replace a whole vehicle chain
 
/**
 
 * Replace a whole vehicle chain
 
 * @param chain vehicle chain to let autoreplace/renew operator on
 
 * @param flags command flags
 
 * @param wagon_removal remove wagons when the resulting chain occupies more tiles than the old did
 
 * @param nothing_to_do is set to 'false' when something was done (only valid when not failed)
 
 * @return cost or error
 
 */
 
@@ -604,13 +613,14 @@ static CommandCost ReplaceChain(Vehicle 
 
		}
 
	}
 

	
 
	return cost;
 
}
 

	
 
/** Autoreplaces a vehicle
 
/**
 
 * Autoreplaces a 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
 
 * @param text unused
src/autoreplace_gui.cpp
Show inline comments
 
@@ -60,13 +60,14 @@ static int CDECL EngineNumberSorter(cons
 
{
 
	int r = ListPositionOfEngine(*a) - ListPositionOfEngine(*b);
 

	
 
	return r;
 
}
 

	
 
/** Rebuild the left autoreplace list if an engine is removed or added
 
/**
 
 * Rebuild the left autoreplace list if an engine is removed or added
 
 * @param e Engine to check if it is removed or added
 
 * @param id_g The group the engine belongs to
 
 *  Note: this function only works if it is called either
 
 *   - when a new vehicle is build, but before it's counted in num_engines
 
 *   - when a vehicle is deleted and after it's substracted from num_engines
 
 *   - when not changing the count (used when changing replace orders)
 
@@ -81,13 +82,14 @@ void InvalidateAutoreplaceWindow(EngineI
 
		 * Either we just sold the last one, we build a new one or we stopped replacing it.
 
		 * In all cases, we need to update the left list */
 
		InvalidateWindowData(WC_REPLACE_VEHICLE, Engine::Get(e)->type, true);
 
	}
 
}
 

	
 
/** When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
 
/**
 
 * When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
 
 * @param type The type of engine
 
 */
 
void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
 
{
 
	InvalidateWindowData(WC_REPLACE_VEHICLE, type, false); // Update the autoreplace window
 
	InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
 
@@ -102,13 +104,14 @@ class ReplaceVehicleWindow : public Wind
 
	bool replace_engines;         ///< If \c true, engines are replaced, if \c false, wagons are replaced (only for trains).
 
	bool reset_sel_engine;        ///< Also reset #sel_engine while updating left and/or right (#update_left and/or #update_right) and no valid engine selected.
 
	GroupID sel_group;            ///< Group selected to replace.
 
	int details_height;           ///< Minimal needed height of the details panels (found so far).
 
	RailType sel_railtype;        ///< Type of rail tracks selected.
 

	
 
	/** Figure out if an engine should be added to a list.
 
	/**
 
	 * Figure out if an engine should be added to a list.
 
	 * @param e            The EngineID.
 
	 * @param draw_left    If \c true, the left list is drawn (the engines specific to the railtype you selected).
 
	 * @param show_engines If \c true, the locomotives are drawn, else the wagons are drawn (never both).
 
	 * @return \c true if the engine should be in the list (based on this check), else \c false.
 
	 */
 
	bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
 
@@ -123,13 +126,14 @@ class ReplaceVehicleWindow : public Wind
 
			if (rvi->railtype != this->sel_railtype) return false;
 
		}
 
		return true;
 
	}
 

	
 

	
 
	/** Generate an engines list
 
	/**
 
	 * Generate an engines list
 
	 * @param draw_left true if generating the left list, otherwise false
 
	 */
 
	void GenerateReplaceVehList(bool draw_left)
 
	{
 
		EngineID selected_engine = INVALID_ENGINE;
 
		VehicleType type = (VehicleType)this->window_number;
src/bridge.h
Show inline comments
 
@@ -12,13 +12,14 @@
 
#ifndef BRIDGE_H
 
#define BRIDGE_H
 

	
 
#include "gfx_type.h"
 
#include "tile_cmd.h"
 

	
 
/** This enum is related to the definition of bridge pieces,
 
/**
 
 * This enum is related to the definition of bridge pieces,
 
 * which is used to determine the proper sprite table to use
 
 * while drawing a given bridge part.
 
 */
 
enum BridgePieces {
 
	BRIDGE_PIECE_NORTH = 0,
 
	BRIDGE_PIECE_SOUTH,
 
@@ -33,13 +34,14 @@ enum BridgePieces {
 
DECLARE_POSTFIX_INCREMENT(BridgePieces)
 

	
 
static const uint MAX_BRIDGES = 13;
 

	
 
typedef uint BridgeType;
 

	
 
/** Struct containing information about a single bridge type
 
/**
 
 * Struct containing information about a single bridge type
 
 */
 
struct BridgeSpec {
 
	Year avail_year;             ///< the year where it becomes available
 
	byte min_length;             ///< the minimum length (not counting start and end tile)
 
	byte max_length;             ///< the maximum length (not counting start and end tile)
 
	uint16 price;                ///< the price multiplier
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -708,13 +708,14 @@ int DrawVehiclePurchaseInfo(int left, in
 
	y = ShowAdditionalText(left, right, y, engine_number);
 
	if (refittable) y = ShowRefitOptionsList(left, right, y, engine_number);
 

	
 
	return y;
 
}
 

	
 
/** Engine drawing loop
 
/**
 
 * Engine drawing loop
 
 * @param type Type of vehicle (VEH_*)
 
 * @param l The left most location of the list
 
 * @param r The right most location of the list
 
 * @param y The top most location of teh list
 
 * @param eng_list What engines to draw
 
 * @param min where to start in the list
src/cargo_type.h
Show inline comments
 
@@ -84,21 +84,23 @@ public:
 
	/** Reset all entries. */
 
	FORCEINLINE void Clear()
 
	{
 
		memset(this->amount, 0, sizeof(this->amount));
 
	}
 

	
 
	/** Read/write access to an amount of a specific cargo type.
 
	/**
 
	 * Read/write access to an amount of a specific cargo type.
 
	 * @param cargo Cargo type to access.
 
	 */
 
	FORCEINLINE uint &operator[](CargoID cargo)
 
	{
 
		return this->amount[cargo];
 
	}
 

	
 
	/** Read-only access to an amount of a specific cargo type.
 
	/**
 
	 * Read-only access to an amount of a specific cargo type.
 
	 * @param cargo Cargo type to access.
 
	 */
 
	FORCEINLINE const uint &operator[](CargoID cargo) const
 
	{
 
		return this->amount[cargo];
 
	}
src/cargotype.cpp
Show inline comments
 
@@ -19,18 +19,20 @@
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
#include "table/cargo_const.h"
 

	
 
CargoSpec CargoSpec::array[NUM_CARGO];
 

	
 
/** Bitmask of cargo types available.
 
/**
 
 * Bitmask of cargo types available.
 
 * Initialized during a call to #SetupCargoForClimate.
 
 */
 
uint32 _cargo_mask;
 

	
 
/** Set up the default cargo types for the given landscape type.
 
/**
 
 * Set up the default cargo types for the given landscape type.
 
 * @param l Landscape
 
 */
 
void SetupCargoForClimate(LandscapeID l)
 
{
 
	assert(l < lengthof(_default_climate_cargo));
 

	
 
@@ -63,13 +65,14 @@ void SetupCargoForClimate(LandscapeID l)
 
				break;
 
			}
 
		}
 
	}
 
}
 

	
 
/** Get the cargo ID by cargo label.
 
/**
 
 * Get the cargo ID by cargo label.
 
 * @param cl Cargo type to get.
 
 * @return ID number if the cargo exists, else #CT_INVALID
 
 */
 
CargoID GetCargoIDByLabel(CargoLabel cl)
 
{
 
	const CargoSpec *cs;
 
@@ -79,13 +82,14 @@ CargoID GetCargoIDByLabel(CargoLabel cl)
 

	
 
	/* No matching label was found, so it is invalid */
 
	return CT_INVALID;
 
}
 

	
 

	
 
/** Find the CargoID of a 'bitnum' value.
 
/**
 
 * Find the CargoID of a 'bitnum' value.
 
 * @param bitnum 'bitnum' to find.
 
 * @return First CargoID with the given bitnum, or #CT_INVALID if not found or if the provided \a bitnum is invalid.
 
 */
 
CargoID GetCargoIDByBitnum(uint8 bitnum)
 
{
 
	if (bitnum == INVALID_CARGO) return CT_INVALID;
 
@@ -96,13 +100,14 @@ CargoID GetCargoIDByBitnum(uint8 bitnum)
 
	}
 

	
 
	/* No matching label was found, so it is invalid */
 
	return CT_INVALID;
 
}
 

	
 
/** Get sprite for showing cargo of this type.
 
/**
 
 * Get sprite for showing cargo of this type.
 
 * @return Sprite number to use.
 
 */
 
SpriteID CargoSpec::GetCargoIcon() const
 
{
 
	SpriteID sprite = this->sprite;
 
	if (sprite == 0xFFFF) {
src/cargotype.h
Show inline comments
 
@@ -133,13 +133,14 @@ CargoID GetCargoIDByBitnum(uint8 bitnum)
 

	
 
void InitializeSortedCargoSpecs();
 
extern const CargoSpec *_sorted_cargo_specs[NUM_CARGO];
 
extern uint8 _sorted_cargo_specs_size;
 
extern uint8 _sorted_standard_cargo_specs_size;
 

	
 
/** Does cargo \a c have cargo class \a cc?
 
/**
 
 * Does cargo \a c have cargo class \a cc?
 
 * @param c  Cargo type.
 
 * @param cc Cargo class.
 
 * @return The type fits in the class.
 
 */
 
static inline bool IsCargoInClass(CargoID c, CargoClass cc)
 
{
src/company_cmd.cpp
Show inline comments
 
@@ -715,13 +715,14 @@ void CompanyNewsInformation::FillData(co
 

	
 
	this->colour = c->colour;
 
	this->face = c->face;
 

	
 
}
 

	
 
/** Control the companies: add, delete, etc.
 
/**
 
 * Control the companies: add, delete, etc.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 various functionality
 
 * - p1 = 0 - create a new company, Which company (network) it will be is in p2
 
 * - p1 = 1 - create a new AI company
 
 * - p1 = 2 - delete a company. Company is identified by p2
 
@@ -866,13 +867,14 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
		default: return CMD_ERROR;
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Change the company manager's face.
 
/**
 
 * Change the company manager's face.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 face bitmasked
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -887,13 +889,14 @@ CommandCost CmdSetCompanyManagerFace(Til
 
		Company::Get(_current_company)->face = cmf;
 
		MarkWholeScreenDirty();
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Change the company's company-colour
 
/**
 
 * Change the company's company-colour
 
 * @param tile unused
 
 * @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.
 
@@ -996,13 +999,14 @@ static bool IsUniqueCompanyName(const ch
 
		if (c->name != NULL && strcmp(c->name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Change the name of the company.
 
/**
 
 * Change the name of the company.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
@@ -1039,13 +1043,14 @@ static bool IsUniquePresidentName(const 
 
		if (c->president_name != NULL && strcmp(c->president_name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Change the name of the president.
 
/**
 
 * Change the name of the president.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
src/company_gui.cpp
Show inline comments
 
@@ -138,13 +138,14 @@ enum CompanyFinancesWindowWidgets {
 
	CFW_MAXLOAN_VALUE, ///< Max loan widget
 
	CFW_SEL_BUTTONS,   ///< Selection of buttons
 
	CFW_INCREASE_LOAN, ///< Increase loan
 
	CFW_REPAY_LOAN,    ///< Decrease loan
 
};
 

	
 
/** Draw the expenses categories.
 
/**
 
 * Draw the expenses categories.
 
 * @param r Available space for drawing.
 
 * @note The environment must provide padding at the left and right of \a r.
 
 */
 
static void DrawCategories(const Rect &r)
 
{
 
	int y = r.top;
 
@@ -165,13 +166,14 @@ static void DrawCategories(const Rect &r
 
		}
 
	}
 

	
 
	DrawString(r.left, r.right, y + EXP_LINESPACE, STR_FINANCES_TOTAL_CAPTION, TC_FROMSTRING, SA_RIGHT);
 
}
 

	
 
/** Draw an amount of money.
 
/**
 
 * Draw an amount of money.
 
 * @param amount Amount of money to draw,
 
 * @param left   Left coordinate of the space to draw in.
 
 * @param right  Right coordinate of the space to draw in.
 
 * @param top    Top coordinate of the space to draw in.
 
 */
 
static void DrawPrice(Money amount, int left, int right, int top)
 
@@ -182,13 +184,14 @@ static void DrawPrice(Money amount, int 
 
		str++;
 
	}
 
	SetDParam(0, amount);
 
	DrawString(left, right, top, str, TC_FROMSTRING, SA_RIGHT);
 
}
 

	
 
/** Draw a column with prices.
 
/**
 
 * Draw a column with prices.
 
 * @param r    Available space for drawing.
 
 * @param year Year being drawn.
 
 * @param tbl  Pointer to table of amounts for \a year.
 
 * @note The environment must provide padding at the left and right of \a r.
 
 */
 
static void DrawYearColumn(const Rect &r, int year, const Money (*tbl)[EXPENSES_END])
 
@@ -275,13 +278,14 @@ static const NWidgetPart _nested_company
 
			NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, CFW_INCREASE_LOAN), SetFill(1, 0), SetDataTip(STR_FINANCES_BORROW_BUTTON, STR_FINANCES_BORROW_TOOLTIP),
 
			NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, CFW_REPAY_LOAN), SetFill(1, 0), SetDataTip(STR_FINANCES_REPAY_BUTTON, STR_FINANCES_REPAY_TOOLTIP),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
/** Window class displaying the company finances.
 
/**
 
 * Window class displaying the company finances.
 
 * @todo #money_width should be calculated dynamically.
 
 */
 
struct CompanyFinancesWindow : Window {
 
	static Money max_money; ///< The maximum amount of money a company has had this 'run'
 
	bool small;             ///< Window is toggled to 'small'.
 

	
 
@@ -384,13 +388,14 @@ struct CompanyFinancesWindow : Window {
 
			case CFW_LOAN_LINE:
 
				GfxFillRect(r.left, r.top, r.right, r.top, 215);
 
				break;
 
		}
 
	}
 

	
 
	/** Setup the widgets in the nested tree, such that the finances window is displayed properly.
 
	/**
 
	 * Setup the widgets in the nested tree, such that the finances window is displayed properly.
 
	 * @note After setup, the window must be (re-)initialized.
 
	 */
 
	void SetupWidgets()
 
	{
 
		int plane = this->small ? SZSP_NONE : 0;
 
		this->GetWidget<NWidgetStacked>(CFW_SEL_PANEL)->SetDisplayedPlane(plane);
 
@@ -474,13 +479,14 @@ static const WindowDesc _company_finance
 
	WDP_AUTO, 0, 0,
 
	WC_FINANCES, WC_NONE,
 
	WDF_UNCLICK_BUTTONS,
 
	_nested_company_finances_widgets, lengthof(_nested_company_finances_widgets)
 
);
 

	
 
/** Open the finances window of a company.
 
/**
 
 * Open the finances window of a company.
 
 * @param company Company to show finances of.
 
 * @pre is company a valid company.
 
 */
 
void ShowCompanyFinances(CompanyID company)
 
{
 
	if (!Company::IsValidID(company)) return;
 
@@ -1142,13 +1148,14 @@ public:
 
		this->owner = (Owner)this->window_number;
 
		this->face = Company::Get((CompanyID)this->window_number)->face;
 

	
 
		this->UpdateData();
 
	}
 

	
 
	/** Select planes to display to the user with the #NWID_SELECTION widgets #SCMFW_WIDGET_SEL_LOADSAVE, #SCMFW_WIDGET_SEL_MALEFEMALE, and #SCMFW_WIDGET_SEL_PARTS.
 
	/**
 
	 * Select planes to display to the user with the #NWID_SELECTION widgets #SCMFW_WIDGET_SEL_LOADSAVE, #SCMFW_WIDGET_SEL_MALEFEMALE, and #SCMFW_WIDGET_SEL_PARTS.
 
	 * @param advanced Display advanced face management window.
 
	 */
 
	void SelectDisplayPlanes(bool advanced)
 
	{
 
		this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_LOADSAVE)->SetDisplayedPlane(advanced ? 0 : SZSP_NONE);
 
		this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_PARTS)->SetDisplayedPlane(advanced ? 0 : SZSP_NONE);
src/console_internal.h
Show inline comments
 
@@ -21,13 +21,14 @@ static const uint ICON_MAX_STREAMSIZE = 
 
enum ConsoleHookResult {
 
	CHR_ALLOW,    ///< Allow command execution.
 
	CHR_DISALLOW, ///< Disallow command execution.
 
	CHR_HIDE,     ///< Hide the existence of the command.
 
};
 

	
 
/** --Commands--
 
/**
 
 * --Commands--
 
 * Commands are commands, or functions. They get executed once and any
 
 * effect they produce are carried out. The arguments to the commands
 
 * are given to them, each input word seperated by a double-quote (") is an argument
 
 * If you want to handle multiple words as one, enclose them in double-quotes
 
 * eg. 'say "hello sexy boy"'
 
 */
 
@@ -38,13 +39,14 @@ struct IConsoleCmd {
 
	IConsoleCmd *next;        ///< next command in list
 

	
 
	IConsoleCmdProc *proc;    ///< process executed when command is typed
 
	IConsoleHook *hook;       ///< any special trigger action that needs executing
 
};
 

	
 
/** --Aliases--
 
/**
 
 * --Aliases--
 
 * Aliases are like shortcuts for complex functions, variable assignments,
 
 * etc. You can use a simple alias to rename a longer command (eg 'set' for
 
 * 'setting' for example), or concatenate more commands into one
 
 * (eg. 'ng' for 'load %A; unpause; debug_level 5'). Aliases can parse the arguments
 
 * given to them in the command line.
 
 * - "%A - %Z" substitute arguments 1 t/m 26
src/core/bitmath_func.hpp
Show inline comments
 
@@ -31,13 +31,14 @@
 
template <typename T>
 
static FORCEINLINE uint GB(const T x, const uint8 s, const uint8 n)
 
{
 
	return (x >> s) & ((1U << n) - 1);
 
}
 

	
 
/** Set \a n bits in \a x starting at bit \a s to \a d
 
/**
 
 * Set \a n bits in \a x starting at bit \a s to \a d
 
 *
 
 * This function sets \a n bits from \a x which started as bit \a s to the value of
 
 * \a d. The parameters \a x, \a s and \a n works the same as the parameters of
 
 * #GB. The result is saved in \a x again. Unused bits in the window
 
 * provided by n are set to 0 if the value of \a d isn't "big" enough.
 
 * This is not a bug, its a feature.
 
@@ -56,13 +57,14 @@ static FORCEINLINE T SB(T &x, const uint
 
{
 
	x &= (T)(~(((1U << n) - 1) << s));
 
	x |= (T)(d << s);
 
	return x;
 
}
 

	
 
/** Add i to n bits of x starting at bit s.
 
/**
 
 * Add i to n bits of x starting at bit s.
 
 *
 
 * This add the value of i on n bits of x starting at bit s. The parameters x,
 
 * s, i are similar to #GB besides x must be a variable as the result are
 
 * saved there. An overflow does not affect the following bits of the given
 
 * bit window and is simply ignored.
 
 *
src/core/enum_type.hpp
Show inline comments
 
@@ -37,23 +37,25 @@
 
	FORCEINLINE mask_t& operator |= (mask_t& m1, mask_t m2) {m1 = m1 | m2; return m1;} \
 
	FORCEINLINE mask_t& operator &= (mask_t& m1, mask_t m2) {m1 = m1 & m2; return m1;} \
 
	FORCEINLINE mask_t& operator ^= (mask_t& m1, mask_t m2) {m1 = m1 ^ m2; return m1;} \
 
	FORCEINLINE mask_t operator ~(mask_t m) {return (mask_t)(~(int)m);}
 

	
 

	
 
/** Informative template class exposing basic enumeration properties used by several
 
/**
 
 * Informative template class exposing basic enumeration properties used by several
 
 *  other templates below. Here we have only forward declaration. For each enum type
 
 *  we will create specialization derived from MakeEnumPropsT<>.
 
 *  i.e.:
 
 *    template <> struct EnumPropsT<Track> : MakeEnumPropsT<Track, byte, TRACK_BEGIN, TRACK_END, INVALID_TRACK> {};
 
 *  followed by:
 
 *    typedef TinyEnumT<Track> TrackByte;
 
 */
 
template <typename Tenum_t> struct EnumPropsT;
 

	
 
/** Helper template class that makes basic properties of given enumeration type visible
 
/**
 
 * Helper template class that makes basic properties of given enumeration type visible
 
 *  from outsize. It is used as base class of several EnumPropsT specializations each
 
 *  dedicated to one of commonly used enumeration types.
 
 *  @param Tenum_t enumeration type that you want to describe
 
 *  @param Tstorage_t what storage type would be sufficient (i.e. byte)
 
 *  @param Tbegin first valid value from the contiguous range (i.e. TRACK_BEGIN)
 
 *  @param Tend one past the last valid value from the contiguous range (i.e. TRACK_END)
 
@@ -69,13 +71,14 @@ struct MakeEnumPropsT {
 
	static const Tenum_t invalid = Tinvalid;  ///< what value is used as invalid value (i.e. INVALID_TRACKDIR)
 
	static const uint num_bits = Tnum_bits;   ///< Number of bits for storing the enum in command parameters
 
};
 

	
 

	
 

	
 
/** In some cases we use byte or uint16 to store values that are defined as enum. It is
 
/**
 
 * In some cases we use byte or uint16 to store values that are defined as enum. It is
 
 *  necessary in order to control the sizeof() such values. Some compilers make enum
 
 *  the same size as int (4 or 8 bytes instead of 1 or 2). As a consequence the strict
 
 *  compiler type - checking causes errors like:
 
 *     'HasPowerOnRail' : cannot convert parameter 1 from 'byte' to 'RailType' when
 
 *  u->u.rail.railtype is passed as argument or type RailType. In such cases it is better
 
 *  to teach the compiler that u->u.rail.railtype is to be treated as RailType. */
src/core/random_func.hpp
Show inline comments
 
@@ -62,22 +62,24 @@ extern Randomizer _interactive_random; /
 
/** Stores the state of all random number generators */
 
struct SavedRandomSeeds {
 
	Randomizer random;
 
	Randomizer interactive_random;
 
};
 

	
 
/** Saves the current seeds
 
/**
 
 * Saves the current seeds
 
 * @param storage Storage for saving
 
 */
 
static inline void SaveRandomSeeds(SavedRandomSeeds *storage)
 
{
 
	storage->random = _random;
 
	storage->interactive_random = _interactive_random;
 
}
 

	
 
/** Restores previously saved seeds
 
/**
 
 * Restores previously saved seeds
 
 * @param storage Storage where SaveRandomSeeds() stored th seeds
 
 */
 
static inline void RestoreRandomSeeds(const SavedRandomSeeds &storage)
 
{
 
	_random = storage.random;
 
	_interactive_random = storage.interactive_random;
src/core/smallmap_type.hpp
Show inline comments
 
@@ -22,13 +22,14 @@ struct SmallPair {
 
	U second;
 

	
 
	/** Initializes this Pair with data */
 
	FORCEINLINE SmallPair(const T &first, const U &second) : first(first), second(second) { }
 
};
 

	
 
/** Implementation of simple mapping class. Both types have to be POD ("Plain Old Data")!
 
/**
 
 * Implementation of simple mapping class. Both types have to be POD ("Plain Old Data")!
 
 * It has inherited accessors from SmallVector().
 
 * @see SmallVector
 
 */
 
template <typename T, typename U, uint S = 16>
 
struct SmallMap : SmallVector<SmallPair<T, U>, S> {
 
	typedef ::SmallPair<T, U> Pair;
 
@@ -37,35 +38,38 @@ struct SmallMap : SmallVector<SmallPair<
 

	
 
	/** Creates new SmallMap. Data are initialized in SmallVector constructor */
 
	FORCEINLINE SmallMap() { }
 
	/** Data are freed in SmallVector destructor */
 
	FORCEINLINE ~SmallMap() { }
 

	
 
	/** Finds given key in this map
 
	/**
 
	 * Finds given key in this map
 
	 * @param key key to find
 
	 * @return &Pair(key, data) if found, this->End() if not
 
	 */
 
	FORCEINLINE Pair *Find(const T &key)
 
	{
 
		for (uint i = 0; i < this->items; i++) {
 
			if (key == this->data[i].first) return &this->data[i];
 
		}
 
		return this->End();
 
	}
 

	
 
	/** Removes given pair from this map
 
	/**
 
	 * Removes given pair from this map
 
	 * @param pair pair to remove
 
	 * @note it has to be pointer to pair in this map. It is overwritten by the last item.
 
	 */
 
	FORCEINLINE void Erase(Pair *pair)
 
	{
 
		assert(pair >= this->Begin() && pair < this->End());
 
		*pair = this->data[--this->items];
 
	}
 

	
 
	/** Removes given key from this map
 
	/**
 
	 * Removes given key from this map
 
	 * @param key key to remove
 
	 * @return true iff the key was found
 
	 * @note last item is moved to its place, so don't increase your iterator if true is returned!
 
	 */
 
	FORCEINLINE bool Erase(const T &key)
 
	{
 
@@ -75,13 +79,14 @@ struct SmallMap : SmallVector<SmallPair<
 
				return true;
 
			}
 
		}
 
		return false;
 
	}
 

	
 
	/** Adds new item to this map.
 
	/**
 
	 * Adds new item to this map.
 
	 * @param key key
 
	 * @param data data
 
	 * @return true iff the key wasn't already present
 
	 */
 
	FORCEINLINE bool Insert(const T &key, const U &data)
 
	{
 
@@ -89,13 +94,14 @@ struct SmallMap : SmallVector<SmallPair<
 
		Pair *n = this->Append();
 
		n->first = key;
 
		n->second = data;
 
		return true;
 
	}
 

	
 
	/** Returns data belonging to this key
 
	/**
 
	 * Returns data belonging to this key
 
	 * @param key key
 
	 * @return data belonging to this key
 
	 * @note if this key wasn't present, new entry is created
 
	 */
 
	FORCEINLINE U &operator[](const T &key)
 
	{
src/debug.cpp
Show inline comments
 
@@ -158,13 +158,14 @@ void SetDebugString(const char *s)
 
			ShowInfoF("Unknown debug level '%.*s'", (int)(s - t), t);
 
			return;
 
		}
 
	}
 
}
 

	
 
/** Print out the current debug-level
 
/**
 
 * Print out the current debug-level
 
 * Just return a string with the values of all the debug categorites
 
 * @return string with debug-levels
 
 */
 
const char *GetDebugString()
 
{
 
	const DebugLevel *i;
src/depot_gui.cpp
Show inline comments
 
@@ -156,13 +156,14 @@ static void TrainDepotMoveVehicle(const 
 

	
 
	if (wagon == v) return;
 

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

	
 
/** Array containing the cell size in pixels of the #DEPOT_WIDGET_MATRIX widget for each vehicle type.
 
/**
 
 * Array containing the cell size in pixels of the #DEPOT_WIDGET_MATRIX widget for each vehicle type.
 
 * @note The train vehicle type uses the entire row for each train. */
 
static Dimension _base_block_sizes[4];
 

	
 
static void InitBlocksizeForShipAircraft(VehicleType type)
 
{
 
	uint max_width  = 0;
 
@@ -191,13 +192,14 @@ static void InitBlocksizeForShipAircraft
 
			_base_block_sizes[VEH_AIRCRAFT].width = max(67U, max_width);
 
			break;
 
	}
 
	_base_block_sizes[type].height = max(GetVehicleHeight(type), max_height);
 
}
 

	
 
/** Set the size of the blocks in the window so we can be sure that they are big enough for the vehicle sprites in the current game.
 
/**
 
 * Set the size of the blocks in the window so we can be sure that they are big enough for the vehicle sprites in the current game.
 
 * @note Calling this function once for each game is enough. */
 
void InitDepotWindowBlockSizes()
 
{
 
	_base_block_sizes[VEH_TRAIN].width = 0;
 
	_base_block_sizes[VEH_TRAIN].height = GetVehicleHeight(VEH_TRAIN);
 

	
 
@@ -241,13 +243,14 @@ struct DepotWindow : Window {
 

	
 
	~DepotWindow()
 
	{
 
		DeleteWindowById(WC_BUILD_VEHICLE, this->window_number);
 
	}
 

	
 
	/** Draw a vehicle in the depot window in the box with the top left corner at x,y.
 
	/**
 
	 * Draw a vehicle in the depot window in the box with the top left corner at x,y.
 
	 * @param v     Vehicle to draw.
 
	 * @param left  Left side of the box to draw in.
 
	 * @param right Right side of the box to draw in.
 
	 * @param y     Top of the box to draw in.
 
	 */
 
	void DrawVehicleInDepot(const Vehicle *v, int left, int right, int y) const
 
@@ -454,13 +457,14 @@ struct DepotWindow : Window {
 

	
 
		d->wagon = (v != NULL ? v->GetFirstEnginePart() : NULL);
 

	
 
		return MODE_DRAG_VEHICLE;
 
	}
 

	
 
	/** Handle click in the depot matrix.
 
	/**
 
	 * Handle click in the depot matrix.
 
	 * @param x Horizontal position in the matrix widget in pixels.
 
	 * @param y Vertical position in the matrix widget in pixels.
 
	 */
 
	void DepotClick(int x, int y)
 
	{
 
		GetDepotVehiclePtData gdvp = { NULL, NULL };
 
@@ -1028,13 +1032,14 @@ static void DepotSellAllConfirmationCall
 
		TileIndex tile = w->window_number;
 
		byte vehtype = w->type;
 
		DoCommandP(tile, vehtype, 0, CMD_DEPOT_SELL_ALL_VEHICLES);
 
	}
 
}
 

	
 
/** Opens a depot window
 
/**
 
 * Opens a depot window
 
 * @param tile The tile where the depot/hangar is located
 
 * @param type The type of vehicles in the depot
 
 */
 
void ShowDepotWindow(TileIndex tile, VehicleType type)
 
{
 
	if (BringWindowToFrontById(WC_VEHICLE_DEPOT, tile) != NULL) return;
 
@@ -1048,13 +1053,14 @@ void ShowDepotWindow(TileIndex tile, Veh
 
		case VEH_AIRCRAFT: desc = &_aircraft_depot_desc; break;
 
	}
 

	
 
	new DepotWindow(desc, tile, type);
 
}
 

	
 
/** Removes the highlight of a vehicle in a depot window
 
/**
 
 * Removes the highlight of a vehicle in a depot window
 
 * @param *v Vehicle to remove all highlights from
 
 */
 
void DeleteDepotHighlightOfVehicle(const Vehicle *v)
 
{
 
	DepotWindow *w;
 

	
src/disaster_cmd.cpp
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 disaster_cmd.cpp
 
/**
 
 * @file disaster_cmd.cpp
 
 * All disaster/easter egg vehicles are handled here.
 
 * The general flow of control for the disaster vehicles is as follows:
 
 * <ol>
 
 * <li>Initialize the disaster in a disaster specific way (eg start position,
 
 *     possible target, etc.) Disaster_XXX_Init() function
 
 * <li>Add a subtype to a disaster, which is an index into the function array
 
@@ -125,13 +126,14 @@ static void DisasterVehicleUpdateImage(D
 
{
 
	SpriteID img = v->image_override;
 
	if (img == 0) img = _disaster_images[v->subtype][v->direction];
 
	v->cur_image = img;
 
}
 

	
 
/** Initialize a disaster vehicle. These vehicles are of type VEH_DISASTER, are unclickable
 
/**
 
 * Initialize a disaster vehicle. These vehicles are of type VEH_DISASTER, are unclickable
 
 * and owned by nobody */
 
static void InitializeDisasterVehicle(DisasterVehicle *v, int x, int y, byte z, Direction direction, byte subtype)
 
{
 
	v->x_pos = x;
 
	v->y_pos = y;
 
	v->z_pos = z;
 
@@ -667,13 +669,14 @@ bool DisasterVehicle::Tick()
 
	return _disastervehicle_tick_procs[this->subtype](this);
 
}
 

	
 
typedef void DisasterInitProc();
 

	
 

	
 
/** Zeppeliner which crashes on a small airport if one found,
 
/**
 
 * Zeppeliner which crashes on a small airport if one found,
 
 * otherwise crashes on a random tile */
 
static void Disaster_Zeppeliner_Init()
 
{
 
	if (!Vehicle::CanAllocateItem(2)) return;
 

	
 
	/* Pick a random place, unless we find a small airport */
 
@@ -695,13 +698,14 @@ static void Disaster_Zeppeliner_Init()
 
	v->SetNext(u);
 
	InitializeDisasterVehicle(u, x, 0, 0, DIR_SE, ST_ZEPPELINER_SHADOW);
 
	u->vehstatus |= VS_SHADOW;
 
}
 

	
 

	
 
/** Ufo which flies around aimlessly from the middle of the map a bit
 
/**
 
 * Ufo which flies around aimlessly from the middle of the map a bit
 
 * until it locates a road vehicle which it targets and then destroys */
 
static void Disaster_Small_Ufo_Init()
 
{
 
	if (!Vehicle::CanAllocateItem(2)) return;
 

	
 
	DisasterVehicle *v = new DisasterVehicle();
 
@@ -841,13 +845,14 @@ static void Disaster_Small_Submarine_Ini
 
static void Disaster_Big_Submarine_Init()
 
{
 
	Disaster_Submarine_Init(ST_BIG_SUBMARINE);
 
}
 

	
 

	
 
/** Coal mine catastrophe, destroys a stretch of 30 tiles of
 
/**
 
 * Coal mine catastrophe, destroys a stretch of 30 tiles of
 
 * land in a certain direction */
 
static void Disaster_CoalMine_Init()
 
{
 
	int index = GB(Random(), 0, 4);
 
	uint m;
 

	
 
@@ -924,13 +929,14 @@ void DisasterDailyLoop()
 

	
 
void StartupDisasters()
 
{
 
	ResetDisasterDelay();
 
}
 

	
 
/** Marks all disasters targeting this industry in such a way
 
/**
 
 * Marks all disasters targeting this industry in such a way
 
 * they won't call Industry::Get(v->dest_tile) on invalid industry anymore.
 
 * @param i deleted industry
 
 */
 
void ReleaseDisastersTargetingIndustry(IndustryID i)
 
{
 
	DisasterVehicle *v;
 
@@ -940,13 +946,14 @@ void ReleaseDisastersTargetingIndustry(I
 
			/* if it has chosen target, and it is this industry (yes, dest_tile is IndustryID here), set order to "leaving map peacefully" */
 
			if (v->current_order.GetDestination() > 0 && v->dest_tile == i) v->current_order.SetDestination(3);
 
		}
 
	}
 
}
 

	
 
/** Notify disasters that we are about to delete a vehicle. So make them head elsewhere.
 
/**
 
 * Notify disasters that we are about to delete a vehicle. So make them head elsewhere.
 
 * @param vehicle deleted vehicle
 
 */
 
void ReleaseDisastersTargetingVehicle(VehicleID vehicle)
 
{
 
	DisasterVehicle *v;
 
	FOR_ALL_DISASTERVEHICLES(v) {
src/driver.cpp
Show inline comments
 
@@ -192,13 +192,14 @@ char *DriverFactoryBase::GetDriversInfo(
 
		p += seprintf(p, last, "\n");
 
	}
 

	
 
	return p;
 
}
 

	
 
/** Frees memory used for this->name
 
/**
 
 * Frees memory used for this->name
 
 */
 
DriverFactoryBase::~DriverFactoryBase()
 
{
 
	if (this->name == NULL) return;
 

	
 
	/* Prefix the name with driver type to make it unique */
src/driver.h
Show inline comments
 
@@ -76,13 +76,14 @@ public:
 
	DriverFactoryBase() :
 
		name(NULL)
 
	{}
 

	
 
	virtual ~DriverFactoryBase();
 

	
 
	/** Shuts down all active drivers
 
	/**
 
	 * Shuts down all active drivers
 
	 */
 
	static void ShutdownDrivers()
 
	{
 
		for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
 
			Driver *driver = *GetActiveDriver(dt);
 
			if (driver != NULL) driver->Stop();
src/economy.cpp
Show inline comments
 
@@ -153,13 +153,14 @@ Money CalculateCompanyValue(const Compan
 
	if (including_loan) value -= c->current_loan;
 
	value += c->money;
 

	
 
	return max(value, (Money)1);
 
}
 

	
 
/** if update is set to true, the economy is updated with this score
 
/**
 
 * if update is set to true, the economy is updated with this score
 
 *  (also the house is updated, should only be true in the on-tick event)
 
 * @param update the economy with calculated score
 
 * @param c company been evaluated
 
 * @return actual score of this company
 
 * */
 
int UpdateCompanyRatingAndValue(Company *c, bool update)
 
@@ -1482,13 +1483,14 @@ static void DoAcquireCompany(Company *c)
 

	
 
	delete c;
 
}
 

	
 
extern int GetAmountOwnedBy(const Company *c, Owner owner);
 

	
 
/** Acquire shares in an opposing company.
 
/**
 
 * 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
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -1529,13 +1531,14 @@ CommandCost CmdBuyShareInCompany(TileInd
 
		}
 
		SetWindowDirty(WC_COMPANY, target_company);
 
	}
 
	return cost;
 
}
 

	
 
/** Sell shares in an opposing company.
 
/**
 
 * 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
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -1562,13 +1565,14 @@ CommandCost CmdSellShareInCompany(TileIn
 
		*b = COMPANY_SPECTATOR;
 
		SetWindowDirty(WC_COMPANY, target_company);
 
	}
 
	return CommandCost(EXPENSES_OTHER, cost);
 
}
 

	
 
/** Buy up another company.
 
/**
 
 * Buy up another company.
 
 * When a competing company is gone bankrupt you get the chance to purchase
 
 * that company.
 
 * @todo currently this only works for AI companies
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 company to buy up
src/elrail.cpp
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 elrail.cpp
 
/**
 
 * @file elrail.cpp
 
 * This file deals with displaying wires and pylons for electric railways.
 
 * <h2>Basics</h2>
 
 *
 
 * <h3>Tile Types</h3>
 
 *
 
 * We have two different types of tiles in the drawing code:
 
@@ -179,13 +180,14 @@ static inline SpriteID GetPylonBase(Tile
 
{
 
	const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
 
	SpriteID pylons = GetCustomRailSprite(rti, tile, RTSG_PYLONS, upper_halftile);
 
	return pylons == 0 ? SPR_PYLON_BASE : pylons;
 
}
 

	
 
/** Corrects the tileh for certain tile types. Returns an effective tileh for the track on the tile.
 
/**
 
 * Corrects the tileh for certain tile types. Returns an effective tileh for the track on the tile.
 
 * @param tile The tile to analyse
 
 * @param *tileh the tileh
 
 */
 
static void AdjustTileh(TileIndex tile, Slope *tileh)
 
{
 
	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
@@ -255,13 +257,14 @@ void DrawCatenaryOnTunnel(const TileInfo
 
		GetTileZ(ti->tile) + sss->z_offset,
 
		IsTransparencySet(TO_CATENARY),
 
		BB_data[0] - sss->x_offset, BB_data[1] - sss->y_offset, BB_Z_SEPARATOR - sss->z_offset
 
	);
 
}
 

	
 
/** Draws wires and, if required, pylons on a given tile
 
/**
 
 * Draws wires and, if required, pylons on a given tile
 
 * @param ti The Tileinfo to draw the tile for
 
 */
 
static void DrawCatenaryRailway(const TileInfo *ti)
 
{
 
	/* Pylons are placed on a tile edge, so we need to take into account
 
	 * the track configuration of 2 adjacent tiles. trackconfig[0] stores the
src/endian_check.cpp
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 endian_check.cpp
 
/**
 
 * @file endian_check.cpp
 
 * This pretty simple file checks if the system is LITTLE_ENDIAN or BIG_ENDIAN
 
 *  it does that by putting a 1 and a 0 in an array, and read it out as one
 
 *  number. If it is 1, it is LITTLE_ENDIAN, if it is 256, it is BIG_ENDIAN
 
 *
 
 * After that it outputs the contents of an include files (endian.h)
 
 *  that says or TTD_LITTLE_ENDIAN, or TTD_BIG_ENDIAN. Makefile takes
src/engine.cpp
Show inline comments
 
@@ -35,13 +35,14 @@
 

	
 
EnginePool _engine_pool("Engine");
 
INSTANTIATE_POOL_METHODS(Engine)
 

	
 
EngineOverrideManager _engine_mngr;
 

	
 
/** Year that engine aging stops. Engines will not reduce in reliability
 
/**
 
 * Year that engine aging stops. Engines will not reduce in reliability
 
 * and no more engines will be introduced */
 
static Year _year_engine_aging_stops;
 

	
 
/** Number of engines of each vehicle type in original engine data */
 
const uint8 _engine_counts[4] = {
 
	lengthof(_orig_rail_vehicle_info),
 
@@ -396,13 +397,14 @@ EngineID EngineOverrideManager::GetID(Ve
 
			return index;
 
		}
 
	}
 
	return INVALID_ENGINE;
 
}
 

	
 
/** Sets cached values in Company::num_vehicles and Group::num_vehicles
 
/**
 
 * Sets cached values in Company::num_vehicles and Group::num_vehicles
 
 */
 
void SetCachedEngineCounts()
 
{
 
	size_t engines = Engine::GetPoolSize();
 

	
 
	/* Set up the engine count for all companies */
 
@@ -650,13 +652,14 @@ void EnginesDailyLoop()
 
				if (IsInteractiveCompany(best_company)) ShowEnginePreviewWindow(i);
 
			}
 
		}
 
	}
 
}
 

	
 
/** Accept an engine prototype. XXX - it is possible that the top-company
 
/**
 
 * Accept an engine prototype. XXX - it is possible that the top-company
 
 * 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
 
 * @param text unused
 
@@ -763,13 +766,14 @@ static bool IsUniqueEngineName(const cha
 
		if (e->name != NULL && strcmp(e->name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Rename an engine.
 
/**
 
 * Rename an engine.
 
 * @param tile unused
 
 * @param flags operation to perfom
 
 * @param p1 engine ID to rename
 
 * @param p2 unused
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
@@ -799,13 +803,14 @@ CommandCost CmdRenameEngine(TileIndex ti
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 

	
 
/** Check if an engine is buildable.
 
/**
 
 * Check if an engine is buildable.
 
 * @param engine  index of the engine to check.
 
 * @param type    the type the engine should be.
 
 * @param company index of the company.
 
 * @return True if an engine is valid, of the specified type, and buildable by
 
 *              the given company.
 
 */
src/engine_gui.cpp
Show inline comments
 
@@ -21,13 +21,14 @@
 
#include "company_func.h"
 
#include "rail.h"
 
#include "settings_type.h"
 

	
 
#include "table/strings.h"
 

	
 
/** Return the category of an engine.
 
/**
 
 * Return the category of an engine.
 
 * @param engine Engine to examine.
 
 * @return String describing the category ("road veh", "train". "airplane", or "ship") of the engine.
 
 */
 
StringID GetEngineCategoryName(EngineID engine)
 
{
 
	const Engine *e = Engine::Get(engine);
 
@@ -289,26 +290,28 @@ void DrawVehicleEngine(int left, int rig
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/** Sort all items using quick sort and given 'CompareItems' function
 
/**
 
 * Sort all items using quick sort and given 'CompareItems' function
 
 * @param el list to be sorted
 
 * @param compare function for evaluation of the quicksort
 
 */
 
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
 
{
 
	uint size = el->Length();
 
	/* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
 
	 * generally, do not sort if there are less than 2 items */
 
	if (size < 2) return;
 
	QSortT(el->Begin(), size, compare);
 
}
 

	
 
/** Sort selected range of items (on indices @ <begin, begin+num_items-1>)
 
/**
 
 * Sort selected range of items (on indices @ <begin, begin+num_items-1>)
 
 * @param el list to be sorted
 
 * @param compare function for evaluation of the quicksort
 
 * @param begin start of sorting
 
 * @param num_items count of items to be sorted
 
 */
 
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
src/engine_type.h
Show inline comments
 
@@ -100,13 +100,14 @@ struct RoadVehicleInfo {
 
	uint8 weight;            ///< Weight in 1/4t units
 
	uint8 power;             ///< Power in 10hp units
 
	uint8 tractive_effort;   ///< Coefficient of tractive effort
 
	uint8 air_drag;          ///< Coefficient of air drag
 
};
 

	
 
/** Information about a vehicle
 
/**
 
 * Information about a vehicle
 
 *  @see table/engines.h
 
 */
 
struct EngineInfo {
 
	Date base_intro;
 
	Year lifelength;    ///< Lifetime of a single vehicle
 
	Year base_life;     ///< Basic duration of engine availability (without random parts)
src/fios.cpp
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 fios.cpp
 
/**
 
 * @file fios.cpp
 
 * This file contains functions for building file lists for the save/load dialogs.
 
 */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "core/sort_func.hpp"
 
@@ -259,13 +260,14 @@ bool FiosFileScanner::AddFile(const char
 
	str_validate(fios->title, lastof(fios->title));
 

	
 
	return true;
 
}
 

	
 

	
 
/** Fill the list of the files in a directory, according to some arbitrary rule.
 
/**
 
 * Fill the list of the files in a directory, according to some arbitrary rule.
 
 *  @param mode The mode we are in. Some modes don't allow 'parent'.
 
 *  @param callback_proc The function that is called where you need to do the filtering.
 
 *  @param subdir The directory from where to start (global) searching.
 
 */
 
static void FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc *callback_proc, Subdirectory subdir)
 
{
src/fios_gui.cpp
Show inline comments
 
@@ -693,13 +693,14 @@ static const WindowDesc _save_dialog_des
 
	WDP_CENTER, 500, 294,
 
	WC_SAVELOAD, WC_NONE,
 
	WDF_UNCLICK_BUTTONS,
 
	_nested_save_dialog_widgets, lengthof(_nested_save_dialog_widgets)
 
);
 

	
 
/** These values are used to convert the file/operations mode into a corresponding file type.
 
/**
 
 * These values are used to convert the file/operations mode into a corresponding file type.
 
 * So each entry, as expressed by the related comment, is based on the enum   */
 
static const FileType _file_modetotype[] = {
 
	FT_SAVEGAME,  ///< used for SLD_LOAD_GAME
 
	FT_SCENARIO,  ///< used for SLD_LOAD_SCENARIO
 
	FT_SAVEGAME,  ///< used for SLD_SAVE_GAME
 
	FT_SCENARIO,  ///< used for SLD_SAVE_SCENARIO
src/fontcache.cpp
Show inline comments
 
@@ -39,13 +39,14 @@ static int _ascender[FS_END];
 

	
 
FreeTypeSettings _freetype;
 

	
 
static const byte FACE_COLOUR   = 1;
 
static const byte SHADOW_COLOUR = 2;
 

	
 
/** Get the font loaded into a Freetype face by using a font-name.
 
/**
 
 * Get the font loaded into a Freetype face by using a font-name.
 
 * If no appropiate font is found, the function returns an error */
 
#ifdef WIN32
 
#include <windows.h>
 
#include <shlobj.h> /* SHGetFolderPath */
 
#include "os/windows/win32.h"
 

	
src/gamelog.cpp
Show inline comments
 
@@ -36,23 +36,25 @@ static GamelogActionType _gamelog_action
 

	
 
LoggedAction *_gamelog_action = NULL;        ///< first logged action
 
uint _gamelog_actions         = 0;           ///< number of actions
 
static LoggedAction *_current_action = NULL; ///< current action we are logging, NULL when there is no action active
 

	
 

	
 
/** Stores information about new action, but doesn't allocate it
 
/**
 
 * Stores information about new action, but doesn't allocate it
 
 * Action is allocated only when there is at least one change
 
 * @param at type of action
 
 */
 
void GamelogStartAction(GamelogActionType at)
 
{
 
	assert(_gamelog_action_type == GLAT_NONE); // do not allow starting new action without stopping the previous first
 
	_gamelog_action_type = at;
 
}
 

	
 
/** Stops logging of any changes
 
/**
 
 * Stops logging of any changes
 
 */
 
void GamelogStopAction()
 
{
 
	assert(_gamelog_action_type != GLAT_NONE); // nobody should try to stop if there is no action in progress
 

	
 
	bool print = _current_action != NULL;
 
@@ -60,13 +62,14 @@ void GamelogStopAction()
 
	_current_action = NULL;
 
	_gamelog_action_type = GLAT_NONE;
 

	
 
	if (print) GamelogPrintDebug(5);
 
}
 

	
 
/** Resets and frees all memory allocated - used before loading or starting a new game
 
/**
 
 * Resets and frees all memory allocated - used before loading or starting a new game
 
 */
 
void GamelogReset()
 
{
 
	assert(_gamelog_action_type == GLAT_NONE);
 

	
 
	for (uint i = 0; i < _gamelog_actions; i++) {
 
@@ -100,26 +103,28 @@ static void AddDebugText(char *buf, cons
 
	va_start(va, s);
 
	_dbgofs += vsnprintf(buf + _dbgofs, GAMELOG_BUF_LEN - _dbgofs, s, va);
 
	va_end(va);
 
}
 

	
 

	
 
/** Prints GRF filename if found
 
/**
 
 * Prints GRF filename if found
 
 * @param buf The location in the _dbgofs buffer to draw
 
 * @param grfid GRF which filename to print
 
 */
 
static void PrintGrfFilename(char *buf, uint grfid)
 
{
 
	const GRFConfig *gc = FindGRFConfig(grfid);
 

	
 
	if (gc == NULL) return;
 

	
 
	AddDebugText(buf, ", filename: %s", gc->filename);
 
}
 

	
 
/** Prints GRF ID, checksum and filename if found
 
/**
 
 * Prints GRF ID, checksum and filename if found
 
 * @param buf The location in the _dbgofs buffer to draw
 
 * @param grfid GRF ID
 
 * @param md5sum array of md5sum to print
 
 */
 
static void PrintGrfInfo(char *buf, uint grfid, const uint8 *md5sum)
 
{
 
@@ -289,25 +294,27 @@ static int _gamelog_print_level = 0; ///
 
static void GamelogPrintDebugProc(const char *s)
 
{
 
	DEBUG(gamelog, _gamelog_print_level, "%s", s);
 
}
 

	
 

	
 
/** Prints gamelog to debug output. Code is executed even when
 
/**
 
 * Prints gamelog to debug output. Code is executed even when
 
 * there will be no output. It is called very seldom, so it
 
 * doesn't matter that much. At least it gives more uniform code...
 
 * @param level debug level we need to print stuff
 
 */
 
void GamelogPrintDebug(int level)
 
{
 
	_gamelog_print_level = level;
 
	GamelogPrint(&GamelogPrintDebugProc);
 
}
 

	
 

	
 
/** Allocates new LoggedChange and new LoggedAction if needed.
 
/**
 
 * Allocates new LoggedChange and new LoggedAction if needed.
 
 * If there is no action active, NULL is returned.
 
 * @param ct type of change
 
 * @return new LoggedChange, or NULL if there is no action active
 
 */
 
static LoggedChange *GamelogChange(GamelogChangeType ct)
 
{
 
@@ -329,24 +336,26 @@ static LoggedChange *GamelogChange(Gamel
 
	lc->ct = ct;
 

	
 
	return lc;
 
}
 

	
 

	
 
/** Logs a emergency savegame
 
/**
 
 * Logs a emergency savegame
 
 */
 
void GamelogEmergency()
 
{
 
	/* Terminate any active action */
 
	if (_gamelog_action_type != GLAT_NONE) GamelogStopAction();
 
	GamelogStartAction(GLAT_EMERGENCY);
 
	GamelogChange(GLCT_EMERGENCY);
 
	GamelogStopAction();
 
}
 

	
 
/** Finds out if current game is a loaded emergency savegame.
 
/**
 
 * Finds out if current game is a loaded emergency savegame.
 
 */
 
bool GamelogTestEmergency()
 
{
 
	const LoggedChange *emergency = NULL;
 

	
 
	const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
 
@@ -357,13 +366,14 @@ bool GamelogTestEmergency()
 
		}
 
	}
 

	
 
	return (emergency != NULL);
 
}
 

	
 
/** Logs a change in game revision
 
/**
 
 * Logs a change in game revision
 
 */
 
void GamelogRevision()
 
{
 
	assert(_gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_LOAD);
 

	
 
	LoggedChange *lc = GamelogChange(GLCT_REVISION);
 
@@ -373,39 +383,42 @@ void GamelogRevision()
 
	strecpy(lc->revision.text, _openttd_revision, lastof(lc->revision.text));
 
	lc->revision.slver = SAVEGAME_VERSION;
 
	lc->revision.modified = _openttd_revision_modified;
 
	lc->revision.newgrf = _openttd_newgrf_version;
 
}
 

	
 
/** Logs a change in game mode (scenario editor or game)
 
/**
 
 * Logs a change in game mode (scenario editor or game)
 
 */
 
void GamelogMode()
 
{
 
	assert(_gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_CHEAT);
 

	
 
	LoggedChange *lc = GamelogChange(GLCT_MODE);
 
	if (lc == NULL) return;
 

	
 
	lc->mode.mode      = _game_mode;
 
	lc->mode.landscape = _settings_game.game_creation.landscape;
 
}
 

	
 
/** Logs loading from savegame without gamelog
 
/**
 
 * Logs loading from savegame without gamelog
 
 */
 
void GamelogOldver()
 
{
 
	assert(_gamelog_action_type == GLAT_LOAD);
 

	
 
	LoggedChange *lc = GamelogChange(GLCT_OLDVER);
 
	if (lc == NULL) return;
 

	
 
	lc->oldver.type = _savegame_type;
 
	lc->oldver.version = (_savegame_type == SGT_OTTD ? ((uint32)_sl_version << 8 | _sl_minor_version) : _ttdp_version);
 
}
 

	
 
/** Logs change in game settings. Only non-networksafe settings are logged
 
/**
 
 * Logs change in game settings. Only non-networksafe settings are logged
 
 * @param name setting name
 
 * @param oldval old setting value
 
 * @param newval new setting value
 
 */
 
void GamelogSetting(const char *name, int32 oldval, int32 newval)
 
{
 
@@ -417,13 +430,14 @@ void GamelogSetting(const char *name, in
 
	lc->setting.name = strdup(name);
 
	lc->setting.oldval = oldval;
 
	lc->setting.newval = newval;
 
}
 

	
 

	
 
/** Finds out if current revision is different than last revision stored in the savegame.
 
/**
 
 * Finds out if current revision is different than last revision stored in the savegame.
 
 * Appends GLCT_REVISION when the revision string changed
 
 */
 
void GamelogTestRevision()
 
{
 
	const LoggedChange *rev = NULL;
 

	
 
@@ -439,13 +453,14 @@ void GamelogTestRevision()
 
			rev->revision.modified != _openttd_revision_modified ||
 
			rev->revision.newgrf != _openttd_newgrf_version) {
 
		GamelogRevision();
 
	}
 
}
 

	
 
/** Finds last stored game mode or landscape.
 
/**
 
 * Finds last stored game mode or landscape.
 
 * Any change is logged
 
 */
 
void GamelogTestMode()
 
{
 
	const LoggedChange *mode = NULL;
 

	
 
@@ -458,13 +473,14 @@ void GamelogTestMode()
 
	}
 

	
 
	if (mode == NULL || mode->mode.mode != _game_mode || mode->mode.landscape != _settings_game.game_creation.landscape) GamelogMode();
 
}
 

	
 

	
 
/** Logs triggered GRF bug.
 
/**
 
 * Logs triggered GRF bug.
 
 * @param grfid ID of problematic GRF
 
 * @param bug type of bug, @see enum GRFBugs
 
 * @param data additional data
 
 */
 
static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data)
 
{
 
@@ -475,13 +491,14 @@ static void GamelogGRFBug(uint32 grfid, 
 

	
 
	lc->grfbug.data  = data;
 
	lc->grfbug.grfid = grfid;
 
	lc->grfbug.bug   = bug;
 
}
 

	
 
/** Logs GRF bug - rail vehicle has different length after reversing.
 
/**
 
 * Logs GRF bug - rail vehicle has different length after reversing.
 
 * Ensures this is logged only once for each GRF and engine type
 
 * This check takes some time, but it is called pretty seldom, so it
 
 * doesn't matter that much (ideally it shouldn't be called at all).
 
 * @param grfid the broken NewGRF
 
 * @param internal_id the internal ID of whatever's broken in the NewGRF
 
 * @return true iff a unique record was done
 
@@ -504,35 +521,38 @@ bool GamelogGRFBugReverse(uint32 grfid, 
 
	GamelogStopAction();
 

	
 
	return true;
 
}
 

	
 

	
 
/** Decides if GRF should be logged
 
/**
 
 * Decides if GRF should be logged
 
 * @param g grf to determine
 
 * @return true iff GRF is not static and is loaded
 
 */
 
static inline bool IsLoggableGrfConfig(const GRFConfig *g)
 
{
 
	return !HasBit(g->flags, GCF_STATIC) && g->status != GCS_NOT_FOUND;
 
}
 

	
 
/** Logs removal of a GRF
 
/**
 
 * Logs removal of a GRF
 
 * @param grfid ID of removed GRF
 
 */
 
void GamelogGRFRemove(uint32 grfid)
 
{
 
	assert(_gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_GRF);
 

	
 
	LoggedChange *lc = GamelogChange(GLCT_GRFREM);
 
	if (lc == NULL) return;
 

	
 
	lc->grfrem.grfid = grfid;
 
}
 

	
 
/** Logs adding of a GRF
 
/**
 
 * Logs adding of a GRF
 
 * @param newg added GRF
 
 */
 
void GamelogGRFAdd(const GRFConfig *newg)
 
{
 
	assert(_gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_GRF);
 

	
 
@@ -541,13 +561,14 @@ void GamelogGRFAdd(const GRFConfig *newg
 
	LoggedChange *lc = GamelogChange(GLCT_GRFADD);
 
	if (lc == NULL) return;
 

	
 
	lc->grfadd = newg->ident;
 
}
 

	
 
/** Logs loading compatible GRF
 
/**
 
 * Logs loading compatible GRF
 
 * (the same ID, but different MD5 hash)
 
 * @param newg new (updated) GRF
 
 */
 
void GamelogGRFCompatible(const GRFIdentifier *newg)
 
{
 
	assert(_gamelog_action_type == GLAT_LOAD || _gamelog_action_type == GLAT_GRF);
 
@@ -555,13 +576,14 @@ void GamelogGRFCompatible(const GRFIdent
 
	LoggedChange *lc = GamelogChange(GLCT_GRFCOMPAT);
 
	if (lc == NULL) return;
 

	
 
	lc->grfcompat = *newg;
 
}
 

	
 
/** Logs changing GRF order
 
/**
 
 * Logs changing GRF order
 
 * @param grfid GRF that is moved
 
 * @param offset how far it is moved, positive = moved down
 
 */
 
static void GamelogGRFMove(uint32 grfid, int32 offset)
 
{
 
	assert(_gamelog_action_type == GLAT_GRF);
 
@@ -570,13 +592,14 @@ static void GamelogGRFMove(uint32 grfid,
 
	if (lc == NULL) return;
 

	
 
	lc->grfmove.grfid  = grfid;
 
	lc->grfmove.offset = offset;
 
}
 

	
 
/** Logs change in GRF parameters.
 
/**
 
 * Logs change in GRF parameters.
 
 * Details about parameters changed are not stored
 
 * @param grfid ID of GRF to store
 
 */
 
static void GamelogGRFParameters(uint32 grfid)
 
{
 
	assert(_gamelog_action_type == GLAT_GRF);
 
@@ -584,13 +607,14 @@ static void GamelogGRFParameters(uint32 
 
	LoggedChange *lc = GamelogChange(GLCT_GRFPARAM);
 
	if (lc == NULL) return;
 

	
 
	lc->grfparam.grfid = grfid;
 
}
 

	
 
/** Logs adding of list of GRFs.
 
/**
 
 * Logs adding of list of GRFs.
 
 * Useful when old savegame is loaded or when new game is started
 
 * @param newg head of GRF linked list
 
 */
 
void GamelogGRFAddList(const GRFConfig *newg)
 
{
 
	assert(_gamelog_action_type == GLAT_START || _gamelog_action_type == GLAT_LOAD);
 
@@ -603,13 +627,14 @@ void GamelogGRFAddList(const GRFConfig *
 
/** List of GRFs using array of pointers instead of linked list */
 
struct GRFList {
 
	uint n;
 
	const GRFConfig *grf[];
 
};
 

	
 
/** Generates GRFList
 
/**
 
 * Generates GRFList
 
 * @param grfc head of GRF linked list
 
 */
 
static GRFList *GenerateGRFList(const GRFConfig *grfc)
 
{
 
	uint n = 0;
 
	for (const GRFConfig *g = grfc; g != NULL; g = g->next) {
 
@@ -623,13 +648,14 @@ static GRFList *GenerateGRFList(const GR
 
		if (IsLoggableGrfConfig(g)) list->grf[list->n++] = g;
 
	}
 

	
 
	return list;
 
}
 

	
 
/** Compares two NewGRF lists and logs any change
 
/**
 
 * Compares two NewGRF lists and logs any change
 
 * @param oldc original GRF list
 
 * @param newc new GRF list
 
 */
 
void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
 
{
 
	GRFList *ol = GenerateGRFList(oldc);
src/gfx.cpp
Show inline comments
 
@@ -65,13 +65,14 @@ static void GfxMainBlitter(const Sprite 
 
struct DrawStringParams {
 
	FontSize fontsize;
 
	TextColour cur_colour, prev_colour;
 

	
 
	DrawStringParams(TextColour colour) : fontsize(FS_NORMAL), cur_colour(colour), prev_colour(colour) {}
 

	
 
	/** Switch to new colour \a c.
 
	/**
 
	 * Switch to new colour \a c.
 
	 * @param c New colour to use.
 
	 */
 
	FORCEINLINE void SetColour(TextColour c)
 
	{
 
		assert(c >=  TC_BLUE && c <= TC_BLACK);
 
		this->prev_colour = this->cur_colour;
 
@@ -81,13 +82,14 @@ struct DrawStringParams {
 
	/** Switch to previous colour. */
 
	FORCEINLINE void SetPreviousColour()
 
	{
 
		Swap(this->cur_colour, this->prev_colour);
 
	}
 

	
 
	/** Switch to using a new font \a f.
 
	/**
 
	 * Switch to using a new font \a f.
 
	 * @param f New font to use.
 
	 */
 
	FORCEINLINE void SetFontSize(FontSize f)
 
	{
 
		this->fontsize = f;
 
	}
 
@@ -355,13 +357,14 @@ static UChar *HandleBiDiAndArabicShapes(
 
	input_output[length] = '\0';
 
	return input_output;
 
}
 
#endif /* WITH_ICU */
 

	
 

	
 
/** Truncate a given string to a maximum width if neccessary.
 
/**
 
 * Truncate a given string to a maximum width if neccessary.
 
 * If the string is truncated, add three dots ('...') to show this.
 
 * @param *str string that is checked and possibly truncated
 
 * @param maxw maximum width in pixels of the string
 
 * @param ignore_setxy whether to ignore SETX(Y) or not
 
 * @param start_fontsize Fontsize to start the text with
 
 * @return new width of (truncated) string
 
@@ -755,13 +758,14 @@ end_of_inner_loop:
 
			for (; str[-1] != '\0';) *s++ = *str++;
 
		}
 
	}
 
}
 

	
 

	
 
/** Calculates height of string (in pixels). Accepts multiline string with '\0' as separators.
 
/**
 
 * Calculates height of string (in pixels). Accepts multiline string with '\0' as separators.
 
 * @param src string to check
 
 * @param num number of extra lines (output of FormatStringLinebreaks())
 
 * @param start_fontsize Fontsize to start the text with
 
 * @note assumes text won't be truncated. FormatStringLinebreaks() is a good way to ensure that.
 
 * @return height of pixels of string when it is drawn
 
 */
 
@@ -784,13 +788,14 @@ static int GetMultilineStringHeight(cons
 
			default:           maxy = max<int>(maxy, y + fh);       break;
 
		}
 
	}
 
}
 

	
 

	
 
/** Calculates height of string (in pixels). The string is changed to a multiline string if needed.
 
/**
 
 * Calculates height of string (in pixels). The string is changed to a multiline string if needed.
 
 * @param str string to check
 
 * @param maxw maximum string width
 
 * @return height of pixels of string when it is drawn
 
 */
 
int GetStringHeight(StringID str, int maxw)
 
{
 
@@ -800,13 +805,14 @@ int GetStringHeight(StringID str, int ma
 

	
 
	uint32 tmp = FormatStringLinebreaks(buffer, lastof(buffer), maxw);
 

	
 
	return GetMultilineStringHeight(buffer, GB(tmp, 0, 16), FS_NORMAL);
 
}
 

	
 
/** Calculate string bounding box for multi-line strings.
 
/**
 
 * Calculate string bounding box for multi-line strings.
 
 * @param str        String to check.
 
 * @param suggestion Suggested bounding box.
 
 * @return Bounding box for the multi-line string, may be bigger than \a suggestion.
 
 */
 
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
 
{
 
@@ -953,13 +959,14 @@ int DrawStringMultiLine(int left, int ri
 
{
 
	char buffer[DRAW_STRING_BUFFER];
 
	GetString(buffer, str, lastof(buffer));
 
	return DrawStringMultiLine(left, right, top, bottom, buffer, lastof(buffer), colour, align, underline);
 
}
 

	
 
/** Return the string dimension in pixels. The height and width are returned
 
/**
 
 * Return the string dimension in pixels. The height and width are returned
 
 * in a single Dimension value. TINYFONT, BIGFONT modifiers are only
 
 * supported as the first character of the string. The returned dimensions
 
 * are therefore a rough estimation correct for all the current strings
 
 * but not every possible combination
 
 * @param str string to calculate pixel-width
 
 * @param start_fontsize Fontsize to start the text with
 
@@ -1024,13 +1031,14 @@ Dimension GetStringBoundingBox(StringID 
 
void DrawCharCentered(WChar c, int x, int y, TextColour colour)
 
{
 
	SetColourRemap(colour);
 
	GfxMainBlitter(GetGlyph(FS_NORMAL, c), x - GetCharacterWidth(FS_NORMAL, c) / 2, y, BM_COLOUR_REMAP);
 
}
 

	
 
/** Draw a string at the given coordinates with the given colour.
 
/**
 
 * Draw a string at the given coordinates with the given colour.
 
 *  While drawing the string, parse it in case some formatting is specified,
 
 *  like new colour, new size or even positionning.
 
 * @param string              The string to draw. This is already bidi reordered.
 
 * @param x                   Offset from left side of the screen
 
 * @param y                   Offset from top side of the screen
 
 * @param params              Text drawing parameters
 
@@ -1703,13 +1711,14 @@ void SetDirtyBlocks(int left, int top, i
 
 */
 
void MarkWholeScreenDirty()
 
{
 
	SetDirtyBlocks(0, 0, _screen.width, _screen.height);
 
}
 

	
 
/** Set up a clipping area for only drawing into a certain area. To do this,
 
/**
 
 * Set up a clipping area for only drawing into a certain area. To do this,
 
 * Fill a DrawPixelInfo object with the supplied relative rectangle, backup
 
 * the original (calling) _cur_dpi and assign the just returned DrawPixelInfo
 
 * _cur_dpi. When you are done, give restore _cur_dpi's original value
 
 * @param *n the DrawPixelInfo that will be the clipping rectangle box allowed
 
 * for drawing
 
 * @param left,top,width,height the relative coordinates of the clipping
src/graph_gui.cpp
Show inline comments
 
@@ -258,13 +258,14 @@ protected:
 

	
 
		current_interval.highest = num_pos_grids * grid_size;
 
		current_interval.lowest = -(num_hori_lines - num_pos_grids) * grid_size;
 
		return current_interval;
 
	}
 

	
 
	/** Get width for Y labels.
 
	/**
 
	 * Get width for Y labels.
 
	 * @param current_interval Interval that contains all of the graph data.
 
	 * @param num_hori_lines Number of horizontal lines to be drawn.
 
	 */
 
	uint GetYLabelWidth(ValuesInterval current_interval, int num_hori_lines) const
 
	{
 
		/* draw text strings on the y axis */
 
@@ -1516,13 +1517,14 @@ struct PerformanceRatingDetailWindow : W
 
		this->LowerWidget(this->company + PRW_COMPANY_FIRST);
 
	}
 
};
 

	
 
CompanyID PerformanceRatingDetailWindow::company = INVALID_COMPANY;
 

	
 
/** Make a vertical list of panels for outputting score details.
 
/**
 
 * Make a vertical list of panels for outputting score details.
 
 * @param biggest_index Storage for collecting the biggest index used in the returned tree.
 
 * @return Panel with performance details.
 
 * @post \c *biggest_index contains the largest used index in the tree.
 
 */
 
static NWidgetBase *MakePerformanceDetailPanels(int *biggest_index)
 
{
src/highscore_gui.cpp
Show inline comments
 
@@ -214,22 +214,24 @@ static const WindowDesc _endgame_desc(
 
	WDP_MANUAL, 0, 0,
 
	WC_ENDSCREEN, WC_NONE,
 
	0,
 
	_nested_highscore_widgets, lengthof(_nested_highscore_widgets)
 
);
 

	
 
/** Show the highscore table for a given difficulty. When called from
 
/**
 
 * Show the highscore table for a given difficulty. When called from
 
 * endgame ranking is set to the top5 element that was newly added
 
 * and is thus highlighted */
 
void ShowHighscoreTable(int difficulty, int8 ranking)
 
{
 
	DeleteWindowByClass(WC_HIGHSCORE);
 
	new HighScoreWindow(&_highscore_desc, difficulty, ranking);
 
}
 

	
 
/** Show the endgame victory screen in 2050. Update the new highscore
 
/**
 
 * Show the endgame victory screen in 2050. Update the new highscore
 
 * if it was high enough */
 
void ShowEndGameChart()
 
{
 
	/* Dedicated server doesn't need the highscore window and neither does -v null. */
 
	if (_network_dedicated || (!_networking && !Company::IsValidID(_local_company))) return;
 

	
src/house.h
Show inline comments
 
@@ -15,22 +15,24 @@
 
#include "strings_type.h"
 
#include "cargo_type.h"
 
#include "economy_type.h"
 
#include "date_type.h"
 
#include "house_type.h"
 

	
 
/** Simple value that indicates the house has reached the final stage of
 
/**
 
 * Simple value that indicates the house has reached the final stage of
 
 * construction. */
 
static const byte TOWN_HOUSE_COMPLETED = 3;
 

	
 
static const uint HOUSE_NO_CLASS      = 0;
 
static const HouseID NEW_HOUSE_OFFSET = 110;
 
static const HouseID HOUSE_MAX        = 512;
 
static const HouseID INVALID_HOUSE_ID = 0xFFFF;
 

	
 
/** There can only be as many classes as there are new houses, plus one for
 
/**
 
 * There can only be as many classes as there are new houses, plus one for
 
 * NO_CLASS, as the original houses don't have classes. */
 
static const uint HOUSE_CLASS_MAX  = HOUSE_MAX - NEW_HOUSE_OFFSET + 1;
 

	
 
enum BuildingFlags {
 
	TILE_NO_FLAG         =       0,
 
	TILE_SIZE_1x1        = 1U << 0,
src/industry_cmd.cpp
Show inline comments
 
@@ -59,13 +59,14 @@ static TileIndex _industry_sound_tile;
 

	
 
uint16 Industry::counts[NUM_INDUSTRYTYPES];
 

	
 
IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
 
IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
 

	
 
/** This function initialize the spec arrays of both
 
/**
 
 * This function initialize the spec arrays of both
 
 * industry and industry tiles.
 
 * It adjusts the enabling of the industry too, based on climate availability.
 
 * This will allow for clearer testings */
 
void ResetIndustries()
 
{
 
	memset(&_industry_specs, 0, sizeof(_industry_specs));
 
@@ -1116,22 +1117,24 @@ void OnTick_Industry()
 
	Industry *i;
 
	FOR_ALL_INDUSTRIES(i) {
 
		ProduceIndustryGoods(i);
 
	}
 
}
 

	
 
/** Check the conditions of #CHECK_NOTHING (Always succeeds).
 
/**
 
 * Check the conditions of #CHECK_NOTHING (Always succeeds).
 
 * @param tile %Tile to perform the checking.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckNewIndustry_NULL(TileIndex tile)
 
{
 
	return CommandCost();
 
}
 

	
 
/** Check the conditions of #CHECK_FOREST (Industry should be build above snow-line in arctic climate).
 
/**
 
 * Check the conditions of #CHECK_FOREST (Industry should be build above snow-line in arctic climate).
 
 * @param tile %Tile to perform the checking.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckNewIndustry_Forest(TileIndex tile)
 
{
 
	if (_settings_game.game_creation.landscape == LT_ARCTIC) {
 
@@ -1139,13 +1142,14 @@ static CommandCost CheckNewIndustry_Fore
 
			return_cmd_error(STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED);
 
		}
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Check the conditions of #CHECK_REFINERY (Industry should be positioned near edge of the map).
 
/**
 
 * Check the conditions of #CHECK_REFINERY (Industry should be positioned near edge of the map).
 
 * @param tile %Tile to perform the checking.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckNewIndustry_OilRefinery(TileIndex tile)
 
{
 
	if (_game_mode == GM_EDITOR) return CommandCost();
 
@@ -1153,26 +1157,28 @@ static CommandCost CheckNewIndustry_OilR
 

	
 
	return_cmd_error(STR_ERROR_CAN_ONLY_BE_POSITIONED);
 
}
 

	
 
extern bool _ignore_restrictions;
 

	
 
/** Check the conditions of #CHECK_OIL_RIG (Industries at sea should be positioned near edge of the map).
 
/**
 
 * Check the conditions of #CHECK_OIL_RIG (Industries at sea should be positioned near edge of the map).
 
 * @param tile %Tile to perform the checking.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckNewIndustry_OilRig(TileIndex tile)
 
{
 
	if (_game_mode == GM_EDITOR && _ignore_restrictions) return CommandCost();
 
	if (TileHeight(tile) == 0 &&
 
			DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _settings_game.game_creation.oil_refinery_limit) return CommandCost();
 

	
 
	return_cmd_error(STR_ERROR_CAN_ONLY_BE_POSITIONED);
 
}
 

	
 
/** Check the conditions of #CHECK_FARM (Industry should be below snow-line in arctic).
 
/**
 
 * Check the conditions of #CHECK_FARM (Industry should be below snow-line in arctic).
 
 * @param tile %Tile to perform the checking.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckNewIndustry_Farm(TileIndex tile)
 
{
 
	if (_settings_game.game_creation.landscape == LT_ARCTIC) {
 
@@ -1180,61 +1186,66 @@ static CommandCost CheckNewIndustry_Farm
 
			return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
		}
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Check the conditions of #CHECK_PLANTATION (Industry should NOT be in the desert).
 
/**
 
 * Check the conditions of #CHECK_PLANTATION (Industry should NOT be in the desert).
 
 * @param tile %Tile to perform the checking.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckNewIndustry_Plantation(TileIndex tile)
 
{
 
	if (GetTropicZone(tile) == TROPICZONE_DESERT) {
 
		return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Check the conditions of #CHECK_WATER (Industry should be in the desert).
 
/**
 
 * Check the conditions of #CHECK_WATER (Industry should be in the desert).
 
 * @param tile %Tile to perform the checking.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckNewIndustry_Water(TileIndex tile)
 
{
 
	if (GetTropicZone(tile) != TROPICZONE_DESERT) {
 
		return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT);
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Check the conditions of #CHECK_LUMBERMILL (Industry should be in the rain forest).
 
/**
 
 * Check the conditions of #CHECK_LUMBERMILL (Industry should be in the rain forest).
 
 * @param tile %Tile to perform the checking.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckNewIndustry_Lumbermill(TileIndex tile)
 
{
 
	if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) {
 
		return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST);
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Check the conditions of #CHECK_BUBBLEGEN (Industry should be in low land).
 
/**
 
 * Check the conditions of #CHECK_BUBBLEGEN (Industry should be in low land).
 
 * @param tile %Tile to perform the checking.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckNewIndustry_BubbleGen(TileIndex tile)
 
{
 
	if (GetTileZ(tile) > TILE_HEIGHT * 4) {
 
		return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_LOW_AREAS);
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Industrytype check function signature.
 
/**
 
 * Industrytype check function signature.
 
 * @param tile %Tile to check.
 
 * @return Succeeded or failed command.
 
 */
 
typedef CommandCost CheckNewIndustryProc(TileIndex tile);
 

	
 
/** Check functions for different types of industry. */
 
@@ -1247,13 +1258,14 @@ static CheckNewIndustryProc * const _che
 
	CheckNewIndustry_Water,       ///< CHECK_WATER
 
	CheckNewIndustry_Lumbermill,  ///< CHECK_LUMBERMILL
 
	CheckNewIndustry_BubbleGen,   ///< CHECK_BUBBLEGEN
 
	CheckNewIndustry_OilRig,      ///< CHECK_OIL_RIG
 
};
 

	
 
/** Find a town for the industry, while checking for multiple industries in the same town.
 
/**
 
 * Find a town for the industry, while checking for multiple industries in the same town.
 
 * @param tile Position of the industry to build.
 
 * @param type Industry type.
 
 * @param [out] town Pointer to return town for the new industry, \c NULL is written if no good town can be found.
 
 * @return Succeeded or failed command.
 
 *
 
 * @precond \c *t != NULL
 
@@ -1290,13 +1302,14 @@ bool IsSlopeRefused(Slope current, Slope
 
		if ((refused & SLOPE_N) && (t & SLOPE_SE)) return true;
 
	}
 

	
 
	return false;
 
}
 

	
 
/** Are the tiles of the industry free?
 
/**
 
 * Are the tiles of the industry free?
 
 * @param tile                     Position to check.
 
 * @param it                       Industry tiles table.
 
 * @param itspec_index             The index of the itsepc to build/fund
 
 * @param type                     Type of the industry.
 
 * @param initial_random_bits      The random bits the industry is going to have after construction.
 
 * @param founder Industry founder
 
@@ -1371,13 +1384,14 @@ static CommandCost CheckIfIndustryTilesA
 
	if (!refused_slope || (_settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !custom_shape && !_ignore_restrictions)) {
 
		return CommandCost();
 
	}
 
	return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
}
 

	
 
/** Is the industry allowed to be built at this place for the town?
 
/**
 
 * Is the industry allowed to be built at this place for the town?
 
 * @param tile Tile to construct the industry.
 
 * @param type Type of the industry.
 
 * @param t    Town authority that the industry belongs to.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
 
@@ -1491,13 +1505,14 @@ static bool CheckIfCanLevelIndustryPlatf
 

	
 
	cur_company.Restore();
 
	return true;
 
}
 

	
 

	
 
/** Check that the new industry is far enough from conflicting industries.
 
/**
 
 * Check that the new industry is far enough from conflicting industries.
 
 * @param tile Tile to construct the industry.
 
 * @param type Type of the new industry.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckIfFarEnoughFromConflictingIndustry(TileIndex tile, int type)
 
{
 
@@ -1514,13 +1529,14 @@ static CommandCost CheckIfFarEnoughFromC
 
			return_cmd_error(STR_ERROR_INDUSTRY_TOO_CLOSE);
 
		}
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Production level maximum, minimum and default values.
 
/**
 
 * Production level maximum, minimum and default values.
 
 * It is not a value been really used in order to change, but rather an indicator
 
 * of how the industry is behaving. */
 
enum ProductionLevels {
 
	PRODLEVEL_CLOSURE = 0x00,  ///< signal set to actually close the industry
 
	PRODLEVEL_MINIMUM = 0x04,  ///< below this level, the industry is set to be closing
 
	PRODLEVEL_DEFAULT = 0x10,  ///< default level set when the industry is created
 
@@ -1658,13 +1674,14 @@ static void DoCreateNewIndustry(Industry
 
	}
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0);
 

	
 
	Station::RecomputeIndustriesNearForAll();
 
}
 

	
 
/** Helper function for Build/Fund an industry
 
/**
 
 * Helper function for Build/Fund an industry
 
 * @param tile tile where industry is built
 
 * @param type of industry to build
 
 * @param flags of operations to conduct
 
 * @param indspec pointer to industry specifications
 
 * @param itspec_index the index of the itsepc to build/fund
 
 * @param seed random seed (possibly) used by industries
 
@@ -1717,13 +1734,14 @@ static CommandCost CreateNewIndustryHelp
 
		DoCreateNewIndustry(*ip, tile, type, it, itspec_index, t, founder, random_initial_bits);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Build/Fund an industry
 
/**
 
 * Build/Fund an industry
 
 * @param tile tile where industry is built
 
 * @param flags of operations to conduct
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 -  7) - industry type see build_industry.h and see industry.h
 
 * - p1 = (bit  8 - 15) - first layout to try
 
 * @param p2 seed to use for desyncfree randomisations
 
@@ -2164,13 +2182,14 @@ static void ReportNewsProductionChangeIn
 
	);
 
}
 

	
 
static const uint PERCENT_TRANSPORTED_60 = 153;
 
static const uint PERCENT_TRANSPORTED_80 = 204;
 

	
 
/** Change industry production or do closure
 
/**
 
 * Change industry production or do closure
 
 * @param i Industry for which changes are performed
 
 * @param monthly true if it's the monthly call, false if it's the random call
 
 */
 
static void ChangeIndustryProduction(Industry *i, bool monthly)
 
{
 
	StringID str = STR_NULL;
src/industry_gui.cpp
Show inline comments
 
@@ -118,26 +118,28 @@ static int CDECL IndustryTypeNameSorter(
 
	int r = strcmp(industry_name[0], industry_name[1]);
 

	
 
	/* If the names are equal, sort by industry type. */
 
	return (r != 0) ? r : (*a - *b);
 
}
 

	
 
/** Initialize the list of sorted industry types.
 
/**
 
 * Initialize the list of sorted industry types.
 
 */
 
void SortIndustryTypes()
 
{
 
	/* Add each industry type to the list. */
 
	for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
		_sorted_industry_types[i] = i;
 
	}
 

	
 
	/* Sort industry types by name. */
 
	QSortT(_sorted_industry_types, NUM_INDUSTRYTYPES, &IndustryTypeNameSorter);
 
}
 

	
 
/** Command callback. In case of failure to build an industry, show an error message.
 
/**
 
 * Command callback. In case of failure to build an industry, show an error message.
 
 * @param result Result of the command.
 
 * @param tile   Tile where the industry is placed.
 
 * @param p1     Additional data of the #CMD_BUILD_INDUSTRY command.
 
 * @param p2     Additional data of the #CMD_BUILD_INDUSTRY command.
 
 */
 
void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
@@ -662,13 +664,14 @@ public:
 
			this->info_height = expected + 1;
 
			this->ReInit();
 
			return;
 
		}
 
	}
 

	
 
	/** Draw the text in the #IVW_INFO panel.
 
	/**
 
	 * Draw the text in the #IVW_INFO panel.
 
	 * @param left  Left edge of the panel.
 
	 * @param right Right edge of the panel.
 
	 * @param top   Top edge of the panel.
 
	 * @return Expected position of the bottom edge of the panel.
 
	 */
 
	int DrawInfo(uint left, uint right, uint top)
src/industrytype.h
Show inline comments
 
@@ -31,13 +31,14 @@ enum IndustryLifeType {
 
	INDUSTRYLIFE_BLACK_HOLE =      0, ///< Like power plants and banks
 
	INDUSTRYLIFE_EXTRACTIVE = 1 << 0, ///< Like mines
 
	INDUSTRYLIFE_ORGANIC    = 1 << 1, ///< Like forests
 
	INDUSTRYLIFE_PROCESSING = 1 << 2, ///< Like factories
 
};
 

	
 
/** Available procedures to check whether an industry may build at a given location.
 
/**
 
 * Available procedures to check whether an industry may build at a given location.
 
 * @see CheckNewIndustryProc, _check_new_industry_procs[]
 
 */
 
enum CheckProc {
 
	CHECK_NOTHING,    ///< Always succeeds.
 
	CHECK_FOREST,     ///< %Industry should be build above snow-line in arctic climate.
 
	CHECK_REFINERY,   ///< %Industry should be positioned near edge of the map.
src/landscape.cpp
Show inline comments
 
@@ -42,13 +42,14 @@ extern const TileTypeProcs
 
	_tile_type_water_procs,
 
	_tile_type_dummy_procs,
 
	_tile_type_industry_procs,
 
	_tile_type_tunnelbridge_procs,
 
	_tile_type_unmovable_procs;
 

	
 
/** Tile callback functions for each type of tile.
 
/**
 
 * Tile callback functions for each type of tile.
 
 * @ingroup TileCallbackGroup
 
 * @see TileType */
 
const TileTypeProcs * const _tile_type_procs[16] = {
 
	&_tile_type_clear_procs,        ///< Callback functions for MP_CLEAR tiles
 
	&_tile_type_rail_procs,         ///< Callback functions for MP_RAILWAY tiles
 
	&_tile_type_road_procs,         ///< Callback functions for MP_ROAD tiles
 
@@ -482,13 +483,14 @@ void DoClearSquare(TileIndex tile)
 
	if (_tile_type_procs[GetTileType(tile)]->animate_tile_proc != NULL) DeleteAnimatedTile(tile);
 

	
 
	MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0);
 
	MarkTileDirtyByTile(tile);
 
}
 

	
 
/** Returns information about trackdirs and signal states.
 
/**
 
 * Returns information about trackdirs and signal states.
 
 * If there is any trackbit at 'side', return all trackdirbits.
 
 * For TRANSPORT_ROAD, return no trackbits if there is no roadbit (of given subtype) at given side.
 
 * @param tile tile to get info about
 
 * @param mode transport type
 
 * @param sub_mode for TRANSPORT_ROAD, roadtypes to check
 
 * @param side side we are entering from, INVALID_DIAGDIR to return all trackbits
 
@@ -585,26 +587,28 @@ byte LowestSnowLine()
 
void ClearSnowLine()
 
{
 
	free(_snow_line);
 
	_snow_line = NULL;
 
}
 

	
 
/** Clear a piece of landscape
 
/**
 
 * Clear a piece of landscape
 
 * @param tile tile to clear
 
 * @param flags of operation to conduct
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag 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
 
/**
 
 * Clear a big piece of landscape
 
 * @param tile end tile of area dragging
 
 * @param flags of operation to conduct
 
 * @param p1 start tile of area dragging
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
src/landscape.h
Show inline comments
 
@@ -15,13 +15,14 @@
 
#include "core/geometry_type.hpp"
 
#include "tile_cmd.h"
 

	
 
static const uint SNOW_LINE_MONTHS = 12; ///< Number of months in the snow line table.
 
static const uint SNOW_LINE_DAYS   = 32; ///< Number of days in each month in the snow line table.
 

	
 
/** Structure describing the height of the snow line each day of the year
 
/**
 
 * Structure describing the height of the snow line each day of the year
 
 * @ingroup SnowLineGroup */
 
struct SnowLine {
 
	byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]; ///< Height of the snow line each day of the year
 
	byte highest_value; ///< Highest snow line of the year
 
	byte lowest_value;  ///< Lowest snow line of the year
 
};
src/misc/array.hpp
Show inline comments
 
@@ -12,13 +12,14 @@
 
#ifndef  ARRAY_HPP
 
#define  ARRAY_HPP
 

	
 
#include "fixedsizearray.hpp"
 
#include "str.hpp"
 

	
 
/** Flexible array with size limit. Implemented as fixed size
 
/**
 
 * Flexible array with size limit. Implemented as fixed size
 
 *  array of fixed size arrays */
 
template <class T, uint B = 1024, uint N = B>
 
class SmallArray {
 
protected:
 
	typedef FixedSizeArray<T, B> SubArray; ///< inner array
 
	typedef FixedSizeArray<SubArray, N> SuperArray; ///< outer array
src/misc/blob.hpp
Show inline comments
 
@@ -13,13 +13,14 @@
 
#define BLOB_HPP
 

	
 
#include "../core/alloc_func.hpp"
 
#include "../core/mem_func.hpp"
 
#include <new>
 

	
 
/** Base class for simple binary blobs.
 
/**
 
 * Base class for simple binary blobs.
 
 *  Item is byte.
 
 *  The word 'simple' means:
 
 *    - no configurable allocator type (always made from heap)
 
 *    - no smart deallocation - deallocation must be called from the same
 
 *        module (DLL) where the blob was allocated
 
 *    - no configurable allocation policy (how big blocks should be allocated)
 
@@ -99,13 +100,14 @@ protected:
 
	/** all allocation should happen here */
 
	static FORCEINLINE BlobHeader *RawAlloc(size_t num_bytes)
 
	{
 
		return (BlobHeader*)MallocT<byte>(num_bytes);
 
	}
 

	
 
	/** Return header pointer to the static BlobHeader with
 
	/**
 
	 * Return header pointer to the static BlobHeader with
 
	 * both items and capacity containing zero */
 
	static FORCEINLINE BlobHeader *Zero()
 
	{
 
		return const_cast<BlobHeader *>(&ByteBlob::hdrEmpty[1]);
 
	}
 

	
 
@@ -228,22 +230,24 @@ public:
 
	{
 
		if (!src.IsEmpty()) {
 
			memcpy(Append(src.Length()), src.Begin(), src.Length());
 
		}
 
	}
 

	
 
	/** Reallocate if there is no free space for num_bytes bytes.
 
	/**
 
	 * Reallocate if there is no free space for num_bytes bytes.
 
	 *  @return pointer to the new data to be added */
 
	FORCEINLINE byte *Prepare(size_t num_bytes)
 
	{
 
		size_t new_size = Length() + num_bytes;
 
		if (new_size > Capacity()) SmartAlloc(new_size);
 
		return data + Length();
 
	}
 

	
 
	/** Increase Length() by num_bytes.
 
	/**
 
	 * Increase Length() by num_bytes.
 
	 *  @return pointer to the new data added */
 
	FORCEINLINE byte *Append(size_t num_bytes)
 
	{
 
		byte *pNewData = Prepare(num_bytes);
 
		LengthRef() += num_bytes;
 
		return pNewData;
 
@@ -283,13 +287,14 @@ public:
 
				p[i] = 0;
 
			}
 
		}
 
	}
 
};
 

	
 
/** Blob - simple dynamic T array. T (template argument) is a placeholder for any type.
 
/**
 
 * Blob - simple dynamic T array. T (template argument) is a placeholder for any type.
 
 *  T can be any integral type, pointer, or structure. Using Blob instead of just plain C array
 
 *  simplifies the resource management in several ways:
 
 *  1. When adding new item(s) it automatically grows capacity if needed.
 
 *  2. When variable of type Blob comes out of scope it automatically frees the data buffer.
 
 *  3. Takes care about the actual data size (number of used items).
 
 *  4. Dynamically constructs only used items (as opposite of static array which constructs all items) */
 
@@ -377,13 +382,14 @@ public:
 
	/** Grow number of data items in Blob by given number - doesn't construct items */
 
	FORCEINLINE T *GrowSizeNC(size_t num_items)
 
	{
 
		return (T*)base::Append(num_items * type_size);
 
	}
 

	
 
	/** Ensures that given number of items can be added to the end of Blob. Returns pointer to the
 
	/**
 
	 * Ensures that given number of items can be added to the end of Blob. Returns pointer to the
 
	 *  first free (unused) item */
 
	FORCEINLINE T *MakeFreeSpace(size_t num_items)
 
	{
 
		return (T*)base::Prepare(num_items * type_size);
 
	}
 

	
src/misc/countedptr.hpp
Show inline comments
 
@@ -9,13 +9,14 @@
 

	
 
/** @file countedptr.hpp CCountedPtr - smart pointer implementation. */
 

	
 
#ifndef COUNTEDPTR_HPP
 
#define COUNTEDPTR_HPP
 

	
 
/** CCountedPtr - simple reference counting smart pointer.
 
/**
 
 * CCountedPtr - simple reference counting smart pointer.
 
 *
 
 *     One of the standard ways how to maintain object's lifetime.
 
 *
 
 *     See http://ootips.org/yonat/4dev/smart-pointers.html for more
 
 *   general info about smart pointers.
 
 *
 
@@ -133,13 +134,14 @@ template <class T> struct AdaptT {
 
	{
 
		return m_t;
 
	}
 
};
 

	
 

	
 
/** Simple counted object. Use it as base of your struct/class if you want to use
 
/**
 
 * Simple counted object. Use it as base of your struct/class if you want to use
 
 *  basic reference counting. Your struct/class will destroy and free itself when
 
 *  last reference to it is released (using Relese() method). The initial reference
 
 *  count (when it is created) is zero (don't forget AddRef() at least one time if
 
 *  not using CCountedPtr<T>.
 
 *
 
 *  @see misc/countedobj.cpp for implementation.
src/misc/dbg_helpers.cpp
Show inline comments
 
@@ -69,13 +69,14 @@ CStrA TileStr(TileIndex tile)
 
{
 
	CStrA out;
 
	out.Format("0x%04X (%d, %d)", tile, TileX(tile), TileY(tile));
 
	return out.Transfer();
 
}
 

	
 
/** Keep track of the last assigned type_id. Used for anti-recursion.
 
/**
 
 * Keep track of the last assigned type_id. Used for anti-recursion.
 
 *static*/ size_t& DumpTarget::LastTypeId()
 
{
 
	static size_t last_type_id = 0;
 
	return last_type_id;
 
}
 

	
src/misc/fixedsizearray.hpp
Show inline comments
 
@@ -11,13 +11,14 @@
 

	
 
#ifndef  FIXEDSIZEARRAY_HPP
 
#define  FIXEDSIZEARRAY_HPP
 

	
 
#include "../core/alloc_func.hpp"
 

	
 
/** fixed size array
 
/**
 
 * fixed size array
 
 *  Upon construction it preallocates fixed size block of memory
 
 *  for all items, but doesn't construct them. Item's construction
 
 *  is delayed. */
 
template <class T, uint C>
 
struct FixedSizeArray {
 
protected:
 
@@ -29,13 +30,14 @@ protected:
 
	};
 

	
 
	/* make constants visible from outside */
 
	static const uint Tsize = sizeof(T);                // size of item
 
	static const uint HeaderSize = sizeof(ArrayHeader); // size of header
 

	
 
	/** the only member of fixed size array is pointer to the block
 
	/**
 
	 * the only member of fixed size array is pointer to the block
 
	 *  of C array of items. Header can be found on the offset -sizeof(ArrayHeader). */
 
	T *data;
 

	
 
	/** return reference to the array header (non-const) */
 
	FORCEINLINE ArrayHeader& Hdr() { return *(ArrayHeader*)(((byte*)data) - HeaderSize); }
 
	/** return reference to the array header (const) */
src/misc/hashtable.hpp
Show inline comments
 
@@ -103,13 +103,14 @@ struct CHashTableSlotT
 
			}
 
		}
 
		return NULL;
 
	}
 
};
 

	
 
/** class CHashTableT<Titem, Thash_bits> - simple hash table
 
/**
 
 * class CHashTableT<Titem, Thash_bits> - simple hash table
 
 *  of pointers allocated elsewhere.
 
 *
 
 *  Supports: Add/Find/Remove of Titems.
 
 *
 
 *  Your Titem must meet some extra requirements to be CHashTableT
 
 *  compliant:
 
@@ -133,13 +134,14 @@ public:
 
	typedef Titem_ Titem;                         // make Titem_ visible from outside of class
 
	typedef typename Titem_::Key Tkey;            // make Titem_::Key a property of HashTable
 
	static const int Thash_bits = Thash_bits_;    // publish num of hash bits
 
	static const int Tcapacity = 1 << Thash_bits; // and num of slots 2^bits
 

	
 
protected:
 
	/** each slot contains pointer to the first item in the list,
 
	/**
 
	 * each slot contains pointer to the first item in the list,
 
	 *  Titem contains pointer to the next item - GetHashNext(), SetHashNext() */
 
	typedef CHashTableSlotT<Titem_> Slot;
 

	
 
	Slot *m_slots;     // here we store our data (array of blobs)
 
	int   m_num_items; // item counter
 

	
src/misc_cmd.cpp
Show inline comments
 
@@ -22,13 +22,14 @@
 
#include "company_gui.h"
 
#include "company_base.h"
 
#include "core/backup_type.hpp"
 

	
 
#include "table/strings.h"
 

	
 
/** Increase the loan of your company.
 
/**
 
 * Increase the loan of your company.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 amount to increase the loan with, multitude of LOAN_INTERVAL. Only used when p2 == 2.
 
 * @param p2 when 0: loans LOAN_INTERVAL
 
 *           when 1: loans the maximum loan permitting money (press CTRL),
 
 *           when 2: loans the amount specified in p1
 
@@ -68,13 +69,14 @@ CommandCost CmdIncreaseLoan(TileIndex ti
 
		InvalidateCompanyWindows(c);
 
	}
 

	
 
	return CommandCost(EXPENSES_OTHER);
 
}
 

	
 
/** Decrease the loan of your company.
 
/**
 
 * Decrease the loan of your company.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 amount to decrease the loan with, multitude of LOAN_INTERVAL. Only used when p2 == 2.
 
 * @param p2 when 0: pays back LOAN_INTERVAL
 
 *           when 1: pays back the maximum loan permitting money (press CTRL),
 
 *           when 2: pays back the amount specified in p1
 
@@ -184,13 +186,14 @@ CommandCost CmdPause(TileIndex tile, DoC
 
		SetWindowDirty(WC_STATUS_BAR, 0);
 
		SetWindowDirty(WC_MAIN_TOOLBAR, 0);
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Change the financial flow of your company.
 
/**
 
 * Change the financial flow of your company.
 
 * This is normally only enabled in offline mode, but if there is a debug
 
 * 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
 
@@ -202,13 +205,14 @@ CommandCost CmdMoneyCheat(TileIndex tile
 
#ifndef _DEBUG
 
	if (_networking) return CMD_ERROR;
 
#endif
 
	return CommandCost(EXPENSES_OTHER, -(int32)p1);
 
}
 

	
 
/** Transfer funds (money) from one company to another.
 
/**
 
 * Transfer funds (money) from one company to another.
 
 * To prevent abuse in multiplayer games you can only send money to other
 
 * companies if you have paid off your loan (either explicitely, or implicitely
 
 * 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
src/misc_gui.cpp
Show inline comments
 
@@ -896,13 +896,14 @@ struct TooltipsWindow : public Window
 
			case TCC_LEFT_CLICK: if (!_left_button_down) delete this; break;
 
			case TCC_HOVER: if (!_mouse_hovering) delete this; break;
 
		}
 
	}
 
};
 

	
 
/** Shows a tooltip
 
/**
 
 * Shows a tooltip
 
 * @param str String to be displayed
 
 * @param paramcount number of params to deal with
 
 * @param params (optional) up to 5 pieces of additional information that may be added to a tooltip
 
 * @param use_left_mouse_button close the tooltip when the left (true) or right (false) mousebutton is released
 
 */
 
void GuiShowTooltips(StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
 
@@ -1407,13 +1408,14 @@ static const WindowDesc _query_string_de
 
	WDP_AUTO, 0, 0,
 
	WC_QUERY_STRING, WC_NONE,
 
	0,
 
	_nested_query_string_widgets, lengthof(_nested_query_string_widgets)
 
);
 

	
 
/** Show a query popup window with a textbox in it.
 
/**
 
 * Show a query popup window with a textbox in it.
 
 * @param str StringID for the text shown in the textbox
 
 * @param caption StringID of text shown in caption of querywindow
 
 * @param maxsize maximum size in bytes (including terminating '\0')
 
 * @param maxwidth maximum width in pixels allowed
 
 * @param parent pointer to a Window that will handle the events (ok/cancel) of this
 
 *        window. If NULL, results are handled by global function HandleOnEditText
 
@@ -1561,13 +1563,14 @@ static const WindowDesc _query_desc(
 
	WDP_CENTER, 0, 0,
 
	WC_CONFIRM_POPUP_QUERY, WC_NONE,
 
	WDF_UNCLICK_BUTTONS | WDF_MODAL,
 
	_nested_query_widgets, lengthof(_nested_query_widgets)
 
);
 

	
 
/** Show a modal confirmation window with standard 'yes' and 'no' buttons
 
/**
 
 * Show a modal confirmation window with standard 'yes' and 'no' buttons
 
 * The window is aligned to the centre of its parent.
 
 * @param caption string shown as window caption
 
 * @param message string that will be shown for the window
 
 * @param parent pointer to parent window, if this pointer is NULL the parent becomes
 
 * the main window WC_MAIN_WINDOW
 
 * @param callback callback function pointer to set in the window descriptor
src/music/allegro_m.cpp
Show inline comments
 
@@ -16,13 +16,14 @@
 
#include "allegro_m.h"
 
#include <allegro.h>
 

	
 
static FMusicDriver_Allegro iFMusicDriver_Allegro;
 
static MIDI *_midi = NULL;
 

	
 
/** There are multiple modules that might be using Allegro and
 
/**
 
 * There are multiple modules that might be using Allegro and
 
 * Allegro can only be initiated once. */
 
extern int _allegro_instance_count;
 

	
 
const char *MusicDriver_Allegro::Start(const char * const *param)
 
{
 
	if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) {
src/network/core/packet.h
Show inline comments
 
@@ -31,13 +31,14 @@ typedef uint8  PacketType; ///< Identifi
 
 * packet. Reading past the size of the packet when receiving
 
 * will return all 0 values and "" in case of the string.
 
 */
 
struct Packet {
 
	/** The next packet. Used for queueing packets before sending. */
 
	Packet *next;
 
	/** The size of the whole packet for received packets. For packets
 
	/**
 
	 * The size of the whole packet for received packets. For packets
 
	 * that will be sent, the value is filled in just before the
 
	 * actual transmission. */
 
	PacketSize size;
 
	/** The current read/write position in the packet */
 
	PacketSize pos;
 
	/** The buffer of this packet */
src/network/network.cpp
Show inline comments
 
@@ -468,13 +468,14 @@ static void CheckPauseOnJoin()
 
			(!_settings_client.network.pause_on_join && (_pause_mode & PM_PAUSED_JOIN) == PM_UNPAUSED)) {
 
		return;
 
	}
 
	CheckPauseHelper(NetworkHasJoiningClient(), PM_PAUSED_JOIN);
 
}
 

	
 
/** Converts a string to ip/port/company
 
/**
 
 * Converts a string to ip/port/company
 
 *  Format: IP:port#company
 
 *
 
 * connection_string will be re-terminated to seperate out the hostname, and company and port will
 
 * be set to the company and port strings given by the user, inside the memory area originally
 
 * occupied by connection_string. */
 
void ParseConnectionString(const char **company, const char **port, char *connection_string)
src/network/network_gamelist.cpp
Show inline comments
 
@@ -24,13 +24,14 @@
 

	
 
NetworkGameList *_network_game_list = NULL;
 

	
 
static ThreadMutex *_network_game_list_mutex = ThreadMutex::New();
 
static NetworkGameList *_network_game_delayed_insertion_list = NULL;
 

	
 
/** Add a new item to the linked gamelist, but do it delayed in the next tick
 
/**
 
 * Add a new item to the linked gamelist, but do it delayed in the next tick
 
 * or so to prevent race conditions.
 
 * @param item the item to add. Will be freed once added.
 
 */
 
void NetworkGameListAddItemDelayed(NetworkGameList *item)
 
{
 
	_network_game_list_mutex->BeginCritical();
 
@@ -63,13 +64,14 @@ static void NetworkGameListHandleDelayed
 
		}
 
		free(ins_item);
 
	}
 
	_network_game_list_mutex->EndCritical();
 
}
 

	
 
/** Add a new item to the linked gamelist. If the IP and Port match
 
/**
 
 * Add a new item to the linked gamelist. If the IP and Port match
 
 * return the existing item instead of adding it again
 
 * @param address the address of the to-be added item
 
 * @param port the port the server is running on
 
 * @return a point to the newly added or already existing item */
 
NetworkGameList *NetworkGameListAddItem(NetworkAddress address)
 
{
 
@@ -103,13 +105,14 @@ NetworkGameList *NetworkGameListAddItem(
 

	
 
	UpdateNetworkGameWindow(false);
 

	
 
	return item;
 
}
 

	
 
/** Remove an item from the gamelist linked list
 
/**
 
 * Remove an item from the gamelist linked list
 
 * @param remove pointer to the item to be removed */
 
void NetworkGameListRemoveItem(NetworkGameList *remove)
 
{
 
	NetworkGameList *prev_item = NULL;
 
	for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
 
		if (remove == item) {
src/network/network_gui.cpp
Show inline comments
 
@@ -61,13 +61,14 @@ void SortNetworkLanguages()
 
	}
 

	
 
	/* Sort the strings (we don't move 'any' and the 'invalid' one) */
 
	QSortT(_language_dropdown, NETLANG_COUNT - 1, &StringIDSorter);
 
}
 

	
 
/** Update the network new window because a new server is
 
/**
 
 * Update the network new window because a new server is
 
 * found on the network.
 
 * @param unselect unselect the currently selected item */
 
void UpdateNetworkGameWindow(bool unselect)
 
{
 
	InvalidateWindowData(WC_NETWORK_WINDOW, 0, unselect ? 1 : 0);
 
}
 
@@ -276,13 +277,14 @@ protected:
 
	/** Sort servers by name. */
 
	static int CDECL NGameNameSorter(NetworkGameList * const *a, NetworkGameList * const *b)
 
	{
 
		return strcasecmp((*a)->info.server_name, (*b)->info.server_name);
 
	}
 

	
 
	/** Sort servers by the amount of clients online on a
 
	/**
 
	 * Sort servers by the amount of clients online on a
 
	 * server. If the two servers have the same amount, the one with the
 
	 * higher maximum is preferred. */
 
	static int CDECL NGameClientSorter(NetworkGameList * const *a, NetworkGameList * const *b)
 
	{
 
		/* Reverse as per default we are interested in most-clients first */
 
		int r = (*a)->info.clients_on - (*b)->info.clients_on;
 
@@ -314,13 +316,14 @@ protected:
 
	static int CDECL NGameYearsSorter(NetworkGameList * const *a, NetworkGameList * const *b)
 
	{
 
		int r = (*a)->info.game_date - (*a)->info.start_date - (*b)->info.game_date + (*b)->info.start_date;
 
		return (r != 0) ? r : NGameDateSorter(a, b);
 
	}
 

	
 
	/** Sort servers by joinability. If both servers are the
 
	/**
 
	 * Sort servers by joinability. If both servers are the
 
	 * same, prefer the non-passworded server first. */
 
	static int CDECL NGameAllowedSorter(NetworkGameList * const *a, NetworkGameList * const *b)
 
	{
 
		/* The servers we do not know anything about (the ones that did not reply) should be at the bottom) */
 
		int r = StrEmpty((*a)->info.server_revision) - StrEmpty((*b)->info.server_revision);
 

	
src/network/network_server.cpp
Show inline comments
 
@@ -881,13 +881,14 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
	}
 

	
 
	/* Wrong status for this packet, give a warning to client, and close connection */
 
	return SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED);
 
}
 

	
 
/** The client has done a command and wants us to handle it
 
/**
 
 * The client has done a command and wants us to handle it
 
 * @param *cs the connected client that has sent the command
 
 * @param *p the packet in which the command was sent
 
 */
 
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
 
{
 
	NetworkClientSocket *new_cs;
 
@@ -918,23 +919,25 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 

	
 
	if ((GetCommandFlags(cp.cmd) & CMD_SPECTATOR) == 0 && !Company::IsValidID(cp.company) && ci->client_id != CLIENT_ID_SERVER) {
 
		IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_id, GetClientIP(ci));
 
		return SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_KICKED);
 
	}
 

	
 
	/** Only CMD_COMPANY_CTRL is always allowed, for the rest, playas needs
 
	/**
 
	 * Only CMD_COMPANY_CTRL is always allowed, for the rest, playas needs
 
	 * to match the company in the packet. If it doesn't, the client has done
 
	 * something pretty naughty (or a bug), and will be kicked
 
	 */
 
	if (!(cp.cmd == CMD_COMPANY_CTRL && cp.p1 == 0 && ci->client_playas == COMPANY_NEW_COMPANY) && ci->client_playas != cp.company) {
 
		IConsolePrintF(CC_ERROR, "WARNING: client %d (IP: %s) tried to execute a command as company %d, kicking...",
 
		               ci->client_playas + 1, GetClientIP(ci), cp.company + 1);
 
		return SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_COMPANY_MISMATCH);
 
	}
 

	
 
	/** @todo CMD_COMPANY_CTRL with p1 = 0 announces a new company to the server. To give the
 
	/**
 
	 * @todo CMD_COMPANY_CTRL with p1 = 0 announces a new company to the server. To give the
 
	 * company the correct ID, the server injects p2 and executes the command. Any other p1
 
	 * is prohibited. Pretty ugly and should be redone together with its function.
 
	 * @see CmdCompanyCtrl()
 
	 */
 
	if (cp.cmd == CMD_COMPANY_CTRL) {
 
		if (cp.p1 != 0 || cp.company != COMPANY_SPECTATOR) {
src/newgrf.cpp
Show inline comments
 
@@ -219,13 +219,14 @@ struct GRFLocation {
 
};
 

	
 
static std::map<GRFLocation, SpriteID> _grm_sprites;
 
typedef std::map<GRFLocation, byte*> GRFLineToSpriteOverride;
 
static GRFLineToSpriteOverride _grf_line_to_action6_sprite_override;
 

	
 
/** DEBUG() function dedicated to newGRF debugging messages
 
/**
 
 * DEBUG() function dedicated to newGRF debugging messages
 
 * Function is essentially the same as DEBUG(grf, severity, ...) with the
 
 * addition of file:line information when parsing grf files.
 
 * NOTE: for the above reason(s) grfmsg() should ONLY be used for
 
 * loading/parsing grf files, not for runtime debug messages as there
 
 * is no file information available during that time.
 
 * @param severity debugging severity level, see debug.h
 
@@ -278,13 +279,14 @@ static void ClearTemporaryNewGRFData(GRF
 
}
 

	
 

	
 
typedef std::map<StringID *, uint32> StringIDToGRFIDMapping;
 
static StringIDToGRFIDMapping _string_to_grf_mapping;
 

	
 
/** Used when setting an object's property to map to the GRF's strings
 
/**
 
 * Used when setting an object's property to map to the GRF's strings
 
 * while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one
 
 * @param grfid Id of the grf file
 
 * @param str StringID that we want to have the equivalent in OoenTTD
 
 * @return the properly adjusted StringID
 
 */
 
StringID MapGRFStringID(uint32 grfid, StringID str)
 
@@ -420,13 +422,14 @@ EngineID GetNewEngineID(const GRFFile *f
 
		if (override != 0) scope_grfid = override;
 
	}
 

	
 
	return _engine_mngr.GetID(type, internal_id, scope_grfid);
 
}
 

	
 
/** Map the colour modifiers of TTDPatch to those that Open is using.
 
/**
 
 * Map the colour modifiers of TTDPatch to those that Open is using.
 
 * @param grf_sprite pointer to the structure been modified
 
 */
 
static void MapSpriteMappingRecolour(PalSpriteID *grf_sprite)
 
{
 
	if (HasBit(grf_sprite->pal, 14)) {
 
		ClrBit(grf_sprite->pal, 14);
 
@@ -6789,13 +6792,14 @@ static void InitNewGRFFile(const GRFConf
 
	}
 

	
 
	*_grf_files.Append() = _cur_grffile = newfile;
 
}
 

	
 

	
 
/** List of what cargo labels are refittable for the given the vehicle-type.
 
/**
 
 * List of what cargo labels are refittable for the given the vehicle-type.
 
 * Only currently active labels are applied. */
 
static const CargoLabel _default_refitmasks_rail[] = {
 
	'PASS', 'COAL', 'MAIL', 'LVST', 'GOOD', 'GRAI', 'WHEA', 'MAIZ', 'WOOD',
 
	'IORE', 'STEL', 'VALU', 'GOLD', 'DIAM', 'PAPR', 'FOOD', 'FRUT', 'CORE',
 
	'WATR', 'SUGR', 'TOYS', 'BATT', 'SWET', 'TOFF', 'COLA', 'CTCD', 'BUBL',
 
	'PLST', 'FZDR',
 
@@ -6922,13 +6926,14 @@ static void FinaliseCargoArray()
 
			cs->quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY;
 
			cs->abbrev = STR_NEWGRF_INVALID_CARGO_ABBREV;
 
		}
 
	}
 
}
 

	
 
/** Add all new houses to the house array. House properties can be set at any
 
/**
 
 * Add all new houses to the house array. House properties can be set at any
 
 * time in the GRF file, so we can only add a house spec to the house array
 
 * after the file has finished loading. We also need to check the dates, due to
 
 * the TTDPatch behaviour described below that we need to emulate. */
 
static void FinaliseHouseArray()
 
{
 
	/* If there are no houses with start dates before 1930, then all houses
 
@@ -6987,13 +6992,14 @@ static void FinaliseHouseArray()
 

	
 
			if (hs->enabled && hs->min_year == min_year) hs->min_year = 0;
 
		}
 
	}
 
}
 

	
 
/** Add all new industries to the industry array. Industry properties can be set at any
 
/**
 
 * Add all new industries to the industry array. Industry properties can be set at any
 
 * time in the GRF file, so we can only add a industry spec to the industry array
 
 * after the file has finished loading. */
 
static void FinaliseIndustriesArray()
 
{
 
	const GRFFile * const *end = _grf_files.End();
 
	for (GRFFile **file = _grf_files.Begin(); file != end; file++) {
src/newgrf_callbacks.h
Show inline comments
 
@@ -40,13 +40,14 @@ enum CallbackID {
 
	/** Determine whether a newstation should be made available to build. */
 
	CBID_STATION_AVAILABILITY            = 0x13, // 8 bit callback
 

	
 
	/** Choose a sprite layout to draw, instead of the standard 0-7 range. */
 
	CBID_STATION_SPRITE_LAYOUT           = 0x14,
 

	
 
	/** Refit capacity, the passed vehicle needs to have its ->cargo_type set to
 
	/**
 
	 * Refit capacity, the passed vehicle needs to have its ->cargo_type set to
 
	 * the cargo we are refitting to, returns the new cargo capacity. */
 
	CBID_VEHICLE_REFIT_CAPACITY          = 0x15, // 15 bit callback
 

	
 
	/** Builds articulated engines for trains and RVs. */
 
	CBID_VEHICLE_ARTIC_ENGINE            = 0x16, // 8 bit callback
 

	
 
@@ -83,13 +84,14 @@ enum CallbackID {
 
	/** Called periodically to determine if a house should be destroyed. */
 
	CBID_HOUSE_DESTRUCTION               = 0x21, // 8 bit callback
 

	
 
	/** Called to determine if the given industry type is available */
 
	CBID_INDUSTRY_AVAILABLE              = 0x22, // 15 bit callback
 

	
 
	/** This callback is called from vehicle purchase lists. It returns a value to be
 
	/**
 
	 * This callback is called from vehicle purchase lists. It returns a value to be
 
	 * used as a custom string ID in the 0xD000 range. */
 
	CBID_VEHICLE_ADDITIONAL_TEXT         = 0x23,
 

	
 
	/** Called when building a station to customize the tile layout */
 
	CBID_STATION_TILE_LAYOUT             = 0x24, // 15 bit callback
 

	
 
@@ -114,26 +116,28 @@ enum CallbackID {
 
	/** Called to query the cargo acceptance of the industry tile */
 
	CBID_INDTILE_CARGO_ACCEPTANCE        = 0x2B, // 15 bit callback
 

	
 
	/** Called to determine which cargoes an industry should accept. */
 
	CBID_INDTILE_ACCEPT_CARGO            = 0x2C, // 15 bit callback
 

	
 
	/** Called to determine if a specific colour map should be used for a vehicle
 
	/**
 
	 * Called to determine if a specific colour map should be used for a vehicle
 
	 * instead of the default livery. */
 
	CBID_VEHICLE_COLOUR_MAPPING          = 0x2D, // 15 bit callback
 

	
 
	/** Called to determine how much cargo a town building produces. */
 
	CBID_HOUSE_PRODUCE_CARGO             = 0x2E, // 15 bit callback
 

	
 
	/** Called to determine if the given industry tile can be built on specific tile. */
 
	CBID_INDTILE_SHAPE_CHECK             = 0x2F, // 15 bit callback
 

	
 
	/** Called to determine the type (if any) of foundation to draw for industry tile. */
 
	CBID_INDTILE_DRAW_FOUNDATIONS        = 0x30, // 15 bit callback
 

	
 
	/** Called when the company (or AI) tries to start or stop a vehicle. Mainly
 
	/**
 
	 * Called when the company (or AI) tries to start or stop a vehicle. Mainly
 
	 * used for preventing a vehicle from leaving the depot. */
 
	CBID_VEHICLE_START_STOP_CHECK        = 0x31, // 15 bit callback, but 0xFF test is done with 8 bit
 

	
 
	/** Called for every vehicle every 32 days (not all on same date though). */
 
	CBID_VEHICLE_32DAY_CALLBACK          = 0x32, // 2 bit callback
 

	
 
@@ -143,13 +147,14 @@ enum CallbackID {
 
	/** Return the vehicles this given vehicle can be "upgraded" to. */
 
	CBID_VEHICLE_AUTOREPLACE_SELECTION   = 0x34, // 15 bit callback, not implemented
 

	
 
	/** Called monthly on production changes, so it can be adjusted more frequently */
 
	CBID_INDUSTRY_MONTHLYPROD_CHANGE     = 0x35, // 15 bit callback
 

	
 
	/** Called to modify various vehicle properties. Callback parameter 1
 
	/**
 
	 * Called to modify various vehicle properties. Callback parameter 1
 
	 * specifies the property index, as used in Action 0, to change. */
 
	CBID_VEHICLE_MODIFY_PROPERTY         = 0x36, // 8/15 bit depends on queried property
 

	
 
	/** Called to determine text to display after cargo name */
 
	CBID_INDUSTRY_CARGO_SUFFIX           = 0x37, // 15 bit callback, but 0xFF test is done with 8 bit
 

	
src/newgrf_canal.h
Show inline comments
 
@@ -13,13 +13,14 @@
 
#define NEWGRF_CANAL_H
 

	
 
#include "gfx_type.h"
 
#include "tile_type.h"
 
#include "newgrf_generic.h"
 

	
 
/** List of different canal 'features'.
 
/**
 
 * List of different canal 'features'.
 
 * Each feature gets an entry in the canal spritegroup table */
 
enum CanalFeature {
 
	CF_WATERSLOPE,
 
	CF_LOCKS,
 
	CF_DIKES,
 
	CF_ICON,
 
@@ -39,13 +40,14 @@ struct WaterFeature {
 

	
 

	
 
/** Table of canal 'feature' sprite groups */
 
extern WaterFeature _water_feature[CF_END];
 

	
 

	
 
/** Lookup the base sprite to use for a canal.
 
/**
 
 * Lookup the base sprite to use for a canal.
 
 * @param feature Which canal feature we want.
 
 * @param tile Tile index of canal, if appropriate.
 
 * @return Base sprite returned by GRF, or 0 if none.
 
 */
 
SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile);
 

	
src/newgrf_commons.cpp
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 newgrf_commons.cpp Implementation of the class OverrideManagerBase
 
/**
 
 * @file newgrf_commons.cpp Implementation of the class OverrideManagerBase
 
 * and its descendance, present and futur
 
 */
 

	
 
#include "stdafx.h"
 
#include "landscape.h"
 
#include "house.h"
 
@@ -20,13 +21,14 @@
 
#include "clear_map.h"
 
#include "station_map.h"
 
#include "tree_map.h"
 
#include "tunnelbridge_map.h"
 
#include "core/mem_func.hpp"
 

	
 
/** Constructor of generic class
 
/**
 
 * Constructor of generic class
 
 * @param offset end of original data for this entity. i.e: houses = 110
 
 * @param maximum of entities this manager can deal with. i.e: houses = 512
 
 * @param invalid is the ID used to identify an invalid entity id
 
 */
 
OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid)
 
{
 
@@ -37,23 +39,25 @@ OverrideManagerBase::OverrideManagerBase
 
	mapping_ID = CallocT<EntityIDMapping>(max_new_entities);
 
	entity_overrides = MallocT<uint16>(max_offset);
 
	for (size_t i = 0; i < max_offset; i++) entity_overrides[i] = invalid;
 
	grfid_overrides = CallocT<uint32>(max_offset);
 
}
 

	
 
/** Destructor of the generic class.
 
/**
 
 * Destructor of the generic class.
 
 * Frees allocated memory of constructor
 
 */
 
OverrideManagerBase::~OverrideManagerBase()
 
{
 
	free(mapping_ID);
 
	free(entity_overrides);
 
	free(grfid_overrides);
 
}
 

	
 
/** Since the entity IDs defined by the GRF file does not necessarily correlate
 
/**
 
 * Since the entity IDs defined by the GRF file does not necessarily correlate
 
 * to those used by the game, the IDs used for overriding old entities must be
 
 * translated when the entity spec is set.
 
 * @param local_id ID in grf file
 
 * @param grfid  ID of the grf file
 
 * @param entity_type original entity type
 
 */
 
@@ -78,13 +82,14 @@ void OverrideManagerBase::ResetOverride(
 
	for (uint16 i = 0; i < max_offset; i++) {
 
		entity_overrides[i] = invalid_ID;
 
		grfid_overrides[i] = 0;
 
	}
 
}
 

	
 
/** Return the ID (if ever available) of a previously inserted entity.
 
/**
 
 * Return the ID (if ever available) of a previously inserted entity.
 
 * @param grf_local_id ID of this enity withing the grfID
 
 * @param grfid ID of the grf file
 
 * @return the ID of the candidate, of the Invalid flag item ID
 
 */
 
uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid)
 
{
 
@@ -97,13 +102,14 @@ uint16 OverrideManagerBase::GetID(uint8 
 
		}
 
	}
 

	
 
	return invalid_ID;
 
}
 

	
 
/** Reserves a place in the mapping array for an entity to be installed
 
/**
 
 * Reserves a place in the mapping array for an entity to be installed
 
 * @param grf_local_id is an arbitrary id given by the grf's author.  Also known as setid
 
 * @param grfid is the id of the grf file itself
 
 * @param substitute_id is the original entity from which data is copied for the new one
 
 * @return the proper usable slot id, or invalid marker if none is found
 
 */
 
uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
 
@@ -131,22 +137,24 @@ uint16 OverrideManagerBase::AddEntityID(
 
		}
 
	}
 

	
 
	return invalid_ID;
 
}
 

	
 
/** Gives the substitute of the entity, as specified by the grf file
 
/**
 
 * Gives the substitute of the entity, as specified by the grf file
 
 * @param entity_id of the entity being queried
 
 * @return mapped id
 
 */
 
uint16 OverrideManagerBase::GetSubstituteID(uint16 entity_id)
 
{
 
	return mapping_ID[entity_id].substitute_id;
 
}
 

	
 
/** Install the specs into the HouseSpecs array
 
/**
 
 * Install the specs into the HouseSpecs array
 
 * It will find itself the proper slot onwhich it will go
 
 * @param hs HouseSpec read from the grf file, ready for inclusion
 
 */
 
void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
 
{
 
	HouseID house_id = this->AddEntityID(hs->local_id, hs->grffile->grfid, hs->substitute_id);
 
@@ -167,13 +175,14 @@ void HouseOverrideManager::SetEntitySpec
 
		overridden_hs->override = house_id;
 
		entity_overrides[i] = invalid_ID;
 
		grfid_overrides[i] = 0;
 
	}
 
}
 

	
 
/** Return the ID (if ever available) of a previously inserted entity.
 
/**
 
 * Return the ID (if ever available) of a previously inserted entity.
 
 * @param grf_local_id ID of this enity withing the grfID
 
 * @param grfid ID of the grf file
 
 * @return the ID of the candidate, of the Invalid flag item ID
 
 */
 
uint16 IndustryOverrideManager::GetID(uint8 grf_local_id, uint32 grfid)
 
{
 
@@ -185,13 +194,14 @@ uint16 IndustryOverrideManager::GetID(ui
 
		if (entity_overrides[id] == grf_local_id && grfid_overrides[id] == grfid) return id;
 
	}
 

	
 
	return invalid_ID;
 
}
 

	
 
/** Method to find an entity ID and to mark it as reserved for the Industry to be included.
 
/**
 
 * Method to find an entity ID and to mark it as reserved for the Industry to be included.
 
 * @param grf_local_id ID used by the grf file for pre-installation work (equivalent of TTDPatch's setid
 
 * @param grfid ID of the current grf file
 
 * @param substitute_id industry from which data has been copied
 
 * @return a free entity id (slotid) if ever one has been found, or Invalid_ID marker otherwise
 
 */
 
uint16 IndustryOverrideManager::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
 
@@ -220,13 +230,14 @@ uint16 IndustryOverrideManager::AddEntit
 
		}
 
	}
 

	
 
	return invalid_ID;
 
}
 

	
 
/** Method to install the new indistry data in its proper slot
 
/**
 
 * Method to install the new indistry data in its proper slot
 
 * The slot assigment is internal of this method, since it requires
 
 * checking what is available
 
 * @param inds Industryspec that comes from the grf decoding process
 
 */
 
void IndustryOverrideManager::SetEntitySpec(IndustrySpec *inds)
 
{
 
@@ -274,13 +285,14 @@ void IndustryTileOverrideManager::SetEnt
 
		overridden_its->enabled = false;
 
		entity_overrides[i] = invalid_ID;
 
		grfid_overrides[i] = 0;
 
	}
 
}
 

	
 
/** Function used by houses (and soon industries) to get information
 
/**
 
 * Function used by houses (and soon industries) to get information
 
 * on type of "terrain" the tile it is queries sits on.
 
 * @param tile TileIndex of the tile been queried
 
 * @param upper_halftile If true, query upper halftile in case of rail tiles.
 
 * @return value corresponding to the grf expected format:
 
 *         Terrain type: 0 normal, 1 desert, 2 rainforest, 4 on or above snowline */
 
uint32 GetTerrainType(TileIndex tile, bool upper_halftile)
src/newgrf_commons.h
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 newgrf_commons.h This file simplyfies and embeds a common mechanism of
 
/**
 
 * @file newgrf_commons.h This file simplyfies and embeds a common mechanism of
 
 * loading/saving and mapping of grf entities.
 
 */
 

	
 
#ifndef NEWGRF_COMMONS_H
 
#define NEWGRF_COMMONS_H
 

	
src/newgrf_config.cpp
Show inline comments
 
@@ -237,13 +237,14 @@ void GRFParameterInfo::SetValue(struct G
 
void UpdateNewGRFConfigPalette()
 
{
 
	for (GRFConfig *c = _grfconfig_newgame; c != NULL; c = c->next) c->SetSuitablePalette();
 
	for (GRFConfig *c = _grfconfig_static;  c != NULL; c = c->next) c->SetSuitablePalette();
 
}
 

	
 
/** Calculate the MD5 sum for a GRF, and store it in the config.
 
/**
 
 * Calculate the MD5 sum for a GRF, and store it in the config.
 
 * @param config GRF to compute.
 
 * @return MD5 sum was successfully computed
 
 */
 
static bool CalcGRFMD5Sum(GRFConfig *config)
 
{
 
	FILE *f;
 
@@ -265,13 +266,14 @@ static bool CalcGRFMD5Sum(GRFConfig *con
 
	FioFCloseFile(f);
 

	
 
	return true;
 
}
 

	
 

	
 
/** Find the GRFID of a given grf, and calculate its md5sum.
 
/**
 
 * Find the GRFID of a given grf, and calculate its md5sum.
 
 * @param config    grf to fill.
 
 * @param is_static grf is static.
 
 * @return Operation was successfully completed.
 
 */
 
bool FillGRFDetails(GRFConfig *config, bool is_static)
 
{
 
@@ -297,13 +299,14 @@ bool FillGRFDetails(GRFConfig *config, b
 
	config->SetSuitablePalette();
 

	
 
	return CalcGRFMD5Sum(config);
 
}
 

	
 

	
 
/** Clear a GRF Config list, freeing all nodes.
 
/**
 
 * Clear a GRF Config list, freeing all nodes.
 
 * @param config Start of the list.
 
 * @post \a config is set to \c NULL.
 
 */
 
void ClearGRFConfigList(GRFConfig **config)
 
{
 
	GRFConfig *c, *next;
 
@@ -312,13 +315,14 @@ void ClearGRFConfigList(GRFConfig **conf
 
		delete c;
 
	}
 
	*config = NULL;
 
}
 

	
 

	
 
/** Copy a GRF Config list
 
/**
 
 * Copy a GRF Config list
 
 * @param dst pointer to destination list
 
 * @param src pointer to source list values
 
 * @param init_only the copied GRF will be processed up to GLS_INIT
 
 * @return pointer to the last value added to the destination list */
 
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only)
 
{
 
@@ -378,13 +382,14 @@ void AppendStaticGRFConfigs(GRFConfig **
 
	while (*tail != NULL) tail = &(*tail)->next;
 

	
 
	CopyGRFConfigList(tail, _grfconfig_static, false);
 
	RemoveDuplicatesFromGRFConfigList(*dst);
 
}
 

	
 
/** Appends an element to a list of GRFs
 
/**
 
 * Appends an element to a list of GRFs
 
 * @param dst the head of the list to add to
 
 * @param el the new tail to be */
 
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el)
 
{
 
	GRFConfig **tail = dst;
 
	while (*tail != NULL) tail = &(*tail)->next;
 
@@ -399,13 +404,14 @@ void ResetGRFConfig(bool defaults)
 
{
 
	CopyGRFConfigList(&_grfconfig, _grfconfig_newgame, !defaults);
 
	AppendStaticGRFConfigs(&_grfconfig);
 
}
 

	
 

	
 
/** Check if all GRFs in the GRF config from a savegame can be loaded.
 
/**
 
 * Check if all GRFs in the GRF config from a savegame can be loaded.
 
 * @param grfconfig GrfConfig to check
 
 * @return will return any of the following 3 values:<br>
 
 * <ul>
 
 * <li> GLC_ALL_GOOD: No problems occurred, all GRF files were found and loaded
 
 * <li> GLC_COMPATIBLE: For one or more GRF's no exact match was found, but a
 
 *     compatible GRF with the same grfid was found and used instead
 
@@ -570,13 +576,14 @@ void ScanNewGRFFiles()
 
#ifdef ENABLE_NETWORK
 
	NetworkAfterNewGRFScan();
 
#endif
 
}
 

	
 

	
 
/** Find a NewGRF in the scanned list.
 
/**
 
 * Find a NewGRF in the scanned list.
 
 * @param grfid GRFID to look for,
 
 * @param md5sum Expected MD5 sum (set to \c NULL if not relevant).
 
 * @return The matching grf, if it exists in #_all_grfs, else \c NULL.
 
 */
 
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum)
 
{
 
@@ -638,13 +645,14 @@ char *FindUnknownGRFName(uint32 grfid, u
 
	return grf->name;
 
}
 

	
 
#endif /* ENABLE_NETWORK */
 

	
 

	
 
/** Retrieve a NewGRF from the current config by its grfid.
 
/**
 
 * Retrieve a NewGRF from the current config by its grfid.
 
 * @param grfid grf to look for.
 
 * @param mask  GRFID mask to allow for partial matching.
 
 * @return The grf config, if it exists, else \c NULL.
 
 */
 
GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask)
 
{
src/newgrf_config.h
Show inline comments
 
@@ -70,13 +70,14 @@ enum GRFPalette {
 

	
 
/** Basic data to distinguish a GRF. Used in the server list window */
 
struct GRFIdentifier {
 
	uint32 grfid;     ///< GRF ID (defined by Action 0x08)
 
	uint8 md5sum[16]; ///< MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
 

	
 
	/** Does the identification match the provided values?
 
	/**
 
	 * Does the identification match the provided values?
 
	 * @param grfid  Expected grfid.
 
	 * @param md5sum Expected md5sum, may be \c NULL (in which case, do not check it).
 
	 * @return the object has the provided grfid and md5sum.
 
	 */
 
	FORCEINLINE bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
 
	{
src/newgrf_engine.cpp
Show inline comments
 
@@ -878,13 +878,14 @@ static inline void NewVehicleResolver(Re
 

	
 
	const Engine *e = Engine::Get(engine_type);
 
	res->grffile         = (e != NULL ? e->grffile : NULL);
 
}
 

	
 

	
 
/** Retrieve the SpriteGroup for the specified vehicle.
 
/**
 
 * Retrieve the SpriteGroup for the specified vehicle.
 
 * If the vehicle is not specified, the purchase list group for the engine is
 
 * chosen. For trains, an additional engine override lookup is performed.
 
 * @param engine    Engine type of the vehicle.
 
 * @param v         The vehicle itself.
 
 * @param use_cache Use cached override
 
 * @returns         The selected SpriteGroup for the vehicle.
src/newgrf_generic.cpp
Show inline comments
 
@@ -131,13 +131,14 @@ static inline void NewGenericResolver(Re
 
	res->reseed          = 0;
 
	res->count           = 0;
 
	res->grffile         = grffile;
 
}
 

	
 

	
 
/** Follow a generic feature callback list and return the first successful
 
/**
 
 * Follow a generic feature callback list and return the first successful
 
 * answer
 
 * @param feature GRF Feature of callback
 
 * @param object  pre-populated resolver object
 
 * @param file    address of GRFFile object if file reference is needed, NULL is valid
 
 * @return callback value if successful or CALLBACK_FAILED
 
 */
src/newgrf_gui.cpp
Show inline comments
 
@@ -551,13 +551,14 @@ struct NewGRFWindow : public QueryString
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 
		this->DrawEditBox(SNGRFS_FILTER);
 
	}
 

	
 
	/** Pick the palette for the sprite of the grf to display.
 
	/**
 
	 * Pick the palette for the sprite of the grf to display.
 
	 * @param c grf to display.
 
	 * @return Palette for the sprite.
 
	 */
 
	FORCEINLINE PaletteID GetPalette(const GRFConfig *c) const
 
	{
 
		PaletteID pal;
 
@@ -920,13 +921,14 @@ struct NewGRFWindow : public QueryString
 
			}
 
		}
 

	
 
		this->InvalidateData();
 
	}
 

	
 
	/** Calback to update internal data.
 
	/**
 
	 * Calback to update internal data.
 
	 *  - 0: (optionally) build availables, update button status.
 
	 *  - 1: build availables, Add newly found grfs, update button status.
 
	 *  - 2: (optionally) build availables, Reset preset, + 3
 
	 *  - 3: (optionally) build availables, Update active scrollbar, update button status.
 
	 *  - 4: Force a rebuild of the availables, + 2
 
	 */
 
@@ -1157,13 +1159,14 @@ NewGRFWindow::GUIGRFConfigList::SortFunc
 
};
 

	
 
NewGRFWindow::GUIGRFConfigList::FilterFunction * const NewGRFWindow::filter_funcs[] = {
 
	&TagNameFilter,
 
};
 

	
 
/** Custom nested widget container for the NewGRF gui.
 
/**
 
 * Custom nested widget container for the NewGRF gui.
 
 * Depending on the space in the gui, it uses either
 
 * - two column mode, put the #acs and the #avs underneath each other and the #info next to it, or
 
 * - three column mode, put the #avs, #acs, and #info each in its own column.
 
 */
 
class NWidgetNewGRFDisplay : public NWidgetContainer {
 
public:
 
@@ -1488,13 +1491,14 @@ static const WindowDesc _newgrf_desc(
 
	WDP_CENTER, 300, 263,
 
	WC_GAME_OPTIONS, WC_NONE,
 
	WDF_UNCLICK_BUTTONS,
 
	_nested_newgrf_widgets, lengthof(_nested_newgrf_widgets)
 
);
 

	
 
/** Callback function for the newgrf 'apply changes' confirmation window
 
/**
 
 * Callback function for the newgrf 'apply changes' confirmation window
 
 * @param w Window which is calling this callback
 
 * @param confirmed boolean value, true when yes was clicked, false otherwise
 
 */
 
static void NewGRFConfirmationCallback(Window *w, bool confirmed)
 
{
 
	if (confirmed) {
 
@@ -1518,13 +1522,14 @@ static void NewGRFConfirmationCallback(W
 
		w->InvalidateData();
 
	}
 
}
 

	
 

	
 

	
 
/** Setup the NewGRF gui
 
/**
 
 * Setup the NewGRF gui
 
 * @param editable allow the user to make changes to the grfconfig in the window
 
 * @param show_params show information about what parameters are set for the grf files
 
 * @param exec_changes if changes are made to the list (editable is true), apply these
 
 *        changes immediately or only update the list
 
 * @param config pointer to a linked-list of grfconfig's that will be shown */
 
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
src/newgrf_house.cpp
Show inline comments
 
@@ -143,13 +143,14 @@ uint32 GetNearbyTileInformation(byte par
 
/** Structure with user-data for SearchNearbyHouseXXX - functions */
 
typedef struct {
 
	const HouseSpec *hs;  ///< Specs of the house, that started the search
 
	TileIndex north_tile; ///< Northern tile of the house.
 
} SearchNearbyHouseData;
 

	
 
/** Callback function to search a house by its HouseID
 
/**
 
 * Callback function to search a house by its HouseID
 
 * @param tile TileIndex to be examined
 
 * @param user_data SearchNearbyHouseData
 
 * @return true or false, if found or not
 
 */
 
static bool SearchNearbyHouseID(TileIndex tile, void *user_data)
 
{
 
@@ -166,13 +167,14 @@ static bool SearchNearbyHouseID(TileInde
 
				hs->grffile->grfid == nbhd->hs->grffile->grfid;  // from the same grf
 
		}
 
	}
 
	return false;
 
}
 

	
 
/** Callback function to search a house by its classID
 
/**
 
 * Callback function to search a house by its classID
 
 * @param tile TileIndex to be examined
 
 * @param user_data SearchNearbyHouseData
 
 * @return true or false, if found or not
 
 */
 
static bool SearchNearbyHouseClass(TileIndex tile, void *user_data)
 
{
 
@@ -189,13 +191,14 @@ static bool SearchNearbyHouseClass(TileI
 
				hs->grffile->grfid == nbhd->hs->grffile->grfid;  // from the same grf
 
		}
 
	}
 
	return false;
 
}
 

	
 
/** Callback function to search a house by its grfID
 
/**
 
 * Callback function to search a house by its grfID
 
 * @param tile TileIndex to be examined
 
 * @param user_data SearchNearbyHouseData
 
 * @return true or false, if found or not
 
 */
 
static bool SearchNearbyHouseGRFID(TileIndex tile, void *user_data)
 
{
 
@@ -211,13 +214,14 @@ static bool SearchNearbyHouseGRFID(TileI
 
			return hs->grffile->grfid == nbhd->hs->grffile->grfid;  // from the same grf
 
		}
 
	}
 
	return false;
 
}
 

	
 
/** This function will activate a search around a central tile, looking for some houses
 
/**
 
 * This function will activate a search around a central tile, looking for some houses
 
 * that fit the requested characteristics
 
 * @param parameter that is given by the callback.
 
 *                  bits 0..6 radius of the search
 
 *                  bits 7..8 search type i.e.: 0 = houseID/ 1 = classID/ 2 = grfID
 
 * @param tile TileIndex from which to start the search
 
 * @param house the HouseID that is associated to the house, the callback is called for
src/newgrf_industries.cpp
Show inline comments
 
@@ -97,13 +97,14 @@ static uint32 GetClosestIndustry(TileInd
 
		best_dist = min(best_dist, DistanceManhattan(tile, i->location.tile));
 
	}
 

	
 
	return best_dist;
 
}
 

	
 
/** Implementation of both var 67 and 68
 
/**
 
 * Implementation of both var 67 and 68
 
 * since the mechanism is almost the same, it is easier to regroup them on the same
 
 * function.
 
 * @param param_setID parameter given to the callback, which is the set id, or the local id, in our terminology
 
 * @param layout_filter on what layout do we filter?
 
 * @param current Industry for which the inquiry is made
 
 * @return the formatted answer to the callback : rr(reserved) cc(count) dddd(manhattan distance of closest sister)
 
@@ -151,13 +152,14 @@ static uint32 GetCountAndDistanceOfClose
 
		}
 
	}
 

	
 
	return count << 16 | GB(closest_dist, 0, 16);
 
}
 

	
 
/** This function implements the industries variables that newGRF defines.
 
/**
 
 * This function implements the industries variables that newGRF defines.
 
 * @param object the object that we want to query
 
 * @param variable that is queried
 
 * @param parameter unused
 
 * @param available will return false if ever the variable asked for does not exist
 
 * @return the value stored in the corresponding variable*/
 
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
 
@@ -444,13 +446,14 @@ uint32 IndustryLocationGetVariable(const
 
	}
 

	
 
	/* None of the special ones, so try the general ones */
 
	return IndustryGetVariable(object, variable, parameter, available);
 
}
 

	
 
/** Check that the industry callback allows creation of the industry.
 
/**
 
 * Check that the industry callback allows creation of the industry.
 
 * @param tile %Tile to build the industry.
 
 * @param type Type of industry to build.
 
 * @param layout Layout number.
 
 * @param seed Seed for the random generator.
 
 * @param initial_random_bits The random bits the industry is going to have after construction.
 
 * @param founder Industry founder
src/newgrf_industrytiles.cpp
Show inline comments
 
@@ -42,13 +42,14 @@ uint32 GetNearbyIndustryTileInformation(
 
	if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
 
	bool is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index);
 

	
 
	return GetNearbyTileInformation(tile) | (is_same_industry ? 1 : 0) << 8;
 
}
 

	
 
/** This is the position of the tile relative to the northernmost tile of the industry.
 
/**
 
 * This is the position of the tile relative to the northernmost tile of the industry.
 
 * Format: 00yxYYXX
 
 * Variable  Content
 
 * x         the x offset from the northernmost tile
 
 * XX        same, but stored in a byte instead of a nibble
 
 * y         the y offset from the northernmost tile
 
 * YY        same, but stored in a byte instead of a nibble
 
@@ -247,13 +248,14 @@ bool DrawNewIndustryTile(TileInfo *ti, I
 
		return true;
 
	}
 
}
 

	
 
extern bool IsSlopeRefused(Slope current, Slope refused);
 

	
 
/** Check the slope of a tile of a new industry.
 
/**
 
 * Check the slope of a tile of a new industry.
 
 * @param ind_base_tile Base tile of the industry.
 
 * @param ind_tile      Tile to check.
 
 * @param its           Tile specification.
 
 * @param type          Industry type.
 
 * @param gfx           Gfx of the tile.
 
 * @param itspec_index  Layout.
src/newgrf_station.cpp
Show inline comments
 
@@ -818,13 +818,14 @@ int AllocateSpecToStation(const StationS
 
	}
 

	
 
	return i;
 
}
 

	
 

	
 
/** Deallocate a StationSpec from a Station. Called when removing a single station tile.
 
/**
 
 * Deallocate a StationSpec from a Station. Called when removing a single station tile.
 
 * @param st Station to work with.
 
 * @param specindex Index of the custom station within the Station's spec list.
 
 * @return Indicates whether the StationSpec was deallocated.
 
 */
 
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
 
{
 
@@ -859,13 +860,14 @@ void DeallocateSpecFromStation(BaseStati
 
		}
 
	}
 

	
 
	StationUpdateAnimTriggers(st);
 
}
 

	
 
/** Draw representation of a station tile for GUI purposes.
 
/**
 
 * Draw representation of a station tile for GUI purposes.
 
 * @param x Position x of image.
 
 * @param y Position y of image.
 
 * @param axis Axis.
 
 * @param railtype Rail type.
 
 * @param sclass, station Type of station.
 
 * @param station station ID
src/newgrf_station.h
Show inline comments
 
@@ -61,24 +61,26 @@ struct StationSpec {
 
	/**
 
	 * Bitmask of platform lengths available for the station.
 
	 * 0..6 correpsond to 1..7, while bit 7 corresponds to >7 tiles long.
 
	 */
 
	byte disallowed_lengths;
 

	
 
	/** Number of tile layouts.
 
	/**
 
	 * Number of tile layouts.
 
	 * A minimum of 8 is required is required for stations.
 
	 * 0-1 = plain platform
 
	 * 2-3 = platform with building
 
	 * 4-5 = platform with roof, left side
 
	 * 6-7 = platform with roof, right side
 
	 */
 
	uint tiles;
 
	DrawTileSprites *renderdata; ///< Array of tile layouts.
 
	bool copied_renderdata;
 

	
 
	/** Cargo threshold for choosing between little and lots of cargo
 
	/**
 
	 * Cargo threshold for choosing between little and lots of cargo
 
	 * @note little/lots are equivalent to the moving/loading states for vehicles
 
	 */
 
	uint16 cargo_threshold;
 

	
 
	uint32 cargo_triggers; ///< Bitmask of cargo types which cause trigger re-randomizing
 

	
src/newgrf_text.cpp
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 newgrf_text.cpp
 
/**
 
 * @file newgrf_text.cpp
 
 * Implementation of  Action 04 "universal holder" structure and functions.
 
 * This file implements a linked-lists of strings,
 
 * holding everything that the newgrf action 04 will send over to OpenTTD.
 
 * One of the biggest problems is that Dynamic lang Array uses ISO codes
 
 * as way to identifying current user lang, while newgrf uses bit shift codes
 
 * not related to ISO.  So equivalence functionnality had to be set.
src/newgrf_town.cpp
Show inline comments
 
@@ -10,13 +10,14 @@
 
/** @file newgrf_town.cpp Implementation of the town part of NewGRF houses. */
 

	
 
#include "stdafx.h"
 
#include "debug.h"
 
#include "town.h"
 

	
 
/** This function implements the town variables that newGRF defines.
 
/**
 
 * This function implements the town variables that newGRF defines.
 
 * @param variable that is queried
 
 * @param parameter unused
 
 * @param available will return false if ever the variable asked for does not exist
 
 * @param t is of course the town we are inquiring
 
 * @return the value stored in the corresponding variable*/
 
uint32 TownGetVariable(byte variable, byte parameter, bool *available, const Town *t)
src/newgrf_townname.cpp
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 newgrf_townname.cpp
 
/**
 
 * @file newgrf_townname.cpp
 
 * Implementation of  Action 0F "universal holder" structure and functions.
 
 * This file implements a linked-lists of townname generators,
 
 * holding everything that the newgrf action 0F will send over to OpenTTD.
 
 */
 

	
 
#include "stdafx.h"
src/newgrf_townname.h
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 newgrf_townname.h
 
/**
 
 * @file newgrf_townname.h
 
 * Header of Action 0F "universal holder" structure and functions
 
 */
 

	
 
#ifndef NEWGRF_TOWNNAME_H
 
#define NEWGRF_TOWNNAME_H
 

	
src/news_gui.cpp
Show inline comments
 
@@ -38,13 +38,14 @@ bool _news_ticker_sound; ///< Make a tic
 

	
 
static uint MIN_NEWS_AMOUNT = 30;           ///< prefered minimum amount of news messages
 
static uint _total_news = 0;                ///< current number of news items
 
static NewsItem *_oldest_news = NULL;       ///< head of news items queue
 
static NewsItem *_latest_news = NULL;       ///< tail of news items queue
 

	
 
/** Forced news item.
 
/**
 
 * Forced news item.
 
 * Users can force an item by accessing the history or "last message".
 
 * If the message being shown was forced by the user, a pointer is stored
 
 * in _forced_news. Otherwise, \a _forced_news variable is NULL. */
 
static const NewsItem *_forced_news = NULL;       ///< item the user has asked for
 

	
 
/** Current news item (last item shown regularly). */
 
@@ -763,13 +764,14 @@ void DeleteVehicleNews(VehicleID vid, St
 
			DeleteNewsItem(ni);
 
		}
 
		ni = next;
 
	}
 
}
 

	
 
/** Remove news regarding given station so there are no 'unknown station now accepts Mail'
 
/**
 
 * Remove news regarding given station so there are no 'unknown station now accepts Mail'
 
 * or 'First train arrived at unknown station' news items.
 
 * @param sid station to remove news about
 
 */
 
void DeleteStationNews(StationID sid)
 
{
 
	NewsItem *ni = _oldest_news;
 
@@ -780,13 +782,14 @@ void DeleteStationNews(StationID sid)
 
			DeleteNewsItem(ni);
 
		}
 
		ni = next;
 
	}
 
}
 

	
 
/** Remove news regarding given industry
 
/**
 
 * Remove news regarding given industry
 
 * @param iid industry to remove news about
 
 */
 
void DeleteIndustryNews(IndustryID iid)
 
{
 
	NewsItem *ni = _oldest_news;
 

	
src/openttd.cpp
Show inline comments
 
@@ -313,13 +313,14 @@ static void InitializeDynamicVariables()
 
	_industile_mngr.ResetMapping();
 
	_airport_mngr.ResetMapping();
 
	_airporttile_mngr.ResetMapping();
 
}
 

	
 

	
 
/** Unitializes drivers, frees allocated memory, cleans pools, ...
 
/**
 
 * Unitializes drivers, frees allocated memory, cleans pools, ...
 
 * Generally, prepares the game for shutting down
 
 */
 
static void ShutdownGame()
 
{
 
	IConsoleFree();
 

	
 
@@ -1270,13 +1271,14 @@ void StateGameLoop()
 
		cur_company.Restore();
 
	}
 

	
 
	assert(IsLocalCompany());
 
}
 

	
 
/** Create an autosave. The default name is "autosave#.sav". However with
 
/**
 
 * Create an autosave. The default name is "autosave#.sav". However with
 
 * the setting 'keep_all_autosave' the name defaults to company-name + date */
 
static void DoAutosave()
 
{
 
	char buf[MAX_PATH];
 

	
 
#if defined(PSP)
src/order_base.h
Show inline comments
 
@@ -251,13 +251,14 @@ public:
 
	 * Converts this order from an old savegame's version;
 
	 * it moves all bits to the new location.
 
	 */
 
	void ConvertFromOldSavegame();
 
};
 

	
 
/** Shared order list linking together the linked list of orders and the list
 
/**
 
 * Shared order list linking together the linked list of orders and the list
 
 *  of vehicles sharing this order list.
 
 */
 
struct OrderList : OrderListPool::PoolItem<&_orderlist_pool> {
 
private:
 
	friend void AfterLoadVehicles(bool part_of_load); ///< For instantiating the shared vehicle chain
 
	friend const struct SaveLoad *GetOrderListDescription(); ///< Saving and loading of order lists.
 
@@ -272,13 +273,14 @@ private:
 
public:
 
	/** Default constructor producing an invalid order list. */
 
	OrderList(VehicleOrderID num_orders = INVALID_VEH_ORDER_ID)
 
		: first(NULL), num_orders(num_orders), num_vehicles(0), first_shared(NULL),
 
		  timetable_duration(0) { }
 

	
 
	/** Create an order list with the given order chain for the given vehicle.
 
	/**
 
	 * Create an order list with the given order chain for the given vehicle.
 
	 *  @param chain pointer to the first order of the order chain
 
	 *  @param v any vehicle using this orderlist
 
	 */
 
	OrderList(Order *chain, Vehicle *v) { this->Initialize(chain, v); }
 

	
 
	/** Destructor. Invalidates OrderList for re-usage by the pool. */
src/order_cmd.cpp
Show inline comments
 
@@ -447,13 +447,14 @@ static uint GetOrderDistance(const Order
 
	TileIndex prev_tile = prev->GetLocation(v);
 
	TileIndex cur_tile = cur->GetLocation(v);
 
	if (prev_tile == INVALID_TILE || cur_tile == INVALID_TILE) return 0;
 
	return DistanceManhattan(prev_tile, cur_tile);
 
}
 

	
 
/** Add an order to the orderlist of a vehicle.
 
/**
 
 * Add an order to the orderlist of a vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements
 
 * - 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
 
@@ -715,13 +716,14 @@ CommandCost CmdInsertOrder(TileIndex til
 
		InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Declone an order-list
 
/**
 
 * Declone an order-list
 
 * @param *dst delete the orders of this vehicle
 
 * @param flags execution flags
 
 */
 
static CommandCost DecloneOrder(Vehicle *dst, DoCommandFlag flags)
 
{
 
	if (flags & DC_EXEC) {
 
@@ -729,13 +731,14 @@ static CommandCost DecloneOrder(Vehicle 
 
		InvalidateVehicleOrder(dst, -1);
 
		InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Delete an order from the orderlist of a 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)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -797,13 +800,14 @@ CommandCost CmdDeleteOrder(TileIndex til
 
		InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Goto order of order-list.
 
/**
 
 * 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
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -911,13 +915,14 @@ CommandCost CmdMoveOrder(TileIndex tile,
 
		InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Modify an order in the orderlist of a vehicle.
 
/**
 
 * Modify an order in the orderlist of a vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements
 
 * - 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
 
@@ -1147,13 +1152,14 @@ CommandCost CmdModifyOrder(TileIndex til
 
		}
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Clone/share/copy an order-list of another vehicle.
 
/**
 
 * Clone/share/copy an order-list of another vehicle.
 
 * @param tile unused
 
 * @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
 
@@ -1275,13 +1281,14 @@ CommandCost CmdCloneOrder(TileIndex tile
 
		default: return CMD_ERROR;
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Add/remove refit orders from an order
 
/**
 
 * Add/remove refit orders from an order
 
 * @param tile Not used
 
 * @param flags operation to perform
 
 * @param p1 VehicleIndex of the vehicle having the order
 
 * @param p2 bitmask
 
 *   - bit 0-7 CargoID
 
 *   - bit 8-15 Cargo subtype
 
@@ -1428,13 +1435,14 @@ void RestoreVehicleOrders(const Vehicle 
 
	DoCommandP(0, v->index, bak->orderindex | (bak->service_interval << 16), CMD_RESTORE_ORDER_INDEX);
 

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

	
 
/** Restore the current order-index of a vehicle and sets service-interval.
 
/**
 
 * 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
 
 * @param p2 various bistuffed elements
 
 * - p2 = (bit  0-15) - current order-index (p2 & 0xFFFF)
 
 * - p2 = (bit 16-31) - service interval (p2 >> 16)
src/order_gui.cpp
Show inline comments
 
@@ -388,13 +388,14 @@ static Order GetOrderCmdFromTile(const V
 

	
 
	/* not found */
 
	order.Free();
 
	return order;
 
}
 

	
 
/** %Order window code for all vehicles.
 
/**
 
 * %Order window code for all vehicles.
 
 *
 
 * At the bottom of the window two button rows are located for changing the orders of the vehicle.
 
 *
 
 * \section top-row Top row
 
 * The top-row is for manipulating an individual order. What row is displayed depends on the type of vehicle, and whether or not you are the owner of the vehicle.
 
 *
src/os/unix/unix.cpp
Show inline comments
 
@@ -123,13 +123,14 @@ bool FiosIsHiddenFile(const struct diren
 
#include "../../string_func.h"
 

	
 
const char *GetCurrentLocale(const char *param);
 

	
 
#define INTERNALCODE "UTF-8"
 

	
 
/** Try and try to decipher the current locale from environmental
 
/**
 
 * Try and try to decipher the current locale from environmental
 
 * variables. MacOSX is hardcoded, other OS's are dynamic. If no suitable
 
 * locale can be found, don't do any conversion "" */
 
static const char *GetLocalCode()
 
{
 
#if defined(__APPLE__)
 
	return "UTF-8-MAC";
 
@@ -171,13 +172,14 @@ static const char *convert_tofrom_fs(ico
 

	
 
	*outbuf = '\0';
 
	/* FIX: invalid characters will abort conversion, but they shouldn't occur? */
 
	return buf;
 
}
 

	
 
/** Convert from OpenTTD's encoding to that of the local environment
 
/**
 
 * Convert from OpenTTD's encoding to that of the local environment
 
 * @param name pointer to a valid string that will be converted
 
 * @return pointer to a new stringbuffer that contains the converted string */
 
const char *OTTD2FS(const char *name)
 
{
 
	static iconv_t convd = (iconv_t)(-1);
 

	
 
@@ -190,13 +192,14 @@ const char *OTTD2FS(const char *name)
 
		}
 
	}
 

	
 
	return convert_tofrom_fs(convd, name);
 
}
 

	
 
/** Convert to OpenTTD's encoding from that of the local environment
 
/**
 
 * Convert to OpenTTD's encoding from that of the local environment
 
 * @param name pointer to a valid string that will be converted
 
 * @return pointer to a new stringbuffer that contains the converted string */
 
const char *FS2OTTD(const char *name)
 
{
 
	static iconv_t convd = (iconv_t)(-1);
 

	
src/os/windows/win32.cpp
Show inline comments
 
@@ -38,13 +38,14 @@ bool MyShowCursor(bool show)
 
	cursor_visible = show;
 
	ShowCursor(show);
 

	
 
	return !show;
 
}
 

	
 
/** Helper function needed by dynamically loading libraries
 
/**
 
 * Helper function needed by dynamically loading libraries
 
 * XXX: Hurray for MS only having an ANSI GetProcAddress function
 
 * on normal windows and no Wide version except for in Windows Mobile/CE */
 
bool LoadLibraryList(Function proc[], const char *dll)
 
{
 
	while (*dll != '\0') {
 
		HMODULE lib;
 
@@ -628,13 +629,14 @@ const TCHAR *OTTD2FS(const char *name)
 
	*s = '\0';
 
	return system_buf;
 
#endif /* UNICODE */
 
}
 

	
 

	
 
/** Convert to OpenTTD's encoding from that of the environment in
 
/**
 
 * Convert to OpenTTD's encoding from that of the environment in
 
 * UNICODE. OpenTTD encoding is UTF8, local is wide
 
 * @param name pointer to a valid string that will be converted
 
 * @param utf8_buf pointer to a valid buffer that will receive the converted string
 
 * @param buflen length in characters of the receiving buffer
 
 * @return pointer to utf8_buf. If conversion fails the string is of zero-length */
 
char *convert_from_fs(const wchar_t *name, char *utf8_buf, size_t buflen)
 
@@ -646,13 +648,14 @@ char *convert_from_fs(const wchar_t *nam
 
	}
 

	
 
	return utf8_buf;
 
}
 

	
 

	
 
/** Convert from OpenTTD's encoding to that of the environment in
 
/**
 
 * Convert from OpenTTD's encoding to that of the environment in
 
 * UNICODE. OpenTTD encoding is UTF8, local is wide
 
 * @param name pointer to a valid string that will be converted
 
 * @param utf16_buf pointer to a valid wide-char buffer that will receive the
 
 * converted string
 
 * @param buflen length in wide characters of the receiving buffer
 
 * @return pointer to utf16_buf. If conversion fails the string is of zero-length */
 
@@ -664,13 +667,14 @@ wchar_t *convert_to_fs(const char *name,
 
		utf16_buf[0] = '\0';
 
	}
 

	
 
	return utf16_buf;
 
}
 

	
 
/** Our very own SHGetFolderPath function for support of windows operating
 
/**
 
 * Our very own SHGetFolderPath function for support of windows operating
 
 * systems that don't have this function (eg Win9x, etc.). We try using the
 
 * native function, and if that doesn't exist we will try a more crude approach
 
 * of environment variables and hope for the best */
 
HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath)
 
{
 
	static HRESULT (WINAPI *SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = NULL;
src/pathfinder/follow_track.hpp
Show inline comments
 
@@ -18,13 +18,14 @@
 
#include "../train.h"
 
#include "../tunnelbridge.h"
 
#include "../tunnelbridge_map.h"
 
#include "../depot_map.h"
 
#include "pf_performance_timer.hpp"
 

	
 
/** Track follower helper template class (can serve pathfinders and vehicle
 
/**
 
 * Track follower helper template class (can serve pathfinders and vehicle
 
 *  controllers). See 6 different typedefs below for 3 different transport
 
 *  types w/ or w/o 90-deg turns allowed */
 
template <TransportType Ttr_type_, typename VehicleType, bool T90deg_turns_allowed_ = true, bool Tmask_reserved_tracks = false>
 
struct CFollowTrackT
 
{
 
	enum ErrorCode {
 
@@ -107,13 +108,14 @@ struct CFollowTrackT
 
				default: break;
 
			}
 
		}
 
		return INVALID_DIAGDIR;
 
	}
 

	
 
	/** main follower routine. Fills all members and return true on success.
 
	/**
 
	 * main follower routine. Fills all members and return true on success.
 
	 *  Otherwise returns false if track can't be followed. */
 
	inline bool Follow(TileIndex old_tile, Trackdir old_td)
 
	{
 
		m_old_tile = old_tile;
 
		m_old_td = old_td;
 
		m_err = EC_NONE;
src/pathfinder/npf/aystar.h
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 aystar.h
 
/**
 
 * @file aystar.h
 
 * This file has the header for AyStar
 
 *  AyStar is a fast pathfinding routine and is used for things like
 
 *  AI_pathfinding and Train_pathfinding.
 
 *  For more information about AyStar (A* Algorithm), you can look at
 
 *   http://en.wikipedia.org/wiki/A-star_search_algorithm
 
 */
src/pathfinder/npf/queue.cpp
Show inline comments
 
@@ -432,13 +432,14 @@ void clear_Hash(Hash *h, bool free_value
 
			}
 
		}
 
	}
 
	h->size = 0;
 
}
 

	
 
/** Finds the node that that saves this key pair. If it is not
 
/**
 
 * Finds the node that that saves this key pair. If it is not
 
 * found, returns NULL. If it is found, *prev is set to the
 
 * node before the one found, or if the node found was the first in the bucket
 
 * to NULL. If it is not found, *prev is set to the last HashNode in the
 
 * bucket, or NULL if it is empty. prev can also be NULL, in which case it is
 
 * not used for output.
 
 */
src/pathfinder/npf/queue.h
Show inline comments
 
@@ -95,13 +95,14 @@ void init_InsSort(Queue *q);
 
 *   http://www.policyalmanac.org/games/binaryHeaps.htm
 
 */
 

	
 
/* The amount of elements that will be malloc'd at a time */
 
#define BINARY_HEAP_BLOCKSIZE_BITS 10
 

	
 
/** Initializes a binary heap and allocates internal memory for maximum of
 
/**
 
 * Initializes a binary heap and allocates internal memory for maximum of
 
 * max_size elements */
 
void init_BinaryHeap(Queue *q, uint max_size);
 

	
 

	
 
/*
 
 * Hash
 
@@ -130,26 +131,30 @@ struct Hash {
 
	 * there are any Nodes in the bucket */
 
	bool *buckets_in_use;
 
};
 

	
 
/* Call these function to manipulate a hash */
 

	
 
/** Deletes the value with the specified key pair from the hash and returns
 
/**
 
 * Deletes the value with the specified key pair from the hash and returns
 
 * that value. Returns NULL when the value was not present. The value returned
 
 * is _not_ free()'d! */
 
void *Hash_Delete(Hash *h, uint key1, uint key2);
 
/** Sets the value associated with the given key pair to the given value.
 
/**
 
 * Sets the value associated with the given key pair to the given value.
 
 * Returns the old value if the value was replaced, NULL when it was not yet present. */
 
void *Hash_Set(Hash *h, uint key1, uint key2, void *value);
 
/** Gets the value associated with the given key pair, or NULL when it is not
 
/**
 
 * Gets the value associated with the given key pair, or NULL when it is not
 
 * present. */
 
void *Hash_Get(const Hash *h, uint key1, uint key2);
 

	
 
/* Call these function to create/destroy a hash */
 

	
 
/** Builds a new hash in an existing struct. Make sure that hash() always
 
/**
 
 * Builds a new hash in an existing struct. Make sure that hash() always
 
 * returns a hash less than num_buckets! Call delete_hash after use */
 
void init_Hash(Hash *h, Hash_HashProc *hash, uint num_buckets);
 
/**
 
 * Deletes the hash and cleans up. Only cleans up memory allocated by new_Hash
 
 * & friends. If free is true, it will call free() on all the values that
 
 * are left in the hash.
src/pathfinder/opf/opf_ship.cpp
Show inline comments
 
@@ -175,13 +175,14 @@ bad:;
 
	} while (bits != 0);
 

	
 
	*track = best_track;
 
	return best_bird_dist;
 
}
 

	
 
/** returns the track to choose on the next tile, or -1 when it's better to
 
/**
 
 * returns the track to choose on the next tile, or -1 when it's better to
 
 * reverse. The tile given is the tile we are about to enter, enterdir is the
 
 * direction in which we are entering the tile */
 
Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
 
{
 
	assert(IsValidDiagDirection(enterdir));
 

	
src/pathfinder/yapf/nodelist.hpp
Show inline comments
 
@@ -13,13 +13,14 @@
 
#define  NODELIST_HPP
 

	
 
#include "../../misc/array.hpp"
 
#include "../../misc/hashtable.hpp"
 
#include "../../misc/binaryheap.hpp"
 

	
 
/** Hash table based node list multi-container class.
 
/**
 
 * Hash table based node list multi-container class.
 
 *  Implements open list, closed list and priority queue for A-star
 
 *  path finder. */
 
template <class Titem_, int Thash_bits_open_, int Thash_bits_closed_>
 
class CNodeList_HashTableT {
 
public:
 
	/** make Titem_ visible from outside of class */
src/pathfinder/yapf/yapf_base.hpp
Show inline comments
 
@@ -14,13 +14,14 @@
 

	
 
#include "../../debug.h"
 
#include "../../settings_type.h"
 

	
 
extern int _total_pf_time_us;
 

	
 
/** CYapfBaseT - A-star type path finder base class.
 
/**
 
 * CYapfBaseT - A-star type path finder base class.
 
 *  Derive your own pathfinder from it. You must provide the following template argument:
 
 *    Types      - used as collection of local types used in pathfinder
 
 *
 
 * Requirements for the Types struct:
 
 *  ----------------------------------
 
 *  The following types must be defined in the 'Types' argument:
 
@@ -105,13 +106,14 @@ public:
 
	/** return current settings (can be custom - company based - but later) */
 
	FORCEINLINE const YAPFSettings& PfGetSettings() const
 
	{
 
		return *m_settings;
 
	}
 

	
 
	/** Main pathfinder routine:
 
	/**
 
	 * Main pathfinder routine:
 
	 *   - set startup node(s)
 
	 *   - main loop that stops if:
 
	 *      - the destination was found
 
	 *      - or the open list is empty (no route to destination).
 
	 *      - or the maximum amount of loops reached - m_max_search_nodes (default = 10000)
 
	 * @return true if the path was found */
 
@@ -171,21 +173,23 @@ public:
 
			}
 
		}
 
#endif /* !NO_DEBUG_MESSAGES */
 
		return bDestFound;
 
	}
 

	
 
	/** If path was found return the best node that has reached the destination. Otherwise
 
	/**
 
	 * If path was found return the best node that has reached the destination. Otherwise
 
	 *  return the best visited node (which was nearest to the destination).
 
	 */
 
	FORCEINLINE Node *GetBestNode()
 
	{
 
		return (m_pBestDestNode != NULL) ? m_pBestDestNode : m_pBestIntermediateNode;
 
	}
 

	
 
	/** Calls NodeList::CreateNewNode() - allocates new node that can be filled and used
 
	/**
 
	 * Calls NodeList::CreateNewNode() - allocates new node that can be filled and used
 
	 *  as argument for AddStartupNode() or AddNewNode()
 
	 */
 
	FORCEINLINE Node& CreateNewNode()
 
	{
 
		Node& node = *m_nodes.CreateNewNode();
 
		return node;
 
@@ -214,13 +218,14 @@ public:
 
			Node& n = Yapf().CreateNewNode();
 
			n.Set(parent, tf.m_new_tile, td, is_choice);
 
			Yapf().AddNewNode(n, tf);
 
		}
 
	}
 

	
 
	/** AddNewNode() - called by Tderived::PfFollowNode() for each child node.
 
	/**
 
	 * AddNewNode() - called by Tderived::PfFollowNode() for each child node.
 
	 *  Nodes are evaluated here and added into open list */
 
	void AddNewNode(Node &n, const TrackFollower &tf)
 
	{
 
		/* evaluate the node */
 
		bool bCached = Yapf().PfNodeCacheFetch(n);
 
		if (!bCached) {
src/pathfinder/yapf/yapf_common.hpp
Show inline comments
 
@@ -143,13 +143,14 @@ public:
 
	FORCEINLINE bool PfDetectDestination(Node& n)
 
	{
 
		bool bDest = (n.m_key.m_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetTrackdir())) != TRACKDIR_BIT_NONE);
 
		return bDest;
 
	}
 

	
 
	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	/**
 
	 * Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
 
	inline bool PfCalcEstimate(Node& n)
 
	{
 
		static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
 
		static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
 
		if (PfDetectDestination(n)) {
 
@@ -171,13 +172,14 @@ public:
 
		n.m_estimate = n.m_cost + d;
 
		assert(n.m_estimate >= n.m_parent->m_estimate);
 
		return true;
 
	}
 
};
 

	
 
/** YAPF template that uses Ttypes template argument to determine all YAPF
 
/**
 
 * YAPF template that uses Ttypes template argument to determine all YAPF
 
 *  components (base classes) from which the actual YAPF is composed.
 
 *  For example classes consult: CYapfRail_TypesT template and its instantiations:
 
 *  CYapfRail1, CYapfRail2, CYapfRail3, CYapfAnyDepotRail1, CYapfAnyDepotRail2, CYapfAnyDepotRail3 */
 
template <class Ttypes>
 
class CYapfT
 
	: public Ttypes::PfBase         ///< Instance of CYapfBaseT - main YAPF loop and support base class
src/pathfinder/yapf/yapf_costcache.hpp
Show inline comments
 
@@ -11,39 +11,43 @@
 

	
 
#ifndef  YAPF_COSTCACHE_HPP
 
#define  YAPF_COSTCACHE_HPP
 

	
 
#include "../../date_func.h"
 

	
 
/** CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements
 
/**
 
 * CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements
 
 * PfNodeCacheFetch() and PfNodeCacheFlush() callbacks. Used when nodes don't have CachedData
 
 * defined (they don't count with any segment cost caching).
 
 */
 
template <class Types>
 
class CYapfSegmentCostCacheNoneT
 
{
 
public:
 
	typedef typename Types::Tpf Tpf;              ///< the pathfinder class (derived from THIS class)
 
	typedef typename Types::NodeList::Titem Node; ///< this will be our node type
 

	
 
	/** Called by YAPF to attach cached or local segment cost data to the given node.
 
	/**
 
	 * Called by YAPF to attach cached or local segment cost data to the given node.
 
	 *  @return true if globally cached data were used or false if local data was used */
 
	FORCEINLINE bool PfNodeCacheFetch(Node& n)
 
	{
 
		return false;
 
	}
 

	
 
	/** Called by YAPF to flush the cached segment cost data back into cache storage.
 
	/**
 
	 * Called by YAPF to flush the cached segment cost data back into cache storage.
 
	 *  Current cache implementation doesn't use that. */
 
	FORCEINLINE void PfNodeCacheFlush(Node& n)
 
	{
 
	}
 
};
 

	
 

	
 
/** CYapfSegmentCostCacheLocalT - the yapf cost cache provider that implements fake segment
 
/**
 
 * CYapfSegmentCostCacheLocalT - the yapf cost cache provider that implements fake segment
 
 * cost caching functionality for yapf. Used when node needs caching, but you don't want to
 
 * cache the segment costs.
 
 */
 
template <class Types>
 
class CYapfSegmentCostCacheLocalT
 
{
 
@@ -62,30 +66,33 @@ protected:
 
	FORCEINLINE Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/** Called by YAPF to attach cached or local segment cost data to the given node.
 
	/**
 
	 * Called by YAPF to attach cached or local segment cost data to the given node.
 
	 *  @return true if globally cached data were used or false if local data was used */
 
	FORCEINLINE bool PfNodeCacheFetch(Node& n)
 
	{
 
		CacheKey key(n.GetKey());
 
		Yapf().ConnectNodeToCachedData(n, *new (m_local_cache.Append()) CachedData(key));
 
		return false;
 
	}
 

	
 
	/** Called by YAPF to flush the cached segment cost data back into cache storage.
 
	/**
 
	 * Called by YAPF to flush the cached segment cost data back into cache storage.
 
	 *  Current cache implementation doesn't use that. */
 
	FORCEINLINE void PfNodeCacheFlush(Node& n)
 
	{
 
	}
 
};
 

	
 

	
 
/** Base class for segment cost cache providers. Contains global counter
 
/**
 
 * Base class for segment cost cache providers. Contains global counter
 
 *  of track layout changes and static notification function called whenever
 
 *  the track layout changes. It is implemented as base class because it needs
 
 *  to be shared between all rail YAPF types (one shared counter, one notification
 
 *  function. */
 
struct CSegmentCostCacheBase
 
{
 
@@ -95,13 +102,14 @@ struct CSegmentCostCacheBase
 
	{
 
		s_rail_change_counter++;
 
	}
 
};
 

	
 

	
 
/** CSegmentCostCacheT - template class providing hash-map and storage (heap)
 
/**
 
 * CSegmentCostCacheT - template class providing hash-map and storage (heap)
 
 *  of Tsegment structures. Each rail node contains pointer to the segment
 
 *  that contains cached (or non-cached) segment cost information. Nodes can
 
 *  differ by key type, but they use the same segment type. Segment key should
 
 *  be always the same (TileIndex + DiagDirection) that represent the beginning
 
 *  of the segment (origin tile and exit-dir from this tile).
 
 *  Different CYapfCachedCostT types can share the same type of CSegmentCostCacheT.
 
@@ -139,13 +147,14 @@ struct CSegmentCostCacheT
 
			*found = true;
 
		}
 
		return *item;
 
	}
 
};
 

	
 
/** CYapfSegmentCostCacheGlobalT - the yapf cost cache provider that adds the segment cost
 
/**
 
 * CYapfSegmentCostCacheGlobalT - the yapf cost cache provider that adds the segment cost
 
 *  caching functionality to yapf. Using this class as base of your will provide the global
 
 *  segment cost caching services for your Nodes.
 
 */
 
template <class Types>
 
class CYapfSegmentCostCacheGlobalT
 
	: public CYapfSegmentCostCacheLocalT<Types>
 
@@ -189,13 +198,14 @@ protected:
 
			C.Flush();
 
		}
 
		return C;
 
	}
 

	
 
public:
 
	/** Called by YAPF to attach cached or local segment cost data to the given node.
 
	/**
 
	 * Called by YAPF to attach cached or local segment cost data to the given node.
 
	 *  @return true if globally cached data were used or false if local data was used */
 
	FORCEINLINE bool PfNodeCacheFetch(Node& n)
 
	{
 
		if (!Yapf().CanUseGlobalCache(n)) {
 
			return Tlocal::PfNodeCacheFetch(n);
 
		}
 
@@ -203,13 +213,14 @@ public:
 
		bool found;
 
		CachedData& item = m_global_cache.Get(key, &found);
 
		Yapf().ConnectNodeToCachedData(n, item);
 
		return found;
 
	}
 

	
 
	/** Called by YAPF to flush the cached segment cost data back into cache storage.
 
	/**
 
	 * Called by YAPF to flush the cached segment cost data back into cache storage.
 
	 *  Current cache implementation doesn't use that. */
 
	FORCEINLINE void PfNodeCacheFlush(Node& n)
 
	{
 
	}
 
};
 

	
src/pathfinder/yapf/yapf_costrail.hpp
Show inline comments
 
@@ -273,13 +273,14 @@ public:
 
public:
 
	FORCEINLINE void SetMaxCost(int max_cost)
 
	{
 
		m_max_cost = max_cost;
 
	}
 

	
 
	/** Called by YAPF to calculate the cost from the origin to the given node.
 
	/**
 
	 * Called by YAPF to calculate the cost from the origin to the given node.
 
	 *  Calculates only the cost of given node, adds it to the parent node cost
 
	 *  and stores the result into Node::m_cost member */
 
	FORCEINLINE bool PfCalcCost(Node &n, const TrackFollower *tf)
 
	{
 
		assert(!n.flags_u.flags_s.m_targed_seen);
 
		assert(tf->m_new_tile == n.m_key.m_tile);
src/pathfinder/yapf/yapf_destrail.hpp
Show inline comments
 
@@ -60,13 +60,14 @@ public:
 
	FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
 
	{
 
		bool bDest = IsRailDepotTile(tile);
 
		return bDest;
 
	}
 

	
 
	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	/**
 
	 * Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
 
	FORCEINLINE bool PfCalcEstimate(Node& n)
 
	{
 
		n.m_estimate = n.m_cost;
 
		return true;
 
	}
 
@@ -99,13 +100,14 @@ public:
 
	{
 
		return
 
			IsSafeWaitingPosition(Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns()) &&
 
			IsWaitingPositionFree(Yapf().GetVehicle(), tile, td, !TrackFollower::Allow90degTurns());
 
	}
 

	
 
	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	/**
 
	 * Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate. */
 
	FORCEINLINE bool PfCalcEstimate(Node& n)
 
	{
 
		n.m_estimate = n.m_cost;
 
		return true;
 
	}
 
@@ -178,13 +180,14 @@ public:
 
			bDest = (tile == m_destTile)
 
				&& ((m_destTrackdirs & TrackdirToTrackdirBits(td)) != TRACKDIR_BIT_NONE);
 
		}
 
		return bDest;
 
	}
 

	
 
	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	/**
 
	 * Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
 
	FORCEINLINE bool PfCalcEstimate(Node& n)
 
	{
 
		static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
 
		static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
 
		if (PfDetectDestination(n)) {
src/pathfinder/yapf/yapf_rail.cpp
Show inline comments
 
@@ -198,13 +198,14 @@ protected:
 
	FORCEINLINE Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/** Called by YAPF to move from the given node to the next tile. For each
 
	/**
 
	 * Called by YAPF to move from the given node to the next tile. For each
 
	 *  reachable trackdir on the new tile creates new node, initializes it
 
	 *  and adds it to the open list by calling Yapf().AddNewNode(n) */
 
	inline void PfFollowNode(Node& old_node)
 
	{
 
		TrackFollower F(Yapf().GetVehicle());
 
		if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
 
@@ -292,13 +293,14 @@ protected:
 
	FORCEINLINE Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/** Called by YAPF to move from the given node to the next tile. For each
 
	/**
 
	 * Called by YAPF to move from the given node to the next tile. For each
 
	 *  reachable trackdir on the new tile creates new node, initializes it
 
	 *  and adds it to the open list by calling Yapf().AddNewNode(n) */
 
	inline void PfFollowNode(Node& old_node)
 
	{
 
		TrackFollower F(Yapf().GetVehicle(), Yapf().GetCompatibleRailTypes());
 
		if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir()) && F.MaskReservedTracks()) {
 
@@ -373,13 +375,14 @@ protected:
 
	FORCEINLINE Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/** Called by YAPF to move from the given node to the next tile. For each
 
	/**
 
	 * Called by YAPF to move from the given node to the next tile. For each
 
	 *  reachable trackdir on the new tile creates new node, initializes it
 
	 *  and adds it to the open list by calling Yapf().AddNewNode(n) */
 
	inline void PfFollowNode(Node& old_node)
 
	{
 
		TrackFollower F(Yapf().GetVehicle());
 
		if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
src/pathfinder/yapf/yapf_road.cpp
Show inline comments
 
@@ -92,13 +92,14 @@ protected:
 
			cost = YAPF_TILE_CORNER_LENGTH + Yapf().PfGetSettings().road_curve_penalty;
 
		}
 
		return cost;
 
	}
 

	
 
public:
 
	/** Called by YAPF to calculate the cost from the origin to the given node.
 
	/**
 
	 * Called by YAPF to calculate the cost from the origin to the given node.
 
	 *  Calculates only the cost of given node, adds it to the parent node cost
 
	 *  and stores the result into Node::m_cost member */
 
	FORCEINLINE bool PfCalcCost(Node& n, const TrackFollower *tf)
 
	{
 
		int segment_cost = 0;
 
		/* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */
 
@@ -183,13 +184,14 @@ public:
 

	
 
	FORCEINLINE bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
 
	{
 
		return IsRoadDepotTile(tile);
 
	}
 

	
 
	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	/**
 
	 * Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
 
	FORCEINLINE bool PfCalcEstimate(Node& n)
 
	{
 
		n.m_estimate = n.m_cost;
 
		return true;
 
	}
 
@@ -251,13 +253,14 @@ public:
 
				(m_non_artic || IsDriveThroughStopTile(tile));
 
		}
 

	
 
		return tile == m_destTile && ((m_destTrackdirs & TrackdirToTrackdirBits(trackdir)) != TRACKDIR_BIT_NONE);
 
	}
 

	
 
	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	/**
 
	 * Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
 
	inline bool PfCalcEstimate(Node& n)
 
	{
 
		static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
 
		static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
 
		if (PfDetectDestination(n)) {
 
@@ -299,13 +302,14 @@ protected:
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 

	
 
	/** Called by YAPF to move from the given node to the next tile. For each
 
	/**
 
	 * Called by YAPF to move from the given node to the next tile. For each
 
	 *  reachable trackdir on the new tile creates new node, initializes it
 
	 *  and adds it to the open list by calling Yapf().AddNewNode(n) */
 
	inline void PfFollowNode(Node& old_node)
 
	{
 
		TrackFollower F(Yapf().GetVehicle());
 
		if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td)) {
src/pathfinder/yapf/yapf_ship.cpp
Show inline comments
 
@@ -29,13 +29,14 @@ protected:
 
	FORCEINLINE Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/** Called by YAPF to move from the given node to the next tile. For each
 
	/**
 
	 * Called by YAPF to move from the given node to the next tile. For each
 
	 *  reachable trackdir on the new tile creates new node, initializes it
 
	 *  and adds it to the open list by calling Yapf().AddNewNode(n) */
 
	inline void PfFollowNode(Node& old_node)
 
	{
 
		TrackFollower F(Yapf().GetVehicle());
 
		if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td)) {
 
@@ -112,13 +113,14 @@ protected:
 
	Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/** Called by YAPF to calculate the cost from the origin to the given node.
 
	/**
 
	 * Called by YAPF to calculate the cost from the origin to the given node.
 
	 *  Calculates only the cost of given node, adds it to the parent node cost
 
	 *  and stores the result into Node::m_cost member */
 
	FORCEINLINE bool PfCalcCost(Node& n, const TrackFollower *tf)
 
	{
 
		/* base tile cost depending on distance */
 
		int c = IsDiagonalTrackdir(n.GetTrackdir()) ? YAPF_TILE_LENGTH : YAPF_TILE_CORNER_LENGTH;
 
@@ -133,13 +135,14 @@ public:
 
		/* apply it */
 
		n.m_cost = n.m_parent->m_cost + c;
 
		return true;
 
	}
 
};
 

	
 
/** Config struct of YAPF for ships.
 
/**
 
 * Config struct of YAPF for ships.
 
 *  Defines all 6 base YAPF modules as classes providing services for CYapfBaseT.
 
 */
 
template <class Tpf_, class Ttrack_follower, class Tnode_list>
 
struct CYapfShip_TypesT
 
{
 
	/** Types - shortcut for this struct type */
src/rail.h
Show inline comments
 
@@ -77,13 +77,14 @@ enum RailTrackOffset {
 
enum RailTrackBridgeOffset {
 
	RTBO_X,     ///< Piece of rail in X direction
 
	RTBO_Y,     ///< Piece of rail in Y direction
 
	RTBO_SLOPE, ///< Sloped rail pieces, in order NE, SE, SW, NW
 
};
 

	
 
/** Offsets from base sprite for fence sprites. These are in the order of
 
/**
 
 * Offsets from base sprite for fence sprites. These are in the order of
 
 *  the sprites in the original data files.
 
 */
 
enum RailFenceOffset {
 
	RFO_FLAT_X,
 
	RFO_FLAT_Y,
 
	RFO_FLAT_VERT,
 
@@ -91,16 +92,18 @@ enum RailFenceOffset {
 
	RFO_SLOPE_SW,
 
	RFO_SLOPE_SE,
 
	RFO_SLOPE_NE,
 
	RFO_SLOPE_NW,
 
};
 

	
 
/** This struct contains all the info that is needed to draw and construct tracks.
 
/**
 
 * This struct contains all the info that is needed to draw and construct tracks.
 
 */
 
struct RailtypeInfo {
 
	/** Struct containing the main sprites. @note not all sprites are listed, but only
 
	/**
 
	 * Struct containing the main sprites. @note not all sprites are listed, but only
 
	 *  the ones used directly in the code */
 
	struct {
 
		SpriteID track_y;      ///< single piece of rail in Y direction, with ground
 
		SpriteID track_ns;     ///< two pieces of rail in North and South corner (East-West direction)
 
		SpriteID ground;       ///< ground sprite for a 3-way switch
 
		SpriteID single_x;     ///< single piece of rail in X direction, without ground
 
@@ -111,13 +114,14 @@ struct RailtypeInfo {
 
		SpriteID single_w;     ///< single piece of rail in the western corner
 
		SpriteID single_sloped;///< single piecs of rail for slopes
 
		SpriteID crossing;     ///< level crossing, rail in X direction
 
		SpriteID tunnel;       ///< tunnel sprites base
 
	} base_sprites;
 

	
 
	/** struct containing the sprites for the rail GUI. @note only sprites referred to
 
	/**
 
	 * struct containing the sprites for the rail GUI. @note only sprites referred to
 
	 * directly in the code are listed */
 
	struct {
 
		SpriteID build_ns_rail;      ///< button for building single rail in N-S direction
 
		SpriteID build_x_rail;       ///< button for building single rail in X direction
 
		SpriteID build_ew_rail;      ///< button for building single rail in E-W direction
 
		SpriteID build_y_rail;       ///< button for building single rail in Y direction
src/rail_cmd.cpp
Show inline comments
 
@@ -157,13 +157,14 @@ static const byte _track_sloped_sprites[
 
static CommandCost EnsureNoTrainOnTrack(TileIndex tile, Track track)
 
{
 
	TrackBits rail_bits = TrackToTrackBits(track);
 
	return EnsureNoTrainOnTrackBits(tile, rail_bits);
 
}
 

	
 
/** Check that the new track bits may be built.
 
/**
 
 * Check that the new track bits may be built.
 
 * @param tile %Tile to build on.
 
 * @param to_build New track bits.
 
 * @param flags    Flags of the operation.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags)
 
@@ -347,13 +348,14 @@ static CommandCost CheckRailSlope(Slope 
 
/* Validate functions for rail building */
 
static inline bool ValParamTrackOrientation(Track track)
 
{
 
	return IsValidTrack(track);
 
}
 

	
 
/** Build a single piece of rail
 
/**
 
 * 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
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -486,13 +488,14 @@ CommandCost CmdBuildSingleRail(TileIndex
 
	}
 

	
 
	cost.AddCost(RailBuildCost(railtype));
 
	return cost;
 
}
 

	
 
/** Remove a single piece of track
 
/**
 
 * 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
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -725,13 +728,14 @@ static CommandCost ValidateAutoDrag(Trac
 
		if (abs(dx) != abs(dy) && abs(dx) + abs(trdy) != abs(dy) + abs(trdx)) return CMD_ERROR;
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Build or remove a stretch of railroad tracks.
 
/**
 
 * Build or remove a stretch of railroad tracks.
 
 * @param tile start tile of drag
 
 * @param flags operation to perform
 
 * @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)
 
@@ -785,13 +789,14 @@ static CommandCost CmdRailTrackHelper(Ti
 
	}
 

	
 
	if (had_success) return total_cost;
 
	return last_error;
 
}
 

	
 
/** Build rail on a stretch of track.
 
/**
 
 * 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
 
 * @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)
 
@@ -803,13 +808,14 @@ static CommandCost CmdRailTrackHelper(Ti
 
 */
 
CommandCost CmdBuildRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return CmdRailTrackHelper(tile, flags, p1, ClrBit(p2, 7), text);
 
}
 

	
 
/** Build rail on a stretch of track.
 
/**
 
 * 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
 
 * @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)
 
@@ -821,13 +827,14 @@ CommandCost CmdBuildRailroadTrack(TileIn
 
 */
 
CommandCost CmdRemoveRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return CmdRailTrackHelper(tile, flags, p1, SetBit(p2, 7), text);
 
}
 

	
 
/** Build a train depot
 
/**
 
 * 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)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -881,13 +888,14 @@ CommandCost CmdBuildTrainDepot(TileIndex
 

	
 
	cost.AddCost(_price[PR_BUILD_DEPOT_TRAIN]);
 
	cost.AddCost(RailBuildCost(railtype));
 
	return cost;
 
}
 

	
 
/** Build signals, alternate between double/single, signal/semaphore,
 
/**
 
 * Build signals, alternate between double/single, signal/semaphore,
 
 * pre/exit/combo-signals, and what-else not. If the rail piece does not
 
 * have any signals, bit 4 (cycle signal-type) is ignored
 
 * @param tile tile where to build the signals
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit 0-2) - track-orientation, valid values: 0-5 (Track enum)
 
@@ -1113,13 +1121,14 @@ static bool CheckSignalAutoFill(TileInde
 
		}
 

	
 
		default: return false;
 
	}
 
}
 

	
 
/** Build many signals by dragging; AutoSignals
 
/**
 
 * Build many signals by dragging; AutoSignals
 
 * @param tile start tile of drag
 
 * @param flags operation to perform
 
 * @param p1  end tile of drag
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
 
@@ -1246,13 +1255,14 @@ static CommandCost CmdSignalTrackHelper(
 
		}
 
	}
 

	
 
	return had_success ? total_cost : last_error;
 
}
 

	
 
/** Build signals on a stretch of track.
 
/**
 
 * Build signals on a stretch of track.
 
 * Stub for the unified signal builder/remover
 
 * @param tile start tile of drag
 
 * @param flags operation to perform
 
 * @param p1  end tile of drag
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
 
@@ -1268,13 +1278,14 @@ static CommandCost CmdSignalTrackHelper(
 
 */
 
CommandCost CmdBuildSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return CmdSignalTrackHelper(tile, flags, p1, p2, text);
 
}
 

	
 
/** Remove signals
 
/**
 
 * 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
 
@@ -1335,13 +1346,14 @@ CommandCost CmdRemoveSingleSignal(TileIn
 
		MarkTileDirtyByTile(tile);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_SIGNALS]);
 
}
 

	
 
/** Remove signals on a stretch of track.
 
/**
 
 * Remove signals on a stretch of track.
 
 * Stub for the unified signal builder/remover
 
 * @param tile start tile of drag
 
 * @param flags operation to perform
 
 * @param p1  end tile of drag
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
 
@@ -1373,13 +1385,14 @@ static Vehicle *UpdateTrainPowerProc(Veh
 
	const RailVehicleInfo *rvi = RailVehInfo(t->engine_type);
 
	if (GetVehicleProperty(t, PROP_TRAIN_POWER, rvi->power) != 0) t->First()->PowerChanged();
 

	
 
	return NULL;
 
}
 

	
 
/** Convert one rail type to the other. You can convert normal rail to
 
/**
 
 * Convert one rail type to the other. You can convert normal rail to
 
 * 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
 
 * @param text unused
 
@@ -2137,13 +2150,14 @@ static void DrawTrackBits(TileInfo *ti, 
 
			static const byte _corner_to_track_sprite[] = {3, 1, 2, 0};
 
			DrawGroundSprite(_corner_to_track_sprite[halftile_corner] + rti->base_sprites.single_n, PALETTE_CRASH, NULL, 0, -(int)TILE_HEIGHT);
 
		}
 
	}
 
}
 

	
 
/** Enums holding the offsets from base signal sprite,
 
/**
 
 * Enums holding the offsets from base signal sprite,
 
 * according to the side it is representing.
 
 * The addtion of 2 per enum is necessary in order to "jump" over the
 
 * green state sprite, all signal sprites being in pair,
 
 * starting with the off-red state */
 
enum SignalOffsets {
 
	SIGNAL_TO_SOUTHWEST =  0,
 
@@ -2679,13 +2693,14 @@ static const byte _fractcoords_enter[4] 
 
static const int8 _deltacoord_leaveoffset[8] = {
 
	-1,  0,  1,  0, /* x */
 
	 0,  1,  0, -1  /* y */
 
};
 

	
 

	
 
/** Compute number of ticks when next wagon will leave a depot.
 
/**
 
 * Compute number of ticks when next wagon will leave a depot.
 
 * Negative means next wagon should have left depot n ticks before.
 
 * @param v vehicle outside (leaving) the depot
 
 * @return number of ticks when the next wagon will leave
 
 */
 
int TicksToLeaveDepot(const Train *v)
 
{
 
@@ -2700,13 +2715,14 @@ int TicksToLeaveDepot(const Train *v)
 
		case DIAGDIR_NW: return  ((int)(v->y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4)   - (length + 1)));
 
	}
 

	
 
	return 0; // make compilers happy
 
}
 

	
 
/** Tile callback routine when vehicle enters tile
 
/**
 
 * Tile callback routine when vehicle enters tile
 
 * @see vehicle_enter_tile_proc */
 
static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int x, int y)
 
{
 
	/* this routine applies only to trains in depot tiles */
 
	if (u->type != VEH_TRAIN || !IsRailDepotTile(tile)) return VETSB_CONTINUE;
 

	
src/rail_gui.cpp
Show inline comments
 
@@ -309,25 +309,27 @@ enum RailToolbarWidgets {
 
	RTW_BUILD_TUNNEL,
 
	RTW_REMOVE,
 
	RTW_CONVERT_RAIL,
 
};
 

	
 

	
 
/** Toggles state of the Remove button of Build rail toolbar
 
/**
 
 * Toggles state of the Remove button of Build rail toolbar
 
 * @param w window the button belongs to
 
 */
 
static void ToggleRailButton_Remove(Window *w)
 
{
 
	DeleteWindowById(WC_SELECT_STATION, 0);
 
	w->ToggleWidgetLoweredState(RTW_REMOVE);
 
	w->SetWidgetDirty(RTW_REMOVE);
 
	_remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE);
 
	SetSelectionRed(_remove_button_clicked);
 
}
 

	
 
/** Updates the Remove button because of Ctrl state change
 
/**
 
 * Updates the Remove button because of Ctrl state change
 
 * @param w window the button belongs to
 
 * @return true iff the remove buton was changed
 
 */
 
static bool RailToolbar_CtrlChanged(Window *w)
 
{
 
	if (w->IsWidgetDisabled(RTW_REMOVE)) return false;
 
@@ -632,13 +634,14 @@ struct BuildRailToolbarWindow : Window {
 

	
 
	~BuildRailToolbarWindow()
 
	{
 
		if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
 
	}
 

	
 
	/** Configures the rail toolbar for railtype given
 
	/**
 
	 * Configures the rail toolbar for railtype given
 
	 * @param railtype the railtype to display
 
	 */
 
	void SetupRailToolbar(RailType railtype)
 
	{
 
		this->railtype = railtype;
 
		const RailtypeInfo *rti = GetRailTypeInfo(railtype);
 
@@ -651,13 +654,14 @@ struct BuildRailToolbarWindow : Window {
 
		this->GetWidget<NWidgetCore>(RTW_AUTORAIL)->widget_data     = rti->gui_sprites.auto_rail;
 
		this->GetWidget<NWidgetCore>(RTW_BUILD_DEPOT)->widget_data  = rti->gui_sprites.build_depot;
 
		this->GetWidget<NWidgetCore>(RTW_CONVERT_RAIL)->widget_data = rti->gui_sprites.convert_rail;
 
		this->GetWidget<NWidgetCore>(RTW_BUILD_TUNNEL)->widget_data = rti->gui_sprites.build_tunnel;
 
	}
 

	
 
	/** Switch to another rail type.
 
	/**
 
	 * Switch to another rail type.
 
	 * @param railtype New rail type.
 
	 */
 
	void ModifyRailType(RailType railtype)
 
	{
 
		this->SetupRailToolbar(railtype);
 
		this->ReInit();
 
@@ -1936,13 +1940,14 @@ bool ResetSignalVariant(int32 p = 0)
 
		_cur_signal_variant = new_variant;
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Resets the rail GUI - sets default railtype to build
 
/**
 
 * Resets the rail GUI - sets default railtype to build
 
 * and resets the signal GUI
 
 */
 
void InitializeRailGUI()
 
{
 
	SetDefaultRailGui();
 

	
src/rail_map.h
Show inline comments
 
@@ -342,13 +342,14 @@ static inline void SetSignalVariant(Tile
 
{
 
	byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 7 : 3;
 
	SB(_m[t].m2, pos, 1, v);
 
	if (track == INVALID_TRACK) SB(_m[t].m2, 7, 1, v);
 
}
 

	
 
/** These are states in which a signal can be. Currently these are only two, so
 
/**
 
 * These are states in which a signal can be. Currently these are only two, so
 
 * simple boolean logic will do. But do try to compare to this enum instead of
 
 * normal boolean evaluation, since that will make future additions easier.
 
 */
 
enum SignalState {
 
	SIGNAL_STATE_RED   = 0, ///< The signal is red
 
	SIGNAL_STATE_GREEN = 1, ///< The signal is green
src/road_cmd.cpp
Show inline comments
 
@@ -165,13 +165,14 @@ CommandCost CheckAllowRemoveRoad(TileInd
 
	ChangeTownRating(t, rating_decrease, RATING_ROAD_MINIMUM, flags);
 

	
 
	return CommandCost();
 
}
 

	
 

	
 
/** Delete a piece of road.
 
/**
 
 * Delete a piece of road.
 
 * @param tile tile where to remove road from
 
 * @param flags operation to perform
 
 * @param pieces roadbits to remove
 
 * @param rt roadtype to remove
 
 * @param crossing_check should we check if there is a tram track when we are removing road from crossing?
 
 * @param town_check should we check if the town allows removal?
 
@@ -435,13 +436,14 @@ static CommandCost CheckRoadSlope(Slope 
 
			return CommandCost();
 
		}
 
	}
 
	return CMD_ERROR;
 
}
 

	
 
/** Build a piece of road.
 
/**
 
 * Build a piece of road.
 
 * @param tile tile where to build road
 
 * @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)
 
@@ -720,13 +722,14 @@ do_clear:;
 

	
 
		MarkTileDirtyByTile(tile);
 
	}
 
	return cost;
 
}
 

	
 
/** Build a long piece of road.
 
/**
 
 * Build a long piece of road.
 
 * @param start_tile start tile of drag (the building cost will appear over this tile)
 
 * @param flags operation to perform
 
 * @param p1 end tile of drag
 
 * @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)
 
@@ -814,13 +817,14 @@ CommandCost CmdBuildLongRoad(TileIndex s
 
		tile += TileOffsByDiagDir(dir);
 
	}
 

	
 
	return had_success ? cost : last_error;
 
}
 

	
 
/** Remove a long piece of road.
 
/**
 
 * Remove a long piece of road.
 
 * @param start_tile start tile of drag
 
 * @param flags operation to perform
 
 * @param p1 end tile of drag
 
 * @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)
 
@@ -888,13 +892,14 @@ CommandCost CmdRemoveLongRoad(TileIndex 
 
		tile += (axis == AXIS_Y) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 
	}
 

	
 
	return had_success ? cost : last_error;
 
}
 

	
 
/** Build a road depot.
 
/**
 
 * Build a road depot.
 
 * @param tile tile where to build the depot
 
 * @param flags operation to perform
 
 * @param p1 bit 0..1 entrance direction (DiagDirection)
 
 *           bit 2..3 road type
 
 * @param p2 unused
 
 * @param text unused
src/road_gui.cpp
Show inline comments
 
@@ -209,13 +209,14 @@ void CcRoadDepot(const CommandCost &resu
 

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

	
 
/** Command callback for building road stops.
 
/**
 
 * Command callback for building road stops.
 
 * @param result Result of the build road stop command.
 
 * @param tile Start tile.
 
 * @param p1 bit 0..7: Width of the road stop.
 
 *           bit 8..15: Length of the road stop.
 
 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
 
 *           bit 1: 0 For normal stops, 1 for drive-through.
 
@@ -309,24 +310,26 @@ enum RoadToolbarWidgets {
 
	RTW_REMOVE,
 
};
 

	
 
typedef void OnButtonClick(Window *w);
 

	
 

	
 
/** Toogles state of the Remove button of Build road toolbar
 
/**
 
 * Toogles state of the Remove button of Build road toolbar
 
 * @param w window the button belongs to
 
 */
 
static void ToggleRoadButton_Remove(Window *w)
 
{
 
	w->ToggleWidgetLoweredState(RTW_REMOVE);
 
	w->SetWidgetDirty(RTW_REMOVE);
 
	_remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE);
 
	SetSelectionRed(_remove_button_clicked);
 
}
 

	
 
/** Updates the Remove button because of Ctrl state change
 
/**
 
 * Updates the Remove button because of Ctrl state change
 
 * @param w window the button belongs to
 
 * @return true iff the remove buton was changed
 
 */
 
static bool RoadToolbar_CtrlChanged(Window *w)
 
{
 
	if (w->IsWidgetDisabled(RTW_REMOVE)) return false;
src/road_map.h
Show inline comments
 
@@ -146,13 +146,14 @@ static inline void SetRoadOwner(TileInde
 
static inline bool IsRoadOwner(TileIndex t, RoadType rt, Owner o)
 
{
 
	assert(HasTileRoadType(t, rt));
 
	return (GetRoadOwner(t, rt) == o);
 
}
 

	
 
/** Checks if given tile has town owned road
 
/**
 
 * Checks if given tile has town owned road
 
 * @param t tile to check
 
 * @return true iff tile has road and the road is owned by a town
 
 * @pre IsTileType(t, MP_ROAD)
 
 */
 
static inline bool HasTownOwnedRoad(TileIndex t)
 
{
src/roadveh_cmd.cpp
Show inline comments
 
@@ -188,13 +188,14 @@ void RoadVehUpdateCache(RoadVehicle *v)
 

	
 
		/* Invalidate the vehicle colour map */
 
		u->colourmap = PAL_NONE;
 
	}
 
}
 

	
 
/** Build a road vehicle.
 
/**
 
 * 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
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -319,13 +320,14 @@ bool RoadVehicle::IsStoppedInDepot() con
 
	for (const RoadVehicle *v = this; v != NULL; v = v->Next()) {
 
		if (v->state != RVSB_IN_DEPOT || v->tile != tile) return false;
 
	}
 
	return true;
 
}
 

	
 
/** Sell a road vehicle.
 
/**
 
 * Sell a road vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -373,13 +375,14 @@ bool RoadVehicle::FindClosestDepot(TileI
 
	if (location    != NULL) *location    = rfdd.tile;
 
	if (destination != NULL) *destination = GetDepotIndex(rfdd.tile);
 

	
 
	return true;
 
}
 

	
 
/** Send a road vehicle to the depot.
 
/**
 
 * Send a road vehicle to the depot.
 
 * @param tile unused
 
 * @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)
 
@@ -397,13 +400,14 @@ CommandCost CmdSendRoadVehToDepot(TileIn
 
	RoadVehicle *v = RoadVehicle::GetIfValid(p1);
 
	if (v == NULL) return CMD_ERROR;
 

	
 
	return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK));
 
}
 

	
 
/** Turn a roadvehicle around.
 
/**
 
 * Turn a roadvehicle around.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to turn
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -1748,13 +1752,14 @@ Trackdir RoadVehicle::GetVehicleTrackdir
 
	/* If vehicle's state is a valid track direction (vehicle is not turning around) return it,
 
	 * otherwise transform it into a valid track direction */
 
	return (Trackdir)((IsReversingRoadTrackdir((Trackdir)this->state)) ? (this->state - 6) : this->state);
 
}
 

	
 

	
 
/** Refit a road vehicle to the specified cargo type
 
/**
 
 * Refit a road vehicle to the specified cargo type
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 Vehicle ID of the vehicle to refit
 
 * @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
src/saveload/afterload.cpp
Show inline comments
 
@@ -2150,13 +2150,14 @@ bool AfterLoadGame()
 
	InitializeWindowsAndCaches();
 
	/* Restore the signals */
 
	ResetSignalHandlers();
 
	return true;
 
}
 

	
 
/** Reload all NewGRF files during a running game. This is a cut-down
 
/**
 
 * Reload all NewGRF files during a running game. This is a cut-down
 
 * version of AfterLoadGame().
 
 * XXX - We need to reset the vehicle position hash because with a non-empty
 
 * hash AfterLoadVehicles() will loop infinitely. We need AfterLoadVehicles()
 
 * to recalculate vehicle data as some NewGRF vehicle sets could have been
 
 * removed or added and changed statistics */
 
void ReloadNewGRFData()
src/saveload/airport_sl.cpp
Show inline comments
 
@@ -11,13 +11,14 @@
 

	
 
#include "../stdafx.h"
 
#include "../newgrf_commons.h"
 

	
 
#include "saveload.h"
 

	
 
/** Save and load the mapping between the airport id in the AirportSpec array
 
/**
 
 * Save and load the mapping between the airport id in the AirportSpec array
 
 * and the grf file it came from. */
 
static const SaveLoad _airport_id_mapping_desc[] = {
 
	SLE_VAR(EntityIDMapping, grfid,         SLE_UINT32),
 
	SLE_VAR(EntityIDMapping, entity_id,     SLE_UINT8),
 
	SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
 
	SLE_END()
src/saveload/order_sl.cpp
Show inline comments
 
@@ -63,22 +63,24 @@ void Order::ConvertFromOldSavegame()
 
		uint t = ((old_flags & 6) == 6) ? ODTFB_SERVICE : ODTF_MANUAL;
 
		if ((old_flags & 2) != 0) t |= ODTFB_PART_OF_ORDERS;
 
		this->SetDepotOrderType((OrderDepotTypeFlags)t);
 
	}
 
}
 

	
 
/** Unpacks a order from savegames with version 4 and lower
 
/**
 
 * Unpacks a order from savegames with version 4 and lower
 
 * @param packed packed order
 
 * @return unpacked order
 
 */
 
static Order UnpackVersion4Order(uint16 packed)
 
{
 
	return Order(GB(packed, 8, 8) << 16 | GB(packed, 4, 4) << 8 | GB(packed, 0, 4));
 
}
 

	
 
/** Unpacks a order from savegames made with TTD(Patch)
 
/**
 
 * Unpacks a order from savegames made with TTD(Patch)
 
 * @param packed packed order
 
 * @return unpacked order
 
 */
 
Order UnpackOldOrder(uint16 packed)
 
{
 
	Order order = UnpackVersion4Order(packed);
src/saveload/saveload.cpp
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 saveload.cpp
 
/**
 
 * @file saveload.cpp
 
 * All actions handling saving and loading goes on in this file. The general actions
 
 * are as follows for saving a game (loading is analogous):
 
 * <ol>
 
 * <li>initialize the writer by creating a temporary memory-buffer for it
 
 * <li>go through all to-be saved elements, each 'chunk' (ChunkHandler) prefixed by a label
 
 * <li>use their description array (SaveLoad) to know what elements to save and in what version
 
@@ -429,13 +430,14 @@ static void SlReadFill()
 

	
 
static inline size_t SlGetOffs()
 
{
 
	return _sl.offs_base - (_sl.bufe - _sl.bufp);
 
}
 

	
 
/** Flush the output buffer by writing to disk with the given reader.
 
/**
 
 * Flush the output buffer by writing to disk with the given reader.
 
 * If the buffer pointer has not yet been set up, set it up now. Usually
 
 * only called when the buffer is full, or there is no more data to be processed
 
 */
 
static void SlWriteFill()
 
{
 
	/* flush the buffer to disk (the writer) */
 
@@ -448,26 +450,28 @@ static void SlWriteFill()
 
	/* All the data from the buffer has been written away, rewind to the beginning
 
	 * to start reading in more data */
 
	_sl.bufp = _sl.buf;
 
	_sl.bufe = _sl.buf + _sl.bufsize;
 
}
 

	
 
/** Read in a single byte from file. If the temporary buffer is full,
 
/**
 
 * Read in a single byte from file. If the temporary buffer is full,
 
 * flush it to its final destination
 
 * @return return the read byte from file
 
 */
 
static inline byte SlReadByteInternal()
 
{
 
	if (_sl.bufp == _sl.bufe) SlReadFill();
 
	return *_sl.bufp++;
 
}
 

	
 
/** Wrapper for SlReadByteInternal */
 
byte SlReadByte() {return SlReadByteInternal();}
 

	
 
/** Write away a single byte from memory. If the temporary buffer is full,
 
/**
 
 * Write away a single byte from memory. If the temporary buffer is full,
 
 * flush it to its destination (file)
 
 * @param b the byte that is currently written
 
 */
 
static inline void SlWriteByteInternal(byte b)
 
{
 
	if (_sl.bufp == _sl.bufe) SlWriteFill();
 
@@ -511,13 +515,14 @@ static inline void SlWriteUint32(uint32 
 
static inline void SlWriteUint64(uint64 x)
 
{
 
	SlWriteUint32((uint32)(x >> 32));
 
	SlWriteUint32((uint32)x);
 
}
 

	
 
/** Read in bytes from the file/data structure but don't do
 
/**
 
 * Read in bytes from the file/data structure but don't do
 
 * anything with them, discarding them in effect
 
 * @param length The amount of bytes that is being treated this way
 
 */
 
static inline void SlSkipBytes(size_t length)
 
{
 
	for (; length != 0; length--) SlReadByte();
 
@@ -1241,13 +1246,14 @@ static inline bool SlIsObjectValidInSave
 
	if (_sl_version < sld->version_from || _sl_version > sld->version_to) return false;
 
	if (sld->conv & SLF_SAVE_NO) return false;
 

	
 
	return true;
 
}
 

	
 
/** Are we going to load this variable when loading a savegame or not?
 
/**
 
 * Are we going to load this variable when loading a savegame or not?
 
 * @note If the variable is skipped it is skipped in the savegame
 
 * bytestream itself as well, so there is no need to skip it somewhere else */
 
static inline bool SlSkipVariableOnLoad(const SaveLoad *sld)
 
{
 
	if ((sld->conv & SLF_NETWORK_NO) && _sl.action != SLA_SAVE && _networking && !_network_server) {
 
		SlSkipBytes(SlCalcConvMemLen(sld->conv) * sld->length);
 
@@ -2063,13 +2069,14 @@ static void SaveFileError()
 
{
 
	SetDParamStr(0, GetSaveLoadErrorString());
 
	ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
 
	SaveFileDone();
 
}
 

	
 
/** We have written the whole game into memory, _memory_savegame, now find
 
/**
 
 * We have written the whole game into memory, _memory_savegame, now find
 
 * and appropiate compressor and start writing to file.
 
 */
 
static SaveOrLoadResult SaveFileToDisk(bool threaded)
 
{
 
	_sl.excpt_uninit = NULL;
 
	try {
src/saveload/saveload.h
Show inline comments
 
@@ -91,13 +91,14 @@ enum ChunkType {
 
	CH_SPARSE_ARRAY =  2,
 
	CH_TYPE_MASK    =  3,
 
	CH_LAST         =  8,
 
	CH_AUTO_LENGTH  = 16,
 
};
 

	
 
/** VarTypes is the general bitmasked magic type that tells us
 
/**
 
 * VarTypes is the general bitmasked magic type that tells us
 
 * certain characteristics about the variable it refers to. For example
 
 * SLE_FILE_* gives the size(type) as it would be in the savegame and
 
 * SLE_VAR_* the size(type) as it is in memory during runtime. These are
 
 * the first 8 bits (0-3 SLE_FILE, 4-7 SLE_VAR).
 
 * Bits 8-15 are reserved for various flags as explained below */
 
enum VarTypes {
 
@@ -248,30 +249,33 @@ typedef SaveLoad SaveLoadGlobVarList;
 
#define SLEG_LST(variable, type) SLEG_CONDLST(variable, type, 0, SL_MAX_VERSION)
 

	
 
#define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_CONFIG_NO, length, from, to, (void*)NULL}
 

	
 
#define SLEG_END() {true, SL_END, 0, 0, 0, 0, NULL}
 

	
 
/** Checks if the savegame is below major.minor.
 
/**
 
 * Checks if the savegame is below major.minor.
 
 */
 
static inline bool CheckSavegameVersionOldStyle(uint16 major, byte minor)
 
{
 
	extern uint16 _sl_version;
 
	extern byte   _sl_minor_version;
 
	return (_sl_version < major) || (_sl_version == major && _sl_minor_version < minor);
 
}
 

	
 
/** Checks if the savegame is below version.
 
/**
 
 * Checks if the savegame is below version.
 
 */
 
static inline bool CheckSavegameVersion(uint16 version)
 
{
 
	extern uint16 _sl_version;
 
	return _sl_version < version;
 
}
 

	
 
/** Checks if some version from/to combination falls within the range of the
 
/**
 
 * Checks if some version from/to combination falls within the range of the
 
 * active savegame version */
 
static inline bool SlIsObjectCurrentlyValid(uint16 version_from, uint16 version_to)
 
{
 
	extern const uint16 SAVEGAME_VERSION;
 
	if (SAVEGAME_VERSION < version_from || SAVEGAME_VERSION > version_to) return false;
 

	
 
@@ -307,13 +311,14 @@ static inline VarType GetVarFileType(Var
 
 */
 
static inline bool IsNumericType(VarType conv)
 
{
 
	return GetVarMemType(conv) <= SLE_VAR_U64;
 
}
 

	
 
/** Get the address of the variable. Which one to pick depends on the object
 
/**
 
 * Get the address of the variable. Which one to pick depends on the object
 
 * pointer. If it is NULL we are dealing with global variables so the address
 
 * is taken. If non-null only the offset is stored in the union and we need
 
 * to add this to the address of the object */
 
static inline void *GetVariableAddress(const void *object, const SaveLoad *sld)
 
{
 
	return (byte*)(sld->global ? NULL : object) + (ptrdiff_t)sld->address;
src/screenshot.cpp
Show inline comments
 
@@ -512,13 +512,14 @@ static void CurrentScreenCallback(void *
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	void *src = blitter->MoveTo(_screen.dst_ptr, 0, y);
 
	blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch);
 
}
 

	
 
/** generate a large piece of the world
 
/**
 
 * generate a large piece of the world
 
 * @param userdata Viewport area to draw
 
 * @param buf Videobuffer with same bitdepth as current blitter
 
 * @param y First line to render
 
 * @param pitch Pitch of the videobuffer
 
 * @param n Number of lines to render
 
 */
src/settings.cpp
Show inline comments
 
@@ -4,13 +4,14 @@
 
 * 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 settings.cpp
 
/**
 
 * @file settings.cpp
 
 * All actions handling saving and loading of the settings/configuration goes on in this file.
 
 * The file consists of three parts:
 
 * <ol>
 
 * <li>Parsing the configuration file (openttd.cfg). This is achieved with the ini_ functions which
 
 *     handle various types, such as normal 'key = value' pairs, lists and value combinations of
 
 *     lists, strings, integers, 'bit'-masks and element selections.
 
@@ -91,13 +92,14 @@ static const char * const _list_group_na
 
	"newgrf",
 
	"servers",
 
	"server_bind_addresses",
 
	NULL
 
};
 

	
 
/** Find the index value of a ONEofMANY type in a string seperated by |
 
/**
 
 * Find the index value of a ONEofMANY type in a string seperated by |
 
 * @param many full domain of values the ONEofMANY setting can have
 
 * @param one the current value of the setting for which a value needs found
 
 * @param onelen force calculation of the *one parameter
 
 * @return the integer index of the full-list, or -1 if not found */
 
static int LookupOneOfMany(const char *many, const char *one, size_t onelen = 0)
 
{
 
@@ -118,13 +120,14 @@ static int LookupOneOfMany(const char *m
 
		if (*s == 0) return -1;
 
		many = s + 1;
 
		idx++;
 
	}
 
}
 

	
 
/** Find the set-integer value MANYofMANY type in a string
 
/**
 
 * Find the set-integer value MANYofMANY type in a string
 
 * @param many full domain of values the MANYofMANY setting can have
 
 * @param str the current string value of the setting, each individual
 
 * of seperated by a whitespace,tab or | character
 
 * @return the 'fully' set integer, or -1 if a set is not found */
 
static uint32 LookupManyOfMany(const char *many, const char *str)
 
{
 
@@ -147,13 +150,14 @@ static uint32 LookupManyOfMany(const cha
 
		if (*s == 0) break;
 
		str = s + 1;
 
	}
 
	return res;
 
}
 

	
 
/** Parse an integerlist string and set each found value
 
/**
 
 * Parse an integerlist string and set each found value
 
 * @param p the string to be parsed. Each element in the list is seperated by a
 
 * comma or a space character
 
 * @param items pointer to the integerlist-array that will be filled with values
 
 * @param maxitems the maximum number of elements the integerlist-array has
 
 * @return returns the number of items found, or -1 on an error */
 
int ParseIntList(const char *p, int *items, int maxitems)
 
@@ -190,13 +194,14 @@ int ParseIntList(const char *p, int *ite
 
	 * We have read comma when (n != 0) and comma is not allowed */
 
	if (n != 0 && !comma) return -1;
 

	
 
	return n;
 
}
 

	
 
/** Load parsed string-values into an integer-array (intlist)
 
/**
 
 * Load parsed string-values into an integer-array (intlist)
 
 * @param str the string that contains the values (and will be parsed)
 
 * @param array pointer to the integer-arrays that will be filled
 
 * @param nelems the number of elements the array holds. Maximum is 64 elements
 
 * @param type the type of elements the array holds (eg INT8, UINT16, etc.)
 
 * @return return true on success and false on error */
 
static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
 
@@ -229,13 +234,14 @@ static bool LoadIntList(const char *str,
 
	default: NOT_REACHED();
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Convert an integer-array (intlist) to a string representation. Each value
 
/**
 
 * Convert an integer-array (intlist) to a string representation. Each value
 
 * is seperated by a comma or a space character
 
 * @param buf output buffer where the string-representation will be stored
 
 * @param last last item to write to in the output buffer
 
 * @param array pointer to the integer-arrays that is read from
 
 * @param nelems the number of elements the array holds.
 
 * @param type the type of elements the array holds (eg INT8, UINT16, etc.) */
 
@@ -256,13 +262,14 @@ static void MakeIntList(char *buf, const
 
		default: NOT_REACHED();
 
		}
 
		buf += seprintf(buf, last, (i == 0) ? "%d" : ",%d", v);
 
	}
 
}
 

	
 
/** Convert a ONEofMANY structure to a string representation.
 
/**
 
 * Convert a ONEofMANY structure to a string representation.
 
 * @param buf output buffer where the string-representation will be stored
 
 * @param last last item to write to in the output buffer
 
 * @param many the full-domain string of possible values
 
 * @param id the value of the variable and whose string-representation must be found */
 
static void MakeOneOfMany(char *buf, const char *last, const char *many, int id)
 
{
 
@@ -281,13 +288,14 @@ static void MakeOneOfMany(char *buf, con
 

	
 
	/* copy string until next item (|) or the end of the list if this is the last one */
 
	while (*many != '\0' && *many != '|' && buf < last) *buf++ = *many++;
 
	*buf = '\0';
 
}
 

	
 
/** Convert a MANYofMANY structure to a string representation.
 
/**
 
 * Convert a MANYofMANY structure to a string representation.
 
 * @param buf output buffer where the string-representation will be stored
 
 * @param last last item to write to in the output buffer
 
 * @param many the full-domain string of possible values
 
 * @param x the value of the variable and whose string-representation must
 
 *        be found in the bitmasked many string */
 
static void MakeManyOfMany(char *buf, const char *last, const char *many, uint32 x)
 
@@ -314,13 +322,14 @@ static void MakeManyOfMany(char *buf, co
 
		if (*many == '|') many++;
 
	}
 

	
 
	*buf = '\0';
 
}
 

	
 
/** Convert a string representation (external) of a setting to the internal rep.
 
/**
 
 * Convert a string representation (external) of a setting to the internal rep.
 
 * @param desc SettingDesc struct that holds all information about the variable
 
 * @param orig_str input string that will be parsed based on the type of desc
 
 * @return return the parsed value of the setting */
 
static const void *StringToVal(const SettingDescBase *desc, const char *orig_str)
 
{
 
	const char *str = orig_str == NULL ? "" : orig_str;
 
@@ -357,13 +366,14 @@ static const void *StringToVal(const Set
 
	default: break;
 
	}
 

	
 
	return NULL;
 
}
 

	
 
/** Set the value of a setting and if needed clamp the value to
 
/**
 
 * Set the value of a setting and if needed clamp the value to
 
 * the preset minimum and maximum.
 
 * @param ptr the variable itself
 
 * @param sd pointer to the 'information'-database of the variable
 
 * @param val signed long version of the new value
 
 * @pre SettingDesc is of type SDT_BOOLX, SDT_NUMX,
 
 * SDT_ONEOFMANY or SDT_MANYOFMANY. Other types are not supported as of now */
 
@@ -409,13 +419,14 @@ static void Write_ValidateSetting(void *
 
		}
 
	}
 

	
 
	WriteValue(ptr, sd->save.conv, (int64)val);
 
}
 

	
 
/** Load values from a group of an IniFile structure into the internal representation
 
/**
 
 * Load values from a group of an IniFile structure into the internal representation
 
 * @param ini pointer to IniFile structure that holds administrative information
 
 * @param sd pointer to SettingDesc structure whose internally pointed variables will
 
 *        be given values
 
 * @param grpname the group of the IniFile to search in for the new values
 
 * @param object pointer to the object been loaded */
 
static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
 
@@ -492,13 +503,14 @@ static void IniLoadSettings(IniFile *ini
 
		}
 
		default: NOT_REACHED();
 
		}
 
	}
 
}
 

	
 
/** Save the values of settings to the inifile.
 
/**
 
 * Save the values of settings to the inifile.
 
 * @param ini pointer to IniFile structure
 
 * @param sd read-only SettingDesc structure which contains the unmodified,
 
 *        loaded values of the configuration file and various information about it
 
 * @param grpname holds the name of the group (eg. [network]) where these will be saved
 
 * @param object pointer to the object been saved
 
 * The function works as follows: for each item in the SettingDesc structure we
 
@@ -615,13 +627,14 @@ static void IniSaveSettings(IniFile *ini
 
		/* The value is different, that means we have to write it to the ini */
 
		free(item->value);
 
		item->value = strdup(buf);
 
	}
 
}
 

	
 
/** Loads all items from a 'grpname' section into a list
 
/**
 
 * Loads all items from a 'grpname' section into a list
 
 * The list parameter can be a NULL pointer, in this case nothing will be
 
 * saved and a callback function should be defined that will take over the
 
 * list-handling and store the data itself somewhere.
 
 * @param ini IniFile handle to the ini file with the source data
 
 * @param grpname character string identifying the section-header of the ini file that will be parsed
 
 * @param list new list with entries of the given section
 
@@ -636,13 +649,14 @@ static void IniLoadSettingList(IniFile *
 

	
 
	for (const IniItem *item = group->item; item != NULL; item = item->next) {
 
		if (item->name != NULL) *list->Append() = strdup(item->name);
 
	}
 
}
 

	
 
/** Saves all items from a list into the 'grpname' section
 
/**
 
 * Saves all items from a list into the 'grpname' section
 
 * The list parameter can be a NULL pointer, in this case a callback function
 
 * should be defined that will provide the source data to be saved.
 
 * @param ini IniFile handle to the ini file where the destination data is saved
 
 * @param grpname character string identifying the section-header of the ini file
 
 * @param list pointer to an string(pointer) array that will be used as the
 
 *             source to be saved into the relevant ini section
 
@@ -979,13 +993,14 @@ static bool MaxNoAIsChange(int32 i)
 
static bool CheckRoadSide(int p1)
 
{
 
	extern bool RoadVehiclesAreBuilt();
 
	return _game_mode == GM_MENU || !RoadVehiclesAreBuilt();
 
}
 

	
 
/** Conversion callback for _gameopt_settings_game.landscape
 
/**
 
 * Conversion callback for _gameopt_settings_game.landscape
 
 * It converts (or try) between old values and the new ones,
 
 * without losing initial setting of the user
 
 * @param value that was read from config file
 
 * @return the "hopefully" converted value
 
 */
 
static int32 ConvertLandscape(const char *value)
 
@@ -1154,13 +1169,14 @@ static void HandleOldDiffCustom(bool sav
 
		if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
 
		void *var = GetVariableAddress(savegame ? &_settings_game : &_settings_newgame, &sd->save);
 
		Write_ValidateSetting(var, sd, (int32)((i == 4 ? 1000 : 1) * _old_diff_custom[i]));
 
	}
 
}
 

	
 
/** tries to convert newly introduced news settings based on old ones
 
/**
 
 * tries to convert newly introduced news settings based on old ones
 
 * @param name pointer to the string defining name of the old news config
 
 * @param value pointer to the string defining value of the old news config
 
 * @returns true if conversion could have been made */
 
static bool ConvertOldNewsSetting(const char *name, const char *value)
 
{
 
	if (strcasecmp(name, "openclose") == 0) {
 
@@ -1536,13 +1552,14 @@ void DeleteGRFPresetFromConfig(const cha
 
static const SettingDesc *GetSettingDescription(uint index)
 
{
 
	if (index >= lengthof(_settings)) return NULL;
 
	return &_settings[index];
 
}
 

	
 
/** Network-safe changing of settings (server-only).
 
/**
 
 * Network-safe changing of settings (server-only).
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the index of the setting in the SettingDesc array which identifies it
 
 * @param p2 the new value for the setting
 
 * The new value is properly clamped to its minimum/maximum when setting
 
 * @param text unused
 
@@ -1590,13 +1607,14 @@ CommandCost CmdChangeSetting(TileIndex t
 
		SetWindowDirty(WC_GAME_OPTIONS, 0);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Change one of the per-company settings.
 
/**
 
 * Change one of the per-company settings.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the index of the setting in the _company_settings array which identifies it
 
 * @param p2 the new value for the setting
 
 * The new value is properly clamped to its minimum/maximum when setting
 
 * @param text unused
 
@@ -1626,13 +1644,14 @@ CommandCost CmdChangeCompanySetting(Tile
 
		SetWindowDirty(WC_GAME_OPTIONS, 0);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Top function to save the new value of an element of the Settings struct
 
/**
 
 * Top function to save the new value of an element of the Settings struct
 
 * @param index offset in the SettingDesc array of the Settings struct which
 
 * identifies the setting member we want to change
 
 * @param value new value of the setting
 
 * @param force_newgame force the newgame settings
 
 */
 
bool SetSettingValue(uint index, int32 value, bool force_newgame)
 
@@ -1665,13 +1684,14 @@ bool SetSettingValue(uint index, int32 v
 
	if (!_networking || (_networking && _network_server)) {
 
		return DoCommandP(0, index, value, CMD_CHANGE_SETTING);
 
	}
 
	return false;
 
}
 

	
 
/** Top function to save the new value of an element of the Settings struct
 
/**
 
 * Top function to save the new value of an element of the Settings struct
 
 * @param index offset in the SettingDesc array of the CompanySettings struct
 
 * which identifies the setting member we want to change
 
 * @param value new value of the setting
 
 */
 
void SetCompanySetting(uint index, int32 value)
 
{
 
@@ -1893,13 +1913,14 @@ void IConsoleListSettings(const char *pr
 
		IConsolePrintF(CC_DEFAULT, "%s = %s", sd->desc.name, value);
 
	}
 

	
 
	IConsolePrintF(CC_WARNING, "Use 'setting' command to change a value");
 
}
 

	
 
/** Save and load handler for settings
 
/**
 
 * Save and load handler for settings
 
 * @param osd SettingDesc struct containing all information
 
 * @param object can be either NULL in which case we load global variables or
 
 * a pointer to a struct which is getting saved */
 
static void LoadSettings(const SettingDesc *osd, void *object)
 
{
 
	for (; osd->save.cmd != SL_END; osd++) {
 
@@ -1908,22 +1929,24 @@ static void LoadSettings(const SettingDe
 

	
 
		if (!SlObjectMember(ptr, sld)) continue;
 
		if (IsNumericType(sld->conv)) Write_ValidateSetting(ptr, osd, ReadValue(ptr, sld->conv));
 
	}
 
}
 

	
 
/** Loadhandler for a list of global variables
 
/**
 
 * Loadhandler for a list of global variables
 
 * @param sdg pointer for the global variable list SettingDescGlobVarList
 
 * @note this is actually a stub for LoadSettings with the
 
 * object pointer set to NULL */
 
static inline void LoadSettingsGlobList(const SettingDescGlobVarList *sdg)
 
{
 
	LoadSettings((const SettingDesc*)sdg, NULL);
 
}
 

	
 
/** Save and load handler for settings
 
/**
 
 * Save and load handler for settings
 
 * @param sd SettingDesc struct containing all information
 
 * @param object can be either NULL in which case we load global variables or
 
 * a pointer to a struct which is getting saved */
 
static void SaveSettings(const SettingDesc *sd, void *object)
 
{
 
	/* We need to write the CH_RIFF header, but unfortunately can't call
 
@@ -1938,13 +1961,14 @@ static void SaveSettings(const SettingDe
 
	for (i = sd; i->save.cmd != SL_END; i++) {
 
		void *ptr = GetVariableAddress(object, &i->save);
 
		SlObjectMember(ptr, &i->save);
 
	}
 
}
 

	
 
/** Savehandler for a list of global variables
 
/**
 
 * Savehandler for a list of global variables
 
 * @note this is actually a stub for SaveSettings with the
 
 * object pointer set to NULL */
 
static inline void SaveSettingsGlobList(const SettingDescGlobVarList *sdg)
 
{
 
	SaveSettings((const SettingDesc*)sdg, NULL);
 
}
src/settings_internal.h
Show inline comments
 
@@ -13,13 +13,14 @@
 
#define SETTINGS_INTERNAL_H
 

	
 
#include "saveload/saveload.h"
 
#include "settings_type.h"
 
#include "strings_type.h"
 

	
 
/** Convention/Type of settings. This is then further specified if necessary
 
/**
 
 * Convention/Type of settings. This is then further specified if necessary
 
 * with the SLE_ (SLE_VAR/SLE_FILE) enums in saveload.h
 
 * @see VarTypes
 
 * @see SettingDescBase */
 
enum SettingDescTypeLong {
 
	/* 4 bytes allocated a maximum of 16 types for GenericType */
 
	SDT_BEGIN       = 0,
src/ship_cmd.cpp
Show inline comments
 
@@ -70,13 +70,14 @@ void DrawShipEngine(int left, int right,
 
	SpriteID sprite = GetShipIcon(engine);
 
	const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
 
	preferred_x = Clamp(preferred_x, left - real_sprite->x_offs, right - real_sprite->width - real_sprite->x_offs);
 
	DrawSprite(sprite, pal, preferred_x, y);
 
}
 

	
 
/** Get the size of the sprite of a ship sprite heading west (used for lists)
 
/**
 
 * Get the size of the sprite of a ship sprite heading west (used for lists)
 
 * @param engine The engine to get the sprite from
 
 * @param width The width of the sprite
 
 * @param height The height of the sprite
 
 */
 
void GetShipSpriteSize(EngineID engine, uint &width, uint &height)
 
{
 
@@ -370,13 +371,14 @@ static void ShipArrivesAt(const Vehicle 
 
		);
 
		AI::NewEvent(v->owner, new AIEventStationFirstVehicle(st->index, v->index));
 
	}
 
}
 

	
 

	
 
/** returns the track to choose on the next tile, or -1 when it's better to
 
/**
 
 * returns the track to choose on the next tile, or -1 when it's better to
 
 * reverse. The tile given is the tile we are about to enter, enterdir is the
 
 * direction in which we are entering the tile */
 
static Track ChooseShipTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
 
{
 
	assert(IsValidDiagDirection(enterdir));
 

	
 
@@ -596,13 +598,14 @@ bool Ship::Tick()
 

	
 
	ShipController(this);
 

	
 
	return true;
 
}
 

	
 
/** Build a ship.
 
/**
 
 * 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
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -693,13 +696,14 @@ CommandCost CmdBuildShip(TileIndex tile,
 
		Company::Get(_current_company)->num_engines[eid]++;
 
	}
 

	
 
	return value;
 
}
 

	
 
/** Sell a ship.
 
/**
 
 * Sell a ship.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
@@ -736,13 +740,14 @@ bool Ship::FindClosestDepot(TileIndex *l
 
	if (location    != NULL) *location    = depot->xy;
 
	if (destination != NULL) *destination = depot->index;
 

	
 
	return true;
 
}
 

	
 
/** Send a ship to the depot.
 
/**
 
 * Send a ship to the depot.
 
 * @param tile unused
 
 * @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)
 
@@ -761,13 +766,14 @@ CommandCost CmdSendShipToDepot(TileIndex
 
	if (v == NULL) return CMD_ERROR;
 

	
 
	return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK));
 
}
 

	
 

	
 
/** Refits a ship to the specified cargo type.
 
/**
 
 * Refits a ship to the specified cargo type.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID of the ship to refit
 
 * @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
src/signs_cmd.cpp
Show inline comments
 
@@ -59,13 +59,14 @@ CommandCost CmdPlaceSign(TileIndex tile,
 
		_new_sign_id = si->index;
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Rename a sign. If the new name of the sign is empty, we assume
 
/**
 
 * Rename a sign. If the new name of the sign is empty, we assume
 
 * the user wanted to delete it. So delete it. Ownership of signs
 
 * has no meaning/effect whatsoever except for eyecandy
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 index of the sign to be renamed/removed
 
 * @param p2 unused
src/smallmap_gui.cpp
Show inline comments
 
@@ -60,13 +60,14 @@ static int _smallmap_industry_count; ///
 
/** Macro for a height legend entry with configurable colour. */
 
#define MC(height)  {0, STR_TINY_BLACK_HEIGHT, {height}, true, false, false}
 

	
 
/** Macro for end of list marker in arrays of LegendAndColour */
 
#define MKEND() {0, STR_NULL, {INVALID_INDUSTRYTYPE}, true, true, false}
 

	
 
/** Macro for break marker in arrays of LegendAndColour.
 
/**
 
 * Macro for break marker in arrays of LegendAndColour.
 
 * It will have valid data, though */
 
#define MS(a, b) {a, b, {INVALID_INDUSTRYTYPE}, true, false, true}
 

	
 
/** Structure for holding relevant data for legends in small map */
 
struct LegendAndColour {
 
	uint8 colour;              ///< Colour of the item on the map.
 
@@ -146,13 +147,14 @@ static const LegendAndColour _legend_lan
 
};
 
#undef MK
 
#undef MC
 
#undef MS
 
#undef MKEND
 

	
 
/** Allow room for all industries, plus a terminator entry
 
/**
 
 * Allow room for all industries, plus a terminator entry
 
 * This is required in order to have the indutry slots all filled up */
 
static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES + 1];
 
/* For connecting industry type to position in industries list(small map legend) */
 
static uint _industry_to_list_pos[NUM_INDUSTRYTYPES];
 
/** Show heightmap in industry mode of smallmap window. */
 
static bool _smallmap_industry_show_heightmap;
 
@@ -628,13 +630,14 @@ class SmallMapWindow : public Window {
 
			scroll.x = (tx + 2 * this->zoom) * TILE_SIZE;
 
			scroll.y = (ty - 2 * this->zoom) * TILE_SIZE;
 
		}
 
		return scroll;
 
	}
 

	
 
	/** Initialize or change the zoom level.
 
	/**
 
	 * Initialize or change the zoom level.
 
	 * @param change  Way to change the zoom level.
 
	 * @param zoom_pt Position to keep fixed while zooming.
 
	 * @pre \c *zoom_pt should contain a point in the smallmap display when zooming in or out.
 
	 */
 
	void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt)
 
	{
 
@@ -980,38 +983,42 @@ public:
 
		this->GetWidget<NWidgetStacked>(SM_WIDGET_SELECTINDUSTRIES)->SetDisplayedPlane(this->map_type != SMT_INDUSTRY);
 

	
 
		this->SetZoomLevel(ZLC_INITIALIZE, NULL);
 
		this->SmallMapCenterOnCurrentPos();
 
	}
 

	
 
	/** Compute maximal required height of the legends.
 
	/**
 
	 * Compute maximal required height of the legends.
 
	 * @return Maximally needed height for displaying the smallmap legends in pixels.
 
	 */
 
	inline uint GetMaxLegendHeight() const
 
	{
 
		uint num_rows = max(this->min_number_of_fixed_rows, CeilDiv(_smallmap_industry_count, this->min_number_of_columns));
 
		return WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + num_rows * FONT_HEIGHT_SMALL;
 
	}
 

	
 
	/** Compute minimal required width of the legends.
 
	/**
 
	 * Compute minimal required width of the legends.
 
	 * @return Minimally needed width for displaying the smallmap legends in pixels.
 
	 */
 
	inline uint GetMinLegendWidth() const
 
	{
 
		return WD_FRAMERECT_LEFT + this->min_number_of_columns * this->column_width;
 
	}
 

	
 
	/** Return number of columns that can be displayed in \a width pixels.
 
	/**
 
	 * Return number of columns that can be displayed in \a width pixels.
 
	 * @return Number of columns to display.
 
	 */
 
	inline uint GetNumberColumnsLegend(uint width) const
 
	{
 
		return width / this->column_width;
 
	}
 

	
 
	/** Compute height given a width.
 
	/**
 
	 * Compute height given a width.
 
	 * @return Needed height for displaying the smallmap legends in pixels.
 
	 */
 
	uint GetLegendHeight(uint width) const
 
	{
 
		uint num_columns = this->GetNumberColumnsLegend(width);
 
		uint num_rows = max(this->min_number_of_fixed_rows, CeilDiv(_smallmap_industry_count, num_columns));
src/sound/allegro_s.cpp
Show inline comments
 
@@ -41,13 +41,14 @@ void SoundDriver_Allegro::MainLoop()
 
	for (int i = 0; i < _buffer_size * 2; i++) snd[i] ^= 0x8000;
 

	
 
	/* Tell we've filled the stream */
 
	free_audio_stream_buffer(_stream);
 
}
 

	
 
/** There are multiple modules that might be using Allegro and
 
/**
 
 * There are multiple modules that might be using Allegro and
 
 * Allegro can only be initiated once. */
 
extern int _allegro_instance_count;
 

	
 
const char *SoundDriver_Allegro::Start(const char * const *parm)
 
{
 
	if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) {
src/spritecache.cpp
Show inline comments
 
@@ -402,13 +402,14 @@ void IncreaseSpriteLRU()
 
	if (++_compact_cache_counter >= 740) {
 
		CompactSpriteCache();
 
		_compact_cache_counter = 0;
 
	}
 
}
 

	
 
/** Called when holes in the sprite cache should be removed.
 
/**
 
 * Called when holes in the sprite cache should be removed.
 
 * That is accomplished by moving the cached data. */
 
static void CompactSpriteCache()
 
{
 
	MemBlock *s;
 

	
 
	DEBUG(sprite, 3, "Compacting sprite cache, inuse=" PRINTF_SIZE, GetSpriteCacheUsage());
 
@@ -519,13 +520,14 @@ static void *AllocSprite(size_t mem_req)
 

	
 
		/* Reached sentinel, but no block found yet. Delete some old entry. */
 
		DeleteEntryFromSpriteCache();
 
	}
 
}
 

	
 
/** Handles the case when a sprite of different type is requested than is present in the SpriteCache.
 
/**
 
 * Handles the case when a sprite of different type is requested than is present in the SpriteCache.
 
 * For ST_FONT sprites, it is normal. In other cases, default sprite is loaded instead.
 
 * @param sprite ID of loaded sprite
 
 * @param requested requested sprite type
 
 * @param sc the currently known sprite cache for the requested sprite
 
 * @return fallback sprite
 
 * @note this function will do usererror() in the case the fallback sprite isn't available */

Changeset was too big and was cut off... Show full diff anyway

0 comments (0 inline, 0 general)