Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
myddrun
Wanderer


Joined: 31 Mar 2005
Posts: 58

PostPosted: Fri Apr 15, 2011 12:07 pm   

Coordinate Sailing System [with related maths query]
 
My usual MUD has introduced a new sailing system which is 360 degree co-ordinate based, so it doesn't use standard rooms.

I was wondering how difficult it would be to write a set of triggers to set courses headings for general open sea navigation. Not close to land because that would be next to impossible.

When sailing we get a 5x5 coordinate of our location. eg 12345 12345 and we know the location of various ports to the first 3 digits 123 123. (Co-ordinate 4 & 5 aren't really required when you get close enough to see the port on the map).

So if the ship's location is X & Y and the destination is A & B I suppose as a basic system you could use for example

if X<A and Y<B course heading would be NE
if X>A and Y<B course heading would be SE etc

(or something)

It is possible to change heading to 000 (due north) 001 (1 degree east of north ) all the way round to 359 but normally I use 8 point compass directions.

Manual adjustments to steer due N,S,E & W with prudent use of classes to turn triggers on and off and watching a basic map should be possible you think?

I already use buttons to set courses manually so the turning the classes off could be done in here for fine heading corrections.

Any one know of a system and triggers like this for zmud?

EDIT

Just had a thought... I would need to factor in something that doesn't change the heading if I was already sailing in the correct approximate direction. Other wise I would be spamming a non required course change.


Last edited by myddrun on Tue Apr 19, 2011 11:40 am; edited 3 times in total
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4689
Location: Pensacola, FL, USA

PostPosted: Fri Apr 15, 2011 1:48 pm   
 
sounds like
N= 0-23 AND 339-360
ne = 24-68
e=69-113
se 114-158
s = 159-203
sw = 204-248
w= 249-293
nw = 294-338

if you can only sail 4 direction

n= 0-45 AND 316-360
e= 46-135
s= 136-225
w= 226-315

Be nice if you had a grid to plot the points on like a graphing calculator
_________________
Discord: Shalimarwildcat
Reply with quote
myddrun
Wanderer


Joined: 31 Mar 2005
Posts: 58

PostPosted: Fri Apr 15, 2011 3:17 pm   
 
It's not that we can only sail in 4 directions.

There are 360 possible directions to sail in, but as zMud doesn't appear to have any functions for doing co-ordinate maths or calculating angles I think I need to do it this way.

The easiest appears to be using relative changes in X & Y to detmine if I need to sail NE, SE, NW or SW and zig zag to the destination.
Reply with quote
myddrun
Wanderer


Joined: 31 Mar 2005
Posts: 58

PostPosted: Fri Apr 15, 2011 8:53 pm   
 
So with some buttons to switch between manual and auto sailing modes I came up with this. It's not perfect and it doesn't steer around land masses but it got me places. Very Happy

#var direw ""
#var dirns ""
#var currentx %1
#var currenty %2
#if @currentx<(@destx-99) {#var direw e}
#if @currentx>(@destx+99) {#var direw w}
#if @currenty<(@desty-99) {#var dirns n}
#if @currenty>(@desty+99) {#var dirns s}
#var sailingdir %concat( @dirns, @direw)
command heading @sailingdir

this is the sailing output if it works.
# is land
~ is water

.======N======. .......=SeaBreeze=====Schooner=.
|#############| .....|
|######~~##~##| .....| Sails at 0%.
|#####~~~~~~~#| .....| Heading: 180°.
|#~~~~~~~~~~~~| .....| Calculated speed 0
|##~~~~~~~#~#~| .....| Docked, Anchored.
|##~~~~~#~#~#~| .....| Coordinates (29650, 13150)
W~~~~~~+######E ...'===================
|~~~~~~~~~#~#~|
|~~~~~~~~~~~##|
|~~~~~~~~~~~#~|
|~~~~~~~~~~~~~|
|~~~~~~~~~~~~~|
|~~~~~~~~~~~~~|
'======S======'

Edited again to correct the code.


Last edited by myddrun on Sat Apr 16, 2011 8:55 am; edited 1 time in total
Reply with quote
hogarius
Adept


Joined: 29 Jan 2003
Posts: 221
Location: islands.genesismuds.org

PostPosted: Fri Apr 15, 2011 11:19 pm   
 
I'm curious about several things...

1. What MUD is this?

2. All the docking sites are at set positions, correct?

3. How many different locations are there?

4. If all the docking sites are at set positions, wouldn't it be possible to determine the exact heading from each docking site to each nearby docking site?

5. How many docking sites are accessible from any given docking site?

6. Is it possible to set up the docking sites in a rough psuedo-grid, so that you can either speedwalk to a nearby site (or, if necessary, a mid-sea turning point instead), or type, for example, "E" and actually sail at a heading of 87 degrees for a distance of 63 miles?
Reply with quote
myddrun
Wanderer


Joined: 31 Mar 2005
Posts: 58

PostPosted: Sat Apr 16, 2011 8:53 am   
 
1) This is Realms of the Dragon. Been around for ages.

