forked from github/server
Merge branch 'master' of github.com:badgerman/eressea
This commit is contained in:
commit
17e86ab6cd
47 changed files with 790 additions and 515 deletions
5
conf/e2/config.json
Normal file
5
conf/e2/config.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"include": [
|
||||||
|
"keywords.json"
|
||||||
|
]
|
||||||
|
}
|
5
conf/e3/config.json
Normal file
5
conf/e3/config.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"include": [
|
||||||
|
"keywords.json"
|
||||||
|
]
|
||||||
|
}
|
5
conf/e4/config.json
Normal file
5
conf/e4/config.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"include": [
|
||||||
|
"keywords.json"
|
||||||
|
]
|
||||||
|
}
|
65
conf/keywords.json
Normal file
65
conf/keywords.json
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
{
|
||||||
|
"keywords": {
|
||||||
|
"de": {
|
||||||
|
"//" : "//",
|
||||||
|
"banner": "BANNER",
|
||||||
|
"work": [ "ARBEITE", "ARBEITEN" ],
|
||||||
|
"attack": ["ATTACKIERE", "ATTACKIEREN"],
|
||||||
|
"steal": [ "BEKLAUE", "BEKLAUEN" ],
|
||||||
|
"besiege": ["BELAGERE", "BELAGERN" ],
|
||||||
|
"name": [ "BENENNE", "BENENNEN" ],
|
||||||
|
"use": [ "BENUTZE", "BENUTZEN" ],
|
||||||
|
"describe": [ "BESCHREIBE", "BESCHREIBEN" ],
|
||||||
|
"enter": ["BETRETE", "BETRETEN"],
|
||||||
|
"guard": ["BEWACHE", "BEWACHEN"],
|
||||||
|
"message": "BOTSCHAFT",
|
||||||
|
"end": "ENDE",
|
||||||
|
"ride": ["REITE", "REITEN"],
|
||||||
|
"number": "NUMMER",
|
||||||
|
"follow": ["FOLGE","FOLGEN"],
|
||||||
|
"research": ["FORSCHE", "FORSCHEN"],
|
||||||
|
"give": "GIB",
|
||||||
|
"help": [ "HELFE", "HELFEN" ],
|
||||||
|
"combat": [ "KÄMPFE", "KÄMPFEN" ],
|
||||||
|
"ready" : "KAMPFZAUBER",
|
||||||
|
"buy" : [ "KAUFE", "KAUFEN"],
|
||||||
|
"contact": [ "KONTAKT", "KONTAKTIEREN"],
|
||||||
|
"teach": ["LEHRE", "LEHREN"],
|
||||||
|
"study": ["LERNE", "LERNEN"],
|
||||||
|
"make": ["MACHE", "MACHEN"],
|
||||||
|
"maketemp": ["MACHE TEMP", "MACHETEMP"],
|
||||||
|
"move" : "NACH",
|
||||||
|
"password" : "PASSWORD",
|
||||||
|
"recruit": ["REKRUTIERE", "REKRUTIEREN"],
|
||||||
|
"reserve": ["RESERVIERE", "RESERVIEREN"],
|
||||||
|
"route": "ROUTE",
|
||||||
|
"sabotage": ["SABOTIERE", "SABOTIEREN"],
|
||||||
|
"option": "OPTION",
|
||||||
|
"spy": ["SPIONIERE", "SPIONIEREN"],
|
||||||
|
"quit": "STIRB",
|
||||||
|
"hide": ["TARNE", "TARNEN"],
|
||||||
|
"carry": ["TRANSPORTIERE", "TRANSPORTIEREN"],
|
||||||
|
"tax": ["TREIBE", "TREIBEN", "STEUERN"],
|
||||||
|
"entertain": ["UNTERHALTE", "UNTERHALTEN"],
|
||||||
|
"sell": ["VERKAUFE", "VERKAUFEN"],
|
||||||
|
"leave": ["VERLASSE", "VERLASSEN"],
|
||||||
|
"forget": ["VERGISS", "VERGESSEN"],
|
||||||
|
"cast": ["ZAUBERE", "ZAUBERN"],
|
||||||
|
"show": ["ZEIGE", "ZEIGEN"],
|
||||||
|
"destroy": ["ZERSTÖRE", "ZERSTÖREN"],
|
||||||
|
"grow": ["ZÜCHTE", "ZÜCHTEN"],
|
||||||
|
"default": "DEFAULT",
|
||||||
|
"origin": "URSPRUNG",
|
||||||
|
"email": "EMAIL",
|
||||||
|
"piracy": "PIRATERIE",
|
||||||
|
"group": "GRUPPE",
|
||||||
|
"sort": ["SORTIERE", "SORTIEREN"],
|
||||||
|
"prefix": "PRÄFIX",
|
||||||
|
"plant": ["PFLANZE", "PFLANZEN"],
|
||||||
|
"alliance": "ALLIANZ",
|
||||||
|
"claim": ["BEANSPRUCHE", "BEANSPRUCHEN"],
|
||||||
|
"promote": ["BEFÖRDERE", "BEFÖRDERUNG"],
|
||||||
|
"pay": ["BEZAHLE", "BEZAHLEN"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2111,199 +2111,6 @@
|
||||||
</string>
|
</string>
|
||||||
</namespace>
|
</namespace>
|
||||||
|
|
||||||
<namespace name="keyword">
|
|
||||||
<!--Befehle -->
|
|
||||||
<string name="//">
|
|
||||||
<text locale="de">//</text>
|
|
||||||
</string>
|
|
||||||
<string name="banner">
|
|
||||||
<text locale="de">BANNER</text>
|
|
||||||
</string>
|
|
||||||
<string name="work">
|
|
||||||
<text locale="de">ARBEITEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="attack">
|
|
||||||
<text locale="de">ATTACKIEREN</text>
|
|
||||||
</string>
|
|
||||||
<string name="claim">
|
|
||||||
<text locale="de">BEANSPRUCHEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="steal">
|
|
||||||
<text locale="de">BEKLAUEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="besiege">
|
|
||||||
<text locale="de">BELAGERE</text>
|
|
||||||
</string>
|
|
||||||
<string name="name">
|
|
||||||
<text locale="de">BENENNEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="use">
|
|
||||||
<text locale="de">BENUTZEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="describe">
|
|
||||||
<text locale="de">BESCHREIBEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="enter">
|
|
||||||
<text locale="de">BETRETEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="give">
|
|
||||||
<text locale="de">GIB</text>
|
|
||||||
</string>
|
|
||||||
<string name="guard">
|
|
||||||
<text locale="de">BEWACHEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="message">
|
|
||||||
<text locale="de">BOTSCHAFT</text>
|
|
||||||
</string>
|
|
||||||
<string name="end">
|
|
||||||
<text locale="de">ENDE</text>
|
|
||||||
</string>
|
|
||||||
<string name="ride">
|
|
||||||
<text locale="de">FAHREN</text>
|
|
||||||
</string>
|
|
||||||
<string name="number">
|
|
||||||
<text locale="de">NUMMER</text>
|
|
||||||
</string>
|
|
||||||
<string name="follow">
|
|
||||||
<text locale="de">FOLGEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="research">
|
|
||||||
<text locale="de">FORSCHEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="help">
|
|
||||||
<text locale="de">HELFEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="fight">
|
|
||||||
<text locale="de">KÄMPFEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="ready">
|
|
||||||
<text locale="de">KAMPFZAUBER</text>
|
|
||||||
</string>
|
|
||||||
<string name="buy">
|
|
||||||
<text locale="de">KAUFEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="contact">
|
|
||||||
<text locale="de">KONTAKTIEREN</text>
|
|
||||||
</string>
|
|
||||||
<string name="teach">
|
|
||||||
<text locale="de">LEHREN</text>
|
|
||||||
</string>
|
|
||||||
<string name="study">
|
|
||||||
<text locale="de">LERNEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="locale">
|
|
||||||
<text locale="de">LOCALE</text>
|
|
||||||
</string>
|
|
||||||
<string name="make">
|
|
||||||
<text locale="de">MACHEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="maketemp">
|
|
||||||
<text locale="de">MACHETEMP</text>
|
|
||||||
</string>
|
|
||||||
<string name="move">
|
|
||||||
<text locale="de">NACH</text>
|
|
||||||
</string>
|
|
||||||
<string name="alliance">
|
|
||||||
<text locale="de">ALLIANZ</text>
|
|
||||||
</string>
|
|
||||||
<string name="promote">
|
|
||||||
<text locale="de">BEFÖRDERUNG</text>
|
|
||||||
</string>
|
|
||||||
<string name="pay">
|
|
||||||
<text locale="de">BEZAHLEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="plant">
|
|
||||||
<text locale="de">PFLANZEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="prefix">
|
|
||||||
<text locale="de">PRÄFIX</text>
|
|
||||||
</string>
|
|
||||||
<string name="info">
|
|
||||||
<text locale="de">INFO</text>
|
|
||||||
</string>
|
|
||||||
<string name="password">
|
|
||||||
<text locale="de">PASSWORT</text>
|
|
||||||
</string>
|
|
||||||
<string name="recruit">
|
|
||||||
<text locale="de">REKRUTIEREN</text>
|
|
||||||
</string>
|
|
||||||
<string name="reserve">
|
|
||||||
<text locale="de">RESERVIEREN</text>
|
|
||||||
</string>
|
|
||||||
<string name="route">
|
|
||||||
<text locale="de">ROUTE</text>
|
|
||||||
</string>
|
|
||||||
<string name="sabotage">
|
|
||||||
<text locale="de">SABOTIEREN</text>
|
|
||||||
</string>
|
|
||||||
<string name="option">
|
|
||||||
<text locale="de">OPTION</text>
|
|
||||||
</string>
|
|
||||||
<string name="spy">
|
|
||||||
<text locale="de">SPIONIEREN</text>
|
|
||||||
</string>
|
|
||||||
<string name="quit">
|
|
||||||
<text locale="de">STIRB</text>
|
|
||||||
</string>
|
|
||||||
<string name="hide">
|
|
||||||
<text locale="de">TARNEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="carry">
|
|
||||||
<text locale="de">TRANSPORTIEREN</text>
|
|
||||||
</string>
|
|
||||||
<string name="tax">
|
|
||||||
<text locale="de">TREIBEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="entertain">
|
|
||||||
<text locale="de">UNTERHALTEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="sell">
|
|
||||||
<text locale="de">VERKAUFEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="leave">
|
|
||||||
<text locale="de">VERLASSEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="forget">
|
|
||||||
<text locale="de">VERGESSEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="cast">
|
|
||||||
<text locale="de">ZAUBERE</text>
|
|
||||||
</string>
|
|
||||||
<string name="show">
|
|
||||||
<text locale="de">ZEIGEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="destroy">
|
|
||||||
<text locale="de">ZERSTÖREN</text>
|
|
||||||
</string>
|
|
||||||
<string name="grow">
|
|
||||||
<text locale="de">ZÜCHTEN</text>
|
|
||||||
</string>
|
|
||||||
<string name="default">
|
|
||||||
<text locale="de">DEFAULT</text>
|
|
||||||
</string>
|
|
||||||
<string name="report">
|
|
||||||
<text locale="de">REPORT</text>
|
|
||||||
</string>
|
|
||||||
<string name="origin">
|
|
||||||
<text locale="de">URSPRUNG</text>
|
|
||||||
</string>
|
|
||||||
<string name="email">
|
|
||||||
<text locale="de">EMAIL</text>
|
|
||||||
</string>
|
|
||||||
<string name="piracy">
|
|
||||||
<text locale="de">PIRATERIE</text>
|
|
||||||
</string>
|
|
||||||
<string name="locale">
|
|
||||||
<text locale="de">LOCALE</text>
|
|
||||||
</string>
|
|
||||||
<string name="group">
|
|
||||||
<text locale="de">GRUPPE</text>
|
|
||||||
</string>
|
|
||||||
<string name="sort">
|
|
||||||
<text locale="de">SORTIEREN</text>
|
|
||||||
</string>
|
|
||||||
</namespace>
|
|
||||||
|
|
||||||
<!--NR generieren -->
|
<!--NR generieren -->
|
||||||
<string name="nr_options">
|
<string name="nr_options">
|
||||||
<text locale="de">Optionen</text>
|
<text locale="de">Optionen</text>
|
||||||
|
|
|
@ -1451,9 +1451,6 @@
|
||||||
<string name="help">
|
<string name="help">
|
||||||
<text locale="en">HELP</text>
|
<text locale="en">HELP</text>
|
||||||
</string>
|
</string>
|
||||||
<string name="fight">
|
|
||||||
<text locale="en">FIGHT</text>
|
|
||||||
</string>
|
|
||||||
<string name="ready">
|
<string name="ready">
|
||||||
<text locale="en">COMBATSPELL</text>
|
<text locale="en">COMBATSPELL</text>
|
||||||
</string>
|
</string>
|
||||||
|
|
|
@ -3767,8 +3767,9 @@
|
||||||
<arg name="command" type="order"/>
|
<arg name="command" type="order"/>
|
||||||
</type>
|
</type>
|
||||||
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - Die Einheit kann nicht bewachen, da sie versucht zu fliehen."</text>
|
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - Die Einheit kann nicht bewachen, da sie versucht zu fliehen."</text>
|
||||||
<text locale="fr">"$unit($unit) in $region($region): '$order($command)' - The unit cannot guard the region because it's trying to flee."</text>
|
<text locale="en">"$unit($unit) in $region($region):
|
||||||
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - The unit cannot guard the region because it's trying to flee."</text>
|
'$order($command)' - The unit cannot guard the region because it
|
||||||
|
is trying to flee."</text>
|
||||||
</message>
|
</message>
|
||||||
|
|
||||||
<message name="error319" section="errors">
|
<message name="error319" section="errors">
|
||||||
|
@ -3778,7 +3779,6 @@
|
||||||
<arg name="command" type="order"/>
|
<arg name="command" type="order"/>
|
||||||
</type>
|
</type>
|
||||||
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - Die Einheit kann den Befehl in dieser Runde nicht ausführen, da sie an einem Kampf teilgenommen hat."</text>
|
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - Die Einheit kann den Befehl in dieser Runde nicht ausführen, da sie an einem Kampf teilgenommen hat."</text>
|
||||||
<text locale="fr">"$unit($unit) in $region($region): '$order($command)' - The unit cannot execute this command because it has been in combat."</text>
|
|
||||||
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - The unit cannot execute this command because it has been in combat."</text>
|
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - The unit cannot execute this command because it has been in combat."</text>
|
||||||
</message>
|
</message>
|
||||||
|
|
||||||
|
@ -8365,7 +8365,8 @@
|
||||||
<arg name="command" type="order"/>
|
<arg name="command" type="order"/>
|
||||||
</type>
|
</type>
|
||||||
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - Es ist so schön friedlich, man möchte hier niemanden angreifen."</text>
|
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - Es ist so schön friedlich, man möchte hier niemanden angreifen."</text>
|
||||||
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - It's so quiet and peaceful, nobody wants to attack anybody right now."</text>
|
<text locale="en">"$unit($unit) in $region($region):
|
||||||
|
'$order($command)' - It is so quiet and peaceful, nobody wants to attack anybody right now."</text>
|
||||||
</message>
|
</message>
|
||||||
|
|
||||||
<message name="error_race_nolearn" section="errors">
|
<message name="error_race_nolearn" section="errors">
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
local confdir = 'conf/'
|
local confdir = 'conf/'
|
||||||
if config.rules then
|
|
||||||
confdir = confdir .. config.rules .. '/'
|
|
||||||
end
|
|
||||||
if config.install then
|
if config.install then
|
||||||
confdir = config.install .. '/' .. confdir
|
confdir = config.install .. '/' .. confdir
|
||||||
end
|
end
|
||||||
read_xml(confdir .. 'config.xml', confdir .. 'catalog.xml')
|
rules=''
|
||||||
|
if config.rules then
|
||||||
|
rules = config.rules .. '/'
|
||||||
|
end
|
||||||
|
read_xml(confdir .. rules .. 'config.xml', confdir .. rules .. 'catalog.xml')
|
||||||
|
eressea.config.read(rules .. 'config.json', confdir)
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
#include <cJSON.h>
|
#include <cJSON.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "kernel/building.h"
|
#include "kernel/building.h"
|
||||||
#include "kernel/race.h"
|
#include "kernel/race.h"
|
||||||
|
@ -48,8 +50,34 @@ int config_parse(const char *json)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int config_read(const char *filename)
|
int config_read(const char *filename, const char * relpath)
|
||||||
{
|
{
|
||||||
|
char name[MAX_PATH];
|
||||||
|
FILE *F;
|
||||||
|
|
||||||
|
json_relpath = relpath;
|
||||||
|
if (relpath) {
|
||||||
|
_snprintf(name, sizeof(name), "%s/%s", relpath, filename);
|
||||||
|
F = fopen(name, "rt");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
F = fopen(filename, "rt");
|
||||||
|
}
|
||||||
|
if (F) {
|
||||||
|
int result;
|
||||||
|
char *data;
|
||||||
|
size_t sz;
|
||||||
|
|
||||||
|
fseek(F, 0, SEEK_END);
|
||||||
|
sz = ftell(F);
|
||||||
|
rewind(F);
|
||||||
|
data = malloc(sz);
|
||||||
|
fread(data, 1, sz, F);
|
||||||
|
fclose(F);
|
||||||
|
result = config_parse(data);
|
||||||
|
free(data);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ extern "C" {
|
||||||
|
|
||||||
void config_reset(void);
|
void config_reset(void);
|
||||||
int config_parse(const char *json);
|
int config_parse(const char *json);
|
||||||
int config_read(const char *filename);
|
int config_read(const char *filename, const char * relpath);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ without prior permission by the authors of Eressea.
|
||||||
#include <quicklist.h>
|
#include <quicklist.h>
|
||||||
#include <util/rand.h>
|
#include <util/rand.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
|
#include <util/xml.h>
|
||||||
|
|
||||||
#include <storage.h>
|
#include <storage.h>
|
||||||
|
|
||||||
|
@ -1001,6 +1002,21 @@ static int tolua_get_spells(lua_State * L)
|
||||||
return tolua_quicklist_push(L, "spell_list", "spell", spells);
|
return tolua_quicklist_push(L, "spell_list", "spell", spells);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int init_data(const char *filename, const char *catalog)
|
||||||
|
{
|
||||||
|
int l;
|
||||||
|
l = read_xml(filename, catalog);
|
||||||
|
reset_locales();
|
||||||
|
if (l) {
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
if (turn < 0) {
|
||||||
|
turn = first_turn;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int tolua_read_xml(lua_State * L)
|
int tolua_read_xml(lua_State * L)
|
||||||
{
|
{
|
||||||
const char *filename = tolua_tostring(L, 1, "config.xml");
|
const char *filename = tolua_tostring(L, 1, "config.xml");
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#define VERSION_MAJOR 3
|
#define VERSION_MAJOR 3
|
||||||
#define VERSION_MINOR 3
|
#define VERSION_MINOR 3
|
||||||
#define VERSION_BUILD 685
|
#define VERSION_BUILD 687
|
||||||
|
|
|
@ -5,7 +5,7 @@ $#include "bind_config.h"
|
||||||
module eressea {
|
module eressea {
|
||||||
module config {
|
module config {
|
||||||
void config_reset @ reset(void);
|
void config_reset @ reset(void);
|
||||||
int config_read @ read(const char *filename);
|
int config_read @ read(const char *filename, const char *relpath);
|
||||||
int config_parse @ parse(const char *json);
|
int config_parse @ parse(const char *json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,16 +57,18 @@ static int tolua_config_eressea_config_read00(lua_State* tolua_S)
|
||||||
#ifndef TOLUA_RELEASE
|
#ifndef TOLUA_RELEASE
|
||||||
tolua_Error tolua_err;
|
tolua_Error tolua_err;
|
||||||
if (
|
if (
|
||||||
!tolua_isstring(tolua_S,1,0,&tolua_err) ||
|
!tolua_isstring(tolua_S, 1, 0, &tolua_err) ||
|
||||||
!tolua_isnoobj(tolua_S,2,&tolua_err)
|
!tolua_isstring(tolua_S, 2, 0, &tolua_err) ||
|
||||||
|
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||||
)
|
)
|
||||||
goto tolua_lerror;
|
goto tolua_lerror;
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
const char* filename = ((const char*) tolua_tostring(tolua_S,1,0));
|
const char* filename = ((const char*)tolua_tostring(tolua_S, 1, 0));
|
||||||
|
const char* relpath = ((const char*)tolua_tostring(tolua_S, 2, 0));
|
||||||
{
|
{
|
||||||
int tolua_ret = (int) config_read(filename);
|
int tolua_ret = (int) config_read(filename, relpath);
|
||||||
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
|
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1039,14 +1039,12 @@ static bool maintain(building * b, bool first)
|
||||||
u = building_owner(b);
|
u = building_owner(b);
|
||||||
if (u == NULL)
|
if (u == NULL)
|
||||||
return false;
|
return false;
|
||||||
/* If the owner is the region owner, check if biggest castle has the dontpay flag */
|
/* If the owner is the region owner, check if dontpay flag is set for the building where he is in */
|
||||||
if (check_param(global.parameters, "rules.region_owner_pay_building", b->type->_name)) {
|
if (check_param(global.parameters, "rules.region_owner_pay_building", b->type->_name)) {
|
||||||
if (u == building_owner(largestbuilding(r, &cmp_taxes, false))) {
|
|
||||||
if (fval(u->building, BLD_DONTPAY)) {
|
if (fval(u->building, BLD_DONTPAY)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for (c = 0; b->type->maintenance[c].number; ++c) {
|
for (c = 0; b->type->maintenance[c].number; ++c) {
|
||||||
const maintenance *m = b->type->maintenance + c;
|
const maintenance *m = b->type->maintenance + c;
|
||||||
int need = m->number;
|
int need = m->number;
|
||||||
|
|
|
@ -3,6 +3,7 @@ project(kernel C)
|
||||||
SET(_TEST_FILES
|
SET(_TEST_FILES
|
||||||
build.test.c
|
build.test.c
|
||||||
config.test.c
|
config.test.c
|
||||||
|
group.test.c
|
||||||
faction.test.c
|
faction.test.c
|
||||||
unit.test.c
|
unit.test.c
|
||||||
save.test.c
|
save.test.c
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
ally * ally_find(ally *al, const struct faction *f) {
|
ally * ally_find(ally *al, const struct faction *f) {
|
||||||
for (;al;al=al->next) {
|
for (; al; al = al->next) {
|
||||||
if (al->faction==f) return al;
|
if (al->faction == f) return al;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ ally * ally_add(ally **al_p, struct faction *f) {
|
||||||
ally * al;
|
ally * al;
|
||||||
while (*al_p) {
|
while (*al_p) {
|
||||||
al = *al_p;
|
al = *al_p;
|
||||||
if (al->faction==f) return al;
|
if (f && al->faction == f) return al;
|
||||||
al_p = &al->next;
|
al_p = &al->next;
|
||||||
}
|
}
|
||||||
al = (ally *)malloc(sizeof(ally));
|
al = (ally *)malloc(sizeof(ally));
|
||||||
|
@ -29,7 +29,7 @@ void ally_remove(ally **al_p, struct faction *f) {
|
||||||
ally * al;
|
ally * al;
|
||||||
while (*al_p) {
|
while (*al_p) {
|
||||||
al = *al_p;
|
al = *al_p;
|
||||||
if (al->faction==f) {
|
if (al->faction == f) {
|
||||||
*al_p = al->next;
|
*al_p = al->next;
|
||||||
free(al);
|
free(al);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -19,10 +19,25 @@ static void test_ally(CuTest * tc)
|
||||||
CuAssertPtrEquals(tc, 0, ally_find(al, f1));
|
CuAssertPtrEquals(tc, 0, ally_find(al, f1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_ally_null(CuTest * tc)
|
||||||
|
{
|
||||||
|
ally *a1 = 0, *a2 = 0;
|
||||||
|
|
||||||
|
a1 = ally_add(&a1, 0);
|
||||||
|
a2 = ally_add(&a1, 0);
|
||||||
|
CuAssertPtrNotNull(tc, a1);
|
||||||
|
CuAssertPtrNotNull(tc, a2);
|
||||||
|
CuAssertPtrEquals(tc, a2, a1->next);
|
||||||
|
CuAssertPtrEquals(tc, 0, a2->next);
|
||||||
|
free(a1);
|
||||||
|
free(a2);
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_ally_suite(void)
|
CuSuite *get_ally_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_ally);
|
SUITE_ADD_TEST(suite, test_ally);
|
||||||
|
SUITE_ADD_TEST(suite, test_ally_null);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -673,7 +673,7 @@ static void init_gms(void)
|
||||||
faction *f;
|
faction *f;
|
||||||
|
|
||||||
for (f = factions; f; f = f->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
const attrib *a = a_findc(f->attribs, &at_gm);
|
attrib *a = a_find(f->attribs, &at_gm);
|
||||||
|
|
||||||
if (a != NULL)
|
if (a != NULL)
|
||||||
fset(f, FFL_GM);
|
fset(f, FFL_GM);
|
||||||
|
@ -1961,20 +1961,6 @@ void kernel_done(void)
|
||||||
gc_done();
|
gc_done();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *localenames[] = {
|
|
||||||
"de", "en",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
void init_locales(void)
|
|
||||||
{
|
|
||||||
int l;
|
|
||||||
for (l = 0; localenames[l]; ++l) {
|
|
||||||
struct locale *lang = get_or_create_locale(localenames[l]);
|
|
||||||
init_locale(lang);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: soll hier weg */
|
/* TODO: soll hier weg */
|
||||||
extern struct attrib_type at_shiptrail;
|
extern struct attrib_type at_shiptrail;
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,6 @@ extern "C" {
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
void add_translation(struct critbit_tree **cb, const char *str, int i);
|
void add_translation(struct critbit_tree **cb, const char *str, int i);
|
||||||
void init_translations(const struct locale *lang, int ut, const char * (*string_cb)(int i), int maxstrings);
|
void init_translations(const struct locale *lang, int ut, const char * (*string_cb)(int i), int maxstrings);
|
||||||
void init_locales(void);
|
|
||||||
int shipspeed(const struct ship *sh, const struct unit *u);
|
int shipspeed(const struct ship *sh, const struct unit *u);
|
||||||
|
|
||||||
#define i2b(i) ((bool)((i)?(true):(false)))
|
#define i2b(i) ((bool)((i)?(true):(false)))
|
||||||
|
@ -171,7 +170,6 @@ extern "C" {
|
||||||
/* returns a value between [0..xpct_2], generated with two dice */
|
/* returns a value between [0..xpct_2], generated with two dice */
|
||||||
|
|
||||||
int distribute(int old, int new_value, int n);
|
int distribute(int old, int new_value, int n);
|
||||||
void init_locales(void);
|
|
||||||
void init_locale(struct locale *lang);
|
void init_locale(struct locale *lang);
|
||||||
|
|
||||||
int newunitid(void);
|
int newunitid(void);
|
||||||
|
|
|
@ -430,10 +430,8 @@ void set_alliance(faction * a, faction * b, int status)
|
||||||
sfp = &sf->next;
|
sfp = &sf->next;
|
||||||
}
|
}
|
||||||
if (*sfp == NULL) {
|
if (*sfp == NULL) {
|
||||||
ally *sf = *sfp = malloc(sizeof(ally));
|
ally *sf = ally_add(sfp, b);
|
||||||
sf->next = NULL;
|
|
||||||
sf->status = status;
|
sf->status = status;
|
||||||
sf->faction = b;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(*sfp)->status |= status;
|
(*sfp)->status |= status;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||||
Katja Zedel <katze@felidae.kn-bremen.de
|
Katja Zedel <katze@felidae.kn-bremen.de
|
||||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -73,9 +73,8 @@ static void init_group(faction * f, group * g)
|
||||||
an = &g->allies;
|
an = &g->allies;
|
||||||
for (a = f->allies; a; a = a->next)
|
for (a = f->allies; a; a = a->next)
|
||||||
if (a->faction) {
|
if (a->faction) {
|
||||||
ally *ga = calloc(sizeof(ally), 1);
|
ally *ga = ally_add(an, a->faction);
|
||||||
*ga = *a;
|
ga->status = a->status;
|
||||||
*an = ga;
|
|
||||||
an = &ga->next;
|
an = &ga->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,14 +112,14 @@ static int read_group(attrib * a, void *owner, struct storage *store)
|
||||||
static void
|
static void
|
||||||
write_group(const attrib * a, const void *owner, struct storage *store)
|
write_group(const attrib * a, const void *owner, struct storage *store)
|
||||||
{
|
{
|
||||||
group *g = (group *) a->data.v;
|
group *g = (group *)a->data.v;
|
||||||
WRITE_INT(store, g->gid);
|
WRITE_INT(store, g->gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
attrib_type at_group = { /* attribute for units assigned to a group */
|
attrib_type at_group = { /* attribute for units assigned to a group */
|
||||||
"grp",
|
"grp",
|
||||||
DEFAULT_INIT,
|
DEFAULT_INIT,
|
||||||
DEFAULT_FINALIZE, DEFAULT_AGE, write_group, read_group, ATF_UNIQUE};
|
DEFAULT_FINALIZE, DEFAULT_AGE, write_group, read_group, ATF_UNIQUE };
|
||||||
|
|
||||||
void free_group(group * g)
|
void free_group(group * g)
|
||||||
{
|
{
|
||||||
|
@ -145,7 +144,7 @@ group * get_group(const struct unit *u)
|
||||||
if (fval(u, UFL_GROUP)) {
|
if (fval(u, UFL_GROUP)) {
|
||||||
attrib * a = a_find(u->attribs, &at_group);
|
attrib * a = a_find(u->attribs, &at_group);
|
||||||
if (a) {
|
if (a) {
|
||||||
return (group *) a->data.v;
|
return (group *)a->data.v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -160,7 +159,7 @@ void set_group(struct unit *u, struct group *g)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a) {
|
if (a) {
|
||||||
group *og = (group *) a->data.v;
|
group *og = (group *)a->data.v;
|
||||||
if (og == g)
|
if (og == g)
|
||||||
return;
|
return;
|
||||||
--og->members;
|
--og->members;
|
||||||
|
@ -173,7 +172,8 @@ void set_group(struct unit *u, struct group *g)
|
||||||
}
|
}
|
||||||
a->data.v = g;
|
a->data.v = g;
|
||||||
g->members++;
|
g->members++;
|
||||||
} else if (a) {
|
}
|
||||||
|
else if (a) {
|
||||||
a_remove(&u->attribs, a);
|
a_remove(&u->attribs, a);
|
||||||
freset(u, UFL_GROUP);
|
freset(u, UFL_GROUP);
|
||||||
}
|
}
|
||||||
|
@ -232,17 +232,14 @@ void read_groups(struct storage *store, faction * f)
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ally *a;
|
ally *a;
|
||||||
variant fid;
|
variant fid;
|
||||||
|
|
||||||
READ_INT(store, &fid.i);
|
READ_INT(store, &fid.i);
|
||||||
if (fid.i <= 0)
|
if (fid.i <= 0)
|
||||||
break;
|
break;
|
||||||
if (global.data_version < STORAGE_VERSION && fid.i == 0)
|
if (global.data_version < STORAGE_VERSION && fid.i == 0)
|
||||||
break;
|
break;
|
||||||
a = malloc(sizeof(ally));
|
a = ally_add(pa, findfaction(fid.i));
|
||||||
*pa = a;
|
|
||||||
pa = &a->next;
|
|
||||||
READ_INT(store, &a->status);
|
READ_INT(store, &a->status);
|
||||||
|
|
||||||
a->faction = findfaction(fid.i);
|
|
||||||
if (!a->faction)
|
if (!a->faction)
|
||||||
ur_add(fid, &a->faction, resolve_faction);
|
ur_add(fid, &a->faction, resolve_faction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* bitfield value for group::flags */
|
|
||||||
#define GFL_ALIVE 0x01 /* There is at least one struct unit in the group */
|
|
||||||
|
|
||||||
struct gamedata;
|
struct gamedata;
|
||||||
|
|
||||||
typedef struct group {
|
typedef struct group {
|
||||||
|
@ -34,7 +31,6 @@ extern "C" {
|
||||||
struct attrib *attribs;
|
struct attrib *attribs;
|
||||||
char *name;
|
char *name;
|
||||||
struct ally *allies;
|
struct ally *allies;
|
||||||
int flags;
|
|
||||||
int gid;
|
int gid;
|
||||||
int members;
|
int members;
|
||||||
} group;
|
} group;
|
||||||
|
|
45
src/kernel/group.test.c
Normal file
45
src/kernel/group.test.c
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#include <platform.h>
|
||||||
|
#include "types.h"
|
||||||
|
#include "group.h"
|
||||||
|
#include "faction.h"
|
||||||
|
#include "unit.h"
|
||||||
|
#include "region.h"
|
||||||
|
|
||||||
|
#include <CuTest.h>
|
||||||
|
#include <tests.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
static void test_group(CuTest * tc)
|
||||||
|
{
|
||||||
|
unit *u;
|
||||||
|
region *r;
|
||||||
|
faction *f;
|
||||||
|
group *g;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
r = findregion(0, 0);
|
||||||
|
f = test_create_faction(0);
|
||||||
|
assert(r && f);
|
||||||
|
u = test_create_unit(f, r);
|
||||||
|
assert(u);
|
||||||
|
CuAssertTrue(tc, join_group(u, "hodor"));
|
||||||
|
CuAssertPtrNotNull(tc, (g = get_group(u)));
|
||||||
|
CuAssertStrEquals(tc, "hodor", g->name);
|
||||||
|
CuAssertIntEquals(tc, 1, g->members);
|
||||||
|
set_group(u, 0);
|
||||||
|
CuAssertIntEquals(tc, 0, g->members);
|
||||||
|
CuAssertPtrEquals(tc, 0, get_group(u));
|
||||||
|
set_group(u, g);
|
||||||
|
CuAssertIntEquals(tc, 1, g->members);
|
||||||
|
CuAssertPtrEquals(tc, g, get_group(u));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
CuSuite *get_group_suite(void)
|
||||||
|
{
|
||||||
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
SUITE_ADD_TEST(suite, test_group);
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
|
@ -627,29 +627,69 @@ static void json_keywords(cJSON *json) {
|
||||||
|
|
||||||
static void json_races(cJSON *json) {
|
static void json_races(cJSON *json) {
|
||||||
cJSON *child;
|
cJSON *child;
|
||||||
if (json->type!=cJSON_Object) {
|
if (json->type != cJSON_Object) {
|
||||||
log_error("races is not a json object: %d", json->type);
|
log_error("races is not a json object: %d", json->type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (child=json->child;child;child=child->next) {
|
for (child = json->child; child; child = child->next) {
|
||||||
json_race(child, rc_get_or_create(child->string));
|
json_race(child, rc_get_or_create(child->string));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * json_relpath;
|
||||||
|
|
||||||
|
static void json_include(cJSON *json) {
|
||||||
|
cJSON *child;
|
||||||
|
if (json->type != cJSON_Array) {
|
||||||
|
log_error("config is not a json array: %d", json->type);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (child = json->child; child; child = child->next) {
|
||||||
|
FILE *F;
|
||||||
|
if (json_relpath) {
|
||||||
|
char name[MAX_PATH];
|
||||||
|
_snprintf(name, sizeof(name), "%s/%s", json_relpath, child->valuestring);
|
||||||
|
F = fopen(name, "rt");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
F = fopen(child->valuestring, "rt");
|
||||||
|
}
|
||||||
|
if (F) {
|
||||||
|
cJSON *config;
|
||||||
|
char *data;
|
||||||
|
size_t sz;
|
||||||
|
fseek(F, 0, SEEK_END);
|
||||||
|
sz = ftell(F);
|
||||||
|
rewind(F);
|
||||||
|
data = malloc(sz);
|
||||||
|
fread(data, 1, sz, F);
|
||||||
|
fclose(F);
|
||||||
|
config = cJSON_Parse(data);
|
||||||
|
free(data);
|
||||||
|
json_config(config);
|
||||||
|
cJSON_Delete(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void json_config(cJSON *json) {
|
void json_config(cJSON *json) {
|
||||||
cJSON *child;
|
cJSON *child;
|
||||||
if (json->type!=cJSON_Object) {
|
if (json->type!=cJSON_Object) {
|
||||||
log_error("config is not a json object: %d", json->type);
|
log_error("config is not a json object: %d", json->type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
reset_locales();
|
||||||
for (child=json->child;child;child=child->next) {
|
for (child=json->child;child;child=child->next) {
|
||||||
if (strcmp(child->string, "races")==0) {
|
if (strcmp(child->string, "races")==0) {
|
||||||
json_races(child);
|
json_races(child);
|
||||||
}
|
}
|
||||||
else if (strcmp(child->string, "items")==0) {
|
else if (strcmp(child->string, "items") == 0) {
|
||||||
json_items(child);
|
json_items(child);
|
||||||
}
|
}
|
||||||
else if (strcmp(child->string, "ships")==0) {
|
else if (strcmp(child->string, "include") == 0) {
|
||||||
|
json_include(child);
|
||||||
|
}
|
||||||
|
else if (strcmp(child->string, "ships") == 0) {
|
||||||
json_ships(child);
|
json_ships(child);
|
||||||
}
|
}
|
||||||
else if (strcmp(child->string, "strings")==0) {
|
else if (strcmp(child->string, "strings")==0) {
|
||||||
|
@ -676,6 +716,5 @@ void json_config(cJSON *json) {
|
||||||
log_error("config contains unknown attribute %s", child->string);
|
log_error("config contains unknown attribute %s", child->string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init_locales();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ extern "C" {
|
||||||
|
|
||||||
struct cJSON;
|
struct cJSON;
|
||||||
void json_config(struct cJSON *str);
|
void json_config(struct cJSON *str);
|
||||||
|
extern const char * json_relpath;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,13 @@
|
||||||
#include "race.h"
|
#include "race.h"
|
||||||
#include "ship.h"
|
#include "ship.h"
|
||||||
#include "spell.h"
|
#include "spell.h"
|
||||||
|
#include "order.h"
|
||||||
#include "terrain.h"
|
#include "terrain.h"
|
||||||
#include "util/language.h"
|
#include "util/language.h"
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <cJSON.h>
|
#include <cJSON.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static const struct race * race_with_flag(const char * name) {
|
static const struct race * race_with_flag(const char * name) {
|
||||||
|
@ -101,7 +103,7 @@ static void test_races(CuTest * tc)
|
||||||
static void test_findrace(CuTest *tc) {
|
static void test_findrace(CuTest *tc) {
|
||||||
const char * data = "{\"races\": { \"dwarf\": {} }, \"strings\": { \"de\" : { \"race::dwarf\" : \"Zwerg\" } } }";
|
const char * data = "{\"races\": { \"dwarf\": {} }, \"strings\": { \"de\" : { \"race::dwarf\" : \"Zwerg\" } } }";
|
||||||
cJSON *json = cJSON_Parse(data);
|
cJSON *json = cJSON_Parse(data);
|
||||||
const struct locale *lang;
|
struct locale *lang;
|
||||||
const race *rc;
|
const race *rc;
|
||||||
|
|
||||||
CuAssertPtrNotNull(tc, json);
|
CuAssertPtrNotNull(tc, json);
|
||||||
|
@ -110,6 +112,7 @@ static void test_findrace(CuTest *tc) {
|
||||||
CuAssertPtrEquals(tc, 0, (void *)findrace("Zwerg", lang));
|
CuAssertPtrEquals(tc, 0, (void *)findrace("Zwerg", lang));
|
||||||
|
|
||||||
json_config(json);
|
json_config(json);
|
||||||
|
init_locale(lang);
|
||||||
rc = findrace("Zwerg", lang);
|
rc = findrace("Zwerg", lang);
|
||||||
CuAssertPtrNotNull(tc, rc);
|
CuAssertPtrNotNull(tc, rc);
|
||||||
CuAssertStrEquals(tc, "dwarf", rc->_name);
|
CuAssertStrEquals(tc, "dwarf", rc->_name);
|
||||||
|
@ -228,29 +231,29 @@ static void test_spells(CuTest * tc)
|
||||||
CuAssertPtrEquals(tc, 0, find_spell("fireball"));
|
CuAssertPtrEquals(tc, 0, find_spell("fireball"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char * building_data = "{\"buildings\": { "
|
||||||
|
"\"house\" : { "
|
||||||
|
"\"maintenance\" : "
|
||||||
|
"{ \"type\" : \"iron\", \"amount\" : 1, \"flags\" : [ \"required\", \"variable\" ] }"
|
||||||
|
","
|
||||||
|
"\"construction\" : {"
|
||||||
|
"\"maxsize\" : 20,"
|
||||||
|
"\"reqsize\" : 10,"
|
||||||
|
"\"minskill\" : 1,"
|
||||||
|
"\"materials\" : {"
|
||||||
|
"\"stone\" : 2,"
|
||||||
|
"\"iron\" : 1"
|
||||||
|
"}}},"
|
||||||
|
"\"shed\" : {"
|
||||||
|
"\"maintenance\" : ["
|
||||||
|
"{ \"type\" : \"iron\", \"amount\" : 1 },"
|
||||||
|
"{ \"type\" : \"stone\", \"amount\" : 2 }"
|
||||||
|
"]}"
|
||||||
|
"}}";
|
||||||
|
|
||||||
static void test_buildings(CuTest * tc)
|
static void test_buildings(CuTest * tc)
|
||||||
{
|
{
|
||||||
const char * data = "{\"buildings\": { "
|
cJSON *json = cJSON_Parse(building_data);
|
||||||
"\"house\" : { "
|
|
||||||
"\"maintenance\" : "
|
|
||||||
"{ \"type\" : \"iron\", \"amount\" : 1, \"flags\" : [ \"required\", \"variable\" ] }"
|
|
||||||
","
|
|
||||||
"\"construction\" : {"
|
|
||||||
"\"maxsize\" : 20,"
|
|
||||||
"\"reqsize\" : 10,"
|
|
||||||
"\"minskill\" : 1,"
|
|
||||||
"\"materials\" : {"
|
|
||||||
"\"stone\" : 2,"
|
|
||||||
"\"iron\" : 1"
|
|
||||||
"}}},"
|
|
||||||
"\"shed\" : {"
|
|
||||||
"\"maintenance\" : ["
|
|
||||||
"{ \"type\" : \"iron\", \"amount\" : 1 },"
|
|
||||||
"{ \"type\" : \"stone\", \"amount\" : 2 }"
|
|
||||||
"]}"
|
|
||||||
"}}";
|
|
||||||
|
|
||||||
cJSON *json = cJSON_Parse(data);
|
|
||||||
const building_type *bt;
|
const building_type *bt;
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
@ -292,6 +295,25 @@ static void test_buildings(CuTest * tc)
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_configs(CuTest * tc)
|
||||||
|
{
|
||||||
|
const char * data = "{\"include\": [ \"test.json\" ] }";
|
||||||
|
FILE *F;
|
||||||
|
cJSON *json = cJSON_Parse(data);
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
|
||||||
|
F = fopen("test.json", "wt");
|
||||||
|
fwrite(building_data, 1, strlen(building_data), F);
|
||||||
|
fclose(F);
|
||||||
|
CuAssertPtrNotNull(tc, json);
|
||||||
|
CuAssertPtrEquals(tc, 0, buildingtypes);
|
||||||
|
json_config(json);
|
||||||
|
CuAssertPtrNotNull(tc, buildingtypes);
|
||||||
|
unlink("test.json");
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_terrains(CuTest * tc)
|
static void test_terrains(CuTest * tc)
|
||||||
{
|
{
|
||||||
const char * data = "{\"terrains\": { \"plain\" : { \"flags\" : [ \"land\", \"fly\", \"walk\" ] } }}";
|
const char * data = "{\"terrains\": { \"plain\" : { \"flags\" : [ \"land\", \"fly\", \"walk\" ] } }}";
|
||||||
|
@ -374,6 +396,7 @@ static void test_keywords(CuTest * tc)
|
||||||
CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang));
|
CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang));
|
||||||
|
|
||||||
CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "keyword::study"));
|
CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "keyword::study"));
|
||||||
|
CuAssertStrEquals(tc, "NACH", locale_string(lang, "keyword::move"));
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
@ -395,6 +418,26 @@ static void test_strings(CuTest * tc)
|
||||||
CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "study"));
|
CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "study"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_infinitive_from_config(CuTest *tc) {
|
||||||
|
char buffer[32];
|
||||||
|
struct locale *lang;
|
||||||
|
struct order *ord;
|
||||||
|
const char * data = "{\"keywords\": { \"de\" : { \"study\" : [ \"LERNE\", \"LERNEN\" ] }}}";
|
||||||
|
|
||||||
|
cJSON *json = cJSON_Parse(data);
|
||||||
|
CuAssertPtrNotNull(tc, json);
|
||||||
|
json_config(json);
|
||||||
|
|
||||||
|
lang = get_or_create_locale("de");
|
||||||
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("LERN", lang));
|
||||||
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNE", lang));
|
||||||
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNEN", lang));
|
||||||
|
|
||||||
|
ord = create_order(K_STUDY, lang, "");
|
||||||
|
CuAssertStrEquals(tc, "LERNE", get_command(ord, buffer, sizeof(buffer)));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_jsonconf_suite(void)
|
CuSuite *get_jsonconf_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
@ -404,6 +447,7 @@ CuSuite *get_jsonconf_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_items);
|
SUITE_ADD_TEST(suite, test_items);
|
||||||
SUITE_ADD_TEST(suite, test_ships);
|
SUITE_ADD_TEST(suite, test_ships);
|
||||||
SUITE_ADD_TEST(suite, test_buildings);
|
SUITE_ADD_TEST(suite, test_buildings);
|
||||||
|
SUITE_ADD_TEST(suite, test_configs);
|
||||||
SUITE_ADD_TEST(suite, test_castles);
|
SUITE_ADD_TEST(suite, test_castles);
|
||||||
SUITE_ADD_TEST(suite, test_terrains);
|
SUITE_ADD_TEST(suite, test_terrains);
|
||||||
SUITE_ADD_TEST(suite, test_races);
|
SUITE_ADD_TEST(suite, test_races);
|
||||||
|
@ -411,6 +455,7 @@ CuSuite *get_jsonconf_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_strings);
|
SUITE_ADD_TEST(suite, test_strings);
|
||||||
SUITE_ADD_TEST(suite, test_spells);
|
SUITE_ADD_TEST(suite, test_spells);
|
||||||
SUITE_ADD_TEST(suite, test_flags);
|
SUITE_ADD_TEST(suite, test_flags);
|
||||||
|
SUITE_ADD_TEST(suite, test_infinitive_from_config);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ static void test_parse_order(CuTest *tc) {
|
||||||
struct locale * lang = get_or_create_locale("en");
|
struct locale * lang = get_or_create_locale("en");
|
||||||
|
|
||||||
locale_setstring(lang, "keyword::move", "MOVE");
|
locale_setstring(lang, "keyword::move", "MOVE");
|
||||||
|
init_keyword(lang, K_MOVE, "MOVE");
|
||||||
ord = parse_order("MOVE NORTH", lang);
|
ord = parse_order("MOVE NORTH", lang);
|
||||||
CuAssertPtrNotNull(tc, ord);
|
CuAssertPtrNotNull(tc, ord);
|
||||||
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
||||||
|
|
|
@ -167,7 +167,7 @@ int count)
|
||||||
|
|
||||||
if ((mode & GET_SLACK) && (mode & GET_RESERVE))
|
if ((mode & GET_SLACK) && (mode & GET_RESERVE))
|
||||||
use = have;
|
use = have;
|
||||||
else {
|
else if (mode & (GET_SLACK|GET_RESERVE)) {
|
||||||
int reserve = get_reservation(u, rtype);
|
int reserve = get_reservation(u, rtype);
|
||||||
int slack = _max(0, have - reserve);
|
int slack = _max(0, have - reserve);
|
||||||
if (mode & GET_RESERVE)
|
if (mode & GET_RESERVE)
|
||||||
|
@ -177,11 +177,9 @@ int count)
|
||||||
}
|
}
|
||||||
if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK | GET_RESERVE)) {
|
if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK | GET_RESERVE)) {
|
||||||
for (v = r->units; v && use < count; v = v->next)
|
for (v = r->units; v && use < count; v = v->next)
|
||||||
if (u != v) {
|
if (u != v && (u->items || rtype->uget)) {
|
||||||
int mask;
|
int mask;
|
||||||
|
|
||||||
if (v->items == NULL && rtype->uget == NULL)
|
|
||||||
continue;
|
|
||||||
if ((urace(v)->ec_flags & GIVEITEM) == 0)
|
if ((urace(v)->ec_flags & GIVEITEM) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ extern "C" {
|
||||||
#define GET_POOLED_SLACK 0x08
|
#define GET_POOLED_SLACK 0x08
|
||||||
#define GET_POOLED_RESERVE 0x10
|
#define GET_POOLED_RESERVE 0x10
|
||||||
#define GET_POOLED_FORCE 0x20 /* ignore f->options pools */
|
#define GET_POOLED_FORCE 0x20 /* ignore f->options pools */
|
||||||
#define GET_ALLIED_SLACK 0x30
|
#define GET_ALLIED_SLACK 0x40
|
||||||
#define GET_ALLIED_RESERVE 0x40
|
#define GET_ALLIED_RESERVE 0x80
|
||||||
|
|
||||||
/* for convenience: */
|
/* for convenience: */
|
||||||
#define GET_DEFAULT (GET_RESERVE|GET_SLACK|GET_POOLED_SLACK)
|
#define GET_DEFAULT (GET_RESERVE|GET_SLACK|GET_POOLED_SLACK)
|
||||||
|
|
|
@ -1,15 +1,138 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
|
|
||||||
|
#include "ally.h"
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
#include "magic.h"
|
#include "magic.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
#include "faction.h"
|
||||||
#include "region.h"
|
#include "region.h"
|
||||||
#include "skill.h"
|
#include "skill.h"
|
||||||
|
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
void test_reservation(CuTest *tc) {
|
||||||
|
unit *u;
|
||||||
|
faction *f;
|
||||||
|
region *r;
|
||||||
|
struct resource_type *rtype;
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
rtype = rt_get_or_create("money");
|
||||||
|
it_get_or_create(rtype);
|
||||||
|
f = test_create_faction(0);
|
||||||
|
r = findregion(0, 0);
|
||||||
|
assert(r && f && rtype && rtype->itype);
|
||||||
|
u = test_create_unit(f, r);
|
||||||
|
assert(u);
|
||||||
|
i_change(&u->items, rtype->itype, 100);
|
||||||
|
CuAssertIntEquals(tc, 100, get_resource(u, rtype));
|
||||||
|
CuAssertIntEquals(tc, 0, get_reservation(u, rtype));
|
||||||
|
CuAssertIntEquals(tc, 50, change_reservation(u, rtype, 50));
|
||||||
|
CuAssertIntEquals(tc, 100, change_reservation(u, rtype, 50));
|
||||||
|
CuAssertIntEquals(tc, 50, set_resvalue(u, rtype, 50));
|
||||||
|
CuAssertIntEquals(tc, 100, get_resource(u, rtype));
|
||||||
|
CuAssertIntEquals(tc, 200, change_resource(u, rtype, 100));
|
||||||
|
CuAssertIntEquals(tc, 200, get_resource(u, rtype));
|
||||||
|
CuAssertIntEquals(tc, 200, i_get(u->items, rtype->itype));
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pool(CuTest *tc) {
|
||||||
|
unit *u1, *u2, *u3;
|
||||||
|
faction *f;
|
||||||
|
region *r;
|
||||||
|
struct resource_type *rtype;
|
||||||
|
ally *al;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
rtype = rt_get_or_create("money");
|
||||||
|
it_get_or_create(rtype);
|
||||||
|
f = test_create_faction(0);
|
||||||
|
r = findregion(0, 0);
|
||||||
|
assert(r && f && rtype && rtype->itype);
|
||||||
|
u1 = test_create_unit(f, r);
|
||||||
|
u2 = test_create_unit(f, r);
|
||||||
|
u3 = test_create_unit(test_create_faction(0), r);
|
||||||
|
assert(u1 && u2);
|
||||||
|
i_change(&u1->items, rtype->itype, 100);
|
||||||
|
set_resvalue(u1, rtype, 50);
|
||||||
|
i_change(&u2->items, rtype->itype, 200);
|
||||||
|
set_resvalue(u2, rtype, 100);
|
||||||
|
i_change(&u3->items, rtype->itype, 400);
|
||||||
|
set_resvalue(u3, rtype, 200);
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 50, get_pooled(u1, rtype, GET_SLACK, 40));
|
||||||
|
CuAssertIntEquals(tc, 50, get_pooled(u1, rtype, GET_SLACK, INT_MAX));
|
||||||
|
CuAssertIntEquals(tc, 100, get_pooled(u1, rtype, GET_SLACK | GET_RESERVE, INT_MAX));
|
||||||
|
CuAssertIntEquals(tc, 150, get_pooled(u1, rtype, GET_SLACK | GET_POOLED_SLACK, INT_MAX));
|
||||||
|
CuAssertIntEquals(tc, 100, get_pooled(u1, rtype, GET_POOLED_SLACK, INT_MAX));
|
||||||
|
CuAssertIntEquals(tc, 200, get_pooled(u1, rtype, GET_POOLED_SLACK | GET_POOLED_RESERVE, INT_MAX));
|
||||||
|
|
||||||
|
al = ally_add(&u3->faction->allies, f);
|
||||||
|
al->status = HELP_GUARD;
|
||||||
|
CuAssertIntEquals(tc, 0, get_pooled(u1, rtype, GET_ALLIED_SLACK | GET_ALLIED_RESERVE, INT_MAX));
|
||||||
|
al->status = HELP_MONEY;
|
||||||
|
CuAssertIntEquals(tc, 200, get_pooled(u1, rtype, GET_ALLIED_SLACK, INT_MAX));
|
||||||
|
CuAssertIntEquals(tc, 200, get_pooled(u1, rtype, GET_ALLIED_RESERVE, INT_MAX));
|
||||||
|
CuAssertIntEquals(tc, 400, get_pooled(u1, rtype, GET_ALLIED_SLACK | GET_ALLIED_RESERVE, INT_MAX));
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 100, get_pooled(u1, rtype, GET_ALL, 50));
|
||||||
|
CuAssertIntEquals(tc, 300, get_pooled(u1, rtype, GET_ALL, 150));
|
||||||
|
CuAssertIntEquals(tc, 300, get_pooled(u1, rtype, GET_ALL, INT_MAX));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pool_use(CuTest *tc) {
|
||||||
|
unit *u1, *u2, *u3;
|
||||||
|
faction *f;
|
||||||
|
region *r;
|
||||||
|
struct resource_type *rtype;
|
||||||
|
ally *al;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
rtype = rt_get_or_create("money");
|
||||||
|
it_get_or_create(rtype);
|
||||||
|
f = test_create_faction(0);
|
||||||
|
r = findregion(0, 0);
|
||||||
|
assert(r && f && rtype && rtype->itype);
|
||||||
|
u1 = test_create_unit(f, r);
|
||||||
|
u2 = test_create_unit(f, r);
|
||||||
|
u3 = test_create_unit(test_create_faction(0), r);
|
||||||
|
assert(u1 && u2);
|
||||||
|
i_change(&u1->items, rtype->itype, 100);
|
||||||
|
set_resvalue(u1, rtype, 50);
|
||||||
|
i_change(&u2->items, rtype->itype, 200);
|
||||||
|
set_resvalue(u2, rtype, 100);
|
||||||
|
i_change(&u3->items, rtype->itype, 400);
|
||||||
|
set_resvalue(u3, rtype, 200);
|
||||||
|
al = ally_add(&u3->faction->allies, f);
|
||||||
|
al->status = HELP_MONEY;
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 10, use_pooled(u1, rtype, GET_SLACK, 10));
|
||||||
|
CuAssertIntEquals(tc, 40, use_pooled(u1, rtype, GET_SLACK, 50));
|
||||||
|
CuAssertIntEquals(tc, 50, i_get(u1->items, rtype->itype));
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 50, get_reservation(u1, rtype));
|
||||||
|
CuAssertIntEquals(tc, 10, use_pooled(u1, rtype, GET_RESERVE, 10));
|
||||||
|
CuAssertIntEquals(tc, 40, i_get(u1->items, rtype->itype));
|
||||||
|
CuAssertIntEquals(tc, 40, get_reservation(u1, rtype));
|
||||||
|
CuAssertIntEquals(tc, 40, use_pooled(u1, rtype, GET_RESERVE, 50));
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 10, use_pooled(u1, rtype, GET_POOLED_SLACK, 10));
|
||||||
|
CuAssertIntEquals(tc, 90, use_pooled(u1, rtype, GET_POOLED_SLACK, 100));
|
||||||
|
CuAssertIntEquals(tc, 100, i_get(u2->items, rtype->itype));
|
||||||
|
CuAssertIntEquals(tc, 10, use_pooled(u1, rtype, GET_POOLED_RESERVE, 10));
|
||||||
|
CuAssertIntEquals(tc, 90, get_reservation(u2, rtype));
|
||||||
|
CuAssertIntEquals(tc, 90, use_pooled(u1, rtype, GET_POOLED_RESERVE, 100));
|
||||||
|
CuAssertIntEquals(tc, 0, i_get(u2->items, rtype->itype));
|
||||||
|
}
|
||||||
|
|
||||||
void test_change_resource(CuTest * tc)
|
void test_change_resource(CuTest * tc)
|
||||||
{
|
{
|
||||||
|
@ -30,18 +153,20 @@ void test_change_resource(CuTest * tc)
|
||||||
set_level(u, SK_MAGIC, 5);
|
set_level(u, SK_MAGIC, 5);
|
||||||
create_mage(u, M_DRAIG);
|
create_mage(u, M_DRAIG);
|
||||||
|
|
||||||
for (i=0;names[i];++i) {
|
for (i = 0; names[i]; ++i) {
|
||||||
const struct resource_type *rtype = rt_find(names[i]);
|
const struct resource_type *rtype = rt_find(names[i]);
|
||||||
int have = get_resource(u, rtype);
|
int have = get_resource(u, rtype);
|
||||||
CuAssertIntEquals(tc, have+1, change_resource(u, rtype, 1));
|
CuAssertIntEquals(tc, have + 1, change_resource(u, rtype, 1));
|
||||||
CuAssertIntEquals(tc, have+1, get_resource(u, rtype));
|
CuAssertIntEquals(tc, have + 1, get_resource(u, rtype));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CuSuite *get_pool_suite(void)
|
CuSuite *get_pool_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
/* SUITE_ADD_TEST(suite, test_pool); */
|
SUITE_ADD_TEST(suite, test_reservation);
|
||||||
|
SUITE_ADD_TEST(suite, test_pool);
|
||||||
|
SUITE_ADD_TEST(suite, test_pool_use);
|
||||||
SUITE_ADD_TEST(suite, test_change_resource);
|
SUITE_ADD_TEST(suite, test_change_resource);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1119,8 +1119,11 @@ static ally **addally(const faction * f, ally ** sfp, int aid, int state)
|
||||||
if (state == 0)
|
if (state == 0)
|
||||||
return sfp;
|
return sfp;
|
||||||
|
|
||||||
sf = calloc(1, sizeof(ally));
|
while (*sfp) {
|
||||||
sf->faction = af;
|
sfp = &(*sfp)->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
sf = ally_add(sfp, af);
|
||||||
if (!sf->faction) {
|
if (!sf->faction) {
|
||||||
variant id;
|
variant id;
|
||||||
id.i = aid;
|
id.i = aid;
|
||||||
|
@ -1128,9 +1131,6 @@ static ally **addally(const faction * f, ally ** sfp, int aid, int state)
|
||||||
}
|
}
|
||||||
sf->status = state & HELP_ALL;
|
sf->status = state & HELP_ALL;
|
||||||
|
|
||||||
while (*sfp)
|
|
||||||
sfp = &(*sfp)->next;
|
|
||||||
*sfp = sf;
|
|
||||||
return &sf->next;
|
return &sf->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1460,6 +1460,7 @@ int readgame(const char *filename, int backup)
|
||||||
storage store;
|
storage store;
|
||||||
FILE *F;
|
FILE *F;
|
||||||
|
|
||||||
|
init_locales();
|
||||||
log_printf(stdout, "- reading game data from %s\n", filename);
|
log_printf(stdout, "- reading game data from %s\n", filename);
|
||||||
sprintf(path, "%s/%s", datapath(), filename);
|
sprintf(path, "%s/%s", datapath(), filename);
|
||||||
|
|
||||||
|
|
|
@ -702,6 +702,7 @@ void set_level(unit * u, skill_t sk, int value)
|
||||||
{
|
{
|
||||||
skill *sv = u->skills;
|
skill *sv = u->skills;
|
||||||
|
|
||||||
|
assert(sk != SK_MAGIC || is_monsters(u->faction) || u->number == 1);
|
||||||
if (!skill_enabled(sk))
|
if (!skill_enabled(sk))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1161,10 +1162,13 @@ skill *add_skill(unit * u, skill_t id)
|
||||||
++u->skill_size;
|
++u->skill_size;
|
||||||
u->skills = realloc(u->skills, u->skill_size * sizeof(skill));
|
u->skills = realloc(u->skills, u->skill_size * sizeof(skill));
|
||||||
sv = (u->skills + u->skill_size - 1);
|
sv = (u->skills + u->skill_size - 1);
|
||||||
sv->level = (unsigned char)0;
|
sv->level = 0;
|
||||||
sv->weeks = (unsigned char)1;
|
sv->weeks = 1;
|
||||||
sv->old = (unsigned char)0;
|
sv->old = 0;
|
||||||
sv->id = (unsigned char)id;
|
sv->id = id;
|
||||||
|
if (id == SK_MAGIC && u->faction && !is_monsters(u->faction)) {
|
||||||
|
assert(u->number==1 && max_magicians(u->faction) >= u->number);
|
||||||
|
}
|
||||||
return sv;
|
return sv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ const char *keywords[MAXKEYWORDS] = {
|
||||||
"research",
|
"research",
|
||||||
"give",
|
"give",
|
||||||
"help",
|
"help",
|
||||||
"fight",
|
"combat",
|
||||||
"ready",
|
"ready",
|
||||||
"buy",
|
"buy",
|
||||||
"contact",
|
"contact",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include "kernel/types.h"
|
#include "kernel/types.h"
|
||||||
#include "kernel/config.h"
|
#include "kernel/config.h"
|
||||||
|
#include "kernel/order.h"
|
||||||
#include "keyword.h"
|
#include "keyword.h"
|
||||||
#include "util/language.h"
|
#include "util/language.h"
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
@ -19,6 +20,25 @@ static void test_init_keywords(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_infinitive(CuTest *tc) {
|
||||||
|
char buffer[32];
|
||||||
|
struct locale *lang;
|
||||||
|
struct order *ord;
|
||||||
|
test_cleanup();
|
||||||
|
|
||||||
|
lang = get_or_create_locale("de");
|
||||||
|
locale_setstring(lang, "keyword::study", "LERNE");
|
||||||
|
init_keyword(lang, K_STUDY, "LERNE");
|
||||||
|
init_keyword(lang, K_STUDY, "LERNEN");
|
||||||
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("LERN", lang));
|
||||||
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNE", lang));
|
||||||
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNEN", lang));
|
||||||
|
|
||||||
|
ord = create_order(K_STUDY, lang, "");
|
||||||
|
CuAssertStrEquals(tc, "LERNE", get_command(ord, buffer, sizeof(buffer)));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_init_keyword(CuTest *tc) {
|
static void test_init_keyword(CuTest *tc) {
|
||||||
struct locale *lang;
|
struct locale *lang;
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
@ -76,6 +96,7 @@ static void test_get_shortest_match(CuTest *tc) {
|
||||||
CuSuite *get_keyword_suite(void)
|
CuSuite *get_keyword_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
SUITE_ADD_TEST(suite, test_infinitive);
|
||||||
SUITE_ADD_TEST(suite, test_init_keyword);
|
SUITE_ADD_TEST(suite, test_init_keyword);
|
||||||
SUITE_ADD_TEST(suite, test_init_keywords);
|
SUITE_ADD_TEST(suite, test_init_keywords);
|
||||||
SUITE_ADD_TEST(suite, test_findkeyword);
|
SUITE_ADD_TEST(suite, test_findkeyword);
|
||||||
|
@ -83,4 +104,3 @@ CuSuite *get_keyword_suite(void)
|
||||||
SUITE_DISABLE_TEST(suite, test_get_keyword_default);
|
SUITE_DISABLE_TEST(suite, test_get_keyword_default);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
21
src/laws.c
21
src/laws.c
|
@ -83,7 +83,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/umlaut.h>
|
#include <util/umlaut.h>
|
||||||
#include <util/message.h>
|
#include <util/message.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
#include <util/xml.h>
|
|
||||||
|
|
||||||
#include <attributes/otherfaction.h>
|
#include <attributes/otherfaction.h>
|
||||||
|
|
||||||
|
@ -1349,10 +1348,8 @@ int ally_cmd(unit * u, struct order *ord)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sf = calloc(1, sizeof(ally));
|
sf = ally_add(sfp, f);
|
||||||
sf->faction = f;
|
|
||||||
sf->status = 0;
|
sf->status = 0;
|
||||||
addlist(sfp, sf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (keyword) {
|
switch (keyword) {
|
||||||
|
@ -2585,7 +2582,7 @@ int reshow_cmd(unit * u, struct order *ord)
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtoken();
|
s = getstrtoken();
|
||||||
|
|
||||||
if (isparam(s, u->faction->locale, P_ANY)) {
|
if (s && isparam(s, u->faction->locale, P_ANY)) {
|
||||||
p = getparam(u->faction->locale);
|
p = getparam(u->faction->locale);
|
||||||
s = NULL;
|
s = NULL;
|
||||||
}
|
}
|
||||||
|
@ -4557,17 +4554,3 @@ void update_subscriptions(void)
|
||||||
}
|
}
|
||||||
fclose(F);
|
fclose(F);
|
||||||
}
|
}
|
||||||
|
|
||||||
int init_data(const char *filename, const char *catalog)
|
|
||||||
{
|
|
||||||
int l;
|
|
||||||
l = read_xml(filename, catalog);
|
|
||||||
if (l) {
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
init_locales();
|
|
||||||
if (turn < 0) {
|
|
||||||
turn = first_turn;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -24,13 +24,10 @@ extern "C" {
|
||||||
|
|
||||||
extern int writepasswd(void);
|
extern int writepasswd(void);
|
||||||
void demographics(void);
|
void demographics(void);
|
||||||
void last_orders(void);
|
|
||||||
void find_address(void);
|
|
||||||
void update_guards(void);
|
void update_guards(void);
|
||||||
void update_subscriptions(void);
|
void update_subscriptions(void);
|
||||||
void deliverMail(struct faction *f, struct region *r, struct unit *u,
|
void deliverMail(struct faction *f, struct region *r, struct unit *u,
|
||||||
const char *s, struct unit *receiver);
|
const char *s, struct unit *receiver);
|
||||||
int init_data(const char *filename, const char *catalog);
|
|
||||||
|
|
||||||
bool renamed_building(const struct building * b);
|
bool renamed_building(const struct building * b);
|
||||||
int rename_building(struct unit * u, struct order * ord, struct building * b, const char *name);
|
int rename_building(struct unit * u, struct order * ord, struct building * b, const char *name);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
|
|
||||||
|
#include <kernel/ally.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include <kernel/building.h>
|
#include <kernel/building.h>
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
|
@ -57,14 +58,15 @@ static void test_rename_building(CuTest * tc)
|
||||||
|
|
||||||
rename_building(u, NULL, b, "Villa Nagel");
|
rename_building(u, NULL, b, "Villa Nagel");
|
||||||
CuAssertStrEquals(tc, "Villa Nagel", b->name);
|
CuAssertStrEquals(tc, "Villa Nagel", b->name);
|
||||||
|
CuAssertTrue(tc, renamed_building(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_rename_building_twice(CuTest * tc)
|
static void test_rename_building_twice(CuTest * tc)
|
||||||
{
|
{
|
||||||
region *r;
|
region *r;
|
||||||
building *b;
|
|
||||||
unit *u;
|
unit *u;
|
||||||
faction *f;
|
faction *f;
|
||||||
|
building *b;
|
||||||
building_type *btype;
|
building_type *btype;
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
@ -85,6 +87,37 @@ static void test_rename_building_twice(CuTest * tc)
|
||||||
CuAssertStrEquals(tc, "Villa Kunterbunt", b->name);
|
CuAssertStrEquals(tc, "Villa Kunterbunt", b->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_contact(CuTest * tc)
|
||||||
|
{
|
||||||
|
region *r;
|
||||||
|
unit *u1, *u2, *u3;
|
||||||
|
building *b;
|
||||||
|
building_type *btype;
|
||||||
|
ally *al;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
|
||||||
|
btype = bt_get_or_create("castle");
|
||||||
|
r = findregion(0, 0);
|
||||||
|
b = new_building(btype, r, default_locale);
|
||||||
|
u1 = test_create_unit(test_create_faction(0), r);
|
||||||
|
u2 = test_create_unit(test_create_faction(0), r);
|
||||||
|
u3 = test_create_unit(test_create_faction(0), r);
|
||||||
|
set_level(u3, SK_PERCEPTION, 2);
|
||||||
|
usetsiege(u3, b);
|
||||||
|
b->besieged = 1;
|
||||||
|
CuAssertIntEquals(tc, 1, can_contact(r, u1, u2));
|
||||||
|
|
||||||
|
u_set_building(u1, b);
|
||||||
|
CuAssertIntEquals(tc, 0, can_contact(r, u1, u2));
|
||||||
|
al = ally_add(&u1->faction->allies, u2->faction);
|
||||||
|
al->status = HELP_ALL;
|
||||||
|
CuAssertIntEquals(tc, HELP_GIVE, can_contact(r, u1, u2));
|
||||||
|
u_set_building(u2, b);
|
||||||
|
CuAssertIntEquals(tc, 1, can_contact(r, u1, u2));
|
||||||
|
}
|
||||||
|
|
||||||
static void test_fishing_feeds_2_people(CuTest * tc)
|
static void test_fishing_feeds_2_people(CuTest * tc)
|
||||||
{
|
{
|
||||||
const resource_type *rtype;
|
const resource_type *rtype;
|
||||||
|
@ -412,5 +445,6 @@ CuSuite *get_laws_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_reserve_cmd);
|
SUITE_ADD_TEST(suite, test_reserve_cmd);
|
||||||
SUITE_ADD_TEST(suite, test_new_units);
|
SUITE_ADD_TEST(suite, test_new_units);
|
||||||
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
|
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
|
||||||
|
SUITE_ADD_TEST(suite, test_contact);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,9 @@
|
||||||
|
|
||||||
static int read_permissions(attrib * a, void *owner, struct storage *store)
|
static int read_permissions(attrib * a, void *owner, struct storage *store)
|
||||||
{
|
{
|
||||||
attrib *attr = NULL;
|
assert(!a);
|
||||||
a_read(store, &attr, owner);
|
a_read(store, &a, owner);
|
||||||
a_remove(&attr, a);
|
a_remove(&a, a);
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1183,7 +1183,7 @@ link_seen(seen_region * seehash[], const region * first, const region * last)
|
||||||
}
|
}
|
||||||
r = r->next;
|
r = r->next;
|
||||||
}
|
}
|
||||||
sr->next = 0;
|
if (sr) sr->next = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
seen_region *find_seen(struct seen_region *seehash[], const region * r)
|
seen_region *find_seen(struct seen_region *seehash[], const region * r)
|
||||||
|
|
|
@ -11,8 +11,8 @@ static void test_init_skills(CuTest *tc) {
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
lang = get_or_create_locale("de");
|
lang = get_or_create_locale("de");
|
||||||
locale_setstring(lang, "alchemy", "Alchemie");
|
// locale_setstring(lang, "alchemy", "Alchemie");
|
||||||
init_skills(lang);
|
init_skill(lang, SK_ALCHEMY, "Alchemie");
|
||||||
CuAssertIntEquals(tc, SK_ALCHEMY, get_skill("alchemie", lang));
|
CuAssertIntEquals(tc, SK_ALCHEMY, get_skill("alchemie", lang));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,10 +35,12 @@ int RunAllTests(void)
|
||||||
ADD_TESTS(suite, bsdstring);
|
ADD_TESTS(suite, bsdstring);
|
||||||
ADD_TESTS(suite, functions);
|
ADD_TESTS(suite, functions);
|
||||||
ADD_TESTS(suite, umlaut);
|
ADD_TESTS(suite, umlaut);
|
||||||
|
ADD_TESTS(suite, unicode);
|
||||||
ADD_TESTS(suite, strings);
|
ADD_TESTS(suite, strings);
|
||||||
/* kernel */
|
/* kernel */
|
||||||
ADD_TESTS(suite, unit);
|
ADD_TESTS(suite, unit);
|
||||||
ADD_TESTS(suite, faction);
|
ADD_TESTS(suite, faction);
|
||||||
|
ADD_TESTS(suite, group);
|
||||||
ADD_TESTS(suite, build);
|
ADD_TESTS(suite, build);
|
||||||
ADD_TESTS(suite, pool);
|
ADD_TESTS(suite, pool);
|
||||||
ADD_TESTS(suite, curse);
|
ADD_TESTS(suite, curse);
|
||||||
|
|
|
@ -7,6 +7,7 @@ strings.test.c
|
||||||
bsdstring.test.c
|
bsdstring.test.c
|
||||||
functions.test.c
|
functions.test.c
|
||||||
umlaut.test.c
|
umlaut.test.c
|
||||||
|
unicode.test.c
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(_FILES
|
SET(_FILES
|
||||||
|
|
|
@ -69,6 +69,13 @@ static void test_attrib_nexttype(CuTest * tc)
|
||||||
CuAssertPtrEquals(tc, a, alist->nexttype);
|
CuAssertPtrEquals(tc, a, alist->nexttype);
|
||||||
CuAssertPtrEquals(tc, 0, a->nexttype);
|
CuAssertPtrEquals(tc, 0, a->nexttype);
|
||||||
|
|
||||||
|
a_remove(&alist, alist);
|
||||||
|
CuAssertPtrEquals(tc, a, alist->nexttype);
|
||||||
|
|
||||||
|
CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar))));
|
||||||
|
a_remove(&alist, alist->nexttype);
|
||||||
|
CuAssertPtrEquals(tc, a, alist->nexttype);
|
||||||
|
|
||||||
a_removeall(&alist, &at_foo);
|
a_removeall(&alist, &at_foo);
|
||||||
a_removeall(&alist, &at_bar);
|
a_removeall(&alist, &at_bar);
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,8 +243,32 @@ void *get_translation(const struct locale *lang, const char *str, int index) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_locales(void)
|
const char *localenames[] = {
|
||||||
|
"de", "en",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void init_locale(struct locale *lang);
|
||||||
|
|
||||||
|
static int locale_init = 0;
|
||||||
|
|
||||||
|
void init_locales(void)
|
||||||
{
|
{
|
||||||
|
int l;
|
||||||
|
if (locale_init) return;
|
||||||
|
for (l = 0; localenames[l]; ++l) {
|
||||||
|
struct locale *lang = get_or_create_locale(localenames[l]);
|
||||||
|
init_locale(lang);
|
||||||
|
}
|
||||||
|
locale_init = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset_locales(void) {
|
||||||
|
locale_init = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_locales(void) {
|
||||||
|
locale_init = 0;
|
||||||
while (locales) {
|
while (locales) {
|
||||||
int i;
|
int i;
|
||||||
locale * next = locales->next;
|
locale * next = locales->next;
|
||||||
|
@ -261,4 +285,5 @@ void free_locales(void)
|
||||||
free(locales);
|
free(locales);
|
||||||
locales = next;
|
locales = next;
|
||||||
}
|
}
|
||||||
|
memset(lstrs, 0, sizeof(lstrs)); // TODO: does this data need to be free'd?
|
||||||
}
|
}
|
|
@ -29,7 +29,9 @@ extern "C" {
|
||||||
/** managing multiple locales: **/
|
/** managing multiple locales: **/
|
||||||
extern struct locale *get_locale(const char *name);
|
extern struct locale *get_locale(const char *name);
|
||||||
extern struct locale *get_or_create_locale(const char *key);
|
extern struct locale *get_or_create_locale(const char *key);
|
||||||
extern void free_locales(void);
|
void init_locales(void);
|
||||||
|
void free_locales(void);
|
||||||
|
void reset_locales(void);
|
||||||
|
|
||||||
/** operations on locales: **/
|
/** operations on locales: **/
|
||||||
extern void locale_setstring(struct locale *lang, const char *key,
|
extern void locale_setstring(struct locale *lang, const char *key,
|
||||||
|
|
23
src/util/unicode.test.c
Normal file
23
src/util/unicode.test.c
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include <CuTest.h>
|
||||||
|
#include "unicode.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
static void test_unicode_tolower(CuTest * tc)
|
||||||
|
{
|
||||||
|
char buffer[32];
|
||||||
|
CuAssertIntEquals(tc, 0, unicode_utf8_tolower(buffer, sizeof(buffer), "HeLlO W0Rld"));
|
||||||
|
CuAssertStrEquals(tc, "hello w0rld", buffer);
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
buffer[5]='X';
|
||||||
|
CuAssertIntEquals(tc, ENOMEM, unicode_utf8_tolower(buffer, 5, "HeLlO W0Rld"));
|
||||||
|
CuAssertStrEquals(tc, "helloX", buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
CuSuite *get_unicode_suite(void)
|
||||||
|
{
|
||||||
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
SUITE_ADD_TEST(suite, test_unicode_tolower);
|
||||||
|
return suite;
|
||||||
|
}
|
Loading…
Reference in a new issue