src/misc_cmd.cpp
author peter1138
Sat, 12 Jan 2008 19:58:06 +0000
changeset 8258 9fa31acb07bc
parent 8254 1496654ca5e7
child 8264 b1e85998c7d3
permissions -rw-r--r--
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
no limit to the amount of names.
-Fix: NewGRF engines could not be renamed.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6190
diff changeset
     3
/** @file misc_cmd.cpp */
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6190
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 193
diff changeset
     7
#include "table/strings.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
     8
#include "command_func.h"
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
     9
#include "economy_func.h"
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1328
diff changeset
    10
#include "gui.h"
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    11
#include "window_func.h"
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    12
#include "textbuf_gui.h"
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 4850
diff changeset
    13
#include "network/network.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    14
#include "variables.h"
4603
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    15
#include "livery.h"
6190
01a2b579b668 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 5587
diff changeset
    16
#include "player_face.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8107
diff changeset
    17
#include "strings_func.h"
8123
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8121
diff changeset
    18
#include "gfx_func.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8123
diff changeset
    19
#include "functions.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8131
diff changeset
    20
#include "vehicle_func.h"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8144
diff changeset
    21
#include "string_func.h"
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8230
diff changeset
    22
#include "player_func.h"
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8230
diff changeset
    23
#include "player_base.h"
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8230
diff changeset
    24
#include "player_gui.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
    26
