From 5576ef37b6a82be58d6683ce2bc5da3ce2a299b3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 9 Dec 2017 21:20:20 +0100 Subject: [PATCH] remove building_action feature, it seems that it isn't in use. --- src/CMakeLists.txt | 1 - src/building_action.c | 151 ------------------------------------------ src/helpers.c | 15 ++++- src/kernel/building.h | 1 - 4 files changed, 14 insertions(+), 154 deletions(-) delete mode 100644 src/building_action.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2374c8a1f..d3cfdafce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -141,7 +141,6 @@ set (ERESSEA_SRC set(SERVER_SRC main.c - building_action.c console.c helpers.c bind_tolua.c diff --git a/src/building_action.c b/src/building_action.c deleted file mode 100644 index 28cd55a48..000000000 --- a/src/building_action.c +++ /dev/null @@ -1,151 +0,0 @@ -/* -+-------------------+ -| | Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -| | Henning Peters -+-------------------+ - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include -#include - -typedef struct building_action { - char *fname; - char *param; -} building_action; - -static int lc_age(struct attrib *a, void *owner) -{ - building_action *data = (building_action *)a->data.v; - const char *fname = data->fname; - const char *fparam = data->param; - building *b = (building *)owner; - int result = -1; - - assert(b != NULL); - if (fname != NULL) { - lua_State *L = (lua_State *)global.vm_state; - - lua_getglobal(L, fname); - if (lua_isfunction(L, -1)) { - tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); - if (fparam) { - tolua_pushstring(L, fparam); - } - - if (lua_pcall(L, fparam ? 2 : 1, 1, 0) != 0) { - const char *error = lua_tostring(L, -1); - log_error("lc_age(%s) calling '%s': %s.\n", buildingname(b), fname, error); - lua_pop(L, 1); - } - else { - result = (int)lua_tonumber(L, -1); - lua_pop(L, 1); - } - } - else { - log_error("lc_age(%s) calling '%s': not a function.\n", buildingname(b), fname); - lua_pop(L, 1); - } - } - return (result != 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; -} - -static const char *NULLSTRING = "(null)"; - -static void lc_init(struct attrib *a) -{ - a->data.v = calloc(1, sizeof(building_action)); -} - -static void 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); -} - -static void lc_write(const struct attrib *a, const void *owner, struct storage *store) -{ - building_action *data = (building_action *)a->data.v; - const char *fname = data->fname; - const char *fparam = data->param; - - UNUSED_ARG(owner); - WRITE_TOK(store, fname); - WRITE_TOK(store, fparam ? fparam : NULLSTRING); -} - -static int lc_read(struct attrib *a, void *owner, gamedata *data) -{ - struct storage *store = data->store; - char name[NAMESIZE]; - building_action *bd = (building_action *)a->data.v; - building *b = (building *)owner; - int result = 0; - if (data->version < ATTRIBOWNER_VERSION) { - READ_INT(data->store, NULL); - } - READ_TOK(store, name, sizeof(name)); - if (strcmp(name, "tunnel_action") == 0) { - /* E2: Weltentor has a new module, doesn't need this any longer */ - result = 0; - b = 0; - } - else { - bd->fname = strdup(name); - } - READ_TOK(store, name, sizeof(name)); - if (strcmp(name, "tnnL") == 0) { - /* tunnel_action was the old Weltentore, their code has changed. ignore this object */ - result = 0; - b = 0; - } - if (strcmp(name, NULLSTRING) == 0) - bd->param = 0; - else { - bd->param = strdup(name); - } - if (result == 0 && !b) { - return AT_READ_FAIL; - } - return AT_READ_OK; -} - -attrib_type at_building_action = { - "lcbuilding", - lc_init, lc_done, - lc_age, - lc_write, lc_read -}; - -void 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->fname = strdup(fname); - if (param) { - data->param = strdup(param); - } -} diff --git a/src/helpers.c b/src/helpers.c index 5f73ac542..897e39720 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -304,11 +304,24 @@ struct trigger_type tt_caldera = { caldera_read }; + +static int building_action_read(struct attrib *a, void *owner, gamedata *data) +{ + struct storage *store = data->store; + + if (data->version < ATTRIBOWNER_VERSION) { + READ_INT(data->store, NULL); + } + READ_TOK(store, NULL, 0); + READ_TOK(store, NULL, 0); + return AT_READ_DEPR; +} + void register_tolua_helpers(void) { tt_register(&tt_caldera); at_register(&at_direction); - at_register(&at_building_action); + at_deprecate("lcbuilding", building_action_read); callbacks.cast_spell = lua_callspell; callbacks.use_item = use_item_lua; diff --git a/src/kernel/building.h b/src/kernel/building.h index af29c324b..e162e041f 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -71,7 +71,6 @@ extern "C" { } building_type; extern struct selist *buildingtypes; - extern struct attrib_type at_building_action; extern struct attrib_type at_building_generic_type; int cmp_castle_size(const struct building *b, const struct building *a);