protected override void InitBrain() { if (Prowling) { fBrain = new BeastBrain(this); return; } Brain = new LeaderBrain(this); }
public override void Execute() { NWCreature self = (NWCreature)Self; BeastBrain beastBrain = (BeastBrain)Brain; int min = beastBrain.fNearKinsfolkDist; CreatureEntity nearKinsfolk = beastBrain.fNearKinsfolk; int cohX = 0; int cohY = 0; int algX = 0; int algY = 0; int cnt = beastBrain.Kinsfolks.Count; for (int i = 0; i < cnt; i++) { NWCreature cr = beastBrain.Kinsfolks[i]; int dir = cr.LastDir; cohX += cr.PosX; cohY += cr.PosY; algX += Directions.Data[dir].DX; algY += Directions.Data[dir].DY; } int dX = 0; int dY = 0; if (cnt > 0) { dX = (dX + (int)Math.Round(algX / (float)cnt)); dY = (dY + (int)Math.Round(algY / (float)cnt)); } if (cnt > 0) { cohX = (int)Math.Round(cohX / (float)cnt); cohY = (int)Math.Round(cohY / (float)cnt); int dir = Directions.GetDirByCoords(self.PosX, self.PosY, cohX, cohY); dX += Directions.Data[dir].DX; dY += Directions.Data[dir].DY; } if (min <= 3 && nearKinsfolk != null) { if (nearKinsfolk.PosX > self.PosX) { dX--; } if (nearKinsfolk.PosX < self.PosX) { dX++; } if (nearKinsfolk.PosY > self.PosY) { dY--; } if (nearKinsfolk.PosY < self.PosY) { dY++; } } ExtPoint newPos = new ExtPoint(); newPos.X = self.PosX + dX; newPos.Y = self.PosY + dY; ExtPoint next = self.GetStep(newPos); if (!next.IsEmpty) { Brain.StepTo(next.X, next.Y); } }