Changeset - r6201:2e76eb9a1d7a
[Not reviewed]
master
0 30 0
belugas - 18 years ago 2007-03-03 04:04:22
belugas@openttd.org
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
30 files changed with 367 insertions and 286 deletions:
0 comments (0 inline, 0 general)
src/fileio.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file fileio.cpp Standard In/Out file operations*/
 
/** @file fileio.cpp Standard In/Out file operations */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "fileio.h"
 
#include "functions.h"
 
#include "string.h"
src/fileio.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file fileio.h Declarations for Standard In/Out file operations*/
 
/** @file fileio.h Declarations for Standard In/Out file operations */
 

	
 
#ifndef FILEIO_H
 
#define FILEIO_H
 

	
 
void FioSeekTo(uint32 pos, int mode);
 
void FioSeekToFile(uint32 pos);
src/industry.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file industry.h */
 

	
 
#ifndef INDUSTRY_H
 
#define INDUSTRY_H
 

	
 
#include "oldpool.h"
 

	
 
typedef byte IndustryGfx;
 
@@ -15,96 +17,102 @@ enum {
 
typedef enum IndustryLifeTypes {
 
	INDUSTRYLIFE_NOT_CLOSABLE,     ///< Industry can never close
 
	INDUSTRYLIFE_PRODUCTION,       ///< Industry can close and change of production
 
	INDUSTRYLIFE_CLOSABLE,         ///< Industry can only close (no production change)
 
} IndustryLifeType;
 

	
 
/**
 
 * Defines the internal data of a functionnal industry
 
 */
 
struct Industry {
 
	TileIndex xy;
 
	byte width; /* swapped order of w/h with town */
 
	TileIndex xy;                   ///< coordinates of the primary tile the industry is built one
 
	byte width;
 
	byte height;
 
	const Town* town;
 
	CargoID produced_cargo[2];
 
	uint16 cargo_waiting[2];
 
	byte production_rate[2];
 
	CargoID accepts_cargo[3];
 
	byte prod_level;
 
	uint16 last_mo_production[2];
 
	uint16 last_mo_transported[2];
 
	byte pct_transported[2];
 
	uint16 total_production[2];
 
	uint16 total_transported[2];
 
	uint16 counter;
 
	const Town* town;               ///< Nearest town
 
	CargoID produced_cargo[2];      ///< 2 production cargo slots
 
	uint16 cargo_waiting[2];        ///< amount of cargo produced per cargo
 
	byte production_rate[2];        ///< production rate for each cargo
 
	CargoID accepts_cargo[3];       ///< 3 input cargo slots
 
	byte prod_level;                ///< general production level
 
	uint16 last_mo_production[2];   ///< stats of last month production per cargo
 
	uint16 last_mo_transported[2];  ///< stats of last month transport per cargo
 
	byte pct_transported[2];        ///< percentage transported per cargo
 
	uint16 total_production[2];     ///< total units produced per cargo
 
	uint16 total_transported[2];    ///< total units transported per cargo
 
	uint16 counter;                 ///< used for animation and/or production (if available cargo)
 

	
 
	byte type;
 
	OwnerByte owner;
 
	byte random_color;
 
	Year last_prod_year;
 
	byte was_cargo_delivered;
 
	byte type;                      ///< type of industry. see IT_COAL_MINE and others
 
	OwnerByte owner;                ///< owner of the industry.  Which SHOULD always be (imho) OWNER_NONE
 
	byte random_color;              ///< randomized colour of the industry, for display purpose
 
	Year last_prod_year;            ///< last year of production
 
	byte was_cargo_delivered;       ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
 

	
 
	IndustryID index;
 
	IndustryID index;               ///< index of the industry in the pool of industries
 
};
 

	
 
typedef struct IndustryTileTable {
 
	TileIndexDiffC ti;
 
	IndustryGfx gfx;
 
} IndustryTileTable;
 

	
 
/**
 
 * Defines the data structure for constructing industry.
 
 */
 
typedef struct IndustrySpec {
 
	/** Tables with the 'layout' of different composition of GFXes */
 
	const IndustryTileTable *const *table;
 
	/** Number of elements in the table */
 
	byte num_table;
 
	/** Base cost multiplier*/
 
	byte cost_multiplier;
 
	/** Industries this industry cannot be close to */
 
	IndustryType conflicting[3];
 
	/** index to a procedure to check for conflicting circumstances */
 
	byte check_proc;
 

	
 
	const IndustryTileTable *const *table;///< List of the tiles composing the industry
 
	byte num_table;                       ///< Number of elements in the table
 
	byte cost_multiplier;                 ///< Base cost multiplier*/
 
	IndustryType conflicting[3];          ///< Industries this industry cannot be close to
 
	byte check_proc;                      ///< Index to a procedure to check for conflicting circumstances
 
	CargoID produced_cargo[2];
 
	byte production_rate[2];
 
	/** The minimum amount of cargo transported to the stations; if the
 
	 * waiting cargo is less than this number, no cargo is moved to it*/
 
	byte minimal_cargo;
 
	CargoID accepts_cargo[3];
 

	
 
	IndustryLifeType life_type;  ///< This is also known as Industry production flag, in newgrf specs
 

	
 
	byte climate_availability;  ///< Bitmask, giving landscape enums as bit position
 

	
 
	StringID name;
 
	StringID closure_text;
 
	StringID production_up_text;
 
	StringID production_down_text;
 
	byte minimal_cargo;                   ///< minimum amount of cargo transported to the stations
 
	                                      ///< If the waiting cargo is less than this number, no cargo is moved to it
 
	CargoID accepts_cargo[3];             ///< 3 accepted cargos
 
	IndustryLifeType life_type;           ///< This is also known as Industry production flag, in newgrf specs
 
	byte climate_availability;            ///< Bitmask, giving landscape enums as bit position
 
	StringID name;                        ///< Displayed name of the industry
 
	StringID closure_text;                ///< Message appearing when the industry closes
 
	StringID production_up_text;          ///< Message appearing when the industry's production is increasing
 
	StringID production_down_text;        ///< Message appearing when the industry's production is decreasing
 
} IndustrySpec;
 

	
 
/**
 
 * Defines the data structure of each indivudual tile of an industry.
 
 */
 
typedef struct IndustryTileSpec {
 
	CargoID accepts_cargo[3];
 
	Slope slopes_refused;
 
	CargoID accepts_cargo[3];             ///< Cargo accepted by this tile
 
	Slope slopes_refused;                 ///< slope pattern on which this tile cannot be built
 
} IndustryTileSpec;
 

	
 
const IndustrySpec *GetIndustrySpec(IndustryType thistype);
 
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx);
 
const IndustrySpec *GetIndustrySpec(IndustryType thistype);    ///< Array of industries default data
 
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx);  ///< Array of industry tiles default data
 

	
 
DECLARE_OLD_POOL(Industry, Industry, 3, 8000)
 

	
 
/**
 
 * Check if an Industry really exists.
 
 * @param industry to check
 
 * @return true if position is a valid one
 
 */
 
static inline bool IsValidIndustry(const Industry *industry)
 
{
 
	return industry->xy != 0;
 
}
 

	
 
/**
 
 * Check if an Industry exists whithin the pool of industries
 
 * @param index of the desired industry
 
 * @return true if it is inside the pool
 
 */
 
static inline bool IsValidIndustryID(IndustryID index)
 
{
 
	return index < GetIndustryPoolSize() && IsValidIndustry(GetIndustry(index));
 
}
 

	
 
VARDEF int _total_industries;
 
VARDEF int _total_industries; //general counter
 

	
 
static inline IndustryID GetMaxIndustryIndex(void)
 
{
 
	/* TODO - This isn't the real content of the function, but
 
	 *  with the new pool-system this will be replaced with one that
 
	 *  _really_ returns the highest index. Now it just returns
src/industry_cmd.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file industry_cmd.cpp */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "clear_map.h"
 
#include "functions.h"
 
#include "industry_map.h"
 
#include "station_map.h"
 
@@ -77,19 +79,28 @@ IndustryType GetIndustryType(TileIndex t
 
/**
 
 * Accessor for array _industry_specs.
 
 * This will ensure at once : proper access and
 
 * not allowing modifications of it.
 
 * @param thistype of industry (which is the index in _industry_specs)
 
 * @pre thistype < IT_END
 
 * @return a pointer to the corresponding industry spec
 
 **/
 
const IndustrySpec *GetIndustrySpec(IndustryType thistype)
 
{
 
	assert(thistype < IT_END);
 
	return &_industry_specs[thistype];
 
}
 

	
 
/**
 
 * Accessor for array _industry_tile_specs.
 
 * This will ensure at once : proper access and
 
 * not allowing modifications of it.
 
 * @param gfx of industrytile (which is the index in _industry_specs)
 
 * @pre gfx < NUM_INDUSTRY_GFXES
 
 * @return a pointer to the corresponding industrytile spec
 
 **/
 
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx)
 
{
 
	assert(gfx < NUM_INDUSTRY_GFXES);
 
	return &_industry_tile_specs[gfx];
 
}
 

	
 
@@ -424,13 +435,13 @@ static void AnimateTile_Industry(TileInd
 
			SetIndustryAnimationState(tile, m);
 

	
 
			MarkTileDirtyByTile(tile);
 
		}
 
		break;
 

	
 
	// Sparks on a coal plant
 
	/* Sparks on a coal plant */
 
	case GFX_POWERPLANT_SPARKS:
 
		if ((_tick_counter & 3) == 0) {
 
			m = GetIndustryAnimationState(tile);
 
			if (m == 6) {
 
				SetIndustryAnimationState(tile, 0);
 
				DeleteAnimatedTile(tile);
 
@@ -866,13 +877,13 @@ static void MaybePlantFarmField(const In
 
}
 

	
 
/**
 
 * Search callback function for ChopLumberMillTrees
 
 * @param tile to test
 
 * @param data that is passed by the caller.  In this case, nothing
 
 * @result of the test
 
 * @return the result of the test
 
 */
 
static bool SearchLumberMillTrees(TileIndex tile, uint32 data)
 
{
 
	if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees
 
		PlayerID old_player = _current_player;
 
		/* found a tree */
 
@@ -1314,30 +1325,30 @@ static bool CheckIfCanLevelIndustryPlatf
 

	
 
static bool CheckIfTooCloseToIndustry(TileIndex tile, int type)
 
{
 
	const IndustrySpec *indspec = GetIndustrySpec(type);
 
	const Industry *i;
 

	
 
	// accepting industries won't be close, not even with patch
 
	/* accepting industries won't be close, not even with patch */
 
	if (_patches.same_industry_close && indspec->accepts_cargo[0] == CT_INVALID)
 
		return true;
 

	
 
	FOR_ALL_INDUSTRIES(i) {
 
		// check if an industry that accepts the same goods is nearby
 
		/* check if an industry that accepts the same goods is nearby */
 
		if (DistanceMax(tile, i->xy) <= 14 &&
 
				indspec->accepts_cargo[0] != CT_INVALID &&
 
				indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
 
					_game_mode != GM_EDITOR ||
 
					!_patches.same_industry_close ||
 
					!_patches.multiple_industry_per_town
 
				)) {
 
			_error_message = STR_INDUSTRY_TOO_CLOSE;
 
			return false;
 
		}
 

	
 
		// check "not close to" field.
 
		/* check "not close to" field. */
 
		if ((i->type == indspec->conflicting[0] || i->type == indspec->conflicting[1] || i->type == indspec->conflicting[2]) &&
 
				DistanceMax(tile, i->xy) <= 14) {
 
			_error_message = STR_INDUSTRY_TOO_CLOSE;
 
			return false;
 
		}
 
	}
 
@@ -1442,12 +1453,20 @@ static void DoCreateNewIndustry(Industry
 
		for (j = 0; j != 50; j++) PlantRandomFarmField(i);
 
	}
 
	_industry_sort_dirty = true;
 
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
 
}
 

	
 
/** 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 it pointer to list of tile type to build
 
 * @return the pointer of the newly created industry, or NULL if it failed
 
 */
 
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, uint32 flags, const IndustrySpec *indspec, const IndustryTileTable *it)
 
{
 
	const Town *t;
 
	Industry *i;
 

	
 
	if (!CheckIfIndustryTilesAreFree(tile, it, type)) return NULL;
 
@@ -1471,14 +1490,16 @@ static Industry *CreateNewIndustryHelper
 

	
 
	return i;
 
}
 

	
 
/** Build/Fund an industry
 
 * @param tile tile where industry is built
 
 * @param p1 industry type @see build_industry.h and @see industry.h
 
 * @param flags of operations to conduct
 
 * @param p1 industry type see build_industry.h and see industry.h
 
 * @param p2 unused
 
 * @return index of the newly create industry, or CMD_ERROR if it failed
 
 */
 
int32 CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int num;
 
	const IndustryTileTable * const *itt;
 
	const IndustryTileTable *it;
 
@@ -1521,25 +1542,25 @@ Industry *CreateNewIndustry(TileIndex ti
 
	const IndustryTileTable *it = indspec->table[RandomRange(indspec->num_table)];
 

	
 
	return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, it);
 
}
 

	
 
static const byte _numof_industry_table[4][12] = {
 
	// difficulty settings for number of industries
 
	/* difficulty settings for number of industries */
 
	{0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0},   //none
 
	{0, 1, 1, 1, 2, 2, 3, 3,  4,  4,  5},   //low
 
	{0, 1, 2, 3, 4, 5, 6, 7,  8,  9, 10},   //normal
 
	{0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10},   //high
 
};
 

	
 
static void PlaceInitialIndustry(IndustryType type, int amount)
 
{
 
	int num = _numof_industry_table[_opt.diff.number_industries][amount];
 

	
 
	if (type == IT_OIL_REFINERY || type == IT_OIL_RIG) {
 
		// These are always placed next to the coastline, so we scale by the perimeter instead.
 
		/* These are always placed next to the coastline, so we scale by the perimeter instead. */
 
		num = ScaleByMapSize1D(num);
 
	} else {
 
		num = ScaleByMapSize(num);
 
	}
 

	
 
	if (_opt.diff.number_industries != 0) {
 
@@ -1820,13 +1841,13 @@ void IndustryMonthlyLoop(void)
 
		i = GetRandomIndustry();
 
		if (i != NULL) ChangeIndustryProduction(i);
 
	}
 

	
 
	_current_player = old_player;
 

	
 
	// production-change
 
	/* production-change */
 
	_industry_sort_dirty = true;
 
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
 
}
 

	
 

	
 
void InitializeIndustries(void)
 
@@ -1878,23 +1899,23 @@ static const SaveLoad _industry_desc[] =
 
	    SLE_VAR(Industry, owner,               SLE_UINT8),
 
	    SLE_VAR(Industry, random_color,        SLE_UINT8),
 
	SLE_CONDVAR(Industry, last_prod_year,      SLE_FILE_U8 | SLE_VAR_I32,  0, 30),
 
	SLE_CONDVAR(Industry, last_prod_year,      SLE_INT32,                 31, SL_MAX_VERSION),
 
	    SLE_VAR(Industry, was_cargo_delivered, SLE_UINT8),
 

	
 
	// reserve extra space in savegame here. (currently 32 bytes)
 
	/* reserve extra space in savegame here. (currently 32 bytes) */
 
	SLE_CONDNULL(32, 2, SL_MAX_VERSION),
 

	
 
	SLE_END()
 
};
 

	
 
