Exemplo n.º 1
0
 public static float FSM_Avoid_Battle(AIEntity pEntity)
 {
     if (pEntity.GetComponent <ObstacleComponent> ().hitObject.tag == "Battleable")
     {
         return(1.0f);
     }
     else
     {
         return(0.0f);
     }
 }
Exemplo n.º 2
0
 public override void Init()
 {
     for (int i = 0; i < mMaxCount; i++)
     {
         mAIPoor [i]        = new AIEntity();
         mAIPoor [i].mAI    = mAI_Template;
         mAIPoor [i].mWorld = ECSWorld.MainWorld;
         mAIPoor [i].Init();
         mAIPoor [i].GetComponent <BaseAIComponent> ().mPoorID = i;
     }
 }
Exemplo n.º 3
0
        /*
         * sleep a AI by id
         *
         */

        public void DestroyEntity(int id)
        {
            mUEntity.mWorld.deleteEntity(mAIPoor[id]);
            mAIPoor [id].GetComponent <BaseAIComponent> ().mAIRT.SetActive(false);
            AIEntity temp = mAIPoor [id];

            mAIPoor [id]             = mAIPoor[mTempCount - 1];
            mAIPoor [mTempCount - 1] = temp;
            mAIPoor [id].GetComponent <BaseAIComponent> ().mPoorID             = id;
            mAIPoor [mTempCount - 1].GetComponent <BaseAIComponent> ().mPoorID = mTempCount - 1;
            mTempCount--;
        }
Exemplo n.º 4
0
        /*
         *
         * add the must component to AIEntity
         *
         */

        public override void Init()
        {
            BaseAIComponent tBAIComponent = new BaseAIComponent();

            tBAIComponent.mAITemplate = mAI;
            tBAIComponent.bornPoint   = AIPos;
            tBAIComponent.Init();
            AIMove            mAIMove            = new AIMove();
            AIAnimation       mAIAnimation       = new AIAnimation();
            HPComponent       hpc                = new HPComponent();
            AIState           aiState            = new AIState();
            AIEmotion         mEmotion           = new AIEmotion();
            AIStrategy        mAIStrategy        = new AIStrategy();
            ObstacleComponent mObstacleComponent = new ObstacleComponent();
            AIGroupState      aiGroupState       = new AIGroupState();

            this.AddComponent <BaseAIComponent> (tBAIComponent);
            this.AddComponent <AIMove> (mAIMove);
            this.AddComponent <AIAnimation> (mAIAnimation);
            this.AddComponent <HPComponent> (hpc);
            this.AddComponent <AIState> (aiState);
            this.AddComponent <AIEmotion> (mEmotion);
            this.AddComponent <AIStrategy> (mAIStrategy);
            this.AddComponent <ObstacleComponent> (mObstacleComponent);
            this.AddComponent <AIGroupState> (aiGroupState);
            this.AddComponent <LODComponent> (new LODComponent());

            mAIStrategy.Init();
            aiGroupState.Init();
            aiState.Init();
            mAIAnimation.Init();
            mEmotion.Init();

            InfluenceMapTrigger tInfluenceMapTrigger = new InfluenceMapTrigger();

            tInfluenceMapTrigger.maxInfluence = 4.0f;
            tInfluenceMapTrigger.mWhere       = "friend";
            tInfluenceMapTrigger.mGameObject  = mAI;
            tInfluenceMapTrigger.mIMComputer  = DefaultFunc.friendComputer;
            tInfluenceMapTrigger.Init();

            UEntity tEntity = new UEntity();

            tEntity.AddComponent <InfluenceMapTrigger> (tInfluenceMapTrigger);
            this.mWorld.registerEntityAfterInit(tEntity);
            AIEntity.getList().Add(this);
        }
Exemplo n.º 5
0
        public void DestroyEntity(AIEntity pEntity)
        {
            int index = -1;

            for (int i = 0; i < 3000; i++)
            {
                if (mAIPoor [i] == pEntity)
                {
                    index = i;
                    break;
                }
            }
            if (index != -1)
            {
                DestroyEntity(index);
            }
        }
