author | glx |
Fri, 22 Feb 2008 00:25:54 +0000 | |
branch | noai |
changeset 9732 | f8eb3e208514 |
parent 9724 | b39bc69bb2f2 |
child 9800 | ab08ca2a2018 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9574 | 3 |
/** @file vehicle.cpp */ |
4 |
||
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
3957
3c39694becd2
(svn r5116) Move the overly generic GetDepotDirection() from a header to its only consumer
tron
parents:
3953
diff
changeset
|
7 |
#include "road_map.h" |
3959 | 8 |
#include "roadveh.h" |
3961
e2783f244ac6
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3959
diff
changeset
|
9 |
#include "ship.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
|
10 |
#include "spritecache.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
11 |
#include "tile_cmd.h" |
9599 | 12 |
#include "landscape.h" |
9629 | 13 |
#include "timetable.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
14 |
#include "viewport_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
15 |
#include "gfx_func.h" |
0 | 16 |
#include "news.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
17 |
#include "command_func.h" |
0 | 18 |
#include "saveload.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
19 |
#include "player_func.h" |
0 | 20 |
#include "engine.h" |
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
21 |
#include "debug.h" |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
22 |
#include "vehicle_gui.h" |
1758
68668114f92e
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
23 |
#include "depot.h" |
68668114f92e
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
24 |
#include "station.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
25 |
#include "rail_type.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
26 |
#include "train.h" |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
27 |
#include "aircraft.h" |
3428
62682d91b4cd
(svn r4256) - Codechange: Replace lone map access in vehicle.c with its map accessor.
peter1138
parents:
3422
diff
changeset
|
28 |
#include "industry_map.h" |
3404
3ac4f7fedfb5
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3393
diff
changeset
|
29 |
#include "station_map.h" |
3957
3c39694becd2
(svn r5116) Move the overly generic GetDepotDirection() from a header to its only consumer
tron
parents:
3953
diff
changeset
|
30 |
#include "water_map.h" |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
31 |
#include "network/network.h" |
4130
9c293b171871
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
KUDr
parents:
4124
diff
changeset
|
32 |
#include "yapf/yapf.h" |
5968
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
33 |
#include "newgrf_callbacks.h" |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
34 |
#include "newgrf_engine.h" |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
35 |
#include "newgrf_sound.h" |
9624 | 36 |
#include "group.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
37 |
#include "order.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
38 |
#include "strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
39 |
#include "zoom_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
40 |
#include "functions.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
41 |
#include "date_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
42 |
#include "window_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
43 |
#include "vehicle_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
44 |
#include "signal_func.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
45 |
#include "sound_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
46 |
#include "variables.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
47 |
#include "autoreplace_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
48 |
#include "autoreplace_gui.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
49 |
#include "string_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
50 |
#include "settings_type.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
51 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
52 |
#include "table/sprites.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
53 |
#include "table/strings.h" |
0 | 54 |
|
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
55 |
#define INVALID_COORD (0x7fffffff) |
4174
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
56 |
#define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6)) |
0 | 57 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
58 |
VehicleID _vehicle_id_ctr_day; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
59 |
Vehicle *_place_clicked_vehicle; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
60 |
VehicleID _new_vehicle_id; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
61 |
uint16 _returned_refit_capacity; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
62 |
|
6043
99c8fb13658b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
6014
diff
changeset
|
63 |
|
99c8fb13658b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
6014
diff
changeset
|
64 |
/* Tables used in vehicle.h to find the right command for a certain vehicle type */ |
99c8fb13658b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
6014
diff
changeset
|
65 |
const uint32 _veh_build_proc_table[] = { |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
66 |
CMD_BUILD_RAIL_VEHICLE, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
67 |
CMD_BUILD_ROAD_VEH, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
68 |
CMD_BUILD_SHIP, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
69 |
CMD_BUILD_AIRCRAFT, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
70 |
}; |
6043
99c8fb13658b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
6014
diff
changeset
|
71 |
const uint32 _veh_sell_proc_table[] = { |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
72 |
CMD_SELL_RAIL_WAGON, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
73 |
CMD_SELL_ROAD_VEH, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
74 |
CMD_SELL_SHIP, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
75 |
CMD_SELL_AIRCRAFT, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
76 |
}; |
2753 | 77 |
|
6043
99c8fb13658b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
6014
diff
changeset
|
78 |
const uint32 _veh_refit_proc_table[] = { |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
79 |
CMD_REFIT_RAIL_VEHICLE, |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3973
diff
changeset
|
80 |
CMD_REFIT_ROAD_VEH, |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
81 |
CMD_REFIT_SHIP, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
82 |
CMD_REFIT_AIRCRAFT, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
83 |
}; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
84 |
|
4451
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
85 |
const uint32 _send_to_depot_proc_table[] = { |
4495
b44566fc9025
(svn r6280) -Codechange: Use the same naming for trains as for other vehicles:
Darkvater
parents:
4465
diff
changeset
|
86 |
CMD_SEND_TRAIN_TO_DEPOT, |
4451
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
87 |
CMD_SEND_ROADVEH_TO_DEPOT, |
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
88 |
CMD_SEND_SHIP_TO_DEPOT, |
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
89 |
CMD_SEND_AIRCRAFT_TO_HANGAR, |
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
90 |
}; |
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
91 |
|
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
92 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
93 |
/* Initialize the vehicle-pool */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
94 |
DEFINE_OLD_POOL_GENERIC(Vehicle, Vehicle) |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
95 |
|
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
|
96 |
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
|
97 |
{ |
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
|
98 |
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
|
99 |
v->breakdowns_since_last_service = 0; |
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
100 |
v->reliability = GetEngine(v->engine_type)->reliability; |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
101 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated |
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
|
102 |
} |
0 | 103 |
|
593 | 104 |
bool VehicleNeedsService(const Vehicle *v) |
105 |
{ |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
106 |
if (v->vehstatus & (VS_STOPPED | VS_CRASHED)) return false; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
107 |
if (v->current_order.type != OT_GOTO_DEPOT || !(v->current_order.flags & OFB_PART_OF_ORDERS)) { // Don't interfere with a depot visit by the order list |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
108 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return false; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
109 |
if (v->current_order.type == OT_LOADING) return false; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
110 |
if (v->current_order.type == OT_GOTO_DEPOT && v->current_order.flags & OFB_HALT_IN_DEPOT) return false; |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
111 |
} |
1757
b179d50241dc
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
112 |
|
4262
4657d940a84c
(svn r5888) -Fix: [autoreplace] if vehicles breakdowns and service are turned off, the vehicles failed to enter any depots
bjarni
parents:
4261
diff
changeset
|
113 |
if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) { |
9624 | 114 |
return EngineHasReplacementForPlayer(GetPlayer(v->owner), v->engine_type, v->group_id); /* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off */ |
4262
4657d940a84c
(svn r5888) -Fix: [autoreplace] if vehicles breakdowns and service are turned off, the vehicles failed to enter any depots
bjarni
parents:
4261
diff
changeset
|
115 |
} |
4657d940a84c
(svn r5888) -Fix: [autoreplace] if vehicles breakdowns and service are turned off, the vehicles failed to enter any depots
bjarni
parents:
4261
diff
changeset
|
116 |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
117 |
return _patches.servint_ispercent ? |
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
118 |
(v->reliability < GetEngine(v->engine_type)->reliability * (100 - v->service_interval) / 100) : |
593 | 119 |
(v->date_of_last_service + v->service_interval < _date); |
120 |
} |
|
121 |
||
3881 | 122 |
StringID VehicleInTheWayErrMsg(const Vehicle* v) |
0 | 123 |
{ |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
124 |
switch (v->type) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
125 |
case VEH_TRAIN: return STR_8803_TRAIN_IN_THE_WAY; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
126 |
case VEH_ROAD: return STR_9000_ROAD_VEHICLE_IN_THE_WAY; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
127 |
case VEH_AIRCRAFT: return STR_A015_AIRCRAFT_IN_THE_WAY; |
3881 | 128 |
default: return STR_980E_SHIP_IN_THE_WAY; |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
129 |
} |
0 | 130 |
} |
131 |
||
132 |
static void *EnsureNoVehicleProcZ(Vehicle *v, void *data) |
|
133 |
{ |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
134 |
byte z = *(byte*)data; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
135 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
136 |
if (v->type == VEH_DISASTER || (v->type == VEH_AIRCRAFT && v->subtype == AIR_SHADOW)) return NULL; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
137 |
if (v->z_pos > z) return NULL; |
0 | 138 |
|
3881 | 139 |
_error_message = VehicleInTheWayErrMsg(v); |
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
140 |
return v; |
0 | 141 |
} |
142 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
143 |
Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z) |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
144 |
{ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
145 |
return (Vehicle*)VehicleFromPos(tile, &z, &EnsureNoVehicleProcZ); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
146 |
} |
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
|
147 |
|
3794
ac26a7b4615d
(svn r4790) Remove slope magic from EnsureNoVehicleZ() and rename it to EnsureNoVehicleOnGround() to make more clear what it does
tron
parents:
3679
diff
changeset
|
148 |
bool EnsureNoVehicleOnGround(TileIndex tile) |
0 | 149 |
{ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
150 |
return FindVehicleOnTileZ(tile, GetTileMaxZ(tile)) == NULL; |
1605
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
151 |
} |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
152 |
|
6191
12d69f54e920
(svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents:
6139
diff
changeset
|
153 |
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z, bool without_crashed) |
0 | 154 |
{ |
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
|
155 |
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
|
156 |
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
|
157 |
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
|
158 |
int y2 = TileY(to); |
0 | 159 |
Vehicle *veh; |
160 |
||
161 |
/* Make sure x1 < x2 or y1 < y2 */ |
|
162 |
if (x1 > x2 || y1 > y2) { |
|
6432 | 163 |
Swap(x1, x2); |
164 |
Swap(y1, y2); |
|
0 | 165 |
} |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
166 |
FOR_ALL_VEHICLES(veh) { |
6191
12d69f54e920
(svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents:
6139
diff
changeset
|
167 |
if (without_crashed && (veh->vehstatus & VS_CRASHED) != 0) continue; |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
168 |
if ((veh->type == VEH_TRAIN || veh->type == VEH_ROAD) && (z == 0xFF || veh->z_pos == z)) { |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
169 |
if ((veh->x_pos >> 4) >= x1 && (veh->x_pos >> 4) <= x2 && |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
170 |
(veh->y_pos >> 4) >= y1 && (veh->y_pos >> 4) <= y2) { |
0 | 171 |
return veh; |
172 |
} |
|
173 |
} |
|
174 |
} |
|
175 |
return NULL; |
|
176 |
} |
|
177 |
||
2817 | 178 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
179 |
/** Procedure called for every vehicle found in tunnel/bridge in the hash map */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
180 |
static void *GetVehicleTunnelBridgeProc(Vehicle *v, void *data) |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
181 |
{ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
182 |
if (v->type != VEH_TRAIN && v->type != VEH_ROAD) return NULL; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
183 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
184 |
_error_message = VehicleInTheWayErrMsg(v); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
185 |
return v; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
186 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
187 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
188 |
/** |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
189 |
* Finds vehicle in tunnel / bridge |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
190 |
* @param tile first end |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
191 |
* @param endtile second end |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
192 |
* @return pointer to vehicle found |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
193 |
*/ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
194 |
Vehicle *GetVehicleTunnelBridge(TileIndex tile, TileIndex endtile) |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
195 |
{ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
196 |
Vehicle *v = (Vehicle*)VehicleFromPos(tile, NULL, &GetVehicleTunnelBridgeProc); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
197 |
if (v != NULL) return v; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
198 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
199 |
return (Vehicle*)VehicleFromPos(endtile, NULL, &GetVehicleTunnelBridgeProc); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
200 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
201 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
202 |
|
2817 | 203 |
static void UpdateVehiclePosHash(Vehicle* v, int x, int y); |
204 |
||
0 | 205 |
void VehiclePositionChanged(Vehicle *v) |
206 |
{ |
|
207 |
int img = v->cur_image; |
|
208 |
Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
209 |
const Sprite* spr = GetSprite(img); |
0 | 210 |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
211 |
pt.x += spr->x_offs; |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
212 |
pt.y += spr->y_offs; |
0 | 213 |
|
214 |
UpdateVehiclePosHash(v, pt.x, pt.y); |
|
215 |
||
216 |
v->left_coord = pt.x; |
|
217 |
v->top_coord = pt.y; |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
218 |
v->right_coord = pt.x + spr->width + 2; |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
219 |
v->bottom_coord = pt.y + spr->height + 2; |
0 | 220 |
} |
221 |
||
9574 | 222 |
/** Called after load to update coordinates */ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
223 |
void AfterLoadVehicles(bool clear_te_id) |
0 | 224 |
{ |
225 |
Vehicle *v; |
|
226 |
||
227 |
FOR_ALL_VEHICLES(v) { |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
228 |
/* Reinstate the previous pointer */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
229 |
if (v->Next() != NULL) v->Next()->previous = v; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
230 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
231 |
v->UpdateDeltaXY(v->direction); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
232 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
233 |
if (clear_te_id) v->fill_percent_te_id = INVALID_TE_ID; |
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
234 |
v->first = NULL; |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
235 |
if (v->type == VEH_TRAIN) v->u.rail.first_engine = INVALID_ENGINE; |
9627 | 236 |
if (v->type == VEH_ROAD) v->u.road.first_engine = INVALID_ENGINE; |
9629 | 237 |
|
238 |
v->cargo.InvalidateCache(); |
|
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3326
diff
changeset
|
239 |
} |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3326
diff
changeset
|
240 |
|
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3326
diff
changeset
|
241 |
FOR_ALL_VEHICLES(v) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
242 |
/* Fill the first pointers */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
243 |
if (v->Previous() == NULL) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
244 |
for (Vehicle *u = v; u != NULL; u = u->Next()) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
245 |
u->first = v; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
246 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
247 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
248 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
249 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
250 |
FOR_ALL_VEHICLES(v) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
251 |
assert(v->first != NULL); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
252 |
|
9627 | 253 |
if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
254 |
if (IsFrontEngine(v)) v->u.rail.last_speed = v->cur_speed; // update displayed train speed |
2994
897b81cf1bba
(svn r3571) - When loading a game, call TrainConsistChanged() for each train head separately before updating images, as v->first is used extensively in GetTrainImage() for custom graphics. This gives a significant speed improvement on loading a game.
peter1138
parents:
2970
diff
changeset
|
255 |
TrainConsistChanged(v); |
9627 | 256 |
} else if (v->type == VEH_ROAD && IsRoadVehFront(v)) { |
257 |
RoadVehUpdateCache(v); |
|
258 |
} |
|
2994
897b81cf1bba
(svn r3571) - When loading a game, call TrainConsistChanged() for each train head separately before updating images, as v->first is used extensively in GetTrainImage() for custom graphics. This gives a significant speed improvement on loading a game.
peter1138
parents:
2970
diff
changeset
|
259 |
} |
897b81cf1bba
(svn r3571) - When loading a game, call TrainConsistChanged() for each train head separately before updating images, as v->first is used extensively in GetTrainImage() for custom graphics. This gives a significant speed improvement on loading a game.
peter1138
parents:
2970
diff
changeset
|
260 |
|
897b81cf1bba
(svn r3571) - When loading a game, call TrainConsistChanged() for each train head separately before updating images, as v->first is used extensively in GetTrainImage() for custom graphics. This gives a significant speed improvement on loading a game.
peter1138
parents:
2970
diff
changeset
|
261 |
FOR_ALL_VEHICLES(v) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
262 |
switch (v->type) { |
9624 | 263 |
case VEH_ROAD: |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
264 |
v->u.road.roadtype = HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD; |
9624 | 265 |
v->u.road.compatible_roadtypes = RoadTypeToRoadTypes(v->u.road.roadtype); |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
266 |
/* FALL THROUGH */ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
267 |
case VEH_TRAIN: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
268 |
case VEH_SHIP: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
269 |
v->cur_image = v->GetImage(v->direction); |
9624 | 270 |
break; |
271 |
||
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
272 |
case VEH_AIRCRAFT: |
6105
761d393829d6
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
6074
diff
changeset
|
273 |
if (IsNormalAircraft(v)) { |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
274 |
v->cur_image = v->GetImage(v->direction); |
6117
b50b5ebc1c98
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
6106
diff
changeset
|
275 |
|
b50b5ebc1c98
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
6106
diff
changeset
|
276 |
/* The plane's shadow will have the same image as the plane */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
277 |
Vehicle *shadow = v->Next(); |
6117
b50b5ebc1c98
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
6106
diff
changeset
|
278 |
shadow->cur_image = v->cur_image; |
b50b5ebc1c98
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
6106
diff
changeset
|
279 |
|
b50b5ebc1c98
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
6106
diff
changeset
|
280 |
/* In the case of a helicopter we will update the rotor sprites */ |
b50b5ebc1c98
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
6106
diff
changeset
|
281 |
if (v->subtype == AIR_HELICOPTER) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
282 |
Vehicle *rotor = shadow->Next(); |
6117
b50b5ebc1c98
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
6106
diff
changeset
|
283 |
rotor->cur_image = GetRotorImage(v); |
b50b5ebc1c98
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
6106
diff
changeset
|
284 |
} |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
285 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
286 |
UpdateAircraftCache(v); |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
287 |
} |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
288 |
break; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
289 |
default: break; |
0 | 290 |
} |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
291 |
|
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
292 |
v->left_coord = INVALID_COORD; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
293 |
VehiclePositionChanged(v); |
0 | 294 |
} |
295 |
} |
|
296 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
297 |
Vehicle::Vehicle() |
0 | 298 |
{ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
299 |
this->type = VEH_INVALID; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
300 |
this->left_coord = INVALID_COORD; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
301 |
this->group_id = DEFAULT_GROUP; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
302 |
this->fill_percent_te_id = INVALID_TE_ID; |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
303 |
this->first = this; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
304 |
this->colormap = PAL_NONE; |
0 | 305 |
} |
306 |
||
2804
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
307 |
/** |
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
308 |
* Get a value for a vehicle's random_bits. |
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
309 |
* @return A random value from 0 to 255. |
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
310 |
*/ |
6573 | 311 |
byte VehicleRandomBits() |
2804
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
312 |
{ |
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
313 |
return GB(Random(), 0, 8); |
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
314 |
} |
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
315 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
316 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
317 |
/* static */ bool Vehicle::AllocateList(Vehicle **vl, int num) |
0 | 318 |
{ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
319 |
uint counter = _Vehicle_pool.first_free_index; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
320 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
321 |
for (int i = 0; i != num; i++) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
322 |
Vehicle *v = AllocateRaw(counter); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
323 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
324 |
if (v == NULL) return false; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
325 |
v = new (v) InvalidVehicle(); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
326 |
|
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
327 |
if (vl != NULL) { |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
328 |
vl[i] = v; |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
329 |
} |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
330 |
counter++; |
2601
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
331 |
} |
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
332 |
|
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
333 |
return true; |
2601
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
334 |
} |
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
335 |
|
9627 | 336 |
/* Size of the hash, 6 = 64 x 64, 7 = 128 x 128. Larger sizes will (in theory) reduce hash |
337 |
* lookup times at the expense of memory usage. */ |
|
338 |
const int HASH_BITS = 7; |
|
339 |
const int HASH_SIZE = 1 << HASH_BITS; |
|
340 |
const int HASH_MASK = HASH_SIZE - 1; |
|
341 |
const int TOTAL_HASH_SIZE = 1 << (HASH_BITS * 2); |
|
342 |
const int TOTAL_HASH_MASK = TOTAL_HASH_SIZE - 1; |
|
343 |
||
344 |
/* Resolution of the hash, 0 = 1*1 tile, 1 = 2*2 tiles, 2 = 4*4 tiles, etc. |
|
345 |
* Profiling results show that 0 is fastest. */ |
|
346 |
const int HASH_RES = 0; |
|
347 |
||
348 |
static Vehicle *_new_vehicle_position_hash[TOTAL_HASH_SIZE]; |
|
349 |
||
350 |
static void *VehicleFromHash(int xl, int yl, int xu, int yu, void *data, VehicleFromPosProc *proc) |
|
351 |
{ |
|
352 |
for (int y = yl; ; y = (y + (1 << HASH_BITS)) & (HASH_MASK << HASH_BITS)) { |
|
353 |
for (int x = xl; ; x = (x + 1) & HASH_MASK) { |
|
354 |
Vehicle *v = _new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; |
|
355 |
for (; v != NULL; v = v->next_new_hash) { |
|
356 |
void *a = proc(v, data); |
|
357 |
if (a != NULL) return a; |
|
358 |
} |
|
359 |
if (x == xu) break; |
|
360 |
} |
|
361 |
if (y == yu) break; |
|
362 |
} |
|
363 |
||
364 |
return NULL; |
|
365 |
} |
|
366 |
||
367 |
||
368 |
void *VehicleFromPosXY(int x, int y, void *data, VehicleFromPosProc *proc) |
|
369 |
{ |
|
370 |
const int COLL_DIST = 6; |
|
371 |
||
372 |
/* Hash area to scan is from xl,yl to xu,yu */ |
|
373 |
int xl = GB((x - COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS); |
|
374 |
int xu = GB((x + COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS); |
|
375 |
int yl = GB((y - COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS; |
|
376 |
int yu = GB((y + COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS; |
|
377 |
||
378 |
return VehicleFromHash(xl, yl, xu, yu, data, proc); |
|
379 |
} |
|
380 |
||
2651 | 381 |
|
0 | 382 |
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc) |
383 |
{ |
|
9627 | 384 |
int x = GB(TileX(tile), HASH_RES, HASH_BITS); |
385 |
int y = GB(TileY(tile), HASH_RES, HASH_BITS) << HASH_BITS; |
|
386 |
||
387 |
Vehicle *v = _new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; |
|
388 |
for (; v != NULL; v = v->next_new_hash) { |
|
389 |
if (v->tile != tile) continue; |
|
390 |
||
391 |
void *a = proc(v, data); |
|
392 |
if (a != NULL) return a; |
|
0 | 393 |
} |
9627 | 394 |
|
0 | 395 |
return NULL; |
396 |
} |
|
397 |
||
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
398 |
static void UpdateNewVehiclePosHash(Vehicle *v, bool remove) |
9627 | 399 |
{ |
400 |
Vehicle **old_hash = v->old_new_hash; |
|
401 |
Vehicle **new_hash; |
|
402 |
||
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
403 |
if (remove) { |
9627 | 404 |
new_hash = NULL; |
405 |
} else { |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
406 |
int x = GB(TileX(v->tile), HASH_RES, HASH_BITS); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
407 |
int y = GB(TileY(v->tile), HASH_RES, HASH_BITS) << HASH_BITS; |
9627 | 408 |
new_hash = &_new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; |
409 |
} |
|
410 |
||
411 |
if (old_hash == new_hash) return; |
|
412 |
||
413 |
/* Remove from the old position in the hash table */ |
|
414 |
if (old_hash != NULL) { |
|
415 |
Vehicle *last = NULL; |
|
416 |
Vehicle *u = *old_hash; |
|
417 |
while (u != v) { |
|
418 |
last = u; |
|
419 |
u = u->next_new_hash; |
|
420 |
assert(u != NULL); |
|
421 |
} |
|
422 |
||
423 |
if (last == NULL) { |
|
424 |
*old_hash = v->next_new_hash; |
|
425 |
} else { |
|
426 |
last->next_new_hash = v->next_new_hash; |
|
427 |
} |
|
428 |
} |
|
429 |
||
430 |
/* Insert vehicle at beginning of the new position in the hash table */ |
|
431 |
if (new_hash != NULL) { |
|
432 |
v->next_new_hash = *new_hash; |
|
433 |
*new_hash = v; |
|
434 |
assert(v != v->next_new_hash); |
|
435 |
} |
|
436 |
||
437 |
/* Remember current hash position */ |
|
438 |
v->old_new_hash = new_hash; |
|
439 |
} |
|
440 |
||
441 |
static Vehicle *_vehicle_position_hash[0x1000]; |
|
0 | 442 |
|
2817 | 443 |
static void UpdateVehiclePosHash(Vehicle* v, int x, int y) |
0 | 444 |
{ |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
445 |
UpdateNewVehiclePosHash(v, x == INVALID_COORD); |
9627 | 446 |
|
5825
d813480f22ac
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5726
diff
changeset
|
447 |
Vehicle **old_hash, **new_hash; |
0 | 448 |
int old_x = v->left_coord; |
449 |
int old_y = v->top_coord; |
|
450 |
||
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
451 |
new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x, y)]; |
0 | 452 |
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
|
453 |
|
2639 | 454 |
if (old_hash == new_hash) return; |
0 | 455 |
|
456 |
/* remove from hash table? */ |
|
457 |
if (old_hash != NULL) { |
|
458 |
Vehicle *last = NULL; |
|
5825
d813480f22ac
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5726
diff
changeset
|
459 |
Vehicle *u = *old_hash; |
d813480f22ac
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5726
diff
changeset
|
460 |
while (u != v) { |
0 | 461 |
last = u; |
5825
d813480f22ac
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5726
diff
changeset
|
462 |
u = u->next_hash; |
d813480f22ac
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5726
diff
changeset
|
463 |
assert(u != NULL); |
0 | 464 |
} |
465 |
||
2639 | 466 |
if (last == NULL) { |
0 | 467 |
*old_hash = v->next_hash; |
2639 | 468 |
} else { |
0 | 469 |
last->next_hash = v->next_hash; |
2639 | 470 |
} |
0 | 471 |
} |
472 |
||
473 |
/* insert into hash table? */ |
|
474 |
if (new_hash != NULL) { |
|
475 |
v->next_hash = *new_hash; |
|
5825
d813480f22ac
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5726
diff
changeset
|
476 |
*new_hash = v; |
0 | 477 |
} |
478 |
} |
|
479 |
||
6573 | 480 |
void ResetVehiclePosHash() |
5352
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
481 |
{ |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
482 |
Vehicle *v; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
483 |
FOR_ALL_VEHICLES(v) { v->old_new_hash = NULL; } |
5825
d813480f22ac
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5726
diff
changeset
|
484 |
memset(_vehicle_position_hash, 0, sizeof(_vehicle_position_hash)); |
9627 | 485 |
memset(_new_vehicle_position_hash, 0, sizeof(_new_vehicle_position_hash)); |
5352
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
486 |
} |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
487 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
488 |
void ResetVehicleColorMap() |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
489 |
{ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
490 |
Vehicle *v; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
491 |
FOR_ALL_VEHICLES(v) { v->colormap = PAL_NONE; } |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
492 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
493 |
|
6573 | 494 |
void InitializeVehicles() |
0 | 495 |
{ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
496 |
_Vehicle_pool.CleanPool(); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
497 |
_Vehicle_pool.AddBlockToPool(); |
5352
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
498 |
|
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
499 |
ResetVehiclePosHash(); |
0 | 500 |
} |
501 |
||
502 |
Vehicle *GetLastVehicleInChain(Vehicle *v) |
|
503 |
{ |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
504 |
while (v->Next() != NULL) v = v->Next(); |
0 | 505 |
return v; |
506 |
} |
|
507 |
||
2630 | 508 |
uint CountVehiclesInChain(const Vehicle* v) |
0 | 509 |
{ |
2639 | 510 |
uint count = 0; |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
511 |
do count++; while ((v = v->Next()) != NULL); |
0 | 512 |
return count; |
513 |
} |
|
514 |
||
4574
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
515 |
/** Check if a vehicle is counted in num_engines in each player struct |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
516 |
* @param *v Vehicle to test |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
517 |
* @return true if the vehicle is counted in num_engines |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
518 |
*/ |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
519 |
bool IsEngineCountable(const Vehicle *v) |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
520 |
{ |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
521 |
switch (v->type) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
522 |
case VEH_AIRCRAFT: return IsNormalAircraft(v); // don't count plane shadows and helicopter rotors |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
523 |
case VEH_TRAIN: |
4574
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
524 |
return !IsArticulatedPart(v) && // tenders and other articulated parts |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
525 |
!IsRearDualheaded(v); // rear parts of multiheaded engines |
9627 | 526 |
case VEH_ROAD: return IsRoadVehFront(v); |
527 |
case VEH_SHIP: return true; |
|
4574
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
528 |
default: return false; // Only count player buildable vehicles |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
529 |
} |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
530 |
} |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
531 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
532 |
void Vehicle::PreDestructor() |
0 | 533 |
{ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
534 |
if (CleaningPool()) return; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
535 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
536 |
if (IsValidStationID(this->last_station_visited)) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
537 |
GetStation(this->last_station_visited)->loading_vehicles.remove(this); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
538 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
539 |
HideFillingPercent(this->fill_percent_te_id); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
540 |
this->fill_percent_te_id = INVALID_TE_ID; |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
541 |
} |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
542 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
543 |
if (IsEngineCountable(this)) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
544 |
GetPlayer(this->owner)->num_engines[this->engine_type]--; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
545 |
if (this->owner == _local_player) InvalidateAutoreplaceWindow(this->engine_type, this->group_id); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
546 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
547 |
if (IsValidGroupID(this->group_id)) GetGroup(this->group_id)->num_engines[this->engine_type]--; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
548 |
if (this->IsPrimaryVehicle()) DecreaseGroupNumVehicle(this->group_id); |
6195
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6191
diff
changeset
|
549 |
} |
4574
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
550 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
551 |
if (this->type == VEH_ROAD) ClearSlot(this); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
552 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
553 |
if (this->type != VEH_TRAIN || (this->type == VEH_TRAIN && (IsFrontEngine(this) || IsFreeWagon(this)))) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
554 |
InvalidateWindowData(WC_VEHICLE_DEPOT, this->tile); |
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
555 |
} |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
556 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
557 |
this->cargo.Truncate(0); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
558 |
DeleteVehicleOrders(this); |
4404
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
559 |
|
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
560 |
/* Now remove any artic part. This will trigger an other |
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
561 |
* destroy vehicle, which on his turn can remove any |
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
562 |
* other artic parts. */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
563 |
if ((this->type == VEH_TRAIN && EngineHasArticPart(this)) || (this->type == VEH_ROAD && RoadVehHasArticPart(this))) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
564 |
delete this->Next(); |
9627 | 565 |
} |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
566 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
567 |
Window *w = FindWindowById(WC_MAIN_WINDOW, 0); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
568 |
if (WP(w, vp_d).follow_vehicle == this->index) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
569 |
ScrollMainWindowTo(this->x_pos, this->y_pos, true); // lock the main view on the vehicle's last position |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
570 |
WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
571 |
} |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
572 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
573 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
574 |
Vehicle::~Vehicle() |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
575 |
{ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
576 |
free(this->name); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
577 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
578 |
if (CleaningPool()) return; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
579 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
580 |
this->SetNext(NULL); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
581 |
UpdateVehiclePosHash(this, INVALID_COORD, 0); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
582 |
this->next_hash = NULL; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
583 |
this->next_new_hash = NULL; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
584 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
585 |
DeleteVehicleNews(this->index, INVALID_STRING_ID); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
586 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
587 |
new (this) InvalidVehicle(); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
588 |
} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
589 |
|
9626 | 590 |
/** |
591 |
* Deletes all vehicles in a chain. |
|
592 |
* @param v The first vehicle in the chain. |
|
593 |
*/ |
|
0 | 594 |
void DeleteVehicleChain(Vehicle *v) |
595 |
{ |
|
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
596 |
assert(v->First() == v); |
9626 | 597 |
|
0 | 598 |
do { |
599 |
Vehicle *u = v; |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
600 |
/* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles, |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
601 |
* it may happen that vehicle chain is deleted when visible */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
602 |
if (!(v->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(v); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
603 |
v = v->Next(); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
604 |
delete u; |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
605 |
} while (v != NULL); |
0 | 606 |
} |
607 |
||
9574 | 608 |
/** head of the linked list to tell what vehicles that visited a depot in a tick */ |
2630 | 609 |
static Vehicle* _first_veh_in_depot_list; |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
610 |
|
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
611 |
/** Adds a vehicle to the list of vehicles, that visited a depot this tick |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
612 |
* @param *v vehicle to add |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
613 |
*/ |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
614 |
void VehicleEnteredDepotThisTick(Vehicle *v) |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
615 |
{ |
9732 | 616 |
/* We need to set v->leave_depot_instantly as we have no control of it's contents at this time. |
617 |
* Vehicle should stop in the depot if it was in 'stopping' state - train intered depot while slowing down. */ |
|
618 |
if ((HasBit(v->current_order.flags, OF_HALT_IN_DEPOT) && !HasBit(v->current_order.flags, OF_PART_OF_ORDERS) && v->current_order.type == OT_GOTO_DEPOT) || |
|
619 |
(v->vehstatus & VS_STOPPED)) { |
|
9574 | 620 |
/* we keep the vehicle in the depot since the user ordered it to stay */ |
2590
5603f43c8cd3
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
621 |
v->leave_depot_instantly = false; |
5603f43c8cd3
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
622 |
} else { |
9574 | 623 |
/* the vehicle do not plan on stopping in the depot, so we stop it to ensure that it will not reserve the path |
624 |
* out of the depot before we might autoreplace it to a different engine. The new engine would not own the reserved path |
|
625 |
* we store that we stopped the vehicle, so autoreplace can start it again */ |
|
2579
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
626 |
v->vehstatus |= VS_STOPPED; |
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
627 |
v->leave_depot_instantly = true; |
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
628 |
} |
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
629 |
|
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
630 |
if (_first_veh_in_depot_list == NULL) { |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
631 |
_first_veh_in_depot_list = v; |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
632 |
} else { |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
633 |
Vehicle *w = _first_veh_in_depot_list; |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
634 |
while (w->depot_list != NULL) w = w->depot_list; |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
635 |
w->depot_list = v; |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
636 |
} |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
637 |
} |
0 | 638 |
|
6573 | 639 |
void CallVehicleTicks() |
0 | 640 |
{ |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
641 |
_first_veh_in_depot_list = NULL; // now we are sure it's initialized at the start of each tick |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
642 |
|
9624 | 643 |
Station *st; |
644 |
FOR_ALL_STATIONS(st) LoadUnloadStation(st); |
|
645 |
||
646 |
Vehicle *v; |
|
0 | 647 |
FOR_ALL_VEHICLES(v) { |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
648 |
v->Tick(); |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
649 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
650 |
switch (v->type) { |
9624 | 651 |
default: break; |
652 |
||
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
653 |
case VEH_TRAIN: |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
654 |
case VEH_ROAD: |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
655 |
case VEH_AIRCRAFT: |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
656 |
case VEH_SHIP: |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
657 |
if (v->type == VEH_TRAIN && IsTrainWagon(v)) continue; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
658 |
if (v->type == VEH_AIRCRAFT && v->subtype != AIR_HELICOPTER) continue; |
9627 | 659 |
if (v->type == VEH_ROAD && !IsRoadVehFront(v)) continue; |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
660 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
661 |
v->motion_counter += (v->direction & 1) ? (v->cur_speed * 3) / 4 : v->cur_speed; |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
662 |
/* Play a running sound if the motion counter passes 256 (Do we not skip sounds?) */ |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
663 |
if (GB(v->motion_counter, 0, 8) < v->cur_speed) PlayVehicleSound(v, VSE_RUNNING); |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
664 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
665 |
/* Play an alterate running sound every 16 ticks */ |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
666 |
if (GB(v->tick_counter, 0, 4) == 0) PlayVehicleSound(v, v->cur_speed > 0 ? VSE_RUNNING_16 : VSE_STOPPED_16); |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
667 |
} |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
668 |
} |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
669 |
|
9574 | 670 |
/* now we handle all the vehicles that entered a depot this tick */ |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
671 |
v = _first_veh_in_depot_list; |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
672 |
while (v != NULL) { |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
673 |
Vehicle *w = v->depot_list; |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
674 |
v->depot_list = NULL; // it should always be NULL at the end of each tick |
4676
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
675 |
MaybeReplaceVehicle(v, false, true); |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
676 |
v = w; |
0 | 677 |
} |
678 |
} |
|
679 |
||
2704
dc9ae68dfd74
(svn r3248) - Codechange: Change interface of CanRefitTo() to supply the engine type directly instead of getting it from a vehicle. This allows the function to be used before vehicles are involved.
peter1138
parents:
2697
diff
changeset
|
680 |
/** Check if a given engine type can be refitted to a given cargo |
dc9ae68dfd74
(svn r3248) - Codechange: Change interface of CanRefitTo() to supply the engine type directly instead of getting it from a vehicle. This allows the function to be used before vehicles are involved.
peter1138
parents:
2697
diff
changeset
|
681 |
* @param engine_type Engine type to check |
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
682 |
* @param cid_to check refit to this cargo-type |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
683 |
* @return true if it is possible, false otherwise |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
684 |
*/ |
2704
dc9ae68dfd74
(svn r3248) - Codechange: Change interface of CanRefitTo() to supply the engine type directly instead of getting it from a vehicle. This allows the function to be used before vehicles are involved.
peter1138
parents:
2697
diff
changeset
|
685 |
bool CanRefitTo(EngineID engine_type, CargoID cid_to) |
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
686 |
{ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
687 |
return HasBit(EngInfo(engine_type)->refit_mask, cid_to); |
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
688 |
} |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
689 |
|
3973
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
690 |
/** Find the first cargo type that an engine can be refitted to. |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
691 |
* @param engine_type Which engine to find cargo for. |
3973
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
692 |
* @return A climate dependent cargo type. CT_INVALID is returned if not refittable. |
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
693 |
*/ |
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
694 |
CargoID FindFirstRefittableCargo(EngineID engine_type) |
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
695 |
{ |
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
696 |
uint32 refit_mask = EngInfo(engine_type)->refit_mask; |
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
697 |
|
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
698 |
if (refit_mask != 0) { |
9505 | 699 |
for (CargoID cid = 0; cid < NUM_CARGO; cid++) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
700 |
if (HasBit(refit_mask, cid)) return cid; |
3973
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
701 |
} |
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
702 |
} |
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
703 |
|
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
704 |
return CT_INVALID; |
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
705 |
} |
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
706 |
|
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
707 |
/** Learn the price of refitting a certain engine |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
708 |
* @param engine_type Which engine to refit |
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
709 |
* @return Price for refitting |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
710 |
*/ |
9629 | 711 |
CommandCost GetRefitCost(EngineID engine_type) |
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
712 |
{ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
713 |
Money base_cost; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
714 |
ExpensesType expense_type; |
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
715 |
switch (GetEngine(engine_type)->type) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
716 |
case VEH_SHIP: |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
717 |
base_cost = _price.ship_base; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
718 |
expense_type = EXPENSES_SHIP_RUN; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
719 |
break; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
720 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
721 |
case VEH_ROAD: |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
722 |
base_cost = _price.roadveh_base; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
723 |
expense_type = EXPENSES_ROADVEH_RUN; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
724 |
break; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
725 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
726 |
case VEH_AIRCRAFT: |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
727 |
base_cost = _price.aircraft_base; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
728 |
expense_type = EXPENSES_AIRCRAFT_RUN; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
729 |
break; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
730 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
731 |
case VEH_TRAIN: |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
732 |
base_cost = 2 * ((RailVehInfo(engine_type)->railveh_type == RAILVEH_WAGON) ? |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
733 |
_price.build_railwagon : _price.build_railvehicle); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
734 |
expense_type = EXPENSES_TRAIN_RUN; |
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
735 |
break; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
736 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
737 |
default: NOT_REACHED(); |
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
738 |
} |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
739 |
return CommandCost(expense_type, (EngInfo(engine_type)->refit_cost * base_cost) >> 10); |
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
740 |
} |
3973
7624a250577b
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
741 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
742 |
static void DoDrawVehicle(const Vehicle *v) |
0 | 743 |
{ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
744 |
SpriteID image = v->cur_image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
745 |
SpriteID pal; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
746 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
747 |
if (v->vehstatus & VS_DEFPAL) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
748 |
pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
749 |
} else { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
750 |
pal = PAL_NONE; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
751 |
} |
0 | 752 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
753 |
AddSortableSpriteToDraw(image, pal, v->x_pos + v->x_offs, v->y_pos + v->y_offs, |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
754 |
v->sprite_width, v->sprite_height, v->z_height, v->z_pos, (v->vehstatus & VS_SHADOW) != 0); |
0 | 755 |
} |
756 |
||
757 |
void ViewportAddVehicles(DrawPixelInfo *dpi) |
|
758 |
{ |
|
9574 | 759 |
/* The bounding rectangle */ |
4174
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
760 |
const int l = dpi->left; |
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
761 |
const int r = dpi->left + dpi->width; |
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
762 |
const int t = dpi->top; |
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
763 |
const int b = dpi->top + dpi->height; |
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
764 |
|
9574 | 765 |
/* The hash area to scan */ |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
766 |
int xl, xu, yl, yu; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
767 |
|
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
768 |
if (dpi->width + 70 < (1 << (7 + 6))) { |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
769 |
xl = GB(l - 70, 7, 6); |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
770 |
xu = GB(r, 7, 6); |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
771 |
} else { |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
772 |
/* scan whole hash row */ |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
773 |
xl = 0; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
774 |
xu = 0x3F; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
775 |
} |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
776 |
|
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
777 |
if (dpi->height + 70 < (1 << (6 + 6))) { |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
778 |
yl = GB(t - 70, 6, 6) << 6; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
779 |
yu = GB(b, 6, 6) << 6; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
780 |
} else { |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
781 |
/* scan whole column */ |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
782 |
yl = 0; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
783 |
yu = 0x3F << 6; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
784 |
} |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
785 |
|
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
786 |
for (int y = yl;; y = (y + (1 << 6)) & (0x3F << 6)) { |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
787 |
for (int x = xl;; x = (x + 1) & 0x3F) { |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
788 |
const Vehicle *v = _vehicle_position_hash[x + y]; // already masked & 0xFFF |
5825
d813480f22ac
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5726
diff
changeset
|
789 |
|
d813480f22ac
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5726
diff
changeset
|
790 |
while (v != NULL) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
791 |
if (!(v->vehstatus & VS_HIDDEN) && |
4174
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
792 |
l <= v->right_coord && |
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
793 |
t <= v->bottom_coord && |
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
794 |
r >= v->left_coord && |
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
795 |
b >= v->top_coord) { |
0 | 796 |
DoDrawVehicle(v); |
797 |
} |
|
5825
d813480f22ac
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5726
diff
changeset
|
798 |
v = v->next_hash; |
0 | 799 |
} |
800 |
||
4174
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
801 |
if (x == xu) break; |
0 | 802 |
} |
4174
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
803 |
|
9ba4e15dac0f
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
804 |
if (y == yu) break; |
0 | 805 |
} |
806 |
} |
|
807 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
808 |
static void ChimneySmokeInit(Vehicle *v) |
0 | 809 |
{ |
810 |
uint32 r = Random(); |
|
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
811 |
v->cur_image = SPR_CHIMNEY_SMOKE_0 + GB(r, 0, 3); |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
812 |
v->progress = GB(r, 16, 3); |
0 | 813 |
} |
814 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
815 |
static void ChimneySmokeTick(Vehicle *v) |
0 | 816 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
817 |
if (v->progress > 0) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
818 |
v->progress--; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
819 |
} else { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
820 |
TileIndex tile; |
0 | 821 |
|
822 |
BeginVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
823 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
824 |
tile = TileVirtXY(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
|
825 |
if (!IsTileType(tile, MP_INDUSTRY)) { |
0 | 826 |
EndVehicleMove(v); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
827 |
delete v; |
0 | 828 |
return; |
829 |
} |
|
830 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
831 |
if (v->cur_image != SPR_CHIMNEY_SMOKE_7) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
832 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
833 |
} else { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
834 |
v->cur_image = SPR_CHIMNEY_SMOKE_0; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
835 |
} |
0 | 836 |
v->progress = 7; |
837 |
VehiclePositionChanged(v); |
|
838 |
EndVehicleMove(v); |
|
839 |
} |
|
840 |
} |
|
841 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
842 |
static void SteamSmokeInit(Vehicle *v) |
0 | 843 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
844 |
v->cur_image = SPR_STEAM_SMOKE_0; |
0 | 845 |
v->progress = 12; |
846 |
} |
|
847 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
848 |
static void SteamSmokeTick(Vehicle *v) |
0 | 849 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
850 |
bool moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
851 |
|
0 | 852 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
853 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
854 |
v->progress++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
855 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
856 |
if ((v->progress & 7) == 0) { |
0 | 857 |
v->z_pos++; |
858 |
moved = true; |
|
859 |
} |
|
860 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
861 |
if ((v->progress & 0xF) == 4) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
862 |
if (v->cur_image != SPR_STEAM_SMOKE_4) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
863 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
864 |
} else { |
0 | 865 |
EndVehicleMove(v); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
866 |
delete v; |
0 | 867 |
return; |
868 |
} |
|
869 |
moved = true; |
|
870 |
} |
|
871 |
||
872 |
if (moved) { |
|
873 |
VehiclePositionChanged(v); |
|
874 |
EndVehicleMove(v); |
|
875 |
} |
|
876 |
} |
|
877 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
878 |
static void DieselSmokeInit(Vehicle *v) |
0 | 879 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
880 |
v->cur_image = SPR_DIESEL_SMOKE_0; |
0 | 881 |
v->progress = 0; |
882 |
} |
|
883 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
884 |
static void DieselSmokeTick(Vehicle *v) |
0 | 885 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
886 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
887 |
|
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
888 |
if ((v->progress & 3) == 0) { |
0 | 889 |
BeginVehicleMove(v); |
890 |
v->z_pos++; |
|
891 |
VehiclePositionChanged(v); |
|
892 |
EndVehicleMove(v); |
|
893 |
} else if ((v->progress & 7) == 1) { |
|
894 |
BeginVehicleMove(v); |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
895 |
if (v->cur_image != SPR_DIESEL_SMOKE_5) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
896 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
897 |
VehiclePositionChanged(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
898 |
EndVehicleMove(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
899 |
} else { |
0 | 900 |
EndVehicleMove(v); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
901 |
delete v; |
0 | 902 |
} |
903 |
} |
|
904 |
} |
|
905 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
906 |
static void ElectricSparkInit(Vehicle *v) |
0 | 907 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
908 |
v->cur_image = SPR_ELECTRIC_SPARK_0; |
0 | 909 |
v->progress = 1; |
910 |
} |
|
911 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
912 |
static void ElectricSparkTick(Vehicle *v) |
0 | 913 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
914 |
if (v->progress < 2) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
915 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
916 |
} else { |
0 | 917 |
v->progress = 0; |
918 |
BeginVehicleMove(v); |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
919 |
if (v->cur_image != SPR_ELECTRIC_SPARK_5) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
920 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
921 |
VehiclePositionChanged(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
922 |
EndVehicleMove(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
923 |
} else { |
0 | 924 |
EndVehicleMove(v); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
925 |
delete v; |
0 | 926 |
} |
927 |
} |
|
928 |
} |
|
929 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
930 |
static void SmokeInit(Vehicle *v) |
0 | 931 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
932 |
v->cur_image = SPR_SMOKE_0; |
0 | 933 |
v->progress = 12; |
934 |
} |
|
935 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
936 |
static void SmokeTick(Vehicle *v) |
0 | 937 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
938 |
bool moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
939 |
|
0 | 940 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
941 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
942 |
v->progress++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
943 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
944 |
if ((v->progress & 3) == 0) { |
0 | 945 |
v->z_pos++; |
946 |
moved = true; |
|
947 |
} |
|
948 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
949 |
if ((v->progress & 0xF) == 4) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
950 |
if (v->cur_image != SPR_SMOKE_4) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
951 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
952 |
} else { |
0 | 953 |
EndVehicleMove(v); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
954 |
delete v; |
0 | 955 |
return; |
956 |
} |
|
957 |
moved = true; |
|
958 |
} |
|
959 |
||
960 |
if (moved) { |
|
961 |
VehiclePositionChanged(v); |
|
962 |
EndVehicleMove(v); |
|
963 |
} |
|
964 |
} |
|
965 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
966 |
static void ExplosionLargeInit(Vehicle *v) |
0 | 967 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
968 |
v->cur_image = SPR_EXPLOSION_LARGE_0; |
0 | 969 |
v->progress = 0; |
970 |
} |
|
971 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
972 |
static void ExplosionLargeTick(Vehicle *v) |
0 | 973 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
974 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
975 |
if ((v->progress & 3) == 0) { |
0 | 976 |
BeginVehicleMove(v); |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
977 |
if (v->cur_image != SPR_EXPLOSION_LARGE_F) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
978 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
979 |
VehiclePositionChanged(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
980 |
EndVehicleMove(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
981 |
} else { |
0 | 982 |
EndVehicleMove(v); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
983 |
delete v; |
0 | 984 |
} |
985 |
} |
|
986 |
} |
|
987 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
988 |
static void BreakdownSmokeInit(Vehicle *v) |
0 | 989 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
990 |
v->cur_image = SPR_BREAKDOWN_SMOKE_0; |
0 | 991 |
v->progress = 0; |
992 |
} |
|
993 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
994 |
static void BreakdownSmokeTick(Vehicle *v) |
0 | 995 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
996 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
997 |
if ((v->progress & 7) == 0) { |
0 | 998 |
BeginVehicleMove(v); |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
999 |
if (v->cur_image != SPR_BREAKDOWN_SMOKE_3) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1000 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1001 |
} else { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1002 |
v->cur_image = SPR_BREAKDOWN_SMOKE_0; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1003 |
} |
0 | 1004 |
VehiclePositionChanged(v); |
1005 |
EndVehicleMove(v); |
|
1006 |
} |
|
1007 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1008 |
v->u.special.animation_state--; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1009 |
if (v->u.special.animation_state == 0) { |
0 | 1010 |
BeginVehicleMove(v); |
1011 |
EndVehicleMove(v); |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1012 |
delete v; |
0 | 1013 |
} |
1014 |
} |
|
1015 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1016 |
static void ExplosionSmallInit(Vehicle *v) |
0 | 1017 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1018 |
v->cur_image = SPR_EXPLOSION_SMALL_0; |
0 | 1019 |
v->progress = 0; |
1020 |
} |
|
1021 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1022 |
static void ExplosionSmallTick(Vehicle *v) |
0 | 1023 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1024 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1025 |
if ((v->progress & 3) == 0) { |
0 | 1026 |
BeginVehicleMove(v); |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1027 |
if (v->cur_image != SPR_EXPLOSION_SMALL_B) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1028 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1029 |
VehiclePositionChanged(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1030 |
EndVehicleMove(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1031 |
} else { |
0 | 1032 |
EndVehicleMove(v); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1033 |
delete v; |
0 | 1034 |
} |
1035 |
} |
|
1036 |
} |
|
1037 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1038 |
static void BulldozerInit(Vehicle *v) |
0 | 1039 |
{ |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1040 |
v->cur_image = SPR_BULLDOZER_NE; |
0 | 1041 |
v->progress = 0; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1042 |
v->u.special.animation_state = 0; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1043 |
v->u.special.animation_substate = 0; |
0 | 1044 |
} |
1045 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1046 |
struct BulldozerMovement { |
1365
7eff6abe942a
(svn r1869) Fix some bugs in the bulldozer movement implementation.
tron
parents:
1364
diff
changeset
|
1047 |
byte direction:2; |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1048 |
byte image:2; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1049 |
byte duration:3; |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1050 |
}; |
0 | 1051 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1052 |
static const BulldozerMovement _bulldozer_movement[] = { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1053 |
{ 0, 0, 4 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1054 |
{ 3, 3, 4 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1055 |
{ 2, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1056 |
{ 0, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1057 |
{ 1, 1, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1058 |
{ 2, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1059 |
{ 0, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1060 |
{ 1, 1, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1061 |
{ 2, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1062 |
{ 0, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1063 |
{ 3, 3, 6 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1064 |
{ 2, 2, 6 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1065 |
{ 1, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1066 |
{ 3, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1067 |
{ 0, 0, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1068 |
{ 1, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1069 |
{ 3, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1070 |
{ 0, 0, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1071 |
{ 1, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1072 |
{ 3, 1, 7 } |
0 | 1073 |
}; |
1074 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1075 |
static const struct { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1076 |
int8 x; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1077 |
int8 y; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1078 |
} _inc_by_dir[] = { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1079 |
{ -1, 0 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1080 |
{ 0, 1 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1081 |
{ 1, 0 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1082 |
{ 0, -1 } |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1083 |
}; |
0 | 1084 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1085 |
static void BulldozerTick(Vehicle *v) |
0 | 1086 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1087 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1088 |
if ((v->progress & 7) == 0) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1089 |
const BulldozerMovement* b = &_bulldozer_movement[v->u.special.animation_state]; |
0 | 1090 |
|
1091 |
BeginVehicleMove(v); |
|
1092 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1093 |
v->cur_image = SPR_BULLDOZER_NE + b->image; |
0 | 1094 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1095 |
v->x_pos += _inc_by_dir[b->direction].x; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1096 |
v->y_pos += _inc_by_dir[b->direction].y; |
0 | 1097 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1098 |
v->u.special.animation_substate++; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1099 |
if (v->u.special.animation_substate >= b->duration) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1100 |
v->u.special.animation_substate = 0; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1101 |
v->u.special.animation_state++; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1102 |
if (v->u.special.animation_state == lengthof(_bulldozer_movement)) { |
0 | 1103 |
EndVehicleMove(v); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1104 |
delete v; |
0 | 1105 |
return; |
1106 |
} |
|
1107 |
} |
|
1108 |
VehiclePositionChanged(v); |
|
1109 |
EndVehicleMove(v); |
|
1110 |
} |
|
1111 |
} |
|
1112 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1113 |
static void BubbleInit(Vehicle *v) |
0 | 1114 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1115 |
v->cur_image = SPR_BUBBLE_GENERATE_0; |
0 | 1116 |
v->spritenum = 0; |
1117 |
v->progress = 0; |
|
1118 |
} |
|
1119 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1120 |
struct BubbleMovement { |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1121 |
int8 x:4; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1122 |
int8 y:4; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1123 |
int8 z:4; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1124 |
byte image:4; |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1125 |
}; |
0 | 1126 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1127 |
#define MK(x, y, z, i) { x, y, z, i } |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1128 |
#define ME(i) { i, 4, 0, 0 } |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1129 |
|
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1130 |
static const BubbleMovement _bubble_float_sw[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1131 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1132 |
MK(1, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1133 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1134 |
MK(1, 0, 1, 2), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1135 |
ME(1) |
0 | 1136 |
}; |
1137 |
||
1138 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1139 |
static const BubbleMovement _bubble_float_ne[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1140 |
MK( 0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1141 |
MK(-1, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1142 |
MK( 0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1143 |
MK(-1, 0, 1, 2), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1144 |
ME(1) |
0 | 1145 |
}; |
1146 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1147 |
static const BubbleMovement _bubble_float_se[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1148 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1149 |
MK(0, 1, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1150 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1151 |
MK(0, 1, 1, 2), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1152 |
ME(1) |
0 | 1153 |
}; |
1154 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1155 |
static const BubbleMovement _bubble_float_nw[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1156 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1157 |
MK(0, -1, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1158 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1159 |
MK(0, -1, 1, 2), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1160 |
ME(1) |
0 | 1161 |
}; |
1162 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1163 |
static const BubbleMovement _bubble_burst[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1164 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1165 |
MK(0, 0, 1, 7), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1166 |
MK(0, 0, 1, 8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1167 |
MK(0, 0, 1, 9), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1168 |
ME(0) |
0 | 1169 |
}; |
1170 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1171 |
static const BubbleMovement _bubble_absorb[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1172 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1173 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1174 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1175 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1176 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1177 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1178 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1179 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1180 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1181 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1182 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1183 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1184 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1185 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1186 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1187 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1188 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1189 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1190 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1191 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1192 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1193 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1194 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1195 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1196 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1197 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1198 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1199 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1200 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1201 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1202 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1203 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1204 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1205 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1206 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1207 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1208 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1209 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1210 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1211 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1212 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1213 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1214 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1215 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1216 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1217 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1218 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1219 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1220 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1221 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1222 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1223 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1224 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1225 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1226 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1227 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1228 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1229 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1230 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1231 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1232 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1233 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1234 |
MK(2, 1, 3, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1235 |
MK(1, 1, 3, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1236 |
MK(2, 1, 3, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1237 |
MK(1, 1, 3, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1238 |
MK(2, 1, 3, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1239 |
MK(1, 1, 3, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1240 |
MK(2, 1, 3, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1241 |
MK(1, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1242 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1243 |
MK(1, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1244 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1245 |
MK(1, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1246 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1247 |
MK(1, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1248 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1249 |
MK(1, 0, 1, 2), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1250 |
ME(2), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1251 |
MK(0, 0, 0, 0xA), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1252 |
MK(0, 0, 0, 0xB), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1253 |
MK(0, 0, 0, 0xC), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1254 |
MK(0, 0, 0, 0xD), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1255 |
MK(0, 0, 0, 0xE), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1256 |
ME(0) |
0 | 1257 |
}; |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1258 |
#undef ME |
0 | 1259 |
#undef MK |
1260 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1261 |
static const BubbleMovement * const _bubble_movement[] = { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1262 |
_bubble_float_sw, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1263 |
_bubble_float_ne, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1264 |
_bubble_float_se, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1265 |
_bubble_float_nw, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1266 |
_bubble_burst, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1267 |
_bubble_absorb, |
0 | 1268 |
}; |
1269 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1270 |
static void BubbleTick(Vehicle *v) |
0 | 1271 |
{ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1272 |
/* |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1273 |
* 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
|
1274 |
* InteractiveRandom(), because somehow someone forgot to save |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1275 |
* 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
|
1276 |
* multiplayer!! (that is: in ToyLand) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1277 |
*/ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1278 |
uint et; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1279 |
const BubbleMovement *b; |
0 | 1280 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1281 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1282 |
if ((v->progress & 3) != 0) |
0 | 1283 |
return; |
1284 |
||
1285 |
BeginVehicleMove(v); |
|
1286 |
||
1287 |
if (v->spritenum == 0) { |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1288 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1289 |
if (v->cur_image < SPR_BUBBLE_GENERATE_3) { |
0 | 1290 |
VehiclePositionChanged(v); |
1291 |
EndVehicleMove(v); |
|
1292 |
return; |
|
1293 |
} |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1294 |
if (v->u.special.animation_substate != 0) { |
2635 | 1295 |
v->spritenum = GB(InteractiveRandom(), 0, 2) + 1; |
0 | 1296 |
} else { |
1297 |
v->spritenum = 6; |
|
1298 |
} |
|
1299 |
et = 0; |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1300 |
} else { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1301 |
et = v->engine_type + 1; |
0 | 1302 |
} |
1303 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1304 |
b = &_bubble_movement[v->spritenum - 1][et]; |
0 | 1305 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1306 |
if (b->y == 4 && b->x == 0) { |
0 | 1307 |
EndVehicleMove(v); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1308 |
delete v; |
0 | 1309 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1310 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1311 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1312 |
if (b->y == 4 && b->x == 1) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1313 |
if (v->z_pos > 180 || Chance16I(1, 96, InteractiveRandom())) { |
0 | 1314 |
v->spritenum = 5; |
541 | 1315 |
SndPlayVehicleFx(SND_2F_POP, v); |
0 | 1316 |
} |
1317 |
et = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1318 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1319 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1320 |
if (b->y == 4 && b->x == 2) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1321 |
TileIndex tile; |
0 | 1322 |
|
1323 |
et++; |
|
541 | 1324 |
SndPlayVehicleFx(SND_31_EXTRACT, v); |
0 | 1325 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1326 |
tile = TileVirtXY(v->x_pos, v->y_pos); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1327 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryGfx(tile) == GFX_BUBBLE_CATCHER) AddAnimatedTile(tile); |
0 | 1328 |
} |
1329 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1330 |
v->engine_type = et; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1331 |
b = &_bubble_movement[v->spritenum - 1][et]; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1332 |
|
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1333 |
v->x_pos += b->x; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1334 |
v->y_pos += b->y; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1335 |
v->z_pos += b->z; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1336 |
v->cur_image = SPR_BUBBLE_0 + b->image; |
0 | 1337 |
|
1338 |
VehiclePositionChanged(v); |
|
1339 |
EndVehicleMove(v); |
|
1340 |
} |
|
1341 |
||
1342 |
||
1343 |
typedef void EffectInitProc(Vehicle *v); |
|
1344 |
typedef void EffectTickProc(Vehicle *v); |
|
1345 |
||
1346 |
static EffectInitProc * const _effect_init_procs[] = { |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1347 |
ChimneySmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1348 |
SteamSmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1349 |
DieselSmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1350 |
ElectricSparkInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1351 |
SmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1352 |
ExplosionLargeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1353 |
BreakdownSmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1354 |
ExplosionSmallInit, |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1355 |
BulldozerInit, |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1356 |
BubbleInit, |
0 | 1357 |
}; |
1358 |
||
1359 |
static EffectTickProc * const _effect_tick_procs[] = { |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1360 |
ChimneySmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1361 |
SteamSmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1362 |
DieselSmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1363 |
ElectricSparkTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1364 |
SmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1365 |
ExplosionLargeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1366 |
BreakdownSmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1367 |
ExplosionSmallTick, |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1368 |
BulldozerTick, |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1369 |
BubbleTick, |
0 | 1370 |
}; |
1371 |
||
1372 |
||
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
|
1373 |
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type) |
0 | 1374 |
{ |
1375 |
Vehicle *v; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1376 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1377 |
v = new SpecialVehicle(); |
0 | 1378 |
if (v != NULL) { |
1379 |
v->subtype = type; |
|
1380 |
v->x_pos = x; |
|
1381 |
v->y_pos = y; |
|
1382 |
v->z_pos = z; |
|
1383 |
v->tile = 0; |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1384 |
v->UpdateDeltaXY(INVALID_DIR); |
0 | 1385 |
v->vehstatus = VS_UNCLICKABLE; |
1386 |
||
1387 |
_effect_init_procs[type](v); |
|
1388 |
||
1389 |
VehiclePositionChanged(v); |
|
1390 |
BeginVehicleMove(v); |
|
1391 |
EndVehicleMove(v); |
|
1392 |
} |
|
1393 |
return v; |
|
1394 |
} |
|
1395 |
||
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
|
1396 |
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type) |
0 | 1397 |
{ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1398 |
int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1399 |
int safe_y = Clamp(y, 0, MapMaxY() * TILE_SIZE); |
5295
ab31e01faa80
(svn r7448) -Fix (r5794): use the height of the edge of the map for effect vehicles that are outside the map.
rubidium
parents:
5256
diff
changeset
|
1400 |
return CreateEffectVehicle(x, y, GetSlopeZ(safe_x, safe_y) + z, type); |
0 | 1401 |
} |
1402 |
||
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
|
1403 |
Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type) |
0 | 1404 |
{ |
1405 |
return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type); |
|
1406 |
} |
|
1407 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1408 |
void SpecialVehicle::Tick() |
0 | 1409 |
{ |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1410 |
_effect_tick_procs[this->subtype](this); |
0 | 1411 |
} |
1412 |
||
2116 | 1413 |
Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y) |
0 | 1414 |
{ |
1415 |
Vehicle *found = NULL, *v; |
|
1416 |
uint dist, best_dist = (uint)-1; |
|
1417 |
||
1418 |
if ( (uint)(x -= vp->left) >= (uint)vp->width || |
|
1419 |
(uint)(y -= vp->top) >= (uint)vp->height) |
|
1420 |
return NULL; |
|
1421 |
||
9624 | 1422 |
x = ScaleByZoom(x, vp->zoom) + vp->virtual_left; |
1423 |
y = ScaleByZoom(y, vp->zoom) + vp->virtual_top; |
|
0 | 1424 |
|
1425 |
FOR_ALL_VEHICLES(v) { |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1426 |
if ((v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0 && |
0 | 1427 |
x >= v->left_coord && x <= v->right_coord && |
1428 |
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
|
1429 |
|
0 | 1430 |
dist = max( |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1431 |
abs( ((v->left_coord + v->right_coord)>>1) - x ), |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1432 |
abs( ((v->top_coord + v->bottom_coord)>>1) - y ) |
0 | 1433 |
); |
1434 |
||
1435 |
if (dist < best_dist) { |
|
1436 |
found = v; |
|
1437 |
best_dist = dist; |
|
1438 |
} |
|
1439 |
} |
|
1440 |
} |
|
1441 |
||
1442 |
return found; |
|
1443 |
} |
|
1444 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1445 |
void CheckVehicle32Day(Vehicle *v) |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1446 |
{ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1447 |
if ((v->day_counter & 0x1F) != 0) return; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1448 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1449 |
uint16 callback = GetVehicleCallback(CBID_VEHICLE_32DAY_CALLBACK, 0, 0, v->engine_type, v); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1450 |
if (callback == CALLBACK_FAILED) return; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1451 |
if (HasBit(callback, 0)) TriggerVehicle(v, VEHICLE_TRIGGER_CALLBACK_32); // Trigger vehicle trigger 10 |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1452 |
if (HasBit(callback, 1)) v->colormap = PAL_NONE; // Update colormap via callback 2D |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1453 |
} |
0 | 1454 |
|
1455 |
void DecreaseVehicleValue(Vehicle *v) |
|
1456 |
{ |
|
1457 |
v->value -= v->value >> 8; |
|
1458 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1459 |
} |
|
1460 |
||
1461 |
static const byte _breakdown_chance[64] = { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1462 |
3, 3, 3, 3, 3, 3, 3, 3, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1463 |
4, 4, 5, 5, 6, 6, 7, 7, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1464 |
8, 8, 9, 9, 10, 10, 11, 11, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1465 |
12, 13, 13, 13, 13, 14, 15, 16, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1466 |
17, 19, 21, 25, 28, 31, 34, 37, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1467 |
40, 44, 48, 52, 56, 60, 64, 68, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1468 |
72, 80, 90, 100, 110, 120, 130, 140, |
0 | 1469 |
150, 170, 190, 210, 230, 250, 250, 250, |
1470 |
}; |
|
1471 |
||
1472 |
void CheckVehicleBreakdown(Vehicle *v) |
|
1473 |
{ |
|
1474 |
int rel, rel_old; |
|
1475 |
uint32 r; |
|
1476 |
int chance; |
|
1477 |
||
1478 |
/* decrease reliability */ |
|
1479 |
v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0); |
|
1480 |
if ((rel_old >> 8) != (rel >> 8)) |
|
1481 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1482 |
||
2639 | 1483 |
if (v->breakdown_ctr != 0 || v->vehstatus & VS_STOPPED || |
1484 |
v->cur_speed < 5 || _game_mode == GM_MENU) { |
|
1485 |
return; |
|
1486 |
} |
|
0 | 1487 |
|
1488 |
r = Random(); |
|
1489 |
||
1490 |
/* increase chance of failure */ |
|
1491 |
chance = v->breakdown_chance + 1; |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1492 |
if (Chance16I(1,25,r)) chance += 25; |
0 | 1493 |
v->breakdown_chance = min(255, chance); |
1494 |
||
1495 |
/* calculate reliability value to use in comparison */ |
|
1496 |
rel = v->reliability; |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1497 |
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
|
1498 |
|
0 | 1499 |
/* disabled breakdowns? */ |
2639 | 1500 |
if (_opt.diff.vehicle_breakdowns < 1) return; |
0 | 1501 |
|
1502 |
/* reduced breakdowns? */ |
|
1503 |
if (_opt.diff.vehicle_breakdowns == 1) rel += 0x6666; |
|
1504 |
||
1505 |
/* check if to break down */ |
|
1506 |
if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) { |
|
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
1507 |
v->breakdown_ctr = GB(r, 16, 6) + 0x3F; |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
1508 |
v->breakdown_delay = GB(r, 24, 7) + 0x80; |
0 | 1509 |
v->breakdown_chance = 0; |
1510 |
} |
|
1511 |
} |
|
1512 |
||
1513 |
static const StringID _vehicle_type_names[4] = { |
|
1514 |
STR_019F_TRAIN, |
|
1515 |
STR_019C_ROAD_VEHICLE, |
|
1516 |
STR_019E_SHIP, |
|
1517 |
STR_019D_AIRCRAFT, |
|
1518 |
}; |
|
1519 |
||
1520 |
static void ShowVehicleGettingOld(Vehicle *v, StringID msg) |
|
1521 |
{ |
|
2639 | 1522 |
if (v->owner != _local_player) return; |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1523 |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1524 |
/* Do not show getting-old message if autorenew is active (and it can replace the vehicle) */ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1525 |
if (GetPlayer(v->owner)->engine_renew && GetEngine(v->engine_type)->player_avail != 0) return; |
0 | 1526 |
|
6206
67358999d80d
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
6195
diff
changeset
|
1527 |
SetDParam(0, _vehicle_type_names[v->type]); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1528 |
SetDParam(1, v->unitnumber); |
0 | 1529 |
AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
1530 |
} |
|
1531 |
||
1532 |
void AgeVehicle(Vehicle *v) |
|
1533 |
{ |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1534 |
if (v->age < 65535) v->age++; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1535 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1536 |
int age = v->age - v->max_age; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1537 |
if (age == 366*0 || age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4) v->reliability_spd_dec <<= 1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1538 |
|
0 | 1539 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
1540 |
||
1541 |
if (age == -366) { |
|
1542 |
ShowVehicleGettingOld(v, STR_01A0_IS_GETTING_OLD); |
|
1543 |
} else if (age == 0) { |
|
1544 |
ShowVehicleGettingOld(v, STR_01A1_IS_GETTING_VERY_OLD); |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1545 |
} else if (age > 0 && (age % 366) == 0) { |
0 | 1546 |
ShowVehicleGettingOld(v, STR_01A2_IS_GETTING_VERY_OLD_AND); |
1547 |
} |
|
1548 |
} |
|
1549 |
||
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1550 |
/** Starts or stops a lot of vehicles |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1551 |
* @param tile Tile of the depot where the vehicles are started/stopped (only used for depots) |
9574 | 1552 |
* @param flags type of operation |
4762
58d2f43ebdda
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1553 |
* @param p1 Station/Order/Depot ID (only used for vehicle list windows) |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1554 |
* @param p2 bitmask |
4762
58d2f43ebdda
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1555 |
* - bit 0-4 Vehicle type |
58d2f43ebdda
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1556 |
* - bit 5 false = start vehicles, true = stop vehicles |
58d2f43ebdda
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1557 |
* - bit 6 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1558 |
* - bit 8-11 Vehicle List Window type (ignored unless bit 1 is set) |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1559 |
*/ |
9629 | 1560 |
CommandCost CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1561 |
{ |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1562 |
Vehicle **vl = NULL; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1563 |
uint16 engine_list_length = 0; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1564 |
uint16 engine_count = 0; |
9629 | 1565 |
CommandCost return_value = CMD_ERROR; |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1566 |
uint i; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1567 |
uint stop_command; |
9624 | 1568 |
VehicleType vehicle_type = (VehicleType)GB(p2, 0, 5); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1569 |
bool start_stop = HasBit(p2, 5); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1570 |
bool vehicle_list_window = HasBit(p2, 6); |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1571 |
|
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1572 |
switch (vehicle_type) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1573 |
case VEH_TRAIN: stop_command = CMD_START_STOP_TRAIN; break; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1574 |
case VEH_ROAD: stop_command = CMD_START_STOP_ROADVEH; break; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1575 |
case VEH_SHIP: stop_command = CMD_START_STOP_SHIP; break; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1576 |
case VEH_AIRCRAFT: stop_command = CMD_START_STOP_AIRCRAFT; break; |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1577 |
default: return CMD_ERROR; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1578 |
} |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1579 |
|
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1580 |
if (vehicle_list_window) { |
5999
0de08210079a
(svn r8296) -Fix: GenerateVehicleSortList() tried to put a TileIndex into an uint16
bjarni
parents:
5998
diff
changeset
|
1581 |
uint32 id = p1; |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1582 |
uint16 window_type = p2 & VLW_MASK; |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1583 |
|
5998
9491f99be62d
(svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument
bjarni
parents:
5997
diff
changeset
|
1584 |
engine_count = GenerateVehicleSortList((const Vehicle***)&vl, &engine_list_length, vehicle_type, _current_player, id, window_type); |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1585 |
} else { |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1586 |
/* Get the list of vehicles in the depot */ |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1587 |
BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL); |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1588 |
} |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1589 |
|
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1590 |
for (i = 0; i < engine_count; i++) { |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1591 |
const Vehicle *v = vl[i]; |
9629 | 1592 |
CommandCost ret; |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1593 |
|
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1594 |
if (!!(v->vehstatus & VS_STOPPED) != start_stop) continue; |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1595 |
|
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1596 |
if (!vehicle_list_window) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1597 |
if (vehicle_type == VEH_TRAIN) { |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1598 |
if (CheckTrainInDepot(v, false) == -1) continue; |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1599 |
} else { |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1600 |
if (!(v->vehstatus & VS_HIDDEN)) continue; |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1601 |
} |
4648
ab94e3a447a8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1602 |
} |
ab94e3a447a8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1603 |
|
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1604 |
ret = DoCommand(tile, v->index, 0, flags, stop_command); |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1605 |
|
9629 | 1606 |
if (CmdSucceeded(ret)) { |
1607 |
return_value = CommandCost(); |
|
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1608 |
/* We know that the command is valid for at least one vehicle. |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1609 |
* If we haven't set DC_EXEC, then there is no point in continueing because it will be valid */ |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1610 |
if (!(flags & DC_EXEC)) break; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1611 |
} |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1612 |
} |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1613 |
|
4648
ab94e3a447a8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1614 |
free(vl); |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1615 |
return return_value; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1616 |
} |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1617 |
|
4659
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1618 |
/** Sells all vehicles in a depot |
9574 | 1619 |
* @param tile Tile of the depot where the depot is |
1620 |
* @param flags type of operation |
|
1621 |
* @param p1 Vehicle type |
|
1622 |
* @param p2 unused |
|
1623 |
*/ |
|
9629 | 1624 |
CommandCost CmdDepotSellAllVehicles(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
4659
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1625 |
{ |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1626 |
Vehicle **engines = NULL; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1627 |
Vehicle **wagons = NULL; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1628 |
uint16 engine_list_length = 0; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1629 |
uint16 engine_count = 0; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1630 |
uint16 wagon_list_length = 0; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1631 |
uint16 wagon_count = 0; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1632 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1633 |
CommandCost cost(EXPENSES_NEW_VEHICLES); |
4659
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1634 |
uint i, sell_command, total_number_vehicles; |
9624 | 1635 |
VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8); |
4659
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1636 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1637 |
switch (vehicle_type) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1638 |
case VEH_TRAIN: sell_command = CMD_SELL_RAIL_WAGON; break; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1639 |
case VEH_ROAD: sell_command = CMD_SELL_ROAD_VEH; break; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1640 |
case VEH_SHIP: sell_command = CMD_SELL_SHIP; break; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1641 |
case VEH_AIRCRAFT: sell_command = CMD_SELL_AIRCRAFT; break; |
4659
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1642 |
default: return CMD_ERROR; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1643 |
} |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1644 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1645 |
/* Get the list of vehicles in the depot */ |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1646 |
BuildDepotVehicleList(vehicle_type, tile, &engines, &engine_list_length, &engine_count, |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1647 |
&wagons, &wagon_list_length, &wagon_count); |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1648 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1649 |
total_number_vehicles = engine_count + wagon_count; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1650 |
for (i = 0; i < total_number_vehicles; i++) { |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1651 |
const Vehicle *v; |
9629 | 1652 |
CommandCost ret; |
4659
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1653 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1654 |
if (i < engine_count) { |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1655 |
v = engines[i]; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1656 |
} else { |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1657 |
v = wagons[i - engine_count]; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1658 |
} |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1659 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1660 |
ret = DoCommand(tile, v->index, 1, flags, sell_command); |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1661 |
|
9629 | 1662 |
if (CmdSucceeded(ret)) cost.AddCost(ret); |
4659
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1663 |
} |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1664 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1665 |
free(engines); |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1666 |
free(wagons); |
9629 | 1667 |
if (cost.GetCost() == 0) return CMD_ERROR; // no vehicles to sell |
4659
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1668 |
return cost; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1669 |
} |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1670 |
|
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1671 |
/** Autoreplace all vehicles in the depot |
9574 | 1672 |
* @param tile Tile of the depot where the vehicles are |
1673 |
* @param flags type of operation |
|
1674 |
* @param p1 Type of vehicle |
|
1675 |
* @param p2 Unused |
|
1676 |
*/ |
|
9629 | 1677 |
CommandCost CmdDepotMassAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1678 |
{ |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1679 |
Vehicle **vl = NULL; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1680 |
uint16 engine_list_length = 0; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1681 |
uint16 engine_count = 0; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1682 |
uint i, x = 0, y = 0, z = 0; |
9629 | 1683 |
CommandCost cost; |
9624 | 1684 |
VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8); |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1685 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1686 |
if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR; |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1687 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1688 |
/* Get the list of vehicles in the depot */ |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1689 |
BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL); |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1690 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1691 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1692 |
for (i = 0; i < engine_count; i++) { |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1693 |
Vehicle *v = vl[i]; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1694 |
bool stopped = !(v->vehstatus & VS_STOPPED); |
9629 | 1695 |
CommandCost ret; |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1696 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1697 |
/* Ensure that the vehicle completely in the depot */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1698 |
if (!v->IsInDepot()) continue; |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1699 |
|
4676
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1700 |
x = v->x_pos; |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1701 |
y = v->y_pos; |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1702 |
z = v->z_pos; |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1703 |
|
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1704 |
if (stopped) { |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1705 |
v->vehstatus |= VS_STOPPED; // Stop the vehicle |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1706 |
v->leave_depot_instantly = true; |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1707 |
} |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1708 |
ret = MaybeReplaceVehicle(v, !(flags & DC_EXEC), false); |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1709 |
|
9629 | 1710 |
if (CmdSucceeded(ret)) { |
1711 |
cost.AddCost(ret); |
|
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1712 |
if (!(flags & DC_EXEC)) break; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1713 |
/* There is a problem with autoreplace and newgrf |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1714 |
* It's impossible to tell the length of a train after it's being replaced before it's actually done |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1715 |
* Because of this, we can't estimate costs due to wagon removal and we will have to always return 0 and pay manually |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1716 |
* Since we pay after each vehicle is replaced and MaybeReplaceVehicle() check if the player got enough money |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1717 |
* we should never reach a condition where the player will end up with negative money from doing this */ |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1718 |
SubtractMoneyFromPlayer(ret); |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1719 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1720 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1721 |
|
9629 | 1722 |
if (cost.GetCost() == 0) { |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1723 |
cost = CMD_ERROR; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1724 |
} else { |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1725 |
if (flags & DC_EXEC) { |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1726 |
/* Display the cost animation now that DoCommandP() can't do it for us (see previous comments) */ |
9629 | 1727 |
if (IsLocalPlayer()) ShowCostOrIncomeAnimation(x, y, z, cost.GetCost()); |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1728 |
} |
9629 | 1729 |
cost = CommandCost(); |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1730 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1731 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1732 |
free(vl); |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1733 |
return cost; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1734 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1735 |
|
2244 | 1736 |
/** Clone a vehicle. If it is a train, it will clone all the cars too |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1737 |
* @param tile tile of the depot where the cloned vehicle is build |
9574 | 1738 |
* @param flags type of operation |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1739 |
* @param p1 the original vehicle's index |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1740 |
* @param p2 1 = shared orders, else copied orders |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1741 |
*/ |
9629 | 1742 |
CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2244 | 1743 |
{ |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1744 |
Vehicle *v_front, *v; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1745 |
Vehicle *w_front, *w, *w_rear; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1746 |
CommandCost cost, total_cost(EXPENSES_NEW_VEHICLES); |
3816
2cdb29b57c1f
(svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
bjarni
parents:
3815
diff
changeset
|
1747 |
uint32 build_argument = 2; |
2244 | 1748 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
1749 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
2244 | 1750 |
v = GetVehicle(p1); |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1751 |
v_front = v; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1752 |
w = NULL; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1753 |
w_front = NULL; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1754 |
w_rear = NULL; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1755 |
|
9599 | 1756 |
|
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1757 |
/* |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1758 |
* v_front is the front engine in the original vehicle |
9599 | 1759 |
* v is the car/vehicle of the original vehicle, that is currently being copied |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1760 |
* w_front is the front engine of the cloned vehicle |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1761 |
* w is the car/vehicle currently being cloned |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1762 |
* w_rear is the rear end of the cloned train. It's used to add more cars and is only used by trains |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1763 |
*/ |
2244 | 1764 |
|
2639 | 1765 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
2244 | 1766 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1767 |
if (v->type == VEH_TRAIN && (!IsFrontEngine(v) || v->u.rail.crash_anim_pos >= 4400)) return CMD_ERROR; |
2244 | 1768 |
|
9574 | 1769 |
/* check that we can allocate enough vehicles */ |
2601
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1770 |
if (!(flags & DC_EXEC)) { |
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1771 |
int veh_counter = 0; |
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1772 |
do { |
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1773 |
veh_counter++; |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1774 |
} while ((v = v->Next()) != NULL); |
2601
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1775 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1776 |
if (!Vehicle::AllocateList(NULL, veh_counter)) { |
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
1777 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
2601
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1778 |
} |
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1779 |
} |
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1780 |
|
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1781 |
v = v_front; |
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1782 |
|
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1783 |
do { |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1784 |
if (v->type == VEH_TRAIN && IsRearDualheaded(v)) { |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1785 |
/* we build the rear ends of multiheaded trains with the front ones */ |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1786 |
continue; |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1787 |
} |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1788 |
|
6043
99c8fb13658b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
6014
diff
changeset
|
1789 |
cost = DoCommand(tile, v->engine_type, build_argument, flags, GetCmdBuildVeh(v)); |
3819
281ac50dba17
(svn r4829) -Codechage: [clone vehilces] only check for a free unitnumber for the first engine in the test run as well as execute run (to improve speed. The result should be unchanged)
bjarni
parents:
3816
diff
changeset
|
1790 |
build_argument = 3; // ensure that we only assign a number to the first engine |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1791 |
|
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1792 |
if (CmdFailed(cost)) return cost; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1793 |
|
9629 | 1794 |
total_cost.AddCost(cost); |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1795 |
|
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1796 |
if (flags & DC_EXEC) { |
2639 | 1797 |
w = GetVehicle(_new_vehicle_id); |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1798 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1799 |
if (v->type == VEH_TRAIN && HasBit(v->u.rail.flags, VRF_REVERSE_DIRECTION)) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1800 |
SetBit(w->u.rail.flags, VRF_REVERSE_DIRECTION); |
3896
292881445b9c
(svn r4967) -Fix: [clone vehicles] a cloned train engine heads the same way as the original (pointed out by bobingabout)
bjarni
parents:
3881
diff
changeset
|
1801 |
} |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1802 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1803 |
if (v->type == VEH_TRAIN && !IsFrontEngine(v)) { |
9574 | 1804 |
/* this s a train car |
1805 |
* add this unit to the end of the train */ |
|
9629 | 1806 |
CommandCost result = DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE); |
9626 | 1807 |
if (CmdFailed(result)) { |
1808 |
/* The train can't be joined to make the same consist as the original. |
|
1809 |
* Sell what we already made (clean up) and return an error. */ |
|
1810 |
DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front)); |
|
1811 |
DoCommand(w_front->tile, w->index, 1, flags, GetCmdSellVeh(w)); |
|
1812 |
return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE |
|
1813 |
} |
|
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1814 |
} else { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1815 |
/* this is a front engine or not a train. */ |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1816 |
w_front = w; |
3679
8e7e14ee361a
(svn r4599) -Fix: [Cloning, autoreplace] FS#141 clone service-interval
bjarni
parents:
3657
diff
changeset
|
1817 |
w->service_interval = v->service_interval; |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1818 |
} |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
1819 |
w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1820 |
} |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1821 |
} while (v->type == VEH_TRAIN && (v = GetNextVehicle(v)) != NULL); |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1822 |
|
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1823 |
if (flags & DC_EXEC && v_front->type == VEH_TRAIN) { |
9574 | 1824 |
/* for trains this needs to be the front engine due to the callback function */ |
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3896
diff
changeset
|
1825 |
_new_vehicle_id = w_front->index; |
2244 | 1826 |
} |
5062
7c341b020f5f
(svn r7115) -Fix [FS#371]: Cloning a vehicle that has been refitted would incur the expense as running costs, not new vehicles.
peter1138
parents:
4972
diff
changeset
|
1827 |
|
9624 | 1828 |
if (flags & DC_EXEC) { |
1829 |
/* Cloned vehicles belong to the same group */ |
|
1830 |
DoCommand(0, v_front->group_id, w_front->index, flags, CMD_ADD_VEHICLE_GROUP); |
|
1831 |
} |
|
1832 |
||
1833 |
||
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1834 |
/* Take care of refitting. */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1835 |
w = w_front; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1836 |
v = v_front; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1837 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1838 |
/* Both building and refitting are influenced by newgrf callbacks, which |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1839 |
* makes it impossible to accurately estimate the cloning costs. In |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1840 |
* particular, it is possible for engines of the same type to be built with |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1841 |
* different numbers of articulated parts, so when refitting we have to |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1842 |
* loop over real vehicles first, and then the articulated parts of those |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1843 |
* vehicles in a different loop. */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1844 |
do { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1845 |
do { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1846 |
if (flags & DC_EXEC) { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1847 |
assert(w != NULL); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1848 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1849 |
if (w->cargo_type != v->cargo_type || w->cargo_subtype != v->cargo_subtype) { |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1850 |
cost = DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8) | 1U << 16 , flags, GetCmdRefitVeh(v)); |
9629 | 1851 |
if (CmdSucceeded(cost)) total_cost.AddCost(cost); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1852 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1853 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1854 |
if (w->type == VEH_TRAIN && EngineHasArticPart(w)) { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1855 |
w = GetNextArticPart(w); |
9627 | 1856 |
} else if (w->type == VEH_ROAD && RoadVehHasArticPart(w)) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1857 |
w = w->Next(); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1858 |
} else { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1859 |
break; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1860 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1861 |
} else { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1862 |
CargoID initial_cargo = GetEngineCargoType(v->engine_type); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1863 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1864 |
if (v->cargo_type != initial_cargo && initial_cargo != CT_INVALID) { |
9629 | 1865 |
total_cost.AddCost(GetRefitCost(v->engine_type)); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1866 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1867 |
} |
9627 | 1868 |
|
1869 |
if (v->type == VEH_TRAIN && EngineHasArticPart(v)) { |
|
1870 |
v = GetNextArticPart(v); |
|
1871 |
} else if (v->type == VEH_ROAD && RoadVehHasArticPart(v)) { |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1872 |
v = v->Next(); |
9627 | 1873 |
} else { |
1874 |
break; |
|
1875 |
} |
|
1876 |
} while (v != NULL); |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1877 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1878 |
if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = GetNextVehicle(w); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1879 |
} while (v->type == VEH_TRAIN && (v = GetNextVehicle(v)) != NULL); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1880 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1881 |
if (flags & DC_EXEC) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1882 |
/* |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1883 |
* Set the orders of the vehicle. Cannot do it earlier as we need |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1884 |
* the vehicle refitted before doing this, otherwise the moved |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1885 |
* cargo types might not match (passenger vs non-passenger) |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1886 |
*/ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1887 |
DoCommand(0, (v_front->index << 16) | w_front->index, p2 & 1 ? CO_SHARE : CO_COPY, flags, CMD_CLONE_ORDER); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1888 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1889 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1890 |
/* Since we can't estimate the cost of cloning a vehicle accurately we must |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1891 |
* check whether the player has enough money manually. */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1892 |
if (!CheckPlayerHasMoney(total_cost)) { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1893 |
if (flags & DC_EXEC) { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1894 |
/* The vehicle has already been bought, so now it must be sold again. */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1895 |
DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front)); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1896 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1897 |
return CMD_ERROR; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1898 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1899 |
|
2244 | 1900 |
return total_cost; |
1901 |
} |
|
1902 |
||
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1903 |
|
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1904 |
/* Extend the list size for BuildDepotVehicleList() */ |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
1905 |
static inline void ExtendVehicleListSize(const Vehicle ***engine_list, uint16 *engine_list_length, uint16 step_size) |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1906 |
{ |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
1907 |
*engine_list_length = min(*engine_list_length + step_size, GetMaxVehicleIndex() + 1); |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
1908 |
*engine_list = ReallocT(*engine_list, *engine_list_length); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1909 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1910 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1911 |
/** Generates a list of vehicles inside a depot |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1912 |
* Will enlarge allocated space for the list if they are too small, so it's ok to call with (pointer to NULL array, pointer to uninitised uint16, pointer to 0) |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1913 |
* If one of the lists is not needed (say wagons when finding ships), all the pointers regarding that list should be set to NULL |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1914 |
* @param type Type of vehicle |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1915 |
* @param tile The tile the depot is located in |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1916 |
* @param ***engine_list Pointer to a pointer to an array of vehicles in the depot (old list is freed and a new one is malloced) |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1917 |
* @param *engine_list_length Allocated size of engine_list. Needs to be set to 0 when engine_list points to a NULL array |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1918 |
* @param *engine_count The number of engines stored in the list |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1919 |
* @param ***wagon_list Pointer to a pointer to an array of free wagons in the depot (old list is freed and a new one is malloced) |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1920 |
* @param *wagon_list_length Allocated size of wagon_list. Needs to be set to 0 when wagon_list points to a NULL array |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1921 |
* @param *wagon_count The number of engines stored in the list |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1922 |
*/ |
9624 | 1923 |
void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count) |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1924 |
{ |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1925 |
Vehicle *v; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1926 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1927 |
/* This function should never be called without an array to store results */ |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1928 |
assert(!(engine_list == NULL && type != VEH_TRAIN)); |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1929 |
assert(!(type == VEH_TRAIN && engine_list == NULL && wagon_list == NULL)); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1930 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1931 |
/* Both array and the length should either be NULL to disable the list or both should not be NULL */ |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1932 |
assert((engine_list == NULL && engine_list_length == NULL) || (engine_list != NULL && engine_list_length != NULL)); |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1933 |
assert((wagon_list == NULL && wagon_list_length == NULL) || (wagon_list != NULL && wagon_list_length != NULL)); |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1934 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1935 |
assert(!(engine_list != NULL && engine_count == NULL)); |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1936 |
assert(!(wagon_list != NULL && wagon_count == NULL)); |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1937 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1938 |
if (engine_count != NULL) *engine_count = 0; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1939 |
if (wagon_count != NULL) *wagon_count = 0; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1940 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1941 |
switch (type) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1942 |
case VEH_TRAIN: |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1943 |
FOR_ALL_VEHICLES(v) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1944 |
if (v->tile == tile && v->type == VEH_TRAIN && v->u.rail.track == TRACK_BIT_DEPOT) { |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1945 |
if (IsFrontEngine(v)) { |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1946 |
if (engine_list == NULL) continue; |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
1947 |
if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1948 |
(*engine_list)[(*engine_count)++] = v; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1949 |
} else if (IsFreeWagon(v)) { |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1950 |
if (wagon_list == NULL) continue; |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
1951 |
if (*wagon_count == *wagon_list_length) ExtendVehicleListSize((const Vehicle***)wagon_list, wagon_list_length, 25); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1952 |
(*wagon_list)[(*wagon_count)++] = v; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1953 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1954 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1955 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1956 |
break; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1957 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1958 |
case VEH_ROAD: |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1959 |
FOR_ALL_VEHICLES(v) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1960 |
if (v->tile == tile && v->type == VEH_ROAD && v->IsInDepot() && IsRoadVehFront(v)) { |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
1961 |
if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1962 |
(*engine_list)[(*engine_count)++] = v; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1963 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1964 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1965 |
break; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1966 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1967 |
case VEH_SHIP: |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1968 |
FOR_ALL_VEHICLES(v) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1969 |
if (v->tile == tile && v->type == VEH_SHIP && v->IsInDepot()) { |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
1970 |
if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1971 |
(*engine_list)[(*engine_count)++] = v; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1972 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1973 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1974 |
break; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1975 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1976 |
case VEH_AIRCRAFT: |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1977 |
FOR_ALL_VEHICLES(v) { |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1978 |
if (v->tile == tile && |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1979 |
v->type == VEH_AIRCRAFT && IsNormalAircraft(v) && |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1980 |
v->IsInDepot()) { |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
1981 |
if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1982 |
(*engine_list)[(*engine_count)++] = v; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1983 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1984 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1985 |
break; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1986 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1987 |
default: NOT_REACHED(); |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1988 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1989 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
1990 |
|
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
1991 |
/** |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
1992 |
* @param sort_list list to store the list in. Either NULL or the length length_of_array tells |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
1993 |
* @param length_of_array informs the length allocated for sort_list. This is not the same as the number of vehicles in the list. Needs to be 0 when sort_list is NULL |
4554
ff008b423676
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1994 |
* @param type type of vehicle |
ff008b423676
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1995 |
* @param owner PlayerID of owner to generate a list for |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1996 |
* @param index This parameter has different meanings depending on window_type |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1997 |
<ul> |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1998 |
<li>VLW_STATION_LIST: index of station to generate a list for</li> |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1999 |
<li>VLW_SHARED_ORDERS: index of order to generate a list for<li> |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2000 |
<li>VLW_STANDARD: not used<li> |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2001 |
<li>VLW_DEPOT_LIST: TileIndex of the depot/hangar to make the list for</li> |
9624 | 2002 |
<li>VLW_GROUP_LIST: index of group to generate a list for</li> |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2003 |
</ul> |
4554
ff008b423676
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2004 |
* @param window_type tells what kind of window the list is for. Use the VLW flags in vehicle_gui.h |
ff008b423676
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2005 |
* @return the number of vehicles added to the list |
ff008b423676
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2006 |
*/ |
9624 | 2007 |
uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type) |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2008 |
{ |
4499
c57155fea7a5
(svn r6284) -Code Cleanup r6282: cleaned up the code a bit
bjarni
parents:
4497
diff
changeset
|
2009 |
uint n = 0; |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2010 |
const Vehicle *v; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2011 |
|
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2012 |
switch (window_type) { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2013 |
case VLW_STATION_LIST: { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2014 |
FOR_ALL_VEHICLES(v) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2015 |
if (v->type == type && v->IsPrimaryVehicle()) { |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2016 |
const Order *order; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2017 |
|
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2018 |
FOR_VEHICLE_ORDERS(v, order) { |
5998
9491f99be62d
(svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument
bjarni
parents:
5997
diff
changeset
|
2019 |
if (order->type == OT_GOTO_STATION && order->dest == index) { |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2020 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 50); |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2021 |
(*sort_list)[n++] = v; |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2022 |
break; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2023 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2024 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2025 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2026 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2027 |
break; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2028 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2029 |
|
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2030 |
case VLW_SHARED_ORDERS: { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2031 |
FOR_ALL_VEHICLES(v) { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2032 |
/* Find a vehicle with the order in question */ |
5998
9491f99be62d
(svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument
bjarni
parents:
5997
diff
changeset
|
2033 |
if (v->orders != NULL && v->orders->index == index) break; |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2034 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2035 |
|
5998
9491f99be62d
(svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument
bjarni
parents:
5997
diff
changeset
|
2036 |
if (v != NULL && v->orders != NULL && v->orders->index == index) { |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2037 |
/* Only try to make the list if we found a vehicle using the order in question */ |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2038 |
for (v = GetFirstVehicleFromSharedList(v); v != NULL; v = v->next_shared) { |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2039 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25); |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2040 |
(*sort_list)[n++] = v; |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2041 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2042 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2043 |
break; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2044 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2045 |
|
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2046 |
case VLW_STANDARD: { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2047 |
FOR_ALL_VEHICLES(v) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2048 |
if (v->type == type && v->owner == owner && v->IsPrimaryVehicle()) { |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2049 |
/* TODO find a better estimate on the total number of vehicles for current player */ |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
2050 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles()/4); |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2051 |
(*sort_list)[n++] = v; |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2052 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2053 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2054 |
break; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2055 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2056 |
|
4681
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2057 |
case VLW_DEPOT_LIST: { |
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2058 |
FOR_ALL_VEHICLES(v) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2059 |
if (v->type == type && v->IsPrimaryVehicle()) { |
4681
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2060 |
const Order *order; |
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2061 |
|
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2062 |
FOR_VEHICLE_ORDERS(v, order) { |
5998
9491f99be62d
(svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument
bjarni
parents:
5997
diff
changeset
|
2063 |
if (order->type == OT_GOTO_DEPOT && order->dest == index) { |
4681
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2064 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25); |
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2065 |
(*sort_list)[n++] = v; |
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2066 |
break; |
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2067 |
} |
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2068 |
} |
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2069 |
} |
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2070 |
} |
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2071 |
break; |
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2072 |
} |
7d7a89b32dd0
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2073 |
|
9624 | 2074 |
case VLW_GROUP_LIST: |
2075 |
FOR_ALL_VEHICLES(v) { |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2076 |
if (v->type == type && v->IsPrimaryVehicle() && |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2077 |
v->owner == owner && v->group_id == index) { |
9624 | 2078 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles() / 4); |
2079 |
||
2080 |
(*sort_list)[n++] = v; |
|
2081 |
} |
|
2082 |
} |
|
2083 |
break; |
|
2084 |
||
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2085 |
default: NOT_REACHED(); break; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2086 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2087 |
|
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2088 |
if ((n + 100) < *length_of_array) { |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2089 |
/* We allocated way too much for sort_list. |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2090 |
* Now we will reduce how much we allocated. |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2091 |
* We will still make it have room for 50 extra vehicles to prevent having |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2092 |
* to move the whole array if just one vehicle is added later */ |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2093 |
*length_of_array = n + 50; |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
2094 |
*sort_list = ReallocT(*sort_list, (*length_of_array) * sizeof((*sort_list)[0])); |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2095 |
} |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2096 |
|
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2097 |
return n; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2098 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2099 |
|
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2100 |
/** send all vehicles of type to depots |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2101 |
* @param type type of vehicle |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2102 |
* @param flags the flags used for DoCommand() |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2103 |
* @param service should the vehicles only get service in the depots |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2104 |
* @param owner PlayerID of owner of the vehicles to send |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2105 |
* @param vlw_flag tells what kind of list requested the goto depot |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2106 |
* @return 0 for success and CMD_ERROR if no vehicle is able to go to depot |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2107 |
*/ |
9629 | 2108 |
CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id) |
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2109 |
{ |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2110 |
const Vehicle **sort_list = NULL; |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2111 |
uint n, i; |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2112 |
uint16 array_length = 0; |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2113 |
|
5998
9491f99be62d
(svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument
bjarni
parents:
5997
diff
changeset
|
2114 |
n = GenerateVehicleSortList(&sort_list, &array_length, type, owner, id, vlw_flag); |
4465
852cf43b354f
(svn r6249) -Fix: fixed assert when pressing goto depot in an empty list (forgot to disable the button in this condition)
bjarni
parents:
4463
diff
changeset
|
2115 |
|
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2116 |
/* Send all the vehicles to a depot */ |
4499
c57155fea7a5
(svn r6284) -Code Cleanup r6282: cleaned up the code a bit
bjarni
parents:
4497
diff
changeset
|
2117 |
for (i = 0; i < n; i++) { |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2118 |
const Vehicle *v = sort_list[i]; |
9629 | 2119 |
CommandCost ret = DoCommand(v->tile, v->index, (service ? 1 : 0) | DEPOT_DONT_CANCEL, flags, GetCmdSendToDepot(type)); |
4560
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2120 |
|
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2121 |
/* Return 0 if DC_EXEC is not set this is a valid goto depot command) |
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2122 |
* In this case we know that at least one vehicle can be sent to a depot |
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2123 |
* and we will issue the command. We can now safely quit the loop, knowing |
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2124 |
* it will succeed at least once. With DC_EXEC we really need to send them to the depot */ |
9629 | 2125 |
if (CmdSucceeded(ret) && !(flags & DC_EXEC)) { |
4683
13d7b7d779cf
(svn r6588) -Fix r6582: killed some windows only warnings (thanks webfreakz for testing)
bjarni
parents:
4681
diff
changeset
|
2126 |
free((void*)sort_list); |
9629 | 2127 |
return CommandCost(); |
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2128 |
} |
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2129 |
} |
4465
852cf43b354f
(svn r6249) -Fix: fixed assert when pressing goto depot in an empty list (forgot to disable the button in this condition)
bjarni
parents:
4463
diff
changeset
|
2130 |
|
4683
13d7b7d779cf
(svn r6588) -Fix r6582: killed some windows only warnings (thanks webfreakz for testing)
bjarni
parents:
4681
diff
changeset
|
2131 |
free((void*)sort_list); |
9629 | 2132 |
return (flags & DC_EXEC) ? CommandCost() : CMD_ERROR; |
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2133 |
} |
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2134 |
|
9629 | 2135 |
/** |
2136 |
* Calculates how full a vehicle is. |
|
2137 |
* @param v The Vehicle to check. For trains, use the first engine. |
|
2138 |
* @param color The string to show depending on if we are unloading or loading |
|
2139 |
* @return A percentage of how full the Vehicle is. |
|
2140 |
*/ |
|
2141 |
uint8 CalcPercentVehicleFilled(Vehicle *v, StringID *color) |
|
2142 |
{ |
|
2143 |
int count = 0; |
|
2144 |
int max = 0; |
|
2145 |
int cars = 0; |
|
2146 |
int unloading = 0; |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2147 |
bool loading = false; |
9629 | 2148 |
|
2149 |
assert(color != NULL); |
|
2150 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2151 |
const Vehicle *u = v; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2152 |
const Station *st = GetStation(v->last_station_visited); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2153 |
|
9629 | 2154 |
/* Count up max and used */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2155 |
for (; v != NULL; v = v->Next()) { |
9629 | 2156 |
count += v->cargo.Count(); |
2157 |
max += v->cargo_cap; |
|
2158 |
if (v->cargo_cap != 0) { |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2159 |
unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2160 |
loading |= (u->current_order.flags & OFB_UNLOAD) == 0 && st->goods[v->cargo_type].days_since_pickup != 255; |
9629 | 2161 |
cars++; |
2162 |
} |
|
2163 |
} |
|
2164 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2165 |
if (unloading == 0 && loading) *color = STR_PERCENT_UP; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2166 |
else if (cars == unloading || !loading) *color = STR_PERCENT_DOWN; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2167 |
else *color = STR_PERCENT_UP_DOWN; |
9629 | 2168 |
|
2169 |
/* Train without capacity */ |
|
2170 |
if (max == 0) return 100; |
|
2171 |
||
2172 |
/* Return the percentage */ |
|
2173 |
return (count * 100) / max; |
|
2174 |
} |
|
2175 |
||
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2176 |
void VehicleEnterDepot(Vehicle *v) |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2177 |
{ |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2178 |
switch (v->type) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2179 |
case VEH_TRAIN: |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2180 |
InvalidateWindowClasses(WC_TRAINS_LIST); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2181 |
if (!IsFrontEngine(v)) v = v->First(); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2182 |
UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner); |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2183 |
v->load_unload_time_rem = 0; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2184 |
break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2185 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2186 |
case VEH_ROAD: |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2187 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2188 |
if (!IsRoadVehFront(v)) v = v->First(); |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2189 |
break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2190 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2191 |
case VEH_SHIP: |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2192 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
6319
27e68b914d3d
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium
parents:
6317
diff
changeset
|
2193 |
v->u.ship.state = TRACK_BIT_DEPOT; |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2194 |
RecalcShipStuff(v); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2195 |
break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2196 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2197 |
case VEH_AIRCRAFT: |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2198 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2199 |
HandleAircraftEnterHangar(v); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2200 |
break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2201 |
default: NOT_REACHED(); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2202 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2203 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2204 |
if (v->type != VEH_TRAIN) { |
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2205 |
/* Trains update the vehicle list when the first unit enters the depot and calls VehicleEnterDepot() when the last unit enters. |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2206 |
* We only increase the number of vehicles when the first one enters, so we will not need to search for more vehicles in the depot */ |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2207 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2208 |
} |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2209 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2210 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2211 |
v->vehstatus |= VS_HIDDEN; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2212 |
v->cur_speed = 0; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2213 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2214 |
VehicleServiceInDepot(v); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2215 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2216 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2217 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2218 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2219 |
Order t; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2220 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2221 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2222 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2223 |
t = v->current_order; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2224 |
v->current_order.type = OT_DUMMY; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2225 |
v->current_order.flags = 0; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2226 |
|
4782
3ee91034a50e
(svn r6696) -Codechange: changed all comparision for refit cargo in orders against CT_NO_REFIT to checks for valid cargo IDs
bjarni
parents:
4762
diff
changeset
|
2227 |
if (t.refit_cargo < NUM_CARGO) { |
9629 | 2228 |
CommandCost cost; |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2229 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2230 |
_current_player = v->owner; |
6043
99c8fb13658b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
6014
diff
changeset
|
2231 |
cost = DoCommand(v->tile, v->index, t.refit_cargo | t.refit_subtype << 8, DC_EXEC, GetCmdRefitVeh(v)); |
4783
77a455254ab0
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2232 |
|
77a455254ab0
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2233 |
if (CmdFailed(cost)) { |
77a455254ab0
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2234 |
v->leave_depot_instantly = false; // We ensure that the vehicle stays in the depot |
77a455254ab0
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2235 |
if (v->owner == _local_player) { |
77a455254ab0
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2236 |
/* Notify the user that we stopped the vehicle */ |
6206
67358999d80d
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
6195
diff
changeset
|
2237 |
SetDParam(0, _vehicle_type_names[v->type]); |
4783
77a455254ab0
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2238 |
SetDParam(1, v->unitnumber); |
77a455254ab0
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2239 |
AddNewsItem(STR_ORDER_REFIT_FAILED, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
77a455254ab0
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2240 |
} |
9629 | 2241 |
} else if (v->owner == _local_player && cost.GetCost() != 0) { |
2242 |
ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost.GetCost()); |
|
4783
77a455254ab0
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2243 |
} |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2244 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2245 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2246 |
if (HasBit(t.flags, OF_PART_OF_ORDERS)) { |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2247 |
/* Part of orders */ |
9629 | 2248 |
UpdateVehicleTimetable(v, true); |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2249 |
v->cur_order_index++; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2250 |
} else if (HasBit(t.flags, OF_HALT_IN_DEPOT)) { |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2251 |
/* Force depot visit */ |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2252 |
v->vehstatus |= VS_STOPPED; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2253 |
if (v->owner == _local_player) { |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2254 |
StringID string; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2255 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2256 |
switch (v->type) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2257 |
case VEH_TRAIN: string = STR_8814_TRAIN_IS_WAITING_IN_DEPOT; break; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2258 |
case VEH_ROAD: string = STR_9016_ROAD_VEHICLE_IS_WAITING; break; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2259 |
case VEH_SHIP: string = STR_981C_SHIP_IS_WAITING_IN_DEPOT; break; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2260 |
case VEH_AIRCRAFT: string = STR_A014_AIRCRAFT_IS_WAITING_IN; break; |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2261 |
default: NOT_REACHED(); string = STR_EMPTY; // Set the string to something to avoid a compiler warning |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2262 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2263 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2264 |
SetDParam(0, v->unitnumber); |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2265 |
AddNewsItem(string, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2266 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2267 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2268 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2269 |
} |
2244 | 2270 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2271 |
static bool IsUniqueVehicleName(const char *name) |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2272 |
{ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2273 |
const Vehicle *v; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2274 |
char buf[512]; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2275 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2276 |
FOR_ALL_VEHICLES(v) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2277 |
switch (v->type) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2278 |
case VEH_TRAIN: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2279 |
if (!IsTrainEngine(v)) continue; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2280 |
break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2281 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2282 |
case VEH_ROAD: |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2283 |
if (!IsRoadVehFront(v)) continue; |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2284 |
break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2285 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2286 |
case VEH_AIRCRAFT: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2287 |
if (!IsNormalAircraft(v)) continue; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2288 |
break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2289 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2290 |
case VEH_SHIP: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2291 |
break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2292 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2293 |
default: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2294 |
continue; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2295 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2296 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2297 |
SetDParam(0, v->index); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2298 |
GetString(buf, STR_VEHICLE_NAME, lastof(buf)); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2299 |
if (strcmp(buf, name) == 0) return false; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2300 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2301 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2302 |
return true; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2303 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2304 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
2305 |
/** Give a custom name to your vehicle |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
2306 |
* @param tile unused |
9574 | 2307 |
* @param flags type of operation |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
2308 |
* @param p1 vehicle ID to name |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
2309 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
2310 |
*/ |
9629 | 2311 |
CommandCost CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 2312 |
{ |
2313 |
Vehicle *v; |
|
2314 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2315 |
if (!IsValidVehicleID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; |
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
|
2316 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2317 |
v = GetVehicle(p1); |
0 | 2318 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
2319 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 2320 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2321 |
if (!IsUniqueVehicleName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2322 |
|
0 | 2323 |
if (flags & DC_EXEC) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2324 |
free(v->name); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2325 |
v->name = strdup(_cmd_text); |
588 | 2326 |
ResortVehicleLists(); |
0 | 2327 |
MarkWholeScreenDirty(); |
2328 |
} |
|
2329 |
||
9629 | 2330 |
return CommandCost(); |
0 | 2331 |
} |
2332 |
||
2333 |
||
2819
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2334 |
/** Change the service interval of a vehicle |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
2335 |
* @param tile unused |
9574 | 2336 |
* @param flags type of operation |
2819
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2337 |
* @param p1 vehicle ID that is being service-interval-changed |
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2338 |
* @param p2 new service interval |
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2339 |
*/ |
9629 | 2340 |
CommandCost CmdChangeServiceInt(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2819
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2341 |
{ |
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2342 |
Vehicle* v; |
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2343 |
uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */ |
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2344 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
2345 |
if (serv_int != p2 || !IsValidVehicleID(p1)) return CMD_ERROR; |
2819
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2346 |
|
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2347 |
v = GetVehicle(p1); |
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2348 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
2349 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
2819
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2350 |
|
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2351 |
if (flags & DC_EXEC) { |
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2352 |
v->service_interval = serv_int; |
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2353 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2354 |
} |
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2355 |
|
9629 | 2356 |
return CommandCost(); |
2819
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2357 |
} |
710436dd4288
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
2358 |
|
0 | 2359 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2360 |
static Rect _old_vehicle_coords; ///< coords of vehicle before it has moved |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2361 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2362 |
/** |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2363 |
* Stores the vehicle image coords for later call to EndVehicleMove() |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2364 |
* @param v vehicle which image's coords to store |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2365 |
* @see _old_vehicle_coords |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2366 |
* @see EndVehicleMove() |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2367 |
*/ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2368 |
void BeginVehicleMove(const Vehicle *v) |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2369 |
{ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2370 |
_old_vehicle_coords.left = v->left_coord; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2371 |
_old_vehicle_coords.top = v->top_coord; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2372 |
_old_vehicle_coords.right = v->right_coord; |
0 | 2373 |
_old_vehicle_coords.bottom = v->bottom_coord; |
2374 |
} |
|
2375 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2376 |
/** |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2377 |
* Marks screen dirty after a vehicle has moved |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2378 |
* @param v vehicle which is marked dirty |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2379 |
* @see _old_vehicle_coords |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2380 |
* @see BeginVehicleMove() |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2381 |
*/ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2382 |
void EndVehicleMove(const Vehicle *v) |
0 | 2383 |
{ |
2384 |
MarkAllViewportsDirty( |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2385 |
min(_old_vehicle_coords.left, v->left_coord), |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2386 |
min(_old_vehicle_coords.top, v->top_coord), |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2387 |
max(_old_vehicle_coords.right, v->right_coord) + 1, |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2388 |
max(_old_vehicle_coords.bottom, v->bottom_coord) + 1 |
0 | 2389 |
); |
2390 |
} |
|
2391 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2392 |
/** |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2393 |
* Marks viewports dirty where the vehicle's image is |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2394 |
* In fact, it equals |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2395 |
* BeginVehicleMove(v); EndVehicleMove(v); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2396 |
* @param v vehicle to mark dirty |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2397 |
* @see BeginVehicleMove() |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2398 |
* @see EndVehicleMove() |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2399 |
*/ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2400 |
void MarkSingleVehicleDirty(const Vehicle *v) |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2401 |
{ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2402 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2403 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2404 |
|
0 | 2405 |
/* returns true if staying in the same tile */ |
6479 | 2406 |
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v) |
0 | 2407 |
{ |
2408 |
static const int8 _delta_coord[16] = { |
|
2409 |
-1,-1,-1, 0, 1, 1, 1, 0, /* x */ |
|
2410 |
-1, 0, 1, 1, 1, 0,-1,-1, /* y */ |
|
2411 |
}; |
|
2412 |
||
2413 |
int x = v->x_pos + _delta_coord[v->direction]; |
|
2414 |
int y = v->y_pos + _delta_coord[v->direction + 8]; |
|
2415 |
||
6479 | 2416 |
GetNewVehiclePosResult gp; |
2417 |
gp.x = x; |
|
2418 |
gp.y = y; |
|
2419 |
gp.old_tile = v->tile; |
|
2420 |
gp.new_tile = TileVirtXY(x, y); |
|
2421 |
return gp; |
|
0 | 2422 |
} |
2423 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2424 |
static const Direction _new_direction_table[] = { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2425 |
DIR_N , DIR_NW, DIR_W , |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2426 |
DIR_NE, DIR_SE, DIR_SW, |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2427 |
DIR_E , DIR_SE, DIR_S |
0 | 2428 |
}; |
2429 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2430 |
Direction GetDirectionTowards(const Vehicle* v, int x, int y) |
0 | 2431 |
{ |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2432 |
Direction dir; |
3158
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
2433 |
DirDiff dirdiff; |
0 | 2434 |
int i = 0; |
2435 |
||
2436 |
if (y >= v->y_pos) { |
|
2437 |
if (y != v->y_pos) i+=3; |
|
2438 |
i+=3; |
|
2439 |
} |
|
2440 |
||
2441 |
if (x >= v->x_pos) { |
|
2442 |
if (x != v->x_pos) i++; |
|
2443 |
i++; |
|
2444 |
} |
|
2445 |
||
2446 |
dir = v->direction; |
|
2447 |
||
3158
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
2448 |
dirdiff = DirDifference(_new_direction_table[i], dir); |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
2449 |
if (dirdiff == DIRDIFF_SAME) return dir; |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
2450 |
return ChangeDir(dir, dirdiff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
0 | 2451 |
} |
2452 |
||
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
2453 |
Trackdir GetVehicleTrackdir(const Vehicle* v) |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2454 |
{ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2455 |
if (v->vehstatus & VS_CRASHED) return INVALID_TRACKDIR; |
1758
68668114f92e
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
2456 |
|
2952 | 2457 |
switch (v->type) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2458 |
case VEH_TRAIN: |
9574 | 2459 |
if (v->u.rail.track == TRACK_BIT_DEPOT) // We'll assume the train is facing outwards |
2460 |
return DiagdirToDiagTrackdir(GetRailDepotDirection(v->tile)); // Train in depot |
|
2461 |
||
2462 |
if (v->u.rail.track == TRACK_BIT_WORMHOLE) // train in tunnel, so just use his direction and assume a diagonal track |
|
3161 | 2463 |
return DiagdirToDiagTrackdir(DirToDiagDir(v->direction)); |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2464 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2465 |
return TrackDirectionToTrackdir(FindFirstTrack(v->u.rail.track), v->direction); |
1959 | 2466 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2467 |
case VEH_SHIP: |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2468 |
if (v->IsInDepot()) |
9574 | 2469 |
// We'll assume the ship is facing outwards |
3953
db302c2d1a2a
(svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents:
3948
diff
changeset
|
2470 |
return DiagdirToDiagTrackdir(GetShipDepotDirection(v->tile)); |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2471 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2472 |
return TrackDirectionToTrackdir(FindFirstTrack(v->u.ship.state), v->direction); |
1959 | 2473 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2474 |
case VEH_ROAD: |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2475 |
if (v->IsInDepot()) // We'll assume the road vehicle is facing outwards |
3179 | 2476 |
return DiagdirToDiagTrackdir(GetRoadDepotDirection(v->tile)); |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2477 |
|
9574 | 2478 |
if (IsStandardRoadStopTile(v->tile)) // We'll assume the road vehicle is facing outwards |
2479 |
return DiagdirToDiagTrackdir(GetRoadStopDir(v->tile)); // Road vehicle in a station |
|
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2480 |
|
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
2481 |
if (IsDriveThroughStopTile(v->tile)) return DiagdirToDiagTrackdir(DirToDiagDir(v->direction)); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
2482 |
|
4270
cfb529779a26
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
2483 |
/* If vehicle's state is a valid track direction (vehicle is not turning around) return it */ |
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6326
diff
changeset
|
2484 |
if (!IsReversingRoadTrackdir((Trackdir)v->u.road.state)) return (Trackdir)v->u.road.state; |
4270
cfb529779a26
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
2485 |
|
cfb529779a26
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
2486 |
/* Vehicle is turning around, get the direction from vehicle's direction */ |
3161 | 2487 |
return DiagdirToDiagTrackdir(DirToDiagDir(v->direction)); |
1959 | 2488 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2489 |
/* case VEH_AIRCRAFT: case VEH_SPECIAL: case VEH_DISASTER: */ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2490 |
default: return INVALID_TRACKDIR; |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2491 |
} |
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2492 |
} |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6206
diff
changeset
|
2493 |
|
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6206
diff
changeset
|
2494 |
/** |
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6206
diff
changeset
|
2495 |
* Returns some meta-data over the to be entered tile. |
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6206
diff
changeset
|
2496 |
* @see VehicleEnterTileStatus to see what the bits in the return value mean. |
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6206
diff
changeset
|
2497 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
2498 |
uint32 VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2499 |
{ |
3657 | 2500 |
return _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y); |
0 | 2501 |
} |
2502 |
||
9624 | 2503 |
UnitID GetFreeUnitNumber(VehicleType type) |
0 | 2504 |
{ |
3018
79f51529a689
(svn r3598) -Fix: suppress invalid warning by assigning value to variable
truelight
parents:
3009
diff
changeset
|
2505 |
UnitID unit, max = 0; |
2995
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2506 |
const Vehicle *u; |
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2507 |
static bool *cache = NULL; |
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2508 |
static UnitID gmax = 0; |
0 | 2509 |
|
2995
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2510 |
switch (type) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2511 |
case VEH_TRAIN: max = _patches.max_trains; break; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2512 |
case VEH_ROAD: max = _patches.max_roadveh; break; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2513 |
case VEH_SHIP: max = _patches.max_ships; break; |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2514 |
case VEH_AIRCRAFT: max = _patches.max_aircraft; break; |
2996
8087faf157d8
(svn r3573) - Replace assert(0) with NOT_REACHED(). This commit sponsored by "giving Darkvater credit for the last three".
peter1138
parents:
2995
diff
changeset
|
2515 |
default: NOT_REACHED(); |
2995
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2516 |
} |
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2517 |
|
4096
c7259875a856
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2518 |
if (max == 0) { |
c7259875a856
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2519 |
/* we can't build any of this kind of vehicle, so we just return 1 instead of looking for a free number |
c7259875a856
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2520 |
* a max of 0 will cause the following code to write to a NULL pointer |
c7259875a856
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2521 |
* We know that 1 is bigger than the max allowed vehicle number, so it's the same as returning something, that is too big |
c7259875a856
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2522 |
*/ |
c7259875a856
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2523 |
return 1; |
c7259875a856
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2524 |
} |
c7259875a856
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2525 |
|
2995
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2526 |
if (max > gmax) { |
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2527 |
gmax = max; |
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2528 |
free(cache); |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
2529 |
cache = MallocT<bool>(max + 1); |
2995
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2530 |
} |
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2531 |
|
9574 | 2532 |
/* Clear the cache */ |
2995
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2533 |
memset(cache, 0, (max + 1) * sizeof(*cache)); |
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2534 |
|
9574 | 2535 |
/* Fill the cache */ |
0 | 2536 |
FOR_ALL_VEHICLES(u) { |
2995
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2537 |
if (u->type == type && u->owner == _current_player && u->unitnumber != 0 && u->unitnumber <= max) |
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2538 |
cache[u->unitnumber] = true; |
0 | 2539 |
} |
2995
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2540 |
|
9574 | 2541 |
/* Find the first unused unit number */ |
2995
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2542 |
for (unit = 1; unit <= max; unit++) { |
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2543 |
if (!cache[unit]) break; |
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2544 |
} |
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2545 |
|
4e16e4fc54ac
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2546 |
return unit; |
0 | 2547 |
} |
2548 |
||
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2549 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2550 |
/** |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2551 |
* Check whether we can build infrastructure for the given |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2552 |
* vehicle type. This to disable building stations etc. when |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2553 |
* you are not allowed/able to have the vehicle type yet. |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2554 |
* @param type the vehicle type to check this for |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2555 |
* @return true if there is any reason why you may build |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2556 |
* the infrastructure for the given vehicle type |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2557 |
*/ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2558 |
bool CanBuildVehicleInfrastructure(VehicleType type) |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2559 |
{ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2560 |
assert(IsPlayerBuildableVehicleType(type)); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2561 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2562 |
if (!IsValidPlayer(_current_player)) return false; |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2563 |
if (_patches.always_build_infrastructure) return true; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2564 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2565 |
UnitID max; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2566 |
switch (type) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2567 |
case VEH_TRAIN: max = _patches.max_trains; break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2568 |
case VEH_ROAD: max = _patches.max_roadveh; break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2569 |
case VEH_SHIP: max = _patches.max_ships; break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2570 |
case VEH_AIRCRAFT: max = _patches.max_aircraft; break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2571 |
default: NOT_REACHED(); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2572 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2573 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2574 |
/* We can build vehicle infrastructure when we may build the vehicle type */ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2575 |
if (max > 0) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2576 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2577 |
/* Can we actually build the vehicle type? */ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2578 |
EngineID e; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2579 |
FOR_ALL_ENGINEIDS_OF_TYPE(e, type) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2580 |
if (HasBit(GetEngine(e)->player_avail, _local_player)) return true; |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2581 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2582 |
return false; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2583 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2584 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2585 |
/* We should be able to build infrastructure when we have the actual vehicle type */ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2586 |
const Vehicle *v; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2587 |
FOR_ALL_VEHICLES(v) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2588 |
if (v->owner == _local_player && v->type == type) return true; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2589 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2590 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2591 |
return false; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2592 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2593 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2594 |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2595 |
const Livery *GetEngineLivery(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v) |
3040
c3473d1fb81f
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
2596 |
{ |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2597 |
const Player *p = GetPlayer(player); |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2598 |
LiveryScheme scheme = LS_DEFAULT; |
5968
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
2599 |
CargoID cargo_type = v == NULL ? (CargoID)CT_INVALID : v->cargo_type; |
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
2600 |
|
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2601 |
/* The default livery is always available for use, but its in_use flag determines |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2602 |
* whether any _other_ liveries are in use. */ |
4616
baa9d4436b9e
(svn r6474) - Add a patch option to control display of liveries, allowing none, your
peter1138
parents:
4613
diff
changeset
|
2603 |
if (p->livery[LS_DEFAULT].in_use && (_patches.liveries == 2 || (_patches.liveries == 1 && player == _local_player))) { |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2604 |
/* Determine the livery scheme to use */ |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2605 |
switch (GetEngine(engine_type)->type) { |
9624 | 2606 |
default: NOT_REACHED(); |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2607 |
case VEH_TRAIN: { |
6014 | 2608 |
const RailVehicleInfo *rvi = RailVehInfo(engine_type); |
2609 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2610 |
if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2611 |
if (rvi->railveh_type == RAILVEH_WAGON) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2612 |
if (!GetCargo(cargo_type)->is_freight) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2613 |
if (parent_engine_type == INVALID_ENGINE) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2614 |
scheme = LS_PASSENGER_WAGON_STEAM; |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2615 |
} else { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2616 |
switch (RailVehInfo(parent_engine_type)->engclass) { |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2617 |
default: NOT_REACHED(); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2618 |
case EC_STEAM: scheme = LS_PASSENGER_WAGON_STEAM; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2619 |
case EC_DIESEL: scheme = LS_PASSENGER_WAGON_DIESEL; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2620 |
case EC_ELECTRIC: scheme = LS_PASSENGER_WAGON_ELECTRIC; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2621 |
case EC_MONORAIL: scheme = LS_PASSENGER_WAGON_MONORAIL; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2622 |
case EC_MAGLEV: scheme = LS_PASSENGER_WAGON_MAGLEV; break; |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2623 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2624 |
} |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2625 |
} else { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2626 |
scheme = LS_FREIGHT_WAGON; |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2627 |
} |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2628 |
} else { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2629 |
bool is_mu = HasBit(EngInfo(engine_type)->misc_flags, EF_RAIL_IS_MU); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2630 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2631 |
switch (rvi->engclass) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2632 |
default: NOT_REACHED(); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2633 |
case EC_STEAM: scheme = LS_STEAM; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2634 |
case EC_DIESEL: scheme = is_mu ? LS_DMU : LS_DIESEL; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2635 |
case EC_ELECTRIC: scheme = is_mu ? LS_EMU : LS_ELECTRIC; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2636 |
case EC_MONORAIL: scheme = LS_MONORAIL; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2637 |
case EC_MAGLEV: scheme = LS_MAGLEV; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2638 |
} |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2639 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2640 |
break; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2641 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2642 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2643 |
case VEH_ROAD: { |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2644 |
const RoadVehicleInfo *rvi = RoadVehInfo(engine_type); |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2645 |
if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2646 |
if (HasBit(EngInfo(engine_type)->misc_flags, EF_ROAD_TRAM)) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2647 |
/* Tram */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2648 |
scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2649 |
} else { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2650 |
/* Bus or truck */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2651 |
scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_BUS : LS_TRUCK; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2652 |
} |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2653 |
break; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2654 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2655 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2656 |
case VEH_SHIP: { |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2657 |
const ShipVehicleInfo *svi = ShipVehInfo(engine_type); |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2658 |
if (cargo_type == CT_INVALID) cargo_type = svi->cargo_type; |
9476 | 2659 |
scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_SHIP : LS_FREIGHT_SHIP; |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2660 |
break; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2661 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2662 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2663 |
case VEH_AIRCRAFT: { |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2664 |
const AircraftVehicleInfo *avi = AircraftVehInfo(engine_type); |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2665 |
if (cargo_type == CT_INVALID) cargo_type = CT_PASSENGERS; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2666 |
switch (avi->subtype) { |
6106
0c9b10a8fedf
(svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater
parents:
6105
diff
changeset
|
2667 |
case AIR_HELI: scheme = LS_HELICOPTER; break; |
0c9b10a8fedf
(svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater
parents:
6105
diff
changeset
|
2668 |
case AIR_CTOL: scheme = LS_SMALL_PLANE; break; |
0c9b10a8fedf
(svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater
parents:
6105
diff
changeset
|
2669 |
case AIR_CTOL | AIR_FAST: scheme = LS_LARGE_PLANE; break; |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2670 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2671 |
break; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2672 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2673 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2674 |
|
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2675 |
/* Switch back to the default scheme if the resolved scheme is not in use */ |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2676 |
if (!p->livery[scheme].in_use) scheme = LS_DEFAULT; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2677 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2678 |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2679 |
return &p->livery[scheme]; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2680 |
} |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2681 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2682 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2683 |
static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v) |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2684 |
{ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2685 |
SpriteID map = (v != NULL) ? v->colormap : PAL_NONE; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2686 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2687 |
/* Return cached value if any */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2688 |
if (map != PAL_NONE) return map; |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2689 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2690 |
/* Check if we should use the colour map callback */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2691 |
if (HasBit(EngInfo(engine_type)->callbackmask, CBM_VEHICLE_COLOUR_REMAP)) { |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2692 |
uint16 callback = GetVehicleCallback(CBID_VEHICLE_COLOUR_MAPPING, 0, 0, engine_type, v); |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2693 |
/* A return value of 0xC000 is stated to "use the default two-color |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2694 |
* maps" which happens to be the failure action too... */ |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2695 |
if (callback != CALLBACK_FAILED && callback != 0xC000) { |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2696 |
map = GB(callback, 0, 14); |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2697 |
/* If bit 14 is set, then the company colours are applied to the |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2698 |
* map else it's returned as-is. */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2699 |
if (!HasBit(callback, 14)) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2700 |
/* Update cache */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2701 |
if (v != NULL) ((Vehicle*)v)->colormap = map; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2702 |
return map; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2703 |
} |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2704 |
} |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2705 |
} |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2706 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2707 |
bool twocc = HasBit(EngInfo(engine_type)->misc_flags, EF_USES_2CC); |
5968
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
2708 |
|
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
2709 |
if (map == PAL_NONE) map = twocc ? (SpriteID)SPR_2CCMAP_BASE : (SpriteID)PALETTE_RECOLOR_START; |
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
2710 |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2711 |
const Livery *livery = GetEngineLivery(engine_type, player, parent_engine_type, v); |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2712 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2713 |
map += livery->colour1; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2714 |
if (twocc) map += livery->colour2 * 16; |
3113
c0f312f22238
(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents:
3105
diff
changeset
|
2715 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2716 |
/* Update cache */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2717 |
if (v != NULL) ((Vehicle*)v)->colormap = map; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
2718 |
return map; |
3040
c3473d1fb81f
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
2719 |
} |
c3473d1fb81f
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
2720 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
2721 |
SpriteID GetEnginePalette(EngineID engine_type, PlayerID player) |
3105
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2722 |
{ |
5968
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
2723 |
return GetEngineColourMap(engine_type, player, INVALID_ENGINE, NULL); |
3105
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2724 |
} |
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2725 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
2726 |
SpriteID GetVehiclePalette(const Vehicle *v) |
3105
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2727 |
{ |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2728 |
if (v->type == VEH_TRAIN) { |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2729 |
return GetEngineColourMap( |
9626 | 2730 |
(v->u.rail.first_engine != INVALID_ENGINE && (UsesWagonOverride(v) || (IsArticulatedPart(v) && RailVehInfo(v->engine_type)->railveh_type != RAILVEH_WAGON))) ? |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2731 |
v->u.rail.first_engine : v->engine_type, |
5968
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
2732 |
v->owner, v->u.rail.first_engine, v); |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2733 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2734 |
|
5968
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
2735 |
return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v); |
3105
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2736 |
} |
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2737 |
|
9629 | 2738 |
static uint8 _cargo_days; |
2739 |
static uint16 _cargo_source; |
|
2740 |
static uint32 _cargo_source_xy; |
|
2741 |
static uint16 _cargo_count; |
|
2742 |
static uint16 _cargo_paid_for; |
|
2743 |
static Money _cargo_feeder_share; |
|
2744 |
static uint32 _cargo_loaded_at_xy; |
|
2745 |
||
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2746 |
/** |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2747 |
* Make it possible to make the saveload tables "friends" of other classes. |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2748 |
* @param vt the vehicle type. Can be VEH_END for the common vehicle description data |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2749 |
* @return the saveload description |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2750 |
*/ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2751 |
const SaveLoad *GetVehicleDescription(VehicleType vt) |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2752 |
{ |
9574 | 2753 |
/** Save and load of vehicles */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2754 |
static const SaveLoad _common_veh_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2755 |
SLE_VAR(Vehicle, subtype, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2756 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2757 |
SLE_REF(Vehicle, next, REF_VEHICLE_OLD), |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2758 |
SLE_CONDVAR(Vehicle, name, SLE_NAME, 0, 83), |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2759 |
SLE_CONDSTR(Vehicle, name, SLE_STR, 0, 84, SL_MAX_VERSION), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2760 |
SLE_CONDVAR(Vehicle, unitnumber, SLE_FILE_U8 | SLE_VAR_U16, 0, 7), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2761 |
SLE_CONDVAR(Vehicle, unitnumber, SLE_UINT16, 8, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2762 |
SLE_VAR(Vehicle, owner, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2763 |
SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2764 |
SLE_CONDVAR(Vehicle, tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2765 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2766 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2767 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2768 |
SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2769 |
SLE_CONDVAR(Vehicle, x_pos, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2770 |
SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2771 |
SLE_CONDVAR(Vehicle, y_pos, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2772 |
SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2773 |
SLE_VAR(Vehicle, direction, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2774 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2775 |
SLE_CONDNULL(2, 0, 57), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2776 |
SLE_VAR(Vehicle, spritenum, SLE_UINT8), |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2777 |
SLE_CONDNULL(5, 0, 57), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2778 |
SLE_VAR(Vehicle, engine_type, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2779 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2780 |
SLE_VAR(Vehicle, max_speed, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2781 |
SLE_VAR(Vehicle, cur_speed, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2782 |
SLE_VAR(Vehicle, subspeed, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2783 |
SLE_VAR(Vehicle, acceleration, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2784 |
SLE_VAR(Vehicle, progress, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2785 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2786 |
SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2787 |
SLE_CONDVAR(Vehicle, last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2788 |
SLE_CONDVAR(Vehicle, last_station_visited, SLE_UINT16, 5, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2789 |
|
9629 | 2790 |
SLE_VAR(Vehicle, cargo_type, SLE_UINT8), |
2791 |
SLE_CONDVAR(Vehicle, cargo_subtype, SLE_UINT8, 35, SL_MAX_VERSION), |
|
2792 |
SLEG_CONDVAR( _cargo_days, SLE_UINT8, 0, 67), |
|
2793 |
SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
|
2794 |
SLEG_CONDVAR( _cargo_source, SLE_UINT16, 7, 67), |
|
2795 |
SLEG_CONDVAR( _cargo_source_xy, SLE_UINT32, 44, 67), |
|
2796 |
SLE_VAR(Vehicle, cargo_cap, SLE_UINT16), |
|
2797 |
SLEG_CONDVAR( _cargo_count, SLE_UINT16, 0, 67), |
|
2798 |
SLE_CONDLST(Vehicle, cargo, REF_CARGO_PACKET, 68, SL_MAX_VERSION), |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2799 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2800 |
SLE_VAR(Vehicle, day_counter, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2801 |
SLE_VAR(Vehicle, tick_counter, SLE_UINT8), |
9732 | 2802 |
SLE_CONDVAR(Vehicle, running_ticks, SLE_UINT8, 88, SL_MAX_VERSION), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2803 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2804 |
SLE_VAR(Vehicle, cur_order_index, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2805 |
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
|
2806 |
|
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2807 |
/* 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
|
2808 |
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
|
2809 |
converted correctly */ |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2810 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, type), SLE_UINT8, 0, 4), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2811 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2812 |
|
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2813 |
/* Orders for version 5 and on */ |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2814 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, type), SLE_UINT8, 5, SL_MAX_VERSION), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2815 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, flags), SLE_UINT8, 5, SL_MAX_VERSION), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2816 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2817 |
|
4712
273ec3b182bf
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4695
diff
changeset
|
2818 |
/* Refit in current order */ |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2819 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, refit_cargo), SLE_UINT8, 36, SL_MAX_VERSION), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2820 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, refit_subtype), SLE_UINT8, 36, SL_MAX_VERSION), |
4712
273ec3b182bf
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4695
diff
changeset
|
2821 |
|
9629 | 2822 |
/* Timetable in current order */ |
2823 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, wait_time), SLE_UINT16, 67, SL_MAX_VERSION), |
|
2824 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, travel_time), SLE_UINT16, 67, SL_MAX_VERSION), |
|
2825 |
||
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2826 |
SLE_REF(Vehicle, orders, REF_ORDER), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2827 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2828 |
SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2829 |
SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2830 |
SLE_CONDVAR(Vehicle, max_age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2831 |
SLE_CONDVAR(Vehicle, max_age, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2832 |
SLE_CONDVAR(Vehicle, date_of_last_service, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2833 |
SLE_CONDVAR(Vehicle, date_of_last_service, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2834 |
SLE_CONDVAR(Vehicle, service_interval, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2835 |
SLE_CONDVAR(Vehicle, service_interval, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2836 |
SLE_VAR(Vehicle, reliability, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2837 |
SLE_VAR(Vehicle, reliability_spd_dec, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2838 |
SLE_VAR(Vehicle, breakdown_ctr, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2839 |
SLE_VAR(Vehicle, breakdown_delay, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2840 |
SLE_VAR(Vehicle, breakdowns_since_last_service, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2841 |
SLE_VAR(Vehicle, breakdown_chance, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2842 |
SLE_CONDVAR(Vehicle, build_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2843 |
SLE_CONDVAR(Vehicle, build_year, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2844 |
|
9629 | 2845 |
SLE_VAR(Vehicle, load_unload_time_rem, SLE_UINT16), |
2846 |
SLEG_CONDVAR( _cargo_paid_for, SLE_UINT16, 45, SL_MAX_VERSION), |
|
2847 |
SLE_CONDVAR(Vehicle, vehicle_flags, SLE_UINT8, 40, SL_MAX_VERSION), |
|
2848 |
||
2849 |
SLE_CONDVAR(Vehicle, profit_this_year, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), |
|
2850 |
SLE_CONDVAR(Vehicle, profit_this_year, SLE_INT64, 65, SL_MAX_VERSION), |
|
2851 |
SLE_CONDVAR(Vehicle, profit_last_year, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), |
|
2852 |
SLE_CONDVAR(Vehicle, profit_last_year, SLE_INT64, 65, SL_MAX_VERSION), |
|
2853 |
SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_I32 | SLE_VAR_I64,51, 64), |
|
2854 |
SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, 65, 67), |
|
2855 |
SLEG_CONDVAR( _cargo_loaded_at_xy, SLE_UINT32, 51, 67), |
|
2856 |
SLE_CONDVAR(Vehicle, value, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), |
|
2857 |
SLE_CONDVAR(Vehicle, value, SLE_INT64, 65, SL_MAX_VERSION), |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2858 |
|
9732 | 2859 |
SLE_CONDVAR(Vehicle, random_bits, SLE_UINT8, 2, SL_MAX_VERSION), |
2860 |
SLE_CONDVAR(Vehicle, waiting_triggers, SLE_UINT8, 2, SL_MAX_VERSION), |
|
2861 |
||
2862 |
SLE_CONDREF(Vehicle, next_shared, REF_VEHICLE, 2, SL_MAX_VERSION), |
|
2863 |
SLE_CONDREF(Vehicle, prev_shared, REF_VEHICLE, 2, SL_MAX_VERSION), |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2864 |
|
9624 | 2865 |
SLE_CONDVAR(Vehicle, group_id, SLE_UINT16, 60, SL_MAX_VERSION), |
2866 |
||
9629 | 2867 |
SLE_CONDVAR(Vehicle, current_order_time, SLE_UINT32, 67, SL_MAX_VERSION), |
2868 |
SLE_CONDVAR(Vehicle, lateness_counter, SLE_INT32, 67, SL_MAX_VERSION), |
|
2869 |
||
9574 | 2870 |
/* reserve extra space in savegame here. (currently 10 bytes) */ |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2871 |
SLE_CONDNULL(10, 2, SL_MAX_VERSION), |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2872 |
|
0 | 2873 |
SLE_END() |
2874 |
}; |
|
2875 |
||
2876 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2877 |
static const SaveLoad _train_desc[] = { |
9626 | 2878 |
SLE_WRITEBYTE(Vehicle, type, VEH_TRAIN), |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2879 |
SLE_VEH_INCLUDEX(), |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2880 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, crash_anim_pos), SLE_UINT16), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2881 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, force_proceed), SLE_UINT8), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2882 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, railtype), SLE_UINT8), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2883 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, track), SLE_UINT8), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2884 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2885 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, flags), SLE_UINT8, 2, SL_MAX_VERSION), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2886 |
SLE_CONDNULL(2, 2, 59), |
0 | 2887 |
|
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2888 |
SLE_CONDNULL(2, 2, 19), |
9574 | 2889 |
/* reserve extra space in savegame here. (currently 11 bytes) */ |
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2890 |
SLE_CONDNULL(11, 2, SL_MAX_VERSION), |
0 | 2891 |
|
2892 |
SLE_END() |
|
2893 |
}; |
|
2894 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2895 |
static const SaveLoad _roadveh_desc[] = { |
9626 | 2896 |
SLE_WRITEBYTE(Vehicle, type, VEH_ROAD), |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2897 |
SLE_VEH_INCLUDEX(), |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2898 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, state), SLE_UINT8), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2899 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, frame), SLE_UINT8), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2900 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, blocked_ctr), SLE_UINT16), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2901 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, overtaking), SLE_UINT8), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2902 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, overtaking_ctr), SLE_UINT8), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2903 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, crashed_ctr), SLE_UINT16), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2904 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, reverse_ctr), SLE_UINT8), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2905 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2906 |
SLE_CONDREFX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, slot), REF_ROADSTOPS, 6, SL_MAX_VERSION), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2907 |
SLE_CONDNULL(1, 6, SL_MAX_VERSION), |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2908 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, slot_age), SLE_UINT8, 6, SL_MAX_VERSION), |
9574 | 2909 |
/* reserve extra space in savegame here. (currently 16 bytes) */ |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2910 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2911 |
|
2912 |
SLE_END() |
|
2913 |
}; |
|
2914 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2915 |
static const SaveLoad _ship_desc[] = { |
9626 | 2916 |
SLE_WRITEBYTE(Vehicle, type, VEH_SHIP), |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2917 |
SLE_VEH_INCLUDEX(), |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2918 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleShip, state), SLE_UINT8), |
0 | 2919 |
|
9574 | 2920 |
/* reserve extra space in savegame here. (currently 16 bytes) */ |
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2921 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2922 |
|
2923 |
SLE_END() |
|
2924 |
}; |
|
2925 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2926 |
static const SaveLoad _aircraft_desc[] = { |
9626 | 2927 |
SLE_WRITEBYTE(Vehicle, type, VEH_AIRCRAFT), |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2928 |
SLE_VEH_INCLUDEX(), |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2929 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, crashed_counter), SLE_UINT16), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2930 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, pos), SLE_UINT8), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2931 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2932 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, targetairport), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2933 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, targetairport), SLE_UINT16, 5, SL_MAX_VERSION), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2934 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2935 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, state), SLE_UINT8), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2936 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2937 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, previous_pos), SLE_UINT8, 2, SL_MAX_VERSION), |
0 | 2938 |
|
9574 | 2939 |
/* reserve extra space in savegame here. (currently 15 bytes) */ |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2940 |
SLE_CONDNULL(15, 2, SL_MAX_VERSION), |
0 | 2941 |
|
2942 |
SLE_END() |
|
2943 |
}; |
|
2944 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2945 |
static const SaveLoad _special_desc[] = { |
9626 | 2946 |
SLE_WRITEBYTE(Vehicle, type, VEH_SPECIAL), |
0 | 2947 |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2948 |
SLE_VAR(Vehicle, subtype, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2949 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2950 |
SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2951 |
SLE_CONDVAR(Vehicle, tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2952 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2953 |
SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2954 |
SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2955 |
SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2956 |
SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2957 |
SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2958 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2959 |
SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2960 |
SLE_CONDNULL(5, 0, 57), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2961 |
SLE_VAR(Vehicle, progress, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2962 |
SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2963 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2964 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleSpecial, animation_state), SLE_UINT16), |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2965 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleSpecial, animation_substate), SLE_UINT8), |
0 | 2966 |
|
9574 | 2967 |
/* reserve extra space in savegame here. (currently 16 bytes) */ |
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2968 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2969 |
|
2970 |
SLE_END() |
|
2971 |
}; |
|
2972 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2973 |
static const SaveLoad _disaster_desc[] = { |
9626 | 2974 |
SLE_WRITEBYTE(Vehicle, type, VEH_DISASTER), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2975 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2976 |
SLE_REF(Vehicle, next, REF_VEHICLE_OLD), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2977 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2978 |
SLE_VAR(Vehicle, subtype, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2979 |
SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2980 |
SLE_CONDVAR(Vehicle, tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2981 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2982 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2983 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2984 |
SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2985 |
SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2986 |
SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2987 |
SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2988 |
SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2989 |
SLE_VAR(Vehicle, direction, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2990 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2991 |
SLE_CONDNULL(5, 0, 57), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2992 |
SLE_VAR(Vehicle, owner, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2993 |
SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2994 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2995 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2996 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2997 |
SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2998 |
SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2999 |
SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3000 |
SLE_VAR(Vehicle, tick_counter, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3001 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3002 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleDisaster, image_override), SLE_UINT16), |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3003 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleDisaster, big_ufo_destroyer_target), SLE_UINT16), |
0 | 3004 |
|
9574 | 3005 |
/* reserve extra space in savegame here. (currently 16 bytes) */ |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3006 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 3007 |
|
3008 |
SLE_END() |
|
3009 |
}; |
|
3010 |
||
3011 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3012 |
static const SaveLoad *_veh_descs[] = { |
0 | 3013 |
_train_desc, |
3014 |
_roadveh_desc, |
|
3015 |
_ship_desc, |
|
3016 |
_aircraft_desc, |
|
3017 |
_special_desc, |
|
3018 |
_disaster_desc, |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3019 |
_common_veh_desc, |
0 | 3020 |
}; |
3021 |
||
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3022 |
return _veh_descs[vt]; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3023 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3024 |
|
9574 | 3025 |
/** Will be called when the vehicles need to be saved. */ |
6573 | 3026 |
static void Save_VEHS() |
0 | 3027 |
{ |
3028 |
Vehicle *v; |
|
9574 | 3029 |
/* Write the vehicles */ |
0 | 3030 |
FOR_ALL_VEHICLES(v) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3031 |
SlSetArrayIndex(v->index); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3032 |
SlObject(v, GetVehicleDescription(v->type)); |
0 | 3033 |
} |
3034 |
} |
|
3035 |
||
9574 | 3036 |
/** Will be called when vehicles need to be loaded. */ |
6573 | 3037 |
static void Load_VEHS() |
0 | 3038 |
{ |
3039 |
int index; |
|
3040 |
Vehicle *v; |
|
3041 |
||
9629 | 3042 |
_cargo_count = 0; |
3043 |
||
0 | 3044 |
while ((index = SlIterateArray()) != -1) { |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
3045 |
Vehicle *v; |
9626 | 3046 |
VehicleType vtype = (VehicleType)SlReadByte(); |
9629 | 3047 |
|
3048 |
switch (vtype) { |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3049 |
case VEH_TRAIN: v = new (index) Train(); break; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3050 |
case VEH_ROAD: v = new (index) RoadVehicle(); break; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3051 |
case VEH_SHIP: v = new (index) Ship(); break; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3052 |
case VEH_AIRCRAFT: v = new (index) Aircraft(); break; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3053 |
case VEH_SPECIAL: v = new (index) SpecialVehicle(); break; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3054 |
case VEH_DISASTER: v = new (index) DisasterVehicle(); break; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3055 |
case VEH_INVALID: v = new (index) InvalidVehicle(); break; |
9624 | 3056 |
default: NOT_REACHED(); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3057 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3058 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3059 |
SlObject(v, GetVehicleDescription(vtype)); |
9629 | 3060 |
|
3061 |
if (_cargo_count != 0 && IsPlayerBuildableVehicleType(v)) { |
|
3062 |
/* Don't construct the packet with station here, because that'll fail with old savegames */ |
|
3063 |
CargoPacket *cp = new CargoPacket(); |
|
3064 |
cp->source = _cargo_source; |
|
3065 |
cp->source_xy = _cargo_source_xy; |
|
3066 |
cp->count = _cargo_count; |
|
3067 |
cp->days_in_transit = _cargo_days; |
|
3068 |
cp->feeder_share = _cargo_feeder_share; |
|
3069 |
cp->loaded_at_xy = _cargo_loaded_at_xy; |
|
3070 |
v->cargo.Append(cp); |
|
3071 |
} |
|
3072 |
||
2549 | 3073 |
/* Old savegames used 'last_station_visited = 0xFF' */ |
2685
00111d5ca47f
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
3074 |
if (CheckSavegameVersion(5) && v->last_station_visited == 0xFF) |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2467
diff
changeset
|
3075 |
v->last_station_visited = INVALID_STATION; |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3076 |
|
2685
00111d5ca47f
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
3077 |
if (CheckSavegameVersion(5)) { |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3078 |
/* Convert the current_order.type (which is a mix of type and flags, because |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
3079 |
* in those versions, they both were 4 bits big) to type and flags */ |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3080 |
v->current_order.flags = (v->current_order.type & 0xF0) >> 4; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
3081 |
v->current_order.type.m_val &= 0x0F; |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3082 |
} |
9624 | 3083 |
|
3084 |
/* Advanced vehicle lists got added */ |
|
3085 |
if (CheckSavegameVersion(60)) v->group_id = DEFAULT_GROUP; |
|
0 | 3086 |
} |
3087 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3088 |
/* Check for shared order-lists (we now use pointers for that) */ |
2685
00111d5ca47f
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
3089 |
if (CheckSavegameVersionOldStyle(5, 2)) { |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3090 |
FOR_ALL_VEHICLES(v) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3091 |
Vehicle *u; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3092 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3093 |
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
|
3094 |
/* If a vehicle has the same orders, add the link to eachother |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
3095 |
* in both vehicles */ |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3096 |
if (v->orders == u->orders) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3097 |
v->next_shared = u; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3098 |
u->prev_shared = v; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3099 |
break; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3100 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3101 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3102 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3103 |
} |
0 | 3104 |
} |
3105 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
3106 |
extern const ChunkHandler _veh_chunk_handlers[] = { |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1541
diff
changeset
|
3107 |
{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY | CH_LAST}, |
0 | 3108 |
}; |
5902
906fea1535ab
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5860
diff
changeset
|
3109 |
|
906fea1535ab
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5860
diff
changeset
|
3110 |
void Vehicle::BeginLoading() |
906fea1535ab
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5860
diff
changeset
|
3111 |
{ |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
3112 |
assert(IsTileType(tile, MP_STATION) || type == VEH_SHIP); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3113 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3114 |
if (this->current_order.type == OT_GOTO_STATION && |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3115 |
this->current_order.dest == this->last_station_visited) { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3116 |
/* Arriving at the ordered station. |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3117 |
* Keep the load/unload flags, as we (obviously) still need them. */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
3118 |
this->current_order.flags &= OFB_FULL_LOAD | OFB_UNLOAD | OFB_TRANSFER; |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3119 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3120 |
/* Furthermore add the Non Stop flag to mark that this station |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3121 |
* is the actual destination of the vehicle, which is (for example) |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3122 |
* necessary to be known for HandleTrainLoading to determine |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3123 |
* whether the train is lost or not; not marking a train lost |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3124 |
* that arrives at random stations is bad. */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
3125 |
this->current_order.flags |= OFB_NON_STOP; |
9629 | 3126 |
UpdateVehicleTimetable(this, true); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3127 |
} else { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3128 |
/* This is just an unordered intermediate stop */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3129 |
this->current_order.flags = 0; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3130 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3131 |
|
5902
906fea1535ab
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5860
diff
changeset
|
3132 |
current_order.type = OT_LOADING; |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
3133 |
GetStation(this->last_station_visited)->loading_vehicles.push_back(this); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3134 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3135 |
VehiclePayment(this); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3136 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3137 |
InvalidateWindow(this->GetVehicleListWindowClass(), this->owner); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
3138 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3139 |
InvalidateWindow(WC_VEHICLE_DETAILS, this->index); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3140 |
InvalidateWindow(WC_STATION_VIEW, this->last_station_visited); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3141 |
|
9626 | 3142 |
GetStation(this->last_station_visited)->MarkTilesDirty(true); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3143 |
this->MarkDirty(); |
5902
906fea1535ab
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5860
diff
changeset
|
3144 |
} |
906fea1535ab
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5860
diff
changeset
|
3145 |
|
906fea1535ab
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5860
diff
changeset
|
3146 |
void Vehicle::LeaveStation() |
906fea1535ab
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5860
diff
changeset
|
3147 |
{ |
906fea1535ab
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5860
diff
changeset
|
3148 |
assert(current_order.type == OT_LOADING); |
9629 | 3149 |
|
3150 |
/* Only update the timetable if the vehicle was supposed to stop here. */ |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
3151 |
if (current_order.flags & OFB_NON_STOP) UpdateVehicleTimetable(this, false); |
9629 | 3152 |
|
5902
906fea1535ab
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5860
diff
changeset
|
3153 |
current_order.type = OT_LEAVESTATION; |
906fea1535ab
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5860
diff
changeset
|
3154 |
current_order.flags = 0; |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
3155 |
GetStation(this->last_station_visited)->loading_vehicles.remove(this); |
9629 | 3156 |
|
3157 |
HideFillingPercent(this->fill_percent_te_id); |
|
3158 |
this->fill_percent_te_id = INVALID_TE_ID; |
|
5902
906fea1535ab
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5860
diff
changeset
|
3159 |
} |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3160 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3161 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3162 |
void Vehicle::HandleLoading(bool mode) |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3163 |
{ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3164 |
switch (this->current_order.type) { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3165 |
case OT_LOADING: { |
9629 | 3166 |
uint wait_time = max(this->current_order.wait_time - this->lateness_counter, 0); |
3167 |
||
9624 | 3168 |
/* Not the first call for this tick, or still loading */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
3169 |
if (mode || !HasBit(this->vehicle_flags, VF_LOADING_FINISHED) || |
9629 | 3170 |
(_patches.timetabling && this->current_order_time < wait_time)) return; |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3171 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3172 |
this->PlayLeaveStationSound(); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3173 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3174 |
Order b = this->current_order; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3175 |
this->LeaveStation(); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3176 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3177 |
/* If this was not the final order, don't remove it from the list. */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
3178 |
if (!(b.flags & OFB_NON_STOP)) return; |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3179 |
break; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3180 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3181 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3182 |
case OT_DUMMY: break; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3183 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3184 |
default: return; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3185 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3186 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3187 |
this->cur_order_index++; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3188 |
InvalidateVehicleOrder(this); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3189 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3190 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3191 |
void Vehicle::SetNext(Vehicle *next) |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3192 |
{ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3193 |
if (this->next != NULL) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3194 |
/* We had an old next vehicle. Update the first and previous pointers */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3195 |
for (Vehicle *v = this->next; v != NULL; v = v->Next()) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3196 |
v->first = this->next; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3197 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3198 |
this->next->previous = NULL; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3199 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3200 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3201 |
this->next = next; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3202 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3203 |
if (this->next != NULL) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3204 |
/* A new next vehicle. Update the first and previous pointers */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3205 |
if (this->next->previous != NULL) this->next->previous->next = NULL; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3206 |
this->next->previous = this; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3207 |
for (Vehicle *v = this->next; v != NULL; v = v->Next()) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3208 |
v->first = this->first; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3209 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3210 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3211 |
} |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3212 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3213 |
void SpecialVehicle::UpdateDeltaXY(Direction direction) |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3214 |
{ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3215 |
this->x_offs = 0; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3216 |
this->y_offs = 0; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3217 |
this->sprite_width = 1; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3218 |
this->sprite_height = 1; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3219 |
this->z_height = 1; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
3220 |
} |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3221 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3222 |
void StopAllVehicles() |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3223 |
{ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3224 |
Vehicle *v; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3225 |
FOR_ALL_VEHICLES(v) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3226 |
/* Code ripped from CmdStartStopTrain. Can't call it, because of |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3227 |
* ownership problems, so we'll duplicate some code, for now */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3228 |
v->vehstatus |= VS_STOPPED; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
3229 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3230 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3231 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3232 |
} |