/** Change the player's face.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 2767
diff changeset
    27
 * @param tile unused
6488
b6c42e91bb35 (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6481
diff changeset
    28
 * @param flags operation to perform
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
    29
 * @param p1 unused
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
    30
 * @param p2 face bitmasked
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6909
diff changeset
    32
CommandCost CmdSetPlayerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
{
6190
01a2b579b668 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 5587
diff changeset
    34
	PlayerFace pf = (PlayerFace)p2;
01a2b579b668 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 5587
diff changeset
    35
01a2b579b668 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 5587
diff changeset
    36
	if (!IsValidPlayerFace(pf)) return CMD_ERROR;
01a2b579b668 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 5587
diff changeset
    37
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	if (flags & DC_EXEC) {
6190
01a2b579b668 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 5587
diff changeset
    39
		GetPlayer(_current_player)->face = pf;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
	}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
    42
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
    45
/** Change the player's company-colour
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 2767
diff changeset
    46
 * @param tile unused
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6231
diff changeset
    47
 * @param flags operation to perform
4603
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    48
 * @param p1 bitstuffed:
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    49
 * p1 bits 0-7 scheme to set
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    50
 * p1 bits 8-9 set in use state or first/second colour
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
    51
 * @param p2 new colour for vehicles, property, etc.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6909
diff changeset
    53
CommandCost CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
{
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
    55
	Player *p, *pp;
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 1962
diff changeset
    56
	byte colour;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    57
	LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
4603
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    58
	byte state = GB(p1, 8, 2);
1878
980fabc7d8a5 (svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents: 1877
diff changeset
    59
980fabc7d8a5 (svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents: 1877
diff changeset
    60
	if (p2 >= 16) return CMD_ERROR; // max 16 colours
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 1962
diff changeset
    61
	colour = p2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
4603
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    63
	if (scheme >= LS_END || state >= 3) return CMD_ERROR;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    64
1767
cda2e9ac430a (svn r2271) CMD_SET_PLAYER_FACE, CMD_SET_PLAYER_COLOR, CMD_INCREASE_LOAN, CMD_DECREASE_LOAN only make sense for the current player, so don't explicitly pass a player number
tron
parents: 1728
diff changeset
    65
	p = GetPlayer(_current_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
4603
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    67
	/* Ensure no two companies have the same primary colour */
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    68
	if (scheme == LS_DEFAULT && state == 0) {
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    69
		FOR_ALL_PLAYERS(pp) {
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    70
			if (pp->is_active && pp != p && pp->player_color == colour) return CMD_ERROR;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    71
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 84
diff changeset
    73
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
	if (flags & DC_EXEC) {
4603
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    75
		switch (state) {
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    76
			case 0:
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    77
				p->livery[scheme].colour1 = colour;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    78
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    79
				/* If setting the first colour of the default scheme, adjust the
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    80
				 * original and cached player colours too. */
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    81
				if (scheme == LS_DEFAULT) {
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    82
					_player_colors[_current_player] = colour;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    83
					p->player_color = colour;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    84
				}
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    85
				break;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    86
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    87
			case 1:
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    88
				p->livery[scheme].colour2 = colour;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    89
				break;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    90
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    91
			case 2:
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    92
				p->livery[scheme].in_use = colour != 0;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    93
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    94
				/* Now handle setting the default scheme's in_use flag.
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    95
				 * This is different to the other schemes, as it signifies if any
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    96
				 * scheme is active at all. If this flag is not set, then no
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    97
				 * processing of vehicle types occurs at all, and only the default
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    98
				 * colours will be used. */
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
    99
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   100
				/* If enabling a scheme, set the default scheme to be in use too */
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   101
				if (colour != 0) {
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   102
					p->livery[LS_DEFAULT].in_use = true;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   103
					break;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   104
				}
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   105
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   106
				/* Else loop through all schemes to see if any are left enabled.
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   107
				 * If not, disable the default scheme too. */
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   108
				p->livery[LS_DEFAULT].in_use = false;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   109
				for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   110
					if (p->livery[scheme].in_use) {
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   111
						p->livery[LS_DEFAULT].in_use = true;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   112
						break;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   113
					}
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   114
				}
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   115
				break;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   116
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   117
			default:
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   118
				break;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4434
diff changeset
   119
		}
7802
246a94599679 (svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents: 7742
diff changeset
   120
		ResetVehicleColorMap();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
	}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   123
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   126
/** Increase the loan of your company.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 2767
diff changeset
   127
 * @param tile unused
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6231
diff changeset
   128
 * @param flags operation to perform
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   129
 * @param p1 unused
6909
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   130
 * @param p2 when 0: loans LOAN_INTERVAL
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   131
 *           when 1: loans the maximum loan permitting money (press CTRL),
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   132
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6909
diff changeset
   133
CommandCost CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
{
6909
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   135
	Player *p = GetPlayer(_current_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
	if (p->current_loan >= _economy.max_loan) {
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   138
		SetDParam(0, _economy.max_loan);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
		return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
6953
230d1e3ac86c (svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium
parents: 6952
diff changeset
   142
	Money loan;
6909
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   143
	switch (p2) {
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   144
		default: return CMD_ERROR; // Invalid method
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   145
		case 0: // Take some extra loan
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   146
			loan = (IsHumanPlayer(_current_player) || _patches.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI;
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   147
			break;
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   148
		case 1: // Take a loan as big as possible
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   149
			loan = _economy.max_loan - p->current_loan;
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   150
			break;
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   151
	}
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   152
6957
a9af2426bf77 (svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium
parents: 6953
diff changeset
   153
	/* Overflow protection */
a9af2426bf77 (svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium
parents: 6953
diff changeset
   154
	if (p->player_money + p->current_loan + loan < p->player_money) return CMD_ERROR;
a9af2426bf77 (svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium
parents: 6953
diff changeset
   155
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
	if (flags & DC_EXEC) {
6952
b19643469024 (svn r10207) -Codechange: remove the redundant player_money in favour of the money64, which is now renamed to player_money.
rubidium
parents: 6950
diff changeset
   157
		p->player_money += loan;
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   158
		p->current_loan += loan;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
		InvalidatePlayerWindows(p);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8214
diff changeset
   162
	return CommandCost(EXPENSES_OTHER);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   165
/** Decrease the loan of your company.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 2767
diff changeset
   166
 * @param tile unused
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6231
diff changeset
   167
 * @param flags operation to perform
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   168
 * @param p1 unused
6909
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   169
 * @param p2 when 0: pays back LOAN_INTERVAL
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   170
 *           when 1: pays back the maximum loan permitting money (press CTRL),
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   171
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6909
diff changeset
   172
CommandCost CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
{
6909
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   174
	Player *p = GetPlayer(_current_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   176
	if (p->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
6957
a9af2426bf77 (svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium
parents: 6953
diff changeset
   178
	Money loan;
6909
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   179
	switch (p2) {
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   180
		default: return CMD_ERROR; // Invalid method
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   181
		case 0: // Pay back one step
6991
bf9cd2a47774 (svn r10247) -Fix (r10210): *always* call SetDParamMoney when you want to place money in some string.
rubidium
parents: 6957
diff changeset
   182
			loan = min(p->current_loan, (Money)(IsHumanPlayer(_current_player) || _patches.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI);
6909
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   183
			break;
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   184
		case 1: // Pay back as much as possible
6957
a9af2426bf77 (svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium
parents: 6953
diff changeset
   185
			loan = max(min(p->current_loan, p->player_money), (Money)LOAN_INTERVAL);
6909
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   186
			loan -= loan % LOAN_INTERVAL;
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6488
diff changeset
   187
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   190
	if (p->player_money < loan) {
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   191
		SetDParam(0, loan);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
		return_cmd_error(STR_702E_REQUIRED);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
	if (flags & DC_EXEC) {
6952
b19643469024 (svn r10207) -Codechange: remove the redundant player_money in favour of the money64, which is now renamed to player_money.
rubidium
parents: 6950
diff changeset
   196
		p->player_money -= loan;
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   197
		p->current_loan -= loan;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
		InvalidatePlayerWindows(p);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   200
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   203
static bool IsUniqueCompanyName(const char *name)
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   204
{
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   205
	const Player *p;
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   206
	char buf[512];
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   207
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   208
	FOR_ALL_PLAYERS(p) {
7108
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
   209
		if (!p->is_active) continue;
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   210
		SetDParam(0, p->index);
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   211
		GetString(buf, STR_COMPANY_NAME, lastof(buf));
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   212
		if (strcmp(buf, name) == 0) return false;
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   213
	}
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   214
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   215
	return true;
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   216
}
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   217
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   218
/** Change the name of the company.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 2767
diff changeset
   219
 * @param tile unused
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6231
diff changeset
   220
 * @param flags operation to perform
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   221
 * @param p1 unused
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   222
 * @param p2 unused
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   223
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6909
diff changeset
   224
CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   228
	if (StrEmpty(_cmd_text)) return CMD_ERROR;
1840
ce40137a6ab4 (svn r2345) - Fix: Don't allow stuff to be renamed to nothing if we don't support it. Only valid ones are signs (delete) and waypoints (rename to default).
Darkvater
parents: 1820
diff changeset
   229
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   230
	if (!IsUniqueCompanyName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   231
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	if (flags & DC_EXEC) {
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1891
diff changeset
   233
		p = GetPlayer(_current_player);
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   234
		free(p->name);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   235
		p->name = strdup(_cmd_text);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
		MarkWholeScreenDirty();
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3491
diff changeset
   237
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   239
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   242
static bool IsUniquePresidentName(const char *name)
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   243
{
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   244
	const Player *p;
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   245
	char buf[512];
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   246
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   247
	FOR_ALL_PLAYERS(p) {
7108
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
   248
		if (!p->is_active) continue;
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   249
		SetDParam(0, p->index);
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   250
		GetString(buf, STR_PLAYER_NAME, lastof(buf));
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   251
		if (strcmp(buf, name) == 0) return false;
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   252
	}
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   253
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   254
	return true;
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   255
}
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   256
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   257
/** Change the name of the president.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 2767
diff changeset
   258
 * @param tile unused
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6231
diff changeset
   259
 * @param flags operation to perform
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   260
 * @param p1 unused
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   261
 * @param p2 unused
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1767
diff changeset
   262
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6909
diff changeset
   263
CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   267
	if (StrEmpty(_cmd_text)) return CMD_ERROR;
1840
ce40137a6ab4 (svn r2345) - Fix: Don't allow stuff to be renamed to nothing if we don't support it. Only valid ones are signs (delete) and waypoints (rename to default).
Darkvater
parents: 1820
diff changeset
   268
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   269
	if (!IsUniquePresidentName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7002
diff changeset
   270
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
	if (flags & DC_EXEC) {
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1891
diff changeset
   272
		p = GetPlayer(_current_player);
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   273
		free(p->president_name);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   274
		p->president_name = strdup(_cmd_text);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
		if (p->name_1 == STR_SV_UNNAMED) {
1820
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1799
diff changeset
   277
			char buf[80];
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1799
diff changeset
   278
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1799
diff changeset
   279
			snprintf(buf, lengthof(buf), "%s Transport", _cmd_text);
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1799
diff changeset
   280
			_cmd_text = buf;
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 2767
diff changeset
   281
			DoCommand(0, 0, 0, DC_EXEC, CMD_CHANGE_COMPANY_NAME);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 84
diff changeset
   282
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
		MarkWholeScreenDirty();
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3491
diff changeset
   284
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   286
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
8013
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   289
/**
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   290
 * In case of an unsafe unpause, we want the
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   291
 * user to confirm that it might crash.
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   292
 * @param w         unused
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   293
 * @param confirmed whether the user confirms his/her action
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   294
 */
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   295
static void AskUnsafeUnpauseCallback(Window *w, bool confirmed)
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   296
{
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   297
	DoCommandP(0, confirmed ? 0 : 1, 0, NULL, CMD_PAUSE);
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   298
}
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   299
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   300
/** Pause/Unpause the game (server-only).
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   301
 * Increase or decrease the pause counter. If the counter is zero,
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   302
 * the game is unpaused. A counter is used instead of a boolean value
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   303
 * to have more control over the game when saving/loading, etc.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 2767
diff changeset
   304
 * @param tile unused
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6231
diff changeset
   305
 * @param flags operation to perform
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   306
 * @param p1 0 = decrease pause counter; 1 = increase pause counter
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   307
 * @param p2 unused
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   308
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6909
diff changeset
   309
CommandCost CmdPause(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
	if (flags & DC_EXEC) {
8065
605375063266 (svn r11626) -Fix [FS#1529]: Pause state wasn't set correctly in multiplayer saves
skidd13
parents: 8013
diff changeset
   312
		_pause_game += (p1 == 0) ? -1 : 1;
8013
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   313
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   314
		switch (_pause_game) {
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   315
			case (byte)-4:
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   316
			case (byte)-1:
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   317
				_pause_game = 0;
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   318
				break;
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   319
			case (byte)-3:
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   320
				ShowQuery(
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   321
					STR_NEWGRF_UNPAUSE_WARNING_TITLE,
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   322
					STR_NEWGRF_UNPAUSE_WARNING,
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   323
					NULL,
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   324
					AskUnsafeUnpauseCallback
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   325
				);
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   326
				break;
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   327
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   328
			default: break;
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   329
		}
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 7802
diff changeset
   330
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
		InvalidateWindow(WC_STATUS_BAR, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
		InvalidateWindow(WC_MAIN_TOOLBAR, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
	}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   334
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   337
/** Change the financial flow of your company.
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   338
 * This is normally only enabled in offline mode, but if there is a debug
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   339
 * build, you can cheat (to test).
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 2767
diff changeset
   340
 * @param tile unused
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6231
diff changeset
   341
 * @param flags operation to perform
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   342
 * @param p1 the amount of money to receive (if negative), or spend (if positive)
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   343
 * @param p2 unused
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   344
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6909
diff changeset
   345
CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
{
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   347
#ifndef _DEBUG
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   348
	if (_networking) return CMD_ERROR;
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   349
#endif
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8214
diff changeset
   350
	return CommandCost(EXPENSES_OTHER, -(Money)p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   353
/** Transfer funds (money) from one player to another.
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4077
diff changeset
   354
 * To prevent abuse in multiplayer games you can only send money to other
1799
6d82d202c145 (svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents: 1796
diff changeset
   355
 * players if you have paid off your loan (either explicitely, or implicitely
6d82d202c145 (svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents: 1796
diff changeset
   356
 * given the fact that you have more money than loan).
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 2767
diff changeset
   357
 * @param tile unused
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6231
diff changeset
   358
 * @param flags operation to perform
1799
6d82d202c145 (svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents: 1796
diff changeset
   359
 * @param p1 the amount of money to transfer; max 20.000.000
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   360
 * @param p2 the player to transfer the money to
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   361
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6909
diff changeset
   362
CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   363
{
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7108
diff changeset
   364
	if (!_patches.give_money) return CMD_ERROR;
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7108
diff changeset
   365
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1891
diff changeset
   366
	const Player *p = GetPlayer(_current_player);
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8214
diff changeset
   367
	CommandCost amount(EXPENSES_OTHER, min((Money)p1, (Money)20000000LL));
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   368
1799
6d82d202c145 (svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents: 1796
diff changeset
   369
	/* You can only transfer funds that is in excess of your loan */
6952
b19643469024 (svn r10207) -Codechange: remove the redundant player_money in favour of the money64, which is now renamed to player_money.
rubidium
parents: 6950
diff changeset
   370
	if (p->player_money - p->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR;
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4845
diff changeset
   371
	if (!_networking || !IsValidPlayer((PlayerID)p2)) return CMD_ERROR;
813
640a517dc129 (svn r1284) -Fix: Fixed 'money-cheat' (read: bug which could give people a lot of money)
truelight
parents: 543
diff changeset
   372
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   373
	if (flags & DC_EXEC) {
1799
6d82d202c145 (svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents: 1796
diff changeset
   374
		/* Add money to player */
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1793
diff changeset
   375
		PlayerID old_cp = _current_player;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   376
		_current_player = (PlayerID)p2;
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8214
diff changeset
   377
		SubtractMoneyFromPlayer(CommandCost(EXPENSES_OTHER, -amount.GetCost()));
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   378
		_current_player = old_cp;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   379
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   380
1799
6d82d202c145 (svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents: 1796
diff changeset
   381
	/* Subtract money from local-player */
6d82d202c145 (svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents: 1796
diff changeset
   382
	return amount;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   383
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   384
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   385
/** Change difficulty level/settings (server-only).
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   386
 * We cannot really check for valid values of p2 (too much work mostly); stored
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   387
 * in file 'settings_gui.c' _game_setting_info[]; we'll just trust the server it knows
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   388
 * what to do and does this correctly
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 2767
diff changeset
   389
 * @param tile unused
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6231
diff changeset
   390
 * @param flags operation to perform
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   391
 * @param p1 the difficulty setting being changed. If it is -1, the difficulty level
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   392
 *           itself is changed. The new value is inside p2
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   393
 * @param p2 new value for a difficulty setting or difficulty level
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   394
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6909
diff changeset
   395
CommandCost CmdChangeDifficultyLevel(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
{
1877
ab6a315fa930 (svn r2383) - Fix: Monkey-testing turned up some command crashes.
Darkvater
parents: 1858
diff changeset
   397
	if (p1 != (uint32)-1L && ((int32)p1 >= GAME_DIFFICULTY_NUM || (int32)p1 < 0)) return CMD_ERROR;
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   398
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
		if (p1 != (uint32)-1L) {
7742
ddea89a86f80 (svn r11279) -Codechange: use a typedeffed type for all magic with GameDifficulty instead on relying ints to always be 32 bits, which they are not.
rubidium
parents: 7657
diff changeset
   401
			((GDType*)&_opt_ptr->diff)[p1] = p2;
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   402
			_opt_ptr->diff_level = 3; // custom difficulty level
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3491
diff changeset
   403
		} else {
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1328
diff changeset
   404
			_opt_ptr->diff_level = p2;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3491
diff changeset
   405
		}
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1328
diff changeset
   406
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   407
		/* If we are a network-client, update the difficult setting (if it is open).
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1787
diff changeset
   408
		 * Use this instead of just dirtying the window because we need to load in
1877
ab6a315fa930 (svn r2383) - Fix: Monkey-testing turned up some command crashes.
Darkvater
parents: 1858
diff changeset
   409
		 * the new difficulty settings */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   410
		if (_networking && !_network_server && FindWindowById(WC_GAME_OPTIONS, 0) != NULL)
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1328
diff changeset
   411
			ShowGameDifficulty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
	}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   413
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
}