Freeciv21
Develop your civilization from humble roots to a global empire
goto.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 #include <cstring>
15 
16 // Qt
17 #include <QLoggingCategory>
18 
19 // common
20 #include "actions.h"
21 #include "fc_types.h"
22 #include "game.h"
23 #include "map.h"
24 #include "packets.h"
25 #include "path_finder.h"
26 #include "pf_tools.h"
27 #include "road.h"
28 #include "unit.h"
29 #include "unitlist.h"
30 
31 /* client/include */
32 #include "client_main.h"
33 #include "control.h"
34 #include "mapview_g.h"
35 
36 // client
37 #include "goto.h"
38 #include "mapctrl_common.h"
39 
40 // Logging category for goto
41 Q_LOGGING_CATEGORY(goto_category, "freeciv.goto")
42 
43 class PFPath;
44 
45 // Indexed by unit id
46 static auto goto_finders = std::map<int, freeciv::path_finder>();
47 
51 static struct tile *goto_destination = nullptr;
52 
56 bool can_unit_move_now(const struct unit *punit)
57 {
58  time_t dt;
59 
60  if (!punit) {
61  return false;
62  }
63 
64  if (punit->action_turn != game.info.turn - 1) {
65  return true;
66  }
67 
68  dt = time(nullptr) - punit->action_timestamp;
69  if (dt < 0) {
70  return false;
71  }
72 
73  return true;
74 }
75 
80 {
81  // Nothing
82 }
83 
88 {
89  goto_finders.clear();
90  goto_destination = nullptr;
91 }
92 
96 bool is_valid_goto_destination(const struct tile *ptile)
97 {
98  return (nullptr != goto_destination && ptile == goto_destination);
99 }
100 
105 {
106  for (auto &[_, finder] : goto_finders) {
107  // Patrol always uses a waypoint
108  if (hover_state == HOVER_PATROL) {
109  finder.pop_waypoint();
110  }
111 
112  finder.push_waypoint(goto_destination);
113 
114  // Patrol always uses a waypoint
115  if (hover_state == HOVER_PATROL) {
116  finder.push_waypoint(goto_destination);
117  }
118  }
120 }
121 
127 {
128  bool popped = false;
129  for (auto &[_, finder] : goto_finders) {
130  // Patrol always uses a waypoint
131  if (hover_state == HOVER_PATROL) {
132  finder.pop_waypoint();
133  }
134 
135  popped |= finder.pop_waypoint();
136 
137  // Patrol always uses a waypoint
138  if (hover_state == HOVER_PATROL) {
139  finder.push_waypoint(goto_destination);
140  }
141  }
142  return popped;
143 }
144 
149 static int get_EC(const struct tile *ptile, enum known_type known,
150  const struct pf_parameter *param)
151 {
152  return 1;
153 }
154 
159 static enum tile_behavior get_TB_aggr(const struct tile *ptile,
160  enum known_type known,
161  const struct pf_parameter *param)
162 {
163  if (known == TILE_UNKNOWN) {
165  return TB_IGNORE;
166  }
167  } else if (is_non_allied_unit_tile(ptile, param->owner)
168  || is_non_allied_city_tile(ptile, param->owner)) {
169  // Can attack but can't count on going through
170  return TB_DONT_LEAVE;
171  }
172  return TB_NORMAL;
173 }
174 
179 static enum tile_behavior get_TB_caravan(const struct tile *ptile,
180  enum known_type known,
181  const struct pf_parameter *param)
182 {
183  if (known == TILE_UNKNOWN) {
185  return TB_IGNORE;
186  }
187  } else if (is_non_allied_city_tile(ptile, param->owner)) {
188  /* Units that can establish a trade route, enter a market place or
189  * establish an embassy can travel to, but not through, enemy cities.
190  * FIXME: ACTION_HELP_WONDER units cannot. */
191  return TB_DONT_LEAVE;
192  } else if (is_non_allied_unit_tile(ptile, param->owner)) {
193  // Note this must be below the city check.
194  return TB_IGNORE;
195  }
196 
197  // Includes empty, allied, or allied-city tiles.
198  return TB_NORMAL;
199 }
200 
205 static enum tile_behavior
206 no_fights_or_unknown_goto(const struct tile *ptile, enum known_type known,
207  const struct pf_parameter *p)
208 {
209  if (known == TILE_UNKNOWN && gui_options->goto_into_unknown) {
210  // Special case allowing goto into the unknown.
211  return TB_NORMAL;
212  }
213 
214  return no_fights_or_unknown(ptile, known, p);
215 }
216 
221 static void goto_fill_parameter_base(struct pf_parameter *parameter,
222  const struct unit *punit)
223 {
224  pft_fill_unit_parameter(parameter, punit);
225 
226  fc_assert(parameter->get_EC == nullptr);
227  fc_assert(parameter->get_TB == nullptr);
228  fc_assert(parameter->get_MC != nullptr);
229  fc_assert(parameter->start_tile == unit_tile(punit));
230  fc_assert(parameter->omniscience == false);
231 
232  parameter->get_EC = get_EC;
233  if (utype_acts_hostile(unit_type_get(punit))) {
234  parameter->get_TB = get_TB_aggr;
235  } else if (utype_may_act_at_all(unit_type_get(punit))
236  && !utype_acts_hostile(unit_type_get(punit))) {
237  parameter->get_TB = get_TB_caravan;
238  } else {
239  parameter->get_TB = no_fights_or_unknown_goto;
240  }
241 }
242 
247 void enter_goto_state(const std::vector<unit *> &units)
248 {
250 
251  // Can't have selection rectangle and goto going on at the same time.
253 
254  // Initialize path finders
255  for (const auto punit : units) {
256  // This calls path_finder::path_finder(punit) behind the scenes
257  // Need to do this because path_finder isn't copy-assignable
258  auto [it, _] = goto_finders.emplace(punit->id, punit);
260  it->second.set_constraint(
261  std::make_unique<freeciv::tile_known_constraint>(client_player()));
262  }
263  }
264 }
265 
270 {
271  if (!goto_is_active()) {
272  return;
273  }
274 
276 
277  goto_finders.clear();
278  goto_destination = nullptr;
279 }
280 
284 void goto_unit_killed(struct unit *punit)
285 {
286  if (!goto_is_active()) {
287  return;
288  }
289 
290  // Drop the finder for the killed unit, if any.
291  goto_finders.erase(punit->id);
292 
293  // Notify our finders that something has changed.
294  for (auto &[_, finder] : goto_finders) {
295  finder.unit_changed(*punit);
296  }
297 }
298 
302 bool goto_is_active() { return !goto_finders.empty(); }
303 
308 bool goto_tile_state(const struct tile *ptile, enum goto_tile_state *state,
309  int *turns, bool *waypoint)
310 {
311  fc_assert_ret_val(ptile != nullptr, false);
312  fc_assert_ret_val(turns != nullptr, false);
313  fc_assert_ret_val(waypoint != nullptr, false);
314 
315  if (!goto_is_active() || goto_destination == nullptr) {
316  return false;
317  }
318 
319  *state = GTS_INVALID;
320  *turns = GTS_INVALID;
321  *waypoint = false;
322 
323  if (hover_state == HOVER_CONNECT) {
324  // FIXME unsupported
325  } else {
326  *waypoint = false;
327  *turns = -1;
328 
329  for (auto &[unit_id, finder] : goto_finders) {
330  // Initial tile
331  const auto unit = game_unit_by_number(unit_id);
332  int last_turns = 0;
333  if (unit->moves_left == 0) {
334  last_turns = 1;
335  if (ptile == unit->tile) {
336  *state = GTS_TURN_STEP;
337  *turns = 1;
338  }
339  }
340 
341  // Get a path
342  const auto destination =
344  const auto path =
345  finder.find_path(freeciv::tile_destination(destination));
346  if (path && !path->empty()) {
347  const auto steps = path->steps();
348  int last_waypoints = 0;
349  // Find tiles on the path where we end turns
350  for (const auto step : steps) {
351  if (ptile == step.location) {
352  *waypoint |= (step.waypoints > last_waypoints);
353  if (step.turns > last_turns) {
354  // Number of turns increased at this step
355  *state = GTS_TURN_STEP;
356  *turns = std::max(*turns, step.turns);
357  }
358  }
359  last_turns = step.turns;
360  last_waypoints = step.waypoints;
361  }
362  // Show end-of-path sprites (only when moving)
363  if (ptile == steps.back().location) {
364  if (*state == GTS_INVALID) { // Not set above => not a turn step
365  *state = GTS_MP_LEFT;
366  } else {
367  *state = GTS_EXHAUSTED_MP;
368  }
369  *turns = std::max(*turns, steps.back().turns);
370  }
371  }
372  }
373  }
374 
375  return (*turns != -1 || *waypoint);
376 }
377 
383 bool is_valid_goto_draw_line(struct tile *dest_tile)
384 {
386  if (nullptr == dest_tile) {
387  return false;
388  }
389 
390  mapdeco_clear_gotoroutes(); // We could be smarter here, but it's fast
391  // enough
392 
393  // assume valid destination
394  goto_destination = dest_tile;
395  for (auto &[unit_id, finder] : goto_finders) {
396  auto destination = dest_tile;
397 
398  // Patrol is implemented by automatically adding a waypoint under the
399  // cursor
400  if (hover_state == HOVER_PATROL) {
401  finder.pop_waypoint(); // Remove the last waypoint
402  finder.push_waypoint(dest_tile);
403  destination = game_unit_by_number(unit_id)->tile;
404  }
405 
406  const auto path =
407  finder.find_path(freeciv::tile_destination(destination));
408  if (!path) {
409  // This is our way of signalling that we can't go to a tile
410  goto_destination = nullptr;
411  continue;
412  }
413 
414  // Show the path on the map
415  auto unit = game_unit_by_number(unit_id);
416  tile *previous_tile = unit_tile(unit);
417  const auto first_unsafe =
418  path->first_unsafe_step(game_unit_by_number(unit_id));
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
424  && base_get_direction_for_step(&(wld.map), previous_tile,
425  step.location, &dir)) {
427  it < first_unsafe);
428  }
429  previous_tile = step.location;
430  }
431  }
432 
433  // Update goto data in info label.
435  return (nullptr != goto_destination);
436 }
437 
442 void request_orders_cleared(struct unit *punit)
443 {
444  struct packet_unit_orders p;
445 
446  if (!can_client_issue_orders()) {
447  return;
448  }
449 
450  // Clear the orders by sending an empty orders path.
451  qCDebug(goto_category, "Clearing orders for unit %d.", punit->id);
452  p.unit_id = punit->id;
453  p.src_tile = tile_index(unit_tile(punit));
454  p.repeat = false;
455  p.vigilant = false;
456  p.length = 0;
457  p.dest_tile = tile_index(unit_tile(punit));
458  request_unit_ssa_set(punit, SSA_NONE);
459  send_packet_unit_orders(&client.conn, &p);
460 }
461 
465 static void make_path_orders(struct unit *punit, const PFPath &path,
466  enum unit_orders orders,
467  struct unit_order *final_order,
468  struct unit_order *order_list, int *length,
469  int *dest_tile)
470 {
471  int i;
472  struct tile *old_tile;
473 
474  fc_assert_ret(!path.empty());
475  fc_assert_ret_msg(unit_tile(punit) == path[0].tile,
476  "Unit %d has moved without goto cancelation.",
477  punit->id);
478  fc_assert_ret(length != nullptr);
479 
480  // We skip the start position.
481  *length = path.length() - 1;
482  fc_assert(*length < MAX_LEN_ROUTE);
483  old_tile = path[0].tile;
484 
485  // If the path has n positions it takes n-1 steps.
486  for (i = 0; i < path.length() - 1; i++) {
487  struct tile *new_tile = path[i + 1].tile;
488 
489  if (same_pos(new_tile, old_tile)) {
490  order_list[i].order = ORDER_FULL_MP;
491  order_list[i].dir = DIR8_ORIGIN;
492  order_list[i].activity = ACTIVITY_LAST;
493  order_list[i].target = NO_TARGET;
494  order_list[i].sub_target = NO_TARGET;
495  order_list[i].action = ACTION_NONE;
496  qCDebug(goto_category, " packet[%d] = wait: %d,%d", i,
497  TILE_XY(old_tile));
498  } else {
499  order_list[i].order = orders;
500  order_list[i].dir = static_cast<direction8>(
501  get_direction_for_step(&(wld.map), old_tile, new_tile));
502  order_list[i].activity = ACTIVITY_LAST;
503  order_list[i].target = NO_TARGET;
504  order_list[i].sub_target = NO_TARGET;
505  order_list[i].action = ACTION_NONE;
506  qCDebug(goto_category, " packet[%d] = move %s: %d,%d => %d,%d", i,
507  dir_get_name(order_list[i].dir), TILE_XY(old_tile),
508  TILE_XY(new_tile));
509  }
510  old_tile = new_tile;
511  }
512 
513  if (i > 0 && order_list[i - 1].order == ORDER_MOVE
514  && (is_non_allied_city_tile(old_tile, client_player()) != nullptr
515  || is_non_allied_unit_tile(old_tile, client_player())
516  != nullptr)) {
517  // Won't be able to perform a regular move to the target tile...
518  if (!final_order) {
519  /* ...and no final order exists. Choose what to do when the unit gets
520  * there. */
521  order_list[i - 1].order = ORDER_ACTION_MOVE;
522  } else {
523  /* ...and a final order exist. Can't assume an action move. Did the
524  * caller hope that the situation would change before the unit got
525  * there? */
526 
527  /* It's currently illegal to walk into tiles with non allied units or
528  * cities. Some actions causes the actor to enter the target tile but
529  * that is a part of the action it self, not a regular pre action
530  * move. */
531  qCDebug(goto_category, "unit or city blocks the path of your %s",
532  unit_rule_name(punit));
533  }
534  }
535 
536  if (final_order) {
537  // Append the final order after moving to the target tile.
538  order_list[i].order = final_order->order;
539  order_list[i].dir = final_order->dir;
540  order_list[i].activity = (final_order->order == ORDER_ACTIVITY)
541  ? final_order->activity
542  : ACTIVITY_LAST;
543  order_list[i].target = final_order->target;
544  order_list[i].sub_target = final_order->sub_target;
545  order_list[i].action = final_order->action;
546  (*length)++;
547  }
548 
549  if (dest_tile) {
550  *dest_tile = tile_index(old_tile);
551  }
552 }
553 
557 static void send_path_orders(struct unit *punit, const PFPath &path,
558  bool repeat, bool vigilant,
559  enum unit_orders orders,
560  struct unit_order *final_order)
561 {
562  struct packet_unit_orders p;
563 
564  if (path.length() == 1 && final_order == nullptr) {
565  return; // No path at all, no need to spam the server.
566  }
567 
568  memset(&p, 0, sizeof(p));
569  p.unit_id = punit->id;
570  p.src_tile = tile_index(unit_tile(punit));
571  p.repeat = repeat;
572  p.vigilant = vigilant;
573 
574  qCDebug(goto_category, "Orders for unit %d:", punit->id);
575  qCDebug(goto_category, " Repeat: %d. Vigilant: %d.", p.repeat,
576  p.vigilant);
577 
578  make_path_orders(punit, path, orders, final_order, p.orders, &p.length,
579  &p.dest_tile);
580 
581  request_unit_ssa_set(punit, SSA_NONE);
582  send_packet_unit_orders(&client.conn, &p);
583 }
584 
588 static void send_rally_path_orders(struct city *pcity, struct unit *punit,
589  const PFPath &path, bool vigilant,
590  enum unit_orders orders,
591  struct unit_order *final_order)
592 {
593  struct packet_city_rally_point p;
594 
595  memset(&p, 0, sizeof(p));
596  p.city_id = pcity->id;
597  p.vigilant = vigilant;
598 
599  qCDebug(goto_category, "Rally orders for city %d:", pcity->id);
600  qCDebug(goto_category, " Vigilant: %d.", p.vigilant);
601 
602  make_path_orders(punit, path, orders, final_order, p.orders, &p.length,
603  nullptr);
604 
605  send_packet_city_rally_point(&client.conn, &p);
606 }
607 
611 void send_goto_path(struct unit *punit, const PFPath &path,
612  struct unit_order *final_order)
613 {
614  send_path_orders(punit, path, false, false, ORDER_MOVE, final_order);
615 }
616 
620 void send_rally_path(struct city *pcity, struct unit *punit,
621  const PFPath &path, struct unit_order *final_order)
622 {
623  send_rally_path_orders(pcity, punit, path, false, ORDER_MOVE, final_order);
624 }
625 
630 bool send_goto_tile(struct unit *punit, struct tile *ptile)
631 {
632  struct pf_parameter parameter;
633  struct pf_map *pfm;
634 
635  goto_fill_parameter_base(&parameter, punit);
636  pfm = pf_map_new(&parameter);
637  auto path = pf_map_path(pfm, ptile);
638  pf_map_destroy(pfm);
639 
640  if (!path.empty()) {
641  send_goto_path(punit, path, nullptr);
642  return true;
643  } else {
644  return false;
645  }
646 }
647 
652 bool send_rally_tile(struct city *pcity, struct tile *ptile)
653 {
654  const struct unit_type *putype;
655  struct unit *punit;
656 
657  struct pf_parameter parameter;
658  struct pf_map *pfm;
659 
660  fc_assert_ret_val(pcity != nullptr, false);
661  fc_assert_ret_val(ptile != nullptr, false);
662 
663  // Create a virtual unit of the type being produced by the city.
664  if (pcity->production.kind != VUT_UTYPE) {
665  // Can only give orders to units.
666  return false;
667  }
668  putype = pcity->production.value.utype;
669  punit =
670  unit_virtual_create(client_player(), pcity, putype,
671  city_production_unit_veteran_level(pcity, putype));
672 
673  // Use the unit to find a path to the destination tile.
674  goto_fill_parameter_base(&parameter, punit);
675  pfm = pf_map_new(&parameter);
676  auto path = pf_map_path(pfm, ptile);
677  pf_map_destroy(pfm);
678 
679  if (!path.empty()) {
680  // Send orders to server.
681  send_rally_path(pcity, punit, path, nullptr);
682  unit_virtual_destroy(punit);
683  return true;
684  } else {
685  unit_virtual_destroy(punit);
686  return false;
687  }
688 }
689 
694 bool send_attack_tile(struct unit *punit, struct tile *ptile)
695 {
696  struct pf_parameter parameter;
697  struct pf_map *pfm;
698 
699  goto_fill_parameter_base(&parameter, punit);
700  parameter.move_rate = 0;
701  parameter.is_pos_dangerous = nullptr;
702  parameter.get_moves_left_req = nullptr;
703  pfm = pf_map_new(&parameter);
704  auto path = pf_map_path(pfm, ptile);
705  pf_map_destroy(pfm);
706 
707  if (!path.empty()) {
708  send_path_orders(punit, path, false, false, ORDER_ACTION_MOVE, nullptr);
709  return true;
710  }
711  return false;
712 }
713 
719 
724 void send_connect_route(enum unit_activity activity, struct extra_type *tgt)
725 {
727  // FIXME unsupported
728 }
729 
730 namespace /* anonymous */ {
731 
735 bool order_requires_adjacent(unit_orders order, action_id action)
736 {
737  switch (order) {
738  case ORDER_MOVE:
739  case ORDER_ACTION_MOVE:
740  // A move is always done in a direction.
741  return true;
743  // Always illegal to do to a target on the actor's own tile.
745  return true;
746  }
747 
748  return false;
749  default:
750  return false;
751  }
752 }
753 
758 bool order_allows_adjacent(unit_orders order, action_id action)
759 {
760  // Only ORDER_PERFORM_ACTION has complicated rules
761  if (order != ORDER_PERFORM_ACTION) {
762  return order_requires_adjacent(order, action);
763  }
764 
765  // Can never be done from adjacent
767  return false;
768  }
769 
770  return true;
771 }
772 
776 bool edit_last_order(packet_unit_orders &packet, const tile *tgt_tile)
777 {
778  // The main complication here is that some actions must be performed from
779  // the target tile and some actions must be performed from an adjacent tile
780  // (or more). We always prefer performing the action from an adjacent tile,
781  // and edit the path accordingly.
782 
783  // Is the last step in the path a move? Otherwise we can't assume it is
784  // from an adjacent tile, so we won't generate
785  const bool have_move =
786  (packet.length > 0
787  && (packet.orders[packet.length - 1].order == ORDER_MOVE
788  || packet.orders[packet.length - 1].order == ORDER_ACTION_MOVE));
789 
790  // Do we want to start from an adjacent tile?
791  bool adjacent =
792  (have_move
793  && order_allows_adjacent(goto_last_order, goto_last_action));
794 
795  // But, do we *need* to start from an adjacent tile?
796  if (order_requires_adjacent(goto_last_order, goto_last_action)) {
797  if (have_move) {
798  // Must be performed from an adjacent tile
799  adjacent = true;
800  } else {
801  // FIXME We could generate a longer path instead
802  return false;
803  }
804  }
805 
806  if (!adjacent) {
807  // If the last order was ORDER_ACTION_MOVE, convert it to ORDER_MOVE
808  // Would happen e.g. for a caravan moving to an allied city
809  if (packet.orders[packet.length - 1].order == ORDER_ACTION_MOVE) {
810  packet.orders[packet.length - 1].order = ORDER_MOVE;
811  }
812 
813  // Append an order after we reach the destination
814  packet.length++;
815  }
816 
817  // Edit the last order (the ORDER_[ACTION_]MOVE if adjacent, the one we
818  // inserted if not)
819  packet.orders[packet.length - 1] = unit_order{
821  ACTIVITY_LAST,
822  (goto_last_tgt == NO_TARGET ? tgt_tile->index : goto_last_tgt),
825  DIR8_ORIGIN};
826 
827  return true;
828 }
829 } // anonymous namespace
830 
837 {
839  fc_assert_ret(goto_destination != nullptr);
840 
841  for (auto &[unit_id, finder] : goto_finders) {
842  auto destination = hover_state == HOVER_PATROL
843  ? game_unit_by_number(unit_id)->tile
845  const auto path =
846  finder.find_path(freeciv::tile_destination(destination));
847  // No path to destination. Still try the other units...
848  if (!path) {
849  continue;
850  }
851 
852  const auto unit = game_unit_by_number(unit_id);
853  fc_assert_ret(unit != nullptr);
854 
855  auto packet = packet_unit_orders{};
856  packet.unit_id = unit_id;
857  packet.dest_tile = goto_destination->index;
858  packet.src_tile = unit->tile->index;
859  packet.repeat = hover_state == HOVER_PATROL;
860  packet.vigilant = hover_state == HOVER_PATROL;
861 
862  const auto steps = path->steps();
863  fc_assert_ret(steps.size() < MAX_LEN_ROUTE);
864 
865  packet.length = steps.size();
866  for (std::size_t i = 0; i < steps.size(); ++i) {
867  packet.orders[i] = steps[i].order;
868  }
869 
870  if (goto_last_order != ORDER_LAST) {
871  if (!edit_last_order(packet, destination)) {
872  continue;
873  }
874  }
875 
876  // Send
877  request_unit_ssa_set(unit, SSA_NONE);
878  send_packet_unit_orders(&client.conn, &packet);
879  }
880 
882  exit_goto_state();
883 }
884 
888 struct tile *tile_before_end_path(struct unit *punit, struct tile *ptile)
889 {
890  struct pf_parameter parameter;
891  struct pf_map *pfm;
892  struct tile *dtile;
893 
894  goto_fill_parameter_base(&parameter, punit);
895  parameter.move_rate = 0;
896  parameter.is_pos_dangerous = nullptr;
897  parameter.get_moves_left_req = nullptr;
898  pfm = pf_map_new(&parameter);
899  auto path = pf_map_path(pfm, ptile);
900  if (path.empty()) {
901  return nullptr;
902  }
903  if (path.length() < 2) {
904  dtile = nullptr;
905  } else {
906  dtile = path[-2].tile;
907  }
908  pf_map_destroy(pfm);
909 
910  return dtile;
911 }
#define action_id_distance_accepted(act_id, distance)
Definition: actions.h:565
#define ACTION_NONE
Definition: actions.h:220
struct city * is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non_allied city on this tile?
Definition: city.cpp:1968
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?
Definition: city.cpp:768
bool empty() const
int length() const
A path finding destination that accepts any path leading to a specific tile.
Definition: path_finder.h:173
struct player * client_player()
Either controlling or observing.
struct civclient client
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.
Definition: control.cpp:169
enum unit_orders goto_last_order
Definition: control.cpp:89
int goto_last_tgt
Definition: control.cpp:87
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...
Definition: control.cpp:1906
enum cursor_hover_state hover_state
Definition: control.cpp:82
int goto_last_sub_tgt
Definition: control.cpp:88
void clear_hover_state()
Clear current hover state (go to HOVER_NONE).
Definition: control.cpp:308
action_id goto_last_action
Definition: control.cpp:86
@ HOVER_CONNECT
Definition: control.h:22
@ HOVER_PATROL
Definition: control.h:23
#define NO_TARGET
Definition: fc_types.h:271
#define DIR8_ORIGIN
Definition: fc_types.h:372
int action_id
Definition: fc_types.h:306
#define _(String)
Definition: fcintl.h:50
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...
Definition: game.cpp:112
struct civ_game game
Definition: game.cpp:47
struct world wld
Definition: game.cpp:48
bool goto_pop_waypoint()
Returns whether there were any waypoint popped (we don't remove the initial position)
Definition: goto.cpp:126
void send_patrol_route()
Send the current patrol route (i.e., the one generated via HOVER_STATE) to the server.
Definition: goto.cpp:718
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).
Definition: goto.cpp:206
static struct tile * goto_destination
Various stuff for the goto routes.
Definition: goto.cpp:51
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).
Definition: goto.cpp:149
static enum tile_behavior get_TB_caravan(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
PF callback for caravans.
Definition: goto.cpp:179
void init_client_goto()
Called only by handle_map_info() in client/packhand.c.
Definition: goto.cpp:79
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.
Definition: goto.cpp:557
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.
Definition: goto.cpp:694
static void goto_fill_parameter_base(struct pf_parameter *parameter, const struct unit *punit)
Fill the PF parameter with the correct client-goto values.
Definition: goto.cpp:221
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.
Definition: goto.cpp:308
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.
Definition: goto.cpp:611
void enter_goto_state(const std::vector< unit * > &units)
Enter the goto state: activate, prepare PF-template and add the initial part.
Definition: goto.cpp:247
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.
Definition: goto.cpp:620
bool goto_is_active()
Is goto state active?
Definition: goto.cpp:302
void send_goto_route()
Send the current goto route (i.e., the one generated via HOVER_STATE) to the server.
Definition: goto.cpp:836
void goto_add_waypoint()
Inserts a waypoint at the end of the current goto line.
Definition: goto.cpp:104
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.
Definition: goto.cpp:588
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.
Definition: goto.cpp:465
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.
Definition: goto.cpp:383
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.
Definition: goto.cpp:159
struct tile * tile_before_end_path(struct unit *punit, struct tile *ptile)
Finds penultimate tile on path for given unit going to ptile.
Definition: goto.cpp:888
bool send_goto_tile(struct unit *punit, struct tile *ptile)
Send orders for the unit to move it to the arbitrary tile.
Definition: goto.cpp:630
bool send_rally_tile(struct city *pcity, struct tile *ptile)
Send rally orders for the city to move new units to the arbitrary tile.
Definition: goto.cpp:652
bool can_unit_move_now(const struct unit *punit)
Returns if unit can move now.
Definition: goto.cpp:56
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.
Definition: goto.cpp:724
void goto_unit_killed(struct unit *punit)
Called from control_unit_killed() in client/control.c.
Definition: goto.cpp:284
static auto goto_finders
Definition: goto.cpp:46
bool is_valid_goto_destination(const struct tile *ptile)
Determines if a goto to the destination tile is allowed.
Definition: goto.cpp:96
void exit_goto_state()
Tidy up and deactivate goto state.
Definition: goto.cpp:269
void request_orders_cleared(struct unit *punit)
Send a packet to the server to request that the current orders be cleared.
Definition: goto.cpp:442
void free_client_goto()
Called above, and by control_done() in client/control.c.
Definition: goto.cpp:87
goto_tile_state
Definition: goto.h:21
@ GTS_INVALID
Definition: goto.h:27
@ GTS_EXHAUSTED_MP
Definition: goto.h:24
@ GTS_MP_LEFT
Definition: goto.h:23
@ GTS_TURN_STEP
Definition: goto.h:22
#define fc_assert_ret(condition)
Definition: log.h:112
#define fc_assert(condition)
Definition: log.h:89
#define fc_assert_ret_msg(condition, message,...)
Definition: log.h:129
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
enum direction8 opposite_direction(enum direction8 dir)
Return direction that is opposite to given one.
Definition: map.cpp:1589
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,...
Definition: map.cpp:1288
const char * dir_get_name(enum direction8 dir)
Return the debugging name of the direction.
Definition: map.cpp:1084
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...
Definition: map.cpp:887
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,...
Definition: map.cpp:1267
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...
Definition: view_map.cpp:446
Definition: path.cpp:10
client_options * gui_options
Definition: options.cpp:74
#define MAX_LEN_ROUTE
Definition: packets.h:38
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.
tile_behavior
Definition: path_finding.h:276
@ TB_NORMAL
Definition: path_finding.h:277
@ TB_DONT_LEAVE
Definition: path_finding.h:279
@ TB_IGNORE
Definition: path_finding.h:278
void pft_fill_unit_parameter(struct pf_parameter *parameter, const struct unit *punit)
Fill classic parameters for an unit.
Definition: pf_tools.cpp:822
enum tile_behavior no_fights_or_unknown(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
PF callback to prohibit going into the unknown.
Definition: pf_tools.cpp:469
int step
Definition: specpq.h:83
Definition: city.h:291
int id
Definition: city.h:296
struct universal production
Definition: city.h:368
struct packet_game_info info
Definition: game.h:80
struct connection conn
Definition: client_main.h:89
bool goto_into_unknown
Definition: options.h:90
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition: path_finding.h:380
int(* get_EC)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition: path_finding.h:387
const struct player * owner
Definition: path_finding.h:356
bool(* is_pos_dangerous)(const struct tile *ptile, enum known_type, const struct pf_parameter *param)
Definition: path_finding.h:418
int(* get_moves_left_req)(const struct tile *ptile, enum known_type, const struct pf_parameter *param)
Definition: path_finding.h:423
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)
Definition: path_finding.h:364
struct tile * start_tile
Definition: path_finding.h:341
Definition: tile.h:42
int index
Definition: tile.h:43
enum unit_activity activity
Definition: unit.h:81
enum unit_orders order
Definition: unit.h:80
int action
Definition: unit.h:87
enum direction8 dir
Definition: unit.h:89
int target
Definition: unit.h:84
int sub_target
Definition: unit.h:85
Definition: unit.h:134
int moves_left
Definition: unit.h:147
int id
Definition: unit.h:141
struct tile * tile
Definition: unit.h:136
enum universals_n kind
Definition: fc_types.h:740
universals_u value
Definition: fc_types.h:739
struct civ_map map
Definition: world_object.h:21
#define tile_index(_pt_)
Definition: tile.h:70
known_type
Definition: tile.h:28
@ TILE_UNKNOWN
Definition: tile.h:29
#define TILE_XY(ptile)
Definition: tile.h:36
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
Definition: fc_types.h:585
struct unit * is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non-allied unit on this tile?
Definition: unit.cpp:1252
void unit_virtual_destroy(struct unit *punit)
Free the memory used by virtual unit.
Definition: unit.cpp:1588
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Create a virtual unit skeleton.
Definition: unit.cpp:1490
#define unit_tile(_pu)
Definition: unit.h:371
unit_orders
Definition: unit.h:31
@ ORDER_ACTION_MOVE
Definition: unit.h:39
@ ORDER_ACTIVITY
Definition: unit.h:35
@ ORDER_FULL_MP
Definition: unit.h:37
@ ORDER_MOVE
Definition: unit.h:33
@ ORDER_LAST
Definition: unit.h:43
@ ORDER_PERFORM_ACTION
Definition: unit.h:41
const char * unit_rule_name(const struct unit *punit)
Return the (untranslated) rule name of the unit.
Definition: unittype.cpp:1283
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
Definition: unittype.cpp:114
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 ...
Definition: unittype.cpp:374
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)...
Definition: unittype.cpp:432
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.