Whicker
Posts: 664
Joined: 6/20/2018 Status: offline
|
updated code for random bios. - random speed between 0 and 4 - random depth (max 270m or so) I still don't like the way lat and lng are set, kind of a pain. Also it needs a large area - more than one lat/lng integer(?). That can be fixed by changing the random chunk added to it, would be nice if the area could be set with ref points and then add a better way to randomize it. Good enough for now though. I also set the area in the script to larger than what the mission zone is, makes them converge on it for the ones that spawn outside of it. If you watch the fish depth at high compression it varies -seems to always come up to -131 for a bit and go back down to what it is set to by the script - that actually seems good, I wonder if that is on purpose? they don't seem to do this if I create one manually but I just did it once to see. quote:
math.randomseed(os.time()) bio_num = math.random(35,55) --change to your specified minimum and maximum number of bios for i = 1,bio_num do redo_count = 0 ::redo:: local lat_var = math.random(1,(10^13)) --don't change local lon_var = math.random(1,(10^13)) --don't change v_lat = math.random(14,26) + (lat_var/(10^13)) --change the first set (south is negative) to your specified minimum and maximum latitude values; it's important that the first number is smaller than the second. v_lon = math.random(-78,-60) + (lon_var/(10^13)) --change first set (west is negative!) to your specified minimum and maximum longitude values; it's important that the first number is smaller than the second. elevation = World_GetElevation({latitude=v_lat, longitude=v_lon}) if elevation > -40 then --(meters?) Checks to see if the water is deep enough, adjust as you please redo_count = redo_count + 1 print("picked bad co-ordinates") if redo_count >50 then print ('units were not able to find a suitable spot for placement. Re-check latitude and longitude settings') break --this cuts the loop if there are no suitable positions found after 50 tries, prevents infinite loop/game freeze else goto redo --retries the placement if the water is too shallow end end DBIDTABLE = { 92,355,354 } --list of dbids for bios, could be subs local actual_depth = elevation --need 2 variables for depth - actual depth at that location and the depth the unit is set to, though this is only for the print to log if elevation < -300 then elevation = -299 end -- max depth for bios is 300, if actual depth is more than 300m set to 299 so random depth is achievable local bio_depth = -1*elevation*math.random(100, 900)/1000 --have to reverse the sign, depth is a positive number, multiply by random percent between 10 and 90% DBID = DBIDTABLE[math.random( 1, #DBIDTABLE)] --choose random dbid for unit local new_bio = ScenEdit_AddUnit({side='Biologics', type='Submarine',name='Biologic #'..i, dbid=DBID,latitude=v_lat,longitude=v_lon, depth='bio_depth', manualSpeed=math.random(0, 4)}) ScenEdit_AssignUnitToMission( new_bio.name, 'Whales') --add to mission which helps with the course print (new_bio.name..' with dbid '..DBID..' was created in water with a depth of '..actual_depth..'m, at a depth of ' ..bio_depth ) end
< Message edited by Whicker -- 7/8/2018 5:42:05 AM >
|