diff --git a/src/common/attributes/variable.c b/src/common/attributes/variable.c index 3fac3e245..32ee7dcad 100644 --- a/src/common/attributes/variable.c +++ b/src/common/attributes/variable.c @@ -25,103 +25,21 @@ #include #include -typedef struct { - char *key; - char *value; -} variable; - -static void -initialize_variable(struct attrib * a) -{ - a->data.v = malloc(sizeof(variable)); -} - -static void -finalize_variable(struct attrib * a) -{ - free(a->data.v); -} - -static void -write_variable(const struct attrib * a, storage * store) -{ - variable * var = (variable *)a->data.v; - store->w_tok(store, var->key); - store->w_str(store, var->value); -} - static int read_variable(struct attrib *a, storage * store) { - variable * var = (variable *)a->data.v; + char * key = store->r_tok(store); + char * value = store->r_str(store); + free(key); + free(value); - var->key = store->r_tok(store); - var->value = store->r_str(store); - - return AT_READ_OK; + return AT_READ_FAIL; } attrib_type at_variable = { - "variable", initialize_variable, finalize_variable, NULL, - write_variable, read_variable + "variable", NULL, NULL, NULL, + NULL, read_variable }; - -const char * -get_variable(attrib *a, const char *key) -{ - attrib *ap = a_find(a, &at_variable); - - while (ap && ap->type==&at_variable) { - variable * var = (variable *)ap->data.v; - if (strcmp(key, var->key) == 0) { - return var->value; - } - ap = ap->next; - } - - return NULL; -} - -void -set_variable(attrib **app, const char *key, const char *value) -{ - attrib *ap = a_find(*app, &at_variable); - - assert(value); - - while (ap && ap->type==&at_variable) { - variable * var = (variable *)ap->data.v; - if (strcmp(key, var->key) == 0) { - free(var->value); - var->value = strdup(value); - return; - } - ap = ap->next; - } - - ap = a_add(app, a_new(&at_variable)); - ((variable *)ap->data.v)->key = strdup(key); - ((variable *)ap->data.v)->value = strdup(value); -} - -void -delete_variable(attrib **app, const char *key) -{ - attrib *ap = a_find(*app, &at_variable); - - while (ap && ap->type==&at_variable) { - variable * var = (variable *)ap->data.v; - if (strcmp(key, var->key) == 0) { - free(var->key); - free(var->value); - a_remove(app, ap); - break; - } - ap = ap->next; - } - -} - void init_variable(void) { diff --git a/src/common/attributes/variable.h b/src/common/attributes/variable.h index 342c52224..d8f95999e 100644 --- a/src/common/attributes/variable.h +++ b/src/common/attributes/variable.h @@ -17,9 +17,6 @@ extern "C" { #endif -const char *get_variable(struct attrib *a, const char *key); -void set_variable(struct attrib **app, const char *key, const char *value); -void delete_variable(struct attrib **app, const char *key); void init_variable(void); #ifdef __cplusplus diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 31a90176a..15c2fc561 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -66,7 +66,7 @@ /* attributes includes */ #include #include -#include +#include /* util includes */ #include @@ -984,8 +984,9 @@ quit_cmd(unit * u, struct order * ord) cmistake(u, ord, 316, MSG_EVENT); return 0; } else { - const char * token = itoa36(f2_id); - set_variable(&f->attribs, "quit", token); + variant var; + var.i = f2_id; + object_create("quit", TINTEGER, var); } } } @@ -1006,14 +1007,21 @@ quit(void) faction * f = *fptr; if (f->flags & FFL_QUIT) { if (EnhancedQuit()) { - const char * token = get_variable(f->attribs, "quit"); - if(token != NULL) { - int f2_id = atoi36(token); - faction *f2 = findfaction(f2_id); + attrib * a = a_find(f->attribs, &at_object); + if (a) { + variant var; + object_type type; + var.i = 0; + object_get(a, &type, &var); + assert(var.i && type==TINTEGER); + if (var.i) { + int f2_id = var.i; + faction *f2 = findfaction(f2_id); - assert(f2_id>0); - assert(f2!=NULL); - transfer_faction(f, f2); + assert(f2_id>0); + assert(f2!=NULL); + transfer_faction(f, f2); + } } } destroyfaction(f); diff --git a/src/eressea/lua/faction.cpp b/src/eressea/lua/faction.cpp index d5fef4355..107f52b73 100644 --- a/src/eressea/lua/faction.cpp +++ b/src/eressea/lua/faction.cpp @@ -132,24 +132,6 @@ faction_setpolicy(faction * a, faction * b, const char * flag, bool value) } } -static const char * -faction_get_variable(faction * f, const char *key) -{ - return get_variable(f->attribs, key); -} - -static void -faction_set_variable(faction * f, const char *key, const char *value) -{ - set_variable(&f->attribs, key, value); -} - -static void -faction_delete_variable(faction * f, const char *key) -{ - return delete_variable(&f->attribs, key); -} - static int faction_additem(faction * f, const char * iname, int number) { @@ -290,7 +272,6 @@ bind_faction(lua_State * L) module(L)[ def("factions", &get_factions, return_stl_iterator), def("get_faction", &findfaction), - def("add_faction", &add_faction), def("faction_origin", &faction_getorigin, pure_out_value(_2) + pure_out_value(_3)), class_("faction") @@ -299,11 +280,6 @@ bind_faction(lua_State * L) .def("set_policy", &faction_setpolicy) .def("get_policy", &faction_getpolicy) - // temporary variables - .def("set_variable", &faction_set_variable) - .def("get_variable", &faction_get_variable) - .def("delete_variable", &faction_delete_variable) - // heroes .def("heroes", &faction_countheroes) .def("max_heroes", &faction_maxheroes) diff --git a/src/eressea/tolua/bind_building.c b/src/eressea/tolua/bind_building.c index 05abfd986..e639086fc 100644 --- a/src/eressea/tolua/bind_building.c +++ b/src/eressea/tolua/bind_building.c @@ -147,7 +147,10 @@ tolua_building_open(lua_State* tolua_S) tolua_variable(tolua_S, "units", tolua_building_get_units, NULL); tolua_variable(tolua_S, "region", tolua_building_get_region, tolua_building_set_region); tolua_function(tolua_S, "add_action", tolua_building_addaction); - +#ifdef TODO + .property("type", &building_gettype) + .def_readwrite("size", &building::size) +#endif tolua_variable(tolua_S, "objects", tolua_building_get_objects, 0); tolua_function(tolua_S, "create", tolua_building_create); diff --git a/src/eressea/tolua/bind_faction.c b/src/eressea/tolua/bind_faction.c index e6eb5769e..66ba6f7bc 100644 --- a/src/eressea/tolua/bind_faction.c +++ b/src/eressea/tolua/bind_faction.c @@ -423,7 +423,38 @@ tolua_faction_open(lua_State* tolua_S) tolua_function(tolua_S, "renumber", tolua_faction_renumber); tolua_function(tolua_S, "create", tolua_faction_create); +#ifdef TODO + def("faction_origin", &faction_getorigin, pure_out_value(_2) + pure_out_value(_3)), + // heroes + .def("heroes", &faction_countheroes) + .def("max_heroes", &faction_maxheroes) + + .def_readonly("name", &faction::name) + .def_readonly("score", &faction::score) + .def_readonly("id", &faction::no) + .def_readwrite("age", &faction::age) + .def_readwrite("options", &faction::options) + .def_readwrite("flags", &faction::flags) + .def_readwrite("subscription", &faction::subscription) + .def_readwrite("lastturn", &faction::lastorders) + + .def("add_item", &faction_additem) + .property("items", &faction_items, return_stl_iterator) + .property("x", &faction_getorigin_x, &faction_setorigin_x) + .property("y", &faction_getorigin_y, &faction_setorigin_y) + + .def("renum", &faction_renumber) + .def("add_notice", &faction_addnotice) + .property("password", &faction_get_passw, &faction_set_passw) + .property("info", &faction_get_banner, &faction_set_banner) + .property("email", &faction_get_email, &faction_set_email) + .property("locale", &faction_getlocale, &faction_setlocale) + .property("units", &faction_units, return_stl_iterator) + .property("alliance", &faction_getalliance, &faction_setalliance) + .property("race", &faction_getrace, &faction_setrace) + .property("objects", &eressea::get_objects) +#endif tolua_variable(tolua_S, "objects", tolua_faction_get_objects, NULL); } tolua_endmodule(tolua_S); diff --git a/src/eressea/tolua/bind_ship.c b/src/eressea/tolua/bind_ship.c index 357212d7d..9098836a2 100644 --- a/src/eressea/tolua/bind_ship.c +++ b/src/eressea/tolua/bind_ship.c @@ -119,7 +119,16 @@ tolua_ship_open(lua_State* tolua_S) tolua_variable(tolua_S, "id", tolua_ship_get_id, NULL); tolua_variable(tolua_S, "name", tolua_ship_get_name, tolua_ship_set_name); tolua_variable(tolua_S, "units", tolua_ship_get_units, NULL); - +#ifdef TODO + .property("type", &ship_gettype) + .property("weight", &ship_getweight) + .property("capacity", &ship_getcapacity) + .property("maxsize", &ship_maxsize) + .property("region", &ship_getregion, &ship_setregion) + .def_readwrite("damage", &ship::damage) + .def_readwrite("size", &ship::size) + .def_readwrite("coast", &ship::coast) +#endif tolua_variable(tolua_S, "objects", tolua_ship_get_objects, 0); tolua_function(tolua_S, "create", tolua_ship_create); diff --git a/src/scripts/run-tests.lua b/src/scripts/run-tests.lua index df54c40ec..b412323fb 100644 --- a/src/scripts/run-tests.lua +++ b/src/scripts/run-tests.lua @@ -52,7 +52,7 @@ end function test_reorder() r = terraform(0, 0, "plain") - f = add_faction("enno@ix.de", "orc", "de") + f = faction.create("enno@ix.de", "orc", "de") s1 = add_ship(r, "boat") s1.size = 1 s2 = add_ship(r, "boat") diff --git a/src/scripts/samples.lua b/src/scripts/samples.lua index 42025980f..6e73e594e 100644 --- a/src/scripts/samples.lua +++ b/src/scripts/samples.lua @@ -33,13 +33,13 @@ function test_movement() r3:set_road(east, 1.0) r4:set_road(west, 1.0) - orcs = add_faction("orcs@eressea.de", "orc", "de") + orcs = faction.create("orcs@eressea.de", "orc", "de") orcs.age = 20 - aqua = add_faction("aqua@eressea.de", "aquarian", "de") + aqua = faction.create("aqua@eressea.de", "aquarian", "de") aqua.age = 20 - bugs = add_faction("bugz@eressea.de", "insect", "de") + bugs = faction.create("bugz@eressea.de", "insect", "de") bugs.age = 20 orc = mkunit(orcs, r0, 10) @@ -139,7 +139,7 @@ end function test_sail() r0 = terraform(0, 0, "plain") - orcs = add_faction("enno@eressea.de", "orc", "de") + orcs = faction.create("enno@eressea.de", "orc", "de") orcs.age = 20 orc = add_unit(orcs, r0) @@ -169,7 +169,7 @@ function test_handler() plain = terraform(0, 0, "plain") skill = 8 - f = add_faction("enno@eressea.de", "orc", "de") + f = faction.create("enno@eressea.de", "orc", "de") f.age = 20 u = add_unit(f, plain) @@ -180,7 +180,7 @@ function test_handler() u:add_handler("message", msg_handler) msg = "BOTSCHAFT EINHEIT " .. itoa36(u.id) .. " Du~Elf~stinken" - f = add_faction("enno@eressea.de", "elf", "de") + f = faction.create("enno@eressea.de", "elf", "de") f.age = 20 u = add_unit(f, plain) @@ -197,7 +197,7 @@ function test_combat() plain = terraform(0, 0, "plain") skill = 8 - f = add_faction("enno@eressea.de", "orc", "de") + f = faction.create("enno@eressea.de", "orc", "de") f.age = 20 u = add_unit(f, plain) @@ -211,7 +211,7 @@ function test_combat() u:add_order("BEFÖRDERUNG") attack = "ATTACKIERE " .. itoa36(u.id) - f = add_faction("enno@eressea.de", "elf", "de") + f = faction.create("enno@eressea.de", "elf", "de") f.age = 20 u = add_unit(f, plain) @@ -232,7 +232,7 @@ function test_rewards() plain = terraform(0, 0, "plain") skill = 5 - f = add_faction("enno@eressea.de", "human", "de") + f = faction.create("enno@eressea.de", "human", "de") f.age = 20 u = add_unit(f, plain) u.number = 10 @@ -253,7 +253,7 @@ function test_rewards() u:add_order("MACHEN Elfenbogen") u:add_order("NUMMER PARTEI test") - f = add_faction("enno@eressea.de", "elf", "de") + f = faction.create("enno@eressea.de", "elf", "de") f.age = 20 u = add_unit(f, plain) u.number = 7 @@ -297,7 +297,7 @@ end function test_give() plain = terraform(0, 0, "plain") - f = add_faction("enno@eressea.de", "human", "de") + f = faction.create("enno@eressea.de", "human", "de") f.age = 20 u = add_unit(f, plain) u.number = 10 @@ -345,7 +345,7 @@ function test_parser() plain = terraform(0, 0, "plain") skill = 5 - f = add_faction("enno@eressea.de", "human", "de") + f = faction.create("enno@eressea.de", "human", "de") f.age = 20 u = add_unit(f, plain) u.number = 10 @@ -359,7 +359,7 @@ function test_fail() plain = terraform(0, 0, "plain") skill = 5 - f = add_faction("enno@eressea.de", "human", "de") + f = faction.create("enno@eressea.de", "human", "de") print(f) end diff --git a/src/scripts/wdw-setup.lua b/src/scripts/wdw-setup.lua index ad8c3e4b5..5043d3db5 100644 --- a/src/scripts/wdw-setup.lua +++ b/src/scripts/wdw-setup.lua @@ -53,7 +53,7 @@ function make_faction(position, alliance, number, email, race) local units = (1+skillno)*6 / number -- jede allianz kriegt 168 leute local money = units * 5 * 10 -- jede allianz kriegt 8400 silber - local f = add_faction(email, race, "de") + local f = faction.create(email, race, "de") if f == nil then print("could not create " .. email .. " " .. race) return diff --git a/src/scripts/wdw/sphinx-announce.lua b/src/scripts/wdw/sphinx-announce.lua index 1b644736f..05b61a4eb 100644 --- a/src/scripts/wdw/sphinx-announce.lua +++ b/src/scripts/wdw/sphinx-announce.lua @@ -22,7 +22,7 @@ function sphinx_handler() hintText[14] = "Das Schiff mit dem Stern im Wappen liegt neben dem des Kriegers, der einen Zweihänder führt" for i=0,4,1 do - possibleHint[i] = u:faction:get_variable("sphinxhint"..tostring(i)) + possibleHint[i] = u:faction.objects:get("sphinxhint"..tostring(i)) end hint = math.random(0,4) @@ -34,7 +34,7 @@ function sphinx_handler() str = evt:get_string(0) u2 = evt:get_unit(1) if str.lower() == "hinweis" then - if u2:faction:get_variable("sphinxGotHint"..itoa36(u.id) then + if u2:faction.objects:get("sphinxGotHint"..itoa36(u.id) then send_gotHint(u2) else send_hint(u2, u) diff --git a/src/scripts/wdw/sphinx-initfactions.lua b/src/scripts/wdw/sphinx-initfactions.lua index 7aae905b6..ed854bf6a 100644 --- a/src/scripts/wdw/sphinx-initfactions.lua +++ b/src/scripts/wdw/sphinx-initfactions.lua @@ -7,12 +7,12 @@ function init_sphinxhints() hints[i] = 0 end for i=0,4,1 do - if faction:get_variable("sphinxhint"..tostring(i)) == nil then + if faction.objects:get("sphinxhint"..tostring(i)) == nil then repeat hint = math.random(0,14) until hints[hint] = 0 hints[hint] = 1 - faction:set_variable("sphinxhint"..tostring(i),tostring(hint)) + faction.objects:set("sphinxhint"..tostring(i), tostring(hint)) end end end diff --git a/src/scripts/wdw/sphinx.lua b/src/scripts/wdw/sphinx.lua index 87cd450f5..bd835cfbb 100644 --- a/src/scripts/wdw/sphinx.lua +++ b/src/scripts/wdw/sphinx.lua @@ -12,12 +12,12 @@ function init_sphinxhints() hints[i] = 0 end for i=0,4,1 do - if f:get_variable("sphinxhint"..tostring(i)) == nil then + if f.objects:get("sphinxhint"..tostring(i)) == nil then repeat hint = math.random(0,14) until hints[hint] == 0 hints[hint] = 1 - f:set_variable("sphinxhint"..tostring(i),tostring(hint)) + f.objects:set("sphinxhint" .. tostring(i), tostring(hint)) end end end @@ -74,7 +74,7 @@ function sphinx_handler() str = evt:get_string(0) u2 = evt:get_unit(1) if string.lower(str) == "hinweis" then - if u2.faction:get_variable("sphinxGotHint"..itoa36(u.id)) ~= nil then + if u2.faction.objects:get("sphinxGotHint"..itoa36(u.id)) ~= nil then send_gotHint(u2) else send_hint(u2, u)