Lua module rewrite, part deux.

rules for E3 and E4
some missing files.
This commit is contained in:
Enno Rehling 2014-07-26 23:41:56 +02:00
parent d994caf7a3
commit 44c89e26ec
16 changed files with 1042 additions and 0 deletions

95
scripts/dumptable.lua Normal file
View File

@ -0,0 +1,95 @@
---------------------------------------------
-- Return indentation string for passed level
---------------------------------------------
local function tabs(i)
return string.rep(".",i).." " -- Dots followed by a space
end
-----------------------------------------------------------
-- Return string representation of parameter's value & type
-----------------------------------------------------------
local function toStrType(t)
local function fttu2hex(t) -- Grab hex value from tostring() output
local str = tostring(t);
if str == nil then
return "tostring() failure! \n"
else
local str2 = string.match(str,"[ :][ (](%x+)")
if str2 == nil then
return "string.match() failure: "..str.."\n"
else
return "0x"..str2
end
end
end
-- Stringify a value of a given type using a table of functions keyed
-- by the name of the type (Lua's version of C's switch() statement).
local stringify = {
-- Keys are all possible strings that type() may return,
-- per http://www.lua.org/manual/5.1/manual.html#pdf-type.
["nil"] = function(v) return "nil (nil)" end,
["string"] = function(v) return '"'..v..'" (string)' end,
["number"] = function(v) return v.." (number)" end,
["boolean"] = function(v) return tostring(v).." (boolean)" end,
["function"] = function(v) return fttu2hex(v).." (function)" end,
["table"] = function(v) return fttu2hex(v).." (table)" end,
["thread"] = function(v) return fttu2hex(v).." (thread)" end,
["userdata"] = function(v) return fttu2hex(v).." (userdata)" end
}
return stringify[type(t)](t)
end
-------------------------------------
-- Count elements in the passed table
-------------------------------------
local function lenTable(t) -- What Lua builtin does this simple thing?
local n=0 -- '#' doesn't work with mixed key types
if ("table" == type(t)) then
for key in pairs(t) do -- Just count 'em
n = n + 1
end
return n
else
return nil
end
end
--------------------------------
-- Pretty-print the passed table
--------------------------------
local function do_dumptable(t, indent, seen)
-- "seen" is an initially empty table used to track all tables
-- that have been dumped so far. No table is dumped twice.
-- This also keeps the code from following self-referential loops,
-- the need for which was found when first dumping "_G".
if ("table" == type(t)) then -- Dump passed table
seen[t] = 1
if (indent == 0) then
print ("The passed table has "..lenTable(t).." entries:")
indent = 1
end
for f,v in pairsByKeys(t) do
if ("table" == type(v)) and (seen[v] == nil) then -- Recurse
print( tabs(indent)..toStrType(f).." has "..lenTable(v).." entries: {")
do_dumptable(v, indent+1, seen)
print( tabs(indent).."}" )
else
print( tabs(indent)..toStrType(f).." = "..toStrType(v))
end
end
else
print (tabs(indent).."Not a table!")
end
end
--------------------------------
-- Wrapper to handle persistence
--------------------------------
function dumptable(t) -- Only global declaration in the package
-- This wrapper exists only to set the environment for the first run:
-- The second param is the indentation level.
-- The third param is the list of tables dumped during this call.
-- Getting this list allocated and freed was a pain, and this
-- wrapper was the best solution I came up with...
return do_dumptable(t, 0, {})
end

View File

@ -0,0 +1,10 @@
-- Astralraum
astral = {}
function astral.update()
print('spawn braineaters')
spawn_braineaters(0.25)
end
return astral

View File

@ -0,0 +1,16 @@
require 'eressea.spells'
print("rules for game E2")
return {
require('eressea'),
require('eressea.xmas2004'),
require('eressea.xmas2005'),
require('eressea.xmas2006'),
require('eressea.wedding'),
require('eressea.embassy'),
require('eressea.eternath'),
require('eressea.tunnels'),
require('eressea.ponnuki'),
require('eressea.astral'),
require('eressea.ents')
}

View File

@ -0,0 +1,11 @@
require 'eressea.e3.rules'
require 'eressea.spells'
print("rules for game E3")
return {
require('eressea'),
require('eressea.xmas2009'),
require('eressea.markets'),
require('eressea.frost'),
require('eressea.ents')
}

View File

