Changeset - r4293:cbb984a32af5
[Not reviewed]
master
0 32 0
rubidium - 18 years ago 2006-08-16 11:39:55
rubidium@openttd.org
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
-Codechange: store all year related variables that are _not_ stored in a savegame/transported over the network in the same format as _cur_year
32 files changed with 201 insertions and 193 deletions:
0 comments (0 inline, 0 general)
aircraft_cmd.c
Show inline comments
 
@@ -341,49 +341,49 @@ int32 CmdBuildAircraft(TileIndex tile, u
 
		{
 
			const Station* st = GetStationByTile(tile);
 
			const AirportFTAClass* apc = GetAirport(st->airport_type);
 
			uint i;
 

	
 
			for (i = 0; i < apc->nof_depots; i++) {
 
				if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == tile) {
 
					assert(apc->layout[i].heading == HANGAR);
 
					v->u.air.pos = apc->layout[i].position;
 
					break;
 
				}
 
			}
 
			// to ensure v->u.air.pos has been given a value
 
			assert(v->u.air.pos != MAX_ELEMENTS);
 
		}
 

	
 
		v->u.air.state = HANGAR;
 
		v->u.air.previous_pos = v->u.air.pos;
 
		v->u.air.targetairport = GetStationIndex(tile);
 
		v->next = u;
 

	
 
		v->service_interval = _patches.servint_aircraft;
 

	
 
		v->date_of_last_service = _date;
 
		v->build_year = u->build_year = _cur_year;
 
		v->build_year = u->build_year = _cur_year - BASE_YEAR;
 

	
 
		v->cur_image = u->cur_image = 0xEA0;
 

	
 
		v->random_bits = VehicleRandomBits();
 
		u->random_bits = VehicleRandomBits();
 

	
 
		VehiclePositionChanged(v);
 
		VehiclePositionChanged(u);
 

	
 
		// Aircraft with 3 vehicles (chopper)?
 
		if (v->subtype == 0) {
 
			w = vl[2];
 

	
 
			u->next = w;
 

	
 
			w->type = VEH_Aircraft;
 
			w->direction = 0;
 
			w->owner = _current_player;
 
			w->x_pos = v->x_pos;
 
			w->y_pos = v->y_pos;
 
			w->z_pos = v->z_pos + 5;
 
			w->x_offs = w->y_offs = -1;
 
			w->sprite_width = w->sprite_height = 2;
 
			w->z_height = 1;
aircraft_gui.c
Show inline comments
 
@@ -45,49 +45,49 @@ void DrawAircraftPurchaseInfo(int x, int
 
	y += 10;
 

	
 
	/* Cargo capacity */
 
	cargo = FindFirstRefittableCargo(engine_number);
 
	if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
 
		SetDParam(0, avi->passenger_capacity);
 
		SetDParam(1, avi->mail_capacity);
 
		DrawString(x, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, 0);
 
	} else {
 
		/* Note, if the default capacity is selected by the refit capacity
 
		 * callback, then the capacity shown is likely to be incorrect. */
 
		SetDParam(0, _cargoc.names_long[cargo]);
 
		SetDParam(1, AircraftDefaultCargoCapacity(cargo, engine_number));
 
		SetDParam(2, STR_9842_REFITTABLE);
 
		DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
 
	}
 
	y += 10;
 

	
 
	/* Running cost */
 
	SetDParam(0, avi->running_cost * _price.aircraft_running >> 8);
 
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
 
	y += 10;
 

	
 
	/* Design date - Life length */
 
	SetDParam(0, BASE_YEAR + ymd.year);
 
	SetDParam(0, ymd.year);
 
	SetDParam(1, e->lifelength);
 
	DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
 
	y += 10;
 

	
 
	/* Reliability */
 
	SetDParam(0, e->reliability * 100 >> 16);
 
	DrawString(x, y, STR_PURCHASE_INFO_RELIABILITY, 0);
 
	y += 10;
 

	
 
	/* Additional text from NewGRF */
 
	// XXX 227 will become a calculated width...
 
	y += ShowAdditionalText(x, y, 227, engine_number);
 
}
 

	
 
static void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
 
{
 
	PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
 
	DrawSprite(GetAircraftImage(v, DIR_W) | pal, x + 25, y + 10);
 
	if (v->subtype == 0) {
 
		SpriteID rotor_sprite = GetCustomRotorSprite(v, true);
 
		if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
 
		DrawSprite(rotor_sprite, x + 25, y + 5);
 
	}
 
	if (v->index == selection) {
bridge.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file bridge.h Header file for bridges */
 

	
 
#ifndef BRIDGE_H
 
#define BRIDGE_H
 

	
 
enum {
 
	MAX_BRIDGES = 13
 
};
 

	
 
/** Struct containing information about a single bridge type
 
 */
 
typedef struct Bridge {
 
	byte avail_year;     ///< the year in which the bridge becomes available
 
	Year avail_year;     ///< the year in which the bridge becomes available
 
	byte min_length;     ///< the minimum length of the bridge (not counting start and end tile)
 
	byte max_length;     ///< the maximum length of the bridge (not counting start and end tile)
 
	uint16 price;        ///< the relative price of the bridge
 
	uint16 speed;        ///< maximum travel speed
 
	PalSpriteID sprite;  ///< the sprite which is used in the GUI (possibly with a recolor sprite)
 
	StringID material;   ///< the string that contains the bridge description
 
	PalSpriteID **sprite_table; ///< table of sprites for drawing the bridge
 
	byte flags;          ///< bit 0 set: disable drawing of far pillars.
 
} Bridge;
 

	
 
extern const Bridge orig_bridge[MAX_BRIDGES];
 
extern Bridge _bridge[MAX_BRIDGES];
 

	
 
uint GetBridgeFoundation(Slope tileh, Axis axis);
 

	
 
#endif /* BRIDGE_H */
currency.c
Show inline comments
 
@@ -60,43 +60,43 @@ const StringID _currency_string_list[] =
 
	STR_CURR_NLG,
 
	STR_CURR_NOK,
 
	STR_CURR_PLN,
 
	STR_CURR_ROL,
 
	STR_CURR_RUR,
 
	STR_CURR_SEK,
 
	STR_CURR_CUSTOM,
 
	INVALID_STRING_ID
 
};
 

	
 
// NOTE: Make sure both lists are in the same order
 
// + 1 string list terminator
 
assert_compile(lengthof(_currency_specs) + 1 == lengthof(_currency_string_list));
 

	
 

	
 
// get a mask of the allowed currencies depending on the year
 
uint GetMaskOfAllowedCurrencies(void)
 
{
 
	uint mask = 0;
 
	uint i;
 

	
 
	for (i = 0; i != lengthof(_currency_specs); i++) {
 
		uint16 to_euro = _currency_specs[i].to_euro;
 

	
 
		if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && BASE_YEAR + _cur_year >= to_euro) continue;
 
		if (to_euro == CF_ISEURO && BASE_YEAR + _cur_year < 2000) continue;
 
		if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= to_euro) continue;
 
		if (to_euro == CF_ISEURO && _cur_year < 2000) continue;
 
		mask |= (1 << i);
 
	}
 
	mask |= (1 << CUSTOM_CURRENCY_ID); // always allow custom currency
 
	return mask;
 
}
 

	
 

	
 
void CheckSwitchToEuro(void)
 
{
 
	if (_currency_specs[_opt.currency].to_euro != CF_NOEURO &&
 
			_currency_specs[_opt.currency].to_euro != CF_ISEURO &&
 
			BASE_YEAR + _cur_year >= _currency_specs[_opt.currency].to_euro) {
 
			_cur_year >= _currency_specs[_opt.currency].to_euro) {
 
		_opt.currency = 2; // this is the index of euro above.
 
		AddNewsItem(STR_EURO_INTRODUCE, NEWS_FLAGS(NM_NORMAL, 0, NT_ECONOMY, 0), 0, 0);
 
	}
 
}
 

	
date.c
Show inline comments
 
@@ -67,98 +67,99 @@ enum {
 
static const uint16 _accum_days_for_month[] = {
 
	ACCUM_JAN, ACCUM_FEB, ACCUM_MAR, ACCUM_APR,
 
	ACCUM_MAY, ACCUM_JUN, ACCUM_JUL, ACCUM_AUG,
 
	ACCUM_SEP, ACCUM_OCT, ACCUM_NOV, ACCUM_DEC,
 
};
 

	
 

	
 
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
 
{
 
	uint yr  = date / (365 + 365 + 365 + 366);
 
	uint rem = date % (365 + 365 + 365 + 366);
 
	uint x;
 

	
 
	yr *= 4;
 

	
 
	if (rem >= 366) {
 
		rem--;
 
		do {
 
			rem -= 365;
 
			yr++;
 
		} while (rem >= 365);
 
		if (rem >= 31 + 28) rem++;
 
	}
 

	
 
	ymd->year = yr;
 
	ymd->year = BASE_YEAR + yr;
 

	
 
	x = _month_date_from_year_day[rem];
 
	ymd->month = x >> 5;
 
	ymd->day = x & 0x1F;
 
}
 

	
 
/**
 
 * Converts a tupe of Year, Month and Day to a Date.
 
 * @param year  is a number between 0..?
 
 * @param month is a number between 0..11
 
 * @param day   is a number between 1..31
 
 */
 
Date ConvertYMDToDate(Year year, Month month, Day day)
 
{
 
	uint rem;
 
	uint yr = year - BASE_YEAR;
 

	
 
	/* day in the year */
 
	rem = _accum_days_for_month[month] + day - 1;
 

	
 
	/* remove feb 29 from year 1,2,3 */
 
	if (year & 3) rem += (year & 3) * 365 + (rem < 31 + 29);
 
	if (yr & 3) rem += (yr & 3) * 365 + (rem < 31 + 29);
 

	
 
	/* base date. */
 
	return (year >> 2) * (365 + 365 + 365 + 366) + rem;
 
	return (yr >> 2) * (365 + 365 + 365 + 366) + rem;
 
}
 

	
 
/**
 
 * Convert a date on the form:
 
 * 1920 - 2090 (MAX_YEAR_END_REAL)
 
 * 192001 - 209012
 
 * 19200101 - 20901231
 
 * or if > 2090 and below 65536, treat it as a daycount.
 
 * @return -1 if no conversion was possible
 
 */
 
Date ConvertIntDate(uint date)
 
{
 
	Year  year;
 
	Month month = 0;
 
	Day   day   = 1;
 

	
 
	if (IS_INT_INSIDE(date, 1920, MAX_YEAR + 1)) {
 
		year = date - 1920;
 
		year = date;
 
	} else if (IS_INT_INSIDE(date, 192001, 209012 + 1)) {
 
		month = date % 100 - 1;
 
		year = date / 100 - 1920;
 
		year = date / 100;
 
	} else if (IS_INT_INSIDE(date, 19200101, 20901231 + 1)) {
 
		day = date % 100; date /= 100;
 
		month = date % 100 - 1;
 
		year = date / 100 - 1920;
 
		year = date / 100;
 
	} else if (IS_INT_INSIDE(date, 2091, 65536)) {
 
		return date;
 
	} else {
 
		return (Date)-1;
 
	}
 

	
 
	/* invalid ranges? */
 
	if (month >= 12 || !IS_INT_INSIDE(day, 1, 31 + 1)) return (Date)-1;
 

	
 
	return ConvertYMDToDate(year, month, day);
 
}
 

	
 

	
 
/** Functions used by the IncreaseDate function */
 

	
 
extern void OnNewDay_Train(Vehicle *v);
 
extern void OnNewDay_RoadVeh(Vehicle *v);
 
extern void OnNewDay_Aircraft(Vehicle *v);
 
extern void OnNewDay_Ship(Vehicle *v);
 
static void OnNewDay_EffectVehicle(Vehicle *v) { /* empty */ }
 
extern void OnNewDay_DisasterVehicle(Vehicle *v);
 

	
 
typedef void OnNewVehicleDayProc(Vehicle *v);
 

	
 
@@ -261,43 +262,43 @@ void IncreaseDate(void)
 
		EnginesMonthlyLoop();
 
		TownsMonthlyLoop();
 
		IndustryMonthlyLoop();
 
		StationMonthlyLoop();
 
#ifdef ENABLE_NETWORK
 
		if (_network_server) NetworkServerMonthlyLoop();
 
#endif /* ENABLE_NETWORK */
 
	}
 

	
 
	/* check if we entered a new year? */
 
	if (ymd.year == _cur_year) return;
 
	_cur_year = ymd.year;
 

	
 
	/* yes, call various yearly loops */
 
	PlayersYearlyLoop();
 
	TrainsYearlyLoop();
 
	RoadVehiclesYearlyLoop();
 
	AircraftYearlyLoop();
 
	ShipsYearlyLoop();
 
#ifdef ENABLE_NETWORK
 
	if (_network_server) NetworkServerYearlyLoop();
 
#endif /* ENABLE_NETWORK */
 

	
 
	/* check if we reached end of the game */
 
	if (_cur_year == _patches.ending_year - MAX_YEAR) {
 
	if (_cur_year == _patches.ending_year) {
 
			ShowEndGameChart();
 
	/* check if we reached the maximum year, decrement dates by a year */
 
	} else if (BASE_YEAR + _cur_year == MAX_YEAR + 1) {
 
	} else if (_cur_year == MAX_YEAR + 1) {
 
		Vehicle *v;
 

	
 
		_cur_year--;
 
		_date -= 365;
 
		FOR_ALL_VEHICLES(v) {
 
			v->date_of_last_service -= 365;
 
		}
 

	
 
		/* Because the _date wraps here, and text-messages expire by game-days, we have to clean out
 
		 *  all of them if the date is set back, else those messages will hang for ever */
 
		InitTextMessage();
 
	}
 

	
 
	if (_patches.auto_euro) CheckSwitchToEuro();
 
}
disaster_cmd.c
Show inline comments
 
@@ -930,75 +930,72 @@ static void Disaster7_Init(void)
 
					uint n;
 

	
 
					for (n = 0; n < 30; n++) {
 
						DisasterClearSquare(tile);
 
						tile = TILE_MASK(tile + step);
 
					}
 
				}
 
				return;
 
			}
 
		}
 
	}
 
}
 

	
 
static DisasterInitProc * const _disaster_initprocs[] = {
 
	Disaster0_Init,
 
	Disaster1_Init,
 
	Disaster2_Init,
 
	Disaster3_Init,
 
	Disaster4_Init,
 
	Disaster5_Init,
 
	Disaster6_Init,
 
	Disaster7_Init,
 
};
 

	
 
#define MK(a, b) { (a) - BASE_YEAR, (b) - BASE_YEAR }
 
static const struct {
 
	byte min;
 
	byte max;
 
	Year min;
 
	Year max;
 
} _dis_years[] = {
 
	MK(1930, 1955),
 
	MK(1940, 1970),
 
	MK(1960, 1990),
 
	MK(1970, 2000),
 
	MK(2000, 2100),
 
	MK(1940, 1965),
 
	MK(1975, 2010),
 
	MK(1950, 1985)
 
	{ 1930, 1955 },
 
	{ 1940, 1970 },
 
	{ 1960, 1990 },
 
	{ 1970, 2000 },
 
	{ 2000, 2100 },
 
	{ 1940, 1965 },
 
	{ 1975, 2010 },
 
	{ 1950, 1985 }
 
};
 
#undef MK
 

	
 

	
 
static void DoDisaster(void)
 
{
 
	byte buf[lengthof(_dis_years)];
 
	byte year = _cur_year;
 
	uint i;
 
	uint j;
 

	
 
	j = 0;
 
	for (i = 0; i != lengthof(_dis_years); i++) {
 
		if (year >= _dis_years[i].min && year < _dis_years[i].max) buf[j++] = i;
 
		if (_cur_year >= _dis_years[i].min && _cur_year < _dis_years[i].max) buf[j++] = i;
 
	}
 

	
 
	if (j == 0) return;
 

	
 
	_disaster_initprocs[buf[RandomRange(j)]]();
 
}
 

	
 

	
 
static void ResetDisasterDelay(void)
 
{
 
	_disaster_delay = GB(Random(), 0, 9) + 730;
 
}
 

	
 
void DisasterDailyLoop(void)
 
{
 
	if (--_disaster_delay != 0) return;
 

	
 
	ResetDisasterDelay();
 

	
 
	if (_opt.diff.disasters != 0) DoDisaster();
 
}
 

	
 
void StartupDisasters(void)
 
{
economy.c
Show inline comments
 
@@ -1373,49 +1373,49 @@ int LoadUnloadVehicle(Vehicle *v)
 
				// Update amount of waiting cargo
 
				SB(ge->waiting_acceptance, 0, 12, min(v->cargo_count + t, 0xFFF));
 
				ge->feeder_profit += v_profit;
 
				u->profit_this_year += v_profit;
 
				result |= 2;
 
				v->cargo_count = 0;
 
			}
 

	
 
			if (v->cargo_count != 0) completely_empty = false;
 
		}
 

	
 
		/* don't pick up goods that we unloaded */
 
		if (u->current_order.flags & OF_UNLOAD) continue;
 

	
 
		/* update stats */
 
		ge->days_since_pickup = 0;
 
		switch (u->type) {
 
			case VEH_Train: t = u->u.rail.cached_max_speed; break;
 
			case VEH_Road:  t = u->max_speed / 2;           break;
 
			default:        t = u->max_speed;               break;
 
		}
 

	
 
		// if last speed is 0, we treat that as if no vehicle has ever visited the station.
 
		ge->last_speed = min(t, 255);
 
		ge->last_age = _cur_year - v->build_year;
 
		ge->last_age = (_cur_year - BASE_YEAR) - v->build_year;
 

	
 
		// If there's goods waiting at the station, and the vehicle
 
		//  has capacity for it, load it on the vehicle.
 
		count = GB(ge->waiting_acceptance, 0, 12);
 
		if (count != 0 &&
 
				(cap = v->cargo_cap - v->cargo_count) != 0) {
 
			int cargoshare;
 
			int feeder_profit_share;
 

	
 
			if (v->cargo_count == 0)
 
				TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO);
 

	
 
			/* Skip loading this vehicle if another train/vehicle is already handling
 
			 * the same cargo type at this station */
 
			if (_patches.improved_load && LoadWait(v,u)) continue;
 

	
 
			/* TODO: Regarding this, when we do gradual loading, we
 
			 * should first unload all vehicles and then start
 
			 * loading them. Since this will cause
 
			 * VEHICLE_TRIGGER_EMPTY to be called at the time when
 
			 * the whole vehicle chain is really totally empty, the
 
			 * @completely_empty assignment can then be safely
 
			 * removed; that's how TTDPatch behaves too. --pasky */
 
			completely_empty = false;
 
@@ -1461,49 +1461,49 @@ int LoadUnloadVehicle(Vehicle *v)
 
	}
 

	
 
	if (result != 0) {
 
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 

	
 
		if (result & 2) InvalidateWindow(WC_STATION_VIEW, last_visited);
 

	
 
		if (profit != 0) {
 
			v->profit_this_year += profit;
 
			SubtractMoneyFromPlayer(-profit);
 

	
 
			if (IsLocalPlayer()) SndPlayVehicleFx(SND_14_CASHTILL, v);
 

	
 
			ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, -profit);
 
		}
 
	}
 

	
 
	_current_player = old_player;
 
	return result;
 
}
 

	
 
void PlayersMonthlyLoop(void)
 
{
 
	PlayersGenStatistics();
 
	if (_patches.inflation && BASE_YEAR + _cur_year < MAX_YEAR)
 
	if (_patches.inflation && _cur_year < MAX_YEAR)
 
		AddInflation();
 
	PlayersPayInterest();
 
	// Reset the _current_player flag
 
	_current_player = OWNER_NONE;
 
	HandleEconomyFluctuations();
 
	SubsidyMonthlyHandler();
 
}
 

	
 
static void DoAcquireCompany(Player *p)
 
{
 
	Player *owner;
 
	int i,pi;
 
	int64 value;
 

	
 
	SetDParam(0, p->name_1);
 
	SetDParam(1, p->name_2);
 
	SetDParam(2, p->bankrupt_value);
 
	AddNewsItem( (StringID)(_current_player + 16*2), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
 

	
 
	// original code does this a little bit differently
 
	pi = p->index;
 
	ChangeOwnershipOfPlayerItems(pi, _current_player);
 

	
 
	if (p->bankrupt_value == 0) {
 
@@ -1525,49 +1525,49 @@ static void DoAcquireCompany(Player *p)
 

	
 
	DeletePlayerWindows(pi);
 
	RebuildVehicleLists();	//Updates the open windows to add the newly acquired vehicles to the lists
 
}
 

	
 
extern int GetAmountOwnedBy(Player *p, byte owner);
 

	
 
/** Acquire shares in an opposing company.
 
 * @param tile unused
 
 * @param p1 player to buy the shares from
 
 * @param p2 unused
 
 */
 
int32 CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Player *p;
 
	int64 cost;
 

	
 
	/* Check if buying shares is allowed (protection against modified clients */
 
	if (p1 >= MAX_PLAYERS || !_patches.allow_shares) return CMD_ERROR;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
 
	p = GetPlayer(p1);
 

	
 
	/* Protect new companies from hostile takeovers */
 
	if (_cur_year - p->inaugurated_year < 6) return_cmd_error(STR_7080_PROTECTED);
 
	if ((_cur_year - BASE_YEAR) - p->inaugurated_year < 6) return_cmd_error(STR_7080_PROTECTED);
 

	
 
	/* Those lines are here for network-protection (clients can be slow) */
 
	if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 0) return 0;
 

	
 
	/* We can not buy out a real player (temporarily). TODO: well, enable it obviously */
 
	if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 1 && !p->is_ai) return 0;
 

	
 
	cost = CalculateCompanyValue(p) >> 2;
 
	if (flags & DC_EXEC) {
 
		PlayerID* b = p->share_owners;
 
		int i;
 

	
 
		while (*b != OWNER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one OWNER_SPECTATOR */
 
		*b = _current_player;
 

	
 
		for (i = 0; p->share_owners[i] == _current_player;) {
 
			if (++i == 4) {
 
				p->bankrupt_value = 0;
 
				DoAcquireCompany(p);
 
				break;
 
			}
 
		}
 
		InvalidateWindow(WC_COMPANY, p1);
 
	}
engine.c
Show inline comments
 
@@ -217,49 +217,49 @@ static PlayerID GetBestPlayer(PlayerID p
 

	
 
	do {
 
		best_hist = -1;
 
		best_player = OWNER_SPECTATOR;
 
		FOR_ALL_PLAYERS(p) {
 
			if (p->is_active && p->block_preview == 0 && !HASBIT(mask, p->index) &&
 
					p->old_economy[0].performance_history > best_hist) {
 
				best_hist = p->old_economy[0].performance_history;
 
				best_player = p->index;
 
			}
 
		}
 

	
 
		if (best_player == OWNER_SPECTATOR) return OWNER_SPECTATOR;
 

	
 
		SETBIT(mask, best_player);
 
	} while (--pp != 0);
 

	
 
	return best_player;
 
}
 

	
 
void EnginesDailyLoop(void)
 
{
 
	EngineID i;
 

	
 
	if (_cur_year >= 130) return;
 
	if (_cur_year >= 2050) return;
 

	
 
	for (i = 0; i != lengthof(_engines); i++) {
 
		Engine *e = &_engines[i];
 

	
 
		if (e->flags & ENGINE_INTRODUCING) {
 
			if (e->flags & ENGINE_PREVIEWING) {
 
				if (e->preview_player != 0xFF && !--e->preview_wait) {
 
					e->flags &= ~ENGINE_PREVIEWING;
 
					DeleteWindowById(WC_ENGINE_PREVIEW, i);
 
					e->preview_player++;
 
				}
 
			} else if (e->preview_player != 0xFF) {
 
				PlayerID best_player = GetBestPlayer(e->preview_player);
 

	
 
				if (best_player == OWNER_SPECTATOR) {
 
					e->preview_player = 0xFF;
 
					continue;
 
				}
 

	
 
				if (!IS_HUMAN_PLAYER(best_player)) {
 
					/* XXX - TTDBUG: TTD has a bug here ???? */
 
					AcceptEnginePreview(e, best_player);
 
				} else {
 
					e->flags |= ENGINE_PREVIEWING;
 
@@ -338,49 +338,49 @@ static void NewVehicleAvailable(Engine *
 

	
 
	// make maglev / monorail available
 
	FOR_ALL_PLAYERS(p) {
 
		if (p->is_active) {
 
			assert(e->railtype < RAILTYPE_END);
 
			SETBIT(p->avail_railtypes, e->railtype);
 
		}
 
	}
 

	
 
	if (index < NUM_TRAIN_ENGINES) {
 
		AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_TRAINAVAIL), 0, 0);
 
	} else if (index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) {
 
		AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_ROADAVAIL), 0, 0);
 
	} else if (index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) {
 
		AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_SHIPAVAIL), 0, 0);
 
	} else {
 
		AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_AIRCRAFTAVAIL), 0, 0);
 
	}
 
}
 

	
 
void EnginesMonthlyLoop(void)
 
{
 
	Engine *e;
 

	
 
	if (_cur_year < 130) {
 
	if (_cur_year < 2050) {
 
		for (e = _engines; e != endof(_engines); e++) {
 
			// Age the vehicle
 
			if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) {
 
				e->age++;
 
				CalcEngineReliability(e);
 
			}
 

	
 
			if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + 365)) {
 
				// Introduce it to all players
 
				NewVehicleAvailable(e);
 
			} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_INTRODUCING)) && _date >= e->intro_date) {
 
				// Introduction date has passed.. show introducing dialog to one player.
 
				e->flags |= ENGINE_INTRODUCING;
 

	
 
				// Do not introduce new rail wagons
 
				if (!IsWagon(e - _engines))
 
					e->preview_player = 1; // Give to the player with the highest rating.
 
			}
 
		}
 
	}
 
	AdjustAvailAircraft();
 
}
 

	
 
/** Rename an engine.
graph_gui.c
Show inline comments
 
@@ -9,49 +9,49 @@
 
#include "gui.h"
 
#include "gfx.h"
 
#include "player.h"
 
#include "economy.h"
 
#include "signs.h"
 
#include "strings.h"
 
#include "debug.h"
 
#include "variables.h"
 
#include "date.h"
 

	
 
static uint _legend_excludebits;
 
static uint _legend_cargobits;
 

	
 
/************************/
 
/* GENERIC GRAPH DRAWER */
 
/************************/
 

	
 
enum {GRAPH_NUM = 16};
 

	
 
typedef struct GraphDrawer {
 
	uint sel; // bitmask of the players *excluded* (e.g. 11111111 means that no players are shown)
 
	byte num_dataset;
 
	byte num_on_x_axis;
 
	byte month;
 
	byte year;
 
	Year year;
 
	bool include_neg;
 
	byte num_vert_lines;
 
	uint16 unk61A;
 
	uint16 unk61C;
 
	int left, top;
 
	uint height;
 
	StringID format_str_y_axis;
 
	byte color_3, color_2, bg_line_color;
 
	byte colors[GRAPH_NUM];
 
	uint64 cost[GRAPH_NUM][24]; // last 2 years
 
} GraphDrawer;
 

	
 
#define INVALID_VALUE 0x80000000
 

	
 
static void DrawGraph(const GraphDrawer *gw)
 
