Beispiel #1
0
    public override void StateTick()
    {
        pState = state;
        if (nextStateCheckTime < Time.time)                        // Don't change state every tick
        {
            ai.aggression = AirCraftAI.AIAggression.FollowInRange; // usually, allow chasing after enemies

            for (int i = 0; i < carriers.Count; i++)
            {
                if (carriers[i] && carriers[i].GetHealth()[0] < carriers[i].GetMaxHealth()[0] * 0.3f)
                {
                    // if base under attack -> defend
                    if (AirCraftAI.getEnemyCountInRange(carriers[i].transform.position, 45f, craft.faction) > 0)
                    {
                        if ((carriers[i].transform.position - craft.transform.position).sqrMagnitude > 1500f)
                        {
                            ai.aggression = AirCraftAI.AIAggression.KeepMoving; // Get to the home base asap
                            primaryTarget = carriers[i];
                        }
                        else
                        {
                            primaryTarget = null;
                            // TODO: find the most dangerous unit in the area, set as primary target
                        }

                        state = BattleState.Defend;
                    }
                    else
                    {
                        state = BattleState.Collect;
                    }
                    break;
                }
            }
            // if population is nearly capped, attack
            if (shellcore.GetTotalCommandLimit() < shellcore.GetUnitsCommanding().Count + 1) // TODO: OR if enemy base is weak
            {
                state = BattleState.Attack;
            }
            else if (shellcore.GetPower() >= 300)
            {
                state         = BattleState.Fortify;
                primaryTarget = null;
            }
            // if there's no need for more population space, try to create turrets to protect owned outposts and stations
            else
            {
                if (state != BattleState.Collect)
                {
                    collectTarget = null;
                }
                if (shellcore.GetTractorTarget() != null && shellcore.GetTractorTarget().GetComponent <Turret>() != null && shellcore.GetHealth()[0] > shellcore.GetMaxHealth()[0] * 0.1f)
                {
                    state = BattleState.Attack;
                }
                else
                {
                    state = BattleState.Collect;
                }
            }

            nextStateCheckTime = Time.time + 1f;
        }
        if (pState != state)
        {
            //Debug.LogFormat("Faction {0} Shellcore changed state to: {1}", craft.faction, state);
        }
    }
Beispiel #2
0
    public override void StateTick()
    {
        pState = state;
        List <EnergyRock> deadRocks = new List <EnergyRock>();

        foreach (var kvp in harvesterTurrets)
        {
            if (!kvp.Value || kvp.Value.GetIsDead())
            {
                deadRocks.Add(kvp.Key);
            }
        }

        foreach (var key in deadRocks)
        {
            harvesterTurrets.Remove(key);
        }

        if (nextStateCheckTime < Time.time)                        // Don't change state every tick
        {
            ai.aggression = AirCraftAI.AIAggression.FollowInRange; // usually, allow chasing after enemies

            for (int i = 0; i < carriers.Count; i++)
            {
                if (carriers[i] && carriers[i].GetHealth()[0] < carriers[i].GetMaxHealth()[0] * 0.3f)
                {
                    // if base under attack -> defend
                    if (AirCraftAI.getEnemyCountInRange(carriers[i].transform.position, 45f, craft.faction) > 0)
                    {
                        if ((carriers[i].transform.position - craft.transform.position).sqrMagnitude > 1500f)
                        {
                            ai.aggression = AirCraftAI.AIAggression.KeepMoving; // Get to the home base asap
                            primaryTarget = carriers[i];
                        }
                        else
                        {
                            primaryTarget = null;
                            // TODO: find the most dangerous unit in the area, set as primary target
                        }

                        state = BattleState.Defend;
                    }
                    else
                    {
                        state = BattleState.Collect;
                    }

                    break;
                }
            }

            var turretIsHarvester = shellcore.GetTractorTarget() &&
                                    shellcore.GetTractorTarget().GetComponent <Turret>() &&
                                    shellcore.GetTractorTarget().GetComponent <Turret>().entityName == "Harvester Turret";
            // if population is nearly capped, attack
            if (shellcore.GetTotalCommandLimit() < shellcore.GetUnitsCommanding().Count + 1) // TODO: OR if enemy base is weak
            {
                state = BattleState.Attack;
            }
            else if (turretIsHarvester)
            {
                state = BattleState.Collect;
            }
            else if (shellcore.GetPower() >= 300)
            {
                bool enemyGround = false;
                for (int j = 0; j < AIData.entities.Count; j++)
                {
                    if (AIData.entities[j].faction != craft.faction && AIData.entities[j].Terrain == Entity.TerrainType.Ground)
                    {
                        enemyGround = true;
                        break;
                    }
                }
                if (enemyGround)
                {
                    state         = BattleState.ReinforceGround;
                    primaryTarget = null;
                }
                else
                {
                    state         = BattleState.Fortify;
                    primaryTarget = null;
                }
            }
            // if there's no need for more population space, try to create turrets to protect owned outposts and stations
            else
            {
                if (state != BattleState.Collect)
                {
                    collectTarget = null;
                }

                if ((shellcore.GetTractorTarget() != null && shellcore.GetTractorTarget().GetComponent <Turret>() != null && !turretIsHarvester &&
                     shellcore.GetHealth()[0] > shellcore.GetMaxHealth()[0] * 0.1f) || harvesterTurrets.Count >= Mathf.Min(1, AIData.energyRocks.Count))
                {
                    state = BattleState.Attack;
                }
                else
                {
                    state = BattleState.Collect;
                }
            }

            nextStateCheckTime = Time.time + 1f;
        }

        if (pState != state)
        {
            //Debug.LogFormat("Faction {0} Shellcore changed state to: {1}", craft.faction, state);
        }
    }