webperimental: killstack decides stack protects.
[freeciv.git] / server / unittools.h
blob4936adb7477816cb267e2d0e405646c73e5a3734
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.
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 #ifndef FC__UNITTOOLS_H
14 #define FC__UNITTOOLS_H
16 #include "fc_types.h"
18 #include "packets.h" /* enum unit_info_use */
19 #include "unitlist.h"
21 #define SPECENUM_NAME unit_loss_reason
22 #define SPECENUM_VALUE0 ULR_KILLED
23 #define SPECENUM_VALUE0NAME "killed"
24 #define SPECENUM_VALUE1 ULR_RETIRED
25 #define SPECENUM_VALUE1NAME "retired"
26 #define SPECENUM_VALUE2 ULR_DISBANDED
27 #define SPECENUM_VALUE2NAME "disbanded"
28 #define SPECENUM_VALUE3 ULR_BARB_UNLEASH
29 #define SPECENUM_VALUE3NAME "barb_unleash"
30 #define SPECENUM_VALUE4 ULR_CITY_LOST
31 #define SPECENUM_VALUE4NAME "city_lost"
32 #define SPECENUM_VALUE5 ULR_STARVED
33 #define SPECENUM_VALUE5NAME "starved"
34 #define SPECENUM_VALUE6 ULR_SOLD
35 #define SPECENUM_VALUE6NAME "sold"
36 #define SPECENUM_VALUE7 ULR_USED
37 #define SPECENUM_VALUE7NAME "used"
38 #define SPECENUM_VALUE8 ULR_EXECUTED
39 #define SPECENUM_VALUE8NAME "executed"
40 #define SPECENUM_VALUE9 ULR_ELIMINATED
41 #define SPECENUM_VALUE9NAME "eliminated"
42 #define SPECENUM_VALUE10 ULR_EDITOR
43 #define SPECENUM_VALUE10NAME "editor"
44 #define SPECENUM_VALUE11 ULR_NONNATIVE_TERR
45 #define SPECENUM_VALUE11NAME "nonnative_terr"
46 #define SPECENUM_VALUE12 ULR_PLAYER_DIED
47 #define SPECENUM_VALUE12NAME "player_died"
48 #define SPECENUM_VALUE13 ULR_ARMISTICE
49 #define SPECENUM_VALUE13NAME "armistice"
50 #define SPECENUM_VALUE14 ULR_SDI
51 #define SPECENUM_VALUE14NAME "sdi"
52 #define SPECENUM_VALUE15 ULR_DETONATED
53 #define SPECENUM_VALUE15NAME "detonated"
54 #define SPECENUM_VALUE16 ULR_MISSILE
55 #define SPECENUM_VALUE16NAME "missile"
56 #define SPECENUM_VALUE17 ULR_NUKE
57 #define SPECENUM_VALUE17NAME "nuke"
58 #define SPECENUM_VALUE18 ULR_HP_LOSS
59 #define SPECENUM_VALUE18NAME "hp_loss"
60 #define SPECENUM_VALUE19 ULR_FUEL
61 #define SPECENUM_VALUE19NAME "fuel"
62 #define SPECENUM_VALUE20 ULR_STACK_CONFLICT
63 #define SPECENUM_VALUE20NAME "stack_conflict"
64 #define SPECENUM_VALUE21 ULR_BRIBED
65 #define SPECENUM_VALUE21NAME "bribed"
66 #define SPECENUM_VALUE22 ULR_CAPTURED
67 #define SPECENUM_VALUE22NAME "captured"
68 #define SPECENUM_VALUE23 ULR_CAUGHT
69 #define SPECENUM_VALUE23NAME "caught"
70 #define SPECENUM_VALUE24 ULR_TRANSPORT_LOST
71 #define SPECENUM_VALUE24NAME "transport_lost"
72 #include "specenum_gen.h"
74 /* battle related */
75 struct unit_type *find_a_unit_type(enum unit_role_id role,
76 enum unit_role_id role_tech);
77 bool maybe_make_veteran(struct unit *punit);
78 void notify_unit_experience(struct unit *punit);
79 void unit_versus_unit(struct unit *attacker, struct unit *defender,
80 int *att_hp, int *def_hp);
81 void unit_bombs_unit(struct unit *attacker, struct unit *defender,
82 int *att_hp, int *def_hp);
83 void combat_veterans(struct unit *attacker, struct unit *defender);
85 /* move check related */
86 bool is_unit_being_refueled(const struct unit *punit);
87 bool is_airunit_refuel_point(const struct tile *ptile,
88 const struct player *pplayer,
89 const struct unit *punit);
91 /* turn update related */
92 void player_restore_units(struct player *pplayer);
93 void update_unit_activities(struct player *pplayer);
94 void execute_unit_orders(struct player *pplayer);
95 void finalize_unit_phase_beginning(struct player *pplayer);
97 /* various */
98 void place_partisans(struct tile *pcenter, struct player *powner,
99 int count, int sq_radius);
100 bool teleport_unit_to_city(struct unit *punit, struct city *pcity, int move_cost,
101 bool verbose);
102 void resolve_unit_stacks(struct player *pplayer, struct player *aplayer,
103 bool verbose);
104 struct unit_list *get_units_seen_via_ally(const struct player *pplayer,
105 const struct player *aplayer);
106 void remove_allied_visibility(struct player *pplayer, struct player *aplayer,
107 const struct unit_list *seen_units);
108 void give_allied_visibility(struct player *pplayer, struct player *aplayer);
109 int get_unit_vision_at(struct unit *punit, struct tile *ptile,
110 enum vision_layer vlayer);
111 void unit_refresh_vision(struct unit *punit);
112 void unit_list_refresh_vision(struct unit_list *punitlist);
113 void bounce_unit(struct unit *punit, bool verbose);
114 bool unit_activity_needs_target_from_client(enum unit_activity activity);
115 void unit_assign_specific_activity_target(struct unit *punit,
116 enum unit_activity *activity,
117 struct extra_type **target);
118 void unit_forget_last_activity(struct unit *punit);
120 /* creation/deletion/upgrading */
121 void transform_unit(struct unit *punit, struct unit_type *to_unit,
122 bool has_to_pay);
123 struct unit *create_unit(struct player *pplayer, struct tile *ptile,
124 struct unit_type *punittype,
125 int veteran_level, int homecity_id, int moves_left);
126 struct unit *create_unit_full(struct player *pplayer, struct tile *ptile,
127 struct unit_type *punittype, int veteran_level,
128 int homecity_id, int moves_left, int hp_left,
129 struct unit *ptrans);
130 void wipe_unit(struct unit *punit, enum unit_loss_reason reason,
131 struct player *killer);
132 void kill_unit(struct unit *pkiller, struct unit *punit, bool vet);
134 struct unit *unit_change_owner(struct unit *punit, struct player *pplayer,
135 int homecity, enum unit_loss_reason reason)
136 fc__warn_unused_result;
138 void unit_set_removal_callback(struct unit *punit,
139 void (*callback)(struct unit *punit));
140 void unit_unset_removal_callback(struct unit *punit);
142 /* sending to client */
143 void package_unit(struct unit *punit, struct packet_unit_info *packet);
144 void package_short_unit(struct unit *punit,
145 struct packet_unit_short_info *packet,
146 enum unit_info_use packet_use, int info_city_id);
147 void send_unit_info(struct conn_list *dest, struct unit *punit);
148 void send_all_known_units(struct conn_list *dest);
149 void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit);
151 /* doing a unit activity */
152 void do_nuclear_explosion(struct player *pplayer, struct tile *ptile);
153 bool do_airline(struct unit *punit, struct city *city2);
154 void do_explore(struct unit *punit);
155 bool do_paradrop(struct unit *punit, struct tile *ptile);
156 void unit_transport_load_send(struct unit *punit, struct unit *ptrans);
157 void unit_transport_unload_send(struct unit *punit);
158 bool unit_move(struct unit *punit, struct tile *ptile, int move_cost,
159 struct unit *embark_to, bool conquer_city_allowed);
160 bool execute_orders(struct unit *punit, const bool fresh);
162 bool unit_can_do_action_now(const struct unit *punit);
163 void unit_did_action(struct unit *punit);
165 bool unit_can_be_retired(struct unit *punit);
167 void unit_activities_cancel_all_illegal(const struct tile *ptile);
169 void unit_get_goods(struct unit *punit);
171 #endif /* FC__UNITTOOLS_H */