KnightHawk75
Posts: 1450
Joined: 11/15/2018 Status: offline
|
quote:
gave me -300 and on screen -984 ft. yeah it always returns meters. -300 * 3.28 = -984 if you need the conversion rate. quote:
In an area with depth -30 ft. hmm, world data you get back 99% of time should match what you are mousing over in game for the same location, sure you didn't flip lat and lon by mistake?. But what if I did not want to initiate the Bio if the ocean floor is too high compared to the initiating unit? do a if (altitude - elevation) > X then ... where X is the min clearance between sub and bottom you want. (I might have that reversed, my brain isn't working right now) Consider maybe breaking it up, farming out the validation to a helper function. Just some testcode (have not tested it in game or anything, should work ok ..crossing fingers..) for thought.
--returns true if everything you want is ok, otherwise false.
function gParel.navtrain.IntroMWC.ValidateSubNavigationPoint(pt,minSeperation,dummydata)
local oceanfloor = World_GetElevation({lat=pt.latitude,lon=pt.longitude}); local test1=false; --marker flag
if oceanfloor < 1 then --at least 6ft of water
local tmp = tostring(dummydata.name); dummydata.name="dummy"; --change name
local retval,dummy = pcall(ScenEdit_AddUnit,dummydata); --create dummy unit.
dummydata.name = tmp;--flip name back.
if retval == true and dummy ~=nil then --created unit successfully
if (dummy.altitude -oceanfloor) > minSeperation then -- (-600 + -250) > 30= true there is 350 ft of water below unit.
test1=true; print('('.. tostring(dummy.altitude) ..' - '..tostring(oceanfloor)..'): '.. (dummy.altitude -oceanfloor)..' > '.. tostring(minSeperation));
else print("debug: location failed validation, there is less then " .. tostring(minSeperation) .. " meters between proposed unit and ocean floor");
print('('.. tostring(dummy.altitude) ..'-'.. tostring(dummy.oceanfloor) ..')'..' > '.. tostring(minSeperation));
end
--if somethingelse then else end; --sample second conditional
dummy:delete(); --remove dummy unit.
else print("debug: failed to create dummy unit err: ".. tosting(dummy));
end
else print("debug: ocean floor was < 1 or oceanfloor was higher then the depth of the dummy unit we were going to create.");
end
return test1;
end
function gParel.navtrain.IntroMWC.InitiateBioContact(ZZ,Dist1,BioDBID,BioDepth)
local ZZUnit = ScenEdit_GetUnit({guid=ZZ});
local Brg1 = ZZUnit.heading; -- Straight ahead
local BioHeading = ZZUnit.heading - 170
local unitaddTemplate = {side='Nature', Type='Submarine', Name='Fish', dbid=BioDBID, lat=pt.latitude,lon=pt.longitude,
Heading=BioHeading, manualSpeed=3, depth=BioDepth, moveto=false, manualAltitude=BioDepth}
local pt = World_GetPointFromBearing({LATITUDE=ZZUnit.latitude,LONGITUDE=ZZUnit.longitude,BEARING=Brg1, DISTANCE=Dist1});
if ValidateSubNavigationPoint(pt,25,unitaddTemplate) then --if that comes back true then...
ScenEdit_AddUnit(unitaddTemplate);
print('added')
else
print ('nocan')
end
end
gParel.navtrain.IntroMWC.InitiateBioContact('b6e0fcc3-77fc-496e-84c0-9d9933c66f9c',3,354,300)
< Message edited by KnightHawk75 -- 11/21/2021 9:19:21 PM >
|