(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
authorrubidium
Thu, 14 Jun 2007 15:24:34 +0000
changeset 7405 480f118e5551
parent 7404 fc0559157f16
child 7406 c626390d81a9
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
src/misc_cmd.cpp
src/player.h
src/player_gui.cpp
--- a/src/misc_cmd.cpp	Thu Jun 14 14:31:48 2007 +0000
+++ b/src/misc_cmd.cpp	Thu Jun 14 15:24:34 2007 +0000
@@ -121,23 +121,30 @@
  * @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);
 	}
 
+	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) {
-		/* Loan the maximum amount or not? */
-		int32 loan = (p2) ? _economy.max_loan - p->current_loan : (IsHumanPlayer(_current_player) || _patches.ainew_active) ? 10000 : 50000;
-
 		p->money64 += loan;
 		p->current_loan += loan;
 		UpdatePlayerMoney32(p);
@@ -151,27 +158,25 @@
  * @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) {
--- a/src/player.h	Thu Jun 14 14:31:48 2007 +0000
+++ b/src/player.h	Thu Jun 14 15:24:34 2007 +0000
@@ -149,6 +149,12 @@
 };
 
 
+/* The "steps" in loan size, in British Pounds! */
+enum {
+	LOAN_INTERVAL        = 10000,
+	LOAN_INTERVAL_OLD_AI = 50000,
+};
+
 typedef uint32 PlayerFace;
 
 struct Player {
--- a/src/player_gui.cpp	Thu Jun 14 14:31:48 2007 +0000
+++ b/src/player_gui.cpp	Thu Jun 14 15:24:34 2007 +0000
@@ -156,15 +156,19 @@
 		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);