mirror of https://github.com/OpenTTD/OpenTTD
(svn r12605) -Cleanup: variable scope and coding style in train*
parent
f46ae97d8e
commit
ac389e16d2
|
@ -10,12 +10,10 @@
|
|||
#include "vehicle_base.h"
|
||||
|
||||
|
||||
/*
|
||||
* enum to handle train subtypes
|
||||
/** enum to handle train subtypes
|
||||
* Do not access it directly unless you have to. Use the access functions below
|
||||
* This is an enum to tell what bit to access as it is a bitmask
|
||||
*/
|
||||
|
||||
enum TrainSubtype {
|
||||
TS_FRONT = 0, ///< Leading engine of a train
|
||||
TS_ARTICULATED_PART = 1, ///< Articulated part of an engine
|
||||
|
|
|
@ -182,7 +182,7 @@ static void TrainCargoChanged(Vehicle* v)
|
|||
*/
|
||||
void TrainConsistChanged(Vehicle *v)
|
||||
{
|
||||
uint16 max_speed = 0xFFFF;
|
||||
uint16 max_speed = UINT16_MAX;
|
||||
|
||||
assert(v->type == VEH_TRAIN);
|
||||
assert(IsFrontEngine(v) || IsFreeWagon(v));
|
||||
|
@ -305,7 +305,7 @@ enum AccelType {
|
|||
/** new acceleration*/
|
||||
static int GetTrainAcceleration(Vehicle *v, bool mode)
|
||||
{
|
||||
static const int absolute_max_speed = 2000;
|
||||
static const int absolute_max_speed = UINT16_MAX;
|
||||
int max_speed = absolute_max_speed;
|
||||
int speed = v->cur_speed * 10 / 16; // km-ish/h -> mp/h
|
||||
int curvecount[2] = {0, 0};
|
||||
|
@ -571,7 +571,7 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 fla
|
|||
v->u.rail.track = TRACK_BIT_DEPOT;
|
||||
v->vehstatus = VS_HIDDEN | VS_DEFPAL;
|
||||
|
||||
v->subtype = 0;
|
||||
// v->subtype = 0;
|
||||
SetTrainWagon(v);
|
||||
|
||||
if (u != NULL) {
|
||||
|
@ -582,7 +582,7 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 fla
|
|||
}
|
||||
|
||||
v->cargo_type = rvi->cargo_type;
|
||||
v->cargo_subtype = 0;
|
||||
// v->cargo_subtype = 0;
|
||||
v->cargo_cap = rvi->capacity;
|
||||
v->value = value.GetCost();
|
||||
// v->day_counter = 0;
|
||||
|
@ -646,7 +646,7 @@ static void AddRearEngineToMultiheadedTrain(Vehicle* v, Vehicle* u, bool buildin
|
|||
u->z_pos = v->z_pos;
|
||||
u->u.rail.track = TRACK_BIT_DEPOT;
|
||||
u->vehstatus = v->vehstatus & ~VS_STOPPED;
|
||||
u->subtype = 0;
|
||||
// u->subtype = 0;
|
||||
SetMultiheaded(u);
|
||||
u->spritenum = v->spritenum + 1;
|
||||
u->cargo_type = v->cargo_type;
|
||||
|
@ -701,8 +701,9 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||
Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1));
|
||||
memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
|
||||
|
||||
if (!Vehicle::AllocateList(vl, num_vehicles))
|
||||
if (!Vehicle::AllocateList(vl, num_vehicles)) {
|
||||
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
|
||||
}
|
||||
|
||||
Vehicle *v = vl[0];
|
||||
|
||||
|
@ -723,17 +724,17 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||
v->x_pos = x;
|
||||
v->y_pos = y;
|
||||
v->z_pos = GetSlopeZ(x, y);
|
||||
v->running_ticks = 0;
|
||||
// v->running_ticks = 0;
|
||||
v->u.rail.track = TRACK_BIT_DEPOT;
|
||||
v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
|
||||
v->spritenum = rvi->image_index;
|
||||
v->cargo_type = rvi->cargo_type;
|
||||
v->cargo_subtype = 0;
|
||||
// v->cargo_subtype = 0;
|
||||
v->cargo_cap = rvi->capacity;
|
||||
v->max_speed = rvi->max_speed;
|
||||
v->value = value.GetCost();
|
||||
v->last_station_visited = INVALID_STATION;
|
||||
v->dest_tile = 0;
|
||||
// v->dest_tile = 0;
|
||||
|
||||
v->engine_type = p1;
|
||||
|
||||
|
@ -752,12 +753,12 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||
v->cur_image = 0xAC2;
|
||||
v->random_bits = VehicleRandomBits();
|
||||
|
||||
v->vehicle_flags = 0;
|
||||
// v->vehicle_flags = 0;
|
||||
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
|
||||
v->group_id = DEFAULT_GROUP;
|
||||
|
||||
v->subtype = 0;
|
||||
// v->subtype = 0;
|
||||
SetFrontEngine(v);
|
||||
SetTrainEngine(v);
|
||||
|
||||
|
@ -786,8 +787,9 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
|
||||
RebuildVehicleLists();
|
||||
InvalidateWindow(WC_COMPANY, v->owner);
|
||||
if (IsLocalPlayer())
|
||||
if (IsLocalPlayer()) {
|
||||
InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window
|
||||
}
|
||||
|
||||
GetPlayer(_current_player)->num_engines[p1]++;
|
||||
}
|
||||
|
@ -1170,12 +1172,12 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||
assert(src->orders == NULL);
|
||||
src->num_orders = 0;
|
||||
|
||||
// Decrease the engines number of the src engine_type
|
||||
/* Decrease the engines number of the src engine_type */
|
||||
if (!IsDefaultGroupID(src->group_id) && IsValidGroupID(src->group_id)) {
|
||||
GetGroup(src->group_id)->num_engines[src->engine_type]--;
|
||||
}
|
||||
|
||||
// If we move an engine to a new line affect it to the DEFAULT_GROUP
|
||||
/* If we move an engine to a new line affect it to the DEFAULT_GROUP */
|
||||
src->group_id = DEFAULT_GROUP;
|
||||
}
|
||||
} else {
|
||||
|
@ -1425,10 +1427,10 @@ CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
* Totally braindead cause building a new engine adds all loco-less
|
||||
* engines to its train anyways */
|
||||
if (p2 == 2 && HasBit(ori_subtype, TS_FRONT)) {
|
||||
Vehicle *tmp;
|
||||
for (v = first; v != NULL; v = tmp) {
|
||||
tmp = GetNextVehicle(v);
|
||||
for (v = first; v != NULL;) {
|
||||
Vehicle *tmp = GetNextVehicle(v);
|
||||
DoCommand(v->tile, v->index | INVALID_VEHICLE << 16, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
|
||||
v = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1437,8 +1439,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
/* Start deleting every vehicle after the selected one
|
||||
* If we encounter a matching rear-engine to a front-engine
|
||||
* earlier in the chain (before deletion), leave it alone */
|
||||
Vehicle *tmp;
|
||||
for (; v != NULL; v = tmp) {
|
||||
for (Vehicle *tmp; v != NULL; v = tmp) {
|
||||
tmp = GetNextVehicle(v);
|
||||
|
||||
if (IsMultiheaded(v)) {
|
||||
|
@ -1526,10 +1527,11 @@ static inline void SetLastSpeed(Vehicle* v, int spd)
|
|||
int old = v->u.rail.last_speed;
|
||||
if (spd != old) {
|
||||
v->u.rail.last_speed = spd;
|
||||
if (_patches.vehicle_speed || (old == 0) != (spd == 0))
|
||||
if (_patches.vehicle_speed || (old == 0) != (spd == 0)) {
|
||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SwapTrainFlags(byte *swap_flag1, byte *swap_flag2)
|
||||
{
|
||||
|
@ -1793,8 +1795,7 @@ static void ReverseTrainDirection(Vehicle *v)
|
|||
TileIndex crossing = TrainApproachingCrossingTile(v);
|
||||
|
||||
/* count number of vehicles */
|
||||
int r = 0; ///< number of vehicles - 1
|
||||
for (const Vehicle *u = v; (u = u->Next()) != NULL;) { r++; }
|
||||
int r = CountVehiclesInChain(v) - 1; // number of vehicles - 1
|
||||
|
||||
AdvanceWagonsBeforeSwap(v);
|
||||
|
||||
|
@ -1843,7 +1844,7 @@ CommandCost CmdReverseTrainDirection(TileIndex tile, uint32 flags, uint32 p1, ui
|
|||
|
||||
if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
|
||||
|
||||
if (p2) {
|
||||
if (p2 != 0) {
|
||||
/* turn a single unit around */
|
||||
|
||||
if (IsMultiheaded(v) || HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) {
|
||||
|
@ -2048,7 +2049,7 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v, int max_distance)
|
|||
} break;
|
||||
|
||||
case VPF_NPF: { /* NPF */
|
||||
Vehicle* last = GetLastVehicleInChain(v);
|
||||
const Vehicle *last = GetLastVehicleInChain(v);
|
||||
Trackdir trackdir = GetVehicleTrackdir(v);
|
||||
Trackdir trackdir_rev = ReverseTrackdir(GetVehicleTrackdir(last));
|
||||
|
||||
|
@ -2168,8 +2169,9 @@ static void HandleLocomotiveSmokeCloud(const Vehicle* v)
|
|||
{
|
||||
bool sound = false;
|
||||
|
||||
if (v->vehstatus & VS_TRAIN_SLOWING || v->load_unload_time_rem != 0 || v->cur_speed < 2)
|
||||
if (v->vehstatus & VS_TRAIN_SLOWING || v->load_unload_time_rem != 0 || v->cur_speed < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Vehicle *u = v;
|
||||
|
||||
|
@ -2231,6 +2233,9 @@ static void HandleLocomotiveSmokeCloud(const Vehicle* v)
|
|||
sound = true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while ((v = v->Next()) != NULL);
|
||||
|
||||
|
@ -2301,10 +2306,10 @@ static bool CheckTrainStayInDepot(Vehicle *v)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* Check for station tiles */
|
||||
/** Check for station tiles */
|
||||
struct TrainTrackFollowerData {
|
||||
TileIndex dest_coords;
|
||||
StationID station_index; // station index we're heading for
|
||||
StationID station_index; ///< station index we're heading for
|
||||
uint best_bird_dist;
|
||||
uint best_track_dist;
|
||||
TrackdirByte best_track;
|
||||
|
@ -2489,8 +2494,9 @@ static bool CheckReverseTrain(Vehicle *v)
|
|||
{
|
||||
if (_opt.diff.line_reverse_mode != 0 ||
|
||||
v->u.rail.track == TRACK_BIT_DEPOT || v->u.rail.track == TRACK_BIT_WORMHOLE ||
|
||||
!(v->direction & 1))
|
||||
!(v->direction & 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TrainTrackFollowerData fd;
|
||||
FillWithStationData(&fd, v);
|
||||
|
@ -2500,9 +2506,9 @@ static bool CheckReverseTrain(Vehicle *v)
|
|||
assert(v->u.rail.track);
|
||||
|
||||
switch (_patches.pathfinder_for_trains) {
|
||||
case VPF_YAPF: { /* YAPF */
|
||||
case VPF_YAPF: /* YAPF */
|
||||
reverse_best = YapfCheckReverseTrain(v);
|
||||
} break;
|
||||
break;
|
||||
|
||||
case VPF_NPF: { /* NPF */
|
||||
NPFFindStationOrTileData fstd;
|
||||
|
@ -2829,8 +2835,8 @@ static uint CountPassengersInTrain(const Vehicle* v)
|
|||
}
|
||||
|
||||
struct TrainCollideChecker {
|
||||
Vehicle *v;
|
||||
uint num;
|
||||
Vehicle *v; ///< vehicle we are testing for collision
|
||||
uint num; ///< number of dead if train collided
|
||||
};
|
||||
|
||||
static void *FindTrainCollideEnum(Vehicle *v, void *data)
|
||||
|
@ -3192,8 +3198,8 @@ static void ChangeTrainDirRandomly(Vehicle *v)
|
|||
v->UpdateDeltaXY(v->direction);
|
||||
v->cur_image = v->GetImage(v->direction);
|
||||
/* Refrain from updating the z position of the vehicle when on
|
||||
a bridge, because AfterSetTrainPos will put the vehicle under
|
||||
the bridge in that case */
|
||||
* a bridge, because AfterSetTrainPos will put the vehicle under
|
||||
* the bridge in that case */
|
||||
if (v->u.rail.track != TRACK_BIT_WORMHOLE) AfterSetTrainPos(v, false);
|
||||
}
|
||||
} while ((v = v->Next()) != NULL);
|
||||
|
@ -3533,10 +3539,10 @@ void Train::Tick()
|
|||
}
|
||||
}
|
||||
|
||||
#define MAX_ACCEPTABLE_DEPOT_DIST 16
|
||||
|
||||
static void CheckIfTrainNeedsService(Vehicle *v)
|
||||
{
|
||||
static const uint MAX_ACCEPTABLE_DEPOT_DIST = 16;
|
||||
|
||||
if (_patches.servint_trains == 0 || !VehicleNeedsService(v)) return;
|
||||
if (v->IsInDepot()) {
|
||||
VehicleServiceInDepot(v);
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
|
||||
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
||||
{
|
||||
Vehicle *v, *found;
|
||||
|
||||
if (!success) return;
|
||||
|
||||
/* find a locomotive in the depot. */
|
||||
found = NULL;
|
||||
Vehicle *found = NULL;
|
||||
Vehicle *v;
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
if (v->type == VEH_TRAIN && IsFrontEngine(v) &&
|
||||
v->tile == tile &&
|
||||
|
@ -50,11 +49,9 @@ void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
|||
|
||||
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
||||
{
|
||||
const Vehicle *v;
|
||||
|
||||
if (!success) return;
|
||||
|
||||
v = GetVehicle(_new_vehicle_id);
|
||||
const Vehicle *v = GetVehicle(_new_vehicle_id);
|
||||
if (tile == _backup_orders_tile) {
|
||||
_backup_orders_tile = 0;
|
||||
RestoreVehicleOrders(v);
|
||||
|
@ -197,8 +194,6 @@ void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vs
|
|||
for (;;) {
|
||||
if (--vscroll_pos < 0 && vscroll_pos >= -vscroll_cap) {
|
||||
int dx = 0;
|
||||
int px;
|
||||
int py;
|
||||
|
||||
u = v;
|
||||
do {
|
||||
|
@ -208,8 +203,8 @@ void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vs
|
|||
u = u->Next();
|
||||
} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);
|
||||
|
||||
px = x + WagonLengthToPixels(dx) + 2;
|
||||
py = y + 2;
|
||||
int px = x + WagonLengthToPixels(dx) + 2;
|
||||
int py = y + 2;
|
||||
switch (det_tab) {
|
||||
default: NOT_REACHED();
|
||||
case 0: TrainDetailsCargoTab( v, px, py); break;
|
||||
|
|
Loading…
Reference in New Issue