private void AddSingleTurretRotationDecision(ArcFacing facing) { AddDecision( facing.ToString(), delegate { ChangeMobileArcFacing(facing); }, isCentered: (facing == ArcFacing.Front || facing == ArcFacing.Rear) ); }
private void AddSingleTurretRotationDecision(ArcFacing facing, ArcFacing currentFacing) { if (facing == currentFacing) { return; } AddDecision( facing.ToString(), delegate { ChangeMobileArcFacing(facing); }, isCentered: (facing == ArcFacing.Front || facing == ArcFacing.Rear) || (facing == ArcFacing.Left && currentFacing == ArcFacing.Right) || (facing == ArcFacing.Right && currentFacing == ArcFacing.Left) ); }
private string GetDefaultDecision() { string chosenFacing = ""; Dictionary <ArcFacing, List <GenericShip> > enemiesInArcHolder = Selection.ThisShip.SectorsInfo.GetEnemiesInAllSectors(); Dictionary <ArcFacing, int> singleTurretPriorities = new Dictionary <ArcFacing, int>(); foreach (ArcFacing facing in Selection.ThisShip.GetAvailableArcFacings()) { int priority = 0; //Ignore static arcs with same facing if (!Selection.ThisShip.ArcsInfo.Arcs.Any(a => a.Facing == facing && (!(a is ArcSingleTurret)))) { priority = enemiesInArcHolder[facing].Count; } Selection.ThisShip.Ai.CallGetRotateArcFacingPriority(facing, ref priority); singleTurretPriorities.Add(facing, priority); } // For single turret if (Selection.ThisShip.ShipInfo.ArcInfo.Arcs.Any(a => a.ArcType == ArcType.SingleTurret)) { ArcFacing currentFacing = Selection.ThisShip.ArcsInfo.GetArc <ArcSingleTurret>().Facing; //if no enemies in all sectors, prioritize default values if (!singleTurretPriorities.Any(n => n.Value > 0)) { if (Selection.ThisShip.ShipInfo.ArcInfo.Arcs.Any(a => a.ArcType == ArcType.Front)) { singleTurretPriorities[ArcFacing.Rear] += 1; } else { singleTurretPriorities[ArcFacing.Front] += 1; } } //Get facing with highest priority that is not current facing singleTurretPriorities.Remove(currentFacing); ArcFacing bestFacing = singleTurretPriorities.FirstOrDefault(a => a.Value == singleTurretPriorities.Max(b => b.Value)).Key; chosenFacing = bestFacing.ToString(); } // For double turret else if (Selection.ThisShip.ShipInfo.ArcInfo.Arcs.Any(a => a.ArcType == ArcType.DoubleTurret)) { ArcFacing currentFacing = Selection.ThisShip.ArcsInfo.GetArc <ArcDualTurretA>().Facing; string currentFacingString = "None"; if (currentFacing == ArcFacing.Front || currentFacing == ArcFacing.Rear) { currentFacingString = "Front-Rear"; } else if (currentFacing == ArcFacing.Left || currentFacing == ArcFacing.Right) { currentFacingString = "Left-Right"; } Dictionary <string, int> doubleTurretPriorities = new Dictionary <string, int> { { "Front-Rear", singleTurretPriorities[ArcFacing.Front] + singleTurretPriorities[ArcFacing.Rear] }, { "Left-Right", singleTurretPriorities[ArcFacing.Left] + singleTurretPriorities[ArcFacing.Right] } }; if (!doubleTurretPriorities.Any(n => n.Value > 0)) { if (Selection.ThisShip.ShipInfo.ArcInfo.Arcs.Any(a => a.ArcType == ArcType.Front)) { doubleTurretPriorities["Left-Right"] += 1; } else { doubleTurretPriorities["Front-Rear"] += 1; } } doubleTurretPriorities.Remove(currentFacingString); chosenFacing = doubleTurretPriorities.FirstOrDefault(a => a.Value == doubleTurretPriorities.Max(b => b.Value)).Key; } return(chosenFacing); }
public void ShowMobileFiringArcAltHighlight(ArcFacing facing) { //Mobile arc alt string newTexture = "ShipStandInsert/Universal/SecondEdition/" + this.ShipInfo.BaseSize.ToString() + "/" + this.Faction.ToString() + "/" + facing.ToString(); Material newMaterial = CreateMaterial(newTexture); StandardShaderUtils.ChangeRenderMode(newMaterial, StandardShaderUtils.BlendMode.Fade); ShipAllParts.Find("ShipBase/ShipStandInsert/ShipStandInsertImage/ThirdArc").GetComponent <Renderer>().material = newMaterial; ShipAllParts.Find("ShipBase/ShipStandInsert/ShipStandInsertImage/ThirdArc").GetComponent <MeshRenderer>().enabled = true; }
private string GetDefaultDecision() { string facing = ""; if (Selection.ThisShip.ShipInfo.ArcInfo.Arcs.Any(a => a.ArcType == ArcType.SingleTurret)) { if (EnemiesInArcHolder.Any(n => n.Value.Count > 0)) { int maxCount = 0; ArcFacing maxFacing = Selection.ThisShip.ArcsInfo.GetArc <ArcSingleTurret>().Facing; List <ArcFacing> availableArcFacings = Selection.ThisShip.GetAvailableArcFacings(); foreach (var sectorInfo in EnemiesInArcHolder) { if (sectorInfo.Value.Count > maxCount && availableArcFacings.Contains(sectorInfo.Key)) { maxCount = sectorInfo.Value.Count; maxFacing = sectorInfo.Key; } } facing = maxFacing.ToString(); } else { if (Selection.ThisShip.ShipInfo.ArcInfo.Arcs.Any(a => a.ArcType == ArcType.Front)) { facing = "Rear"; } else { facing = "Front"; } } } else if (Selection.ThisShip.ShipInfo.ArcInfo.Arcs.Any(a => a.ArcType == ArcType.DoubleTurret)) { if (EnemiesInArcHolder.Any(n => n.Value.Count > 0)) { int enemiesInFrontRearArc = 0; int enemiesInLeftRearArc = 0; if (Selection.ThisShip.ShipInfo.ArcInfo.Arcs.Any(a => a.ArcType == ArcType.Front)) { enemiesInFrontRearArc = EnemiesInArcHolder .Where(a => a.Key == ArcFacing.Front || a.Key == ArcFacing.Rear) .Sum(a => a.Value.Count); enemiesInLeftRearArc = EnemiesInArcHolder .Where(a => a.Key == ArcFacing.Front || a.Key == ArcFacing.Left || a.Key == ArcFacing.Right) .Sum(a => a.Value.Count); } else { enemiesInFrontRearArc = EnemiesInArcHolder .Where(a => a.Key == ArcFacing.Front || a.Key == ArcFacing.Rear) .Sum(a => a.Value.Count); enemiesInLeftRearArc = EnemiesInArcHolder .Where(a => a.Key == ArcFacing.Left || a.Key == ArcFacing.Right) .Sum(a => a.Value.Count); } facing = (enemiesInFrontRearArc >= enemiesInLeftRearArc) ? "Front-Rear" : "Left-Right"; } else { if (Selection.ThisShip.ShipInfo.ArcInfo.Arcs.Any(a => a.ArcType == ArcType.Front)) { facing = "Left-Right"; } else { facing = "Front-Rear"; } } } return(facing); }