function GetTileCenterCoordinate takes real a returns real
if (a >= 0.) then
set a = R2I((a/128) + .5)
else
set a = R2I((a/128) - .5)
endif
return a*128
endfunction
//GetTerrainTypeInRange by Ardenian
function GetWaterDepth takes real x, real y returns real
local real z
local integer PLATFORM = 'LT06'
local real PLATFORM_HEIGHT = 2745.46265
local destructable d
local location p = Location(0.0, 0.0)
call MoveLocation(p, x, y)
set z = GetLocationZ(p)
set d = CreateDestructable(PLATFORM, x, y, 0.0, 10.0, 0)
set z = z + PLATFORM_HEIGHT - GetLocationZ(p)
call RemoveDestructable(d)
set d = null
if z >= 0.0 then // Small negative results may occur such as -0.0001
return z
endif
return 0.0
endfunction
function GetWaterType takes real x, real y returns integer
local real d = GetWaterDepth(x, y)
local real WATER_DEPTH_SHALLOW = 52.0
local integer WATER_TYPE_DEEP = 2
local integer WATER_TYPE_SHALLOW = 1
local integer WATER_TYPE_NONE = 0
if d == 0.0 then
return WATER_TYPE_NONE
elseif d < WATER_DEPTH_SHALLOW then
return WATER_TYPE_SHALLOW
endif
return WATER_TYPE_DEEP
endfunction
function IsTerrainType takes real x, real y, string tt, integer ic returns integer
if tt == "blight" then
if IsPointBlighted( x, y) == true then
set ic = ic + 1
endif
return ic
elseif tt == "water" then
if GetWaterType(x,y) > 0 then
set ic = ic + 1
endif
return ic
elseif GetTerrainType( x, y) == S2I(tt) then
set ic = ic + 1
return ic
endif
return ic
endfunction
function GetTerrainTypeInRange takes location p, string tt, real range returns integer
local integer pn = 1 // algebraic sign +/-
local integer ic = 0 // counts matching tiles
local real x
local real y
local real y2
local real y3
local real px = GetTileCenterCoordinate(GetLocationX(p))// x of the next tile center to a point
local real py = GetTileCenterCoordinate(GetLocationY(p))// y of the next tile center to a point
set x = px
set y = py
set ic = IsTerrainType( x, y, tt, ic) // check the initial tile
loop // decide direction, first positive, then negative
exitwhen pn < -1 // runs two times, once positive and once negative
set x = px // reset to inital tile
set y = py // reset to inital tile
loop // update x tile, moving along the x axis dependent on pn
exitwhen SquareRoot((x - px)*(x - px) + (y - py)*(y - py)) > range
set x = x + 128*pn
set ic = IsTerrainType( x, y, tt, ic) // check tiles on the x axis
set y2 = y
set y3 = y
// go up and down in y direction
loop
exitwhen SquareRoot((x - px)*(x - px) + (y2 - py)*(y2 - py)) > range
set y2 = y2 + 128
set ic = IsTerrainType( x, y2, tt, ic) // check tiles on the positive y branch
endloop
loop
exitwhen SquareRoot((x - px)*(x - px) + (y3 - py)*(y3 - py)) > range
set y3 = y3 - 128
set ic = IsTerrainType( x, y3, tt, ic) // check tiles on the negative y branch
endloop
endloop
set x = px
// go up and down y from initial x tile
loop
exitwhen SquareRoot((x - px)*(x - px) + (y - py)*(y - py)) > range
set y = y + 128*pn
set ic = IsTerrainType( x, y, tt, ic)
endloop
set pn = pn-2 // reverse direction, run again once
endloop
return ic
endfunction