Phobos icon indicating copy to clipboard operation
Phobos copied to clipboard

Forcing specific weapon by target type

Open Coronia opened this issue 7 months ago • 4 comments

This is a supplement for https://github.com/Phobos-developers/Phobos/pull/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.
    • ForceWeapon.Naval forces specified weapon to be used against Naval=yes targets. Taking priority to other target type-based forced weapons.
    • 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.Naval=-1                            ; integer, -1 to disable
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

Coronia avatar Apr 16 '25 06:04 Coronia

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.

github-actions[bot] avatar Apr 16 '25 06:04 github-actions[bot]

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 https://github.com/Phobos-developers/Phobos/pull/1568

Coronia avatar Apr 16 '25 07:04 Coronia

I think after updating it, we can merge this.

By the way, my opinion on ForceWeapon.Naval is probably like this, what do you think?

case AbstractType::Unit:
{
	forceWeaponIndex = (this->ForceAAWeapon_Units >= 0 && pTarget->IsInAir())
		? this->ForceAAWeapon_Units
		: ((this->ForceWeapon_Naval >= 0 && pTargetType->Naval)
			? this->ForceWeapon_Naval
			: this->ForceWeapon_Units);

	break;
}

Naval=yes can not only be applied to unit, but also other type of techno. If we're changing it to this way I'm afraid it might be somehow misleading

Coronia avatar Jun 13 '25 07:06 Coronia

Naval=yes can not only be applied to unit, but also other type of techno. If we're changing it to this way I'm afraid it might be somehow misleading

In this case, I think it's necessary to further distinguish between vehicles and buildings that Naval=yes.

CrimRecya avatar Jun 13 '25 07:06 CrimRecya

I think after updating it, we can merge this. By the way, my opinion on ForceWeapon.Naval is probably like this, what do you think?

case AbstractType::Unit:
{
	forceWeaponIndex = (this->ForceAAWeapon_Units >= 0 && pTarget->IsInAir())
		? this->ForceAAWeapon_Units
		: ((this->ForceWeapon_Naval >= 0 && pTargetType->Naval)
			? this->ForceWeapon_Naval
			: this->ForceWeapon_Units);

	break;
}

Naval=yes can not only be applied to unit, but also other type of techno. If we're changing it to this way I'm afraid it might be somehow misleading

Since when is allowed in the code style of this project the concatenated inlined if? (I dont know if inlined is the right word in English for the "condition ? value1 : value2" )

FS-21 avatar Jun 25 '25 07:06 FS-21