Exemplo n.º 6
0
 // SimpleClone from a AIState, using in AIStrategy
 public void SimpleClone(AIState pState)
 {
     mtempCount       = pState.mtempCount;
     tempID           = pState.tempID;
     mCaptureFrame    = pState.mCaptureFrame;
     mFeedbackerState = pState.mFeedbackerState;
     for (int i = 0; i < 10; i++)
     {
         mframebuffer [i] = pState.mframebuffer [i];
     }
     mTempFeedbacker = pState.mTempFeedbacker;
     mid_fir         = pState.mid_fir;
     mid_sec         = pState.mid_sec;
     IAnyway         = pState.IAnyway;
     mStateRecorder  = pState.mStateRecorder;
     mStateAnimation = new Dictionary <int, string> ();
     foreach (var item in pState.mStateAnimation)
     {
         int    i1 = item.Key;
         string s1 = item.Value;
         mStateAnimation.Add(i1, s1);
     }
     for (int i = 0; i < mtempCount; i++)
     {
         mPowerEdge [i].Clear();
         for (int j = 0; j < pState.mPowerEdge [i].Count; j++)
         {
             mPowerEdge [i].Add(pState.mPowerEdge[i][j]);
         }
         mFeedbacker [i].Clear();
         for (int j = 0; j < pState.mFeedbacker [i].Count; j++)
         {
             mFeedbacker [i].Add(pState.mFeedbacker[i][j]);
         }
         mTranfer [i].Clear();
         for (int j = 0; j < pState.mTranfer [i].Count; j++)
         {
             mTranfer [i].Add(pState.mTranfer[i][j]);
         }
         mEnterer [i]   = pState.mEnterer [i];
         mExiter [i]    = pState.mExiter [i];
         mExecuter [i]  = pState.mExecuter [i];
         mStateName [i] = pState.mStateName [i];
     }
     LastEntityData = pState.LastEntityData;
 }
Exemplo n.º 7
0
        public static void FSM_Avoid(AIEntity pEntity)
        {
            if (pEntity.GetComponent <ObstacleComponent> ().target == Vector3.zero)
            {
                Vector3 v1 = pEntity.GetComponent <ObstacleComponent> ().hitObject.transform.position - pEntity.AIPos;
                v1.y = 0.0f;
                Vector3 v2 = new Vector3(1.0f, 0.0f, -v1.x / v1.z);
                v2.Normalize();
                Vector3 v3 = -v2;
                for (int i = 0; i <= 10; i++)
                {
                    float   tempRate = (float)i / 10.0f;
                    Vector3 vdir1    = Vector3.Lerp(v1, v2, tempRate);
                    vdir1.Normalize();
                    Vector3 vdir2 = Vector3.Lerp(v1, v3, tempRate);
                    vdir2.Normalize();
                    float      maxDis     = 2.0f;
                    LayerMask  layoutmask = 1 << LayerMask.NameToLayer("Collision");
                    RaycastHit hit        = new RaycastHit();
                    if (!Physics.Raycast(pEntity.GetComponent <BaseAIComponent> ().mAIRT.transform.position, vdir1, out hit, maxDis, layoutmask))
                    {
                        pEntity.GetComponent <ObstacleComponent> ().target = pEntity.GetComponent <BaseAIComponent> ().mAIRT.transform.position + vdir1 * maxDis;
                        break;
                    }
                    if (!Physics.Raycast(pEntity.GetComponent <BaseAIComponent> ().mAIRT.transform.position, vdir2, out hit, maxDis, layoutmask))
                    {
                        pEntity.GetComponent <ObstacleComponent> ().target = pEntity.GetComponent <BaseAIComponent> ().mAIRT.transform.position + vdir2 * maxDis;
                        break;
                    }
                }
            }
            float tdis = Vector3.Distance(pEntity.GetComponent <ObstacleComponent>().target, pEntity.AIPos);

            if (tdis < 0.15f)
            {
                pEntity.GetComponent <AIMove> ().mDirection = Vector3.zero;
                pEntity.GetComponent <AIMove> ().mVelocity  = 0.0f;
                return;
            }
            Vector3 tdir = pEntity.GetComponent <ObstacleComponent> ().target - pEntity.AIPos;

            tdir.y = 0.0f;
            pEntity.GetComponent <AIMove> ().mDirection = tdir.normalized;
            pEntity.GetComponent <AIMove> ().mVelocity  = 5.0f;
        }
Exemplo n.º 8
0
        /*
         * @param pEntity: Find center Entity
         * @param riaus:Find riaus
         *
         * get all AIEntity in the riaus by the center of Entity
         *
         * @return:the OK AIEntity set
         *
         */

        public static AIEntity[] getAllEntityWithSphere(AIEntity pEntity, float riaus)
        {
            Collider[]      tColliders = Physics.OverlapSphere(pEntity.AIPos, riaus);
            List <AIEntity> tList      = new List <AIEntity> ();

            for (int i = 0; i < tColliders.Length; i++)
            {
                foreach (AIEntity aie in AIEntity.getList())
                {
                    if (aie.GetComponent <BaseAIComponent>().mAIRT == tColliders [i].gameObject && aie.GetComponent <BaseAIComponent>().mAIRT != pEntity.GetComponent <BaseAIComponent>().mAIRT)
                    {
                        tList.Add(aie);
                        break;
                    }
                }
            }
            return(tList.ToArray());
        }
Exemplo n.º 9
0
        // init all array
        public override void Init()
        {
            mStateAnimation = new Dictionary <int, string> ();

            mExiter = new StateExit[25];

            mEnterer = new StateEnter[25];

            mExecuter = new StateExecuter[25];

            mTranfer = new List <TranferNode> [25];

            mStateName = new string[25];

            for (int i = 0; i < 25; i++)
            {
                mTranfer [i] = new List <TranferNode> ();
            }

            mFeedbacker = new List <FeedbackerNode> [25];
            for (int i = 0; i < 25; i++)
            {
                mFeedbacker [i] = new List <FeedbackerNode> ();
            }

            mPowerEdge = new List <PowerNode> [25];
            for (int i = 0; i < 25; i++)
            {
                mPowerEdge [i] = new List <PowerNode> ();
            }

            LastPlayerEntity = new UEntity();

            LastEntityData = new AIEntity();
            LastEntityData.PlayerEntity = LastPlayerEntity;
            if (mUEntity != null)
            {
                LastEntityData.mWorld = this.mUEntity.mWorld;
            }
            IAnyway = (uint)mtempCount;
            mtempCount++;
        }
Exemplo n.º 10
0
 public static void StateExit(AIEntity pSponsor, AIEntity[] pResponses, int pid)
 {
 }
Exemplo n.º 11
0
        public override void Update(UEntity uEntity)
        {
            base.Update(uEntity);
            if (!uEntity.GetComponent <AIStrategy> ().isEnable)
            {
                return;
            }
            AIEntity pEntity = (AIEntity)uEntity;
            // get lod now
            int lod = uEntity.GetComponent <LODComponent> ().mLOD;

            // compute logic update velocity
            lod = lod * lod * lod;
            // update logic with lod
            if (pEntity.GetComponent <AIStrategy> ().timer <= 0.2f * lod)
            {
                pEntity.GetComponent <AIStrategy> ().timer += Time.deltaTime;
                return;
            }

            pEntity.GetComponent <AIStrategy> ().timer = 0.0f;
            // having cache ?
            if (pEntity.GetComponent <AIStrategy> ().IDBuffer != -1)
            {
                if (pEntity.GetComponent <AIStrategy> ().BufferFrame != 0)
                {
                    pEntity.GetComponent <AIStrategy> ().BufferFrame--;
                }
                else
                {
                    pEntity.GetComponent <AIStrategy> ().IDBuffer = -1;
                }
                return;
            }
            //the min value of the strategy action
            float minValue = 0.15f;
            // the max
            actionNode tActionNode1 = new actionNode();

            tActionNode1.action = 0.0f;
            tActionNode1.mid    = -1;
            // the second max
            actionNode tActionNode2 = new actionNode();

            tActionNode2.action = 0.0f;
            tActionNode2.mid    = -1;

            for (int i = 0; i < pEntity.GetComponent <AIStrategy> ().tempCount; i++)
            {
                float tempRate = pEntity.GetComponent <AIStrategy> ().mStrategyActioner [i](pEntity);
                tempRate *= pEntity.GetComponent <AIStrategy> ().mPower [i];
                if (tempRate > tActionNode1.action)
                {
                    tActionNode2.action = tActionNode1.action;
                    tActionNode2.mid    = tActionNode1.mid;
                    tActionNode1.action = tempRate;
                    tActionNode1.mid    = i;
                }
                else if (tempRate > tActionNode2.action)
                {
                    tActionNode2.action = tempRate;
                    tActionNode2.mid    = i;
                }
            }

            if (tActionNode1.action > minValue)
            {
                if (tActionNode1.mid == pEntity.GetComponent <AIStrategy> ().tempID)
                {
                    return;
                }
                // transfer, so compute the last frame data
                if (pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter != 10)
                {
                    float sum = 0.0f;
                    for (int i = 0; i < 10 - pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter; i++)
                    {
                        sum += pEntity.GetComponent <AIStrategy> ().bufferdata [i];
                    }
                    sum /= 10 - pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter;
                    pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] += sum;
                    if (pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] > 3.0f)
                    {
                        pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] = 3.0f;
                    }
                    if (pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] < 0.3f)
                    {
                        pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] = 0.3f;
                    }
                    pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter = 10;
                }
                pEntity.GetComponent <AIStrategy> ().LastID             = pEntity.GetComponent <AIStrategy> ().tempID;
                pEntity.GetComponent <AIStrategy> ().mFrameCaptureStart = true;

                for (int i = 0; i < pEntity.GetComponent <AIState> ().mtempCount; i++)
                {
                    for (int j = 0; j < pEntity.GetComponent <AIStrategy> ().mAIState [pEntity.GetComponent <AIStrategy> ().tempID].mPowerEdge [i].Count; j++)
                    {
                        PowerNode pnt = new PowerNode();
                        pnt.id    = pEntity.GetComponent <AIState> ().mPowerEdge [i] [j].id;
                        pnt.power = pEntity.GetComponent <AIState> ().mPowerEdge [i] [j].power;
                        pEntity.GetComponent <AIStrategy> ().mAIState [pEntity.GetComponent <AIStrategy> ().tempID].mPowerEdge [i] [j] = pnt;
                    }
                }
                // update Strategy
                pEntity.GetComponent <AIStrategy> ().mStrategyExit[pEntity.GetComponent <AIStrategy>().tempID](pEntity);
                pEntity.GetComponent <AIStrategy> ().SetEntry(tActionNode1.mid);
                pEntity.GetComponent <AIStrategy> ().mStrategyEnter[pEntity.GetComponent <AIStrategy>().tempID](pEntity);
                // update cache
                if (tActionNode1.action - tActionNode2.action > 0.3f)
                {
                    pEntity.GetComponent <AIStrategy> ().IDBuffer    = pEntity.GetComponent <AIStrategy> ().tempID;
                    pEntity.GetComponent <AIStrategy> ().BufferFrame = 6;
                }
            }
        }
Exemplo n.º 12
0
 public static void Strategy_Enter(AIEntity pEntity)
 {
     pEntity.GetComponent <ObstacleComponent> ().target = Vector3.zero;
 }
Exemplo n.º 13
0
 public static void Run(AIEntity pEntity)
 {
 }
