as-hoc scripts for seeding new players into old game

This commit is contained in:
Enno Rehling 2015-04-30 15:22:06 +02:00
parent 4dd0ffefe1
commit 6c4e74bc25
3 changed files with 123 additions and 1 deletions

View File

@ -38,9 +38,11 @@ for line in infile.readlines():
if not options.has_key("reports"):
continue
reports = options["reports"].split(",")
# reports = reports + [ "iso.cr" ]
prefix = "%(turn)s-%(faction)s." % options
files=[]
times="../parteien"
if os.path.isfile(times):
files = files + [ times ]
if options["compression"]=="zip":
output = prefix+"zip"
files = [output]

88
scripts/newplayer.lua Normal file
View File

@ -0,0 +1,88 @@
function seed(r, email, race, lang)
local f = faction.create(email, race, lang)
local u = unit.create(f, r)
u:set_skill("perception", 30)
u:add_item("money", 10000)
items = {
log = 50,
stone = 50,
iron = 50,
laen = 10,
mallorn = 10,
skillpotion = 5
}
for it, num in pairs(items) do
u:add_item(it, num)
end
skills ={
"crossbow",
"mining",
"bow",
"building",
"trade",
"forestry",
"catapult",
"herbalism",
"training",
"riding",
"armorer",
"shipcraft",
"melee",
"sailing",
"polearm",
"espionage",
"quarrying",
"roadwork",
"tactics",
"stealth",
"entertainment",
"weaponsmithing",
"cartmaking",
"taxation",
"stamina"
}
for _, sk in ipairs(skills) do
u = unit.create(f, r, 5)
u:set_skill(sk, 15)
end
return f
end
turn = 923
dofile("config.lua")
p = require("populate")
eressea.read_game(("%d.dat"):format(turn))
best = { score = 0, r = nil }
limit = 30000
sel = p.select(regions(), limit)
for _, r in ipairs(sel) do
score = p.score(r)
if score > best.score then
best.r = r
best.score = score
end
print(score, r, r.terrain)
end
-- print(best.r, best.score)
math.randomseed(os.time())
print(#sel, limit)
players = {
{ email = "Reinhardt.Karnapke@Freenet.de", race = "dwarf", lang = "de" }
}
for _, p in ipairs(players) do
local index = math.random(#sel)
local start = nil
while not start or start.units() do
start = sel[index]
end
f = seed(start, p.email, p.race or "human", p.lang or "de")
print(f, start)
init_reports()
write_report(f)
end
eressea.write_game(("%d.dat.new"):format(turn))

32
scripts/populate.lua Normal file
View File

@ -0,0 +1,32 @@
local this = {}
local function score(r, res)
assert(r)
res = res or "peasant"
local x, y, rn
local peas = r:get_resource(res)
for _, rn in pairs(r.adj) do
if rn then
peas = peas + rn:get_resource(res)
end
end
return peas
end
local function select(regions, limit)
local sel = {}
for r in regions do
if r.terrain~="ocean" and r.units()==nil then
s = score(r)
if s >= limit then
table.insert(sel, r)
end
end
end
return sel
end
return {
score = score,
select = select
}