author | celestar |
Mon, 19 Mar 2007 12:38:16 +0000 | |
branch | gamebalance |
changeset 9895 | 7bd07f43b0e3 |
parent 6535 | 1a5437f36d78 |
child 9909 | dce9a6923bb7 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
3 |
/** @file engine.cpp */ |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1883
diff
changeset
|
6 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1197
diff
changeset
|
7 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
8 |
#include "functions.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
485
diff
changeset
|
9 |
#include "table/strings.h" |
0 | 10 |
#include "engine.h" |
1009
a7ccb8e39cbc
(svn r1508) Remove duplicate declarations and include proper headers where necessary
tron
parents:
964
diff
changeset
|
11 |
#include "gfx.h" |
0 | 12 |
#include "player.h" |
13 |
#include "command.h" |
|
14 |
#include "vehicle.h" |
|
15 |
#include "news.h" |
|
16 |
#include "saveload.h" |
|
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2147
diff
changeset
|
17 |
#include "variables.h" |
2708
9d1a8d5dc3ea
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
18 |
#include "train.h" |
6105
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6091
diff
changeset
|
19 |
#include "aircraft.h" |
3866
113de2b20059
(svn r4902) Newgrf : Introduction of the newgrf_cargo files.
belugas
parents:
3865
diff
changeset
|
20 |
#include "newgrf_cargo.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4171
diff
changeset
|
21 |
#include "date.h" |
4322
0bee6d9bc452
(svn r5975) -Cleanup: use ORIGINAL_BASE_YEAR & ORIGINAL_MAX_YEAR where the functions really depend on the original date format.
rubidium
parents:
4300
diff
changeset
|
22 |
#include "table/engines.h" |
0 | 23 |
|
2763 | 24 |
EngineInfo _engine_info[TOTAL_NUM_ENGINES]; |
25 |
RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES]; |
|
26 |
ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES]; |
|
27 |
AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES]; |
|
28 |
RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES]; |
|
29 |
||
0 | 30 |
enum { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
31 |
YEAR_ENGINE_AGING_STOPS = 2050, |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
32 |
}; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
33 |
|
0 | 34 |
|
2477
d454d5152386
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2469
diff
changeset
|
35 |
void ShowEnginePreviewWindow(EngineID engine); |
0 | 36 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
37 |
void DeleteCustomEngineNames() |
0 | 38 |
{ |
39 |
uint i; |
|
40 |
StringID old; |
|
41 |
||
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
42 |
for (i = 0; i != TOTAL_NUM_ENGINES; i++) { |
0 | 43 |
old = _engine_name_strings[i]; |
44 |
_engine_name_strings[i] = i + STR_8000_KIRBY_PAUL_TANK_STEAM; |
|
45 |
DeleteName(old); |
|
46 |
} |
|
47 |
||
48 |
_vehicle_design_names &= ~1; |
|
49 |
} |
|
50 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
51 |
void LoadCustomEngineNames() |
0 | 52 |
{ |
4432
33631ac88c40
(svn r6195) -Codechange: do not use '//' in '/* ... */' style comments and '/*' or '*/' in '//' style comments.
rubidium
parents:
4384
diff
changeset
|
53 |
/* XXX: not done */ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5216
diff
changeset
|
54 |
DEBUG(misc, 1, "LoadCustomEngineNames: not done"); |
0 | 55 |
} |
56 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
57 |
static void SetupEngineNames() |
0 | 58 |
{ |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
59 |
StringID *name; |
0 | 60 |
|
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
61 |
for (name = _engine_name_strings; name != endof(_engine_name_strings); name++) |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
62 |
*name = STR_SV_EMPTY; |
0 | 63 |
|
64 |
DeleteCustomEngineNames(); |
|
65 |
LoadCustomEngineNames(); |
|
66 |
} |
|
67 |
||
68 |
||
69 |
static void CalcEngineReliability(Engine *e) |
|
70 |
{ |
|
71 |
uint age = e->age; |
|
72 |
||
73 |
if (age < e->duration_phase_1) { |
|
74 |
uint start = e->reliability_start; |
|
75 |
e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start; |
|
4767
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
76 |
} else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _patches.never_expire_vehicles) { |
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
77 |
/* We are at the peak of this engines life. It will have max reliability. |
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
78 |
* This is also true if the engines never expire. They will not go bad over time */ |
0 | 79 |
e->reliability = e->reliability_max; |
80 |
} else if ((age -= e->duration_phase_2) < e->duration_phase_3) { |
|
81 |
uint max = e->reliability_max; |
|
82 |
e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max; |
|
83 |
} else { |
|
4767
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
84 |
/* time's up for this engine. |
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
85 |
* We will now completely retire this design */ |
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
86 |
e->player_avail = 0; |
0 | 87 |
e->reliability = e->reliability_final; |
6195
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6119
diff
changeset
|
88 |
/* Kick this engine out of the lists */ |
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6119
diff
changeset
|
89 |
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
0 | 90 |
} |
4767
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
91 |
InvalidateWindowClasses(WC_BUILD_VEHICLE); // Update to show the new reliability |
6195
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6119
diff
changeset
|
92 |
InvalidateWindowClasses(WC_REPLACE_VEHICLE); |
0 | 93 |
} |
94 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
95 |
void AddTypeToEngines() |
842 | 96 |
{ |
2242
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
97 |
Engine* e = _engines; |
842 | 98 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
99 |
do e->type = VEH_TRAIN; while (++e < &_engines[ROAD_ENGINES_INDEX]); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
100 |
do e->type = VEH_ROAD; while (++e < &_engines[SHIP_ENGINES_INDEX]); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
101 |
do e->type = VEH_SHIP; while (++e < &_engines[AIRCRAFT_ENGINES_INDEX]); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
102 |
do e->type = VEH_AIRCRAFT; while (++e < &_engines[TOTAL_NUM_ENGINES]); |
842 | 103 |
} |
104 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
105 |
void StartupEngines() |
0 | 106 |
{ |
107 |
Engine *e; |
|
108 |
const EngineInfo *ei; |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
109 |
/* Aging of vehicles stops, so account for that when starting late */ |
4322
0bee6d9bc452
(svn r5975) -Cleanup: use ORIGINAL_BASE_YEAR & ORIGINAL_MAX_YEAR where the functions really depend on the original date format.
rubidium
parents:
4300
diff
changeset
|
110 |
const Date aging_date = min(_date, ConvertYMDToDate(YEAR_ENGINE_AGING_STOPS, 0, 1)); |
0 | 111 |
|
112 |
SetupEngineNames(); |
|
113 |
||
2242
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
114 |
for (e = _engines, ei = _engine_info; e != endof(_engines); e++, ei++) { |
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
115 |
uint32 r; |
0 | 116 |
|
117 |
e->age = 0; |
|
118 |
e->flags = 0; |
|
119 |
e->player_avail = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
120 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
121 |
/* The magic value of 729 days below comes from the NewGRF spec. If the |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
122 |
* base intro date is before 1922 then the random number of days is not |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
123 |
* added. */ |
0 | 124 |
r = Random(); |
4297
47ce9665b4af
(svn r5934) -Cleanup: forgot some conversions to Year and to Date
rubidium
parents:
4293
diff
changeset
|
125 |
e->intro_date = ei->base_intro <= ConvertYMDToDate(1922, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro; |
0 | 126 |
if (e->intro_date <= _date) { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
127 |
e->age = (aging_date - e->intro_date) >> 5; |
0 | 128 |
e->player_avail = (byte)-1; |
129 |
e->flags |= ENGINE_AVAILABLE; |
|
130 |
} |
|
131 |
||
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
1988
diff
changeset
|
132 |
e->reliability_start = GB(r, 16, 14) + 0x7AE0; |
0 | 133 |
r = Random(); |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
1988
diff
changeset
|
134 |
e->reliability_max = GB(r, 0, 14) + 0xBFFF; |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
1988
diff
changeset
|
135 |
e->reliability_final = GB(r, 16, 14) + 0x3FFF; |
0 | 136 |
|
137 |
r = Random(); |
|
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
1988
diff
changeset
|
138 |
e->duration_phase_1 = GB(r, 0, 5) + 7; |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
1988
diff
changeset
|
139 |
e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96; |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
1988
diff
changeset
|
140 |
e->duration_phase_3 = GB(r, 9, 7) + 120; |
0 | 141 |
|
142 |
e->reliability_spd_dec = (ei->unk2&0x7F) << 2; |
|
143 |
||
144 |
/* my invented flag for something that is a wagon */ |
|
145 |
if (ei->unk2 & 0x80) { |
|
146 |
e->age = 0xFFFF; |
|
147 |
} else { |
|
148 |
CalcEngineReliability(e); |
|
149 |
} |
|
150 |
||
151 |
e->lifelength = ei->lifelength + _patches.extend_vehicle_life; |
|
152 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
153 |
/* prevent certain engines from ever appearing. */ |
2530
b8d5a5284024
(svn r3059) Use bitfields to encode railtype and climates of engines instead of manual shifting/anding
tron
parents:
2491
diff
changeset
|
154 |
if (!HASBIT(ei->climates, _opt.landscape)) { |
0 | 155 |
e->flags |= ENGINE_AVAILABLE; |
156 |
e->player_avail = 0; |
|
157 |
} |
|
915 | 158 |
|
819
02e9296ccdca
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
159 |
/* This sets up type for the engine |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4432
diff
changeset
|
160 |
* It is needed if you want to ask the engine what type it is |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4432
diff
changeset
|
161 |
* It should hopefully be the same as when you ask a vehicle what it is |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4432
diff
changeset
|
162 |
* but using this, you can ask what type an engine number is |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4432
diff
changeset
|
163 |
* even if it is not a vehicle (yet)*/ |
0 | 164 |
} |
165 |
} |
|
166 |
||
6074 | 167 |
static void AcceptEnginePreview(EngineID eid, PlayerID player) |
0 | 168 |
{ |
6074 | 169 |
Engine *e = GetEngine(eid); |
0 | 170 |
|
171 |
SETBIT(e->player_avail, player); |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
172 |
if (e->type == VEH_TRAIN) { |
6074 | 173 |
const RailVehicleInfo *rvi = RailVehInfo(eid); |
174 |
Player *p = GetPlayer(player); |
|
175 |
||
176 |
assert(rvi->railtype < RAILTYPE_END); |
|
177 |
SETBIT(p->avail_railtypes, rvi->railtype); |
|
178 |
} |
|
0 | 179 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
180 |
e->preview_player = INVALID_PLAYER; |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4549
diff
changeset
|
181 |
if (player == _local_player) { |
6195
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6119
diff
changeset
|
182 |
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4549
diff
changeset
|
183 |
} |
0 | 184 |
} |
185 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
186 |
static PlayerID GetBestPlayer(PlayerID pp) |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
187 |
{ |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
188 |
const Player *p; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
189 |
int32 best_hist; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
190 |
PlayerID best_player; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
191 |
uint mask = 0; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
192 |
|
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
193 |
do { |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
194 |
best_hist = -1; |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
195 |
best_player = PLAYER_SPECTATOR; |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
196 |
FOR_ALL_PLAYERS(p) { |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
197 |
if (p->is_active && p->block_preview == 0 && !HASBIT(mask, p->index) && |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
198 |
p->old_economy[0].performance_history > best_hist) { |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
199 |
best_hist = p->old_economy[0].performance_history; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
200 |
best_player = p->index; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
201 |
} |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
202 |
} |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
203 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
204 |
if (best_player == PLAYER_SPECTATOR) return PLAYER_SPECTATOR; |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
205 |
|
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
206 |
SETBIT(mask, best_player); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
207 |
} while (pp--, pp != 0); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
208 |
|
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
209 |
return best_player; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
210 |
} |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
211 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
212 |
void EnginesDailyLoop() |
0 | 213 |
{ |
2477
d454d5152386
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2469
diff
changeset
|
214 |
EngineID i; |
0 | 215 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
216 |
if (_cur_year >= YEAR_ENGINE_AGING_STOPS) return; |
0 | 217 |
|
2242
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
218 |
for (i = 0; i != lengthof(_engines); i++) { |
4171 | 219 |
Engine *e = &_engines[i]; |
2242
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
220 |
|
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
221 |
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) { |
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
222 |
if (e->flags & ENGINE_OFFER_WINDOW_OPEN) { |
740
c1d06749846b
(svn r1196) -Fix: Preview Vehicle had a small glitch. Fixed now.
truelight
parents:
555
diff
changeset
|
223 |
if (e->preview_player != 0xFF && !--e->preview_wait) { |
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
224 |
e->flags &= ~ENGINE_OFFER_WINDOW_OPEN; |
0 | 225 |
DeleteWindowById(WC_ENGINE_PREVIEW, i); |
226 |
e->preview_player++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
227 |
} |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3866
diff
changeset
|
228 |
} else if (e->preview_player != 0xFF) { |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
229 |
PlayerID best_player = GetBestPlayer(e->preview_player); |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
230 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
231 |
if (best_player == PLAYER_SPECTATOR) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
232 |
e->preview_player = INVALID_PLAYER; |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
233 |
continue; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
234 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
235 |
|
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4792
diff
changeset
|
236 |
if (!IsHumanPlayer(best_player)) { |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
237 |
/* XXX - TTDBUG: TTD has a bug here ???? */ |
6074 | 238 |
AcceptEnginePreview(i, best_player); |
0 | 239 |
} else { |
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
240 |
e->flags |= ENGINE_OFFER_WINDOW_OPEN; |
0 | 241 |
e->preview_wait = 20; |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4792
diff
changeset
|
242 |
if (IsInteractivePlayer(best_player)) ShowEnginePreviewWindow(i); |
0 | 243 |
} |
244 |
} |
|
245 |
} |
|
246 |
} |
|
247 |
} |
|
248 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
249 |
/** Accept an engine prototype. XXX - it is possible that the top-player |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
250 |
* changes while you are waiting to accept the offer? Then it becomes invalid |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
251 |
* @param tile unused |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
252 |
* @param p1 engine-prototype offered |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
253 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
254 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
255 |
int32 CmdWantEnginePreview(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 256 |
{ |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
257 |
Engine *e; |
2951 | 258 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
259 |
if (!IsEngineIndex(p1)) return CMD_ERROR; |
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1908
diff
changeset
|
260 |
e = GetEngine(p1); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
261 |
if (GetBestPlayer(e->preview_player) != _current_player) return CMD_ERROR; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
262 |
|
6074 | 263 |
if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_player); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
264 |
|
0 | 265 |
return 0; |
266 |
} |
|
267 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
268 |
/* Determine if an engine type is a wagon (and not a loco) */ |
2477
d454d5152386
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2469
diff
changeset
|
269 |
static bool IsWagon(EngineID index) |
257
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
270 |
{ |
6119
b47985557d1e
(svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents:
6105
diff
changeset
|
271 |
return index < NUM_TRAIN_ENGINES && RailVehInfo(index)->railveh_type == RAILVEH_WAGON; |
257
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
272 |
} |
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
273 |
|
410 | 274 |
static void NewVehicleAvailable(Engine *e) |
0 | 275 |
{ |
276 |
Vehicle *v; |
|
277 |
Player *p; |
|
2477
d454d5152386
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2469
diff
changeset
|
278 |
EngineID index = e - _engines; |
0 | 279 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
280 |
/* In case the player didn't build the vehicle during the intro period, |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
281 |
* prevent that player from getting future intro periods for a while. */ |
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
282 |
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) { |
0 | 283 |
FOR_ALL_PLAYERS(p) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
284 |
uint block_preview = p->block_preview; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
285 |
|
2639 | 286 |
if (!HASBIT(e->player_avail, p->index)) continue; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
287 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
288 |
/* We assume the user did NOT build it.. prove me wrong ;) */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
289 |
p->block_preview = 20; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
290 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
291 |
FOR_ALL_VEHICLES(v) { |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
292 |
if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP || |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
293 |
(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
294 |
if (v->owner == p->index && v->engine_type == index) { |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
295 |
/* The user did prove me wrong, so restore old value */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
296 |
p->block_preview = block_preview; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
297 |
break; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
298 |
} |
0 | 299 |
} |
300 |
} |
|
301 |
} |
|
302 |
} |
|
303 |
||
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
304 |
e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE; |
6195
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6119
diff
changeset
|
305 |
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
306 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
307 |
/* Now available for all players */ |
0 | 308 |
e->player_avail = (byte)-1; |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
309 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
310 |
/* Do not introduce new rail wagons */ |
2639 | 311 |
if (IsWagon(index)) return; |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
312 |
|
6074 | 313 |
if (index < NUM_TRAIN_ENGINES) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
314 |
/* maybe make another rail type available */ |
6074 | 315 |
RailType railtype = RailVehInfo(index)->railtype; |
316 |
assert(railtype < RAILTYPE_END); |
|
317 |
FOR_ALL_PLAYERS(p) { |
|
318 |
if (p->is_active) SETBIT(p->avail_railtypes, railtype); |
|
2147
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
2140
diff
changeset
|
319 |
} |
0 | 320 |
} |
6535
1a5437f36d78
(svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents:
6500
diff
changeset
|
321 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_VEHICLEAVAIL), 0, 0); |
0 | 322 |
} |
323 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
324 |
void EnginesMonthlyLoop() |
0 | 325 |
{ |
326 |
Engine *e; |
|
327 |
||
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
328 |
if (_cur_year < YEAR_ENGINE_AGING_STOPS) { |
2242
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
329 |
for (e = _engines; e != endof(_engines); e++) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
330 |
/* Age the vehicle */ |
2242
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
331 |
if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) { |
0 | 332 |
e->age++; |
333 |
CalcEngineReliability(e); |
|
334 |
} |
|
335 |
||
2990
352b4590ee1c
(svn r3565) - Fix: On loading a game, GetPlayerRailtypes() didn't account for the fact that vehicles are introduced a year after their introduction date. This will also relieve possible (rare) network desyncs.
peter1138
parents:
2962
diff
changeset
|
336 |
if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + 365)) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
337 |
/* Introduce it to all players */ |
0 | 338 |
NewVehicleAvailable(e); |
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
339 |
} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
340 |
/* Introduction date has passed.. show introducing dialog to one player. */ |
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
341 |
e->flags |= ENGINE_EXCLUSIVE_PREVIEW; |
257
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
342 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
343 |
/* Do not introduce new rail wagons */ |
964
4bd472539a4e
(svn r1456) Simplify isWagon(), make it static and give it a canonical name (IsWagon)
tron
parents:
938
diff
changeset
|
344 |
if (!IsWagon(e - _engines)) |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
345 |
e->preview_player = (PlayerID)1; // Give to the player with the highest rating. |
0 | 346 |
} |
347 |
} |
|
348 |
} |
|
349 |
} |
|
350 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
351 |
/** Rename an engine. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
352 |
* @param tile unused |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
353 |
* @param p1 engine ID to rename |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
354 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
355 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
356 |
int32 CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 357 |
{ |
358 |
StringID str; |
|
359 |
||
1840
c181d5cb4ffe
(svn r2345) - Fix: Don't allow stuff to be renamed to nothing if we don't support it. Only valid ones are signs (delete) and waypoints (rename to default).
Darkvater
parents:
1820
diff
changeset
|
360 |
if (!IsEngineIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR; |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
361 |
|
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
362 |
str = AllocateNameUnique(_cmd_text, 0); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
363 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
364 |
|
0 | 365 |
if (flags & DC_EXEC) { |
366 |
StringID old_str = _engine_name_strings[p1]; |
|
367 |
_engine_name_strings[p1] = str; |
|
368 |
DeleteName(old_str); |
|
369 |
_vehicle_design_names |= 3; |
|
370 |
MarkWholeScreenDirty(); |
|
371 |
} else { |
|
372 |
DeleteName(str); |
|
373 |
} |
|
374 |
||
375 |
return 0; |
|
376 |
} |
|
377 |
||
378 |
||
2848 | 379 |
/* |
380 |
* returns true if an engine is valid, of the specified type, and buildable by |
|
5215
439d5ca71311
(svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents:
5037
diff
changeset
|
381 |
* the given player, false otherwise |
2848 | 382 |
* |
383 |
* engine = index of the engine to check |
|
384 |
* type = the type the engine should be of (VEH_xxx) |
|
5215
439d5ca71311
(svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents:
5037
diff
changeset
|
385 |
* player = index of the player |
2848 | 386 |
*/ |
5215
439d5ca71311
(svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents:
5037
diff
changeset
|
387 |
bool IsEngineBuildable(EngineID engine, byte type, PlayerID player) |
2848 | 388 |
{ |
389 |
const Engine *e; |
|
390 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
391 |
/* check if it's an engine that is in the engine array */ |
2848 | 392 |
if (!IsEngineIndex(engine)) return false; |
393 |
||
394 |
e = GetEngine(engine); |
|
395 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
396 |
/* check if it's an engine of specified type */ |
2848 | 397 |
if (e->type != type) return false; |
398 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
399 |
/* check if it's available */ |
5215
439d5ca71311
(svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents:
5037
diff
changeset
|
400 |
if (!HASBIT(e->player_avail, player)) return false; |
2848 | 401 |
|
402 |
return true; |
|
403 |
} |
|
404 |
||
405 |
/************************************************************************ |
|
406 |
* Engine Replacement stuff |
|
407 |
************************************************************************/ |
|
408 |
||
4974
c962d0622bc1
(svn r6977) Use the pool macros for the EngineRenew pool
tron
parents:
4848
diff
changeset
|
409 |
static void EngineRenewPoolNewBlock(uint start_item); |
2848 | 410 |
|
5216
d581e4db95b6
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
5215
diff
changeset
|
411 |
DEFINE_OLD_POOL(EngineRenew, EngineRenew, EngineRenewPoolNewBlock, NULL) |
2848 | 412 |
|
413 |
static void EngineRenewPoolNewBlock(uint start_item) |
|
414 |
{ |
|
415 |
EngineRenew *er; |
|
416 |
||
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
417 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
418 |
* TODO - This is just a temporary stage, this will be removed. */ |
4974
c962d0622bc1
(svn r6977) Use the pool macros for the EngineRenew pool
tron
parents:
4848
diff
changeset
|
419 |
for (er = GetEngineRenew(start_item); er != NULL; er = (er->index + 1U < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1U) : NULL) { |
2848 | 420 |
er->index = start_item++; |
421 |
er->from = INVALID_ENGINE; |
|
422 |
} |
|
423 |
} |
|
424 |
||
425 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
426 |
static EngineRenew *AllocateEngineRenew() |
2848 | 427 |
{ |
428 |
EngineRenew *er; |
|
429 |
||
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
430 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
431 |
* TODO - This is just a temporary stage, this will be removed. */ |
4974
c962d0622bc1
(svn r6977) Use the pool macros for the EngineRenew pool
tron
parents:
4848
diff
changeset
|
432 |
for (er = GetEngineRenew(0); er != NULL; er = (er->index + 1U < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1U) : NULL) { |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
433 |
if (IsValidEngineRenew(er)) continue; |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
434 |
|
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
435 |
er->to = INVALID_ENGINE; |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
436 |
er->next = NULL; |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
437 |
return er; |
2848 | 438 |
} |
439 |
||
440 |
/* Check if we can add a block to the pool */ |
|
4974
c962d0622bc1
(svn r6977) Use the pool macros for the EngineRenew pool
tron
parents:
4848
diff
changeset
|
441 |
if (AddBlockToPool(&_EngineRenew_pool)) return AllocateEngineRenew(); |
2848 | 442 |
|
443 |
return NULL; |
|
444 |
} |
|
445 |
||
446 |
/** |
|
447 |
* Retrieves the EngineRenew that specifies the replacement of the given |
|
448 |
* engine type from the given renewlist */ |
|
449 |
static EngineRenew *GetEngineReplacement(EngineRenewList erl, EngineID engine) |
|
450 |
{ |
|
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
451 |
EngineRenew *er = (EngineRenew *)erl; |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
452 |
|
2848 | 453 |
while (er) { |
454 |
if (er->from == engine) return er; |
|
455 |
er = er->next; |
|
456 |
} |
|
457 |
return NULL; |
|
458 |
} |
|
459 |
||
4171 | 460 |
void RemoveAllEngineReplacement(EngineRenewList *erl) |
2848 | 461 |
{ |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
462 |
EngineRenew *er = (EngineRenew *)(*erl); |
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4358
diff
changeset
|
463 |
EngineRenew *next; |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
464 |
|
2848 | 465 |
while (er) { |
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4358
diff
changeset
|
466 |
next = er->next; |
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4358
diff
changeset
|
467 |
DeleteEngineRenew(er); |
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4358
diff
changeset
|
468 |
er = next; |
2848 | 469 |
} |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
470 |
*erl = NULL; // Empty list |
2848 | 471 |
} |
472 |
||
473 |
EngineID EngineReplacement(EngineRenewList erl, EngineID engine) |
|
474 |
{ |
|
475 |
const EngineRenew *er = GetEngineReplacement(erl, engine); |
|
476 |
return er == NULL ? INVALID_ENGINE : er->to; |
|
477 |
} |
|
478 |
||
4171 | 479 |
int32 AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, uint32 flags) |
2848 | 480 |
{ |
481 |
EngineRenew *er; |
|
482 |
||
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
483 |
/* Check if the old vehicle is already in the list */ |
2848 | 484 |
er = GetEngineReplacement(*erl, old_engine); |
485 |
if (er != NULL) { |
|
486 |
if (flags & DC_EXEC) er->to = new_engine; |
|
487 |
return 0; |
|
488 |
} |
|
489 |
||
490 |
er = AllocateEngineRenew(); |
|
491 |
if (er == NULL) return CMD_ERROR; |
|
492 |
||
493 |
if (flags & DC_EXEC) { |
|
494 |
er->from = old_engine; |
|
495 |
er->to = new_engine; |
|
496 |
||
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
497 |
/* Insert before the first element */ |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
498 |
er->next = (EngineRenew *)(*erl); |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
499 |
*erl = (EngineRenewList)er; |
2848 | 500 |
} |
501 |
||
502 |
return 0; |
|
503 |
} |
|
504 |
||
4171 | 505 |
int32 RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, uint32 flags) |
2848 | 506 |
{ |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
507 |
EngineRenew *er = (EngineRenew *)(*erl); |
4171 | 508 |
EngineRenew *prev = NULL; |
2848 | 509 |
|
510 |
while (er) |
|
511 |
{ |
|
512 |
if (er->from == engine) { |
|
513 |
if (flags & DC_EXEC) { |
|
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
514 |
if (prev == NULL) { // First element |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
515 |
/* The second becomes the new first element */ |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
516 |
*erl = (EngineRenewList)er->next; |
2848 | 517 |
} else { |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
518 |
/* Cut this element out */ |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
519 |
prev->next = er->next; |
2848 | 520 |
} |
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4358
diff
changeset
|
521 |
DeleteEngineRenew(er); |
2848 | 522 |
} |
523 |
return 0; |
|
524 |
} |
|
525 |
prev = er; |
|
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
526 |
er = er->next; |
2848 | 527 |
} |
528 |
||
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
529 |
return CMD_ERROR; |
2848 | 530 |
} |
531 |
||
532 |
static const SaveLoad _engine_renew_desc[] = { |
|
533 |
SLE_VAR(EngineRenew, from, SLE_UINT16), |
|
534 |
SLE_VAR(EngineRenew, to, SLE_UINT16), |
|
535 |
||
536 |
SLE_REF(EngineRenew, next, REF_ENGINE_RENEWS), |
|
537 |
||
538 |
SLE_END() |
|
539 |
}; |
|
540 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
541 |
static void Save_ERNW() |
2848 | 542 |
{ |
543 |
EngineRenew *er; |
|
544 |
||
545 |
FOR_ALL_ENGINE_RENEWS(er) { |
|
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
546 |
SlSetArrayIndex(er->index); |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
547 |
SlObject(er, _engine_renew_desc); |
2848 | 548 |
} |
549 |
} |
|
550 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
551 |
static void Load_ERNW() |
2848 | 552 |
{ |
553 |
int index; |
|
554 |
||
555 |
while ((index = SlIterateArray()) != -1) { |
|
556 |
EngineRenew *er; |
|
557 |
||
4974
c962d0622bc1
(svn r6977) Use the pool macros for the EngineRenew pool
tron
parents:
4848
diff
changeset
|
558 |
if (!AddBlockIfNeeded(&_EngineRenew_pool, index)) |
2848 | 559 |
error("EngineRenews: failed loading savegame: too many EngineRenews"); |
560 |
||
561 |
er = GetEngineRenew(index); |
|
562 |
SlObject(er, _engine_renew_desc); |
|
563 |
} |
|
564 |
} |
|
565 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1855
diff
changeset
|
566 |
static const SaveLoad _engine_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
567 |
SLE_CONDVAR(Engine, intro_date, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
568 |
SLE_CONDVAR(Engine, intro_date, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
569 |
SLE_CONDVAR(Engine, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
570 |
SLE_CONDVAR(Engine, age, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
571 |
SLE_VAR(Engine, reliability, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
572 |
SLE_VAR(Engine, reliability_spd_dec, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
573 |
SLE_VAR(Engine, reliability_start, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
574 |
SLE_VAR(Engine, reliability_max, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
575 |
SLE_VAR(Engine, reliability_final, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
576 |
SLE_VAR(Engine, duration_phase_1, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
577 |
SLE_VAR(Engine, duration_phase_2, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
578 |
SLE_VAR(Engine, duration_phase_3, SLE_UINT16), |
0 | 579 |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
580 |
SLE_VAR(Engine, lifelength, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
581 |
SLE_VAR(Engine, flags, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
582 |
SLE_VAR(Engine, preview_player, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
583 |
SLE_VAR(Engine, preview_wait, SLE_UINT8), |
6074 | 584 |
SLE_CONDNULL(1, 0, 44), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
585 |
SLE_VAR(Engine, player_avail, SLE_UINT8), |
0 | 586 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
587 |
/* reserve extra space in savegame here. (currently 16 bytes) */ |
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3047
diff
changeset
|
588 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 589 |
|
590 |
SLE_END() |
|
591 |
}; |
|
592 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
593 |
static void Save_ENGN() |
0 | 594 |
{ |
2242
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
595 |
uint i; |
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
596 |
|
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
597 |
for (i = 0; i != lengthof(_engines); i++) { |
0 | 598 |
SlSetArrayIndex(i); |
2242
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
599 |
SlObject(&_engines[i], _engine_desc); |
0 | 600 |
} |
601 |
} |
|
602 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
603 |
static void Load_ENGN() |
0 | 604 |
{ |
605 |
int index; |
|
606 |
while ((index = SlIterateArray()) != -1) { |
|
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1908
diff
changeset
|
607 |
SlObject(GetEngine(index), _engine_desc); |
0 | 608 |
} |
609 |
} |
|
610 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
611 |
static void LoadSave_ENGS() |
0 | 612 |
{ |
613 |
SlArray(_engine_name_strings, lengthof(_engine_name_strings), SLE_STRINGID); |
|
614 |
} |
|
615 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
616 |
extern const ChunkHandler _engine_chunk_handlers[] = { |
2848 | 617 |
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY }, |
618 |
{ 'ENGS', LoadSave_ENGS, LoadSave_ENGS, CH_RIFF }, |
|
619 |
{ 'ERNW', Save_ERNW, Load_ERNW, CH_ARRAY | CH_LAST}, |
|
0 | 620 |
}; |
621 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6535
diff
changeset
|
622 |
void InitializeEngines() |
1197 | 623 |
{ |
2848 | 624 |
/* Clean the engine renew pool and create 1 block in it */ |
4974
c962d0622bc1
(svn r6977) Use the pool macros for the EngineRenew pool
tron
parents:
4848
diff
changeset
|
625 |
CleanPool(&_EngineRenew_pool); |
c962d0622bc1
(svn r6977) Use the pool macros for the EngineRenew pool
tron
parents:
4848
diff
changeset
|
626 |
AddBlockToPool(&_EngineRenew_pool); |
1196
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
627 |
} |