Esempio n. 1
0
        public void SimpleClone(AIGroupState pGroupState)
        {
            Dictionary <int, GroupAnimationRT> mdic = new Dictionary <int, GroupAnimationRT> ();

            foreach (var item in pGroupState.mAnimationDic)
            {
                int ti = item.Key;
                GroupAnimationRT ts = item.Value;
                mdic.Add(ti, ts);
            }
            mAnimationDic   = mdic;
            GroupStateCount = pGroupState.GroupStateCount;
            for (int i = 0; i < GroupStateCount; i++)
            {
                mGroupStateEnters [i] = pGroupState.mGroupStateEnters [i];
                mGroupStateExits [i]  = pGroupState.mGroupStateExits [i];
                mGroupStateRTs [i]    = pGroupState.mGroupStateRTs [i];
            }
            for (int i = 0; i < 30; i++)
            {
                mGroupStateTransfers [i].Clear();
                for (int j = 0; j < pGroupState.mGroupStateTransfers [i].Count; j++)
                {
                    mGroupStateTransfers [i].Add(pGroupState.mGroupStateTransfers[i][j]);
                }
                //Debug.Log (mGroupStateTransfers[i].Count);
            }
            tempID = pGroupState.tempID;
            mGroupStateEnters [tempID] (pLeader, pMembers, tempGroupID);
        }
Esempio n. 2
0
        // add a strategy
        public void AddStrategy(string tag, int id, AIGroupState pStateRT)
        {
            EntityStrategyNode esn = new EntityStrategyNode();

            esn.tagName = tag;
            esn.id      = id;
            DictionaryforGroupState.Add(esn, pStateRT);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
                        }
                    }
                }
            }
        }