17 #include <QLoggingCategory>
64 if (punit->action_turn !=
game.
info.turn - 1) {
68 dt = time(
nullptr) - punit->action_timestamp;
109 finder.pop_waypoint();
132 finder.pop_waypoint();
135 popped |= finder.pop_waypoint();
222 const struct unit *punit)
255 for (
const auto punit : units) {
260 it->second.set_constraint(
261 std::make_unique<freeciv::tile_known_constraint>(
client_player()));
295 finder.unit_changed(*punit);
309 int *turns,
bool *waypoint)
342 const auto destination =
346 if (path && !path->empty()) {
347 const auto steps = path->steps();
348 int last_waypoints = 0;
350 for (
const auto step : steps) {
351 if (ptile ==
step.location) {
352 *waypoint |= (
step.waypoints > last_waypoints);
353 if (
step.turns > last_turns) {
356 *turns = std::max(*turns,
step.turns);
359 last_turns =
step.turns;
360 last_waypoints =
step.waypoints;
363 if (ptile == steps.back().location) {
369 *turns = std::max(*turns, steps.back().turns);
375 return (*turns != -1 || *waypoint);
386 if (
nullptr == dest_tile) {
396 auto destination = dest_tile;
401 finder.pop_waypoint();
402 finder.push_waypoint(dest_tile);
417 const auto first_unsafe =
419 const auto &steps = path->steps();
420 for (
auto it = steps.begin(); it != steps.end(); ++it) {
421 const auto &
step = *it;
422 if (
auto dir = direction8_invalid();
423 previous_tile !=
nullptr
425 step.location, &dir)) {
429 previous_tile =
step.location;
444 struct packet_unit_orders p;
451 qCDebug(goto_category,
"Clearing orders for unit %d.", punit->
id);
452 p.unit_id = punit->
id;
472 struct tile *old_tile;
476 "Unit %d has moved without goto cancelation.",
481 *length = path.
length() - 1;
483 old_tile = path[0].tile;
486 for (i = 0; i < path.
length() - 1; i++) {
487 struct tile *new_tile = path[i + 1].tile;
492 order_list[i].
activity = ACTIVITY_LAST;
496 qCDebug(goto_category,
" packet[%d] = wait: %d,%d", i,
499 order_list[i].
order = orders;
500 order_list[i].
dir =
static_cast<direction8
>(
502 order_list[i].
activity = ACTIVITY_LAST;
506 qCDebug(goto_category,
" packet[%d] = move %s: %d,%d => %d,%d", i,
513 if (i > 0 && order_list[i - 1].order ==
ORDER_MOVE
531 qCDebug(goto_category,
"unit or city blocks the path of your %s",
539 order_list[i].
dir = final_order->
dir;
558 bool repeat,
bool vigilant,
562 struct packet_unit_orders p;
564 if (path.
length() == 1 && final_order ==
nullptr) {
568 memset(&p, 0,
sizeof(p));
569 p.unit_id = punit->
id;
572 p.vigilant = vigilant;
574 qCDebug(goto_category,
"Orders for unit %d:", punit->
id);
575 qCDebug(goto_category,
" Repeat: %d. Vigilant: %d.", p.repeat,
589 const PFPath &path,
bool vigilant,
593 struct packet_city_rally_point p;
595 memset(&p, 0,
sizeof(p));
596 p.city_id = pcity->
id;
597 p.vigilant = vigilant;
599 qCDebug(goto_category,
"Rally orders for city %d:", pcity->
id);
600 qCDebug(goto_category,
" Vigilant: %d.", p.vigilant);
605 send_packet_city_rally_point(&
client.
conn, &p);
762 return order_requires_adjacent(order,
action);
776 bool edit_last_order(packet_unit_orders &packet,
const tile *tgt_tile)
785 const bool have_move =
787 && (packet.orders[packet.length - 1].order ==
ORDER_MOVE
810 packet.orders[packet.length - 1].order =
ORDER_MOVE;
819 packet.orders[packet.length - 1] =
unit_order{
855 auto packet = packet_unit_orders{};
856 packet.unit_id = unit_id;
862 const auto steps = path->steps();
865 packet.length = steps.size();
866 for (std::size_t i = 0; i < steps.size(); ++i) {
867 packet.orders[i] = steps[i].order;
871 if (!edit_last_order(packet, destination)) {
878 send_packet_unit_orders(&
client.
conn, &packet);
903 if (path.length() < 2) {
906 dtile = path[-2].tile;
#define action_id_distance_accepted(act_id, distance)
struct city * is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non_allied city on this tile?
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
How many veteran levels will created unit of this type get?
A path finding destination that accepts any path leading to a specific tile.
struct player * client_player()
Either controlling or observing.
bool can_client_issue_orders()
Returns TRUE iff the client can issue orders (such as giving unit commands).
std::vector< unit * > & get_units_in_focus()
Returns list of units currently in focus.
enum unit_orders goto_last_order
void request_unit_ssa_set(const struct unit *punit, enum server_side_agent agent)
Call to request (from the server) that the unit is put under the control of the specified server side...
enum cursor_hover_state hover_state
void clear_hover_state()
Clear current hover state (go to HOVER_NONE).
action_id goto_last_action
struct unit * game_unit_by_number(int id)
Find unit out of all units in game: now uses fast idex method, instead of looking through all units o...
bool goto_pop_waypoint()
Returns whether there were any waypoint popped (we don't remove the initial position)
void send_patrol_route()
Send the current patrol route (i.e., the one generated via HOVER_STATE) to the server.
static enum tile_behavior no_fights_or_unknown_goto(const struct tile *ptile, enum known_type known, const struct pf_parameter *p)
PF callback to prohibit going into the unknown (conditionally).
static struct tile * goto_destination
Various stuff for the goto routes.
static int get_EC(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
PF callback to get the path with the minimal number of steps (out of all shortest paths).
static enum tile_behavior get_TB_caravan(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
PF callback for caravans.
void init_client_goto()
Called only by handle_map_info() in client/packhand.c.
static void send_path_orders(struct unit *punit, const PFPath &path, bool repeat, bool vigilant, enum unit_orders orders, struct unit_order *final_order)
Send a path as a goto or patrol route to the server.
bool send_attack_tile(struct unit *punit, struct tile *ptile)
Send orders for the unit to move it to the arbitrary tile and attack everything it approaches.
static void goto_fill_parameter_base(struct pf_parameter *parameter, const struct unit *punit)
Fill the PF parameter with the correct client-goto values.
bool goto_tile_state(const struct tile *ptile, enum goto_tile_state *state, int *turns, bool *waypoint)
Returns the state of 'ptile': turn number to print, and whether 'ptile' is a waypoint.
void send_goto_path(struct unit *punit, const PFPath &path, struct unit_order *final_order)
Send an arbitrary goto path for the unit to the server.
void enter_goto_state(const std::vector< unit * > &units)
Enter the goto state: activate, prepare PF-template and add the initial part.
void send_rally_path(struct city *pcity, struct unit *punit, const PFPath &path, struct unit_order *final_order)
Send an arbitrary rally path for the city to the server.
bool goto_is_active()
Is goto state active?
void send_goto_route()
Send the current goto route (i.e., the one generated via HOVER_STATE) to the server.
void goto_add_waypoint()
Inserts a waypoint at the end of the current goto line.
static void send_rally_path_orders(struct city *pcity, struct unit *punit, const PFPath &path, bool vigilant, enum unit_orders orders, struct unit_order *final_order)
Send a path as a goto or patrol rally orders to the server.
static void make_path_orders(struct unit *punit, const PFPath &path, enum unit_orders orders, struct unit_order *final_order, struct unit_order *order_list, int *length, int *dest_tile)
Creates orders for a path as a goto or patrol route.
bool is_valid_goto_draw_line(struct tile *dest_tile)
Puts a line to dest_tile on the map according to the current goto_map.
static enum tile_behavior get_TB_aggr(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
PF callback to prohibit going into the unknown.
struct tile * tile_before_end_path(struct unit *punit, struct tile *ptile)
Finds penultimate tile on path for given unit going to ptile.
bool send_goto_tile(struct unit *punit, struct tile *ptile)
Send orders for the unit to move it to the arbitrary tile.
bool send_rally_tile(struct city *pcity, struct tile *ptile)
Send rally orders for the city to move new units to the arbitrary tile.
bool can_unit_move_now(const struct unit *punit)
Returns if unit can move now.
void send_connect_route(enum unit_activity activity, struct extra_type *tgt)
Send the current connect route (i.e., the one generated via HOVER_STATE) to the server.
void goto_unit_killed(struct unit *punit)
Called from control_unit_killed() in client/control.c.
bool is_valid_goto_destination(const struct tile *ptile)
Determines if a goto to the destination tile is allowed.
void exit_goto_state()
Tidy up and deactivate goto state.
void request_orders_cleared(struct unit *punit)
Send a packet to the server to request that the current orders be cleared.
void free_client_goto()
Called above, and by control_done() in client/control.c.
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_msg(condition, message,...)
#define fc_assert_ret_val(condition, val)
enum direction8 opposite_direction(enum direction8 dir)
Return direction that is opposite to given one.
int get_direction_for_step(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile)
Return the direction which is needed for a step on the map from (start_x, start_y) to (end_x,...
const char * dir_get_name(enum direction8 dir)
Return the debugging name of the direction.
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Are (x1,y1) and (x2,y2) really the same when adjusted? This function might be necessary ALOT of place...
bool base_get_direction_for_step(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile, enum direction8 *dir)
Return TRUE and sets dir to the direction of the step if (end_x, end_y) can be reached from (start_x,...
void cancel_selection_rectangle()
Redraws the selection rectangle after a map flush.
void update_unit_info_label(const std::vector< unit * > &unit_list)
Update the information label which gives info on the current unit and the tile under the current unit...
client_options * gui_options
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
Factory function to create a new map according to the parameter.
PFPath pf_map_path(struct pf_map *pfm, struct tile *ptile)
CHECK DOCS AFTER FULL CONVERSTION OF pf_path to class PFPath Tries to find the best path in the given...
void pf_map_destroy(struct pf_map *pfm)
After usage the map must be destroyed.
struct universal production
struct packet_game_info info
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
int(* get_EC)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
const struct player * owner
bool(* is_pos_dangerous)(const struct tile *ptile, enum known_type, const struct pf_parameter *param)
int(* get_moves_left_req)(const struct tile *ptile, enum known_type, const struct pf_parameter *param)
int(* get_MC)(const struct tile *from_tile, enum pf_move_scope src_move_scope, const struct tile *to_tile, enum pf_move_scope dst_move_scope, const struct pf_parameter *param)
enum unit_activity activity
Q_LOGGING_CATEGORY(tileset_category, "freeciv.tileset")
Functions for handling the tilespec files which describe the files and contents of tilesets.
const struct unit_type * utype
struct unit * is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non-allied unit on this tile?
void unit_virtual_destroy(struct unit *punit)
Free the memory used by virtual unit.
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Create a virtual unit skeleton.
const char * unit_rule_name(const struct unit *punit)
Return the (untranslated) rule name of the unit.
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
bool utype_may_act_at_all(const struct unit_type *putype)
Return TRUE iff units of this type can do actions controlled by generalized (ruleset defined) action ...
bool utype_acts_hostile(const struct unit_type *putype)
Return TRUE iff units of this type can do hostile actions controlled by generalized (ruleset defined)...
void mapdeco_add_gotoline(const struct tile *ptile, enum direction8 dir, bool safe)
Add a goto line from the given tile 'ptile' in the direction 'dir'.
void mapdeco_clear_gotoroutes()
Clear all goto line map decorations and queues mapview updates for the affected tiles.