@ -0,0 +1,77 @@
-- when appending to this, make sure the item has a canuse-function!
local goblin_denied = " plate lance mallornlance greatbow axe greatsword halberd rustyaxe rustyhalberd towershield scale "
function item_canuse(u, iname)
local race = u.race
if race=="goblin" then
if string.find(goblin_denied, " " .. iname .. " ") then
return false
end
end
if iname=="rep_crossbow" then
-- only dwarves and halflings allowed to use repeating crossbow
return race=="dwarf" or race=="halfling"
end
if iname=="scale" then
-- only dwarves and halflings can use scale
return race=="dwarf" or race=="halfling"
end
if iname=="towershield" then
-- only dwarves allowed to use towershield
return race=="dwarf"
end
if iname=="greatbow" then
-- only elves use greatbow
return race=="elf"
end
return true
end
function building_protection(b, u)
return 1
end
function building_taxes(b, blevel)
btype = b.type
if btype=="castle" then
return blevel * 0.01
elseif btype=="watch" then
return blevel * 0.005
end
return 0.0
end
-- the "raindance" spell
function raindance(r, mage, level, force)
if (create_curse(mage, r, "blessedharvest", force, 1+force*2, 100 * force)) then
-- slightly crooked way of reporting an action to everyone in the region
local msg = message.create("raindance_effect")
msg:set_unit("mage", mage)
if (msg:report_action(r, mage, 3)) then
local msg2 = message.create("raindance_effect")
msg2:set_unit("mage", nil)
msg2:report_action(r, mage, 4)
end
end
return level
end
-- the "blessed harvest" spell
function blessedharvest(r, mage, level, force)
if create_curse(mage, r, "blessedharvest", force, 1+force*2, 50 * force) then
-- slightly crooked way of reporting an action to everyone in the region
local msg = message.create("harvest_effect")
msg:set_unit("mage", mage)
if (msg:report_action(r, mage, 3)) then
local msg2 = message.create("harvest_effect")
msg2:set_unit("mage", nil)
msg2:report_action(r, mage, 4)
end
for idx, rn in ipairs(r.adj) do
-- nur landregionen haben moral>=0
if r.morale>=0 then
create_curse(mage, r, "blessedharvest", force, force*2, 50 * force)
end
end
end
return level
end

View File

@ -0,0 +1,11 @@
require 'eressea.e3.rules'
require 'eressea.spells'
print("rules for game E3")
return {
require('eressea'),
require('eressea.xmas2009'),
require('eressea.markets'),
require('eressea.frost'),
require('eressea.ents')
}

52
scripts/eressea/frost.lua Normal file
View File

@ -0,0 +1,52 @@
local function is_winter(turn)
local season = get_season(turn)
return season == "calendar::winter"
end
local function is_spring(turn)
local season = get_season(turn)
return season == "calendar::spring"
end
local function freeze(r, chance)
for i, rn in ipairs(r.adj) do
-- each region has a chance to freeze
if rn.terrain=="ocean" and (chance>=100 or math.fmod(rng_int(), 100)<chance) then
rn.terrain = "packice"
end
end
end
local function thaw(r, chance)
if chance>=100 or math.fmod(rng_int(), 100)<chance then
r.terrain = "ocean"
for s in r.ships do
s.coast = nil
end
end
end
local frost = {}
function frost.update()
local turn = get_turn()
if is_winter(turn) then
for r in regions() do
if r.terrain=="glacier" then
freeze(r, 20)
end
end
elseif is_spring(turn) then
for r in regions() do
if r.terrain=="packice" then
thaw(r, 20)
end
end
elseif is_spring(turn-1) then
for r in regions() do
if r.terrain=="packice" then
thaw(r, 100)
end
end
end
end
return frost

29
scripts/eressea/gates.lua Normal file
View File

@ -0,0 +1,29 @@
-- implements gates and travel between them
-- used in HSE and Eressea
local gates = {}
function gates.travel(b, units)
-- we've found which units we want to exchange, now swap them:
local u
for key, u in pairs(units) do
u.region = b.region
u.building = b
end
end
function gates.units(b, maxsize)
local size = maxsize
local units = {}
local u
for u in b.units do
if u.number<=size and u.weight<=u.capacity then
units[u] = u
size = size - u.number
end
end
return units
end
return gates

23
scripts/eressea/init.lua Normal file
View File

