public ArrayList getNeighboursInRange(AIEntity target, double range) { ArrayList list = new ArrayList(); foreach( KeyValuePair<int, AIEntity> ent in entityDictionary){ AIEntity temp = ent.Value; Vector to = temp.getPosition() - target.getPosition(); double ran = range + temp.boundingRadius(); if(temp.entityID() != target.entityID() && to.lengthSquared() < ran*ran) list.Add(temp); } return list; }
Vector pursueEntity(AIEntity entityToCatch) { Vector targetPos = entityToCatch.getPosition() - this.owner.getPosition(); double relativeHead = owner.getHeadingDirection().dotProduct(entityToCatch.getHeadingDirection()); if(targetPos.dotProduct(owner.getHeadingDirection()) > 0 && relativeHead < -0.9) { return this.seek(entityToCatch.getPosition()); } double lookAhead = Math.sqrt(vecToTarg.lengthSquared()) / (owner.getMaxSpeed() + Math.sqrt(entityToCatch.currentSpeedSquared())); return this.seek(entityToCatch.getPosition() + (entityToCatch.getVelocity() * lookAhead)); }
Vector evadeEntity(AIEntity entityToEvade) { Vector toTarget = entityToEvade.getPosition() - owner.getPosition(); double range = 1000; if(toTarget.lengthSquared() > range)return Vector(0,0); double lookAhead = Math.sqrt(vecToTarg.lengthSquared()) / (owner.getMaxSpeed() + Math.sqrt(entityToEvade.currentSpeedSquared())); return this.flee(entityToEvade.getPosition + (entityToEvade.getVelocity()*lookAhead)); }