10 #include "../stdafx.h"
11 #include "../vehicle_func.h"
13 #include "../roadveh.h"
15 #include "../aircraft.h"
16 #include "../station_base.h"
17 #include "../effectvehicle_base.h"
18 #include "../company_base.h"
19 #include "../company_func.h"
20 #include "../disaster_vehicle.h"
26 #include "../safeguards.h"
35 v->other_multiheaded_part =
nullptr;
39 if (v->IsFrontEngine() || v->IsFreeWagon()) {
53 bool sequential_matching = v->IsFrontEngine();
56 if (u->other_multiheaded_part !=
nullptr)
continue;
58 if (u->IsMultiheaded()) {
68 if (sequential_matching) {
87 if (stack_pos == 0)
break;
94 w->other_multiheaded_part = u;
95 u->other_multiheaded_part = w;
115 if (
HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) {
116 for (
Train *u = t; u !=
nullptr; u = u->
Next()) {
120 switch (u->subtype) {
129 u->SetArticulatedPart();
139 if (rvi->railveh_type ==
RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) {
166 st->airport.flags = 0;
172 if (a->IsNormalAircraft()) {
174 if ((a->vehstatus &
VS_STOPPED) && a->state == 0) {
182 a->cur_speed = a->vcache.cached_max_speed;
183 if (!a->current_order.IsType(OT_GOTO_STATION) && !a->current_order.IsType(OT_GOTO_DEPOT)) {
185 a->current_order.MakeDummy();
193 if (a->subtype ==
AIR_HELICOPTER) a->Next()->Next()->cur_speed = 32;
226 if (v->engine_type >= total_engines || v->type != v->GetEngine()->type) {
227 v->engine_type = first_engine[v->type];
244 if (v->Next() !=
nullptr) v->Next()->previous = v;
245 if (v->NextShared() !=
nullptr) v->NextShared()->previous_shared = v;
247 if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID;
249 if (v->IsGroundVehicle()) v->GetGroundVehicleCache()->first_engine =
INVALID_ENGINE;
261 std::map<Order*, OrderList*> mapping;
264 if (v->orders.old !=
nullptr) {
266 if (mapping[v->orders.old] ==
nullptr) {
273 v->orders.list = mapping[v->orders.old] =
new OrderList(v->orders.old, v);
275 v->orders.list = mapping[v->orders.old];
278 v->AddToShared(v->orders.list->GetFirstSharedVehicle());
282 if (v->PreviousShared() ==
nullptr) {
283 v->orders.list->Initialize(v->orders.list->first, v);
292 if (v->Previous() ==
nullptr) {
293 for (
Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
303 if (v->First() != v || v->orders.list !=
nullptr || v->previous_shared !=
nullptr || v->next_shared ==
nullptr)
continue;
307 v->orders.list =
new OrderList(
nullptr, v);
309 u->orders.list = v->orders.list;
317 if (rv->subtype == 0) {
319 rv->SetFrontEngine();
320 }
else if (rv->subtype == 1) {
323 rv->SetArticulatedPart();
333 if (!v->IsPrimaryVehicle() && v->type !=
VEH_DISASTER) {
334 v->current_order.Free();
350 if (!v->IsPrimaryVehicle())
continue;
355 v->SetServiceIntervalIsCustom(v->GetServiceInterval() != interval);
363 s->rotation = s->direction;
367 if (s->rotation == s->direction)
continue;
372 s->rotation_x_pos = s->x_pos;
373 s->rotation_y_pos = s->y_pos;
381 assert(v->first !=
nullptr);
448 v->GetImage(v->direction,
EIT_ON_MAP, &v->sprite_cache.sprite_seq);
453 v->GetImage(v->direction,
EIT_ON_MAP, &v->sprite_cache.sprite_seq);
475 v->UpdateViewport(
false);
489 if (v->type ==
VEH_TRAIN && v->IsPrimaryVehicle()) {
501 for (done = 0; done < diff; done++) {
505 if (next !=
nullptr && done < diff && u->IsFrontEngine()) {
515 int r = CountVehiclesInChain(u) - 1;
527 for (moved = 0; moved < diff + 1; moved++) {
532 r = CountVehiclesInChain(u) - 1;
536 u->force_proceed = old_tfp;
540 if (moved < diff + 1)
break;
568 static uint8 _cargo_days;
569 static uint16 _cargo_source;
570 static uint32 _cargo_source_xy;
571 static uint16 _cargo_count;
572 static uint16 _cargo_paid_for;
573 static Money _cargo_feeder_share;
574 static uint32 _cargo_loaded_at_xy;
584 static const SaveLoad _common_veh_desc[] = {
720 static const SaveLoad _train_desc[] = {
741 static const SaveLoad _roadveh_desc[] = {
763 static const SaveLoad _ship_desc[] = {
775 static const SaveLoad _aircraft_desc[] = {
798 static const SaveLoad _special_desc[] = {
813 SLE_VAR(
Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
828 static const SaveLoad _disaster_desc[] = {
853 SLE_VAR(
Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
870 static const SaveLoad *
const _veh_descs[] = {
880 return _veh_descs[vt];
888 SlSetArrayIndex(v->index);
919 CargoPacket *cp =
new CargoPacket(_cargo_count, _cargo_days, _cargo_source, _cargo_source_xy, _cargo_loaded_at_xy, _cargo_feeder_share);
942 static void Ptrs_VEHS()