Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. *Read more...*

Feature #850770 ยป 0001-Improve-movement-cost-from-action-estimation.patch

Sveinung Kvilhaugsvik, 2019-12-12 08:44 AM

View differences:

ai/default/daiactions.c
utility -= unit_build_shield_cost_base(actor_unit);
} else {
/* Not going to spend the unit so care about move fragment cost. */
adv_want move_fragment_cost;
struct unit_type *actor_utype = unit_type_get(actor_unit);
/* FIXME: The action performer function may charge more. */
/* FIXME: Potentially wrong result if the unit moves as a part of the
* action and EFT_ACTION_SUCCESS_MOVE_COST depends on the unit's
* location since this is evaluated *before* the unit moves. */
move_fragment_cost = unit_pays_mp_for_action(paction, actor_unit);
if (utype_pays_for_regular_move_to_tgt(paction,
unit_type_get(actor_unit))) {
/* Add the cost from the move. */
move_fragment_cost += map_move_cost_unit(&(wld.map), actor_unit,
city_tile(target_city));
if (utype_is_moved_to_tgt_by_action(paction, actor_utype)) {
/* FIXME: doesn't catch all moved by action kinds. */
struct tile *actor_tile = unit_tile(actor_unit);
struct tile *target_tile = city_tile(target_city);
move_fragment_cost = utype_pays_mp_for_action_estimate(paction,
actor_utype,
actor_player,
actor_tile,
target_tile);
} else {
move_fragment_cost = unit_pays_mp_for_action(paction, actor_unit);
if (utype_pays_for_regular_move_to_tgt(paction,
unit_type_get(actor_unit))) {
/* Add the cost from the move. */
move_fragment_cost += map_move_cost_unit(&(wld.map), actor_unit,
city_tile(target_city));
}
}
/* Taking MAX_MOVE_FRAGS takes all the move fragments. */
common/unit.c
punit, unit_type_get(punit), NULL, NULL,
paction, EFT_ACTION_SUCCESS_MOVE_COST);
if (action_has_result(paction, ACTION_ATTACK)) {
if (unit_has_type_flag(punit, UTYF_ONEATTACK)) {
mpco += MAX_MOVE_FRAGS;
} else {
mpco += SINGLE_MOVE;
}
}
mpco += utype_pays_mp_for_action_base(paction, unit_type_get(punit));
return mpco;
}
common/unittype.c
return FALSE;
}
/**********************************************************************//**
Returns the amount of movement points successfully performing the
specified action will consume in the actor unit type without taking
effects or regular moves into account.
**************************************************************************/
int utype_pays_mp_for_action_base(const struct action *paction,
const struct unit_type *putype)
{
int mpco = 0;
if (action_has_result(paction, ACTION_ATTACK)) {
if (utype_has_flag(putype, UTYF_ONEATTACK)) {
mpco += MAX_MOVE_FRAGS;
} else {
mpco += SINGLE_MOVE;
}
}
return mpco;
}
/**********************************************************************//**
Returns an estimate of the amount of movement points successfully
performing the specified action will consume in the actor unit type.
**************************************************************************/
int utype_pays_mp_for_action_estimate(const struct action *paction,
const struct unit_type *putype,
const struct player *act_player,
const struct tile *act_tile,
const struct tile *tgt_tile)
{
const struct tile *post_action_tile;
int mpco = utype_pays_mp_for_action_base(paction, putype);
if (utype_is_moved_to_tgt_by_action(paction, putype)) {
post_action_tile = tgt_tile;
} else {
/* FIXME: Not 100% true. May escape, have a probability for moving to
* target tile etc. */
post_action_tile = act_tile;
}
if (utype_pays_for_regular_move_to_tgt(paction, putype)) {
/* Add the cost from the move. */
mpco += map_move_cost(&(wld.map), act_player, putype,
act_tile, tgt_tile);
}
/* FIXME: Probably wrong result if the effect
* EFT_ACTION_SUCCESS_MOVE_COST depends on unit state. Add unit state
* parameters? */
mpco += get_target_bonus_effects(NULL,
act_player,
NULL,
tile_city(post_action_tile),
NULL, tgt_tile,
NULL, putype, NULL, NULL,
paction, EFT_ACTION_SUCCESS_MOVE_COST);
return mpco;
}
/**********************************************************************//**
Returns the number of shields it takes to build this unit type.
**************************************************************************/
common/unittype.h
bool utype_pays_for_regular_move_to_tgt(const struct action *paction,
const struct unit_type *utype);
int utype_pays_mp_for_action_base(const struct action *paction,
const struct unit_type *putype);
int utype_pays_mp_for_action_estimate(const struct action *paction,
const struct unit_type *putype,
const struct player *act_player,
const struct tile *act_tile,
const struct tile *tgt_tile);
/* Functions to operate on various flag and roles. */
typedef bool (*role_unit_callback)(struct unit_type *ptype, void *data);
    (1-1/1)