diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2019-01-04 23:56:55 +0100 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2019-01-23 23:50:09 +0100 |
| commit | 8b0f73bc418e340132ba99305baa5ea1605a2d11 (patch) | |
| tree | a4470393c563f6f4afbed2bb4935b5cc7105676a /TemplePushing.c4s/System.c4g | |
| parent | dcae2a1b34211eea3109cb2d1fc7b60d2e811dec (diff) | |
| download | tempelschubsen-8b0f73bc418e340132ba99305baa5ea1605a2d11.tar.gz tempelschubsen-8b0f73bc418e340132ba99305baa5ea1605a2d11.zip | |
Execute pushes in a random order instead of in network execution order
Diffstat (limited to 'TemplePushing.c4s/System.c4g')
| -rw-r--r-- | TemplePushing.c4s/System.c4g/Clonk.c | 25 | ||||
| -rw-r--r-- | TemplePushing.c4s/System.c4g/Helpers.c | 12 |
2 files changed, 30 insertions, 7 deletions
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 |
