Example #1
0
        public static WorkerRequirementSet GetWorkerRequirementSet(Type workerType, params Type[] workerTypes)
        {
            var workerAttributes = new Improbable.Collections.List <WorkerAttributeSet>();

            workerAttributes.Add(WorkerTypeToAttributeSet[workerType]);
            foreach (var nextType in workerTypes)
            {
                workerAttributes.Add(WorkerTypeToAttributeSet[nextType]);
            }

            return(new WorkerRequirementSet(workerAttributes));
        }
Example #2
0
    public Improbable.Collections.List <Improbable.Vector3f> generatePointToPointPlan(Improbable.Vector3f p1, Improbable.Vector3f p2)
    {
        if (isPointInNoFlyZone(p2))
        {
            Debug.LogError("next target is in a NFZ");
            return(null); // A plan can not be found
        }

        int[] coord1 = bitmap.findGridCoordinatesOfPoint(p1);
        if (coord1 == null)
        {
            Debug.LogError("coord1 fail");
            return(null);
        }

        int[] coord2 = bitmap.findGridCoordinatesOfPoint(p2);
        if (coord1 == null)
        {
            Debug.LogError("coord2 fail");
            return(null);
        }

        GridLocation l1 = new GridLocation(coord1[0], coord1[1]);
        GridLocation l2 = new GridLocation(coord2[0], coord2[1]);

        ASearch = new ThetaStarSearch(true); // Use AStarSearch or ThetaStarSearch here.

        float droneHeight        = UnityEngine.Random.Range(SimulationSettings.MinimumDroneHeight, SimulationSettings.MaximumDroneHeight);
        List <GridLocation> locs = ASearch.run(bitmap, l1, l2);

        if (locs == null)
        {                 // The case that a path could not be found.
            Debug.LogError("search fail");
            return(null); // Just return empty list.
        }

        //Debug.LogWarning("NUM VERTICES IN PATH: " + locs.Count);

        Improbable.Collections.List <Improbable.Vector3f> result = new Improbable.Collections.List <Improbable.Vector3f>();

        result.Add(p1);
        foreach (GridLocation l in locs)
        {
            Improbable.Vector3f convertedLocation = convertLocation(l);
            Improbable.Vector3f location          = new Improbable.Vector3f(convertedLocation.x, droneHeight, convertedLocation.z);

            result.Add(location);
        }
        result.Add(p2);

        return(result);
    }
Example #3
0
        private void RegisterBarracks(EntityId barrackId)
        {
            var newBarracks = new Improbable.Collections.List <EntityId>(hqInfo.Data.barracks);

            newBarracks.Add(barrackId);
            hqInfo.Send(new HQInfo.Update().SetBarracks(newBarracks));
        }
        private Nothing OnRegisterBarracks(RegisterBarracksRequest request, ICommandCallerInfo callerinfo)
        {
            var newBarracks = new Improbable.Collections.List <EntityId>(hqInfo.Data.barracks);

            newBarracks.Add(request.entityId);
            hqInfo.Send(new HQInfo.Update().SetBarracks(newBarracks));
            return(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());
        }
Example #6
0
 private static Improbable.Collections.List <DroneInfo> PopulateControllerSlots()
 {
     Improbable.Collections.List <DroneInfo> droneSlots = new Improbable.Collections.List <DroneInfo>((int)SimulationSettings.MaxDroneCountPerController);
     while (droneSlots.Count < droneSlots.Capacity)
     {
         droneSlots.Add(GenerateDroneInfo());
     }
     return(droneSlots);
 }
Example #7
0
    public void AddNoFlyZone(Improbable.Controller.NoFlyZone zone, bool sendUpdate = true)
    {
        zones.Add(zone);
        bitmap.addNoFlyZone(zone, sendUpdate);

        if (sendUpdate)
        {
            SendZonesUpdate();
        }
    }
    private TimeValueFunction GenerateRandomTVF()
    {
        Improbable.Collections.List <bool> steps = new Improbable.Collections.List <bool>(SimulationSettings.TVFSteps);
        int numSteps = 0;

        for (int i = 0; i < steps.Capacity; i++)
        {
            if (UnityEngine.Random.Range(0f, 1f) < 0.5f)
            {
                steps.Add(true);
                ++numSteps;
            }
            else
            {
                steps.Add(false);
            }
        }

        return(new TimeValueFunction(steps, numSteps, GenerateDeliveryType()));
    }
Example #9
0
    public Improbable.Controller.NoFlyZone GetNoFlyZone()
    {
        Improbable.Collections.List <Vector3f> positions = new Improbable.Collections.List <Vector3f>();

        for (int i = 0; i < nfzNodes.Length; i++)
        {
            positions.Add(nfzNodes[i].transform.position.ToSpatialVector3f());
        }

        return(NFZ_Templates.CreateCustomNoFlyZone(positions));
    }
Example #10
0
    public static TimeValueFunction GenerateTypeB(DeliveryType deliveryType)
    {
        Improbable.Collections.List <bool> steps = new Improbable.Collections.List <bool>(SimulationSettings.TVFSteps);
        int numSteps = 2;

        for (int i = 0; i < steps.Capacity; i++)
        {
            steps.Add(i == 4 || i == 9);
        }
        return(new TimeValueFunction(steps, numSteps, deliveryType));
    }
    void Scheduler.UpdateDeliveryRequestQueue()
    {
        Improbable.Collections.List <QueueEntry> queueList = new Improbable.Collections.List <QueueEntry>();
        foreach (QueueEntry entry in requestQueue)
        {
            queueList.Add(entry);
        }

        DeliveryHandlerWriter.Send(new DeliveryHandler.Update()
                                   .SetRequestQueue(queueList)
                                   .SetPotential(potential)
                                   .SetRejections(rejections)
                                   .SetRejectedValue(rejecValue));
    }
        static ModularData GetModularComponent(DocumentSnapshot[] moduleSnapshots)
        {
            var installList = new Improbable.Collections.List <int>(moduleSnapshots.Length);

            for (int i = 0; i < moduleSnapshots.Length; i++)
            {
                moduleSnapshots[i].TryGetValue <bool>("equip", out var installed);

                if (installed)
                {
                    installList.Add(i);
                }
            }

            return(new ModularData(installList, ShipType.Starter));
        }
Example #13
0
        private static void ProfilingSnapshot()
        {
            float maxX = 400;
            float maxZ = 400;

            var snapshotEntities = new Dictionary <EntityId, Entity>();
            var currentEntityId  = 2; //reserve id 1 for the scheduler

            Improbable.Collections.List <Improbable.Controller.NoFlyZone> noFlyZones = new Improbable.Collections.List <Improbable.Controller.NoFlyZone>();
            Improbable.Collections.List <ControllerInfo> controllers = new Improbable.Collections.List <ControllerInfo>();

            // CONTROLLERS
            int         firstController = currentEntityId;
            EntityId    controllerId    = new EntityId(currentEntityId++);
            Coordinates controllerPos   = new Coordinates(100, 0, 100);

            controllers.Add(new ControllerInfo(controllerId, controllerPos.ToSpatialVector3f()));
            snapshotEntities.Add(
                controllerId,
                EntityTemplateFactory.CreateControllerTemplate(
                    controllerPos,
                    new Vector3f(-maxX, 0, maxZ),
                    new Vector3f(maxX, 0, -maxZ),
                    noFlyZones,
                    PopulateControllerSlots()
                    ));
            int lastController = currentEntityId;
            // controller placement complete

            // ORDER GENERATOR
            // find and place order generator
            OrderGeneratorBehaviour orderGenerator = FindObjectOfType <OrderGeneratorBehaviour>();

            snapshotEntities.Add(
                SimulationSettings.OrderGeneratorEntityId,
                EntityTemplateFactory.CreateSchedulerTemplate(
                    new Vector3(0, 0, 0),
                    firstController,
                    lastController,
                    noFlyZones,
                    controllers
                    )
                );
            // end scheduler placement

            SnapshotMenu.SaveSnapshot(snapshotEntities, "profiling");
        }
        static async Task <ModuleResources> GetModuleResources(DocumentReference moduleRef)
        {
            var resourceQuery = await moduleRef.Collection(ResourceCollection).GetSnapshotAsync();

            var resourceSnapshots = resourceQuery.Documents;

            var list = new Improbable.Collections.List <ResourceInfo>(resourceQuery.Count);

            for (int i = 0; i < resourceQuery.Count; i++)
            {
                var resourceSnapshot = resourceSnapshots[i];
                var resource         = resourceSnapshot.ConvertTo <Resource>();

                list.Add(new ResourceInfo(resourceSnapshot.Id, resource.Type, resource.Quantity));
            }

            return(new ModuleResources(list));
        }
Example #15
0
        private static void LondonLarge()
        {
            float maxX = SimulationSettings.maxX; //routable width is 31500m
            float maxZ = SimulationSettings.maxZ; //routable height is 14000m

            var snapshotEntities = new Dictionary <EntityId, Entity>();
            var currentEntityId  = 2; //reserve id 1 for the scheduler

            Improbable.Collections.List <Improbable.Controller.NoFlyZone> noFlyZones = new Improbable.Collections.List <Improbable.Controller.NoFlyZone>();
            Improbable.Collections.List <ControllerInfo> controllers = new Improbable.Collections.List <ControllerInfo>();

            // NO FLY ZONES
            // start creating no fly zones from the editor
            NFZScript[] noFlyZoneScripts = FindObjectsOfType <NFZScript>();
            foreach (NFZScript noFlyZoneScript in noFlyZoneScripts)
            {
                noFlyZones.Add(noFlyZoneScript.GetNoFlyZone());
            }
            // end creation of no fly zones

            // CONTROLLERS
            // start placing controllers
            int firstController = currentEntityId;

            ControllerBehaviour[] controllerScripts = FindObjectsOfType <ControllerBehaviour>();
            foreach (ControllerBehaviour controllerScript in controllerScripts)
            {
                EntityId    controllerId  = new EntityId(currentEntityId++);
                Coordinates controllerPos = controllerScript.gameObject.transform.position.ToCoordinates();

                controllers.Add(new ControllerInfo(controllerId, controllerPos.ToSpatialVector3f()));

                snapshotEntities.Add(
                    controllerId,
                    EntityTemplateFactory.CreateControllerTemplate(
                        controllerPos,
                        new Vector3f(-maxX, 0, maxZ),
                        new Vector3f(maxX, 0, -maxZ),
                        noFlyZones,
                        PopulateControllerSlots()
                        ));
            }
            int lastController = currentEntityId;
            // controller placement complete

            // make nfz nodes show up on the inspector map
            //currentEntityId = ShowNoFlyZones(noFlyZones, snapshotEntities, currentEntityId);

            // ORDER GENERATOR
            // find and place order generator
            OrderGeneratorBehaviour orderGenerator = FindObjectOfType <OrderGeneratorBehaviour>();

            snapshotEntities.Add(
                SimulationSettings.OrderGeneratorEntityId,
                EntityTemplateFactory.CreateSchedulerTemplate(
                    orderGenerator.gameObject.transform.position,
                    firstController,
                    lastController,
                    noFlyZones,
                    controllers
                    )
                );
            // end scheduler placement

            SnapshotMenu.SaveSnapshot(snapshotEntities, "london_large");
        }
        private static Improbable.Collections.List <EntityId> getNeighbors(double x, int maxColumnCount, double y, int maxRowCount, int id)
        {
            Improbable.Collections.List <EntityId> neighbors = new Improbable.Collections.List <EntityId>();

            int  maxX = maxColumnCount - 1;
            int  maxY = maxRowCount - 1;
            long nId;

            //Top-Left
            if ((x > 0) & (y < maxY))
            {
                nId = (long)((y + 1) * maxColumnCount + ((x + 1) - 1));
                neighbors.Add(new EntityId(nId));
            }

            //Top
            if (y < maxY)
            {
                nId = (long)((y + 1) * maxColumnCount + (x + 1));
                neighbors.Add(new EntityId(nId));
            }

            //Top-Right
            if ((y < maxY) & (x < maxX))
            {
                nId = (long)((y + 1) * maxColumnCount + (x + 2));
                neighbors.Add(new EntityId(nId));
            }

            //Right
            if (x < maxX)
            {
                neighbors.Add(new EntityId(id + 1));
            }

            //Bottom-Right
            if ((x < maxX) & (y > 0))
            {
                nId = (long)((y - 1) * maxColumnCount + (x + 1 + 1));
                neighbors.Add(new EntityId(nId));
            }

            //Bottom
            if (y > 0)
            {
                nId = (long)((y - 1) * maxColumnCount + (x + 1));
                neighbors.Add(new EntityId(nId));
            }

            //Bottom-Left
            if ((y > 0) & (x > 0))
            {
                nId = (long)((y - 1) * maxColumnCount + ((x + 1) - 1));
                neighbors.Add(new EntityId(nId));
            }

            //Left
            if (x > 0)
            {
                neighbors.Add(new EntityId(id - 1));
            }

            return(neighbors);
        }