remove archetypes, they are not used by any existing game.

make compiling with libxml2 optional (USE_LIBXML2)
disable xml reports
This commit is contained in:
Enno Rehling 2014-06-09 19:04:11 -07:00
parent 3c4b6b9dd4
commit a304b981d5
15 changed files with 36 additions and 470 deletions

View File

@ -66,7 +66,11 @@ ELSE(CMAKE_COMPILER_IS_GNUCC)
MESSAGE(STATUS "Unknown compiler ${CMAKE_C_COMPILER_ID}")
ENDIF(CMAKE_COMPILER_IS_GNUCC)
find_package (LibXml2 REQUIRED)
find_package (LibXml2)
if (LIBXML2_FOUND)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_LIBXML2")
endif(LIBXML2_FOUND)
find_package (SQLite3 REQUIRED)
find_package (Curses REQUIRED)
find_package (Lua REQUIRED)

View File

@ -21,7 +21,6 @@ include_directories (${CRYPTO_INCLUDE_DIR})
include_directories (${QUICKLIST_INCLUDE_DIR})
include_directories (${CUTEST_INCLUDE_DIR})
include_directories (${LUA_INCLUDE_DIR})
include_directories (${LIBXML2_INCLUDE_DIR})
include_directories (${BSON_INCLUDE_DIR})
include_directories (${INIPARSER_INCLUDE_DIR})
include_directories (${CURSES_INCLUDE_DIR})
@ -65,7 +64,6 @@ set (SERVER_SRC
settings.pkg.c
eressea.c
json.c
archetype.c
creation.c
creport.c
economy.c
@ -79,7 +77,7 @@ set (SERVER_SRC
spy.c
study.c
summary.c
xmlreport.c
# xmlreport.c
gmtool.c
monsters.c
bind_building.c
@ -88,11 +86,11 @@ set (SERVER_SRC
bind_gmtool.c
bind_hashtable.c
bindings.c
helpers.c
helpers.c
bind_message.c
bind_monsters.c
bind_process.c
bind_region.c
bind_process.c
bind_region.c
bind_settings.c
bind_ship.c
bind_sqlite.c
@ -113,7 +111,6 @@ target_link_libraries(eressea
${LUA_LIBRARIES}
${TOLUA_LIBRARIES}
${QUICKLIST_LIBRARIES}
${LIBXML2_LIBRARIES}
${STORAGE_LIBRARIES}
${SQLITE3_LIBRARIES}
${CRITBIT_LIBRARIES}
@ -141,7 +138,6 @@ target_link_libraries(test_eressea
${LUA_LIBRARIES}
${TOLUA_LIBRARIES}
${QUICKLIST_LIBRARIES}
${LIBXML2_LIBRARIES}
${STORAGE_LIBRARIES}
${SQLITE3_LIBRARIES}
${CRITBIT_LIBRARIES}
@ -164,3 +160,10 @@ add_test(
)
install(TARGETS eressea DESTINATION bin)
if (LIBXML2_FOUND)
include_directories (${LIBXML2_INCLUDE_DIR})
target_link_libraries(eressea ${LIBXML2_LIBRARIES})
target_link_libraries(test_eressea ${LIBXML2_LIBRARIES})
endif(LIBXML2_FOUND)

View File

@ -1,161 +0,0 @@
#include <platform.h>
#include <kernel/config.h>
#include "archetype.h"
/* kernel includes */
#include <kernel/equipment.h>
#include <kernel/building.h>
#include <kernel/xmlkernel.h>
#include <kernel/xmlreader.h>
/* util includes */
#include <util/attrib.h>
#include <util/umlaut.h>
#include <util/language.h>
#include <util/xml.h>
#include <util/functions.h>
/* libxml includes */
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <libxml/encoding.h>
/* libc includes */
#include <string.h>
#include <assert.h>
static struct archetype *archetypes;
struct attrib_type at_recruit = {
"recruit", NULL, NULL, NULL, NULL, NULL, ATF_UNIQUE
};
const struct archetype *find_archetype(const char *s, const struct locale *lang)
{
void **tokens = get_translations(lang, UT_ARCHETYPES);
variant token;
if (tokens && findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
return (const struct archetype *)token.v;
}
return NULL;
}
void register_archetype(archetype * arch)
{
arch->next = archetypes;
archetypes = arch;
}
void init_archetypes(void)
{
const struct locale *lang = locales;
for (; lang; lang = nextlocale(lang)) {
variant var;
archetype *arch = archetypes;
void *tokens = get_translations(lang, UT_ARCHETYPES);
for (; arch; arch = arch->next) {
const char *s1, *s2;
var.v = arch;
s1 = LOC(lang, arch->name[0]);
addtoken(tokens, s1, var);
s2 = LOC(lang, arch->name[1]);
if (strcmp(s2, s1) != 0) {
addtoken(tokens, s2, var);
}
}
}
}
static int parse_archetypes(xmlDocPtr doc)
{
char zName[64];
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
xmlXPathObjectPtr result =
xmlXPathEvalExpression(BAD_CAST "/eressea/archetypes/archetype", xpath);
xmlNodeSetPtr nodes = result->nodesetval;
xmlChar *propValue;
if (nodes) {
int i;
for (i = 0; i != nodes->nodeNr; ++i) {
xmlNodePtr node = nodes->nodeTab[i];
xmlNodePtr child;
archetype *arch = calloc(1, sizeof(archetype));
xmlXPathObjectPtr sub;
propValue = xmlGetProp(node, BAD_CAST "name");
assert(propValue != NULL);
arch->name[0] = _strdup((const char *)propValue);
sprintf(zName, "%s_p", arch->name[0]);
arch->name[1] = _strdup(zName);
xmlFree(propValue);
propValue = xmlGetProp(node, BAD_CAST "equip");
if (propValue != NULL) {
arch->equip = get_equipment((const char *)propValue);
xmlFree(propValue);
} else {
arch->equip = get_equipment(arch->name[0]);
}
propValue = xmlGetProp(node, BAD_CAST "building");
if (propValue != NULL) {
arch->btype = bt_find((const char *)propValue);
xmlFree(propValue);
}
arch->size = xml_ivalue(node, "cost", 0);
for (child = node->children; child; child = child->next) {
if (strcmp((const char *)child->name, "function") == 0) {
xmlChar *propName = xmlGetProp(child, BAD_CAST "name");
xmlChar *propValue = xmlGetProp(child, BAD_CAST "value");
if (strcmp((const char *)propName, "create")) {
pf_generic foo = get_function((const char *)propValue);
arch->exec = (archetype_function) foo;
}
xmlFree(propValue);
xmlFree(propName);
}
}
xpath->node = node;
sub = xmlXPathEvalExpression(BAD_CAST "allow|deny", xpath);
if (sub->nodesetval && sub->nodesetval->nodeNr) {
int k;
arch->rules = calloc(sub->nodesetval->nodeNr + 1, sizeof(rule));
for (k = 0; k != sub->nodesetval->nodeNr; ++k) {
xmlNodePtr rule = sub->nodesetval->nodeTab[k];
arch->rules[k].allow = (rule->name[0] == 'a');
propValue = xmlGetProp(rule, BAD_CAST "property");
arch->rules[k].property = _strdup((const char *)propValue);
xmlFree(propValue);
propValue = xmlGetProp(rule, BAD_CAST "value");
arch->rules[k].value = _strdup((const char *)propValue);
xmlFree(propValue);
}
}
xmlXPathFreeObject(sub);
xpath->node = node;
sub = xmlXPathEvalExpression(BAD_CAST "construction", xpath);
if (sub->nodesetval) {
xml_readconstruction(xpath, sub->nodesetval, &arch->ctype);
}
xmlXPathFreeObject(sub);
register_archetype(arch);
}
}
xmlXPathFreeObject(result);
xmlXPathFreeContext(xpath);
return 0;
}
void register_archetypes(void)
{
xml_register_callback(parse_archetypes);
}

View File

@ -1,52 +0,0 @@
/* vi: set ts=2:
+-------------------+
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
| (c) 1998 - 2007 | Katja Zedel <katze@felidae.kn-bremen.de>
| | Henning Peters <faroul@beyond.kn-bremen.de>
+-------------------+
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#ifndef H_GC_ARCHETYPE
#define H_GC_ARCHETYPE
#ifdef __cplusplus
extern "C" {
#endif
typedef struct rule {
bool allow;
char *property;
char *value;
} rule;
struct archetype;
typedef int (*archetype_function) (struct unit * u, const struct archetype *,
int);
typedef struct archetype {
struct archetype *next;
char *name[2];
int size;
struct building_type *btype;
struct equipment *equip;
struct construction *ctype;
struct rule *rules;
archetype_function exec;
} archetype;
extern const struct archetype *find_archetype(const char *s,
const struct locale *lang);
extern void init_archetypes(void);
extern void register_archetype(struct archetype *arch);
extern void register_archetypes(void);
extern struct attrib_type at_recruit;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -22,7 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "economy.h"
/* gamecode includes */
#include "archetype.h"
#include "give.h"
#include "laws.h"
#include "randenc.h"
@ -101,7 +100,6 @@ static request *oa;
#define RECRUIT_MERGE 1
#define RECRUIT_CLASSIC 2
#define RECRUIT_ARCHETYPES 4
static int rules_recruit = -1;
static void recruit_init(void)
@ -114,9 +112,6 @@ static void recruit_init(void)
if (get_param_int(global.parameters, "recruit.classic", 1)) {
rules_recruit |= RECRUIT_CLASSIC;
}
if (get_param_int(global.parameters, "recruit.archetype", 0)) {
rules_recruit |= RECRUIT_ARCHETYPES;
}
}
}
@ -510,7 +505,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders)
if (u->number == 0) {
str = getstrtoken();
if (str && str[0]) {
/* Monster dürfen REKRUTIERE 15 dracoid machen
/* Monsters can RECRUIT 15 DRACOID
* also: secondary race */
rc = findrace(str, f->locale);
if (rc != NULL) {
@ -1145,152 +1140,6 @@ void maintain_buildings(region * r, bool crash)
}
}
static int recruit_archetype(unit * u, order * ord)
{
bool merge = (u->number > 0);
int want;
const char *s;
if (rules_recruit < 0)
recruit_init();
init_tokens(ord);
skip_token();
want = getuint();
s = getstrtoken();
if (want > 0 && s && s[0]) {
int n = want;
const archetype *arch = find_archetype(s, u->faction->locale);
attrib *a = NULL;
if ((rules_recruit & RECRUIT_MERGE) == 0 && merge) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_must_be_new", ""));
/* TODO: error message */
return 0;
}
if (arch == NULL) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unknown_archetype",
"name", s));
/* TODO: error message */
return 0;
}
if (arch->rules) {
/* Simple allow/deny style restrictions for archetypes (let only humans
* recruit gamedesigners, etc). These need to be more powerful to be
* useful, and the current way they are implemented is not, but the
* general idea strikes me as good. Also, feedback should be configurable
* for each failed rule.
*/
int k;
for (k = 0; arch->rules[k].property; ++k) {
bool match = false;
if (arch->rules[k].value[0] == '*')
match = true;
else if (strcmp(arch->rules[k].property, "race") == 0) {
const race *rc = rc_find(arch->rules[k].value);
assert(rc);
if (rc == u_race(u))
match = true;
} else if (strcmp(arch->rules[k].property, "building") == 0) {
const building_type *btype = bt_find(arch->rules[k].value);
assert(btype);
if (u->building && u->building->type == btype)
match = true;
}
if (match) {
if (arch->rules[k].allow)
break;
else {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "recruit_rule_fail",
"property value", arch->rules[k].property,
arch->rules[k].value));
/* TODO: error message */
return 0;
}
}
}
}
if (arch->btype) {
if (u->building == NULL || u->building->type != arch->btype) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
"unit_must_be_in_building", "type", arch->btype));
/* TODO: error message */
return 0;
}
if (arch->size) {
int maxsize = u->building->size;
attrib *a = a_find(u->building->attribs, &at_recruit);
if (a != NULL) {
maxsize -= a->data.i;
}
n = _min(maxsize / arch->size, n);
if (n <= 0) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
"recruit_capacity_exhausted", "building", u->building));
/* TODO: error message */
return 0;
}
}
}
n = build(u, arch->ctype, 0, n);
if (n > 0) {
unit *u2;
if (merge) {
u2 = create_unit(u->region, u->faction, 0, u_race(u), 0, 0, u);
} else {
u2 = u;
}
if (arch->exec) {
n = arch->exec(u2, arch, n);
} else {
set_number(u2, n);
equip_unit(u2, arch->equip);
u2->hp = n * unit_max_hp(u2);
if (arch->size) {
if (a == NULL)
a = a_add(&u->building->attribs, a_new(&at_recruit));
a->data.i += n * arch->size;
}
}
ADDMSG(&u->faction->msgs, msg_message("recruit_archetype",
"unit amount archetype", u, n, arch->name[n == 1]));
if (u != u2 && u_race(u) == u_race(u2)) {
transfermen(u2, u, u2->number);
}
return n;
} else
switch (n) {
case ENOMATERIALS:
ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, arch->ctype,
want));
break;
case ELOWSKILL:
case ENEEDSKILL:
/* no skill, or not enough skill points to build */
cmistake(u, ord, 50, MSG_PRODUCE);
break;
case EBUILDINGREQ:
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "building_needed", "building",
arch->ctype->btype->_name));
break;
default:
assert(!"unhandled return value from build() in recruit_archetype");
}
return 0;
}
return -1;
}
int recruit_archetypes(void)
{
if (rules_recruit < 0)
recruit_init();
return (rules_recruit & RECRUIT_ARCHETYPES) != 0;
}
void economics(region * r)
{
unit *u;
@ -1333,11 +1182,6 @@ void economics(region * r)
if ((rules_recruit & RECRUIT_MERGE) || u->number == 0) {
for (ord = u->orders; ord; ord = ord->next) {
if (get_keyword(ord) == K_RECRUIT) {
if (rules_recruit & RECRUIT_ARCHETYPES) {
if (recruit_archetype(u, ord) >= 0) {
continue;
}
}
if (rules_recruit & RECRUIT_CLASSIC) {
recruit(u, ord, &recruitorders);
}

View File

@ -24,11 +24,9 @@
#include <modules/xmas.h>
#include <items/itemtypes.h>
#include <attributes/attributes.h>
#include "archetype.h"
#include "report.h"
#include "items.h"
#include "creport.h"
#include "xmlreport.h"
void game_done(void)
{
@ -58,7 +56,6 @@ void game_init(void)
register_reports();
register_nr();
register_cr();
register_xr();
register_names();
register_resources();
@ -76,8 +73,9 @@ void game_init(void)
register_wormholes();
register_itemtypes();
#ifdef USE_LIBXML2
register_xmlreader();
register_archetypes();
#endif
register_attributes();
register_gmcmd();

View File

@ -286,29 +286,6 @@ void give_men(int n, unit * u, unit * u2, struct order *ord)
}
if (u2) {
if (u2->number != 0 && recruit_archetypes()) {
/* must have same set of skills */
bool okay = false;
if (u->skill_size == u2->skill_size) {
int i;
for (i = 0; i != u->skill_size; ++i) {
int j;
for (j = 0; j != u2->skill_size; ++j) {
if (u->skills[i].id == u2->skills[j].id)
break;
}
if (j != u2->skill_size)
break;
}
if (i == u->skill_size)
okay = true;
}
if (!okay) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "give_cannot_merge",
""));
}
}
/* Einheiten von Schiffen können nicht NACH in von
* Nicht-alliierten bewachten Regionen ausführen */
sh = leftship(u);

View File

@ -29,8 +29,6 @@ without prior permission by the authors of Eressea.
#include <kernel/item.h>
#include <kernel/region.h>
#include "archetype.h"
#include <tolua.h>
#include <lua.h>
@ -558,35 +556,6 @@ lua_useitem(struct unit *u, const struct item_type *itype, int amount,
return result;
}
static int lua_recruit(struct unit *u, const struct archetype *arch, int amount)
{
lua_State *L = (lua_State *) global.vm_state;
int result = 0;
char fname[64];
strlcpy(fname, "recruit_", sizeof(fname));
strlcat(fname, arch->name[0], sizeof(fname));
lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
tolua_pushnumber(L, (lua_Number) amount);
if (lua_pcall(L, 2, 1, 0) != 0) {
const char *error = lua_tostring(L, -1);
log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error);
lua_pop(L, 1);
} else {
result = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
}
} else {
log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
}
return result;
}
int tolua_toid(lua_State * L, int idx, int def)
{
int no = 0;
@ -610,7 +579,6 @@ void register_tolua_helpers(void)
TOLUA_CAST "lua_building_taxes");
register_function((pf_generic) & lua_agebuilding,
TOLUA_CAST "lua_agebuilding");
register_function((pf_generic) & lua_recruit, TOLUA_CAST "lua_recruit");
register_function((pf_generic) & lua_callspell, TOLUA_CAST "lua_castspell");
register_function((pf_generic) & lua_initfamiliar,
TOLUA_CAST "lua_initfamiliar");

