src/players.cpp
author rubidium
Thu, 01 Feb 2007 15:49:12 +0000
changeset 5893 7e431a4abebb
parent 5868 94430141c189
child 5944 6d059cc8662b
permissions -rw-r--r--
(svn r8511) -Codechange: make WindowClass an enumerated value.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2170
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2170
diff changeset
     2
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
     3
/** @file players.c
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4444
diff changeset
     4
 * @todo Cleanup the messy DrawPlayerFace function asap
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4444
diff changeset
     5
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     7
#include "openttd.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
     8
#include "engine.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     9
#include "functions.h"
1317
3c90086ff34f (svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents: 1309
diff changeset
    10
#include "string.h"
1309
4403a69da4f8 (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1304
diff changeset
    11
#include "strings.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 337
diff changeset
    12
#include "table/strings.h"
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    13
#include "table/sprites.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 670
diff changeset
    14
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "command.h"
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 206
diff changeset
    23
#include "sound.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: 5441
diff changeset
    24
#include "network/network.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    25
#include "variables.h"
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
    26
#include "engine.h"
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2381
diff changeset
    27
#include "ai/ai.h"
4261
28670f743746 (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4260
diff changeset
    28
#include "date.h"
5077
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5073
diff changeset
    29
#include "window.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    31
/**
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    32
 * Sets the local player and updates the patch settings that are set on a
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    33
 * per-company (player) basis to reflect the core's state in the GUI.
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    34
 * @param new_player the new player
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    35
 * @pre IsValidPlayer(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    36
 */
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    37
void SetLocalPlayer(PlayerID new_player)
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    38
{
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    39
	/* Player could also be PLAYER_SPECTATOR or OWNER_NONE */
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    40
	assert(IsValidPlayer(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE);
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    41
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    42
	_local_player = new_player;
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    43
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    44
	/* Do not update the patches if we are in the intro GUI */
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    45
	if (IsValidPlayer(new_player) && _game_mode != GM_MENU) {
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    46
		const Player *p = GetPlayer(new_player);
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    47
		_patches.autorenew        = p->engine_renew;
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    48
		_patches.autorenew_months = p->engine_renew_months;
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    49
		_patches.autorenew_money  = p->engine_renew_money;
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    50
		InvalidateWindow(WC_GAME_OPTIONS, 0);
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    51
	}
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    52
}
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
    53
4428
6d9fab57f2af (svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents: 4344
diff changeset
    54
6d9fab57f2af (svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents: 4344
diff changeset
    55
uint16 GetDrawStringPlayerColor(PlayerID player)
6d9fab57f2af (svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents: 4344
diff changeset
    56
{
4944
f597859bba38 (svn r6932) -Codechange: Send server messages with format NETWORK_ACTION_SERVER_MESSAGE so it is
Darkvater
parents: 4921
diff changeset
    57
	/* Get the color for DrawString-subroutines which matches the color
f597859bba38 (svn r6932) -Codechange: Send server messages with format NETWORK_ACTION_SERVER_MESSAGE so it is
Darkvater
parents: 4921
diff changeset
    58
	 * of the player */
f597859bba38 (svn r6932) -Codechange: Send server messages with format NETWORK_ACTION_SERVER_MESSAGE so it is
Darkvater
parents: 4921
diff changeset
    59
	if (!IsValidPlayer(player)) return _colour_gradient[COLOUR_WHITE][4] | IS_PALETTE_COLOR;
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4428
diff changeset
    60
	return (_colour_gradient[_player_colors[player]][4]) | IS_PALETTE_COLOR;
4428
6d9fab57f2af (svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents: 4344
diff changeset
    61
}
6d9fab57f2af (svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents: 4344
diff changeset
    62
5750
5824ab1f36e2 (svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents: 5692
diff changeset
    63
void DrawPlayerIcon(PlayerID p, int x, int y)
5824ab1f36e2 (svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents: 5692
diff changeset
    64
{
5824ab1f36e2 (svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents: 5692
diff changeset
    65
	DrawSprite(SPR_PLAYER_ICON, PLAYER_SPRITE_COLOR(p), x, y);
5824ab1f36e2 (svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents: 5692
diff changeset
    66
}
5824ab1f36e2 (svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents: 5692
diff changeset
    67
4428
6d9fab57f2af (svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents: 4344
diff changeset
    68
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
static const SpriteID cheeks_table[4] = {
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
    70
	0x325, 0x326,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
	0x390, 0x3B0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
static const SpriteID mouth_table[3] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	0x34C, 0x34D, 0x34F
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
void DrawPlayerFace(uint32 face, int color, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
	byte flag = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
	if ( (int32)face < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
		flag |= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
	if ((((((face >> 7) ^ face) >> 7) ^ face) & 0x8080000) == 0x8000000)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
		flag |= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	/* draw the gradient */
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    88
	DrawSprite(SPR_GRADIENT, GENERAL_SPRITE_COLOR(color), x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
	/* draw the cheeks */
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    91
	DrawSprite(cheeks_table[flag&3], PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	/* draw the chin */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
	/* FIXME: real code uses -2 in zoomlevel 1 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
	{
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2119
diff changeset
    96
		uint val = GB(face, 4, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
		if (!(flag & 2)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    98
			DrawSprite(0x327 + (flag&1?0:val), PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
		} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   100
			DrawSprite((flag&1?0x3B1:0x391) + (val>>1), PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
	/* draw the eyes */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	{
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2119
diff changeset
   105
		uint val1 = GB(face,  6, 4);
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2119
diff changeset
   106
		uint val2 = GB(face, 20, 3);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   107
		SpriteID pal;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   109
		if (val2 < 6) {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   110
			pal = PALETTE_TO_BROWN;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   111
		} else if (val2 == 6) {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   112
			pal = PALETTE_TO_BLUE;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   113
		} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   114
			pal = PALETTE_TO_GREEN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
		if (!(flag & 2)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
			if (!(flag & 1)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   119
				DrawSprite(0x32B + (val1 * 12 >> 4), pal, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
			} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   121
				DrawSprite(0x337 + val1, pal, x, y);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   122
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
			if (!(flag & 1)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   125
				DrawSprite(0x39A + (val1 * 11 >> 4), pal, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
			} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   127
				DrawSprite(0x3B8 + val1, pal, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
	/* draw the mouth */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
	{
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2119
diff changeset
   134
		uint val = GB(face, 10, 6);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
		uint val2;
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 (!(flag&1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
			val2 = ((val&0xF) * 15 >> 4);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   139
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
			if (val2 < 3) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   141
				DrawSprite((flag&2 ? 0x397 : 0x367) + val2, PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
				/* skip the rest */
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   143
				goto skip_mouth;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
			val2 -= 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
			if (flag & 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
				if (val2 > 8) val2 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
				val2 += 0x3A5 - 0x35B;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
			}
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   151
			DrawSprite(val2 + 0x35B, PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
		} else if (!(flag&2)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   153
			DrawSprite(((val&0xF) * 10 >> 4) + 0x351, PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
		} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   155
			DrawSprite(((val&0xF) * 9 >> 4) + 0x3C8, PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
		val >>= 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
		if (!(flag&2)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
			if (!(flag&1)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   162
				DrawSprite(0x349 + val, PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
			} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   164
				DrawSprite( mouth_table[(val*3>>3)], PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
			if (!(flag&1)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   168
				DrawSprite(0x393 + (val&3), PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
			} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   170
				DrawSprite(0x3B3 + (val*5>>3), PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
		skip_mouth:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
	/* draw the hair */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	{
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2119
diff changeset
   180
		uint val = GB(face, 16, 4);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   181
		if (flag & 2) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   182
			if (flag & 1) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   183
				DrawSprite(0x3D9 + (val * 5 >> 4), PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
			} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   185
				DrawSprite(0x3D4 + (val * 5 >> 4), PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
		} else {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   188
			if (flag & 1) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   189
				DrawSprite(0x38B + (val * 5 >> 4), PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
			} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   191
				DrawSprite(0x382 + (val * 9 >> 4), PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
			}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
	/* draw the tie */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
	{
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2119
diff changeset
   198
		uint val = GB(face, 20, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
		if (!(flag&1)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   201
			DrawSprite(0x36B + (GB(val, 0, 2) * 3 >> 2), PAL_NONE, x, y);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   202
			DrawSprite(0x36E + (GB(val, 2, 2) * 4 >> 2), PAL_NONE, x, y);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   203
			DrawSprite(0x372 + (GB(val, 4, 4) * 6 >> 4), PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
		} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   205
			DrawSprite(0x378 + (GB(val, 0, 2) * 3 >> 2), PAL_NONE, x, y);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   206
			DrawSprite(0x37B + (GB(val, 2, 2) * 4 >> 2), PAL_NONE, x, y);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   207
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
			val >>= 4;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   209
			if (val < 3) DrawSprite((flag & 2 ? 0x3D1 : 0x37F) + val, PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
	/* draw the glasses */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
	{
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2119
diff changeset
   215
		uint val = GB(face, 28, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   217
		if (flag & 2) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   218
			if (val <= 1) DrawSprite(0x3AE + val, PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
		} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   220
			if (val <= 1) DrawSprite(0x347 + val, PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
2475
efdcc705cb61 (svn r3001) s/Player*/const Player*/
tron
parents: 2469
diff changeset
   225
void InvalidatePlayerWindows(const Player *p)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
{
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2147
diff changeset
   227
	PlayerID pid = p->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2147
diff changeset
   229
	if (pid == _local_player) InvalidateWindow(WC_STATUS_BAR, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	InvalidateWindow(WC_FINANCES, pid);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
bool CheckPlayerHasMoney(int32 cost)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	if (cost > 0) {
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2484
diff changeset
   236
		PlayerID pid = _current_player;
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4849
diff changeset
   237
		if (IsValidPlayer(pid) && cost > GetPlayer(pid)->player_money) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   238
			SetDParam(0, cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
			_error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
static void SubtractMoneyFromAnyPlayer(Player *p, int32 cost)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
	p->money64 -= cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
	UpdatePlayerMoney32(p);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   250
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
	p->yearly_expenses[0][_yearly_expenses_type] += cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   253
	if (HASBIT(1<<7|1<<8|1<<9|1<<10, _yearly_expenses_type)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
		p->cur_economy.income -= cost;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   255
	} else if (HASBIT(1<<2|1<<3|1<<4|1<<5|1<<6|1<<11, _yearly_expenses_type)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
		p->cur_economy.expenses -= cost;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   257
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   258
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	InvalidatePlayerWindows(p);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
void SubtractMoneyFromPlayer(int32 cost)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
{
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   264
	PlayerID pid = _current_player;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   265
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4849
diff changeset
   266
	if (IsValidPlayer(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
   269
void SubtractMoneyFromPlayerFract(PlayerID player, int32 cost)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
{
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1901
diff changeset
   271
	Player *p = GetPlayer(player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
	byte m = p->player_money_fraction;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   273
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
	p->player_money_fraction = m - (byte)cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	cost >>= 8;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   276
	if (p->player_money_fraction > m) cost++;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   277
	if (cost != 0) SubtractMoneyFromAnyPlayer(p, cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
// the player_money field is kept as it is, but money64 contains the actual amount of money.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
void UpdatePlayerMoney32(Player *p)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
{
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   283
	if (p->money64 < -2000000000) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
		p->player_money = -2000000000;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   285
	} else if (p->money64 > 2000000000) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
		p->player_money = 2000000000;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   287
	} else {
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   288
		p->player_money = (int32)p->money64;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   289
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
4849
1c6f21eb97f2 (svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents: 4848
diff changeset
   292
void GetNameOfOwner(Owner owner, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
{
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   294
	SetDParam(2, owner);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   295
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	if (owner != OWNER_TOWN) {
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4849
diff changeset
   297
		if (!IsValidPlayer(owner)) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   298
			SetDParam(0, STR_0150_SOMEONE);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   299
		} else {
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   300
			const Player* p = GetPlayer(owner);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   301
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   302
			SetDParam(0, p->name_1);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   303
			SetDParam(1, p->name_2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	} else {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   306
		const Town* t = ClosestTownFromTile(tile, (uint)-1);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   307
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 1977
diff changeset
   308
		SetDParam(0, STR_TOWN);
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 1977
diff changeset
   309
		SetDParam(1, t->index);
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
   314
bool CheckOwnership(PlayerID owner)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
{
4849
1c6f21eb97f2 (svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents: 4848
diff changeset
   316
	assert(owner < OWNER_END);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   318
	if (owner == _current_player) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
	_error_message = STR_013B_OWNED_BY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
	GetNameOfOwner(owner, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   324
bool CheckTileOwnership(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
{
4849
1c6f21eb97f2 (svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents: 4848
diff changeset
   326
	Owner owner = GetTileOwner(tile);
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   327
4849
1c6f21eb97f2 (svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents: 4848
diff changeset
   328
	assert(owner < OWNER_END);
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   329
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   330
	if (owner == _current_player) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
	_error_message = STR_013B_OWNED_BY;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   332
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
	// no need to get the name of the owner unless we're the local player (saves some time)
2425
e755ee29133a (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2395
diff changeset
   334
	if (IsLocalPlayer()) GetNameOfOwner(owner, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
static void GenerateCompanyName(Player *p)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
{
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   340
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
	StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
	Player *pp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
	uint32 strp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
	char buffer[100];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   347
	if (p->name_1 != STR_SV_UNNAMED) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	tile = p->last_build_coordinate;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   350
	if (tile == 0) return;
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
	t = ClosestTownFromTile(tile, (uint)-1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
	if (IS_INT_INSIDE(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST+1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
		str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_PLAYERNAME_START;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
		strp = t->townnameparts;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
verify_name:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
		// No player must have this name already
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
		FOR_ALL_PLAYERS(pp) {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   361
			if (pp->name_1 == str && pp->name_2 == strp) goto bad_town_name;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4878
diff changeset
   364
		GetString(buffer, str, lastof(buffer));
4609
954fe701062f (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4606
diff changeset
   365
		if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 150)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
			goto bad_town_name;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
set_name:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
		p->name_1 = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
		p->name_2 = strp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
4845
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
   374
		if (!IsHumanPlayer(p->index)) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   375
			SetDParam(0, t->index);
4873
11880cbbc9f6 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4858
diff changeset
   376
			AddNewsItem((StringID)(p->index | NB_BNEWCOMPANY), NEWS_FLAGS(NM_CALLBACK, NF_TILE, NT_COMPANY_INFO, DNC_BANKRUPCY), p->last_build_coordinate, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
bad_town_name:;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   381
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
	if (p->president_name_1 == SPECSTR_PRESIDENT_NAME) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
		str = SPECSTR_ANDCO_NAME;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
		strp = p->president_name_2;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   385
		goto set_name;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
		str = SPECSTR_ANDCO_NAME;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
		strp = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
		goto verify_name;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
#define COLOR_SWAP(i,j) do { byte t=colors[i];colors[i]=colors[j];colors[j]=t; } while(0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
static const byte _color_sort[16] = {2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 1, 1};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
static const byte _color_similar_1[16] = {8, 6, 255, 12,  255, 0, 1, 1, 0, 13,  11,  10, 3,   9,  15, 14};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
static const byte _color_similar_2[16] = {5, 7, 255, 255, 255, 8, 7, 6, 5, 12, 255, 255, 9, 255, 255, 255};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1021
diff changeset
   399
static byte GeneratePlayerColor(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
	byte colors[16], pcolor, t2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
	int i,j,n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
	// Initialize array
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
   407
	for (i = 0; i != 16; i++) colors[i] = i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
	// And randomize it
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
	n = 100;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
		r = Random();
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2119
diff changeset
   413
		COLOR_SWAP(GB(r, 0, 4), GB(r, 4, 4));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
	} while (--n);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
	// Bubble sort it according to the values in table 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	i = 16;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
	do {
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
   419
		for (j = 0; j != 15; j++) {
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
   420
			if (_color_sort[colors[j]] < _color_sort[colors[j + 1]]) {
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
   421
				COLOR_SWAP(j, j + 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
	// Move the colors that look similar to each player's color to the side
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
	FOR_ALL_PLAYERS(p) if (p->is_active) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
		pcolor = p->player_color;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
   429
		for (i=0; i!=16; i++) if (colors[i] == pcolor) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
			colors[i] = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   432
			t2 = _color_similar_1[pcolor];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
			if (t2 == 0xFF) break;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
   434
			for (i=0; i!=15; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
				if (colors[i] == t2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
					do COLOR_SWAP(i,i+1); while (++i != 15);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   441
			t2 = _color_similar_2[pcolor];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
			if (t2 == 0xFF) break;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
   443
			for (i = 0; i != 15; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
				if (colors[i] == t2) {
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
   445
					do COLOR_SWAP(i, i + 1); while (++i != 15);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	// Return the first available color
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   454
	for (i = 0;; i++) {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   455
		if (colors[i] != 0xFF) return colors[i];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
static void GeneratePresidentName(Player *p)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	Player *pp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
	char buffer[100], buffer2[40];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
   464
	for (;;) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
restart:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
		p->president_name_2 = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
		p->president_name_1 = SPECSTR_PRESIDENT_NAME;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   469
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   470
		SetDParam(0, p->president_name_2);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4878
diff changeset
   471
		GetString(buffer, p->president_name_1, lastof(buffer));
4609
954fe701062f (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4606
diff changeset
   472
		if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 94)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
			continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
		FOR_ALL_PLAYERS(pp) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
			if (pp->is_active && p != pp) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   477
				SetDParam(0, pp->president_name_2);
4921
b6f08b37fe62 (svn r6897) - Fix (r6884): Another wrong last parametr :)
peter1138
parents: 4912
diff changeset
   478
				GetString(buffer2, pp->president_name_1, lastof(buffer2));
1304
6460f4c8600e (svn r1808) Use strcmp() instead of home brewed function str_eq()
tron
parents: 1174
diff changeset
   479
				if (strcmp(buffer2, buffer) == 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
					goto restart;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1021
diff changeset
   487
static Player *AllocatePlayer(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
	// Find a free slot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
	FOR_ALL_PLAYERS(p) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
		if (!p->is_active) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   493
			PlayerID i = p->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
			memset(p, 0, sizeof(Player));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
			p->index = i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
			return p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
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: 4580
diff changeset
   502
void ResetPlayerLivery(Player *p)
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: 4580
diff changeset
   503
{
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   504
	for (LiveryScheme scheme = LS_BEGIN; scheme < LS_END; scheme++) {
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: 4580
diff changeset
   505
		p->livery[scheme].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: 4580
diff changeset
   506
		p->livery[scheme].colour1 = p->player_color;
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: 4580
diff changeset
   507
		p->livery[scheme].colour2 = p->player_color;
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: 4580
diff changeset
   508
	}
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: 4580
diff changeset
   509
}
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: 4580
diff changeset
   510
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
Player *DoStartupNewPlayer(bool is_ai)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
	p = AllocatePlayer();
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   516
	if (p == NULL) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
	// Make a color
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
	p->player_color = GeneratePlayerColor();
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: 4580
diff changeset
   520
	ResetPlayerLivery(p);
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2381
diff changeset
   521
	_player_colors[p->index] = p->player_color;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	p->name_1 = STR_SV_UNNAMED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
	p->is_active = true;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   524
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
	p->money64 = p->player_money = p->current_loan = 100000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	p->is_ai = is_ai;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
	p->ai.state = 5; /* AIS_WANT_NEW_ROUTE */
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4845
diff changeset
   529
	p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = PLAYER_SPECTATOR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2381
diff changeset
   531
	p->avail_railtypes = GetPlayerRailtypes(p->index);
4326
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
   532
	p->inaugurated_year = _cur_year;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
	p->face = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   535
	/* Engine renewal settings */
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   536
	p->engine_renew_list = NULL;
2617
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   537
	p->renew_keep_length = false;
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   538
	p->engine_renew = false;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   539
	p->engine_renew_months = -6;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   540
	p->engine_renew_money = 100000;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   541
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
	GeneratePresidentName(p);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
	InvalidateWindow(WC_GRAPH_LEGEND, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
	InvalidateWindow(WC_TOOLBAR_MENU, 0);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   546
	InvalidateWindow(WC_CLIENT_LIST, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2381
diff changeset
   548
	if (is_ai && (!_networking || _network_server) && _ai.enabled)
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2381
diff changeset
   549
		AI_StartNewAI(p->index);
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2381
diff changeset
   550
4580
9e0e39d077a5 (svn r6430) -Fix r6424: fixed failure to init the whole array of engines when starting a new player
bjarni
parents: 4574
diff changeset
   551
	memset(p->num_engines, 0, sizeof(p->num_engines));
4574
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
   552
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
	return p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1021
diff changeset
   556
void StartupPlayers(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
{
23
324407ad61da (svn r24) Fix: competitors are starting more real
truelight
parents: 2
diff changeset
   558
	// The AI starts like in the setting with +2 month max
165
f81fa8c27236 (svn r166) -Codechange: change 74 for constant DAY_TICKS
darkvater
parents: 84
diff changeset
   559
	_next_competitor_start = _opt.diff.competitor_start_time * 90 * DAY_TICKS + RandomRange(60 * DAY_TICKS) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1021
diff changeset
   562
static void MaybeStartNewPlayer(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
	uint n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
	Player *p;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   566
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
	// count number of competitors
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
	n = 0;
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2381
diff changeset
   569
	FOR_ALL_PLAYERS(p) {
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   570
		if (p->is_active && p->is_ai) n++;
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2381
diff changeset
   571
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
	// when there's a lot of computers in game, the probability that a new one starts is lower
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   574
	if (n < (uint)_opt.diff.max_no_competitors &&
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   575
			n < (_network_server ?
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   576
				InteractiveRandomRange(_opt.diff.max_no_competitors + 2) :
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   577
				RandomRange(_opt.diff.max_no_competitors + 2)
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   578
			)) {
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   579
		/* Send a command to all clients to start up a new AI.
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   580
		 * Works fine for Multiplayer and Singleplayer */
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   581
		DoCommandP(0, 1, 0, NULL, CMD_PLAYER_CTRL);
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   582
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   583
23
324407ad61da (svn r24) Fix: competitors are starting more real
truelight
parents: 2
diff changeset
   584
	// The next AI starts like the difficulty setting said, with +2 month max
2092
6b0d340ecc42 (svn r2602) -Codechange: removed unused variable (disable_computer)
truelight
parents: 2070
diff changeset
   585
	_next_competitor_start = _opt.diff.competitor_start_time * 90 * DAY_TICKS + 1;
2682
7fa4b202b9f0 (svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents: 2639
diff changeset
   586
	_next_competitor_start += _network_server ? InteractiveRandomRange(60 * DAY_TICKS) : RandomRange(60 * DAY_TICKS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1021
diff changeset
   589
void InitializePlayers(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
	memset(_players, 0, sizeof(_players));
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   592
	for (PlayerID i = PLAYER_FIRST; i != MAX_PLAYERS; i++) _players[i].index = i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
	_cur_player_tick_index = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1021
diff changeset
   596
void OnTick_Players(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
   600
	if (_game_mode == GM_EDITOR) return;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   601
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   602
	p = GetPlayer((PlayerID)_cur_player_tick_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
	_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
	if (p->name_1 != 0) GenerateCompanyName(p);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
2682
7fa4b202b9f0 (svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents: 2639
diff changeset
   606
	if (AI_AllowNewAI() && _game_mode != GM_MENU && !--_next_competitor_start)
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   607
		MaybeStartNewPlayer();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
2
104b2984cd3e (svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents: 1
diff changeset
   610
// index is the next parameter in _decode_parameters to set up
2475
efdcc705cb61 (svn r3001) s/Player*/const Player*/
tron
parents: 2469
diff changeset
   611
StringID GetPlayerNameString(PlayerID player, uint index)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
{
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4849
diff changeset
   613
	if (IsHumanPlayer(player) && IsValidPlayer(player)) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   614
		SetDParam(index, player+1);
2
104b2984cd3e (svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents: 1
diff changeset
   615
		return STR_7002_PLAYER;
104b2984cd3e (svn r3) -[1005611] Player Window patch: When looking in dropdownlist for player stuff, it will say
darkvater
parents: 1
diff changeset
   616
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
	return STR_EMPTY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   620
extern void ShowPlayerFinances(PlayerID player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1021
diff changeset
   622
void PlayersYearlyLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
	// Copy statistics
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
	FOR_ALL_PLAYERS(p) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
		if (p->is_active) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
			memmove(&p->yearly_expenses[1], &p->yearly_expenses[0], sizeof(p->yearly_expenses) - sizeof(p->yearly_expenses[0]));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
			memset(&p->yearly_expenses[0], 0, sizeof(p->yearly_expenses[0]));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
			InvalidateWindow(WC_FINANCES, p->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4845
diff changeset
   635
	if (_patches.show_finances && _local_player != PLAYER_SPECTATOR) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
		ShowPlayerFinances(_local_player);
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1901
diff changeset
   637
		p = GetPlayer(_local_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
		if (p->num_valid_stat_ent > 5 && p->old_economy[0].performance_history < p->old_economy[4].performance_history) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   639
			SndPlayFx(SND_01_BAD_YEAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
		} else {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   641
			SndPlayFx(SND_00_GOOD_YEAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2535
diff changeset
   646
byte GetPlayerRailtypes(PlayerID p)
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   647
{
2554
92c3fe9f1412 (svn r3087) Rewrite GetPlayerRailtypes() so it doesn't depend on magical numbers to sort out wagons
tron
parents: 2548
diff changeset
   648
	byte rt = 0;
2634
0df9396b0067 (svn r3176) Use proper types, not some variants of int
tron
parents: 2617
diff changeset
   649
	EngineID i;
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   650
2554
92c3fe9f1412 (svn r3087) Rewrite GetPlayerRailtypes() so it doesn't depend on magical numbers to sort out wagons
tron
parents: 2548
diff changeset
   651
	for (i = 0; i != TOTAL_NUM_ENGINES; i++) {
92c3fe9f1412 (svn r3087) Rewrite GetPlayerRailtypes() so it doesn't depend on magical numbers to sort out wagons
tron
parents: 2548
diff changeset
   652
		const Engine* e = GetEngine(i);
3393
c40975f04842 (svn r4201) - Codechange: Do for _engine_info[] what we do for _*_vehicle_info[]; create and use a function to retrieve data, and ensure constness.
peter1138
parents: 3351
diff changeset
   653
		const EngineInfo *ei = EngInfo(i);
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   654
2913
5324c597e047 (svn r3468) - Fix: Rail type availability should take climate type into account.
peter1138
parents: 2879
diff changeset
   655
		if (e->type == VEH_Train && HASBIT(ei->climates, _opt.landscape) &&
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5750
diff changeset
   656
				(HASBIT(e->player_avail, p) || _date >= e->intro_date + 365)) {
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5750
diff changeset
   657
			const RailVehicleInfo *rvi = RailVehInfo(i);
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5750
diff changeset
   658
5868
94430141c189 (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 5823
diff changeset
   659
			if (rvi->railveh_type != RAILVEH_WAGON) {
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5750
diff changeset
   660
				assert(rvi->railtype < RAILTYPE_END);
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5750
diff changeset
   661
				SETBIT(rt, rvi->railtype);
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5750
diff changeset
   662
			}
2554
92c3fe9f1412 (svn r3087) Rewrite GetPlayerRailtypes() so it doesn't depend on magical numbers to sort out wagons
tron
parents: 2548
diff changeset
   663
		}
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   664
	}
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   665
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   666
	return rt;
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   667
}
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   668
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2535
diff changeset
   669
static void DeletePlayerStuff(PlayerID pi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
	DeletePlayerWindows(pi);
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1901
diff changeset
   674
	p = GetPlayer(pi);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
	DeleteName(p->name_1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
	DeleteName(p->president_name_1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
	p->name_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
	p->president_name_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   681
/** Change engine renewal parameters
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: 3393
diff changeset
   682
 * @param tile unused
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   683
 * @param p1 bits 0-3 command
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   684
 * - p1 = 0 - change auto renew bool
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   685
 * - p1 = 1 - change auto renew months
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   686
 * - p1 = 2 - change auto renew money
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   687
 * - p1 = 3 - change auto renew array
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   688
 * - p1 = 4 - change bool, months & money all together
2617
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   689
 * - p1 = 5 - change renew_keep_length
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   690
 * @param p2 value to set
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   691
 * if p1 = 0, then:
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   692
 * - p2 = enable engine renewal
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   693
 * if p1 = 1, then:
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   694
 * - p2 = months left before engine expires to replace it
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   695
 * if p1 = 2, then
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   696
 * - p2 = minimum amount of money available
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   697
 * if p1 = 3, then:
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   698
 * - p2 bits  0-15 = old engine type
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   699
 * - p2 bits 16-31 = new engine type
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   700
 * if p1 = 4, then:
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   701
 * - p1 bit     15 = enable engine renewal
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   702
 * - p1 bits 16-31 = months left before engine expires to replace it
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   703
 * - p2 bits  0-31 = minimum amount of money available
2617
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   704
 * if p1 = 5, then
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   705
 * - p2 = enable renew_keep_length
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   706
 */
4661
89c3cbba9846 (svn r6544) - Codechange: Rename CmdReplaceVehicle to CmdSetAutoReplace, to reflect what it does.
peter1138
parents: 4609
diff changeset
   707
int32 CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   708
{
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   709
	Player *p;
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4849
diff changeset
   710
	if (!IsValidPlayer(_current_player)) return CMD_ERROR;
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   711
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   712
	p = GetPlayer(_current_player);
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   713
	switch (GB(p1, 0, 3)) {
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   714
		case 0:
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   715
			if (p->engine_renew == (bool)GB(p2, 0, 1))
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   716
				return CMD_ERROR;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   717
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   718
			if (flags & DC_EXEC) {
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   719
				p->engine_renew = (bool)GB(p2, 0, 1);
2425
e755ee29133a (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2395
diff changeset
   720
				if (IsLocalPlayer()) {
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   721
					_patches.autorenew = p->engine_renew;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   722
					InvalidateWindow(WC_GAME_OPTIONS, 0);
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   723
				}
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   724
			}
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   725
			break;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   726
		case 1:
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   727
			if (p->engine_renew_months == (int16)p2)
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   728
				return CMD_ERROR;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   729
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   730
			if (flags & DC_EXEC) {
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   731
				p->engine_renew_months = (int16)p2;
2425
e755ee29133a (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2395
diff changeset
   732
				if (IsLocalPlayer()) {
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   733
					_patches.autorenew_months = p->engine_renew_months;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   734
					InvalidateWindow(WC_GAME_OPTIONS, 0);
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   735
				}
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   736
			}
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   737
			break;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   738
		case 2:
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   739
			if (p->engine_renew_money == (uint32)p2)
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   740
				return CMD_ERROR;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   741
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   742
			if (flags & DC_EXEC) {
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   743
				p->engine_renew_money = (uint32)p2;
2425
e755ee29133a (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2395
diff changeset
   744
				if (IsLocalPlayer()) {
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   745
					_patches.autorenew_money = p->engine_renew_money;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   746
					InvalidateWindow(WC_GAME_OPTIONS, 0);
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   747
				}
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   748
			}
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   749
			break;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   750
		case 3: {
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   751
			EngineID old_engine_type = GB(p2, 0, 16);
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   752
			EngineID new_engine_type = GB(p2, 16, 16);
2811
30a1aff946db (svn r3359) - Autoreplace GUI: When starting or stopping a replacement, redraw the replace window after the command has completed, rather than after calling the command.
peter1138
parents: 2795
diff changeset
   753
			int32 cost;
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   754
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   755
			if (new_engine_type != INVALID_ENGINE) {
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   756
				/* First we make sure that it's a valid type the user requested
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   757
				 * check that it's an engine that is in the engine array */
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
   758
				if (!IsEngineIndex(new_engine_type))
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   759
					return CMD_ERROR;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   760
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   761
				// check that the new vehicle type is the same as the original one
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   762
				if (GetEngine(old_engine_type)->type != GetEngine(new_engine_type)->type)
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   763
					return CMD_ERROR;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   764
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   765
				// make sure that we do not replace a plane with a helicopter or vise versa
4023
5d84c056a2b1 (svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents: 4000
diff changeset
   766
				if (GetEngine(new_engine_type)->type == VEH_Aircraft &&
5d84c056a2b1 (svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents: 4000
diff changeset
   767
						(AircraftVehInfo(old_engine_type)->subtype & AIR_CTOL) != (AircraftVehInfo(new_engine_type)->subtype & AIR_CTOL))
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   768
					return CMD_ERROR;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   769
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   770
				// make sure that the player can actually buy the new engine
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   771
				if (!HASBIT(GetEngine(new_engine_type)->player_avail, _current_player))
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   772
					return CMD_ERROR;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   773
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   774
				cost = AddEngineReplacementForPlayer(p, old_engine_type, new_engine_type, flags);
2697
97fc22baf3da (svn r3239) - Codechange: Introduce and use helper functions for engine replacement code.
peter1138
parents: 2684
diff changeset
   775
			} else {
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   776
				cost = RemoveEngineReplacementForPlayer(p, old_engine_type, flags);
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   777
			}
2811
30a1aff946db (svn r3359) - Autoreplace GUI: When starting or stopping a replacement, redraw the replace window after the command has completed, rather than after calling the command.
peter1138
parents: 2795
diff changeset
   778
30a1aff946db (svn r3359) - Autoreplace GUI: When starting or stopping a replacement, redraw the replace window after the command has completed, rather than after calling the command.
peter1138
parents: 2795
diff changeset
   779
			if (IsLocalPlayer()) InvalidateWindow(WC_REPLACE_VEHICLE, GetEngine(old_engine_type)->type);
30a1aff946db (svn r3359) - Autoreplace GUI: When starting or stopping a replacement, redraw the replace window after the command has completed, rather than after calling the command.
peter1138
parents: 2795
diff changeset
   780
30a1aff946db (svn r3359) - Autoreplace GUI: When starting or stopping a replacement, redraw the replace window after the command has completed, rather than after calling the command.
peter1138
parents: 2795
diff changeset
   781
			return cost;
2755
ba133949851b (svn r3300) Remove unreachable code - in this case some duplicate breaks
tron
parents: 2697
diff changeset
   782
		}
ba133949851b (svn r3300) Remove unreachable code - in this case some duplicate breaks
tron
parents: 2697
diff changeset
   783
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   784
		case 4:
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   785
			if (flags & DC_EXEC) {
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   786
				p->engine_renew = (bool)GB(p1, 15, 1);
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   787
				p->engine_renew_months = (int16)GB(p1, 16, 16);
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   788
				p->engine_renew_money = (uint32)p2;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   789
2425
e755ee29133a (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2395
diff changeset
   790
				if (IsLocalPlayer()) {
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   791
					_patches.autorenew = p->engine_renew;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   792
					_patches.autorenew_months = p->engine_renew_months;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   793
					_patches.autorenew_money = p->engine_renew_money;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   794
					InvalidateWindow(WC_GAME_OPTIONS, 0);
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   795
				}
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   796
			}
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   797
			break;
2617
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   798
		case 5:
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   799
			if (p->renew_keep_length == (bool)GB(p2, 0, 1))
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   800
				return CMD_ERROR;
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   801
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   802
			if (flags & DC_EXEC) {
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   803
				p->renew_keep_length = (bool)GB(p2, 0, 1);
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   804
				if (IsLocalPlayer()) {
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   805
					InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Train);
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   806
				}
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   807
			}
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   808
		break;
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
   809
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   810
	}
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   811
	return 0;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   812
}
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
   813
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   814
/** Control the players: add, delete, 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: 3393
diff changeset
   815
 * @param tile unused
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   816
 * @param p1 various functionality
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   817
 * - p1 = 0 - create a new player, Which player (network) it will be is in p2
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   818
 * - p1 = 1 - create a new AI player
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   819
 * - p1 = 2 - delete a player. Player is identified by p2
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   820
 * - p1 = 3 - merge two companies together. Player to merge #1 with player #2. Identified by p2
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   821
 * @param p2 various functionality, dictated by p1
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   822
 * - p1 = 0 - ClientID of the newly created player
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   823
 * - p1 = 2 - PlayerID of the that is getting deleted
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   824
 * - p1 = 3 - #1 p2 = (bit  0-15) - player to merge (p2 & 0xFFFF)
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   825
 *          - #2 p2 = (bit 16-31) - player to be merged into ((p2>>16)&0xFFFF)
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   826
 * @todo In the case of p1=0, create new player, the clientID of the new player is in parameter
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   827
 * p2. This parameter is passed in at function DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   828
 * on the server itself. First of all this is unbelievably ugly; second of all, well,
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   829
 * it IS ugly! <b>Someone fix this up :)</b> So where to fix?@n
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   830
 * @arg - network_server.c:838 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)@n
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   831
 * @arg - network_client.c:536 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) from where the map has been received
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   832
 */
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: 3393
diff changeset
   833
int32 CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
{
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   835
	if (flags & DC_EXEC) _current_player = OWNER_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   837
	switch (p1) {
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   838
	case 0: { /* Create a new player */
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   839
		/* Joining Client:
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   840
		 * _local_player: PLAYER_SPECTATOR
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   841
		 * _network_playas/cid = requested company/player
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   842
		 *
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   843
		 * Other client(s)/server:
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   844
		 * _local_player/_network_playas: what they play as
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   845
		 * cid = requested company/player of joining client */
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   846
		Player *p;
5692
bce5374837b0 (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5668
diff changeset
   847
#ifdef ENABLE_NETWORK
4858
1b63ed767b29 (svn r6784) -Codechange: Change invalid PlayerID type into ClientID which it is in CmdPlayerCtrl
Darkvater
parents: 4854
diff changeset
   848
		uint16 cid = p2; // ClientID
5692
bce5374837b0 (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5668
diff changeset
   849
#endif /* ENABLE_NETWORK */
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
   850
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   851
		/* This command is only executed in a multiplayer game */
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   852
		if (!_networking) return CMD_ERROR;
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   853
5375
a0bf4e683027 (svn r7560) -Fix (r2300): p2 is not a PlayerID when creating a new company, but the ClientID (index in _network_client_info). Therefore it was not possible to create a new company if 8 or more clients were connected. Thanks to FlashFF for noticing this bug.
rubidium
parents: 5077
diff changeset
   854
		/* Has the network client a correct ClientID? */
5441
e8bac228a6db (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5376
diff changeset
   855
		if (!(flags & DC_EXEC)) return 0;
e8bac228a6db (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5376
diff changeset
   856
#ifdef ENABLE_NETWORK
e8bac228a6db (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5376
diff changeset
   857
		if (cid >= MAX_CLIENT_INFO) return 0;
e8bac228a6db (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5376
diff changeset
   858
#endif /* ENABLE_NETWORK */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   859
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   860
		/* Delete multiplayer progress bar */
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   861
		DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   862
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
		p = DoStartupNewPlayer(false);
670
d164965bb35a (svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents: 662
diff changeset
   864
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   865
		/* A new player could not be created, revert to being a spectator */
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   866
		if (p == NULL) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   867
#ifdef ENABLE_NETWORK
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   868
			if (_network_server) {
4858
1b63ed767b29 (svn r6784) -Codechange: Change invalid PlayerID type into ClientID which it is in CmdPlayerCtrl
Darkvater
parents: 4854
diff changeset
   869
				NetworkClientInfo *ci = &_network_client_info[cid];
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   870
				ci->client_playas = PLAYER_SPECTATOR;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
   871
				NetworkUpdateClientInfo(ci->client_index);
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   872
			} else
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   873
#endif /* ENABLE_NETWORK */
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   874
			{
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
   875
				_network_playas = PLAYER_SPECTATOR;
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
   876
				SetLocalPlayer(PLAYER_SPECTATOR);
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   877
			}
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   878
			break;
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   879
		}
690
3afcad69d4f7 (svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents: 688
diff changeset
   880
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   881
		/* This is the joining client who wants a new company */
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   882
		if (_local_player != _network_playas) {
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   883
			assert(_local_player == PLAYER_SPECTATOR && _network_playas == p->index);
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5375
diff changeset
   884
			SetLocalPlayer(p->index);
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   885
			MarkWholeScreenDirty();
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   886
		}
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   887
5073
99ff52c14896 (svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents: 5068
diff changeset
   888
		/* Now that we have a new player, broadcast its autorenew settings to
99ff52c14896 (svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents: 5068
diff changeset
   889
		 * all clients so everything is in sync */
99ff52c14896 (svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents: 5068
diff changeset
   890
		DoCommand(0,
99ff52c14896 (svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents: 5068
diff changeset
   891
			(_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4,
99ff52c14896 (svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents: 5068
diff changeset
   892
			_patches.autorenew_money,
99ff52c14896 (svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents: 5068
diff changeset
   893
			DC_EXEC,
99ff52c14896 (svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents: 5068
diff changeset
   894
			CMD_SET_AUTOREPLACE
99ff52c14896 (svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents: 5068
diff changeset
   895
		);
99ff52c14896 (svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents: 5068
diff changeset
   896
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   897
#ifdef ENABLE_NETWORK
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   898
		if (_network_server) {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   899
			/* XXX - UGLY! p2 (pid) is mis-used to fetch the client-id, done at
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   900
			 * server-side in network_server.c:838, function
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   901
			 * DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) */
4858
1b63ed767b29 (svn r6784) -Codechange: Change invalid PlayerID type into ClientID which it is in CmdPlayerCtrl
Darkvater
parents: 4854
diff changeset
   902
			NetworkClientInfo *ci = &_network_client_info[cid];
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   903
			ci->client_playas = p->index;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   904
			NetworkUpdateClientInfo(ci->client_index);
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   905
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   906
			if (IsValidPlayer(ci->client_playas)) {
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   907
				PlayerID player_backup = _local_player;
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   908
				_network_player_info[p->index].months_empty = 0;
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   909
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   910
				/* XXX - When a client joins, we automatically set its name to the
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   911
				 * player's name (for some reason). As it stands now only the server
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   912
				 * knows the client's name, so it needs to send out a "broadcast" to
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   913
				 * do this. To achieve this we send a network command. However, it
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   914
				 * uses _local_player to execute the command as.  To prevent abuse
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   915
				 * (eg. only yourself can change your name/company), we 'cheat' by
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   916
				 * impersonation _local_player as the server. Not the best solution;
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   917
				 * but it works.
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   918
				 * TODO: Perhaps this could be improved by when the client is ready
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   919
				 * with joining to let it send itself the command, and not the server?
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   920
				 * For example in network_client.c:534? */
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   921
				_cmd_text = ci->client_name;
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   922
				_local_player = ci->client_playas;
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   923
				NetworkSend_Command(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME, NULL);
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   924
				_local_player = player_backup;
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   925
			}
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   926
		}
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   927
#endif /* ENABLE_NETWORK */
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   928
	} break;
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   929
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   930
	case 1: /* Make a new AI player */
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   931
		if (!(flags & DC_EXEC)) return 0;
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   932
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
		DoStartupNewPlayer(true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
		break;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   935
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   936
	case 2: { /* Delete a player */
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   937
		Player *p;
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   938
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   939
		if (!IsValidPlayer((PlayerID)p2)) return CMD_ERROR;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   940
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   941
		if (!(flags & DC_EXEC)) return 0;
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   942
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   943
		p = GetPlayer((PlayerID)p2);
688
1bf7db6d29b7 (svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents: 679
diff changeset
   944
1bf7db6d29b7 (svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents: 679
diff changeset
   945
		/* Only allow removal of HUMAN companies */
4845
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
   946
		if (IsHumanPlayer(p->index)) {
688
1bf7db6d29b7 (svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents: 679
diff changeset
   947
			/* Delete any open window of the company */
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   948
			DeletePlayerWindows(p->index);
688
1bf7db6d29b7 (svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents: 679
diff changeset
   949
1bf7db6d29b7 (svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents: 679
diff changeset
   950
			/* Show the bankrupt news */
1bf7db6d29b7 (svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents: 679
diff changeset
   951
			SetDParam(0, p->name_1);
1bf7db6d29b7 (svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents: 679
diff changeset
   952
			SetDParam(1, p->name_2);
4873
11880cbbc9f6 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4858
diff changeset
   953
			AddNewsItem( (StringID)(p->index | NB_BBANKRUPT), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
688
1bf7db6d29b7 (svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents: 679
diff changeset
   954
1bf7db6d29b7 (svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents: 679
diff changeset
   955
			/* Remove the company */
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4845
diff changeset
   956
			ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
688
1bf7db6d29b7 (svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents: 679
diff changeset
   957
			p->is_active = false;
1bf7db6d29b7 (svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents: 679
diff changeset
   958
		}
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   959
		RemoveAllEngineReplacementForPlayer(p);
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   960
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   961
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   963
	case 3: { /* Merge a company (#1) into another company (#2), elimination company #1 */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   964
		PlayerID pid_old = (PlayerID)GB(p2,  0, 16);
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   965
		PlayerID pid_new = (PlayerID)GB(p2, 16, 16);
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   966
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4849
diff changeset
   967
		if (!IsValidPlayer(pid_old) || !IsValidPlayer(pid_new)) return CMD_ERROR;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   968
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   969
		if (!(flags & DC_EXEC)) 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: 1787
diff changeset
   970
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   971
		ChangeOwnershipOfPlayerItems(pid_old, pid_new);
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   972
		DeletePlayerStuff(pid_old);
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   973
	} break;
5067
f3816e74ad32 (svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents: 4944
diff changeset
   974
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1787
diff changeset
   975
	default: return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   981
static const StringID _endgame_perf_titles[] = {
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   982
	STR_0213_BUSINESSMAN,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   983
	STR_0213_BUSINESSMAN,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   984
	STR_0213_BUSINESSMAN,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   985
	STR_0213_BUSINESSMAN,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   986
	STR_0213_BUSINESSMAN,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   987
	STR_0214_ENTREPRENEUR,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   988
	STR_0214_ENTREPRENEUR,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   989
	STR_0215_INDUSTRIALIST,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   990
	STR_0215_INDUSTRIALIST,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   991
	STR_0216_CAPITALIST,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   992
	STR_0216_CAPITALIST,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   993
	STR_0217_MAGNATE,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   994
	STR_0217_MAGNATE,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   995
	STR_0218_MOGUL,
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   996
	STR_0218_MOGUL,
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
   997
	STR_0219_TYCOON_OF_THE_CENTURY
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   998
};
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
   999
1016
75b12fe9c4e1 (svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents: 998
diff changeset
  1000
StringID EndGameGetPerformanceTitleFromValue(uint value)
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1001
{
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
  1002
	value = minu(value / 64, lengthof(_endgame_perf_titles) - 1);
2613
c43a30171b62 (svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents: 2572
diff changeset
  1003
c43a30171b62 (svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents: 2572
diff changeset
  1004
	return _endgame_perf_titles[value];
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1005
}
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1006
1016
75b12fe9c4e1 (svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents: 998
diff changeset
  1007
/* Return true if any cheat has been used, false otherwise */
1021
d5738de2b051 (svn r1522) -Fix: warning players.c; forgot return type. Damn, makefile is too strict ;) (Thx Tron)
darkvater
parents: 1019
diff changeset
  1008
static bool CheatHasBeenUsed(void)
1016
75b12fe9c4e1 (svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents: 998
diff changeset
  1009
{
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
  1010
	const Cheat* cht = (Cheat*)&_cheats;
1016
75b12fe9c4e1 (svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents: 998
diff changeset
  1011
	const Cheat* cht_last = &cht[sizeof(_cheats) / sizeof(Cheat)];
75b12fe9c4e1 (svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents: 998
diff changeset
  1012
75b12fe9c4e1 (svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents: 998
diff changeset
  1013
	for (; cht != cht_last; cht++) {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4023
diff changeset
  1014
		if (cht->been_used) return true;
1016
75b12fe9c4e1 (svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents: 998
diff changeset
  1015
	}
75b12fe9c4e1 (svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents: 998
diff changeset
  1016
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1017
diff changeset
  1017
	return false;
1016
75b12fe9c4e1 (svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents: 998
diff changeset
  1018
}
75b12fe9c4e1 (svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents: 998
diff changeset
  1019
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1020
/* Save the highscore for the player */
998
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1021
int8 SaveHighScoreValue(const Player *p)
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1022
{
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1023
	HighScore *hs = _highscore_table[_opt.diff_level];
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1024
	uint i;
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1025
	uint16 score = p->old_economy[0].performance_history;
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1026
1016
75b12fe9c4e1 (svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents: 998
diff changeset
  1027
	/* Exclude cheaters from the honour of being in the highscore table */
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
  1028
	if (CheatHasBeenUsed()) return -1;
1016
75b12fe9c4e1 (svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents: 998
diff changeset
  1029
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1030
	for (i = 0; i < lengthof(_highscore_table[0]); i++) {
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1031
		/* You are in the TOP5. Move all values one down and save us there */
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1032
		if (hs[i].score <= score) {
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1033
			// move all elements one down starting from the replaced one
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1034
			memmove(&hs[i + 1], &hs[i], sizeof(HighScore) * (lengthof(_highscore_table[0]) - i - 1));
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1035
			SetDParam(0, p->president_name_1);
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1036
			SetDParam(1, p->president_name_2);
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1037
			SetDParam(2, p->name_1);
1017
b09bae77a850 (svn r1518) -Fix: server issue where some company names were wrong
darkvater
parents: 1016
diff changeset
  1038
			SetDParam(3, p->name_2);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4878
diff changeset
  1039
			GetString(hs[i].company, STR_HIGHSCORE_NAME, lastof(hs[i].company)); // get manager/company name string
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1040
			hs[i].score = score;
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1041
			hs[i].title = EndGameGetPerformanceTitleFromValue(score);
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1042
			return i;
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1043
		}
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1044
	}
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1045
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1046
	return -1; // too bad; we did not make it into the top5
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1047
}
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1048
998
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1049
/* Sort all players given their performance */
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1050
static int CDECL HighScoreSorter(const void *a, const void *b)
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1051
{
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1052
	const Player *pa = *(const Player* const*)a;
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1053
	const Player *pb = *(const Player* const*)b;
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1054
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1055
	return pb->old_economy[0].performance_history - pa->old_economy[0].performance_history;
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1056
}
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1057
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1058
/* Save the highscores in a network game when it has ended */
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1059
#define LAST_HS_ITEM lengthof(_highscore_table) - 1
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1060
int8 SaveHighScoreValueNetwork(void)
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1061
{
2988
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1062
	const Player* p;
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1063
	const Player* pl[MAX_PLAYERS];
998
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1064
	size_t count = 0;
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1065
	int8 player = -1;
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1066
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1067
	/* Sort all active players with the highest score first */
2988
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1068
	FOR_ALL_PLAYERS(p) if (p->is_active) pl[count++] = p;
2992
bb83a99307cb (svn r3568) - Fix: constantizing side-effect of qsort in r3563. Ugly? Yes. Makes MSVC happy? Yes.
Darkvater
parents: 2990
diff changeset
  1069
	qsort((Player*)pl, count, sizeof(pl[0]), HighScoreSorter);
998
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1070
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1071
	{
2988
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1072
		uint i;
998
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1073
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1074
		memset(_highscore_table[LAST_HS_ITEM], 0, sizeof(_highscore_table[0]));
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1075
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1076
		/* Copy over Top5 companies */
2484
0e45d70ae908 (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2475
diff changeset
  1077
		for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < count; i++) {
2988
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1078
			HighScore* hs = &_highscore_table[LAST_HS_ITEM][i];
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1079
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1080
			SetDParam(0, pl[i]->president_name_1);
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1081
			SetDParam(1, pl[i]->president_name_2);
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1082
			SetDParam(2, pl[i]->name_1);
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1083
			SetDParam(3, pl[i]->name_2);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4878
diff changeset
  1084
			GetString(hs->company, STR_HIGHSCORE_NAME, lastof(hs->company)); // get manager/company name string
2988
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1085
			hs->score = pl[i]->old_economy[0].performance_history;
998
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1086
			hs->title = EndGameGetPerformanceTitleFromValue(hs->score);
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1087
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1088
			// get the ranking of the local player
2988
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1089
			if (pl[i]->index == _local_player) player = i;
998
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1090
		}
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1091
	}
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1092
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1093
	/* Add top5 players to highscore table */
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1094
	return player;
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1095
}
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1096
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1097
/* Save HighScore table to file */
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1098
void SaveToHighScore(void)
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1099
{
2613
c43a30171b62 (svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents: 2572
diff changeset
  1100
	FILE *fp = fopen(_highscore_file, "wb");
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1101
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1102
	if (fp != NULL) {
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1103
		uint i;
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1104
		HighScore *hs;
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1105
998
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1106
		for (i = 0; i < LAST_HS_ITEM; i++) { // don't save network highscores
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1107
			for (hs = _highscore_table[i]; hs != endof(_highscore_table[i]); hs++) {
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1108
				/* First character is a command character, so strlen will fail on that */
4321
958a8e9c012b (svn r5974) -Codechange: added casts all around the place to make Windows 64bit happy (michi_cc)
truelight
parents: 4293
diff changeset
  1109
				byte length = min(sizeof(hs->company), (hs->company[0] == '\0') ? 0 : (int)strlen(&hs->company[1]) + 1);
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1110
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1111
				fwrite(&length, sizeof(length), 1, fp); // write away string length
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1112
				fwrite(hs->company, length, 1, fp);
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1113
				fwrite(&hs->score, sizeof(hs->score), 1, fp);
2613
c43a30171b62 (svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents: 2572
diff changeset
  1114
				fwrite("", 2, 1, fp); /* XXX - placeholder for hs->title, not saved anymore; compatibility */
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1115
			}
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1116
		}
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1117
		fclose(fp);
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1118
	}
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1119
}
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1120
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1121
/* Initialize the highscore table to 0 and if any file exists, load in values */
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1017
diff changeset
  1122
void LoadFromHighScore(void)
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1123
{
2613
c43a30171b62 (svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents: 2572
diff changeset
  1124
	FILE *fp = fopen(_highscore_file, "rb");
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1125
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1126
	memset(_highscore_table, 0, sizeof(_highscore_table));
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1127
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1128
	if (fp != NULL) {
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1129
		uint i;
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1130
		HighScore *hs;
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1131
998
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1132
		for (i = 0; i < LAST_HS_ITEM; i++) { // don't load network highscores
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1133
			for (hs = _highscore_table[i]; hs != endof(_highscore_table[i]); hs++) {
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1134
				byte length;
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1135
				fread(&length, sizeof(length), 1, fp);
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1136
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1137
				fread(hs->company, 1, length, fp);
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1138
				fread(&hs->score, sizeof(hs->score), 1, fp);
2613
c43a30171b62 (svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents: 2572
diff changeset
  1139
				fseek(fp, 2, SEEK_CUR); /* XXX - placeholder for hs->title, not saved anymore; compatibility */
c43a30171b62 (svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents: 2572
diff changeset
  1140
				hs->title = EndGameGetPerformanceTitleFromValue(hs->score);
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1141
			}
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1142
		}
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1143
		fclose(fp);
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1144
	}
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1017
diff changeset
  1145
998
c90459c24842 (svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents: 983
diff changeset
  1146
	/* Initialize end of game variable (when to show highscore chart) */
4285
19cb745c694e (svn r5915) -Cleanup: some variables were named *_date while they were only holding years; rename these variables to match this.
rubidium
parents: 4261
diff changeset
  1147
	_patches.ending_year = 2051;
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1148
}
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 717
diff changeset
  1149
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
// Save/load of players
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1834
diff changeset
  1151
static const SaveLoad _player_desc[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1152
	    SLE_VAR(Player, name_2,          SLE_UINT32),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1153
	    SLE_VAR(Player, name_1,          SLE_STRINGID),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1155
	    SLE_VAR(Player, president_name_1,SLE_UINT16),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1156
	    SLE_VAR(Player, president_name_2,SLE_UINT32),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1158
	    SLE_VAR(Player, face,            SLE_UINT32),
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
  1159
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
	// money was changed to a 64 bit field in savegame version 1.
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1161
	SLE_CONDVAR(Player, money64,               SLE_VAR_I64 | SLE_FILE_I32, 0, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1162
	SLE_CONDVAR(Player, money64,               SLE_INT64, 1, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1164
	    SLE_VAR(Player, current_loan,          SLE_INT32),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1166
	    SLE_VAR(Player, player_color,          SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1167
	    SLE_VAR(Player, player_money_fraction, SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1168
	    SLE_VAR(Player, avail_railtypes,       SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1169
	    SLE_VAR(Player, block_preview,         SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1171
	    SLE_VAR(Player, cargo_types,           SLE_UINT16),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1172
	SLE_CONDVAR(Player, location_of_house,     SLE_FILE_U16 | SLE_VAR_U32,  0,  5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1173
	SLE_CONDVAR(Player, location_of_house,     SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1174
	SLE_CONDVAR(Player, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32,  0,  5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1175
	SLE_CONDVAR(Player, last_build_coordinate, SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1176
	SLE_CONDVAR(Player, inaugurated_year,      SLE_FILE_U8  | SLE_VAR_I32,  0, 30),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1177
	SLE_CONDVAR(Player, inaugurated_year,      SLE_INT32,                  31, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1178
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1179
	    SLE_ARR(Player, share_owners,          SLE_UINT8, 4),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1180
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1181
	    SLE_VAR(Player, num_valid_stat_ent,    SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1182
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1183
	    SLE_VAR(Player, quarters_of_bankrupcy, SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1184
	    SLE_VAR(Player, bankrupt_asked,        SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1185
	    SLE_VAR(Player, bankrupt_timeout,      SLE_INT16),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1186
	    SLE_VAR(Player, bankrupt_value,        SLE_INT32),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
	// yearly expenses was changed to 64-bit in savegame version 2.
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1189
	SLE_CONDARR(Player, yearly_expenses,       SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, 0, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1190
	SLE_CONDARR(Player, yearly_expenses,       SLE_INT64, 3 * 13,                  2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1192
	SLE_CONDVAR(Player, is_ai,                 SLE_BOOL, 2, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1193
	SLE_CONDVAR(Player, is_active,             SLE_BOOL, 4, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
  1195
	// Engine renewal settings
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3047
diff changeset
  1196
	SLE_CONDNULL(512, 16, 18),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1197
	SLE_CONDREF(Player, engine_renew_list,     REF_ENGINE_RENEWS,          19, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1198
	SLE_CONDVAR(Player, engine_renew,          SLE_BOOL,                   16, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1199
	SLE_CONDVAR(Player, engine_renew_months,   SLE_INT16,                  16, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1200
	SLE_CONDVAR(Player, engine_renew_money,    SLE_UINT32,                 16, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1201
	SLE_CONDVAR(Player, renew_keep_length,     SLE_BOOL,                    2, SL_MAX_VERSION), // added with 16.1, but was blank since 2
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2204
diff changeset
  1202
2617
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2616
diff changeset
  1203
	// reserve extra space in savegame here. (currently 63 bytes)
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3047
diff changeset
  1204
	SLE_CONDNULL(63, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1834
diff changeset
  1209
static const SaveLoad _player_economy_desc[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
	// these were changed to 64-bit in savegame format 2
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1211
	SLE_CONDVAR(PlayerEconomyEntry, income,              SLE_INT32,                  0, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1212
	SLE_CONDVAR(PlayerEconomyEntry, expenses,            SLE_INT32,                  0, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1213
	SLE_CONDVAR(PlayerEconomyEntry, company_value,       SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1214
	SLE_CONDVAR(PlayerEconomyEntry, income,              SLE_FILE_I64 | SLE_VAR_I32, 2, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1215
	SLE_CONDVAR(PlayerEconomyEntry, expenses,            SLE_FILE_I64 | SLE_VAR_I32, 2, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1216
	SLE_CONDVAR(PlayerEconomyEntry, company_value,       SLE_INT64,                  2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1218
	    SLE_VAR(PlayerEconomyEntry, delivered_cargo,     SLE_INT32),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1219
	    SLE_VAR(PlayerEconomyEntry, performance_history, SLE_INT32),
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 165
diff changeset
  1220
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1834
diff changeset
  1224
static const SaveLoad _player_ai_desc[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1225
	    SLE_VAR(PlayerAI, state,             SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1226
	    SLE_VAR(PlayerAI, tick,              SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1227
	SLE_CONDVAR(PlayerAI, state_counter,     SLE_FILE_U16 | SLE_VAR_U32,  0, 12),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1228
	SLE_CONDVAR(PlayerAI, state_counter,     SLE_UINT32,                 13, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1229
	    SLE_VAR(PlayerAI, timeout_counter,   SLE_UINT16),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1231
	    SLE_VAR(PlayerAI, state_mode,        SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1232
	    SLE_VAR(PlayerAI, banned_tile_count, SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1233
	    SLE_VAR(PlayerAI, railtype_to_use,   SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1235
	    SLE_VAR(PlayerAI, cargo_type,        SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1236
	    SLE_VAR(PlayerAI, num_wagons,        SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1237
	    SLE_VAR(PlayerAI, build_kind,        SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1238
	    SLE_VAR(PlayerAI, num_build_rec,     SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1239
	    SLE_VAR(PlayerAI, num_loco_to_build, SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1240
	    SLE_VAR(PlayerAI, num_want_fullload, SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1242
	    SLE_VAR(PlayerAI, route_type_mask,   SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1244
	SLE_CONDVAR(PlayerAI, start_tile_a,      SLE_FILE_U16 | SLE_VAR_U32,  0,  5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1245
	SLE_CONDVAR(PlayerAI, start_tile_a,      SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1246
	SLE_CONDVAR(PlayerAI, cur_tile_a,        SLE_FILE_U16 | SLE_VAR_U32,  0,  5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1247
	SLE_CONDVAR(PlayerAI, cur_tile_a,        SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1248
	    SLE_VAR(PlayerAI, start_dir_a,       SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1249
	    SLE_VAR(PlayerAI, cur_dir_a,         SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1250
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1251
	SLE_CONDVAR(PlayerAI, start_tile_b,      SLE_FILE_U16 | SLE_VAR_U32,  0,  5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1252
	SLE_CONDVAR(PlayerAI, start_tile_b,      SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1253
	SLE_CONDVAR(PlayerAI, cur_tile_b,        SLE_FILE_U16 | SLE_VAR_U32,  0,  5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1254
	SLE_CONDVAR(PlayerAI, cur_tile_b,        SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1255
	    SLE_VAR(PlayerAI, start_dir_b,       SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1256
	    SLE_VAR(PlayerAI, cur_dir_b,         SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1257
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1258
	    SLE_REF(PlayerAI, cur_veh,           REF_VEHICLE),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1259
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1260
	    SLE_ARR(PlayerAI, wagon_list,        SLE_UINT16, 9),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1261
	    SLE_ARR(PlayerAI, order_list_blocks, SLE_UINT8, 20),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1262
	    SLE_ARR(PlayerAI, banned_tiles,      SLE_UINT16, 16),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3047
diff changeset
  1264
	SLE_CONDNULL(64, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1834
diff changeset
  1268
static const SaveLoad _player_ai_build_rec_desc[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1269
	SLE_CONDVAR(AiBuildRec, spec_tile,         SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1270
	SLE_CONDVAR(AiBuildRec, spec_tile,         SLE_UINT32,                 6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1271
	SLE_CONDVAR(AiBuildRec, use_tile,          SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1272
	SLE_CONDVAR(AiBuildRec, use_tile,          SLE_UINT32,                 6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1273
	    SLE_VAR(AiBuildRec, rand_rng,          SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1274
	    SLE_VAR(AiBuildRec, cur_building_rule, SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1275
	    SLE_VAR(AiBuildRec, unk6,              SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1276
	    SLE_VAR(AiBuildRec, unk7,              SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1277
	    SLE_VAR(AiBuildRec, buildcmd_a,        SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1278
	    SLE_VAR(AiBuildRec, buildcmd_b,        SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1279
	    SLE_VAR(AiBuildRec, direction,         SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1280
	    SLE_VAR(AiBuildRec, cargo,             SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
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: 4580
diff changeset
  1284
static const SaveLoad _player_livery_desc[] = {
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: 4580
diff changeset
  1285
	SLE_CONDVAR(Livery, in_use,  SLE_BOOL,  34, SL_MAX_VERSION),
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: 4580
diff changeset
  1286
	SLE_CONDVAR(Livery, colour1, SLE_UINT8, 34, SL_MAX_VERSION),
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: 4580
diff changeset
  1287
	SLE_CONDVAR(Livery, colour2, SLE_UINT8, 34, SL_MAX_VERSION),
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: 4580
diff changeset
  1288
	SLE_END()
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: 4580
diff changeset
  1289
};
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: 4580
diff changeset
  1290
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
  1291
static void SaveLoad_PLYR(Player* p)
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
  1292
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
	SlObject(p, _player_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
	// Write AI?
4845
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
  1298
	if (!IsHumanPlayer(p->index)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
		SlObject(&p->ai, _player_ai_desc);
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
  1300
		for (i = 0; i != p->ai.num_build_rec; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
			SlObject(&p->ai.src + i, _player_ai_build_rec_desc);
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3873
diff changeset
  1302
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
	// Write economy
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
	SlObject(&p->cur_economy, _player_economy_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
	// Write old economy entries.
2988
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1309
	for (i = 0; i < p->num_valid_stat_ent; i++) {
26ff5a921204 (svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents: 2987
diff changeset
  1310
		SlObject(&p->old_economy[i], _player_economy_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
	}
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: 4580
diff changeset
  1312
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: 4580
diff changeset
  1313
	// Write each livery entry.
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: 4580
diff changeset
  1314
	for (i = 0; i < LS_END; i++) {
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: 4580
diff changeset
  1315
		SlObject(&p->livery[i], _player_livery_desc);
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: 4580
diff changeset
  1316
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1021
diff changeset
  1319
static void Save_PLYR(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
	FOR_ALL_PLAYERS(p) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
		if (p->is_active) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
			SlSetArrayIndex(p->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
			SlAutolength((AutolengthProc*)SaveLoad_PLYR, p);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1328
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1021
diff changeset
  1330
static void Load_PLYR(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
	while ((index = SlIterateArray()) != -1) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1334
		Player *p = GetPlayer((PlayerID)index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
		SaveLoad_PLYR(p);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
		_player_colors[index] = p->player_color;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
		UpdatePlayerMoney32(p);
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2381
diff changeset
  1338
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2381
diff changeset
  1339
		/* This is needed so an AI is attached to a loaded AI */
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2381
diff changeset
  1340
		if (p->is_ai && (!_networking || _network_server) && _ai.enabled)
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2381
diff changeset
  1341
			AI_StartNewAI(p->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1345
extern const ChunkHandler _player_chunk_handlers[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
	{ 'PLYR', Save_PLYR, Load_PLYR, CH_ARRAY | CH_LAST},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
};