{
 

	
 
	int i,j,k;
 
	uint x,y,old_x,old_y;
 
	int color;
 
	int right, bottom;
 
	int num_x, num_dataset;
 
	const uint64 *row_ptr, *col_ptr;
 
	int64 mx;
 
@@ -130,49 +130,49 @@ static void DrawGraph(const GraphDrawer 
 
		mx = (mx + 7) & ~7;
 
		y_scaling = (((uint64) (value>>1) << 32) / mx);
 
		value = mx;
 
	}
 

	
 
	/* draw text strings on the y axis */
 
	tmp = value;
 
	if (gw->include_neg) tmp >>= 1;
 
	x = gw->left + 45;
 
	y = gw->top - 3;
 
	i = 9;
 
	do {
 
		SetDParam(0, gw->format_str_y_axis);
 
		SetDParam64(1, (int64)tmp);
 
		tmp -= (value >> 3);
 
		DrawStringRightAligned(x, y, STR_0170, gw->color_3);
 
		y += gw->height >> 3;
 
	} while (--i);
 

	
 
	/* draw strings on the x axis */
 
	if (gw->month != 0xFF) {
 
		x = gw->left + 44;
 
		y = gw->top + gw->height + 1;
 
		j = gw->month;
 
		k = BASE_YEAR + gw->year;
 
		k = gw->year;
 
		i = gw->num_on_x_axis;assert(i>0);
 
		do {
 
			SetDParam(2, k);
 
			SetDParam(0, j + STR_0162_JAN);
 
			SetDParam(1, j + STR_0162_JAN + 2);
 
			DrawString(x, y, j == 0 ? STR_016F : STR_016E, gw->color_3);
 

	
 
			j += 3;
 
			if (j >= 12) {
 
				j = 0;
 
				k++;
 
			}
 
			x += 22;
 
		} while (--i);
 
	} else {
 
		x = gw->left + 52;
 
		y = gw->top + gw->height + 1;
 
		j = gw->unk61A;
 
		i = gw->num_on_x_axis;assert(i>0);
 
		do {
 
			SetDParam(0, j);
 
			DrawString(x, y, STR_01CB, gw->color_3);
 
			j += gw->unk61C;
 
			x += 22;
industry_cmd.c
Show inline comments
 
@@ -1309,49 +1309,49 @@ static void DoCreateNewIndustry(Industry
 
	i->production_rate[1] = indspec->production_rate[1];
 

	
 
	if (_patches.smooth_economy) {
 
		i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255);
 
		i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255);
 
	}
 

	
 
	i->town = t;
 
	i->owner = owner;
 

	
 
	r = Random();
 
	i->color_map = GB(r, 8, 4);
 
	i->counter = GB(r, 0, 12);
 
	i->cargo_waiting[0] = 0;
 
	i->cargo_waiting[1] = 0;
 
	i->last_mo_production[0] = 0;
 
	i->last_mo_production[1] = 0;
 
	i->last_mo_transported[0] = 0;
 
	i->last_mo_transported[1] = 0;
 
	i->pct_transported[0] = 0;
 
	i->pct_transported[1] = 0;
 
	i->total_transported[0] = 0;
 
	i->total_transported[1] = 0;
 
	i->was_cargo_delivered = false;
 
	i->last_prod_year = _cur_year;
 
	i->last_prod_year = _cur_year - BASE_YEAR;
 
	i->total_production[0] = i->production_rate[0] * 8;
 
	i->total_production[1] = i->production_rate[1] * 8;
 

	
 
	if (!_generating_world) i->total_production[0] = i->total_production[1] = 0;
 

	
 
	i->prod_level = 0x10;
 

	
 
	do {
 
		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
 

	
 
		if (it->gfx != 0xFF) {
 
			byte size;
 

	
 
			size = it->ti.x;
 
			if (size > i->width) i->width = size;
 
			size = it->ti.y;
 
			if (size > i->height)i->height = size;
 

	
 
			DoCommand(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 

	
 
			MakeIndustry(cur_tile, i->index, it->gfx);
 
			if (_generating_world) _m[cur_tile].m1 = 0x1E; /* maturity */
 
		}
 
	} while ((++it)->ti.x != -0x80);
 
@@ -1510,49 +1510,49 @@ static void PlaceInitialIndustry(Industr
 
}
 

	
 
void GenerateIndustries(void)
 
{
 
	const byte *b;
 

	
 
	b = _industry_create_table[_opt.landscape];
 
	do {
 
		PlaceInitialIndustry(b[1], b[0]);
 
	} while ( (b+=2)[0] != 0);
 
}
 

	
 
/* Change industry production or do closure */
 
static void ExtChangeIndustryProduction(Industry *i)
 
{
 
	bool closeit = true;
 
	int j;
 
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
 

	
 
	switch (_industry_close_mode[i->type]) {
 
		case INDUSTRYLIFE_NOT_CLOSABLE:
 
			return;
 

	
 
		case INDUSTRYLIFE_CLOSABLE:
 
			if ((byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1, 180))
 
			if ((byte)((_cur_year - BASE_YEAR) - i->last_prod_year) < 5 || !CHANCE16(1, 180))
 
				closeit = false;
 
			break;
 

	
 
		default: /* INDUSTRY_PRODUCTION */
 
			for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
 
				uint32 r = Random();
 
				int old, new, percent;
 
				int mag;
 

	
 
				new = old = i->production_rate[j];
 
				if (CHANCE16I(20, 1024, r))
 
					new -= ((RandomRange(50) + 10) * old) >> 8;
 
				if (CHANCE16I(20 + (i->pct_transported[j] * 20 >> 8), 1024, r >> 16))
 
					new += ((RandomRange(50) + 10) * old) >> 8;
 

	
 
				new = clamp(new, 0, 255);
 
				if (new == old) {
 
					closeit = false;
 
					continue;
 
				}
 

	
 
				percent = new * 100 / old - 100;
 
				i->production_rate[j] = new;
 

	
 
@@ -1573,64 +1573,64 @@ static void ExtChangeIndustryProduction(
 
			}
 
			break;
 
	}
 

	
 
	/* If industry will be closed down, show this */
 
	if (closeit) {
 
		i->prod_level = 0;
 
		SetDParam(0, i->index);
 
		AddNewsItem(
 
			indspec->closure_text,
 
			NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
 
			i->xy + TileDiffXY(1, 1), 0
 
		);
 
	}
 
}
 

	
 

	
 
static void UpdateIndustryStatistics(Industry *i)
 
{
 
	byte pct;
 

	
 
	if (i->produced_cargo[0] != CT_INVALID) {
 
		pct = 0;
 
		if (i->last_mo_production[0] != 0) {
 
			i->last_prod_year = _cur_year;
 
			i->last_prod_year = _cur_year - BASE_YEAR;
 
			pct = min(i->last_mo_transported[0] * 256 / i->last_mo_production[0],255);
 
		}
 
		i->pct_transported[0] = pct;
 

	
 
		i->total_production[0] = i->last_mo_production[0];
 
		i->last_mo_production[0] = 0;
 

	
 
		i->total_transported[0] = i->last_mo_transported[0];
 
		i->last_mo_transported[0] = 0;
 
	}
 

	
 
	if (i->produced_cargo[1] != CT_INVALID) {
 
		pct = 0;
 
		if (i->last_mo_production[1] != 0) {
 
			i->last_prod_year = _cur_year;
 
			i->last_prod_year = _cur_year - BASE_YEAR;
 
			pct = min(i->last_mo_transported[1] * 256 / i->last_mo_production[1],255);
 
		}
 
		i->pct_transported[1] = pct;
 

	
 
		i->total_production[1] = i->last_mo_production[1];
 
		i->last_mo_production[1] = 0;
 

	
 
		i->total_transported[1] = i->last_mo_transported[1];
 
		i->last_mo_transported[1] = 0;
 
	}
 

	
 

	
 
	if (i->produced_cargo[0] != CT_INVALID || i->produced_cargo[1] != CT_INVALID)
 
		InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
 

	
 
	if (i->prod_level == 0) {
 
		DeleteIndustry(i);
 
	} else if (_patches.smooth_economy) {
 
		ExtChangeIndustryProduction(i);
 
	}
 
}
 

	
 
static const byte _new_industry_rand[4][32] = {
 
	{12,12,12,12,12,12,12, 0, 0, 6, 6, 9, 9, 3, 3, 3,18,18, 4, 4, 2, 2, 5, 5, 5, 5, 5, 5, 1, 1, 8, 8},
 
@@ -1700,49 +1700,49 @@ static void ChangeIndustryProduction(Ind
 
						if (i->production_rate[1] >= 128)
 
							b = 0xFF;
 
						i->production_rate[1] = b;
 

	
 
						str = indspec->production_up_text;
 
					}
 
				} else {
 
					/* Decrease production */
 
					if (i->prod_level == 4) {
 
						i->prod_level = 0;
 
						str = indspec->closure_text;
 
					} else {
 
						i->prod_level >>= 1;
 
						i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
 
						i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
 

	
 
						str = indspec->production_down_text;
 
					}
 
				}
 
			}
 
			break;
 

	
 
		case INDUSTRYLIFE_CLOSABLE:
 
			/* maybe close */
 
			if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1,2)) {
 
			if ( (byte)((_cur_year - BASE_YEAR) - i->last_prod_year) >= 5 && CHANCE16(1,2)) {
 
				i->prod_level = 0;
 
				str = indspec->closure_text;
 
			}
 
			break;
 
	}
 

	
 
	if (str != STR_NULL) {
 
		SetDParam(0, i->index);
 
		AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0);
 
	}
 
}
 

	
 
void IndustryMonthlyLoop(void)
 
{
 
	Industry *i;
 
	PlayerID old_player = _current_player;
 
	_current_player = OWNER_NONE;
 

	
 
	FOR_ALL_INDUSTRIES(i) {
 
		if (i->xy != 0) UpdateIndustryStatistics(i);
 
	}
 

	
 
	/* 3% chance that we start a new industry */
 
	if (CHANCE16(3, 100)) {
misc_gui.c
Show inline comments
 
@@ -1656,49 +1656,49 @@ static int32 ClickChangePlayerCheat(int3
 
	}
 

	
 
	return _local_player;
 
}
 

	
 
// 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;
 
	GfxLoadSprites();
 
	MarkWholeScreenDirty();
 
	return _opt.landscape;
 
}
 

	
 
extern void EnginesMonthlyLoop(void);
 

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

	
 
	if ((BASE_YEAR + ymd.year == MIN_YEAR && p2 == -1) || (BASE_YEAR + ymd.year == MAX_YEAR && p2 == 1)) return _cur_year;
 
	if ((ymd.year == MIN_YEAR && p2 == -1) || (ymd.year == MAX_YEAR && p2 == 1)) return _cur_year;
 

	
 
	SetDate(ConvertYMDToDate(_cur_year + p2, ymd.month, ymd.day));
 
	EnginesMonthlyLoop();
 
	SetWindowDirty(FindWindowById(WC_STATUS_BAR, 0));
 
	return _cur_year;
 
}
 

	
 
static int32 ClickAllowConvrail(int32 p1, int32 p2)
 
{
 
	Vehicle *v;
 
	SB(_railtypes[RAILTYPE_ELECTRIC].powered_railtypes, RAILTYPE_RAIL, 1, p1);
 

	
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Train && IsFrontEngine(v)) TrainConsistChanged(v);
 
	}
 
	return p1;
 
}
 

	
 

	
 
typedef int32 CheckButtonClick(int32, int32);
 

	
 
enum ce_flags {CE_CLICK = 1 << 0};
 

	
 
typedef byte ce_flags;
network.h
Show inline comments
 
@@ -185,49 +185,49 @@ VARDEF bool _network_first_time;
 
VARDEF NetworkJoinStatus _network_join_status;
 
VARDEF uint8 _network_join_waiting;
 
VARDEF uint16 _network_join_kbytes;
 
VARDEF uint16 _network_join_kbytes_total;
 

	
 
VARDEF char _network_last_host[NETWORK_HOSTNAME_LENGTH];
 
VARDEF short _network_last_port;
 
VARDEF uint32 _network_last_host_ip;
 
VARDEF uint8 _network_reconnect;
 

	
 
VARDEF bool _network_udp_server;
 
VARDEF uint16 _network_udp_broadcast;
 

	
 
VARDEF byte _network_lan_internet;
 

	
 
VARDEF bool _network_advertise;
 
VARDEF bool _network_need_advertise;
 
VARDEF uint32 _network_last_advertise_frame;
 
VARDEF uint8 _network_advertise_retries;
 

	
 
VARDEF bool _network_autoclean_companies;
 
VARDEF uint8 _network_autoclean_unprotected; // Remove a company after X months
 
VARDEF uint8 _network_autoclean_protected;   // Unprotect a company after X months
 

	
 
VARDEF uint16 _network_restart_game_year;    // If this year is reached, the server automaticly restarts
 
VARDEF Year _network_restart_game_year;      // If this year is reached, the server automaticly restarts
 

	
 
NetworkGameList *NetworkQueryServer(const char* host, unsigned short port, bool game_info);
 

	
 
byte NetworkSpectatorCount(void);
 

	
 
VARDEF char *_network_host_list[10];
 
VARDEF char *_network_ban_list[25];
 

	
 
void ParseConnectionString(const char **player, const char **port, char *connection_string);
 
void NetworkUpdateClientInfo(uint16 client_index);
 
void NetworkAddServer(const char *b);
 
void NetworkRebuildHostList(void);
 
bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
 
void NetworkPopulateCompanyInfo(void);
 

	
 
#endif /* ENABLE_NETWORK */
 

	
 
// Those variables must always be registered!
 
VARDEF bool _networking;
 
VARDEF bool _network_available;  // is network mode available?
 
VARDEF bool _network_server; // network-server is active
 
VARDEF bool _network_dedicated; // are we a dedicated server?
 
VARDEF PlayerID _network_playas; // an id to play as..
 

	
network_server.c
Show inline comments
 
