src/group_cmd.cpp
branchgamebalance
changeset 9912 1ac8aac92385
parent 9911 0b8b245a2391
child 9913 e79cd19772dd
equal deleted inserted replaced
9911:0b8b245a2391 9912:1ac8aac92385
   203 {
   203 {
   204 	GroupID new_g = p1;
   204 	GroupID new_g = p1;
   205 
   205 
   206 	if (!IsValidVehicleID(p2) || (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
   206 	if (!IsValidVehicleID(p2) || (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
   207 
   207 
   208 	Group *g = GetGroup(new_g);
   208 	if (IsValidGroupID(new_g)) {
   209 	if (g->owner != _current_player) return CMD_ERROR;
   209 		Group *g = GetGroup(new_g);
       
   210 		if (g->owner != _current_player) return CMD_ERROR;
       
   211 	}
   210 
   212 
   211 	Vehicle *v = GetVehicle(p2);
   213 	Vehicle *v = GetVehicle(p2);
   212 	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;
   213 
   215 
   214 	if (flags & DC_EXEC) {
   216 	if (flags & DC_EXEC) {
   215 		DecreaseGroupNumVehicle(v->group_id);
   217 		DecreaseGroupNumVehicle(v->group_id);
   216 		IncreaseGroupNumVehicle(new_g);
   218 		IncreaseGroupNumVehicle(new_g);
   217 
   219 
   250 
   252 
   251 	if (flags & DC_EXEC) {
   253 	if (flags & DC_EXEC) {
   252 		Vehicle *v;
   254 		Vehicle *v;
   253 		VehicleType type = (VehicleType)p2;
   255 		VehicleType type = (VehicleType)p2;
   254 		GroupID id_g = p1;
   256 		GroupID id_g = p1;
   255 		uint subtype = (type == VEH_AIRCRAFT) ? AIR_AIRCRAFT : 0;
       
   256 
   257 
   257 		/* 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
   258 		 * 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 */
   259 		FOR_ALL_VEHICLES(v) {
   260 		FOR_ALL_VEHICLES(v) {
   260 			if ((v->type == type) && (
   261 			if (v->type == type && v->IsPrimaryVehicle()) {
   261 					(type == VEH_TRAIN && IsFrontEngine(v)) ||
       
   262 					(type != VEH_TRAIN && v->subtype <= subtype))) {
       
   263 				if (v->group_id != id_g) continue;
   262 				if (v->group_id != id_g) continue;
   264 
   263 
   265 				/* For each shared vehicles add it to the group */
   264 				/* For each shared vehicles add it to the group */
   266 				for (Vehicle *v2 = GetFirstVehicleFromSharedList(v); v2 != NULL; v2 = v2->next_shared) {
   265 				for (Vehicle *v2 = GetFirstVehicleFromSharedList(v); v2 != NULL; v2 = v2->next_shared) {
   267 					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);
   291 	Group *g = GetGroup(p1);
   290 	Group *g = GetGroup(p1);
   292 	if (g->owner != _current_player) return CMD_ERROR;
   291 	if (g->owner != _current_player) return CMD_ERROR;
   293 
   292 
   294 	if (flags & DC_EXEC) {
   293 	if (flags & DC_EXEC) {
   295 		GroupID old_g = p1;
   294 		GroupID old_g = p1;
   296 		uint subtype = (type == VEH_AIRCRAFT) ? AIR_AIRCRAFT : 0;
       
   297 		Vehicle *v;
   295 		Vehicle *v;
   298 
   296 
   299 		/* 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 */
   300 		FOR_ALL_VEHICLES(v) {
   298 		FOR_ALL_VEHICLES(v) {
   301 			if ((v->type == type) && (
   299 			if (v->type == type && v->IsPrimaryVehicle()) {
   302 					(type == VEH_TRAIN && IsFrontEngine(v)) ||
       
   303 					(type != VEH_TRAIN && v->subtype <= subtype))) {
       
   304 				if (v->group_id != old_g) continue;
   300 				if (v->group_id != old_g) continue;
   305 
   301 
   306 				/* Add The Vehicle to the default group */
   302 				/* Add The Vehicle to the default group */
   307 				CmdAddVehicleGroup(tile, flags, DEFAULT_GROUP, v->index);
   303 				CmdAddVehicleGroup(tile, flags, DEFAULT_GROUP, v->index);
   308 			}
   304 			}
   344  * @note Called in CmdSellRailWagon and DeleteLasWagon,
   340  * @note Called in CmdSellRailWagon and DeleteLasWagon,
   345  * @param v     FrontEngine of the train we want to remove.
   341  * @param v     FrontEngine of the train we want to remove.
   346  */
   342  */
   347 void RemoveVehicleFromGroup(const Vehicle *v)
   343 void RemoveVehicleFromGroup(const Vehicle *v)
   348 {
   344 {
   349 	if (!IsValidVehicle(v) || v->type != VEH_TRAIN || !IsFrontEngine(v)) return;
   345 	if (!IsValidVehicle(v) || !(v->HasFront() && v->IsPrimaryVehicle())) return;
   350 
   346 
   351 	if (!IsDefaultGroupID(v->group_id)) DecreaseGroupNumVehicle(v->group_id);
   347 	if (!IsDefaultGroupID(v->group_id)) DecreaseGroupNumVehicle(v->group_id);
   352 }
   348 }
   353 
   349 
   354 
   350