public void UpdateBulletSituation(GameState gameState) { BulletCalculation bulletCalc = BulletCalculator.GetBulletCalculation(gameState); List <BulletThreat> bulletThreats = new List <BulletThreat>(); foreach (BulletPathCalculation bulletPathCalc in bulletCalc.BulletPaths) { foreach (BulletThreat bulletThreat in bulletPathCalc.BulletThreats) { if (bulletThreat.TankThreatened == Tank) { bulletThreats.Add(bulletThreat); // If base is attacked, tank will automatically defend it: // // TODO: Will this kill some scenarios, because it applies to the scenario, // but doesn't seem to through its predetermined move? // If so, do this in a separate scenario. if ((bulletPathCalc.BaseThreatened == Tank.Player.Base) && (bulletThreat.NodePathToTakeOnBullet != null) && (bulletThreat.NodePathToTakeOnBullet.Length > 0)) { ChosenTankAction = bulletThreat.TankActionsToTakeOnBullet[0]; IsTankActionDetermined = true; continue; } } } } BulletThreats = bulletThreats.ToArray(); IsShotAt = BulletThreats.Length > 0; }
private void RespondToBullets(GameState currGameState, TankActionSet actionSet, bool[] moveChosen) { BulletCalculation bulletCalc = BulletCalculator.GetBulletCalculation(currGameState, You); foreach (BulletPathCalculation bulletPathCalc in bulletCalc.BulletPaths) { BulletThreat[] bulletThreats = bulletPathCalc.BulletThreats; for (int i = 0; i < bulletThreats.Length; i++) { BulletThreat bulletThreat = bulletThreats[i]; if (bulletThreat.TankThreatened.Player == You && !moveChosen[bulletThreat.TankThreatened.Number]) { if ((bulletPathCalc.BaseThreatened == You.Base) && (bulletThreat.NodePathToTakeOnBullet != null) && (bulletThreat.NodePathToTakeOnBullet.Length > 0)) { actionSet.Actions[bulletThreat.TankThreatened.Number] = bulletThreat.TankActionsToTakeOnBullet[0]; moveChosen[bulletThreat.TankThreatened.Number] = true; continue; } if (bulletThreat.LateralMoveInOneDirection != null && bulletThreat.LateralMoveInOneDirection.Length > 0) { actionSet.Actions[bulletThreat.TankThreatened.Number] = bulletThreat.TankActionsForLateralMoveInOneDirection[0]; moveChosen[bulletThreat.TankThreatened.Number] = true; continue; } if (bulletThreat.LateralMoveInOtherDirection != null && bulletThreat.LateralMoveInOtherDirection.Length > 0) { actionSet.Actions[bulletThreat.TankThreatened.Number] = bulletThreat.TankActionsForLateralMoveInOtherDirection[0]; moveChosen[bulletThreat.TankThreatened.Number] = true; continue; } if ((bulletThreat.NodePathToTakeOnBullet != null) && (bulletThreat.NodePathToTakeOnBullet.Length > 0)) { actionSet.Actions[bulletThreat.TankThreatened.Number] = bulletThreat.TankActionsToTakeOnBullet[0]; moveChosen[bulletThreat.TankThreatened.Number] = true; continue; } } } } }