2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/** @file misc_cmd.cpp */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2005-02-06 13:41:02 +00:00
|
|
|
#include "string.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "command.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "window.h"
|
2005-03-12 21:21:47 +00:00
|
|
|
#include "gui.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "economy.h"
|
2007-01-02 17:34:03 +00:00
|
|
|
#include "network/network.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2006-09-15 12:27:00 +00:00
|
|
|
#include "livery.h"
|
2007-03-02 01:17:11 +00:00
|
|
|
#include "player_face.h"
|
2007-06-27 20:53:25 +00:00
|
|
|
#include "strings.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Change the player's face.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-18 18:00:33 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 face bitmasked
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdSetPlayerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-02 01:17:11 +00:00
|
|
|
PlayerFace pf = (PlayerFace)p2;
|
|
|
|
|
|
|
|
if (!IsValidPlayerFace(pf)) return CMD_ERROR;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2007-03-02 01:17:11 +00:00
|
|
|
GetPlayer(_current_player)->face = pf;
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Change the player's company-colour
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2006-09-15 12:27:00 +00:00
|
|
|
* @param p1 bitstuffed:
|
|
|
|
* p1 bits 0-7 scheme to set
|
|
|
|
* p1 bits 8-9 set in use state or first/second colour
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p2 new colour for vehicles, property, etc.
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-05-11 00:00:27 +00:00
|
|
|
Player *p, *pp;
|
2005-07-21 06:31:02 +00:00
|
|
|
byte colour;
|
2007-01-10 18:56:51 +00:00
|
|
|
LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
|
2006-09-15 12:27:00 +00:00
|
|
|
byte state = GB(p1, 8, 2);
|
2005-05-30 15:50:20 +00:00
|
|
|
|
|
|
|
if (p2 >= 16) return CMD_ERROR; // max 16 colours
|
2005-07-21 06:31:02 +00:00
|
|
|
colour = p2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-09-15 12:27:00 +00:00
|
|
|
if (scheme >= LS_END || state >= 3) return CMD_ERROR;
|
|
|
|
|
2005-05-06 06:56:30 +00:00
|
|
|
p = GetPlayer(_current_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-09-15 12:27:00 +00:00
|
|
|
/* Ensure no two companies have the same primary colour */
|
|
|
|
if (scheme == LS_DEFAULT && state == 0) {
|
|
|
|
FOR_ALL_PLAYERS(pp) {
|
|
|
|
if (pp->is_active && pp != p && pp->player_color == colour) return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2006-09-15 12:27:00 +00:00
|
|
|
switch (state) {
|
|
|
|
case 0:
|
|
|
|
p->livery[scheme].colour1 = colour;
|
|
|
|
|
|
|
|
/* If setting the first colour of the default scheme, adjust the
|
|
|
|
* original and cached player colours too. */
|
|
|
|
if (scheme == LS_DEFAULT) {
|
|
|
|
_player_colors[_current_player] = colour;
|
|
|
|
p->player_color = colour;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
p->livery[scheme].colour2 = colour;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
p->livery[scheme].in_use = colour != 0;
|
|
|
|
|
|
|
|
/* Now handle setting the default scheme's in_use flag.
|
|
|
|
* This is different to the other schemes, as it signifies if any
|
|
|
|
* scheme is active at all. If this flag is not set, then no
|
|
|
|
* processing of vehicle types occurs at all, and only the default
|
|
|
|
* colours will be used. */
|
|
|
|
|
|
|
|
/* If enabling a scheme, set the default scheme to be in use too */
|
|
|
|
if (colour != 0) {
|
|
|
|
p->livery[LS_DEFAULT].in_use = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Else loop through all schemes to see if any are left enabled.
|
|
|
|
* If not, disable the default scheme too. */
|
|
|
|
p->livery[LS_DEFAULT].in_use = false;
|
|
|
|
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
|
|
|
|
if (p->livery[scheme].in_use) {
|
|
|
|
p->livery[LS_DEFAULT].in_use = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Increase the loan of your company.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p1 unused
|
2007-06-14 15:24:34 +00:00
|
|
|
* @param p2 when 0: loans LOAN_INTERVAL
|
|
|
|
* when 1: loans the maximum loan permitting money (press CTRL),
|
2005-05-11 00:00:27 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-14 15:24:34 +00:00
|
|
|
Player *p = GetPlayer(_current_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (p->current_loan >= _economy.max_loan) {
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, _economy.max_loan);
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN);
|
|
|
|
}
|
|
|
|
|
2007-06-18 21:44:47 +00:00
|
|
|
Money loan;
|
2007-06-14 15:24:34 +00:00
|
|
|
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;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-19 00:05:26 +00:00
|
|
|
/* Overflow protection */
|
|
|
|
if (p->player_money + p->current_loan + loan < p->player_money) return CMD_ERROR;
|
|
|
|
|
2007-06-14 15:24:34 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2007-06-18 21:00:14 +00:00
|
|
|
p->player_money += loan;
|
2005-05-11 00:00:27 +00:00
|
|
|
p->current_loan += loan;
|
2004-08-09 17:04:08 +00:00
|
|
|
InvalidatePlayerWindows(p);
|
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Decrease the loan of your company.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p1 unused
|
2007-06-14 15:24:34 +00:00
|
|
|
* @param p2 when 0: pays back LOAN_INTERVAL
|
|
|
|
* when 1: pays back the maximum loan permitting money (press CTRL),
|
2005-05-11 00:00:27 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-14 15:24:34 +00:00
|
|
|
Player *p = GetPlayer(_current_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (p->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED);
|
|
|
|
|
2007-06-19 00:05:26 +00:00
|
|
|
Money loan;
|
2007-06-14 15:24:34 +00:00
|
|
|
switch (p2) {
|
|
|
|
default: return CMD_ERROR; // Invalid method
|
|
|
|
case 0: // Pay back one step
|
2007-06-21 14:54:51 +00:00
|
|
|
loan = min(p->current_loan, (Money)(IsHumanPlayer(_current_player) || _patches.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI);
|
2007-06-14 15:24:34 +00:00
|
|
|
break;
|
|
|
|
case 1: // Pay back as much as possible
|
2007-06-19 00:05:26 +00:00
|
|
|
loan = max(min(p->current_loan, p->player_money), (Money)LOAN_INTERVAL);
|
2007-06-14 15:24:34 +00:00
|
|
|
loan -= loan % LOAN_INTERVAL;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (p->player_money < loan) {
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, loan);
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_702E_REQUIRED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2007-06-18 21:00:14 +00:00
|
|
|
p->player_money -= loan;
|
2005-05-11 00:00:27 +00:00
|
|
|
p->current_loan -= loan;
|
2004-08-09 17:04:08 +00:00
|
|
|
InvalidatePlayerWindows(p);
|
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-27 20:53:25 +00:00
|
|
|
static bool IsUniqueCompanyName(const char *name)
|
|
|
|
{
|
|
|
|
const Player *p;
|
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
FOR_ALL_PLAYERS(p) {
|
2007-06-28 19:14:29 +00:00
|
|
|
if (!p->is_active) continue;
|
2007-06-27 20:53:25 +00:00
|
|
|
SetDParam(0, p->index);
|
|
|
|
GetString(buf, STR_COMPANY_NAME, lastof(buf));
|
|
|
|
if (strcmp(buf, name) == 0) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Change the name of the company.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-05-11 12:46:19 +00:00
|
|
|
StringID str;
|
2004-08-09 17:04:08 +00:00
|
|
|
Player *p;
|
|
|
|
|
2007-06-27 20:53:25 +00:00
|
|
|
if (StrEmpty(_cmd_text)) return CMD_ERROR;
|
|
|
|
|
|
|
|
if (!IsUniqueCompanyName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
|
2005-05-17 20:58:58 +00:00
|
|
|
|
2007-06-27 20:53:25 +00:00
|
|
|
str = AllocateName(_cmd_text, 4);
|
2005-05-11 00:00:27 +00:00
|
|
|
if (str == 0) return CMD_ERROR;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2005-06-21 16:28:17 +00:00
|
|
|
p = GetPlayer(_current_player);
|
2005-05-11 12:46:19 +00:00
|
|
|
DeleteName(p->name_1);
|
2004-08-09 17:04:08 +00:00
|
|
|
p->name_1 = str;
|
|
|
|
MarkWholeScreenDirty();
|
2006-06-27 21:25:53 +00:00
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteName(str);
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-27 20:53:25 +00:00
|
|
|
static bool IsUniquePresidentName(const char *name)
|
|
|
|
{
|
|
|
|
const Player *p;
|
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
FOR_ALL_PLAYERS(p) {
|
2007-06-28 19:14:29 +00:00
|
|
|
if (!p->is_active) continue;
|
2007-06-27 20:53:25 +00:00
|
|
|
SetDParam(0, p->index);
|
|
|
|
GetString(buf, STR_PLAYER_NAME, lastof(buf));
|
|
|
|
if (strcmp(buf, name) == 0) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Change the name of the president.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-05-11 12:46:19 +00:00
|
|
|
StringID str;
|
2004-08-09 17:04:08 +00:00
|
|
|
Player *p;
|
|
|
|
|
2007-06-27 20:53:25 +00:00
|
|
|
if (StrEmpty(_cmd_text)) return CMD_ERROR;
|
|
|
|
|
|
|
|
if (!IsUniquePresidentName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
|
2005-05-17 20:58:58 +00:00
|
|
|
|
2007-06-27 20:53:25 +00:00
|
|
|
str = AllocateName(_cmd_text, 4);
|
2005-05-11 00:00:27 +00:00
|
|
|
if (str == 0) return CMD_ERROR;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2005-06-21 16:28:17 +00:00
|
|
|
p = GetPlayer(_current_player);
|
2005-05-11 12:46:19 +00:00
|
|
|
DeleteName(p->president_name_1);
|
2004-08-09 17:04:08 +00:00
|
|
|
p->president_name_1 = str;
|
|
|
|
|
|
|
|
if (p->name_1 == STR_SV_UNNAMED) {
|
2005-05-15 18:50:55 +00:00
|
|
|
char buf[80];
|
|
|
|
|
|
|
|
snprintf(buf, lengthof(buf), "%s Transport", _cmd_text);
|
|
|
|
_cmd_text = buf;
|
2006-04-10 07:15:58 +00:00
|
|
|
DoCommand(0, 0, 0, DC_EXEC, CMD_CHANGE_COMPANY_NAME);
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkWholeScreenDirty();
|
2006-06-27 21:25:53 +00:00
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteName(str);
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 00:11:37 +00:00
|
|
|
/** Pause/Unpause the game (server-only).
|
|
|
|
* Increase or decrease the pause counter. If the counter is zero,
|
|
|
|
* the game is unpaused. A counter is used instead of a boolean value
|
|
|
|
* to have more control over the game when saving/loading, etc.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-12 00:11:37 +00:00
|
|
|
* @param p1 0 = decrease pause counter; 1 = increase pause counter
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdPause(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (flags & DC_EXEC) {
|
2007-03-06 20:59:52 +00:00
|
|
|
_pause_game += (p1 == 1) ? 1 : -1;
|
|
|
|
if (_pause_game == (byte)-1) _pause_game = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
InvalidateWindow(WC_STATUS_BAR, 0);
|
|
|
|
InvalidateWindow(WC_MAIN_TOOLBAR, 0);
|
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
/** Change the financial flow of your company.
|
|
|
|
* This is normally only enabled in offline mode, but if there is a debug
|
|
|
|
* build, you can cheat (to test).
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-12 23:46:01 +00:00
|
|
|
* @param p1 the amount of money to receive (if negative), or spend (if positive)
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-05-12 23:46:01 +00:00
|
|
|
#ifndef _DEBUG
|
|
|
|
if (_networking) return CMD_ERROR;
|
|
|
|
#endif
|
2004-09-10 19:02:27 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_OTHER);
|
2007-06-18 21:44:47 +00:00
|
|
|
return CommandCost(-(Money)p1);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
/** Transfer funds (money) from one player to another.
|
2006-08-28 18:53:03 +00:00
|
|
|
* To prevent abuse in multiplayer games you can only send money to other
|
2005-05-13 17:09:05 +00:00
|
|
|
* players if you have paid off your loan (either explicitely, or implicitely
|
|
|
|
* given the fact that you have more money than loan).
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-13 17:09:05 +00:00
|
|
|
* @param p1 the amount of money to transfer; max 20.000.000
|
2005-05-12 23:46:01 +00:00
|
|
|
* @param p2 the player to transfer the money to
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-12-04 17:54:56 +00:00
|
|
|
{
|
2005-06-21 16:28:17 +00:00
|
|
|
const Player *p = GetPlayer(_current_player);
|
2007-06-21 14:54:51 +00:00
|
|
|
CommandCost amount(min((Money)p1, (Money)20000000LL));
|
2005-05-13 17:09:05 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_OTHER);
|
|
|
|
|
2005-05-13 17:09:05 +00:00
|
|
|
/* You can only transfer funds that is in excess of your loan */
|
2007-06-18 21:00:14 +00:00
|
|
|
if (p->player_money - p->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR;
|
2006-10-14 22:31:18 +00:00
|
|
|
if (!_networking || !IsValidPlayer((PlayerID)p2)) return CMD_ERROR;
|
2004-12-28 09:24:02 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2005-05-13 17:09:05 +00:00
|
|
|
/* Add money to player */
|
2005-05-12 23:46:01 +00:00
|
|
|
PlayerID old_cp = _current_player;
|
2007-01-10 18:56:51 +00:00
|
|
|
_current_player = (PlayerID)p2;
|
2007-06-18 19:53:50 +00:00
|
|
|
SubtractMoneyFromPlayer(CommandCost(-amount.GetCost()));
|
2004-12-04 17:54:56 +00:00
|
|
|
_current_player = old_cp;
|
|
|
|
}
|
|
|
|
|
2005-05-13 17:09:05 +00:00
|
|
|
/* Subtract money from local-player */
|
|
|
|
return amount;
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 00:11:37 +00:00
|
|
|
/** Change difficulty level/settings (server-only).
|
|
|
|
* We cannot really check for valid values of p2 (too much work mostly); stored
|
|
|
|
* in file 'settings_gui.c' _game_setting_info[]; we'll just trust the server it knows
|
|
|
|
* what to do and does this correctly
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-12 00:11:37 +00:00
|
|
|
* @param p1 the difficulty setting being changed. If it is -1, the difficulty level
|
|
|
|
* itself is changed. The new value is inside p2
|
|
|
|
* @param p2 new value for a difficulty setting or difficulty level
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdChangeDifficultyLevel(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-05-30 14:45:36 +00:00
|
|
|
if (p1 != (uint32)-1L && ((int32)p1 >= GAME_DIFFICULTY_NUM || (int32)p1 < 0)) return CMD_ERROR;
|
2005-05-12 00:11:37 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
if (p1 != (uint32)-1L) {
|
2005-03-12 21:21:47 +00:00
|
|
|
((int*)&_opt_ptr->diff)[p1] = p2;
|
2005-05-12 00:11:37 +00:00
|
|
|
_opt_ptr->diff_level = 3; // custom difficulty level
|
2006-06-27 21:25:53 +00:00
|
|
|
} else {
|
2005-03-12 21:21:47 +00:00
|
|
|
_opt_ptr->diff_level = p2;
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2005-03-12 21:21:47 +00:00
|
|
|
|
2005-05-12 00:11:37 +00:00
|
|
|
/* If we are a network-client, update the difficult setting (if it is open).
|
|
|
|
* Use this instead of just dirtying the window because we need to load in
|
2005-05-30 14:45:36 +00:00
|
|
|
* the new difficulty settings */
|
2004-12-04 17:54:56 +00:00
|
|
|
if (_networking && !_network_server && FindWindowById(WC_GAME_OPTIONS, 0) != NULL)
|
2005-03-12 21:21:47 +00:00
|
|
|
ShowGameDifficulty();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|