Skip to content

Fix AI team recruitment inconsistency causing underfilled teams#2172

Open
handama wants to merge 11 commits intoPhobos-developers:developfrom
handama:bugfix-teamRecruitment
Open

Fix AI team recruitment inconsistency causing underfilled teams#2172
handama wants to merge 11 commits intoPhobos-developers:developfrom
handama:bugfix-teamRecruitment

Conversation

@handama
Copy link
Copy Markdown
Contributor

@handama handama commented Apr 15, 2026

In certain situations, the AI incorrectly assumes that some units on the map are recruitable when forming a team, leading to teams that can never reach full strength. For example, when there are 3 GI on the map with recruitable flags (RecruitableA, RecruitableB) set to 1,1; 1,0; and 0,0, and an AI team with Autocreate enabled is created via trigger action 4 (Create Team), only the units with 1,1 should be considered recruitable, and the AI should produce 2 additional GIs to fill the team. However, during production planning (0x4DA230), the AI incorrectly treats units with 1,0 or 0,0 as recruitable and therefore only produces 1 GI. During actual recruitment (0x6EA610), these GIs are skipped due to stricter conditions, leaving the team permanently underfilled. Notably, if the intermediate GI (1,0) is destroyed, the AI will then correctly produce the missing GI and the team can finally form.
Snipaste_2026-04-15_15-12-31
testmap.zip

This PR addresses it by modifying 0x4DA230 so that its conditions match those of 0x6EA610 as closely as possible to avoid such inconsistencies.

@phoboscn-bot
Copy link
Copy Markdown

To Chinese users:
This pull request has been mentioned on Phobos CN. There might be relevant details there:

致中文用户:
此拉取请求已在 Phobos CN 上被提及。那里可能有相关详细信息:

https://www.phoboscn.top/t/topic/358/11

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 15, 2026

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
Copy Markdown
Contributor

Coronia commented Apr 15, 2026

as far as I know, if Recruitable A and B are both set to 0, the unit will not be considered as occupying a team member. AI will still skip it when recruiting a team and build sufficient units instead

Making it as 1,0 is indeed problematic but maybe a toggle is needed for this fix, since it'll alter the AI behaviors of existing missions, making their AI unintentionally stronger

@handama
Copy link
Copy Markdown
Contributor Author

handama commented Apr 15, 2026

as far as I know, if Recruitable A and B are both set to 0, the unit will not be considered as occupying a team member. AI will still skip it when recruiting a team and build sufficient units instead

Making it as 1,0 is indeed problematic but maybe a toggle is needed for this fix, since it'll alter the AI behaviors of existing missions, making their AI unintentionally stronger

I understand the concern about potentially affecting AI strength, but I don’t think a toggle is necessary here. This change mainly fixes a case which is more of a bug than intended behavior. The situations where this occurs should also be relatively limited, so the overall impact on existing missions is likely small. What do you think?

@DeathFishAtEase DeathFishAtEase added ❓Vanilla bug Vanilla game bugs that are requested to be fixed Needs testing ⚙️T1 T1 maintainer review is sufficient labels Apr 15, 2026
Copy link
Copy Markdown
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.

The code looks good to me.
I have a shallow understanding of the Team system. So I think I am not qualified for judging the design aspect.

Comment thread src/Ext/Techno/Body.cpp Outdated
@TaranDahl
Copy link
Copy Markdown
Contributor

@Metadorius @Starkku @ZivDero can anyone help judging the design concept?

@DeathFishAtEase
Copy link
Copy Markdown
Collaborator

Tested by: https://www.phoboscn.top/t/topic/361/9
image

@TaranDahl
Copy link
Copy Markdown
Contributor

Given that no one is willing to make further comments, this PR will be merged in 24 hours.

@TaranDahl TaranDahl added the Will be merged in 24h This PR will be merged in 24 hours if no one has further instructions. label May 5, 2026
@DeathFishAtEase
Copy link
Copy Markdown
Collaborator

DeathFishAtEase commented May 5, 2026

Strange, ef120cd is just a documentation change (resolve merge conflicts), but Nightly failed to build successfully. However, when I pull the branch of that PR locally for testing, it builds successfully.

