示例#1
0
 private void NewMoveOrder(IContext context, Fleet fleet)
 {
     if (_items.ContainsKey(fleet))
     {
         _items[fleet].Dispose();
     }
     if (fleet.MoveOrder == null)
     {
         _items.Remove(fleet);
         return;
     }
     List<Step> steps = fleet.MoveOrder.Steps.ToList();
     List<VertexDefinition.Path> vertices = new List<VertexDefinition.Path>();
     int index = 0;
     Vector3 prevPosition = (Vector3) steps[0].Source.Center;
     float totalDistance = 0.0f;
     for(int i = 0; i<steps.Count ; i++)
     {
         Vector3 middlePoint = (Vector3)steps[i].Destination.Adjacencies.Single(a => a.Neighbourg == steps[i].Source).PassingPoints.First();
         Vector3 startPoint = (Vector3)steps[i].Source.Center;
         Vector3 endPoint = (Vector3)steps[i].Destination.Center;
         Vector3 prevPoint = i == 0 ? startPoint :
             (Vector3)steps[i].Source.Adjacencies.Single(a => a.Neighbourg == steps[i - 1].Source).PassingPoints.First();
         Vector3 nextPoint = i == steps.Count -1 ? endPoint :
             (Vector3)steps[i].Destination.Adjacencies.Single(a => a.Neighbourg == steps[i + 1].Destination).PassingPoints.First();
         //First part of the arc
         for (int j = 0; j < ArcSubdivisions; j++)
         {
             Vector3 position = Vector3.CatmullRom(prevPoint, startPoint, middlePoint, endPoint, (1.0f * j) / ArcSubdivisions);
             float arcLength = Vector3.Distance(prevPosition, position);
             vertices.Add(new VertexDefinition.Path
             {
                 fillingIndex = (uint)(++index),
                 position = position,
                 pathLength = new Vector2(totalDistance, arcLength)
             });
             totalDistance += arcLength;
             prevPosition = position;
         }
         //Second part of the arc
         for (int j = 0; j < ArcSubdivisions; j++)
         {
             Vector3 position = Vector3.CatmullRom(startPoint, middlePoint, endPoint, nextPoint, (1.0f * j) / ArcSubdivisions);
             float arcLength = Vector3.Distance(prevPosition, position);
             vertices.Add(new VertexDefinition.Path
             {
                 fillingIndex = (uint)(++index),
                 position = position,
                 pathLength = new Vector2(totalDistance, arcLength)
             });
             totalDistance += arcLength;
             prevPosition = position;
         }
     }
     _items[fleet] = new MoveOrderRenderingItem(
         vertices.Count,
         Buffer.Create(context.DirectX.Device, BindFlags.VertexBuffer, vertices.ToArray()),
         fleet.Speed);
 }
示例#2
0
 internal NewFleetNotification(Fleet fleet)
 {
     Fleet = fleet;
 }
示例#3
0
 public void CreateFleet(Fleet fleet)
 {
     _fleets.Add(fleet);
 }
示例#4
0
 public DestroyFleetCommand(Fleet fleet)
 {
     _fleet = fleet;
 }
示例#5
0
 internal FleetMovedNotification(Fleet fleet)
 {
     Fleet = fleet;
 }
示例#6
0
文件: PathFinder.cs 项目: ndech/Alpha
 public static List<Step> CalculatePath(Fleet fleet, Zone destination)
 {
     return CalculatePath((IMovable)fleet, destination);
 }
 internal NewFleetMoveOrderNotification(Fleet fleet)
 {
     Fleet = fleet;
 }
示例#8
0
 public void CreateFleet(Fleet fleet)
 {
     _fleets.Add(fleet);
 }
示例#9
0
 public MoveFleetCommand(Fleet fleet, List<Step> steps)
 {
     _fleet = fleet;
     _steps = steps;
 }
示例#10
0
 public FleetRenderingInfo(IContext context, Fleet fleet, Vector2I size)
 {
     WorldPosition = (Vector3)fleet.Location.Center;
     WorldMatrix = Matrix.RotationY(-(float) (Math.PI/2))*Matrix.Translation(WorldPosition);
     ShipCount = fleet.ShipCount;
     Fleets = new List<Fleet> { fleet };
     if(fleet.Owner.Equals(context.Realm))
         CurrentStatus = Status.Mine;
     else
         CurrentStatus = new List<Status> {Status.Ally, Status.Enemy, Status.Neutral}.RandomItem();
     Text = context.TextManager.Create("Courrier", 14, RandomGenerator.Get(1,2000).ToString(CultureInfo.InvariantCulture),
         new Vector2I(size.X-8, size.Y), Color.Wheat, HorizontalAlignment.Center, VerticalAlignment.Middle, new Padding(2));
 }
示例#11
0
 private void OnNewFleet(IContext context, Fleet fleet)
 {
     if(_fleetRenderingInfos.ContainsKey(fleet.Location))
         _fleetRenderingInfos[fleet.Location].Fleets.Add(fleet);
     else
         _fleetRenderingInfos[fleet.Location] = new FleetRenderingInfo(context, fleet, _baseOverlay.Size);
 }
示例#12
0
 private void OnFleetUpdate(IContext context, Fleet fleet)
 {
     OnFleetDelete(fleet);
     OnNewFleet(context, fleet);
 }
示例#13
0
        private void OnFleetDelete(Fleet fleet)
        {
            var info = _fleetRenderingInfos.Single(kvp => kvp.Value.Fleets.Contains(fleet));
            if (info.Value.FleetCount == 1)
            {
                info.Value.Dispose();
                _fleetRenderingInfos.Remove(info.Key);

            }
            else info.Value.Fleets.Remove(fleet);
        }
示例#14
0
 public RenameFleetCommand(Fleet fleet, string newName)
 {
     _fleet = fleet;
     _newName = newName;
 }