summaryrefslogtreecommitdiffstats
path: root/TemplePushing.c4s
diff options
context:
space:
mode:
authorJan <>2015-10-29 23:02:26 +0100
committerJan <>2015-10-29 23:02:26 +0100
commitc9679a587e19b10c8ed7903c854a3b71af1b6a47 (patch)
tree2eee9c9b95c9c3d04ba0b283b725ce1008f0bf71 /TemplePushing.c4s
parent23dd9f7bb0920cf0b553a9bb10775beecef5c6d7 (diff)
downloadtempelschubsen-c9679a587e19b10c8ed7903c854a3b71af1b6a47.tar.gz
tempelschubsen-c9679a587e19b10c8ed7903c854a3b71af1b6a47.zip
Choose best launch position based on y-coordinate and enemy distance
Diffstat (limited to 'TemplePushing.c4s')
-rw-r--r--TemplePushing.c4s/Script.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/TemplePushing.c4s/Script.c b/TemplePushing.c4s/Script.c
index 197757c..f37c183 100644
--- a/TemplePushing.c4s/Script.c
+++ b/TemplePushing.c4s/Script.c
@@ -560,28 +560,29 @@ func LaunchClonk(int player, object clonk, bool relaunch)
// Move clonk to random position
- var NumCheckPos = 25;
- var positions = CreateArray(NumCheckPos);
+ var maxDistance = Distance(0, 0, LandscapeWidth(), LandscapeHeight());
+ var bestPosition = [LandscapeWidth() / 2, LandscapeHeight() / 2], bestQuality = 0;
- for (var i = 0; i < NumCheckPos; ++i)
+ // Generate 25 random positions and choose best
+ for (var i = 0; i < 25; ++i)
{
+ // Place wipf, save its position and remove it
var wipf = PlaceAnimal(WIPF);
- positions[i] = IIf(wipf, [wipf->GetX(), wipf->GetY()], [LandscapeWidth() / 2, LandscapeHeight() / 2]);
+ if (!wipf) continue;
+ var pos = IIf(wipf, [wipf->GetX(), wipf->GetY()], bestPosition);
if (wipf) wipf->RemoveObject();
- }
- // Prevent spawning too close to an enemy
+ // Get distance to closest enemy
+ var closestEnemy = FindObject2(Find_OCF(OCF_CrewMember | OCF_Alive), Find_Hostile(player), Sort_Distance(pos[0], pos[1]));
+ var enemyDistance;
+ if (closestEnemy) enemyDistance = Distance(pos[0], pos[1], closestEnemy->GetX(), closestEnemy->GetY());
- var bestPosition = positions[0], bestDistance = 0;
- for (var pos in positions)
- {
- var closestHostileClonk = FindObject2(Find_OCF(OCF_CrewMember | OCF_Alive), Find_Hostile(player), Sort_Distance(pos[0], pos[1]));
- if (!closestHostileClonk) break;
- var distance = Distance(pos[0], pos[1], closestHostileClonk->GetX(), closestHostileClonk->GetY());
- if (distance > bestDistance)
+ // Calculate quality of position from its y-value and its distance to the closest enemy and use position if it is the best
+ var quality = (LandscapeHeight() - pos[1]) * 1000 / LandscapeHeight() + enemyDistance * 1000 / maxDistance;
+ if (quality > bestQuality)
{
bestPosition = pos;
- bestDistance = distance;
+ bestQuality = quality;
}
}