2) Yes each dock is at a specific location

3) About 12 diffent docks most on the main continent and seperate islands have 1 or 2 each depending on size.

4) You could by hand using trig, pythagarus and a calculator. I can't find any maths functions in zmud that well let me do this. hence
the botch job. I suppose you could call external functions by that's out side my knowledge.

5) Not quite sure I understand. But all ports can be sailed to from all other ports. There are no enclosed lakes with their own docks.

6) No not really. As there are no rooms, you can't speed walk. You might be able to hand code your own way points but you'll need to work out how to intersect your not quite excat location with an area not exact XY coordinate. Because this is a mud the screen scrolls from bottom just like any other so the map is static. With net lag and variations in ship speed it would be next to impossible to get to an exact location so you would need to set an area.

It's quite a new sailing system and at the moment you can't say "sail for 63 miles heading 87 deg" wold be cool if you could though.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4689
Location: Pensacola, FL, USA

PostPosted: Sat Apr 16, 2011 2:27 pm   
 
So how do you know when you have stopped sailing?
There should be some sort of messaging you can use to #say {recalculate and change course}

Or is it just time based?
You could always figure out the speed of each vessel and use that to caculate how much $time till you need to check again with a single fire #alarm.
_________________
Discord: Shalimarwildcat
Reply with quote
hogarius
Adept


Joined: 29 Jan 2003
Posts: 221
Location: islands.genesismuds.org

PostPosted: Sat Apr 16, 2011 4:37 pm   
 
Here's what I'm thinking.

1. Each dock can be thought of as a "room" on the map.

2. Although theoretically there are 360 exits for each dock/room (one for each degree of heading), we are really only interested in the ones that lead to other docks.

3. Eventually, either through calculating the exact headings or through repeated trial and error, we should be able to figure out how to go from one point to another in a single shot, without having to zigzag our way to each destination. We don't really use zMUD or the mapper to "calculate" this; we either use a piece of graph paper, or just pay attention to what almost works the first time and make adjustments each subsequent time we make the same trip.

4. When we get to the point where we know the headings from each dock to each other dock, will we really need a automated zScript sailing system? Might it be quicker or easier to just automatically, instictively, type in "Heading XXX" when we are at Dock A and want to go to Dock B?

I'm intrigued by this, Myddrun. I'm also wondering if I'm just full of crap. : /
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4689
Location: Pensacola, FL, USA

PostPosted: Sat Apr 16, 2011 5:50 pm   
 
Odds are there are obstacles to sail around as well, so you need to plot a course to various (likely unseen) buoys and then change heading again based on final destination.

According to the ascii map, it looks like you do have rooms, its just a matter of actually trying to capture all that into a complete whole.... even just maping the edges of the land masses could do wonders to assist your getting the courses perfect.
_________________
Discord: Shalimarwildcat
Reply with quote
myddrun
Wanderer


Joined: 31 Mar 2005
Posts: 58

PostPosted: Sat Apr 16, 2011 6:34 pm   
 
Well I suppose there are Rooms to in some respects on the map. Each character on the map has a predefined boundry.

In terms of docking the boat, as soon as you replace the character used for the Dock with the + sign you see in the middle of my example you are there. But in terms of sailing there are no walls, no n,s,e,w, etc and it takes time to get from one room to another depending on direction and speed.

You could write code to sailing in 1 direction for x seconds, change direction, sail more, but you need to factor in the skill the character has in sailing. The less experienced you are the more likely you are to sail off course.... I think. Fortunately you still get to know your accurate coordinate location) but I have a feeling the coders are going to make that a bit less accurate too.

I'm pretty new to this sailing system, in fact any MUD sailing system. Once I learn the coordinates for each dock it may well be easy just to change direction by hand. I just like tinkering with stuff.

And yes there is geography to sail around, so it's not like all you need to do is pick a single heading from one dock to another.
Reply with quote
myddrun
Wanderer


Joined: 31 Mar 2005
Posts: 58

PostPosted: Sat Apr 16, 2011 6:37 pm   
 
Double post due to router problems. It lost connection in the middle of submitting. Deleted.
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Sat Apr 16, 2011 11:34 pm   
 
Here's a function to make arctan available using vbscript, converted from radians to degrees. With this and some basic trig, you should be able to plot the angle between any two coordinates exactly.

#FUNC atn {%mss(round( atn( %1) * 180 / 3.141592654))}

Input: #PRINT @atn(1)
Output: 45

Input: #PRINT @atn(1.7)
Output: 60

