static protected bool Fight(UnitAgent attacker, UnitAgent defender)
 {
     if (attacker.team == defender.team)
     {
         attacker.AddReward(-0.05f);
         return(false);
     }
     else if (attacker.attack >= defender.attack && attacker.attack > 0)
     {
         defender.SetReward(-.1f);
         defender.Dead();
         defender.Done();
         attacker.SetReward(1f);
         attacker.Done();
         Debug.Log("Attacker Beat Defender");
         return(true);
     }
     else
     {
         attacker.SetReward(-.1f);
         attacker.Dead();
         attacker.Done();
         Debug.Log("Defender Beat Attacker");
         return(false);
     }
 }
Esempio n. 2
0
 public void RemoveAgent(UnitAgent agent)
 {
     if (agents != null && agents.Contains(agent))
     {
         agents.Remove(agent);
     }
 }
Esempio n. 3
0
    public int AddAgent(UnitAgent newAgent)
    {
#if UNITY_EDITOR
        if (newAgent != null)
        {
            agents.Add(newAgent);
            if (logs == null)
            {
                Debug.Log("WHAT THE FUUUUUUCK");
            }
            logs.Add(new InfoLog());
            return(logs.Count - 1);
        }
#endif
        return(-1);
    }
Esempio n. 4
0
    public void Step()
    {
        foreach (GameObject unit in team)
        {
            UnitAgent agent = unit.GetComponent <UnitAgent>();

            switch (agent.GetUnitType())
            {
            case UnitAgent.Warrior:
                if (agent.IsDead() && resources > 100)
                {
                    agent.Done();
                    resources -= 100;
                }
                break;

            case UnitAgent.Worker:
                if (agent.IsDead() && resources > 50)
                {
                    agent.Done();
                    resources -= 50;
                }
                break;
            }
        }
        if (!academy.training)
        {
            if (team.Count < 6 && resources > 50)
            {
                GameObject newUnit = academy.BuildUnit(UnitAgent.Worker, teamNum);
                team.Add(newUnit);
                newUnit.GetComponent <UnitAgent>().castle = this;
                newUnit.GetComponent <UnitAgent>().ResetAgent();
                resources -= 50;
            }
            else if (resources > 100)
            {
                GameObject newUnit = academy.BuildUnit(UnitAgent.Warrior, teamNum);
                team.Add(newUnit);
                newUnit.GetComponent <UnitAgent>().castle = this;
                newUnit.GetComponent <UnitAgent>().ResetAgent();
                resources -= 100;
            }
        }
    }
    private void Start()
    {
        Monitor.SetActive(true);

        if (!training)
        {
            teams = new List <List <GameObject> >();

            while (teams.Count < numTeams)
            {
                teams.Add(new List <GameObject>());
            }

            Agent[] agents = FindObjectsOfType(typeof(Agent)) as Agent[];
            for (int i = 0; i < agents.Length; i++)
            {
                UnitAgent unit = agents[i].GetComponent <UnitAgent>();

                teams[unit.team].Add(agents[i].gameObject);
            }

            castles = new List <GameObject>();

            for (int i = 0; i < teams.Count; i++)
            {
                Castle castle = Instantiate(CastlePrefab).GetComponent <Castle>();
                castle.SetTeam(teams[i], i);
                MeshRenderer mesh = castle.GetComponentInChildren <MeshRenderer>();
                Material[]   mat  = mesh.materials;
                mat[0]         = Colors[i];
                mesh.materials = mat;

                castles.Add(castle.gameObject);
            }

            gameState  = FindObjectOfType(typeof(GameState)) as GameState;
            controller = FindObjectOfType(typeof(GameController)) as GameController;
            maxRange   = 25;

            resetButton = Instantiate(resetButton);
            resetButton.GetComponentInChildren <Button>().onClick.AddListener(ResetAcademy);

            ResetAcademy();
        }
    }
    public override void InitializeAcademy()
    {
        if (training)
        {
            teams = new List <List <GameObject> >();

            Agent[] agents = FindObjectsOfType(typeof(Agent)) as Agent[];
            for (int i = 0; i < agents.Length; i++)
            {
                UnitAgent unit = agents[i].GetComponent <UnitAgent>();
                while (teams.Count <= unit.team)
                {
                    teams.Add(new List <GameObject>());
                }

                teams[unit.team].Add(agents[i].gameObject);
            }
            gameState  = FindObjectOfType(typeof(GameState)) as GameState;
            controller = FindObjectOfType(typeof(GameController)) as GameController;
            maxRange   = 20;

            castles = new List <GameObject>();

            for (int i = 0; i < teams.Count; i++)
            {
                Castle castle = Instantiate(CastlePrefab).GetComponent <Castle>();
                castle.SetTeam(teams[i], i);
                MeshRenderer mesh = castle.GetComponentInChildren <MeshRenderer>();
                Material[]   mat  = mesh.materials;
                mat[0]         = Colors[i];
                mesh.materials = mat;

                castles.Add(castle.gameObject);
            }
        }
    }
    public void SetEnvironment()
    {
        gameState.EmptyHexes();

        controller.InitMap();

        for (int i = 0; i < teams.Count; i++)
        {
            List <GameObject> team = teams[i];

            Hex  teamLoc;
            bool validLoc = false;

            int x;
            int y;

            int count = 0;

            do
            {
                count++;

                x = Random.Range(-maxRange, maxRange);
                y = Random.Range(-maxRange, maxRange);

                if (Mathf.Abs(x + y) == Mathf.Abs(x) + Mathf.Abs(y))
                {
                    y = y - x;
                }

                x += gameState.centerX;
                y += gameState.centerY;

                Coordinates2D coords = new Coordinates2D(x, y);

                teamLoc = gameState.GetHex(coords).GetComponent <Hex>();

                if (teamLoc.getType() != GameState.HexTypes.Mountain &&
                    teamLoc.getType() != GameState.HexTypes.Water &&
                    teamLoc.unitInHex == null)
                {
                    validLoc = true;
                }
            } while (!validLoc && count < 50);

            if (!validLoc)
            {
                Debug.Log("Failed to find valid tiles.");
                SetEnvironment();
                return;
            }

            foreach (GameObject member in team)
            {
                UnitAgent unit = member.GetComponent <UnitAgent>();
                unit.homeX = x;
                unit.homeY = y;
                unit.Dead();
            }

            castles[i].transform.position = teamLoc.transform.position;
        }

        timer = -1;
    }