Skip to content

Commit c3ac33b

Browse files
authored
Forcing specific weapon by target type (#1631)
This is a supplement for #1695. With multiple weapons being set, you can use `ForceWeapon` to enable them when attacking different targets. This pull request is a basic one that should be enough for many cases - A series of tags can force specified weapons based on the target's type. - `ForceWeapon.Naval.Units` forces specified weapon to be used against `Naval=yes` units. Taking priority to `ForceWeapon.Units`. - If `ForceWeapon.Defenses` is enabled, it'll be used if the target is a building with `BuildCat=Combat`. Otherwise it'll follow `ForceWeapon.Buildings`, if enabled. - `ForceWeapon.Infantry/Units/Aircraft` can be applied to both ground and air target if `ForceAAWeapon.Infantry/Units/Aircraft` is not set. - `ForceAAWeapon.Infantry/Units/Aircraft` do the same things but only for air target. Taking priority to `ForceWeapon.Infantry/Units/Naval.Units/Aircraft`, which means that they can only be applied to ground target when they're both set. In `rulesmd.ini`: ```ini [SOMETECHNO] ; TechnoType ForceWeapon.Buildings=-1 ; integer, -1 to disable ForceWeapon.Defenses=-1 ; integer, -1 to disable ForceWeapon.Infantry=-1 ; integer, -1 to disable ForceWeapon.Naval.Units=-1 ; integer, -1 to disable ForceWeapon.Units=-1 ; integer, -1 to disable ForceWeapon.Aircraft=-1 ; integer, -1 to disable ForceAAWeapon.Infantry=-1 ; integer, -1 to disable ForceAAWeapon.Units=-1 ; integer, -1 to disable ForceAAWeapon.Aircraft=-1 ; integer, -1 to disable ```
1 parent 11205db commit c3ac33b

File tree

5 files changed

+114
-10
lines changed

5 files changed

+114
-10
lines changed

CREDITS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ This page lists all the individual contributions to the project by their author.
510510
- Fix `DefaultDisguise` showing wrong house colors for different players
511511
- Fire weapon when Warhead kills something
512512
- Promotion animation deglobalization
513-
- Forcing specific weapon by range
513+
- Forcing specific weapon by range and target type
514514
- Passenger-based insignias
515515
- Use `InsigniaType` to set the properties of insignia in a batch
516516
- Allow player's self-healing effects to be benefited by allied or `PlayerControl=true` houses

docs/New-or-Enhanced-Logics.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,29 +1486,43 @@ FLHKEY.BurstN= ; integer - Forward,Lateral,Height. FLHKey refers to weapon-spec
14861486
*Enemy behavior against EMP targets with `ForceWeapon.UnderEMP` in [C&C: Reloaded](https://www.moddb.com/mods/cncreloaded)*
14871487

14881488
- Can be used to override normal weapon selection logic to force specific weapons to use against certain targets. If multiple are set and target satisfies the conditions, the first one in listed order satisfied takes effect.
1489-
- `ForceWeapon.Naval.Decloaked` forces specified weapon to be used against uncloaked naval targets. Useful if your naval unit has one weapon only for underwater and another weapon for surface targets.
1489+
- `ForceWeapon.Naval.Decloaked` forces specified weapon to be used against uncloaked `Naval=yes` targets. Useful if your naval unit has one weapon only for underwater and another weapon for surface targets.
14901490
- `ForceWeapon.Cloaked` forces specified weapon to be used against any cloaked targets.
14911491
- `ForceWeapon.Disguised` forces specified weapon to be used against any disguised targets.
14921492
- `ForceWeapon.UnderEMP` forces specified weapon to be used if the target is under EMP effect.
14931493
- `ForceWeapon.InRange` forces specified a list of weapons to be used once the target is within their `Range`. If `ForceWeapon.InRange.TechnoOnly` set to true, it'll only be forced on TechnoTypes like other forced weapons, otherwise it'll also be forced when attacking empty grounds. The first weapon in the listed order satisfied will be selected. Can be applied to both ground and air target if `ForceAAWeapon.InRange` is not set.
14941494
- `ForceAAWeapon.InRange` does the same thing but only for air target. Taking priority to `ForceWeapon.InRange`, which means that it can only be applied to ground target when they're both set.
14951495
- `Force(AA)Weapon.InRange.Overrides` overrides the range when decides which weapon to use. Value from position matching the position from `Force(AA)Weapon.InRange` is used if found, or the weapon's own `Range` if not found or set to a value below 0.
14961496
- If `Force(AA)Weapon.InRange.ApplyRangeModifiers` is set to true, any applicable weapon range modifiers from the firer are applied to the decision range.
1497+
- A series of tags can force specified weapons based on the target's type.
1498+
- `ForceWeapon.Naval.Units` forces specified weapon to be used against `Naval=yes` units. Taking priority to `ForceWeapon.Units`.
1499+
- If `ForceWeapon.Defenses` is enabled, it'll be used if the target is a building with `BuildCat=Combat`. Otherwise it'll follow `ForceWeapon.Buildings`, if enabled.
1500+
- `ForceWeapon.Infantry/Units/Aircraft` can be applied to both ground and air target if `ForceAAWeapon.Infantry/Units/Aircraft` is not set.
1501+
- `ForceAAWeapon.Infantry/Units/Aircraft` do the same things but only for air target. Taking priority to `ForceWeapon.Infantry/Units/Naval.Units/Aircraft`, which means that they can only be applied to ground target when they're both set.
14971502

14981503
In `rulesmd.ini`:
14991504
```ini
15001505
[SOMETECHNO] ; TechnoType
1501-
ForceWeapon.Naval.Decloaked=-1 ; integer. 0 for primary weapon, 1 for secondary weapon, -1 to disable
1502-
ForceWeapon.Cloaked=-1 ; integer. 0 for primary weapon, 1 for secondary weapon, -1 to disable
1503-
ForceWeapon.Disguised=-1 ; integer. 0 for primary weapon, 1 for secondary weapon, -1 to disable
1504-
ForceWeapon.UnderEMP=-1 ; integer. 0 for primary weapon, 1 for secondary weapon, -1 to disable
1505-
ForceWeapon.InRange= ; List of integers. 0 for primary weapon, 1 for secondary weapon, -1 to disable
1506+
ForceWeapon.Naval.Decloaked=-1 ; integer, -1 to disable
1507+
ForceWeapon.Cloaked=-1 ; integer, -1 to disable
1508+
ForceWeapon.Disguised=-1 ; integer, -1 to disable
1509+
ForceWeapon.UnderEMP=-1 ; integer, -1 to disable
1510+
ForceWeapon.InRange= ; List of integers
15061511
ForceWeapon.InRange.Overrides= ; List of floating-point values
15071512
ForceWeapon.InRange.ApplyRangeModifiers=false ; boolean
15081513
ForceWeapon.InRange.TechnoOnly=true ; boolean
1509-
ForceAAWeapon.InRange= ; List of integers. 0 for primary weapon, 1 for secondary weapon, -1 to disable
1514+
ForceAAWeapon.InRange= ; List of integers
15101515
ForceAAWeapon.InRange.Overrides= ; List of floating-point values
15111516
ForceAAWeapon.InRange.ApplyRangeModifiers=false ; boolean
1517+
ForceWeapon.Buildings=-1 ; integer, -1 to disable
1518+
ForceWeapon.Defenses=-1 ; integer, -1 to disable
1519+
ForceWeapon.Infantry=-1 ; integer, -1 to disable
1520+
ForceWeapon.Naval.Units=-1 ; integer, -1 to disable
1521+
ForceWeapon.Units=-1 ; integer, -1 to disable
1522+
ForceWeapon.Aircraft=-1 ; integer, -1 to disable
1523+
ForceAAWeapon.Infantry=-1 ; integer, -1 to disable
1524+
ForceAAWeapon.Units=-1 ; integer, -1 to disable
1525+
ForceAAWeapon.Aircraft=-1 ; integer, -1 to disable
15121526
```
15131527

15141528
```{note}

docs/Whats-New.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ New:
365365
- [Customize overpower logic](Fixed-or-Improved-Logics.md#customize-overpower-logic) (by NetsuNegi)
366366
- [Promotion animation deglobalization](New-or-Enhanced-Logics.md#promotion-animation) (by Ollerus)
367367
- Enhanced [reveal](New-or-Enhanced-Logics.md#reveal-map-for-owner-on-impact) & [gap](New-or-Enhanced-Logics.md#shroud-map-for-enemies-on-impact) warhead (by NetsuNegi)
368-
- [Forcing specific weapon by range](New-or-Enhanced-Logics.md#forcing-specific-weapon-against-certain-targets) (by Ollerus)
368+
- [Forcing specific weapon by range and target type](New-or-Enhanced-Logics.md#forcing-specific-weapon-against-certain-targets) (by Ollerus)
369369
- [Jumpjet Tilts While Moving](New-or-Enhanced-Logics.md#jumpjet-tilts-while-moving) (by CrimRecya)
370370
- [Spawned aircraft facing to match turret toggle](New-or-Enhanced-Logics.md#aircraft-spawner-customizations) (by Starkku)
371371
- [Removed dependency on `blowfish.dll`](Miscellanous.md#blowfish-dependency) (by ZivDero)

src/Ext/TechnoType/Body.cpp

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ int TechnoTypeExt::ExtData::SelectForceWeapon(TechnoClass* pThis, AbstractClass*
4141

4242
int forceWeaponIndex = -1;
4343
const auto pTargetTechno = abstract_cast<TechnoClass*>(pTarget);
44+
TechnoTypeClass* pTargetType = nullptr;
4445

4546
if (pTargetTechno)
4647
{
47-
const auto pTargetType = pTargetTechno->GetTechnoType();
48+
pTargetType = pTargetTechno->GetTechnoType();
4849

4950
if (this->ForceWeapon_Naval_Decloaked >= 0
5051
&& pTargetType->Cloakable
@@ -79,6 +80,49 @@ int TechnoTypeExt::ExtData::SelectForceWeapon(TechnoClass* pThis, AbstractClass*
7980
TechnoTypeExt::SelectWeaponMutex = false;
8081
}
8182

83+
if (forceWeaponIndex == -1 && pTargetType)
84+
{
85+
switch (pTarget->WhatAmI())
86+
{
87+
case AbstractType::Building:
88+
{
89+
forceWeaponIndex = this->ForceWeapon_Buildings;
90+
91+
if (this->ForceWeapon_Defenses >= 0)
92+
{
93+
auto const pBuildingType = static_cast<BuildingTypeClass*>(pTargetType);
94+
95+
if (pBuildingType->BuildCat == BuildCat::Combat)
96+
forceWeaponIndex = this->ForceWeapon_Defenses;
97+
}
98+
99+
break;
100+
}
101+
case AbstractType::Infantry:
102+
{
103+
forceWeaponIndex = (this->ForceAAWeapon_Infantry >= 0 && pTarget->IsInAir())
104+
? this->ForceAAWeapon_Infantry : this->ForceWeapon_Infantry;
105+
106+
break;
107+
}
108+
case AbstractType::Unit:
109+
{
110+
forceWeaponIndex = (this->ForceAAWeapon_Units >= 0 && pTarget->IsInAir())
111+
? this->ForceAAWeapon_Units : ((this->ForceWeapon_Naval_Units >= 0 && pTargetType->Naval)
112+
? this->ForceWeapon_Naval_Units : this->ForceWeapon_Units);
113+
114+
break;
115+
}
116+
case AbstractType::Aircraft:
117+
{
118+
forceWeaponIndex = (this->ForceAAWeapon_Aircraft >= 0 && pTarget->IsInAir())
119+
? this->ForceAAWeapon_Aircraft : this->ForceWeapon_Aircraft;
120+
121+
break;
122+
}
123+
}
124+
}
125+
82126
return forceWeaponIndex;
83127
}
84128

@@ -639,13 +683,32 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
639683
this->ForceAAWeapon_InRange.Read(exINI, pSection, "ForceAAWeapon.InRange");
640684
this->ForceAAWeapon_InRange_Overrides.Read(exINI, pSection, "ForceAAWeapon.InRange.Overrides");
641685
this->ForceAAWeapon_InRange_ApplyRangeModifiers.Read(exINI, pSection, "ForceAAWeapon.InRange.ApplyRangeModifiers");
686+
this->ForceWeapon_Buildings.Read(exINI, pSection, "ForceWeapon.Buildings");
687+
this->ForceWeapon_Defenses.Read(exINI, pSection, "ForceWeapon.Defenses");
688+
this->ForceWeapon_Infantry.Read(exINI, pSection, "ForceWeapon.Infantry");
689+
this->ForceWeapon_Naval_Units.Read(exINI, pSection, "ForceWeapon.Naval.Units");
690+
this->ForceWeapon_Units.Read(exINI, pSection, "ForceWeapon.Units");
691+
this->ForceWeapon_Aircraft.Read(exINI, pSection, "ForceWeapon.Aircraft");
692+
this->ForceAAWeapon_Infantry.Read(exINI, pSection, "ForceAAWeapon.Infantry");
693+
this->ForceAAWeapon_Units.Read(exINI, pSection, "ForceAAWeapon.Units");
694+
this->ForceAAWeapon_Aircraft.Read(exINI, pSection, "ForceAAWeapon.Aircraft");
695+
642696
this->ForceWeapon_Check = (
643697
this->ForceWeapon_Naval_Decloaked >= 0
644698
|| this->ForceWeapon_Cloaked >= 0
645699
|| this->ForceWeapon_Disguised >= 0
646700
|| this->ForceWeapon_UnderEMP >= 0
647701
|| !this->ForceWeapon_InRange.empty()
648702
|| !this->ForceAAWeapon_InRange.empty()
703+
|| this->ForceWeapon_Buildings >= 0
704+
|| this->ForceWeapon_Defenses >= 0
705+
|| this->ForceWeapon_Infantry >= 0
706+
|| this->ForceWeapon_Naval_Units >= 0
707+
|| this->ForceWeapon_Units >= 0
708+
|| this->ForceWeapon_Aircraft >= 0
709+
|| this->ForceAAWeapon_Infantry >= 0
710+
|| this->ForceAAWeapon_Units >= 0
711+
|| this->ForceAAWeapon_Aircraft >= 0
649712
);
650713

651714
this->Ammo_Shared.Read(exINI, pSection, "Ammo.Shared");
@@ -1234,6 +1297,15 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
12341297
.Process(this->ForceAAWeapon_InRange)
12351298
.Process(this->ForceAAWeapon_InRange_Overrides)
12361299
.Process(this->ForceAAWeapon_InRange_ApplyRangeModifiers)
1300+
.Process(this->ForceWeapon_Buildings)
1301+
.Process(this->ForceWeapon_Defenses)
1302+
.Process(this->ForceWeapon_Infantry)
1303+
.Process(this->ForceWeapon_Naval_Units)
1304+
.Process(this->ForceWeapon_Units)
1305+
.Process(this->ForceWeapon_Aircraft)
1306+
.Process(this->ForceAAWeapon_Infantry)
1307+
.Process(this->ForceAAWeapon_Units)
1308+
.Process(this->ForceAAWeapon_Aircraft)
12371309

12381310
.Process(this->Ammo_Shared)
12391311
.Process(this->Ammo_Shared_Group)

src/Ext/TechnoType/Body.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ class TechnoTypeExt
182182
ValueableVector<int> ForceAAWeapon_InRange;
183183
ValueableVector<double> ForceAAWeapon_InRange_Overrides;
184184
Valueable<bool> ForceAAWeapon_InRange_ApplyRangeModifiers;
185+
Valueable<int> ForceWeapon_Buildings;
186+
Valueable<int> ForceWeapon_Defenses;
187+
Valueable<int> ForceWeapon_Infantry;
188+
Valueable<int> ForceWeapon_Naval_Units;
189+
Valueable<int> ForceWeapon_Units;
190+
Valueable<int> ForceWeapon_Aircraft;
191+
Valueable<int> ForceAAWeapon_Infantry;
192+
Valueable<int> ForceAAWeapon_Units;
193+
Valueable<int> ForceAAWeapon_Aircraft;
185194

186195
Valueable<bool> Ammo_Shared;
187196
Valueable<int> Ammo_Shared_Group;
@@ -534,6 +543,15 @@ class TechnoTypeExt
534543
, ForceAAWeapon_InRange {}
535544
, ForceAAWeapon_InRange_Overrides {}
536545
, ForceAAWeapon_InRange_ApplyRangeModifiers { false }
546+
, ForceWeapon_Buildings { -1 }
547+
, ForceWeapon_Defenses { -1 }
548+
, ForceWeapon_Infantry { -1 }
549+
, ForceWeapon_Naval_Units { -1 }
550+
, ForceWeapon_Units { -1 }
551+
, ForceWeapon_Aircraft { -1 }
552+
, ForceAAWeapon_Infantry { -1 }
553+
, ForceAAWeapon_Units { -1 }
554+
, ForceAAWeapon_Aircraft { -1 }
537555

538556
, Ammo_Shared { false }
539557
, Ammo_Shared_Group { -1 }

0 commit comments

Comments
 (0)