diff --git a/planet/Objects.ocd/HUD.ocd/ObjectInteractionMenu.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/ObjectInteractionMenu.ocd/Script.c index c76783ef8..08d418eeb 100644 --- a/planet/Objects.ocd/HUD.ocd/ObjectInteractionMenu.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/ObjectInteractionMenu.ocd/Script.c @@ -142,7 +142,10 @@ func FxIntCheckObjectsTimer(target, effect fx) // Find only vehicles and structures (plus Clonks ("livings") and helper objects). This makes sure that no C4D_Object-containers (extra slot) are shown. Find_Or(Find_Category(C4D_Vehicle), Find_Category(C4D_Structure), Find_OCF(OCF_Alive), Find_ActionTarget(target), Find_Func("IsContainerEx")), // But these objects still need to either be a container or provide an own interaction menu. - Find_Or(Find_Func("IsContainer"), Find_Func("HasInteractionMenu")), Find_Func("CheckVisibility", GetOwner())); + Find_Or(Find_Func("IsContainer"), Find_Func("HasInteractionMenu")), Find_Func("CheckVisibility", GetOwner()), + // Normally sorted by z-order. But some objects may have a lower priority. + Sort_Reverse(Sort_Func("GetInteractionPriority", target)) + ); var equal = GetLength(new_objects) == GetLength(current_objects); if (equal) diff --git a/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c index b7f99f0d0..ef69cfef5 100644 --- a/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c @@ -1362,4 +1362,22 @@ func ExecuteInteraction(proplist action_info) if(action_info.extra_data) action_info.extra_data.Object->Call(action_info.extra_data.Fn, this); } -} \ No newline at end of file +} + +// Interaction with clonks is special: +// * The clonk opening the menu should always have higher priority so the clonk is predictably selected on the left side even if standing behind e.g. a crate +// * Other clonks should be behind because interaction with them is rare but having your fellow players stand in front of a building is very common +// (Allies also tend to run in front just when you opened that menu...) +func GetInteractionPriority(object target) +{ + // Self with high priority + if (target == this) return 100; + var owner = NO_OWNER; + if (target) owner = target->GetOwner(); + // Prefer own clonks for item transfer + if (owner == GetOwner()) return -100; + // If no own clonk, prefer friendly + if (!Hostile(owner, GetOwner())) return -120; + // Hostile clonks? Lowest priority. + return -200; +}