Esempio n. 1
0
        //Определяет текущее состояние конвоя
        private void SetState(MyAI _player)
        {
            //Проверка, живы ли боты
            if (MyDefender != null && MyDefender.HitPoint <= 0)
            {
                MyDefender = null;
            }
            if (MyContainer[0] != null && MyContainer[0].HitPoint <= 0)
            {
                MyContainer[0] = null;
            }
            if (MyContainer[1] != null && MyContainer[1].HitPoint <= 0)
            {
                MyContainer[1] = null;
            }

            //Если ботов нет, то конвой уничтожен
            if (MyDefender == null && MyContainer[0] == null && MyContainer[1] == null)
            {
                this.State            = ConvoyState.UnderConstruction;
                this.MyDefender       = null;
                this.MyContainer[0]   = null;
                this.MyContainer[1]   = null;
                this.DefendersNumber  = 0;
                this.ContainersNumber = 0;
                this.HPNumber         = -1;
                return;
            }

            //Обновляем данные для Stock и Location
            this.Stock = 0;
            if (MyDefender != null)
            {
                this.Location = MyDefender.Location;
            }
            if (MyContainer[0] != null)
            {
                this.Location = MyContainer[0].Location;
                this.Stock   += MyContainer[0].Stock;
            }
            if (MyContainer[1] != null)
            {
                this.Location = MyContainer[1].Location;
                this.Stock   += MyContainer[1].Stock;
            }

            //Если HP не определён, то определяем
            if (this.HPNumber == -1)
            {
                //this.HPoint = _player.GetNearestHPForConvoy(this.Location, ref HPNumber);
                this.HPoint = _player.GetNextHPForConvoy(this.Location, ref this.HPNumber);
            }

            //Если HP занят противником или заполнен, запрашиваем новый
            if (HPNumber >= 0)
            {
                if ((_player.HoshimiPoints[HPNumber].Needle == 2) || (_player.HoshimiPoints[HPNumber].Full == 1))
                {
                    //this.HPoint = _player.GetNearestHPForConvoy(this.Location, ref HPNumber);
                    this.HPoint = _player.GetNextHPForConvoy(this.Location, ref this.HPNumber);
                    this.Stop();
                }
            }

            //Если Defender в бою, то значит и конвой в бою
            if (MyDefender != null && MyDefender.State == NanoBotState.Defending)
            {
                this.State = ConvoyState.Fighting;
                return;
            }

            //Долгие-долгие извращения из-за того, что неясно, кто жив, а кто deadlink
            if (MyDefender != null)
            {
                if (MyContainer[0] != null && MyContainer[1] != null)
                {
                    if ((MyDefender.State == NanoBotState.WaitingOrders) &&
                        (MyContainer[0].State == NanoBotState.WaitingOrders) &&
                        (MyContainer[1].State == NanoBotState.WaitingOrders))
                    {
                        this.State = ConvoyState.Waiting;
                    }
                    if ((MyDefender.State == NanoBotState.Moving) ||
                        (MyContainer[0].State == NanoBotState.Moving) ||
                        (MyContainer[1].State == NanoBotState.Moving))
                    {
                        this.State = ConvoyState.Moving;
                    }
                    if ((MyContainer[0].State == NanoBotState.Collecting) ||
                        (MyContainer[1].State == NanoBotState.Collecting))
                    {
                        this.State = ConvoyState.CollectingAZN;
                    }
                    if ((MyContainer[0].State == NanoBotState.TransferingStock) ||
                        (MyContainer[1].State == NanoBotState.TransferingStock))
                    {
                        this.State = ConvoyState.TransferingAZN;
                    }
                }
                else if (MyContainer[0] != null && MyContainer[1] == null)
                {
                    if ((MyDefender.State == NanoBotState.WaitingOrders) &&
                        (MyContainer[0].State == NanoBotState.WaitingOrders))
                    {
                        this.State = ConvoyState.Waiting;
                    }
                    if ((MyDefender.State == NanoBotState.Moving) ||
                        (MyContainer[0].State == NanoBotState.Moving))
                    {
                        this.State = ConvoyState.Moving;
                    }
                    if (MyContainer[0].State == NanoBotState.Collecting)
                    {
                        this.State = ConvoyState.CollectingAZN;
                    }
                    if (MyContainer[0].State == NanoBotState.TransferingStock)
                    {
                        this.State = ConvoyState.TransferingAZN;
                    }
                }
                else if (MyContainer[0] == null && MyContainer[1] != null)
                {
                    if ((MyDefender.State == NanoBotState.WaitingOrders) &&
                        (MyContainer[1].State == NanoBotState.WaitingOrders))
                    {
                        this.State = ConvoyState.Waiting;
                    }
                    if ((MyDefender.State == NanoBotState.Moving) ||
                        (MyContainer[1].State == NanoBotState.Moving))
                    {
                        this.State = ConvoyState.Moving;
                    }
                    if (MyContainer[1].State == NanoBotState.Collecting)
                    {
                        this.State = ConvoyState.CollectingAZN;
                    }
                    if (MyContainer[1].State == NanoBotState.TransferingStock)
                    {
                        this.State = ConvoyState.TransferingAZN;
                    }
                }
                else if (MyContainer[0] == null && MyContainer[1] == null)
                {
                    if (MyDefender.State == NanoBotState.WaitingOrders)
                    {
                        this.State = ConvoyState.Waiting;
                    }
                    if (MyDefender.State == NanoBotState.Moving)
                    {
                        this.State = ConvoyState.Moving;
                    }
                }
            }
            else
            {
                if (MyContainer[0] != null && MyContainer[1] != null)
                {
                    if ((MyContainer[0].State == NanoBotState.WaitingOrders) &&
                        (MyContainer[1].State == NanoBotState.WaitingOrders))
                    {
                        this.State = ConvoyState.Waiting;
                    }
                    if ((MyContainer[0].State == NanoBotState.Moving) ||
                        (MyContainer[1].State == NanoBotState.Moving))
                    {
                        this.State = ConvoyState.Moving;
                    }
                    if ((MyContainer[0].State == NanoBotState.Collecting) ||
                        (MyContainer[1].State == NanoBotState.Collecting))
                    {
                        this.State = ConvoyState.CollectingAZN;
                    }
                    if ((MyContainer[0].State == NanoBotState.TransferingStock) ||
                        (MyContainer[1].State == NanoBotState.TransferingStock))
                    {
                        this.State = ConvoyState.TransferingAZN;
                    }
                }
                else if (MyContainer[0] != null && MyContainer[1] == null)
                {
                    if (MyContainer[0].State == NanoBotState.WaitingOrders)
                    {
                        this.State = ConvoyState.Waiting;
                    }
                    if (MyContainer[0].State == NanoBotState.Moving)
                    {
                        this.State = ConvoyState.Moving;
                    }
                    if (MyContainer[0].State == NanoBotState.Collecting)
                    {
                        this.State = ConvoyState.CollectingAZN;
                    }
                    if (MyContainer[0].State == NanoBotState.TransferingStock)
                    {
                        this.State = ConvoyState.TransferingAZN;
                    }
                }
                else if (MyContainer[0] == null && MyContainer[1] != null)
                {
                    if (MyContainer[1].State == NanoBotState.WaitingOrders)
                    {
                        this.State = ConvoyState.Waiting;
                    }
                    if (MyContainer[1].State == NanoBotState.Moving)
                    {
                        this.State = ConvoyState.Moving;
                    }
                    if (MyContainer[1].State == NanoBotState.Collecting)
                    {
                        this.State = ConvoyState.CollectingAZN;
                    }
                    if (MyContainer[1].State == NanoBotState.TransferingStock)
                    {
                        this.State = ConvoyState.TransferingAZN;
                    }
                }
                else if (MyContainer[0] == null && MyContainer[1] == null)
                {
                    this.State            = ConvoyState.UnderConstruction;
                    this.MyDefender       = null;
                    this.MyContainer[0]   = null;
                    this.MyContainer[1]   = null;
                    this.ContainersNumber = 0;
                    this.DefendersNumber  = 0;
                    this.HPNumber         = -1;
                }
            }
        }
Esempio n. 2
0
        //Основная функция. Управляет всеми движениями конвоя
        public void Action(MyAI _player)
        {
            double Distance;
            double MinDistance;
            Point  ShootAt = new Point();

            //Если конвоя ещё нет, то и делать нечего
            if (State == ConvoyState.UnderConstruction)
            {
                return;
            }

            //Устанавливаем все значения: State, Location, Stock, etc
            SetState(_player);

            //Если боец жив, проверяем наличие противников
            if (MyDefender != null)
            {
                //Если в пределах досягаемости кто-то есть, останавливаем конвой
                if (_player.OtherNanoBotsInfo != null)
                {
                    foreach (NanoBotInfo botEnemy in _player.OtherNanoBotsInfo)
                    {
                        if (botEnemy.PlayerID == 0)
                        {
                            Distance = _player.GeomDist(botEnemy.Location, MyDefender.Location);
                            if (Distance < MyDefender.DefenseDistance)
                            {
                                this.Stop();
                            }
                        }
                    }
                }
                //Если конвой стоит
                if (this.State == ConvoyState.Waiting)
                {
                    //Ищем ближайшую цель
                    MinDistance = 1000;
                    if (_player.OtherNanoBotsInfo != null)
                    {
                        foreach (NanoBotInfo botEnemy in _player.OtherNanoBotsInfo)
                        {
                            if (botEnemy.PlayerID == 0)
                            {
                                Distance = _player.GeomDist(botEnemy.Location, MyDefender.Location);
                                if ((botEnemy.NanoBotType == NanoBotType.NanoAI) && (Distance < MyDefender.DefenseDistance))
                                {
                                    MinDistance = -1;
                                    ShootAt     = botEnemy.Location;
                                }
                                if (Distance < MinDistance)
                                {
                                    MinDistance = Distance;
                                    ShootAt     = botEnemy.Location;
                                }
                            }
                        }
                    }
                    //Если она достаточно близко, стреляем и завершаем действия
                    if (MinDistance < MyDefender.DefenseDistance)
                    {
                        MyDefender.DefendTo(ShootAt, 4);
                        return;
                    }
                }
            }

            //Если конвой стоит
            if (State == ConvoyState.Waiting)
            {
                //Если мы не в куче, то собираемся в неё самую
                if (this.NeedGathering())
                {
                    this.Gather(_player);
                    return;
                }

                //Если мы на AZNPoint
                if (this.Location == this.APoint)
                {
                    //Если контейнеры пустые, то заполняем их
                    if (this.Stock == 0)
                    {
                        this.FillContainers();
                        return;
                    }
                    //Если не пустые, то идём к HoshimiPoint
                    else
                    {
                        if (this.Location == this.HPoint)
                        {
                            return;
                        }
                        this.Path = _player.Pathfinder.FindPath(this.Location, this.HPoint);
                        this.Move();
                        return;
                    }
                }

                //Если мы на HoshimiPoint
                if (this.Location == this.HPoint)
                {
                    //Если это валидный HP, то проверяем, наш ли он
                    if (HPNumber >= 0)
                    {
                        //Если нет, то переключаемся на новый
                        if (_player.HoshimiPoints[HPNumber].Needle == 2)
                        {
                            //this.HPoint = _player.GetNearestHPForConvoy(this.Location, ref this.HPNumber);
                            this.HPoint = _player.GetNextHPForConvoy(this.Location, ref this.HPNumber);
                            //Если пустые, то идём за AZN
                            if (this.Stock == 0)
                            {
                                this.APoint = _player.GetNearestAZNPoint(this.Location, this.HPoint);
                                this.Path   = _player.Pathfinder.FindPath(this.Location, this.APoint);
                                this.Move();
                                return;
                            }
                            //Иначе сразу к HP
                            else
                            {
                                if (this.Location == this.HPoint)
                                {
                                    return;
                                }
                                this.Path = _player.Pathfinder.FindPath(this.Location, this.HPoint);
                                this.Move();
                                return;
                            }
                        }
                    }
                    //Проверяем все Needle`ы
                    foreach (NanoBot bot in _player.NanoBots)
                    {
                        //Если находим Needle на этой точке и он полный
                        if ((bot is Needle) && (bot.Stock == bot.ContainerCapacity) && (bot.Location == this.Location))
                        {
                            if (HPNumber >= 0)
                            {
                                //То отмечаем этот факт
                                _player.HoshimiPoints[HPNumber].Full = 1;
                                //Запрашиваем новую HP
                                //this.HPoint = _player.GetNearestHPForConvoy(this.Location, ref this.HPNumber);
                                this.HPoint = _player.GetNextHPForConvoy(this.Location, ref this.HPNumber);
                                //Если пустые, то идём за AZN
                                if (this.Stock == 0)
                                {
                                    this.APoint = _player.GetNearestAZNPoint(this.Location, this.HPoint);
                                    this.Path   = _player.Pathfinder.FindPath(this.Location, this.APoint);
                                    this.Move();
                                    return;
                                }
                                //Иначе сразу к HP
                                else
                                {
                                    if (this.Location == this.HPoint)
                                    {
                                        return;
                                    }
                                    this.Path = _player.Pathfinder.FindPath(this.Location, this.HPoint);
                                    this.Move();
                                    return;
                                }
                            }
                        }
                    }

                    if (HPNumber >= 0)
                    {
                        //Если стоит наш Needle
                        if (_player.HoshimiPoints[HPNumber].Needle == 1)
                        {
                            //И Needle ещё не заполнен
                            //Если мы уже разгрузились, то идём за AZN
                            if (this.Stock == 0)
                            {
                                this.APoint = _player.GetNearestAZNPoint(this.Location, this.HPoint);
                                this.Path   = _player.Pathfinder.FindPath(this.Location, this.APoint);
                                this.Move();
                                return;
                            }
                            //Иначе разгружаемся
                            else
                            {
                                this.Transfert();
                                return;
                            }
                        }
                    }
                }

                //Если мы чёрте где
                //Если пустые, то за AZN
                if (this.Stock == 0)
                {
                    this.APoint = _player.GetNearestAZNPoint(this.Location, this.HPoint);
                    this.Path   = _player.Pathfinder.FindPath(this.Location, this.APoint);
                    this.Move();
                    return;
                }
                //иначе на HP
                else
                {
                    if (this.Location == this.HPoint)
                    {
                        return;
                    }
                    this.Path = _player.Pathfinder.FindPath(this.Location, this.HPoint);
                    this.Move();
                    return;
                }
            }
        }