Changeset - r4850:7a78073de588
[Not reviewed]
master
0 15 0
Darkvater - 18 years ago 2006-10-14 22:31:18
darkvater@openttd.org
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
actual playable player (< MAX_PLAYERS) or not.
15 files changed with 49 insertions and 48 deletions:
0 comments (0 inline, 0 general)
ai/ai.c
Show inline comments
 
@@ -210,13 +210,13 @@ void AI_RunGameLoop(void)
 

	
 
/**
 
 * A new AI sees the day of light. You can do here what ever you think is needed.
 
 */
 
void AI_StartNewAI(PlayerID player)
 
{
 
	assert(player < MAX_PLAYERS);
 
	assert(IsValidPlayer(player));
 

	
 
	/* Called if a new AI is booted */
 
	_ai_player[player].active = true;
 
}
 

	
 
/**
command.c
Show inline comments
 
@@ -380,25 +380,25 @@ error:
 
	}
 

	
 
	// if toplevel, subtract the money.
 
	if (--_docommand_recursive == 0) {
 
		SubtractMoneyFromPlayer(res);
 
		// XXX - Old AI hack which doesn't use DoCommandDP; update last build coord of player
 
		if (tile != 0 && _current_player < MAX_PLAYERS) {
 
		if (tile != 0 && IsValidPlayer(_current_player)) {
 
			GetPlayer(_current_player)->last_build_coordinate = tile;
 
		}
 
	}
 

	
 
	_cmd_text = NULL;
 
	return res;
 
}
 

	
 
int32 GetAvailableMoneyForCommand(void)
 
{
 
	PlayerID pid = _current_player;
 
	if (pid >= MAX_PLAYERS) return 0x7FFFFFFF; // max int
 
	if (!IsValidPlayer(pid)) return 0x7FFFFFFF; // max int
 
	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)
 
@@ -505,13 +505,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) {
 
	if (tile != 0 && IsValidPlayer(_current_player)) {
 
		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;
console_cmds.c
Show inline comments
 
@@ -1287,18 +1287,18 @@ DEF_CONSOLE_HOOK(ConHookRconPW)
 
}
 

	
 
/* Also use from within player_gui to change the password graphically */
 
bool NetworkChangeCompanyPassword(byte argc, char *argv[])
 
