Salmo
Feb-12-2014, 18:11
It frustrates me to join a mission, select an army, & see the spawn spawn bases, but I see base names but no indication of what planes are at those bases. In some cases mission builders include the planeset in the base name, but what if the mission builder wants to change the planeset around? They would have to rename all their spawn bases. I have an easier solution. Just name your bases in FMB when you build your mission & run this script with the mission. All bases are automatcally renamed to include their current planeset in the map label.
public class Mission : AMission
{
bool PlaneTypesInMapLabels = true; // include spawn-base plane types within the base label on the map screen
public override void OnBattleStarted()
{
base.OnBattleStarted();
if (PlaneTypesInMapLabels)
{
Timeout(10.0, () =>
{ // wait for bases to 'spawn-in' to battle then rename them all
PutPlaneTypesInMapLabels(); // put plane types in the spawn-base map labels
});
}
}
public void PutPlaneTypesInMapLabels()
{
// put plane types in the spawn-base map labels
foreach (AiBirthPlace bp in GamePlay.gpBirthPlaces())
{
string OldMapLabel = bp.Name();
string[] Planeset = bp.GetAircraftTypes();
string[] words = bp.Name().Trim().Split('(');
string MapLabel = words[0] + " (";
foreach (string aircraftname in Planeset)
{
if (aircraftname.Contains("Spit")) MapLabel = MapLabel + "Spitfire, ";
if (aircraftname.Contains("Hurr")) MapLabel = MapLabel + "Hurricane, ";
if (aircraftname.Contains("Blenheim")) MapLabel = MapLabel + "Blenheim, ";
if (aircraftname.Contains("DH82A ")) MapLabel = MapLabel + "Tiger Moth, ";
if (aircraftname.Contains("88")) MapLabel = MapLabel + "Ju88, ";
if (aircraftname.Contains("87")) MapLabel = MapLabel + "Ju87, ";
if (aircraftname.Contains("109")) MapLabel = MapLabel + "Bf109, ";
if (aircraftname.Contains("BR")) MapLabel = MapLabel + "BR20, ";
if (aircraftname.Contains("G50")) MapLabel = MapLabel + "G50, ";
if (aircraftname.Contains("111")) MapLabel = MapLabel + "He111, ";
if (aircraftname.Contains("110")) MapLabel = MapLabel + "Bf110, ";
if (aircraftname.Contains("CR")) MapLabel = MapLabel + "CR42, ";
}
MapLabel = MapLabel.Remove(MapLabel.LastIndexOf(',')) + ")"; ; // get last occurance of , character
RenameSpawnbase(bp, MapLabel);
//Console.WriteLine("Renamed " + OldMapLabel + " to " + MapLabel);
}
public void RenameSpawnbase(AiBirthPlace bp, string name)
{
// write a temporary mission file with the new base name
try
{
ISectionFile f = GamePlay.gpCreateSectionFile();
string line = '"' + name + '"' + bp.Army().ToString() + " " + bp.Pos().x.ToString() + " " +
bp.Pos().y.ToString() + " 0 " + bp.MaxPlanes().ToString() + " " + "1" + " " +
"1" + " " + bp.Country() + " " + bp.Hierarchy() + " " + bp.Regiment();
f.add("BirthPlace", line, null); // write a line of text to the file
string[] planeset = bp.GetAircraftTypes();
foreach (string aircraft in planeset) f.add("BirthPlace0", aircraft, null);
bp.destroy();
GamePlay.gpPostMissionLoad(f);
}
catch (NullReferenceException n)
{ }
catch (Exception e)
{
Console.WriteLine("ERROR: [RenameSpawnbase] " + e.Message);
}
}
}
public class Mission : AMission
{
bool PlaneTypesInMapLabels = true; // include spawn-base plane types within the base label on the map screen
public override void OnBattleStarted()
{
base.OnBattleStarted();
if (PlaneTypesInMapLabels)
{
Timeout(10.0, () =>
{ // wait for bases to 'spawn-in' to battle then rename them all
PutPlaneTypesInMapLabels(); // put plane types in the spawn-base map labels
});
}
}
public void PutPlaneTypesInMapLabels()
{
// put plane types in the spawn-base map labels
foreach (AiBirthPlace bp in GamePlay.gpBirthPlaces())
{
string OldMapLabel = bp.Name();
string[] Planeset = bp.GetAircraftTypes();
string[] words = bp.Name().Trim().Split('(');
string MapLabel = words[0] + " (";
foreach (string aircraftname in Planeset)
{
if (aircraftname.Contains("Spit")) MapLabel = MapLabel + "Spitfire, ";
if (aircraftname.Contains("Hurr")) MapLabel = MapLabel + "Hurricane, ";
if (aircraftname.Contains("Blenheim")) MapLabel = MapLabel + "Blenheim, ";
if (aircraftname.Contains("DH82A ")) MapLabel = MapLabel + "Tiger Moth, ";
if (aircraftname.Contains("88")) MapLabel = MapLabel + "Ju88, ";
if (aircraftname.Contains("87")) MapLabel = MapLabel + "Ju87, ";
if (aircraftname.Contains("109")) MapLabel = MapLabel + "Bf109, ";
if (aircraftname.Contains("BR")) MapLabel = MapLabel + "BR20, ";
if (aircraftname.Contains("G50")) MapLabel = MapLabel + "G50, ";
if (aircraftname.Contains("111")) MapLabel = MapLabel + "He111, ";
if (aircraftname.Contains("110")) MapLabel = MapLabel + "Bf110, ";
if (aircraftname.Contains("CR")) MapLabel = MapLabel + "CR42, ";
}
MapLabel = MapLabel.Remove(MapLabel.LastIndexOf(',')) + ")"; ; // get last occurance of , character
RenameSpawnbase(bp, MapLabel);
//Console.WriteLine("Renamed " + OldMapLabel + " to " + MapLabel);
}
public void RenameSpawnbase(AiBirthPlace bp, string name)
{
// write a temporary mission file with the new base name
try
{
ISectionFile f = GamePlay.gpCreateSectionFile();
string line = '"' + name + '"' + bp.Army().ToString() + " " + bp.Pos().x.ToString() + " " +
bp.Pos().y.ToString() + " 0 " + bp.MaxPlanes().ToString() + " " + "1" + " " +
"1" + " " + bp.Country() + " " + bp.Hierarchy() + " " + bp.Regiment();
f.add("BirthPlace", line, null); // write a line of text to the file
string[] planeset = bp.GetAircraftTypes();
foreach (string aircraft in planeset) f.add("BirthPlace0", aircraft, null);
bp.destroy();
GamePlay.gpPostMissionLoad(f);
}
catch (NullReferenceException n)
{ }
catch (Exception e)
{
Console.WriteLine("ERROR: [RenameSpawnbase] " + e.Message);
}
}
}