ServUO Version
Publish Unknown
Ultima Expansion
None
Not sure how to go about this one...

What i'm wanting is to be able to drop a item around a boundary on a map.

I have the X, Y map cords for the start point and the width & height, like a EndX, EndY location... it works kind of like defining a region.
What i'm wanting to do is outline the region and drop boundary markers around it.

How do i get it to follow the terrain for the Z axis and place the markers on the terrain ?
Is there a way to get the Z value for the surface ?

Image to better explain it...
drop.jpg


Thanks in advance ;)
 
You can get the landtile Z with this code, and then move the "Caster" to the Z level of that X Y position.

landtile:
LandTile landtile = Caster.Map.Tiles.GetLandTile(box.X, box.Y);
Caster.MoveToWorld(new Point3D(box.X, box.Y, landtile.Z), Caster.Map);
The box would be your Rect3d or whatever.
 
Fixed...

dropfixed.jpg

Got the ideas from Champspawn code...

C#:
public Point3D GetSpawnLocation()
{
    Map map = Map;

    if( map == null )
        return Location;

    // Try 20 times to find a spawnable location.
    for( int i = 0; i < 20; i++ )
    {
        /*
        int x = Location.X + (Utility.Random( (m_SpawnRange * 2) + 1 ) - m_SpawnRange);
        int y = Location.Y + (Utility.Random( (m_SpawnRange * 2) + 1 ) - m_SpawnRange);
        */

        int x = Utility.Random( m_SpawnArea.X, m_SpawnArea.Width );
        int y = Utility.Random( m_SpawnArea.Y, m_SpawnArea.Height );

        int z = Map.GetAverageZ( x, y );

        if( Map.CanSpawnMobile( new Point2D( x, y ), z ) )
            return new Point3D( x, y, z );
    }

    return Location;
}

Gave me a rough idea what i needed so worked a function out for what i was after. Just spits the X,Y,Z back to me.
 
If the location is for spawning an item, you may want to switch from CanSpawnMobile to CanFit, the former checks whether the region accepts spawns or not and can cause it to fail unexpectedly in some areas.
 
CanFit would probably be a better option.

If the 'LandTile landtile = Caster.Map.Tiles.GetLandTile(box.X, box.Y);' gives me the exact tile type at each point on the boundary that might be another option.

This is mainly just to drop the boundary items into the world for the moment to allow me to see where the regions i am making start and finish so i can make the new regions right next to each other. There is another approach i'm looking into for this idea. The main goal of marking out the boundary was to make sure the next region never overlaps the one it sits next to.

I think the region code already does something like this but i'm not sure but if say for example one region overlapped another it can split the regions up into smaller squares.

Kind of like this idea (very rough idea btw...

squares.jpg

Starting with a big green region (square) then dropping the red region on the map but it overlaps the green part (top left area), working out 3 'new' areas (blue) areas. So what happens is it replaces the green region with the 3 blue areas, kind of cutting along the X & Y axis of the red box. Straight down the right side of the red box all the way down to the botton (cutting the green area into 2 parts) and the same left to right along the bottom of the red box cutting the now 2 green parts into 3 and making what was green into blue via 3 new regions covering the same area.

Or this happens, you have 1 region (big green box) and place a new region into the middle of it (red), the green area would need to turn into 8 new areas to allow the red area to become a new region...


squares2.jpg

If i could work out the maths & code to do it this way it would be helpful to say the least.
It's for the Admin side of this idea i''ve built, there mines and this is to define the region the mine sits on for the resource type it pulls from the ground...

mines001.jpg

The regions CANT overlap or the mines wont know what resource to give out.

Shameful advertising... 'Automines, out now on Haven Reborn' ;)
 
Last edited:

Active Shards

Donations

Total amount
$0.00
Goal
$500.00
Back