sin() cos() and tan() are also availble through vbscript
Reply with quote
myddrun
Wanderer


Joined: 31 Mar 2005
Posts: 58

PostPosted: Mon Apr 18, 2011 7:39 am   
 
*ponders*
Drax... Maths isn't a strong point for me but I'll look in to it. Thanks :)
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Mon Apr 18, 2011 10:05 am   
 
I was pretty good at math...

Here's a semi functional script to help you out. I tried to add most of the info as comments in to the script itself but couldn't get it to parse properly so the comments are in this post instead.

// Syntax: navigate x y a b
// where x and y are the current coordinates as expressed by a 5 digit number and
// a and b are destination coordinates as expressed by a 3 digit number.
// Sets @course in degrees where 0 is north, 90 is east, 180 is south and 270 is west.
//
// opposite = x - a
// adjacent = y - b
// angle = arctan( opposite / adjacent)

Code:
#CLASS {navigation}
#ALIAS navigate {#IF (%2 = (%4*100)) {#NOOP // already at destination or course is due north or due south. This check prevents a divide by 0 error;#IF (%1 > (%3 * 100)) {#VAR course 180} {#VAR course 0}} {#VAR angle @atn(%abs((%1 - (%3 * 100.0)) / (%2 - (%4 * 100.0))));#IF (%1 < (%3*100) & %2 < (%4*100)) {#NOOP // between north and east;#VAR course %eval( 0 + @angle)};#IF (%1 < (%3*100) & %2 > (%4*100)) {#NOOP // between east and south;#VAR course %eval( 180 - @angle)};#IF (%1 > (%3*100) & %2 > (%4*100)) {#NOOP // between south and west;#VAR course %eval( 180 + @angle)};#IF (%1 > (%3*100) & %2 < (%4*100)) {#NOOP // between west and north;#VAR course %eval( 360 - @angle)}};#SAY To sail from %1,%2 to %3,%4 set a course of @course}
#VAR atn {%mss(round( atn( %1) * 180 / 3.141592654))}
#VAR angle {0}
#VAR course {0}
#CLASS 0
Reply with quote
myddrun
Wanderer


Joined: 31 Mar 2005
Posts: 58

PostPosted: Mon Apr 18, 2011 10:42 am   
 
Wow... Ok.

I'll have to get that in to zmud of course and have to change it a little as I fire my orginal code using a trigger not by alias. But many thanks!
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Mon Apr 18, 2011 11:39 am   
 
No problem
Reply with quote
myddrun
Wanderer


Joined: 31 Mar 2005
Posts: 58

PostPosted: Tue Apr 19, 2011 12:00 pm   
 
With thanks to Drax I've got the code to suit my triggers, but now I want to check a related maths query.
Obviously with compass bearings there is no -5 degrees. From 000 (north) anticlockwise it goes to 359, 358 etc.

I'm going to add some buttons that with tweak the direction so getting the maths right for adding and subtracting degrees when close to due north needs a little work.

So if @sailingcourse is the current course & @newheading is going to be the new one I think this should work.

For a negative change of say 5 degree:

Code:
#If ((@sailingcourse-5) < 0) {#var newheading 359-(%abs(@sailingcourse - 5))}


and for a positive change of 5 degrees

Code:
#If ((@sailingcourse + 5) > 359) {
#var temp (359-@sailingcourse)
#var newheading (0 + %abs(@temp -5)}


Can anyone see an easier way?
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Tue Apr 19, 2011 3:55 pm   
 
Code:
#ALIAS setcourse {#IF (%begins( %1, "+") | %begins( %1, "-")) {#VAR sailingcourse %eval( @sailingcourse + %1)} {#VAR sailingcourse %1};#IF (@sailingcourse < 0) {#ADD sailingcourse 360};#IF (@sailingcourse > 359) {#ADD sailingcourse -360};#VAR sailingcourse %concat(%repeat("0", %eval(3 - %len(@sailingcourse))), @sailingcourse);#SAY Course is now @sailingcourse}


I think this is the easiest way for you to set things up. This way you can have your triggers and buttons all calling the same alias.

Syntax is:
setcourse n to make n your new course, eg. setcourse 315 makes you turn northwest
setcourse +n to turn n degrees to the right, eg setcourse +90 makes you turn from northwest (course 315) to northeast (course 045)
setcourse -n to turn n degrees to the left, eg setcourse -90 makes you turn from northeast (course 045) to northwest (course 315)
I also added a bit to pad the course with 0's so it's always three digits. Your first post suggested that was what the mud wanted.
Reply with quote
myddrun
Wanderer


Joined: 31 Mar 2005
Posts: 58

PostPosted: Wed Apr 27, 2011 12:30 pm   
 
Not overly keen on merging the aliases like that, but I now have it working so all is good.

It's just the way I am Very Happy
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net