[freeciv-ai] Re: [Freeciv-Dev] Re: Patch for units recovering hit points
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Thu, 25 Jul 2002, Raimar Falke wrote:
> > An idea: if a unit wants to heal, but it can't find a city that's close
> > enough, fotify it.
...on a terrain position with high defense value, yes.
> > Also, if a unit's in a city, it only goes after huts.
> > You might want to change that to also attack enemies that it really wants to
> > fight (> 70000?).
Yes.
+/* is the unit damaged?, if true recover hit points */
+ punittype=get_unit_type(punit->type);
+ if (punit->hp < punittype->hp * 0.25 ||
+ (punit->ai.ai_role = AIUNIT_RECOVER_HIT_POINTS &&
As Raimar said, missing =
+static bool find_nearest_friendly_city(struct unit *punit)
I suggest renaming to find_nearest_friendly_barrack() to indicate strongly
that this is only for land units. Also, please add something to the
function comment about the return value.
+{
+ struct player *pplayer = unit_owner(punit);
+ 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.seacost[pcity->x][pcity->y];
You should use warmap.cost, not warmap.seacost.
+static void ai_recover_hit_points(struct player *pplayer,struct unit *punit)
I would call it ai_manage_hitpoint_recovery() to indicate that it is in
the same league as the other ai_manage_* functions.
+ /* rest in city until the hitpoints are recovered */
+ do {
+ res=ai_military_findvictim(pplayer, punit, &dest_x, &dest_y);
Indent.
+ if ((dest_x == punit->x && dest_y == punit->y) || (res != 99998)) {
+ /* nothing to kill and no huts to find, so wait to recover all the
hitpoints */
+ break;
This makes no sense to me. If dest_x|y are unchanged, then findvictim
found nothing, correct. But why special case huts (99998)?
I would instead check if (res > 1).
+ } else { /* goto does NOT work for fast units */
I don't understand this comment.
+ handle_unit_move_request(punit, dest_x, dest_y, FALSE, FALSE);
Replace with ai_unit_attack().
+ punit = find_unit_by_id(id);
+ }
+ } while (punit && punit->moves_left > 0); /* want units to attack multiple
times */
Good idea, a bit hard to read implementation.
+ } else {
+ /* goto to nearest city to recover hit points */
+ /* just before, check to see if we can occupy at enemy city undefended */
+ res=ai_military_findvictim(pplayer, punit, &dest_x, &dest_y);
+ if (res == 99999) {
+ /* we find an undefended city near us, occupy!!! */
+ freelog(LOG_DEBUG, "%s's %s at (%d, %d) occuping (%d, %d) while trying
to recover hit points.",
+ pplayer->name, unit_type(punit)->name,
+ punit->x, punit->y, dest_x, dest_y);
+ handle_unit_move_request(punit, dest_x, dest_y, FALSE, FALSE);
+ return;
+ }
I would combine this with the similar code above, and use if (res > 1),
since it is always better to attack a weaker unit, I believe, than to let
it attack us. It could be a catapult type unit. Our weakened state is
calculated into consideration anyway.
+ freelog(LOG_DEBUG, "%s's unit (%d) die trying to recover hit points.",
Should be "died".
Overall, looks like a very nice patch, but I have not tested it.
Will anyone post an updated version?
Yours
Per
- [freeciv-ai] Re: [Freeciv-Dev] Re: Patch for units recovering hit points,
Per I. Mathisen <=
|
|