src/group_cmd.cpp
branchnoai
changeset 9625 3301b1b3889c
parent 9624 b71483f2330f
child 9629 66dde6412125
equal deleted inserted replaced
9624:b71483f2330f 9625:3301b1b3889c
   209 		Group *g = GetGroup(new_g);
   209 		Group *g = GetGroup(new_g);
   210 		if (g->owner != _current_player) return CMD_ERROR;
   210 		if (g->owner != _current_player) return CMD_ERROR;
   211 	}
   211 	}
   212 
   212 
   213 	Vehicle *v = GetVehicle(p2);
   213 	Vehicle *v = GetVehicle(p2);
   214 	if (v->owner != _current_player || (v->type == VEH_TRAIN && !IsFrontEngine(v))) return CMD_ERROR;
   214 	if (v->owner != _current_player || !v->IsPrimaryVehicle()) return CMD_ERROR;
   215 
   215 
   216 	if (flags & DC_EXEC) {
   216 	if (flags & DC_EXEC) {
   217 		DecreaseGroupNumVehicle(v->group_id);
   217 		DecreaseGroupNumVehicle(v->group_id);
   218 		IncreaseGroupNumVehicle(new_g);
   218 		IncreaseGroupNumVehicle(new_g);
   219 
   219 
   252 
   252 
   253 	if (flags & DC_EXEC) {
   253 	if (flags & DC_EXEC) {
   254 		Vehicle *v;
   254 		Vehicle *v;
   255 		VehicleType type = (VehicleType)p2;
   255 		VehicleType type = (VehicleType)p2;
   256 		GroupID id_g = p1;
   256 		GroupID id_g = p1;
   257 		uint subtype = (type == VEH_AIRCRAFT) ? AIR_AIRCRAFT : 0;
       
   258 
   257 
   259 		/* Find the first front engine which belong to the group id_g
   258 		/* Find the first front engine which belong to the group id_g
   260 		 * then add all shared vehicles of this front engine to the group id_g */
   259 		 * then add all shared vehicles of this front engine to the group id_g */
   261 		FOR_ALL_VEHICLES(v) {
   260 		FOR_ALL_VEHICLES(v) {
   262 			if ((v->type == type) && (
   261 			if (v->type == type && v->IsPrimaryVehicle()) {
   263 					(type == VEH_TRAIN && IsFrontEngine(v)) ||
       
   264 					(type != VEH_TRAIN && v->subtype <= subtype))) {
       
   265 				if (v->group_id != id_g) continue;
   262 				if (v->group_id != id_g) continue;
   266 
   263 
   267 				/* For each shared vehicles add it to the group */
   264 				/* For each shared vehicles add it to the group */
   268 				for (Vehicle *v2 = GetFirstVehicleFromSharedList(v); v2 != NULL; v2 = v2->next_shared) {
   265 				for (Vehicle *v2 = GetFirstVehicleFromSharedList(v); v2 != NULL; v2 = v2->next_shared) {
   269 					if (v2->group_id != id_g) CmdAddVehicleGroup(tile, flags, id_g, v2->index);
   266 					if (v2->group_id != id_g) CmdAddVehicleGroup(tile, flags, id_g, v2->index);
   293 	Group *g = GetGroup(p1);
   290 	Group *g = GetGroup(p1);
   294 	if (g->owner != _current_player) return CMD_ERROR;
   291 	if (g->owner != _current_player) return CMD_ERROR;
   295 
   292 
   296 	if (flags & DC_EXEC) {
   293 	if (flags & DC_EXEC) {
   297 		GroupID old_g = p1;
   294 		GroupID old_g = p1;
   298 		uint subtype = (type == VEH_AIRCRAFT) ? AIR_AIRCRAFT : 0;
       
   299 		Vehicle *v;
   295 		Vehicle *v;
   300 
   296 
   301 		/* Find each Vehicle that belongs to the group old_g and add it to the default group */
   297 		/* Find each Vehicle that belongs to the group old_g and add it to the default group */
   302 		FOR_ALL_VEHICLES(v) {
   298 		FOR_ALL_VEHICLES(v) {
   303 			if ((v->type == type) && (
   299 			if (v->type == type && v->IsPrimaryVehicle()) {
   304 					(type == VEH_TRAIN && IsFrontEngine(v)) ||
       
   305 					(type != VEH_TRAIN && v->subtype <= subtype))) {
       
   306 				if (v->group_id != old_g) continue;
   300 				if (v->group_id != old_g) continue;
   307 
   301 
   308 				/* Add The Vehicle to the default group */
   302 				/* Add The Vehicle to the default group */
   309 				CmdAddVehicleGroup(tile, flags, DEFAULT_GROUP, v->index);
   303 				CmdAddVehicleGroup(tile, flags, DEFAULT_GROUP, v->index);
   310 			}
   304 			}
   346  * @note Called in CmdSellRailWagon and DeleteLasWagon,
   340  * @note Called in CmdSellRailWagon and DeleteLasWagon,
   347  * @param v     FrontEngine of the train we want to remove.
   341  * @param v     FrontEngine of the train we want to remove.
   348  */
   342  */
   349 void RemoveVehicleFromGroup(const Vehicle *v)
   343 void RemoveVehicleFromGroup(const Vehicle *v)
   350 {
   344 {
   351 	if (!IsValidVehicle(v) || v->type != VEH_TRAIN || !IsFrontEngine(v)) return;
   345 	if (!IsValidVehicle(v) || !(v->HasFront() && v->IsPrimaryVehicle())) return;
   352 
   346 
   353 	if (!IsDefaultGroupID(v->group_id)) DecreaseGroupNumVehicle(v->group_id);
   347 	if (!IsDefaultGroupID(v->group_id)) DecreaseGroupNumVehicle(v->group_id);
   354 }
   348 }
   355 
   349 
   356 
   350