All pastes #251188 Raw Edit

Something

public text v1 · immutable
#251188 ·published 2006-11-17 21:22 UTC
rendered paste body
#define MAPPER_NONE 0
#define MAPPER_MAP 1

objectdef oMapper inherits oBase
{
	variable string ConfigDir = "c:/program files/innerspace/scripts/bytebot/map/"
	
	variable int CurrentState = 0
	
	variable point3f CurrentLocation
	variable lnavregionref CurrentZone
	variable lnavregionref CurrentSubZone
	variable lnavregionref CurrentRegion
	
        member SubZoneText()
        {
                return ${WoWScript[GetMinimapZoneText()]}
        }

        member ZoneText()
        {
                return ${WoWScript[GetRealZoneText()]}
        }

        member Continent()
        {
                WoWScript SetMapToCurrentZone()
		if ${WoWScript[GetMapContinents(),${WoWScript[GetCurrentMapContinent()]}](exists)}
		{
			return ${WoWScript[GetMapContinents(),${WoWScript[GetCurrentMapContinent()]}]}
		}
        }

        method InitializeRegions()
        {
                variable string Continent
                variable int IdxContinent
                variable string Zone
                variable int IdxZone

                if ${LNavRegion[Azeroth](exists)}
                {
                        LNavRegion[Azeroth]:Remove
                }
                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()
        {
		variable lnavregionref CurrentContinent
		variable lnavregionref CurrentZone
	 ;-lso first
		if ${LNavRegion[Azeroth].Children(exists)}
		{
			CurrentContinent:SetRegion[${LNavRegion[Azeroth].Children}]
			do
			{
				if ${CurrentContinent.Children(exists)}
				{
					CurrentZone:SetRegion[${CurrentContinent.Children}]
					do
					{
						if ${CurrentZone.ChildCount} > 0
						{
							CurrentZone:Export[-lso,"${This.ConfigDir}${CurrentContinent.Name}.${CurrentZone.Name}.lso"]
						}
						CurrentZone:SetRegion[${CurrentZone.Next}]
					}
					while ${CurrentZone.Region(exists)}
				}
				CurrentContinent:SetRegion[${CurrentContinent.Next}]
			}
			while ${CurrentContinent.Region(exists)}
		}
        }

        method LoadZone(string Continent, string ZoneName)
        {
                variable filepath Dir = "${ConfigDir}"
		variable lnavregionref ZoneRef
		ZoneRef:SetRegion[${ZoneName}]

                if ${Dir.FileExists["${Continent}.${ZoneRef.Name}.lso"]} && ${ZoneRef.ChildCount} <= 1
                {
			ZoneRef:Import[-lso,"${This.ConfigDir}${Continent}.${ZoneRef.Name}.lso"]
			This:Debug["Importing file: ${Continent}.${ZoneRef.Name}.lso"]
                }
        }

	/*
	 *
	 *
	 *
	 *
	 */

	 method Map()
	 {
		variable point3f C1
		variable point3f C2
		variable int ConnectionCount
		variable string PointName

		C1.X:Set[${This.CurrentLocation.X}]
		C1.Y:Set[${This.CurrentLocation.Y}]
		C1.Z:Set[${This.CurrentLocation.Z} - 0.1]
		
		C2.X:Set[${This.CurrentLocation.X}]
		C2.Y:Set[${This.CurrentLocation.Y}]
		C2.Z:Set[${This.CurrentLocation.Z} + 0.1]
		
		do
		{
			C1.X:Dec
			C2.X:Inc
			C1.Y:Dec
			C2.Y:Inc
		}
		while !${This.BoxObstructed[${C1.X},${C1.Y},${C1.Z},${C2.X},${C2.Y},${C2.Z},FALSE]} && ${Math.Distance[${C1.X},${C2.X}]} < 16 

		C1.X:Inc
		C2.X:Dec
		C1.Y:Inc
		C2.Y:Dec

		do
		{
			C2.Z:Set[${Math.Calc[${C2.Z} + 1]}]
		}
		while !${This.BoxObstructed[${C1.X},${C1.Y},${C1.Z},${C2.X},${C2.Y},${C2.Z},FALSE]} && ${Math.Distance[${C1.Z},${C2.Z}]} < 16 
		C2.Z:Set[${Math.Calc[${C2.Z} - 1]}]
	
		do
		{
			C1.Z:Set[${Math.Calc[${C1.Z} - 0.1]}]
		}
		while !${This.BoxObstructed[${C1.X},${C1.Y},${C1.Z},${C2.X},${C2.Y},${C2.Z},FALSE]} && ${Math.Distance[${C1.Z},${C2.Z}]} < 16 
		C1.Z:Set[${Math.Calc[${C1.Z} + 0.1]}]
		
		if ${Math.Distance[${C1.X},${C2.X}]} > 0
		{
			PointName:Set["${This.CurrentSubZone.FQN}-${This.CurrentSubZone.ChildCount}"]
			This.CurrentSubZone:AddChild[box, ${PointName}, -unique, ${C1.X}, ${C2.X}, ${C1.Y}, ${C2.Y}, ${C1.Z}, ${C2.Z}]
			ConnectionCount:Set[${This.ConnectNeighbours[${PointName}]}]
			This:Debug["Region Added: ${PointName} ${Math.Distance[${C1.X},${C2.X}]} ${Math.Distance[${C1.Y},${C2.Y}]} ${Math.Distance[${C1.Z},${C2.Z}]}, ${ConnectionCount} connections"]
			if ${ConnectionCount} == 0
			{
;				WoWScript message("${PointName} has 0 connections")
			}
		}
	 }

	member BoxObstructed(float X1, float Y1, float Z1, float X2, float Y2, float Z2, bool Contents = FALSE)
	{
		variable float MiddleX
		variable float MiddleY

		if ${Contents}
		{
			if ${X1} > ${X2}
			{
				MiddleX:Set[${Math.Calc[(${X1} - ${X2}) / 2]}]
				MiddleX:Set[${Math.Calc[${MiddleX} + ${X2}]}]
			} 
			else
			{
				MiddleX:Set[${Math.Calc[(${X2} - ${X1}) / 2]}]
				MiddleX:Set[${Math.Calc[${MiddleX} + ${X1}]}]
			}

			if ${Y1} > ${Y2}
			{
				MiddleY:Set[${Math.Calc[(${Y1} - ${Y2}) / 2]}]
				MiddleY:Set[${Math.Calc[${MiddleY} + ${Y2}]}]
			}
			else
			{
				MiddleY:Set[${Math.Calc[(${Y2} - ${Y1}) / 2]}]
				MiddleY:Set[${Math.Calc[${MiddleY} + ${Y1}]}]
			}

			if ${This.CollisionTest[${X1},${Y1},${Z1},${X2},${Y2},${Z2}]}
			{
				return TRUE
			}

			if ${This.CollisionTest[${X1},${Y2},${Z1},${X2},${Y1},${Z2}]}
			{
				return TRUE
			}

			if ${This.CollisionTest[${MiddleX},${Y1},${Z1},${MiddleX},${Y2},${Z2}]}
			{
				return TRUE
			}

			if ${This.CollisionTest[${X1},${MiddleY},${Z1},${X2},${MiddleY},${Z2}]}
			{
				return TRUE
			}
		}

		if ${This.CollisionTest[${X1},${Y1},${Z1},${X2},${Y1},${Z2}]}
		{
			return TRUE
		}

		if ${This.CollisionTest[${X1},${Y2},${Z1},${X2},${Y2},${Z2}]}
		{
			return TRUE
		}

		if ${This.CollisionTest[${X1},${Y1},${Z1},${X1},${Y2},${Z2}]}
		{
			return TRUE
		}

		if ${This.CollisionTest[${X2},${Y1},${Z1},${X2},${Y2},${Z2}]}
		{
			return TRUE
		}

		return FALSE
	}

	member CollisionTest(float FromX, float FromY, float FromZ, float ToX, float ToY, float ToZ)
	{
		return ${Me.IsPathObstructed[${ToX},${ToY},${ToZ},999,${FromX}, ${FromY}, ${FromZ}]}
	}
	
	member ConnectNeighbours(string RegionName)
	{
		variable index:lnavregionref SurroundingRegions
		variable lnavregionref Region
		variable int RegionsFound
		variable int Index = 1
		variable int ConnectionCount = 0
		
		Region:SetRegion[${RegionName}]
		RegionsFound:Set[${LNavRegion[${This.Continent}].DescendantsWithin[SurroundingRegions,${Math.Calc[${Math.Distance[${Region.X1},${Region.X2}]} * 2]},${Region.CenterPoint.X},${Region.CenterPoint.Y},${Region.CenterPoint.Z}]}]

		if ${RegionsFound} > 0
		{
			do
			{
				if ${This.ShouldConnect[${Region.FQN},${SurroundingRegions.Get[${Index}].FQN}]}
				{
					ConnectionCount:Inc
					Region:Connect[${SurroundingRegions.Get[${Index}].FQN}]
					SurroundingRegions.Get[${Index}]:Connect[${Region.FQN}]
				}
			}
			while ${SurroundingRegions.Get[${Index:Inc}](exists)}
		}

		return ${ConnectionCount}
	}

	member ShouldConnect(string RegionA, string RegionB)
	{
		variable lnavregionref RegionRefA
		variable lnavregionref RegionRefB
		
		if ${RegionA.Equal[${RegionB}]}
		{
			return FALSE
		}
	
		RegionRefA:SetRegion[${RegionA}]
		RegionRefB:SetRegion[${RegionB}]
		
		if ${This.RegionsObstructed[${RegionA},${RegionB}]}
		{
			return FALSE
		}
		
		return TRUE
	}

	member RegionsObstructed(string RegionA, string RegionB)
	{
		variable lnavregionref RegionRefA
		variable lnavregionref RegionRefB
		
		RegionRefA:SetRegion[${RegionA}]
		RegionRefB:SetRegion[${RegionB}]

		if ${RegionRefA.Type.NotEqual["Box"]} || ${RegionRefB.Type.NotEqual["Box"]}
		{
			return TRUE
		}
		
		if ${This.CollisionTest[${RegionRefA.X1},${RegionRefA.Y1},${RegionRefA.CenterPoint.Z},${RegionRefB.X1},${RegionRefB.Y1},${RegionRefB.CenterPoint.Z}]}
		{
			return TRUE
		}

		if ${This.CollisionTest[${RegionRefA.X2},${RegionRefA.Y1},${RegionRefA.CenterPoint.Z},${RegionRefB.X2},${RegionRefB.Y1},${RegionRefB.CenterPoint.Z}]}
		{
			return TRUE
		}

		if ${This.CollisionTest[${RegionRefA.X1},${RegionRefA.Y2},${RegionRefA.CenterPoint.Z},${RegionRefB.X1},${RegionRefB.Y2},${RegionRefB.CenterPoint.Z}]}
		{
			return TRUE
		}

		if ${This.CollisionTest[${RegionRefA.X2},${RegionRefA.Y2},${RegionRefA.CenterPoint.Z},${RegionRefB.X2},${RegionRefB.Y2},${RegionRefB.CenterPoint.Z}]}
		{
			return TRUE
		}
		
		return FALSE
	}
	
	/*
	 *
	 *
	 *
	 *
	 */
	 
	method ZoneChanged()
	{
		This:Debug["Zone changed to ${This.ZoneText}"]
		if !${LNavRegion[${This.ZoneText}](exists)}
		{
			LNavRegion[${This.Continent}]:AddChild[universe,${This.ZoneText},-unique]
		}
		This.CurrentZone:SetRegion[${LNavRegion[${This.ZoneText}].FQN}]
		This:LoadZone[${This.Continent},${This.CurrentZone.Name}]
	}
	
	method SubZoneChanged()
	{
		This:Debug["SubZone changed to ${This.SubZoneText}"]
		if !${LNavRegion[${This.SubZoneText}](exists)}
		{
			This.CurrentZone:AddChild[universe,${This.SubZoneText},-unique]
		}
		This.CurrentSubZone:SetRegion[${LNavRegion[${This.SubZoneText}].FQN}]
	}
	
	member ShouldMap()
	{
		if !${Me(exists)} || ${Me.Flying}
		{
			return FALSE
		}
	
		if ${This.CurrentSubZone.ID} != ${This.CurrentRegion.ID}
		{
			return FALSE
		}
		
		return TRUE
	}
	
	method SetCurrentRegion()
	{
		This.CurrentLocation.X:Set[${Me.X}]
		This.CurrentLocation.Y:Set[${Me.Y}]
		This.CurrentLocation.Z:Set[${Me.Z} + ${Math.Calc[${Me.Height} / 2]}]
		
		This.CurrentRegion:SetRegion[${This.CurrentSubZone.BestContainer[${This.CurrentLocation.X},${This.CurrentLocation.Y},${This.CurrentLocation.Z}].ID}]
	}
	
	member State()
	{
		if ${This.ShouldMap}
		{
			return MAPPER_MAP
		}
	
		return MAPPER_NONE
	}
	
	method Pulse()
	{
		This:SetCurrentRegion
		
		This.CurrentState:Set[${This.State}]
		
		switch ${This.CurrentState}
		{
			case MAPPER_MAP
				This:Map
				break
			case MAPPER_NONE
				break
		}
	}

	method Plugin()
	{
		This:InitializeRegions
		This:ZoneChanged
		This:SubZoneChanged
		This:SetCurrentRegion
		
		AddTrigger ${This.ObjectName}:ZoneChanged "[Event:204:ZONE_CHANGED]"
		AddTrigger ${This.ObjectName}:SubZoneChanged "[Event:207:MINIMAP_ZONE_CHANGED]"
		Event[CORE_EVENT_PULSE]:AttachAtom[${This.ObjectName}:Pulse]
	}
	
	method Shutdown()
	{
		Event[CORE_EVENT_PULSE]:DetachAtom[${This.ObjectName}:Pulse]
		This:Save
	}
	
}