src/group_cmd.cpp
branchgamebalance
changeset 9912 1ac8aac92385
parent 9911 0b8b245a2391
child 9913 e79cd19772dd
--- a/src/group_cmd.cpp	Wed Jun 13 11:45:14 2007 +0000
+++ b/src/group_cmd.cpp	Wed Jun 13 12:05:56 2007 +0000
@@ -205,11 +205,13 @@
 
 	if (!IsValidVehicleID(p2) || (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
 
-	Group *g = GetGroup(new_g);
-	if (g->owner != _current_player) return CMD_ERROR;
+	if (IsValidGroupID(new_g)) {
+		Group *g = GetGroup(new_g);
+		if (g->owner != _current_player) return CMD_ERROR;
+	}
 
 	Vehicle *v = GetVehicle(p2);
-	if (v->owner != _current_player || (v->type == VEH_TRAIN && !IsFrontEngine(v))) return CMD_ERROR;
+	if (v->owner != _current_player || !v->IsPrimaryVehicle()) return CMD_ERROR;
 
 	if (flags & DC_EXEC) {
 		DecreaseGroupNumVehicle(v->group_id);
@@ -252,14 +254,11 @@
 		Vehicle *v;
 		VehicleType type = (VehicleType)p2;
 		GroupID id_g = p1;
-		uint subtype = (type == VEH_AIRCRAFT) ? AIR_AIRCRAFT : 0;
 
 		/* Find the first front engine which belong to the group id_g
 		 * then add all shared vehicles of this front engine to the group id_g */
 		FOR_ALL_VEHICLES(v) {
-			if ((v->type == type) && (
-					(type == VEH_TRAIN && IsFrontEngine(v)) ||
-					(type != VEH_TRAIN && v->subtype <= subtype))) {
+			if (v->type == type && v->IsPrimaryVehicle()) {
 				if (v->group_id != id_g) continue;
 
 				/* For each shared vehicles add it to the group */
@@ -293,14 +292,11 @@
 
 	if (flags & DC_EXEC) {
 		GroupID old_g = p1;
-		uint subtype = (type == VEH_AIRCRAFT) ? AIR_AIRCRAFT : 0;
 		Vehicle *v;
 
 		/* Find each Vehicle that belongs to the group old_g and add it to the default group */
 		FOR_ALL_VEHICLES(v) {
-			if ((v->type == type) && (
-					(type == VEH_TRAIN && IsFrontEngine(v)) ||
-					(type != VEH_TRAIN && v->subtype <= subtype))) {
+			if (v->type == type && v->IsPrimaryVehicle()) {
 				if (v->group_id != old_g) continue;
 
 				/* Add The Vehicle to the default group */
@@ -346,7 +342,7 @@
  */
 void RemoveVehicleFromGroup(const Vehicle *v)
 {
-	if (!IsValidVehicle(v) || v->type != VEH_TRAIN || !IsFrontEngine(v)) return;
+	if (!IsValidVehicle(v) || !(v->HasFront() && v->IsPrimaryVehicle())) return;
 
 	if (!IsDefaultGroupID(v->group_id)) DecreaseGroupNumVehicle(v->group_id);
 }