Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] (PR#12921) Clean up combat.c
Home

[Freeciv-Dev] (PR#12921) Clean up combat.c

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12921) Clean up combat.c
From: "James Canete" <use_less@xxxxxxxxxxx>
Date: Thu, 28 Apr 2005 02:50:19 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12921 >

I don't like the interface to the unit power functions in combat.c. 
Most of them are cryptically named and tell you nothing about which
power modifiers are being applied.

For instance, base_get_defense_power and get_defense_power().  By just
looking at those functions, you can't tell that base_get_defense_power()
includes veteran modifiers, and get_defense_power() includes veteran and
terrain modifiers, but no unit type modifiers.

Also, they are quite convoluted, calling each other to stack
multipliers.  This is quite ugly.

So, in this patch, I moved all of the power calculations into two (ugly)
functions named real_get_attack_power() and real_get_defense_power().  I
then made two more functions called get_unit_attack_power() and
get_unit_defense_power() to wrap the ugly functions.

In these functions, you specify a bit mask to select which modifiers you
want applied to the strength.  For instance, to replace
get_defense_power(), you would call get_unit_defense_power() with the
bitmask MOD_VETERAN | MOD_TERRAIN.

This patch is not complete; instead of going through all the code and
replacing the old calls, I made all the old functions wrappers for the
first four.  Also, there is a lot of redundancy in the four new
functions that should probably be cleared up.  And the functions
real_get_attack_power() and real_get_defense_power() aren't just ugly on
the inside, they also have a disgustingly large parameter list to cover
every single situation.  Also, needs comments.

I tested the patch out on an autogame and saves match with a clean CVS
checkout, but performance is most likely slower because of the wrappers
upon wrappers.

Thoughts?

-James Canete

Attachment: combat_cleanup-2.diff
Description: Binary data


[Prev in Thread] Current Thread [Next in Thread]