HSE-specific changes and LUA extensions donw during the game

This commit is contained in:
Enno Rehling 2005-01-13 12:42:36 +00:00
parent b32890df96
commit d46c0a9d46
12 changed files with 120 additions and 31 deletions

View File

@ -34,7 +34,11 @@ CCFLAGS += -Wwrite-strings
;
# this require the latet luabind from CVS
C++FLAGS += -DHAVE_LUABIND_B7 ;
if ! $(LUABIND) {
LUABIND = "B7" ;
}
C++FLAGS += -DHAVE_LUABIND_$(LUABIND) ;
if $(HOST) = "hamunaptra" {
XMLHDRS = /homes2/info-f/enno/software/hamunaptra/include/libxml2 ;
} else {

View File

@ -177,7 +177,7 @@ bind_building(lua_State * L)
.property("info", &building_getinfo, &building_setinfo)
.property("units", &building_units, return_stl_iterator)
.property("region", &building_getregion, &building_setregion)
.def("type", &building_gettype)
.property("type", &building_gettype)
.def_readonly("id", &building::no)
.def_readwrite("size", &building::size)
.def("add_action", &building_addaction)

View File

@ -4,6 +4,7 @@
// kernel includes
#include <kernel/building.h>
#include <kernel/item.h>
#include <kernel/plane.h>
#include <kernel/region.h>
#include <kernel/ship.h>
@ -106,6 +107,15 @@ region_setflag(region& r, int bit, bool set)
else r.flags &= ~(1<<bit);
}
static int
region_getresource(const region& r, const char * type)
{
const resource_type * rtype = rt_find(type);
if (rtype==rt_find("money")) return rmoney(&r);
if (rtype==rt_find("peasant")) return rpeasants(&r);
return 0;
}
static void
region_setroad(region& r, int dir, lua_Number size)
{
@ -249,6 +259,7 @@ bind_region(lua_State * L)
.def("set_road", &region_setroad)
.def("next", &region_next)
.def("get_resource", &region_getresource)
.def_readonly("x", &region::x)
.def_readonly("y", &region::y)
.def_readwrite("age", &region::age)

View File

@ -44,6 +44,12 @@ add_ship(const char * sname, region& r)
return sh;
}
const char *
ship_gettype(const ship& s) {
return s.type->name[0];
}
void
bind_ship(lua_State * L)
{
@ -54,6 +60,7 @@ bind_ship(lua_State * L)
class_<struct ship>("ship")
.def(self == ship())
.def(tostring(self))
.property("type", &ship_gettype)
.def_readonly("name", &ship::name)
.def_readonly("region", &ship::region)
.def_readonly("id", &ship::no)

View File

@ -27,7 +27,7 @@
<order name="MAGIEGEBIET" disable="yes"/>
<param name="entertain.base" value="15"/>
<param name="entertain.perlevel" value="5"/>
<param name="nmr.timeout" value="9999"/>
<param name="nmr.timeout" value="20"/>
<param name="nmr.removenewbie" value="0"/>
<param name="GiveRestriction" value="3"/>
<param name="NewbieImmunity" value="4"/>
@ -45,8 +45,8 @@
<xi:include href="eressea/temple.xml"/>
<strings>
<string name="mailto">
<text locale="de">hse-server@eressea.upb.de</text>
<text locale="en">hse-server@eressea.upb.de</text>
<text locale="de">hse-server@eressea.de</text>
<text locale="en">hse-server@eressea.de</text>
</string>
<string name="mailcmd">
<text locale="de">ERESSEA BEFEHLE</text>

View File

@ -11,16 +11,11 @@ function gate_units(b, maxsize)
local size = maxsize
local units = {}
local u
local first = true
for u in b.units do
if first then
first = false
else
if u.number<=size and u.weight<=u.capacity then
units[u] = u
size = size - u.number
end
if u.number<=size and u.weight<=u.capacity then
units[u] = u
size = size - u.number
end
end
return units

View File

@ -1,7 +1,7 @@
function run_scripts()
scripts = {
"hse05-portals.lua",
"hse05-grails.lua"
"hse05-stats.lua"
}
for index in scripts do
local script = scriptpath .. "/" .. scripts[index]
@ -57,7 +57,7 @@ function process(orders)
return -1
end
write_grails("grails.txt")
write_stats("grails.txt")
end

View File

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

View File

@ -1,25 +1,26 @@
function write_grails(filename)
function write_grails(file)
grails = {}
for f in factions() do
if f.id ~= 0 then
for u in f.units do
if u:get_item("grail") > 0 then
if grails[f] == nil then
grails[f] = u:get_item("grail")
else
grails[f] = grails[f] + u:get_item("grail")
end
for u in f.units do
if u:get_item("grail") > 0 then
if grails[f.id] == nil then
grails[f.id] = u:get_item("grail")
else
grails[f.id] = grails[f.id] + u:get_item("grail")
end
end
end
end
local file = io.open(reportpath .. "/" .. filename, "w")
file:write("Parteien mit mehr oder weniger als einem Gral:\n")
for k, v in grails do
if v ~= 1 then
for k in factions() do
v = 0
if grails[k.id] ~= nil then
v = grails[k.id]
end
if v~= 1 then
file:write("- " .. v .. " Grale: " .. k.name .. " (" .. itoa36(k.id) .. ")\n")
end
end
file:close()
end

View File

@ -5,10 +5,11 @@ end
buildings = {}
function portal_exchange(b1, param)
b2 = buildings[param]
if buildings[param] == nil then
buildings[param] = b1
id = buildings[param]
if id == nil then
buildings[param] = b1.id
else
b2 = get_building(id)
u1 = gate_units(b1, 100)
u2 = gate_units(b2, 100)
gate_travel(b1, u2)

View File

@ -0,0 +1,30 @@
function fname(f)
return f.name .. " (" .. itoa36(f.id) .. ")"
end
function write_spoils(file)
items = { "elfspoil", "demonspoil", "goblinspoil", "dwarfspoil", "halflingspoil", "humanspoil", "aquarianspoil", "insectspoil", "catspoil", "orcspoil", "trollspoil" }
for index, iname in items do
printed = false
for f in factions() do
trophies = 0
for u in f.units do
if u:get_item(iname) > 0 then
trophies = trophies + u:get_item(iname)
end
end
if trophies > 0 then
if not printed then
file:write(get_string("de", iname .. "_p") .. "\n")
printed=true
end
if trophies == 1 then
istr = get_string("de", iname)
else
istr = get_string("de", iname .. "_p")
end
file:write("- " .. trophies .. " " .. istr .. ": " .. fname(f) .. "\n")
end
end
end
end

View File

@ -0,0 +1,15 @@
dofile(scriptpath .. "/hse05-grails.lua")
dofile(scriptpath .. "/hse05-spoils.lua")
dofile(scriptpath .. "/hse05-buildings.lua")
function write_stats(filename)
local file = io.open(reportpath .. "/" .. filename, "w")
print("grails")
write_grails(file)
file:write("\n")
print("spoils")
write_spoils(file)
print("buildings")
write_buildings(file)
file:close()
end