Changeset - r2498:8dfa040ed505
[Not reviewed]
master
0 22 0
tron - 19 years ago 2005-10-07 07:35:15
tron@openttd.org
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
22 files changed with 84 insertions and 85 deletions:
0 comments (0 inline, 0 general)
aircraft_gui.c
Show inline comments
 
@@ -120,65 +120,65 @@ static void NewAircraftWndProc(Window *w
 
		}
 

	
 
		DrawWindowWidgets(w);
 

	
 
		{
 
			int num = NUM_AIRCRAFT_ENGINES;
 
			const Engine* e = GetEngine(AIRCRAFT_ENGINES_INDEX);
 
			int x = 2;
 
			int y = 15;
 
			int sel = WP(w,buildtrain_d).sel_index;
 
			int pos = w->vscroll.pos;
 
			EngineID engine_id = AIRCRAFT_ENGINES_INDEX;
 
			int selected_id = -1;
 
			EngineID selected_id = INVALID_ENGINE;
 

	
 
			do {
 
				if (HASBIT(e->player_avail, _local_player)) {
 
					if (sel==0) selected_id = engine_id;
 
					if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
 
						DrawString(x+62, y+7, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10);
 
						DrawAircraftEngine(x+29, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
 
						y += 24;
 
					}
 
					sel--;
 
				}
 
			} while (++engine_id, ++e,--num);
 

	
 
			WP(w,buildtrain_d).sel_engine = selected_id;
 

	
 
			if (selected_id != -1) {
 
			if (selected_id != INVALID_ENGINE) {
 
				DrawAircraftPurchaseInfo(2, w->widget[4].top + 1, selected_id);
 
			}
 
		}
 
	} break;
 

	
 
	case WE_CLICK:
 
		switch(e->click.widget) {
 
		case 2: { /* listbox */
 
			uint i = (e->click.pt.y - 14) / 24;
 
			if (i < w->vscroll.cap) {
 
				WP(w,buildtrain_d).sel_index = i + w->vscroll.pos;
 
				SetWindowDirty(w);
 
			}
 
		} break;
 

	
 
		case 5: { /* build */
 
			int sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != -1)
 
			EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != INVALID_ENGINE)
 
				DoCommandP(w->window_number, sel_eng, 0, CcBuildAircraft, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
 
		} break;
 

	
 
		case 6:	{ /* rename */
 
			int sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != -1) {
 
			EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != INVALID_ENGINE) {
 
				WP(w,buildtrain_d).rename_engine = sel_eng;
 
				ShowQueryString(GetCustomEngineName(sel_eng),
 
					STR_A039_RENAME_AIRCRAFT_TYPE, 31, 160, w->window_class, w->window_number);
 
			}
 
		} break;
 
		}
 
		break;
 

	
 
	case WE_4:
 
		if (w->window_number != 0 && !FindWindowById(WC_VEHICLE_DEPOT, w->window_number)) {
 
			DeleteWindow(w);
 
		}
economy.c
Show inline comments
 
@@ -1314,25 +1314,25 @@ int LoadUnloadVehicle(Vehicle *v)
 
{
 
	int profit = 0;
 
	int v_profit; //virtual profit for feeder systems
 
	int v_profit_total = 0;
 
	int unloading_time = 20;
 
	Vehicle *u = v;
 
	int result = 0;
 
	uint16 last_visited;
 
	Station *st;
 
	GoodsEntry *ge;
 
	int t;
 
	uint count, cap;
 
	byte old_player;
 
	PlayerID old_player;
 
	bool completely_empty = true;
 

	
 
	assert(v->current_order.type == OT_LOADING);
 

	
 
	v->cur_speed = 0;
 

	
 
	old_player = _current_player;
 
	_current_player = v->owner;
 

	
 
	st = GetStation(last_visited = v->last_station_visited);
 

	
 
	for (; v != NULL; v = v->next) {
 
@@ -1551,26 +1551,26 @@ int32 CmdBuyShareInCompany(int x, int y,
 

	
 
	/* Protect new companies from hostile takeovers */
 
	if (_cur_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;
 
		byte *b = p->share_owners;
 

	
 
		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, (int)p1);
 
@@ -1593,25 +1593,25 @@ int32 CmdSellShareInCompany(int x, int y
 

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

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

	
 
	/* adjust it a little to make it less profitable to sell and buy */
 
	cost = CalculateCompanyValue(p) >> 2;
 
	cost = -(cost - (cost >> 7));
 

	
 
	if (flags & DC_EXEC) {
 
		byte *b = p->share_owners;
 
		PlayerID* b = p->share_owners;
 
		while (*b != _current_player) b++; /* share owners is guaranteed to contain player */
 
		*b = OWNER_SPECTATOR;
 
		InvalidateWindow(WC_COMPANY, (int)p1);
 
	}
 
	return cost;
 
}
 

	
 
/** Buy up another company.
 
 * When a competing company is gone bankrupt you get the chance to purchase
 
 * that company.
 
 * @todo currently this only works for AI players
 
 * @param x,y unused
industry_cmd.c
Show inline comments
 
@@ -1033,25 +1033,25 @@ static void ChopLumberMillTrees(Industry
 
	int dir, a, j;
 

	
 
	if ((_m[tile].m1 & 0x80) == 0)
 
		return;
 

	
 
	/* search outwards as a rectangular spiral */
 
	for(a=1; a!=41; a+=2) {
 
		for(dir=0; dir!=4; dir++) {
 
			j = a;
 
			do {
 
				tile = TILE_MASK(tile);
 
				if (IsTileType(tile, MP_TREES)) {
 
					uint old_player = _current_player;
 
					PlayerID old_player = _current_player;
 
					/* found a tree */
 

	
 
					_current_player = OWNER_NONE;
 
					_industry_sound_ctr = 1;
 
					_industry_sound_tile = tile;
 
					SndPlayTileFx(SND_38_CHAINSAW, tile);
 

	
 
					DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
					SetMapExtraBits(tile, 0);
 

	
 
					i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + 45);
 

	
 
@@ -1653,25 +1653,25 @@ static void PlaceInitialIndustry(byte ty
 
{
 
	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.
 
		num = ScaleByMapSize1D(num);
 
	} else {
 
		num = ScaleByMapSize(num);
 
	}
 

	
 
	if (_opt.diff.number_industries != 0)
 
	{
 
		byte old_player = _current_player;
 
		PlayerID old_player = _current_player;
 
		_current_player = OWNER_NONE;
 
		assert(num > 0);
 

	
 
		do {
 
			int i = 2000;
 
			do {
 
				if (CreateNewIndustry(RandomTile(), type) != NULL)
 
					break;
 
			} while (--i != 0);
 
		} while (--num);
 

	
 
		_current_player = old_player;
 
@@ -1893,25 +1893,25 @@ static void ChangeIndustryProduction(Ind
 
			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;
 
	byte old_player = _current_player;
 
	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)) {
 
		MaybeNewIndustry(Random());
 
	} else if (!_patches.smooth_economy && _total_industries > 0) {
 
		i = GetIndustry(RandomRange(_total_industries));
landscape.c
Show inline comments
 
@@ -371,25 +371,25 @@ void CDECL ModifyTile(TileIndex tile, ui
 
		int x = 0;
 
		if (flags & MP_MAP3LO) x = va_arg(va, int);
 
		_m[tile].m3 = x;
 
	}
 

	
 
	if (flags & (MP_MAP3HI_CLEAR | MP_MAP3HI)) {
 
		int x = 0;
 
		if (flags & MP_MAP3HI) x = va_arg(va, int);
 
		_m[tile].m4 = x;
 
	}
 

	
 
	if (flags & (MP_MAPOWNER|MP_MAPOWNER_CURRENT)) {
 
		byte x = _current_player;
 
		PlayerID x = _current_player;
 
		if (flags & MP_MAPOWNER) x = va_arg(va, int);
 
		_m[tile].m1 = x;
 
	}
 

	
 
	if (flags & MP_MAP5) {
 
		_m[tile].m5 = va_arg(va, int);
 
	}
 

	
 
	va_end(va);
 

	
 
	if (!(flags & MP_NODIRTY))
 
		MarkTileDirtyByTile(tile);
misc_gui.c
Show inline comments
 
@@ -574,37 +574,37 @@ void ShowErrorMessage(StringID msg_1, St
 
			pt.x = (_screen.width - 334) >> 1;
 
			pt.y = (_screen.height - 137) >> 1;
 
		}
 
		w = AllocateWindow(pt.x, pt.y, 334, 137, ErrmsgWndProc, WC_ERRMSG, _errmsg_face_widgets);
 
	}
 

	
 
	w->desc_flags = WDF_STD_BTN | WDF_DEF_WIDGET;
 
}
 

	
 

	
 
void ShowEstimatedCostOrIncome(int32 cost, int x, int y)
 
{
 
	int msg = STR_0805_ESTIMATED_COST;
 
	StringID msg = STR_0805_ESTIMATED_COST;
 

	
 
	if (cost < 0) {
 
		cost = -cost;
 
		msg = STR_0807_ESTIMATED_INCOME;
 
	}
 
	SetDParam(0, cost);
 
	ShowErrorMessage(-1, msg, x, y);
 
	ShowErrorMessage(INVALID_STRING_ID, msg, x, y);
 
}
 

	
 
void ShowCostOrIncomeAnimation(int x, int y, int z, int32 cost)
 
{
 
	int msg;
 
	StringID msg;
 
	Point pt = RemapCoords(x,y,z);
 

	
 
	msg = STR_0801_COST;
 
	if (cost < 0) {
 
		cost = -cost;
 
		msg = STR_0803_INCOME;
 
	}
 
	SetDParam(0, cost);
 
	AddTextEffect(msg, pt.x, pt.y, 0x250);
 
}
 

	
 
void ShowFeederIncomeAnimation(int x, int y, int z, int32 cost)
 
@@ -703,25 +703,25 @@ static void DrawStationCoverageText(cons
 
		b = InlineString(b, STR_00D0_NOTHING);
 
		*b++ = '\0';
 
	} else {
 
		b[-2] = '\0';
 
	}
 

	
 
	DrawStringMultiLine(str_x, str_y, STR_SPEC_USERSTRING, 144);
 
}
 

	
 
void DrawStationCoverageAreaText(int sx, int sy, uint mask, int rad) {
 
	int x = _thd.pos.x;
 
	int y = _thd.pos.y;
 
	uint accepts[NUM_CARGO];
 
	AcceptedCargo accepts;
 
	if (x != -1) {
 
		GetAcceptanceAroundTiles(accepts, TileVirtXY(x, y), _thd.size.x / 16, _thd.size.y / 16 , rad);
 
		DrawStationCoverageText(accepts, sx, sy, mask);
 
	}
 
}
 

	
 
void CheckRedrawStationCoverage(Window *w)
 
{
 
	if (_thd.dirty&1) {
 
		_thd.dirty&=~1;
 
		SetWindowDirty(w);
 
	}
network_data.h
Show inline comments
 
@@ -26,25 +26,25 @@
 

	
 
typedef uint16 PacketSize;
 

	
 
typedef struct Packet {
 
	struct Packet *next;
 
	PacketSize size;
 
	PacketSize pos;
 
	byte buffer[SEND_MTU];
 
} Packet;
 

	
 
typedef struct CommandPacket {
 
	struct CommandPacket *next;
 
	byte player;   /// player that is executing the command (PlayerID)
 
	PlayerID player; /// player that is executing the command
 
	uint32 cmd;    /// command being executed
 
	uint32 p1;     /// parameter p1
 
	uint32 p2;     /// parameter p2
 
	TileIndex tile; /// tile command being executed on
 
	char text[80];
 
	uint32 frame;  /// the frame in which this packet is executed
 
	byte callback; /// any callback function executed upon successful completion of the command
 
} CommandPacket;
 

	
 
typedef enum {
 
	STATUS_INACTIVE,
 
	STATUS_AUTH, // This means that the client is authorized
news_gui.c
Show inline comments
 
@@ -364,25 +364,25 @@ static inline void SetNewsDisplayValue(b
 
{
 
	assert(item < 10 && val <= 2);
 
	item *= 2;
 
	CLRBIT(_news_display_opt, item);
 
	CLRBIT(_news_display_opt, item + 1);
 
	_news_display_opt |= val << item;
 
}
 

	
 
// open up an own newspaper window for the news item
 
static void ShowNewspaper(NewsItem *ni)
 
{
 
	Window *w;
 
	int sound;
 
	SoundFx sound;
 
	int top;
 
	ni->flags &= ~(NF_NOEXPIRE | NF_FORCE_BIG);
 
	ni->duration = 555;
 

	
 
	sound = _news_sounds[ni->type];
 
	if (sound != 0)
 
		SndPlayFx(sound);
 

	
 
	top = _screen.height;
 
	switch (ni->display_mode) {
 
		case NM_NORMAL:
 
		case NM_CALLBACK: {
oldloader.c
Show inline comments
 
@@ -780,25 +780,25 @@ static bool LoadOldIndustry(LoadgameStat
 

	
 
	i = GetIndustry(num);
 
	if (!LoadChunk(ls, i, industry_chunk))
 
		return false;
 

	
 
	if (i->xy != 0) {
 
		i->town = GetTown(REMAP_TOWN_IDX(_old_town_index));
 
	}
 

	
 
	return true;
 
}
 

	
 
static uint _current_player_id;
 
static PlayerID _current_player_id;
 
static uint16 _old_inaugurated_year;
 
static int32 _old_yearly;
 

	
 
static const OldChunks player_yearly_chunk[] = {
 
	OCL_VAR(  OC_INT32,   1, &_old_yearly ),
 
	OCL_END()
 
};
 
static bool OldPlayerYearly(LoadgameState *ls, int num)
 
{
 
	int i;
 
	Player *p = GetPlayer(_current_player_id);
 

	
openttd.c
Show inline comments
 
@@ -858,25 +858,25 @@ void StateGameLoop(void)
 
		if ((uint)_frame_counter >= _savedump_last) exit(1);
 
	}
 

	
 
	if (_game_mode == GM_EDITOR) {
 
		RunTileLoop();
 
		CallVehicleTicks();
 
		CallLandscapeTick();
 
		CallWindowTickEvent();
 
		NewsLoop();
 
	} else {
 
		// All these actions has to be done from OWNER_NONE
 
		//  for multiplayer compatibility
 
		uint p = _current_player;
 
		PlayerID p = _current_player;
 
		_current_player = OWNER_NONE;
 

	
 
		AnimateAnimatedTiles();
 
		IncreaseDate();
 
		RunTileLoop();
 
		CallVehicleTicks();
 
		CallLandscapeTick();
 

	
 
		AI_RunGameLoop();
 

	
 
		CallWindowTickEvent();
 
		NewsLoop();
player_gui.c
Show inline comments
 
@@ -682,25 +682,25 @@ static const WindowDesc _my_player_compa
 

	
 
static const WindowDesc _other_player_company_desc = {
 
	-1,-1, 360, 170,
 
	WC_COMPANY,0,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
 
	_other_player_company_widgets,
 
	PlayerCompanyWndProc
 
};
 

	
 
void ShowPlayerCompany(PlayerID player)
 
{
 
	Window *w;
 
	w = AllocateWindowDescFront((byte)player == _local_player ? &_my_player_company_desc : &_other_player_company_desc,  player);
 
	w = AllocateWindowDescFront(player == _local_player ? &_my_player_company_desc : &_other_player_company_desc,  player);
 
	if (w)
 
		w->caption_color = w->window_number;
 
}
 

	
 

	
 

	
 
static void BuyCompanyWndProc(Window *w, WindowEvent *e)
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 
		Player *p = GetPlayer(w->window_number);
 
		SetDParam(0, p->name_1);
players.c
Show inline comments
 
@@ -187,25 +187,25 @@ void DrawPlayerFace(uint32 face, int col
 

	
 
void InvalidatePlayerWindows(const Player *p)
 
{
 
	PlayerID pid = p->index;
 

	
 
	if (pid == _local_player) InvalidateWindow(WC_STATUS_BAR, 0);
 
	InvalidateWindow(WC_FINANCES, pid);
 
}
 

	
 
bool CheckPlayerHasMoney(int32 cost)
 
{
 
	if (cost > 0) {
 
		uint pid = _current_player;
 
		PlayerID pid = _current_player;
 
		if (pid < MAX_PLAYERS && cost > GetPlayer(pid)->player_money) {
 
			SetDParam(0, cost);
 
			_error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES;
 
			return false;
 
		}
 
	}
 
	return true;
 
}
 

	
 
static void SubtractMoneyFromAnyPlayer(Player *p, int32 cost)
 
{
 
	p->money64 -= cost;
 
@@ -275,25 +275,25 @@ bool CheckOwnership(PlayerID owner)
 
{
 
	assert(owner <= OWNER_WATER);
 

	
 
	if (owner == _current_player)
 
		return true;
 
	_error_message = STR_013B_OWNED_BY;
 
	GetNameOfOwner(owner, 0);
 
	return false;
 
}
 

	
 
bool CheckTileOwnership(TileIndex tile)
 
{
 
	byte owner = GetTileOwner(tile);
 
	PlayerID owner = GetTileOwner(tile);
 

	
 
	assert(owner <= OWNER_WATER);
 

	
 
	if (owner == _current_player)
 
		return true;
 
	_error_message = STR_013B_OWNED_BY;
 

	
 
	// no need to get the name of the owner unless we're the local player (saves some time)
 
	if (IsLocalPlayer()) GetNameOfOwner(owner, tile);
 
	return false;
 
}
 

	
roadveh_gui.c
Show inline comments
 
@@ -403,40 +403,40 @@ static void DrawNewRoadVehWindow(Window 
 
	}
 

	
 
	DrawWindowWidgets(w);
 

	
 
	{
 
		int num = NUM_ROAD_ENGINES;
 
		const Engine* e = GetEngine(ROAD_ENGINES_INDEX);
 
		int x = 1;
 
		int y = 15;
 
		int sel = WP(w,buildtrain_d).sel_index;
 
		int pos = w->vscroll.pos;
 
		EngineID engine_id = ROAD_ENGINES_INDEX;
 
		int selected_id = -1;
 
		EngineID selected_id = INVALID_ENGINE;
 

	
 
		do {
 
			if (HASBIT(e->player_avail, _local_player)) {
 
				if (sel==0) selected_id = engine_id;
 
				if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
 
					DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10);
 
					DrawRoadVehEngine(x+29, y+6, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
 
					y += 14;
 
				}
 
				sel--;
 
			}
 
		} while (++engine_id, ++e,--num);
 

	
 
		WP(w,buildtrain_d).sel_engine = selected_id;
 
		if (selected_id != -1) {
 
		if (selected_id != INVALID_ENGINE) {
 
			DrawRoadVehPurchaseInfo(2, w->widget[4].top + 1, selected_id);
 
		}
 
	}
 
}
 

	
 
void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 

	
 
	if (!success) return;
 

	
 
	v = GetVehicle(_new_roadveh_id);
 
@@ -456,32 +456,32 @@ static void NewRoadVehWndProc(Window *w,
 

	
 
	case WE_CLICK:
 
		switch(e->click.widget) {
 
		case 2: { /* listbox */
 
			uint i = (e->click.pt.y - 14) / 14;
 
			if (i < w->vscroll.cap) {
 
				WP(w,buildtrain_d).sel_index = i + w->vscroll.pos;
 
				SetWindowDirty(w);
 
			}
 
		} break;
 

	
 
		case 5: { /* build */
 
			int sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != -1)
 
			EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != INVALID_ENGINE)
 
				DoCommandP(w->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
 
		} break;
 

	
 
		case 6: { /* rename */
 
			int sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != -1) {
 
			EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != INVALID_ENGINE) {
 
				WP(w,buildtrain_d).rename_engine = sel_eng;
 
				ShowQueryString(GetCustomEngineName(sel_eng),
 
					STR_9036_RENAME_ROAD_VEHICLE_TYPE, 31, 160, w->window_class, w->window_number);
 
			}
 
		}	break;
 
		}
 
		break;
 

	
 
	case WE_4:
 
		if (w->window_number != 0 && !FindWindowById(WC_VEHICLE_DEPOT, w->window_number)) {
 
			DeleteWindow(w);
 
		}
ship_gui.c
Show inline comments
 
@@ -343,64 +343,64 @@ static void NewShipWndProc(Window *w, Wi
 
		}
 

	
 
		DrawWindowWidgets(w);
 

	
 
		{
 
			int num = NUM_SHIP_ENGINES;
 
			const Engine* e = GetEngine(SHIP_ENGINES_INDEX);
 
			int x = 2;
 
			int y = 15;
 
			int sel = WP(w,buildtrain_d).sel_index;
 
			int pos = w->vscroll.pos;
 
			EngineID engine_id = SHIP_ENGINES_INDEX;
 
			int selected_id = -1;
 
			EngineID selected_id = INVALID_ENGINE;
 

	
 
			do {
 
				if (HASBIT(e->player_avail, _local_player)) {
 
					if (sel==0) selected_id = engine_id;
 
					if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
 
						DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10);
 
						DrawShipEngine(x+35, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
 
						y += 24;
 
					}
 
					sel--;
 
				}
 
			} while (++engine_id, ++e,--num);
 

	
 
			WP(w,buildtrain_d).sel_engine = selected_id;
 

	
 
			if (selected_id != -1) {
 
			if (selected_id != INVALID_ENGINE) {
 
				DrawShipPurchaseInfo(2, w->widget[4].top + 1, selected_id);
 
			}
 
		}
 
		break;
 

	
 
	case WE_CLICK:
 
		switch(e->click.widget) {
 
		case 2: { /* listbox */
 
			uint i = (e->click.pt.y - 14) / 24;
 
			if (i < w->vscroll.cap) {
 
				WP(w,buildtrain_d).sel_index = i + w->vscroll.pos;
 
				SetWindowDirty(w);
 
			}
 
		} break;
 
		case 5: { /* build */
 
			int sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != -1)
 
			EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != INVALID_ENGINE)
 
				DoCommandP(w->window_number, sel_eng, 0, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
 
		} break;
 

	
 
		case 6:	{ /* rename */
 
			int sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != -1) {
 
			EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != INVALID_ENGINE) {
 
				WP(w,buildtrain_d).rename_engine = sel_eng;
 
				ShowQueryString(GetCustomEngineName(sel_eng),
 
					STR_9838_RENAME_SHIP_TYPE, 31, 160, w->window_class, w->window_number);
 
			}
 
		}	break;
 
		}
 
		break;
 

	
 
	case WE_4:
 
		if (w->window_number != 0 && !FindWindowById(WC_VEHICLE_DEPOT, w->window_number)) {
 
			DeleteWindow(w);
 
		}
signs.h
Show inline comments
 
@@ -2,25 +2,25 @@
 

	
 
#ifndef SIGNS_H
 
#define SIGNS_H
 

	
 
#include "pool.h"
 

	
 
typedef struct SignStruct {
 
	StringID     str;
 
	ViewportSign sign;
 
	int32        x;
 
	int32        y;
 
	byte         z;
 
	byte owner; // placed by this player. Anyone can delete them though.
 
	PlayerID owner; // placed by this player. Anyone can delete them though.
 
							// OWNER_NONE for gray signs from old games.
 

	
 
	uint16       index;
 
} SignStruct;
 

	
 
extern MemoryPool _sign_pool;
 

	
 
/**
 
 * Check if a Sign really exists.
 
 */
 
static inline bool IsValidSign(const SignStruct* ss)
 
{
station.h
Show inline comments
 
@@ -114,29 +114,29 @@ enum {
 
	CA_BUS = 3,
 
	CA_TRUCK = 3,
 
	CA_AIR_OILPAD = 3,
 
	CA_TRAIN = 4,
 
	CA_AIR_HELIPORT = 4,
 
	CA_AIR_SMALL = 4,
 
	CA_AIR_LARGE = 5,
 
	CA_DOCK = 5,
 
	CA_AIR_METRO = 6,
 
	CA_AIR_INTER = 8,
 
};
 

	
 
void ModifyStationRatingAround(TileIndex tile, byte owner, int amount, uint radius);
 
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius);
 

	
 
TileIndex GetStationTileForVehicle(const Vehicle *v, const Station *st);
 

	
 
void ShowStationViewWindow(int station);
 
void ShowStationViewWindow(StationID station);
 
void UpdateAllStationVirtCoord(void);
 

	
 
VARDEF SortStruct *_station_sort;
 

	
 
extern MemoryPool _station_pool;
 

	
 
/**
 
 * Get the pointer to the station with index 'index'
 
 */
 
static inline Station *GetStation(StationID index)
 
{
 
	return (Station*)GetItemFromPool(&_station_pool, index);
station_cmd.c
Show inline comments
 
@@ -170,47 +170,46 @@ static byte FindCatchmentRadius(Station 
 
			case AT_HELIPORT:      ret = max(ret, CA_AIR_HELIPORT); break;
 
			case AT_LARGE:         ret = max(ret, CA_AIR_LARGE);    break;
 
			case AT_METROPOLITAN:  ret = max(ret, CA_AIR_METRO);    break;
 
			case AT_INTERNATIONAL: ret = max(ret, CA_AIR_INTER);    break;
 
		}
 
	}
 

	
 
	return ret;
 
}
 

	
 
#define CHECK_STATIONS_ERR ((Station*)-1)
 

	
 
static Station *GetStationAround(TileIndex tile, int w, int h, int closest_station)
 
static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest_station)
 
{
 
	// check around to see if there's any stations there
 
	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
 
		if (IsTileType(tile_cur, MP_STATION)) {
 
			int t;
 
			t = _m[tile_cur].m2;
 
			StationID t = _m[tile_cur].m2;
 
			{
 
				Station *st = GetStation(t);
 
				// you cannot take control of an oilrig!!
 
				if (st->airport_type == AT_OILRIG && st->facilities == (FACIL_AIRPORT|FACIL_DOCK))
 
					continue;
 
			}
 

	
 
			if (closest_station == -1) {
 
			if (closest_station == INVALID_STATION) {
 
				closest_station = t;
 
			} else if (closest_station != t) {
 
				_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING;
 
				return CHECK_STATIONS_ERR;
 
			}
 
		}
 
	END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
 
	return (closest_station == -1) ? NULL : GetStation(closest_station);
 
	return (closest_station == INVALID_STATION) ? NULL : GetStation(closest_station);
 
}
 

	
 
TileIndex GetStationTileForVehicle(const Vehicle *v, const Station *st)
 
{
 
	switch (v->type) {
 
		case VEH_Train: 		return st->train_tile;
 
		case VEH_Aircraft:	return st->airport_tile;
 
		case VEH_Ship:			return st->dock_tile;
 
		case VEH_Road:
 
			if (v->cargo_type == CT_PASSENGERS) {
 
				if (st->bus_stops != NULL)
 
					return st->bus_stops->xy;
 
@@ -415,25 +414,25 @@ static bool GenerateStationName(Station 
 
	if (tmp == 0) {
 
		_error_message = STR_3007_TOO_MANY_STATIONS_LOADING;
 
		return false;
 
	}
 
	found = FindFirstBit(tmp);
 

	
 
done:
 
	st->string_id = found + STR_SV_STNAME;
 
	return true;
 
}
 
#undef M
 

	
 
static Station *GetClosestStationFromTile(TileIndex tile, uint threshold, byte owner)
 
static Station* GetClosestStationFromTile(TileIndex tile, uint threshold, PlayerID owner)
 
{
 
	Station* best_station = NULL;
 
	Station* st;
 

	
 
	FOR_ALL_STATIONS(st) {
 
		if (st->xy != 0 && (owner == OWNER_SPECTATOR || st->owner == owner)) {
 
			uint cur_dist = DistanceManhattan(tile, st->xy);
 

	
 
			if (cur_dist < threshold) {
 
				threshold = cur_dist;
 
				best_station = st;
 
			}
 
@@ -746,25 +745,25 @@ static void UpdateStationAcceptance(Stat
 
// deleted after a little while.
 
static void DeleteStationIfEmpty(Station *st) {
 
	if (st->facilities == 0) {
 
		st->delete_ctr = 0;
 
		InvalidateWindow(WC_STATION_LIST, st->owner);
 
	}
 
}
 

	
 
static int32 ClearTile_Station(TileIndex tile, byte flags);
 

	
 
// Tries to clear the given area. Returns the cost in case of success.
 
// Or an error code if it failed.
 
int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, int *station)
 
int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station)
 
{
 
	int32 cost = 0, ret;
 

	
 
	uint tileh;
 
	uint z;
 
	int allowed_z = -1;
 
	int flat_z;
 

	
 
	BEGIN_TILE_LOOP(tile_cur, w, h, tile)
 
		if (!EnsureNoVehicle(tile_cur))
 
			return CMD_ERROR;
 

	
 
@@ -801,35 +800,35 @@ int32 CheckFlatLandBelow(TileIndex tile,
 
		}
 

	
 
		// get corresponding flat level and make sure that all parts of the station have the same level.
 
		if (allowed_z == -1) {
 
			// first tile
 
			allowed_z = flat_z;
 
		} else if (allowed_z != flat_z) {
 
			_error_message = STR_0007_FLAT_LAND_REQUIRED;
 
			return CMD_ERROR;
 
		}
 

	
 
		// if station is set, then we have special handling to allow building on top of already existing stations.
 
		// so station points to -1 if we can build on any station. or it points to a station if we're only allowed to build
 
		// so station points to INVALID_STATION if we can build on any station. or it points to a station if we're only allowed to build
 
		// on exactly that station.
 
		if (station != NULL && IsTileType(tile_cur, MP_STATION)) {
 
			if (_m[tile_cur].m5 >= 8) {
 
				_error_message = ClearTile_Station(tile_cur, DC_AUTO); // get error message
 
				return CMD_ERROR;
 
			} else {
 
				int st = _m[tile_cur].m2;
 
				if (*station == -1)
 
				StationID st = _m[tile_cur].m2;
 
				if (*station == INVALID_STATION) {
 
					*station = st;
 
				else if (*station != st) {
 
				} else if (*station != st) {
 
					_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING;
 
					return CMD_ERROR;
 
				}
 
			}
 
		} else {
 
			ret = DoCommandByTile(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			if (ret == CMD_ERROR) return CMD_ERROR;
 
			cost += ret;
 
		}
 
	END_TILE_LOOP(tile_cur, w, h, tile)
 

	
 
	return cost;
 
@@ -943,25 +942,25 @@ static void GetStationLayout(byte *layou
 
 * - p1 = (bit 16-23) - platform length
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 3) - railtype (p2 & 0xF)
 
 * - p2 = (bit  4)    - set for custom station (p2 & 0x10)
 
 * - p2 = (bit  8-..) - custom station id (p2 >> 8)
 
 */
 
int32 CmdBuildRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Station *st;
 
	TileIndex tile_org;
 
	int w_org, h_org;
 
	int32 cost, ret;
 
	int est;
 
	StationID est;
 
	int plat_len, numtracks;
 
	int direction;
 
	uint finalvalues[3];
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	tile_org = TileVirtXY(x, y);
 

	
 
	/* Does the authority allow this? */
 
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR;
 
	if (!ValParamRailtype(p2 & 0xF)) return CMD_ERROR;
 

	
 
@@ -977,25 +976,25 @@ int32 CmdBuildRailroadStation(int x, int
 
		w_org = plat_len;
 
		h_org = numtracks;
 
	}
 

	
 
	if (h_org > _patches.station_spread || w_org > _patches.station_spread) return CMD_ERROR;
 

	
 
	// these values are those that will be stored in train_tile and station_platforms
 
	finalvalues[0] = tile_org;
 
	finalvalues[1] = w_org;
 
	finalvalues[2] = h_org;
 

	
 
	// Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station)
 
	est = -1;
 
	est = INVALID_STATION;
 
	// If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug
 
	//  for detail info, see: https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365
 
	if (CmdFailed(ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags&~DC_EXEC, 5 << direction, _patches.nonuniform_stations ? &est : NULL))) return CMD_ERROR;
 
	cost = ret + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len;
 

	
 
	// Make sure there are no similar stations around us.
 
	st = GetStationAround(tile_org, w_org, h_org, est);
 
	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
 

	
 
	// See if there is a deleted station close to us.
 
	if (st == NULL) {
 
		st = GetClosestStationFromTile(tile_org, 8, _current_player);
 
@@ -1181,26 +1180,27 @@ int32 CmdRemoveFromRailroadStation(int x
 
		if (st->train_tile == 0) {
 
			st->facilities &= ~FACIL_TRAIN;
 
			UpdateStationVirtCoordDirty(st);
 
			DeleteStationIfEmpty(st);
 
		}
 
	}
 
	return _price.remove_rail_station;
 
}
 

	
 
// determine the number of platforms for the station
 
uint GetStationPlatforms(const Station *st, TileIndex tile)
 
{
 
	uint t;
 
	int dir,delta;
 
	TileIndex t;
 
	TileIndexDiff delta;
 
	int dir;
 
	int len;
 
	assert(TileBelongsToRailStation(st, tile));
 

	
 
	len = 0;
 
	dir = _m[tile].m5&1;
 
	delta = dir ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 

	
 
	// find starting tile..
 
	t = tile;
 
	do { t -= delta; len++; } while (TileBelongsToRailStation(st, t) && (_m[t].m5&1) == dir);
 

	
 
	// find ending tile
 
@@ -2128,25 +2128,25 @@ extern uint16 _custom_sprites_base;
 
static void DrawTile_Station(TileInfo *ti)
 
{
 
	uint32 image_or_modificator;
 
	uint32 image;
 
	const DrawTileSeqStruct *dtss;
 
	const DrawTileSprites *t = NULL;
 
	byte railtype = GB(_m[ti->tile].m3, 0, 4);
 
	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
 
	SpriteID offset;
 
	uint32 relocation = 0;
 

	
 
	{
 
		uint owner = GetTileOwner(ti->tile);
 
		PlayerID owner = GetTileOwner(ti->tile);
 
		image_or_modificator = PALETTE_TO_GREY; /* NOTE: possible bug in ttd here? */
 
		if (owner < MAX_PLAYERS)
 
			image_or_modificator = PLAYER_SPRITE_COLOR(owner);
 
	}
 

	
 
	// don't show foundation for docks (docks are between 76 (0x4C) and 81 (0x51))
 
	if (ti->tileh != 0 && (ti->map5 < 0x4C || ti->map5 > 0x51))
 
		DrawFoundation(ti, ti->tileh);
 

	
 
	if (_m[ti->tile].m3 & 0x10) {
 
		// look for customization
 
		StationSpec *statspec = GetCustomStation(STAT_CLASS_DFLT, _m[ti->tile].m4);
 
@@ -2671,25 +2671,25 @@ void OnTick_Station(void)
 
	FOR_ALL_STATIONS(st) {
 
		if (st->xy != 0)
 
			StationHandleSmallTick(st);
 
	}
 

	
 
}
 

	
 
void StationMonthlyLoop(void)
 
{
 
}
 

	
 

	
 
void ModifyStationRatingAround(TileIndex tile, byte owner, int amount, uint radius)
 
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius)
 
{
 
	Station *st;
 
	GoodsEntry *ge;
 
	int i;
 

	
 
	FOR_ALL_STATIONS(st) {
 
		if (st->xy != 0 && st->owner == owner &&
 
				DistanceManhattan(tile, st->xy) <= radius) {
 
			ge = st->goods;
 
			for(i=0; i!=NUM_CARGO; i++,ge++) {
 
				if (ge->enroute_from != INVALID_STATION) {
 
					ge->rating = clamp(ge->rating + amount, 0, 255);
station_gui.c
Show inline comments
 
@@ -103,93 +103,93 @@ static void GlobalSortStationList(void)
 
	// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2
 
	for (i = &_num_station_sort[1]; i != endof(_num_station_sort); i++) {*i += *(i-1);}
 

	
 
	qsort(_station_sort, n, sizeof(_station_sort[0]), GeneralOwnerSorter); // sort by owner
 

	
 
	// since indexes are messed up after adding/removing a station, mark all lists dirty
 
	memset(_station_sort_dirty, true, sizeof(_station_sort_dirty));
 
	_global_station_sort_dirty = false;
 

	
 
	DEBUG(misc, 1) ("Resorting global station list...");
 
}
 

	
 
static void MakeSortedStationList(byte owner)
 
static void MakeSortedStationList(PlayerID owner)
 
{
 
	SortStruct *firstelement;
 
	uint32 n = 0;
 

	
 
	if (owner == 0) { // first element starts at 0th element and has n elements as described above
 
		firstelement = &_station_sort[0];
 
		n = _num_station_sort[0];
 
	} else { // nth element starts at the end of the previous one, and has n elements as described above
 
		firstelement = &_station_sort[_num_station_sort[owner - 1]];
 
		n = _num_station_sort[owner] - _num_station_sort[owner - 1];
 
	}
 

	
 
	_last_station_idx = 0; // used for "cache" in namesorting
 
	qsort(firstelement, n, sizeof(_station_sort[0]), StationNameSorter); // sort by name
 

	
 
	_station_sort_dirty[owner] = false;
 

	
 
	DEBUG(misc, 1) ("Resorting Stations list player %d...", owner+1);
 
}
 

	
 
static void PlayerStationsWndProc(Window *w, WindowEvent *e)
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 
		const PlayerID owner = w->window_number;
 
		uint32 i;
 
		const byte window_number = (byte)w->window_number;
 

	
 
		// resort station window if stations have been added/removed
 
		if (_global_station_sort_dirty)
 
			GlobalSortStationList();
 

	
 
		if (_station_sort_dirty[window_number]) { // resort in case of a station rename.
 
			MakeSortedStationList(window_number);
 
		if (_station_sort_dirty[owner]) { // resort in case of a station rename.
 
			MakeSortedStationList(owner);
 
		}
 

	
 
		// stations are stored as a cummulative index, eg 25, 41, 43. This means
 
		// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 stations
 
		i = (window_number == 0) ? 0 : _num_station_sort[window_number-1];
 
		SetVScrollCount(w, _num_station_sort[window_number] - i);
 
		i = (owner == 0) ? 0 : _num_station_sort[owner - 1];
 
		SetVScrollCount(w, _num_station_sort[owner] - i);
 

	
 
		/* draw widgets, with player's name in the caption */
 
		{
 
			Player *p = GetPlayer(window_number);
 
			const Player* p = GetPlayer(owner);
 
			SetDParam(0, p->name_1);
 
			SetDParam(1, p->name_2);
 
			SetDParam(2, w->vscroll.count);
 
			DrawWindowWidgets(w);
 
		}
 

	
 
		{
 
			byte p = 0;
 
			Station *st;
 
			int x,xb = 2;
 
			int y = 16; // offset from top of widget
 
			int j;
 

	
 
			if (w->vscroll.count == 0) { // player has no stations
 
				DrawString(xb, y, STR_304A_NONE, 0);
 
				return;
 
			}
 

	
 
			i += w->vscroll.pos; // offset from sorted station list of current player
 
			assert(i < _num_station_sort[window_number]); // at least one station must exist
 
			assert(i < _num_station_sort[owner]); // at least one station must exist
 

	
 
			while (i < _num_station_sort[window_number]) { // do until max number of stations of owner
 
			while (i < _num_station_sort[owner]) { // do until max number of stations of owner
 
				st = GetStation(_station_sort[i].index);
 

	
 
				assert(st->xy && st->owner == window_number);
 
				assert(st->xy && st->owner == owner);
 

	
 
				SetDParam(0, st->index);
 
				SetDParam(1, st->facilities);
 
				x = DrawString(xb, y, STR_3049_0, 0) + 5;
 

	
 
				// show cargo waiting and station ratings
 
				for(j=0; j!=NUM_CARGO; j++) {
 
					int acc = (st->goods[j].waiting_acceptance & 0xFFF);
 
					if (acc != 0) {
 
						StationsWndShowStationRating(x, y, j, acc, st->goods[j].rating);
 
						x += 10;
 
					}
 
@@ -201,25 +201,25 @@ static void PlayerStationsWndProc(Window
 
		}
 
	} break;
 
	case WE_CLICK: {
 
		switch(e->click.widget) {
 
		case 3: {
 
			uint32 id_v = (e->click.pt.y - 15) / 10;
 

	
 
			if (id_v >= w->vscroll.cap) { return;} // click out of bounds
 

	
 
			id_v += w->vscroll.pos;
 

	
 
			{
 
				const byte owner = (byte)w->window_number;
 
				const PlayerID owner = w->window_number;
 
				Station *st;
 
				id_v += (owner == 0) ? 0 : _num_station_sort[owner - 1]; // first element in list
 

	
 
				if (id_v >= _num_station_sort[owner]) { return;} // click out of station bound
 

	
 
				st = GetStation(_station_sort[id_v].index);
 

	
 
				assert(st->xy && st->owner == owner);
 

	
 
				ScrollMainWindowToTile(st->xy);
 
			}
 
		} break;
 
@@ -307,29 +307,29 @@ static const Widget _station_view_widget
 
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   235,   248,    98,   109, STR_SHIP, STR_SCHEDULED_SHIPS_TIP },
 
{   WIDGETS_END},
 
};
 

	
 
static void DrawStationViewWindow(Window *w)
 
{
 
	Station *st;
 
	int i;
 
	int num;
 
	int x,y;
 
	int pos;
 
	StringID str;
 
	uint16 station_id;
 
	StationID station_id;
 

	
 
	station_id = w->window_number;
 

	
 
	st = GetStation(w->window_number);
 
	st = GetStation(station_id);
 

	
 
	num = 1;
 
	for(i=0; i!=NUM_CARGO; i++) {
 
		if ((st->goods[i].waiting_acceptance & 0xFFF) != 0) {
 
			num++;
 
			if (st->goods[i].enroute_from != station_id)
 
				num++;
 
		}
 
	}
 
	SetVScrollCount(w, num);
 

	
 
	w->disabled_state = st->owner == _local_player ? 0 : (1 << 9);
 
@@ -524,25 +524,25 @@ static void StationViewWndProc(Window *w
 
	}
 
}
 

	
 

	
 
static const WindowDesc _station_view_desc = {
 
	-1, -1, 249, 110,
 
	WC_STATION_VIEW,0,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
 
	_station_view_widgets,
 
	StationViewWndProc
 
};
 

	
 
void ShowStationViewWindow(int station)
 
void ShowStationViewWindow(StationID station)
 
{
 
	Window *w;
 
	byte color;
 

	
 
	w = AllocateWindowDescFront(&_station_view_desc, station);
 
	if (w) {
 
		color = GetStation(w->window_number)->owner;
 
		if (color != 0x10)
 
			w->caption_color = color;
 
		w->vscroll.cap = 5;
 
	}
 
}
town.h
Show inline comments
 
@@ -23,25 +23,25 @@ struct Town {
 
	// Makes sure we don't build certain house types twice.
 
	byte flags12;
 

	
 
	// Which players have a statue?
 
	byte statues;
 

	
 
	// Sort index in listings
 
	byte sort_index_obsolete;
 

	
 
	// Player ratings as well as a mask that determines which players have a rating.
 
	byte have_ratings;
 
	uint8 unwanted[MAX_PLAYERS]; // how many months companies aren't wanted by towns (bribe)
 
	uint8 exclusivity;	     // which player has exslusivity
 
	PlayerID exclusivity;        // which player has exslusivity
 
	uint8 exclusive_counter;     // months till the exclusivity expires
 
	int16 ratings[MAX_PLAYERS];
 

	
 
	// Maximum amount of passengers and mail that can be transported.
 
	uint32 max_pass;
 
	uint32 max_mail;
 
	uint32 new_max_pass;
 
	uint32 new_max_mail;
 
	uint32 act_pass;
 
	uint32 act_mail;
 
	uint32 new_act_pass;
 
	uint32 new_act_mail;
town_cmd.c
Show inline comments
 
@@ -773,25 +773,25 @@ static int GenRandomRoadBits(void)
 
	uint b = GB(r, 8, 2);
 
	if (a == b) b ^= 2;
 
	return (1 << a) + (1 << b);
 
}
 

	
 
// Grow the town
 
// Returns true if a house was built, or no if the build failed.
 
bool GrowTown(Town *t)
 
{
 
	TileIndex tile;
 
	const TileIndexDiffC *ptr;
 
	TileInfo ti;
 
	byte old_player;
 
	PlayerID old_player;
 

	
 
	static const TileIndexDiffC _town_coord_mod[] = {
 
		{-1,  0},
 
		{ 1,  1},
 
		{ 1, -1},
 
		{-1, -1},
 
		{-1,  0},
 
		{ 0,  2},
 
		{ 2,  0},
 
		{ 0, -2},
 
		{-1, -1},
 
		{-2,  2},
 
@@ -1569,25 +1569,25 @@ static void TownActionRoadRebuild(Town *
 

	
 
	p = GetPlayer(_current_player);
 
	SetDParam(1, p->name_1);
 
	SetDParam(2, p->name_2);
 

	
 
	AddNewsItem(STR_2055_TRAFFIC_CHAOS_IN_ROAD_REBUILDING,
 
		NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_GENERAL, 0), t->xy, 0);
 
}
 

	
 
static bool DoBuildStatueOfCompany(TileIndex tile)
 
{
 
	TileInfo ti;
 
	byte old;
 
	PlayerID old;
 
	int32 r;
 

	
 
	FindLandscapeHeightByTile(&ti, tile);
 
	if (ti.tileh != 0)
 
		return false;
 

	
 
	if (ti.type != MP_HOUSE && ti.type != MP_CLEAR && ti.type != MP_TREES)
 
		return false;
 

	
 

	
 
	old = _current_player;
 
	_current_player = OWNER_NONE;
train_gui.c
Show inline comments
 
@@ -164,25 +164,25 @@ void CcBuildLoco(bool success, TileIndex
 
void CcCloneTrain(bool success, uint tile, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 

	
 
	if (!success)
 
		return;
 

	
 
	v = GetVehicle(_new_train_id);
 
	ShowTrainViewWindow(v);
 
}
 

	
 
static void engine_drawing_loop(int *x, int *y, int *pos, int *sel,
 
	int *selected_id, byte railtype, byte show_max, bool is_engine)
 
	EngineID* selected_id, byte railtype, byte show_max, bool is_engine)
 
{
 
	EngineID i;
 

	
 
	for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
 
		const Engine *e = GetEngine(i);
 
		const RailVehicleInfo *rvi = RailVehInfo(i);
 

	
 
		if (!IsCompatibleRail(railtype, e->railtype) || !(rvi->flags & RVI_WAGON) != is_engine ||
 
				!HASBIT(e->player_avail, _local_player))
 
			continue;
 

	
 
		if (*sel == 0)
 
@@ -220,68 +220,67 @@ static void NewRailVehicleWndProc(Window
 
			SetVScrollCount(w, count);
 
		}
 

	
 
		SetDParam(0, WP(w,buildtrain_d).railtype + STR_881C_NEW_RAIL_VEHICLES);
 
		DrawWindowWidgets(w);
 

	
 
		{
 
			byte railtype = WP(w,buildtrain_d).railtype;
 
			int sel = WP(w,buildtrain_d).sel_index;
 
			int pos = w->vscroll.pos;
 
			int x = 1;
 
			int y = 15;
 
			int selected_id = -1;
 
			EngineID selected_id = INVALID_ENGINE;
 

	
 
			/* Ensure that custom engines which substituted wagons
 
			 * are sorted correctly.
 
			 * XXX - DO NOT EVER DO THIS EVER AGAIN! GRRR hacking in wagons as
 
			 * engines to get more types.. Stays here until we have our own format
 
			 * then it is exit!!! */
 
			engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, w->vscroll.cap, true); // True engines
 
			engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, w->vscroll.cap, false); // Feeble wagons
 

	
 
			WP(w,buildtrain_d).sel_engine = selected_id;
 

	
 
			if (selected_id != -1) {
 
			if (selected_id != INVALID_ENGINE) {
 
				const RailVehicleInfo *rvi = RailVehInfo(selected_id);
 

	
 
				if (!(rvi->flags & RVI_WAGON)) {
 
					/* it's an engine */
 
					DrawTrainEnginePurchaseInfo(2, w->widget[4].top + 1,selected_id);
 
				} else {
 
					/* it's a wagon */
 
					DrawTrainWagonPurchaseInfo(2, w->widget[4].top + 1, selected_id);
 
				}
 
			}
 
		}
 
	break;
 

	
 
	case WE_CLICK: {
 
		switch(e->click.widget) {
 
		case 2: {
 
			uint i = (e->click.pt.y - 14) / 14;
 
			if (i < w->vscroll.cap) {
 
				WP(w,buildtrain_d).sel_index = i + w->vscroll.pos;
 
				SetWindowDirty(w);
 
			}
 
		} break;
 
		case 5: {
 
			int sel_eng;
 
			sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != -1)
 
			EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != INVALID_ENGINE)
 
				DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->flags & RVI_WAGON) ? CcBuildWagon : CcBuildLoco, CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
 
		}	break;
 
		case 6: { /* rename */
 
			int sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != -1) {
 
			EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
 
			if (sel_eng != INVALID_ENGINE) {
 
				WP(w,buildtrain_d).rename_engine = sel_eng;
 
				ShowQueryString(GetCustomEngineName(sel_eng),
 
					STR_886A_RENAME_TRAIN_VEHICLE_TYPE, 31, 160, w->window_class, w->window_number);
 
			}
 
		} break;
 
		}
 
	} break;
 

	
 
	case WE_4:
 
		if (w->window_number != 0 && !FindWindowById(WC_VEHICLE_DEPOT, w->window_number)) {
 
			DeleteWindow(w);
 
		}
vehicle.c
Show inline comments
 
@@ -325,25 +325,25 @@ void UpdateVehiclePosHash(Vehicle *v, in
 
	int old_y = v->top_coord;
 
	Vehicle *u;
 

	
 
	new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x,y)];
 
	old_hash = (old_x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(old_x, old_y)];
 

	
 
	if (old_hash == new_hash)
 
		return;
 

	
 
	/* remove from hash table? */
 
	if (old_hash != NULL) {
 
		Vehicle *last = NULL;
 
		int idx = *old_hash;
 
		VehicleID idx = *old_hash;
 
		while ((u = GetVehicle(idx)) != v) {
 
			idx = u->next_hash;
 
			assert(idx != INVALID_VEHICLE);
 
			last = u;
 
		}
 

	
 
		if (last == NULL)
 
			*old_hash = v->next_hash;
 
		else
 
			last->next_hash = v->next_hash;
 
	}
 

	
 
@@ -1449,25 +1449,25 @@ int32 ReplaceVehicle(Vehicle *v)
 
					if ( u->engine_type == old_engine_type && RailVehInfo(old_engine_type)->flags & RVI_MULTIHEAD) {
 
						if (v->next != NULL) rear_engine_cost = -(int32)u->value;
 
					}
 
				}
 
			 }
 
		}
 
	}
 

	
 
	/* Check if there is money for the upgrade.. if not, give a nice news-item
 
	    (that is needed, because this CMD is called automaticly) */
 
	if ( p->money64 < (int32)(p->engine_renew_money + build_cost + rear_engine_cost - v->value)) {
 
		if (( _local_player == v->owner ) && ( v->unitnumber != 0 )) {  //v->unitnumber = 0 for train cars
 
			int message;
 
			StringID message;
 
			SetDParam(0, v->unitnumber);
 
			switch (v->type) {
 
				case VEH_Train:    message = STR_TRAIN_AUTORENEW_FAILED;       break;
 
				case VEH_Road:     message = STR_ROADVEHICLE_AUTORENEW_FAILED; break;
 
				case VEH_Ship:     message = STR_SHIP_AUTORENEW_FAILED;        break;
 
				case VEH_Aircraft: message = STR_AIRCRAFT_AUTORENEW_FAILED;    break;
 
				// This should never happen
 
				default: message = 0; break;
 
			}
 

	
 
			AddNewsItem(message, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0);
 
		}
window.h
Show inline comments
 
@@ -343,26 +343,26 @@ typedef struct {
 
	byte refresh_counter; /* follow_vehicle */
 
} plstations_d;
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(plstations_d));
 

	
 
typedef struct {
 
	StringID string_id;
 
} tooltips_d;
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tooltips_d));
 

	
 
typedef struct {
 
	byte railtype;
 
	byte sel_index;
 
	int16 sel_engine;
 
	int16 rename_engine;
 
	EngineID sel_engine;
 
	EngineID rename_engine;
 
} buildtrain_d;
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(buildtrain_d));
 

	
 
typedef struct {
 
	byte vehicletype;
 
	byte sel_index[2];
 
	int16 sel_engine[2];
 
	uint16 count[2];
 
} replaceveh_d;
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(replaceveh_d));
 

	
 
typedef struct {
0 comments (0 inline, 0 general)