diff --git a/src/common/gamecode/market.c b/src/common/gamecode/market.c index 7e95b0c67..31ff27052 100644 --- a/src/common/gamecode/market.c +++ b/src/common/gamecode/market.c @@ -105,42 +105,44 @@ void do_markets(void) for (d=0;d!=MAXDIRECTIONS;++d) { region * r2 = rconnect(r, d); if (r2 && r2->buildings) { - nmarkets += get_markets(r, markets+nmarkets, MAX_MARKETS-nmarkets); + nmarkets += get_markets(r2, markets+nmarkets, MAX_MARKETS-nmarkets); } } - while (lux && numlux--) { - int n = rng_int() % nmarkets; - unit * u = markets[n]; - item * items; - attrib * a = a_find(u->attribs, &at_market); - if (a==NULL) { - unit_list * ulist = malloc(sizeof(unit_list)); - a = a_add(&u->attribs, a_new(&at_market)); - ulist->next = traders; - ulist->data = u; - traders = ulist; + if (nmarkets) { + while (lux && numlux--) { + int n = rng_int() % nmarkets; + unit * u = markets[n]; + item * items; + attrib * a = a_find(u->attribs, &at_market); + if (a==NULL) { + unit_list * ulist = malloc(sizeof(unit_list)); + a = a_add(&u->attribs, a_new(&at_market)); + ulist->next = traders; + ulist->data = u; + traders = ulist; + } + items = (item *)a->data.v; + i_change(&items, lux, 1); + a->data.v = items; + /* give 1 luxury */ } - items = (item *)a->data.v; - i_change(&items, lux, 1); - a->data.v = items; - /* give 1 luxury */ - } - while (herb && numherbs--) { - int n = rng_int() % nmarkets; - unit * u = markets[n]; - item * items; - attrib * a = a_find(u->attribs, &at_market); - if (a==NULL) { - unit_list * ulist = malloc(sizeof(unit_list)); - a = a_add(&u->attribs, a_new(&at_market)); - ulist->next = traders; - ulist->data = u; - traders = ulist; + while (herb && numherbs--) { + int n = rng_int() % nmarkets; + unit * u = markets[n]; + item * items; + attrib * a = a_find(u->attribs, &at_market); + if (a==NULL) { + unit_list * ulist = malloc(sizeof(unit_list)); + a = a_add(&u->attribs, a_new(&at_market)); + ulist->next = traders; + ulist->data = u; + traders = ulist; + } + items = (item *)a->data.v; + i_change(&items, herb, 1); + a->data.v = items; + /* give 1 luxury */ } - items = (item *)a->data.v; - i_change(&items, herb, 1); - a->data.v = items; - /* give 1 luxury */ } } } @@ -152,6 +154,7 @@ void do_markets(void) attrib * a = a_find(u->attribs, &at_market); item * items = a->data.v; + a->data.v = NULL; while (items) { item * itm = items; items = itm->next; @@ -159,7 +162,10 @@ void do_markets(void) if (itm->number) { ADDMSG(&u->faction->msgs, msg_message("buyamount", "unit amount resource", u, itm->number, itm->type->rtype)); + itm->next = NULL; i_add(&u->items, itm); + } else { + i_free(itm); } } diff --git a/src/common/kernel/building.c b/src/common/kernel/building.c index 7aa7eb0fb..f9b307988 100644 --- a/src/common/kernel/building.c +++ b/src/common/kernel/building.c @@ -454,6 +454,7 @@ new_building(const struct building_type * btype, region * r, const struct locale init_lighthouse = true; } + b->flags = BLD_WORKING|BLD_MAINTAINED; b->no = newcontainerid(); bhash(b); diff --git a/src/eressea/server.c b/src/eressea/server.c index 06f411b54..a88ef2673 100644 --- a/src/eressea/server.c +++ b/src/eressea/server.c @@ -599,7 +599,7 @@ static void write_spells(void) { struct locale * loc = find_locale("de"); - FILE * F = fopen("spells.txt", "w"); + FILE * F = fopen("spells.csv", "w"); spell_list * spl = spells; for (;spl;spl=spl->next) { const spell * sp = spl->data; @@ -615,6 +615,37 @@ write_spells(void) fclose(F); } +static void +write_skills(void) +{ + struct locale * loc = find_locale("de"); + FILE * F = fopen("skills.csv", "w"); + race * rc; + skill_t sk; + fputs("\"Rasse\",", F); + for (rc=races;rc;rc = rc->next) { + if (playerrace(rc)) { + fprintf(F, "\"%s\",", LOC(loc, rc->_name[0])); + } + } + fputc('\n', F); + + for (sk=0;sk!=MAXSKILLS;++sk) { + const char * str = skillname(sk, loc); + if (str) { + fprintf(F, "\"%s\",", str); + for (rc=races;rc;rc = rc->next) { + if (playerrace(rc)) { + if (rc->bonus[sk]) fprintf(F, "%d,", rc->bonus[sk]); + else fputc(',', F); + } + } + fputc('\n', F); + } + } + fclose(F); +} + int main(int argc, char *argv[]) { @@ -622,6 +653,7 @@ main(int argc, char *argv[]) char * lc_ctype; char * lc_numeric; lua_State * luaState = lua_init(); + static int write_csv = 1; setup_signal_handler(); @@ -650,9 +682,10 @@ main(int argc, char *argv[]) kernel_init(); game_init(); - if (0) + if (write_csv) { + write_skills(); write_spells(); - + } /* run the main script */ if (luafile==NULL) lua_console(luaState); else { diff --git a/src/eressea/tolua/bind_region.c b/src/eressea/tolua/bind_region.c index 4ee02f76d..27f1d6615 100644 --- a/src/eressea/tolua/bind_region.c +++ b/src/eressea/tolua/bind_region.c @@ -118,6 +118,15 @@ static int tolua_region_get_flag(lua_State* tolua_S) return 1; } +static int tolua_region_get_adj(lua_State* tolua_S) +{ + region* self = (region*)tolua_tousertype(tolua_S, 1, 0); + direction_t dir = (direction_t)tolua_tonumber(tolua_S, 2, 0); + + tolua_pushusertype(tolua_S, (void*)r_connect(self, dir), "region"); + return 1; +} + static int tolua_region_set_flag(lua_State* tolua_S) { region* self = (region*)tolua_tousertype(tolua_S, 1, 0); @@ -230,6 +239,7 @@ tolua_region_create(lua_State* tolua_S) if (result) { terraform_region(result, terrain); } + fix_demand(result); tolua_pushusertype(tolua_S, result, "region"); return 1; @@ -356,6 +366,7 @@ tolua_region_open(lua_State* tolua_S) tolua_function(tolua_S, "set_resource", tolua_region_set_resource); tolua_function(tolua_S, "get_flag", tolua_region_get_flag); tolua_function(tolua_S, "set_flag", tolua_region_set_flag); + tolua_function(tolua_S, "next", tolua_region_get_adj); tolua_function(tolua_S, "get_key", tolua_region_getkey); tolua_function(tolua_S, "set_key", tolua_region_setkey); diff --git a/src/res/e2k9/races.xml b/src/res/e2k9/races.xml index 585f6e397..c7cb5906c 100644 --- a/src/res/e2k9/races.xml +++ b/src/res/e2k9/races.xml @@ -40,10 +40,9 @@ + - - @@ -159,7 +158,7 @@ - + diff --git a/src/res/e2k9/spells.xml b/src/res/e2k9/spells.xml index ef31d931c..13b2aa0a0 100644 --- a/src/res/e2k9/spells.xml +++ b/src/res/e2k9/spells.xml @@ -405,7 +405,7 @@ - @@ -424,7 +424,7 @@ - diff --git a/src/res/e2k9/strings.xml b/src/res/e2k9/strings.xml index 9870cb085..78a59b7bb 100644 --- a/src/res/e2k9/strings.xml +++ b/src/res/e2k9/strings.xml @@ -7,10 +7,20 @@ _a: including article (ein Troll, a troll) --> - - des dritten Zeitalters - the third age - + + des dritten Zeitalters + the third age + + + + Repetierarmbrust + repeating crossbow + + + Repetierarmbrüste + repeating crossbows + + Wachstube guard house diff --git a/src/res/e2k9/weapons.xml b/src/res/e2k9/weapons.xml index 200be70de..1dadff1d7 100644 --- a/src/res/e2k9/weapons.xml +++ b/src/res/e2k9/weapons.xml @@ -4,6 +4,7 @@ + diff --git a/src/res/weapons/rep_crossbow.xml b/src/res/weapons/rep_crossbow.xml new file mode 100644 index 000000000..ad11c083b --- /dev/null +++ b/src/res/weapons/rep_crossbow.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/scripts/e2k9/items.lua b/src/scripts/e2k9/items.lua index d2875735d..9d759841c 100644 --- a/src/scripts/e2k9/items.lua +++ b/src/scripts/e2k9/items.lua @@ -6,7 +6,7 @@ function item_canuse(u, iname) return false end end - if iname=="towershield" then + if iname=="towershield" or iname=="rep_crossbow" then -- only dwarves allowed to use towershield return u.race=="dwarf" end diff --git a/src/scripts/tests.lua b/src/scripts/tests.lua index 874566d0b..c18527bbc 100644 --- a/src/scripts/tests.lua +++ b/src/scripts/tests.lua @@ -345,6 +345,32 @@ local function spells_csv() fail = 1 end +function test_market() + free_game() + local r + for x = -1, 1 do for y = -1, 1 do + r = region.create(x, y, "plain") + r.peasants = 5000 + end end + r = get_region(0, 0) + local b = building.create(r, "market") + b.size = 10 + local f = faction.create("enno@eressea.de", "human", "de") + f.id = 42 + local u = unit.create(f, r, 1) + u.building = b + u:add_item("money", u.number * 10000) + for i = 0, 5 do + local rn = r:next(i) + end + process_orders() + local len = 0 + for i in u.items do + len = len + 1 + end + assert(len>1) +end + function test_storage() free_game() local r = region.create(0, 0, "plain") @@ -385,10 +411,11 @@ tests = { ["produce"] = test_produce, ["rename"] = test_rename, ["recruit"] = test_recruit, - ["spells"] = test_spells + ["spells"] = test_spells, + ["storage"] = test_storage } mytests = { - ["storage"] = test_storage + ["market"] = test_market } fail = 0 for k, v in pairs(mytests) do @@ -403,7 +430,7 @@ end -- spells_csv() -if fail > 0 then +if true or fail > 0 then print(fail .. " tests failed.") io.stdin:read() end