Example #1
0
    public override void OnBeat(bool isRelevant)
    {
        if (!manager.running || manager.Paused || paused)
        {
            return;
        }

        if (manager.TotalBeats == nextDecisionBeat)
        {
            EnemyDecision   decision = EnemyDecision.Spawn;
            List <BaseShip> ships    = manager.GetShipsForFaction(teamID);
            if (ships.Count > 0)
            {
                if (ships.Count == maxShipsToDeploy || UnityEngine.Random.value >= deployProbability)
                {
                    decision = EnemyDecision.Deploy;
                }
            }

            switch (decision)
            {
            case EnemyDecision.Spawn:
            {
                int units = UnityEngine.Random.Range(minSpawnUnits, maxSpawnUnits);
                Debug.LogFormat("Spawning {0} {1} enemy units", units, shipPrefab.shipName);
                for (int i = 0; i < units; ++i)
                {
                    BaseShip s = Instantiate <BaseShip>(shipPrefab);
                    s.name = string.Format("{0}#{1}", s.shipName, counter++);
                    s.SetHQ(hq);
                    manager.RegisterShip(s);
                }
                break;
            }

            case EnemyDecision.Deploy:
            {
                List <BasePlanet> planets = manager.GetPlanetsInFaction(TeamType.Player);
                // Force attacking only the base
                BasePlanet target = planets.Find(x => x is HQPlanet);
                if (target != null)
                {
                    manager.LaunchAttack(target, 0.0f);
                }
                break;
            }
            }

            nextDecisionBeat += Random.Range(minDecisionMult, maxDecisionMult) * UnityEngine.Random.Range(minDecisionBeats, maxDecisionBeats);
        }
        base.OnBeat(isRelevant);
    }
Example #2
0
    public EnemyDecision GetDecision()
    {
        UnitTracker ut = GetComponent <UnitTracker>();

        switch (behaviour)
        {
        case EnemyBehaviour.IDLE:
            //In this state, enemies will simply stand still, and will not attack (will still counterattack)
            return(new EnemyDecision());

        case EnemyBehaviour.HOLD:
            //In this state, enemies will stay in place, and will not move. They will attack anything in their immediate range,
            //but will not move to attack a unit
            return(FindBestAttackAt(ut.GetLocation()));

        case EnemyBehaviour.WAIT:
            //In this state, enemies will stay in place, but will move to attack any enemies they can move to and attack
            return(FindBestMoveAttack(ut.PossibleMovement()));

        case EnemyBehaviour.SEEK:
            //In this state, enemies will stay in place, but will move to attack any enemies they can move to and attack
            //If there are no enemies to attack, enemies will move towards their goal
            EnemyDecision bestCombat = FindBestMoveAttack(ut.PossibleMovement());
            if (bestCombat.pass)
            {
                return(FindBestMove(new Vector3Int(0, 0, 0)));
            }
            else
            {
                return(bestCombat);
            }
        }

        print("???");
        return(new EnemyDecision());
    }
Example #3
0
 void Start()
 {
     enemyDecision = GetComponent <EnemyDecision>();
 }