@@ -287,9 +287,24 @@ struct OverrideHasHeightAdvantageStruct
287
287
var protectedwrite array <OverrideHasHeightAdvantageStruct > OverrideHasHeightAdvantageCallbacks ;
288
288
// End Issue #851
289
289
290
+ // Start Issue #1138
291
+ struct PrioritizeRightClickMeleeStruct
292
+ {
293
+ var delegate <PrioritizeRightClickMeleeDelegate > PrioritizeRightClickMeleeFn ;
294
+ var int Priority ;
295
+
296
+ structdefaultproperties
297
+ {
298
+ Priority = 50
299
+ }
300
+ };
301
+ var protectedwrite array <PrioritizeRightClickMeleeStruct > PrioritizeRightClickMeleeCallbacks ;
302
+ // End Issue #1138
303
+
290
304
delegate EHLDelegateReturn ShouldDisplayMultiSlotItemInStrategyDelegate (XComGameState_Unit UnitState , XComGameState_Item ItemState , out int bDisplayItem , XComUnitPawn UnitPawn , optional XComGameState CheckGameState ); // Issue #885
291
305
delegate EHLDelegateReturn ShouldDisplayMultiSlotItemInTacticalDelegate (XComGameState_Unit UnitState , XComGameState_Item ItemState , out int bDisplayItem , XGUnit UnitVisualizer , optional XComGameState CheckGameState ); // Issue #885
292
306
delegate EHLDelegateReturn OverrideHasHeightAdvantageDelegate (XComGameState_Unit Attacker , XComGameState_Unit TargetUnit , out int bHasHeightAdvantage ); // Issue #851
307
+ delegate EHLDelegateReturn PrioritizeRightClickMeleeDelegate (XComGameState_Unit UnitState , XComGameState_BaseObject TargetObject , out XComGameState_Ability PrioritizedMeleeAbility ); // Issue #1138
293
308
294
309
// Start Issue #123
295
310
simulated static function RebuildPerkContentCache () {
@@ -949,6 +964,95 @@ simulated function TriggerOverrideHasHeightAdvantage(XComGameState_Unit Attacker
949
964
}
950
965
// End Issue #851
951
966
967
+ // Start Issue #1138
968
+ /// HL-Docs: ref:PrioritizeRightClickMelee
969
+ /// # Delegate Priority
970
+ /// You can optionally specify callback Priority.
971
+ ///```unrealscript
972
+ ///CHHelpersObj.AddPrioritizeRightClickMeleeCallback(PrioritizeRightClickMelee, 45);
973
+ ///```
974
+ /// Delegates with higher Priority value are executed first.
975
+ /// Delegates with the same Priority are executed in the order they were added to CHHelpers,
976
+ /// which would normally be the same as [DLCRunOrder](../misc/DLCRunOrder.md).
977
+ /// This function will return `true` if the delegate was successfully registered.
978
+ simulated function bool AddPrioritizeRightClickMeleeCallback (delegate <PrioritizeRightClickMeleeDelegate > PrioritizeRightClickMeleeFn , optional int Priority = 50 )
979
+ {
980
+ local PrioritizeRightClickMeleeStruct NewPrioritizeRightClickMeleeCallback ;
981
+ local int i , PriorityIndex ;
982
+ local bool bPriorityIndexFound ;
983
+
984
+ if (PrioritizeRightClickMeleeFn == none )
985
+ {
986
+ return false ;
987
+ }
988
+ // Cycle through the array of callbacks backwards
989
+ for (i = PrioritizeRightClickMeleeCallbacks .Length - 1 ; i >= 0 ; i --)
990
+ {
991
+ // Do not allow registering the same delegate more than once.
992
+ if (PrioritizeRightClickMeleeCallbacks [i ].PrioritizeRightClickMeleeFn == PrioritizeRightClickMeleeFn )
993
+ {
994
+ return false ;
995
+ }
996
+
997
+ // Record the array index of the callback whose priority is higher or equal to the priority of the new callback,
998
+ // so that the new callback can be inserted right after it.
999
+ if (PrioritizeRightClickMeleeCallbacks [i ].Priority >= Priority && !bPriorityIndexFound )
1000
+ {
1001
+ PriorityIndex = i + 1 ; // +1 so that InsertItem puts the new callback *after* this one.
1002
+
1003
+ // Keep cycling through the array so that the previous check for duplicate delegates can run for every currently registered delegate.
1004
+ bPriorityIndexFound = true ;
1005
+ }
1006
+ }
1007
+
1008
+ NewPrioritizeRightClickMeleeCallback .Priority = Priority ;
1009
+ NewPrioritizeRightClickMeleeCallback .PrioritizeRightClickMeleeFn = PrioritizeRightClickMeleeFn ;
1010
+ PrioritizeRightClickMeleeCallbacks .InsertItem (PriorityIndex , NewPrioritizeRightClickMeleeCallback );
1011
+
1012
+ return true ;
1013
+ }
1014
+
1015
+ /// HL-Docs: ref:PrioritizeRightClickMelee
1016
+ /// # Removing Delegates
1017
+ /// If necessary, it's possible to remove a delegate.
1018
+ ///```unrealscript
1019
+ ///CHHelpersObj.RemovePrioritizeRightClickMeleeCallback(PrioritizeRightClickMelee);
1020
+ ///```
1021
+ /// The function will return `true` if the Callback was successfully deleted, return false otherwise.
1022
+ simulated function bool RemovePrioritizeRightClickMeleeCallback (delegate <PrioritizeRightClickMeleeDelegate > PrioritizeRightClickMeleeFn )
1023
+ {
1024
+ local int i ;
1025
+
1026
+ for (i = PrioritizeRightClickMeleeCallbacks .Length - 1 ; i >= 0 ; i --)
1027
+ {
1028
+ if (PrioritizeRightClickMeleeCallbacks [i ].PrioritizeRightClickMeleeFn == PrioritizeRightClickMeleeFn )
1029
+ {
1030
+ PrioritizeRightClickMeleeCallbacks .Remove (i , 1 );
1031
+ return true ;
1032
+ }
1033
+ }
1034
+ return false ;
1035
+ }
1036
+
1037
+ // Called by X2AbilityTrigger_EndOfMove::GetAvailableEndOfMoveAbilityForUnit()
1038
+ // This is an internal CHL API. It is not intended for use by mods and is not covered by Backwards Compatibility policy.
1039
+ simulated function TriggerPrioritizeRightClickMelee (XComGameState_Unit UnitState , XComGameState_BaseObject TargetObject , out XComGameState_Ability PrioritizedMeleeAbility )
1040
+ {
1041
+ local delegate <PrioritizeRightClickMeleeDelegate > PrioritizeRightClickMeleeFn ;
1042
+ local int i ;
1043
+
1044
+ for (i = 0 ; i < PrioritizeRightClickMeleeCallbacks .Length ; i ++)
1045
+ {
1046
+ PrioritizeRightClickMeleeFn = PrioritizeRightClickMeleeCallbacks [i ].PrioritizeRightClickMeleeFn ;
1047
+
1048
+ if (PrioritizeRightClickMeleeFn (UnitState , TargetObject , PrioritizedMeleeAbility ) == EHLDR_InterruptDelegates )
1049
+ {
1050
+ break ;
1051
+ }
1052
+ }
1053
+ }
1054
+ // End Issue #1138
1055
+
952
1056
// Start Issue #855
953
1057
static function name GetPlaceEvacZoneAbilityName ()
954
1058
{
0 commit comments