Freeciv-3.1: /fast/freeciv/nightly/S3_1/ai/tex/texaicity.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
texaicity.c
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
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "log.h"
20
21/* common */
22#include "city.h"
23#include "game.h"
24#include "map.h"
25#include "movement.h"
26#include "tile.h"
27#include "unit.h"
28#include "workertask.h"
29
30/* server */
31#include "citytools.h"
32
33/* server/advisors */
34#include "advbuilding.h"
35#include "advdata.h"
36#include "autosettlers.h"
37#include "infracache.h"
38
39/* ai/default */
40#include "aidata.h"
41
42/* ai/tex */
43#include "texaimsg.h"
44#include "texaiplayer.h"
45
46#include "texaicity.h"
47
48/* Task Want Multiplier */
49#define TWMP 100
50
51 struct texai_worker_task_req
52{
53 int city_id;
54 struct worker_task task;
55};
56
57 enum texai_worker_task_limitation {
58 TWTL_CURRENT_UNITS,
59 TWTL_BUILDABLE_UNITS
60};
61
62static bool texai_city_worker_task_select(struct ai_type *ait,
63 struct player *pplayer,
64 struct city *pcity,
65 struct worker_task *task,
66 enum texai_worker_task_limitation limit);
67
68/**********************************************************************/
72 void texai_city_worker_requests_create(struct ai_type *ait,
73 struct player *pplayer, struct city *pcity)
74{
75 struct worker_task task;
76
77 if (texai_city_worker_task_select(ait, pplayer, pcity, &task, TWTL_CURRENT_UNITS)) {
78 struct texai_worker_task_req *data = fc_malloc(sizeof(*data));
79
80 data->city_id = pcity->id;
81 data->task.ptile = task.ptile;
82 data->task.act = task.act;
83 data->task.tgt = task.tgt;
84 data->task.want = task.want;
85
86 texai_send_req(TEXAI_REQ_WORKER_TASK, pplayer, data);
87 }
88}
89
90/**********************************************************************/
93 void texai_city_worker_wants(struct ai_type *ait,
94 struct player *pplayer, struct city *pcity)
95{
96 struct worker_task task;
97 struct texai_city *cdata = texai_city_data(ait, pcity);
98 int *wants = cdata->unit_wants;
99 int maxwant = 0;
100 struct unit_type *type = NULL;
101 Continent_id place = tile_continent(city_tile(pcity));
102 struct ai_plr *dai = dai_plr_data_get(ait, pplayer, NULL);
103 struct adv_data *adv = adv_data_get(pplayer, NULL);
104
105 unit_type_iterate(ptype) {
106 wants[utype_index(ptype)] = 0;
107 } unit_type_iterate_end;
108
109 texai_city_worker_task_select(ait, pplayer, pcity, &task, TWTL_BUILDABLE_UNITS);
110
111 unit_type_iterate(ptype) {
112 int twant = wants[utype_index(ptype)];
113
114 twant -= 20 * ptype->pop_cost;
115 twant -= ptype->build_cost;
116 twant -= ptype->upkeep[O_FOOD] * FOOD_WEIGHTING / 2;
117
118 /* Massage our desire based on available statistics to prevent
119 * overflooding with worker type units if they come cheap in
120 * the ruleset */
121 if (place >= 0) {
122 twant /= 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 } unit_type_iterate_end;
135
136 cdata->defai.worker_want = maxwant / 70;
137 cdata->defai.worker_type = type;
138}
139
140 struct texai_tile_state
141{
142 int uw_max_base; /* Value for the city working the tile */
143 int uw_max; /* With road connectivity bonus */
144 int worst_worked;
145 int orig_worst_worked;
146 int old_worst_worked;
147 int *wants;
148};
149
150/**********************************************************************/
153 static void texai_tile_worker_task_select(struct player *pplayer,
154 struct city *pcity, struct tile *ptile,
155 int cindex, struct unit_list *units,
156 struct worker_task *worked,
157 struct worker_task *unworked,
158 struct texai_tile_state *state,
159 enum texai_worker_task_limitation limit)
160{
161 int orig_value;
162 bool potential_worst_worked = FALSE;
163
164 if (!city_can_work_tile(pcity, ptile)) {
165 return;
166 }
167
168 orig_value = city_tile_value(pcity, ptile, 0, 0);
169
170 if (tile_worked(ptile) == pcity
171 && orig_value < state->worst_worked) {
172 state->worst_worked = orig_value;
173 state->orig_worst_worked = orig_value;
174 potential_worst_worked = TRUE;
175 }
176
177 as_transform_action_iterate(act) {
178 bool consider = TRUE;
179 bool possible = FALSE;
180 enum extra_cause cause;
181 enum extra_rmcause rmcause;
182 struct extra_type *tgt = NULL;
183
184 /* Do not request activities that already are under way. */
185 unit_list_iterate(ptile->units, punit) {
186 if (unit_owner(punit) == pplayer
187 && unit_has_type_flag(punit, UTYF_SETTLERS)
188 && punit->activity == action_id_get_activity(act)) {
189 consider = FALSE;
190 break;
191 }
192 } unit_list_iterate_end;
193
194 if (!consider) {
195 continue;
196 }
197
198 cause = activity_to_extra_cause(action_id_get_activity(act));
199 rmcause = activity_to_extra_rmcause(action_id_get_activity(act));
200
201 unit_list_iterate(units, punit) {
202 if (cause != EC_NONE) {
203 tgt = next_extra_for_tile(ptile, cause, pplayer, punit);
204 } else if (rmcause != ERM_NONE) {
205 tgt = prev_extra_in_tile(ptile, rmcause, pplayer, punit);
206 }
207
208 if (action_prob_possible(
209 action_speculate_unit_on_tile(act,
210 punit, unit_home(punit), ptile,
211 TRUE,
212 ptile, tgt))) {
213 possible = TRUE;
214 break;
215 }
216 } unit_list_iterate_end;
217
218 if (possible) {
219 int value = adv_city_worker_act_get(pcity, cindex,
220 action_id_get_activity(act));
221
222 if (tile_worked(ptile) == pcity) {
223 if ((value - orig_value) * TWMP > worked->want) {
224 worked->want = TWMP * (value - orig_value);
225 worked->ptile = ptile;
226 worked->act = action_id_get_activity(act);
227 worked->tgt = NULL;
228 if (limit == TWTL_BUILDABLE_UNITS) {
229 unit_list_iterate(units, punit) {
230 if (action_prob_possible(
231 action_speculate_unit_on_tile(act,
232 punit, unit_home(punit),
233 ptile,
234 TRUE,
235 ptile, tgt))) {
236 state->wants[utype_index(unit_type_get(punit))] += worked->want;
237 }
238 } unit_list_iterate_end;
239 }
240 }
241 if (value > state->old_worst_worked) {
242 /* After improvement it would not be the worst */
243 potential_worst_worked = FALSE;
244 } else {
245 state->worst_worked = value;
246 }
247 } else {
248 if (value > orig_value && value > state->uw_max) {
249 state->uw_max = value;
250 state->uw_max_base = value;
251 unworked->want = TWMP * (value - orig_value);
252 unworked->ptile = ptile;
253 unworked->act = action_id_get_activity(act);
254 unworked->tgt = NULL;
255 if (limit == TWTL_BUILDABLE_UNITS) {
256 unit_list_iterate(units, punit) {
257 if (action_prob_possible(
258 action_speculate_unit_on_tile(act,
259 punit, unit_home(punit),
260 ptile,
261 TRUE,
262 ptile, tgt))) {
263 state->wants[utype_index(unit_type_get(punit))] += unworked->want;
264 }
265 } unit_list_iterate_end;
266 }
267 }
268 }
269 }
270 } as_transform_action_iterate_end;
271
272 extra_type_iterate(tgt) {
273 struct action *paction = NULL;
274 bool removing = tile_has_extra(ptile, tgt);
275
276 unit_list_iterate(units, punit) {
277 if (removing) {
278 as_rmextra_action_iterate(try_act) {
279 struct action *taction = action_by_number(try_act);
280 if (is_extra_removed_by_action(tgt, taction)
281 && action_prob_possible(
282 action_speculate_unit_on_tile(try_act,
283 punit,
284 unit_home(punit), ptile,
285 TRUE,
286 ptile, tgt))) {
287 paction = taction;
288 break;
289 }
290 } as_rmextra_action_iterate_end;
291 } else {
292 as_extra_action_iterate(try_act) {
293 struct action *taction = action_by_number(try_act);
294 if (is_extra_caused_by_action(tgt, taction)
295 && action_prob_possible(
296 action_speculate_unit_on_tile(try_act,
297 punit,
298 unit_home(punit), ptile,
299 TRUE,
300 ptile, tgt))) {
301 paction = taction;
302 break;
303 }
304 } as_extra_action_iterate_end;
305 }
306 } unit_list_iterate_end;
307
308 if (paction != NULL) {
309 adv_want base_value;
310 int value;
311 adv_want extra;
312 bool consider = TRUE;
313 struct road_type *proad;
314
315 /* Do not request activities that already are under way. */
316 unit_list_iterate(ptile->units, punit) {
317 if (unit_owner(punit) == pplayer
318 && unit_has_type_flag(punit, UTYF_SETTLERS)
319 && punit->activity == actres_get_activity(paction->result)) {
320 consider = FALSE;
321 break;
322 }
323 } unit_list_iterate_end;
324
325 if (!consider) {
326 continue;
327 }
328
329 proad = extra_road_get(tgt);
330
331 if (removing) {
332 base_value = adv_city_worker_rmextra_get(pcity, cindex, tgt);
333 } else {
334 base_value = adv_city_worker_extra_get(pcity, cindex, tgt);
335 }
336
337 if (proad != NULL && road_provides_move_bonus(proad)) {
338 int old_move_cost;
339 int mc_multiplier = 1;
340 int mc_divisor = 1;
341
342 /* Here 'old' means actually 'without the evaluated': In case of
343 * removal activity it's the value after the removal. */
344 old_move_cost = tile_terrain(ptile)->movement_cost * SINGLE_MOVE;
345
346 extra_type_by_cause_iterate(EC_ROAD, poe) {
347 struct road_type *pold = extra_road_get(poe);
348
349 if (tile_has_extra(ptile, poe) && poe != tgt) {
350 if (road_provides_move_bonus(pold)
351 && pold->move_cost < old_move_cost) {
352 old_move_cost = pold->move_cost;
353 }
354 }
355 } extra_type_by_cause_iterate_end;
356
357 if (proad->move_cost < old_move_cost) {
358 if (proad->move_cost >= terrain_control.move_fragments) {
359 mc_divisor = proad->move_cost / terrain_control.move_fragments;
360 } else {
361 if (proad->move_cost == 0) {
362 mc_multiplier = 2;
363 } else {
364 mc_multiplier = 1 - proad->move_cost;
365 }
366 mc_multiplier += old_move_cost;
367 }
368 }
369
370 extra = adv_settlers_road_bonus(&(wld.map), ptile, proad)
371 * mc_multiplier / mc_divisor;
372
373 if (removing) {
374 extra = -extra;
375 }
376 } else {
377 extra = 0;
378 }
379
380 value = base_value + extra;
381
382 if (tile_worked(ptile) == pcity) {
383 if ((value - orig_value) * TWMP > worked->want) {
384 worked->want = TWMP * (value - orig_value);
385 worked->ptile = ptile;
386 worked->act = actres_get_activity(paction->result);
387 worked->tgt = tgt;
388 if (limit == TWTL_BUILDABLE_UNITS) {
389 unit_list_iterate(units, punit) {
390 fc_assert_action(action_get_target_kind(paction) == ATK_TILE,
391 break);
392 if (action_prob_possible(action_speculate_unit_on_tile(
393 paction->id,
394 punit, unit_home(punit), ptile,
395 TRUE,
396 ptile, tgt))) {
397 state->wants[utype_index(unit_type_get(punit))] += worked->want;
398 }
399 } unit_list_iterate_end;
400 }
401 }
402 if (value > state->old_worst_worked) {
403 /* After improvement it would not be the worst */
404 potential_worst_worked = FALSE;
405 } else {
406 state->worst_worked = value;
407 }
408 } else {
409 if (value > orig_value && value > state->uw_max) {
410 state->uw_max = value;
411 state->uw_max_base = base_value;
412 unworked->want = TWMP * (value - orig_value);
413 unworked->ptile = ptile;
414 unworked->act = actres_get_activity(paction->result);
415 unworked->tgt = tgt;
416 if (limit == TWTL_BUILDABLE_UNITS) {
417 unit_list_iterate(units, punit) {
418 fc_assert_action(action_get_target_kind(paction) == ATK_TILE,
419 break);
420 if (action_prob_possible(action_speculate_unit_on_tile(
421 paction->id,
422 punit, unit_home(punit), ptile,
423 TRUE,
424 ptile, tgt))) {
425 state->wants[utype_index(unit_type_get(punit))] += unworked->want;
426 }
427 } unit_list_iterate_end;
428 }
429 }
430 }
431 }
432 } extra_type_iterate_end;
433
434 if (potential_worst_worked) {
435 /* Would still be worst worked even if we improved *it*. */
436 state->old_worst_worked = state->worst_worked;
437 }
438}
439
440/**********************************************************************/
443 static bool texai_city_worker_task_select(struct ai_type *ait,
444 struct player *pplayer, struct city *pcity,
445 struct worker_task *task,
446 enum texai_worker_task_limitation limit)
447{
448 struct worker_task *selected;
449 struct worker_task worked = { .ptile = NULL, .want = 0, .act = ACTIVITY_IDLE, .tgt = NULL };
450 struct worker_task unworked = { .ptile = NULL, .want = 0, .act = ACTIVITY_IDLE, .tgt = NULL };
451 struct texai_tile_state state = { .uw_max = 0, .uw_max_base = 0, .worst_worked = FC_INFINITY,
452 .orig_worst_worked = 0, .old_worst_worked = FC_INFINITY };
453 struct unit_list *units = NULL;
454 const struct civ_map *nmap = &(wld.map);
455
456 switch (limit) {
457 case TWTL_CURRENT_UNITS:
458 units = texai_player_units(pplayer);
459 state.wants = NULL;
460 break;
461 case TWTL_BUILDABLE_UNITS:
462 units = unit_list_new();
463 unit_type_iterate(ptype) {
464 if (can_city_build_unit_now(pcity, ptype)) {
465 unit_list_append(units, unit_virtual_create(pplayer, pcity, ptype, 0));
466 }
467 } unit_type_iterate_end;
468 state.wants = texai_city_data(ait, pcity)->unit_wants;
469 break;
470 }
471
472 city_tile_iterate_index(nmap, city_map_radius_sq_get(pcity), city_tile(pcity),
473 ptile, cindex) {
474 texai_tile_worker_task_select(pplayer, pcity, ptile, cindex, units,
475 &worked, &unworked, &state, limit);
476 } city_tile_iterate_end;
477
478 if (worked.ptile == NULL
479 || (state.old_worst_worked < state.uw_max
480 && (state.uw_max - state.orig_worst_worked) * TWMP > worked.want)
481 || (state.uw_max - state.uw_max_base * TWMP > worked.want)) {
482 /* It's better to improve best yet unworked tile and take it to use after that,
483 than to improve already worked tile. OR it's more important to
484 improve road connectivity outside worked tiles than improve worked tiles */
485 selected = &unworked;
486 } else {
487 selected = &worked;
488 }
489
490 if (limit == TWTL_BUILDABLE_UNITS) {
491 unit_list_iterate(units, punit) {
492 unit_virtual_destroy(punit);
493 } unit_list_iterate_end;
494 unit_list_destroy(units);
495 }
496
497 if (selected->ptile != NULL) {
498 struct extra_type *target = NULL;
499
500 if (selected->tgt == NULL) {
501 enum extra_cause cause = activity_to_extra_cause(selected->act);
502
503 if (cause != EC_NONE) {
504 target = next_extra_for_tile(selected->ptile, cause, pplayer, NULL);
505 } else {
506 enum extra_rmcause rmcause = activity_to_extra_rmcause(selected->act);
507
508 if (rmcause != ERM_NONE) {
509 target = prev_extra_in_tile(selected->ptile, rmcause, pplayer, NULL);
510 }
511 }
512 } else {
513 target = selected->tgt;
514 }
515
516 task->ptile = selected->ptile;
517 task->act = selected->act;
518 task->tgt = target;
519 task->want = selected->want;
520
521 return TRUE;
522 }
523
524 return FALSE;
525}
526
527/**********************************************************************/
530 void texai_req_worker_task_rcv(struct texai_req *req)
531{
532 struct texai_worker_task_req *data = (struct texai_worker_task_req *)req->data;
533 struct city *pcity;
534
535 pcity = game_city_by_number(data->city_id);
536
537 if (pcity != NULL && city_owner(pcity) == req->plr) {
538 /* City has not been lost meanwhile */
539 struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
540
541 if (ptask == NULL) {
542 ptask = fc_malloc(sizeof(struct worker_task));
543 worker_task_init(ptask);
544 worker_task_list_append(pcity->task_reqs, ptask);
545 }
546
547 log_debug("%s storing req for act %d at (%d,%d)",
548 pcity->name, data->task.act, TILE_XY(data->task.ptile));
549 ptask->ptile = data->task.ptile;
550 ptask->act = data->task.act;
551 ptask->tgt = data->task.tgt;
552 ptask->want = data->task.want;
553
554 /* Send info to observers */
555 package_and_send_worker_tasks(pcity);
556 }
557
558 free(data);
559}
560
561/**********************************************************************/
564 void texai_city_alloc(struct ai_type *ait, struct city *pcity)
565{
566 struct texai_city *city_data = fc_calloc(1, sizeof(struct texai_city));
567
568 city_data->defai.building_wait = BUILDING_WAIT_MINIMUM;
569 adv_init_choice(&(city_data->defai.choice));
570
571 city_set_ai_data(pcity, ait, city_data);
572}
573
574/**********************************************************************/
577 void texai_city_free(struct ai_type *ait, struct city *pcity)
578{
579 struct texai_city *city_data = texai_city_data(ait, pcity);
580
581 if (city_data != NULL) {
582 adv_deinit_choice(&(city_data->defai.choice));
583 city_set_ai_data(pcity, ait, NULL);
584 FC_FREE(city_data);
585 }
586}
action_prob_possible
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:6707
actres_get_activity
enum unit_activity actres_get_activity(enum action_result result)
Definition actions.c:2136
action_get_target_kind
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1740
action_speculate_unit_on_tile
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)
Definition actions.c:6560
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
action_id_get_activity
#define action_id_get_activity(act_id)
Definition actions.h:712
advbuilding.h
FOOD_WEIGHTING
#define FOOD_WEIGHTING
Definition advbuilding.h:19
adv_deinit_choice
void adv_deinit_choice(struct adv_choice *choice)
Definition advchoice.c:46
adv_init_choice
void adv_init_choice(struct adv_choice *choice)
Definition advchoice.c:31
adv_data_get
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Definition advdata.c:593
advdata.h
dai_plr_data_get
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Definition aidata.c:308
aidata.h
adv_settlers_road_bonus
adv_want adv_settlers_road_bonus(const struct civ_map *nmap, struct tile *ptile, struct road_type *proad)
Definition autosettlers.c:133
autosettlers.h
as_transform_action_iterate_end
#define as_transform_action_iterate_end
Definition autosettlers.h:79
as_rmextra_action_iterate
#define as_rmextra_action_iterate(_act_)
Definition autosettlers.h:95
as_rmextra_action_iterate_end
#define as_rmextra_action_iterate_end
Definition autosettlers.h:99
as_extra_action_iterate_end
#define as_extra_action_iterate_end
Definition autosettlers.h:89
as_extra_action_iterate
#define as_extra_action_iterate(_act_)
Definition autosettlers.h:85
as_transform_action_iterate
#define as_transform_action_iterate(_act_)
Definition autosettlers.h:75
city_set_ai_data
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3512
city_map_radius_sq_get
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:132
city_can_work_tile
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1425
can_city_build_unit_now
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:928
city.h
city_tile
#define city_tile(_pcity_)
Definition city.h:544
city_tile_iterate_index
#define city_tile_iterate_index(_nmap, _radius_sq, _city_tile, _tile, _index)
Definition city.h:193
city_owner
#define city_owner(_pcity_)
Definition city.h:543
city_tile_iterate_end
#define city_tile_iterate_end
Definition city.h:230
package_and_send_worker_tasks
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3505
citytools.h
BUILDING_WAIT_MINIMUM
#define BUILDING_WAIT_MINIMUM
Definition daicity.h:39
punit
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
next_extra_for_tile
struct extra_type * next_extra_for_tile(const struct tile *ptile, enum extra_cause cause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:740
prev_extra_in_tile
struct extra_type * prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:765
activity_to_extra_cause
enum extra_cause activity_to_extra_cause(enum unit_activity act)
Definition extras.c:1028
is_extra_caused_by_action
bool is_extra_caused_by_action(const struct extra_type *pextra, const struct action *paction)
Definition extras.c:1006
is_extra_removed_by_action
bool is_extra_removed_by_action(const struct extra_type *pextra, const struct action *paction)
Definition extras.c:1017
activity_to_extra_rmcause
enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act)
Definition extras.c:1049
extra_type_iterate
#define extra_type_iterate(_p)
Definition extras.h:291
extra_type_iterate_end
#define extra_type_iterate_end
Definition extras.h:297
extra_road_get
#define extra_road_get(_e_)
Definition extras.h:185
extra_type_by_cause_iterate_end
#define extra_type_by_cause_iterate_end
Definition extras.h:315
extra_type_by_cause_iterate
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
adv_want
float adv_want
Definition fc_types.h:1206
EC_NONE
#define EC_NONE
Definition fc_types.h:967
ERM_NONE
#define ERM_NONE
Definition fc_types.h:992
O_FOOD
@ O_FOOD
Definition fc_types.h:91
Continent_id
signed short Continent_id
Definition fc_types.h:342
wld
struct world wld
Definition game.c:58
game_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:102
game.h
type
GType type
Definition repodlgs.c:1312
adv_city_worker_act_get
adv_want adv_city_worker_act_get(const struct city *pcity, int city_tile_index, enum unit_activity act_id)
Definition infracache.c:359
adv_city_worker_extra_get
int adv_city_worker_extra_get(const struct city *pcity, int city_tile_index, const struct extra_type *pextra)
Definition infracache.c:429
adv_city_worker_rmextra_get
int adv_city_worker_rmextra_get(const struct city *pcity, int city_tile_index, const struct extra_type *pextra)
Definition infracache.c:446
city_tile_value
adv_want city_tile_value(const struct city *pcity, const struct tile *ptile, int foodneed, int prodneed)
Definition infracache.c:302
infracache.h
log.h
fc_assert_action
#define fc_assert_action(condition, action)
Definition log.h:187
log_debug
#define log_debug(message,...)
Definition log.h:115
terrain_control
struct terrain_misc terrain_control
Definition map.c:69
map.h
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
movement.h
SINGLE_MOVE
#define SINGLE_MOVE
Definition movement.h:24
road_provides_move_bonus
bool road_provides_move_bonus(const struct road_type *proad)
Definition road.c:499
FC_INFINITY
#define FC_INFINITY
Definition shared.h:36
MAX
#define MAX(x, y)
Definition shared.h:54
action
Definition actions.h:379
action::id
action_id id
Definition actions.h:380
action::result
enum action_result result
Definition actions.h:382
adv_data
Definition advdata.h:45
adv_data::stats
struct adv_data::@92 stats
adv_data::cities
int * cities
Definition advdata.h:90
ai_city::choice
struct adv_choice choice
Definition daicity.h:41
ai_city::building_wait
int building_wait
Definition daicity.h:38
ai_city::worker_want
int worker_want
Definition daicity.h:67
ai_city::worker_type
struct unit_type * worker_type
Definition daicity.h:68
ai_plr
Definition aidata.h:71
ai_plr::workers
int * workers
Definition aidata.h:82
ai_plr::stats
struct ai_plr::@267 stats
ai_type
Definition ai.h:50
city
Definition city.h:309
city::task_reqs
struct worker_task_list * task_reqs
Definition city.h:395
city::id
int id
Definition city.h:315
city::name
char * name
Definition city.h:310
civ_map
Definition map_types.h:71
extra_type
Definition extras.h:85
player
Definition player.h:249
road_type
Definition road.h:75
road_type::move_cost
int move_cost
Definition road.h:78
texai_city
Definition texaicity.h:23
texai_city::defai
struct ai_city defai
Definition texaicity.h:24
texai_city::unit_wants
int unit_wants[U_LAST]
Definition texaicity.h:25
texai_req
Definition texaimsg.h:62
texai_req::data
void * data
Definition texaimsg.h:65
texai_req::plr
struct player * plr
Definition texaimsg.h:64
texai_tile_state
Definition texaicity.c:141
texai_tile_state::uw_max
int uw_max
Definition texaicity.c:143
texai_tile_state::orig_worst_worked
int orig_worst_worked
Definition texaicity.c:145
texai_tile_state::uw_max_base
int uw_max_base
Definition texaicity.c:142
texai_tile_state::wants
int * wants
Definition texaicity.c:147
texai_tile_state::worst_worked
int worst_worked
Definition texaicity.c:144
texai_tile_state::old_worst_worked
int old_worst_worked
Definition texaicity.c:146
texai_worker_task_req
Definition texaicity.c:52
texai_worker_task_req::task
struct worker_task task
Definition texaicity.c:54
texai_worker_task_req::city_id
int city_id
Definition texaicity.c:53
tile
Definition tile.h:49
tile::units
struct unit_list * units
Definition tile.h:57
unit_type
Definition unittype.h:481
unit::activity
enum unit_activity activity
Definition unit.h:157
worker_task
Definition workertask.h:21
worker_task::act
enum unit_activity act
Definition workertask.h:23
worker_task::ptile
struct tile * ptile
Definition workertask.h:22
worker_task::tgt
struct extra_type * tgt
Definition workertask.h:24
worker_task::want
int want
Definition workertask.h:25
world::map
struct civ_map map
Definition world_object.h:38
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
texai_worker_task_limitation
texai_worker_task_limitation
Definition texaicity.c:57
TWTL_BUILDABLE_UNITS
@ TWTL_BUILDABLE_UNITS
Definition texaicity.c:59
TWTL_CURRENT_UNITS
@ TWTL_CURRENT_UNITS
Definition texaicity.c:58
TWMP
#define TWMP
Definition texaicity.c:49
texai_tile_worker_task_select
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)
Definition texaicity.c:153
texai_city_worker_task_select
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)
Definition texaicity.c:443
texai_city_alloc
void texai_city_alloc(struct ai_type *ait, struct city *pcity)
Definition texaicity.c:564
texai_city_free
void texai_city_free(struct ai_type *ait, struct city *pcity)
Definition texaicity.c:577
texai_city_worker_requests_create
void texai_city_worker_requests_create(struct ai_type *ait, struct player *pplayer, struct city *pcity)
Definition texaicity.c:72
texai_city_worker_wants
void texai_city_worker_wants(struct ai_type *ait, struct player *pplayer, struct city *pcity)
Definition texaicity.c:93
texai_req_worker_task_rcv
void texai_req_worker_task_rcv(struct texai_req *req)
Definition texaicity.c:530
texaicity.h
texai_city_data
static struct texai_city * texai_city_data(struct ai_type *ait, const struct city *pcity)
Definition texaicity.h:37
texai_send_req
void texai_send_req(enum texaireqtype type, struct player *pplayer, void *data)
Definition texaimsg.c:48
texaimsg.h
texai_player_units
struct unit_list * texai_player_units(struct player *pplayer)
Definition texaiplayer.c:156
texaiplayer.h
tile.h
tile_worked
#define tile_worked(_tile)
Definition tile.h:113
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:109
TILE_XY
#define TILE_XY(ptile)
Definition tile.h:42
tile_continent
#define tile_continent(_tile)
Definition tile.h:91
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
unit_virtual_create
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1619
unit_virtual_destroy
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1715
unit.h
unit_owner
#define unit_owner(_pu)
Definition unit.h:387
unit_home
#define unit_home(_pu_)
Definition unit.h:386
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:184
utype_index
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
unit_type_iterate
#define unit_type_iterate(_p)
Definition unittype.h:838
unit_type_iterate_end
#define unit_type_iterate_end
Definition unittype.h:845
worker_task_init
void worker_task_init(struct worker_task *ptask)
Definition workertask.c:31
workertask.h