Пример #1
0
        protected void checkAttachedSlots()
        {
            List <IHangarMechanic> hangars = this.hangarMgr.getAllHangar();

            foreach (var hangar in hangars)
            {
                HangarLiftSlot liftSlotMech = hangar.getLiftSlotMech();
                liftSlotMech.runActionQueue();

                if (liftSlotMech.hasStopped())
                {
                    // still attached to lift, set command to return back
                    hangar.setReturn();
                    liftSlotMech.reset();
                    return;
                }

                if (liftSlotMech.hasActions())
                {
                    return;
                }
            }

            this.checkAttached = true;
        }
Пример #2
0
        public HangarMechanic(Lift myLift, int subfloor, string name)
        {
            this.myLift   = myLift;
            this.subfloor = subfloor;
            this.name     = name;

            this.liftSlotMech = new HangarLiftSlot(myLift.myProgram, name);
            this.myLift.mechMgr.add(this.liftSlotMech);
        }
Пример #3
0
        public SetupHangarLiftSlot(Program myProgram, MechanicManager mechMgr, HangarManager hangarMgr)
        {
            this.myProgram = myProgram;
            this.hangarMgr = hangarMgr;

            List <IHangarMechanic> hangars = this.hangarMgr.getAllHangar();

            foreach (var hangar in hangars)
            {
                HangarLiftSlot liftSlotMech = hangar.getLiftSlotMech();
                liftSlotMech.execAction("checkAttached");
            }
        }
Пример #4
0
        public void run()
        {
            if (!checkAttached)
            {
                this.checkAttachedSlots();
                return;
            }

            List <IHangarMechanic> hangars = this.hangarMgr.getAllHangar();

            if (!retractingPistons)
            {
                foreach (var hangar in hangars)
                {
                    HangarLiftSlot liftSlotMech = hangar.getLiftSlotMech();
                    liftSlotMech.reset();
                    liftSlotMech.queueAction("setupRetract");
                    //   liftSlotMech.queueAction("mergeOn");
                }
                this.retractingPistons = true;
                return;
            }

            foreach (var hangar in hangars)
            {
                HangarLiftSlot liftSlotMech = hangar.getLiftSlotMech();
                liftSlotMech.runActionQueue();

                if (liftSlotMech.hasStopped())
                {
                    throw new Exception("Hangar lift slot in error state.");
                }

                if (liftSlotMech.hasActions())
                {
                    return;
                }
            }
            this.inReadyState = true;
        }
Пример #5
0
        public void execute()
        {
            IHangarMechanic hangar;

            if (this.currentHangar == "")
            {
                return;
            }

            if (this.hasStarted == true && this.actionQueue.Count() == 0)
            {
                this.myProgram.Echo("Lift is done");
                this.direction     = LiftDirection.Stopped;
                this.action        = LiftAction.Stopped;
                this.hasStarted    = false;
                this.currentHangar = "";
                return;
            }

            if (this.actionQueue.Count() != 0)
            {
                IMechanicAction action = this.actionQueue.First();
                this.myProgram.Echo(action.getName());

                if (action.hasError())
                {
                    this.myProgram.Echo("Action Error " + action.getName());
                    this.actionQueue.Clear();
                    this.direction = LiftDirection.Stopped;
                    this.action    = LiftAction.Stopped;
                    hangar         = this.hangarMgr.getHangar(this.currentHangar);
                    hangar.setReturned();
                    this.hasStarted    = true;
                    this.currentHangar = "";
                    return;
                }

                if (!action.hasStarted())
                {
                    this.myProgram.Echo("Processing action");
                    action.process();
                    return;
                }

                if (action.hasStarted() && !action.isDone())
                {
                    this.myProgram.Echo("Action running");
                    action.execute();
                    return;
                }

                if (action.isDone())
                {
                    this.myProgram.Echo("Popping Action " + action.getName());
                    this.actionQueue.RemoveAt(0);
                    return;
                }
            }

            hangar = this.hangarMgr.getHangar(this.currentHangar);
            HangarLiftSlot hangerliftslot = (HangarLiftSlot)this.mechMgr.getMechanic("hangerlift" + hangar.getName());
            Climber        climber        = (Climber)this.mechMgr.getMechanic("climber");

            if (climber.hasActions())
            {
                return;
            }

            this.action = LiftAction.MovingToHangar;
            int moveFloors = climber.getSubFloor() - hangar.getSubFloor();

            string cmd = "";

            if (moveFloors > 0)
            {
                this.direction = LiftDirection.Up;
                cmd            = "up";
            }
            else
            {
                this.direction = LiftDirection.Down;
                cmd            = "down";
                moveFloors     = moveFloors * -1;
            }

            List <String> climberList = new List <string>();

            for (int i = 0; i < moveFloors; i++)
            {
                climberList.Add(cmd);
            }

            // Move hangar piston out
            this.actionQueue.Add(new MechanicAction(this.myProgram, hangerliftslot, new List <string> {
                "moveOut",
            }));
            // Move Climber in place
            this.actionQueue.Add(new MechanicAction(this.myProgram, climber, climberList));
            // Lock lift to climber
            this.actionQueue.Add(new MechanicAction(this.myProgram, hangerliftslot, new List <string> {
                "lockClimber",
                "unlockGrabber",
                "moveInNoLift"
            }));
            // Move climber up
            climberList = new List <string>();
            for (int i = hangar.getSubFloor(); i != 0; i--)
            {
                climberList.Add("up");
            }
            climberList.Add("upAirLock");
            this.actionQueue.Add(new MechanicAction(this.myProgram, climber, climberList));

            // move down actions
            this.actionQueue.Add(new MechanicAction(this.myProgram, climber, new List <string> {
                "downAirLock",
                "down",
                "down",
            }));
            this.actionQueue.Add(new MechanicAction(this.myProgram, hangerliftslot, new List <string> {
                "moveOutNoLift",
                "lockGrabber",
            }));
            this.actionQueue.Add(new MechanicAction(this.myProgram, climber, new List <string> {
                "down",
            }));
            this.actionQueue.Add(new MechanicAction(this.myProgram, hangerliftslot, new List <string> {
                "moveIn"
            }));

            this.hasStarted = true;
        }