summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-06-14 15:24:34 +0000
committerrubidium <rubidium@openttd.org>2007-06-14 15:24:34 +0000
commit0e2978720d7e942c5a407adbde7e498d7a3c8654 (patch)
tree04c4a363bfd59a1ef12e81e7c265442fbf62fbe7 /src
parent144035bf5cb747fd5ffd2c41ae713f66ca79fe62 (diff)
downloadopenttd-0e2978720d7e942c5a407adbde7e498d7a3c8654.tar.xz
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
Diffstat (limited to 'src')
-rw-r--r--src/misc_cmd.cpp49
-rw-r--r--src/player.h6
-rw-r--r--src/player_gui.cpp8
3 files changed, 39 insertions, 24 deletions
diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp
index d912b6646..4d3d5ae6f 100644
--- a/src/misc_cmd.cpp
+++ b/src/misc_cmd.cpp
@@ -121,23 +121,30 @@ int32 CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
* @param tile unused
* @param flags operation to perform
* @param p1 unused
- * @param p2 when set, loans the maximum amount in one go (press CTRL)
+ * @param p2 when 0: loans LOAN_INTERVAL
+ * when 1: loans the maximum loan permitting money (press CTRL),
*/
int32 CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
- Player *p;
-
- p = GetPlayer(_current_player);
+ Player *p = GetPlayer(_current_player);
if (p->current_loan >= _economy.max_loan) {
SetDParam(0, _economy.max_loan);
return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN);
}
- if (flags & DC_EXEC) {
- /* Loan the maximum amount or not? */
- int32 loan = (p2) ? _economy.max_loan - p->current_loan : (IsHumanPlayer(_current_player) || _patches.ainew_active) ? 10000 : 50000;
+ int32 loan;
+ switch (p2) {
+ default: return CMD_ERROR; // Invalid method
+ case 0: // Take some extra loan
+ loan = (IsHumanPlayer(_current_player) || _patches.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI;
+ break;
+ case 1: // Take a loan as big as possible
+ loan = _economy.max_loan - p->current_loan;
+ break;
+ }
+ if (flags & DC_EXEC) {
p->money64 += loan;
p->current_loan += loan;
UpdatePlayerMoney32(p);
@@ -151,27 +158,25 @@ int32 CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
* @param tile unused
* @param flags operation to perform
* @param p1 unused
- * @param p2 when set, pays back the maximum loan permitting money (press CTRL)
+ * @param p2 when 0: pays back LOAN_INTERVAL
+ * when 1: pays back the maximum loan permitting money (press CTRL),
*/
int32 CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
- Player *p;
- int32 loan;
-
- p = GetPlayer(_current_player);
+ Player *p = GetPlayer(_current_player);
if (p->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED);
- loan = p->current_loan;
-
- /* p2 is true while CTRL is pressed (repay all possible loan, or max money you have)
- * Repay any loan in chunks of 10.000 pounds */
- if (p2) {
- loan = min(loan, p->player_money);
- loan = max(loan, 10000);
- loan -= loan % 10000;
- } else {
- loan = min(loan, (IsHumanPlayer(_current_player) || _patches.ainew_active) ? 10000 : 50000);
+ int32 loan;
+ switch (p2) {
+ default: return CMD_ERROR; // Invalid method
+ case 0: // Pay back one step
+ loan = min(p->current_loan, (IsHumanPlayer(_current_player) || _patches.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI);
+ break;
+ case 1: // Pay back as much as possible
+ loan = max(min(p->current_loan, p->player_money), (int32)LOAN_INTERVAL);
+ loan -= loan % LOAN_INTERVAL;
+ break;
}
if (p->player_money < loan) {
diff --git a/src/player.h b/src/player.h
index 191fc30eb..d6857aa3f 100644
--- a/src/player.h
+++ b/src/player.h
@@ -149,6 +149,12 @@ struct PlayerAiNew {
};
+/* The "steps" in loan size, in British Pounds! */
+enum {
+ LOAN_INTERVAL = 10000,
+ LOAN_INTERVAL_OLD_AI = 50000,
+};
+
typedef uint32 PlayerFace;
struct Player {
diff --git a/src/player_gui.cpp b/src/player_gui.cpp
index 861c4182f..252b14572 100644
--- a/src/player_gui.cpp
+++ b/src/player_gui.cpp
@@ -156,15 +156,19 @@ static void PlayerFinancesWndProc(Window *w, WindowEvent *e)
PlayerID player = (PlayerID)w->window_number;
const Player *p = GetPlayer(player);
+ /* Borrow/repay buttons only exist for local player */
if (player == _local_player) {
- /* borrow/repay buttons only exist for local player */
+ /* Borrow button only shows when there is any more money to loan */
+ SetWindowWidgetDisabledState(w, 6, p->current_loan == _economy.max_loan);
+
+ /* Repay button only shows when there is any more money to repay */
SetWindowWidgetDisabledState(w, 7, p->current_loan == 0);
}
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
SetDParam(2, GetPlayerNameString(player, 3));
- SetDParam(4, 10000);
+ SetDParam(4, LOAN_INTERVAL);
DrawWindowWidgets(w);
DrawPlayerEconomyStats(p, (byte)WP(w, def_d).data_1);