示例#1
0
        public static Exit.Direction FindPath(int inRoomIndexNumber, int outRoomIndexNumber, CharData ch, int depth, bool inZone)
        {
            RoomTemplate herep;
            RoomTemplate startp;
            Exit         exitp;
            RoomQ        tmp_q;
            RoomQ        q_head;
            RoomQ        q_tail;
            HashHeader   x_room = null;
            bool         throughDoors;
            int          i;
            int          tmp_room;
            int          count = 0;

            // TODO: Re-enable this.
            return(Exit.Direction.invalid);

            if (depth < 0)
            {
                throughDoors = true;
                depth        = -depth;
            }
            else
            {
                throughDoors = false;
            }

            startp = Room.GetRoom(inRoomIndexNumber);

            InitHashTable(x_room, sizeof(int), 2048);
            //HashEnter(x_room, inRoomIndexNumber, null);

            /* initialize queue */
            q_head        = new RoomQ();
            q_tail        = q_head;
            q_tail.RoomNR = inRoomIndexNumber;
            q_tail.NextQ  = null;

            while (q_head != null)
            {
                herep = Room.GetRoom(q_head.RoomNR);
                /* for each room test all directions */
                if (herep.Area == startp.Area || inZone == false)
                {
                    /*
                     * only look in this zone...
                     * saves cpu time and makes world safer for players
                     */
                    for (i = 0; i < Limits.MAX_DIRECTION; i++)
                    {
                        exitp = herep.ExitData[i];
                        if (ExitOk(exitp) != 0 && (throughDoors ? GO_OK_SMARTER :
                                                   Macros.IsSet((int)Room.GetRoom(q_head.RoomNR).ExitData[i].ExitFlags, (int)Exit.ExitFlag.closed)))
                        {
                            /* next room */
                            tmp_room = herep.ExitData[i].TargetRoom.IndexNumber;
                            if (tmp_room != outRoomIndexNumber)
                            {
                                /*
                                 * shall we add room to queue ?
                                 * count determines total breadth and depth
                                 */
                                if (!hash_find(x_room, tmp_room) &&
                                    (count < depth))
                                /* && !IS_SET( RM_FLAGS(tmp_room), DEATH ) ) */
                                {
                                    ++count;
                                    /* mark room as visted and put on queue */

                                    tmp_q        = new RoomQ();
                                    tmp_q.RoomNR = tmp_room;
                                    tmp_q.NextQ  = null;
                                    q_tail.NextQ = tmp_q;
                                    q_tail       = tmp_q;

                                    /* Ancestor for first layer is the direction */

                                    /*HashEnter(x_room, tmp_room,
                                     *          ((long)hash_find(x_room, q_head.RoomNR) == -1)
                                     *          ? (Object)(i + 1)
                                     *          : hash_find(x_room, q_head.RoomNR));*/
                                }
                            }
                            else
                            {
                                /* have reached our goal so free queue */
                                tmp_room = q_head.RoomNR;
                                for (; q_head != null; q_head = tmp_q)
                                {
                                    tmp_q  = q_head.NextQ;
                                    q_head = null;
                                }
                                /* return direction if first layer */

                                /*if ((long)hash_find(x_room, tmp_room) == -1)
                                 * {
                                 *  if (x_room.Buckets)
                                 *  {
                                 *      // junk left over from a previous track
                                 *      DestroyHashTable(x_room, null);
                                 *  }
                                 *  return (i);*/
                                //}
                                //else
                                {
                                    /* else return the Ancestor */
                                    //long j;

                                    /*j = (long)hash_find(x_room, tmp_room);
                                     * if (x_room.Buckets)
                                     * {
                                     *  // junk left over from a previous track
                                     *  DestroyHashTable(x_room, null);
                                     * }
                                     * return (-1 + j);*/
                                }
                            }
                        }
                    }
                }

                /* free queue head and point to next entry */
                tmp_q  = q_head.NextQ;
                q_head = null;
                q_head = tmp_q;
            }

            /* couldn't find path */

            /*if (x_room.Buckets)
             * {
             *  // junk left over from a previous track
             *  DestroyHashTable(x_room, null);
             * }*/
            return(Exit.Direction.invalid);
        }
示例#2
0
        public static Exit.Direction FindPath( int inRoomIndexNumber, int outRoomIndexNumber, CharData ch, int depth, bool inZone )
        {
            RoomTemplate herep;
            RoomTemplate startp;
            Exit exitp;
            RoomQ tmp_q;
            RoomQ q_head;
            RoomQ q_tail;
            HashHeader x_room = null;
            bool throughDoors;
            int i;
            int tmp_room;
            int count = 0;

            // TODO: Re-enable this.
            return Exit.Direction.invalid;

            if (depth < 0)
            {
                throughDoors = true;
                depth = -depth;
            }
            else
            {
                throughDoors = false;
            }

            startp = Room.GetRoom(inRoomIndexNumber);

            InitHashTable(x_room, sizeof(int), 2048);
            //HashEnter(x_room, inRoomIndexNumber, null);

            /* initialize queue */
            q_head = new RoomQ();
            q_tail = q_head;
            q_tail.RoomNR = inRoomIndexNumber;
            q_tail.NextQ = null;

            while (q_head != null)
            {
                herep = Room.GetRoom(q_head.RoomNR);
                /* for each room test all directions */
                if (herep.Area == startp.Area || inZone == false)
                {
                    /*
                    * only look in this zone...
                    * saves cpu time and makes world safer for players
                    */
                    for (i = 0; i < Limits.MAX_DIRECTION; i++)
                    {
                        exitp = herep.ExitData[i];
                        if (ExitOk(exitp) != 0 && (throughDoors ? GO_OK_SMARTER :
                            Macros.IsSet((int)Room.GetRoom(q_head.RoomNR).ExitData[i].ExitFlags, (int)Exit.ExitFlag.closed)))
                        {
                            /* next room */
                            tmp_room = herep.ExitData[i].TargetRoom.IndexNumber;
                            if (tmp_room != outRoomIndexNumber)
                            {
                                /*
                                * shall we add room to queue ?
                                * count determines total breadth and depth
                                */
                                if (!hash_find(x_room, tmp_room)
                                        && (count < depth))
                                /* && !IS_SET( RM_FLAGS(tmp_room), DEATH ) ) */
                                {
                                    ++count;
                                    /* mark room as visted and put on queue */

                                    tmp_q = new RoomQ();
                                    tmp_q.RoomNR = tmp_room;
                                    tmp_q.NextQ = null;
                                    q_tail.NextQ = tmp_q;
                                    q_tail = tmp_q;

                                    /* Ancestor for first layer is the direction */
                                    /*HashEnter(x_room, tmp_room,
                                                ((long)hash_find(x_room, q_head.RoomNR) == -1)
                                                ? (Object)(i + 1)
                                                : hash_find(x_room, q_head.RoomNR));*/
                                }
                            }
                            else
                            {
                                /* have reached our goal so free queue */
                                tmp_room = q_head.RoomNR;
                                for (; q_head != null; q_head = tmp_q)
                                {
                                    tmp_q = q_head.NextQ;
                                    q_head = null;
                                }
                                /* return direction if first layer */
                                /*if ((long)hash_find(x_room, tmp_room) == -1)
                                {
                                    if (x_room.Buckets)
                                    {
                                        // junk left over from a previous track
                                        DestroyHashTable(x_room, null);
                                    }
                                    return (i);*/
                                //}
                                //else
                                {
                                    /* else return the Ancestor */
                                    //long j;

                                    /*j = (long)hash_find(x_room, tmp_room);
                                    if (x_room.Buckets)
                                    {
                                        // junk left over from a previous track
                                        DestroyHashTable(x_room, null);
                                    }
                                    return (-1 + j);*/
                                }
                            }
                        }
                    }
                }

                /* free queue head and point to next entry */
                tmp_q = q_head.NextQ;
                q_head = null;
                q_head = tmp_q;
            }

            /* couldn't find path */
            /*if (x_room.Buckets)
            {
                // junk left over from a previous track
                DestroyHashTable(x_room, null);
            }*/
            return Exit.Direction.invalid;
        }