forked from github/server
Merge pull request #523 from ennorehling/feature/bug-2207
fix seeding new players (bug 2207)
This commit is contained in:
commit
0a9cbc308b
|
@ -1,8 +1,8 @@
|
||||||
local autoseed = {}
|
local autoseed = {}
|
||||||
|
|
||||||
-- minimum required resources in the 7-hex neighborhood:
|
-- minimum required resources in the 7-hex neighborhood:
|
||||||
local peasants = 20000
|
local peasants = 10000
|
||||||
local trees = 1000
|
local trees = 800
|
||||||
-- number of starters per region:
|
-- number of starters per region:
|
||||||
local per_region = 2
|
local per_region = 2
|
||||||
|
|
||||||
|
@ -23,8 +23,12 @@ local function select_regions(regions, peasants, trees)
|
||||||
local sel = {}
|
local sel = {}
|
||||||
for r in regions do
|
for r in regions do
|
||||||
if not r.plane and r.terrain~="ocean" and not r.units() then
|
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")
|
||||||
table.insert(sel, r)
|
st = score(r, "tree")
|
||||||
|
if sp >= peasants then
|
||||||
|
if st >= trees then
|
||||||
|
table.insert(sel, r)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -47,8 +51,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,31 +76,38 @@ 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)
|
||||||
for _, p in ipairs(players) do
|
if #sel == 0 then
|
||||||
if num_seeded == per_region then
|
eressea.log.error("autoseed could not select regions for new factions")
|
||||||
while not start or start.units() do
|
else
|
||||||
local index = 1 + (rng_int() % #sel)
|
for _, p in ipairs(players) do
|
||||||
start = sel[index]
|
if num_seeded == per_region then
|
||||||
|
local index = rng_int() % #sel
|
||||||
|
while not start do
|
||||||
|
start = sel[index + 1]
|
||||||
|
index = (index + 1) % #sel
|
||||||
|
end
|
||||||
|
num_seeded = 0
|
||||||
|
end
|
||||||
|
local dupe = get_faction_by_email(p.email)
|
||||||
|
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
|
||||||
end
|
end
|
||||||
num_seeded = 0
|
|
||||||
end
|
|
||||||
local dupe = get_faction_by_email(p.email)
|
|
||||||
if dupe then
|
|
||||||
eressea.log.warning("seed: duplicate email " .. p.email .. " already used by " .. tostring(dupe))
|
|
||||||
else
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -889,19 +889,15 @@ 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);
|
||||||
|
const char *rcname = tolua_tostring(L, 4, NULL);
|
||||||
int num = (int)tolua_tonumber(L, 3, 1);
|
int num = (int)tolua_tonumber(L, 3, 1);
|
||||||
if (f && r) {
|
const race *rc;
|
||||||
const race *rc = f->race;
|
assert(f && r);
|
||||||
const char *rcname = tolua_tostring(L, 4, NULL);
|
rc = rcname ? rc_find(rcname) : f->race;
|
||||||
if (rcname)
|
assert(rc);
|
||||||
rc = rc_find(rcname);
|
unit *u = create_unit(r, f, num, rc, 0, NULL, NULL);
|
||||||
if (rc) {
|
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||||
unit *u = create_unit(r, f, num, rc, 0, NULL, NULL);
|
return 1;
|
||||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_tostring(lua_State * L)
|
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);
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue