예제 #1
0
        ///<param name="IsAnimPr">Нужно ли искать путь вместе с животными</param>
        private void ThinkNew(bool IsAnimPr = false)
        {
            LookEventArgs Mlook = new LookEventArgs();

            if (PartEnem(Mlook))
            {
                return;
            }
            SearchWayEventArgs Way = new SearchWayEventArgs()
            {
                IsAnimPr = IsAnimPr
            };

            if (PartEat(Mlook, Way))
            {
                return;
            }
            if (PartIdle())
            {
                return;
            }
            if (State == AnimState.Zero)
            {
                DoAvAct(Rstate.Disarray, new List <Pos>());
                ActRest(2);
            }
        }
예제 #2
0
        private bool PartEat(LookEventArgs Mlook, SearchWayEventArgs Way)
        {
            if (Hunger.Hung > Hunger.MaxHung * 0.8)
            {
                return(false);
            }
            if (Mlook.Envirs == null)
            {
                Mlook.MustLkEnv = true; Mlook.MustLkAnm = false;
                Mlook.radius    = RadSee.Item2;
                Mlook.Queier    = QuerEat;
                QActLook(Mlook);
            }
            float min; uint index;

            for (int iter = 0; iter < 5; iter++)
            {
                index = 0;
                min   = float.MaxValue;                          //Раскидываем по приоритету.
                for (ushort i = 0; i < Mlook.Envirs.Lenght; i++) //проверяем все окружающие Envir
                {
                    if (Mlook.Esort[i].Item1 < min && Mlook.Esort[i].Item2 == false)
                    {
                        index = i;
                        min   = Mlook.Esort[i].Item1;
                    }
                }
                if (min != float.MaxValue)
                {
                    Mlook.Esort[index].Item2 = true;
                    if (Pos.PosNear(Location, Mlook.Envirs[index].Location))
                    {
                        ActEat(Mlook.Envirs[index].Location);
                        DoAvAct(Rstate.GoEat, new List <Pos>());
                        return(true);
                    }
                    Way.TPos     = (Mlook.Envirs[index]).Location;
                    Way.StayNear = true;
                    QActSearchWay(Way);//Console.Write("1");
                    if (Way.CanGo == true)
                    {
                        DoAvAct(Rstate.GoEat, Way.MGoPos, true);
                        if (Targ.Count != 0)
                        {
                            ActGo(new GoEventArgs()
                            {
                                CurPos  = Location,
                                TargPos = Targ[Targ.Count - 1],   //не должно быть 0 элементов
                            });
                        }
                        return(true);//мы уже всё решили и выходим
                    }
                }
                else
                {
                    return(false);// всё просмотрели
                }
            }
            return(false);
        }
예제 #3
0
        private bool PartEnem(LookEventArgs Mlook)
        {
            if (Mlook.Animals == null)
            {
                Mlook.MustLkAnm = true; Mlook.MustLkEnv = false;
                Mlook.radius    = RadSee.Item2;
                Mlook.Queier    = delegate(Actor Act, float l) { if (Act is Wolf)
                                                                 {
                                                                     return(l, true);
                                                                 }
                                                                 else
                                                                 {
                                                                     return(100, false);
                                                                 } };
                QActLook(Mlook);
            }
            for (ushort i = 0; i < Mlook.Animals.Lenght; i++)
            {
                if (Mlook.Animals[i] is Wolf)    //go away!
                {
                    Pos   GAtarg   = Location - Mlook.Animals[i].Location;
                    Pos   RTarg    = GAtarg;
                    float minangle = float.MaxValue;
                    for (byte j = 0; j <= 7; j++)
                    {
                        Cell  Mcell = QActGetCell(Location + Pos.GetDirPos((Direction)j));
                        float angle = (float)Math.Abs(Vector.AngleBetween(new Vector(GAtarg.X, GAtarg.Y), new Vector(Pos.GetDirPos((Direction)j).X, Pos.GetDirPos((Direction)j).Y)));
                        if (this.GetCanPlace(Mcell.ID, Mcell.LEnvir) && Mcell.LAnimal == null &&
                            angle < minangle)
                        {
                            RTarg    = Pos.GetDirPos((Direction)j);
                            minangle = angle;
                        }
                    }

                    if (minangle < float.MaxValue)
                    {
                        DoAvAct(Rstate.GoAway, new List <Pos>());
                        ActGo(new GoEventArgs()
                        {
                            CurPos  = Location,
                            TargPos = Location + RTarg,
                        });
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }


                    //Console.WriteLine("Go Away!");
                    ////  ActRest(2);
                    //return true;
                }
            }
            return(false);
        }
예제 #4
0
        private bool ThinkMed()
        {
            LookEventArgs      Mlook = new LookEventArgs();
            SearchWayEventArgs Way   = new SearchWayEventArgs();

            if (PartEat(Mlook, Way))
            {
                return(false);
            }

            return(true);
        }
예제 #5
0
        public void LookAnimal(object sender, LookEventArgs e)
        {
            Animal       send    = sender as Animal;
            const ushort massize = 30;
            //  e.Sender.Location.
            Pos   ChCoord = new Pos(send.Location.X / 16, send.Location.Y / 16);
            int   ChRad   = e.radius / 16 + 1;
            Pos   Loc     = send.Location;
            float lenght;

            if (e.MustLkAnm)    // если он нужен
            {
                e.Animals = new Vector <Animal>(massize);
                e.Asort   = new (float, bool)[massize];
예제 #6
0
        private bool PartAttack(LookEventArgs Mlook, SearchWayEventArgs Way)
        {
            Mlook.MustLkAnm = true;
            Mlook.radius    = RadSee.Item2;
            Mlook.Queier    = QuerAttack;
            QActLook(Mlook);
            float min; uint index;

            for (int iter = 0; iter < 5; iter++)
            {
                index = 0;
                min   = float.MaxValue;                                              //Раскидываем по приоритету.
                for (ushort i = 0; i < Mlook.Animals.Lenght; i++)                    //проверяем все окружающие Envir
                {
                    if (Mlook.Asort[i].Item1 < min && Mlook.Asort[i].Item2 == false) //добавлять доп.условие что это еда
                    {
                        index = i;
                        min   = Mlook.Asort[i].Item1;
                    }
                }
                if (min != float.MaxValue)
                {
                    Mlook.Asort[index].Item2 = true;
                    if (Pos.PosNear(Location, Mlook.Animals[index].Location))
                    {
                        ActAttack(Mlook.Animals[index]);
                        DoAvAct(WolfState.GoAttack, new List <Pos>());
                        return(true);
                    }
                    Way.TPos     = (Mlook.Animals[index]).Location;
                    Way.StayNear = true;
                    QActSearchWay(Way);
                    if (Way.CanGo == true)
                    {
                        DoAvAct(WolfState.GoAttack, new List <Pos>());
                        ActGo(new GoEventArgs()
                        {
                            CurPos  = Location,
                            TargPos = Way.MGoPos.Last(), //не должно быть 0 элементов
                        });
                        return(true);                    //мы уже всё решили и выходим
                    }
                }
                else
                {
                    return(false);// всё просмотрели
                }
            }
            return(false);
        }
예제 #7
0
        private bool ThinkMed()  //возвращает true,если надо дальше двигаться к цели
        {
            LookEventArgs Mlook = new LookEventArgs();

            if (PartEnem(Mlook))
            {
                return(false);
            }

            if (AvState == Rstate.GoEat)
            {
                Cell c = QActGetCell(Targ[0]);
                if (c.LEnvir != null && QuerEat(c.LEnvir, 1).Item2)
                {
                    Console.WriteLine("Иди дальше");
                    return(true);// можешь идти дальше
                }
                else
                {
                    DoAvAct(Rstate.Zero, new List <Pos>());
                    return(false);
                }
            }
            else if (AvState == Rstate.GoGulyat)
            {
                SearchWayEventArgs Way = new SearchWayEventArgs()
                {
                    IsAnimPr = false
                };
                if (PartEat(Mlook, Way))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #8
0
        private bool PartEat(LookEventArgs Mlook, SearchWayEventArgs Way)
        {
            if (Hunger.Hung > Hunger.MaxHung * 0.8)
            {
                return(false);
            }
            Mlook.MustLkAnm = true;
            Mlook.radius    = RadSee.Item2;
            Mlook.Queier    = QuerEat;
            QActLook(Mlook);
            float min; uint index;

            for (int iter = 0; iter < 3; iter++)
            {
                index = 0;
                min   = float.MaxValue;                                              //Раскидываем по приоритету.
                for (ushort i = 0; i < Mlook.Animals.Lenght; i++)                    //проверяем нужное окружение
                {
                    if (Mlook.Asort[i].Item1 < min && Mlook.Asort[i].Item2 == false) //добавлять доп.условие что это еда
                    {
                        index = i;
                        min   = Mlook.Asort[i].Item1;
                    }
                }
                if (min != float.MaxValue)
                {
                    Mlook.Asort[index].Item2 = true;
                    if (Pos.PosNear(Location, Mlook.Animals[index].Location))
                    {
                        if ((Mlook.Animals[index] as IEatable).FoodRec > 0)
                        {
                            ActEat(Mlook.Animals[index].Location);
                            DoAvAct(WolfState.GoEat, new List <Pos>());
                            return(true);
                        }
                    }
                    Way.TPos     = (Mlook.Animals[index]).Location;
                    Way.StayNear = true;
                    QActSearchWay(Way);

                    if (Way.CanGo == true)
                    {
                        DoAvAct(WolfState.GoEat, Way.MGoPos, true);
                        if (Targ.Count != 0)
                        {
                            ActGo(new GoEventArgs()
                            {
                                CurPos  = Location,
                                TargPos = Targ[Targ.Count - 1],   //не должно быть 0 элементов
                            });
                        }
                        return(true);//мы уже всё решили и выходим
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }