PenUltima Online Forum Index Official Core: 096.7
Official Core: 097 2008-02-26
Donate towards the POL web hosting bill!
 POL Home   FAQ   Search    Memberlist   Usergroups    Register    Profile   Log in to check your private messages   Log in
Coordinates

 
Post new topic   Reply to topic    PenUltima Online Forum Index -> Development Discussion 097
Display posts from previous:   

Author Message
itec



Joined: 10 Feb 2006
Posts: 33
Location: Finland

PostPosted: Wed Apr 30, 2008 3:17 pm    Post subject: Coordinates Reply with quote

Here's a topic that I think would need some improvement. Current habit is to use coordinates in four different variables. Instead of that, I suggest everyone to start using coordinates in a struct: {x, y, z, realm} It's more easy to use (takes less time writing), simpler, cleaner. In the end, it would be best if core functions would also act like this, ie:

PlayMovingEffectXYZ( srcloc, dstloc, effect, speed, loop, explode)

instead of:

PlayMovingEffectXYZ( srcx, srcy, srcz, dstx, dsty, dstz, effect, speed, loop, explode, realm )

Quiet a bit neater, eh? Also if we add little bit of polymorphism-like support, you could use UObjects as the first two parameters as well.

To start with, here's a few simple functions.

Code:

/*
   GetCoords
   
   Takes objects location and sets it in a struct.
   
   Returns: struct with x, y, z, and realm.
*/

function GetCoords( object )
   
   return struct{"x" := object.x, "y" := object.y, "z" := object.z, "realm" := object.realm };
   
endfunction

/*
   NewCoords
   
   Easy way to create Coordinate Struct
   
   Returns: coordinate struct
*/

function NewCoords( x, y, z := 0, realm := _DEFAULT_REALM )
   
   return struct{"x" := x, "y" := y, "z" := z, "realm" := realm};
   
endfunction

/*
   SameCoords
   
   To check if two set of coordinates match.
   For example, can be used to check if mobile has moved.
   
   Returns:
      1 if same
      0 if different
*/

function SameCoords( first, second )
   
   return (
      first.x == second.x &&
      first.y == second.y &&
      first.z == second.z &&
      first.realm == second.realm
   );
   
endfunction



Best part is, in many situations UObject is compatible with the Coords Struct.

Post new topic   Reply to topic    PenUltima Online Forum Index -> Development Discussion 097 All times are GMT - 4 Hours
Page 1 of 1

 




Powered by phpBB © 2001, 2005 phpBB Group :: Theme & Graphics by GHS & Scott E. Royalty