10 #include "../stdafx.h"
15 #include "../vehicle_func.h"
17 #include "../roadveh.h"
19 #include "../aircraft.h"
20 #include "../timetable.h"
21 #include "../station_base.h"
22 #include "../effectvehicle_base.h"
23 #include "../company_base.h"
24 #include "../company_func.h"
25 #include "../disaster_vehicle.h"
26 #include "../economy_base.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;
205 for (
auto iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ) {
208 iter = st->loading_vehicles.erase(iter);
241 if (v->engine_type >= total_engines || v->type != v->GetEngine()->type) {
242 v->engine_type = first_engine[v->type];
259 if (v->Next() !=
nullptr) v->Next()->previous = v;
260 if (v->NextShared() !=
nullptr) v->NextShared()->previous_shared = v;
262 if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID;
264 if (v->IsGroundVehicle()) v->GetGroundVehicleCache()->first_engine =
INVALID_ENGINE;
276 std::map<Order*, OrderList*> mapping;
279 if (v->old_orders !=
nullptr) {
281 if (mapping[v->old_orders] ==
nullptr) {
288 v->orders = mapping[v->old_orders] =
new OrderList(v->old_orders, v);
290 v->orders = mapping[v->old_orders];
293 v->AddToShared(v->orders->GetFirstSharedVehicle());
297 if (v->PreviousShared() ==
nullptr) {
298 v->orders->Initialize(v->orders->first, v);
307 if (v->Previous() ==
nullptr) {
308 for (
Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
318 if (v->First() != v || v->orders !=
nullptr || v->previous_shared !=
nullptr || v->next_shared ==
nullptr)
continue;
324 u->orders = v->orders;
332 if (rv->subtype == 0) {
334 rv->SetFrontEngine();
335 }
else if (rv->subtype == 1) {
338 rv->SetArticulatedPart();
348 if (!v->IsPrimaryVehicle() && v->type !=
VEH_DISASTER) {
349 v->current_order.Free();
365 if (!v->IsPrimaryVehicle())
continue;
370 v->SetServiceIntervalIsCustom(v->GetServiceInterval() != interval);
378 s->rotation = s->direction;
382 if (s->rotation == s->direction)
continue;
387 s->rotation_x_pos = s->x_pos;
388 s->rotation_y_pos = s->y_pos;
396 if (v->timetable_start == 0)
continue;
405 v->economy_age = v->age.base();
413 assert(v->first !=
nullptr);
434 RoadTramType rtt = GetRoadTramType(rv->
roadtype);
482 v->GetImage(v->direction,
EIT_ON_MAP, &v->sprite_cache.sprite_seq);
487 v->GetImage(v->direction,
EIT_ON_MAP, &v->sprite_cache.sprite_seq);
491 if (shadow ==
nullptr)
SlErrorCorrupt(
"Missing shadow for aircraft");
498 if (rotor ==
nullptr)
SlErrorCorrupt(
"Missing rotor for helicopter");
527 if (part_of_load && v->unitnumber != 0) {
528 Company::Get(v->owner)->freeunits[v->type].UseID(v->unitnumber);
535 v->UpdateViewport(
false);
549 if (v->type ==
VEH_TRAIN && v->IsPrimaryVehicle()) {
561 for (done = 0; done < diff; done++) {
565 if (next !=
nullptr && done < diff && u->IsFrontEngine()) {
575 int r = CountVehiclesInChain(u) - 1;
587 for (moved = 0; moved < diff + 1; moved++) {
592 r = CountVehiclesInChain(u) - 1;
596 u->force_proceed = old_tfp;
600 if (moved < diff + 1)
break;
628 static uint8_t _cargo_periods;
629 static uint16_t _cargo_source;
630 static uint32_t _cargo_source_xy;
631 static uint16_t _cargo_count;
632 static uint16_t _cargo_paid_for;
633 static Money _cargo_feeder_share;
637 inline static const SaveLoad description[] = {
769 void Save(
Vehicle *v)
const override
774 void Load(
Vehicle *v)
const override
779 void FixPointers(
Vehicle *v)
const override
787 inline static const SaveLoad description[] = {
801 void Save(
Vehicle *v)
const override
807 void Load(
Vehicle *v)
const override
813 void FixPointers(
Vehicle *v)
const override
822 inline static const SaveLoad description[] = {
837 void Save(
Vehicle *v)
const override
843 void Load(
Vehicle *v)
const override
849 void FixPointers(
Vehicle *v)
const override
858 inline static const SaveLoad description[] = {
866 void Save(
Vehicle *v)
const override
872 void Load(
Vehicle *v)
const override
878 void FixPointers(
Vehicle *v)
const override
887 inline static const SaveLoad description[] = {
906 void Save(
Vehicle *v)
const override
912 void Load(
Vehicle *v)
const override
918 void FixPointers(
Vehicle *v)
const override
927 inline static const SaveLoad description[] = {
940 SLE_VAR(
Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
951 void Save(
Vehicle *v)
const override
957 void Load(
Vehicle *v)
const override
963 void FixPointers(
Vehicle *v)
const override
972 inline static const SaveLoad description[] = {
995 SLE_VAR(
Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
1009 void Save(
Vehicle *v)
const override
1015 void Load(
Vehicle *v)
const override
1021 void FixPointers(
Vehicle *v)
const override
1028 const static SaveLoad _vehicle_desc[] = {
1047 SlSetArrayIndex(v->index);
1079 CargoPacket *cp =
new CargoPacket(_cargo_count, _cargo_periods, _cargo_source, _cargo_source_xy, _cargo_feeder_share);