Ejemplo n.º 1
0
    private void Awake()
    {
        m_agent = gameObject.GetComponent <ShooterAgent>();
        if (m_agent == null)
        {
            Debug.Log("AgentBT not attached to agent GameObject.");
        }

        //N_AgentNode.AgentType agent;

        //if (StaticMethods.GetInstance().GetAgent0() == this.GetComponent<ShooterAgent>())
        //    agent = N_AgentNode.AgentType.agent0;
        //else
        //    agent = N_AgentNode.AgentType.agent1;


        //// Temporary code for testing out a simple BT
        //N_Root testTree = new N_Root();
        //N_Selection select = new N_Selection();

        //N_Sequence seq = new N_Sequence();
        //seq.AddLast(BehaviourSubtrees.Tree_PatrolOrKite(agent));
        //seq.AddFirst(BehaviourSubtrees.Tree_ShootAtEnemy(agent));
        //select.AddLast(BehaviourSubtrees.Tree_ReloadIfLow(agent, 5));
        //select.AddLast(seq);

        //testTree.Child = select;

        //FileSaver.GetInstance().SaveTree(testTree, gameObject.name);
        //N_Root loadedTree = FileSaver.GetInstance().LoadTree(gameObject.name);

        //// Set the tree before being able to copy
        //SetTree(loadedTree, agent);
    }
Ejemplo n.º 2
0
    public override Response Signal()
    {
        ShooterAgent agent = StaticMethods.GetInstance().GetAgentOfType(agentType);

        //Debug.Log("Kiting!");
        return(agent.Kite() == true ? Response.Success : Response.Running);
    }
Ejemplo n.º 3
0
    public override Response Signal()
    {
        ShooterAgent agent = StaticMethods.GetInstance().GetAgentOfType(agentType);

        agent.TurnAround();
        return(Response.Success);
    }
Ejemplo n.º 4
0
    public override Response Signal()
    {
        ShooterAgent agent = StaticMethods.GetInstance().GetAgentOfType(agentType);

        // If not lost and has no path, walk towards enemy position.
        if (!agent.EnemyLost && !agent.HasPath())
        {
            agent.CancelPath();
            agent.WalkTowards(agent.EnemyPosition);
        }
        // If the agent reached the enemypos yet there's no enemy in sight, return failure.
        else if (agent.AtEnemyPosition() && !agent.EnemyVisible())
        {
            agent.EnemyLost = true;
            return(Response.Failure);
        }
        // When enemy is found, cancel following and return success.
        else if (agent.EnemyVisible())
        {
            agent.CancelPath();
            return(Response.Success);
        }

        return(Response.Running);
    }
Ejemplo n.º 5
0
    public override Response Signal()
    {
        ShooterAgent agent = StaticMethods.GetInstance().GetAgentOfType(agentType);

        agent.ShootAt(agent.EnemyPosition);
        return(Response.Success);
    }
Ejemplo n.º 6
0
 public void DealDamage(int amount, ShooterAgent enemy)
 {
     health -= amount;
     enemy.AddReward(1.0f);
     if (health <= 0)
     {
         //Debug.LogError("killed");
         enemy.AddReward(10f);
         AddReward(-10f);
         enemy.EndEpisode();
         EndEpisode();
     }
 }
Ejemplo n.º 7
0
    public void DealDamage(int amount, ShooterAgent shooter)
    {
        health -= amount;
        shooter.AddReward(1f);
        if (health <= 0)
        {
            shooter.AddReward(10f);

            //shooter.EndEpisode();
            GetComponentInParent <WorldArea>().targetsCount--;
            //Debug.LogError("end");
            Destroy(this.transform.gameObject);
        }
    }
Ejemplo n.º 8
0
    void Awake()
    {
        // Make sure simulation runs in background during built application
        Application.runInBackground = true;

        // Find prefab of healthPack for respawning purposes.
        m_hpPrefab = Resources.Load("healthPack") as GameObject;
        if (m_hpPrefab == null)
        {
            Debug.LogError("No healthPack prefab found in resources.");
        }
        // Save spawning positions of healthpacks
        GameObject[] hpArray = GetHealthPacks();
        foreach (GameObject hp in hpArray)
        {
            m_hpPositions.Add(hp.transform.position);
        }

        liveSimulationScale = simulationTimeScale;
        if (agent0 != null || agent1 != null)
        {
            // Set default values of agents when found.
            startPos_agent0 = agent0.transform.position;
            startPos_agent1 = agent1.transform.position;
            startRot_agent0 = agent0.transform.rotation;
            startRot_agent1 = agent1.transform.rotation;
            behave_agent0   = agent0.GetComponent <ShooterAgent>();
            behave_agent1   = agent1.GetComponent <ShooterAgent>();
            bt_agent0       = agent0.GetComponent <AgentBT>();
            bt_agent1       = agent1.GetComponent <AgentBT>();
            result_agent0   = new AgentResults();
            result_agent1   = new AgentResults();
        }
        else
        {
            Debug.LogError("MatchSimulator missing agents.");
        }
        if (startGameOnStartup)
        {
            StartMatch();
        }
        else
        {
            Time.timeScale = 0.0f;
        }
    }
Ejemplo n.º 9
0
    // Set random destination and walk towards it.
    public override Response Signal()
    {
        ShooterAgent agent = StaticMethods.GetInstance().GetAgentOfType(agentType);

        // If no current path, randomize new one and walk towards it.
        if (!agent.HasPath() || agent.StateOfAgent == ShooterAgent.AgentState.kiting)
        {
            agent.StateOfAgent = ShooterAgent.AgentState.patroling;
            agent.SetRandomDestination();
            agent.WalkTowards(agent.WalkingDestination);
            return(Response.Success);
        }
        else
        {
            return(Response.Running);
        }
    }
Ejemplo n.º 10
0
    public void Initialize(ShooterAgent agent, Vector3 direction)
    {
        Direction             = direction;
        this.gameObject.layer = LayerMask.NameToLayer("projectile");
        this.shooter          = agent;
        var layerName = LayerMask.LayerToName(agent.gameObject.layer);

        if (layerName == "TeamA")
        {
            this.gameObject.tag = "blueProjectile";
        }
        else if (layerName == "TeamB")
        {
            this.gameObject.tag = "redProjectile";
        }
        shotPosition       = agent.gameObject.transform.position;
        Rigidbody          = GetComponent <Rigidbody>();
        Rigidbody.velocity = Direction * rojectileSpeed;
    }
Ejemplo n.º 11
0
    public override Response Signal()
    {
        ShooterAgent agent = StaticMethods.GetInstance().GetAgentOfType(agentType);

        return(agent.Bullets <= threshold ? Response.Success : Response.Failure);
    }
Ejemplo n.º 12
0
    public override Response Signal()
    {
        ShooterAgent agent = StaticMethods.GetInstance().GetAgentOfType(agentType);

        return(agent.Reload() == true ? Response.Running : Response.Success);
    }
Ejemplo n.º 13
0
    public override Response Signal()
    {
        ShooterAgent agent = StaticMethods.GetInstance().GetAgentOfType(agentType);

        return(agent.EnemyVisible() == true ? Response.Success : Response.Failure);
    }
Ejemplo n.º 14
0
    // Return running if hp is found. If no hp exists, return success.
    public override Response Signal()
    {
        ShooterAgent agent = StaticMethods.GetInstance().GetAgentOfType(agentType);

        return(agent.GetHealthPack() == true ? Response.Running : Response.Failure);
    }