View File

@ -74,7 +74,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static FILE *bdebug;
#define TACTICS_BONUS 1 /* when undefined, we have a tactics round. else this is the bonus tactics give */
#define TACTICS_MODIFIER 1 /* modifier for generals in the fromt/rear */
#define TACTICS_MODIFIER 1 /* modifier for generals in the front/rear */
#define CATAPULT_INITIAL_RELOAD 4 /* erster schuss in runde 1 + rng_int() % INITIAL */
#define CATAPULT_STRUCTURAL_DAMAGE

View File

@ -1,28 +0,0 @@
/* vi: set ts=2:
+-------------------+
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
| (c) 1998 - 2007 | Katja Zedel <katze@felidae.kn-bremen.de>
| | Henning Peters <faroul@beyond.kn-bremen.de>
+-------------------+
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#ifndef H_KRNL_XML
#define H_KRNL_XML
#ifdef __cplusplus
extern "C" {
#endif
#include <libxml/xpath.h>
extern void xml_readconstruction(xmlXPathContextPtr xpath,
xmlNodeSetPtr nodeSet, struct construction **consPtr);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -40,10 +40,12 @@ without prior permission by the authors of Eressea.
#include <util/nrmessage.h>
#include <util/xml.h>
#ifdef USE_LIBXML2
/* libxml includes */
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <libxml/encoding.h>
#endif
/* libc includes */
#include <assert.h>
@ -51,6 +53,7 @@ without prior permission by the authors of Eressea.
#include <limits.h>
#include <string.h>
#ifdef USE_LIBXML2
static void xml_readtext(xmlNodePtr node, struct locale **lang, xmlChar ** text)
{
xmlChar *propValue = xmlGetProp(node, BAD_CAST "locale");
@ -2364,3 +2367,4 @@ void register_xmlreader(void)
xml_register_callback(parse_calendar);
xml_register_callback(parse_directions);
}
#endif

View File

@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* gamecode includes */
#include "economy.h"
#include "archetype.h"
#include "monster.h"
#include "randenc.h"
#include "spy.h"
@ -4717,7 +4716,6 @@ int init_data(const char *filename, const char *catalog)
return l;
init_locales();
init_archetypes();
if (turn < 0) {
turn = first_turn;

View File

@ -85,6 +85,7 @@ double xml_fvalue(xmlNodePtr node, const char *name, double dflt)
#include <libxml/parser.h>
#include <libxml/xinclude.h>
#ifdef USE_LIBXML2
typedef struct xml_reader {
struct xml_reader *next;
xml_callback callback;
@ -103,9 +104,11 @@ void xml_register_callback(xml_callback callback)
insert = &(*insert)->next;
*insert = reader;
}
#endif
int read_xml(const char *filename, const char *catalog)
{
#ifdef USE_LIBXML2
xml_reader *reader = xmlReaders;
xmlDocPtr doc;
int result;
@ -132,4 +135,8 @@ int read_xml(const char *filename, const char *catalog)
}
xmlFreeDoc(doc);
return result;
#else
log_error("LIBXML2 disabled, cannot read %s.\n", filename);
return -1;
#endif
}

View File

@ -17,17 +17,19 @@
extern "C" {
#endif
#ifdef USE_LIBXML2
/* new xml functions: */
#include <libxml/tree.h>
typedef int (*xml_callback) (xmlDocPtr);
extern void xml_register_callback(xml_callback callback);
extern int read_xml(const char *filename, const char *catalog);
extern double xml_fvalue(xmlNodePtr node, const char *name, double dflt);
extern int xml_ivalue(xmlNodePtr node, const char *name, int dflt);
extern bool xml_bvalue(xmlNodePtr node, const char *name, bool dflt);
const xmlChar *xml_i(double number);
#endif
extern int read_xml(const char *filename, const char *catalog);
#ifdef __cplusplus
}

View File

@ -64,12 +64,14 @@ without prior permission by the authors of Eressea.
#include <util/unicode.h>
#include <util/xml.h>
#ifdef USE_LIBXML2
/* libxml2 includes */
#include <libxml/tree.h>
#include <libxml/encoding.h>
#ifdef USE_ICONV
#include <iconv.h>
#endif
#endif
/* libc includes */
#include <assert.h>