error C1083: Cannot open include file: 'atlbase.h': No such file or directory [D:\a\Phobos\Phobos\Phobos.vcxproj]

@DeathFishAtEase DeathFishAtEase force-pushed the bugfix-teamRecruitment branch from f34ef4d to cdbe08d Compare May 5, 2026 14:39
@TaranDahl
Copy link
Copy Markdown
Contributor

Could it possibly be this one that's causing the problem?
055cdc2

@DeathFishAtEase DeathFishAtEase force-pushed the bugfix-teamRecruitment branch from cdbe08d to f34ef4d Compare May 5, 2026 15:17
@DeathFishAtEase
Copy link
Copy Markdown
Collaborator

DeathFishAtEase commented May 5, 2026

Could it possibly be this one that's causing the problem? 055cdc2

Not that one. I also suspected this, so I tested in another repository. The result was that whether or not Revert that commit, the build succeeded. I even reset the FreeWindor:develop branch of that repository to be exactly the same as Phobos-developers:develop (without Revert or Reapply) for testing, but the build also succeeded.

Additionally, that 055cdc2 had already been merged into the develop branch during the last synchronization (dea4751), and at that time it did not cause any problems.

After further testing, it was found that as long as the synchronization target of the branch where this PR is located is set to commit 0b21108 and later commits, this abnormal behavior will occur, but the cause is not clear.

@DeathFishAtEase DeathFishAtEase force-pushed the bugfix-teamRecruitment branch from f34ef4d to dea4751 Compare May 5, 2026 15:37
@DeathFishAtEase DeathFishAtEase force-pushed the bugfix-teamRecruitment branch 3 times, most recently from b057271 to 1da520d Compare May 5, 2026 15:48
@TaranDahl
Copy link
Copy Markdown
Contributor

@Metadorius Help

@DeathFishAtEase DeathFishAtEase force-pushed the bugfix-teamRecruitment branch 2 times, most recently from 42e9952 to f34ef4d Compare May 5, 2026 15:58
@DeathFishAtEase
Copy link
Copy Markdown
Collaborator

The branch has been restored to the state before a series of tests were conducted, waiting for others to handle it.

Copy link
Copy Markdown
Contributor

@Starkku Starkku left a comment

Choose a reason for hiding this comment

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

After review, investigation and some research it appears this PR addresses a real inconsistency and correctly fixes the problem - adjusting the recruitment-stage check to require both recruitment flags (which as an aside could be renamed in YRpp to better match their actual purpose, A is for Autocreate=false teams and B for true ones) to be set to true produces no false-positive results for Autocreate=true teams and has no impact on Autocreate=false teams which didn't have this issue to begin with.

Although I am unsure how the both flags set to false case return true from 0x4DA230 when the only code path in it that can requires RecruitableA to be set to true.

Aside from that I have some nitpicks.

Comment thread src/Ext/Techno/Body.cpp Outdated
Comment thread src/Ext/Techno/Body.cpp Outdated
Copy link
Copy Markdown
Contributor

@Starkku Starkku left a comment

Choose a reason for hiding this comment

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

Single row if statements (the condition is on single row) don't need the curly braces per project code style specs and omitting them is usually cleaner but them being there isn't a problem. LGTM I guess.

Although I am unsure how the both flags set to false case return true from 0x4DA230 when the only code path in it that can requires RecruitableA to be set to true.

If someone is able to enlighten me on how this happened though it would be nice for understanding this part of the game better.

@handama
Copy link
Copy Markdown
Contributor Author

handama commented May 5, 2026

Single row if statements (the condition is on single row) don't need the curly braces per project code style specs and omitting them is usually cleaner but them being there isn't a problem. LGTM I guess.

Although I am unsure how the both flags set to false case return true from 0x4DA230 when the only code path in it that can requires RecruitableA to be set to true.

If someone is able to enlighten me on how this happened though it would be nice for understanding this part of the game better.

My mistake. The issue only occurs in the 1,0 case. I didn’t thoroughly double-check during the translation.

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 ❓Vanilla bug Vanilla game bugs that are requested to be fixed Will be merged in 24h This PR will be merged in 24 hours if no one has further instructions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants