From 8b0f73bc418e340132ba99305baa5ea1605a2d11 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Fri, 4 Jan 2019 23:56:55 +0100 Subject: Execute pushes in a random order instead of in network execution order --- TemplePushing.c4s/System.c4g/Clonk.c | 25 ++++++++++++++++++------- TemplePushing.c4s/System.c4g/Helpers.c | 12 ++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) (limited to 'TemplePushing.c4s/System.c4g') diff --git a/TemplePushing.c4s/System.c4g/Clonk.c b/TemplePushing.c4s/System.c4g/Clonk.c index adc3c41..9753271 100644 --- a/TemplePushing.c4s/System.c4g/Clonk.c +++ b/TemplePushing.c4s/System.c4g/Clonk.c @@ -39,11 +39,14 @@ protected func ControlThrow(object byObj) } */ -protected func ControlSpecial() +protected func CanPush() { - [$Push$|Image=CXIV] + return GetAction() == "Walk"; +} - if (GetAction() != "Walk") return 0; +func ExecutePush() +{ + if (!CanPush()) return 0; // Use action "Throw" starting with phase 3 SetAction("Throw"); @@ -52,10 +55,10 @@ protected func ControlSpecial() // Find clonks in range var clonks = FindObjects( Find_ID(CLNK), - Find_InRect(-20 + GetDir() * 29, 0, 12, 10), - Find_OCF(OCF_Alive), - Find_Hostile(GetOwner()), - Find_Not(Find_Action("Tumble"))); + Find_InRect(-20 + GetDir() * 29, 0, 12, 10), + Find_OCF(OCF_Alive), + Find_Hostile(GetOwner()), + Find_Not(Find_Action("Tumble"))); if (GetLength(clonks) == 0) return 0; @@ -71,7 +74,15 @@ protected func ControlSpecial() Fling(target, -1 + GetDir() * 2, -1); target->SetKiller(GetOwner()); } +} + +protected func ControlSpecial() +{ + [$Push$|Image=CXIV|Condition=CanPush] + + if (!CanPush()) return 0; + PushExecuter->RequestPush(this); return 1; } diff --git a/TemplePushing.c4s/System.c4g/Helpers.c b/TemplePushing.c4s/System.c4g/Helpers.c index c89784e..0915376 100644 --- a/TemplePushing.c4s/System.c4g/Helpers.c +++ b/TemplePushing.c4s/System.c4g/Helpers.c @@ -34,3 +34,15 @@ global func Angle360(int angle) CleanAngle(angle); return angle; } + +// Fisher-Yates Shuffle +global func ShuffleArray(array& arr) +{ + for(var i = GetLength(arr); i > 0; --i) + { + var randomIndex = Random(i); + var tmp = arr[i - 1]; + arr[i - 1] = arr[randomIndex]; + arr[randomIndex] = tmp; + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf