Пример #1
0
        private void PrepareFlock()
        {
            try {
                IsLeader = true;
                Kinsfolks.Clear();

                NWCreature self = (NWCreature)fSelf;
                NWField    fld  = self.CurrentField;

                fNearKinsfolk     = null;
                fNearKinsfolkDist = AuxUtils.MaxInt;

                int num = fld.Creatures.Count;
                for (int i = 0; i < num; i++)
                {
                    NWCreature cr   = fld.Creatures.GetItem(i);
                    int        dist = MathHelper.Distance(cr.Location, self.Location);
                    if (!cr.Equals(self) && dist <= self.Survey && cr.CLSID == self.CLSID && fld.LineOfSight(self.PosX, self.PosY, cr.PosX, cr.PosY))
                    {
                        Kinsfolks.Add(cr);
                        if (fNearKinsfolkDist > dist)
                        {
                            fNearKinsfolkDist = dist;
                            fNearKinsfolk     = cr;
                        }
                        IsLeader = (IsLeader && self.Leadership > cr.Leadership);
                    }
                }

                if (FindGoalByKind(GoalKind.gk_Flock) == null)
                {
                    GoalEntity goal = CreateGoal(GoalKind.gk_Flock);
                    goal.Duration = 25;
                }
            } catch (Exception ex) {
                Logger.Write("BeastBrain.prepareFlock(): " + ex.Message);
            }
        }