Freeciv-3.1
Loading...
Searching...
No Matches
unittools.h
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#ifndef FC__UNITTOOLS_H
14#define FC__UNITTOOLS_H
15
16/* common */
17#include "fc_types.h"
18#include "packets.h" /* enum unit_info_use */
19#include "unitlist.h"
20
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/* Upkeep other than one of the above ones */
37#define SPECENUM_VALUE7 ULR_UPKEEP
38#define SPECENUM_VALUE7NAME "upkeep"
39#define SPECENUM_VALUE8 ULR_USED
40#define SPECENUM_VALUE8NAME "used"
41#define SPECENUM_VALUE9 ULR_EXECUTED
42#define SPECENUM_VALUE9NAME "executed"
43#define SPECENUM_VALUE10 ULR_ELIMINATED
44#define SPECENUM_VALUE10NAME "eliminated"
45#define SPECENUM_VALUE11 ULR_EDITOR
46#define SPECENUM_VALUE11NAME "editor"
47#define SPECENUM_VALUE12 ULR_NONNATIVE_TERR
48#define SPECENUM_VALUE12NAME "nonnative_terr"
49#define SPECENUM_VALUE13 ULR_PLAYER_DIED
50#define SPECENUM_VALUE13NAME "player_died"
51#define SPECENUM_VALUE14 ULR_ARMISTICE
52#define SPECENUM_VALUE14NAME "armistice"
53#define SPECENUM_VALUE15 ULR_SDI
54#define SPECENUM_VALUE15NAME "sdi"
55#define SPECENUM_VALUE16 ULR_DETONATED
56#define SPECENUM_VALUE16NAME "detonated"
57#define SPECENUM_VALUE17 ULR_MISSILE
58#define SPECENUM_VALUE17NAME "missile"
59#define SPECENUM_VALUE18 ULR_NUKE
60#define SPECENUM_VALUE18NAME "nuke"
61#define SPECENUM_VALUE19 ULR_HP_LOSS
62#define SPECENUM_VALUE19NAME "hp_loss"
63#define SPECENUM_VALUE20 ULR_FUEL
64#define SPECENUM_VALUE20NAME "fuel"
65#define SPECENUM_VALUE21 ULR_STACK_CONFLICT
66#define SPECENUM_VALUE21NAME "stack_conflict"
67#define SPECENUM_VALUE22 ULR_BRIBED
68#define SPECENUM_VALUE22NAME "bribed"
69#define SPECENUM_VALUE23 ULR_CAPTURED
70#define SPECENUM_VALUE23NAME "captured"
71#define SPECENUM_VALUE24 ULR_CAUGHT
72#define SPECENUM_VALUE24NAME "caught"
73#define SPECENUM_VALUE25 ULR_TRANSPORT_LOST
74#define SPECENUM_VALUE25NAME "transport_lost"
75#include "specenum_gen.h"
76
77/* battle related */
78struct unit_type *find_a_unit_type(enum unit_role_id role,
79 enum unit_role_id role_tech);
80bool maybe_make_veteran(struct unit *punit, int base_chance);
82bool unit_versus_unit(struct unit *attacker, struct unit *defender,
83 int *att_hp, int *def_hp, int *att_vet, int *def_vet);
84void unit_bombs_unit(struct unit *attacker, struct unit *defender,
85 int *att_hp, int *def_hp);
86void combat_veterans(struct unit *attacker, struct unit *defender,
87 bool powerless, int att_vet, int def_vet);
88
89/* Move check related */
90bool is_unit_being_refueled(const struct unit *punit);
91bool is_refuel_point(const struct tile *ptile,
92 const struct player *pplayer,
93 const struct unit *punit);
94
95/* Turn update related */
96void player_restore_units(struct player *pplayer);
97void update_unit_activities(struct player *pplayer);
98void execute_unit_orders(struct player *pplayer);
99void unit_tc_effect_refresh(struct player *pplayer);
100void finalize_unit_phase_beginning(struct player *pplayer);
101
102/* Various */
103void place_partisans(struct tile *pcenter, struct player *powner,
104 int count, int sq_radius);
105bool teleport_unit_to_city(struct unit *punit, struct city *pcity, int move_cost,
106 bool verbose);
107void resolve_unit_stacks(struct player *pplayer, struct player *aplayer,
108 bool verbose);
109struct unit_list *get_units_seen_via_ally(const struct player *pplayer,
110 const struct player *aplayer);
111void remove_allied_visibility(struct player *pplayer, struct player *aplayer,
112 const struct unit_list *seen_units);
113void give_allied_visibility(struct player *pplayer, struct player *aplayer);
114int get_unit_vision_at(struct unit *punit, const struct tile *ptile,
115 enum vision_layer vlayer);
116void unit_refresh_vision(struct unit *punit);
117void unit_list_refresh_vision(struct unit_list *punitlist);
118void bounce_unit(struct unit *punit, bool verbose);
119bool unit_activity_needs_target_from_client(enum unit_activity activity);
121 enum unit_activity *activity,
122 struct extra_type **target);
124
125/* creation/deletion/upgrading */
126void transform_unit(struct unit *punit, const struct unit_type *to_unit,
127 int vet_loss);
128struct unit *create_unit(struct player *pplayer, struct tile *ptile,
129 const struct unit_type *punittype,
130 int veteran_level, int homecity_id, int moves_left);
131struct unit *create_unit_full(struct player *pplayer, struct tile *ptile,
132 const struct unit_type *punittype, int veteran_level,
133 int homecity_id, int moves_left, int hp_left,
134 struct unit *ptrans);
135struct unit *unit_virtual_prepare(struct player *pplayer, struct tile *ptile,
136 const struct unit_type *type,
137 int veteran_level, int homecity_id,
138 int moves_left, int hp_left);
139bool place_unit(struct unit *punit, struct player *pplayer,
140 struct city *pcity, struct unit *ptrans, bool force);
141void wipe_unit(struct unit *punit, enum unit_loss_reason reason,
142 struct player *killer);
143void kill_unit(struct unit *pkiller, struct unit *punit, bool vet);
144
145struct unit *unit_change_owner(struct unit *punit, struct player *pplayer,
146 int homecity, enum unit_loss_reason reason)
148
150 void (*callback)(struct unit *punit));
152
153/* sending to client */
154void package_unit(struct unit *punit, struct packet_unit_info *packet);
155void package_short_unit(struct unit *punit,
156 struct packet_unit_short_info *packet,
157 enum unit_info_use packet_use, int info_city_id);
158void send_unit_info(struct conn_list *dest, struct unit *punit);
159void send_all_known_units(struct conn_list *dest);
160void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit);
161
162/* doing a unit activity */
163void do_nuclear_explosion(struct player *pplayer, struct tile *ptile);
164bool do_airline(struct unit *punit, struct city *city2,
165 const struct action *paction);
166void do_explore(struct unit *punit);
167bool do_paradrop(struct unit *punit, struct tile *ptile,
168 const struct action *paction);
169void unit_transport_load_send(struct unit *punit, struct unit *ptrans);
171bool unit_move(struct unit *punit, struct tile *pdesttile, int move_cost,
172 struct unit *embark_to, bool find_embark_target,
173 bool conquer_city_allowed, bool conquer_extras_allowed,
174 bool enter_hut, bool frighten_hut);
175bool execute_orders(struct unit *punit, const bool fresh);
176
177bool unit_can_do_action_now(const struct unit *punit);
178void unit_did_action(struct unit *punit);
179
180bool unit_can_be_retired(struct unit *punit);
181
182void unit_activities_cancel(struct unit *punit);
183void unit_activities_cancel_all_illegal_plr(const struct player *pplayer);
184void unit_activities_cancel_all_illegal_tile(const struct tile *ptile);
185void unit_activities_cancel_all_illegal_area(const struct tile *ptile);
186
187void unit_get_goods(struct unit *punit);
188
189#endif /* FC__UNITTOOLS_H */
static void enter_hut(QVariant data1, QVariant data2)
Definition dialogs.cpp:2571
static void frighten_hut(QVariant data1, QVariant data2)
Definition dialogs.cpp:2601
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
GType type
Definition repodlgs.c:1312
unit_info_use
Definition packets.h:81
Definition city.h:309
Definition tile.h:49
Definition unit.h:138
int moves_left
Definition unit.h:150
int homecity
Definition unit.h:146
#define fc__warn_unused_result
Definition support.h:99
void unit_did_action(struct unit *punit)
Definition unittools.c:4913
void place_partisans(struct tile *pcenter, struct player *powner, int count, int sq_radius)
Definition unittools.c:1177
bool do_airline(struct unit *punit, struct city *city2, const struct action *paction)
Definition unittools.c:2963
bool execute_orders(struct unit *punit, const bool fresh)
Definition unittools.c:4372
void update_unit_activities(struct player *pplayer)
Definition unittools.c:658
void transform_unit(struct unit *punit, const struct unit_type *to_unit, int vet_loss)
Definition unittools.c:1565
struct unit_list * get_units_seen_via_ally(const struct player *pplayer, const struct player *aplayer)
Definition unittools.c:1429
void remove_allied_visibility(struct player *pplayer, struct player *aplayer, const struct unit_list *seen_units)
Definition unittools.c:1464
void combat_veterans(struct unit *attacker, struct unit *defender, bool powerless, int att_vet, int def_vet)
Definition unittools.c:392
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
Definition unittools.c:1414
void unit_set_removal_callback(struct unit *punit, void(*callback)(struct unit *punit))
Definition unittools.c:1781
void unit_bombs_unit(struct unit *attacker, struct unit *defender, int *att_hp, int *def_hp)
Definition unittools.c:352
void package_unit(struct unit *punit, struct packet_unit_info *packet)
Definition unittools.c:2650
void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit)
Definition unittools.c:2781
void unit_activities_cancel_all_illegal_plr(const struct player *pplayer)
Definition unittools.c:806
void finalize_unit_phase_beginning(struct player *pplayer)
Definition unittools.c:690
void execute_unit_orders(struct player *pplayer)
Definition unittools.c:668
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2794
struct unit * unit_change_owner(struct unit *punit, struct player *pplayer, int homecity, enum unit_loss_reason reason) fc__warn_unused_result
Definition unittools.c:2307
int get_unit_vision_at(struct unit *punit, const struct tile *ptile, enum vision_layer vlayer)
Definition unittools.c:4839
bool unit_versus_unit(struct unit *attacker, struct unit *defender, int *att_hp, int *def_hp, int *att_vet, int *def_vet)
Definition unittools.c:286
bool place_unit(struct unit *punit, struct player *pplayer, struct city *pcity, struct unit *ptrans, bool force)
Definition unittools.c:1723
void notify_unit_experience(struct unit *punit)
Definition unittools.c:735
void unit_activities_cancel(struct unit *punit)
Definition unittools.c:788
void package_short_unit(struct unit *punit, struct packet_unit_short_info *packet, enum unit_info_use packet_use, int info_city_id)
Definition unittools.c:2733
struct unit * unit_virtual_prepare(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left, int hp_left)
Definition unittools.c:1675
void give_allied_visibility(struct player *pplayer, struct player *aplayer)
Definition unittools.c:1488
void unit_forget_last_activity(struct unit *punit)
Definition unittools.c:1069
void unit_unset_removal_callback(struct unit *punit)
Definition unittools.c:1795
bool maybe_make_veteran(struct unit *punit, int base_chance)
Definition unittools.c:217
void unit_refresh_vision(struct unit *punit)
Definition unittools.c:4852
void do_explore(struct unit *punit)
Definition unittools.c:2996
void unit_transport_load_send(struct unit *punit, struct unit *ptrans)
Definition unittools.c:3276
bool unit_can_do_action_now(const struct unit *punit)
Definition unittools.c:4880
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2247
void unit_tc_effect_refresh(struct player *pplayer)
Definition unittools.c:680
bool do_paradrop(struct unit *punit, struct tile *ptile, const struct action *paction)
Definition unittools.c:3032
void player_restore_units(struct player *pplayer)
Definition unittools.c:469
void do_nuclear_explosion(struct player *pplayer, struct tile *ptile)
Definition unittools.c:2946
bool is_refuel_point(const struct tile *ptile, const struct player *pplayer, const struct unit *punit)
Definition unittools.c:1543
void unit_transport_unload_send(struct unit *punit)
Definition unittools.c:3328
bool is_unit_being_refueled(const struct unit *punit)
Definition unittools.c:1534
struct unit_type * find_a_unit_type(enum unit_role_id role, enum unit_role_id role_tech)
Definition unittools.c:174
bool unit_can_be_retired(struct unit *punit)
Definition unittools.c:4928
struct unit * create_unit(struct player *pplayer, struct tile *ptile, const struct unit_type *punittype, int veteran_level, int homecity_id, int moves_left)
Definition unittools.c:1615
void unit_activities_cancel_all_illegal_tile(const struct tile *ptile)
Definition unittools.c:818
bool teleport_unit_to_city(struct unit *punit, struct city *pcity, int move_cost, bool verbose)
Definition unittools.c:1203
void unit_assign_specific_activity_target(struct unit *punit, enum unit_activity *activity, struct extra_type **target)
Definition unittools.c:1098
void unit_activities_cancel_all_illegal_area(const struct tile *ptile)
Definition unittools.c:833
struct unit * create_unit_full(struct player *pplayer, struct tile *ptile, const struct unit_type *punittype, int veteran_level, int homecity_id, int moves_left, int hp_left, struct unit *ptrans)
Definition unittools.c:1642
void unit_get_goods(struct unit *punit)
Definition unittools.c:1626
void send_all_known_units(struct conn_list *dest)
Definition unittools.c:2838
bool unit_move(struct unit *punit, struct tile *pdesttile, int move_cost, struct unit *embark_to, bool find_embark_target, bool conquer_city_allowed, bool conquer_extras_allowed, bool enter_hut, bool frighten_hut)
Definition unittools.c:3884
void unit_list_refresh_vision(struct unit_list *punitlist)
Definition unittools.c:4869
void kill_unit(struct unit *pkiller, struct unit *punit, bool vet)
Definition unittools.c:2373
void bounce_unit(struct unit *punit, bool verbose)
Definition unittools.c:1241
bool unit_activity_needs_target_from_client(enum unit_activity activity)
Definition unittools.c:1078