rbsj
Posts: 14
Joined: 12/4/2018 From: Portugal Status: offline
|
POST EDITED: 22/07/2020 by me. ADD In ATTACHED SCENARIO WITH THE CODE. Please note that with this code you only have to run the InitLUACode one time at the start of the scenario. And that for each carrier you only have to add one different trigger. The LUA Action is the same for each Event. ORIGINAL POST: Dear Community and Dear Developers, Let me thank to all of you for this amazing community, also let me thank to the developers team who are constantly doing an amazing job. I'm not an English Native Speaker. I'm more of a lurker here. This is the first time I'm sharing some of the stuff that I do for my own. ---CONTEXT--- One of the interesting things when I started playing CMANO that I realized was that Aircraft Carriers (CV) need to manage well Aircraft Times Queues for Landing. I remember in one game after the publishing of CMANO of having launched a huge number of aircrafts from a CV in a mission to surprisingly see a great number of them lost due to lacking fuel in the queu times. Since then I'm careful when preparing Carrier operations. Having in mind how difficult is to land in a CV - being this awareness due to the Documentaries on Carriers - I was a little dissatisfied with how easy was to recover the aircraft, even during night and with bad weather. Because of that I create this small script in LUA to help with this issue and I'm glad with it. ---THE FUNCTIONS--- What this does is to check when a Aircraft is in approximation to land on a Carrier. Then it performs some calculations to check what is the Chance of a Sucessful Landing, for that and for now it counts with: 1. Pilot Proficiency 2. How much time is the Pilot Flying (I have seen in a doc that tired pilots after flying in a mission for 6 or 8 hours are more prone to error)-- So it calculates how much time the aircraft was flying and attributes a score. 3. Time of the Day (Night, Day, Dawn, Dusk) - Visibility 4. Sea State/Wind 5. State of the Sky 6. Level of Rainfall 7. Proficiency of the Crew of the Aircraft Carrier (For instance like in that episode that an E-2 failed a landing because of the poor maintenance of the arresting gears having one break, finding the report that a better crew maintenance could avoid the problem. If a landing is sucessful then the Aircraft Lands. If not there can happen two things: or the Plane crashes (small probability and the variables above play a role) or the Plane simple misses and will return to land again on the aircrat. If the aircraft simple misses the Aircraft is teleported to a small point at 52º west at +- 9nm at 1066m to repeat the landing. In this teleportation the aircraft looses a small amount of fuel corresponding to the teleportation travel with Afterburner on the carrier deck. I use the method of teleportation because I think it is the best. First I cannot change with LUA the route of an aircraft at the final stage of landing in a Aircraft Carrier, the other option was to assign the aircraft to a mission of support with reference points near the Aircraft Carrier but the problem of that solution was that the aircraft lost info of the previous mission, so the best option was to opt for a teleportation. If the plane crashes what happens is the fuel of the aircraft is place to 0 to crash. I had problems with the Function of delete Unit and I don't know why. A final report is presented. It is good to have in some cases at night and with bad weather at least an Aircraft to refuel aircrats that are missing the landings as in real life that happens. The script has some stuff in Portuguese my Native Speaker language. The final Reports are in English. There is a lot to improve, I know that and I'm trying some new stuff. Some values are hardcoded but I have a Longer Version that allows to change stuff. --------The Code/Short Version------ ---COMPILAR SCRIPT DO CV--- ---1º PASSO COLOCAÇÂO de PONTOS --- ---COMPILAÇÃO DE TABELAS--- local listaunidades = VP_GetSide({side='Blue'}).units tabelaa = {} for k, v in ipairs(listaunidades) do local unit = ScenEdit_GetUnit({guid=v.guid}) if unit.type == 'Ship' and unit.subtype == '2001' or unit.subtype == '2002' or unit.subtype == '2003' or unit.subtype == '2004' or unit.subtype == '2007' or unit.subtype == '2008' then table.insert(tabelaa, v) end end print(tabelaa) ---FIM--- ---INICACAÇAO DOS PONTOS A VOLTA DO CV---- for k, v in ipairs(tabelaa) do local b0 = v.name local b1 = "entrada" local u = ScenEdit_GetUnit({guid=v.guid}) local qtpontos = 4 local area = 360/qtpontos for i=1,qtpontos do local c = i * area local b2 = i + 0 local b3 = b1..b0..b2 ScenEdit_AddReferencePoint({side='Blue', RelativeTo=u.guid, name=b3, bearingtype=0, bearing=c ,distance=1, highlighted=true }) end end ---COLOCAÇÃO DE PONTO-- for k, v in ipairs(tabelaa) do local u = ScenEdit_GetUnit({guid=v.guid}) latitudecv = u.latitude longitudecv = u.longitude local hlatlon = 0.18505664276415 radiano = 0.92201803953 angulo = 52.8277423915014 local bearingcirculorad = math.rad(u.heading) local anguloponto = math.abs((bearingcirculorad - radiano)) local xref = 0 local yref = 0 if u.heading < angulo then xref = -1 yref = 1 elseif u.heading < (angulo + 90) then xref = 1 yref = 1 elseif u.heading < (angulo + 180) then xref = 1 yref = -1 elseif u.heading < (angulo + 270) then xref = -1 yref = -1 else end novalat = math.sin(anguloponto)*hlatlon*yref + (u.latitude) novalong = math.cos(anguloponto)*hlatlon*xref + (u.longitude) local b0 = u.name local nteletransporte = "teletransporte" local nfteletransporte = nteletransporte..b0 ScenEdit_AddReferencePoint({side="Blue", name=nfteletransporte, lat=novalat, lon=novalong, RelativeTo=u.name, bearingtype=1, highlighted =true}) end ---FIM--- -------------------------------------------------------------------------EVENTO------------------------------------------------------------------- ---ESTABELECER LIGAÇÃO DE UNIDADES--- math.randomseed(os.time()) local aterrador = ScenEdit_UnitX() local basecv = aterrador.base local distanciaaterradorbasecv = Tool_Range(basecv.guid, aterrador.guid) local aterrou = false local b0 = basecv.name local nteletransporte = "teletransporte" local nfteletransporte = nteletransporte..b0 local pontodereferencia = ScenEdit_GetReferencePoint({side="Blue", name=nfteletransporte}) print(pontodereferencia) -------VAMOS AO AVIAO------- ---- VAMOS AO PILOTO E TRIPULACAO------- local nivelpiloto = 100 local cansacopiloto = 100 local nivelpilotoqueda = 1 local nivelcv = 100 if aterrador.proficiency == 'Novice' then nivelpilotoqueda = 1.20 elseif aterrador.proficiency == 'Cadet' then nivelpilotoqueda = 1.10 elseif aterrador.proficiency == 'Regular' then nivelpilotoqueda = 1 elseif aterrador.proficiency == 'Veteran' then nivelpilotoqueda = 0.75 elseif aterrador.proficiency == 'Ace' then nivelpilotoqueda = 0.5 else end if aterrador.proficiency == 'Novice' then nivelpiloto = 60 elseif aterrador.proficiency == 'Cadet' then nivelpiloto = 65 elseif aterrador.proficiency == 'Regular' then nivelpiloto = 75 elseif aterrador.proficiency == 'Veteran' then nivelpiloto = 90 elseif aterrador.proficiency == 'Ace' then nivelpiloto = 95 else end if basecv.proficiency == 'Novice' then nivelcv = 85 elseif basecv.proficiency == 'Cadet' then nivelcv = 90 elseif basecv.proficiency == 'Regular' then nivelcv = 95 elseif basecv.proficiency == 'Veteran' then nivelcv = 98.5 elseif basecv.proficiency == 'Ace' then nivelcv = 99.5 else end ---TEMPO DE VOO--- local s = aterrador.airbornetime local nhorasvoo = 0 local nminutosvoo = 0 local nsegundosvoo = 0 local mhorasvoo = string.match(s, "%d+%shr") if mhorasvoo == nil then nhorasvoo = 0 else nhorasvoo = string.match(mhorasvoo, "%d+") end local mminutosvoo = string.match(s, "%d+%smin") if mminutosvoo == nil then nminutosvoo = 0 else nminutosvoo = string.match(mminutosvoo, "%d+") end local msegundosvoo = string.match(s, "%d+%ssec") if msegundosvoo == nil then nsegundosvoo = 0 else nsegundosvoo = string.match(msegundosvoo, "%d+") end local tempovoo = nhorasvoo*3600 + nminutosvoo*60 + nsegundosvoo if tempovoo >= 0 and tempovoo <= 10800 then cansacopiloto = 100 elseif tempovoo >= 10801 and tempovoo <= 14400 then cansacopiloto = 95 elseif tempovoo >= 14401 and tempovoo <= 21600 then cansacopiloto = 85 elseif tempovoo >= 21601 and tempovoo <= 28800 then cansacopiloto = 75 elseif tempovoo >= 28801 then cansacopiloto = 65 else end -----VAMOS À METEOROLOGIA------ local unicentral = basecv local ipma = ScenEdit_GetWeather() print(ipma) local tdia = ScenEdit_GetTimeOfDay({lat=unicentral.latitude, long=unicentral.longitude}) print(tdia) local estadoceu = 100 local estadotemp = 100 local estadochuva = 100 local estadomarvento = 100 if tdia.tod == 0 then estadoceu = 100 elseif tdia.tod == 2 then estadoceu = 65 elseif tdia.tod == 3 then estadoceu = 95 elseif tdia.tod == 4 then estadoceu = 95 else end print(estadoceu) if ipma.rainfall == 0 then local estadochuva = 100 elseif ipma.rainfall >= 1 and ipma.rainfall <= 4 then local estadochuva = 95 elseif ipma.rainfall >= 5 and ipma.rainfall <= 9 then local estadochuva = 90 elseif ipma.rainfall >= 10 and ipma.rainfall <= 19 then local estadochuva = 80 elseif ipma.rainfall >= 20 and ipma.rainfall <= 29 then local estadochuva = 65 elseif ipma.rainfall >= 30 and ipma.rainfall <= 39 then local estadochuva = 55 elseif ipma.rainfall >= 40 and ipma.rainfall <= 50 then local estadochuva = 45 else end print(estadochuva) if ipma.seastate == 0 then estadomarvento = 100 elseif ipma.seastate == 1 then estadomarvento = 95 elseif ipma.seastate == 2 then estadomarvento = 90 elseif ipma.seastate == 3 then estadomarvento = 80 elseif ipma.seastate == 4 then estadomarvento = 70 elseif ipma.seastate == 5 then estadomarvento = 60 elseif ipma.seastate == 6 then estadomarvento = 50 elseif ipma.seastate == 7 then estadomarvento = 45 elseif ipma.seastate == 8 then estadomarvento = 40 elseif ipma.seastate == 9 then estadomarvento = 35 else end print(estadomarvento) ---VAMOS A ATERRAGEM local condaterrador = false if aterrador.category == '2002' then condaterrador = true else condaterrador = false end local vaiaterrar = false if aterrador.condition == 'On final approach' or aterrador.condition == 'RTB_Manual' and condaterrador == true then vaiaterrar = true else vaiaterrar = false end print("ATERRADOR CONDITION") print(aterrador.condition) ---VAMOS VER SE TEM SUCESSO E CONSEQUENCIAS--- local probaterragem = 1 local probacidente = 1 local basedificuldade = 100 local aleaterragem = math.random(1,basedificuldade) local aleacidente = math.random(1,basedificuldade) local probaterragem = (nivelpiloto/100)*(cansacopiloto/100)*(estadoceu/100)*(estadotemp/100)*(estadochuva/100)*(estadomarvento/100)*(nivelcv/100) print("PROBABILIDADE ATERRAGEM %") print(probaterragem) local probacidente = ((1-probaterragem)*nivelpilotoqueda)*10 local probacidentefinal = 100-probacidente local stringfuel = "% de Combustivel " local fuel = aterrador.fuel local fuelrate = fuel[2001].current/fuel[2001].max * 100 local constantefuel = 0.991980049 print(stringfuel..fuelrate) if vaiaterrar == true then if probaterragem*100 >= aleaterragem then aterrou = true ScenEdit_SpecialMessage('Blue', "The " ..aterrador.name.. " Performed a Sucessful Landing on the Carrier " ..basecv.name.. "<p>Chance of Landing Sucessfuly = </p>" ..probaterragem.. "<p> Score </p>" ..aleaterragem) end if aterrou == false and probacidentefinal <= aleacidente then fuel[2001].current = 0 aterrador.fuel = fuel ScenEdit_SpecialMessage('Blue', "Tragic News. The " ..aterrador.name.. " Crashed during his attempt to Landing on the Carrier " ..basecv.name.. "<p>Chance of Landing Sucessfuly = </p>" ..probaterragem.. "<p> Score </p>" ..aleaterragem.. "<p>Chance of NOT having an accident = </p>"..probacidentefinal.."<p> Score </p>" ..aleacidente) elseif aterrou == false and probacidentefinal > aleacidente then aterrador.latitude = pontodereferencia.latitude aterrador.longitude = pontodereferencia.longitude aterrador.altitude = 1066 fuel[2001].current = fuel[2001].current - (fuel[2001].max - (fuel[2001].max*constantefuel)) aterrador.fuel = fuel ScenEdit_SpecialMessage('Blue', "The " ..aterrador.name.. " Failed Landing on the Carrier " ..basecv.name.. "<p>Chance of Landing Sucessfuly = </p>" ..probaterragem.. "<p> Score </p>" ..aleaterragem.. "<p>Chance of NOT having an accident = </p>"..probacidentefinal.."<p> Score </p>" ..aleacidente) end end print("NUMERO DOS DADOS") print(aleaterragem) print("ATERROU?") print(aterrou) print("PROBABILIDADE ACIDENTE") print(probacidentefinal) print("NUMEROS DOS DADOS ACIDENTE") print(aleacidente) ------------------------ Hope you like it. Any doubts don't hesitate to ask. Best Regards,
Attachment (1)
< Message edited by rbsj -- 7/22/2020 12:08:21 PM >
|