package Creep import public Entity import public ClosureTimers import public Wave import public TerrainUtils import public Bounty import public initlater PlayerData import initlater LumberAndCoinSystem import GameTimer public constant CREEP_OWNER = players[9] public int array pow2 init for int i = 0 to 31 pow2[i] = R2I(Pow(2, I2R(i))) public function getPathingNormal(vec2 pos) returns vec2 let numberOfTests = 8 let radius = 64. vec2 addedVecs = vec2(0, 0) for int i = 1 to numberOfTests let direction = vec2(0,0).polarOffset((i * 2 * bj_PI/numberOfTests).asAngleRadians(), radius) let testPoint = pos + direction if testPoint.isTerrainWalkable() addedVecs += direction return addedVecs.setLength(1.) * (-1.) public function getBounceVec(vec3 vel3, vec2 nor2) returns vec3 let nor3 = nor2.toVec3() let pv3 = vel3.project(nor3) vec2 pv2 = pv3.toVec2() pv2 *= (-1.25) return vel3 + pv2 public class Creep extends UnitEntity int bounty boolean dropCoin construct(vec3 pos, int typId, int bounty, vec2 target, angle ang) super(createUnit(CREEP_OWNER, typId, pos.toVec2(), ang), pos, 16) actor.setAnimation("birth") this.bounty = bounty dropCoin = shouldSpawnCoin() // Apply timed life to prevent blocking and creeps getting stuck actor.setTimedLife(5.15 * 60.) EventListener.add(actor, EVENT_PLAYER_UNIT_DEATH, () -> onDeath()) doAfter(GetRandomReal(0.01, 0.2)) -> actor.issuePointOrder("attack", target) function onDeath() let killer = GetKillingUnit() if dropCoin let itm = createItem(COIN_ID, getPos()) itm.setUserData((getElapsedGameTime() / 17.).round()) doAfter(45.) -> if itm != null and GetWidgetLife(itm) > .405 itm.remove() if killer != null and killer.getOwner() != owner let size = allPlayers.size() if pDatas[killer.getOwner().getId()] == null var killBounty = (bounty div size) if killBounty <= 0 killBounty = 1 for pd in allPlayers if(pd.p != killer.getOwner()) pd.p.addGold(killBounty) showBountyTextTag(killBounty, actor, pd.p) else if size > 0 and bounty > 0 var killBounty = (bounty div size) + (bounty mod size) if killBounty < 1 killBounty = 1 var restBounty = 0 if size > 1 and bounty-killBounty > 0 restBounty = ((bounty-killBounty) / (size - 1.)).round() killer.getOwner().addGold(killBounty) showBountyTextTag(killBounty, actor, killer.getOwner()) if restBounty > 0 for pd in allPlayers if(pd.p != killer.getOwner()) pd.p.addGold(restBounty) showBountyTextTag(restBounty, actor, pd.p) override function update() if pos.toVec2().isTerrainWalkable() vel *= (0.975) else let normal = getPathingNormal(pos.toVec2()) vel = getBounceVec(vel, normal) super.update()