author | glx |
Sun, 15 Jun 2008 22:18:10 +0000 | |
branch | noai |
changeset 10971 | aaf89f8c59b9 |
parent 10955 | 56b381e5253f |
child 11126 | 72d4c9314c72 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
3 |
/** @file vehicle.cpp Base implementations of all vehicles. */ |
9574 | 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" |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
16 |
#include "news_func.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" |
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
|
20 |
#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
|
21 |
#include "vehicle_gui.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
22 |
#include "rail_type.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
23 |
#include "train.h" |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
24 |
#include "aircraft.h" |
3428
62682d91b4cd
(svn r4256) - Codechange: Replace lone map access in vehicle.c with its map accessor.
peter1138
parents:
3422
diff
changeset
|
25 |
#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
|
26 |
#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
|
27 |
#include "water_map.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
|
28 |
#include "yapf/yapf.h" |
5968
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
29 |
#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
|
30 |
#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
|
31 |
#include "newgrf_sound.h" |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
32 |
#include "newgrf_station.h" |
9624 | 33 |
#include "group.h" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
34 |
#include "order_func.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
35 |
#include "strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
36 |
#include "zoom_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
37 |
#include "functions.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
38 |
#include "date_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
39 |
#include "window_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
40 |
#include "vehicle_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
41 |
#include "signal_func.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
42 |
#include "sound_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
43 |
#include "variables.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
44 |
#include "autoreplace_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
45 |
#include "autoreplace_gui.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
46 |
#include "string_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
47 |
#include "settings_type.h" |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
48 |
#include "oldpool_func.h" |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
49 |
#include "depot_map.h" |
10294 | 50 |
#include "animated_tile_func.h" |
51 |
#include "effectvehicle_base.h" |
|
10370
fa4f88090694
(svn r12911) [NoAI] -Add: added AIEventVehicle(List|WaitingInDepot|Unprofitable) (Yexo)
truebrain
parents:
10355
diff
changeset
|
52 |
#include "ai/ai.h" |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
53 |
#include "core/alloc_func.hpp" |
10776 | 54 |
#include "vehiclelist.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
55 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
56 |
#include "table/sprites.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
57 |
#include "table/strings.h" |
0 | 58 |
|
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
59 |
#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
|
60 |
#define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6)) |
0 | 61 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
62 |
VehicleID _vehicle_id_ctr_day; |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
63 |
const Vehicle *_place_clicked_vehicle; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
64 |
VehicleID _new_vehicle_id; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
65 |
uint16 _returned_refit_capacity; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
66 |
|
6043
99c8fb13658b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
6014
diff
changeset
|
67 |
|
99c8fb13658b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
6014
diff
changeset
|
68 |
/* 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
|
69 |
const uint32 _veh_build_proc_table[] = { |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
70 |
CMD_BUILD_RAIL_VEHICLE, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
71 |
CMD_BUILD_ROAD_VEH, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
72 |
CMD_BUILD_SHIP, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
73 |
CMD_BUILD_AIRCRAFT, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
74 |
}; |
6043
99c8fb13658b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
6014
diff
changeset
|
75 |
const uint32 _veh_sell_proc_table[] = { |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
76 |
CMD_SELL_RAIL_WAGON, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
77 |
CMD_SELL_ROAD_VEH, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
78 |
CMD_SELL_SHIP, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
79 |
CMD_SELL_AIRCRAFT, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
80 |
}; |
2753 | 81 |
|
6043
99c8fb13658b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
6014
diff
changeset
|
82 |
const uint32 _veh_refit_proc_table[] = { |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
83 |
CMD_REFIT_RAIL_VEHICLE, |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3973
diff
changeset
|
84 |
CMD_REFIT_ROAD_VEH, |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
85 |
CMD_REFIT_SHIP, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
86 |
CMD_REFIT_AIRCRAFT, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
87 |
}; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
88 |
|
4451
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
89 |
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
|
90 |
CMD_SEND_TRAIN_TO_DEPOT, |
4451
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
91 |
CMD_SEND_ROADVEH_TO_DEPOT, |
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
92 |
CMD_SEND_SHIP_TO_DEPOT, |
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
93 |
CMD_SEND_AIRCRAFT_TO_HANGAR, |
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
94 |
}; |
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
95 |
|
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
96 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
97 |
/* Initialize the vehicle-pool */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
98 |
DEFINE_OLD_POOL_GENERIC(Vehicle, Vehicle) |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
99 |
|
9800 | 100 |
/** Function to tell if a vehicle needs to be autorenewed |
101 |
* @param *p The vehicle owner |
|
102 |
* @return true if the vehicle is old enough for replacement |
|
103 |
*/ |
|
104 |
bool Vehicle::NeedsAutorenewing(const Player *p) const |
|
105 |
{ |
|
106 |
/* We can always generate the Player pointer when we have the vehicle. |
|
107 |
* However this takes time and since the Player pointer is often present |
|
108 |
* when this function is called then it's faster to pass the pointer as an |
|
109 |
* argument rather than finding it again. */ |
|
110 |
assert(p == GetPlayer(this->owner)); |
|
111 |
||
112 |
if (!p->engine_renew) return false; |
|
113 |
if (this->age - this->max_age < (p->engine_renew_months * 30)) return false; |
|
10294 | 114 |
if (this->age == 0) return false; // rail cars don't age and lacks a max age |
9800 | 115 |
|
116 |
return true; |
|
117 |
} |
|
118 |
||
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
|
119 |
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
|
120 |
{ |
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
|
121 |
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
|
122 |
v->breakdowns_since_last_service = 0; |
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
123 |
v->reliability = GetEngine(v->engine_type)->reliability; |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
124 |
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
|
125 |
} |
0 | 126 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
127 |
bool Vehicle::NeedsServicing() const |
593 | 128 |
{ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
129 |
if (this->vehstatus & (VS_STOPPED | VS_CRASHED)) return false; |
1757
b179d50241dc
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
130 |
|
10776 | 131 |
if (_settings_game.order.no_servicing_if_no_breakdowns && _settings_game.difficulty.vehicle_breakdowns == 0) { |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
132 |
/* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
133 |
* Note: If servicing is enabled, we postpone replacement till next service. */ |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
134 |
return EngineHasReplacementForPlayer(GetPlayer(this->owner), this->engine_type, this->group_id); |
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
|
135 |
} |
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
|
136 |
|
10776 | 137 |
return _settings_game.vehicle.servint_ispercent ? |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
138 |
(this->reliability < GetEngine(this->engine_type)->reliability * (100 - this->service_interval) / 100) : |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
139 |
(this->date_of_last_service + this->service_interval < _date); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
140 |
} |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
141 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
142 |
bool Vehicle::NeedsAutomaticServicing() const |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
143 |
{ |
10776 | 144 |
if (_settings_game.order.gotodepot && VehicleHasDepotOrders(this)) return false; |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
145 |
if (this->current_order.IsType(OT_LOADING)) return false; |
10181
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
10142
diff
changeset
|
146 |
if (this->current_order.IsType(OT_GOTO_DEPOT) && this->current_order.GetDepotOrderType() != ODTFB_SERVICE) return false; |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
147 |
return NeedsServicing(); |
593 | 148 |
} |
149 |
||
3881 | 150 |
StringID VehicleInTheWayErrMsg(const Vehicle* v) |
0 | 151 |
{ |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
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
|
155 |
case VEH_AIRCRAFT: return STR_A015_AIRCRAFT_IN_THE_WAY; |
3881 | 156 |
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
|
157 |
} |
0 | 158 |
} |
159 |
||
160 |
static void *EnsureNoVehicleProcZ(Vehicle *v, void *data) |
|
161 |
{ |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
162 |
byte z = *(byte*)data; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
163 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
164 |
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
|
165 |
if (v->z_pos > z) return NULL; |
0 | 166 |
|
3881 | 167 |
_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
|
168 |
return v; |
0 | 169 |
} |
170 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
171 |
Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z) |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
172 |
{ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
173 |
return (Vehicle*)VehicleFromPos(tile, &z, &EnsureNoVehicleProcZ); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
174 |
} |
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
|
175 |
|
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
|
176 |
bool EnsureNoVehicleOnGround(TileIndex tile) |
0 | 177 |
{ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
178 |
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
|
179 |
} |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
180 |
|
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
|
181 |
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z, bool without_crashed) |
0 | 182 |
{ |
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
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
int y2 = TileY(to); |
0 | 187 |
Vehicle *veh; |
188 |
||
189 |
/* Make sure x1 < x2 or y1 < y2 */ |
|
190 |
if (x1 > x2 || y1 > y2) { |
|
6432 | 191 |
Swap(x1, x2); |
192 |
Swap(y1, y2); |
|
0 | 193 |
} |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
194 |
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
|
195 |
if (without_crashed && (veh->vehstatus & VS_CRASHED) != 0) continue; |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
196 |
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
|
197 |
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
|
198 |
(veh->y_pos >> 4) >= y1 && (veh->y_pos >> 4) <= y2) { |
0 | 199 |
return veh; |
200 |
} |
|
201 |
} |
|
202 |
} |
|
203 |
return NULL; |
|
204 |
} |
|
205 |
||
2817 | 206 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
207 |
/** 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
|
208 |
static void *GetVehicleTunnelBridgeProc(Vehicle *v, void *data) |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
209 |
{ |
10955 | 210 |
if (v->type != VEH_TRAIN && v->type != VEH_ROAD && v->type != VEH_SHIP) return NULL; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
211 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
212 |
_error_message = VehicleInTheWayErrMsg(v); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
213 |
return v; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
214 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
215 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
216 |
/** |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
217 |
* Finds vehicle in tunnel / bridge |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
218 |
* @param tile first end |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
219 |
* @param endtile second end |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
220 |
* @return pointer to vehicle found |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
221 |
*/ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
222 |
Vehicle *GetVehicleTunnelBridge(TileIndex tile, TileIndex endtile) |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
223 |
{ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
224 |
Vehicle *v = (Vehicle*)VehicleFromPos(tile, NULL, &GetVehicleTunnelBridgeProc); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
225 |
if (v != NULL) return v; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
226 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
227 |
return (Vehicle*)VehicleFromPos(endtile, NULL, &GetVehicleTunnelBridgeProc); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
228 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
229 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
230 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
231 |
static void UpdateVehiclePosHash(Vehicle *v, int x, int y); |
2817 | 232 |
|
0 | 233 |
void VehiclePositionChanged(Vehicle *v) |
234 |
{ |
|
235 |
int img = v->cur_image; |
|
236 |
Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
237 |
const Sprite *spr = GetSprite(img); |
0 | 238 |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
239 |
pt.x += spr->x_offs; |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
240 |
pt.y += spr->y_offs; |
0 | 241 |
|
242 |
UpdateVehiclePosHash(v, pt.x, pt.y); |
|
243 |
||
244 |
v->left_coord = pt.x; |
|
245 |
v->top_coord = pt.y; |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
246 |
v->right_coord = pt.x + spr->width + 2; |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
247 |
v->bottom_coord = pt.y + spr->height + 2; |
0 | 248 |
} |
249 |
||
9574 | 250 |
/** Called after load to update coordinates */ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
251 |
void AfterLoadVehicles(bool clear_te_id) |
0 | 252 |
{ |
253 |
Vehicle *v; |
|
254 |
||
255 |
FOR_ALL_VEHICLES(v) { |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
256 |
/* Reinstate the previous pointer */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
257 |
if (v->Next() != NULL) v->Next()->previous = v; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
258 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
259 |
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
|
260 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
261 |
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
|
262 |
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
|
263 |
if (v->type == VEH_TRAIN) v->u.rail.first_engine = INVALID_ENGINE; |
9627 | 264 |
if (v->type == VEH_ROAD) v->u.road.first_engine = INVALID_ENGINE; |
9629 | 265 |
|
266 |
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
|
267 |
} |
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
|
268 |
|
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
|
269 |
FOR_ALL_VEHICLES(v) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
270 |
/* Fill the first pointers */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
271 |
if (v->Previous() == NULL) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
272 |
for (Vehicle *u = v; u != NULL; u = u->Next()) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
273 |
u->first = v; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
274 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
275 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
276 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
277 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
278 |
FOR_ALL_VEHICLES(v) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
279 |
assert(v->first != NULL); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
280 |
|
9627 | 281 |
if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
282 |
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
|
283 |
TrainConsistChanged(v); |
9627 | 284 |
} else if (v->type == VEH_ROAD && IsRoadVehFront(v)) { |
285 |
RoadVehUpdateCache(v); |
|
286 |
} |
|
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
|
287 |
} |
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
|
288 |
|
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
|
289 |
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
|
290 |
switch (v->type) { |
9624 | 291 |
case VEH_ROAD: |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
292 |
v->u.road.roadtype = HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD; |
9624 | 293 |
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
|
294 |
/* FALL THROUGH */ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
295 |
case VEH_TRAIN: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
296 |
case VEH_SHIP: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
297 |
v->cur_image = v->GetImage(v->direction); |
9624 | 298 |
break; |
299 |
||
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
|
300 |
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
|
301 |
if (IsNormalAircraft(v)) { |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
302 |
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
|
303 |
|
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
|
304 |
/* 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
|
305 |
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
|
306 |
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
|
307 |
|
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
|
308 |
/* 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
|
309 |
if (v->subtype == AIR_HELICOPTER) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
310 |
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
|
311 |
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
|
312 |
} |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
313 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
314 |
UpdateAircraftCache(v); |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
315 |
} |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
316 |
break; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
317 |
default: break; |
0 | 318 |
} |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
319 |
|
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
320 |
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
|
321 |
VehiclePositionChanged(v); |
0 | 322 |
} |
323 |
} |
|
324 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
325 |
Vehicle::Vehicle() |
0 | 326 |
{ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
327 |
this->type = VEH_INVALID; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
328 |
this->left_coord = INVALID_COORD; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
329 |
this->group_id = DEFAULT_GROUP; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
330 |
this->fill_percent_te_id = INVALID_TE_ID; |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
331 |
this->first = this; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
332 |
this->colormap = PAL_NONE; |
0 | 333 |
} |
334 |
||
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
|
335 |
/** |
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
|
336 |
* 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
|
337 |
* @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
|
338 |
*/ |
6573 | 339 |
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
|
340 |
{ |
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
|
341 |
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
|
342 |
} |
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
|
343 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
344 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
345 |
/* static */ bool Vehicle::AllocateList(Vehicle **vl, int num) |
0 | 346 |
{ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
347 |
uint counter = _Vehicle_pool.first_free_index; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
348 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
349 |
for (int i = 0; i != num; i++) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
350 |
Vehicle *v = AllocateRaw(counter); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
351 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
352 |
if (v == NULL) return false; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
353 |
v = new (v) InvalidVehicle(); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
354 |
|
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
355 |
if (vl != NULL) { |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
356 |
vl[i] = v; |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
357 |
} |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
358 |
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
|
359 |
} |
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
|
360 |
|
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
361 |
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
|
362 |
} |
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
|
363 |
|
9627 | 364 |
/* Size of the hash, 6 = 64 x 64, 7 = 128 x 128. Larger sizes will (in theory) reduce hash |
365 |
* lookup times at the expense of memory usage. */ |
|
366 |
const int HASH_BITS = 7; |
|
367 |
const int HASH_SIZE = 1 << HASH_BITS; |
|
368 |
const int HASH_MASK = HASH_SIZE - 1; |
|
369 |
const int TOTAL_HASH_SIZE = 1 << (HASH_BITS * 2); |
|
370 |
const int TOTAL_HASH_MASK = TOTAL_HASH_SIZE - 1; |
|
371 |
||
372 |
/* Resolution of the hash, 0 = 1*1 tile, 1 = 2*2 tiles, 2 = 4*4 tiles, etc. |
|
373 |
* Profiling results show that 0 is fastest. */ |
|
374 |
const int HASH_RES = 0; |
|
375 |
||
376 |
static Vehicle *_new_vehicle_position_hash[TOTAL_HASH_SIZE]; |
|
377 |
||
378 |
static void *VehicleFromHash(int xl, int yl, int xu, int yu, void *data, VehicleFromPosProc *proc) |
|
379 |
{ |
|
380 |
for (int y = yl; ; y = (y + (1 << HASH_BITS)) & (HASH_MASK << HASH_BITS)) { |
|
381 |
for (int x = xl; ; x = (x + 1) & HASH_MASK) { |
|
382 |
Vehicle *v = _new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; |
|
383 |
for (; v != NULL; v = v->next_new_hash) { |
|
384 |
void *a = proc(v, data); |
|
385 |
if (a != NULL) return a; |
|
386 |
} |
|
387 |
if (x == xu) break; |
|
388 |
} |
|
389 |
if (y == yu) break; |
|
390 |
} |
|
391 |
||
392 |
return NULL; |
|
393 |
} |
|
394 |
||
395 |
||
396 |
void *VehicleFromPosXY(int x, int y, void *data, VehicleFromPosProc *proc) |
|
397 |
{ |
|
398 |
const int COLL_DIST = 6; |
|
399 |
||
400 |
/* Hash area to scan is from xl,yl to xu,yu */ |
|
401 |
int xl = GB((x - COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS); |
|
402 |
int xu = GB((x + COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS); |
|
403 |
int yl = GB((y - COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS; |
|
404 |
int yu = GB((y + COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS; |
|
405 |
||
406 |
return VehicleFromHash(xl, yl, xu, yu, data, proc); |
|
407 |
} |
|
408 |
||
2651 | 409 |
|
0 | 410 |
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc) |
411 |
{ |
|
9627 | 412 |
int x = GB(TileX(tile), HASH_RES, HASH_BITS); |
413 |
int y = GB(TileY(tile), HASH_RES, HASH_BITS) << HASH_BITS; |
|
414 |
||
415 |
Vehicle *v = _new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; |
|
416 |
for (; v != NULL; v = v->next_new_hash) { |
|
417 |
if (v->tile != tile) continue; |
|
418 |
||
419 |
void *a = proc(v, data); |
|
420 |
if (a != NULL) return a; |
|
0 | 421 |
} |
9627 | 422 |
|
0 | 423 |
return NULL; |
424 |
} |
|
425 |
||
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
426 |
static void UpdateNewVehiclePosHash(Vehicle *v, bool remove) |
9627 | 427 |
{ |
428 |
Vehicle **old_hash = v->old_new_hash; |
|
429 |
Vehicle **new_hash; |
|
430 |
||
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
431 |
if (remove) { |
9627 | 432 |
new_hash = NULL; |
433 |
} else { |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
434 |
int x = GB(TileX(v->tile), HASH_RES, HASH_BITS); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
435 |
int y = GB(TileY(v->tile), HASH_RES, HASH_BITS) << HASH_BITS; |
9627 | 436 |
new_hash = &_new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; |
437 |
} |
|
438 |
||
439 |
if (old_hash == new_hash) return; |
|
440 |
||
441 |
/* Remove from the old position in the hash table */ |
|
442 |
if (old_hash != NULL) { |
|
443 |
Vehicle *last = NULL; |
|
444 |
Vehicle *u = *old_hash; |
|
445 |
while (u != v) { |
|
446 |
last = u; |
|
447 |
u = u->next_new_hash; |
|
448 |
assert(u != NULL); |
|
449 |
} |
|
450 |
||
451 |
if (last == NULL) { |
|
452 |
*old_hash = v->next_new_hash; |
|
453 |
} else { |
|
454 |
last->next_new_hash = v->next_new_hash; |
|
455 |
} |
|
456 |
} |
|
457 |
||
458 |
/* Insert vehicle at beginning of the new position in the hash table */ |
|
459 |
if (new_hash != NULL) { |
|
460 |
v->next_new_hash = *new_hash; |
|
461 |
*new_hash = v; |
|
462 |
assert(v != v->next_new_hash); |
|
463 |
} |
|
464 |
||
465 |
/* Remember current hash position */ |
|
466 |
v->old_new_hash = new_hash; |
|
467 |
} |
|
468 |
||
469 |
static Vehicle *_vehicle_position_hash[0x1000]; |
|
0 | 470 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
471 |
static void UpdateVehiclePosHash(Vehicle *v, int x, int y) |
0 | 472 |
{ |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
473 |
UpdateNewVehiclePosHash(v, x == INVALID_COORD); |
9627 | 474 |
|
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
|
475 |
Vehicle **old_hash, **new_hash; |
0 | 476 |
int old_x = v->left_coord; |
477 |
int old_y = v->top_coord; |
|
478 |
||
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
479 |
new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x, y)]; |
0 | 480 |
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
|
481 |
|
2639 | 482 |
if (old_hash == new_hash) return; |
0 | 483 |
|
484 |
/* remove from hash table? */ |
|
485 |
if (old_hash != NULL) { |
|
486 |
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
|
487 |
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
|
488 |
while (u != v) { |
0 | 489 |
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
|
490 |
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
|
491 |
assert(u != NULL); |
0 | 492 |
} |
493 |
||
2639 | 494 |
if (last == NULL) { |
0 | 495 |
*old_hash = v->next_hash; |
2639 | 496 |
} else { |
0 | 497 |
last->next_hash = v->next_hash; |
2639 | 498 |
} |
0 | 499 |
} |
500 |
||
501 |
/* insert into hash table? */ |
|
502 |
if (new_hash != NULL) { |
|
503 |
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
|
504 |
*new_hash = v; |
0 | 505 |
} |
506 |
} |
|
507 |
||
6573 | 508 |
void ResetVehiclePosHash() |
5352
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
509 |
{ |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
510 |
Vehicle *v; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
511 |
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
|
512 |
memset(_vehicle_position_hash, 0, sizeof(_vehicle_position_hash)); |
9627 | 513 |
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
|
514 |
} |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
515 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
516 |
void ResetVehicleColorMap() |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
517 |
{ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
518 |
Vehicle *v; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
519 |
FOR_ALL_VEHICLES(v) { v->colormap = PAL_NONE; } |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
520 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
521 |
|
6573 | 522 |
void InitializeVehicles() |
0 | 523 |
{ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
524 |
_Vehicle_pool.CleanPool(); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
525 |
_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
|
526 |
|
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
527 |
ResetVehiclePosHash(); |
0 | 528 |
} |
529 |
||
530 |
Vehicle *GetLastVehicleInChain(Vehicle *v) |
|
531 |
{ |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
532 |
while (v->Next() != NULL) v = v->Next(); |
0 | 533 |
return v; |
534 |
} |
|
535 |
||
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
536 |
const Vehicle *GetLastVehicleInChain(const Vehicle *v) |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
537 |
{ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
538 |
while (v->Next() != NULL) v = v->Next(); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
539 |
return v; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
540 |
} |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
541 |
|
2630 | 542 |
uint CountVehiclesInChain(const Vehicle* v) |
0 | 543 |
{ |
2639 | 544 |
uint count = 0; |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
545 |
do count++; while ((v = v->Next()) != NULL); |
0 | 546 |
return count; |
547 |
} |
|
548 |
||
4574
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
549 |
/** 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
|
550 |
* @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
|
551 |
* @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
|
552 |
*/ |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
553 |
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
|
554 |
{ |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
555 |
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
|
556 |
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
|
557 |
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
|
558 |
return !IsArticulatedPart(v) && // tenders and other articulated parts |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
559 |
!IsRearDualheaded(v); // rear parts of multiheaded engines |
9627 | 560 |
case VEH_ROAD: return IsRoadVehFront(v); |
561 |
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
|
562 |
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
|
563 |
} |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
564 |
} |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
565 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
566 |
void Vehicle::PreDestructor() |
0 | 567 |
{ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
568 |
if (CleaningPool()) return; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
569 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
570 |
if (IsValidStationID(this->last_station_visited)) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
571 |
GetStation(this->last_station_visited)->loading_vehicles.remove(this); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
572 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
573 |
HideFillingPercent(this->fill_percent_te_id); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
574 |
this->fill_percent_te_id = INVALID_TE_ID; |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
575 |
} |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
576 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
577 |
if (IsEngineCountable(this)) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
578 |
GetPlayer(this->owner)->num_engines[this->engine_type]--; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
579 |
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
|
580 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
581 |
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
|
582 |
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
|
583 |
} |
4574
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
584 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
585 |
if (this->type == VEH_ROAD) ClearSlot(this); |
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 |
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
|
588 |
InvalidateWindowData(WC_VEHICLE_DEPOT, this->tile); |
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
589 |
} |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
590 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
591 |
this->cargo.Truncate(0); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
592 |
DeleteVehicleOrders(this); |
4404
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
593 |
|
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
594 |
/* 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
|
595 |
* 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
|
596 |
* other artic parts. */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
597 |
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
|
598 |
delete this->Next(); |
9627 | 599 |
} |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
600 |
|
10645 | 601 |
extern void StopGlobalFollowVehicle(const Vehicle *v); |
602 |
StopGlobalFollowVehicle(this); |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
603 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
604 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
605 |
Vehicle::~Vehicle() |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
606 |
{ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
607 |
free(this->name); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
608 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
609 |
if (CleaningPool()) return; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
610 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
611 |
this->SetNext(NULL); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
612 |
UpdateVehiclePosHash(this, INVALID_COORD, 0); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
613 |
this->next_hash = NULL; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
614 |
this->next_new_hash = NULL; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
615 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
616 |
DeleteVehicleNews(this->index, INVALID_STRING_ID); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
617 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
618 |
new (this) InvalidVehicle(); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
619 |
} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
620 |
|
9626 | 621 |
/** |
622 |
* Deletes all vehicles in a chain. |
|
623 |
* @param v The first vehicle in the chain. |
|
624 |
*/ |
|
0 | 625 |
void DeleteVehicleChain(Vehicle *v) |
626 |
{ |
|
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
627 |
assert(v->First() == v); |
9626 | 628 |
|
0 | 629 |
do { |
630 |
Vehicle *u = v; |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
631 |
/* 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
|
632 |
* it may happen that vehicle chain is deleted when visible */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
633 |
if (!(v->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(v); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
634 |
v = v->Next(); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
635 |
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
|
636 |
} while (v != NULL); |
0 | 637 |
} |
638 |
||
9574 | 639 |
/** head of the linked list to tell what vehicles that visited a depot in a tick */ |
2630 | 640 |
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
|
641 |
|
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
642 |
/** 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
|
643 |
* @param *v vehicle to add |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
644 |
*/ |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
645 |
void VehicleEnteredDepotThisTick(Vehicle *v) |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
646 |
{ |
9732 | 647 |
/* We need to set v->leave_depot_instantly as we have no control of it's contents at this time. |
648 |
* Vehicle should stop in the depot if it was in 'stopping' state - train intered depot while slowing down. */ |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
649 |
if (((v->current_order.GetDepotActionType() & ODATFB_HALT) && !(v->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) && v->current_order.IsType(OT_GOTO_DEPOT)) || |
9732 | 650 |
(v->vehstatus & VS_STOPPED)) { |
9574 | 651 |
/* 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
|
652 |
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
|
653 |
} else { |
9574 | 654 |
/* the vehicle do not plan on stopping in the depot, so we stop it to ensure that it will not reserve the path |
655 |
* out of the depot before we might autoreplace it to a different engine. The new engine would not own the reserved path |
|
656 |
* 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
|
657 |
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
|
658 |
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
|
659 |
} |
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
660 |
|
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
661 |
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
|
662 |
_first_veh_in_depot_list = v; |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
663 |
} else { |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
664 |
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
|
665 |
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
|
666 |
w->depot_list = v; |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
667 |
} |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
668 |
} |
0 | 669 |
|
6573 | 670 |
void CallVehicleTicks() |
0 | 671 |
{ |
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
|
672 |
_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
|
673 |
|
9624 | 674 |
Station *st; |
675 |
FOR_ALL_STATIONS(st) LoadUnloadStation(st); |
|
676 |
||
677 |
Vehicle *v; |
|
0 | 678 |
FOR_ALL_VEHICLES(v) { |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
679 |
v->Tick(); |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
680 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
681 |
switch (v->type) { |
9624 | 682 |
default: break; |
683 |
||
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
|
684 |
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
|
685 |
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
|
686 |
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
|
687 |
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
|
688 |
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
|
689 |
if (v->type == VEH_AIRCRAFT && v->subtype != AIR_HELICOPTER) continue; |
9627 | 690 |
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
|
691 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
692 |
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
|
693 |
/* 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
|
694 |
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
|
695 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
696 |
/* 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
|
697 |
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
|
698 |
} |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
699 |
} |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
700 |
|
9574 | 701 |
/* 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
|
702 |
v = _first_veh_in_depot_list; |
10294 | 703 |
if (v != NULL) { |
704 |
while (v != NULL) { |
|
705 |
/* Autoreplace needs the current player set as the vehicle owner */ |
|
706 |
_current_player = v->owner; |
|
707 |
||
708 |
/* Buffer v->depot_list and clear it. |
|
709 |
* Autoreplace might clear this so it has to be buffered. */ |
|
710 |
Vehicle *w = v->depot_list; |
|
711 |
v->depot_list = NULL; // it should always be NULL at the end of each tick |
|
712 |
||
713 |
/* Start vehicle if we stopped them in VehicleEnteredDepotThisTick() |
|
714 |
* We need to stop them between VehicleEnteredDepotThisTick() and here or we risk that |
|
715 |
* they are already leaving the depot again before being replaced. */ |
|
716 |
if (v->leave_depot_instantly) { |
|
717 |
v->leave_depot_instantly = false; |
|
718 |
v->vehstatus &= ~VS_STOPPED; |
|
719 |
} |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
720 |
MaybeReplaceVehicle(v, DC_EXEC, true); |
10294 | 721 |
v = w; |
722 |
} |
|
723 |
_current_player = OWNER_NONE; |
|
0 | 724 |
} |
725 |
} |
|
726 |
||
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
|
727 |
/** 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
|
728 |
* @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
|
729 |
* @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
|
730 |
* @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
|
731 |
*/ |
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
|
732 |
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
|
733 |
{ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
734 |
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
|
735 |
} |
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
|
736 |
|
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
|
737 |
/** 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
|
738 |
* @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
|
739 |
* @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
|
740 |
*/ |
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 |
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
|
742 |
{ |
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
|
743 |
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
|
744 |
|
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
|
745 |
if (refit_mask != 0) { |
9505 | 746 |
for (CargoID cid = 0; cid < NUM_CARGO; cid++) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
747 |
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
|
748 |
} |
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
|
749 |
} |
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
|
750 |
|
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
|
751 |
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
|
752 |
} |
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
|
753 |
|
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
754 |
/** Learn the price of refitting a certain engine |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
755 |
* @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
|
756 |
* @return Price for refitting |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
757 |
*/ |
9629 | 758 |
CommandCost GetRefitCost(EngineID engine_type) |
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
759 |
{ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
760 |
Money base_cost; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
761 |
ExpensesType expense_type; |
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
762 |
switch (GetEngine(engine_type)->type) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
763 |
case VEH_SHIP: |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
764 |
base_cost = _price.ship_base; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
765 |
expense_type = EXPENSES_SHIP_RUN; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
766 |
break; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
767 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
768 |
case VEH_ROAD: |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
769 |
base_cost = _price.roadveh_base; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
770 |
expense_type = EXPENSES_ROADVEH_RUN; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
771 |
break; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
772 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
773 |
case VEH_AIRCRAFT: |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
774 |
base_cost = _price.aircraft_base; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
775 |
expense_type = EXPENSES_AIRCRAFT_RUN; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
776 |
break; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
777 |
|
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
|
778 |
case VEH_TRAIN: |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
779 |
base_cost = 2 * ((RailVehInfo(engine_type)->railveh_type == RAILVEH_WAGON) ? |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
780 |
_price.build_railwagon : _price.build_railvehicle); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
781 |
expense_type = EXPENSES_TRAIN_RUN; |
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
782 |
break; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
783 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
784 |
default: NOT_REACHED(); |
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
785 |
} |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
786 |
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
|
787 |
} |
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
|
788 |
|
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
|
789 |
static void DoDrawVehicle(const Vehicle *v) |
0 | 790 |
{ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
791 |
SpriteID image = v->cur_image; |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
792 |
SpriteID pal = PAL_NONE; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
793 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
794 |
if (v->vehstatus & VS_DEFPAL) pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
0 | 795 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
796 |
AddSortableSpriteToDraw(image, pal, v->x_pos + v->x_offs, v->y_pos + v->y_offs, |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
797 |
v->x_extent, v->y_extent, v->z_extent, v->z_pos, (v->vehstatus & VS_SHADOW) != 0); |
0 | 798 |
} |
799 |
||
800 |
void ViewportAddVehicles(DrawPixelInfo *dpi) |
|
801 |
{ |
|
9574 | 802 |
/* 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
|
803 |
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
|
804 |
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
|
805 |
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
|
806 |
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
|
807 |
|
9574 | 808 |
/* The hash area to scan */ |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
809 |
int xl, xu, yl, yu; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
810 |
|
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
811 |
if (dpi->width + 70 < (1 << (7 + 6))) { |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
812 |
xl = GB(l - 70, 7, 6); |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
813 |
xu = GB(r, 7, 6); |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
814 |
} else { |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
815 |
/* scan whole hash row */ |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
816 |
xl = 0; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
817 |
xu = 0x3F; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
818 |
} |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
819 |
|
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
820 |
if (dpi->height + 70 < (1 << (6 + 6))) { |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
821 |
yl = GB(t - 70, 6, 6) << 6; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
822 |
yu = GB(b, 6, 6) << 6; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
823 |
} else { |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
824 |
/* scan whole column */ |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
825 |
yl = 0; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
826 |
yu = 0x3F << 6; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
827 |
} |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
828 |
|
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
829 |
for (int y = yl;; y = (y + (1 << 6)) & (0x3F << 6)) { |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
830 |
for (int x = xl;; x = (x + 1) & 0x3F) { |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
831 |
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
|
832 |
|
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
|
833 |
while (v != NULL) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
834 |
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
|
835 |
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
|
836 |
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
|
837 |
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
|
838 |
b >= v->top_coord) { |
0 | 839 |
DoDrawVehicle(v); |
840 |
} |
|
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
|
841 |
v = v->next_hash; |
0 | 842 |
} |
843 |
||
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
|
844 |
if (x == xu) break; |
0 | 845 |
} |
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
|
846 |
|
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
|
847 |
if (y == yu) break; |
0 | 848 |
} |
849 |
} |
|
850 |
||
2116 | 851 |
Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y) |
0 | 852 |
{ |
853 |
Vehicle *found = NULL, *v; |
|
854 |
uint dist, best_dist = (uint)-1; |
|
855 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
856 |
if ((uint)(x -= vp->left) >= (uint)vp->width || (uint)(y -= vp->top) >= (uint)vp->height) return NULL; |
0 | 857 |
|
9624 | 858 |
x = ScaleByZoom(x, vp->zoom) + vp->virtual_left; |
859 |
y = ScaleByZoom(y, vp->zoom) + vp->virtual_top; |
|
0 | 860 |
|
861 |
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
|
862 |
if ((v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0 && |
0 | 863 |
x >= v->left_coord && x <= v->right_coord && |
864 |
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
|
865 |
|
0 | 866 |
dist = max( |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
867 |
abs(((v->left_coord + v->right_coord) >> 1) - x), |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
868 |
abs(((v->top_coord + v->bottom_coord) >> 1) - y) |
0 | 869 |
); |
870 |
||
871 |
if (dist < best_dist) { |
|
872 |
found = v; |
|
873 |
best_dist = dist; |
|
874 |
} |
|
875 |
} |
|
876 |
} |
|
877 |
||
878 |
return found; |
|
879 |
} |
|
880 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
881 |
void CheckVehicle32Day(Vehicle *v) |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
882 |
{ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
883 |
if ((v->day_counter & 0x1F) != 0) return; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
884 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
885 |
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
|
886 |
if (callback == CALLBACK_FAILED) return; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
887 |
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
|
888 |
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
|
889 |
} |
0 | 890 |
|
891 |
void DecreaseVehicleValue(Vehicle *v) |
|
892 |
{ |
|
893 |
v->value -= v->value >> 8; |
|
894 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
895 |
} |
|
896 |
||
897 |
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
|
898 |
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
|
899 |
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
|
900 |
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
|
901 |
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
|
902 |
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
|
903 |
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
|
904 |
72, 80, 90, 100, 110, 120, 130, 140, |
0 | 905 |
150, 170, 190, 210, 230, 250, 250, 250, |
906 |
}; |
|
907 |
||
908 |
void CheckVehicleBreakdown(Vehicle *v) |
|
909 |
{ |
|
910 |
int rel, rel_old; |
|
911 |
||
912 |
/* decrease reliability */ |
|
913 |
v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0); |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
914 |
if ((rel_old >> 8) != (rel >> 8)) InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
0 | 915 |
|
2639 | 916 |
if (v->breakdown_ctr != 0 || v->vehstatus & VS_STOPPED || |
10776 | 917 |
_settings_game.difficulty.vehicle_breakdowns < 1 || |
2639 | 918 |
v->cur_speed < 5 || _game_mode == GM_MENU) { |
919 |
return; |
|
920 |
} |
|
0 | 921 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
922 |
uint32 r = Random(); |
0 | 923 |
|
924 |
/* increase chance of failure */ |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
925 |
int chance = v->breakdown_chance + 1; |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
926 |
if (Chance16I(1, 25, r)) chance += 25; |
0 | 927 |
v->breakdown_chance = min(255, chance); |
928 |
||
929 |
/* calculate reliability value to use in comparison */ |
|
930 |
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
|
931 |
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
|
932 |
|
0 | 933 |
/* reduced breakdowns? */ |
10776 | 934 |
if (_settings_game.difficulty.vehicle_breakdowns == 1) rel += 0x6666; |
0 | 935 |
|
936 |
/* check if to break down */ |
|
937 |
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
|
938 |
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
|
939 |
v->breakdown_delay = GB(r, 24, 7) + 0x80; |
0 | 940 |
v->breakdown_chance = 0; |
941 |
} |
|
942 |
} |
|
943 |
||
944 |
static const StringID _vehicle_type_names[4] = { |
|
945 |
STR_019F_TRAIN, |
|
946 |
STR_019C_ROAD_VEHICLE, |
|
947 |
STR_019E_SHIP, |
|
948 |
STR_019D_AIRCRAFT, |
|
949 |
}; |
|
950 |
||
951 |
static void ShowVehicleGettingOld(Vehicle *v, StringID msg) |
|
952 |
{ |
|
2639 | 953 |
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
|
954 |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
955 |
/* 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
|
956 |
if (GetPlayer(v->owner)->engine_renew && GetEngine(v->engine_type)->player_avail != 0) return; |
0 | 957 |
|
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
|
958 |
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
|
959 |
SetDParam(1, v->unitnumber); |
10645 | 960 |
AddNewsItem(msg, NS_ADVICE, v->index, 0); |
0 | 961 |
} |
962 |
||
963 |
void AgeVehicle(Vehicle *v) |
|
964 |
{ |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
965 |
if (v->age < 65535) v->age++; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
966 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
967 |
int age = v->age - v->max_age; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
968 |
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
|
969 |
|
0 | 970 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
971 |
||
972 |
if (age == -366) { |
|
973 |
ShowVehicleGettingOld(v, STR_01A0_IS_GETTING_OLD); |
|
974 |
} else if (age == 0) { |
|
975 |
ShowVehicleGettingOld(v, STR_01A1_IS_GETTING_VERY_OLD); |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
976 |
} else if (age > 0 && (age % 366) == 0) { |
0 | 977 |
ShowVehicleGettingOld(v, STR_01A2_IS_GETTING_VERY_OLD_AND); |
978 |
} |
|
979 |
} |
|
980 |
||
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
981 |
/** 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
|
982 |
* @param tile Tile of the depot where the vehicles are started/stopped (only used for depots) |
9574 | 983 |
* @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
|
984 |
* @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
|
985 |
* @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
|
986 |
* - 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
|
987 |
* - 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
|
988 |
* - 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
|
989 |
* - 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
|
990 |
*/ |
9629 | 991 |
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
|
992 |
{ |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
993 |
VehicleList list; |
9629 | 994 |
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
|
995 |
uint stop_command; |
9624 | 996 |
VehicleType vehicle_type = (VehicleType)GB(p2, 0, 5); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
997 |
bool start_stop = HasBit(p2, 5); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
998 |
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
|
999 |
|
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1000 |
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
|
1001 |
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
|
1002 |
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
|
1003 |
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
|
1004 |
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
|
1005 |
default: return CMD_ERROR; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1006 |
} |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1007 |
|
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1008 |
if (vehicle_list_window) { |
5999
0de08210079a
(svn r8296) -Fix: GenerateVehicleSortList() tried to put a TileIndex into an uint16
bjarni
parents:
5998
diff
changeset
|
1009 |
uint32 id = p1; |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1010 |
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
|
1011 |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1012 |
GenerateVehicleSortList(&list, 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
|
1013 |
} else { |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1014 |
/* Get the list of vehicles in the depot */ |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1015 |
BuildDepotVehicleList(vehicle_type, tile, &list, NULL); |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1016 |
} |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1017 |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1018 |
for (uint i = 0; i < list.Length(); i++) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1019 |
const Vehicle *v = list[i]; |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1020 |
|
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1021 |
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
|
1022 |
|
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1023 |
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
|
1024 |
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
|
1025 |
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
|
1026 |
} else { |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1027 |
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
|
1028 |
} |
4648
ab94e3a447a8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1029 |
} |
ab94e3a447a8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1030 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1031 |
CommandCost ret = DoCommand(tile, v->index, 0, flags, stop_command); |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1032 |
|
9629 | 1033 |
if (CmdSucceeded(ret)) { |
1034 |
return_value = CommandCost(); |
|
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1035 |
/* 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
|
1036 |
* 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
|
1037 |
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
|
1038 |
} |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1039 |
} |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1040 |
|
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1041 |
return return_value; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1042 |
} |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1043 |
|
4659
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1044 |
/** Sells all vehicles in a depot |
9574 | 1045 |
* @param tile Tile of the depot where the depot is |
1046 |
* @param flags type of operation |
|
1047 |
* @param p1 Vehicle type |
|
1048 |
* @param p2 unused |
|
1049 |
*/ |
|
9629 | 1050 |
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
|
1051 |
{ |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1052 |
VehicleList list; |
4659
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1053 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1054 |
CommandCost cost(EXPENSES_NEW_VEHICLES); |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1055 |
uint sell_command; |
9624 | 1056 |
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
|
1057 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1058 |
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
|
1059 |
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
|
1060 |
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
|
1061 |
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
|
1062 |
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
|
1063 |
default: return CMD_ERROR; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1064 |
} |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1065 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1066 |
/* Get the list of vehicles in the depot */ |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1067 |
BuildDepotVehicleList(vehicle_type, tile, &list, &list); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1068 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1069 |
for (uint i = 0; i < list.Length(); i++) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1070 |
CommandCost ret = DoCommand(tile, list[i]->index, 1, flags, sell_command); |
9629 | 1071 |
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
|
1072 |
} |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1073 |
|
9629 | 1074 |
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
|
1075 |
return cost; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1076 |
} |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1077 |
|
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1078 |
/** Autoreplace all vehicles in the depot |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1079 |
* Note: this command can make incorrect cost estimations |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1080 |
* Luckily the final price can only drop, not increase. This is due to the fact that |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1081 |
* estimation can't predict wagon removal so it presumes worst case which is no income from selling wagons. |
9574 | 1082 |
* @param tile Tile of the depot where the vehicles are |
1083 |
* @param flags type of operation |
|
1084 |
* @param p1 Type of vehicle |
|
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1085 |
* @param p2 If bit 0 is set, then either replace all or nothing (instead of replacing until money runs out) |
9574 | 1086 |
*/ |
9629 | 1087 |
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
|
1088 |
{ |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1089 |
VehicleList list; |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1090 |
CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES); |
9624 | 1091 |
VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8); |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1092 |
bool all_or_nothing = HasBit(p2, 0); |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1093 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1094 |
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
|
1095 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1096 |
/* Get the list of vehicles in the depot */ |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1097 |
BuildDepotVehicleList(vehicle_type, tile, &list, &list); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1098 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1099 |
for (uint i = 0; i < list.Length(); i++) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1100 |
Vehicle *v = (Vehicle*)list[i]; |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1101 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1102 |
/* Ensure that the vehicle completely in the depot */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1103 |
if (!v->IsInDepot()) continue; |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1104 |
|
10294 | 1105 |
CommandCost ret = MaybeReplaceVehicle(v, flags, false); |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1106 |
|
9629 | 1107 |
if (CmdSucceeded(ret)) { |
1108 |
cost.AddCost(ret); |
|
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1109 |
} else { |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1110 |
if (all_or_nothing) { |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1111 |
/* We failed to replace a vehicle even though we set all or nothing. |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1112 |
* We should never reach this if DC_EXEC is set since then it should |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1113 |
* have failed the estimation guess. */ |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1114 |
assert(!(flags & DC_EXEC)); |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1115 |
/* Now we will have to return an error. */ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1116 |
return CMD_ERROR; |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1117 |
} |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1118 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1119 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1120 |
|
9629 | 1121 |
if (cost.GetCost() == 0) { |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1122 |
/* Either we didn't replace anything or something went wrong. |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1123 |
* Either way we want to return an error and not execute this command. */ |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1124 |
cost = CMD_ERROR; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1125 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1126 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1127 |
return cost; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1128 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1129 |
|
2244 | 1130 |
/** 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
|
1131 |
* @param tile tile of the depot where the cloned vehicle is build |
9574 | 1132 |
* @param flags type of operation |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1133 |
* @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
|
1134 |
* @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
|
1135 |
*/ |
9629 | 1136 |
CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2244 | 1137 |
{ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1138 |
CommandCost 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
|
1139 |
uint32 build_argument = 2; |
2244 | 1140 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
1141 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1142 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1143 |
Vehicle *v = GetVehicle(p1); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1144 |
Vehicle *v_front = v; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1145 |
Vehicle *w = NULL; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1146 |
Vehicle *w_front = NULL; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1147 |
Vehicle *w_rear = NULL; |
9599 | 1148 |
|
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1149 |
/* |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1150 |
* v_front is the front engine in the original vehicle |
9599 | 1151 |
* 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
|
1152 |
* 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
|
1153 |
* w is the car/vehicle currently being cloned |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1154 |
* 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
|
1155 |
*/ |
2244 | 1156 |
|
2639 | 1157 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
2244 | 1158 |
|
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
|
1159 |
if (v->type == VEH_TRAIN && (!IsFrontEngine(v) || v->u.rail.crash_anim_pos >= 4400)) return CMD_ERROR; |
2244 | 1160 |
|
9574 | 1161 |
/* 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
|
1162 |
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
|
1163 |
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
|
1164 |
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
|
1165 |
veh_counter++; |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1166 |
} 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
|
1167 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1168 |
if (!Vehicle::AllocateList(NULL, veh_counter)) { |
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
1169 |
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
|
1170 |
} |
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
|
1171 |
} |
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
|
1172 |
|
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
|
1173 |
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
|
1174 |
|
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1175 |
do { |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1176 |
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
|
1177 |
/* 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
|
1178 |
continue; |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1179 |
} |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1180 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1181 |
CommandCost 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
|
1182 |
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
|
1183 |
|
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1184 |
if (CmdFailed(cost)) return cost; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1185 |
|
9629 | 1186 |
total_cost.AddCost(cost); |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1187 |
|
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1188 |
if (flags & DC_EXEC) { |
2639 | 1189 |
w = GetVehicle(_new_vehicle_id); |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1190 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1191 |
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
|
1192 |
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
|
1193 |
} |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1194 |
|
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
|
1195 |
if (v->type == VEH_TRAIN && !IsFrontEngine(v)) { |
9574 | 1196 |
/* this s a train car |
1197 |
* add this unit to the end of the train */ |
|
9629 | 1198 |
CommandCost result = DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE); |
9626 | 1199 |
if (CmdFailed(result)) { |
1200 |
/* The train can't be joined to make the same consist as the original. |
|
1201 |
* Sell what we already made (clean up) and return an error. */ |
|
1202 |
DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front)); |
|
1203 |
DoCommand(w_front->tile, w->index, 1, flags, GetCmdSellVeh(w)); |
|
1204 |
return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE |
|
1205 |
} |
|
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1206 |
} else { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1207 |
/* 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
|
1208 |
w_front = w; |
3679
8e7e14ee361a
(svn r4599) -Fix: [Cloning, autoreplace] FS#141 clone service-interval
bjarni
parents:
3657
diff
changeset
|
1209 |
w->service_interval = v->service_interval; |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1210 |
} |
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
|
1211 |
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
|
1212 |
} |
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
|
1213 |
} 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
|
1214 |
|
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
|
1215 |
if (flags & DC_EXEC && v_front->type == VEH_TRAIN) { |
9574 | 1216 |
/* 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
|
1217 |
_new_vehicle_id = w_front->index; |
2244 | 1218 |
} |
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
|
1219 |
|
9624 | 1220 |
if (flags & DC_EXEC) { |
1221 |
/* Cloned vehicles belong to the same group */ |
|
1222 |
DoCommand(0, v_front->group_id, w_front->index, flags, CMD_ADD_VEHICLE_GROUP); |
|
1223 |
} |
|
1224 |
||
1225 |
||
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1226 |
/* 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
|
1227 |
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
|
1228 |
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
|
1229 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1230 |
/* 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
|
1231 |
* 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
|
1232 |
* 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
|
1233 |
* 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
|
1234 |
* 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
|
1235 |
* 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
|
1236 |
do { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1237 |
do { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1238 |
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
|
1239 |
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
|
1240 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1241 |
if (w->cargo_type != v->cargo_type || w->cargo_subtype != v->cargo_subtype) { |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1242 |
CommandCost cost = DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8) | 1U << 16 , flags, GetCmdRefitVeh(v)); |
9629 | 1243 |
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
|
1244 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1245 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1246 |
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
|
1247 |
w = GetNextArticPart(w); |
9627 | 1248 |
} else if (w->type == VEH_ROAD && RoadVehHasArticPart(w)) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1249 |
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
|
1250 |
} else { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1251 |
break; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1252 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1253 |
} else { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1254 |
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
|
1255 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1256 |
if (v->cargo_type != initial_cargo && initial_cargo != CT_INVALID) { |
9629 | 1257 |
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
|
1258 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1259 |
} |
9627 | 1260 |
|
1261 |
if (v->type == VEH_TRAIN && EngineHasArticPart(v)) { |
|
1262 |
v = GetNextArticPart(v); |
|
1263 |
} else if (v->type == VEH_ROAD && RoadVehHasArticPart(v)) { |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1264 |
v = v->Next(); |
9627 | 1265 |
} else { |
1266 |
break; |
|
1267 |
} |
|
1268 |
} 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
|
1269 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1270 |
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
|
1271 |
} 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
|
1272 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1273 |
if (flags & DC_EXEC) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1274 |
/* |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1275 |
* 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
|
1276 |
* the vehicle refitted before doing this, otherwise the moved |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1277 |
* cargo types might not match (passenger vs non-passenger) |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1278 |
*/ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1279 |
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
|
1280 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1281 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1282 |
/* 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
|
1283 |
* 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
|
1284 |
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
|
1285 |
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
|
1286 |
/* 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
|
1287 |
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
|
1288 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1289 |
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
|
1290 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1291 |
|
2244 | 1292 |
return total_cost; |
1293 |
} |
|
1294 |
||
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1295 |
/** |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1296 |
* 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
|
1297 |
* @param type type of vehicle |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1298 |
* @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
|
1299 |
* @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
|
1300 |
* @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
|
1301 |
* @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
|
1302 |
* @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
|
1303 |
*/ |
9629 | 1304 |
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
|
1305 |
{ |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1306 |
VehicleList list; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1307 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1308 |
GenerateVehicleSortList(&list, 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
|
1309 |
|
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
1310 |
/* Send all the vehicles to a depot */ |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1311 |
for (uint i = 0; i < list.Length(); i++) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1312 |
const Vehicle *v = list[i]; |
9629 | 1313 |
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
|
1314 |
|
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
1315 |
/* 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
|
1316 |
* 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
|
1317 |
* 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
|
1318 |
* it will succeed at least once. With DC_EXEC we really need to send them to the depot */ |
9629 | 1319 |
if (CmdSucceeded(ret) && !(flags & DC_EXEC)) { |
1320 |
return CommandCost(); |
|
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
1321 |
} |
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
1322 |
} |
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
|
1323 |
|
9629 | 1324 |
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
|
1325 |
} |
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
1326 |
|
9629 | 1327 |
/** |
1328 |
* Calculates how full a vehicle is. |
|
1329 |
* @param v The Vehicle to check. For trains, use the first engine. |
|
1330 |
* @param color The string to show depending on if we are unloading or loading |
|
1331 |
* @return A percentage of how full the Vehicle is. |
|
1332 |
*/ |
|
10645 | 1333 |
uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *color) |
9629 | 1334 |
{ |
1335 |
int count = 0; |
|
1336 |
int max = 0; |
|
1337 |
int cars = 0; |
|
1338 |
int unloading = 0; |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1339 |
bool loading = false; |
9629 | 1340 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1341 |
const Vehicle *u = v; |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1342 |
const Station *st = v->last_station_visited != INVALID_STATION ? GetStation(v->last_station_visited) : NULL; |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1343 |
|
9629 | 1344 |
/* Count up max and used */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1345 |
for (; v != NULL; v = v->Next()) { |
9629 | 1346 |
count += v->cargo.Count(); |
1347 |
max += v->cargo_cap; |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1348 |
if (v->cargo_cap != 0 && color != NULL) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1349 |
unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0; |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1350 |
loading |= !(u->current_order.GetUnloadType() & OUFB_UNLOAD) && st->goods[v->cargo_type].days_since_pickup != 255; |
9629 | 1351 |
cars++; |
1352 |
} |
|
1353 |
} |
|
1354 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1355 |
if (color != NULL) { |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1356 |
if (unloading == 0 && loading) { |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1357 |
*color = STR_PERCENT_UP; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1358 |
} else if (cars == unloading || !loading) { |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1359 |
*color = STR_PERCENT_DOWN; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1360 |
} else { |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1361 |
*color = STR_PERCENT_UP_DOWN; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1362 |
} |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1363 |
} |
9629 | 1364 |
|
1365 |
/* Train without capacity */ |
|
1366 |
if (max == 0) return 100; |
|
1367 |
||
1368 |
/* Return the percentage */ |
|
1369 |
return (count * 100) / max; |
|
1370 |
} |
|
1371 |
||
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1372 |
void VehicleEnterDepot(Vehicle *v) |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1373 |
{ |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1374 |
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
|
1375 |
case VEH_TRAIN: |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1376 |
InvalidateWindowClasses(WC_TRAINS_LIST); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1377 |
if (!IsFrontEngine(v)) v = v->First(); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1378 |
UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner); |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1379 |
v->load_unload_time_rem = 0; |
10181
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
10142
diff
changeset
|
1380 |
ClrBit(v->u.rail.flags, VRF_TOGGLE_REVERSE); |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
1381 |
TrainConsistChanged(v); |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1382 |
break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1383 |
|
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
|
1384 |
case VEH_ROAD: |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1385 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1386 |
if (!IsRoadVehFront(v)) v = v->First(); |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1387 |
break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1388 |
|
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
|
1389 |
case VEH_SHIP: |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1390 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
6319
27e68b914d3d
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium
parents:
6317
diff
changeset
|
1391 |
v->u.ship.state = TRACK_BIT_DEPOT; |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1392 |
RecalcShipStuff(v); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1393 |
break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1394 |
|
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
|
1395 |
case VEH_AIRCRAFT: |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1396 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1397 |
HandleAircraftEnterHangar(v); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1398 |
break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1399 |
default: NOT_REACHED(); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1400 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1401 |
|
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
|
1402 |
if (v->type != VEH_TRAIN) { |
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
1403 |
/* 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
|
1404 |
* 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
|
1405 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
1406 |
} |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1407 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1408 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1409 |
v->vehstatus |= VS_HIDDEN; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1410 |
v->cur_speed = 0; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1411 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1412 |
VehicleServiceInDepot(v); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1413 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1414 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1415 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1416 |
if (v->current_order.IsType(OT_GOTO_DEPOT)) { |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1417 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1418 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1419 |
Order t = v->current_order; |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1420 |
v->current_order.MakeDummy(); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1421 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1422 |
if (t.IsRefit()) { |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1423 |
_current_player = v->owner; |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1424 |
CommandCost cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 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
|
1425 |
|
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
|
1426 |
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
|
1427 |
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
|
1428 |
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
|
1429 |
/* 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
|
1430 |
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
|
1431 |
SetDParam(1, v->unitnumber); |
10645 | 1432 |
AddNewsItem(STR_ORDER_REFIT_FAILED, NS_ADVICE, v->index, 0); |
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
|
1433 |
} |
9629 | 1434 |
} else if (v->owner == _local_player && cost.GetCost() != 0) { |
1435 |
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
|
1436 |
} |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1437 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1438 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1439 |
if (t.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) { |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1440 |
/* Part of orders */ |
9629 | 1441 |
UpdateVehicleTimetable(v, true); |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1442 |
v->cur_order_index++; |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1443 |
} else if (t.GetDepotActionType() & ODATFB_HALT) { |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1444 |
/* Force depot visit */ |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1445 |
v->vehstatus |= VS_STOPPED; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1446 |
if (v->owner == _local_player) { |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1447 |
StringID string; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1448 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1449 |
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
|
1450 |
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
|
1451 |
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
|
1452 |
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
|
1453 |
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
|
1454 |
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
|
1455 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1456 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1457 |
SetDParam(0, v->unitnumber); |
10645 | 1458 |
AddNewsItem(string, NS_ADVICE, v->index, 0); |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1459 |
} |
10370
fa4f88090694
(svn r12911) [NoAI] -Add: added AIEventVehicle(List|WaitingInDepot|Unprofitable) (Yexo)
truebrain
parents:
10355
diff
changeset
|
1460 |
AI_Event(v->owner, new AIEventVehicleWaitingInDepot(v->index)); |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1461 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1462 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1463 |
} |
2244 | 1464 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1465 |
static bool IsUniqueVehicleName(const char *name) |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1466 |
{ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1467 |
const Vehicle *v; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1468 |
char buf[512]; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1469 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1470 |
FOR_ALL_VEHICLES(v) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1471 |
switch (v->type) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1472 |
case VEH_TRAIN: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1473 |
if (!IsTrainEngine(v)) continue; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1474 |
break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1475 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1476 |
case VEH_ROAD: |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1477 |
if (!IsRoadVehFront(v)) continue; |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1478 |
break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1479 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1480 |
case VEH_AIRCRAFT: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1481 |
if (!IsNormalAircraft(v)) continue; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1482 |
break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1483 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1484 |
case VEH_SHIP: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1485 |
break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1486 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1487 |
default: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1488 |
continue; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1489 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1490 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1491 |
SetDParam(0, v->index); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1492 |
GetString(buf, STR_VEHICLE_NAME, lastof(buf)); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1493 |
if (strcmp(buf, name) == 0) return false; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1494 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1495 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1496 |
return true; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1497 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1498 |
|
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
|
1499 |
/** 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
|
1500 |
* @param tile unused |
9574 | 1501 |
* @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
|
1502 |
* @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
|
1503 |
* @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
|
1504 |
*/ |
9629 | 1505 |
CommandCost CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1506 |
{ |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1507 |
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
|
1508 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1509 |
Vehicle *v = GetVehicle(p1); |
0 | 1510 |
|
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
|
1511 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 1512 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1513 |
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
|
1514 |
|
0 | 1515 |
if (flags & DC_EXEC) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1516 |
free(v->name); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1517 |
v->name = strdup(_cmd_text); |
10645 | 1518 |
InvalidateWindowClassesData(WC_TRAINS_LIST, 1); |
0 | 1519 |
MarkWholeScreenDirty(); |
1520 |
} |
|
1521 |
||
9629 | 1522 |
return CommandCost(); |
0 | 1523 |
} |
1524 |
||
1525 |
||
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
|
1526 |
/** 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
|
1527 |
* @param tile unused |
9574 | 1528 |
* @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
|
1529 |
* @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
|
1530 |
* @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
|
1531 |
*/ |
9629 | 1532 |
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
|
1533 |
{ |
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
|
1534 |
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
|
1535 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
1536 |
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
|
1537 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1538 |
Vehicle *v = GetVehicle(p1); |
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
|
1539 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
1540 |
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
|
1541 |
|
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
|
1542 |
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
|
1543 |
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
|
1544 |
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
|
1545 |
} |
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
|
1546 |
|
9629 | 1547 |
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
|
1548 |
} |
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
|
1549 |
|
0 | 1550 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1551 |
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
|
1552 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1553 |
/** |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1554 |
* Stores the vehicle image coords for later call to EndVehicleMove() |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1555 |
* @param v vehicle which image's coords to store |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1556 |
* @see _old_vehicle_coords |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1557 |
* @see EndVehicleMove() |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1558 |
*/ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1559 |
void BeginVehicleMove(const Vehicle *v) |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1560 |
{ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1561 |
_old_vehicle_coords.left = v->left_coord; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1562 |
_old_vehicle_coords.top = v->top_coord; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1563 |
_old_vehicle_coords.right = v->right_coord; |
0 | 1564 |
_old_vehicle_coords.bottom = v->bottom_coord; |
1565 |
} |
|
1566 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1567 |
/** |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1568 |
* Marks screen dirty after a vehicle has moved |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1569 |
* @param v vehicle which is marked dirty |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1570 |
* @see _old_vehicle_coords |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1571 |
* @see BeginVehicleMove() |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1572 |
*/ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1573 |
void EndVehicleMove(const Vehicle *v) |
0 | 1574 |
{ |
1575 |
MarkAllViewportsDirty( |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1576 |
min(_old_vehicle_coords.left, v->left_coord), |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1577 |
min(_old_vehicle_coords.top, v->top_coord), |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1578 |
max(_old_vehicle_coords.right, v->right_coord) + 1, |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1579 |
max(_old_vehicle_coords.bottom, v->bottom_coord) + 1 |
0 | 1580 |
); |
1581 |
} |
|
1582 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1583 |
/** |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1584 |
* Marks viewports dirty where the vehicle's image is |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1585 |
* In fact, it equals |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1586 |
* BeginVehicleMove(v); EndVehicleMove(v); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1587 |
* @param v vehicle to mark dirty |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1588 |
* @see BeginVehicleMove() |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1589 |
* @see EndVehicleMove() |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1590 |
*/ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1591 |
void MarkSingleVehicleDirty(const Vehicle *v) |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1592 |
{ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1593 |
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
|
1594 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1595 |
|
0 | 1596 |
/* returns true if staying in the same tile */ |
6479 | 1597 |
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v) |
0 | 1598 |
{ |
1599 |
static const int8 _delta_coord[16] = { |
|
1600 |
-1,-1,-1, 0, 1, 1, 1, 0, /* x */ |
|
1601 |
-1, 0, 1, 1, 1, 0,-1,-1, /* y */ |
|
1602 |
}; |
|
1603 |
||
1604 |
int x = v->x_pos + _delta_coord[v->direction]; |
|
1605 |
int y = v->y_pos + _delta_coord[v->direction + 8]; |
|
1606 |
||
6479 | 1607 |
GetNewVehiclePosResult gp; |
1608 |
gp.x = x; |
|
1609 |
gp.y = y; |
|
1610 |
gp.old_tile = v->tile; |
|
1611 |
gp.new_tile = TileVirtXY(x, y); |
|
1612 |
return gp; |
|
0 | 1613 |
} |
1614 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
1615 |
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
|
1616 |
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
|
1617 |
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
|
1618 |
DIR_E , DIR_SE, DIR_S |
0 | 1619 |
}; |
1620 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1621 |
Direction GetDirectionTowards(const Vehicle *v, int x, int y) |
0 | 1622 |
{ |
1623 |
int i = 0; |
|
1624 |
||
1625 |
if (y >= v->y_pos) { |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1626 |
if (y != v->y_pos) i += 3; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1627 |
i += 3; |
0 | 1628 |
} |
1629 |
||
1630 |
if (x >= v->x_pos) { |
|
1631 |
if (x != v->x_pos) i++; |
|
1632 |
i++; |
|
1633 |
} |
|
1634 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1635 |
Direction dir = v->direction; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1636 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1637 |
DirDiff dirdiff = DirDifference(_new_direction_table[i], dir); |
3158
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1638 |
if (dirdiff == DIRDIFF_SAME) return dir; |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1639 |
return ChangeDir(dir, dirdiff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
0 | 1640 |
} |
1641 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1642 |
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
|
1643 |
{ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1644 |
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
|
1645 |
|
2952 | 1646 |
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
|
1647 |
case VEH_TRAIN: |
9574 | 1648 |
if (v->u.rail.track == TRACK_BIT_DEPOT) // We'll assume the train is facing outwards |
10645 | 1649 |
return DiagDirToDiagTrackdir(GetRailDepotDirection(v->tile)); // Train in depot |
9574 | 1650 |
|
1651 |
if (v->u.rail.track == TRACK_BIT_WORMHOLE) // train in tunnel, so just use his direction and assume a diagonal track |
|
10645 | 1652 |
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
|
1653 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1654 |
return TrackDirectionToTrackdir(FindFirstTrack(v->u.rail.track), v->direction); |
1959 | 1655 |
|
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
|
1656 |
case VEH_SHIP: |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1657 |
if (v->IsInDepot()) |
9574 | 1658 |
// We'll assume the ship is facing outwards |
10645 | 1659 |
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
|
1660 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1661 |
return TrackDirectionToTrackdir(FindFirstTrack(v->u.ship.state), v->direction); |
1959 | 1662 |
|
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
|
1663 |
case VEH_ROAD: |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1664 |
if (v->IsInDepot()) // We'll assume the road vehicle is facing outwards |
10645 | 1665 |
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
|
1666 |
|
9574 | 1667 |
if (IsStandardRoadStopTile(v->tile)) // We'll assume the road vehicle is facing outwards |
10645 | 1668 |
return DiagDirToDiagTrackdir(GetRoadStopDir(v->tile)); // Road vehicle in a station |
1669 |
||
1670 |
if (IsDriveThroughStopTile(v->tile)) return DiagDirToDiagTrackdir(DirToDiagDir(v->direction)); |
|
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1671 |
|
4270
cfb529779a26
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
1672 |
/* 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
|
1673 |
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
|
1674 |
|
cfb529779a26
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
1675 |
/* Vehicle is turning around, get the direction from vehicle's direction */ |
10645 | 1676 |
return DiagDirToDiagTrackdir(DirToDiagDir(v->direction)); |
1959 | 1677 |
|
10294 | 1678 |
/* case VEH_AIRCRAFT: case VEH_EFFECT: 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
|
1679 |
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
|
1680 |
} |
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
1681 |
} |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6206
diff
changeset
|
1682 |
|
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6206
diff
changeset
|
1683 |
/** |
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6206
diff
changeset
|
1684 |
* Returns some meta-data over the to be entered tile. |
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6206
diff
changeset
|
1685 |
* @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
|
1686 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1687 |
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
|
1688 |
{ |
3657 | 1689 |
return _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y); |
0 | 1690 |
} |
1691 |
||
9624 | 1692 |
UnitID GetFreeUnitNumber(VehicleType type) |
0 | 1693 |
{ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1694 |
UnitID 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
|
1695 |
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
|
1696 |
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
|
1697 |
static UnitID gmax = 0; |
0 | 1698 |
|
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
|
1699 |
switch (type) { |
10776 | 1700 |
case VEH_TRAIN: max = _settings_game.vehicle.max_trains; break; |
1701 |
case VEH_ROAD: max = _settings_game.vehicle.max_roadveh; break; |
|
1702 |
case VEH_SHIP: max = _settings_game.vehicle.max_ships; break; |
|
1703 |
case VEH_AIRCRAFT: max = _settings_game.vehicle.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
|
1704 |
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
|
1705 |
} |
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
|
1706 |
|
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
|
1707 |
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
|
1708 |
/* 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
|
1709 |
* 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
|
1710 |
* 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
|
1711 |
*/ |
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
|
1712 |
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
|
1713 |
} |
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
|
1714 |
|
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
|
1715 |
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
|
1716 |
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
|
1717 |
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
|
1718 |
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
|
1719 |
} |
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
|
1720 |
|
9574 | 1721 |
/* 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
|
1722 |
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
|
1723 |
|
9574 | 1724 |
/* Fill the cache */ |
0 | 1725 |
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
|
1726 |
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
|
1727 |
cache[u->unitnumber] = true; |
0 | 1728 |
} |
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
|
1729 |
|
9574 | 1730 |
/* Find the first unused unit number */ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1731 |
UnitID unit = 1; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
1732 |
for (; unit <= max; unit++) { |
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
|
1733 |
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
|
1734 |
} |
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
|
1735 |
|
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
|
1736 |
return unit; |
0 | 1737 |
} |
1738 |
||
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1739 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1740 |
/** |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1741 |
* Check whether we can build infrastructure for the given |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1742 |
* vehicle type. This to disable building stations etc. when |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1743 |
* 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
|
1744 |
* @param type the vehicle type to check this for |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1745 |
* @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
|
1746 |
* the infrastructure for the given vehicle type |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1747 |
*/ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1748 |
bool CanBuildVehicleInfrastructure(VehicleType type) |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1749 |
{ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1750 |
assert(IsPlayerBuildableVehicleType(type)); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1751 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1752 |
if (!IsValidPlayer(_current_player)) return false; |
10776 | 1753 |
if (_settings_client.gui.always_build_infrastructure) return true; |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1754 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1755 |
UnitID max; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1756 |
switch (type) { |
10776 | 1757 |
case VEH_TRAIN: max = _settings_game.vehicle.max_trains; break; |
1758 |
case VEH_ROAD: max = _settings_game.vehicle.max_roadveh; break; |
|
1759 |
case VEH_SHIP: max = _settings_game.vehicle.max_ships; break; |
|
1760 |
case VEH_AIRCRAFT: max = _settings_game.vehicle.max_aircraft; break; |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1761 |
default: NOT_REACHED(); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1762 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1763 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1764 |
/* 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
|
1765 |
if (max > 0) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1766 |
/* Can we actually build the vehicle type? */ |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
1767 |
const Engine *e; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
1768 |
FOR_ALL_ENGINES_OF_TYPE(e, type) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
1769 |
if (HasBit(e->player_avail, _local_player)) return true; |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1770 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1771 |
return false; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1772 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1773 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1774 |
/* 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
|
1775 |
const Vehicle *v; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1776 |
FOR_ALL_VEHICLES(v) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1777 |
if (v->owner == _local_player && v->type == type) return true; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1778 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1779 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1780 |
return false; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1781 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1782 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
1783 |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1784 |
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
|
1785 |
{ |
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
|
1786 |
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
|
1787 |
LiveryScheme scheme = LS_DEFAULT; |
5968
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
1788 |
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
|
1789 |
|
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
|
1790 |
/* 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
|
1791 |
* whether any _other_ liveries are in use. */ |
10776 | 1792 |
if (p->livery[LS_DEFAULT].in_use && (_settings_client.gui.liveries == 2 || (_settings_client.gui.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
|
1793 |
/* 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
|
1794 |
switch (GetEngine(engine_type)->type) { |
9624 | 1795 |
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
|
1796 |
case VEH_TRAIN: { |
6014 | 1797 |
const RailVehicleInfo *rvi = RailVehInfo(engine_type); |
1798 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1799 |
if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1800 |
if (rvi->railveh_type == RAILVEH_WAGON) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1801 |
if (!GetCargo(cargo_type)->is_freight) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1802 |
if (parent_engine_type == INVALID_ENGINE) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1803 |
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
|
1804 |
} else { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1805 |
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
|
1806 |
default: NOT_REACHED(); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1807 |
case EC_STEAM: scheme = LS_PASSENGER_WAGON_STEAM; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1808 |
case EC_DIESEL: scheme = LS_PASSENGER_WAGON_DIESEL; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1809 |
case EC_ELECTRIC: scheme = LS_PASSENGER_WAGON_ELECTRIC; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1810 |
case EC_MONORAIL: scheme = LS_PASSENGER_WAGON_MONORAIL; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1811 |
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
|
1812 |
} |
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
|
1813 |
} |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1814 |
} else { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1815 |
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
|
1816 |
} |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1817 |
} else { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1818 |
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
|
1819 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1820 |
switch (rvi->engclass) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1821 |
default: NOT_REACHED(); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1822 |
case EC_STEAM: scheme = LS_STEAM; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1823 |
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
|
1824 |
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
|
1825 |
case EC_MONORAIL: scheme = LS_MONORAIL; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1826 |
case EC_MAGLEV: scheme = LS_MAGLEV; break; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1827 |
} |
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
|
1828 |
} |
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
|
1829 |
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
|
1830 |
} |
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
|
1831 |
|
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
|
1832 |
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
|
1833 |
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
|
1834 |
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
|
1835 |
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
|
1836 |
/* Tram */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1837 |
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
|
1838 |
} else { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1839 |
/* Bus or truck */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1840 |
scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_BUS : LS_TRUCK; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1841 |
} |
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
|
1842 |
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
|
1843 |
} |
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
|
1844 |
|
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
|
1845 |
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
|
1846 |
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
|
1847 |
if (cargo_type == CT_INVALID) cargo_type = svi->cargo_type; |
9476 | 1848 |
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
|
1849 |
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
|
1850 |
} |
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
|
1851 |
|
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
|
1852 |
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
|
1853 |
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
|
1854 |
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
|
1855 |
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
|
1856 |
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
|
1857 |
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
|
1858 |
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
|
1859 |
} |
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
|
1860 |
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
|
1861 |
} |
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
|
1862 |
} |
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
|
1863 |
|
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
|
1864 |
/* 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
|
1865 |
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
|
1866 |
} |
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
|
1867 |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1868 |
return &p->livery[scheme]; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1869 |
} |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1870 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1871 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1872 |
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
|
1873 |
{ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1874 |
SpriteID map = (v != NULL) ? v->colormap : PAL_NONE; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1875 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1876 |
/* Return cached value if any */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1877 |
if (map != PAL_NONE) return map; |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1878 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1879 |
/* Check if we should use the colour map callback */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1880 |
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
|
1881 |
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
|
1882 |
/* 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
|
1883 |
* maps" which happens to be the failure action too... */ |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1884 |
if (callback != CALLBACK_FAILED && callback != 0xC000) { |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1885 |
map = GB(callback, 0, 14); |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1886 |
/* 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
|
1887 |
* map else it's returned as-is. */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1888 |
if (!HasBit(callback, 14)) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1889 |
/* Update cache */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1890 |
if (v != NULL) ((Vehicle*)v)->colormap = map; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1891 |
return map; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1892 |
} |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1893 |
} |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1894 |
} |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1895 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1896 |
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
|
1897 |
|
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
1898 |
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
|
1899 |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1900 |
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
|
1901 |
|
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1902 |
map += livery->colour1; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1903 |
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
|
1904 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1905 |
/* Update cache */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1906 |
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
|
1907 |
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
|
1908 |
} |
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
|
1909 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
1910 |
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
|
1911 |
{ |
5968
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
1912 |
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
|
1913 |
} |
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
1914 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
1915 |
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
|
1916 |
{ |
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
|
1917 |
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
|
1918 |
return GetEngineColourMap( |
9626 | 1919 |
(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
|
1920 |
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
|
1921 |
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
|
1922 |
} |
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
|
1923 |
|
5968
eecf6681445e
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5944
diff
changeset
|
1924 |
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
|
1925 |
} |
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
1926 |
|
9629 | 1927 |
static uint8 _cargo_days; |
1928 |
static uint16 _cargo_source; |
|
1929 |
static uint32 _cargo_source_xy; |
|
1930 |
static uint16 _cargo_count; |
|
1931 |
static uint16 _cargo_paid_for; |
|
1932 |
static Money _cargo_feeder_share; |
|
1933 |
static uint32 _cargo_loaded_at_xy; |
|
1934 |
||
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1935 |
/** |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1936 |
* 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
|
1937 |
* @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
|
1938 |
* @return the saveload description |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1939 |
*/ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1940 |
const SaveLoad *GetVehicleDescription(VehicleType vt) |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1941 |
{ |
9574 | 1942 |
/** Save and load of vehicles */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1943 |
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
|
1944 |
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
|
1945 |
|
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
|
1946 |
SLE_REF(Vehicle, next, REF_VEHICLE_OLD), |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1947 |
SLE_CONDVAR(Vehicle, name, SLE_NAME, 0, 83), |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1948 |
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
|
1949 |
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
|
1950 |
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
|
1951 |
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
|
1952 |
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
|
1953 |
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
|
1954 |
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
|
1955 |
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
|
1956 |
|
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
|
1957 |
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
|
1958 |
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
|
1959 |
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
|
1960 |
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
|
1961 |
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
|
1962 |
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
|
1963 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1964 |
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
|
1965 |
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
|
1966 |
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
|
1967 |
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
|
1968 |
|
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
|
1969 |
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
|
1970 |
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
|
1971 |
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
|
1972 |
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
|
1973 |
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
|
1974 |
|
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
|
1975 |
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
|
1976 |
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
|
1977 |
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
|
1978 |
|
9629 | 1979 |
SLE_VAR(Vehicle, cargo_type, SLE_UINT8), |
1980 |
SLE_CONDVAR(Vehicle, cargo_subtype, SLE_UINT8, 35, SL_MAX_VERSION), |
|
1981 |
SLEG_CONDVAR( _cargo_days, SLE_UINT8, 0, 67), |
|
1982 |
SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
|
1983 |
SLEG_CONDVAR( _cargo_source, SLE_UINT16, 7, 67), |
|
1984 |
SLEG_CONDVAR( _cargo_source_xy, SLE_UINT32, 44, 67), |
|
1985 |
SLE_VAR(Vehicle, cargo_cap, SLE_UINT16), |
|
1986 |
SLEG_CONDVAR( _cargo_count, SLE_UINT16, 0, 67), |
|
1987 |
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
|
1988 |
|
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
|
1989 |
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
|
1990 |
SLE_VAR(Vehicle, tick_counter, SLE_UINT8), |
9732 | 1991 |
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
|
1992 |
|
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
|
1993 |
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
|
1994 |
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
|
1995 |
|
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1996 |
/* 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
|
1997 |
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
|
1998 |
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
|
1999 |
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
|
2000 |
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
|
2001 |
|
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2002 |
/* 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
|
2003 |
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
|
2004 |
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
|
2005 |
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
|
2006 |
|
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
|
2007 |
/* 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
|
2008 |
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
|
2009 |
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
|
2010 |
|
9629 | 2011 |
/* Timetable in current order */ |
2012 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, wait_time), SLE_UINT16, 67, SL_MAX_VERSION), |
|
2013 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, travel_time), SLE_UINT16, 67, SL_MAX_VERSION), |
|
2014 |
||
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
|
2015 |
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
|
2016 |
|
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
|
2017 |
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
|
2018 |
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
|
2019 |
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
|
2020 |
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
|
2021 |
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
|
2022 |
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
|
2023 |
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
|
2024 |
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
|
2025 |
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
|
2026 |
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
|
2027 |
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
|
2028 |
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
|
2029 |
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
|
2030 |
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
|
2031 |
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
|
2032 |
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
|
2033 |
|
9629 | 2034 |
SLE_VAR(Vehicle, load_unload_time_rem, SLE_UINT16), |
2035 |
SLEG_CONDVAR( _cargo_paid_for, SLE_UINT16, 45, SL_MAX_VERSION), |
|
2036 |
SLE_CONDVAR(Vehicle, vehicle_flags, SLE_UINT8, 40, SL_MAX_VERSION), |
|
2037 |
||
2038 |
SLE_CONDVAR(Vehicle, profit_this_year, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), |
|
2039 |
SLE_CONDVAR(Vehicle, profit_this_year, SLE_INT64, 65, SL_MAX_VERSION), |
|
2040 |
SLE_CONDVAR(Vehicle, profit_last_year, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), |
|
2041 |
SLE_CONDVAR(Vehicle, profit_last_year, SLE_INT64, 65, SL_MAX_VERSION), |
|
2042 |
SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_I32 | SLE_VAR_I64,51, 64), |
|
2043 |
SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, 65, 67), |
|
2044 |
SLEG_CONDVAR( _cargo_loaded_at_xy, SLE_UINT32, 51, 67), |
|
2045 |
SLE_CONDVAR(Vehicle, value, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), |
|
2046 |
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
|
2047 |
|
9732 | 2048 |
SLE_CONDVAR(Vehicle, random_bits, SLE_UINT8, 2, SL_MAX_VERSION), |
2049 |
SLE_CONDVAR(Vehicle, waiting_triggers, SLE_UINT8, 2, SL_MAX_VERSION), |
|
2050 |
||
2051 |
SLE_CONDREF(Vehicle, next_shared, REF_VEHICLE, 2, SL_MAX_VERSION), |
|
2052 |
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
|
2053 |
|
9624 | 2054 |
SLE_CONDVAR(Vehicle, group_id, SLE_UINT16, 60, SL_MAX_VERSION), |
2055 |
||
9629 | 2056 |
SLE_CONDVAR(Vehicle, current_order_time, SLE_UINT32, 67, SL_MAX_VERSION), |
2057 |
SLE_CONDVAR(Vehicle, lateness_counter, SLE_INT32, 67, SL_MAX_VERSION), |
|
2058 |
||
9574 | 2059 |
/* 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
|
2060 |
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
|
2061 |
|
0 | 2062 |
SLE_END() |
2063 |
}; |
|
2064 |
||
2065 |
||
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
|
2066 |
static const SaveLoad _train_desc[] = { |
9626 | 2067 |
SLE_WRITEBYTE(Vehicle, type, VEH_TRAIN), |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2068 |
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
|
2069 |
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
|
2070 |
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
|
2071 |
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
|
2072 |
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
|
2073 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2074 |
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
|
2075 |
SLE_CONDNULL(2, 2, 59), |
0 | 2076 |
|
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
|
2077 |
SLE_CONDNULL(2, 2, 19), |
9574 | 2078 |
/* 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
|
2079 |
SLE_CONDNULL(11, 2, SL_MAX_VERSION), |
0 | 2080 |
|
2081 |
SLE_END() |
|
2082 |
}; |
|
2083 |
||
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
|
2084 |
static const SaveLoad _roadveh_desc[] = { |
9626 | 2085 |
SLE_WRITEBYTE(Vehicle, type, VEH_ROAD), |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2086 |
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
|
2087 |
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
|
2088 |
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
|
2089 |
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
|
2090 |
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
|
2091 |
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
|
2092 |
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
|
2093 |
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
|
2094 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2095 |
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
|
2096 |
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
|
2097 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, slot_age), SLE_UINT8, 6, SL_MAX_VERSION), |
9574 | 2098 |
/* 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
|
2099 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2100 |
|
2101 |
SLE_END() |
|
2102 |
}; |
|
2103 |
||
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
|
2104 |
static const SaveLoad _ship_desc[] = { |
9626 | 2105 |
SLE_WRITEBYTE(Vehicle, type, VEH_SHIP), |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2106 |
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
|
2107 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleShip, state), SLE_UINT8), |
0 | 2108 |
|
9574 | 2109 |
/* 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
|
2110 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2111 |
|
2112 |
SLE_END() |
|
2113 |
}; |
|
2114 |
||
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
|
2115 |
static const SaveLoad _aircraft_desc[] = { |
9626 | 2116 |
SLE_WRITEBYTE(Vehicle, type, VEH_AIRCRAFT), |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2117 |
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
|
2118 |
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
|
2119 |
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
|
2120 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2121 |
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
|
2122 |
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
|
2123 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2124 |
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
|
2125 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2126 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, previous_pos), SLE_UINT8, 2, SL_MAX_VERSION), |
0 | 2127 |
|
9574 | 2128 |
/* 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
|
2129 |
SLE_CONDNULL(15, 2, SL_MAX_VERSION), |
0 | 2130 |
|
2131 |
SLE_END() |
|
2132 |
}; |
|
2133 |
||
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
|
2134 |
static const SaveLoad _special_desc[] = { |
10294 | 2135 |
SLE_WRITEBYTE(Vehicle, type, VEH_EFFECT), |
0 | 2136 |
|
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
|
2137 |
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
|
2138 |
|
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
|
2139 |
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
|
2140 |
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
|
2141 |
|
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
|
2142 |
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
|
2143 |
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
|
2144 |
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
|
2145 |
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
|
2146 |
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
|
2147 |
|
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
|
2148 |
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
|
2149 |
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
|
2150 |
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
|
2151 |
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
|
2152 |
|
10294 | 2153 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleEffect, animation_state), SLE_UINT16), |
2154 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleEffect, animation_substate), SLE_UINT8), |
|
0 | 2155 |
|
9574 | 2156 |
/* 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
|
2157 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2158 |
|
2159 |
SLE_END() |
|
2160 |
}; |
|
2161 |
||
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
|
2162 |
static const SaveLoad _disaster_desc[] = { |
9626 | 2163 |
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
|
2164 |
|
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
|
2165 |
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
|
2166 |
|
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
|
2167 |
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
|
2168 |
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
|
2169 |
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
|
2170 |
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
|
2171 |
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
|
2172 |
|
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
|
2173 |
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
|
2174 |
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
|
2175 |
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
|
2176 |
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
|
2177 |
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
|
2178 |
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
|
2179 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2180 |
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
|
2181 |
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
|
2182 |
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
|
2183 |
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
|
2184 |
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
|
2185 |
|
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
|
2186 |
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
|
2187 |
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
|
2188 |
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
|
2189 |
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
|
2190 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2191 |
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
|
2192 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleDisaster, big_ufo_destroyer_target), SLE_UINT16), |
0 | 2193 |
|
9574 | 2194 |
/* 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
|
2195 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2196 |
|
2197 |
SLE_END() |
|
2198 |
}; |
|
2199 |
||
2200 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2201 |
static const SaveLoad *_veh_descs[] = { |
0 | 2202 |
_train_desc, |
2203 |
_roadveh_desc, |
|
2204 |
_ship_desc, |
|
2205 |
_aircraft_desc, |
|
2206 |
_special_desc, |
|
2207 |
_disaster_desc, |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2208 |
_common_veh_desc, |
0 | 2209 |
}; |
2210 |
||
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2211 |
return _veh_descs[vt]; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2212 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2213 |
|
9574 | 2214 |
/** Will be called when the vehicles need to be saved. */ |
6573 | 2215 |
static void Save_VEHS() |
0 | 2216 |
{ |
2217 |
Vehicle *v; |
|
9574 | 2218 |
/* Write the vehicles */ |
0 | 2219 |
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
|
2220 |
SlSetArrayIndex(v->index); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2221 |
SlObject(v, GetVehicleDescription(v->type)); |
0 | 2222 |
} |
2223 |
} |
|
2224 |
||
9574 | 2225 |
/** Will be called when vehicles need to be loaded. */ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2226 |
void Load_VEHS() |
0 | 2227 |
{ |
2228 |
int index; |
|
2229 |
Vehicle *v; |
|
2230 |
||
9629 | 2231 |
_cargo_count = 0; |
2232 |
||
0 | 2233 |
while ((index = SlIterateArray()) != -1) { |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2234 |
Vehicle *v; |
9626 | 2235 |
VehicleType vtype = (VehicleType)SlReadByte(); |
9629 | 2236 |
|
2237 |
switch (vtype) { |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2238 |
case VEH_TRAIN: v = new (index) Train(); break; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2239 |
case VEH_ROAD: v = new (index) RoadVehicle(); break; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2240 |
case VEH_SHIP: v = new (index) Ship(); break; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2241 |
case VEH_AIRCRAFT: v = new (index) Aircraft(); break; |
10294 | 2242 |
case VEH_EFFECT: v = new (index) EffectVehicle(); break; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2243 |
case VEH_DISASTER: v = new (index) DisasterVehicle(); break; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2244 |
case VEH_INVALID: v = new (index) InvalidVehicle(); break; |
9624 | 2245 |
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
|
2246 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2247 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2248 |
SlObject(v, GetVehicleDescription(vtype)); |
9629 | 2249 |
|
2250 |
if (_cargo_count != 0 && IsPlayerBuildableVehicleType(v)) { |
|
2251 |
/* Don't construct the packet with station here, because that'll fail with old savegames */ |
|
2252 |
CargoPacket *cp = new CargoPacket(); |
|
2253 |
cp->source = _cargo_source; |
|
2254 |
cp->source_xy = _cargo_source_xy; |
|
2255 |
cp->count = _cargo_count; |
|
2256 |
cp->days_in_transit = _cargo_days; |
|
2257 |
cp->feeder_share = _cargo_feeder_share; |
|
2258 |
cp->loaded_at_xy = _cargo_loaded_at_xy; |
|
2259 |
v->cargo.Append(cp); |
|
2260 |
} |
|
2261 |
||
2549 | 2262 |
/* 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
|
2263 |
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
|
2264 |
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
|
2265 |
|
2685
00111d5ca47f
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
2266 |
if (CheckSavegameVersion(5)) { |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2267 |
/* 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
|
2268 |
* in those versions, they both were 4 bits big) to type and flags */ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2269 |
v->current_order.flags = GB(v->current_order.type, 4, 4); |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2270 |
v->current_order.type &= 0x0F; |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2271 |
} |
9624 | 2272 |
|
2273 |
/* Advanced vehicle lists got added */ |
|
2274 |
if (CheckSavegameVersion(60)) v->group_id = DEFAULT_GROUP; |
|
0 | 2275 |
} |
2276 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2277 |
/* 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
|
2278 |
if (CheckSavegameVersionOldStyle(5, 2)) { |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2279 |
FOR_ALL_VEHICLES(v) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2280 |
Vehicle *u; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2281 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2282 |
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
|
2283 |
/* 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
|
2284 |
* in both vehicles */ |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2285 |
if (v->orders == u->orders) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2286 |
v->next_shared = u; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2287 |
u->prev_shared = v; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2288 |
break; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2289 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2290 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2291 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2292 |
} |
0 | 2293 |
} |
2294 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2295 |
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
|
2296 |
{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY | CH_LAST}, |
0 | 2297 |
}; |
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
|
2298 |
|
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
|
2299 |
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
|
2300 |
{ |
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
|
2301 |
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
|
2302 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2303 |
if (this->current_order.IsType(OT_GOTO_STATION) && |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2304 |
this->current_order.GetDestination() == this->last_station_visited) { |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2305 |
current_order.MakeLoading(true); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2306 |
UpdateVehicleTimetable(this, true); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2307 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2308 |
/* 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
|
2309 |
* 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
|
2310 |
* 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
|
2311 |
* 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
|
2312 |
* that arrives at random stations is bad. */ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2313 |
this->current_order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2314 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2315 |
} else { |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2316 |
current_order.MakeLoading(false); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2317 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2318 |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2319 |
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
|
2320 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2321 |
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
|
2322 |
|
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2323 |
InvalidateWindow(GetWindowClassForVehicleType(this->type), this->owner); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2324 |
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
|
2325 |
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
|
2326 |
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
|
2327 |
|
9626 | 2328 |
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
|
2329 |
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
|
2330 |
} |
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
|
2331 |
|
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
|
2332 |
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
|
2333 |
{ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2334 |
assert(current_order.IsType(OT_LOADING)); |
9629 | 2335 |
|
2336 |
/* Only update the timetable if the vehicle was supposed to stop here. */ |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2337 |
if (current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE) UpdateVehicleTimetable(this, false); |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2338 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2339 |
current_order.MakeLeaveStation(); |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2340 |
Station *st = GetStation(this->last_station_visited); |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2341 |
st->loading_vehicles.remove(this); |
9629 | 2342 |
|
2343 |
HideFillingPercent(this->fill_percent_te_id); |
|
2344 |
this->fill_percent_te_id = INVALID_TE_ID; |
|
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2345 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2346 |
/* Trigger station animation for trains only */ |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2347 |
if (this->type == VEH_TRAIN && IsTileType(this->tile, MP_STATION)) StationAnimationTrigger(st, this->tile, STAT_ANIM_TRAIN_DEPARTS); |
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
|
2348 |
} |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2349 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2350 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2351 |
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
|
2352 |
{ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2353 |
switch (this->current_order.GetType()) { |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2354 |
case OT_LOADING: { |
9629 | 2355 |
uint wait_time = max(this->current_order.wait_time - this->lateness_counter, 0); |
2356 |
||
9624 | 2357 |
/* 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
|
2358 |
if (mode || !HasBit(this->vehicle_flags, VF_LOADING_FINISHED) || |
10776 | 2359 |
(_settings_game.order.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
|
2360 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2361 |
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
|
2362 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2363 |
bool at_destination_station = this->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE; |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2364 |
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
|
2365 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2366 |
/* If this was not the final order, don't remove it from the list. */ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2367 |
if (!at_destination_station) 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
|
2368 |
break; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2369 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2370 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2371 |
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
|
2372 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2373 |
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
|
2374 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2375 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2376 |
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
|
2377 |
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
|
2378 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2379 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2380 |
CommandCost Vehicle::SendToDepot(uint32 flags, DepotCommand command) |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2381 |
{ |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2382 |
if (!CheckOwnership(this->owner)) return CMD_ERROR; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2383 |
if (this->vehstatus & VS_CRASHED) return CMD_ERROR; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2384 |
if (this->IsInDepot()) return CMD_ERROR; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2385 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2386 |
if (this->current_order.IsType(OT_GOTO_DEPOT)) { |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2387 |
bool halt_in_depot = this->current_order.GetDepotActionType() & ODATFB_HALT; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2388 |
if (!!(command & DEPOT_SERVICE) == halt_in_depot) { |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2389 |
/* We called with a different DEPOT_SERVICE setting. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2390 |
* Now we change the setting to apply the new one and let the vehicle head for the same depot. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2391 |
* Note: the if is (true for requesting service == true for ordered to stop in depot) */ |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2392 |
if (flags & DC_EXEC) { |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2393 |
this->current_order.SetDepotOrderType(ODTF_MANUAL); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2394 |
this->current_order.SetDepotActionType(halt_in_depot ? ODATF_SERVICE_ONLY : ODATFB_HALT); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2395 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2396 |
} |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2397 |
return CommandCost(); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2398 |
} |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2399 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2400 |
if (command & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2401 |
if (flags & DC_EXEC) { |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2402 |
/* If the orders to 'goto depot' are in the orders list (forced servicing), |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2403 |
* then skip to the next order; effectively cancelling this forced service */ |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2404 |
if (this->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) this->cur_order_index++; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2405 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2406 |
this->current_order.MakeDummy(); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2407 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2408 |
} |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2409 |
return CommandCost(); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2410 |
} |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2411 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2412 |
/* check if at a standstill (not stopped only) in a depot |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2413 |
* the check is down here to make it possible to alter stop/service for trains entering the depot */ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2414 |
if (this->type == VEH_TRAIN && IsRailDepotTile(this->tile) && this->cur_speed == 0) return CMD_ERROR; |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2415 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2416 |
TileIndex location; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2417 |
DestinationID destination; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2418 |
bool reverse; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2419 |
static const StringID no_depot[] = {STR_883A_UNABLE_TO_FIND_ROUTE_TO, STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT, STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT, STR_A012_CAN_T_SEND_AIRCRAFT_TO}; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2420 |
if (!this->FindClosestDepot(&location, &destination, &reverse)) return_cmd_error(no_depot[this->type]); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2421 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2422 |
if (flags & DC_EXEC) { |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2423 |
if (this->current_order.IsType(OT_LOADING)) this->LeaveStation(); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2424 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2425 |
this->dest_tile = location; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2426 |
this->current_order.MakeGoToDepot(destination, ODTF_MANUAL); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2427 |
if (!(command & DEPOT_SERVICE)) this->current_order.SetDepotActionType(ODATFB_HALT); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2428 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2429 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2430 |
/* If there is no depot in front, reverse automatically (trains only) */ |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2431 |
if (this->type == VEH_TRAIN && reverse) DoCommand(this->tile, this->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2432 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2433 |
if (this->type == VEH_AIRCRAFT && this->u.air.state == FLYING && this->u.air.targetairport != destination) { |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2434 |
/* The aircraft is now heading for a different hangar than the next in the orders */ |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2435 |
extern void AircraftNextAirportPos_and_Order(Vehicle *v); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2436 |
AircraftNextAirportPos_and_Order(this); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2437 |
} |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2438 |
} |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2439 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2440 |
return CommandCost(); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2441 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2442 |
} |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
2443 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2444 |
void Vehicle::SetNext(Vehicle *next) |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2445 |
{ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2446 |
if (this->next != NULL) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2447 |
/* 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
|
2448 |
for (Vehicle *v = this->next; v != NULL; v = v->Next()) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2449 |
v->first = this->next; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2450 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2451 |
this->next->previous = NULL; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2452 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2453 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2454 |
this->next = next; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2455 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2456 |
if (this->next != NULL) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2457 |
/* A new next vehicle. Update the first and previous pointers */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2458 |
if (this->next->previous != NULL) this->next->previous->next = NULL; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2459 |
this->next->previous = this; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2460 |
for (Vehicle *v = this->next; v != NULL; v = v->Next()) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2461 |
v->first = this->first; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2462 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2463 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2464 |
} |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
2465 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2466 |
/** Backs up a chain of vehicles |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2467 |
* @param v The vehicle to back up |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2468 |
*/ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2469 |
void BackuppedVehicle::BackupVehicle(Vehicle *v) |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2470 |
{ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2471 |
int length = CountVehiclesInChain(v); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2472 |
|
10513
33cb70ff2f5d
(svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents:
10455
diff
changeset
|
2473 |
size_t cargo_packages_count = 1; |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2474 |
for (const Vehicle *v_count = v; v_count != NULL; v_count=v_count->Next()) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2475 |
/* Now we count how many cargo packets we need to store. |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2476 |
* We started with an offset by one because we also need an end of array marker. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2477 |
cargo_packages_count += v_count->cargo.packets.size(); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2478 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2479 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2480 |
vehicles = MallocT<Vehicle>(length); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2481 |
cargo_packets = MallocT<CargoPacket>(cargo_packages_count); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2482 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2483 |
/* Now we make some pointers to iterate over the arrays. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2484 |
Vehicle *copy = vehicles; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2485 |
CargoPacket *cargo = cargo_packets; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2486 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2487 |
Vehicle *original = v; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2488 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2489 |
for (; 0 < length; original = original->Next(), copy++, length--) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2490 |
/* First we need to copy the vehicle itself. |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2491 |
* However there is an issue as the cargo list isn't copied. |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2492 |
* To avoid restoring invalid pointers we start by swapping the cargo list with an empty one. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2493 |
CargoList::List empty_packets; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2494 |
original->cargo.packets.swap(empty_packets); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2495 |
memcpy(copy, original, sizeof(Vehicle)); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2496 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2497 |
/* No need to do anything else if the cargo list is empty. |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2498 |
* It really doesn't matter if we swap an empty list with an empty list. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2499 |
if (original->cargo.Empty()) continue; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2500 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2501 |
/* And now we swap the cargo lists back. The vehicle now has it's cargo again. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2502 |
original->cargo.packets.swap(empty_packets); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2503 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2504 |
/* The vehicle contains some cargo so we will back up the cargo as well. |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2505 |
* We only need to store the packets and not which vehicle they came from. |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2506 |
* We will still be able to put them together with the right vehicle when restoring. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2507 |
const CargoList::List *packets = original->cargo.Packets(); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2508 |
for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2509 |
memcpy(cargo, (*it), sizeof(CargoPacket)); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2510 |
cargo++; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2511 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2512 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2513 |
/* We should end with a 0 packet so restoring can detect the end of the array. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2514 |
memset(cargo, 0, sizeof(CargoPacket)); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2515 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2516 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2517 |
/** Restore a backed up row of vehicles |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2518 |
* @param *v The array of vehicles to restore |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2519 |
* @param *p The owner of the vehicle |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2520 |
*/ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2521 |
Vehicle* BackuppedVehicle::RestoreBackupVehicle(Vehicle *v, Player *p) |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2522 |
{ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2523 |
Vehicle *backup = v; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2524 |
CargoPacket *cargo = cargo_packets; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2525 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2526 |
assert(v->owner == p->index); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2527 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2528 |
/* Cache the result of the vehicle type check since it will not change |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2529 |
* and we need this check once for every run though the loop. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2530 |
bool is_road_veh = v->type == VEH_ROAD; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2531 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2532 |
while (true) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2533 |
Vehicle *dest = GetVehicle(backup->index); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2534 |
/* The vehicle should be free since we are restoring something we just sold. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2535 |
assert(!dest->IsValid()); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2536 |
memcpy(dest, backup, sizeof(Vehicle)); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2537 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2538 |
/* We decreased the engine count when we sold the engines so we will increase it again. */ |
10645 | 2539 |
if (IsEngineCountable(backup)) { |
2540 |
p->num_engines[backup->engine_type]++; |
|
2541 |
if (IsValidGroupID(backup->group_id)) GetGroup(backup->group_id)->num_engines[backup->engine_type]++; |
|
2542 |
if (backup->IsPrimaryVehicle()) IncreaseGroupNumVehicle(backup->group_id); |
|
2543 |
} |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2544 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2545 |
/* Update hash. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2546 |
Vehicle *dummy = dest; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2547 |
dest->old_new_hash = &dummy; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2548 |
dest->left_coord = INVALID_COORD; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2549 |
UpdateVehiclePosHash(dest, INVALID_COORD, 0); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2550 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2551 |
if (is_road_veh) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2552 |
/* Removed the slot in the road vehicles as the slot is gone. |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2553 |
* We don't want a pointer to a slot that's gone. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2554 |
dest->u.road.slot = NULL; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2555 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2556 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2557 |
if (!dest->cargo.Empty()) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2558 |
/* The vehicle in question contains some cargo. |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2559 |
* However we lost the list so we will have to recreate it. |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2560 |
* We know that the packets are stored in the same order as the vehicles so |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2561 |
* the one cargo_packets points to and maybe some following ones belongs to |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2562 |
* the current vehicle. |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2563 |
* Now all we have to do is to add the packets to a list and keep track of how |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2564 |
* much cargo we restore and once we reached the cached cargo hold we recovered |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2565 |
* everything for this vehicle. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2566 |
uint cargo_count = 0; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2567 |
for(; cargo_count < dest->cargo.Count(); cargo++) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2568 |
dest->cargo.packets.push_back(GetCargoPacket(cargo->index)); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2569 |
cargo_count += cargo->count; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2570 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2571 |
/* This design should always end up with the right amount of cargo. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2572 |
assert(cargo_count == dest->cargo.Count()); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2573 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2574 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2575 |
if (backup->Next() == NULL) break; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2576 |
backup++; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2577 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2578 |
return GetVehicle(v->index); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2579 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2580 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2581 |
/** Restores a backed up vehicle |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2582 |
* @param *v A vehicle we should sell and take the windows from (NULL for not using this) |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2583 |
* @param *p The owner of the vehicle |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2584 |
* @return The vehicle we restored (front for trains) or v if we didn't have anything to restore |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2585 |
*/ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2586 |
Vehicle *BackuppedVehicle::Restore(Vehicle *v, Player *p) |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2587 |
{ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2588 |
if (!ContainsBackup()) return v; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2589 |
if (v != NULL) { |
10645 | 2590 |
ChangeVehicleViewWindow(v->index, INVALID_VEHICLE); |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2591 |
DoCommand(0, v->index, 1, DC_EXEC, GetCmdSellVeh(v)); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2592 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2593 |
v = RestoreBackupVehicle(this->vehicles, p); |
10645 | 2594 |
ChangeVehicleViewWindow(INVALID_VEHICLE, v->index); |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2595 |
if (orders != NULL) RestoreVehicleOrdersBruteForce(v, orders); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2596 |
if (economy != NULL) economy->Restore(); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2597 |
/* If we stored cargo as well then we should restore it. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2598 |
cargo_packets->RestoreBackup(); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2599 |
return v; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2600 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2601 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2602 |
/** Backs up a vehicle |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2603 |
* This should never be called when the object already contains a backup |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2604 |
* @param v the vehicle to backup |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2605 |
* @param p If it's set to the vehicle's owner then economy is backed up. If NULL then economy backup will be skipped. |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2606 |
*/ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2607 |
void BackuppedVehicle::Backup(Vehicle *v, Player *p) |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2608 |
{ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2609 |
assert(!ContainsBackup()); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2610 |
if (p != NULL) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2611 |
assert(p->index == v->owner); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2612 |
economy = new PlayerMoneyBackup(p); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2613 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2614 |
BackupVehicle(v); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2615 |
if (orders != NULL) BackupVehicleOrders(v, orders); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2616 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10370
diff
changeset
|
2617 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2618 |
void StopAllVehicles() |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2619 |
{ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2620 |
Vehicle *v; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2621 |
FOR_ALL_VEHICLES(v) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2622 |
/* Code ripped from CmdStartStopTrain. Can't call it, because of |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2623 |
* ownership problems, so we'll duplicate some code, for now */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2624 |
v->vehstatus |= VS_STOPPED; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2625 |
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
|
2626 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2627 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2628 |
} |