static void Save_INDY(void)
 
{
 
	Industry *ind;
 

	
 
	// Write the vehicles
 
	/* Write the vehicles */
 
	FOR_ALL_INDUSTRIES(ind) {
 
		SlSetArrayIndex(ind->index);
 
		SlObject(ind, _industry_desc);
 
	}
 
}
 

	
src/industry_gui.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file industry_gui.cpp */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "debug.h"
 
#include "functions.h"
 
#include "strings.h"
 
#include "table/strings.h"
 
@@ -16,12 +18,13 @@
 
#include "industry.h"
 
#include "town.h"
 
#include "variables.h"
 
#include "helpers.hpp"
 
#include "cargotype.h"
 

	
 
/* industries per climate, according to the different construction windows */
 
const byte _build_industry_types[4][12] = {
 
	{  1,  2,  4,  6,  8,  0,  3,  5,  9, 11, 18 },
 
	{  1, 14,  4, 13,  7,  0,  3,  9, 11, 15 },
 
	{ 25, 13,  4, 23, 22, 11, 17, 10, 24, 19, 20, 21 },
 
	{ 27, 30, 31, 33, 26, 28, 29, 32, 34, 35, 36 },
 
};
 
@@ -287,15 +290,15 @@ static inline bool IsProductionAlterable
 
	return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
 
		     (i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES));
 
}
 

	
 
static void IndustryViewWndProc(Window *w, WindowEvent *e)
 
