public static void AddUnitsToGroup(UnitGroup group, int numUnits) { var units = current.groupUnitsMap[group.ID]; group.AddUnits(numUnits); for (int i = 0; i < numUnits; i++) { var unit = CreateUnitForFaction(group.Faction); unit.SetGroup(group); units.Add(unit); } }
// places new unit within nearby group if one exists, aggregating multiple should it bridge different groups. private void IntegrateUnit(ResUnit unit) { Debug.Log("INTEGRATING"); VectorHex posHex = unit.posHex; Debug.Log("ID: " + unit.owner.playerID); List <UnitGroup> neighborGroups = grid.GetPosNeighborGroups(posHex, distinguishPlayers: true, playerQueried: unit.owner.playerID, ignoreOwnGroup: true, invertPlayerSelection: false); // if there are no neighbors if (neighborGroups.Count < 1) { UnitGroup newGroup = new UnitGroup(unit.owner); newGroup.AddUnit(unit); allGroups.Add(newGroup); } else if (neighborGroups.Count > 1) { UnitGroup superGroup = neighborGroups[0]; for (int i = 1; i < neighborGroups.Count; i++) { superGroup.AddUnits(neighborGroups[i].units); if (allGroups.Contains(neighborGroups[i])) { allGroups.Remove(neighborGroups[i]); } } superGroup.AddUnit(unit); } else { neighborGroups[0].AddUnit(unit); } grid.PlaceUnit(unit); allUnits.Add(unit); }