Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ This page lists all the individual contributions to the project by their author.
- **Flactine**
- Add target filtering options to attacheffect system
- Add veterancy-based target filtering for weapons and warheads
- Add a new AutoDeath condition based on the owner's power status
- **tyuah8**:
- Drive/Jumpjet/Ship/Teleport locomotor did not power on when it is un-piggybacked bugfix
- Destroyed unit leaves sensors bugfix
Expand Down
12 changes: 12 additions & 0 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1924,6 +1924,15 @@ Both `InitialStrength` and `InitialStrength.Cloning` never surpass the type's `S
- `Technos(Dont)Exist.Any` controls whether or not a single listed TechnoType is enough to satisfy the requirement or if all are required.
- `Technos(Dont)Exist.AllowLimboed` controls whether or not limboed TechnoTypes (f.ex those in transports) are counted.
- `Technos(Dont)Exist.Houses` controls which houses are checked.
- `PlayerPower`: The object will die if its owner's power status matches the configured state.
- `low` / `consumer`: Trigger when the owner is in low power.
- `normal`: Trigger when the owner is not in low power.
- `PlayerMoneyLessThan` / `PlayerMoneyMoreThan`: The object will die based on the owner's available credits.
- If only `PlayerMoneyLessThan` is set, triggers when money is below this value.
- If only `PlayerMoneyMoreThan` is set, triggers when money is above this value.
- If both are set, they define a range condition:
- If `PlayerMoneyLessThan < PlayerMoneyMoreThan`: triggers when money is **inside the range**.
- If `PlayerMoneyLessThan >= PlayerMoneyMoreThan`: triggers when money is **outside the range**.

