示例#1
0
        public void process()
        {
            Utility.Trace("Maze.process");
            for (int iRoom = 1; iRoom <= fNumRooms; iRoom++)
            {
                Room room = this.getRoom(iRoom);
                room.process();
            }

            // Wizard
            //
            Room aRoom = fWizard;

            while (aRoom == fWizard && fWizard != null)
            {
                int no = GameEngine.rand.range(1, this.getNumRooms());
                aRoom = this.getRoom(no);
                if (aRoom.hasMuck())
                {
                    Utility.Trace("The wizard disposed of muck in cavern " + aRoom.getRoomNumber());
                    aRoom.removeMuck();
                }
                break;
            }
            fWizard = aRoom;

            Utility.Trace("Maze.process - janitor");
            // Janitor
            //
            if (fJanitor != null)
            {
                Utility.Trace("Janitor path: " + this.getJanitorPath());
                if (fJanitor.fWeb)
                {
                    Utility.Trace("The janitor is removing a web in cavern " + fJanitor.getRoomNumber());
                    if (GameEngine.rand.range(1, 2) == 1)
                    {
                        Utility.Trace("The janitor removed a web in cavern " + fJanitor.getRoomNumber());
                        fJanitor.fWeb = false;
                    }
                }
                else if (fJanitor.fPit)
                {
                    Utility.Trace("The janitor is filling in pit in cavern " + fJanitor.getRoomNumber());
                    if (GameEngine.rand.range(1, 2) == 1)
                    {
                        Utility.Trace("The janitor filled in pit in cavern " + fJanitor.getRoomNumber());
                        fJanitor.fPit = false;
                    }
                }
                else if (fJanitor.hasMuck())
                {
                    Utility.Trace("The janitor is cleaning up muck in cavern " + fJanitor.getRoomNumber());
                    if (GameEngine.rand.range(1, 3) == 1)
                    {
                        Utility.Trace("The janitor cleaned up muck in cavern " + fJanitor.getRoomNumber());
                        fJanitor.removeMuck();
                    }
                }
                else
                {
                    if (fJanitor.getRoomNumber() == fJanitorTarget.getRoomNumber())
                    {
                        while (fJanitor.getRoomNumber() == fJanitorTarget.getRoomNumber())
                        {
                            int no = GameEngine.rand.range(1, this.getNumRooms());
                            if (!this.getRoom(no).isLair())
                            {
                                no = GameEngine.rand.range(1, this.getNumRooms());
                            }
                            fJanitorTarget = this.getRoom(no);
                        }

                        // Set new target! Help adventurer if any.
                        Room target = null;
                        int  thirst = GameEngine.rand.range(0, 20);
                        for (int iPlayer = 1; iPlayer <= GameEngine.instance.fNumPlayers; iPlayer++)
                        {
                            Player player = GameEngine.instance.getPlayer(iPlayer);
                            if (player.isAlive() && !player.hasEscaped() && player.fWater <= thirst)
                            {
                                target = player.fRoom;
                                thirst = player.fWater;
                                Utility.Trace("The janitor detects a thirsty player in cavern " + player.fRoom.getRoomNumber());
                            }
                        }

                        if (target != null && target != fJanitor)
                        {
                            fJanitorTarget = target;
                            Utility.Trace("The janitor is rescuing a thirsty player in cavern " + target.getRoomNumber());
                        }
                    }

                    // take one step towards the target
                    Room[] path = GameEngine.instance.fMaze.findRoute(fJanitor, fJanitorTarget, null, Maze.USE_EVERYTHING);
                    Utility.Assert(path.Length > 0, "Maze.process - path.length > 0");
                    Utility.Trace("The janitor is moving towards " + fJanitorTarget.getRoomNumber() + " via " + path[0].getRoomNumber());
                    aRoom = path[0];

                    int num = fJanitor.getNumPassages();
                    if (fJanitor.hasDoor() && !fJanitor.isExitDoor() /* && !fJanitor.isDoorLocked() */)
                    {
                        num++;
                    }
                    Room tmp = aRoom;
                    for (int i = 0; i < num; i++)
                    {
                        if (tmp.hasMuck())
                        {
                            aRoom = tmp;
                            Utility.Trace("The janitor smells muck in cavern " + aRoom.getRoomNumber());
                            break;
                        }
                        if (tmp.fPit)
                        {
                            aRoom = tmp;
                            Utility.Trace("The janitor feels a draft from cavern " + aRoom.getRoomNumber());
                            break;
                        }
                        if (tmp.fWeb)
                        {
                            aRoom = tmp;
                            Utility.Trace("The janitor sees a web in cavern " + aRoom.getRoomNumber());
                            break;
                        }
                        if (fJanitor.isBlockedByPortcullis(tmp))
                        {
                            Utility.Trace("The janitor raises the portcullis between cavern " + fJanitor.getRoomNumber() + " and " + tmp.getRoomNumber());
                            fJanitor.openPortcullis(tmp);
                            tmp.openPortcullis(fJanitor);
                        }
                        int no = GameEngine.rand.range(1, num);
                        if (no > fJanitor.getNumPassages())
                        {
                            tmp = fJanitor.fDoor;
                        }
                        else
                        {
                            tmp = fJanitor.getPassage(no);
                        }
                    }

                    if (fJanitorUnlockedDoor != null)
                    {
                        if (!fJanitorUnlockedDoor.isDoorJammed())
                        {
                            if (fJanitorUnlockedDoor.isDoorOpen())
                            {
                                Utility.Trace("The janitor closes the door between cavern " + fJanitor.getRoomNumber() + " and " + fJanitorUnlockedDoor.getRoomNumber());
                                fJanitorUnlockedDoor.closeDoor();
                                fJanitor.closeDoor();
                            }
                            if (!fJanitorUnlockedDoor.isDoorLocked())
                            {
                                Utility.Trace("The janitor locks the door between cavern " + fJanitor.getRoomNumber() + " and " + fJanitorUnlockedDoor.getRoomNumber());
                                fJanitorUnlockedDoor.lockDoor();
                                fJanitor.lockDoor();
                            }
                        }
                        fJanitorUnlockedDoor = null;
                    }
//				if (fJanitorRaisedPortcullis != null)
//				{
//					Utility.Trace("The janitor lowers the portcullis between cavern " + fJanitor.getRoomNumber() + " and " + fJanitorRaisedPortcullis.getRoomNumber());
//					fJanitor.closePortcullis();
//					fJanitorRaisedPortcullis.closePortcullis();
//				}
                    if (fJanitor.hasDoor() && fJanitor.fDoor == aRoom)
                    {
                        if (fJanitor.isDoorLocked())
                        {
                            Utility.Trace("The janitor unlocks the door between cavern " + fJanitor.getRoomNumber() + " and " + aRoom.getRoomNumber());
                            fJanitor.unlockDoor();
                            aRoom.unlockDoor();
                            fJanitorUnlockedDoor = fJanitor;
                        }
                        if (!fJanitor.isDoorOpen())
                        {
                            Utility.Trace("The janitor opens the door between cavern " + fJanitor.getRoomNumber() + " and " + aRoom.getRoomNumber());
                            fJanitor.openDoor();
                            aRoom.openDoor();
                        }
                    }
                    if (fJanitor.isBlockedByPortcullis(aRoom))
                    {
                        Utility.Trace("The janitor raises the portcullis between cavern " + fJanitor.getRoomNumber() + " and " + aRoom.getRoomNumber());
                        fJanitor.openPortcullis(aRoom);
                        aRoom.openPortcullis(fJanitor);
                    }
                    Utility.Trace("The janitor moves to cavern " + aRoom.getRoomNumber());
                    fJanitor = aRoom;
                }
            }
            fPlayerInWeb = false;
            Utility.Trace("Maze.process - done");
        }