Lua 5.1 has deprecated the old for-syntax for tables.

This commit is contained in:
Enno Rehling 2007-06-13 12:38:15 +00:00
parent 9d72640755
commit 0c05d8f978
13 changed files with 62 additions and 66 deletions

View File

@ -10,8 +10,9 @@ function write_emails()
local locales = { "de", "en" } local locales = { "de", "en" }
local files = {} local files = {}
local key local key
for key in locales do local locale
local locale = locales[key] local file
for key, locale in pairs(locales) do
files[locale] = io.open(basepath .. "/emails." .. locale, "w") files[locale] = io.open(basepath .. "/emails." .. locale, "w")
end end
@ -21,8 +22,8 @@ function write_emails()
files[faction.locale]:write(faction.email .. "\n") files[faction.locale]:write(faction.email .. "\n")
end end
for key in files do for key, file in pairs(files) do
files[key]:close() file:close()
end end
end end

View File

@ -10,8 +10,8 @@ function change_locales()
-- local localechange = { } -- local localechange = { }
local localechange = { de = { "bLub" } } local localechange = { de = { "bLub" } }
for loc, flist in localechange do for loc, flist in pairs(localechange) do
for index, name in flist do for index, name in pairs(flist) do
f = get_faction(atoi36(name)) f = get_faction(atoi36(name))
if f ~= nil then if f ~= nil then
f.locale = loc f.locale = loc
@ -38,8 +38,8 @@ function run_scripts()
"eressea/embassy.lua", "eressea/embassy.lua",
"eressea/ents.lua" "eressea/ents.lua"
} }
for index in scripts do for index, value in pairs(scripts) do
loadscript(scripts[index]) loadscript(value)
end end
end end

View File

@ -1,8 +1,8 @@
function teleport_all(map, grave) function teleport_all(map, grave)
print("- teleporting all quest members to the grave") print("- teleporting all quest members to the grave")
local index local index
for index in map do local r
local r = map[index] for index, r in pairs(map) do
local u local u
for u in r.units do for u in r.units do
u.region = grave u.region = grave
@ -36,8 +36,8 @@ function wyrm()
end end
local index local index
for index in map do local r
local r = map[index] for index, r in pairs(map) do
if r~=grave then if r~=grave then
if (math.mod(r.x,2)==math.mod(get_turn(),2)) then if (math.mod(r.x,2)==math.mod(get_turn(),2)) then
r:add_notice("Eine Botschaft von Igjarjuk, Herr der Wyrme: 'Die Zeit des Wartens ist beinahe vorrüber. Euer Fürst kehrt aus dem Grabe zurück.'") r:add_notice("Eine Botschaft von Igjarjuk, Herr der Wyrme: 'Die Zeit des Wartens ist beinahe vorrüber. Euer Fürst kehrt aus dem Grabe zurück.'")

View File

@ -4,7 +4,9 @@ local function kill_multis()
-- ["amam"]="Wird wegen Missbrauch von Sonnensegeln geloescht", -- ["amam"]="Wird wegen Missbrauch von Sonnensegeln geloescht",
-- ["jr81"]="Wird wegen Missbrauch von Sonnensegeln geloescht" -- ["jr81"]="Wird wegen Missbrauch von Sonnensegeln geloescht"
} }
for k, v in multis do local k
local v
for k, v in pairs(multis) do
local f = get_faction(atoi36(k)) local f = get_faction(atoi36(k))
if f~=nil then if f~=nil then
print("- marking " .. tostring(f) .. " as a multi-player.") print("- marking " .. tostring(f) .. " as a multi-player.")

View File

@ -4,7 +4,7 @@
function gate_travel(b, units) function gate_travel(b, units)
-- we've found which units we want to exchange, now swap them: -- we've found which units we want to exchange, now swap them:
local u local u
for u in units do for key, u in pairs(units) do
u.region = b.region u.region = b.region
u.building = b u.building = b
end end
@ -16,7 +16,7 @@ function gate_units(b, maxsize)
local u local u
for u in b.units do for u in b.units do
if u.number<=size and u.weight<=u.capacity then if u.number<=size and u.weight<=u.capacity then
units[u] = u units[u] = u
size = size - u.number size = size - u.number
end end

View File

@ -1,25 +1,27 @@
function write_buildings(file) function write_buildings(file)
types = { "sawmill", "quarry", "mine", "lighthouse", "castle", "monument" } types = { "sawmill", "quarry", "mine", "lighthouse", "castle", "monument" }
for index, tname in types do local index
count = 0 local tname
best = nil for index, tname in pairs(types) do
count = 0
best = nil
for r in regions() do for r in regions() do
for b in r.buildings do for b in r.buildings do
if b.type == tname then if b.type == tname then
count = count + 1 count = count + 1
if best == nil then if best == nil then
best = b best = b
else else
if best.size<b.size then if best.size<b.size then
best = b best = b
end end
end end
end end
end end
end end
if best ~= nil then if best ~= nil then
file:write("\n" .. count .. " x " .. get_string("de", best.type) .. "\n") file:write("\n" .. count .. " x " .. get_string("de", best.type) .. "\n")
file:write("- " .. fname(best) .. ", Groesse " .. best.size .. "\n") file:write("- " .. fname(best) .. ", Groesse " .. best.size .. "\n")
end end
end end
end end

View File

