author | rubidium |
Fri, 18 Apr 2008 23:33:51 +0000 | |
branch | noai |
changeset 10249 | 58810805030e |
parent 10188 | 13e73691378a |
child 10294 | 7798ae816af8 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6443
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6195
diff
changeset
|
3 |
/** @file players.cpp |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4444
diff
changeset
|
4 |
*/ |
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
7 |
#include "engine_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
8 |
#include "player_func.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
9 |
#include "player_gui.h" |
0 | 10 |
#include "town.h" |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9724
diff
changeset
|
11 |
#include "news_func.h" |
0 | 12 |
#include "saveload.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
13 |
#include "command_func.h" |
5720
cc0ceeafaa55
(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:
5692
diff
changeset
|
14 |
#include "network/network.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
15 |
#include "network/network_internal.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2154
diff
changeset
|
16 |
#include "variables.h" |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10188
diff
changeset
|
17 |
#include "cheat_func.h" |
9429
25b7d020a3a9
(svn r9232) [NoAI] -Fix r9230: incode update about file/dir moving
truelight
parents:
9360
diff
changeset
|
18 |
#include "ai/ai.h" |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
19 |
#include "player_face.h" |
9624 | 20 |
#include "group.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
21 |
#include "window_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
22 |
#include "tile_map.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
23 |
#include "strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
24 |
#include "gfx_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
25 |
#include "functions.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
26 |
#include "date_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
27 |
#include "vehicle_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
28 |
#include "sound_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
29 |
#include "autoreplace_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
30 |
#include "autoreplace_gui.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
31 |
#include "string_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
32 |
#include "road_func.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
33 |
#include "rail.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
34 |
#include "settings_type.h" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
35 |
#include "sprite.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
36 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
37 |
#include "table/strings.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
38 |
#include "table/sprites.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
39 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
40 |
Player _players[MAX_PLAYERS]; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
41 |
PlayerByte _local_player; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
42 |
PlayerByte _current_player; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
43 |
/* NOSAVE: can be determined from player structs */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
44 |
byte _player_colors[MAX_PLAYERS]; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
45 |
PlayerFace _player_face; ///< for player face storage in openttd.cfg |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
46 |
HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5 |
0 | 47 |
|
5564
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
48 |
/** |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
49 |
* Sets the local player and updates the patch settings that are set on a |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
50 |
* per-company (player) basis to reflect the core's state in the GUI. |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
51 |
* @param new_player the new player |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
52 |
* @pre IsValidPlayer(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
53 |
*/ |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
54 |
void SetLocalPlayer(PlayerID new_player) |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
55 |
{ |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
56 |
/* Player could also be PLAYER_SPECTATOR or OWNER_NONE */ |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
57 |
assert(IsValidPlayer(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE); |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
58 |
|
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
59 |
_local_player = new_player; |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
60 |
|
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
61 |
/* Do not update the patches if we are in the intro GUI */ |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
62 |
if (IsValidPlayer(new_player) && _game_mode != GM_MENU) { |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
63 |
const Player *p = GetPlayer(new_player); |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
64 |
_patches.autorenew = p->engine_renew; |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
65 |
_patches.autorenew_months = p->engine_renew_months; |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
66 |
_patches.autorenew_money = p->engine_renew_money; |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
67 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
68 |
} |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
69 |
} |
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
70 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
71 |
bool IsHumanPlayer(PlayerID pi) |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
72 |
{ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
73 |
return !GetPlayer(pi)->is_ai; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
74 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
75 |
|
4428
0b0ee542d5b6
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
76 |
|
0b0ee542d5b6
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
77 |
uint16 GetDrawStringPlayerColor(PlayerID player) |
0b0ee542d5b6
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
78 |
{ |
4944
c61494b1ec35
(svn r6932) -Codechange: Send server messages with format NETWORK_ACTION_SERVER_MESSAGE so it is
Darkvater
parents:
4921
diff
changeset
|
79 |
/* Get the color for DrawString-subroutines which matches the color |
c61494b1ec35
(svn r6932) -Codechange: Send server messages with format NETWORK_ACTION_SERVER_MESSAGE so it is
Darkvater
parents:
4921
diff
changeset
|
80 |
* of the player */ |
c61494b1ec35
(svn r6932) -Codechange: Send server messages with format NETWORK_ACTION_SERVER_MESSAGE so it is
Darkvater
parents:
4921
diff
changeset
|
81 |
if (!IsValidPlayer(player)) return _colour_gradient[COLOUR_WHITE][4] | IS_PALETTE_COLOR; |
4444
9c9c7f962482
(svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents:
4428
diff
changeset
|
82 |
return (_colour_gradient[_player_colors[player]][4]) | IS_PALETTE_COLOR; |
4428
0b0ee542d5b6
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
83 |
} |
0b0ee542d5b6
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
84 |
|
6001
1e4c5406cd1a
(svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents:
5943
diff
changeset
|
85 |
void DrawPlayerIcon(PlayerID p, int x, int y) |
1e4c5406cd1a
(svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents:
5943
diff
changeset
|
86 |
{ |
1e4c5406cd1a
(svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents:
5943
diff
changeset
|
87 |
DrawSprite(SPR_PLAYER_ICON, PLAYER_SPRITE_COLOR(p), x, y); |
1e4c5406cd1a
(svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents:
5943
diff
changeset
|
88 |
} |
1e4c5406cd1a
(svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents:
5943
diff
changeset
|
89 |
|
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
90 |
/** |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
91 |
* Converts an old player face format to the new player face format |
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
92 |
* |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
93 |
* Meaning of the bits in the old face (some bits are used in several times): |
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
94 |
* - 4 and 5: chin |
6475
f80c51a83069
(svn r8892) -Fix (r8879): swapped the eye colour and eyebrow bits.
rubidium
parents:
6470
diff
changeset
|
95 |
* - 6 to 9: eyebrows |
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
96 |
* - 10 to 13: nose |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
97 |
* - 13 to 15: lips (also moustache for males) |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
98 |
* - 16 to 19: hair |
6475
f80c51a83069
(svn r8892) -Fix (r8879): swapped the eye colour and eyebrow bits.
rubidium
parents:
6470
diff
changeset
|
99 |
* - 20 to 22: eye color |
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
100 |
* - 20 to 27: tie, ear rings etc. |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
101 |
* - 28 to 30: glasses |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
102 |
* - 19, 26 and 27: race (bit 27 set and bit 19 equal to bit 26 = black, otherwise white) |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
103 |
* - 31: gender (0 = male, 1 = female) |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
104 |
* |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
105 |
* @param face the face in the old format |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
106 |
* @return the face in the new format |
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
107 |
*/ |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
108 |
PlayerFace ConvertFromOldPlayerFace(uint32 face) |
0 | 109 |
{ |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
110 |
PlayerFace pf = 0; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
111 |
GenderEthnicity ge = GE_WM; |
0 | 112 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
113 |
if (HasBit(face, 31)) SetBit(ge, GENDER_FEMALE); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
114 |
if (HasBit(face, 27) && (HasBit(face, 26) == HasBit(face, 19))) SetBit(ge, ETHNICITY_BLACK); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
115 |
|
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
116 |
SetPlayerFaceBits(pf, PFV_GEN_ETHN, ge, ge); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
117 |
SetPlayerFaceBits(pf, PFV_HAS_GLASSES, ge, GB(face, 28, 3) <= 1); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
118 |
SetPlayerFaceBits(pf, PFV_EYE_COLOUR, ge, HasBit(ge, ETHNICITY_BLACK) ? 0 : ClampU(GB(face, 20, 3), 5, 7) - 5); |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
119 |
SetPlayerFaceBits(pf, PFV_CHIN, ge, ScalePlayerFaceValue(PFV_CHIN, ge, GB(face, 4, 2))); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
120 |
SetPlayerFaceBits(pf, PFV_EYEBROWS, ge, ScalePlayerFaceValue(PFV_EYEBROWS, ge, GB(face, 6, 4))); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
121 |
SetPlayerFaceBits(pf, PFV_HAIR, ge, ScalePlayerFaceValue(PFV_HAIR, ge, GB(face, 16, 4))); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
122 |
SetPlayerFaceBits(pf, PFV_JACKET, ge, ScalePlayerFaceValue(PFV_JACKET, ge, GB(face, 20, 2))); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
123 |
SetPlayerFaceBits(pf, PFV_COLLAR, ge, ScalePlayerFaceValue(PFV_COLLAR, ge, GB(face, 22, 2))); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
124 |
SetPlayerFaceBits(pf, PFV_GLASSES, ge, GB(face, 28, 1)); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
125 |
|
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
126 |
uint lips = GB(face, 10, 4); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
127 |
if (!HasBit(ge, GENDER_FEMALE) && lips < 4) { |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
128 |
SetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge, true); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
129 |
SetPlayerFaceBits(pf, PFV_MOUSTACHE, ge, max(lips, 1U) - 1); |
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
130 |
} else { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
131 |
if (!HasBit(ge, GENDER_FEMALE)) { |
9505 | 132 |
lips = lips * 15 / 16; |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
133 |
lips -= 3; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
134 |
if (HasBit(ge, ETHNICITY_BLACK) && lips > 8) lips = 0; |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
135 |
} else { |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
136 |
lips = ScalePlayerFaceValue(PFV_LIPS, ge, lips); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
137 |
} |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
138 |
SetPlayerFaceBits(pf, PFV_LIPS, ge, lips); |
0 | 139 |
|
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
140 |
uint nose = GB(face, 13, 3); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
141 |
if (ge == GE_WF) { |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
142 |
nose = (nose * 3 >> 3) * 3 >> 2; // There is 'hole' in the nose sprites for females |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
143 |
} else { |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
144 |
nose = ScalePlayerFaceValue(PFV_NOSE, ge, nose); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
145 |
} |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
146 |
SetPlayerFaceBits(pf, PFV_NOSE, ge, nose); |
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
147 |
} |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
148 |
|
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
149 |
uint tie_earring = GB(face, 24, 4); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
150 |
if (!HasBit(ge, GENDER_FEMALE) || tie_earring < 3) { // Not all females have an earring |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
151 |
if (HasBit(ge, GENDER_FEMALE)) SetPlayerFaceBits(pf, PFV_HAS_TIE_EARRING, ge, true); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
152 |
SetPlayerFaceBits(pf, PFV_TIE_EARRING, ge, HasBit(ge, GENDER_FEMALE) ? tie_earring : ScalePlayerFaceValue(PFV_TIE_EARRING, ge, tie_earring / 2)); |
0 | 153 |
} |
154 |
||
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
155 |
return pf; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
156 |
} |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
157 |
|
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
158 |
/** |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
159 |
* Checks whether a player's face is a valid encoding. |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
160 |
* Unused bits are not enforced to be 0. |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
161 |
* @param pf the fact to check |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
162 |
* @return true if and only if the face is valid |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
163 |
*/ |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
164 |
bool IsValidPlayerFace(PlayerFace pf) |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
165 |
{ |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
166 |
if (!ArePlayerFaceBitsValid(pf, PFV_GEN_ETHN, GE_WM)) return false; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
167 |
|
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
168 |
GenderEthnicity ge = (GenderEthnicity)GetPlayerFaceBits(pf, PFV_GEN_ETHN, GE_WM); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
169 |
bool has_moustache = !HasBit(ge, GENDER_FEMALE) && GetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge) != 0; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
170 |
bool has_tie_earring = !HasBit(ge, GENDER_FEMALE) || GetPlayerFaceBits(pf, PFV_HAS_TIE_EARRING, ge) != 0; |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
171 |
bool has_glasses = GetPlayerFaceBits(pf, PFV_HAS_GLASSES, ge) != 0; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
172 |
|
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
173 |
if (!ArePlayerFaceBitsValid(pf, PFV_EYE_COLOUR, ge)) return false; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
174 |
for (PlayerFaceVariable pfv = PFV_CHEEKS; pfv < PFV_END; pfv++) { |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
175 |
switch (pfv) { |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
176 |
case PFV_MOUSTACHE: if (!has_moustache) continue; break; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
177 |
case PFV_LIPS: /* FALL THROUGH */ |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
178 |
case PFV_NOSE: if (has_moustache) continue; break; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
179 |
case PFV_TIE_EARRING: if (!has_tie_earring) continue; break; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
180 |
case PFV_GLASSES: if (!has_glasses) continue; break; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
181 |
default: break; |
6470
a868173ae25b
(svn r8887) -Fix (r8879)[MorphOS]: initialization of mouth_table[] skipped by goto
KUDr
parents:
6463
diff
changeset
|
182 |
} |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
183 |
if (!ArePlayerFaceBitsValid(pf, pfv, ge)) return false; |
0 | 184 |
} |
185 |
||
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
186 |
return true; |
0 | 187 |
} |
188 |
||
2475 | 189 |
void InvalidatePlayerWindows(const Player *p) |
0 | 190 |
{ |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2147
diff
changeset
|
191 |
PlayerID pid = p->index; |
0 | 192 |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2147
diff
changeset
|
193 |
if (pid == _local_player) InvalidateWindow(WC_STATUS_BAR, 0); |
0 | 194 |
InvalidateWindow(WC_FINANCES, pid); |
195 |
} |
|
196 |
||
9629 | 197 |
bool CheckPlayerHasMoney(CommandCost cost) |
0 | 198 |
{ |
9629 | 199 |
if (cost.GetCost() > 0) { |
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2484
diff
changeset
|
200 |
PlayerID pid = _current_player; |
9629 | 201 |
if (IsValidPlayer(pid) && cost.GetCost() > GetPlayer(pid)->player_money) { |
202 |
SetDParam(0, cost.GetCost()); |
|
0 | 203 |
_error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES; |
204 |
return false; |
|
205 |
} |
|
206 |
} |
|
207 |
return true; |
|
208 |
} |
|
209 |
||
9629 | 210 |
static void SubtractMoneyFromAnyPlayer(Player *p, CommandCost cost) |
0 | 211 |
{ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
212 |
if (cost.GetCost() == 0) return; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
213 |
assert(cost.GetExpensesType() != INVALID_EXPENSES); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
214 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
215 |
p->player_money -= cost.GetCost(); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
216 |
p->yearly_expenses[0][cost.GetExpensesType()] += cost.GetCost(); |
0 | 217 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
218 |
if (HasBit(1 << EXPENSES_TRAIN_INC | |
9626 | 219 |
1 << EXPENSES_ROADVEH_INC | |
220 |
1 << EXPENSES_AIRCRAFT_INC | |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
221 |
1 << EXPENSES_SHIP_INC, cost.GetExpensesType())) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
222 |
p->cur_economy.income -= cost.GetCost(); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
223 |
} else if (HasBit(1 << EXPENSES_TRAIN_RUN | |
9626 | 224 |
1 << EXPENSES_ROADVEH_RUN | |
225 |
1 << EXPENSES_AIRCRAFT_RUN | |
|
226 |
1 << EXPENSES_SHIP_RUN | |
|
227 |
1 << EXPENSES_PROPERTY | |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
228 |
1 << EXPENSES_LOAN_INT, cost.GetExpensesType())) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
229 |
p->cur_economy.expenses -= cost.GetCost(); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
230 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
231 |
|
0 | 232 |
InvalidatePlayerWindows(p); |
233 |
} |
|
234 |
||
9629 | 235 |
void SubtractMoneyFromPlayer(CommandCost cost) |
0 | 236 |
{ |
1796
cae31916ae54
(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
|
237 |
PlayerID pid = _current_player; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
238 |
|
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4849
diff
changeset
|
239 |
if (IsValidPlayer(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost); |
0 | 240 |
} |
241 |
||
9629 | 242 |
void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cst) |
0 | 243 |
{ |
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1901
diff
changeset
|
244 |
Player *p = GetPlayer(player); |
0 | 245 |
byte m = p->player_money_fraction; |
9629 | 246 |
Money cost = cst.GetCost(); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
247 |
|
0 | 248 |
p->player_money_fraction = m - (byte)cost; |
249 |
cost >>= 8; |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
250 |
if (p->player_money_fraction > m) cost++; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
251 |
if (cost != 0) SubtractMoneyFromAnyPlayer(p, CommandCost(cst.GetExpensesType(), cost)); |
0 | 252 |
} |
253 |
||
4849
9a3c3ae7f62f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
254 |
void GetNameOfOwner(Owner owner, TileIndex tile) |
0 | 255 |
{ |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
256 |
SetDParam(2, owner); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
257 |
|
0 | 258 |
if (owner != OWNER_TOWN) { |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4849
diff
changeset
|
259 |
if (!IsValidPlayer(owner)) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
260 |
SetDParam(0, STR_0150_SOMEONE); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
261 |
} else { |
4000
bab1ebc37da0
(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
|
262 |
const Player* p = GetPlayer(owner); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
263 |
|
9629 | 264 |
SetDParam(0, STR_COMPANY_NAME); |
265 |
SetDParam(1, p->index); |
|
0 | 266 |
} |
267 |
} else { |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
268 |
const Town* t = ClosestTownFromTile(tile, (uint)-1); |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
269 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
1977
diff
changeset
|
270 |
SetDParam(0, STR_TOWN); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
1977
diff
changeset
|
271 |
SetDParam(1, t->index); |
0 | 272 |
} |
273 |
} |
|
274 |
||
275 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
276 |
bool CheckOwnership(PlayerID owner) |
0 | 277 |
{ |
4849
9a3c3ae7f62f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
278 |
assert(owner < OWNER_END); |
0 | 279 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
280 |
if (owner == _current_player) return true; |
0 | 281 |
_error_message = STR_013B_OWNED_BY; |
282 |
GetNameOfOwner(owner, 0); |
|
283 |
return false; |
|
284 |
} |
|
285 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
286 |
bool CheckTileOwnership(TileIndex tile) |
0 | 287 |
{ |
4849
9a3c3ae7f62f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
288 |
Owner owner = GetTileOwner(tile); |
1901
fb05044cf5c3
(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
|
289 |
|
4849
9a3c3ae7f62f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
290 |
assert(owner < OWNER_END); |
1901
fb05044cf5c3
(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
|
291 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
292 |
if (owner == _current_player) return true; |
0 | 293 |
_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
|
294 |
|
9505 | 295 |
/* no need to get the name of the owner unless we're the local player (saves some time) */ |
2425
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2395
diff
changeset
|
296 |
if (IsLocalPlayer()) GetNameOfOwner(owner, tile); |
0 | 297 |
return false; |
298 |
} |
|
299 |
||
300 |
static void GenerateCompanyName(Player *p) |
|
301 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
302 |
TileIndex tile; |
0 | 303 |
Town *t; |
304 |
StringID str; |
|
305 |
Player *pp; |
|
306 |
uint32 strp; |
|
307 |
char buffer[100]; |
|
308 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
309 |
if (p->name_1 != STR_SV_UNNAMED) return; |
0 | 310 |
|
311 |
tile = p->last_build_coordinate; |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
312 |
if (tile == 0) return; |
0 | 313 |
|
314 |
t = ClosestTownFromTile(tile, (uint)-1); |
|
315 |
||
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10188
diff
changeset
|
316 |
if (IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) { |
0 | 317 |
str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_PLAYERNAME_START; |
318 |
strp = t->townnameparts; |
|
319 |
||
320 |
verify_name:; |
|
9505 | 321 |
/* No player must have this name already */ |
0 | 322 |
FOR_ALL_PLAYERS(pp) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
323 |
if (pp->name_1 == str && pp->name_2 == strp) goto bad_town_name; |
0 | 324 |
} |
325 |
||
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4878
diff
changeset
|
326 |
GetString(buffer, str, lastof(buffer)); |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4606
diff
changeset
|
327 |
if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 150) |
0 | 328 |
goto bad_town_name; |
329 |
||
330 |
set_name:; |
|
331 |
p->name_1 = str; |
|
332 |
p->name_2 = strp; |
|
333 |
||
334 |
MarkWholeScreenDirty(); |
|
335 |
||
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4824
diff
changeset
|
336 |
if (!IsHumanPlayer(p->index)) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
337 |
SetDParam(0, t->index); |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9724
diff
changeset
|
338 |
AddNewsItem((StringID)(p->index | NB_BNEWCOMPANY), NM_CALLBACK, NF_TILE, NT_COMPANY_INFO, DNC_BANKRUPCY, p->last_build_coordinate, 0); |
0 | 339 |
} |
340 |
return; |
|
341 |
} |
|
342 |
bad_town_name:; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
343 |
|
0 | 344 |
if (p->president_name_1 == SPECSTR_PRESIDENT_NAME) { |
345 |
str = SPECSTR_ANDCO_NAME; |
|
346 |
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
|
347 |
goto set_name; |
0 | 348 |
} else { |
349 |
str = SPECSTR_ANDCO_NAME; |
|
350 |
strp = Random(); |
|
351 |
goto verify_name; |
|
352 |
} |
|
353 |
} |
|
354 |
||
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10188
diff
changeset
|
355 |
#define COLOR_SWAP(i, j) do { byte t = colors[i];colors[i] = colors[j];colors[j] = t; } while(0) |
0 | 356 |
|
357 |
static const byte _color_sort[16] = {2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 1, 1}; |
|
358 |
static const byte _color_similar_1[16] = {8, 6, 255, 12, 255, 0, 1, 1, 0, 13, 11, 10, 3, 9, 15, 14}; |
|
359 |
static const byte _color_similar_2[16] = {5, 7, 255, 255, 255, 8, 7, 6, 5, 12, 255, 255, 9, 255, 255, 255}; |
|
360 |
||
6573 | 361 |
static byte GeneratePlayerColor() |
0 | 362 |
{ |
363 |
byte colors[16], pcolor, t2; |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10188
diff
changeset
|
364 |
int i, j, n; |
0 | 365 |
uint32 r; |
366 |
Player *p; |
|
367 |
||
9505 | 368 |
/* Initialize array */ |
2952 | 369 |
for (i = 0; i != 16; i++) colors[i] = i; |
0 | 370 |
|
9505 | 371 |
/* And randomize it */ |
0 | 372 |
n = 100; |
373 |
do { |
|
374 |
r = Random(); |
|
2140
d708eb80ab8b
(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
|
375 |
COLOR_SWAP(GB(r, 0, 4), GB(r, 4, 4)); |
0 | 376 |
} while (--n); |
377 |
||
9505 | 378 |
/* Bubble sort it according to the values in table 1 */ |
0 | 379 |
i = 16; |
380 |
do { |
|
2952 | 381 |
for (j = 0; j != 15; j++) { |
382 |
if (_color_sort[colors[j]] < _color_sort[colors[j + 1]]) { |
|
383 |
COLOR_SWAP(j, j + 1); |
|
0 | 384 |
} |
385 |
} |
|
386 |
} while (--i); |
|
387 |
||
9505 | 388 |
/* Move the colors that look similar to each player's color to the side */ |
0 | 389 |
FOR_ALL_PLAYERS(p) if (p->is_active) { |
390 |
pcolor = p->player_color; |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10188
diff
changeset
|
391 |
for (i = 0; i != 16; i++) if (colors[i] == pcolor) { |
0 | 392 |
colors[i] = 0xFF; |
393 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
394 |
t2 = _color_similar_1[pcolor]; |
0 | 395 |
if (t2 == 0xFF) break; |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10188
diff
changeset
|
396 |
for (i = 0; i != 15; i++) { |
0 | 397 |
if (colors[i] == t2) { |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10188
diff
changeset
|
398 |
do COLOR_SWAP(i, i + 1); while (++i != 15); |
0 | 399 |
break; |
400 |
} |
|
401 |
} |
|
402 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
403 |
t2 = _color_similar_2[pcolor]; |
0 | 404 |
if (t2 == 0xFF) break; |
2952 | 405 |
for (i = 0; i != 15; i++) { |
0 | 406 |
if (colors[i] == t2) { |
2952 | 407 |
do COLOR_SWAP(i, i + 1); while (++i != 15); |
0 | 408 |
break; |
409 |
} |
|
410 |
} |
|
411 |
break; |
|
412 |
} |
|
413 |
} |
|
414 |
||
9505 | 415 |
/* Return the first available color */ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
416 |
for (i = 0;; i++) { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
417 |
if (colors[i] != 0xFF) return colors[i]; |
0 | 418 |
} |
419 |
} |
|
420 |
||
421 |
static void GeneratePresidentName(Player *p) |
|
422 |
{ |
|
423 |
Player *pp; |
|
424 |
char buffer[100], buffer2[40]; |
|
425 |
||
2952 | 426 |
for (;;) { |
0 | 427 |
restart:; |
428 |
||
429 |
p->president_name_2 = Random(); |
|
430 |
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
|
431 |
|
9629 | 432 |
SetDParam(0, p->index); |
433 |
GetString(buffer, STR_PLAYER_NAME, lastof(buffer)); |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4606
diff
changeset
|
434 |
if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 94) |
0 | 435 |
continue; |
436 |
||
437 |
FOR_ALL_PLAYERS(pp) { |
|
438 |
if (pp->is_active && p != pp) { |
|
9629 | 439 |
SetDParam(0, pp->index); |
440 |
GetString(buffer2, STR_PLAYER_NAME, lastof(buffer2)); |
|
1304
8570010abe7b
(svn r1808) Use strcmp() instead of home brewed function str_eq()
tron
parents:
1174
diff
changeset
|
441 |
if (strcmp(buffer2, buffer) == 0) |
0 | 442 |
goto restart; |
443 |
} |
|
444 |
} |
|
445 |
return; |
|
446 |
} |
|
447 |
} |
|
448 |
||
6573 | 449 |
static Player *AllocatePlayer() |
0 | 450 |
{ |
451 |
Player *p; |
|
9505 | 452 |
/* Find a free slot */ |
0 | 453 |
FOR_ALL_PLAYERS(p) { |
454 |
if (!p->is_active) { |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
455 |
PlayerID i = p->index; |
0 | 456 |
memset(p, 0, sizeof(Player)); |
457 |
p->index = i; |
|
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
458 |
p->is_noai = true; |
0 | 459 |
return p; |
460 |
} |
|
461 |
} |
|
462 |
return NULL; |
|
463 |
} |
|
464 |
||
4603
3ccd4ee0a2e2
(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
|
465 |
void ResetPlayerLivery(Player *p) |
3ccd4ee0a2e2
(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
|
466 |
{ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
467 |
for (LiveryScheme scheme = LS_BEGIN; scheme < LS_END; scheme++) { |
4603
3ccd4ee0a2e2
(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
|
468 |
p->livery[scheme].in_use = false; |
3ccd4ee0a2e2
(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
|
469 |
p->livery[scheme].colour1 = p->player_color; |
3ccd4ee0a2e2
(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
|
470 |
p->livery[scheme].colour2 = p->player_color; |
3ccd4ee0a2e2
(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
|
471 |
} |
3ccd4ee0a2e2
(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
|
472 |
} |
3ccd4ee0a2e2
(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
|
473 |
|
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9686
diff
changeset
|
474 |
/** |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9686
diff
changeset
|
475 |
* Create a new player and sets all player variables default values |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9686
diff
changeset
|
476 |
* |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9686
diff
changeset
|
477 |
* @param is_ai is a ai player? |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9686
diff
changeset
|
478 |
* @return the player struct |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9686
diff
changeset
|
479 |
*/ |
0 | 480 |
Player *DoStartupNewPlayer(bool is_ai) |
481 |
{ |
|
482 |
Player *p; |
|
483 |
||
484 |
p = AllocatePlayer(); |
|
4000
bab1ebc37da0
(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
|
485 |
if (p == NULL) return NULL; |
0 | 486 |
|
9505 | 487 |
/* Make a color */ |
0 | 488 |
p->player_color = GeneratePlayerColor(); |
4603
3ccd4ee0a2e2
(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
|
489 |
ResetPlayerLivery(p); |
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
490 |
_player_colors[p->index] = p->player_color; |
0 | 491 |
p->name_1 = STR_SV_UNNAMED; |
492 |
p->is_active = true; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
493 |
|
9629 | 494 |
p->player_money = p->current_loan = 100000; |
0 | 495 |
|
496 |
p->is_ai = is_ai; |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
497 |
p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = PLAYER_SPECTATOR; |
0 | 498 |
|
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
499 |
p->avail_railtypes = GetPlayerRailtypes(p->index); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
500 |
p->avail_roadtypes = GetPlayerRoadtypes(p->index); |
4326
c2ae4dbc1074
(svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents:
4321
diff
changeset
|
501 |
p->inaugurated_year = _cur_year; |
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9686
diff
changeset
|
502 |
RandomPlayerFaceBits(p->face, (GenderEthnicity)Random(), false); // create a random player face |
0 | 503 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
504 |
/* Engine renewal settings */ |
2848 | 505 |
p->engine_renew_list = NULL; |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
506 |
p->renew_keep_length = false; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
507 |
p->engine_renew = _patches_newgame.autorenew; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
508 |
p->engine_renew_months = _patches_newgame.autorenew_months; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
509 |
p->engine_renew_money = _patches_newgame.autorenew_money; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
510 |
|
0 | 511 |
GeneratePresidentName(p); |
512 |
||
513 |
InvalidateWindow(WC_GRAPH_LEGEND, 0); |
|
514 |
InvalidateWindow(WC_TOOLBAR_MENU, 0); |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
515 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
0 | 516 |
|
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
9359
diff
changeset
|
517 |
if (is_ai) AI_StartNewAI(p->index); |
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
518 |
|
4580
31f863c3aa7a
(svn r6430) -Fix r6424: fixed failure to init the whole array of engines when starting a new player
bjarni
parents:
4574
diff
changeset
|
519 |
memset(p->num_engines, 0, sizeof(p->num_engines)); |
4574
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4549
diff
changeset
|
520 |
|
0 | 521 |
return p; |
522 |
} |
|
523 |
||
6573 | 524 |
void StartupPlayers() |
0 | 525 |
{ |
9505 | 526 |
/* 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
|
527 |
_next_competitor_start = _opt.diff.competitor_start_time * 90 * DAY_TICKS + RandomRange(60 * DAY_TICKS) + 1; |
0 | 528 |
} |
529 |
||
6573 | 530 |
static void MaybeStartNewPlayer() |
0 | 531 |
{ |
532 |
uint n; |
|
533 |
Player *p; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
534 |
|
9505 | 535 |
/* count number of competitors */ |
0 | 536 |
n = 0; |
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
537 |
FOR_ALL_PLAYERS(p) { |
4000
bab1ebc37da0
(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
|
538 |
if (p->is_active && p->is_ai) n++; |
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
539 |
} |
0 | 540 |
|
9505 | 541 |
/* when there's a lot of computers in game, the probability that a new one starts is lower */ |
4000
bab1ebc37da0
(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
|
542 |
if (n < (uint)_opt.diff.max_no_competitors && |
bab1ebc37da0
(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
|
543 |
n < (_network_server ? |
bab1ebc37da0
(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
|
544 |
InteractiveRandomRange(_opt.diff.max_no_competitors + 2) : |
bab1ebc37da0
(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
|
545 |
RandomRange(_opt.diff.max_no_competitors + 2) |
bab1ebc37da0
(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
|
546 |
)) { |
bab1ebc37da0
(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
|
547 |
/* Send a command to all clients to start up a new AI. |
bab1ebc37da0
(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
|
548 |
* Works fine for Multiplayer and Singleplayer */ |
bab1ebc37da0
(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
|
549 |
DoCommandP(0, 1, 0, NULL, CMD_PLAYER_CTRL); |
bab1ebc37da0
(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
|
550 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
551 |
|
9505 | 552 |
/* The next AI starts like the difficulty setting said, with +2 month max */ |
2092
c30495feef79
(svn r2602) -Codechange: removed unused variable (disable_computer)
truelight
parents:
2070
diff
changeset
|
553 |
_next_competitor_start = _opt.diff.competitor_start_time * 90 * DAY_TICKS + 1; |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
554 |
_next_competitor_start += _network_server ? InteractiveRandomRange(60 * DAY_TICKS) : RandomRange(60 * DAY_TICKS); |
0 | 555 |
} |
556 |
||
6573 | 557 |
void InitializePlayers() |
0 | 558 |
{ |
559 |
memset(_players, 0, sizeof(_players)); |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
560 |
for (PlayerID i = PLAYER_FIRST; i != MAX_PLAYERS; i++) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
561 |
_players[i].index = i; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
562 |
for (uint j = 0; j < 4; j++) _players[i].share_owners[j] = PLAYER_SPECTATOR; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
563 |
} |
0 | 564 |
_cur_player_tick_index = 0; |
565 |
} |
|
566 |
||
6573 | 567 |
void OnTick_Players() |
0 | 568 |
{ |
569 |
Player *p; |
|
570 |
||
4000
bab1ebc37da0
(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
|
571 |
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
|
572 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
573 |
p = GetPlayer((PlayerID)_cur_player_tick_index); |
0 | 574 |
_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS; |
575 |
if (p->name_1 != 0) GenerateCompanyName(p); |
|
576 |
||
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
577 |
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
|
578 |
MaybeStartNewPlayer(); |
0 | 579 |
} |
580 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
581 |
extern void ShowPlayerFinances(PlayerID player); |
0 | 582 |
|
6573 | 583 |
void PlayersYearlyLoop() |
0 | 584 |
{ |
585 |
Player *p; |
|
586 |
||
9505 | 587 |
/* Copy statistics */ |
0 | 588 |
FOR_ALL_PLAYERS(p) { |
589 |
if (p->is_active) { |
|
590 |
memmove(&p->yearly_expenses[1], &p->yearly_expenses[0], sizeof(p->yearly_expenses) - sizeof(p->yearly_expenses[0])); |
|
591 |
memset(&p->yearly_expenses[0], 0, sizeof(p->yearly_expenses[0])); |
|
592 |
InvalidateWindow(WC_FINANCES, p->index); |
|
593 |
} |
|
594 |
} |
|
595 |
||
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
596 |
if (_patches.show_finances && _local_player != PLAYER_SPECTATOR) { |
0 | 597 |
ShowPlayerFinances(_local_player); |
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1901
diff
changeset
|
598 |
p = GetPlayer(_local_player); |
0 | 599 |
if (p->num_valid_stat_ent > 5 && p->old_economy[0].performance_history < p->old_economy[4].performance_history) { |
541 | 600 |
SndPlayFx(SND_01_BAD_YEAR); |
0 | 601 |
} else { |
541 | 602 |
SndPlayFx(SND_00_GOOD_YEAR); |
0 | 603 |
} |
604 |
} |
|
605 |
} |
|
606 |
||
2544 | 607 |
static void DeletePlayerStuff(PlayerID pi) |
0 | 608 |
{ |
609 |
Player *p; |
|
610 |
||
611 |
DeletePlayerWindows(pi); |
|
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1901
diff
changeset
|
612 |
p = GetPlayer(pi); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
613 |
p->name_1 = STR_NULL; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
614 |
p->president_name_1 = STR_NULL; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
615 |
free(p->name); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
616 |
free(p->president_name); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
617 |
p->name = NULL; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
618 |
p->president_name = NULL; |
0 | 619 |
} |
620 |
||
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
621 |
/** Change engine renewal parameters |
3491
4c8427796c64
(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
|
622 |
* @param tile unused |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9598
diff
changeset
|
623 |
* @param flags operation to perform |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
624 |
* @param p1 bits 0-3 command |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
625 |
* - p1 = 0 - change auto renew bool |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
626 |
* - p1 = 1 - change auto renew months |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
627 |
* - p1 = 2 - change auto renew money |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
628 |
* - p1 = 3 - change auto renew array |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
629 |
* - p1 = 4 - change bool, months & money all together |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
630 |
* - p1 = 5 - change renew_keep_length |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
631 |
* @param p2 value to set |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
632 |
* if p1 = 0, then: |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
633 |
* - p2 = enable engine renewal |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
634 |
* if p1 = 1, then: |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
635 |
* - p2 = months left before engine expires to replace it |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
636 |
* if p1 = 2, then |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
637 |
* - p2 = minimum amount of money available |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
638 |
* if p1 = 3, then: |
9624 | 639 |
* - p1 bits 8-15 = engine group |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
640 |
* - p2 bits 0-15 = old engine type |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
641 |
* - p2 bits 16-31 = new engine type |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
642 |
* if p1 = 4, then: |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
643 |
* - p1 bit 15 = enable engine renewal |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
644 |
* - p1 bits 16-31 = months left before engine expires to replace it |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
645 |
* - p2 bits 0-31 = minimum amount of money available |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
646 |
* if p1 = 5, then |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
647 |
* - p2 = enable renew_keep_length |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
648 |
*/ |
9629 | 649 |
CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
650 |
{ |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
651 |
Player *p; |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4849
diff
changeset
|
652 |
if (!IsValidPlayer(_current_player)) return CMD_ERROR; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
653 |
|
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
654 |
p = GetPlayer(_current_player); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
655 |
switch (GB(p1, 0, 3)) { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
656 |
case 0: |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
657 |
if (p->engine_renew == HasBit(p2, 0)) |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
658 |
return CMD_ERROR; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
659 |
|
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
660 |
if (flags & DC_EXEC) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
661 |
p->engine_renew = HasBit(p2, 0); |
2425
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2395
diff
changeset
|
662 |
if (IsLocalPlayer()) { |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
663 |
_patches.autorenew = p->engine_renew; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
664 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
665 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
666 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
667 |
break; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
668 |
case 1: |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
669 |
if (p->engine_renew_months == (int16)p2) |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
670 |
return CMD_ERROR; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
671 |
|
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
672 |
if (flags & DC_EXEC) { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
673 |
p->engine_renew_months = (int16)p2; |
2425
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2395
diff
changeset
|
674 |
if (IsLocalPlayer()) { |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
675 |
_patches.autorenew_months = p->engine_renew_months; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
676 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
677 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
678 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
679 |
break; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
680 |
case 2: |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
681 |
if (p->engine_renew_money == (uint32)p2) |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
682 |
return CMD_ERROR; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
683 |
|
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
684 |
if (flags & DC_EXEC) { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
685 |
p->engine_renew_money = (uint32)p2; |
2425
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2395
diff
changeset
|
686 |
if (IsLocalPlayer()) { |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
687 |
_patches.autorenew_money = p->engine_renew_money; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
688 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
689 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
690 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
691 |
break; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
692 |
case 3: { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
693 |
EngineID old_engine_type = GB(p2, 0, 16); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
694 |
EngineID new_engine_type = GB(p2, 16, 16); |
9624 | 695 |
GroupID id_g = GB(p1, 16, 16); |
9629 | 696 |
CommandCost cost; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
697 |
|
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
698 |
if (!IsValidGroupID(id_g) && !IsAllGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
699 |
if (new_engine_type != INVALID_ENGINE) { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
700 |
/* First we make sure that it's a valid type the user requested |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
701 |
* check that it's an engine that is in the engine array */ |
2952 | 702 |
if (!IsEngineIndex(new_engine_type)) |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
703 |
return CMD_ERROR; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
704 |
|
9505 | 705 |
/* check that the new vehicle type is the same as the original one */ |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
706 |
if (GetEngine(old_engine_type)->type != GetEngine(new_engine_type)->type) |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
707 |
return CMD_ERROR; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
708 |
|
9505 | 709 |
/* make sure that we do not replace a plane with a helicopter or vise versa */ |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6573
diff
changeset
|
710 |
if (GetEngine(new_engine_type)->type == VEH_AIRCRAFT && |
4023
b65af90447d2
(svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents:
4000
diff
changeset
|
711 |
(AircraftVehInfo(old_engine_type)->subtype & AIR_CTOL) != (AircraftVehInfo(new_engine_type)->subtype & AIR_CTOL)) |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
712 |
return CMD_ERROR; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
713 |
|
9505 | 714 |
/* make sure that the player can actually buy the new engine */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
715 |
if (!HasBit(GetEngine(new_engine_type)->player_avail, _current_player)) |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
716 |
return CMD_ERROR; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
717 |
|
9624 | 718 |
cost = AddEngineReplacementForPlayer(p, old_engine_type, new_engine_type, id_g, flags); |
2697
c7b1a950c4cf
(svn r3239) - Codechange: Introduce and use helper functions for engine replacement code.
peter1138
parents:
2684
diff
changeset
|
719 |
} else { |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10188
diff
changeset
|
720 |
cost = RemoveEngineReplacementForPlayer(p, old_engine_type, id_g, flags); |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
721 |
} |
2811
a2f26f7361e3
(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
|
722 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
723 |
if (IsLocalPlayer()) InvalidateAutoreplaceWindow(old_engine_type, id_g); |
2811
a2f26f7361e3
(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
|
724 |
|
a2f26f7361e3
(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
|
725 |
return cost; |
2755
3098984d08c8
(svn r3300) Remove unreachable code - in this case some duplicate breaks
tron
parents:
2697
diff
changeset
|
726 |
} |
3098984d08c8
(svn r3300) Remove unreachable code - in this case some duplicate breaks
tron
parents:
2697
diff
changeset
|
727 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
728 |
case 4: |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
729 |
if (flags & DC_EXEC) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
730 |
p->engine_renew = HasBit(p1, 15); |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
731 |
p->engine_renew_months = (int16)GB(p1, 16, 16); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
732 |
p->engine_renew_money = (uint32)p2; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
733 |
|
2425
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2395
diff
changeset
|
734 |
if (IsLocalPlayer()) { |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
735 |
_patches.autorenew = p->engine_renew; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
736 |
_patches.autorenew_months = p->engine_renew_months; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
737 |
_patches.autorenew_money = p->engine_renew_money; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
738 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
739 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
740 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
741 |
break; |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
742 |
case 5: |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
743 |
if (p->renew_keep_length == HasBit(p2, 0)) |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
744 |
return CMD_ERROR; |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
745 |
|
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
746 |
if (flags & DC_EXEC) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
747 |
p->renew_keep_length = HasBit(p2, 0); |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
748 |
if (IsLocalPlayer()) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6573
diff
changeset
|
749 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_TRAIN); |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
750 |
} |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
751 |
} |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
752 |
break; |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
753 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
754 |
} |
9629 | 755 |
return CommandCost(); |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
756 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
757 |
|
1796
cae31916ae54
(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
|
758 |
/** Control the players: add, delete, etc. |
3491
4c8427796c64
(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
|
759 |
* @param tile unused |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9598
diff
changeset
|
760 |
* @param flags operation to perform |
1796
cae31916ae54
(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
|
761 |
* @param p1 various functionality |
cae31916ae54
(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
|
762 |
* - p1 = 0 - create a new player, Which player (network) it will be is in p2 |
cae31916ae54
(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
|
763 |
* - p1 = 1 - create a new AI player |
cae31916ae54
(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
|
764 |
* - p1 = 2 - delete a player. Player is identified by p2 |
cae31916ae54
(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
|
765 |
* - p1 = 3 - merge two companies together. Player to merge #1 with player #2. Identified by p2 |
cae31916ae54
(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
|
766 |
* @param p2 various functionality, dictated by p1 |
cae31916ae54
(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
|
767 |
* - p1 = 0 - ClientID of the newly created player |
cae31916ae54
(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
|
768 |
* - p1 = 2 - PlayerID of the that is getting deleted |
cae31916ae54
(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
|
769 |
* - p1 = 3 - #1 p2 = (bit 0-15) - player to merge (p2 & 0xFFFF) |
cae31916ae54
(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
|
770 |
* - #2 p2 = (bit 16-31) - player to be merged into ((p2>>16)&0xFFFF) |
cae31916ae54
(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
|
771 |
* @todo In the case of p1=0, create new player, the clientID of the new player is in parameter |
cae31916ae54
(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
|
772 |
* p2. This parameter is passed in at function DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) |
cae31916ae54
(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
|
773 |
* on the server itself. First of all this is unbelievably ugly; second of all, well, |
cae31916ae54
(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
|
774 |
* it IS ugly! <b>Someone fix this up :)</b> So where to fix?@n |
cae31916ae54
(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
|
775 |
* @arg - network_server.c:838 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)@n |
cae31916ae54
(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
|
776 |
* @arg - network_client.c:536 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) from where the map has been received |
cae31916ae54
(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
|
777 |
*/ |
9629 | 778 |
CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 779 |
{ |
1796
cae31916ae54
(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
|
780 |
if (flags & DC_EXEC) _current_player = OWNER_NONE; |
0 | 781 |
|
1796
cae31916ae54
(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
|
782 |
switch (p1) { |
cae31916ae54
(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
|
783 |
case 0: { /* Create a new player */ |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
784 |
/* Joining Client: |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
785 |
* _local_player: PLAYER_SPECTATOR |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
786 |
* _network_playas/cid = requested company/player |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
787 |
* |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
788 |
* Other client(s)/server: |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
789 |
* _local_player/_network_playas: what they play as |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
790 |
* cid = requested company/player of joining client */ |
1796
cae31916ae54
(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
|
791 |
Player *p; |
5943
9acc30eb83cd
(svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents:
5919
diff
changeset
|
792 |
#ifdef ENABLE_NETWORK |
4858
91f058409592
(svn r6784) -Codechange: Change invalid PlayerID type into ClientID which it is in CmdPlayerCtrl
Darkvater
parents:
4854
diff
changeset
|
793 |
uint16 cid = p2; // ClientID |
5943
9acc30eb83cd
(svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents:
5919
diff
changeset
|
794 |
#endif /* ENABLE_NETWORK */ |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
795 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
796 |
/* This command is only executed in a multiplayer game */ |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
797 |
if (!_networking) return CMD_ERROR; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
798 |
|
5563
d17a2d8cd77c
(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
|
799 |
/* Has the network client a correct ClientID? */ |
9629 | 800 |
if (!(flags & DC_EXEC)) return CommandCost(); |
5692
b83442e14fd4
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5564
diff
changeset
|
801 |
#ifdef ENABLE_NETWORK |
9629 | 802 |
if (cid >= MAX_CLIENT_INFO) return CommandCost(); |
5692
b83442e14fd4
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5564
diff
changeset
|
803 |
#endif /* ENABLE_NETWORK */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
804 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
805 |
/* Delete multiplayer progress bar */ |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
806 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
807 |
|
0 | 808 |
p = DoStartupNewPlayer(false); |
670
7c58dc46609c
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
809 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
810 |
/* A new player could not be created, revert to being a spectator */ |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
811 |
if (p == NULL) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
812 |
#ifdef ENABLE_NETWORK |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
813 |
if (_network_server) { |
4858
91f058409592
(svn r6784) -Codechange: Change invalid PlayerID type into ClientID which it is in CmdPlayerCtrl
Darkvater
parents:
4854
diff
changeset
|
814 |
NetworkClientInfo *ci = &_network_client_info[cid]; |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
815 |
ci->client_playas = PLAYER_SPECTATOR; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
816 |
NetworkUpdateClientInfo(ci->client_index); |
9629 | 817 |
} else if (_local_player == PLAYER_SPECTATOR) { |
818 |
_network_playas = PLAYER_SPECTATOR; |
|
819 |
} |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
820 |
#endif /* ENABLE_NETWORK */ |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
821 |
break; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
822 |
} |
690
9f449a6b133e
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
688
diff
changeset
|
823 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
824 |
/* This is the joining client who wants a new company */ |
9574 | 825 |
if (_local_player != _network_playas && _network_playas == p->index) { |
826 |
assert(_local_player == PLAYER_SPECTATOR); |
|
5564
6e1b3ea1ba7f
(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:
5563
diff
changeset
|
827 |
SetLocalPlayer(p->index); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
828 |
#ifdef ENABLE_NETWORK |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
829 |
if (!StrEmpty(_network_default_company_pass)) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
830 |
char *password = _network_default_company_pass; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
831 |
NetworkChangeCompanyPassword(1, &password); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
832 |
} |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
833 |
#endif /* ENABLE_NETWORK */ |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
834 |
MarkWholeScreenDirty(); |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
835 |
} |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
836 |
|
5073
7983f98f3d4c
(svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents:
5068
diff
changeset
|
837 |
/* Now that we have a new player, broadcast its autorenew settings to |
7983f98f3d4c
(svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents:
5068
diff
changeset
|
838 |
* all clients so everything is in sync */ |
7983f98f3d4c
(svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents:
5068
diff
changeset
|
839 |
DoCommand(0, |
7983f98f3d4c
(svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents:
5068
diff
changeset
|
840 |
(_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, |
7983f98f3d4c
(svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents:
5068
diff
changeset
|
841 |
_patches.autorenew_money, |
7983f98f3d4c
(svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents:
5068
diff
changeset
|
842 |
DC_EXEC, |
7983f98f3d4c
(svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents:
5068
diff
changeset
|
843 |
CMD_SET_AUTOREPLACE |
7983f98f3d4c
(svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents:
5068
diff
changeset
|
844 |
); |
7983f98f3d4c
(svn r7131) -Fix (r7126) which fixes (r2817) the activating of a function call that was
Darkvater
parents:
5068
diff
changeset
|
845 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
846 |
#ifdef ENABLE_NETWORK |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
847 |
if (_network_server) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
848 |
/* XXX - UGLY! p2 (pid) is mis-used to fetch the client-id, done at |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
849 |
* server-side in network_server.c:838, function |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
850 |
* DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) */ |
4858
91f058409592
(svn r6784) -Codechange: Change invalid PlayerID type into ClientID which it is in CmdPlayerCtrl
Darkvater
parents:
4854
diff
changeset
|
851 |
NetworkClientInfo *ci = &_network_client_info[cid]; |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
852 |
ci->client_playas = p->index; |
1796
cae31916ae54
(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
|
853 |
NetworkUpdateClientInfo(ci->client_index); |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
854 |
|
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
855 |
if (IsValidPlayer(ci->client_playas)) { |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
856 |
PlayerID player_backup = _local_player; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
857 |
_network_player_info[p->index].months_empty = 0; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
858 |
|
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
859 |
/* XXX - When a client joins, we automatically set its name to the |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
860 |
* player's name (for some reason). As it stands now only the server |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
861 |
* knows the client's name, so it needs to send out a "broadcast" to |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
862 |
* do this. To achieve this we send a network command. However, it |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
863 |
* uses _local_player to execute the command as. To prevent abuse |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
864 |
* (eg. only yourself can change your name/company), we 'cheat' by |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
865 |
* impersonation _local_player as the server. Not the best solution; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
866 |
* but it works. |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
867 |
* TODO: Perhaps this could be improved by when the client is ready |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
868 |
* with joining to let it send itself the command, and not the server? |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
869 |
* For example in network_client.c:534? */ |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
870 |
_cmd_text = ci->client_name; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
871 |
_local_player = ci->client_playas; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
872 |
NetworkSend_Command(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME, NULL); |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
873 |
_local_player = player_backup; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
874 |
} |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
875 |
} |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
876 |
#endif /* ENABLE_NETWORK */ |
1796
cae31916ae54
(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
|
877 |
} break; |
cae31916ae54
(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
|
878 |
|
cae31916ae54
(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
|
879 |
case 1: /* Make a new AI player */ |
9629 | 880 |
if (!(flags & DC_EXEC)) return CommandCost(); |
1796
cae31916ae54
(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
|
881 |
|
0 | 882 |
DoStartupNewPlayer(true); |
883 |
break; |
|
1796
cae31916ae54
(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
|
884 |
|
cae31916ae54
(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
|
885 |
case 2: { /* Delete a player */ |
cae31916ae54
(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
|
886 |
Player *p; |
cae31916ae54
(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
|
887 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
888 |
if (!IsValidPlayer((PlayerID)p2)) return CMD_ERROR; |
1796
cae31916ae54
(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
|
889 |
|
9629 | 890 |
if (!(flags & DC_EXEC)) return CommandCost(); |
1796
cae31916ae54
(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
|
891 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
892 |
p = GetPlayer((PlayerID)p2); |
688
bcaa5256253d
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
893 |
|
10188
13e73691378a
(svn r12719) [NoAI] -Add: finished the Reload AI button in AIDebug Window.
truebrain
parents:
9837
diff
changeset
|
894 |
/* Delete any open window of the company */ |
13e73691378a
(svn r12719) [NoAI] -Add: finished the Reload AI button in AIDebug Window.
truebrain
parents:
9837
diff
changeset
|
895 |
DeletePlayerWindows(p->index); |
688
bcaa5256253d
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
896 |
|
10188
13e73691378a
(svn r12719) [NoAI] -Add: finished the Reload AI button in AIDebug Window.
truebrain
parents:
9837
diff
changeset
|
897 |
/* Show the bankrupt news */ |
13e73691378a
(svn r12719) [NoAI] -Add: finished the Reload AI button in AIDebug Window.
truebrain
parents:
9837
diff
changeset
|
898 |
SetDParam(0, p->index); |
13e73691378a
(svn r12719) [NoAI] -Add: finished the Reload AI button in AIDebug Window.
truebrain
parents:
9837
diff
changeset
|
899 |
AddNewsItem((StringID)(p->index | NB_BBANKRUPT), NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, 0); |
688
bcaa5256253d
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
900 |
|
10188
13e73691378a
(svn r12719) [NoAI] -Add: finished the Reload AI button in AIDebug Window.
truebrain
parents:
9837
diff
changeset
|
901 |
/* Remove the company */ |
13e73691378a
(svn r12719) [NoAI] -Add: finished the Reload AI button in AIDebug Window.
truebrain
parents:
9837
diff
changeset
|
902 |
ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR); |
13e73691378a
(svn r12719) [NoAI] -Add: finished the Reload AI button in AIDebug Window.
truebrain
parents:
9837
diff
changeset
|
903 |
p->is_active = false; |
13e73691378a
(svn r12719) [NoAI] -Add: finished the Reload AI button in AIDebug Window.
truebrain
parents:
9837
diff
changeset
|
904 |
if (!IsHumanPlayer(p->index)) AI_PlayerDied(p->index); |
13e73691378a
(svn r12719) [NoAI] -Add: finished the Reload AI button in AIDebug Window.
truebrain
parents:
9837
diff
changeset
|
905 |
|
2848 | 906 |
RemoveAllEngineReplacementForPlayer(p); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
907 |
RemoveAllGroupsForPlayer(p->index); |
2848 | 908 |
|
1796
cae31916ae54
(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
|
909 |
} break; |
0 | 910 |
|
1796
cae31916ae54
(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
|
911 |
case 3: { /* Merge a company (#1) into another company (#2), elimination company #1 */ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
912 |
PlayerID pid_old = (PlayerID)GB(p2, 0, 16); |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
913 |
PlayerID pid_new = (PlayerID)GB(p2, 16, 16); |
1796
cae31916ae54
(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
|
914 |
|
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4849
diff
changeset
|
915 |
if (!IsValidPlayer(pid_old) || !IsValidPlayer(pid_new)) return CMD_ERROR; |
1796
cae31916ae54
(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
|
916 |
|
cae31916ae54
(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
|
917 |
if (!(flags & DC_EXEC)) return CMD_ERROR; |
cae31916ae54
(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
|
918 |
|
cae31916ae54
(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
|
919 |
ChangeOwnershipOfPlayerItems(pid_old, pid_new); |
cae31916ae54
(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
|
920 |
DeletePlayerStuff(pid_old); |
cae31916ae54
(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
|
921 |
} break; |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
922 |
|
1796
cae31916ae54
(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
|
923 |
default: return CMD_ERROR; |
0 | 924 |
} |
925 |
||
9629 | 926 |
return CommandCost(); |
0 | 927 |
} |
928 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
929 |
static const StringID _endgame_perf_titles[] = { |
983
1be852dcdd4c
(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
|
930 |
STR_0213_BUSINESSMAN, |
1be852dcdd4c
(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
|
931 |
STR_0213_BUSINESSMAN, |
1be852dcdd4c
(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
|
932 |
STR_0213_BUSINESSMAN, |
1be852dcdd4c
(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
|
933 |
STR_0213_BUSINESSMAN, |
1be852dcdd4c
(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
|
934 |
STR_0213_BUSINESSMAN, |
1be852dcdd4c
(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
|
935 |
STR_0214_ENTREPRENEUR, |
1be852dcdd4c
(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
|
936 |
STR_0214_ENTREPRENEUR, |
1be852dcdd4c
(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
|
937 |
STR_0215_INDUSTRIALIST, |
1be852dcdd4c
(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
|
938 |
STR_0215_INDUSTRIALIST, |
1be852dcdd4c
(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
|
939 |
STR_0216_CAPITALIST, |
1be852dcdd4c
(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
|
940 |
STR_0216_CAPITALIST, |
1be852dcdd4c
(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
|
941 |
STR_0217_MAGNATE, |
1be852dcdd4c
(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
|
942 |
STR_0217_MAGNATE, |
1be852dcdd4c
(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
|
943 |
STR_0218_MOGUL, |
1be852dcdd4c
(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
|
944 |
STR_0218_MOGUL, |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
945 |
STR_0219_TYCOON_OF_THE_CENTURY |
983
1be852dcdd4c
(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
|
946 |
}; |
1be852dcdd4c
(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
|
947 |
|
1016
026b2de61647
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
948 |
StringID EndGameGetPerformanceTitleFromValue(uint value) |
983
1be852dcdd4c
(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
|
949 |
{ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
950 |
value = minu(value / 64, lengthof(_endgame_perf_titles) - 1); |
2613
b008d366ed8a
(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
|
951 |
|
b008d366ed8a
(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
|
952 |
return _endgame_perf_titles[value]; |
983
1be852dcdd4c
(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
|
953 |
} |
1be852dcdd4c
(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
|
954 |
|
9505 | 955 |
/** Save the highscore for the player */ |
998
d9dc257b8949
(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
|
956 |
int8 SaveHighScoreValue(const Player *p) |
983
1be852dcdd4c
(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
|
957 |
{ |
1be852dcdd4c
(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
|
958 |
HighScore *hs = _highscore_table[_opt.diff_level]; |
1be852dcdd4c
(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
|
959 |
uint i; |
1be852dcdd4c
(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
|
960 |
uint16 score = p->old_economy[0].performance_history; |
1be852dcdd4c
(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
|
961 |
|
1016
026b2de61647
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
962 |
/* Exclude cheaters from the honour of being in the highscore table */ |
4000
bab1ebc37da0
(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
|
963 |
if (CheatHasBeenUsed()) return -1; |
1016
026b2de61647
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
964 |
|
983
1be852dcdd4c
(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
|
965 |
for (i = 0; i < lengthof(_highscore_table[0]); i++) { |
1be852dcdd4c
(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
|
966 |
/* You are in the TOP5. Move all values one down and save us there */ |
1be852dcdd4c
(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
|
967 |
if (hs[i].score <= score) { |
9505 | 968 |
/* move all elements one down starting from the replaced one */ |
983
1be852dcdd4c
(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
|
969 |
memmove(&hs[i + 1], &hs[i], sizeof(HighScore) * (lengthof(_highscore_table[0]) - i - 1)); |
9629 | 970 |
SetDParam(0, p->index); |
971 |
SetDParam(1, p->index); |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4878
diff
changeset
|
972 |
GetString(hs[i].company, STR_HIGHSCORE_NAME, lastof(hs[i].company)); // get manager/company name string |
983
1be852dcdd4c
(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
|
973 |
hs[i].score = score; |
1be852dcdd4c
(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
|
974 |
hs[i].title = EndGameGetPerformanceTitleFromValue(score); |
1be852dcdd4c
(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
|
975 |
return i; |
1be852dcdd4c
(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
|
976 |
} |
1be852dcdd4c
(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
|
977 |
} |
1be852dcdd4c
(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
|
978 |
|
1be852dcdd4c
(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
|
979 |
return -1; // too bad; we did not make it into the top5 |
1be852dcdd4c
(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
|
980 |
} |
1be852dcdd4c
(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
|
981 |
|
9505 | 982 |
/** Sort all players given their performance */ |
998
d9dc257b8949
(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
|
983 |
static int CDECL HighScoreSorter(const void *a, const void *b) |
d9dc257b8949
(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
|
984 |
{ |
d9dc257b8949
(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
|
985 |
const Player *pa = *(const Player* const*)a; |
d9dc257b8949
(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
|
986 |
const Player *pb = *(const Player* const*)b; |
d9dc257b8949
(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
|
987 |
|
d9dc257b8949
(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
|
988 |
return pb->old_economy[0].performance_history - pa->old_economy[0].performance_history; |
d9dc257b8949
(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
|
989 |
} |
d9dc257b8949
(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
|
990 |
|
d9dc257b8949
(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
|
991 |
/* Save the highscores in a network game when it has ended */ |
d9dc257b8949
(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
|
992 |
#define LAST_HS_ITEM lengthof(_highscore_table) - 1 |
6573 | 993 |
int8 SaveHighScoreValueNetwork() |
998
d9dc257b8949
(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
|
994 |
{ |
2988
032feb8d9d8a
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
995 |
const Player* p; |
032feb8d9d8a
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
996 |
const Player* pl[MAX_PLAYERS]; |
998
d9dc257b8949
(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
|
997 |
size_t count = 0; |
d9dc257b8949
(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
|
998 |
int8 player = -1; |
d9dc257b8949
(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
|
999 |
|
d9dc257b8949
(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
|
1000 |
/* Sort all active players with the highest score first */ |
2988
032feb8d9d8a
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
1001 |
FOR_ALL_PLAYERS(p) if (p->is_active) pl[count++] = p; |
2992
d3248a561d0d
(svn r3568) - Fix: constantizing side-effect of qsort in r3563. Ugly? Yes. Makes MSVC happy? Yes.
Darkvater
parents:
2990
diff
changeset
|
1002 |
qsort((Player*)pl, count, sizeof(pl[0]), HighScoreSorter); |
998
d9dc257b8949
(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
|
1003 |
|
d9dc257b8949
(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
|
1004 |
{ |
2988
032feb8d9d8a
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
1005 |
uint i; |
998
d9dc257b8949
(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
|
1006 |
|
d9dc257b8949
(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
|
1007 |
memset(_highscore_table[LAST_HS_ITEM], 0, sizeof(_highscore_table[0])); |
d9dc257b8949
(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
|
1008 |
|
d9dc257b8949
(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
|
1009 |
/* Copy over Top5 companies */ |
2484
8e0c88a833fb
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2475
diff
changeset
|
1010 |
for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < count; i++) { |
2988
032feb8d9d8a
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
1011 |
HighScore* hs = &_highscore_table[LAST_HS_ITEM][i]; |
032feb8d9d8a
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
1012 |
|
9629 | 1013 |
SetDParam(0, pl[i]->index); |
1014 |
SetDParam(1, pl[i]->index); |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4878
diff
changeset
|
1015 |
GetString(hs->company, STR_HIGHSCORE_NAME, lastof(hs->company)); // get manager/company name string |
2988
032feb8d9d8a
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
1016 |
hs->score = pl[i]->old_economy[0].performance_history; |
998
d9dc257b8949
(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
|
1017 |
hs->title = EndGameGetPerformanceTitleFromValue(hs->score); |
d9dc257b8949
(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
|
1018 |
|
9505 | 1019 |
/* get the ranking of the local player */ |
2988
032feb8d9d8a
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
1020 |
if (pl[i]->index == _local_player) player = i; |
998
d9dc257b8949
(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 |
} |
d9dc257b8949
(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
|
1022 |
} |
d9dc257b8949
(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
|
1023 |
|
d9dc257b8949
(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
|
1024 |
/* Add top5 players to highscore table */ |
d9dc257b8949
(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
|
1025 |
return player; |
d9dc257b8949
(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
|
1026 |
} |
d9dc257b8949
(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
|
1027 |
|
9505 | 1028 |
/** Save HighScore table to file */ |
6573 | 1029 |
void SaveToHighScore() |
983
1be852dcdd4c
(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 |
{ |
2613
b008d366ed8a
(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
|
1031 |
FILE *fp = fopen(_highscore_file, "wb"); |
983
1be852dcdd4c
(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 |
|
1be852dcdd4c
(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 |
if (fp != NULL) { |
1be852dcdd4c
(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 |
uint i; |
1be852dcdd4c
(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 |
HighScore *hs; |
1be852dcdd4c
(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 |
|
998
d9dc257b8949
(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
|
1037 |
for (i = 0; i < LAST_HS_ITEM; i++) { // don't save network highscores |
983
1be852dcdd4c
(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
|
1038 |
for (hs = _highscore_table[i]; hs != endof(_highscore_table[i]); hs++) { |
1be852dcdd4c
(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
|
1039 |
/* First character is a command character, so strlen will fail on that */ |
4321
b763b7007162
(svn r5974) -Codechange: added casts all around the place to make Windows 64bit happy (michi_cc)
truelight
parents:
4293
diff
changeset
|
1040 |
byte length = min(sizeof(hs->company), (hs->company[0] == '\0') ? 0 : (int)strlen(&hs->company[1]) + 1); |
983
1be852dcdd4c
(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 |
|
1be852dcdd4c
(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 |
fwrite(&length, sizeof(length), 1, fp); // write away string length |
1be852dcdd4c
(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 |
fwrite(hs->company, length, 1, fp); |
1be852dcdd4c
(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 |
fwrite(&hs->score, sizeof(hs->score), 1, fp); |
9505 | 1045 |
fwrite("", 2, 1, fp); // XXX - placeholder for hs->title, not saved anymore; compatibility |
983
1be852dcdd4c
(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 |
} |
1be852dcdd4c
(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 |
} |
1be852dcdd4c
(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 |
fclose(fp); |
1be852dcdd4c
(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
|
1049 |
} |
1be852dcdd4c
(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
|
1050 |
} |
1be852dcdd4c
(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
|
1051 |
|
9505 | 1052 |
/** Initialize the highscore table to 0 and if any file exists, load in values */ |
6573 | 1053 |
void LoadFromHighScore() |
983
1be852dcdd4c
(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
|
1054 |
{ |
2613
b008d366ed8a
(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
|
1055 |
FILE *fp = fopen(_highscore_file, "rb"); |
983
1be852dcdd4c
(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
|
1056 |
|
1be852dcdd4c
(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
|
1057 |
memset(_highscore_table, 0, sizeof(_highscore_table)); |
1be852dcdd4c
(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
|
1058 |
|
1be852dcdd4c
(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
|
1059 |
if (fp != NULL) { |
1be852dcdd4c
(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
|
1060 |
uint i; |
1be852dcdd4c
(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
|
1061 |
HighScore *hs; |
1be852dcdd4c
(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
|
1062 |
|
998
d9dc257b8949
(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
|
1063 |
for (i = 0; i < LAST_HS_ITEM; i++) { // don't load network highscores |
983
1be852dcdd4c
(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
|
1064 |
for (hs = _highscore_table[i]; hs != endof(_highscore_table[i]); hs++) { |
1be852dcdd4c
(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
|
1065 |
byte length; |
1be852dcdd4c
(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
|
1066 |
fread(&length, sizeof(length), 1, fp); |
1be852dcdd4c
(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
|
1067 |
|
1be852dcdd4c
(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
|
1068 |
fread(hs->company, 1, length, fp); |
1be852dcdd4c
(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
|
1069 |
fread(&hs->score, sizeof(hs->score), 1, fp); |
9505 | 1070 |
fseek(fp, 2, SEEK_CUR); // XXX - placeholder for hs->title, not saved anymore; compatibility |
2613
b008d366ed8a
(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
|
1071 |
hs->title = EndGameGetPerformanceTitleFromValue(hs->score); |
983
1be852dcdd4c
(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
|
1072 |
} |
1be852dcdd4c
(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
|
1073 |
} |
1be852dcdd4c
(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
|
1074 |
fclose(fp); |
1be852dcdd4c
(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
|
1075 |
} |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1017
diff
changeset
|
1076 |
|
998
d9dc257b8949
(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
|
1077 |
/* Initialize end of game variable (when to show highscore chart) */ |
4285
72b3f7d6c891
(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
|
1078 |
_patches.ending_year = 2051; |
983
1be852dcdd4c
(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
|
1079 |
} |
1be852dcdd4c
(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
|
1080 |
|
9505 | 1081 |
/* Save/load of players */ |
1881
023a134a4b12
(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
|
1082 |
static const SaveLoad _player_desc[] = { |
4344
5d0e40cd67b9
(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
|
1083 |
SLE_VAR(Player, name_2, SLE_UINT32), |
5d0e40cd67b9
(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
|
1084 |
SLE_VAR(Player, name_1, SLE_STRINGID), |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1085 |
SLE_CONDSTR(Player, name, SLE_STR, 0, 84, SL_MAX_VERSION), |
0 | 1086 |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10188
diff
changeset
|
1087 |
SLE_VAR(Player, president_name_1, SLE_UINT16), |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10188
diff
changeset
|
1088 |
SLE_VAR(Player, president_name_2, SLE_UINT32), |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1089 |
SLE_CONDSTR(Player, president_name, SLE_STR, 0, 84, SL_MAX_VERSION), |
0 | 1090 |
|
4344
5d0e40cd67b9
(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
|
1091 |
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
|
1092 |
|
9505 | 1093 |
/* money was changed to a 64 bit field in savegame version 1. */ |
9629 | 1094 |
SLE_CONDVAR(Player, player_money, SLE_VAR_I64 | SLE_FILE_I32, 0, 0), |
1095 |
SLE_CONDVAR(Player, player_money, SLE_INT64, 1, SL_MAX_VERSION), |
|
0 | 1096 |
|
9629 | 1097 |
SLE_CONDVAR(Player, current_loan, SLE_VAR_I64 | SLE_FILE_I32, 0, 64), |
1098 |
SLE_CONDVAR(Player, current_loan, SLE_INT64, 65, SL_MAX_VERSION), |
|
0 | 1099 |
|
4344
5d0e40cd67b9
(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
|
1100 |
SLE_VAR(Player, player_color, SLE_UINT8), |
5d0e40cd67b9
(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
|
1101 |
SLE_VAR(Player, player_money_fraction, SLE_UINT8), |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1102 |
SLE_CONDVAR(Player, avail_railtypes, SLE_UINT8, 0, 57), |
4344
5d0e40cd67b9
(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
|
1103 |
SLE_VAR(Player, block_preview, SLE_UINT8), |
0 | 1104 |
|
4344
5d0e40cd67b9
(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
|
1105 |
SLE_VAR(Player, cargo_types, SLE_UINT16), |
5d0e40cd67b9
(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
|
1106 |
SLE_CONDVAR(Player, location_of_house, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(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
|
1107 |
SLE_CONDVAR(Player, location_of_house, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(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
|
1108 |
SLE_CONDVAR(Player, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(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
|
1109 |
SLE_CONDVAR(Player, last_build_coordinate, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(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
|
1110 |
SLE_CONDVAR(Player, inaugurated_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(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
|
1111 |
SLE_CONDVAR(Player, inaugurated_year, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(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
|
1112 |
|
5d0e40cd67b9
(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
|
1113 |
SLE_ARR(Player, share_owners, SLE_UINT8, 4), |
5d0e40cd67b9
(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
|
1114 |
|
5d0e40cd67b9
(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
|
1115 |
SLE_VAR(Player, num_valid_stat_ent, SLE_UINT8), |
5d0e40cd67b9
(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
|
1116 |
|
5d0e40cd67b9
(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
|
1117 |
SLE_VAR(Player, quarters_of_bankrupcy, SLE_UINT8), |
5d0e40cd67b9
(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
|
1118 |
SLE_VAR(Player, bankrupt_asked, SLE_UINT8), |
5d0e40cd67b9
(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
|
1119 |
SLE_VAR(Player, bankrupt_timeout, SLE_INT16), |
9629 | 1120 |
SLE_CONDVAR(Player, bankrupt_value, SLE_VAR_I64 | SLE_FILE_I32, 0, 64), |
1121 |
SLE_CONDVAR(Player, bankrupt_value, SLE_INT64, 65, SL_MAX_VERSION), |
|
0 | 1122 |
|
9505 | 1123 |
/* yearly expenses was changed to 64-bit in savegame version 2. */ |
4344
5d0e40cd67b9
(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
|
1124 |
SLE_CONDARR(Player, yearly_expenses, SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, 0, 1), |
5d0e40cd67b9
(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
|
1125 |
SLE_CONDARR(Player, yearly_expenses, SLE_INT64, 3 * 13, 2, SL_MAX_VERSION), |
0 | 1126 |
|
4344
5d0e40cd67b9
(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
|
1127 |
SLE_CONDVAR(Player, is_ai, SLE_BOOL, 2, SL_MAX_VERSION), |
5d0e40cd67b9
(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
|
1128 |
SLE_CONDVAR(Player, is_active, SLE_BOOL, 4, SL_MAX_VERSION), |
0 | 1129 |
|
9505 | 1130 |
/* Engine renewal settings */ |
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3047
diff
changeset
|
1131 |
SLE_CONDNULL(512, 16, 18), |
4344
5d0e40cd67b9
(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
|
1132 |
SLE_CONDREF(Player, engine_renew_list, REF_ENGINE_RENEWS, 19, SL_MAX_VERSION), |
5d0e40cd67b9
(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
|
1133 |
SLE_CONDVAR(Player, engine_renew, SLE_BOOL, 16, SL_MAX_VERSION), |
5d0e40cd67b9
(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
|
1134 |
SLE_CONDVAR(Player, engine_renew_months, SLE_INT16, 16, SL_MAX_VERSION), |
5d0e40cd67b9
(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
|
1135 |
SLE_CONDVAR(Player, engine_renew_money, SLE_UINT32, 16, SL_MAX_VERSION), |
5d0e40cd67b9
(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
|
1136 |
SLE_CONDVAR(Player, renew_keep_length, SLE_BOOL, 2, SL_MAX_VERSION), // added with 16.1, but was blank since 2 |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
1137 |
|
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1138 |
/* Reserve extra space in savegame here. (currently 62 bytes) |
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1139 |
* The 63rd byte is used to tell us whether we are a player of the NoAI-branch or not. |
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1140 |
* Part of the NoAI 'hack' to retain savegame compatability with trunk. */ |
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1141 |
SLE_CONDVAR(Player, is_noai, SLE_BOOL, 2, SL_NOAI_MAX_VERSION), |
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1142 |
SLE_CONDNULL(62, 2, SL_MAX_VERSION), |
0 | 1143 |
|
1144 |
SLE_END() |
|
1145 |
}; |
|
1146 |
||
1881
023a134a4b12
(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
|
1147 |
static const SaveLoad _player_economy_desc[] = { |
9505 | 1148 |
/* these were changed to 64-bit in savegame format 2 */ |
9629 | 1149 |
SLE_CONDVAR(PlayerEconomyEntry, income, SLE_FILE_I32 | SLE_VAR_I64, 0, 1), |
1150 |
SLE_CONDVAR(PlayerEconomyEntry, income, SLE_INT64, 2, SL_MAX_VERSION), |
|
1151 |
SLE_CONDVAR(PlayerEconomyEntry, expenses, SLE_FILE_I32 | SLE_VAR_I64, 0, 1), |
|
1152 |
SLE_CONDVAR(PlayerEconomyEntry, expenses, SLE_INT64, 2, SL_MAX_VERSION), |
|
4344
5d0e40cd67b9
(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_CONDVAR(PlayerEconomyEntry, company_value, SLE_FILE_I32 | SLE_VAR_I64, 0, 1), |
5d0e40cd67b9
(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
|
1154 |
SLE_CONDVAR(PlayerEconomyEntry, company_value, SLE_INT64, 2, SL_MAX_VERSION), |
0 | 1155 |
|
4344
5d0e40cd67b9
(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(PlayerEconomyEntry, delivered_cargo, SLE_INT32), |
5d0e40cd67b9
(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
|
1157 |
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
|
1158 |
|
0 | 1159 |
SLE_END() |
1160 |
}; |
|
1161 |
||
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1162 |
/* We do need to read this single value, as the bigger it gets, the more data is stored */ |
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1163 |
struct PlayerOldAI { |
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1164 |
uint8 num_build_rec; |
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1165 |
}; |
0 | 1166 |
|
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1167 |
static const SaveLoad _player_ai_desc[] = { |
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1168 |
SLE_CONDNULL(2, 0, SL_NOAI_MAX_VERSION), |
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1169 |
SLE_CONDNULL(2, 0, 12), |
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1170 |
SLE_CONDNULL(4, 13, SL_NOAI_MAX_VERSION), |
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1171 |
SLE_CONDNULL(8, 0, SL_NOAI_MAX_VERSION), |
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1172 |
SLE_CONDVAR(PlayerOldAI, num_build_rec, SLE_UINT8, 0, SL_NOAI_MAX_VERSION), |
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1173 |
SLE_CONDNULL(3, 0, SL_NOAI_MAX_VERSION), |
4344
5d0e40cd67b9
(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 |
|
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1175 |
SLE_CONDNULL(2, 0, 5), |
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1176 |
SLE_CONDNULL(4, 6, SL_NOAI_MAX_VERSION), |
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1177 |
SLE_CONDNULL(2, 0, 5), |
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1178 |
SLE_CONDNULL(4, 6, SL_NOAI_MAX_VERSION), |
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1179 |
SLE_CONDNULL(2, 0, SL_NOAI_MAX_VERSION), |
4344
5d0e40cd67b9
(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 |
|
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1181 |
SLE_CONDNULL(2, 0, 5), |
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1182 |
SLE_CONDNULL(4, 6, SL_NOAI_MAX_VERSION), |
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1183 |
SLE_CONDNULL(2, 0, 5), |
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1184 |
SLE_CONDNULL(4, 6, SL_NOAI_MAX_VERSION), |
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1185 |
SLE_CONDNULL(2, 0, SL_NOAI_MAX_VERSION), |
4344
5d0e40cd67b9
(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 |
|
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1187 |
SLE_CONDNULL(2, 0, SL_NOAI_MAX_VERSION), |
0 | 1188 |
|
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1189 |
SLE_CONDNULL(18, 0, SL_NOAI_MAX_VERSION), |
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1190 |
SLE_CONDNULL(20, 0, SL_NOAI_MAX_VERSION), |
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1191 |
SLE_CONDNULL(32, 0, SL_NOAI_MAX_VERSION), |
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1192 |
|
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1193 |
SLE_CONDNULL(64, 2, SL_NOAI_MAX_VERSION), |
0 | 1194 |
SLE_END() |
1195 |
}; |
|
1196 |
||
1881
023a134a4b12
(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
|
1197 |
static const SaveLoad _player_ai_build_rec_desc[] = { |
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1198 |
SLE_CONDNULL(2, 0, 5), |
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1199 |
SLE_CONDNULL(4, 6, SL_NOAI_MAX_VERSION), |
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1200 |
SLE_CONDNULL(2, 0, 5), |
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1201 |
SLE_CONDNULL(4, 6, SL_NOAI_MAX_VERSION), |
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1202 |
SLE_CONDNULL(8, 0, SL_NOAI_MAX_VERSION), |
0 | 1203 |
SLE_END() |
1204 |
}; |
|
1205 |
||
4603
3ccd4ee0a2e2
(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
|
1206 |
static const SaveLoad _player_livery_desc[] = { |
3ccd4ee0a2e2
(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
|
1207 |
SLE_CONDVAR(Livery, in_use, SLE_BOOL, 34, SL_MAX_VERSION), |
3ccd4ee0a2e2
(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
|
1208 |
SLE_CONDVAR(Livery, colour1, SLE_UINT8, 34, SL_MAX_VERSION), |
3ccd4ee0a2e2
(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
|
1209 |
SLE_CONDVAR(Livery, colour2, SLE_UINT8, 34, SL_MAX_VERSION), |
3ccd4ee0a2e2
(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
|
1210 |
SLE_END() |
3ccd4ee0a2e2
(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
|
1211 |
}; |
3ccd4ee0a2e2
(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
|
1212 |
|
2952 | 1213 |
static void SaveLoad_PLYR(Player* p) |
1214 |
{ |
|
0 | 1215 |
int i; |
1216 |
||
1217 |
SlObject(p, _player_desc); |
|
1218 |
||
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1219 |
/* Keep backwards compatible for savegames, so load the old AI block */ |
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1220 |
if (!IsHumanPlayer(p->index) && !p->is_noai) { |
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1221 |
PlayerOldAI old_ai; |
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1222 |
char nothing; |
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1223 |
|
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1224 |
SlObject(&old_ai, _player_ai_desc); |
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1225 |
for (i = 0; i != old_ai.num_build_rec; i++) { |
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
1226 |
SlObject(¬hing, _player_ai_build_rec_desc); |
4000
bab1ebc37da0
(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
|
1227 |
} |
0 | 1228 |
} |
1229 |
||
9505 | 1230 |
/* Write economy */ |
0 | 1231 |
SlObject(&p->cur_economy, _player_economy_desc); |
1232 |
||
9505 | 1233 |
/* Write old economy entries. */ |
2988
032feb8d9d8a
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
1234 |
for (i = 0; i < p->num_valid_stat_ent; i++) { |
032feb8d9d8a
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
1235 |
SlObject(&p->old_economy[i], _player_economy_desc); |
0 | 1236 |
} |
4603
3ccd4ee0a2e2
(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
|
1237 |
|
9505 | 1238 |
/* Write each livery entry. */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1239 |
int num_liveries = CheckSavegameVersion(63) ? LS_END - 4 : (CheckSavegameVersion(85) ? LS_END - 2: LS_END); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1240 |
for (i = 0; i < num_liveries; i++) { |
4603
3ccd4ee0a2e2
(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
|
1241 |
SlObject(&p->livery[i], _player_livery_desc); |
3ccd4ee0a2e2
(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
|
1242 |
} |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1243 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1244 |
if (num_liveries < LS_END) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1245 |
/* We want to insert some liveries somewhere in between. This means some have to be moved. */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1246 |
memmove(&p->livery[LS_FREIGHT_WAGON], &p->livery[LS_PASSENGER_WAGON_MONORAIL], (LS_END - LS_FREIGHT_WAGON) * sizeof(p->livery[0])); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1247 |
p->livery[LS_PASSENGER_WAGON_MONORAIL] = p->livery[LS_MONORAIL]; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1248 |
p->livery[LS_PASSENGER_WAGON_MAGLEV] = p->livery[LS_MAGLEV]; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1249 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1250 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1251 |
if (num_liveries == LS_END - 4) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1252 |
/* Copy bus/truck liveries over to trams */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1253 |
p->livery[LS_PASSENGER_TRAM] = p->livery[LS_BUS]; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1254 |
p->livery[LS_FREIGHT_TRAM] = p->livery[LS_TRUCK]; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1255 |
} |
0 | 1256 |
} |
1257 |
||
6573 | 1258 |
static void Save_PLYR() |
0 | 1259 |
{ |
1260 |
Player *p; |
|
1261 |
FOR_ALL_PLAYERS(p) { |
|
1262 |
if (p->is_active) { |
|
1263 |
SlSetArrayIndex(p->index); |
|
1264 |
SlAutolength((AutolengthProc*)SaveLoad_PLYR, p); |
|
1265 |
} |
|
1266 |
} |
|
1267 |
} |
|
1268 |
||
6573 | 1269 |
static void Load_PLYR() |
0 | 1270 |
{ |
1271 |
int index; |
|
1272 |
while ((index = SlIterateArray()) != -1) { |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1273 |
Player *p = GetPlayer((PlayerID)index); |
0 | 1274 |
SaveLoad_PLYR(p); |
1275 |
_player_colors[index] = p->player_color; |
|
9598
b73018a5ffc0
(svn r9631) [NoAI] -Codechange: rewrite the loading in such a manner that the NoAI branch gets savegame compatability for both NoAI branch savegames (from this revision on) as well as trunk savegames up to the revision that NoAI is synched with.
rubidium
parents:
9574
diff
changeset
|
1276 |
p->is_noai = true; |
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
1277 |
|
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
1278 |
/* This is needed so an AI is attached to a loaded AI */ |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
9359
diff
changeset
|
1279 |
if (p->is_ai) AI_StartNewAI(p->index); |
0 | 1280 |
} |
1281 |
} |
|
1282 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1283 |
extern const ChunkHandler _player_chunk_handlers[] = { |
0 | 1284 |
{ 'PLYR', Save_PLYR, Load_PLYR, CH_ARRAY | CH_LAST}, |
1285 |
}; |