builing_action kann jetzt einen string-parameter haben.

This commit is contained in:
Enno Rehling 2005-01-07 17:02:32 +00:00
parent 293c12c382
commit 032466e908
5 changed files with 25 additions and 4 deletions

View File

@ -40,6 +40,8 @@
/* attributes includes */
#include <attributes/matmod.h>
static const char * NULLSTRING = "(null)";
static void
lc_init(struct attrib *a)
{
@ -51,6 +53,7 @@ lc_done(struct attrib *a)
{
building_action * data = (building_action*)a->data.v;
if (data->fname) free(data->fname);
if (data->param) free(data->param);
free(data);
}
@ -59,10 +62,14 @@ lc_write(const struct attrib * a, FILE* F)
{
building_action * data = (building_action*)a->data.v;
const char * fname = data->fname;
const char * fparam = data->param;
building * b = data->b;
write_building_reference(b, F);
fwritestr(F, fname);
#if RELEASE_VERSION>=BACTION_VERSION
fwritestr(F, fparam?fparam:NULLSTRING);
#endif
fputc(' ', F);
}
@ -75,6 +82,13 @@ lc_read(struct attrib * a, FILE* F)
read_building_reference(&data->b, F);
freadstr(F, lbuf, sizeof(lbuf));
data->fname = strdup(lbuf);
if (global.data_version>=BACTION_VERSION) {
freadstr(F, lbuf, sizeof(lbuf));
if (strcmp(lbuf, NULLSTRING)==0) data->param = NULL;
else data->param = strdup(lbuf);
} else {
data->param = strdup(NULLSTRING);
}
return AT_READ_OK;
}

View File

@ -145,6 +145,7 @@ extern attrib_type at_building_action;
typedef struct building_action {
building * b;
char * fname;
char * param;
} building_action;
#ifdef __cplusplus

View File

@ -161,6 +161,7 @@ struct building_type;
#define SAVEXMLNAME_VERSION 316
#define SAVEALLIANCE_VERSION 317
#define CLAIM_VERSION 318
#define BACTION_VERSION 319 /* building action gets a param string */
#define MIN_VERSION ALLIANCES_VERSION
#define REGIONOWNERS_VERSION 400
@ -169,7 +170,7 @@ struct building_type;
#ifdef REGIONOWNERS
# define RELEASE_VERSION REGIONOWNERS_VERSION
#else
# define RELEASE_VERSION CLAIM_VERSION
# define RELEASE_VERSION BACTION_VERSION
#endif
#if RESOURCE_CONVERSION

View File

@ -36,6 +36,7 @@ lc_age(struct attrib * a)
lua_State * L = (lua_State *)global.vm_state;
building_action * data = (building_action*)a->data.v;
const char * fname = data->fname;
const char * fparam = data->param;
building * b = data->b;
assert(b!=NULL);
@ -62,16 +63,21 @@ lc_age(struct attrib * a)
std::terminate();
}
if (fparam) {
return luabind::call_function<int>(L, fname, *b, fparam);
} else {
return luabind::call_function<int>(L, fname, *b);
}
}
static int
building_addaction(building& b, const char * fname)
building_addaction(building& b, const char * fname, const char * param)
{
attrib * a = a_add(&b.attribs, a_new(&at_building_action));
building_action * data = (building_action*)a->data.v;
data->b = &b;
data->fname = strdup(fname);
if (param) data->param = strdup(param);
return 0;
}

View File

@ -171,7 +171,6 @@ region_remove(region& r)
region ** rp = &regions;
while (*rp) {
if (*rp==&r) {
unit * u;
while (r.units) {
destroy_unit(r.units);
}