691 if (!ShipAccelerate(v)) return; |
691 if (!ShipAccelerate(v)) return; |
692 |
692 |
693 BeginVehicleMove(v); |
693 BeginVehicleMove(v); |
694 |
694 |
695 if (GetNewVehiclePos(v, &gp)) { |
695 if (GetNewVehiclePos(v, &gp)) { |
696 // staying in tile |
696 /* Staying in tile */ |
697 if (IsShipInDepot(v)) { |
697 if (IsShipInDepot(v)) { |
698 gp.x = v->x_pos; |
698 gp.x = v->x_pos; |
699 gp.y = v->y_pos; |
699 gp.y = v->y_pos; |
700 } else { |
700 } else { |
701 /* isnot inside depot */ |
701 /* Not inside depot */ |
702 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
702 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
703 if (HASBIT(r, VETS_CANNOT_ENTER)) goto reverse_direction; |
703 if (HASBIT(r, VETS_CANNOT_ENTER)) goto reverse_direction; |
704 |
704 |
705 /* A leave station order only needs one tick to get processed, so we can |
705 /* A leave station order only needs one tick to get processed, so we can |
706 * always skip ahead. */ |
706 * always skip ahead. */ |
720 InvalidateVehicleOrder(v); |
720 InvalidateVehicleOrder(v); |
721 } else { |
721 } else { |
722 /* Non-buoy orders really need to reach the tile */ |
722 /* Non-buoy orders really need to reach the tile */ |
723 if (v->dest_tile == gp.new_tile) { |
723 if (v->dest_tile == gp.new_tile) { |
724 if (v->current_order.type == OT_GOTO_DEPOT) { |
724 if (v->current_order.type == OT_GOTO_DEPOT) { |
725 if ((gp.x&0xF)==8 && (gp.y&0xF)==8) { |
725 if ((gp.x & 0xF) == 8 && (gp.y & 0xF) == 8) { |
726 VehicleEnterDepot(v); |
726 VehicleEnterDepot(v); |
727 return; |
727 return; |
728 } |
728 } |
729 } else if (v->current_order.type == OT_GOTO_STATION) { |
729 } else if (v->current_order.type == OT_GOTO_STATION) { |
730 Station *st; |
730 Station *st; |
755 } |
755 } |
756 } |
756 } |
757 } |
757 } |
758 } else { |
758 } else { |
759 DiagDirection diagdir; |
759 DiagDirection diagdir; |
760 // new tile |
760 /* New tile */ |
761 if (TileX(gp.new_tile) >= MapMaxX() || TileY(gp.new_tile) >= MapMaxY()) |
761 if (TileX(gp.new_tile) >= MapMaxX() || TileY(gp.new_tile) >= MapMaxY()) { |
762 goto reverse_direction; |
762 goto reverse_direction; |
|
763 } |
763 |
764 |
764 dir = ShipGetNewDirectionFromTiles(gp.new_tile, gp.old_tile); |
765 dir = ShipGetNewDirectionFromTiles(gp.new_tile, gp.old_tile); |
765 assert(dir == DIR_NE || dir == DIR_SE || dir == DIR_SW || dir == DIR_NW); |
766 assert(dir == DIR_NE || dir == DIR_SE || dir == DIR_SW || dir == DIR_NW); |
766 diagdir = DirToDiagDir(dir); |
767 diagdir = DirToDiagDir(dir); |
767 tracks = GetAvailShipTracks(gp.new_tile, diagdir); |
768 tracks = GetAvailShipTracks(gp.new_tile, diagdir); |
768 if (tracks == 0) |
769 if (tracks == TRACK_BIT_NONE) goto reverse_direction; |
769 goto reverse_direction; |
770 |
770 |
771 /* Choose a direction, and continue if we find one */ |
771 // Choose a direction, and continue if we find one |
|
772 track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks); |
772 track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks); |
773 if (track == INVALID_TRACK) |
773 if (track == INVALID_TRACK) goto reverse_direction; |
774 goto reverse_direction; |
|
775 |
774 |
776 b = _ship_subcoord[diagdir][track]; |
775 b = _ship_subcoord[diagdir][track]; |
777 |
776 |
778 gp.x = (gp.x&~0xF) | b[0]; |
777 gp.x = (gp.x & ~0xF) | b[0]; |
779 gp.y = (gp.y&~0xF) | b[1]; |
778 gp.y = (gp.y & ~0xF) | b[1]; |
780 |
779 |
781 /* Call the landscape function and tell it that the vehicle entered the tile */ |
780 /* Call the landscape function and tell it that the vehicle entered the tile */ |
782 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
781 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
783 if (HASBIT(r, VETS_CANNOT_ENTER)) goto reverse_direction; |
782 if (HASBIT(r, VETS_CANNOT_ENTER)) goto reverse_direction; |
784 |
783 |