Merge pull request #186 from badgerman/develop

newplayer script updates, small gmtool fixes
This commit is contained in:
Enno Rehling 2015-05-10 14:05:39 -07:00
commit 7f1ee527d9
14 changed files with 158 additions and 78 deletions

View File

@ -91,7 +91,8 @@ ini_add lua install $SOURCE
ini_add lua paths $SOURCE/scripts:$SOURCE/lunit ini_add lua paths $SOURCE/scripts:$SOURCE/lunit
ini_add lua rules $rules ini_add lua rules $rules
ln -f $SOURCE/bin/eressea touch newfactions
ln -f $SOURCE/scripts/run-turn.lua ln -sf $SOURCE/bin/eressea
ln -f $SOURCE/scripts/reports.lua ln -sf $SOURCE/scripts/run-turn.lua
ln -f $SOURCE/scripts/config.lua ln -sf $SOURCE/scripts/reports.lua
ln -sf $SOURCE/scripts/config.lua

View File

@ -1,22 +1,38 @@
function seed(r, email, race, lang) dofile("config.lua")
p = require("populate")
local function read_players()
-- return {{ email = "noreply@mailinator.com", race = "dwarf", lang = "de" }}
local players = {}
local input = open("newfactions", "r")
while input do
local str = input:read("*line")
if str==nil then break end
local email, race, lang = str:match("([^ ]*) ([^ ]*) ([^ ]*)")
table.insert(players, { race = race, lang = lang, email = email })
end
return players
end
local function seed(r, email, race, lang)
local f = faction.create(email, race, lang) local f = faction.create(email, race, lang)
local u = unit.create(f, r) local u = unit.create(f, r)
u:set_skill("perception", 30) u:set_skill("perception", 30)
u:add_item("money", 10000) u:add_item("money", 20000)
items = { items = {
log = 50, log = 50,
stone = 50, stone = 50,
iron = 50, iron = 50,
laen = 10, laen = 10,
mallorn = 10, mallorn = 10,
skillpotion = 5 skillpotion = 5
} }
for it, num in pairs(items) do for it, num in pairs(items) do
u:add_item(it, num) u:add_item(it, num)
end end
u = nil
skills ={ skills ={
"crossbow", "crossbow",
"mining",
"bow", "bow",
"building", "building",
"trade", "trade",
@ -31,58 +47,80 @@ function seed(r, email, race, lang)
"sailing", "sailing",
"polearm", "polearm",
"espionage", "espionage",
"quarrying",
"roadwork", "roadwork",
"tactics", "tactics",
"stealth", "stealth",
"entertainment",
"weaponsmithing", "weaponsmithing",
"cartmaking", "cartmaking",
"taxation", "taxation",
"stamina" "stamina"
} }
unit.create(f, r, 50):set_skill("entertainment", 15)
unit.create(f, r, 5):set_skill("mining", 30)
unit.create(f, r, 5):set_skill("quarrying", 30)
for _, sk in ipairs(skills) do for _, sk in ipairs(skills) do
u = unit.create(f, r, 5) u = u or unit.create(f, r, 5)
u:set_skill(sk, 15) if u:set_skill(sk, 15)>0 then u=nil end
end end
return f return f
end end
turn = 923 local function dump_selection(sel)
dofile("config.lua") local best = { score = 0, r = nil }
p = require("populate") local r, score
eressea.read_game(("%d.dat"):format(turn)) for _, r in ipairs(sel) do
best = { score = 0, r = nil } score = p.score(r)
limit = 30000 if score > best.score then
sel = p.select(regions(), limit) best.r = r
for _, r in ipairs(sel) do best.score = score
score = p.score(r) end
if score > best.score then print(score, r, r.terrain)
best.r = r end
best.score = score return best
end
players = read_players()
local limit = 30000
local turn = get_turn()
local sel
if #players > 0 then
read_game(turn)
eressea.read_game(("%d.dat"):format(turn))
sel = p.select(regions(), limit)
if #sel > 0 then
local best = dump_selection(sel)
print("finest region, " .. best.score .. " points: " .. tostring(best.r))
end end
print(score, r, r.terrain)
end end
-- print(best.r, best.score)
math.randomseed(os.time()) math.randomseed(os.time())
print(#sel, limit) local newbs = {}
players = {
{ email = "Reinhardt.Karnapke@Freenet.de", race = "dwarf", lang = "de" }
}
for _, p in ipairs(players) do for _, p in ipairs(players) do
local index = math.random(#sel) local index = math.random(#sel)
local start = nil local start = nil
while not start or start.units() do while not start or start.units() do
start = sel[index] start = sel[index]
end end
f = seed(start, p.email, p.race or "human", p.lang or "de") local dupe = false
print(f, start) for f in factions() do
init_reports() if f.email==p.email then
write_report(f) print("seed: duplicate email " .. p.email .. " already used by faction " .. tostring(f))
dupe = true
break
end
end
if not dupe then
f = seed(start, p.email, p.race or "human", p.lang or "de")
print("new faction ".. tostring(f) .. " starts in ".. tostring(start))
table.insert(newbs, f)
end
end end
eressea.write_game(("%d.dat.new"):format(turn)) if #newbs > 0 then
init_reports()
for _, f in ipairs(newbs) do
write_report(f)
end
eressea.write_game(("%d.dat.new"):format(turn))
end

View File

@ -7,7 +7,8 @@ function setup()
"races" : { "human" : {} }, "races" : { "human" : {} },
"terrains" : { "plain" : { "flags" : [ "land" ] } }, "terrains" : { "plain" : { "flags" : [ "land" ] } },
"keywords" : { "de" : { "study": "LERNEN" } }, "keywords" : { "de" : { "study": "LERNEN" } },
"skills" : { "de": { "alchemy" : "Alchemie", "crossbow" : "Armbrust" } } "skills" : { "de": { "alchemy" : "Alchemie", "crossbow" : "Armbrust" } },
"spells" : { "fireball" : { "syntax" : "u+" } }
}]] }]]
eressea.game.reset() eressea.game.reset()
eressea.config.reset(); eressea.config.reset();
@ -36,3 +37,17 @@ function test_study_expensive()
assert_equal(1, u:get_skill("alchemy")) assert_equal(1, u:get_skill("alchemy"))
assert_equal(0, u:get_item("money")) assert_equal(0, u:get_item("money"))
end end
function test_unit_spells()
local r = region.create(0, 0, "plain")
local f = faction.create("test@example.com", "human", "de")
local u = unit.create(f, r, 1)
u.magic = "gray"
u:set_skill("magic", 1)
u:add_spell("toast")
assert_equal(nil, u.spells)
u:add_spell("fireball", 2)
local sp = u.spells()
assert_equal("fireball", sp.name)
assert_equal(2, sp.level)
end

