예제 #1
0
		public static void BuildSectorNodeNetwork(CommandEventArgs e)
		{
			if (m_Nodes == null)
			{
				try
				{
					Console.Write("Initializing SectorNodes...");
					DateTime dt = DateTime.Now;

					m_Nodes = new SectorNode[Map.Felucca.Width >> Map.SectorShift, Map.Felucca.Height >> Map.SectorShift];

					for (int y = 0; y < (Map.Felucca.Height >> Map.SectorShift); y++)
					{
						for (int x = 0; x < (Map.Felucca.Width >> Map.SectorShift); x++)
						{
							SectorNode sn = new SectorNode();
							sn.Point = Point3D.Zero;
							sn.Island = -1;
							sn.Links = new SectorNode[8];
							sn.Distances = new int[8];
							sn.NumLinks = 0;

							for (int sy = 0; sy < Map.SectorSize && sn.Point == Point3D.Zero; sy++)
							{
								for (int sx = 0; sx < Map.SectorSize && sn.Point == Point3D.Zero; sx++)
								{
									if (Map.Felucca.CanSpawnMobile((x << Map.SectorShift) + sx, (y << Map.SectorShift) + sy, 
										Map.Felucca.GetAverageZ((x << Map.SectorShift) + sx, (y << Map.SectorShift) + sy)))
									{
										sn.Point = new Point3D((x << Map.SectorShift) + sx, (y << Map.SectorShift) + sy, 
											Map.Felucca.GetAverageZ((x << Map.SectorShift) + sx, (y << Map.SectorShift) + sy));
									}
								}
							}

							m_Nodes[x, y] = sn;
						}
					}

					Console.WriteLine("done in {0} seconds.", (DateTime.Now - dt).TotalSeconds);
					Console.Write("Computing SectorNode network...");
					dt = DateTime.Now;

					Mobile m = new Server.Mobiles.WanderingHealer();
					MovementPath mp = null;
			
					for (int y = 0; y < (Map.Felucca.Height >> Map.SectorShift); y++)
					{
						for (int x = 0; x < (Map.Felucca.Width >> Map.SectorShift); x++)
						{
							if (m_Nodes[x, y].Point != Point3D.Zero)
							{
								m.MoveToWorld(m_Nodes[x, y].Point, Map.Felucca);

								if (x < (Map.Felucca.Width >> Map.SectorShift) - 1 && y > 0 && m_Nodes[x + 1, y - 1].Point != Point3D.Zero &&
									(mp = new MovementPath(m, m_Nodes[x + 1, y - 1].Point)).Success)
								{
									m_Nodes[x, y].Links[m_Nodes[x, y].NumLinks] = m_Nodes[x + 1, y - 1];
									m_Nodes[x, y].Distances[m_Nodes[x, y].NumLinks] = mp.Directions.Length;
									m_Nodes[x, y].NumLinks++;

									m_Nodes[x + 1, y - 1].Links[m_Nodes[x + 1, y - 1].NumLinks] = m_Nodes[x, y];
									m_Nodes[x + 1, y - 1].Distances[m_Nodes[x + 1, y - 1].NumLinks] = mp.Directions.Length;
									m_Nodes[x + 1, y - 1].NumLinks++;
								}
						
								if (x < (Map.Felucca.Width >> Map.SectorShift) - 1 && m_Nodes[x + 1, y].Point != Point3D.Zero &&
									(mp = new MovementPath(m, m_Nodes[x + 1, y].Point)).Success)
								{
									m_Nodes[x, y].Links[m_Nodes[x, y].NumLinks] = m_Nodes[x + 1, y];
									m_Nodes[x, y].Distances[m_Nodes[x, y].NumLinks] = mp.Directions.Length;
									m_Nodes[x, y].NumLinks++;

									m_Nodes[x + 1, y].Links[m_Nodes[x + 1, y].NumLinks] = m_Nodes[x, y];
									m_Nodes[x + 1, y].Distances[m_Nodes[x + 1, y].NumLinks] = mp.Directions.Length;
									m_Nodes[x + 1, y].NumLinks++;
								}

								if (x < (Map.Felucca.Width >> Map.SectorShift) - 1 && y < (Map.Felucca.Height >> Map.SectorShift) - 1 &&
									m_Nodes[x + 1, y + 1].Point != Point3D.Zero && (mp = new MovementPath(m, m_Nodes[x + 1, y + 1].Point)).Success)
								{
									m_Nodes[x, y].Links[m_Nodes[x, y].NumLinks] = m_Nodes[x + 1, y + 1];
									m_Nodes[x, y].Distances[m_Nodes[x, y].NumLinks] = mp.Directions.Length;
									m_Nodes[x, y].NumLinks++;

									m_Nodes[x + 1, y + 1].Links[m_Nodes[x + 1, y + 1].NumLinks] = m_Nodes[x, y];
									m_Nodes[x + 1, y + 1].Distances[m_Nodes[x + 1, y + 1].NumLinks] = mp.Directions.Length;
									m_Nodes[x + 1, y + 1].NumLinks++;
								}

								if (y < (Map.Felucca.Height >> Map.SectorShift) - 1 && m_Nodes[x, y + 1].Point != Point3D.Zero &&
									(mp = new MovementPath(m, m_Nodes[x, y + 1].Point)).Success)
								{
									m_Nodes[x, y].Links[m_Nodes[x, y].NumLinks] = m_Nodes[x, y + 1];
									m_Nodes[x, y].Distances[m_Nodes[x, y].NumLinks] = mp.Directions.Length;
									m_Nodes[x, y].NumLinks++;

									m_Nodes[x, y + 1].Links[m_Nodes[x, y + 1].NumLinks] = m_Nodes[x, y];
									m_Nodes[x, y + 1].Distances[m_Nodes[x, y + 1].NumLinks] = mp.Directions.Length;
									m_Nodes[x, y + 1].NumLinks++;
								}
							}
						}
					}

					m.Delete();

					Console.WriteLine("done in {0} seconds.", (DateTime.Now - dt).TotalSeconds);
					Console.Write("Finding islands...");
					dt = DateTime.Now;

					int nextIsland = 0;
					Queue open = new Queue();
					ArrayList closed = new ArrayList();

					for (int y = 0; y < (Map.Felucca.Height >> Map.SectorShift); y++)
					{
						for (int x = 0; x < (Map.Felucca.Width >> Map.SectorShift); x++)
						{
							if (m_Nodes[x, y].Point == Point3D.Zero)
								continue;

							if (m_Nodes[x, y].Island == -1)
							{
								int island = nextIsland++;

								// now use dijkstra-style flood fill to find all connected nodes
								open.Clear();
								closed.Clear();

								open.Enqueue(m_Nodes[x, y]);

								while (open.Count > 0)
								{
									SectorNode sn = (SectorNode)open.Dequeue();
									closed.Add(sn);

									sn.Island = island;

									for (int i = 0; i < sn.NumLinks; i++)
										if (!closed.Contains(sn.Links[i]) && !open.Contains(sn.Links[i]))
											open.Enqueue(sn.Links[i]);
								}
							}
						}
					}

					Console.WriteLine("done in {0} seconds.", (DateTime.Now - dt).TotalSeconds);
				}
				catch (Exception ex)
				{
					LogHelper.LogException(ex);
					Console.WriteLine("error!");
					Console.WriteLine(ex);
				}
			}
		}
예제 #2
0
        public static void BuildSectorNodeNetwork(CommandEventArgs e)
        {
            if (m_Nodes == null)
            {
                try
                {
                    Console.Write("Initializing SectorNodes...");
                    DateTime dt = DateTime.Now;

                    m_Nodes = new SectorNode[Map.Felucca.Width >> Map.SectorShift, Map.Felucca.Height >> Map.SectorShift];

                    for (int y = 0; y < (Map.Felucca.Height >> Map.SectorShift); y++)
                    {
                        for (int x = 0; x < (Map.Felucca.Width >> Map.SectorShift); x++)
                        {
                            SectorNode sn = new SectorNode();
                            sn.Point     = Point3D.Zero;
                            sn.Island    = -1;
                            sn.Links     = new SectorNode[8];
                            sn.Distances = new int[8];
                            sn.NumLinks  = 0;

                            for (int sy = 0; sy < Map.SectorSize && sn.Point == Point3D.Zero; sy++)
                            {
                                for (int sx = 0; sx < Map.SectorSize && sn.Point == Point3D.Zero; sx++)
                                {
                                    if (Map.Felucca.CanSpawnMobile((x << Map.SectorShift) + sx, (y << Map.SectorShift) + sy,
                                                                   Map.Felucca.GetAverageZ((x << Map.SectorShift) + sx, (y << Map.SectorShift) + sy)))
                                    {
                                        sn.Point = new Point3D((x << Map.SectorShift) + sx, (y << Map.SectorShift) + sy,
                                                               Map.Felucca.GetAverageZ((x << Map.SectorShift) + sx, (y << Map.SectorShift) + sy));
                                    }
                                }
                            }

                            m_Nodes[x, y] = sn;
                        }
                    }

                    Console.WriteLine("done in {0} seconds.", (DateTime.Now - dt).TotalSeconds);
                    Console.Write("Computing SectorNode network...");
                    dt = DateTime.Now;

                    Mobile       m  = new Server.Mobiles.WanderingHealer();
                    MovementPath mp = null;

                    for (int y = 0; y < (Map.Felucca.Height >> Map.SectorShift); y++)
                    {
                        for (int x = 0; x < (Map.Felucca.Width >> Map.SectorShift); x++)
                        {
                            if (m_Nodes[x, y].Point != Point3D.Zero)
                            {
                                m.MoveToWorld(m_Nodes[x, y].Point, Map.Felucca);

                                if (x < (Map.Felucca.Width >> Map.SectorShift) - 1 && y > 0 && m_Nodes[x + 1, y - 1].Point != Point3D.Zero &&
                                    (mp = new MovementPath(m, m_Nodes[x + 1, y - 1].Point)).Success)
                                {
                                    m_Nodes[x, y].Links[m_Nodes[x, y].NumLinks]     = m_Nodes[x + 1, y - 1];
                                    m_Nodes[x, y].Distances[m_Nodes[x, y].NumLinks] = mp.Directions.Length;
                                    m_Nodes[x, y].NumLinks++;

                                    m_Nodes[x + 1, y - 1].Links[m_Nodes[x + 1, y - 1].NumLinks]     = m_Nodes[x, y];
                                    m_Nodes[x + 1, y - 1].Distances[m_Nodes[x + 1, y - 1].NumLinks] = mp.Directions.Length;
                                    m_Nodes[x + 1, y - 1].NumLinks++;
                                }

                                if (x < (Map.Felucca.Width >> Map.SectorShift) - 1 && m_Nodes[x + 1, y].Point != Point3D.Zero &&
                                    (mp = new MovementPath(m, m_Nodes[x + 1, y].Point)).Success)
                                {
                                    m_Nodes[x, y].Links[m_Nodes[x, y].NumLinks]     = m_Nodes[x + 1, y];
                                    m_Nodes[x, y].Distances[m_Nodes[x, y].NumLinks] = mp.Directions.Length;
                                    m_Nodes[x, y].NumLinks++;

                                    m_Nodes[x + 1, y].Links[m_Nodes[x + 1, y].NumLinks]     = m_Nodes[x, y];
                                    m_Nodes[x + 1, y].Distances[m_Nodes[x + 1, y].NumLinks] = mp.Directions.Length;
                                    m_Nodes[x + 1, y].NumLinks++;
                                }

                                if (x < (Map.Felucca.Width >> Map.SectorShift) - 1 && y < (Map.Felucca.Height >> Map.SectorShift) - 1 &&
                                    m_Nodes[x + 1, y + 1].Point != Point3D.Zero && (mp = new MovementPath(m, m_Nodes[x + 1, y + 1].Point)).Success)
                                {
                                    m_Nodes[x, y].Links[m_Nodes[x, y].NumLinks]     = m_Nodes[x + 1, y + 1];
                                    m_Nodes[x, y].Distances[m_Nodes[x, y].NumLinks] = mp.Directions.Length;
                                    m_Nodes[x, y].NumLinks++;

                                    m_Nodes[x + 1, y + 1].Links[m_Nodes[x + 1, y + 1].NumLinks]     = m_Nodes[x, y];
                                    m_Nodes[x + 1, y + 1].Distances[m_Nodes[x + 1, y + 1].NumLinks] = mp.Directions.Length;
                                    m_Nodes[x + 1, y + 1].NumLinks++;
                                }

                                if (y < (Map.Felucca.Height >> Map.SectorShift) - 1 && m_Nodes[x, y + 1].Point != Point3D.Zero &&
                                    (mp = new MovementPath(m, m_Nodes[x, y + 1].Point)).Success)
                                {
                                    m_Nodes[x, y].Links[m_Nodes[x, y].NumLinks]     = m_Nodes[x, y + 1];
                                    m_Nodes[x, y].Distances[m_Nodes[x, y].NumLinks] = mp.Directions.Length;
                                    m_Nodes[x, y].NumLinks++;

                                    m_Nodes[x, y + 1].Links[m_Nodes[x, y + 1].NumLinks]     = m_Nodes[x, y];
                                    m_Nodes[x, y + 1].Distances[m_Nodes[x, y + 1].NumLinks] = mp.Directions.Length;
                                    m_Nodes[x, y + 1].NumLinks++;
                                }
                            }
                        }
                    }

                    m.Delete();

                    Console.WriteLine("done in {0} seconds.", (DateTime.Now - dt).TotalSeconds);
                    Console.Write("Finding islands...");
                    dt = DateTime.Now;

                    int       nextIsland = 0;
                    Queue     open       = new Queue();
                    ArrayList closed     = new ArrayList();

                    for (int y = 0; y < (Map.Felucca.Height >> Map.SectorShift); y++)
                    {
                        for (int x = 0; x < (Map.Felucca.Width >> Map.SectorShift); x++)
                        {
                            if (m_Nodes[x, y].Point == Point3D.Zero)
                            {
                                continue;
                            }

                            if (m_Nodes[x, y].Island == -1)
                            {
                                int island = nextIsland++;

                                // now use dijkstra-style flood fill to find all connected nodes
                                open.Clear();
                                closed.Clear();

                                open.Enqueue(m_Nodes[x, y]);

                                while (open.Count > 0)
                                {
                                    SectorNode sn = (SectorNode)open.Dequeue();
                                    closed.Add(sn);

                                    sn.Island = island;

                                    for (int i = 0; i < sn.NumLinks; i++)
                                    {
                                        if (!closed.Contains(sn.Links[i]) && !open.Contains(sn.Links[i]))
                                        {
                                            open.Enqueue(sn.Links[i]);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    Console.WriteLine("done in {0} seconds.", (DateTime.Now - dt).TotalSeconds);
                }
                catch (Exception ex)
                {
                    LogHelper.LogException(ex);
                    Console.WriteLine("error!");
                    Console.WriteLine(ex);
                }
            }
        }