void HandleDeliveryRequest(QueueEntry entry) { DeliveryRequest request = entry.request; DeliveryInfo deliveryInfo; Vector2 random; deliveryInfo.timestamp = entry.timestamp; deliveryInfo.packageInfo = request.packageInfo; deliveryInfo.timeValueFunction = request.timeValueFunction; deliveryInfo.slot = GetNextSlot(); if (deliveryInfo.slot < 0) { Debug.LogError("Something's gone terribly wrong with the slot mechanics."); } random = UnityEngine.Random.insideUnitCircle * SimulationSettings.DronePadRadius; Vector3f departurePoint = departuresPoint.ToSpatialVector3f() + new Vector3f(random.x, 0, random.y); random = UnityEngine.Random.insideUnitCircle * SimulationSettings.DronePadRadius; Vector3f arrivalPoint = arrivalsPoint.ToSpatialVector3f() + new Vector3f(random.x, 0, random.y); //Debug.LogWarning("point to point plan"); //for new flight plan deliveryInfo.nextWaypoint = 1; deliveryInfo.returning = false; Improbable.Collections.List <Improbable.Vector3f> plan = globalLayer.generatePointToPointPlan( departurePoint, request.destination); //Debug.LogWarning("null check"); if (plan == null || plan.Count < 2) { // let scheduler know that this job can't be done DroneDeploymentFailure(); return; } deliveryInfo.waypoints = plan; //0th index only useful as last point in return journey //so make sure 0th index == last location in journey == arrivalsPoint deliveryInfo.waypoints[0] = arrivalPoint; deliveryInfo.latestCheckinTime = Time.time + (SimulationSettings.DroneETAConstant * Vector3.Distance( departurePoint.ToUnityVector(), deliveryInfo.waypoints[1].ToUnityVector()) / SimulationSettings.MaxDroneSpeed); //create drone //if successful, add to droneMap //if failure, tell scheduler job couldn't be done var droneTemplate = EntityTemplateFactory.CreateDroneTemplate( departurePoint.ToCoordinates(), deliveryInfo.waypoints[deliveryInfo.nextWaypoint], gameObject.EntityId(), request.packageInfo.weight + PayloadGenerator.GetPackagingWeight(request.packageInfo.type), SimulationSettings.MaxDroneSpeed); SpatialOS.Commands.CreateEntity(PositionWriter, droneTemplate) .OnSuccess((response) => DroneDeploymentSuccess(response.CreatedEntityId, deliveryInfo)) .OnFailure((response) => DroneDeploymentFailure()); }