[Freeciv-Dev] (PR#13513) encapsulate the unit_types array
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13513 >
This patch:
1. Encapsulates the unit_types array, making it static in unittype.c.
2. Changes all callers to use get_unit_type.
-jason
Index: ai/advmilitary.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v
retrieving revision 1.193
diff -p -u -r1.193 advmilitary.c
--- ai/advmilitary.c 22 Jul 2005 16:18:04 -0000 1.193
+++ ai/advmilitary.c 22 Jul 2005 16:29:51 -0000
@@ -814,7 +814,7 @@ static void process_attacker_want(struct
/* The enemy city. acity == NULL means stray enemy unit */
struct city *acity = tile_get_city(ptile);
bool shore = is_ocean_near_tile(pcity->tile);
- int orig_move_type = unit_types[best_choice->choice].move_type;
+ int orig_move_type = get_unit_type(best_choice->choice)->move_type;
int victim_count = 1;
int needferry = 0;
bool unhap = ai_assess_military_unhappiness(pcity,
@@ -1158,19 +1158,20 @@ static void kill_something_with(struct p
/* We want attacker more than what we have selected before */
copy_if_better_choice(&best_choice, choice);
CITY_LOG(LOG_DEBUG, pcity, "ksw: %s has chosen attacker, %s, want=%d",
- pcity->name, unit_types[choice->choice].name, choice->want);
+ pcity->name, get_unit_type(choice->choice)->name, choice->want);
if (go_by_boat && !ferryboat) { /* need a new ferry */
/* We might need a new boat even if there are boats free,
* if they are blockaded or in inland seas*/
assert(is_ground_unit(myunit));
ai_choose_role_unit(pplayer, pcity, choice, L_FERRYBOAT, choice->want);
- if (SEA_MOVING == unit_types[choice->choice].move_type) {
+ if (SEA_MOVING == get_unit_type(choice->choice)->move_type) {
struct ai_data *ai = ai_data_get(pplayer);
freelog(LOG_DEBUG,
"%s has chosen attacker ferry, %s, want=%d, %d of %d free",
- pcity->name, unit_types[choice->choice].name, choice->want,
+ pcity->name, get_unit_type(choice->choice)->name,
+ choice->want,
ai->stats.available_boats, ai->stats.boats);
} /* else can not build ferries yet */
}
@@ -1373,7 +1374,8 @@ void military_advisor_choose_build(struc
} else if (danger > 0 && num_defenders <= urgency) {
/* Consider building defensive units units */
process_defender_want(pplayer, pcity, danger, choice);
- if (urgency == 0 && unit_types[choice->choice].defense_strength == 1) {
+ if (urgency == 0
+ && get_unit_type(choice->choice)->defense_strength == 1) {
if (get_city_bonus(pcity, EFT_LAND_REGEN) > 0) {
/* unlikely */
choice->want = MIN(49, danger);
@@ -1455,7 +1457,7 @@ void military_advisor_choose_build(struc
CITY_LOG(LOGLEVEL_BUILD, pcity, "military advisor has no advice");
} else if (is_unit_choice_type(choice->type)) {
CITY_LOG(LOGLEVEL_BUILD, pcity, "military advisor choice: %s (want %d)",
- unit_types[choice->choice].name, choice->want);
+ get_unit_type(choice->choice)->name, choice->want);
} else {
CITY_LOG(LOGLEVEL_BUILD, pcity, "military advisor choice: %s (want %d)",
improvement_types[choice->choice].name, choice->want);
Index: ai/aisettler.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aisettler.c,v
retrieving revision 1.26
diff -p -u -r1.26 aisettler.c
--- ai/aisettler.c 22 Jul 2005 16:18:04 -0000 1.26
+++ ai/aisettler.c 22 Jul 2005 16:29:51 -0000
@@ -593,8 +593,7 @@ void find_best_city_placement(struct uni
struct unit_type *boattype = get_role_unit(L_FERRYBOAT, 0);
if (boattype != NULL) {
- Tech_type_id tech_req
- = unit_types[boattype->index].tech_requirement;
+ Tech_type_id tech_req = boattype->tech_requirement;
pplayer->ai.tech_want[tech_req] += FERRY_TECH_WANT;
TECH_LOG(LOG_DEBUG, pplayer, tech_req, "+ %d for %s to ferry
settler",
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.156
diff -p -u -r1.156 aitools.c
--- ai/aitools.c 22 Jul 2005 16:18:04 -0000 1.156
+++ ai/aitools.c 22 Jul 2005 16:29:52 -0000
@@ -1113,11 +1113,13 @@ void copy_if_better_choice(struct ai_cho
{
if (cur->want > best->want) {
freelog(LOG_DEBUG, "Overriding choice (%s, %d) with (%s, %d)",
- (best->type == CT_BUILDING ?
- get_improvement_name(best->choice) :
unit_types[best->choice].name),
+ (best->type == CT_BUILDING
+ ? get_improvement_name(best->choice)
+ : get_unit_type(best->choice)->name),
best->want,
- (cur->type == CT_BUILDING ?
- get_improvement_name(cur->choice) : unit_types[cur->choice].name),
+ (cur->type == CT_BUILDING
+ ? get_improvement_name(cur->choice)
+ : get_unit_type(cur->choice)->name),
cur->want);
best->choice =cur->choice;
best->want = cur->want;
Index: client/mapctrl_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.c,v
retrieving revision 1.57
diff -p -u -r1.57 mapctrl_common.c
--- client/mapctrl_common.c 22 Jul 2005 16:18:05 -0000 1.57
+++ client/mapctrl_common.c 22 Jul 2005 16:29:52 -0000
@@ -350,8 +350,8 @@ void clipboard_copy_production(struct ti
upgrade_canvas_clipboard();
my_snprintf(msg, sizeof(msg), _("Copy %s to clipboard."),
- clipboard_is_unit ? unit_types[clipboard].name :
- get_improvement_name(clipboard));
+ clipboard_is_unit ? get_unit_type(clipboard)->name
+ : get_improvement_name(clipboard));
append_output_window(msg);
}
Index: common/unittype.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.c,v
retrieving revision 1.62
diff -p -u -r1.62 unittype.c
--- common/unittype.c 22 Jul 2005 16:18:06 -0000 1.62
+++ common/unittype.c 22 Jul 2005 16:29:53 -0000
@@ -31,7 +31,7 @@
#include "unittype.h"
-struct unit_type unit_types[U_LAST];
+static struct unit_type unit_types[U_LAST];
/* the unit_types array is now setup in:
server/ruleset.c (for the server)
client/packhand.c (for the client)
Index: common/unittype.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.h,v
retrieving revision 1.53
diff -p -u -r1.53 unittype.h
--- common/unittype.h 22 Jul 2005 16:18:06 -0000 1.53
+++ common/unittype.h 22 Jul 2005 16:29:53 -0000
@@ -190,9 +190,8 @@ struct unit_type {
};
-extern struct unit_type unit_types[U_LAST];
#define CHECK_UNIT_TYPE(ut) (assert((ut) != NULL \
- && (&unit_types[(ut)->index] == (ut))))
+ && (get_unit_type((ut)->index) == (ut))))
struct unit_type *get_unit_type(Unit_type_id id);
struct unit_type *unit_type(const struct unit *punit);
Index: server/cityhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityhand.c,v
retrieving revision 1.149
diff -p -u -r1.149 cityhand.c
--- server/cityhand.c 22 Jul 2005 16:18:06 -0000 1.149
+++ server/cityhand.c 22 Jul 2005 16:29:53 -0000
@@ -244,7 +244,7 @@ void really_handle_city_buy(struct playe
}
if (pcity->is_building_unit) {
- name = unit_types[pcity->currently_building].name;
+ name = get_unit_type(pcity->currently_building)->name;
total = unit_build_shield_cost(get_unit_type(pcity->currently_building));
} else {
name = get_improvement_name(pcity->currently_building);
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.337
diff -p -u -r1.337 citytools.c
--- server/citytools.c 22 Jul 2005 16:18:06 -0000 1.337
+++ server/citytools.c 22 Jul 2005 16:29:53 -0000
@@ -1816,7 +1816,7 @@ void change_build_target(struct player *
/* What's the name of the target? */
if (is_unit)
- name = unit_types[pcity->currently_building].name;
+ name = get_unit_type(pcity->currently_building)->name;
else
name = improvement_types[pcity->currently_building].name;
Index: server/gamelog.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamelog.c,v
retrieving revision 1.51
diff -p -u -r1.51 gamelog.c
--- server/gamelog.c 12 Jul 2005 21:25:47 -0000 1.51
+++ server/gamelog.c 22 Jul 2005 16:29:53 -0000
@@ -430,13 +430,13 @@ void gamelog(int level, ...)
pcity->is_building_unit ? 1 : 0,
(!pcity->is_building_unit
&& is_wonder(pcity->currently_building)) ? 1 : 0,
- pcity->is_building_unit ?
- unit_types[pcity->currently_building].name :
- get_impr_name_ex(pcity, pcity->currently_building),
+ pcity->is_building_unit
+ ? get_unit_type(pcity->currently_building)->name
+ : get_impr_name_ex(pcity, pcity->currently_building),
get_nation_name_plural(city_owner(pcity)->nation),
- pcity->is_building_unit ?
- unit_types[pcity->currently_building].name :
- get_impr_name_ex(pcity, pcity->currently_building),
+ pcity->is_building_unit
+ ? get_unit_type(pcity->currently_building)->name
+ : get_impr_name_ex(pcity, pcity->currently_building),
pcity->name);
gamelog_put_prefix(buf, sizeof(buf), "build");
break;
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.275
diff -p -u -r1.275 ruleset.c
--- server/ruleset.c 22 Jul 2005 16:18:06 -0000 1.275
+++ server/ruleset.c 22 Jul 2005 16:29:54 -0000
@@ -887,8 +887,8 @@ static void load_unit_names(struct secti
const int i = punittype->index;
char *name = secfile_lookup_str(file, "%s.name", sec[i]);
- name_strlcpy(unit_types[i].name_orig, name);
- unit_types[i].name = unit_types[i].name_orig;
+ name_strlcpy(punittype->name_orig, name);
+ punittype->name = punittype->name_orig;
} unit_type_iterate_end;
free(sec);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#13513) encapsulate the unit_types array,
Jason Short <=
|
|