2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
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"
|
2004-12-04 17:54:56 +00:00
|
|
|
#include "network.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Change the player's face.
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 face bitmasked
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
|
|
|
int32 CmdSetPlayerFace(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
|
|
|
if (flags & DC_EXEC) {
|
2005-05-06 06:56:30 +00:00
|
|
|
GetPlayer(_current_player)->face = p2;
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Change the player's company-colour
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 new colour for vehicles, property, etc.
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
|
|
|
int32 CmdSetPlayerColor(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
2005-05-11 00:00:27 +00:00
|
|
|
Player *p, *pp;
|
2005-07-21 06:31:02 +00:00
|
|
|
byte colour;
|
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
|
|
|
|
2005-05-06 06:56:30 +00:00
|
|
|
p = GetPlayer(_current_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/* Ensure no two companies have the same colour */
|
2004-08-09 17:04:08 +00:00
|
|
|
FOR_ALL_PLAYERS(pp) {
|
2005-05-30 15:50:20 +00:00
|
|
|
if (pp->is_active && pp != p && pp->player_color == colour)
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2005-05-30 15:50:20 +00:00
|
|
|
_player_colors[_current_player] = colour;
|
|
|
|
p->player_color = colour;
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Increase the loan of your company.
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 when set, loans the maximum amount in one go (press CTRL)
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 CmdIncreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
|
|
|
Player *p;
|
|
|
|
|
2005-05-06 06:56:30 +00:00
|
|
|
p = GetPlayer(_current_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (p->current_loan >= _economy.max_loan) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, _economy.max_loan);
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2005-05-11 00:00:27 +00:00
|
|
|
/* Loan the maximum amount or not? */
|
(svn r3313) Remove GPMI related changes from trunk
Revisions in detail: 2542, 3226 (partial), 3229, 3231, 3232, 3238, 3242-3245, 3251, 3253, 3260, 3263, 3265, 3266, 3269, 3277, 3278, 3279, 3283 (partial), 3304, 3305, 3306
2005-12-18 12:10:46 +00:00
|
|
|
int32 loan = (p2) ? _economy.max_loan - p->current_loan : (IS_HUMAN_PLAYER(_current_player) || _patches.ainew_active) ? 10000 : 50000;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
p->money64 += loan;
|
|
|
|
p->current_loan += loan;
|
2004-08-09 17:04:08 +00:00
|
|
|
UpdatePlayerMoney32(p);
|
|
|
|
InvalidatePlayerWindows(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Decrease the loan of your company.
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 when set, pays back the maximum loan permitting money (press CTRL)
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 CmdDecreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
|
|
|
Player *p;
|
2005-05-11 00:00:27 +00:00
|
|
|
int32 loan;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-06 06:56:30 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
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 {
|
(svn r3313) Remove GPMI related changes from trunk
Revisions in detail: 2542, 3226 (partial), 3229, 3231, 3232, 3238, 3242-3245, 3251, 3253, 3260, 3263, 3265, 3266, 3269, 3277, 3278, 3279, 3283 (partial), 3304, 3305, 3306
2005-12-18 12:10:46 +00:00
|
|
|
loan = min(loan, (IS_HUMAN_PLAYER(_current_player) || _patches.ainew_active) ? 10000 : 50000);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (p->player_money < loan) {
|
|
|
|
SetDParam(0, loan);
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_702E_REQUIRED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2005-05-11 00:00:27 +00:00
|
|
|
p->money64 -= loan;
|
|
|
|
p->current_loan -= loan;
|
2004-08-09 17:04:08 +00:00
|
|
|
UpdatePlayerMoney32(p);
|
|
|
|
InvalidatePlayerWindows(p);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Change the name of the company.
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 CmdChangeCompanyName(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
2005-05-11 12:46:19 +00:00
|
|
|
StringID str;
|
2004-08-09 17:04:08 +00:00
|
|
|
Player *p;
|
|
|
|
|
2005-05-17 20:58:58 +00:00
|
|
|
if (_cmd_text[0] == '\0') return CMD_ERROR;
|
|
|
|
|
2005-05-15 18:50:55 +00:00
|
|
|
str = AllocateNameUnique(_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();
|
2005-05-11 12:46:19 +00:00
|
|
|
} else
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteName(str);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Change the name of the president.
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 CmdChangePresidentName(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
2005-05-11 12:46:19 +00:00
|
|
|
StringID str;
|
2004-08-09 17:04:08 +00:00
|
|
|
Player *p;
|
|
|
|
|
2005-05-17 20:58:58 +00:00
|
|
|
if (_cmd_text[0] == '\0') return CMD_ERROR;
|
|
|
|
|
2005-05-15 18:50:55 +00:00
|
|
|
str = AllocateNameUnique(_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;
|
2005-05-11 12:46:19 +00:00
|
|
|
DoCommandByTile(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();
|
2005-05-11 12:46:19 +00:00
|
|
|
} else
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteName(str);
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
return 0;
|
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.
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 0 = decrease pause counter; 1 = increase pause counter
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 CmdPause(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
|
|
|
if (flags & DC_EXEC) {
|
2005-01-24 21:33:44 +00:00
|
|
|
_pause += (p1 == 1) ? 1 : -1;
|
|
|
|
if (_pause == (byte)-1) _pause = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
InvalidateWindow(WC_STATUS_BAR, 0);
|
|
|
|
InvalidateWindow(WC_MAIN_TOOLBAR, 0);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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).
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 the amount of money to receive (if negative), or spend (if positive)
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 CmdMoneyCheat(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
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);
|
2004-08-09 17:04:08 +00:00
|
|
|
return (int32)p1;
|
|
|
|
}
|
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
/** Transfer funds (money) from one player to another.
|
2005-05-13 17:09:05 +00:00
|
|
|
* To prevent abuse in multiplayer games you can only send money to other
|
|
|
|
* players if you have paid off your loan (either explicitely, or implicitely
|
|
|
|
* given the fact that you have more money than loan).
|
2005-05-12 23:46:01 +00:00
|
|
|
* @param x,y unused
|
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
|
|
|
|
*/
|
2004-12-04 17:54:56 +00:00
|
|
|
int32 CmdGiveMoney(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
2005-06-21 16:28:17 +00:00
|
|
|
const Player *p = GetPlayer(_current_player);
|
2005-05-13 17:09:05 +00:00
|
|
|
int32 amount = min((int32)p1, 20000000);
|
|
|
|
|
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 */
|
|
|
|
if (p->money64 - p->current_loan < amount || amount <= 0) return CMD_ERROR;
|
|
|
|
if (!_networking || p2 >= MAX_PLAYERS) 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;
|
2004-12-04 17:54:56 +00:00
|
|
|
_current_player = p2;
|
2005-05-13 17:09:05 +00:00
|
|
|
SubtractMoneyFromPlayer(-amount);
|
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
|
|
|
|
* @param x,y unused
|
|
|
|
* @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
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 CmdChangeDifficultyLevel(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
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
|
2005-03-12 21:21:47 +00:00
|
|
|
} else
|
|
|
|
_opt_ptr->diff_level = p2;
|
|
|
|
|
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
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
return 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|