Example #1
0
    //Adds an owned system to the list
    public static void AddControlledSystem(int factionID, GalaxyNode newControlledSystem)
    {
        if (factionID < factions.Length && factionID >= 0)
        {
            //Check the system is not already in the list
            bool        alreadyInList   = false;
            bool        alreadyInIDList = false;
            FactionData data            = factions[factionID];
            for (int i = 0; i < data.ownedSystems.Count; i++)
            {
                if (data.ownedSystems.Contains(newControlledSystem))
                {
                    alreadyInList = true;
                }
                if (data.ownedSystemIDs.Contains(newControlledSystem.nodeID))
                {
                    alreadyInIDList = true;
                }
            }

            //If its new to the list
            if (alreadyInList == false)
            {
                //Add to explored systems, incase it wasnt added before
                AddExploredSystem(factionID, newControlledSystem);
                //Adding to controlled lists
                factions[factionID].ownedSystems.Add(newControlledSystem);
                newControlledSystem.SetOwningFaction(factionID);
                UpdateResourceInflux(factionID, newControlledSystem);
            }
            if (alreadyInIDList == false)
            {
                factions[factionID].ownedSystemIDs.Add(newControlledSystem.nodeID);
            }
        }
    }
Example #2
0
    //Create faction data array randomly.
    public static FactionData[] CreateFactions(int numberOfFactionsToCreate, GameObject[] systems)
    {
        numberOfFactions = numberOfFactionsToCreate;
        factions         = new FactionData[numberOfFactions];
        GameObject[] homeSystems = new GameObject[numberOfFactions];
        //For every faction to create
        for (int i = 0; i < numberOfFactionsToCreate; i++)
        {
            //Faction identifiers
            factions[i].factionID     = i;
            factions[i].factionName   = "Faction" + Random.Range(0, 100);
            factions[i].factionColour = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));

            //Home / Starting system
            GalaxyNode homeSystem = systems[Random.Range(0, systems.Length)].GetComponent <GalaxyNode>();

            //Validating faction system, prevents positioning multiple factions inside same system.
            bool valid = true;
            for (int j = 0; j < homeSystems.Length; j++)
            {
                //If the system is already in the array
                if (homeSystems[j] == homeSystem.gameObject)
                {
                    //It is not valid
                    valid = false;
                }
            }

            //If positioning is valid
            if (valid == true)
            {
                //Basic setup
                factions[i].homeSystem = homeSystem;
                homeSystem.AddSystemFeature(GalaxyNode.SystemFeatures.Planet);
                homeSystem.SetOwningFaction(i);
                factions[i].homeSystemID   = homeSystem.nodeID;
                homeSystems[i]             = homeSystem.gameObject;
                factions[i].hasCapitulated = false;

                //Assigning Galaxy node arrays
                factions[i].exploredSystems   = new List <GalaxyNode>();
                factions[i].ownedSystems      = new List <GalaxyNode>();
                factions[i].exploredSystemIDs = new List <int>();
                factions[i].ownedSystemIDs    = new List <int>();

                //Resource assigning
                factions[i].resourceData = ResetFactionResourceData(factions[i].factionID);

                //Add homesystem to explored and owned systems
                AddExploredSystem(factions[i].factionID, factions[i].homeSystem);
                AddControlledSystem(factions[i].factionID, factions[i].homeSystem);

                //Update resources
                UpdateResourceInflux(i, homeSystem);
            }
            else
            {
                i--;
            }
        }
        return(factions);
    }