Skip to content

Commit d58b28e

Browse files
author
Motive
committed
- Fixed a bug where texttags created by @Label could be orphaned due to a Blizzard bug which won't be fixed anytime soon.
1 parent d07b9d4 commit d58b28e

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

Commands/UnitCommands.galaxy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,8 @@ bool libcrtx_command_label(bool testConds, bool runActions)
22012201
TextTagAttachToUnit(tagId, UnitGroupLoopCurrent(), 1.0);
22022202

22032203
UnitSetCustomValue(UnitGroupLoopCurrent(), libcrtx_unit_custom_value_texttag, IntToFixed(tagId));
2204+
2205+
libcrtx_labelmgr_addlabel(tagId, UnitGroupLoopCurrent());
22042206
}
22052207
UnitGroupLoopStep();
22062208
}

Common/Global.galaxy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ string libcrtx_getspawnertype()
7373
include "Cortex/Common/Debug.galaxy"
7474
include "Cortex/Common/Settings.galaxy"
7575
include "Cortex/Common/Variables.galaxy"
76+
include "Cortex/Common/LabelManager.galaxy"
7677
include "Cortex/Common/Admin.galaxy"
7778
include "Cortex/Common/SharedData.galaxy"
7879
include "Cortex/Common/CortexID.galaxy"

Common/LabelManager.galaxy

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Cortex SC2 Roleplaying Engine
2+
// Copyright (C) 2009-2011 <http://www.cortexrp.com/>
3+
//
4+
// This program is free software; you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation; version 2 of the License.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
13+
// This entire file's purpose would be useless if Blizzard
14+
// left us a viable way to detect when a unit died in a transport
15+
// ><
16+
// Bug report filed and ignored: http://us.battle.net/sc2/en/forum/topic/3811454102
17+
18+
string libcrtx_labelmgr_prefix = "labelmgr_id_";
19+
int libcrtx_labelmgr_highId = -1;
20+
21+
// Adds entry in dataTable for labelId -> unitHandle
22+
void libcrtx_labelmgr_addlabel(int labelId, unit unitHandle)
23+
{
24+
if( labelId > libcrtx_labelmgr_highId ) {
25+
libcrtx_labelmgr_highId = labelId;
26+
}
27+
28+
DataTableSetUnit(true, libcrtx_labelmgr_prefix + IntToString(labelId), unitHandle);
29+
}
30+
31+
// Removes labels not tied to active units.
32+
void libcrtx_labelmgr_update()
33+
{
34+
int i = -1;
35+
unit linkedUnit;
36+
37+
while( i <= libcrtx_labelmgr_highId )
38+
{
39+
linkedUnit = DataTableGetUnit(true, libcrtx_labelmgr_prefix + IntToString(i));
40+
if( linkedUnit == null || !UnitIsAlive(linkedUnit) ) {
41+
DataTableValueRemove(true, libcrtx_labelmgr_prefix + IntToString(i));
42+
if( TextTagVisible(i, 1) ) {
43+
TextTagDestroy(i);
44+
}
45+
}
46+
i += 1;
47+
}
48+
}

Common/Log.galaxy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void libcrtx_log_event_global(int player, string message)
6060
while(currentLevel < c_cortexMaxLoggedCommands)
6161
{
6262
libcrtx_log_globallog[currentLevel - 1] = libcrtx_log_globallog[currentLevel];
63-
libcrtx_log_globallogplayers[c_currentLevel - 1] = libcrtx_log_globallogplayers[currentLevel];
63+
libcrtx_log_globallogplayers[currentLevel - 1] = libcrtx_log_globallogplayers[currentLevel];
6464
currentLevel += 1;
6565
}
6666
libcrtx_log_globallog[c_cortexMaxLoggedCommands - 1] = message;

Events/Events.galaxy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ bool libcrtx_event_periodic_tick(bool checkConds, bool runActions)
131131
i = i + 1;
132132
}
133133
libcrtx_ai_update();
134+
libcrtx_labelmgr_update();
134135
return true;
135136
}
136137

0 commit comments

Comments
 (0)