From 4a06a8ce56a4b343b15b4db9cb71a1fafe16cb1c Mon Sep 17 00:00:00 2001 From: spencer-ki Date: Sat, 14 May 2022 21:19:36 -0700 Subject: [PATCH] bypassing triggers and merging before save --- Generator/RotorOpsMission.py | 27 ++++++++++++++++++++++++++- scripts/RotorOps.lua | 12 ++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Generator/RotorOpsMission.py b/Generator/RotorOpsMission.py index 5b2f929..3e054b6 100644 --- a/Generator/RotorOpsMission.py +++ b/Generator/RotorOpsMission.py @@ -132,7 +132,22 @@ class RotorOpsMission: window.statusBar().showMessage("Loading scenario mission", 10000) - self.m.load_file(options["scenario_file"]) + # self.m.load_file(options["scenario_file"]) + + # Bypass trig, triggrules, and triggers. Then load triggers + # manually. We want to get our zones from the template mission, but leave the existing trigger actions and + # conditions the same, since pydcs cannot yet handle some of them well. + + self.m.load_file(options["scenario_file"], True) + self.m.triggers.load_from_dict(self.m.bypassed_triggers) + + # Create some 'empty' triggerrules so that we can maintain indexing when we merge dictionaries on save + for rule in self.m.bypassed_trigrules: + trig = dcs.triggers.TriggerOnce(comment="Empty " + str(rule)) + trig.rules.append(dcs.condition.TimeAfter(1)) + trig.actions.append(dcs.action.DoScript(dcs.action.String("Filler " + str(rule)))) + self.m.triggerrules.triggers.append(trig) + # Add countries if they're missing if not self.m.country(jtf_red): self.m.coalition.get("red").add_country(dcs.countries.CombinedJointTaskForcesRed()) @@ -496,6 +511,16 @@ class RotorOpsMission: output_dir = directories.output # default dir os.chdir(output_dir) output_filename = options["scenario_name"] + " " + time.strftime('%a%H%M%S') + '.miz' + + # dcs.mission.save will use the bypassed trig, trigrules, and triggers. Our goal is to leave the trigrules and + # trig from the source mission untouched. See comments in self.m.load_file above + + #merge dictionaries + self.m.bypassed_trig = self.m.triggerrules.trig() | self.m.bypassed_trig + self.m.bypassed_trigrules = self.m.triggerrules.trigrules() | self.m.bypassed_trigrules + + self.m.bypassed_triggers = self.m.triggers.dict() + success = self.m.save(output_filename) return {"success": success, "filename": output_filename, "directory": output_dir} # let the UI know the result diff --git a/scripts/RotorOps.lua b/scripts/RotorOps.lua index 642fa99..eb05725 100644 --- a/scripts/RotorOps.lua +++ b/scripts/RotorOps.lua @@ -40,7 +40,7 @@ RotorOps.pickup_zone_smoke = "blue" RotorOps.ai_task_by_name = true --allow tasking all groups that include key strings in their group names eg 'Patrol' RotorOps.ai_task_by_name_scheduler = true --continually search active groups for key strings and ai tasking RotorOps.patrol_task_string = 'patrol' --default string to search group names for the patrol task. requires ai_task_by_name -RotorOps.aggressive_task_string = 'aggressive' --default string to search group names for the patrol task. requires ai_task_by_name +RotorOps.aggressive_task_string = 'aggressive' --default string to search group names for the aggressive task. requires ai_task_by_name RotorOps.move_to_active_task_string = "activezone" --default string to search group names for the move to active zone task. requires ai_task_by_name RotorOps.shift_task_string = "shift" RotorOps.guard_task_string = "guard" @@ -897,13 +897,12 @@ function RotorOps.guardPosition(vars) start_point = first_valid_unit:getPoint() end local object_vol_thresh = 0 - local max_waypoints = 1 local foundUnits = {} local volS = { id = world.VolumeType.SPHERE, params = { - point = grp:getUnit(1):getPoint(), --check if exists, maybe itterate through grp + point = start_point, radius = search_radius } } @@ -927,9 +926,10 @@ function RotorOps.guardPosition(vars) --world.searchObjects(Object.Category.BASE, volS, ifFound) if #foundUnits > 0 then local path = {} - path[1] = mist.ground.buildWP(start_point, '', 5) + --path[1] = mist.ground.buildWP(RotorOps.getValidUnitFromGroup(grp):getPoint(), '', 2) + path[1] = mist.ground.buildWP(RotorOps.getValidUnitFromGroup(grp):getPoint(), '', 2) local rand_index = math.random(1,#foundUnits) - path[#path + 1] = mist.ground.buildWP(foundUnits[rand_index]:getPoint(), '', 3) + path[#path + 1] = mist.ground.buildWP(foundUnits[rand_index]:getPoint(), '', 2) mist.goRoute(grp, path) end end @@ -1742,7 +1742,7 @@ function RotorOps.taskByName() end end if RotorOps.ai_task_by_name_scheduler then - local timer_id = timer.scheduleFunction(RotorOps.taskByName, nil, timer.getTime() + 120) + local timer_id = timer.scheduleFunction(RotorOps.taskByName, nil, timer.getTime() + 500) end end