Exemplo n.º 14
0
        // no using now
        public void InitAvoid(StateExecuter pStateExecuter, StateEnter pStateEnter, StateExit pStateExit, StateRecorder pStateRecorder, AIEntity pLast)
        {
            StrategyActioner AvoidActioner = ObstacleAvoidance.ActionFunc;
            StateExecuter    AvoidState    = ObstacleAvoidance.FSM_Avoid;
            AIState          aiState       = new AIState();

            aiState.Init();
            int id_battle = aiState.AddExecuter(pStateExecuter, pStateExit, pStateEnter);
            int id_avoid  = aiState.AddExecuter(AvoidState, EmptyExitAndEnter.EmptyExit, EmptyExitAndEnter.EmptyEnter);

            aiState.AddAnimation(pStateExecuter, "Attack");
            aiState.AddAnimation(AvoidState, "Walk");
            aiState.tempID = id_avoid;
            StateTranfer tAvoid_Battle = ObstacleAvoidance.FSM_Avoid_Battle;
            StateTranfer tBattle_Avoid = ObstacleAvoidance.FSM_Battle_Avoid;

            aiState.AddEdge(tAvoid_Battle, EmptyFeedbacker.Run, id_avoid, id_battle);
            aiState.AddEdge(tBattle_Avoid, EmptyFeedbacker.Run, id_battle, id_avoid);
            StrategyEnter tAvoidEnter = ObstacleAvoidance.Strategy_Enter;

            aiState.mStateRecorder = pStateRecorder;
            aiState.LastEntityData = pLast;
            AddStrategy(AvoidActioner, tAvoidEnter, EmptyStrategyExit.Run, EmptyStrategyFeedbacker.Run, aiState);
        }
Exemplo n.º 15
0
 public static void EmptyExit(AIEntity pEntity)
 {
 }
Exemplo n.º 16
0
 public static float Run(AIEntity pEntity)
 {
     return(0.0f);
 }
