forked from github/server
Merge branch 'develop' of github.com:ennorehling/eressea into develop
This commit is contained in:
commit
ba6f75df3e
2
crypto
2
crypto
|
@ -1 +1 @@
|
|||
Subproject commit f0013933852154eccc78536dd813774df5ee7f5d
|
||||
Subproject commit 913358a8d7d961ffc35b238c744ca6ce823ffdd9
|
|
@ -1,8 +1,8 @@
|
|||
local autoseed = {}
|
||||
|
||||
-- minimum required resources in the 7-hex neighborhood:
|
||||
local peasants = 20000
|
||||
local trees = 1000
|
||||
local peasants = 10000
|
||||
local trees = 800
|
||||
-- number of starters per region:
|
||||
local per_region = 2
|
||||
|
||||
|
@ -23,11 +23,15 @@ local function select_regions(regions, peasants, trees)
|
|||
local sel = {}
|
||||
for r in regions do
|
||||
if not r.plane and r.terrain~="ocean" and not r.units() then
|
||||
if score(r, "peasant") >= peasants and score(r, "tree") >= trees then
|
||||
sp = score(r, "peasant")
|
||||
st = score(r, "tree")
|
||||
if sp >= peasants then
|
||||
if st >= trees then
|
||||
table.insert(sel, r)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return sel
|
||||
end
|
||||
|
||||
|
@ -47,8 +51,11 @@ local function read_players()
|
|||
end
|
||||
|
||||
local function seed(r, email, race, lang)
|
||||
assert(r)
|
||||
local f = faction.create(email, race, lang)
|
||||
assert(f)
|
||||
local u = unit.create(f, r)
|
||||
assert(u)
|
||||
equip_unit(u, "new_faction")
|
||||
equip_unit(u, "first_unit")
|
||||
equip_unit(u, "first_" .. race, 7) -- disable old callbacks
|
||||
|
@ -69,20 +76,27 @@ end
|
|||
|
||||
function autoseed.init()
|
||||
-- local newbs = {}
|
||||
local num_seeded = per_region
|
||||
local num_seeded = 0
|
||||
local start = nil
|
||||
|
||||
eressea.log.info('autoseed new players')
|
||||
players = read_players()
|
||||
if players then
|
||||
print('autoseed ' .. #players .. ' new players')
|
||||
end
|
||||
if players and #players >= per_region then
|
||||
local sel
|
||||
eressea.log.info(#players .. ' new players')
|
||||
sel = select_regions(regions(), peasants, trees)
|
||||
if #sel == 0 then
|
||||
eressea.log.error("autoseed could not select regions for new factions")
|
||||
else
|
||||
for _, p in ipairs(players) do
|
||||
if num_seeded == per_region then
|
||||
while not start or start.units() do
|
||||
local index = 1 + (rng_int() % #sel)
|
||||
start = sel[index]
|
||||
local index = rng_int() % #sel
|
||||
while not start do
|
||||
start = sel[index + 1]
|
||||
index = (index + 1) % #sel
|
||||
end
|
||||
num_seeded = 0
|
||||
end
|
||||
|
@ -90,10 +104,10 @@ function autoseed.init()
|
|||
if dupe then
|
||||
eressea.log.warning("seed: duplicate email " .. p.email .. " already used by " .. tostring(dupe))
|
||||
else
|
||||
print("new faction ".. p.email .. " starts in ".. tostring(start))
|
||||
local f = seed(start, p.email, p.race or "human", p.lang or "de")
|
||||
num_seeded = num_seeded + 1
|
||||
print("new faction ".. tostring(f) .. " starts in ".. tostring(start))
|
||||
-- table.insert(newbs, f)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,32 +1,13 @@
|
|||
dofile("config.lua")
|
||||
p = require("populate")
|
||||
local path = 'scripts'
|
||||
if config.install then
|
||||
path = config.install .. '/' .. path
|
||||
end
|
||||
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
|
||||
require 'eressea'
|
||||
require 'eressea.xmlconf' -- read xml data
|
||||
|
||||
local function read_players()
|
||||
-- return {{ email = "noreply@mailinator.com", race = "dwarf", lang = "de" }}
|
||||
local players = {}
|
||||
local input = io.open("newfactions", "r")
|
||||
while input do
|
||||
local str = input:read("*line")
|
||||
if str==nil then break end
|
||||
local email, race, lang = str:match("([^ ]*) ([^ ]*) ([^ ]*)")
|
||||
if string.char(string.byte(email, 1))~='#' then
|
||||
table.insert(players, { race = race, lang = lang, email = email })
|
||||
end
|
||||
end
|
||||
return players
|
||||
end
|
||||
|
||||
local function seed(r, email, race, lang)
|
||||
local f = faction.create(email, race, lang)
|
||||
local u = unit.create(f, r)
|
||||
equip_unit(u, "new_faction")
|
||||
equip_unit(u, "first_unit")
|
||||
equip_unit(u, "first_" .. race, 7) -- disable old callbacks
|
||||
unit.create(f, r, 5):set_skill("mining", 30)
|
||||
unit.create(f, r, 5):set_skill("quarrying", 30)
|
||||
f:set_origin(r)
|
||||
return f
|
||||
end
|
||||
require 'config'
|
||||
auto = require 'eressea.autoseed'
|
||||
|
||||
local function dump_selection(sel)
|
||||
local best = { score = 0, r = nil }
|
||||
|
@ -42,54 +23,9 @@ local function dump_selection(sel)
|
|||
return best
|
||||
end
|
||||
|
||||
players = read_players()
|
||||
local peasants = 20000
|
||||
local trees = 1000
|
||||
local turn = get_turn()
|
||||
local sel
|
||||
if #players > 0 then
|
||||
eressea.read_game(("%d.dat"):format(turn))
|
||||
sel = p.select(regions(), peasants, trees)
|
||||
if #sel > 0 then
|
||||
local best = dump_selection(sel)
|
||||
print("finest region, " .. best.score .. " points: " .. tostring(best.r))
|
||||
end
|
||||
end
|
||||
math.randomseed(os.time())
|
||||
|
||||
local newbs = {}
|
||||
local per_region = 2
|
||||
local num_seeded = 2
|
||||
local start = nil
|
||||
for _, p in ipairs(players) do
|
||||
if num_seeded == per_region then
|
||||
while not start or start.units() do
|
||||
local index = math.random(#sel)
|
||||
start = sel[index]
|
||||
end
|
||||
num_seeded = 0
|
||||
end
|
||||
local dupe = false
|
||||
for f in factions() do
|
||||
if f.email==p.email then
|
||||
print("seed: duplicate email " .. p.email .. " already used by " .. tostring(f))
|
||||
dupe = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not dupe then
|
||||
num_seeded = num_seeded + 1
|
||||
f = seed(start, p.email, p.race or "human", p.lang or "de")
|
||||
print("new faction ".. tostring(f) .. " starts in ".. tostring(start))
|
||||
table.insert(newbs, f)
|
||||
end
|
||||
end
|
||||
|
||||
if #newbs > 0 then
|
||||
init_reports()
|
||||
for _, f in ipairs(newbs) do
|
||||
write_report(f)
|
||||
end
|
||||
eressea.write_game(("%d.dat.new"):format(turn))
|
||||
end
|
||||
|
||||
print("read game")
|
||||
eressea.read_game(get_turn() .. ".dat")
|
||||
print("auto-seed")
|
||||
auto.init()
|
||||
print("editor")
|
||||
gmtool.editor()
|
||||
|
|
|
@ -2,6 +2,29 @@ require "lunit"
|
|||
|
||||
module("tests.e2.e2features", package.seeall, lunit.testcase )
|
||||
|
||||
function test_build_harbour()
|
||||
-- try to reproduce mantis bug 2221
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("harbour@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r)
|
||||
size = 30
|
||||
u.number = 20
|
||||
u:set_skill("building", 3)
|
||||
u:add_item("money", size*250)
|
||||
u:add_item("stone", size*5)
|
||||
u:add_item("log", size*5)
|
||||
u:clear_orders()
|
||||
u:add_order("MACHE HAFEN")
|
||||
process_orders()
|
||||
assert_not_nil(u.building)
|
||||
assert_equal("harbour", u.building.type)
|
||||
assert_equal(20, u.building.size)
|
||||
process_orders()
|
||||
assert_equal(25, u.building.size)
|
||||
process_orders()
|
||||
assert_equal(25, u.building.size)
|
||||
end
|
||||
|
||||
local function one_unit(r, f)
|
||||
local u = unit.create(f, r, 1)
|
||||
u:add_item("money", u.number * 100)
|
||||
|
|
|
@ -889,20 +889,16 @@ static int tolua_unit_create(lua_State * L)
|
|||
{
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 2, 0);
|
||||
int num = (int)tolua_tonumber(L, 3, 1);
|
||||
if (f && r) {
|
||||
const race *rc = f->race;
|
||||
const char *rcname = tolua_tostring(L, 4, NULL);
|
||||
if (rcname)
|
||||
rc = rc_find(rcname);
|
||||
if (rc) {
|
||||
int num = (int)tolua_tonumber(L, 3, 1);
|
||||
const race *rc;
|
||||
assert(f && r);
|
||||
rc = rcname ? rc_find(rcname) : f->race;
|
||||
assert(rc);
|
||||
unit *u = create_unit(r, f, num, rc, 0, NULL, NULL);
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_unit_tostring(lua_State * L)
|
||||
{
|
||||
|
|
|
@ -448,7 +448,7 @@ static int tolua_equipunit(lua_State * L)
|
|||
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||
const char *eqname = tolua_tostring(L, 2, 0);
|
||||
int mask = (int)tolua_tonumber(L, 3, EQUIP_ALL);
|
||||
assert(mask > 0);
|
||||
assert(u && mask > 0);
|
||||
equip_unit_mask(u, get_equipment(eqname), mask);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1239,7 +1239,10 @@ void run_mapper(void)
|
|||
int split = 20;
|
||||
state *st;
|
||||
point tl;
|
||||
|
||||
/* FIXME: dsiable logging
|
||||
int old_flags = log_flags;
|
||||
log_flags &= ~(LOG_CPERROR | LOG_CPWARNING);
|
||||
*/
|
||||
init_curses();
|
||||
curs_set(1);
|
||||
|
||||
|
@ -1331,6 +1334,9 @@ void run_mapper(void)
|
|||
set_readline(NULL);
|
||||
curs_set(1);
|
||||
endwin();
|
||||
/* FIXME: reset logging
|
||||
log_flags = old_flags;
|
||||
*/
|
||||
state_close(st);
|
||||
}
|
||||
|
||||
|
|
|
@ -848,6 +848,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
|
|||
}
|
||||
|
||||
b->size += built;
|
||||
assert(b->type->maxsize <= 0 || b->size <= b->type->maxsize);
|
||||
fset(b, BLD_EXPANDED);
|
||||
|
||||
update_lighthouse(b);
|
||||
|
|
|
@ -1059,7 +1059,7 @@ int rule_give(void)
|
|||
|
||||
bool markets_module(void)
|
||||
{
|
||||
return config_get_int("modules.markets", 0);
|
||||
return (bool)config_get_int("modules.markets", 0);
|
||||
}
|
||||
|
||||
static struct param *configuration;
|
||||
|
|
|
@ -174,7 +174,7 @@ static unit *unitorders(FILE * F, int enc, struct faction *f)
|
|||
if (s[0] != '@') {
|
||||
char token[128];
|
||||
const char *stok = s;
|
||||
stok = parse_token(&stok, token, sizeof(token));
|
||||
stok = parse_token(&stok, token, 64); // FIXME: use sizeof, but parse_token overwrites the buffer
|
||||
|
||||
if (stok) {
|
||||
bool quit = false;
|
||||
|
@ -1676,6 +1676,11 @@ int read_game(gamedata *data) {
|
|||
if (b->type == bt_lighthouse) {
|
||||
r->flags |= RF_LIGHTHOUSE;
|
||||
}
|
||||
// repairs, bug 2221:
|
||||
if (b->type->maxsize>0 && b->size>b->type->maxsize) {
|
||||
log_error("building too big: %s (%s size %d of %d), fixing.", buildingname(b), b->type->_name, b->size, b->type->maxsize);
|
||||
b->size = b->type->maxsize;
|
||||
}
|
||||
}
|
||||
/* Schiffe */
|
||||
|
||||
|
|
51
src/main.c
51
src/main.c
|
@ -128,9 +128,31 @@ static int get_arg(int argc, char **argv, size_t len, int index, const char **re
|
|||
return index;
|
||||
}
|
||||
|
||||
static int verbosity_to_flags(int verbosity) {
|
||||
int flags = 0;
|
||||
switch (verbosity) {
|
||||
case 0:
|
||||
flags = 0;
|
||||
break;
|
||||
case 1:
|
||||
flags = LOG_CPERROR;
|
||||
break;
|
||||
case 2:
|
||||
flags = LOG_CPERROR | LOG_CPWARNING;
|
||||
break;
|
||||
case 3:
|
||||
flags = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO;
|
||||
break;
|
||||
default:
|
||||
flags = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO | LOG_CPDEBUG;
|
||||
break;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
static int parse_args(int argc, char **argv, int *exitcode)
|
||||
{
|
||||
int i, log_stderr = 0;
|
||||
int i, log_stderr = 0, log_flags = 0;
|
||||
|
||||
for (i = 1; i != argc; ++i) {
|
||||
char *argi = argv[i];
|
||||
|
@ -168,7 +190,8 @@ static int parse_args(int argc, char **argv, int *exitcode)
|
|||
i = get_arg(argc, argv, 2, i, &luafile, 0);
|
||||
break;
|
||||
case 'l':
|
||||
i = get_arg(argc, argv, 2, i, &logfile, 0);
|
||||
i = get_arg(argc, argv, 2, i, &arg, 0);
|
||||
log_flags = arg ? atoi(arg) : 0xff;
|
||||
break;
|
||||
case 't':
|
||||
i = get_arg(argc, argv, 2, i, &arg, 0);
|
||||
|
@ -192,28 +215,15 @@ static int parse_args(int argc, char **argv, int *exitcode)
|
|||
}
|
||||
}
|
||||
|
||||
switch (verbosity) {
|
||||
case 0:
|
||||
log_stderr = 0;
|
||||
break;
|
||||
case 1:
|
||||
log_stderr = LOG_CPERROR;
|
||||
break;
|
||||
case 2:
|
||||
log_stderr = LOG_CPERROR | LOG_CPWARNING;
|
||||
break;
|
||||
case 3:
|
||||
log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO;
|
||||
break;
|
||||
default:
|
||||
log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO | LOG_CPDEBUG;
|
||||
break;
|
||||
}
|
||||
// open logfile on disk:
|
||||
log_flags = verbosity_to_flags(log_flags);
|
||||
log_open(logfile, log_flags);
|
||||
|
||||
// also log to stderr:
|
||||
log_stderr = verbosity_to_flags(verbosity);
|
||||
if (log_stderr) {
|
||||
log_to_file(log_stderr | LOG_FLUSH | LOG_BRIEF, stderr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -296,7 +306,6 @@ int main(int argc, char **argv)
|
|||
/* parse arguments again, to override ini file */
|
||||
parse_args(argc, argv, &err);
|
||||
|
||||
log_open(logfile, LOG_CPERROR | LOG_CPWARNING | LOG_CPDEBUG | LOG_FLUSH);
|
||||
locale_init();
|
||||
|
||||
#ifdef CRTDBG
|
||||
|
|
|
@ -22,9 +22,6 @@ without prior permission by the authors of Eressea.
|
|||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
||||
/* TODO: set from external function */
|
||||
int log_flags = LOG_FLUSH | LOG_CPERROR | LOG_CPWARNING | LOG_CPDEBUG;
|
||||
|
||||
#ifdef STDIO_CP
|
||||
static int stdio_codepage = STDIO_CP;
|
||||
#else
|
||||
|
@ -126,7 +123,7 @@ static const char *log_prefix(int level) {
|
|||
return prefix;
|
||||
}
|
||||
|
||||
static int check_dupe(const char *format, int type)
|
||||
static int check_dupe(const char *format, int level)
|
||||
{
|
||||
static int last_type; /* STATIC_XCALL: used across calls */
|
||||
static char last_message[32]; /* STATIC_XCALL: used across calls */
|
||||
|
@ -136,12 +133,14 @@ static int check_dupe(const char *format, int type)
|
|||
return 1;
|
||||
}
|
||||
if (dupes) {
|
||||
if (level & LOG_CPERROR) {
|
||||
fprintf(stderr, "%s: last message repeated %d times\n", log_prefix(last_type),
|
||||
dupes + 1);
|
||||
}
|
||||
dupes = 0;
|
||||
}
|
||||
strlcpy(last_message, format, sizeof(last_message));
|
||||
last_type = type;
|
||||
last_type = level;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -176,6 +175,7 @@ static void log_stdio(void *data, int level, const char *module, const char *for
|
|||
if (format[len - 1] != '\n') {
|
||||
fputc('\n', out);
|
||||
}
|
||||
fflush(out);
|
||||
}
|
||||
|
||||
log_t *log_to_file(int flags, FILE *out) {
|
||||
|
@ -280,7 +280,7 @@ log_t *log_open(const char *filename, int log_flags)
|
|||
fprintf(logfile, "===\n=== Logfile started at %s===\n", ctime(<ime));
|
||||
return log_create(log_flags, logfile, log_stdio);
|
||||
}
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int log_level(log_t * log, int flags)
|
||||
|
|
|
@ -43,6 +43,8 @@ extern "C" {
|
|||
#define LOG_FLUSH 0x10
|
||||
#define LOG_BRIEF 0x20
|
||||
|
||||
|
||||
extern int log_stderr;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue