Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/remove functions9 #1115

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ai/default/daicity.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
struct adv_data;
struct tech_vector;

struct ai_activity_cache; // defined and only used within aicity.c

// Who's coming to kill us, for attack co-ordination
struct ai_invasion {
int attack; // Units capable of attacking city
Expand Down
2 changes: 0 additions & 2 deletions client/cityrep.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
#include "cityrepdata.h"
#include "climisc.h"

#define NEG_VAL(x) ((x) < 0 ? (x) : (-x))
#define CMA_NONE (10000)
#define CMA_CUSTOM (10001)

class QHBoxLayout;
class QItemSelection;
Expand Down
1 change: 0 additions & 1 deletion client/climisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ cid cid_encode_building(const struct impr_type *pimprove);
cid cid_encode_from_city(const struct city *pcity);

struct universal cid_decode(cid cid);
#define cid_production cid_decode

bool city_unit_supported(const struct city *pcity,
const struct universal *target);
Expand Down
12 changes: 4 additions & 8 deletions client/mapctrl_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,16 @@ void key_city_overlay(int canvas_x, int canvas_y)
void key_city_show_open(struct city *pcity)
{
if (can_client_change_view() && pcity) {
if (pcity) {
pcity->client.city_opened = true;
refresh_city_mapcanvas(pcity, pcity->tile, true, false);
}
pcity->client.city_opened = true;
refresh_city_mapcanvas(pcity, pcity->tile, true, false);
}
}

void key_city_hide_open(struct city *pcity)
{
if (can_client_change_view() && pcity) {
if (pcity) {
pcity->client.city_opened = false;
refresh_city_mapcanvas(pcity, pcity->tile, true, false);
}
pcity->client.city_opened = false;
refresh_city_mapcanvas(pcity, pcity->tile, true, false);
}
}

Expand Down
1 change: 0 additions & 1 deletion client/mapview_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ extern struct view mapview;
* reenabled afterwards. */
extern bool can_slide;

#define BORDER_WIDTH 2
#define GOTO_WIDTH 2

/*
Expand Down
2 changes: 0 additions & 2 deletions client/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ extern const struct option_set *server_optset;

struct option *optset_option_by_number(const struct option_set *poptset,
int id);
#define optset_option_by_index optset_option_by_number
struct option *optset_option_by_name(const struct option_set *poptset,
const char *name);
struct option *optset_option_first(const struct option_set *poptset);
Expand All @@ -212,7 +211,6 @@ const char *optset_category_name(const struct option_set *poptset,
// Common option functions.
const struct option_set *option_optset(const struct option *poption);
int option_number(const struct option *poption);
#define option_index option_number
const char *option_name(const struct option *poption);
const char *option_description(const struct option *poption);
QString option_help_text(const struct option *poption);
Expand Down
32 changes: 2 additions & 30 deletions client/tradecalculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,8 @@ void trade_generator::discard()

for (int i = j; i > -j; i--) {
while ((tc = find_most_free())) {
if (!discard_one(tc)) {
if (!discard_any(tc, i)) {
break;
}
if (!discard_any(tc, i)) {
break;
}
}
}
Expand All @@ -287,32 +285,6 @@ void trade_generator::discard_trade(trade_city *tc, trade_city *ttc)
check_if_done(tc, ttc);
}

/**
Drops one trade route for given city if possible
*/
bool trade_generator::discard_one(trade_city *tc)
{
int best = 0;
int current_candidate = 0;
int best_id;
trade_city *ttc;

for (int i = cities.size() - 1; i >= 0; i--) {
ttc = cities.at(i);
current_candidate = ttc->over_max;
if (current_candidate > best) {
best_id = i;
}
}
if (best == 0) {
return false;
}
Q_UNREACHABLE();
ttc = cities.at(best_id);
discard_trade(tc, ttc);
return true;
}

/**
Drops all trade routes for given city
*/
Expand Down
1 change: 0 additions & 1 deletion client/tradecalculation.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class trade_generator {

private:
bool discard_any(trade_city *tc, int freeroutes);
bool discard_one(trade_city *tc);
int find_over_max(struct city *pcity);
trade_city *find_most_free();
void check_if_done(trade_city *tc1, trade_city *tc2);
Expand Down
19 changes: 8 additions & 11 deletions common/aicore/caravan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ typedef bool (*search_callback)(void *data, const struct city *pcity,

static void caravan_search_from(const struct unit *caravan,
const struct caravan_parameter *param,
struct tile *start_tile, int turns_before,
struct tile *start_tile,
int moves_left_before, bool omniscient,
search_callback callback,
void *callback_data)
Expand All @@ -124,7 +124,7 @@ static void caravan_search_from(const struct unit *caravan,
struct pf_parameter pfparam;
int end_time;

end_time = param->horizon - turns_before;
end_time = param->horizon;

// Initialize the pf run.
pft_fill_unit_parameter(&pfparam, const_cast<struct unit *>(caravan));
Expand All @@ -148,9 +148,7 @@ static void caravan_search_from(const struct unit *caravan,
}

pcity = tile_city(pos.tile);
if (pcity
&& callback(callback_data, pcity, turns_before + pos.turn,
pos.moves_left)) {
if (pcity && callback(callback_data, pcity, pos.turn, pos.moves_left)) {
break;
}
}
Expand Down Expand Up @@ -540,8 +538,8 @@ static bool cfbdw_callback(void *vdata, const struct city *dest,
*/
static void caravan_find_best_destination_withtransit(
const struct unit *caravan, const struct caravan_parameter *param,
const struct city *src, int turns_before, int moves_left,
bool omniscient, struct caravan_result *result)
const struct city *src, int moves_left, bool omniscient,
struct caravan_result *result)
{
Q_UNUSED(moves_left)
struct tile *start_tile;
Expand All @@ -558,9 +556,8 @@ static void caravan_find_best_destination_withtransit(
start_tile = unit_tile(caravan);
}

caravan_search_from(caravan, param, start_tile, turns_before,
caravan->moves_left, omniscient, cfbdw_callback,
&data);
caravan_search_from(caravan, param, start_tile, caravan->moves_left,
omniscient, cfbdw_callback, &data);
}

/**
Expand All @@ -581,6 +578,6 @@ void caravan_find_best_destination(const struct unit *caravan,
fc_assert(src != nullptr);

caravan_find_best_destination_withtransit(
caravan, parameter, src, 0, caravan->moves_left, omniscient, result);
caravan, parameter, src, caravan->moves_left, omniscient, result);
}
}
29 changes: 0 additions & 29 deletions common/aicore/path_finding.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,6 @@
* // do something
* } pf_map_positions_iterate_end;
*
* 4) information about the whole path (leading to the next nearest
* position):
* pf_map_paths_iterate(pfm, path, true) {
* // do something
* pf_path_destroy(path);
* } pf_map_paths_iterate_end;
*
* The third argument passed to the iteration macros is a condition that
* controls if the start tile of the pf_parameter should iterated or not.
*
Expand Down Expand Up @@ -573,25 +566,3 @@ bool pf_reverse_map_unit_position(struct pf_reverse_map *pfrm,
while (pf_map_iterate(_MY_pf_map_)) \
; \
}

/* This macro iterates all possible pathes.
* NB: you need to free the pathes with pf_path_destroy(path_iter).
*
* ARG_pfm - A pf_map structure pointer.
* NAME_path - The name of the iterator to use (type PFPath *). This
* is defined inside the macro.
* COND_from_start - A boolean value (or equivalent, it can be a function)
* which indicate if the start tile should be iterated or
* not. */
#define pf_map_paths_iterate(ARG_pfm, NAME_path, COND_from_start) \
if (COND_from_start || pf_map_iterate((ARG_pfm))) { \
struct pf_map *_MY_pf_map_ = (ARG_pfm); \
PFPath *NAME_path; \
do { \
NAME_path = pf_map_iter_path(_MY_pf_map_);

#define pf_map_paths_iterate_end \
} \
while (pf_map_iterate(_MY_pf_map_)) \
; \
}
42 changes: 3 additions & 39 deletions common/clientutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@ struct actcalc {

/**
Calculate completion time for all unit activities on tile.
If pmodunit is supplied, take into account the effect if it changed to
doing new_act on new_tgt instead of whatever it's currently doing (if
anything).
*/
static void calc_activity(struct actcalc *calc, const struct tile *ptile,
const struct unit *pmodunit,
Activity_type_id new_act,
const struct extra_type *new_tgt)
Activity_type_id new_act)
{
// This temporary working state is a bit big to allocate on the stack
struct tmp_state {
Expand All @@ -62,7 +57,7 @@ static void calc_activity(struct actcalc *calc, const struct tile *ptile,
{
Activity_type_id act = punit->activity;

if (punit == pmodunit) {
if (punit == nullptr) {
// We'll account for this one later
continue;
}
Expand All @@ -87,37 +82,6 @@ static void calc_activity(struct actcalc *calc, const struct tile *ptile,
}
unit_list_iterate_end;

/* Hypothetical contribution from pmodunit, if it changed to specified
* activity/target */
if (pmodunit) {
if (is_build_activity(new_act, ptile)) {
int eidx = extra_index(new_tgt);

if (new_act == pmodunit->changed_from
&& new_tgt == pmodunit->changed_from_target) {
t->extra_total[eidx][new_act] += pmodunit->changed_from_count;
}
t->extra_total[eidx][new_act] += get_activity_rate_this_turn(pmodunit);
t->extra_units[eidx][new_act] += get_activity_rate(pmodunit);
} else if (is_clean_activity(new_act)) {
int eidx = extra_index(new_tgt);

if (new_act == pmodunit->changed_from
&& new_tgt == pmodunit->changed_from_target) {
t->rmextra_total[eidx][new_act] += pmodunit->changed_from_count;
}
t->rmextra_total[eidx][new_act] +=
get_activity_rate_this_turn(pmodunit);
t->rmextra_units[eidx][new_act] += get_activity_rate(pmodunit);
} else {
if (new_act == pmodunit->changed_from) {
t->activity_total[new_act] += pmodunit->changed_from_count;
}
t->activity_total[new_act] += get_activity_rate_this_turn(pmodunit);
t->activity_units[new_act] += get_activity_rate(pmodunit);
}
}

// Turn activity counts into turn estimates
activity_type_iterate(act)
{
Expand Down Expand Up @@ -188,7 +152,7 @@ QString concat_tile_activity_text(struct tile *ptile)
int num_activities = 0;
QString str;

calc_activity(calc, ptile, nullptr, ACTIVITY_LAST, nullptr);
calc_activity(calc, ptile, ACTIVITY_LAST);

activity_type_iterate(i)
{
Expand Down
1 change: 0 additions & 1 deletion common/extras.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ struct extra_type *extra_type_by_translated_name(const char *name);

#define extra_base_get(_e_) (_e_)->data.base
#define extra_road_get(_e_) (_e_)->data.road
#define extra_resource_get(_e_) (_e_)->data.resource

void extra_to_caused_by_list(struct extra_type *pextra,
enum extra_cause cause);
Expand Down
4 changes: 0 additions & 4 deletions common/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,6 @@ extern struct world wld;
#define RS_MIN_CITY_CENTER_OUTPUT 0
#define RS_MAX_CITY_CENTER_OUTPUT RS_MAX_VALUE

#define RS_DEFAULT_CITIES_MIN_DIST 2
#define RS_MIN_CITIES_MIN_DIST 1
#define RS_MAX_CITIES_MIN_DIST RS_MAX_VALUE

// the constants CITY_MAP_*_RADIUS are defined in city.c
#define RS_DEFAULT_CITY_RADIUS_SQ CITY_MAP_DEFAULT_RADIUS_SQ
#define RS_MIN_CITY_RADIUS_SQ CITY_MAP_MIN_RADIUS_SQ
Expand Down
17 changes: 0 additions & 17 deletions common/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,6 @@ bool map_startpos_remove(struct tile *ptile);
*(pnat_x) = 2 * (map_x) - *(pnat_y)) \
: (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))

/* Provide a block to convert from map to native coordinates. This allows
* you to use a native version of the map position within the block. Note
* that the native position is declared as const and can't be changed
* inside the block. */
#define do_in_native_pos(nat_x, nat_y, map_x, map_y) \
{ \
int _nat_x, _nat_y; \
MAP_TO_NATIVE_POS(&_nat_x, &_nat_y, map_x, map_y); \
{ \
const int nat_x = _nat_x, nat_y = _nat_y;

#define do_in_native_pos_end \
} \
}

/* Provide a block to convert from map to natural coordinates. This allows
* you to use a natural version of the map position within the block. Note
* that the natural position is declared as const and can't be changed
Expand All @@ -167,8 +152,6 @@ bool map_startpos_remove(struct tile *ptile);
}

// Width and height of the map, in native coordinates.
#define NATIVE_WIDTH wld.map.xsize
#define NATIVE_HEIGHT wld.map.ysize

// Width and height of the map, in natural coordinates.
#define NATURAL_WIDTH (MAP_IS_ISOMETRIC ? 2 * wld.map.xsize : wld.map.xsize)
Expand Down
2 changes: 0 additions & 2 deletions common/map_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*****************************************************************/
#define terrain_misc packet_ruleset_terrain_control

// Some types used below.
struct nation_hash;
struct nation_type;
struct packet_edit_startpos_full;

Expand Down
13 changes: 0 additions & 13 deletions common/requirements.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,6 @@ bool universal_is_relevant_to_requirement(const struct requirement *req,
sv_universal_fulfills_requirements( \
false, (_rqs_), \
(struct universal){.value = {.utype = (_ut_)}, .kind = VUT_UTYPE})
#define requirement_fulfilled_by_extra(_ex_, _rqs_) \
sv_universal_fulfills_requirements( \
false, (_rqs_), \
(struct universal){.value = {.extra = (_ex_)}, .kind = VUT_EXTRA})
#define requirement_fulfilled_by_output_type(_o_, _rqs_) \
sv_universal_fulfills_requirements( \
false, (_rqs_), \
(struct universal){.value = {.outputtype = (_o_)}, \
.kind = VUT_OTYPE})
#define requirement_fulfilled_by_action(_act_, _rqs_) \
sv_universal_fulfills_requirements( \
false, (_rqs_), \
(struct universal){.value = {.action = (_act_)}, .kind = VUT_ACTION})

#define requirement_needs_improvement(_imp_, _rqs_) \
sv_universal_fulfills_requirements( \
Expand Down
2 changes: 1 addition & 1 deletion common/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ int basic_city_style_for_style(struct nation_style *pstyle)
requirement_vector_iterate(&city_styles[i].reqs, preq)
{
if (preq->source.kind == VUT_STYLE
&& preq->source.value.style == pstyle && style_style != TRI_NO) {
&& preq->source.value.style == pstyle) {
style_style = TRI_YES;
} else {
/* No any other requirements allowed at the moment.
Expand Down
Loading