config.c cleanup: move attribute registration to attributes.c

This commit is contained in:
Enno Rehling 2015-11-24 19:32:52 +01:00
parent 84a943b698
commit 8aa7fec54c
8 changed files with 114 additions and 108 deletions

View File

@ -20,12 +20,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "attributes.h"
#include "laws.h"
#include "move.h"
#include "guard.h"
/* attributes includes */
#include "follow.h"
#include "hate.h"
#include "iceberg.h"
#include "key.h"
#include "stealth.h"
#include "magic.h"
#include "moved.h"
#include "movement.h"
#include "dict.h"
@ -38,8 +43,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "targetregion.h"
/* kernel includes */
#include <kernel/ally.h>
#include <kernel/connection.h>
#include <kernel/curse.h>
#include <kernel/unit.h>
#include <kernel/faction.h>
#include <kernel/group.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/ship.h>
@ -47,13 +56,67 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */
#include <util/attrib.h>
#include <util/event.h>
#include <storage.h>
attrib_type at_unitdissolve = {
"unitdissolve", NULL, NULL, NULL, a_writechars, a_readchars
};
static int read_ext(attrib * a, void *owner, struct storage *store)
{
int len;
READ_INT(store, &len);
store->api->r_bin(store->handle, NULL, (size_t)len);
return AT_READ_OK;
}
void register_attributes(void)
{
/* Alle speicherbaren Attribute müssen hier registriert werden */
at_register(&at_shiptrail);
at_register(&at_familiar);
at_register(&at_familiarmage);
at_register(&at_clone);
at_register(&at_clonemage);
at_register(&at_eventhandler);
at_register(&at_mage);
at_register(&at_countdown);
at_register(&at_curse);
at_register(&at_seenspell);
/* neue REGION-Attribute */
at_register(&at_moveblock);
at_register(&at_deathcount);
at_register(&at_woodcount);
/* neue UNIT-Attribute */
at_register(&at_siege);
at_register(&at_effect);
at_register(&at_private);
at_register(&at_icastle);
at_register(&at_guard);
at_register(&at_group);
at_register(&at_building_generic_type);
at_register(&at_maxmagicians);
at_register(&at_npcfaction);
/* connection-typen */
register_bordertype(&bt_noway);
register_bordertype(&bt_fogwall);
register_bordertype(&bt_wall);
register_bordertype(&bt_illusionwall);
register_bordertype(&bt_road);
at_register(&at_germs);
at_deprecate("xontormiaexpress", a_readint); /* required for old datafiles */
at_deprecate("lua", read_ext); /* required for old datafiles */
at_deprecate("gm", a_readint);
at_register(&at_stealth);
at_register(&at_dict);

View File

@ -44,7 +44,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "race.h"
#include "reports.h"
#include "region.h"
#include "save.h"
#include "ship.h"
#include "skill.h"
#include "terrain.h"
@ -85,7 +84,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#endif
/* external libraries */
#include <storage.h>
#include <iniparser.h>
#include <critbit.h>
@ -267,34 +265,6 @@ const char *options[MAXOPTIONS] = {
"SHOWSKCHANGE"
};
static void init_maxmagicians(struct attrib *a)
{
a->data.i = MAXMAGICIANS;
}
static attrib_type at_maxmagicians = {
"maxmagicians",
init_maxmagicians,
NULL,
NULL,
a_writeint,
a_readint,
ATF_UNIQUE
};
int max_magicians(const faction * f)
{
int m = config_get_int("rules.maxskills.magic", MAXMAGICIANS);
attrib *a;
if ((a = a_find(f->attribs, &at_maxmagicians)) != NULL) {
m = a->data.i;
}
if (f->race == get_race(RC_ELF))
++m;
return m;
}
FILE *debug;
/* ----------------------------------------------------------------------- */
@ -786,16 +756,6 @@ void kernel_done(void)
free_attribs();
}
attrib_type at_germs = {
"germs",
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
a_writeshorts,
a_readshorts,
ATF_UNIQUE
};
void setstatus(struct unit *u, int status)
{
assert(status >= ST_AGGRO && status <= ST_FLEE);
@ -1099,70 +1059,12 @@ bool has_limited_skills(const struct unit * u)
}
}
static int read_ext(attrib * a, void *owner, struct storage *store)
{
int len;
READ_INT(store, &len);
store->api->r_bin(store->handle, NULL, (size_t)len);
return AT_READ_OK;
}
void attrib_init(void)
{
/* Alle speicherbaren Attribute müssen hier registriert werden */
at_register(&at_shiptrail);
at_register(&at_familiar);
at_register(&at_familiarmage);
at_register(&at_clone);
at_register(&at_clonemage);
at_register(&at_eventhandler);
at_register(&at_mage);
at_register(&at_countdown);
at_register(&at_curse);
at_register(&at_seenspell);
/* neue REGION-Attribute */
at_register(&at_moveblock);
at_register(&at_deathcount);
at_register(&at_woodcount);
/* neue UNIT-Attribute */
at_register(&at_siege);
at_register(&at_effect);
at_register(&at_private);
at_register(&at_icastle);
at_register(&at_guard);
at_register(&at_group);
at_register(&at_building_generic_type);
at_register(&at_maxmagicians);
at_register(&at_npcfaction);
/* connection-typen */
register_bordertype(&bt_noway);
register_bordertype(&bt_fogwall);
register_bordertype(&bt_wall);
register_bordertype(&bt_illusionwall);
register_bordertype(&bt_road);
register_function((pf_generic)minimum_wage, "minimum_wage");
at_register(&at_germs);
at_deprecate("xontormiaexpress", a_readint); /* required for old datafiles */
at_deprecate("lua", read_ext); /* required for old datafiles */
}
void kernel_init(void)
{
register_reports();
mt_clear();
attrib_init();
translation_init();
register_function((pf_generic)minimum_wage, "minimum_wage");
}
static order * defaults[MAXLOCALES];

