Skip to content
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

Let AI engulf even if running out of atp #5729

Merged

Conversation

Patryk26g
Copy link
Contributor

@Patryk26g Patryk26g commented Dec 5, 2024

Brief Description of What This PR Does

If there is a microbe nearby and the cell is not moving make it able to engulf the prey in order to survive

Related Issues

closes #5678

Progress Checklist

Note: before starting this checklist the PR should be marked as non-draft.

  • PR author has checked that this PR works as intended and doesn't
    break existing features:
    https://wiki.revolutionarygamesstudio.com/wiki/Testing_Checklist
    (this is important as to not waste the time of Thrive team
    members reviewing this PR)
  • Initial code review passed (this and further items should not be checked by the PR author)
  • Functionality is confirmed working by another person (see above checklist link)
  • Final code review is passed and code conforms to the
    styleguide.

Before merging all CI jobs should finish on this PR without errors, if
there are automatically detected style issues they should be fixed by
the PR author. Merging must follow our
styleguide.

@hhyyrylainen
Copy link
Member

This is for the AI, right? That's unclear from just the title (so I had to open up this PR immediately when I received the notification to make sure this wasn't a fix for a critical regression in the game).

@hhyyrylainen hhyyrylainen added this to the Release 0.8.0 milestone Dec 5, 2024
@hhyyrylainen hhyyrylainen requested review from a team December 5, 2024 19:56
@Patryk26g
Copy link
Contributor Author

This is for the AI, right? That's unclear from just the title (so I had to open up this PR immediately when I received the notification to make sure this wasn't a fix for a critical regression in the game).

Yes it is, sorry for not being clear

@Patryk26g Patryk26g changed the title Engulf even if running out of atp Let AI engulf even if running out of atp Dec 5, 2024
@HexapodPhilosopher
Copy link
Contributor

From testing this today, the AI still doesn't engulf while out of ATP.

@Patryk26g
Copy link
Contributor Author

From testing this today, the AI still doesn't engulf while out of ATP.

It should work now, the "if statement" was built improperly

Copy link
Member

@hhyyrylainen hhyyrylainen left a comment

Choose a reason for hiding this comment

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

I'm not seeing any references to EnterEngulfModeForcedState so how does this actually force the engulf mode?

@Patryk26g
Copy link
Contributor Author

Well, tried rebasing onto master but it seems to mess up my branch again

@Patryk26g Patryk26g marked this pull request as draft December 12, 2024 18:44
@hhyyrylainen
Copy link
Member

hhyyrylainen commented Dec 12, 2024

Probably easiest if you just start a new fresh local branch and either cherry-pick the commits you want from here or just redo the changes manually. Then delete your local branch named engulfEvenIfOutOfAtp and make that branch again but starting from that new fix branch, then force push to overwrite all commits here.

Edit: also I wanted to mention that usually when duplicate commits get created like that you've either messed up a merge (with losing the info that the branch is actually merged) or an interactive rebase ended up rebasing remote commits (this is pretty easy to accidentally do if you do an interactive rebase onto a different branch and you have merge commits made in your branch, it's better to either rebase or squash first).

@Patryk26g Patryk26g force-pushed the engulfEvenIfOutOfAtp branch from 1d8f921 to fecacc8 Compare December 13, 2024 12:00
@Patryk26g Patryk26g marked this pull request as ready for review December 13, 2024 12:06
@hhyyrylainen hhyyrylainen removed this from the Release 0.8.0 milestone Dec 20, 2024
@hhyyrylainen hhyyrylainen added this to the Release 0.8.1 milestone Dec 20, 2024
@revolutionary-bot
Copy link

We are currently in feature freeze until the next release.
If your PR is not just a simple fix, then it may take until the release to get reviewed and merged.

Copy link
Member

@dligr dligr left a comment

Choose a reason for hiding this comment

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

I have noticed some issues with the code, but the main functionality seems to work based on my testing

src/microbe_stage/systems/MicrobeAISystem.cs Outdated Show resolved Hide resolved
@hhyyrylainen
Copy link
Member

but the main functionality seems to work based on my testing

How? I'm sorry that I'm commenting while on my break but I've read this PR like twice but I didn't see anything that could set the forced engulfing time variable above 0? So that means that there should be no way for this PR to trigger that functionality (refer to my comment: #5729 (review))

control.SetStateColonyAware(entity, engulf ? MicrobeState.Engulf : MicrobeState.Normal);
var ourCompounds = compoundStorage.Compounds;

if (atpLevel <= Constants.ENGULF_NO_ATP_TRIGGER_THRESHOLD)
Copy link
Member

Choose a reason for hiding this comment

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

I see the EnterEngulfModeForcedState call now, but now I'm wondering why the ATP level is checked here? Because EnterEngulfModeForcedState ultimately calls ForceStateApplyIfRequired which only causes problems if ATP is not sufficient, so the AI code doesn't actually need this duplicate check, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we just use EnterEngulfModeForcedState withour SetStateColonyAware?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I didn't fully read the PR again but from a quick look EnterEngulfModeForcedState already has colony handling and checking for the ATP levels. So my comment is just about reducing unnecessary code in the AI system in this spot.

Copy link
Member

@hhyyrylainen hhyyrylainen left a comment

Choose a reason for hiding this comment

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

There's just a small change I'd like to see to make this conform to our styleguide. Then if the AI works fine in game this will be ready to merge.

src/microbe_stage/systems/MicrobeAISystem.cs Show resolved Hide resolved
bool isHunting = CheckForHuntingConditions(ref ai, ref position, ref organelles, ref ourSpecies, ref engulfer,
ref cellProperties, ref control, ref health, ref compoundStorage, entity, speciesFocus, speciesAggression,
speciesActivity, speciesOpportunism, strain, random, false, atpLevel);
if (isHunting)
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be cleaner to not split out the isHunting variable here? There's already a very similar block of code above that doesn't use a temporary variable. (will also need to add braces here as the if is then so long)

{
// Keep the maximum at 95% full, as there is flickering when near full
ai.ATPThreshold = 0.95f * speciesFocus / Constants.MAX_SPECIES_FOCUS;
}

// Even if we are out of ATP and there is microbe nearby, engulf them.
// make sure engulfing doesn't kill the cell. The cell won't engulf if it would kill it
Copy link
Member

Choose a reason for hiding this comment

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

I think this comment line is pretty unclear and either should be removed or reworded.

@hhyyrylainen
Copy link
Member

Other than that one hard to read comment, the code changes look good to me here. And as long as the AI does actually sometimes use this new functionality, this will be good to merge.

Copy link
Member

@hhyyrylainen hhyyrylainen left a comment

Choose a reason for hiding this comment

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

I'll trust that there's been enough playtesting to merge this.

@hhyyrylainen hhyyrylainen merged commit 5cb19a9 into Revolutionary-Games:master Feb 3, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Microbe AI should be able to use the enter engulf mode at the cost of health without ATP
6 participants