694 Vehicle *w = v->depot_list; |
697 Vehicle *w = v->depot_list; |
695 v->depot_list = NULL; // it should always be NULL at the end of each tick |
698 v->depot_list = NULL; // it should always be NULL at the end of each tick |
696 MaybeReplaceVehicle(v, false, true); |
699 MaybeReplaceVehicle(v, false, true); |
697 v = w; |
700 v = w; |
698 } |
701 } |
699 } |
|
700 |
|
701 static bool CanFillVehicle_FullLoadAny(Vehicle *v) |
|
702 { |
|
703 uint32 full = 0, not_full = 0; |
|
704 bool keep_loading = false; |
|
705 const GoodsEntry *ge = GetStation(v->last_station_visited)->goods; |
|
706 |
|
707 /* special handling of aircraft */ |
|
708 |
|
709 /* if the aircraft carries passengers and is NOT full, then |
|
710 *continue loading, no matter how much mail is in */ |
|
711 if (v->type == VEH_AIRCRAFT && |
|
712 IsCargoInClass(v->cargo_type, CC_PASSENGERS) && |
|
713 v->cargo_cap != v->cargo_count) { |
|
714 return true; |
|
715 } |
|
716 |
|
717 /* patch should return "true" to continue loading, i.e. when there is no cargo type that is fully loaded. */ |
|
718 do { |
|
719 /* Should never happen, but just in case future additions change this */ |
|
720 assert(v->cargo_type<32); |
|
721 |
|
722 if (v->cargo_cap != 0) { |
|
723 uint32 mask = 1 << v->cargo_type; |
|
724 |
|
725 if (v->cargo_cap == v->cargo_count) { |
|
726 full |= mask; |
|
727 } else if (GB(ge[v->cargo_type].waiting_acceptance, 0, 12) > 0 || |
|
728 (HASBIT(v->vehicle_flags, VF_CARGO_UNLOADING) && (ge[v->cargo_type].waiting_acceptance & 0x8000))) { |
|
729 /* If there is any cargo waiting, or this vehicle is still unloading |
|
730 * and the station accepts the cargo, don't leave the station. */ |
|
731 keep_loading = true; |
|
732 } else { |
|
733 not_full |= mask; |
|
734 } |
|
735 } |
|
736 } while ((v = v->next) != NULL); |
|
737 |
|
738 /* continue loading if there is a non full cargo type and no cargo type that is full */ |
|
739 return keep_loading || (not_full && (full & ~not_full) == 0); |
|
740 } |
|
741 |
|
742 bool CanFillVehicle(Vehicle *v) |
|
743 { |
|
744 TileIndex tile = v->tile; |
|
745 |
|
746 if (IsTileType(tile, MP_STATION) || |
|
747 (v->type == VEH_SHIP && ( |
|
748 IsTileType(TILE_ADDXY(tile, 1, 0), MP_STATION) || |
|
749 IsTileType(TILE_ADDXY(tile, -1, 0), MP_STATION) || |
|
750 IsTileType(TILE_ADDXY(tile, 0, 1), MP_STATION) || |
|
751 IsTileType(TILE_ADDXY(tile, 0, -1), MP_STATION) || |
|
752 IsTileType(TILE_ADDXY(tile, -2, 0), MP_STATION) |
|
753 ))) { |
|
754 |
|
755 /* If patch is active, use alternative CanFillVehicle-function */ |
|
756 if (_patches.full_load_any && v->current_order.flags & OF_FULL_LOAD) return CanFillVehicle_FullLoadAny(v); |
|
757 |
|
758 do { |
|
759 if (v->cargo_count != v->cargo_cap) return true; |
|
760 } while ((v = v->next) != NULL); |
|
761 } |
|
762 return false; |
|
763 } |
702 } |
764 |
703 |
765 /** Check if a given engine type can be refitted to a given cargo |
704 /** Check if a given engine type can be refitted to a given cargo |
766 * @param engine_type Engine type to check |
705 * @param engine_type Engine type to check |
767 * @param cid_to check refit to this cargo-type |
706 * @param cid_to check refit to this cargo-type |
1900 } while (v->type == VEH_TRAIN && (v = GetNextVehicle(v)) != NULL); |
1814 } while (v->type == VEH_TRAIN && (v = GetNextVehicle(v)) != NULL); |
1901 |
1815 |
1902 if (flags & DC_EXEC && v_front->type == VEH_TRAIN) { |
1816 if (flags & DC_EXEC && v_front->type == VEH_TRAIN) { |
1903 /* for trains this needs to be the front engine due to the callback function */ |
1817 /* for trains this needs to be the front engine due to the callback function */ |
1904 _new_vehicle_id = w_front->index; |
1818 _new_vehicle_id = w_front->index; |
|
1819 } |
|
1820 |
|
1821 /* Take care of refitting. */ |
|
1822 w = w_front; |
|
1823 v = v_front; |
|
1824 |
|
1825 /* Both building and refitting are influenced by newgrf callbacks, which |
|
1826 * makes it impossible to accurately estimate the cloning costs. In |
|
1827 * particular, it is possible for engines of the same type to be built with |
|
1828 * different numbers of articulated parts, so when refitting we have to |
|
1829 * loop over real vehicles first, and then the articulated parts of those |
|
1830 * vehicles in a different loop. */ |
|
1831 do { |
|
1832 do { |
|
1833 if (flags & DC_EXEC) { |
|
1834 assert(w != NULL); |
|
1835 |
|
1836 if (w->cargo_type != v->cargo_type || w->cargo_subtype != v->cargo_type) { |
|
1837 cost = DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8) | 1U << 16 , flags, GetCmdRefitVeh(v)); |
|
1838 if (!CmdFailed(cost)) total_cost += cost; |
|
1839 } |
|
1840 |
|
1841 if (w->type == VEH_TRAIN && EngineHasArticPart(w)) { |
|
1842 w = GetNextArticPart(w); |
|
1843 } else { |
|
1844 break; |
|
1845 } |
|
1846 } else { |
|
1847 CargoID initial_cargo = GetEngineCargoType(v->engine_type); |
|
1848 |
|
1849 if (v->cargo_type != initial_cargo && initial_cargo != CT_INVALID) { |
|
1850 total_cost += GetRefitCost(v->engine_type); |
|
1851 } |
|
1852 } |
|
1853 } while (v->type == VEH_TRAIN && EngineHasArticPart(v) && (v = GetNextArticPart(v)) != NULL); |
|
1854 |
|
1855 if (flags & DC_EXEC) w = GetNextVehicle(w); |
|
1856 } while (v->type == VEH_TRAIN && (v = GetNextVehicle(v)) != NULL); |
|
1857 |
|
1858 /* Since we can't estimate the cost of cloning a vehicle accurately we must |
|
1859 * check whether the player has enough money manually. */ |
|
1860 if (!CheckPlayerHasMoney(total_cost)) { |
|
1861 if (flags & DC_EXEC) { |
|
1862 /* The vehicle has already been bought, so now it must be sold again. */ |
|
1863 DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front)); |
|
1864 } |
|
1865 return CMD_ERROR; |
1905 } |
1866 } |
1906 |
1867 |
1907 /* Set the expense type last as refitting will make the cost go towards |
1868 /* Set the expense type last as refitting will make the cost go towards |
1908 * running costs... */ |
1869 * running costs... */ |
1909 SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
1870 SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
2619 SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
2581 SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
2620 SLE_CONDVAR(Vehicle, y_pos, SLE_UINT32, 6, SL_MAX_VERSION), |
2582 SLE_CONDVAR(Vehicle, y_pos, SLE_UINT32, 6, SL_MAX_VERSION), |
2621 SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
2583 SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
2622 SLE_VAR(Vehicle, direction, SLE_UINT8), |
2584 SLE_VAR(Vehicle, direction, SLE_UINT8), |
2623 |
2585 |
2624 SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
2586 SLE_CONDNULL(2, 0, 57), |
2625 SLE_VAR(Vehicle, spritenum, SLE_UINT8), |
2587 SLE_VAR(Vehicle, spritenum, SLE_UINT8), |
2626 SLE_VAR(Vehicle, sprite_width, SLE_UINT8), |
2588 SLE_CONDNULL(5, 0, 57), |
2627 SLE_VAR(Vehicle, sprite_height, SLE_UINT8), |
|
2628 SLE_VAR(Vehicle, z_height, SLE_UINT8), |
|
2629 SLE_VAR(Vehicle, x_offs, SLE_INT8), |
|
2630 SLE_VAR(Vehicle, y_offs, SLE_INT8), |
|
2631 SLE_VAR(Vehicle, engine_type, SLE_UINT16), |
2589 SLE_VAR(Vehicle, engine_type, SLE_UINT16), |
2632 |
2590 |
2633 SLE_VAR(Vehicle, max_speed, SLE_UINT16), |
2591 SLE_VAR(Vehicle, max_speed, SLE_UINT16), |
2634 SLE_VAR(Vehicle, cur_speed, SLE_UINT16), |
2592 SLE_VAR(Vehicle, cur_speed, SLE_UINT16), |
2635 SLE_VAR(Vehicle, subspeed, SLE_UINT8), |
2593 SLE_VAR(Vehicle, subspeed, SLE_UINT8), |
2656 SLE_VAR(Vehicle, num_orders, SLE_UINT8), |
2614 SLE_VAR(Vehicle, num_orders, SLE_UINT8), |
2657 |
2615 |
2658 /* This next line is for version 4 and prior compatibility.. it temporarily reads |
2616 /* This next line is for version 4 and prior compatibility.. it temporarily reads |
2659 type and flags (which were both 4 bits) into type. Later on this is |
2617 type and flags (which were both 4 bits) into type. Later on this is |
2660 converted correctly */ |
2618 converted correctly */ |
2661 SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type), SLE_UINT8, 0, 4), |
2619 SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, type), SLE_UINT8, 0, 4), |
2662 SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
2620 SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
2663 |
2621 |
2664 /* Orders for version 5 and on */ |
2622 /* Orders for version 5 and on */ |
2665 SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type), SLE_UINT8, 5, SL_MAX_VERSION), |
2623 SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, type), SLE_UINT8, 5, SL_MAX_VERSION), |
2666 SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, flags), SLE_UINT8, 5, SL_MAX_VERSION), |
2624 SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, flags), SLE_UINT8, 5, SL_MAX_VERSION), |
2667 SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION), |
2625 SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION), |
2668 |
2626 |
2669 /* Refit in current order */ |
2627 /* Refit in current order */ |
2670 SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, refit_cargo), SLE_UINT8, 36, SL_MAX_VERSION), |
2628 SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, refit_cargo), SLE_UINT8, 36, SL_MAX_VERSION), |
2671 SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, refit_subtype), SLE_UINT8, 36, SL_MAX_VERSION), |
2629 SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, refit_subtype), SLE_UINT8, 36, SL_MAX_VERSION), |
2672 |
2630 |
2673 SLE_REF(Vehicle, orders, REF_ORDER), |
2631 SLE_REF(Vehicle, orders, REF_ORDER), |
2674 |
2632 |
2675 SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
2633 SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
2676 SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION), |
2634 SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION), |
2713 |
2671 |
2714 |
2672 |
2715 static const SaveLoad _train_desc[] = { |
2673 static const SaveLoad _train_desc[] = { |
2716 SLE_WRITEBYTE(Vehicle, type, VEH_TRAIN, 0), // Train type. VEH_TRAIN in mem, 0 in file. |
2674 SLE_WRITEBYTE(Vehicle, type, VEH_TRAIN, 0), // Train type. VEH_TRAIN in mem, 0 in file. |
2717 SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
2675 SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
2718 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRail, crash_anim_pos), SLE_UINT16), |
2676 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, crash_anim_pos), SLE_UINT16), |
2719 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRail, force_proceed), SLE_UINT8), |
2677 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, force_proceed), SLE_UINT8), |
2720 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRail, railtype), SLE_UINT8), |
2678 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, railtype), SLE_UINT8), |
2721 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRail, track), SLE_UINT8), |
2679 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, track), SLE_UINT8), |
2722 |
2680 |
2723 SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleRail, flags), SLE_UINT8, 2, SL_MAX_VERSION), |
2681 SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, flags), SLE_UINT8, 2, SL_MAX_VERSION), |
2724 SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleRail, days_since_order_progr), SLE_UINT16, 2, SL_MAX_VERSION), |
2682 SLE_CONDNULL(2, 2, 59), |
2725 |
2683 |
2726 SLE_CONDNULL(2, 2, 19), |
2684 SLE_CONDNULL(2, 2, 19), |
2727 /* reserve extra space in savegame here. (currently 11 bytes) */ |
2685 /* reserve extra space in savegame here. (currently 11 bytes) */ |
2728 SLE_CONDNULL(11, 2, SL_MAX_VERSION), |
2686 SLE_CONDNULL(11, 2, SL_MAX_VERSION), |
2729 |
2687 |
2731 }; |
2689 }; |
2732 |
2690 |
2733 static const SaveLoad _roadveh_desc[] = { |
2691 static const SaveLoad _roadveh_desc[] = { |
2734 SLE_WRITEBYTE(Vehicle, type, VEH_ROAD, 1), // Road type. VEH_ROAD in mem, 1 in file. |
2692 SLE_WRITEBYTE(Vehicle, type, VEH_ROAD, 1), // Road type. VEH_ROAD in mem, 1 in file. |
2735 SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
2693 SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
2736 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, state), SLE_UINT8), |
2694 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, state), SLE_UINT8), |
2737 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, frame), SLE_UINT8), |
2695 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, frame), SLE_UINT8), |
2738 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, blocked_ctr), SLE_UINT16), |
2696 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, blocked_ctr), SLE_UINT16), |
2739 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, overtaking), SLE_UINT8), |
2697 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, overtaking), SLE_UINT8), |
2740 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, overtaking_ctr), SLE_UINT8), |
2698 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, overtaking_ctr), SLE_UINT8), |
2741 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, crashed_ctr), SLE_UINT16), |
2699 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, crashed_ctr), SLE_UINT16), |
2742 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, reverse_ctr), SLE_UINT8), |
2700 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, reverse_ctr), SLE_UINT8), |
2743 |
2701 |
2744 SLE_CONDREFX(offsetof(Vehicle, u) + offsetof(VehicleRoad, slot), REF_ROADSTOPS, 6, SL_MAX_VERSION), |
2702 SLE_CONDREFX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, slot), REF_ROADSTOPS, 6, SL_MAX_VERSION), |
2745 SLE_CONDNULL(1, 6, SL_MAX_VERSION), |
2703 SLE_CONDNULL(1, 6, SL_MAX_VERSION), |
2746 SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, slot_age), SLE_UINT8, 6, SL_MAX_VERSION), |
2704 SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, slot_age), SLE_UINT8, 6, SL_MAX_VERSION), |
2747 /* reserve extra space in savegame here. (currently 16 bytes) */ |
2705 /* reserve extra space in savegame here. (currently 16 bytes) */ |
2748 SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
2706 SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
2749 |
2707 |
2750 SLE_END() |
2708 SLE_END() |
2751 }; |
2709 }; |
2752 |
2710 |
2753 static const SaveLoad _ship_desc[] = { |
2711 static const SaveLoad _ship_desc[] = { |
2754 SLE_WRITEBYTE(Vehicle, type, VEH_SHIP, 2), // Ship type. VEH_SHIP in mem, 2 in file. |
2712 SLE_WRITEBYTE(Vehicle, type, VEH_SHIP, 2), // Ship type. VEH_SHIP in mem, 2 in file. |
2755 SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
2713 SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
2756 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleShip, state), SLE_UINT8), |
2714 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleShip, state), SLE_UINT8), |
2757 |
2715 |
2758 /* reserve extra space in savegame here. (currently 16 bytes) */ |
2716 /* reserve extra space in savegame here. (currently 16 bytes) */ |
2759 SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
2717 SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
2760 |
2718 |
2761 SLE_END() |
2719 SLE_END() |
2762 }; |
2720 }; |
2763 |
2721 |
2764 static const SaveLoad _aircraft_desc[] = { |
2722 static const SaveLoad _aircraft_desc[] = { |
2765 SLE_WRITEBYTE(Vehicle, type, VEH_AIRCRAFT, 3), // Aircraft type. VEH_AIRCRAFT in mem, 3 in file. |
2723 SLE_WRITEBYTE(Vehicle, type, VEH_AIRCRAFT, 3), // Aircraft type. VEH_AIRCRAFT in mem, 3 in file. |
2766 SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
2724 SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
2767 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleAir, crashed_counter), SLE_UINT16), |
2725 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, crashed_counter), SLE_UINT16), |
2768 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleAir, pos), SLE_UINT8), |
2726 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, pos), SLE_UINT8), |
2769 |
2727 |
2770 SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleAir, targetairport), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
2728 SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, targetairport), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
2771 SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleAir, targetairport), SLE_UINT16, 5, SL_MAX_VERSION), |
2729 SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, targetairport), SLE_UINT16, 5, SL_MAX_VERSION), |
2772 |
2730 |
2773 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleAir, state), SLE_UINT8), |
2731 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, state), SLE_UINT8), |
2774 |
2732 |
2775 SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleAir, previous_pos), SLE_UINT8, 2, SL_MAX_VERSION), |
2733 SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, previous_pos), SLE_UINT8, 2, SL_MAX_VERSION), |
2776 |
2734 |
2777 /* reserve extra space in savegame here. (currently 15 bytes) */ |
2735 /* reserve extra space in savegame here. (currently 15 bytes) */ |
2778 SLE_CONDNULL(15, 2, SL_MAX_VERSION), |
2736 SLE_CONDNULL(15, 2, SL_MAX_VERSION), |
2779 |
2737 |
2780 SLE_END() |
2738 SLE_END() |
2793 SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
2751 SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
2794 SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
2752 SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
2795 SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
2753 SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
2796 |
2754 |
2797 SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
2755 SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
2798 SLE_VAR(Vehicle, sprite_width, SLE_UINT8), |
2756 SLE_CONDNULL(5, 0, 57), |
2799 SLE_VAR(Vehicle, sprite_height, SLE_UINT8), |
|
2800 SLE_VAR(Vehicle, z_height, SLE_UINT8), |
|
2801 SLE_VAR(Vehicle, x_offs, SLE_INT8), |
|
2802 SLE_VAR(Vehicle, y_offs, SLE_INT8), |
|
2803 SLE_VAR(Vehicle, progress, SLE_UINT8), |
2757 SLE_VAR(Vehicle, progress, SLE_UINT8), |
2804 SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
2758 SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
2805 |
2759 |
2806 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleSpecial, unk0), SLE_UINT16), |
2760 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleSpecial, unk0), SLE_UINT16), |
2807 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleSpecial, unk2), SLE_UINT8), |
2761 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleSpecial, unk2), SLE_UINT8), |
2808 |
2762 |
2809 /* reserve extra space in savegame here. (currently 16 bytes) */ |
2763 /* reserve extra space in savegame here. (currently 16 bytes) */ |
2810 SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
2764 SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
2811 |
2765 |
2812 SLE_END() |
2766 SLE_END() |
2828 SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
2782 SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
2829 SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
2783 SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
2830 SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
2784 SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
2831 SLE_VAR(Vehicle, direction, SLE_UINT8), |
2785 SLE_VAR(Vehicle, direction, SLE_UINT8), |
2832 |
2786 |
2833 SLE_VAR(Vehicle, x_offs, SLE_INT8), |
2787 SLE_CONDNULL(5, 0, 57), |
2834 SLE_VAR(Vehicle, y_offs, SLE_INT8), |
|
2835 SLE_VAR(Vehicle, sprite_width, SLE_UINT8), |
|
2836 SLE_VAR(Vehicle, sprite_height, SLE_UINT8), |
|
2837 SLE_VAR(Vehicle, z_height, SLE_UINT8), |
|
2838 SLE_VAR(Vehicle, owner, SLE_UINT8), |
2788 SLE_VAR(Vehicle, owner, SLE_UINT8), |
2839 SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
2789 SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
2840 SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
2790 SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
2841 SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION), |
2791 SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION), |
2842 |
2792 |
2843 SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
2793 SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
2844 SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
2794 SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
2845 SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION), |
2795 SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION), |
2846 SLE_VAR(Vehicle, tick_counter, SLE_UINT8), |
2796 SLE_VAR(Vehicle, tick_counter, SLE_UINT8), |
2847 |
2797 |
2848 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleDisaster, image_override), SLE_UINT16), |
2798 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleDisaster, image_override), SLE_UINT16), |
2849 SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleDisaster, unk2), SLE_UINT16), |
2799 SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleDisaster, unk2), SLE_UINT16), |
2850 |
2800 |
2851 /* reserve extra space in savegame here. (currently 16 bytes) */ |
2801 /* reserve extra space in savegame here. (currently 16 bytes) */ |
2852 SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
2802 SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
2853 |
2803 |
2854 SLE_END() |
2804 SLE_END() |
2925 }; |
2885 }; |
2926 |
2886 |
2927 void Vehicle::BeginLoading() |
2887 void Vehicle::BeginLoading() |
2928 { |
2888 { |
2929 assert(IsTileType(tile, MP_STATION) || type == VEH_SHIP); |
2889 assert(IsTileType(tile, MP_STATION) || type == VEH_SHIP); |
|
2890 |
|
2891 if (this->current_order.type == OT_GOTO_STATION && |
|
2892 this->current_order.dest == this->last_station_visited) { |
|
2893 /* Arriving at the ordered station. |
|
2894 * Keep the load/unload flags, as we (obviously) still need them. */ |
|
2895 this->current_order.flags &= OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER; |
|
2896 |
|
2897 /* Furthermore add the Non Stop flag to mark that this station |
|
2898 * is the actual destination of the vehicle, which is (for example) |
|
2899 * necessary to be known for HandleTrainLoading to determine |
|
2900 * whether the train is lost or not; not marking a train lost |
|
2901 * that arrives at random stations is bad. */ |
|
2902 this->current_order.flags |= OF_NON_STOP; |
|
2903 } else { |
|
2904 /* This is just an unordered intermediate stop */ |
|
2905 this->current_order.flags = 0; |
|
2906 } |
|
2907 |
2930 current_order.type = OT_LOADING; |
2908 current_order.type = OT_LOADING; |
2931 GetStation(this->last_station_visited)->loading_vehicles.push_back(this); |
2909 GetStation(this->last_station_visited)->loading_vehicles.push_back(this); |
|
2910 |
|
2911 SET_EXPENSES_TYPE(this->GetExpenseType(true)); |
|
2912 VehiclePayment(this); |
|
2913 |
|
2914 InvalidateWindow(this->GetVehicleListWindowClass(), this->owner); |
|
2915 InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, STATUS_BAR); |
|
2916 InvalidateWindow(WC_VEHICLE_DETAILS, this->index); |
|
2917 InvalidateWindow(WC_STATION_VIEW, this->last_station_visited); |
|
2918 |
|
2919 GetStation(this->last_station_visited)->MarkTilesDirty(); |
|
2920 this->MarkDirty(); |
2932 } |
2921 } |
2933 |
2922 |
2934 void Vehicle::LeaveStation() |
2923 void Vehicle::LeaveStation() |
2935 { |
2924 { |
2936 assert(IsTileType(tile, MP_STATION) || type == VEH_SHIP); |
|
2937 assert(current_order.type == OT_LOADING); |
2925 assert(current_order.type == OT_LOADING); |
2938 current_order.type = OT_LEAVESTATION; |
2926 current_order.type = OT_LEAVESTATION; |
2939 current_order.flags = 0; |
2927 current_order.flags = 0; |
2940 GetStation(this->last_station_visited)->loading_vehicles.remove(this); |
2928 GetStation(this->last_station_visited)->loading_vehicles.remove(this); |
2941 } |
2929 } |
|
2930 |
|
2931 |
|
2932 void Vehicle::HandleLoading(bool mode) |
|
2933 { |
|
2934 switch (this->current_order.type) { |
|
2935 case OT_LOADING: { |
|
2936 /* Not the first call for this tick */ |
|
2937 if (mode) return; |
|
2938 |
|
2939 /* We have not waited enough time till the next round of loading/unloading */ |
|
2940 if (--this->load_unload_time_rem) return; |
|
2941 |
|
2942 /* Load/unload the vehicle; when it actually did something |
|
2943 * we do not leave the station. */ |
|
2944 if (LoadUnloadVehicle(this)) return; |
|
2945 |
|
2946 this->PlayLeaveStationSound(); |
|
2947 |
|
2948 Order b = this->current_order; |
|
2949 this->LeaveStation(); |
|
2950 |
|
2951 /* If this was not the final order, don't remove it from the list. */ |
|
2952 if (!(b.flags & OF_NON_STOP)) return; |
|
2953 break; |
|
2954 } |
|
2955 |
|
2956 case OT_DUMMY: break; |
|
2957 |
|
2958 default: return; |
|
2959 } |
|
2960 |
|
2961 this->cur_order_index++; |
|
2962 InvalidateVehicleOrder(this); |
|
2963 } |
|
2964 |
|
2965 |
|
2966 void SpecialVehicle::UpdateDeltaXY(Direction direction) |
|
2967 { |
|
2968 this->x_offs = 0; |
|
2969 this->y_offs = 0; |
|
2970 this->sprite_width = 1; |
|
2971 this->sprite_height = 1; |
|
2972 this->z_height = 1; |
|
2973 } |