Merge branch 'master' of github.com:eressea/server

This commit is contained in:
Enno Rehling 2018-06-24 18:39:46 +02:00
commit 82b1e16a82
16 changed files with 95 additions and 85 deletions

View file

@ -698,10 +698,16 @@
<arg name="faction" type="faction"/> <arg name="faction" type="faction"/>
</type> </type>
</message> </message>
<message name="nr_borderlist_postfix" section="nr"> <message name="nr_border_transparent" section="nr">
<type> <type>
<arg name="transparent" type="int"/>
<arg name="object" type="string"/> <arg name="object" type="string"/>
<arg name="dir" type="direction"/>
</type>
</message>
<message name="nr_border_opaque" section="nr">
<type>
<arg name="object" type="string"/>
<arg name="dir" type="direction"/>
</type> </type>
</message> </message>
<message name="nr_building_besieged" section="nr"> <message name="nr_building_besieged" section="nr">

View file

@ -1355,8 +1355,11 @@ msgstr "\"Es herrscht eine fröhliche und ausgelassene Stimmung. ($int36($id))\"
msgid "buildroad" msgid "buildroad"
msgstr "\"$unit($unit) erweitert in $region($region) das Straßennetz um $int($size).\"" msgstr "\"$unit($unit) erweitert in $region($region) das Straßennetz um $int($size).\""
msgid "nr_borderlist_postfix" msgid "nr_border_opaque"
msgstr "\"$if($transparent,\" befindet sich\",\" versperrt\") ${object}$if($transparent,\"\",\" die Sicht\").\"" msgstr "Im $direction($dir) verperrt ${object} die Sicht."
msgid "nr_border_transparent"
msgstr "Im $direction($dir) befindet sich ${object}."
msgid "effectstrength" msgid "effectstrength"
msgstr "\"$unit($mage) erhöht die Körperkraft von $unit.dative($target) beträchtlich.\"" msgstr "\"$unit($mage) erhöht die Körperkraft von $unit.dative($target) beträchtlich.\""

View file

@ -1355,8 +1355,11 @@ msgstr "\"Everyone in this region seems to be having a very good time. ($int36($
msgid "buildroad" msgid "buildroad"
msgstr "\"$unit($unit) extends the road network in $region($region) by $int($size).\"" msgstr "\"$unit($unit) extends the road network in $region($region) by $int($size).\""
msgid "nr_borderlist_postfix" msgid "nr_border_opaque"
msgstr "\"$if($transparent,\" there is\",\" sight is blocked by \") ${object}.\"" msgstr "To the $direction($dir), ${object} is blocking the view."
msgid "nr_border_transparent"
msgstr "To the $direction($dir) is ${object}."
msgid "effectstrength" msgid "effectstrength"
msgstr "\"$unit($mage) increases the strength of $unit($target) dramatically.\"" msgstr "\"$unit($mage) increases the strength of $unit($target) dramatically.\""

View file

@ -1906,9 +1906,6 @@ msgstr "Mallorn"
msgid "castle" msgid "castle"
msgstr "Burg" msgstr "Burg"
msgid "nr_borderlist_infix"
msgstr ", im "
msgctxt "race" msgctxt "race"
msgid "shadowbat_p" msgid "shadowbat_p"
msgstr "Todesflattern" msgstr "Todesflattern"
@ -3706,9 +3703,6 @@ msgctxt "spell"
msgid "analyse_object" msgid "analyse_object"
msgstr "Lied des Ortes analysieren" msgstr "Lied des Ortes analysieren"
msgid "nr_borderlist_lastfix"
msgstr "und im "
msgctxt "race" msgctxt "race"
msgid "shadowknight_d" msgid "shadowknight_d"
msgstr "Schattenrittern" msgstr "Schattenrittern"

View file

@ -1642,9 +1642,6 @@ msgstr "mallorn"
msgid "castle" msgid "castle"
msgstr "castle" msgstr "castle"
msgid "nr_borderlist_infix"
msgstr ", to the "
msgctxt "race" msgctxt "race"
msgid "shadowbat_p" msgid "shadowbat_p"
msgstr "darkbats" msgstr "darkbats"
@ -3261,9 +3258,6 @@ msgctxt "spell"
msgid "analyse_object" msgid "analyse_object"
msgstr "Analysis" msgstr "Analysis"
msgid "nr_borderlist_lastfix"
msgstr ", and to the "
msgctxt "race" msgctxt "race"
msgid "shadowknight_d" msgid "shadowknight_d"
msgstr "shadow knights" msgstr "shadow knights"

View file

@ -4,6 +4,7 @@ eressea.log.debug('rules for game E2')
math.randomseed(rng.random()) math.randomseed(rng.random())
local equipment = require('eressea.equipment') local equipment = require('eressea.equipment')
local sets = { local sets = {
['seed_faction'] = { ['seed_faction'] = {
['items'] = { ['items'] = {

View file

@ -1,5 +1,6 @@
require 'eressea.path' require 'eressea.path'
require 'eressea.resources' require 'eressea.resources'
require 'eressea.equipment'
require 'eressea.spells' require 'eressea.spells'
local self = {} local self = {}

View file

@ -6,5 +6,6 @@ package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
require 'eressea.path' require 'eressea.path'
require 'eressea' require 'eressea'
require 'eressea.xmlconf' require 'eressea.xmlconf'
eressea.read_game(get_turn() .. ".dat") eressea.read_game(get_turn() .. ".dat")
gmtool.editor() gmtool.editor()

View file

@ -1092,9 +1092,13 @@ static void start_races(parseinfo *pi, const XML_Char *el, const XML_Char **attr
name = attr_get(attr, "name"); name = attr_get(attr, "name");
if (name) { if (name) {
int i;
assert(!rc); assert(!rc);
pi->object = rc = rc_get_or_create(name); pi->object = rc = rc_get_or_create(name);
int i; while (AT_NONE != rc->attack[nattacks].type) {
++nattacks;
}
for (i = 0; attr[i]; i += 2) { for (i = 0; attr[i]; i += 2) {
const XML_Char *key = attr[i], *val = attr[i + 1]; const XML_Char *key = attr[i], *val = attr[i + 1];

View file

@ -631,28 +631,24 @@ void kernel_init(void)
translation_init(); translation_init();
} }
static order * defaults[MAXLOCALES];
order *default_order(const struct locale *lang) order *default_order(const struct locale *lang)
{ {
int i = locale_index(lang); int i = locale_index(lang);
keyword_t kwd;
const char * str;
order *result = 0; order *result = 0;
assert(i < MAXLOCALES);
result = defaults[i]; assert(i < MAXLOCALES);
if (!result) { kwd = keyword_disabled(K_WORK) ? NOKEYWORD : K_WORK;
const char * str; str = config_get("orders.default");
keyword_t kwd = NOKEYWORD; if (str) {
str = config_get("orders.default"); kwd = findkeyword(str);
if (str) {
kwd = findkeyword(str);
}
if (kwd != NOKEYWORD) {
result = create_order(kwd, lang, NULL);
defaults[i] = result;
}
} }
return result ? copy_order(result) : 0; if (kwd != NOKEYWORD) {
result = create_order(kwd, lang, NULL);
return copy_order(result);
}
return NULL;
} }
int rule_give(void) int rule_give(void)
@ -760,14 +756,6 @@ void free_config(void) {
*/ */
void free_gamedata(void) void free_gamedata(void)
{ {
int i;
for (i = 0; i != MAXLOCALES; ++i) {
if (defaults[i]) {
free_order(defaults[i]);
defaults[i] = 0;
}
}
free(forbidden_ids); free(forbidden_ids);
forbidden_ids = NULL; forbidden_ids = NULL;

View file

@ -180,15 +180,22 @@ static void test_default_order(CuTest *tc) {
test_setup(); test_setup();
loc = test_create_locale(); loc = test_create_locale();
ord = default_order(loc);
CuAssertPtrEquals(tc, 0, ord);
free_order(ord);
config_set("orders.default", "work");
ord = default_order(loc); ord = default_order(loc);
CuAssertPtrNotNull(tc, ord); CuAssertPtrNotNull(tc, ord);
CuAssertIntEquals(tc, K_WORK, getkeyword(ord)); CuAssertIntEquals(tc, K_WORK, getkeyword(ord));
free_order(ord); free_order(ord);
enable_keyword(K_WORK, false);
ord = default_order(loc);
CuAssertPtrEquals(tc, NULL, ord);
free_order(ord);
config_set("orders.default", "entertain");
ord = default_order(loc);
CuAssertPtrNotNull(tc, ord);
CuAssertIntEquals(tc, K_ENTERTAIN, getkeyword(ord));
free_order(ord);
test_teardown(); test_teardown();
} }

View file

@ -188,7 +188,7 @@ border_type *find_bordertype(const char *name)
{ {
border_type *bt = bordertypes; border_type *bt = bordertypes;
while (bt && strcmp(bt->__name, name)!=0) while (bt && strcmp(bt->_name, name)!=0)
bt = bt->next; bt = bt->next;
return bt; return bt;
} }
@ -563,7 +563,7 @@ void write_borders(struct storage *store)
for (b = bhash; b != NULL; b = b->next) { for (b = bhash; b != NULL; b = b->next) {
if (b->type->valid && !b->type->valid(b)) if (b->type->valid && !b->type->valid(b))
continue; continue;
WRITE_TOK(store, b->type->__name); WRITE_TOK(store, b->type->_name);
WRITE_INT(store, b->id); WRITE_INT(store, b->id);
WRITE_INT(store, b->from->uid); WRITE_INT(store, b->from->uid);
WRITE_INT(store, b->to->uid); WRITE_INT(store, b->to->uid);
@ -614,7 +614,7 @@ int read_borders(gamedata *data)
if (to == from && from) { if (to == from && from) {
direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS); direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS);
region *r = rconnect(from, dir); region *r = rconnect(from, dir);
log_error("[read_borders] invalid %s in %s\n", type->__name, regionname(from, NULL)); log_error("[read_borders] invalid %s in %s\n", type->_name, regionname(from, NULL));
if (r != NULL) if (r != NULL)
to = r; to = r;
} }
@ -633,5 +633,5 @@ int read_borders(gamedata *data)
} }
const char * border_name(const connection *co, const struct region * r, const struct faction * f, int flags) { const char * border_name(const connection *co, const struct region * r, const struct faction * f, int flags) {
return (co->type->name) ? co->type->name(co, r, f, flags) : co->type->__name; return (co->type->name) ? co->type->name(co, r, f, flags) : co->type->_name;
} }

View file

@ -45,7 +45,7 @@ extern "C" {
} connection; } connection;
typedef struct border_type { typedef struct border_type {
const char *__name; /* internal use only */ const char *_name; /* internal use only */
variant_type datatype; variant_type datatype;
bool(*transparent) (const connection *, const struct faction *); bool(*transparent) (const connection *, const struct faction *);
/* is it possible to see through this? */ /* is it possible to see through this? */

View file

@ -29,6 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "group.h" #include "group.h"
#include "item.h" #include "item.h"
#include "messages.h" #include "messages.h"
#include "order.h"
#include "plane.h" #include "plane.h"
#include "race.h" #include "race.h"
#include "region.h" #include "region.h"
@ -294,8 +295,13 @@ unit *addplayer(region * r, faction * f)
assert(f->units == NULL); assert(f->units == NULL);
faction_setorigin(f, 0, r->x, r->y); faction_setorigin(f, 0, r->x, r->y);
u = create_unit(r, f, 1, f->race, 0, NULL, NULL); u = create_unit(r, f, 1, f->race, 0, NULL, NULL);
u->thisorder = default_order(f->locale);
unit_addorder(u, copy_order(u->thisorder));
name = config_get("rules.equip_first"); name = config_get("rules.equip_first");
equip_unit(u, name ? name : "first_unit"); if (!equip_unit(u, name ? name : "first_unit")) {
/* give every unit enough money to survive the first turn */
i_change(&u->items, get_resourcetype(R_SILVER)->itype, maintenance_cost(u));
}
u->hp = unit_max_hp(u) * u->number; u->hp = unit_max_hp(u) * u->number;
fset(u, UFL_ISNEW); fset(u, UFL_ISNEW);
if (f->race == get_race(RC_DAEMON)) { if (f->race == get_race(RC_DAEMON)) {

View file

@ -3,8 +3,10 @@
#include <kernel/ally.h> #include <kernel/ally.h>
#include <kernel/alliance.h> #include <kernel/alliance.h>
#include <kernel/calendar.h> #include <kernel/calendar.h>
#include <kernel/callbacks.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/item.h> #include <kernel/item.h>
#include <kernel/order.h>
#include <kernel/plane.h> #include <kernel/plane.h>
#include <kernel/race.h> #include <kernel/race.h>
#include <kernel/region.h> #include <kernel/region.h>
@ -298,9 +300,30 @@ static void test_save_special_items(CuTest *tc) {
test_teardown(); test_teardown();
} }
static void test_addplayer(CuTest *tc) {
unit *u;
region *r;
faction *f;
item_type *itype;
test_setup();
callbacks.equip_unit = NULL;
itype = test_create_silver();
r = test_create_plain(0, 0);
f = test_create_faction(NULL);
u = addplayer(r, f);
CuAssertPtrNotNull(tc, u);
CuAssertPtrEquals(tc, r, u->region);
CuAssertPtrEquals(tc, f, u->faction);
CuAssertIntEquals(tc, i_get(u->items, itype), 10);
CuAssertPtrNotNull(tc, u->orders);
CuAssertIntEquals(tc, K_WORK, getkeyword(u->orders));
test_teardown();
}
CuSuite *get_faction_suite(void) CuSuite *get_faction_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_addplayer);
SUITE_ADD_TEST(suite, test_max_migrants); SUITE_ADD_TEST(suite, test_max_migrants);
SUITE_ADD_TEST(suite, test_addfaction); SUITE_ADD_TEST(suite, test_addfaction);
SUITE_ADD_TEST(suite, test_remove_empty_factions); SUITE_ADD_TEST(suite, test_remove_empty_factions);

View file

@ -769,11 +769,11 @@ static void rp_battles(struct stream *out, faction * f)
while (bm) { while (bm) {
char buf[256]; char buf[256];
RENDER(f, buf, sizeof(buf), ("header_battle", "region", bm->r)); RENDER(f, buf, sizeof(buf), ("header_battle", "region", bm->r));
newline(out);
centre(out, buf, true); centre(out, buf, true);
newline(out); newline(out);
rp_messages(out, bm->msgs, f, 0, false); rp_messages(out, bm->msgs, f, 0, false);
bm = bm->next; bm = bm->next;
newline(out);
} }
} }
} }
@ -1237,39 +1237,17 @@ void report_region(struct stream *out, const region * r, faction * f)
if (edges) if (edges)
newline(out); newline(out);
for (e = edges; e; e = e->next) { for (e = edges; e; e = e->next) {
bool first = true;
message *msg; message *msg;
bufp = buf;
size = sizeof(buf) - 1;
for (d = 0; d != MAXDIRECTIONS; ++d) { for (d = 0; d != MAXDIRECTIONS; ++d) {
if (!e->exist[d]) if (e->exist[d]) {
continue; msg = msg_message(e->transparent ? "nr_border_transparent" : "nr_border_opaque",
/* this localization might not work for every language but is fine for de and en */ "object dir", e->name, d);
if (first) nr_render(msg, f->locale, buf, sizeof(buf), f);
bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_borderlist_prefix"), size); msg_release(msg);
else if (e->lastd == d) paragraph(out, buf, 0, 0, 0);
bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_borderlist_lastfix"), size); }
else
bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_borderlist_infix"), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)str_strlcpy(bufp, LOC(f->locale, directions[d]), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
first = false;
} }
/* TODO name is localized? Works for roads anyway... */
/* TODO: creating messages during reporting makes them not show up in CR? */
msg = msg_message("nr_borderlist_postfix", "transparent object",
e->transparent, e->name);
bytes = (int)nr_render(msg, f->locale, bufp, size, f);
msg_release(msg);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
*bufp = 0;
paragraph(out, buf, 0, 0, 0);
} }
if (edges) { if (edges) {
while (edges) { while (edges) {
@ -1299,7 +1277,6 @@ static void statistics(struct stream *out, const region * r, const faction * f)
} }
} }
/* print */ /* print */
newline(out);
m = msg_message("nr_stat_header", "region", r); m = msg_message("nr_stat_header", "region", r);
nr_render(m, f->locale, buf, sizeof(buf), f); nr_render(m, f->locale, buf, sizeof(buf), f);
msg_release(m); msg_release(m);
@ -2305,8 +2282,10 @@ report_plaintext(const char *filename, report_context * ctx,
report_travelthru(out, r, f); report_travelthru(out, r, f);
} }
if (wants_stats && r->seen.mode >= seen_unit) if (wants_stats && r->seen.mode >= seen_unit) {
statistics(out, r, f); statistics(out, r, f);
newline(out);
}
/* Nachrichten an REGION in der Region */ /* Nachrichten an REGION in der Region */
if (r->seen.mode >= seen_travel) { if (r->seen.mode >= seen_travel) {