forked from github/server
Merge remote-tracking branch 'eressea/master'
This commit is contained in:
commit
cbdf486d45
|
@ -1,26 +1,4 @@
|
|||
#!/bin/sh
|
||||
git submodule update --init
|
||||
MACHINE=`uname -m`
|
||||
[ -z "$CC" ] && [ ! -z `which gcc` ] && CC="gcc"
|
||||
[ -z "$CC" ] && [ ! -z `which tcc` ] && CC="tcc"
|
||||
[ -z "$CC" ] && [ ! -z `which cc` ] && CC="cc"
|
||||
[ -z "$JOBS" ] && JOBS=$(nproc)
|
||||
|
||||
BIN_DIR="build-$MACHINE-$CC-Debug"
|
||||
DISTCC=`which distcc`
|
||||
if [ ! -z "$DISTCC" ] ; then
|
||||
JOBS=`distcc -j`
|
||||
if [ -z "$JOBS" ] ; then
|
||||
JOBS=1
|
||||
elif [ $JOBS -gt 1 ] ; then
|
||||
CC="$DISTCC $CC"
|
||||
MAKEOPTS=-j$JOBS
|
||||
fi
|
||||
fi
|
||||
echo "Building with $CC and $JOBS jobs"
|
||||
|
||||
mkdir -p $BIN_DIR
|
||||
cd $BIN_DIR
|
||||
CC="$CC" ../s/cmake-init
|
||||
make -j$JOBS
|
||||
make test
|
||||
s/cmake-init
|
||||
echo "configuration complete. run s/build to build the server"
|
||||
|
|
2
s/build
2
s/build
|
@ -31,4 +31,4 @@ fi
|
|||
|
||||
cd $ROOT/$BIN_DIR
|
||||
make $MAKEOPTS && make test
|
||||
cd -
|
||||
cd $OLDPWD
|
||||
|
|
|
@ -14,11 +14,6 @@ done
|
|||
[ -z "$CC" ] && [ ! -z `which tcc` ] && CC="tcc"
|
||||
[ -z "$CC" ] && [ ! -z `which cc` ] && CC="cc"
|
||||
|
||||
if [ ! -e ../CMakeLists.txt ]; then
|
||||
echo "are you sure you are in the build directory?"
|
||||
exit
|
||||
fi
|
||||
|
||||
MACHINE=$(gcc -dumpmachine)
|
||||
rm -f CMakeCache.txt
|
||||
|
||||
|
@ -41,4 +36,4 @@ cmake .. \
|
|||
-DCMAKE_INCLUDE_PATH=$INCLUDE_PATH \
|
||||
-DCMAKE_PREFIX_PATH=$PREFIX_PATH \
|
||||
-DCMAKE_INSTALL_PREFIX=$HOME/eressea $*
|
||||
cd -
|
||||
cd $OLDPWD
|
||||
|
|
|
@ -16,4 +16,4 @@ BIN_DIR="build-$MACHINE-$CC-Debug"
|
|||
|
||||
cd $ROOT/$BIN_DIR
|
||||
make install
|
||||
cd -
|
||||
cd $OLDPWD
|
||||
|
|
|
@ -18,4 +18,4 @@ fi
|
|||
$ROOT/$BIN_DIR/eressea/test_eressea
|
||||
cd $ROOT
|
||||
$ROOT/$BIN_DIR/eressea/eressea -v0 scripts/runtests.lua
|
||||
cd -
|
||||
cd $OLDWPD
|
||||
|
|
|
@ -59,6 +59,7 @@ ENDIF()
|
|||
|
||||
set (ERESSEA_SRC
|
||||
eressea.c
|
||||
callback.c
|
||||
direction.c
|
||||
keyword.c
|
||||
skill.c
|
||||
|
@ -146,6 +147,7 @@ set(TESTS_SRC
|
|||
test_eressea.c
|
||||
tests.c
|
||||
tests.test.c
|
||||
callback.test.c
|
||||
direction.test.c
|
||||
keyword.test.c
|
||||
skill.test.c
|
||||
|
|
|
@ -36,8 +36,9 @@ int config_parse(const char *json)
|
|||
int line;
|
||||
char buffer[10];
|
||||
const char *xp = json, *lp, *ep = cJSON_GetErrorPtr();
|
||||
for (line=0,lp=xp;xp && xp<ep;++line,lp=xp+1) {
|
||||
for (line=1,lp=xp;xp && xp<ep;++line,lp=xp+1) {
|
||||
xp = strchr(lp, '\n');
|
||||
if (xp>=ep) break;
|
||||
}
|
||||
xp = (ep > json + 10) ? ep - 10 : json;
|
||||
strncpy(buffer, xp, sizeof(buffer));
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
#include <config.h>
|
||||
#include <platform.h>
|
||||
#include "callback.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static struct reg {
|
||||
struct reg * next;
|
||||
HCALLBACK cb;
|
||||
char *name;
|
||||
} *registry;
|
||||
|
||||
HCALLBACK create_callback(void(*cbv)(va_list va)) {
|
||||
HCALLBACK cb;
|
||||
cb.cbv = cbv;
|
||||
return cb;
|
||||
}
|
||||
|
||||
void reset_callbacks(void) {
|
||||
while(registry) {
|
||||
struct reg *r = registry;
|
||||
registry = r->next;
|
||||
free(r->name);
|
||||
free(r);
|
||||
}
|
||||
registry = 0;
|
||||
}
|
||||
|
||||
HCALLBACK register_callback(const char *name, void(*cbv)(va_list va))
|
||||
{
|
||||
struct reg * r = (struct reg *)malloc(sizeof(struct reg));
|
||||
r->next = registry;
|
||||
r->name = _strdup(name);
|
||||
r->cb.cbv = cbv;
|
||||
registry = r;
|
||||
return r->cb;
|
||||
}
|
||||
|
||||
int find_callback(const char *name, HCALLBACK *result) {
|
||||
if (result && name) {
|
||||
struct reg *r;
|
||||
for (r=registry;r;r=r->next) {
|
||||
if (strcmp(r->name, name)==0) {
|
||||
*result = r->cb;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int call_callback(HCALLBACK cb, const char *name, ...) {
|
||||
va_list ap;
|
||||
if (name) {
|
||||
int err = find_callback(name, &cb);
|
||||
if (err) return err;
|
||||
}
|
||||
va_start(ap, name);
|
||||
cb.cbv(ap);
|
||||
va_end(ap);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef H_CALLBACK_H
|
||||
#define H_CALLBACK_H
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
typedef struct {
|
||||
void (*cbv)(va_list va);
|
||||
} HCALLBACK;
|
||||
|
||||
HCALLBACK register_callback(const char *name, void(*cbv)(va_list va));
|
||||
HCALLBACK create_callback(void(*cbv)(va_list va));
|
||||
int find_callback(const char *name, HCALLBACK *result);
|
||||
int call_callback(HCALLBACK cb, const char *name, ...);
|
||||
void reset_callbacks(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,51 @@
|
|||
#include "callback.h"
|
||||
#include <stdlib.h>
|
||||
#include <CuTest.h>
|
||||
|
||||
void callback(va_list ap) {
|
||||
int i = (int)va_arg(ap, int);
|
||||
int *p = va_arg(ap, int *);
|
||||
*p += i;
|
||||
}
|
||||
|
||||
static void test_find_callback(CuTest *tc) {
|
||||
HCALLBACK cb;
|
||||
reset_callbacks();
|
||||
CuAssertIntEquals(tc, -1, find_callback("test", &cb));
|
||||
cb = register_callback("test", callback);
|
||||
CuAssertIntEquals(tc, 0, find_callback("test", &cb));
|
||||
reset_callbacks();
|
||||
}
|
||||
|
||||
static void test_call_by_handle(CuTest *tc) {
|
||||
HCALLBACK cb;
|
||||
int x = 0;
|
||||
reset_callbacks();
|
||||
cb = create_callback(callback);
|
||||
CuAssertIntEquals(tc, 0, call_callback(cb, 0, 42, &x));
|
||||
CuAssertIntEquals(tc, 42, x);
|
||||
reset_callbacks();
|
||||
}
|
||||
|
||||
static void test_call_by_name(CuTest *tc) {
|
||||
HCALLBACK cb = { 0 };
|
||||
HCALLBACK ca = { 0 };
|
||||
int x = 0;
|
||||
reset_callbacks();
|
||||
CuAssertIntEquals(tc, -1, call_callback(cb, "test", 42, &x));
|
||||
cb = register_callback("test", callback);
|
||||
CuAssertIntEquals(tc, 0, call_callback(cb, "test", 42, &x));
|
||||
CuAssertIntEquals(tc, 42, x);
|
||||
CuAssertIntEquals(tc, 0, call_callback(ca, "test", 42, &x));
|
||||
CuAssertIntEquals(tc, 84, x);
|
||||
reset_callbacks();
|
||||
}
|
||||
|
||||
CuSuite *get_callback_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_find_callback);
|
||||
SUITE_ADD_TEST(suite, test_call_by_name);
|
||||
SUITE_ADD_TEST(suite, test_call_by_handle);
|
||||
return suite;
|
||||
}
|
|
@ -1161,21 +1161,24 @@ int findoption(const char *s, const struct locale *lang)
|
|||
|
||||
param_t findparam(const char *s, const struct locale * lang)
|
||||
{
|
||||
param_t result = NOPARAM;
|
||||
char buffer[64];
|
||||
char * str = transliterate(buffer, sizeof(buffer)-sizeof(int), s);
|
||||
param_t result = NOPARAM;
|
||||
char buffer[64];
|
||||
char * str = transliterate(buffer, sizeof(buffer)-sizeof(int), s);
|
||||
|
||||
if (str && *str) {
|
||||
int i;
|
||||
const void * match;
|
||||
void **tokens = get_translations(lang, UT_PARAMS);
|
||||
critbit_tree *cb = (critbit_tree *)*tokens;
|
||||
if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) {
|
||||
cb_get_kv(match, &i, sizeof(int));
|
||||
result = (param_t)i;
|
||||
if (str && *str) {
|
||||
int i;
|
||||
const void * match;
|
||||
void **tokens = get_translations(lang, UT_PARAMS);
|
||||
critbit_tree *cb = (critbit_tree *)*tokens;
|
||||
if (!cb) {
|
||||
log_error_n("no parameters defined in locale %s", locale_name(lang));
|
||||
}
|
||||
else if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) {
|
||||
cb_get_kv(match, &i, sizeof(int));
|
||||
result = (param_t)i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
param_t findparam_ex(const char *s, const struct locale * lang)
|
||||
|
|
|
@ -345,6 +345,35 @@ static void json_buildings(cJSON *json) {
|
|||
}
|
||||
}
|
||||
|
||||
static void json_spells(cJSON *json) {
|
||||
cJSON *child;
|
||||
if (json->type != cJSON_Object) {
|
||||
log_error_n("spells is not a json object: %d", json->type);
|
||||
return;
|
||||
}
|
||||
for (child = json->child; child; child = child->next) {
|
||||
if (child->type == cJSON_Object) {
|
||||
spell *sp;
|
||||
cJSON * item = cJSON_GetObjectItem(child, "index");
|
||||
sp = create_spell(child->string, item ? item->valueint : 0);
|
||||
for (item = child->child; item; item = item->next) {
|
||||
if (strcmp(item->string, "index") == 0) {
|
||||
continue;
|
||||
}
|
||||
else if (strcmp(item->string, "cast") == 0) {
|
||||
sp->cast = (spell_f)get_function(item->valuestring);
|
||||
}
|
||||
else if (strcmp(item->string, "fumble") == 0) {
|
||||
sp->fumble = (fumble_f)get_function(item->valuestring);
|
||||
}
|
||||
else if (strcmp(item->string, "syntax") == 0) {
|
||||
sp->syntax = _strdup(item->valuestring);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void json_items(cJSON *json) {
|
||||
cJSON *child;
|
||||
if (json->type!=cJSON_Object) {
|
||||
|
@ -560,10 +589,13 @@ void json_config(cJSON *json) {
|
|||
else if (strcmp(child->string, "skills")==0) {
|
||||
json_skills(child);
|
||||
}
|
||||
else if (strcmp(child->string, "buildings")==0) {
|
||||
else if (strcmp(child->string, "buildings") == 0) {
|
||||
json_buildings(child);
|
||||
}
|
||||
else if (strcmp(child->string, "terrains")==0) {
|
||||
else if (strcmp(child->string, "spells") == 0) {
|
||||
json_spells(child);
|
||||
}
|
||||
else if (strcmp(child->string, "terrains") == 0) {
|
||||
json_terrains(child);
|
||||
} else {
|
||||
log_error_n("config contains unknown attribute %s", child->string);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "keyword.h"
|
||||
#include "race.h"
|
||||
#include "ship.h"
|
||||
#include "spell.h"
|
||||
#include "terrain.h"
|
||||
#include "util/language.h"
|
||||
#include <CuTest.h>
|
||||
|
@ -177,6 +178,26 @@ static void test_castles(CuTest *tc) {
|
|||
CuAssertPtrEquals(tc, 0, bt->construction->improvement->improvement);
|
||||
}
|
||||
|
||||
static void test_spells(CuTest * tc)
|
||||
{
|
||||
const char * data = "{\"spells\": { \"fireball\" : { \"syntax\" : \"u+\" } } }";
|
||||
|
||||
cJSON *json = cJSON_Parse(data);
|
||||
const spell *sp;
|
||||
|
||||
test_cleanup();
|
||||
CuAssertPtrNotNull(tc, json);
|
||||
CuAssertPtrEquals(tc, 0, find_spell("fireball"));
|
||||
|
||||
json_config(json);
|
||||
sp = find_spell("fireball");
|
||||
CuAssertPtrNotNull(tc, sp);
|
||||
CuAssertStrEquals(tc, "u+", sp->syntax);
|
||||
|
||||
test_cleanup();
|
||||
CuAssertPtrEquals(tc, 0, find_spell("fireball"));
|
||||
}
|
||||
|
||||
static void test_buildings(CuTest * tc)
|
||||
{
|
||||
const char * data = "{\"buildings\": { \"house\" : { "
|
||||
|
@ -331,6 +352,7 @@ CuSuite *get_jsonconf_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_terrains);
|
||||
SUITE_ADD_TEST(suite, test_races);
|
||||
SUITE_ADD_TEST(suite, test_strings);
|
||||
SUITE_ADD_TEST(suite, test_spells);
|
||||
SUITE_ADD_TEST(suite, test_flags);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <util/log.h>
|
||||
|
||||
CuSuite *get_tests_suite(void);
|
||||
CuSuite *get_callback_suite(void);
|
||||
CuSuite *get_jsonconf_suite(void);
|
||||
CuSuite *get_json_suite(void);
|
||||
CuSuite *get_economy_suite(void);
|
||||
|
@ -41,6 +42,7 @@ int RunAllTests(void)
|
|||
|
||||
/* self-test */
|
||||
CuSuiteAddSuite(suite, get_tests_suite());
|
||||
CuSuiteAddSuite(suite, get_callback_suite());
|
||||
CuSuiteAddSuite(suite, get_json_suite());
|
||||
CuSuiteAddSuite(suite, get_jsonconf_suite());
|
||||
CuSuiteAddSuite(suite, get_direction_suite());
|
||||
|
|
|
@ -7,3 +7,4 @@ require "tests.ships"
|
|||
require "tests.study"
|
||||
require "tests.movement"
|
||||
require "tests.castles"
|
||||
require "tests.spells"
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.spells", package.seeall, lunit.testcase)
|
||||
|
||||
function setup()
|
||||
eressea.game.reset()
|
||||
eressea.settings.set("nmr.removenewbie", "0")
|
||||
eressea.settings.set("nmr.timeout", "0")
|
||||
conf = [[{
|
||||
"races": {
|
||||
"human" : {}
|
||||
},
|
||||
"terrains" : {
|
||||
"plain": { "flags" : [ "land", "walk", "sail" ] }
|
||||
},
|
||||
"spells" : {
|
||||
"resist_magic" : {
|
||||
"index" : 97,
|
||||
"parameters" : "u+"
|
||||
}
|
||||
},
|
||||
"keywords" : {
|
||||
"de" : {
|
||||
"cast" : "ZAUBERE"
|
||||
}
|
||||
},
|
||||
"strings" : {
|
||||
"de" : {
|
||||
"harbour" : "Hafen"
|
||||
}
|
||||
}
|
||||
}]]
|
||||
|
||||
eressea.config.reset()
|
||||
assert(eressea.config.parse(conf)==0)
|
||||
end
|
||||
|
||||
function test_antimagic_visibility()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f1 = faction.create("test@example.com", "human", "de")
|
||||
local mage = unit.create(f1, r, 1)
|
||||
local target = unit.create(f1, r, 1)
|
||||
mage:set_skill("magic", 10)
|
||||
mage:add_spell("resist_magic")
|
||||
mage:add_order("ZAUBERE Antimagie " .. target.id)
|
||||
process_orders()
|
||||
end
|
Loading…
Reference in New Issue