author | Tero Marttila <terom@fixme.fi> |
Fri, 18 Jul 2008 21:28:42 +0300 | |
changeset 11175 | 020c61e39c94 |
parent 11161 | 7d0fac8f14cd |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10429
1b99254f9607
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
10382
diff
changeset
|
3 |
/** @file players.cpp Handling of players. */ |
1b99254f9607
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
10382
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" |
9282
2bb9703aeb39
(svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium
parents:
9281
diff
changeset
|
7 |
#include "engine_func.h" |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10372
diff
changeset
|
8 |
#include "engine_base.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
9 |
#include "player_func.h" |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
10 |
#include "player_gui.h" |
0 | 11 |
#include "town.h" |
9259
088d3649dd4f
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
8805
diff
changeset
|
12 |
#include "news_func.h" |
0 | 13 |
#include "saveload.h" |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8610
diff
changeset
|
14 |
#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
|
15 |
#include "network/network.h" |
10792
95b6eb9fcc9e
(svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents:
10784
diff
changeset
|
16 |
#include "network/network_func.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2154
diff
changeset
|
17 |
#include "variables.h" |
10225
8becb17444a7
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
9282
diff
changeset
|
18 |
#include "cheat_func.h" |
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
19 |
#include "ai/ai.h" |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
20 |
#include "player_face.h" |
7139
4ae3ab180d05
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
7054
diff
changeset
|
21 |
#include "group.h" |
8602
9e75e594a068
(svn r11667) -Codechange: split window.h into a header that defines some 'global' window related types, on that defined 'global' window functions and one that defines functions and types only used by *_gui.cpps.
rubidium
parents:
8494
diff
changeset
|
22 |
#include "window_func.h" |
8604
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
8602
diff
changeset
|
23 |
#include "tile_map.h" |
8610
17cc343a23dd
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8604
diff
changeset
|
24 |
#include "strings_func.h" |
8619
c2434269c3eb
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8617
diff
changeset
|
25 |
#include "gfx_func.h" |
8627
448ebf3a8291
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8619
diff
changeset
|
26 |
#include "functions.h" |
8636
2b158acb649c
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8635
diff
changeset
|
27 |
#include "date_func.h" |
8640
1e93b81e96d2
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8636
diff
changeset
|
28 |
#include "vehicle_func.h" |
8653
a83f7a536919
(svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents:
8651
diff
changeset
|
29 |
#include "sound_func.h" |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10372
diff
changeset
|
30 |
#include "core/alloc_func.hpp" |
10968
8f9c4121e43b
(svn r13522) -Codechange: Replace the qsort of the highscore with one of the internal sorters
skidd13
parents:
10967
diff
changeset
|
31 |
#include "core/sort_func.hpp" |
8708
0c29fbc79be4
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents:
8704
diff
changeset
|
32 |
#include "autoreplace_func.h" |
0c29fbc79be4
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents:
8704
diff
changeset
|
33 |
#include "autoreplace_gui.h" |
8710
52015340050c
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
8708
diff
changeset
|
34 |
#include "string_func.h" |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8710
diff
changeset
|
35 |
#include "ai/default/default.h" |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8710
diff
changeset
|
36 |
#include "ai/trolly/trolly.h" |
8732
b18f578f7c16
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents:
8726
diff
changeset
|
37 |
#include "road_func.h" |
b18f578f7c16
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents:
8726
diff
changeset
|
38 |
#include "rail.h" |
9281
d8cd9ac52a68
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
9259
diff
changeset
|
39 |
#include "sprite.h" |
10432
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
40 |
#include "debug.h" |
0 | 41 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
42 |
#include "table/strings.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
43 |
#include "table/sprites.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
44 |
|
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
45 |
Player _players[MAX_PLAYERS]; |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
46 |
PlayerByte _local_player; |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
47 |
PlayerByte _current_player; |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
48 |
/* NOSAVE: can be determined from player structs */ |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
49 |
byte _player_colors[MAX_PLAYERS]; |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
50 |
PlayerFace _player_face; ///< for player face storage in openttd.cfg |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
51 |
HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5 |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
52 |
|
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
|
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 |
* 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
|
55 |
* 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
|
56 |
* @param new_player the new player |
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
11160
diff
changeset
|
57 |
* @pre IsValidPlayerID(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE |
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
|
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 |
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
|
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 |
/* Player could also be PLAYER_SPECTATOR or OWNER_NONE */ |
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
11160
diff
changeset
|
62 |
assert(IsValidPlayerID(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE); |
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
|
63 |
|
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 |
_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
|
65 |
|
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 |
/* Do not update the patches if we are in the intro GUI */ |
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
11160
diff
changeset
|
67 |
if (IsValidPlayerID(new_player) && _game_mode != GM_MENU) { |
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
|
68 |
const Player *p = GetPlayer(new_player); |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
69 |
_settings_client.gui.autorenew = p->engine_renew; |
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
70 |
_settings_client.gui.autorenew_months = p->engine_renew_months; |
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
71 |
_settings_client.gui.autorenew_money = p->engine_renew_money; |
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
|
72 |
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
|
73 |
} |
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
|
74 |
} |
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
|
75 |
|
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
76 |
bool IsHumanPlayer(PlayerID pi) |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
77 |
{ |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
78 |
return !GetPlayer(pi)->is_ai; |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
79 |
} |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8743
diff
changeset
|
80 |
|
4428
0b0ee542d5b6
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
81 |
|
0b0ee542d5b6
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
82 |
uint16 GetDrawStringPlayerColor(PlayerID player) |
0b0ee542d5b6
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
83 |
{ |
4944
c61494b1ec35
(svn r6932) -Codechange: Send server messages with format NETWORK_ACTION_SERVER_MESSAGE so it is
Darkvater
parents:
4921
diff
changeset
|
84 |
/* 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
|
85 |
* of the player */ |
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
11160
diff
changeset
|
86 |
if (!IsValidPlayerID(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
|
87 |
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
|
88 |
} |
0b0ee542d5b6
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
89 |
|
6001
1e4c5406cd1a
(svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents:
5943
diff
changeset
|
90 |
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
|
91 |
{ |
1e4c5406cd1a
(svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents:
5943
diff
changeset
|
92 |
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
|
93 |
} |
1e4c5406cd1a
(svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents:
5943
diff
changeset
|
94 |
|
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
95 |
/** |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
96 |
* 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
|
97 |
* |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
98 |
* 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
|
99 |
* - 4 and 5: chin |
6475
f80c51a83069
(svn r8892) -Fix (r8879): swapped the eye colour and eyebrow bits.
rubidium
parents:
6470
diff
changeset
|
100 |
* - 6 to 9: eyebrows |
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
101 |
* - 10 to 13: nose |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
102 |
* - 13 to 15: lips (also moustache for males) |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
103 |
* - 16 to 19: hair |
6475
f80c51a83069
(svn r8892) -Fix (r8879): swapped the eye colour and eyebrow bits.
rubidium
parents:
6470
diff
changeset
|
104 |
* - 20 to 22: eye color |
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
105 |
* - 20 to 27: tie, ear rings etc. |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
106 |
* - 28 to 30: glasses |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
107 |
* - 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
|
108 |
* - 31: gender (0 = male, 1 = female) |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
109 |
* |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
110 |
* @param face the face in the old format |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
111 |
* @return the face in the new format |
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
112 |
*/ |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
113 |
PlayerFace ConvertFromOldPlayerFace(uint32 face) |
0 | 114 |
{ |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
115 |
PlayerFace pf = 0; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
116 |
GenderEthnicity ge = GE_WM; |
0 | 117 |
|
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
118 |
if (HasBit(face, 31)) SetBit(ge, GENDER_FEMALE); |
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
119 |
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
|
120 |
|
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
121 |
SetPlayerFaceBits(pf, PFV_GEN_ETHN, ge, ge); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
122 |
SetPlayerFaceBits(pf, PFV_HAS_GLASSES, ge, GB(face, 28, 3) <= 1); |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
SetPlayerFaceBits(pf, PFV_GLASSES, ge, GB(face, 28, 1)); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
130 |
|
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
131 |
uint lips = GB(face, 10, 4); |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
132 |
if (!HasBit(ge, GENDER_FEMALE) && lips < 4) { |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
133 |
SetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge, true); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
134 |
SetPlayerFaceBits(pf, PFV_MOUSTACHE, ge, max(lips, 1U) - 1); |
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
135 |
} else { |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
136 |
if (!HasBit(ge, GENDER_FEMALE)) { |
6672
1edb7a33f618
(svn r9377) -Fix (r9376): the off-by-one error was also present at another location :(
rubidium
parents:
6585
diff
changeset
|
137 |
lips = lips * 15 / 16; |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
138 |
lips -= 3; |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
139 |
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
|
140 |
} else { |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
141 |
lips = ScalePlayerFaceValue(PFV_LIPS, ge, lips); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
142 |
} |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
143 |
SetPlayerFaceBits(pf, PFV_LIPS, ge, lips); |
0 | 144 |
|
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
145 |
uint nose = GB(face, 13, 3); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
146 |
if (ge == GE_WF) { |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
147 |
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
|
148 |
} else { |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
149 |
nose = ScalePlayerFaceValue(PFV_NOSE, ge, nose); |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
150 |
} |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
151 |
SetPlayerFaceBits(pf, PFV_NOSE, ge, nose); |
6463
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
152 |
} |
cc9e4a024b61
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6443
diff
changeset
|
153 |
|
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
154 |
uint tie_earring = GB(face, 24, 4); |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
155 |
if (!HasBit(ge, GENDER_FEMALE) || tie_earring < 3) { // Not all females have an earring |
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
156 |
if (HasBit(ge, GENDER_FEMALE)) SetPlayerFaceBits(pf, PFV_HAS_TIE_EARRING, ge, true); |
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
157 |
SetPlayerFaceBits(pf, PFV_TIE_EARRING, ge, HasBit(ge, GENDER_FEMALE) ? tie_earring : ScalePlayerFaceValue(PFV_TIE_EARRING, ge, tie_earring / 2)); |
0 | 158 |
} |
159 |
||
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
160 |
return pf; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
161 |
} |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
162 |
|
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 |
* 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
|
165 |
* Unused bits are not enforced to be 0. |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
166 |
* @param pf the fact to check |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
167 |
* @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
|
168 |
*/ |
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
11160
diff
changeset
|
169 |
bool IsValidPlayerIDFace(PlayerFace pf) |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
170 |
{ |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
171 |
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
|
172 |
|
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
173 |
GenderEthnicity ge = (GenderEthnicity)GetPlayerFaceBits(pf, PFV_GEN_ETHN, GE_WM); |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
174 |
bool has_moustache = !HasBit(ge, GENDER_FEMALE) && GetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge) != 0; |
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
175 |
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
|
176 |
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
|
177 |
|
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
178 |
if (!ArePlayerFaceBitsValid(pf, PFV_EYE_COLOUR, ge)) return false; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
179 |
for (PlayerFaceVariable pfv = PFV_CHEEKS; pfv < PFV_END; pfv++) { |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
180 |
switch (pfv) { |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
181 |
case PFV_MOUSTACHE: if (!has_moustache) continue; break; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
182 |
case PFV_LIPS: /* FALL THROUGH */ |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
183 |
case PFV_NOSE: if (has_moustache) continue; break; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
184 |
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
|
185 |
case PFV_GLASSES: if (!has_glasses) continue; break; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
186 |
default: break; |
6470
a868173ae25b
(svn r8887) -Fix (r8879)[MorphOS]: initialization of mouth_table[] skipped by goto
KUDr
parents:
6463
diff
changeset
|
187 |
} |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
188 |
if (!ArePlayerFaceBitsValid(pf, pfv, ge)) return false; |
0 | 189 |
} |
190 |
||
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6475
diff
changeset
|
191 |
return true; |
0 | 192 |
} |
193 |
||
2475 | 194 |
void InvalidatePlayerWindows(const Player *p) |
0 | 195 |
{ |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2147
diff
changeset
|
196 |
PlayerID pid = p->index; |
0 | 197 |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2147
diff
changeset
|
198 |
if (pid == _local_player) InvalidateWindow(WC_STATUS_BAR, 0); |
0 | 199 |
InvalidateWindow(WC_FINANCES, pid); |
200 |
} |
|
201 |
||
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7337
diff
changeset
|
202 |
bool CheckPlayerHasMoney(CommandCost cost) |
0 | 203 |
{ |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
204 |
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
|
205 |
PlayerID pid = _current_player; |
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
11160
diff
changeset
|
206 |
if (IsValidPlayerID(pid) && cost.GetCost() > GetPlayer(pid)->player_money) { |
7498
ce6588257e8d
(svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents:
7487
diff
changeset
|
207 |
SetDParam(0, cost.GetCost()); |
0 | 208 |
_error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES; |
209 |
return false; |
|
210 |
} |
|
211 |
} |
|
212 |
return true; |
|
213 |
} |
|
214 |
||
10372
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
215 |
/** Backs up current economic data for a player |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
216 |
*/ |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
217 |
PlayerMoneyBackup::PlayerMoneyBackup(Player *player) |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
218 |
{ |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
219 |
p = player; |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
220 |
memcpy(backup_yearly_expenses, p->yearly_expenses, EXPENSES_END * sizeof(Money)); |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
221 |
backup_cur_economy = p->cur_economy; |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
222 |
} |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
223 |
|
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
224 |
/** Restore the economic data from last backup |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
225 |
* This should only be used right after Player::BackupEconomy() |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
226 |
*/ |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
227 |
void PlayerMoneyBackup::Restore() |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
228 |
{ |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
229 |
memcpy(p->yearly_expenses, backup_yearly_expenses, EXPENSES_END * sizeof(Money)); |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
230 |
p->cur_economy = backup_cur_economy; |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
231 |
} |
93844492fdd9
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
10365
diff
changeset
|
232 |
|
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7337
diff
changeset
|
233 |
static void SubtractMoneyFromAnyPlayer(Player *p, CommandCost cost) |
0 | 234 |
{ |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8725
diff
changeset
|
235 |
if (cost.GetCost() == 0) return; |
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8725
diff
changeset
|
236 |
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
|
237 |
|
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8725
diff
changeset
|
238 |
p->player_money -= cost.GetCost(); |
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8725
diff
changeset
|
239 |
p->yearly_expenses[0][cost.GetExpensesType()] += cost.GetCost(); |
0 | 240 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
241 |
if (HasBit(1 << EXPENSES_TRAIN_INC | |
7337
c86a1f45e023
(svn r10080) -Cleanup: replaced magic numbers in SubtractMoneyFromAnyPlayer() with enum values
bjarni
parents:
7220
diff
changeset
|
242 |
1 << EXPENSES_ROADVEH_INC | |
c86a1f45e023
(svn r10080) -Cleanup: replaced magic numbers in SubtractMoneyFromAnyPlayer() with enum values
bjarni
parents:
7220
diff
changeset
|
243 |
1 << EXPENSES_AIRCRAFT_INC | |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8725
diff
changeset
|
244 |
1 << EXPENSES_SHIP_INC, cost.GetExpensesType())) { |
8738
a12b246a4986
(svn r11806) -Fix (r11793) [FS#1638]: sign inversion when updating income and expenses
glx
parents:
8733
diff
changeset
|
245 |
p->cur_economy.income -= cost.GetCost(); |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
246 |
} else if (HasBit(1 << EXPENSES_TRAIN_RUN | |
7337
c86a1f45e023
(svn r10080) -Cleanup: replaced magic numbers in SubtractMoneyFromAnyPlayer() with enum values
bjarni
parents:
7220
diff
changeset
|
247 |
1 << EXPENSES_ROADVEH_RUN | |
c86a1f45e023
(svn r10080) -Cleanup: replaced magic numbers in SubtractMoneyFromAnyPlayer() with enum values
bjarni
parents:
7220
diff
changeset
|
248 |
1 << EXPENSES_AIRCRAFT_RUN | |
c86a1f45e023
(svn r10080) -Cleanup: replaced magic numbers in SubtractMoneyFromAnyPlayer() with enum values
bjarni
parents:
7220
diff
changeset
|
249 |
1 << EXPENSES_SHIP_RUN | |
c86a1f45e023
(svn r10080) -Cleanup: replaced magic numbers in SubtractMoneyFromAnyPlayer() with enum values
bjarni
parents:
7220
diff
changeset
|
250 |
1 << EXPENSES_PROPERTY | |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8725
diff
changeset
|
251 |
1 << EXPENSES_LOAN_INT, cost.GetExpensesType())) { |
8738
a12b246a4986
(svn r11806) -Fix (r11793) [FS#1638]: sign inversion when updating income and expenses
glx
parents:
8733
diff
changeset
|
252 |
p->cur_economy.expenses -= cost.GetCost(); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
253 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
254 |
|
0 | 255 |
InvalidatePlayerWindows(p); |
256 |
} |
|
257 |
||
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7337
diff
changeset
|
258 |
void SubtractMoneyFromPlayer(CommandCost cost) |
0 | 259 |
{ |
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
|
260 |
PlayerID pid = _current_player; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
261 |
|
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
11160
diff
changeset
|
262 |
if (IsValidPlayerID(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost); |
0 | 263 |
} |
264 |
||
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
265 |
void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cst) |
0 | 266 |
{ |
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1901
diff
changeset
|
267 |
Player *p = GetPlayer(player); |
0 | 268 |
byte m = p->player_money_fraction; |
7449
5cedaf2c861c
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium
parents:
7448
diff
changeset
|
269 |
Money cost = cst.GetCost(); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
270 |
|
0 | 271 |
p->player_money_fraction = m - (byte)cost; |
272 |
cost >>= 8; |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
273 |
if (p->player_money_fraction > m) cost++; |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8725
diff
changeset
|
274 |
if (cost != 0) SubtractMoneyFromAnyPlayer(p, CommandCost(cst.GetExpensesType(), cost)); |
0 | 275 |
} |
276 |
||
4849
9a3c3ae7f62f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
277 |
void GetNameOfOwner(Owner owner, TileIndex tile) |
0 | 278 |
{ |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
279 |
SetDParam(2, owner); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
280 |
|
0 | 281 |
if (owner != OWNER_TOWN) { |
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
11160
diff
changeset
|
282 |
if (!IsValidPlayerID(owner)) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
283 |
SetDParam(0, STR_0150_SOMEONE); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
284 |
} 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
|
285 |
const Player* p = GetPlayer(owner); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
286 |
|
7554
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7518
diff
changeset
|
287 |
SetDParam(0, STR_COMPANY_NAME); |
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7518
diff
changeset
|
288 |
SetDParam(1, p->index); |
0 | 289 |
} |
290 |
} else { |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
291 |
const Town* t = ClosestTownFromTile(tile, (uint)-1); |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
292 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
1977
diff
changeset
|
293 |
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
|
294 |
SetDParam(1, t->index); |
0 | 295 |
} |
296 |
} |
|
297 |
||
298 |
||
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
|
299 |
bool CheckOwnership(PlayerID owner) |
0 | 300 |
{ |
4849
9a3c3ae7f62f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
301 |
assert(owner < OWNER_END); |
0 | 302 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
303 |
if (owner == _current_player) return true; |
0 | 304 |
_error_message = STR_013B_OWNED_BY; |
305 |
GetNameOfOwner(owner, 0); |
|
306 |
return false; |
|
307 |
} |
|
308 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
309 |
bool CheckTileOwnership(TileIndex tile) |
0 | 310 |
{ |
4849
9a3c3ae7f62f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
311 |
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
|
312 |
|
4849
9a3c3ae7f62f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
313 |
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
|
314 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
315 |
if (owner == _current_player) return true; |
0 | 316 |
_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
|
317 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
318 |
/* 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
|
319 |
if (IsLocalPlayer()) GetNameOfOwner(owner, tile); |
0 | 320 |
return false; |
321 |
} |
|
322 |
||
323 |
static void GenerateCompanyName(Player *p) |
|
324 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
325 |
TileIndex tile; |
0 | 326 |
Town *t; |
327 |
StringID str; |
|
328 |
Player *pp; |
|
329 |
uint32 strp; |
|
330 |
char buffer[100]; |
|
331 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
332 |
if (p->name_1 != STR_SV_UNNAMED) return; |
0 | 333 |
|
334 |
tile = p->last_build_coordinate; |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
335 |
if (tile == 0) return; |
0 | 336 |
|
337 |
t = ClosestTownFromTile(tile, (uint)-1); |
|
338 |
||
10229
fba3f9fa44d7
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents:
10225
diff
changeset
|
339 |
if (IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) { |
0 | 340 |
str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_PLAYERNAME_START; |
341 |
strp = t->townnameparts; |
|
342 |
||
343 |
verify_name:; |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
344 |
/* No player must have this name already */ |
0 | 345 |
FOR_ALL_PLAYERS(pp) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
346 |
if (pp->name_1 == str && pp->name_2 == strp) goto bad_town_name; |
0 | 347 |
} |
348 |
||
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4878
diff
changeset
|
349 |
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
|
350 |
if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 150) |
0 | 351 |
goto bad_town_name; |
352 |
||
353 |
set_name:; |
|
354 |
p->name_1 = str; |
|
355 |
p->name_2 = strp; |
|
356 |
||
357 |
MarkWholeScreenDirty(); |
|
358 |
||
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4824
diff
changeset
|
359 |
if (!IsHumanPlayer(p->index)) { |
10521
79e3bb000aed
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
10435
diff
changeset
|
360 |
SetDParam(0, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED); |
79e3bb000aed
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
10435
diff
changeset
|
361 |
SetDParam(1, STR_705F_STARTS_CONSTRUCTION_NEAR); |
79e3bb000aed
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
10435
diff
changeset
|
362 |
SetDParam(2, p->index); |
79e3bb000aed
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
10435
diff
changeset
|
363 |
SetDParam(3, t->index); |
10579
0319efb408a0
(svn r13123) -Codechange: passing the bankrupt type via data_b is not needed anymore. Patch by Cirdan.
rubidium
parents:
10556
diff
changeset
|
364 |
AddNewsItem(STR_02B6, NS_COMPANY_NEW, p->last_build_coordinate, p->index); |
0 | 365 |
} |
366 |
return; |
|
367 |
} |
|
368 |
bad_town_name:; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
369 |
|
0 | 370 |
if (p->president_name_1 == SPECSTR_PRESIDENT_NAME) { |
371 |
str = SPECSTR_ANDCO_NAME; |
|
372 |
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
|
373 |
goto set_name; |
0 | 374 |
} else { |
375 |
str = SPECSTR_ANDCO_NAME; |
|
376 |
strp = Random(); |
|
377 |
goto verify_name; |
|
378 |
} |
|
379 |
} |
|
380 |
||
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
381 |
static const byte _colour_sort[COLOUR_END] = {2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 1, 1}; |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
382 |
static const Colours _similar_colour[COLOUR_END][2] = { |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
383 |
{ COLOUR_BLUE, COLOUR_LIGHT_BLUE }, // COLOUR_DARK_BLUE |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
384 |
{ COLOUR_GREEN, COLOUR_DARK_GREEN }, // COLOUR_PALE_GREEN |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
385 |
{ INVALID_COLOUR, INVALID_COLOUR }, // COLOUR_PINK |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
386 |
{ COLOUR_ORANGE, INVALID_COLOUR }, // COLOUR_YELLOW |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
387 |
{ INVALID_COLOUR, INVALID_COLOUR }, // COLOUR_RED |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
388 |
{ COLOUR_DARK_BLUE, COLOUR_BLUE }, // COLOUR_LIGHT_BLUE |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
389 |
{ COLOUR_PALE_GREEN, COLOUR_DARK_GREEN }, // COLOUR_GREEN |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
390 |
{ COLOUR_PALE_GREEN, COLOUR_GREEN }, // COLOUR_DARK_GREEN |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
391 |
{ COLOUR_BLUE, COLOUR_LIGHT_BLUE }, // COLOUR_BLUE |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
392 |
{ COLOUR_BROWN, COLOUR_ORANGE }, // COLOUR_CREAM |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
393 |
{ COLOUR_PURPLE, INVALID_COLOUR }, // COLOUR_MAUVE |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
394 |
{ COLOUR_MAUVE, INVALID_COLOUR }, // COLOUR_PURPLE |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
395 |
{ COLOUR_YELLOW, COLOUR_CREAM }, // COLOUR_ORANGE |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
396 |
{ COLOUR_CREAM, INVALID_COLOUR }, // COLOUR_BROWN |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
397 |
{ COLOUR_WHITE, INVALID_COLOUR }, // COLOUR_GREY |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
398 |
{ COLOUR_GREY, INVALID_COLOUR }, // COLOUR_WHITE |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
399 |
}; |
0 | 400 |
|
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
401 |
static byte GeneratePlayerColour() |
0 | 402 |
{ |
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
403 |
Colours colours[COLOUR_END]; |
0 | 404 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
405 |
/* Initialize array */ |
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
406 |
for (uint i = 0; i < COLOUR_END; i++) colours[i] = (Colours)i; |
0 | 407 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
408 |
/* And randomize it */ |
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
409 |
for (uint i = 0; i < 100; i++) { |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
410 |
uint r = Random(); |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
411 |
Swap(colours[GB(r, 0, 4)], colours[GB(r, 4, 4)]); |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
412 |
} |
0 | 413 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
414 |
/* Bubble sort it according to the values in table 1 */ |
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
415 |
for (uint i = 0; i < COLOUR_END; i++) { |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
416 |
for (uint j = 1; j < COLOUR_END; j++) { |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
417 |
if (_colour_sort[colours[j - 1]] < _colour_sort[colours[j]]) { |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
418 |
Swap(colours[j - 1], colours[j]); |
0 | 419 |
} |
420 |
} |
|
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
421 |
}; |
0 | 422 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
423 |
/* Move the colors that look similar to each player's color to the side */ |
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
424 |
Player *p; |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
425 |
FOR_ALL_PLAYERS(p) { |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
426 |
if (!p->is_active) continue; |
0 | 427 |
|
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
428 |
Colours pcolour = (Colours)p->player_color; |
0 | 429 |
|
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
430 |
for (uint i = 0; i < COLOUR_END; i++) { |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
431 |
if (colours[i] == pcolour) { |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
432 |
colours[i] = INVALID_COLOUR; |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
433 |
break; |
0 | 434 |
} |
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
435 |
} |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
436 |
|
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
437 |
for (uint j = 0; j < 2; j++) { |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
438 |
Colours similar = _similar_colour[pcolour][j]; |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
439 |
if (similar == INVALID_COLOUR) break; |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
440 |
|
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
441 |
for (uint i = 1; i < COLOUR_END; i++) { |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
442 |
if (colours[i - 1] == similar) Swap(colours[i - 1], colours[i]); |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
443 |
} |
0 | 444 |
} |
445 |
} |
|
446 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
447 |
/* Return the first available color */ |
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
448 |
for (uint i = 0; i < COLOUR_END; i++) { |
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
449 |
if (colours[i] != INVALID_COLOUR) return colours[i]; |
0 | 450 |
} |
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
451 |
|
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
452 |
NOT_REACHED(); |
0 | 453 |
} |
454 |
||
455 |
static void GeneratePresidentName(Player *p) |
|
456 |
{ |
|
457 |
Player *pp; |
|
458 |
char buffer[100], buffer2[40]; |
|
459 |
||
2952 | 460 |
for (;;) { |
0 | 461 |
restart:; |
462 |
||
463 |
p->president_name_2 = Random(); |
|
464 |
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
|
465 |
|
7554
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7518
diff
changeset
|
466 |
SetDParam(0, p->index); |
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7518
diff
changeset
|
467 |
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
|
468 |
if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 94) |
0 | 469 |
continue; |
470 |
||
471 |
FOR_ALL_PLAYERS(pp) { |
|
472 |
if (pp->is_active && p != pp) { |
|
7554
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7518
diff
changeset
|
473 |
SetDParam(0, pp->index); |
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7518
diff
changeset
|
474 |
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
|
475 |
if (strcmp(buffer2, buffer) == 0) |
0 | 476 |
goto restart; |
477 |
} |
|
478 |
} |
|
479 |
return; |
|
480 |
} |
|
481 |
} |
|
482 |
||
6573 | 483 |
static Player *AllocatePlayer() |
0 | 484 |
{ |
485 |
Player *p; |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
486 |
/* Find a free slot */ |
0 | 487 |
FOR_ALL_PLAYERS(p) { |
488 |
if (!p->is_active) { |
|
10365
fa999605dd21
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz
parents:
10322
diff
changeset
|
489 |
free(p->name); |
fa999605dd21
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz
parents:
10322
diff
changeset
|
490 |
free(p->president_name); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
491 |
PlayerID i = p->index; |
0 | 492 |
memset(p, 0, sizeof(Player)); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8710
diff
changeset
|
493 |
memset(&_players_ai[i], 0, sizeof(PlayerAI)); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8710
diff
changeset
|
494 |
memset(&_players_ainew[i], 0, sizeof(PlayerAiNew)); |
0 | 495 |
p->index = i; |
496 |
return p; |
|
497 |
} |
|
498 |
} |
|
499 |
return NULL; |
|
500 |
} |
|
501 |
||
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
|
502 |
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
|
503 |
{ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
504 |
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
|
505 |
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
|
506 |
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
|
507 |
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
|
508 |
} |
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
|
509 |
} |
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
|
510 |
|
8230
7b40f75cba12
(svn r11269) -Feature: user customisable faces. Patch by BigBB.
rubidium
parents:
7754
diff
changeset
|
511 |
/** |
7b40f75cba12
(svn r11269) -Feature: user customisable faces. Patch by BigBB.
rubidium
parents:
7754
diff
changeset
|
512 |
* Create a new player and sets all player variables default values |
7b40f75cba12
(svn r11269) -Feature: user customisable faces. Patch by BigBB.
rubidium
parents:
7754
diff
changeset
|
513 |
* |
7b40f75cba12
(svn r11269) -Feature: user customisable faces. Patch by BigBB.
rubidium
parents:
7754
diff
changeset
|
514 |
* @param is_ai is a ai player? |
7b40f75cba12
(svn r11269) -Feature: user customisable faces. Patch by BigBB.
rubidium
parents:
7754
diff
changeset
|
515 |
* @return the player struct |
7b40f75cba12
(svn r11269) -Feature: user customisable faces. Patch by BigBB.
rubidium
parents:
7754
diff
changeset
|
516 |
*/ |
0 | 517 |
Player *DoStartupNewPlayer(bool is_ai) |
518 |
{ |
|
519 |
Player *p; |
|
520 |
||
521 |
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
|
522 |
if (p == NULL) return NULL; |
0 | 523 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
524 |
/* Make a color */ |
10322
02d72ef5a6a7
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
10284
diff
changeset
|
525 |
p->player_color = GeneratePlayerColour(); |
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
|
526 |
ResetPlayerLivery(p); |
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
527 |
_player_colors[p->index] = p->player_color; |
0 | 528 |
p->name_1 = STR_SV_UNNAMED; |
529 |
p->is_active = true; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
530 |
|
7448
424ab8df8adb
(svn r10207) -Codechange: remove the redundant player_money in favour of the money64, which is now renamed to player_money.
rubidium
parents:
7446
diff
changeset
|
531 |
p->player_money = p->current_loan = 100000; |
0 | 532 |
|
533 |
p->is_ai = is_ai; |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8710
diff
changeset
|
534 |
_players_ai[p->index].state = 5; // AIS_WANT_NEW_ROUTE |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
535 |
p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = PLAYER_SPECTATOR; |
0 | 536 |
|
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
537 |
p->avail_railtypes = GetPlayerRailtypes(p->index); |
7181
f966d75af3a6
(svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents:
7144
diff
changeset
|
538 |
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
|
539 |
p->inaugurated_year = _cur_year; |
8230
7b40f75cba12
(svn r11269) -Feature: user customisable faces. Patch by BigBB.
rubidium
parents:
7754
diff
changeset
|
540 |
RandomPlayerFaceBits(p->face, (GenderEthnicity)Random(), false); // create a random player face |
0 | 541 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
542 |
/* Engine renewal settings */ |
2848 | 543 |
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
|
544 |
p->renew_keep_length = false; |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
545 |
p->engine_renew = _settings_client.gui.autorenew; |
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
546 |
p->engine_renew_months = _settings_client.gui.autorenew_months; |
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
547 |
p->engine_renew_money = _settings_client.gui.autorenew_money; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
548 |
|
0 | 549 |
GeneratePresidentName(p); |
550 |
||
551 |
InvalidateWindow(WC_GRAPH_LEGEND, 0); |
|
552 |
InvalidateWindow(WC_TOOLBAR_MENU, 0); |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
553 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
0 | 554 |
|
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
555 |
if (is_ai && (!_networking || _network_server) && _ai.enabled) |
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
556 |
AI_StartNewAI(p->index); |
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
557 |
|
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10372
diff
changeset
|
558 |
free(p->num_engines); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10372
diff
changeset
|
559 |
p->num_engines = CallocT<uint16>(GetEnginePoolSize()); |
4574
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4549
diff
changeset
|
560 |
|
0 | 561 |
return p; |
562 |
} |
|
563 |
||
6573 | 564 |
void StartupPlayers() |
0 | 565 |
{ |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
566 |
/* The AI starts like in the setting with +2 month max */ |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
567 |
_next_competitor_start = _settings_game.difficulty.competitor_start_time * 90 * DAY_TICKS + RandomRange(60 * DAY_TICKS) + 1; |
0 | 568 |
} |
569 |
||
6573 | 570 |
static void MaybeStartNewPlayer() |
0 | 571 |
{ |
572 |
uint n; |
|
573 |
Player *p; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
574 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
575 |
/* count number of competitors */ |
0 | 576 |
n = 0; |
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
577 |
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
|
578 |
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
|
579 |
} |
0 | 580 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
581 |
/* when there's a lot of computers in game, the probability that a new one starts is lower */ |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
582 |
if (n < (uint)_settings_game.difficulty.max_no_competitors && |
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
|
583 |
n < (_network_server ? |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
584 |
InteractiveRandomRange(_settings_game.difficulty.max_no_competitors + 2) : |
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
585 |
RandomRange(_settings_game.difficulty.max_no_competitors + 2) |
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
|
586 |
)) { |
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
|
587 |
/* 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
|
588 |
* 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
|
589 |
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
|
590 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
591 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
592 |
/* The next AI starts like the difficulty setting said, with +2 month max */ |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
593 |
_next_competitor_start = _settings_game.difficulty.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
|
594 |
_next_competitor_start += _network_server ? InteractiveRandomRange(60 * DAY_TICKS) : RandomRange(60 * DAY_TICKS); |
0 | 595 |
} |
596 |
||
6573 | 597 |
void InitializePlayers() |
0 | 598 |
{ |
599 |
memset(_players, 0, sizeof(_players)); |
|
8651
0775567ebf8a
(svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents:
8640
diff
changeset
|
600 |
for (PlayerID i = PLAYER_FIRST; i != MAX_PLAYERS; i++) { |
0775567ebf8a
(svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents:
8640
diff
changeset
|
601 |
_players[i].index = i; |
0775567ebf8a
(svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents:
8640
diff
changeset
|
602 |
for (uint j = 0; j < 4; j++) _players[i].share_owners[j] = PLAYER_SPECTATOR; |
0775567ebf8a
(svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents:
8640
diff
changeset
|
603 |
} |
0 | 604 |
_cur_player_tick_index = 0; |
605 |
} |
|
606 |
||
6573 | 607 |
void OnTick_Players() |
0 | 608 |
{ |
609 |
Player *p; |
|
610 |
||
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
|
611 |
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
|
612 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
613 |
p = GetPlayer((PlayerID)_cur_player_tick_index); |
0 | 614 |
_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS; |
615 |
if (p->name_1 != 0) GenerateCompanyName(p); |
|
616 |
||
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
617 |
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
|
618 |
MaybeStartNewPlayer(); |
0 | 619 |
} |
620 |
||
6573 | 621 |
void PlayersYearlyLoop() |
0 | 622 |
{ |
623 |
Player *p; |
|
624 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
625 |
/* Copy statistics */ |
0 | 626 |
FOR_ALL_PLAYERS(p) { |
627 |
if (p->is_active) { |
|
628 |
memmove(&p->yearly_expenses[1], &p->yearly_expenses[0], sizeof(p->yearly_expenses) - sizeof(p->yearly_expenses[0])); |
|
629 |
memset(&p->yearly_expenses[0], 0, sizeof(p->yearly_expenses[0])); |
|
630 |
InvalidateWindow(WC_FINANCES, p->index); |
|
631 |
} |
|
632 |
} |
|
633 |
||
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
634 |
if (_settings_client.gui.show_finances && _local_player != PLAYER_SPECTATOR) { |
0 | 635 |
ShowPlayerFinances(_local_player); |
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1901
diff
changeset
|
636 |
p = GetPlayer(_local_player); |
0 | 637 |
if (p->num_valid_stat_ent > 5 && p->old_economy[0].performance_history < p->old_economy[4].performance_history) { |
541 | 638 |
SndPlayFx(SND_01_BAD_YEAR); |
0 | 639 |
} else { |
541 | 640 |
SndPlayFx(SND_00_GOOD_YEAR); |
0 | 641 |
} |
642 |
} |
|
643 |
} |
|
644 |
||
2544 | 645 |
static void DeletePlayerStuff(PlayerID pi) |
0 | 646 |
{ |
647 |
Player *p; |
|
648 |
||
649 |
DeletePlayerWindows(pi); |
|
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1901
diff
changeset
|
650 |
p = GetPlayer(pi); |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
651 |
p->name_1 = STR_NULL; |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
652 |
p->president_name_1 = STR_NULL; |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
653 |
free(p->name); |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
654 |
free(p->president_name); |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
655 |
p->name = NULL; |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
656 |
p->president_name = NULL; |
0 | 657 |
} |
658 |
||
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
659 |
/** 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
|
660 |
* @param tile unused |
6979
d194d25020e7
(svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents:
6895
diff
changeset
|
661 |
* @param flags operation to perform |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
662 |
* @param p1 bits 0-3 command |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
663 |
* - p1 = 0 - change auto renew bool |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
664 |
* - p1 = 1 - change auto renew months |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
665 |
* - p1 = 2 - change auto renew money |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
666 |
* - p1 = 3 - change auto renew array |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
667 |
* - 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
|
668 |
* - p1 = 5 - change renew_keep_length |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
669 |
* @param p2 value to set |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
670 |
* if p1 = 0, then: |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
671 |
* - p2 = enable engine renewal |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
672 |
* if p1 = 1, then: |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
673 |
* - 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
|
674 |
* if p1 = 2, then |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
675 |
* - p2 = minimum amount of money available |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
676 |
* if p1 = 3, then: |
11055
4a2809a022b5
(svn r13612) -Fix [FS#2104]: wrong comment of CmdSetAutoReplace. Patch by Yexo.
rubidium
parents:
11016
diff
changeset
|
677 |
* - p1 bits 16-31 = engine group |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
678 |
* - p2 bits 0-15 = old engine type |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
679 |
* - p2 bits 16-31 = new engine type |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
680 |
* if p1 = 4, then: |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
681 |
* - p1 bit 15 = enable engine renewal |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
682 |
* - 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
|
683 |
* - 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
|
684 |
* if p1 = 5, then |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
685 |
* - p2 = enable renew_keep_length |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
686 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7337
diff
changeset
|
687 |
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
|
688 |
{ |
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
11160
diff
changeset
|
689 |
if (!IsValidPlayerID(_current_player)) return CMD_ERROR; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
690 |
|
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
691 |
Player *p = GetPlayer(_current_player); |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
692 |
switch (GB(p1, 0, 3)) { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
693 |
case 0: |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
694 |
if (p->engine_renew == HasBit(p2, 0)) return CMD_ERROR; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
695 |
|
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
696 |
if (flags & DC_EXEC) { |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
697 |
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
|
698 |
if (IsLocalPlayer()) { |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
699 |
_settings_client.gui.autorenew = p->engine_renew; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
700 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
701 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
702 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
703 |
break; |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
704 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
705 |
case 1: |
10276
e28934bc929a
(svn r12808) -Fix: enforce autorenew values range in command
glx
parents:
10229
diff
changeset
|
706 |
if (Clamp((int16)p2, -12, 12) != (int16)p2) return CMD_ERROR; |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
707 |
if (p->engine_renew_months == (int16)p2) return CMD_ERROR; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
708 |
|
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
709 |
if (flags & DC_EXEC) { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
710 |
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
|
711 |
if (IsLocalPlayer()) { |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
712 |
_settings_client.gui.autorenew_months = p->engine_renew_months; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
713 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
714 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
715 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
716 |
break; |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
717 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
718 |
case 2: |
10276
e28934bc929a
(svn r12808) -Fix: enforce autorenew values range in command
glx
parents:
10229
diff
changeset
|
719 |
if (ClampU(p2, 0, 2000000) != p2) return CMD_ERROR; |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
720 |
if (p->engine_renew_money == p2) return CMD_ERROR; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
721 |
|
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
722 |
if (flags & DC_EXEC) { |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
723 |
p->engine_renew_money = p2; |
2425
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2395
diff
changeset
|
724 |
if (IsLocalPlayer()) { |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
725 |
_settings_client.gui.autorenew_money = p->engine_renew_money; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
726 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
727 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
728 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
729 |
break; |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
730 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
731 |
case 3: { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
732 |
EngineID old_engine_type = GB(p2, 0, 16); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
733 |
EngineID new_engine_type = GB(p2, 16, 16); |
7144
f058df019ea2
(svn r9879) -Fix (r9874): global autoreplace was little broken ;)
rubidium
parents:
7139
diff
changeset
|
734 |
GroupID id_g = GB(p1, 16, 16); |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7337
diff
changeset
|
735 |
CommandCost cost; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
736 |
|
7754
8e7205edd6c7
(svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents:
7592
diff
changeset
|
737 |
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
|
738 |
if (new_engine_type != INVALID_ENGINE) { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
739 |
/* 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
|
740 |
* check that it's an engine that is in the engine array */ |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
741 |
if (!IsEngineIndex(new_engine_type)) return CMD_ERROR; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
742 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
743 |
/* check that the new vehicle type is the same as the original one */ |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
744 |
if (GetEngine(old_engine_type)->type != GetEngine(new_engine_type)->type) return CMD_ERROR; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
745 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
746 |
/* 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
|
747 |
if (GetEngine(new_engine_type)->type == VEH_AIRCRAFT && |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
748 |
(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
|
749 |
return CMD_ERROR; |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
750 |
} |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
751 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
752 |
/* make sure that the player can actually buy the new engine */ |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
753 |
if (!HasBit(GetEngine(new_engine_type)->player_avail, _current_player)) return CMD_ERROR; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
754 |
|
7139
4ae3ab180d05
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
7054
diff
changeset
|
755 |
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
|
756 |
} else { |
10229
fba3f9fa44d7
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents:
10225
diff
changeset
|
757 |
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
|
758 |
} |
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
|
759 |
|
7592
48055c5dd43d
(svn r10363) -Fix [FS#911]: invalidating autoreplace windows didn't take account of vehicle group (Matthias Wolf)
peter1138
parents:
7554
diff
changeset
|
760 |
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
|
761 |
|
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
|
762 |
return cost; |
2755
3098984d08c8
(svn r3300) Remove unreachable code - in this case some duplicate breaks
tron
parents:
2697
diff
changeset
|
763 |
} |
3098984d08c8
(svn r3300) Remove unreachable code - in this case some duplicate breaks
tron
parents:
2697
diff
changeset
|
764 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
765 |
case 4: |
10276
e28934bc929a
(svn r12808) -Fix: enforce autorenew values range in command
glx
parents:
10229
diff
changeset
|
766 |
if (Clamp((int16)GB(p1, 16, 16), -12, 12) != (int16)GB(p1, 16, 16)) return CMD_ERROR; |
e28934bc929a
(svn r12808) -Fix: enforce autorenew values range in command
glx
parents:
10229
diff
changeset
|
767 |
if (ClampU(p2, 0, 2000000) != p2) return CMD_ERROR; |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
768 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
769 |
if (flags & DC_EXEC) { |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
770 |
p->engine_renew = HasBit(p1, 15); |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
771 |
p->engine_renew_months = (int16)GB(p1, 16, 16); |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
772 |
p->engine_renew_money = p2; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
773 |
|
2425
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2395
diff
changeset
|
774 |
if (IsLocalPlayer()) { |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
775 |
_settings_client.gui.autorenew = p->engine_renew; |
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
776 |
_settings_client.gui.autorenew_months = p->engine_renew_months; |
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
777 |
_settings_client.gui.autorenew_money = p->engine_renew_money; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
778 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
779 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
780 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
781 |
break; |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
782 |
|
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
783 |
case 5: |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
784 |
if (p->renew_keep_length == HasBit(p2, 0)) return CMD_ERROR; |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
785 |
|
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
786 |
if (flags & DC_EXEC) { |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
787 |
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
|
788 |
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
|
789 |
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
|
790 |
} |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
791 |
} |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
792 |
break; |
10278
f0fbbccb931d
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
10276
diff
changeset
|
793 |
} |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
794 |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
795 |
return CommandCost(); |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
796 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
797 |
|
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
|
798 |
/** 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
|
799 |
* @param tile unused |
6979
d194d25020e7
(svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents:
6895
diff
changeset
|
800 |
* @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
|
801 |
* @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
|
802 |
* - 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
|
803 |
* - 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
|
804 |
* - 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
|
805 |
* - 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
|
806 |
* @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
|
807 |
* - 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
|
808 |
* - 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
|
809 |
* - 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
|
810 |
* - #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
|
811 |
* @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
|
812 |
* 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
|
813 |
* 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
|
814 |
* 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
|
815 |
* @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
|
816 |
* @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
|
817 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7337
diff
changeset
|
818 |
CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 819 |
{ |
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
|
820 |
if (flags & DC_EXEC) _current_player = OWNER_NONE; |
0 | 821 |
|
10967
fb9a80b89ea4
(svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13
parents:
10951
diff
changeset
|
822 |
InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0); |
fb9a80b89ea4
(svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13
parents:
10951
diff
changeset
|
823 |
|
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
|
824 |
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
|
825 |
case 0: { /* Create a new player */ |
11159
ca1c1162080a
(svn r13717) -Codechange: place the whole 'create new company' command in #ifdef ENABLE_NETWORK as it may only be executed when we are playing in a network game.
rubidium
parents:
11055
diff
changeset
|
826 |
/* This command is only executed in a multiplayer game */ |
ca1c1162080a
(svn r13717) -Codechange: place the whole 'create new company' command in #ifdef ENABLE_NETWORK as it may only be executed when we are playing in a network game.
rubidium
parents:
11055
diff
changeset
|
827 |
if (!_networking) return CMD_ERROR; |
ca1c1162080a
(svn r13717) -Codechange: place the whole 'create new company' command in #ifdef ENABLE_NETWORK as it may only be executed when we are playing in a network game.
rubidium
parents:
11055
diff
changeset
|
828 |
|
ca1c1162080a
(svn r13717) -Codechange: place the whole 'create new company' command in #ifdef ENABLE_NETWORK as it may only be executed when we are playing in a network game.
rubidium
parents:
11055
diff
changeset
|
829 |
#ifdef ENABLE_NETWORK |
ca1c1162080a
(svn r13717) -Codechange: place the whole 'create new company' command in #ifdef ENABLE_NETWORK as it may only be executed when we are playing in a network game.
rubidium
parents:
11055
diff
changeset
|
830 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
831 |
/* Joining Client: |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
832 |
* _local_player: PLAYER_SPECTATOR |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
833 |
* _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
|
834 |
* |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
835 |
* Other client(s)/server: |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
836 |
* _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
|
837 |
* cid = requested company/player of joining client */ |
4858
91f058409592
(svn r6784) -Codechange: Change invalid PlayerID type into ClientID which it is in CmdPlayerCtrl
Darkvater
parents:
4854
diff
changeset
|
838 |
uint16 cid = p2; // ClientID |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
839 |
|
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
|
840 |
/* Has the network client a correct ClientID? */ |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
841 |
if (!(flags & DC_EXEC)) return CommandCost(); |
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
842 |
if (cid >= MAX_CLIENT_INFO) return CommandCost(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
843 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
844 |
/* Delete multiplayer progress bar */ |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
845 |
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
|
846 |
|
11159
ca1c1162080a
(svn r13717) -Codechange: place the whole 'create new company' command in #ifdef ENABLE_NETWORK as it may only be executed when we are playing in a network game.
rubidium
parents:
11055
diff
changeset
|
847 |
Player *p = DoStartupNewPlayer(false); |
670
7c58dc46609c
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
848 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
849 |
/* 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
|
850 |
if (p == NULL) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
851 |
if (_network_server) { |
4858
91f058409592
(svn r6784) -Codechange: Change invalid PlayerID type into ClientID which it is in CmdPlayerCtrl
Darkvater
parents:
4854
diff
changeset
|
852 |
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
|
853 |
ci->client_playas = PLAYER_SPECTATOR; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
854 |
NetworkUpdateClientInfo(ci->client_index); |
7518 | 855 |
} else if (_local_player == PLAYER_SPECTATOR) { |
7517
756fb66c4843
(svn r10284) -Fix [FS#899]: in the unlucky event 2 clients join at the same time to start a new company while there is only one spot left, all clients became spectator. Now only make either one of the joining clients spectator (much more game-friendly ;))
truelight
parents:
7498
diff
changeset
|
856 |
_network_playas = PLAYER_SPECTATOR; |
756fb66c4843
(svn r10284) -Fix [FS#899]: in the unlucky event 2 clients join at the same time to start a new company while there is only one spot left, all clients became spectator. Now only make either one of the joining clients spectator (much more game-friendly ;))
truelight
parents:
7498
diff
changeset
|
857 |
} |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
858 |
break; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
859 |
} |
690
9f449a6b133e
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
688
diff
changeset
|
860 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
861 |
/* This is the joining client who wants a new company */ |
6895
a86d6390246a
(svn r9529) -Fix [FS#705]: when 2 clients joined together, the second asserted on the NewCompany command of the first
truelight
parents:
6678
diff
changeset
|
862 |
if (_local_player != _network_playas && _network_playas == p->index) { |
a86d6390246a
(svn r9529) -Fix [FS#705]: when 2 clients joined together, the second asserted on the NewCompany command of the first
truelight
parents:
6678
diff
changeset
|
863 |
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
|
864 |
SetLocalPlayer(p->index); |
10784
c3c7b558b4f1
(svn r13334) -Codechange: move the network settings variables from network/network_internal to settings.
rubidium
parents:
10775
diff
changeset
|
865 |
if (!StrEmpty(_settings_client.network.default_company_pass)) { |
c3c7b558b4f1
(svn r13334) -Codechange: move the network settings variables from network/network_internal to settings.
rubidium
parents:
10775
diff
changeset
|
866 |
char *password = _settings_client.network.default_company_pass; |
8494
88f26cafc858
(svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents:
8450
diff
changeset
|
867 |
NetworkChangeCompanyPassword(1, &password); |
88f26cafc858
(svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents:
8450
diff
changeset
|
868 |
} |
11160
4b963391b435
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
11159
diff
changeset
|
869 |
|
4b963391b435
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
11159
diff
changeset
|
870 |
_current_player = _local_player; |
4b963391b435
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
11159
diff
changeset
|
871 |
|
4b963391b435
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
11159
diff
changeset
|
872 |
/* Now that we have a new player, broadcast our autorenew settings to |
4b963391b435
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
11159
diff
changeset
|
873 |
* all clients so everything is in sync */ |
4b963391b435
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
11159
diff
changeset
|
874 |
NetworkSend_Command(0, |
4b963391b435
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
11159
diff
changeset
|
875 |
(_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, |
4b963391b435
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
11159
diff
changeset
|
876 |
_settings_client.gui.autorenew_money, |
4b963391b435
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
11159
diff
changeset
|
877 |
CMD_SET_AUTOREPLACE, |
4b963391b435
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
11159
diff
changeset
|
878 |
NULL |
4b963391b435
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
11159
diff
changeset
|
879 |
); |
4b963391b435
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
11159
diff
changeset
|
880 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
881 |
MarkWholeScreenDirty(); |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
882 |
} |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
883 |
|
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
884 |
if (_network_server) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
885 |
/* 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
|
886 |
* server-side in network_server.c:838, function |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
887 |
* 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
|
888 |
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
|
889 |
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
|
890 |
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
|
891 |
|
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
11160
diff
changeset
|
892 |
if (IsValidPlayerID(ci->client_playas)) { |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
893 |
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
|
894 |
_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
|
895 |
|
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
896 |
/* 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
|
897 |
* 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
|
898 |
* 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
|
899 |
* 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
|
900 |
* 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
|
901 |
* (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
|
902 |
* 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
|
903 |
* but it works. |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
904 |
* 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
|
905 |
* 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
|
906 |
* 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
|
907 |
_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
|
908 |
_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
|
909 |
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
|
910 |
_local_player = player_backup; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
911 |
} |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
912 |
} |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
913 |
#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
|
914 |
} 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
|
915 |
|
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 |
case 1: /* Make a new AI player */ |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
917 |
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
|
918 |
|
0 | 919 |
DoStartupNewPlayer(true); |
920 |
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
|
921 |
|
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
|
922 |
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
|
923 |
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
|
924 |
|
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
11160
diff
changeset
|
925 |
if (!IsValidPlayerID((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
|
926 |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
927 |
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
|
928 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
929 |
p = GetPlayer((PlayerID)p2); |
688
bcaa5256253d
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
930 |
|
bcaa5256253d
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
931 |
/* Only allow removal of HUMAN companies */ |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4824
diff
changeset
|
932 |
if (IsHumanPlayer(p->index)) { |
688
bcaa5256253d
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
933 |
/* Delete any open window of the company */ |
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
|
934 |
DeletePlayerWindows(p->index); |
688
bcaa5256253d
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
935 |
|
bcaa5256253d
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
936 |
/* Show the bankrupt news */ |
10521
79e3bb000aed
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
10435
diff
changeset
|
937 |
SetDParam(0, STR_705C_BANKRUPT); |
79e3bb000aed
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
10435
diff
changeset
|
938 |
SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY); |
79e3bb000aed
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
10435
diff
changeset
|
939 |
SetDParam(2, p->index); |
10579
0319efb408a0
(svn r13123) -Codechange: passing the bankrupt type via data_b is not needed anymore. Patch by Cirdan.
rubidium
parents:
10556
diff
changeset
|
940 |
AddNewsItem(STR_02B6, NS_COMPANY_BANKRUPT, 0, p->index); |
688
bcaa5256253d
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
941 |
|
bcaa5256253d
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
942 |
/* Remove the company */ |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
943 |
ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR); |
688
bcaa5256253d
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
944 |
p->is_active = false; |
bcaa5256253d
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
truelight
parents:
679
diff
changeset
|
945 |
} |
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
|
946 |
} break; |
0 | 947 |
|
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
|
948 |
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
|
949 |
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
|
950 |
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
|
951 |
|
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
11160
diff
changeset
|
952 |
if (!IsValidPlayerID(pid_old) || !IsValidPlayerID(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
|
953 |
|
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
|
954 |
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
|
955 |
|
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
|
956 |
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
|
957 |
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
|
958 |
} break; |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
959 |
|
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
|
960 |
default: return CMD_ERROR; |
0 | 961 |
} |
962 |
||
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
963 |
return CommandCost(); |
0 | 964 |
} |
965 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
966 |
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
|
967 |
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
|
968 |
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
|
969 |
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
|
970 |
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
|
971 |
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
|
972 |
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
|
973 |
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
|
974 |
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
|
975 |
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
|
976 |
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
|
977 |
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
|
978 |
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
|
979 |
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
|
980 |
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
|
981 |
STR_0218_MOGUL, |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
982 |
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
|
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
|
984 |
|
1016
026b2de61647
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
985 |
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
|
986 |
{ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
987 |
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
|
988 |
|
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
|
989 |
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
|
990 |
} |
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
|
991 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
992 |
/** 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
|
993 |
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
|
994 |
{ |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
995 |
HighScore *hs = _highscore_table[_settings_game.difficulty.diff_level]; |
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
|
996 |
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
|
997 |
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
|
998 |
|
1016
026b2de61647
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
999 |
/* 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
|
1000 |
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
|
1001 |
|
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
|
1002 |
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
|
1003 |
/* 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
|
1004 |
if (hs[i].score <= score) { |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1005 |
/* 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
|
1006 |
memmove(&hs[i + 1], &hs[i], sizeof(HighScore) * (lengthof(_highscore_table[0]) - i - 1)); |
7554
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7518
diff
changeset
|
1007 |
SetDParam(0, p->index); |
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7518
diff
changeset
|
1008 |
SetDParam(1, p->index); |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4878
diff
changeset
|
1009 |
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
|
1010 |
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
|
1011 |
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
|
1012 |
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
|
1013 |
} |
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
|
1014 |
} |
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
|
1015 |
|
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
|
1016 |
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
|
1017 |
} |
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
|
1018 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1019 |
/** Sort all players given their performance */ |
10968
8f9c4121e43b
(svn r13522) -Codechange: Replace the qsort of the highscore with one of the internal sorters
skidd13
parents:
10967
diff
changeset
|
1020 |
static int CDECL HighScoreSorter(const Player* const *a, const Player* const *b) |
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 |
{ |
10968
8f9c4121e43b
(svn r13522) -Codechange: Replace the qsort of the highscore with one of the internal sorters
skidd13
parents:
10967
diff
changeset
|
1022 |
return (*b)->old_economy[0].performance_history - (*a)->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
|
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 |
|
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 |
/* 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
|
1026 |
#define LAST_HS_ITEM lengthof(_highscore_table) - 1 |
6573 | 1027 |
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
|
1028 |
{ |
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
|
1029 |
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
|
1030 |
const Player* pl[MAX_PLAYERS]; |
11016 | 1031 |
uint count = 0; |
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
|
1032 |
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
|
1033 |
|
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
|
1034 |
/* 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
|
1035 |
FOR_ALL_PLAYERS(p) if (p->is_active) pl[count++] = p; |
10968
8f9c4121e43b
(svn r13522) -Codechange: Replace the qsort of the highscore with one of the internal sorters
skidd13
parents:
10967
diff
changeset
|
1036 |
|
8f9c4121e43b
(svn r13522) -Codechange: Replace the qsort of the highscore with one of the internal sorters
skidd13
parents:
10967
diff
changeset
|
1037 |
GSortT(pl, count, &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
|
1038 |
|
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
|
1039 |
{ |
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
|
1040 |
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
|
1041 |
|
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
|
1042 |
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
|
1043 |
|
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
|
1044 |
/* 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
|
1045 |
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
|
1046 |
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
|
1047 |
|
7554
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7518
diff
changeset
|
1048 |
SetDParam(0, pl[i]->index); |
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7518
diff
changeset
|
1049 |
SetDParam(1, pl[i]->index); |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4878
diff
changeset
|
1050 |
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
|
1051 |
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
|
1052 |
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
|
1053 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1054 |
/* 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
|
1055 |
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
|
1056 |
} |
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
|
1057 |
} |
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
|
1058 |
|
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
|
1059 |
/* 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
|
1060 |
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
|
1061 |
} |
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
|
1062 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1063 |
/** Save HighScore table to file */ |
6573 | 1064 |
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
|
1065 |
{ |
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
|
1066 |
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
|
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 |
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
|
1069 |
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
|
1070 |
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
|
1071 |
|
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
|
1072 |
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
|
1073 |
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
|
1074 |
/* First character is a command character, so strlen will fail on that */ |
10432
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1075 |
byte length = min(sizeof(hs->company), StrEmpty(hs->company) ? 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
|
1076 |
|
10432
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1077 |
if (fwrite(&length, sizeof(length), 1, fp) != 1 || // write away string length |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1078 |
fwrite(hs->company, length, 1, fp) > 1 || // Yes... could be 0 bytes too |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1079 |
fwrite(&hs->score, sizeof(hs->score), 1, fp) != 1 || |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1080 |
fwrite(" ", 2, 1, fp) != 1) { // XXX - placeholder for hs->title, not saved anymore; compatibility |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1081 |
DEBUG(misc, 1, "Could not save highscore."); |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1082 |
i = LAST_HS_ITEM; |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1083 |
break; |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1084 |
} |
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
|
1085 |
} |
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
|
1086 |
} |
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
|
1087 |
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
|
1088 |
} |
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
|
1089 |
} |
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
|
1090 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1091 |
/** Initialize the highscore table to 0 and if any file exists, load in values */ |
6573 | 1092 |
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
|
1093 |
{ |
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
|
1094 |
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
|
1095 |
|
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
|
1096 |
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
|
1097 |
|
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
|
1098 |
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
|
1099 |
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
|
1100 |
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
|
1101 |
|
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
|
1102 |
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
|
1103 |
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
|
1104 |
byte length; |
10432
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1105 |
if (fread(&length, sizeof(length), 1, fp) != 1 || |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1106 |
fread(hs->company, length, 1, fp) > 1 || // Yes... could be 0 bytes too |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1107 |
fread(&hs->score, sizeof(hs->score), 1, fp) != 1 || |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1108 |
fseek(fp, 2, SEEK_CUR) == -1) { // XXX - placeholder for hs->title, not saved anymore; compatibility |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1109 |
DEBUG(misc, 1, "Highscore corrupted"); |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1110 |
i = LAST_HS_ITEM; |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1111 |
break; |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1112 |
} |
9e0139a63042
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
10429
diff
changeset
|
1113 |
*lastof(hs->company) = '\0'; |
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
|
1114 |
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
|
1115 |
} |
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
|
1116 |
} |
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
|
1117 |
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
|
1118 |
} |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1017
diff
changeset
|
1119 |
|
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
|
1120 |
/* Initialize end of game variable (when to show highscore chart) */ |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10707
diff
changeset
|
1121 |
_settings_client.gui.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
|
1122 |
} |
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
|
1123 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1124 |
/* 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
|
1125 |
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
|
1126 |
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
|
1127 |
SLE_VAR(Player, name_1, SLE_STRINGID), |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
1128 |
SLE_CONDSTR(Player, name, SLE_STR, 0, 84, SL_MAX_VERSION), |
0 | 1129 |
|
10229
fba3f9fa44d7
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents:
10225
diff
changeset
|
1130 |
SLE_VAR(Player, president_name_1, SLE_UINT16), |
fba3f9fa44d7
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents:
10225
diff
changeset
|
1131 |
SLE_VAR(Player, president_name_2, SLE_UINT32), |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
1132 |
SLE_CONDSTR(Player, president_name, SLE_STR, 0, 84, SL_MAX_VERSION), |
0 | 1133 |
|
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
|
1134 |
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
|
1135 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1136 |
/* money was changed to a 64 bit field in savegame version 1. */ |
7451
82101e591f90
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents:
7449
diff
changeset
|
1137 |
SLE_CONDVAR(Player, player_money, SLE_VAR_I64 | SLE_FILE_I32, 0, 0), |
82101e591f90
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents:
7449
diff
changeset
|
1138 |
SLE_CONDVAR(Player, player_money, SLE_INT64, 1, SL_MAX_VERSION), |
0 | 1139 |
|
7451
82101e591f90
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents:
7449
diff
changeset
|
1140 |
SLE_CONDVAR(Player, current_loan, SLE_VAR_I64 | SLE_FILE_I32, 0, 64), |
82101e591f90
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents:
7449
diff
changeset
|
1141 |
SLE_CONDVAR(Player, current_loan, SLE_INT64, 65, SL_MAX_VERSION), |
0 | 1142 |
|
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
|
1143 |
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
|
1144 |
SLE_VAR(Player, player_money_fraction, SLE_UINT8), |
7054
edbb4d7765f2
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6979
diff
changeset
|
1145 |
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
|
1146 |
SLE_VAR(Player, block_preview, SLE_UINT8), |
0 | 1147 |
|
10284
4f4086cd9585
(svn r12816) -Fix: the cargo count in the performance rating window could be wrong.
rubidium
parents:
10278
diff
changeset
|
1148 |
SLE_CONDVAR(Player, cargo_types, SLE_FILE_U16 | SLE_VAR_U32, 0, 93), |
4f4086cd9585
(svn r12816) -Fix: the cargo count in the performance rating window could be wrong.
rubidium
parents:
10278
diff
changeset
|
1149 |
SLE_CONDVAR(Player, cargo_types, SLE_UINT32, 94, 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
|
1150 |
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
|
1151 |
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
|
1152 |
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
|
1153 |
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
|
1154 |
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
|
1155 |
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
|
1156 |
|
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_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
|
1158 |
|
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
|
1159 |
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
|
1160 |
|
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
|
1161 |
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
|
1162 |
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
|
1163 |
SLE_VAR(Player, bankrupt_timeout, SLE_INT16), |
7451
82101e591f90
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents:
7449
diff
changeset
|
1164 |
SLE_CONDVAR(Player, bankrupt_value, SLE_VAR_I64 | SLE_FILE_I32, 0, 64), |
82101e591f90
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents:
7449
diff
changeset
|
1165 |
SLE_CONDVAR(Player, bankrupt_value, SLE_INT64, 65, SL_MAX_VERSION), |
0 | 1166 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1167 |
/* 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
|
1168 |
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
|
1169 |
SLE_CONDARR(Player, yearly_expenses, SLE_INT64, 3 * 13, 2, SL_MAX_VERSION), |
0 | 1170 |
|
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
|
1171 |
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
|
1172 |
SLE_CONDVAR(Player, is_active, SLE_BOOL, 4, SL_MAX_VERSION), |
0 | 1173 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1174 |
/* 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
|
1175 |
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
|
1176 |
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
|
1177 |
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
|
1178 |
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
|
1179 |
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
|
1180 |
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
|
1181 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1182 |
/* reserve extra space in savegame here. (currently 63 bytes) */ |
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
|
1183 |
SLE_CONDNULL(63, 2, SL_MAX_VERSION), |
0 | 1184 |
|
1185 |
SLE_END() |
|
1186 |
}; |
|
1187 |
||
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
|
1188 |
static const SaveLoad _player_economy_desc[] = { |
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1189 |
/* these were changed to 64-bit in savegame format 2 */ |
7451
82101e591f90
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents:
7449
diff
changeset
|
1190 |
SLE_CONDVAR(PlayerEconomyEntry, income, SLE_FILE_I32 | SLE_VAR_I64, 0, 1), |
82101e591f90
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents:
7449
diff
changeset
|
1191 |
SLE_CONDVAR(PlayerEconomyEntry, income, SLE_INT64, 2, SL_MAX_VERSION), |
82101e591f90
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents:
7449
diff
changeset
|
1192 |
SLE_CONDVAR(PlayerEconomyEntry, expenses, SLE_FILE_I32 | SLE_VAR_I64, 0, 1), |
82101e591f90
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents:
7449
diff
changeset
|
1193 |
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
|
1194 |
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
|
1195 |
SLE_CONDVAR(PlayerEconomyEntry, company_value, SLE_INT64, 2, SL_MAX_VERSION), |
0 | 1196 |
|
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
|
1197 |
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
|
1198 |
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
|
1199 |
|
0 | 1200 |
SLE_END() |
1201 |
}; |
|
1202 |
||
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
|
1203 |
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
|
1204 |
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
|
1205 |
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
|
1206 |
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
|
1207 |
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
|
1208 |
}; |
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 |
|
2952 | 1210 |
static void SaveLoad_PLYR(Player* p) |
1211 |
{ |
|
0 | 1212 |
int i; |
1213 |
||
1214 |
SlObject(p, _player_desc); |
|
1215 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1216 |
/* Write AI? */ |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4824
diff
changeset
|
1217 |
if (!IsHumanPlayer(p->index)) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8710
diff
changeset
|
1218 |
SaveLoad_AI(p->index); |
0 | 1219 |
} |
1220 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1221 |
/* Write economy */ |
0 | 1222 |
SlObject(&p->cur_economy, _player_economy_desc); |
1223 |
||
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1224 |
/* 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
|
1225 |
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
|
1226 |
SlObject(&p->old_economy[i], _player_economy_desc); |
0 | 1227 |
} |
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
|
1228 |
|
6678
6353b8865d42
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6672
diff
changeset
|
1229 |
/* Write each livery entry. */ |
8805
7269d54ce5dc
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8772
diff
changeset
|
1230 |
int num_liveries = CheckSavegameVersion(63) ? LS_END - 4 : (CheckSavegameVersion(85) ? LS_END - 2: LS_END); |
7220
a8d6abc0981f
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
7181
diff
changeset
|
1231 |
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
|
1232 |
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
|
1233 |
} |
7220
a8d6abc0981f
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
7181
diff
changeset
|
1234 |
|
8805
7269d54ce5dc
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8772
diff
changeset
|
1235 |
if (num_liveries < LS_END) { |
7269d54ce5dc
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8772
diff
changeset
|
1236 |
/* We want to insert some liveries somewhere in between. This means some have to be moved. */ |
7269d54ce5dc
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8772
diff
changeset
|
1237 |
memmove(&p->livery[LS_FREIGHT_WAGON], &p->livery[LS_PASSENGER_WAGON_MONORAIL], (LS_END - LS_FREIGHT_WAGON) * sizeof(p->livery[0])); |
7269d54ce5dc
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8772
diff
changeset
|
1238 |
p->livery[LS_PASSENGER_WAGON_MONORAIL] = p->livery[LS_MONORAIL]; |
7269d54ce5dc
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8772
diff
changeset
|
1239 |
p->livery[LS_PASSENGER_WAGON_MAGLEV] = p->livery[LS_MAGLEV]; |
7269d54ce5dc
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8772
diff
changeset
|
1240 |
} |
7269d54ce5dc
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8772
diff
changeset
|
1241 |
|
7269d54ce5dc
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8772
diff
changeset
|
1242 |
if (num_liveries == LS_END - 4) { |
7220
a8d6abc0981f
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
7181
diff
changeset
|
1243 |
/* Copy bus/truck liveries over to trams */ |
a8d6abc0981f
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
7181
diff
changeset
|
1244 |
p->livery[LS_PASSENGER_TRAM] = p->livery[LS_BUS]; |
a8d6abc0981f
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
7181
diff
changeset
|
1245 |
p->livery[LS_FREIGHT_TRAM] = p->livery[LS_TRUCK]; |
a8d6abc0981f
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
7181
diff
changeset
|
1246 |
} |
0 | 1247 |
} |
1248 |
||
6573 | 1249 |
static void Save_PLYR() |
0 | 1250 |
{ |
1251 |
Player *p; |
|
1252 |
FOR_ALL_PLAYERS(p) { |
|
1253 |
if (p->is_active) { |
|
1254 |
SlSetArrayIndex(p->index); |
|
1255 |
SlAutolength((AutolengthProc*)SaveLoad_PLYR, p); |
|
1256 |
} |
|
1257 |
} |
|
1258 |
} |
|
1259 |
||
6573 | 1260 |
static void Load_PLYR() |
0 | 1261 |
{ |
1262 |
int index; |
|
1263 |
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
|
1264 |
Player *p = GetPlayer((PlayerID)index); |
0 | 1265 |
SaveLoad_PLYR(p); |
1266 |
_player_colors[index] = p->player_color; |
|
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
1267 |
|
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
1268 |
/* This is needed so an AI is attached to a loaded AI */ |
10951
4db23258381f
(svn r13505) -Fix: clear the memory for the new AI during the loading of a savegame so it does not try to execute commands generated in a different savegame, which could be resulting in the AI trying to give orders to stations that do not exist.
rubidium
parents:
10792
diff
changeset
|
1269 |
if (p->is_ai && (!_networking || _network_server) && _ai.enabled) { |
4db23258381f
(svn r13505) -Fix: clear the memory for the new AI during the loading of a savegame so it does not try to execute commands generated in a different savegame, which could be resulting in the AI trying to give orders to stations that do not exist.
rubidium
parents:
10792
diff
changeset
|
1270 |
/* Clear the memory of the new AI, otherwise we might be doing wrong things. */ |
4db23258381f
(svn r13505) -Fix: clear the memory for the new AI during the loading of a savegame so it does not try to execute commands generated in a different savegame, which could be resulting in the AI trying to give orders to stations that do not exist.
rubidium
parents:
10792
diff
changeset
|
1271 |
memset(&_players_ainew[index], 0, sizeof(PlayerAiNew)); |
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
1272 |
AI_StartNewAI(p->index); |
10951
4db23258381f
(svn r13505) -Fix: clear the memory for the new AI during the loading of a savegame so it does not try to execute commands generated in a different savegame, which could be resulting in the AI trying to give orders to stations that do not exist.
rubidium
parents:
10792
diff
changeset
|
1273 |
} |
0 | 1274 |
} |
1275 |
} |
|
1276 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1277 |
extern const ChunkHandler _player_chunk_handlers[] = { |
0 | 1278 |
{ 'PLYR', Save_PLYR, Load_PLYR, CH_ARRAY | CH_LAST}, |
1279 |
}; |