Freeciv21
Develop your civilization from humble roots to a global empire
texaicity.c
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 <fc_config.h>
15 
16 /* utility */
17 #include "log.h"
18 
19 /* common */
20 #include "city.h"
21 #include "game.h"
22 #include "map.h"
23 #include "movement.h"
24 #include "tile.h"
25 #include "unit.h"
26 #include "workertask.h"
27 
28 /* server */
29 #include "citytools.h"
30 
31 /* server/advisors */
32 #include "advbuilding.h"
33 #include "advdata.h"
34 #include "autosettlers.h"
35 #include "infracache.h"
36 
37 /* ai/default */
38 #include "aidata.h"
39 
40 /* ai/tex */
41 #include "texaimsg.h"
42 #include "texaiplayer.h"
43 
44 #include "texaicity.h"
45 
46 /* Task Want Multiplier */
47 #define TWMP 100
48 
50  int city_id;
51  struct worker_task task;
52 };
53 
57 };
58 
59 static bool
60 texai_city_worker_task_select(struct ai_type *ait, struct player *pplayer,
61  struct city *pcity, struct worker_task *task,
62  enum texai_worker_task_limitation limit);
63 
64 /**********************************************************************/
69  struct player *pplayer,
70  struct city *pcity)
71 {
72  struct worker_task task;
73 
74  if (texai_city_worker_task_select(ait, pplayer, pcity, &task,
76  struct texai_worker_task_req *data = fc_malloc(sizeof(*data));
77 
78  data->city_id = pcity->id;
79  data->task.ptile = task.ptile;
80  data->task.act = task.act;
81  data->task.tgt = task.tgt;
82  data->task.want = task.want;
83 
84  texai_send_req(TEXAI_REQ_WORKER_TASK, pplayer, data);
85  }
86 }
87 
88 /**********************************************************************/
91 void texai_city_worker_wants(struct ai_type *ait, struct player *pplayer,
92  struct city *pcity)
93 {
94  struct worker_task task;
95  struct texai_city *cdata = texai_city_data(ait, pcity);
96  int *wants = cdata->unit_wants;
97  int maxwant = 0;
98  struct unit_type *type = NULL;
99  Continent_id place = tile_continent(city_tile(pcity));
100  struct ai_plr *dai = dai_plr_data_get(ait, pplayer, NULL);
101  struct adv_data *adv = adv_data_get(pplayer, NULL);
102 
103  unit_type_iterate(ptype) { wants[utype_index(ptype)] = 0; }
105 
106  texai_city_worker_task_select(ait, pplayer, pcity, &task,
108 
109  unit_type_iterate(ptype)
110  {
111  int twant = wants[utype_index(ptype)];
112 
113  twant -= 20 * ptype->pop_cost;
114  twant -= ptype->build_cost;
115  twant -= ptype->upkeep[O_FOOD] * FOOD_WEIGHTING / 2;
116 
117  /* Massage our desire based on available statistics to prevent
118  * overflooding with worker type units if they come cheap in
119  * the ruleset */
120  if (place >= 0) {
121  twant /=
122  MAX(1, dai->stats.workers[place] / (adv->stats.cities[place] + 1));
123  twant -= dai->stats.workers[place];
124  } else {
125  /* TODO: Handle Oceans with cities sensibly */
126  }
127 
128  twant = MAX(twant, 0);
129 
130  if (twant > maxwant) {
131  maxwant = twant;
132  type = ptype;
133  }
134  }
136 
137  cdata->defai.worker_want = maxwant / 70;
138  cdata->defai.worker_type = type;
139 }
140 
142  int uw_max_base; /* Value for the city working the tile */
143  int uw_max; /* With road connectivity bonus */
147  int *wants;
148 };
149 
150 /**********************************************************************/
154  struct player *pplayer, struct city *pcity, struct tile *ptile,
155  int cindex, struct unit_list *units, struct worker_task *worked,
156  struct worker_task *unworked, struct texai_tile_state *state,
157  enum texai_worker_task_limitation limit)
158 {
159  int orig_value;
160  bool potential_worst_worked = false;
161 
162  if (!city_can_work_tile(pcity, ptile)) {
163  return;
164  }
165 
166  orig_value = city_tile_value(pcity, ptile, 0, 0);
167 
168  if (tile_worked(ptile) == pcity && orig_value < state->worst_worked) {
169  state->worst_worked = orig_value;
170  state->orig_worst_worked = orig_value;
171  potential_worst_worked = true;
172  }
173 
175  {
176  bool consider = true;
177  bool possible = false;
178  enum extra_cause cause;
179  enum extra_rmcause rmcause;
180  struct extra_type *tgt = NULL;
181 
182  /* Do not request activities that already are under way. */
183  unit_list_iterate(ptile->units, punit)
184  {
185  if (unit_owner(punit) == pplayer
186  && unit_has_type_flag(punit, UTYF_SETTLERS)
187  && punit->activity == action_id_get_activity(act)) {
188  consider = false;
189  break;
190  }
191  }
193 
194  if (!consider) {
195  continue;
196  }
197 
200 
201  unit_list_iterate(units, punit)
202  {
203  if (cause != EC_NONE) {
204  tgt = next_extra_for_tile(ptile, cause, pplayer, punit);
205  } else if (rmcause != ERM_NONE) {
206  tgt = prev_extra_in_tile(ptile, rmcause, pplayer, punit);
207  }
208 
210  act, punit, unit_home(punit), ptile, true, ptile, tgt))) {
211  possible = true;
212  break;
213  }
214  }
216 
217  if (possible) {
218  int value = adv_city_worker_act_get(pcity, cindex,
220 
221  if (tile_worked(ptile) == pcity) {
222  if ((value - orig_value) * TWMP > worked->want) {
223  worked->want = TWMP * (value - orig_value);
224  worked->ptile = ptile;
225  worked->act = action_id_get_activity(act);
226  worked->tgt = NULL;
227  if (limit == TWTL_BUILDABLE_UNITS) {
228  unit_list_iterate(units, punit)
229  {
231  act, punit, unit_home(punit), ptile, true, ptile,
232  tgt))) {
233  state->wants[utype_index(unit_type_get(punit))] +=
234  worked->want;
235  }
236  }
238  }
239  }
240  if (value > state->old_worst_worked) {
241  /* After improvement it would not be the worst */
242  potential_worst_worked = false;
243  } else {
244  state->worst_worked = value;
245  }
246  } else {
247  if (value > orig_value && value > state->uw_max) {
248  state->uw_max = value;
249  state->uw_max_base = value;
250  unworked->want = TWMP * (value - orig_value);
251  unworked->ptile = ptile;
252  unworked->act = action_id_get_activity(act);
253  unworked->tgt = NULL;
254  if (limit == TWTL_BUILDABLE_UNITS) {
255  unit_list_iterate(units, punit)
256  {
258  act, punit, unit_home(punit), ptile, true, ptile,
259  tgt))) {
260  state->wants[utype_index(unit_type_get(punit))] +=
261  unworked->want;
262  }
263  }
265  }
266  }
267  }
268  }
269  }
271 
272  extra_type_iterate(tgt)
273  {
274  struct action *paction = NULL;
275  bool removing = tile_has_extra(ptile, tgt);
276 
277  unit_list_iterate(units, punit)
278  {
279  if (removing) {
281  {
282  struct action *taction = action_by_number(try_act);
283  if (is_extra_removed_by_action(tgt, taction)
285  try_act, punit, unit_home(punit), ptile, true, ptile,
286  tgt))) {
287  paction = taction;
288  break;
289  }
290  }
292  } else {
293  as_extra_action_iterate(try_act)
294  {
295  struct action *taction = action_by_number(try_act);
296  if (is_extra_caused_by_action(tgt, taction)
298  try_act, punit, unit_home(punit), ptile, true, ptile,
299  tgt))) {
300  paction = taction;
301  break;
302  }
303  }
305  }
306  }
308 
309  if (paction != NULL) {
310  adv_want base_value;
311  int value;
312  adv_want extra;
313  bool consider = true;
314  struct road_type *proad;
315 
316  /* Do not request activities that already are under way. */
317  unit_list_iterate(ptile->units, punit)
318  {
319  if (unit_owner(punit) == pplayer
320  && unit_has_type_flag(punit, UTYF_SETTLERS)
321  && punit->activity == action_get_activity(paction)) {
322  consider = false;
323  break;
324  }
325  }
327 
328  if (!consider) {
329  continue;
330  }
331 
332  proad = extra_road_get(tgt);
333 
334  if (removing) {
335  base_value = adv_city_worker_rmextra_get(pcity, cindex, tgt);
336  } else {
337  base_value = adv_city_worker_extra_get(pcity, cindex, tgt);
338  }
339 
340  if (proad != NULL && road_provides_move_bonus(proad)) {
341  int old_move_cost;
342  int mc_multiplier = 1;
343  int mc_divisor = 1;
344 
345  /* Here 'old' means actually 'without the evaluated': In case of
346  * removal activity it's the value after the removal. */
347  old_move_cost = tile_terrain(ptile)->movement_cost * SINGLE_MOVE;
348 
349  extra_type_by_cause_iterate(EC_ROAD, poe)
350  {
351  struct road_type *pold = extra_road_get(poe);
352 
353  if (tile_has_extra(ptile, poe) && poe != tgt) {
354  if (road_provides_move_bonus(pold)
355  && pold->move_cost < old_move_cost) {
356  old_move_cost = pold->move_cost;
357  }
358  }
359  }
361 
362  if (proad->move_cost < old_move_cost) {
363  if (proad->move_cost >= terrain_control.move_fragments) {
364  mc_divisor = proad->move_cost / terrain_control.move_fragments;
365  } else {
366  if (proad->move_cost == 0) {
367  mc_multiplier = 2;
368  } else {
369  mc_multiplier = 1 - proad->move_cost;
370  }
371  mc_multiplier += old_move_cost;
372  }
373  }
374 
375  extra = adv_settlers_road_bonus(ptile, proad) * mc_multiplier
376  / mc_divisor;
377 
378  if (removing) {
379  extra = -extra;
380  }
381  } else {
382  extra = 0;
383  }
384 
385  value = base_value + extra;
386 
387  if (tile_worked(ptile) == pcity) {
388  if ((value - orig_value) * TWMP > worked->want) {
389  worked->want = TWMP * (value - orig_value);
390  worked->ptile = ptile;
391  worked->act = action_get_activity(paction);
392  worked->tgt = tgt;
393  if (limit == TWTL_BUILDABLE_UNITS) {
394  unit_list_iterate(units, punit)
395  {
396  fc_assert_action(action_get_target_kind(paction) == ATK_TILE,
397  break);
399  paction->id, punit, unit_home(punit), ptile, true,
400  ptile, tgt))) {
401  state->wants[utype_index(unit_type_get(punit))] +=
402  worked->want;
403  }
404  }
406  }
407  }
408  if (value > state->old_worst_worked) {
409  /* After improvement it would not be the worst */
410  potential_worst_worked = false;
411  } else {
412  state->worst_worked = value;
413  }
414  } else {
415  if (value > orig_value && value > state->uw_max) {
416  state->uw_max = value;
417  state->uw_max_base = base_value;
418  unworked->want = TWMP * (value - orig_value);
419  unworked->ptile = ptile;
420  unworked->act = action_get_activity(paction);
421  unworked->tgt = tgt;
422  if (limit == TWTL_BUILDABLE_UNITS) {
423  unit_list_iterate(units, punit)
424  {
425  fc_assert_action(action_get_target_kind(paction) == ATK_TILE,
426  break);
428  paction->id, punit, unit_home(punit), ptile, true,
429  ptile, tgt))) {
430  state->wants[utype_index(unit_type_get(punit))] +=
431  unworked->want;
432  }
433  }
435  }
436  }
437  }
438  }
439  }
441 
442  if (potential_worst_worked) {
443  /* Would still be worst worked even if we improved *it*. */
444  state->old_worst_worked = state->worst_worked;
445  }
446 }
447 
448 /**********************************************************************/
451 static bool
452 texai_city_worker_task_select(struct ai_type *ait, struct player *pplayer,
453  struct city *pcity, struct worker_task *task,
454  enum texai_worker_task_limitation limit)
455 {
456  struct worker_task *selected;
457  struct worker_task worked = {
458  .ptile = NULL, .want = 0, .act = ACTIVITY_IDLE, .tgt = NULL};
459  struct worker_task unworked = {
460  .ptile = NULL, .want = 0, .act = ACTIVITY_IDLE, .tgt = NULL};
461  struct texai_tile_state state = {.uw_max = 0,
462  .uw_max_base = 0,
463  .worst_worked = FC_INFINITY,
464  .orig_worst_worked = 0,
465  .old_worst_worked = FC_INFINITY};
466  struct unit_list *units = NULL;
467 
468  switch (limit) {
469  case TWTL_CURRENT_UNITS:
470  units = texai_player_units(pplayer);
471  state.wants = NULL;
472  break;
474  units = unit_list_new();
475  unit_type_iterate(ptype)
476  {
477  if (can_city_build_unit_now(pcity, ptype)) {
478  unit_list_append(units,
479  unit_virtual_create(pplayer, pcity, ptype, 0));
480  }
481  }
483  state.wants = texai_city_data(ait, pcity)->unit_wants;
484  break;
485  }
486 
488  ptile, cindex)
489  {
490  texai_tile_worker_task_select(pplayer, pcity, ptile, cindex, units,
491  &worked, &unworked, &state, limit);
492  }
494 
495  if (worked.ptile == NULL
496  || (state.old_worst_worked < state.uw_max
497  && (state.uw_max - state.orig_worst_worked) * TWMP > worked.want)
498  || (state.uw_max - state.uw_max_base * TWMP > worked.want)) {
499  /* It's better to improve best yet unworked tile and take it to use after
500  that, than to improve already worked tile. OR it's more important to
501  improve road connectivity outside worked tiles than improve worked
502  tiles */
503  selected = &unworked;
504  } else {
505  selected = &worked;
506  }
507 
508  if (limit == TWTL_BUILDABLE_UNITS) {
509  unit_list_iterate(units, punit) { unit_virtual_destroy(punit); }
511  unit_list_destroy(units);
512  }
513 
514  if (selected->ptile != NULL) {
515  struct extra_type *target = NULL;
516 
517  if (selected->tgt == NULL) {
518  enum extra_cause cause = activity_to_extra_cause(selected->act);
519 
520  if (cause != EC_NONE) {
521  target = next_extra_for_tile(selected->ptile, cause, pplayer, NULL);
522  } else {
523  enum extra_rmcause rmcause =
524  activity_to_extra_rmcause(selected->act);
525 
526  if (rmcause != ERM_NONE) {
527  target =
528  prev_extra_in_tile(selected->ptile, rmcause, pplayer, NULL);
529  }
530  }
531  } else {
532  target = selected->tgt;
533  }
534 
535  task->ptile = selected->ptile;
536  task->act = selected->act;
537  task->tgt = target;
538  task->want = selected->want;
539 
540  return true;
541  }
542 
543  return false;
544 }
545 
546 /**********************************************************************/
550 {
551  struct texai_worker_task_req *data =
552  (struct texai_worker_task_req *) req->data;
553  struct city *pcity;
554 
555  pcity = game_city_by_number(data->city_id);
556 
557  if (pcity != NULL && city_owner(pcity) == req->plr) {
558  /* City has not been lost meanwhile */
559  struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
560 
561  if (ptask == NULL) {
562  ptask = new worker_task{};
563  worker_task_init(ptask);
564  worker_task_list_append(pcity->task_reqs, ptask);
565  }
566 
567  log_debug("%s storing req for act %d at (%d,%d)", pcity->name,
568  data->task.act, TILE_XY(data->task.ptile));
569  ptask->ptile = data->task.ptile;
570  ptask->act = data->task.act;
571  ptask->tgt = data->task.tgt;
572  ptask->want = data->task.want;
573 
574  /* Send info to observers */
576  }
577 
578  delete[] data;
579 }
580 
581 /**********************************************************************/
584 void texai_city_alloc(struct ai_type *ait, struct city *pcity)
585 {
586  struct texai_city *city_data = new struct texai_city {
587  };
588 
590  adv_init_choice(&(city_data->defai.choice));
591 
592  city_set_ai_data(pcity, ait, city_data);
593 }
594 
595 /**********************************************************************/
598 void texai_city_free(struct ai_type *ait, struct city *pcity)
599 {
600  struct texai_city *city_data = texai_city_data(ait, pcity);
601 
602  if (city_data != NULL) {
603  adv_deinit_choice(&(city_data->defai.choice));
604  city_set_ai_data(pcity, ait, nullptr);
605  delete city_data;
606  city_data = nullptr;
607  }
608 }
bool action_prob_possible(const struct act_prob probability)
Returns TRUE iff the given action probability belongs to an action that may be possible.
Definition: actions.cpp:5380
struct action * action_by_number(action_id act_id)
Return the action with the given id.
Definition: actions.cpp:1149
enum unit_activity action_get_activity(const struct action *paction)
Returns the unit activity this action may cause or ACTIVITY_LAST if the action doesn't result in a un...
Definition: actions.cpp:1557
enum action_target_kind action_get_target_kind(const struct action *paction)
Get the target kind of an action.
Definition: actions.cpp:1198
struct act_prob action_speculate_unit_on_tile(action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct tile *target_tile, const struct extra_type *target_extra)
Returns a speculation about the actor unit's probability of successfully performing the chosen action...
Definition: actions.cpp:5273
#define action_id_get_activity(act_id)
Definition: actions.h:583
#define FOOD_WEIGHTING
Definition: advbuilding.h:16
void adv_deinit_choice(struct adv_choice *choice)
Clear choice without freeing it itself.
Definition: advchoice.cpp:42
void adv_init_choice(struct adv_choice *choice)
Sets the values of the choice to initial values.
Definition: advchoice.cpp:27
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Return a pointer to our data.
Definition: advdata.cpp:591
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Get current default ai data related to player.
Definition: aidata.cpp:304
adv_want adv_settlers_road_bonus(struct tile *ptile, struct road_type *proad)
Calculate the attractiveness of building a road/rail at the given tile.
#define as_transform_action_iterate_end
Definition: autosettlers.h:69
#define as_rmextra_action_iterate(_act_)
Definition: autosettlers.h:85
#define as_rmextra_action_iterate_end
Definition: autosettlers.h:89
#define as_extra_action_iterate_end
Definition: autosettlers.h:79
#define as_extra_action_iterate(_act_)
Definition: autosettlers.h:75
#define as_transform_action_iterate(_act_)
Definition: autosettlers.h:65
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Attach ai data to city.
Definition: city.cpp:3517
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
Definition: city.cpp:1095
int city_map_radius_sq_get(const struct city *pcity)
Returns the current squared radius of the city.
Definition: city.cpp:130
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Returns TRUE when a tile is available to be worked, or the city itself is currently working the tile ...
Definition: city.cpp:1392
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Return whether given city can build given unit; returns FALSE if unit is obsolete.
Definition: city.cpp:894
#define city_tile_iterate_end
Definition: city.h:209
#define city_tile_iterate_index(_radius_sq, _city_tile, _tile, _index)
Definition: city.h:169
void package_and_send_worker_tasks(struct city *pcity)
Send city worker task to owner.
Definition: citytools.cpp:3433
#define BUILDING_WAIT_MINIMUM
Definition: daicity.h:36
enum extra_cause activity_to_extra_cause(enum unit_activity act)
What extra cause activity is considered to be?
Definition: extras.cpp:973
struct extra_type * prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit)
Returns prev extra by cause that unit or player can remove from tile.
Definition: extras.cpp:732
bool is_extra_caused_by_action(const struct extra_type *pextra, const struct action *paction)
Is the extra caused by specific worker action?
Definition: extras.cpp:953
bool is_extra_removed_by_action(const struct extra_type *pextra, const struct action *paction)
Is the extra removed by specific worker action?
Definition: extras.cpp:963
enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act)
What extra rmcause activity is considered to be?
Definition: extras.cpp:994
struct extra_type * next_extra_for_tile(const struct tile *ptile, enum extra_cause cause, const struct player *pplayer, const struct unit *punit)
Returns next extra by cause that unit or player can build to tile.
Definition: extras.cpp:687
#define extra_type_iterate(_p)
Definition: extras.h:279
#define extra_type_iterate_end
Definition: extras.h:285
#define extra_road_get(_e_)
Definition: extras.h:171
#define extra_type_by_cause_iterate_end
Definition: extras.h:307
#define extra_type_by_cause_iterate(_cause, _extra)
Definition: extras.h:299
float adv_want
Definition: fc_types.h:1144
#define EC_NONE
Definition: fc_types.h:934
#define ERM_NONE
Definition: fc_types.h:958
@ O_FOOD
Definition: fc_types.h:85
signed short Continent_id
Definition: fc_types.h:289
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
Definition: game.cpp:103
int adv_city_worker_act_get(const struct city *pcity, int city_tile_index, enum unit_activity act_id)
Return the value for activity 'doing' on tile 'city_tile_index' of city 'pcity'.
Definition: infracache.cpp:362
int adv_city_worker_extra_get(const struct city *pcity, int city_tile_index, const struct extra_type *pextra)
Return the value for extra on tile 'city_tile_index' of city 'pcity'.
Definition: infracache.cpp:434
int adv_city_worker_rmextra_get(const struct city *pcity, int city_tile_index, const struct extra_type *pextra)
Return the value for extra removal on tile 'city_tile_index' of city 'pcity'.
Definition: infracache.cpp:453
int city_tile_value(const struct city *pcity, const struct tile *ptile, int foodneed, int prodneed)
Returns a measure of goodness of a tile to pcity.
Definition: infracache.cpp:305
#define fc_assert_action(condition, action)
Definition: log.h:104
#define log_debug(message,...)
Definition: log.h:65
struct terrain_misc terrain_control
Definition: map.cpp:40
#define SINGLE_MOVE
Definition: movement.h:17
bool road_provides_move_bonus(const struct road_type *proad)
Does road type provide move bonus.
Definition: road.cpp:437
#define FC_INFINITY
Definition: shared.h:32
#define MAX(x, y)
Definition: shared.h:48
action_id id
Definition: actions.h:306
int * cities
Definition: advdata.h:86
struct adv_data::@87 stats
struct adv_choice choice
Definition: daicity.h:38
int building_wait
Definition: daicity.h:35
int worker_want
Definition: daicity.h:64
struct unit_type * worker_type
Definition: daicity.h:65
Definition: aidata.h:63
int * workers
Definition: aidata.h:74
struct ai_plr::@155 stats
Definition: ai.h:42
Definition: city.h:291
int id
Definition: city.h:296
Definition: player.h:231
Definition: road.h:54
int move_cost
Definition: road.h:57
struct ai_city defai
Definition: texaicity.h:22
int unit_wants[U_LAST]
Definition: texaicity.h:23
void * data
Definition: texaimsg.h:62
struct player * plr
Definition: texaimsg.h:61
struct worker_task task
Definition: texaicity.c:51
Definition: tile.h:42
struct unit_list * units
Definition: tile.h:50
enum unit_activity act
Definition: workertask.h:17
struct tile * ptile
Definition: workertask.h:16
struct extra_type * tgt
Definition: workertask.h:18
#define fc_malloc(sz)
Definition: support.h:58
texai_worker_task_limitation
Definition: texaicity.c:54
@ TWTL_BUILDABLE_UNITS
Definition: texaicity.c:56
@ TWTL_CURRENT_UNITS
Definition: texaicity.c:55
#define TWMP
Definition: texaicity.c:47
static void texai_tile_worker_task_select(struct player *pplayer, struct city *pcity, struct tile *ptile, int cindex, struct unit_list *units, struct worker_task *worked, struct worker_task *unworked, struct texai_tile_state *state, enum texai_worker_task_limitation limit)
Select worker task suitable for the tile.
Definition: texaicity.c:153
static bool texai_city_worker_task_select(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct worker_task *task, enum texai_worker_task_limitation limit)
Select worker task suitable for the city.
Definition: texaicity.c:452
void texai_city_alloc(struct ai_type *ait, struct city *pcity)
Initialize city for use with tex AI.
Definition: texaicity.c:584
void texai_city_free(struct ai_type *ait, struct city *pcity)
Free city from use with tex AI.
Definition: texaicity.c:598
void texai_city_worker_requests_create(struct ai_type *ait, struct player *pplayer, struct city *pcity)
Create worker request for the city.
Definition: texaicity.c:68
void texai_city_worker_wants(struct ai_type *ait, struct player *pplayer, struct city *pcity)
Set wants for worker-type units.
Definition: texaicity.c:91
void texai_req_worker_task_rcv(struct texai_req *req)
Receive message from thread to main thread.
Definition: texaicity.c:549
static struct texai_city * texai_city_data(struct ai_type *ait, const struct city *pcity)
Definition: texaicity.h:36
void texai_send_req(enum texaireqtype type, struct player *pplayer, void *data)
Construct and send request from player thread.
Definition: texaimsg.c:46
struct unit_list * texai_player_units(struct player *pplayer)
Callback that returns unit list from player tex ai data.
Definition: texaiplayer.c:141
#define tile_worked(_tile)
Definition: tile.h:97
#define tile_terrain(_tile)
Definition: tile.h:93
#define TILE_XY(ptile)
Definition: tile.h:36
#define tile_continent(_tile)
Definition: tile.h:74
#define tile_has_extra(ptile, pextra)
Definition: tile.h:130
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_owner(_pu)
Definition: unit.h:370
#define unit_home(_pu_)
Definition: unit.h:369
#define unit_list_iterate(unitlist, punit)
Definition: unitlist.h:25
#define unit_list_iterate_end
Definition: unitlist.h:27
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
Definition: unittype.cpp:114
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Return whether the unit has the given flag.
Definition: unittype.cpp:176
Unit_type_id utype_index(const struct unit_type *punittype)
Return the unit type index.
Definition: unittype.cpp:82
#define unit_type_iterate(_p)
Definition: unittype.h:785
#define unit_type_iterate_end
Definition: unittype.h:791
void worker_task_init(struct worker_task *ptask)
Initialize empty worker_task.
Definition: workertask.cpp:18