151 } |
151 } |
152 |
152 |
153 const Depot *depot = FindClosestShipDepot(v); |
153 const Depot *depot = FindClosestShipDepot(v); |
154 |
154 |
155 if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) { |
155 if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) { |
156 if (v->current_order.type == OT_GOTO_DEPOT) { |
156 if (v->current_order.IsType(OT_GOTO_DEPOT)) { |
157 v->current_order.type = OT_DUMMY; |
157 v->current_order.MakeDummy(); |
158 v->current_order.flags = 0; |
|
159 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
158 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
160 } |
159 } |
161 return; |
160 return; |
162 } |
161 } |
163 |
162 |
164 v->current_order.type = OT_GOTO_DEPOT; |
163 v->current_order.MakeGoToDepot(depot->index, false); |
165 v->current_order.flags = OFB_NON_STOP; |
|
166 v->current_order.dest = depot->index; |
|
167 v->dest_tile = depot->xy; |
164 v->dest_tile = depot->xy; |
168 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
165 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
169 } |
166 } |
170 |
167 |
171 void Ship::OnNewDay() |
168 void Ship::OnNewDay() |
623 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
620 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
624 if (HasBit(r, VETS_CANNOT_ENTER)) goto reverse_direction; |
621 if (HasBit(r, VETS_CANNOT_ENTER)) goto reverse_direction; |
625 |
622 |
626 /* A leave station order only needs one tick to get processed, so we can |
623 /* A leave station order only needs one tick to get processed, so we can |
627 * always skip ahead. */ |
624 * always skip ahead. */ |
628 if (v->current_order.type == OT_LEAVESTATION) { |
625 if (v->current_order.IsType(OT_LEAVESTATION)) { |
629 v->current_order.Free(); |
626 v->current_order.Free(); |
630 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
627 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
631 } else if (v->dest_tile != 0) { |
628 } else if (v->dest_tile != 0) { |
632 /* We have a target, let's see if we reached it... */ |
629 /* We have a target, let's see if we reached it... */ |
633 if (v->current_order.type == OT_GOTO_STATION && |
630 if (v->current_order.IsType(OT_GOTO_STATION) && |
634 IsBuoyTile(v->dest_tile) && |
631 IsBuoyTile(v->dest_tile) && |
635 DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) { |
632 DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) { |
636 /* We got within 3 tiles of our target buoy, so let's skip to our |
633 /* We got within 3 tiles of our target buoy, so let's skip to our |
637 * next order */ |
634 * next order */ |
638 UpdateVehicleTimetable(v, true); |
635 UpdateVehicleTimetable(v, true); |
639 v->cur_order_index++; |
636 v->cur_order_index++; |
640 v->current_order.type = OT_DUMMY; |
637 v->current_order.MakeDummy(); |
641 InvalidateVehicleOrder(v); |
638 InvalidateVehicleOrder(v); |
642 } else { |
639 } else { |
643 /* Non-buoy orders really need to reach the tile */ |
640 /* Non-buoy orders really need to reach the tile */ |
644 if (v->dest_tile == gp.new_tile) { |
641 if (v->dest_tile == gp.new_tile) { |
645 if (v->current_order.type == OT_GOTO_DEPOT) { |
642 if (v->current_order.IsType(OT_GOTO_DEPOT)) { |
646 if ((gp.x & 0xF) == 8 && (gp.y & 0xF) == 8) { |
643 if ((gp.x & 0xF) == 8 && (gp.y & 0xF) == 8) { |
647 VehicleEnterDepot(v); |
644 VehicleEnterDepot(v); |
648 return; |
645 return; |
649 } |
646 } |
650 } else if (v->current_order.type == OT_GOTO_STATION) { |
647 } else if (v->current_order.IsType(OT_GOTO_STATION)) { |
651 Station *st; |
|
652 |
|
653 v->last_station_visited = v->current_order.dest; |
648 v->last_station_visited = v->current_order.dest; |
654 |
649 |
655 /* Process station in the orderlist. */ |
650 /* Process station in the orderlist. */ |
656 st = GetStation(v->current_order.dest); |
651 Station *st = GetStation(v->current_order.dest); |
657 if (st->facilities & FACIL_DOCK) { // ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations |
652 if (st->facilities & FACIL_DOCK) { // ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations |
658 ShipArrivesAt(v, st); |
653 ShipArrivesAt(v, st); |
659 v->BeginLoading(); |
654 v->BeginLoading(); |
660 } else { // leave stations without docks right aways |
655 } else { // leave stations without docks right aways |
661 v->current_order.type = OT_LEAVESTATION; |
656 v->current_order.MakeLeaveStation(); |
662 v->cur_order_index++; |
657 v->cur_order_index++; |
663 InvalidateVehicleOrder(v); |
658 InvalidateVehicleOrder(v); |
664 } |
659 } |
665 } |
660 } |
666 } |
661 } |
945 if (v->vehstatus & VS_CRASHED) return CMD_ERROR; |
940 if (v->vehstatus & VS_CRASHED) return CMD_ERROR; |
946 |
941 |
947 if (v->IsInDepot()) return CMD_ERROR; |
942 if (v->IsInDepot()) return CMD_ERROR; |
948 |
943 |
949 /* If the current orders are already goto-depot */ |
944 /* If the current orders are already goto-depot */ |
950 if (v->current_order.type == OT_GOTO_DEPOT) { |
945 if (v->current_order.IsType(OT_GOTO_DEPOT)) { |
951 if (!!(p2 & DEPOT_SERVICE) == HasBit(v->current_order.flags, OF_HALT_IN_DEPOT)) { |
946 if (!!(p2 & DEPOT_SERVICE) == HasBit(v->current_order.flags, OF_HALT_IN_DEPOT)) { |
952 /* We called with a different DEPOT_SERVICE setting. |
947 /* We called with a different DEPOT_SERVICE setting. |
953 * Now we change the setting to apply the new one and let the vehicle head for the same depot. |
948 * Now we change the setting to apply the new one and let the vehicle head for the same depot. |
954 * Note: the if is (true for requesting service == true for ordered to stop in depot) */ |
949 * Note: the if is (true for requesting service == true for ordered to stop in depot) */ |
955 if (flags & DC_EXEC) { |
950 if (flags & DC_EXEC) { |
965 /* If the orders to 'goto depot' are in the orders list (forced servicing), |
960 /* If the orders to 'goto depot' are in the orders list (forced servicing), |
966 * then skip to the next order; effectively cancelling this forced service */ |
961 * then skip to the next order; effectively cancelling this forced service */ |
967 if (HasBit(v->current_order.flags, OF_PART_OF_ORDERS)) |
962 if (HasBit(v->current_order.flags, OF_PART_OF_ORDERS)) |
968 v->cur_order_index++; |
963 v->cur_order_index++; |
969 |
964 |
970 v->current_order.type = OT_DUMMY; |
965 v->current_order.MakeDummy(); |
971 v->current_order.flags = 0; |
|
972 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
966 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
973 } |
967 } |
974 return CommandCost(); |
968 return CommandCost(); |
975 } |
969 } |
976 |
970 |
977 dep = FindClosestShipDepot(v); |
971 dep = FindClosestShipDepot(v); |
978 if (dep == NULL) return_cmd_error(STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT); |
972 if (dep == NULL) return_cmd_error(STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT); |
979 |
973 |
980 if (flags & DC_EXEC) { |
974 if (flags & DC_EXEC) { |
981 if (v->current_order.type == OT_LOADING) v->LeaveStation(); |
975 if (v->current_order.IsType(OT_LOADING)) v->LeaveStation(); |
982 |
976 |
983 v->dest_tile = dep->xy; |
977 v->dest_tile = dep->xy; |
984 v->current_order.type = OT_GOTO_DEPOT; |
978 v->current_order.MakeGoToDepot(dep->index, false); |
985 v->current_order.flags = OFB_NON_STOP; |
|
986 if (!(p2 & DEPOT_SERVICE)) SetBit(v->current_order.flags, OF_HALT_IN_DEPOT); |
979 if (!(p2 & DEPOT_SERVICE)) SetBit(v->current_order.flags, OF_HALT_IN_DEPOT); |
987 v->current_order.refit_cargo = CT_INVALID; |
|
988 v->current_order.dest = dep->index; |
|
989 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
980 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
990 } |
981 } |
991 |
982 |
992 return CommandCost(); |
983 return CommandCost(); |
993 } |
984 } |