Exemple #1
0
        /// <summary>
        ///     Finds the path.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="diag">if set to <c>true</c> [diag].</param>
        /// <param name="map">The map.</param>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <returns>List&lt;Vector2D&gt;.</returns>
        public static List<Vector2D> FindPath(RoomUser user, bool diag, Gamemap map, Vector2D start, Vector2D end)
        {
            List<Vector2D> list = new List<Vector2D>();

            PathFinderNode pathFinderNode = FindPathReversed(user, diag, map, start, end);

            if (pathFinderNode != null)
            {
                list.Add(end);

                while (pathFinderNode.Next != null)
                {
                    list.Add(pathFinderNode.Next.Position);
                    pathFinderNode = pathFinderNode.Next;
                }
            }

            return list;
        }
Exemple #2
0
        /// <summary>
        ///     Initializes the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="roomData">The room data.</param>
        /// <param name="rightOverride">if set to <c>true</c> [right override].</param>
        /// <param name="wordFilter">The word filter.</param>
        /// <param name="forceLoad"></param>
        private void Initialize(uint id, RoomData roomData, bool rightOverride, List<string> wordFilter, bool forceLoad)
        {
            RoomData = roomData;

            Disposed = false;
            RoomId = id;
            Bans = new Dictionary<long, double>();
            MutedUsers = new Dictionary<uint, uint>();
            ActiveTrades = new ArrayList();
            MutedBots = false;
            MutedPets = false;
            _mCycleEnded = false;
            EveryoneGotRights = rightOverride;
            LoadedGroups = new Dictionary<uint, string>();
            _roomKick = new Queue();
            _idleTime = 0;
            RoomMuted = false;
            _gameMap = new Gamemap(this);
            _roomItemHandler = new RoomItemHandler(this);
            _roomUserManager = new RoomUserManager(this);
            WordFilter = wordFilter;

            LoadRights();
            LoadMusic();
            LoadBans();
            InitUserBots();

            if (!forceLoad)
            {
                _roomThread = new Thread(StartRoomProcessing) {Name = "Room Loader"};
                _roomThread.Start();
            }

            Yupi.GetGame().GetRoomManager().QueueActiveRoomAdd(RoomData);
        }
Exemple #3
0
        /// <summary>
        ///     Finds the path reversed.
        /// </summary>
        /// <param name="roomUserable">The user.</param>
        /// <param name="whatIsDiag">if set to <c>true</c> [diag].</param>
        /// <param name="gameLocalMap">The map.</param>
        /// <param name="startMap">The start.</param>
        /// <param name="endMap">The end.</param>
        /// <returns>PathFinderNode.</returns>
        public static PathFinderNode FindPathReversed(RoomUser roomUserable, bool whatIsDiag, Gamemap gameLocalMap, Vector2D startMap, Vector2D endMap)
        {
            MinHeap<PathFinderNode> minSpanTreeCost = new MinHeap<PathFinderNode>(256);
            PathFinderNode[,] pathFinderMap = new PathFinderNode[gameLocalMap.Model.MapSizeX, gameLocalMap.Model.MapSizeY];
            PathFinderNode pathFinderStart = new PathFinderNode(startMap) {Cost = 0};
            PathFinderNode pathFinderEnd = new PathFinderNode(endMap);

            pathFinderMap[pathFinderStart.Position.X, pathFinderStart.Position.Y] = pathFinderStart;
            minSpanTreeCost.Add(pathFinderStart);

            while (minSpanTreeCost.Count > 0)
            {
                pathFinderStart = minSpanTreeCost.ExtractFirst();
                pathFinderStart.InClosed = true;

                for (int index = 0; (whatIsDiag ? (index < DiagMovePoints.Length ? 1 : 0) : (index < NoDiagMovePoints.Length ? 1 : 0)) != 0; index++)
                {
                    Vector2D realEndPosition = pathFinderStart.Position + (whatIsDiag ? DiagMovePoints[index] : NoDiagMovePoints[index]);

                    bool isEndOfPath = (realEndPosition.X == endMap.X) && (realEndPosition.Y == endMap.Y);

                    if (gameLocalMap.IsValidStep(roomUserable, new Vector2D(pathFinderStart.Position.X, pathFinderStart.Position.Y), realEndPosition, isEndOfPath, roomUserable.AllowOverride))
                    {
                        PathFinderNode pathFinderSecondNodeCalculation;

                        if (pathFinderMap[realEndPosition.X, realEndPosition.Y] == null)
                        {
                            pathFinderSecondNodeCalculation = new PathFinderNode(realEndPosition);
                            pathFinderMap[realEndPosition.X, realEndPosition.Y] = pathFinderSecondNodeCalculation;
                        }
                        else
                            pathFinderSecondNodeCalculation = pathFinderMap[realEndPosition.X, realEndPosition.Y];

                        if (!pathFinderSecondNodeCalculation.InClosed)
                        {
                            int internalSpanTreeCost = 0;

                            if (pathFinderStart.Position.X != pathFinderSecondNodeCalculation.Position.X)
                                internalSpanTreeCost++;

                            if (pathFinderStart.Position.Y != pathFinderSecondNodeCalculation.Position.Y)
                                internalSpanTreeCost++;

                            int loopTotalCost = pathFinderStart.Cost + internalSpanTreeCost + pathFinderSecondNodeCalculation.Position.GetDistanceSquared(endMap);

                            if (loopTotalCost < pathFinderSecondNodeCalculation.Cost)
                            {
                                pathFinderSecondNodeCalculation.Cost = loopTotalCost;
                                pathFinderSecondNodeCalculation.Next = pathFinderStart;
                            }

                            if (!pathFinderSecondNodeCalculation.InOpen)
                            {
                                if (pathFinderSecondNodeCalculation.Equals(pathFinderEnd))
                                {
                                    pathFinderSecondNodeCalculation.Next = pathFinderStart;

                                    return pathFinderSecondNodeCalculation;
                                }

                                pathFinderSecondNodeCalculation.InOpen = true;

                                minSpanTreeCost.Add(pathFinderSecondNodeCalculation);
                            }
                        }
                    }
                }
            }

            return null;
        }
Exemple #4
0
 /// <summary>
 ///     Resets the game map.
 /// </summary>
 /// <param name="newModelName">New name of the model.</param>
 /// <param name="wallHeight">Height of the wall.</param>
 /// <param name="wallThick">The wall thick.</param>
 /// <param name="floorThick">The floor thick.</param>
 internal void ResetGameMap(string newModelName, int wallHeight, int wallThick, int floorThick)
 {
     RoomData.ModelName = newModelName;
     RoomData.ModelName = newModelName;
     RoomData.ResetModel();
     RoomData.WallHeight = wallHeight;
     RoomData.WallThickness = wallThick;
     RoomData.FloorThickness = floorThick;
     _gameMap = new Gamemap(this);
 }