- Joined
- Oct 9, 2015
- Messages
- 721
I need it so I can use it with normal world editor
JASS:
//TESH.scrollpos=0
//TESH.alwaysfold=0
library TerrainPathability initializer Initialization
globals
private constant real MAX_RANGE = 10.
private constant integer DUMMY_ITEM_ID = 'wolg'
endglobals
globals
private item Item = null
private rect Find = null
private item array Hid
private integer HidMax = 0
public real X = 0.
public real Y = 0.
endglobals
function IsTerrainDeepWater takes real x, real y returns boolean
return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)
endfunction
function IsTerrainShallowWater takes real x, real y returns boolean
return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) and IsTerrainPathable(x, y, PATHING_TYPE_BUILDABILITY)
endfunction
function IsTerrainLand takes real x, real y returns boolean
return IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY)
endfunction
function IsTerrainPlatform takes real x, real y returns boolean
return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_BUILDABILITY)
endfunction
private function HideItem takes nothing returns nothing
if IsItemVisible(GetEnumItem()) then
set Hid[HidMax] = GetEnumItem()
call SetItemVisible(Hid[HidMax], false)
set HidMax = HidMax + 1
endif
endfunction
function IsTerrainWalkable takes real x, real y returns boolean
call MoveRectTo(Find, x, y)
call EnumItemsInRect(Find ,null, function HideItem)
call SetItemPosition(Item, x, y)
set X = GetItemX(Item)
set Y = GetItemY(Item)
call SetItemVisible(Item, false)
loop
exitwhen HidMax <= 0
set HidMax = HidMax - 1
call SetItemVisible(Hid[HidMax], true)
set Hid[HidMax] = null
endloop
return (X-x)*(X-x)+(Y-y)*(Y-y) <= MAX_RANGE*MAX_RANGE and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)
endfunction
private function Initialization takes nothing returns nothing
set Find = Rect(0., 0., 128., 128.)
set Item = CreateItem(DUMMY_ITEM_ID, 0, 0)
call SetItemVisible(Item, false)
endfunction
endlibrary
JASS:
//TESH.scrollpos=24
//TESH.alwaysfold=0
function Trig_Multiplayer_Camera_Actions takes nothing returns nothing
local boolean b //The pathing boolean
local integer i = 1 //The player index counter
local location l = Location(0,0) //A point used to detect height
local real v //The distance of the camera
local real x //Coordinates x,y,z of two points
local real y
local real z
local real x1
local real y1
local real z1
loop
if udg_camera_target_unit[i] != null and (GetWidgetLife(udg_camera_target_unit[i]) > 0.405) then
set v = 25 //We set the minimum distance to 25
set x = GetUnitX(udg_camera_target_unit[i]) //Get the x coordinate of the unit wich has the camera on it
set y = GetUnitY(udg_camera_target_unit[i]) //Get the y coordinate of the unit wich has the camera on it
call MoveLocation(l,x,y) //We move the l point to the units coordinates
set z = GetLocationZ(l) // store the heignt as z
set x1 = x + 64 * Cos((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
set y1 = y + 64 * Sin((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
call MoveLocation(l,x1,y1)
set z1 = GetLocationZ(l) //We find the point right in front of the unit's camera and get its height
loop //Here begins the main loop for all players
set x1 = x - v * Cos((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
set y1 = y - v * Sin((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
set b = IsTerrainWalkable(x1, y1) // This part uses the library I implemented to see is the point behind the unit in distance v is pathable
if (b == false) then
set b = IsTerrainDeepWater(x1, y1) // We dont want to avoid water right...
endif
if (GetUnitFlyHeight(udg_camera_target_unit[i]) > 0) then
set b = true
endif // This is just to avoid distance changes if the unit is in the air
if ((b == true) and (v < 250)) then
set v = v + 25
elseif ((b == false) or (v == 250)) then
exitwhen true // This increases the camera distance until the system detects a non-pathable point.
// Max distance can be changed, its the 450 integer
endif
endloop
if GetLocalPlayer() == Player(i - 1) then //Make the system do the folowing stuff only for one player at the time
call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i], 0.5) //Set the rotation of the cam to the units+our rotation wish
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, v, 0.2) //Set the distance to v
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, 335 + ((z1 - z) * 0.5), 0.32) //This is meant for the player to be able to see the "top of the mountain"
call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, 120, 0)
call SetCameraField(CAMERA_FIELD_FARZ, 5000, 5) //How far the player will be able to see
call SetCameraTargetController(udg_camera_target_unit[i], 0, 0, false) //Locks the camera to the unit
call SetCameraField(CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(udg_camera_target_unit[i]) + GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + 128, -0.06)
call SetCameraField(CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(udg_camera_target_unit[i]) + GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + 128, 0.06) //Height of the camera is adjusted here
endif
endif
exitwhen i == 12 // Change the value here for more players eg: i==9 for nine players
set i = i + 1 //Next player is set
call RemoveLocation(l) //We dont want leaks of points
endloop //Loop ends for one player and starts for another
set l = null //We remove the previous l
endfunction
function InitTrig_Multiplayer_Camera takes nothing returns nothing
set gg_trg_Multiplayer_Camera = CreateTrigger( )
call TriggerRegisterTimerEvent(gg_trg_Multiplayer_Camera,0.06,true) //You can change the time if you want the cam to be faster
call TriggerAddAction( gg_trg_Multiplayer_Camera, function Trig_Multiplayer_Camera_Actions )
endfunction
Last edited by a moderator: