Inspired by the great work that Flintlock has done with his C3X patch, I became intrigued with just how he manages to do this. I'm also really irritated by the barbarian NW/SE axis bug.
I thought I might try to investigate this particular bug as a learning exercise. Whether or not I manage to identify the location of this bug remains to be seen, but as long as I learn something along the way it won't matter so much.
This thread is for anyone that wants to follow my progress, learn or even participate in identifying this bug.
I am by no means an authority on this bug, Civ3 or programming making me totally ill-equipped to investigate this! Corrections to any statements I make, or ideas I have are warmly received.
What is the barbarian NW/SE axis bug?
The intended behaviour for barbarians as shipped with vanilla Civ3 is to 'check' a number of surrounding squares. If it 'sees' a non-barbarian unit within this range, it will pursue them as a matter of priority. If it can't 'see' any units the barbarian unit will fortify (if NoAIPatrol=1) or patrol randomly (if NoAIPatrol=0).
Details are sketchy, but at some point with the PTW expansion, a bug was introduced where instead of 'checking' all the surrounding squares, the barbarian would only 'check' the squares on the NW/SE axis.
This bug was corrected with a later PTW expansion patch. However, the bug resurfaced again with Conquests.
If I haven't covered off on any significant aspects of the bug above then please let me know!
There are two excellent threads I've found on this bug below:
https://forums.civfanatics.com/threads/fix-for-the-barbarians-sort-of.100704/
https://forums.civfanatics.com/threads/submarine-bug-investigation.526635/
In the second link above, Antal proposes that the AI calculates a 'net' of positions which, based on what I know, seems relevant to the barbarian NW/SE axis bug.
Flintlock and the C3X patch
For anyone who hasn't been following, Flintlock is doing some really incredible things, fixing bugs that have been present for two decades, and introducing wonderful QOL improvements into Civ3 with his C3X patch.
Check it out here:
https://forums.civfanatics.com/threads/sub-bug-fix-and-other-adventures-in-exe-modding.666881/
Want to follow along?
Flintlock has made the reverse engineering work he is doing on the Civ3 executable available on GitHub. You can find the link on page 21 of the thread above.
My own experience includes a little bit of visual basic programming and absolutely zilch in assembly programming!
I have since learned that the reverse engineering work disassembles the executable into assembly language. So I've had to start by reading up on assembly language.
Resources
I've found the below resources on assembly programming useful.
https://www.cs.virginia.edu/~evans/cs216/guides/x86.html
https://www.tutorialspoint.com/assembly_programming/index.htm
If anyone has got other resources that will be helpful, please share!
If there are any assembly language guru's out there, I'd appreciate any pointers on what to cover in order for me to try to begin working through the assembly code in Ghidra.
Going forward
So that's pretty much where I'm at. Life gets busy and I can never quite give these things the sort of time I would like to. I want to get through a little more reading on assembly, mostly around memory, stacks and how information is stored and transferred.
After that I'll try to start taking a closer look at trying to identify the logical functions where this bug might reside. If anyone wants to make a start, a couple of functions that look promising are:
I thought I might try to investigate this particular bug as a learning exercise. Whether or not I manage to identify the location of this bug remains to be seen, but as long as I learn something along the way it won't matter so much.
This thread is for anyone that wants to follow my progress, learn or even participate in identifying this bug.
I am by no means an authority on this bug, Civ3 or programming making me totally ill-equipped to investigate this! Corrections to any statements I make, or ideas I have are warmly received.
What is the barbarian NW/SE axis bug?
The intended behaviour for barbarians as shipped with vanilla Civ3 is to 'check' a number of surrounding squares. If it 'sees' a non-barbarian unit within this range, it will pursue them as a matter of priority. If it can't 'see' any units the barbarian unit will fortify (if NoAIPatrol=1) or patrol randomly (if NoAIPatrol=0).
Details are sketchy, but at some point with the PTW expansion, a bug was introduced where instead of 'checking' all the surrounding squares, the barbarian would only 'check' the squares on the NW/SE axis.
This bug was corrected with a later PTW expansion patch. However, the bug resurfaced again with Conquests.
If I haven't covered off on any significant aspects of the bug above then please let me know!
There are two excellent threads I've found on this bug below:
https://forums.civfanatics.com/threads/fix-for-the-barbarians-sort-of.100704/
https://forums.civfanatics.com/threads/submarine-bug-investigation.526635/
In the second link above, Antal proposes that the AI calculates a 'net' of positions which, based on what I know, seems relevant to the barbarian NW/SE axis bug.
Flintlock and the C3X patch
For anyone who hasn't been following, Flintlock is doing some really incredible things, fixing bugs that have been present for two decades, and introducing wonderful QOL improvements into Civ3 with his C3X patch.
Check it out here:
https://forums.civfanatics.com/threads/sub-bug-fix-and-other-adventures-in-exe-modding.666881/
Want to follow along?
Flintlock has made the reverse engineering work he is doing on the Civ3 executable available on GitHub. You can find the link on page 21 of the thread above.
My own experience includes a little bit of visual basic programming and absolutely zilch in assembly programming!
I have since learned that the reverse engineering work disassembles the executable into assembly language. So I've had to start by reading up on assembly language.
Resources
I've found the below resources on assembly programming useful.
https://www.cs.virginia.edu/~evans/cs216/guides/x86.html
https://www.tutorialspoint.com/assembly_programming/index.htm
If anyone has got other resources that will be helpful, please share!
If there are any assembly language guru's out there, I'd appreciate any pointers on what to cover in order for me to try to begin working through the assembly code in Ghidra.
Going forward
So that's pretty much where I'm at. Life gets busy and I can never quite give these things the sort of time I would like to. I want to get through a little more reading on assembly, mostly around memory, stacks and how information is stored and transferred.
After that I'll try to start taking a closer look at trying to identify the logical functions where this bug might reside. If anyone wants to make a start, a couple of functions that look promising are:
- ai_move_barbarian
- Trade_Net::get_movement_cost
- Trade_Net::set_unit_path