Esempio n. 1
0
    public static void SpawnOneEntityInChunkNonAlloc(SpawnableEntity se, EntityData?data, ChunkCoords cc)
    {
        //pick a position within the chunk coordinates
        Vector2     spawnPos = Vector2.zero;
        Vector2Pair range    = ChunkCoords.GetCellArea(cc, EntityNetwork.CHUNK_SIZE);

        switch (se.posType)
        {
        case SpawnableEntity.SpawnPosition.Random:
            spawnPos.x = Random.Range(range.a.x, range.b.x);
            spawnPos.y = Random.Range(range.a.y, range.b.y);
            break;

        case SpawnableEntity.SpawnPosition.Center:
            spawnPos = ChunkCoords.GetCenterCell(cc, EntityNetwork.CHUNK_SIZE);
            break;
        }
        //spawn it
        Entity newEntity = Instantiate(
            se.prefab,
            spawnPos,
            Quaternion.identity,
            instance.holders[se.entityName].transform);

        newEntity.ApplyData(data);
    }
Esempio n. 2
0
    //This will determine where to set up more particle systems and create them in those positions
    private void Expansion()
    {
        int size = Random.Range(minSystemSize, maxSystemSize + 1);

        cluster = new List <NebulaSetup>(size);
        List <ChunkCoords> filled = new List <ChunkCoords>(size);
        ChunkCoords        c      = coords;

        filled.Add(c);
        int count     = 1;
        int failCount = 0;

        while (count < size && failCount < FAIL_LIMIT)
        {
            c = filled[Random.Range(0, filled.Count)];
            //pick a random adjacent coordinate
            float randomVal = Random.value;
            if (randomVal >= 0.5f)
            {
                c.x += randomVal >= 0.75f ? 1 : -1;
            }
            else
            {
                c.y += randomVal >= 0.25f ? 1 : -1;
            }
            c = c.Validate();

            bool alreadyExists = false;
            //this will check for nebulas already created in this group
            for (int i = 0; i < filled.Count; i++)
            {
                ChunkCoords check = filled[i];
                if (c == check)
                {
                    alreadyExists = true;
                    break;
                }
            }
            //if new coordinates have already been filled with nebula then pick a new coordinate
            if (alreadyExists)
            {
                failCount++;
                continue;
            }

            count++;
            filled.Add(c);
            NebulaSetup newNebula = Instantiate(this, transform.parent);
            cluster.Add(newNebula);
            newNebula.cluster = cluster;
            newNebula.SetColors(col1, col2);
            newNebula.SetThrusterReference(thrusterRef);
            newNebula.transform.position = ChunkCoords.GetCenterCell(c, EntityNetwork.CHUNK_SIZE);
            newNebula.shouldExpand       = false;
            EntityGenerator.FillChunk(c, true);
        }
    }
Esempio n. 3
0
    public void AssignUnoccupiedCoords(GatherBot b)
    {
        if (b == null)
        {
            return;
        }
        CheckEmptyMarkedCoords();
        botOccupiedCoords.Clear();
        botOccupiedCoords.AddRange(emptyCoords);

        for (int i = 0; i < childBots.Count; i++)
        {
            EntityNetwork.IterateCoordsInRange(
                childBots[i].GetIntendedCoords(),
                1,
                cc =>
            {
                botOccupiedCoords.Add(cc);
                return(false);
            },
                false);
        }

        //find a random nearby coordinate that is not already occupied
        int         searchRange = 1;
        ChunkCoords location    = ChunkCoords.Invalid;

        while (location == ChunkCoords.Invalid)
        {
            EntityNetwork.IterateCoordsOnRangeBorder(
                coords,
                searchRange,
                cc =>
            {
                if (botOccupiedCoords.Contains(cc))
                {
                    return(false);
                }
                if (Random.value < 0.1f)
                {
                    location = cc;
                    return(true);
                }

                return(false);
            },
                false);
            searchRange++;
        }

        Vector2 pos = ChunkCoords.GetCenterCell(location, EntityNetwork.CHUNK_SIZE);

        b.HiveOrders(pos);
    }
Esempio n. 4
0
    public static void FillChunk(ChunkCoords cc, bool excludePriority = false)
    {
        //don't bother if the given coordinates are not valid
        if (!cc.IsValid())
        {
            return;
        }
        //if these coordinates have no been generated yet then reserve some space for the new coordinates
        instance.GenerateVoid(cc);
        //don't bother if the coordinates have already been filled
        if (instance.Chunk(cc))
        {
            return;
        }
        //flag that this chunk coordinates was filled
        instance.Column(cc)[cc.y] = true;

        //look through the space priority entities and check if one may spawn
        SpawnableEntity se = instance.ChooseEntityToSpawn(
            ChunkCoords.GetCenterCell(cc, EntityNetwork.CHUNK_SIZE).magnitude);

        SpawnEntityInChunkNonAlloc(se, null, cc);
    }