42 spritenum = orig_ship_vehicle_info[engine - SHIP_ENGINES_INDEX].image_index; |
42 spritenum = orig_ship_vehicle_info[engine - SHIP_ENGINES_INDEX].image_index; |
43 } |
43 } |
44 DrawSprite((6 + _ship_sprites[spritenum]) | image_ormod, x, y); |
44 DrawSprite((6 + _ship_sprites[spritenum]) | image_ormod, x, y); |
45 } |
45 } |
46 |
46 |
47 int GetShipImage(const Vehicle *v, byte direction) |
47 int GetShipImage(const Vehicle* v, Direction direction) |
48 { |
48 { |
49 int spritenum = v->spritenum; |
49 int spritenum = v->spritenum; |
50 |
50 |
51 if (is_custom_sprite(spritenum)) { |
51 if (is_custom_sprite(spritenum)) { |
52 int sprite = GetCustomVehicleSprite(v, direction); |
52 int sprite = GetCustomVehicleSprite(v, direction); |
577 return -1; |
577 return -1; |
578 return track; |
578 return track; |
579 } |
579 } |
580 } |
580 } |
581 |
581 |
582 static const byte _new_vehicle_direction_table[11] = { |
582 static const Direction _new_vehicle_direction_table[] = { |
583 0, 7, 6, 0, |
583 DIR_N , DIR_NW, DIR_W , 0, |
584 1, 0, 5, 0, |
584 DIR_NE, DIR_N , DIR_SW, 0, |
585 2, 3, 4, |
585 DIR_E , DIR_SE, DIR_S |
586 }; |
586 }; |
587 |
587 |
588 static int ShipGetNewDirectionFromTiles(TileIndex new_tile, TileIndex old_tile) |
588 static int ShipGetNewDirectionFromTiles(TileIndex new_tile, TileIndex old_tile) |
589 { |
589 { |
590 uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 + |
590 uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 + |
734 } |
736 } |
735 } |
737 } |
736 } |
738 } |
737 } |
739 } |
738 } else { |
740 } else { |
|
741 DiagDirection diagdir; |
739 // new tile |
742 // new tile |
740 if (TileX(gp.new_tile) >= MapMaxX() || TileY(gp.new_tile) >= MapMaxY()) |
743 if (TileX(gp.new_tile) >= MapMaxX() || TileY(gp.new_tile) >= MapMaxY()) |
741 goto reverse_direction; |
744 goto reverse_direction; |
742 |
745 |
743 dir = ShipGetNewDirectionFromTiles(gp.new_tile, gp.old_tile); |
746 dir = ShipGetNewDirectionFromTiles(gp.new_tile, gp.old_tile); |
744 assert(dir == 1 || dir == 3 || dir == 5 || dir == 7); |
747 assert(dir == DIR_NE || dir == DIR_SE || dir == DIR_SW || dir == DIR_NW); |
745 dir>>=1; |
748 diagdir = DirToDiagDir(dir); |
746 tracks = GetAvailShipTracks(gp.new_tile, dir); |
749 tracks = GetAvailShipTracks(gp.new_tile, diagdir); |
747 if (tracks == 0) |
750 if (tracks == 0) |
748 goto reverse_direction; |
751 goto reverse_direction; |
749 |
752 |
750 // Choose a direction, and continue if we find one |
753 // Choose a direction, and continue if we find one |
751 track = ChooseShipTrack(v, gp.new_tile, dir, tracks); |
754 track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks); |
752 if (track < 0) |
755 if (track < 0) |
753 goto reverse_direction; |
756 goto reverse_direction; |
754 |
757 |
755 b = _ship_subcoord[dir][track]; |
758 b = _ship_subcoord[diagdir][track]; |
756 |
759 |
757 gp.x = (gp.x&~0xF) | b[0]; |
760 gp.x = (gp.x&~0xF) | b[0]; |
758 gp.y = (gp.y&~0xF) | b[1]; |
761 gp.y = (gp.y&~0xF) | b[1]; |
759 |
762 |
760 /* Call the landscape function and tell it that the vehicle entered the tile */ |
763 /* Call the landscape function and tell it that the vehicle entered the tile */ |