{
 
	if (argc == 0) {
 
		if (_local_player >= MAX_PLAYERS) return true; // dedicated server
 
		if (!IsValidPlayer(_local_player)) return true; // dedicated server
 
		IConsolePrintF(_icolour_warn, "Current value for 'company_pw': %s", _network_player_info[_local_player].password);
 
		return true;
 
	}
 

	
 
	if (_local_player >= MAX_PLAYERS) {
 
	if (!IsValidPlayer(_local_player)) {
 
		IConsoleError("You have to own a company to make use of this command.");
 
		return false;
 
	}
 

	
 
	if (argc != 1) return false;
 

	
economy.c
Show inline comments
 
@@ -1540,13 +1540,13 @@ extern int GetAmountOwnedBy(Player *p, b
 
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;
 
	if (!IsValidPlayer((PlayerID)p1) || !_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);
 
@@ -1585,13 +1585,13 @@ int32 CmdBuyShareInCompany(TileIndex til
 
int32 CmdSellShareInCompany(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;
 
	if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares) return CMD_ERROR;
 

	
 
	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;
 
@@ -1619,13 +1619,13 @@ int32 CmdSellShareInCompany(TileIndex ti
 
 */
 
int32 CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Player *p;
 

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

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

	
 
	if (!p->is_ai) return CMD_ERROR;
 

	
misc_cmd.c
Show inline comments
 
@@ -288,13 +288,13 @@ int32 CmdGiveMoney(TileIndex tile, uint3
 
	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;
 
	if (!_networking || p2 >= MAX_PLAYERS) return CMD_ERROR;
 
	if (!_networking || !IsValidPlayer((PlayerID)p2)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		/* Add money to player */
 
		PlayerID old_cp = _current_player;
 
		_current_player = p2;
 
		SubtractMoneyFromPlayer(-amount);
misc_gui.c
Show inline comments
 
@@ -152,13 +152,13 @@ static void Place_LandInfo(TileIndex til
 
	w = AllocateWindowDesc(&_land_info_desc);
 
	WP(w,void_d).data = &lid;
 

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

	
 
	p = GetPlayer(_local_player < MAX_PLAYERS ? _local_player : 0);
 
	p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : 0);
 

	
 
	old_money = p->money64;
 
	p->money64 = p->player_money = 0x7fffffff;
 
	lid.costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR);
 
	p->money64 = old_money;
 
	UpdatePlayerMoney32(p);
 
@@ -1303,13 +1303,13 @@ static void MakeSortedSaveGameList(void)
 
}
 

	
 
static void GenerateFileName(void)
 
{
 
	/* Check if we are not a specatator who wants to generate a name..
 
	    Let's use the name of player #0 for now. */
 
	const Player *p = GetPlayer(_local_player < MAX_PLAYERS ? _local_player : 0);
 
	const Player *p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : 0);
 

	
 
	SetDParam(0, p->name_1);
 
	SetDParam(1, p->name_2);
 
	SetDParam(2, _date);
 
	GetString(_edit_str_buf, STR_4004);
 
}
 
@@ -1633,15 +1633,15 @@ static int32 ClickMoneyCheat(int32 p1, i
 
		return true;
 
}
 

	
 
// p1 player to set to, p2 is -1 or +1 (down/up)
 
static int32 ClickChangePlayerCheat(int32 p1, int32 p2)
 
{
 
	while (p1 >= 0 && p1 < MAX_PLAYERS) {
 
	while (IsValidPlayer((PlayerID)p1)) {
 
		if (_players[p1].is_active) {
 
			_local_player = p1;
 
			_local_player = (PlayerID)p1;
 
			MarkWholeScreenDirty();
 
			return _local_player;
 
		}
 
		p1 += p2;
 
	}
 

	
network_server.c
Show inline comments
 
@@ -1229,13 +1229,13 @@ void NetworkPopulateCompanyInfo(void)
 
		_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;
 
		if (!IsValidPlayer(v->owner)) continue;
 
		switch (v->type) {
 
			case VEH_Train:
 
				if (IsFrontEngine(v)) {
 
					_network_player_info[v->owner].num_vehicle[0]++;
 
				}
 
				break;
 
@@ -1263,13 +1263,13 @@ void NetworkPopulateCompanyInfo(void)
 
				break;
 
		}
 
	}
 

	
 
	// Go through all stations and count the types of stations
 
	FOR_ALL_STATIONS(s) {
 
		if (s->owner < MAX_PLAYERS) {
 
		if (IsValidPlayer(s->owner)) {
 
			NetworkPlayerInfo* npi = &_network_player_info[s->owner];
 

	
 
			if (s->facilities & FACIL_TRAIN)      npi->num_station[0]++;
 
			if (s->facilities & FACIL_TRUCK_STOP) npi->num_station[1]++;
 
			if (s->facilities & FACIL_BUS_STOP)   npi->num_station[2]++;
 
			if (s->facilities & FACIL_AIRPORT)    npi->num_station[3]++;
openttd.c
Show inline comments
 
@@ -1254,13 +1254,13 @@ bool AfterLoadGame(void)
 
		FOR_ALL_PLAYERS(p) {
 
			p->engine_renew_list = NULL;
 
			p->engine_renew = false;
 
			p->engine_renew_months = -6;
 
			p->engine_renew_money = 100000;
 
		}
 
		if (_local_player < MAX_PLAYERS) {
 
		if (IsValidPlayer(_local_player)) {
 
			// Set the human controlled player to the patch settings
 
			// Scenario editor do not have any companies
 
			p = GetPlayer(_local_player);
 
			p->engine_renew = _patches.autorenew;
 
			p->engine_renew_months = _patches.autorenew_months;
 
			p->engine_renew_money = _patches.autorenew_money;
player.h
Show inline comments
 
@@ -242,12 +242,17 @@ static inline Player* GetPlayer(PlayerID
 

	
 
static inline bool IsLocalPlayer(void)
 
{
 
	return _local_player == _current_player;
 
}
 

	
 
static inline bool IsValidPlayer(PlayerID pi)
 
{
 
	return pi < MAX_PLAYERS;
 
}
 

	
 
void DeletePlayerWindows(PlayerID pi);
 
byte GetPlayerRailtypes(PlayerID p);
 

	
 
/** Finds out if a Player has a certain railtype available */
 
static inline bool HasRailtypeAvail(const Player *p, RailType Railtype)
 
{
players.c
Show inline comments
 
@@ -201,13 +201,13 @@ void InvalidatePlayerWindows(const Playe
 
}
 

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

	
 
void SubtractMoneyFromPlayer(int32 cost)
 
{
 
	PlayerID pid = _current_player;
 

	
 
	if (pid < MAX_PLAYERS) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
 
	if (IsValidPlayer(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
 
}
 

	
 
void SubtractMoneyFromPlayerFract(PlayerID player, int32 cost)
 
{
 
	Player *p = GetPlayer(player);
 
	byte m = p->player_money_fraction;
 
@@ -261,13 +261,13 @@ void UpdatePlayerMoney32(Player *p)
 

	
 
void GetNameOfOwner(Owner owner, TileIndex tile)
 
{
 
	SetDParam(2, owner);
 

	
 
	if (owner != OWNER_TOWN) {
 
		if (owner >= MAX_PLAYERS) {
 
		if (!IsValidPlayer(owner)) {
 
			SetDParam(0, STR_0150_SOMEONE);
 
		} else {
 
			const Player* p = GetPlayer(owner);
 

	
 
			SetDParam(0, p->name_1);
 
			SetDParam(1, p->name_2);
 
@@ -581,13 +581,13 @@ void OnTick_Players(void)
 
		MaybeStartNewPlayer();
 
}
 

	
 
// index is the next parameter in _decode_parameters to set up
 
StringID GetPlayerNameString(PlayerID player, uint index)
 
{
 
	if (IsHumanPlayer(player) && player < MAX_PLAYERS) {
 
	if (IsHumanPlayer(player) && IsValidPlayer(player)) {
 
		SetDParam(index, player+1);
 
		return STR_7002_PLAYER;
 
	}
 
	return STR_EMPTY;
 
}
 

	
 
@@ -688,14 +688,13 @@ static void DeletePlayerStuff(PlayerID p
 
 * if p1 = 5, then
 
 * - p2 = enable renew_keep_length
 
 */
 
int32 CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Player *p;
 
	if (!(_current_player < MAX_PLAYERS))
 
		return CMD_ERROR;
 
	if (!IsValidPlayer(_current_player)) return CMD_ERROR;
 

	
 
	p = GetPlayer(_current_player);
 
	switch (GB(p1, 0, 3)) {
 
		case 0:
 
			if (p->engine_renew == (bool)GB(p2, 0, 1))
 
				return CMD_ERROR;
 
@@ -821,13 +820,13 @@ int32 CmdPlayerCtrl(TileIndex tile, uint
 

	
 
	switch (p1) {
 
	case 0: { /* Create a new player */
 
		Player *p;
 
		PlayerID pid = p2;
 

	
 
		if (!(flags & DC_EXEC) || pid >= MAX_PLAYERS) return 0;
 
		if (!(flags & DC_EXEC) || !IsValidPlayer(pid)) return 0;
 

	
 
		p = DoStartupNewPlayer(false);
 

	
 
#ifdef ENABLE_NETWORK
 
		if (_networking && !_network_server && _local_player == PLAYER_SPECTATOR) {
 
			/* In case we are a client joining a server... */
 
@@ -907,13 +906,13 @@ int32 CmdPlayerCtrl(TileIndex tile, uint
 
		DoStartupNewPlayer(true);
 
		break;
 

	
 
	case 2: { /* Delete a player */
 
		Player *p;
 

	
 
		if (p2 >= MAX_PLAYERS) return CMD_ERROR;
 
		if (!IsValidPlayer(p2)) return CMD_ERROR;
 

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

	
 
		p = GetPlayer(p2);
 

	
 
		/* Only allow removal of HUMAN companies */
 
@@ -935,13 +934,13 @@ int32 CmdPlayerCtrl(TileIndex tile, uint
 
	} break;
 

	
 
	case 3: { /* Merge a company (#1) into another company (#2), elimination company #1 */
 
		PlayerID pid_old = GB(p2,  0, 16);
 
		PlayerID pid_new = GB(p2, 16, 16);
 

	
 
		if (pid_old >= MAX_PLAYERS || pid_new >= MAX_PLAYERS) return CMD_ERROR;
 
		if (!IsValidPlayer(pid_old) || !IsValidPlayer(pid_new)) return CMD_ERROR;
 

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

	
 
		ChangeOwnershipOfPlayerItems(pid_old, pid_new);
 
		DeletePlayerStuff(pid_old);
 
	} break;
road_cmd.c
Show inline comments
 
@@ -42,13 +42,13 @@ static bool CheckAllowRemoveRoad(TileInd
 
	Owner owner;
 
	*edge_road = true;
 

	
 
	if (_game_mode == GM_EDITOR) return true;
 

	
 
	// Only do the special processing for actual players.
 
	if (_current_player >= MAX_PLAYERS) return true;
 
	if (!IsValidPlayer(_current_player)) return true;
 

	
 
	owner = IsLevelCrossingTile(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile);
 

	
 
	// Only do the special processing if the road is owned
 
	// by a town
 
	if (owner != OWNER_TOWN) return (owner == OWNER_NONE) || CheckOwnership(owner);
 
@@ -286,13 +286,13 @@ int32 CmdBuildRoad(TileIndex tile, uint3
 
	Slope tileh;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
 
	 * if a non-player is building the road */
 
	if ((p1 >> 4) || (_current_player < MAX_PLAYERS && p2 != 0) || !IsValidTownID(p2)) return CMD_ERROR;
 
	if ((p1 >> 4) || (IsValidPlayer(_current_player) && p2 != 0) || !IsValidTownID(p2)) return CMD_ERROR;
 
	pieces = p1;
 

	
 
	tileh = GetTileSlope(tile, NULL);
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_STREET:
station_cmd.c
Show inline comments
 
@@ -1021,13 +1021,13 @@ int32 CmdBuildRailroadStation(TileIndex 
 
	} else {
 
		// Create a new station
 
		st = AllocateStation();
 
		if (st == NULL) return CMD_ERROR;
 

	
 
		st->town = ClosestTownFromTile(tile_org, (uint)-1);
 
		if (_current_player < MAX_PLAYERS && flags & DC_EXEC)
 
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC))
 
			SETBIT(st->town->have_ratings, _current_player);
 

	
 
		if (!GenerateStationName(st, tile_org, 0)) return CMD_ERROR;
 

	
 
		if (flags & DC_EXEC) StationInitialize(st, tile_org);
 
	}
 
@@ -1449,13 +1449,13 @@ int32 CmdBuildRoadStop(TileIndex tile, u
 
		if (st == NULL) return CMD_ERROR;
 

	
 
		st->town = t = ClosestTownFromTile(tile, (uint)-1);
 

	
 
		FindRoadStopSpot(type, st, &currstop, &prev);
 

	
 
		if (_current_player < MAX_PLAYERS && flags & DC_EXEC) {
 
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC)) {
 
			SETBIT(t->have_ratings, _current_player);
 
		}
 

	
 
		st->sign.width_1 = 0;
 

	
 
		if (!GenerateStationName(st, tile, 0)) return CMD_ERROR;
 
@@ -1695,13 +1695,13 @@ int32 CmdBuildAirport(TileIndex tile, ui
 

	
 
		st = AllocateStation();
 
		if (st == NULL) return CMD_ERROR;
 

	
 
		st->town = t;
 

	
 
		if (_current_player < MAX_PLAYERS && flags & DC_EXEC)
 
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC))
 
			SETBIT(t->have_ratings, _current_player);
 

	
 
		st->sign.width_1 = 0;
 

	
 
		// if airport type equals Heliport then generate
 
		// type 5 name, which is heliport, otherwise airport names (1)
 
@@ -1856,16 +1856,14 @@ static bool CheckShipsOnBuoy(Station *st
 
}
 

	
 
static int32 RemoveBuoy(Station *st, uint32 flags)
 
{
 
	TileIndex tile;
 

	
 
	if (_current_player >= MAX_PLAYERS) {
 
		/* XXX: strange stuff */
 
		return_cmd_error(INVALID_STRING_ID);
 
	}
 
	if (!IsValidPlayer(_current_player))  return_cmd_error(INVALID_STRING_ID);
 

	
 
	tile = st->dock_tile;
 

	
 
	if (CheckShipsOnBuoy(st))   return_cmd_error(STR_BUOY_IS_IN_USE);
 
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
@@ -1964,13 +1962,13 @@ int32 CmdBuildDock(TileIndex tile, uint3
 

	
 
		st = AllocateStation();
 
		if (st == NULL) return CMD_ERROR;
 

	
 
		st->town = t = ClosestTownFromTile(tile, (uint)-1);
 

	
 
		if (_current_player < MAX_PLAYERS && flags&DC_EXEC)
 
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC))
 
			SETBIT(t->have_ratings, _current_player);
 

	
 
		st->sign.width_1 = 0;
 

	
 
		if (!GenerateStationName(st, tile, 3)) return CMD_ERROR;
 

	
 
@@ -2041,13 +2039,13 @@ static void DrawTile_Station(TileInfo *t
 
	uint32 relocation = 0;
 
	const Station *st = NULL;
 
	const StationSpec *statspec = NULL;
 
	PlayerID owner = GetTileOwner(ti->tile);
 
	uint32 palette;
 

	
 
	if (owner < MAX_PLAYERS) {
 
	if (IsValidPlayer(owner)) {
 
		palette = PLAYER_SPRITE_COLOR(owner);
 
	} else {
 
		// Some stations are not owner by a player, namely oil rigs
 
		palette = PALETTE_TO_GREY;
 
	}
 

	
 
@@ -2397,13 +2395,13 @@ void DestroyStation(Station *st)
 

	
 
void DeleteAllPlayerStations(void)
 
{
 
	Station *st;
 

	
 
	FOR_ALL_STATIONS(st) {
 
		if (st->owner < MAX_PLAYERS) DeleteStation(st);
 
		if (IsValidPlayer(st->owner)) DeleteStation(st);
 
	}
 
}
 

	
 
/* this function is called for one station each tick */
 
static void StationHandleBigTick(Station *st)
 
{
 
@@ -2445,14 +2443,13 @@ static void UpdateStationRating(Station 
 
				(age >= 3) ||
 
				(rating += 10, age >= 2) ||
 
				(rating += 10, age >= 1) ||
 
				(rating += 13, true);
 
			}
 

	
 
			if (st->owner < MAX_PLAYERS && HASBIT(st->town->statues, st->owner))
 
				rating += 26;
 
			if (IsValidPlayer(st->owner) && HASBIT(st->town->statues, st->owner)) rating += 26;
 

	
 
			{
 
				byte days = ge->days_since_pickup;
 
				if (st->last_vehicle_type == VEH_Ship)
 
							days >>= 2;
 
				(days > 21) ||
town_cmd.c
Show inline comments
 
@@ -352,13 +352,13 @@ static int32 ClearTile_Town(TileIndex ti
 
	cost = _price.remove_house * _housetype_remove_cost[house] >> 8;
 

	
 
	rating = _housetype_remove_ratingmod[house];
 
	_cleared_town_rating += rating;
 
	_cleared_town = t = GetTownByTile(tile);
 

	
 
	if (_current_player < MAX_PLAYERS) {
 
	if (IsValidPlayer(_current_player)) {
 
		if (rating > t->ratings[_current_player] && !(flags & DC_NO_TOWN_RATING) && !_cheats.magic_bulldozer.value) {
 
			SetDParam(0, t->index);
 
			return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
 
		}
 
	}
 

	
 
@@ -1627,16 +1627,16 @@ static void UpdateTownGrowRate(Town *t)
 

	
 
	n = 0;
 
	FOR_ALL_STATIONS(st) {
 
		if (DistanceSquare(st->xy, t->xy) <= t->radius[0]) {
 
			if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
 
				n++;
 
				if (st->owner < MAX_PLAYERS && t->ratings[st->owner] <= 1000-12)
 
				if (IsValidPlayer(st->owner) && t->ratings[st->owner] <= 1000-12)
 
					t->ratings[st->owner] += 12;
 
			} else {
 
				if (st->owner < MAX_PLAYERS && t->ratings[st->owner] >= -1000+15)
 
				if (IsValidPlayer(st->owner) && t->ratings[st->owner] >= -1000+15)
 
					t->ratings[st->owner] -= 15;
 
			}
 
		}
 
	}
 

	
 
	CLRBIT(t->flags12, TOWN_IS_FUNDED);
 
@@ -1701,13 +1701,13 @@ static void UpdateTownUnwanted(Town *t)
 
}
 

	
 
bool CheckIfAuthorityAllows(TileIndex tile)
 
{
 
	Town *t;
 

	
 
	if (_current_player >= MAX_PLAYERS) return true;
 
	if (!IsValidPlayer(_current_player)) return true;
 

	
 
	t = ClosestTownFromTile(tile, _patches.dist_local_authority);
 
	if (t == NULL) return true;
 

	
 
	if (t->ratings[_current_player] > -200) return true;
 

	
 
@@ -1752,13 +1752,13 @@ Town *ClosestTownFromTile(TileIndex tile
 
void ChangeTownRating(Town *t, int add, int max)
 
{
 
	int rating;
 

	
 
	// if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff
 
	if (t == NULL ||
 
			_current_player >= MAX_PLAYERS ||
 
			!IsValidPlayer(_current_player) ||
 
			(_cheats.magic_bulldozer.value && add < 0)) {
 
		return;
 
	}
 

	
 
	SETBIT(t->have_ratings, _current_player);
 

	
 
@@ -1788,13 +1788,13 @@ static const int _default_rating_setting
 

	
 
bool CheckforTownRating(uint32 flags, Town *t, byte type)
 
{
 
	int modemod;
 

	
 
	// if magic_bulldozer cheat is active, town doesn't restrict your destructive actions
 
	if (t == NULL || _current_player >= MAX_PLAYERS || _cheats.magic_bulldozer.value)
 
	if (t == NULL || !IsValidPlayer(_current_player) || _cheats.magic_bulldozer.value)
 
		return true;
 

	
 
	/* check if you're allowed to remove the street/bridge/tunnel/industry
 
	 * owned by a town no removal if rating is lower than ... depends now on
 
	 * difficulty setting. Minimum town rating selected by difficulty level
 
	 */
tree_cmd.c
Show inline comments
 
@@ -262,13 +262,13 @@ int32 CmdPlantTree(TileIndex tile, uint3
 
					}
 

	
 
					if (flags & DC_EXEC) {
 
						TreeType treetype;
 
						uint growth;
 

	
 
						if (_game_mode != GM_EDITOR && _current_player < MAX_PLAYERS) {
 
						if (_game_mode != GM_EDITOR && IsValidPlayer(_current_player)) {
 
							Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
 
							if (t != NULL)
 
								ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM);
 
						}
 

	
 
						treetype = p1;
 
@@ -412,13 +412,13 @@ static Slope GetSlopeTileh_Trees(TileInd
 
}
 

	
 
static int32 ClearTile_Trees(TileIndex tile, byte flags)
 
{
 
	uint num;
 

	
 
	if (flags & DC_EXEC && _current_player < MAX_PLAYERS) {
 
	if ((flags & DC_EXEC) && IsValidPlayer(_current_player)) {
 
		Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
 
		if (t != NULL)
 
			ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM);
 
	}
 

	
 
	num = GetTreeCount(tile) + 1;
tunnelbridge_cmd.c
Show inline comments
 
@@ -420,13 +420,13 @@ not_valid_below:;
 
	 */
 
	if (!(flags & DC_QUERY_COST)) {
 
		const Bridge *b = &_bridge[bridge_type];
 

	
 
		bridge_len += 2; // begin and end tiles/ramps
 

	
 
		if (_current_player < MAX_PLAYERS && !_is_old_ai_player)
 
		if (IsValidPlayer(_current_player) && !_is_old_ai_player)
 
			bridge_len = CalcBridgeLenCostFactor(bridge_len);
 

	
 
		cost += (int64)bridge_len * _price.build_bridge * b->price >> 8;
 
	}
 

	
 
	return cost;
0 comments (0 inline, 0 general)