public override void Enter() { HasDoneStrike = false; FadingOut = true; FadeAlpha = 0; FadeAlphaChange = 0.01f; UnitTurret BestTurret = null; int BestKills = -1; foreach (UnitTurret t in GameManager.GetLevel().getCurrentScene().Enumerate(typeof(UnitTurret))) { if (t.GetTeam() == WaveManager.ActiveTeam && t.Kills > BestKills) { BestTurret = t; } } if (BestTurret != null) { StrikePosition = BestTurret.getPosition(); } base.Enter(); }
private void ResetDefenseTarget() { Dictionary <MiningPlatform, float> PlatformScores = new Dictionary <MiningPlatform, float>(); foreach (UnitBasic u in FactionManager.SortedUnits[Parent.ParentController.ParentShip.GetTeam()]) { if (u.GetType().IsSubclassOf(typeof(MiningPlatform))) { MiningPlatform m = (MiningPlatform)u; if (!PlatformScores.ContainsKey(m)) { PlatformScores.Add(m, 0); foreach (UnitBasic u2 in FactionManager.SortedUnits[Parent.ParentController.ParentShip.GetTeam()]) { if (u2.GetType().IsSubclassOf(typeof(UnitTurret))) { UnitTurret t2 = (UnitTurret)u2; if (t2.IsAlly(Parent.ParentController.ParentShip) && !t2.Dead) { PlatformScores[m] += Vector2.Distance(t2.Position.get(), m.Position.get()); } } } } } } MiningPlatform forwardPlatform = PathFindingManager.TraceToMiningPlatform(NeutralManager.GetSpawnPosition(), Parent.ParentController.ParentShip.GetTeam()); if (forwardPlatform != null && PlatformScores.ContainsKey(forwardPlatform)) { PlatformScores[forwardPlatform] *= 2; } float BestScore = 0; foreach (MiningPlatform m in PlatformScores.Keys) { if (PlatformScores[m] > BestScore) { CurrentDefenseTarget = m; BestScore = PlatformScores[m]; } } DefenseLocation = PathFindingManager.TraceCellPoint(CurrentDefenseTarget.Position.get(), 10); }
private void SearchForEnemies() { DodgeBullet = null; float BestDistance = 150; foreach (Bullet b in Bullet.DodgeBullets) { if (!Parent.ParentController.ParentShip.IsAlly(b.ParentUnit) && b.attackType != Parent.ParentController.ParentShip.Resistence) { float d = Logic.DistanceLineSegmentToPoint(b.Position.get(), b.Position.get() + b.Speed * 8, Parent.ParentController.ParentShip.Position.get()); if (d < 100) { BestDistance = d; DodgeBullet = b; } } } BestDistance = 1500; foreach (Basic2DObject o in Parent.ParentController.ParentShip.Parent2DScene.quadGrids.First.Value.Enumerate( Parent.ParentController.ParentShip.Position.get(), new Vector2(BestDistance * 2))) { if (o.GetType().IsSubclassOf(typeof(UnitBasic))) { float d = Vector2.Distance(o.Position.get(), Parent.ParentController.ParentShip.Position.get()); if (d < BestDistance) { UnitBasic u = (UnitBasic)o; if (!Parent.ParentController.ParentShip.IsAlly(u) && u.CanBeTargeted()) { if (u.GetType().IsSubclassOf(typeof(UnitTurret))) { UnitTurret t = (UnitTurret)u; if (t.MyCard != null && t.MyCard.StrongVs.Equals("Light")) { continue; } } BestDistance = d; AttackTarget = u; } } } } }
public override void Update(GameTime gameTime) { if (DodgeBullet != null && DodgeBullet.TimeAlive >= DodgeBullet.LifeTime) { DodgeBullet = null; } SearchTime += gameTime.ElapsedGameTime.Milliseconds; if (SearchTime > MaxSearchTime || (AttackTarget != null && !AttackTarget.CanBeTargeted())) { SearchTime = 0; SearchForEnemies(); } if (AttackTarget == null || AttackTarget.GetType().IsSubclassOf(typeof(UnitTurret))) { UnitTurret u = (UnitTurret)AttackTarget; if (AttackTarget == null || (u.MyCard == null && NeutralManager.MyPattern.CurrentCard.Type.Equals("Heavy") || (u.MyCard != null && NeutralManager.MyPattern.CurrentCard.Type.Equals(u.MyCard.StrongVs)))) { if (!isPathfinding || Vector2.Distance(Parent.ParentController.ParentShip.Position.get(), PathfindingTarget) < 300) { isPathfinding = true; PathfindingTarget = PathFindingManager.TraceAttackPoint(Parent.ParentController.ParentShip.Position.get(), 10); } } else { isPathfinding = false; } } else { isPathfinding = false; } if (Parent.ParentController.ParentShip.Dead || !WaveFSM.WaveStepState.WeaponsFree) { AiState s = Parent.GetExistingState(typeof(PlaceTurretState)); Parent.SetState(s == null ? new PlaceTurretState() : s); } base.Update(gameTime); }
public override void Enter(AiStateManager Parent) { float BestScore = 1000; Moving = false; PauseTime = 0; foreach (WaveCard card in OverCardPicker.CurrentCards) { float Score = 0; foreach (UnitBasic u in FactionManager.SortedUnits[WaveManager.ActiveTeam]) { if (u.GetType().IsSubclassOf(typeof(UnitTurret))) { UnitTurret t = (UnitTurret)u; if (t.MyCard != null) { if (t.MyCard.StrongVs.Equals(card.Type)) { Score += t.GetWeight(); } } else if (card.Type.Equals("Heavy")) { Score += t.GetWeight(); } } } if (Score < BestScore) { SelectedCard = card; BestScore = Score; } } base.Enter(Parent); }
public override void Update(GameTime gameTime) { if (WaveManager.GetState() == WaveFSM.PickEnemyState.self && WaveManager.CurrentWave > 4 && WaveManager.ActiveTeam != Parent.ParentController.ParentShip.GetTeam()) { AiState s = Parent.GetExistingState(typeof(PickAttackerState)); Parent.SetState(s == null ? new PickAttackerState() : s); } else { if (TargetObject == null && TargetCard == null) { bool Damaged = false; foreach (UnitBasic u in FactionManager.SortedUnits[Parent.ParentController.ParentShip.GetTeam()]) { if (u.GetType().IsSubclassOf(typeof(MiningPlatform))) { if (u.HullDamage > 0) { Damaged = true; break; } } } if (FactionManager.CanBuildMiningPlatform(Parent.ParentController.ParentShip.FactionNumber) && (WaveManager.ActiveTeam != Parent.ParentController.ParentShip.GetTeam() || FactionManager.NeutralUnitCount < 3 || (FactionManager.Factions[Parent.ParentController.ParentShip.FactionNumber].MiningPlatformCount < 2 && Damaged))) { float BestStrength = 100000; foreach (MineralRock m in Parent.ParentController.ParentShip.ParentScene.Enumerate(typeof(MineralRock))) { if (m.miningPlatform == null) { float MineralRockStrength = 0; foreach (MiningPlatform f in Parent.ParentController.ParentShip.ParentScene.Enumerate(typeof(MiningPlatform))) { if (f.IsAlly(Parent.ParentController.ParentShip)) { MineralRockStrength += Vector2.Distance(m.Position.get(), f.Position.get()) / 1000; } } foreach (UnitTurret f in Parent.ParentController.ParentShip.ParentScene.Enumerate(typeof(UnitTurret))) { if (f.IsAlly(Parent.ParentController.ParentShip)) { MineralRockStrength += Vector2.Distance(m.Position.get(), f.Position.get()) / 2000; } } if (MineralRockStrength < BestStrength) { BestStrength = MineralRockStrength; TargetObject = m; } } } } else if (WaveManager.ActiveTeam == Parent.ParentController.ParentShip.GetTeam() && PathFindingManager.CellJobQue.Count == 0 && WaveManager.CurrentWave > 1) { Faction f = FactionManager.Factions[Parent.ParentController.ParentShip.FactionNumber]; TurretCard BestCard = null; float BestStrength = 0; foreach (TurretCard c in f.Cards) { float s = c.GetPlaceStrength(f.FactionNumber); if (s > BestStrength) { BestStrength = s; BestCard = c; } } if (BestCard != null && (!BestCard.FactionCostIncreases.ContainsKey(f.FactionNumber) ? f.Cells >= BestCard.CardCellsCost : f.Cells >= BestCard.CardCellsCost + BestCard.CardCellsCostIncrease * BestCard.FactionCostIncreases[f.FactionNumber])) { TargetCard = BestCard; TargetCardPosition = BestCard.GetPlacePosition(f.FactionNumber); } } } else { if (TargetObject != null) { if (TargetObject.GetType().Equals(typeof(MineralRock))) { MineralRock m = (MineralRock)TargetObject; if (m.miningPlatform != null) { TargetObject = null; } } else if (TargetObject.GetType().IsSubclassOf(typeof(UnitBuilding))) { UnitBuilding b = (UnitBuilding)TargetObject; if (b.IsUpdgraded) { TargetObject = null; } } } else if (Vector2.Distance(TargetCardPosition, Parent.ParentController.ParentShip.FloatingViewPosition) < 4) { PlayerShip ParentShip = Parent.ParentController.ParentShip; int CardCost = TargetCard.CardCellsCost; if (TargetCard.FactionCostIncreases.ContainsKey(ParentShip.FactionNumber)) { CardCost += TargetCard.CardCellsCostIncrease * TargetCard.FactionCostIncreases[ParentShip.FactionNumber]; } if (TargetCard.FactionCostIncreases.ContainsKey(ParentShip.FactionNumber)) { TargetCard.FactionCostIncreases[ParentShip.FactionNumber]++; } else { TargetCard.FactionCostIncreases.Add(ParentShip.FactionNumber, 1); } FactionManager.AddCells(ParentShip.FactionNumber, -CardCost); UnitTurret u = (UnitTurret)TargetCard.GetUnit(ParentShip.FactionNumber); u.MyCard = TargetCard; ParentShip.PlaceTurret(u); TargetCard = null; } } } if (WaveFSM.WaveStepState.WeaponsFree && !Parent.ParentController.ParentShip.Dead && TargetObject == null && TargetCard == null) { if (WaveManager.ActiveTeam != Parent.ParentController.ParentShip.GetTeam()) { AiState s = Parent.GetExistingState(typeof(AttackState)); Parent.SetState(s == null ? new AttackState() : s); } else { AiState s = Parent.GetExistingState(typeof(DefendState)); Parent.SetState(s == null ? new DefendState() : s); } } base.Update(gameTime); }