Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/unit.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
unit.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "astring.h"
20#include "bitvector.h"
21#include "fcintl.h"
22#include "mem.h"
23#include "shared.h"
24#include "support.h"
25
26/* common */
27#include "ai.h"
28#include "actions.h"
29#include "base.h"
30#include "city.h"
31#include "game.h"
32#include "log.h"
33#include "map.h"
34#include "movement.h"
35#include "packets.h"
36#include "player.h"
37#include "road.h"
38#include "tech.h"
39#include "traderoutes.h"
40#include "unitlist.h"
41
42#include "unit.h"
43
44 Activity_type_id real_activities[ACTIVITY_LAST];
45
46 const Activity_type_id tile_changing_activities[] =
47 { ACTIVITY_PILLAGE, ACTIVITY_GEN_ROAD, ACTIVITY_IRRIGATE, ACTIVITY_MINE,
48 ACTIVITY_BASE, ACTIVITY_CULTIVATE, ACTIVITY_PLANT, ACTIVITY_TRANSFORM,
49 ACTIVITY_POLLUTION, ACTIVITY_FALLOUT, ACTIVITY_LAST };
50
51 struct cargo_iter {
52 struct iterator vtable;
53 const struct unit_list_link *links[GAME_TRANSPORT_MAX_RECURSIVE];
54 int depth;
55};
56#define CARGO_ITER(iter) ((struct cargo_iter *) (iter))
57
58/**********************************************************************/
61 bool are_unit_orders_equal(const struct unit_order *order1,
62 const struct unit_order *order2)
63{
64 return order1->order == order2->order
65 && order1->activity == order2->activity
66 && order1->target == order2->target
67 && order1->sub_target == order2->sub_target
68 && order1->action == order2->action
69 && order1->dir == order2->dir;
70}
71
72/**********************************************************************/
82enum unit_airlift_result
83 test_unit_can_airlift_to(const struct civ_map *nmap,
84 const struct player *restriction,
85 const struct unit *punit,
86 const struct city *pdest_city)
87{
88 const struct city *psrc_city = tile_city(unit_tile(punit));
89 const struct player *punit_owner;
90 enum unit_airlift_result ok_result = AR_OK;
91
92 if (0 == punit->moves_left
93 && !utype_may_act_move_frags(unit_type_get(punit),
94 ACTION_AIRLIFT, 0)) {
95 /* No moves left. */
96 return AR_NO_MOVES;
97 }
98
99 if (!unit_can_do_action(punit, ACTION_AIRLIFT)) {
100 return AR_WRONG_UNITTYPE;
101 }
102
103 if (0 < get_transporter_occupancy(punit)) {
104 /* Units with occupants can't be airlifted currently. */
105 return AR_OCCUPIED;
106 }
107
108 if (NULL == psrc_city) {
109 /* No city there. */
110 return AR_NOT_IN_CITY;
111 }
112
113 if (psrc_city == pdest_city) {
114 /* Airlifting to our current position doesn't make sense. */
115 return AR_BAD_DST_CITY;
116 }
117
118 if (pdest_city
119 && (NULL == restriction
120 || (tile_get_known(city_tile(pdest_city), restriction)
121 == TILE_KNOWN_SEEN))
122 && !can_unit_exist_at_tile(nmap, punit, city_tile(pdest_city))) {
123 /* Can't exist at the destination tile. */
124 return AR_BAD_DST_CITY;
125 }
126
127 punit_owner = unit_owner(punit);
128
129 /* Check validity of both source and destination before checking capacity,
130 * to avoid misleadingly optimistic returns. */
131
132 if (punit_owner != city_owner(psrc_city)
133 && !(game.info.airlifting_style & AIRLIFTING_ALLIED_SRC
134 && pplayers_allied(punit_owner, city_owner(psrc_city)))) {
135 /* Not allowed to airlift from this source. */
136 return AR_BAD_SRC_CITY;
137 }
138
139 if (pdest_city
140 && punit_owner != city_owner(pdest_city)
141 && !(game.info.airlifting_style & AIRLIFTING_ALLIED_DEST
142 && pplayers_allied(punit_owner, city_owner(pdest_city)))) {
143 /* Not allowed to airlift to this destination. */
144 return AR_BAD_DST_CITY;
145 }
146
147 if (NULL == restriction || city_owner(psrc_city) == restriction) {
148 /* We know for sure whether or not src can airlift this turn. */
149 if (0 >= psrc_city->airlift
150 && (!(game.info.airlifting_style & AIRLIFTING_UNLIMITED_SRC)
151 || !game.info.airlift_from_always_enabled)) {
152 /* The source cannot airlift for this turn (maybe already airlifted
153 * or no airport).
154 * See also do_airline() in server/unittools.h. */
155 return AR_SRC_NO_FLIGHTS;
156 } /* else, there is capacity; continue to other checks */
157 } else {
158 /* We don't have access to the 'airlift' field. Assume it's OK; can
159 * only find out for sure by trying it. */
160 ok_result = AR_OK_SRC_UNKNOWN;
161 }
162
163 if (pdest_city) {
164 if (NULL == restriction || city_owner(pdest_city) == restriction) {
165 if (0 >= pdest_city->airlift
166 && (!(game.info.airlifting_style & AIRLIFTING_UNLIMITED_DEST)
167 || !game.info.airlift_to_always_enabled)) {
168 /* The destination cannot support airlifted units for this turn
169 * (maybe already airlifted or no airport).
170 * See also do_airline() in server/unittools.h. */
171 return AR_DST_NO_FLIGHTS;
172 } /* else continue */
173 } else {
174 ok_result = AR_OK_DST_UNKNOWN;
175 }
176 }
177
178 return ok_result;
179}
180
181/**********************************************************************/
188 bool unit_can_airlift_to(const struct unit *punit,
189 const struct city *pdest_city)
190{
191 const struct civ_map *nmap = &(wld.map);
192
193 fc_assert_ret_val(pdest_city, FALSE);
194
195 if (is_server()) {
196 return is_action_enabled_unit_on_city(nmap, ACTION_AIRLIFT,
197 punit, pdest_city);
198 } else {
199 return action_prob_possible(action_prob_vs_city(punit, ACTION_AIRLIFT,
200 pdest_city));
201 }
202}
203
204/**********************************************************************/
207 bool unit_has_orders(const struct unit *punit)
208{
209 return punit->has_orders;
210}
211
212/**********************************************************************/
219 int unit_shield_value(const struct unit *punit,
220 const struct unit_type *punittype,
221 const struct action *paction)
222{
223 int value;
224
225 bool has_unit;
226 const struct player *act_player;
227
228 has_unit = punit != NULL;
229
230 if (has_unit && punittype == NULL) {
231 punittype = unit_type_get(punit);
232 }
233
234 fc_assert_ret_val(punittype != NULL, 0);
235 fc_assert(punit == NULL || unit_type_get(punit) == punittype);
236 fc_assert_ret_val(paction != NULL, 0);
237
238 act_player = has_unit ? unit_owner(punit) : NULL;
239 /* TODO: determine if tile and city should be where the unit currently is
240 * located or the target city. Those two may differ. Wait for ruleset
241 * author feed back. */
242
243 value = utype_build_shield_cost_base(punittype);
244 value += ((value
245 * get_target_bonus_effects(NULL,
246 &(const struct req_context) {
247 .player = act_player,
248 .unit = punit,
249 .unittype = punittype,
250 .action = paction,
251 },
252 NULL,
253 EFT_UNIT_SHIELD_VALUE_PCT))
254 / 100);
255
256 return value;
257}
258
259/**********************************************************************/
263 bool unit_can_help_build_wonder_here(const struct unit *punit)
264{
265 struct city *pcity = tile_city(unit_tile(punit));
266
267 if (!pcity) {
268 /* No city to help at this tile. */
269 return FALSE;
270 }
271
272 if (!utype_can_do_action(unit_type_get(punit), ACTION_HELP_WONDER)) {
273 /* This unit can never do help wonder. */
274 return FALSE;
275 }
276
277 /* Evaluate all action enablers for extra accuracy. */
278 /* TODO: Is it worth it? */
279 return action_prob_possible(action_prob_vs_city(punit,
280 ACTION_HELP_WONDER,
281 pcity));
282}
283
284/**********************************************************************/
288 bool unit_can_est_trade_route_here(const struct unit *punit)
289{
290 struct city *phomecity, *pdestcity;
291
292 return (utype_can_do_action(unit_type_get(punit), ACTION_TRADE_ROUTE)
293 && (pdestcity = tile_city(unit_tile(punit)))
294 && (phomecity = game_city_by_number(punit->homecity))
295 && can_cities_trade(phomecity, pdestcity));
296}
297
298/**********************************************************************/
301 int get_transporter_capacity(const struct unit *punit)
302{
303 return unit_type_get(punit)->transport_capacity;
304}
305
306/**********************************************************************/
309 bool is_attack_unit(const struct unit *punit)
310{
311 return ((unit_can_do_action_result(punit, ACTRES_ATTACK)
312 || unit_can_do_action_result(punit, ACTRES_BOMBARD))
313 && unit_type_get(punit)->attack_strength > 0);
314}
315
316/**********************************************************************/
321 bool is_military_unit(const struct unit *punit)
322{
323 return !unit_has_type_flag(punit, UTYF_CIVILIAN);
324}
325
326/**********************************************************************/
330 bool unit_can_do_action(const struct unit *punit,
331 const action_id act_id)
332{
333 return utype_can_do_action(unit_type_get(punit), act_id);
334}
335
336/**********************************************************************/
340 bool unit_can_do_action_result(const struct unit *punit,
341 enum action_result result)
342{
343 return utype_can_do_action_result(unit_type_get(punit), result);
344}
345
346/**********************************************************************/
350 bool unit_can_do_action_sub_result(const struct unit *punit,
351 enum action_sub_result sub_result)
352{
353 return utype_can_do_action_sub_result(unit_type_get(punit), sub_result);
354}
355
356/**********************************************************************/
359 bool is_square_threatened(const struct civ_map *nmap,
360 const struct player *pplayer,
361 const struct tile *ptile, bool omniscient)
362{
363 square_iterate(nmap, ptile, 2, ptile1) {
364 unit_list_iterate(ptile1->units, punit) {
365 if ((omniscient
366 || can_player_see_unit(pplayer, punit))
367 && pplayers_at_war(pplayer, unit_owner(punit))
368 && utype_acts_hostile(unit_type_get(punit))
369 && (is_native_tile(unit_type_get(punit), ptile)
370 || (can_attack_non_native(unit_type_get(punit))
371 && is_native_near_tile(nmap,
372 unit_class_get(punit), ptile)))) {
373 return TRUE;
374 }
375 } unit_list_iterate_end;
376 } square_iterate_end;
377
378 return FALSE;
379}
380
381/**********************************************************************/
385 bool is_field_unit(const struct unit *punit)
386{
387 return unit_has_type_flag(punit, UTYF_FIELDUNIT);
388}
389
390/**********************************************************************/
397 bool is_hiding_unit(const struct unit *punit)
398{
399 enum vision_layer vl = unit_type_get(punit)->vlayer;
400
401 if (vl == V_INVIS || vl == V_SUBSURFACE) {
402 return TRUE;
403 }
404
405 if (unit_transported(punit)) {
406 vl = unit_type_get(unit_transport_get(punit))->vlayer;
407 if (vl == V_INVIS || vl == V_SUBSURFACE) {
408 return TRUE;
409 }
410 }
411
412 return FALSE;
413}
414
415/**********************************************************************/
419 bool kills_citizen_after_attack(const struct unit *punit)
420{
421 return game.info.killcitizen
422 && uclass_has_flag(unit_class_get(punit), UCF_KILLCITIZEN);
423}
424
425/**********************************************************************/
429 bool unit_can_add_or_build_city(const struct unit *punit)
430{
431 struct city *tgt_city;
432
433 if ((tgt_city = tile_city(unit_tile(punit)))) {
434 return action_prob_possible(action_prob_vs_city(punit,
435 ACTION_JOIN_CITY, tgt_city));
436 } else {
437 return action_prob_possible(action_prob_vs_tile(punit,
438 ACTION_FOUND_CITY, unit_tile(punit), NULL));
439 }
440}
441
442/**********************************************************************/
445 bool can_unit_change_homecity_to(const struct unit *punit,
446 const struct city *pcity)
447{
448 if (pcity == NULL) {
449 /* Can't change home city to a non existing city. */
450 return FALSE;
451 }
452
453 return action_prob_possible(action_prob_vs_city(punit, ACTION_HOME_CITY,
454 pcity));
455}
456
457/**********************************************************************/
460 bool can_unit_change_homecity(const struct unit *punit)
461{
462 return can_unit_change_homecity_to(punit, tile_city(unit_tile(punit)));
463}
464
465/**********************************************************************/
473 int get_activity_rate(const struct unit *punit)
474{
475 const struct veteran_level *vlevel;
476
477 fc_assert_ret_val(punit != NULL, 0);
478
479 vlevel = utype_veteran_level(unit_type_get(punit), punit->veteran);
480 fc_assert_ret_val(vlevel != NULL, 0);
481
482 /* The speed of the settler depends on its base move_rate, not on
483 * the number of moves actually remaining or the adjusted move rate.
484 * This means sea formers won't have their activity rate increased by
485 * Magellan's, and it means injured units work just as fast as
486 * uninjured ones. Note the value is never less than SINGLE_MOVE. */
487 int move_rate = unit_type_get(punit)->move_rate;
488
489 /* All settler actions are multiplied by ACTIVITY_FACTOR. */
490 return ACTIVITY_FACTOR
491 * (float)vlevel->power_fact / 100
492 * move_rate / SINGLE_MOVE;
493}
494
495/**********************************************************************/
501 int get_activity_rate_this_turn(const struct unit *punit)
502{
503 /* This logic is also coded in client/goto.c. */
504 if (punit->moves_left > 0) {
505 return get_activity_rate(punit);
506 } else {
507 return 0;
508 }
509}
510
511/**********************************************************************/
517 int get_turns_for_activity_at(const struct unit *punit,
518 enum unit_activity activity,
519 const struct tile *ptile,
520 struct extra_type *tgt)
521{
522 /* FIXME: This is just an approximation since we don't account for
523 * get_activity_rate_this_turn. */
524 int speed = get_activity_rate(punit);
525 int points_needed = tile_activity_time(activity, ptile, tgt);
526
527 if (points_needed >= 0 && speed > 0) {
528 return (points_needed - 1) / speed + 1; /* round up */
529 } else {
530 return FC_INFINITY;
531 }
532}
533
534/**********************************************************************/
537 bool activity_requires_target(enum unit_activity activity)
538{
539 switch (activity) {
540 case ACTIVITY_PILLAGE:
541 case ACTIVITY_BASE:
542 case ACTIVITY_GEN_ROAD:
543 case ACTIVITY_IRRIGATE:
544 case ACTIVITY_MINE:
545 case ACTIVITY_POLLUTION:
546 case ACTIVITY_FALLOUT:
547 return TRUE;
548 case ACTIVITY_IDLE:
549 case ACTIVITY_FORTIFIED:
550 case ACTIVITY_SENTRY:
551 case ACTIVITY_GOTO:
552 case ACTIVITY_EXPLORE:
553 case ACTIVITY_TRANSFORM:
554 case ACTIVITY_CULTIVATE:
555 case ACTIVITY_PLANT:
556 case ACTIVITY_FORTIFYING:
557 case ACTIVITY_CONVERT:
558 return FALSE;
559 /* These shouldn't be kicking around internally. */
560 case ACTIVITY_FORTRESS:
561 case ACTIVITY_AIRBASE:
562 case ACTIVITY_PATROL_UNUSED:
563 default:
564 fc_assert_ret_val(FALSE, FALSE);
565 }
566
567 return FALSE;
568}
569
570/**********************************************************************/
579 bool can_unit_do_autosettlers(const struct unit *punit)
580{
581 return unit_type_get(punit)->adv.worker;
582}
583
584/**********************************************************************/
587 void setup_real_activities_array(void)
588{
589 Activity_type_id act;
590 int i = 0;
591
592 for (act = 0; act < ACTIVITY_LAST; act++) {
593 if (is_real_activity(act)) {
594 real_activities[i++] = act;
595 }
596 }
597
598 real_activities[i] = ACTIVITY_LAST;
599}
600
601/**********************************************************************/
605 bool is_real_activity(enum unit_activity activity)
606{
607 /* ACTIVITY_FORTRESS, ACTIVITY_AIRBASE, ACTIVITY_OLD_ROAD, and
608 * ACTIVITY_OLD_RAILROAD are deprecated */
609 return (activity < ACTIVITY_LAST)
610 && activity != ACTIVITY_FORTRESS
611 && activity != ACTIVITY_AIRBASE
612 && activity != ACTIVITY_OLD_ROAD
613 && activity != ACTIVITY_OLD_RAILROAD
614 && activity != ACTIVITY_UNKNOWN
615 && activity != ACTIVITY_PATROL_UNUSED;
616}
617
618/**********************************************************************/
621 const char *get_activity_text(enum unit_activity activity)
622{
623 /* The switch statement has just the activities listed with no "default"
624 * handling. This enables the compiler to detect missing entries
625 * automatically, and still handles everything correctly. */
626 switch (activity) {
627 case ACTIVITY_IDLE:
628 return _("Idle");
629 case ACTIVITY_POLLUTION:
630 return _("Pollution");
631 case ACTIVITY_MINE:
632 /* TRANS: Activity name, verb in English */
633 return Q_("?act:Mine");
634 case ACTIVITY_PLANT:
635 /* TRANS: Activity name, verb in English */
636 return _("Plant");
637 case ACTIVITY_IRRIGATE:
638 return _("Irrigate");
639 case ACTIVITY_CULTIVATE:
640 return _("Cultivate");
641 case ACTIVITY_FORTIFYING:
642 return _("Fortifying");
643 case ACTIVITY_FORTIFIED:
644 return _("Fortified");
645 case ACTIVITY_SENTRY:
646 return _("Sentry");
647 case ACTIVITY_PILLAGE:
648 return _("Pillage");
649 case ACTIVITY_GOTO:
650 return _("Goto");
651 case ACTIVITY_EXPLORE:
652 return _("Explore");
653 case ACTIVITY_TRANSFORM:
654 return _("Transform");
655 case ACTIVITY_FALLOUT:
656 return _("Fallout");
657 case ACTIVITY_BASE:
658 return _("Base");
659 case ACTIVITY_GEN_ROAD:
660 return _("Road");
661 case ACTIVITY_CONVERT:
662 return _("Convert");
663 case ACTIVITY_OLD_ROAD:
664 case ACTIVITY_OLD_RAILROAD:
665 case ACTIVITY_FORTRESS:
666 case ACTIVITY_AIRBASE:
667 case ACTIVITY_UNKNOWN:
668 case ACTIVITY_PATROL_UNUSED:
669 case ACTIVITY_LAST:
670 break;
671 }
672
673 fc_assert(FALSE);
674 return _("Unknown");
675}
676
677/**********************************************************************/
683 bool could_unit_be_in_transport(const struct unit *pcargo,
684 const struct unit *ptrans)
685{
686 /* Make sure this transporter can carry this type of unit. */
687 if (!can_unit_transport(ptrans, pcargo)) {
688 return FALSE;
689 }
690
691 /* Make sure there's room in the transporter. */
692 if (get_transporter_occupancy(ptrans)
693 >= get_transporter_capacity(ptrans)) {
694 return FALSE;
695 }
696
697 /* Check iff this is a valid transport. */
698 if (!unit_transport_check(pcargo, ptrans)) {
699 return FALSE;
700 }
701
702 /* Check transport depth. */
703 if (GAME_TRANSPORT_MAX_RECURSIVE
704 < 1 + unit_transport_depth(ptrans) + unit_cargo_depth(pcargo)) {
705 return FALSE;
706 }
707
708 return TRUE;
709}
710
711/**********************************************************************/
715 bool could_unit_load(const struct unit *pcargo, const struct unit *ptrans)
716{
717 if (!pcargo || !ptrans || pcargo == ptrans) {
718 return FALSE;
719 }
720
721 /* Double-check ownership of the units: you can load into an allied unit
722 * (of course only allied units can be on the same tile). */
723 if (!pplayers_allied(unit_owner(pcargo), unit_owner(ptrans))) {
724 return FALSE;
725 }
726
727 /* Un-embarkable transport must be in city or base to load cargo. */
728 if (!utype_can_freely_load(unit_type_get(pcargo), unit_type_get(ptrans))
729 && !tile_city(unit_tile(ptrans))
730 && !tile_has_native_base(unit_tile(ptrans), unit_type_get(ptrans))) {
731 return FALSE;
732 }
733
734 return could_unit_be_in_transport(pcargo, ptrans);
735}
736
737/**********************************************************************/
740 bool can_unit_load(const struct unit *pcargo, const struct unit *ptrans)
741{
742 /* This function needs to check EVERYTHING. */
743
744 /* Check positions of the units. Of course you can't load a unit onto
745 * a transporter on a different tile... */
746 if (!same_pos(unit_tile(pcargo), unit_tile(ptrans))) {
747 return FALSE;
748 }
749
750 /* Cannot load if cargo is already loaded onto something else. */
751 if (unit_transported(pcargo)) {
752 return FALSE;
753 }
754
755 return could_unit_load(pcargo, ptrans);
756}
757
758/**********************************************************************/
767 bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
768{
769 if (!pcargo || !ptrans) {
770 return FALSE;
771 }
772
773 /* Make sure the unit's transporter exists and is known. */
774 if (unit_transport_get(pcargo) != ptrans) {
775 return FALSE;
776 }
777
778 /* Un-disembarkable transport must be in city or base to unload cargo. */
779 if (!utype_can_freely_unload(unit_type_get(pcargo), unit_type_get(ptrans))
780 && !tile_city(unit_tile(ptrans))
781 && !tile_has_native_base(unit_tile(ptrans), unit_type_get(ptrans))) {
782 return FALSE;
783 }
784
785 return TRUE;
786}
787
788/**********************************************************************/
792 bool can_unit_alight_or_be_unloaded(const struct unit *pcargo,
793 const struct unit *ptrans)
794{
795 const struct civ_map *nmap = &(wld.map);
796
797 if (!pcargo || !ptrans) {
798 return FALSE;
799 }
800
801 fc_assert_ret_val(unit_transport_get(pcargo) == ptrans, FALSE);
802
803 if (is_server()) {
804 return (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_ALIGHT,
805 pcargo, ptrans)
806 || is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_UNLOAD,
807 ptrans, pcargo));
808 } else {
809 return (action_prob_possible(
810 action_prob_vs_unit(pcargo, ACTION_TRANSPORT_ALIGHT, ptrans))
811 || action_prob_possible(
812 action_prob_vs_unit(ptrans, ACTION_TRANSPORT_UNLOAD,
813 pcargo)));
814 }
815}
816
817
818/**********************************************************************/
823 bool can_unit_paradrop(const struct civ_map *nmap, const struct unit *punit)
824{
825 action_by_result_iterate(paction, ACTRES_PARADROP) {
826 if (action_maybe_possible_actor_unit(nmap, paction->id, punit)) {
827 return TRUE;
828 }
829 } action_by_result_iterate_end;
830 action_by_result_iterate(paction, ACTRES_PARADROP_CONQUER) {
831 if (action_maybe_possible_actor_unit(nmap, paction->id, punit)) {
832 return TRUE;
833 }
834 } action_by_result_iterate_end;
835
836 return FALSE;
837}
838
839/**********************************************************************/
842 bool can_unit_continue_current_activity(const struct civ_map *nmap,
843 struct unit *punit)
844{
845 enum unit_activity current = punit->activity;
846 struct extra_type *target = punit->activity_target;
847 enum unit_activity current2 =
848 (current == ACTIVITY_FORTIFIED) ? ACTIVITY_FORTIFYING : current;
849 bool result;
850
851 punit->activity = ACTIVITY_IDLE;
852 punit->activity_target = NULL;
853
854 result = can_unit_do_activity_targeted(nmap, punit, current2, target);
855
856 punit->activity = current;
857 punit->activity_target = target;
858
859 return result;
860}
861
862/**********************************************************************/
869 bool can_unit_do_activity(const struct civ_map *nmap,
870 const struct unit *punit,
871 enum unit_activity activity)
872{
873 struct extra_type *target = NULL;
874
875 /* FIXME: Lots of callers (usually client real_menus_update()) rely on
876 * being able to find out whether an activity is in general possible.
877 * Find one for them, but when they come to do the activity, they will
878 * have to determine the target themselves */
879 {
880 struct tile *ptile = unit_tile(punit);
881
882 if (activity == ACTIVITY_IRRIGATE) {
883 target = next_extra_for_tile(ptile,
884 EC_IRRIGATION,
885 unit_owner(punit),
886 punit);
887 if (NULL == target) {
888 return FALSE; /* No more irrigation extras available. */
889 }
890 } else if (activity == ACTIVITY_MINE) {
891 target = next_extra_for_tile(ptile,
892 EC_MINE,
893 unit_owner(punit),
894 punit);
895 if (NULL == target) {
896 return FALSE; /* No more mine extras available. */
897 }
898 }
899 }
900
901 return can_unit_do_activity_targeted(nmap, punit, activity, target);
902}
903
904/**********************************************************************/
908 bool can_unit_do_activity_targeted(const struct civ_map *nmap,
909 const struct unit *punit,
910 enum unit_activity activity,
911 struct extra_type *target)
912{
913 return can_unit_do_activity_targeted_at(nmap, punit, activity, target,
914 unit_tile(punit));
915}
916
917/**********************************************************************/
921 bool can_unit_do_activity_targeted_at(const struct civ_map *nmap,
922 const struct unit *punit,
923 enum unit_activity activity,
924 struct extra_type *target,
925 const struct tile *ptile)
926{
927 /* Check that no build activity conflicting with one already in progress
928 * gets executed. */
929 /* FIXME: Should check also the cases where one of the activities is terrain
930 * change that destroys the target of the other activity */
931 if (target != NULL && is_build_activity(activity)) {
932 if (tile_is_placing(ptile)) {
933 return FALSE;
934 }
935
936 unit_list_iterate(ptile->units, tunit) {
937 if (is_build_activity(tunit->activity)
938 && !can_extras_coexist(target, tunit->activity_target)) {
939 return FALSE;
940 }
941 } unit_list_iterate_end;
942 }
943
944#define RETURN_IS_ACTIVITY_ENABLED_UNIT_ON(paction) \
945{ \
946 switch (action_get_target_kind(paction)) { \
947 case ATK_TILE: \
948 return is_action_enabled_unit_on_tile(nmap, paction->id, \
949 punit, ptile, target); \
950 case ATK_EXTRAS: \
951 return is_action_enabled_unit_on_extras(nmap, paction->id, \
952 punit, ptile, target); \
953 case ATK_CITY: \
954 case ATK_UNIT: \
955 case ATK_UNITS: \
956 case ATK_SELF: \
957 return FALSE; \
958 case ATK_COUNT: \
959 break; /* Handle outside switch */ \
960 } \
961 fc_assert(action_target_kind_is_valid( \
962 action_get_target_kind(paction))); \
963 return FALSE; \
964 }
965
966 switch (activity) {
967 case ACTIVITY_IDLE:
968 case ACTIVITY_GOTO:
969 return TRUE;
970
971 case ACTIVITY_POLLUTION:
972 /* The call below doesn't support actor tile speculation. */
973 fc_assert_msg(unit_tile(punit) == ptile,
974 "Please use action_speculate_unit_on_tile()");
975 return is_action_enabled_unit_on_tile(nmap, ACTION_CLEAN_POLLUTION,
976 punit, ptile, target);
977
978 case ACTIVITY_FALLOUT:
979 /* The call below doesn't support actor tile speculation. */
980 fc_assert_msg(unit_tile(punit) == ptile,
981 "Please use action_speculate_unit_on_tile()");
982 return is_action_enabled_unit_on_tile(nmap, ACTION_CLEAN_FALLOUT,
983 punit, ptile, target);
984
985 case ACTIVITY_MINE:
986 /* The call below doesn't support actor tile speculation. */
987 fc_assert_msg(unit_tile(punit) == ptile,
988 "Please use action_speculate_unit_on_tile()");
989 return is_action_enabled_unit_on_tile(nmap, ACTION_MINE, punit,
990 ptile, target);
991
992 case ACTIVITY_PLANT:
993 /* The call below doesn't support actor tile speculation. */
994 fc_assert_msg(unit_tile(punit) == ptile,
995 "Please use action_speculate_unit_on_tile()");
996 return is_action_enabled_unit_on_tile(nmap, ACTION_PLANT,
997 punit, ptile, NULL);
998
999 case ACTIVITY_IRRIGATE:
1000 /* The call below doesn't support actor tile speculation. */
1001 fc_assert_msg(unit_tile(punit) == ptile,
1002 "Please use action_speculate_unit_on_tile()");
1003 return is_action_enabled_unit_on_tile(nmap, ACTION_IRRIGATE, punit,
1004 ptile, target);
1005
1006 case ACTIVITY_CULTIVATE:
1007 /* The call below doesn't support actor tile speculation. */
1008 fc_assert_msg(unit_tile(punit) == ptile,
1009 "Please use action_speculate_unit_on_tile()");
1010 return is_action_enabled_unit_on_tile(nmap, ACTION_CULTIVATE,
1011 punit, ptile, NULL);
1012
1013 case ACTIVITY_FORTIFYING:
1014 /* The call below doesn't support actor tile speculation. */
1015 fc_assert_msg(unit_tile(punit) == ptile,
1016 "Please use action_speculate_unit_on_self()");
1017 return is_action_enabled_unit_on_self(ACTION_FORTIFY,
1018 punit);
1019
1020 case ACTIVITY_FORTIFIED:
1021 return FALSE;
1022
1023 case ACTIVITY_BASE:
1024 /* The call below doesn't support actor tile speculation. */
1025 fc_assert_msg(unit_tile(punit) == ptile,
1026 "Please use action_speculate_unit_on_tile()");
1027 return is_action_enabled_unit_on_tile(nmap, ACTION_BASE,
1028 punit, ptile, target);
1029
1030 case ACTIVITY_GEN_ROAD:
1031 /* The call below doesn't support actor tile speculation. */
1032 fc_assert_msg(unit_tile(punit) == ptile,
1033 "Please use action_speculate_unit_on_tile()");
1034 return is_action_enabled_unit_on_tile(nmap, ACTION_ROAD,
1035 punit, ptile, target);
1036
1037 case ACTIVITY_SENTRY:
1038 if (!can_unit_survive_at_tile(nmap, punit, unit_tile(punit))
1039 && !unit_transported(punit)) {
1040 /* Don't let units sentry on tiles they will die on. */
1041 return FALSE;
1042 }
1043 return TRUE;
1044
1045 case ACTIVITY_PILLAGE:
1046 /* The call below doesn't support actor tile speculation. */
1047 fc_assert_msg(unit_tile(punit) == ptile,
1048 "Please use action_speculate_unit_on_tile()");
1049 RETURN_IS_ACTIVITY_ENABLED_UNIT_ON(action_by_number(ACTION_PILLAGE));
1050
1051 case ACTIVITY_EXPLORE:
1052 return (!unit_type_get(punit)->fuel && !is_losing_hp(punit));
1053
1054 case ACTIVITY_TRANSFORM:
1055 /* The call below doesn't support actor tile speculation. */
1056 fc_assert_msg(unit_tile(punit) == ptile,
1057 "Please use action_speculate_unit_on_tile()");
1058 return is_action_enabled_unit_on_tile(nmap, ACTION_TRANSFORM_TERRAIN,
1059 punit, ptile, NULL);
1060
1061 case ACTIVITY_CONVERT:
1062 /* The call below doesn't support actor tile speculation. */
1063 fc_assert_msg(unit_tile(punit) == ptile,
1064 "Please use action_speculate_unit_on_self()");
1065 return is_action_enabled_unit_on_self(ACTION_CONVERT, punit);
1066
1067 case ACTIVITY_OLD_ROAD:
1068 case ACTIVITY_OLD_RAILROAD:
1069 case ACTIVITY_FORTRESS:
1070 case ACTIVITY_AIRBASE:
1071 case ACTIVITY_PATROL_UNUSED:
1072 case ACTIVITY_LAST:
1073 case ACTIVITY_UNKNOWN:
1074 break;
1075 }
1076 log_error("can_unit_do_activity_targeted_at() unknown activity %d",
1077 activity);
1078 return FALSE;
1079
1080#undef RETURN_IS_ACTIVITY_ENABLED_UNIT_ON
1081}
1082
1083/**********************************************************************/
1086 static void set_unit_activity_internal(struct unit *punit,
1087 enum unit_activity new_activity)
1088{
1089 fc_assert_ret(new_activity != ACTIVITY_FORTRESS
1090 && new_activity != ACTIVITY_AIRBASE);
1091
1092 punit->activity = new_activity;
1093 punit->activity_count = 0;
1094 punit->activity_target = NULL;
1095 if (new_activity == ACTIVITY_IDLE && punit->moves_left > 0) {
1096 /* No longer done. */
1097 punit->done_moving = FALSE;
1098 }
1099}
1100
1101/**********************************************************************/
1104 void set_unit_activity(struct unit *punit, enum unit_activity new_activity)
1105{
1106 fc_assert_ret(!activity_requires_target(new_activity));
1107
1108 if (new_activity == ACTIVITY_FORTIFYING
1109 && punit->changed_from == ACTIVITY_FORTIFIED) {
1110 new_activity = ACTIVITY_FORTIFIED;
1111 }
1112 set_unit_activity_internal(punit, new_activity);
1113 if (new_activity == punit->changed_from) {
1114 punit->activity_count = punit->changed_from_count;
1115 }
1116}
1117
1118/**********************************************************************/
1121 void set_unit_activity_targeted(struct unit *punit,
1122 enum unit_activity new_activity,
1123 struct extra_type *new_target)
1124{
1125 fc_assert_ret(activity_requires_target(new_activity)
1126 || new_target == NULL);
1127
1128 set_unit_activity_internal(punit, new_activity);
1129 punit->activity_target = new_target;
1130 if (new_activity == punit->changed_from
1131 && new_target == punit->changed_from_target) {
1132 punit->activity_count = punit->changed_from_count;
1133 }
1134}
1135
1136/**********************************************************************/
1139 bool is_unit_activity_on_tile(enum unit_activity activity,
1140 const struct tile *ptile)
1141{
1142 unit_list_iterate(ptile->units, punit) {
1143 if (punit->activity == activity) {
1144 return TRUE;
1145 }
1146 } unit_list_iterate_end;
1147 return FALSE;
1148}
1149
1150/**********************************************************************/
1154bv_extras get_unit_tile_pillage_set(const struct tile *ptile)
1155{
1156 bv_extras tgt_ret;
1157
1158 BV_CLR_ALL(tgt_ret);
1159 unit_list_iterate(ptile->units, punit) {
1160 if (punit->activity == ACTIVITY_PILLAGE) {
1161 BV_SET(tgt_ret, extra_index(punit->activity_target));
1162 }
1163 } unit_list_iterate_end;
1164
1165 return tgt_ret;
1166}
1167
1168/**********************************************************************/
1171 void unit_activity_astr(const struct unit *punit, struct astring *astr)
1172{
1173 if (!punit || !astr) {
1174 return;
1175 }
1176
1177 switch (punit->activity) {
1178 case ACTIVITY_IDLE:
1179 if (utype_fuel(unit_type_get(punit))) {
1180 int rate, f;
1181
1182 rate = unit_type_get(punit)->move_rate;
1183 f = ((punit->fuel) - 1);
1184
1185 /* Add in two parts as move_points_text() returns ptr to static
1186 * End result: "Moves: (fuel)moves_left" */
1187 astr_add_line(astr, "%s: (%s)", _("Moves"),
1188 move_points_text((rate * f) + punit->moves_left, FALSE));
1189 astr_add(astr, "%s",
1190 move_points_text(punit->moves_left, FALSE));
1191 } else {
1192 astr_add_line(astr, "%s: %s", _("Moves"),
1193 move_points_text(punit->moves_left, FALSE));
1194 }
1195 return;
1196 case ACTIVITY_POLLUTION:
1197 case ACTIVITY_FALLOUT:
1198 case ACTIVITY_OLD_ROAD:
1199 case ACTIVITY_OLD_RAILROAD:
1200 case ACTIVITY_TRANSFORM:
1201 case ACTIVITY_FORTIFYING:
1202 case ACTIVITY_FORTIFIED:
1203 case ACTIVITY_AIRBASE:
1204 case ACTIVITY_FORTRESS:
1205 case ACTIVITY_SENTRY:
1206 case ACTIVITY_GOTO:
1207 case ACTIVITY_EXPLORE:
1208 case ACTIVITY_CONVERT:
1209 case ACTIVITY_CULTIVATE:
1210 case ACTIVITY_PLANT:
1211 astr_add_line(astr, "%s", get_activity_text(punit->activity));
1212 return;
1213 case ACTIVITY_MINE:
1214 case ACTIVITY_IRRIGATE:
1215 if (punit->activity_target == NULL) {
1216 astr_add_line(astr, "%s", get_activity_text(punit->activity));
1217 } else {
1218 astr_add_line(astr, "Building %s",
1219 extra_name_translation(punit->activity_target));
1220 }
1221 return;
1222 case ACTIVITY_PILLAGE:
1223 if (punit->activity_target != NULL) {
1224 astr_add_line(astr, "%s: %s", get_activity_text(punit->activity),
1225 extra_name_translation(punit->activity_target));
1226 } else {
1227 astr_add_line(astr, "%s", get_activity_text(punit->activity));
1228 }
1229 return;
1230 case ACTIVITY_BASE:
1231 astr_add_line(astr, "%s: %s", get_activity_text(punit->activity),
1232 extra_name_translation(punit->activity_target));
1233 return;
1234 case ACTIVITY_GEN_ROAD:
1235 astr_add_line(astr, "%s: %s", get_activity_text(punit->activity),
1236 extra_name_translation(punit->activity_target));
1237 return;
1238 case ACTIVITY_UNKNOWN:
1239 case ACTIVITY_PATROL_UNUSED:
1240 case ACTIVITY_LAST:
1241 break;
1242 }
1243
1244 log_error("Unknown unit activity %d for %s (nb %d) in %s()",
1245 punit->activity, unit_rule_name(punit), punit->id, __FUNCTION__);
1246}
1247
1248/**********************************************************************/
1254 void unit_upkeep_astr(const struct unit *punit, struct astring *astr)
1255{
1256 if (!punit || !astr) {
1257 return;
1258 }
1259
1260 astr_add_line(astr, "%s %d/%d/%d", _("Food/Shield/Gold:"),
1261 punit->upkeep[O_FOOD], punit->upkeep[O_SHIELD],
1262 punit->upkeep[O_GOLD]);
1263}
1264
1265/**********************************************************************/
1268 struct player *unit_nationality(const struct unit *punit)
1269{
1270 fc_assert_ret_val(NULL != punit, NULL);
1271 return punit->nationality;
1272}
1273
1274/**********************************************************************/
1278 void unit_tile_set(struct unit *punit, struct tile *ptile)
1279{
1280 fc_assert_ret(NULL != punit);
1281 punit->tile = ptile;
1282}
1283
1284/**********************************************************************/
1291 struct unit *tile_allied_unit(const struct tile *ptile,
1292 const struct player *pplayer)
1293{
1294 struct unit *punit = NULL;
1295
1296 unit_list_iterate(ptile->units, cunit) {
1297 if (pplayers_allied(pplayer, unit_owner(cunit))) {
1298 punit = cunit;
1299 } else {
1300 return NULL;
1301 }
1302 }
1303 unit_list_iterate_end;
1304
1305 return punit;
1306}
1307
1308/**********************************************************************/
1314 struct unit *tile_enemy_unit(const struct tile *ptile,
1315 const struct player *pplayer)
1316{
1317 unit_list_iterate(ptile->units, punit) {
1318 if (pplayers_at_war(unit_owner(punit), pplayer)) {
1319 return punit;
1320 }
1321 } unit_list_iterate_end;
1322
1323 return NULL;
1324}
1325
1326/**********************************************************************/
1329 struct unit *tile_non_allied_unit(const struct tile *ptile,
1330 const struct player *pplayer)
1331{
1332 unit_list_iterate(ptile->units, punit) {
1333 if (!pplayers_allied(unit_owner(punit), pplayer)) {
1334 return punit;
1335 }
1336 }
1337 unit_list_iterate_end;
1338
1339 return NULL;
1340}
1341
1342/**********************************************************************/
1346 struct unit *tile_other_players_unit(const struct tile *ptile,
1347 const struct player *pplayer)
1348{
1349 unit_list_iterate(ptile->units, punit) {
1350 if (unit_owner(punit) != pplayer) {
1351 return punit;
1352 }
1353 } unit_list_iterate_end;
1354
1355 return NULL;
1356}
1357
1358/**********************************************************************/
1362 struct unit *tile_non_attack_unit(const struct tile *ptile,
1363 const struct player *pplayer)
1364{
1365 unit_list_iterate(ptile->units, punit) {
1366 if (pplayers_non_attack(unit_owner(punit), pplayer)) {
1367 return punit;
1368 }
1369 }
1370 unit_list_iterate_end;
1371
1372 return NULL;
1373}
1374
1375/**********************************************************************/
1383 struct unit *unit_occupies_tile(const struct tile *ptile,
1384 const struct player *pplayer)
1385{
1386 unit_list_iterate(ptile->units, punit) {
1387 if (!is_military_unit(punit)) {
1388 continue;
1389 }
1390
1391 if (uclass_has_flag(unit_class_get(punit), UCF_DOESNT_OCCUPY_TILE)) {
1392 continue;
1393 }
1394
1395 if (pplayers_at_war(unit_owner(punit), pplayer)) {
1396 return punit;
1397 }
1398 } unit_list_iterate_end;
1399
1400 return NULL;
1401}
1402
1403/**********************************************************************/
1410 bool is_plr_zoc_srv(const struct player *pplayer, const struct tile *ptile0,
1411 const struct civ_map *zmap)
1412{
1413 square_iterate(zmap, ptile0, 1, ptile) {
1414 struct terrain *pterrain;
1415 struct city *pcity;
1416
1417 pterrain = tile_terrain(ptile);
1418 if (terrain_has_flag(pterrain, TER_NO_ZOC)) {
1419 continue;
1420 }
1421
1422 pcity = tile_non_allied_city(ptile, pplayer);
1423 if (pcity != NULL) {
1424 if (unit_list_size(ptile->units) > 0) {
1425 /* Occupied enemy city, it doesn't matter if units inside have
1426 * UTYF_NOZOC or not. */
1427 return FALSE;
1428 }
1429 } else {
1430 unit_list_iterate(ptile->units, punit) {
1431 if (!pplayers_allied(unit_owner(punit), pplayer)
1432 && !unit_has_type_flag(punit, UTYF_NOZOC)
1433 && !unit_transported_server(punit)) {
1434 bool hidden = FALSE;
1435
1436 /* We do NOT check the possibility that player is allied with an extra owner,
1437 * and should thus see inside the extra.
1438 * This is to avoid the situation where having an alliance with third player
1439 * suddenly causes ZoC from a unit that would not cause it without the alliance. */
1440 extra_type_list_iterate(unit_class_get(punit)->cache.hiding_extras, pextra) {
1441 if (tile_has_extra(ptile, pextra)) {
1442 hidden = TRUE;
1443 break;
1444 }
1445 } extra_type_list_iterate_end;
1446
1447 if (!hidden) {
1448 return FALSE;
1449 }
1450 }
1451 } unit_list_iterate_end;
1452 }
1453 } square_iterate_end;
1454
1455 return TRUE;
1456}
1457
1458/**********************************************************************/
1469 bool is_plr_zoc_client(const struct player *pplayer, const struct tile *ptile0,
1470 const struct civ_map *zmap)
1471{
1472 square_iterate(zmap, ptile0, 1, ptile) {
1473 struct terrain *pterrain;
1474 struct city *pcity;
1475
1476 pterrain = tile_terrain(ptile);
1477 if (T_UNKNOWN == pterrain
1478 || terrain_has_flag(pterrain, TER_NO_ZOC)) {
1479 continue;
1480 }
1481
1482 pcity = tile_non_allied_city(ptile, pplayer);
1483 if (pcity != NULL) {
1484 if (pcity->client.occupied
1485 || TILE_KNOWN_UNSEEN == tile_get_known(ptile, pplayer)) {
1486 /* Occupied enemy city, it doesn't matter if units inside have
1487 * UTYF_NOZOC or not. Fogged city is assumed to be occupied. */
1488 return FALSE;
1489 }
1490 } else {
1491 unit_list_iterate(ptile->units, punit) {
1492 if (!unit_transported_client(punit)
1493 && !pplayers_allied(unit_owner(punit), pplayer)
1494 && !unit_has_type_flag(punit, UTYF_NOZOC)) {
1495 return FALSE;
1496 }
1497 } unit_list_iterate_end;
1498 }
1499 } square_iterate_end;
1500
1501 return TRUE;
1502}
1503
1504/**********************************************************************/
1507 bool unit_type_really_ignores_zoc(const struct unit_type *punittype)
1508{
1509 return (!uclass_has_flag(utype_class(punittype), UCF_ZOC)
1510 || utype_has_flag(punittype, UTYF_IGZOC));
1511}
1512
1513/**********************************************************************/
1521 bool unit_being_aggressive(const struct unit *punit)
1522{
1523 if (!is_attack_unit(punit)) {
1524 return FALSE;
1525 }
1526 if (tile_city(unit_tile(punit))) {
1527 return FALSE;
1528 }
1529 if (BORDERS_DISABLED != game.info.borders) {
1530 switch (game.info.happyborders) {
1531 case HB_DISABLED:
1532 break;
1533 case HB_NATIONAL:
1534 if (tile_owner(unit_tile(punit)) == unit_owner(punit)) {
1535 return FALSE;
1536 }
1537 break;
1538 case HB_ALLIANCE:
1539 if (pplayers_allied(tile_owner(unit_tile(punit)), unit_owner(punit))) {
1540 return FALSE;
1541 }
1542 break;
1543 }
1544 }
1545 if (tile_has_not_aggressive_extra_for_unit(unit_tile(punit),
1546 unit_type_get(punit))) {
1547 return !is_unit_near_a_friendly_city(punit);
1548 }
1549
1550 return TRUE;
1551}
1552
1553/**********************************************************************/
1556 bool is_build_activity(enum unit_activity activity)
1557{
1558 switch (activity) {
1559 case ACTIVITY_MINE:
1560 case ACTIVITY_IRRIGATE:
1561 case ACTIVITY_BASE:
1562 case ACTIVITY_GEN_ROAD:
1563 return TRUE;
1564 default:
1565 return FALSE;
1566 }
1567}
1568
1569/**********************************************************************/
1572 bool is_clean_activity(enum unit_activity activity)
1573{
1574 switch (activity) {
1575 case ACTIVITY_PILLAGE:
1576 case ACTIVITY_POLLUTION:
1577 case ACTIVITY_FALLOUT:
1578 return TRUE;
1579 default:
1580 return FALSE;
1581 }
1582}
1583
1584/**********************************************************************/
1587 bool is_terrain_change_activity(enum unit_activity activity)
1588{
1589 switch (activity) {
1590 case ACTIVITY_CULTIVATE:
1591 case ACTIVITY_PLANT:
1592 case ACTIVITY_TRANSFORM:
1593 return TRUE;
1594 default:
1595 return FALSE;
1596 }
1597}
1598
1599/**********************************************************************/
1602 bool is_tile_activity(enum unit_activity activity)
1603{
1604 return is_build_activity(activity)
1605 || is_clean_activity(activity)
1606 || is_terrain_change_activity(activity);
1607}
1608
1609/**********************************************************************/
1613 struct unit *unit_virtual_create(struct player *pplayer, struct city *pcity,
1614 const struct unit_type *punittype,
1615 int veteran_level)
1616{
1617 /* Make sure that contents of unit structure are correctly initialized,
1618 * if you ever allocate it by some other mean than fc_calloc() */
1619 struct unit *punit = fc_calloc(1, sizeof(*punit));
1620 int max_vet_lvl;
1621
1622 /* It does not register the unit so the id is set to 0. */
1623 punit->id = IDENTITY_NUMBER_ZERO;
1624
1625 fc_assert_ret_val(NULL != punittype, NULL); /* No untyped units! */
1626 punit->utype = punittype;
1627
1628 fc_assert_ret_val(NULL != pplayer, NULL); /* No unowned units! */
1629 punit->owner = pplayer;
1630 punit->nationality = pplayer;
1631
1632 punit->refcount = 1;
1633 punit->facing = rand_direction();
1634
1635 if (pcity) {
1636 unit_tile_set(punit, pcity->tile);
1637 punit->homecity = pcity->id;
1638 } else {
1639 unit_tile_set(punit, NULL);
1640 punit->homecity = IDENTITY_NUMBER_ZERO;
1641 }
1642
1643 memset(punit->upkeep, 0, O_LAST * sizeof(*punit->upkeep));
1644 punit->goto_tile = NULL;
1645 max_vet_lvl = utype_veteran_levels(punittype) - 1;
1646 punit->veteran = MIN(veteran_level, max_vet_lvl);
1647 /* A unit new and fresh ... */
1648 punit->fuel = utype_fuel(unit_type_get(punit));
1649 punit->hp = unit_type_get(punit)->hp;
1650 punit->moves_left = unit_move_rate(punit);
1651 punit->moved = FALSE;
1652
1653 punit->ssa_controller = SSA_NONE;
1654 punit->paradropped = FALSE;
1655 punit->done_moving = FALSE;
1656
1657 punit->transporter = NULL;
1658 punit->transporting = unit_list_new();
1659
1660 punit->carrying = NULL;
1661
1662 set_unit_activity(punit, ACTIVITY_IDLE);
1663 punit->battlegroup = BATTLEGROUP_NONE;
1664 punit->has_orders = FALSE;
1665
1666 punit->action_decision_want = ACT_DEC_NOTHING;
1667 punit->action_decision_tile = NULL;
1668
1669 punit->stay = FALSE;
1670
1671 if (is_server()) {
1672 punit->server.debug = FALSE;
1673 punit->server.birth_turn = game.info.turn;
1674
1675 punit->server.dying = FALSE;
1676
1677 punit->server.removal_callback = NULL;
1678
1679 memset(punit->server.upkeep_paid, 0,
1680 O_LAST * sizeof(*punit->server.upkeep_paid));
1681
1682 punit->server.ord_map = 0;
1683 punit->server.ord_city = 0;
1684
1685 punit->server.vision = NULL; /* No vision. */
1686 punit->server.action_timestamp = 0;
1687 /* Must be an invalid turn number, and an invalid previous turn
1688 * number. */
1689 punit->server.action_turn = -2;
1690 /* punit->server.moving = NULL; set by fc_calloc(). */
1691
1692 punit->server.adv = fc_calloc(1, sizeof(*punit->server.adv));
1693
1694 CALL_FUNC_EACH_AI(unit_alloc, punit);
1695 } else {
1696 punit->client.focus_status = FOCUS_AVAIL;
1697 punit->client.transported_by = -1;
1698 punit->client.colored = FALSE;
1699 punit->client.act_prob_cache = NULL;
1700 }
1701
1702 return punit;
1703}
1704
1705/**********************************************************************/
1709 void unit_virtual_destroy(struct unit *punit)
1710{
1711 free_unit_orders(punit);
1712
1713 /* Unload unit if transported. */
1714 unit_transport_unload(punit);
1715 fc_assert(!unit_transported(punit));
1716
1717 /* Check for transported units. Use direct access to the list. */
1718 if (unit_list_size(punit->transporting) != 0) {
1719 /* Unload all units. */
1720 unit_list_iterate_safe(punit->transporting, pcargo) {
1721 unit_transport_unload(pcargo);
1722 } unit_list_iterate_safe_end;
1723 }
1724 fc_assert(unit_list_size(punit->transporting) == 0);
1725
1726 if (punit->transporting) {
1727 unit_list_destroy(punit->transporting);
1728 }
1729
1730 CALL_FUNC_EACH_AI(unit_free, punit);
1731
1732 if (is_server() && punit->server.adv) {
1733 FC_FREE(punit->server.adv);
1734 } else {
1735 if (punit->client.act_prob_cache) {
1736 FC_FREE(punit->client.act_prob_cache);
1737 }
1738 }
1739
1740 if (--punit->refcount <= 0) {
1741 FC_FREE(punit);
1742 }
1743}
1744
1745/**********************************************************************/
1749 void free_unit_orders(struct unit *punit)
1750{
1751 if (punit->has_orders) {
1752 punit->goto_tile = NULL;
1753 free(punit->orders.list);
1754 punit->orders.list = NULL;
1755 }
1756 punit->orders.length = 0;
1757 punit->has_orders = FALSE;
1758}
1759
1760/**********************************************************************/
1763 int get_transporter_occupancy(const struct unit *ptrans)
1764{
1765 fc_assert_ret_val(ptrans, -1);
1766
1767 return unit_list_size(ptrans->transporting);
1768}
1769
1770/**********************************************************************/
1773 static struct unit *base_transporter_for_unit(const struct unit *pcargo,
1774 const struct tile *ptile,
1775 bool (*unit_load_test)
1776 (const struct unit *pc,
1777 const struct unit *pt))
1778{
1779 struct unit *best_trans = NULL;
1780 struct {
1781 bool has_orders, is_idle, can_freely_unload;
1782 int depth, outermost_moves_left, total_moves;
1783 } cur, best = { FALSE };
1784
1785 unit_list_iterate(ptile->units, ptrans) {
1786 if (!unit_load_test(pcargo, ptrans)) {
1787 continue;
1788 } else if (best_trans == NULL) {
1789 best_trans = ptrans;
1790 }
1791
1792 /* Gather data from transport stack in a single pass, for use in
1793 * various conditions below. */
1794 cur.has_orders = unit_has_orders(ptrans);
1795 cur.outermost_moves_left = ptrans->moves_left;
1796 cur.total_moves = ptrans->moves_left + unit_move_rate(ptrans);
1797 unit_transports_iterate(ptrans, ptranstrans) {
1798 if (unit_has_orders(ptranstrans)) {
1799 cur.has_orders = TRUE;
1800 }
1801 cur.outermost_moves_left = ptranstrans->moves_left;
1802 cur.total_moves += ptranstrans->moves_left + unit_move_rate(ptranstrans);
1803 } unit_transports_iterate_end;
1804
1805 /* Criteria for deciding the 'best' transport to load onto.
1806 * The following tests are applied in order; earlier ones have
1807 * lexicographically greater significance than later ones. */
1808
1809 /* Transports which have orders, or are on transports with orders,
1810 * are less preferable to transport stacks without orders (to
1811 * avoid loading on units that are just passing through). */
1812 if (best_trans != ptrans) {
1813 if (!cur.has_orders && best.has_orders) {
1814 best_trans = ptrans;
1815 } else if (cur.has_orders && !best.has_orders) {
1816 continue;
1817 }
1818 }
1819
1820 /* Else, transports which are idle are preferable (giving players
1821 * some control over loading) -- this does not check transports
1822 * of transports. */
1823 cur.is_idle = (ptrans->activity == ACTIVITY_IDLE);
1824 if (best_trans != ptrans) {
1825 if (cur.is_idle && !best.is_idle) {
1826 best_trans = ptrans;
1827 } else if (!cur.is_idle && best.is_idle) {
1828 continue;
1829 }
1830 }
1831
1832 /* Else, transports from which the cargo could unload at any time
1833 * are preferable to those where the cargo can only disembark in
1834 * cities/bases. */
1835 cur.can_freely_unload = utype_can_freely_unload(unit_type_get(pcargo),
1836 unit_type_get(ptrans));
1837 if (best_trans != ptrans) {
1838 if (cur.can_freely_unload && !best.can_freely_unload) {
1839 best_trans = ptrans;
1840 } else if (!cur.can_freely_unload && best.can_freely_unload) {
1841 continue;
1842 }
1843 }
1844
1845 /* Else, transports which are less deeply nested are preferable. */
1846 cur.depth = unit_transport_depth(ptrans);
1847 if (best_trans != ptrans) {
1848 if (cur.depth < best.depth) {
1849 best_trans = ptrans;
1850 } else if (cur.depth > best.depth) {
1851 continue;
1852 }
1853 }
1854
1855 /* Else, transport stacks where the outermost transport has more
1856 * moves left are preferable (on the assumption that it's the
1857 * outermost transport that's about to move). */
1858 if (best_trans != ptrans) {
1859 if (cur.outermost_moves_left > best.outermost_moves_left) {
1860 best_trans = ptrans;
1861 } else if (cur.outermost_moves_left < best.outermost_moves_left) {
1862 continue;
1863 }
1864 }
1865
1866 /* All other things being equal, as a tie-breaker, compare the total
1867 * moves left (this turn) and move rate (future turns) for the whole
1868 * stack, to take into account total potential movement for both
1869 * short and long journeys (we don't know which the cargo intends to
1870 * make). Doesn't try to account for whether transports can unload,
1871 * etc. */
1872 if (best_trans != ptrans) {
1873 if (cur.total_moves > best.total_moves) {
1874 best_trans = ptrans;
1875 } else {
1876 continue;
1877 }
1878 }
1879
1880 fc_assert(best_trans == ptrans);
1881 best = cur;
1882 } unit_list_iterate_end;
1883
1884 return best_trans;
1885}
1886
1887/**********************************************************************/
1892 struct unit *transporter_for_unit(const struct unit *pcargo)
1893{
1894 return base_transporter_for_unit(pcargo, unit_tile(pcargo), can_unit_load);
1895}
1896
1897/**********************************************************************/
1902 struct unit *transporter_for_unit_at(const struct unit *pcargo,
1903 const struct tile *ptile)
1904{
1905 return base_transporter_for_unit(pcargo, ptile, could_unit_load);
1906}
1907
1908/**********************************************************************/
1912 static bool can_type_transport_units_cargo(const struct unit_type *utype,
1913 const struct unit *punit)
1914{
1915 if (get_transporter_occupancy(punit) > utype->transport_capacity) {
1916 return FALSE;
1917 }
1918
1919 unit_list_iterate(punit->transporting, pcargo) {
1920 if (!can_unit_type_transport(utype, unit_class_get(pcargo))) {
1921 return FALSE;
1922 }
1923 } unit_list_iterate_end;
1924
1925 return TRUE;
1926}
1927
1928/**********************************************************************/
1935enum unit_upgrade_result
1936unit_transform_result(const struct civ_map *nmap,
1937 const struct unit *punit,
1938 const struct unit_type *to_unittype)
1939{
1940 fc_assert_ret_val(NULL != to_unittype, UU_NO_UNITTYPE);
1941
1942 if (!can_type_transport_units_cargo(to_unittype, punit)) {
1943 return UU_NOT_ENOUGH_ROOM;
1944 }
1945
1946 if (punit->transporter != NULL) {
1947 if (!can_unit_type_transport(unit_type_get(punit->transporter),
1948 utype_class(to_unittype))) {
1949 return UU_UNSUITABLE_TRANSPORT;
1950 }
1951 } else if (!can_exist_at_tile(nmap, to_unittype, unit_tile(punit))) {
1952 /* The new unit type can't survive on this terrain. */
1953 return UU_NOT_TERRAIN;
1954 }
1955
1956 return UU_OK;
1957}
1958
1959/**********************************************************************/
1968 enum unit_upgrade_result unit_upgrade_test(const struct civ_map *nmap,
1969 const struct unit *punit,
1970 bool is_free)
1971{
1972 struct player *pplayer = unit_owner(punit);
1973 const struct unit_type *to_unittype = can_upgrade_unittype(pplayer,
1974 unit_type_get(punit));
1975 struct city *pcity;
1976 int cost;
1977
1978 if (!to_unittype) {
1979 return UU_NO_UNITTYPE;
1980 }
1981
1982 if (punit->activity == ACTIVITY_CONVERT) {
1983 /* TODO: There may be other activities that the upgraded unit is not
1984 allowed to do, which we could also test.
1985 -
1986 If convert were legal for new unit_type we could allow, but then it
1987 has a 'head start' getting activity time from the old conversion. */
1988 return UU_NOT_ACTIVITY;
1989 }
1990
1991 if (!is_free) {
1992 cost = unit_upgrade_price(pplayer, unit_type_get(punit), to_unittype);
1993 if (pplayer->economic.gold < cost) {
1994 return UU_NO_MONEY;
1995 }
1996
1997 pcity = tile_city(unit_tile(punit));
1998 if (!pcity) {
1999 return UU_NOT_IN_CITY;
2000 }
2001 if (city_owner(pcity) != pplayer) {
2002 /* TODO: Should upgrades in allied cities be possible? */
2003 return UU_NOT_CITY_OWNER;
2004 }
2005 }
2006
2007 /* TODO: Allow transported units to be reassigned. Check here
2008 * and make changes to upgrade_unit. */
2009 return unit_transform_result(nmap, punit, to_unittype);
2010}
2011
2012/**********************************************************************/
2015 bool unit_can_convert(const struct civ_map *nmap,
2016 const struct unit *punit)
2017{
2018 const struct unit_type *tgt = unit_type_get(punit)->converted_to;
2019
2020 if (tgt == NULL) {
2021 return FALSE;
2022 }
2023
2024 return UU_OK == unit_transform_result(nmap, punit, tgt);
2025}
2026
2027/**********************************************************************/
2031 enum unit_upgrade_result unit_upgrade_info(const struct civ_map *nmap,
2032 const struct unit *punit,
2033 char *buf, size_t bufsz)
2034{
2035 struct player *pplayer = unit_owner(punit);
2036 enum unit_upgrade_result result = unit_upgrade_test(nmap, punit, FALSE);
2037 int upgrade_cost;
2038 const struct unit_type *from_unittype = unit_type_get(punit);
2039 const struct unit_type *to_unittype = can_upgrade_unittype(pplayer,
2040 unit_type_get(punit));
2041 char tbuf[MAX_LEN_MSG];
2042
2043 fc_snprintf(tbuf, ARRAY_SIZE(tbuf), PL_("Treasury contains %d gold.",
2044 "Treasury contains %d gold.",
2045 pplayer->economic.gold),
2046 pplayer->economic.gold);
2047
2048 switch (result) {
2049 case UU_OK:
2050 upgrade_cost = unit_upgrade_price(pplayer, from_unittype, to_unittype);
2051 /* This message is targeted toward the GUI callers. */
2052 /* TRANS: Last %s is pre-pluralised "Treasury contains %d gold." */
2053 fc_snprintf(buf, bufsz, PL_("Upgrade %s to %s for %d gold?\n%s",
2054 "Upgrade %s to %s for %d gold?\n%s",
2055 upgrade_cost),
2056 utype_name_translation(from_unittype),
2057 utype_name_translation(to_unittype),
2058 upgrade_cost, tbuf);
2059 break;
2060 case UU_NO_UNITTYPE:
2061 fc_snprintf(buf, bufsz,
2062 _("Sorry, cannot upgrade %s (yet)."),
2063 utype_name_translation(from_unittype));
2064 break;
2065 case UU_NO_MONEY:
2066 upgrade_cost = unit_upgrade_price(pplayer, from_unittype, to_unittype);
2067 /* TRANS: Last %s is pre-pluralised "Treasury contains %d gold." */
2068 fc_snprintf(buf, bufsz, PL_("Upgrading %s to %s costs %d gold.\n%s",
2069 "Upgrading %s to %s costs %d gold.\n%s",
2070 upgrade_cost),
2071 utype_name_translation(from_unittype),
2072 utype_name_translation(to_unittype),
2073 upgrade_cost, tbuf);
2074 break;
2075 case UU_NOT_IN_CITY:
2076 case UU_NOT_CITY_OWNER:
2077 fc_snprintf(buf, bufsz,
2078 _("You can only upgrade units in your cities."));
2079 break;
2080 case UU_NOT_ENOUGH_ROOM:
2081 fc_snprintf(buf, bufsz,
2082 _("Upgrading this %s would strand units it transports."),
2083 utype_name_translation(from_unittype));
2084 break;
2085 case UU_NOT_TERRAIN:
2086 fc_snprintf(buf, bufsz,
2087 _("Upgrading this %s would result in a %s which can not "
2088 "survive at this place."),
2089 utype_name_translation(from_unittype),
2090 utype_name_translation(to_unittype));
2091 break;
2092 case UU_UNSUITABLE_TRANSPORT:
2093 fc_snprintf(buf, bufsz,
2094 _("Upgrading this %s would result in a %s which its "
2095 "current transport, %s, could not transport."),
2096 utype_name_translation(from_unittype),
2097 utype_name_translation(to_unittype),
2098 unit_name_translation(punit->transporter));
2099 break;
2100 case UU_NOT_ACTIVITY:
2101 fc_snprintf(buf, bufsz,
2102 _("Cannot upgrade %s while doing '%s'."),
2103 utype_name_translation(from_unittype),
2104 unit_activity_name(punit->activity));
2105 break;
2106 }
2107
2108 return result;
2109}
2110
2111/**********************************************************************/
2115 int unit_pays_mp_for_action(const struct action *paction,
2116 const struct unit *punit)
2117{
2118 int mpco;
2119
2120 mpco = get_target_bonus_effects(NULL,
2121 &(const struct req_context) {
2122 .player = unit_owner(punit),
2123 .city = unit_tile(punit)
2124 ? tile_city(unit_tile(punit))
2125 : NULL,
2126 .tile = unit_tile(punit),
2127 .unit = punit,
2128 .unittype = unit_type_get(punit),
2129 .action = paction,
2130 },
2131 NULL,
2132 EFT_ACTION_SUCCESS_MOVE_COST);
2133
2134 mpco += utype_pays_mp_for_action_base(paction, unit_type_get(punit));
2135
2136 return mpco;
2137}
2138
2139/**********************************************************************/
2142 int hp_gain_coord(const struct unit *punit)
2143{
2144 int hp = 0;
2145 const int base = unit_type_get(punit)->hp;
2146 int min = base * get_unit_bonus(punit, EFT_MIN_HP_PCT) / 100;
2147
2148 /* Includes barracks (100%), fortress (25%), etc. */
2149 hp += base * get_unit_bonus(punit, EFT_HP_REGEN) / 100;
2150
2151 /* Minimum HP after regen effects applied. */
2152 hp = MAX(hp, min);
2153
2154 /* Regen2 effects that apply after there's at least Min HP */
2155 hp += ceil(base / 10) * get_unit_bonus(punit, EFT_HP_REGEN_2) / 10;
2156
2157 return MAX(hp, 0);
2158}
2159
2160/**********************************************************************/
2163 int unit_gain_hitpoints(const struct unit *punit)
2164{
2165 const struct unit_type *utype = unit_type_get(punit);
2166 struct unit_class *pclass = unit_class_get(punit);
2167 struct city *pcity = tile_city(unit_tile(punit));
2168 int gain;
2169
2170 if (!punit->moved) {
2171 gain = hp_gain_coord(punit);
2172 } else {
2173 gain = 0;
2174 }
2175
2176 gain += get_unit_bonus(punit, EFT_UNIT_RECOVER);
2177
2178 if (!punit->homecity && 0 < game.server.killunhomed
2179 && !unit_has_type_flag(punit, UTYF_GAMELOSS)) {
2180 /* Hit point loss of units without homecity; at least 1 hp! */
2181 /* Gameloss units are immune to this effect. */
2182 int hp_loss = MAX(utype->hp * game.server.killunhomed / 100, 1);
2183
2184 if (gain > hp_loss) {
2185 gain = -1;
2186 } else {
2187 gain -= hp_loss;
2188 }
2189 }
2190
2191 if (pcity == NULL && !tile_has_native_base(unit_tile(punit), utype)
2192 && !unit_transported(punit)) {
2193 gain -= utype->hp * pclass->hp_loss_pct / 100;
2194 }
2195
2196 if (punit->hp + gain > utype->hp) {
2197 gain = utype->hp - punit->hp;
2198 } else if (punit->hp + gain < 0) {
2199 gain = -punit->hp;
2200 }
2201
2202 return gain;
2203}
2204
2205/**********************************************************************/
2208 bool is_losing_hp(const struct unit *punit)
2209{
2210 const struct unit_type *punittype = unit_type_get(punit);
2211
2212 return get_unit_bonus(punit, EFT_UNIT_RECOVER)
2213 < (punittype->hp *
2214 utype_class(punittype)->hp_loss_pct / 100);
2215}
2216
2217/**********************************************************************/
2220 bool unit_type_is_losing_hp(const struct player *pplayer,
2221 const struct unit_type *punittype)
2222{
2223 return get_unittype_bonus(pplayer, NULL, punittype, NULL,
2224 EFT_UNIT_RECOVER)
2225 < (punittype->hp *
2226 utype_class(punittype)->hp_loss_pct / 100);
2227}
2228
2229/**********************************************************************/
2233 bool unit_is_alive(int id)
2234{
2235 /* Check if unit exist in game */
2236 if (game_unit_by_number(id)) {
2237 return TRUE;
2238 }
2239
2240 return FALSE;
2241}
2242
2243/**********************************************************************/
2250 bool unit_is_virtual(const struct unit *punit)
2251{
2252 if (!punit) {
2253 return FALSE;
2254 }
2255
2256 return punit != game_unit_by_number(punit->id);
2257}
2258
2259/**********************************************************************/
2262 void *unit_ai_data(const struct unit *punit, const struct ai_type *ai)
2263{
2264 return punit->server.ais[ai_type_number(ai)];
2265}
2266
2267/**********************************************************************/
2270 void unit_set_ai_data(struct unit *punit, const struct ai_type *ai,
2271 void *data)
2272{
2273 punit->server.ais[ai_type_number(ai)] = data;
2274}
2275
2276/**********************************************************************/
2284 int unit_bribe_cost(struct unit *punit, struct player *briber)
2285{
2286 int cost, default_hp, dist = 0;
2287 struct tile *ptile = unit_tile(punit);
2288
2289 fc_assert_ret_val(punit != NULL, 0);
2290
2291 default_hp = unit_type_get(punit)->hp;
2292 cost = unit_owner(punit)->economic.gold + game.info.base_bribe_cost;
2293
2294 /* Consider the distance to the capital. */
2295 dist = GAME_UNIT_BRIBE_DIST_MAX;
2296 city_list_iterate(unit_owner(punit)->cities, capital) {
2297 if (is_capital(capital)) {
2298 int tmp = map_distance(capital->tile, ptile);
2299
2300 if (tmp < dist) {
2301 dist = tmp;
2302 }
2303 }
2304 } city_list_iterate_end;
2305
2306 cost /= dist + 2;
2307
2308 /* Consider the build cost. */
2309 cost *= unit_build_shield_cost_base(punit) / 10.0;
2310
2311 /* Rule set specific cost modification */
2312 cost += (cost
2313 * get_target_bonus_effects(NULL,
2314 &(const struct req_context) {
2315 .player = unit_owner(punit),
2316 .city = game_city_by_number(
2317 punit->homecity
2318 ),
2319 .tile = ptile,
2320 .unit = punit,
2321 .unittype = unit_type_get(punit),
2322 },
2323 briber,
2324 EFT_UNIT_BRIBE_COST_PCT))
2325 / 100;
2326
2327 /* Veterans are not cheap. */
2328 {
2329 const struct veteran_level *vlevel
2330 = utype_veteran_level(unit_type_get(punit), punit->veteran);
2331
2332 fc_assert_ret_val(vlevel != NULL, 0);
2333 cost = cost * vlevel->power_fact / 100;
2334 if (unit_type_get(punit)->move_rate > 0) {
2335 cost += cost * vlevel->move_bonus / unit_type_get(punit)->move_rate;
2336 } else {
2337 cost += cost * vlevel->move_bonus / SINGLE_MOVE;
2338 }
2339 }
2340
2341 /* Cost now contains the basic bribe cost. We now reduce it by:
2342 * bribecost = cost/2 + cost/2 * damage/hp
2343 * = cost/2 * (1 + damage/hp) */
2344 return ((float)cost / 2 * (1.0 + (float)punit->hp / default_hp));
2345}
2346
2347/**********************************************************************/
2350 bool unit_transport_load(struct unit *pcargo, struct unit *ptrans, bool force)
2351{
2352 fc_assert_ret_val(ptrans != NULL, FALSE);
2353 fc_assert_ret_val(pcargo != NULL, FALSE);
2354
2355 fc_assert_ret_val(!unit_list_search(ptrans->transporting, pcargo), FALSE);
2356
2357 if (force || can_unit_load(pcargo, ptrans)) {
2358 pcargo->transporter = ptrans;
2359 unit_list_append(ptrans->transporting, pcargo);
2360
2361 return TRUE;
2362 }
2363
2364 return FALSE;
2365}
2366
2367/**********************************************************************/
2370 bool unit_transport_unload(struct unit *pcargo)
2371{
2372 struct unit *ptrans;
2373
2374 fc_assert_ret_val(pcargo != NULL, FALSE);
2375
2376 if (!unit_transported(pcargo)) {
2377 /* 'pcargo' is not transported. */
2378 return FALSE;
2379 }
2380
2381 /* Get the transporter; must not be defined on the client! */
2382 ptrans = unit_transport_get(pcargo);
2383 if (ptrans) {
2384 /* 'pcargo' and 'ptrans' should be on the same tile. */
2385 fc_assert(same_pos(unit_tile(pcargo), unit_tile(ptrans)));
2386
2387#ifndef FREECIV_NDEBUG
2388 bool success =
2389#endif
2390 unit_list_remove(ptrans->transporting, pcargo);
2391
2392 /* It is an error if 'pcargo' can not be removed from the 'ptrans'. */
2393 fc_assert(success);
2394 }
2395
2396 /* For the server (also safe for the client). */
2397 pcargo->transporter = NULL;
2398
2399 return TRUE;
2400}
2401
2402/**********************************************************************/
2405 bool unit_transported(const struct unit *pcargo)
2406{
2407 fc_assert_ret_val(pcargo != NULL, FALSE);
2408
2409 /* The unit is transported if a transporter unit is set or, (for the client)
2410 * if the transported_by field is set. */
2411 if (is_server()) {
2412 return unit_transported_server(pcargo);
2413 } else {
2414 return unit_transported_client(pcargo);
2415 }
2416}
2417
2418/**********************************************************************/
2421 struct unit *unit_transport_get(const struct unit *pcargo)
2422{
2423 fc_assert_ret_val(pcargo != NULL, NULL);
2424
2425 return pcargo->transporter;
2426}
2427
2428/**********************************************************************/
2431 struct unit_list *unit_transport_cargo(const struct unit *ptrans)
2432{
2433 fc_assert_ret_val(ptrans != NULL, NULL);
2434 fc_assert_ret_val(ptrans->transporting != NULL, NULL);
2435
2436 return ptrans->transporting;
2437}
2438
2439/**********************************************************************/
2442static inline bool
2443unit_transport_check_one(const struct unit_type *cargo_utype,
2444 const struct unit_type *trans_utype)
2445{
2446 return (trans_utype != cargo_utype
2447 && !can_unit_type_transport(cargo_utype,
2448 utype_class(trans_utype)));
2449}
2450
2451/**********************************************************************/
2459 bool unit_transport_check(const struct unit *pcargo,
2460 const struct unit *ptrans)
2461{
2462 const struct unit_type *cargo_utype = unit_type_get(pcargo);
2463
2464 /* Check 'pcargo' against 'ptrans'. */
2465 if (!unit_transport_check_one(cargo_utype, unit_type_get(ptrans))) {
2466 return FALSE;
2467 }
2468
2469 /* Check 'pcargo' against 'ptrans' parents. */
2470 unit_transports_iterate(ptrans, pparent) {
2471 if (!unit_transport_check_one(cargo_utype, unit_type_get(pparent))) {
2472 return FALSE;
2473 }
2474 } unit_transports_iterate_end;
2475
2476 /* Check cargo children... */
2477 unit_cargo_iterate(pcargo, pchild) {
2478 cargo_utype = unit_type_get(pchild);
2479
2480 /* ...against 'ptrans'. */
2481 if (!unit_transport_check_one(cargo_utype, unit_type_get(ptrans))) {
2482 return FALSE;
2483 }
2484
2485 /* ...and against 'ptrans' parents. */
2486 unit_transports_iterate(ptrans, pparent) {
2487 if (!unit_transport_check_one(cargo_utype, unit_type_get(pparent))) {
2488 return FALSE;
2489 }
2490 } unit_transports_iterate_end;
2491 } unit_cargo_iterate_end;
2492
2493 return TRUE;
2494}
2495
2496/**********************************************************************/
2500 bool unit_contained_in(const struct unit *pcargo, const struct unit *ptrans)
2501{
2502 unit_transports_iterate(pcargo, plevel) {
2503 if (ptrans == plevel) {
2504 return TRUE;
2505 }
2506 } unit_transports_iterate_end;
2507 return FALSE;
2508}
2509
2510/**********************************************************************/
2513 int unit_cargo_depth(const struct unit *ptrans)
2514{
2515 struct cargo_iter iter;
2516 struct iterator *it;
2517 int depth = 0;
2518
2519 for (it = cargo_iter_init(&iter, ptrans); iterator_valid(it);
2520 iterator_next(it)) {
2521 if (iter.depth > depth) {
2522 depth = iter.depth;
2523 }
2524 }
2525 return depth;
2526}
2527
2528/**********************************************************************/
2531 int unit_transport_depth(const struct unit *pcargo)
2532{
2533 int level = 0;
2534
2535 unit_transports_iterate(pcargo, plevel) {
2536 level++;
2537 } unit_transports_iterate_end;
2538 return level;
2539}
2540
2541/**********************************************************************/
2544 size_t cargo_iter_sizeof(void)
2545{
2546 return sizeof(struct cargo_iter);
2547}
2548
2549/**********************************************************************/
2552 static void *cargo_iter_get(const struct iterator *it)
2553{
2554 const struct cargo_iter *iter = CARGO_ITER(it);
2555
2556 return unit_list_link_data(iter->links[iter->depth - 1]);
2557}
2558
2559/**********************************************************************/
2562 static void cargo_iter_next(struct iterator *it)
2563{
2564 struct cargo_iter *iter = CARGO_ITER(it);
2565 const struct unit_list_link *piter;
2566 const struct unit_list_link *pnext;
2567
2568 /* Variant 1: unit has cargo. */
2569 pnext = unit_list_head(unit_transport_cargo(cargo_iter_get(it)));
2570 if (NULL != pnext) {
2571 fc_assert(iter->depth < ARRAY_SIZE(iter->links));
2572 iter->links[iter->depth++] = pnext;
2573 return;
2574 }
2575
2576 while (iter->depth > 0) {
2577 piter = iter->links[iter->depth - 1];
2578
2579 /* Variant 2: there are other cargo units at same level. */
2580 pnext = unit_list_link_next(piter);
2581 if (NULL != pnext) {
2582 iter->links[iter->depth - 1] = pnext;
2583 return;
2584 }
2585
2586 /* Variant 3: return to previous level, and do same tests. */
2587 iter->depth--;
2588 }
2589}
2590
2591/**********************************************************************/
2594 static bool cargo_iter_valid(const struct iterator *it)
2595{
2596 return (0 < CARGO_ITER(it)->depth);
2597}
2598
2599/**********************************************************************/
2602 struct iterator *cargo_iter_init(struct cargo_iter *iter,
2603 const struct unit *ptrans)
2604{
2605 struct iterator *it = ITERATOR(iter);
2606
2607 it->get = cargo_iter_get;
2608 it->next = cargo_iter_next;
2609 it->valid = cargo_iter_valid;
2610 iter->links[0] = unit_list_head(unit_transport_cargo(ptrans));
2611 iter->depth = (NULL != iter->links[0] ? 1 : 0);
2612
2613 return it;
2614}
2615
2616/**********************************************************************/
2619 bool unit_is_cityfounder(const struct unit *punit)
2620{
2621 return utype_is_cityfounder(unit_type_get(punit));
2622}
2623
2624
2625/**********************************************************************/
2628 bool unit_order_list_is_sane(const struct civ_map *nmap,
2629 int length, const struct unit_order *orders)
2630{
2631 int i;
2632
2633 for (i = 0; i < length; i++) {
2634 struct action *paction;
2635 struct extra_type *pextra;
2636
2637 if (orders[i].order > ORDER_LAST) {
2638 log_error("invalid order %d at index %d", orders[i].order, i);
2639 return FALSE;
2640 }
2641 switch (orders[i].order) {
2642 case ORDER_MOVE:
2643 case ORDER_ACTION_MOVE:
2644 if (!map_untrusted_dir_is_valid(orders[i].dir)) {
2645 log_error("in order %d, invalid move direction %d.", i, orders[i].dir);
2646 return FALSE;
2647 }
2648 break;
2649 case ORDER_ACTIVITY:
2650 switch (orders[i].activity) {
2651 case ACTIVITY_SENTRY:
2652 if (i != length - 1) {
2653 /* Only allowed as the last order. */
2654 log_error("activity %d is not allowed at index %d.", orders[i].activity,
2655 i);
2656 return FALSE;
2657 }
2658 break;
2659 /* Replaced by action orders */
2660 case ACTIVITY_BASE:
2661 case ACTIVITY_GEN_ROAD:
2662 case ACTIVITY_FALLOUT:
2663 case ACTIVITY_POLLUTION:
2664 case ACTIVITY_PILLAGE:
2665 case ACTIVITY_MINE:
2666 case ACTIVITY_IRRIGATE:
2667 case ACTIVITY_PLANT:
2668 case ACTIVITY_CULTIVATE:
2669 case ACTIVITY_TRANSFORM:
2670 case ACTIVITY_CONVERT:
2671 case ACTIVITY_FORTIFYING:
2672 log_error("at index %d, use action rather than activity %d.",
2673 i, orders[i].activity);
2674 return FALSE;
2675 /* Not supported. */
2676 case ACTIVITY_EXPLORE:
2677 case ACTIVITY_IDLE:
2678 /* Not set from the client. */
2679 case ACTIVITY_GOTO:
2680 case ACTIVITY_FORTIFIED:
2681 /* Compatiblity, used in savegames. */
2682 case ACTIVITY_OLD_ROAD:
2683 case ACTIVITY_OLD_RAILROAD:
2684 case ACTIVITY_FORTRESS:
2685 case ACTIVITY_AIRBASE:
2686 /* Unused. */
2687 case ACTIVITY_PATROL_UNUSED:
2688 case ACTIVITY_LAST:
2689 case ACTIVITY_UNKNOWN:
2690 log_error("at index %d, unsupported activity %d.", i, orders[i].activity);
2691 return FALSE;
2692 }
2693
2694 break;
2695 case ORDER_PERFORM_ACTION:
2696 if (!action_id_exists(orders[i].action)) {
2697 /* Non-existent action. */
2698 log_error("at index %d, the action %d doesn't exist.", i, orders[i].action);
2699 return FALSE;
2700 }
2701
2702 paction = action_by_number(orders[i].action);
2703
2704 /* Validate main target. */
2705 if (index_to_tile(nmap, orders[i].target) == NULL) {
2706 log_error("at index %d, invalid tile target %d for the action %d.",
2707 i, orders[i].target, orders[i].action);
2708 return FALSE;
2709 }
2710
2711 if (orders[i].dir != DIR8_ORIGIN) {
2712 log_error("at index %d, the action %d sets the outdated target"
2713 " specification dir.",
2714 i, orders[i].action);
2715 }
2716
2717 /* Validate sub target. */
2718 switch (action_id_get_sub_target_kind(orders[i].action)) {
2719 case ASTK_BUILDING:
2720 /* Sub target is a building. */
2721 if (!improvement_by_number(orders[i].sub_target)) {
2722 /* Sub target is invalid. */
2723 log_error("at index %d, cannot do %s without a target.", i,
2724 action_id_rule_name(orders[i].action));
2725 return FALSE;
2726 }
2727 break;
2728 case ASTK_TECH:
2729 /* Sub target is a technology. */
2730 if (orders[i].sub_target == A_NONE
2731 || (!valid_advance_by_number(orders[i].sub_target)
2732 && orders[i].sub_target != A_FUTURE)) {
2733 /* Target tech is invalid. */
2734 log_error("at index %d, cannot do %s without a target.", i,
2735 action_id_rule_name(orders[i].action));
2736 return FALSE;
2737 }
2738 break;
2739 case ASTK_EXTRA:
2740 case ASTK_EXTRA_NOT_THERE:
2741 /* Sub target is an extra. */
2742 pextra = (!(orders[i].sub_target == NO_TARGET
2743 || (orders[i].sub_target < 0
2744 || (orders[i].sub_target
2745 >= game.control.num_extra_types)))
2746 ? extra_by_number(orders[i].sub_target) : NULL);
2747 fc_assert(pextra == NULL || !(pextra->ruledit_disabled));
2748 if (pextra == NULL) {
2749 if (paction->target_complexity != ACT_TGT_COMPL_FLEXIBLE) {
2750 /* Target extra is invalid. */
2751 log_error("at index %d, cannot do %s without a target.", i,
2752 action_id_rule_name(orders[i].action));
2753 return FALSE;
2754 }
2755 } else {
2756 if (!(action_removes_extra(paction, pextra)
2757 || action_creates_extra(paction, pextra))) {
2758 /* Target extra is irrelevant for the action. */
2759 log_error("at index %d, cannot do %s to %s.", i,
2760 action_id_rule_name(orders[i].action),
2761 extra_rule_name(pextra));
2762 return FALSE;
2763 }
2764 }
2765 break;
2766 case ASTK_NONE:
2767 /* No validation required. */
2768 break;
2769 /* Invalid action? */
2770 case ASTK_COUNT:
2771 fc_assert_ret_val_msg(
2772 action_id_get_sub_target_kind(orders[i].action) != ASTK_COUNT,
2773 FALSE,
2774 "Bad action %d in order number %d.", orders[i].action, i);
2775 }
2776
2777 /* Some action orders are sane only in the last order. */
2778 if (i != length - 1) {
2779 /* If the unit is dead, */
2780 if (utype_is_consumed_by_action(paction, NULL)
2781 /* or if Freeciv has no idea where the unit will end up after it
2782 * has performed this action, */
2783 || !(utype_is_unmoved_by_action(paction, NULL)
2784 || utype_is_moved_to_tgt_by_action(paction, NULL))
2785 /* or if the unit will end up standing still, */
2786 || action_has_result(paction, ACTRES_FORTIFY)) {
2787 /* than having this action in the middle of a unit's orders is
2788 * probably wrong. */
2789 log_error("action %d is not allowed at index %d.",
2790 orders[i].action, i);
2791 return FALSE;
2792 }
2793 }
2794
2795 /* Don't validate that the target tile really contains a target or
2796 * that the actor player's map think the target tile has one.
2797 * The player may target something from their player map that isn't
2798 * there any more, a target they think is there even if their player
2799 * map doesn't have it, or even a target they assume will be there
2800 * when the unit reaches the target tile.
2801 *
2802 * With that said: The client should probably at least have an
2803 * option to only aim city targeted actions at cities. */
2804
2805 break;
2806 case ORDER_FULL_MP:
2807 break;
2808 case ORDER_LAST:
2809 /* An invalid order. This is handled above. */
2810 break;
2811 }
2812 }
2813
2814 return TRUE;
2815}
2816
2817/**********************************************************************/
2821 struct unit_order *create_unit_orders(const struct civ_map *nmap,
2822 int length,
2823 const struct unit_order *orders)
2824{
2825 struct unit_order *unit_orders;
2826
2827 if (!unit_order_list_is_sane(nmap, length, orders)) {
2828 return NULL;
2829 }
2830
2831 unit_orders = fc_malloc(length * sizeof(*(unit_orders)));
2832 memcpy(unit_orders, orders, length * sizeof(*(unit_orders)));
2833
2834 return unit_orders;
2835}
action_removes_extra
bool action_removes_extra(const struct action *paction, const struct extra_type *pextra)
Definition actions.c:2312
action_prob_possible
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:6709
is_action_enabled_unit_on_self
bool is_action_enabled_unit_on_self(const action_id wanted_action, const struct unit *actor_unit)
Definition actions.c:5145
action_prob_vs_city
struct act_prob action_prob_vs_city(const struct unit *actor_unit, const action_id act_id, const struct city *target_city)
Definition actions.c:5871
action_prob_vs_unit
struct act_prob action_prob_vs_unit(const struct unit *actor_unit, const action_id act_id, const struct unit *target_unit)
Definition actions.c:5955
action_id_rule_name
const char * action_id_rule_name(action_id act_id)
Definition actions.c:1899
action_prob_vs_tile
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)
Definition actions.c:6228
is_action_enabled_unit_on_tile
bool is_action_enabled_unit_on_tile(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:4996
is_action_enabled_unit_on_city
bool is_action_enabled_unit_on_city(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct city *target_city)
Definition actions.c:4755
is_action_enabled_unit_on_unit
bool is_action_enabled_unit_on_unit(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Definition actions.c:4832
action_maybe_possible_actor_unit
bool action_maybe_possible_actor_unit(const struct civ_map *nmap, const action_id act_id, const struct unit *actor_unit)
Definition actions.c:7171
action_id_exists
bool action_id_exists(const action_id act_id)
Definition actions.c:1697
action_creates_extra
bool action_creates_extra(const struct action *paction, const struct extra_type *pextra)
Definition actions.c:2224
actions.h
action_by_result_iterate
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:488
action_id_get_sub_target_kind
#define action_id_get_sub_target_kind(act_id)
Definition actions.h:659
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
action_has_result
#define action_has_result(_act_, _res_)
Definition actions.h:448
action_by_result_iterate_end
#define action_by_result_iterate_end
Definition actions.h:492
ai_type_number
int ai_type_number(const struct ai_type *ai)
Definition ai.c:272
ai.h
CALL_FUNC_EACH_AI
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:384
astr_add_line
void astr_add_line(struct astring *astr, const char *format,...)
Definition astring.c:299
astr_add
void astr_add(struct astring *astr, const char *format,...)
Definition astring.c:287
astring.h
base.h
bitvector.h
BV_CLR_ALL
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
is_capital
bool is_capital(const struct city *pcity)
Definition city.c:1544
tile_non_allied_city
struct city * tile_non_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2031
is_unit_near_a_friendly_city
bool is_unit_near_a_friendly_city(const struct unit *punit)
Definition city.c:2047
city.h
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:488
city_tile
#define city_tile(_pcity_)
Definition city.h:544
city_owner
#define city_owner(_pcity_)
Definition city.h:543
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:490
base
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2839
punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
cost
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:73
get_target_bonus_effects
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:691
get_unit_bonus
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:992
get_unittype_bonus
int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, const struct unit_type *punittype, const struct action *paction, enum effect_type effect_type)
Definition effects.c:957
next_extra_for_tile
struct extra_type * next_extra_for_tile(const struct tile *ptile, enum extra_cause cause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:740
extra_by_number
struct extra_type * extra_by_number(int id)
Definition extras.c:175
can_extras_coexist
bool can_extras_coexist(const struct extra_type *pextra1, const struct extra_type *pextra2)
Definition extras.c:952
extra_rule_name
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:195
extra_name_translation
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
extra_type_list_iterate
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:159
extra_index
#define extra_index(_e_)
Definition extras.h:177
extra_type_list_iterate_end
#define extra_type_list_iterate_end
Definition extras.h:161
is_server
static bool is_server(void)
Definition fc_interface.h:69
NO_TARGET
#define NO_TARGET
Definition fc_types.h:324
Activity_type_id
enum unit_activity Activity_type_id
Definition fc_types.h:349
DIR8_ORIGIN
#define DIR8_ORIGIN
Definition fc_types.h:427
action_id
int action_id
Definition fc_types.h:359
HB_ALLIANCE
@ HB_ALLIANCE
Definition fc_types.h:1144
HB_DISABLED
@ HB_DISABLED
Definition fc_types.h:1142
HB_NATIONAL
@ HB_NATIONAL
Definition fc_types.h:1143
O_SHIELD
@ O_SHIELD
Definition fc_types.h:91
O_FOOD
@ O_FOOD
Definition fc_types.h:91
O_GOLD
@ O_GOLD
Definition fc_types.h:91
O_LAST
@ O_LAST
Definition fc_types.h:91
BORDERS_DISABLED
@ BORDERS_DISABLED
Definition fc_types.h:891
IDENTITY_NUMBER_ZERO
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:82
fcintl.h
Q_
#define Q_(String)
Definition fcintl.h:70
PL_
#define PL_(String1, String2, n)
Definition fcintl.h:71
_
#define _(String)
Definition fcintl.h:67
game
struct civ_game game
Definition game.c:57
wld
struct world wld
Definition game.c:58
game_unit_by_number
struct unit * game_unit_by_number(int id)
Definition game.c:111
game_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:102
game.h
GAME_UNIT_BRIBE_DIST_MAX
#define GAME_UNIT_BRIBE_DIST_MAX
Definition game.h:727
GAME_TRANSPORT_MAX_RECURSIVE
#define GAME_TRANSPORT_MAX_RECURSIVE
Definition game.h:730
bufsz
static const int bufsz
Definition helpdlg.c:70
improvement_by_number
struct impr_type * improvement_by_number(const Impr_type_id id)
Definition improvement.c:192
iterator_valid
static bool iterator_valid(const struct iterator *it)
Definition iterator.h:61
ITERATOR
#define ITERATOR(p)
Definition iterator.h:37
iterator_next
static void iterator_next(struct iterator *it)
Definition iterator.h:42
log.h
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
log_error
#define log_error(message,...)
Definition log.h:103
fc_assert_ret_val_msg
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:208
index_to_tile
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:454
same_pos
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:938
map_untrusted_dir_is_valid
bool map_untrusted_dir_is_valid(enum direction8 dir)
Definition map.c:1271
rand_direction
enum direction8 rand_direction(void)
Definition map.c:1732
map_distance
int map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:652
map.h
square_iterate
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:385
square_iterate_end
#define square_iterate_end
Definition map.h:388
mem.h
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
move_points_text
const char * move_points_text(int mp, bool reduce)
Definition movement.c:973
can_exist_at_tile
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:275
can_unit_exist_at_tile
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:304
is_native_tile
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:316
can_unit_transport
bool can_unit_transport(const struct unit *transporter, const struct unit *transported)
Definition movement.c:813
unit_move_rate
int unit_move_rate(const struct unit *punit)
Definition movement.c:90
can_unit_survive_at_tile
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:476
is_native_near_tile
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:450
can_unit_type_transport
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:826
can_attack_non_native
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:202
movement.h
SINGLE_MOVE
#define SINGLE_MOVE
Definition movement.h:24
packets.h
MAX_LEN_MSG
#define MAX_LEN_MSG
Definition packets.h:43
cities
struct city_list * cities
Definition packhand.c:117
can_player_see_unit
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1084
pplayers_at_war
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1364
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
pplayers_non_attack
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1435
player.h
road.h
level
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:183
shared.h
ARRAY_SIZE
#define ARRAY_SIZE(x)
Definition shared.h:85
MIN
#define MIN(x, y)
Definition shared.h:55
FC_INFINITY
#define FC_INFINITY
Definition shared.h:36
MAX
#define MAX(x, y)
Definition shared.h:54
action
Definition actions.h:379
action::target_complexity
enum act_tgt_compl target_complexity
Definition actions.h:390
ai_type
Definition ai.h:50
astring
Definition astring.h:36
cargo_iter
Definition unit.c:51
cargo_iter::vtable
struct iterator vtable
Definition unit.c:52
cargo_iter::depth
int depth
Definition unit.c:54
cargo_iter::links
const struct unit_list_link * links[GAME_TRANSPORT_MAX_RECURSIVE]
Definition unit.c:53
city
Definition city.h:309
city::id
int id
Definition city.h:315
city::airlift
int airlift
Definition city.h:365
city::occupied
bool occupied
Definition city.h:443
city::tile
struct tile * tile
Definition city.h:311
city::client
struct city::@17::@20 client
civ_game::server
struct civ_game::@30::@34 server
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_game::killunhomed
int killunhomed
Definition game.h:153
civ_map
Definition map_types.h:71
extra_type
Definition extras.h:85
extra_type::ruledit_disabled
bool ruledit_disabled
Definition extras.h:88
iterator
Definition iterator.h:31
iterator::valid
bool(* valid)(const struct iterator *it)
Definition iterator.h:34
iterator::get
void *(* get)(const struct iterator *it)
Definition iterator.h:33
iterator::next
void(* next)(struct iterator *it)
Definition iterator.h:32
packet_game_info::borders
enum borders_mode borders
Definition packets_gen.h:133
packet_game_info::happyborders
enum happyborders_type happyborders
Definition packets_gen.h:177
packet_game_info::airlifting_style
enum airlifting_style airlifting_style
Definition packets_gen.h:123
packet_game_info::airlift_from_always_enabled
bool airlift_from_always_enabled
Definition packets_gen.h:124
packet_game_info::turn
int turn
Definition packets_gen.h:241
packet_game_info::base_bribe_cost
int base_bribe_cost
Definition packets_gen.h:134
packet_game_info::airlift_to_always_enabled
bool airlift_to_always_enabled
Definition packets_gen.h:125
packet_game_info::killcitizen
bool killcitizen
Definition packets_gen.h:187
packet_ruleset_control::num_extra_types
int num_extra_types
Definition packets_gen.h:1460
player_economic::gold
int gold
Definition player.h:70
player
Definition player.h:249
player::economic
struct player_economic economic
Definition player.h:284
req_context
Definition requirements.h:99
terrain
Definition terrain.h:176
tile
Definition tile.h:49
tile::units
struct unit_list * units
Definition tile.h:57
unit_class
Definition unittype.h:136
unit_class::hp_loss_pct
int hp_loss_pct
Definition unittype.h:142
unit_class::hiding_extras
struct extra_type_list * hiding_extras
Definition unittype.h:159
unit_order
Definition unit.h:92
unit_order::activity
enum unit_activity activity
Definition unit.h:94
unit_order::order
enum unit_orders order
Definition unit.h:93
unit_order::action
int action
Definition unit.h:100
unit_order::dir
enum direction8 dir
Definition unit.h:102
unit_order::target
int target
Definition unit.h:97
unit_order::sub_target
int sub_target
Definition unit.h:98
unit_type
Definition unittype.h:481
unit_type::transport_capacity
int transport_capacity
Definition unittype.h:504
unit_type::adv
struct unit_type::@87 adv
unit_type::worker
bool worker
Definition unittype.h:556
unit_type::move_rate
int move_rate
Definition unittype.h:497
unit_type::vlayer
enum vision_layer vlayer
Definition unittype.h:550
unit_type::hp
int hp
Definition unittype.h:505
unit_type::converted_to
const struct unit_type * converted_to
Definition unittype.h:511
unit
Definition unit.h:138
unit::action_timestamp
time_t action_timestamp
Definition unit.h:243
unit::length
int length
Definition unit.h:195
unit::upkeep
int upkeep[O_LAST]
Definition unit.h:148
unit::has_orders
bool has_orders
Definition unit.h:193
unit::action_decision_want
enum action_decision action_decision_want
Definition unit.h:202
unit::battlegroup
int battlegroup
Definition unit.h:191
unit::activity
enum unit_activity activity
Definition unit.h:157
unit::moves_left
int moves_left
Definition unit.h:150
unit::refcount
int refcount
Definition unit.h:141
unit::id
int id
Definition unit.h:145
unit::transporting
struct unit_list * transporting
Definition unit.h:184
unit::ord_city
int ord_city
Definition unit.h:240
unit::moved
bool moved
Definition unit.h:173
unit::ord_map
int ord_map
Definition unit.h:239
unit::debug
bool debug
Definition unit.h:231
unit::vision
struct vision * vision
Definition unit.h:242
unit::hp
int hp
Definition unit.h:151
unit::client
struct unit::@80::@82 client
unit::orders
struct unit::@79 orders
unit::fuel
int fuel
Definition unit.h:153
unit::changed_from_target
struct extra_type * changed_from_target
Definition unit.h:170
unit::stay
bool stay
Definition unit.h:205
unit::colored
bool colored
Definition unit.h:219
unit::facing
enum direction8 facing
Definition unit.h:142
unit::tile
struct tile * tile
Definition unit.h:140
unit::activity_target
struct extra_type * activity_target
Definition unit.h:164
unit::act_prob_cache
struct act_prob * act_prob_cache
Definition unit.h:225
unit::activity_count
int activity_count
Definition unit.h:162
unit::list
struct unit_order * list
Definition unit.h:198
unit::changed_from
enum unit_activity changed_from
Definition unit.h:168
unit::adv
struct unit_adv * adv
Definition unit.h:233
unit::nationality
struct player * nationality
Definition unit.h:144
unit::transported_by
int transported_by
Definition unit.h:213
unit::removal_callback
void(* removal_callback)(struct unit *punit)
Definition unit.h:251
unit::ais
void * ais[FREECIV_AI_MOD_LAST]
Definition unit.h:234
unit::action_turn
int action_turn
Definition unit.h:244
unit::server
struct unit::@80::@83 server
unit::homecity
int homecity
Definition unit.h:146
unit::upkeep_paid
int upkeep_paid[O_LAST]
Definition unit.h:254
unit::paradropped
bool paradropped
Definition unit.h:174
unit::done_moving
bool done_moving
Definition unit.h:181
unit::transporter
struct unit * transporter
Definition unit.h:183
unit::birth_turn
int birth_turn
Definition unit.h:235
unit::carrying
struct goods_type * carrying
Definition unit.h:186
unit::goto_tile
struct tile * goto_tile
Definition unit.h:155
unit::action_decision_tile
struct tile * action_decision_tile
Definition unit.h:203
unit::utype
const struct unit_type * utype
Definition unit.h:139
unit::veteran
int veteran
Definition unit.h:152
unit::changed_from_count
int changed_from_count
Definition unit.h:169
unit::owner
struct player * owner
Definition unit.h:143
unit::dying
bool dying
Definition unit.h:248
unit::focus_status
enum unit_focus_status focus_status
Definition unit.h:211
unit::ssa_controller
enum server_side_agent ssa_controller
Definition unit.h:172
veteran_level
Definition unittype.h:467
veteran_level::power_fact
int power_fact
Definition unittype.h:469
veteran_level::move_bonus
int move_bonus
Definition unittype.h:470
world::map
struct civ_map map
Definition world_object.h:38
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
support.h
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
valid_advance_by_number
struct advance * valid_advance_by_number(const Tech_type_id id)
Definition tech.c:176
tech.h
A_FUTURE
#define A_FUTURE
Definition tech.h:46
A_NONE
#define A_NONE
Definition tech.h:43
T_UNKNOWN
#define T_UNKNOWN
Definition terrain.h:57
terrain_has_flag
#define terrain_has_flag(terr, flag)
Definition terrain.h:269
tile_has_not_aggressive_extra_for_unit
bool tile_has_not_aggressive_extra_for_unit(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:193
tile_is_placing
bool tile_is_placing(const struct tile *ptile)
Definition tile.c:1114
tile_activity_time
int tile_activity_time(enum unit_activity activity, const struct tile *ptile, const struct extra_type *tgt)
Definition tile.c:412
tile_has_native_base
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:318
tile_get_known
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:386
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
TILE_KNOWN_UNSEEN
@ TILE_KNOWN_UNSEEN
Definition tile.h:36
TILE_KNOWN_SEEN
@ TILE_KNOWN_SEEN
Definition tile.h:37
ACTIVITY_FACTOR
#define ACTIVITY_FACTOR
Definition tile.h:164
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:109
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
tile_owner
#define tile_owner(_tile)
Definition tile.h:95
can_cities_trade
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:214
traderoutes.h
unit_can_do_action_sub_result
bool unit_can_do_action_sub_result(const struct unit *punit, enum action_sub_result sub_result)
Definition unit.c:350
cargo_iter_sizeof
size_t cargo_iter_sizeof(void)
Definition unit.c:2544
real_activities
Activity_type_id real_activities[ACTIVITY_LAST]
Definition unit.c:44
is_real_activity
bool is_real_activity(enum unit_activity activity)
Definition unit.c:605
can_unit_do_activity_targeted_at
bool can_unit_do_activity_targeted_at(const struct civ_map *nmap, const struct unit *punit, enum unit_activity activity, struct extra_type *target, const struct tile *ptile)
Definition unit.c:921
is_tile_activity
bool is_tile_activity(enum unit_activity activity)
Definition unit.c:1602
create_unit_orders
struct unit_order * create_unit_orders(const struct civ_map *nmap, int length, const struct unit_order *orders)
Definition unit.c:2821
unit_transform_result
enum unit_upgrade_result unit_transform_result(const struct civ_map *nmap, const struct unit *punit, const struct unit_type *to_unittype)
Definition unit.c:1936
unit_being_aggressive
bool unit_being_aggressive(const struct unit *punit)
Definition unit.c:1521
unit_type_really_ignores_zoc
bool unit_type_really_ignores_zoc(const struct unit_type *punittype)
Definition unit.c:1507
unit_type_is_losing_hp
bool unit_type_is_losing_hp(const struct player *pplayer, const struct unit_type *punittype)
Definition unit.c:2220
is_terrain_change_activity
bool is_terrain_change_activity(enum unit_activity activity)
Definition unit.c:1587
tile_non_allied_unit
struct unit * tile_non_allied_unit(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1329
unit_shield_value
int unit_shield_value(const struct unit *punit, const struct unit_type *punittype, const struct action *paction)
Definition unit.c:219
get_transporter_occupancy
int get_transporter_occupancy(const struct unit *ptrans)
Definition unit.c:1763
cargo_iter_next
static void cargo_iter_next(struct iterator *it)
Definition unit.c:2562
free_unit_orders
void free_unit_orders(struct unit *punit)
Definition unit.c:1749
can_unit_change_homecity
bool can_unit_change_homecity(const struct unit *punit)
Definition unit.c:460
unit_set_ai_data
void unit_set_ai_data(struct unit *punit, const struct ai_type *ai, void *data)
Definition unit.c:2270
unit_is_alive
bool unit_is_alive(int id)
Definition unit.c:2233
unit_can_est_trade_route_here
bool unit_can_est_trade_route_here(const struct unit *punit)
Definition unit.c:288
is_hiding_unit
bool is_hiding_unit(const struct unit *punit)
Definition unit.c:397
get_activity_rate_this_turn
int get_activity_rate_this_turn(const struct unit *punit)
Definition unit.c:501
unit_pays_mp_for_action
int unit_pays_mp_for_action(const struct action *paction, const struct unit *punit)
Definition unit.c:2115
get_turns_for_activity_at
int get_turns_for_activity_at(const struct unit *punit, enum unit_activity activity, const struct tile *ptile, struct extra_type *tgt)
Definition unit.c:517
is_plr_zoc_client
bool is_plr_zoc_client(const struct player *pplayer, const struct tile *ptile0, const struct civ_map *zmap)
Definition unit.c:1469
unit_transport_load
bool unit_transport_load(struct unit *pcargo, struct unit *ptrans, bool force)
Definition unit.c:2350
unit_can_add_or_build_city
bool unit_can_add_or_build_city(const struct unit *punit)
Definition unit.c:429
transporter_for_unit_at
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1902
cargo_iter_init
struct iterator * cargo_iter_init(struct cargo_iter *iter, const struct unit *ptrans)
Definition unit.c:2602
unit_upgrade_info
enum unit_upgrade_result unit_upgrade_info(const struct civ_map *nmap, const struct unit *punit, char *buf, size_t bufsz)
Definition unit.c:2031
unit_transport_depth
int unit_transport_depth(const struct unit *pcargo)
Definition unit.c:2531
set_unit_activity
void set_unit_activity(struct unit *punit, enum unit_activity new_activity)
Definition unit.c:1104
is_losing_hp
bool is_losing_hp(const struct unit *punit)
Definition unit.c:2208
can_unit_change_homecity_to
bool can_unit_change_homecity_to(const struct unit *punit, const struct city *pcity)
Definition unit.c:445
can_unit_load
bool can_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:740
tile_non_attack_unit
struct unit * tile_non_attack_unit(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1362
hp_gain_coord
int hp_gain_coord(const struct unit *punit)
Definition unit.c:2142
cargo_iter_get
static void * cargo_iter_get(const struct iterator *it)
Definition unit.c:2552
unit_nationality
struct player * unit_nationality(const struct unit *punit)
Definition unit.c:1268
get_activity_rate
int get_activity_rate(const struct unit *punit)
Definition unit.c:473
unit_transport_check
bool unit_transport_check(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:2459
is_attack_unit
bool is_attack_unit(const struct unit *punit)
Definition unit.c:309
tile_changing_activities
const Activity_type_id tile_changing_activities[]
Definition unit.c:46
setup_real_activities_array
void setup_real_activities_array(void)
Definition unit.c:587
unit_transport_get
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2421
unit_transport_unload
bool unit_transport_unload(struct unit *pcargo)
Definition unit.c:2370
is_build_activity
bool is_build_activity(enum unit_activity activity)
Definition unit.c:1556
unit_contained_in
bool unit_contained_in(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:2500
unit_gain_hitpoints
int unit_gain_hitpoints(const struct unit *punit)
Definition unit.c:2163
test_unit_can_airlift_to
enum unit_airlift_result test_unit_can_airlift_to(const struct civ_map *nmap, const struct player *restriction, const struct unit *punit, const struct city *pdest_city)
Definition unit.c:83
is_military_unit
bool is_military_unit(const struct unit *punit)
Definition unit.c:321
can_unit_continue_current_activity
bool can_unit_continue_current_activity(const struct civ_map *nmap, struct unit *punit)
Definition unit.c:842
unit_bribe_cost
int unit_bribe_cost(struct unit *punit, struct player *briber)
Definition unit.c:2284
unit_upkeep_astr
void unit_upkeep_astr(const struct unit *punit, struct astring *astr)
Definition unit.c:1254
could_unit_load
bool could_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:715
unit_is_cityfounder
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2619
is_unit_activity_on_tile
bool is_unit_activity_on_tile(enum unit_activity activity, const struct tile *ptile)
Definition unit.c:1139
can_unit_do_autosettlers
bool can_unit_do_autosettlers(const struct unit *punit)
Definition unit.c:579
unit_can_help_build_wonder_here
bool unit_can_help_build_wonder_here(const struct unit *punit)
Definition unit.c:263
can_unit_alight_or_be_unloaded
bool can_unit_alight_or_be_unloaded(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:792
is_field_unit
bool is_field_unit(const struct unit *punit)
Definition unit.c:385
cargo_iter_valid
static bool cargo_iter_valid(const struct iterator *it)
Definition unit.c:2594
unit_can_do_action
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:330
unit_can_do_action_result
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Definition unit.c:340
RETURN_IS_ACTIVITY_ENABLED_UNIT_ON
#define RETURN_IS_ACTIVITY_ENABLED_UNIT_ON(paction)
set_unit_activity_targeted
void set_unit_activity_targeted(struct unit *punit, enum unit_activity new_activity, struct extra_type *new_target)
Definition unit.c:1121
unit_virtual_create
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1613
unit_cargo_depth
int unit_cargo_depth(const struct unit *ptrans)
Definition unit.c:2513
unit_transport_check_one
static bool unit_transport_check_one(const struct unit_type *cargo_utype, const struct unit_type *trans_utype)
Definition unit.c:2443
CARGO_ITER
#define CARGO_ITER(iter)
Definition unit.c:56
unit_order_list_is_sane
bool unit_order_list_is_sane(const struct civ_map *nmap, int length, const struct unit_order *orders)
Definition unit.c:2628
get_activity_text
const char * get_activity_text(enum unit_activity activity)
Definition unit.c:621
get_unit_tile_pillage_set
bv_extras get_unit_tile_pillage_set(const struct tile *ptile)
Definition unit.c:1154
get_transporter_capacity
int get_transporter_capacity(const struct unit *punit)
Definition unit.c:301
is_plr_zoc_srv
bool is_plr_zoc_srv(const struct player *pplayer, const struct tile *ptile0, const struct civ_map *zmap)
Definition unit.c:1410
is_clean_activity
bool is_clean_activity(enum unit_activity activity)
Definition unit.c:1572
unit_can_airlift_to
bool unit_can_airlift_to(const struct unit *punit, const struct city *pdest_city)
Definition unit.c:188
can_unit_paradrop
bool can_unit_paradrop(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:823
unit_activity_astr
void unit_activity_astr(const struct unit *punit, struct astring *astr)
Definition unit.c:1171
can_unit_do_activity
bool can_unit_do_activity(const struct civ_map *nmap, const struct unit *punit, enum unit_activity activity)
Definition unit.c:869
tile_other_players_unit
struct unit * tile_other_players_unit(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1346
unit_virtual_destroy
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1709
tile_enemy_unit
struct unit * tile_enemy_unit(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1314
unit_tile_set
void unit_tile_set(struct unit *punit, struct tile *ptile)
Definition unit.c:1278
unit_upgrade_test
enum unit_upgrade_result unit_upgrade_test(const struct civ_map *nmap, const struct unit *punit, bool is_free)
Definition unit.c:1968
kills_citizen_after_attack
bool kills_citizen_after_attack(const struct unit *punit)
Definition unit.c:419
unit_transported
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2405
are_unit_orders_equal
bool are_unit_orders_equal(const struct unit_order *order1, const struct unit_order *order2)
Definition unit.c:61
unit_is_virtual
bool unit_is_virtual(const struct unit *punit)
Definition unit.c:2250
set_unit_activity_internal
static void set_unit_activity_internal(struct unit *punit, enum unit_activity new_activity)
Definition unit.c:1086
is_square_threatened
bool is_square_threatened(const struct civ_map *nmap, const struct player *pplayer, const struct tile *ptile, bool omniscient)
Definition unit.c:359
can_unit_unload
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:767
unit_occupies_tile
struct unit * unit_occupies_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1383
unit_transport_cargo
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Definition unit.c:2431
can_type_transport_units_cargo
static bool can_type_transport_units_cargo(const struct unit_type *utype, const struct unit *punit)
Definition unit.c:1912
unit_ai_data
void * unit_ai_data(const struct unit *punit, const struct ai_type *ai)
Definition unit.c:2262
unit_has_orders
bool unit_has_orders(const struct unit *punit)
Definition unit.c:207
tile_allied_unit
struct unit * tile_allied_unit(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1291
transporter_for_unit
struct unit * transporter_for_unit(const struct unit *pcargo)
Definition unit.c:1892
base_transporter_for_unit
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))
Definition unit.c:1773
unit_can_convert
bool unit_can_convert(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:2015
activity_requires_target
bool activity_requires_target(enum unit_activity activity)
Definition unit.c:537
could_unit_be_in_transport
bool could_unit_be_in_transport(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:683
can_unit_do_activity_targeted
bool can_unit_do_activity_targeted(const struct civ_map *nmap, const struct unit *punit, enum unit_activity activity, struct extra_type *target)
Definition unit.c:908
unit.h
unit_tile
#define unit_tile(_pu)
Definition unit.h:388
unit_transports_iterate_end
#define unit_transports_iterate_end
Definition unit.h:552
unit_cargo_iterate_end
#define unit_cargo_iterate_end
Definition unit.h:562
FOCUS_AVAIL
@ FOCUS_AVAIL
Definition unit.h:53
BATTLEGROUP_NONE
#define BATTLEGROUP_NONE
Definition unit.h:190
unit_orders
unit_orders
Definition unit.h:37
ORDER_ACTION_MOVE
@ ORDER_ACTION_MOVE
Definition unit.h:45
ORDER_ACTIVITY
@ ORDER_ACTIVITY
Definition unit.h:41
ORDER_FULL_MP
@ ORDER_FULL_MP
Definition unit.h:43
ORDER_MOVE
@ ORDER_MOVE
Definition unit.h:39
ORDER_LAST
@ ORDER_LAST
Definition unit.h:49
ORDER_PERFORM_ACTION
@ ORDER_PERFORM_ACTION
Definition unit.h:47
unit_transported_server
#define unit_transported_server(_pcargo_)
Definition unit.h:530
unit_cargo_iterate
#define unit_cargo_iterate(_ptrans, _pcargo)
Definition unit.h:559
unit_owner
#define unit_owner(_pu)
Definition unit.h:387
unit_transports_iterate
#define unit_transports_iterate(_pcargo, _ptrans)
Definition unit.h:548
unit_upgrade_result
unit_upgrade_result
Definition unit.h:60
UU_NO_MONEY
@ UU_NO_MONEY
Definition unit.h:63
UU_NOT_IN_CITY
@ UU_NOT_IN_CITY
Definition unit.h:64
UU_NO_UNITTYPE
@ UU_NO_UNITTYPE
Definition unit.h:62
UU_NOT_TERRAIN
@ UU_NOT_TERRAIN
Definition unit.h:67
UU_UNSUITABLE_TRANSPORT
@ UU_UNSUITABLE_TRANSPORT
Definition unit.h:68
UU_NOT_CITY_OWNER
@ UU_NOT_CITY_OWNER
Definition unit.h:65
UU_NOT_ENOUGH_ROOM
@ UU_NOT_ENOUGH_ROOM
Definition unit.h:66
UU_OK
@ UU_OK
Definition unit.h:61
UU_NOT_ACTIVITY
@ UU_NOT_ACTIVITY
Definition unit.h:69
unit_transported_client
#define unit_transported_client(_pcargo_)
Definition unit.h:533
unit_airlift_result
unit_airlift_result
Definition unit.h:72
AR_SRC_NO_FLIGHTS
@ AR_SRC_NO_FLIGHTS
Definition unit.h:84
AR_OK_SRC_UNKNOWN
@ AR_OK_SRC_UNKNOWN
Definition unit.h:75
AR_OK_DST_UNKNOWN
@ AR_OK_DST_UNKNOWN
Definition unit.h:76
AR_NO_MOVES
@ AR_NO_MOVES
Definition unit.h:78
AR_BAD_DST_CITY
@ AR_BAD_DST_CITY
Definition unit.h:83
AR_NOT_IN_CITY
@ AR_NOT_IN_CITY
Definition unit.h:81
AR_OCCUPIED
@ AR_OCCUPIED
Definition unit.h:80
AR_OK
@ AR_OK
Definition unit.h:74
AR_DST_NO_FLIGHTS
@ AR_DST_NO_FLIGHTS
Definition unit.h:85
AR_WRONG_UNITTYPE
@ AR_WRONG_UNITTYPE
Definition unit.h:79
AR_BAD_SRC_CITY
@ AR_BAD_SRC_CITY
Definition unit.h:82
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_safe
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unit_list_iterate_safe_end
#define unit_list_iterate_safe_end
Definition unitlist.h:61
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
utype_pays_mp_for_action_base
int utype_pays_mp_for_action_base(const struct action *paction, const struct unit_type *putype)
Definition unittype.c:1433
utype_can_freely_unload
bool utype_can_freely_unload(const struct unit_type *pcargotype, const struct unit_type *ptranstype)
Definition unittype.c:294
unit_name_translation
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1621
utype_is_moved_to_tgt_by_action
bool utype_is_moved_to_tgt_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1301
utype_is_cityfounder
bool utype_is_cityfounder(const struct unit_type *utype)
Definition unittype.c:2967
unit_rule_name
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1639
utype_build_shield_cost_base
int utype_build_shield_cost_base(const struct unit_type *punittype)
Definition unittype.c:1520
utype_may_act_move_frags
bool utype_may_act_move_frags(const struct unit_type *punit_type, const action_id act_id, const int move_fragments)
Definition unittype.c:1110
unit_build_shield_cost_base
int unit_build_shield_cost_base(const struct unit *punit)
Definition unittype.c:1536
can_upgrade_unittype
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1755
utype_can_freely_load
bool utype_can_freely_load(const struct unit_type *pcargotype, const struct unit_type *ptranstype)
Definition unittype.c:282
utype_veteran_levels
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2661
unit_class_get
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2546
utype_can_do_action_result
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:459
utype_veteran_level
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2631
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:184
utype_is_consumed_by_action
bool utype_is_consumed_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1271
utype_can_do_action_sub_result
bool utype_can_do_action_sub_result(const struct unit_type *putype, enum action_sub_result sub_result)
Definition unittype.c:480
utype_is_unmoved_by_action
bool utype_is_unmoved_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1340
utype_acts_hostile
bool utype_acts_hostile(const struct unit_type *putype)
Definition unittype.c:515
utype_name_translation
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1612
utype_can_do_action
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:443
unit_upgrade_price
int unit_upgrade_price(const struct player *pplayer, const struct unit_type *from, const struct unit_type *to)
Definition unittype.c:1783
uclass_has_flag
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:753
utype_class
#define utype_class(_t_)
Definition unittype.h:736
utype_fuel
#define utype_fuel(ptype)
Definition unittype.h:822
utype_has_flag
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:604