[Patch] Refactor AutoResolveCombat

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

[Patch] Refactor AutoResolveCombat

#1 Post by Mitten.O »

In CombatSystem.cpp, AutoResolveCombat was basically one huge function.

I added a new struct, AutoresolveInfo to package some of the information
floating around and split AutoResolveCombat into smaller functions in other ways.

I tried to stay close to the original code, so it still isn't very pretty,
but it should be considerably better than before.
All the logic should be entirely intact.

Since there is no change in functionality, the benefit of this patch is somewhat subjective,
but I think it would be hard to argue that AutoResolveCombat was nice as it was.
Nonetheless, changes like this benefit especially from discussion,
so comment away.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Any code by me in this post is released under GPL 2.0 or later.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [Patch] Refactor AutoResolveCombat

#2 Post by Geoff the Medio »

Looks generally OK, other than minor formatting nitpicks. Am not able to test immediately, though, and haven't look through everything carefully... but breaking the combat processing into smaller functions should be fine in principle.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [Patch] Refactor AutoResolveCombat

#3 Post by Geoff the Medio »

Combat seems to run OK, after a few early game simple tests. More thorough tests and reports would be useful, though.

Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

Re: [Patch] Refactor AutoResolveCombat

#4 Post by Mitten.O »

Some for loops had their ending braces indented, which threw off my indentation.
Fixed that and a few other possible formatting nitpicks.

Some sort of automated testing sure would make it easier to
do this large refactorings confidently.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Any code by me in this post is released under GPL 2.0 or later.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [Patch] Refactor AutoResolveCombat

#5 Post by Geoff the Medio »

There have been several discussions on the subject, and a few aborted attempts at, automated testing / unit tests. You might want to search the forums...?

Edit: applies and builds OK

Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

Re: [Patch] Refactor AutoResolveCombat

#6 Post by Mitten.O »

I played a game for a couple hundred turns with this patch
and didn't notice anything off with the results of battle.
I did feel like I got one battle report a turn too early,
but was probably just confused by a similarly named system.

I was even ambushed by stealthy space monsters I couldn't see
(which was cool), and the "you can hit them after they hit you"
logic seemed to work.

I of course don't have a very fine tuned feel of how the battles
are meant to go, so this experience does not weight that much.
Any code by me in this post is released under GPL 2.0 or later.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [Patch] Refactor AutoResolveCombat

#7 Post by Geoff the Medio »

I've committed the patch. Can be reverted if more testing reveals problems.

Post Reply