@ -0,0 +1,23 @@
if config.paths ~= nil then
for path in string.gmatch(config.paths, "([^:]+)") do
package.path = package.path .. ';' .. path .. '\\?.lua;' .. path .. '\\?\\init.lua'
end
end
print(package.path)
require 'eressea.resources'
require 'eressea.spells'
local self = {}
function self.update()
print('spawn dragons')
spawn_dragons()
print('spawn undead')
spawn_undead()
update_guards()
update_scores()
end
return self

View File

@ -0,0 +1,90 @@
local function get_markets(r, result)
local n = 0
result = result or {}
for b in r.buildings do
if b.type=="market" then
u = b.owner
if u~=nil then
table.insert(result, u)
n = n + 1
end
end
end
return n, result
end
local function collect_markets(r, result)
local result = result or {}
local n = 0
n, result = get_markets(r, result)
for i, r in ipairs(r.adj) do
if r then
local x, result = get_markets(r, result)
n = n + x
end
end
return n, result
end
local function market_action(r)
local f = r.owner
local trade = 1000
if f~=nil and f.race=="halfling" then
trade = 600
end
local p = r:get_resource("peasant")
if p > 500 then
local n, markets = collect_markets(r)
if n>0 then
local give
if r.luxury~=nil then
give = {}
local numlux = p / trade
for x = 1, numlux do
local m = 1+math.fmod(rng_int(), n)
u = markets[m]
if give[u] then
give[u] = give[u] + 1
else
give[u] = 1
end
end
for u, v in pairs(give) do
u:add_item(r.luxury, v)
end
end
if r.herb~=nil then
give = {}
local numherb = p / 500
for x = 1, numherb do
local m = 1+math.fmod(rng_int(), n)
u = markets[m]
if give[u] then
give[u] = give[u] + 1
else
give[u] = 1
end
end
for u, v in pairs(give) do
u:add_item(r.herb, v)
end
end
end
end
end
local markets = {}
local function markets.update()
local r
for r in regions() do
market_action(r)
end
end
return markets

View File

@ -0,0 +1,98 @@
-- global functions used in items.xml
if not item_canuse then
-- define a default, everyone can use everything
function item_canuse(u, iname)
return true
end
end
function peasant_getresource(u)
return u.region:get_resource("peasant")
end
function peasant_changeresource(u, delta)
local p = u.region:get_resource("peasant")
p = p + delta
if p < 0 then
p = 0
end
u.region:set_resource("peasant", p)
return p
end
function hp_getresource(u)
return u.hp
end
function hp_changeresource(u, delta)
local hp = u.hp + delta
if hp < u.number then
if hp < 0 then
hp = 0
end
u.number = hp
end
u.hp = hp
return hp
end
function horse_limit(r)
return r:get_resource("horse")
end
function horse_produce(r, n)
local horses = r:get_resource("horse")
if horses>=n then
r:set_resource("horse", horses-n)
else
r:set_resource("horse", 0)
end
end
function log_limit(r)
-- if r:get_flag(1) then -- RF_MALLORN
-- return 0
-- end
return r:get_resource("tree") + r:get_resource("sapling")
end
function log_produce(r, n)
local trees = r:get_resource("tree")
if trees>=n then
r:set_resource("tree", trees-n)
else
r:set_resource("tree", 0)
n = n - trees
trees = r:get_resource("sapling")
if trees>=n then
r:set_resource("sapling", trees-n)
else
r:set_resource("sapling", 0)
end
end
end
function mallorn_limit(r)
if not r:get_flag(1) then -- RF_MALLORN
return 0
end
return r:get_resource("tree") + r:get_resource("sapling")
end
function mallorn_produce(r, n)
local trees = r:get_resource("tree")
if trees>=n then
r:set_resource("tree", trees-n)
else
r:set_resource("tree", 0)
n = n - trees
trees = r:get_resource("sapling")
if trees>=n then
r:set_resource("sapling", trees-n)
else
r:set_resource("sapling", 0)
end
end
end

155
scripts/eressea/spells.lua Normal file
View File