{
 
	// WP(w,vp2_d).data_1 is for the editbox line
 
	// WP(w,vp2_d).data_2 is for the clickline
 
	// WP(w,vp2_d).data_3 is for the click pos (left or right)
 
	/* WP(w,vp2_d).data_1 is for the editbox line
 
	 * WP(w,vp2_d).data_2 is for the clickline
 
	 * WP(w,vp2_d).data_3 is for the click pos (left or right) */
 

	
 
	switch (e->event) {
 
	case WE_PAINT: {
 
		const Industry *i = GetIndustry(w->window_number);
 

	
 
		SetDParam(0, w->window_number);
 
@@ -322,24 +325,24 @@ static void IndustryViewWndProc(Window *
 

	
 
			SetDParam(0, i->produced_cargo[0]);
 
			SetDParam(1, i->total_production[0]);
 

	
 
			SetDParam(2, i->pct_transported[0] * 100 >> 8);
 
			DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 127, STR_482B_TRANSPORTED, 0);
 
			// Let's put out those buttons..
 
			/* Let's put out those buttons.. */
 
			if (IsProductionAlterable(i)) {
 
				DrawArrowButtons(5, 127, 3, (WP(w,vp2_d).data_2 == 1) ? WP(w,vp2_d).data_3 : 0,
 
						!isProductionMinimum(i, 0), !isProductionMaximum(i, 0));
 
			}
 

	
 
			if (i->produced_cargo[1] != CT_INVALID) {
 
				SetDParam(0, i->produced_cargo[1]);
 
				SetDParam(1, i->total_production[1]);
 
				SetDParam(2, i->pct_transported[1] * 100 >> 8);
 
				DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 137, STR_482B_TRANSPORTED, 0);
 
				// Let's put out those buttons..
 
				/* Let's put out those buttons.. */
 
				if (IsProductionAlterable(i)) {
 
					DrawArrowButtons(5, 137, 3, (WP(w,vp2_d).data_2 == 2) ? WP(w,vp2_d).data_3 : 0,
 
						!isProductionMinimum(i, 1), !isProductionMaximum(i, 1));
 
				}
 
			}
 
		}
 
@@ -354,13 +357,13 @@ static void IndustryViewWndProc(Window *
 
		switch (e->we.click.widget) {
 
		case 5: {
 
			int line, x;
 

	
 
			i = GetIndustry(w->window_number);
 

	
 
			// We should work if needed..
 
			/* We should work if needed.. */
 
			if (!IsProductionAlterable(i)) return;
 

	
 
			x = e->we.click.pt.x;
 
			line = (e->we.click.pt.y - 127) / 10;
 
			if (e->we.click.pt.y >= 127 && IS_INT_INSIDE(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) {
 
				if (IS_INT_INSIDE(x, 5, 25) ) {
 
@@ -376,13 +379,13 @@ static void IndustryViewWndProc(Window *
 
					UpdateIndustryProduction(i);
 
					SetWindowDirty(w);
 
					w->flags4 |= 5 << WF_TIMEOUT_SHL;
 
					WP(w,vp2_d).data_2 = line+1;
 
					WP(w,vp2_d).data_3 = (x < 15 ? 1 : 2);
 
				} else if (IS_INT_INSIDE(x, 34, 160)) {
 
					// clicked the text
 
					/* clicked the text */
 
					WP(w,vp2_d).data_1 = line;
 
					SetDParam(0, i->production_rate[line] * 8);
 
					ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_GAME_PRODUCTION, 10, 100, w, CS_ALPHANUMERAL);
 
				}
 
			}
 
		} break;
 
@@ -530,13 +533,13 @@ static int CDECL GeneralIndustrySorter(c
 
					r = pi - pj;
 
				}
 
			}
 
			break;
 
	}
 

	
 
	// default to string sorting if they are otherwise equal
 
	/* default to string sorting if they are otherwise equal */
 
	if (r == 0) {
 
		char buf1[96];
 

	
 
		SetDParam(0, i->town->index);
 
		GetString(buf1, STR_TOWN, lastof(buf1));
 

	
src/industry_map.h
Show inline comments
 
@@ -169,48 +169,48 @@ static inline void ResetIndustryConstruc
 
typedef struct IndustryTypeSolver {
 
	IndustryGfx MinGfx;
 
	IndustryGfx MaxGfx;
 
} IndustryTypeSolver;
 

	
 
static const IndustryTypeSolver industry_gfx_Solver [IT_END] = {
 
	{  0,   6}, //IT_COAL_MINE
 
	{  7,  10}, //IT_POWER_STATION,
 
	{ 11,  15}, //IT_SAWMILL,
 
	{ 16,  17}, //IT_FOREST,
 
	{ 18,  23}, //IT_OIL_REFINERY,
 
	{ 24,  28}, //IT_OIL_RIG,
 
	{ 29,  31}, //IT_OIL_WELL,
 
	{ 32,  38}, //IT_FARM,
 
	{ 39,  42}, //IT_FACTORY,
 
	{ 43,  46}, //IT_PRINTING_WORKS,
 
	{ 47,  51}, //IT_COPPER_MINE,
 
	{ 52,  57}, //IT_STEEL_MILL,
 
	{ 58,  59}, //IT_BANK_TEMP,
 
	{ 60,  63}, //IT_FOOD_PROCESS,
 
	{ 64,  71}, //IT_PAPER_MILL,
 
	{ 72,  88}, //IT_GOLD_MINE,
 
	{ 89,  90}, //IT_BANK_TROPIC_ARCTIC,
 
	{ 91,  99}, //IT_DIAMOND_MINE,
 
	{100, 115}, //IT_IRON_MINE,
 
	{116, 116}, //IT_FRUIT_PLANTATION,
 
	{117, 117}, //IT_RUBBER_PLANTATION,
 
	{118, 119}, //IT_WATER_SUPPLY,
 
	{120, 120}, //IT_WATER_TOWER,
 
	{121, 124}, //IT_FACTORY_2,
 
	{125, 128}, //IT_LUMBER_MILL,
 
	{129, 130}, //IT_COTTON_CANDY,
 
	{131, 134}, //IT_CANDY_FACTORY or sweet factory
 
	{135, 136}, //IT_BATTERY_FARM,
 
	{137, 137}, //IT_COLA_WELLS,
 
	{138, 141}, //IT_TOY_SHOP,
 
	{142, 147}, //IT_TOY_FACTORY,
 
	{148, 155}, //IT_PLASTIC_FOUNTAINS,
 
	{156, 159}, //IT_FIZZY_DRINK_FACTORY,
 
	{160, 163}, //IT_BUBBLE_GENERATOR,
 
	{164, 166}, //IT_TOFFEE_QUARRY,
 
	{167, 174}  //IT_SUGAR_MINE,
 
	{  0,   6}, ///< IT_COAL_MINE
 
	{  7,  10}, ///< IT_POWER_STATION,
 
	{ 11,  15}, ///< IT_SAWMILL,
 
	{ 16,  17}, ///< IT_FOREST,
 
	{ 18,  23}, ///< IT_OIL_REFINERY,
 
	{ 24,  28}, ///< IT_OIL_RIG,
 
	{ 29,  31}, ///< IT_OIL_WELL,
 
	{ 32,  38}, ///< IT_FARM,
 
	{ 39,  42}, ///< IT_FACTORY,
 
	{ 43,  46}, ///< IT_PRINTING_WORKS,
 
	{ 47,  51}, ///< IT_COPPER_MINE,
 
	{ 52,  57}, ///< IT_STEEL_MILL,
 
	{ 58,  59}, ///< IT_BANK_TEMP,
 
	{ 60,  63}, ///< IT_FOOD_PROCESS,
 
	{ 64,  71}, ///< IT_PAPER_MILL,
 
	{ 72,  88}, ///< IT_GOLD_MINE,
 
	{ 89,  90}, ///< IT_BANK_TROPIC_ARCTIC,
 
	{ 91,  99}, ///< IT_DIAMOND_MINE,
 
	{100, 115}, ///< IT_IRON_MINE,
 
	{116, 116}, ///< IT_FRUIT_PLANTATION,
 
	{117, 117}, ///< IT_RUBBER_PLANTATION,
 
	{118, 119}, ///< IT_WATER_SUPPLY,
 
	{120, 120}, ///< IT_WATER_TOWER,
 
	{121, 124}, ///< IT_FACTORY_2,
 
	{125, 128}, ///< IT_LUMBER_MILL,
 
	{129, 130}, ///< IT_COTTON_CANDY,
 
	{131, 134}, ///< IT_CANDY_FACTORY or sweet factory
 
	{135, 136}, ///< IT_BATTERY_FARM,
 
	{137, 137}, ///< IT_COLA_WELLS,
 
	{138, 141}, ///< IT_TOY_SHOP,
 
	{142, 147}, ///< IT_TOY_FACTORY,
 
	{148, 155}, ///< IT_PLASTIC_FOUNTAINS,
 
	{156, 159}, ///< IT_FIZZY_DRINK_FACTORY,
 
	{160, 163}, ///< IT_BUBBLE_GENERATOR,
 
	{164, 166}, ///< IT_TOFFEE_QUARRY,
 
	{167, 174}  ///< IT_SUGAR_MINE,
 
};
 

	
 
/**
 
 * Get the animation loop number
 
 * @param tile the tile to get the animation loop number of
 
 * @pre IsTileType(tile, MP_INDUSTRY)
src/intro_gui.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file intro_gui.cpp */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "table/strings.h"
 
#include "table/sprites.h"
 
#include "functions.h"
 
#include "window.h"
src/landscape.cpp
Show inline comments
 
@@ -169,13 +169,13 @@ uint GetSlopeZ(int x, int y)
 

	
 
static Slope GetFoundationSlope(TileIndex tile, uint* z)
 
{
 
	Slope tileh = GetTileSlope(tile, z);
 
	Slope slope = _tile_type_procs[GetTileType(tile)]->get_slope_tileh_proc(tile, tileh);
 

	
 
	// Flatter slope -> higher base height
 
	/* Flatter slope -> higher base height */
 
	if (slope < tileh) *z += TILE_HEIGHT;
 
	return slope;
 
}
 

	
 

	
 
static bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
 
@@ -220,47 +220,47 @@ void DrawFoundation(TileInfo *ti, uint f
 
	if (!HasFoundationNW(ti->tile, slope, z)) sprite_base += 22;
 
	if (!HasFoundationNE(ti->tile, slope, z)) sprite_base += 44;
 

	
 
	if (IsSteepSlope(ti->tileh)) {
 
		SpriteID lower_base;
 

	
 
		// Lower part of foundation
 
		/* Lower part of foundation */
 
		lower_base = sprite_base;
 
		if (lower_base == SPR_SLOPES_BASE - 15) lower_base = SPR_FOUNDATION_BASE;
 
		AddSortableSpriteToDraw(
 
			lower_base + (ti->tileh & ~SLOPE_STEEP), PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z
 
		);
 
		ti->z += TILE_HEIGHT;
 
		ti->tileh = _inclined_tileh[f - 15];
 
		if (f < 15 + 8) {
 
			// inclined
 
			/* inclined */
 
			AddSortableSpriteToDraw(sprite_base + f, PAL_NONE, ti->x, ti->y, 16, 16, 1, ti->z);
 
			OffsetGroundSprite(31, 9);
 
		} else if (f >= 15 + 8 + 4) {
 
			// three corners raised
 
			/* three corners raised */
 
			SpriteID upper = sprite_base + 15 + (f - 15 - 8 - 4) * 2;
 

	
 
			AddSortableSpriteToDraw(upper, PAL_NONE, ti->x, ti->y, 16, 16, 1, ti->z);
 
			AddChildSpriteScreen(upper + 1, PAL_NONE, 31, 9);
 
			OffsetGroundSprite(31, 9);
 
		} else {
 
			// one corner raised
 
			/* one corner raised */
 
			OffsetGroundSprite(31, 1);
 
		}
 
	} else {
 
		if (f < 15) {
 
			// leveled foundation
 
			// Use the original slope sprites if NW and NE borders should be visible
 
			/* leveled foundation
 
			 * Use the original slope sprites if NW and NE borders should be visible */
 
			if (sprite_base  == SPR_SLOPES_BASE - 15) sprite_base = SPR_FOUNDATION_BASE;
 

	
 
			AddSortableSpriteToDraw(sprite_base + f, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
 
			ti->z += TILE_HEIGHT;
 
			ti->tileh = SLOPE_FLAT;
 
			OffsetGroundSprite(31, 1);
 
		} else {
 
			// inclined foundation
 
			/* inclined foundation */
 
			AddSortableSpriteToDraw(sprite_base + f, PAL_NONE, ti->x, ti->y, 16, 16, 1, ti->z);
 
			ti->tileh = _inclined_tileh[f - 15];
 
			OffsetGroundSprite(31, 9);
 
		}
 
	}
 
}
 
@@ -301,12 +301,13 @@ void GetTileDesc(TileIndex tile, TileDes
 
{
 
	_tile_type_procs[GetTileType(tile)]->get_tile_desc_proc(tile, td);
 
}
 

	
 
/** Clear a piece of landscape
 
 * @param tile tile to clear
 
 * @param flags of operation to conduct
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
int32 CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
@@ -314,12 +315,13 @@ int32 CmdLandscapeClear(TileIndex tile, 
 
	return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
 
}
 

	
 
/** Clear a big piece of landscape
 
 * @param tile end tile of area dragging
 
 * @param p1 start tile of area dragging
 
 * @param flags of operation to conduct
 
 * @param p2 unused
 
 */
 
int32 CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 cost, ret, money;
 
	int ex;
 
@@ -329,13 +331,13 @@ int32 CmdClearArea(TileIndex tile, uint3
 
	bool success = false;
 

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

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	// make sure sx,sy are smaller than ex,ey
 
	/* make sure sx,sy are smaller than ex,ey */
 
	ex = TileX(tile);
 
	ey = TileY(tile);
 
	sx = TileX(p1);
 
	sy = TileY(p1);
 
	if (ex < sx) Swap(ex, sx);
 
	if (ey < sy) Swap(ey, sy);
 
@@ -354,15 +356,15 @@ int32 CmdClearArea(TileIndex tile, uint3
 
				if (ret > 0 && (money -= ret) < 0) {
 
					_additional_cash_required = ret;
 
					return cost - ret;
 
				}
 
				DoCommand(TileXY(x, y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 

	
 
				// draw explosion animation...
 
				/* draw explosion animation... */
 
				if ((x == sx || x == ex) && (y == sy || y == ey)) {
 
					// big explosion in each corner, or small explosion for single tiles
 
					/* big explosion in each corner, or small explosion for single tiles */
 
					CreateEffectVehicleAbove(x * TILE_SIZE + TILE_SIZE / 2, y * TILE_SIZE + TILE_SIZE / 2, 2,
 
						sy == ey && sx == ex ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
 
					);
 
				}
 
			}
 
		}
 
@@ -387,13 +389,13 @@ void RunTileLoop(void)
 
	assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
 
	count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
 
	do {
 
		_tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
 

	
 
		if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
 
			tile += TILELOOP_SIZE; /* no overflow */
 
			tile += TILELOOP_SIZE; // no overflow
 
		} else {
 
			tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE - 1) + TileDiffXY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
 
		}
 
	} while (--count);
 
	assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
 

	
src/livery.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file livery.h */
 

	
 
#ifndef LIVERY_H
 
#define LIVERY_H
 

	
 
#include "helpers.hpp"
 

	
 
/* List of different livery schemes. */
src/lzoconf.h
Show inline comments
 
/* $Id$ */
 

	
 
/* lzoconf.h -- configuration for the LZO real-time data compression library
 
/** @file lzoconf.h -- configuration for the LZO real-time data compression library
 

	
 
   This file is part of the LZO real-time data compression library.
 

	
 
   Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
 
   Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
 
   Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
src/macros.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file macros.h */
 

	
 
#ifndef MACROS_H
 
#define MACROS_H
 

	
 
/// Fetch n bits starting at bit s from x
 
/* Fetch n bits starting at bit s from x */
 
#define GB(x, s, n) (((x) >> (s)) & ((1U << (n)) - 1))
 
/// Set n bits starting at bit s in x to d
 
/* Set n bits starting at bit s in x to d */
 
#define SB(x, s, n, d) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | ((d) << (s)))
 
/// Add i to the n bits starting at bit s in x
 
/* Add i to the n bits starting at bit s in x */
 
#define AB(x, s, n, i) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | (((x) + ((i) << (s))) & (((1U << (n)) - 1) << (s))))
 

	
 
#ifdef min
 
#undef min
 
#endif
 

	
 
@@ -76,13 +78,13 @@ template<typename T> static inline T CLR
 
template<typename T> static inline T TOGGLEBIT(T& x, int y)
 
{
 
	return x ^= (T)1 << y;
 
}
 

	
 

	
 
// checking more bits. Maybe unneccessary, but easy to use
 
/* checking more bits. Maybe unneccessary, but easy to use */
 
#define HASBITS(x,y) ((x) & (y))
 
#define SETBITS(x,y) ((x) |= (y))
 
#define CLRBITS(x,y) ((x) &= ~(y))
 

	
 
#define GENERAL_SPRITE_COLOR(color) ((color) + PALETTE_RECOLOR_START)
 
#define PLAYER_SPRITE_COLOR(owner) (GENERAL_SPRITE_COLOR(_player_colors[owner]))
src/main_gui.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file main_gui.cpp */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "heightmap.h"
 
#include "currency.h"
 
#include "functions.h"
 
#include "spritecache.h"
 
@@ -57,31 +59,31 @@ extern bool GenerateTowns(void);
 
void HandleOnEditText(const char *str)
 
{
 
	int id = _rename_id;
 
	_cmd_text = str;
 

	
 
	switch (_rename_what) {
 
	case 0: /* Rename a s sign, if string is empty, delete sign */
 
	case 0: // Rename a s sign, if string is empty, delete sign
 
		DoCommandP(0, id, 0, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME));
 
		break;
 
	case 1: /* Rename a waypoint */
 
	case 1: // Rename a waypoint
 
		if (*str == '\0') return;
 
		DoCommandP(0, id, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME));
 
		break;
 
#ifdef ENABLE_NETWORK
 
	case 3: { /* Give money, you can only give money in excess of loan */
 
	case 3: { // Give money, you can only give money in excess of loan
 
		const Player *p = GetPlayer(_current_player);
 
		int32 money = min(p->money64 - p->current_loan, atoi(str) / _currency->rate);
 
		char msg[20];
 

	
 
		money = clamp(money, 0, 20000000); // Clamp between 20 million and 0
 

	
 
		// Give 'id' the money, and substract it from ourself
 
		/* Give 'id' the money, and substract it from ourself */
 
		if (!DoCommandP(0, money, id, NULL, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS))) break;
 

	
 
		// Inform the player of this action
 
		/* Inform the player of this action */
 
		snprintf(msg, sizeof(msg), "%d", money);
 

	
 
		if (!_network_server) {
 
			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, id, msg);
 
		} else {
 
			NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, id, msg, NETWORK_SERVER_INDEX);
 
@@ -100,13 +102,12 @@ void HandleOnEditText(const char *str)
 
 *
 
 * @param w Window which called the function
 
 * @param widget ID of the widget (=button) that called this function
 
 * @param cursor How should the cursor image change? E.g. cursor with depot image in it
 
 * @param mode Tile highlighting mode, e.g. drawing a rectangle or a dot on the ground
 
 * @param placeproc Procedure which will be called when someone clicks on the map
 

	
 
 * @return true if the button is clicked, false if it's unclicked
 
 */
 
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, int mode, PlaceProc *placeproc)
 
{
 
	if (IsWindowWidgetDisabled(w, widget)) return false;
 

	
 
@@ -523,13 +524,13 @@ static int GetPlayerIndexFromMenu(int in
 
}
 

	
 
static void UpdatePlayerMenuHeight(Window *w)
 
{
 
	byte num = ActivePlayerCount();
 

	
 
	// Increase one to fit in PlayerList in the menu when in network
 
	/* Increase one to fit in PlayerList in the menu when in network */
 
	if (_networking && WP(w,menu_d).main_button == 9) num++;
 

	
 
	if (WP(w,menu_d).item_count != num) {
 
		WP(w,menu_d).item_count = num;
 
		SetWindowDirty(w);
 
		num = num * 10 + 2;
 
@@ -553,13 +554,13 @@ static void PlayerMenuWndProc(Window *w,
 

	
 
		x = 1;
 
		y = 1;
 
		sel = WP(w,menu_d).sel_index;
 
		chk = WP(w,menu_d).checked_items; // let this mean gray items.
 

	
 
		// 9 = playerlist
 
		/* 9 = playerlist */
 
		if (_networking && WP(w,menu_d).main_button == 9) {
 
			if (sel == 0) {
 
				GfxFillRect(x, y, x + 238, y + 9, 0);
 
			}
 
			DrawString(x + 19, y, STR_NETWORK_CLIENT_LIST, 0x0);
 
			y += 10;
 
@@ -598,14 +599,14 @@ static void PlayerMenuWndProc(Window *w,
 
		}
 

	
 
	case WE_POPUPMENU_SELECT: {
 
		int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
 
		int action_id = WP(w,menu_d).action_id;
 

	
 
		// We have a new entry at the top of the list of menu 9 when networking
 
		//  so keep that in count
 
		/* We have a new entry at the top of the list of menu 9 when networking
 
		 *  so keep that in count */
 
		if (_networking && WP(w,menu_d).main_button == 9) {
 
			if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1;
 
		} else {
 
			index = GetPlayerIndexFromMenu(index);
 
		}
 

	
 
@@ -625,14 +626,14 @@ static void PlayerMenuWndProc(Window *w,
 
		}
 
	case WE_POPUPMENU_OVER: {
 
		int index;
 
		UpdatePlayerMenuHeight(w);
 
		index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
 

	
 
		// We have a new entry at the top of the list of menu 9 when networking
 
		//  so keep that in count
 
		/* We have a new entry at the top of the list of menu 9 when networking
 
		 * so keep that in count */
 
		if (_networking && WP(w,menu_d).main_button == 9) {
 
			if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1;
 
		} else {
 
			index = GetPlayerIndexFromMenu(index);
 
		}
 

	
 
@@ -970,26 +971,26 @@ static void ToolbarScenSaveOrLoad(Window
 
{
 
	PopupMainToolbMenu(w, 3, STR_0292_SAVE_SCENARIO, 6, 0);
 
}
 

	
 
static void ToolbarScenDateBackward(Window *w)
 
{
 
	// don't allow too fast scrolling
 
	/* don't allow too fast scrolling */
 
	if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
 
		HandleButtonClick(w, 6);
 
		SetWindowDirty(w);
 

	
 
		_patches_newgame.starting_year = clamp(_patches_newgame.starting_year - 1, MIN_YEAR, MAX_YEAR);
 
		SetDate(ConvertYMDToDate(_patches_newgame.starting_year, 0, 1));
 
	}
 
	_left_button_clicked = false;
 
}
 

	
 
static void ToolbarScenDateForward(Window *w)
 
{
 
	// don't allow too fast scrolling
 
	/* don't allow too fast scrolling */
 
	if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
 
		HandleButtonClick(w, 7);
 
		SetWindowDirty(w);
 

	
 
		_patches_newgame.starting_year = clamp(_patches_newgame.starting_year + 1, MIN_YEAR, MAX_YEAR);
 
		SetDate(ConvertYMDToDate(_patches_newgame.starting_year, 0, 1));
 
@@ -1038,18 +1039,18 @@ void ZoomInOrOutToCursorWindow(bool in, 
 

	
 
			DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, w);
 
		}
 
	}
 
}
 

	
 
// TODO - Incorporate into game itself to allow for ingame raising/lowering of
 
// larger chunks at the same time OR remove altogether, as we have 'level land' ?
 
/**
 
 * Raise/Lower a bigger chunk of land at the same time in the editor. When
 
 * raising get the lowest point, when lowering the highest point, and set all
 
 * tiles in the selection to that height.
 
 * @todo : Incorporate into game itself to allow for ingame raising/lowering of
 
 *         larger chunks at the same time OR remove altogether, as we have 'level land' ?
 
 * @param tile The top-left tile where the terraforming will start
 
 * @param mode 1 for raising, 0 for lowering land
 
 */
 
static void CommonRaiseLowerBigLand(TileIndex tile, int mode)
 
{
 
	int sizex, sizey;
 
@@ -1063,13 +1064,13 @@ static void CommonRaiseLowerBigLand(Tile
 

	
 
		DoCommandP(tile, 8, (uint32)mode, CcTerraform, CMD_TERRAFORM_LAND | CMD_AUTO | CMD_MSG(msg));
 
	} else {
 
		SndPlayTileFx(SND_1F_SPLAT, tile);
 

	
 
		assert(_terraform_size != 0);
 
		// check out for map overflows
 
		/* check out for map overflows */
 
		sizex = min(MapSizeX() - TileX(tile) - 1, _terraform_size);
 
		sizey = min(MapSizeY() - TileY(tile) - 1, _terraform_size);
 

	
 
		if (sizex == 0 || sizey == 0) return;
 

	
 
		if (mode != 0) {
 
@@ -1171,14 +1172,16 @@ static const int8 _multi_terraform_coord
 
	{-16,  2}, {-12,  4}, { -8,  6}, { -4,  8}, {  0, 10}, {  4,  8}, {  8,  6}, { 12,  4}, { 16,  2},
 
	{-20,  0}, {-16, -2}, {-12, -4}, { -8, -6}, { -4, -8}, {  0,-10}, {  4, -8}, {  8, -6}, { 12, -4}, { 16, -2}, { 20,  0},
 
	{-24,  2}, {-20,  4}, {-16,  6}, {-12,  8}, { -8, 10}, { -4, 12}, {  0, 14}, {  4, 12}, {  8, 10}, { 12,  8}, { 16,  6}, { 20,  4}, { 24,  2},
 
	{-28,  0}, {-24, -2}, {-20, -4}, {-16, -6}, {-12, -8}, { -8,-10}, { -4,-12}, {  0,-14}, {  4,-12}, {  8,-10}, { 12, -8}, { 16, -6}, { 20, -4}, { 24, -2}, { 28,  0},
 
};
 

	
 
// TODO - Merge with terraform_gui.c (move there) after I have cooled down at its braindeadness
 
// and changed OnButtonClick to include the widget as well in the function decleration. Post 0.4.0 - Darkvater
 
/**
 
 * @todo Merge with terraform_gui.cpp (move there) after I have cooled down at its braindeadness
 
 * and changed OnButtonClick to include the widget as well in the function declaration. Post 0.4.0 - Darkvater
 
 */
 
static void EditorTerraformClick_Dynamite(Window *w)
 
{
 
	HandlePlacePushButton(w, 4, ANIMCURSOR_DEMOLISH, 1, PlaceProc_DemolishArea);
 
}
 

	
 
static void EditorTerraformClick_LowerBigLand(Window *w)
 
@@ -1268,13 +1271,13 @@ static void ResetLandscapeConfirmationCa
 
}
 

	
 
static void ScenEditLandGenWndProc(Window *w, WindowEvent *e)
 
{
 
	switch (e->event) {
 
	case WE_CREATE:
 
		// XXX - lighthouse button is widget 10!! Don't forget when changing
 
		/* XXX - lighthouse button is widget 10!! Don't forget when changing */
 
		w->widget[10].tooltips = (_opt.landscape == LT_DESERT) ? STR_028F_DEFINE_DESERT_AREA : STR_028D_PLACE_LIGHTHOUSE;
 
		break;
 

	
 
	case WE_PAINT:
 
		DrawWindowWidgets(w);
 

	
 
@@ -1308,28 +1311,28 @@ static void ScenEditLandGenWndProc(Windo
 

	
 
	case WE_CLICK:
 
		switch (e->we.click.widget) {
 
		case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11:
 
			_editor_terraform_button_proc[e->we.click.widget - 4](w);
 
			break;
 
		case 12: case 13: { /* Increase/Decrease terraform size */
 
		case 12: case 13: { // Increase/Decrease terraform size
 
			int size = (e->we.click.widget == 12) ? 1 : -1;
 
			HandleButtonClick(w, e->we.click.widget);
 
			size += _terraform_size;
 

	
 
			if (!IS_INT_INSIDE(size, 1, 8 + 1)) return;
 
			_terraform_size = size;
 

	
 
			SndPlayFx(SND_15_BEEP);
 
			SetWindowDirty(w);
 
		} break;
 
		case 14: /* gen random land */
 
		case 14: // gen random land
 
			HandleButtonClick(w, 14);
 
			ShowCreateScenario();
 
			break;
 
		case 15: /* Reset landscape */
 
		case 15: // Reset landscape
 
			ShowQuery(
 
			  STR_022C_RESET_LANDSCAPE,
 
			  STR_RESET_LANDSCAPE_CONFIRMATION_TEXT,
 
			  NULL,
 
			  ResetLandscapeConfirmationCallback);
 
			break;
 
@@ -1428,16 +1431,16 @@ static void ScenEditTownGenWndProc(Windo
 
	case WE_CREATE:
 
		LowerWindowWidget(w, (_scengen_town_size - 1)+ 7);
 
		break;
 

	
 
	case WE_CLICK:
 
		switch (e->we.click.widget) {
 
		case 4: /* new town */
 
		case 4: // new town
 
			HandlePlacePushButton(w, 4, SPR_CURSOR_TOWN, 1, PlaceProc_Town);
 
			break;
 
		case 5: {/* random town */
 
		case 5: {// random town
 
			Town *t;
 

	
 
			HandleButtonClick(w, 5);
 
			_generating_world = true;
 
			t = CreateRandomTown(20, _scengen_town_size);
 
			_generating_world = false;
 
@@ -1447,13 +1450,13 @@ static void ScenEditTownGenWndProc(Windo
 
			} else {
 
				ScrollMainWindowToTile(t->xy);
 
			}
 

	
 
			break;
 
		}
 
		case 6: {/* many random towns */
 
		case 6: {// many random towns
 
			HandleButtonClick(w, 6);
 

	
 
			_generating_world = true;
 
			if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
 
			_generating_world = false;
 
			break;
 
@@ -1602,24 +1605,25 @@ static bool AnyTownExists(void)
 
extern Industry *CreateNewIndustry(TileIndex tile, IndustryType type);
 

	
 
/**
 
 * Search callback function for TryBuildIndustry
 
 * @param tile to test
 
 * @param data that is passed by the caller.  In this case, the type of industry been tested
 
 * @result of the operation
 
 * @return the success (or not) of the operation
 
 */
 
static bool SearchTileForIndustry(TileIndex tile, uint32 data)
 
{
 
	return CreateNewIndustry(tile, data) != NULL;
 
}
 

	
 
/**
 
 * Perform a 9*9 tiles circular search around a tile
 
 * in order to find a suitable zone to create the desired industry
 
 * @param tile to start search for
 
 * @param type of the desired industry
 
 * @return the success (or not) of the operation
 
 */
 
static bool TryBuildIndustry(TileIndex tile, int type)
 
{
 
	return CircularTileSearch(tile, 9, SearchTileForIndustry, type);
 
}
 

	
 
@@ -1662,13 +1666,13 @@ static void ScenEditIndustryWndProc(Wind
 
				_industry_type_to_place = _industry_type_list[_opt.landscape][button - 4];
 
		}
 
		break;
 
	case WE_PLACE_OBJ: {
 
		int type;
 

	
 
		// Show error if no town exists at all
 
		/* Show error if no town exists at all */
 
		type = _industry_type_to_place;
 
		if (!AnyTownExists()) {
 
			SetDParam(0, GetIndustrySpec(type)->name);
 
			ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_0285_CAN_T_BUILD_HERE, e->we.place.pt.x, e->we.place.pt.y);
 
			return;
 
		}
 
@@ -1801,13 +1805,13 @@ static ToolbarButtonProc * const _toolba
 
};
 

	
 
static void MainToolbarWndProc(Window *w, WindowEvent *e)
 
{
 
	switch (e->event) {
 
	case WE_PAINT:
 
		// Draw brown-red toolbar bg.
 
		/* Draw brown-red toolbar bg. */
 
		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
 
		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT));
 

	
 
		/* If spectator, disable all construction buttons
 
		 * ie : Build road, rail, ships, airports and landscaping
 
		 * Since enabled state is the default, just disable when needed */
 
@@ -2014,13 +2018,13 @@ static void ScenEditToolbarWndProc(Windo
 
{
 
	switch (e->event) {
 
	case WE_PAINT:
 
		SetWindowWidgetDisabledState(w, 6, _patches_newgame.starting_year <= MIN_YEAR);
 
		SetWindowWidgetDisabledState(w, 7, _patches_newgame.starting_year >= MAX_YEAR);
 

	
 
		// Draw brown-red toolbar bg.
 
		/* Draw brown-red toolbar bg. */
 
		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
 
		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT));
 

	
 
		DrawWindowWidgets(w);
 

	
 
		SetDParam(0, ConvertYMDToDate(_patches_newgame.starting_year, 0, 1));
 
@@ -2152,31 +2156,31 @@ static void StatusBarWndProc(Window *w, 
 
		SetDParam(0, _date);
 
		DrawStringCentered(
 
			70, 1, (_pause || _patches.status_long_date) ? STR_00AF : STR_00AE, 0
 
		);
 

	
 
		if (p != NULL) {
 
			// Draw player money
 
			/* Draw player money */
 
			SetDParam64(0, p->money64);
 
			DrawStringCentered(570, 1, p->player_money >= 0 ? STR_0004 : STR_0005, 0);
 
		}
 

	
 
		// Draw status bar
 
		/* Draw status bar */
 
		if (w->message.msg) { // true when saving is active
 
			DrawStringCentered(320, 1, STR_SAVING_GAME, 0);
 
		} else if (_do_autosave) {
 
			DrawStringCentered(320, 1, STR_032F_AUTOSAVE, 0);
 
		} else if (_pause) {
 
			DrawStringCentered(320, 1, STR_0319_PAUSED, 0);
 
		} else if (WP(w,def_d).data_1 > -1280 && FindWindowById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) {
 
			// Draw the scrolling news text
 
			/* Draw the scrolling news text */
 
			if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w,def_d).data_1))
 
				WP(w,def_d).data_1 = -1280;
 
		} else {
 
			if (p != NULL) {
 
				// This is the default text
 
				/* This is the default text */
 
				SetDParam(0, p->name_1);
 
				SetDParam(1, p->name_2);
 
				DrawStringCentered(320, 1, STR_02BA, 0);
 
			}
 
		}
 

	
 
@@ -2196,18 +2200,18 @@ static void StatusBarWndProc(Window *w, 
 
		}
 
		break;
 

	
 
	case WE_TICK: {
 
		if (_pause) return;
 

	
 
		if (WP(w, def_d).data_1 > -1280) { /* Scrolling text */
 
		if (WP(w, def_d).data_1 > -1280) { // Scrolling text
 
			WP(w, def_d).data_1 -= 2;
 
			InvalidateWidget(w, 1);
 
		}
 

	
 
		if (WP(w, def_d).data_2 > 0) { /* Red blot to show there are new unread newsmessages */
 
		if (WP(w, def_d).data_2 > 0) { // Red blot to show there are new unread newsmessages
 
			WP(w, def_d).data_2 -= 2;
 
		} else if (WP(w, def_d).data_2 < 0) {
 
			WP(w, def_d).data_2 = 0;
 
			InvalidateWidget(w, 1);
 
		}
 

	
 
@@ -2308,23 +2312,23 @@ static void MainWindowWndProc(Window *w,
 
			case WKC_ESC: ResetObjectToPlace(); break;
 
			case WKC_DELETE: DeleteNonVitalWindows(); break;
 
			case WKC_DELETE | WKC_SHIFT: DeleteAllNonVitalWindows(); break;
 
			case 'R' | WKC_CTRL: MarkWholeScreenDirty(); break;
 

	
 
#if defined(_DEBUG)
 
			case '0' | WKC_ALT: /* Crash the game */
 
			case '0' | WKC_ALT: // Crash the game
 
				*(byte*)0 = 0;
 
				break;
 

	
 
			case '1' | WKC_ALT: /* Gimme money */
 
			case '1' | WKC_ALT: // Gimme money
 
				/* Server can not cheat in advertise mode either! */
 
				if (!_networking || !_network_server || !_network_advertise)
 
					DoCommandP(0, 10000000, 0, NULL, CMD_MONEY_CHEAT);
 
				break;
 

	
 
			case '2' | WKC_ALT: /* Update the coordinates of all station signs */
 
			case '2' | WKC_ALT: // Update the coordinates of all station signs
 
				UpdateAllStationVirtCoord();
 
				break;
 
#endif
 

	
 
			case 'X':
 
				_display_opt ^= DO_TRANS_BUILDINGS;
 
@@ -2415,13 +2419,13 @@ void SetupColorsAndInitialWindow(void)
 
	width = _screen.width;
 
	height = _screen.height;
 

	
 
	w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
 
	AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0);
 

	
 
	// XXX: these are not done
 
	/* XXX: these are not done */
 
	switch (_game_mode) {
 
		default: NOT_REACHED();
 
		case GM_MENU:
 
			ShowSelectGameWindow();
 
			break;
 

	
src/map.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file map.cpp */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "debug.h"
 
#include "functions.h"
 
#include "macros.h"
 
#include "map.h"
 
@@ -22,14 +24,14 @@ uint _map_size;
 

	
 
Tile* _m = NULL;
 

	
 

	
 
void AllocateMap(uint size_x, uint size_y)
 
{
 
	// Make sure that the map size is within the limits and that
 
	// the x axis size is a power of 2.
 
	/* Make sure that the map size is within the limits and that
 
	 * the x axis size is a power of 2. */
 
	if (size_x < 64 || size_x > 2048 ||
 
			size_y < 64 || size_y > 2048 ||
 
			(size_x&(size_x-1)) != 0 ||
 
			(size_y&(size_y-1)) != 0)
 
		error("Invalid map size");
 

	
 
@@ -41,13 +43,13 @@ void AllocateMap(uint size_x, uint size_
 
	_map_size = size_x * size_y;
 
	_map_tile_mask = _map_size - 1;
 

	
 
	free(_m);
 
	_m = CallocT<Tile>(_map_size);
 

	
 
	// XXX TODO handle memory shortage more gracefully
 
	/* XXX TODO handle memory shortage more gracefully */
 
	if (_m == NULL) error("Failed to allocate memory for the map");
 
}
 

	
 

	
 
#ifdef _DEBUG
 
TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
 
@@ -83,64 +85,64 @@ TileIndex TileAdd(TileIndex tile, TileIn
 
}
 
#endif
 

	
 

	
 
uint ScaleByMapSize(uint n)
 
{
 
	// First shift by 12 to prevent integer overflow for large values of n.
 
	// >>12 is safe since the min mapsize is 64x64
 
	// Add (1<<4)-1 to round upwards.
 
	/* First shift by 12 to prevent integer overflow for large values of n.
 
	 * >>12 is safe since the min mapsize is 64x64
 
	 * Add (1<<4)-1 to round upwards. */
 
	return (n * (MapSize() >> 12) + (1<<4) - 1) >> 4;
 
}
 

	
 

	
 
// Scale relative to the circumference of the map
 
/* Scale relative to the circumference of the map */
 
uint ScaleByMapSize1D(uint n)
 
{
 
	// Normal circumference for the X+Y is 256+256 = 1<<9
 
	// Note, not actually taking the full circumference into account,
 
	// just half of it.
 
	// (1<<9) - 1 is there to scale upwards.
 
	/* Normal circumference for the X+Y is 256+256 = 1<<9
 
	 * Note, not actually taking the full circumference into account,
 
	 * just half of it.
 
	 * (1<<9) - 1 is there to scale upwards. */
 
	return (n * (MapSizeX() + MapSizeY()) + (1<<9) - 1) >> 9;
 
}
 

	
 

	
 
// This function checks if we add addx/addy to tile, if we
 
//  do wrap around the edges. For example, tile = (10,2) and
 
//  addx = +3 and addy = -4. This function will now return
 
//  INVALID_TILE, because the y is wrapped. This is needed in
 
//  for example, farmland. When the tile is not wrapped,
 
//  the result will be tile + TileDiffXY(addx, addy)
 
/* This function checks if we add addx/addy to tile, if we
 
 *  do wrap around the edges. For example, tile = (10,2) and
 
 *  addx = +3 and addy = -4. This function will now return
 
 *  INVALID_TILE, because the y is wrapped. This is needed in
 
 *  for example, farmland. When the tile is not wrapped,
 
 *  the result will be tile + TileDiffXY(addx, addy) */
 
uint TileAddWrap(TileIndex tile, int addx, int addy)
 
{
 
	uint x = TileX(tile) + addx;
 
	uint y = TileY(tile) + addy;
 

	
 
	// Are we about to wrap?
 
	/* Are we about to wrap? */
 
	if (x < MapMaxX() && y < MapMaxY())
 
		return tile + TileDiffXY(addx, addy);
 

	
 
	return INVALID_TILE;
 
}
 

	
 
extern const TileIndexDiffC _tileoffs_by_diagdir[] = {
 
	{-1,  0}, // DIAGDIR_NE
 
	{ 0,  1}, // DIAGDIR_SE
 
	{ 1,  0}, // DIAGDIR_SW
 
	{ 0, -1}  // DIAGDIR_NW
 
	{-1,  0}, ///< DIAGDIR_NE
 
	{ 0,  1}, ///< DIAGDIR_SE
 
	{ 1,  0}, ///< DIAGDIR_SW
 
	{ 0, -1}  ///< DIAGDIR_NW
 
};
 

	
 
extern const TileIndexDiffC _tileoffs_by_dir[] = {
 
	{-1, -1}, // DIR_N
 
	{-1,  0}, // DIR_NE
 
	{-1,  1}, // DIR_E
 
	{ 0,  1}, // DIR_SE
 
	{ 1,  1}, // DIR_S
 
	{ 1,  0}, // DIR_SW
 
	{ 1, -1}, // DIR_W
 
	{ 0, -1}  // DIR_NW
 
	{-1, -1}, ///< DIR_N
 
	{-1,  0}, ///< DIR_NE
 
	{-1,  1}, ///< DIR_E
 
	{ 0,  1}, ///< DIR_SE
 
	{ 1,  1}, ///< DIR_S
 
	{ 1,  0}, ///< DIR_SW
 
	{ 1, -1}, ///< DIR_W
 
	{ 0, -1}  ///< DIR_NW
 
};
 

	
 
uint DistanceManhattan(TileIndex t0, TileIndex t1)
 
{
 
	const uint dx = delta(TileX(t0), TileX(t1));
 
	const uint dy = delta(TileY(t0), TileY(t1));
 
@@ -188,13 +190,13 @@ uint DistanceFromEdge(TileIndex tile)
 
 * Every tile will be tested by means of the callback function proc,
 
 * which will determine if yes or no the given tile meets criteria of search.
 
 * @param tile to start the search from
 
 * @param size: number of tiles per side of the desired search area
 
 * @param proc: callback testing function pointer.
 
 * @param data to be passed to the callback function. Depends on the implementation
 
 * @result of the search
 
 * @return result of the search
 
 * @pre proc != NULL
 
 * @pre size > 0
 
 */
 
bool CircularTileSearch(TileIndex tile, uint size, TestTileOnSearchProc proc, uint32 data)
 
{
 
	uint n, x, y;
src/map.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file map.h */
 

	
 
#ifndef MAP_H
 
#define MAP_H
 

	
 
#include "stdafx.h"
 

	
 
// Putting externs inside inline functions seems to confuse the aliasing
 
// checking on MSVC6. Never use those variables directly.
 
/* Putting externs inside inline functions seems to confuse the aliasing
 
 * checking on MSVC6. Never use those variables directly. */
 
extern uint _map_log_x;
 
extern uint _map_size_x;
 
extern uint _map_size_y;
 
extern uint _map_tile_mask;
 
extern uint _map_size;
 

	
 
@@ -27,24 +29,24 @@ typedef struct Tile {
 
} Tile;
 

	
 
extern Tile* _m;
 

	
 
void AllocateMap(uint size_x, uint size_y);
 

	
 
// binary logarithm of the map size, try to avoid using this one
 
/* binary logarithm of the map size, try to avoid using this one */
 
static inline uint MapLogX(void)  { return _map_log_x; }
 
/* The size of the map */
 
static inline uint MapSizeX(void) { return _map_size_x; }
 
static inline uint MapSizeY(void) { return _map_size_y; }
 
/* The maximum coordinates */
 
static inline uint MapMaxX(void) { return _map_size_x - 1; }
 
static inline uint MapMaxY(void) { return _map_size_y - 1; }
 
/* The number of tiles in the map */
 
static inline uint MapSize(void) { return _map_size; }
 

	
 
// Scale a number relative to the map size
 
/* Scale a number relative to the map size */
 
uint ScaleByMapSize(uint); // Scale relative to the number of tiles
 
uint ScaleByMapSize1D(uint); // Scale relative to the circumference of the map
 

	
 
typedef uint32 TileIndex;
 
typedef int32 TileIndexDiff;
 

	
 
@@ -52,16 +54,16 @@ static inline TileIndex TileXY(uint x, u
 
{
 
	return (y * MapSizeX()) + x;
 
}
 

	
 
static inline TileIndexDiff TileDiffXY(int x, int y)
 
{
 
	// Multiplication gives much better optimization on MSVC than shifting.
 
	// 0 << shift isn't optimized to 0 properly.
 
	// Typically x and y are constants, and then this doesn't result
 
	// in any actual multiplication in the assembly code..
 
	/* Multiplication gives much better optimization on MSVC than shifting.
 
	 * 0 << shift isn't optimized to 0 properly.
 
	 * Typically x and y are constants, and then this doesn't result
 
	 * in any actual multiplication in the assembly code.. */
 
	return (y * MapSizeX()) + x;
 
}
 

	
 
static inline TileIndex TileVirtXY(uint x, uint y)
 
{
 
	return (y >> 4 << MapLogX()) + (x >> 4);
 
@@ -70,15 +72,15 @@ static inline TileIndex TileVirtXY(uint 
 

	
 
enum {
 
	INVALID_TILE = (TileIndex)-1
 
};
 

	
 
enum {
 
	TILE_SIZE   = 16,   /* Tiles are 16x16 "units" in size */
 
	TILE_PIXELS = 32,   /* a tile is 32x32 pixels */
 
	TILE_HEIGHT =  8,   /* The standard height-difference between tiles on two levels is 8 (z-diff 8) */
 
	TILE_SIZE   = 16,   ///< Tiles are 16x16 "units" in size
 
	TILE_PIXELS = 32,   ///< a tile is 32x32 pixels
 
	TILE_HEIGHT =  8,   ///< The standard height-difference between tiles on two levels is 8 (z-diff 8)
 
};
 

	
 

	
 
static inline uint TileX(TileIndex tile)
 
{
 
	return tile & MapMaxX();
 
@@ -129,18 +131,18 @@ static inline TileIndex AddTileIndexDiff
 
	if (x < 0 || y < 0 || x > (int)MapMaxX() || y > (int)MapMaxY())
 
		return INVALID_TILE;
 
	else
 
		return TileXY(x, y);
 
}
 

	
 
// Functions to calculate distances
 
uint DistanceManhattan(TileIndex, TileIndex); // also known as L1-Norm. Is the shortest distance one could go over diagonal tracks (or roads)
 
uint DistanceSquare(TileIndex, TileIndex); // euclidian- or L2-Norm squared
 
uint DistanceMax(TileIndex, TileIndex); // also known as L-Infinity-Norm
 
uint DistanceMaxPlusManhattan(TileIndex, TileIndex); // Max + Manhattan
 
uint DistanceFromEdge(TileIndex); // shortest distance from any edge of the map
 
/* Functions to calculate distances */
 
uint DistanceManhattan(TileIndex, TileIndex); ///< also known as L1-Norm. Is the shortest distance one could go over diagonal tracks (or roads)
 
uint DistanceSquare(TileIndex, TileIndex); ///< euclidian- or L2-Norm squared
 
uint DistanceMax(TileIndex, TileIndex); ///< also known as L-Infinity-Norm
 
uint DistanceMaxPlusManhattan(TileIndex, TileIndex); ///< Max + Manhattan
 
uint DistanceFromEdge(TileIndex); ///< shortest distance from any edge of the map
 

	
 

	
 
#define BEGIN_TILE_LOOP(var,w,h,tile)                      \
 
	{                                                        \
 
		int h_cur = h;                                         \
 
		uint var = tile;                                       \
src/md5.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file md5.cpp */
 

	
 
/*
 
  Copyright (C) 1999, 2000, 2002 Aladdin Enterprises.  All rights reserved.
 

	
 
  This software is provided 'as-is', without any express or implied
 
  warranty.  In no event will the authors be held liable for any damages
 
  arising from the use of this software.
 
@@ -20,13 +22,13 @@
 
  3. This notice may not be removed or altered from any source distribution.
 

	
 
  L. Peter Deutsch
 
  ghost@aladdin.com
 

	
 
 */
 
/* $Id$ */
 

	
 
/*
 
  Independent implementation of MD5 (RFC 1321).
 

	
 
  This code implements the MD5 Algorithm defined in RFC 1321, whose
 
  text is available at
 
	http://www.ietf.org/rfc/rfc1321.txt
src/md5.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file md5.h */
 

	
 
/*
 
  Copyright (C) 1999, 2002 Aladdin Enterprises.  All rights reserved.
 

	
 
  This software is provided 'as-is', without any express or implied
 
  warranty.  In no event will the authors be held liable for any damages
 
  arising from the use of this software.
 
@@ -20,13 +22,13 @@
 
  3. This notice may not be removed or altered from any source distribution.
 

	
 
  L. Peter Deutsch
 
  ghost@aladdin.com
 

	
 
 */
 
/* $Id$ */
 

	
 
/*
 
  Independent implementation of MD5 (RFC 1321).
 

	
 
  This code implements the MD5 Algorithm defined in RFC 1321, whose
 
  text is available at
 
	http://www.ietf.org/rfc/rfc1321.txt
src/mersenne.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file mersenne.cpp */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 

	
 
#ifdef MERSENNE_TWISTER
 

	
 
// Source code for Mersenne Twister.
src/minilzo.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/* minilzo.c -- mini subset of the LZO real-time data compression library
 
/* @file minilzo.cpp -- mini subset of the LZO real-time data compression library
 

	
 
   This file is part of the LZO real-time data compression library.
 

	
 
   Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
 
   Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
 
   Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
src/minilzo.h
Show inline comments
 
/* $Id$ */
 

	
 
/* minilzo.h -- mini subset of the LZO real-time data compression library
 
/* @file minilzo.h -- mini subset of the LZO real-time data compression library
 

	
 
   This file is part of the LZO real-time data compression library.
 

	
 
   Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
 
   Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
 
   Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
src/misc.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file misc.cpp */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "currency.h"
 
#include "functions.h"
 
#include "news.h"
 
#include "player.h"
 
@@ -231,13 +233,13 @@ void ConvertNameArray(void)
 
		/* Terminate the new string and copy it back to the name array */
 
		*strto = '\0';
 
		memcpy(_name_array[i], tmp, sizeof(*_name_array));
 
	}
 
}
 

	
 
// Calculate constants that depend on the landscape type.
 
/* Calculate constants that depend on the landscape type. */
 
void InitializeLandscapeVariables(bool only_constants)
 
{
 
	if (only_constants) return;
 

	
 
	for (CargoID i = 0; i != NUM_CARGO; i++) {
 
		_cargo_payment_rates[i] = GetCargo(i)->initial_payment;
 
@@ -246,14 +248,14 @@ void InitializeLandscapeVariables(bool o
 
}
 

	
 

	
 

	
 
int FindFirstBit(uint32 value)
 
{
 
	// The macro FIND_FIRST_BIT is better to use when your value is
 
	// not more than 128.
 
	/* The macro FIND_FIRST_BIT is better to use when your value is
 
	  not more than 128. */
 
	byte i = 0;
 

	
 
	if (value == 0) return 0;
 

	
 
	if ((value & 0x0000ffff) == 0) { value >>= 16; i += 16; }
 
	if ((value & 0x000000ff) == 0) { value >>= 8;  i += 8;  }
 
@@ -307,14 +309,14 @@ static const SaveLoadGlobVarList _date_d
 
	    SLEG_VAR(_trees_tick_ctr,         SLE_UINT8),
 
	SLEG_CONDVAR(_pause,                  SLE_UINT8,                   4, SL_MAX_VERSION),
 
	SLEG_CONDVAR(_cur_town_iter,          SLE_UINT32,                 11, SL_MAX_VERSION),
 
	    SLEG_END()
 
};
 

	
 
// Save load date related variables as well as persistent tick counters
 
// XXX: currently some unrelated stuff is just put here
 
/* Save load date related variables as well as persistent tick counters
 
 * XXX: currently some unrelated stuff is just put here */
 
static void SaveLoad_DATE(void)
 
{
 
	SlGlobList(_date_desc);
 
}
 

	
 

	
src/misc_cmd.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file misc_cmd.cpp */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "functions.h"
 
#include "string.h"
 
#include "table/strings.h"
 
#include "command.h"
src/misc_gui.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file misc_gui.cpp */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "hal.h"
 
#include "heightmap.h"
 
#include "debug.h"
 
#include "functions.h"
 
@@ -246,40 +248,40 @@ static const char *credits[] = {
 
	"  Chris Sawyer - For an amazing game!"
 
};
 

	
 
static void AboutWindowProc(Window *w, WindowEvent *e)
 
{
 
	switch (e->event) {
 
	case WE_CREATE: /* Set up window counter and start position of scroller */
 
	case WE_CREATE: // Set up window counter and start position of scroller
 
		WP(w, scroller_d).counter = 0;
 
		WP(w, scroller_d).height = w->height - 40;
 
		break;
 
	case WE_PAINT: {
 
		uint i;
 
		int y = WP(w, scroller_d).height;
 
		DrawWindowWidgets(w);
 

	
 
		// Show original copyright and revision version
 
		/* Show original copyright and revision version */
 
		DrawStringCentered(210, 17, STR_00B6_ORIGINAL_COPYRIGHT, 0);
 
		DrawStringCentered(210, 17 + 10, STR_00B7_VERSION, 0);
 

	
 
		// Show all scrolling credits
 
		/* Show all scrolling credits */
 
		for (i = 0; i < lengthof(credits); i++) {
 
			if (y >= 50 && y < (w->height - 40)) {
 
				DoDrawString(credits[i], 10, y, 0x10);
 
			}
 
			y += 10;
 
		}
 

	
 
		// If the last text has scrolled start anew from the start
 
		/* If the last text has scrolled start anew from the start */
 
		if (y < 50) WP(w, scroller_d).height = w->height - 40;
 

	
 
		DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", 16);
 
		DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, 0);
 
	}	break;
 
	case WE_MOUSELOOP: /* Timer to scroll the text and adjust the new top */
 
	case WE_MOUSELOOP: // Timer to scroll the text and adjust the new top
 
		if (WP(w, scroller_d).counter++ % 3 == 0) {
 
			WP(w, scroller_d).height--;
 
			SetWindowDirty(w);
 
		}
 
		break;
 
	}
 
@@ -366,13 +368,13 @@ static void BuildTreesWndProc(Window *w,
 

	
 
		case 15: // tree of random type.
 
			if (HandlePlacePushButton(w, 15, SPR_CURSOR_TREE, 1, NULL))
 
				_tree_to_plant = -1;
 
			break;
 

	
 
		case 16: /* place trees randomly over the landscape*/
 
		case 16: // place trees randomly over the landscape
 
			LowerWindowWidget(w, 16);
 
			w->flags4 |= 5 << WF_TIMEOUT_SHL;
 
			SndPlayFx(SND_15_BEEP);
 
			PlaceTreesRandomly();
 
			MarkWholeScreenDirty();
 
			break;
 
@@ -542,13 +544,13 @@ static void ErrmsgWndProc(Window *w, Win
 
		SetRedErrorSquare(0);
 
		_switch_mode_errorstr = INVALID_STRING_ID;
 
		break;
 

	
 
	case WE_KEYPRESS:
 
		if (e->we.keypress.keycode == WKC_SPACE) {
 
			// Don't continue.
 
			/* Don't continue. */
 
			e->we.keypress.cont = false;
 
			DeleteWindow(w);
 
		}
 
		break;
 
	}
 
}
 
@@ -573,17 +575,17 @@ void ShowErrorMessage(StringID msg_1, St
 
	if (_errmsg_message_1 != STR_013B_OWNED_BY || GetDParamX(_errmsg_decode_params,2) >= 8) {
 

	
 
		if ( (x|y) != 0) {
 
			pt = RemapCoords2(x, y);
 
			vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
 

	
 
			// move x pos to opposite corner
 
			/* move x pos to opposite corner */
 
			pt.x = ((pt.x - vp->virtual_left) >> vp->zoom) + vp->left;
 
			pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - 260 : 20;
 

	
 
			// move y pos to opposite corner
 
			/* move y pos to opposite corner */
 
			pt.y = ((pt.y - vp->virtual_top) >> vp->zoom) + vp->top;
 
			pt.y = (pt.y < (_screen.height >> 1)) ? _screen.height - 80 : 100;
 

	
 
		} else {
 
			pt.x = (_screen.width - 240) >> 1;
 
			pt.y = (_screen.height - 46) >> 1;
 
@@ -1102,18 +1104,18 @@ static void QueryStringWndProc(Window *w
 
		case WE_MOUSELOOP:
 
			HandleEditBox(w, qs, QUERY_STR_WIDGET_TEXT);
 
			break;
 

	
 
		case WE_KEYPRESS:
 
			switch (HandleEditBoxKey(w, qs, QUERY_STR_WIDGET_TEXT, e)) {
 
				case 1: goto press_ok; /* Enter pressed, confirms change */
 
				case 2: DeleteWindow(w); break; /* ESC pressed, closes window, abandons changes */
 
				case 1: goto press_ok; // Enter pressed, confirms change
 
				case 2: DeleteWindow(w); break; // ESC pressed, closes window, abandons changes
 
			}
 
			break;
 

	
 
		case WE_DESTROY: /* Call cancellation of query, if we have not handled it before */
 
		case WE_DESTROY: // Call cancellation of query, if we have not handled it before
 
			if (!qs->handled && w->parent != NULL) {
 
				WindowEvent e;
 
				Window *parent = w->parent;
 

	
 
				qs->handled = true;
 
				e.event = WE_ON_EDIT_TEXT_CANCEL;
 
@@ -1222,13 +1224,13 @@ static void QueryWndProc(Window *w, Wind
 
				case QUERY_WIDGET_NO:
 
					DeleteWindow(w);
 
					break;
 
				}
 
			break;
 

	
 
		case WE_KEYPRESS: /* ESC closes the window, Enter confirms the action */
 
		case WE_KEYPRESS: // ESC closes the window, Enter confirms the action
 
			switch (e->we.keypress.keycode) {
 
				case WKC_RETURN:
 
				case WKC_NUM_ENTER:
 
					q->calledback = true;
 
					if (q->proc != NULL) q->proc(w->parent, true);
 
					/* Fallthrough */
 
@@ -1236,13 +1238,13 @@ static void QueryWndProc(Window *w, Wind
 
					e->we.keypress.cont = false;
 
					DeleteWindow(w);
 
					break;
 
			}
 
			break;
 

	
 
		case WE_DESTROY: /* Call callback function (if any) on window close if not yet called */
 
		case WE_DESTROY: // Call callback function (if any) on window close if not yet called
 
			if (!q->calledback && q->proc != NULL) {
 
				q->calledback = true;
 
				q->proc(w->parent, false);
 
			}
 
			break;
 
	}
 
@@ -1324,13 +1326,13 @@ static const Widget _save_dialog_widgets
 
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   127,   308,   319, STR_4003_DELETE,  STR_400C_DELETE_THE_CURRENTLY_SELECTED},
 
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   128,   244,   308,   319, STR_4002_SAVE,    STR_400D_SAVE_THE_CURRENT_GAME_USING},
 
{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   245,   256,   308,   319, 0x0,              STR_RESIZE_BUTTON},
 
{   WIDGETS_END},
 
};
 

	
 
// Colors for fios types
 
/* Colors for fios types */
 
const byte _fios_colors[] = {13, 9, 9, 6, 5, 6, 5, 6, 6, 8};
 

	
 
void BuildFileList(void)
 
{
 
	_fios_path_changed = true;
 
	FiosFreeSavegameList();
 
@@ -1403,13 +1405,13 @@ extern void StartupEngines(void);
 

	
 
static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
 
{
 
	static FiosItem o_dir;
 

	
 
	switch (e->event) {
 
	case WE_CREATE: { /* Set up OPENTTD button */
 
	case WE_CREATE: { // Set up OPENTTD button
 
		o_dir.type = FIOS_TYPE_DIRECT;
 
		switch (_saveload_mode) {
 
			case SLD_SAVE_GAME:
 
			case SLD_LOAD_GAME:
 
				ttd_strlcpy(&o_dir.name[0], _paths.save_dir, sizeof(o_dir.name));
 
				break;
 
@@ -1463,33 +1465,33 @@ static void SaveLoadDlgWndProc(Window *w
 
		}
 
		break;
 
	}
 

	
 
	case WE_CLICK:
 
		switch (e->we.click.widget) {
 
		case 2: /* Sort save names by name */
 
		case 2: // Sort save names by name
 
			_savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
 
				SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
 
			_savegame_sort_dirty = true;
 
			SetWindowDirty(w);
 
			break;
 

	
 
		case 3: /* Sort save names by date */
 
		case 3: // Sort save names by date
 
			_savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
 
				SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
 
			_savegame_sort_dirty = true;
 
			SetWindowDirty(w);
 
			break;
 

	
 
		case 6: /* OpenTTD 'button', jumps to OpenTTD directory */
 
		case 6: // OpenTTD 'button', jumps to OpenTTD directory
 
			FiosBrowseTo(&o_dir);
 
			SetWindowDirty(w);
 
			BuildFileList();
 
			break;
 

	
 
		case 7: { /* Click the listbox */
 
		case 7: { // Click the listbox
 
			int y = (e->we.click.pt.y - w->widget[e->we.click.widget].top - 1) / 10;
 
			char *name;
 
			const FiosItem *file;
 

	
 
			if (y < 0 || (y += w->vscroll.pos) >= w->vscroll.count) return;
 

	
 
@@ -1510,26 +1512,26 @@ static void SaveLoadDlgWndProc(Window *w
 
					ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
 
					ttd_strlcpy(_file_to_saveload.title, file->title, sizeof(_file_to_saveload.title));
 

	
 
					DeleteWindow(w);
 
					ShowHeightmapLoad();
 
				} else {
 
					// SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox
 
					/* SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox */
 
					ttd_strlcpy(WP(w, querystr_d).text.buf, file->title, WP(w, querystr_d).text.maxlength);
 
					UpdateTextBufferSize(&WP(w, querystr_d).text);
 
					InvalidateWidget(w, 10);
 
				}
 
			} else {
 
				// Changed directory, need repaint.
 
				/* Changed directory, need repaint. */
 
				SetWindowDirty(w);
 
				BuildFileList();
 
			}
 
			break;
 
		}
 

	
 
		case 11: case 12: /* Delete, Save game */
 
		case 11: case 12: // Delete, Save game
 
			break;
 
		}
 
		break;
 
	case WE_MOUSELOOP:
 
		if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
 
			HandleEditBox(w, &WP(w, querystr_d), 10);
 
@@ -1539,42 +1541,42 @@ static void SaveLoadDlgWndProc(Window *w
 
		if (e->we.keypress.keycode == WKC_ESC) {
 
			DeleteWindow(w);
 
			return;
 
		}
 

	
 
		if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
 
			if (HandleEditBoxKey(w, &WP(w, querystr_d), 10, e) == 1) /* Press Enter */
 
			if (HandleEditBoxKey(w, &WP(w, querystr_d), 10, e) == 1) // Press Enter
 
					HandleButtonClick(w, 12);
 
		}
 
		break;
 
	case WE_TIMEOUT:
 
		/* This test protects against using widgets 11 and 12 which are only available
 
		 * in those two saveload mode  */
 
		if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO)) break;
 

	
 
		if (IsWindowWidgetLowered(w, 11)) { /* Delete button clicked */
 
		if (IsWindowWidgetLowered(w, 11)) { // Delete button clicked
 
			if (!FiosDelete(WP(w,querystr_d).text.buf)) {
 
				ShowErrorMessage(INVALID_STRING_ID, STR_4008_UNABLE_TO_DELETE_FILE, 0, 0);
 
			} else {
 
				BuildFileList();
 
				/* Reset file name to current date on successfull delete */
 
				if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName();
 
			}
 

	
 
			UpdateTextBufferSize(&WP(w, querystr_d).text);
 
			SetWindowDirty(w);
 
		} else if (IsWindowWidgetLowered(w, 12)) { /* Save button clicked */
 
		} else if (IsWindowWidgetLowered(w, 12)) { // Save button clicked
 
			_switch_mode = SM_SAVE;
 
			FiosMakeSavegameName(_file_to_saveload.name, WP(w,querystr_d).text.buf, sizeof(_file_to_saveload.name));
 

	
 
			/* In the editor set up the vehicle engines correctly (date might have changed) */
 
			if (_game_mode == GM_EDITOR) StartupEngines();
 
		}
 
		break;
 
	case WE_DESTROY:
 
		// pause is only used in single-player, non-editor mode, non menu mode
 
		/* pause is only used in single-player, non-editor mode, non menu mode */
 
		if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
 
			DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
 
		}
 
		FiosFreeSavegameList();
 
		CLRBIT(_no_scroll, SCROLL_SAVE);
 
		break;
 
@@ -1649,14 +1651,14 @@ void ShowSaveLoadDialog(int mode)
 
	w->resize.height = w->height - 14 * 10; // Minimum of 10 items
 
	LowerWindowWidget(w, 7);
 

	
 
	WP(w, querystr_d).afilter = CS_ALPHANUMERAL;
 
	InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 240);
 

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

	
 
	BuildFileList();
 

	
 
@@ -1700,13 +1702,16 @@ void SetFiosType(const byte fiostype)
 
static int32 ClickMoneyCheat(int32 p1, int32 p2)
 
{
 
		DoCommandP(0, 10000000, 0, NULL, CMD_MONEY_CHEAT);
 
		return true;
 
}
 

	
 
// p1 player to set to, p2 is -1 or +1 (down/up)
 
/**
 
 * @param p1 player to set to
 
 * @param p2 is -1 or +1 (down/up)
 
 */
 
static int32 ClickChangePlayerCheat(int32 p1, int32 p2)
 
{
 
	while (IsValidPlayer((PlayerID)p1)) {
 
		if (_players[p1].is_active) {
 
			SetLocalPlayer((PlayerID)p1);
 

	
 
@@ -1716,25 +1721,29 @@ static int32 ClickChangePlayerCheat(int3
 
		p1 += p2;
 
	}
 

	
 
	return _local_player;
 
}
 

	
 
// p1 -1 or +1 (down/up)
 
/**
 
 * @param p1 -1 or +1 (down/up)
 
 */
 
static int32 ClickChangeClimateCheat(int32 p1, int32 p2)
 
{
 
	if (p1 == -1) p1 = 3;
 
	if (p1 ==  4) p1 = 0;
 
	_opt.landscape = p1;
 
	ReloadNewGRFData();
 
	return _opt.landscape;
 
}
 

	
 
extern void EnginesMonthlyLoop(void);
 

	
 
// p2 1 (increase) or -1 (decrease)
 
/**
 
 * @param p2 1 (increase) or -1 (decrease)
 
 */
 
static int32 ClickChangeDateCheat(int32 p1, int32 p2)
 
{
 
	YearMonthDay ymd;
 
	ConvertDateToYMD(_date, &ymd);
 

	
 
	if ((ymd.year == MIN_YEAR && p2 == -1) || (ymd.year == MAX_YEAR && p2 == 1)) return _cur_year;
 
@@ -1757,19 +1766,19 @@ enum ce_flags_long
 
/** Define basic enum properties */
 
template <> struct EnumPropsT<ce_flags_long> : MakeEnumPropsT<ce_flags_long, byte, CE_NONE, CE_END, CE_END> {};
 
typedef TinyEnumT<ce_flags_long> ce_flags;
 

	
 

	
 
typedef struct CheatEntry {
 
	VarType type;          // type of selector
 
	ce_flags flags;        // selector flags
 
	StringID str;          // string with descriptive text
 
	void *variable;        // pointer to the variable
 
	bool *been_used;       // has this cheat been used before?
 
	CheckButtonClick *proc;// procedure
 
	int16 min, max;        // range for spinbox setting
 
	VarType type;          ///< type of selector
 
	ce_flags flags;        ///< selector flags
 
	StringID str;          ///< string with descriptive text
 
	void *variable;        ///< pointer to the variable
 
	bool *been_used;       ///< has this cheat been used before?
 
	CheckButtonClick *proc;///< procedure
 
	int16 min, max;        ///< range for spinbox setting
 
} CheatEntry;
 

	
 
static const CheatEntry _cheats_ui[] = {
 
	{SLE_BOOL, {CE_CLICK}, STR_CHEAT_MONEY,          &_cheats.money.value,           &_cheats.money.been_used,           &ClickMoneyCheat,         0,  0},
 
	{SLE_UINT8, {CE_NONE}, STR_CHEAT_CHANGE_PLAYER,  &_local_player,                 &_cheats.switch_player.been_used,   &ClickChangePlayerCheat,  0, 11},
 
	{SLE_BOOL,  {CE_NONE}, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, NULL,                     0,  0},
 
@@ -1860,13 +1869,13 @@ static void CheatsWndProc(Window *w, Win
 
	case WE_CLICK: {
 
			const CheatEntry *ce;
 
			uint btn = (e->we.click.pt.y - 46) / 12;
 
			int32 value, oldvalue;
 
			uint x = e->we.click.pt.x;
 

	
 
			// not clicking a button?
 
			/* not clicking a button? */
 
			if (!IS_INT_INSIDE(x, 20, 40) || btn >= lengthof(_cheats_ui)) break;
 

	
 
			ce = &_cheats_ui[btn];
 
			oldvalue = value = (int32)ReadValue(ce->variable, ce->type);
 

	
 
			*ce->been_used = true;
 
@@ -1884,13 +1893,13 @@ static void CheatsWndProc(Window *w, Win
 
				if (step == 0) step = 1;
 

	
 
				/* Increase or decrease the value and clamp it to extremes */
 
				value += (x >= 30) ? step : -step;
 
				value = clamp(value, ce->min, ce->max);
 

	
 
				// take whatever the function returns
 
				/* take whatever the function returns */
 
				value = ce->proc(value, (x >= 30) ? 1 : -1);
 

	
 
				if (value != oldvalue) {
 
					WP(w,def_d).data_1 = btn * 2 + 1 + ((x >= 30) ? 1 : 0);
 
				}
 
			} break;
src/mixer.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file mixer.cpp*/
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "mixer.h"
 

	
 
struct MixerChannel {
 
	bool active;
 

	
 
	// pointer to allocated buffer memory
 
	/* pointer to allocated buffer memory */
 
	int8 *memory;
 

	
 
	// current position in memory
 
	/* current position in memory */
 
	uint32 pos;
 
	uint32 frac_pos;
 
	uint32 frac_speed;
 
	uint32 samples_left;
 

	
 
	// Mixing volume
 
	/* Mixing volume */
 
	uint volume_left;
 
	uint volume_right;
 

	
 
	uint flags;
 
};
 

	
 
@@ -43,13 +45,13 @@ static void mix_int8_to_int16(MixerChann
 
	frac_pos = sc->frac_pos;
 
	frac_speed = sc->frac_speed;
 
	volume_left = sc->volume_left;
 
	volume_right = sc->volume_right;
 

	
 
	if (frac_speed == 0x10000) {
 
		// Special case when frac_speed is 0x10000
 
		/* Special case when frac_speed is 0x10000 */
 
		do {
 
			buffer[0] += *b * volume_left >> 8;
 
			buffer[1] += *b * volume_right >> 8;
 
			b++;
 
			buffer += 2;
 
		} while (--samples > 0);
 
@@ -76,16 +78,16 @@ static void MxCloseChannel(MixerChannel 
 
}
 

	
 
void MxMixSamples(void *buffer, uint samples)
 
{
 
	MixerChannel *mc;
 

	
 
	// Clear the buffer
 
	/* Clear the buffer */
 
	memset(buffer, 0, sizeof(int16) * 2 * samples);
 

	
 
	// Mix each channel
 
	/* Mix each channel */
 
	for (mc = _channels; mc != endof(_channels); mc++) {
 
		if (mc->active) {
 
			mix_int8_to_int16(mc, (int16*)buffer, samples);
 
			if (mc->samples_left == 0) MxCloseChannel(mc);
 
		}
 
	}
 
@@ -108,13 +110,13 @@ void MxSetChannelRawSrc(MixerChannel *mc
 
	mc->flags = flags;
 
	mc->frac_pos = 0;
 
	mc->pos = 0;
 

	
 
	mc->frac_speed = (rate << 16) / _play_rate;
 

	
 
	// adjust the magnitude to prevent overflow
 
	/* adjust the magnitude to prevent overflow */
 
	while (size & 0xFFFF0000) {
 
		size >>= 1;
 
		rate = (rate >> 1) + 1;
 
	}
 

	
 
	mc->samples_left = size * _play_rate / rate;
src/mixer.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file mixer.h */
 

	
 
#ifndef MIXER_H
 
#define MIXER_H
 

	
 
typedef struct MixerChannel MixerChannel;
 

	
 
enum {
src/music.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file music.cpp */
 

	
 
#include "music.h"
 

	
 
const SongSpecs origin_songs_specs[NUM_SONGS_AVAILABLE] = {
 
	{"gm_tt00.gm", "Tycoon DELUXE Theme"},
 
	{"gm_tt02.gm", "Easy Driver"},
 
	{"gm_tt03.gm", "Little Red Diesel"},
src/music.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file music.h */
 

	
 
#ifndef MUSIC_H
 
#define MUSIC_H
 

	
 
#define NUM_SONGS_PLAYLIST 33
 
#define NUM_SONGS_AVAILABLE 22
 

	
src/music_gui.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file music_gui.cpp */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "table/strings.h"
 
#include "table/sprites.h"
 
#include "functions.h"
 
#include "window.h"
src/station_cmd.cpp
Show inline comments
 
@@ -138,13 +138,13 @@ static Station* GetStationAround(TileInd
 
/**
 
 * Counts the numbers of tiles matching a specific type in the area around
 
 * @param tile the center tile of the 'count area'
 
 * @param type the type of tile searched for
 
 * @param industry when type == MP_INDUSTRY, the type of the industry,
 
 *                 in all other cases this parameter is ignored
 
 * @result the noumber of matching tiles around
 
 * @return the result the noumber of matching tiles around
 
 */
 
static int CountMapSquareAround(TileIndex tile, TileType type, IndustryType industry)
 
{
 
	int num = 0;
 

	
 
	for (int dx = -3; dx <= 3; dx++) {
src/town_cmd.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file town_cmd.cpp */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "functions.h"
 
#include "strings.h"
 
#include "road_map.h"
 
#include "table/strings.h"
 
@@ -1489,13 +1491,13 @@ static bool DoBuildStatueOfCompany(TileI
 
	return true;
 
}
 

	
 
/**
 
 * Search callback function for TownActionBuildStatue
 
 * @param data that is passed by the caller.  In this case, nothing
 
 * @result of the test
 
 * @return the result of the test
 
 */
 
static bool SearchTileForStatue(TileIndex tile, uint32 data)
 
{
 
	return DoBuildStatueOfCompany(tile);
 
}
 

	
src/yapf/yapf_common.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file yapf_common.cpp */
 

	
 
#include "../stdafx.h"
 

	
 
#include "yapf.hpp"
 
#include "follow_track.hpp"
 
#include "yapf_node_rail.hpp"
 
#include "yapf_costbase.hpp"
 
#include "yapf_costcache.hpp"
 

	
 
/** translate tileh to the bitset of up-hill trackdirs */
 
const TrackdirBits CYapfCostBase::c_upwards_slopes[] = {
 
	TRACKDIR_BIT_NONE                    , // no tileh
 
	TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_NW, // 1
 
	TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_SE, // 2
 
	TRACKDIR_BIT_X_SW                    , // 3
 
	TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_SE, // 4
 
	TRACKDIR_BIT_NONE                    , // 5
 
	TRACKDIR_BIT_Y_SE                    , // 6
 
	TRACKDIR_BIT_NONE                    , // 7
 
	TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_NW, // 8,
 
	TRACKDIR_BIT_Y_NW                    , // 9
 
	TRACKDIR_BIT_NONE                    , //10
 
	TRACKDIR_BIT_NONE                    , //11,
 
	TRACKDIR_BIT_X_NE                    , //12
 
	TRACKDIR_BIT_NONE                    , //13
 
	TRACKDIR_BIT_NONE                    , //14
 
	TRACKDIR_BIT_NONE                    , //15
 
	TRACKDIR_BIT_NONE                    , ///<  no tileh
 
	TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_NW, ///<  1
 
	TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_SE, ///<  2
 
	TRACKDIR_BIT_X_SW                    , ///<  3
 
	TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_SE, ///<  4
 
	TRACKDIR_BIT_NONE                    , ///<  5
 
	TRACKDIR_BIT_Y_SE                    , ///<  6
 
	TRACKDIR_BIT_NONE                    , ///<  7
 
	TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_NW, ///<  8
 
	TRACKDIR_BIT_Y_NW                    , ///<  9
 
	TRACKDIR_BIT_NONE                    , ///< 10
 
	TRACKDIR_BIT_NONE                    , ///< 11
 
	TRACKDIR_BIT_X_NE                    , ///< 12
 
	TRACKDIR_BIT_NONE                    , ///< 13
 
	TRACKDIR_BIT_NONE                    , ///< 14
 
	TRACKDIR_BIT_NONE                    , ///< 15
 
};
0 comments (0 inline, 0 general)