@@ -1187,49 +1187,49 @@ void NetworkPopulateCompanyInfo(void)
 
	NetworkClientState *cs;
 
	NetworkClientInfo *ci;
 
	int i;
 
	uint16 months_empty;
 

	
 
	FOR_ALL_PLAYERS(p) {
 
		if (!p->is_active) {
 
			memset(&_network_player_info[p->index], 0, sizeof(NetworkPlayerInfo));
 
			continue;
 
		}
 

	
 
		// Clean the info but not the password
 
		ttd_strlcpy(password, _network_player_info[p->index].password, sizeof(password));
 
		months_empty = _network_player_info[p->index].months_empty;
 
		memset(&_network_player_info[p->index], 0, sizeof(NetworkPlayerInfo));
 
		_network_player_info[p->index].months_empty = months_empty;
 
		ttd_strlcpy(_network_player_info[p->index].password, password, sizeof(_network_player_info[p->index].password));
 

	
 
		// Grap the company name
 
		SetDParam(0, p->name_1);
 
		SetDParam(1, p->name_2);
 
		GetString(_network_player_info[p->index].company_name, STR_JUST_STRING);
 

	
 
		// Check the income
 
		if (_cur_year - 1 == p->inaugurated_year) {
 
		if (_cur_year - 1 == BASE_YEAR + p->inaugurated_year) {
 
			// The player is here just 1 year, so display [2], else display[1]
 
			for (i = 0; i < 13; i++) {
 
				_network_player_info[p->index].income -= p->yearly_expenses[2][i];
 
			}
 
		} else {
 
			for (i = 0; i < 13; i++) {
 
				_network_player_info[p->index].income -= p->yearly_expenses[1][i];
 
			}
 
		}
 

	
 
		// Set some general stuff
 
		_network_player_info[p->index].inaugurated_year = p->inaugurated_year;
 
		_network_player_info[p->index].company_value = p->old_economy[0].company_value;
 
		_network_player_info[p->index].money = p->money64;
 
		_network_player_info[p->index].performance = p->old_economy[0].performance_history;
 
	}
 

	
 
	// Go through all vehicles and count the type of vehicles
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->owner >= MAX_PLAYERS) continue;
 
		switch (v->type) {
 
			case VEH_Train:
 
				if (IsFrontEngine(v)) {
 
					_network_player_info[v->owner].num_vehicle[0]++;
 
@@ -1292,50 +1292,50 @@ void NetworkPopulateCompanyInfo(void)
 
		}
 
	}
 
}
 

	
 
// Send a packet to all clients with updated info about this client_index
 
void NetworkUpdateClientInfo(uint16 client_index)
 
{
 
	NetworkClientState *cs;
 
	NetworkClientInfo *ci;
 

	
 
	ci = NetworkFindClientInfoFromIndex(client_index);
 

	
 
	if (ci == NULL) return;
 

	
 
	FOR_ALL_CLIENTS(cs) {
 
		SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, ci);
 
	}
 
}
 

	
 
extern void SwitchMode(int new_mode);
 

	
 
/* Check if we want to restart the map */
 
static void NetworkCheckRestartMap(void)
 
{
 
	if (_network_restart_game_year != 0 && BASE_YEAR + _cur_year >= _network_restart_game_year) {
 
		DEBUG(net, 0)("Auto-restarting map. Year %d reached.", BASE_YEAR + _cur_year);
 
	if (_network_restart_game_year != 0 && _cur_year >= _network_restart_game_year) {
 
		DEBUG(net, 0)("Auto-restarting map. Year %d reached.", _cur_year);
 

	
 
		_random_seeds[0][0] = Random();
 
		_random_seeds[0][1] = InteractiveRandom();
 

	
 
		SwitchMode(SM_NEWGAME);
 
	}
 
}
 

	
 
/* Check if the server has autoclean_companies activated
 
    Two things happen:
 
      1) If a company is not protected, it is closed after 1 year (for example)
 
      2) If a company is protected, protection is disabled after 3 years (for example)
 
           (and item 1. happens a year later) */
 
static void NetworkAutoCleanCompanies(void)
 
{
 
	NetworkClientState *cs;
 
	NetworkClientInfo *ci;
 
	Player *p;
 
	bool clients_in_company[MAX_PLAYERS];
 

	
 
	if (!_network_autoclean_companies) return;
 

	
 
	memset(clients_in_company, 0, sizeof(clients_in_company));
 

	
newgrf.c
Show inline comments
 
@@ -2,48 +2,49 @@
 

	
 
#include "stdafx.h"
 

	
 
#include <stdarg.h>
 

	
 
#include "openttd.h"
 
#include "debug.h"
 
#include "gfx.h"
 
#include "fileio.h"
 
#include "functions.h"
 
#include "engine.h"
 
#include "spritecache.h"
 
#include "station.h"
 
#include "sprite.h"
 
#include "newgrf.h"
 
#include "variables.h"
 
#include "string.h"
 
#include "table/strings.h"
 
#include "bridge.h"
 
#include "economy.h"
 
#include "newgrf_engine.h"
 
#include "vehicle.h"
 
#include "newgrf_text.h"
 
#include "table/sprites.h"
 
#include "date.h"
 

	
 
#include "newgrf_spritegroup.h"
 

	
 
/* TTDPatch extended GRF format codec
 
 * (c) Petr Baudis 2004 (GPL'd)
 
 * Changes by Florian octo Forster are (c) by the OpenTTD development team.
 
 *
 
 * Contains portions of documentation by TTDPatch team.
 
 * Thanks especially to Josef Drexler for the documentation as well as a lot
 
 * of help at #tycoon. Also thanks to Michael Blunck for is GRF files which
 
 * served as subject to the initial testing of this codec. */
 

	
 

	
 
static int _skip_sprites; // XXX
 
static uint _file_index; // XXX
 
SpriteID _signal_base = 0;
 

	
 
static GRFFile *_cur_grffile;
 
GRFFile *_first_grffile;
 
GRFConfig *_first_grfconfig;
 
static SpriteID _cur_spriteid;
 
static int _cur_stage;
 
static uint32 _nfo_line;
 

	
 
@@ -985,49 +986,49 @@ static bool StationChangeInfo(uint stid,
 
			FOR_EACH_OBJECT statspec[i]->wires = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x15: /* Blocked tiles */
 
			FOR_EACH_OBJECT statspec[i]->blocked = grf_load_byte(&buf);
 
			break;
 

	
 
		default:
 
			ret = true;
 
			break;
 
	}
 

	
 
	*bufp = buf;
 
	return ret;
 
}
 

	
 
static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int len)
 
{
 
	byte *buf = *bufp;
 
	int i;
 
	bool ret = false;
 

	
 
	switch (prop) {
 
		case 0x08: /* Year of availability */
 
			FOR_EACH_OBJECT _bridge[brid + i].avail_year = grf_load_byte(&buf);
 
			FOR_EACH_OBJECT _bridge[brid + i].avail_year = BASE_YEAR + grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x09: /* Minimum length */
 
			FOR_EACH_OBJECT _bridge[brid + i].min_length = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x0A: /* Maximum length */
 
			FOR_EACH_OBJECT _bridge[brid + i].max_length = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x0B: /* Cost factor */
 
			FOR_EACH_OBJECT _bridge[brid + i].price = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x0C: /* Maximum speed */
 
			FOR_EACH_OBJECT _bridge[brid + i].speed = grf_load_word(&buf);
 
			break;
 

	
 
		case 0x0D: /* Bridge sprite tables */
 
			FOR_EACH_OBJECT {
 
				Bridge *bridge = &_bridge[brid + i];
 
				byte tableid = grf_load_byte(&buf);
 
				byte numtables = grf_load_byte(&buf);
 

	
 
@@ -1038,48 +1039,52 @@ static bool BridgeChangeInfo(uint brid, 
 

	
 
				for (; numtables-- != 0; tableid++) {
 
					byte sprite;
 

	
 
					if (tableid >= 7) { // skip invalid data
 
						grfmsg(GMS_WARN, "BridgeChangeInfo: Table %d >= 7, skipping.", tableid);
 
						for (sprite = 0; sprite < 32; sprite++) grf_load_dword(&buf);
 
						continue;
 
					}
 

	
 
					if (bridge->sprite_table[tableid] == NULL) {
 
						bridge->sprite_table[tableid] = malloc(32 * sizeof(**bridge->sprite_table));
 
					}
 

	
 
					for (sprite = 0; sprite < 32; sprite++)
 
						bridge->sprite_table[tableid][sprite] = grf_load_dword(&buf);
 
				}
 
			}
 
			break;
 

	
 
		case 0x0E: /* Flags; bit 0 - disable far pillars */
 
			FOR_EACH_OBJECT _bridge[brid + i].flags = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x0F: /* Long year -- must be set after property 8 */
 
			FOR_EACH_OBJECT _bridge[brid + i].avail_year = grf_load_word(&buf);
 
			break;
 

	
 
		default:
 
			ret = true;
 
	}
 

	
 
	*bufp = buf;
 
	return ret;
 
}
 

	
 
static bool GlobalVarChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, int len)
 
