Freeciv-3.3: /fast/freeciv/nightly/main/common/aicore/cm.h Source File

Freeciv-3.3

Loading...
Searching...
No Matches
cm.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2002 - The Freeciv Project
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#ifndef FC__CM_H
15#define FC__CM_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21/*
22 * The purpose of this module is to manage the citizens of a city. The
23 * caller has to provide a goal (struct cm_parameter) which determines
24 * in which way the citizens are allocated and placed. The module will
25 * also avoid disorder.
26 *
27 * The plan defines a minimal surplus. The module will try to get the
28 * required surplus. If there are citizens free after allocation of
29 * the minimal surplus these citizens will get arranged to maximize
30 * the weighted sum over the surplus of each type.
31 */
32
33/* utility */
34#include "support.h" /* bool type */
35
36/* common */
37#include "city.h" /* CITY_MAP_MAX_SIZE */
38
39/* A description of the goal. */
40 struct cm_parameter {
41 int minimal_surplus[O_LAST];
42 bool max_growth;
43 bool require_happy;
44 bool allow_disorder;
45 bool allow_specialists;
46
47 int factor[O_LAST];
48 int happy_factor;
49};
50
51/* A result which can examined. */
52 struct cm_result {
53 bool aborted;
54 bool found_a_valid, disorder, happy;
55
56 int surplus[O_LAST];
57
58 int city_radius_sq;
59 bool *worker_positions;
60 citizens specialists[SP_MAX];
61};
62
63void cm_init(void);
64void cm_init_citymap(void);
65void cm_clear_cache(struct city *pcity);
66void cm_free(void);
67
68struct cm_result *cm_result_new(struct city *pcity);
69void cm_result_destroy(struct cm_result *result);
70
71/*
72 * Will try to meet the requirements and fill out the result. Caller
73 * should test result->found_a_valid. cm_query_result() will not change
74 * the actual city setting.
75 */
76void cm_query_result(struct city *pcity,
77 const struct cm_parameter *const parameter,
78 struct cm_result *result, bool negative_ok);
79
80/*
81 * Call this function if the city has changed. To be safe call it
82 * everytime before you call cm_query_result().
83 */
84void cm_clear_cache(struct city *pcity);
85
86/***************** utility methods *************************************/
87bool cm_are_parameter_equal(const struct cm_parameter *const p1,
88 const struct cm_parameter *const p2);
89void cm_copy_parameter(struct cm_parameter *dest,
90 const struct cm_parameter *const src);
91void cm_init_parameter(struct cm_parameter *dest);
92void cm_init_emergency_parameter(struct cm_parameter *dest);
93
94void cm_print_city(const struct city *pcity);
95void cm_print_result(const struct cm_result *result);
96
97int cm_result_citizens(const struct cm_result *result);
98int cm_result_specialists(const struct cm_result *result);
99int cm_result_workers(const struct cm_result *result);
100
101void cm_result_from_main_map(struct cm_result *result,
102 const struct city *pcity);
103
104#ifdef __cplusplus
105}
106#endif /* __cplusplus */
107
108#endif /* FC__CM_H */
city.h
cm_init_citymap
void cm_init_citymap(void)
Definition cm.c:314
cm_clear_cache
void cm_clear_cache(struct city *pcity)
Definition cm.c:322
cm_copy_parameter
void cm_copy_parameter(struct cm_parameter *dest, const struct cm_parameter *const src)
Definition cm.c:2171
cm_init_parameter
void cm_init_parameter(struct cm_parameter *dest)
Definition cm.c:2180
cm_result_new
struct cm_result * cm_result_new(struct city *pcity)
Definition cm.c:345
cm_result_specialists
int cm_result_specialists(const struct cm_result *result)
Definition cm.c:2235
cm_result_from_main_map
void cm_result_from_main_map(struct cm_result *result, const struct city *pcity)
Definition cm.c:2258
cm_are_parameter_equal
bool cm_are_parameter_equal(const struct cm_parameter *const p1, const struct cm_parameter *const p2)
Definition cm.c:2138
cm_query_result
void cm_query_result(struct city *pcity, const struct cm_parameter *const parameter, struct cm_result *result, bool negative_ok)
Definition cm.c:2120
cm_result_destroy
void cm_result_destroy(struct cm_result *result)
Definition cm.c:368
cm_print_result
void cm_print_result(const struct cm_result *result)
Definition cm.c:2466
cm_init
void cm_init(void)
Definition cm.c:293
cm_result_citizens
int cm_result_citizens(const struct cm_result *result)
Definition cm.c:2249
cm_init_emergency_parameter
void cm_init_emergency_parameter(struct cm_parameter *dest)
Definition cm.c:2198
cm_print_city
void cm_print_city(const struct city *pcity)
Definition cm.c:2428
cm_result_workers
int cm_result_workers(const struct cm_result *result)
Definition cm.c:2215
cm_free
void cm_free(void)
Definition cm.c:330
incite_cost
char * incite_cost
Definition comments.c:74
citizens
unsigned char citizens
Definition fc_types.h:392
SP_MAX
#define SP_MAX
Definition fc_types.h:412
O_LAST
@ O_LAST
Definition fc_types.h:101
city
Definition city.h:320
cm_parameter
Definition cm.h:40
cm_parameter::allow_disorder
bool allow_disorder
Definition cm.h:44
cm_parameter::factor
int factor[O_LAST]
Definition cm.h:47
cm_parameter::max_growth
bool max_growth
Definition cm.h:42
cm_parameter::allow_specialists
bool allow_specialists
Definition cm.h:45
cm_parameter::require_happy
bool require_happy
Definition cm.h:43
cm_parameter::minimal_surplus
int minimal_surplus[O_LAST]
Definition cm.h:41
cm_parameter::happy_factor
int happy_factor
Definition cm.h:48
cm_result
Definition cm.h:52
cm_result::found_a_valid
bool found_a_valid
Definition cm.h:54
cm_result::disorder
bool disorder
Definition cm.h:54
cm_result::aborted
bool aborted
Definition cm.h:53
cm_result::surplus
int surplus[O_LAST]
Definition cm.h:56
cm_result::happy
bool happy
Definition cm.h:54
cm_result::worker_positions
bool * worker_positions
Definition cm.h:59
cm_result::city_radius_sq
int city_radius_sq
Definition cm.h:58
cm_result::specialists
citizens specialists[SP_MAX]
Definition cm.h:60
support.h