This is the mail archive of the
xconq7@sources.redhat.com
mailing list for the Xconq project.
Kind-of, sort-of improved facility_worth function
- From: Lincoln Peters <peters2000 at mindspring dot com>
- To: Xconq mailing list <xconq7 at sources dot redhat dot com>
- Date: 31 Jul 2002 13:36:39 -0700
- Subject: Kind-of, sort-of improved facility_worth function
I have completed a (hopefully) better facility_worth function that can
consider what the facilities do when deciding how valuable they are.
This function looks at the facility's defensive abilities (for city
walls), production abilities (for granary, factory), growth abilities
(for aqueduct, sewer system), and repair abilities (for barracks).
However, the balance between the different types of facilities is
haphazard at best, and if it is to work well at all, it really should be
split into several functions, one for each type of facility. That would
require plan_improve to be re-written, but unless doing so would
interfere with anyone's long-term plans, I think that it should be
re-written.
There are a few things it still does not consider such as:
* Facilities that produce materials themselves, rather than affect the
transport's production (e.g. the amulet of power from fantasy.g).
* Materials that may be more important than others (e.g. food > ores).
This is just an attempt on my part to create a facility_worth function
that has all of the necessary code to allow the AI to understand as many
kinds of facilities as possible. I'm still not quite sure how to
re-write plan_improve to consider multiple worths, but what I have
figured out is that:
* Higher weights go to defensive facilities when enemies are close.
* Higher weights go to growth facilities when approaching a
size-limit-without-occupant.
* Higher weights go to repair facilities when lots of mobile units are
in the area (should also consider enemies and damaged units).
* Higher weights go to production facilities in all other cases.
And the new facility_worth function is:
int
facility_worth(int u)
{
int worth = 0;
int u2, u3, m;
/* The worth of a facility is determined by its ability to defend a unit (e.g. city walls),
to improve production of some material (e.g. granary),
to allow units to grow beyond a certain size (e.g. aqueduct),
and to repair other units (e.g. barracks).
However, the interactions between different facility types is quite unpredictable.
There should really be multiple facility_worth functions, one for each type of facility. */
if (!mobile(u)) {
/* Is it a defensive facility? */
for_all_unit_types(u2) {
if ( g_combat_model == 0 ) {
if ( uu_protection(u, u2) < 1.00 )
worth += 100 * ( 1 - uu_protection(u, u2) );
if ( uu_cellwide_protection_for(u, u2) < 1.00 ) {
for_all_unit_types(u3) {
if ( uu_cellwide_protection_against(u, u3) < 1.00 )
worth += ( 100 * ( 1 - uu_cellwide_protection_for(u, u2) ) ) * ( 100 * ( 1 - uu_cellwide_protection_against(u, u3) ) );
}
}
} else if ( g_combat_model == 1 ) {
for_all_unit_types(u2) {
if ( uu_neighbour_affects_defense(u, u2) > 100 )
worth += uu_neighbour_affects_defense(u, u2);
}
}
}
/* Is it a productive facility? */
for_all_material_types(m) {
if ( um_occ_mult_production(u, m) > 100 )
worth += um_occ_mult_production(u, m);
}
/* Is it a growth facility? */
for_all_unit_types(u2) {
if ( uu_size_limit_without_occ(u2, u) < pow( 6, u_reach(u2) ) )
worth += uu_size_limit_without_occ(u2, u);
}
/* Is it a repair facility? */
for_all_unit_types(u2) {
if ( uu_auto_repair(u, u2) > 0 )
worth += 100 * uu_auto_repair(u, u2);
}
}
DMprintf("unit type %s facility worth %d \n ", u_type_name(u), worth);
if (worth < 0)
init_warning("%s has negative facility worth", u_type_name(u));
return worth;
}