Skip to content

Comments

Unit:ForceReverseMove#116

Open
Strogoo wants to merge 1 commit intoFAForever:masterfrom
Strogoo:ReverseMove
Open

Unit:ForceReverseMove#116
Strogoo wants to merge 1 commit intoFAForever:masterfrom
Strogoo:ReverseMove

Conversation

@Strogoo
Copy link

@Strogoo Strogoo commented May 8, 2025

Added sim Unit:ForceReverseMove(true/false)

It affects both: new move command and already existed one. BUT if unit has a command already and moves forward, then there will be delay (~5-10 ticks) before it switches to reverse. That's because of movement function update rate.

So, if we want it to be instant (or at least as fast as possible) it's better to remove existed move order in simCallback, then Unit:ForceReverseMove(true) and then add new move command via sim function.

*Feel free to suggest different namings :)

Summary by CodeRabbit

  • New Features

    • Units can be toggled into a force-reverse movement mode via scripting.
  • Refactor

    • Movement logic hooks reorganized and padded to integrate reverse-move checks while preserving default behavior when disabled.
    • Entity variable handling adjusted to centralize boolean flags related to footprint and movement.

✏️ Tip: You can customize this high-level summary in your review settings.

@Garanas
Copy link
Member

Garanas commented May 8, 2025

What would the user interaction look like?

@Strogoo
Copy link
Author

Strogoo commented May 8, 2025

I was thinking about a hotkey. When hotkey is pressed and user issue a move order (RMB), we catch it and send data to some simCallback function. Then delete initial move order there, call ForceReverse, and issue new order similar to how we do it with distributing orders.

Also we have to strore units that were send to simCallback's function somewhere on UI side, so we know that they are "reversed" now. And next time when user issue normal move, and if some of selected units are in this "reversed" array, we send a callback to remove flag.

@GodFuper
Copy link

Do I understand correctly that this will be a "reverse gear", as implemented in COH2?
изображение
If so, then can come up with a similar hotkey and button.

@Strogoo
Copy link
Author

Strogoo commented May 10, 2025

@GodFuper Yeah, similar to COH2. I remember coh1 and it had same problem as we have now in FAF, when you are trying to retreat with your low hp tank and placing move order as close as possible to its back. Yeah, nostalgia hits hard :') good times...

Anyway, let's see how our Lua guys will implement this. Even simple hotkey with some indicator near cursor will be enough I think.

@coderabbitai
Copy link

coderabbitai bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

Consolidates a removed memory-write from EntityGetFootprint.hook into a new MohoEntityVariableData.hook mapping three boolean flags, and adds Unit force-reverse-move support via assembly hooks plus a C++ module exposing a Lua binding to toggle the flag.

Changes

Cohort / File(s) Summary
Hook refactoring
hooks/EntityGetFootprint.hook, hooks/MohoEntityVariableData.hook
Removed SSTIEntityVariableData block from EntityGetFootprint.hook (deleted the mov to [eax+0x0A4]); added MohoEntityVariableData.hook that performs mov dword ptr [eax+0x0A4], ecx to populate three booleans: forceAltFootprint, isForceReclaim, isForceReverseMove.
Unit force-reverse-move
hooks/UnitForceReverseMove.hook, section/UnitForceReverseMove.cpp
Added three assembly hook entry points at 0x005B34FB, 0x005B3566, 0x005B3578 routing to asm__UnitForceReverseCheck, asm__MovementTypeIDCheck, asm__BackUpDistanceCheck (with NOP padding). Added section/UnitForceReverseMove.cpp implementing those checks, a ForceReverseMove(lua_State*) function that writes the boolean to the unit offset, and a UnitMethodReg ForceReverseMoveReg binding exported to Lua.

Sequence Diagram

sequenceDiagram
    participant Lua as "Lua Script"
    participant Cpp as "ForceReverseMove() (C++)"
    participant Unit as "Unit Entity"
    participant Mem as "Memory [eax+0x0A4]"
    participant Asm as "Assembly Hooks"

    Lua->>Cpp: Call ForceReverseMove(unit, flag)
    Cpp->>Unit: Resolve unit pointer
    Cpp->>Mem: Write flag to [eax+0x0A4]
    Unit->>Asm: Movement logic executes
    Asm->>Mem: Read forceReverseMove flag
    alt flag == true
        Asm->>Asm: Jump to reverse-move path
    else
        Asm->>Asm: Continue default movement
    end
    Asm-->>Unit: Resume execution
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I nibble bytes and tuck a flag away,
A Lua whisper steers the unit's sway,
Assembly pivots, paths reverse and bend,
Tiny hops of code bring motion to end,
A rabbit claps for fixes small and gay 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description explains the feature and usage patterns, but omits several checklist items required by the template: no mention of moho.h/global.h/Info.txt updates, README.md changes, test instructions, or guide compliance. Address the checklist items: clarify which data structures were added to header files, describe README.md updates, and provide test instructions or hints for the new functionality.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Unit:ForceReverseMove' accurately describes the main change: adding a ForceReverseMove function to the Unit class.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@section/UnitForceReverseMove.cpp`:
- Around line 5-6: Fix the minor grammar in the top comment: change "goes" to
"go" in the sentence "Without this flag all movement calculations goes through
default route" so it reads "Without this flag all movement calculations go
through default route"; locate and edit the comment in UnitForceReverseMove.cpp
(the two-line header comment starting with "Any changes made here WILL NOT
affect units without ForceReverseMove flag") and update the wording only.
- Around line 36-38: Fix the typos in the comment block in
UnitForceReverseMove.cpp: change "randonly" to "randomly" and "notmal" to
"normal" in the comment that explains ForceReverseMove behavior (the comment
referencing ForceReverseMove mode and movementTypeID being 5); keep the rest of
the comment wording unchanged so the explanation about movementTypeID and
formation reverse move remains intact.
🧹 Nitpick comments (1)
hooks/UnitForceReverseMove.hook (1)

1-14: Consider ordering hook addresses sequentially for maintainability.

The hook addresses are defined out of order (0x005B34FB, 0x005B3578, 0x005B3566). Reordering them sequentially would improve readability when correlating with disassembly or debugging.

Suggested reordering
 0x005B34FB:
     jmp `@asm__UnitForceReverseCheck`
     nop
     nop
     nop
     nop

-0x005B3578:
-    jmp `@asm__BackUpDistanceCheck`
-    
 0x005B3566:
     jmp `@asm__MovementTypeIDCheck`
     nop
     nop
+
+0x005B3578:
+    jmp `@asm__BackUpDistanceCheck`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants