(svn r2271) CMD_SET_PLAYER_FACE, CMD_SET_PLAYER_COLOR, CMD_INCREASE_LOAN, CMD_DECREASE_LOAN only make sense for the current player, so don't explicitly pass a player number
authortron
Fri, 06 May 2005 06:56:30 +0000
changeset 1767 394867897b0a
parent 1766 7c048e309f18
child 1768 997fd3ae1384
(svn r2271) CMD_SET_PLAYER_FACE, CMD_SET_PLAYER_COLOR, CMD_INCREASE_LOAN, CMD_DECREASE_LOAN only make sense for the current player, so don't explicitly pass a player number
ai.c
ai_new.c
misc_cmd.c
player.h
player_gui.c
--- a/ai.c	Thu May 05 20:46:14 2005 +0000
+++ b/ai.c	Fri May 06 06:56:30 2005 +0000
@@ -3882,14 +3882,14 @@
 	if (p->player_money > base * 1400) {
 		// Decrease loan
 		if (p->current_loan != 0) {
-			DoCommandByTile(0, _current_player, 0, DC_EXEC, CMD_DECREASE_LOAN);
+			DoCommandByTile(0, 0, 0, DC_EXEC, CMD_DECREASE_LOAN);
 		}
 	} else if (p->player_money < base * 500) {
 		// Increase loan
 		if (p->current_loan < _economy.max_loan &&
 				p->num_valid_stat_ent >= 2 &&
 				-(p->old_economy[0].expenses+p->old_economy[1].expenses) < base * 60) {
-			DoCommandByTile(0, _current_player, 0, DC_EXEC, CMD_INCREASE_LOAN);
+			DoCommandByTile(0, 0, 0, DC_EXEC, CMD_INCREASE_LOAN);
 		}
 	}
 }
--- a/ai_new.c	Thu May 05 20:46:14 2005 +0000
+++ b/ai_new.c	Fri May 06 06:56:30 2005 +0000
@@ -1191,7 +1191,7 @@
 static void AiNew_State_RepayMoney(Player *p) {
     int i;
     for (i=0;i<AI_LOAN_REPAY;i++)
-    	DoCommandByTile(0, _current_player, 0, DC_EXEC, CMD_DECREASE_LOAN);
+    	DoCommandByTile(0, 0, 0, DC_EXEC, CMD_DECREASE_LOAN);
     p->ainew.state = AI_STATE_ACTION_DONE;
 }
 
--- a/misc_cmd.c	Thu May 05 20:46:14 2005 +0000
+++ b/misc_cmd.c	Fri May 06 06:56:30 2005 +0000
@@ -18,7 +18,7 @@
 int32 CmdSetPlayerFace(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 {
 	if (flags & DC_EXEC) {
-		DEREF_PLAYER(p1)->face = p2;
+		GetPlayer(_current_player)->face = p2;
 		MarkWholeScreenDirty();
 	}
 	return 0;
@@ -31,11 +31,7 @@
 {
 	Player *p,*pp;
 
-//	/* can only set color for itself */
-//	if ( (byte)p1 != _current_player)
-//		return CMD_ERROR;
-
-	p = DEREF_PLAYER(p1);
+	p = GetPlayer(_current_player);
 
 	/* ensure no dups */
 	FOR_ALL_PLAYERS(pp) {
@@ -44,7 +40,7 @@
 	}
 
 	if (flags & DC_EXEC) {
-		_player_colors[p1] = (byte)p2;
+		_player_colors[_current_player] = (byte)p2;
 		p->player_color = (byte)p2;
 		MarkWholeScreenDirty();
 	}
@@ -56,10 +52,7 @@
 	Player *p;
 	int32 size;
 
-	if ( (byte)p1 != _current_player)
-		return CMD_ERROR;
-
-	p = DEREF_PLAYER(p1);
+	p = GetPlayer(_current_player);
 
 	if (p->current_loan >= _economy.max_loan) {
 		SetDParam(0, _economy.max_loan);
@@ -70,7 +63,7 @@
 		if (p2)
 			size = _economy.max_loan - p->current_loan;
 		else
-			size = IS_HUMAN_PLAYER((byte)p1) ? 10000 : 50000;
+			size = IS_HUMAN_PLAYER(_current_player) ? 10000 : 50000;
 
 		p->money64 += size;
 		p->current_loan += size;
@@ -85,10 +78,8 @@
 {
 	Player *p;
 	int32 size;
-	if ( (byte)p1 != _current_player)
-		return CMD_ERROR;
 
-	p = DEREF_PLAYER(p1);
+	p = GetPlayer(_current_player);
 
 	if (p->current_loan == 0)
 		return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED);
@@ -100,7 +91,7 @@
 	    if (_patches.ainew_active)
  		    size = min(size, 10000);
 	    else
-		    size = min(size, IS_HUMAN_PLAYER((byte)p1) ? 10000 : 50000);
+		    size = min(size, IS_HUMAN_PLAYER(_current_player) ? 10000 : 50000);
 	} else {	// only repay in chunks of 10K
 		size = min(size, p->player_money);
 		size = max(size, 10000);
--- a/player.h	Thu May 05 20:46:14 2005 +0000
+++ b/player.h	Fri May 06 06:56:30 2005 +0000
@@ -192,12 +192,18 @@
 void InvalidatePlayerWindows(Player *p);
 void AiDoGameLoop(Player *p);
 void UpdatePlayerMoney32(Player *p);
-#define DEREF_PLAYER(i) (&_players[i])
 #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_INTERACTIVE_PLAYER(p) (((byte)p) == _local_player)
 
--- a/player_gui.c	Thu May 05 20:46:14 2005 +0000
+++ b/player_gui.c	Fri May 06 06:56:30 2005 +0000
@@ -168,11 +168,11 @@
 		} break;
 
 		case 6: /* increase loan */
-			DoCommandP(0, w->window_number, _ctrl_pressed, NULL, CMD_INCREASE_LOAN | CMD_MSG(STR_702C_CAN_T_BORROW_ANY_MORE_MONEY));
+			DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_INCREASE_LOAN | CMD_MSG(STR_702C_CAN_T_BORROW_ANY_MORE_MONEY));
 			break;
 
 		case 7: /* repay loan */
-			DoCommandP(0, w->window_number, _ctrl_pressed, NULL, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
+			DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
 			break;
 		}
 		break;
@@ -285,7 +285,7 @@
 
 			for(i=0; i!=16; i++) {
 				if (!(used_colors & 1) && --item < 0) {
-					DoCommandP(0, w->window_number, i, NULL, CMD_SET_PLAYER_COLOR);
+					DoCommandP(0, 0, i, NULL, CMD_SET_PLAYER_COLOR);
 					DeleteWindow(w);
 					break;
 				}
@@ -327,7 +327,7 @@
 		switch(e->click.widget) {
 		case 3: DeleteWindow(w); break;
 		case 4: /* ok click */
-			DoCommandP(0, w->window_number, WP(w,facesel_d).face, NULL, CMD_SET_PLAYER_FACE);
+			DoCommandP(0, 0, WP(w,facesel_d).face, NULL, CMD_SET_PLAYER_FACE);
 			DeleteWindow(w);
 			break;
 		case 5: /* male click */