Project

General

Profile

Feature #139 » 0013-Unhardcode-wld.map-from-unit_transform_result.patch

S3_1 - Marko Lindqvist, 01/07/2024 09:02 AM

View differences:

client/gui-gtk-3.0/menu.c
units_can_do_action(punits, ACTION_DISBAND_UNIT,
TRUE));
menu_entry_set_sensitive("UNIT_UPGRADE",
units_can_upgrade(punits));
units_can_upgrade(&(wld.map), punits));
/* "UNIT_CONVERT" dealt with below */
menu_entry_set_sensitive("UNIT_HOMECITY",
can_units_do(punits, can_unit_change_homecity));
......
menus_rename("UNIT_UPGRADE", _("Upgr_ade"));
}
if (units_can_convert(punits)) {
if (units_can_convert(&(wld.map), punits)) {
menu_entry_set_sensitive("UNIT_CONVERT", TRUE);
if (units_all_same_type) {
struct unit *punit = unit_list_get(punits, 0);
/* TRANS: %s is a unit type. */
fc_snprintf(acttext, sizeof(acttext), _("C_onvert to %s"),
utype_name_translation(unit_type_get(punit)->converted_to));
client/gui-gtk-3.22/menu.c
units_can_do_action(punits, ACTION_DISBAND_UNIT,
TRUE));
menu_entry_set_sensitive("UNIT_UPGRADE",
units_can_upgrade(punits));
units_can_upgrade(&(wld.map), punits));
/* "UNIT_CONVERT" dealt with below */
menu_entry_set_sensitive("UNIT_HOMECITY",
can_units_do(punits, can_unit_change_homecity));
......
menus_rename("UNIT_UPGRADE", _("Upgr_ade"));
}
if (units_can_convert(punits)) {
if (units_can_convert(&(wld.map), punits)) {
menu_entry_set_sensitive("UNIT_CONVERT", TRUE);
if (units_all_same_type) {
struct unit *punit = unit_list_get(punits, 0);
/* TRANS: %s is a unit type. */
fc_snprintf(acttext, sizeof(acttext), _("C_onvert to %s"),
utype_name_translation(unit_type_get(punit)->converted_to));
client/gui-gtk-4.0/menu.c
ACTIVITY_SENTRY));
menu_entry_set_sensitive(map, "UNIT_HOMECITY",
can_units_do(punits, can_unit_change_homecity));
menu_entry_set_sensitive(map, "UNIT_UPGRADE", units_can_upgrade(punits));
menu_entry_set_sensitive(map, "UNIT_CONVERT", units_can_convert(punits));
menu_entry_set_sensitive(map, "UNIT_UPGRADE", units_can_upgrade(&(wld.map), punits));
menu_entry_set_sensitive(map, "UNIT_CONVERT", units_can_convert(&(wld.map), punits));
menu_entry_set_sensitive(map, "UNIT_DISBAND",
units_can_do_action(punits, ACTION_DISBAND_UNIT,
TRUE));
......
menus_rename(unit_menu, 13, "UNIT_UPGRADE", _("Upgr_ade"));
}
if (units_can_convert(punits)) {
if (units_can_convert(&(wld.map), punits)) {
if (units_all_same_type && num_units > 0) {
struct unit *punit = unit_list_get(punits, 0);
client/gui-qt/citydlg.cpp
unload_trans = NULL;
}
if (units_can_upgrade(qunits)) {
if (units_can_upgrade(&(wld.map), qunits)) {
upgrade = new QAction(_("Upgrade Unit"), this);
connect(upgrade, &QAction::triggered, this, &unit_item::upgrade_unit);
} else {
client/gui-qt/hudwidget.cpp
actions.append(a);
}
/* Set homecity */
// Set homecity
if (tile_city(unit_tile(current_unit))) {
if (can_unit_change_homecity_to(current_unit,
tile_city(unit_tile(current_unit)))) {
......
}
}
/* Upgrade */
if (UU_OK == unit_upgrade_test(current_unit, FALSE)) {
// Upgrade
if (UU_OK == unit_upgrade_test(&(wld.map), current_unit, FALSE)) {
a = new hud_action(this);
a->action_shortcut = SC_UPGRADE_UNIT;
a->set_pixmap(fc_icons::instance()->get_pixmap("upgrade"));
actions.append(a);
}
/* Automate */
// Automate
if (can_unit_do_autosettlers(current_unit)) {
a = new hud_action(this);
a->action_shortcut = SC_AUTOMATE;
......
actions.append(a);
}
/* Paradrop */
// Paradrop
if (can_unit_paradrop(current_unit)) {
a = new hud_action(this);
a->action_shortcut = SC_PARADROP;
client/gui-qt/menu.cpp
break;
case CONVERT:
if (units_can_convert(punits)) {
if (units_can_convert(&(wld.map), punits)) {
i.value()->setEnabled(true);
}
break;
......
break;
case UPGRADE:
if (units_can_upgrade(punits)) {
if (units_can_upgrade(&(wld.map), punits)) {
i.value()->setEnabled(true);
}
break;
client/gui-sdl2/dialogs.c
unit_upgrade_dlg = fc_calloc(1, sizeof(struct small_dialog));
unit_upgrade_result = unit_upgrade_info(punit, cbuf, sizeof(cbuf));
unit_upgrade_result = unit_upgrade_info(&(wld.map), punit, cbuf, sizeof(cbuf));
pstr = create_utf8_from_char_fonto(_("Upgrade Obsolete Units"),
FONTO_ATTENTION);
client/gui-sdl2/menu.c
local_hide(ID_UNIT_ORDER_UPGRADE);
}
if (unit_can_convert(punit)) {
if (unit_can_convert(&(wld.map), punit)) {
local_show(ID_UNIT_ORDER_CONVERT);
} else {
local_hide(ID_UNIT_ORDER_CONVERT);
client/text.c
fc_snprintf(buf, bufsz, _("No units to upgrade!"));
return FALSE;
} else if (unit_list_size(punits) == 1) {
return (UU_OK == unit_upgrade_info(unit_list_front(punits), buf, bufsz));
return (UU_OK == unit_upgrade_info(&(wld.map), unit_list_front(punits), buf, bufsz));
} else {
int upgrade_cost = 0;
int num_upgraded = 0;
......
unit_list_iterate(punits, punit) {
if (unit_owner(punit) == client_player()
&& UU_OK == unit_upgrade_test(punit, FALSE)) {
&& UU_OK == unit_upgrade_test(&(wld.map), punit, FALSE)) {
const struct unit_type *from_unittype = unit_type_get(punit);
const struct unit_type *to_unittype = can_upgrade_unittype(client.conn.playing,
from_unittype);
common/actions.c
const struct city *homecity)
{
enum action_result result = paction->result;
const struct civ_map *nmap = &(wld.map);
if (actor == NULL) {
actor = req_context_empty();
......
case ACTRES_CONVERT:
/* Reason: Keep the old rules. */
/* Info leak: The player knows their unit's cargo and location. */
if (!unit_can_convert(actor->unit)) {
if (!unit_can_convert(nmap, actor->unit)) {
return TRI_NO;
}
break;
......
* of cargo, they can predict if there will be enough room in the unit
* upgraded to, as long as they know what unit type their unit will end
* up as. */
if (unit_upgrade_test(actor->unit, FALSE) != UU_OK) {
if (unit_upgrade_test(nmap, actor->unit, FALSE) != UU_OK) {
return TRI_NO;
}
common/scriptcore/api_game_methods.c
bool api_methods_unit_can_upgrade(lua_State *L, Unit *punit, bool is_free)
{
return UU_OK == unit_upgrade_test(punit, is_free);
return UU_OK == unit_upgrade_test(&(wld.map), punit, is_free);
}
/**********************************************************************//**
......
LUASCRIPT_CHECK_SELF(L, punit, NULL);
LUASCRIPT_CHECK_ARG_NIL(L, ptype, 3, Unit_Type, NULL);
uu = unit_transform_result(punit, ptype);
uu = unit_transform_result(&(wld.map), punit, ptype);
switch (uu) {
case UU_OK:
return NULL;
common/unit.c
in result.
**************************************************************************/
enum unit_upgrade_result
unit_transform_result(const struct unit *punit,
unit_transform_result(const struct civ_map *nmap,
const struct unit *punit,
const struct unit_type *to_unittype)
{
fc_assert_ret_val(NULL != to_unittype, UU_NO_UNITTYPE);
......
utype_class(to_unittype))) {
return UU_UNSUITABLE_TRANSPORT;
}
} else if (!can_exist_at_tile(&(wld.map), to_unittype, unit_tile(punit))) {
} else if (!can_exist_at_tile(nmap, to_unittype, unit_tile(punit))) {
/* The new unit type can't survive on this terrain. */
return UU_NOT_TERRAIN;
}
......
Note that this function is strongly tied to unittools.c:transform_unit().
**************************************************************************/
enum unit_upgrade_result unit_upgrade_test(const struct unit *punit,
enum unit_upgrade_result unit_upgrade_test(const struct civ_map *nmap,
const struct unit *punit,
bool is_free)
{
struct player *pplayer = unit_owner(punit);
......
return UU_NOT_IN_CITY;
}
if (city_owner(pcity) != pplayer) {
/* TODO: should upgrades in allied cities be possible? */
/* TODO: Should upgrades in allied cities be possible? */
return UU_NOT_CITY_OWNER;
}
}
/* TODO: allow transported units to be reassigned. Check here
/* TODO: Allow transported units to be reassigned. Check here
* and make changes to upgrade_unit. */
return unit_transform_result(punit, to_unittype);
return unit_transform_result(nmap, punit, to_unittype);
}
/**********************************************************************//**
Tests if unit can be converted to another type.
**************************************************************************/
bool unit_can_convert(const struct unit *punit)
bool unit_can_convert(const struct civ_map *nmap,
const struct unit *punit)
{
const struct unit_type *tgt = unit_type_get(punit)->converted_to;
......
return FALSE;
}
return UU_OK == unit_transform_result(punit, tgt);
return UU_OK == unit_transform_result(nmap, punit, tgt);
}
/**********************************************************************//**
Find the result of trying to upgrade the unit, and a message that
most callers can use directly.
**************************************************************************/
enum unit_upgrade_result unit_upgrade_info(const struct unit *punit,
enum unit_upgrade_result unit_upgrade_info(const struct civ_map *nmap,
const struct unit *punit,
char *buf, size_t bufsz)
{
struct player *pplayer = unit_owner(punit);
enum unit_upgrade_result result = unit_upgrade_test(punit, FALSE);
enum unit_upgrade_result result = unit_upgrade_test(nmap, punit, FALSE);
int upgrade_cost;
const struct unit_type *from_unittype = unit_type_get(punit);
const struct unit_type *to_unittype = can_upgrade_unittype(pplayer,
common/unit.h
const struct tile *ptile);
enum unit_upgrade_result
unit_transform_result(const struct unit *punit,
unit_transform_result(const struct civ_map *nmap,
const struct unit *punit,
const struct unit_type *to_unittype);
enum unit_upgrade_result unit_upgrade_test(const struct unit *punit,
enum unit_upgrade_result unit_upgrade_test(const struct civ_map *nmap,
const struct unit *punit,
bool is_free);
enum unit_upgrade_result unit_upgrade_info(const struct unit *punit,
enum unit_upgrade_result unit_upgrade_info(const struct civ_map *nmap,
const struct unit *punit,
char *buf, size_t bufsz);
bool unit_can_convert(const struct unit *punit);
bool unit_can_convert(const struct civ_map *nmap, const struct unit *punit);
int unit_pays_mp_for_action(const struct action *paction,
const struct unit *punit);
common/unitlist.c
Return TRUE iff any of the units can be upgraded to another unit type
(for money)
****************************************************************************/
bool units_can_upgrade(const struct unit_list *punits)
bool units_can_upgrade(const struct civ_map *nmap,
const struct unit_list *punits)
{
unit_list_iterate(punits, punit) {
if (UU_OK == unit_upgrade_test(punit, FALSE)) {
if (UU_OK == unit_upgrade_test(nmap, punit, FALSE)) {
return TRUE;
}
} unit_list_iterate_end;
......
/************************************************************************//**
Return TRUE iff any of the units can convert to another unit type
****************************************************************************/
bool units_can_convert(const struct unit_list *punits)
bool units_can_convert(const struct civ_map *nmap,
const struct unit_list *punits)
{
unit_list_iterate(punits, punit) {
if (utype_can_do_action(unit_type_get(punit), ACTION_CONVERT)
&& unit_can_convert(punit)) {
&& unit_can_convert(nmap, punit)) {
return TRUE;
}
} unit_list_iterate_end;
common/unitlist.h
bool units_have_activity_on_tile(const struct unit_list *punits,
enum unit_activity activity);
bool units_can_upgrade(const struct unit_list *punits);
bool units_can_convert(const struct unit_list *punits);
bool units_can_upgrade(const struct civ_map *nmap,
const struct unit_list *punits);
bool units_can_convert(const struct civ_map *nmap,
const struct unit_list *punits);
#ifdef __cplusplus
}
server/scripting/api_server_edit.c
ur_transform_unit(struct unit *punit, const struct unit_type *to_unit,
int vet_loss)
{
if (UU_OK == unit_transform_result(punit, to_unit)) {
if (UU_OK == unit_transform_result(&(wld.map), punit, to_unit)) {
/* Avoid getting overt veteranship if a user requests increasing it */
if (vet_loss < 0) {
int vl = utype_veteran_levels(to_unit);
server/unithand.c
&& unit_perform_action(pplayer, punit->id, pcity->id, 0, "",
paction->id, ACT_REQ_SS_AGENT)) {
number_of_upgraded_units++;
} else if (UU_NO_MONEY == unit_upgrade_test(punit, FALSE)) {
} else if (UU_NO_MONEY == unit_upgrade_test(&(wld.map), punit, FALSE)) {
break;
}
}
......
} else {
switch (paction->result) {
case ACTRES_UPGRADE_UNIT:
action_custom = unit_upgrade_test(punit, FALSE);
action_custom = unit_upgrade_test(nmap, punit, FALSE);
break;
case ACTRES_AIRLIFT:
action_custom = test_unit_can_airlift_to(nmap, NULL, punit, target_city);
server/unittools.c
unit_list_iterate(pplayer->units, punit) {
/* We have to be careful not to strand units at sea, for example by
* upgrading a frigate to an ironclad while it was carrying a unit. */
if (UU_OK == unit_upgrade_test(punit, TRUE)) {
if (UU_OK == unit_upgrade_test(&(wld.map), punit, TRUE)) {
unit_list_prepend(candidates, punit); /* Potential candidate :) */
}
} unit_list_iterate_end;
......
from_type = unit_type_get(punit);
to_type = from_type->converted_to;
if (unit_can_convert(punit)) {
if (unit_can_convert(&(wld.map), punit)) {
transform_unit(punit, to_type, 0);
notify_player(unit_owner(punit), unit_tile(punit),
E_UNIT_UPGRADED, ftc_server,
(3-3/3)