public override void InitActionNonTerminal()
    {
        base.InitActionNonTerminal();

        _actionsNT["ACTN_HEADING_SOUTH"] = delegate()
        {
            GetComponent <Stats>().SetHeading(270);
        };
        _actionsNT["ACTN_HEADING_NORTH"] = delegate()
        {
            GetComponent <Stats>().SetHeading(90);
        };
        _actionsNT["ACTN_HEADING_EAST"] = delegate()
        {
            GetComponent <Stats>().SetHeading(0);
        };
        _actionsNT["ACTN_HEADING_WEST"] = delegate()
        {
            GetComponent <Stats>().SetHeading(180);
        };

        _actionsNT["ACTN_HEADING_RANDOM"] = delegate()
        {
            GetComponent <Stats>().SetHeading(Random.Range(0f, 360f));
        };

        _actionsNT["ACTN_TURN_AROUND"] = delegate()
        {
            GetComponent <Stats>().SetHeading(180 + GetComponent <Stats>().GetHeading());
        };
        _actionsNT["ACTN_TOWARD_MESSAGE_SENDER"] = delegate()
        {
            print("ACTN_TOWARD_MESSAGE_SENDER " + _tmpMessage);
            if (_tmpMessage != null)
            {
                GetComponent <Stats>().SetHeading(_tmpMessage.heading);
            }
        };
        _actionsNT["ACTN_ADD_ELIMINATION_CONTRACT"] = delegate()
        {
            EliminationContract newContract = new EliminationContract((GameObject)_tmpMessage._contenu);
            GetComponent <Stats>().AddContract(newContract);
        };
    }
示例#2
0
    public override void InitPercept()
    {
        base.InitPercept();
        _percepts["PERCEPT_BLOCKED"] = delegate() { return(GetComponent <MovableCharacter>().isBlocked()); };

        _percepts["PERCEPT_BASE_NEAR_ALLY"] = delegate()
        {
            GetComponent <Stats>().SetTarget(null);
            foreach (GameObject gO in GetComponent <Sight>()._listOfCollision)
            {
                if (gO && gO.GetComponent <Stats>() != null && gO.GetComponent <Stats>()._unitType == "Base" &&
                    Vector3.Distance(transform.position, gO.transform.position) < 8f && gO.GetComponent <Stats>()._teamIndex == GetComponent <Stats>()._teamIndex)
                {
                    GetComponent <Stats>().SetTarget(gO);
                    return(true);
                }
            }
            return(false);
        };
        /** PERCEPT **/
        _percepts["PERCEPT_CAN_GIVE"] = delegate()
        {
            GetComponent <Stats>().SetTarget(null);
            foreach (GameObject gO in GetComponent <Sight>()._listOfCollision)
            {
                if (gO && gO.GetComponent <Stats>() != null &&
                    Vector3.Distance(transform.position, gO.transform.position) < 8f && gO.GetComponent <Stats>()._teamIndex == GetComponent <Stats>()._teamIndex)
                {
                    GetComponent <Stats>().SetTarget(gO);
                    return(true);
                }
            }
            return(false);
        };
        _percepts["PERCEPT_CONTRACT_ELIMINATION"]             = delegate() { return(GetComponent <Stats>().HaveContrat() && GetComponent <Stats>().GetContract().type == "Elimination"); };
        _percepts["PERCEPT_CONTRACT_ELIMINATION_TARGET_NEAR"] = delegate() {
            Brain             brain           = GetComponent <Brain>();
            Sight             sight           = brain.GetComponent <Sight>();
            List <GameObject> _listOfUnitColl = new List <GameObject>();
            if (!GetComponent <Stats>().HaveContrat() || (GetComponent <Stats>().HaveContrat() && GetComponent <Stats>().GetContract().type != "Elimination"))
            {
                return(false);
            }
            EliminationContract contract = (EliminationContract)GetComponent <Stats>().GetContract();

            foreach (GameObject gO in sight._listOfCollision)
            {
                if (gO && contract._target == gO)
                {
                    GetComponent <Stats>().SetTarget(gO);
                    GetComponent <Stats>().SetHeading(getAngle(gO));
                    return(true);
                }
            }
            return(false);
        };

        _percepts["PERCEPT_FOOD_NEAR"] = delegate()
        {
            return((_percepts["PERCEPT_FOOD"]()) && (Vector3.Distance(GetComponent <Stats>().GetTarget().transform.position, transform.position) < 4f));
        };

        _percepts["PERCEPT_CONTRACT"] = delegate() { return(GetComponent <Stats>().HaveContrat()); };
        _percepts["PERCEPT_FOOD"]     = delegate()
        {
            GetComponent <Stats>().SetTarget(null);
            foreach (GameObject gO in GetComponent <Sight>()._listOfCollision)
            {
                if (gO && gO.tag == "Item")
                {
                    GetComponent <Stats>().SetTarget(gO);
                    return(true);
                }
            }
            return(false);
        };
    }