private Hashtable _stats; // Hashtable of all tracked stats. We use a hashtable for flexibility and automatic export/display.

        #endregion Fields

        #region Constructors

        public World(ArrayList races, int initialLifelets, SpawnMethod spawnMethod)
        {
            // Init
            _stats = new Hashtable();
            _randomGen = new Random((int)DateTime.Now.Ticks);
            _initialLifelets = initialLifelets;
            _races = races;
            _spawnMethod = spawnMethod;
            _age = 0;

            // Assign a color for each race
            ArrayList colors = new ArrayList(new Color[]{Color.Red,Color.Blue,Color.Green,Color.Aqua,Color.Lime,Color.Orange});
            foreach(Type t in races) {
                Color c = Color.FromArgb(_randomGen.Next(256),_randomGen.Next(256),_randomGen.Next(256)); // Random color, if we run out
                if(colors.Count > 0) {
                    int i = _randomGen.Next(colors.Count);
                    c = (Color)colors[i];
                    colors.RemoveAt(i);
                }
                _stats[t.FullName + "_Color"] = c;
            }

            // Reset
            this.Reset();
        }
        private static int GetSpawnPointIndex(Transform[] spawnPoints, SpawnMethod spawnMethod)
        {
            if (spawnPoints.Length <= 0)
            {
                return(-1);
            }

            switch (spawnMethod)
            {
            case SpawnMethod.RoundRobin:
                return(spawnIndex++ & spawnPoints.Length);

            case SpawnMethod.Random:
            default:
                return(Random.Range(0, spawnPoints.Length - 1));
            }
        }
Example #3
0
    public void SpawnEnemies(SpawnMethod method, EnemyType enemyType = EnemyType.Squid, BehaviourType?moveType = null, int numEnemies = 10)
    {
        switch (method)
        {
        case SpawnMethod.Random:
            SpawnEnemiesRandom(moveType, enemyType, numEnemies);
            break;

        case SpawnMethod.InHouses:
            SpawnEnemiesInHouses(moveType, enemyType);
            break;

        case SpawnMethod.InJail:
            SpawnEnemiesInJail(moveType, enemyType, numEnemies);
            break;

        default:
            throw new UnityException("Invalid spawn method requested (EnemyManager)");
        }
    }
        private static int FindSpawnPointIndex(Transform[] spawnPoints, SpawnMethod spawnMethod)
        {
            if (spawnPoints == null)
            {
                return(-1);
            }

            for (int i = 0; i < spawnPoints.Length; i++)
            {
                int spawnPointIndex = GetSpawnPointIndex(spawnPoints, spawnMethod);
                if (spawnPointIndex >= 0 && spawnPointIndex < spawnPoints.Length && spawnPoints[spawnPointIndex] != null)
                {
                    Vector3 spawnPosition = spawnPoints[spawnPointIndex].position;
                    if (CheckSpawnPointIsFree(spawnPosition))
                    {
                        return(spawnPointIndex);
                    }
                }
            }
            return(-1);
        }
Example #5
0
    /// <summary>
    /// Sets values, checks spawn type, clears formation then calls generate function
    /// </summary>
    public void vGenerateFormation(SpawnMethod _type, int _xP, int _xN, int _yP, int _yN, float _xSpacing, float _ySpacing)
    {
        if (m_iXNegSpawns < 0 || m_iYNegSpawns < 0 || m_iXPosSpawns < 0 || m_iYPosSpawns < 0)
        {
            Debug.LogWarning("FLAG: A LdrCreate was given invalid Generation values: "
                             + m_iXPosSpawns + "x/" + m_iXNegSpawns + " -x/" + m_iYPosSpawns + " y/" + m_iYNegSpawns + " -y/"
                             + gameObject);
        }
        else
        {
            m_iXNegSpawns = _xN;
            m_iYNegSpawns = _yN;
            m_iXPosSpawns = _xP;
            m_iYPosSpawns = _yP;
        }

        if (m_fXSpacing < 0f && m_fYSpacing < 0f)
        {
            Debug.LogWarning("FLAG: A LdrCreate was given invalid Spacing values: " + m_fXSpacing + "x, " + m_fYSpacing + "y, " + gameObject);
        }
        else
        {
            m_fXSpacing = _xSpacing;
            m_fYSpacing = _ySpacing;
        }

        if (Enum.IsDefined(typeof(SpawnMethod), _type))
        {
            m_eSpawnMethod = _type;
        }
        else
        {
            Debug.LogWarning("FLAG: A LdrCreate was given an invalid enumeration type value: " + _type + ", " + gameObject);
        }

        vGenerateSelect();
    }
Example #6
0
    /// <summary>
    /// Sets values, checks spawn type, clears formation then calls generate function
    /// </summary>
    public void vGenerateFormation(SpawnMethod _type, int _xP, int _xN, int _yP, int _yN, float _xSpacing, float _ySpacing)
    {
        if (m_iXNegSpawns < 0 || m_iYNegSpawns < 0 || m_iXPosSpawns < 0 || m_iYPosSpawns < 0)
            Debug.LogWarning("FLAG: A LdrCreate was given invalid Generation values: "
                + m_iXPosSpawns + "x/" + m_iXNegSpawns + " -x/" + m_iYPosSpawns + " y/" + m_iYNegSpawns + " -y/"
                + gameObject);
        else
        {
            m_iXNegSpawns = _xN;
            m_iYNegSpawns = _yN;
            m_iXPosSpawns = _xP;
            m_iYPosSpawns = _yP;
        }

        if (m_fXSpacing < 0f && m_fYSpacing < 0f)
            Debug.LogWarning("FLAG: A LdrCreate was given invalid Spacing values: " + m_fXSpacing + "x, " + m_fYSpacing + "y, " + gameObject);
        else
        {
            m_fXSpacing = _xSpacing;
            m_fYSpacing = _ySpacing;
        }

        if (Enum.IsDefined(typeof(SpawnMethod), _type))
            m_eSpawnMethod = _type;
        else
            Debug.LogWarning("FLAG: A LdrCreate was given an invalid enumeration type value: " + _type + ", " + gameObject);

        vGenerateSelect();
    }
        public static HumanoidControl Spawn(HumanoidControl humanoidPrefab, Transform[] spawnPoints = null, SpawnMethod spawnMethod = SpawnMethod.RoundRobin)
        {
            if (humanoidPrefab == null || (spawnMethod == SpawnMethod.SinglePlayer && nHumanoids > 0))
            {
                return(null);
            }

            GameObject newPlayer       = null;
            int        spawnPointIndex = FindSpawnPointIndex(spawnPoints, spawnMethod);

            if (spawnPointIndex < 0)
            {
                newPlayer = Instantiate(humanoidPrefab.gameObject);
            }
            else
            {
                newPlayer = Instantiate(humanoidPrefab.gameObject, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
            }


            HumanoidControl humanoid = newPlayer.GetComponent <HumanoidControl>();

            if (humanoid == null)
            {
                humanoid = AddHumanoidToAvatar(newPlayer);
                if (humanoid == null)
                {
                    Debug.LogError("Avatar is not a Humanoid!");
                    return(null);
                }
            }

            return(humanoid);
        }