/* * 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); }
public override void Init() { base.Init(); this.AddComponent <GroupManager> (GroupManager.getInstance()); }