src/vehicle.cpp
author rubidium
Thu, 26 Jul 2007 15:37:19 +0000
changeset 7334 ed9a43cf642a
parent 7333 e48228e44be8
child 7351 7cd3e98e8296
permissions -rw-r--r--
(svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
     3
/** @file vehicle.cpp */
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
3957
25f4a4f22e05 (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
48f178431701 (svn r5118) Add IsRoadVehInDepot{Stopped,}()
tron
parents: 3957
diff changeset
     8
#include "roadveh.h"
3961
9868b766fda7 (svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents: 3959
diff changeset
     9
#include "ship.h"
1349
15979a2e9001 (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"
1364
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
    11
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 445
diff changeset
    12
#include "table/strings.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2148
diff changeset
    13
#include "functions.h"
6453
226bcddeba32 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6444
diff changeset
    14
#include "landscape.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 593
diff changeset
    15
#include "map.h"
1209
2e00193652b2 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1192
diff changeset
    16
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "vehicle.h"
6980
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
    18
#include "timetable.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
#include "engine.h"
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 260
diff changeset
    26
#include "sound.h"
1601
83fbe3bfb847 (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
    27
#include "debug.h"
1752
d65cd19f7117 (svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents: 1735
diff changeset
    28
#include "vehicle_gui.h"
1758
2158a0938e45 (svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents: 1757
diff changeset
    29
#include "depot.h"
2158a0938e45 (svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents: 1757
diff changeset
    30
#include "station.h"
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1926
diff changeset
    31
#include "rail.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2666
diff changeset
    32
#include "train.h"
4662
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
    33
#include "aircraft.h"
3428
146dc5f172fc (svn r4256) - Codechange: Replace lone map access in vehicle.c with its map accessor.
peter1138
parents: 3422
diff changeset
    34
#include "industry_map.h"
3404
eb8ebfe5df67 (svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents: 3393
diff changeset
    35
#include "station_map.h"
3957
25f4a4f22e05 (svn r5116) Move the overly generic GetDepotDirection() from a header to its only consumer
tron
parents: 3953
diff changeset
    36
#include "water_map.h"
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5380
diff changeset
    37
#include "network/network.h"
4130
fd86f49a1e96 (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
    38
#include "yapf/yapf.h"
4261
28670f743746 (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4176
diff changeset
    39
#include "date.h"
5717
b6fb89cd9cce (svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents: 5693
diff changeset
    40
#include "newgrf_callbacks.h"
4603
20c816f664de (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
    41
#include "newgrf_engine.h"
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4648
diff changeset
    42
#include "newgrf_sound.h"
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    43
#include "helpers.hpp"
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
    44
#include "group.h"
6565
96ef0ede4b83 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents: 6562
diff changeset
    45
#include "economy.h"
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
    46
#include "strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
6904
cc02894b3cce (svn r10153) -Fix [FS#869]: vehicles disappear when crossing certain tiles. Fix by B. N. SmatZ!.
rubidium
parents: 6886
diff changeset
    48
#define INVALID_COORD (0x7fffffff)
4174
0b13c25586f7 (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
    49
#define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
5792
c4dad358b30b (svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents: 5763
diff changeset
    51
c4dad358b30b (svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents: 5763
diff changeset
    52
/* Tables used in vehicle.h to find the right command for a certain vehicle type */
c4dad358b30b (svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents: 5763
diff changeset
    53
const uint32 _veh_build_proc_table[] = {
2552
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    54
	CMD_BUILD_RAIL_VEHICLE,
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    55
	CMD_BUILD_ROAD_VEH,
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    56
	CMD_BUILD_SHIP,
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    57
	CMD_BUILD_AIRCRAFT,
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    58
};
5792
c4dad358b30b (svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents: 5763
diff changeset
    59
const uint32 _veh_sell_proc_table[] = {
2552
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    60
	CMD_SELL_RAIL_WAGON,
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    61
	CMD_SELL_ROAD_VEH,
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    62
	CMD_SELL_SHIP,
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    63
	CMD_SELL_AIRCRAFT,
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    64
};
2753
b25bd313785e (svn r3298) Remove unused and write-only variables
tron
parents: 2752
diff changeset
    65
5792
c4dad358b30b (svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents: 5763
diff changeset
    66
const uint32 _veh_refit_proc_table[] = {
2552
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    67
	CMD_REFIT_RAIL_VEHICLE,
3990
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3973
diff changeset
    68
	CMD_REFIT_ROAD_VEH,
2552
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    69
	CMD_REFIT_SHIP,
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    70
	CMD_REFIT_AIRCRAFT,
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    71
};
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    72
4451
2e86da0081b5 (svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents: 4434
diff changeset
    73
const uint32 _send_to_depot_proc_table[] = {
4495
b6381e4bcb61 (svn r6280) -Codechange: Use the same naming for trains as for other vehicles:
Darkvater
parents: 4465
diff changeset
    74
	CMD_SEND_TRAIN_TO_DEPOT,
4451
2e86da0081b5 (svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents: 4434
diff changeset
    75
	CMD_SEND_ROADVEH_TO_DEPOT,
2e86da0081b5 (svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents: 4434
diff changeset
    76
	CMD_SEND_SHIP_TO_DEPOT,
2e86da0081b5 (svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents: 4434
diff changeset
    77
	CMD_SEND_AIRCRAFT_TO_HANGAR,
2e86da0081b5 (svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents: 4434
diff changeset
    78
};
2e86da0081b5 (svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents: 4434
diff changeset
    79
2552
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    80
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
    81
enum {
3173
f56ca618721b (svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents: 3161
diff changeset
    82
	BLOCKS_FOR_SPECIAL_VEHICLES   = 2, ///< Blocks needed for special vehicles
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
    83
};
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
    84
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
    85
/**
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
    86
 * Called if a new block is added to the vehicle-pool
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
    87
 */
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
    88
static void VehiclePoolNewBlock(uint start_item)
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
    89
{
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
    90
	Vehicle *v;
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
    91
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    92
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    93
	 * TODO - This is just a temporary stage, this will be removed. */
5955
fe61588d5188 (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: 5944
diff changeset
    94
	for (v = GetVehicle(start_item); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) {
fe61588d5188 (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: 5944
diff changeset
    95
		v->index = start_item++;
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
    96
		v = new (v) InvalidVehicle();
5955
fe61588d5188 (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: 5944
diff changeset
    97
	}
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
    98
}
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
    99
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   100
/* Initialize the vehicle-pool */
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 5211
diff changeset
   101
DEFINE_OLD_POOL(Vehicle, Vehicle, VehiclePoolNewBlock, NULL)
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   102
578
1e66514eb621 (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
   103
void VehicleServiceInDepot(Vehicle *v)
1e66514eb621 (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
   104
{
1e66514eb621 (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
   105
	v->date_of_last_service = _date;
1e66514eb621 (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
   106
	v->breakdowns_since_last_service = 0;
1926
530480d14685 (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1922
diff changeset
   107
	v->reliability = GetEngine(v->engine_type)->reliability;
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
   108
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated
578
1e66514eb621 (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
   109
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
593
4240f624bca0 (svn r1015) MFM r789
tron
parents: 588
diff changeset
   111
bool VehicleNeedsService(const Vehicle *v)
4240f624bca0 (svn r1015) MFM r789
tron
parents: 588
diff changeset
   112
{
1757
89f63a75ffd2 (svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents: 1752
diff changeset
   113
	if (v->vehstatus & VS_CRASHED)
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   114
		return false; // Crashed vehicles don't need service anymore
1757
89f63a75ffd2 (svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents: 1752
diff changeset
   115
4262
048f6a144c7c (svn r5888) -Fix: [autoreplace] if vehicles breakdowns and service are turned off, the vehicles failed to enter any depots
bjarni
parents: 4261
diff changeset
   116
	if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) {
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
   117
		return EngineHasReplacementForPlayer(GetPlayer(v->owner), v->engine_type, v->group_id);  /* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off */
4262
048f6a144c7c (svn r5888) -Fix: [autoreplace] if vehicles breakdowns and service are turned off, the vehicles failed to enter any depots
bjarni
parents: 4261
diff changeset
   118
	}
048f6a144c7c (svn r5888) -Fix: [autoreplace] if vehicles breakdowns and service are turned off, the vehicles failed to enter any depots
bjarni
parents: 4261
diff changeset
   119
812
65ecc321b3db (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
   120
	return _patches.servint_ispercent ?
1926
530480d14685 (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1922
diff changeset
   121
		(v->reliability < GetEngine(v->engine_type)->reliability * (100 - v->service_interval) / 100) :
593
4240f624bca0 (svn r1015) MFM r789
tron
parents: 588
diff changeset
   122
		(v->date_of_last_service + v->service_interval < _date);
4240f624bca0 (svn r1015) MFM r789
tron
parents: 588
diff changeset
   123
}
4240f624bca0 (svn r1015) MFM r789
tron
parents: 588
diff changeset
   124
3881
c899867fd46e (svn r4937) Reduce the use of _error_message a bit
tron
parents: 3819
diff changeset
   125
StringID VehicleInTheWayErrMsg(const Vehicle* v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
{
2631
2ed0eb408229 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
   127
	switch (v->type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   128
		case VEH_TRAIN:    return STR_8803_TRAIN_IN_THE_WAY;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   129
		case VEH_ROAD:     return STR_9000_ROAD_VEHICLE_IN_THE_WAY;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   130
		case VEH_AIRCRAFT: return STR_A015_AIRCRAFT_IN_THE_WAY;
3881
c899867fd46e (svn r4937) Reduce the use of _error_message a bit
tron
parents: 3819
diff changeset
   131
		default:           return STR_980E_SHIP_IN_THE_WAY;
2631
2ed0eb408229 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
   132
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
static void *EnsureNoVehicleProc(Vehicle *v, void *data)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
{
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   137
	if (v->tile != *(const TileIndex*)data || v->type == VEH_DISASTER)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
		return NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   139
3881
c899867fd46e (svn r4937) Reduce the use of _error_message a bit
tron
parents: 3819
diff changeset
   140
	_error_message = VehicleInTheWayErrMsg(v);
537
901bd4c077f0 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
   141
	return v;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   142
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
bool EnsureNoVehicle(TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
{
537
901bd4c077f0 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
   146
	return VehicleFromPos(tile, &tile, EnsureNoVehicleProc) == NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
static void *EnsureNoVehicleProcZ(Vehicle *v, void *data)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
{
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   151
	const TileInfo *ti = (const TileInfo*)data;
537
901bd4c077f0 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
   152
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   153
	if (v->tile != ti->tile || v->type == VEH_DISASTER) return NULL;
3794
f72053a38797 (svn r4790) Remove slope magic from EnsureNoVehicleZ() and rename it to EnsureNoVehicleOnGround() to make more clear what it does
tron
parents: 3679
diff changeset
   154
	if (v->z_pos > ti->z) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
3881
c899867fd46e (svn r4937) Reduce the use of _error_message a bit
tron
parents: 3819
diff changeset
   156
	_error_message = VehicleInTheWayErrMsg(v);
537
901bd4c077f0 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
   157
	return v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
1082
a83d7ac6fecb (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
   160
3794
f72053a38797 (svn r4790) Remove slope magic from EnsureNoVehicleZ() and rename it to EnsureNoVehicleOnGround() to make more clear what it does
tron
parents: 3679
diff changeset
   161
bool EnsureNoVehicleOnGround(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	TileInfo ti;
537
901bd4c077f0 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
   164
2871
1ac651552db5 (svn r3419) - Fix: [FS#40] (Possible) game crash on removing track/road under bridge. This was caused by a wrong tile-occupancy testing where it was assumed that a vehicle's height is only a multitude of 8 (a single height-difference). This is incorrect as a vehicle on a slope will assume all height levels between the lower-and upper-bounds. The crash is still possible as seen in the Flyspray bugreport but this has a different cause.
Darkvater
parents: 2855
diff changeset
   165
	ti.tile = tile;
3794
f72053a38797 (svn r4790) Remove slope magic from EnsureNoVehicleZ() and rename it to EnsureNoVehicleOnGround() to make more clear what it does
tron
parents: 3679
diff changeset
   166
	ti.z = GetTileMaxZ(tile);
537
901bd4c077f0 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
   167
	return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ) == NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
1605
279dd2265cae (svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents: 1601
diff changeset
   170
Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z)
279dd2265cae (svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents: 1601
diff changeset
   171
{
279dd2265cae (svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents: 1601
diff changeset
   172
	TileInfo ti;
279dd2265cae (svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents: 1601
diff changeset
   173
279dd2265cae (svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents: 1601
diff changeset
   174
	ti.tile = tile;
279dd2265cae (svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents: 1601
diff changeset
   175
	ti.z = z;
279dd2265cae (svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents: 1601
diff changeset
   176
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   177
	return (Vehicle*)VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ);
1605
279dd2265cae (svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents: 1601
diff changeset
   178
}
279dd2265cae (svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents: 1601
diff changeset
   179
5940
3bb99a7ad58f (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: 5888
diff changeset
   180
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z, bool without_crashed)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
{
926
a6d140a6a4de (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
   182
	int x1 = TileX(from);
a6d140a6a4de (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 y1 = TileY(from);
a6d140a6a4de (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 x2 = TileX(to);
a6d140a6a4de (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 y2 = TileY(to);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	Vehicle *veh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	/* Make sure x1 < x2 or y1 < y2 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	if (x1 > x2 || y1 > y2) {
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 6047
diff changeset
   190
		Swap(x1, x2);
2898cd9417fd (svn r8841) -Fix
tron
parents: 6047
diff changeset
   191
		Swap(y1, y2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	}
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   193
	FOR_ALL_VEHICLES(veh) {
5940
3bb99a7ad58f (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: 5888
diff changeset
   194
		if (without_crashed && (veh->vehstatus & VS_CRASHED) != 0) continue;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6490
diff changeset
   195
		if ((veh->type == VEH_TRAIN || veh->type == VEH_ROAD) && (z == 0xFF || veh->z_pos == z)) {
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6490
diff changeset
   196
			if ((veh->x_pos >> 4) >= x1 && (veh->x_pos >> 4) <= x2 &&
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6490
diff changeset
   197
					(veh->y_pos >> 4) >= y1 && (veh->y_pos >> 4) <= y2) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
				return veh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2814
diff changeset
   205
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2814
diff changeset
   206
static void UpdateVehiclePosHash(Vehicle* v, int x, int y);
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2814
diff changeset
   207
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
void VehiclePositionChanged(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
	int img = v->cur_image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos);
2319
fba7d61df04a (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2296
diff changeset
   212
	const Sprite* spr = GetSprite(img);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
2319
fba7d61df04a (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2296
diff changeset
   214
	pt.x += spr->x_offs;
fba7d61df04a (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2296
diff changeset
   215
	pt.y += spr->y_offs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
	UpdateVehiclePosHash(v, pt.x, pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
	v->left_coord = pt.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
	v->top_coord = pt.y;
2319
fba7d61df04a (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2296
diff changeset
   221
	v->right_coord = pt.x + spr->width + 2;
fba7d61df04a (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2296
diff changeset
   222
	v->bottom_coord = pt.y + spr->height + 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   225
/** Called after load to update coordinates */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6198
diff changeset
   226
void AfterLoadVehicles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	FOR_ALL_VEHICLES(v) {
6558
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
   231
		v->UpdateDeltaXY(v->direction);
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
   232
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
   233
		v->fill_percent_te_id = INVALID_TE_ID;
1601
83fbe3bfb847 (svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents: 1600
diff changeset
   234
		v->first = NULL;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   235
		if (v->type == VEH_TRAIN) v->u.rail.first_engine = INVALID_ENGINE;
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   236
		if (v->type == VEH_ROAD)  v->u.road.first_engine = INVALID_ENGINE;
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
   237
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
   238
		v->cargo.InvalidateCache();
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3326
diff changeset
   239
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3326
diff changeset
   240
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3326
diff changeset
   241
	FOR_ALL_VEHICLES(v) {
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   242
		if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) {
2994
38c63961334e (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
   243
			TrainConsistChanged(v);
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   244
		} else if (v->type == VEH_ROAD && IsRoadVehFront(v)) {
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   245
			RoadVehUpdateCache(v);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   246
		}
2994
38c63961334e (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
   247
	}
38c63961334e (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
   248
38c63961334e (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
   249
	FOR_ALL_VEHICLES(v) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   250
		switch (v->type) {
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6665
diff changeset
   251
			case VEH_ROAD:
6685
00490513d7b1 (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents: 6683
diff changeset
   252
				v->u.road.roadtype = HASBIT(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6665
diff changeset
   253
				v->u.road.compatible_roadtypes = RoadTypeToRoadTypes(v->u.road.roadtype);
7134
5b2d47128d05 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7108
diff changeset
   254
				/* FALL THROUGH */
5b2d47128d05 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7108
diff changeset
   255
			case VEH_TRAIN:
5b2d47128d05 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7108
diff changeset
   256
			case VEH_SHIP:
5b2d47128d05 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7108
diff changeset
   257
				v->cur_image = v->GetImage(v->direction);
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6665
diff changeset
   258
				break;
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6665
diff changeset
   259
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   260
			case VEH_AIRCRAFT:
5854
9eee280920f0 (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: 5823
diff changeset
   261
				if (IsNormalAircraft(v)) {
7134
5b2d47128d05 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7108
diff changeset
   262
					v->cur_image = v->GetImage(v->direction);
5866
60ee9fff5c99 (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: 5855
diff changeset
   263
60ee9fff5c99 (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: 5855
diff changeset
   264
					/* The plane's shadow will have the same image as the plane */
60ee9fff5c99 (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: 5855
diff changeset
   265
					Vehicle *shadow = v->next;
60ee9fff5c99 (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: 5855
diff changeset
   266
					shadow->cur_image = v->cur_image;
60ee9fff5c99 (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: 5855
diff changeset
   267
60ee9fff5c99 (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: 5855
diff changeset
   268
					/* In the case of a helicopter we will update the rotor sprites */
60ee9fff5c99 (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: 5855
diff changeset
   269
					if (v->subtype == AIR_HELICOPTER) {
60ee9fff5c99 (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: 5855
diff changeset
   270
						Vehicle *rotor = shadow->next;
60ee9fff5c99 (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: 5855
diff changeset
   271
						rotor->cur_image = GetRotorImage(v);
60ee9fff5c99 (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: 5855
diff changeset
   272
					}
6490
fe4443fba5e3 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6484
diff changeset
   273
fe4443fba5e3 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents: 6484
diff changeset
   274
					UpdateAircraftCache(v);
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   275
				}
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   276
				break;
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   277
			default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
		}
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   279
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   280
		v->left_coord = INVALID_COORD;
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   281
		VehiclePositionChanged(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
static Vehicle *InitializeVehicle(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	VehicleID index = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	memset(v, 0, sizeof(Vehicle));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	v->index = index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
   291
	assert(v->orders == NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
   293
	v = new (v) InvalidVehicle();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
	v->left_coord = INVALID_COORD;
1601
83fbe3bfb847 (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
   295
	v->first = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	v->next = NULL;
5574
2cb543714009 (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: 5475
diff changeset
   297
	v->next_hash = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	v->string_id = 0;
1111
6f4d8544e70b (svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents: 1109
diff changeset
   299
	v->next_shared = NULL;
6f4d8544e70b (svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents: 1109
diff changeset
   300
	v->prev_shared = NULL;
2574
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   301
	v->depot_list  = NULL;
2804
ea4080819175 (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
   302
	v->random_bits = 0;
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
   303
	v->group_id = DEFAULT_GROUP;
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
   304
	v->fill_percent_te_id = INVALID_TE_ID;
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
   305
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	return v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
2804
ea4080819175 (svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents: 2791
diff changeset
   309
/**
ea4080819175 (svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents: 2791
diff changeset
   310
 * Get a value for a vehicle's random_bits.
ea4080819175 (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
   311
 * @return A random value from 0 to 255.
ea4080819175 (svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents: 2791
diff changeset
   312
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6198
diff changeset
   313
byte VehicleRandomBits()
2804
ea4080819175 (svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents: 2791
diff changeset
   314
{
ea4080819175 (svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents: 2791
diff changeset
   315
	return GB(Random(), 0, 8);
ea4080819175 (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
   316
}
ea4080819175 (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
   317
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6198
diff changeset
   318
Vehicle *ForceAllocateSpecialVehicle()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
{
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   320
	/* This stays a strange story.. there should always be room for special
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   321
	 * vehicles (special effects all over the map), but with 65k of vehicles
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   322
	 * is this realistic to double-check for that? For now we just reserve
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   323
	 * BLOCKS_FOR_SPECIAL_VEHICLES times block_size vehicles that may only
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   324
	 * be used for special vehicles.. should work nicely :) */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   326
	Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   328
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   329
	 * TODO - This is just a temporary stage, this will be removed. */
4972
c7f92c6b74e4 (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4925
diff changeset
   330
	for (v = GetVehicle(0); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) {
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   331
		/* No more room for the special vehicles, return NULL */
4972
c7f92c6b74e4 (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4925
diff changeset
   332
		if (v->index >= (1 << Vehicle_POOL_BLOCK_SIZE_BITS) * BLOCKS_FOR_SPECIAL_VEHICLES)
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   333
			return NULL;
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   334
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   335
		if (!IsValidVehicle(v)) return InitializeVehicle(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
	}
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   337
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   341
/**
2606
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   342
 * finds a free vehicle in the memory or allocates a new one
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   343
 * returns a pointer to the first free vehicle or NULL if all vehicles are in use
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   344
 * *skip_vehicles is an offset to where in the array we should begin looking
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   345
 * this is to avoid looping though the same vehicles more than once after we learned that they are not free
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   346
 * this feature is used by AllocateVehicles() since it need to allocate more than one and when
4972
c7f92c6b74e4 (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4925
diff changeset
   347
 * another block is added to _Vehicle_pool, since we only do that when we know it's already full
2606
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   348
 */
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   349
static Vehicle *AllocateSingleVehicle(VehicleID *skip_vehicles)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
{
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   351
	/* See note by ForceAllocateSpecialVehicle() why we skip the
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   352
	 * first blocks */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
	Vehicle *v;
4972
c7f92c6b74e4 (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4925
diff changeset
   354
	const int offset = (1 << Vehicle_POOL_BLOCK_SIZE_BITS) * BLOCKS_FOR_SPECIAL_VEHICLES;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   356
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   357
	 * @todo - This is just a temporary stage, this will be removed. */
4972
c7f92c6b74e4 (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4925
diff changeset
   358
	if (*skip_vehicles < (_Vehicle_pool.total_items - offset)) { // make sure the offset in the array is not larger than the array itself
c7f92c6b74e4 (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4925
diff changeset
   359
		for (v = GetVehicle(offset + *skip_vehicles); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) {
2606
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   360
			(*skip_vehicles)++;
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   361
			if (!IsValidVehicle(v)) return InitializeVehicle(v);
2606
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   362
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   365
	/* Check if we can add a block to the pool */
4972
c7f92c6b74e4 (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4925
diff changeset
   366
	if (AddBlockToPool(&_Vehicle_pool))
2606
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   367
		return AllocateSingleVehicle(skip_vehicles);
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   368
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   369
	return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   372
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6198
diff changeset
   373
Vehicle *AllocateVehicle()
2606
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   374
{
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   375
	VehicleID counter = 0;
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   376
	return AllocateSingleVehicle(&counter);
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   377
}
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   378
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   379
2601
d1a193af01e6 (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
   380
/** Allocates a lot of vehicles and frees them again
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
   381
 * @param vl pointer to an array of vehicles to get allocated. Can be NULL if the vehicles aren't needed (makes it test only)
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
   382
 * @param num number of vehicles to allocate room for
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
   383
 * @return true if there is room to allocate all the vehicles
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
   384
 */
2601
d1a193af01e6 (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
   385
bool AllocateVehicles(Vehicle **vl, int num)
d1a193af01e6 (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
   386
{
d1a193af01e6 (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
   387
	int i;
d1a193af01e6 (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
   388
	Vehicle *v;
2606
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   389
	VehicleID counter = 0;
2601
d1a193af01e6 (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
   390
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   391
	for (i = 0; i != num; i++) {
2606
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   392
		v = AllocateSingleVehicle(&counter);
2601
d1a193af01e6 (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
   393
		if (v == NULL) {
2606
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   394
			return false;
2601
d1a193af01e6 (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
   395
		}
2606
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   396
		if (vl != NULL) {
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   397
			vl[i] = v;
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   398
		}
2601
d1a193af01e6 (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
   399
	}
d1a193af01e6 (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
   400
2606
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
   401
	return true;
2601
d1a193af01e6 (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
   402
}
d1a193af01e6 (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
   403
6871
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   404
/* Size of the hash, 6 = 64 x 64, 7 = 128 x 128. Larger sizes will (in theory) reduce hash
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   405
 * lookup times at the expense of memory usage. */
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   406
const int HASH_BITS = 7;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   407
const int HASH_SIZE = 1 << HASH_BITS;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   408
const int HASH_MASK = HASH_SIZE - 1;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   409
const int TOTAL_HASH_SIZE = 1 << (HASH_BITS * 2);
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   410
const int TOTAL_HASH_MASK = TOTAL_HASH_SIZE - 1;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   411
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   412
/* Resolution of the hash, 0 = 1*1 tile, 1 = 2*2 tiles, 2 = 4*4 tiles, etc.
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   413
 * Profiling results show that 0 is fastest. */
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   414
const int HASH_RES = 0;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   415
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   416
static Vehicle *_new_vehicle_position_hash[TOTAL_HASH_SIZE];
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   417
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   418
static void *VehicleFromHash(int xl, int yl, int xu, int yu, void *data, VehicleFromPosProc *proc)
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   419
{
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   420
	for (int y = yl; ; y = (y + (1 << HASH_BITS)) & (HASH_MASK << HASH_BITS)) {
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   421
		for (int x = xl; ; x = (x + 1) & HASH_MASK) {
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   422
			Vehicle *v = _new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK];
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   423
			for (; v != NULL; v = v->next_new_hash) {
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   424
				void *a = proc(v, data);
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   425
				if (a != NULL) return a;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   426
			}
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   427
			if (x == xu) break;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   428
		}
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   429
		if (y == yu) break;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   430
	}
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   431
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   432
	return NULL;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   433
}
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   434
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   435
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   436
void *VehicleFromPosXY(int x, int y, void *data, VehicleFromPosProc *proc)
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   437
{
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   438
	const int COLL_DIST = 6;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   439
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   440
	/* Hash area to scan is from xl,yl to xu,yu */
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   441
	int xl = GB((x - COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS);
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   442
	int xu = GB((x + COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS);
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   443
	int yl = GB((y - COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   444
	int yu = GB((y + COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   445
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   446
	return VehicleFromHash(xl, yl, xu, yu, data, proc);
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   447
}
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   448
2651
901ece5377b7 (svn r3193) Staticise the vehicle position hash
tron
parents: 2639
diff changeset
   449
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
{
6871
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   452
	int x = GB(TileX(tile), HASH_RES, HASH_BITS);
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   453
	int y = GB(TileY(tile), HASH_RES, HASH_BITS) << HASH_BITS;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   454
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   455
	Vehicle *v = _new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK];
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   456
	for (; v != NULL; v = v->next_new_hash) {
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   457
		if (v->tile != tile) continue;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   458
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   459
		void *a = proc(v, data);
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   460
		if (a != NULL) return a;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	}
6871
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   462
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
6886
e7f939f0206d (svn r10129) -Fix (r10111): Test for x == INVALID_COORD instead of v->tile == INVALID_TILE to determine if a vehicle should be removed from the has.
peter1138
parents: 6883
diff changeset
   466
static void UpdateNewVehiclePosHash(Vehicle *v, bool remove)
6871
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   467
{
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   468
	Vehicle **old_hash = v->old_new_hash;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   469
	Vehicle **new_hash;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   470
6886
e7f939f0206d (svn r10129) -Fix (r10111): Test for x == INVALID_COORD instead of v->tile == INVALID_TILE to determine if a vehicle should be removed from the has.
peter1138
parents: 6883
diff changeset
   471
	if (remove) {
6871
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   472
		new_hash = NULL;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   473
	} else {
7232
21170a714fea (svn r10513) -Fix [FS#1022]: use vehicle subtile position to update cache, not tile, so that collision detection works on bridges and tunnels.
peter1138
parents: 7200
diff changeset
   474
		int x = GB(v->x_pos / TILE_SIZE, HASH_RES, HASH_BITS);
21170a714fea (svn r10513) -Fix [FS#1022]: use vehicle subtile position to update cache, not tile, so that collision detection works on bridges and tunnels.
peter1138
parents: 7200
diff changeset
   475
		int y = GB(v->y_pos / TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS;
6871
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   476
		new_hash = &_new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK];
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   477
	}
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   478
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   479
	if (old_hash == new_hash) return;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   480
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   481
	/* Remove from the old position in the hash table */
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   482
	if (old_hash != NULL) {
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   483
		Vehicle *last = NULL;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   484
		Vehicle *u = *old_hash;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   485
		while (u != v) {
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   486
			last = u;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   487
			u = u->next_new_hash;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   488
			assert(u != NULL);
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   489
		}
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   490
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   491
		if (last == NULL) {
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   492
			*old_hash = v->next_new_hash;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   493
		} else {
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   494
			last->next_new_hash = v->next_new_hash;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   495
		}
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   496
	}
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   497
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   498
	/* Insert vehicle at beginning of the new position in the hash table */
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   499
	if (new_hash != NULL) {
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   500
		v->next_new_hash = *new_hash;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   501
		*new_hash = v;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   502
		assert(v != v->next_new_hash);
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   503
	}
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   504
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   505
	/* Remember current hash position */
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   506
	v->old_new_hash = new_hash;
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   507
}
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   508
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   509
static Vehicle *_vehicle_position_hash[0x1000];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2814
diff changeset
   511
static void UpdateVehiclePosHash(Vehicle* v, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
{
6886
e7f939f0206d (svn r10129) -Fix (r10111): Test for x == INVALID_COORD instead of v->tile == INVALID_TILE to determine if a vehicle should be removed from the has.
peter1138
parents: 6883
diff changeset
   513
	UpdateNewVehiclePosHash(v, x == INVALID_COORD);
6871
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   514
5574
2cb543714009 (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: 5475
diff changeset
   515
	Vehicle **old_hash, **new_hash;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
	int old_x = v->left_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
	int old_y = v->top_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6490
diff changeset
   519
	new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x, y)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
	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
   521
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   522
	if (old_hash == new_hash) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
	/* remove from hash table? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
	if (old_hash != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
		Vehicle *last = NULL;
5574
2cb543714009 (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: 5475
diff changeset
   527
		Vehicle *u = *old_hash;
2cb543714009 (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: 5475
diff changeset
   528
		while (u != v) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
			last = u;
5574
2cb543714009 (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: 5475
diff changeset
   530
			u = u->next_hash;
2cb543714009 (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: 5475
diff changeset
   531
			assert(u != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   534
		if (last == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
			*old_hash = v->next_hash;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   536
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
			last->next_hash = v->next_hash;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   538
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
	/* insert into hash table? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
	if (new_hash != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
		v->next_hash = *new_hash;
5574
2cb543714009 (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: 5475
diff changeset
   544
		*new_hash = v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6198
diff changeset
   548
void ResetVehiclePosHash()
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5295
diff changeset
   549
{
6883
a7be3fb54737 (svn r10126) -Fix (r10111, FS#864): old_new_hash cache was not reset when the position hash were
glx
parents: 6871
diff changeset
   550
	Vehicle *v;
a7be3fb54737 (svn r10126) -Fix (r10111, FS#864): old_new_hash cache was not reset when the position hash were
glx
parents: 6871
diff changeset
   551
	FOR_ALL_VEHICLES(v) { v->old_new_hash = NULL; }
5574
2cb543714009 (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: 5475
diff changeset
   552
	memset(_vehicle_position_hash, 0, sizeof(_vehicle_position_hash));
6871
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   553
	memset(_new_vehicle_position_hash, 0, sizeof(_new_vehicle_position_hash));
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5295
diff changeset
   554
}
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5295
diff changeset
   555
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6198
diff changeset
   556
void InitializeVehicles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
{
4174
0b13c25586f7 (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
   558
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   560
	/* Clean the vehicle pool, and reserve enough blocks
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   561
	 *  for the special vehicles, plus one for all the other
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
   562
	 *  vehicles (which is increased on-the-fly) */
4972
c7f92c6b74e4 (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4925
diff changeset
   563
	CleanPool(&_Vehicle_pool);
c7f92c6b74e4 (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4925
diff changeset
   564
	AddBlockToPool(&_Vehicle_pool);
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5295
diff changeset
   565
	for (i = 0; i < BLOCKS_FOR_SPECIAL_VEHICLES; i++) {
4972
c7f92c6b74e4 (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4925
diff changeset
   566
		AddBlockToPool(&_Vehicle_pool);
4174
0b13c25586f7 (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
   567
	}
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5295
diff changeset
   568
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5295
diff changeset
   569
	ResetVehiclePosHash();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
Vehicle *GetLastVehicleInChain(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
	while (v->next != NULL) v = v->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
	return v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
1985
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   578
/** Finds the previous vehicle in a chain, by a brute force search.
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   579
 * This old function is REALLY slow because it searches through all vehicles to
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   580
 * find the previous vehicle, but if v->first has not been set, then this function
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   581
 * will need to be used to find the previous one. This function should never be
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   582
 * called by anything but GetFirstVehicleInChain
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   583
 */
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   584
static Vehicle *GetPrevVehicleInChain_bruteforce(const Vehicle *v)
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   585
{
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   586
	Vehicle *u;
2006
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 1985
diff changeset
   587
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   588
	FOR_ALL_VEHICLES(u) if (u->type == v->type && u->next == v) return u;
2006
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 1985
diff changeset
   589
1985
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   590
	return NULL;
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   591
}
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   592
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   593
/** Find the previous vehicle in a chain, by using the v->first cache.
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   594
 * While this function is fast, it cannot be used in the GetFirstVehicleInChain
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   595
 * function, otherwise you'll end up in an infinite loop call
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   596
 */
1475
c21a6481b735 (svn r1979) Const correctness
tron
parents: 1394
diff changeset
   597
Vehicle *GetPrevVehicleInChain(const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
{
1600
d2f718ee5111 (svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents: 1542
diff changeset
   599
	Vehicle *u;
1985
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   600
	assert(v != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
1985
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   602
	u = GetFirstVehicleInChain(v);
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   603
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   604
	/* Check to see if this is the first */
1985
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   605
	if (v == u) return NULL;
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   606
4165
2b5f642aa2bf (svn r5599) GetPrevVehicleInChain() may never fail to find a valid vehicle. Reflect this in the code
tron
parents: 4130
diff changeset
   607
	for (; u->next != v; u = u->next) assert(u->next != NULL);
2b5f642aa2bf (svn r5599) GetPrevVehicleInChain() may never fail to find a valid vehicle. Reflect this in the code
tron
parents: 4130
diff changeset
   608
2b5f642aa2bf (svn r5599) GetPrevVehicleInChain() may never fail to find a valid vehicle. Reflect this in the code
tron
parents: 4130
diff changeset
   609
	return u;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
1985
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   612
/** Finds the first vehicle in a chain.
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   613
 * This function reads out the v->first cache. Should the cache be dirty,
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   614
 * it determines the first vehicle in a chain, and updates the cache.
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   615
 */
1475
c21a6481b735 (svn r1979) Const correctness
tron
parents: 1394
diff changeset
   616
Vehicle *GetFirstVehicleInChain(const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
{
1601
83fbe3bfb847 (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
   618
	Vehicle* u;
83fbe3bfb847 (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
   619
1985
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   620
	assert(v != NULL);
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   621
	assert(v->type == VEH_TRAIN || v->type == VEH_ROAD);
1985
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   622
1601
83fbe3bfb847 (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
   623
	if (v->first != NULL) {
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   624
		if (v->type == VEH_TRAIN) {
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   625
			if (IsFrontEngine(v->first) || IsFreeWagon(v->first)) return v->first;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   626
		} else {
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   627
			if (IsRoadVehFront(v->first)) return v->first;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   628
		}
1765
155dfdbbbc8d (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
   629
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5357
diff changeset
   630
		DEBUG(misc, 0, "v->first cache faulty. We shouldn't be here, rebuilding cache!");
1601
83fbe3bfb847 (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
   631
	}
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   632
1765
155dfdbbbc8d (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
   633
	/* It is the fact (currently) that newly built vehicles do not have
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
   634
	 * their ->first pointer set. When this is the case, go up to the
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
   635
	 * first engine and set the pointers correctly. Also the first pointer
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
   636
	 * is not saved in a savegame, so this has to be fixed up after loading */
1765
155dfdbbbc8d (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
   637
155dfdbbbc8d (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
   638
	/* Find the 'locomotive' or the first wagon in a chain */
1985
46d2f03f66e4 (svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents: 1980
diff changeset
   639
	while ((u = GetPrevVehicleInChain_bruteforce(v)) != NULL) v = u;
1600
d2f718ee5111 (svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents: 1542
diff changeset
   640
1765
155dfdbbbc8d (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
   641
	/* Set the first pointer of all vehicles in that chain to the first wagon */
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   642
	if ((v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) ||
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   643
			(v->type == VEH_ROAD && IsRoadVehFront(v))) {
1601
83fbe3bfb847 (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
   644
		for (u = (Vehicle *)v; u != NULL; u = u->next) u->first = (Vehicle *)v;
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   645
	}
1601
83fbe3bfb847 (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
   646
1600
d2f718ee5111 (svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents: 1542
diff changeset
   647
	return (Vehicle*)v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2617
diff changeset
   650
uint CountVehiclesInChain(const Vehicle* v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   652
	uint count = 0;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   653
	do count++; while ((v = v->next) != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	return count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
4574
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   657
/** Check if a vehicle is counted in num_engines in each player struct
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   658
 * @param *v Vehicle to test
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   659
 * @return true if the vehicle is counted in num_engines
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   660
 */
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   661
bool IsEngineCountable(const Vehicle *v)
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   662
{
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   663
	switch (v->type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   664
		case VEH_AIRCRAFT: return IsNormalAircraft(v); // don't count plane shadows and helicopter rotors
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   665
		case VEH_TRAIN:
4574
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   666
			return !IsArticulatedPart(v) && // tenders and other articulated parts
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   667
			(!IsMultiheaded(v) || IsTrainEngine(v)); // rear parts of multiheaded engines
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   668
		case VEH_ROAD: return IsRoadVehFront(v);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   669
		case VEH_SHIP: return true;
4574
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   670
		default: return false; // Only count player buildable vehicles
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   671
	}
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   672
}
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   673
4404
b58b0af53da3 (svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents: 4389
diff changeset
   674
void DestroyVehicle(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
{
6509
d30ae4cf0cfa (svn r9692) -Fix (r9683): don't try to remove vehicles from the queue of a non-existing station.
rubidium
parents: 6506
diff changeset
   676
	if (IsValidStationID(v->last_station_visited)) {
6500
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6492
diff changeset
   677
		GetStation(v->last_station_visited)->loading_vehicles.remove(v);
7200
54afe2891d7b (svn r10478) -Fix [FS#999]: remove the loading indicator when a vehicle is removed.
rubidium
parents: 7135
diff changeset
   678
54afe2891d7b (svn r10478) -Fix [FS#999]: remove the loading indicator when a vehicle is removed.
rubidium
parents: 7135
diff changeset
   679
		HideFillingPercent(v->fill_percent_te_id);
54afe2891d7b (svn r10478) -Fix [FS#999]: remove the loading indicator when a vehicle is removed.
rubidium
parents: 7135
diff changeset
   680
		v->fill_percent_te_id = INVALID_TE_ID;
6500
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6492
diff changeset
   681
	}
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6492
diff changeset
   682
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5940
diff changeset
   683
	if (IsEngineCountable(v)) {
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5940
diff changeset
   684
		GetPlayer(v->owner)->num_engines[v->engine_type]--;
7096
9b231813f232 (svn r10363) -Fix [FS#911]: invalidating autoreplace windows didn't take account of vehicle group (Matthias Wolf)
peter1138
parents: 7087
diff changeset
   685
		if (v->owner == _local_player) InvalidateAutoreplaceWindow(v->engine_type, v->group_id);
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
   686
6647
aa2284cbb2dc (svn r9878) -Fix (9874): some vehicle count's were not properly updated on delete or autoreplace of vehicles.
rubidium
parents: 6643
diff changeset
   687
		if (IsValidGroupID(v->group_id)) GetGroup(v->group_id)->num_engines[v->engine_type]--;
6773
bc98b0b16ec4 (svn r10009) -Codechange: Add and use Vehicle::IsPrimaryVehicle to replace individual checks depending on the vehicle type.
maedhros
parents: 6727
diff changeset
   688
		if (v->IsPrimaryVehicle()) DecreaseGroupNumVehicle(v->group_id);
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5940
diff changeset
   689
	}
4574
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4560
diff changeset
   690
3139
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 3132
diff changeset
   691
	DeleteVehicleNews(v->index, INVALID_STRING_ID);
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 3132
diff changeset
   692
4404
b58b0af53da3 (svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents: 4389
diff changeset
   693
	DeleteName(v->string_id);
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   694
	if (v->type == VEH_ROAD) ClearSlot(v);
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   695
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   696
	if (v->type != VEH_TRAIN || (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v)))) {
4739
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4736
diff changeset
   697
		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4736
diff changeset
   698
	}
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4736
diff changeset
   699
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
   700
	v->cargo.Truncate(0);
4404
b58b0af53da3 (svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents: 4389
diff changeset
   701
	UpdateVehiclePosHash(v, INVALID_COORD, 0);
5574
2cb543714009 (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: 5475
diff changeset
   702
	v->next_hash = NULL;
6871
d8b53c9f0b13 (svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents: 6857
diff changeset
   703
	v->next_new_hash = NULL;
5746
ab94eb9bdde6 (svn r8294) -Fix: deleting a vehicle with shared orders, but no orders would fail to reset prev_shared and next_shared
bjarni
parents: 5717
diff changeset
   704
	if (IsPlayerBuildableVehicleType(v)) DeleteVehicleOrders(v);
4404
b58b0af53da3 (svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents: 4389
diff changeset
   705
b58b0af53da3 (svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents: 4389
diff changeset
   706
	/* Now remove any artic part. This will trigger an other
b58b0af53da3 (svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents: 4389
diff changeset
   707
	 *  destroy vehicle, which on his turn can remove any
b58b0af53da3 (svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents: 4389
diff changeset
   708
	 *  other artic parts. */
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   709
	if ((v->type == VEH_TRAIN && EngineHasArticPart(v)) || (v->type == VEH_ROAD && RoadVehHasArticPart(v))) {
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   710
		DeleteVehicle(v->next);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   711
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
6782
e36e22d356a9 (svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents: 6773
diff changeset
   714
/**
e36e22d356a9 (svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents: 6773
diff changeset
   715
 * Deletes all vehicles in a chain.
e36e22d356a9 (svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents: 6773
diff changeset
   716
 * @param v The first vehicle in the chain.
e36e22d356a9 (svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents: 6773
diff changeset
   717
 *
e36e22d356a9 (svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents: 6773
diff changeset
   718
 * @warning This function is not valid for any vehicle containing articulated
e36e22d356a9 (svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents: 6773
diff changeset
   719
 * parts.
e36e22d356a9 (svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents: 6773
diff changeset
   720
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
void DeleteVehicleChain(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
{
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   723
	assert(v->type != VEH_TRAIN && v->type != VEH_ROAD);
6782
e36e22d356a9 (svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents: 6773
diff changeset
   724
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
		Vehicle *u = v;
6782
e36e22d356a9 (svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents: 6773
diff changeset
   727
		v = v->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
		DeleteVehicle(u);
1765
155dfdbbbc8d (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
   729
	} while (v != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   732
/** head of the linked list to tell what vehicles that visited a depot in a tick */
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2617
diff changeset
   733
static Vehicle* _first_veh_in_depot_list;
2574
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   734
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   735
/** Adds a vehicle to the list of vehicles, that visited a depot this tick
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
   736
 * @param *v vehicle to add
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
   737
 */
2574
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   738
void VehicleEnteredDepotThisTick(Vehicle *v)
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   739
{
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   740
	/* we need to set v->leave_depot_instantly as we have no control of it's contents at this time */
2600
3266a93d1444 (svn r3137) -Fix: [autoreplace] fixed assert that was triggerable when a vehicle entered a depot even though the goto depot was canceled
bjarni
parents: 2599
diff changeset
   741
	if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS) && v->current_order.type == OT_GOTO_DEPOT) {
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   742
		/* we keep the vehicle in the depot since the user ordered it to stay */
2590
64e3f69a4ad8 (svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents: 2579
diff changeset
   743
		v->leave_depot_instantly = false;
64e3f69a4ad8 (svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents: 2579
diff changeset
   744
	} else {
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   745
		/* the vehicle do not plan on stopping in the depot, so we stop it to ensure that it will not reserve the path
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   746
		 * out of the depot before we might autoreplace it to a different engine. The new engine would not own the reserved path
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   747
		 * we store that we stopped the vehicle, so autoreplace can start it again */
2579
8048bed6e67e (svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents: 2575
diff changeset
   748
		v->vehstatus |= VS_STOPPED;
8048bed6e67e (svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents: 2575
diff changeset
   749
		v->leave_depot_instantly = true;
8048bed6e67e (svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents: 2575
diff changeset
   750
	}
8048bed6e67e (svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents: 2575
diff changeset
   751
2574
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   752
	if (_first_veh_in_depot_list == NULL) {
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   753
		_first_veh_in_depot_list = v;
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   754
	} else {
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   755
		Vehicle *w = _first_veh_in_depot_list;
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   756
		while (w->depot_list != NULL) w = w->depot_list;
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   757
		w->depot_list = v;
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   758
	}
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   759
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6198
diff changeset
   761
void CallVehicleTicks()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
{
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4404
diff changeset
   763
	_first_veh_in_depot_list = NULL; // now we are sure it's initialized at the start of each tick
2574
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   764
6616
0b3835bdd796 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium
parents: 6611
diff changeset
   765
	Station *st;
0b3835bdd796 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium
parents: 6611
diff changeset
   766
	FOR_ALL_STATIONS(st) LoadUnloadStation(st);
0b3835bdd796 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium
parents: 6611
diff changeset
   767
0b3835bdd796 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium
parents: 6611
diff changeset
   768
	Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
	FOR_ALL_VEHICLES(v) {
7135
3c1bcca0d6bb (svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents: 7134
diff changeset
   770
		v->Tick();
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4648
diff changeset
   771
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4648
diff changeset
   772
		switch (v->type) {
6621
441559124aea (svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium
parents: 6616
diff changeset
   773
			default: break;
441559124aea (svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium
parents: 6616
diff changeset
   774
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   775
			case VEH_TRAIN:
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   776
			case VEH_ROAD:
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   777
			case VEH_AIRCRAFT:
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   778
			case VEH_SHIP:
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   779
				if (v->type == VEH_TRAIN && IsTrainWagon(v)) continue;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   780
				if (v->type == VEH_AIRCRAFT && v->subtype != AIR_HELICOPTER) continue;
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
   781
				if (v->type == VEH_ROAD && !IsRoadVehFront(v)) continue;
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4648
diff changeset
   782
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4648
diff changeset
   783
				v->motion_counter += (v->direction & 1) ? (v->cur_speed * 3) / 4 : v->cur_speed;
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4648
diff changeset
   784
				/* Play a running sound if the motion counter passes 256 (Do we not skip sounds?) */
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4648
diff changeset
   785
				if (GB(v->motion_counter, 0, 8) < v->cur_speed) PlayVehicleSound(v, VSE_RUNNING);
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4648
diff changeset
   786
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4648
diff changeset
   787
				/* Play an alterate running sound every 16 ticks */
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4648
diff changeset
   788
				if (GB(v->tick_counter, 0, 4) == 0) PlayVehicleSound(v, v->cur_speed > 0 ? VSE_RUNNING_16 : VSE_STOPPED_16);
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4648
diff changeset
   789
		}
2574
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   790
	}
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   791
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   792
	/* now we handle all the vehicles that entered a depot this tick */
2574
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   793
	v = _first_veh_in_depot_list;
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   794
	while (v != NULL) {
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   795
		Vehicle *w = v->depot_list;
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4404
diff changeset
   796
		v->depot_list = NULL; // it should always be NULL at the end of each tick
4676
dd1d2d78d6f2 (svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents: 4675
diff changeset
   797
		MaybeReplaceVehicle(v, false, true);
2574
70a4e3cb85bf (svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents: 2564
diff changeset
   798
		v = w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
2704
bdf6ae0cb27c (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
   802
/** Check if a given engine type can be refitted to a given cargo
bdf6ae0cb27c (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
   803
 * @param engine_type Engine type to check
1802
da61740cc1e7 (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
   804
 * @param cid_to check refit to this cargo-type
da61740cc1e7 (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
   805
 * @return true if it is possible, false otherwise
da61740cc1e7 (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
   806
 */
2704
bdf6ae0cb27c (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
   807
bool CanRefitTo(EngineID engine_type, CargoID cid_to)
1802
da61740cc1e7 (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
   808
{
6148
5247b66aad19 (svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents: 6113
diff changeset
   809
	return HASBIT(EngInfo(engine_type)->refit_mask, cid_to);
1802
da61740cc1e7 (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
   810
}
da61740cc1e7 (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
   811
3973
9d3cd1ed6ac0 (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
   812
/** Find the first cargo type that an engine can be refitted to.
6484
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
   813
 * @param engine_type Which engine to find cargo for.
3973
9d3cd1ed6ac0 (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
   814
 * @return A climate dependent cargo type. CT_INVALID is returned if not refittable.
9d3cd1ed6ac0 (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
   815
 */
9d3cd1ed6ac0 (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
   816
CargoID FindFirstRefittableCargo(EngineID engine_type)
9d3cd1ed6ac0 (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
   817
{
9d3cd1ed6ac0 (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
   818
	uint32 refit_mask = EngInfo(engine_type)->refit_mask;
9d3cd1ed6ac0 (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
   819
9d3cd1ed6ac0 (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
   820
	if (refit_mask != 0) {
6350
04b19f551aec (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6331
diff changeset
   821
		for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
6148
5247b66aad19 (svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents: 6113
diff changeset
   822
			if (HASBIT(refit_mask, cid)) return cid;
3973
9d3cd1ed6ac0 (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
   823
		}
9d3cd1ed6ac0 (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
   824
	}
9d3cd1ed6ac0 (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
   825
9d3cd1ed6ac0 (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
   826
	return CT_INVALID;
9d3cd1ed6ac0 (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
   827
}
9d3cd1ed6ac0 (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
   828
4544
69f1248a2d97 (svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents: 4527
diff changeset
   829
/** Learn the price of refitting a certain engine
6484
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
   830
* @param engine_type Which engine to refit
4544
69f1248a2d97 (svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents: 4527
diff changeset
   831
* @return Price for refitting
69f1248a2d97 (svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents: 4527
diff changeset
   832
*/
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
   833
CommandCost GetRefitCost(EngineID engine_type)
4544
69f1248a2d97 (svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents: 4527
diff changeset
   834
{
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   835
	CommandCost base_cost;
4544
69f1248a2d97 (svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents: 4527
diff changeset
   836
69f1248a2d97 (svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents: 4527
diff changeset
   837
	switch (GetEngine(engine_type)->type) {
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   838
		case VEH_SHIP: base_cost.AddCost(_price.ship_base); break;
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   839
		case VEH_ROAD: base_cost.AddCost(_price.roadveh_base); break;
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   840
		case VEH_AIRCRAFT: base_cost.AddCost(_price.aircraft_base); break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   841
		case VEH_TRAIN:
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   842
			base_cost.AddCost(2 * ((RailVehInfo(engine_type)->railveh_type == RAILVEH_WAGON) ?
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   843
							 _price.build_railwagon : _price.build_railvehicle));
4544
69f1248a2d97 (svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents: 4527
diff changeset
   844
			break;
69f1248a2d97 (svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents: 4527
diff changeset
   845
		default: NOT_REACHED(); break;
69f1248a2d97 (svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents: 4527
diff changeset
   846
	}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   847
	return CommandCost((EngInfo(engine_type)->refit_cost * base_cost.GetCost()) >> 10);
4544
69f1248a2d97 (svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents: 4527
diff changeset
   848
}
3973
9d3cd1ed6ac0 (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
   849
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
   850
static void DoDrawVehicle(const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
{
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5651
diff changeset
   852
	SpriteID image = v->cur_image;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5651
diff changeset
   853
	SpriteID pal;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   854
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7321
diff changeset
   855
	if (v->vehstatus & VS_DEFPAL) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5651
diff changeset
   856
		pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5651
diff changeset
   857
	} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5651
diff changeset
   858
		pal = PAL_NONE;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   859
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5651
diff changeset
   861
	AddSortableSpriteToDraw(image, pal, v->x_pos + v->x_offs, v->y_pos + v->y_offs,
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7321
diff changeset
   862
		v->sprite_width, v->sprite_height, v->z_height, v->z_pos, v->vehstatus & VS_SHADOW);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
void ViewportAddVehicles(DrawPixelInfo *dpi)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
{
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   867
	/* The bounding rectangle */
4174
0b13c25586f7 (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
   868
	const int l = dpi->left;
0b13c25586f7 (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
   869
	const int r = dpi->left + dpi->width;
0b13c25586f7 (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
   870
	const int t = dpi->top;
0b13c25586f7 (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
   871
	const int b = dpi->top + dpi->height;
0b13c25586f7 (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
   872
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
   873
	/* The hash area to scan */
6905
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   874
	int xl, xu, yl, yu;
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   875
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   876
	if (dpi->width + 70 < (1 << (7 + 6))) {
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   877
		xl = GB(l - 70, 7, 6);
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   878
		xu = GB(r,      7, 6);
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   879
	} else {
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   880
		/* scan whole hash row */
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   881
		xl = 0;
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   882
		xu = 0x3F;
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   883
	}
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   884
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   885
	if (dpi->height + 70 < (1 << (6 + 6))) {
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   886
		yl = GB(t - 70, 6, 6) << 6;
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   887
		yu = GB(b,      6, 6) << 6;
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   888
	} else {
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   889
		/* scan whole column */
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   890
		yl = 0;
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   891
		yu = 0x3F << 6;
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   892
	}
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   893
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   894
	for (int y = yl;; y = (y + (1 << 6)) & (0x3F << 6)) {
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   895
		for (int x = xl;; x = (x + 1) & 0x3F) {
cc682e1608bf (svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents: 6904
diff changeset
   896
			const Vehicle *v = _vehicle_position_hash[x + y]; // already masked & 0xFFF
5574
2cb543714009 (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: 5475
diff changeset
   897
2cb543714009 (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: 5475
diff changeset
   898
			while (v != NULL) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   899
				if (!(v->vehstatus & VS_HIDDEN) &&
4174
0b13c25586f7 (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
   900
						l <= v->right_coord &&
0b13c25586f7 (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
   901
						t <= v->bottom_coord &&
0b13c25586f7 (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
   902
						r >= v->left_coord &&
0b13c25586f7 (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
   903
						b >= v->top_coord) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
					DoDrawVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
				}
5574
2cb543714009 (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: 5475
diff changeset
   906
				v = v->next_hash;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
4174
0b13c25586f7 (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
   909
			if (x == xu) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
		}
4174
0b13c25586f7 (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
   911
0b13c25586f7 (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
   912
		if (y == yu) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   916
static void ChimneySmokeInit(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
	uint32 r = Random();
2140
a04d0142ad65 (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
   919
	v->cur_image = SPR_CHIMNEY_SMOKE_0 + GB(r, 0, 3);
a04d0142ad65 (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
   920
	v->progress = GB(r, 16, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   923
static void ChimneySmokeTick(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   925
	if (v->progress > 0) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   926
		v->progress--;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   927
	} else {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   928
		TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
		BeginVehicleMove(v);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   931
1980
6c5917cfcb78 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
   932
		tile = TileVirtXY(v->x_pos, v->y_pos);
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1024
diff changeset
   933
		if (!IsTileType(tile, MP_INDUSTRY)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   939
		if (v->cur_image != SPR_CHIMNEY_SMOKE_7) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   940
			v->cur_image++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   941
		} else {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   942
			v->cur_image = SPR_CHIMNEY_SMOKE_0;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   943
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
		v->progress = 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   950
static void SteamSmokeInit(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   952
	v->cur_image = SPR_STEAM_SMOKE_0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
	v->progress = 12;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   956
static void SteamSmokeTick(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   958
	bool moved = false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   959
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
	BeginVehicleMove(v);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   961
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   962
	v->progress++;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   963
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   964
	if ((v->progress & 7) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
		v->z_pos++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
		moved = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   969
	if ((v->progress & 0xF) == 4) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   970
		if (v->cur_image != SPR_STEAM_SMOKE_4) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   971
			v->cur_image++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   972
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
		moved = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
	if (moved) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   986
static void DieselSmokeInit(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   988
	v->cur_image = SPR_DIESEL_SMOKE_0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   992
static void DieselSmokeTick(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   994
	v->progress++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   995
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
   996
	if ((v->progress & 3) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
		v->z_pos++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
	} else if ((v->progress & 7) == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
		BeginVehicleMove(v);
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1003
		if (v->cur_image != SPR_DIESEL_SMOKE_5) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1004
			v->cur_image++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1005
			VehiclePositionChanged(v);
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1006
			EndVehicleMove(v);
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1007
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1014
static void ElectricSparkInit(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1016
	v->cur_image = SPR_ELECTRIC_SPARK_0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
	v->progress = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1020
static void ElectricSparkTick(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1022
	if (v->progress < 2) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1023
		v->progress++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1024
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
		v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
		BeginVehicleMove(v);
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1027
		if (v->cur_image != SPR_ELECTRIC_SPARK_5) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1028
			v->cur_image++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1029
			VehiclePositionChanged(v);
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1030
			EndVehicleMove(v);
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1031
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1038
static void SmokeInit(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1040
	v->cur_image = SPR_SMOKE_0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
	v->progress = 12;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1044
static void SmokeTick(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1046
	bool moved = false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1047
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
	BeginVehicleMove(v);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1049
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1050
	v->progress++;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1051
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1052
	if ((v->progress & 3) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
		v->z_pos++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
		moved = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1057
	if ((v->progress & 0xF) == 4) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1058
		if (v->cur_image != SPR_SMOKE_4) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1059
			v->cur_image++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1060
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
		moved = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
	if (moved) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1074
static void ExplosionLargeInit(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1076
	v->cur_image = SPR_EXPLOSION_LARGE_0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1080
static void ExplosionLargeTick(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1082
	v->progress++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1083
	if ((v->progress & 3) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
		BeginVehicleMove(v);
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1085
		if (v->cur_image != SPR_EXPLOSION_LARGE_F) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1086
			v->cur_image++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1087
			VehiclePositionChanged(v);
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1088
			EndVehicleMove(v);
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1089
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1096
static void BreakdownSmokeInit(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1098
	v->cur_image = SPR_BREAKDOWN_SMOKE_0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1102
static void BreakdownSmokeTick(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1104
	v->progress++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1105
	if ((v->progress & 7) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
		BeginVehicleMove(v);
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1107
		if (v->cur_image != SPR_BREAKDOWN_SMOKE_3) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1108
			v->cur_image++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1109
		} else {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1110
			v->cur_image = SPR_BREAKDOWN_SMOKE_0;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1111
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
7334
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  1116
	v->u.special.animation_state--;
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  1117
	if (v->u.special.animation_state == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
		DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1124
static void ExplosionSmallInit(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1126
	v->cur_image = SPR_EXPLOSION_SMALL_0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1130
static void ExplosionSmallTick(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1132
	v->progress++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1133
	if ((v->progress & 3) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
		BeginVehicleMove(v);
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1135
		if (v->cur_image != SPR_EXPLOSION_SMALL_B) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1136
			v->cur_image++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1137
			VehiclePositionChanged(v);
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1138
			EndVehicleMove(v);
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1139
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
1364
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1146
static void BulldozerInit(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
{
1364
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1148
	v->cur_image = SPR_BULLDOZER_NE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
	v->progress = 0;
7334
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  1150
	v->u.special.animation_state = 0;
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  1151
	v->u.special.animation_substate = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  1154
struct BulldozerMovement {
1365
3ec3ff0adc01 (svn r1869) Fix some bugs in the bulldozer movement implementation.
tron
parents: 1364
diff changeset
  1155
	byte direction:2;
1364
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1156
	byte image:2;
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1157
	byte duration:3;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  1158
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
1364
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1160
static const BulldozerMovement _bulldozer_movement[] = {
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1161
	{ 0, 0, 4 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1162
	{ 3, 3, 4 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1163
	{ 2, 2, 7 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1164
	{ 0, 2, 7 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1165
	{ 1, 1, 3 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1166
	{ 2, 2, 7 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1167
	{ 0, 2, 7 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1168
	{ 1, 1, 3 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1169
	{ 2, 2, 7 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1170
	{ 0, 2, 7 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1171
	{ 3, 3, 6 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1172
	{ 2, 2, 6 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1173
	{ 1, 1, 7 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1174
	{ 3, 1, 7 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1175
	{ 0, 0, 3 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1176
	{ 1, 1, 7 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1177
	{ 3, 1, 7 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1178
	{ 0, 0, 3 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1179
	{ 1, 1, 7 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1180
	{ 3, 1, 7 }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
1364
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1183
static const struct {
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1184
	int8 x;
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1185
	int8 y;
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1186
} _inc_by_dir[] = {
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1187
	{ -1,  0 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1188
	{  0,  1 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1189
	{  1,  0 },
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1190
	{  0, -1 }
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1191
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
1364
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1193
static void BulldozerTick(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1195
	v->progress++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1196
	if ((v->progress & 7) == 0) {
7334
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  1197
		const BulldozerMovement* b = &_bulldozer_movement[v->u.special.animation_state];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
1364
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1201
		v->cur_image = SPR_BULLDOZER_NE + b->image;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
1364
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1203
		v->x_pos += _inc_by_dir[b->direction].x;
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1204
		v->y_pos += _inc_by_dir[b->direction].y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
7334
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  1206
		v->u.special.animation_substate++;
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  1207
		if (v->u.special.animation_substate >= b->duration) {
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  1208
			v->u.special.animation_substate = 0;
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  1209
			v->u.special.animation_state++;
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  1210
			if (v->u.special.animation_state == lengthof(_bulldozer_movement)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
				EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
				DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1221
static void BubbleInit(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
{
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1223
	v->cur_image = SPR_BUBBLE_GENERATE_0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
	v->spritenum = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  1228
struct BubbleMovement {
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1229
	int8 x:4;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1230
	int8 y:4;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1231
	int8 z:4;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1232
	byte image:4;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  1233
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1235
#define MK(x, y, z, i) { x, y, z, i }
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1236
#define ME(i) { i, 4, 0, 0 }
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1237
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1238
static const BubbleMovement _bubble_float_sw[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1239
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1240
	MK(1, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1241
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1242
	MK(1, 0, 1, 2),
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1243
	ME(1)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1247
static const BubbleMovement _bubble_float_ne[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1248
	MK( 0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1249
	MK(-1, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1250
	MK( 0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1251
	MK(-1, 0, 1, 2),
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1252
	ME(1)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1255
static const BubbleMovement _bubble_float_se[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1256
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1257
	MK(0, 1, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1258
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1259
	MK(0, 1, 1, 2),
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1260
	ME(1)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1263
static const BubbleMovement _bubble_float_nw[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1264
	MK(0,  0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1265
	MK(0, -1, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1266
	MK(0,  0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1267
	MK(0, -1, 1, 2),
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1268
	ME(1)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1271
static const BubbleMovement _bubble_burst[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1272
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1273
	MK(0, 0, 1, 7),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1274
	MK(0, 0, 1, 8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1275
	MK(0, 0, 1, 9),
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1276
	ME(0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1279
static const BubbleMovement _bubble_absorb[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1280
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1281
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1282
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1283
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1284
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1285
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1286
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1287
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1288
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1289
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1290
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1291
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1292
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1293
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1294
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1295
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1296
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1297
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1298
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1299
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1300
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1301
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1302
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1303
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1304
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1305
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1306
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1307
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1308
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1309
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1310
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1311
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1312
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1313
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1314
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1315
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1316
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1317
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1318
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1319
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1320
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1321
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1322
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1323
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1324
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1325
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1326
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1327
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1328
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1329
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1330
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1331
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1332
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1333
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1334
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1335
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1336
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1337
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1338
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1339
	MK(0, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1340
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1341
	MK(0, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1342
	MK(2, 1, 3, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1343
	MK(1, 1, 3, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1344
	MK(2, 1, 3, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1345
	MK(1, 1, 3, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1346
	MK(2, 1, 3, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1347
	MK(1, 1, 3, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1348
	MK(2, 1, 3, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1349
	MK(1, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1350
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1351
	MK(1, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1352
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1353
	MK(1, 0, 1, 2),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1354
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1355
	MK(1, 0, 1, 1),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1356
	MK(0, 0, 1, 0),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1357
	MK(1, 0, 1, 2),
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1358
	ME(2),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1359
	MK(0, 0, 0, 0xA),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1360
	MK(0, 0, 0, 0xB),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1361
	MK(0, 0, 0, 0xC),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1362
	MK(0, 0, 0, 0xD),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1363
	MK(0, 0, 0, 0xE),
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1364
	ME(0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
};
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1366
#undef ME
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
#undef MK
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1369
static const BubbleMovement * const _bubble_movement[] = {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1370
	_bubble_float_sw,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1371
	_bubble_float_ne,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1372
	_bubble_float_se,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1373
	_bubble_float_nw,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1374
	_bubble_burst,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1375
	_bubble_absorb,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1378
static void BubbleTick(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
{
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1380
	/*
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1381
	 * Warning: those effects can NOT use Random(), and have to use
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1382
	 *  InteractiveRandom(), because somehow someone forgot to save
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1383
	 *  spritenum to the savegame, and so it will cause desyncs in
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1384
	 *  multiplayer!! (that is: in ToyLand)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1385
	 */
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1386
	uint et;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1387
	const BubbleMovement *b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1389
	v->progress++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1390
	if ((v->progress & 3) != 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
	BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
	if (v->spritenum == 0) {
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1396
		v->cur_image++;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1397
		if (v->cur_image < SPR_BUBBLE_GENERATE_3) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
			VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
		}
7334
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  1402
		if (v->u.special.animation_substate != 0) {
2635
7ed07303448d (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2631
diff changeset
  1403
			v->spritenum = GB(InteractiveRandom(), 0, 2) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
			v->spritenum = 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
		et = 0;
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1408
	} else {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1409
		et = v->engine_type + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1412
	b = &_bubble_movement[v->spritenum - 1][et];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1414
	if (b->y == 4 && b->x == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1415
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
		DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
		return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1418
	}
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1419
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1420
	if (b->y == 4 && b->x == 1) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1421
		if (v->z_pos > 180 || CHANCE16I(1, 96, InteractiveRandom())) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1422
			v->spritenum = 5;
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 537
diff changeset
  1423
			SndPlayVehicleFx(SND_2F_POP, v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
		et = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1426
	}
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1427
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1428
	if (b->y == 4 && b->x == 2) {
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1429
		TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
		et++;
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 537
diff changeset
  1432
		SndPlayVehicleFx(SND_31_EXTRACT, v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
1980
6c5917cfcb78 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  1434
		tile = TileVirtXY(v->x_pos, v->y_pos);
3428
146dc5f172fc (svn r4256) - Codechange: Replace lone map access in vehicle.c with its map accessor.
peter1138
parents: 3422
diff changeset
  1435
		if (IsTileType(tile, MP_INDUSTRY) && GetIndustryGfx(tile) == 0xA2) AddAnimatedTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1438
	v->engine_type = et;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1439
	b = &_bubble_movement[v->spritenum - 1][et];
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1440
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1441
	v->x_pos += b->x;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1442
	v->y_pos += b->y;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1443
	v->z_pos += b->z;
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1444
	v->cur_image = SPR_BUBBLE_0 + b->image;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
	VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
	EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
typedef void EffectInitProc(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
typedef void EffectTickProc(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
static EffectInitProc * const _effect_init_procs[] = {
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1455
	ChimneySmokeInit,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1456
	SteamSmokeInit,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1457
	DieselSmokeInit,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1458
	ElectricSparkInit,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1459
	SmokeInit,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1460
	ExplosionLargeInit,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1461
	BreakdownSmokeInit,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1462
	ExplosionSmallInit,
1364
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1463
	BulldozerInit,
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1464
	BubbleInit,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
static EffectTickProc * const _effect_tick_procs[] = {
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1468
	ChimneySmokeTick,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1469
	SteamSmokeTick,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1470
	DieselSmokeTick,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1471
	ElectricSparkTick,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1472
	SmokeTick,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1473
	ExplosionLargeTick,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1474
	BreakdownSmokeTick,
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1475
	ExplosionSmallTick,
1364
238934514bfd (svn r1868) Improve readability of the bulldozer movement code
tron
parents: 1359
diff changeset
  1476
	BulldozerTick,
1371
fc15eaac6bb2 (svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents: 1365
diff changeset
  1477
	BubbleTick,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
1359
52782e5cf7c9 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1349
diff changeset
  1481
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
	Vehicle *v;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1484
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
	v = ForceAllocateSpecialVehicle();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1486
	if (v != NULL) {
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  1487
		v = new (v) SpecialVehicle();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1488
		v->subtype = type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1489
		v->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1490
		v->y_pos = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1491
		v->z_pos = z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1492
		v->tile = 0;
6558
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
  1493
		v->UpdateDeltaXY(INVALID_DIR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
		v->vehstatus = VS_UNCLICKABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
		_effect_init_procs[type](v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1498
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1499
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1500
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1502
	return v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1503
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1504
1359
52782e5cf7c9 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1349
diff changeset
  1505
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
{
5295
9cdf003cf6d1 (svn r7448) -Fix (r5794): use the height of the edge of the map for effect vehicles that are outside the map.
rubidium
parents: 5256
diff changeset
  1507
	int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE);
9cdf003cf6d1 (svn r7448) -Fix (r5794): use the height of the edge of the map for effect vehicles that are outside the map.
rubidium
parents: 5256
diff changeset
  1508
	int safe_y = clamp(y, 0, MapMaxY() * TILE_SIZE);
9cdf003cf6d1 (svn r7448) -Fix (r5794): use the height of the edge of the map for effect vehicles that are outside the map.
rubidium
parents: 5256
diff changeset
  1509
	return CreateEffectVehicle(x, y, GetSlopeZ(safe_x, safe_y) + z, type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1511
1359
52782e5cf7c9 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1349
diff changeset
  1512
Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
	return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
7135
3c1bcca0d6bb (svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents: 7134
diff changeset
  1517
void SpecialVehicle::Tick()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1518
{
7135
3c1bcca0d6bb (svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents: 7134
diff changeset
  1519
	_effect_tick_procs[this->subtype](this);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1520
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2115
diff changeset
  1522
Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1523
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
	Vehicle *found = NULL, *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
	uint dist, best_dist = (uint)-1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
	if ( (uint)(x -= vp->left) >= (uint)vp->width ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1528
			 (uint)(y -= vp->top) >= (uint)vp->height)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
				return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1530
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6621
diff changeset
  1531
	x = ScaleByZoom(x, vp->zoom) + vp->virtual_left;
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6621
diff changeset
  1532
	y = ScaleByZoom(y, vp->zoom) + vp->virtual_top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1533
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1534
	FOR_ALL_VEHICLES(v) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1535
		if ((v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0 &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
				x >= v->left_coord && x <= v->right_coord &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
				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
  1538
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1539
			dist = max(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1540
				myabs( ((v->left_coord + v->right_coord)>>1) - x ),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
				myabs( ((v->top_coord + v->bottom_coord)>>1) - y )
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1542
			);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
			if (dist < best_dist) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1545
				found = v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1546
				best_dist = dist;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1547
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1548
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
	return found;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1555
void DecreaseVehicleValue(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
	v->value -= v->value >> 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1561
static const byte _breakdown_chance[64] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1562
	  3,   3,   3,   3,   3,   3,   3,   3,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1563
	  4,   4,   5,   5,   6,   6,   7,   7,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1564
	  8,   8,   9,   9,  10,  10,  11,  11,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1565
	 12,  13,  13,  13,  13,  14,  15,  16,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1566
	 17,  19,  21,  25,  28,  31,  34,  37,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1567
	 40,  44,  48,  52,  56,  60,  64,  68,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1568
	 72,  80,  90, 100, 110, 120, 130, 140,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
	150, 170, 190, 210, 230, 250, 250, 250,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1571
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1572
void CheckVehicleBreakdown(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
	int rel, rel_old;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
	int chance;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
	/* decrease reliability */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
	v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
	if ((rel_old >> 8) != (rel >> 8))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1582
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1583
	if (v->breakdown_ctr != 0 || v->vehstatus & VS_STOPPED ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1584
			v->cur_speed < 5 || _game_mode == GM_MENU) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1585
		return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1586
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1587
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1588
	r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1590
	/* increase chance of failure */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1591
	chance = v->breakdown_chance + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1592
	if (CHANCE16I(1,25,r)) chance += 25;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1593
	v->breakdown_chance = min(255, chance);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1594
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1595
	/* calculate reliability value to use in comparison */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1596
	rel = v->reliability;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1597
	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
  1598
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1599
	/* disabled breakdowns? */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1600
	if (_opt.diff.vehicle_breakdowns < 1) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1601
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1602
	/* reduced breakdowns? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1603
	if (_opt.diff.vehicle_breakdowns == 1) rel += 0x6666;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
	/* check if to break down */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1606
	if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) {
2140
a04d0142ad65 (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
  1607
		v->breakdown_ctr    = GB(r, 16, 6) + 0x3F;
a04d0142ad65 (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
  1608
		v->breakdown_delay  = GB(r, 24, 7) + 0x80;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1609
		v->breakdown_chance = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1612
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1613
static const StringID _vehicle_type_names[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1614
	STR_019F_TRAIN,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1615
	STR_019C_ROAD_VEHICLE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1616
	STR_019E_SHIP,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1617
	STR_019D_AIRCRAFT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1619
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
static void ShowVehicleGettingOld(Vehicle *v, StringID msg)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1622
	if (v->owner != _local_player) return;
812
65ecc321b3db (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1623
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1624
	/* Do not show getting-old message if autorenew is active */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1625
	if (GetPlayer(v->owner)->engine_renew) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
5955
fe61588d5188 (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: 5944
diff changeset
  1627
	SetDParam(0, _vehicle_type_names[v->type]);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1628
	SetDParam(1, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
	AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1630
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
void AgeVehicle(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1634
	int age;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1635
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
	if (v->age < 65535)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
		v->age++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
	age = v->age - v->max_age;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
	if (age == 366*0 || age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1641
		v->reliability_spd_dec <<= 1;
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1642
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
	if (age == -366) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
		ShowVehicleGettingOld(v, STR_01A0_IS_GETTING_OLD);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
	} else if (age == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
		ShowVehicleGettingOld(v, STR_01A1_IS_GETTING_VERY_OLD);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
	} else if (age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4 || age == 366*5) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
		ShowVehicleGettingOld(v, STR_01A2_IS_GETTING_VERY_OLD_AND);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1653
4640
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1654
/** Starts or stops a lot of vehicles
4673
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1655
 * @param tile Tile of the depot where the vehicles are started/stopped (only used for depots)
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1656
 * @param flags type of operation
4762
771ccf746531 (svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents: 4741
diff changeset
  1657
 * @param p1 Station/Order/Depot ID (only used for vehicle list windows)
4673
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1658
 * @param p2 bitmask
4762
771ccf746531 (svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents: 4741
diff changeset
  1659
 *   - bit 0-4 Vehicle type
771ccf746531 (svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents: 4741
diff changeset
  1660
 *   - bit 5 false = start vehicles, true = stop vehicles
771ccf746531 (svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents: 4741
diff changeset
  1661
 *   - bit 6 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case
4673
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1662
 *   - bit 8-11 Vehicle List Window type (ignored unless bit 1 is set)
4640
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1663
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  1664
CommandCost CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
4640
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1665
{
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1666
	Vehicle **vl = NULL;
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1667
	uint16 engine_list_length = 0;
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1668
	uint16 engine_count = 0;
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  1669
	CommandCost return_value = CMD_ERROR;
4640
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1670
	uint i;
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1671
	uint stop_command;
6641
1b14f8887cb7 (svn r9872) -Codechange: more type strictness for vehicle types
rubidium
parents: 6638
diff changeset
  1672
	VehicleType vehicle_type = (VehicleType)GB(p2, 0, 5);
4762
771ccf746531 (svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents: 4741
diff changeset
  1673
	bool start_stop = HASBIT(p2, 5);
771ccf746531 (svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents: 4741
diff changeset
  1674
	bool vehicle_list_window = HASBIT(p2, 6);
4640
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1675
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1676
	switch (vehicle_type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1677
		case VEH_TRAIN:    stop_command = CMD_START_STOP_TRAIN;    break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1678
		case VEH_ROAD:     stop_command = CMD_START_STOP_ROADVEH;  break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1679
		case VEH_SHIP:     stop_command = CMD_START_STOP_SHIP;     break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1680
		case VEH_AIRCRAFT: stop_command = CMD_START_STOP_AIRCRAFT; break;
4640
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1681
		default: return CMD_ERROR;
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1682
	}
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1683
4673
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1684
	if (vehicle_list_window) {
5748
cf2f07fa20ca (svn r8296) -Fix: GenerateVehicleSortList() tried to put a TileIndex into an uint16
bjarni
parents: 5747
diff changeset
  1685
		uint32 id = p1;
4673
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1686
		uint16 window_type = p2 & VLW_MASK;
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1687
5747
ba5393ff957a (svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument
bjarni
parents: 5746
diff changeset
  1688
		engine_count = GenerateVehicleSortList((const Vehicle***)&vl, &engine_list_length, vehicle_type, _current_player, id, window_type);
4673
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1689
	} else {
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1690
		/* Get the list of vehicles in the depot */
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1691
		BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL);
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1692
	}
4640
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1693
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1694
	for (i = 0; i < engine_count; i++) {
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1695
		const Vehicle *v = vl[i];
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  1696
		CommandCost ret;
4640
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1697
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1698
		if (!!(v->vehstatus & VS_STOPPED) != start_stop) continue;
4673
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1699
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1700
		if (!vehicle_list_window) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1701
			if (vehicle_type == VEH_TRAIN) {
4673
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1702
				if (CheckTrainInDepot(v, false) == -1) continue;
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1703
			} else {
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1704
				if (!(v->vehstatus & VS_HIDDEN)) continue;
3160067b8751 (svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents: 4662
diff changeset
  1705
			}
4648
7bde2a5c36e8 (svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents: 4640
diff changeset
  1706
		}
7bde2a5c36e8 (svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents: 4640
diff changeset
  1707
4640
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1708
		ret = DoCommand(tile, v->index, 0, flags, stop_command);
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1709
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  1710
		if (CmdSucceeded(ret)) {
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1711
			return_value = CommandCost();
4640
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1712
			/* We know that the command is valid for at least one vehicle.
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1713
			 * If we haven't set DC_EXEC, then there is no point in continueing because it will be valid */
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1714
			if (!(flags & DC_EXEC)) break;
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1715
		}
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1716
	}
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1717
4648
7bde2a5c36e8 (svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents: 4640
diff changeset
  1718
	free(vl);
4640
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1719
	return return_value;
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1720
}
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4635
diff changeset
  1721
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1722
/** Sells all vehicles in a depot
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1723
 * @param tile Tile of the depot where the depot is
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1724
 * @param flags type of operation
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1725
 * @param p1 Vehicle type
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1726
 * @param p2 unused
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1727
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  1728
CommandCost CmdDepotSellAllVehicles(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1729
{
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1730
	Vehicle **engines = NULL;
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1731
	Vehicle **wagons = NULL;
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1732
	uint16 engine_list_length = 0;
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1733
	uint16 engine_count = 0;
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1734
	uint16 wagon_list_length = 0;
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1735
	uint16 wagon_count = 0;
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1736
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1737
	CommandCost cost;
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1738
	uint i, sell_command, total_number_vehicles;
6641
1b14f8887cb7 (svn r9872) -Codechange: more type strictness for vehicle types
rubidium
parents: 6638
diff changeset
  1739
	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1740
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1741
	switch (vehicle_type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1742
		case VEH_TRAIN:    sell_command = CMD_SELL_RAIL_WAGON; break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1743
		case VEH_ROAD:     sell_command = CMD_SELL_ROAD_VEH;   break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1744
		case VEH_SHIP:     sell_command = CMD_SELL_SHIP;       break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1745
		case VEH_AIRCRAFT: sell_command = CMD_SELL_AIRCRAFT;   break;
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1746
		default: return CMD_ERROR;
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1747
	}
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1748
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1749
	/* Get the list of vehicles in the depot */
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1750
	BuildDepotVehicleList(vehicle_type, tile, &engines, &engine_list_length, &engine_count,
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1751
						                      &wagons,  &wagon_list_length,  &wagon_count);
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1752
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1753
	total_number_vehicles = engine_count + wagon_count;
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1754
	for (i = 0; i < total_number_vehicles; i++) {
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1755
		const Vehicle *v;
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  1756
		CommandCost ret;
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1757
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1758
		if (i < engine_count) {
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1759
			v = engines[i];
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1760
		} else {
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1761
			v = wagons[i - engine_count];
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1762
		}
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1763
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1764
		ret = DoCommand(tile, v->index, 1, flags, sell_command);
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1765
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1766
		if (CmdSucceeded(ret)) cost.AddCost(ret);
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1767
	}
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1768
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1769
	free(engines);
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1770
	free(wagons);
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1771
	if (cost.GetCost() == 0) return CMD_ERROR; // no vehicles to sell
4659
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1772
	return cost;
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1773
}
e476c76389a8 (svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents: 4656
diff changeset
  1774
4662
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1775
/** Autoreplace all vehicles in the depot
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1776
 * @param tile Tile of the depot where the vehicles are
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1777
 * @param flags type of operation
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1778
 * @param p1 Type of vehicle
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1779
 * @param p2 Unused
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1780
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  1781
CommandCost CmdDepotMassAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
4662
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1782
{
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1783
	Vehicle **vl = NULL;
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1784
	uint16 engine_list_length = 0;
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1785
	uint16 engine_count = 0;
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1786
	uint i, x = 0, y = 0, z = 0;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1787
	CommandCost cost;
6641
1b14f8887cb7 (svn r9872) -Codechange: more type strictness for vehicle types
rubidium
parents: 6638
diff changeset
  1788
	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
4662
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1789
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1790
	if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1791
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1792
	/* Get the list of vehicles in the depot */
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1793
	BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL);
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1794
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1795
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1796
	for (i = 0; i < engine_count; i++) {
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1797
		Vehicle *v = vl[i];
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1798
		bool stopped = !(v->vehstatus & VS_STOPPED);
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  1799
		CommandCost ret;
4662
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1800
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1801
		/* Ensure that the vehicle completely in the depot */
4736
56f9dcf1d133 (svn r6648) -Codechange: simplified CmdDepotMassAutoReplace() by changing a switch-case into using a function, that was added in r6647
bjarni
parents: 4734
diff changeset
  1802
		if (!IsVehicleInDepot(v)) continue;
4662
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1803
4676
dd1d2d78d6f2 (svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents: 4675
diff changeset
  1804
		x = v->x_pos;
dd1d2d78d6f2 (svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents: 4675
diff changeset
  1805
		y = v->y_pos;
dd1d2d78d6f2 (svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents: 4675
diff changeset
  1806
		z = v->z_pos;
dd1d2d78d6f2 (svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents: 4675
diff changeset
  1807
dd1d2d78d6f2 (svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents: 4675
diff changeset
  1808
		if (stopped) {
dd1d2d78d6f2 (svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents: 4675
diff changeset
  1809
			v->vehstatus |= VS_STOPPED; // Stop the vehicle
dd1d2d78d6f2 (svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents: 4675
diff changeset
  1810
			v->leave_depot_instantly = true;
dd1d2d78d6f2 (svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents: 4675
diff changeset
  1811
		}
dd1d2d78d6f2 (svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents: 4675
diff changeset
  1812
		ret = MaybeReplaceVehicle(v, !(flags & DC_EXEC), false);
4662
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1813
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  1814
		if (CmdSucceeded(ret)) {
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1815
			cost.AddCost(ret);
4662
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1816
			if (!(flags & DC_EXEC)) break;
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1817
			/* There is a problem with autoreplace and newgrf
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1818
			 * It's impossible to tell the length of a train after it's being replaced before it's actually done
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1819
			 * Because of this, we can't estimate costs due to wagon removal and we will have to always return 0 and pay manually
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1820
			 * Since we pay after each vehicle is replaced and MaybeReplaceVehicle() check if the player got enough money
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1821
			 * we should never reach a condition where the player will end up with negative money from doing this */
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1822
			SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1823
			SubtractMoneyFromPlayer(ret);
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1824
		}
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1825
	}
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1826
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1827
	if (cost.GetCost() == 0) {
4662
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1828
		cost = CMD_ERROR;
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1829
	} else {
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1830
		if (flags & DC_EXEC) {
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1831
			/* Display the cost animation now that DoCommandP() can't do it for us (see previous comments) */
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1832
			if (IsLocalPlayer()) ShowCostOrIncomeAnimation(x, y, z, cost.GetCost());
4662
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1833
		}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1834
		cost = CommandCost();
4662
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1835
	}
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1836
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1837
	free(vl);
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1838
	return cost;
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1839
}
e36935c7bdde (svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents: 4659
diff changeset
  1840
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  1841
/** Clone a vehicle. If it is a train, it will clone all the cars too
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
  1842
 * @param tile tile of the depot where the cloned vehicle is build
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1843
 * @param flags type of operation
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
  1844
 * @param p1 the original vehicle's index
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
  1845
 * @param p2 1 = shared orders, else copied orders
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
  1846
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  1847
CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  1848
{
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1849
	Vehicle *v_front, *v;
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1850
	Vehicle *w_front, *w, *w_rear;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1851
	CommandCost cost, total_cost;
3816
28ee8b8c2522 (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
  1852
	uint32 build_argument = 2;
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  1853
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4346
diff changeset
  1854
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  1855
	v = GetVehicle(p1);
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1856
	v_front = v;
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1857
	w = NULL;
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1858
	w_front = NULL;
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1859
	w_rear = NULL;
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1860
6444
31f400a4b890 (svn r9581) -Revert (r9562): This broke as much as it fixed, so revert until a proper way of paying for refits when cloning can be found.
maedhros
parents: 6426
diff changeset
  1861
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1862
	/*
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1863
	 * v_front is the front engine in the original vehicle
6444
31f400a4b890 (svn r9581) -Revert (r9562): This broke as much as it fixed, so revert until a proper way of paying for refits when cloning can be found.
maedhros
parents: 6426
diff changeset
  1864
	 * v is the car/vehicle of the original vehicle, that is currently being copied
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1865
	 * w_front is the front engine of the cloned vehicle
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1866
	 * w is the car/vehicle currently being cloned
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1867
	 * w_rear is the rear end of the cloned train. It's used to add more cars and is only used by trains
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1868
	 */
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  1869
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1870
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  1871
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1872
	if (v->type == VEH_TRAIN && (!IsFrontEngine(v) || v->u.rail.crash_anim_pos >= 4400)) return CMD_ERROR;
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  1873
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1874
	/* check that we can allocate enough vehicles */
2601
d1a193af01e6 (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
  1875
	if (!(flags & DC_EXEC)) {
d1a193af01e6 (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
  1876
		int veh_counter = 0;
d1a193af01e6 (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
  1877
		do {
d1a193af01e6 (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
  1878
			veh_counter++;
d1a193af01e6 (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
  1879
		} while ((v = v->next) != NULL);
d1a193af01e6 (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
  1880
2606
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
  1881
		if (!AllocateVehicles(NULL, veh_counter)) {
715bba67addf (svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents: 2602
diff changeset
  1882
			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
2601
d1a193af01e6 (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
  1883
		}
d1a193af01e6 (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
  1884
	}
d1a193af01e6 (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
  1885
d1a193af01e6 (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
  1886
	v = v_front;
d1a193af01e6 (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
  1887
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1888
	do {
6721
bf2931e39754 (svn r9953) -Fix: Only check whether trains are multiheaded when cloning.
maedhros
parents: 6707
diff changeset
  1889
		if (v->type == VEH_TRAIN && IsMultiheaded(v) && !IsTrainEngine(v)) {
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2666
diff changeset
  1890
			/* we build the rear ends of multiheaded trains with the front ones */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2666
diff changeset
  1891
			continue;
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2666
diff changeset
  1892
		}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2666
diff changeset
  1893
5792
c4dad358b30b (svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents: 5763
diff changeset
  1894
		cost = DoCommand(tile, v->engine_type, build_argument, flags, GetCmdBuildVeh(v));
3819
64c55c77567a (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
  1895
		build_argument = 3; // ensure that we only assign a number to the first engine
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1896
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1897
		if (CmdFailed(cost)) return cost;
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1898
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1899
		total_cost.AddCost(cost);
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1900
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1901
		if (flags & DC_EXEC) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1902
			w = GetVehicle(_new_vehicle_id);
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1903
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1904
			if (v->type == VEH_TRAIN && HASBIT(v->u.rail.flags, VRF_REVERSE_DIRECTION)) {
3896
580ff4e6a49e (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
  1905
				SETBIT(w->u.rail.flags, VRF_REVERSE_DIRECTION);
580ff4e6a49e (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
  1906
			}
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1907
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1908
			if (v->type == VEH_TRAIN && !IsFrontEngine(v)) {
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1909
				/* this s a train car
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1910
				 * add this unit to the end of the train */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  1911
				CommandCost result = DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE);
6838
243a588e6a0d (svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents: 6823
diff changeset
  1912
				if (CmdFailed(result)) {
243a588e6a0d (svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents: 6823
diff changeset
  1913
					/* The train can't be joined to make the same consist as the original.
243a588e6a0d (svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents: 6823
diff changeset
  1914
					 * Sell what we already made (clean up) and return an error.           */
243a588e6a0d (svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents: 6823
diff changeset
  1915
					DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front));
243a588e6a0d (svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents: 6823
diff changeset
  1916
					DoCommand(w_front->tile, w->index,       1, flags, GetCmdSellVeh(w));
243a588e6a0d (svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents: 6823
diff changeset
  1917
					return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE
243a588e6a0d (svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents: 6823
diff changeset
  1918
				}
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1919
			} else {
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1920
				/* this is a front engine or not a train. It need orders */
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1921
				w_front = w;
3679
252b4ab2aad4 (svn r4599) -Fix: [Cloning, autoreplace] FS#141 clone service-interval
bjarni
parents: 3657
diff changeset
  1922
				w->service_interval = v->service_interval;
3491
35d747bb5e82 (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
  1923
				DoCommand(0, (v->index << 16) | w->index, p2 & 1 ? CO_SHARE : CO_COPY, flags, CMD_CLONE_ORDER);
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1924
			}
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4404
diff changeset
  1925
			w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop
2563
abf7a5e73988 (svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents: 2558
diff changeset
  1926
		}
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1927
	} while (v->type == VEH_TRAIN && (v = GetNextVehicle(v)) != NULL);
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1928
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1929
	if (flags & DC_EXEC && v_front->type == VEH_TRAIN) {
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  1930
		/* for trains this needs to be the front engine due to the callback function */
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3896
diff changeset
  1931
		_new_vehicle_id = w_front->index;
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  1932
	}
5062
470335730a60 (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
  1933
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  1934
	if (flags & DC_EXEC) {
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  1935
		/* Cloned vehicles belong to the same group */
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  1936
		DoCommand(0, v_front->group_id, w_front->index, flags, CMD_ADD_VEHICLE_GROUP);
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  1937
	}
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  1938
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  1939
6546
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1940
	/* Take care of refitting. */
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1941
	w = w_front;
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1942
	v = v_front;
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1943
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1944
	/* Both building and refitting are influenced by newgrf callbacks, which
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1945
	 * makes it impossible to accurately estimate the cloning costs. In
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1946
	 * particular, it is possible for engines of the same type to be built with
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1947
	 * different numbers of articulated parts, so when refitting we have to
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1948
	 * loop over real vehicles first, and then the articulated parts of those
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1949
	 * vehicles in a different loop. */
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1950
	do {
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1951
		do {
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1952
			if (flags & DC_EXEC) {
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1953
				assert(w != NULL);
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1954
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1955
				if (w->cargo_type != v->cargo_type || w->cargo_subtype != v->cargo_type) {
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1956
					cost = DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8) | 1U << 16 , flags, GetCmdRefitVeh(v));
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1957
					if (CmdSucceeded(cost)) total_cost.AddCost(cost);
6546
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1958
				}
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1959
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1960
				if (w->type == VEH_TRAIN && EngineHasArticPart(w)) {
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1961
					w = GetNextArticPart(w);
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  1962
				} else if (w->type == VEH_ROAD && RoadVehHasArticPart(w)) {
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  1963
					w = w->next;
6546
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1964
				} else {
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1965
					break;
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1966
				}
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1967
			} else {
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1968
				CargoID initial_cargo = GetEngineCargoType(v->engine_type);
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1969
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1970
				if (v->cargo_type != initial_cargo && initial_cargo != CT_INVALID) {
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1971
					total_cost.AddCost(GetRefitCost(v->engine_type));
6546
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1972
				}
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1973
			}
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  1974
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  1975
			if (v->type == VEH_TRAIN && EngineHasArticPart(v)) {
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  1976
				v = GetNextArticPart(v);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  1977
			} else if (v->type == VEH_ROAD && RoadVehHasArticPart(v)) {
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  1978
				v = v->next;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  1979
			} else {
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  1980
				break;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  1981
			}
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  1982
		} while (v != NULL);
6546
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1983
6727
7b016b7e17af (svn r9959) -Fix: Only call GetNextVehicle for trains.
maedhros
parents: 6724
diff changeset
  1984
		if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = GetNextVehicle(w);
6546
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1985
	} while (v->type == VEH_TRAIN && (v = GetNextVehicle(v)) != NULL);
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1986
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1987
	/* Since we can't estimate the cost of cloning a vehicle accurately we must
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1988
	 * check whether the player has enough money manually. */
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1989
	if (!CheckPlayerHasMoney(total_cost)) {
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1990
		if (flags & DC_EXEC) {
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1991
			/* The vehicle has already been bought, so now it must be sold again. */
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1992
			DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front));
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1993
		}
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1994
		return CMD_ERROR;
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1995
	}
4c6d90bde803 (svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents: 6526
diff changeset
  1996
5062
470335730a60 (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
  1997
	/* Set the expense type last as refitting will make the cost go towards
470335730a60 (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
  1998
	 * running costs... */
470335730a60 (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
  1999
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  2000
	return total_cost;
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  2001
}
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  2002
2552
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  2003
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2004
/* Extend the list size for BuildDepotVehicleList() */
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2005
static inline void ExtendVehicleListSize(const Vehicle ***engine_list, uint16 *engine_list_length, uint16 step_size)
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2006
{
5247
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
  2007
	*engine_list_length = min(*engine_list_length + step_size, GetMaxVehicleIndex() + 1);
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
  2008
	*engine_list = ReallocT(*engine_list, *engine_list_length);
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2009
}
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2010
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2011
/** Generates a list of vehicles inside a depot
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2012
 * Will enlarge allocated space for the list if they are too small, so it's ok to call with (pointer to NULL array, pointer to uninitised uint16, pointer to 0)
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2013
 * If one of the lists is not needed (say wagons when finding ships), all the pointers regarding that list should be set to NULL
6484
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
  2014
 * @param type Type of vehicle
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2015
 * @param tile The tile the depot is located in
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2016
 * @param ***engine_list Pointer to a pointer to an array of vehicles in the depot (old list is freed and a new one is malloced)
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2017
 * @param *engine_list_length Allocated size of engine_list. Needs to be set to 0 when engine_list points to a NULL array
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2018
 * @param *engine_count The number of engines stored in the list
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2019
 * @param ***wagon_list Pointer to a pointer to an array of free wagons in the depot (old list is freed and a new one is malloced)
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2020
 * @param *wagon_list_length Allocated size of wagon_list. Needs to be set to 0 when wagon_list points to a NULL array
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2021
 * @param *wagon_count The number of engines stored in the list
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2022
 */
6641
1b14f8887cb7 (svn r9872) -Codechange: more type strictness for vehicle types
rubidium
parents: 6638
diff changeset
  2023
void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count)
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2024
{
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2025
	Vehicle *v;
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2026
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2027
	/* This function should never be called without an array to store results */
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2028
	assert(!(engine_list == NULL && type != VEH_TRAIN));
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2029
	assert(!(type == VEH_TRAIN && engine_list == NULL && wagon_list == NULL));
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2030
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2031
	/* Both array and the length should either be NULL to disable the list or both should not be NULL */
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2032
	assert((engine_list == NULL && engine_list_length == NULL) || (engine_list != NULL && engine_list_length != NULL));
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2033
	assert((wagon_list == NULL && wagon_list_length == NULL) || (wagon_list != NULL && wagon_list_length != NULL));
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2034
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2035
	assert(!(engine_list != NULL && engine_count == NULL));
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2036
	assert(!(wagon_list != NULL && wagon_count == NULL));
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2037
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2038
	if (engine_count != NULL) *engine_count = 0;
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2039
	if (wagon_count != NULL) *wagon_count = 0;
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2040
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2041
	switch (type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2042
		case VEH_TRAIN:
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2043
			FOR_ALL_VEHICLES(v) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2044
				if (v->tile == tile && v->type == VEH_TRAIN && v->u.rail.track == TRACK_BIT_DEPOT) {
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2045
					if (IsFrontEngine(v)) {
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2046
						if (engine_list == NULL) continue;
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2047
						if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25);
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2048
						(*engine_list)[(*engine_count)++] = v;
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2049
					} else if (IsFreeWagon(v)) {
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2050
						if (wagon_list == NULL) continue;
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2051
						if (*wagon_count == *wagon_list_length) ExtendVehicleListSize((const Vehicle***)wagon_list, wagon_list_length, 25);
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2052
						(*wagon_list)[(*wagon_count)++] = v;
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2053
					}
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2054
				}
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2055
			}
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2056
			break;
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2057
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2058
		case VEH_ROAD:
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2059
			FOR_ALL_VEHICLES(v) {
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  2060
				if (v->tile == tile && v->type == VEH_ROAD && IsRoadVehInDepot(v) && IsRoadVehFront(v)) {
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2061
					if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25);
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2062
					(*engine_list)[(*engine_count)++] = v;
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2063
				}
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2064
			}
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2065
			break;
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2066
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2067
		case VEH_SHIP:
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2068
			FOR_ALL_VEHICLES(v) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2069
				if (v->tile == tile && v->type == VEH_SHIP && IsShipInDepot(v)) {
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2070
					if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25);
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2071
					(*engine_list)[(*engine_count)++] = v;
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2072
				}
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2073
			}
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2074
			break;
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2075
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2076
		case VEH_AIRCRAFT:
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2077
			FOR_ALL_VEHICLES(v) {
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2078
				if (v->tile == tile &&
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2079
						v->type == VEH_AIRCRAFT && IsNormalAircraft(v) &&
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2080
						v->vehstatus & VS_HIDDEN) {
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2081
					if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25);
4635
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2082
					(*engine_list)[(*engine_count)++] = v;
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2083
				}
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2084
			}
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2085
			break;
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2086
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2087
		default: NOT_REACHED();
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2088
	}
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2089
}
1b35cdc018ee (svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents: 4616
diff changeset
  2090
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2091
/**
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2092
* @param sort_list list to store the list in. Either NULL or the length length_of_array tells
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2093
* @param length_of_array informs the length allocated for sort_list. This is not the same as the number of vehicles in the list. Needs to be 0 when sort_list is NULL
4554
8342a6d0a366 (svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents: 4551
diff changeset
  2094
* @param type type of vehicle
8342a6d0a366 (svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents: 4551
diff changeset
  2095
* @param owner PlayerID of owner to generate a list for
6484
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
  2096
* @param index This parameter has different meanings depending on window_type
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
  2097
    <ul>
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
  2098
      <li>VLW_STATION_LIST:  index of station to generate a list for</li>
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
  2099
      <li>VLW_SHARED_ORDERS: index of order to generate a list for<li>
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
  2100
      <li>VLW_STANDARD: not used<li>
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
  2101
      <li>VLW_DEPOT_LIST: TileIndex of the depot/hangar to make the list for</li>
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  2102
      <li>VLW_GROUP_LIST: index of group to generate a list for</li>
6484
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
  2103
    </ul>
4554
8342a6d0a366 (svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents: 4551
diff changeset
  2104
* @param window_type tells what kind of window the list is for. Use the VLW flags in vehicle_gui.h
8342a6d0a366 (svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents: 4551
diff changeset
  2105
* @return the number of vehicles added to the list
8342a6d0a366 (svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents: 4551
diff changeset
  2106
*/
6641
1b14f8887cb7 (svn r9872) -Codechange: more type strictness for vehicle types
rubidium
parents: 6638
diff changeset
  2107
uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type)
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2108
{
4499
ca3e924db010 (svn r6284) -Code Cleanup r6282: cleaned up the code a bit
bjarni
parents: 4497
diff changeset
  2109
	uint n = 0;
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2110
	const Vehicle *v;
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2111
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2112
	switch (window_type) {
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2113
		case VLW_STATION_LIST: {
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2114
			FOR_ALL_VEHICLES(v) {
6773
bc98b0b16ec4 (svn r10009) -Codechange: Add and use Vehicle::IsPrimaryVehicle to replace individual checks depending on the vehicle type.
maedhros
parents: 6727
diff changeset
  2115
				if (v->type == type && v->IsPrimaryVehicle()) {
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2116
					const Order *order;
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2117
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2118
					FOR_VEHICLE_ORDERS(v, order) {
5747
ba5393ff957a (svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument
bjarni
parents: 5746
diff changeset
  2119
						if (order->type == OT_GOTO_STATION && order->dest == index) {
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2120
							if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 50);
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2121
							(*sort_list)[n++] = v;
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2122
							break;
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2123
						}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2124
					}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2125
				}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2126
			}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2127
			break;
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2128
		}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2129
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2130
		case VLW_SHARED_ORDERS: {
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2131
			FOR_ALL_VEHICLES(v) {
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2132
				/* Find a vehicle with the order in question */
5747
ba5393ff957a (svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument
bjarni
parents: 5746
diff changeset
  2133
				if (v->orders != NULL && v->orders->index == index) break;
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2134
			}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2135
5747
ba5393ff957a (svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument
bjarni
parents: 5746
diff changeset
  2136
			if (v != NULL && v->orders != NULL && v->orders->index == index) {
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2137
				/* Only try to make the list if we found a vehicle using the order in question */
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2138
				for (v = GetFirstVehicleFromSharedList(v); v != NULL; v = v->next_shared) {
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2139
					if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25);
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2140
					(*sort_list)[n++] = v;
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2141
				}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2142
			}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2143
			break;
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2144
		}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2145
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2146
		case VLW_STANDARD: {
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2147
			FOR_ALL_VEHICLES(v) {
6773
bc98b0b16ec4 (svn r10009) -Codechange: Add and use Vehicle::IsPrimaryVehicle to replace individual checks depending on the vehicle type.
maedhros
parents: 6727
diff changeset
  2148
				if (v->type == type && v->owner == owner && v->IsPrimaryVehicle()) {
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2149
					/* TODO find a better estimate on the total number of vehicles for current player */
5247
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
  2150
					if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles()/4);
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2151
					(*sort_list)[n++] = v;
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2152
				}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2153
			}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2154
			break;
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2155
		}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2156
4681
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2157
		case VLW_DEPOT_LIST: {
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2158
			FOR_ALL_VEHICLES(v) {
6773
bc98b0b16ec4 (svn r10009) -Codechange: Add and use Vehicle::IsPrimaryVehicle to replace individual checks depending on the vehicle type.
maedhros
parents: 6727
diff changeset
  2159
				if (v->type == type && v->IsPrimaryVehicle()) {
4681
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2160
					const Order *order;
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2161
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2162
					FOR_VEHICLE_ORDERS(v, order) {
5747
ba5393ff957a (svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument
bjarni
parents: 5746
diff changeset
  2163
						if (order->type == OT_GOTO_DEPOT && order->dest == index) {
4681
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2164
							if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25);
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2165
							(*sort_list)[n++] = v;
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2166
							break;
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2167
						}
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2168
					}
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2169
				}
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2170
			}
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2171
			break;
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2172
		}
bc077405e9a8 (svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents: 4678
diff changeset
  2173
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  2174
 		case VLW_GROUP_LIST:
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  2175
			FOR_ALL_VEHICLES(v) {
6773
bc98b0b16ec4 (svn r10009) -Codechange: Add and use Vehicle::IsPrimaryVehicle to replace individual checks depending on the vehicle type.
maedhros
parents: 6727
diff changeset
  2176
				if (v->type == type && v->IsPrimaryVehicle() &&
bc98b0b16ec4 (svn r10009) -Codechange: Add and use Vehicle::IsPrimaryVehicle to replace individual checks depending on the vehicle type.
maedhros
parents: 6727
diff changeset
  2177
						v->owner == owner && v->group_id == index) {
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  2178
					if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles() / 4);
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  2179
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  2180
					(*sort_list)[n++] = v;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  2181
				}
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  2182
			}
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  2183
			break;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  2184
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2185
		default: NOT_REACHED(); break;
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2186
	}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2187
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2188
	if ((n + 100) < *length_of_array) {
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2189
		/* We allocated way too much for sort_list.
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2190
		 * Now we will reduce how much we allocated.
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2191
		 * We will still make it have room for 50 extra vehicles to prevent having
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2192
		 * to move the whole array if just one vehicle is added later */
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2193
		*length_of_array = n + 50;
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
  2194
		*sort_list = ReallocT(*sort_list, (*length_of_array) * sizeof((*sort_list)[0]));
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2195
	}
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2196
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2197
	return n;
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2198
}
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2199
4463
4d67d3a36fc5 (svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents: 4451
diff changeset
  2200
/** send all vehicles of type to depots
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
  2201
 * @param type type of vehicle
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
  2202
 * @param flags the flags used for DoCommand()
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
  2203
 * @param service should the vehicles only get service in the depots
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
  2204
 * @param owner PlayerID of owner of the vehicles to send
6484
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
  2205
 * @param vlw_flag tells what kind of list requested the goto depot
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
  2206
 * @return 0 for success and CMD_ERROR if no vehicle is able to go to depot
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
  2207
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  2208
CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id)
4463
4d67d3a36fc5 (svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents: 4451
diff changeset
  2209
{
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2210
	const Vehicle **sort_list = NULL;
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2211
	uint n, i;
4678
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2212
	uint16 array_length = 0;
e5fe6e4aca39 (svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents: 4676
diff changeset
  2213
5747
ba5393ff957a (svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument
bjarni
parents: 5746
diff changeset
  2214
	n = GenerateVehicleSortList(&sort_list, &array_length, type, owner, id, vlw_flag);
4465
262c344f6f3d (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
  2215
4463
4d67d3a36fc5 (svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents: 4451
diff changeset
  2216
	/* Send all the vehicles to a depot */
4499
ca3e924db010 (svn r6284) -Code Cleanup r6282: cleaned up the code a bit
bjarni
parents: 4497
diff changeset
  2217
	for (i = 0; i < n; i++) {
4497
9d43f65d9e78 (svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents: 4495
diff changeset
  2218
		const Vehicle *v = sort_list[i];
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  2219
		CommandCost ret = DoCommand(v->tile, v->index, (service ? 1 : 0) | DEPOT_DONT_CANCEL, flags, GetCmdSendToDepot(type));
4560
434cb4b568d4 (svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents: 4555
diff changeset
  2220
434cb4b568d4 (svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents: 4555
diff changeset
  2221
		/* Return 0 if DC_EXEC is not set this is a valid goto depot command)
434cb4b568d4 (svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents: 4555
diff changeset
  2222
			* In this case we know that at least one vehicle can be sent to a depot
434cb4b568d4 (svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents: 4555
diff changeset
  2223
			* and we will issue the command. We can now safely quit the loop, knowing
434cb4b568d4 (svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents: 4555
diff changeset
  2224
			* it will succeed at least once. With DC_EXEC we really need to send them to the depot */
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  2225
		if (CmdSucceeded(ret) && !(flags & DC_EXEC)) {
4683
700e6d81e214 (svn r6588) -Fix r6582: killed some windows only warnings (thanks webfreakz for testing)
bjarni
parents: 4681
diff changeset
  2226
			free((void*)sort_list);
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  2227
			return CommandCost();
4463
4d67d3a36fc5 (svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents: 4451
diff changeset
  2228
		}
4d67d3a36fc5 (svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents: 4451
diff changeset
  2229
	}
4465
262c344f6f3d (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
  2230
4683
700e6d81e214 (svn r6588) -Fix r6582: killed some windows only warnings (thanks webfreakz for testing)
bjarni
parents: 4681
diff changeset
  2231
	free((void*)sort_list);
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  2232
	return (flags & DC_EXEC) ? CommandCost() : CMD_ERROR;
4463
4d67d3a36fc5 (svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents: 4451
diff changeset
  2233
}
4d67d3a36fc5 (svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents: 4451
diff changeset
  2234
4734
24b34218c5ce (svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents: 4728
diff changeset
  2235
bool IsVehicleInDepot(const Vehicle *v)
24b34218c5ce (svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents: 4728
diff changeset
  2236
{
24b34218c5ce (svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents: 4728
diff changeset
  2237
	switch (v->type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2238
		case VEH_TRAIN:    return CheckTrainInDepot(v, false) != -1;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2239
		case VEH_ROAD:     return IsRoadVehInDepot(v);
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2240
		case VEH_SHIP:     return IsShipInDepot(v);
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2241
		case VEH_AIRCRAFT: return IsAircraftInHangar(v);
4734
24b34218c5ce (svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents: 4728
diff changeset
  2242
		default: NOT_REACHED();
24b34218c5ce (svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents: 4728
diff changeset
  2243
	}
24b34218c5ce (svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents: 4728
diff changeset
  2244
	return false;
24b34218c5ce (svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents: 4728
diff changeset
  2245
}
24b34218c5ce (svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents: 4728
diff changeset
  2246
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2247
/**
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2248
 * Calculates how full a vehicle is.
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2249
 * @param v The Vehicle to check. For trains, use the first engine.
7014
533521754123 (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents: 7010
diff changeset
  2250
 * @param color The string to show depending on if we are unloading or loading
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2251
 * @return A percentage of how full the Vehicle is.
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2252
 */
7014
533521754123 (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents: 7010
diff changeset
  2253
uint8 CalcPercentVehicleFilled(Vehicle *v, StringID *color)
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2254
{
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2255
	int count = 0;
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2256
	int max = 0;
7014
533521754123 (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents: 7010
diff changeset
  2257
	int cars = 0;
533521754123 (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents: 7010
diff changeset
  2258
	int unloading = 0;
7087
0e076cedc6fd (svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium
parents: 7086
diff changeset
  2259
	bool loading = false;
7014
533521754123 (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents: 7010
diff changeset
  2260
533521754123 (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents: 7010
diff changeset
  2261
	assert(color != NULL);
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2262
7087
0e076cedc6fd (svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium
parents: 7086
diff changeset
  2263
	const Vehicle *u = v;
0e076cedc6fd (svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium
parents: 7086
diff changeset
  2264
	const Station *st = GetStation(v->last_station_visited);
0e076cedc6fd (svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium
parents: 7086
diff changeset
  2265
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2266
	/* Count up max and used */
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2267
	for (; v != NULL; v = v->next) {
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2268
		count += v->cargo.Count();
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2269
		max += v->cargo_cap;
7014
533521754123 (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents: 7010
diff changeset
  2270
		if (v->cargo_cap != 0) {
533521754123 (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents: 7010
diff changeset
  2271
			unloading += HASBIT(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0;
7087
0e076cedc6fd (svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium
parents: 7086
diff changeset
  2272
			loading |= (u->current_order.flags & OF_UNLOAD) == 0 && st->goods[v->cargo_type].days_since_pickup != 255;
7014
533521754123 (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents: 7010
diff changeset
  2273
			cars++;
533521754123 (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents: 7010
diff changeset
  2274
		}
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2275
	}
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2276
7087
0e076cedc6fd (svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium
parents: 7086
diff changeset
  2277
	if (unloading == 0 && loading)          *color = STR_PERCENT_UP;
0e076cedc6fd (svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium
parents: 7086
diff changeset
  2278
	else if (cars == unloading || !loading) *color = STR_PERCENT_DOWN;
0e076cedc6fd (svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium
parents: 7086
diff changeset
  2279
	else                                    *color = STR_PERCENT_UP_DOWN;
7014
533521754123 (svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents: 7010
diff changeset
  2280
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2281
	/* Train without capacity */
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2282
	if (max == 0) return 100;
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2283
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2284
	/* Return the percentage */
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2285
	return (count * 100) / max;
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2286
}
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  2287
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2288
void VehicleEnterDepot(Vehicle *v)
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2289
{
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2290
	switch (v->type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2291
		case VEH_TRAIN:
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2292
			InvalidateWindowClasses(WC_TRAINS_LIST);
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2293
			if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v);
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2294
			UpdateSignalsOnSegment(v->tile, GetRailDepotDirection(v->tile));
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2295
			v->load_unload_time_rem = 0;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2296
			break;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2297
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2298
		case VEH_ROAD:
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2299
			InvalidateWindowClasses(WC_ROADVEH_LIST);
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6838
diff changeset
  2300
			if (!IsRoadVehFront(v)) v = GetFirstVehicleInChain(v);
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2301
			break;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2302
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2303
		case VEH_SHIP:
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2304
			InvalidateWindowClasses(WC_SHIPS_LIST);
5993
956d341d930e (svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium
parents: 5991
diff changeset
  2305
			v->u.ship.state = TRACK_BIT_DEPOT;
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2306
			RecalcShipStuff(v);
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2307
			break;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2308
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2309
		case VEH_AIRCRAFT:
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2310
			InvalidateWindowClasses(WC_AIRCRAFT_LIST);
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2311
			HandleAircraftEnterHangar(v);
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2312
			break;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2313
		default: NOT_REACHED();
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2314
	}
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2315
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2316
	if (v->type != VEH_TRAIN) {
4739
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4736
diff changeset
  2317
		/* Trains update the vehicle list when the first unit enters the depot and calls VehicleEnterDepot() when the last unit enters.
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4736
diff changeset
  2318
		 * 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 */
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4736
diff changeset
  2319
		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4736
diff changeset
  2320
	}
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2321
	InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2322
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2323
	v->vehstatus |= VS_HIDDEN;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2324
	v->cur_speed = 0;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2325
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2326
	VehicleServiceInDepot(v);
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2327
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2328
	TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT);
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2329
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2330
	if (v->current_order.type == OT_GOTO_DEPOT) {
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2331
		Order t;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2332
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2333
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2334
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2335
		t = v->current_order;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2336
		v->current_order.type = OT_DUMMY;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2337
		v->current_order.flags = 0;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2338
4782
6aa485b21dae (svn r6696) -Codechange: changed all comparision for refit cargo in orders against CT_NO_REFIT to checks for valid cargo IDs
bjarni
parents: 4762
diff changeset
  2339
		if (t.refit_cargo < NUM_CARGO) {
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  2340
			CommandCost cost;
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2341
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2342
			_current_player = v->owner;
5792
c4dad358b30b (svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents: 5763
diff changeset
  2343
			cost = DoCommand(v->tile, v->index, t.refit_cargo | t.refit_subtype << 8, DC_EXEC, GetCmdRefitVeh(v));
4783
3d3cbea8b503 (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
  2344
3d3cbea8b503 (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
  2345
			if (CmdFailed(cost)) {
3d3cbea8b503 (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
  2346
				v->leave_depot_instantly = false; // We ensure that the vehicle stays in the depot
3d3cbea8b503 (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
  2347
				if (v->owner == _local_player) {
3d3cbea8b503 (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
  2348
					/* Notify the user that we stopped the vehicle */
5955
fe61588d5188 (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: 5944
diff changeset
  2349
					SetDParam(0, _vehicle_type_names[v->type]);
4783
3d3cbea8b503 (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
  2350
					SetDParam(1, v->unitnumber);
3d3cbea8b503 (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
  2351
					AddNewsItem(STR_ORDER_REFIT_FAILED, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0);
3d3cbea8b503 (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
  2352
				}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  2353
			} else if (v->owner == _local_player && cost.GetCost() != 0) {
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  2354
				ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost.GetCost());
4783
3d3cbea8b503 (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
  2355
			}
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2356
		}
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2357
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2358
		if (HASBIT(t.flags, OFB_PART_OF_ORDERS)) {
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2359
			/* Part of orders */
7070
2f4e1b2facc6 (svn r10335) -Fix (r10331): Increment the current order index *after* using it in UpdateVehicleTimetable.
maedhros
parents: 7038
diff changeset
  2360
			UpdateVehicleTimetable(v, true);
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2361
			v->cur_order_index++;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2362
		} else if (HASBIT(t.flags, OFB_HALT_IN_DEPOT)) {
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2363
			/* Force depot visit */
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2364
			v->vehstatus |= VS_STOPPED;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2365
			if (v->owner == _local_player) {
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2366
				StringID string;
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2367
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2368
				switch (v->type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2369
					case VEH_TRAIN:    string = STR_8814_TRAIN_IS_WAITING_IN_DEPOT; break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2370
					case VEH_ROAD:     string = STR_9016_ROAD_VEHICLE_IS_WAITING;   break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2371
					case VEH_SHIP:     string = STR_981C_SHIP_IS_WAITING_IN_DEPOT;  break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2372
					case VEH_AIRCRAFT: string = STR_A014_AIRCRAFT_IS_WAITING_IN;    break;
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2373
					default: NOT_REACHED(); string = STR_EMPTY; // Set the string to something to avoid a compiler warning
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2374
				}
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2375
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2376
				SetDParam(0, v->unitnumber);
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6491
diff changeset
  2377
				AddNewsItem(string, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0);
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2378
			}
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2379
		}
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2380
	}
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4712
diff changeset
  2381
}
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  2382
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2383
static bool IsUniqueVehicleName(const char *name)
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2384
{
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2385
	const Vehicle *v;
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2386
	char buf[512];
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2387
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2388
	FOR_ALL_VEHICLES(v) {
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2389
		switch (v->type) {
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2390
			case VEH_TRAIN:
7108
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2391
				if (!IsTrainEngine(v)) continue;
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2392
				break;
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2393
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2394
			case VEH_ROAD:
7108
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2395
				break;
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2396
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2397
			case VEH_AIRCRAFT:
7108
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2398
				if (!IsNormalAircraft(v)) continue;
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2399
				break;
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2400
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2401
			case VEH_SHIP:
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2402
				break;
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2403
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2404
			default:
7108
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2405
				continue;
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2406
		}
7108
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2407
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2408
		SetDParam(0, v->index);
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2409
		GetString(buf, STR_VEHICLE_NAME, lastof(buf));
fef4440c4063 (svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents: 7097
diff changeset
  2410
		if (strcmp(buf, name) == 0) return false;
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2411
	}
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2412
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2413
	return true;
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2414
}
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2415
1786
7cfd46c3fcc4 (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
  2416
/** Give a custom name to your vehicle
3491
35d747bb5e82 (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
  2417
 * @param tile unused
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2418
 * @param flags type of operation
1786
7cfd46c3fcc4 (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
  2419
 * @param p1 vehicle ID to name
7cfd46c3fcc4 (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
  2420
 * @param p2 unused
7cfd46c3fcc4 (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
  2421
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  2422
CommandCost CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2423
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2424
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2425
	StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2426
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2427
	if (!IsValidVehicleID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR;
1237
1c7a3f9c94b9 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1217
diff changeset
  2428
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
  2429
	v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2430
1786
7cfd46c3fcc4 (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
  2431
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2432
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2433
	if (!IsUniqueVehicleName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2434
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7096
diff changeset
  2435
	str = AllocateName(_cmd_text, 2);
1786
7cfd46c3fcc4 (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
  2436
	if (str == 0) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  2437
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2438
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2439
		StringID old_str = v->string_id;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2440
		v->string_id = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2441
		DeleteName(old_str);
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 585
diff changeset
  2442
		ResortVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2443
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2444
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2445
		DeleteName(str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2446
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2447
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  2448
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2449
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2450
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2451
2819
f25fb6ee397f (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
  2452
/** Change the service interval of a vehicle
3491
35d747bb5e82 (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
  2453
 * @param tile unused
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2454
 * @param flags type of operation
2819
f25fb6ee397f (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
  2455
 * @param p1 vehicle ID that is being service-interval-changed
f25fb6ee397f (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
  2456
 * @param p2 new service interval
f25fb6ee397f (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
  2457
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6905
diff changeset
  2458
CommandCost CmdChangeServiceInt(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
2819
f25fb6ee397f (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
  2459
{
f25fb6ee397f (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
  2460
	Vehicle* v;
f25fb6ee397f (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
  2461
	uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */
f25fb6ee397f (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
  2462
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4346
diff changeset
  2463
	if (serv_int != p2 || !IsValidVehicleID(p1)) return CMD_ERROR;
2819
f25fb6ee397f (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
  2464
f25fb6ee397f (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
  2465
	v = GetVehicle(p1);
f25fb6ee397f (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
  2466
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4346
diff changeset
  2467
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
2819
f25fb6ee397f (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
  2468
f25fb6ee397f (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
  2469
	if (flags & DC_EXEC) {
f25fb6ee397f (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
  2470
		v->service_interval = serv_int;
f25fb6ee397f (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
  2471
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
f25fb6ee397f (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
  2472
	}
f25fb6ee397f (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
  2473
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  2474
	return CommandCost();
2819
f25fb6ee397f (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
  2475
}
f25fb6ee397f (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
  2476
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2477
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2478
static Rect _old_vehicle_coords;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2479
7321
f91bdca345e8 (svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents: 7273
diff changeset
  2480
void BeginVehicleMove(Vehicle *v)
f91bdca345e8 (svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents: 7273
diff changeset
  2481
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2482
	_old_vehicle_coords.left = v->left_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2483
	_old_vehicle_coords.top = v->top_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2484
	_old_vehicle_coords.right = v->right_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2485
	_old_vehicle_coords.bottom = v->bottom_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2486
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2487
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2488
void EndVehicleMove(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2489
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2490
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2491
		min(_old_vehicle_coords.left,v->left_coord),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2492
		min(_old_vehicle_coords.top,v->top_coord),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2493
		max(_old_vehicle_coords.right,v->right_coord)+1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2494
		max(_old_vehicle_coords.bottom,v->bottom_coord)+1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2495
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2496
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2497
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2498
/* returns true if staying in the same tile */
6153
eb35b73b300a (svn r8897) -Fix
tron
parents: 6152
diff changeset
  2499
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2500
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2501
	static const int8 _delta_coord[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2502
		-1,-1,-1, 0, 1, 1, 1, 0, /* x */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2503
		-1, 0, 1, 1, 1, 0,-1,-1, /* y */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2504
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2505
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2506
	int x = v->x_pos + _delta_coord[v->direction];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2507
	int y = v->y_pos + _delta_coord[v->direction + 8];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2508
6153
eb35b73b300a (svn r8897) -Fix
tron
parents: 6152
diff changeset
  2509
	GetNewVehiclePosResult gp;
eb35b73b300a (svn r8897) -Fix
tron
parents: 6152
diff changeset
  2510
	gp.x = x;
eb35b73b300a (svn r8897) -Fix
tron
parents: 6152
diff changeset
  2511
	gp.y = y;
eb35b73b300a (svn r8897) -Fix
tron
parents: 6152
diff changeset
  2512
	gp.old_tile = v->tile;
eb35b73b300a (svn r8897) -Fix
tron
parents: 6152
diff changeset
  2513
	gp.new_tile = TileVirtXY(x, y);
eb35b73b300a (svn r8897) -Fix
tron
parents: 6152
diff changeset
  2514
	return gp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2515
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2516
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3139
diff changeset
  2517
static const Direction _new_direction_table[] = {
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3139
diff changeset
  2518
	DIR_N , DIR_NW, DIR_W ,
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3139
diff changeset
  2519
	DIR_NE, DIR_SE, DIR_SW,
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3139
diff changeset
  2520
	DIR_E , DIR_SE, DIR_S
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2521
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2522
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3139
diff changeset
  2523
Direction GetDirectionTowards(const Vehicle* v, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2524
{
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3139
diff changeset
  2525
	Direction dir;
3158
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
  2526
	DirDiff dirdiff;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2527
	int i = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2528
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2529
	if (y >= v->y_pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2530
		if (y != v->y_pos) i+=3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2531
		i+=3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2532
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2533
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2534
	if (x >= v->x_pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2535
		if (x != v->x_pos) i++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2536
		i++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2537
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2538
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2539
	dir = v->direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2540
3158
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
  2541
	dirdiff = DirDifference(_new_direction_table[i], dir);
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
  2542
	if (dirdiff == DIRDIFF_SAME) return dir;
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
  2543
	return ChangeDir(dir, dirdiff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2544
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2545
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
  2546
Trackdir GetVehicleTrackdir(const Vehicle* v)
1752
d65cd19f7117 (svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents: 1735
diff changeset
  2547
{
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2548
	if (v->vehstatus & VS_CRASHED) return INVALID_TRACKDIR;
1758
2158a0938e45 (svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents: 1757
diff changeset
  2549
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
  2550
	switch (v->type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2551
		case VEH_TRAIN:
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2552
			if (v->u.rail.track == TRACK_BIT_DEPOT) // We'll assume the train is facing outwards
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2553
				return DiagdirToDiagTrackdir(GetRailDepotDirection(v->tile)); // Train in depot
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2554
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2555
			if (v->u.rail.track == TRACK_BIT_WORMHOLE) // train in tunnel, so just use his direction and assume a diagonal track
3161
c0c237a63373 (svn r3787) Use DirToDiagDir() instead of >> 1
tron
parents: 3158
diff changeset
  2556
				return DiagdirToDiagTrackdir(DirToDiagDir(v->direction));
1765
155dfdbbbc8d (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
  2557
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2558
			return TrackDirectionToTrackdir(FindFirstTrack(v->u.rail.track), v->direction);
1959
c2c3a9850c2e (svn r2465) Remove some unreachable code
tron
parents: 1944
diff changeset
  2559
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2560
		case VEH_SHIP:
3961
9868b766fda7 (svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents: 3959
diff changeset
  2561
			if (IsShipInDepot(v))
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2562
				// We'll assume the ship is facing outwards
3953
e64bbd8598e2 (svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents: 3948
diff changeset
  2563
				return DiagdirToDiagTrackdir(GetShipDepotDirection(v->tile));
1765
155dfdbbbc8d (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
  2564
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2565
			return TrackDirectionToTrackdir(FindFirstTrack(v->u.ship.state), v->direction);
1959
c2c3a9850c2e (svn r2465) Remove some unreachable code
tron
parents: 1944
diff changeset
  2566
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2567
		case VEH_ROAD:
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2568
			if (IsRoadVehInDepot(v)) // We'll assume the road vehicle is facing outwards
3179
8ef3e8028af5 (svn r3816) Use existing accessors
tron
parents: 3175
diff changeset
  2569
				return DiagdirToDiagTrackdir(GetRoadDepotDirection(v->tile));
1765
155dfdbbbc8d (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
  2570
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2571
			if (IsStandardRoadStopTile(v->tile)) // We'll assume the road vehicle is facing outwards
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2572
				return DiagdirToDiagTrackdir(GetRoadStopDir(v->tile)); // Road vehicle in a station
1765
155dfdbbbc8d (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
  2573
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6009
diff changeset
  2574
			if (IsDriveThroughStopTile(v->tile)) return DiagdirToDiagTrackdir(DirToDiagDir(v->direction));
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6009
diff changeset
  2575
4270
923ac6b88dad (svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents: 4263
diff changeset
  2576
			/* If vehicle's state is a valid track direction (vehicle is not turning around) return it */
6009
bbe756070082 (svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents: 6000
diff changeset
  2577
			if (!IsReversingRoadTrackdir((Trackdir)v->u.road.state)) return (Trackdir)v->u.road.state;
4270
923ac6b88dad (svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents: 4263
diff changeset
  2578
923ac6b88dad (svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents: 4263
diff changeset
  2579
			/* Vehicle is turning around, get the direction from vehicle's direction */
3161
c0c237a63373 (svn r3787) Use DirToDiagDir() instead of >> 1
tron
parents: 3158
diff changeset
  2580
			return DiagdirToDiagTrackdir(DirToDiagDir(v->direction));
1959
c2c3a9850c2e (svn r2465) Remove some unreachable code
tron
parents: 1944
diff changeset
  2581
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2582
		/* case VEH_AIRCRAFT: case VEH_SPECIAL: case VEH_DISASTER: */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2583
		default: return INVALID_TRACKDIR;
1752
d65cd19f7117 (svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents: 1735
diff changeset
  2584
	}
d65cd19f7117 (svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents: 1735
diff changeset
  2585
}
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5955
diff changeset
  2586
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5955
diff changeset
  2587
/**
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5955
diff changeset
  2588
 * Returns some meta-data over the to be entered tile.
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5955
diff changeset
  2589
 * @see VehicleEnterTileStatus to see what the bits in the return value mean.
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5955
diff changeset
  2590
 */
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  2591
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
  2592
{
3657
eb28d97d3d18 (svn r4572) Remove vehicle_leave_tile_proc
tron
parents: 3645
diff changeset
  2593
	return _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2594
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2595
6641
1b14f8887cb7 (svn r9872) -Codechange: more type strictness for vehicle types
rubidium
parents: 6638
diff changeset
  2596
UnitID GetFreeUnitNumber(VehicleType type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2597
{
3018
22ede527b855 (svn r3598) -Fix: suppress invalid warning by assigning value to variable
truelight
parents: 3009
diff changeset
  2598
	UnitID unit, max = 0;
2995
fcc4c71eccda (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
  2599
	const Vehicle *u;
fcc4c71eccda (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
  2600
	static bool *cache = NULL;
fcc4c71eccda (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
  2601
	static UnitID gmax = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2602
2995
fcc4c71eccda (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
  2603
	switch (type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2604
		case VEH_TRAIN:    max = _patches.max_trains; break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2605
		case VEH_ROAD:     max = _patches.max_roadveh; break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2606
		case VEH_SHIP:     max = _patches.max_ships; break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2607
		case VEH_AIRCRAFT: max = _patches.max_aircraft; break;
2996
9d77b3aec341 (svn r3573) - Replace assert(0) with NOT_REACHED(). This commit sponsored by "giving Darkvater credit for the last three".
peter1138
parents: 2995
diff changeset
  2608
		default: NOT_REACHED();
2995
fcc4c71eccda (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
  2609
	}
fcc4c71eccda (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
  2610
4096
3ee959ce63c9 (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
  2611
	if (max == 0) {
3ee959ce63c9 (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
  2612
		/* we can't build any of this kind of vehicle, so we just return 1 instead of looking for a free number
3ee959ce63c9 (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
  2613
		 * a max of 0 will cause the following code to write to a NULL pointer
3ee959ce63c9 (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
  2614
		 * We know that 1 is bigger than the max allowed vehicle number, so it's the same as returning something, that is too big
3ee959ce63c9 (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
  2615
		 */
3ee959ce63c9 (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
  2616
		return 1;
3ee959ce63c9 (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
  2617
	}
3ee959ce63c9 (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
  2618
2995
fcc4c71eccda (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
  2619
	if (max > gmax) {
fcc4c71eccda (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
  2620
		gmax = max;
fcc4c71eccda (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
  2621
		free(cache);
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
  2622
		cache = MallocT<bool>(max + 1);
2995
fcc4c71eccda (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
  2623
	}
fcc4c71eccda (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
  2624
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2625
	/* Clear the cache */
2995
fcc4c71eccda (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
  2626
	memset(cache, 0, (max + 1) * sizeof(*cache));
fcc4c71eccda (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
  2627
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2628
	/* Fill the cache */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2629
	FOR_ALL_VEHICLES(u) {
2995
fcc4c71eccda (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
  2630
		if (u->type == type && u->owner == _current_player && u->unitnumber != 0 && u->unitnumber <= max)
fcc4c71eccda (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
  2631
			cache[u->unitnumber] = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2632
	}
2995
fcc4c71eccda (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
  2633
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2634
	/* Find the first unused unit number */
2995
fcc4c71eccda (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
  2635
	for (unit = 1; unit <= max; unit++) {
fcc4c71eccda (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
  2636
		if (!cache[unit]) break;
fcc4c71eccda (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
  2637
	}
fcc4c71eccda (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
  2638
fcc4c71eccda (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
  2639
	return unit;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2640
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2641
6516
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2642
7086
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2643
/**
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2644
 * Check whether we can build infrastructure for the given
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2645
 * vehicle type. This to disable building stations etc. when
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2646
 * you are not allowed/able to have the vehicle type yet.
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2647
 * @param type the vehicle type to check this for
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2648
 * @return true if there is any reason why you may build
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2649
 *         the infrastructure for the given vehicle type
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2650
 */
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2651
bool CanBuildVehicleInfrastructure(VehicleType type)
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2652
{
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2653
	assert(IsPlayerBuildableVehicleType(type));
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2654
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2655
	if (_patches.always_build_infrastructure) return true;
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2656
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2657
	UnitID max;
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2658
	switch (type) {
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2659
		case VEH_TRAIN:    max = _patches.max_trains; break;
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2660
		case VEH_ROAD:     max = _patches.max_roadveh; break;
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2661
		case VEH_SHIP:     max = _patches.max_ships; break;
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2662
		case VEH_AIRCRAFT: max = _patches.max_aircraft; break;
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2663
		default: NOT_REACHED();
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2664
	}
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2665
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2666
	/* We can build vehicle infrastructure when we may build the vehicle type */
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2667
	if (max > 0) {
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2668
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2669
		/* Can we actually build the vehicle type? */
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2670
		EngineID e;
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2671
		FOR_ALL_ENGINEIDS_OF_TYPE(e, type) {
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2672
			if (HASBIT(GetEngine(e)->player_avail, _local_player)) return true;
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2673
		}
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2674
		return false;
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2675
	}
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2676
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2677
	/* We should be able to build infrastructure when we have the actual vehicle type */
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2678
	const Vehicle *v;
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2679
	FOR_ALL_VEHICLES(v) {
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2680
		if (v->owner == _local_player && v->type == type) return true;
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2681
	}
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2682
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2683
	return false;
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2684
}
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2685
de7e83fb1602 (svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents: 7076
diff changeset
  2686
6516
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2687
const Livery *GetEngineLivery(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v)
3040
7043c0de7c6d (svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents: 3039
diff changeset
  2688
{
4603
20c816f664de (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
  2689
	const Player *p = GetPlayer(player);
20c816f664de (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
  2690
	LiveryScheme scheme = LS_DEFAULT;
5717
b6fb89cd9cce (svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents: 5693
diff changeset
  2691
	CargoID cargo_type = v == NULL ? (CargoID)CT_INVALID : v->cargo_type;
b6fb89cd9cce (svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents: 5693
diff changeset
  2692
4603
20c816f664de (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
  2693
	/* The default livery is always available for use, but its in_use flag determines
20c816f664de (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
  2694
	 * whether any _other_ liveries are in use. */
4616
3c22e5eb5ffe (svn r6474) - Add a patch option to control display of liveries, allowing none, your
peter1138
parents: 4613
diff changeset
  2695
	if (p->livery[LS_DEFAULT].in_use && (_patches.liveries == 2 || (_patches.liveries == 1 && player == _local_player))) {
4603
20c816f664de (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
  2696
		/* Determine the livery scheme to use */
20c816f664de (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
  2697
		switch (GetEngine(engine_type)->type) {
6638
09c5d7bf69a5 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 6626
diff changeset
  2698
			default: NOT_REACHED();
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2699
			case VEH_TRAIN: {
5763
a6029daa547f (svn r8314) -Fix
tron
parents: 5748
diff changeset
  2700
				const RailVehicleInfo *rvi = RailVehInfo(engine_type);
a6029daa547f (svn r8314) -Fix
tron
parents: 5748
diff changeset
  2701
a6029daa547f (svn r8314) -Fix
tron
parents: 5748
diff changeset
  2702
				switch (rvi->railtype) {
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5794
diff changeset
  2703
					default: NOT_REACHED();
4603
20c816f664de (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
  2704
					case RAILTYPE_RAIL:
20c816f664de (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
  2705
					case RAILTYPE_ELECTRIC:
20c816f664de (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
  2706
					{
20c816f664de (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
  2707
						if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type;
5868
94430141c189 (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 5866
diff changeset
  2708
						if (rvi->railveh_type == RAILVEH_WAGON) {
6658
fdd0a344784b (svn r9889) -Codechange: Use cargo's freight status for choosing livery scheme.
peter1138
parents: 6647
diff changeset
  2709
							if (!GetCargo(cargo_type)->is_freight) {
4604
50d4768623b0 (svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents: 4603
diff changeset
  2710
								if (parent_engine_type == INVALID_ENGINE) {
50d4768623b0 (svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents: 4603
diff changeset
  2711
									scheme = LS_PASSENGER_WAGON_STEAM;
50d4768623b0 (svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents: 4603
diff changeset
  2712
								} else {
50d4768623b0 (svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents: 4603
diff changeset
  2713
									switch (RailVehInfo(parent_engine_type)->engclass) {
6585
46035c6baa8d (svn r9799) -Codechange: separate engine class and engine running cost class (mart3p).
rubidium
parents: 6581
diff changeset
  2714
										default: NOT_REACHED();
6581
3641873f4f3f (svn r9795) -Codechange: enumify the EngineClass.
rubidium
parents: 6580
diff changeset
  2715
										case EC_STEAM:    scheme = LS_PASSENGER_WAGON_STEAM;    break;
3641873f4f3f (svn r9795) -Codechange: enumify the EngineClass.
rubidium
parents: 6580
diff changeset
  2716
										case EC_DIESEL:   scheme = LS_PASSENGER_WAGON_DIESEL;   break;
3641873f4f3f (svn r9795) -Codechange: enumify the EngineClass.
rubidium
parents: 6580
diff changeset
  2717
										case EC_ELECTRIC: scheme = LS_PASSENGER_WAGON_ELECTRIC; break;
4604
50d4768623b0 (svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents: 4603
diff changeset
  2718
									}
50d4768623b0 (svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents: 4603
diff changeset
  2719
								}
50d4768623b0 (svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents: 4603
diff changeset
  2720
							} else {
50d4768623b0 (svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents: 4603
diff changeset
  2721
								scheme = LS_FREIGHT_WAGON;
50d4768623b0 (svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents: 4603
diff changeset
  2722
							}
4603
20c816f664de (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
  2723
						} else {
7273
6cbc9e849d99 (svn r10603) -Codechange: avoid direct access to _engine_info
peter1138
parents: 7232
diff changeset
  2724
							bool is_mu = HASBIT(EngInfo(engine_type)->misc_flags, EF_RAIL_IS_MU);
4603
20c816f664de (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
  2725
20c816f664de (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
  2726
							switch (rvi->engclass) {
6585
46035c6baa8d (svn r9799) -Codechange: separate engine class and engine running cost class (mart3p).
rubidium
parents: 6581
diff changeset
  2727
								default: NOT_REACHED();
6581
3641873f4f3f (svn r9795) -Codechange: enumify the EngineClass.
rubidium
parents: 6580
diff changeset
  2728
								case EC_STEAM:    scheme = LS_STEAM; break;
3641873f4f3f (svn r9795) -Codechange: enumify the EngineClass.
rubidium
parents: 6580
diff changeset
  2729
								case EC_DIESEL:   scheme = is_mu ? LS_DMU : LS_DIESEL;   break;
3641873f4f3f (svn r9795) -Codechange: enumify the EngineClass.
rubidium
parents: 6580
diff changeset
  2730
								case EC_ELECTRIC: scheme = is_mu ? LS_EMU : LS_ELECTRIC; break;
4603
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
  2731
							}
20c816f664de (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
  2732
						}
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
  2733
						break;
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
  2734
					}
20c816f664de (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
  2735
20c816f664de (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
  2736
					case RAILTYPE_MONO: scheme = LS_MONORAIL; break;
20c816f664de (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
  2737
					case RAILTYPE_MAGLEV: scheme = LS_MAGLEV; break;
20c816f664de (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
  2738
				}
20c816f664de (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
  2739
				break;
20c816f664de (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
  2740
			}
20c816f664de (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
  2741
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2742
			case VEH_ROAD: {
4603
20c816f664de (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
  2743
				const RoadVehicleInfo *rvi = RoadVehInfo(engine_type);
20c816f664de (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
  2744
				if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type;
6724
4f404dfe9752 (svn r9956) -Codechange: Add tram livery schemes
peter1138
parents: 6721
diff changeset
  2745
				if (HASBIT(EngInfo(engine_type)->misc_flags, EF_ROAD_TRAM)) {
4f404dfe9752 (svn r9956) -Codechange: Add tram livery schemes
peter1138
parents: 6721
diff changeset
  2746
					/* Tram */
4f404dfe9752 (svn r9956) -Codechange: Add tram livery schemes
peter1138
parents: 6721
diff changeset
  2747
					scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM;
4f404dfe9752 (svn r9956) -Codechange: Add tram livery schemes
peter1138
parents: 6721
diff changeset
  2748
				} else {
4f404dfe9752 (svn r9956) -Codechange: Add tram livery schemes
peter1138
parents: 6721
diff changeset
  2749
					/* Bus or truck */
4f404dfe9752 (svn r9956) -Codechange: Add tram livery schemes
peter1138
parents: 6721
diff changeset
  2750
					scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_BUS : LS_TRUCK;
4f404dfe9752 (svn r9956) -Codechange: Add tram livery schemes
peter1138
parents: 6721
diff changeset
  2751
				}
4603
20c816f664de (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
  2752
				break;
20c816f664de (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
  2753
			}
20c816f664de (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
  2754
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2755
			case VEH_SHIP: {
4603
20c816f664de (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
  2756
				const ShipVehicleInfo *svi = ShipVehInfo(engine_type);
20c816f664de (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
  2757
				if (cargo_type == CT_INVALID) cargo_type = svi->cargo_type;
6330
989ca49d0da3 (svn r9302) -Codechange: Use cargo class to test for passengers when deciding on the livery scheme to use.
peter1138
parents: 6264
diff changeset
  2758
				scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_SHIP : LS_FREIGHT_SHIP;
4603
20c816f664de (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
  2759
				break;
20c816f664de (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
  2760
			}
20c816f664de (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
  2761
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2762
			case VEH_AIRCRAFT: {
4603
20c816f664de (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
  2763
				const AircraftVehicleInfo *avi = AircraftVehInfo(engine_type);
20c816f664de (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
  2764
				if (cargo_type == CT_INVALID) cargo_type = CT_PASSENGERS;
20c816f664de (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
  2765
				switch (avi->subtype) {
5855
6f273e99a57a (svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater
parents: 5854
diff changeset
  2766
					case AIR_HELI: scheme = LS_HELICOPTER; break;
6f273e99a57a (svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater
parents: 5854
diff changeset
  2767
					case AIR_CTOL: scheme = LS_SMALL_PLANE; break;
6f273e99a57a (svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater
parents: 5854
diff changeset
  2768
					case AIR_CTOL | AIR_FAST: scheme = LS_LARGE_PLANE; break;
4603
20c816f664de (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
  2769
				}
20c816f664de (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
  2770
				break;
20c816f664de (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
  2771
			}
20c816f664de (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
  2772
		}
20c816f664de (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
  2773
20c816f664de (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
  2774
		/* Switch back to the default scheme if the resolved scheme is not in use */
20c816f664de (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
  2775
		if (!p->livery[scheme].in_use) scheme = LS_DEFAULT;
20c816f664de (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
  2776
	}
20c816f664de (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
  2777
6516
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2778
	return &p->livery[scheme];
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2779
}
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2780
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2781
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2782
static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v)
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2783
{
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2784
	SpriteID map = PAL_NONE;
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2785
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2786
	/* Check if we should use the colour map callback */
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2787
	if (HASBIT(EngInfo(engine_type)->callbackmask, CBM_COLOUR_REMAP)) {
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2788
		uint16 callback = GetVehicleCallback(CBID_VEHICLE_COLOUR_MAPPING, 0, 0, engine_type, v);
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2789
		/* A return value of 0xC000 is stated to "use the default two-color
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2790
		 * maps" which happens to be the failure action too... */
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2791
		if (callback != CALLBACK_FAILED && callback != 0xC000) {
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2792
			map = GB(callback, 0, 14);
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2793
			/* If bit 14 is set, then the company colours are applied to the
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2794
			 * map else it's returned as-is. */
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2795
			if (!HASBIT(callback, 14)) return map;
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2796
		}
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2797
	}
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2798
5717
b6fb89cd9cce (svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents: 5693
diff changeset
  2799
	bool twocc = HASBIT(EngInfo(engine_type)->misc_flags, EF_USES_2CC);
b6fb89cd9cce (svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents: 5693
diff changeset
  2800
b6fb89cd9cce (svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents: 5693
diff changeset
  2801
	if (map == PAL_NONE) map = twocc ? (SpriteID)SPR_2CCMAP_BASE : (SpriteID)PALETTE_RECOLOR_START;
b6fb89cd9cce (svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents: 5693
diff changeset
  2802
6516
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2803
	const Livery *livery = GetEngineLivery(engine_type, player, parent_engine_type, v);
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2804
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2805
	map += livery->colour1;
0d14650b196b (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents: 6509
diff changeset
  2806
	if (twocc) map += livery->colour2 * 16;
3113
d79500c648da (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
  2807
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5651
diff changeset
  2808
	return map;
3040
7043c0de7c6d (svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents: 3039
diff changeset
  2809
}
7043c0de7c6d (svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents: 3039
diff changeset
  2810
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5651
diff changeset
  2811
SpriteID GetEnginePalette(EngineID engine_type, PlayerID player)
3105
02f849f946d0 (svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents: 3047
diff changeset
  2812
{
5717
b6fb89cd9cce (svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents: 5693
diff changeset
  2813
	return GetEngineColourMap(engine_type, player, INVALID_ENGINE, NULL);
3105
02f849f946d0 (svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents: 3047
diff changeset
  2814
}
02f849f946d0 (svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents: 3047
diff changeset
  2815
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5651
diff changeset
  2816
SpriteID GetVehiclePalette(const Vehicle *v)
3105
02f849f946d0 (svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents: 3047
diff changeset
  2817
{
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2818
	if (v->type == VEH_TRAIN) {
4603
20c816f664de (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
  2819
		return GetEngineColourMap(
6809
0f306c3e1030 (svn r10048) -Fix (r6455): Don't use override engine type for articulated wagon parts.
peter1138
parents: 6782
diff changeset
  2820
			(v->u.rail.first_engine != INVALID_ENGINE && (UsesWagonOverride(v) || (IsArticulatedPart(v) && RailVehInfo(v->engine_type)->railveh_type != RAILVEH_WAGON))) ?
4603
20c816f664de (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
  2821
				v->u.rail.first_engine : v->engine_type,
5717
b6fb89cd9cce (svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents: 5693
diff changeset
  2822
			v->owner, v->u.rail.first_engine, v);
4603
20c816f664de (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
  2823
	}
20c816f664de (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
  2824
5717
b6fb89cd9cce (svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents: 5693
diff changeset
  2825
	return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v);
3105
02f849f946d0 (svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents: 3047
diff changeset
  2826
}
02f849f946d0 (svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents: 3047
diff changeset
  2827
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2828
static uint8  _cargo_days;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2829
static uint16 _cargo_source;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2830
static uint32 _cargo_source_xy;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2831
static uint16 _cargo_count;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2832
static uint16 _cargo_paid_for;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2833
static Money  _cargo_feeder_share;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2834
static uint32 _cargo_loaded_at_xy;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2835
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2836
/** Save and load of vehicles */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2837
extern const SaveLoad _common_veh_desc[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2838
	    SLE_VAR(Vehicle, subtype,              SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2839
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2840
	    SLE_REF(Vehicle, next,                 REF_VEHICLE_OLD),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2841
	    SLE_VAR(Vehicle, string_id,            SLE_STRINGID),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2842
	SLE_CONDVAR(Vehicle, unitnumber,           SLE_FILE_U8  | SLE_VAR_U16,  0, 7),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2843
	SLE_CONDVAR(Vehicle, unitnumber,           SLE_UINT16,                  8, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2844
	    SLE_VAR(Vehicle, owner,                SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2845
	SLE_CONDVAR(Vehicle, tile,                 SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2846
	SLE_CONDVAR(Vehicle, tile,                 SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2847
	SLE_CONDVAR(Vehicle, dest_tile,            SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2848
	SLE_CONDVAR(Vehicle, dest_tile,            SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2849
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2850
	SLE_CONDVAR(Vehicle, x_pos,                SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2851
	SLE_CONDVAR(Vehicle, x_pos,                SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2852
	SLE_CONDVAR(Vehicle, y_pos,                SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2853
	SLE_CONDVAR(Vehicle, y_pos,                SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2854
	    SLE_VAR(Vehicle, z_pos,                SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2855
	    SLE_VAR(Vehicle, direction,            SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2856
6561
073e48516812 (svn r9763) -Codechange/Fix (r9760): don't read the variables that are calculated automatically either.
rubidium
parents: 6558
diff changeset
  2857
	SLE_CONDNULL(2,                                                         0, 57),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2858
	    SLE_VAR(Vehicle, spritenum,            SLE_UINT8),
6561
073e48516812 (svn r9763) -Codechange/Fix (r9760): don't read the variables that are calculated automatically either.
rubidium
parents: 6558
diff changeset
  2859
	SLE_CONDNULL(5,                                                         0, 57),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2860
	    SLE_VAR(Vehicle, engine_type,          SLE_UINT16),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2861
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2862
	    SLE_VAR(Vehicle, max_speed,            SLE_UINT16),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2863
	    SLE_VAR(Vehicle, cur_speed,            SLE_UINT16),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2864
	    SLE_VAR(Vehicle, subspeed,             SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2865
	    SLE_VAR(Vehicle, acceleration,         SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2866
	    SLE_VAR(Vehicle, progress,             SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2867
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2868
	    SLE_VAR(Vehicle, vehstatus,            SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2869
	SLE_CONDVAR(Vehicle, last_station_visited, SLE_FILE_U8  | SLE_VAR_U16,  0, 4),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2870
	SLE_CONDVAR(Vehicle, last_station_visited, SLE_UINT16,                  5, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2871
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2872
	     SLE_VAR(Vehicle, cargo_type,           SLE_UINT8),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2873
	 SLE_CONDVAR(Vehicle, cargo_subtype,        SLE_UINT8,                  35, SL_MAX_VERSION),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2874
	SLEG_CONDVAR(         _cargo_days,          SLE_UINT8,                   0, 67),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2875
	SLEG_CONDVAR(         _cargo_source,        SLE_FILE_U8  | SLE_VAR_U16,  0, 6),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2876
	SLEG_CONDVAR(         _cargo_source,        SLE_UINT16,                  7, 67),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2877
	SLEG_CONDVAR(         _cargo_source_xy,     SLE_UINT32,                 44, 67),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2878
	     SLE_VAR(Vehicle, cargo_cap,            SLE_UINT16),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2879
	SLEG_CONDVAR(         _cargo_count,         SLE_UINT16,                  0, 67),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2880
	 SLE_CONDLST(Vehicle, cargo,                REF_CARGO_PACKET,           68, SL_MAX_VERSION),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2881
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2882
	    SLE_VAR(Vehicle, day_counter,          SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2883
	    SLE_VAR(Vehicle, tick_counter,         SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2884
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2885
	    SLE_VAR(Vehicle, cur_order_index,      SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2886
	    SLE_VAR(Vehicle, num_orders,           SLE_UINT8),
956
dda0863632df (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2887
dda0863632df (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2888
	/* This next line is for version 4 and prior compatibility.. it temporarily reads
dda0863632df (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2889
	    type and flags (which were both 4 bits) into type. Later on this is
dda0863632df (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2890
	    converted correctly */
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2891
	SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, type), SLE_UINT8,                 0, 4),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2892
	SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
956
dda0863632df (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2893
dda0863632df (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2894
	/* Orders for version 5 and on */
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2895
	SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, type),  SLE_UINT8,  5, SL_MAX_VERSION),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2896
	SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, flags), SLE_UINT8,  5, SL_MAX_VERSION),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2897
	SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest),  SLE_UINT16, 5, SL_MAX_VERSION),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2898
4712
4335ad42e163 (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
  2899
	/* Refit in current order */
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2900
	SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, refit_cargo),    SLE_UINT8, 36, SL_MAX_VERSION),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2901
	SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, refit_subtype),  SLE_UINT8, 36, SL_MAX_VERSION),
4712
4335ad42e163 (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
  2902
6980
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  2903
	/* Timetable in current order */
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  2904
	SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, wait_time),      SLE_UINT16, 67, SL_MAX_VERSION),
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  2905
	SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, travel_time),    SLE_UINT16, 67, SL_MAX_VERSION),
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  2906
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2907
	    SLE_REF(Vehicle, orders,               REF_ORDER),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2908
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2909
	SLE_CONDVAR(Vehicle, age,                  SLE_FILE_U16 | SLE_VAR_I32,  0, 30),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2910
	SLE_CONDVAR(Vehicle, age,                  SLE_INT32,                  31, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2911
	SLE_CONDVAR(Vehicle, max_age,              SLE_FILE_U16 | SLE_VAR_I32,  0, 30),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2912
	SLE_CONDVAR(Vehicle, max_age,              SLE_INT32,                  31, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2913
	SLE_CONDVAR(Vehicle, date_of_last_service, SLE_FILE_U16 | SLE_VAR_I32,  0, 30),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2914
	SLE_CONDVAR(Vehicle, date_of_last_service, SLE_INT32,                  31, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2915
	SLE_CONDVAR(Vehicle, service_interval,     SLE_FILE_U16 | SLE_VAR_I32,  0, 30),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2916
	SLE_CONDVAR(Vehicle, service_interval,     SLE_INT32,                  31, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2917
	    SLE_VAR(Vehicle, reliability,          SLE_UINT16),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2918
	    SLE_VAR(Vehicle, reliability_spd_dec,  SLE_UINT16),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2919
	    SLE_VAR(Vehicle, breakdown_ctr,        SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2920
	    SLE_VAR(Vehicle, breakdown_delay,      SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2921
	    SLE_VAR(Vehicle, breakdowns_since_last_service, SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2922
	    SLE_VAR(Vehicle, breakdown_chance,     SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2923
	SLE_CONDVAR(Vehicle, build_year,           SLE_FILE_U8 | SLE_VAR_I32,  0, 30),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2924
	SLE_CONDVAR(Vehicle, build_year,           SLE_INT32,                 31, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2925
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2926
	     SLE_VAR(Vehicle, load_unload_time_rem, SLE_UINT16),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2927
	SLEG_CONDVAR(         _cargo_paid_for,      SLE_UINT16,                45, SL_MAX_VERSION),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2928
	 SLE_CONDVAR(Vehicle, vehicle_flags,        SLE_UINT8,                 40, SL_MAX_VERSION),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2929
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2930
	 SLE_CONDVAR(Vehicle, profit_this_year,     SLE_FILE_I32 | SLE_VAR_I64, 0, 64),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2931
	 SLE_CONDVAR(Vehicle, profit_this_year,     SLE_INT64,                 65, SL_MAX_VERSION),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2932
	 SLE_CONDVAR(Vehicle, profit_last_year,     SLE_FILE_I32 | SLE_VAR_I64, 0, 64),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2933
	 SLE_CONDVAR(Vehicle, profit_last_year,     SLE_INT64,                 65, SL_MAX_VERSION),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2934
	SLEG_CONDVAR(         _cargo_feeder_share,  SLE_FILE_I32 | SLE_VAR_I64,51, 64),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2935
	SLEG_CONDVAR(         _cargo_feeder_share,  SLE_INT64,                 65, 67),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2936
	SLEG_CONDVAR(         _cargo_loaded_at_xy,  SLE_UINT32,                51, 67),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2937
	 SLE_CONDVAR(Vehicle, value,                SLE_FILE_I32 | SLE_VAR_I64, 0, 64),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  2938
	 SLE_CONDVAR(Vehicle, value,                SLE_INT64,                 65, SL_MAX_VERSION),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2939
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2940
	    SLE_VAR(Vehicle, random_bits,          SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2941
	    SLE_VAR(Vehicle, waiting_triggers,     SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2942
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2943
	    SLE_REF(Vehicle, next_shared,          REF_VEHICLE),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2944
	    SLE_REF(Vehicle, prev_shared,          REF_VEHICLE),
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2945
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  2946
	SLE_CONDVAR(Vehicle, group_id,             SLE_UINT16,                60, SL_MAX_VERSION),
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  2947
6980
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  2948
	SLE_CONDVAR(Vehicle, current_order_time,   SLE_UINT32,                67, SL_MAX_VERSION),
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  2949
	SLE_CONDVAR(Vehicle, lateness_counter,     SLE_INT32,                 67, SL_MAX_VERSION),
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  2950
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2951
	/* reserve extra space in savegame here. (currently 10 bytes) */
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2952
	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
  2953
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2954
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2955
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2956
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2957
1881
435d39bd6ee0 (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
  2958
static const SaveLoad _train_desc[] = {
6817
ca1cc2fd4cfa (svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents: 6810
diff changeset
  2959
	SLE_WRITEBYTE(Vehicle, type, VEH_TRAIN),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2960
	SLE_INCLUDEX(0, INC_VEHICLE_COMMON),
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2961
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, crash_anim_pos),         SLE_UINT16),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2962
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, force_proceed),          SLE_UINT8),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2963
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, railtype),               SLE_UINT8),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2964
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, track),                  SLE_UINT8),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2965
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2966
	SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, flags),                  SLE_UINT8,  2, SL_MAX_VERSION),
6573
26d4c4618f60 (svn r9784) -Codechange: remove unused variable.
rubidium
parents: 6568
diff changeset
  2967
	SLE_CONDNULL(2, 2, 59),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2968
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3185
diff changeset
  2969
	SLE_CONDNULL(2, 2, 19),
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2970
	/* reserve extra space in savegame here. (currently 11 bytes) */
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3185
diff changeset
  2971
	SLE_CONDNULL(11, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2972
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2973
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2974
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2975
1881
435d39bd6ee0 (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
  2976
static const SaveLoad _roadveh_desc[] = {
6817
ca1cc2fd4cfa (svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents: 6810
diff changeset
  2977
	SLE_WRITEBYTE(Vehicle, type, VEH_ROAD),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2978
	SLE_INCLUDEX(0, INC_VEHICLE_COMMON),
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2979
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, state),          SLE_UINT8),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2980
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, frame),          SLE_UINT8),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2981
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, blocked_ctr),    SLE_UINT16),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2982
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, overtaking),     SLE_UINT8),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2983
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, overtaking_ctr), SLE_UINT8),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2984
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, crashed_ctr),    SLE_UINT16),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2985
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, reverse_ctr),    SLE_UINT8),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2986
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2987
	SLE_CONDREFX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, slot),     REF_ROADSTOPS, 6, SL_MAX_VERSION),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2988
	SLE_CONDNULL(1,                                                                     6, SL_MAX_VERSION),
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2989
	SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, slot_age), SLE_UINT8,     6, SL_MAX_VERSION),
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  2990
	/* reserve extra space in savegame here. (currently 16 bytes) */
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2991
	SLE_CONDNULL(16,                                                                    2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2992
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2993
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2994
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2995
1881
435d39bd6ee0 (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
  2996
static const SaveLoad _ship_desc[] = {
6817
ca1cc2fd4cfa (svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents: 6810
diff changeset
  2997
	SLE_WRITEBYTE(Vehicle, type, VEH_SHIP),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2998
	SLE_INCLUDEX(0, INC_VEHICLE_COMMON),
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  2999
	SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleShip, state), SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3000
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  3001
	/* reserve extra space in savegame here. (currently 16 bytes) */
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3185
diff changeset
  3002
	SLE_CONDNULL(16, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3003
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3004
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3005
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3006
1881
435d39bd6ee0 (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
  3007
static const SaveLoad _aircraft_desc[] = {
6817
ca1cc2fd4cfa (svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents: 6810
diff changeset
  3008
	SLE_WRITEBYTE(Vehicle, type, VEH_AIRCRAFT),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3009
	SLE_INCLUDEX(0, INC_VEHICLE_COMMON),
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3010
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, crashed_counter), SLE_UINT16),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3011
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, pos),             SLE_UINT8),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3012
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3013
	SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, targetairport),   SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3014
	SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, targetairport),   SLE_UINT16,                5, SL_MAX_VERSION),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3015
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3016
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, state),           SLE_UINT8),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3017
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3018
	SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, previous_pos),    SLE_UINT8,                 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3019
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  3020
	/* reserve extra space in savegame here. (currently 15 bytes) */
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3021
	SLE_CONDNULL(15,                                                                                      2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3022
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3023
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3024
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3025
1881
435d39bd6ee0 (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
  3026
static const SaveLoad _special_desc[] = {
6817
ca1cc2fd4cfa (svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents: 6810
diff changeset
  3027
	SLE_WRITEBYTE(Vehicle, type, VEH_SPECIAL),
ca1cc2fd4cfa (svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents: 6810
diff changeset
  3028
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3029
	    SLE_VAR(Vehicle, subtype,       SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3030
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3031
	SLE_CONDVAR(Vehicle, tile,          SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3032
	SLE_CONDVAR(Vehicle, tile,          SLE_UINT32,                 6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3033
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3034
	SLE_CONDVAR(Vehicle, x_pos,         SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3035
	SLE_CONDVAR(Vehicle, x_pos,         SLE_INT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3036
	SLE_CONDVAR(Vehicle, y_pos,         SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3037
	SLE_CONDVAR(Vehicle, y_pos,         SLE_INT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3038
	    SLE_VAR(Vehicle, z_pos,         SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3039
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3040
	    SLE_VAR(Vehicle, cur_image,     SLE_UINT16),
6561
073e48516812 (svn r9763) -Codechange/Fix (r9760): don't read the variables that are calculated automatically either.
rubidium
parents: 6558
diff changeset
  3041
	SLE_CONDNULL(5,                                                 0, 57),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3042
	    SLE_VAR(Vehicle, progress,      SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3043
	    SLE_VAR(Vehicle, vehstatus,     SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3044
7334
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  3045
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleSpecial, animation_state),    SLE_UINT16),
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  3046
	    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleSpecial, animation_substate), SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3047
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  3048
	/* reserve extra space in savegame here. (currently 16 bytes) */
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3185
diff changeset
  3049
	SLE_CONDNULL(16, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3050
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3051
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3052
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3053
1881
435d39bd6ee0 (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
  3054
static const SaveLoad _disaster_desc[] = {
6817
ca1cc2fd4cfa (svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents: 6810
diff changeset
  3055
	SLE_WRITEBYTE(Vehicle, type, VEH_DISASTER),
ca1cc2fd4cfa (svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents: 6810
diff changeset
  3056
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3057
	    SLE_REF(Vehicle, next,          REF_VEHICLE_OLD),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3058
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3059
	    SLE_VAR(Vehicle, subtype,       SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3060
	SLE_CONDVAR(Vehicle, tile,          SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3061
	SLE_CONDVAR(Vehicle, tile,          SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3062
	SLE_CONDVAR(Vehicle, dest_tile,     SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3063
	SLE_CONDVAR(Vehicle, dest_tile,     SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3064
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3065
	SLE_CONDVAR(Vehicle, x_pos,         SLE_FILE_I16 | SLE_VAR_I32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3066
	SLE_CONDVAR(Vehicle, x_pos,         SLE_INT32,                   6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3067
	SLE_CONDVAR(Vehicle, y_pos,         SLE_FILE_I16 | SLE_VAR_I32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3068
	SLE_CONDVAR(Vehicle, y_pos,         SLE_INT32,                   6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3069
	    SLE_VAR(Vehicle, z_pos,         SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3070
	    SLE_VAR(Vehicle, direction,     SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3071
6561
073e48516812 (svn r9763) -Codechange/Fix (r9760): don't read the variables that are calculated automatically either.
rubidium
parents: 6558
diff changeset
  3072
	SLE_CONDNULL(5,                                                  0, 57),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3073
	    SLE_VAR(Vehicle, owner,         SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3074
	    SLE_VAR(Vehicle, vehstatus,     SLE_UINT8),
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3075
	SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3076
	SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_UINT16,                5, SL_MAX_VERSION),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3077
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3078
	    SLE_VAR(Vehicle, cur_image,     SLE_UINT16),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3079
	SLE_CONDVAR(Vehicle, age,           SLE_FILE_U16 | SLE_VAR_I32,  0, 30),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3080
	SLE_CONDVAR(Vehicle, age,           SLE_INT32,                  31, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3081
	    SLE_VAR(Vehicle, tick_counter,  SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3082
7334
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  3083
	   SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleDisaster, image_override),           SLE_UINT16),
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
  3084
	   SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleDisaster, big_ufo_destroyer_target), SLE_UINT16),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3085
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  3086
	/* reserve extra space in savegame here. (currently 16 bytes) */
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3087
	SLE_CONDNULL(16,                                                 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3088
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3089
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3090
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3091
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3092
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3093
static const void *_veh_descs[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3094
	_train_desc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3095
	_roadveh_desc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3096
	_ship_desc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3097
	_aircraft_desc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3098
	_special_desc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3099
	_disaster_desc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3100
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3101
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  3102
/** Will be called when the vehicles need to be saved. */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6198
diff changeset
  3103
static void Save_VEHS()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3104
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3105
	Vehicle *v;
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  3106
	/* Write the vehicles */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3107
	FOR_ALL_VEHICLES(v) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3108
		SlSetArrayIndex(v->index);
5955
fe61588d5188 (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: 5944
diff changeset
  3109
		SlObject(v, (SaveLoad*)_veh_descs[v->type]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3110
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3111
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3112
6423
8e10e79e0fd1 (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents: 6350
diff changeset
  3113
/** Will be called when vehicles need to be loaded. */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6198
diff changeset
  3114
static void Load_VEHS()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3115
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3116
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3117
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3118
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3119
	_cargo_count = 0;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3120
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3121
	while ((index = SlIterateArray()) != -1) {
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
  3122
		Vehicle *v;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
  3123
4972
c7f92c6b74e4 (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4925
diff changeset
  3124
		if (!AddBlockIfNeeded(&_Vehicle_pool, index))
1279
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
  3125
			error("Vehicles: failed loading savegame: too many vehicles");
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
  3126
bc761aad52b3 (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1266
diff changeset
  3127
		v = GetVehicle(index);
6817
ca1cc2fd4cfa (svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents: 6810
diff changeset
  3128
		VehicleType vtype = (VehicleType)SlReadByte();
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3129
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3130
		switch (vtype) {
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3131
			case VEH_TRAIN:    v = new (v) Train();           break;
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3132
			case VEH_ROAD:     v = new (v) RoadVehicle();     break;
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3133
			case VEH_SHIP:     v = new (v) Ship();            break;
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3134
			case VEH_AIRCRAFT: v = new (v) Aircraft();        break;
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3135
			case VEH_SPECIAL:  v = new (v) SpecialVehicle();  break;
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3136
			case VEH_DISASTER: v = new (v) DisasterVehicle(); break;
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3137
			case VEH_INVALID:  v = new (v) InvalidVehicle();  break;
6621
441559124aea (svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium
parents: 6616
diff changeset
  3138
			default: NOT_REACHED();
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3139
		}
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6550
diff changeset
  3140
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3141
		SlObject(v, (SaveLoad*)_veh_descs[vtype]);
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3142
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3143
		if (_cargo_count != 0 && IsPlayerBuildableVehicleType(v)) {
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3144
			/* Don't construct the packet with station here, because that'll fail with old savegames */
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3145
			CargoPacket *cp = new CargoPacket();
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3146
			cp->source          = _cargo_source;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3147
			cp->source_xy       = _cargo_source_xy;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3148
			cp->count           = _cargo_count;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3149
			cp->days_in_transit = _cargo_days;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3150
			cp->feeder_share    = _cargo_feeder_share;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3151
			cp->loaded_at_xy    = _cargo_loaded_at_xy;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3152
			v->cargo.Append(cp);
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3153
		}
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6998
diff changeset
  3154
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2498
diff changeset
  3155
		/* Old savegames used 'last_station_visited = 0xFF' */
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2681
diff changeset
  3156
		if (CheckSavegameVersion(5) && v->last_station_visited == 0xFF)
2469
59a0073914d8 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2467
diff changeset
  3157
			v->last_station_visited = INVALID_STATION;
956
dda0863632df (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  3158
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2681
diff changeset
  3159
		if (CheckSavegameVersion(5)) {
956
dda0863632df (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  3160
			/* Convert the current_order.type (which is a mix of type and flags, because
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
  3161
			 *  in those versions, they both were 4 bits big) to type and flags */
956
dda0863632df (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  3162
			v->current_order.flags = (v->current_order.type & 0xF0) >> 4;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  3163
			v->current_order.type.m_val &= 0x0F;
956
dda0863632df (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  3164
		}
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  3165
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  3166
		/* Advanced vehicle lists got added */
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6641
diff changeset
  3167
		if (CheckSavegameVersion(60)) v->group_id = DEFAULT_GROUP;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3168
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3169
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3170
	/* Check for shared order-lists (we now use pointers for that) */
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2681
diff changeset
  3171
	if (CheckSavegameVersionOldStyle(5, 2)) {
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3172
		FOR_ALL_VEHICLES(v) {
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3173
			Vehicle *u;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3174
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3175
			FOR_ALL_VEHICLES_FROM(u, v->index + 1) {
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3176
				/* If a vehicle has the same orders, add the link to eachother
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4544
diff changeset
  3177
				 *  in both vehicles */
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3178
				if (v->orders == u->orders) {
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3179
					v->next_shared = u;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3180
					u->prev_shared = v;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3181
					break;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3182
				}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3183
			}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3184
		}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  3185
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3186
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3187
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  3188
extern const ChunkHandler _veh_chunk_handlers[] = {
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1541
diff changeset
  3189
	{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY | CH_LAST},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3190
};
5651
79496e6d8a56 (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: 5609
diff changeset
  3191
79496e6d8a56 (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: 5609
diff changeset
  3192
void Vehicle::BeginLoading()
79496e6d8a56 (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: 5609
diff changeset
  3193
{
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  3194
	assert(IsTileType(tile, MP_STATION) || type == VEH_SHIP);
6550
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3195
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3196
	if (this->current_order.type == OT_GOTO_STATION &&
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3197
			this->current_order.dest == this->last_station_visited) {
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3198
		/* Arriving at the ordered station.
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3199
		 * Keep the load/unload flags, as we (obviously) still need them. */
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3200
		this->current_order.flags &= OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER;
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3201
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3202
		/* Furthermore add the Non Stop flag to mark that this station
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3203
		 * is the actual destination of the vehicle, which is (for example)
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3204
		 * necessary to be known for HandleTrainLoading to determine
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3205
		 * whether the train is lost or not; not marking a train lost
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3206
		 * that arrives at random stations is bad. */
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3207
		this->current_order.flags |= OF_NON_STOP;
6980
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  3208
		UpdateVehicleTimetable(this, true);
6550
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3209
	} else {
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3210
		/* This is just an unordered intermediate stop */
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3211
		this->current_order.flags = 0;
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3212
	}
8bdb954bba16 (svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents: 6546
diff changeset
  3213
5651
79496e6d8a56 (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: 5609
diff changeset
  3214
	current_order.type = OT_LOADING;
6500
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6492
diff changeset
  3215
	GetStation(this->last_station_visited)->loading_vehicles.push_back(this);
6553
976a684212ad (svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium
parents: 6552
diff changeset
  3216
6562
077afce9a4ee (svn r9764) -Codechange: replace some lookup tables by functions.
rubidium
parents: 6561
diff changeset
  3217
	SET_EXPENSES_TYPE(this->GetExpenseType(true));
6565
96ef0ede4b83 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents: 6562
diff changeset
  3218
	VehiclePayment(this);
96ef0ede4b83 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents: 6562
diff changeset
  3219
96ef0ede4b83 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents: 6562
diff changeset
  3220
	InvalidateWindow(this->GetVehicleListWindowClass(), this->owner);
6553
976a684212ad (svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium
parents: 6552
diff changeset
  3221
	InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, STATUS_BAR);
6565
96ef0ede4b83 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents: 6562
diff changeset
  3222
	InvalidateWindow(WC_VEHICLE_DETAILS, this->index);
96ef0ede4b83 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents: 6562
diff changeset
  3223
	InvalidateWindow(WC_STATION_VIEW, this->last_station_visited);
96ef0ede4b83 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents: 6562
diff changeset
  3224
6823
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6817
diff changeset
  3225
	GetStation(this->last_station_visited)->MarkTilesDirty(true);
6565
96ef0ede4b83 (svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents: 6562
diff changeset
  3226
	this->MarkDirty();
5651
79496e6d8a56 (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: 5609
diff changeset
  3227
}
79496e6d8a56 (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: 5609
diff changeset
  3228
79496e6d8a56 (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: 5609
diff changeset
  3229
void Vehicle::LeaveStation()
79496e6d8a56 (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: 5609
diff changeset
  3230
{
79496e6d8a56 (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: 5609
diff changeset
  3231
	assert(current_order.type == OT_LOADING);
7076
0416a03dff7c (svn r10341) -Fix (r10236): Only update the timetable when leaving stations if this is a scheduled stop.
maedhros
parents: 7070
diff changeset
  3232
0416a03dff7c (svn r10341) -Fix (r10236): Only update the timetable when leaving stations if this is a scheduled stop.
maedhros
parents: 7070
diff changeset
  3233
	/* Only update the timetable if the vehicle was supposed to stop here. */
0416a03dff7c (svn r10341) -Fix (r10236): Only update the timetable when leaving stations if this is a scheduled stop.
maedhros
parents: 7070
diff changeset
  3234
	if (current_order.flags & OF_NON_STOP) UpdateVehicleTimetable(this, false);
0416a03dff7c (svn r10341) -Fix (r10236): Only update the timetable when leaving stations if this is a scheduled stop.
maedhros
parents: 7070
diff changeset
  3235
5651
79496e6d8a56 (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: 5609
diff changeset
  3236
	current_order.type = OT_LEAVESTATION;
79496e6d8a56 (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: 5609
diff changeset
  3237
	current_order.flags = 0;
6501
7df55f74f00c (svn r9684) -Fix (r9683): Remove vehicles from the station loading list instead of adding
maedhros
parents: 6500
diff changeset
  3238
	GetStation(this->last_station_visited)->loading_vehicles.remove(this);
6980
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  3239
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  3240
	HideFillingPercent(this->fill_percent_te_id);
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6980
diff changeset
  3241
	this->fill_percent_te_id = INVALID_TE_ID;
5651
79496e6d8a56 (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: 5609
diff changeset
  3242
}
6558
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
  3243
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
  3244
6594
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3245
void Vehicle::HandleLoading(bool mode)
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3246
{
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3247
	switch (this->current_order.type) {
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3248
		case OT_LOADING: {
6980
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  3249
			uint wait_time = max(this->current_order.wait_time - this->lateness_counter, 0);
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  3250
6616
0b3835bdd796 (svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium
parents: 6611
diff changeset
  3251
			/* Not the first call for this tick, or still loading */
6980
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  3252
			if (mode || !HASBIT(this->vehicle_flags, VF_LOADING_FINISHED) ||
c7c4f3bf5901 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6955
diff changeset
  3253
					(_patches.timetabling && this->current_order_time < wait_time)) return;
6594
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3254
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3255
			this->PlayLeaveStationSound();
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3256
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3257
			Order b = this->current_order;
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3258
			this->LeaveStation();
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3259
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3260
			/* If this was not the final order, don't remove it from the list. */
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3261
			if (!(b.flags & OF_NON_STOP)) return;
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3262
			break;
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3263
		}
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3264
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3265
		case OT_DUMMY: break;
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3266
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3267
		default: return;
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3268
	}
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3269
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3270
	this->cur_order_index++;
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3271
	InvalidateVehicleOrder(this);
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3272
}
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3273
9673331eb174 (svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents: 6585
diff changeset
  3274
6558
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
  3275
void SpecialVehicle::UpdateDeltaXY(Direction direction)
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
  3276
{
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
  3277
	this->x_offs        = 0;
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
  3278
	this->y_offs        = 0;
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
  3279
	this->sprite_width  = 1;
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
  3280
	this->sprite_height = 1;
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
  3281
	this->z_height      = 1;
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
  3282
}