// Creates a new order for a ship to move to the target Entity public bool MoveOrder(Entity ship, Entity target) { MoveOrder moveOrder = new MoveOrder(ship, target); _orderList.Add(order); return(true); }
// Creates a new order for a ship to move to the given coordinates in a star system public bool MoveOrder(Entity ship, StarSystem system, double x, double y) { PositionDB position = new PositionDB(new Vector4(x, y, 0.0, 0.0), system.Guid); MoveOrder moveOrder = new MoveOrder(ship, position); _orderList.Add(moveOrder); return(true); }
public override object Clone() { MoveOrder order = new MoveOrder(); order.DelayTime = DelayTime; order.Owner = Owner; // The owners positions is sometimes set to that of another entity for orbiting purposes. This resets that issue order.Owner.SetDataBlob <PositionDB>(new PositionDB(Owner.GetDataBlob <PositionDB>())); order.Target = Target; order.PositionTarget = PositionTarget; order.OrbitRadius = OrbitRadius; order.MaximumSpeed = MaximumSpeed; return(order); }
/// <summary> /// process PropulsionDB movement for a single system /// </summary> /// <param name="manager">the system to process</param> /// <param name="deltaSeconds">amount of time in seconds</param> internal static void Process(EntityManager manager, int deltaSeconds) { OrderProcessor.ProcessSystem(manager); foreach (Entity shipEntity in manager.GetAllEntitiesWithDataBlob <PropulsionDB>()) { PositionDB positionDB = shipEntity.GetDataBlob <PositionDB>(); PropulsionDB propulsionDB = shipEntity.GetDataBlob <PropulsionDB>(); Queue <BaseOrder> orders = shipEntity.GetDataBlob <ShipInfoDB>().Orders; if (orders.Count > 0) { if (orders.Peek().OrderType == orderType.MOVETO) { // Check to see if we will overtake the target MoveOrder order = (MoveOrder)orders.Peek(); Vector4 shipPos = positionDB.AbsolutePosition; Vector4 targetPos; Vector4 currentSpeed = shipEntity.GetDataBlob <PropulsionDB>().CurrentSpeed; Vector4 nextTPos = shipPos + (currentSpeed * deltaSeconds); Vector4 newPos = shipPos; Vector4 deltaVecToTarget; Vector4 deltaVecToNextT; double distanceToTarget; double distanceToNextTPos; double speedDelta; double distanceDelta; double newDistanceDelta; double fuelMaxDistanceAU; double currentSpeedLength = currentSpeed.Length(); CargoStorageDB storedResources = shipEntity.GetDataBlob <CargoStorageDB>(); Dictionary <Guid, double> fuelUsePerMeter = propulsionDB.FuelUsePerKM; int maxKMeters = CalcMaxFuelDistance(shipEntity); if (order.PositionTarget == null) { targetPos = order.Target.GetDataBlob <PositionDB>().AbsolutePosition; } else { targetPos = order.PositionTarget.AbsolutePosition; } deltaVecToTarget = shipPos - targetPos; distanceToTarget = deltaVecToTarget.Length(); //in au deltaVecToNextT = shipPos - nextTPos; fuelMaxDistanceAU = GameConstants.Units.KmPerAu * maxKMeters; distanceToNextTPos = deltaVecToNextT.Length(); if (fuelMaxDistanceAU < distanceToNextTPos) { newDistanceDelta = fuelMaxDistanceAU; double percent = fuelMaxDistanceAU / distanceToNextTPos; newPos = nextTPos + deltaVecToNextT * percent; Event usedAllFuel = new Event(manager.ManagerSubpulses.SystemLocalDateTime, "Used all Fuel", shipEntity.GetDataBlob <OwnedDB>().ObjectOwner, shipEntity); usedAllFuel.EventType = EventType.FuelExhausted; manager.Game.EventLog.AddEvent(usedAllFuel); } else { newDistanceDelta = distanceToNextTPos; newPos = nextTPos; } if (distanceToTarget < newDistanceDelta) // moving would overtake target, just go directly to target { newDistanceDelta = distanceToTarget; propulsionDB.CurrentSpeed = new Vector4(0, 0, 0, 0); newPos = targetPos; if (order.Target != null && order.Target.HasDataBlob <SystemBodyInfoDB>()) { positionDB.SetParent(order.Target); } if (order.Target != null) { if (order.Target.HasDataBlob <SystemBodyInfoDB>()) // Set position to the target body { positionDB.SetParent(order.Target); } } else // We arrived, get rid of the order { shipEntity.GetDataBlob <ShipInfoDB>().Orders.Dequeue(); } } positionDB.AbsolutePosition = newPos; int kMetersMoved = (int)(newDistanceDelta * GameConstants.Units.KmPerAu); Dictionary <Guid, int> fuelAmounts = new Dictionary <Guid, int>(); foreach (var item in propulsionDB.FuelUsePerKM) { fuelAmounts.Add(item.Key, (int)item.Value * kMetersMoved); } StorageSpaceProcessor.RemoveResources(storedResources, fuelAmounts); } } } }