Skip to content

Commit

Permalink
Fix: AI now target all static buildings
Browse files Browse the repository at this point in the history
  • Loading branch information
john681611 committed Jan 27, 2025
1 parent 8f581a0 commit 192bfa5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 37 deletions.
71 changes: 37 additions & 34 deletions src/BriefingRoom/Generator/FlightPathWaypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ You should have received a copy of the GNU General Public License
using System.Collections.Generic;
using BriefingRoom4DCS.Mission.DCSLuaObjects;
using BriefingRoom4DCS.Data;
using System.Linq;

namespace BriefingRoom4DCS.Generator
{
Expand All @@ -36,57 +37,59 @@ public readonly struct Waypoint
internal bool ScriptIgnore { get; }
internal bool AircraftIgnore { get; }

internal int TargetGroupID { get; }
internal bool HiddenMapMarker {get; }
internal List<int> TargetGroupIDs { get; }
internal bool HiddenMapMarker { get; }

internal Waypoint(string name, Coordinates coordinates, bool onGround = false, int targetGroupID = 0, bool scriptIgnore = false, bool aircraftIgnore = false, bool hiddenMapMarker = false)
internal Waypoint(string name, Coordinates coordinates, bool onGround = false, List<int> targetGroupIDs = null, bool scriptIgnore = false, bool aircraftIgnore = false, bool hiddenMapMarker = false)
{
Name = name;
Coordinates = coordinates;
OnGround = onGround;
ScriptIgnore = scriptIgnore;
TargetGroupID = targetGroupID;
TargetGroupIDs = targetGroupIDs;
AircraftIgnore = aircraftIgnore;
HiddenMapMarker = hiddenMapMarker;
}

internal DCSWaypoint ToDCSWaypoint(Data.DBEntryAircraft aircraftData, DCSTask task)
{
var tasks = new List<DCSWaypointTask>();
if (TargetGroupID > 0)
if (TargetGroupIDs != null && TargetGroupIDs.Count > 0)
{
if (ATTACK_GROUP_TASKS.Contains(task))
tasks.Add(new DCSWaypointTask
{
Enabled = true,
Auto = false,
Id = "AttackGroup",
Parameters = new Dictionary<string, object>{
{"altitudeEnabled", false},
{"groupId", TargetGroupID},
{"attackQtyLimit", false},
{"attackQty", 1},
{"expend", "Auto"},
{"altitude", 2000},
{"directionEnabled", false},
{"groupAttack", false},
{"weaponType", 9663676414},
{"direction", 0},
}
});
foreach (var TargetGroupID in TargetGroupIDs)
tasks.Add(new DCSWaypointTask
{
Enabled = true,
Auto = false,
Id = "AttackGroup",
Parameters = new Dictionary<string, object>{
{"altitudeEnabled", false},
{"groupId", TargetGroupID},
{"attackQtyLimit", false},
{"attackQty", 1},
{"expend", "Auto"},
{"altitude", 2000},
{"directionEnabled", false},
{"groupAttack", false},
{"weaponType", 9663676414},
{"direction", 0},
}
});
else if (task == DCSTask.CAP)
tasks.Add(new DCSWaypointTask
{
Enabled = true,
Auto = false,
Id = "EngageGroup",
Parameters = new Dictionary<string, object>{
{"visible", false},
{"groupId", TargetGroupID},
{"priority", 1},
{"weaponType", 9659482112},
foreach (var TargetGroupID in TargetGroupIDs)
tasks.Add(new DCSWaypointTask
{
Enabled = true,
Auto = false,
Id = "EngageGroup",
Parameters = new Dictionary<string, object>{
{"visible", false},
{"groupId", TargetGroupID},
{"priority", 1},
{"weaponType", 9659482112},
}
}
}
);
}
return new DCSWaypoint
Expand Down
6 changes: 3 additions & 3 deletions src/BriefingRoom/Generator/MissionGeneratorObjectives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private static List<Waypoint> CreateObjective(
mission.ObjectiveCoordinates.Add(isInverseTransportWayPoint ? unitCoordinates : objectiveCoordinates);
var objCoords = objectiveCoordinates;
var furthestWaypoint = targetGroupInfo.Value.DCSGroup.Waypoints.Aggregate(objectiveCoordinates, (furthest, x) => objCoords.GetDistanceFrom(x.Coordinates) > objCoords.GetDistanceFrom(furthest) ? x.Coordinates : furthest);
var waypoint = GenerateObjectiveWaypoint(ref mission, task, objectiveCoordinates, furthestWaypoint, objectiveName, targetGroupInfo.Value.GroupID, hiddenMapMarker: task.ProgressionOptions.Contains(ObjectiveProgressionOption.ProgressionHiddenBrief));
var waypoint = GenerateObjectiveWaypoint(ref mission, task, objectiveCoordinates, furthestWaypoint, objectiveName, targetGroupInfo.Value.DCSGroups.Select(x => x.GroupId).ToList(), hiddenMapMarker: task.ProgressionOptions.Contains(ObjectiveProgressionOption.ProgressionHiddenBrief));
mission.Waypoints.Add(waypoint);
objectiveWaypoints.Add(waypoint);
mission.MapData.Add($"OBJECTIVE_AREA_{objectiveIndex}", new List<double[]> { waypoint.Coordinates.ToArray() });
Expand Down Expand Up @@ -642,7 +642,7 @@ private static void CreateTaskString(ref DCSMission mission, int pluralIndex, re
mission.Briefing.AddItem(DCSMissionBriefingItemType.Task, taskString);
}

private static Waypoint GenerateObjectiveWaypoint(ref DCSMission mission, MissionTemplateSubTaskRecord objectiveTemplate, Coordinates objectiveCoordinates, Coordinates ObjectiveDestinationCoordinates, string objectiveName, int groupId = 0, bool scriptIgnore = false, bool hiddenMapMarker = false)
private static Waypoint GenerateObjectiveWaypoint(ref DCSMission mission, MissionTemplateSubTaskRecord objectiveTemplate, Coordinates objectiveCoordinates, Coordinates ObjectiveDestinationCoordinates, string objectiveName, List<int> groupIds = null, bool scriptIgnore = false, bool hiddenMapMarker = false)
{
var (targetDB, targetBehaviorDB, taskDB, objectiveOptions, presetDB) = GetCustomObjectiveData(mission.LangKey, objectiveTemplate);
var targetBehaviorLocation = targetBehaviorDB.Location;
Expand All @@ -661,7 +661,7 @@ private static Waypoint GenerateObjectiveWaypoint(ref DCSMission mission, Missio
DrawingMaker.AddDrawing(ref mission, $"Target Zone {objectiveName}", DrawingType.Circle, waypointCoordinates, "Radius".ToKeyValuePair(Database.Instance.Common.DropOffDistanceMeters));
else if (targetBehaviorLocation == DBEntryObjectiveTargetBehaviorLocation.Patrolling)
DrawingMaker.AddDrawing(ref mission, $"Target Zone {objectiveName}", DrawingType.Circle, waypointCoordinates, "Radius".ToKeyValuePair(ObjectiveDestinationCoordinates.GetDistanceFrom(objectiveCoordinates)));
return new Waypoint(objectiveName, waypointCoordinates, onGround, groupId, scriptIgnore, objectiveTemplate.Options.Contains(ObjectiveOption.NoAircraftWaypoint), hiddenMapMarker);
return new Waypoint(objectiveName, waypointCoordinates, onGround, groupIds, scriptIgnore, objectiveTemplate.Options.Contains(ObjectiveOption.NoAircraftWaypoint), hiddenMapMarker);
}

//----------------SUB TASK SUPPORT FUNCTIONS-------------------------------
Expand Down

0 comments on commit 192bfa5

Please sign in to comment.