PDA

View Full Version : Sal's useful scripts [Random AA at airfields]



Salmo
Feb-23-2014, 01:12
Here's a little gem that will automatically generate a random number of AA units at airfields when the battle starts. No need to place AA's around airfields, this beauty does it all for you. You can turn it on & off, and specify how many AA you want & whether you want AA at spawn bases only or at all airfields.



using System.Text;
using System;
using System.Collections;
using maddox.game;
using maddox.game.world;
using part;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using System.Runtime.InteropServices;
using System.Globalization;
using System.Reflection;
using maddox.GP;
using System.Text.RegularExpressions;


public class Mission : AMission
{
Random random = new Random();

// random AA on battle startup (generate random AA at airfields on battle start)
#region random AA on battle startup
bool GenerateRandomAA = true; // turn random AA at airfields on/off
bool SpawnBasesAAOnly = false; // random AA generated at spawn airfields only
int ChanceSpawnbaseHasAA = 100; // percent chance a spawn base has AA defences
int ChanceNonSpawnbaseHasAA = 0; // percent chance a non-spawn base has AA defences
int RedMinAirfieldAA = 6; // minimum number of AA units at red airfields
int RedMaxAirfieldAA = 8; // maximum number of AA units at red airfields
int BlueMinAirfieldAA = 8; // minimum number of AA units at blue airfields
int BlueMaxAirfieldAA = 10; // maximum number of AA units at blue airfields
#endregion

public override void OnBattleStarted()
{
base.OnBattleStarted();
if (GenerateRandomAA ) GenerateRandomAAatAirfields();
}

public void GenerateRandomAAatAirfields()
#region spawn random AA at airfields
{ // spawn random AA at airfields
List<string> AlliedAA = new List<string>
{
"Artillery.3_inch_20_CWT_QF_Mk_I gb",
"Artillery.3_7_inch_QF_Mk_I gb",
"Artillery.Bofors gb",
"Artillery.20_mm_Flak_38 gb"
};

List<string> AxisAA = new List<string>
{
"Artillery.Flak30_Shield de",
"Artillery.Flak37 de",
"Artillery.20_mm_Flak_38 de",
"Artillery.Zwillingssockel36_GER1 de",
"Artillery.4_cm_Flak_28 de"
};

// do some parameter intergity checks
if (ChanceSpawnbaseHasAA > 100) ChanceSpawnbaseHasAA = 100;
if (ChanceSpawnbaseHasAA < 0) ChanceSpawnbaseHasAA = 0;
if (ChanceNonSpawnbaseHasAA > 100) ChanceNonSpawnbaseHasAA = 100;
if (ChanceNonSpawnbaseHasAA < 0) ChanceNonSpawnbaseHasAA = 0;
if (RedMinAirfieldAA < 0) RedMinAirfieldAA = 0;
if (BlueMinAirfieldAA < 0) BlueMinAirfieldAA = 0;
if (RedMaxAirfieldAA < RedMinAirfieldAA) RedMaxAirfieldAA = RedMinAirfieldAA;
if (BlueMaxAirfieldAA < BlueMinAirfieldAA) BlueMaxAirfieldAA = BlueMinAirfieldAA;

int staticno = 0;
ISectionFile f = GamePlay.gpCreateSectionFile();

foreach (AiAirport TargetAirport in GamePlay.gpAirports()) // loop through all map airfields
{
Point2d port = new Point2d(); // remember the airfield position
port.x = TargetAirport.Pos().x;
port.y = TargetAirport.Pos().y;

if (IsInBattleZone(port)) // is airfield inside the battle zone grid?
{
Point2d AApos = new Point2d(); // create a point for the AA position
int AirportArmy = GetArmyAtPoint(port.x, port.y); // remember the airport army
if (AirportArmy == 0) AirportArmy = TargetAirport.Army(); // remember the airport army

// ------------------------------------------------------------------------------------------------
// ALLIED ARMY SPAWN BASES
// ------------------------------------------------------------------------------------------------
if (AirportArmy == 1 && IsBirthplace(TargetAirport)) // airfield is allied army & a spawn point
{
if (random.Next(100) < ChanceSpawnbaseHasAA) // chance a spawn airfield has AA defences
{
int i = random.Next(RedMinAirfieldAA, RedMaxAirfieldAA + 1); // decide how many AA units to spawn at the airfield
for (int j = 0; j < i; j++)
{
// find a suitable AA position close to, but just outside, the airfield perimeter
AApos = GetRandomPointInsideCircle(TargetAirport.Pos().x, TargetAirport.Pos().y, TargetAirport.FieldR() * 0.70 * 1.25);
while (port.distance(ref AApos) < (TargetAirport.FieldR() * 0.95) || IsInvalidAAposition(AApos, 100))
{
AApos = GetRandomPointInsideCircle(TargetAirport.Pos().x, TargetAirport.Pos().y, TargetAirport.FieldR() * 0.70 * 1.25);
};

// make a new unique static object number for mission file
staticno++;
if (j == 0)
{ // at least one black flak unit
f.add("Stationary", "Static" + staticno.ToString("0000"), AlliedAA[0] + " " +
AApos.x.ToString() + " " + AApos.y.ToString() + " " + random.Next(1, 178 + 1).ToString() + " /timeout 0/radius_hide 0/skill 1");
}
else
{
int rnd = random.Next(AlliedAA.Count);
f.add("Stationary", "Static" + staticno.ToString("0000"), AlliedAA[rnd] + " " +
AApos.x.ToString() + " " + AApos.y.ToString() + " " + random.Next(1, 178 + 1).ToString() + " /timeout 0/radius_hide 0/skill 1");
}
}
}
}

// ------------------------------------------------------------------------------------------------
// AXIS ARMY SPAWN BASES
// ------------------------------------------------------------------------------------------------
if (AirportArmy == 2 && IsBirthplace(TargetAirport)) // airfield is axis army & a spawn point
{
if (random.Next(100) < ChanceSpawnbaseHasAA) // chance a spawn airfield has AA defences
{
int i = random.Next(BlueMinAirfieldAA, BlueMaxAirfieldAA + 1); // decide how many AA units to spawn at the airfield
for (int j = 0; j < i; j++)
{
// find a suitable AA position close to, but just outside, the airfield perimeter
AApos = GetRandomPointInsideCircle(TargetAirport.Pos().x, TargetAirport.Pos().y, TargetAirport.FieldR() * 0.70 * 1.25);
while (port.distance(ref AApos) < (TargetAirport.FieldR() * 0.95) || IsInvalidAAposition(AApos, 100))
{
AApos = GetRandomPointInsideCircle(TargetAirport.Pos().x, TargetAirport.Pos().y, TargetAirport.FieldR() * 0.70 * 1.25);
};

// make a new unique static object number for mission file
staticno++;
if (j == 0)
{ // at least one black flak unit
f.add("Stationary", "Static" + staticno.ToString("0000"), "Artillery.20_mm_Flak_38 de " + AApos.x.ToString() + " " + AApos.y.ToString() + " " + random.Next(1, 178 + 1).ToString() + " /timeout 0/radius_hide 0");
}
else
{
int rnd = random.Next(AxisAA.Count);
f.add("Stationary", "Static" + staticno.ToString("0000"), AxisAA[rnd] + " " +
AApos.x.ToString() + " " + AApos.y.ToString() + " " + random.Next(1, 178 + 1).ToString() + " /timeout 0/radius_hide 0");
}
}
}


if (!SpawnBasesAAOnly) // do we also want AA units at non-spawn bases?
{
// ------------------------------------------------------------------------------------------------
// ALLIED ARMY NON-SPAWN BASES
// ------------------------------------------------------------------------------------------------
if (AirportArmy == 1 && !IsBirthplace(TargetAirport)) // airfield is allied army & NOT a spawn point
{
if (random.Next(100) < ChanceNonSpawnbaseHasAA) // chance a non-spawn airfield has AA defences
{
int i = random.Next(RedMinAirfieldAA, RedMaxAirfieldAA + 1); // decide how many AA units to spawn at the airfield
for (int j = 0; j < i; j++)
{
// find a suitable AA position close to, but just outside, the airfield perimeter
AApos = GetRandomPointInsideCircle(TargetAirport.Pos().x, TargetAirport.Pos().y, TargetAirport.FieldR() * 0.70 * 1.25);
while (port.distance(ref AApos) < (TargetAirport.FieldR() * 0.95) || IsInvalidAAposition(AApos, 100))
{
AApos = GetRandomPointInsideCircle(TargetAirport.Pos().x, TargetAirport.Pos().y, TargetAirport.FieldR() * 0.70 * 1.25);
};

// make a new unique static object number for mission file
staticno++;
if (j == 0)
{ // at least one black flak unit
f.add("Stationary", "Static" + staticno.ToString("0000"), AlliedAA[0] + " " +
AApos.x.ToString() + " " + AApos.y.ToString() + " " + random.Next(1, 178 + 1).ToString() + " /timeout 0/radius_hide 0/skill 1");

Point3d p;
p.x = AApos.x;
p.y = AApos.y;
p.z = 0;
}
else
{
int rnd = random.Next(AlliedAA.Count);
f.add("Stationary", "Static" + staticno.ToString("0000"), AlliedAA[rnd] + " " +
AApos.x.ToString() + " " + AApos.y.ToString() + " " + random.Next(1, 178 + 1).ToString() + " /timeout 0/radius_hide 0/skill 1");
}
}
}
}

if (AirportArmy == 2 && !IsBirthplace(TargetAirport)) // airfield is axis army & NOT a spawn point
{
// ------------------------------------------------------------------------------------------------
// AXIS ARMY NON-SPAWN BASES
// ------------------------------------------------------------------------------------------------
if (random.Next(100) < ChanceNonSpawnbaseHasAA) // chance a non-spawn airfield has AA defences
{
int i = random.Next(BlueMinAirfieldAA, BlueMaxAirfieldAA + 1); // decide how many AA units to spawn at the airfield
for (int j = 0; j < i; j++)
{
// find a suitable AA position close to, but just outside, the airfield perimeter
AApos = GetRandomPointInsideCircle(TargetAirport.Pos().x, TargetAirport.Pos().y, TargetAirport.FieldR() * 0.70 * 1.25);
while (port.distance(ref AApos) < (TargetAirport.FieldR() * 0.95) || IsInvalidAAposition(AApos, 100))
{
AApos = GetRandomPointInsideCircle(TargetAirport.Pos().x, TargetAirport.Pos().y, TargetAirport.FieldR() * 0.70 * 1.25);
};

// make a new unique static object number for mission file
staticno++;
if (j == 0)
{ // at least one black flak unit
f.add("Stationary", "Static" + staticno.ToString("0000"), "Artillery.20_mm_Flak_38 de " + AApos.x.ToString() + " " + AApos.y.ToString() + " " + random.Next(1, 178 + 1).ToString() + " /timeout 0/radius_hide 0");
}
else
{
int rnd = random.Next(AxisAA.Count);
f.add("Stationary", "Static" + staticno.ToString("0000"), AxisAA[rnd] + " " +
AApos.x.ToString() + " " + AApos.y.ToString() + " " + random.Next(1, 178 + 1).ToString() + " /timeout 0/radius_hide 0");
}
}
}
}
}
}
else
{ // write an error message to the concole
//Console.WriteLine("CAUTION: Could not spawn AA at " + TargetAirport.Name() + "(army=" + AirportArmy.ToString() + ") [GenerateRandomAAatAirfields]");
}
}
}

GamePlay.gpPostMissionLoad(f); // load the mission with the AA units
}
#endregion

public bool IsBirthplace(AiAirport airfield)
#region returns whether named airfield is a birthpace (spawn point)
{
bool result = false;
foreach (AiBirthPlace bp in GamePlay.gpBirthPlaces())
{
Point3d p = bp.Pos();
if (airfield.Pos().distance(ref p) <= airfield.CoverageR() || airfield.Pos().distance(ref p) <= airfield.FieldR())
{
result = true;
}
}
return result;
}
#endregion

public bool IsInBattleZone(Point2d p)
#region returns true if specified point is inside the battle zone grid
{ // returns true if specified point is inside the battle zone grid
bool result = false;
string sector = GamePlay.gpSectorName(p.x, p.y); // get the sector at the specified point
string[] words = sector.Split(','); // break up the sector name
string axis1 = words[0]; // first part is X axis
string axis2 = words[1]; // second part is Y axis
// is it inside the battle grid?
if (Regex.IsMatch(axis1, @"^[a-zA-Z0-9]+$") && Regex.IsMatch(axis2, @"^[a-zA-Z0-9]+$")) result = true;
return result;
}
#endregion

public bool IsInvalidAAposition(Point2d point, double radius)
#region returns true if specified point is not a valid position for an AA unit
{
bool result = false;
Point3d p = new Point3d();
p.x = point.x;
p.y = point.y;
p.z = 0;

// too close to other ground units
try
{
foreach (GroundStationary gs in GamePlay.gpGroundStationarys())
{
if (gs.pos.distance(ref p) <= radius) result = true;
}
}
catch { }

// wrong terrain
if (GamePlay.gpLandType(point.x, point.y) == LandTypes.RAIL || GamePlay.gpLandType(point.x, point.y) == LandTypes.ROAD ||
GamePlay.gpLandType(point.x, point.y) == LandTypes.WATER || GamePlay.gpLandType(point.x, point.y) == LandTypes.OBJECTS_MASK ||
GamePlay.gpLandType(point.x, point.y) == LandTypes.ROAD_MASK || GamePlay.gpLandType(point.x, point.y) == LandTypes.HIGHWAY ||
GamePlay.gpLandType(point.x, point.y) == LandTypes.CITY) result = true;

// outside the battle zone?
if (!IsInBattleZone(point)) result = true;

return result;
}
catch { return true; }
}
#endregion