View File

@ -297,7 +297,7 @@ static int tolua_faction_set_origin(lua_State * L)
plane *pl = rplane(r); plane *pl = rplane(r);
int id = pl ? pl->id : 0; int id = pl ? pl->id : 0;
set_ursprung(f, id, r->x - plane_center_x(pl), r->y - plane_center_y(pl)); set_origin(f, id, r->x - plane_center_x(pl), r->y - plane_center_y(pl));
return 0; return 0;
} }
@ -507,14 +507,6 @@ static int tolua_faction_tostring(lua_State * L)
return 1; return 1;
} }
#ifdef TODO /* these usertypes are undefined */
static int tolua_faction_get_spells(lua_State * L)
{
faction *self = (faction *) tolua_tousertype(L, 1, 0);
return tolua_quicklist_push(L, "spellbook", "spellbook_entry", self->spellbook->spells);
}
#endif
void tolua_faction_open(lua_State * L) void tolua_faction_open(lua_State * L)
{ {
/* register user types */ /* register user types */
@ -544,9 +536,6 @@ void tolua_faction_open(lua_State * L)
&tolua_faction_set_info); &tolua_faction_set_info);
tolua_variable(L, TOLUA_CAST "units", tolua_faction_get_units, NULL); tolua_variable(L, TOLUA_CAST "units", tolua_faction_get_units, NULL);
tolua_variable(L, TOLUA_CAST "heroes", tolua_faction_get_heroes, NULL); tolua_variable(L, TOLUA_CAST "heroes", tolua_faction_get_heroes, NULL);
#ifdef TODO
tolua_variable(L, TOLUA_CAST "spells", tolua_faction_get_spells, 0);
#endif
tolua_variable(L, TOLUA_CAST "maxheroes", tolua_faction_get_maxheroes, tolua_variable(L, TOLUA_CAST "maxheroes", tolua_faction_get_maxheroes,
NULL); NULL);
tolua_variable(L, TOLUA_CAST "password", tolua_faction_get_password, tolua_variable(L, TOLUA_CAST "password", tolua_faction_get_password,

View File

@ -560,7 +560,7 @@ static int tolua_unit_addspell(lua_State * L)
spell *sp = find_spell(str); spell *sp = find_spell(str);
if (!sp) { if (!sp) {
log_error("spell %s could not be found\n", str); log_warning("spell %s could not be found\n", str);
return EINVAL; return EINVAL;
} }
else { else {
@ -758,23 +758,22 @@ static int tolua_unit_get_items(lua_State * L)
return 1; return 1;
} }
#ifdef TODO /* spellbooks */
static int tolua_unit_get_spells(lua_State * L) static int tolua_unit_get_spells(lua_State * L)
{ {
unit *self = (unit *) tolua_tousertype(L, 1, 0); unit *self = (unit *) tolua_tousertype(L, 1, 0);
sc_mage *mage = get_mage(self); sc_mage *mage = self ? get_mage(self) : 0;
spellbook *sb = mage ? mage->spellbook : 0;
quicklist *slist = 0; quicklist *slist = 0;
if (sb) {
if (mage) { quicklist **slist_ptr = &sb->spells;
quicklist **slist_ptr = get_spelllist(mage, self->faction);
if (slist_ptr) { if (slist_ptr) {
slist = *slist_ptr; slist = *slist_ptr;
} }
} }
return tolua_quicklist_push(L, "spellbook", "spell_entry", slist);
return tolua_quicklist_push(L, "spell_list", "spell", slist);
} }
#ifdef TODO /* spellbooks */
static void unit_removespell(unit * u, spell * sp) static void unit_removespell(unit * u, spell * sp)
{ {
quicklist **isptr; quicklist **isptr;
@ -1034,8 +1033,8 @@ void tolua_unit_open(lua_State * L)
tolua_function(L, TOLUA_CAST "add_spell", &tolua_unit_addspell); tolua_function(L, TOLUA_CAST "add_spell", &tolua_unit_addspell);
#ifdef TODO /* spellbooks */ #ifdef TODO /* spellbooks */
tolua_function(L, TOLUA_CAST "remove_spell", &tolua_unit_removespell); tolua_function(L, TOLUA_CAST "remove_spell", &tolua_unit_removespell);
tolua_variable(L, TOLUA_CAST "spells", &tolua_unit_get_spells, 0);
#endif #endif
tolua_variable(L, TOLUA_CAST "spells", &tolua_unit_get_spells, 0);
tolua_function(L, TOLUA_CAST "cast_spell", &tolua_unit_castspell); tolua_function(L, TOLUA_CAST "cast_spell", &tolua_unit_castspell);
tolua_variable(L, TOLUA_CAST "magic", &tolua_unit_get_magic, tolua_variable(L, TOLUA_CAST "magic", &tolua_unit_get_magic,

View File

@ -47,6 +47,7 @@ without prior permission by the authors of Eressea.
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/save.h> #include <kernel/save.h>
#include <kernel/spell.h> #include <kernel/spell.h>
#include <kernel/spellbook.h>
#include "creport.h" #include "creport.h"
#include "economy.h" #include "economy.h"
@ -988,9 +989,22 @@ static int tolua_get_spell_level(lua_State * L)
static int tolua_get_spell_name(lua_State * L) static int tolua_get_spell_name(lua_State * L)
{ {
const struct locale *lang = default_locale;
spell *self = (spell *)tolua_tousertype(L, 1, 0); spell *self = (spell *)tolua_tousertype(L, 1, 0);
lua_pushstring(L, spell_name(self, lang)); lua_pushstring(L, self->sname);
return 1;
}
static int tolua_get_spell_entry_name(lua_State * L)
{
spellbook_entry *self = (spellbook_entry*)tolua_tousertype(L, 1, 0);
lua_pushstring(L, self->sp->sname);
return 1;
}
static int tolua_get_spell_entry_level(lua_State * L)
{
spellbook_entry *self = (spellbook_entry*)tolua_tousertype(L, 1, 0);
lua_pushinteger(L, self->level);
return 1; return 1;
} }
@ -1085,6 +1099,8 @@ int tolua_bindings_open(lua_State * L)
tolua_bind_open(L); tolua_bind_open(L);
/* register user types */ /* register user types */
tolua_usertype(L, TOLUA_CAST "spellbook");
tolua_usertype(L, TOLUA_CAST "spell_entry");
tolua_usertype(L, TOLUA_CAST "spell"); tolua_usertype(L, TOLUA_CAST "spell");
tolua_usertype(L, TOLUA_CAST "spell_list"); tolua_usertype(L, TOLUA_CAST "spell_list");
tolua_usertype(L, TOLUA_CAST "order"); tolua_usertype(L, TOLUA_CAST "order");
@ -1112,12 +1128,16 @@ int tolua_bindings_open(lua_State * L)
{ {
tolua_function(L, TOLUA_CAST "__tostring", tolua_get_spell_name); tolua_function(L, TOLUA_CAST "__tostring", tolua_get_spell_name);
tolua_variable(L, TOLUA_CAST "name", tolua_get_spell_name, 0); tolua_variable(L, TOLUA_CAST "name", tolua_get_spell_name, 0);
#ifdef TODO
tolua_variable(L, TOLUA_CAST "school", tolua_get_spell_school, 0);
tolua_variable(L, TOLUA_CAST "level", tolua_get_spell_level, 0);
#endif
tolua_variable(L, TOLUA_CAST "text", tolua_get_spell_text, 0); tolua_variable(L, TOLUA_CAST "text", tolua_get_spell_text, 0);
} tolua_endmodule(L); } tolua_endmodule(L);
tolua_cclass(L, TOLUA_CAST "spell_entry", TOLUA_CAST "spell_entry", TOLUA_CAST "",
NULL);
tolua_beginmodule(L, TOLUA_CAST "spell_entry");
{
tolua_function(L, TOLUA_CAST "__tostring", tolua_get_spell_entry_name);
tolua_variable(L, TOLUA_CAST "name", tolua_get_spell_entry_name, 0);
tolua_variable(L, TOLUA_CAST "level", tolua_get_spell_entry_level, 0);
} tolua_endmodule(L);
tolua_module(L, TOLUA_CAST "report", 1); tolua_module(L, TOLUA_CAST "report", 1);
tolua_beginmodule(L, TOLUA_CAST "report"); tolua_beginmodule(L, TOLUA_CAST "report");
{ {

View File

@ -929,6 +929,7 @@ static void handlekey(state * st, int c)
} }
} }
break; break;
case 'f':
case 0x14: /* C-t */ case 0x14: /* C-t */
terraform_at(&st->cursor, select_terrain(st, NULL)); terraform_at(&st->cursor, select_terrain(st, NULL));
st->modified = 1; st->modified = 1;
@ -1011,6 +1012,7 @@ static void handlekey(state * st, int c)
statusline(st->wnd_status->handle, "tag-"); statusline(st->wnd_status->handle, "tag-");
doupdate(); doupdate();
switch (getch()) { switch (getch()) {
case 'f':
case 't': case 't':
terraform_selection(st->selected, select_terrain(st, NULL)); terraform_selection(st->selected, select_terrain(st, NULL));
st->modified = 1; st->modified = 1;

View File

@ -257,7 +257,7 @@ unit *addplayer(region * r, faction * f)
char buffer[32]; char buffer[32];
assert(f->units == NULL); assert(f->units == NULL);
set_ursprung(f, 0, r->x, r->y); set_origin(f, 0, r->x, r->y);
u = create_unit(r, f, 1, f->race, 0, NULL, NULL); u = create_unit(r, f, 1, f->race, 0, NULL, NULL);
equip_items(&u->faction->items, get_equipment("new_faction")); equip_items(&u->faction->items, get_equipment("new_faction"));
equip_unit(u, get_equipment("first_unit")); equip_unit(u, get_equipment("first_unit"));

View File

@ -4,6 +4,7 @@
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/race.h> #include <kernel/race.h>
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/plane.h>
#include <kernel/config.h> #include <kernel/config.h>
#include <util/language.h> #include <util/language.h>
@ -109,6 +110,20 @@ static void test_get_monsters(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void test_set_origin(CuTest *tc) {
faction *f;
test_cleanup();
test_create_world();
f = test_create_faction(0);
CuAssertPtrEquals(tc, 0, f->ursprung);
set_origin(f, 0, 1, 1);
CuAssertIntEquals(tc, 0, f->ursprung->id);
CuAssertIntEquals(tc, 1, f->ursprung->x);
CuAssertIntEquals(tc, 1, f->ursprung->y);
test_cleanup();
}
CuSuite *get_faction_suite(void) CuSuite *get_faction_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
@ -117,5 +132,6 @@ CuSuite *get_faction_suite(void)
SUITE_ADD_TEST(suite, test_remove_empty_factions_allies); SUITE_ADD_TEST(suite, test_remove_empty_factions_allies);
SUITE_ADD_TEST(suite, test_remove_dead_factions); SUITE_ADD_TEST(suite, test_remove_dead_factions);
SUITE_ADD_TEST(suite, test_get_monsters); SUITE_ADD_TEST(suite, test_get_monsters);
SUITE_ADD_TEST(suite, test_set_origin);
return suite; return suite;
} }

View File

@ -136,7 +136,7 @@ ursprung_x(const faction * f, const plane * pl, const region * rdefault)
} }
if (!rdefault) if (!rdefault)
return 0; return 0;
set_ursprung((faction *)f, id, rdefault->x - plane_center_x(pl), set_origin((faction *)f, id, rdefault->x - plane_center_x(pl),
rdefault->y - plane_center_y(pl)); rdefault->y - plane_center_y(pl));
return rdefault->x - plane_center_x(pl); return rdefault->x - plane_center_x(pl);
} }
@ -159,7 +159,7 @@ ursprung_y(const faction * f, const plane * pl, const region * rdefault)
} }
if (!rdefault) if (!rdefault)
return 0; return 0;
set_ursprung((faction *)f, id, rdefault->x - plane_center_x(pl), set_origin((faction *)f, id, rdefault->x - plane_center_x(pl),
rdefault->y - plane_center_y(pl)); rdefault->y - plane_center_y(pl));
return rdefault->y - plane_center_y(pl); return rdefault->y - plane_center_y(pl);
} }
@ -221,7 +221,7 @@ const region * r)
*y = ny; *y = ny;
} }
void set_ursprung(faction * f, int id, int x, int y) void set_origin(faction * f, int id, int x, int y)
{ {
ursprung *ur; ursprung *ur;
assert(f != NULL); assert(f != NULL);

View File

@ -70,7 +70,7 @@ extern "C" {
struct plane *getplanebyid(int id); struct plane *getplanebyid(int id);
int plane_center_x(const struct plane *pl); int plane_center_x(const struct plane *pl);
int plane_center_y(const struct plane *pl); int plane_center_y(const struct plane *pl);
void set_ursprung(struct faction *f, int id, int x, int y); void set_origin(struct faction *f, int id, int x, int y);
struct plane *create_new_plane(int id, const char *name, int minx, int maxx, struct plane *create_new_plane(int id, const char *name, int minx, int maxx,
int miny, int maxy, int flags); int miny, int maxy, int flags);
struct plane *getplanebyname(const char *); struct plane *getplanebyname(const char *);

View File

@ -1250,7 +1250,7 @@ faction *readfaction(struct gamedata * data)
READ_INT(data->store, &id); READ_INT(data->store, &id);
READ_INT(data->store, &ux); READ_INT(data->store, &ux);
READ_INT(data->store, &uy); READ_INT(data->store, &uy);
set_ursprung(f, id, ux, uy); set_origin(f, id, ux, uy);
} }
f->newbies = 0; f->newbies = 0;

View File

@ -2544,7 +2544,7 @@ int origin_cmd(unit * u, struct order *ord)
px = (short)getint(); px = (short)getint();
py = (short)getint(); py = (short)getint();
set_ursprung(u->faction, getplaneid(u->region), px, py); set_origin(u->faction, getplaneid(u->region), px, py);
return 0; return 0;
} }

View File

@ -181,7 +181,7 @@ newfaction *read_newfactions(const char *filename)
password[0] = '\0'; password[0] = '\0';
if (sscanf(buf, "%54s %20s %8s %d %d %16s %d", email, race, lang, &bonus, if (sscanf(buf, "%54s %20s %8s %d %d %16s %d", email, race, lang, &bonus,
&subscription, password, &alliance) < 6) &subscription, password, &alliance) < 3)
break; break;
if (email[0] == '\0') if (email[0] == '\0')
break; break;