Skip to content

Unit & infantry auto-conversion on ammo change #1653

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 11 commits into
base: develop
Choose a base branch
from

Conversation

FS-21
Copy link
Contributor

@FS-21 FS-21 commented May 5, 2025

  • Units/infantry can now be converted into another unit/infantry by ammo count.
  • Ammo.AutoConvertMinimumAmount determines the minimal number of ammo at which a unit converts automatically.
  • Ammo.AutoConvertMaximumAmount determines the maximum number of ammo at which a unit converts automatically.
  • Ammo.AutoConvertType specify the new techno after the conversion. This unit must be of the same type of the original (vehicle -> vehicle or infantry -> infantry).
  • Setting a negative number will disable ammo count check.

In rulesmd.ini:

[SOMETECHNO]                      ; InfantryType or VehicleType
Ammo.AutoConvertMinimumAmount=-1  ; integer
Ammo.AutoConvertMaximumAmount=-1  ; integer
Ammo.AutoConvertType=             ; InfantryType or VehicleType
  • Tested in online games.
  • This auto-conversion feature requires Ares.
  • Based / Inspired in Frione's work for "vehicle auto-deploy / deploy block on ammo change".

Copy link

github-actions bot commented May 5, 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

Coronia commented May 6, 2025

Think it's still better to batch these conditional conversion and AutoDeath in a same condition group, so it has the following benefits:

  • use same condition calculation logic, so more consistent
  • more conditions can be naturally supported by this system

see #1346

@TaranDahl
Copy link
Contributor

Two concerns:

  1. Why are the AircraftTypes excluded?
  2. The behavior of checking during the techno update does not match the description in the document (on ammo change). I think you should check it when the ammo changes or clarify the actual checking timing in the document.

@FS-21
Copy link
Contributor Author

FS-21 commented May 19, 2025

Two concerns:

  1. Why are the AircraftTypes excluded?
  2. The behavior of checking during the techno update does not match the description in the document (on ammo change). I think you should check it when the ammo changes or clarify the actual checking timing in the document.
  1. [SOMETECHNO] ; InfantryType or VehicleType <--- do you mean this in the docs? I never tested what happens in AircraftTypes but since it uses the Ares conversion logic is the same case of any aircraft (again, I never tested it on this kind of unit), only infantry & vehicles that was the initial scope of the feature (the additional types are welcome if they are supported without additional code changes).
  2. Probably docs confussion but I don't see too much the difference. Modders shouldn't know that the check process is during an internal check done every frame in every techno and is more clear that it happens after the ammo changed the value. Do you have any better idea for changing this text for clarifying the possible confussion?

@FS-21
Copy link
Contributor Author

FS-21 commented May 19, 2025

Think it's still better to batch these conditional conversion and AutoDeath in a same condition group, so it has the following benefits:

  • use same condition calculation logic, so more consistent
  • more conditions can be naturally supported by this system

see #1346

We can re-think the code after the merge into develop of #1346 but for now I need this feature for my mod and I share the current implementation :-D

@TaranDahl
Copy link
Contributor

Probably docs confussion but I don't see too much the difference. Modders shouldn't know that the check process is during an internal check done every frame in every techno and is more clear that it happens after the ammo changed the value. Do you have any better idea for changing this text for clarifying the possible confussion?

There is not much difference indeed. I think you just need to additionally explain the actual check process in the document.

@TaranDahl
Copy link
Contributor

[SOMETECHNO] ; InfantryType or VehicleType <--- do you mean this in the docs? I never tested what happens in AircraftTypes but since it uses the Ares conversion logic is the same case of any aircraft (again, I never tested it on this kind of unit), only infantry & vehicles that was the initial scope of the feature (the additional types are welcome if they are supported without additional code changes).

You don't need to worry about ConvertToType. If the conversion can not be processed, it will exit safely.

Copy link
Contributor

@TaranDahl TaranDahl left a comment

Choose a reason for hiding this comment

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

LGTM. Only one small concern.

const auto pFoot = abstract_cast<FootClass*>(pThis);
const auto pFoot = pThis && (pThis->AbstractFlags & AbstractFlags::Foot) ? static_cast<FootClass*>(pThis) : nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

const auto pFoot = abstract_cast<FootClass* , true >(pThis); is a method of using encapsulated functions, which can be directly used.

Copy link
Contributor Author

@FS-21 FS-21 May 30, 2025

Choose a reason for hiding this comment

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

But you are suggesting a code change or simply explaining a recommendation for future similar situations? is for going direct & closing the pending conversation :-P

Copy link
Contributor

@CrimRecya CrimRecya May 30, 2025

Choose a reason for hiding this comment

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

You don't need to do sanity check on pThis. You have already used pThis->Ammo and are even still using pThis->GetTechnoType(), it cannot be empty.
I explained for a while just to make you understand what the true in abstract_cast means.

Copy link
Contributor Author

@FS-21 FS-21 May 30, 2025

Choose a reason for hiding this comment

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

Ok now I understood, so I'll leave as
const auto pFoot = abstract_cast<FootClass*, true>(pThis);
because as you said pThis was already used and the last bit of information i wanted to know is if pThis is a FootClass object or something else for future things.

Copy link
Contributor

@CrimRecya CrimRecya May 30, 2025

Choose a reason for hiding this comment

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

if pThis is a FootClass object or something else for future things.

Sorry, I didn't understand what you meant. pThis is a TechnoClass pointer and the converted pFoot is a FootClass pointer. Unless it is not a Foot (such as a Building), they all point to the same entity.

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

Successfully merging this pull request may close these issues.

4 participants