rendered paste body#ifndef ObjMap
#define ObjMap FukabunMap
#endif
#define GROW_LIMIT 25
#define STATE_MAP_NONE 0
#define STATE_MAP_ZONE_CHANGED 1
#define STATE_MAP_PLOT 2
objectdef FukabunMap inherits ObjBaseObject
{
variable string navigationDir = "${LavishScript.HomeDirectory}/Scripts/Fukabun/etc/"
variable string navigationMap = "map.xml"
variable lnavregionref ZoneRegion
variable lnavregionref CurrentRegion
variable lnavregionref PreviousRegion
member SubZoneText()
{
return ${WoWScript[GetMinimapZoneText()]}
}
member ZoneText()
{
return ${WoWScript[GetRealZoneText()]}
}
member Continent()
{
WoWScript SetMapToCurrentZone()
return ${WoWScript[GetMapContinents(),${WoWScript[GetCurrentMapContinent()]}]}
}
method InitializeRegions()
{
variable string Continent
variable int IdxContinent
variable string Zone
variable int IdxZone
LavishNav.Tree:AddChild[universe,Azeroth,-unique]
IdxContinent:Set[1]
do
{
Continent:Set[${WoWScript[GetMapContinents(),${IdxContinent}]}]
LNavRegion[Azeroth]:AddChild[universe,${Continent},-unique,-coordinatesystem]
IdxZone:Set[1]
do
{
Zone:Set[${WoWScript[GetMapZones(${IdxContinent}),${IdxZone}]}]
LNavRegion[${Continent}]:AddChild[universe,${Zone},-unique]
IdxZone:Inc
}
while ${WoWScript[GetMapZones(${IdxContinent}),${IdxZone}](exists)}
IdxContinent:Inc
}
while ${WoWScript[GetMapContinents(),${IdxContinent}](exists)}
}
method Save()
{
LNavRegion[Azeroth]:Export["${navigationDir}${navigationMap}"]
This:Echo["Fukabun map: saved to: ${navigationDir}${navigationMap}"]
}
method Load()
{
variable filepath navDir = "${navigationDir}"
LavishNav:Clear
if ${navDir.FileExists[${navigationMap}]}
{
if ${LNavRegion[Azeroth](exists)}
{
LNavRegion[Azeroth]:Remove
}
LavishNav:Import["${navigationDir}${navigationMap}"]
This:Echo["Fukabun map: loaded from: ${navigationDir}${navigationMap}"]
}
if !${LNavRegion[Azeroth](exists)}
{
This:InitializeRegions
This:Save
}
}
/*
*
*
*/
member State()
{
if (${This.ZoneRegion.ID} != ${LNavRegion[${This.ZoneText}].ID})
{
return STATE_MAP_ZONE_CHANGED
}
if ((${This.ZoneRegion.ID} == ${This.CurrentRegion.ID}) || ${This.ShouldPlot})
{
return STATE_MAP_PLOT
}
return STATE_MAP_NONE
}
method Pulse()
{
This.PreviousRegion:SetRegion[${This.CurrentRegion.FQN}]
This.CurrentRegion:SetRegion[${This.ZoneRegion.BestContainer[${Me.X},${Me.Y},${Me.Z}].ID}]
This.CurrentState:Set[${This.State}]
switch ${This.CurrentState}
{
case STATE_MAP_ZONE_CHANGED
This:ZoneRegionChanged
break
case STATE_MAP_PLOT
This:PlotBox[${Me.X}, ${Me.Y}, ${Math.Calc[${Me.Z}]}]
break
}
This:UpdateGUI
}
method UpdateGUI()
{
UIElement[edtZone@FukabunMapGUI]:SetText[${This.ZoneRegion.FQN}]
UIElement[edtSector@FukabunMapGUI]:SetText[${This.CurrentRegion.FQN}]
UIElement[edtState@FukabunMapGUI]:SetText[${This.CurrentState}]
}
/*
*
*
*/
method ZoneRegionChanged()
{
variable string Region
This.ZoneRegion:SetRegion[${LNavRegion[${This.ZoneText}].FQN}]
This:Debug["Fukabun map: Zone Region changed to ${This.ZoneRegion.FQN}"]
}
method PlotBox(float cX, float cY, float cZ)
{
variable float X1 = ${cX}
variable float X2 = ${cX}
variable float Y1 = ${cY}
variable float Y2 = ${cY}
variable float Z1 = ${cZ}
variable float Z2 = ${cZ}
variable string PointName
Z1:Set[${Math.Calc[${cZ} + 0.2]}]
Z2:Set[${Math.Calc[${cZ} + 0.4]}]
do
{
X1:Dec
X2:Inc
Y1:Dec
Y2:Inc
}
while !${This.CollisionCheck[${X1},${Y1},${Z1},${X2},${Y2},${Z2}]} && ${Math.Distance[${cX},${X1}]} < GROW_LIMIT
echo "${cX}, ${cY}, ${cZ} :: ${Math.Distance[${X1},${X2}]} : ${Math.Distance[${Y1},${Y2}]} : ${Z1}, ${Z2}"
PointName:Set["P${Time.Timestamp}${This.ZoneRegion.ChildCount}"]
This.ZoneRegion:AddChild[box, ${PointName}, -unique, ${X1}, ${X2}, ${Y1}, ${Y2}, ${Math.Calc[${cZ} - 3]}, ${Math.Calc[${cZ} + 3]}]
if ${This.PreviousRegion.FQN(exists)}
{
This.PreviousRegion:Connect[${PointName}]
LNavRegion[${PointName}]:Connect[${This.PreviousRegion.FQN}]
}
}
member CollisionCheck(float X1, float Y1, float Z1, float X2, float Y2, float Z2)
{
variable float X = ${X1}
variable float Y = ${Y1}
variable float Z = ${Z1}
/*
* [FIXME] Star check \ | / -
*/
for (X:Set[${X1}]; ${X} < ${X2}; X:Inc)
{
if (${This.CollisionTest[${X},${Y1},${Z1},${X},${Y2},${Z2}]})
{
return TRUE
}
}
for (Y:Set[${Y1}]; ${Y} < ${Y2}; Y:Inc)
{
if (${This.CollisionTest[${X},${Y1},${Z1},${X},${Y2},${Z2}]})
{
return TRUE
}
}
return FALSE
}
member CollisionTest(float X1, float Y1, float Z1, float X2, float Y2, float Z2)
{
return ${Me.IsPathObstructed[${X2},${Y2},${Z2},-1,${X1},${Y1},${Z1}]}
}
/*
*
*
*/
method Initialize()
{
This:Load
This:ZoneRegionChanged
}
method Shutdown()
{
This:Save
}
}