changeset 6771:8c1fa460e018 draft

(svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
author maedhros <maedhros@openttd.org>
date Fri, 01 Jun 2007 11:17:30 +0000
parents 93b0e6996fcc
children 5d92b1c91256
files src/train.h src/train_cmd.cpp
diffstat 2 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/train.h
+++ b/src/train.h
@@ -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 */
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -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();