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

Code(feat) fighter ai #17

Draft
wants to merge 20 commits into
base: experimental
Choose a base branch
from

Conversation

Zitchas
Copy link
Member

@Zitchas Zitchas commented Apr 20, 2023

Feature: This PR implements the RearAttack pattern for high speed ships as detailed in Revamp

Feature Details

This is an attack pattern aimed primarily at fighters, causing them to preferentially circle the target ship and focus on attacking the rear of it, thus keeping them out of the line of fire of any guns it might have.

It's not actually working yet, although it does build. I've been testing it with a job that spawns a vanguard with 3x the mass (thus slowing down its turning) and a pack of Terns to attack it (which have 3x the normal engines and their hull reduced to 0 mass, thus they move very fast)

@Zitchas Zitchas added the enhancement New feature or request label Apr 20, 2023
Testing swizzles are using the finchtest ship sprite, which has lots of extra orange painted on it.

cloaking red if in front
default 0 if atSide
salmon if notbehind
blue if behind but too far away
purplish if behind but too close
neon green if behind and in range
pink is all else
@Zitchas
Copy link
Member Author

Zitchas commented Apr 21, 2023

https://youtu.be/tB5eZiIUNOc
This is a short clip of a flight of test fighters attacking a test vanguard. The vanguard has +1000 mass compared to normal, and the fighters are actually terns whose anvil engines provide about 5x more thrust than usual. They also have double the drag to keep their top speed from getting too big. They are using a modified finch sprite with large swaths of orange painted onto it to make the swizzle changes extremely obvious. The code for the Rear Attack routine has a bunch of swizzle changes programmed into it so that we can see what part of the code they are in as they move around. Note, none of the terns have cloaks, so when they turn cloaking red they're just denoting that they are in the "in front" part of the code.

cloaking red if in front
orange if atSide
salmon if notbehind
blue if behind but too far away
purplish if behind but too close
neon green if behind and in range
pink is all else

@Zitchas
Copy link
Member Author

Zitchas commented Apr 25, 2023

Tried something new, and actually kind of got the desired behavior. Not entirely sure why it's working, but it is fairly consistent for the test job.

https://youtu.be/oxMLOLVIS8A

@1010todd 1010todd mentioned this pull request Apr 26, 2023
Copy link
Member

@RisingLeaf RisingLeaf left a comment

Choose a reason for hiding this comment

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

Are you going to use these variables?

{
int weaponsRange = 370; // attacker weapon range this will be passed in eventually
int targetTurretRange = target.GetAICache().TurretRange();
Point offset = target.Position() - target.Facing().Unit() * weaponsRange;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Point offset = target.Position() - target.Facing().Unit() * weaponsRange;

Point southEastUnit(southUnit.X() + eastUnit.X(), southUnit.Y() + eastUnit.Y());
Point southEast = (target.Position() + southEastUnit * targetTurretRange / 1.41);

Point frontAvoid = (direction.Cross(ship.Facing().Unit()) < 0. ? northWest : northEast);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Point frontAvoid = (direction.Cross(ship.Facing().Unit()) < 0. ? northWest : northEast);

Point southEast = (target.Position() + southEastUnit * targetTurretRange / 1.41);

Point frontAvoid = (direction.Cross(ship.Facing().Unit()) < 0. ? northWest : northEast);
Point rearAvoid = (direction.Cross(target.Facing().Unit()) > 0. ? southWest : southEast);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Point rearAvoid = (direction.Cross(target.Facing().Unit()) > 0. ? southWest : southEast);

Point rearAvoid = (direction.Cross(target.Facing().Unit()) > 0. ? southWest : southEast);

bool isBehind = direction.Unit().Dot(target.Facing().Unit()) < -.90;
bool justLeft = direction.Unit().Dot(target.Facing().Unit()) < -.8 && direction.Cross(target.Facing().Unit()) > 0;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bool justLeft = direction.Unit().Dot(target.Facing().Unit()) < -.8 && direction.Cross(target.Facing().Unit()) > 0;


bool isBehind = direction.Unit().Dot(target.Facing().Unit()) < -.90;
bool justLeft = direction.Unit().Dot(target.Facing().Unit()) < -.8 && direction.Cross(target.Facing().Unit()) > 0;
bool justRight = direction.Unit().Dot(target.Facing().Unit()) < -.8 && direction.Cross(target.Facing().Unit()) <= 0;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bool justRight = direction.Unit().Dot(target.Facing().Unit()) < -.8 && direction.Cross(target.Facing().Unit()) <= 0;

bool justRight = direction.Unit().Dot(target.Facing().Unit()) < -.8 && direction.Cross(target.Facing().Unit()) <= 0;
bool inFront = direction.Unit().Dot(target.Facing().Unit()) > .75;

bool atSide = (!inFront && !isBehind);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bool atSide = (!inFront && !isBehind);

bool tooClose = direction.Length() < weaponsRange * .9;
bool outerRadius = direction.Length() < weaponsRange * 2;
double reverseSpeed = ship.MaxReverseVelocity();
double speed = ship.MaxVelocity();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
double speed = ship.MaxVelocity();

@Zitchas
Copy link
Member Author

Zitchas commented Apr 27, 2023

I don't know. Obviously they aren't being used right now, but they were used in VitalChip's original code to achieve more (and better) functionality than I am getting now. I've left them in for now because they might help me get to that better level. That being said, my brain's a bit fuzzy right now, so not sure when I'll be continuing work on this.

@Zitchas Zitchas marked this pull request as draft April 29, 2023 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants