(svn r5118) Add IsRoadVehInDepot{Stopped,}()

This commit is contained in:
tron 2006-06-05 10:23:18 +00:00
parent ddbcd9007c
commit eeeb8172e8
4 changed files with 28 additions and 10 deletions

15
roadveh.h Normal file
View File

@ -0,0 +1,15 @@
/* $Id$ */
#include "vehicle.h"
static inline bool IsRoadVehInDepot(const Vehicle* v)
{
assert(v->type == VEH_Road);
return v->u.road.state == 254;
}
static inline bool IsRoadVehInDepotStopped(const Vehicle* v)
{
return IsRoadVehInDepot(v) && v->vehstatus & VS_STOPPED;
}

View File

@ -6,6 +6,7 @@
#include "debug.h" #include "debug.h"
#include "functions.h" #include "functions.h"
#include "road_map.h" #include "road_map.h"
#include "roadveh.h"
#include "station_map.h" #include "station_map.h"
#include "table/strings.h" #include "table/strings.h"
#include "map.h" #include "map.h"
@ -216,7 +217,7 @@ int32 CmdStartStopRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
if (v->vehstatus & VS_STOPPED && v->u.road.state == 254) { if (IsRoadVehInDepotStopped(v)) {
DeleteVehicleNews(p1, STR_9016_ROAD_VEHICLE_IS_WAITING); DeleteVehicleNews(p1, STR_9016_ROAD_VEHICLE_IS_WAITING);
} }
@ -259,7 +260,7 @@ int32 CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
if (v->u.road.state != 254 || !(v->vehstatus & VS_STOPPED)) { if (!IsRoadVehInDepotStopped(v)) {
return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE);
} }
@ -409,7 +410,7 @@ int32 CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
v->breakdown_ctr != 0 || v->breakdown_ctr != 0 ||
v->u.road.overtaking != 0 || v->u.road.overtaking != 0 ||
v->u.road.state == 255 || v->u.road.state == 255 ||
v->u.road.state == 254 || IsRoadVehInDepot(v) ||
v->cur_speed < 5) { v->cur_speed < 5) {
return CMD_ERROR; return CMD_ERROR;
} }
@ -742,7 +743,7 @@ static void* EnumCheckRoadVehClose(Vehicle *v, void* data)
return return
rvf->veh != v && rvf->veh != v &&
v->type == VEH_Road && v->type == VEH_Road &&
v->u.road.state != 254 && !IsRoadVehInDepot(v) &&
myabs(v->z_pos - rvf->veh->z_pos) < 6 && myabs(v->z_pos - rvf->veh->z_pos) < 6 &&
v->direction == rvf->dir && v->direction == rvf->dir &&
(dist_x[v->direction] >= 0 || (x_diff > dist_x[v->direction] && x_diff <= 0)) && (dist_x[v->direction] >= 0 || (x_diff > dist_x[v->direction] && x_diff <= 0)) &&
@ -1226,7 +1227,7 @@ static void RoadVehController(Vehicle *v)
if (v->current_order.type == OT_LOADING) return; if (v->current_order.type == OT_LOADING) return;
if (v->u.road.state == 254) { if (IsRoadVehInDepot(v)) {
DiagDirection dir; DiagDirection dir;
const RoadDriveEntry* rdp; const RoadDriveEntry* rdp;
byte rd2; byte rd2;

View File

@ -4,6 +4,7 @@
#include "openttd.h" #include "openttd.h"
#include "debug.h" #include "debug.h"
#include "functions.h" #include "functions.h"
#include "roadveh.h"
#include "table/sprites.h" #include "table/sprites.h"
#include "table/strings.h" #include "table/strings.h"
#include "map.h" #include "map.h"
@ -554,7 +555,7 @@ static void DrawRoadDepotWindow(Window *w)
/* determine amount of items for scroller */ /* determine amount of items for scroller */
num = 0; num = 0;
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
if (v->type == VEH_Road && v->u.road.state == 254 && v->tile == tile) if (v->type == VEH_Road && IsRoadVehInDepot(v) && v->tile == tile)
num++; num++;
} }
SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap); SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap);
@ -571,7 +572,7 @@ static void DrawRoadDepotWindow(Window *w)
num = w->vscroll.pos * w->hscroll.cap; num = w->vscroll.pos * w->hscroll.cap;
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
if (v->type == VEH_Road && v->u.road.state == 254 && v->tile == tile && if (v->type == VEH_Road && IsRoadVehInDepot(v) && v->tile == tile &&
--num < 0 && num >= -w->vscroll.cap * w->hscroll.cap) { --num < 0 && num >= -w->vscroll.cap * w->hscroll.cap) {
DrawRoadVehImage(v, x+24, y, WP(w,traindepot_d).sel); DrawRoadVehImage(v, x+24, y, WP(w,traindepot_d).sel);
@ -608,7 +609,7 @@ static int GetVehicleFromRoadDepotWndPt(const Window *w, int x, int y, Vehicle *
tile = w->window_number; tile = w->window_number;
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
if (v->type == VEH_Road && v->u.road.state == 254 && v->tile == tile && if (v->type == VEH_Road && IsRoadVehInDepot(v) && v->tile == tile &&
--pos < 0) { --pos < 0) {
*veh = v; *veh = v;
if (xm >= 24) return 0; if (xm >= 24) return 0;
@ -917,7 +918,7 @@ static void PlayerRoadVehWndProc(Window *w, WindowEvent *e)
DrawVehicleProfitButton(v, x, y + 13); DrawVehicleProfitButton(v, x, y + 13);
SetDParam(0, v->unitnumber); SetDParam(0, v->unitnumber);
if (IsTileDepotType(v->tile, TRANSPORT_ROAD) && (v->vehstatus & VS_HIDDEN)) if (IsRoadVehInDepot(v))
str = STR_021F; str = STR_021F;
else else
str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2; str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;

View File

@ -3,6 +3,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "openttd.h" #include "openttd.h"
#include "road_map.h" #include "road_map.h"
#include "roadveh.h"
#include "spritecache.h" #include "spritecache.h"
#include "table/sprites.h" #include "table/sprites.h"
#include "table/strings.h" #include "table/strings.h"
@ -1996,7 +1997,7 @@ Trackdir GetVehicleTrackdir(const Vehicle* v)
return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.ship.state),v->direction); return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.ship.state),v->direction);
case VEH_Road: case VEH_Road:
if (v->u.road.state == 254) /* We'll assume the road vehicle is facing outwards */ if (IsRoadVehInDepot(v)) /* We'll assume the road vehicle is facing outwards */
return DiagdirToDiagTrackdir(GetRoadDepotDirection(v->tile)); return DiagdirToDiagTrackdir(GetRoadDepotDirection(v->tile));
if (IsRoadStopTile(v->tile)) /* We'll assume the road vehicle is facing outwards */ if (IsRoadStopTile(v->tile)) /* We'll assume the road vehicle is facing outwards */