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

Freeciv-3.1

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