check that there are any regions that we can seed new factions into
don't run into endless loop
This commit is contained in:
Enno Rehling 2016-05-15 23:21:39 +02:00
parent c31f543718
commit f2c02232cd
5 changed files with 37 additions and 30 deletions

View file

@ -47,8 +47,11 @@ local function read_players()
end end
local function seed(r, email, race, lang) local function seed(r, email, race, lang)
assert(r)
local f = faction.create(email, race, lang) local f = faction.create(email, race, lang)
assert(f)
local u = unit.create(f, r) local u = unit.create(f, r)
assert(u)
equip_unit(u, "new_faction") equip_unit(u, "new_faction")
equip_unit(u, "first_unit") equip_unit(u, "first_unit")
equip_unit(u, "first_" .. race, 7) -- disable old callbacks equip_unit(u, "first_" .. race, 7) -- disable old callbacks
@ -69,15 +72,21 @@ end
function autoseed.init() function autoseed.init()
-- local newbs = {} -- local newbs = {}
local num_seeded = per_region local num_seeded = 0
local start = nil local start = nil
eressea.log.info('autoseed new players') eressea.log.info('autoseed new players')
players = read_players() players = read_players()
if players then
print('autoseed ' .. #players .. ' new players')
end
if players and #players >= per_region then if players and #players >= per_region then
local sel local sel
eressea.log.info(#players .. ' new players') eressea.log.info(#players .. ' new players')
sel = select_regions(regions(), peasants, trees) 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 for _, p in ipairs(players) do
if num_seeded == per_region then if num_seeded == per_region then
while not start or start.units() do while not start or start.units() do
@ -98,5 +107,6 @@ function autoseed.init()
end end
end end
end end
end
return autoseed return autoseed

View file

@ -889,20 +889,16 @@ static int tolua_unit_create(lua_State * L)
{ {
faction *f = (faction *)tolua_tousertype(L, 1, 0); faction *f = (faction *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 2, 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); const char *rcname = tolua_tostring(L, 4, NULL);
if (rcname) int num = (int)tolua_tonumber(L, 3, 1);
rc = rc_find(rcname); const race *rc;
if (rc) { assert(f && r);
rc = rcname ? rc_find(rcname) : f->race;
assert(rc);
unit *u = create_unit(r, f, num, rc, 0, NULL, NULL); unit *u = create_unit(r, f, num, rc, 0, NULL, NULL);
tolua_pushusertype(L, u, TOLUA_CAST "unit"); tolua_pushusertype(L, u, TOLUA_CAST "unit");
return 1; return 1;
} }
}
return 0;
}
static int tolua_unit_tostring(lua_State * L) static int tolua_unit_tostring(lua_State * L)
{ {

View file

@ -448,7 +448,7 @@ static int tolua_equipunit(lua_State * L)
unit *u = (unit *)tolua_tousertype(L, 1, 0); unit *u = (unit *)tolua_tousertype(L, 1, 0);
const char *eqname = tolua_tostring(L, 2, 0); const char *eqname = tolua_tostring(L, 2, 0);
int mask = (int)tolua_tonumber(L, 3, EQUIP_ALL); int mask = (int)tolua_tonumber(L, 3, EQUIP_ALL);
assert(mask > 0); assert(u && mask > 0);
equip_unit_mask(u, get_equipment(eqname), mask); equip_unit_mask(u, get_equipment(eqname), mask);
return 0; return 0;
} }

View file

@ -174,7 +174,7 @@ static unit *unitorders(FILE * F, int enc, struct faction *f)
if (s[0] != '@') { if (s[0] != '@') {
char token[128]; char token[128];
const char *stok = s; 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) { if (stok) {
bool quit = false; bool quit = false;

View file

@ -176,6 +176,7 @@ static void log_stdio(void *data, int level, const char *module, const char *for
if (format[len - 1] != '\n') { if (format[len - 1] != '\n') {
fputc('\n', out); fputc('\n', out);
} }
fflush(out);
} }
log_t *log_to_file(int flags, FILE *out) { log_t *log_to_file(int flags, FILE *out) {