- The auto-death behavior can be chosen from the following:
- `kill`: The object will be destroyed normally.
Expand All @@ -1950,6 +1959,9 @@ AutoDeath.TechnosExist= ; List of TechnoTypes
AutoDeath.TechnosExist.Any=true ; boolean
AutoDeath.TechnosExist.AllowLimboed=false ; boolean
AutoDeath.TechnosExist.Houses=owner ; Affected House Enumeration (none|owner/self|allies/ally|team|enemies/enemy|all)
AutoDeath.PlayerPowerStatus=none ; Player Power Enumeration (none|low/consumer|normal)
AutoDeath.PlayerMoneyLessThan=-1 ; integer
AutoDeath.PlayerMoneyMoreThan=-1 ; integer
```

```{note}
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ HideShakeEffects=false ; boolean
- Add `ClampToScreen` tag for `BannerType` (defaults to `true`) to control whether banner position is clamped to the visible area (by Chang_zhi)
- [Customizable Berzerk mission](Fixed-or-Improved-Logics.md#enhanced-berzerk-behavior) (by TaranDahl)
- [Tank Bunker foundation and state update delay improvements](Fixed-or-Improved-Logics.md#tank-bunker-improvements) (by Starkku)
- [AutoDeath based on player power status and player credits](New-or-Enhanced-Logics.md#kill-object-automatically) (by Flactine)

#### Vanilla fixes:
- Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya)
Expand Down
27 changes: 27 additions & 0 deletions docs/locale/zh_CN/LC_MESSAGES/New-or-Enhanced-Logics.po
Original file line number Diff line number Diff line change
Expand Up @@ -4425,6 +4425,33 @@ msgstr "`Technos(Dont)Exist.AllowLimboed` 控制是否计入虚拟的科技类
msgid "`Technos(Dont)Exist.Houses` controls which houses are checked."
msgstr "`Technos(Dont)Exist.Houses` 控制检查哪些所属方。"

msgid "`PlayerPower`: The object will die if its owner's power status matches the configured state."
msgstr "`PlayerPower`:当对象所属方的电力状态符合设定条件时,则对象死亡。"

msgid "`low` / `consumer`: Trigger when the owner is in low power."
msgstr "`low` / `consumer`:当对象所属方处于电力不足状态时触发。"

msgid "`normal`: Trigger when the owner is not in low power."
msgstr "`normal`:当对象所属方未处于电力不足状态时触发。"

msgid "`PlayerMoneyLessThan` / `PlayerMoneyMoreThan`: The object will die based on the owner's available credits."
msgstr "`PlayerMoneyLessThan` / `PlayerMoneyMoreThan`:根据对象所属方的资金决定对象是否死亡。"

msgid "If only `PlayerMoneyLessThan` is set, triggers when money is below this value."
msgstr "仅设置 `PlayerMoneyLessThan` 时,当资金低于该值时触发。"

msgid "If only `PlayerMoneyMoreThan` is set, triggers when money is above this value."
msgstr "仅设置 `PlayerMoneyMoreThan` 时,当资金高于该值时触发。"

msgid "If both are set, they define a range condition:"
msgstr "同时设置时为区间条件:"

msgid "If `PlayerMoneyLessThan < PlayerMoneyMoreThan`: triggers when money is **outside the range**."
msgstr "当 `PlayerMoneyLessThan < PlayerMoneyMoreThan` 时:资金处于**区间内**时触发。"

msgid "If `PlayerMoneyLessThan >= PlayerMoneyMoreThan`: triggers when money is **inside the range**."
msgstr "当 `PlayerMoneyLessThan >= PlayerMoneyMoreThan` 时:资金处于**区间外**时触发。"

msgid "The auto-death behavior can be chosen from the following:"
msgstr "自毁行为有以下选择:"

Expand Down
42 changes: 42 additions & 0 deletions src/Ext/Techno/Body.Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,48 @@ bool TechnoExt::ExtData::CheckDeathConditions(bool isInLimbo)
: std::all_of(vTypes.begin(), vTypes.end(), existSingleType);
};

if (pTypeExt->AutoDeath_PlayerPowerStatus != PlayerPowerStatus::None)
{
const bool isLowPower = pOwner->HasLowPower();
const auto status = pTypeExt->AutoDeath_PlayerPowerStatus;

if ((status == PlayerPowerStatus::Normal && !isLowPower) || (status == PlayerPowerStatus::Low && isLowPower))
{
TechnoExt::KillSelf(pThis, howToDie, pTypeExt->AutoDeath_VanishAnimation, isInLimbo);
return true;
}
}

if (pTypeExt->AutoDeath_PlayerMoneyLessThan != -1 || pTypeExt->AutoDeath_PlayerMoneyMoreThan != -1)
{
const int lessThan = pTypeExt->AutoDeath_PlayerMoneyLessThan;
const int moreThan = pTypeExt->AutoDeath_PlayerMoneyMoreThan;
const int money = pOwner->Available_Money();
bool shouldDie = false;

if (lessThan != -1 && moreThan != -1)
{
if (lessThan < moreThan)
shouldDie = (money < lessThan && money > moreThan);
else
shouldDie = (money < lessThan || money > moreThan);
}
else if (lessThan != -1)
{
shouldDie = (money < lessThan);
}
else
{
shouldDie = (money > moreThan);
}
Comment thread
Flactine marked this conversation as resolved.
Outdated

if (shouldDie)
{
TechnoExt::KillSelf(pThis, howToDie, pTypeExt->AutoDeath_VanishAnimation, isInLimbo);
return true;
}
}

// death if listed technos don't exist
if (!pTypeExt->AutoDeath_TechnosDontExist.empty())
{
Expand Down
6 changes: 6 additions & 0 deletions src/Ext/TechnoType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,9 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->AutoDeath_TechnosExist_Any.Read(exINI, pSection, "AutoDeath.TechnosExist.Any");
this->AutoDeath_TechnosExist_AllowLimboed.Read(exINI, pSection, "AutoDeath.TechnosExist.AllowLimboed");
this->AutoDeath_TechnosExist_Houses.Read(exINI, pSection, "AutoDeath.TechnosExist.Houses");
this->AutoDeath_PlayerPowerStatus.Read(exINI, pSection, "AutoDeath.PlayerPowerStatus");
this->AutoDeath_PlayerMoneyLessThan.Read(exINI, pSection, "AutoDeath.PlayerMoneyLessThan");
this->AutoDeath_PlayerMoneyMoreThan.Read(exINI, pSection, "AutoDeath.PlayerMoneyMoreThan");

this->Slaved_OwnerWhenMasterKilled.Read(exINI, pSection, "Slaved.OwnerWhenMasterKilled");
this->SlavesFreeSound.Read(exINI, pSection, "SlavesFreeSound");
Expand Down Expand Up @@ -1551,6 +1554,9 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
.Process(this->AutoDeath_TechnosExist_Any)
.Process(this->AutoDeath_TechnosExist_AllowLimboed)
.Process(this->AutoDeath_TechnosExist_Houses)
.Process(this->AutoDeath_PlayerPowerStatus)
.Process(this->AutoDeath_PlayerMoneyLessThan)
.Process(this->AutoDeath_PlayerMoneyMoreThan)

.Process(this->Slaved_OwnerWhenMasterKilled)
.Process(this->SlavesFreeSound)
Expand Down
6 changes: 6 additions & 0 deletions src/Ext/TechnoType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class TechnoTypeExt
Valueable<bool> AutoDeath_TechnosExist_Any;
Valueable<bool> AutoDeath_TechnosExist_AllowLimboed;
Valueable<AffectedHouse> AutoDeath_TechnosExist_Houses;
Valueable<PlayerPowerStatus> AutoDeath_PlayerPowerStatus;
Valueable<int> AutoDeath_PlayerMoneyLessThan;
Valueable<int> AutoDeath_PlayerMoneyMoreThan;

Valueable<SlaveChangeOwnerType> Slaved_OwnerWhenMasterKilled;
NullableIdx<VocClass> SlavesFreeSound;
Expand Down Expand Up @@ -656,6 +659,9 @@ class TechnoTypeExt
, AutoDeath_TechnosExist_Any { true }
, AutoDeath_TechnosExist_AllowLimboed { true }
, AutoDeath_TechnosExist_Houses { AffectedHouse::Owner }
, AutoDeath_PlayerPowerStatus { PlayerPowerStatus::None }
, AutoDeath_PlayerMoneyLessThan { -1 }
, AutoDeath_PlayerMoneyMoreThan { -1 }

, Slaved_OwnerWhenMasterKilled { SlaveChangeOwnerType::Killer }
, SlavesFreeSound {}
Expand Down
7 changes: 7 additions & 0 deletions src/Utilities/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ enum class AutoDeathBehavior
Sell = 2, // buildings only
};

enum class PlayerPowerStatus
{
None = 0,
Normal = 1, // not low power
Low = 2, // low power
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PlayerPowerStatus -> PowerStatus
Normal -> Full


enum class SelfHealGainType
{
NoHeal = 0,
Expand Down
27 changes: 27 additions & 0 deletions src/Utilities/TemplateDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,33 @@ if(_strcmpi(parser.value(), #name) == 0){ value = __uuidof(name ## LocomotionCla
Debug::INIParseFailed(pSection, pKey, pCur);
}
}

template <>
inline bool read<PlayerPowerStatus>(PlayerPowerStatus& value, INI_EX& parser, const char* pSection, const char* pKey)
{
if (parser.ReadString(pSection, pKey))
{
static const std::pair<const char*, PlayerPowerStatus> Names[] =
{
{"none", PlayerPowerStatus::None},
{"consumer", PlayerPowerStatus::Low},
{"low", PlayerPowerStatus::Low},
{"normal", PlayerPowerStatus::Normal},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove consumer since it's not a clear term here
change normal to full

};

for (auto const& [name, val] : Names)
{
if (_strcmpi(parser.value(), name) == 0)
{
value = val;
return true;
}
}

Debug::INIParseFailed(pSection, pKey, parser.value(), "Expected a valid PlayerPowerStatus (none, normal, low|consumer");
}
return false;
}
}

// Valueable
Expand Down