Changeset - r1962:cc4c06e3f6b5
[Not reviewed]
master
0 26 0
celestar - 19 years ago 2005-06-21 16:28:17
celestar@openttd.org
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
26 files changed with 73 insertions and 74 deletions:
0 comments (0 inline, 0 general)
ai_pathfinder.c
Show inline comments
 
@@ -10,13 +10,13 @@
 
#define TEST_STATION_NO_DIR 0xFF
 

	
 
// Tests if a station can be build on the given spot
 
// TODO: make it train compatible
 
static bool TestCanBuildStationHere(uint tile, byte dir)
 
{
 
	Player *p = DEREF_PLAYER(_current_player);
 
	Player *p = GetPlayer(_current_player);
 

	
 
	if (dir == TEST_STATION_NO_DIR) {
 
		int32 ret;
 
		// TODO: currently we only allow spots that can be access from al 4 directions...
 
		//  should be fixed!!!
 
		for (dir = 0; dir < 4; dir++) {
aircraft_gui.c
Show inline comments
 
@@ -939,13 +939,13 @@ static void PlayerAircraftWndProc(Window
 
		// disable 'Sort By' tooltip on Unsorted sorting criteria
 
		if (vl->sort_type == SORT_BY_UNSORTED)
 
			w->disabled_state |= (1 << 3);
 

	
 
		/* draw the widgets */
 
		{
 
			const Player *p = DEREF_PLAYER(owner);
 
			const Player *p = GetPlayer(owner);
 
			if (station == -1) {
 
				/* Company Name -- (###) Aircraft */
 
				SetDParam(0, p->name_1);
 
				SetDParam(1, p->name_2);
 
				SetDParam(2, w->vscroll.count);
 
				w->widget[1].unkA = STR_A009_AIRCRAFT;
command.c
Show inline comments
 
@@ -333,13 +333,13 @@ int32 DoCommand(int x, int y, uint32 p1,
 
	proc = _command_proc_table[procc].proc;
 

	
 
	if (_docommand_recursive == 0) {
 
		_error_message = INVALID_STRING_ID;
 
		// update last build coord of player
 
		if ( (x|y) != 0 && _current_player < MAX_PLAYERS) {
 
			DEREF_PLAYER(_current_player)->last_build_coordinate = TILE_FROM_XY(x,y);
 
			GetPlayer(_current_player)->last_build_coordinate = TILE_FROM_XY(x,y);
 
		}
 
	}
 

	
 
	_docommand_recursive++;
 

	
 
	// only execute the test call if it's toplevel, or we're not execing.
 
@@ -383,13 +383,13 @@ error:
 
}
 

	
 
int32 GetAvailableMoneyForCommand(void)
 
{
 
	PlayerID pid = _current_player;
 
	if (pid >= MAX_PLAYERS) return 0x7FFFFFFF; // max int
 
	return DEREF_PLAYER(pid)->player_money;
 
	return GetPlayer(pid)->player_money;
 
}
 

	
 
// toplevel network safe docommand function for the current player. must not be called recursively.
 
// the callback is called when the command succeeded or failed.
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd)
 
{
 
@@ -494,13 +494,13 @@ bool DoCommandP(TileIndex tile, uint32 p
 
		_cmd_text = NULL;
 
		return true;
 
	}
 
#endif /* ENABLE_NETWORK */
 

	
 
	// update last build coordinate of player.
 
	if ( tile != 0 && _current_player < MAX_PLAYERS) DEREF_PLAYER(_current_player)->last_build_coordinate = tile;
 
	if ( tile != 0 && _current_player < MAX_PLAYERS) GetPlayer(_current_player)->last_build_coordinate = tile;
 

	
 
	/* Actually try and execute the command. If no cost-type is given
 
	 * use the construction one */
 
	_yearly_expenses_type = EXPENSES_CONSTRUCTION;
 
	res2 = proc(x,y, flags|DC_EXEC, p1, p2);
 

	
console_cmds.c
Show inline comments
 
@@ -541,13 +541,13 @@ DEF_CONSOLE_CMD(ConResetCompany)
 
		IConsolePrintF(_icolour_err, "Company does not exist. Company-id must be between 1 and %d.", MAX_PLAYERS);
 
		return true;
 
	}
 

	
 
	/* Check if company does exist */
 
	index--;
 
	p = DEREF_PLAYER(index);
 
	p = GetPlayer(index);
 
	if (!p->is_active) {
 
		IConsoleError("Company does not exist.");
 
		return true;
 
	}
 

	
 
	if (p->is_ai) {
economy.c
Show inline comments
 
@@ -375,13 +375,13 @@ void ChangeOwnershipOfPlayerItems(Player
 
			for (i = 0; i < 4; i++) {
 
				/* 'Sell' the share if this player has any */
 
				if (p->share_owners[i] == _current_player)
 
					p->share_owners[i] = 0xFF;
 
			}
 
		}
 
		p = DEREF_PLAYER(_current_player);
 
		p = GetPlayer(_current_player);
 
		/* Sell all the shares that people have on this company */
 
		for (i = 0; i < 4; i++)
 
			p->share_owners[i] = 0xFF;
 
	}
 

	
 
	_current_player = old;
 
@@ -481,13 +481,13 @@ static void PlayersCheckBankrupt(Player 
 
void DrawNewsBankrupcy(Window *w)
 
{
 
	Player *p;
 

	
 
	DrawNewsBorder(w);
 

	
 
	p = DEREF_PLAYER(WP(w,news_d).ni->string_id & 15);
 
	p = GetPlayer(WP(w,news_d).ni->string_id & 15);
 
	DrawPlayerFace(p->face, p->player_color, 2, 23);
 
	GfxFillRect(3, 23, 3+91, 23+118, 0x4323);
 

	
 
	SetDParam(0, p->president_name_1);
 
	SetDParam(1, p->president_name_2);
 

	
 
@@ -550,13 +550,13 @@ void DrawNewsBankrupcy(Window *w)
 
		NOT_REACHED();
 
	}
 
}
 

	
 
StringID GetNewsStringBankrupcy(NewsItem *ni)
 
{
 
	Player *p = DEREF_PLAYER(ni->string_id & 0xF);
 
	Player *p = GetPlayer(ni->string_id & 0xF);
 

	
 
	switch(ni->string_id >> 4) {
 
	case 1:
 
		SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE);
 
		SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED);
 
		SetDParam(2, p->name_1);
 
@@ -1196,13 +1196,13 @@ static bool CheckSubsidised(Station *fro
 
			s->to = to->index;
 

	
 
			/* Add a news item */
 
			pair = SetupSubsidyDecodeParam(s, 0);
 
			InjectDParam(2);
 

	
 
			p = DEREF_PLAYER(_current_player);
 
			p = GetPlayer(_current_player);
 
			SetDParam(0, p->name_1);
 
			SetDParam(1, p->name_2);
 
			AddNewsItem(
 
				STR_2031_SERVICE_SUBSIDY_AWARDED + _opt.diff.subsidy_multiplier,
 
				NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0),
 
				pair.a, pair.b);
 
@@ -1221,13 +1221,13 @@ static int32 DeliverGoods(int num_pieces
 
	int32 profit;
 

	
 
 	assert(num_pieces > 0);
 

	
 
	// Update player statistics
 
	{
 
		Player *p = DEREF_PLAYER(_current_player);
 
		Player *p = GetPlayer(_current_player);
 
		p->cur_economy.delivered_cargo += num_pieces;
 
		SETBIT(p->cargo_types, cargo_type);
 
	}
 

	
 
	// Get station pointers.
 
	s_from = GetStation(source);
 
@@ -1522,20 +1522,20 @@ static void DoAcquireCompany(Player *p)
 

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

	
 
	if (p->bankrupt_value == 0) {
 
		owner = DEREF_PLAYER(_current_player);
 
		owner = GetPlayer(_current_player);
 
		owner->current_loan += p->current_loan;
 
	}
 

	
 
	value = CalculateCompanyValue(p) >> 2;
 
	for(i=0; i!=4; i++) {
 
		if (p->share_owners[i] != 0xFF) {
 
			owner = DEREF_PLAYER(p->share_owners[i]);
 
			owner = GetPlayer(p->share_owners[i]);
 
			owner->money64 += value;
 
			owner->yearly_expenses[0][EXPENSES_OTHER] += value;
 
			UpdatePlayerMoney32(owner);
 
		}
 
	}
 

	
 
@@ -1558,13 +1558,13 @@ int32 CmdBuyShareInCompany(int x, int y,
 
	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 = DEREF_PLAYER(p1);
 
	p = GetPlayer(p1);
 

	
 
	/* 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;
 
@@ -1603,13 +1603,13 @@ int32 CmdSellShareInCompany(int x, int y
 
	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 = DEREF_PLAYER(p1);
 
	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;
 
@@ -1637,13 +1637,13 @@ int32 CmdBuyCompany(int x, int y, uint32
 
	Player *p;
 

	
 
	/* Disable takeovers in multiplayer games */
 
	if (p1 >= MAX_PLAYERS || _networking) return CMD_ERROR;
 

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

	
 
	if (!p->is_ai) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		DoAcquireCompany(p);
 
	}
engine.c
Show inline comments
 
@@ -751,13 +751,13 @@ StringID GetCustomEngineName(int engine)
 
	return STR_SPEC_USERSTRING;
 
}
 

	
 

	
 
void AcceptEnginePreview(Engine *e, PlayerID player)
 
{
 
	Player *p = DEREF_PLAYER(player);
 
	Player *p = GetPlayer(player);
 

	
 
	SETBIT(e->player_avail, player);
 

	
 
	UPDATE_PLAYER_RAILTYPE(e, p);
 

	
 
	e->preview_player = 0xFF;
graph_gui.c
Show inline comments
 
@@ -901,13 +901,13 @@ static void PerformanceRatingDetailWndPr
 

	
 
		// The player of which we check the detail performance rating
 
		owner = FindFirstBit(w->click_state) - 13;
 

	
 
		// Paint the player icons
 
		for (i=0;i<MAX_PLAYERS;i++) {
 
       		if (!DEREF_PLAYER(i)->is_active) {
 
       		if (!GetPlayer(i)->is_active) {
 
       			// Check if we have the player as an active player
 
       			if (!(w->disabled_state & (1 << (i+13)))) {
 
       				// Bah, player gone :(
 
                   	w->disabled_state += 1 << (i+13);
 
                   	// Is this player selected? If so, select first player (always save? :s)
 
                   	if (w->click_state == 1U << (i + 13))
 
@@ -1021,13 +1021,13 @@ static void PerformanceRatingDetailWndPr
 
    		Player *p2;
 
        	w->hidden_state = 0;
 
        	w->disabled_state = 0;
 

	
 
        	// Hide the player who are not active
 
        	for (i=0;i<MAX_PLAYERS;i++) {
 
        		if (!DEREF_PLAYER(i)->is_active) {
 
        		if (!GetPlayer(i)->is_active) {
 
        			w->disabled_state += 1 << (i+13);
 
        		}
 
        	}
 
        	// Update all player stats with the current data
 
        	//  (this is because _score_info is not saved to a savegame)
 
        	FOR_ALL_PLAYERS(p2)
main_gui.c
Show inline comments
 
@@ -81,13 +81,13 @@ void HandleOnEditText(WindowEvent *e)
 
		if (!_network_server)
 
			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str);
 
		else
 
			NetworkServer_HandleChat(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str, NETWORK_SERVER_INDEX);
 
		break;
 
	case 3: { /* Give money, you can only give money in excess of loan */
 
		const Player *p = DEREF_PLAYER(_current_player);
 
		const Player *p = GetPlayer(_current_player);
 
		int32 money = min(p->money64 - p->current_loan, atoi(e->edittext.str) / GetCurrentCurrencyRate());
 
		char msg[20];
 

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

	
 
		// Give 'id' the money, and substract it from ourself
 
@@ -326,13 +326,13 @@ static void MenuClickShowAir(int index)
 
{
 
	ShowPlayerAircraft(index, -1);
 
}
 

	
 
static void MenuClickBuildRail(int index)
 
{
 
	Player *p = DEREF_PLAYER(_local_player);
 
	Player *p = GetPlayer(_local_player);
 
	_last_built_railtype = min(index, p->max_railtype-1);
 
	ShowBuildRailToolbar(_last_built_railtype, -1);
 
}
 

	
 
static void MenuClickBuildRoad(int index)
 
{
 
@@ -938,13 +938,13 @@ static void ToolbarZoomOutClick(Window *
 
		SndPlayFx(SND_15_BEEP);
 
	}
 
}
 

	
 
static void ToolbarBuildRailClick(Window *w)
 
{
 
	Player *p = DEREF_PLAYER(_local_player);
 
	Player *p = GetPlayer(_local_player);
 
	Window *w2;
 
	w2 = PopupMainToolbMenu(w, 457, 19, STR_1015_RAILROAD_CONSTRUCTION, p->max_railtype);
 
	WP(w2,menu_d).sel_index = _last_built_railtype;
 
}
 

	
 
static void ToolbarBuildRoadClick(Window *w)
 
@@ -2208,13 +2208,13 @@ static bool DrawScrollingStatusText(News
 
}
 

	
 
static void StatusBarWndProc(Window *w, WindowEvent *e)
 
{
 
	switch (e->event) {
 
	case WE_PAINT: {
 
		const Player *p = (_local_player == OWNER_SPECTATOR) ? NULL : DEREF_PLAYER(_local_player);
 
		const Player *p = (_local_player == OWNER_SPECTATOR) ? NULL : GetPlayer(_local_player);
 

	
 
		DrawWindowWidgets(w);
 
		SetDParam(0, _date);
 
		DrawStringCentered(70, 1, ((_pause||_patches.status_long_date)?STR_00AF:STR_00AE), 0);
 

	
 
		if (p != NULL) {
misc_cmd.c
Show inline comments
 
@@ -134,13 +134,13 @@ int32 CmdChangeCompanyName(int x, int y,
 
	if (_cmd_text[0] == '\0') return CMD_ERROR;
 

	
 
	str = AllocateNameUnique(_cmd_text, 4);
 
	if (str == 0) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		p = DEREF_PLAYER(_current_player);
 
		p = GetPlayer(_current_player);
 
		DeleteName(p->name_1);
 
		p->name_1 = str;
 
		MarkWholeScreenDirty();
 
	} else
 
		DeleteName(str);
 

	
 
@@ -160,13 +160,13 @@ int32 CmdChangePresidentName(int x, int 
 
	if (_cmd_text[0] == '\0') return CMD_ERROR;
 

	
 
	str = AllocateNameUnique(_cmd_text, 4);
 
	if (str == 0) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		p = DEREF_PLAYER(_current_player);
 
		p = GetPlayer(_current_player);
 
		DeleteName(p->president_name_1);
 
		p->president_name_1 = str;
 

	
 
		if (p->name_1 == STR_SV_UNNAMED) {
 
			char buf[80];
 

	
 
@@ -223,13 +223,13 @@ int32 CmdMoneyCheat(int x, int y, uint32
 
 * @param x,y unused
 
 * @param p1 the amount of money to transfer; max 20.000.000
 
 * @param p2 the player to transfer the money to
 
 */
 
int32 CmdGiveMoney(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	const Player *p = DEREF_PLAYER(_current_player);
 
	const Player *p = GetPlayer(_current_player);
 
	int32 amount = min((int32)p1, 20000000);
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
 

	
 
	/* You can only transfer funds that is in excess of your loan */
 
	if (p->money64 - p->current_loan < amount || amount <= 0) return CMD_ERROR;
misc_gui.c
Show inline comments
 
@@ -128,15 +128,15 @@ static void Place_LandInfo(uint tile)
 
	WP(w,void_d).data = &lid;
 

	
 
	lid.tile = tile;
 
	lid.town = ClosestTownFromTile(tile, _patches.dist_local_authority);
 

	
 
	if (_local_player >= MAX_PLAYERS)
 
		p = DEREF_PLAYER(0);
 
		p = GetPlayer(0);
 
	else
 
		p = DEREF_PLAYER(_local_player);
 
		p = GetPlayer(_local_player);
 

	
 
	old_money = p->money64;
 
	p->money64 = p->player_money = 0x7fffffff;
 
	lid.costclear = DoCommandByTile(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR);
 
	p->money64 = old_money;
 
	UpdatePlayerMoney32(p);
 
@@ -467,13 +467,13 @@ static void ErrmsgWndProc(Window *w, Win
 
				DrawStringMultiCenter(
 
					120,
 
					30,
 
					_errmsg_message_1,
 
					238);
 
		} else {
 
			Player *p = DEREF_PLAYER(GetDParamX(_errmsg_decode_params,2));
 
			Player *p = GetPlayer(GetDParamX(_errmsg_decode_params,2));
 
			DrawPlayerFace(p->face, p->player_color, 2, 16);
 

	
 
			DrawStringMultiCenter(
 
				214,
 
				(_errmsg_message_1 == INVALID_STRING_ID ? 65 : 45),
 
				_errmsg_message_2,
 
@@ -1198,15 +1198,15 @@ static void MakeSortedSaveGameList(void)
 
static void GenerateFileName(void)
 
{
 
	const Player *p;
 
	/* Check if we are not a specatator who wants to generate a name..
 
	    Let's use the name of player #0 for now. */
 
	if (_local_player < MAX_PLAYERS)
 
		p = DEREF_PLAYER(_local_player);
 
		p = GetPlayer(_local_player);
 
	else
 
		p = DEREF_PLAYER(0);
 
		p = GetPlayer(0);
 

	
 
	SetDParam(0, p->name_1);
 
	SetDParam(1, p->name_2);
 
	SetDParam(2, _date);
 
	GetString(_edit_str_buf, STR_4004);
 
}
network_client.c
Show inline comments
 
@@ -510,13 +510,13 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 
		_opt_ptr = &_opt; // during a network game you are always in-game
 

	
 
		// Say we received the map and loaded it correctly!
 
		SEND_COMMAND(PACKET_CLIENT_MAP_OK)();
 

	
 
		if (_network_playas == 0 || _network_playas > MAX_PLAYERS ||
 
				!DEREF_PLAYER(_network_playas - 1)->is_active) {
 
				!GetPlayer(_network_playas - 1)->is_active) {
 

	
 
			if (_network_playas == OWNER_SPECTATOR) {
 
				// The client wants to be a spectator..
 
				_local_player = OWNER_SPECTATOR;
 
				DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
 
			} else {
 
@@ -629,13 +629,13 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 
				break;
 
			case NETWORK_ACTION_CHAT_PLAYER:
 
			case NETWORK_ACTION_GIVE_MONEY:
 
				/* For speak to player or give money, we need the player-name */
 
				if (ci_to->client_playas > MAX_PLAYERS)
 
					return NETWORK_RECV_STATUS_OKAY; // This should never happen
 
				GetString(name, DEREF_PLAYER(ci_to->client_playas-1)->name_1);
 
				GetString(name, GetPlayer(ci_to->client_playas-1)->name_1);
 
				ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
 
				break;
 
			default:
 
				/* This should never happen */
 
				NOT_REACHED();
 
				break;
network_server.c
Show inline comments
 
@@ -1043,13 +1043,13 @@ void NetworkServer_HandleChat(NetworkAct
 
		if (ci_to == NULL) break;
 

	
 
		// Display the message locally (so you know you have sent it)
 
		if (ci != NULL && show_local) {
 
			if (from_index == NETWORK_SERVER_INDEX) {
 
				char name[NETWORK_NAME_LENGTH];
 
				GetString(name, DEREF_PLAYER(ci_to->client_playas-1)->name_1);
 
				GetString(name, GetPlayer(ci_to->client_playas-1)->name_1);
 
				NetworkTextMessage(action, GetDrawStringPlayerColor(ci_own->client_playas-1), true, name, "%s", msg);
 
			} else {
 
				FOR_ALL_CLIENTS(cs) {
 
					if (cs->index == from_index) {
 
						SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, ci_to->client_index, true, msg);
 
					}
oldloader.c
Show inline comments
 
@@ -807,13 +807,13 @@ static const OldChunks player_yearly_chu
 
	OCL_VAR(  OC_INT32,   1, &_old_yearly ),
 
	OCL_END()
 
};
 
static bool OldPlayerYearly(LoadgameState *ls, int num)
 
{
 
	int i;
 
	Player *p = DEREF_PLAYER(_current_player_id);
 
	Player *p = GetPlayer(_current_player_id);
 

	
 
	for (i = 0; i < 13; i++) {
 
		if (!LoadChunk(ls, NULL, player_yearly_chunk))
 
			return false;
 

	
 
		p->yearly_expenses[num][i] = _old_yearly;
 
@@ -831,13 +831,13 @@ static const OldChunks player_economy_ch
 

	
 
	OCL_END()
 
};
 
static bool OldPlayerEconomy(LoadgameState *ls, int num)
 
{
 
	int i;
 
	Player *p = DEREF_PLAYER(_current_player_id);
 
	Player *p = GetPlayer(_current_player_id);
 

	
 
	if (!LoadChunk(ls, &p->cur_economy, player_economy_chunk))
 
		return false;
 

	
 
	/* Don't ask, but the number in TTD(Patch) are inversed to OpenTTD */
 
	p->cur_economy.income   = -p->cur_economy.income;
 
@@ -869,13 +869,13 @@ static const OldChunks player_ai_build_r
 
	OCL_NULL( 8 ),  // Junk...
 

	
 
	OCL_END()
 
};
 
static bool OldLoadAIBuildRec(LoadgameState *ls, int num)
 
{
 
	Player *p = DEREF_PLAYER(_current_player_id);
 
	Player *p = GetPlayer(_current_player_id);
 

	
 
	switch (num) {
 
		case 0: return LoadChunk(ls, &p->ai.src, player_ai_build_rec_chunk);
 
		case 1: return LoadChunk(ls, &p->ai.dst, player_ai_build_rec_chunk);
 
		case 2: return LoadChunk(ls, &p->ai.mid1, player_ai_build_rec_chunk);
 
		case 3: return LoadChunk(ls, &p->ai.mid2, player_ai_build_rec_chunk);
 
@@ -984,13 +984,13 @@ static const OldChunks player_ai_chunk[]
 
	OCL_SVAR(  OC_UINT8, PlayerAI, route_type_mask ),
 

	
 
	OCL_END()
 
};
 
static bool OldPlayerAI(LoadgameState *ls, int num)
 
{
 
	Player *p = DEREF_PLAYER(_current_player_id);
 
	Player *p = GetPlayer(_current_player_id);
 

	
 
	return LoadChunk(ls, &p->ai, player_ai_chunk);
 
}
 

	
 
static const OldChunks player_chunk[] = {
 
	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
 
@@ -1032,13 +1032,13 @@ static const OldChunks player_chunk[] = 
 
	OCL_NULL( 8 ), // junk at end of chunk
 

	
 
	OCL_END()
 
};
 
static bool LoadOldPlayer(LoadgameState *ls, int num)
 
{
 
	Player *p = DEREF_PLAYER(num);
 
	Player *p = GetPlayer(num);
 

	
 
	_current_player_id = num;
 

	
 
	if (!LoadChunk(ls, p, player_chunk))
 
		return false;
 

	
openttd.c
Show inline comments
 
@@ -1030,13 +1030,13 @@ void StateGameLoop(void)
 

	
 
static void DoAutosave(void)
 
{
 
	char buf[200];
 

	
 
	if (_patches.keep_all_autosave && _local_player != OWNER_SPECTATOR) {
 
		const Player *p = DEREF_PLAYER(_local_player);
 
		const Player *p = GetPlayer(_local_player);
 
		char *s;
 
		sprintf(buf, "%s%s", _path.autosave_dir, PATHSEP);
 

	
 
		SetDParam(0, p->name_1);
 
		SetDParam(1, p->name_2);
 
		SetDParam(2, _date);
player.h
Show inline comments
 
@@ -194,20 +194,19 @@ void AiDoGameLoop(Player *p);
 
void UpdatePlayerMoney32(Player *p);
 
#define FOR_ALL_PLAYERS(p) for(p=_players; p != endof(_players); p++)
 

	
 
#define MAX_PLAYERS 8
 
VARDEF Player _players[MAX_PLAYERS];
 

	
 
#define DEREF_PLAYER(i) (GetPlayer(i))
 
static inline Player* GetPlayer(uint i)
 
{
 
  assert(i < lengthof(_players));
 
  return &_players[i];
 
}
 

	
 
#define IS_HUMAN_PLAYER(p) (!DEREF_PLAYER((byte)(p))->is_ai)
 
#define IS_HUMAN_PLAYER(p) (!GetPlayer((byte)(p))->is_ai)
 
#define IS_INTERACTIVE_PLAYER(p) (((byte)p) == _local_player)
 

	
 
typedef struct HighScore {
 
	char company[100];
 
	StringID title;
 
	uint16 score;
player_gui.c
Show inline comments
 
@@ -141,13 +141,13 @@ static const Widget _player_finances_sma
 

	
 

	
 
static void PlayerFinancesWndProc(Window *w, WindowEvent *e)
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 
		Player *p = DEREF_PLAYER(w->window_number);
 
		Player *p = GetPlayer(w->window_number);
 

	
 
		w->disabled_state = p->current_loan != 0 ? 0 : (1 << 7);
 

	
 
		SetDParam(0, p->name_1);
 
		SetDParam(1, p->name_2);
 
		SetDParam(2, GetPlayerNameString((byte)w->window_number, 3));
 
@@ -316,13 +316,13 @@ static void SelectPlayerFaceWndProc(Wind
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 
		Player *p;
 
		w->click_state = (w->click_state & ~(1<<5|1<<6)) | ((1<<5) << WP(w,facesel_d).gender);
 
		DrawWindowWidgets(w);
 
		p = DEREF_PLAYER(w->window_number);
 
		p = GetPlayer(w->window_number);
 
		DrawPlayerFace(WP(w,facesel_d).face, p->player_color, 2, 16);
 
	} break;
 

	
 
	case WE_CLICK:
 
		switch(e->click.widget) {
 
		case 3: DeleteWindow(w); break;
 
@@ -498,13 +498,13 @@ static void DrawCompanyOwnerText(Player 
 
}
 

	
 
static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 
		Player *p = DEREF_PLAYER(w->window_number);
 
		Player *p = GetPlayer(w->window_number);
 
		uint32 dis = 0;
 

	
 
		if (!IsWindowOfPrototype(w, _other_player_company_widgets)) {
 
			AssignWidgetToWindow(w, (p->location_of_house != 0) ? _my_player_company_bh_widgets : _my_player_company_widgets);
 

	
 
			if (!_networking) SETBIT(w->hidden_state, 11); // hide company-password widget
 
@@ -558,13 +558,13 @@ static void PlayerCompanyWndProc(Window 
 
	case WE_CLICK:
 
		switch(e->click.widget) {
 
		case 3: { /* select face */
 
			Window *wf = AllocateWindowDescFront(&_select_player_face_desc, w->window_number);
 
			if (wf) {
 
				wf->caption_color = w->window_number;
 
				WP(wf,facesel_d).face = DEREF_PLAYER(wf->window_number)->face;
 
				WP(wf,facesel_d).face = GetPlayer(wf->window_number)->face;
 
				WP(wf,facesel_d).gender = 0;
 
			}
 
		} break;
 

	
 
		case 4: {/* change color */
 
			Window *wf = AllocateWindowDescFront(&_select_player_color_desc,w->window_number);
 
@@ -572,27 +572,27 @@ static void PlayerCompanyWndProc(Window 
 
				wf->caption_color = wf->window_number;
 
				wf->vscroll.cap = 8;
 
			}
 
		} break;
 

	
 
		case 5: {/* change president name */
 
			Player *p = DEREF_PLAYER(w->window_number);
 
			Player *p = GetPlayer(w->window_number);
 
			WP(w,def_d).byte_1 = 0;
 
			SetDParam(0, p->president_name_2);
 
			ShowQueryString(p->president_name_1, STR_700B_PRESIDENT_S_NAME, 31, 94, w->window_class, w->window_number);
 
		} break;
 

	
 
		case 6: {/* change company name */
 
			Player *p = DEREF_PLAYER(w->window_number);
 
			Player *p = GetPlayer(w->window_number);
 
			WP(w,def_d).byte_1 = 1;
 
			SetDParam(0, p->name_2);
 
			ShowQueryString(p->name_1, STR_700A_COMPANY_NAME, 31, 150, w->window_class, w->window_number);
 
		} break;
 

	
 
		case 7: {/* build hq */
 
			TileIndex tile = DEREF_PLAYER(w->window_number)->location_of_house;
 
			TileIndex tile = GetPlayer(w->window_number)->location_of_house;
 
			if (tile == 0) {
 
				if ((byte)w->window_number != _local_player)
 
					return;
 
				SetObjectToPlaceWnd(SPR_CURSOR_HQ, 1, w);
 
				SetTileSelectSize(2, 2);
 
			} else {
 
@@ -629,13 +629,13 @@ static void PlayerCompanyWndProc(Window 
 
		if ((++w->vscroll.pos & 0x1F) == 0)
 
			SetWindowDirty(w);
 
		break;
 

	
 
	case WE_PLACE_OBJ: {
 
		/* You cannot destroy a HQ, only relocate it. So build_HQ is called, just with different flags */
 
		TileIndex tile = DEREF_PLAYER(w->window_number)->location_of_house;
 
		TileIndex tile = GetPlayer(w->window_number)->location_of_house;
 
		if (DoCommandP(e->place.tile, (tile == 0) ? 0 : 1 | w->window_number, 0, NULL, CMD_BUILD_COMPANY_HQ | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_7071_CAN_T_BUILD_COMPANY_HEADQUARTERS)))
 
			ResetObjectToPlace();
 
		break;
 
	}
 

	
 

	
 
@@ -697,13 +697,13 @@ void ShowPlayerCompany(int player)
 

	
 

	
 
static void BuyCompanyWndProc(Window *w, WindowEvent *e)
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 
		Player *p = DEREF_PLAYER(w->window_number);
 
		Player *p = GetPlayer(w->window_number);
 
		SetDParam(0, p->name_1);
 
		SetDParam(1, p->name_2);
 
		DrawWindowWidgets(w);
 

	
 
		DrawPlayerFace(p->face, p->player_color, 2, 16);
 

	
 
@@ -776,13 +776,13 @@ extern StringID EndGameGetPerformanceTit
 

	
 
/* End game window shown at the end of the game */
 
static void EndGameWndProc(Window *w, WindowEvent *e)
 
{
 
	switch (e->event) {
 
	case WE_PAINT: {
 
		const Player *p = DEREF_PLAYER(_local_player);
 
		const Player *p = GetPlayer(_local_player);
 
		uint x, y;
 

	
 
		SetupHighScoreEndWindow(w, &x, &y);
 

	
 
		/* We need to get performance from last year because the image is shown
 
		 * at the start of the new year when these things have already been copied */
 
@@ -915,24 +915,24 @@ void ShowEndGameChart(void)
 
	if (w != NULL) {
 
		MarkWholeScreenDirty();
 

	
 
		WP(w, highscore_d).background_img = SPR_TYCOON_IMG1_BEGIN;
 

	
 
		if (_local_player != OWNER_SPECTATOR) {
 
			const Player *p = DEREF_PLAYER(_local_player);
 
			const Player *p = GetPlayer(_local_player);
 
			if (p->old_economy[0].performance_history == SCORE_MAX)
 
				WP(w, highscore_d).background_img = SPR_TYCOON_IMG2_BEGIN;
 
		}
 

	
 
		/* In a network game show the endscores of the custom difficulty 'network' which is the last one
 
		 * as well as generate a TOP5 of that game, and not an all-time top5. */
 
		if (_networking) {
 
			w->window_number = lengthof(_highscore_table) - 1;
 
			WP(w, highscore_d).rank = SaveHighScoreValueNetwork();
 
		} else {
 
			// in single player _local player is always valid
 
			const Player *p = DEREF_PLAYER(_local_player);
 
			const Player *p = GetPlayer(_local_player);
 
			w->window_number = _opt.diff_level;
 
			WP(w, highscore_d).rank = SaveHighScoreValue(p);
 
		}
 
	}
 
}
players.c
Show inline comments
 
@@ -191,13 +191,13 @@ void InvalidatePlayerWindows(Player *p)
 
}
 

	
 
bool CheckPlayerHasMoney(int32 cost)
 
{
 
	if (cost > 0) {
 
		uint pid = _current_player;
 
		if (pid < MAX_PLAYERS && cost > DEREF_PLAYER(pid)->player_money) {
 
		if (pid < MAX_PLAYERS && cost > GetPlayer(pid)->player_money) {
 
			SetDParam(0, cost);
 
			_error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES;
 
			return false;
 
		}
 
	}
 
	return true;
 
@@ -219,18 +219,18 @@ static void SubtractMoneyFromAnyPlayer(P
 
}
 

	
 
void SubtractMoneyFromPlayer(int32 cost)
 
{
 
	PlayerID pid = _current_player;
 
	if (pid < MAX_PLAYERS)
 
		SubtractMoneyFromAnyPlayer(DEREF_PLAYER(pid), cost);
 
		SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
 
}
 

	
 
void SubtractMoneyFromPlayerFract(byte player, int32 cost)
 
{
 
	Player *p = DEREF_PLAYER(player);
 
	Player *p = GetPlayer(player);
 
	byte m = p->player_money_fraction;
 
	p->player_money_fraction = m - (byte)cost;
 
	cost >>= 8;
 
	if (p->player_money_fraction > m)
 
		cost++;
 
	if (cost != 0)
 
@@ -253,13 +253,13 @@ void GetNameOfOwner(byte owner, uint til
 
	SetDParam(2, owner);
 

	
 
	if (owner != OWNER_TOWN) {
 
		if (owner >= 8)
 
			SetDParam(0, STR_0150_SOMEONE);
 
		else {
 
			Player *p = DEREF_PLAYER(owner);
 
			Player *p = GetPlayer(owner);
 
			SetDParam(0, p->name_1);
 
			SetDParam(1, p->name_2);
 
		}
 
	} else {
 
		Town *t = ClosestTownFromTile(tile, (uint)-1);
 
		SetDParam(0, t->townnametype);
 
@@ -541,13 +541,13 @@ void OnTick_Players(void)
 
{
 
	Player *p;
 

	
 
	if (_game_mode == GM_EDITOR)
 
		return;
 

	
 
	p = DEREF_PLAYER(_cur_player_tick_index);
 
	p = GetPlayer(_cur_player_tick_index);
 
	_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS;
 
	if (p->name_1 != 0) GenerateCompanyName(p);
 

	
 
	if (!_networking && _game_mode != GM_MENU && !--_next_competitor_start) {
 
		MaybeStartNewPlayer();
 
	}
 
@@ -597,13 +597,13 @@ void PlayersYearlyLoop(void)
 
			InvalidateWindow(WC_FINANCES, p->index);
 
		}
 
	}
 

	
 
	if (_patches.show_finances && _local_player != OWNER_SPECTATOR) {
 
		ShowPlayerFinances(_local_player);
 
		p = DEREF_PLAYER(_local_player);
 
		p = GetPlayer(_local_player);
 
		if (p->num_valid_stat_ent > 5 && p->old_economy[0].performance_history < p->old_economy[4].performance_history) {
 
			SndPlayFx(SND_01_BAD_YEAR);
 
		} else {
 
			SndPlayFx(SND_00_GOOD_YEAR);
 
		}
 
	}
 
@@ -625,13 +625,13 @@ void DeletePlayerWindows(int pi)
 

	
 
static void DeletePlayerStuff(int pi)
 
{
 
	Player *p;
 

	
 
	DeletePlayerWindows(pi);
 
	p = DEREF_PLAYER(pi);
 
	p = GetPlayer(pi);
 
	DeleteName(p->name_1);
 
	DeleteName(p->president_name_1);
 
	p->name_1 = 0;
 
	p->president_name_1 = 0;
 
}
 

	
 
@@ -732,13 +732,13 @@ int32 CmdPlayerCtrl(int x, int y, uint32
 
		Player *p;
 

	
 
		if (p2 >= MAX_PLAYERS) return CMD_ERROR;
 

	
 
		if (!(flags & DC_EXEC)) return 0;
 

	
 
		p = DEREF_PLAYER(p2);
 
		p = GetPlayer(p2);
 

	
 
		/* Only allow removal of HUMAN companies */
 
		if (IS_HUMAN_PLAYER(p->index)) {
 
			/* Delete any open window of the company */
 
			DeletePlayerWindows(p->index);
 

	
 
@@ -1112,13 +1112,13 @@ static void Save_PLYR(void)
 
}
 

	
 
static void Load_PLYR(void)
 
{
 
	int index;
 
	while ((index = SlIterateArray()) != -1) {
 
		Player *p = DEREF_PLAYER(index);
 
		Player *p = GetPlayer(index);
 
		p->is_ai = (index != 0);
 
		SaveLoad_PLYR(p);
 
		_player_colors[index] = p->player_color;
 
		UpdatePlayerMoney32(p);
 
	}
 
}
roadveh_gui.c
Show inline comments
 
@@ -823,13 +823,13 @@ static void PlayerRoadVehWndProc(Window 
 
		// disable 'Sort By' tooltip on Unsorted sorting criteria
 
		if (vl->sort_type == SORT_BY_UNSORTED)
 
			w->disabled_state |= (1 << 3);
 

	
 
		/* draw the widgets */
 
		{
 
			const Player *p = DEREF_PLAYER(owner);
 
			const Player *p = GetPlayer(owner);
 
			if (station == -1) {
 
				/* Company Name -- (###) Road vehicles */
 
				SetDParam(0, p->name_1);
 
				SetDParam(1, p->name_2);
 
				SetDParam(2, w->vscroll.count);
 
				w->widget[1].unkA = STR_9001_ROAD_VEHICLES;
ship_gui.c
Show inline comments
 
@@ -923,13 +923,13 @@ static void PlayerShipsWndProc(Window *w
 
		// disable 'Sort By' tooltip on Unsorted sorting criteria
 
		if (vl->sort_type == SORT_BY_UNSORTED)
 
			w->disabled_state |= (1 << 3);
 

	
 
		/* draw the widgets */
 
		{
 
			const Player *p = DEREF_PLAYER(owner);
 
			const Player *p = GetPlayer(owner);
 
			if (station == -1) {
 
				/* Company Name -- (###) Trains */
 
				SetDParam(0, p->name_1);
 
				SetDParam(1, p->name_2);
 
				SetDParam(2, w->vscroll.count);
 
				w->widget[1].unkA = STR_9805_SHIPS;
station_gui.c
Show inline comments
 
@@ -151,13 +151,13 @@ static void PlayerStationsWndProc(Window
 
		// 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);
 

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

	
subsidy_gui.c
Show inline comments
 
@@ -109,13 +109,13 @@ static void DrawSubsidiesWindow(Window *
 
	num = 0;
 

	
 
	for(s=_subsidies; s != endof(_subsidies); s++) {
 
		if (s->cargo_type != 0xFF && s->age >= 12) {
 
			SetupSubsidyDecodeParam(s, 1);
 

	
 
			p = DEREF_PLAYER(GetStation(s->to)->owner);
 
			p = GetPlayer(GetStation(s->to)->owner);
 
			SetDParam(3, p->name_1);
 
			SetDParam(4, p->name_2);
 

	
 
			xt = DrawString(x+2, y, STR_202C_FROM_TO, 0);
 

	
 
			SetDParam(0, _date - ymd.day + 768 - s->age * 32);
town_cmd.c
Show inline comments
 
@@ -1553,13 +1553,13 @@ static void TownActionRoadRebuild(Town *
 
	Player *p;
 

	
 
	t->road_build_months = 6;
 

	
 
	SetDParam(0, t->index);
 

	
 
	p = DEREF_PLAYER(_current_player);
 
	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);
 
}
town_gui.c
Show inline comments
 
@@ -49,13 +49,13 @@ uint GetMaskOfTownActions(int *nump, Pla
 
				avail_buttons = 0;
 
			} else if (t->ratings[pid] < 600)
 
				SETBIT(avail_buttons, 7); // only bribe if less than excellent
 
		}
 

	
 
		// Things worth more than this are not shown
 
		avail = DEREF_PLAYER(pid)->player_money + _price.station_value * 200;
 
		avail = GetPlayer(pid)->player_money + _price.station_value * 200;
 
		ref = _price.build_industry >> 8;
 

	
 
		for (i = 0; i != lengthof(_town_action_costs); i++, avail_buttons >>= 1) {
 
			if (HASBIT(avail_buttons, 0) && avail >= _town_action_costs[i] * ref) {
 
				SETBIT(buttons, i);
 
				num++;
train_gui.c
Show inline comments
 
@@ -320,13 +320,13 @@ static void ShowBuildTrainWindow(uint ti
 

	
 
	if (tile != 0) {
 
		w->caption_color = GetTileOwner(tile);
 
		WP(w,buildtrain_d).railtype = _map3_lo[tile] & 0xF;
 
	} else {
 
		w->caption_color = _local_player;
 
		WP(w,buildtrain_d).railtype = DEREF_PLAYER(_local_player)->max_railtype - 1;
 
		WP(w,buildtrain_d).railtype = GetPlayer(_local_player)->max_railtype - 1;
 
	}
 
}
 

	
 
static void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
 
{
 
	int max_x = x + count * 29;
 
@@ -1302,13 +1302,13 @@ static void PlayerTrainsWndProc(Window *
 
		// disable 'Sort By' tooltip on Unsorted sorting criteria
 
		if (vl->sort_type == SORT_BY_UNSORTED)
 
			w->disabled_state |= (1 << 3);
 

	
 
		/* draw the widgets */
 
		{
 
			const Player *p = DEREF_PLAYER(owner);
 
			const Player *p = GetPlayer(owner);
 
			if (station == -1) {
 
				/* Company Name -- (###) Trains */
 
				SetDParam(0, p->name_1);
 
				SetDParam(1, p->name_2);
 
				SetDParam(2, w->vscroll.count);
 
				w->widget[1].unkA = STR_881B_TRAINS;
unmovable_cmd.c
Show inline comments
 
@@ -33,13 +33,13 @@ int32 DestroyCompanyHQ(TileIndex tile, u
 
				dodelete = true;
 
				break;
 
			}
 
		}
 
		if (!dodelete) return CMD_ERROR;
 
	} else /* Destruction was initiated by player */
 
		p = DEREF_PLAYER(_current_player);
 
		p = GetPlayer(_current_player);
 

	
 
		if (p->location_of_house == 0) return CMD_ERROR;
 

	
 
		if (flags & DC_EXEC) {
 
			DoClearSquare(p->location_of_house + TILE_XY(0,0));
 
			DoClearSquare(p->location_of_house + TILE_XY(0,1));
 
@@ -59,13 +59,13 @@ int32 DestroyCompanyHQ(TileIndex tile, u
 
 * @param p2 unused
 
 */
 
 extern int32 CheckFlatLandBelow(uint tile, uint w, uint h, uint flags, uint invalid_dirs, int *);
 
int32 CmdBuildCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TileIndex tile = TILE_FROM_XY(x,y);
 
	Player *p = DEREF_PLAYER(_current_player);
 
	Player *p = GetPlayer(_current_player);
 
	int cost;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
 

	
 
	cost = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL);
 
	if (CmdFailed(cost)) return CMD_ERROR;
vehicle.c
Show inline comments
 
@@ -1412,13 +1412,13 @@ int32 CmdReplaceVehicle(int x, int y, ui
 
			 }
 
		}
 
	}
 

	
 
	/* 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 ( DEREF_PLAYER(v->owner)->money64 < (int32)(autorefit_money + build_cost + rear_engine_cost - v->value)) {
 
	if ( GetPlayer(v->owner)->money64 < (int32)(autorefit_money + build_cost + rear_engine_cost - v->value)) {
 
		if (( _local_player == v->owner ) && ( v->unitnumber != 0 )) {  //v->unitnumber = 0 for train cars
 
			int 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;
0 comments (0 inline, 0 general)