10 #include "../stdafx.h"
15 #include "../vehicle_func.h"
17 #include "../roadveh.h"
19 #include "../aircraft.h"
20 #include "../station_base.h"
21 #include "../effectvehicle_base.h"
22 #include "../company_base.h"
23 #include "../company_func.h"
24 #include "../disaster_vehicle.h"
28 #include "../safeguards.h"
37 v->other_multiheaded_part =
nullptr;
41 if (v->IsFrontEngine() || v->IsFreeWagon()) {
55 bool sequential_matching = v->IsFrontEngine();
58 if (u->other_multiheaded_part !=
nullptr)
continue;
60 if (u->IsMultiheaded()) {
70 if (sequential_matching) {
89 if (stack_pos == 0)
break;
96 w->other_multiheaded_part = u;
97 u->other_multiheaded_part = w;
117 if (
HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) {
118 for (
Train *u = t; u !=
nullptr; u = u->
Next()) {
122 switch (u->subtype) {
131 u->SetArticulatedPart();
141 if (rvi->railveh_type ==
RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) {
168 st->airport.flags = 0;
174 if (a->IsNormalAircraft()) {
176 if ((a->vehstatus &
VS_STOPPED) && a->state == 0) {
184 a->cur_speed = a->vcache.cached_max_speed;
185 if (!a->current_order.IsType(OT_GOTO_STATION) && !a->current_order.IsType(OT_GOTO_DEPOT)) {
187 a->current_order.MakeDummy();
195 if (a->subtype ==
AIR_HELICOPTER) a->Next()->Next()->cur_speed = 32;
228 if (v->engine_type >= total_engines || v->type != v->GetEngine()->type) {
229 v->engine_type = first_engine[v->type];
246 if (v->Next() !=
nullptr) v->Next()->previous = v;
247 if (v->NextShared() !=
nullptr) v->NextShared()->previous_shared = v;
249 if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID;
251 if (v->IsGroundVehicle()) v->GetGroundVehicleCache()->first_engine =
INVALID_ENGINE;
263 std::map<Order*, OrderList*> mapping;
266 if (v->orders.old !=
nullptr) {
268 if (mapping[v->orders.old] ==
nullptr) {
275 v->orders.list = mapping[v->orders.old] =
new OrderList(v->orders.old, v);
277 v->orders.list = mapping[v->orders.old];
280 v->AddToShared(v->orders.list->GetFirstSharedVehicle());
284 if (v->PreviousShared() ==
nullptr) {
285 v->orders.list->Initialize(v->orders.list->first, v);
294 if (v->Previous() ==
nullptr) {
295 for (
Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
305 if (v->First() != v || v->orders.list !=
nullptr || v->previous_shared !=
nullptr || v->next_shared ==
nullptr)
continue;
309 v->orders.list =
new OrderList(
nullptr, v);
311 u->orders.list = v->orders.list;
319 if (rv->subtype == 0) {
321 rv->SetFrontEngine();
322 }
else if (rv->subtype == 1) {
325 rv->SetArticulatedPart();
335 if (!v->IsPrimaryVehicle() && v->type !=
VEH_DISASTER) {
336 v->current_order.Free();
352 if (!v->IsPrimaryVehicle())
continue;
357 v->SetServiceIntervalIsCustom(v->GetServiceInterval() != interval);
365 s->rotation = s->direction;
369 if (s->rotation == s->direction)
continue;
374 s->rotation_x_pos = s->x_pos;
375 s->rotation_y_pos = s->y_pos;
383 assert(v->first !=
nullptr);
450 v->GetImage(v->direction,
EIT_ON_MAP, &v->sprite_cache.sprite_seq);
455 v->GetImage(v->direction,
EIT_ON_MAP, &v->sprite_cache.sprite_seq);
477 v->UpdateViewport(
false);
491 if (v->type ==
VEH_TRAIN && v->IsPrimaryVehicle()) {
503 for (done = 0; done < diff; done++) {
507 if (next !=
nullptr && done < diff && u->IsFrontEngine()) {
517 int r = CountVehiclesInChain(u) - 1;
529 for (moved = 0; moved < diff + 1; moved++) {
534 r = CountVehiclesInChain(u) - 1;
538 u->force_proceed = old_tfp;
542 if (moved < diff + 1)
break;
570 static uint8 _cargo_days;
571 static uint16 _cargo_source;
572 static uint32 _cargo_source_xy;
573 static uint16 _cargo_count;
574 static uint16 _cargo_paid_for;
575 static Money _cargo_feeder_share;
576 static uint32 _cargo_loaded_at_xy;
580 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
585 inline static const SaveLoad description[] = {{}};
590 static const SaveLoad description[] = {
710 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
716 void Save(
Vehicle *v)
const override
721 void Load(
Vehicle *v)
const override
726 void FixPointers(
Vehicle *v)
const override
734 inline static const SaveLoad description[] = {
748 void Save(
Vehicle *v)
const override
754 void Load(
Vehicle *v)
const override
760 void FixPointers(
Vehicle *v)
const override
769 inline static const SaveLoad description[] = {
784 void Save(
Vehicle *v)
const override
790 void Load(
Vehicle *v)
const override
796 void FixPointers(
Vehicle *v)
const override
805 inline static const SaveLoad description[] = {
813 void Save(
Vehicle *v)
const override
819 void Load(
Vehicle *v)
const override
825 void FixPointers(
Vehicle *v)
const override
834 inline static const SaveLoad description[] = {
853 void Save(
Vehicle *v)
const override
859 void Load(
Vehicle *v)
const override
865 void FixPointers(
Vehicle *v)
const override
874 inline static const SaveLoad description[] = {
887 SLE_VAR(
Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
898 void Save(
Vehicle *v)
const override
904 void Load(
Vehicle *v)
const override
910 void FixPointers(
Vehicle *v)
const override
919 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
924 inline static const SaveLoad description[] = {{}};
929 static const SaveLoad description[] = {
951 SLE_VAR(
Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
962 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
968 void Save(
Vehicle *v)
const override
974 void Load(
Vehicle *v)
const override
980 void FixPointers(
Vehicle *v)
const override
987 const static SaveLoad _vehicle_desc[] = {
1006 SlSetArrayIndex(v->index);
1038 CargoPacket *cp =
new CargoPacket(_cargo_count, _cargo_days, _cargo_source, _cargo_source_xy, _cargo_loaded_at_xy, _cargo_feeder_share);