public int GetArmyAtPoint(double x, double y)
#region returns the army number at the specified point
{
int result = 0;
result = GamePlay.gpFrontArmy(x, y);
return result;
}
#endregion

public Point2d GetRandomPointInsideCircle(double x, double y, double r)
#region return a random 2d point inside circle with centre x, y and radius r (metres)
{ // return a random 2d point inside circle with centre x, y and radius r (metres)
Point2d p = new Point2d();
p.x = x + r * Math.Cos(random.Next());
p.y = y + r * Math.Sin(random.Next());
return p;
}
#endregion
}

No601_Swallow
Feb-23-2014, 12:43
:dazed!:

Just wow! It's getting to the stage that I'm wondering if there's anything scripting in this game can't do...

And inspired by Salmo's example, I'm going to enroll my 14-year-old son in a scripting and coding night school (I'm too old to learn!)
:doh:

=FI=Murph
Feb-25-2014, 22:43
Could you provide some guidance on how to set this up? (Other than copy/pasting it as a .cs file in the location of the mission) How are the parameters set for likelyhood of AA spawning? How to set so they are at all bases?
I am trying to use this as you have posted it with a DF mission but I can't see any effect. Does it matter if I already have some flak guns placed in the mission?

Salmo
Feb-26-2014, 02:57
Could you provide some guidance on how to set this up? (Other than copy/pasting it as a .cs file in the location of the mission) How are the parameters set for likelyhood of AA spawning? How to set so they are at all bases?
I am trying to use this as you have posted it with a DF mission but I can't see any effect. Does it matter if I already have some flak guns placed in the mission?

Hello Murph,

Firstly, have you named your cs file exactly the same as your mission file?
Secondly, is it in the same folder as the mission file?
Thirdly, have you maybe got the line GenerateRandomAA = false; which will turn all AA generation off.
Fourthly, AA is generated within the batle grid area. Is it possible you have the battle grid outside the area you want the AA generated?
Fithly, have you set the percent chance of AA generation to zero? So both ChanceSpawnbaseHasAA = 0 and ChanceNonSpawnbaseHasAA = 0? To test I'd start off by setting both these to 100% then scale down from there. Remember if you set these to less than 100% then there is a chance that some bases will not have AA by design.

Does it matter if I already have some flak guns placed in the mission? - No. AA already existing on the map will not be affected.

How to set so they are at all bases? Set GenerateRandomAA = true, ChanceSpawnbaseHasAA = 100, ChanceNonSpawnbaseHasAA = 100, RedMinAirfieldAA = greater than 0 (try a largish number say 20) & work down, RedMaxAirfieldAA = at least equal to RedMinAirfieldAA, BlueMinAirfieldAA = greater than 0 (try a largish number say 20) & work down, BlueMaxAirfieldAA = at least equal to BlueMinAirfieldAA

Each of the user configurarable parameters is at the start of the script. Parameters have self-explanatory comments, but here's more of an explanation:

bool GenerateRandomAA = true; // turn random AA at airfields on/off
false - all automatic AA generation is turned off.
true - automatic AA generation is turmed on

bool SpawnBasesAAOnly = false; // random AA generated at spawn airfields only
false - AA is automatically generated at all airbases within the battle zone grid
rue - AA is on generated at spawnbases within the battle zone grid

int ChanceSpawnbaseHasAA = 100; // percent chance a spawn base has AA defences
A number from 0 to 100 representing that % chance a spawn base has AA defences. So if for example you put 50, then (on avaerage) 50% of spawn bases will have AA around them.

int ChanceNonSpawnbaseHasAA = 0; // percent chance a non-spawn base has AA defences
A number from 0 to 100 representing that % chance a non-spawn airfield has AA defences. So if for example you put 50, then (on avaerage) 50% of non-spawn airfields will have AA around them.

int RedMinAirfieldAA = 6; // minimum number of AA units at red airfields
Any integer number greater than 0. This will be the minimum number of AA generated at red airfields/bases if the base is chosen by the script to have AA.

int RedMaxAirfieldAA = 8; // maximum number of AA units at red airfields
Any integer number greater than or eaqual to RedMinAirfieldAA. This will be the maximum number of AA generated at red airfields/bases if the base is chosen by the script to have AA.

int BlueMinAirfieldAA = 8; // minimum number of AA units at blue airfields
Any integer number greater than 0. This will be the minimum number of AA generated at blue airfields/bases is the base if chosen by the script to have AA.

int BlueMaxAirfieldAA = 10; // maximum number of AA units at blue airfields
Any integer number greater than or eaqual to BlueMinAirfieldAA. This will be the maximum number of AA generated at blue airfields/bases if the base is chosen by the script to have AA.

=FI=Murph
Feb-27-2014, 10:11
Thanks for the clarification. I'll do some testing.

ATAG_Lolsav
Mar-01-2014, 14:57
Hi Sal. tryed to use this script to populate AA, but it gives a error on line 87. Seems it doesnt recognize the word "random". Wonder if im missing something

Salmo
Mar-01-2014, 18:07
Hi Sal. tryed to use this script to populate AA, but it gives a error on line 87. Seems it doesnt recognize the word "random". Wonder if im missing something

I failed to declare the random vatiable at the start of the script. Add the line "Random random = new Random();" just after the public AMission class declation as below.



public class Mission : AMission
{
Random random = new Random();



1st post updated.

ATAG_Lolsav
Mar-01-2014, 18:48
Thank you. Testing and i feedback next.

Feedback: Now its other error. "Nearest airfield" does not exist on the context

Salmo
Mar-01-2014, 20:36
Thank you. Testing and i feedback next.

Feedback: Now its other error. "Nearest airfield" does not exist on the context

Thanks Lolsav,

I forgot to include the getNearestAirfield function. 1st post updated. Add this function just before the lasy "}" at the end of the script


airports = GamePlay.gpAirports();
Point3d StartPos = location;

if (airports != null)
{
foreach (AiAirport airport in airports)
{
if (NearestAirfield != null)
{
if (NearestAirfield.Pos().distance(ref StartPos) > airport.Pos().distance(ref StartPos))
NearestAirfield = airport;
}
else NearestAirfield = airport;
}
}
return NearestAirfield;
}

ATAG_Lolsav
Mar-01-2014, 23:18
The line:


ColoredConsoleWrite(ConsoleColor.Yellow, "Spawned AA: " + AlliedAA[0] + " at " + GetNearestAirfield(p).Name());

does not exist in the current context

Salmo
Mar-01-2014, 23:28
The line:


ColoredConsoleWrite(ConsoleColor.Yellow, "Spawned AA: " + AlliedAA[0] + " at " + GetNearestAirfield(p).Name());

does not exist in the current context

Is a leftover debugging line. Delete the line. Now that the debug line is deleted, you won't need the GetNearestAirfield function so that can be deleted too.

1st post updated.

ATAG_Lolsav
Mar-01-2014, 23:33
One by one we will get there:

"Not all code paths return a value" --- looking for correspondent part on code, brb

Believe its due to this section


public int GenerateRandomAAatAirfields()

Salmo
Mar-02-2014, 04:04
One by one we will get there:

"Not all code paths return a value" --- looking for correspondent part on code, brb

Believe its due to this section


public int GenerateRandomAAatAirfields()

You are indeed correct, the line should be public void GenerateRandomAAatAirfields(). That's what you get for trying to snip out some working code from 5,000 lines of code & presenting it for others to use. Most people don't appeciate the work involved. Hope it works for you now.

1st post code updated ...

ATAG_Lolsav
Mar-02-2014, 13:11
No code lines error but seems to be a script bug somewhere.

"Object reference not set to a instance of an object"

Then it presents Server stack trace, starting with:

at Mission.IsInvalidAAposition (point2d point, Double radius)

Mission.GenerateRandomAAatAirfields ()

... and goes on

Salmo
Mar-02-2014, 14:05
No code lines error but seems to be a script bug somewhere.

"Object reference not set to a instance of an object"

Then it presents Server stack trace, starting with:

at Mission.IsInvalidAAposition (point2d point, Double radius)

Mission.GenerateRandomAAatAirfields ()

... and goes on

do you have red & blue front line markers? What map are you using?

ATAG_Lolsav
Mar-02-2014, 14:09
7832

Yes i do. Frontline markers as usual.

Salmo
Mar-02-2014, 15:00
7832

Yes i do. Frontline markers as usual.

I've changed the IsInvalidAAposition function to trap the error. Replace this function with bthe new code in the 1st post. 1st post updated again.

ATAG_Lolsav
Mar-02-2014, 16:18
EDIT: Found it was case sensitive and replaced "T" by "t" - but now battle wont start.. trying again once my pc responds

EDIT2: Doesnt respond, it hangs.

__________________________________________________ __________________________________________________ _____

Synthax error with "Try"


Try
{
// too close to other ground units
foreach (GroundStationary gs in GamePlay.gpGroundStationarys())
{
if (gs.pos.distance(ref p) <= radius) result = true;
}

// wrong terrain
if (GamePlay.gpLandType(point.x, point.y) == LandTypes.RAIL || GamePlay.gpLandType(point.x, point.y) == LandTypes.ROAD ||
GamePlay.gpLandType(point.x, point.y) == LandTypes.WATER || GamePlay.gpLandType(point.x, point.y) == LandTypes.OBJECTS_MASK ||
GamePlay.gpLandType(point.x, point.y) == LandTypes.ROAD_MASK || GamePlay.gpLandType(point.x, point.y) == LandTypes.HIGHWAY ||
GamePlay.gpLandType(point.x, point.y) == LandTypes.CITY) result = true;

// outside the battle zone?
if (!IsInBattleZone(point)) result = true;

return result;
}
catch { return true; }
}

Salmo
Mar-02-2014, 16:35
Synthax error with "Try"

Aghhh! I hate trying to provide code without running it though Express for syntax correction. Change "Try" to "try" (no quotes all lower case). 1st post updated again.

ATAG_Lolsav
Mar-02-2014, 16:45
Aghhh! I hate trying to provide code without running it though Express for syntax correction. Change "Try" to "try" (no quotes all lower case). 1st post updated again.

done that :) see the edits above.

Edit: Was trying to put a pause in the loop, to prevent the hang. How can i do that?

Salmo
Mar-03-2014, 03:12
done that :) see the edits above.

Edit: Was trying to put a pause in the loop, to prevent the hang. How can i do that?

Prevent the hang? I assume it's hanging while looping looking searching for suitab;e AA position the plave the AA gun. I've have a look tomorrow or the next day when I have more time & completely revise the routines.

In the meaantime you could try this function



public bool IsInvalidAAposition(Point2d point, double radius)
#region returns true if specified point is not a valid position for an AA unit
{
bool result = false;
Point3d p = new Point3d();
p.x = point.x;
p.y = point.y;
p.z = 0;

// too close to other ground units
try
{
foreach (GroundStationary gs in GamePlay.gpGroundStationarys())
{
if (gs.pos.distance(ref p) <= radius) result = true;
}
}
catch {}

// wrong terrain
if (GamePlay.gpLandType(point.x, point.y) == LandTypes.RAIL || GamePlay.gpLandType(point.x, point.y) == LandTypes.ROAD ||
GamePlay.gpLandType(point.x, point.y) == LandTypes.WATER || GamePlay.gpLandType(point.x, point.y) == LandTypes.OBJECTS_MASK ||
GamePlay.gpLandType(point.x, point.y) == LandTypes.ROAD_MASK || GamePlay.gpLandType(point.x, point.y) == LandTypes.HIGHWAY ||
GamePlay.gpLandType(point.x, point.y) == LandTypes.CITY) result = true;

// outside the battle zone?
if (!IsInBattleZone(point)) result = true;

return result;
}
#endregion

