# HG changeset patch # User celestar # Date 1144425423 0 # Node ID 04173b5ed0d2806117c6e8e224307b62f812f734 # Parent e454e2c0c23e007a779edc94ed36fe6b98b817e0 (svn r4317) -Codechange: More map accessors for ship_cmd. it is now map-access free, but still requires a huge cleanup diff -r e454e2c0c23e -r 04173b5ed0d2 ship_cmd.c --- a/ship_cmd.c Fri Apr 07 09:37:04 2006 +0000 +++ b/ship_cmd.c Fri Apr 07 15:57:03 2006 +0000 @@ -190,17 +190,6 @@ SndPlayVehicleFx(ShipVehInfo(v->engine_type)->sfx, v); } -static const TileIndexDiffC _dock_offs[] = { - { 2, 0}, - {-2, 0}, - { 0, 2}, - { 2, 0}, - { 0, -2}, - { 0, 0}, - { 0, 0}, - { 0, 0} -}; - static void ProcessShipOrder(Vehicle *v) { const Order *order; @@ -245,7 +234,7 @@ st = GetStation(order->station); if (st->dock_tile != 0) { - v->dest_tile = TILE_ADD(st->dock_tile, ToTileIndexDiff(_dock_offs[_m[st->dock_tile].m5-0x4B])); + v->dest_tile = TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile))); } } else if (order->type == OT_GOTO_DEPOT) { v->dest_tile = GetDepot(order->station)->xy; diff -r e454e2c0c23e -r 04173b5ed0d2 station_map.h --- a/station_map.h Fri Apr 07 09:37:04 2006 +0000 +++ b/station_map.h Fri Apr 07 15:57:03 2006 +0000 @@ -184,6 +184,25 @@ return (DiagDirection)(_m[t].m5 - DOCK_BASE); } +static inline TileIndexDiffC GetDockOffset(TileIndex t) +{ + static const TileIndexDiffC buoy_offset = {0, 0}; + static const TileIndexDiffC oilrig_offset = {2, 0}; + static const TileIndexDiffC dock_offset[DIAGDIR_END] = { + {-2, 0}, + { 0, 2}, + { 2, 0}, + { 0, -2}, + }; + assert(IsTileType(t, MP_STATION)); + + if (IsBuoy_(t)) return buoy_offset; + if (IsOilRig(t)) return oilrig_offset; + + assert(IsDock(t)); + + return dock_offset[GetDockDirection(t)]; +} static inline bool IsCustomStationSprite(TileIndex t) {