Random placement possible?

Take command of air and naval assets from post-WW2 to the near future in tactical and operational scale, complete with historical and hypothetical scenarios and an integrated scenario editor.

Moderator: MOD_Command

Post Reply
User avatar
PoorOldSpike
Posts: 244
Joined: Sat Apr 19, 2008 4:59 pm
Location: Plymouth, England

Random placement possible?

Post by PoorOldSpike »

Hi, I got CMANO 1.12.5 last week, sorry to start a new thread but I've been stuck all weekend on a couple of things-
1- When creating scens, is there any way to place AI ships so that when the game begins they'll appear at random locations in the area of operations so that I won't know where they are and will have the fun of hunting them down?

2- I can't figure out how to set the 'event/trigger' routines to make my home-made scens automatically end when my (or the AI's) last ship is sunk.
For example if I BOL-launch ASM's at his suspected position it'd give me a warm fuzzy feeling if the game ended shortly afterwards so I'd know I'd nailed him..:)
"Fight with your brain first and your weapons second!"
Rory Noonan
Posts: 2418
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: Random placement possible?

Post by Rory Noonan »

Hi Spike,

You're in luck, both of these are possible and easy to do.

To start in a random position, I usually use Lua scripting as it is much more customisable. However, the easiest way is to place your units in the editor, then create an area with reference points where you'd like the random position to be and then set up an event as follows:
Trigger: Time-Game start time +1s
Action: Teleport selected units to selected area.

This will teleport the selected units to a random position within the selected area at game start time +1s.

To end a scenario automatically, set up an event as follows:
Trigger: Unit destroyed (in your example; could be any trigger you like)
Action: End scenario
Image
User avatar
kevinkins
Posts: 2465
Joined: Wed Mar 08, 2006 11:54 am

RE: Random placement possible?

Post by kevinkins »

last ship is sunk.

By "last" I think you may need a "counter". I have set up a dummy "side" called "shipcounter" and incremented its score by +1 as each ship is sunk. Then you can evaluate the score in an Side Score event to end the scenario using the End Scenario action when the final ship goes down. The dummy side is sort of a global variable within the context of Command and lua. Dummy sides can hold a lot of valuable housekeeping info.

Kevin
“The study of history lies at the foundation of all sound military conclusions and practice.”
Alfred Thayer Mahan
ExNusquam
Posts: 531
Joined: Mon Mar 03, 2014 11:26 pm
Location: Washington, D.C.

RE: Random placement possible?

Post by ExNusquam »

I know this is a week old- but for doing randomization you really should be using a non-repeatable "Scenario Is Loaded" trigger. This means you can randomize the location of player units cleanly as well.
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: Random placement possible?

Post by tjhkkr »

ORIGINAL: Poor Old Spike

Hi, I got CMANO 1.12.5 last week, sorry to start a new thread but I've been stuck all weekend on a couple of things-
1- When creating scens, is there any way to place AI ships so that when the game begins they'll appear at random locations in the area of operations so that I won't know where they are and will have the fun of hunting them down?

Listen, I cannot help you with number 2, but I can help you with this one.
Would you like me to PM you a script that would accomplish this?
Or I can put it out on this group of messages.

I am also working on a way to randomly set units to one side or another... that should be operational in the next day or so...
The biggest problem I have had with that is that you cannot change WHOLE groups... the LUA script chokes on the scenedit command.
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: Random placement possible?

Post by tjhkkr »

This LUA script was meant to add randomly located oil rigs....
Some are enemy.
The 'Neutral 1' will not fire on the opponent, but will report the position
Neutral was truly neutral.
The latitudes and longitudes were within a specific geographical area in the Persian Gulf.
the variable 'b' is the number of platforms I wanted.

So if you wanted to place say, random submarines, and wanted 7, b would be 7.
====
a = 0
b = 25
repeat
a = a + 1
string.name = 'Oil Platform EOP.' .. a
UnitProf = math.random(1,5); UnitProf = UnitProf - 1

r = math.random(1, 85) - 1
r = r / 100
lati = 25.5 + r

r = math.random(1, 175) - 1
r = r / 100
longi = 52.05 + r

string.strLati = lati; string.strLongi = longi

