Project

General

Profile

Feature #993 » 0031-Unhardcode-wld.map-from-can_city_build_now.patch

S3_2 - Marko Lindqvist, 10/20/2024 03:34 AM

View differences:

client/citydlg_common.c
}
/* If it can be built... */
if (can_city_build_now(pcity, &target)) {
if (can_city_build_now(&(wld.map), pcity, &target)) {
/* ...but we're not yet building it, then switch. */
if (!same_as_current_build) {
/* Change the current target */
client/climisc.c
connection_do_buffer(&client.conn);
city_list_iterate (client.conn.playing->cities, pcity) {
if (are_universals_equal(&pcity->production, from)
&& can_city_build_now(pcity, to)) {
&& can_city_build_now(&(wld.map), pcity, to)) {
city_change_production(pcity, to);
}
} city_list_iterate_end;
......
&& city_has_building(pcity, target->value.building);
}
/**********************************************************************//**
A TestCityFunc wrapper for can_city_build_now()
**************************************************************************/
bool can_city_build_now_client(const struct city *pcity,
const struct universal *target)
{
return can_city_build_now(&(wld.map), pcity, target);
}
/**********************************************************************//**
Return the numerical "section" of an item. This is used for sorting.
**************************************************************************/
client/climisc.h
const struct universal *target);
bool city_building_present(const struct city *pcity,
const struct universal *target);
bool can_city_build_now_client(const struct city *pcity,
const struct universal *target);
struct item {
struct universal item;
client/gui-gtk-3.22/citydlg.c
name_and_sort_items(targets, targets_used, items, FALSE, pcity);
for (item = 0; item < targets_used; item++) {
if (can_city_build_now(pcity, &items[item].item)) {
if (can_city_build_now(&(wld.map), pcity, &items[item].item)) {
const char *name;
struct sprite* sprite;
GdkPixbuf *pix;
client/gui-gtk-3.22/cityrep.c
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(change_improvements_item),
FALSE, FALSE, CO_CHANGE,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(change_units_item),
TRUE, FALSE, CO_CHANGE,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(change_wonders_item),
FALSE, TRUE, CO_CHANGE,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
}
......
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(last_improvements_item),
FALSE, FALSE, CO_LAST,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(last_units_item),
TRUE, FALSE, CO_LAST,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(last_wonders_item),
FALSE, TRUE, CO_LAST,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
}
......
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(first_improvements_item),
FALSE, FALSE, CO_FIRST,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(first_units_item),
TRUE, FALSE, CO_FIRST,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(first_wonders_item),
FALSE, TRUE, CO_FIRST,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
}
......
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(next_improvements_item),
FALSE, FALSE, CO_NEXT,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(next_units_item),
TRUE, FALSE, CO_NEXT,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(next_wonders_item),
FALSE, TRUE, CO_NEXT,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
}
......
item = next_to_last_improvements_item;
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(item),
FALSE, FALSE, CO_NEXT_TO_LAST,
can_city_build_now,
can_city_build_now_client,
callback, n);
item = next_to_last_units_item;
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(item),
TRUE, FALSE, CO_NEXT_TO_LAST,
can_city_build_now,
can_city_build_now_client,
callback, n);
item = next_to_last_wonders_item;
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(item),
FALSE, TRUE, CO_NEXT_TO_LAST,
can_city_build_now,
can_city_build_now_client,
callback, n);
}
......
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(select_improvements_item),
FALSE, FALSE, CO_NONE,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), -1);
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(select_units_item),
TRUE, FALSE, CO_NONE,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), -1);
append_impr_or_unit_to_menu_item(GTK_MENU_ITEM(select_wonders_item),
FALSE, TRUE, CO_NONE,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), -1);
append_cma_to_menu_item(GTK_MENU_ITEM(select_cma_item), FALSE);
client/gui-gtk-4.0/citydlg.c
name_and_sort_items(targets, targets_used, items, FALSE, pcity);
for (item = 0; item < targets_used; item++) {
if (can_city_build_now(pcity, &items[item].item)) {
if (can_city_build_now(&(wld.map), pcity, &items[item].item)) {
const char *name;
struct sprite *sprite;
GdkPixbuf *pix;
client/gui-gtk-4.0/cityrep.c
submenu = g_menu_new();
append_impr_or_unit_to_menu(submenu, group, mname, "_u",
TRUE, FALSE, oper,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
fc_snprintf(buf, sizeof(buf), human_mname, _("Unit"));
submenu_append_unref(menu, buf, G_MENU_MODEL(submenu));
......
submenu = g_menu_new();
append_impr_or_unit_to_menu(submenu, group, mname, "_i",
FALSE, FALSE, oper,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
fc_snprintf(buf, sizeof(buf), human_mname, _("Improvement"));
submenu_append_unref(menu, buf, G_MENU_MODEL(submenu));
......
submenu = g_menu_new();
append_impr_or_unit_to_menu(submenu, group, mname, "_w",
FALSE, TRUE, oper,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), n);
fc_snprintf(buf, sizeof(buf), human_mname, _("Wonder"));
submenu_append_unref(menu, buf, G_MENU_MODEL(submenu));
......
unit_a_select_menu = g_menu_new();
append_impr_or_unit_to_menu(unit_a_select_menu, group, "sel", "_a_u",
TRUE, FALSE, CO_NONE,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), -1);
fc_snprintf(buf, sizeof(buf), _("Available %s"), _("Unit"));
submenu_append_unref(select_menu, buf, G_MENU_MODEL(unit_a_select_menu));
......
impr_a_select_menu = g_menu_new();
append_impr_or_unit_to_menu(impr_a_select_menu, group, "sel", "_a_b",
FALSE, FALSE, CO_NONE,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), -1);
fc_snprintf(buf, sizeof(buf), _("Available %s"), _("Improvement"));
submenu_append_unref(select_menu, buf, G_MENU_MODEL(impr_a_select_menu));
......
wndr_a_select_menu = g_menu_new();
append_impr_or_unit_to_menu(wndr_a_select_menu, group, "sel", "_a_w",
FALSE, TRUE, CO_NONE,
can_city_build_now,
can_city_build_now_client,
G_CALLBACK(select_impr_or_unit_callback), -1);
fc_snprintf(buf, sizeof(buf), _("Available %s"), _("Wonder"));
submenu_append_unref(select_menu, buf, G_MENU_MODEL(wndr_a_select_menu));
client/gui-qt/citydlg.cpp
name_and_sort_items(targets, targets_used, items, false, dlgcity);
for (item = 0; item < targets_used; item++) {
if (can_city_build_now(dlgcity, &items[item].item)) {
if (can_city_build_now(&(wld.map), dlgcity, &items[item].item)) {
prod_list << cid_encode(items[item].item);
}
}
......
name_and_sort_items(targets, targets_used, items, false, mcity);
for (item = 0; item < targets_used; item++) {
if (future_t || can_city_build_now(mcity, &items[item].item)) {
if (future_t || can_city_build_now(&(wld.map), mcity, &items[item].item)) {
renegade = new universal(items[item].item);
// Renagade deleted in production_item destructor
// Renegade deleted in production_item destructor
if (VUT_UTYPE == renegade->kind) {
str = utype_name_translation(renegade->value.utype);
sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
client/gui-qt/cityrep.cpp
if (!selected_cities.isEmpty()) {
some_menu = list_menu->addMenu(_("Production"));
tmp_menu = some_menu->addMenu(_("Change"));
fill_production_menus(CHANGE_PROD_NOW, custom_labels, can_city_build_now,
fill_production_menus(CHANGE_PROD_NOW, custom_labels, can_city_build_now_client,
tmp_menu);
tmp_menu = some_menu->addMenu(_("Add next"));
fill_production_menus(CHANGE_PROD_NEXT, custom_labels, can_city_build_now,
fill_production_menus(CHANGE_PROD_NEXT, custom_labels, can_city_build_now_client,
tmp_menu);
tmp_menu = some_menu->addMenu(_("Add before last"));
fill_production_menus(CHANGE_PROD_BEF_LAST, custom_labels,
can_city_build_now, tmp_menu);
can_city_build_now_client, tmp_menu);
tmp_menu = some_menu->addMenu(_("Add last"));
fill_production_menus(CHANGE_PROD_LAST, custom_labels, can_city_build_now,
fill_production_menus(CHANGE_PROD_LAST, custom_labels, can_city_build_now_client,
tmp_menu);
tmp_menu = some_menu->addMenu(_("Worklist"));
......
clearSelection();
}
need_clear = false;
if (can_city_build_now(iter_city, &target)) {
if (can_city_build_now(&(wld.map), iter_city, &target)) {
select_city(iter_city);
}
break;
......
clearSelection();
}
need_clear = false;
if (can_city_build_now(iter_city, &target)) {
if (can_city_build_now(&(wld.map), iter_city, &target)) {
select_city(iter_city);
}
break;
......
clearSelection();
}
need_clear = false;
if (can_city_build_now(iter_city, &target)) {
if (can_city_build_now(&(wld.map), iter_city, &target)) {
select_city(iter_city);
}
break;
......
menu->addSeparator();
tmp_menu = menu->addMenu(_("Available Units"));
gen_production_labels(SELECT_AVAIL_UNITS, custom_labels, true, false,
can_city_build_now, true);
can_city_build_now_client, true);
fill_data(SELECT_AVAIL_UNITS, custom_labels, tmp_menu);
tmp_menu = menu->addMenu(_("Available Improvements"));
gen_production_labels(SELECT_AVAIL_IMPR, custom_labels, false, false,
can_city_build_now, true);
can_city_build_now_client, true);
fill_data(SELECT_AVAIL_IMPR, custom_labels, tmp_menu);
tmp_menu = menu->addMenu(_("Available Wonders"));
gen_production_labels(SELECT_AVAIL_WONDERS, custom_labels, false, true,
can_city_build_now, true);
can_city_build_now_client, true);
fill_data(SELECT_AVAIL_WONDERS, custom_labels, tmp_menu);
}
/***********************************************************************//**
client/mapctrl_common.c
static void clipboard_send_production_packet(struct city *pcity)
{
if (are_universals_equal(&pcity->production, &clipboard)
|| !can_city_build_now(pcity, &clipboard)) {
|| !can_city_build_now(&(wld.map), pcity, &clipboard)) {
return;
}
common/city.c
Returns whether city can immediately build given target,
unit or improvement. This considers obsolete targets no longer buildable.
**************************************************************************/
bool can_city_build_now(const struct city *pcity,
bool can_city_build_now(const struct civ_map *nmap,
const struct city *pcity,
const struct universal *target)
{
const struct civ_map *nmap = &(wld.map);
switch (target->kind) {
case VUT_UTYPE:
return can_city_build_unit_now(nmap, pcity, target->value.utype);
common/city.h
const struct universal *target);
bool can_city_build_later(const struct city *pcity,
const struct universal *target);
bool can_city_build_now(const struct city *pcity,
bool can_city_build_now(const struct civ_map *nmap,
const struct city *pcity,
const struct universal *target);
int city_unit_slots_available(const struct city *pcity);
server/cityhand.c
{
struct universal prod;
struct city *pcity = player_city_by_number(pplayer, city_id);
const struct civ_map *nmap = &(wld.map);
if (!universals_n_is_valid(production_kind)) {
log_error("[%s] bad production_kind %d.", __FUNCTION__,
......
return;
}
if (!can_city_build_now(pcity, &prod)) {
if (!can_city_build_now(nmap, pcity, &prod)) {
return;
}
if (!city_can_change_build(pcity)) {
server/citytools.c
int central_units[ul_size + 1];
bv_player *could_see_unit = NULL;
int i;
const struct civ_map *nmap = &(wld.map);
fc_assert_ret_val(pgiver != ptaker, TRUE);
......
/* Set production to something valid for pplayer, if not.
* (previously allowed building obsolete units.) */
if (!can_city_build_now(pcity, &pcity->production)) {
if (!can_city_build_now(nmap, pcity, &pcity->production)) {
advisor_choose_build(ptaker, pcity);
}
server/cityturn.c
}
if (worklist_peek_ith(pwl, &target, i)) {
success = can_city_build_now(pcity, &target);
success = can_city_build_now(nmap, pcity, &target);
} else {
success = FALSE;
}
(2-2/3)