--- a/src/misc_cmd.cpp Wed Jun 13 12:05:56 2007 +0000
+++ b/src/misc_cmd.cpp Tue Jun 19 07:21:01 2007 +0000
@@ -24,7 +24,7 @@
* @param p1 unused
* @param p2 face bitmasked
*/
-int32 CmdSetPlayerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdSetPlayerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
PlayerFace pf = (PlayerFace)p2;
@@ -45,7 +45,7 @@
* p1 bits 8-9 set in use state or first/second colour
* @param p2 new colour for vehicles, property, etc.
*/
-int32 CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
Player *p, *pp;
byte colour;
@@ -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)
+CommandCost 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)
+CommandCost 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) {
@@ -194,7 +199,7 @@
* @param p1 unused
* @param p2 unused
*/
-int32 CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
StringID str;
Player *p;
@@ -222,7 +227,7 @@
* @param p1 unused
* @param p2 unused
*/
-int32 CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
StringID str;
Player *p;
@@ -261,7 +266,7 @@
* @param p1 0 = decrease pause counter; 1 = increase pause counter
* @param p2 unused
*/
-int32 CmdPause(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdPause(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
if (flags & DC_EXEC) {
_pause_game += (p1 == 1) ? 1 : -1;
@@ -280,7 +285,7 @@
* @param p1 the amount of money to receive (if negative), or spend (if positive)
* @param p2 unused
*/
-int32 CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
#ifndef _DEBUG
if (_networking) return CMD_ERROR;
@@ -298,10 +303,10 @@
* @param p1 the amount of money to transfer; max 20.000.000
* @param p2 the player to transfer the money to
*/
-int32 CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
const Player *p = GetPlayer(_current_player);
- int32 amount = min((int32)p1, 20000000);
+ CommandCost amount = min((int32)p1, 20000000);
SET_EXPENSES_TYPE(EXPENSES_OTHER);
@@ -331,7 +336,7 @@
* itself is changed. The new value is inside p2
* @param p2 new value for a difficulty setting or difficulty level
*/
-int32 CmdChangeDifficultyLevel(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdChangeDifficultyLevel(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
if (p1 != (uint32)-1L && ((int32)p1 >= GAME_DIFFICULTY_NUM || (int32)p1 < 0)) return CMD_ERROR;