author | translators |
Thu, 27 Nov 2008 18:49:00 +0000 | |
changeset 10388 | ea6c13c8b6bc |
parent 10236 | 50afe9dd466e |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
3 |
/** @file company_cmd.cpp Handling of companies. */ |
9111
48ce04029fe4
(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:
9070
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
8786
1823ff88a054
(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:
8785
diff
changeset
|
7 |
#include "engine_func.h" |
9070
dd0121143eba
(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:
9061
diff
changeset
|
8 |
#include "engine_base.h" |
10208
72c00af5c95d
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents:
10207
diff
changeset
|
9 |
#include "company_func.h" |
72c00af5c95d
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents:
10207
diff
changeset
|
10 |
#include "company_gui.h" |
0 | 11 |
#include "town.h" |
8763
81fadd257f67
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
8309
diff
changeset
|
12 |
#include "news_func.h" |
0 | 13 |
#include "saveload.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
14 |
#include "command_func.h" |
5469
7edfc643abbc
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5441
diff
changeset
|
15 |
#include "network/network.h" |
9428
1ba05b499957
(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:
9420
diff
changeset
|
16 |
#include "network/network_func.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2154
diff
changeset
|
17 |
#include "variables.h" |
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8786
diff
changeset
|
18 |
#include "cheat_func.h" |
2395
d1629f64d157
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
19 |
#include "ai/ai.h" |
10208
72c00af5c95d
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents:
10207
diff
changeset
|
20 |
#include "company_manager_face.h" |
6643
f81bee57bc09
(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:
6558
diff
changeset
|
21 |
#include "group.h" |
8106
e6790dd9e750
(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:
7998
diff
changeset
|
22 |
#include "window_func.h" |
8108
b42a0e5c67ef
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
8106
diff
changeset
|
23 |
#include "tile_map.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8108
diff
changeset
|
24 |
#include "strings_func.h" |
8123
ce31d2843a95
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8121
diff
changeset
|
25 |
#include "gfx_func.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8123
diff
changeset
|
26 |
#include "functions.h" |
8140
0d0d8c94f84b
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8139
diff
changeset
|
27 |
#include "date_func.h" |
8144
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
28 |
#include "vehicle_func.h" |
8157
1505def01945
(svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents:
8155
diff
changeset
|
29 |
#include "sound_func.h" |
9070
dd0121143eba
(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:
9061
diff
changeset
|
30 |
#include "core/alloc_func.hpp" |
9526
37771bef1f79
(svn r13522) -Codechange: Replace the qsort of the highscore with one of the internal sorters
skidd13
parents:
9525
diff
changeset
|
31 |
#include "core/sort_func.hpp" |
8212
cf3fce5c7464
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents:
8208
diff
changeset
|
32 |
#include "autoreplace_func.h" |
cf3fce5c7464
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents:
8208
diff
changeset
|
33 |
#include "autoreplace_gui.h" |
8214
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
8212
diff
changeset
|
34 |
#include "string_func.h" |
8229
00e7467ceeee
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8214
diff
changeset
|
35 |
#include "ai/default/default.h" |
00e7467ceeee
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8214
diff
changeset
|
36 |
#include "ai/trolly/trolly.h" |
8236
8a5dd0b42e47
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents:
8230
diff
changeset
|
37 |
#include "road_func.h" |
8a5dd0b42e47
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents:
8230
diff
changeset
|
38 |
#include "rail.h" |
8785
871586967963
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
8763
diff
changeset
|
39 |
#include "sprite.h" |
9114
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
40 |
#include "debug.h" |
9659
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
41 |
#include "oldpool_func.h" |
0 | 42 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8258
diff
changeset
|
43 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8258
diff
changeset
|
44 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8258
diff
changeset
|
45 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
46 |
CompanyByte _local_company; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
47 |
CompanyByte _current_company; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
48 |
/* NOSAVE: can be determined from company structs */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
49 |
byte _company_colours[MAX_COMPANIES]; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
50 |
CompanyManagerFace _company_manager_face; ///< for company manager face storage in openttd.cfg |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8247
diff
changeset
|
51 |
HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5 |
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8247
diff
changeset
|
52 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
53 |
DEFINE_OLD_POOL_GENERIC(Company, Company) |
9659
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
54 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
55 |
Company::Company(uint16 name_1, bool is_ai) : name_1(name_1), is_ai(is_ai) |
9659
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
56 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
57 |
for (uint j = 0; j < 4; j++) this->share_owners[j] = COMPANY_SPECTATOR; |
9659
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
58 |
} |
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
59 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
60 |
Company::~Company() |
9659
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
61 |
{ |
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
62 |
free(this->name); |
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
63 |
free(this->president_name); |
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
64 |
free(this->num_engines); |
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
65 |
|
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
66 |
if (CleaningPool()) return; |
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
67 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
68 |
DeleteCompanyWindows(this->index); |
9659
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
69 |
this->name_1 = 0; |
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
70 |
} |
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
71 |
|
5376
204acb84473f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5375
diff
changeset
|
72 |
/** |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
73 |
* Sets the local company and updates the patch settings that are set on a |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
74 |
* per-company basis to reflect the core's state in the GUI. |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
75 |
* @param new_company the new company |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
76 |
* @pre IsValidCompanyID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE |
5376
204acb84473f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5375
diff
changeset
|
77 |
*/ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
78 |
void SetLocalCompany(CompanyID new_company) |
5376
204acb84473f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5375
diff
changeset
|
79 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
80 |
/* company could also be COMPANY_SPECTATOR or OWNER_NONE */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
81 |
assert(IsValidCompanyID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE); |
5376
204acb84473f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5375
diff
changeset
|
82 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
83 |
_local_company = new_company; |
5376
204acb84473f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5375
diff
changeset
|
84 |
|
204acb84473f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5375
diff
changeset
|
85 |
/* Do not update the patches if we are in the intro GUI */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
86 |
if (IsValidCompanyID(new_company) && _game_mode != GM_MENU) { |
10225
eb61dd8101c1
(svn r14448) -Codechange [FS#2328]: rename a few variables (based on a patch by planetmaker)
smatz
parents:
10209
diff
changeset
|
87 |
const Company *c = GetCompany(new_company); |
eb61dd8101c1
(svn r14448) -Codechange [FS#2328]: rename a few variables (based on a patch by planetmaker)
smatz
parents:
10209
diff
changeset
|
88 |
_settings_client.gui.autorenew = c->engine_renew; |
eb61dd8101c1
(svn r14448) -Codechange [FS#2328]: rename a few variables (based on a patch by planetmaker)
smatz
parents:
10209
diff
changeset
|
89 |
_settings_client.gui.autorenew_months = c->engine_renew_months; |
eb61dd8101c1
(svn r14448) -Codechange [FS#2328]: rename a few variables (based on a patch by planetmaker)
smatz
parents:
10209
diff
changeset
|
90 |
_settings_client.gui.autorenew_money = c->engine_renew_money; |
5376
204acb84473f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5375
diff
changeset
|
91 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
204acb84473f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5375
diff
changeset
|
92 |
} |
204acb84473f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5375
diff
changeset
|
93 |
} |
204acb84473f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5375
diff
changeset
|
94 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
95 |
bool IsHumanCompany(CompanyID company) |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8247
diff
changeset
|
96 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
97 |
return !GetCompany(company)->is_ai; |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8247
diff
changeset
|
98 |
} |
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8247
diff
changeset
|
99 |
|
4428
6d9fab57f2af
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
100 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
101 |
uint16 GetDrawStringCompanyColor(CompanyID company) |
4428
6d9fab57f2af
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
102 |
{ |
4944
f597859bba38
(svn r6932) -Codechange: Send server messages with format NETWORK_ACTION_SERVER_MESSAGE so it is
Darkvater
parents:
4921
diff
changeset
|
103 |
/* Get the color for DrawString-subroutines which matches the color |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
104 |
* of the company */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
105 |
if (!IsValidCompanyID(company)) return _colour_gradient[COLOUR_WHITE][4] | IS_PALETTE_COLOR; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
106 |
return (_colour_gradient[_company_colours[company]][4]) | IS_PALETTE_COLOR; |
4428
6d9fab57f2af
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
107 |
} |
6d9fab57f2af
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4344
diff
changeset
|
108 |
|
10225
eb61dd8101c1
(svn r14448) -Codechange [FS#2328]: rename a few variables (based on a patch by planetmaker)
smatz
parents:
10209
diff
changeset
|
109 |
void DrawCompanyIcon(CompanyID c, int x, int y) |
5750
5824ab1f36e2
(svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents:
5692
diff
changeset
|
110 |
{ |
10225
eb61dd8101c1
(svn r14448) -Codechange [FS#2328]: rename a few variables (based on a patch by planetmaker)
smatz
parents:
10209
diff
changeset
|
111 |
DrawSprite(SPR_PLAYER_ICON, COMPANY_SPRITE_COLOR(c), x, y); |
5750
5824ab1f36e2
(svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents:
5692
diff
changeset
|
112 |
} |
5824ab1f36e2
(svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents:
5692
diff
changeset
|
113 |
|
6137
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
114 |
/** |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
115 |
* Converts an old company manager's face format to the new company manager's face format |
6137
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
116 |
* |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
117 |
* Meaning of the bits in the old face (some bits are used in several times): |
6137
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
118 |
* - 4 and 5: chin |
6149
2d662e0fd6fb
(svn r8892) -Fix (r8879): swapped the eye colour and eyebrow bits.
rubidium
parents:
6144
diff
changeset
|
119 |
* - 6 to 9: eyebrows |
6137
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
120 |
* - 10 to 13: nose |
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
121 |
* - 13 to 15: lips (also moustache for males) |
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
122 |
* - 16 to 19: hair |
6149
2d662e0fd6fb
(svn r8892) -Fix (r8879): swapped the eye colour and eyebrow bits.
rubidium
parents:
6144
diff
changeset
|
123 |
* - 20 to 22: eye color |
6137
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
124 |
* - 20 to 27: tie, ear rings etc. |
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
125 |
* - 28 to 30: glasses |
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
126 |
* - 19, 26 and 27: race (bit 27 set and bit 19 equal to bit 26 = black, otherwise white) |
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
127 |
* - 31: gender (0 = male, 1 = female) |
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
128 |
* |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
129 |
* @param face the face in the old format |
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
130 |
* @return the face in the new format |
6137
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
131 |
*/ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
132 |
CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face) |
0 | 133 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
134 |
CompanyManagerFace cmf = 0; |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
135 |
GenderEthnicity ge = GE_WM; |
0 | 136 |
|
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7928
diff
changeset
|
137 |
if (HasBit(face, 31)) SetBit(ge, GENDER_FEMALE); |
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7928
diff
changeset
|
138 |
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
|
139 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
140 |
SetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN, ge, ge); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
141 |
SetCompanyManagerFaceBits(cmf, CMFV_HAS_GLASSES, ge, GB(face, 28, 3) <= 1); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
142 |
SetCompanyManagerFaceBits(cmf, CMFV_EYE_COLOUR, ge, HasBit(ge, ETHNICITY_BLACK) ? 0 : ClampU(GB(face, 20, 3), 5, 7) - 5); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
143 |
SetCompanyManagerFaceBits(cmf, CMFV_CHIN, ge, ScaleCompanyManagerFaceValue(CMFV_CHIN, ge, GB(face, 4, 2))); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
144 |
SetCompanyManagerFaceBits(cmf, CMFV_EYEBROWS, ge, ScaleCompanyManagerFaceValue(CMFV_EYEBROWS, ge, GB(face, 6, 4))); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
145 |
SetCompanyManagerFaceBits(cmf, CMFV_HAIR, ge, ScaleCompanyManagerFaceValue(CMFV_HAIR, ge, GB(face, 16, 4))); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
146 |
SetCompanyManagerFaceBits(cmf, CMFV_JACKET, ge, ScaleCompanyManagerFaceValue(CMFV_JACKET, ge, GB(face, 20, 2))); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
147 |
SetCompanyManagerFaceBits(cmf, CMFV_COLLAR, ge, ScaleCompanyManagerFaceValue(CMFV_COLLAR, ge, GB(face, 22, 2))); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
148 |
SetCompanyManagerFaceBits(cmf, CMFV_GLASSES, ge, GB(face, 28, 1)); |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
149 |
|
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
150 |
uint lips = GB(face, 10, 4); |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
151 |
if (!HasBit(ge, GENDER_FEMALE) && lips < 4) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
152 |
SetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge, true); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
153 |
SetCompanyManagerFaceBits(cmf, CMFV_MOUSTACHE, ge, max(lips, 1U) - 1); |
6137
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
154 |
} else { |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
155 |
if (!HasBit(ge, GENDER_FEMALE)) { |
6346
9b250d7d2bff
(svn r9377) -Fix (r9376): the off-by-one error was also present at another location :(
rubidium
parents:
6259
diff
changeset
|
156 |
lips = lips * 15 / 16; |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
157 |
lips -= 3; |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
158 |
if (HasBit(ge, ETHNICITY_BLACK) && lips > 8) lips = 0; |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
159 |
} else { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
160 |
lips = ScaleCompanyManagerFaceValue(CMFV_LIPS, ge, lips); |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
161 |
} |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
162 |
SetCompanyManagerFaceBits(cmf, CMFV_LIPS, ge, lips); |
0 | 163 |
|
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
164 |
uint nose = GB(face, 13, 3); |
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
165 |
if (ge == GE_WF) { |
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
166 |
nose = (nose * 3 >> 3) * 3 >> 2; // There is 'hole' in the nose sprites for females |
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
167 |
} else { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
168 |
nose = ScaleCompanyManagerFaceValue(CMFV_NOSE, ge, nose); |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
169 |
} |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
170 |
SetCompanyManagerFaceBits(cmf, CMFV_NOSE, ge, nose); |
6137
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
171 |
} |
f015946be07b
(svn r8879) -Codechange: make DrawPlayerFace easier to read.
rubidium
parents:
6117
diff
changeset
|
172 |
|
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
173 |
uint tie_earring = GB(face, 24, 4); |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
174 |
if (!HasBit(ge, GENDER_FEMALE) || tie_earring < 3) { // Not all females have an earring |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
175 |
if (HasBit(ge, GENDER_FEMALE)) SetCompanyManagerFaceBits(cmf, CMFV_HAS_TIE_EARRING, ge, true); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
176 |
SetCompanyManagerFaceBits(cmf, CMFV_TIE_EARRING, ge, HasBit(ge, GENDER_FEMALE) ? tie_earring : ScaleCompanyManagerFaceValue(CMFV_TIE_EARRING, ge, tie_earring / 2)); |
0 | 177 |
} |
178 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
179 |
return cmf; |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
180 |
} |
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
181 |
|
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
182 |
/** |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
183 |
* Checks whether a company manager's face is a valid encoding. |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
184 |
* Unused bits are not enforced to be 0. |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
185 |
* @param cmf the fact to check |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
186 |
* @return true if and only if the face is valid |
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
187 |
*/ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
188 |
bool IsValidCompanyManagerFace(CompanyManagerFace cmf) |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
189 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
190 |
if (!AreCompanyManagerFaceBitsValid(cmf, CMFV_GEN_ETHN, GE_WM)) return false; |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
191 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
192 |
GenderEthnicity ge = (GenderEthnicity)GetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN, GE_WM); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
193 |
bool has_moustache = !HasBit(ge, GENDER_FEMALE) && GetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge) != 0; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
194 |
bool has_tie_earring = !HasBit(ge, GENDER_FEMALE) || GetCompanyManagerFaceBits(cmf, CMFV_HAS_TIE_EARRING, ge) != 0; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
195 |
bool has_glasses = GetCompanyManagerFaceBits(cmf, CMFV_HAS_GLASSES, ge) != 0; |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
196 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
197 |
if (!AreCompanyManagerFaceBitsValid(cmf, CMFV_EYE_COLOUR, ge)) return false; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
198 |
for (CompanyManagerFaceVariable cmfv = CMFV_CHEEKS; cmfv < CMFV_END; cmfv++) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
199 |
switch (cmfv) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
200 |
case CMFV_MOUSTACHE: if (!has_moustache) continue; break; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
201 |
case CMFV_LIPS: /* FALL THROUGH */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
202 |
case CMFV_NOSE: if (has_moustache) continue; break; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
203 |
case CMFV_TIE_EARRING: if (!has_tie_earring) continue; break; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
204 |
case CMFV_GLASSES: if (!has_glasses) continue; break; |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
205 |
default: break; |
6144
aaa63fc00f1d
(svn r8887) -Fix (r8879)[MorphOS]: initialization of mouth_table[] skipped by goto
KUDr
parents:
6137
diff
changeset
|
206 |
} |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
207 |
if (!AreCompanyManagerFaceBitsValid(cmf, cmfv, ge)) return false; |
0 | 208 |
} |
209 |
||
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6149
diff
changeset
|
210 |
return true; |
0 | 211 |
} |
212 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
213 |
void InvalidateCompanyWindows(const Company *company) |
0 | 214 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
215 |
CompanyID cid = company->index; |
0 | 216 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
217 |
if (cid == _local_company) InvalidateWindow(WC_STATUS_BAR, 0); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
218 |
InvalidateWindow(WC_FINANCES, cid); |
0 | 219 |
} |
220 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
221 |
bool CheckCompanyHasMoney(CommandCost cost) |
0 | 222 |
{ |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
223 |
if (cost.GetCost() > 0) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
224 |
CompanyID company = _current_company; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
225 |
if (IsValidCompanyID(company) && cost.GetCost() > GetCompany(company)->money) { |
7002
1bf6a62b0fcb
(svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents:
6991
diff
changeset
|
226 |
SetDParam(0, cost.GetCost()); |
0 | 227 |
_error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES; |
228 |
return false; |
|
229 |
} |
|
230 |
} |
|
231 |
return true; |
|
232 |
} |
|
233 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
234 |
static void SubtractMoneyFromAnyCompany(Company *c, CommandCost cost) |
0 | 235 |
{ |
8230
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8229
diff
changeset
|
236 |
if (cost.GetCost() == 0) return; |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8229
diff
changeset
|
237 |
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
|
238 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
239 |
c->money -= cost.GetCost(); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
240 |
c->yearly_expenses[0][cost.GetExpensesType()] += cost.GetCost(); |
0 | 241 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
242 |
if (HasBit(1 << EXPENSES_TRAIN_INC | |
6841
46b2303390c6
(svn r10080) -Cleanup: replaced magic numbers in SubtractMoneyFromAnyPlayer() with enum values
bjarni
parents:
6724
diff
changeset
|
243 |
1 << EXPENSES_ROADVEH_INC | |
46b2303390c6
(svn r10080) -Cleanup: replaced magic numbers in SubtractMoneyFromAnyPlayer() with enum values
bjarni
parents:
6724
diff
changeset
|
244 |
1 << EXPENSES_AIRCRAFT_INC | |
8230
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8229
diff
changeset
|
245 |
1 << EXPENSES_SHIP_INC, cost.GetExpensesType())) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
246 |
c->cur_economy.income -= cost.GetCost(); |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
247 |
} else if (HasBit(1 << EXPENSES_TRAIN_RUN | |
6841
46b2303390c6
(svn r10080) -Cleanup: replaced magic numbers in SubtractMoneyFromAnyPlayer() with enum values
bjarni
parents:
6724
diff
changeset
|
248 |
1 << EXPENSES_ROADVEH_RUN | |
46b2303390c6
(svn r10080) -Cleanup: replaced magic numbers in SubtractMoneyFromAnyPlayer() with enum values
bjarni
parents:
6724
diff
changeset
|
249 |
1 << EXPENSES_AIRCRAFT_RUN | |
46b2303390c6
(svn r10080) -Cleanup: replaced magic numbers in SubtractMoneyFromAnyPlayer() with enum values
bjarni
parents:
6724
diff
changeset
|
250 |
1 << EXPENSES_SHIP_RUN | |
46b2303390c6
(svn r10080) -Cleanup: replaced magic numbers in SubtractMoneyFromAnyPlayer() with enum values
bjarni
parents:
6724
diff
changeset
|
251 |
1 << EXPENSES_PROPERTY | |
8230
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8229
diff
changeset
|
252 |
1 << EXPENSES_LOAN_INT, cost.GetExpensesType())) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
253 |
c->cur_economy.expenses -= cost.GetCost(); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
254 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
255 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
256 |
InvalidateCompanyWindows(c); |
0 | 257 |
} |
258 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
259 |
void SubtractMoneyFromCompany(CommandCost cost) |
0 | 260 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
261 |
CompanyID cid = _current_company; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
262 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
263 |
if (IsValidCompanyID(cid)) SubtractMoneyFromAnyCompany(GetCompany(cid), cost); |
0 | 264 |
} |
265 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
266 |
void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cst) |
0 | 267 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
268 |
Company *c = GetCompany(company); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
269 |
byte m = c->money_fraction; |
6953
230d1e3ac86c
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium
parents:
6952
diff
changeset
|
270 |
Money cost = cst.GetCost(); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
271 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
272 |
c->money_fraction = m - (byte)cost; |
0 | 273 |
cost >>= 8; |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
274 |
if (c->money_fraction > m) cost++; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
275 |
if (cost != 0) SubtractMoneyFromAnyCompany(c, CommandCost(cst.GetExpensesType(), cost)); |
0 | 276 |
} |
277 |
||
4849
1c6f21eb97f2
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
278 |
void GetNameOfOwner(Owner owner, TileIndex tile) |
0 | 279 |
{ |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
280 |
SetDParam(2, owner); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
281 |
|
0 | 282 |
if (owner != OWNER_TOWN) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
283 |
if (!IsValidCompanyID(owner)) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
284 |
SetDParam(0, STR_0150_SOMEONE); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
285 |
} else { |
7058
8105bb13ce3d
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7022
diff
changeset
|
286 |
SetDParam(0, STR_COMPANY_NAME); |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
287 |
SetDParam(1, owner); |
0 | 288 |
} |
289 |
} else { |
|
10236
50afe9dd466e
(svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium
parents:
10225
diff
changeset
|
290 |
const Town *t = ClosestTownFromTile(tile, UINT_MAX); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
291 |
|
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
1977
diff
changeset
|
292 |
SetDParam(0, STR_TOWN); |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
1977
diff
changeset
|
293 |
SetDParam(1, t->index); |
0 | 294 |
} |
295 |
} |
|
296 |
||
297 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
298 |
bool CheckOwnership(Owner owner) |
0 | 299 |
{ |
4849
1c6f21eb97f2
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
300 |
assert(owner < OWNER_END); |
0 | 301 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
302 |
if (owner == _current_company) return true; |
0 | 303 |
_error_message = STR_013B_OWNED_BY; |
304 |
GetNameOfOwner(owner, 0); |
|
305 |
return false; |
|
306 |
} |
|
307 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
308 |
bool CheckTileOwnership(TileIndex tile) |
0 | 309 |
{ |
4849
1c6f21eb97f2
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
310 |
Owner owner = GetTileOwner(tile); |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
311 |
|
4849
1c6f21eb97f2
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
312 |
assert(owner < OWNER_END); |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
313 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
314 |
if (owner == _current_company) return true; |
0 | 315 |
_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
|
316 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
317 |
/* no need to get the name of the owner unless we're the local company (saves some time) */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
318 |
if (IsLocalCompany()) GetNameOfOwner(owner, tile); |
0 | 319 |
return false; |
320 |
} |
|
321 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
322 |
static void GenerateCompanyName(Company *c) |
0 | 323 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
324 |
TileIndex tile; |
0 | 325 |
Town *t; |
326 |
StringID str; |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
327 |
Company *cc; |
0 | 328 |
uint32 strp; |
329 |
char buffer[100]; |
|
330 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
331 |
if (c->name_1 != STR_SV_UNNAMED) return; |
0 | 332 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
333 |
tile = c->last_build_coordinate; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
334 |
if (tile == 0) return; |
0 | 335 |
|
10236
50afe9dd466e
(svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium
parents:
10225
diff
changeset
|
336 |
t = ClosestTownFromTile(tile, UINT_MAX); |
0 | 337 |
|
10141
6e3a58a7587d
(svn r14327) -Fix [FS#2251]: if you rename a town before building something and build something near that town your company would be called "<old townname> Transport".
rubidium
parents:
10010
diff
changeset
|
338 |
if (t->name == NULL && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) { |
0 | 339 |
str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_PLAYERNAME_START; |
340 |
strp = t->townnameparts; |
|
341 |
||
342 |
verify_name:; |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
343 |
/* No companies must have this name already */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
344 |
FOR_ALL_COMPANIES(cc) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
345 |
if (cc->name_1 == str && cc->name_2 == strp) goto bad_town_name; |
0 | 346 |
} |
347 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4878
diff
changeset
|
348 |
GetString(buffer, str, lastof(buffer)); |
9914
c07d0352d8d5
(svn r14064) -Fix [FS#1752]: check for the length of strings (in bytes) in the command. Checking for the length in pixels is impossible because that differs per client.
rubidium
parents:
9890
diff
changeset
|
349 |
if (strlen(buffer) >= MAX_LENGTH_COMPANY_NAME_BYTES) goto bad_town_name; |
0 | 350 |
|
351 |
set_name:; |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
352 |
c->name_1 = str; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
353 |
c->name_2 = strp; |
0 | 354 |
|
355 |
MarkWholeScreenDirty(); |
|
356 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
357 |
if (!IsHumanCompany(c->index)) { |
9658
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
358 |
CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1); |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
359 |
cni->FillData(c); |
9199
ce9fbdff6581
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
9117
diff
changeset
|
360 |
SetDParam(0, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED); |
ce9fbdff6581
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
9117
diff
changeset
|
361 |
SetDParam(1, STR_705F_STARTS_CONSTRUCTION_NEAR); |
9658
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
362 |
SetDParamStr(2, cni->company_name); |
9199
ce9fbdff6581
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
9117
diff
changeset
|
363 |
SetDParam(3, t->index); |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
364 |
AddNewsItem(STR_02B6, NS_COMPANY_NEW, c->last_build_coordinate, 0, cni); |
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 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
370 |
if (c->president_name_1 == SPECSTR_PRESIDENT_NAME) { |
0 | 371 |
str = SPECSTR_ANDCO_NAME; |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
372 |
strp = c->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 |
||
9044
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
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}; |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
382 |
static const Colours _similar_colour[COLOUR_END][2] = { |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
383 |
{ COLOUR_BLUE, COLOUR_LIGHT_BLUE }, // COLOUR_DARK_BLUE |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
384 |
{ COLOUR_GREEN, COLOUR_DARK_GREEN }, // COLOUR_PALE_GREEN |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
385 |
{ INVALID_COLOUR, INVALID_COLOUR }, // COLOUR_PINK |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
386 |
{ COLOUR_ORANGE, INVALID_COLOUR }, // COLOUR_YELLOW |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
387 |
{ INVALID_COLOUR, INVALID_COLOUR }, // COLOUR_RED |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
388 |
{ COLOUR_DARK_BLUE, COLOUR_BLUE }, // COLOUR_LIGHT_BLUE |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
389 |
{ COLOUR_PALE_GREEN, COLOUR_DARK_GREEN }, // COLOUR_GREEN |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
390 |
{ COLOUR_PALE_GREEN, COLOUR_GREEN }, // COLOUR_DARK_GREEN |
9981
56b0a90e9e89
(svn r14138) -Fix (r12863): dark blue wasn't considered as similiar to blue
smatz
parents:
9930
diff
changeset
|
391 |
{ COLOUR_DARK_BLUE, COLOUR_LIGHT_BLUE }, // COLOUR_BLUE |
9044
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
392 |
{ COLOUR_BROWN, COLOUR_ORANGE }, // COLOUR_CREAM |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
393 |
{ COLOUR_PURPLE, INVALID_COLOUR }, // COLOUR_MAUVE |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
394 |
{ COLOUR_MAUVE, INVALID_COLOUR }, // COLOUR_PURPLE |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
395 |
{ COLOUR_YELLOW, COLOUR_CREAM }, // COLOUR_ORANGE |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
396 |
{ COLOUR_CREAM, INVALID_COLOUR }, // COLOUR_BROWN |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
397 |
{ COLOUR_WHITE, INVALID_COLOUR }, // COLOUR_GREY |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
398 |
{ COLOUR_GREY, INVALID_COLOUR }, // COLOUR_WHITE |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
399 |
}; |
0 | 400 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
401 |
static byte GenerateCompanyColour() |
0 | 402 |
{ |
9044
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
403 |
Colours colours[COLOUR_END]; |
0 | 404 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
405 |
/* Initialize array */ |
9044
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
406 |
for (uint i = 0; i < COLOUR_END; i++) colours[i] = (Colours)i; |
0 | 407 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
408 |
/* And randomize it */ |
9044
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
409 |
for (uint i = 0; i < 100; i++) { |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
410 |
uint r = Random(); |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
411 |
Swap(colours[GB(r, 0, 4)], colours[GB(r, 4, 4)]); |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
412 |
} |
0 | 413 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
414 |
/* Bubble sort it according to the values in table 1 */ |
9044
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
415 |
for (uint i = 0; i < COLOUR_END; i++) { |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
416 |
for (uint j = 1; j < COLOUR_END; j++) { |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
417 |
if (_colour_sort[colours[j - 1]] < _colour_sort[colours[j]]) { |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
418 |
Swap(colours[j - 1], colours[j]); |
0 | 419 |
} |
420 |
} |
|
9044
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
421 |
}; |
0 | 422 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
423 |
/* Move the colors that look similar to each company's color to the side */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
424 |
Company *c; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
425 |
FOR_ALL_COMPANIES(c) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
426 |
Colours pcolour = (Colours)c->colour; |
0 | 427 |
|
9044
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
428 |
for (uint i = 0; i < COLOUR_END; i++) { |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
429 |
if (colours[i] == pcolour) { |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
430 |
colours[i] = INVALID_COLOUR; |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
431 |
break; |
0 | 432 |
} |
9044
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
433 |
} |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
434 |
|
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
435 |
for (uint j = 0; j < 2; j++) { |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
436 |
Colours similar = _similar_colour[pcolour][j]; |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
437 |
if (similar == INVALID_COLOUR) break; |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
438 |
|
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
439 |
for (uint i = 1; i < COLOUR_END; i++) { |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
440 |
if (colours[i - 1] == similar) Swap(colours[i - 1], colours[i]); |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
441 |
} |
0 | 442 |
} |
443 |
} |
|
444 |
||
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
445 |
/* Return the first available color */ |
9044
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
446 |
for (uint i = 0; i < COLOUR_END; i++) { |
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
447 |
if (colours[i] != INVALID_COLOUR) return colours[i]; |
0 | 448 |
} |
9044
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
449 |
|
d01d22d12fce
(svn r12863) -Codechange: rewrite GeneratePlayerColour to be better understandable.
rubidium
parents:
9017
diff
changeset
|
450 |
NOT_REACHED(); |
0 | 451 |
} |
452 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
453 |
static void GeneratePresidentName(Company *c) |
0 | 454 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
455 |
Company *cc; |
0 | 456 |
char buffer[100], buffer2[40]; |
457 |
||
2952 | 458 |
for (;;) { |
0 | 459 |
restart:; |
460 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
461 |
c->president_name_2 = Random(); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
462 |
c->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
|
463 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
464 |
SetDParam(0, c->index); |
10209
a1e7417bf1b7
(svn r14423) -Codechange: also do r14221 for the strings.
rubidium
parents:
10208
diff
changeset
|
465 |
GetString(buffer, STR_PRESIDENT_NAME, lastof(buffer)); |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4606
diff
changeset
|
466 |
if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 94) |
0 | 467 |
continue; |
468 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
469 |
FOR_ALL_COMPANIES(cc) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
470 |
if (c != cc) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
471 |
SetDParam(0, cc->index); |
10209
a1e7417bf1b7
(svn r14423) -Codechange: also do r14221 for the strings.
rubidium
parents:
10208
diff
changeset
|
472 |
GetString(buffer2, STR_PRESIDENT_NAME, lastof(buffer2)); |
1304
6460f4c8600e
(svn r1808) Use strcmp() instead of home brewed function str_eq()
tron
parents:
1174
diff
changeset
|
473 |
if (strcmp(buffer2, buffer) == 0) |
0 | 474 |
goto restart; |
475 |
} |
|
476 |
} |
|
477 |
return; |
|
478 |
} |
|
479 |
} |
|
480 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
481 |
void ResetCompanyLivery(Company *c) |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4580
diff
changeset
|
482 |
{ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
483 |
for (LiveryScheme scheme = LS_BEGIN; scheme < LS_END; scheme++) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
484 |
c->livery[scheme].in_use = false; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
485 |
c->livery[scheme].colour1 = c->colour; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
486 |
c->livery[scheme].colour2 = c->colour; |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4580
diff
changeset
|
487 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4580
diff
changeset
|
488 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4580
diff
changeset
|
489 |
|
7734
627817106768
(svn r11269) -Feature: user customisable faces. Patch by BigBB.
rubidium
parents:
7258
diff
changeset
|
490 |
/** |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
491 |
* Create a new company and sets all company variables default values |
7734
627817106768
(svn r11269) -Feature: user customisable faces. Patch by BigBB.
rubidium
parents:
7258
diff
changeset
|
492 |
* |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
493 |
* @param is_ai is a ai company? |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
494 |
* @return the company struct |
7734
627817106768
(svn r11269) -Feature: user customisable faces. Patch by BigBB.
rubidium
parents:
7258
diff
changeset
|
495 |
*/ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
496 |
Company *DoStartupNewCompany(bool is_ai) |
0 | 497 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
498 |
if (!Company::CanAllocateItem()) return NULL; |
9890
d78e15f4ac71
(svn r14038) -Fix [FS#2211] (r13731): company limit was not properly enforced for CMD_PLAYER_CTRL.
rubidium
parents:
9889
diff
changeset
|
499 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
500 |
Company *c = new Company(STR_SV_UNNAMED, is_ai); |
0 | 501 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
502 |
memset(&_companies_ai[c->index], 0, sizeof(CompanyAI)); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
503 |
memset(&_companies_ainew[c->index], 0, sizeof(CompanyAiNew)); |
9659
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
504 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
505 |
/* Make a color */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
506 |
c->colour = GenerateCompanyColour(); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
507 |
ResetCompanyLivery(c); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
508 |
_company_colours[c->index] = c->colour; |
0 | 509 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
510 |
c->money = c->current_loan = 100000; |
0 | 511 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
512 |
_companies_ai[c->index].state = 5; // AIS_WANT_NEW_ROUTE |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
513 |
c->share_owners[0] = c->share_owners[1] = c->share_owners[2] = c->share_owners[3] = INVALID_OWNER; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
514 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
515 |
c->avail_railtypes = GetCompanyRailtypes(c->index); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
516 |
c->avail_roadtypes = GetCompanyRoadtypes(c->index); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
517 |
c->inaugurated_year = _cur_year; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
518 |
RandomCompanyManagerFaceBits(c->face, (GenderEthnicity)Random(), false); // create a random company manager face |
0 | 519 |
|
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
520 |
/* Engine renewal settings */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
521 |
c->engine_renew_list = NULL; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
522 |
c->renew_keep_length = false; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
523 |
c->engine_renew = _settings_client.gui.autorenew; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
524 |
c->engine_renew_months = _settings_client.gui.autorenew_months; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
525 |
c->engine_renew_money = _settings_client.gui.autorenew_money; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
526 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
527 |
GeneratePresidentName(c); |
0 | 528 |
|
529 |
InvalidateWindow(WC_GRAPH_LEGEND, 0); |
|
530 |
InvalidateWindow(WC_TOOLBAR_MENU, 0); |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
531 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
0 | 532 |
|
2395
d1629f64d157
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
533 |
if (is_ai && (!_networking || _network_server) && _ai.enabled) |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
534 |
AI_StartNewAI(c->index); |
2395
d1629f64d157
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
535 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
536 |
c->num_engines = CallocT<uint16>(GetEnginePoolSize()); |
4574
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4549
diff
changeset
|
537 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
538 |
return c; |
0 | 539 |
} |
540 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
541 |
void StartupCompanies() |
0 | 542 |
{ |
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
543 |
/* The AI starts like in the setting with +2 month max */ |
9413
7042a8ec3fa8
(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:
9358
diff
changeset
|
544 |
_next_competitor_start = _settings_game.difficulty.competitor_start_time * 90 * DAY_TICKS + RandomRange(60 * DAY_TICKS) + 1; |
0 | 545 |
} |
546 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
547 |
static void MaybeStartNewCompany() |
0 | 548 |
{ |
549 |
uint n; |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
550 |
Company *c; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
551 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
552 |
/* count number of competitors */ |
0 | 553 |
n = 0; |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
554 |
FOR_ALL_COMPANIES(c) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
555 |
if (c->is_ai) n++; |
2395
d1629f64d157
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
556 |
} |
0 | 557 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
558 |
/* when there's a lot of computers in game, the probability that a new one starts is lower */ |
9413
7042a8ec3fa8
(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:
9358
diff
changeset
|
559 |
if (n < (uint)_settings_game.difficulty.max_no_competitors && |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3873
diff
changeset
|
560 |
n < (_network_server ? |
9413
7042a8ec3fa8
(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:
9358
diff
changeset
|
561 |
InteractiveRandomRange(_settings_game.difficulty.max_no_competitors + 2) : |
7042a8ec3fa8
(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:
9358
diff
changeset
|
562 |
RandomRange(_settings_game.difficulty.max_no_competitors + 2) |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3873
diff
changeset
|
563 |
)) { |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3873
diff
changeset
|
564 |
/* Send a command to all clients to start up a new AI. |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3873
diff
changeset
|
565 |
* Works fine for Multiplayer and Singleplayer */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
566 |
DoCommandP(0, 1, 0, NULL, CMD_COMPANY_CTRL); |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3873
diff
changeset
|
567 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
568 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
569 |
/* The next AI starts like the difficulty setting said, with +2 month max */ |
9413
7042a8ec3fa8
(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:
9358
diff
changeset
|
570 |
_next_competitor_start = _settings_game.difficulty.competitor_start_time * 90 * DAY_TICKS + 1; |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
571 |
_next_competitor_start += _network_server ? InteractiveRandomRange(60 * DAY_TICKS) : RandomRange(60 * DAY_TICKS); |
0 | 572 |
} |
573 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
574 |
void InitializeCompanies() |
0 | 575 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
576 |
_Company_pool.CleanPool(); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
577 |
_Company_pool.AddBlockToPool(); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
578 |
_cur_company_tick_index = 0; |
0 | 579 |
} |
580 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
581 |
void OnTick_Companies() |
0 | 582 |
{ |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3873
diff
changeset
|
583 |
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
|
584 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
585 |
if (IsValidCompanyID((CompanyID)_cur_company_tick_index)) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
586 |
Company *c = GetCompany((CompanyID)_cur_company_tick_index); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
587 |
if (c->name_1 != 0) GenerateCompanyName(c); |
9659
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
588 |
|
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
589 |
if (AI_AllowNewAI() && _game_mode != GM_MENU && !--_next_competitor_start) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
590 |
MaybeStartNewCompany(); |
9659
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
591 |
} |
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
592 |
} |
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
593 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
594 |
_cur_company_tick_index = (_cur_company_tick_index + 1) % MAX_COMPANIES; |
0 | 595 |
} |
596 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
597 |
void CompaniesYearlyLoop() |
0 | 598 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
599 |
Company *c; |
0 | 600 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
601 |
/* Copy statistics */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
602 |
FOR_ALL_COMPANIES(c) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
603 |
memmove(&c->yearly_expenses[1], &c->yearly_expenses[0], sizeof(c->yearly_expenses) - sizeof(c->yearly_expenses[0])); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
604 |
memset(&c->yearly_expenses[0], 0, sizeof(c->yearly_expenses[0])); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
605 |
InvalidateWindow(WC_FINANCES, c->index); |
0 | 606 |
} |
607 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
608 |
if (_settings_client.gui.show_finances && _local_company != COMPANY_SPECTATOR) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
609 |
ShowCompanyFinances(_local_company); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
610 |
c = GetCompany(_local_company); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
611 |
if (c->num_valid_stat_ent > 5 && c->old_economy[0].performance_history < c->old_economy[4].performance_history) { |
541 | 612 |
SndPlayFx(SND_01_BAD_YEAR); |
0 | 613 |
} else { |
541 | 614 |
SndPlayFx(SND_00_GOOD_YEAR); |
0 | 615 |
} |
616 |
} |
|
617 |
} |
|
618 |
||
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
619 |
/** Change engine renewal parameters |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3393
diff
changeset
|
620 |
* @param tile unused |
6483
ae78fc3c6b20
(svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents:
6399
diff
changeset
|
621 |
* @param flags operation to perform |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
622 |
* @param p1 bits 0-3 command |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
623 |
* - p1 = 0 - change auto renew bool |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
624 |
* - p1 = 1 - change auto renew months |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
625 |
* - p1 = 2 - change auto renew money |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
626 |
* - p1 = 3 - change auto renew array |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
627 |
* - p1 = 4 - change bool, months & money all together |
2617
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
628 |
* - p1 = 5 - change renew_keep_length |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
629 |
* @param p2 value to set |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
630 |
* if p1 = 0, then: |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
631 |
* - p2 = enable engine renewal |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
632 |
* if p1 = 1, then: |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
633 |
* - p2 = months left before engine expires to replace it |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
634 |
* if p1 = 2, then |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
635 |
* - p2 = minimum amount of money available |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
636 |
* if p1 = 3, then: |
9579
7bff076f85be
(svn r13612) -Fix [FS#2104]: wrong comment of CmdSetAutoReplace. Patch by Yexo.
rubidium
parents:
9552
diff
changeset
|
637 |
* - p1 bits 16-31 = engine group |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
638 |
* - p2 bits 0-15 = old engine type |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
639 |
* - p2 bits 16-31 = new engine type |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
640 |
* if p1 = 4, then: |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
641 |
* - p1 bit 15 = enable engine renewal |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
642 |
* - p1 bits 16-31 = months left before engine expires to replace it |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
643 |
* - p2 bits 0-31 = minimum amount of money available |
2617
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
644 |
* if p1 = 5, then |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
645 |
* - p2 = enable renew_keep_length |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
646 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6841
diff
changeset
|
647 |
CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
648 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
649 |
if (!IsValidCompanyID(_current_company)) return CMD_ERROR; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
650 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
651 |
Company *c = GetCompany(_current_company); |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
652 |
switch (GB(p1, 0, 3)) { |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
653 |
case 0: |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
654 |
if (c->engine_renew == HasBit(p2, 0)) return CMD_ERROR; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
655 |
|
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
656 |
if (flags & DC_EXEC) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
657 |
c->engine_renew = HasBit(p2, 0); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
658 |
if (IsLocalCompany()) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
659 |
_settings_client.gui.autorenew = c->engine_renew; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
660 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
661 |
} |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
662 |
} |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
663 |
break; |
9013
f51d22e7c7b8
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
9011
diff
changeset
|
664 |
|
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
665 |
case 1: |
9011
151f5c9430be
(svn r12808) -Fix: enforce autorenew values range in command
glx
parents:
8969
diff
changeset
|
666 |
if (Clamp((int16)p2, -12, 12) != (int16)p2) return CMD_ERROR; |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
667 |
if (c->engine_renew_months == (int16)p2) return CMD_ERROR; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
668 |
|
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
669 |
if (flags & DC_EXEC) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
670 |
c->engine_renew_months = (int16)p2; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
671 |
if (IsLocalCompany()) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
672 |
_settings_client.gui.autorenew_months = c->engine_renew_months; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
673 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
674 |
} |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
675 |
} |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
676 |
break; |
9013
f51d22e7c7b8
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
9011
diff
changeset
|
677 |
|
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
678 |
case 2: |
9011
151f5c9430be
(svn r12808) -Fix: enforce autorenew values range in command
glx
parents:
8969
diff
changeset
|
679 |
if (ClampU(p2, 0, 2000000) != p2) return CMD_ERROR; |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
680 |
if (c->engine_renew_money == p2) return CMD_ERROR; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
681 |
|
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
682 |
if (flags & DC_EXEC) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
683 |
c->engine_renew_money = p2; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
684 |
if (IsLocalCompany()) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
685 |
_settings_client.gui.autorenew_money = c->engine_renew_money; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
686 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
687 |
} |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
688 |
} |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
689 |
break; |
9013
f51d22e7c7b8
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
9011
diff
changeset
|
690 |
|
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
691 |
case 3: { |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
692 |
EngineID old_engine_type = GB(p2, 0, 16); |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
693 |
EngineID new_engine_type = GB(p2, 16, 16); |
6648
d0ab85b643a8
(svn r9879) -Fix (r9874): global autoreplace was little broken ;)
rubidium
parents:
6643
diff
changeset
|
694 |
GroupID id_g = GB(p1, 16, 16); |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6841
diff
changeset
|
695 |
CommandCost cost; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
696 |
|
7258
8ea218277d00
(svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents:
7096
diff
changeset
|
697 |
if (!IsValidGroupID(id_g) && !IsAllGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
698 |
if (new_engine_type != INVALID_ENGINE) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
699 |
if (!CheckAutoreplaceValidity(old_engine_type, new_engine_type, _current_company)) return CMD_ERROR; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
700 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
701 |
cost = AddEngineReplacementForCompany(c, old_engine_type, new_engine_type, id_g, flags); |
2697
97fc22baf3da
(svn r3239) - Codechange: Introduce and use helper functions for engine replacement code.
peter1138
parents:
2684
diff
changeset
|
702 |
} else { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
703 |
cost = RemoveEngineReplacementForCompany(c, old_engine_type, id_g, flags); |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
704 |
} |
2811
30a1aff946db
(svn r3359) - Autoreplace GUI: When starting or stopping a replacement, redraw the replace window after the command has completed, rather than after calling the command.
peter1138
parents:
2795
diff
changeset
|
705 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
706 |
if (IsLocalCompany()) InvalidateAutoreplaceWindow(old_engine_type, id_g); |
2811
30a1aff946db
(svn r3359) - Autoreplace GUI: When starting or stopping a replacement, redraw the replace window after the command has completed, rather than after calling the command.
peter1138
parents:
2795
diff
changeset
|
707 |
|
30a1aff946db
(svn r3359) - Autoreplace GUI: When starting or stopping a replacement, redraw the replace window after the command has completed, rather than after calling the command.
peter1138
parents:
2795
diff
changeset
|
708 |
return cost; |
2755
ba133949851b
(svn r3300) Remove unreachable code - in this case some duplicate breaks
tron
parents:
2697
diff
changeset
|
709 |
} |
ba133949851b
(svn r3300) Remove unreachable code - in this case some duplicate breaks
tron
parents:
2697
diff
changeset
|
710 |
|
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
711 |
case 4: |
9011
151f5c9430be
(svn r12808) -Fix: enforce autorenew values range in command
glx
parents:
8969
diff
changeset
|
712 |
if (Clamp((int16)GB(p1, 16, 16), -12, 12) != (int16)GB(p1, 16, 16)) return CMD_ERROR; |
151f5c9430be
(svn r12808) -Fix: enforce autorenew values range in command
glx
parents:
8969
diff
changeset
|
713 |
if (ClampU(p2, 0, 2000000) != p2) return CMD_ERROR; |
9013
f51d22e7c7b8
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
9011
diff
changeset
|
714 |
|
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
715 |
if (flags & DC_EXEC) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
716 |
c->engine_renew = HasBit(p1, 15); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
717 |
c->engine_renew_months = (int16)GB(p1, 16, 16); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
718 |
c->engine_renew_money = p2; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
719 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
720 |
if (IsLocalCompany()) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
721 |
_settings_client.gui.autorenew = c->engine_renew; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
722 |
_settings_client.gui.autorenew_months = c->engine_renew_months; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
723 |
_settings_client.gui.autorenew_money = c->engine_renew_money; |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
724 |
InvalidateWindow(WC_GAME_OPTIONS, 0); |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
725 |
} |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
726 |
} |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
727 |
break; |
9013
f51d22e7c7b8
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
9011
diff
changeset
|
728 |
|
2617
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
729 |
case 5: |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
730 |
if (c->renew_keep_length == HasBit(p2, 0)) return CMD_ERROR; |
2617
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
731 |
|
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
732 |
if (flags & DC_EXEC) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
733 |
c->renew_keep_length = HasBit(p2, 0); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
734 |
if (IsLocalCompany()) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
735 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_TRAIN); |
2617
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
736 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
737 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
738 |
break; |
9013
f51d22e7c7b8
(svn r12810) -Codechange: style and useless casts in CmdSetAutoReplace()
glx
parents:
9011
diff
changeset
|
739 |
} |
2617
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2616
diff
changeset
|
740 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
741 |
return CommandCost(); |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
742 |
} |
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
743 |
|
9658
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
744 |
/** |
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
745 |
* Fill the CompanyNewsInformation struct with the required data. |
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
746 |
* @param p the current company. |
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
747 |
* @param other the other company. |
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
748 |
*/ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
749 |
void CompanyNewsInformation::FillData(const Company *c, const Company *other) |
9658
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
750 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
751 |
SetDParam(0, c->index); |
9658
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
752 |
GetString(this->company_name, STR_COMPANY_NAME, lastof(this->company_name)); |
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
753 |
|
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
754 |
if (other == NULL) { |
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
755 |
*this->other_company_name = '\0'; |
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
756 |
} else { |
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
757 |
SetDParam(0, other->index); |
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
758 |
GetString(this->other_company_name, STR_COMPANY_NAME, lastof(this->other_company_name)); |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
759 |
c = other; |
9658
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
760 |
} |
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
761 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
762 |
SetDParam(0, c->index); |
9658
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
763 |
GetString(this->president_name, STR_7058_PRESIDENT, lastof(this->president_name)); |
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
764 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
765 |
this->colour = c->colour; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
766 |
this->face = c->face; |
9658
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
767 |
|
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
768 |
} |
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
769 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
770 |
/** Control the companies: add, delete, etc. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3393
diff
changeset
|
771 |
* @param tile unused |
6483
ae78fc3c6b20
(svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents:
6399
diff
changeset
|
772 |
* @param flags operation to perform |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1787
diff
changeset
|
773 |
* @param p1 various functionality |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
774 |
* - p1 = 0 - create a new company, Which company (network) it will be is in p2 |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
775 |
* - p1 = 1 - create a new AI company |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
776 |
* - p1 = 2 - delete a company. Company is identified by p2 |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
777 |
* - p1 = 3 - merge two companies together. merge #1 with #2. Identified by p2 |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1787
diff
changeset
|
778 |
* @param p2 various functionality, dictated by p1 |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
779 |
* - p1 = 0 - ClientID of the newly created client |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
780 |
* - p1 = 2 - CompanyID of the that is getting deleted |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
781 |
* - p1 = 3 - #1 p2 = (bit 0-15) - company to merge (p2 & 0xFFFF) |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
782 |
* - #2 p2 = (bit 16-31) - company to be merged into ((p2>>16)&0xFFFF) |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
783 |
* @todo In the case of p1=0, create new company, the clientID of the new client is in parameter |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1787
diff
changeset
|
784 |
* p2. This parameter is passed in at function DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1787
diff
changeset
|
785 |
* on the server itself. First of all this is unbelievably ugly; second of all, well, |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1787
diff
changeset
|
786 |
* it IS ugly! <b>Someone fix this up :)</b> So where to fix?@n |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1787
diff
changeset
|
787 |
* @arg - network_server.c:838 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)@n |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1787
diff
changeset
|
788 |
* @arg - network_client.c:536 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) from where the map has been received |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1787
diff
changeset
|
789 |
*/ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
790 |
CommandCost CmdCompanyCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 791 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
792 |
if (flags & DC_EXEC) _current_company = OWNER_NONE; |
0 | 793 |
|
9525
dc9739a19016
(svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13
parents:
9514
diff
changeset
|
794 |
InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0); |
dc9739a19016
(svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13
parents:
9514
diff
changeset
|
795 |
|
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1787
diff
changeset
|
796 |
switch (p1) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
797 |
case 0: { /* Create a new company */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
798 |
/* This command is only executed in a multiplayer game */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
799 |
if (!_networking) return CMD_ERROR; |
9650
700a9df79460
(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:
9579
diff
changeset
|
800 |
|
700a9df79460
(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:
9579
diff
changeset
|
801 |
#ifdef ENABLE_NETWORK |
700a9df79460
(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:
9579
diff
changeset
|
802 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
803 |
/* Joining Client: |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
804 |
* _local_company: COMPANY_SPECTATOR |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
805 |
* _network_playas/cid = requested company/clientid |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
806 |
* |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
807 |
* Other client(s)/server: |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
808 |
* _local_company/_network_playas: what they play as |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
809 |
* cid = requested company/company of joining client */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
810 |
uint16 cid = p2; // ClientID |
670
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
811 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
812 |
/* Has the network client a correct ClientID? */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
813 |
if (!(flags & DC_EXEC)) return CommandCost(); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
814 |
if (cid >= MAX_CLIENT_INFO) return CommandCost(); |
690
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
688
diff
changeset
|
815 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
816 |
/* Delete multiplayer progress bar */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
817 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
818 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
819 |
Company *c = DoStartupNewCompany(false); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
820 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
821 |
/* A new company could not be created, revert to being a spectator */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
822 |
if (c == NULL) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
823 |
if (_network_server) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
824 |
NetworkClientInfo *ci = &_network_client_info[cid]; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
825 |
ci->client_playas = COMPANY_SPECTATOR; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
826 |
NetworkUpdateClientInfo(ci->client_index); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
827 |
} else if (_local_company == COMPANY_SPECTATOR) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
828 |
_network_playas = COMPANY_SPECTATOR; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
829 |
} |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
830 |
break; |
7998
9cf9f9153262
(svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents:
7954
diff
changeset
|
831 |
} |
9651
1285c0b3a4de
(svn r13718) -Fix: possible desync on the autorenew settings 20+ game years (i.e. 4.5+ hours) after a company was started.
rubidium
parents:
9650
diff
changeset
|
832 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
833 |
/* This is the joining client who wants a new company */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
834 |
if (_local_company != _network_playas && _network_playas == c->index) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
835 |
assert(_local_company == COMPANY_SPECTATOR); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
836 |
SetLocalCompany(c->index); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
837 |
if (!StrEmpty(_settings_client.network.default_company_pass)) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
838 |
char *password = _settings_client.network.default_company_pass; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
839 |
NetworkChangeCompanyPassword(1, &password); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
840 |
} |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1787
diff
changeset
|
841 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
842 |
_current_company = _local_company; |
9658
f5c4d3c04b5d
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium
parents:
9652
diff
changeset
|
843 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
844 |
/* Now that we have a new company, broadcast our autorenew settings to |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
845 |
* all clients so everything is in sync */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
846 |
NetworkSend_Command(0, |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
847 |
(_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
848 |
_settings_client.gui.autorenew_money, |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
849 |
CMD_SET_AUTOREPLACE, |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
850 |
NULL |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
851 |
); |
0 | 852 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
853 |
MarkWholeScreenDirty(); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
854 |
} |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1787
diff
changeset
|
855 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
856 |
if (_network_server) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
857 |
/* XXX - UGLY! p2 (pid) is mis-used to fetch the client-id, done at |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
858 |
* server-side in network_server.c:838, function |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
859 |
* DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
860 |
NetworkClientInfo *ci = &_network_client_info[cid]; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
861 |
ci->client_playas = c->index; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
862 |
NetworkUpdateClientInfo(ci->client_index); |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1787
diff
changeset
|
863 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
864 |
if (IsValidCompanyID(ci->client_playas)) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
865 |
CompanyID company_backup = _local_company; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
866 |
_network_company_info[c->index].months_empty = 0; |
5067
f3816e74ad32
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4944
diff
changeset
|
867 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
868 |
/* XXX - When a client joins, we automatically set its name to the |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
869 |
* client's name (for some reason). As it stands now only the server |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
870 |
* knows the client's name, so it needs to send out a "broadcast" to |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
871 |
* do this. To achieve this we send a network command. However, it |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
872 |
* uses _local_company to execute the command as. To prevent abuse |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
873 |
* (eg. only yourself can change your name/company), we 'cheat' by |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
874 |
* impersonation _local_company as the server. Not the best solution; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
875 |
* but it works. |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
876 |
* TODO: Perhaps this could be improved by when the client is ready |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
877 |
* with joining to let it send itself the command, and not the server? |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
878 |
* For example in network_client.c:534? */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
879 |
_cmd_text = ci->client_name; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
880 |
_local_company = ci->client_playas; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
881 |
NetworkSend_Command(0, 0, 0, CMD_RENAME_PRESIDENT, NULL); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
882 |
_local_company = company_backup; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
883 |
} |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
884 |
} |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
885 |
#endif /* ENABLE_NETWORK */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
886 |
} break; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
887 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
888 |
case 1: /* Make a new AI company */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
889 |
if (!(flags & DC_EXEC)) return CommandCost(); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
890 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
891 |
DoStartupNewCompany(true); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
892 |
break; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
893 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
894 |
case 2: { /* Delete a company */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
895 |
Company *c; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
896 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
897 |
if (!IsValidCompanyID((CompanyID)p2)) return CMD_ERROR; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
898 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
899 |
if (!(flags & DC_EXEC)) return CommandCost(); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
900 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
901 |
c = GetCompany((CompanyID)p2); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
902 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
903 |
/* Only allow removal of HUMAN companies */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
904 |
if (IsHumanCompany(c->index)) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
905 |
/* Delete any open window of the company */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
906 |
DeleteCompanyWindows(c->index); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
907 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
908 |
CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
909 |
cni->FillData(c); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
910 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
911 |
/* Show the bankrupt news */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
912 |
SetDParam(0, STR_705C_BANKRUPT); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
913 |
SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
914 |
SetDParamStr(2, cni->company_name); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
915 |
AddNewsItem(STR_02B6, NS_COMPANY_BANKRUPT, 0, 0, cni); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
916 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
917 |
/* Remove the company */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
918 |
ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
919 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
920 |
delete c; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
921 |
} |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
922 |
} break; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
923 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
924 |
case 3: { /* Merge a company (#1) into another company (#2), elimination company #1 */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
925 |
CompanyID cid_old = (CompanyID)GB(p2, 0, 16); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
926 |
CompanyID cid_new = (CompanyID)GB(p2, 16, 16); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
927 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
928 |
if (!IsValidCompanyID(cid_old) || !IsValidCompanyID(cid_new)) return CMD_ERROR; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
929 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
930 |
if (!(flags & DC_EXEC)) return CMD_ERROR; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
931 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
932 |
ChangeOwnershipOfCompanyItems(cid_old, cid_new); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
933 |
delete GetCompany(cid_old); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
934 |
} break; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
935 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
936 |
default: return CMD_ERROR; |
0 | 937 |
} |
938 |
||
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
939 |
return CommandCost(); |
0 | 940 |
} |
941 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
942 |
static const StringID _endgame_perf_titles[] = { |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
943 |
STR_0213_BUSINESSMAN, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
944 |
STR_0213_BUSINESSMAN, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
945 |
STR_0213_BUSINESSMAN, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
946 |
STR_0213_BUSINESSMAN, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
947 |
STR_0213_BUSINESSMAN, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
948 |
STR_0214_ENTREPRENEUR, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
949 |
STR_0214_ENTREPRENEUR, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
950 |
STR_0215_INDUSTRIALIST, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
951 |
STR_0215_INDUSTRIALIST, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
952 |
STR_0216_CAPITALIST, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
953 |
STR_0216_CAPITALIST, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
954 |
STR_0217_MAGNATE, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
955 |
STR_0217_MAGNATE, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
956 |
STR_0218_MOGUL, |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
957 |
STR_0218_MOGUL, |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
958 |
STR_0219_TYCOON_OF_THE_CENTURY |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
959 |
}; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
960 |
|
1016
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
961 |
StringID EndGameGetPerformanceTitleFromValue(uint value) |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
962 |
{ |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4023
diff
changeset
|
963 |
value = minu(value / 64, lengthof(_endgame_perf_titles) - 1); |
2613
c43a30171b62
(svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents:
2572
diff
changeset
|
964 |
|
c43a30171b62
(svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents:
2572
diff
changeset
|
965 |
return _endgame_perf_titles[value]; |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
966 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
967 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
968 |
/** Save the highscore for the company */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
969 |
int8 SaveHighScoreValue(const Company *c) |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
970 |
{ |
9413
7042a8ec3fa8
(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:
9358
diff
changeset
|
971 |
HighScore *hs = _highscore_table[_settings_game.difficulty.diff_level]; |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
972 |
uint i; |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
973 |
uint16 score = c->old_economy[0].performance_history; |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
974 |
|
1016
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
975 |
/* Exclude cheaters from the honour of being in the highscore table */ |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3873
diff
changeset
|
976 |
if (CheatHasBeenUsed()) return -1; |
1016
75b12fe9c4e1
(svn r1516) -Cheating players do not get their names added to the highscore table/file
darkvater
parents:
998
diff
changeset
|
977 |
|
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
978 |
for (i = 0; i < lengthof(_highscore_table[0]); i++) { |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
979 |
/* You are in the TOP5. Move all values one down and save us there */ |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
980 |
if (hs[i].score <= score) { |
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
981 |
/* move all elements one down starting from the replaced one */ |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
982 |
memmove(&hs[i + 1], &hs[i], sizeof(HighScore) * (lengthof(_highscore_table[0]) - i - 1)); |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
983 |
SetDParam(0, c->index); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
984 |
SetDParam(1, c->index); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4878
diff
changeset
|
985 |
GetString(hs[i].company, STR_HIGHSCORE_NAME, lastof(hs[i].company)); // get manager/company name string |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
986 |
hs[i].score = score; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
987 |
hs[i].title = EndGameGetPerformanceTitleFromValue(score); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
988 |
return i; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
989 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
990 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
991 |
|
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
992 |
return -1; // too bad; we did not make it into the top5 |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
993 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
994 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
995 |
/** Sort all companies given their performance */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
996 |
static int CDECL HighScoreSorter(const Company* const *a, const Company* const *b) |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
997 |
{ |
9526
37771bef1f79
(svn r13522) -Codechange: Replace the qsort of the highscore with one of the internal sorters
skidd13
parents:
9525
diff
changeset
|
998 |
return (*b)->old_economy[0].performance_history - (*a)->old_economy[0].performance_history; |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
999 |
} |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1000 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1001 |
/* Save the highscores in a network game when it has ended */ |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1002 |
#define LAST_HS_ITEM lengthof(_highscore_table) - 1 |
6247 | 1003 |
int8 SaveHighScoreValueNetwork() |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1004 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1005 |
const Company *c; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1006 |
const Company *cl[MAX_COMPANIES]; |
9552 | 1007 |
uint count = 0; |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1008 |
int8 company = -1; |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1009 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1010 |
/* Sort all active companies with the highest score first */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1011 |
FOR_ALL_COMPANIES(c) cl[count++] = c; |
9526
37771bef1f79
(svn r13522) -Codechange: Replace the qsort of the highscore with one of the internal sorters
skidd13
parents:
9525
diff
changeset
|
1012 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1013 |
GSortT(cl, count, &HighScoreSorter); |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1014 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1015 |
{ |
2988
26ff5a921204
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
1016 |
uint i; |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1017 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1018 |
memset(_highscore_table[LAST_HS_ITEM], 0, sizeof(_highscore_table[0])); |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1019 |
|
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1020 |
/* Copy over Top5 companies */ |
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2475
diff
changeset
|
1021 |
for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < count; i++) { |
2988
26ff5a921204
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
1022 |
HighScore* hs = &_highscore_table[LAST_HS_ITEM][i]; |
26ff5a921204
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
tron
parents:
2987
diff
changeset
|
1023 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1024 |
SetDParam(0, cl[i]->index); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1025 |
SetDParam(1, cl[i]->index); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4878
diff
changeset
|
1026 |
GetString(hs->company, STR_HIGHSCORE_NAME, lastof(hs->company)); // get manager/company name string |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1027 |
hs->score = cl[i]->old_economy[0].performance_history; |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1028 |
hs->title = EndGameGetPerformanceTitleFromValue(hs->score); |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1029 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1030 |
/* get the ranking of the local company */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1031 |
if (cl[i]->index == _local_company) company = i; |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1032 |
} |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1033 |
} |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1034 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1035 |
/* Add top5 companys to highscore table */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1036 |
return company; |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1037 |
} |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1038 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
1039 |
/** Save HighScore table to file */ |
6247 | 1040 |
void SaveToHighScore() |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1041 |
{ |
2613
c43a30171b62
(svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents:
2572
diff
changeset
|
1042 |
FILE *fp = fopen(_highscore_file, "wb"); |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1043 |
|
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1044 |
if (fp != NULL) { |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1045 |
uint i; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1046 |
HighScore *hs; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1047 |
|
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1048 |
for (i = 0; i < LAST_HS_ITEM; i++) { // don't save network highscores |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1049 |
for (hs = _highscore_table[i]; hs != endof(_highscore_table[i]); hs++) { |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1050 |
/* First character is a command character, so strlen will fail on that */ |
9114
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1051 |
byte length = min(sizeof(hs->company), StrEmpty(hs->company) ? 0 : (int)strlen(&hs->company[1]) + 1); |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1052 |
|
9114
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1053 |
if (fwrite(&length, sizeof(length), 1, fp) != 1 || // write away string length |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1054 |
fwrite(hs->company, length, 1, fp) > 1 || // Yes... could be 0 bytes too |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1055 |
fwrite(&hs->score, sizeof(hs->score), 1, fp) != 1 || |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1056 |
fwrite(" ", 2, 1, fp) != 1) { // XXX - placeholder for hs->title, not saved anymore; compatibility |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1057 |
DEBUG(misc, 1, "Could not save highscore."); |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1058 |
i = LAST_HS_ITEM; |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1059 |
break; |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1060 |
} |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1061 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1062 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1063 |
fclose(fp); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1064 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1065 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1066 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
1067 |
/** Initialize the highscore table to 0 and if any file exists, load in values */ |
6247 | 1068 |
void LoadFromHighScore() |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1069 |
{ |
2613
c43a30171b62
(svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents:
2572
diff
changeset
|
1070 |
FILE *fp = fopen(_highscore_file, "rb"); |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1071 |
|
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1072 |
memset(_highscore_table, 0, sizeof(_highscore_table)); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1073 |
|
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1074 |
if (fp != NULL) { |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1075 |
uint i; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1076 |
HighScore *hs; |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1077 |
|
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1078 |
for (i = 0; i < LAST_HS_ITEM; i++) { // don't load network highscores |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1079 |
for (hs = _highscore_table[i]; hs != endof(_highscore_table[i]); hs++) { |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1080 |
byte length; |
9114
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1081 |
if (fread(&length, sizeof(length), 1, fp) != 1 || |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1082 |
fread(hs->company, length, 1, fp) > 1 || // Yes... could be 0 bytes too |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1083 |
fread(&hs->score, sizeof(hs->score), 1, fp) != 1 || |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1084 |
fseek(fp, 2, SEEK_CUR) == -1) { // XXX - placeholder for hs->title, not saved anymore; compatibility |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1085 |
DEBUG(misc, 1, "Highscore corrupted"); |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1086 |
i = LAST_HS_ITEM; |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1087 |
break; |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1088 |
} |
032218c1235b
(svn r12974) -Codechange: check whether loading/saving highscores goes as it should be.
rubidium
parents:
9111
diff
changeset
|
1089 |
*lastof(hs->company) = '\0'; |
2613
c43a30171b62
(svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents:
2572
diff
changeset
|
1090 |
hs->title = EndGameGetPerformanceTitleFromValue(hs->score); |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1091 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1092 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1093 |
fclose(fp); |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1094 |
} |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1017
diff
changeset
|
1095 |
|
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
983
diff
changeset
|
1096 |
/* Initialize end of game variable (when to show highscore chart) */ |
9413
7042a8ec3fa8
(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:
9358
diff
changeset
|
1097 |
_settings_client.gui.ending_year = 2051; |
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1098 |
} |
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
717
diff
changeset
|
1099 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1100 |
/* Save/load of companies */ |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1101 |
static const SaveLoad _company_desc[] = { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1102 |
SLE_VAR(Company, name_2, SLE_UINT32), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1103 |
SLE_VAR(Company, name_1, SLE_STRINGID), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1104 |
SLE_CONDSTR(Company, name, SLE_STR, 0, 84, SL_MAX_VERSION), |
0 | 1105 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1106 |
SLE_VAR(Company, president_name_1, SLE_UINT16), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1107 |
SLE_VAR(Company, president_name_2, SLE_UINT32), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1108 |
SLE_CONDSTR(Company, president_name, SLE_STR, 0, 84, SL_MAX_VERSION), |
0 | 1109 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1110 |
SLE_VAR(Company, face, SLE_UINT32), |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
1111 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
1112 |
/* money was changed to a 64 bit field in savegame version 1. */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1113 |
SLE_CONDVAR(Company, money, SLE_VAR_I64 | SLE_FILE_I32, 0, 0), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1114 |
SLE_CONDVAR(Company, money, SLE_INT64, 1, SL_MAX_VERSION), |
0 | 1115 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1116 |
SLE_CONDVAR(Company, current_loan, SLE_VAR_I64 | SLE_FILE_I32, 0, 64), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1117 |
SLE_CONDVAR(Company, current_loan, SLE_INT64, 65, SL_MAX_VERSION), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1118 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1119 |
SLE_VAR(Company, colour, SLE_UINT8), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1120 |
SLE_VAR(Company, money_fraction, SLE_UINT8), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1121 |
SLE_CONDVAR(Company, avail_railtypes, SLE_UINT8, 0, 57), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1122 |
SLE_VAR(Company, block_preview, SLE_UINT8), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1123 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1124 |
SLE_CONDVAR(Company, cargo_types, SLE_FILE_U16 | SLE_VAR_U32, 0, 93), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1125 |
SLE_CONDVAR(Company, cargo_types, SLE_UINT32, 94, SL_MAX_VERSION), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1126 |
SLE_CONDVAR(Company, location_of_HQ, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1127 |
SLE_CONDVAR(Company, location_of_HQ, SLE_UINT32, 6, SL_MAX_VERSION), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1128 |
SLE_CONDVAR(Company, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1129 |
SLE_CONDVAR(Company, last_build_coordinate, SLE_UINT32, 6, SL_MAX_VERSION), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1130 |
SLE_CONDVAR(Company, inaugurated_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1131 |
SLE_CONDVAR(Company, inaugurated_year, SLE_INT32, 31, SL_MAX_VERSION), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1132 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1133 |
SLE_ARR(Company, share_owners, SLE_UINT8, 4), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1134 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1135 |
SLE_VAR(Company, num_valid_stat_ent, SLE_UINT8), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1136 |
|
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1137 |
SLE_VAR(Company, quarters_of_bankrupcy, SLE_UINT8), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1138 |
SLE_VAR(Company, bankrupt_asked, SLE_UINT8), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1139 |
SLE_VAR(Company, bankrupt_timeout, SLE_INT16), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1140 |
SLE_CONDVAR(Company, bankrupt_value, SLE_VAR_I64 | SLE_FILE_I32, 0, 64), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1141 |
SLE_CONDVAR(Company, bankrupt_value, SLE_INT64, 65, SL_MAX_VERSION), |
0 | 1142 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
1143 |
/* yearly expenses was changed to 64-bit in savegame version 2. */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1144 |
SLE_CONDARR(Company, yearly_expenses, SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, 0, 1), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1145 |
SLE_CONDARR(Company, yearly_expenses, SLE_INT64, 3 * 13, 2, SL_MAX_VERSION), |
0 | 1146 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1147 |
SLE_CONDVAR(Company, is_ai, SLE_BOOL, 2, SL_MAX_VERSION), |
9659
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9658
diff
changeset
|
1148 |
SLE_CONDNULL(1, 4, 99), |
0 | 1149 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
1150 |
/* Engine renewal settings */ |
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3047
diff
changeset
|
1151 |
SLE_CONDNULL(512, 16, 18), |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1152 |
SLE_CONDREF(Company, engine_renew_list, REF_ENGINE_RENEWS, 19, SL_MAX_VERSION), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1153 |
SLE_CONDVAR(Company, engine_renew, SLE_BOOL, 16, SL_MAX_VERSION), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1154 |
SLE_CONDVAR(Company, engine_renew_months, SLE_INT16, 16, SL_MAX_VERSION), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1155 |
SLE_CONDVAR(Company, engine_renew_money, SLE_UINT32, 16, SL_MAX_VERSION), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1156 |
SLE_CONDVAR(Company, renew_keep_length, SLE_BOOL, 2, SL_MAX_VERSION), // added with 16.1, but was blank since 2 |
2293
b48192aec903
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2204
diff
changeset
|
1157 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
1158 |
/* reserve extra space in savegame here. (currently 63 bytes) */ |
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3047
diff
changeset
|
1159 |
SLE_CONDNULL(63, 2, SL_MAX_VERSION), |
0 | 1160 |
|
1161 |
SLE_END() |
|
1162 |
}; |
|
1163 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1164 |
static const SaveLoad _company_economy_desc[] = { |
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
1165 |
/* these were changed to 64-bit in savegame format 2 */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1166 |
SLE_CONDVAR(CompanyEconomyEntry, income, SLE_FILE_I32 | SLE_VAR_I64, 0, 1), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1167 |
SLE_CONDVAR(CompanyEconomyEntry, income, SLE_INT64, 2, SL_MAX_VERSION), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1168 |
SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_FILE_I32 | SLE_VAR_I64, 0, 1), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1169 |
SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_INT64, 2, SL_MAX_VERSION), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1170 |
SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_FILE_I32 | SLE_VAR_I64, 0, 1), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1171 |
SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_INT64, 2, SL_MAX_VERSION), |
0 | 1172 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1173 |
SLE_VAR(CompanyEconomyEntry, delivered_cargo, SLE_INT32), |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1174 |
SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32), |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
165
diff
changeset
|
1175 |
|
0 | 1176 |
SLE_END() |
1177 |
}; |
|
1178 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1179 |
static const SaveLoad _company_livery_desc[] = { |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4580
diff
changeset
|
1180 |
SLE_CONDVAR(Livery, in_use, SLE_BOOL, 34, SL_MAX_VERSION), |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4580
diff
changeset
|
1181 |
SLE_CONDVAR(Livery, colour1, SLE_UINT8, 34, SL_MAX_VERSION), |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4580
diff
changeset
|
1182 |
SLE_CONDVAR(Livery, colour2, SLE_UINT8, 34, SL_MAX_VERSION), |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4580
diff
changeset
|
1183 |
SLE_END() |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4580
diff
changeset
|
1184 |
}; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4580
diff
changeset
|
1185 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1186 |
static void SaveLoad_PLYR(Company *c) |
2952 | 1187 |
{ |
0 | 1188 |
int i; |
1189 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1190 |
SlObject(c, _company_desc); |
0 | 1191 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
1192 |
/* Write AI? */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1193 |
if (!IsHumanCompany(c->index)) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1194 |
SaveLoad_AI(c->index); |
0 | 1195 |
} |
1196 |
||
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
1197 |
/* Write economy */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1198 |
SlObject(&c->cur_economy, _company_economy_desc); |
0 | 1199 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
1200 |
/* Write old economy entries. */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1201 |
for (i = 0; i < c->num_valid_stat_ent; i++) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1202 |
SlObject(&c->old_economy[i], _company_economy_desc); |
0 | 1203 |
} |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4580
diff
changeset
|
1204 |
|
6352
938ab8f48e5d
(svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents:
6346
diff
changeset
|
1205 |
/* Write each livery entry. */ |
8309
5d3e63cd70e0
(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:
8276
diff
changeset
|
1206 |
int num_liveries = CheckSavegameVersion(63) ? LS_END - 4 : (CheckSavegameVersion(85) ? LS_END - 2: LS_END); |
6724
4f404dfe9752
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
6685
diff
changeset
|
1207 |
for (i = 0; i < num_liveries; i++) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1208 |
SlObject(&c->livery[i], _company_livery_desc); |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4580
diff
changeset
|
1209 |
} |
6724
4f404dfe9752
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
6685
diff
changeset
|
1210 |
|
8309
5d3e63cd70e0
(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:
8276
diff
changeset
|
1211 |
if (num_liveries < LS_END) { |
5d3e63cd70e0
(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:
8276
diff
changeset
|
1212 |
/* We want to insert some liveries somewhere in between. This means some have to be moved. */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1213 |
memmove(&c->livery[LS_FREIGHT_WAGON], &c->livery[LS_PASSENGER_WAGON_MONORAIL], (LS_END - LS_FREIGHT_WAGON) * sizeof(c->livery[0])); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1214 |
c->livery[LS_PASSENGER_WAGON_MONORAIL] = c->livery[LS_MONORAIL]; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1215 |
c->livery[LS_PASSENGER_WAGON_MAGLEV] = c->livery[LS_MAGLEV]; |
8309
5d3e63cd70e0
(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:
8276
diff
changeset
|
1216 |
} |
5d3e63cd70e0
(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:
8276
diff
changeset
|
1217 |
|
5d3e63cd70e0
(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:
8276
diff
changeset
|
1218 |
if (num_liveries == LS_END - 4) { |
6724
4f404dfe9752
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
6685
diff
changeset
|
1219 |
/* Copy bus/truck liveries over to trams */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1220 |
c->livery[LS_PASSENGER_TRAM] = c->livery[LS_BUS]; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1221 |
c->livery[LS_FREIGHT_TRAM] = c->livery[LS_TRUCK]; |
6724
4f404dfe9752
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
6685
diff
changeset
|
1222 |
} |
0 | 1223 |
} |
1224 |
||
6247 | 1225 |
static void Save_PLYR() |
0 | 1226 |
{ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1227 |
Company *c; |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1228 |
FOR_ALL_COMPANIES(c) { |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1229 |
SlSetArrayIndex(c->index); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1230 |
SlAutolength((AutolengthProc*)SaveLoad_PLYR, c); |
0 | 1231 |
} |
1232 |
} |
|
1233 |
||
6247 | 1234 |
static void Load_PLYR() |
0 | 1235 |
{ |
1236 |
int index; |
|
1237 |
while ((index = SlIterateArray()) != -1) { |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1238 |
Company *c = new (index) Company(); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1239 |
SaveLoad_PLYR(c); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1240 |
_company_colours[index] = c->colour; |
2395
d1629f64d157
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
1241 |
|
d1629f64d157
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2381
diff
changeset
|
1242 |
/* This is needed so an AI is attached to a loaded AI */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1243 |
if (c->is_ai && (!_networking || _network_server) && _ai.enabled) { |
9514
a8a8210139a6
(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:
9428
diff
changeset
|
1244 |
/* Clear the memory of the new AI, otherwise we might be doing wrong things. */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1245 |
memset(&_companies_ainew[index], 0, sizeof(CompanyAiNew)); |
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1246 |
AI_StartNewAI(c->index); |
9514
a8a8210139a6
(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:
9428
diff
changeset
|
1247 |
} |
0 | 1248 |
} |
1249 |
} |
|
1250 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
10151
diff
changeset
|
1251 |
extern const ChunkHandler _company_chunk_handlers[] = { |
0 | 1252 |
{ 'PLYR', Save_PLYR, Load_PLYR, CH_ARRAY | CH_LAST}, |
1253 |
}; |