ATAG_Lolsav
Mar-03-2014, 08:39
In my lunch hour so only have time to do a quick update:

With latest function it works :) Eureka!!!

Im not sure the red artillery is spawned at correct location and blue vice-versa, but when i have more time will re-test it.

=FI=Murph
Mar-03-2014, 08:49
Let us know when we have a complete revised version in the first post. There are so many little edits now I'm losing track. Thanks to you both for the script and for the testing and editing!

Salmo
Mar-03-2014, 14:57
Let us know when we have a complete revised version in the first post. There are so many little edits now I'm losing track. Thanks to you both for the script and for the testing and editing!

1st post updated with all changes, hope it works now.

No601_Swallow
Mar-04-2014, 05:28
S! Salmo and Lobsav! Highly instructive for the interested observer. A few key cogs have just dropped into place in my brain!:thumbsup:

ATAG_Lolsav
Mar-04-2014, 16:55
Hi again with good news and hopefully presenting a problem with easy fix.

It works, definatly and managed to integrate to work with other scripts (like the Salmo random weather)

But we have to get around a annoying bug. Sometimes, not sure under what conditions, it spawns a enemy unit over the wrong side:

7884

Example of what happened at a hawkinge spawn

SoW Reddog
Mar-04-2014, 17:02
Looks to be a 20mm flak 38 to me. Not sure if simply by using "gb" you can switch the side??

ATAG_Lolsav
Mar-04-2014, 17:07
I dont think its a misplaced name, "de" or "gb", i just dont know if its the script misplacing the unit on the wrong side of the map. It spawns, its placed, but why is it on the wrong side of the border i dont know.

SoW Reddog
Mar-04-2014, 17:14
If you look at the spawnable AA units, you'll see it on both sides. Just comment out the other types, run the mission. If all the British guns fire at you, that's the problem unit. Debugging is an iterative, process of elimination thing, especially in CloD.

ATAG_Lolsav
Mar-04-2014, 17:27
If you take a look at Salmos code you will see


List<string> AlliedAA = new List<string>
{
"Artillery.3_inch_20_CWT_QF_Mk_I gb",
"Artillery.3_7_inch_QF_Mk_I gb",
"Artillery.Bofors gb",
"Artillery.20_mm_Flak_38 gb"
};

List<string> AxisAA = new List<string>
{
"Artillery.Flak30_Shield de",
"Artillery.Flak37 de",
"Artillery.20_mm_Flak_38 de",
"Artillery.Zwillingssockel36_GER1 de",
"Artillery.4_cm_Flak_28 de"

So what puzzles me its the artillery is defined on the correct army side, but it spawns as a germany unit

Artillery.3_inch_20_CWT_QF_Mk_I gb was what killed me in the screenshot