Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/agents/cma_core.c File Reference

Freeciv-3.1

Loading...
Searching...
No Matches
Macros | Functions | Variables
cma_core.c File Reference
`#include <string.h>`
`#include "bugs.h"`
`#include "fcintl.h"`
`#include "log.h"`
`#include "mem.h"`
`#include "shared.h"`
`#include "specialist.h"`
`#include "support.h"`
`#include "timing.h"`
`#include "city.h"`
`#include "dataio.h"`
`#include "events.h"`
`#include "game.h"`
`#include "government.h"`
`#include "packets.h"`
`#include "attribute.h"`
`#include "client_main.h"`
`#include "climisc.h"`
`#include "packhand.h"`
`#include "chatline_g.h"`
`#include "citydlg_g.h"`
`#include "cityrep_g.h"`
`#include "messagewin_g.h"`
`#include "agents.h"`
`#include "cma_core.h"`

Go to the source code of this file.

## Macros

#define | log_apply_result log_debug
#define | log_handle_city log_debug
#define | log_handle_city2 log_debug
#define | log_results_are_equal log_debug
#define | SHOW_TIME_STATS FALSE
#define | SHOW_APPLY_RESULT_ON_SERVER_ERRORS FALSE
#define | ALWAYS_APPLY_AT_SERVER FALSE
#define | SAVED_PARAMETER_SIZE 30
#define | CMA_ATTR_VERSION 3
#define | CMA_ATTR_VERSION_MIN_SUPPORTED 2
#define | T(x)

## Functions

static bool | fc_results_are_equal (const struct cm_result *result1, const struct cm_result *result2)
static struct city * | check_city (int city_id, struct cm_parameter *parameter)
static bool | apply_result_on_server (struct city *pcity, const struct cm_result *result)
static void | report_stats (void)
static void | release_city (int city_id)
static void | handle_city (struct city *pcity)
static void | city_changed (int city_id)
static void | city_remove (int city_id)
static void | new_turn (void)
void | cma_init (void)
bool | cma_apply_result (struct city *pcity, const struct cm_result *result)
void | cma_put_city_under_agent (struct city *pcity, const struct cm_parameter *const parameter)
void | cma_release_city (struct city *pcity)
bool | cma_is_city_under_agent (const struct city *pcity, struct cm_parameter *parameter)
bool | cma_get_parameter (enum attr_city attr, int city_id, struct cm_parameter *parameter)
void | cma_set_parameter (enum attr_city attr, int city_id, const struct cm_parameter *parameter)

## Variables

struct { |
struct timer * wall_timer |
int apply_result_ignored |
int apply_result_applied |
int refresh_forced |
} | stats |

## Macro Definition Documentation

## ◆ ALWAYS_APPLY_AT_SERVER

#define ALWAYS_APPLY_AT_SERVER FALSE

Definition at line 79 of file cma_core.c.

## ◆ CMA_ATTR_VERSION

#define CMA_ATTR_VERSION 3

Definition at line 83 of file cma_core.c.

## ◆ CMA_ATTR_VERSION_MIN_SUPPORTED

#define CMA_ATTR_VERSION_MIN_SUPPORTED 2

Definition at line 84 of file cma_core.c.

## ◆ log_apply_result

#define log_apply_result log_debug

Definition at line 72 of file cma_core.c.

## ◆ log_handle_city

#define log_handle_city log_debug

Definition at line 73 of file cma_core.c.

## ◆ log_handle_city2

#define log_handle_city2 log_debug

Definition at line 74 of file cma_core.c.

## ◆ log_results_are_equal

#define log_results_are_equal log_debug

Definition at line 75 of file cma_core.c.

## ◆ SAVED_PARAMETER_SIZE

#define SAVED_PARAMETER_SIZE 30

Definition at line 81 of file cma_core.c.

## ◆ SHOW_APPLY_RESULT_ON_SERVER_ERRORS

#define SHOW_APPLY_RESULT_ON_SERVER_ERRORS FALSE

Definition at line 78 of file cma_core.c.

## ◆ SHOW_TIME_STATS

#define SHOW_TIME_STATS FALSE

Definition at line 77 of file cma_core.c.

## ◆ T

#define T | ( |  | x | ) |

Value:
if (result1->x != result2->x) { \
log_results_are_equal(#x); \
return FALSE; }
FALSE
#define FALSE
Definition support.h:47

## Function Documentation

## ◆ apply_result_on_server()

static bool apply_result_on_server | ( | struct city * | pcity,
|  | const struct cm_result * | result
| ) |  |

static

Change the actual city setting to the given result. Returns TRUE iff the actual data matches the calculated one.

Definition at line 167 of file cma_core.c.

Referenced by cma_apply_result(), and handle_city().

## ◆ check_city()

static struct city * check_city | ( | int | city_id,
|  | struct cm_parameter * | parameter
| ) |  |

static

Returns TRUE if the city is valid for CMA. Fills parameter if TRUE is returned. Parameter can be NULL.

Definition at line 140 of file cma_core.c.

Referenced by apply_result_on_server(), and handle_city().

## ◆ city_changed()

static void city_changed | ( | int | city_id | ) |

static

Callback for the agent interface.

Definition at line 447 of file cma_core.c.

Referenced by cma_init(), and handle_trade_route_info().

## ◆ city_remove()

static void city_remove | ( | int | city_id | ) |

static

Callback for the agent interface.

Definition at line 460 of file cma_core.c.

Referenced by cma_init().

## ◆ cma_apply_result()

bool cma_apply_result | ( | struct city * | pcity,
|  | const struct cm_result * | result
| ) |  |

Apply result on server if it's valid

Definition at line 508 of file cma_core.c.

Referenced by run_cma_once_callback().

## ◆ cma_get_parameter()

bool cma_get_parameter | ( | enum attr_city | attr,
|  | int | city_id,
|  | struct cm_parameter * | parameter
| ) |  |

Get the parameter.

Don't bother to cm_init_parameter(), since we set all the fields anyway. But leave the comment here so we can find this place when searching for all the creators of a parameter.

Definition at line 573 of file cma_core.c.

Referenced by check_city(), cma_is_city_under_agent(), and cmafec_get_fe_parameter().

## ◆ cma_init()

void cma_init | ( | void |  | ) |

Initialize city governor code

Definition at line 477 of file cma_core.c.

Referenced by agents_init().

## ◆ cma_is_city_under_agent()

bool cma_is_city_under_agent | ( | const struct city * | pcity,
|  | struct cm_parameter * | parameter
| ) |  |

Check whether city is under governor control, and fill parameter if it is.

Definition at line 550 of file cma_core.c.

Referenced by adjust_workers_button_pressed(), append_cma_to_menu_item(), button_down_citymap(), canvas_draw_cb(), canvas_exposed_cb(), city_dlg_callback(), cma_activate_preset_callback(), cma_active_callback(), cma_apply_result(), city_dialog::cma_double_clicked(), city_dialog::cma_enable(), city_dialog::cma_selected(), city_dialog::cma_slider(), city_dialog::cma_toggle_changed(), cmafec_get_fe_parameter(), cmafec_get_short_descr_of_city(), create_governor_menu(), enable_city_dlg_widgets(), factor_horiz_cma_callback(), hscale_changed(), ld_cma_callback(), left_button_down_citymap(), min_horiz_cma_callback(), city_label::mousePressEvent(), city_map::paintEvent(), popup_load_del_presets_dialog(), real_city_dialog_popup(), real_city_report_dialog_update_city(), real_info_city_report_dialog_update(), rebuild_citydlg_title_str(), redraw_city_dialog(), refresh_cma_dialog(), select_cma_callback(), select_governor_callback(), set_client_state(), update_city_cma_dialog(), city_dialog::update_cma_tab(), and city_dialog::update_sliders().

## ◆ cma_put_city_under_agent()

void cma_put_city_under_agent | ( | struct city * | pcity,
|  | const struct cm_parameter *const | parameter
| ) |  |

Put city under governor control

Definition at line 522 of file cma_core.c.

Referenced by button_press_callback(), button_press_callback(), cma_activate_preset_callback(), cma_active_callback(), city_dialog::cma_changed(), city_dialog::cma_double_clicked(), cma_iterate(), city_dialog::cma_selected(), city_widget::display_list_menu(), factor_horiz_cma_callback(), governors_iterate(), hscale_changed(), min_horiz_cma_callback(), and run_cma_callback().

## ◆ cma_release_city()

void cma_release_city | ( | struct city * | pcity | ) |

Release city from governor control.

Definition at line 540 of file cma_core.c.

Referenced by check_city(), cma_activate_preset_callback(), cma_active_callback(), city_dialog::cma_double_clicked(), city_dialog::cma_enable(), cma_iterate(), city_dialog::cma_selected(), city_widget::display_list_menu(), factor_horiz_cma_callback(), governors_iterate(), handle_city(), hscale_changed(), ld_cma_callback(), min_horiz_cma_callback(), popup_cma_from_city_report_callback(), popup_load_del_presets_dialog(), set_client_state(), and stop_cma_callback().

## ◆ cma_set_parameter()

void cma_set_parameter | ( | enum attr_city | attr,
|  | int | city_id,
|  | const struct cm_parameter * | parameter
| ) |  |

Set attribute block for city from parameter.

Definition at line 621 of file cma_core.c.

Referenced by cma_put_city_under_agent(), and cmafec_set_fe_parameter().

## ◆ fc_results_are_equal()

static bool fc_results_are_equal | ( | const struct cm_result * | result1,
|  | const struct cm_result * | result2
| ) |  |

static

Returns TRUE iff the two results are equal. Both results have to be results for the given city.

Definition at line 98 of file cma_core.c.

Referenced by apply_result_on_server().

## ◆ handle_city()

static void handle_city | ( | struct city * | pcity | ) |

static

The given city has changed. handle_city ensures that either the city follows the set CMA goal or that the CMA detaches itself from the city.

Definition at line 371 of file cma_core.c.

Referenced by city_changed().

## ◆ new_turn()

static void new_turn | ( | void |  | ) |

static

Callback for the agent interface.

Definition at line 468 of file cma_core.c.

Referenced by cma_init().

## ◆ release_city()

static void release_city | ( | int | city_id | ) |

static

Remove governor setting from city.

Definition at line 357 of file cma_core.c.

Referenced by city_remove(), and cma_release_city().

## ◆ report_stats()

static void report_stats | ( | void |  | ) |

static

Prints the data of the stats struct via log_test(...).

Definition at line 338 of file cma_core.c.

Referenced by new_turn().

## Variable Documentation

## ◆ apply_result_applied

int apply_result_applied

Definition at line 91 of file cma_core.c.

## ◆ apply_result_ignored

int apply_result_ignored

Definition at line 91 of file cma_core.c.

## ◆ refresh_forced

int refresh_forced

Definition at line 91 of file cma_core.c.

## ◆ [struct]

struct { ... } stats

Referenced by apply_result_on_server(), cma_init(), and report_stats().

## ◆ wall_timer

struct timer* wall_timer

Definition at line 90 of file cma_core.c.