Fix units with multiple weapons not attacking when attack-moving.#19062
Fix units with multiple weapons not attacking when attack-moving.#19062pchote wants to merge 1 commit intoOpenRA:bleedfrom
Conversation
|
If target is in range of any valid weapon, fire. |
I was going to write something along those lines. If a one-size-fits-all solution cannot be accomplished in code only, leave the choice to the modder. From a modders' perspective, I'd want support for both: |
This is exactly what I was thinking too, but i'm not sure how to best expose this to yaml. My current idea is to use the armament names listed on |
|
Or imagine a unit with long range splash damage weapon and short range direct damage. Players should IMO have to move their units into a position that's best for a given situation, instead of relying on the engine to automate this task for them. |
|
That would mean that Mammoth tanks would treat their missiles as their primary weapon, and require micro if you want them to use their main cannon. That's a deal breaker, IMO. |
Not sure if I understand. Missiles are invalid against ground vehicles so if you target a tank it would need to move into cannon range anyway. I don't know if cannons are valid against infantry, but yes, if they are and the mammoth is in missile range, you'd need to move closer. I can't really see how that's a dealbreaker tbh, especially since you don't want to move into cannon range against infantry with mammoths anyway. But I see that designers might want to have that automation in their games, so perhaps it could be another configuration setting. |
That might be good enough. Modders who need the priority to be toggleable on the fly could switch between Attack* traits with different priorities via conditions, I guess. |
cbb9ee0 to
5c7cbad
Compare
|
I don't see any complaints or further feedback, so have rebased and implemented the idea above. |
5c7cbad to
f49b2ce
Compare
|
Rebased. |
|
Got a crash on the shellmap in RA |
| // * If the actor cannot move, the ideal location check simplifies to whether *any* primary | ||
| // armament is able to fire, calculated using the union of ranges, since attacking using | ||
| // a subset of weapons is better than sitting idle. | ||
| var primaryArmaments = armaments.Where(a => a.Info.Name == attack.Info.Armaments.First()); |
There was a problem hiding this comment.
var armaments only includes weapons valid against this target.
In cases like Mammoth tanks, only secondary might be valid, resulting in primaryArmaments being null.
Maybe just change the above to FirstOrDefault and fall back to armaments if primaryArmaments is still null?
Alternatively, we could work on the assumption that primary and secondary will remain the only levels used in our official mods and many 3rd-party mods, and do something like this to try to fall back to secondary before falling back to bleed behavior:
var armamentsToDetermineRange = armaments.Where(a => a.Info.Name == attack.Info.Armaments.FirstOrDefault());
if (armamentsToDetermineRange == null)
armamentsToDetermineRange = armaments.Where(a => a.Info.Name == attack.Info.Armaments.Skip(1).FirstOrDefault());
if (armamentsToDetermineRange == null)
armamentsToDetermineRange = armaments;
|
I've lost motivation to try and get back into this. Parking on the future milestone until someone wants to take over or we encounter another bug where this would be an efficient fix. |
The underlying problem in #18935 was caused by inconsistent target validation logic in
AutoTargetversusAttackFrontal'sAttackactivity:AutoTargetconsiders a target valid if any weapon is in range, butAttackonly considers it valid if all valid weapons are in range.This PR removes the all-weapon restriction if the unit isn't able to move, where it is clearly bogus.
As the comment notes, the existing logic is also bogus for units that define non-overlapping weapon ranges. I don't know how we want to solve this (its a game design issue, not a code bug), so I have left a TODO documenting the problem for now. If there is a clear consensus on how to solve that, then I can update the PR to implement it here.