Exemple #1
0
 public RandomDrone(IDrone sourceDrone, float restrictedZone = 1, float coneRange = 360, float startDirection = 0)
 {
     CopyFrom(sourceDrone);
     _restrictedZone = restrictedZone;
     _coneRange      = coneRange;
     _startDirection = startDirection;
 }
        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);
                }
            }
        }
Exemple #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);
        }
Exemple #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));
            }
        }
Exemple #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;
            }
        }
        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);
            }
        }
        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);
        }
Exemple #8
0
        public IDrone Deliver(IRoute route)
        {
            IDrone drone = this;

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

            return(drone);
        }
 /// <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}.");
     }
 }
 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));
     }
 }
Exemple #11
0
        public MyInstanceProvider(IDrone dep)
        {
            if (dep == null)
            {
                throw new ArgumentNullException("dep");
            }

            this.dep = dep;
        }
Exemple #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);
            }
        }
Exemple #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);
        }
Exemple #14
0
        public Target GetNextTarget(IDrone drone)
        {
            Target target;

            while (!targets[drone.GetId()].TryDequeue(out target))
            {
                ;
            }
            return(target);
        }
Exemple #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));
        }
        public bool Execute(char command, IDrone drone)
        {
            if (drone == null || !this.IsValid(command))
            {
                return false;
            }

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

            this.ProcessCommand(command, drone);
            return true;
        }
        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));
        }
Exemple #21
0
 public void Subscribe(IDrone drone)
 {
     lock (lockObject)
     {
         if (!drones.Contains(drone))
         {
             drones.Add(drone);
         }
     }
 }
        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);
        }
Exemple #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;
 }
Exemple #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;
        }
 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
     });
 }
Exemple #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));
            }
        }
        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);
            }
        }
Exemple #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;
            }
        }
Exemple #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;
        }
Exemple #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);
        }
Exemple #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.
        }
    }
Exemple #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;
        }
Exemple #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();
        }