public void EnqueueDeliveryRequest(Improbable.Entity.Component.ResponseHandle <DeliveryHandler.Commands.RequestDelivery, DeliveryRequest, DeliveryResponse> handle) { MetricsWriter.Send(new ControllerMetrics.Update().SetIncomingDeliveryRequests(++incomingRequests)); float estimatedTime = Vector3.Distance(gameObject.transform.position, handle.Request.destination.ToUnityVector()) / SimulationSettings.MaxDroneSpeed; QueueEntry queueEntry = new QueueEntry(Time.time, handle.Request, 0, estimatedTime); if (requestQueue.Count >= SimulationSettings.MaxDeliveryRequestQueueSize) { QueueEntry longestJob = requestQueue.Max; float duration, value, maxValue; if (estimatedTime > longestJob.expectedDuration) { handle.Respond(new DeliveryResponse(false)); value = TimeValueFunctions.ExpectedProfit(estimatedTime, estimatedTime, queueEntry.request.packageInfo, queueEntry.request.timeValueFunction); potential += value; rejecValue += value; ++rejections; return; } requestQueue.Remove(longestJob); duration = Time.time - longestJob.timestamp + longestJob.expectedDuration; value = TimeValueFunctions.ExpectedProfit(duration, longestJob.expectedDuration, longestJob.request.packageInfo, longestJob.request.timeValueFunction); maxValue = TimeValueFunctions.ExpectedProfit(longestJob.expectedDuration, longestJob.expectedDuration, longestJob.request.packageInfo, longestJob.request.timeValueFunction); potential += value; rejecValue += maxValue; ++rejections; } requestQueue.Add(queueEntry); handle.Respond(new DeliveryResponse(true)); }
void HandleUnlinkRequest(Improbable.Entity.Component.ResponseHandle <Controller.Commands.UnlinkDrone, UnlinkRequest, UnlinkResponse> handle) { DeliveryInfo droneInfo; if (deliveriesMap.TryGetValue(handle.Request.droneId, out droneInfo)) { DestroyDrone(handle.Request.droneId, droneInfo.slot); DroneRetrieval(handle.Request.location.ToUnityVector()); if (droneInfo.returning) { MetricsWriter.Send(new ControllerMetrics.Update() .SetFailedReturns(++failedReturns) .SetCosts(costs) .SetPenalties(penalties)); } else { penalties += SimulationSettings.FailedDeliveryPenalty; MetricsWriter.Send(new ControllerMetrics.Update() .SetFailedDeliveries(++failedDeliveries) .SetCosts(costs) .SetPenalties(penalties)); } UpdateDroneSlotsAndMap(); } else { MetricsWriter.Send(new ControllerMetrics.Update().SetUnknownRequests(++unknownRequests)); } handle.Respond(new UnlinkResponse()); }
private void OnAddResource(Improbable.Entity.Component.ResponseHandle <StockpileDepository.Commands.AddResource, AddResource, Improbable.Core.Nothing> request) { if (stockpileDepository.Data.canAcceptResources) { healthBehaviour.AddCurrentHealthDelta(request.Request.quantity); } request.Respond(new Nothing()); }
private void OnRegisterBarracks(Improbable.Entity.Component.ResponseHandle <HQInfo.Commands.RegisterBarracks, RegisterBarracksRequest, Nothing> request) { var newBarracks = new Improbable.Collections.List <EntityId>(hqInfo.Data.barracks); newBarracks.Add(request.Request.entityId); hqInfo.Send(new HQInfo.Update().SetBarracks(newBarracks)); request.Respond(new Nothing()); }
void GetNearestObstacle(Improbable.Entity.Component.ResponseHandle <ReactiveLayer.Commands.GetNearestObstacle, ObstacleRequest, ObstacleResponse> handle) { Vector3f nearestNoFlyZone = bitmap.nearestNoFlyZonePoint(handle.Request.location); APFObstacleType obstacleType = APFObstacleType.NO_FLY_ZONE; if (nearestNoFlyZone.y < 0) { obstacleType = APFObstacleType.NONE; } handle.Respond(new ObstacleResponse(new APFObstacle(obstacleType, nearestNoFlyZone))); }
public void EnqueueDeliveryRequest(Improbable.Entity.Component.ResponseHandle <DeliveryHandler.Commands.RequestDelivery, DeliveryRequest, DeliveryResponse> handle) { MetricsWriter.Send(new ControllerMetrics.Update().SetIncomingDeliveryRequests(++incomingRequests)); float estimatedTime = Vector3.Distance(gameObject.transform.position, handle.Request.destination.ToUnityVector()) / SimulationSettings.MaxDroneSpeed; QueueEntry queueEntry = new QueueEntry(Time.time, handle.Request, 0, estimatedTime); requestQueue.Add(queueEntry); sorted = false; handle.Respond(new DeliveryResponse(true)); }
private void OnUnregisterBarracks(Improbable.Entity.Component.ResponseHandle <HQInfo.Commands.UnregisterBarracks, UnregisterBarracksRequest, Nothing> request) { var barracks = new Improbable.Collections.List <EntityId>(hqInfo.Data.barracks); if (barracks.Contains(request.Request.entityId)) { barracks.Remove(request.Request.entityId); } hqInfo.Send(new HQInfo.Update().SetBarracks(barracks)); request.Respond(new Nothing()); }
void HandleCollision(Improbable.Entity.Component.ResponseHandle <Controller.Commands.Collision, CollisionRequest, CollisionResponse> handle) { handle.Respond(new CollisionResponse()); penalties += 2 * SimulationSettings.DroneReplacementCost; DestroyDrone(handle.Request.droneId); DestroyDrone(handle.Request.colliderId); MetricsWriter.Send(new ControllerMetrics.Update() .SetCollisionsReported(++collisionsReported) .SetPenalties(penalties) .SetCosts(costs)); UpdateDroneSlotsAndMap(); }
public void EnqueueDeliveryRequest(Improbable.Entity.Component.ResponseHandle <DeliveryHandler.Commands.RequestDelivery, DeliveryRequest, DeliveryResponse> handle) { MetricsWriter.Send(new ControllerMetrics.Update().SetIncomingDeliveryRequests(++incomingRequests)); float expectedDuration = Vector3.Distance(gameObject.transform.position, handle.Request.destination.ToUnityVector()) / SimulationSettings.MaxDroneSpeed; if (deliveryRequestQueue.Count >= SimulationSettings.MaxDeliveryRequestQueueSize) { handle.Respond(new DeliveryResponse(false)); float value = TimeValueFunctions.DeliveryValue(expectedDuration, handle.Request.packageInfo, handle.Request.timeValueFunction); potential += value; rejecValue += value; ++rejections; } else { deliveryRequestQueue.Enqueue(new QueueEntry(Time.time, handle.Request, 0, expectedDuration)); handle.Respond(new DeliveryResponse(true)); } }
void UnsuccessfulTargetRequest(Improbable.Entity.Component.ResponseHandle <Controller.Commands.RequestNewTarget, TargetRequest, TargetResponse> handle, TargetResponseCode responseCode) { handle.Respond(new TargetResponse(new Vector3f(), responseCode)); }
void HandleTargetRequest(Improbable.Entity.Component.ResponseHandle <Controller.Commands.RequestNewTarget, TargetRequest, TargetResponse> handle) { DeliveryInfo deliveryInfo; if (deliveriesMap.TryGetValue(handle.Request.droneId, out deliveryInfo)) { //Debug.LogWarning("is final waypoint?"); //final waypoint, figure out if it's back at controller or only just delivered if (deliveryInfo.nextWaypoint < deliveryInfo.waypoints.Count) { handle.Respond(new TargetResponse(deliveryInfo.waypoints[deliveryInfo.nextWaypoint], TargetResponseCode.SUCCESS)); IncrementNextWaypoint(handle.Request.droneId, handle.Request.energyUsed); } else { if (deliveryInfo.returning) { UnsuccessfulTargetRequest(handle, TargetResponseCode.JOURNEY_COMPLETE); DestroyDrone(handle.Request.droneId, deliveryInfo.slot); MetricsWriter.Send(new ControllerMetrics.Update() .SetCompletedRoundTrips(++completedRoundTrips) .SetCosts(costs)); UpdateDroneSlotsAndMap(); } else { RegisterCompletedDelivery(deliveryInfo); MetricsWriter.Send(new ControllerMetrics.Update() .SetCompletedDeliveries(completedDeliveries) .SetAvgDeliveryTime(avgDeliveryTime) .SetRevenue(revenue)); deliveryInfo.returning = true; deliveryInfo.waypoints.Reverse(); Vector3f arrivalsGridPoint = globalLayer.GetClosestVector3fOnGrid(deliveryInfo.waypoints[0]); arrivalsGridPoint.y = deliveryInfo.waypoints[2].y; deliveryInfo.waypoints[1] = arrivalsGridPoint; deliveryInfo.nextWaypoint = 2; deliveryInfo.latestCheckinTime = Time.time + (SimulationSettings.DroneETAConstant * Vector3.Distance( deliveryInfo.waypoints[0].ToUnityVector(), deliveryInfo.waypoints[1].ToUnityVector()) / SimulationSettings.MaxDroneSpeed); deliveriesMap.Remove(handle.Request.droneId); deliveriesMap.Add(handle.Request.droneId, deliveryInfo); DroneInfo droneInfo = droneSlots[deliveryInfo.slot]; droneInfo.energyUsed = handle.Request.energyUsed; droneSlots[deliveryInfo.slot] = droneInfo; UpdateDroneSlotsAndMap(); //ignore 0 because that's the point that we've just reached //saved as 2, but sending 1 back to drone - only 1 spatial update instead of 2 now handle.Respond(new TargetResponse(deliveryInfo.waypoints[1], TargetResponseCode.SUCCESS)); } } } else { UnsuccessfulTargetRequest(handle, TargetResponseCode.WRONG_CONTROLLER); } }
private void OnHeartbeat(Improbable.Entity.Component.ResponseHandle<Heartbeat.Commands.Heartbeat, Nothing, Nothing> request) { SetHeartbeat(SimulationSettings.HeartbeatMax); request.Respond(new Nothing()); }
private void OnSpellCastRequest(Improbable.Entity.Component.ResponseHandle <Spells.Commands.SpellCastRequest, SpellCastRequest, Nothing> request) { CastSpell(request.Request.spellType, request.Request.position.ToVector3()); request.Respond(new Nothing()); }