/// <summary> /// Runs de task and lets the robots move. /// </summary> /// <param name="robot">Robots object</param> public void RunTask(Robots robot) { //Checks if the given robot is this robot. if (this.robot == robot) { //Calls the methode FollowPath so the robots moves. robot.FollowPath(); } }
/// <summary> /// Checks if a robot is anywhere to be found nearby the door. /// </summary> /// <returns>True or false</returns> public bool check() { foreach (Model3D model3d in worldObjects) { if (model3d is Robots) { Robots robot = (Robots)model3d; if (robot.x == -35 && (robot.z <= (z + 2.5) && robot.z >= (z - 2.5))) { return(true); } } } return(false); }
/// <summary> /// Checks which robot is the closest to the rack and gives the task to the closest robot. /// </summary> public void giveTask() { if (_Inventory.Tasks.Count != 0) { //Sets for every robot the distance to the rack foreach (Model3D model3d in worldObjects) { if (model3d is Robots) { Robots robot = (Robots)model3d; double closestToX = robot.x - _Inventory.Tasks.First().getRack.x; double closestToZ = robot.z - _Inventory.Tasks.First().getRack.z; robot.closestTo = Math.Sqrt(Math.Pow(closestToX, 2) + Math.Pow(closestToZ, 2)); } } //Checking which robot is the closest foreach (Model3D model3d in worldObjects) { if (model3d is Robots) { Robots robot = (Robots)model3d; if (robot.closestTo < this.closestTo || robot.closestTo == this.closestTo) { this.closestTo = robot.closestTo; destined = robot; } } } //Is giving the robot the task if (robotMove == null && destined == this && !_Inventory.Tasks.First().getRack.moving) { robotMove = new RobotMove(_Inventory.Tasks.First(), this, Grid); _Inventory.Tasks.RemoveAt(0); } destined = null; } }
/// <summary> /// This methode start the task by the given robot. /// </summary> /// <param name="robot"></param> public void StartTask(Robots robot) { if (this.robot == robot) { //Checks where the robot is. robotLocation = grid.GetNodeByCoordinates(robot.x, robot.z); //If loaded is false, set firstDestination as destination and call the methode robot.InitPaths and sets the values robotlocation and the destination. if (!loaded) { loaded = true; destination = task.firstDestination; robot.InitPaths(robotLocation, destination); } //If loaded is true than set final destination as destination and call the methode robot.initpaths and sets the values robotlocation and the destination. else { destination = task.finalDestination; robot.InitPaths(robotLocation, destination); } RunTask(robot); } }
public bool Update(int tick) { for (int i = 0; i < worldObjects.Count; i++) { Model3D u = worldObjects[i]; if (u is IUpdatable) { bool needsCommand = ((IUpdatable)u).Update(tick); if (needsCommand) { if (u is Robots) { Robots robot = (Robots)u; robot.Update(tick); } else if (u is Spaceships) { Spaceships spaceship = (Spaceships)u; spaceship.needsUpdate = true; // Check if the spaceship is above the building and shipments is not empty if (Inventory.shipments.Count() > 0 && (spaceship.z <= 8 && spaceship.z >= -8)) { ReceiveShipment(spaceship); } // Check if the warehouse needs to be restocked after the spaceship passed the building if (spaceship.z < -8) { Inventory.CheckStock(); } // Check if the warehouse has orders if (Inventory.orders.Count() > 0) { checkCoordinateShip = ReceiveCargo(spaceship); } // Move the spaceship if the spaceship has any type of orders or has already begun moving if ((Inventory.orders.Count() > 0 || Inventory.shipments.Count() > 0) || (spaceship.z > -140 ^ spaceship.z == 125)) { spaceship.moveSpaceship(); } // If the spaceship has almost reached his destination, you receive your delivery if (spaceship.z == -139 && spaceship.cargo.Count() > 0) { spaceship.cargo.ForEach(x => Console.WriteLine("{0} of {1} was delivered to you", x.stock, x.name)); spaceship.cargo.Clear(); } } else if (u is Racks) { Racks rack = (Racks)u; rack.moveRack(); if (rack.attr == "deleted") { worldObjects.Remove(rack); Inventory.RemoveRack(rack); } } else if (u is Doors) { Doors door = (Doors)u; door.Update(tick); } else if (u is Model3D) { Model3D model = (Model3D)u; //If model type is light then call the methode move of light. if (model.type == "light") { model.Move(model.x, model.y, model.z); } //Calls the methode moveEarth and gives model along with it. moveEarth(model); } SendCommandToObservers(new UpdateModel3DCommand(u)); } } } return(true); }
/// <summary> /// Sets the object task, robot and grid. /// </summary> /// <param name="task">Task object</param> /// <param name="robot">Robots object</param> /// <param name="grid">Grid object</param> public RobotMove(Task task, Robots robot, Grid grid) { this.task = task; this.robot = robot; this.grid = grid; }
/// <summary> /// Lets the rack move along with the robot. /// </summary> /// <param name="rack">Racks object</param> /// <param name="robot">Robots object</param> public void MovingRack(Racks rack, Robots robot) { rack.x = robot.x; rack.z = robot.z; }