fix flag marker redrawing on owner change

issue1247
Maikel de Vries 2015-02-16 17:15:29 +01:00
parent eed1c43b8a
commit d2988163f5
5 changed files with 22 additions and 20 deletions

View File

@ -85,9 +85,6 @@ protected func InitializePlayer(int plr)
// Claim ownership of unowned structures
for (var structure in FindObjects(Find_Or(Find_Category(C4D_Structure), Find_Func("IsFlagpole")), Find_Owner(NO_OWNER)))
structure->SetOwner(plr);
// Should be done in OnOwnerChanged? It doesn't happen ATM.
RedrawAllFlagRadiuses();
return;
}

View File

@ -85,9 +85,6 @@ protected func InitializePlayer(int plr)
// Claim ownership of unowned structures
for (var structure in FindObjects(Find_Or(Find_Category(C4D_Structure), Find_Func("IsFlagpole")), Find_Owner(NO_OWNER)))
structure->SetOwner(plr);
// Should be done in OnOwnerChanged? It doesn't happen ATM.
RedrawAllFlagRadiuses();
return;
}

View File

@ -2,4 +2,4 @@
#appendto Library_Flag
func RedrawAllFlagRadiuses() {}
local DefaultFlagRadius = 0;

View File

@ -25,7 +25,7 @@
static LIB_FLAG_FlagList;
// Radius of new flag of this type, unless overwritten by SetFlagRadius().
local DefaultFlagRadius = 200;
local DefaultFlagRadius = 200;
// All flag related local variables are stored in a single proplist.
// This reduces the chances of clashing local variables. See
@ -76,6 +76,8 @@ public func IsFlagpole() { return true; }
// Redraws the ownership markers of this flag according to the current circumstances.
public func RedrawFlagRadius()
{
// Debugging logs.
//Log("FLAG - RedrawFlagRadius(): flag = %v", this);
// A flag with no radius is not drawn.
if (!lib_flag.radius)
{
@ -163,6 +165,16 @@ public func RedrawFlagRadius()
return;
}
// Removes all the ownership markers for this flag.
private func ClearFlagMarkers()
{
for (var marker in lib_flag.range_markers)
if (marker)
marker->RemoveObject();
lib_flag.range_markers = [];
return;
}
// Changes the ownership of the structures within this flag's radius.
private func RefreshOwnershipOfSurrounding()
{
@ -363,13 +375,6 @@ public func CopyLinkedFlags(object from, array flaglist)
return;
}
private func ClearFlagMarkers()
{
for(var obj in lib_flag.range_markers)
if (obj) obj->RemoveObject();
lib_flag.range_markers = [];
}
// Engine callback: owner of the flag has changed.
protected func OnOwnerChanged(int new_owner, int old_owner)
{
@ -383,8 +388,12 @@ protected func OnOwnerChanged(int new_owner, int old_owner)
marker->SetOwner(new_owner);
marker->ResetColor();
}
// Redraw radiuses of all flags.
RedrawAllFlagRadiuses();
// Also change the ownership of the surrounding buildings.
RefreshOwnershipOfSurrounding();
// Linked flags - refresh links for this flag.
RefreshLinkedFlags();
return _inherited(new_owner, old_owner, ...);
}
@ -394,7 +403,7 @@ protected func OnHostilityChange(int player1, int player2, bool hostile, bool ol
// Debugging logs.
//Log("FLAG - OnHostilityChange(): flag = %v, player1 = %d, player2 = %d, hostile = %v, old_hostility = %v", this, player1, player2, hostile, old_hostility);
// Redraw radiuses of all flags.
RedrawFlagRadius();
RedrawAllFlagRadiuses();
// Refresh the ownership of the flag's surroundings.
RefreshOwnershipOfSurrounding();
// Linked flags - refresh links for this flag.
@ -408,7 +417,7 @@ protected func OnTeamSwitch(int player, int new_team, int old_team)
// Debugging logs.
//Log("FLAG - OnTeamSwitch(): flag = %v, player = %d, new_team = %d, old_team = %d", this, player, new_team, old_team);
// Redraw radiuses of all flags.
RedrawFlagRadius();
RedrawAllFlagRadiuses();
// Refresh the ownership of the flag's surroundings.
RefreshOwnershipOfSurrounding();
// Linked flags - refresh links for this flag.
@ -534,7 +543,7 @@ private func LogFlags()
{
for (var flag in LIB_FLAG_FlagList)
{
Log("FLAG - Flag (%v): owner = %d, con_time = %d, radius = %d, power_network = %v", flag, flag->GetOwner(), flag->GetFlagConstructionTime(), flag->GetFlagRadius(), flag->GetPowerHelper());
Log("FLAG - State for flag (%v): owner = %d, con_time = %d, radius = %d, power_network = %v", flag, flag->GetOwner(), flag->GetFlagConstructionTime(), flag->GetFlagRadius(), flag->GetPowerHelper());
Log("\tlinked flags = %v", flag->GetLinkedFlags());
}
return;

View File

@ -33,8 +33,7 @@
OPEN TODOS:
* Remove all the if (!link) checks, they are not needed in principle but errors arise when they are removed.
* Fix overproduction if a request is not met, e.g. compensator trying to supply a workshop alone.
* Flag library documentation.
* Flag markers sometimes not updated (e.g. Gem Grabbers).
* Think about the necessity of global func RedrawAllFlagRadiuses().
* Move network merging from flag to power library.
@author Zapper, Maikel