author | glx |
Sun, 15 Jun 2008 22:18:10 +0000 | |
branch | noai |
changeset 10971 | aaf89f8c59b9 |
parent 10867 | 5de2923d6e59 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
3 |
/** @file engine.cpp Base for all engine handling. */ |
6451
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" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
8 |
#include "player_base.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
9 |
#include "player_func.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
10 |
#include "command_func.h" |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
11 |
#include "news_func.h" |
0 | 12 |
#include "saveload.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2147
diff
changeset
|
13 |
#include "variables.h" |
2708
9d1a8d5dc3ea
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
14 |
#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
|
15 |
#include "aircraft.h" |
3866
113de2b20059
(svn r4902) Newgrf : Introduction of the newgrf_cargo files.
belugas
parents:
3865
diff
changeset
|
16 |
#include "newgrf_cargo.h" |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
17 |
#include "newgrf_engine.h" |
9624 | 18 |
#include "group.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
19 |
#include "strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
20 |
#include "gfx_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
21 |
#include "functions.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
22 |
#include "window_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
23 |
#include "date_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
24 |
#include "autoreplace_base.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
25 |
#include "autoreplace_gui.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
26 |
#include "string_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
27 |
#include "settings_type.h" |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9837
diff
changeset
|
28 |
#include "oldpool_func.h" |
10297
433b21fd002c
(svn r12838) [NoAI] -Add: added AIEventEnginePreview, which tells you when you have been chosen for testing an engine, and allows you to accept it
glx
parents:
10142
diff
changeset
|
29 |
#include "ai/ai.h" |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
30 |
#include "core/alloc_func.hpp" |
10645 | 31 |
#include "vehicle_func.h" |
10829 | 32 |
#include <map> |
0 | 33 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
34 |
#include "table/strings.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
35 |
#include "table/engines.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
36 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
37 |
DEFINE_OLD_POOL_GENERIC(Engine, Engine) |
2763 | 38 |
|
0 | 39 |
enum { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
40 |
YEAR_ENGINE_AGING_STOPS = 2050, |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
41 |
}; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
42 |
|
0 | 43 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
44 |
/** Number of engines of each vehicle type in original engine data */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
45 |
const uint8 _engine_counts[4] = { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
46 |
lengthof(_orig_rail_vehicle_info), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
47 |
lengthof(_orig_road_vehicle_info), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
48 |
lengthof(_orig_ship_vehicle_info), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
49 |
lengthof(_orig_aircraft_vehicle_info), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
50 |
}; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
51 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
52 |
/** Offset of the first engine of each vehicle type in original engine data */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
53 |
const uint8 _engine_offsets[4] = { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
54 |
0, |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
55 |
lengthof(_orig_rail_vehicle_info), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
56 |
lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
57 |
lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
58 |
}; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
59 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
60 |
Engine::Engine() : |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
61 |
name(NULL), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
62 |
overrides_count(0), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
63 |
overrides(NULL) |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
64 |
{ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
65 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
66 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
67 |
Engine::Engine(VehicleType type, EngineID base) |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
68 |
{ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
69 |
this->type = type; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
70 |
this->internal_id = base; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
71 |
this->list_position = base; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
72 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
73 |
/* Check if this base engine is within the original engine data range */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
74 |
if (base >= _engine_counts[type]) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
75 |
/* Mark engine as valid anyway */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
76 |
this->info.climates = 0x80; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
77 |
return; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
78 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
79 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
80 |
/* Copy the original engine info for this slot */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
81 |
this->info = _orig_engine_info[_engine_offsets[type] + base]; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
82 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
83 |
/* Copy the original engine data for this slot */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
84 |
switch (type) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
85 |
default: NOT_REACHED(); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
86 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
87 |
case VEH_TRAIN: |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
88 |
this->u.rail = _orig_rail_vehicle_info[base]; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
89 |
this->image_index = this->u.rail.image_index; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
90 |
this->info.string_id = STR_8000_KIRBY_PAUL_TANK_STEAM + base; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
91 |
break; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
92 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
93 |
case VEH_ROAD: |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
94 |
this->u.road = _orig_road_vehicle_info[base]; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
95 |
this->image_index = this->u.road.image_index; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
96 |
this->info.string_id = STR_8074_MPS_REGAL_BUS + base; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
97 |
break; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
98 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
99 |
case VEH_SHIP: |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
100 |
this->u.ship = _orig_ship_vehicle_info[base]; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
101 |
this->image_index = this->u.ship.image_index; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
102 |
this->info.string_id = STR_80CC_MPS_OIL_TANKER + base; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
103 |
break; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
104 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
105 |
case VEH_AIRCRAFT: |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
106 |
this->u.air = _orig_aircraft_vehicle_info[base]; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
107 |
this->image_index = this->u.air.image_index; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
108 |
this->info.string_id = STR_80D7_SAMPSON_U52 + base; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
109 |
break; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
110 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
111 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
112 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
113 |
Engine::~Engine() |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
114 |
{ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
115 |
UnloadWagonOverrides(this); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
116 |
free(this->name); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
117 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
118 |
|
10645 | 119 |
/** Sets cached values in Player::num_vehicles and Group::num_vehicles |
120 |
*/ |
|
121 |
void SetCachedEngineCounts() |
|
122 |
{ |
|
123 |
uint engines = GetEnginePoolSize(); |
|
124 |
||
125 |
/* Set up the engine count for all players */ |
|
126 |
Player *p; |
|
127 |
FOR_ALL_PLAYERS(p) { |
|
128 |
free(p->num_engines); |
|
129 |
p->num_engines = CallocT<EngineID>(engines); |
|
130 |
} |
|
131 |
||
132 |
/* Recalculate */ |
|
133 |
Group *g; |
|
134 |
FOR_ALL_GROUPS(g) { |
|
135 |
free(g->num_engines); |
|
136 |
g->num_engines = CallocT<EngineID>(engines); |
|
137 |
} |
|
138 |
||
139 |
const Vehicle *v; |
|
140 |
FOR_ALL_VEHICLES(v) { |
|
141 |
if (!IsEngineCountable(v)) continue; |
|
142 |
||
143 |
assert(v->engine_type < engines); |
|
144 |
||
145 |
GetPlayer(v->owner)->num_engines[v->engine_type]++; |
|
146 |
||
147 |
if (v->group_id == DEFAULT_GROUP) continue; |
|
148 |
||
149 |
g = GetGroup(v->group_id); |
|
150 |
assert(v->type == g->vehicle_type); |
|
151 |
assert(v->owner == g->owner); |
|
152 |
||
153 |
g->num_engines[v->engine_type]++; |
|
154 |
} |
|
155 |
} |
|
156 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
157 |
void SetupEngines() |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
158 |
{ |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
159 |
_Engine_pool.CleanPool(); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
160 |
_Engine_pool.AddBlockToPool(); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
161 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
162 |
for (uint i = 0; i < lengthof(_orig_rail_vehicle_info); i++) new Engine(VEH_TRAIN, i); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
163 |
for (uint i = 0; i < lengthof(_orig_road_vehicle_info); i++) new Engine(VEH_ROAD, i); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
164 |
for (uint i = 0; i < lengthof(_orig_ship_vehicle_info); i++) new Engine(VEH_SHIP, i); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
165 |
for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++) new Engine(VEH_AIRCRAFT, i); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
166 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
167 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
168 |
|
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
|
169 |
void ShowEnginePreviewWindow(EngineID engine); |
0 | 170 |
|
6573 | 171 |
void DeleteCustomEngineNames() |
0 | 172 |
{ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
173 |
Engine *e; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
174 |
FOR_ALL_ENGINES(e) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
175 |
free(e->name); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
176 |
e->name = NULL; |
0 | 177 |
} |
178 |
||
179 |
_vehicle_design_names &= ~1; |
|
180 |
} |
|
181 |
||
6573 | 182 |
void LoadCustomEngineNames() |
0 | 183 |
{ |
4432
33631ac88c40
(svn r6195) -Codechange: do not use '//' in '/* ... */' style comments and '/*' or '*/' in '//' style comments.
rubidium
parents:
4384
diff
changeset
|
184 |
/* XXX: not done */ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5216
diff
changeset
|
185 |
DEBUG(misc, 1, "LoadCustomEngineNames: not done"); |
0 | 186 |
} |
187 |
||
10867
5de2923d6e59
(svn r13418) [NoAI] -Sync: with trunk r13380:13417.
rubidium
parents:
10829
diff
changeset
|
188 |
/* Determine if an engine type is a wagon (and not a loco) */ |
5de2923d6e59
(svn r13418) [NoAI] -Sync: with trunk r13380:13417.
rubidium
parents:
10829
diff
changeset
|
189 |
static bool IsWagon(EngineID index) |
5de2923d6e59
(svn r13418) [NoAI] -Sync: with trunk r13380:13417.
rubidium
parents:
10829
diff
changeset
|
190 |
{ |
5de2923d6e59
(svn r13418) [NoAI] -Sync: with trunk r13380:13417.
rubidium
parents:
10829
diff
changeset
|
191 |
const Engine *e = GetEngine(index); |
5de2923d6e59
(svn r13418) [NoAI] -Sync: with trunk r13380:13417.
rubidium
parents:
10829
diff
changeset
|
192 |
return e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON; |
5de2923d6e59
(svn r13418) [NoAI] -Sync: with trunk r13380:13417.
rubidium
parents:
10829
diff
changeset
|
193 |
} |
5de2923d6e59
(svn r13418) [NoAI] -Sync: with trunk r13380:13417.
rubidium
parents:
10829
diff
changeset
|
194 |
|
0 | 195 |
static void CalcEngineReliability(Engine *e) |
196 |
{ |
|
197 |
uint age = e->age; |
|
198 |
||
9624 | 199 |
/* Check for early retirement */ |
10776 | 200 |
if (e->player_avail != 0 && !_settings_game.vehicle.never_expire_vehicles) { |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
201 |
int retire_early = e->info.retire_early; |
9732 | 202 |
uint retire_early_max_age = max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12); |
203 |
if (retire_early != 0 && age >= retire_early_max_age) { |
|
9624 | 204 |
/* Early retirement is enabled and we're past the date... */ |
205 |
e->player_avail = 0; |
|
206 |
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
|
207 |
} |
|
208 |
} |
|
209 |
||
0 | 210 |
if (age < e->duration_phase_1) { |
211 |
uint start = e->reliability_start; |
|
212 |
e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start; |
|
10776 | 213 |
} else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _settings_game.vehicle.never_expire_vehicles) { |
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
|
214 |
/* 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
|
215 |
* This is also true if the engines never expire. They will not go bad over time */ |
0 | 216 |
e->reliability = e->reliability_max; |
217 |
} else if ((age -= e->duration_phase_2) < e->duration_phase_3) { |
|
218 |
uint max = e->reliability_max; |
|
219 |
e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max; |
|
220 |
} 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
|
221 |
/* 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
|
222 |
* 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
|
223 |
e->player_avail = 0; |
0 | 224 |
e->reliability = e->reliability_final; |
6195
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6119
diff
changeset
|
225 |
/* 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
|
226 |
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
0 | 227 |
} |
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
|
228 |
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
|
229 |
InvalidateWindowClasses(WC_REPLACE_VEHICLE); |
0 | 230 |
} |
231 |
||
6573 | 232 |
void StartupEngines() |
0 | 233 |
{ |
234 |
Engine *e; |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
235 |
/* 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
|
236 |
const Date aging_date = min(_date, ConvertYMDToDate(YEAR_ENGINE_AGING_STOPS, 0, 1)); |
0 | 237 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
238 |
FOR_ALL_ENGINES(e) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
239 |
const EngineInfo *ei = &e->info; |
2242
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
240 |
uint32 r; |
0 | 241 |
|
242 |
e->age = 0; |
|
243 |
e->flags = 0; |
|
244 |
e->player_avail = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
245 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
246 |
/* 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
|
247 |
* 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
|
248 |
* added. */ |
0 | 249 |
r = Random(); |
4297
47ce9665b4af
(svn r5934) -Cleanup: forgot some conversions to Year and to Date
rubidium
parents:
4293
diff
changeset
|
250 |
e->intro_date = ei->base_intro <= ConvertYMDToDate(1922, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro; |
0 | 251 |
if (e->intro_date <= _date) { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
252 |
e->age = (aging_date - e->intro_date) >> 5; |
0 | 253 |
e->player_avail = (byte)-1; |
254 |
e->flags |= ENGINE_AVAILABLE; |
|
255 |
} |
|
256 |
||
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
|
257 |
e->reliability_start = GB(r, 16, 14) + 0x7AE0; |
0 | 258 |
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
|
259 |
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
|
260 |
e->reliability_final = GB(r, 16, 14) + 0x3FFF; |
0 | 261 |
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
e->duration_phase_3 = GB(r, 9, 7) + 120; |
0 | 266 |
|
10867
5de2923d6e59
(svn r13418) [NoAI] -Sync: with trunk r13380:13417.
rubidium
parents:
10829
diff
changeset
|
267 |
e->reliability_spd_dec = ei->decay_speed << 2; |
0 | 268 |
|
10867
5de2923d6e59
(svn r13418) [NoAI] -Sync: with trunk r13380:13417.
rubidium
parents:
10829
diff
changeset
|
269 |
if (IsWagon(e->index)) { |
0 | 270 |
e->age = 0xFFFF; |
271 |
} else { |
|
272 |
CalcEngineReliability(e); |
|
273 |
} |
|
274 |
||
10776 | 275 |
e->lifelength = ei->lifelength + _settings_game.vehicle.extend_vehicle_life; |
0 | 276 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
277 |
/* prevent certain engines from ever appearing. */ |
10776 | 278 |
if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) { |
0 | 279 |
e->flags |= ENGINE_AVAILABLE; |
280 |
e->player_avail = 0; |
|
281 |
} |
|
282 |
} |
|
283 |
} |
|
284 |
||
6074 | 285 |
static void AcceptEnginePreview(EngineID eid, PlayerID player) |
0 | 286 |
{ |
6074 | 287 |
Engine *e = GetEngine(eid); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
288 |
Player *p = GetPlayer(player); |
0 | 289 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9694
diff
changeset
|
290 |
SetBit(e->player_avail, player); |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6573
diff
changeset
|
291 |
if (e->type == VEH_TRAIN) { |
6074 | 292 |
const RailVehicleInfo *rvi = RailVehInfo(eid); |
293 |
||
294 |
assert(rvi->railtype < RAILTYPE_END); |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9694
diff
changeset
|
295 |
SetBit(p->avail_railtypes, rvi->railtype); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
296 |
} else if (e->type == VEH_ROAD) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9694
diff
changeset
|
297 |
SetBit(p->avail_roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD); |
6074 | 298 |
} |
0 | 299 |
|
9732 | 300 |
e->preview_player_rank = 0xFF; |
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
|
301 |
if (player == _local_player) { |
6195
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6119
diff
changeset
|
302 |
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
|
303 |
} |
0 | 304 |
} |
305 |
||
9732 | 306 |
static PlayerID GetBestPlayer(uint8 pp) |
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
|
307 |
{ |
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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
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
|
312 |
|
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
|
313 |
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
|
314 |
best_hist = -1; |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
315 |
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
|
316 |
FOR_ALL_PLAYERS(p) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9694
diff
changeset
|
317 |
if (p->is_active && p->block_preview == 0 && !HasBit(mask, p->index) && |
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
|
318 |
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
|
319 |
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
|
320 |
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
|
321 |
} |
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
|
322 |
} |
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
|
323 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
324 |
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
|
325 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9694
diff
changeset
|
326 |
SetBit(mask, best_player); |
9800 | 327 |
} while (--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
|
328 |
|
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
|
329 |
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
|
330 |
} |
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
|
331 |
|
6573 | 332 |
void EnginesDailyLoop() |
0 | 333 |
{ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
334 |
if (_cur_year >= YEAR_ENGINE_AGING_STOPS) return; |
0 | 335 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
336 |
Engine *e; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
337 |
FOR_ALL_ENGINES(e) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
338 |
EngineID i = e->index; |
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 |
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
|
340 |
if (e->flags & ENGINE_OFFER_WINDOW_OPEN) { |
9732 | 341 |
if (e->preview_player_rank != 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
|
342 |
e->flags &= ~ENGINE_OFFER_WINDOW_OPEN; |
0 | 343 |
DeleteWindowById(WC_ENGINE_PREVIEW, i); |
9732 | 344 |
e->preview_player_rank++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
345 |
} |
9732 | 346 |
} else if (e->preview_player_rank != 0xFF) { |
347 |
PlayerID best_player = GetBestPlayer(e->preview_player_rank); |
|
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
|
348 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
349 |
if (best_player == PLAYER_SPECTATOR) { |
9732 | 350 |
e->preview_player_rank = 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
|
351 |
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
|
352 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
353 |
|
10297
433b21fd002c
(svn r12838) [NoAI] -Add: added AIEventEnginePreview, which tells you when you have been chosen for testing an engine, and allows you to accept it
glx
parents:
10142
diff
changeset
|
354 |
e->flags |= ENGINE_OFFER_WINDOW_OPEN; |
433b21fd002c
(svn r12838) [NoAI] -Add: added AIEventEnginePreview, which tells you when you have been chosen for testing an engine, and allows you to accept it
glx
parents:
10142
diff
changeset
|
355 |
e->preview_wait = 20; |
433b21fd002c
(svn r12838) [NoAI] -Add: added AIEventEnginePreview, which tells you when you have been chosen for testing an engine, and allows you to accept it
glx
parents:
10142
diff
changeset
|
356 |
AI_Event(best_player, new AIEventEnginePreview(i)); |
433b21fd002c
(svn r12838) [NoAI] -Add: added AIEventEnginePreview, which tells you when you have been chosen for testing an engine, and allows you to accept it
glx
parents:
10142
diff
changeset
|
357 |
if (IsInteractivePlayer(best_player)) ShowEnginePreviewWindow(i); |
0 | 358 |
} |
359 |
} |
|
360 |
} |
|
361 |
} |
|
362 |
||
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 |
/** 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
|
364 |
* 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
|
365 |
* @param tile unused |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
366 |
* @param flags operation to perfom |
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
|
367 |
* @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
|
368 |
* @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
|
369 |
*/ |
9629 | 370 |
CommandCost CmdWantEnginePreview(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 371 |
{ |
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
|
372 |
Engine *e; |
2951 | 373 |
|
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
|
374 |
if (!IsEngineIndex(p1)) return CMD_ERROR; |
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1908
diff
changeset
|
375 |
e = GetEngine(p1); |
9732 | 376 |
if (GetBestPlayer(e->preview_player_rank) != _current_player) 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
|
377 |
|
6074 | 378 |
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
|
379 |
|
9629 | 380 |
return CommandCost(); |
0 | 381 |
} |
382 |
||
10645 | 383 |
StringID GetEngineCategoryName(EngineID engine); |
384 |
||
410 | 385 |
static void NewVehicleAvailable(Engine *e) |
0 | 386 |
{ |
387 |
Vehicle *v; |
|
388 |
Player *p; |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
389 |
EngineID index = e->index; |
0 | 390 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
391 |
/* 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
|
392 |
* 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
|
393 |
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) { |
0 | 394 |
FOR_ALL_PLAYERS(p) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
395 |
uint block_preview = p->block_preview; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
396 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9694
diff
changeset
|
397 |
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
|
398 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
399 |
/* 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
|
400 |
p->block_preview = 20; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
401 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
402 |
FOR_ALL_VEHICLES(v) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6573
diff
changeset
|
403 |
if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP || |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6573
diff
changeset
|
404 |
(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
|
405 |
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
|
406 |
/* 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
|
407 |
p->block_preview = block_preview; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
408 |
break; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
409 |
} |
0 | 410 |
} |
411 |
} |
|
412 |
} |
|
413 |
} |
|
414 |
||
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
|
415 |
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
|
416 |
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
417 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
418 |
/* Now available for all players */ |
0 | 419 |
e->player_avail = (byte)-1; |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
420 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
421 |
/* Do not introduce new rail wagons */ |
2639 | 422 |
if (IsWagon(index)) return; |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
423 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
424 |
if (e->type == VEH_TRAIN) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
425 |
/* maybe make another rail type available */ |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
426 |
RailType railtype = e->u.rail.railtype; |
6074 | 427 |
assert(railtype < RAILTYPE_END); |
428 |
FOR_ALL_PLAYERS(p) { |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9694
diff
changeset
|
429 |
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
|
430 |
} |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
431 |
} else if (e->type == VEH_ROAD) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
432 |
/* maybe make another road type available */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
433 |
FOR_ALL_PLAYERS(p) { |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
434 |
if (p->is_active) SetBit(p->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
435 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
436 |
} |
10645 | 437 |
|
10971
aaf89f8c59b9
(svn r13525) [NoAI] -Add: added AIEventEngineAvailable and AIEventStationFirstVehicle
glx
parents:
10867
diff
changeset
|
438 |
for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { |
aaf89f8c59b9
(svn r13525) [NoAI] -Add: added AIEventEngineAvailable and AIEventStationFirstVehicle
glx
parents:
10867
diff
changeset
|
439 |
AI_Event(i, new AIEventEngineAvailable(index)); |
aaf89f8c59b9
(svn r13525) [NoAI] -Add: added AIEventEngineAvailable and AIEventStationFirstVehicle
glx
parents:
10867
diff
changeset
|
440 |
} |
aaf89f8c59b9
(svn r13525) [NoAI] -Add: added AIEventEngineAvailable and AIEventStationFirstVehicle
glx
parents:
10867
diff
changeset
|
441 |
|
10645 | 442 |
SetDParam(0, GetEngineCategoryName(index)); |
443 |
SetDParam(1, index); |
|
444 |
AddNewsItem(STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NS_NEW_VEHICLES, index, 0); |
|
0 | 445 |
} |
446 |
||
6573 | 447 |
void EnginesMonthlyLoop() |
0 | 448 |
{ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
449 |
if (_cur_year < YEAR_ENGINE_AGING_STOPS) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
450 |
Engine *e; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
451 |
FOR_ALL_ENGINES(e) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
452 |
/* Age the vehicle */ |
2242
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
453 |
if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) { |
0 | 454 |
e->age++; |
455 |
CalcEngineReliability(e); |
|
456 |
} |
|
457 |
||
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
|
458 |
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
|
459 |
/* Introduce it to all players */ |
0 | 460 |
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
|
461 |
} 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
|
462 |
/* 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
|
463 |
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
|
464 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
465 |
/* Do not introduce new rail wagons */ |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
466 |
if (!IsWagon(e->index)) |
9732 | 467 |
e->preview_player_rank = 1; // Give to the player with the highest rating. |
0 | 468 |
} |
469 |
} |
|
470 |
} |
|
471 |
} |
|
472 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
473 |
static bool IsUniqueEngineName(const char *name) |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
474 |
{ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
475 |
char buf[512]; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
476 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
477 |
const Engine *e; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
478 |
FOR_ALL_ENGINES(e) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
479 |
SetDParam(0, e->index); |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
480 |
GetString(buf, STR_ENGINE_NAME, lastof(buf)); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
481 |
if (strcmp(buf, name) == 0) return false; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
482 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
483 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
484 |
return true; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
485 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
486 |
|
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
|
487 |
/** 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
|
488 |
* @param tile unused |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
489 |
* @param flags operation to perfom |
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
|
490 |
* @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
|
491 |
* @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
|
492 |
*/ |
9629 | 493 |
CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 494 |
{ |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
495 |
if (!IsEngineIndex(p1) || StrEmpty(_cmd_text)) 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
|
496 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
497 |
if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
498 |
|
0 | 499 |
if (flags & DC_EXEC) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
500 |
Engine *e = GetEngine(p1); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
501 |
free(e->name); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
502 |
e->name = strdup(_cmd_text); |
0 | 503 |
_vehicle_design_names |= 3; |
504 |
MarkWholeScreenDirty(); |
|
505 |
} |
|
506 |
||
9629 | 507 |
return CommandCost(); |
0 | 508 |
} |
509 |
||
510 |
||
9732 | 511 |
/** Check if an engine is buildable. |
512 |
* @param engine index of the engine to check. |
|
513 |
* @param type the type the engine should be. |
|
514 |
* @param player index of the player. |
|
515 |
* @return True if an engine is valid, of the specified type, and buildable by |
|
516 |
* the given player. |
|
2848 | 517 |
*/ |
9732 | 518 |
bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player) |
2848 | 519 |
{ |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
520 |
/* check if it's an engine that is in the engine array */ |
2848 | 521 |
if (!IsEngineIndex(engine)) return false; |
522 |
||
9732 | 523 |
const Engine *e = GetEngine(engine); |
2848 | 524 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
525 |
/* check if it's an engine of specified type */ |
2848 | 526 |
if (e->type != type) return false; |
527 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
528 |
/* check if it's available */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9694
diff
changeset
|
529 |
if (!HasBit(e->player_avail, player)) return false; |
2848 | 530 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
531 |
if (type == VEH_TRAIN) { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
532 |
/* Check if the rail type is available to this player */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
533 |
const Player *p = GetPlayer(player); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9694
diff
changeset
|
534 |
if (!HasBit(p->avail_railtypes, RailVehInfo(engine)->railtype)) return false; |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
535 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
536 |
|
2848 | 537 |
return true; |
538 |
} |
|
539 |
||
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
540 |
/** Get the default cargo type for a certain engine type |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
541 |
* @param engine The ID to get the cargo for |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
542 |
* @return The cargo type. CT_INVALID means no cargo capacity |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
543 |
*/ |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
544 |
CargoID GetEngineCargoType(EngineID engine) |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
545 |
{ |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
546 |
assert(IsEngineIndex(engine)); |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
547 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
548 |
switch (GetEngine(engine)->type) { |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
549 |
case VEH_TRAIN: |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
550 |
if (RailVehInfo(engine)->capacity == 0) return CT_INVALID; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
551 |
return RailVehInfo(engine)->cargo_type; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
552 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
553 |
case VEH_ROAD: |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
554 |
if (RoadVehInfo(engine)->capacity == 0) return CT_INVALID; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
555 |
return RoadVehInfo(engine)->cargo_type; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
556 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
557 |
case VEH_SHIP: |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
558 |
if (ShipVehInfo(engine)->capacity == 0) return CT_INVALID; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
559 |
return ShipVehInfo(engine)->cargo_type; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
560 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
561 |
case VEH_AIRCRAFT: |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
562 |
/* all aircraft starts as passenger planes with cargo capacity */ |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
563 |
return CT_PASSENGERS; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
564 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
565 |
default: NOT_REACHED(); return CT_INVALID; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
566 |
} |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
567 |
} |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6585
diff
changeset
|
568 |
|
2848 | 569 |
/************************************************************************ |
570 |
* Engine Replacement stuff |
|
571 |
************************************************************************/ |
|
572 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
573 |
DEFINE_OLD_POOL_GENERIC(EngineRenew, EngineRenew) |
2848 | 574 |
|
575 |
/** |
|
576 |
* Retrieves the EngineRenew that specifies the replacement of the given |
|
577 |
* engine type from the given renewlist */ |
|
9624 | 578 |
static EngineRenew *GetEngineReplacement(EngineRenewList erl, EngineID engine, GroupID group) |
2848 | 579 |
{ |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
580 |
EngineRenew *er = (EngineRenew *)erl; |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
581 |
|
2848 | 582 |
while (er) { |
9624 | 583 |
if (er->from == engine && er->group_id == group) return er; |
2848 | 584 |
er = er->next; |
585 |
} |
|
586 |
return NULL; |
|
587 |
} |
|
588 |
||
4171 | 589 |
void RemoveAllEngineReplacement(EngineRenewList *erl) |
2848 | 590 |
{ |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
591 |
EngineRenew *er = (EngineRenew *)(*erl); |
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4358
diff
changeset
|
592 |
EngineRenew *next; |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
593 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
594 |
while (er != NULL) { |
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4358
diff
changeset
|
595 |
next = er->next; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
596 |
delete er; |
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4358
diff
changeset
|
597 |
er = next; |
2848 | 598 |
} |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
599 |
*erl = NULL; // Empty list |
2848 | 600 |
} |
601 |
||
9624 | 602 |
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group) |
2848 | 603 |
{ |
9624 | 604 |
const EngineRenew *er = GetEngineReplacement(erl, engine, group); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
605 |
if (er == NULL && (group == DEFAULT_GROUP || (IsValidGroupID(group) && !GetGroup(group)->replace_protection))) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
606 |
/* We didn't find anything useful in the vehicle's own group so we will try ALL_GROUP */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
607 |
er = GetEngineReplacement(erl, engine, ALL_GROUP); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
608 |
} |
2848 | 609 |
return er == NULL ? INVALID_ENGINE : er->to; |
610 |
} |
|
611 |
||
9629 | 612 |
CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags) |
2848 | 613 |
{ |
614 |
EngineRenew *er; |
|
615 |
||
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
616 |
/* Check if the old vehicle is already in the list */ |
9624 | 617 |
er = GetEngineReplacement(*erl, old_engine, group); |
2848 | 618 |
if (er != NULL) { |
619 |
if (flags & DC_EXEC) er->to = new_engine; |
|
9629 | 620 |
return CommandCost(); |
2848 | 621 |
} |
622 |
||
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10297
diff
changeset
|
623 |
if (!EngineRenew::CanAllocateItem()) return CMD_ERROR; |
2848 | 624 |
|
625 |
if (flags & DC_EXEC) { |
|
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10297
diff
changeset
|
626 |
er = new EngineRenew(old_engine, new_engine); |
9624 | 627 |
er->group_id = group; |
2848 | 628 |
|
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
629 |
/* Insert before the first element */ |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
630 |
er->next = (EngineRenew *)(*erl); |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
631 |
*erl = (EngineRenewList)er; |
2848 | 632 |
} |
633 |
||
9629 | 634 |
return CommandCost(); |
2848 | 635 |
} |
636 |
||
9629 | 637 |
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags) |
2848 | 638 |
{ |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
639 |
EngineRenew *er = (EngineRenew *)(*erl); |
4171 | 640 |
EngineRenew *prev = NULL; |
2848 | 641 |
|
642 |
while (er) |
|
643 |
{ |
|
9624 | 644 |
if (er->from == engine && er->group_id == group) { |
2848 | 645 |
if (flags & DC_EXEC) { |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
646 |
if (prev == NULL) { // First element |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
647 |
/* The second becomes the new first element */ |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
648 |
*erl = (EngineRenewList)er->next; |
2848 | 649 |
} else { |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
650 |
/* Cut this element out */ |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
651 |
prev->next = er->next; |
2848 | 652 |
} |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
653 |
delete er; |
2848 | 654 |
} |
9629 | 655 |
return CommandCost(); |
2848 | 656 |
} |
657 |
prev = er; |
|
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
658 |
er = er->next; |
2848 | 659 |
} |
660 |
||
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
661 |
return CMD_ERROR; |
2848 | 662 |
} |
663 |
||
664 |
static const SaveLoad _engine_renew_desc[] = { |
|
9624 | 665 |
SLE_VAR(EngineRenew, from, SLE_UINT16), |
666 |
SLE_VAR(EngineRenew, to, SLE_UINT16), |
|
2848 | 667 |
|
9624 | 668 |
SLE_REF(EngineRenew, next, REF_ENGINE_RENEWS), |
669 |
SLE_CONDVAR(EngineRenew, group_id, SLE_UINT16, 60, SL_MAX_VERSION), |
|
2848 | 670 |
SLE_END() |
671 |
}; |
|
672 |
||
6573 | 673 |
static void Save_ERNW() |
2848 | 674 |
{ |
675 |
EngineRenew *er; |
|
676 |
||
677 |
FOR_ALL_ENGINE_RENEWS(er) { |
|
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
678 |
SlSetArrayIndex(er->index); |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
679 |
SlObject(er, _engine_renew_desc); |
2848 | 680 |
} |
681 |
} |
|
682 |
||
6573 | 683 |
static void Load_ERNW() |
2848 | 684 |
{ |
685 |
int index; |
|
686 |
||
687 |
while ((index = SlIterateArray()) != -1) { |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
688 |
EngineRenew *er = new (index) EngineRenew(); |
2848 | 689 |
SlObject(er, _engine_renew_desc); |
9624 | 690 |
|
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
691 |
/* Advanced vehicle lists, ungrouped vehicles got added */ |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
692 |
if (CheckSavegameVersion(60)) { |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
693 |
er->group_id = ALL_GROUP; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
694 |
} else if (CheckSavegameVersion(71)) { |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
695 |
if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_GROUP; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
696 |
} |
2848 | 697 |
} |
698 |
} |
|
699 |
||
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
|
700 |
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
|
701 |
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
|
702 |
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
|
703 |
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
|
704 |
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
|
705 |
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
|
706 |
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
|
707 |
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
|
708 |
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
|
709 |
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
|
710 |
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
|
711 |
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
|
712 |
SLE_VAR(Engine, duration_phase_3, SLE_UINT16), |
0 | 713 |
|
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
|
714 |
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
|
715 |
SLE_VAR(Engine, flags, SLE_UINT8), |
9732 | 716 |
SLE_VAR(Engine, preview_player_rank, SLE_UINT8), |
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
|
717 |
SLE_VAR(Engine, preview_wait, SLE_UINT8), |
6074 | 718 |
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
|
719 |
SLE_VAR(Engine, player_avail, SLE_UINT8), |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
720 |
SLE_CONDSTR(Engine, name, SLE_STR, 0, 84, SL_MAX_VERSION), |
0 | 721 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
722 |
/* 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
|
723 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 724 |
|
725 |
SLE_END() |
|
726 |
}; |
|
727 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
728 |
static std::map<EngineID, Engine> _temp_engine; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
729 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
730 |
Engine *GetTempDataEngine(EngineID index) |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
731 |
{ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
732 |
return &_temp_engine[index]; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
733 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
734 |
|
6573 | 735 |
static void Save_ENGN() |
0 | 736 |
{ |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
737 |
Engine *e; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
738 |
FOR_ALL_ENGINES(e) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
739 |
SlSetArrayIndex(e->index); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
740 |
SlObject(e, _engine_desc); |
0 | 741 |
} |
742 |
} |
|
743 |
||
6573 | 744 |
static void Load_ENGN() |
0 | 745 |
{ |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
746 |
/* As engine data is loaded before engines are initialized we need to load |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
747 |
* this information into a temporary array. This is then copied into the |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
748 |
* engine pool after processing NewGRFs by CopyTempEngineData(). */ |
0 | 749 |
int index; |
750 |
while ((index = SlIterateArray()) != -1) { |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
751 |
Engine *e = GetTempDataEngine(index); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
752 |
SlObject(e, _engine_desc); |
0 | 753 |
} |
754 |
} |
|
755 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
756 |
/** |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
757 |
* Copy data from temporary engine array into the real engine pool. |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
758 |
*/ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
759 |
void CopyTempEngineData() |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
760 |
{ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
761 |
Engine *e; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
762 |
FOR_ALL_ENGINES(e) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
763 |
if (e->index >= _temp_engine.size()) break; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
764 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
765 |
const Engine *se = GetTempDataEngine(e->index); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
766 |
e->intro_date = se->intro_date; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
767 |
e->age = se->age; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
768 |
e->reliability = se->reliability; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
769 |
e->reliability_spd_dec = se->reliability_spd_dec; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
770 |
e->reliability_start = se->reliability_start; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
771 |
e->reliability_max = se->reliability_max; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
772 |
e->reliability_final = se->reliability_final; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
773 |
e->duration_phase_1 = se->duration_phase_1; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
774 |
e->duration_phase_2 = se->duration_phase_2; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
775 |
e->duration_phase_3 = se->duration_phase_3; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
776 |
e->lifelength = se->lifelength; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
777 |
e->flags = se->flags; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
778 |
e->preview_player_rank = se->preview_player_rank; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
779 |
e->preview_wait = se->preview_wait; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
780 |
e->player_avail = se->player_avail; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
781 |
if (se->name != NULL) e->name = strdup(se->name); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
782 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
783 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
784 |
/* Get rid of temporary data */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
785 |
_temp_engine.clear(); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
786 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
787 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
788 |
static void Load_ENGS() |
0 | 789 |
{ |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
790 |
/* Load old separate String ID list into a temporary array. This |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
791 |
* was always 256 entries. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
792 |
StringID names[256]; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
793 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
794 |
SlArray(names, lengthof(names), SLE_STRINGID); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
795 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
796 |
/* Copy each string into the temporary engine array. */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
797 |
for (EngineID engine = 0; engine < lengthof(names); engine++) { |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
798 |
Engine *e = GetTempDataEngine(engine); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
799 |
e->name = CopyFromOldName(names[engine]); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
800 |
} |
0 | 801 |
} |
802 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
803 |
extern const ChunkHandler _engine_chunk_handlers[] = { |
2848 | 804 |
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY }, |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
805 |
{ 'ENGS', NULL, Load_ENGS, CH_RIFF }, |
2848 | 806 |
{ 'ERNW', Save_ERNW, Load_ERNW, CH_ARRAY | CH_LAST}, |
0 | 807 |
}; |
808 |
||
6573 | 809 |
void InitializeEngines() |
1197 | 810 |
{ |
2848 | 811 |
/* Clean the engine renew pool and create 1 block in it */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
812 |
_EngineRenew_pool.CleanPool(); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
813 |
_EngineRenew_pool.AddBlockToPool(); |
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
|
814 |
} |