Beispiel #1
0
    public static List <WeightedUnit> GetUnitsForGroupPower(UnitSpawnGroupConfig group)
    {
        int powerLeft = group.GroupPower;

        List <WeightedUnit> possibleUnits = group.SpawnableUnits.Where(u => !u.ForceUnit).ToList();
        List <WeightedUnit> choosenUnits  = group.SpawnableUnits.Where(u => u.ForceUnit).ToList();

        List <WeightedUnit> validUnits = GetUnitsInPowerRange(possibleUnits, powerLeft);

        while (validUnits.Count > 0)
        {
            WeightedUnit choosen = M_Weightable.GetWeighted(validUnits);
            choosenUnits.Add(choosen);
            int unitPower = choosen.UnitConfig.UnitPower;
            if (unitPower <= 0)
            {
                Debug.LogWarning("UNIT POWER 0, aborting to avoid infinite loop");
                return(null);
            }

            powerLeft -= unitPower;

            validUnits = GetUnitsInPowerRange(possibleUnits, powerLeft);
        }

        return(choosenUnits);
    }
Beispiel #2
0
    public List <UnitSpawner> GetSpawnerForGroup(List <int> unique_ids, UnitSpawnGroupConfig group)
    {
        //if there are no distinct spawner ids left, stop
        if (unique_ids.Count == 0)
        {
            Debug.LogWarning("Not Enough SpawnGroups in Tileset for GroupCount");
            return(null);
        }

        if (group == null)
        {
            Debug.LogWarning("No Group");
            return(null);
        }

        return(GetSpawners(unique_ids, group.SpawnerGroup));
    }
Beispiel #3
0
    void SpawnGroup(UnitSpawnGroupConfig group, List <int> spawnerIDs)
    {
        if (group == null)
        {
            Debug.LogWarning("No Group");
            return;
        }

        globalGroupCounter++;

        List <UnitSpawner> spawnersForGroup = GetSpawnerForGroup(spawnerIDs, group);

        if (spawnersForGroup == null || spawnersForGroup.Count == 0)
        {
            Debug.LogWarning("NO SPAWNERS FOR GROUP");
            return;
        }

        List <WeightedUnit> unitConfigs = RegionLoader.GetUnitsForGroupPower(group);

        if (unitConfigs.Count > spawnersForGroup.Count)
        {
            Debug.LogWarning("Not enough spawners for my group :(   spawners:" + spawnersForGroup.Count + "  units:" + unitConfigs.Count);
            //  return;
        }

        // MDebug.Log(spawnersForGroup.Count+ "   "+unitConfigs.Count);
        while (spawnersForGroup.Count > 0 && unitConfigs.Count > 0)
        {
            // MDebug.Log("SPAWN");
            WeightedUnit unit    = unitConfigs.GetRandom();
            UnitSpawner  spawner = spawnersForGroup.GetRandom();

            unitConfigs.Remove(unit);
            spawnersForGroup.Remove(spawner);

            spawner.SpawnUnit(unit.UnitConfig, unit.TurnTimeOnSpawn, globalGroupCounter, unit.HidePlayerUnit);
        }
    }
Beispiel #4
0
    public static List <UnitSpawnGroupConfig> GetGroupsForPower(RegionConfig region)
    {
        // MDebug.Log("Get groups for " + region);
        //Add all forced groups to choosen ones
        List <UnitSpawnGroupConfig> choosenGroups = region.Groups.Where(gr => gr.ForceGroup).ToList();

        //make a copy of groups but exclude the ones that we already have
        List <UnitSpawnGroupConfig> groupsCopy = new List <UnitSpawnGroupConfig>(region.Groups).Where(gr => !choosenGroups.Contains(gr)).ToList();

        int powerLeft = region.RegionTotalEnemyPower;
        //list of groupls that are valid for the powerlevel left
        List <UnitSpawnGroupConfig> validgroups = GetGroupsInPowerLevel(groupsCopy, powerLeft);

        while (validgroups.Count > 0)
        {
            UnitSpawnGroupConfig choosen = M_Weightable.GetWeighted(validgroups);
            choosenGroups.Add(choosen);
            groupsCopy.Remove(choosen);
            int groupPower = choosen.GroupPower;

            if (groupPower <= 0)
            {
                Debug.LogWarning("UNIT POWER 0, aborting to avoid infinite loop");
                return(choosenGroups);
            }

            powerLeft -= groupPower;

            if (groupsCopy.Count == 0)
            {
                Debug.LogWarning("No groups to spawn left");
                return(choosenGroups);
            }
            validgroups = GetGroupsInPowerLevel(groupsCopy, powerLeft);
        }

        return(choosenGroups);
    }
Beispiel #5
0
    public static UnitSpawnGroupConfig MakeSquadGroup()
    {
        List <ScriptableUnitConfig> unit_configs = new List <ScriptableUnitConfig>();
        UnitSpawnGroupConfig        conf         = new UnitSpawnGroupConfig();

        conf.ForceGroup     = true;
        conf.SpawnerGroup   = 1;
        conf.SpawnableUnits = new List <WeightedUnit>();

        if (Instance.selected_units.IsNullOrEmpty())
        {
            Debug.LogWarning("NO UNITS SELECTED");

            Instance.unitunlocks.Select(unlock => unlock.Item).ToList().ForEach(unlock => unit_configs.Add(unlock.Tiers.GetRandom().Config));
        }
        else
        {
            foreach (var _selected in Instance.selected_units)
            {
                unit_configs.Add(TieredUnit.Unlocks(_selected.Tiers, PlayerLevel.Instance).GetHighestUnlocked().Config);
            }
        }


        List <ScriptableUnitConfig> selected = unit_configs.GetRandomRemove(Instance.GetMaxSquadsize());

        foreach (ScriptableUnitConfig unit_config in selected)
        {
            WeightedUnit unit = new WeightedUnit();
            unit.ForceUnit       = true;
            unit.TurnTimeOnSpawn = Constants.PLAYER_SQUAD_START_INITIATIVE;
            unit.UnitConfig      = unit_config;

            conf.SpawnableUnits.Add(unit);
        }

        return(conf);
    }