Exemplo n.º 1
0
 public RandomDrone(IDrone sourceDrone, float restrictedZone = 1, float coneRange = 360, float startDirection = 0)
 {
     CopyFrom(sourceDrone);
     _restrictedZone = restrictedZone;
     _coneRange      = coneRange;
     _startDirection = startDirection;
 }
Exemplo n.º 2
0
        private static IEnumerator GenerateVerticalGridDrones(IDrone drone, int droneCount, float delay, Area area, DroneFactory factory, bool addDrones)
        {
            var         height    = area.TopBoundary - (0.5f + drone.Size / 2);
            var         lenght    = area.RightBoundary - (0.5f + drone.Size / 2);
            const float direction = 180f;

            droneCount *= (int)(lenght / height);

            while (true)
            {
                for (var i = 0; i < droneCount; i++)
                {
                    var startPos = new Vector3(-lenght + i * 2 * lenght / droneCount, 0.4f, height);
                    factory.SpawnDrones(new DefaultDrone(drone, startPos, direction));
                    yield return(new WaitForSeconds(delay * 2 * lenght / droneCount));
                }
                for (var i = 0; i < droneCount; i++)
                {
                    var startPos = new Vector3(lenght - i * 2 * lenght / droneCount, 0.4f, height);
                    factory.SpawnDrones(new DefaultDrone(drone, startPos, direction));
                    yield return(new WaitForSeconds(delay * 2 * lenght / droneCount));
                }

                if (addDrones)
                {
                    droneCount += (int)(lenght / height);
                }
            }
        }
Exemplo n.º 3
0
        public async Task <InvokeResult> SendMessage(IDrone drone, MAVLINK_MSG_ID messageId, object req)
        {
            var buffer = MavlinkUtil.GeneratePacket(drone, MAVLINK_MSG_ID.MISSION_REQUEST_LIST, req);
            await _serialPort.WriteAsync(buffer);

            return(InvokeResult.Success);
        }
