[freeciv-ai] Re: hp recovery patch
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
I would prefer that changes like this not be made since they would have to
be redone almost in their entirely for general effects. I would suggest
combining these two functions with a:
find_nearest_recovery_[point|city|location](struct unit *punit);
since we'll be looking for the Unit_Recover effect eventually. Obviously
for now, we'll be searching for port facilities and barracks... you can
check for a sailing flag and then branch with switch if you'd like from
there.
I would also encourage anyone having any contact with a B_* anything to
also keep this in mind. Let's make the transition as painless as possible,
and that means not having to change new code as well as old.
-mike
On Wed, Dec 04, 2002 at 04:38:06PM +0000, Per I. Mathisen wrote:
>
> -/**********************************************************************
> +/**********************************************************************
> Find safe harbour (preferably with PORT). An allied player's city is
> just as good as one of our own, since both replenish our hitpoints and
> reduce unhappiness.
> ***********************************************************************/
> -static bool find_nearest_friendly_port(struct unit *punit)
> +static struct city *find_nearest_friendly_port(struct unit *punit)
> {
> struct player *pplayer = unit_owner(punit);
> + struct city *acity = NULL;
> int best = 6 * THRESHOLD + 1, cur;
> generate_warmap(map_get_city(punit->x, punit->y), punit);
> players_iterate(aplayer) {
> @@ -1899,19 +1915,51 @@
> cur = warmap.seacost[pcity->x][pcity->y];
> if (city_got_building(pcity, B_PORT)) cur /= 3;
> if (cur < best) {
> - punit->goto_dest_x = pcity->x;
> - punit->goto_dest_y = pcity->y;
> best = cur;
> + acity = pcity;
> }
> } city_list_iterate_end;
> }
> } players_iterate_end;
> - if (best > 6 * THRESHOLD) return FALSE;
> - freelog(LOG_DEBUG, "Friendly port nearest to (%d,%d) is %s@(%d,%d) [%d]",
> - punit->x, punit->y,
> - map_get_city(punit->goto_dest_x, punit->goto_dest_y)->name,
> - punit->goto_dest_x, punit->goto_dest_y, best);
> - return TRUE;
> + if (best > 6 * THRESHOLD) {
> + return NULL;
> + }
> + return acity;
> +}
> +
> +/**********************************************************************
> + Find safe city (preferably with Barracks). An allied player's city is
> + just as good as one of our own, since both replenish our hitpoints and
> + reduce unhappiness.
> +***********************************************************************/
> +static struct city *find_nearest_friendly_barrack(struct unit *punit)
> +{
> + struct player *pplayer = unit_owner(punit);
> + struct city *acity = NULL;
> + int best = 6 * THRESHOLD + 1, cur;
> +
> + generate_warmap(map_get_city(punit->x, punit->y), punit);
> + players_iterate(aplayer) {
> + if (pplayers_allied(pplayer,aplayer)) {
> + city_list_iterate(aplayer->cities, pcity) {
> + cur = warmap.cost[pcity->x][pcity->y];
> + /* we favour cities which barracks */
> + if (city_got_building(pcity, B_BARRACKS)
> + || city_got_building(pcity, B_BARRACKS2)
> + || city_got_building(pcity, B_BARRACKS3)) {
> + cur /= 3;
> + }
> + if (cur < best) {
> + acity = pcity;
> + best = cur;
> + }
> + } city_list_iterate_end;
> + }
> + } players_iterate_end;
> + if (best > 6 * THRESHOLD) {
> + return NULL;
> + }
> + return acity;
> }
|
|