private void setGridCell(int x, int z, GridType value) { int index = z * GridWidth + x; if (Grid.ContainsKey(index)) { Grid.Remove(index); } Grid.Add(index, value); }
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); } }