protected ControlableWave(ControlableWave copy) : base(copy) { this.Killed = Functions.Clone <EventHandler>(copy.Killed); this.shipState = new ShipState(copy.shipState); this.movementInfo = new ShipMovementInfo(copy.movementInfo); foreach (IControler controler in copy.controlers) { AddControler(null, (IControler)controler.Clone()); } this.target = copy.target; this.ControlHandler = Functions.Clone <IControlHandler>(copy.ControlHandler); this.currentControlInput = copy.currentControlInput; this.direction = copy.direction; this.controlableType = copy.controlableType; this.controlableSounds = copy.controlableSounds; this.attachedEffectCollection = new EffectCollection(copy.attachedEffectCollection); this.contFlags = copy.contFlags; this.CollisionState.GenerateRayEvents = true; this.colors = copy.colors; this.primaryColor = copy.primaryColor; if (copy.weaponInfo != null) { this.weaponInfo = (IWeaponsLogic)copy.weaponInfo.Clone(); } }
public override bool IsThreatTo(IControlable other) { if (cost != null && !source.ShipState.MeetsCost(-cost) || !action.CanTarget(other)) { return(false); } Vector2D diff = other.Current.Position.Linear - source.Current.Position.Linear; float distance = diff.Magnitude; float angle = diff.Angle; if (directions != null) { for (int pos = 0; pos < directions.Length; ++pos) { float currentAngle = source.DirectionAngle + directions[pos]; float weaponrange = distances[pos] + other.BoundingRadius + source.BoundingRadius; if (distance < weaponrange && Logic.InArc(currentAngle, angle, distance, other.BoundingRadius, GunActionAIInfo.AimTolerance)) { return(true); } } } return(false); }
public override bool IsThreatTo(IControlable other) { if (cost != null && !source.ShipState.MeetsCost(-cost)) { return(false); } Vector2D diff = other.Current.Position.Linear - source.Current.Position.Linear; float distance = diff.Magnitude; float angle = diff.Angle; for (int pos = 0; pos < action.VelocityAngles.Length; ++pos) { float currentAngle = source.DirectionAngle + action.VelocityAngles[pos]; float weaponrange = action.Weapons[pos].LifeTime.TimeLeft * action.Weapons[pos].MovementInfo.MaxLinearVelocity + other.BoundingRadius + source.BoundingRadius; if (distance < weaponrange && Logic.InArc(currentAngle, angle, distance, other.BoundingRadius, GunActionAIInfo.AimTolerance + GetRandomVelocityAngle(pos))) { return(true); } } return(false); }
public override void CalcBoundingBox2D() { ray2DEffects.Clear(); float timepassed = totalTime - lifeTime.TimeLeft; int length = positions.Length; BoundingBox2D box = null; IControlable source = weaponInfo.LastBody; for (int pos = 0; pos < length; ++pos) { if (timepassed >= startTimes[pos] && timepassed <= startTimes[pos] + lifeTimes[pos]) { Vector2D start = Vector2D.Rotate(source.Current.Position.Angular + positions[pos], Vector2D.XAxis) * source.BoundingRadius + source.Current.Position.Linear; Vector2D Direction = Vector2D.Rotate(source.Current.Position.Angular + directions[pos], Vector2D.XAxis); RaySegment2D segment = new RaySegment2D(start, Direction, distances[pos]); if (box == null) { box = segment.BoundingBox2D; } else { box = BoundingBox2D.From2BoundingBox2Ds(box, segment.BoundingBox2D); } ray2DEffects.Add(new SelectiveImpulseRay(lifeTime, segment, impulses[pos], BodyFlags.IgnoreGravity)); } } if (box == null) { box = new BoundingBox2D(Vector2D.Zero, Vector2D.Zero); } this.boundingBox2D = box; }
public override void OnCreation(GameResult gameResult, IControlable host) { base.OnCreation(gameResult, host); CollidableBubble bubble = new CollidableBubble(1000, host, obstacles); gameResult.AddCollidableArea(bubble); }
public void HandlePossibleIntersections(float dt, List <ICollidableBody> pairs) { pairs.Remove(host); collidables.Clear(); List <CDist> tmp = new List <CDist>(); foreach (ICollidableBody col in pairs) { IControlable c = col as IControlable; if (c != null && c.IsTargetable) { float truerange = range + c.BoundingRadius + host.BoundingRadius; float distanceSq = (host.Current.Position.Linear - c.Current.Position.Linear).MagnitudeSq; if ((truerange * truerange) >= distanceSq) { CDist d = new CDist(); d.Controlable = c; d.DistanceSq = distanceSq; tmp.Add(d); } } } tmp.Sort(); foreach (CDist d in tmp) { collidables.Add(d.Controlable); } }
public CollidableBubble(float range, IControlable host, List <IControlable> collidables) : base(new LifeSpan(host.LifeTime)) { this.host = host; this.range = range; this.collidables = collidables; }
public IControlable NextClosest(Predicate <IControlable> match, Vector2D location) { if (match(host)) { return(host); } float gooddistance = 0; int goodIndex = -1; for (int pos = 0; pos < possibleTargets.Count; pos++) { IControlable possibleTarget = possibleTargets[pos]; if (match(possibleTarget)) { float distance = (possibleTarget.Current.Position.Linear - location).MagnitudeSq; if (goodIndex < 0 || distance < gooddistance) { goodIndex = pos; gooddistance = distance; } } } if (goodIndex >= 0) { index.Current = goodIndex; return(possibleTargets[goodIndex]); } return(null); }
public override void OnCollision(GameResult gameResult, IControlable collider) { Vector2D dir = this.current.Position.Linear - collider.Current.Position.Linear; this.current.Velocity.Linear = Vector2D.SetMagnitude(dir, this.movementInfo.MaxLinearVelocity); base.OnCollision(gameResult, collider); }
protected override bool OnTargetAquired(GameResult gameResult, float dt, IControlable newTarget) { Vector2D sourcePosition = this.source.Current.Position.Linear; // +this.source.Current.Velocity.Linear * dt; Vector2D targetPosition = newTarget.Current.Position.Linear; // +newTarget.Current.Velocity.Linear * dt; Vector2D relativeVelocity = newTarget.Current.Velocity.Linear - this.source.Current.Velocity.Linear; float time; if (Logic.TrySolveTimeToWaveIntercept( sourcePosition, targetPosition, relativeVelocity, weapon.MovementInfo.MaxLinearVelocity.Value, out time)) { if (time > 0 && time < weapon.LifeTime.TimeLeft && time < newTarget.LifeTime.TimeLeft) { Vector2D point = targetPosition + relativeVelocity * time; float angle = (point - sourcePosition).Angle - this.source.Current.Position.Angular; SolidWeaponHardPoint hardpoint = new SolidWeaponHardPoint(0, weapon.MovementInfo.MaxLinearVelocity, angle); ISolidWeapon newWeapon = hardpoint.FireGun((ISolidWeapon)weapon.Clone(), this.source); newWeapon.IgnoreInfo.JoinGroupToIgnore(source.FactionInfo.FactionNumber); newWeapon.OnCreation(gameResult, source, this); return(true); } } return(false); }
public static void ApplydLV(IControlable host, Vector2D dv, float dt) { Vector2D force = dv * (host.MassInfo.Mass / dt); host.Current.ForceAccumulator.Linear += force; //host.Current.Velocity.Linear += dv; }
public static void UpdateLinearMovement(float dt, IControlable host) { if (dt == 0) { return; } ControlInput input = host.CurrentControlInput; if (input == null) { return; } if (input[InputAction.MoveForward]) { ApplyThrust(dt, host, host.DirectionVector, input.ThrustPercent); } else if (input[InputAction.MoveBackwards]) { ApplyThrust(dt, host, -host.DirectionVector, input.ThrustPercent); } else if (input[InputAction.MoveLeft]) { ApplyThrust(dt, host, host.DirectionVector.LeftHandNormal, input.ThrustPercent); } else if (input[InputAction.MoveRight]) { ApplyThrust(dt, host, host.DirectionVector.RightHandNormal, input.ThrustPercent); } }
public GeneralNPC(CharacterNPC character, Vector3 position, IWalkable terrain, IControlable entity) { this.character = character; this.terrain = terrain; this.entity = entity; this.position3D = position; this.position2D = terrain.Get2DMapPosition(this.position3D); this.taskStack = new Stack <NpcTask>(); this.taskMove = new Traveling(new Astar()); this.fightMove = new Traveling(new Astar()); //init start status this.currentStatus = new Status(); this.currentStatus.hp = character.hp; this.currentStatus.mana = character.mana; this.currentStatus.energy = 100; this.currentStatus.position = this.position2D; this.currentStatus.enemySeen = 0; this.currentStatus.alive = true; this.currentStatus.nearEnemies = new List <IActing>(); this.targetCell = this.position2D; aiMap = Map.GetInstance(); this.npcMap = aiMap.getRelatedMap(this.position2D, this.visualRange); }
protected void SpawnWeapon(GameResult gameResult, IControlable collider) { if (spawned) { return; } spawned = true; PhysicsState physicsState = new PhysicsState(this.Good); physicsState.ForceAccumulator = ALVector2D.Zero; physicsState.Acceleration = ALVector2D.Zero; if (collider != null) { physicsState.Velocity.Linear = collider.Good.Velocity.Linear; } else { physicsState.Velocity.Linear = this.current.Velocity.Linear; } ISolidWeapon newWeapon = (ISolidWeapon)spawn.Clone(); newWeapon.Current.Set(physicsState); newWeapon.SetAllPositions(); newWeapon.OnCreation(gameResult, this.weaponInfo); if (diesOnSpawn) { this.Kill(gameResult); } }
public override void Do() { base.Do(); controlable = controlableGameObject.GetComponent <IControlable>(); if (controlable == null) { onComplete?.Invoke(); Debug.Log($"{name} action havent controllable entity"); return; } if (targetIsPlayer) { Actor player = PlayerManager.Instance().GetPlayer(); if (player == null) { doing = false; return; } targetPoint = player.transform; } startTime = Time.time; doing = true; controlable.Follow(targetPoint, 1.2f); }
/// <summary> /// ctor, initialize ai structures /// </summary> /// <param name="character">character of npc</param> /// <param name="position">position on which npc stands</param> /// <param name="terrain">terrain, where npc moves</param> /// <param name="entity">pointer on graphical representation of npc, used for changing position, making effects, ...</param> public NPC(CharacterNPC character, Vector3 position, IWalkable terrain, IControlable entity) { this.position3D = position; System.Drawing.Point xy = terrain.Get2DMapPosition(position); this.x = xy.X; this.y = xy.Y; this.character = character; this.visualRange = this.character.visualRange; this.currentStatus = new Status(); this.currentStatus.hp = character.hp; this.currentStatus.mana = character.mana; this.currentStatus.energy = 100; this.currentStatus.position = this.GetPosition2D(); this.currentStatus.enemySeen = 0; this.currentStatus.alive = true; this.currentStatus.nearEnemies = new List <IActing>(); this.entity = entity; this.terrain = terrain; this.taskStack = new Stack <NpcTask>(); this.taskMove = new Traveling(new Astar()); this.fightMove = new Traveling(new Astar()); this.targetCell = new System.Drawing.Point(x, y); this.aiMap = Map.GetInstance(); pathFinding = new Astar(); this.entity.ChangePosition(position); }
public bool IsThreatTo(IControlable other) { if (solidHost.IgnoreInfo.CanCollideWith(other.IgnoreInfo) && CanEffect(other) && effectCollection.IsHarmful && (other.Current.Velocity.Linear - solidHost.Current.Velocity.Linear) * (other.Current.Position.Linear - solidHost.Current.Position.Linear) < 0) { float time; if (Logic.TrySolveTimeToWaveIntercept( other.Current.Position.Linear, solidHost.Current.Position.Linear, solidHost.Current.Velocity.Linear - other.Current.Velocity.Linear, other.MovementInfo.MaxLinearVelocity, out time)) { return(((solidHost.Current.Velocity.Linear * time + solidHost.Current.Position.Linear) - (other.Current.Velocity.Linear * time + other.Current.Position.Linear)).Magnitude < ((other.BoundingRadius + solidHost.BoundingRadius) * 3)); } } return(false); }
public static TargetingTypes GetTargetingType(IControlable host, IControlable possibleTarget) { int rv; if (host != null) { rv = (int)DefaultFactionCollection.GetDiplomacy(host.FactionInfo, possibleTarget.FactionInfo); } else { rv = (int)FactionDiplomacy.Neutral; } rv = rv | (int)possibleTarget.FactionInfo.FactionType; rv = rv | (int)possibleTarget.ControlableType; if (host == possibleTarget || IsSubShipofHost(host, possibleTarget)) { rv = rv | (int)TargetingTypes.Self; } else { rv = rv | (int)TargetingTypes.Other; } return((TargetingTypes)rv); }
public static void ApplydAV(IControlable host, float dv, float dt) { float torque = dv * (host.MassInfo.MomentofInertia / dt); host.Current.ForceAccumulator.Angular += torque; //host.Current.Velocity.Angular += dv; }
public override void OnCollision(GameResult gameResult, IControlable collider) { base.OnCollision(gameResult, collider); if (diesOnSpawn) { SpawnWeapon(gameResult, collider); } }
public void OnCreation(GameResult gameResult, IControlable host) { count = base.Count; for (int pos = 0; pos < count; ++pos) { base[pos].OnCreation(gameResult, host); } }
protected override bool OnTargetAquired(GameResult gameResult, float dt, IControlable newTarget) { TargetedRayWeapon newWeapon = (TargetedRayWeapon)weapon.Clone(); newWeapon.OnCreation(gameResult, source, this); newWeapon.WeaponInfo.Target = newTarget; return(true); }
public override void OnCollision(GameResult gameResult, IControlable collider) { if (damageDelay.IsFull) { didCollision = true; base.OnCollision(gameResult, collider); } }
public override bool IsThreatTo(IControlable other) { if (cost != null && !source.ShipState.MeetsCost(-cost) || !action.CanTarget(other)) { return(false); } return((other.Current.Position.Linear - source.Current.Position.Linear).Magnitude < action.Radius); }
public override bool IsThreatTo(IControlable other) { if (cost != null && !source.ShipState.MeetsCost(-cost)) { return(false); } return(source.ShipState.MeetsCost(-cost) && ((other.Current.Position.Linear - source.Current.Position.Linear).Magnitude < range)); }
public AIStateInfo(IControlable target, Vector2D vectorToTarget, IControlable[] obstacles, bool[] threats) { this.target = target; this.obstacles = obstacles; this.vectorToTarget = vectorToTarget; this.threats = threats; }
public virtual void Init(IControlable actMovement) { base.Init(); movement = actMovement; currentAttackAnimSet = defaultAttackAnimSet; RegisterEvents(); enabled = true; }
// Called when the node enters the scene tree for the first time. public override void _Ready() { _controls = new PlayerMovementController(); head = GetChild <PlayerController>(0); AddTail(); AddTail(); AddTail(); AddTail(); AddTail(); }
protected virtual bool CheckTarget() { if (IsCurrentTargetInvalid) { target = host.TargetRetriever.NextClosest(targetingInfo, this.host.Current.Position.Linear); host.Target = target; return(IsCurrentTargetInvalid); } return(false); }
protected BaseEffect(BaseEffect copy) { this.exhausted = copy.exhausted; this.harmfulEffectTypes = copy.harmfulEffectTypes; this.weaponInfo = copy.weaponInfo; this.attachie = copy.attachie; this.effectsWho = copy.effectsWho; this.effectSounds = copy.effectSounds; this.isHarmful = copy.isHarmful; }