Example #1
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);
        }
Example #2
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);
                        }
                    }
                }
            }
        }