players.c
changeset 4850 b4e9be22945f
parent 4849 9a3c3ae7f62f
child 4854 383ef523793f
--- a/players.c	Sat Oct 14 22:22:48 2006 +0000
+++ b/players.c	Sat Oct 14 22:31:18 2006 +0000
@@ -204,7 +204,7 @@
 {
 	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;
@@ -233,7 +233,7 @@
 {
 	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)
@@ -264,7 +264,7 @@
 	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);
@@ -584,7 +584,7 @@
 // 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;
 	}
@@ -691,8 +691,7 @@
 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)) {
@@ -824,7 +823,7 @@
 		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);
 
@@ -910,7 +909,7 @@
 	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;
 
@@ -938,7 +937,7 @@
 		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;