summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-05-06 06:56:30 +0000
committertron <tron@openttd.org>2005-05-06 06:56:30 +0000
commitd17476b058fb877484159bec0b725d1be5a6d68f (patch)
treeec6a2e5ec15ed8e58408a2c562f10913bb6382e8
parent203a84dd0b4f1fd7397052d3a645731eaeb5ebd7 (diff)
downloadopenttd-d17476b058fb877484159bec0b725d1be5a6d68f.tar.xz
(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
-rw-r--r--ai.c4
-rw-r--r--ai_new.c2
-rw-r--r--misc_cmd.c23
-rw-r--r--player.h8
-rw-r--r--player_gui.c8
5 files changed, 21 insertions, 24 deletions
diff --git a/ai.c b/ai.c
index 2cb475997..05f5a82f6 100644
--- a/ai.c
+++ b/ai.c
@@ -3882,14 +3882,14 @@ static void AiAdjustLoan(Player *p)
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);
}
}
}
diff --git a/ai_new.c b/ai_new.c
index 3ca443f32..a2317fc06 100644
--- a/ai_new.c
+++ b/ai_new.c
@@ -1191,7 +1191,7 @@ static void AiNew_State_StartVehicle(Player *p) {
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;
}
diff --git a/misc_cmd.c b/misc_cmd.c
index c7e60a2ec..1e84edeed 100644
--- a/misc_cmd.c
+++ b/misc_cmd.c
@@ -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 @@ int32 CmdSetPlayerColor(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
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 @@ int32 CmdSetPlayerColor(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
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 @@ int32 CmdIncreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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 @@ int32 CmdIncreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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 @@ int32 CmdDecreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
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 @@ int32 CmdDecreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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);
diff --git a/player.h b/player.h
index 2fc8fd89b..020e6617f 100644
--- a/player.h
+++ b/player.h
@@ -192,12 +192,18 @@ int64 CalculateCompanyValue(Player *p);
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)
diff --git a/player_gui.c b/player_gui.c
index da7de978c..fa5b94ca6 100644
--- a/player_gui.c
+++ b/player_gui.c
@@ -168,11 +168,11 @@ static void PlayerFinancesWndProc(Window *w, WindowEvent *e)
} 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 @@ static void SelectPlayerColorWndProc(Window *w, WindowEvent *e)
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 @@ static void SelectPlayerFaceWndProc(Window *w, WindowEvent *e)
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 */