forked from github/server
remove besiege from keywords[] array
fix broken at_keys attributes remove unused global.attribs
This commit is contained in:
parent
a876a60b68
commit
681cf32e1f
10 changed files with 88 additions and 54 deletions
|
@ -953,7 +953,6 @@ function test_bug2083()
|
||||||
-- this is a bit weird, but the bug was caused by market code
|
-- this is a bit weird, but the bug was caused by market code
|
||||||
-- being called in two places. We want to make sure this doesn't happen
|
-- being called in two places. We want to make sure this doesn't happen
|
||||||
for k, v in pairs(rules) do
|
for k, v in pairs(rules) do
|
||||||
set_key("xm09", true)
|
|
||||||
if 'table' == type(v) then
|
if 'table' == type(v) then
|
||||||
cb = v['update']
|
cb = v['update']
|
||||||
if 'function' == type(cb) then
|
if 'function' == type(cb) then
|
||||||
|
|
|
@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <storage.h>
|
#include <storage.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -76,25 +77,83 @@ static int keys_size(int n) {
|
||||||
return 4096;
|
return 4096;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int read_flags(gamedata *data, int *keys, int n) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i != n; ++i) {
|
||||||
|
int key;
|
||||||
|
READ_INT(data->store, &key);
|
||||||
|
keys[i * 2] = key;
|
||||||
|
keys[i * 2 + 1] = 1;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef KEYVAL_VERSION
|
||||||
|
static int read_keyval(gamedata *data, int *keys, int n) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i != n; ++i) {
|
||||||
|
int key, val;
|
||||||
|
READ_INT(data->store, &key);
|
||||||
|
READ_INT(data->store, &val);
|
||||||
|
keys[i * 2] = key;
|
||||||
|
keys[i * 2 + 1] = val;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef FIXATKEYS_VERSION
|
||||||
|
static int read_keyval_orig(gamedata *data, int *keys, int n) {
|
||||||
|
int i, j = 0, dk = -1;
|
||||||
|
for (i = 0; i != n; ++i) {
|
||||||
|
int key, val;
|
||||||
|
READ_INT(data->store, &key);
|
||||||
|
READ_INT(data->store, &val);
|
||||||
|
if (key > dk) {
|
||||||
|
keys[j * 2] = key;
|
||||||
|
keys[j * 2 + 1] = val;
|
||||||
|
dk = key;
|
||||||
|
++j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int a_readkeys(variant *var, void *owner, gamedata *data) {
|
static int a_readkeys(variant *var, void *owner, gamedata *data) {
|
||||||
int i, n, *keys;
|
int i, n, ksn, *keys;
|
||||||
|
|
||||||
READ_INT(data->store, &n);
|
READ_INT(data->store, &n);
|
||||||
assert(n < 4096 && n >= 0);
|
assert(n < 4096 && n >= 0);
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return AT_READ_FAIL;
|
return AT_READ_FAIL;
|
||||||
}
|
}
|
||||||
keys = malloc(sizeof(int)*(keys_size(n) * 2 + 1));
|
ksn = keys_size(n);
|
||||||
*keys = n;
|
keys = malloc((ksn * 2 + 1) * sizeof(int));
|
||||||
for (i = 0; i != n; ++i) {
|
if (data->version >= FIXATKEYS_VERSION) {
|
||||||
READ_INT(data->store, keys + i * 2 + 1);
|
n = read_keyval(data, keys + 1, n);
|
||||||
if (data->version >= KEYVAL_VERSION) {
|
}
|
||||||
READ_INT(data->store, keys + i * 2 + 2);
|
else if (data->version >= KEYVAL_VERSION) {
|
||||||
|
int m = read_keyval_orig(data, keys + 1, n);
|
||||||
|
if (n != m) {
|
||||||
|
int ksm = keys_size(m);
|
||||||
|
if (ksm != ksn) {
|
||||||
|
int *nkeys = (int *)realloc(keys, (ksm * 2 + 1) * sizeof(int));
|
||||||
|
if (nkeys != NULL) {
|
||||||
|
keys = nkeys;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
keys[i * 2 + 2] = 1;
|
log_error("a_readkeys allocation failed: %s", strerror(errno));
|
||||||
|
return AT_READ_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
n = m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
n = read_flags(data, keys + 1, n);
|
||||||
|
}
|
||||||
|
keys[0] = n;
|
||||||
if (data->version < SORTKEYS_VERSION) {
|
if (data->version < SORTKEYS_VERSION) {
|
||||||
int e = 1;
|
int e = 1;
|
||||||
for (i = 1; i != n; ++i) {
|
for (i = 1; i != n; ++i) {
|
||||||
|
|
|
@ -153,15 +153,6 @@ int tolua_itemlist_next(lua_State * L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_getkey(lua_State * L)
|
|
||||||
{
|
|
||||||
const char *name = tolua_tostring(L, 1, 0);
|
|
||||||
int flag = atoi36(name);
|
|
||||||
|
|
||||||
lua_pushboolean(L, key_get(global.attribs, flag));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tolua_translate(lua_State * L)
|
static int tolua_translate(lua_State * L)
|
||||||
{
|
{
|
||||||
const char *str = tolua_tostring(L, 1, 0);
|
const char *str = tolua_tostring(L, 1, 0);
|
||||||
|
@ -175,20 +166,6 @@ static int tolua_translate(lua_State * L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_setkey(lua_State * L)
|
|
||||||
{
|
|
||||||
const char *name = tolua_tostring(L, 1, 0);
|
|
||||||
int value = (int)tolua_tonumber(L, 3, 0);
|
|
||||||
int flag = atoi36(name);
|
|
||||||
if (value) {
|
|
||||||
key_set(&global.attribs, flag, value);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
key_unset(&global.attribs, flag);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tolua_random(lua_State * L)
|
static int tolua_random(lua_State * L)
|
||||||
{
|
{
|
||||||
lua_pushinteger(L, rng_int());
|
lua_pushinteger(L, rng_int());
|
||||||
|
@ -1003,8 +980,6 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile)
|
||||||
tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners);
|
tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners);
|
||||||
tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill);
|
tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill);
|
||||||
tolua_function(L, TOLUA_CAST "create_curse", tolua_create_curse);
|
tolua_function(L, TOLUA_CAST "create_curse", tolua_create_curse);
|
||||||
tolua_function(L, TOLUA_CAST "get_key", tolua_getkey);
|
|
||||||
tolua_function(L, TOLUA_CAST "set_key", tolua_setkey);
|
|
||||||
tolua_function(L, TOLUA_CAST "translate", &tolua_translate);
|
tolua_function(L, TOLUA_CAST "translate", &tolua_translate);
|
||||||
tolua_function(L, TOLUA_CAST "spells", tolua_get_spells);
|
tolua_function(L, TOLUA_CAST "spells", tolua_get_spells);
|
||||||
tolua_function(L, TOLUA_CAST "equip_newunits", tolua_equip_newunits);
|
tolua_function(L, TOLUA_CAST "equip_newunits", tolua_equip_newunits);
|
||||||
|
|
|
@ -846,7 +846,7 @@ static void json_keyword(cJSON *json, struct locale *lang) {
|
||||||
}
|
}
|
||||||
for (child = json->child; child; child = child->next) {
|
for (child = json->child; child; child = child->next) {
|
||||||
keyword_t kwd = findkeyword(child->string);
|
keyword_t kwd = findkeyword(child->string);
|
||||||
if (kwd != NOKEYWORD) {
|
if (kwd != NOKEYWORD && keywords[kwd]) {
|
||||||
if (child->type == cJSON_String) {
|
if (child->type == cJSON_String) {
|
||||||
init_keyword(lang, kwd, child->valuestring);
|
init_keyword(lang, kwd, child->valuestring);
|
||||||
locale_setstring(lang, mkname("keyword", keywords[kwd]), child->valuestring);
|
locale_setstring(lang, mkname("keyword", keywords[kwd]), child->valuestring);
|
||||||
|
|
|
@ -767,10 +767,6 @@ void free_gamedata(void)
|
||||||
free_borders();
|
free_borders();
|
||||||
free_alliances();
|
free_alliances();
|
||||||
|
|
||||||
while (global.attribs) {
|
|
||||||
a_remove(&global.attribs, global.attribs);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (planes) {
|
while (planes) {
|
||||||
plane *pl = planes;
|
plane *pl = planes;
|
||||||
planes = planes->next;
|
planes = planes->next;
|
||||||
|
|
|
@ -109,7 +109,6 @@ extern "C" {
|
||||||
|
|
||||||
/* globale settings des Spieles */
|
/* globale settings des Spieles */
|
||||||
typedef struct settings {
|
typedef struct settings {
|
||||||
struct attrib *attribs;
|
|
||||||
void *vm_state;
|
void *vm_state;
|
||||||
} settings;
|
} settings;
|
||||||
|
|
||||||
|
|
|
@ -1392,7 +1392,13 @@ int read_game(gamedata *data)
|
||||||
else {
|
else {
|
||||||
READ_STR(store, NULL, 0);
|
READ_STR(store, NULL, 0);
|
||||||
}
|
}
|
||||||
read_attribs(data, &global.attribs, NULL);
|
|
||||||
|
if (data->version < FIXATKEYS_VERSION) {
|
||||||
|
attrib *a = NULL;
|
||||||
|
read_attribs(data, &a, NULL);
|
||||||
|
a_removeall(&a, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
READ_INT(store, &turn);
|
READ_INT(store, &turn);
|
||||||
log_debug(" - reading turn %d", turn);
|
log_debug(" - reading turn %d", turn);
|
||||||
rng_init(turn + config_get_int("game.seed", 0));
|
rng_init(turn + config_get_int("game.seed", 0));
|
||||||
|
@ -1614,9 +1620,6 @@ int write_game(gamedata *data) {
|
||||||
WRITE_INT(store, game_id());
|
WRITE_INT(store, game_id());
|
||||||
WRITE_SECTION(store);
|
WRITE_SECTION(store);
|
||||||
|
|
||||||
write_attribs(store, global.attribs, NULL);
|
|
||||||
WRITE_SECTION(store);
|
|
||||||
|
|
||||||
WRITE_INT(store, turn);
|
WRITE_INT(store, turn);
|
||||||
WRITE_INT(store, 0 /* max_unique_id */);
|
WRITE_INT(store, 0 /* max_unique_id */);
|
||||||
WRITE_INT(store, nextborder);
|
WRITE_INT(store, nextborder);
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
const char * keyword(keyword_t kwd)
|
const char * keyword(keyword_t kwd)
|
||||||
{
|
{
|
||||||
static char result[32]; /* FIXME: static return value */
|
static char result[32]; /* FIXME: static return value */
|
||||||
if (kwd==NOKEYWORD) {
|
if (kwd==NOKEYWORD || keywords[kwd] == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!result[0]) {
|
if (!result[0]) {
|
||||||
|
@ -43,7 +43,7 @@ void init_keywords(const struct locale *lang) {
|
||||||
keyword_t findkeyword(const char *s) {
|
keyword_t findkeyword(const char *s) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i != MAXKEYWORDS; ++i) {
|
for (i = 0; i != MAXKEYWORDS; ++i) {
|
||||||
if (strcmp(s, keywords[i]) == 0) {
|
if (keywords[i] && (strcmp(s, keywords[i]) == 0)) {
|
||||||
return (keyword_t)i;
|
return (keyword_t)i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ const char *keywords[MAXKEYWORDS] = {
|
||||||
"work",
|
"work",
|
||||||
"attack",
|
"attack",
|
||||||
"steal",
|
"steal",
|
||||||
"deprecated_besiege",
|
NULL,
|
||||||
"name",
|
"name",
|
||||||
"use",
|
"use",
|
||||||
"describe",
|
"describe",
|
||||||
|
|
|
@ -147,8 +147,10 @@ struct locale * test_create_locale(void) {
|
||||||
locale_setstring(loc, combatstatus[i], combatstatus[i] + 7);
|
locale_setstring(loc, combatstatus[i], combatstatus[i] + 7);
|
||||||
}
|
}
|
||||||
for (i = 0; i != MAXKEYWORDS; ++i) {
|
for (i = 0; i != MAXKEYWORDS; ++i) {
|
||||||
|
if (keywords[i]) {
|
||||||
locale_setstring(loc, mkname("keyword", keywords[i]), keywords[i]);
|
locale_setstring(loc, mkname("keyword", keywords[i]), keywords[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (i = 0; i != MAXPARAMS; ++i) {
|
for (i = 0; i != MAXPARAMS; ++i) {
|
||||||
locale_setstring(loc, parameters[i], parameters[i]);
|
locale_setstring(loc, parameters[i], parameters[i]);
|
||||||
test_translate_param(loc, i, parameters[i]);
|
test_translate_param(loc, i, parameters[i]);
|
||||||
|
|
|
@ -36,10 +36,11 @@
|
||||||
#define FAMILIAR_FIX_VERSION 359 /* familiar links are fixed */
|
#define FAMILIAR_FIX_VERSION 359 /* familiar links are fixed */
|
||||||
#define SKILLSORT_VERSION 360 /* u->skills is sorted */
|
#define SKILLSORT_VERSION 360 /* u->skills is sorted */
|
||||||
#define LANDDISPLAY_VERSION 360 /* r.display is now in r.land.display */
|
#define LANDDISPLAY_VERSION 360 /* r.display is now in r.land.display */
|
||||||
|
#define FIXATKEYS_VERSION 361 /* remove global.attribs, fix at_keys */
|
||||||
/* unfinished: */
|
/* unfinished: */
|
||||||
#define CRYPT_VERSION 400 /* passwords are encrypted */
|
#define CRYPT_VERSION 400 /* passwords are encrypted */
|
||||||
|
|
||||||
#define RELEASE_VERSION LANDDISPLAY_VERSION /* current datafile */
|
#define RELEASE_VERSION FIXATKEYS_VERSION /* current datafile */
|
||||||
#define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */
|
#define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */
|
||||||
#define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */
|
#define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue