Beispiel #1
0
        public static void Update()
        {
            MyStrategy.TimerStart();

            CellLength = Const.MapSize / GridSize;

            var newState = new Dictionary <long, ATree>();

            NewTrees.Clear();
            DisappearedTrees.Clear();

            foreach (var tree in MyStrategy.World.Trees)
            {
                var a = new ATree(tree);
                if (!_prevState.ContainsKey(tree.Id))
                {
                    // новое дерево
                    NewTrees.Add(a);
                }
                newState[tree.Id] = a;
            }

            foreach (var it in _prevState)
            {
                if (!MyStrategy.IsPointVisible(it.Value))
                {
                    // его не видно, считаем что осталось
                    newState[it.Key] = it.Value;
                }
                else if (!newState.ContainsKey(it.Key))
                {
                    // видно, но исчезло
                    DisappearedTrees.Add(it.Value);
                }
            }

            _prevState = newState;
            _updateGrid();

            MyStrategy.TimerEndLog("Update trees", 1);
        }
Beispiel #2
0
        public static void Update()
        {
            foreach (var b in Bonuses)
            {
                for (var t = MyStrategy.PrevTickIndex + 1; t < MyStrategy.World.TickIndex; t++) // это если убили
                {
                    b.SkipTick();
                }
            }

            var interval = MyStrategy.Game.BonusAppearanceIntervalTicks;
            var newDict  = new Dictionary <int, ABonus>();
            var curStage = (MyStrategy.World.TickIndex - 1) / interval;

            foreach (var b in MyStrategy.World.Bonuses)
            {
                var visibleBonus = new ABonus(b);
                newDict[visibleBonus.Order]           = visibleBonus;
                _lastVisibleStage[visibleBonus.Order] = curStage;
            }
            foreach (var oldBonus in _bonuses.Values)
            {
                if (!MyStrategy.IsPointVisible(oldBonus))
                {
                    // он точно не прилетел в World, т.к. не виден
                    // остается на текущей тик
                    oldBonus.SkipTick();
                    newDict[oldBonus.Order] = oldBonus;
                }
                else
                {
                    _lastVisibleStage[oldBonus.Order] = curStage;
                    if (!oldBonus.Exists && !newDict.ContainsKey(oldBonus.Order))
                    {
                        // вижу, но он ещё не появился
                        oldBonus.SkipTick();
                        if (!oldBonus.Exists) // если он не должен был появиться только что
                        {
                            newDict[oldBonus.Order] = oldBonus;
                        }
                    }
                }
            }

            for (var i = 0; i < 2; i++)
            {
                if (!newDict.ContainsKey(i))
                {
                    var remains = curStage > _lastVisibleStage[i]
                        ? 0
                        : (MyStrategy.World.TickIndex == 0
                            ? interval + 1
                            : (interval - MyStrategy.World.TickIndex % interval) % interval + 1
                           );
                    if (MyStrategy.World.TickIndex + remains >= MyStrategy.Game.TickCount)
                    {
                        remains = 100500;
                    }

                    newDict[i] = new ABonus
                    {
                        X  = Const.BonusAppearencePoints[i].X,
                        Y  = Const.BonusAppearencePoints[i].Y,
                        Id = i - 2,
                        RemainingAppearanceTicks = remains,
                        Radius = MyStrategy.Game.BonusRadius,
                    };
                }
            }
            _bonuses = newDict;
        }
Beispiel #3
0
        public static void Update()
        {
            var newState = new Dictionary <long, ABuilding>();

            NewBuildings.Clear();
            DisappearedBuildings.Clear();

            foreach (var bld in MyStrategy.World.Buildings)
            {
                var a   = new ABuilding(bld);
                var key = _getCoordinatesKey(a);
                if (!_prevState.ContainsKey(key))
                {
                    // новое здание
                    NewBuildings.Add(a);
                }
                newState[key] = a;

                if (MyStrategy.World.TickIndex == 0)
                {
                    var opposit = new ABuilding(bld);
                    opposit.X          = Const.MapSize - opposit.X;
                    opposit.Y          = Const.MapSize - opposit.Y;
                    opposit.Faction    = opposit.Faction == Faction.Academy ? Faction.Renegades : Faction.Academy;
                    opposit.Id        *= -1; // temp Id
                    opposit.IsTeammate = false;
                    var oppositKey = _getCoordinatesKey(opposit);
                    if (!_prevState.ContainsKey(oppositKey))
                    {
                        // новое здание
                        NewBuildings.Add(opposit);
                    }
                    newState[oppositKey] = opposit;
                }
            }

            foreach (var it in _prevState)
            {
                var bld = it.Value;
                var key = _getCoordinatesKey(bld);
                if (!MyStrategy.IsPointVisible(bld))
                {
                    // его не видно, считаем что осталось
                    if (bld.RemainingActionCooldownTicks == 0)
                    {
                        // значит, если кто-то был поблизости, башня 100% выстрелила
                        if (MyStrategy.Combats.Any(x => x.IsTeammate && bld.GetDistanceTo2(x) <= Geom.Sqr(bld.CastRange)))
                        {
                            bld.RemainingActionCooldownTicks = (bld.IsBase
                                ? MyStrategy.Game.FactionBaseCooldownTicks
                                : MyStrategy.Game.GuardianTowerCooldownTicks) - 1;
                        }
                    }
                    else
                    {
                        bld.RemainingActionCooldownTicks--;
                    }
                    newState[key] = bld;
                }
                else if (!newState.ContainsKey(key))
                {
                    // видно, но исчезло
                    DisappearedBuildings.Add(bld);
                }
            }

            _prevState = newState;

            OpponentBase = Buildings.FirstOrDefault(x => x.IsBase && x.IsOpponent);
            MyBase       = Buildings.FirstOrDefault(x => x.IsBase && x.IsTeammate);

            foreach (var building in Buildings)
            {
                if (building.IsBase)
                {
                    building._isAssailable = Buildings.Count(x => x.Faction == building.Faction && x.Order == 1) < 3;
                }
                else
                {
                    building._isAssailable =
                        Buildings.Count(
                            x =>
                            x.Faction == building.Faction && x.Order + 1 == building.Order &&
                            x.Lane == building.Lane) == 0;
                }
            }
        }