[Freeciv-Dev] (PR#13007) new files specialist.[ch]
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13007 >
PR#8759 requires some new specialist functionality: an index value, some
more accessor functions (find_specialist_by_name), etc. Rather than
trying to fit this into the current specialist code (split between
game.h and city.h) I'd rather just go ahead and make a new file.
This does that. It also adds the specialist->index value.
-jason
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.221
diff -u -r1.221 aicity.c
--- ai/aicity.c 7 May 2005 18:58:01 -0000 1.221
+++ ai/aicity.c 7 May 2005 21:47:53 -0000
@@ -98,7 +98,7 @@
int providers = 0;
specialist_type_iterate(i) {
- if (game.rgame.specialists[i].bonus[O_LUXURY] >= HAPPY_COST) {
+ if (get_specialist(i)->bonus[O_LUXURY] >= HAPPY_COST) {
providers += pcity->specialists[i];
}
} specialist_type_iterate_end;
Index: client/cityrepdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.c,v
retrieving revision 1.50
diff -u -r1.50 cityrepdata.c
--- client/cityrepdata.c 22 Apr 2005 04:20:08 -0000 1.50
+++ client/cityrepdata.c 7 May 2005 21:47:53 -0000
@@ -126,10 +126,9 @@
const void *data)
{
static char buf[8];
- const struct specialist *sp_data = data;
- Specialist_type_id sp = sp_data - game.rgame.specialists;
+ const struct specialist *sp = data;
- my_snprintf(buf, sizeof(buf), "%2d", pcity->specialists[sp]);
+ my_snprintf(buf, sizeof(buf), "%2d", pcity->specialists[sp->index]);
return buf;
}
@@ -551,13 +550,13 @@
p->width = 2;
p->space = 1;
p->title1 = Q_("?specialist:S");
- p->title2 = Q_(game.rgame.specialists[sp].short_name);
+ p->title2 = Q_(get_specialist(sp)->short_name);
my_snprintf(explanation[sp], sizeof(explanation[sp]),
- _("Specialists: %s"), _(game.rgame.specialists[sp].name));
+ _("Specialists: %s"), _(get_specialist(sp)->name));
p->explanation = explanation[sp];
- p->data = &game.rgame.specialists[sp];
+ p->data = get_specialist(sp);
p->func = cr_entry_specialist;
- p->tagname = game.rgame.specialists[sp].name;
+ p->tagname = get_specialist(sp)->name;
i++;
} specialist_type_iterate_end;
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.509
diff -u -r1.509 packhand.c
--- client/packhand.c 7 May 2005 14:03:51 -0000 1.509
+++ client/packhand.c 7 May 2005 21:47:54 -0000
@@ -2427,15 +2427,15 @@
int i;
/* Must set num_specialist_types before iterating over them. */
- game.rgame.num_specialist_types = packet->num_specialist_types;
- game.rgame.default_specialist = packet->default_specialist;
+ SP_COUNT = packet->num_specialist_types;
+ DEFAULT_SPECIALIST = packet->default_specialist;
specialist_type_iterate(sp) {
- int *bonus = game.rgame.specialists[sp].bonus;
+ struct specialist *s = get_specialist(sp);
+ int *bonus = s->bonus;
int j;
- sz_strlcpy(game.rgame.specialists[sp].name, packet->specialist_name[sp]);
- sz_strlcpy(game.rgame.specialists[sp].short_name,
- packet->specialist_short_name[sp]);
+ sz_strlcpy(s->name, packet->specialist_name[sp]);
+ sz_strlcpy(s->short_name, packet->specialist_short_name[sp]);
output_type_iterate(o) {
bonus[o] = packet->specialist_bonus[sp * O_COUNT + o];
} output_type_iterate_end;
@@ -2443,11 +2443,10 @@
for (j = 0; j < MAX_NUM_REQS; j++) {
int index = sp * MAX_NUM_REQS + j;
- game.rgame.specialists[sp].req[j]
- = req_from_values(packet->specialist_req_type[index],
- packet->specialist_req_range[index],
- packet->specialist_req_survives[index],
- packet->specialist_req_value[index]);
+ s->req[j] = req_from_values(packet->specialist_req_type[index],
+ packet->specialist_req_range[index],
+ packet->specialist_req_survives[index],
+ packet->specialist_req_value[index]);
}
} specialist_type_iterate_end;
tileset_setup_specialist_types(tileset);
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.302
diff -u -r1.302 tilespec.c
--- client/tilespec.c 5 May 2005 19:22:24 -0000 1.302
+++ client/tilespec.c 7 May 2005 21:47:55 -0000
@@ -1526,7 +1526,7 @@
* translate. */
switch (citizen.type) {
case CITIZEN_SPECIALIST:
- return game.rgame.specialists[citizen.spec_type].name;
+ return get_specialist(citizen.spec_type)->name;
case CITIZEN_HAPPY:
return "happy";
case CITIZEN_CONTENT:
Index: common/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/Makefile.am,v
retrieving revision 1.56
diff -u -r1.56 Makefile.am
--- common/Makefile.am 25 Apr 2005 19:11:25 -0000 1.56
+++ common/Makefile.am 7 May 2005 21:47:55 -0000
@@ -51,6 +51,8 @@
requirements.h \
spaceship.c \
spaceship.h \
+ specialist.c \
+ specialist.h \
tech.c \
tech.h \
terrain.c \
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.342
diff -u -r1.342 city.c
--- common/city.c 7 May 2005 18:58:02 -0000 1.342
+++ common/city.c 7 May 2005 21:47:55 -0000
@@ -524,7 +524,7 @@
Specialist_type_id type)
{
return are_reqs_active(city_owner(pcity), pcity, NULL, NULL, NULL, NULL,
- game.rgame.specialists[type].req, MAX_NUM_REQS);
+ get_specialist(type)->req, MAX_NUM_REQS);
}
/**************************************************************************
@@ -1540,7 +1540,7 @@
int *output)
{
specialist_type_iterate(sp) {
- int *bonus = game.rgame.specialists[sp].bonus;
+ int *bonus = get_specialist(sp)->bonus;
int count = pcity->specialists[sp];
output_type_iterate(stat) {
@@ -2260,13 +2260,13 @@
const struct city *pcity)
{
int best = DEFAULT_SPECIALIST;
- int val = game.rgame.specialists[DEFAULT_SPECIALIST].bonus[otype];
+ int val = get_specialist(best)->bonus[otype];
specialist_type_iterate(i) {
if (!pcity || city_can_use_specialist(pcity, i)) {
- if (game.rgame.specialists[i].bonus[otype] > val) {
+ if (get_specialist(i)->bonus[otype] > val) {
best = i;
- val = game.rgame.specialists[i].bonus[otype];
+ val = get_specialist(i)->bonus[otype];
}
}
} specialist_type_iterate_end;
@@ -2275,30 +2275,6 @@
}
/**************************************************************************
- Return a string showing the number of specialists in the array.
-
- For instance with a city with (0,3,1) specialists call
-
- specialists_string(pcity->specialists);
-
- and you'll get "0/3/1".
-**************************************************************************/
-const char *specialists_string(const int *specialists)
-{
- static char buf[5 * SP_MAX];
-
- buf[0] = '\0';
-
- specialist_type_iterate(sp) {
- char *separator = (buf[0] == '\0') ? "" : "/";
-
- cat_snprintf(buf, sizeof(buf), "%s%d", separator, specialists[sp]);
- } specialist_type_iterate_end;
-
- return buf;
-}
-
-/**************************************************************************
Adds an improvement (and its effects) to a city.
**************************************************************************/
void city_add_improvement(struct city *pcity, Impr_type_id impr)
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.211
diff -u -r1.211 city.h
--- common/city.h 7 May 2005 18:58:02 -0000 1.211
+++ common/city.h 7 May 2005 21:47:55 -0000
@@ -512,7 +512,6 @@
int city_specialists(const struct city *pcity); /*
elv+tax+scie */
Specialist_type_id best_specialist(Output_type_id otype,
const struct city *pcity);
-const char *specialists_string(const int *specialists);
int get_city_output_bonus(const struct city *pcity, Output_type_id otype);
bool city_built_last_turn(const struct city *pcity);
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.212
diff -u -r1.212 game.c
--- common/game.c 7 May 2005 14:03:51 -0000 1.212
+++ common/game.c 7 May 2005 21:47:55 -0000
@@ -279,6 +279,7 @@
improvements_init();
techs_init();
unit_types_init();
+ specialists_init();
idex_init();
cm_init();
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.189
diff -u -r1.189 game.h
--- common/game.h 5 May 2005 20:00:42 -0000 1.189
+++ common/game.h 7 May 2005 21:47:55 -0000
@@ -27,6 +27,7 @@
#include "improvement.h" /* Impr_Status */
#include "player.h"
#include "packets.h"
+#include "specialist.h"
enum server_states {
PRE_GAME_STATE,
@@ -84,17 +85,6 @@
/* values from game.info.t */
struct {
- int num_specialist_types;
- int default_specialist;
- struct specialist {
- char name[MAX_LEN_NAME];
- char short_name[MAX_LEN_NAME];
- int bonus[O_MAX];
- struct requirement req[MAX_NUM_REQS];
- } specialists[SP_MAX];
-#define SP_COUNT game.rgame.num_specialist_types
-#define DEFAULT_SPECIALIST game.rgame.default_specialist
-
/* Items given to all players at game start. Server only. */
int global_init_techs[MAX_NUM_TECH_LIST];
int global_init_buildings[MAX_NUM_BUILDING_LIST];
@@ -369,14 +359,4 @@
#define GAME_START_YEAR -4000
-#define specialist_type_iterate(sp) \
-{ \
- int sp; \
- \
- for (sp = 0; sp < SP_COUNT; sp++) {
-
-#define specialist_type_iterate_end \
- } \
-}
-
#endif /* FC__GAME_H */
Index: common/specialist.c
===================================================================
RCS file: common/specialist.c
diff -N common/specialist.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ common/specialist.c 7 May 2005 21:47:56 -0000
@@ -0,0 +1,66 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 2005 - The Freeciv Project
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "specialist.h"
+
+struct specialist specialists[SP_MAX];
+int num_specialist_types;
+int default_specialist;
+
+/****************************************************************************
+ Initialize data for specialists.
+****************************************************************************/
+void specialists_init(void)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(specialists); i++) {
+ specialists[i].index = i;
+ }
+}
+
+/****************************************************************************
+ Return the specialist struct for the given specialist ID.
+****************************************************************************/
+struct specialist *get_specialist(Specialist_type_id spec)
+{
+ return &specialists[spec];
+}
+
+/****************************************************************************
+ Return a string showing the number of specialists in the array.
+
+ For instance with a city with (0,3,1) specialists call
+
+ specialists_string(pcity->specialists);
+
+ and you'll get "0/3/1".
+****************************************************************************/
+const char *specialists_string(const int *specialists)
+{
+ static char buf[5 * SP_MAX];
+
+ buf[0] = '\0';
+
+ specialist_type_iterate(sp) {
+ char *separator = (buf[0] == '\0') ? "" : "/";
+
+ cat_snprintf(buf, sizeof(buf), "%s%d", separator, specialists[sp]);
+ } specialist_type_iterate_end;
+
+ return buf;
+}
Index: common/specialist.h
===================================================================
RCS file: common/specialist.h
diff -N common/specialist.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ common/specialist.h 7 May 2005 21:47:56 -0000
@@ -0,0 +1,52 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 2005 - The Freeciv Project
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+***********************************************************************/
+
+#ifndef FC__SPECIALIST_H
+#define FC__SPECIALIST_H
+
+#include "shared.h"
+
+#include "fc_types.h"
+#include "requirements.h"
+
+struct specialist {
+ int index;
+ char name[MAX_LEN_NAME];
+ char short_name[MAX_LEN_NAME];
+ int bonus[O_MAX];
+ struct requirement req[MAX_NUM_REQS];
+};
+
+#define SP_COUNT num_specialist_types
+#define DEFAULT_SPECIALIST default_specialist
+
+extern struct specialist specialists[SP_MAX];
+extern int num_specialist_types;
+extern int default_specialist;
+
+void specialists_init(void);
+struct specialist *get_specialist(Specialist_type_id spec);
+
+const char *specialists_string(const int *specialists);
+
+#define specialist_type_iterate(sp) \
+{ \
+ Specialist_type_id sp; \
+ \
+ for (sp = 0; sp < SP_COUNT; sp++) {
+
+#define specialist_type_iterate_end \
+ } \
+}
+
+#endif /* FC__SPECIALIST_H */
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.64
diff -u -r1.64 cm.c
--- common/aicore/cm.c 7 May 2005 06:01:12 -0000 1.64
+++ common/aicore/cm.c 7 May 2005 21:47:57 -0000
@@ -925,7 +925,7 @@
if (city_can_use_specialist(pcity, i)) {
type.spec = i;
output_type_iterate(output) {
- type.production[output] = game.rgame.specialists[i].bonus[output];
+ type.production[output] = get_specialist(i)->bonus[output];
} output_type_iterate_end;
tile_type_lattice_add(lattice, &type, 0, 0);
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.256
diff -u -r1.256 ruleset.c
--- server/ruleset.c 7 May 2005 14:03:53 -0000 1.256
+++ server/ruleset.c 7 May 2005 21:47:58 -0000
@@ -2265,14 +2265,15 @@
for (i = 0; i < nval; i++) {
const char *name = specialist_names[i], *short_name;
- int *bonus = game.rgame.specialists[i].bonus;
+ struct specialist *s = &specialists[i];
+ int *bonus = s->bonus;
int j;
- sz_strlcpy(game.rgame.specialists[i].name, name);
+ sz_strlcpy(s->name, name);
short_name
= secfile_lookup_str_default(file, name,
"specialist.%s_short_name", name);
- sz_strlcpy(game.rgame.specialists[i].short_name, short_name);
+ sz_strlcpy(s->short_name, short_name);
output_type_iterate(o) {
bonus[o] = secfile_lookup_int_default(file, 0,
@@ -2303,20 +2304,19 @@
req.source.type = REQ_NONE;
}
- game.rgame.specialists[i].req[j] = req;
+ s->req[j] = req;
}
- if (game.rgame.specialists[i].req[0].source.type == REQ_NONE
- && game.rgame.default_specialist == -1) {
- game.rgame.default_specialist = i;
+ if (s->req[0].source.type == REQ_NONE && DEFAULT_SPECIALIST == -1) {
+ DEFAULT_SPECIALIST = i;
}
}
- if (game.rgame.default_specialist == -1) {
+ if (DEFAULT_SPECIALIST == -1) {
freelog(LOG_FATAL, "You must give a min_size of 0 for at least one "
"specialist type (in %s).", filename);
exit(EXIT_FAILURE);
}
- game.rgame.num_specialist_types = nval;
+ SP_COUNT = nval;
free(specialist_names);
game.info.celebratesize =
@@ -2962,12 +2962,12 @@
misc_p.req_array_size = SP_COUNT * MAX_NUM_REQS;
misc_p.default_specialist = DEFAULT_SPECIALIST;
specialist_type_iterate(sp) {
- int *bonus = game.rgame.specialists[sp].bonus;
+ struct specialist *s = get_specialist(sp);
+ int *bonus = s->bonus;
int j;
- sz_strlcpy(misc_p.specialist_name[sp], game.rgame.specialists[sp].name);
- sz_strlcpy(misc_p.specialist_short_name[sp],
- game.rgame.specialists[sp].short_name);
+ sz_strlcpy(misc_p.specialist_name[sp], s->name);
+ sz_strlcpy(misc_p.specialist_short_name[sp], s->short_name);
output_type_iterate(o) {
misc_p.specialist_bonus[sp * O_COUNT + o] = bonus[o];
@@ -2976,7 +2976,7 @@
for (j = 0; j < MAX_NUM_REQS; j++) {
int index = sp * MAX_NUM_REQS + j;
- req_get_values(&game.rgame.specialists[sp].req[j],
+ req_get_values(&s->req[j],
&misc_p.specialist_req_type[index],
&misc_p.specialist_req_range[index],
&misc_p.specialist_req_survives[index],
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.245
diff -u -r1.245 savegame.c
--- server/savegame.c 7 May 2005 15:38:31 -0000 1.245
+++ server/savegame.c 7 May 2005 21:47:58 -0000
@@ -2063,7 +2063,7 @@
specialist_type_iterate(sp) {
pcity->specialists[sp]
= secfile_lookup_int(file, "player%d.c%d.n%s", plrno, i,
- game.rgame.specialists[sp].name);
+ get_specialist(sp)->name);
} specialist_type_iterate_end;
for (j = 0; j < NUM_TRADEROUTES; j++)
@@ -2856,7 +2856,7 @@
specialist_type_iterate(sp) {
secfile_insert_int(file, pcity->specialists[sp],
"player%d.c%d.n%s", plrno, i,
- game.rgame.specialists[sp].name);
+ get_specialist(sp)->name);
} specialist_type_iterate_end;
for (j = 0; j < NUM_TRADEROUTES; j++)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#13007) new files specialist.[ch],
Jason Short <=
|
|