Exemplo n.º 17
0
        /*
         * check all the member neighbor
         * if have members full a list-precompute
         * Group them by the Group Strategy function value
         *
         */

        public bool checkGroup()
        {
            foreach (int i in mGroupListID)
            {
                List <GroupBehaviourNode> gbns = GroupManager.getInstance().getGroupList(i);
                List <int> tempIDs             = new List <int> ();
                bool       isSucceed           = true;
                // list-precompute
                foreach (GroupBehaviourNode gbn in gbns)
                {
                    int tCount = 0;
                    if (mSponsor.tag == gbn.mRoleName)
                    {
                        tCount++;
                    }
                    for (int j = 0; j < memebercount; j++)
                    {
                        if (tCount == gbn.mCount)
                        {
                            break;
                        }
                        if (members [j].mResponse.tag == gbn.mRoleName)
                        {
                            tCount++;
                            tempIDs.Add(j);
                        }
                    }

                    if (tCount < gbn.mCount)
                    {
                        isSucceed = false;
                        break;
                    }
                }
                // having member full the list
                if (isSucceed)
                {
                    GroupStrategyRT mStrategy  = GroupManager.getInstance().Dictionaryforid2Strategy[i];
                    AIEntity[]      pResponses = new AIEntity[tempIDs.Count];
                    for (int j = 0; j < tempIDs.Count; j++)
                    {
                        pResponses [j] = members [tempIDs[j]].mResponse;
                    }

                    // compute the strategy value
                    float rate = mStrategy(mSponsor, pResponses);

                    if (rate * Time.deltaTime > Random.Range(0.0f, 1.0f))
                    {
                        // succeed, then group them

                        tempGroupID  = i;
                        memebercount = tempIDs.Count;
                        ResponseNode[] rn = new ResponseNode[25];
                        for (int j = 0; j < memebercount; j++)
                        {
                            rn [j] = members [tempIDs [j]];
                        }

                        members = rn;

                        for (int j = 0; j < memebercount; j++)
                        {
                            members [j].mSucceedTeam = true;
                            members [j].mLeader      = mSponsor;
                        }

                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 18
0
        public override void Update(UEntity uEntity)
        {
            base.Update(uEntity);
            if (!uEntity.GetComponent <AIGroupState> ().isEnable)
            {
                return;
            }
            AIEntity pLeader = uEntity.GetComponent <AIGroupState> ().pLeader;

            AIEntity[] pMembers = uEntity.GetComponent <AIGroupState> ().pMembers;
            int        pid      = uEntity.GetComponent <AIGroupState> ().tempGroupID;

            // check any

            foreach (GroupStateTransferNode gstn in uEntity.GetComponent <AIGroupState>().mGroupStateAnyTransfers)
            {
                if (pid != 0)
                {
                    break;
                }

                int id = gstn.id;
                if (id == uEntity.GetComponent <AIGroupState> ().tempID)
                {
                    continue;
                }
                // update logic
                GroupStateTransfer tTransfer = gstn.mTransfer;
                float rate = tTransfer(pLeader, pMembers, pid);
                if (rate * Time.deltaTime > Random.Range(0.0f, 1.0f))
                {
                    GroupStateExit tExit = uEntity.GetComponent <AIGroupState>().mGroupStateExits[uEntity.GetComponent <AIGroupState>().tempID];
                    tExit(pLeader, pMembers, pid);
                    uEntity.GetComponent <AIGroupState> ().tempID = id;
                    GroupStateEnter tEnter = uEntity.GetComponent <AIGroupState>().mGroupStateEnters[uEntity.GetComponent <AIGroupState>().tempID];
                    tEnter(pLeader, pMembers, pid);
                    GroupStateRT ttRT = uEntity.GetComponent <AIGroupState> ().mGroupStateRTs [uEntity.GetComponent <AIGroupState> ().tempID];
                    ttRT(pLeader, pMembers, pid);
                    GroupAnimationRT ttName  = uEntity.GetComponent <AIGroupState>().mAnimationDic[uEntity.GetComponent <AIGroupState> ().tempID];
                    string           ttName_ = ttName(uEntity.GetComponent <AIGroupState>().tempGroupID);
                    uEntity.GetComponent <AIAnimation> ().mtempAnim = ttName_;
                    // async data by leader
                    for (int i = 0; i < pMembers.Length; i++)
                    {
                        GroupStateExit tExit_ = uEntity.GetComponent <AIGroupState>().mGroupStateExits[uEntity.GetComponent <AIGroupState>().tempID];
                        int            pid_   = pMembers [i].GetComponent <AIGroupState> ().tempGroupID;
                        tExit(pLeader, pMembers, pid_);
                        pMembers [i].GetComponent <AIGroupState> ().tempID = id;
                        GroupStateEnter tEnter_ = uEntity.GetComponent <AIGroupState>().mGroupStateEnters[uEntity.GetComponent <AIGroupState>().tempID];
                        tEnter_(pLeader, pMembers, pid_);
                        GroupStateRT ttRT_ = uEntity.GetComponent <AIGroupState> ().mGroupStateRTs [uEntity.GetComponent <AIGroupState> ().tempID];
                        ttRT_(pLeader, pMembers, pid_);
                        GroupAnimationRT ttName__  = uEntity.GetComponent <AIGroupState>().mAnimationDic[uEntity.GetComponent <AIGroupState> ().tempID];
                        string           ttName___ = ttName__(pid_);
                        uEntity.GetComponent <AIAnimation> ().mtempAnim = ttName___;
                    }

                    return;
                }
            }

            // check relate

            foreach (GroupStateTransferNode gstn in uEntity.GetComponent <AIGroupState>().mGroupStateTransfers[uEntity.GetComponent <AIGroupState>().tempID])
            {
                if (pid != 0)
                {
                    break;
                }

                int id = gstn.id;
                GroupStateTransfer tTransfer = gstn.mTransfer;
                float rate = tTransfer(pLeader, pMembers, pid);

                if (rate * Time.deltaTime > Random.Range(0.0f, 1.0f))
                {
                    GroupStateExit tExit = uEntity.GetComponent <AIGroupState>().mGroupStateExits[uEntity.GetComponent <AIGroupState>().tempID];
                    tExit(pLeader, pMembers, pid);
                    uEntity.GetComponent <AIGroupState> ().tempID = id;
                    GroupStateEnter tEnter = uEntity.GetComponent <AIGroupState>().mGroupStateEnters[uEntity.GetComponent <AIGroupState>().tempID];
                    tEnter(pLeader, pMembers, pid);
                    // async data by leader
                    for (int i = 0; i < pMembers.Length; i++)
                    {
                        GroupStateExit tExit_ = uEntity.GetComponent <AIGroupState>().mGroupStateExits[uEntity.GetComponent <AIGroupState>().tempID];
                        int            pid_   = pMembers [i].GetComponent <AIGroupState> ().tempGroupID;
                        tExit(pLeader, pMembers, pid_);
                        pMembers [i].GetComponent <AIGroupState> ().tempID = id;
                        GroupStateEnter tEnter_ = uEntity.GetComponent <AIGroupState>().mGroupStateEnters[uEntity.GetComponent <AIGroupState>().tempID];
                        tEnter_(pLeader, pMembers, pid_);
                    }

                    break;
                }
            }
            // run the Group State node function
            GroupStateRT tRT = uEntity.GetComponent <AIGroupState> ().mGroupStateRTs [uEntity.GetComponent <AIGroupState> ().tempID];

            tRT(pLeader, pMembers, pid);
            GroupAnimationRT tNameRT = uEntity.GetComponent <AIGroupState>().mAnimationDic[uEntity.GetComponent <AIGroupState> ().tempID];
            string           tName   = tNameRT(uEntity.GetComponent <AIGroupState>().tempGroupID);

            uEntity.GetComponent <AIAnimation> ().mtempAnim = tName;
        }
Exemplo n.º 19
0
        public override void Update(UEntity uEntity)
        {
            base.Update(uEntity);
            // clear responsor data
            for (int i = 0; i < uEntity.GetComponent <GroupManager> ().mResponseCount; i++)
            {
                if (!uEntity.GetComponent <GroupManager> ().mResponses [i].mSucceedTeam)
                {
                    uEntity.GetComponent <GroupManager> ().mResponses [i].mLeader = null;
                }
            }


            for (int i = 0; i < uEntity.GetComponent <GroupManager> ().mSponsorCount; i++)
            {
                // sponsor having grouping
                if (uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.isGrouping)
                {
                    if (uEntity.GetComponent <GroupManager> ().mSponsors [i].mDissloveTimer < 1.0f)
                    {
                        uEntity.GetComponent <GroupManager> ().mSponsors [i].mDissloveTimer += Time.deltaTime;
                    }
                    else
                    {
                        //Debug.Log (uEntity.GetComponent<GroupManager> ().mSponsors [i].tempGroupID+" "+i);
                        // check dissolve
                        GroupDissolve tDissolve = uEntity.GetComponent <GroupManager> ().Dictionaryforid2Dissolve [uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID];
                        AIEntity[]    pEntitys  = new AIEntity[uEntity.GetComponent <GroupManager> ().mSponsors[i].memebercount];
                        for (int j = 0; j < uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount; j++)
                        {
                            pEntitys [j] = uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse;
                        }
                        float             rate  = tDissolve(uEntity.GetComponent <GroupManager>().mSponsors[i].mSponsor, pEntitys);
                        GroupStrategyExit tExit = uEntity.GetComponent <GroupManager> ().Dictionaryforid2StrategyExit [uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID];
                        if (Random.Range(0.0f, 1.0f) < rate)
                        {
                            // dissolve
                            for (int j = 0; j < uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount; j++)
                            {
                                uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.isGrouping = false;
                                uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mSucceedTeam         = false;
                                uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mLeader  = null;
                                uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mGroupID = -1;
                                uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.mDissloveTimer = 10.0f;
                            }
                            uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount        = 0;
                            uEntity.GetComponent <GroupManager> ().mSponsors [i].mDissloveTimer      = 0.0f;
                            uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.isGrouping = false;
                            uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID         = -1;
                            tExit(uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor, pEntitys);
                        }
                        uEntity.GetComponent <GroupManager> ().mSponsors [i].mDissloveTimer = 0.0f;
                    }
                }
                else
                {
                    uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount = 0;
                                        #if DEBUG
                    AIEntity[] mEntity = AIEntity.getAllEntityWithSphere(uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor, uEntity.GetComponent <GroupManager> ().mCheckDistance);
                                        #else
                    AIEntity[] mEntity = AIEntity.getAllEntityWithSphere(uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor, 10.0f);
                                        #endif

                    List <ResponseNode> mResponseList = new List <ResponseNode> ();


                    // get real responsor neighbor sponsor

                    for (int j = 0; j < mEntity.Length; j++)
                    {
                        if (mEntity [j].mDissloveTimer > 0.0f)
                        {
                            continue;
                        }
                        for (int k = 0; k < uEntity.GetComponent <GroupManager>().mResponseCount; k++)
                        {
                            ResponseNode rn = uEntity.GetComponent <GroupManager> ().mResponses [k];

                            if (rn.mResponse == mEntity [j] && rn.mLeader == null)
                            {
                                mResponseList.Add(rn);
                                break;
                            }
                        }
                    }

                    // responsor count

                    int count = Mathf.Min(mResponseList.Count, uEntity.GetComponent <GroupManager>().mSponsors[i].members.Length);
                    //	Debug.Log (count);
                    // init
                    for (int j = 0; j < count; j++)
                    {
                        uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j] = mResponseList [j];
                        //uEntity.GetComponent<GroupManager> ().mSponsors [i].members [j].mLeader = uEntity.GetComponent<GroupManager> ().mSponsors [i].mSponsor;
                    }

                    uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount = count;
                    // check Group
                    if (uEntity.GetComponent <GroupManager> ().mSponsors [i].checkGroup())
                    {
                        /*
                         * for (int j = 0; j < count; j++)
                         * {
                         *      uEntity.GetComponent<GroupManager> ().mSponsors [i].members [j].mLeader = uEntity.GetComponent<GroupManager> ().mSponsors [i].mSponsor;
                         * }
                         */
                        // enter group
                        GroupStrategyEnter tEnter   = uEntity.GetComponent <GroupManager> ().Dictionaryforid2StrategyEnter [uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID];
                        GroupAllocation    tAlloc   = uEntity.GetComponent <GroupManager> ().Dictionaryforid2Allocation [uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID];
                        AIEntity[]         pEntitys = new AIEntity[uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount];
                        for (int j = 0; j < uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount; j++)
                        {
                            pEntitys [j] = uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse;
                        }
                        // enter function
                        tEnter(uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor, pEntitys);
                        // alloc function
                        int[] ids = tAlloc(uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor, pEntitys);
                        // init sponsor
                        uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.isGrouping = true;
                        uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.GetComponent <AIGroupState> ().tempGroupID = 0;
                        EntityStrategyNode esn = new EntityStrategyNode();
                        esn.id      = uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID;
                        esn.tagName = uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.tag;
                        // AIGroupState temp
                        AIGroupState mStateRT = uEntity.GetComponent <GroupManager> ().DictionaryforGroupState [esn];

                        uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.GetComponent <AIGroupState> ().pLeader  = uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor;
                        uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.GetComponent <AIGroupState> ().pMembers = pEntitys;
                        uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.GetComponent <AIGroupState> ().SimpleClone(mStateRT);
                        for (int j = 0; j < uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount; j++)
                        {
                            // init Responsor
                            uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mGroupID             = ids [j];
                            uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.isGrouping = true;
                            uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.GetComponent <AIGroupState> ().tempGroupID = ids [j];
                            EntityStrategyNode esn1 = new EntityStrategyNode();
                            esn1.id      = uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID;
                            esn1.tagName = uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.tag;
                            AIGroupState mStateRT1 = uEntity.GetComponent <GroupManager> ().DictionaryforGroupState [esn1];
                            uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.GetComponent <AIGroupState> ().pLeader  = uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor;
                            uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.GetComponent <AIGroupState> ().pMembers = pEntitys;
                            uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.GetComponent <AIGroupState> ().SimpleClone(mStateRT1);
                        }
                    }
                }
            }
        }
Exemplo n.º 20
0
 public static void StrategyExit(AIEntity pSponsor, AIEntity[] pResponses)
 {
 }
Exemplo n.º 21
0
 public static void EmptyEnter(AIEntity pEntity)
 {
 }
Exemplo n.º 22
0
 public static float Run(AIEntity pEntity, bool isNow)
 {
     return(0.0f);
 }
Exemplo n.º 23
0
 public void Destroy()
 {
     AIEntity.getList().Remove(this);
     GameObject.Destroy(mAI);
     Release();
 }