@ -4,7 +4,9 @@ end
function write_spoils(file) function write_spoils(file)
items = { "elfspoil", "demonspoil", "goblinspoil", "dwarfspoil", "halflingspoil", "humanspoil", "aquarianspoil", "insectspoil", "catspoil", "orcspoil", "trollspoil" } items = { "elfspoil", "demonspoil", "goblinspoil", "dwarfspoil", "halflingspoil", "humanspoil", "aquarianspoil", "insectspoil", "catspoil", "orcspoil", "trollspoil" }
for index, iname in items do local index
local iname
for index, iname in pairs(items) do
printed = false printed = false
for f in factions() do for f in factions() do
trophies = 0 trophies = 0

View File

@ -6,21 +6,6 @@ function loadscript(name)
end end
end end
function change_locales()
-- local localechange = { }
local localechange = { de = { "bLub" } }
for loc, flist in localechange do
for index, name in flist do
f = get_faction(atoi36(name))
if f ~= nil then
f.locale = loc
print("LOCALECHANGE ", f, loc)
end
end
end
end
function run_scripts() function run_scripts()
scripts = { scripts = {
"spells.lua", "spells.lua",
@ -28,8 +13,8 @@ function run_scripts()
"familiars.lua", "familiars.lua",
"write_emails.lua" "write_emails.lua"
} }
for index in scripts do for index, name in pairs(scripts) do
loadscript(scripts[index]) loadscript(name)
end end
end end
@ -70,8 +55,6 @@ function process(orders)
update_guards() update_guards()
update_scores() update_scores()
change_locales()
-- use newfactions file to place out new players -- use newfactions file to place out new players
autoseed(basepath .. "/newfactions", false) autoseed(basepath .. "/newfactions", false)

View File

@ -285,9 +285,11 @@ function test_rewards()
items = { "hornofdancing", "trappedairelemental", items = { "hornofdancing", "trappedairelemental",
"aurapotion50", "bagpipeoffear", "aurapotion50", "bagpipeoffear",
"instantartacademy", "instantartsculpture" } "instantartacademy", "instantartsculpture" }
for index in items do local index
u:add_item(items[index], 1) local item
u:add_order('@BENUTZEN "' .. get_string("de", items[index]) .. '"') for index, item in pairs(items) do
u:add_item(item, 1)
u:add_order('@BENUTZEN "' .. get_string("de", item) .. '"')
end end
u:add_order("NUMMER PARTEI eviL") u:add_order("NUMMER PARTEI eviL")
@ -365,8 +367,10 @@ function run_scripts()
scripts = { scripts = {
"xmas2004.lua" "xmas2004.lua"
} }
for index in scripts do local index
local script = scriptpath .. "/" .. scripts[index] local name
for index, name in pairs(scripts) do
local script = scriptpath .. "/" .. name
print("- loading " .. script) print("- loading " .. script)
if pcall(dofile, script)==0 then if pcall(dofile, script)==0 then
print("Could not load " .. script) print("Could not load " .. script)

View File

@ -67,8 +67,10 @@ scripts = {
if orderfile==nil then if orderfile==nil then
print "you must specify an orderfile" print "you must specify an orderfile"
else else
for index in scripts do local name
local script = scriptpath .. "/" .. scripts[index] local index
for index, name in pairs(scripts) do
local script = scriptpath .. "/" .. name
print("- loading " .. script) print("- loading " .. script)
if pcall(dofile, script)==0 then if pcall(dofile, script)==0 then
print("Could not load " .. script) print("Could not load " .. script)

View File

@ -77,7 +77,8 @@ function make_faction(position, alliance, number, email, race)
end end
local sk local sk
for sk in skills do local skill
for sk, skill in pairs(skills) do
u = add_unit(f, position) u = add_unit(f, position)
-- anzahl personen berechnen -- anzahl personen berechnen
@ -86,7 +87,6 @@ function make_faction(position, alliance, number, email, race)
skillno = skillno - 1 skillno = skillno - 1
u.number = number u.number = number
local skill = skills[sk]
u:set_skill(skill, 3) u:set_skill(skill, 3)
print("- " .. number .. " x " .. skill) print("- " .. number .. " x " .. skill)

View File

@ -22,11 +22,12 @@ function write_standings()
log(file, "** Erfüllte Siegbedingungen **") log(file, "** Erfüllte Siegbedingungen **")
local condition local condition
for condition in conditions do local index
for index, condition in pairs(conditions) do
local none = true local none = true
log(file, conditions[condition]) log(file, condition)
for alliance in alliances() do for alliance in alliances() do
if victorycondition(alliance, condition)==1 then if victorycondition(alliance, index)==1 then
log(file, " - " .. alliance.name .. " (" .. alliance.id .. ")") log(file, " - " .. alliance.name .. " (" .. alliance.id .. ")")
none = false none = false
end end

View File

@ -3,8 +3,7 @@ function write_emails()
local locales = { "de", "en" } local locales = { "de", "en" }
local files = {} local files = {}
local key local key
for key in locales do for key, locale in pairs(locales) do
local locale = locales[key]
files[locale] = io.open(basepath .. "/emails." .. locale, "w") files[locale] = io.open(basepath .. "/emails." .. locale, "w")
end end
@ -14,8 +13,8 @@ function write_emails()
files[faction.locale]:write(faction.email .. "\n") files[faction.locale]:write(faction.email .. "\n")
end end
for key in files do for key, file in pairs(files) do
files[key]:close() file:close()
end end
end end