39 ACTIVITY_PILLAGE, ACTIVITY_GEN_ROAD, ACTIVITY_IRRIGATE,
40 ACTIVITY_MINE, ACTIVITY_BASE, ACTIVITY_CULTIVATE,
41 ACTIVITY_PLANT, ACTIVITY_TRANSFORM, ACTIVITY_POLLUTION,
42 ACTIVITY_FALLOUT, ACTIVITY_LAST};
49 #define CARGO_ITER(iter) ((struct cargo_iter *) (iter))
76 const struct unit *punit,
77 const struct city *pdest_city)
80 const struct player *punit_owner;
99 if (
nullptr == psrc_city) {
104 if (psrc_city == pdest_city) {
110 && (
nullptr == restriction
124 && !(
game.
info.airlifting_style & AIRLIFTING_ALLIED_SRC
130 if (pdest_city && punit_owner !=
city_owner(pdest_city)
131 && !(
game.
info.airlifting_style & AIRLIFTING_ALLIED_DEST
137 if (
nullptr == restriction ||
city_owner(psrc_city) == restriction) {
156 if (
nullptr == restriction ||
city_owner(pdest_city) == restriction) {
158 && !(
game.
info.airlifting_style & AIRLIFTING_UNLIMITED_DEST)) {
180 const struct city *pdest_city)
206 const struct action *paction)
211 const struct player *act_player;
213 has_unit = punit !=
nullptr;
215 if (has_unit && punittype ==
nullptr) {
223 act_player = has_unit ?
unit_owner(punit) :
nullptr;
232 nullptr, act_player,
nullptr,
nullptr,
nullptr,
nullptr, punit,
233 punittype,
nullptr,
nullptr, paction, EFT_UNIT_SHIELD_VALUE_PCT))
269 struct city *phomecity, *pdestcity;
319 enum action_result result)
328 const struct tile *ptile,
bool omniscient)
371 if (vl == V_INVIS || vl == V_SUBSURFACE) {
377 if (vl == V_INVIS || vl == V_SUBSURFACE) {
401 struct city *tgt_city;
408 punit, ACTION_FOUND_CITY,
unit_tile(punit),
nullptr));
416 const struct city *pcity)
418 if (pcity ==
nullptr) {
487 enum unit_activity activity,
488 const struct tile *ptile,
496 if (points_needed >= 0 && speed > 0) {
497 return (points_needed - 1) / speed + 1;
509 case ACTIVITY_PILLAGE:
511 case ACTIVITY_GEN_ROAD:
512 case ACTIVITY_IRRIGATE:
514 case ACTIVITY_POLLUTION:
515 case ACTIVITY_FALLOUT:
518 case ACTIVITY_FORTIFIED:
519 case ACTIVITY_SENTRY:
521 case ACTIVITY_EXPLORE:
522 case ACTIVITY_TRANSFORM:
523 case ACTIVITY_CULTIVATE:
525 case ACTIVITY_FORTIFYING:
526 case ACTIVITY_CONVERT:
529 case ACTIVITY_FORTRESS:
530 case ACTIVITY_AIRBASE:
531 case ACTIVITY_PATROL_UNUSED:
560 for (
int act = 0; act < ACTIVITY_LAST; act++) {
577 return (activity < ACTIVITY_LAST) && activity != ACTIVITY_FORTRESS
578 && activity != ACTIVITY_AIRBASE && activity != ACTIVITY_OLD_ROAD
579 && activity != ACTIVITY_OLD_RAILROAD && activity != ACTIVITY_UNKNOWN
580 && activity != ACTIVITY_PATROL_UNUSED;
594 case ACTIVITY_POLLUTION:
595 return _(
"Pollution");
602 case ACTIVITY_IRRIGATE:
603 return _(
"Irrigate");
604 case ACTIVITY_CULTIVATE:
605 return _(
"Cultivate");
606 case ACTIVITY_FORTIFYING:
607 return _(
"Fortifying");
608 case ACTIVITY_FORTIFIED:
609 return _(
"Fortified");
610 case ACTIVITY_SENTRY:
612 case ACTIVITY_PILLAGE:
616 case ACTIVITY_EXPLORE:
618 case ACTIVITY_TRANSFORM:
619 return _(
"Transform");
620 case ACTIVITY_FALLOUT:
624 case ACTIVITY_GEN_ROAD:
626 case ACTIVITY_CONVERT:
628 case ACTIVITY_OLD_ROAD:
629 case ACTIVITY_OLD_RAILROAD:
630 case ACTIVITY_FORTRESS:
631 case ACTIVITY_AIRBASE:
632 case ACTIVITY_UNKNOWN:
633 case ACTIVITY_PATROL_UNUSED:
648 if (!pcargo || !ptrans || pcargo == ptrans) {
722 if (!pcargo || !ptrans) {
746 const struct unit *ptrans)
748 if (!pcargo || !ptrans) {
763 ptrans, ACTION_TRANSPORT_UNLOAD, pcargo)));
782 enum unit_activity current = punit->
activity;
784 enum unit_activity current2 =
785 (current == ACTIVITY_FORTIFIED) ? ACTIVITY_FORTIFYING : current;
807 enum unit_activity activity)
819 if (activity == ACTIVITY_IRRIGATE
823 if (
nullptr == target) {
826 }
else if (activity == ACTIVITY_MINE
829 if (
nullptr == target) {
843 enum unit_activity activity,
855 enum unit_activity activity,
857 const struct tile *ptile)
883 case ACTIVITY_POLLUTION:
886 "Please use action_speculate_unit_on_tile()");
890 case ACTIVITY_FALLOUT:
893 "Please use action_speculate_unit_on_tile()");
900 "Please use action_speculate_unit_on_tile()");
906 "Please use action_speculate_unit_on_tile()");
910 case ACTIVITY_IRRIGATE:
913 "Please use action_speculate_unit_on_tile()");
917 case ACTIVITY_CULTIVATE:
920 "Please use action_speculate_unit_on_tile()");
924 case ACTIVITY_FORTIFYING:
927 "Please use action_speculate_unit_on_self()");
930 case ACTIVITY_FORTIFIED:
936 "Please use action_speculate_unit_on_tile()");
939 case ACTIVITY_GEN_ROAD:
942 "Please use action_speculate_unit_on_tile()");
945 case ACTIVITY_SENTRY:
953 case ACTIVITY_PILLAGE:
956 "Please use action_speculate_unit_on_tile()");
960 case ACTIVITY_EXPLORE:
963 case ACTIVITY_TRANSFORM:
966 "Please use action_speculate_unit_on_tile()");
970 case ACTIVITY_CONVERT:
973 "Please use action_speculate_unit_on_self()");
976 case ACTIVITY_OLD_ROAD:
977 case ACTIVITY_OLD_RAILROAD:
978 case ACTIVITY_FORTRESS:
979 case ACTIVITY_AIRBASE:
980 case ACTIVITY_PATROL_UNUSED:
982 case ACTIVITY_UNKNOWN:
985 qCritical(
"can_unit_do_activity_targeted_at() unknown activity %d",
994 enum unit_activity new_activity)
997 && new_activity != ACTIVITY_AIRBASE);
1002 if (new_activity == ACTIVITY_IDLE && punit->
moves_left > 0) {
1015 if (new_activity == ACTIVITY_FORTIFYING
1017 new_activity = ACTIVITY_FORTIFIED;
1029 enum unit_activity new_activity,
1033 || new_target ==
nullptr);
1047 const struct tile *ptile)
1070 if (punit->
activity == ACTIVITY_PILLAGE) {
1105 s += QString(
_(
"Moves: (%1T) %2"))
1106 .arg(QString::number(punit->
fuel - 1),
1109 s += QStringLiteral(
"%1: %2\n")
1113 case ACTIVITY_POLLUTION:
1114 case ACTIVITY_FALLOUT:
1115 case ACTIVITY_OLD_ROAD:
1116 case ACTIVITY_OLD_RAILROAD:
1117 case ACTIVITY_TRANSFORM:
1118 case ACTIVITY_FORTIFYING:
1119 case ACTIVITY_FORTIFIED:
1120 case ACTIVITY_AIRBASE:
1121 case ACTIVITY_FORTRESS:
1122 case ACTIVITY_SENTRY:
1124 case ACTIVITY_EXPLORE:
1125 case ACTIVITY_CONVERT:
1126 case ACTIVITY_CULTIVATE:
1127 case ACTIVITY_PLANT:
1131 case ACTIVITY_IRRIGATE:
1135 s += QStringLiteral(
"Building %1\n")
1139 case ACTIVITY_PILLAGE:
1141 s += QStringLiteral(
"%1: %2\n")
1149 s += QStringLiteral(
"%1: %2\n")
1153 case ACTIVITY_GEN_ROAD:
1154 s += QStringLiteral(
"%1: %2\n")
1158 case ACTIVITY_UNKNOWN:
1159 case ACTIVITY_PATROL_UNUSED:
1164 qCritical(
"Unknown unit activity %d for %s (nb %d) in %s()",
1180 s += QStringLiteral(
"%1 %2/%3/%4\n")
1181 .arg(
_(
"Food/Shield/Gold:"),
1203 punit->
tile = ptile;
1212 const struct player *pplayer)
1214 struct unit *punit =
nullptr;
1236 const struct player *pplayer)
1253 const struct player *pplayer)
1270 const struct player *pplayer)
1287 const struct player *pplayer)
1309 const struct player *pplayer)
1357 if (pcity !=
nullptr) {
1358 if ((srv && unit_list_size(ptile->units) > 0)
1360 && (pcity->
client.occupied
1424 BF_NOT_AGGRESSIVE)) {
1438 case ACTIVITY_IRRIGATE:
1440 case ACTIVITY_GEN_ROAD:
1453 case ACTIVITY_PILLAGE:
1454 case ACTIVITY_POLLUTION:
1455 case ACTIVITY_FALLOUT:
1468 case ACTIVITY_CULTIVATE:
1469 case ACTIVITY_PLANT:
1470 case ACTIVITY_TRANSFORM:
1504 punit->
utype = punittype;
1506 punit->
owner = pplayer;
1528 punit->
moved =
false;
1548 punit->
stay =
false;
1552 punit->
server.debug =
false;
1555 punit->
server.dying =
false;
1557 punit->
server.removal_callback =
nullptr;
1559 memset(punit->
server.upkeep_payed, 0,
1562 punit->
server.ord_map = 0;
1563 punit->
server.ord_city = 0;
1565 punit->
server.vision =
nullptr;
1576 punit->
client.transported_by = -1;
1577 punit->
client.colored =
false;
1578 punit->
client.act_prob_cache =
nullptr;
1614 delete[] punit->
server.adv;
1615 punit->
server.adv =
nullptr;
1617 if (punit->
client.act_prob_cache) {
1618 delete[] punit->
client.act_prob_cache;
1619 punit->
client.act_prob_cache =
nullptr;
1658 const struct unit *pcargo,
const struct tile *ptile,
1659 bool (*unit_load_test)(
const struct unit *pc,
const struct unit *pt))
1661 struct unit *best_trans =
nullptr;
1664 int depth, outermost_moves_left, total_moves;
1665 } cur, best = {
false};
1669 if (!unit_load_test(pcargo, ptrans)) {
1671 }
else if (best_trans ==
nullptr) {
1672 best_trans = ptrans;
1678 cur.outermost_moves_left = ptrans->moves_left;
1683 cur.has_orders =
true;
1685 cur.outermost_moves_left = ptranstrans->moves_left;
1698 if (best_trans != ptrans) {
1699 if (!cur.has_orders && best.has_orders) {
1700 best_trans = ptrans;
1701 }
else if (cur.has_orders && !best.has_orders) {
1709 cur.is_idle = (ptrans->activity == ACTIVITY_IDLE);
1710 if (best_trans != ptrans) {
1711 if (cur.is_idle && !best.is_idle) {
1712 best_trans = ptrans;
1713 }
else if (!cur.is_idle && best.is_idle) {
1723 if (best_trans != ptrans) {
1724 if (cur.can_freely_unload && !best.can_freely_unload) {
1725 best_trans = ptrans;
1726 }
else if (!cur.can_freely_unload && best.can_freely_unload) {
1733 if (best_trans != ptrans) {
1734 if (cur.depth < best.depth) {
1735 best_trans = ptrans;
1736 }
else if (cur.depth > best.depth) {
1744 if (best_trans != ptrans) {
1745 if (cur.outermost_moves_left > best.outermost_moves_left) {
1746 best_trans = ptrans;
1747 }
else if (cur.outermost_moves_left < best.outermost_moves_left) {
1758 if (best_trans != ptrans) {
1759 if (cur.total_moves > best.total_moves) {
1760 best_trans = ptrans;
1790 const struct tile *ptile)
1800 const struct unit *punit)
1881 if (tgt ==
nullptr) {
1901 char *buf,
size_t bufsz)
1912 PL_(
"Treasury contains %d gold.",
"Treasury contains %d gold.",
1922 PL_(
"Upgrade %s to %s for %d gold?\n%s",
1923 "Upgrade %s to %s for %d gold?\n%s", upgrade_cost),
1928 fc_snprintf(buf, bufsz,
_(
"Sorry, cannot upgrade %s (yet)."),
1935 PL_(
"Upgrading %s to %s costs %d gold.\n%s",
1936 "Upgrading %s to %s costs %d gold.\n%s", upgrade_cost),
1942 fc_snprintf(buf, bufsz,
_(
"You can only upgrade units in your cities."));
1946 _(
"Upgrading this %s would strand units it transports."),
1951 _(
"Upgrading this %s would result in a %s which can not "
1952 "survive at this place."),
1958 _(
"Upgrading this %s would result in a %s which its "
1959 "current transport, %s, could not transport."),
1974 const struct unit *punit)
1982 paction, EFT_ACTION_SUCCESS_MOVE_COST);
1997 < (punittype->
hp *
utype_class(punittype)->hp_loss_pct / 100);
2007 < (punittype->
hp *
utype_class(punittype)->hp_loss_pct / 100);
2063 int cost, default_hp, dist = 0;
2094 nullptr, ptile, punit,
2096 nullptr, EFT_UNIT_BRIBE_COST_PCT))
2116 return (
static_cast<float>(cost) / 2
2117 * (1.0 +
static_cast<float>(punit->
hp) / default_hp));
2146 struct unit *ptrans;
2163 success = unit_list_remove(ptrans->
transporting, pcargo);
2215 trans_utype != cargo_utype
2228 const struct unit *ptrans)
2278 if (ptrans == plevel) {
2297 if (iter.
depth > depth) {
2328 return unit_list_link_data(iter->
links[iter->
depth - 1]);
2337 const struct unit_list_link *piter = iter->
links[iter->
depth - 1];
2338 const struct unit_list_link *pnext;
2342 if (
nullptr != pnext) {
2350 pnext = unit_list_link_next(piter);
2351 if (
nullptr != pnext) {
2358 }
while (0 < iter->
depth);
2373 const struct unit *ptrans)
2381 iter->
depth = (
nullptr != iter->
links[0] ? 1 : 0);
bool is_action_enabled_unit_on_unit(const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Returns TRUE if actor_unit can do wanted_action to target_unit as far as action enablers are concerne...
bool action_prob_possible(const struct act_prob probability)
Returns TRUE iff the given action probability belongs to an action that may be possible.
bool is_action_enabled_unit_on_self(const action_id wanted_action, const struct unit *actor_unit)
Returns TRUE if actor_unit can do wanted_action to itself as far as action enablers are concerned.
bool is_action_enabled_unit_on_city(const action_id wanted_action, const struct unit *actor_unit, const struct city *target_city)
Returns TRUE if actor_unit can do wanted_action to target_city as far as action enablers are concerne...
struct act_prob action_prob_vs_city(const struct unit *actor_unit, const action_id act_id, const struct city *target_city)
Get the actor unit's probability of successfully performing the chosen action on the target city.
struct act_prob action_prob_vs_unit(const struct unit *actor_unit, const action_id act_id, const struct unit *target_unit)
Get the actor unit's probability of successfully performing the chosen action on the target unit.
struct act_prob action_prob_vs_tile(const struct unit *actor_unit, const action_id act_id, const struct tile *target_tile, const struct extra_type *target_extra)
Get the actor unit's probability of successfully performing the chosen action on the target tile.
bool action_maybe_possible_actor_unit(const action_id act_id, const struct unit *actor_unit)
Returns TRUE if the wanted action (as far as the player knows) can be performed right now by the spec...
bool is_action_enabled_unit_on_tile(const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Returns TRUE if actor_unit can do wanted_action to the target_tile as far as action enablers are conc...
int ai_type_number(const struct ai_type *ai)
Returns id of the given ai_type.
#define CALL_FUNC_EACH_AI(_func,...)
struct city * is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non_allied city on this tile?
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
bool is_capital(const struct city *pcity)
Return TRUE iff this city is its nation's capital.
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
bool is_unit_near_a_friendly_city(const struct unit *punit)
Return TRUE if there is a friendly city near to this unit (within 3 steps).
#define city_list_iterate(citylist, pcity)
#define city_list_iterate_end
int get_target_bonus_effects(struct effect_list *plist, const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, enum effect_type effect_type, enum vision_layer vision_layer, enum national_intelligence nintel)
Returns the effect bonus of a given type for any target.
int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, const struct unit_type *punittype, enum effect_type effect_type, enum vision_layer vision_layer)
Returns the effect bonus that applies at a tile for a given unittype.
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Returns the effect bonus at a unit.
enum unit_activity Activity_type_id
#define IDENTITY_NUMBER_ZERO
#define PL_(String1, String2, n)
struct unit * game_unit_by_number(int id)
Find unit out of all units in game: now uses fast idex method, instead of looking through all units o...
bool is_server()
Is program type server?
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
#define GAME_UNIT_BRIBE_DIST_MAX
#define GAME_TRANSPORT_MAX_RECURSIVE
static bool iterator_valid(const struct iterator *it)
static void iterator_next(struct iterator *it)
#define fc_assert_msg(condition, message,...)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
enum direction8 rand_direction()
Return random direction that is valid in current map.
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Are (x1,y1) and (x2,y2) really the same when adjusted? This function might be necessary ALOT of place...
int map_distance(const struct tile *tile0, const struct tile *tile1)
Return Manhattan distance between two tiles.
#define square_iterate(nmap, center_tile, radius, tile_itr)
#define square_iterate_end
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Return TRUE iff a unit of the given unit type can "exist" at this location.
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Return TRUE iff the unit can "exist" at this location.
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
This tile is native to unit.
bool can_unit_transport(const struct unit *transporter, const struct unit *transported)
Return true iff transporter has ability to transport transported.
int unit_move_rate(const struct unit *punit)
This function calculates the move rate of the unit.
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Return TRUE iff the unit can "survive" at this location.
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Is there native tile adjacent to given tile.
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Return TRUE iff transporter type has ability to transport transported class.
bool can_attack_non_native(const struct unit_type *utype)
This unit can attack non-native tiles (eg.
const char * move_points_text(int mp, bool reduce)
Simple version of move_points_text_full() – render positive movement points as text without any prefi...
struct city_list * cities
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Checks if a unit can be seen by pplayer at its current location.
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players can attack each other.
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players are allied.
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players have peace, cease-fire, or armistice.
struct setting_list * level[OLEVELS_NUM]
const struct unit_list_link * links[GAME_TRANSPORT_MAX_RECURSIVE]
struct city::@15::@18 client
struct packet_game_info info
bool(* valid)(const struct iterator *it)
void *(* get)(const struct iterator *it)
void(* next)(struct iterator *it)
struct player_economic economic
struct terrain * irrigation_result
struct terrain * mining_result
enum unit_activity activity
struct unit_type::@82 adv
const struct unit_type * converted_to
enum action_decision action_decision_want
enum unit_activity activity
struct unit::@76::@78 client
struct unit_list * transporting
struct extra_type * changed_from_target
struct unit::@76::@79 server
struct extra_type * activity_target
enum unit_activity changed_from
struct player * nationality
struct unit * transporter
struct goods_type * carrying
struct tile * action_decision_tile
const struct unit_type * utype
enum server_side_agent ssa_controller
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
#define terrain_has_flag(terr, flag)
bool tile_is_placing(const struct tile *ptile)
Is there a placing ongoing?
bool tile_has_base_flag_for_unit(const struct tile *ptile, const struct unit_type *punittype, enum base_flag_id flag)
Check if tile contains base providing effect for unit.
int tile_activity_time(enum unit_activity activity, const struct tile *ptile, const struct extra_type *tgt)
Time to complete the given activity on the given tile.
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
Check if tile contains base native for unit.
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Return a known_type enumeration value for the tile.
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
#define tile_terrain(_tile)
#define tile_owner(_tile)
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Return TRUE iff the two cities are capable of trade; i.e., if a caravan from one city can enter the o...
Activity_type_id real_activities[ACTIVITY_LAST]
bool is_tile_activity(enum unit_activity activity)
Returns true if given activity affects tile.
bool unit_being_aggressive(const struct unit *punit)
An "aggressive" unit is a unit which may cause unhappiness under a Republic or Democracy.
bool unit_type_really_ignores_zoc(const struct unit_type *punittype)
Takes into account unit class flag UCF_ZOC as well as IGZOC.
size_t cargo_iter_sizeof()
Returns the size of the unit cargo iterator.
bool unit_type_is_losing_hp(const struct player *pplayer, const struct unit_type *punittype)
Does unit lose hitpoints each turn?
bool is_terrain_change_activity(enum unit_activity activity)
Returns true if given activity changes terrain.
int unit_shield_value(const struct unit *punit, const struct unit_type *punittype, const struct action *paction)
Returns how many shields the unit (type) is worth.
int get_transporter_occupancy(const struct unit *ptrans)
Return how many units are in the transport.
static void cargo_iter_next(struct iterator *it)
Try to find next unit for the cargo iterator.
void free_unit_orders(struct unit *punit)
Free and reset the unit's goto route (punit->pgr).
bool can_unit_change_homecity(const struct unit *punit)
Return TRUE iff the unit can change homecity at its current location.
struct unit * transporter_for_unit(const struct unit *pcargo)
Find the best transporter at the given location for the unit.
enum unit_upgrade_result unit_upgrade_test(const struct unit *punit, bool is_free)
Tests if the unit could be updated.
void * unit_ai_data(const struct unit *punit, const struct ai_type *ai)
Return pointer to ai data of given unit and ai type.
void unit_set_ai_data(struct unit *punit, const struct ai_type *ai, void *data)
Attach ai data to unit.
bool unit_is_alive(int id)
Check if unit with given id is still alive.
bool unit_can_est_trade_route_here(const struct unit *punit)
Return TRUE iff this unit can be disbanded at its current location to provide a trade route from the ...
bool is_hiding_unit(const struct unit *punit)
Is the unit one that is invisible on the map.
int get_activity_rate_this_turn(const struct unit *punit)
Returns the amount of work a unit does (will do) on an activity this turn.
int unit_pays_mp_for_action(const struct action *paction, const struct unit *punit)
Returns the amount of movement points successfully performing the specified action will consume in th...
int get_turns_for_activity_at(const struct unit *punit, enum unit_activity activity, const struct tile *ptile, struct extra_type *tgt)
Return the estimated number of turns for the worker unit to start and complete the activity at the gi...
bool can_unit_paradrop(const struct unit *punit)
Return whether the unit can be paradropped - that is, if the unit is in a friendly city or on an airb...
struct unit * is_other_players_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an unit belonging to another player on this tile?
void unit_upkeep_astr(const struct unit *punit, QString &s)
Append a line of text describing the unit's upkeep to the astring.
bool unit_transport_load(struct unit *pcargo, struct unit *ptrans, bool force)
Load pcargo onto ptrans.
bool unit_can_add_or_build_city(const struct unit *punit)
Return TRUE iff this unit can add to a current city or build a new city at its current location.
bool is_my_zoc(const struct player *pplayer, const struct tile *ptile0, const struct civ_map *zmap)
Is this square controlled by the pplayer?
int unit_transport_depth(const struct unit *pcargo)
Returns the number of unit transport layers which carry unit 'pcargo'.
void set_unit_activity(struct unit *punit, enum unit_activity new_activity)
Assign a new untargeted task to a unit.
bool is_losing_hp(const struct unit *punit)
Does unit lose hitpoints each turn?
bool can_unit_change_homecity_to(const struct unit *punit, const struct city *pcity)
Return TRUE iff the unit can change homecity to the given city.
struct unit * is_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Returns true if the tile contains an allied unit and only allied units.
bool can_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Return TRUE iff the given unit can be loaded into the transporter.
int get_activity_rate(const struct unit *punit)
Returns the speed of a unit doing an activity.
struct unit * is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non-allied unit on this tile?
bool unit_transport_check(const struct unit *pcargo, const struct unit *ptrans)
Returns whether 'pcargo' in 'ptrans' is a valid transport.
bool is_attack_unit(const struct unit *punit)
Is the unit capable of attacking?
const Activity_type_id tile_changing_activities[]
static bool is_real_activity(enum unit_activity activity)
Return if given activity really is in game.
struct unit * unit_transport_get(const struct unit *pcargo)
Returns the transporter of the unit or nullptr if it is not transported.
bool unit_transport_unload(struct unit *pcargo)
Unload pcargo from ptrans.
bool unit_contained_in(const struct unit *pcargo, const struct unit *ptrans)
Returns whether 'pcargo' is transported by 'ptrans', either directly or indirectly.
bool can_unit_continue_current_activity(struct unit *punit)
Check if the unit's current activity is actually legal.
bool is_military_unit(const struct unit *punit)
Military units are capable of enforcing martial law.
struct unit * unit_occupies_tile(const struct tile *ptile, const struct player *pplayer)
Is there an occupying unit on this tile?
bool can_unit_do_activity_targeted_at(const struct unit *punit, enum unit_activity activity, struct extra_type *target, const struct tile *ptile)
Return TRUE if the unit can do the targeted activity at the given location.
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Find the best transporter at the given location for the unit.
int unit_bribe_cost(struct unit *punit, struct player *briber)
Calculate how expensive it is to bribe the unit.
bool is_build_activity(enum unit_activity activity, const struct tile *ptile)
Returns true if given activity is some kind of building.
bool is_square_threatened(const struct player *pplayer, const struct tile *ptile, bool omniscient)
Return TRUE iff this tile is threatened from any unit within 2 tiles.
bool could_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Return TRUE iff the given unit could be loaded into the transporter if we moved there.
bool unit_is_cityfounder(const struct unit *punit)
Is a cityfounder unit?
bool is_unit_activity_on_tile(enum unit_activity activity, const struct tile *ptile)
Return whether any units on the tile are doing this activity.
bool can_unit_do_autosettlers(const struct unit *punit)
Return whether the unit can be put in auto-settler mode.
bool unit_can_help_build_wonder_here(const struct unit *punit)
Return TRUE unless it is known to be imposible to disband this unit at its current position to get fu...
bool can_unit_alight_or_be_unloaded(const struct unit *pcargo, const struct unit *ptrans)
Return TRUE iff the given unit can leave its current transporter without doing any other action or mo...
bool is_field_unit(const struct unit *punit)
This checks the "field unit" flag on the unit.
static bool cargo_iter_valid(const struct iterator *it)
Return whether the iterator is still valid.
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Return TRUE iff this unit can do the specified generalized (ruleset defined) action enabler controlle...
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Return TRUE iff this unit can do any enabler controlled action with the specified action result.
void set_unit_activity_targeted(struct unit *punit, enum unit_activity new_activity, struct extra_type *new_target)
assign a new targeted task to a unit.
bool unit_can_convert(const struct unit *punit)
Tests if unit can be converted to another type.
int unit_cargo_depth(const struct unit *ptrans)
Returns the number of unit cargo layers within transport 'ptrans'.
static bool unit_transport_check_one(const struct unit_type *cargo_utype, const struct unit_type *trans_utype)
Helper for unit_transport_check().
bool can_unit_do_activity_targeted(const struct unit *punit, enum unit_activity activity, struct extra_type *target)
Return whether the unit can do the targeted activity at its current location.
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Returns the list of cargo units.
bv_extras get_unit_tile_pillage_set(const struct tile *ptile)
Return a mask of the extras which are actively (currently) being pillaged on the given tile.
int get_transporter_capacity(const struct unit *punit)
Return the number of units the transporter can hold (or 0).
struct unit * is_non_attack_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an unit we have peace or ceasefire with on this tile?
bool is_clean_activity(enum unit_activity activity)
Returns true if given activity is some kind of cleaning.
bool unit_can_airlift_to(const struct unit *punit, const struct city *pdest_city)
Determines if punit can be airlifted to dest_city now! So punit needs to be in a city now.
enum unit_upgrade_result unit_upgrade_info(const struct unit *punit, char *buf, size_t bufsz)
Find the result of trying to upgrade the unit, and a message that most callers can use directly.
bool can_unit_do_activity(const struct unit *punit, enum unit_activity activity)
Return TRUE iff the unit can do the given untargeted activity at its current location.
static struct unit * base_transporter_for_unit(const struct unit *pcargo, const struct tile *ptile, bool(*unit_load_test)(const struct unit *pc, const struct unit *pt))
Helper for transporter_for_unit() and transporter_for_unit_at()
void unit_virtual_destroy(struct unit *punit)
Free the memory used by virtual unit.
const char * get_activity_text(enum unit_activity activity)
Return the name of the activity in a static buffer.
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Create a virtual unit skeleton.
void unit_tile_set(struct unit *punit, struct tile *ptile)
Set the tile location of the unit.
struct iterator * cargo_iter_init(struct cargo_iter *iter, const struct unit *ptrans)
Initialize the cargo iterator.
static void * cargo_iter_get(const struct iterator *it)
Get the unit of the cargo iterator.
enum unit_airlift_result test_unit_can_airlift_to(const struct player *restriction, const struct unit *punit, const struct city *pdest_city)
Determines if punit can be airlifted to dest_city now! So punit needs to be in a city now.
const QString unit_activity_text(const struct unit *punit)
Return text describing the unit's current activity as a static string.
bool kills_citizen_after_attack(const struct unit *punit)
Return TRUE iff an attack from this unit would kill a citizen in a city (city walls protect against t...
bool unit_transported(const struct unit *pcargo)
Returns TRUE iff the unit is transported.
bool are_unit_orders_equal(const struct unit_order *order1, const struct unit_order *order2)
Checks unit orders for equality.
bool unit_is_virtual(const struct unit *punit)
Return TRUE if this is a valid unit pointer but does not correspond to any unit that exists in the ga...
static void set_unit_activity_internal(struct unit *punit, enum unit_activity new_activity)
Assign a new task to a unit.
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Return TRUE iff the given unit can be unloaded from its current transporter.
void unit_activity_astr(const struct unit *punit, QString &s)
Append text describing the unit's current activity to the given astring.
static bool can_type_transport_units_cargo(const struct unit_type *utype, const struct unit *punit)
Check if unit of given type would be able to transport all of transport's cargo.
bool unit_has_orders(const struct unit *punit)
Return TRUE iff the unit is following client-side orders.
struct player * unit_nationality(const struct unit *punit)
Return the nationality of the unit.
bool activity_requires_target(enum unit_activity activity)
Return TRUE if activity requires some sort of target to be specified.
struct unit * is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an enemy unit on this tile? Returns the unit or nullptr if none.
void setup_real_activities_array()
Setup array of real activities.
#define unit_transports_iterate_end
#define unit_cargo_iterate_end
#define unit_cargo_iterate(_ptrans, _pcargo)
#define unit_transports_iterate(_pcargo, _ptrans)
@ UU_UNSUITABLE_TRANSPORT
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_safe(unitlist, _unit)
#define unit_list_iterate_end
#define unit_list_iterate_safe_end
const char * unit_rule_name(const struct unit *punit)
Return the (untranslated) rule name of the unit.
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
int utype_pays_mp_for_action_base(const struct action *paction, const struct unit_type *putype)
Returns the amount of movement points successfully performing the specified action will consume in th...
bool utype_can_freely_unload(const struct unit_type *pcargotype, const struct unit_type *ptranstype)
Return TRUE iff the given cargo type has no restrictions on when it can unload from the given transpo...
bool utype_is_cityfounder(const struct unit_type *utype)
Is cityfounder type.
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Return whether this player can upgrade this unit type (to any other unit type).
int utype_build_shield_cost_base(const struct unit_type *punittype)
Returns the number of shields this unit type represents.
bool utype_may_act_move_frags(const struct unit_type *punit_type, const action_id act_id, const int move_fragments)
Return TRUE iff the given (action enabler controlled) action may be performed by a unit of the given ...
int unit_build_shield_cost_base(const struct unit *punit)
Returns the number of shields this unit represents.
bool utype_can_freely_load(const struct unit_type *pcargotype, const struct unit_type *ptranstype)
Return TRUE iff the given cargo type has no restrictions on when it can load onto the given transport...
struct unit_class * unit_class_get(const struct unit *punit)
Returns unit class pointer for a unit.
int utype_veteran_levels(const struct unit_type *punittype)
Return veteran levels of the given unit type.
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Return TRUE iff units of the given type can do any enabler controlled action with the specified actio...
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Return whether the unit has the given flag.
const char * utype_name_translation(const struct unit_type *punittype)
Return the (translated) name of the unit type.
const char * unit_name_translation(const struct unit *punit)
Return the (translated) name of the unit.
bool utype_acts_hostile(const struct unit_type *putype)
Return TRUE iff units of this type can do hostile actions controlled by generalized (ruleset defined)...
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Return TRUE iff units of the given type can do the specified generalized (ruleset defined) action ena...
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Return veteran level properties of given unit in given veterancy level.
int unit_upgrade_price(const struct player *pplayer, const struct unit_type *from, const struct unit_type *to)
Return the cost (gold) of upgrading a single unit of the specified type to the new type.
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
#define utype_fuel(ptype)
static bool utype_has_flag(const struct unit_type *punittype, int flag)