Skip to content

Commit

Permalink
Added clearunits command
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiephan committed Dec 30, 2020
1 parent 4d2bd1b commit 8346f6e
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 1 deletion.
98 changes: 98 additions & 0 deletions (10)trymemode.stormmap/base.stormdata/Modules/LibUnits.galaxy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ include "TriggerLibs/NativeLib"
//--------------------------------------------------------------------------------------------------
// Validating: templates

// Constants
const int libUNIT_gv_summonedUnits_MaxPlayer = 16;
const int libUNIT_gv_summonedUnits_MaxLength = 927;

// Structures
struct libUNIT_gs_AddBehaviorPanel {
int lv_mainDialog;
Expand Down Expand Up @@ -36,6 +40,9 @@ bool libUNIT_gv_addBehaviorPanel_IsShowingDialog;
bool libUNIT_gv_toggleOutputIDEnabled;
libUNIT_gs_SummonUnitPanel libUNIT_gv_summonUnitPanel;
bool libUNIT_gv_summonUnitPanel_IsShowingDialog;
unit[libUNIT_gv_summonedUnits_MaxPlayer + 1][libUNIT_gv_summonedUnits_MaxLength + 1] libUNIT_gv_summonedUnits_database;
int[libUNIT_gv_summonedUnits_MaxPlayer + 1] libUNIT_gv_summonedUnits_index;
bool[libUNIT_gv_summonedUnits_MaxPlayer + 1] libUNIT_gv_summonedUnits_resetted;

// Trigger Declarations
trigger libUNIT_gt_MapInit;
Expand Down Expand Up @@ -78,6 +85,7 @@ trigger libUNIT_gt_SummonUnitPanelamountInputBoxUnfocus;
trigger libUNIT_gt_SummonUnitPanelSummonButtonClicked;
trigger libUNIT_gt_SummonUnitPanelCloseButtonClicked;
trigger libUNIT_gt_SummonUnit;
trigger libUNIT_gt_ClearSummonedUnits;

// Library Initialization
void libUNIT_InitVariables ();
Expand Down Expand Up @@ -1740,6 +1748,16 @@ bool libUNIT_gt_SummonUnitPanelSummonButtonClicked_Func (bool testConds, bool ru
libNtve_gf_CreateUnitsWithDefaultFacing(1, lv_unittype, 0, lv_player, CameraGetTarget(EventPlayer()), null);
AIAddPlayerUnit(UnitLastCreated());
UnitSetScale(UnitLastCreated(), (lv_scale * 100.0), (lv_scale * 100.0), (lv_scale * 100.0));
if ((libUNIT_gv_summonedUnits_index[lv_player] >= libUNIT_gv_summonedUnits_MaxLength)) {
libUNIT_gv_summonedUnits_index[lv_player] = 0;
libUNIT_gv_summonedUnits_resetted[lv_player] = true;
libUNIT_gv_summonedUnits_database[lv_player][libUNIT_gv_summonedUnits_index[lv_player]] = UnitLastCreated();
libUNIT_gv_summonedUnits_index[lv_player] = (libUNIT_gv_summonedUnits_index[lv_player] + 1);
}
else {
libUNIT_gv_summonedUnits_database[lv_player][libUNIT_gv_summonedUnits_index[lv_player]] = UnitLastCreated();
libUNIT_gv_summonedUnits_index[lv_player] = (libUNIT_gv_summonedUnits_index[lv_player] + 1);
}
}
}
else {
Expand Down Expand Up @@ -1851,6 +1869,16 @@ bool libUNIT_gt_SummonUnit_Func (bool testConds, bool runActions) {
libNtve_gf_CreateUnitsWithDefaultFacing(1, lv_unittype, 0, lv_player, CameraGetTarget(EventPlayer()), null);
AIAddPlayerUnit(UnitLastCreated());
UnitSetScale(UnitLastCreated(), (lv_scale * 100.0), (lv_scale * 100.0), (lv_scale * 100.0));
if ((libUNIT_gv_summonedUnits_index[lv_player] >= libUNIT_gv_summonedUnits_MaxLength)) {
libUNIT_gv_summonedUnits_index[lv_player] = 0;
libUNIT_gv_summonedUnits_resetted[lv_player] = true;
libUNIT_gv_summonedUnits_database[lv_player][libUNIT_gv_summonedUnits_index[lv_player]] = UnitLastCreated();
libUNIT_gv_summonedUnits_index[lv_player] = (libUNIT_gv_summonedUnits_index[lv_player] + 1);
}
else {
libUNIT_gv_summonedUnits_database[lv_player][libUNIT_gv_summonedUnits_index[lv_player]] = UnitLastCreated();
libUNIT_gv_summonedUnits_index[lv_player] = (libUNIT_gv_summonedUnits_index[lv_player] + 1);
}
}
return true;
}
Expand All @@ -1862,6 +1890,75 @@ void libUNIT_gt_SummonUnit_Init () {
TriggerAddEventChatMessage(libUNIT_gt_SummonUnit, c_playerAny, "sum", false);
}

//--------------------------------------------------------------------------------------------------
// Trigger: Clear Summoned Units
//--------------------------------------------------------------------------------------------------
bool libUNIT_gt_ClearSummonedUnits_Func (bool testConds, bool runActions) {
// Variable Declarations
unit lv_currentUnit;
int lv_i;
int lv_player;
int lv_unitCount;

// Automatic Variable Declarations
int auto7D8A0510_ae;
const int auto7D8A0510_ai = 1;
int auto0E93C612_ae;
const int auto0E93C612_ai = 1;

// Variable Initialization
lv_player = EventPlayer();
lv_unitCount = libUNIT_gv_summonedUnits_index[lv_player];

// Conditions
if (testConds) {
if (!(((StringWord(EventChatMessage(false), 1) == "clu") || (StringWord(EventChatMessage(false), 1) == "clearunits")))) {
return false;
}
}

// Actions
if (!runActions) {
return true;
}

if ((StringWord(EventChatMessage(false), 2) != null)) {
lv_player = StringToInt(StringWord(EventChatMessage(false), 2));
lv_unitCount = libUNIT_gv_summonedUnits_index[lv_player];
}

if ((libUNIT_gv_summonedUnits_resetted[lv_player] == true)) {
auto0E93C612_ae = (libUNIT_gv_summonedUnits_MaxLength - 1);
lv_i = 0;
for ( ; ( (auto0E93C612_ai >= 0 && lv_i <= auto0E93C612_ae) || (auto0E93C612_ai < 0 && lv_i >= auto0E93C612_ae) ) ; lv_i += auto0E93C612_ai ) {
lv_currentUnit = libUNIT_gv_summonedUnits_database[lv_player][lv_i];
UnitKill(lv_currentUnit);
libUNIT_gv_summonedUnits_database[lv_player][lv_i] = null;
}
UIDisplayMessage(PlayerGroupAll(), c_messageAreaDebug, StringToText((("Cleared " + IntToString(libUNIT_gv_summonedUnits_MaxLength)) + (" Units for Player " + (IntToString(lv_player) + ".")))));
}
else {
auto7D8A0510_ae = (lv_unitCount - 1);
lv_i = 0;
for ( ; ( (auto7D8A0510_ai >= 0 && lv_i <= auto7D8A0510_ae) || (auto7D8A0510_ai < 0 && lv_i >= auto7D8A0510_ae) ) ; lv_i += auto7D8A0510_ai ) {
lv_currentUnit = libUNIT_gv_summonedUnits_database[lv_player][lv_i];
UnitKill(lv_currentUnit);
libUNIT_gv_summonedUnits_database[lv_player][lv_i] = null;
}
UIDisplayMessage(PlayerGroupAll(), c_messageAreaDebug, StringToText((("Cleared " + IntToString(lv_unitCount)) + (" Units for Player " + (IntToString(lv_player) + ".")))));
}
libUNIT_gv_summonedUnits_index[lv_player] = 0;
libUNIT_gv_summonedUnits_resetted[lv_player] = false;
return true;
}

//--------------------------------------------------------------------------------------------------
void libUNIT_gt_ClearSummonedUnits_Init () {
libUNIT_gt_ClearSummonedUnits = TriggerCreate("libUNIT_gt_ClearSummonedUnits_Func");
TriggerAddEventChatMessage(libUNIT_gt_ClearSummonedUnits, c_playerAny, "clu", false);
TriggerAddEventChatMessage(libUNIT_gt_ClearSummonedUnits, c_playerAny, "clearunits", false);
}

void libUNIT_InitTriggers () {
libUNIT_gt_MapInit_Init();
libUNIT_gt_AddEffectstoCamera_Init();
Expand Down Expand Up @@ -1903,6 +2000,7 @@ void libUNIT_InitTriggers () {
libUNIT_gt_SummonUnitPanelSummonButtonClicked_Init();
libUNIT_gt_SummonUnitPanelCloseButtonClicked_Init();
libUNIT_gt_SummonUnit_Init();
libUNIT_gt_ClearSummonedUnits_Init();
}

//--------------------------------------------------------------------------------------------------
Expand Down
Binary file not shown.
29 changes: 29 additions & 0 deletions (10)trymemode.stormmap/base.stormdata/Modules/doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,35 @@
}
]
},
{
"shortCommand": "clu",
"command": "clearunits",
"description": [
"Clear all summoned unit(s) (summoned by the [summon](#cmd-summon) command) for a Player. This is useful for remove large numbers of summoned units, or when summoned untargetable/unselectable units that are not able to use the [killunits](#cmd-killunits) command.",
"",
">Note: Due to the memory limitation, only the **last 927 summoned units** will be able to remove with this command. Older units will not be affected, if you would like to remove ALL summoned units, either respec your hero, or restart the game."
],
"uiAvailable": false,
"parameters": [
{
"name": "PlayerId",
"required": false,
"description": "Define to clear which player's summoned unit(s).",
"type": "string",
"defaultValue": "The player id of whoever used this command."
}
],
"examples": [
{
"command": "clu",
"description": "Clear summoned unit(s) from player who used the command"
},
{
"command": "clearunits 6",
"description": "Clear summoned unit(s) from Player 6"
}
]
},
{
"shortCommand": "rpu",
"command": "replaceunit",
Expand Down
40 changes: 39 additions & 1 deletion USAGE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a name="meta-top"></a>

# Usage
<sup>*(Generated from [doc.json](./(10)trymemode.stormmap/base.stormdata/Modules/doc.json) at Wed, 30 Dec 2020 02:59:36 GMT)*</sup>
<sup>*(Generated from [doc.json](./(10)trymemode.stormmap/base.stormdata/Modules/doc.json) at Wed, 30 Dec 2020 09:36:04 GMT)*</sup>

Generally, most of the functionalities are using chat commands. Simply type the commands in the chat box (like how you would normally chat with teammates).
>Note: Remember to either use allies or all chat channel when try to use the commands. Public chat channels and Private Messages (PM) does not work.
Expand Down Expand Up @@ -68,6 +68,8 @@ Some of the commands have an UI counterpart implemented, which will display a me

- 💭 [Command: `clearbehavior`](#cmd-clearbehavior)

- 💭 [Command: `clearunits`](#cmd-clearunits)

- 💭 [Command: `countbehavior`](#cmd-countbehavior)

- 💭 [Command: `getbehavior`](#cmd-getbehavior)
Expand Down Expand Up @@ -774,6 +776,42 @@ Clear all active behaviors for selected units.



[\[Return to Table of Contents 🧾\]](#meta-toc)

[\[Return to Top ⬆\]](#meta-top)

<a name="cmd-clearunits"></a>

## (`clearunits` | `clu`) `[PlayerId]`
<a name="cmd-clearunits-description"></a>

#### ✏ Description:
Clear all summoned unit(s) (summoned by the [summon](#cmd-summon) command) for a Player. This is useful for remove large numbers of summoned units, or when summoned untargetable/unselectable units that are not able to use the [killunits](#cmd-killunits) command.

>Note: Due to the memory limitation, only the **last 927 summoned units** will be able to remove with this command. Older units will not be affected, if you would like to remove ALL summoned units, either respec your hero, or restart the game.
<a name="cmd-clearunits-parameters"></a>

#### ⚙ Parameters:
[PlayerId]
Required: false
Type: string
Usage: Define to clear which player's summoned unit(s).
Default: The player id of whoever used this command.
<a name="cmd-clearunits-examples"></a>

#### 🔧 Examples:
> clu
(Clear summoned unit(s) from player who used the command)
> clearunits 6
(Clear summoned unit(s) from Player 6)
<a name="cmd-clearunits-uiAvailability"></a>

#### 🖼 UI Availability:
-**Not Implemented**



[\[Return to Table of Contents 🧾\]](#meta-toc)

[\[Return to Top ⬆\]](#meta-top)
Expand Down

0 comments on commit 8346f6e

Please sign in to comment.