Exemplo n.º 4
0
        private IEnumerator GenerateDrones(DroneFactory factory, IDrone drone, StartPositionDelegate posDelegate, GameObject parentDrone = null)
        {
            var addPattern = parentDrone != null;

            while (true)
            {
                if (parentDrone == null && addPattern)
                {
                    yield break;
                }

                if (parentDrone != null)
                {
                    factory.SpawnDrones(drone, DroneCount, posDelegate: delegate
                    {
                        return(parentDrone.transform.position);
                    });
                }
                else
                {
                    factory.SpawnDrones(drone, DroneCount, posDelegate: posDelegate);
                }
                yield return(new WaitForSeconds(Delay));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets plaforms where chasers have start and destory position and which platforms spawn them.
        /// </summary>
        public void SetChaserPlatforms(IDrone chaserBase, int[] chaserSpawnPlatformIndex = null,
                                       int[] chaserDestroyPlatformIndex = null, int[] chaserStartPlatformIndex = null, IPattern pattern = null,
                                       IDrone iDrone = null)
        {
            _chaserSpawnPlatformIdxs   = chaserSpawnPlatformIndex;
            _chaserDestroyPlatformIdxs = chaserDestroyPlatformIndex;
            _chaserBase = chaserBase;
            _pattern    = pattern;
            _iDrone     = iDrone ?? new DefaultDrone(7, 1, DroneColor.Cyan);

            if (_chaserSpawnPlatformIdxs == null || _chaserDestroyPlatformIdxs == null)
            {
                return;
            }

            if (chaserStartPlatformIndex == null || chaserStartPlatformIndex.Length != _chaserSpawnPlatformIdxs.Length)
            {
                _chaserStartPosition = new int[_chaserSpawnPlatformIdxs.Length];
                for (var i = 0; i < _chaserSpawnPlatformIdxs.Length; i++)
                {
                    _chaserStartPosition[i] = _chaserSpawnPlatformIdxs[i] - 1;
                }
            }
            else
            {
                _chaserStartPosition = chaserStartPlatformIndex;
            }
        }
Exemplo n.º 6
0
        public IInstruction ToSpecificInstruction(
            GlobalInstruction globalInstruction,
            IDrone drone,
            DateTime startedAt)
        {
            if (globalInstruction == null)
            {
                throw new ArgumentException("globalInstruction is null");
            }
            if (drone == null)
            {
                throw new ArgumentException("drone is null");
            }

            switch (globalInstruction.TYPE)
            {
            case "Collect":
                return(new Collect(PlayerContext, drone, startedAt));

            case "MoveTo":
                return(new MoveTo(PlayerContext, drone, startedAt, drone.CurrentPosition, globalInstruction.Destination));

            case "Unload":
                return(new Unload(PlayerContext, drone, startedAt));

            default:
                throw new ArgumentException("Unknown instruction type " + globalInstruction.TYPE);
            }
        }
Exemplo n.º 7
0
        public List <GameObject> SpawnDrones(IDrone drone, int droneCount = 1, bool isAdded = false, Area area = new Area(), StartPositionDelegate posDelegate = null)
        {
            var drones     = new List <GameObject>();
            var droneDatas = new List <SpawnDroneData>();

            for (var i = 0; i < droneCount; i++)
            {
                var newDrone = drone.CreateDroneInstance(this, isAdded, area, posDelegate);
                newDrone.AddComponent <DroneManager>();

                if (IsServer)
                {
                    var data = AddDroneData(newDrone);
                    drone.ConfigureDrone(newDrone, this);
                    droneDatas.Add(new SpawnDroneData(
                                       new DroneState(data.Id, newDrone.transform.position.x, newDrone.transform.position.z),
                                       drone.Speed, drone.Size, drone.Color, drone.DroneType));
                }
                else
                {
                    drone.ConfigureDrone(newDrone, this);
                }
                drones.Add(newDrone);
            }

            if (IsServer)
            {
                SyncDroneServer.SpawnDrones(droneDatas);
            }
            return(drones);
        }
Exemplo n.º 8
0
        public IDrone Deliver(IRoute route)
        {
            IDrone drone = this;

            route.Commands.ToList().ForEach(c => drone = drone.Execute(c));

            return(drone);
        }
Exemplo n.º 9
0
 /// <summary>
 ///     Associates the drone to the battlefield area and validates that it is inside of it.
 /// </summary>
 /// <param name="drone">The drone.</param>
 /// <exception cref="System.InvalidOperationException"></exception>
 private void AssociateBattlefieldAreaAndValidate(IDrone drone)
 {
     drone.SetBattlefieldArea(_battlefieldArea);
     if (!drone.IsInBattlefieldArea())
     {
         throw new InvalidOperationException($"Drone '{drone}' not within battlefield area {_battlefieldArea}.");
     }
 }
Exemplo n.º 10
0
 public void SpawnChaser(IDrone drone, Vector3?position = null)
 {
     foreach (var playerManager in _controlSLA.PlayerManagers.Values)
     {
         drone.MovementType = new ChaserMovement(playerManager);
         playerManager.Chaser.AddRange(DroneFactory.SpawnDrones(drone));
     }
 }
Exemplo n.º 11
0
        public MyInstanceProvider(IDrone dep)
        {
            if (dep == null)
            {
                throw new ArgumentNullException("dep");
            }

            this.dep = dep;
        }
Exemplo n.º 12
0
        private IEnumerator GenerateDrones(IDrone drone, float delay, Area area, StartPositionDelegate posDelegate)
        {
            while (true)
            {
                yield return(new WaitForSeconds(delay));

                SpawnDrones(drone, isAdded: true, area: area, posDelegate: posDelegate);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the most optimal path of grid positions for the drone based on the target positionX and positionX.
        /// Automatically sets the drones path and target locations
        /// </summary>
        /// <param name="drone"></param>
        /// <param name="targetX"></param>
        /// <param name="targetY"></param>
        /// <returns>path list</returns>
        public IGridPosition[] GetPathForDrone(IDrone drone, int targetX, int targetY)
        {
            var path = Map.GetPath(drone.CurrentX, drone.CurrentY, targetX, targetY);

            drone.SetTargetPosition(targetX, targetY);
            drone.SetPath(path);

            return(path);
        }
Exemplo n.º 14
0
        public Target GetNextTarget(IDrone drone)
        {
            Target target;

            while (!targets[drone.GetId()].TryDequeue(out target))
            {
                ;
            }
            return(target);
        }
Exemplo n.º 15
0
        public void SetPattern(DroneFactory factory, IDrone drone, Area area, StartPositionDelegate posDelegate = null)
        {
            if (posDelegate == null)
            {
                posDelegate = delegate { return(new Vector3(0, 0.4f, 0)); }
            }
            ;

            factory.StartCoroutine(GenerateDrones(factory, drone, posDelegate));
        }
Exemplo n.º 16
0
        public bool Execute(char command, IDrone drone)
        {
            if (drone == null || !this.IsValid(command))
            {
                return false;
            }

            drone.Move();
            return true;
        }
Exemplo n.º 17
0
 public DefaultDrone(IDrone sourceDrone, Vector3 position, float direction, IDroneMovement movementType = null)
 {
     CopyFrom(sourceDrone);
     _position  = position;
     _direction = direction;
     if (movementType != null)
     {
         MovementType = movementType;
     }
 }
Exemplo n.º 18
0
 public void Unsubscribe(IDrone drone)
 {
     lock (this)
     {
         if (drones.Contains(drone))
         {
             drones.Remove(drone);
         }
     }
 }
Exemplo n.º 19
0
        public bool Execute(char command, IDrone drone)
        {
            if (!this.IsValid(command))
            {
                return false;
            }

            this.ProcessCommand(command, drone);
            return true;
        }
Exemplo n.º 20
0
        public static void Synced360Mines(DroneFactory factory, int mineCount, IDrone mineDrone, Area area, IDrone spawnedDrones,
                                          int spawnedDroneCount, float delay, float?reduceDelay = null, float?minDelay = null)
        {
            var minDel = minDelay ?? 1;
            var mines  = new List <GameObject>();

            mines.AddRange(factory.SpawnDrones(mineDrone, mineCount, area: area));

            factory.StartCoroutine(Generate360Drones(factory, mines, spawnedDrones, spawnedDroneCount, delay, minDel, reduceDelay));
        }
Exemplo n.º 21
0
 public void Subscribe(IDrone drone)
 {
     lock (lockObject)
     {
         if (!drones.Contains(drone))
         {
             drones.Add(drone);
         }
     }
 }
Exemplo n.º 22
0
        private static IDrone DeliverOrder(IDeliverySettings deliverySettings, IDrone drone, IRoute route)
        {
            var baseDrone = drone;
            var newDrone  = drone.Deliver(route);

            if (IsOutOfReach(deliverySettings, newDrone.Position))
            {
                return(baseDrone);
            }
            return(newDrone);
        }
Exemplo n.º 23
0
 protected ADrone(float speed, float size, DroneColor color, DroneType droneType, IDroneMovement movementType,
                  IPattern pattern = null, IDrone spawnedDrones = null)
 {
     Speed         = speed;
     Size          = size;
     Color         = color;
     DroneType     = droneType;
     MovementType  = movementType ?? new StraightMovement();
     Pattern       = pattern;
     SpawnedDrones = spawnedDrones;
 }
Exemplo n.º 24
0
        public MainViewModel(ISerialTelemetryLink telemeteryLink, IDroneAdapter droneAdapter, IMissionPlanner planner)
        {
            TelemetryLink = telemeteryLink;
            TelemetryLink.MessageParsed += _telemeteryLink_MessageParsed;
            OpenSerialPortCommand        = new RelayCommand(HandleConnectClick, CanPressConnect);
            GetWaypointsCommand          = new RelayCommand(GetWaypoints, CanDoConnectedStuff);

            Title = "Kevin";

            _apmDrone     = new LagoVista.Drone.Models.Drone();
            _droneAdapter = droneAdapter;
            _planner      = planner;
        }
Exemplo n.º 25
0
 public IDroneDto Map(IDrone drone)
 {
     return(new DroneDto()
     {
         CurrentPosition = drone.CurrentPosition,
         LastInstruction = drone.GetLastValidInstruction(),
         Name = drone.Name,
         Speed = drone.Speed,
         State = drone.State,
         StorageSize = drone.StorageSize,
         Storage = drone.Storage
     });
 }
Exemplo n.º 26
0
        public DroneServiceHost(IDrone dep, Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
        {
            if (dep == null)
            {
                throw new ArgumentNullException("dep");
            }

            foreach (var cd in this.ImplementedContracts.Values)
            {
                cd.Behaviors.Add(new MyInstanceProvider(dep));
            }
        }
Exemplo n.º 27
0
        private void ProcessCommand(char command, IDrone drone)
        {
            string commandAsString = command.ToString(CultureInfo.InvariantCulture);
            if (this.IsLeftCommand(commandAsString))
            {
                drone.Rotate(false);
            }

            if (this.IsRightCommand(commandAsString))
            {
                drone.Rotate(true);
            }
        }
Exemplo n.º 28
0
        protected void CopyFrom(IDrone sourceDrone)
        {
            var rhs = sourceDrone as ADrone;

            if (rhs != null)
            {
                Speed         = rhs.Speed;
                Size          = rhs.Size;
                Color         = rhs.Color;
                DroneType     = rhs.DroneType;
                MovementType  = rhs.MovementType;
                Pattern       = rhs.Pattern;
                SpawnedDrones = rhs.SpawnedDrones;
            }
        }
Exemplo n.º 29
0
        public Unload(IPlayerContext playerContext, IDrone drone, DateTime startedAt)
        {
            var item = playerContext.GetMap().Factories.FirstOrDefault(
                itm => drone.CurrentPosition.IsNear(itm.Position)
                );

            if (item == null)
            {
                throw new InvalidInstructionException("No factory near the drone");
            }
            Drone     = drone;
            StartedAt = startedAt;
            Resource  = drone.Storage;
            AbortedAt = null;
        }
Exemplo n.º 30
0
        /// <summary>
        /// Adds a drone to the port - starts working immediately
        /// </summary>
        /// <param name="drone"></param>
        /// <returns>id of drone</returns>
        public int AddDrone(IDrone drone)
        {
            drone.SetPort(this);
            var displayObject = Communicaiton.Instance.GetDisplayObjectAt(drone.CurrentX, drone.CurrentY);
            var insertedDrone = _drones.Add(new DroneWithPosition(drone, displayObject));

            var waitingOrder = GetWaitingOrder();

            if (waitingOrder != null)
            {
                drone.AddOrder(waitingOrder);
            }


            return(insertedDrone.Id);
        }
Exemplo n.º 31
0
    public override void InitializeAgent()
    {
        drone = (IDrone)rotorCtrlAgent;

        if (detectionMode == DetectionMode.Raycast)
        {
            rayDetection = new RayDetection();
        }
        else
        {
            cam = GetComponentInChildren <Camera>();
            Texture2D tex = new Texture2D(84, 84, TextureFormat.RGB24, false);
            cam.GetComponent <DepthCam>().Initialize(ref tex);
            // TODO add tex to agent observations.
        }
    }
Exemplo n.º 32
0
        public Collect(IPlayerContext playerContext, IDrone drone, DateTime startedAt)
        {
            var item = playerContext.GetMap().Mines.FirstOrDefault(
                itm => drone.CurrentPosition.IsNear(itm.Position)
                );

            if (item == null)
            {
                throw new InvalidInstructionException("No mine near the drone");
            }
            var mine = item as Mine;

            Drone     = drone;
            StartedAt = startedAt;
            Mine      = mine;
        }
Exemplo n.º 33
0
        static void Main(string[] args)
        {
            //DemoInterfaceObj();
            Bike b = new Bike {
                Name = "pulsar"
            };

            // b.GetDetails();


            BikeDrone bd = new BikeDrone();

            IDrone id1 = bd;

            bd.GetDetails();
            Console.WriteLine(bd.show(b.Name));
            id1.GetDetails();


            Console.ReadKey();
        }