Merge branch 'master' into jgrpp
# Conflicts: # cmake/CompileFlags.cmake # src/crashlog.cpp # src/fileio.cpp # src/fileio_func.h # src/fios_gui.cpp # src/ini_load.cpp # src/ini_type.h # src/lang/english.txt # src/lang/german.txt # src/lang/korean.txt # src/network/network_client.cpp # src/order_base.h # src/order_cmd.cpp # src/os/windows/win32.cpp # src/road_cmd.cpp # src/saveload/saveload.cpp # src/saveload/saveload.h # src/settings.cpp # src/station_cmd.cpp # src/stdafx.h # src/table/settings.ini # src/tree_cmd.cpp # src/tree_gui.cpp # src/vehicle_base.h # src/video/cocoa/cocoa_v.mm # src/video/cocoa/event.mm # src/video/cocoa/wnd_quartz.mm # src/viewport.cpp # src/widgets/tree_widget.h
This commit is contained in:
@@ -26,14 +26,18 @@
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
/* Make sure we can discard lower 2 bits of 64bit amount when passing it to Cmd[In|De]creaseLoan() */
|
||||
static_assert((LOAN_INTERVAL & 3) == 0);
|
||||
|
||||
/**
|
||||
* Increase the loan of your company.
|
||||
* @param tile unused
|
||||
* @param flags operation to perform
|
||||
* @param p1 amount to increase the loan with, multitude of LOAN_INTERVAL. Only used when p2 == 2.
|
||||
* @param p2 when 0: loans LOAN_INTERVAL
|
||||
* when 1: loans the maximum loan permitting money (press CTRL),
|
||||
* when 2: loans the amount specified in p1
|
||||
* @param p1 higher half of amount to increase the loan with, multitude of LOAN_INTERVAL. Only used when (p2 & 3) == 2.
|
||||
* @param p2 (bit 2-31) - lower half of amount (lower 2 bits assumed to be 0)
|
||||
* (bit 0-1) - when 0: loans LOAN_INTERVAL
|
||||
* when 1: loans the maximum loan permitting money (press CTRL),
|
||||
* when 2: loans the amount specified in p1 and p2
|
||||
* @param text unused
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
@@ -47,7 +51,7 @@ CommandCost CmdIncreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||
}
|
||||
|
||||
Money loan;
|
||||
switch (p2) {
|
||||
switch (p2 & 3) {
|
||||
default: return CMD_ERROR; // Invalid method
|
||||
case 0: // Take some extra loan
|
||||
loan = LOAN_INTERVAL;
|
||||
@@ -56,8 +60,8 @@ CommandCost CmdIncreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||
loan = _economy.max_loan - c->current_loan;
|
||||
break;
|
||||
case 2: // Take the given amount of loan
|
||||
if ((int32)p1 < LOAN_INTERVAL || c->current_loan + (int32)p1 > _economy.max_loan || p1 % LOAN_INTERVAL != 0) return CMD_ERROR;
|
||||
loan = p1;
|
||||
loan = ((uint64)p1 << 32) | (p2 & 0xFFFFFFFC);
|
||||
if (loan < LOAN_INTERVAL || c->current_loan + loan > _economy.max_loan || loan % LOAN_INTERVAL != 0) return CMD_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -77,10 +81,11 @@ CommandCost CmdIncreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||
* Decrease the loan of your company.
|
||||
* @param tile unused
|
||||
* @param flags operation to perform
|
||||
* @param p1 amount to decrease the loan with, multitude of LOAN_INTERVAL. Only used when p2 == 2.
|
||||
* @param p2 when 0: pays back LOAN_INTERVAL
|
||||
* when 1: pays back the maximum loan permitting money (press CTRL),
|
||||
* when 2: pays back the amount specified in p1
|
||||
* @param p1 higher half of amount to decrease the loan with, multitude of LOAN_INTERVAL. Only used when (p2 & 3) == 2.
|
||||
* @param p2 (bit 2-31) - lower half of amount (lower 2 bits assumed to be 0)
|
||||
* (bit 0-1) - when 0: pays back LOAN_INTERVAL
|
||||
* when 1: pays back the maximum loan permitting money (press CTRL),
|
||||
* when 2: pays back the amount specified in p1 and p2
|
||||
* @param text unused
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
@@ -91,7 +96,7 @@ CommandCost CmdDecreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||
if (c->current_loan == 0) return_cmd_error(STR_ERROR_LOAN_ALREADY_REPAYED);
|
||||
|
||||
Money loan;
|
||||
switch (p2) {
|
||||
switch (p2 & 3) {
|
||||
default: return CMD_ERROR; // Invalid method
|
||||
case 0: // Pay back one step
|
||||
loan = min(c->current_loan, (Money)LOAN_INTERVAL);
|
||||
@@ -101,8 +106,8 @@ CommandCost CmdDecreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||
loan -= loan % LOAN_INTERVAL;
|
||||
break;
|
||||
case 2: // Repay the given amount of loan
|
||||
if (p1 % LOAN_INTERVAL != 0 || (int32)p1 < LOAN_INTERVAL || p1 > c->current_loan) return CMD_ERROR; // Invalid amount to loan
|
||||
loan = p1;
|
||||
loan = ((uint64)p1 << 32) | (p2 & 0xFFFFFFFC);
|
||||
if (loan % LOAN_INTERVAL != 0 || loan < LOAN_INTERVAL || loan > c->current_loan) return CMD_ERROR; // Invalid amount to loan
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user