View File

@ -27,11 +27,6 @@ extern "C" {
#include "types.h"
struct param;
/* getunit results: */
#define GET_UNIT 0
#define GET_NOTFOUND 1
#define GET_PEASANTS 2
#define DISPLAYSIZE 8192 /* max. Länge einer Beschreibung, incl trailing 0 */
#define ORDERSIZE (DISPLAYSIZE*2) /* max. length of an order */
#define NAMESIZE 128 /* max. Länge eines Namens, incl trailing 0 */
@ -50,7 +45,6 @@ struct param;
#define fset(u, i) ((u)->flags |= (i))
#define freset(u, i) ((u)->flags &= ~(i))
int max_magicians(const struct faction * f);
int findoption(const char *s, const struct locale *lang);
param_t findparam(const char *s, const struct locale *lang);

View File

@ -30,6 +30,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "plane.h"
#include "race.h"
#include "region.h"
#include "save.h"
#include "spellbook.h"
#include "terrain.h"
#include "unit.h"
@ -773,3 +774,32 @@ int count_maxmigrants(const faction * f)
}
return 0;
}
static void init_maxmagicians(struct attrib *a)
{
a->data.i = MAXMAGICIANS;
}
attrib_type at_maxmagicians = {
"maxmagicians",
init_maxmagicians,
NULL,
NULL,
a_writeint,
a_readint,
ATF_UNIQUE
};
int max_magicians(const faction * f)
{
int m = config_get_int("rules.maxskills.magic", MAXMAGICIANS);
attrib *a;
if ((a = a_find(f->attribs, &at_maxmagicians)) != NULL) {
m = a->data.i;
}
if (f->race == get_race(RC_ELF))
++m;
return m;
}

View File

@ -29,7 +29,9 @@ extern "C" {
struct alliance;
struct item;
struct seen_region;
struct attrib_type;
extern struct attrib_type at_maxmagicians;
/* SMART_INTERVALS: define to speed up finding the interval of regions that a
faction is in. defining this speeds up the turn by 30-40% */
#define SMART_INTERVALS
@ -173,7 +175,7 @@ extern "C" {
int count_maxmigrants(const struct faction * f);
int count_all(const struct faction * f);
int count_units(const struct faction * f);
int max_magicians(const struct faction * f);
#ifdef __cplusplus
}

View File

@ -256,8 +256,13 @@ extern "C" {
bool unit_name_equals_race(const struct unit *u);
bool unit_can_study(const struct unit *u);
int newunitid(void);
/* getunit results: */
#define GET_UNIT 0
#define GET_NOTFOUND 1
#define GET_PEASANTS 2
int getunit(const struct region * r, const struct faction * f, struct unit **uresult);
int newunitid(void);
int read_unitid(const struct faction *f, const struct region *r);
#ifdef __cplusplus

View File

@ -478,7 +478,16 @@ static int count_race(const region * r, const race * rc)
return c;
}
extern struct attrib_type at_germs;
attrib_type at_germs = {
"germs",
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
a_writeshorts,
a_readshorts,
ATF_UNIQUE
};
static void
growing_trees_e3(region * r, const int current_season,

View File

@ -34,6 +34,7 @@ extern "C" {
struct attrib_type;
extern struct attrib_type at_germs;
extern int dropouts[2];
extern int *age;