[freeciv-ai] (PR#3584) Renaming vulnerability/belligerence
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
> Editing:
> ========
> 1. unit_vulnerability_virtual must be multiplied by firepower!
> 2. Remove alternativ_hp from unit_vulnerability_virtual2
> (not used).
>
>
> More renaming:
> ==============
> 1. unit_vulnerability_virtual2
> -> unittype_def_rating_sq
> 2. unit_vulnerability_virtual
> -> unit_def_rating_basic_sq
> 3. unit_vulnerability_basic
> -> unit_def_rating
> 4. unit_vulnerability
> -> unit_def_rating_sq
>
>
> Add:
> ====
> 1. unit_def_rating_basic and make
> unit_def_rating_basic_sq it's square.
All this in one bunch, so if this is committed, the case will
be closed.
I defined diff to be text/plain in Netscape, but let's see if
it helps in this upload.
Note that in aiunit.c I moved a function to more logical position
and diff shows it quite obscurely, of course. It may be easiest
to run the patch and then view the def_rating area.
Also take a close scrutiny at this time. Especially that
firepower in unit_def_rating_basic is what Greg meant.
I used unittype_def_rating_sq as a model, but if taken
literally, Greg said that current unit_def_rating_basic_sq
should be multiplied. Now unit_def_rating_basic_sq gets
multiplied with firepower twice.
Also I have a feeling that there could be cleaner expressions
than unit_types[def_type].firepower and such, so please tell
me if I should think these over.
--
Juhani Heino
Finnish translator
--- ai/aiair.c.orig Thu May 8 20:59:50 2003
+++ ai/aiair.c Thu May 8 23:16:16 2003
@@ -126,7 +126,7 @@
* unit_win_chance(punit, pdefender));
/* Defence value of the enemy
- victim_defence = unit_vulnerability_basic(punit, pdefender) / 10; */
+ victim_defence = unit_def_rating(punit, pdefender) / 10; */
victim_defence = PROB_MULTIPLIER - unit_attack;
balanced_cost = build_cost_balanced(punit->type);
--- ai/advmilitary.c.orig Thu May 8 21:00:48 2003
+++ ai/advmilitary.c Thu May 8 23:13:51 2003
@@ -811,8 +811,8 @@
/* Estimate strength of the enemy. */
- vuln = unit_vulnerability_virtual2(unit_type, victim_unit_type, x, y,
- FALSE, veteran, FALSE, 0);
+ vuln = unittype_def_rating_sq(unit_type, victim_unit_type,
+ x, y, FALSE, veteran);
/* Not bothering to s/!vuln/!pdef/ here for the time being. -- Syela
* (this is noted elsewhere as terrible bug making warships yoyoing)
@@ -1008,8 +1008,8 @@
def_type = ai_choose_defender_versus(acity, myunit->type);
if (move_time > 1) {
def_vet = do_make_unit_veteran(acity, def_type);
- vuln = unit_vulnerability_virtual2(myunit->type, def_type, x, y, FALSE,
- def_vet, FALSE, 0);
+ vuln = unittype_def_rating_sq(myunit->type, def_type,
+ x, y, FALSE, def_vet);
benefit = unit_types[def_type].build_cost;
} else {
vuln = 0;
@@ -1019,8 +1019,8 @@
pdef = get_defender(myunit, x, y);
if (pdef) {
- int m = unit_vulnerability_virtual2(myunit->type, pdef->type, x, y,
FALSE,
- pdef->veteran, FALSE, 0);
+ int m = unittype_def_rating_sq(myunit->type, pdef->type,
+ x, y, FALSE, pdef->veteran);
if (vuln < m) {
vuln = m;
benefit = unit_type(pdef)->build_cost;
--- ai/aihand.c.orig Thu May 8 21:01:12 2003
+++ ai/aihand.c Thu May 8 23:05:35 2003
@@ -259,8 +259,8 @@
*/
if (incity == pcity) {
if (defender) {
- if (unit_vulnerability_virtual(punit) <
- unit_vulnerability_virtual(defender)) {
+ if (unit_def_rating_basic_sq(punit) <
+ unit_def_rating_basic_sq(defender)) {
freelog(LOG_VERBOSE, "Disbanding %s in %s",
unit_type(punit)->name, pcity->name);
pack.unit_id = punit->id;
--- server/unittools.c.orig Thu May 8 21:08:17 2003
+++ server/unittools.c Thu May 8 21:18:32 2003
@@ -1306,7 +1306,7 @@
db = get_tile_type(map_get_terrain(x, y))->defense_bonus;
if (map_has_special(x, y, S_RIVER))
db += (db * terrain_control.river_defense_bonus) / 100;
- d = unit_vulnerability_virtual(punit) * db;
+ d = unit_def_rating_basic_sq(punit) * db;
adjc_iterate(x, y, x1, y1) {
if (ai_handicap(pplayer, H_FOG)
--- ai/aiunit.h.orig Thu May 8 21:05:46 2003
+++ ai/aiunit.h Thu May 8 23:59:01 2003
@@ -65,10 +65,10 @@
int unittype_att_rating(Unit_Type_id type, bool veteran,
int moves_left, int hp);
int unit_att_rating(struct unit *punit);
-int unit_vulnerability_virtual(struct unit *punit);
-int unit_vulnerability_virtual2(Unit_Type_id att_type, Unit_Type_id def_type,
- int x, int y, bool fortified, bool veteran,
- bool use_alternative_hp, int alternative_hp);
+int unit_def_rating_basic(struct unit *punit);
+int unit_def_rating_basic_sq(struct unit *punit);
+int unittype_def_rating_sq(Unit_Type_id att_type, Unit_Type_id def_type,
+ int x, int y, bool fortified, bool veteran);
int kill_desire(int benefit, int attack, int loss, int vuln, int attack_count);
bool is_on_unit_upgrade_path(Unit_Type_id test, Unit_Type_id base);
--- ai/aiunit.c.orig Thu May 8 21:04:25 2003
+++ ai/aiunit.c Fri May 9 00:20:19 2003
@@ -69,7 +69,7 @@
static int unit_move_turns(struct unit *punit, int x, int y);
static bool unit_role_defender(Unit_Type_id type);
-static int unit_vulnerability(struct unit *punit, struct unit *pdef);
+static int unit_def_rating_sq(struct unit *punit, struct unit *pdef);
/*
* Cached values. Updated by update_simple_ai_types.
@@ -846,49 +846,56 @@
}
/**********************************************************************
- ...
+ Defence rating of this particular unit against this attacker.
***********************************************************************/
-static int unit_vulnerability_basic(struct unit *punit, struct unit *pdef)
+static int unit_def_rating(struct unit *attacker, struct unit *defender)
{
- return (get_total_defense_power(punit, pdef) *
- (punit->id != 0 ? pdef->hp : unit_type(pdef)->hp) *
- unit_type(pdef)->firepower / POWER_DIVIDER);
+ return get_total_defense_power(attacker, defender) *
+ (attacker->id != 0 ? defender->hp : unit_type(defender)->hp) *
+ unit_type(defender)->firepower / POWER_DIVIDER;
}
/**********************************************************************
- ...
+ Square of the previous function - used in actual computations.
***********************************************************************/
-int unit_vulnerability_virtual(struct unit *punit)
+static int unit_def_rating_sq(struct unit *attacker,
+ struct unit *defender)
{
- int v = base_get_defense_power(punit) * punit->hp / POWER_DIVIDER;
-
+ int v = unit_def_rating(attacker, defender);
return v * v;
}
-/**************************************************************************
- See get_virtual_defense_power for the arguments att_type, def_type,
- x, y, fortified and veteran. If use_alternative_hp is FALSE the
- (maximum) hps of the given unit type is used. If use_alternative_hp
- is TRUE the given alternative_hp value is used.
-**************************************************************************/
-int unit_vulnerability_virtual2(Unit_Type_id att_type, Unit_Type_id def_type,
- int x, int y, bool fortified, bool veteran,
- bool use_alternative_hp, int alternative_hp)
-{
- int v = (get_virtual_defense_power(att_type, def_type, x, y, fortified,
- veteran) *
- (use_alternative_hp ? alternative_hp : unit_types[def_type].
- hp) * unit_types[def_type].firepower / POWER_DIVIDER);
- return v * v;
+/**********************************************************************
+ Basic defence rating of this particular unit.
+***********************************************************************/
+int unit_def_rating_basic(struct unit *punit)
+{
+ return base_get_defense_power(punit) * punit->hp *
+ unit_types[punit->type].firepower / POWER_DIVIDER;
}
/**********************************************************************
- ...
+ Square of the previous function - used in actual computations.
***********************************************************************/
-static int unit_vulnerability(struct unit *punit, struct unit *pdef)
+int unit_def_rating_basic_sq(struct unit *punit)
{
- int v = unit_vulnerability_basic(punit, pdef);
- return (v * v);
+ int v = unit_def_rating_basic(punit);
+ return v * v;
+}
+
+/**************************************************************************
+ Defence rating of this kind of unit, squared.
+ See get_virtual_defense_power for the arguments att_type, def_type,
+ x, y, fortified and veteran.
+**************************************************************************/
+int unittype_def_rating_sq(Unit_Type_id att_type, Unit_Type_id def_type,
+ int x, int y, bool fortified, bool veteran)
+{
+ int v = get_virtual_defense_power(att_type, def_type, x, y,
+ fortified, veteran) *
+ unit_types[def_type].hp *
+ unit_types[def_type].firepower / POWER_DIVIDER;
+ return v * v;
}
/**********************************************************************
@@ -1088,7 +1095,7 @@
unit_owner(pdef)->name, unit_type(pdef)->name, punit->x,
punit->y);
} else {
/* See description of kill_desire() about this variables. */
- int vuln = unit_vulnerability(punit, pdef);
+ int vuln = unit_def_rating_sq(punit, pdef);
int attack = reinforcements_value(punit, pdef->x, pdef->y)
+ attack_power;
int benefit = unit_type(pdef)->build_cost;
@@ -1545,7 +1552,7 @@
struct unit **aunit, struct city **acity)
{
int dist, def, best = 0;
- int toughness = unit_vulnerability_virtual(punit);
+ int toughness = unit_def_rating_basic_sq(punit);
if (toughness == 0) {
/* useless */
@@ -1564,7 +1571,7 @@
continue;
}
dist = unit_move_turns(punit, buddy->x, buddy->y);
- def = (toughness - unit_vulnerability_virtual(buddy));
+ def = (toughness - unit_def_rating_basic_sq(buddy));
if (get_transporter_capacity(buddy) == 0) {
/* Reduce want based on distance. We can't do this for
* transports since they move around all the time, leading
@@ -1634,7 +1641,7 @@
if (assess_defense_unit(pcity, pdef, FALSE) >= val) val = 0;
}
unit_list_iterate_end; /* was getting confused without the is_military
part in */
- if (unit_vulnerability_virtual(punit) == 0) q = 0; /* thanks, JMT,
Paul */
+ if (unit_def_rating_basic_sq(punit) == 0) q = 0; /* thanks, JMT, Paul
*/
else q = (pcity->ai.danger * 2 - def *
unit_type(punit)->attack_strength /
unit_type(punit)->defense_strength);
/* this was a WAG, but it works, so now it's just good code! -- Syela */
@@ -1664,8 +1671,8 @@
/* Check if city we are on our way to rescue is still in danger,
* or unit we should protect is still alive */
if ((aunit && aunit->ai.bodyguard != BODYGUARD_NONE
- && unit_vulnerability_virtual(punit) >
- unit_vulnerability_virtual(aunit)) ||
+ && unit_def_rating_basic_sq(punit) >
+ unit_def_rating_basic_sq(aunit)) ||
(acity && acity->owner == punit->owner && acity->ai.urgency != 0 &&
acity->ai.danger > assess_defense_quadratic(acity))) {
assert(punit->ai.ai_role == AIUNIT_ESCORT);
@@ -1702,7 +1709,7 @@
if (q > 0) {
q *= 100;
- q /= unit_vulnerability_virtual(punit);
+ q /= unit_def_rating_basic_sq(punit);
q >>= unit_move_turns(punit, pcity->x, pcity->y);
}
@@ -2071,7 +2078,7 @@
}
if ((pdef = get_defender(punit, acity->x, acity->y))) {
- vuln = unit_vulnerability(punit, pdef);
+ vuln = unit_def_rating_sq(punit, pdef);
benefit = unit_type(pdef)->build_cost;
} else {
vuln = 0;
@@ -2083,11 +2090,9 @@
if (move_time > 1) {
Unit_Type_id def_type = ai_choose_defender_versus(acity, punit->type);
- int v
- = unit_vulnerability_virtual2(punit->type, def_type, acity->x,
- acity->y, FALSE,
- do_make_unit_veteran(acity, def_type),
- FALSE, 0);
+ int v = unittype_def_rating_sq(punit->type, def_type,
+ acity->x, acity->y, FALSE,
+ do_make_unit_veteran(acity, def_type));
if (v > vuln) {
/* They can build a better defender! */
vuln = v;
@@ -2234,7 +2239,7 @@
continue;
}
- vuln = unit_vulnerability(punit, aunit);
+ vuln = unit_def_rating_sq(punit, aunit);
benefit = unit_type(aunit)->build_cost;
move_time = turns_to_enemy_unit(punit->type, move_rate,
|
|