Skip to content

Forcing specific weapon by target type #1631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

Coronia
Copy link
Contributor

@Coronia Coronia commented Apr 16, 2025

This is a supplement for #1630. 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.
    • If ForceWeapon.Defenses is enabled, it'll be used if the target is a building with IsBaseDefense=yes. 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/Aircraft, which means that they can only be applied to ground target when they're both set.

In rulesmd.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.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

Copy link

github-actions bot commented Apr 16, 2025

Nightly build for this pull request:

This comment is automatic and is meant to allow guests to get latest nightly builds for this pull request without registering. It is updated on every successful build.

@Coronia
Copy link
Contributor Author

Coronia commented Apr 16, 2025

besides, if you're certain that weapons of a techno won't make use of the following things, you can use this ability to make it skip previous weapon index picking logic, to save some calculation cost

  • CanTarget
  • CanTargetHouse
  • AttachEffect.RequiredTypes/Groups
  • AttachEffect.DisallowedTypes/Groups
  • Land/NavalTargeting

a similar optimization was also made in #1568

@Coronia Coronia added Tested ⚙️T1 T1 maintainer review is sufficient labels Apr 17, 2025

if (pTypeExt->ForceWeapon_Defenses >= 0)
{
auto const pBuildingType = abstract_cast<BuildingTypeClass*>(pTargetTechno->GetTechnoType());
Copy link
Contributor

@CrimRecya CrimRecya Apr 19, 2025

Choose a reason for hiding this comment

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

auto const pBuildingType = static_cast<BuildingClass*>(pTargetTechno)->Type;
or auto const pBuildingType = static_cast<BuildingTypeClass*>(pTargetType);

Comment on lines +148 to +156
case AbstractType::Unit:
{
if (pTypeExt->ForceAAWeapon_Units >= 0 && pTarget->IsInAir())
forceWeaponIndex = pTypeExt->ForceAAWeapon_Units;
else
forceWeaponIndex = pTypeExt->ForceWeapon_Units;

break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can also add a ForceWeapon.Naval

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️T1 T1 maintainer review is sufficient Tested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants