- Joined
- Sep 26, 2009
- Messages
- 9,534
JASS:
//! zinc
library Point
{
/**
* The purpose of this snippet is to use "points" that are
* basically coordinate objects that act as locations.
* Designed to be as intuitive and user-friendly as I can,
* this short-and-sweet snippet is a handy little utility.
*
* The x- and y- attributes can be set arbitrarily while
* the z- attribute replaces GetLocationZ() and is there-
* fore readonly.
*
* Type Name: point
*
* Syntax: local point pt = GetWidgetPoint(GetTriggerUnit())
* local real z = GetTerrainZ(GetSpellTargetX(), GetSpellTargetY())
*
* API:
*
* CreatePoint(real x, real y) -> creates a new set of coordinates.
* DestroyPoint(point pt) -> destoys the set.
*
* Point2Loc(point pt) -> if you somehow need a location parameter,
* this provides you with one that does not need to be destroyed.
* Unreliable after a wait period.
* Loc2Point(location loc) -> reverse of the above function call.
*
* GetTerrainZ(real x, real y) -> get the elevation of specified coordinates.
*
* GetSpellPoint() -> user-friendly creator.
* GetOrderPoint() -> user-friendly creator.
* GetWidgetPoint(widget w) -> user-friendly creator.
*
* Textmacros:
*
* //! runtextmacro GetLocationZ("x", "y", "z")
* //! runtextmacro GetZincLocationZ("x", "y", "z")
*
* Object Attributes:
*
* pt.x -> x-coordinate.
* pt.y -> y-coordinate.
* pt.z -> z-coordinate (readonly).
*/
public struct point
{
private static location loc = Location(0.0, 0.0);
static method setPointZ(real x, real y) {
MoveLocation(point.loc, x, y);
}
static method getPointZ() -> real {
return GetLocationZ(point.loc);
}
real x;
real y;
method operator z() -> real
{
point.setPointZ(this.x, this.y);
return point.getPointZ();
}
}
public function CreatePoint(real x, real y) -> point
{
point pt = point.create();
pt.x = x;
pt.y = y;
return pt;
}
public function DestroyPoint(point pt)
{
pt.x = 0.0;
pt.y = 0.0;
pt.destroy();
}
public function GetTerrainZ(real x, real y) -> real
{
point.getPointZ(x, y);
return point.getPointZ();
}
//! textmacro GetLocationZ takes ValueX, ValueY, VariableNameZ
call point.setPointZ($ValueX$, $ValueY$)
set $VariableNameZ$ = point.getPointZ()
//! endtextmacro
//! textmacro GetZincLocationZ takes ValueX, ValueY, VariableNameZ
point.setPointZ($ValueX$, $ValueY$);
$VariableNameZ$ = point.getPointZ();
//! endtextmacro
public location Point_Loc = null;
public function Point2Loc(point pt) -> location
{
if(Point_Loc == null)
{
Point_Loc = Location(pt.x, pt.y);
}
else
{
MoveLocation(Point_Loc, pt.x, pt.y);
}
return Point_Loc;
}
public function Loc2Point(location loc) -> point
{
point pt = point.create();
pt.x = GetLocationX(loc);
pt.y = GetLocationY(loc);
return pt;
}
public function GetWidgetPoint(widget w) -> point
{
point pt = point.create();
pt.x = GetWidgetX(w);
pt.y = GetWidgetY(w);
return pt;
}
public function GetSpellPoint() -> point
{
point pt = point.create();
pt.x = GetSpellTargetX();
pt.y = GetSpellTargetY();
return pt;
}
public function GetOrderPoint() -> point
{
point pt = point.create();
pt.x = GetOrderPointX();
pt.y = GetOrderPointY();
return pt;
}
}
//! endzinc
Last edited: