Mercurial > hg > openttd
changeset 3961:4a3e1d2e1925 draft
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
author | tron <tron@openttd.org> |
---|---|
date | Mon, 05 Jun 2006 11:28:00 +0000 |
parents | 9b52296d06a4 |
children | 082bf707b9ef |
files | ship_cmd.c ship_gui.c vehicle.c |
diffstat | 3 files changed, 18 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/ship_cmd.c +++ b/ship_cmd.c @@ -2,6 +2,7 @@ #include "stdafx.h" #include "openttd.h" +#include "ship.h" #include "table/strings.h" #include "functions.h" #include "map.h" @@ -319,7 +320,7 @@ Axis axis; uint m; - if (v->u.ship.state != 0x80) return; + if (!IsShipInDepot(v)) return; tile = v->tile; axis = GetShipDepotAxis(tile); @@ -681,7 +682,7 @@ if (GetNewVehiclePos(v, &gp)) { // staying in tile - if (v->u.ship.state == 0x80) { + if (IsShipInDepot(v)) { gp.x = v->x_pos; gp.y = v->y_pos; } else { @@ -931,8 +932,9 @@ SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); - if (!IsTileDepotType(v->tile, TRANSPORT_WATER) || v->u.ship.state != 0x80 || !(v->vehstatus&VS_STOPPED)) + if (!IsShipInDepotStopped(v)) { return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN); + } if (flags & DC_EXEC) { InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); @@ -963,7 +965,7 @@ if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR; if (flags & DC_EXEC) { - if (v->vehstatus & VS_STOPPED && v->u.ship.state == 0x80) { + if (IsShipInDepotStopped(v)) { DeleteVehicleNews(p1, STR_981C_SHIP_IS_WAITING_IN_DEPOT); } @@ -1045,9 +1047,9 @@ if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR; - if (!IsTileDepotType(v->tile, TRANSPORT_WATER) || !(v->vehstatus&VS_STOPPED) || v->u.ship.state != 0x80) - return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN); - + if (!IsShipInDepotStopped(v)) { + return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN); + } /* Check cargo */ if (!ShipVehInfo(v->engine_type)->refittable) return CMD_ERROR;
--- a/ship_gui.c +++ b/ship_gui.c @@ -4,6 +4,7 @@ #include "openttd.h" #include "debug.h" #include "functions.h" +#include "ship.h" #include "table/strings.h" #include "table/sprites.h" #include "map.h" @@ -466,11 +467,9 @@ StringID str; // Possible to refit? - if (ShipVehInfo(v->engine_type)->refittable && - v->vehstatus&VS_STOPPED && - v->u.ship.state == 0x80 && - IsTileDepotType(v->tile, TRANSPORT_WATER)) + if (ShipVehInfo(v->engine_type)->refittable && IsShipInDepotStopped(v)) { disabled = 0; + } if (v->owner != _local_player) disabled |= 1<<8 | 1<<7; @@ -568,7 +567,7 @@ Vehicle *v; uint32 h; v = GetVehicle(w->window_number); - h = IsTileDepotType(v->tile, TRANSPORT_WATER) && v->vehstatus & VS_HIDDEN ? (1<< 7) : (1 << 11); + h = IsShipInDepot(v) ? 1 << 7 : 1 << 11; if (h != w->hidden_state) { w->hidden_state = h; SetWindowDirty(w); @@ -629,7 +628,7 @@ /* determine amount of items for scroller */ num = 0; FOR_ALL_VEHICLES(v) { - if (v->type == VEH_Ship && v->u.ship.state == 0x80 && v->tile == tile) + if (v->type == VEH_Ship && IsShipInDepot(v) && v->tile == tile) num++; } SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap); @@ -646,7 +645,7 @@ num = w->vscroll.pos * w->hscroll.cap; FOR_ALL_VEHICLES(v) { - if (v->type == VEH_Ship && v->u.ship.state == 0x80 && v->tile == tile && + if (v->type == VEH_Ship && IsShipInDepot(v) && v->tile == tile && --num < 0 && num >= -w->vscroll.cap * w->hscroll.cap) { DrawShipImage(v, x+19, y, WP(w,traindepot_d).sel); @@ -1013,7 +1012,7 @@ DrawVehicleProfitButton(v, x, y + 13); SetDParam(0, v->unitnumber); - if (IsTileDepotType(v->tile, TRANSPORT_WATER) && (v->vehstatus & VS_HIDDEN)) + if (IsShipInDepot(v)) str = STR_021F; else str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
--- a/vehicle.c +++ b/vehicle.c @@ -4,6 +4,7 @@ #include "openttd.h" #include "road_map.h" #include "roadveh.h" +#include "ship.h" #include "spritecache.h" #include "table/sprites.h" #include "table/strings.h" @@ -1990,7 +1991,7 @@ return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.rail.track),v->direction); case VEH_Ship: - if (v->u.ship.state == 0x80) /* Inside a depot? */ + if (IsShipInDepot(v)) /* We'll assume the ship is facing outwards */ return DiagdirToDiagTrackdir(GetShipDepotDirection(v->tile));