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

[Highly Customized] Optimize aircrafts actions #1366

Merged
merged 59 commits into from
Dec 28, 2024

Conversation

CrimRecya
Copy link
Contributor

@CrimRecya CrimRecya commented Aug 25, 2024

  • Now, when a stop command (S) is issued to an aircraft, the aircraft will immediately return to the airport. When a guard command (G) is issued, the aircraft will search for targets around the current location and return immediately when target is not found, target is destroyed or ammos are depleted (Note that if the target is destroyed but ammos are not depleted yet, it will also return because the aircraft's command is one-time). When a attack move command (Ctrl+Shift) is issued, the aircraft will move towards the destination and search for nearby targets on the route for attack. Once ammos are depleted or the destination is reached, it will return (Note that if the automatically selected target is destroyed but ammos are not depleted yet during the process, the aircraft will continue to go to the destination).

In rulesmd.ini:

[General]
ExpandAircraftMission=     ; boolean

@Coronia
Copy link
Contributor

Coronia commented Aug 25, 2024

suggest to make these guard behaviors compatible with GuardRange instead of always tying to weapon ranges, just like infantry and units did

@CrimRecya
Copy link
Contributor Author

suggest to make these guard behaviors compatible with GuardRange instead of always tying to weapon ranges, just like infantry and units did

Only the attack move action will use the weapon's range to reduce the range that search the valid target.

Copy link

github-actions bot commented Sep 16, 2024

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.

src/Ext/Aircraft/Hooks.cpp Outdated Show resolved Hide resolved
src/Ext/Aircraft/Hooks.cpp Outdated Show resolved Hide resolved
src/Ext/Aircraft/Hooks.cpp Outdated Show resolved Hide resolved
src/Ext/Aircraft/Hooks.cpp Outdated Show resolved Hide resolved
src/Ext/Aircraft/Hooks.cpp Outdated Show resolved Hide resolved
src/Ext/Aircraft/Hooks.cpp Outdated Show resolved Hide resolved
@CrimRecya
Copy link
Contributor Author

TechnoClass
unknown_bool_418 -> bool IsTether
unknown_bool_419 -> bool IsAlternativeTether

FootClass
unknown_5A0 -> AbstractClass* Follow
unknown_int_5C4 -> Mission MegaMission
unknown_5C8 -> AbstractClass* MegaDestination
unknown_5CC -> AbstractClass* MegaTarget
unknown_bool_5D1 -> bool HaveAttackMoveTarget

TechnoClass_vtbl
bool TargetAndEstimateDamage(DWORD dwUnk, DWORD dwUnk2) -> bool TargetAndEstimateDamage(CoordStruct* pSelectCrd, TargetFlags targetFlags)
CellClass* SelectAutoTarget(TargetFlags TargetFlags, int CurrentThreat, bool OnlyTargetHouseEnemy) -> AbstractClass* SelectAutoTarget(TargetFlags targetFlags, CoordStruct* pSelectCrd, bool onlyTargetHouseEnemy)

vt_entry_3B4 -> bool InAuxiliarySearchRange(AbstractClass* pTarget)
vt_entry_3E8 -> int GetSecondaryWeaponIndex()
vt_entry_47C -> void SetFollowTarget(AbstractClass* pFollow)
vt_entry_4A4 -> Mission RespondMegaEventMission(EventClass* pRespondTo)
vt_entry_4A8 -> void ClearMegaMissionData()
vt_entry_4AC -> bool HaveMegaMission()
vt_entry_4B0 -> bool HaveAttackMoveTarget()
vt_entry_4B4 -> Mission GetMegaMission()
vt_entry_4B8 -> CoordStruct* GetAttackMoveCoords(CoordStruct* pBuffer)
vt_entry_4C4 -> bool MegaMissionIsAttackMove()
vt_entry_4C8 -> bool ContinueMegaMission()
vt_entry_4CC -> void UpdateAttackMove()
vt_entry_4D0 -> bool RefreshMegaMission()

@CrimRecya
Copy link
Contributor Author

I modified the above content and merged the branch #1449.
But I don't know how to pull request for YRpp. Should I create a branch in YRpp or just the same from Phobos?

@CrimRecya CrimRecya changed the title Optimize aircrafts actions [Highly Customized] Optimize aircrafts actions Dec 26, 2024
@Metadorius
Copy link
Member

Metadorius commented Dec 26, 2024

I modified the above content and merged the branch #1449.
But I don't know how to pull request for YRpp. Should I create a branch in YRpp or just the same from Phobos?

To do that you have to create a branch in YRpp, then you can push it and submit a pull request to YRpp repository.

When you cloned Phobos recursively - you also cloned YRpp as a submodule. Basically submodules are just nested repositories. You can open it like any other repository, so the changes can be synchronized to Phobos and you don't need to rename stuff by hand.

What I suggest to do is: in Visual Studio (regular or Code) rename fields and functions using Rename... feature ([F2] by default), then you will have two "levels" of changes displayed in your Git client:

  • for Phobos repository - changes in the Phobos code (as regular changes) and changes to YRpp (as one submodule change)
  • for YRpp repository - changes to the field names and function names in YRpp as regular changes.

At this point you have to create a branch in YRpp repository (create a fork of it if you didn't yet), commit and push the changes and submit it as a pull request. After pushing it you have two options in Phobos repository:

  • wait until it's accepted, checkout YRpp at the newest commit, then commit and push - this will save you having to commit and push multiple times, but you won't be able to get a nightly build for people to test;
  • don't wait for YRpp changes to be merged, commit and push right after you pushed the YRpp changes to your YRpp branch - you will have an up-to-date build on Phobos pull request this way. Note that you must do it only after you committed to and pushed your YRpp branch, otherwise the build system won't know what are the changes as they are not exposed to the world, only available to you locally.

After the YRpp pull request gets accepted you will need to switch to the latest commit that was merged (you do that in the submodule), verify that it compiles like normal, and then commit and push it to your Phobos branch that you made for the pull request.

Copy link
Member

@Metadorius Metadorius left a comment

Choose a reason for hiding this comment

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

It all looks good to me except one thing. I also took the liberty of helping you out with documentation. Please review the changes and the question and let's get this merged.

@Metadorius Metadorius requested a review from ZivDero December 27, 2024 22:41
@Metadorius
Copy link
Member

Metadorius commented Dec 27, 2024

It seems I am not able to push to this branch. Could you please enable "Allow edits by maintainers" on your pull requests so we can submit improvements without creating additional pull requests? I will push my doc/spelling improvements then.

@CrimRecya
Copy link
Contributor Author

It seems I am not able to push to this branch. Could you please enable "Allow edits by maintainers" on your pull requests so we can submit improvements without creating additional pull requests? I will push my doc/spelling improvements then.

It seems that Allow edits and access to secrets by maintainers is always on. I turned it off and then on again. You can try again.

@Metadorius
Copy link
Member

I think there's some configuration that prevents me from directly pushing. I have submitted a PR: CrimRecya#2

Doc and spelling/style improvements
@CrimRecya
Copy link
Contributor Author

I think there's some configuration that prevents me from directly pushing. I have submitted a PR: CrimRecya#2

Thank you for your correction. I have merged it.

@Metadorius Metadorius merged commit 7090604 into Phobos-developers:develop Dec 28, 2024
6 checks passed
@chaserli
Copy link
Contributor

Excuse me for being unable to test when it was a PR, but it seems an aircraft still has some trouble proceeding to the next planning waypoint. For example it will try to contact the airport first. Is this intended?

@CrimRecya
Copy link
Contributor Author

CrimRecya commented Dec 29, 2024

Excuse me for being unable to test when it was a PR, but it seems an aircraft still has some trouble proceeding to the next planning waypoint. For example it will try to contact the airport first. Is this intended?

No, judging from the mission of the aircraft, there will be 1-2 frames trying to contact the airport before entering the next planning waypoint, but this should not prevent it from continuing to the next waypoint. Is this the problem caused by the aircraft ammunition upper limit is greater than (not equal to) 2 and its ammo is not 0 but less than (not equal to) half of the upper limit?

@chaserli
Copy link
Contributor

I don't have much clue either. I once tried avoiding it via flyloco methods such as 4CFA70, but it no longer works with your code here.

if (distance > std::max((pType->SlowdownDistance >> 1), (2048 / pType->ROT)))
return (R->Origin() == 0x4168C7 ? ContinueMoving1 : ContinueMoving2);

pThis->EnterIdleMode(false, true);
Copy link
Contributor

@chaserli chaserli Dec 29, 2024

Choose a reason for hiding this comment

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

For example an easy but nasty way to "avoid" this is to add remaining waypoints check before enteridlemode. But it's probably not correct.

Copy link
Contributor Author

@CrimRecya CrimRecya Dec 29, 2024

Choose a reason for hiding this comment

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

Normally bool __thiscall EnterIdleMode(TechnoClass *this, bool construction, bool nextPlanningPath) should have handled the next waypoint, but I don't understand why it didn't take effect. I'll check it carefully.

@CrimRecya
Copy link
Contributor Author

I don't have much clue either. I once tried avoiding it via flyloco methods such as 4CFA70, but it no longer works with your code here.

At present, the return purpose of one or two frames is not a big problem, at least they will continue to the next waypoint. One more thing, ww hard coded that the aircraft cannot move directly to the water surface, which is also a problem. But anyway, I will try to solve these two problems and submit a new fix later.

@CrimRecya
Copy link
Contributor Author

I don't have much clue either. I once tried avoiding it via flyloco methods such as 4CFA70, but it no longer works with your code here.

At present, the return purpose of one or two frames is not a big problem, at least they will continue to the next waypoint. One more thing, ww hard coded that the aircraft cannot move directly to the water surface, which is also a problem. But anyway, I will try to solve these two problems and submit a new fix later.

I fixed these two problems in #1484. Please check them in your own time.

Metadorius added a commit that referenced this pull request Jan 12, 2025
1. Fix aircrafts planning waypoint problem - At the end of each task,
all units with planning waypoints will generate an mega event to the
next planning waypoint and respond after 1 frame. This is really no
problem for most units, but for aircrafts, they will always return to
the airport after each task. So they will try to return to the airport
in the frame before it respond to event. There will be looked like a
"shaking", if the `Speed` and `ROT` of the aircraft are fast. To solve
this problem, I check the waypoints of aircrafts and let them wait
before returning.
2. Fix a vanilla issue - Now aircrafts can fly towards the water surface
normally.

---------

Co-authored-by: Kerbiter <crabiter@vivaldi.net>
@CrimRecya CrimRecya deleted the develop-aircraft branch January 17, 2025 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants