コード例 #1
0
        void MoveUnit(Unit Unit, MovementEventArgs E, bool Visible)
        {
            Tile tile = E.Tile;

            UnitView view = _UnitViews[Unit];

            view.Move(E);
            view.SetAlpha(Visible ? (byte)255 : LAST_SEEN_ALPHA);

            var       from      = _Stacks.FirstOrDefault(i => i.Value.Contains(Unit));
            StackView fromStack = from.Value;
            StackView toStack   = _Stacks.FirstOrDefault(i => i.Key == tile).Value;

            if (toStack != null && toStack == fromStack)
            {
                return;
            }
            if (toStack == null)
            {
                toStack = new StackView();
                _Stacks.Add(new KeyValuePair <Tile, StackView>(tile, toStack));
            }
            toStack.Add(view);
            if (fromStack != null)
            {
                fromStack.Remove(Unit);
                if (fromStack.Units.Count() == 0)
                {
                    _Stacks.Remove(from);
                }
            }
        }
コード例 #2
0
        public List <Tuple <Unit, UnitVisibility> > ComputeDelta(
            SightFinder SightFinder, Unit Unit, MovementEventArgs Movement)
        {
            if (Unit.Army == TrackingArmy)
            {
                return(new List <Tuple <Unit, UnitVisibility> >
                {
                    new Tuple <Unit, UnitVisibility>(Unit, new UnitVisibility(true, Unit.Position))
                });
            }
            var  visible  = SightFinder.IsSighted(Unit);
            Tile lastSeen = null;

            if (Movement != null && Movement.Path != null)
            {
                for (int i = Movement.Path.Count - 2; i >= 0; --i)
                {
                    if (SightFinder.IsSighted(Unit, Movement.Path[i]))
                    {
                        lastSeen = Movement.Path[i + 1];
                        break;
                    }
                }
            }
            return(new List <Tuple <Unit, UnitVisibility> >
            {
                new Tuple <Unit, UnitVisibility>(Unit, MergeVisibility(Unit, visible, OverrideLastSeen: lastSeen))
            });
        }
コード例 #3
0
        void HandleMove(object Sender, MovementEventArgs E)
        {
            var unit = (Unit)Sender;

            if (unit.Army == TrackingArmy)
            {
                var recalculateTiles = new HashSet <Tile>();
                if (unit.CanSight())
                {
                    if (E.Path != null && E.Path.Count > 1)
                    {
                        foreach (var tile in unit.GetFieldOfSight(
                                     unit.Configuration.SightRange, E.Path[0]).Select(i => i.Final))
                        {
                            recalculateTiles.Add(tile);
                        }
                    }
                    foreach (var tile in unit.GetFieldOfSight(unit.Configuration.SightRange, E.Tile)
                             .Select(i => i.Final))
                    {
                        recalculateTiles.Add(tile);
                    }
                }
                var tileDeltas =
                    recalculateTiles.Select(i => new Tuple <Tile, TileSightLevel>(i, GetTileSightLevel(i))).ToList();
                HandleDeltas(tileDeltas);
                var unitDeltas = UnitTracker.ComputeDelta(this, tileDeltas);
                if (OnSightUpdated != null)
                {
                    OnSightUpdated(
                        this,
                        new SightUpdatedEventArgs(unit, E, tileDeltas, unitDeltas));
                }
            }
            else
            {
                var otherUnits =
                    SightMovingUnit(unit, E.Path != null && E.Path.Count > 1 ? E.Path[E.Path.Count - 2] : null, E.Tile);
                var delta = UnitTracker.ComputeDelta(this, unit, E);
                foreach (var otherUnit in otherUnits)
                {
                    delta.AddRange(UnitTracker.Update(this, otherUnit));
                }

                if (OnSightUpdated != null)
                {
                    OnSightUpdated(
                        this,
                        new SightUpdatedEventArgs(
                            unit,
                            E,
                            new List <Tuple <Tile, TileSightLevel> >(),
                            delta));
                }
            }
        }
コード例 #4
0
 public SightUpdatedEventArgs(
     Unit Unit,
     MovementEventArgs Movement,
     List <Tuple <Tile, TileSightLevel> > TileDeltas,
     List <Tuple <Unit, UnitVisibility> > UnitDeltas)
 {
     this.Unit       = Unit;
     this.Movement   = Movement;
     this.TileDeltas = TileDeltas;
     this.UnitDeltas = UnitDeltas;
 }
コード例 #5
0
 public void Move(MovementEventArgs E)
 {
     if (E.Path != null)
     {
         _Movement = new MovementDolly(this, E.Path, E.Carrier);
     }
     else
     {
         _Movement = null;
         Position  = E.Tile.Center;
     }
 }
コード例 #6
0
 public void UpdateUnitVisibilities(
     Unit Unit, MovementEventArgs Movement, List <Tuple <Unit, UnitVisibility> > UnitDeltas)
 {
     foreach (var delta in UnitDeltas)
     {
         SetUnitVisibility(delta.Item1, delta.Item2);
     }
     if (Unit != null && Movement != null)
     {
         MoveUnit(Unit, Movement, true);
     }
     else if (Unit != null)
     {
         UpdateStack(Unit);
     }
 }
コード例 #7
0
 public List <Tuple <Unit, UnitVisibility> > ComputeDelta(
     SightFinder SightFinder, Unit Unit, MovementEventArgs Movement)
 {
     return(new List <Tuple <Unit, UnitVisibility> >());
 }
コード例 #8
0
        void HandleUnitMove(object Sender, MovementEventArgs E)
        {
            var unit = (Unit)Sender;

            unit.Deployment?.EnterUnits(unit.Army.Match.CurrentTurn, unit.Configuration.IsVehicle);
        }
コード例 #9
0
 void HandleUnitMove(object Sender, MovementEventArgs E)
 {
     OnUnitMove?.Invoke(Sender, E);
 }