{
 
	byte *buf = *bufp;
 
	int i;
 
	bool ret = false;
 

	
 
	switch (prop) {
 
		case 0x08: /* Cost base factor */
 
			FOR_EACH_OBJECT {
 
				byte factor = grf_load_byte(&buf);
 
				uint price = gvid + i;
 

	
 
				if (price < NUM_PRICES) {
 
					SetPriceBaseMultiplier(price, factor);
 
				} else {
 
					grfmsg(GMS_WARN, "GlobalVarChangeInfo: Price %d out of range, ignoring.", price);
newgrf_engine.c
Show inline comments
 
@@ -532,49 +532,49 @@ static uint32 GetVehicleTypeInfo(EngineI
 
	if (e->player_avail > 0 && e->player_avail != 0xFF) SETBIT(var, 2);
 
	return var;
 
}
 

	
 

	
 
static uint32 GetGRFParameter(EngineID engine_type, byte parameter)
 
{
 
	const GRFFile *file = GetEngineGRF(engine_type);
 

	
 
	if (parameter >= file->param_end) return 0;
 
	return file->param[parameter];
 
}
 

	
 

	
 
static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
 
{
 
	const Vehicle *v = GRV(object);
 

	
 
	if (v == NULL) {
 
		/* Vehicle does not exist, so we're in a purchase list */
 
		switch (variable) {
 
			case 0x43: return _current_player; /* Owner information */
 
			case 0x46: return 0;               /* Motion counter */
 
			case 0x48: return GetVehicleTypeInfo(object->u.vehicle.self_type); /* Vehicle Type Info */
 
			case 0xC4: return _cur_year;       /* Build year */
 
			case 0xC4: return clamp(_cur_year, BASE_YEAR, MAX_YEAR) - BASE_YEAR; /* Build year */
 
			case 0xDA: return INVALID_VEHICLE; /* Next vehicle */
 
			case 0x7F: return GetGRFParameter(object->u.vehicle.self_type, parameter); /* Read GRF parameter */
 
		}
 

	
 
		*available = false;
 
		return -1;
 
	}
 

	
 
	/* Calculated vehicle parameters */
 
	switch (variable) {
 
		case 0x40: /* Get length of consist */
 
		case 0x41: /* Get length of same consecutive wagons */
 
			if (v->type != VEH_Train) return 1;
 

	
 
			{
 
				const Vehicle* u;
 
				byte chain_before = 0;
 
				byte chain_after  = 0;
 

	
 
				for (u = GetFirstVehicleInChain(v); u != v; u = u->next) {
 
					chain_before++;
 
					if (variable == 0x41 && u->engine_type != v->engine_type) chain_before = 0;
 
				}
 

	
newgrf_spritegroup.c
Show inline comments
 
@@ -55,49 +55,49 @@ static MemoryPool _spritegroup_pool = { 
 
SpriteGroup *AllocateSpriteGroup(void)
 
{
 
	/* This is totally different to the other pool allocators, as we never remove an item from the pool. */
 
	if (_spritegroup_count == _spritegroup_pool.total_items) {
 
		if (!AddBlockToPool(&_spritegroup_pool)) return NULL;
 
	}
 

	
 
	return (SpriteGroup*)GetItemFromPool(&_spritegroup_pool, _spritegroup_count++);
 
}
 

	
 

	
 
void InitializeSpriteGroupPool(void)
 
{
 
	CleanPool(&_spritegroup_pool);
 

	
 
	_spritegroup_count = 0;
 
}
 

	
 

	
 
static inline uint32 GetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
 
{
 
	/* Return common variables */
 
	switch (variable) {
 
		case 0x00: return _date;
 
		case 0x01: return _cur_year;
 
		case 0x01: return clamp(_cur_year, BASE_YEAR, MAX_YEAR) - BASE_YEAR;
 
		case 0x02: return _cur_month;
 
		case 0x03: return _opt.landscape;
 
		case 0x09: return _date_fract;
 
		case 0x0A: return _tick_counter;
 
		case 0x0C: return object->callback;
 
		case 0x10: return object->callback_param1;
 
		case 0x11: return 0;
 
		case 0x18: return object->callback_param2;
 
		case 0x1A: return -1;
 
		case 0x1B: return GB(_display_opt, 0, 6);
 
		case 0x1C: return object->last_value;
 
		case 0x20: return _opt.landscape == LT_HILLY ? _opt.snow_line : 0xFF;
 

	
 
		/* Not a common variable, so evalute the feature specific variables */
 
		default: return object->GetVariable(object, variable, parameter, available);
 
	}
 
}
 

	
 

	
 
/* Evaluate an adjustment for a variable of the given size. This is a bit of
 
 * an unwieldy macro, but it saves triplicating the code. */
 
#define BUILD_EVAL_ADJUST(size, usize) \
 
static inline usize EvalAdjust_ ## size(const DeterministicSpriteGroupAdjust *adjust, usize last_value, int32 value) \
 
{ \
news_gui.c
Show inline comments
 
@@ -237,49 +237,49 @@ void AddNewsItem(StringID string, uint32
 

	
 
	// check the rare case that the oldest (to be overwritten) news item is open
 
	if (_total_news==MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news))
 
		MoveToNexItem();
 

	
 
	_forced_news = INVALID_NEWS;
 
	if (_total_news < MAX_NEWS) _total_news++;
 

	
 
	// make sure our pointer isn't overflowing
 
	_latest_news = increaseIndex(_latest_news);
 

	
 
	// overwrite oldest news entry
 
	if (_oldest_news == _latest_news && _news_items[_oldest_news].string_id != 0)
 
		_oldest_news = increaseIndex(_oldest_news); // but make sure we're not overflowing here
 

	
 
	// add news to _latest_news
 
	ni = &_news_items[_latest_news];
 
	memset(ni, 0, sizeof(*ni));
 

	
 
	ni->string_id = string;
 
	ni->display_mode = (byte)flags;
 
	ni->flags = (byte)(flags >> 8) | NF_NOEXPIRE;
 

	
 
	// show this news message in color?
 
	if (_date >= ConvertIntDate(_patches.colored_news_year))
 
	if (_cur_year >= _patches.colored_news_year)
 
		ni->flags |= NF_INCOLOR;
 

	
 
	ni->type = (byte)(flags >> 16);
 
	ni->callback = (byte)(flags >> 24);
 
	ni->data_a = data_a;
 
	ni->data_b = data_b;
 
	ni->date = _date;
 
	COPY_OUT_DPARAM(ni->params, 0, lengthof(ni->params));
 

	
 
	w = FindWindowById(WC_MESSAGE_HISTORY, 0);
 
	if (w == NULL) return;
 
	SetWindowDirty(w);
 
	w->vscroll.count = _total_news;
 
}
 

	
 

	
 
// don't show item if it's older than x days
 
static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180};
 

	
 
static const Widget _news_type13_widgets[] = {
 
{      WWT_PANEL,   RESIZE_NONE,    15,     0,   429,     0,   169, 0x0, STR_NULL},
 
{      WWT_PANEL,   RESIZE_NONE,    15,     0,    10,     0,    11, 0x0, STR_NULL},
 
{   WIDGETS_END},
 
};
openttd.c
Show inline comments
 
@@ -295,49 +295,49 @@ static void LoadIntroGame(void)
 
#endif
 
	if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
 
		GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
 
	}
 

	
 
	_pause = 0;
 
	_local_player = 0;
 
	MarkWholeScreenDirty();
 

	
 
	// Play main theme
 
	if (_music_driver->is_song_playing()) ResetMusic();
 
}
 

	
 
#if defined(UNIX) && !defined(__MORPHOS__)
 
extern void DedicatedFork(void);
 
#endif
 

	
 
int ttd_main(int argc, char *argv[])
 
{
 
	MyGetOptData mgo;
 
	int i;
 
	const char *optformat;
 
	char musicdriver[16], sounddriver[16], videodriver[16];
 
	int resolution[2] = {0,0};
 
	uint startyear = -1;
 
	Year startyear = INVALID_YEAR;
 

	
 
	bool dedicated = false;
 
	bool network   = false;
 
	char *network_conn = NULL;
 

	
 
	musicdriver[0] = sounddriver[0] = videodriver[0] = 0;
 

	
 
	_game_mode = GM_MENU;
 
	_switch_mode = SM_MENU;
 
	_switch_mode_errorstr = INVALID_STRING_ID;
 
	_dedicated_forks = false;
 
	_config_file = NULL;
 

	
 
	// The last param of the following function means this:
 
	//   a letter means: it accepts that param (e.g.: -h)
 
	//   a ':' behind it means: it need a param (e.g.: -m<driver>)
 
	//   a '::' behind it means: it can optional have a param (e.g.: -d<debug>)
 
	optformat = "bm:s:v:hDn::eit:d::r:g::G:c:"
 
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
 
		"f"
 
#endif
 
	;
 

	
 
	MyGetOptInit(&mgo, argc-1, argv+1, optformat);
 
@@ -387,49 +387,49 @@ int ttd_main(int argc, char *argv[])
 

	
 
	if (_ai.network_client && !network) {
 
		_ai.network_client = false;
 
		DEBUG(ai, 0) ("[AI] Can't enable network-AI, because '-n' is not used\n");
 
	}
 

	
 
	DeterminePaths();
 
	CheckExternalFiles();
 

	
 
#if defined(UNIX) && !defined(__MORPHOS__)
 
	// We must fork here, or we'll end up without some resources we need (like sockets)
 
	if (_dedicated_forks)
 
		DedicatedFork();
 
#endif
 

	
 
	LoadFromConfig();
 
	CheckConfig();
 
	LoadFromHighScore();
 

	
 
	// override config?
 
	if (musicdriver[0]) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
 
	if (sounddriver[0]) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
 
	if (videodriver[0]) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
 
	if (resolution[0]) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; }
 
	if (startyear != (uint)-1) _patches_newgame.starting_year = startyear;
 
	if (startyear != INVALID_YEAR) _patches_newgame.starting_year = startyear;
 

	
 
	if (_dedicated_forks && !dedicated) _dedicated_forks = false;
 

	
 
	// enumerate language files
 
	InitializeLanguagePacks();
 

	
 
	// initialize screenshot formats
 
	InitializeScreenshotFormats();
 

	
 
	// initialize airport state machines
 
	InitializeAirports();
 

	
 
	/* initialize all variables that are allocated dynamically */
 
	InitializeDynamicVariables();
 

	
 
	/* start the AI */
 
	AI_Initialize();
 

	
 
	// Sample catalogue
 
	DEBUG(misc, 1) ("Loading sound effects...");
 
	MxInitialize(11025);
 
	SoundInitialize("sample.cat");
 

	
 
	// This must be done early, since functions use the InvalidateWindow* calls
openttd.h
Show inline comments
 
@@ -31,49 +31,54 @@ typedef struct Waypoint Waypoint;
 
typedef struct Window Window;
 
typedef struct Station Station;
 
typedef struct ViewPort ViewPort;
 
typedef struct Town Town;
 
typedef struct NewsItem NewsItem;
 
typedef struct Industry Industry;
 
typedef struct DrawPixelInfo DrawPixelInfo;
 
typedef uint16 VehicleID;
 
typedef uint16 StationID;
 
typedef uint16 TownID;
 
typedef byte PlayerID;
 
typedef byte OrderID;
 
typedef byte CargoID;
 
typedef byte LandscapeID;
 
typedef uint16 StringID;
 
typedef uint32 SpriteID;    ///< The number of a sprite, without mapping bits and colortables
 
typedef uint32 PalSpriteID; ///< The number of a sprite plus all the mapping bits and colortables
 
typedef uint32 CursorID;
 
typedef uint16 EngineID; ///< All enginenumbers should be of this type
 
typedef uint16 UnitID;   ///< All unitnumber stuff is of this type (or anyway, should be)
 

	
 
typedef uint32 WindowNumber;
 
typedef byte WindowClass;
 

	
 
typedef uint8  Year;
 
enum {
 
	INVALID_YEAR = -1,
 
	INVALID_DATE = (uint16)-1,
 
};
 

	
 
typedef int16  Year;
 
typedef uint16 Date;
 

	
 

	
 
enum GameModes {
 
	GM_MENU,
 
	GM_NORMAL,
 
	GM_EDITOR
 
};
 

	
 
enum SwitchModes {
 
	SM_NONE = 0,
 
	SM_NEWGAME = 1,
 
	SM_EDITOR = 2,
 
	SM_LOAD = 3,
 
	SM_MENU = 4,
 
	SM_SAVE = 5,
 
	SM_GENRANDLAND = 6,
 
	SM_LOAD_SCENARIO = 9,
 
	SM_START_SCENARIO = 10,
 
};
 

	
 

	
 
/* Modes for GenerateWorld */
 
enum GenerateWorldModes {
player_gui.c
Show inline comments
 
@@ -25,50 +25,50 @@
 

	
 
static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied);
 

	
 

	
 
static void DrawPlayerEconomyStats(const Player *p, byte mode)
 
{
 
	int x,y,i,j,year;
 
	const int64 (*tbl)[13];
 
	int64 sum, cost;
 
	StringID str;
 

	
 
	if (!(mode & 1)) { // normal sized economics window (mode&1) is minimized status
 
		/* draw categories */
 
		DrawStringCenterUnderline(61, 15, STR_700F_EXPENDITURE_INCOME, 0);
 
		for (i = 0; i != 13; i++)
 
			DrawString(2, 27 + i*10, STR_7011_CONSTRUCTION + i, 0);
 
		DrawStringRightAligned(111, 27 + 10*13 + 2, STR_7020_TOTAL, 0);
 

	
 
		/* draw the price columns */
 
		year = _cur_year - 2;
 
		j = 3;
 
		x = 215;
 
		tbl = p->yearly_expenses + 2;
 
		do {
 
			if (year >= p->inaugurated_year) {
 
				SetDParam(0, BASE_YEAR + year);
 
			if (year >= BASE_YEAR + p->inaugurated_year) {
 
				SetDParam(0, year);
 
				DrawStringCenterUnderline(x-17, 15, STR_7010, 0);
 
				sum = 0;
 
				for (i = 0; i != 13; i++) {
 
					/* draw one row in the price column */
 
					cost = (*tbl)[i];
 
					if (cost != 0) {
 
						sum += cost;
 

	
 
						str = STR_701E;
 
						if (cost < 0) { cost = -cost; str++; }
 
						SetDParam64(0, cost);
 
						DrawStringRightAligned(x, 27+i*10, str, 0);
 
					}
 
				}
 

	
 
				str = STR_701E;
 
				if (sum < 0) { sum = -sum; str++; }
 
				SetDParam64(0, sum);
 
				DrawStringRightAligned(x, 27 + 13*10 + 2, str, 0);
 

	
 
				GfxFillRect(x - 75, 27 + 10*13, x, 27 + 10*13, 215);
 
				x += 95;
 
			}
 
			year++;
players.c
Show inline comments
 
@@ -469,49 +469,49 @@ static Player *AllocatePlayer(void)
 
	}
 
	return NULL;
 
}
 

	
 
Player *DoStartupNewPlayer(bool is_ai)
 
{
 
	Player *p;
 

	
 
	p = AllocatePlayer();
 
	if (p == NULL) return NULL;
 

	
 
	// Make a color
 
	p->player_color = GeneratePlayerColor();
 
	_player_colors[p->index] = p->player_color;
 
	p->name_1 = STR_SV_UNNAMED;
 
	p->is_active = true;
 

	
 
	p->money64 = p->player_money = p->current_loan = 100000;
 

	
 
	p->is_ai = is_ai;
 
	p->ai.state = 5; /* AIS_WANT_NEW_ROUTE */
 
	p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = OWNER_SPECTATOR;
 

	
 
	p->avail_railtypes = GetPlayerRailtypes(p->index);
 
	p->inaugurated_year = _cur_year;
 
	p->inaugurated_year = _cur_year - BASE_YEAR;
 
	p->face = Random();
 

	
 
	/* Engine renewal settings */
 
	p->engine_renew_list = NULL;
 
	p->renew_keep_length = false;
 
	p->engine_renew = false;
 
	p->engine_renew_months = -6;
 
	p->engine_renew_money = 100000;
 

	
 
	GeneratePresidentName(p);
 

	
 
	InvalidateWindow(WC_GRAPH_LEGEND, 0);
 
	InvalidateWindow(WC_TOOLBAR_MENU, 0);
 
	InvalidateWindow(WC_CLIENT_LIST, 0);
 

	
 
	if (is_ai && (!_networking || _network_server) && _ai.enabled)
 
		AI_StartNewAI(p->index);
 

	
 
	return p;
 
}
 

	
 
void StartupPlayers(void)
 
{
 
	// The AI starts like in the setting with +2 month max
roadveh_cmd.c
Show inline comments
 
@@ -163,49 +163,49 @@ int32 CmdBuildRoadVeh(TileIndex tile, ui
 
		v->value = cost;
 
//		v->day_counter = 0;
 
//		v->next_order_param = v->next_order = 0;
 
//		v->load_unload_time_rem = 0;
 
//		v->progress = 0;
 

	
 
//	v->u.road.unk2 = 0;
 
//	v->u.road.overtaking = 0;
 

	
 
		v->last_station_visited = INVALID_STATION;
 
		v->max_speed = rvi->max_speed;
 
		v->engine_type = (byte)p1;
 

	
 
		e = GetEngine(p1);
 
		v->reliability = e->reliability;
 
		v->reliability_spd_dec = e->reliability_spd_dec;
 
		v->max_age = e->lifelength * 366;
 
		_new_vehicle_id = v->index;
 

	
 
		v->string_id = STR_SV_ROADVEH_NAME;
 

	
 
		v->service_interval = _patches.servint_roadveh;
 

	
 
		v->date_of_last_service = _date;
 
		v->build_year = _cur_year;
 
		v->build_year = _cur_year - BASE_YEAR;
 

	
 
		v->type = VEH_Road;
 
		v->cur_image = 0xC15;
 
		v->random_bits = VehicleRandomBits();
 

	
 
		VehiclePositionChanged(v);
 

	
 
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 
		RebuildVehicleLists();
 
		InvalidateWindow(WC_COMPANY, v->owner);
 
		if (IsLocalPlayer())
 
			InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window
 
	}
 

	
 
	return cost;
 
}
 

	
 
/** Start/Stop a road vehicle.
 
 * @param tile unused
 
 * @param p1 road vehicle ID to start/stop
 
 * @param p2 unused
 
 */
 
int32 CmdStartStopRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
roadveh_gui.c
Show inline comments
 
@@ -33,49 +33,49 @@ void DrawRoadVehPurchaseInfo(int x, int 
 
	const Engine *e = GetEngine(engine_number);
 
	bool refittable = (_engine_info[engine_number].refit_mask != 0);
 
	YearMonthDay ymd;
 
	ConvertDateToYMD(e->intro_date, &ymd);
 

	
 
	/* Purchase cost - Max speed */
 
	SetDParam(0, rvi->base_cost * (_price.roadveh_base>>3)>>5);
 
	SetDParam(1, rvi->max_speed / 2);
 
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
 
	y += 10;
 

	
 
	/* Running cost */
 
	SetDParam(0, rvi->running_cost * _price.roadveh_running >> 8);
 
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
 
	y += 10;
 

	
 
	/* Cargo type + capacity */
 
	SetDParam(0, _cargoc.names_long[rvi->cargo_type]);
 
	SetDParam(1, rvi->capacity);
 
	SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
 
	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
 
	y += 10;
 

	
 
	/* Design date - Life length */
 
	SetDParam(0, BASE_YEAR + ymd.year);
 
	SetDParam(0, ymd.year);
 
	SetDParam(1, e->lifelength);
 
	DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
 
	y += 10;
 

	
 
	/* Reliability */
 
	SetDParam(0, e->reliability * 100 >> 16);
 
	DrawString(x, y, STR_PURCHASE_INFO_RELIABILITY, 0);
 
	y += 10;
 

	
 
	/* Additional text from NewGRF */
 
	// XXX 227 will become a calculated width...
 
	y += ShowAdditionalText(x, y, 227, engine_number);
 
}
 

	
 
static void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection)
 
{
 
	PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
 
	DrawSprite(GetRoadVehImage(v, DIR_W) | pal, x + 14, y + 6);
 

	
 
	if (v->index == selection) {
 
		DrawFrameRect(x - 1, y - 1, x + 28, y + 12, 15, FR_BORDERONLY);
 
	}
 
}
 

	
settings.c
Show inline comments
 
@@ -1185,49 +1185,49 @@ static const SettingDescGlobVarList _mis
 
	  SDTG_STR("savegame_format",  SLE_STRB, S, 0, _savegame_format,       NULL,    STR_NULL, NULL),
 
	 SDTG_BOOL("rightclick_emulate",         S, 0, _rightclick_emulate,   false,    STR_NULL, NULL),
 
	  SDTG_END()
 
};
 

	
 
#ifdef ENABLE_NETWORK
 
static const SettingDescGlobVarList _network_settings[] = {
 
	 SDTG_VAR("sync_freq",           SLE_UINT16,C|S,0, _network_sync_freq,            100, 0,  100,STR_NULL, NULL),
 
	 SDTG_VAR("frame_freq",           SLE_UINT8,C|S,0, _network_frame_freq,             0, 0,  100,STR_NULL, NULL),
 
	 SDTG_VAR("max_join_time",       SLE_UINT16, S, 0, _network_max_join_time,        500, 0,32000,STR_NULL, NULL),
 
	SDTG_BOOL("pause_on_join",                   S, 0, _network_pause_on_join,        true,        STR_NULL, NULL),
 
	 SDTG_STR("server_bind_ip",        SLE_STRB, S, 0, _network_server_bind_ip_host,  "0.0.0.0",   STR_NULL, NULL),
 
	 SDTG_VAR("server_port",         SLE_UINT16, S, 0, _network_server_port,          NETWORK_DEFAULT_PORT, 0, 65535,STR_NULL, NULL),
 
	SDTG_BOOL("server_advertise",                S, 0, _network_advertise,            false,       STR_NULL, NULL),
 
	 SDTG_VAR("lan_internet",         SLE_UINT8, S, 0, _network_lan_internet,           0, 0,    1,STR_NULL, NULL),
 
	 SDTG_STR("player_name",           SLE_STRB, S, 0, _network_player_name,          NULL,        STR_NULL, NULL),
 
	 SDTG_STR("server_password",       SLE_STRB, S, 0, _network_server_password,      NULL,        STR_NULL, NULL),
 
	 SDTG_STR("rcon_password",         SLE_STRB, S, 0, _network_rcon_password,        NULL,        STR_NULL, NULL),
 
	 SDTG_STR("server_name",           SLE_STRB, S, 0, _network_server_name,          NULL,        STR_NULL, NULL),
 
	 SDTG_STR("connect_to_ip",         SLE_STRB, S, 0, _network_default_ip,           NULL,        STR_NULL, NULL),
 
	 SDTG_STR("network_id",            SLE_STRB, S, 0, _network_unique_id,            NULL,        STR_NULL, NULL),
 
	SDTG_BOOL("autoclean_companies",             S, 0, _network_autoclean_companies,  false,       STR_NULL, NULL),
 
	 SDTG_VAR("autoclean_unprotected",SLE_UINT8, S, 0, _network_autoclean_unprotected,12, 0,  60,  STR_NULL, NULL),
 
	 SDTG_VAR("autoclean_protected",  SLE_UINT8, S, 0, _network_autoclean_protected,  36, 0, 180,  STR_NULL, NULL),
 
	 SDTG_VAR("restart_game_year",   SLE_UINT16, S,D0, _network_restart_game_year,    0, MIN_YEAR, MAX_YEAR, STR_NULL, NULL),
 
	 SDTG_VAR("restart_game_year",    SLE_INT16, S,D0, _network_restart_game_year,    0, MIN_YEAR, MAX_YEAR, STR_NULL, NULL),
 
	 SDTG_END()
 
};
 
#endif /* ENABLE_NETWORK */
 

	
 
static const SettingDesc _gameopt_settings[] = {
 
	/* In version 4 a new difficulty setting has been added to the difficulty settings,
 
	 * town attitude towards demolishing. Needs special handling because some dimwit thought
 
	 * it funny to have the GameDifficulty struct be an array while it is a struct of
 
	 * same-sized members
 
	 * XXX - To save file-space and since values are never bigger than about 10? only
 
	 * save the first 16 bits in the savegame. Question is why the values are still int32
 
	 * and why not byte for example? */
 
	SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 17, 0, 0, 0, NULL, STR_NULL, NULL, 0, 3),
 
	SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 18, 0, 0, 0, NULL, STR_NULL, NULL, 4, SL_MAX_VERSION),
 
	    SDT_VAR(GameOptions, diff_level,SLE_UINT8, 0, 0, 9,0, 9, STR_NULL, NULL),
 
	  SDT_OMANY(GameOptions, currency,  SLE_UINT8, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SEK|custom", STR_NULL, NULL),
 
	  SDT_OMANY(GameOptions, units,     SLE_UINT8, N, 0, 1,   2, "imperial|metric|si", STR_NULL, NULL),
 
	  SDT_OMANY(GameOptions, town_name, SLE_UINT8, 0, 0, 0,  19, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss|danish|turkish|italian", STR_NULL, NULL),
 
	  SDT_OMANY(GameOptions, landscape, SLE_UINT8, 0, 0, 0,   3, "normal|hilly|desert|candy", STR_NULL, NULL),
 
	    SDT_VAR(GameOptions, snow_line, SLE_UINT8, 0, 0, 1,0,56, STR_NULL, NULL),
 
	SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8, 0, 22,             N, 0, 0, 0, "", STR_NULL, NULL),
 
	SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8,23, SL_MAX_VERSION, S, 0, 1, 4, "off|monthly|quarterly|half year|yearly", STR_NULL, NULL),
 
	  SDT_OMANY(GameOptions, road_side, SLE_UINT8, 0, 0, 1,   1, "left|right", STR_NULL, NULL),
 
	    SDT_END()
 
@@ -1299,51 +1299,51 @@ const SettingDesc _patch_settings[] = {
 
	 SDT_VAR(Patches, servint_aircraft,  SLE_UINT16, 0,D0,   100,     5,    800, STR_CONFIG_PATCHES_SERVINT_AIRCRAFT,     InValidateDetailsWindow),
 
	SDT_BOOL(Patches, no_servicing_if_no_breakdowns, 0, 0, false,                STR_CONFIG_PATCHES_NOSERVICE,            NULL),
 
	SDT_BOOL(Patches, wagon_speed_limits,            0, 0,  true,                STR_CONFIG_PATCHES_WAGONSPEEDLIMITS,     NULL),
 

	
 
	/***************************************************************************/
 
	/* Station section of the GUI-configure patches window */
 
	SDT_BOOL(Patches, join_stations,           0, 0,  true,   STR_CONFIG_PATCHES_JOINSTATIONS,       NULL),
 
	SDT_BOOL(Patches, full_load_any,           0, 0,  true,   STR_CONFIG_PATCHES_FULLLOADANY,        NULL),
 
	SDT_BOOL(Patches, improved_load,           0, 0, false,   STR_CONFIG_PATCHES_IMPROVEDLOAD,       NULL),
 
	SDT_BOOL(Patches, selectgoods,             0, 0,  true,   STR_CONFIG_PATCHES_SELECTGOODS,        NULL),
 
	SDT_BOOL(Patches, new_nonstop,             0, 0, false,   STR_CONFIG_PATCHES_NEW_NONSTOP,        NULL),
 
	SDT_BOOL(Patches, nonuniform_stations,     0, 0,  true,   STR_CONFIG_PATCHES_NONUNIFORM_STATIONS,NULL),
 
	 SDT_VAR(Patches, station_spread,SLE_UINT8,0, 0, 12, 4,64,STR_CONFIG_PATCHES_STATION_SPREAD,     InvalidateStationBuildWindow),
 
	SDT_BOOL(Patches, serviceathelipad,        0, 0,  true,   STR_CONFIG_PATCHES_SERVICEATHELIPAD,   NULL),
 
	SDT_BOOL(Patches, modified_catchment,      0, 0,  true,   STR_CONFIG_PATCHES_CATCHMENT,          NULL),
 

	
 
	/***************************************************************************/
 
	/* Economy section of the GUI-configure patches window */
 
	SDT_BOOL(Patches, inflation,                  0, 0,  true,            STR_CONFIG_PATCHES_INFLATION,        NULL),
 
	SDT_BOOL(Patches, build_rawmaterial_ind,      0, 0, false,            STR_CONFIG_PATCHES_BUILDXTRAIND,     NULL),
 
	SDT_BOOL(Patches, multiple_industry_per_town, 0, 0, false,            STR_CONFIG_PATCHES_MULTIPINDTOWN,    NULL),
 
	SDT_BOOL(Patches, same_industry_close,        0, 0, false,            STR_CONFIG_PATCHES_SAMEINDCLOSE,     NULL),
 
	SDT_BOOL(Patches, bribe,                      0, 0,  true,            STR_CONFIG_PATCHES_BRIBE,            NULL),
 
	 SDT_VAR(Patches, snow_line_height,SLE_UINT8, 0, 0,     7,   2,   13, STR_CONFIG_PATCHES_SNOWLINE_HEIGHT,  NULL),
 
	 SDT_VAR(Patches, colored_news_year,SLE_UINT, 0,NC,  2000, MIN_YEAR, MAX_YEAR, STR_CONFIG_PATCHES_COLORED_NEWS_YEAR,NULL),
 
	 SDT_VAR(Patches, starting_year,    SLE_UINT, 0,NC,  1950, MIN_YEAR, MAX_YEAR, STR_CONFIG_PATCHES_STARTING_YEAR,NULL),
 
	 SDT_VAR(Patches, ending_year,      SLE_UINT,0,NC|NO,2051, MIN_YEAR, MAX_YEAR, STR_CONFIG_PATCHES_ENDING_YEAR,  NULL),
 
	 SDT_VAR(Patches, colored_news_year,SLE_FILE_U32 | SLE_VAR_I16, 0,NC,  2000, MIN_YEAR, MAX_YEAR, STR_CONFIG_PATCHES_COLORED_NEWS_YEAR,NULL),
 
	 SDT_VAR(Patches, starting_year,    SLE_FILE_U32 | SLE_VAR_I16, 0,NC,  1950, MIN_YEAR, MAX_YEAR, STR_CONFIG_PATCHES_STARTING_YEAR,NULL),
 
	 SDT_VAR(Patches, ending_year,      SLE_FILE_U32 | SLE_VAR_I16,0,NC|NO,2051, MIN_YEAR, MAX_YEAR, STR_CONFIG_PATCHES_ENDING_YEAR,  NULL),
 
	SDT_BOOL(Patches, smooth_economy,             0, 0,  true,            STR_CONFIG_PATCHES_SMOOTH_ECONOMY,   NULL),
 
	SDT_BOOL(Patches, allow_shares,               0, 0,  true,            STR_CONFIG_PATCHES_ALLOW_SHARES,     NULL),
 

	
 
	/***************************************************************************/
 
	/* AI section of the GUI-configure patches window */
 
	SDT_BOOL(Patches, ainew_active,           0, 0, false, STR_CONFIG_PATCHES_AINEW_ACTIVE,      AiNew_PatchActive_Warning),
 
	SDT_BOOL(Patches, ai_in_multiplayer,      0, 0, false, STR_CONFIG_PATCHES_AI_IN_MULTIPLAYER, Ai_In_Multiplayer_Warning),
 
	SDT_BOOL(Patches, ai_disable_veh_train,   0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_TRAINS,  NULL),
 
	SDT_BOOL(Patches, ai_disable_veh_roadveh, 0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_ROADVEH, NULL),
 
	SDT_BOOL(Patches, ai_disable_veh_aircraft,0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_AIRCRAFT,NULL),
 
	SDT_BOOL(Patches, ai_disable_veh_ship,    0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_SHIPS,   NULL),
 

	
 
	/***************************************************************************/
 
	/* Patches without any GUI representation */
 
	SDT_BOOL(Patches, keep_all_autosave,              S, 0, false,      STR_NULL, NULL),
 
	SDT_BOOL(Patches, autosave_on_exit,               S, 0, false,      STR_NULL, NULL),
 
	 SDT_VAR(Patches, max_num_autosaves,   SLE_UINT8, S, 0, 16, 0, 255, STR_NULL, NULL),
 
	SDT_BOOL(Patches, bridge_pillars,                 S, 0,  true,      STR_NULL, NULL),
 
	 SDT_VAR(Patches, extend_vehicle_life, SLE_UINT8, 0, 0,  0, 0, 100, STR_NULL, NULL),
 
	SDT_BOOL(Patches, auto_euro,                      S, 0,  true,      STR_NULL, NULL),
 
	 SDT_VAR(Patches, dist_local_authority,SLE_UINT8, 0, 0, 20, 5,  60, STR_NULL, NULL),
 
	 SDT_VAR(Patches, wait_oneway_signal,  SLE_UINT8, 0, 0, 15, 2, 100, STR_NULL, NULL),
 
	 SDT_VAR(Patches, wait_twoway_signal,  SLE_UINT8, 0, 0, 41, 2, 100, STR_NULL, NULL),
 

	
ship_cmd.c
Show inline comments
 
@@ -880,49 +880,49 @@ int32 CmdBuildShip(TileIndex tile, uint3
 
		v->y_offs = -3;
 
		v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
 

	
 
		v->spritenum = svi->image_index;
 
		v->cargo_type = svi->cargo_type;
 
		v->cargo_subtype = 0;
 
		v->cargo_cap = svi->capacity;
 
		v->value = value;
 

	
 
		v->last_station_visited = INVALID_STATION;
 
		v->max_speed = svi->max_speed;
 
		v->engine_type = p1;
 

	
 
		e = GetEngine(p1);
 
		v->reliability = e->reliability;
 
		v->reliability_spd_dec = e->reliability_spd_dec;
 
		v->max_age = e->lifelength * 366;
 
		_new_vehicle_id = v->index;
 

	
 
		v->string_id = STR_SV_SHIP_NAME;
 
		v->u.ship.state = 0x80;
 

	
 
		v->service_interval = _patches.servint_ships;
 
		v->date_of_last_service = _date;
 
		v->build_year = _cur_year;
 
		v->build_year = _cur_year - BASE_YEAR;
 
		v->cur_image = 0x0E5E;
 
		v->type = VEH_Ship;
 
		v->random_bits = VehicleRandomBits();
 

	
 
		VehiclePositionChanged(v);
 

	
 
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 
		RebuildVehicleLists();
 
		InvalidateWindow(WC_COMPANY, v->owner);
 
		if (IsLocalPlayer())
 
			InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Ship); // updates the replace Ship window
 
	}
 

	
 
	return value;
 
}
 

	
 
/** Sell a ship.
 
 * @param tile unused
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 */
 
int32 CmdSellShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
ship_gui.c
Show inline comments
 
@@ -33,49 +33,49 @@ void DrawShipPurchaseInfo(int x, int y, 
 
	const ShipVehicleInfo *svi = ShipVehInfo(engine_number);
 
	const Engine *e;
 

	
 
	/* Purchase cost - Max speed */
 
	SetDParam(0, svi->base_cost * (_price.ship_base>>3)>>5);
 
	SetDParam(1, svi->max_speed / 2);
 
	DrawString(x,y, STR_PURCHASE_INFO_COST_SPEED, 0);
 
	y += 10;
 

	
 
	/* Cargo type + capacity */
 
	SetDParam(0, _cargoc.names_long[svi->cargo_type]);
 
	SetDParam(1, svi->capacity);
 
	SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
 
	DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0);
 
	y += 10;
 

	
 
	/* Running cost */
 
	SetDParam(0, svi->running_cost * _price.ship_running >> 8);
 
	DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
 
	y += 10;
 

	
 
	/* Design date - Life length */
 
	e = GetEngine(engine_number);
 
	ConvertDateToYMD(e->intro_date, &ymd);
 
	SetDParam(0, BASE_YEAR + ymd.year);
 
	SetDParam(0, ymd.year);
 
	SetDParam(1, e->lifelength);
 
	DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
 
	y += 10;
 

	
 
	/* Reliability */
 
	SetDParam(0, e->reliability * 100 >> 16);
 
	DrawString(x,y, STR_PURCHASE_INFO_RELIABILITY, 0);
 
	y += 10;
 

	
 
	/* Additional text from NewGRF */
 
	// XXX 227 will become a calculated width...
 
	y += ShowAdditionalText(x, y, 227, engine_number);
 
}
 

	
 
static void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection)
 
{
 
	DrawSprite(GetShipImage(v, DIR_W) | GetVehiclePalette(v), x + 32, y + 10);
 

	
 
	if (v->index == selection) {
 
		DrawFrameRect(x - 5, y - 1, x + 67, y + 21, 15, FR_BORDERONLY);
 
	}
 
}
 

	
 
static void ShipRefitWndProc(Window *w, WindowEvent *e)
strings.c
Show inline comments
 
@@ -318,70 +318,70 @@ static char *FormatNoCommaNumber(char *b
 
		if (tot |= quot || i == 9) {
 
			*buff++ = '0' + quot;
 
		}
 
	}
 

	
 
	*buff = '\0';
 

	
 
	return buff;
 
}
 

	
 

	
 
static char *FormatYmdString(char *buff, Date date)
 
{
 
	const char *src;
 
	YearMonthDay ymd;
 

	
 
	ConvertDateToYMD(date, &ymd);
 

	
 
	for (src = GetStringPtr(ymd.day + STR_01AC_1ST - 1); (*buff++ = *src++) != '\0';) {}
 
	buff[-1] = ' ';
 

	
 
	for (src = GetStringPtr(STR_0162_JAN + ymd.month); (*buff++ = *src++) != '\0';) {}
 
	buff[-1] = ' ';
 

	
 
	return FormatNoCommaNumber(buff, BASE_YEAR + ymd.year);
 
	return FormatNoCommaNumber(buff, ymd.year);
 
}
 

	
 
static char *FormatMonthAndYear(char *buff, Date date)
 
{
 
	const char *src;
 
	YearMonthDay ymd;
 

	
 
	ConvertDateToYMD(date, &ymd);
 

	
 
	for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {}
 
	buff[-1] = ' ';
 

	
 
	return FormatNoCommaNumber(buff, BASE_YEAR + ymd.year);
 
	return FormatNoCommaNumber(buff, ymd.year);
 
}
 

	
 
static char *FormatTinyDate(char *buff, Date date)
 
{
 
	YearMonthDay ymd;
 

	
 
	ConvertDateToYMD(date, &ymd);
 
	buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, BASE_YEAR + ymd.year);
 
	buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year);
 

	
 
	return buff;
 
}
 

	
 
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact)
 
