private AiIdentifiableObjectInfo FindClosestSpacecraft(List <AiIdentifiableObjectInfo> list, Spacecraft me) { AiIdentifiableObjectInfo closestObject = null; float minDistance = float.MaxValue; foreach (var info in list) { if (info.GameObjectId == me.GameObjectId) { continue; } if (info.GameObjectType != GameObjectType.Spacecraft) { continue; } var distanceFromMe = MyMath.Distance(info.Position, me.GamePosition); if (distanceFromMe < minDistance) { minDistance = distanceFromMe; closestObject = info; } } return(closestObject); }
public List <AiIdentifiableObjectInfo> GetIdentifiableObjects() { List <AiIdentifiableObjectInfo> gameObjectInfos = new List <AiIdentifiableObjectInfo>(); foreach (GameObject gameObject in gameObjects) { if (gameObject is IAiIdentifiableObject) { var gameObjectInfo = new AiIdentifiableObjectInfo(); (gameObject as IAiIdentifiableObject).PopulateGameObjectInfo(gameObjectInfo); gameObjectInfos.Add(gameObjectInfo); } } return(gameObjectInfos); }
private AiIdentifiableObjectInfo FindTarget(List <AiIdentifiableObjectInfo> list, Spacecraft spacecraft) { //return list.Find(info => info.GameObjectId == 0); AiIdentifiableObjectInfo target = null; foreach (var identityInfo in list) { if (identityInfo.GameObjectId == targetId) { target = identityInfo; } target = AnotherTargetAttackingMe(list, identityInfo, spacecraft) ?? target; } if (target != null) { return(target); } return(FindClosestSpacecraft(list, spacecraft)); }
private AiIdentifiableObjectInfo AnotherTargetAttackingMe(List <AiIdentifiableObjectInfo> list, AiIdentifiableObjectInfo identityInfo, Spacecraft spacecraft) { AiIdentifiableObjectInfo target = null; if (identityInfo.GameObjectId != spacecraft.GameObjectId && identityInfo.GameObjectType == GameObjectType.Bullet && MyMath.Distance(identityInfo.Position, spacecraft.GamePosition) < 100 && MyMath.MovingTowards(spacecraft.GamePosition, identityInfo.Position, identityInfo.Velocity, 0.7f)) { if (!enimity.ContainsKey(identityInfo.GameObjectId)) { enimity[identityInfo.GameObjectId] = 0; } enimity[identityInfo.GameObjectId] += 10; if (enimity[identityInfo.GameObjectId] > targetEnimity) { AiIdentifiableObjectInfo identityInfo1 = identityInfo; target = list.Find(info => info.GameObjectId == identityInfo1.GameObjectId); targetEnimity = enimity[identityInfo.GameObjectId]; } } return(target); }
private void MoveTowardsAndAttack(Spacecraft me, AiIdentifiableObjectInfo target, List <AiIdentifiableObjectInfo> list) { var adjustedTargetVelocity = target.Position - me.GamePosition; foreach (var info in list) { var diffDistanceFromMe = MyMath.Distance(me.GamePosition, info.Position) - MyMath.Distance(me.GamePosition, target.Position); if (info.GameObjectId == me.GameObjectId && info.GameObjectType == GameObjectType.Bullet && (diffDistanceFromMe) < 3 * MyMath.Distance(me.GamePosition, target.Position) ) { var vector2 = (MyMath.ReflectAcrossLine(info.Position - me.GamePosition, target.Position - me.GamePosition)); adjustedTargetVelocity += vector2; adjustedTargetVelocity += target.Position - me.GamePosition; } } adjustedTargetVelocity.Normalize(); adjustedTargetVelocity = MyMath.Distance(me.GamePosition, target.Position) * adjustedTargetVelocity; me.TargetReticle = adjustedTargetVelocity; RotateAndMoveWithVelocitySpeedAndTurnLimits(me, adjustedTargetVelocity); }
public List<AiIdentifiableObjectInfo> GetIdentifiableObjects() { List<AiIdentifiableObjectInfo> gameObjectInfos = new List<AiIdentifiableObjectInfo>(); foreach (GameObject gameObject in gameObjects) { if (gameObject is IAiIdentifiableObject) { var gameObjectInfo = new AiIdentifiableObjectInfo(); (gameObject as IAiIdentifiableObject).PopulateGameObjectInfo(gameObjectInfo); gameObjectInfos.Add(gameObjectInfo); } } return gameObjectInfos; }
private void MoveAwayFrom(Spacecraft me, AiIdentifiableObjectInfo target) { RotateAndMoveWithVelocitySpeedAndTurnLimits(me, me.GamePosition - target.Position); }
public void PopulateGameObjectInfo(AiIdentifiableObjectInfo info) { info.Create(ownerId, GameObjectType.Bullet, gamePosition, Velocity); }
public void PopulateGameObjectInfo(AiIdentifiableObjectInfo info) { info.Create(GameObjectId, GameObjectType.Spacecraft, gamePosition, velocity); }
private void MoveTowardsAndAttack(Spacecraft me, AiIdentifiableObjectInfo target, List<AiIdentifiableObjectInfo> list) { var adjustedTargetVelocity = target.Position - me.GamePosition; foreach (var info in list) { var diffDistanceFromMe = MyMath.Distance(me.GamePosition, info.Position) - MyMath.Distance(me.GamePosition, target.Position); if (info.GameObjectId == me.GameObjectId && info.GameObjectType == GameObjectType.Bullet && (diffDistanceFromMe) <3*MyMath.Distance(me.GamePosition, target.Position) ) { var vector2 = (MyMath.ReflectAcrossLine(info.Position - me.GamePosition, target.Position - me.GamePosition)); adjustedTargetVelocity += vector2; adjustedTargetVelocity += target.Position - me.GamePosition; } } adjustedTargetVelocity.Normalize(); adjustedTargetVelocity = MyMath.Distance(me.GamePosition, target.Position)*adjustedTargetVelocity; me.TargetReticle = adjustedTargetVelocity; RotateAndMoveWithVelocitySpeedAndTurnLimits(me, adjustedTargetVelocity); }
private void MoveAwayFrom(Spacecraft me, AiIdentifiableObjectInfo target) { RotateAndMoveWithVelocitySpeedAndTurnLimits(me, me.GamePosition-target.Position); }
private AiIdentifiableObjectInfo AnotherTargetAttackingMe(List<AiIdentifiableObjectInfo> list, AiIdentifiableObjectInfo identityInfo, Spacecraft spacecraft) { AiIdentifiableObjectInfo target = null; if (identityInfo.GameObjectId != spacecraft.GameObjectId && identityInfo.GameObjectType == GameObjectType.Bullet && MyMath.Distance(identityInfo.Position, spacecraft.GamePosition) < 100 &&MyMath.MovingTowards(spacecraft.GamePosition, identityInfo.Position, identityInfo.Velocity, 0.7f)) { if (!enimity.ContainsKey(identityInfo.GameObjectId)) enimity[identityInfo.GameObjectId] = 0; enimity[identityInfo.GameObjectId] += 10; if (enimity[identityInfo.GameObjectId] > targetEnimity) { AiIdentifiableObjectInfo identityInfo1 = identityInfo; target = list.Find(info => info.GameObjectId == identityInfo1.GameObjectId); targetEnimity = enimity[identityInfo.GameObjectId]; } } return target; }