Freeciv-3.2: /fast/freeciv/nightly/S3_2/common/unit.c Source File

Freeciv-3.2

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