{
 
	const char *s;
 
	char c;
 
	char buf[40], *p;
 
	int j;
 

	
 
	// multiply by exchange rate
 
	number *= spec->rate;
 

	
 
	// convert from negative
 
	if (number < 0) {
 
		*buff++ = '-';
 
		number = -number;
 
	}
 

	
 
	// add prefix part
 
	s = spec->prefix;
 
	while (s != spec->prefix + lengthof(spec->prefix) && (c = *s++) != '\0') *buff++ = c;
 

	
table/town_land.h
Show inline comments
 
@@ -1998,162 +1998,162 @@ static const byte _housetype_remove_cost
 
	 140, 145, 165,  90,  75,  85,
 
};
 
assert_compile(lengthof(_housetype_remove_cost) == HOUSE_MAX);
 

	
 
static const uint16 _housetype_remove_ratingmod[] = {
 
	 140, 130,  90, 230, 160, 160,  80, 150,
 
	 150,  40,  40,  75,  75, 110, 100, 100,
 
	 100, 150, 110, 110, 300, 300, 300, 300,
 
	  75,  75,  75, 100, 170, 135, 180, 230,
 
	 300, 300, 300, 300, 250,  75,  75, 230,
 
	 300, 300, 300, 300,  90,  90,  70,  70,
 
	  70,  70, 120, 120, 130, 130, 140, 140,
 
	  60,  60,  80,  80, 230, 230,  80,  80,
 
	 110, 110, 160, 160, 160, 160, 105, 105,
 
	 135, 135, 200, 200, 200, 200,  80,  80,
 
	  80,  30,  95, 200,  80,  95,  95, 140,
 
	 140,  95, 150, 200,  90,  50,  75,  75,
 
	  75,  75, 130,  80,  80, 130,  45,  45,
 
	 130, 130, 130,  70,  65,  95,
 
};
 
assert_compile(lengthof(_housetype_remove_ratingmod) == HOUSE_MAX);
 

	
 

	
 
typedef struct {
 
	byte min,max;
 
	Year min, max;
 
} HousetypeYear;
 

	
 
static const HousetypeYear _housetype_years[] = {
 
	{43, 255},
 
	{37, 255},
 
	{48, 255},
 
	{0,  255},
 
	{55, 255},
 
	{55, 255},
 
	{0,  255},
 
	{39, 255},
 
	{39, 255},
 
	{25, 255},
 
	{25, 255},
 
	{0, 255},
 
	{15, 255},
 
	{31, 255},
 
	{10, 40},
 
	{10, 40},
 
	{10, 40},
 
	{57, 255},
 
	{63, 255},
 
	{65, 255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  31},
 
	{0,  32},
 
	{11, 255},
 
	{15, 255},
 
	{43, 255},
 
	{0,  35},
 
	{53, 255},
 
	{0,  255},
 
	{38, 255},
 
	{38, 255},
 
	{38, 255},
 
	{38, 255},
 
	{80, 255},
 
	{0,  40},
 
	{0,  40},
 
	{25, 255},
 
	{63, 255},
 
	{63, 255},
 
	{63, 255},
 
	{63, 255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  43},
 
	{0,  43},
 
	{46, 255},
 
	{46, 255},
 
	{50, 255},
 
	{50, 255},
 
	{54, 255},
 
	{54, 255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  40},
 
	{0,  40},
 
	{52, 255},
 
	{52, 255},
 
	{52, 255},
 
	{52, 255},
 
	{43, 255},
 
	{43, 255},
 
	{58, 255},
 
	{58, 255},
 
	{47, 255},
 
	{47, 255},
 
	{47, 255},
 
	{47, 255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{53, 255},
 
	{42, 255},
 
	{64, 255},
 
	{64, 255},
 
	{0,  255},
 
	{73, 255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{0,  255},
 
	{ 1963, MAX_YEAR },
 
	{ 1957, MAX_YEAR },
 
	{ 1968, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{ 1975, MAX_YEAR },
 
	{ 1975, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{ 1959, MAX_YEAR },
 
	{ 1959, MAX_YEAR },
 
	{ 1945, MAX_YEAR },
 
	{ 1945, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{ 1935, MAX_YEAR },
 
	{ 1951, MAX_YEAR },
 
	{ 1930,     1960 },
 
	{ 1930,     1960 },
 
	{ 1930,     1960 },
 
	{ 1977, MAX_YEAR },
 
	{ 1983, MAX_YEAR },
 
	{ 1985, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0,     1951 },
 
	{    0,     1952 },
 
	{ 1941, MAX_YEAR },
 
	{ 1945, MAX_YEAR },
 
	{ 1963, MAX_YEAR },
 
	{    0,     1955 },
 
	{ 1973, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{ 1958, MAX_YEAR },
 
	{ 1958, MAX_YEAR },
 
	{ 1958, MAX_YEAR },
 
	{ 1958, MAX_YEAR },
 
	{ 1950, MAX_YEAR },
 
	{    0,     1960 },
 
	{    0,     1960 },
 
	{ 1945, MAX_YEAR },
 
	{ 1983, MAX_YEAR },
 
	{ 1983, MAX_YEAR },
 
	{ 1983, MAX_YEAR },
 
	{ 1983, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0,     1963 },
 
	{    0,     1963 },
 
	{ 1966, MAX_YEAR },
 
	{ 1966, MAX_YEAR },
 
	{ 1970, MAX_YEAR },
 
	{ 1970, MAX_YEAR },
 
	{ 1974, MAX_YEAR },
 
	{ 1974, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0,     1960 },
 
	{    0,     1960 },
 
	{ 1972, MAX_YEAR },
 
	{ 1972, MAX_YEAR },
 
	{ 1972, MAX_YEAR },
 
	{ 1972, MAX_YEAR },
 
	{ 1963, MAX_YEAR },
 
	{ 1963, MAX_YEAR },
 
	{ 1978, MAX_YEAR },
 
	{ 1978, MAX_YEAR },
 
	{ 1967, MAX_YEAR },
 
	{ 1967, MAX_YEAR },
 
	{ 1967, MAX_YEAR },
 
	{ 1967, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{ 1973, MAX_YEAR },
 
	{ 1962, MAX_YEAR },
 
	{ 1984, MAX_YEAR },
 
	{ 1984, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{ 1993, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
	{    0, MAX_YEAR },
 
};
 
assert_compile(lengthof(_housetype_years) == HOUSE_MAX);
 

	
 
static const byte _housetype_cargo_passengers[] = {
 
	8, 8, 8, 2, 10,10,4, 6,
 
	6, 2, 2, 2, 2, 8, 6, 6,
 
	6, 10,6, 6, 4, 4, 4, 4,
 
	3, 3, 3, 7, 8, 6, 8, 8,
 
	4, 4, 4, 4, 8, 3, 3, 8,
 
	8, 8, 8, 8, 5, 5, 3, 3,
 
	3, 3, 8, 8, 9, 9,10, 10,
 
	2, 2, 3, 3, 2, 2, 3, 3,
 
	6, 6, 6, 6, 6, 6, 7, 7,
 
	9, 9, 7, 7, 7, 7, 3, 3,
 
	3, 3, 6, 2, 3, 6, 6, 8,
 
	8, 6, 8, 2, 6, 3, 3, 3,
 
	3, 3, 8, 4, 4, 8, 3, 3,
 
	8, 8, 8, 4, 3, 3,
 
};
 
assert_compile(lengthof(_housetype_cargo_passengers) == HOUSE_MAX);
 

	
 
static const byte _housetype_cargo_mail[] = {
 
	 3, 3, 3, 0, 4, 4, 1, 1,
 
	 1, 0, 0, 0, 0, 2, 2, 2,
train_cmd.c
Show inline comments
 
@@ -602,49 +602,49 @@ static int32 CmdBuildRailWagon(EngineID 
 
			v->x_pos = x;
 
			v->y_pos = y;
 
			v->z_pos = GetSlopeZ(x,y);
 
			v->owner = _current_player;
 
			v->z_height = 6;
 
			v->u.rail.track = 0x80;
 
			v->vehstatus = VS_HIDDEN | VS_DEFPAL;
 

	
 
			v->subtype = 0;
 
			SetTrainWagon(v);
 
			if (u != NULL) {
 
				u->next = v;
 
			} else {
 
				SetFreeWagon(v);
 
			}
 

	
 
			v->cargo_type = rvi->cargo_type;
 
			v->cargo_subtype = 0;
 
			v->cargo_cap = rvi->capacity;
 
			v->value = value;
 
//			v->day_counter = 0;
 

	
 
			v->u.rail.railtype = GetEngine(engine)->railtype;
 

	
 
			v->build_year = _cur_year;
 
			v->build_year = _cur_year - BASE_YEAR;
 
			v->type = VEH_Train;
 
			v->cur_image = 0xAC2;
 
			v->random_bits = VehicleRandomBits();
 

	
 
			AddArticulatedParts(vl);
 

	
 
			_new_vehicle_id = v->index;
 

	
 
			VehiclePositionChanged(v);
 
			TrainConsistChanged(GetFirstVehicleInChain(v));
 

	
 
			InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 
			if (IsLocalPlayer()) {
 
				InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Train); // updates the replace Train window
 
			}
 
		}
 
	}
 

	
 
	return value;
 
}
 

	
 
// Move all free vehicles in the depot to the train
 
static void NormalizeTrainVehInDepot(const Vehicle* u)
 
{
 
@@ -762,49 +762,49 @@ int32 CmdBuildRailVehicle(TileIndex tile
 
			v->z_height = 6;
 
			v->u.rail.track = 0x80;
 
			v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
 
			v->spritenum = rvi->image_index;
 
			v->cargo_type = rvi->cargo_type;
 
			v->cargo_subtype = 0;
 
			v->cargo_cap = rvi->capacity;
 
			v->max_speed = rvi->max_speed;
 
			v->value = value;
 
			v->last_station_visited = INVALID_STATION;
 
			v->dest_tile = 0;
 

	
 
			v->engine_type = p1;
 

	
 
			v->reliability = e->reliability;
 
			v->reliability_spd_dec = e->reliability_spd_dec;
 
			v->max_age = e->lifelength * 366;
 

	
 
			v->string_id = STR_SV_TRAIN_NAME;
 
			v->u.rail.railtype = e->railtype;
 
			_new_vehicle_id = v->index;
 

	
 
			v->service_interval = _patches.servint_trains;
 
			v->date_of_last_service = _date;
 
			v->build_year = _cur_year;
 
			v->build_year = _cur_year - BASE_YEAR;
 
			v->type = VEH_Train;
 
			v->cur_image = 0xAC2;
 
			v->random_bits = VehicleRandomBits();
 

	
 
			v->subtype = 0;
 
			SetFrontEngine(v);
 
			SetTrainEngine(v);
 

	
 
			VehiclePositionChanged(v);
 

	
 
			if (rvi->flags & RVI_MULTIHEAD) {
 
				SetMultiheaded(v);
 
				AddRearEngineToMultiheadedTrain(vl[0], vl[1], true);
 
				/* Now we need to link the front and rear engines together
 
				 * other_multiheaded_part is the pointer that links to the other half of the engine
 
				 * vl[0] is the front and vl[1] is the rear
 
				 */
 
				vl[0]->u.rail.other_multiheaded_part = vl[1];
 
				vl[1]->u.rail.other_multiheaded_part = vl[0];
 
			} else {
 
				AddArticulatedParts(vl);
 
			}
 

	
 
			TrainConsistChanged(v);
train_gui.c
Show inline comments
 
@@ -52,49 +52,49 @@ void DrawTrainEnginePurchaseInfo(int x, 
 
	SetDParam(0, (rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8) << multihead);
 
	DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
 
	y += 10;
 

	
 
	/* Powered wagons power - Powered wagons extra weight */
 
	if (rvi->pow_wag_power != 0) {
 
		SetDParam(0, rvi->pow_wag_power);
 
		SetDParam(1, rvi->pow_wag_weight);
 
		DrawString(x,y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, 0);
 
		y += 10;
 
	};
 

	
 
	/* Cargo type + capacity, or N/A */
 
	SetDParam(0, STR_8838_N_A);
 
	SetDParam(2, STR_EMPTY);
 
	if (rvi->capacity != 0) {
 
		SetDParam(0, _cargoc.names_long[rvi->cargo_type]);
 
		SetDParam(1, rvi->capacity << multihead);
 
		SetDParam(2, STR_9842_REFITTABLE);
 
	}
 
	DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0);
 
	y += 10;
 

	
 
	/* Design date - Life length */
 
	SetDParam(0, BASE_YEAR + ymd.year);
 
	SetDParam(0, ymd.year);
 
	SetDParam(1, e->lifelength);
 
	DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
 
	y += 10;
 

	
 
	/* Reliability */
 
	SetDParam(0, e->reliability * 100 >> 16);
 
	DrawString(x,y, STR_PURCHASE_INFO_RELIABILITY, 0);
 
	y += 10;
 

	
 
	/* Additional text from NewGRF */
 
	// XXX 227 will become a calculated width...
 
	y += ShowAdditionalText(x, y, 227, engine_number);
 
}
 

	
 
/**
 
 * Draw the purchase info details of a train wagon at a given location.
 
 * @param x,y location where to draw the info
 
 * @param engine_number the engine of which to draw the info of
 
 */
 
void DrawTrainWagonPurchaseInfo(int x, int y, EngineID engine_number)
 
{
 
	const RailVehicleInfo *rvi = RailVehInfo(engine_number);
 
	bool refittable = (EngInfo(engine_number)->refit_mask != 0);
 

	
tunnelbridge_cmd.c
Show inline comments
 
@@ -26,59 +26,59 @@
 
#include "bridge.h"
 
#include "train.h"
 
#include "water_map.h"
 
#include "yapf/yapf.h"
 
#include "date.h"
 

	
 
#include "table/bridge_land.h"
 

	
 
extern const byte _track_sloped_sprites[14];
 
extern const SpriteID _water_shore_sprites[15];
 

	
 
extern void DrawCanalWater(TileIndex tile);
 

	
 
const Bridge orig_bridge[] = {
 
/*
 
	   year of availablity
 
	   |  minimum length
 
	   |  |   maximum length
 
	   |  |   |    price
 
	   |  |   |    |    maximum speed
 
	   |  |   |    |    |  sprite to use in GUI                string with description
 
	   |  |   |    |    |  |                                   |                            */
 
	{  0, 0, 16,  80,  32, 0xA24                             , STR_5012_WOODEN             , NULL, 0 },
 
	{  0, 0,  2, 112,  48, 0xA26 | PALETTE_TO_STRUCT_RED     , STR_5013_CONCRETE           , NULL, 0 },
 
	{ 10, 0,  5, 144,  64, 0xA25                             , STR_500F_GIRDER_STEEL       , NULL, 0 },
 
	{ 1930, 0,  5, 144,  64, 0xA25                             , STR_500F_GIRDER_STEEL       , NULL, 0 },
 
	{  0, 2, 10, 168,  80, 0xA22 | PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE, NULL, 0 },
 
	{ 10, 3, 16, 185,  96, 0xA22                             , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
 
	{ 10, 3, 16, 192, 112, 0xA22 | PALETTE_TO_STRUCT_YELLOW  , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
 
	{ 10, 3,  7, 224, 160, 0xA23                             , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
 
	{ 10, 3,  8, 232, 208, 0xA23 | PALETTE_TO_STRUCT_BROWN   , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
 
	{ 10, 3,  9, 248, 240, 0xA23 | PALETTE_TO_STRUCT_RED     , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
 
	{ 10, 0,  2, 240, 256, 0xA27                             , STR_500F_GIRDER_STEEL       , NULL, 0 },
 
	{ 75, 2, 16, 255, 320, 0xA28                             , STR_5014_TUBULAR_STEEL      , NULL, 0 },
 
	{ 85, 2, 32, 380, 512, 0xA28 | PALETTE_TO_STRUCT_YELLOW  , STR_5014_TUBULAR_STEEL      , NULL, 0 },
 
	{ 90, 2, 32, 510, 608, 0xA28 | PALETTE_TO_STRUCT_GREY    , STR_BRIDGE_TUBULAR_SILICON  , NULL, 0 }
 
	{ 1930, 3, 16, 185,  96, 0xA22                             , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
 
	{ 1930, 3, 16, 192, 112, 0xA22 | PALETTE_TO_STRUCT_YELLOW  , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
 
	{ 1930, 3,  7, 224, 160, 0xA23                             , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
 
	{ 1930, 3,  8, 232, 208, 0xA23 | PALETTE_TO_STRUCT_BROWN   , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
 
	{ 1930, 3,  9, 248, 240, 0xA23 | PALETTE_TO_STRUCT_RED     , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
 
	{ 1930, 0,  2, 240, 256, 0xA27                             , STR_500F_GIRDER_STEEL       , NULL, 0 },
 
	{ 1995, 2, 16, 255, 320, 0xA28                             , STR_5014_TUBULAR_STEEL      , NULL, 0 },
 
	{ 2005, 2, 32, 380, 512, 0xA28 | PALETTE_TO_STRUCT_YELLOW  , STR_5014_TUBULAR_STEEL      , NULL, 0 },
 
	{ 2010, 2, 32, 510, 608, 0xA28 | PALETTE_TO_STRUCT_GREY    , STR_BRIDGE_TUBULAR_SILICON  , NULL, 0 }
 
};
 

	
 
Bridge _bridge[MAX_BRIDGES];
 

	
 

	
 
// calculate the price factor for building a long bridge.
 
// basically the cost delta is 1,1, 1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5, 6,6,6,6,6,6,  7,7,7,7,7,7,7,  8,8,8,8,8,8,8,8,
 
int CalcBridgeLenCostFactor(int x)
 
{
 
	int n;
 
	int r;
 

	
 
	if (x < 2) return x;
 
	x -= 2;
 
	for (n = 0, r = 2;; n++) {
 
		if (x <= n) return r + x * n;
 
		r += n * n;
 
		x -= n;
 
	}
 
}
 

	
 
#define M(x) (1 << (x))
 
enum {
 
	// foundation, whole tile is leveled up --> 3 corners raised
variables.h
Show inline comments
 
@@ -126,51 +126,51 @@ typedef struct Patches {
 
	UnitID max_roadveh;				//max trucks in game per player
 
	UnitID max_aircraft;			//max planes in game per player
 
	UnitID max_ships;					//max ships in game per player
 

	
 
	bool servint_ispercent;	// service intervals are in percents
 
	uint16 servint_trains;	// service interval for trains
 
	uint16 servint_roadveh;	// service interval for road vehicles
 
	uint16 servint_aircraft;// service interval for aircraft
 
	uint16 servint_ships;		// service interval for ships
 

	
 
	bool autorenew;
 
	int16 autorenew_months;
 
	int32 autorenew_money;
 

	
 
	byte pf_maxdepth;				// maximum recursion depth when searching for a train route for new pathfinder
 
	uint16 pf_maxlength;		// maximum length when searching for a train route for new pathfinder
 

	
 

	
 
	bool bridge_pillars;		// show bridge pillars for high bridges
 

	
 
	bool ai_disable_veh_train;		// disable types for AI
 
	bool ai_disable_veh_roadveh;		// disable types for AI
 
	bool ai_disable_veh_aircraft;		// disable types for AI
 
	bool ai_disable_veh_ship;		// disable types for AI
 
	uint32 starting_year;		// starting date
 
	uint32 ending_year;		// end of the game (just show highscore)
 
	uint32 colored_news_year; // when does newspaper become colored?
 
	Year starting_year;				// starting date
 
	Year ending_year;					// end of the game (just show highscore)
 
	Year colored_news_year;		// when does newspaper become colored?
 

	
 
	bool keep_all_autosave;		// name the autosave in a different way.
 
	bool autosave_on_exit;		// save an autosave when you quit the game, but do not ask "Do you really want to quit?"
 
	byte max_num_autosaves;		// controls how many autosavegames are made before the game starts to overwrite (names them 0 to max_num_autosaves - 1)
 
	bool extra_dynamite;			// extra dynamite
 

	
 
	bool never_expire_vehicles; // never expire vehicles
 
	byte extend_vehicle_life;	// extend vehicle life by this many years
 

	
 
	bool auto_euro;						// automatically switch to euro in 2002
 
	bool serviceathelipad;	// service helicopters at helipads automatically (no need to send to depot)
 
	bool smooth_economy;		// smooth economy
 
	bool allow_shares;			// allow the buying/selling of shares
 
	byte dist_local_authority;		// distance for town local authority, default 20
 

	
 
	byte wait_oneway_signal;	//waitingtime in days before a oneway signal
 
	byte wait_twoway_signal;	//waitingtime in days before a twoway signal
 

	
 
	uint8 map_x; // Size of map
 
	uint8 map_y;
 

	
 
	byte drag_signals_density; // many signals density
 
	bool ainew_active;  // Is the new AI active?
 
	bool ai_in_multiplayer; // Do we allow AIs in multiplayer
0 comments (0 inline, 0 general)