@ -0,0 +1,155 @@
function creation_message(mage, type, number)
local msg = message.create("item_create_spell")
local err = 0
err = err + msg:set_unit("mage", mage)
err = err + msg:set_int("number", number)
err = err + msg:set_resource("item", type)
if err ~= 0 then
return nil
else
return msg
end
end
local function create_item(mage, level, name, number)
local count = number or 1
mage:add_item(name, count);
local msg = creation_message(mage, name, count)
msg:send_faction(mage.faction)
return level
end
-- Wasser des Lebens
function create_potion_p2(r, mage, level, force)
return create_item(mage, level, "p2", level)
end
-- Siebenmeilentee
function create_potion_p0(r, mage, level, force)
return create_item(mage, level, "p0", level)
end
-- Wundsalbe
function create_potion_ointment(r, mage, level, force)
return create_item(mage, level, "ointment", level)
end
-- Bauernblut
function create_potion_peasantblood(r, mage, level, force)
return create_item(mage, level, "peasantblood", level)
end
-- Pferdeglueck
function create_potion_p9(r, mage, level, force)
return create_item(mage, level, "p9", level)
end
-- Schaffenstrunk
function create_potion_p3(r, mage, level, force)
return create_item(mage, level, "p3", level)
end
-- Heiltrank
function create_potion_p14(r, mage, level, force)
return create_item(mage, level, "p14", level)
end
-- Elixier der Macht
function create_potion_p13(r, mage, level, force)
return create_item(mage, level, "p13", level)
end
-- Erschaffe ein Flammenschwert
function create_firesword(r, mage, level, force)
return create_item(mage, level, "firesword")
end
-- Erschaffe einen Guertel der Trollstaerke
function create_trollbelt(r, mage, level, force)
return create_item(mage, level, "trollbelt")
end
-- Erschaffe einen Ring der Unsichtbarkeit
function create_roi(r, mage, level, force)
return create_item(mage, level, "roi")
end
-- Erschaffe einen Ring der flinken Finger
function create_roqf(r, mage, level, force)
return create_item(mage, level, "roqf")
end
-- Erschaffe ein Amulett des wahren Sehens
function create_aots(r, mage, level, force)
return create_item(mage, level, "aots")
end
-- Erschaffe einen magischen Kraeuterbeutel
function create_magicherbbag(r, mage, level, force)
return create_item(mage, level, "magicherbbag")
end
-- Erschaffe einen Taktikkristal
function create_dreameye(r, mage, level, force)
return create_item(mage, level, "dreameye")
end
-- Erschaffe einen Antimagiekristall
function create_antimagic(r, mage, level, force)
return create_item(mage, level, "antimagic")
end
-- Erschaffe eine Sphaere der Unsichtbarkeit
function create_invisibility_sphere(r, mage, level, force)
return create_item(mage, level, "sphereofinv")
end
-- Erschaffe einen Guertel der Keuschheit
function create_chastitybelt(r, mage, level, force)
return create_item(mage, level, "ao_chastity")
end
-- Erschaffe ein Runenschwert
function create_runesword(r, mage, level, force)
return create_item(mage, level, "runesword")
end
-- Erschaffe ein Aurafokus
function create_focus(r, mage, level, force)
return create_item(mage, level, "aurafocus")
end
-- Erschaffe einen Ring der Macht
function create_rop(r, mage, level, force)
return create_item(mage, level, "rop")
end
-- Erschaffe einen Ring der Regeneration
function create_ror(r, mage, level, force)
return create_item(mage, level, "ror")
end
-- Erschaffe einen Zauberbeutel
function create_bagofholding(r, mage, level, force)
return create_item(mage, level, "magicbag")
end
function earn_silver(r, mage, level, force)
local money = r:get_resource("money")
local wanted = 50 * force
local amount = wanted
if wanted > money then
amount = money
end
r:set_resource("money", money - amount)
mage:add_item("money", amount)
local msg = message.create("income")
msg:set_unit("unit", mage)
msg:set_region("region", r)
msg:set_int("mode", 6)
msg:set_int("wanted", wanted)
msg:set_int("amount", amount)
msg:send_faction(mage.faction)
return level
end

View File

@ -0,0 +1,52 @@
-- DEPRECATED
-- this script contains the action functions for the two portals
-- used on the jadee/wildente wedding island. the two _action functions
-- are used as age() functions for a building_action with b:addaction("name")
-- this module is deprecated, because it puts functions in the global environment for at_building_action
local gates = require('eressea.gates')
local hellgate = nil
local peacegate = nil
local function wedding_travellers(b)
local units = {}
for u in b.units do
if u:get_flag('wdgt') then
units[u] = u
end
end
return units
end
local function wedding_exchange(b1, b2)
local units1 = wedding_travellers(b1)
local units2 = wedding_travellers(b2)
gates.travel(b2, units1)
gates.travel(b1, units2)
end
function hellgate_action(b)
hellgate = b
return 1
end
function peacegate_action(b)
peacegate = b
return 1
end
local wedding = {}
function wedding.update()
if peacegate and hellgate then
wedding_exchange(peacegate, hellgate)
else
eressea.log.error("hellgate or peacegate not found!", hellgate, peacegate)
end
end
return wedding

