package Helper import Terrain import Filter public int array pow2 constant rot45 = 0.707106 constant nrot45 = -0.707106 init for int i = 0 to 31 pow2[i] = R2I(Pow(2, I2R(i))) public function getPathingNormal(vec2 pos) returns vec2 int numberOfTests = 15 real radius = 64 vec2 addedVecs = vec2(0, 0) for int i = 1 to numberOfTests vec2 direction = vec2(0,0).polarOffset((i*2*bj_PI/numberOfTests).asAngleRadians(), radius) vec2 testPoint = pos + direction if IsTerrainPathable(testPoint.x, testPoint.y, PATHING_TYPE_WALKABILITY) addedVecs += direction if addedVecs.length() == 0.0 print(pos.toString()) return addedVecs.setLength(1.) * (-1.) public function getBounceVec(vec2 vel, vec2 nor) returns vec2 if vel.dot(nor) < 0 vec2 u = (vel.dot(nor)) * nor return (vel - u) - u return vel public function getLastPathablePoint(vec2 pos1, vec2 pos2) returns vec2 vec2 p1 = pos1 vec2 p2 = pos2 for int i = 1 to 8 vec2 h = p1 - p2 vec2 toTest = p2 + vec2(h.x / 2, h.y / 2) if not IsTerrainPathable(toTest.x, toTest.y, PATHING_TYPE_WALKABILITY) p1 = toTest else p2 = toTest return p1 public function checkForPathing(vec2 pos, vec2 vel, real radius) returns vec2 vec2 test = vel.setLength(radius) if IsTerrainPathable(pos.x + test.x, pos.y + test.y, PATHING_TYPE_WALKABILITY) return vec2(pos.x + test.x, pos.y + test.y) if IsTerrainPathable(pos.x - test.x, pos.y - test.y, PATHING_TYPE_WALKABILITY) return vec2(pos.x - test.x, pos.y - test.y) if IsTerrainPathable(pos.x - test.y, pos.y + test.x, PATHING_TYPE_WALKABILITY) return vec2(pos.x - test.y, pos.y + test.x) if IsTerrainPathable(pos.x + test.y, pos.y + test.x, PATHING_TYPE_WALKABILITY) return vec2(pos.x + test.y, pos.y + test.x) test *= rot45 if IsTerrainPathable(pos.x + (test.x - test.y), pos.y + (test.x + test.y), PATHING_TYPE_WALKABILITY) return vec2(pos.x + (test.x - test.y), pos.y + (test.x + test.y)) if IsTerrainPathable(pos.x - (test.x - test.y), pos.y - (test.x + test.y), PATHING_TYPE_WALKABILITY) return vec2(pos.x - (test.x - test.y), pos.y - (test.x + test.y)) if IsTerrainPathable(pos.x - (test.x + test.y), pos.y + (test.x - test.y), PATHING_TYPE_WALKABILITY) return vec2(pos.x - (test.x + test.y), pos.y + (test.x - test.y)) if IsTerrainPathable(pos.x + (test.x + test.y), pos.y - (test.x - test.y), PATHING_TYPE_WALKABILITY) return vec2(pos.x + (test.x + test.y), pos.y - (test.x - test.y)) return vec2(0,0) /** Same as dot product */ public function vec2.op_mult(vec2 v) returns real return this.x * v.x + this.y + v.y public function int.asFourchar() returns string string charMap = ".................................!.#$%&'()*+,-./0123456789:;<=>.@ABCDEFGHIJKLMNOPQRSTUVWXYZ[.]^_`abcdefghijklmnopqrstuvwxyz{|}~................................................................................................................................." string result = "" int remainingValue = this int charValue for int byteno = 0 to 3 charValue = ModuloInteger(remainingValue, 256) remainingValue = remainingValue div 256 result = SubString(charMap, charValue, charValue + 1) + result return result endpackage