forked from Mirrors/openclonk
move flag coordinate in area check into flag's script
This allows also for using rectangular ownership shapes, which can be useful for blocking areas.shapetextures
parent
c925351b15
commit
2dde6fd600
|
@ -95,7 +95,7 @@ private func FxIntAreaMonteCarloTimer(object target, proplist effect, int time)
|
|||
{
|
||||
var x = Random(LandscapeWidth());
|
||||
var y = Random(LandscapeHeight());
|
||||
if (CoveredByFlag(x, y))
|
||||
if (GetFlagpoleForPosition(x, y))
|
||||
rate++;
|
||||
}
|
||||
var promille = 1000 * rate / cnt;
|
||||
|
@ -107,15 +107,6 @@ private func FxIntAreaMonteCarloTimer(object target, proplist effect, int time)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// Returns whether the point (x,y) is covered by a flagpole.
|
||||
private func CoveredByFlag(int x, int y)
|
||||
{
|
||||
for (var flag in FindObjects(Find_Func("IsFlagpole"), Sort_Distance(x - GetX(), y - GetY())))
|
||||
if (Distance(flag->GetX(), flag->GetY(), x, y) < flag->GetFlagRadius())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return the description of this goal.
|
||||
public func GetDescription(int plr)
|
||||
{
|
||||
|
|
|
@ -18,8 +18,7 @@ global func GetFlagpoleForPosition(int x, int y)
|
|||
// Safety in case this gets called during destruction of a flag.
|
||||
if (!flag)
|
||||
continue;
|
||||
var d = Distance(GetX() + x, GetY() + y, flag->GetX(), flag->GetY());
|
||||
if (d > flag->GetFlagRadius())
|
||||
if (!flag->HasCoordinatesInControlArea(x + GetX(), y + GetY()))
|
||||
continue;
|
||||
|
||||
if (oldest == nil || flag->GetFlagConstructionTime() < oldest_time)
|
||||
|
|
|
@ -111,7 +111,7 @@ public func RedrawFlagRadius()
|
|||
{
|
||||
if (other_flag)
|
||||
{
|
||||
if (Distance(GetX() + x, GetY() + y, other_flag->GetX(), other_flag->GetY()) <= other_flag->GetFlagRadius())
|
||||
if (other_flag->HasCoordinatesInControlArea(GetX() + x, GetY() + y))
|
||||
{
|
||||
// For equal construction times, increase this construction time.
|
||||
// TODO: this feels rather hacky?!
|
||||
|
@ -165,6 +165,14 @@ public func RedrawFlagRadius()
|
|||
return;
|
||||
}
|
||||
|
||||
// Callback from the global function that determines the ownership for a position.
|
||||
// The coordinates x and y are global.
|
||||
public func HasCoordinatesInControlArea(int x, int y)
|
||||
{
|
||||
var d = Distance(x, y, GetX(), GetY());
|
||||
return d <= GetFlagRadius();
|
||||
}
|
||||
|
||||
// Removes all the ownership markers for this flag.
|
||||
private func ClearFlagMarkers()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue