/* System by The_Witcher. Modified by Magtheridon96 */
constant function Camera_GetDelay takes nothing returns real
return 0.25
endfunction
constant function Camera_GetNormalHeight takes nothing returns real
return 300.
endfunction
constant function Camera_GetAccuracy takes nothing returns real
return 50.
endfunction
constant function Camera_ExtremeAccuracy takes nothing returns real
return 10.
endfunction
function Camera_hideAll takes nothing returns nothing
local item i = GetEnumItem()
if IsItemVisible(i) then
call SaveBoolean(udg_cam_tb, GetHandleId(i), 0, true)
endif
call SetItemVisible(i, false)
set i = null
endfunction
function Camera_showAll takes nothing returns nothing
local integer id = GetHandleId(GetEnumItem())
if LoadBoolean(udg_cam_tb, id, 0) then
call SetItemVisible(GetEnumItem(), true)
call SaveBoolean(udg_cam_tb, id, 0, false)
endif
endfunction
function Camera_isPointPathable takes real x, real y returns boolean
local item i = CreateItem('wolg', 0, 0)
call SetItemPosition(i, x, y)
set x = GetItemX(i) - x
set y = GetItemY(i) - y
call RemoveItem(i)
return x < 1 and x > -1 and y < 1 and y > -1
endfunction
function Camera_iterate takes nothing returns nothing
local real x = GetUnitX(udg_cam_camUnit)
local real y = GetUnitY(udg_cam_camUnit)
local real angle = (GetUnitFacing(udg_cam_camUnit) - 180) * bj_DEGTORAD
local real cos = Cos(angle)
local real sin = Sin(angle)
local real rz = 0
local real z = 0
local real checkDistance = Camera_GetAccuracy()
local real distanceDone = 0
local boolean check = true
local rect area = Rect(0,0,0,0)
local location loc = Location(0,0)
loop
set x = x + checkDistance * cos
set y = y + checkDistance * sin
set distanceDone = distanceDone + checkDistance
call MoveLocation(loc, x, y)
set z = GetLocationZ(loc)
if RAbsBJ(z) > RAbsBJ(rz) and distanceDone <= udg_cam_checkDist then
set rz = z
endif
if not Camera_isPointPathable(x, y) then
call SetRect(area, x - Camera_GetAccuracy(), y - Camera_GetAccuracy(), x + Camera_GetAccuracy(), y + Camera_GetAccuracy())
call EnumItemsInRect(area, null, function Camera_hideAll)
if not Camera_isPointPathable(x, y) then
set check = false
endif
endif
if not check and checkDistance == Camera_GetAccuracy() then
set distanceDone = distanceDone - checkDistance
set x = x - checkDistance * cos
set y = y - checkDistance * sin
set check = false
set checkDistance = Camera_ExtremeAccuracy()
endif
exitwhen (not check and checkDistance == Camera_ExtremeAccuracy()) or distanceDone > udg_cam_distance
endloop
call MoveLocation(loc, GetUnitX(udg_cam_camUnit), GetUnitY(udg_cam_camUnit))
set x = GetLocationZ(loc)
set z = Atan2(x - rz, 200) * bj_RADTODEG + udg_cam_angleOfAttack
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, distanceDone, Camera_GetDelay())
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, z, Camera_GetDelay())
call SetCameraField(CAMERA_FIELD_ZOFFSET, GetCameraField(CAMERA_FIELD_ZOFFSET) + x + GetUnitFlyHeight(udg_cam_camUnit) + Camera_GetNormalHeight() - GetCameraTargetPositionZ(), Camera_GetDelay())
call SetCameraField(CAMERA_FIELD_ROTATION, angle * bj_RADTODEG + 180, Camera_GetDelay())
call SetCameraTargetController(udg_cam_camUnit, 0, 0, false)
call EnumItemsInRect(bj_mapInitialPlayableArea, null, function Camera_showAll)
call RemoveRect(area)
call RemoveLocation(loc)
set loc = null
set area = null
endfunction
function Camera_Start takes nothing returns nothing
call TimerStart(udg_cam_timer, 0.03125, true, function Camera_iterate)
endfunction
function Camera_Stop takes nothing returns nothing
call PauseTimer(udg_cam_timer)
endfunction
function InitTrig_Camera takes nothing returns nothing
set udg_cam_angleOfAttack = -5
set udg_cam_distance = 300
set udg_cam_checkDist = 300
set udg_cam_tb = InitHashtable()
call CameraSetSmoothingFactor(1)
endfunction