Skip to content

Commit

Permalink
Track ACUs last taking damage for disconnect rules
Browse files Browse the repository at this point in the history
  • Loading branch information
lL1l1 committed Mar 17, 2024
1 parent 7387f9f commit b8431de
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
6 changes: 3 additions & 3 deletions loc/US/strings_db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7727,7 +7727,7 @@ lobui_0796="Partial Share"
lobui_0797="Your buildings and engineers will be transferred to your highest rated ally when you die. Your other units will be destroyed when you die, except those captured by the enemy."

lobui_0798="DC Share Conditions"
lobui_0799="Set what happens to a player's units when they disconnect. In Assassination, only applies if an ACU is at full health/shield."
lobui_0799="Set what happens to a player's units when they disconnect. In Assassination, only applies if an ACU has not been damaged in the last 2 minutes."
lobui_0800="Same as Share Condition"
lobui_0801="Treat disconnecting players the same as defeated players."

Expand All @@ -7740,9 +7740,9 @@ lobui_0806="Yes"
lobui_0807="This game will not be rated."

lobui_0808="Recall Disconnected ACUs"
lobui_0809="Should disconnecting players' full health/shield ACUs be recalled, preventing their explosion?"
lobui_0809="Should disconnecting players' ACUs be recalled, preventing their explosion if they were not damaged in the last 2 minutes?"
lobui_0810="ACUs explode when their player disconnects."
lobui_0811="ACUs that are at full health and shield are recalled when their player disconnects."
lobui_0811="ACUs not damaged in the last 2 minutes are recalled when their player disconnects."

aisettings_0001="AIx Cheat Multiplier"
aisettings_0002="Set the cheat multiplier for the cheating AIs."
Expand Down
12 changes: 3 additions & 9 deletions lua/aibrain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -966,15 +966,9 @@ AIBrain = Class(AIBrainHQComponent, AIBrainStatisticsComponent, AIBrainJammerCom

local commanders = self:GetListOfUnits(categories.COMMAND, false)
for _, com in commanders do
if com:GetHealth() == com:GetMaxHealth() then
local comShield = com.MyShield
if comShield then
if comShield:GetHealth() == comShield:GetMaxHealth() then
table.insert(safeCommanders, com)
end
else
table.insert(safeCommanders, com)
end
-- 2 minutes since last damaged
if com.LastTickDamaged == nil or com.LastTickDamaged + 1200 <= GetGameTick() then
table.insert(safeCommanders, com)
end
end

Expand Down
14 changes: 14 additions & 0 deletions lua/sim/units/ACUUnit.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local CommandUnit = import("/lua/sim/units/commandunit.lua").CommandUnit

---@class ACUUnit : CommandUnit
---@field LastTickDamaged number
ACUUnit = ClassUnit(CommandUnit) {
-- The "commander under attack" warnings.
---@param self ACUUnit
Expand Down Expand Up @@ -59,6 +60,19 @@ ACUUnit = ClassUnit(CommandUnit) {
self.WeaponEnabled = {}
end,

---@param self ACUUnit
---@param instigator Unit
---@param amount number
---@param vector Vector
---@param damageType DamageType
OnDamage = function(self, instigator, amount, vector, damageType)
if self.CanTakeDamage and damageType ~= "TreeForce" and damageType ~= "TreeFire" then
self.LastTickDamaged = GetGameTick()
end

CommandUnit.OnDamage(self, instigator, amount, vector, damageType)
end,

---@param self ACUUnit
---@param instigator Unit
---@param amount number
Expand Down
6 changes: 3 additions & 3 deletions lua/ui/lobby/lobbyOptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ globalOpts = {
{
default = 1,
label = "<LOC lobui_0798>DC Share Conditions",
help = "<LOC lobui_0799>Set what happens to a player's units when they disconnect. In Assassination, only applies if an ACU is at full health/shield.",
help = "<LOC lobui_0799>Set what happens to a player's units when they disconnect. In Assassination, only applies if an ACU has not been damaged in the last 2 minutes.",
key = 'AbandonmentShare',
values = {
{
Expand Down Expand Up @@ -279,7 +279,7 @@ globalOpts = {
{
default = 1,
label = "<LOC lobui_0808>Recall Disconnected ACUs",
help = "<LOC lobui_0809>Should disconnecting players' full health/shield ACUs be recalled, preventing their explosion?",
help = "<LOC lobui_0809>Should disconnecting players' ACUs be recalled, preventing their explosion if they were not damaged in the last 2 minutes?",
key = 'AbandonmentRecall',
values = {
{
Expand All @@ -289,7 +289,7 @@ globalOpts = {
},
{
text = "<LOC _Yes>Yes",
help = "<LOC lobui_0811>ACUs that are at full health and shield are recalled when their player disconnects.",
help = "<LOC lobui_0811>ACUs not damaged in the last 2 minutes are recalled when their player disconnects.",
key = true,
},
},
Expand Down

0 comments on commit b8431de

Please sign in to comment.