View File

@ -0,0 +1,29 @@
function use_xmastree(u, amount)
if u.region.herb~=nil then
local trees = u.region:get_resource("tree")
u.region:set_resource("tree", 10+trees)
u:use_pooled("xmastree", amount)
local msg = message.create("usepotion")
msg:set_unit("unit", u)
msg:set_resource("potion", "xmastree")
msg:send_region(u.region)
return 0
end
end
local xmas = {}
function xmas.update()
if not get_key("xm09") then
print("Es weihnachtet sehr (2009)")
set_key("xm09", true)
for f in factions() do
f:add_item("xmastree", 1)
local msg = message.create("msg_event")
msg:set_string("string", translate("santa2006"))
msg:send_faction(f)
end
end
end
return xmas

194
scripts/tools/build-e3.lua Normal file
View File

@ -0,0 +1,194 @@
function size()
return 16
end
function make_island(pl, x, y, a, b)
if b==nil then b = a/3 end
local nx, ny = plane.normalize(pl, x, y)
gmtool.make_island(nx, ny, a, b)
end
function make_block(pl, x, y, r)
local nx, ny = plane.normalize(pl, x, y)
gmtool.make_block(nx, ny, r)
end
function find(email)
for f in factions() do if f.email==email then return f end end
return nil
end
function give_item(email, id, uname, iname)
f = find(email)
for u in f.units do
u.id=atoi36(id)
u.name=uname
u:add_item(iname, 1)
break
end
end
function give_items()
give_item("hongeldongel@web.de", "boss", "Drollitz", "rpg_item_1")
give_item("zangerl.helmut@chello.at", "holb", "Holbard", "rpg_item_2")
give_item("r.lang@chello.at", "brtL", "Bertl", "rpg_item_2")
give_item("schlaustauch@gmx.de", "bert", "Bertram", "rpg_item_3")
end
function island(pl, x, y, r)
make_block(pl, x, y, r)
make_island(pl, x+r/2+2, y+r/2, size() * 3)
make_island(pl, x-r-2, y+r/2, size() * 3)
make_island(pl, x-r/2-2, y-r/2, size() * 3)
make_island(pl, x+r+2, y-r/2, size() * 3)
make_island(pl, x+r/2+2, y-r-2, size() * 3)
make_island(pl, x-r/2-2, y+r+2, size() * 3)
end
function cross(pl, x, y, r)
make_block(pl, x-r, y+r*2, r)
make_block(pl, x+r*4/3, y, r)
make_block(pl, x-r*4/3, y, r)
make_block(pl, x+r, y-r*2, r)
make_island(pl, x, y, size() * 3)
make_island(pl, x, y-r*4/3, size() * 3)
make_island(pl, x, y+r*4/3, size() * 3)
make_island(pl, x+r*4/3, y-r*4/3, size() * 3)
make_island(pl, x-r*4/3, y+r*4/3, size() * 3)
end
function clean()
for r in regions() do
if r.terrain=="ocean" then
-- print(r)
region.destroy(r)
end
end
end
function count()
local i = 0
for f in factions() do i = i + 1 end
print(i)
end
function line(pl)
local m = 0
local i = 0
local x, y = plane.normalize(pl, 0, i)
local r = get_region(x, y)
while true do
if r==nil then
if m==0 and (i>=0 or i<-10) then
local s = size()
gmtool.make_island(x, y, s*3, s)
else
gmtool.make_block(x, y, 6)
end
r = get_region(x, y)
if r==nil then
r = region.create(x, y, "ocean")
end
m = 1 - m
end
i = r.y + 1
x, y = plane.normalize(pl, 0, i)
r = get_region(x, y)
if r~=nil and r.y==0 then break end
end
end
function build(pl)
local d = 28
local h = 20
line(pl)
island(pl, d+15, -6, 11)
island(pl, -d, -h-10, 11)
cross(pl, -d, h-10, 6)
island(pl, d, 2*h, 11)
end
function fill(pl, w, h)
local x, y
for x=0,w do
for y=0,h do
local nx, ny = plane.normalize(pl, x, y)
local r = get_region(nx, ny)
if r==nil then
r = region.create(nx, ny, "ocean")
end
end
end
end
function seed()
local input = io.open(config.basepath .. "/parteien.txt")
for f in factions() do
if f.race=="vampunicorn" then
local str = input:read("*line")
if str==nil then break end
local race, lang, email = str:match("([^ ]*) ([^ ]*) ([^ ]*)")
f.race = race:lower()
f.options = f.options + 4096
f.email = email
f.locale = lang
for u in f.units do
u.race = race:lower()
u.hp = u.hp_max
local b = building.create(u.region, "castle")
if lang=="de" then
u.name = "Entdecker"
b.name = "Heimat"
else
u.name = "Explorer"
b.name = "Home"
end
b.size = 10
u.building = b
end
end
end
for r in regions() do
r:set_resource("sapling", r:get_resource("tree")/4)
r:set_resource("seed", 0)
end
update_owners()
end
function select()
for f in factions() do
if f.email=="enno@eressea.de" then
for u in f.units do
gmtool.select(u.region, true)
u.number = 0
end
end
end
end
function justWords(str)
local t = {}
local function helper(word) table.insert(t, word) return "" end
if not str:gsub("%w+", helper):find"%S" then return t end
end
function rebuild()
free_game()
local w = 110
local h = 80
local pl = plane.create(0, -w/2, -h/2, w+1, h+1)
build(pl)
fill(pl, w, h)
write_map("export.cr")
end
function testwelt()
free_game()
local w = 10
local h = 10
local pl = plane.create(0, -w/2, -h/2, w+1, h+1)
gmtool.make_island(0, 0, 30, 3)
fill(pl, w, h)
write_map("export.cr")
end

100
scripts/tools/build-e4.lua Normal file
View File

@ -0,0 +1,100 @@
function new_faction(email, race, lang, r)
f = faction.create(email, race, lang)
u = unit.create(f, r, 10)
u:add_item("log", 5);
u:add_item("horse", 2);
u:add_item("silver", 1000);
u:add_item("adamantium", 1);
end
function get_homes(f)
homes={}
for u in f.units do
table.insert(homes, u.region)
end
return homes
end
if eressea~=nil then
eressea.free_game()
eressea.read_game("game4.dat")
homes = get_homes(get_faction("xin8"))
else
-- running in the lua interpreter, not eressea. fake it.
new_faction = print
eressea = { ['write_game'] = function(s) print("writing " .. s) end }
homes = { "Andune", "Bedap", "Curtis", "Dovre" }
end
local f=assert(io.open("factions", "r"))
line=f:read("*line")
players = {}
emails = {}
patrons = {}
nplayers = 0
while line~=nil do
fields = {}
line:gsub("([^\t]*)\t*", function(c) table.insert(fields, c) end)
line=f:read("*line")
email = fields[1]
if fields[2]=='yes' then
table.insert(patrons, email)
else
table.insert(emails, email)
end
if fields[3]=='German' then lang='de' else lang='en' end
race=string.gsub(fields[4], "/.*", ''):lower()
players[email] = { ['lang'] = lang, ['race'] = race }
nplayers = nplayers + 1
end
for k, r in ipairs(homes) do
print(k, r)
end
npatrons = #patrons
print(#homes .. " regions.")
print(nplayers .. " players.")
print(npatrons .. " patrons.")
maxfactions = 20
selected = {}
if maxfactions > nplayers then maxfactions = nplayers end
while maxfactions > 0 do
if npatrons > 0 then
email = patrons[npatrons]
patrons[npatrons] = nil
npatrons = npatrons - 1
else
local np = #emails
local i = math.random(np)
email = emails[i]
emails[i] = emails[np]
emails[np] = nil
end
local player = players[email]
player.email = email
table.insert(selected, player)
maxfactions = maxfactions - 1
end
-- random shuffle
for j=1,#selected do
k = math.random(j)
if k ~= j then
local temp = selected[j]
selected[j] = selected[k]
selected[k] = temp
end
end
print('## players')
for k, player in ipairs(selected) do
local r = homes[1 + k % #homes]
new_faction(player.email, player.race, player.lang, r)
print(player.email)
end
eressea.write_game("game4.dat")
print("## no faction")
for i, email in ipairs(emails) do
print(email)
end