46 #include "unit_utils.h"
93 #define SPECLIST_TAG unit_move_data
95 #define unit_move_data_list_iterate(_plist, _pdata) \
96 TYPED_LIST_ITERATE(struct unit_move_data, _plist, _pdata)
97 #define unit_move_data_list_iterate_end LIST_ITERATE_END
98 #define unit_move_data_list_iterate_rev(_plist, _pdata) \
99 TYPED_LIST_ITERATE_REV(struct unit_move_data, _plist, _pdata)
100 #define unit_move_data_list_iterate_rev_end LIST_ITERATE_REV_END
111 #define SPECLIST_TAG autoattack_prob
112 #define SPECLIST_TYPE struct autoattack_prob
115 #define autoattack_prob_list_iterate_safe(autoattack_prob_list, _aap_, \
117 TYPED_LIST_ITERATE(struct autoattack_prob, autoattack_prob_list, _aap_) \
118 struct unit *_unit_ = game_unit_by_number(_aap_->unit_id); \
120 if (_unit_ == nullptr) { \
124 #define autoattack_prob_list_iterate_safe_end LIST_ITERATE_END
130 const struct unit_type *pttype,
bool helpless,
131 bool teleporting,
const struct city *pexclcity);
139 struct unit *ptrans,
bool force);
142 enum unit_loss_reason reason,
160 enum unit_role_id role_tech)
165 if (role_tech != -1) {
168 const int minplayers = 2;
181 if (players > minplayers) {
182 which[num++] = iunit;
238 }
else if (!settler) {
269 int *att_hp,
int *def_hp)
273 int attack_firepower, defense_firepower;
279 *att_hp = attacker->
hp;
280 *def_hp = defender->
hp;
284 qDebug(
"attack:%d, defense:%d, attack firepower:%d, "
285 "defense firepower:%d",
286 attackpower, defensepower, attack_firepower, defense_firepower);
292 if (max_rounds <= 0) {
293 if (attackpower == 0 || attack_firepower == 0) {
295 }
else if (defensepower == 0 || defense_firepower == 0) {
299 for (rounds = 0; *att_hp > 0 && *def_hp > 0
300 && (max_rounds <= 0 || max_rounds > rounds);
302 if (
fc_rand(attackpower + defensepower) >= defensepower) {
303 *def_hp -= attack_firepower;
305 *att_hp -= defense_firepower;
322 int *att_hp,
int *def_hp)
325 int old_def_hp, bomb_limit_hp, bomb_limit_pct;
330 int attack_firepower, defense_firepower;
334 *att_hp = attacker->
hp;
335 old_def_hp = *def_hp = defender->
hp;
338 if (bomb_limit_pct > 0)
344 bomb_limit_hp =
MIN(bomb_limit_hp, old_def_hp);
348 qDebug(
"attack:%d, defense:%d, attack firepower:%d, "
349 "defense firepower:%d, bomb limit:%d",
350 attackpower, defensepower, attack_firepower, defense_firepower,
356 for (i = 0; i < rate; i++) {
357 if (
fc_rand(attackpower + defensepower) >= defensepower) {
358 *def_hp -= attack_firepower;
363 if (*def_hp < bomb_limit_hp) {
364 *def_hp = bomb_limit_hp;
373 if (attacker->
hp <= 0 || defender->
hp <= 0
374 || !
game.
info.only_killing_makes_veteran) {
375 if (attacker->
hp > 0) {
378 if (defender->
hp > 0) {
391 struct unit_list *candidates;
396 candidates = unit_list_new();
403 unit_list_prepend(candidates, punit);
408 while (upgrades > 0 && unit_list_size(candidates) > 0) {
411 int candidate_to_upgrade =
fc_rand(unit_list_size(candidates));
412 struct unit *punit = unit_list_get(candidates, candidate_to_upgrade);
417 if (type_to ==
nullptr) {
423 unit_list_remove(candidates, punit);
429 _(
"%s was upgraded for free to %s."),
431 unit_list_remove(candidates, punit);
435 unit_list_destroy(candidates);
444 const struct unit_type *from_type, *to_type;
446 if (punit->
activity != ACTIVITY_CONVERT)
492 if (punit->hp <= 0) {
497 if (!punit->homecity && 0 <
game.
info.killunhomed) {
500 _(
"Your %s has run out of hit points "
501 "because it was not supported by a city."),
505 ftc_server,
_(
"Your %s has run out of hit points."),
522 struct unit *carrier;
539 if (move_cost > punit->moves_left) {
557 qCritical(
"rescue plane: unit %d died enroute!",
id);
562 log_debug(
"rescue plane: unit %d could not move to "
572 punit->goto_tile =
nullptr;
583 _(
"Your %s has returned to refuel."),
unit_link(punit));
616 _(
"Your %s has run out of fuel."),
648 auto now = time(
nullptr);
679 punit->changed_from = punit->activity;
680 punit->changed_from_target = punit->activity_target;
681 punit->changed_from_count = punit->activity_count;
699 if (punit->activity == act
700 && (!tgt_matters || punit->activity_target == tgt)) {
701 total += punit->activity_count;
742 _(
"Your %s became more experienced and achieved the rank "
782 _(
"Orders for %s aborted because activity "
783 "is no longer available."),
819 bool unit_activity_done =
false;
820 enum unit_activity activity = punit->
activity;
825 case ACTIVITY_FORTIFIED:
826 case ACTIVITY_SENTRY:
828 case ACTIVITY_UNKNOWN:
829 case ACTIVITY_FORTIFYING:
830 case ACTIVITY_CONVERT:
831 case ACTIVITY_PATROL_UNUSED:
836 case ACTIVITY_EXPLORE:
840 case ACTIVITY_PILLAGE:
844 unit_activity_done =
true;
853 case ACTIVITY_POLLUTION:
863 unit_activity_done =
true;
867 case ACTIVITY_FALLOUT:
877 unit_activity_done =
true;
881 case ACTIVITY_BASE: {
886 unit_activity_done =
true;
890 case ACTIVITY_GEN_ROAD: {
895 unit_activity_done =
true;
899 case ACTIVITY_IRRIGATE:
901 case ACTIVITY_CULTIVATE:
903 case ACTIVITY_TRANSFORM:
912 unit_activity_done =
true;
916 case ACTIVITY_OLD_ROAD:
917 case ACTIVITY_OLD_RAILROAD:
918 case ACTIVITY_FORTRESS:
919 case ACTIVITY_AIRBASE:
924 if (unit_activity_done) {
926 if (ACTIVITY_IRRIGATE == activity || ACTIVITY_MINE == activity
927 || ACTIVITY_CULTIVATE == activity || ACTIVITY_PLANT == activity
928 || ACTIVITY_TRANSFORM == activity) {
936 if (punit2->activity == activity) {
959 if (activity == ACTIVITY_FORTIFYING) {
963 unit_activity_done =
true;
967 if (activity == ACTIVITY_CONVERT) {
972 unit_activity_done =
true;
976 if (unit_activity_done) {
977 if (activity == ACTIVITY_PILLAGE) {
998 enum unit_activity activity = punit->
activity;
1007 case ACTIVITY_EXPLORE:
1008 case ACTIVITY_FORTIFIED:
1009 case ACTIVITY_SENTRY:
1011 case ACTIVITY_PATROL_UNUSED:
1012 case ACTIVITY_UNKNOWN:
1017 case ACTIVITY_POLLUTION:
1019 case ACTIVITY_CULTIVATE:
1020 case ACTIVITY_IRRIGATE:
1021 case ACTIVITY_PILLAGE:
1022 case ACTIVITY_PLANT:
1023 case ACTIVITY_TRANSFORM:
1024 case ACTIVITY_FALLOUT:
1026 case ACTIVITY_GEN_ROAD:
1032 case ACTIVITY_FORTIFYING:
1033 case ACTIVITY_CONVERT:
1035 && (
game.
server.unitwaittime_style & UWT_ACTIVITIES)
1040 wait->
id = punit->
id;
1042 unit_wait_list_append(
server.unit_waits, wait);
1049 case ACTIVITY_OLD_ROAD:
1050 case ACTIVITY_OLD_RAILROAD:
1051 case ACTIVITY_FORTRESS:
1052 case ACTIVITY_AIRBASE:
1076 if (punit->
server.wait) {
1077 unit_wait_list_erase(
server.unit_waits, punit->
server.wait);
1088 case ACTIVITY_PILLAGE:
1109 if (*
activity == ACTIVITY_PILLAGE && *target ==
nullptr) {
1124 *activity = ACTIVITY_IDLE;
1135 int sq_radius,
struct tile **dst_tile)
1152 if (0 < unit_list_size(ptile->units)) {
1167 if (value > bestvalue) {
1174 return bestvalue > 0;
1183 struct tile *ptile =
nullptr;
1199 punit =
create_unit(powner, ptile, u_type, 0, 0, -1);
1201 punit->
activity = ACTIVITY_FORTIFIED;
1213 int move_cost,
bool verbose)
1218 qDebug(
"Teleported %s %s from (%d,%d) to %s",
1230 if (move_cost == -1) {
1233 unit_move(punit, dst_tile, move_cost,
nullptr,
false,
false);
1253 explicit bounce_destination(
const unit *
unit) : m_unit(
unit) {}
1256 ~bounce_destination() {}
1268 template <
bool SAFE>
1269 bool bounce_destination<SAFE>::reached(
1272 if constexpr (SAFE) {
1273 return vertex.
location != m_unit->tile
1276 return vertex.
location != m_unit->tile
1290 const tile *start_from,
int max_distance)
1291 : m_player(
player), m_start(start_from), m_distance(max_distance)
1296 virtual ~bounce_path_constraint() =
default;
1302 const tile *m_start;
1303 const int m_distance;
1309 bool bounce_path_constraint::is_allowed(
1335 const auto punit_tile =
unit_tile(punit);
1343 finder.set_constraint(std::make_unique<bounce_path_constraint>(
1344 pplayer, punit_tile, max_distance));
1348 auto paths = finder.find_all(bounce_destination<true>(punit));
1349 if (paths.empty()) {
1350 paths = finder.find_all(bounce_destination<false>(punit));
1353 qDebug() <<
"Bouncing: found" << paths.size() <<
"possible paths";
1355 if (!paths.empty()) {
1356 const auto path = paths[
fc_rand(paths.size())];
1357 const auto steps = path.steps();
1358 const auto end_tile = path.steps().back().location;
1369 _(
"Moved your %s due to changing terrain."),
1378 auto packet = packet_unit_orders{};
1379 packet.unit_id = punit->
id;
1380 packet.dest_tile = steps.back().location->index;
1382 packet.repeat =
false;
1383 packet.vigilant =
false;
1385 packet.length = steps.size();
1387 for (std::size_t i = 0; i < steps.size(); ++i) {
1388 packet.orders[i] = steps[i].order;
1400 if (punit->
tile != punit_tile) {
1425 _(
"Disbanded your %s due to changing terrain."),
1430 wipe_unit(punit, ULR_STACK_CONFLICT,
nullptr);
1443 struct unit *ptrans;
1444 struct unit_list *pcargo_units;
1475 if (
nullptr == ptrans || pplayer !=
unit_owner(ptrans)) {
1482 #ifdef FREECIV_DEBUG
1490 "Failed to throw %s %d from %s %d (%d, %d)",
unit_rule_name(punit),
1506 struct player *aplayer,
bool verbose)
1553 const struct player *aplayer)
1555 struct unit_list *seen_units = unit_list_new();
1563 unit_list_append(seen_units, punit);
1574 unit_list_append(seen_units, punit);
1581 unit_list_unique(seen_units);
1594 const struct unit_list *seen_units)
1636 const struct player *pplayer,
1637 const struct unit *punit)
1683 bv_player can_see_unit;
1699 punit->
utype = to_unit;
1778 if (home !=
nullptr &&
game.
info.goods_selection == GSM_LEAVING) {
1793 struct unit *ptrans)
1795 struct unit *punit =
1815 punit->
hp = hp_left;
1818 if (moves_left >= 0) {
1835 punit->
moved = (moves_left >= 0);
1837 unit_list_prepend(pplayer->
units, punit);
1838 unit_list_prepend(ptile->
units, punit);
1873 void (*callback)(
struct unit *punit))
1880 punit->
server.removal_callback = callback;
1888 punit->
server.removal_callback =
nullptr;
1896 enum unit_loss_reason reason)
1898 struct packet_unit_remove packet;
1902 struct unit *ptrans;
1906 punit->
server.dying =
true;
1908 #ifdef FREECIV_DEBUG
1934 punit->
server.vision =
nullptr;
1937 if (punit->
server.wait) {
1938 unit_wait_list_erase(
server.unit_waits, punit->
server.wait);
1941 packet.unit_id = punit->
id;
1947 lsend_packet_unit_remove(aplayer->connections, &packet);
1955 send_packet_unit_remove(pconn, &packet);
1960 if (punit->
server.moving !=
nullptr) {
1962 punit->
server.moving->punit =
nullptr;
1965 if (punit->
server.removal_callback !=
nullptr) {
1967 punit->
server.removal_callback(punit);
1974 _(
"Unable to defend %s, %s has lost the game."),
1977 _(
"Losing %s meant losing the game! "
1978 "Be more careful next time!"),
1984 unit_loss_reason_name(reason));
1990 if (
nullptr != ptrans) {
2004 if (pcity && pcity != phomecity) {
2009 if (pcity && unit_list_size(ptile->
units) == 0) {
2020 enum unit_loss_reason reason)
2029 struct unit *pcargo,
2052 enum unit_loss_reason reason,
2059 struct unit_list *helpless = unit_list_new();
2060 struct unit_list *imperiled = unit_list_new();
2061 struct unit_list *unsaved = unit_list_new();
2063 struct city *pexclcity;
2066 punit->
server.dying =
true;
2072 if (reason == ULR_CITY_LOST) {
2075 pexclcity =
nullptr;
2079 if (ptrans !=
nullptr) {
2090 bool healthy =
false;
2093 unit_list_prepend(helpless, pcargo);
2096 unit_list_prepend(imperiled, pcargo);
2110 if (pcargo->activity == ACTIVITY_SENTRY) {
2137 case ULR_ELIMINATED:
2138 case ULR_TRANSPORT_LOST:
2139 if (killer !=
nullptr) {
2144 case ULR_BARB_UNLEASH:
2147 case ULR_NONNATIVE_TERR:
2151 case ULR_STACK_CONFLICT:
2159 case ULR_PLAYER_DIED:
2166 if (unit_list_size(helpless) > 0) {
2167 struct unit_list *remaining = unit_list_new();
2178 unit_list_prepend(unsaved, pcargo);
2181 unit_list_prepend(remaining, pcargo);
2190 unit_list_prepend(unsaved, pcargo);
2195 unit_list_destroy(remaining);
2197 unit_list_destroy(helpless);
2200 if (unit_list_size(imperiled) > 0) {
2201 struct unit_list *remaining = unit_list_new();
2212 unit_list_prepend(unsaved, pcargo);
2215 unit_list_prepend(remaining, pcargo);
2224 unit_list_prepend(unsaved, pcargo);
2229 unit_list_destroy(remaining);
2231 unit_list_destroy(imperiled);
2234 if (unit_list_size(unsaved) > 0) {
2241 unit_list_destroy(unsaved);
2261 const struct unit_type *pttype,
bool helpless,
2262 bool teleporting,
const struct city *pexclcity)
2269 if (!helpless && ptransport !=
nullptr) {
2276 struct city *pcity =
2279 if (pcity !=
nullptr) {
2286 pplayer, ptile, E_UNIT_RELOCATED,
ftc_server,
2287 _(
"%s escaped the destruction of %s, and fled to %s."), tplink,
2303 int homecity,
enum unit_loss_reason reason)
2305 struct unit *gained_unit;
2322 gained_unit->
server.birth_turn = punit->
server.birth_turn;
2363 int ransom, unitcount = 0;
2370 punit->
server.dying =
true;
2372 if ((
game.
info.gameloss_style & GAMELOSS_STYLE_LOOT)
2390 log_debug(
"Worthless enemy doesn't have more techs to steal.");
2393 log_debug(
"Pressed tech %s from captured enemy",
2404 int vcsize = city_list_size(pvictim->
cities);
2405 int evcsize = vcsize;
2406 int conqsize = evcsize;
2420 bool submit =
false;
2427 if (
fc_rand(vcsize) < conqsize) {
2442 if (conqsize <= 0) {
2461 PL_(
"Barbarian leader captured; %d gold ransom paid.",
2462 "Barbarian leader captured; %d gold ransom paid.",
2471 if (unitcount == 0) {
2495 other_killed[i] =
nullptr;
2510 && vunit->hp > 0 && vunit->moves_left > pkiller->
moves_left
2514 struct tile *dsttile =
nullptr;
2524 if (pkiller->
moves_left <= vunit->moves_left - move_cost
2526 || unit_list_size(ptile2->units))
2530 if (def_bonus <= curr_def_bonus) {
2531 def_bonus = curr_def_bonus;
2539 if (dsttile !=
nullptr) {
2548 unit_move(vunit, dsttile, move_cost,
nullptr,
true,
false);
2557 if (vunit != punit) {
2567 if (unitcount > 1) {
2571 PL_(
"Another unit was eliminated by your attacking %s!",
2572 "Another %2$d units were eliminated by your attacking %1$s!",
2574 pkiller_link, unitcount - 1);
2588 if (num_killed[i] > 1) {
2594 PL_(
"One other unit lost when the %s %s defeated your %s.",
2595 "%4$d other units lost when the %1$s %2$s defeated your "
2601 if ((unitcount - 1) > num_killed[i]) {
2606 PL_(
"One allied unit lost when the %s %s defeated your %s.",
2607 "%4$d allied units lost when the %1$s %2$s defeated your "
2614 if (num_killed[i] >= 1) {
2619 PL_(
"One unit lost when the %s %s defeated the %s %s.",
2620 "%5$d units lost when the %1$s %2$s defeated the %3$s "
2632 if (0 < num_escaped[i]) {
2635 PL_(
"%d unit escaped from attack by %s %s",
2636 "%d units escaped from attack by %s %s",
2638 num_escaped[i], pkiller_link,
2664 packet->id = punit->
id;
2668 packet->facing = punit->
facing;
2669 packet->homecity = punit->
homecity;
2673 packet->veteran = punit->
veteran;
2676 packet->hp = punit->
hp;
2677 packet->activity = punit->
activity;
2696 packet->fuel = punit->
fuel;
2701 packet->stay = punit->
stay;
2703 packet->transported =
false;
2704 packet->transported_by = 0;
2706 packet->transported =
true;
2712 packet->carrying = -1;
2725 packet->orders_length = packet->orders_index = 0;
2726 packet->orders_repeat = packet->orders_vigilant =
false;
2734 QDateTime localtime;
2735 localtime.setSecsSinceEpoch(gotime);
2736 QDateTime utctime(localtime.toUTC());
2737 gotime = utctime.toSecsSinceEpoch();
2738 packet->action_timestamp = gotime;
2740 packet->action_decision_tile =
2751 struct packet_unit_short_info *packet,
2754 packet->packet_use = packet_use;
2755 packet->info_city_id = info_city_id;
2757 packet->id = punit->
id;
2760 packet->facing = punit->
facing;
2761 packet->veteran = punit->
veteran;
2763 packet->hp = punit->
hp;
2766 if (punit->
activity == ACTIVITY_EXPLORE
2767 || punit->
activity == ACTIVITY_GOTO) {
2768 packet->activity = ACTIVITY_IDLE;
2770 packet->activity = punit->
activity;
2784 packet->transported =
false;
2785 packet->transported_by = 0;
2787 packet->transported =
true;
2798 if (punit->
server.moving !=
nullptr) {
2810 const struct player *powner;
2811 struct packet_unit_info info;
2812 struct packet_unit_short_info sinfo;
2815 if (dest ==
nullptr) {
2831 if (pplayer ==
nullptr) {
2832 if (pconn->observer) {
2833 send_packet_unit_info(pconn, &info);
2835 }
else if (pplayer == powner) {
2836 send_packet_unit_info(pconn, &info);
2837 if (pdata !=
nullptr) {
2841 send_packet_unit_info(pconn, &info);
2842 if (pdata !=
nullptr) {
2846 send_packet_unit_short_info(pconn, &sinfo,
false);
2847 if (pdata !=
nullptr) {
2864 struct player *pplayer = pconn->playing;
2866 if (
nullptr == pplayer && !pconn->observer) {
2894 struct city *pcity =
nullptr;
2913 _(
"The %s %s was nuked."),
2941 ftc_server,
_(
"%s destroyed in nuclear explosion!"),
2956 nullptr, pplayer,
extra_owner(ptile), pcity,
nullptr,
nullptr,
nullptr,
2957 nullptr,
nullptr,
nullptr,
nullptr, EFT_NUKE_INFRASTRUCTURE_PCT);
2962 if (extra->category != ECAT_INFRA) {
3008 API_TYPE_PLAYER, pplayer);
3010 _(
"The %s detonated a nuke!"),
3019 const struct action *paction)
3032 if (!(
game.
info.airlifting_style & AIRLIFTING_UNLIMITED_SRC)) {
3036 if (!(
game.
info.airlifting_style & AIRLIFTING_UNLIMITED_DEST)) {
3060 if (punit->
activity == ACTIVITY_EXPLORE) {
3083 const struct action *paction)
3097 if (
nullptr == plrtile->
site
3101 _(
"This unit cannot paradrop into %s."),
3106 if (
nullptr != plrtile->
site && plrtile->
owner !=
nullptr
3109 _(
"Cannot attack unless you declare war first."));
3118 && (!
game.
info.paradrop_to_transport
3122 _(
"Your %s paradropped into the %s and was lost."),
3139 _(
"Your %s was killed by enemy units at the "
3140 "paradrop destination."),
3155 0,
nullptr,
game.
info.paradrop_to_transport,
3183 if (hut_chance != 0) {
3186 PL_(
"You found %d gold.",
"You found %d gold.", cred),
3195 _(
"Your %s has been killed by barbarians!"),
3197 wipe_unit(punit, ULR_BARB_UNLEASH,
nullptr);
3223 ptile,
nullptr,
nullptr,
nullptr,
nullptr,
3263 bv_player can_see_unit;
3296 struct unit *ptrans,
bool force)
3318 struct unit *ptrans;
3359 const struct unit *p1trans = p1unit, *q1trans = q1unit;
3364 while (p1trans && q1trans) {
3368 if (!p1trans && q1trans) {
3372 }
else if (p1trans && !q1trans) {
3394 struct autoattack_prob_list *autoattack;
3396 int sanity1 = punit->
id;
3418 AAPC_UNIT_MOVED_ADJ, penemy,
unit_owner(punit),
nullptr, tgt_tile,
3422 probability->unit_id = penemy->id;
3423 autoattack_prob_list_prepend(autoattack, probability);
3426 probability =
nullptr;
3435 if (autoattack_prob_list_size(autoattack) >= 2) {
3441 int sanity2 = penemy->id;
3444 double punitwin, penemywin;
3445 double threshold = 0.25;
3455 if (
nullptr != enemy_defender) {
3464 AAPC_UNIT_MOVED_ADJ, penemy,
unit_owner(punit),
nullptr, tgt_tile,
3475 if ((penemywin > 1.0 - punitwin
3477 && penemywin > threshold) {
3478 #ifdef REALLY_DEBUG_THIS
3479 log_test(
"AA %s -> %s (%d,%d) %.2f > %.2f && > %.2f",
3490 #ifdef REALLY_DEBUG_THIS
3491 log_test(
"!AA %s -> %s (%d,%d) %.2f > %.2f && > %.2f",
3505 autoattack_prob_list_destroy(autoattack);
3511 autoattack_prob_list_destroy(autoattack);
3552 alone_in_city = (1 == count);
3554 alone_in_city =
false;
3568 && penemy->activity == ACTIVITY_SENTRY
3569 && radius_sq >= distance_sq
3580 _(
"Your sentried %s spotted a %s %s %s [id:%d, %s, hp:%d] at "
3600 && ppatrol->orders.vigilant) {
3602 cancel_orders(ppatrol,
" stopping because of nearby enemy");
3605 _(
"Orders for %s aborted after enemy movement was "
3626 struct tile *dst_tile,
bool passenger,
3627 bool conquer_city_allowed)
3631 struct city *homecity_start_pos =
nullptr;
3632 struct city *homecity_end_pos =
nullptr;
3633 int homecity_id_start_pos = punit->
homecity;
3634 int homecity_id_end_pos = punit->
homecity;
3636 struct player *pplayer_end_pos = pplayer_start_pos;
3638 const struct unit_type *type_end_pos = type_start_pos;
3639 bool refresh_homecity_start_pos =
false;
3640 bool refresh_homecity_end_pos =
false;
3641 int saved_id = punit->
id;
3644 if (tocity && conquer_city_allowed) {
3659 homecity_id_end_pos = punit->
homecity;
3663 if (homecity_id_start_pos != 0) {
3666 if (homecity_id_start_pos != homecity_id_end_pos) {
3669 homecity_end_pos = homecity_start_pos;
3680 if (tocity->
owner == pplayer_end_pos) {
3681 if (tocity != homecity_end_pos &&
is_human(pplayer_end_pos)) {
3686 if (homecity_start_pos) {
3687 refresh_homecity_start_pos =
true;
3692 if (homecity_start_pos) {
3693 refresh_homecity_start_pos =
true;
3695 if (fromcity != homecity_start_pos
3696 && fromcity->
owner == pplayer_start_pos
3704 if (homecity_start_pos || homecity_end_pos) {
3713 refresh_homecity_start_pos =
true;
3714 refresh_homecity_end_pos =
true;
3718 if (refresh_homecity_start_pos &&
is_human(pplayer_start_pos)) {
3722 if (refresh_homecity_end_pos
3723 && (!refresh_homecity_start_pos
3724 || homecity_start_pos != homecity_end_pos)
3744 case ACTIVITY_SENTRY:
3745 case ACTIVITY_EXPLORE:
3748 case ACTIVITY_POLLUTION:
3750 case ACTIVITY_IRRIGATE:
3751 case ACTIVITY_CULTIVATE:
3752 case ACTIVITY_PLANT:
3753 case ACTIVITY_FORTIFIED:
3754 case ACTIVITY_FORTRESS:
3755 case ACTIVITY_PILLAGE:
3756 case ACTIVITY_TRANSFORM:
3757 case ACTIVITY_UNKNOWN:
3758 case ACTIVITY_AIRBASE:
3759 case ACTIVITY_FORTIFYING:
3760 case ACTIVITY_FALLOUT:
3761 case ACTIVITY_PATROL_UNUSED:
3763 case ACTIVITY_GEN_ROAD:
3764 case ACTIVITY_CONVERT:
3765 case ACTIVITY_OLD_ROAD:
3766 case ACTIVITY_OLD_RAILROAD:
3777 struct tile *psrctile,
3778 struct tile *pdesttile)
3786 struct vision *new_vision;
3789 if (punit->
server.moving) {
3791 pdata = punit->
server.moving;
3794 "Unit number %d (%p) was going to die, but "
3795 "server attempts to move it.",
3798 "Unit number %d (%p) has done an incomplete move.",
3813 success = unit_list_remove(psrctile->
units,
punit);
3853 "Unit number %d (%p) has done an incomplete move.",
3859 if (pdata->
punit !=
nullptr) {
3879 struct unit *embark_to,
bool find_embark_target,
3880 bool conquer_city_allowed)
3883 struct tile *psrctile;
3885 struct unit *ptransporter;
3886 struct packet_unit_info src_info, dest_info;
3887 struct packet_unit_short_info src_sinfo, dest_sinfo;
3888 struct unit_move_data_list *plist;
3893 enum direction8 facing;
3902 saved_id = punit->
id;
3911 if (ptransporter !=
nullptr) {
3932 unit_move_data_list_prepend(plist, pdata);
3941 punit->
moved =
true;
3976 unit_move_data_list_append(plist, pdata);
3981 pdata = unit_move_data_list_front(plist);
4002 if (adj && pmove_data == pdata) {
4012 pmove_data != pdata))
4014 pmove_data != pdata)) {
4019 pmove_data != pdata)) {
4031 bool new_information_for_enemy =
false;
4037 if (penemy->is_connected && pplayer != penemy
4040 new_information_for_enemy =
true;
4046 if (new_information_for_enemy) {
4064 if (aplayer ==
nullptr) {
4065 if (pconn->observer) {
4067 send_packet_unit_info(pconn, &src_info);
4068 send_packet_unit_info(pconn, &dest_info);
4071 if (aplayer == pplayer) {
4072 send_packet_unit_info(pconn, &src_info);
4073 send_packet_unit_info(pconn, &dest_info);
4075 send_packet_unit_short_info(pconn, &src_sinfo,
false);
4076 send_packet_unit_short_info(pconn, &dest_sinfo,
false);
4086 if (adj && pmove_data == pdata) {
4101 if (aplayer ==
nullptr) {
4102 if (pconn->observer) {
4104 send_packet_unit_info(pconn, &dest_info);
4107 if (aplayer == pmove_data->powner) {
4108 send_packet_unit_info(pconn, &dest_info);
4110 send_packet_unit_short_info(pconn, &dest_sinfo,
false);
4123 pmove_data->old_vision =
nullptr;
4130 struct unit *aunit = pmove_data->punit;
4132 if (aunit !=
nullptr &&
unit_owner(aunit) == pmove_data->powner
4135 pdata != pmove_data,
4136 conquer_city_allowed);
4141 unit_lives = (pdata->
punit == punit);
4153 if (embark_to !=
nullptr) {
4154 ptransporter = embark_to;
4155 }
else if (find_embark_target) {
4160 ptransporter =
nullptr;
4180 struct unit *aunit = pmove_data->punit;
4182 if (aunit ==
nullptr) {
4205 struct unit *ptrans;
4207 struct unit *act_unit;
4208 struct player *act_player;
4210 act_unit = pmove_data->punit;
4243 if (
nullptr == ptrans) {
4273 unit_move_data_list_destroy(plist);
4327 bool cancel =
false;
4389 bool res, last_order;
4390 int unitid = punit->
id;
4396 if (punit->
activity != ACTIVITY_IDLE) {
4411 struct tile *dst_tile;
4412 struct city *tgt_city;
4413 struct unit *tgt_unit;
4419 log_debug(
" stopping because we're done this turn");
4427 _(
"Orders for %s aborted as there are units nearby."),
4434 log_debug(
" stopping because we ran a round");
4449 switch (order.
order) {
4454 log_debug(
" stopping because of no more move points");
4460 log_debug(
" stopping. Not enough move points this turn");
4487 switch (order.
order) {
4499 enum unit_activity activity = order.
activity;
4512 cancel_orders(punit,
" orders canceled because of failed activity");
4514 _(
"Orders for %s aborted since they "
4515 "give an invalid activity."),
4522 cancel_orders(punit,
" move order sent us to invalid location");
4524 _(
"Orders for %s aborted since they "
4525 "give an invalid location."),
4535 _(
"Orders for %s aborted as there "
4536 "are units in the way."),
4552 log_debug(
" orders resulted in combat.");
4578 _(
"Orders for %s aborted because of failed move."),
4595 if (dst_tile ==
nullptr) {
4601 order.
action, dst_tile,
nullptr,
nullptr);
4609 if (tgt_city ==
nullptr
4613 cancel_orders(punit,
" perform action vs city with no city");
4615 order.
action, dst_tile, tgt_city,
nullptr);
4623 if (tgt_unit ==
nullptr
4627 cancel_orders(punit,
" perform action vs unit with no unit");
4629 order.
action, dst_tile, tgt_city, tgt_unit);
4671 tgt_id = dst_tile->
index;
4675 tgt_id = dst_tile->
index;
4679 tgt_id = tgt_city->
id;
4684 tgt_id = tgt_unit->
id;
4692 qCritical(
"Invalid action target kind");
4708 _(
"%s could not do %s to %s."),
unit_link(punit),
4714 order.
action, dst_tile, tgt_city, tgt_unit);
4741 _(
"Orders for %s aborted because "
4742 "doing %s to %s failed."),
4765 _(
"Your %s has invalid orders."),
unit_link(punit));
4771 log_debug(
" stopping because orders are complete");
4792 enum vision_layer vlayer)
4797 EFT_UNIT_VISION_RADIUS_SQ, vlayer);
4808 qCritical(
"Unsupported vision layer variant: %d.", vlayer);
4866 _(
"Your unit may not act for another %s "
4867 "this turn. See /help unitwaittime."),
4886 const auto now = time(
nullptr);
4893 && now < punit->action_timestamp +
game.
server.unitwaittime) {
4928 for (i = 0; i < length; i++) {
4933 qCritical(
"invalid order %d at index %d", orders[i].order, i);
4936 switch (orders[i].order) {
4940 qCritical(
"in order %d, invalid move direction %d.", i,
4946 switch (orders[i].activity) {
4947 case ACTIVITY_SENTRY:
4948 if (i != length - 1) {
4950 qCritical(
"activity %d is not allowed at index %d.",
4951 orders[i].activity, i);
4957 case ACTIVITY_GEN_ROAD:
4958 case ACTIVITY_FALLOUT:
4959 case ACTIVITY_POLLUTION:
4960 case ACTIVITY_PILLAGE:
4962 case ACTIVITY_IRRIGATE:
4963 case ACTIVITY_PLANT:
4964 case ACTIVITY_CULTIVATE:
4965 case ACTIVITY_TRANSFORM:
4966 case ACTIVITY_CONVERT:
4967 case ACTIVITY_FORTIFYING:
4968 qCritical(
"at index %d, use action rather than activity %d.", i,
4969 orders[i].activity);
4972 case ACTIVITY_EXPLORE:
4976 case ACTIVITY_FORTIFIED:
4978 case ACTIVITY_OLD_ROAD:
4979 case ACTIVITY_OLD_RAILROAD:
4980 case ACTIVITY_FORTRESS:
4981 case ACTIVITY_AIRBASE:
4983 case ACTIVITY_PATROL_UNUSED:
4985 case ACTIVITY_UNKNOWN:
4986 qCritical(
"at index %d, unsupported activity %d.", i,
4987 orders[i].activity);
4995 qCritical(
"at index %d, the action %d doesn't exist.", i,
5004 qCritical(
"at index %d, invalid tile target %d for the action %d.",
5005 i, orders[i].target, orders[i].
action);
5010 qCritical(
"at index %d, the action %d sets the outdated target"
5011 " specification dir.",
5021 qCritical(
"at index %d, cannot do %s without a target.", i,
5028 if (orders[i].sub_target ==
A_NONE
5030 && orders[i].sub_target !=
A_FUTURE)) {
5032 qCritical(
"at index %d, cannot do %s without a target.", i,
5038 case ASTK_EXTRA_NOT_THERE:
5047 if (pextra ==
nullptr) {
5050 qCritical(
"at index %d, cannot do %s without a target.", i,
5058 qCritical(
"at index %d, cannot do %s to %s.", i,
5072 false,
"Bad action %d in order number %d.", orders[i].
action, i);
5076 if (i != length - 1) {
5087 qCritical(
"action %d is not allowed at index %d.",
bool action_removes_extra(const struct action *paction, const struct extra_type *pextra)
Returns TRUE iff the specified action can remove the specified extra.
bool action_mp_full_makes_legal(const struct unit *actor, const action_id act_id)
Returns TRUE if the specified action can't be done now but would have been legal if the unit had full...
const char * action_rule_name(const struct action *action)
Get the rule name of the action.
struct act_prob action_prob_self(const struct unit *actor_unit, const action_id act_id)
Get the actor unit's probability of successfully performing the chosen action on itself.
bool action_prob_possible(const struct act_prob probability)
Returns TRUE iff the given action probability belongs to an action that may be possible.
struct unit * action_tgt_unit(struct unit *actor, struct tile *target_tile, bool accept_all_actions)
Find a unit to target for an action at the specified tile.
struct city * action_tgt_city(struct unit *actor, struct tile *target_tile, bool accept_all_actions)
Find a city to target for an action on the specified tile.
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.
enum action_sub_target_kind action_get_sub_target_kind(const struct action *paction)
Get the sub target kind of an action.
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.
struct act_prob action_prob_vs_units(const struct unit *actor_unit, const action_id act_id, const struct tile *target_tile)
Get the actor unit's probability of successfully performing the chosen action on all units at the tar...
const QString action_id_name_translation(action_id act_id)
Get the action name used when displaying the action in the UI.
struct action * action_by_number(action_id act_id)
Return the action with the given id.
bool action_id_exists(const action_id act_id)
Returns TRUE iff the specified action ID refers to a valid action.
bool action_has_result(const struct action *paction, enum action_result result)
Returns TRUE iff performing the specified action has the specified result.
bool action_creates_extra(const struct action *paction, const struct extra_type *pextra)
Returns TRUE iff the specified action can create the specified extra.
int action_prob_cmp_pessimist(const struct act_prob ap1, const struct act_prob ap2)
Compare action probabilities.
double action_prob_to_0_to_1_pessimist(const struct act_prob ap)
Returns double in the range [0-1] representing the minimum of the given action probability.
const char * action_id_rule_name(action_id act_id)
Get the rule name of the action.
#define action_id_get_sub_target_kind(act_id)
#define action_id_get_act_time(act_id, actor_unit, tgt_tile, tgt_extra)
#define ACTPROB_IMPOSSIBLE
#define action_id_get_target_kind(act_id)
#define action_id_has_result_safe(act_id, result)
bool adv_follow_path(struct unit *punit, const PFPath &path, struct tile *ptile)
Move a unit along a path without disturbing its activity, role or assigned destination Return FALSE i...
#define CALL_FUNC_EACH_AI(_func,...)
#define CALL_PLR_AI_FUNC(_func, _player,...)
enum unit_move_result manage_auto_explorer(struct unit *punit)
Handle eXplore mode of a unit (explorers are always in eXplore mode for AI) - explores unknown territ...
void adv_unit_new_task(struct unit *punit, enum adv_unit_task task, struct tile *ptile)
Change unit's advisor task.
bool BV_ISSET(const BV &bv, int bit)
bool city_exists_within_max_city_map(const struct tile *ptile, bool may_be_on_center)
Return TRUE iff a city exists within a city radius of the given location.
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 city * is_enemy_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an enemy city on this tile?
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
struct city * is_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an friendly city on this tile?
struct city * is_non_attack_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an enemy city on this tile?
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Removes an improvement (and its effects) from a city.
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
const char * city_name_get(const struct city *pcity)
Return the name of the city.
citizens city_size_get(const struct city *pcity)
Get the city size.
bool is_friendly_city_near(const struct player *owner, const struct tile *ptile)
Return TRUE if there is a friendly city near to this tile (within 3 steps).
#define city_list_iterate_safe(citylist, _city)
#define city_list_iterate(citylist, pcity)
#define output_type_iterate(output)
#define city_list_iterate_end
#define city_list_iterate_safe_end
#define city_built_iterate(_pcity, _p)
#define city_built_iterate_end
#define output_type_iterate_end
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Reduce the city size.
bool city_refresh(struct city *pcity)
Updates unit upkeeps and city internal cached data.
Abstraction for path finding destinations.
A path is a succession of moves and actions to go from one location to another.
Allows one to limit the scope a path finding search.
struct unit * get_defender(const struct unit *attacker, const struct tile *ptile)
Finds the best defender on the tile, given an attacker.
bool is_unit_reachable_at(const struct unit *defender, const struct unit *attacker, const struct tile *location)
Can unit attack other at given location.
bool is_stack_vulnerable(const struct tile *ptile)
Is it a city/fortress/air base or will the whole stack die in an attack.
int get_total_defense_power(const struct unit *attacker, const struct unit *defender)
return the modified defense power of a unit.
int get_virtual_defense_power(const struct unit_type *att_type, const struct unit_type *def_type, struct player *def_player, struct tile *ptile, bool fortified, int veteran)
May be called with a non-existing att_type to avoid any effects which depend on the attacker.
int get_total_attack_power(const struct unit *attacker, const struct unit *defender)
Return the modified attack power of a unit.
double unit_win_chance(const struct unit *attacker, const struct unit *defender)
Returns a double in the range [0;1] indicating the attackers chance of winning.
void get_modified_firepower(const struct unit *attacker, const struct unit *defender, int *att_fp, int *def_fp)
A unit's effective firepower depend on the situation.
void unit_restore_hitpoints(struct unit *punit)
add hitpoints to the unit, hp_gain_coord returns the amount to add united nations will speed up the p...
void conn_list_do_unbuffer(struct conn_list *dest)
Convenience functions to unbuffer a list of connections.
struct player * conn_get_player(const struct connection *pconn)
Returns the player that this connection is attached to, or nullptr.
void conn_list_do_buffer(struct conn_list *dest)
Convenience functions to buffer a list of connections.
bool conn_is_global_observer(const struct connection *pconn)
Returns TRUE if the given connection is a global observer.
#define conn_list_iterate(connlist, pconn)
#define conn_list_iterate_end
static void base(QVariant data1, QVariant data2)
Action "Build Base" for choice dialog.
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.
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
#define ACT_TIME_INSTANTANEOUS
#define MAX_NUM_PLAYER_SLOTS
#define IDENTITY_NUMBER_ZERO
#define PL_(String1, String2, n)
const char * unit_veteran_level_and_bonus(const unit *punit)
Get a text of a unit's numerical veteran level and the bonus percentage it confers.
const char * tile_link(const struct tile *ptile)
Get a text link to a tile.
const char * unit_tile_link(const struct unit *punit)
Get a text link to a unit tile (make a clickable link to a tile with the unit type name as text).
const char * unit_veteran_level_string(const struct unit *punit)
Get a text of a unit's vet level.
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
Get a text link to a city.
const char * unit_link(const struct unit *punit)
Get a text link to an unit.
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...
void game_remove_unit(struct world *gworld, struct unit *punit)
In the server call wipe_unit(), and never this function directly.
int current_turn_timeout()
Return timeout value for the current turn.
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
void increase_timeout_because_unit_moved()
adjusts game.seconds_to_turn_done when enemy moves a unit, we see it and the remaining timeout is sma...
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
AI players may have handicaps - allowing them to cheat or preventing them from using certain algorith...
void idex_register_unit(struct world *iworld, struct unit *punit)
Register a unit into idex, with current punit->id.
bool is_improvement(const struct impr_type *pimprove)
Is this building a regular improvement?
struct impr_type * improvement_by_number(const Impr_type_id id)
Returns the improvement type for the given index/ID.
const char * improvement_name_translation(const struct impr_type *pimprove)
Return the (translated) name of the given improvement.
#define fc_assert_msg(condition, message,...)
#define fc_assert_ret(condition)
#define fc_assert_exit_msg(condition, message,...)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define fc_assert_action(condition, action)
#define log_debug(message,...)
#define fc_assert_ret_val_msg(condition, val, message,...)
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
Return squared distance between two tiles.
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...
bool map_untrusted_dir_is_valid(enum direction8 dir)
Returns TRUE iff the given direction is a valid one.
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Return real distance between two tiles.
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Return the tile for the given index position.
bool base_get_direction_for_step(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile, enum direction8 *dir)
Return TRUE and sets dir to the direction of the step if (end_x, end_y) can be reached from (start_x,...
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Step from the given tile in the given direction.
#define square_iterate(nmap, center_tile, radius, tile_itr)
#define adjc_iterate(nmap, center_tile, itr_tile)
#define square_iterate_end
static int map_move_cost_unit(const struct civ_map *nmap, struct unit *punit, const struct tile *ptile)
#define circle_iterate(nmap, center_tile, sq_radius, tile_itr)
#define circle_iterate_end
void vision_clear_sight(struct vision *vision)
Clear all sight points from this vision source.
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Remove extra from tile.
void bounce_units_on_terrain_change(struct tile *ptile)
Check ptile and nearby tiles to see if all units can remain at their current locations,...
void give_distorted_map(struct player *pfrom, struct player *pto, int prob, bool reveal_cities)
Transfer (random parts of) player pfrom's world map to pto.
void tile_claim_bases(struct tile *ptile, struct player *powner)
Claim ownership of bases on single tile.
void create_extra(struct tile *ptile, const extra_type *pextra, struct player *pplayer)
Create extra to tile.
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Returns whether the layer 'vlayer' of the tile 'ptile' is known and seen by the player 'pplayer'.
void map_show_circle(struct player *pplayer, struct tile *ptile, int radius_sq)
Shows the area to the player.
void update_tile_knowledge(struct tile *ptile)
Update playermap knowledge for everybody who sees the tile, and send a packet to everyone whose info ...
void check_terrain_change(struct tile *ptile, struct terrain *oldter)
Handles local and global side effects for a terrain change for a single tile.
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Players' information of tiles is tracked so that fogged area can be kept consistent even when the cli...
struct vision_site * map_get_player_site(const struct tile *ptile, const struct player *pplayer)
Returns site located at given tile from player map.
void vision_change_sight(struct vision *vision, const v_radius_t radius_sq)
Change the sight points for the vision source, fogging or unfogging tiles as needed.
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.
int unit_move_rate(const struct unit *punit)
This function calculates the move rate of the unit.
bool unit_could_load_at(const struct unit *punit, const struct tile *ptile)
Return whether we could find a suitable transporter for given unit at 'ptile'.
bool is_native_to_class(const struct unit_class *punitclass, const struct terrain *pterrain, const bv_extras *extras)
This terrain is native to unit class.
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_unit_being_refueled(const struct unit *punit)
Is unit being refueled in its current position.
static const char * name_translation_get(const struct name_translation *ptrans)
const char * nation_rule_name(const struct nation_type *pnation)
Return the (untranslated) rule name of the nation (adjective form).
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
struct nation_type * nation_of_unit(const struct unit *punit)
Return the nation of the player who owns the unit.
const char * nation_adjective_for_player(const struct player *pplayer)
Return the (translated) adjective for the given nation of a player.
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Similar to notify_conn_packet (see also), but takes player as "destination".
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
See notify_conn_packet - this is just the "non-v" version, with varargs.
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
Factory function to create a new map according to the parameter.
PFPath pf_map_path(struct pf_map *pfm, struct tile *ptile)
CHECK DOCS AFTER FULL CONVERSTION OF pf_path to class PFPath Tries to find the best path in the given...
void pf_map_destroy(struct pf_map *pfm)
After usage the map must be destroyed.
#define pf_map_move_costs_iterate_end
#define pf_map_move_costs_iterate(ARG_pfm, NAME_tile, NAME_cost, COND_from_start)
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
If the specified player owns the unit with the specified id, return pointer to the unit struct.
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Return TRUE if players are in the same team.
bool can_player_see_unit_at(const struct player *pplayer, const struct unit *punit, const struct tile *ptile, bool is_transported)
Checks if a unit can be seen by pplayer at (x,y).
struct player * player_by_number(const int player_id)
Return struct player pointer for the given player index.
int player_number(const struct player *pplayer)
Return the player index/number/id.
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.
int player_index(const struct player *pplayer)
Return the player index.
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
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.
#define players_iterate_end
#define players_iterate(_pplayer)
static bool is_barbarian(const struct player *pplayer)
struct conn_list * player_reply_dest(struct player *pplayer)
Convenience function to return "reply" destination connection list for player: pplayer->current_conn ...
void player_update_last_war_action(struct player *pplayer)
Update last war action timestamp (affects player mood).
void player_status_add(struct player *plr, enum player_status pstatus)
Add a status flag to a player.
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Check if we make contact with anyone.
void send_player_info_c(struct player *src, struct conn_list *dest)
Send information about player slot 'src', or all valid (i.e.
#define phase_players_iterate(pplayer)
#define phase_players_iterate_end
bool are_reqs_active(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, const struct requirement_vector *reqs, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Checks the requirement(s) to see if they are active on the given target.
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
QString research_advance_rule_name(const struct research *presearch, Tech_type_id tech)
Store the rule name of the given tech (including A_FUTURE) in 'buf'.
void script_server_signal_emit(const char *signal_name,...)
Invoke all the callback functions attached to a given signal.
void script_server_remove_exported_object(void *object)
Mark any, if exported, full userdata representing 'object' in the current script state as 'Nonexisten...
void flush_packets()
Attempt to flush all information in the send buffers for upto 'netwait' seconds.
void format_time_duration(time_t t, char *buf, int maxlen)
Convenience function to nicely format a time_t seconds value in to a string with hours,...
#define CLIP(lower, current, upper)
int identity_number()
Identity ids wrap at IDENTITY_NUMBER_SIZE, skipping IDENTITY_NUMBER_ZERO Setup in server_game_init()
enum act_tgt_compl target_complexity
struct unit_list * units_supported
struct civ_game::@28::@32 server
struct packet_ruleset_control control
struct conn_list * est_connections
struct packet_game_info info
A vertex in the path-finding graph.
tile * location
Where we are.
enum barbarian_type barbarian_type
std::unique_ptr< vision_site > site
struct city_list * cities
struct player_ai ai_common
struct player::@65::@67 server
struct conn_list * connections
struct player_economic economic
struct player_score score
struct unit_class::@81 cache
enum hut_behavior hut_behavior
struct extra_type_list * refuel_bases
struct vision * old_vision
enum unit_activity activity
const struct unit_type * converted_to
enum unit_activity activity
enum action_decision action_decision_want
enum unit_activity activity
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 goods_type * carrying
struct tile * action_decision_tile
const struct unit_type * utype
enum server_side_agent ssa_controller
struct name_translation name
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
#define sz_strlcpy(dest, src)
struct advance * valid_advance_by_number(const Tech_type_id id)
Returns pointer when the advance "exists" in this game, returns nullptr otherwise.
struct extra_type * get_preferred_pillage(bv_extras extras)
Returns the highest-priority (best) extra to be pillaged from the terrain set.
const char * terrain_name_translation(const struct terrain *pterrain)
Return the (translated) name of the terrain.
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Adds extra to tile.
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Check if tile contains base providing effect for unit.
bool tile_apply_activity(struct tile *ptile, Activity_type_id act, struct extra_type *tgt)
Apply an activity (Activity_type_id, e.g., ACTIVITY_TRANSFORM) to a tile.
int tile_extras_defense_bonus(const struct tile *ptile, const struct unit_type *punittype)
Calculate defense bonus given for unit type by bases and roads.
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.
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)
static const bv_extras * tile_extras(const struct tile *ptile)
#define tile_continent(_tile)
#define tile_has_extra(ptile, pextra)
#define tile_owner(_tile)
struct goods_type * goods_from_city_to_unit(struct city *src, struct unit *punit)
Return goods type for the new traderoute between given cities.
Goods_type_id goods_index(const struct goods_type *pgood)
Return the goods index.
int get_transporter_occupancy(const struct unit *ptrans)
Return how many units are in the transport.
void free_unit_orders(struct unit *punit)
Free and reset the unit's goto route (punit->pgr).
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.
bool unit_is_alive(int id)
Check if unit with given id is still alive.
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.
bool unit_transport_load(struct unit *pcargo, struct unit *ptrans, bool force)
Load pcargo onto ptrans.
void set_unit_activity(struct unit *punit, enum unit_activity new_activity)
Assign a new untargeted task to a unit.
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.
struct unit * is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non-allied unit on this tile?
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 can_unit_continue_current_activity(struct unit *punit)
Check if the unit's current activity is actually legal.
bool unit_can_convert(const struct unit *punit)
Tests if unit can be converted to another type.
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.
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.
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.
bool unit_transported(const struct unit *pcargo)
Returns TRUE iff the unit is transported.
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.
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.
#define unit_cargo_iterate_end
#define unit_cargo_iterate(_ptrans, _pcargo)
#define CHECK_UNIT(punit)
bool unit_move_handling(struct unit *punit, struct tile *pdesttile, bool igzoc, bool move_do_not_act)
Will try to move to/attack the tile dest_x,dest_y.
void handle_unit_orders(struct player *pplayer, const struct packet_unit_orders *packet)
Receives route packages.
void illegal_action_msg(struct player *pplayer, const enum event_type event, struct unit *actor, const action_id stopped_action, const struct tile *target_tile, const struct city *target_city, const struct unit *target_unit)
Try to explain to the player why an action is illegal.
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Handle request for changing activity.
bool unit_perform_action(struct player *pplayer, const int actor_id, const int target_id, const int sub_tgt_id_incoming, const char *name, const action_id action_type, const enum action_requester requester)
Execute a request to perform an action and let the caller know if it was performed or not.
void handle_unit_server_side_agent_set(struct player *pplayer, int unit_id, enum server_side_agent agent)
Handle request to change controlling server side agent.
#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.
bool utype_is_moved_to_tgt_by_action(const struct action *paction, const struct unit_type *utype)
Returns TRUE iff successfully performing the specified action always will move the actor unit of the ...
struct unit_type * best_role_unit_for_player(const struct player *pplayer, int role)
Return "best" unit the player can build, with given role/flag.
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 num_role_units(int role)
How many unit types have specified role/flag.
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Returns TRUE iff the unit type is unique and the player already has one.
struct unit_class * unit_class_get(const struct unit *punit)
Returns unit class pointer for a unit.
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype)
Whether player can build given unit somewhere, ignoring whether unit is obsolete and assuming the pla...
bool unit_has_type_role(const struct unit *punit, enum unit_role_id role)
Return whether the unit has the given role.
const struct veteran_system * utype_veteran_system(const struct unit_type *punittype)
Return veteran system used for this unit type.
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.
bool utype_is_consumed_by_action(const struct action *paction, const struct unit_type *utype)
Returns TRUE iff performing the specified action will consume an actor unit of the specified type.
Unit_type_id utype_number(const struct unit_type *punittype)
Return the unit type index.
struct unit_type * get_role_unit(int role, int role_index)
Return index-th unit with specified role/flag.
const char * unit_name_translation(const struct unit *punit)
Return the (translated) name of the unit.
bool utype_is_unmoved_by_action(const struct action *paction, const struct unit_type *utype)
Returns TRUE iff successfully performing the specified action never will move the actor unit from its...
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)
struct vision * vision_new(struct player *pplayer, struct tile *ptile)
Create a new vision source.
void vision_free(struct vision *vision)
Free the vision source.
#define V_RADIUS(main_sq, invis_sq, subs_sq)
#define vision_site_owner(v)
short int v_radius_t[V_COUNT]