r = math.random(1, 12)
if r >= 1 and r <= 5 then
string.sidename = 'Neutral 1'
rr = math.random(1, 3)
if rr == 1 or rr == 2 then
numdbid = 1869
else
numdbid = 1239
end
elseif r >= 6 and r <= 10 then
string.sidename = 'Neutral'
rr = math.random(1, 3)
if rr == 1 or rr == 2 then
numdbid = 1869
else
numdbid = 1239
end
elseif r > 10 then
string.sidename = 'ISIS/Al Quaida'
numdbid = 1239
if UnitProf < 4 then
UnitProf = UnitProf + 1
end
end

ScenEdit_AddUnit({type = 'ship', name = string.name, heading = 0, dbid = numdbid, side = string.sidename, Latitude= string.strLati ,Longitude= string.strLongi, autodetectable="false",holdfire="false",proficiency=UnitProf})
if string.sidename == 'ISIS/Al Quaida' then
ScenEdit_AssignUnitToMission(string.name, 'YankeeGoHome')
end
until a >= b
Attachments
LUAAddOilRigs.txt
(1.2 KiB) Downloaded 63 times
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: Random placement possible?

Post by tjhkkr »

math.randomseed(1471)
subscr = 0
string.UnitMissionName = 'YankeeGoHome'
string.SiteName = {'Radar (Alfa)', 'Radar (Bandur Abbas)', 'SAM Bty I-HAWK (Bandar-E Bushehr)',
'SAM Grp SA-5 (Bandar-E Bushehr)', 'Radar (Bandar-E Bushehr)', 'Emplacement 1',
'Emplacement 2', 'Emplacement 4','Emplacement 8', 'Emplacement 9a', 'Emplacement 9b', 'eof'}
repeat
subscr = subscr + 1
if string.SiteName[subscr] == 'eof' then
print(subscr)
else
print(subscr)
junkvar = math.random(1,3)
if junkvar > 1 then
ScenEdit_SetUnitSide({side='Neutral', name=string.SiteName[subscr], newside='Iran'})
ScenEdit_AssignUnitToMission(string.SiteName[subscr], string.UnitMissionName)
end
end
until string.SiteName[subscr] == 'eof'


First of all, many of you many not understand the need for such a script, but I love fog of war.

This Script takes single units and randomly assigns it to a nation...
It only takes SINGLE units, it does not work on groups because the Scenedit_SetUnitSide chokes on groups.

The script makes use of subscripted variables. string.SiteName is loaded... obviously you have need to make sure you have the names of the units you wish to run through this process both unique AND must be present or the script ABENDs.
You can have as many units as you want but the last unit must be EOF. That is how the script knows to end.
So I take the sites/units that I want to assign randomly either to Neutral or Iran.
I assign them then to a Mission.

*** WARNING ***
Make sure you save the scenario BEFORE running the script. The change is permanent...
ALSO: the randomseed number should be changed from game to game to that you have some 'randomness'
Attachments
lua_set_pl..rm_side2.txt
(766 Bytes) Downloaded 43 times
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
User avatar
michaelm75au
Posts: 12467
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Random placement possible?

Post by michaelm75au »

To randomize whenever it runs.
math.randomseed( os.time() )
Michael
User avatar
kevinkins
Posts: 2465
Joined: Wed Mar 08, 2006 11:54 am

RE: Random placement possible?

Post by kevinkins »

I read in lua forums that there is an issue with the language generating random numbers and it's best to seed a few times before accepting the number, e.g.

https://stackoverflow.com/questions/201 ... ers-in-lua

https://stackoverflow.com/questions/323 ... generation

These are rather old posts. But I wanted to mention it to make sure everyone's code runs the way they want.

Kevin
“The study of history lies at the foundation of all sound military conclusions and practice.”
Alfred Thayer Mahan
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: Random placement possible?

Post by tjhkkr »

ORIGINAL: michaelm
To randomize whenever it runs.
math.randomseed(os.time() )

Thank you very much! That is EXTREMELY helpful!
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: Random placement possible?

Post by tjhkkr »

ORIGINAL: kevinkin
I read in lua forums that there is an issue with the language generating random numbers and it's best to seed a few times before accepting the number, e.g.

https://stackoverflow.com/questions/201 ... ers-in-lua
https://stackoverflow.com/questions/323 ... generation

These are rather old posts. But I wanted to mention it to make sure everyone's code runs the way they want.
Kevin

Thank you, that is VERY good to know.
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
Post Reply

Return to “Command: Modern Operations series”