src/misc_cmd.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9909 dce9a6923bb7
equal deleted inserted replaced
9912:1ac8aac92385 9913:e79cd19772dd
    22  * @param tile unused
    22  * @param tile unused
    23  * @param flags operation to perform
    23  * @param flags operation to perform
    24  * @param p1 unused
    24  * @param p1 unused
    25  * @param p2 face bitmasked
    25  * @param p2 face bitmasked
    26  */
    26  */
    27 int32 CmdSetPlayerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
    27 CommandCost CmdSetPlayerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
    28 {
    28 {
    29 	PlayerFace pf = (PlayerFace)p2;
    29 	PlayerFace pf = (PlayerFace)p2;
    30 
    30 
    31 	if (!IsValidPlayerFace(pf)) return CMD_ERROR;
    31 	if (!IsValidPlayerFace(pf)) return CMD_ERROR;
    32 
    32 
    43  * @param p1 bitstuffed:
    43  * @param p1 bitstuffed:
    44  * p1 bits 0-7 scheme to set
    44  * p1 bits 0-7 scheme to set
    45  * p1 bits 8-9 set in use state or first/second colour
    45  * p1 bits 8-9 set in use state or first/second colour
    46  * @param p2 new colour for vehicles, property, etc.
    46  * @param p2 new colour for vehicles, property, etc.
    47  */
    47  */
    48 int32 CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
    48 CommandCost CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
    49 {
    49 {
    50 	Player *p, *pp;
    50 	Player *p, *pp;
    51 	byte colour;
    51 	byte colour;
    52 	LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
    52 	LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
    53 	byte state = GB(p1, 8, 2);
    53 	byte state = GB(p1, 8, 2);
   119 
   119 
   120 /** Increase the loan of your company.
   120 /** Increase the loan of your company.
   121  * @param tile unused
   121  * @param tile unused
   122  * @param flags operation to perform
   122  * @param flags operation to perform
   123  * @param p1 unused
   123  * @param p1 unused
   124  * @param p2 when set, loans the maximum amount in one go (press CTRL)
   124  * @param p2 when 0: loans LOAN_INTERVAL
   125  */
   125  *           when 1: loans the maximum loan permitting money (press CTRL),
   126 int32 CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   126  */
   127 {
   127 CommandCost CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   128 	Player *p;
   128 {
   129 
   129 	Player *p = GetPlayer(_current_player);
   130 	p = GetPlayer(_current_player);
       
   131 
   130 
   132 	if (p->current_loan >= _economy.max_loan) {
   131 	if (p->current_loan >= _economy.max_loan) {
   133 		SetDParam(0, _economy.max_loan);
   132 		SetDParam(0, _economy.max_loan);
   134 		return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN);
   133 		return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN);
   135 	}
   134 	}
   136 
   135 
   137 	if (flags & DC_EXEC) {
   136 	int32 loan;
   138 		/* Loan the maximum amount or not? */
   137 	switch (p2) {
   139 		int32 loan = (p2) ? _economy.max_loan - p->current_loan : (IsHumanPlayer(_current_player) || _patches.ainew_active) ? 10000 : 50000;
   138 		default: return CMD_ERROR; // Invalid method
   140 
   139 		case 0: // Take some extra loan
       
   140 			loan = (IsHumanPlayer(_current_player) || _patches.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI;
       
   141 			break;
       
   142 		case 1: // Take a loan as big as possible
       
   143 			loan = _economy.max_loan - p->current_loan;
       
   144 			break;
       
   145 	}
       
   146 
       
   147 	if (flags & DC_EXEC) {
   141 		p->money64 += loan;
   148 		p->money64 += loan;
   142 		p->current_loan += loan;
   149 		p->current_loan += loan;
   143 		UpdatePlayerMoney32(p);
   150 		UpdatePlayerMoney32(p);
   144 		InvalidatePlayerWindows(p);
   151 		InvalidatePlayerWindows(p);
   145 	}
   152 	}
   149 
   156 
   150 /** Decrease the loan of your company.
   157 /** Decrease the loan of your company.
   151  * @param tile unused
   158  * @param tile unused
   152  * @param flags operation to perform
   159  * @param flags operation to perform
   153  * @param p1 unused
   160  * @param p1 unused
   154  * @param p2 when set, pays back the maximum loan permitting money (press CTRL)
   161  * @param p2 when 0: pays back LOAN_INTERVAL
   155  */
   162  *           when 1: pays back the maximum loan permitting money (press CTRL),
   156 int32 CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   163  */
   157 {
   164 CommandCost CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   158 	Player *p;
   165 {
       
   166 	Player *p = GetPlayer(_current_player);
       
   167 
       
   168 	if (p->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED);
       
   169 
   159 	int32 loan;
   170 	int32 loan;
   160 
   171 	switch (p2) {
   161 	p = GetPlayer(_current_player);
   172 		default: return CMD_ERROR; // Invalid method
   162 
   173 		case 0: // Pay back one step
   163 	if (p->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED);
   174 			loan = min(p->current_loan, (IsHumanPlayer(_current_player) || _patches.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI);
   164 
   175 			break;
   165 	loan = p->current_loan;
   176 		case 1: // Pay back as much as possible
   166 
   177 			loan = max(min(p->current_loan, p->player_money), (int32)LOAN_INTERVAL);
   167 	/* p2 is true while CTRL is pressed (repay all possible loan, or max money you have)
   178 			loan -= loan % LOAN_INTERVAL;
   168 	 * Repay any loan in chunks of 10.000 pounds */
   179 			break;
   169 	if (p2) {
       
   170 		loan = min(loan, p->player_money);
       
   171 		loan = max(loan, 10000);
       
   172 		loan -= loan % 10000;
       
   173 	} else {
       
   174 		loan = min(loan, (IsHumanPlayer(_current_player) || _patches.ainew_active) ? 10000 : 50000);
       
   175 	}
   180 	}
   176 
   181 
   177 	if (p->player_money < loan) {
   182 	if (p->player_money < loan) {
   178 		SetDParam(0, loan);
   183 		SetDParam(0, loan);
   179 		return_cmd_error(STR_702E_REQUIRED);
   184 		return_cmd_error(STR_702E_REQUIRED);
   192  * @param tile unused
   197  * @param tile unused
   193  * @param flags operation to perform
   198  * @param flags operation to perform
   194  * @param p1 unused
   199  * @param p1 unused
   195  * @param p2 unused
   200  * @param p2 unused
   196  */
   201  */
   197 int32 CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   202 CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   198 {
   203 {
   199 	StringID str;
   204 	StringID str;
   200 	Player *p;
   205 	Player *p;
   201 
   206 
   202 	if (_cmd_text[0] == '\0') return CMD_ERROR;
   207 	if (_cmd_text[0] == '\0') return CMD_ERROR;
   220  * @param tile unused
   225  * @param tile unused
   221  * @param flags operation to perform
   226  * @param flags operation to perform
   222  * @param p1 unused
   227  * @param p1 unused
   223  * @param p2 unused
   228  * @param p2 unused
   224  */
   229  */
   225 int32 CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   230 CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   226 {
   231 {
   227 	StringID str;
   232 	StringID str;
   228 	Player *p;
   233 	Player *p;
   229 
   234 
   230 	if (_cmd_text[0] == '\0') return CMD_ERROR;
   235 	if (_cmd_text[0] == '\0') return CMD_ERROR;
   259  * @param tile unused
   264  * @param tile unused
   260  * @param flags operation to perform
   265  * @param flags operation to perform
   261  * @param p1 0 = decrease pause counter; 1 = increase pause counter
   266  * @param p1 0 = decrease pause counter; 1 = increase pause counter
   262  * @param p2 unused
   267  * @param p2 unused
   263  */
   268  */
   264 int32 CmdPause(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   269 CommandCost CmdPause(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   265 {
   270 {
   266 	if (flags & DC_EXEC) {
   271 	if (flags & DC_EXEC) {
   267 		_pause_game += (p1 == 1) ? 1 : -1;
   272 		_pause_game += (p1 == 1) ? 1 : -1;
   268 		if (_pause_game == (byte)-1) _pause_game = 0;
   273 		if (_pause_game == (byte)-1) _pause_game = 0;
   269 		InvalidateWindow(WC_STATUS_BAR, 0);
   274 		InvalidateWindow(WC_STATUS_BAR, 0);
   278  * @param tile unused
   283  * @param tile unused
   279  * @param flags operation to perform
   284  * @param flags operation to perform
   280  * @param p1 the amount of money to receive (if negative), or spend (if positive)
   285  * @param p1 the amount of money to receive (if negative), or spend (if positive)
   281  * @param p2 unused
   286  * @param p2 unused
   282  */
   287  */
   283 int32 CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   288 CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   284 {
   289 {
   285 #ifndef _DEBUG
   290 #ifndef _DEBUG
   286 	if (_networking) return CMD_ERROR;
   291 	if (_networking) return CMD_ERROR;
   287 #endif
   292 #endif
   288 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
   293 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
   296  * @param tile unused
   301  * @param tile unused
   297  * @param flags operation to perform
   302  * @param flags operation to perform
   298  * @param p1 the amount of money to transfer; max 20.000.000
   303  * @param p1 the amount of money to transfer; max 20.000.000
   299  * @param p2 the player to transfer the money to
   304  * @param p2 the player to transfer the money to
   300  */
   305  */
   301 int32 CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   306 CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   302 {
   307 {
   303 	const Player *p = GetPlayer(_current_player);
   308 	const Player *p = GetPlayer(_current_player);
   304 	int32 amount = min((int32)p1, 20000000);
   309 	CommandCost amount = min((int32)p1, 20000000);
   305 
   310 
   306 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
   311 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
   307 
   312 
   308 	/* You can only transfer funds that is in excess of your loan */
   313 	/* You can only transfer funds that is in excess of your loan */
   309 	if (p->money64 - p->current_loan < amount || amount <= 0) return CMD_ERROR;
   314 	if (p->money64 - p->current_loan < amount || amount <= 0) return CMD_ERROR;
   329  * @param flags operation to perform
   334  * @param flags operation to perform
   330  * @param p1 the difficulty setting being changed. If it is -1, the difficulty level
   335  * @param p1 the difficulty setting being changed. If it is -1, the difficulty level
   331  *           itself is changed. The new value is inside p2
   336  *           itself is changed. The new value is inside p2
   332  * @param p2 new value for a difficulty setting or difficulty level
   337  * @param p2 new value for a difficulty setting or difficulty level
   333  */
   338  */
   334 int32 CmdChangeDifficultyLevel(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   339 CommandCost CmdChangeDifficultyLevel(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   335 {
   340 {
   336 	if (p1 != (uint32)-1L && ((int32)p1 >= GAME_DIFFICULTY_NUM || (int32)p1 < 0)) return CMD_ERROR;
   341 	if (p1 != (uint32)-1L && ((int32)p1 >= GAME_DIFFICULTY_NUM || (int32)p1 < 0)) return CMD_ERROR;
   337 
   342 
   338 	if (flags & DC_EXEC) {
   343 	if (flags & DC_EXEC) {
   339 		if (p1 != (uint32)-1L) {
   344 		if (p1 != (uint32)-1L) {