package Terrain import NoWurst import Item constant real MAX_RANGE = 10. constant integer DUMMY_ITEM_ID = 'wolg' location tempLoc = Location(0.,0.) item dItem = null rect find = null item array hid integer hidMax = 0 vec2 tempPos = vec2(0,0) init find = Rect(0., 0., 128., 128.) dItem = CreateItem(DUMMY_ITEM_ID, 0, 0) SetItemVisible(dItem, false) /** Returns the (not normalised) terrain-normal at the given point */ public function getTerrainNormal( real x, real y, real sampleRadius) returns vec3 MoveLocation(tempLoc, x-sampleRadius, y) var zx = GetLocationZ(tempLoc) MoveLocation(tempLoc, x+sampleRadius, y) zx -= GetLocationZ(tempLoc) MoveLocation(tempLoc, x, y-sampleRadius) var zy = GetLocationZ(tempLoc) MoveLocation(tempLoc, x, y+sampleRadius) zy -= GetLocationZ(tempLoc) let sampleRadius2 = 2*sampleRadius return vec3( zx*sampleRadius2, zy*sampleRadius2, sampleRadius2*sampleRadius2 ) public function getTerrainZ(real x, real y) returns real MoveLocation( tempLoc, x, y ) return GetLocationZ( tempLoc ) public function getTerrainZ(vec2 v) returns real MoveLocation( tempLoc, v.x, v.y ) return GetLocationZ( tempLoc ) public function vec2.withTerrainZ() returns vec3 return vec3(this.x, this.y, getTerrainZ(this.x, this.y)) public function vec2.withTerrainZ(real zoffset) returns vec3 return vec3(this.x, this.y, getTerrainZ(this.x, this.y) + zoffset) public function vec3.withTerrainZ() returns vec3 return vec3(this.x, this.y, getTerrainZ(this.x, this.y)) public function vec3.withTerrainZ(real zoffset) returns vec3 return vec3(this.x, this.y, getTerrainZ(this.x, this.y) + zoffset) public function isTerrainDeepWater(real x, real y) returns boolean return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) public function isTerrainShallowWater(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) public function isTerrainLand(real x, real y) returns boolean return IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) public function isTerrainPlatform(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) function hideItem() if IsItemVisible(GetEnumItem()) hid[hidMax] = GetEnumItem() SetItemVisible(hid[hidMax], false) hidMax++ public function isTerrainWalkable(real x, real y) returns boolean //Hide any items in the area to avoid conflicts with our item MoveRectTo(find, x, y) EnumItemsInRect(find ,null, function hideItem) //Try to move the test item and get its coords SetItemPosition(dItem, x, y) //Unhides the item tempPos = dItem.getPos() SetItemVisible(dItem, false)//Hide it again //Unhide any items hidden at the start while hidMax > 0 hidMax-- SetItemVisible(hid[hidMax], true) hid[hidMax] = null //Return walkability return (tempPos.x-x)*(tempPos.x-x)+(tempPos.y-y)*(tempPos.y-y) <= MAX_RANGE*MAX_RANGE and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)