Example #1
0
        public void ScheduleChunkUpdate(ChunkCoordinates position, ScheduleType type, bool prioritize = false)
        {
            if (Chunks.TryGetValue(position, out IChunkColumn chunk))
            {
                var currentSchedule = chunk.Scheduled;
                if (prioritize)
                {
                    chunk.Scheduled = type;

                    if (!Enqueued.Contains(position) && Enqueued.TryAdd(position))
                    {
                        HighestPriority.Enqueue(position);
                    }

                    return;
                }


                if (currentSchedule != ScheduleType.Unscheduled)
                {
                    return;
                }

                if (!_workItems.ContainsKey(position) &&
                    !Enqueued.Contains(position) && Enqueued.TryAdd(position))
                {
                    chunk.Scheduled = type;

                    Interlocked.Increment(ref _chunkUpdates);
                }
            }
        }
    private void MakeChoise()
    {
        if (m_AttackPercentage > m_DefencePercentage)
        {
            m_HighestPriority = HighestPriority.Attack;
        }
        else if (m_DefencePercentage > m_AttackPercentage)
        {
            m_HighestPriority = HighestPriority.Defence;
        }

        m_NewCollectorLimitTimer -= Time.deltaTime;

        if (m_NewCollectorLimitTimer <= 0f)
        {
            m_CollectorsLimit       += 1;
            m_NewCollectorLimitTimer = 60f;
        }

        if (m_GoldPercentage <= 15f || m_GoldPercentage >= 85)
        {
            if (m_PlayerUnits.Count <= m_AIUnits.Count && m_AmountOfCollectors <= m_CollectorsLimit)
            {
                SpawnCollector();
            }
        }

        if (m_DefencePercentage >= 40f)
        {
            List <string> unitsToSpawn = new List <string>();

            if (m_GoldPercentage >= 80f)
            {
                unitsToSpawn.Add("Melee");
                unitsToSpawn.Add("Melee");
                unitsToSpawn.Add("Ranged");
            }
            else if (m_GoldPercentage >= 50f)
            {
                unitsToSpawn.Add("Melee");
                unitsToSpawn.Add("Ranged");
            }
            else if (m_GoldPercentage >= 30f)
            {
                unitsToSpawn.Add("Melee");
            }

            SpawnUnit(unitsToSpawn);
        }
        else if (m_AttackPercentage >= 40f)
        {
            List <string> unitsToSpawn = new List <string>();

            if (m_GoldPercentage >= 80f)
            {
                unitsToSpawn.Add("Melee");
                unitsToSpawn.Add("Melee");
                unitsToSpawn.Add("Ranged");
                unitsToSpawn.Add("Spellcaster");
            }
            else if (m_GoldPercentage >= 50f)
            {
                unitsToSpawn.Add("Melee");
                unitsToSpawn.Add("Ranged");
                unitsToSpawn.Add("Ranged");
            }
            else if (m_GoldPercentage >= 30f)
            {
                unitsToSpawn.Add("Melee");
                unitsToSpawn.Add("Ranged");
            }
            else if (m_GoldPercentage >= 20f)
            {
                unitsToSpawn.Add("Melee");
            }

            SpawnUnit(unitsToSpawn);
        }
    }