1
0
Fork 0

(svn r16720) -Codechange: make Set/ClearFrontEngine(), Set/ClearArticulatedPart(), Set/ClearWagon(), Set/ClearEngine(), Set/ClearFreeWagon() and Set/ClearMultiheaded() members of Train

release/1.0
smatz 2009-07-02 00:17:27 +00:00
parent d86e17d65a
commit 77eaefb61c
4 changed files with 92 additions and 137 deletions

View File

@ -322,7 +322,7 @@ void AddArticulatedParts(Vehicle *first, VehicleType type)
t->cargo_cap = 0; t->cargo_cap = 0;
} }
SetArticulatedPart(t); t->SetArticulatedPart();
} break; } break;
case VEH_ROAD: { case VEH_ROAD: {

View File

@ -50,7 +50,7 @@ void ConnectMultiheadedTrains()
if (u->IsMultiheaded()) { if (u->IsMultiheaded()) {
if (!u->IsEngine()) { if (!u->IsEngine()) {
/* we got a rear car without a front car. We will convert it to a front one */ /* we got a rear car without a front car. We will convert it to a front one */
SetTrainEngine(u); u->SetEngine();
u->spritenum--; u->spritenum--;
} }
@ -63,7 +63,7 @@ void ConnectMultiheadedTrains()
/* we found a car to partner with this engine. Now we will make sure it face the right way */ /* we found a car to partner with this engine. Now we will make sure it face the right way */
if (w->IsEngine()) { if (w->IsEngine()) {
ClearTrainEngine(w); w->ClearEngine();
w->spritenum++; w->spritenum++;
} }
break; break;
@ -87,7 +87,7 @@ void ConnectMultiheadedTrains()
u->other_multiheaded_part = w; u->other_multiheaded_part = w;
} else { } else {
/* we got a front car and no rear cars. We will fake this one for forget that it should have been multiheaded */ /* we got a front car and no rear cars. We will fake this one for forget that it should have been multiheaded */
ClearMultiheaded(u); u->ClearMultiheaded();
} }
} }
} }
@ -106,42 +106,42 @@ void ConvertOldMultiheadToNew()
FOR_ALL_TRAINS(t) { FOR_ALL_TRAINS(t) {
if (HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) { if (HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) {
for (Vehicle *u = t; u != NULL; u = u->Next()) { for (Train *u = t; u != NULL; u = u->Next()) {
const RailVehicleInfo *rvi = RailVehInfo(u->engine_type); const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
ClrBit(u->subtype, 7); ClrBit(u->subtype, 7);
switch (u->subtype) { switch (u->subtype) {
case 0: // TS_Front_Engine case 0: // TS_Front_Engine
if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u); if (rvi->railveh_type == RAILVEH_MULTIHEAD) u->SetMultiheaded();
SetFrontEngine(u); u->SetFrontEngine();
SetTrainEngine(u); u->SetEngine();
break; break;
case 1: // TS_Artic_Part case 1: // TS_Artic_Part
u->subtype = 0; u->subtype = 0;
SetArticulatedPart(u); u->SetArticulatedPart();
break; break;
case 2: // TS_Not_First case 2: // TS_Not_First
u->subtype = 0; u->subtype = 0;
if (rvi->railveh_type == RAILVEH_WAGON) { if (rvi->railveh_type == RAILVEH_WAGON) {
/* normal wagon */ /* normal wagon */
SetTrainWagon(u); u->SetWagon();
break; break;
} }
if (rvi->railveh_type == RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) { if (rvi->railveh_type == RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) {
/* rear end of a multiheaded engine */ /* rear end of a multiheaded engine */
SetMultiheaded(u); u->SetMultiheaded();
break; break;
} }
if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u); if (rvi->railveh_type == RAILVEH_MULTIHEAD) u->SetMultiheaded();
SetTrainEngine(u); u->SetEngine();
break; break;
case 4: // TS_Free_Car case 4: // TS_Free_Car
u->subtype = 0; u->subtype = 0;
SetTrainWagon(u); u->SetWagon();
SetFreeWagon(u); u->SetFreeWagon();
break; break;
default: NOT_REACHED(); default: NOT_REACHED();
} }

View File

@ -51,114 +51,6 @@ enum TrainSubtype {
TS_MULTIHEADED = 5, ///< Engine is a multiheaded TS_MULTIHEADED = 5, ///< Engine is a multiheaded
}; };
/** Set front engine state
* @param v vehicle to change
*/
static inline void SetFrontEngine(Vehicle *v)
{
assert(v->type == VEH_TRAIN);
SetBit(v->subtype, TS_FRONT);
}
/** Remove the front engine state
* @param v vehicle to change
*/
static inline void ClearFrontEngine(Vehicle *v)
{
assert(v->type == VEH_TRAIN);
ClrBit(v->subtype, TS_FRONT);
}
/** Set a vehicle to be an articulated part
* @param v vehicle to change
*/
static inline void SetArticulatedPart(Vehicle *v)
{
assert(v->type == VEH_TRAIN);
SetBit(v->subtype, TS_ARTICULATED_PART);
}
/** Clear a vehicle from being an articulated part
* @param v vehicle to change
*/
static inline void ClearArticulatedPart(Vehicle *v)
{
assert(v->type == VEH_TRAIN);
ClrBit(v->subtype, TS_ARTICULATED_PART);
}
/** Set a vehicle to be a wagon
* @param v vehicle to change
*/
static inline void SetTrainWagon(Vehicle *v)
{
assert(v->type == VEH_TRAIN);
SetBit(v->subtype, TS_WAGON);
}
/** Clear wagon property
* @param v vehicle to change
*/
static inline void ClearTrainWagon(Vehicle *v)
{
assert(v->type == VEH_TRAIN);
ClrBit(v->subtype, TS_WAGON);
}
/** Set engine status
* @param v vehicle to change
*/
static inline void SetTrainEngine(Vehicle *v)
{
assert(v->type == VEH_TRAIN);
SetBit(v->subtype, TS_ENGINE);
}
/** Clear engine status
* @param v vehicle to change
*/
static inline void ClearTrainEngine(Vehicle *v)
{
assert(v->type == VEH_TRAIN);
ClrBit(v->subtype, TS_ENGINE);
}
/** Set if a vehicle is a free wagon
* @param v vehicle to change
*/
static inline void SetFreeWagon(Vehicle *v)
{
assert(v->type == VEH_TRAIN);
SetBit(v->subtype, TS_FREE_WAGON);
}
/** Clear a vehicle from being a free wagon
* @param v vehicle to change
*/
static inline void ClearFreeWagon(Vehicle *v)
{
assert(v->type == VEH_TRAIN);
ClrBit(v->subtype, TS_FREE_WAGON);
}
/** Set if a vehicle is a multiheaded engine
* @param v vehicle to change
*/
static inline void SetMultiheaded(Vehicle *v)
{
assert(v->type == VEH_TRAIN);
SetBit(v->subtype, TS_MULTIHEADED);
}
/** Clear multiheaded engine property
* @param v vehicle to change
*/
static inline void ClearMultiheaded(Vehicle *v)
{
assert(v->type == VEH_TRAIN);
ClrBit(v->subtype, TS_MULTIHEADED);
}
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2); void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2);
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2); void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2);
@ -257,6 +149,69 @@ struct Train : public SpecializedVehicle<Train, VEH_TRAIN> {
TileIndex GetOrderStationLocation(StationID station); TileIndex GetOrderStationLocation(StationID station);
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse); bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
/**
* Set front engine state
*/
FORCEINLINE void SetFrontEngine() { SetBit(this->subtype, TS_FRONT); }
/**
* Remove the front engine state
*/
FORCEINLINE void ClearFrontEngine() { ClrBit(this->subtype, TS_FRONT); }
/**
* Set a vehicle to be an articulated part
*/
FORCEINLINE void SetArticulatedPart() { SetBit(this->subtype, TS_ARTICULATED_PART); }
/**
* Clear a vehicle from being an articulated part
*/
FORCEINLINE void ClearArticulatedPart() { ClrBit(this->subtype, TS_ARTICULATED_PART); }
/**
* Set a vehicle to be a wagon
*/
FORCEINLINE void SetWagon() { SetBit(this->subtype, TS_WAGON); }
/**
* Clear wagon property
*/
FORCEINLINE void ClearWagon() { ClrBit(this->subtype, TS_WAGON); }
/**
* Set engine status
* @param v vehicle to change
*/
FORCEINLINE void SetEngine() { SetBit(this->subtype, TS_ENGINE); }
/**
* Clear engine status
*/
FORCEINLINE void ClearEngine() { ClrBit(this->subtype, TS_ENGINE); }
/**
* Set if a vehicle is a free wagon
*/
FORCEINLINE void SetFreeWagon() { SetBit(this->subtype, TS_FREE_WAGON); }
/**
* Clear a vehicle from being a free wagon
* @param v vehicle to change
*/
FORCEINLINE void ClearFreeWagon() { ClrBit(this->subtype, TS_FREE_WAGON); }
/**
* Set if a vehicle is a multiheaded engine
*/
FORCEINLINE void SetMultiheaded() { SetBit(this->subtype, TS_MULTIHEADED); }
/**
* Clear multiheaded engine property
*/
FORCEINLINE void ClearMultiheaded() { ClrBit(this->subtype, TS_MULTIHEADED); }
/** /**
* Check if train is a front engine * Check if train is a front engine
* @return Returns true if train is a front engine * @return Returns true if train is a front engine

View File

@ -704,12 +704,12 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, DoCommandF
v->vehstatus = VS_HIDDEN | VS_DEFPAL; v->vehstatus = VS_HIDDEN | VS_DEFPAL;
// v->subtype = 0; // v->subtype = 0;
SetTrainWagon(v); v->SetWagon();
if (u != NULL) { if (u != NULL) {
u->SetNext(v); u->SetNext(v);
} else { } else {
SetFreeWagon(v); v->SetFreeWagon();
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
} }
@ -784,8 +784,8 @@ static void AddRearEngineToMultiheadedTrain(Train *v)
u->build_year = v->build_year; u->build_year = v->build_year;
u->cur_image = SPR_IMG_QUERY; u->cur_image = SPR_IMG_QUERY;
u->random_bits = VehicleRandomBits(); u->random_bits = VehicleRandomBits();
SetMultiheaded(v); v->SetMultiheaded();
SetMultiheaded(u); u->SetMultiheaded();
v->SetNext(u); v->SetNext(u);
VehicleMove(u, false); VehicleMove(u, false);
@ -886,8 +886,8 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
v->group_id = DEFAULT_GROUP; v->group_id = DEFAULT_GROUP;
// v->subtype = 0; // v->subtype = 0;
SetFrontEngine(v); v->SetFrontEngine();
SetTrainEngine(v); v->SetEngine();
VehicleMove(v, false); VehicleMove(v, false);
@ -971,7 +971,7 @@ static Train *UnlinkWagon(Train *v, Train *first)
v = GetNextVehicle(v); v = GetNextVehicle(v);
if (v == NULL) return NULL; if (v == NULL) return NULL;
if (v->IsWagon()) SetFreeWagon(v); if (v->IsWagon()) v->SetFreeWagon();
/* First can be an articulated engine, meaning GetNextVehicle() isn't /* First can be an articulated engine, meaning GetNextVehicle() isn't
* v->Next(). Thus set the next vehicle of the last articulated part * v->Next(). Thus set the next vehicle of the last articulated part
@ -1020,8 +1020,8 @@ static void AddWagonToConsist(Train *v, Train *dest)
v->SetNext(NULL); v->SetNext(NULL);
dest->SetNext(v); dest->SetNext(v);
v->SetNext(next); v->SetNext(next);
ClearFreeWagon(v); v->ClearFreeWagon();
ClearFrontEngine(v); v->ClearFrontEngine();
} }
/* /*
@ -1302,7 +1302,7 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (src->IsEngine()) { if (src->IsEngine()) {
if (!src->IsFrontEngine()) { if (!src->IsFrontEngine()) {
/* setting the type to 0 also involves setting up the orders field. */ /* setting the type to 0 also involves setting up the orders field. */
SetFrontEngine(src); src->SetFrontEngine();
assert(src->orders.list == NULL); assert(src->orders.list == NULL);
/* Decrease the engines number of the src engine_type */ /* Decrease the engines number of the src engine_type */
@ -1314,7 +1314,7 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
src->group_id = DEFAULT_GROUP; src->group_id = DEFAULT_GROUP;
} }
} else { } else {
SetFreeWagon(src); src->SetFreeWagon();
} }
dst_head = src; dst_head = src;
} else { } else {
@ -1331,8 +1331,8 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (src->IsFrontEngine() || src->IsFreeWagon()) { if (src->IsFrontEngine() || src->IsFreeWagon()) {
InvalidateWindowData(WC_VEHICLE_DEPOT, src->tile); InvalidateWindowData(WC_VEHICLE_DEPOT, src->tile);
ClearFrontEngine(src); src->ClearFrontEngine();
ClearFreeWagon(src); src->ClearFreeWagon();
src->unitnumber = 0; // doesn't occupy a unitnumber anymore. src->unitnumber = 0; // doesn't occupy a unitnumber anymore.
} }
@ -1504,7 +1504,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* 4 If the second wagon was an engine, update it to front_engine /* 4 If the second wagon was an engine, update it to front_engine
* which UnlinkWagon() has changed to TS_Free_Car */ * which UnlinkWagon() has changed to TS_Free_Car */
if (switch_engine) SetFrontEngine(first); if (switch_engine) first->SetFrontEngine();
/* 5. If the train still exists, update its acceleration, window, etc. */ /* 5. If the train still exists, update its acceleration, window, etc. */
if (first != NULL) { if (first != NULL) {