Hi
I have seen the use of this function that is very interesting, but I was wondering how does he knows which units correspond to each side? Is it looking at the sides file and then searching for Axis or Ally units?
I am saying this because it appears to be a big limitation right now, as it appears that there is going to be a single squads file I would like to have another attribute that establishes the nation of the unit (I was using the soundbank for it). That way you can have a more generic function that searches for units per nation rather than side, so that it is simpler to add any unit with more control and without the limitation of 2sides=2nations.
FindRandomSquad sides and nations
Moderators: Slitherine Core, BA Moderators
-
pipfromslitherine
- Site Admin

- Posts: 9947
- Joined: Wed Mar 23, 2005 10:35 pm
Re: FindRandomSquad sides and nations
Some further info on this function (although - stop modding! Keep playing and giving us unit feedback!
).
unit selection heavily uses a new function FindRandomSquad(side, squadType, minCost, maxCost, numAttribs) to find a random squad meeting specified criteria
side - 0 or 1 as usual
squadType - corresponds to the Type column in the squads table
minCost - the suggested minimum cost for the squad (the Cost column in the squads table), this is not a hard limit and the most expensive squad that meets all other criteria will be returned if nothing has at least minCost
maxCost – the maximum cost for the squad (this is a hard limit)
numAttribs – the number of other criteria for the squad set in the work arrays
work array 0 contains the attribute names for the criteria
work array 1 contains the values for the criteria
work array 2 contains the comparison method (-1: less than, 0: equal, 1: greater than, 99: less than or -1, 100: equal or -1, 101: greater than or -1)
return value – 1 if a match is found, –1 otherwise; the result is set in the default work string
ex – to find a Tracked unit with APRating > 29, HERating > 19, Startdate < Jun-40 or undefined, Endate > Jun-41 or undefined with a cost between 100-999:
SetArray(0, "APRating", 0) ;
SetArray(0, 29, 1) ;
SetArray(0, 1, 2) ;
SetArray(1, "HERating", 0) ;
SetArray(1, 19, 1) ;
SetArray(1, 1, 2) ;
SetArray(2, "Startdate", 0) ;
SetArray(2, (12 * 40) + 5, 1) ;
SetArray(2, 99, 2) ; // special date mode, < or undefined
SetArray(3, "Endate", 0) ;
SetArray(3, (12 * 41) + 5, 1) ;
SetArray(3, 101, 2) ; // special date mode, > or undefined
found = FindRandomSquad(side, "TRACKED", 100, 999, 4) ;
if (found > 0)
{
id = AddMapUnit(side, x, y, GetWorkString(0), 0) ;
}
Cheers
Pip
unit selection heavily uses a new function FindRandomSquad(side, squadType, minCost, maxCost, numAttribs) to find a random squad meeting specified criteria
side - 0 or 1 as usual
squadType - corresponds to the Type column in the squads table
minCost - the suggested minimum cost for the squad (the Cost column in the squads table), this is not a hard limit and the most expensive squad that meets all other criteria will be returned if nothing has at least minCost
maxCost – the maximum cost for the squad (this is a hard limit)
numAttribs – the number of other criteria for the squad set in the work arrays
work array 0 contains the attribute names for the criteria
work array 1 contains the values for the criteria
work array 2 contains the comparison method (-1: less than, 0: equal, 1: greater than, 99: less than or -1, 100: equal or -1, 101: greater than or -1)
return value – 1 if a match is found, –1 otherwise; the result is set in the default work string
ex – to find a Tracked unit with APRating > 29, HERating > 19, Startdate < Jun-40 or undefined, Endate > Jun-41 or undefined with a cost between 100-999:
SetArray(0, "APRating", 0) ;
SetArray(0, 29, 1) ;
SetArray(0, 1, 2) ;
SetArray(1, "HERating", 0) ;
SetArray(1, 19, 1) ;
SetArray(1, 1, 2) ;
SetArray(2, "Startdate", 0) ;
SetArray(2, (12 * 40) + 5, 1) ;
SetArray(2, 99, 2) ; // special date mode, < or undefined
SetArray(3, "Endate", 0) ;
SetArray(3, (12 * 41) + 5, 1) ;
SetArray(3, 101, 2) ; // special date mode, > or undefined
found = FindRandomSquad(side, "TRACKED", 100, 999, 4) ;
if (found > 0)
{
id = AddMapUnit(side, x, y, GetWorkString(0), 0) ;
}
Cheers
Pip
follow me on Twitter here
-
AndrewGardner
- Slitherine

- Posts: 535
- Joined: Tue Nov 13, 2012 6:24 pm
Re: FindRandomSquad sides and nations
The side is interpreted as the correct Madeby (Axis/Allies) value for the current scenario based on the sides file.
You can filter for additional attribute(s) that specify a specific nation. As you say, SoundBank implies the nation, but your scenario would still need to have its own copy of the squads file if you wanted to add a column which is more precise.
You can filter for additional attribute(s) that specify a specific nation. As you say, SoundBank implies the nation, but your scenario would still need to have its own copy of the squads file if you wanted to add a column which is more precise.
-
pipfromslitherine
- Site Admin

- Posts: 9947
- Joined: Wed Mar 23, 2005 10:35 pm
Re: FindRandomSquad sides and nations
Just to add - you can still have your own squads file in a campaign, you just need to add the #REPLACE tag in the very first cell. This causes the game not to load the original squads file at all.
Cheers
Pip
Cheers
Pip
follow me on Twitter here
Re: FindRandomSquad sides and nations
I cannot avoid looking at how things are done, and I don't know too much about history to give good unit feedback, at least not better than a lot of people here.
Could I use the FindRandomSquad to pick up a specific unit giving for example the ID attribute or another one that is unique to that unit?
Will put up another post on some suggestions for the sniper unit and another one for my first mod
Could I use the FindRandomSquad to pick up a specific unit giving for example the ID attribute or another one that is unique to that unit?
Will put up another post on some suggestions for the sniper unit and another one for my first mod
