Project

General

Profile

Bug #173 » 0018-Unhardcode-wld.map-from-action_hard_reqs_actor.patch

S3_1 - Marko Lindqvist, 01/12/2024 07:26 AM

View differences:

common/actions.c
may or may not be legal depending on the action.
**************************************************************************/
static enum fc_tristate
action_hard_reqs_actor(const struct action *paction,
action_hard_reqs_actor(const struct civ_map *nmap,
const struct action *paction,
const struct req_context *actor,
const bool omniscient,
const struct city *homecity)
{
enum action_result result = paction->result;
const struct civ_map *nmap = &(wld.map);
if (actor == NULL) {
actor = req_context_empty();
......
}
/* Actor specific hard requirements. */
out = action_hard_reqs_actor(paction, actor, omniscient, homecity);
out = action_hard_reqs_actor(nmap, paction, actor, omniscient, homecity);
if (out == TRI_NO) {
/* Illegal because of a hard actor requirement. */
......
/**********************************************************************//**
Returns the action probability for when a target is unseen.
**************************************************************************/
static struct act_prob act_prob_unseen_target(action_id act_id,
static struct act_prob act_prob_unseen_target(const struct civ_map *nmap,
action_id act_id,
const struct unit *actor_unit)
{
if (action_maybe_possible_actor_unit(act_id, actor_unit)) {
if (action_maybe_possible_actor_unit(nmap, act_id, actor_unit)) {
/* Unknown because the target is unseen. */
return ACTPROB_NOT_KNOWN;
} else {
......
const struct impr_type *target_building;
const struct unit_type *target_utype;
const struct action *act = action_by_number(act_id);
const struct civ_map *nmap = &(wld.map);
if (actor_unit == NULL || target_city == NULL) {
/* Can't do an action when actor or target are missing. */
......
if (!player_can_see_city_externals(unit_owner(actor_unit), target_city)) {
/* The invisible city at this tile may, as far as the player knows, not
* exist anymore. */
return act_prob_unseen_target(act_id, actor_unit);
return act_prob_unseen_target(nmap, act_id, actor_unit);
}
target_building = tgt_city_local_building(target_city);
......
struct act_prob prob_all;
const struct req_context *actor_ctxt;
const struct action *act = action_by_number(act_id);
const struct civ_map *nmap = &(wld.map);
if (actor_unit == NULL || target_tile == NULL) {
/* Can't do an action when actor or target are missing. */
......
return ACTPROB_IMPOSSIBLE;
} else {
/* The player doesn't know that the tile is empty. */
return act_prob_unseen_target(act_id, actor_unit);
return act_prob_unseen_target(nmap, act_id, actor_unit);
}
}
......
performed right now by the specified actor unit if an approriate target
is provided.
**************************************************************************/
bool action_maybe_possible_actor_unit(const action_id act_id,
bool action_maybe_possible_actor_unit(const struct civ_map *nmap,
const action_id act_id,
const struct unit *actor_unit)
{
const struct player *actor_player = unit_owner(actor_unit);
......
return FALSE;
}
result = action_hard_reqs_actor(paction, &actor_ctxt, FALSE,
result = action_hard_reqs_actor(nmap, paction, &actor_ctxt, FALSE,
unit_home(actor_unit));
if (result == TRI_NO) {
common/actions.h
/* common */
#include "fc_types.h"
#include "map_types.h"
#include "metaknowledge.h"
#include "requirements.h"
......
const struct player *actor_player,
const struct city* target_city);
bool action_maybe_possible_actor_unit(const action_id wanted_action,
bool action_maybe_possible_actor_unit(const struct civ_map *nmap,
const action_id wanted_action,
const struct unit* actor_unit);
bool action_mp_full_makes_legal(const struct unit *actor,
common/unit.c
**************************************************************************/
bool can_unit_paradrop(const struct unit *punit)
{
const struct civ_map *nmap = &(wld.map);
action_by_result_iterate(paction, ACTRES_PARADROP) {
if (action_maybe_possible_actor_unit(paction->id, punit)) {
if (action_maybe_possible_actor_unit(nmap, paction->id, punit)) {
return TRUE;
}
} action_by_result_iterate_end;
action_by_result_iterate(paction, ACTRES_PARADROP_CONQUER) {
if (action_maybe_possible_actor_unit(paction->id, punit)) {
if (action_maybe_possible_actor_unit(nmap, paction->id, punit)) {
return TRUE;
}
} action_by_result_iterate_end;
server/unithand.c
int actor_target_distance;
const struct player_tile *plrtile;
int target_extra_id = target_extra_id_client;
const struct civ_map *nmap = &(wld.map);
/* No potentially legal action is known yet. If none is found the player
* should get an explanation. */
......
actor_player = pc->playing;
actor_unit = game_unit_by_number(actor_unit_id);
target_tile = index_to_tile(&(wld.map), target_tile_id);
target_tile = index_to_tile(nmap, target_tile_id);
/* Initialize the action probabilities. */
action_iterate(act) {
......
probabilities[act] = action_prob_vs_city(actor_unit, act,
target_city);
} else if (!tile_is_seen(target_tile, actor_player)
&& action_maybe_possible_actor_unit(act, actor_unit)
&& action_maybe_possible_actor_unit(nmap, act, actor_unit)
&& action_id_distance_accepted(act,
actor_target_distance)) {
/* The target city is non existing. The player isn't aware of this
(2-2/2)