# HG changeset patch # User maedhros # Date 1180696650 0 # Node ID b58be16fb2689ab3fc53f572bc11410caf6ae3b7 # Parent 408585d467f9b02bf336b76956e7c6cf1e585095 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them. diff -r 408585d467f9 -r b58be16fb268 src/train.h --- a/src/train.h Thu May 31 21:21:04 2007 +0000 +++ b/src/train.h Fri Jun 01 11:17:30 2007 +0000 @@ -31,6 +31,7 @@ */ static inline bool IsFrontEngine(const Vehicle *v) { + assert(v->type == VEH_TRAIN); return HASBIT(v->subtype, Train_Front); } @@ -39,6 +40,7 @@ */ static inline void SetFrontEngine(Vehicle *v) { + assert(v->type == VEH_TRAIN); SETBIT(v->subtype, Train_Front); } @@ -47,6 +49,7 @@ */ static inline void ClearFrontEngine(Vehicle *v) { + assert(v->type == VEH_TRAIN); CLRBIT(v->subtype, Train_Front); } @@ -56,6 +59,7 @@ */ static inline bool IsArticulatedPart(const Vehicle *v) { + assert(v->type == VEH_TRAIN); return HASBIT(v->subtype, Train_Articulated_Part); } @@ -64,6 +68,7 @@ */ static inline void SetArticulatedPart(Vehicle *v) { + assert(v->type == VEH_TRAIN); SETBIT(v->subtype, Train_Articulated_Part); } @@ -72,6 +77,7 @@ */ static inline void ClearArticulatedPart(Vehicle *v) { + assert(v->type == VEH_TRAIN); CLRBIT(v->subtype, Train_Articulated_Part); } @@ -81,6 +87,7 @@ */ static inline bool IsTrainWagon(const Vehicle *v) { + assert(v->type == VEH_TRAIN); return HASBIT(v->subtype, Train_Wagon); } @@ -89,6 +96,7 @@ */ static inline void SetTrainWagon(Vehicle *v) { + assert(v->type == VEH_TRAIN); SETBIT(v->subtype, Train_Wagon); } @@ -97,6 +105,7 @@ */ static inline void ClearTrainWagon(Vehicle *v) { + assert(v->type == VEH_TRAIN); CLRBIT(v->subtype, Train_Wagon); } @@ -106,6 +115,7 @@ */ static inline bool IsTrainEngine(const Vehicle *v) { + assert(v->type == VEH_TRAIN); return HASBIT(v->subtype, Train_Engine); } @@ -114,6 +124,7 @@ */ static inline void SetTrainEngine(Vehicle *v) { + assert(v->type == VEH_TRAIN); SETBIT(v->subtype, Train_Engine); } @@ -122,6 +133,7 @@ */ static inline void ClearTrainEngine(Vehicle *v) { + assert(v->type == VEH_TRAIN); CLRBIT(v->subtype, Train_Engine); } @@ -131,6 +143,7 @@ */ static inline bool IsFreeWagon(const Vehicle *v) { + assert(v->type == VEH_TRAIN); return HASBIT(v->subtype, Train_Free_Wagon); } @@ -139,6 +152,7 @@ */ static inline void SetFreeWagon(Vehicle *v) { + assert(v->type == VEH_TRAIN); SETBIT(v->subtype, Train_Free_Wagon); } @@ -147,6 +161,7 @@ */ static inline void ClearFreeWagon(Vehicle *v) { + assert(v->type == VEH_TRAIN); CLRBIT(v->subtype, Train_Free_Wagon); } @@ -156,6 +171,7 @@ */ static inline bool IsMultiheaded(const Vehicle *v) { + assert(v->type == VEH_TRAIN); return HASBIT(v->subtype, Train_Multiheaded); } @@ -164,6 +180,7 @@ */ static inline void SetMultiheaded(Vehicle *v) { + assert(v->type == VEH_TRAIN); SETBIT(v->subtype, Train_Multiheaded); } @@ -172,6 +189,7 @@ */ static inline void ClearMultiheaded(Vehicle *v) { + assert(v->type == VEH_TRAIN); CLRBIT(v->subtype, Train_Multiheaded); } @@ -181,6 +199,7 @@ */ static inline bool EngineHasArticPart(const Vehicle *v) { + assert(v->type == VEH_TRAIN); return (v->next != NULL && IsArticulatedPart(v->next)); } @@ -201,6 +220,7 @@ */ static inline Vehicle *GetLastEnginePart(Vehicle *v) { + assert(v->type == VEH_TRAIN); while (EngineHasArticPart(v)) v = GetNextArticPart(v); return v; } @@ -211,6 +231,7 @@ */ static inline Vehicle *GetNextVehicle(const Vehicle *v) { + assert(v->type == VEH_TRAIN); while (EngineHasArticPart(v)) v = GetNextArticPart(v); /* v now contains the last artic part in the engine */ diff -r 408585d467f9 -r b58be16fb268 src/train_cmd.cpp --- a/src/train_cmd.cpp Thu May 31 21:21:04 2007 +0000 +++ b/src/train_cmd.cpp Fri Jun 01 11:17:30 2007 +0000 @@ -619,8 +619,10 @@ v->u.rail.track = TRACK_BIT_DEPOT; v->vehstatus = VS_HIDDEN | VS_DEFPAL; + v = new (v) Train(); v->subtype = 0; SetTrainWagon(v); + if (u != NULL) { u->next = v; } else { @@ -637,7 +639,6 @@ v->u.rail.railtype = rvi->railtype; v->build_year = _cur_year; - v = new (v) Train(); v->cur_image = 0xAC2; v->random_bits = VehicleRandomBits();