public static List <FormationPatternData> CreateCubeFormationPattern( List <Ship> ships, Matrix formationMat) { List <FormationPatternData> formationPatternDataList = new List <FormationPatternData>(); int count = ships.Count; for (int index = 0; index < count; ++index) { formationPatternDataList.Add(new FormationPatternData() { Position = FormationPatternCreator.GetCubeFormationPositionAtIndex(index), Ship = (Ship)null, IsLead = index == 0 }); } List <Ship> remainingShips = new List <Ship>(); remainingShips.AddRange((IEnumerable <Ship>)ships); for (int index = 0; index < count; ++index) { formationPatternDataList[index].Ship = FormationPatternCreator.FindBestFitShipBySize(remainingShips, formationPatternDataList[index].Position, formationMat, ShipClass.Leviathan); remainingShips.Remove(formationPatternDataList[index].Ship); } return(formationPatternDataList); }
public void CreateFormationPattern(Vector3 pos, Vector3 facing, bool vFormation) { if ((double)facing.LengthSquared <= 9.99999974737875E-06 || !facing.IsFinite() || this.m_ships.Count == 0) { return; } Matrix world = Matrix.CreateWorld(ShipFormation.GetCenterOfMass(this.m_ships), facing, Vector3.UnitY); this.m_formationPattern = !vFormation?FormationPatternCreator.CreateLineAbreastPattern(this.m_ships, world) : FormationPatternCreator.CreateVFormationPattern(this.m_ships, world); float val2 = 0.0f; foreach (FormationPatternData formationPatternData in this.m_formationPattern) { val2 = Math.Max(formationPatternData.Position.Z, val2); } List <FormationPatternData> lineAbreastPattern = FormationPatternCreator.CreateLineAbreastPattern(this.m_shipsOnBackLine, Matrix.CreateWorld(ShipFormation.GetCenterOfMass(this.m_shipsOnBackLine), facing, Vector3.UnitY)); foreach (FormationPatternData formationPatternData in lineAbreastPattern) { Vector3 position = formationPatternData.Position; position.Z += this.m_BackLineOffsetDist + val2; formationPatternData.IsLead = formationPatternData.IsLead && this.m_formationPattern.Count == 0; formationPatternData.Position = position; } this.m_formationPattern.AddRange((IEnumerable <FormationPatternData>)lineAbreastPattern); }
public static List <FormationPatternData> CreateLineAbreastPattern( List <Ship> ships, Matrix formationMat) { List <FormationPatternData> formationPatternDataList = new List <FormationPatternData>(); int count = ships.Count; Vector3 zero = Vector3.Zero; for (int index = 0; index < count; ++index) { FormationPatternData formationPatternData = new FormationPatternData(); formationPatternData.Position = FormationPatternCreator.GetLineAbreastPositionAtIndex(index); formationPatternData.Ship = (Ship)null; formationPatternData.IsLead = index == 0; zero += formationPatternData.Position; formationPatternDataList.Add(formationPatternData); } if (formationPatternDataList.Count > 0) { zero /= (float)formationPatternDataList.Count; } List <Ship> remainingShips = new List <Ship>(); remainingShips.AddRange((IEnumerable <Ship>)ships); for (int index = 0; index < count; ++index) { formationPatternDataList[index].Ship = FormationPatternCreator.FindBestFitShipBySize(remainingShips, formationPatternDataList[index].Position - zero, formationMat, ShipClass.Leviathan); remainingShips.Remove(formationPatternDataList[index].Ship); } return(formationPatternDataList); }