author | tron |
Sun, 13 Feb 2005 11:31:35 +0000 | |
changeset 1365 | 7eff6abe942a |
parent 1364 | 9fad41818ac1 |
child 1371 | 76c98f1ff2bf |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1349
07514c2cc6d1
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1328
diff
changeset
|
3 |
#include "spritecache.h" |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
4 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
445
diff
changeset
|
5 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
593
diff
changeset
|
6 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1192
diff
changeset
|
7 |
#include "tile.h" |
0 | 8 |
#include "vehicle.h" |
9 |
#include "gfx.h" |
|
10 |
#include "viewport.h" |
|
11 |
#include "news.h" |
|
12 |
#include "command.h" |
|
13 |
#include "saveload.h" |
|
14 |
#include "player.h" |
|
15 |
#include "engine.h" |
|
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
260
diff
changeset
|
16 |
#include "sound.h" |
0 | 17 |
|
18 |
#define INVALID_COORD (-0x8000) |
|
19 |
#define GEN_HASH(x,y) (((x & 0x1F80)>>7) + ((y & 0xFC0))) |
|
20 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
21 |
enum { |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
22 |
/* Max vehicles: 64000 (512 * 125) */ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
23 |
VEHICLES_POOL_BLOCK_SIZE_BITS = 9, /* In bits, so (1 << 9) == 512 */ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
24 |
VEHICLES_POOL_MAX_BLOCKS = 125, |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
25 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
26 |
BLOCKS_FOR_SPECIAL_VEHICLES = 2, //! Blocks needed for special vehicles |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
27 |
}; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
28 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
29 |
/** |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
30 |
* Called if a new block is added to the vehicle-pool |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
31 |
*/ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
32 |
static void VehiclePoolNewBlock(uint start_item) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
33 |
{ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
34 |
Vehicle *v; |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
35 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
36 |
FOR_ALL_VEHICLES_FROM(v, start_item) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
37 |
v->index = start_item++; |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
38 |
} |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
39 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
40 |
/* Initialize the vehicle-pool */ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
41 |
MemoryPool _vehicle_pool = { "Vehicle", VEHICLES_POOL_MAX_BLOCKS, VEHICLES_POOL_BLOCK_SIZE_BITS, sizeof(Vehicle), &VehiclePoolNewBlock, 0, 0, NULL }; |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
42 |
|
578
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
43 |
void VehicleServiceInDepot(Vehicle *v) |
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
44 |
{ |
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
45 |
v->date_of_last_service = _date; |
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
46 |
v->breakdowns_since_last_service = 0; |
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
47 |
v->reliability = _engines[v->engine_type].reliability; |
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
48 |
} |
0 | 49 |
|
593 | 50 |
bool VehicleNeedsService(const Vehicle *v) |
51 |
{ |
|
1037
60bb8079eeea
(svn r1538) -Feature: [988816] Disable servicing when breakdowns set to none (jaguar7)
darkvater
parents:
1035
diff
changeset
|
52 |
if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) |
60bb8079eeea
(svn r1538) -Feature: [988816] Disable servicing when breakdowns set to none (jaguar7)
darkvater
parents:
1035
diff
changeset
|
53 |
return false; |
60bb8079eeea
(svn r1538) -Feature: [988816] Disable servicing when breakdowns set to none (jaguar7)
darkvater
parents:
1035
diff
changeset
|
54 |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
55 |
return _patches.servint_ispercent ? |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
56 |
(v->reliability < _engines[v->engine_type].reliability * (100 - v->service_interval) / 100) : |
593 | 57 |
(v->date_of_last_service + v->service_interval < _date); |
58 |
} |
|
59 |
||
0 | 60 |
void VehicleInTheWayErrMsg(Vehicle *v) |
61 |
{ |
|
62 |
StringID id; |
|
63 |
||
64 |
(id = STR_8803_TRAIN_IN_THE_WAY,v->type == VEH_Train) || |
|
65 |
(id = STR_9000_ROAD_VEHICLE_IN_THE_WAY,v->type == VEH_Road) || |
|
66 |
(id = STR_A015_AIRCRAFT_IN_THE_WAY,v->type == VEH_Aircraft) || |
|
67 |
(id = STR_980E_SHIP_IN_THE_WAY, true); |
|
68 |
||
69 |
_error_message = id; |
|
70 |
} |
|
71 |
||
72 |
static void *EnsureNoVehicleProc(Vehicle *v, void *data) |
|
73 |
{ |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
74 |
if (v->tile != *(const TileIndex*)data || v->type == VEH_Disaster) |
0 | 75 |
return NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
76 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
77 |
VehicleInTheWayErrMsg(v); |
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
78 |
return v; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
79 |
} |
0 | 80 |
|
81 |
bool EnsureNoVehicle(TileIndex tile) |
|
82 |
{ |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
83 |
return VehicleFromPos(tile, &tile, EnsureNoVehicleProc) == NULL; |
0 | 84 |
} |
85 |
||
86 |
static void *EnsureNoVehicleProcZ(Vehicle *v, void *data) |
|
87 |
{ |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
88 |
const TileInfo *ti = data; |
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
89 |
|
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
90 |
if (v->tile != ti->tile || v->z_pos != ti->z || v->type == VEH_Disaster) |
0 | 91 |
return NULL; |
92 |
||
93 |
VehicleInTheWayErrMsg(v); |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
94 |
return v; |
0 | 95 |
} |
96 |
||
1082
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
97 |
static inline uint Correct_Z(uint tileh) |
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
98 |
{ |
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
99 |
// needs z correction for slope-type graphics that have the NORTHERN tile lowered |
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
100 |
// 1, 2, 3, 4, 5, 6 and 7 |
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
101 |
return (CORRECT_Z(tileh)) ? 8 : 0; |
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
102 |
} |
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
103 |
|
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
104 |
uint GetCorrectTileHeight(TileIndex tile) |
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
105 |
{ |
1192
cd9b8a18a183
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1187
diff
changeset
|
106 |
return Correct_Z(GetTileSlope(tile, NULL)); |
1082
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
107 |
} |
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
108 |
|
0 | 109 |
bool EnsureNoVehicleZ(TileIndex tile, byte z) |
110 |
{ |
|
111 |
TileInfo ti; |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
112 |
|
0 | 113 |
FindLandscapeHeightByTile(&ti, tile); |
1082
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
114 |
ti.z = z + Correct_Z(ti.tileh); |
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
115 |
|
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
116 |
return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ) == NULL; |
0 | 117 |
} |
118 |
||
119 |
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z) |
|
120 |
{ |
|
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
121 |
int x1 = TileX(from); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
122 |
int y1 = TileY(from); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
123 |
int x2 = TileX(to); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
124 |
int y2 = TileY(to); |
0 | 125 |
Vehicle *veh; |
126 |
||
127 |
/* Make sure x1 < x2 or y1 < y2 */ |
|
128 |
if (x1 > x2 || y1 > y2) { |
|
129 |
intswap(x1,x2); |
|
130 |
intswap(y1,y2); |
|
131 |
} |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
132 |
FOR_ALL_VEHICLES(veh) { |
0 | 133 |
if ((veh->type == VEH_Train || veh->type == VEH_Road) && (z==0xFF || veh->z_pos == z)) { |
134 |
if ((veh->x_pos>>4) >= x1 && (veh->x_pos>>4) <= x2 && |
|
135 |
(veh->y_pos>>4) >= y1 && (veh->y_pos>>4) <= y2) { |
|
136 |
return veh; |
|
137 |
} |
|
138 |
} |
|
139 |
} |
|
140 |
return NULL; |
|
141 |
} |
|
142 |
||
143 |
void VehiclePositionChanged(Vehicle *v) |
|
144 |
{ |
|
145 |
int img = v->cur_image; |
|
146 |
const SpriteDimension *sd; |
|
147 |
Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); |
|
148 |
||
149 |
sd = GetSpriteDimension(img); |
|
150 |
||
151 |
pt.x += sd->xoffs; |
|
152 |
pt.y += sd->yoffs; |
|
153 |
||
154 |
UpdateVehiclePosHash(v, pt.x, pt.y); |
|
155 |
||
156 |
v->left_coord = pt.x; |
|
157 |
v->top_coord = pt.y; |
|
158 |
v->right_coord = pt.x + sd->xsize + 2; |
|
159 |
v->bottom_coord = pt.y + sd->ysize + 2; |
|
160 |
} |
|
161 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
162 |
void UpdateWaypointSign(Waypoint *cp) |
0 | 163 |
{ |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
164 |
Point pt = RemapCoords2(TileX(cp->xy) * 16, TileY(cp->xy) * 16); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
165 |
SetDParam(0, cp - _waypoints); |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
166 |
UpdateViewportSignPos(&cp->sign, pt.x, pt.y - 0x20, STR_WAYPOINT_VIEWPORT); |
0 | 167 |
} |
168 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
169 |
void RedrawWaypointSign(Waypoint *cp) |
0 | 170 |
{ |
171 |
MarkAllViewportsDirty( |
|
172 |
cp->sign.left - 6, |
|
173 |
cp->sign.top, |
|
174 |
cp->sign.left + (cp->sign.width_1 << 2) + 12, |
|
175 |
cp->sign.top + 48); |
|
176 |
} |
|
177 |
||
178 |
// Called after load to update coordinates |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
179 |
void AfterLoadVehicles(void) |
0 | 180 |
{ |
181 |
Vehicle *v; |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
182 |
Waypoint *cp; |
0 | 183 |
|
184 |
FOR_ALL_VEHICLES(v) { |
|
185 |
if (v->type != 0) { |
|
186 |
v->left_coord = INVALID_COORD; |
|
187 |
VehiclePositionChanged(v); |
|
188 |
||
189 |
if (v->type == VEH_Train) { |
|
1067
a083a6dd1419
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1063
diff
changeset
|
190 |
if (v->subtype == TS_Front_Engine) |
0 | 191 |
UpdateTrainAcceleration(v); |
192 |
} |
|
193 |
} |
|
194 |
} |
|
195 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
196 |
// update waypoint signs |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
197 |
for(cp=_waypoints; cp != endof(_waypoints); cp++) if (cp->xy) UpdateWaypointSign(cp); |
0 | 198 |
} |
199 |
||
200 |
||
201 |
static Vehicle *InitializeVehicle(Vehicle *v) |
|
202 |
{ |
|
203 |
VehicleID index = v->index; |
|
204 |
memset(v, 0, sizeof(Vehicle)); |
|
205 |
v->index = index; |
|
206 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
207 |
assert(v->orders == NULL); |
0 | 208 |
|
209 |
v->left_coord = INVALID_COORD; |
|
210 |
v->next = NULL; |
|
211 |
v->next_hash = 0xffff; |
|
212 |
v->string_id = 0; |
|
1111
2184bf930d25
(svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents:
1109
diff
changeset
|
213 |
v->next_shared = NULL; |
2184bf930d25
(svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents:
1109
diff
changeset
|
214 |
v->prev_shared = NULL; |
1139
c63f257aa7fb
(svn r1640) fix: now helicopters will use a hangar in schedule to be replaced in, even if they are only set to service there. Since helicopters are serviced at helipads, they will only go there if they needs to be replaced or renewed.
bjarni
parents:
1128
diff
changeset
|
215 |
v->set_for_replacement = false; |
548
bd14538d4a66
(svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents:
547
diff
changeset
|
216 |
/* random_bits is used to pick out a random sprite for vehicles |
bd14538d4a66
(svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents:
547
diff
changeset
|
217 |
which are technical the same (newgrf stuff). |
bd14538d4a66
(svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents:
547
diff
changeset
|
218 |
Because RandomRange() results in desyncs, and because it does |
826 | 219 |
not really matter that one client has other visual vehicles than |
548
bd14538d4a66
(svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents:
547
diff
changeset
|
220 |
the other, it can be InteractiveRandomRange() without any problem |
bd14538d4a66
(svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents:
547
diff
changeset
|
221 |
*/ |
547 | 222 |
v->random_bits = InteractiveRandomRange(256); |
0 | 223 |
return v; |
224 |
} |
|
225 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
226 |
Vehicle *ForceAllocateSpecialVehicle(void) |
0 | 227 |
{ |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
228 |
/* This stays a strange story.. there should always be room for special |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
229 |
* vehicles (special effects all over the map), but with 65k of vehicles |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
230 |
* is this realistic to double-check for that? For now we just reserve |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
231 |
* BLOCKS_FOR_SPECIAL_VEHICLES times block_size vehicles that may only |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
232 |
* be used for special vehicles.. should work nicely :) */ |
0 | 233 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
234 |
Vehicle *v; |
0 | 235 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
236 |
FOR_ALL_VEHICLES(v) { |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
237 |
/* No more room for the special vehicles, return NULL */ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
238 |
if (v->index >= (1 << _vehicle_pool.block_size_bits) * BLOCKS_FOR_SPECIAL_VEHICLES) |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
239 |
return NULL; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
240 |
|
0 | 241 |
if (v->type == 0) |
242 |
return InitializeVehicle(v); |
|
243 |
} |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
244 |
|
0 | 245 |
return NULL; |
246 |
} |
|
247 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
248 |
Vehicle *AllocateVehicle(void) |
0 | 249 |
{ |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
250 |
/* See note by ForceAllocateSpecialVehicle() why we skip the |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
251 |
* first blocks */ |
0 | 252 |
Vehicle *v; |
253 |
||
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
254 |
FOR_ALL_VEHICLES_FROM(v, (1 << _vehicle_pool.block_size_bits) * BLOCKS_FOR_SPECIAL_VEHICLES) { |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
255 |
if (v->type == 0) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
256 |
return InitializeVehicle(v); |
0 | 257 |
} |
258 |
||
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
259 |
/* Check if we can add a block to the pool */ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
260 |
if (AddBlockToPool(&_vehicle_pool)) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
261 |
return AllocateVehicle(); |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
262 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
263 |
return NULL; |
0 | 264 |
} |
265 |
||
266 |
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc) |
|
267 |
{ |
|
268 |
int x,y,x2,y2; |
|
269 |
VehicleID veh; |
|
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
270 |
Point pt = RemapCoords(TileX(tile) * 16, TileY(tile) * 16, 0); |
0 | 271 |
|
272 |
x2 = ((pt.x + 104) & 0x1F80) >> 7; |
|
273 |
x = ((pt.x - 174) & 0x1F80) >> 7; |
|
274 |
||
275 |
y2 = ((pt.y + 56) & 0xFC0); |
|
276 |
y = ((pt.y - 294) & 0xFC0); |
|
277 |
||
278 |
for(;;) { |
|
279 |
int xb = x; |
|
280 |
for(;;) { |
|
281 |
veh = _vehicle_position_hash[ (x+y)&0xFFFF ]; |
|
282 |
while (veh != INVALID_VEHICLE) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
283 |
Vehicle *v = GetVehicle(veh); |
0 | 284 |
void *a; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
285 |
|
0 | 286 |
if ((a = proc(v, data)) != NULL) |
287 |
return a; |
|
288 |
veh = v->next_hash; |
|
289 |
} |
|
290 |
||
291 |
if (x == x2) |
|
292 |
break; |
|
293 |
||
294 |
x = (x + 1) & 0x3F; |
|
295 |
} |
|
296 |
x = xb; |
|
297 |
||
298 |
if (y == y2) |
|
299 |
break; |
|
300 |
||
301 |
y = (y + 0x40) & ((0x3F) << 6); |
|
302 |
} |
|
303 |
return NULL; |
|
304 |
} |
|
305 |
||
306 |
||
307 |
||
308 |
void UpdateVehiclePosHash(Vehicle *v, int x, int y) |
|
309 |
{ |
|
310 |
VehicleID *old_hash, *new_hash; |
|
311 |
int old_x = v->left_coord; |
|
312 |
int old_y = v->top_coord; |
|
313 |
Vehicle *u; |
|
314 |
||
315 |
new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x,y)]; |
|
316 |
old_hash = (old_x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(old_x, old_y)]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
317 |
|
0 | 318 |
if (old_hash == new_hash) |
319 |
return; |
|
320 |
||
321 |
/* remove from hash table? */ |
|
322 |
if (old_hash != NULL) { |
|
323 |
Vehicle *last = NULL; |
|
324 |
int idx = *old_hash; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
325 |
while ((u = GetVehicle(idx)) != v) { |
0 | 326 |
idx = u->next_hash; |
327 |
assert(idx != INVALID_VEHICLE); |
|
328 |
last = u; |
|
329 |
} |
|
330 |
||
331 |
if (last == NULL) |
|
332 |
*old_hash = v->next_hash; |
|
333 |
else |
|
334 |
last->next_hash = v->next_hash; |
|
335 |
} |
|
336 |
||
337 |
/* insert into hash table? */ |
|
338 |
if (new_hash != NULL) { |
|
339 |
v->next_hash = *new_hash; |
|
340 |
*new_hash = v->index; |
|
341 |
} |
|
342 |
} |
|
343 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
344 |
void InitializeVehicles(void) |
0 | 345 |
{ |
346 |
int i; |
|
347 |
||
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
348 |
/* Clean the vehicle pool, and reserve enough blocks |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
349 |
* for the special vehicles, plus one for all the other |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
350 |
* vehicles (which is increased on-the-fly) */ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
351 |
CleanPool(&_vehicle_pool); |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
352 |
AddBlockToPool(&_vehicle_pool); |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
353 |
for (i = 0; i < BLOCKS_FOR_SPECIAL_VEHICLES; i++) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
354 |
AddBlockToPool(&_vehicle_pool); |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
355 |
|
0 | 356 |
// clear it... |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
357 |
memset(&_waypoints, 0, sizeof(_waypoints)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
358 |
|
0 | 359 |
memset(_vehicle_position_hash, -1, sizeof(_vehicle_position_hash)); |
360 |
} |
|
361 |
||
362 |
Vehicle *GetLastVehicleInChain(Vehicle *v) |
|
363 |
{ |
|
364 |
while (v->next != NULL) v = v->next; |
|
365 |
return v; |
|
366 |
} |
|
367 |
||
368 |
Vehicle *GetPrevVehicleInChain(Vehicle *v) |
|
369 |
{ |
|
370 |
Vehicle *org = v; |
|
371 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
372 |
FOR_ALL_VEHICLES(v) { |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
373 |
if (v->type == VEH_Train && org == v->next) |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
374 |
return v; |
0 | 375 |
} |
376 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
377 |
return NULL; |
0 | 378 |
} |
379 |
||
380 |
Vehicle *GetFirstVehicleInChain(Vehicle *v) |
|
381 |
{ |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
382 |
Vehicle *u; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
383 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
384 |
while (true) { |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
385 |
u = v; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
386 |
v = GetPrevVehicleInChain(v); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
387 |
/* If there is no such vehicle, |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
388 |
'v' == NULL and so 'u' is the first vehicle in chain */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
389 |
if (v == NULL) |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
390 |
return u; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
391 |
} |
0 | 392 |
} |
393 |
||
394 |
int CountVehiclesInChain(Vehicle *v) |
|
395 |
{ |
|
396 |
int count = 0; |
|
397 |
do count++; while ( (v=v->next) != NULL); |
|
398 |
return count; |
|
399 |
} |
|
400 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
401 |
Waypoint *AllocateWaypoint(void) |
0 | 402 |
{ |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
403 |
Waypoint *cp; |
0 | 404 |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
405 |
for(cp = _waypoints; cp != endof(_waypoints); cp++) { |
0 | 406 |
if (cp->xy == 0) |
407 |
return cp; |
|
408 |
} |
|
409 |
||
410 |
return NULL; |
|
411 |
} |
|
412 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
413 |
uint GetWaypointByTile(uint tile) |
0 | 414 |
{ |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
415 |
Waypoint *cp; |
0 | 416 |
int i=0; |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
417 |
for(cp=_waypoints; cp->xy != (TileIndex)tile; cp++) { i++; } |
0 | 418 |
return i; |
419 |
} |
|
420 |
||
421 |
void DeleteVehicle(Vehicle *v) |
|
422 |
{ |
|
423 |
DeleteName(v->string_id); |
|
424 |
v->type = 0; |
|
425 |
UpdateVehiclePosHash(v, INVALID_COORD, 0); |
|
426 |
v->next_hash = 0xffff; |
|
427 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
428 |
if (v->orders != NULL) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
429 |
DeleteVehicleOrders(v); |
0 | 430 |
} |
431 |
||
432 |
void DeleteVehicleChain(Vehicle *v) |
|
433 |
{ |
|
434 |
do { |
|
435 |
Vehicle *u = v; |
|
436 |
v = v->next; |
|
437 |
DeleteVehicle(u); |
|
438 |
} while (v); |
|
439 |
} |
|
440 |
||
441 |
||
442 |
void Aircraft_Tick(Vehicle *v); |
|
443 |
void RoadVeh_Tick(Vehicle *v); |
|
444 |
void Ship_Tick(Vehicle *v); |
|
445 |
void Train_Tick(Vehicle *v); |
|
410 | 446 |
static void EffectVehicle_Tick(Vehicle *v); |
0 | 447 |
void DisasterVehicle_Tick(Vehicle *v); |
448 |
||
449 |
VehicleTickProc *_vehicle_tick_procs[] = { |
|
450 |
Train_Tick, |
|
451 |
RoadVeh_Tick, |
|
452 |
Ship_Tick, |
|
453 |
Aircraft_Tick, |
|
454 |
EffectVehicle_Tick, |
|
455 |
DisasterVehicle_Tick, |
|
456 |
}; |
|
457 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
458 |
void CallVehicleTicks(void) |
0 | 459 |
{ |
460 |
Vehicle *v; |
|
461 |
||
462 |
FOR_ALL_VEHICLES(v) { |
|
463 |
if (v->type != 0) |
|
464 |
_vehicle_tick_procs[v->type - 0x10](v); |
|
465 |
} |
|
466 |
} |
|
467 |
||
468 |
static bool CanFillVehicle_FullLoadAny(Vehicle *v) |
|
469 |
{ |
|
470 |
uint32 full = 0, not_full = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
471 |
|
924
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
472 |
//special handling of aircraft |
941
4a695e126035
(svn r1429) Change: bumped savegame to revision 5.
truelight
parents:
939
diff
changeset
|
473 |
|
924
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
474 |
//if the aircraft carries passengers and is NOT full, then |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
475 |
//continue loading, no matter how much mail is in |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
476 |
if ((v->type == VEH_Aircraft) && (v->cargo_type == CT_PASSENGERS) && (v->cargo_cap != v->cargo_count)) { |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
477 |
return true; |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
478 |
} |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
479 |
|
0 | 480 |
// patch should return "true" to continue loading, i.e. when there is no cargo type that is fully loaded. |
481 |
do { |
|
482 |
//Should never happen, but just in case future additions change this |
|
483 |
assert(v->cargo_type<32); |
|
484 |
||
485 |
if (v->cargo_cap != 0) { |
|
486 |
uint32 mask = 1 << v->cargo_type; |
|
487 |
if (v->cargo_cap == v->cargo_count) full |= mask; else not_full |= mask; |
|
488 |
} |
|
489 |
} while ( (v=v->next) != NULL); |
|
490 |
||
491 |
// continue loading if there is a non full cargo type and no cargo type that is full |
|
492 |
return not_full && (full & ~not_full) == 0; |
|
493 |
} |
|
494 |
||
495 |
bool CanFillVehicle(Vehicle *v) |
|
496 |
{ |
|
1058
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
497 |
TileIndex tile = v->tile; |
0 | 498 |
|
1058
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
499 |
if (IsTileType(tile, MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
500 |
(v->type == VEH_Ship && ( |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
501 |
IsTileType(TILE_ADDXY(tile, 1, 0), MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
502 |
IsTileType(TILE_ADDXY(tile, -1, 0), MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
503 |
IsTileType(TILE_ADDXY(tile, 0, 1), MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
504 |
IsTileType(TILE_ADDXY(tile, 0, -1), MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
505 |
IsTileType(TILE_ADDXY(tile, -2, 0), MP_STATION) |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
506 |
))) { |
0 | 507 |
|
508 |
// If patch is active, use alternative CanFillVehicle-function |
|
509 |
if (_patches.full_load_any) |
|
510 |
return CanFillVehicle_FullLoadAny(v); |
|
511 |
||
512 |
do { |
|
513 |
if (v->cargo_count != v->cargo_cap) |
|
514 |
return true; |
|
515 |
} while ( (v=v->next) != NULL); |
|
516 |
} |
|
517 |
return false; |
|
518 |
} |
|
519 |
||
520 |
static void DoDrawVehicle(Vehicle *v) |
|
521 |
{ |
|
522 |
uint32 image = v->cur_image; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
523 |
|
0 | 524 |
if (v->vehstatus & VS_DISASTER) { |
525 |
image |= 0x3224000; |
|
526 |
} else if (v->vehstatus & VS_DEFPAL) { |
|
527 |
image |= (v->vehstatus & VS_CRASHED) ? 0x3248000 : SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
528 |
} |
0 | 529 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
530 |
AddSortableSpriteToDraw(image, v->x_pos + v->x_offs, v->y_pos + v->y_offs, |
0 | 531 |
v->sprite_width, v->sprite_height, v->z_height, v->z_pos); |
532 |
} |
|
533 |
||
534 |
void ViewportAddVehicles(DrawPixelInfo *dpi) |
|
535 |
{ |
|
536 |
int x,xb, y, x2, y2; |
|
537 |
VehicleID veh; |
|
538 |
Vehicle *v; |
|
539 |
||
540 |
x = ((dpi->left - 70) & 0x1F80) >> 7; |
|
541 |
x2 = ((dpi->left + dpi->width) & 0x1F80) >> 7; |
|
542 |
||
543 |
y = ((dpi->top - 70) & 0xFC0); |
|
544 |
y2 = ((dpi->top + dpi->height) & 0xFC0); |
|
545 |
||
546 |
for(;;) { |
|
547 |
xb = x; |
|
548 |
for(;;) { |
|
549 |
veh = _vehicle_position_hash[ (x+y)&0xFFFF ]; |
|
550 |
while (veh != INVALID_VEHICLE) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
551 |
v = GetVehicle(veh); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
552 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
553 |
if (!(v->vehstatus & VS_HIDDEN) && |
0 | 554 |
dpi->left <= v->right_coord && |
555 |
dpi->top <= v->bottom_coord && |
|
556 |
dpi->left + dpi->width >= v->left_coord && |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
557 |
dpi->top + dpi->height >= v->top_coord) { |
0 | 558 |
DoDrawVehicle(v); |
559 |
} |
|
560 |
veh = v->next_hash; |
|
561 |
} |
|
562 |
||
563 |
if (x == x2) |
|
564 |
break; |
|
565 |
x = (x + 1) & 0x3F; |
|
566 |
} |
|
567 |
x = xb; |
|
568 |
||
569 |
if (y == y2) |
|
570 |
break; |
|
571 |
y = (y + 0x40) & ((0x3F) << 6); |
|
572 |
} |
|
573 |
} |
|
574 |
||
575 |
static void EffectInit_0(Vehicle *v) |
|
576 |
{ |
|
577 |
uint32 r = Random(); |
|
578 |
v->cur_image = (uint16)((r & 7) + 3701); |
|
579 |
v->progress = (byte)((r >> 16)&7); |
|
580 |
} |
|
581 |
||
582 |
static void EffectTick_0(Vehicle *v) |
|
583 |
{ |
|
584 |
uint tile; |
|
585 |
uint img; |
|
586 |
||
587 |
if (--v->progress & 0x80) { |
|
588 |
BeginVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
589 |
|
0 | 590 |
tile = TILE_FROM_XY(v->x_pos, v->y_pos); |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
591 |
if (!IsTileType(tile, MP_INDUSTRY)) { |
0 | 592 |
EndVehicleMove(v); |
593 |
DeleteVehicle(v); |
|
594 |
return; |
|
595 |
} |
|
596 |
||
597 |
img = v->cur_image + 1; |
|
598 |
if (img > 3708) img = 3701; |
|
599 |
v->cur_image = img; |
|
600 |
v->progress = 7; |
|
601 |
VehiclePositionChanged(v); |
|
602 |
EndVehicleMove(v); |
|
603 |
} |
|
604 |
} |
|
605 |
||
606 |
static void EffectInit_1(Vehicle *v) |
|
607 |
{ |
|
608 |
v->cur_image = 3079; |
|
609 |
v->progress = 12; |
|
610 |
} |
|
611 |
||
612 |
static void EffectTick_1(Vehicle *v) |
|
613 |
{ |
|
614 |
bool moved; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
615 |
|
0 | 616 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
617 |
|
0 | 618 |
moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
619 |
|
0 | 620 |
if ((++v->progress & 7) == 0) { |
621 |
v->z_pos++; |
|
622 |
moved = true; |
|
623 |
} |
|
624 |
||
625 |
if ((v->progress & 0xF)==4) { |
|
626 |
if (++v->cur_image > 3083) { |
|
627 |
EndVehicleMove(v); |
|
628 |
DeleteVehicle(v); |
|
629 |
return; |
|
630 |
} |
|
631 |
moved = true; |
|
632 |
} |
|
633 |
||
634 |
if (moved) { |
|
635 |
VehiclePositionChanged(v); |
|
636 |
EndVehicleMove(v); |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
static void EffectInit_2(Vehicle *v) |
|
641 |
{ |
|
642 |
v->cur_image = 3073; |
|
643 |
v->progress = 0; |
|
644 |
} |
|
645 |
||
646 |
static void EffectTick_2(Vehicle *v) |
|
647 |
{ |
|
648 |
if ((++v->progress & 3) == 0) { |
|
649 |
BeginVehicleMove(v); |
|
650 |
v->z_pos++; |
|
651 |
VehiclePositionChanged(v); |
|
652 |
EndVehicleMove(v); |
|
653 |
} else if ((v->progress & 7) == 1) { |
|
654 |
BeginVehicleMove(v); |
|
655 |
if (++v->cur_image > 3078) { |
|
656 |
EndVehicleMove(v); |
|
657 |
DeleteVehicle(v); |
|
658 |
} else { |
|
659 |
VehiclePositionChanged(v); |
|
660 |
EndVehicleMove(v); |
|
661 |
} |
|
662 |
} |
|
663 |
} |
|
664 |
||
665 |
static void EffectInit_3(Vehicle *v) |
|
666 |
{ |
|
667 |
v->cur_image = 3084; |
|
668 |
v->progress = 1; |
|
669 |
} |
|
670 |
||
671 |
static void EffectTick_3(Vehicle *v) |
|
672 |
{ |
|
673 |
if (++v->progress > 2) { |
|
674 |
v->progress = 0; |
|
675 |
BeginVehicleMove(v); |
|
676 |
if (++v->cur_image > 3089) { |
|
677 |
EndVehicleMove(v); |
|
678 |
DeleteVehicle(v); |
|
679 |
} else { |
|
680 |
VehiclePositionChanged(v); |
|
681 |
EndVehicleMove(v); |
|
682 |
} |
|
683 |
} |
|
684 |
} |
|
685 |
||
686 |
static void EffectInit_4(Vehicle *v) |
|
687 |
{ |
|
688 |
v->cur_image = 2040; |
|
689 |
v->progress = 12; |
|
690 |
} |
|
691 |
||
692 |
static void EffectTick_4(Vehicle *v) |
|
693 |
{ |
|
694 |
bool moved; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
695 |
|
0 | 696 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
697 |
|
0 | 698 |
moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
699 |
|
0 | 700 |
if ((++v->progress & 3) == 0) { |
701 |
v->z_pos++; |
|
702 |
moved = true; |
|
703 |
} |
|
704 |
||
705 |
if ((v->progress & 0xF)==4) { |
|
706 |
if (++v->cur_image > 2044) { |
|
707 |
EndVehicleMove(v); |
|
708 |
DeleteVehicle(v); |
|
709 |
return; |
|
710 |
} |
|
711 |
moved = true; |
|
712 |
} |
|
713 |
||
714 |
if (moved) { |
|
715 |
VehiclePositionChanged(v); |
|
716 |
EndVehicleMove(v); |
|
717 |
} |
|
718 |
} |
|
719 |
||
720 |
static void EffectInit_5(Vehicle *v) |
|
721 |
{ |
|
722 |
v->cur_image = 3709; |
|
723 |
v->progress = 0; |
|
724 |
} |
|
725 |
||
726 |
static void EffectTick_5(Vehicle *v) |
|
727 |
{ |
|
728 |
if (!(++v->progress & 3)) { |
|
729 |
BeginVehicleMove(v); |
|
730 |
if (++v->cur_image > 3724) { |
|
731 |
EndVehicleMove(v); |
|
732 |
DeleteVehicle(v); |
|
733 |
} else { |
|
734 |
VehiclePositionChanged(v); |
|
735 |
EndVehicleMove(v); |
|
736 |
} |
|
737 |
} |
|
738 |
} |
|
739 |
||
740 |
static void EffectInit_6(Vehicle *v) |
|
741 |
{ |
|
742 |
v->cur_image = 3737; |
|
743 |
v->progress = 0; |
|
744 |
} |
|
745 |
||
746 |
static void EffectTick_6(Vehicle *v) |
|
747 |
{ |
|
748 |
if (!(++v->progress & 7)) { |
|
749 |
BeginVehicleMove(v); |
|
750 |
if (++v->cur_image > 3740) v->cur_image = 3737; |
|
751 |
VehiclePositionChanged(v); |
|
752 |
EndVehicleMove(v); |
|
753 |
} |
|
754 |
||
755 |
if (!--v->u.special.unk0) { |
|
756 |
BeginVehicleMove(v); |
|
757 |
EndVehicleMove(v); |
|
758 |
DeleteVehicle(v); |
|
759 |
} |
|
760 |
} |
|
761 |
||
762 |
static void EffectInit_7(Vehicle *v) |
|
763 |
{ |
|
764 |
v->cur_image = 3725; |
|
765 |
v->progress = 0; |
|
766 |
} |
|
767 |
||
768 |
static void EffectTick_7(Vehicle *v) |
|
769 |
{ |
|
770 |
if (!(++v->progress & 3)) { |
|
771 |
BeginVehicleMove(v); |
|
772 |
if (++v->cur_image > 3736) { |
|
773 |
EndVehicleMove(v); |
|
774 |
DeleteVehicle(v); |
|
775 |
} else { |
|
776 |
VehiclePositionChanged(v); |
|
777 |
EndVehicleMove(v); |
|
778 |
} |
|
779 |
} |
|
780 |
} |
|
781 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
782 |
static void BulldozerInit(Vehicle *v) |
0 | 783 |
{ |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
784 |
v->cur_image = SPR_BULLDOZER_NE; |
0 | 785 |
v->progress = 0; |
786 |
v->u.special.unk0 = 0; |
|
787 |
v->u.special.unk2 = 0; |
|
788 |
} |
|
789 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
790 |
typedef struct BulldozerMovement { |
1365
7eff6abe942a
(svn r1869) Fix some bugs in the bulldozer movement implementation.
tron
parents:
1364
diff
changeset
|
791 |
byte direction:2; |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
792 |
byte image:2; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
793 |
byte duration:3; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
794 |
} BulldozerMovement; |
0 | 795 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
796 |
static const BulldozerMovement _bulldozer_movement[] = { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
797 |
{ 0, 0, 4 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
798 |
{ 3, 3, 4 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
799 |
{ 2, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
800 |
{ 0, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
801 |
{ 1, 1, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
802 |
{ 2, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
803 |
{ 0, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
804 |
{ 1, 1, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
805 |
{ 2, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
806 |
{ 0, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
807 |
{ 3, 3, 6 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
808 |
{ 2, 2, 6 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
809 |
{ 1, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
810 |
{ 3, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
811 |
{ 0, 0, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
812 |
{ 1, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
813 |
{ 3, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
814 |
{ 0, 0, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
815 |
{ 1, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
816 |
{ 3, 1, 7 } |
0 | 817 |
}; |
818 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
819 |
static const struct { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
820 |
int8 x; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
821 |
int8 y; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
822 |
} _inc_by_dir[] = { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
823 |
{ -1, 0 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
824 |
{ 0, 1 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
825 |
{ 1, 0 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
826 |
{ 0, -1 } |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
827 |
}; |
0 | 828 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
829 |
static void BulldozerTick(Vehicle *v) |
0 | 830 |
{ |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
831 |
if ((++v->progress & 7) == 0) { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
832 |
const BulldozerMovement* b = &_bulldozer_movement[v->u.special.unk0]; |
0 | 833 |
|
834 |
BeginVehicleMove(v); |
|
835 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
836 |
v->cur_image = SPR_BULLDOZER_NE + b->image; |
0 | 837 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
838 |
v->x_pos += _inc_by_dir[b->direction].x; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
839 |
v->y_pos += _inc_by_dir[b->direction].y; |
0 | 840 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
841 |
v->u.special.unk2++; |
1365
7eff6abe942a
(svn r1869) Fix some bugs in the bulldozer movement implementation.
tron
parents:
1364
diff
changeset
|
842 |
if (v->u.special.unk2 >= b->duration) { |
0 | 843 |
v->u.special.unk2 = 0; |
844 |
v->u.special.unk0++; |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
845 |
if (v->u.special.unk0 == lengthof(_bulldozer_movement)) { |
0 | 846 |
EndVehicleMove(v); |
847 |
DeleteVehicle(v); |
|
848 |
return; |
|
849 |
} |
|
850 |
} |
|
851 |
VehiclePositionChanged(v); |
|
852 |
EndVehicleMove(v); |
|
853 |
} |
|
854 |
} |
|
855 |
||
856 |
static void EffectInit_9(Vehicle *v) |
|
857 |
{ |
|
858 |
v->cur_image = 4751; |
|
859 |
v->spritenum = 0; |
|
860 |
v->progress = 0; |
|
861 |
} |
|
862 |
||
863 |
#define MK(x,y,z,i) (x+4)+(y+4)*16,(z+4)+i*16 |
|
864 |
||
865 |
/* -1,0,1,2 = 2*/ |
|
866 |
/* -1,0,1 = 2*/ |
|
867 |
/* */ |
|
868 |
static const byte _effecttick9_data1[] = { |
|
869 |
MK(0,0,1,0), |
|
870 |
MK(1,0,1,1), |
|
871 |
MK(0,0,1,0), |
|
872 |
MK(1,0,1,2), |
|
873 |
0x81, |
|
874 |
}; |
|
875 |
||
876 |
||
877 |
static const byte _effecttick9_data2[] = { |
|
878 |
MK(0,0,1,0), |
|
879 |
MK(-1,0,1,1), |
|
880 |
MK(0,0,1,0), |
|
881 |
MK(-1,0,1,2), |
|
882 |
0x81, |
|
883 |
}; |
|
884 |
||
885 |
static const byte _effecttick9_data3[] = { |
|
886 |
MK(0,0,1,0), |
|
887 |
MK(0,1,1,1), |
|
888 |
MK(0,0,1,0), |
|
889 |
MK(0,1,1,2), |
|
890 |
0x81, |
|
891 |
}; |
|
892 |
||
893 |
static const byte _effecttick9_data4[] = { |
|
894 |
MK(0,0,1,0), |
|
895 |
MK(0,-1,1,1), |
|
896 |
MK(0,0,1,0), |
|
897 |
MK(0,-1,1,2), |
|
898 |
0x81, |
|
899 |
}; |
|
900 |
||
901 |
static const byte _effecttick9_data5[] = { |
|
902 |
MK(0,0,1,2), |
|
903 |
MK(0,0,1,7), |
|
904 |
MK(0,0,1,8), |
|
905 |
MK(0,0,1,9), |
|
906 |
0x80, |
|
907 |
}; |
|
908 |
||
909 |
static const byte _effecttick9_data6[] = { |
|
910 |
MK(0,0,1,0), |
|
911 |
MK(0,0,1,1), |
|
912 |
MK(0,0,1,0), |
|
913 |
MK(0,0,1,2), |
|
914 |
MK(0,0,1,0), |
|
915 |
MK(0,0,1,1), |
|
916 |
MK(0,0,1,0), |
|
917 |
MK(0,0,1,2), |
|
918 |
MK(0,0,1,0), |
|
919 |
MK(0,0,1,1), |
|
920 |
MK(0,0,1,0), |
|
921 |
MK(0,0,1,2), |
|
922 |
MK(0,0,1,0), |
|
923 |
MK(0,0,1,1), |
|
924 |
MK(0,0,1,0), |
|
925 |
MK(0,0,1,2), |
|
926 |
MK(0,0,1,0), |
|
927 |
MK(0,0,1,1), |
|
928 |
MK(0,0,1,0), |
|
929 |
MK(0,0,1,2), |
|
930 |
MK(0,0,1,0), |
|
931 |
MK(0,0,1,1), |
|
932 |
MK(0,0,1,0), |
|
933 |
MK(0,0,1,2), |
|
934 |
MK(0,0,1,0), |
|
935 |
MK(0,0,1,1), |
|
936 |
MK(0,0,1,0), |
|
937 |
MK(0,0,1,2), |
|
938 |
MK(0,0,1,0), |
|
939 |
MK(0,0,1,1), |
|
940 |
MK(0,0,1,0), |
|
941 |
MK(0,0,1,2), |
|
942 |
MK(0,0,1,0), |
|
943 |
MK(0,0,1,1), |
|
944 |
MK(0,0,1,0), |
|
945 |
MK(0,0,1,2), |
|
946 |
MK(0,0,1,0), |
|
947 |
MK(0,0,1,1), |
|
948 |
MK(0,0,1,0), |
|
949 |
MK(0,0,1,2), |
|
950 |
MK(0,0,1,0), |
|
951 |
MK(0,0,1,1), |
|
952 |
MK(0,0,1,0), |
|
953 |
MK(0,0,1,2), |
|
954 |
MK(0,0,1,0), |
|
955 |
MK(0,0,1,1), |
|
956 |
MK(0,0,1,0), |
|
957 |
MK(0,0,1,2), |
|
958 |
MK(0,0,1,0), |
|
959 |
MK(0,0,1,1), |
|
960 |
MK(0,0,1,0), |
|
961 |
MK(0,0,1,2), |
|
962 |
MK(0,0,1,0), |
|
963 |
MK(0,0,1,1), |
|
964 |
MK(0,0,1,0), |
|
965 |
MK(0,0,1,2), |
|
966 |
MK(0,0,1,0), |
|
967 |
MK(0,0,1,1), |
|
968 |
MK(0,0,1,0), |
|
969 |
MK(0,0,1,2), |
|
970 |
MK(0,0,1,0), |
|
971 |
MK(0,0,1,1), |
|
972 |
MK(2,1,3,0), |
|
973 |
MK(1,1,3,1), |
|
974 |
MK(2,1,3,0), |
|
975 |
MK(1,1,3,2), |
|
976 |
MK(2,1,3,0), |
|
977 |
MK(1,1,3,1), |
|
978 |
MK(2,1,3,0), |
|
979 |
MK(1,0,1,2), |
|
980 |
MK(0,0,1,0), |
|
981 |
MK(1,0,1,1), |
|
982 |
MK(0,0,1,0), |
|
983 |
MK(1,0,1,2), |
|
984 |
MK(0,0,1,0), |
|
985 |
MK(1,0,1,1), |
|
986 |
MK(0,0,1,0), |
|
987 |
MK(1,0,1,2), |
|
988 |
0x82,0, |
|
989 |
MK(0,0,0,0xA), |
|
990 |
MK(0,0,0,0xB), |
|
991 |
MK(0,0,0,0xC), |
|
992 |
MK(0,0,0,0xD), |
|
993 |
MK(0,0,0,0xE), |
|
994 |
0x80 |
|
995 |
}; |
|
996 |
#undef MK |
|
997 |
||
998 |
static const byte * const _effecttick9_data[6] = { |
|
999 |
_effecttick9_data1, |
|
1000 |
_effecttick9_data2, |
|
1001 |
_effecttick9_data3, |
|
1002 |
_effecttick9_data4, |
|
1003 |
_effecttick9_data5, |
|
1004 |
_effecttick9_data6, |
|
1005 |
}; |
|
1006 |
||
1007 |
static void EffectTick_9(Vehicle *v) |
|
1008 |
{ |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1009 |
/* |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1010 |
* Warning: those effects can NOT use Random(), and have to use |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1011 |
* InteractiveRandom(), because somehow someone forgot to save |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1012 |
* spritenum to the savegame, and so it will cause desyncs in |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1013 |
* multiplayer!! (that is: in ToyLand) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1014 |
*/ |
0 | 1015 |
int et; |
1016 |
const byte *b; |
|
1017 |
||
1018 |
if (((++v->progress)&3) != 0) |
|
1019 |
return; |
|
1020 |
||
1021 |
BeginVehicleMove(v); |
|
1022 |
||
1023 |
et = v->engine_type + 1; |
|
1024 |
||
1025 |
if (v->spritenum == 0) { |
|
1026 |
if (++v->cur_image < 4754) { |
|
1027 |
VehiclePositionChanged(v); |
|
1028 |
EndVehicleMove(v); |
|
1029 |
return; |
|
1030 |
} |
|
1031 |
if (v->u.special.unk2 != 0) { |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1032 |
v->spritenum = (byte)((InteractiveRandom()&3)+1); |
0 | 1033 |
} else { |
1034 |
v->spritenum = 6; |
|
1035 |
} |
|
1036 |
et = 0; |
|
1037 |
} |
|
1038 |
||
1039 |
again: |
|
1040 |
v->engine_type = et; |
|
1041 |
b = &_effecttick9_data[v->spritenum - 1][et*2]; |
|
1042 |
||
1043 |
if (*b == 0x80) { |
|
1044 |
EndVehicleMove(v); |
|
1045 |
DeleteVehicle(v); |
|
1046 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1047 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1048 |
|
0 | 1049 |
if (*b == 0x81) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1050 |
if (v->z_pos > 180 || CHANCE16I(1,96, InteractiveRandom())) { |
0 | 1051 |
v->spritenum = 5; |
541 | 1052 |
SndPlayVehicleFx(SND_2F_POP, v); |
0 | 1053 |
} |
1054 |
et = 0; |
|
1055 |
goto again; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1056 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1057 |
|
0 | 1058 |
if (*b == 0x82) { |
1059 |
uint tile; |
|
1060 |
||
1061 |
et++; |
|
541 | 1062 |
SndPlayVehicleFx(SND_31_EXTRACT, v); |
0 | 1063 |
|
1064 |
tile = TILE_FROM_XY(v->x_pos, v->y_pos); |
|
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1065 |
if (IsTileType(tile, MP_INDUSTRY) && |
0 | 1066 |
_map5[tile]==0xA2) { |
1067 |
AddAnimatedTile(tile); |
|
1068 |
} |
|
1069 |
goto again; |
|
1070 |
} |
|
1071 |
||
1072 |
v->x_pos += (b[0]&0xF) - 4; |
|
1073 |
v->y_pos += (b[0]>>4) - 4; |
|
1074 |
v->z_pos += (b[1]&0xF) - 4; |
|
1075 |
v->cur_image = 4748 + (b[1] >> 4); |
|
1076 |
||
1077 |
VehiclePositionChanged(v); |
|
1078 |
EndVehicleMove(v); |
|
1079 |
} |
|
1080 |
||
1081 |
||
1082 |
typedef void EffectInitProc(Vehicle *v); |
|
1083 |
typedef void EffectTickProc(Vehicle *v); |
|
1084 |
||
1085 |
static EffectInitProc * const _effect_init_procs[] = { |
|
1086 |
EffectInit_0, |
|
1087 |
EffectInit_1, |
|
1088 |
EffectInit_2, |
|
1089 |
EffectInit_3, |
|
1090 |
EffectInit_4, |
|
1091 |
EffectInit_5, |
|
1092 |
EffectInit_6, |
|
1093 |
EffectInit_7, |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1094 |
BulldozerInit, |
0 | 1095 |
EffectInit_9, |
1096 |
}; |
|
1097 |
||
1098 |
static EffectTickProc * const _effect_tick_procs[] = { |
|
1099 |
EffectTick_0, |
|
1100 |
EffectTick_1, |
|
1101 |
EffectTick_2, |
|
1102 |
EffectTick_3, |
|
1103 |
EffectTick_4, |
|
1104 |
EffectTick_5, |
|
1105 |
EffectTick_6, |
|
1106 |
EffectTick_7, |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1107 |
BulldozerTick, |
0 | 1108 |
EffectTick_9, |
1109 |
}; |
|
1110 |
||
1111 |
||
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1349
diff
changeset
|
1112 |
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type) |
0 | 1113 |
{ |
1114 |
Vehicle *v; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1115 |
|
0 | 1116 |
v = ForceAllocateSpecialVehicle(); |
1117 |
if (v != NULL) { |
|
1118 |
v->type = VEH_Special; |
|
1119 |
v->subtype = type; |
|
1120 |
v->x_pos = x; |
|
1121 |
v->y_pos = y; |
|
1122 |
v->z_pos = z; |
|
1123 |
v->z_height = v->sprite_width = v->sprite_height = 1; |
|
1124 |
v->x_offs = v->y_offs = 0; |
|
1125 |
v->tile = 0; |
|
1126 |
v->vehstatus = VS_UNCLICKABLE; |
|
1127 |
||
1128 |
_effect_init_procs[type](v); |
|
1129 |
||
1130 |
VehiclePositionChanged(v); |
|
1131 |
BeginVehicleMove(v); |
|
1132 |
EndVehicleMove(v); |
|
1133 |
} |
|
1134 |
return v; |
|
1135 |
} |
|
1136 |
||
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1349
diff
changeset
|
1137 |
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type) |
0 | 1138 |
{ |
1139 |
return CreateEffectVehicle(x, y, GetSlopeZ(x, y) + z, type); |
|
1140 |
} |
|
1141 |
||
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1349
diff
changeset
|
1142 |
Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type) |
0 | 1143 |
{ |
1144 |
return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type); |
|
1145 |
} |
|
1146 |
||
410 | 1147 |
static void EffectVehicle_Tick(Vehicle *v) |
0 | 1148 |
{ |
1149 |
_effect_tick_procs[v->subtype](v); |
|
1150 |
} |
|
1151 |
||
1152 |
Vehicle *CheckClickOnVehicle(ViewPort *vp, int x, int y) |
|
1153 |
{ |
|
1154 |
Vehicle *found = NULL, *v; |
|
1155 |
uint dist, best_dist = (uint)-1; |
|
1156 |
||
1157 |
if ( (uint)(x -= vp->left) >= (uint)vp->width || |
|
1158 |
(uint)(y -= vp->top) >= (uint)vp->height) |
|
1159 |
return NULL; |
|
1160 |
||
1161 |
x = (x << vp->zoom) + vp->virtual_left; |
|
1162 |
y = (y << vp->zoom) + vp->virtual_top; |
|
1163 |
||
1164 |
FOR_ALL_VEHICLES(v) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1165 |
if (v->type != 0 && (v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0 && |
0 | 1166 |
x >= v->left_coord && x <= v->right_coord && |
1167 |
y >= v->top_coord && y <= v->bottom_coord) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1168 |
|
0 | 1169 |
dist = max( |
1170 |
myabs( ((v->left_coord + v->right_coord)>>1) - x ), |
|
1171 |
myabs( ((v->top_coord + v->bottom_coord)>>1) - y ) |
|
1172 |
); |
|
1173 |
||
1174 |
if (dist < best_dist) { |
|
1175 |
found = v; |
|
1176 |
best_dist = dist; |
|
1177 |
} |
|
1178 |
} |
|
1179 |
} |
|
1180 |
||
1181 |
return found; |
|
1182 |
} |
|
1183 |
||
1184 |
||
1185 |
void DecreaseVehicleValue(Vehicle *v) |
|
1186 |
{ |
|
1187 |
v->value -= v->value >> 8; |
|
1188 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1189 |
} |
|
1190 |
||
1191 |
static const byte _breakdown_chance[64] = { |
|
1192 |
3, 3, 3, 3, 3, 3, 3, 3, |
|
1193 |
4, 4, 5, 5, 6, 6, 7, 7, |
|
1194 |
8, 8, 9, 9, 10, 10, 11, 11, |
|
1195 |
12, 13, 13, 13, 13, 14, 15, 16, |
|
1196 |
17, 19, 21, 25, 28, 31, 34, 37, |
|
1197 |
40, 44, 48, 52, 56, 60, 64, 68, |
|
1198 |
72, 80, 90, 100, 110, 120, 130, 140, |
|
1199 |
150, 170, 190, 210, 230, 250, 250, 250, |
|
1200 |
}; |
|
1201 |
||
1202 |
void CheckVehicleBreakdown(Vehicle *v) |
|
1203 |
{ |
|
1204 |
int rel, rel_old; |
|
1205 |
uint32 r; |
|
1206 |
int chance; |
|
1207 |
||
1208 |
/* decrease reliability */ |
|
1209 |
v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0); |
|
1210 |
if ((rel_old >> 8) != (rel >> 8)) |
|
1211 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1212 |
||
1213 |
if (v->breakdown_ctr != 0 || (v->vehstatus & VS_STOPPED) != 0 || |
|
1214 |
v->cur_speed < 5 || _game_mode == GM_MENU) |
|
1215 |
return; |
|
1216 |
||
1217 |
r = Random(); |
|
1218 |
||
1219 |
/* increase chance of failure */ |
|
1220 |
chance = v->breakdown_chance + 1; |
|
1221 |
if (CHANCE16I(1,25,r)) chance += 25; |
|
1222 |
v->breakdown_chance = min(255, chance); |
|
1223 |
||
1224 |
/* calculate reliability value to use in comparison */ |
|
1225 |
rel = v->reliability; |
|
1226 |
if (v->type == VEH_Ship) rel += 0x6666; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1227 |
|
0 | 1228 |
/* disabled breakdowns? */ |
1229 |
if (_opt.diff.vehicle_breakdowns < 1) |
|
1230 |
return; |
|
1231 |
||
1232 |
/* reduced breakdowns? */ |
|
1233 |
if (_opt.diff.vehicle_breakdowns == 1) rel += 0x6666; |
|
1234 |
||
1235 |
/* check if to break down */ |
|
1236 |
if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) { |
|
1237 |
v->breakdown_ctr = (byte)(((r >> 16) & 0x3F) + 0x3F); |
|
1238 |
v->breakdown_delay = (byte)(((r >> 24) & 0x7F) | 0x80); |
|
1239 |
v->breakdown_chance = 0; |
|
1240 |
} |
|
1241 |
} |
|
1242 |
||
1243 |
static const StringID _vehicle_type_names[4] = { |
|
1244 |
STR_019F_TRAIN, |
|
1245 |
STR_019C_ROAD_VEHICLE, |
|
1246 |
STR_019E_SHIP, |
|
1247 |
STR_019D_AIRCRAFT, |
|
1248 |
}; |
|
1249 |
||
1250 |
static void ShowVehicleGettingOld(Vehicle *v, StringID msg) |
|
1251 |
{ |
|
1252 |
if (v->owner != _local_player) |
|
1253 |
return; |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1254 |
|
26 | 1255 |
// Do not show getting-old message if autorenew is active |
1256 |
if (_patches.autorenew) |
|
1257 |
return; |
|
0 | 1258 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1259 |
SetDParam(0, _vehicle_type_names[v->type - 0x10]); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1260 |
SetDParam(1, v->unitnumber); |
0 | 1261 |
AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
1262 |
} |
|
1263 |
||
1264 |
void AgeVehicle(Vehicle *v) |
|
1265 |
{ |
|
1266 |
int age; |
|
1267 |
||
1268 |
if (v->age < 65535) |
|
1269 |
v->age++; |
|
1270 |
||
1271 |
age = v->age - v->max_age; |
|
1272 |
if (age == 366*0 || age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1273 |
v->reliability_spd_dec <<= 1; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1274 |
|
0 | 1275 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
1276 |
||
1277 |
if (age == -366) { |
|
1278 |
ShowVehicleGettingOld(v, STR_01A0_IS_GETTING_OLD); |
|
1279 |
} else if (age == 0) { |
|
1280 |
ShowVehicleGettingOld(v, STR_01A1_IS_GETTING_VERY_OLD); |
|
1281 |
} else if (age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4 || age == 366*5) { |
|
1282 |
ShowVehicleGettingOld(v, STR_01A2_IS_GETTING_VERY_OLD_AND); |
|
1283 |
} |
|
1284 |
} |
|
1285 |
||
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1286 |
extern int32 EstimateTrainCost(const RailVehicleInfo *rvi); |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1287 |
extern int32 EstimateRoadVehCost(byte engine_type); |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1288 |
extern int32 EstimateShipCost(uint16 engine_type); |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1289 |
extern int32 EstimateAircraftCost(uint16 engine_type); |
842 | 1290 |
extern int32 CmdRefitRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
1291 |
extern int32 CmdRefitShip(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
|
1292 |
extern int32 CmdRefitAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1293 |
|
842 | 1294 |
/* Replaces a vehicle (used to be called autorenew) |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1295 |
p1 - Index of vehicle |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1296 |
p2 - Type of new engine */ |
842 | 1297 |
int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
0 | 1298 |
{ |
842 | 1299 |
/* makesvariables to inform about how much money the player wants to have left after replacing |
1300 |
and which engine to replace with out of p2. |
|
1301 |
the first 16 bit is the money. The last 5 digits (all 0) were removed when sent, so we add them again. |
|
1302 |
This way the max is 6553 millions and it is more than the 32 bit that is stored in _patches |
|
1303 |
This is a nice way to send 32 bit and only use 16 bit |
|
1304 |
the last 8 bit is the engine. The 8 bits in front of the engine is free so it have room for 16 bit engine entries */ |
|
1305 |
uint16 new_engine_type = (uint16)(p2 & 0xFFFF); |
|
915 | 1306 |
uint32 autorefit_money = (p2 >> 16) * 100000; |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
1307 |
Vehicle *v, *u; |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1308 |
int cost, build_cost, rear_engine_cost = 0; |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
1309 |
byte old_engine_type; |
889
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
842
diff
changeset
|
1310 |
|
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
1311 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
915 | 1312 |
|
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
1313 |
v = u = GetVehicle(p1); |
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
1314 |
|
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
1315 |
old_engine_type = v->engine_type; |
915 | 1316 |
|
890
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1317 |
// first we make sure that it's a valid type the user requested |
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1318 |
// check that it's an engine that is in the engine array |
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1319 |
if (new_engine_type >= TOTAL_NUM_ENGINES ) return CMD_ERROR; |
915 | 1320 |
|
890
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1321 |
// check that the new vehicle type is the same as the original one |
907
60cb7cfb0580
(svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
bjarni
parents:
892
diff
changeset
|
1322 |
if (v->type != DEREF_ENGINE(new_engine_type)->type) return CMD_ERROR; |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1323 |
|
890
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1324 |
// check that it's the vehicle's owner that requested the replace |
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1325 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1326 |
|
1185
08d48bad089c
(svn r1687) - Feature: [autoreplace] server now checks for plane<->helicopter replacement and reject replacement if needed
bjarni
parents:
1174
diff
changeset
|
1327 |
// makes sure that we do not replace a plane with a helicopter or vise versa |
1187
4ee23281d3a5
(svn r1690) - Fix: [autoreplace] Cheaters can no longer exploit autoreplace to get vehicles, that's not invented yet
bjarni
parents:
1185
diff
changeset
|
1328 |
if (v->type == VEH_Aircraft) { |
4ee23281d3a5
(svn r1690) - Fix: [autoreplace] Cheaters can no longer exploit autoreplace to get vehicles, that's not invented yet
bjarni
parents:
1185
diff
changeset
|
1329 |
if (HASBIT(AircraftVehInfo(old_engine_type)->subtype, 0) != HASBIT(AircraftVehInfo(new_engine_type)->subtype, 0)) return CMD_ERROR; |
4ee23281d3a5
(svn r1690) - Fix: [autoreplace] Cheaters can no longer exploit autoreplace to get vehicles, that's not invented yet
bjarni
parents:
1185
diff
changeset
|
1330 |
} |
1185
08d48bad089c
(svn r1687) - Feature: [autoreplace] server now checks for plane<->helicopter replacement and reject replacement if needed
bjarni
parents:
1174
diff
changeset
|
1331 |
|
1187
4ee23281d3a5
(svn r1690) - Fix: [autoreplace] Cheaters can no longer exploit autoreplace to get vehicles, that's not invented yet
bjarni
parents:
1185
diff
changeset
|
1332 |
// makes sure that the player can actually buy the new engine. Renewing is still allowed to outdated engines |
4ee23281d3a5
(svn r1690) - Fix: [autoreplace] Cheaters can no longer exploit autoreplace to get vehicles, that's not invented yet
bjarni
parents:
1185
diff
changeset
|
1333 |
if (!HASBIT(DEREF_ENGINE(new_engine_type)->player_avail, v->owner) && old_engine_type != new_engine_type) return CMD_ERROR; |
890
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1334 |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1335 |
switch (v->type) { |
842 | 1336 |
case VEH_Train: build_cost = EstimateTrainCost(RailVehInfo(new_engine_type)); break; |
1337 |
case VEH_Road: build_cost = EstimateRoadVehCost(new_engine_type); break; |
|
1338 |
case VEH_Ship: build_cost = EstimateShipCost(new_engine_type); break; |
|
1339 |
case VEH_Aircraft: build_cost = EstimateAircraftCost(new_engine_type); break; |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1340 |
default: return CMD_ERROR; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1341 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1342 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1343 |
/* In a rare situation, when 2 clients are connected to 1 company and have the same |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1344 |
settings, a vehicle can be replaced twice.. check if this is the situation here */ |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1345 |
if (old_engine_type == new_engine_type && v->age == 0) |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1346 |
return CMD_ERROR; |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1347 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1348 |
if ( v->type == VEH_Train ) { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1349 |
u = GetLastVehicleInChain(v); |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1350 |
if ( RailVehInfo(new_engine_type)->flags & RVI_MULTIHEAD ) |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1351 |
build_cost = build_cost >> 1; //multiheaded engines have EstimateTrainCost() for both engines |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1352 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1353 |
if ( old_engine_type != new_engine_type ) { |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1354 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1355 |
// prevent that the rear engine can get replaced to something else than the front engine |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1356 |
if ( v->u.rail.first_engine != 0xffff && RailVehInfo(old_engine_type)->flags & RVI_MULTIHEAD && RailVehInfo(old_engine_type)->flags ) { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1357 |
Vehicle *first = GetFirstVehicleInChain(v); |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1358 |
if ( first->engine_type != new_engine_type ) return CMD_ERROR; |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1359 |
} |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1360 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1361 |
// checks if the engine is the first one |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1362 |
if ( v->u.rail.first_engine == 0xffff ) { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1363 |
if ( RailVehInfo(new_engine_type)->flags & RVI_MULTIHEAD ) { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1364 |
if ( u->engine_type == old_engine_type && v->next != NULL) { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1365 |
rear_engine_cost = build_cost - u->value; |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1366 |
} else { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1367 |
rear_engine_cost = build_cost; |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1368 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1369 |
} else { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1370 |
if ( u->engine_type == old_engine_type && RailVehInfo(old_engine_type)->flags & RVI_MULTIHEAD) { |
1068 | 1371 |
if (v->next != NULL) rear_engine_cost = -(int32)u->value; |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1372 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1373 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1374 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1375 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1376 |
} |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1377 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1378 |
/* Check if there is money for the upgrade.. if not, give a nice news-item |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1379 |
(that is needed, because this CMD is called automaticly) */ |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1380 |
if ( DEREF_PLAYER(v->owner)->money64 < (int32)(autorefit_money + build_cost + rear_engine_cost - v->value)) { |
842 | 1381 |
if (( _local_player == v->owner ) && ( v->unitnumber != 0 )) { //v->unitnumber = 0 for train cars |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1382 |
int message; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1383 |
SetDParam(0, v->unitnumber); |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1384 |
switch (v->type) { |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1385 |
case VEH_Train: message = STR_TRAIN_AUTORENEW_FAILED; break; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1386 |
case VEH_Road: message = STR_ROADVEHICLE_AUTORENEW_FAILED; break; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1387 |
case VEH_Ship: message = STR_SHIP_AUTORENEW_FAILED; break; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1388 |
case VEH_Aircraft: message = STR_AIRCRAFT_AUTORENEW_FAILED; break; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1389 |
// This should never happen |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1390 |
default: message = 0; break; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1391 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1392 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1393 |
AddNewsItem(message, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1394 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1395 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1396 |
return CMD_ERROR; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1397 |
} |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1398 |
cost = build_cost - v->value + rear_engine_cost; |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1399 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1400 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1401 |
if (flags & DC_EXEC) { |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1402 |
/* We do not really buy a new vehicle, we upgrade the old one */ |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1403 |
Engine *e; |
907
60cb7cfb0580
(svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
bjarni
parents:
892
diff
changeset
|
1404 |
e = DEREF_ENGINE(new_engine_type); |
915 | 1405 |
|
1139
c63f257aa7fb
(svn r1640) fix: now helicopters will use a hangar in schedule to be replaced in, even if they are only set to service there. Since helicopters are serviced at helipads, they will only go there if they needs to be replaced or renewed.
bjarni
parents:
1128
diff
changeset
|
1406 |
v->set_for_replacement = false; |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1407 |
v->reliability = e->reliability; |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1408 |
v->reliability_spd_dec = e->reliability_spd_dec; |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1409 |
v->age = 0; |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1410 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1411 |
v->date_of_last_service = _date; |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1412 |
v->build_year = _cur_year; |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1413 |
|
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1414 |
v->value = build_cost; |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1415 |
|
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1416 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1417 |
|
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1418 |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1419 |
if (v->engine_type != new_engine_type) { |
933
90817bb28f1d
(svn r1421) improved autoreplace multiheaded trains. It now remembers the current heading for an engine instead of turning all of them like the first one and the last the other way
bjarni
parents:
931
diff
changeset
|
1420 |
byte sprite = v->spritenum; |
842 | 1421 |
byte cargo_type = v->cargo_type; |
1422 |
v->engine_type = new_engine_type; |
|
1423 |
v->max_age = e->lifelength * 366; |
|
915 | 1424 |
|
842 | 1425 |
/* Update limits of the vehicle (for when upgraded) */ |
1426 |
switch (v->type) { |
|
1427 |
case VEH_Train: |
|
1428 |
{ |
|
1429 |
const RailVehicleInfo *rvi = RailVehInfo(new_engine_type); |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1430 |
const RailVehicleInfo *rvi2 = RailVehInfo(old_engine_type); |
842 | 1431 |
byte capacity = rvi->capacity; |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1432 |
Vehicle *first = GetFirstVehicleInChain(v); |
842 | 1433 |
|
1128
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1111
diff
changeset
|
1434 |
//if (v->owner == _local_player) InvalidateWindowClasses(WC_TRAINS_LIST); |
933
90817bb28f1d
(svn r1421) improved autoreplace multiheaded trains. It now remembers the current heading for an engine instead of turning all of them like the first one and the last the other way
bjarni
parents:
931
diff
changeset
|
1435 |
/* rvi->image_index is the new sprite for the engine. Adding +1 makes the engine head the other way |
90817bb28f1d
(svn r1421) improved autoreplace multiheaded trains. It now remembers the current heading for an engine instead of turning all of them like the first one and the last the other way
bjarni
parents:
931
diff
changeset
|
1436 |
if it is a multiheaded engine (rear engine) |
939
68f8d6560c23
(svn r1427) fixed issue where the wrong sprite could be used if autoreplacing between single and multiheaded trains
bjarni
parents:
938
diff
changeset
|
1437 |
(rvi->flags & RVI_MULTIHEAD && sprite - rvi2->image_index) is true if the engine is heading the other way, otherwise 0*/ |
68f8d6560c23
(svn r1427) fixed issue where the wrong sprite could be used if autoreplacing between single and multiheaded trains
bjarni
parents:
938
diff
changeset
|
1438 |
v->spritenum = rvi->image_index + (( rvi->flags & RVI_MULTIHEAD && sprite - rvi2->image_index) ? 1 : 0); |
941
4a695e126035
(svn r1429) Change: bumped savegame to revision 5.
truelight
parents:
939
diff
changeset
|
1439 |
|
939
68f8d6560c23
(svn r1427) fixed issue where the wrong sprite could be used if autoreplacing between single and multiheaded trains
bjarni
parents:
938
diff
changeset
|
1440 |
// turn the last engine in a multiheaded train if needed |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1441 |
if ( v->next == NULL && v->u.rail.first_engine != 0xffff && rvi->flags & RVI_MULTIHEAD && v->spritenum == rvi->image_index ) |
939
68f8d6560c23
(svn r1427) fixed issue where the wrong sprite could be used if autoreplacing between single and multiheaded trains
bjarni
parents:
938
diff
changeset
|
1442 |
v->spritenum++; |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1443 |
|
842 | 1444 |
v->cargo_type = rvi->cargo_type; |
1445 |
v->cargo_cap = rvi->capacity; |
|
1446 |
v->max_speed = rvi->max_speed; |
|
1447 |
||
1448 |
v->u.rail.railtype = e->railtype; |
|
915 | 1449 |
|
842 | 1450 |
// 0x0100 means that we skip the check for being stopped inside the depot |
1451 |
// since we do not stop it for autorefitting |
|
1452 |
if (v->cargo_type != cargo_type && capacity) { |
|
1453 |
// BUG: somehow v->index is not transfered properly |
|
1454 |
//CmdRefitRailVehicle(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 ); |
|
1455 |
v->cargo_type = cargo_type; // workaround, but it do not check the refit table |
|
1456 |
} else { |
|
1457 |
v->cargo_type = rvi->cargo_type; |
|
1458 |
} |
|
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1459 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1460 |
if ( rvi2->flags & RVI_MULTIHEAD && !(rvi->flags & RVI_MULTIHEAD) && v->index == first->index) { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1461 |
if (old_engine_type == u->engine_type ) { |
1063
03fed43e58fc
(svn r1564) ISO C90 forbids mixed declarations and code (bad bjarni, no cookie)
tron
parents:
1062
diff
changeset
|
1462 |
Vehicle *w; |
03fed43e58fc
(svn r1564) ISO C90 forbids mixed declarations and code (bad bjarni, no cookie)
tron
parents:
1062
diff
changeset
|
1463 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1464 |
u = GetLastVehicleInChain(v); |
1063
03fed43e58fc
(svn r1564) ISO C90 forbids mixed declarations and code (bad bjarni, no cookie)
tron
parents:
1062
diff
changeset
|
1465 |
w = GetPrevVehicleInChain(u); |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1466 |
w->next = NULL; |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1467 |
DeleteVehicle(u); |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1468 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1469 |
} |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1470 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1471 |
if ( rvi->flags & RVI_MULTIHEAD && rvi2->flags & RVI_MULTIHEAD && v->index == first->index ) { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1472 |
CmdReplaceVehicle(x, y, flags, u->index, p2); |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1473 |
} |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1474 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1475 |
if ( rvi->flags & RVI_MULTIHEAD && !(rvi2->flags & RVI_MULTIHEAD) && v->index == first->index ) { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1476 |
if ( old_engine_type != u->engine_type ) { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1477 |
Vehicle *w; |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1478 |
if ( (w=AllocateVehicle()) != NULL ) { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1479 |
AddRearEngineToMultiheadedTrain(v,w, false); |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1480 |
u->next = w; |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1481 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1482 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1483 |
} |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1484 |
|
1062
4131a8dfde94
(svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents:
1060
diff
changeset
|
1485 |
// updates the id of the front engine in the other units, since the front engine just got a new engine_id |
4131a8dfde94
(svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents:
1060
diff
changeset
|
1486 |
// this is needed for wagon override |
4131a8dfde94
(svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents:
1060
diff
changeset
|
1487 |
if ( v->u.rail.first_engine == 0xffff && v->next != NULL ) { |
4131a8dfde94
(svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents:
1060
diff
changeset
|
1488 |
Vehicle *veh = v->next; |
4131a8dfde94
(svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents:
1060
diff
changeset
|
1489 |
do { |
4131a8dfde94
(svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents:
1060
diff
changeset
|
1490 |
veh->u.rail.first_engine = new_engine_type; |
4131a8dfde94
(svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents:
1060
diff
changeset
|
1491 |
} while ( (veh=veh->next) != NULL ); |
4131a8dfde94
(svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents:
1060
diff
changeset
|
1492 |
} |
1128
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1111
diff
changeset
|
1493 |
InvalidateWindowClasses(WC_TRAINS_LIST); |
842 | 1494 |
break; |
1495 |
} |
|
1496 |
case VEH_Road: |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1497 |
{ |
842 | 1498 |
const RoadVehicleInfo *rvi = RoadVehInfo(new_engine_type); |
1499 |
||
1500 |
v->spritenum = rvi->image_index; |
|
1501 |
v->cargo_type = rvi->cargo_type; |
|
1502 |
v->cargo_cap = rvi->capacity; |
|
1503 |
v->max_speed = rvi->max_speed; |
|
1128
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1111
diff
changeset
|
1504 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
842 | 1505 |
break; |
1506 |
} |
|
1507 |
case VEH_Ship: |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1508 |
{ |
842 | 1509 |
const ShipVehicleInfo *svi = ShipVehInfo(new_engine_type); |
1510 |
||
1511 |
v->spritenum = svi->image_index; |
|
1512 |
v->cargo_type = svi->cargo_type; |
|
1513 |
v->cargo_cap = svi->capacity; |
|
1514 |
v->max_speed = svi->max_speed; |
|
915 | 1515 |
|
842 | 1516 |
// 0x0100 means that we skip the check for being stopped inside the depot |
1517 |
// since we do not stop it for autorefitting |
|
1518 |
if (v->cargo_type != cargo_type) |
|
1519 |
CmdRefitShip(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 ); |
|
1128
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1111
diff
changeset
|
1520 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
842 | 1521 |
break; |
1522 |
} |
|
1523 |
case VEH_Aircraft: |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1524 |
{ |
842 | 1525 |
const AircraftVehicleInfo *avi = AircraftVehInfo(new_engine_type); |
1526 |
Vehicle *u; |
|
1527 |
||
1528 |
v->max_speed = avi->max_speed; |
|
1529 |
v->acceleration = avi->acceleration; |
|
1530 |
v->spritenum = avi->image_index; |
|
1531 |
||
1532 |
if ( cargo_type == CT_PASSENGERS ) { |
|
922
fc040662bd43
(svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents:
919
diff
changeset
|
1533 |
v->cargo_cap = avi->passenger_capacity; |
842 | 1534 |
u = v->next; |
1535 |
u->cargo_cap = avi->mail_capacity; |
|
1536 |
} else { |
|
1537 |
// 0x0100 means that we skip the check for being stopped inside the hangar |
|
1538 |
// since we do not stop it for autorefitting |
|
1539 |
CmdRefitAircraft(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 ); |
|
1540 |
} |
|
1128
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1111
diff
changeset
|
1541 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
842 | 1542 |
break; |
1543 |
} |
|
1544 |
default: return CMD_ERROR; |
|
1545 |
} |
|
1546 |
// makes sure that the cargo is still valid compared to new capacity |
|
1547 |
if (v->cargo_count != 0) { |
|
1548 |
if ( v->cargo_type != cargo_type ) |
|
1549 |
v->cargo_count = 0; |
|
1550 |
else if ( v->cargo_count > v->cargo_cap ) |
|
1551 |
v->cargo_count = v->cargo_cap; |
|
1552 |
} |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1553 |
} |
1128
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1111
diff
changeset
|
1554 |
InvalidateWindow(WC_REPLACE_VEHICLE, v->type); |
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1111
diff
changeset
|
1555 |
ResortVehicleLists(); |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1556 |
} |
842 | 1557 |
//needs to be down here because refitting will change SET_EXPENSES_TYPE if called |
1558 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1559 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1560 |
return cost; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1561 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1562 |
|
842 | 1563 |
void MaybeReplaceVehicle(Vehicle *v) |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1564 |
{ |
842 | 1565 |
uint32 new_engine_and_autoreplace_money; |
915 | 1566 |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1567 |
if (v->owner != _local_player) |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1568 |
return; |
842 | 1569 |
// uncomment next line if you want to see what engine type just entered a depot |
1570 |
//printf("engine type: %d\n", v->engine_type); |
|
0 | 1571 |
|
26 | 1572 |
// A vehicle is autorenewed when it it gets the amount of months |
1573 |
// give by _patches.autorenew_months away for his max age. |
|
1574 |
// Standard is -6, meaning 6 months before his max age |
|
1575 |
// It can be any value between -12 and 12. |
|
842 | 1576 |
// Here it also checks if the vehicles is listed for replacement |
1577 |
if (!_patches.autorenew || v->age - v->max_age < (_patches.autorenew_months * 30)) { //replace if engine is too old |
|
1578 |
if (_autoreplace_array[v->engine_type] == v->engine_type && v->type != VEH_Train) //updates to a new model |
|
1579 |
return; |
|
1580 |
} |
|
1581 |
/* Now replace the vehicle */ |
|
829
b71111ccf2cc
(svn r1300) -Fix: The cost for an autorenew was not always send to the right player ;)
truelight
parents:
826
diff
changeset
|
1582 |
_current_player = v->owner; |
915 | 1583 |
|
842 | 1584 |
/* makes the variable to inform about how much money the player wants to have left after replacing |
1585 |
and which engine to replace with |
|
1586 |
the first 16 bit is the money. Since we know the last 5 digits is 0, they are thrown away. |
|
1587 |
This way the max is 6553 millions and it is more than the 32 bit that is stored in _patches |
|
1588 |
This is a nice way to send 32 bit and only use 16 bit |
|
1589 |
the last 8 bit is the engine. The 8 bits in front of the engine is free so it have room for 16 bit engine entries */ |
|
892
3e5dd4c4d5b3
(svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents:
890
diff
changeset
|
1590 |
new_engine_and_autoreplace_money = ((_patches.autorenew_money / 100000) << 16) + _autoreplace_array[v->engine_type]; |
915 | 1591 |
|
907
60cb7cfb0580
(svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
bjarni
parents:
892
diff
changeset
|
1592 |
assert(v->type == DEREF_ENGINE(_autoreplace_array[v->engine_type])->type); |
915 | 1593 |
|
842 | 1594 |
if ( v->type != VEH_Train ) { |
1595 |
DoCommandP(v->tile, v->index, new_engine_and_autoreplace_money, NULL, CMD_REPLACE_VEHICLE | CMD_SHOW_NO_ERROR); |
|
1596 |
} else { |
|
892
3e5dd4c4d5b3
(svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents:
890
diff
changeset
|
1597 |
// checks if any of the engines in the train are either old or listed for replacement |
3e5dd4c4d5b3
(svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents:
890
diff
changeset
|
1598 |
do { |
907
60cb7cfb0580
(svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
bjarni
parents:
892
diff
changeset
|
1599 |
if ( v->engine_type != _autoreplace_array[v->engine_type] || (_patches.autorenew && (v->age - v->max_age) > (_patches.autorenew_months * 30))) { |
892
3e5dd4c4d5b3
(svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents:
890
diff
changeset
|
1600 |
new_engine_and_autoreplace_money = (new_engine_and_autoreplace_money & 0xFFFF0000) + _autoreplace_array[v->engine_type]; // sets the new engine replacement type |
3e5dd4c4d5b3
(svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents:
890
diff
changeset
|
1601 |
DoCommandP(v->tile, v->index, new_engine_and_autoreplace_money, NULL, CMD_REPLACE_VEHICLE | CMD_SHOW_NO_ERROR); |
842 | 1602 |
} |
892
3e5dd4c4d5b3
(svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents:
890
diff
changeset
|
1603 |
} while ((v=v->next) != NULL); |
842 | 1604 |
} |
1605 |
_current_player = OWNER_NONE; |
|
0 | 1606 |
} |
1607 |
||
1608 |
||
1609 |
int32 CmdNameVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1610 |
{ |
|
1611 |
Vehicle *v; |
|
1612 |
StringID str; |
|
1613 |
||
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
1614 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
1615 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1616 |
v = GetVehicle(p1); |
0 | 1617 |
|
1618 |
if (!CheckOwnership(v->owner)) |
|
1619 |
return CMD_ERROR; |
|
1620 |
||
1328
e069d2db0e4c
(svn r1832) Next byte -> char iteration: custom names
tron
parents:
1313
diff
changeset
|
1621 |
str = AllocateNameUnique((const char*)_decode_parameters, 2); |
0 | 1622 |
if (str == 0) |
1623 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1624 |
|
0 | 1625 |
if (flags & DC_EXEC) { |
1626 |
StringID old_str = v->string_id; |
|
1627 |
v->string_id = str; |
|
1628 |
DeleteName(old_str); |
|
588 | 1629 |
ResortVehicleLists(); |
0 | 1630 |
MarkWholeScreenDirty(); |
1631 |
} else { |
|
1632 |
DeleteName(str); |
|
1633 |
} |
|
1634 |
||
1635 |
return 0; |
|
1636 |
} |
|
1637 |
||
1638 |
||
1639 |
||
1640 |
static Rect _old_vehicle_coords; |
|
1641 |
||
1642 |
void BeginVehicleMove(Vehicle *v) { |
|
1643 |
_old_vehicle_coords.left = v->left_coord; |
|
1644 |
_old_vehicle_coords.top = v->top_coord; |
|
1645 |
_old_vehicle_coords.right = v->right_coord; |
|
1646 |
_old_vehicle_coords.bottom = v->bottom_coord; |
|
1647 |
} |
|
1648 |
||
1649 |
void EndVehicleMove(Vehicle *v) |
|
1650 |
{ |
|
1651 |
MarkAllViewportsDirty( |
|
1652 |
min(_old_vehicle_coords.left,v->left_coord), |
|
1653 |
min(_old_vehicle_coords.top,v->top_coord), |
|
1654 |
max(_old_vehicle_coords.right,v->right_coord)+1, |
|
1655 |
max(_old_vehicle_coords.bottom,v->bottom_coord)+1 |
|
1656 |
); |
|
1657 |
} |
|
1658 |
||
1659 |
/* returns true if staying in the same tile */ |
|
1660 |
bool GetNewVehiclePos(Vehicle *v, GetNewVehiclePosResult *gp) |
|
1661 |
{ |
|
1662 |
static const int8 _delta_coord[16] = { |
|
1663 |
-1,-1,-1, 0, 1, 1, 1, 0, /* x */ |
|
1664 |
-1, 0, 1, 1, 1, 0,-1,-1, /* y */ |
|
1665 |
}; |
|
1666 |
||
1667 |
int x = v->x_pos + _delta_coord[v->direction]; |
|
1668 |
int y = v->y_pos + _delta_coord[v->direction + 8]; |
|
1669 |
||
1670 |
gp->x = x; |
|
1671 |
gp->y = y; |
|
1672 |
gp->old_tile = v->tile; |
|
1673 |
gp->new_tile = TILE_FROM_XY(x,y); |
|
1674 |
return gp->old_tile == gp->new_tile; |
|
1675 |
} |
|
1676 |
||
1677 |
static const byte _new_direction_table[9] = { |
|
1678 |
0, 7, 6, |
|
1679 |
1, 3, 5, |
|
1680 |
2, 3, 4, |
|
1681 |
}; |
|
1682 |
||
1683 |
byte GetDirectionTowards(Vehicle *v, int x, int y) |
|
1684 |
{ |
|
1685 |
byte dirdiff, dir; |
|
1686 |
int i = 0; |
|
1687 |
||
1688 |
if (y >= v->y_pos) { |
|
1689 |
if (y != v->y_pos) i+=3; |
|
1690 |
i+=3; |
|
1691 |
} |
|
1692 |
||
1693 |
if (x >= v->x_pos) { |
|
1694 |
if (x != v->x_pos) i++; |
|
1695 |
i++; |
|
1696 |
} |
|
1697 |
||
1698 |
dir = v->direction; |
|
1699 |
||
1700 |
dirdiff = _new_direction_table[i] - dir; |
|
1701 |
if (dirdiff == 0) |
|
1702 |
return dir; |
|
1703 |
return (dir+((dirdiff&7)<5?1:-1)) & 7; |
|
1704 |
} |
|
1705 |
||
22 | 1706 |
/* Return value has bit 0x2 set, when the vehicle enters a station. Then, |
1707 |
* result << 8 contains the id of the station entered. If the return value has |
|
1708 |
* bit 0x8 set, the vehicle could not and did not enter the tile. Are there |
|
1709 |
* other bits that can be set? */ |
|
0 | 1710 |
uint32 VehicleEnterTile(Vehicle *v, uint tile, int x, int y) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1711 |
{ |
0 | 1712 |
uint old_tile = v->tile; |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
1713 |
uint32 result = _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1714 |
|
22 | 1715 |
/* When vehicle_enter_tile_proc returns 8, that apparently means that |
1716 |
* we cannot enter the tile at all. In that case, don't call |
|
1717 |
* leave_tile. */ |
|
0 | 1718 |
if (!(result & 8) && old_tile != tile) { |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
1719 |
VehicleLeaveTileProc *proc = _tile_type_procs[GetTileType(old_tile)]->vehicle_leave_tile_proc; |
0 | 1720 |
if (proc != NULL) |
1721 |
proc(v, old_tile, x, y); |
|
1722 |
} |
|
1723 |
return result; |
|
1724 |
} |
|
1725 |
||
1282
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
1726 |
UnitID GetFreeUnitNumber(byte type) |
0 | 1727 |
{ |
1282
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
1728 |
UnitID unit_num = 0; |
0 | 1729 |
Vehicle *u; |
1730 |
||
1731 |
restart: |
|
1732 |
unit_num++; |
|
1733 |
FOR_ALL_VEHICLES(u) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1734 |
if (u->type == type && u->owner == _current_player && |
0 | 1735 |
unit_num == u->unitnumber) |
1736 |
goto restart; |
|
1737 |
} |
|
1738 |
return unit_num; |
|
1739 |
} |
|
1740 |
||
1741 |
||
1742 |
// Save and load of vehicles |
|
1743 |
const byte _common_veh_desc[] = { |
|
1744 |
SLE_VAR(Vehicle,subtype, SLE_UINT8), |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1745 |
|
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
933
diff
changeset
|
1746 |
SLE_REF(Vehicle,next, REF_VEHICLE_OLD), |
0 | 1747 |
SLE_VAR(Vehicle,string_id, SLE_STRINGID), |
1282
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
1748 |
SLE_CONDVAR(Vehicle,unitnumber, SLE_FILE_U8 | SLE_VAR_U16, 0, 7), |
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
1749 |
SLE_CONDVAR(Vehicle,unitnumber, SLE_UINT16, 8, 255), |
0 | 1750 |
SLE_VAR(Vehicle,owner, SLE_UINT8), |
1174
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1751 |
SLE_CONDVAR(Vehicle,tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1752 |
SLE_CONDVAR(Vehicle,tile, SLE_UINT32, 6, 255), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1753 |
SLE_CONDVAR(Vehicle,dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1754 |
SLE_CONDVAR(Vehicle,dest_tile, SLE_UINT32, 6, 255), |
0 | 1755 |
|
1174
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1756 |
SLE_CONDVAR(Vehicle,x_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1757 |
SLE_CONDVAR(Vehicle,x_pos, SLE_UINT32, 6, 255), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1758 |
SLE_CONDVAR(Vehicle,y_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1759 |
SLE_CONDVAR(Vehicle,y_pos, SLE_UINT32, 6, 255), |
0 | 1760 |
SLE_VAR(Vehicle,z_pos, SLE_UINT8), |
1761 |
SLE_VAR(Vehicle,direction, SLE_UINT8), |
|
1762 |
||
1763 |
SLE_VAR(Vehicle,cur_image, SLE_UINT16), |
|
1764 |
SLE_VAR(Vehicle,spritenum, SLE_UINT8), |
|
1765 |
SLE_VAR(Vehicle,sprite_width, SLE_UINT8), |
|
1766 |
SLE_VAR(Vehicle,sprite_height, SLE_UINT8), |
|
1767 |
SLE_VAR(Vehicle,z_height, SLE_UINT8), |
|
1768 |
SLE_VAR(Vehicle,x_offs, SLE_INT8), |
|
1769 |
SLE_VAR(Vehicle,y_offs, SLE_INT8), |
|
1770 |
SLE_VAR(Vehicle,engine_type, SLE_UINT16), |
|
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
410
diff
changeset
|
1771 |
|
0 | 1772 |
SLE_VAR(Vehicle,max_speed, SLE_UINT16), |
1773 |
SLE_VAR(Vehicle,cur_speed, SLE_UINT16), |
|
1774 |
SLE_VAR(Vehicle,subspeed, SLE_UINT8), |
|
1775 |
SLE_VAR(Vehicle,acceleration, SLE_UINT8), |
|
1776 |
SLE_VAR(Vehicle,progress, SLE_UINT8), |
|
1777 |
||
1778 |
SLE_VAR(Vehicle,vehstatus, SLE_UINT8), |
|
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
1779 |
SLE_CONDVAR(Vehicle,last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
1780 |
SLE_CONDVAR(Vehicle,last_station_visited, SLE_UINT16, 5, 255), |
0 | 1781 |
|
1782 |
SLE_VAR(Vehicle,cargo_type, SLE_UINT8), |
|
1783 |
SLE_VAR(Vehicle,cargo_days, SLE_UINT8), |
|
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1237
diff
changeset
|
1784 |
SLE_CONDVAR(Vehicle,cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1237
diff
changeset
|
1785 |
SLE_CONDVAR(Vehicle,cargo_source, SLE_UINT16, 7, 255), |
0 | 1786 |
SLE_VAR(Vehicle,cargo_cap, SLE_UINT16), |
1787 |
SLE_VAR(Vehicle,cargo_count, SLE_UINT16), |
|
1788 |
||
1789 |
SLE_VAR(Vehicle,day_counter, SLE_UINT8), |
|
1790 |
SLE_VAR(Vehicle,tick_counter, SLE_UINT8), |
|
1791 |
||
1792 |
SLE_VAR(Vehicle,cur_order_index, SLE_UINT8), |
|
1793 |
SLE_VAR(Vehicle,num_orders, SLE_UINT8), |
|
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1794 |
|
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1795 |
/* This next line is for version 4 and prior compatibility.. it temporarily reads |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1796 |
type and flags (which were both 4 bits) into type. Later on this is |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1797 |
converted correctly */ |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1798 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type), SLE_UINT8, 0, 4), |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1799 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1800 |
|
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1801 |
/* Orders for version 5 and on */ |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1802 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type), SLE_UINT8, 5, 255), |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1803 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, flags), SLE_UINT8, 5, 255), |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1804 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_UINT16, 5, 255), |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1805 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
1806 |
SLE_REF(Vehicle,orders, REF_ORDER), |
0 | 1807 |
|
1808 |
SLE_VAR(Vehicle,age, SLE_UINT16), |
|
1809 |
SLE_VAR(Vehicle,max_age, SLE_UINT16), |
|
1810 |
SLE_VAR(Vehicle,date_of_last_service,SLE_UINT16), |
|
1811 |
SLE_VAR(Vehicle,service_interval, SLE_UINT16), |
|
1812 |
SLE_VAR(Vehicle,reliability, SLE_UINT16), |
|
1813 |
SLE_VAR(Vehicle,reliability_spd_dec,SLE_UINT16), |
|
1814 |
SLE_VAR(Vehicle,breakdown_ctr, SLE_UINT8), |
|
1815 |
SLE_VAR(Vehicle,breakdown_delay, SLE_UINT8), |
|
1816 |
SLE_VAR(Vehicle,breakdowns_since_last_service, SLE_UINT8), |
|
1817 |
SLE_VAR(Vehicle,breakdown_chance, SLE_UINT8), |
|
1818 |
SLE_VAR(Vehicle,build_year, SLE_UINT8), |
|
1819 |
||
1820 |
SLE_VAR(Vehicle,load_unload_time_rem, SLE_UINT16), |
|
1821 |
||
1822 |
SLE_VAR(Vehicle,profit_this_year, SLE_INT32), |
|
1823 |
SLE_VAR(Vehicle,profit_last_year, SLE_INT32), |
|
1824 |
SLE_VAR(Vehicle,value, SLE_UINT32), |
|
1825 |
||
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
410
diff
changeset
|
1826 |
SLE_VAR(Vehicle,random_bits, SLE_UINT8), |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
410
diff
changeset
|
1827 |
SLE_VAR(Vehicle,waiting_triggers, SLE_UINT8), |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
410
diff
changeset
|
1828 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
1829 |
SLE_REF(Vehicle,next_shared, REF_VEHICLE), |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
1830 |
SLE_REF(Vehicle,prev_shared, REF_VEHICLE), |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
1831 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
1832 |
// reserve extra space in savegame here. (currently 10 bytes) |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
410
diff
changeset
|
1833 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 2, 2, 255), /* 2 */ |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
410
diff
changeset
|
1834 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U32 | SLE_VAR_NULL, 2, 2, 255), /* 8 */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1835 |
|
0 | 1836 |
SLE_END() |
1837 |
}; |
|
1838 |
||
1839 |
||
1840 |
static const byte _train_desc[] = { |
|
1841 |
SLE_WRITEBYTE(Vehicle,type,VEH_Train, 0), // Train type. VEH_Train in mem, 0 in file. |
|
1842 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
1843 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,crash_anim_pos), SLE_UINT16), |
|
1844 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,force_proceed), SLE_UINT8), |
|
1845 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,railtype), SLE_UINT8), |
|
1846 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,track), SLE_UINT8), |
|
1847 |
||
1848 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,flags), SLE_UINT8, 2, 255), |
|
1849 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,days_since_order_progr), SLE_UINT16, 2, 255), |
|
1850 |
||
1851 |
// reserve extra space in savegame here. (currently 13 bytes) |
|
1852 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 13, 2, 255), |
|
1853 |
||
1854 |
SLE_END() |
|
1855 |
}; |
|
1856 |
||
1857 |
static const byte _roadveh_desc[] = { |
|
1858 |
SLE_WRITEBYTE(Vehicle,type,VEH_Road, 1), // Road type. VEH_Road in mem, 1 in file. |
|
1859 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
1860 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,state), SLE_UINT8), |
|
1861 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,frame), SLE_UINT8), |
|
1862 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,unk2), SLE_UINT16), |
|
1863 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,overtaking), SLE_UINT8), |
|
1864 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,overtaking_ctr),SLE_UINT8), |
|
1865 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,crashed_ctr), SLE_UINT16), |
|
1866 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,reverse_ctr), SLE_UINT8), |
|
1867 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1868 |
SLE_CONDREFX(offsetof(Vehicle,u)+offsetof(VehicleRoad,slot), REF_ROADSTOPS, 6, 255), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1869 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,slotindex), SLE_UINT8, 6, 255), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1870 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,slot_age), SLE_UINT8, 6, 255), |
0 | 1871 |
// reserve extra space in savegame here. (currently 16 bytes) |
1872 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
1873 |
||
1874 |
SLE_END() |
|
1875 |
}; |
|
1876 |
||
1877 |
static const byte _ship_desc[] = { |
|
1878 |
SLE_WRITEBYTE(Vehicle,type,VEH_Ship, 2), // Ship type. VEH_Ship in mem, 2 in file. |
|
1879 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
1880 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleShip,state), SLE_UINT8), |
|
1881 |
||
1882 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
1883 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
1884 |
||
1885 |
SLE_END() |
|
1886 |
}; |
|
1887 |
||
1888 |
static const byte _aircraft_desc[] = { |
|
1889 |
SLE_WRITEBYTE(Vehicle,type,VEH_Aircraft, 3), // Aircraft type. VEH_Aircraft in mem, 3 in file. |
|
1890 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
1891 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,crashed_counter), SLE_UINT16), |
|
1892 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,pos), SLE_UINT8), |
|
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
1893 |
|
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
1894 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,targetairport), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
1895 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,targetairport), SLE_UINT16, 5, 255), |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
1896 |
|
0 | 1897 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,state), SLE_UINT8), |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1898 |
|
0 | 1899 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,previous_pos), SLE_UINT8, 2, 255), |
1900 |
||
1901 |
// reserve extra space in savegame here. (currently 15 bytes) |
|
1902 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 15, 2, 255), |
|
1903 |
||
1904 |
SLE_END() |
|
1905 |
}; |
|
1906 |
||
1907 |
static const byte _special_desc[] = { |
|
1908 |
SLE_WRITEBYTE(Vehicle,type,VEH_Special, 4), |
|
1909 |
||
1910 |
SLE_VAR(Vehicle,subtype, SLE_UINT8), |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1911 |
|
1174
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1912 |
SLE_CONDVAR(Vehicle,tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1913 |
SLE_CONDVAR(Vehicle,tile, SLE_UINT32, 6, 255), |
0 | 1914 |
|
1174
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1915 |
SLE_CONDVAR(Vehicle,x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1916 |
SLE_CONDVAR(Vehicle,x_pos, SLE_INT32, 6, 255), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1917 |
SLE_CONDVAR(Vehicle,y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1918 |
SLE_CONDVAR(Vehicle,y_pos, SLE_INT32, 6, 255), |
0 | 1919 |
SLE_VAR(Vehicle,z_pos, SLE_UINT8), |
1920 |
||
1921 |
SLE_VAR(Vehicle,cur_image, SLE_UINT16), |
|
1922 |
SLE_VAR(Vehicle,sprite_width, SLE_UINT8), |
|
1923 |
SLE_VAR(Vehicle,sprite_height, SLE_UINT8), |
|
1924 |
SLE_VAR(Vehicle,z_height, SLE_UINT8), |
|
1925 |
SLE_VAR(Vehicle,x_offs, SLE_INT8), |
|
1926 |
SLE_VAR(Vehicle,y_offs, SLE_INT8), |
|
1927 |
SLE_VAR(Vehicle,progress, SLE_UINT8), |
|
1928 |
SLE_VAR(Vehicle,vehstatus, SLE_UINT8), |
|
1929 |
||
1930 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleSpecial,unk0), SLE_UINT16), |
|
1931 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleSpecial,unk2), SLE_UINT8), |
|
1932 |
||
1933 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
1934 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
1935 |
||
1936 |
SLE_END() |
|
1937 |
}; |
|
1938 |
||
1939 |
static const byte _disaster_desc[] = { |
|
1940 |
SLE_WRITEBYTE(Vehicle,type,VEH_Disaster, 5), |
|
1941 |
||
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
933
diff
changeset
|
1942 |
SLE_REF(Vehicle,next, REF_VEHICLE_OLD), |
0 | 1943 |
|
1944 |
SLE_VAR(Vehicle,subtype, SLE_UINT8), |
|
1174
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1945 |
SLE_CONDVAR(Vehicle,tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1946 |
SLE_CONDVAR(Vehicle,tile, SLE_UINT32, 6, 255), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1947 |
SLE_CONDVAR(Vehicle,dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1948 |
SLE_CONDVAR(Vehicle,dest_tile, SLE_UINT32, 6, 255), |
0 | 1949 |
|
1174
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1950 |
SLE_CONDVAR(Vehicle,x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1951 |
SLE_CONDVAR(Vehicle,x_pos, SLE_INT32, 6, 255), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1952 |
SLE_CONDVAR(Vehicle,y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
1953 |
SLE_CONDVAR(Vehicle,y_pos, SLE_INT32, 6, 255), |
0 | 1954 |
SLE_VAR(Vehicle,z_pos, SLE_UINT8), |
1955 |
SLE_VAR(Vehicle,direction, SLE_UINT8), |
|
1956 |
||
1957 |
SLE_VAR(Vehicle,x_offs, SLE_INT8), |
|
1958 |
SLE_VAR(Vehicle,y_offs, SLE_INT8), |
|
1959 |
SLE_VAR(Vehicle,sprite_width, SLE_UINT8), |
|
1960 |
SLE_VAR(Vehicle,sprite_height, SLE_UINT8), |
|
1961 |
SLE_VAR(Vehicle,z_height, SLE_UINT8), |
|
1962 |
SLE_VAR(Vehicle,owner, SLE_UINT8), |
|
1963 |
SLE_VAR(Vehicle,vehstatus, SLE_UINT8), |
|
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1964 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1965 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_UINT16, 5, 255), |
0 | 1966 |
|
1967 |
SLE_VAR(Vehicle,cur_image, SLE_UINT16), |
|
1968 |
SLE_VAR(Vehicle,age, SLE_UINT16), |
|
1969 |
||
1970 |
SLE_VAR(Vehicle,tick_counter, SLE_UINT8), |
|
1971 |
||
1972 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleDisaster,image_override), SLE_UINT16), |
|
1973 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleDisaster,unk2), SLE_UINT16), |
|
1974 |
||
1975 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
1976 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
1977 |
||
1978 |
SLE_END() |
|
1979 |
}; |
|
1980 |
||
1981 |
||
1982 |
static const void *_veh_descs[] = { |
|
1983 |
_train_desc, |
|
1984 |
_roadveh_desc, |
|
1985 |
_ship_desc, |
|
1986 |
_aircraft_desc, |
|
1987 |
_special_desc, |
|
1988 |
_disaster_desc, |
|
1989 |
}; |
|
1990 |
||
1991 |
// Will be called when the vehicles need to be saved. |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
1992 |
static void Save_VEHS(void) |
0 | 1993 |
{ |
1994 |
Vehicle *v; |
|
1995 |
// Write the vehicles |
|
1996 |
FOR_ALL_VEHICLES(v) { |
|
1997 |
if (v->type != 0) { |
|
1998 |
SlSetArrayIndex(v->index); |
|
1999 |
SlObject(v, _veh_descs[v->type - 0x10]); |
|
2000 |
} |
|
2001 |
} |
|
2002 |
} |
|
2003 |
||
2004 |
// Will be called when vehicles need to be loaded. |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
2005 |
static void Load_VEHS(void) |
0 | 2006 |
{ |
2007 |
int index; |
|
2008 |
Vehicle *v; |
|
2009 |
||
2010 |
while ((index = SlIterateArray()) != -1) { |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2011 |
Vehicle *v; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2012 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2013 |
if (!AddBlockIfNeeded(&_vehicle_pool, index)) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2014 |
error("Vehicles: failed loading savegame: too many vehicles"); |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2015 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2016 |
v = GetVehicle(index); |
0 | 2017 |
SlObject(v, _veh_descs[SlReadByte()]); |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2018 |
|
0 | 2019 |
if (v->type == VEH_Train) |
2020 |
v->u.rail.first_engine = 0xffff; |
|
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2021 |
|
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2022 |
/* Old savegames used 'last_station_visited = 0xFF', should be 0xFFFF */ |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2023 |
if (_sl.version < 5 && v->last_station_visited == 0xFF) |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2024 |
v->last_station_visited = 0xFFFF; |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2025 |
|
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2026 |
if (_sl.version < 5) { |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2027 |
/* Convert the current_order.type (which is a mix of type and flags, because |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2028 |
in those versions, they both were 4 bits big) to type and flags */ |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2029 |
v->current_order.flags = (v->current_order.type & 0xF0) >> 4; |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2030 |
v->current_order.type = v->current_order.type & 0x0F; |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2031 |
} |
0 | 2032 |
} |
2033 |
||
2034 |
// Iterate through trains and set first_engine appropriately. |
|
2035 |
FOR_ALL_VEHICLES(v) { |
|
2036 |
Vehicle *w; |
|
2037 |
||
1067
a083a6dd1419
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1063
diff
changeset
|
2038 |
if (v->type != VEH_Train || v->subtype != TS_Front_Engine) |
0 | 2039 |
continue; |
2040 |
||
2041 |
for (w = v->next; w; w = w->next) |
|
2042 |
w->u.rail.first_engine = v->engine_type; |
|
2043 |
} |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2044 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2045 |
/* Check for shared order-lists (we now use pointers for that) */ |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2046 |
if (_sl.full_version < 0x502) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2047 |
FOR_ALL_VEHICLES(v) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2048 |
Vehicle *u; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2049 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2050 |
if (v->type == 0) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2051 |
continue; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2052 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2053 |
FOR_ALL_VEHICLES_FROM(u, v->index + 1) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2054 |
if (u->type == 0) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2055 |
continue; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2056 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2057 |
/* If a vehicle has the same orders, add the link to eachother |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2058 |
in both vehicles */ |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2059 |
if (v->orders == u->orders) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2060 |
v->next_shared = u; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2061 |
u->prev_shared = v; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2062 |
break; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2063 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2064 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2065 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2066 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2067 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2068 |
/* This is to ensure all pointers are within the limits of |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2069 |
_vehicles_size */ |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2070 |
if (_vehicle_id_ctr_day >= GetVehiclePoolSize()) |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2071 |
_vehicle_id_ctr_day = 0; |
0 | 2072 |
} |
2073 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
2074 |
static const byte _waypoint_desc[] = { |
1174
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
2075 |
SLE_CONDVAR(Waypoint, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
2076 |
SLE_CONDVAR(Waypoint, xy, SLE_UINT32, 6, 255), |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
2077 |
SLE_VAR(Waypoint,town_or_string, SLE_UINT16), |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
2078 |
SLE_VAR(Waypoint,deleted, SLE_UINT8), |
0 | 2079 |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
2080 |
SLE_CONDVAR(Waypoint, build_date, SLE_UINT16, 3, 255), |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
2081 |
SLE_CONDVAR(Waypoint, stat_id, SLE_UINT8, 3, 255), |
0 | 2082 |
|
2083 |
SLE_END() |
|
2084 |
}; |
|
2085 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
2086 |
static void Save_CHKP(void) |
0 | 2087 |
{ |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
2088 |
Waypoint *cp; |
0 | 2089 |
int i; |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
2090 |
for(i=0,cp=_waypoints; i!=lengthof(_waypoints); i++,cp++) { |
0 | 2091 |
if (cp->xy != 0) { |
2092 |
SlSetArrayIndex(i); |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
2093 |
SlObject(cp, _waypoint_desc); |
0 | 2094 |
} |
2095 |
} |
|
2096 |
} |
|
2097 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
2098 |
static void Load_CHKP(void) |
0 | 2099 |
{ |
2100 |
int index; |
|
2101 |
while ((index = SlIterateArray()) != -1) { |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
337
diff
changeset
|
2102 |
SlObject(&_waypoints[index], _waypoint_desc); |
0 | 2103 |
} |
2104 |
} |
|
2105 |
||
2106 |
const ChunkHandler _veh_chunk_handlers[] = { |
|
2107 |
{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY}, |
|
2108 |
{ 'CHKP', Save_CHKP, Load_CHKP, CH_ARRAY | CH_LAST}, |
|
2109 |
}; |
|
2110 |
||
2111 |