diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index bf792f9f5..cf403bd93 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -1091,6 +1091,7 @@ report_computer(FILE * F, faction * f, const faction_list * addresses, building *b; ship *sh; unit *u; + int score = 0, avgscore = 0; const char * mailto = locale_string(f->locale, "mailto"); region * first = NULL, * last = NULL; const attrib * a; @@ -1124,9 +1125,11 @@ report_computer(FILE * F, faction * f, const faction_list * addresses, fprintf(F, "\"%s\";locale\n", locale_name(f->locale)); fprintf(F, "%d;Optionen\n", f->options); if (f->options & want(O_SCORE) && f->age>DISPLAYSCORE) { - fprintf(F, "%d;Punkte\n", f->score); - fprintf(F, "%d;Punktedurchschnitt\n", average_score_of_age(f->age, f->age / 24 + 1)); - } + score = f->score; + avgscore = average_score_of_age(f->age, f->age / 24 + 1); + } + fprintf(F, "%d;Punkte\n", score); + fprintf(F, "%d;Punktedurchschnitt\n", avgscore); { const char * zRace = rc_name(f->race, 1); fprintf(F, "\"%s\";Typ\n", add_translation(zRace, LOC(f->locale, zRace))); diff --git a/src/common/items/speedsail.c b/src/common/items/speedsail.c index 08afc0fc0..2ff1b9a8f 100644 --- a/src/common/items/speedsail.c +++ b/src/common/items/speedsail.c @@ -44,7 +44,7 @@ use_speedsail(struct unit * u, const struct item_type * itype, int amount, struc } else { if (u->ship) { attrib * a = a_find(u->ship->attribs, &at_speedup); - if (a!=NULL) { + if (a==NULL) { a = a_add(&u->ship->attribs, a_new(&at_speedup)); a->data.sa[0] = 50; /* speed */ a->data.sa[1] = 50; /* decay */ diff --git a/src/common/kernel/border.c b/src/common/kernel/border.c index 7669e5aca..c6e9d3089 100644 --- a/src/common/kernel/border.c +++ b/src/common/kernel/border.c @@ -24,6 +24,8 @@ #include #include +extern boolean incomplete_data; + unsigned int nextborder = 0; border * borders[BMAXHASH]; @@ -508,12 +510,12 @@ read_borders(FILE * f) assert(type || !"border type not registered"); from = findregion(fx, fy); if (from==NULL) { - log_error(("border for unknown region %d,%d\n", fx, fy)); + if (!incomplete_data) log_error(("border for unknown region %d,%d\n", fx, fy)); from = new_region(fx, fy); } to = findregion(tx, ty); if (to==NULL) { - log_error(("border for unknown region %d,%d\n", tx, ty)); + if (!incomplete_data) log_error(("border for unknown region %d,%d\n", tx, ty)); to = new_region(tx, ty); } if (to==from) { diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index bd82f6b98..89932b5b0 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -677,6 +677,7 @@ int maxregions = -1; int loadplane = 0; boolean dirtyload = false; +boolean incomplete_data = false; enum { U_MAN, @@ -1828,7 +1829,9 @@ readgame(const char * filename, int backup) n = ri(F); if (rmax<0) rmax = n; printf(" - Einzulesende Regionen: %d/%d\r", rmax, n); - + if (loadplane || dirtyload || firstx || firsty || maxregions>=0) { + incomplete_data = true; + } while (--n >= 0) { unit **up; boolean skip = false; diff --git a/src/eressea/korrektur.c b/src/eressea/korrektur.c index 1cebde167..6660d92d7 100644 --- a/src/eressea/korrektur.c +++ b/src/eressea/korrektur.c @@ -84,6 +84,7 @@ #undef XMAS2002 extern void reorder_owners(struct region * r); +extern int incomplete_data; static int curse_emptiness(void) @@ -933,15 +934,17 @@ extern border *borders[]; static void fix_road_borders(void) { - border *deleted[10000]; +#define MAXDEL 10000 + border *deleted[MAXDEL]; int hash; int i = 0; - for(hash=0; hashnexthash) { + for (bhash=borders[hash];bhash && i!=MAXDEL;bhash=bhash->nexthash) { border * b; - for (b=bhash;b;b=b->next) { + for (b=bhash;b && i!=MAXDEL;b=b->next) { if (b->type == &bt_road) { int x1, x2, y1, y2; region *r1, *r2; diff --git a/src/eressea/lua/building.cpp b/src/eressea/lua/building.cpp index aad03b575..ec54f32f8 100644 --- a/src/eressea/lua/building.cpp +++ b/src/eressea/lua/building.cpp @@ -18,6 +18,7 @@ // util includes #include +#include using namespace luabind; @@ -40,8 +41,26 @@ lc_age(struct attrib * a) assert(b!=NULL); if (fname==NULL) return -1; - luabind::object globals = luabind::get_globals(L); - if (globals.at(fname).type()!=LUA_TFUNCTION) return -1; + try { + luabind::object globals = luabind::get_globals(L); + luabind::object fun = globals.at(fname); + if (!fun.is_valid()) { + log_error(("Could not index function %s\n", fname)); + return -1; + } + if (fun.type()!=LUA_TFUNCTION) { + log_error(("Lua global object %s is not a function\n", fname)); + return -1; + } + } + catch (luabind::error& e) { + lua_State* L = e.state(); + const char* error = lua_tostring(L, -1); + + log_error((error)); + lua_pop(L, 1); + std::terminate(); + } return luabind::call_function(L, fname, *b); } diff --git a/src/scripts/eternath.lua b/src/scripts/eternath.lua index 475387285..f70e41a26 100644 --- a/src/scripts/eternath.lua +++ b/src/scripts/eternath.lua @@ -1,4 +1,8 @@ -function eternath_travellers(b, maxsize) +if gate_exchange==nil then + dofile("gates.lua") +end + +local function eternath_travellers(b, maxsize) local size = maxsize local units = {} local u @@ -17,28 +21,18 @@ function eternath_travellers(b, maxsize) return units end -function eternath_exchange(b1, b2) - -- identify everyone who is travelling, first: - local units1 = eternath_travellers(b1, 10) - local units2 = eternath_travellers(b2, 10) +local function eternath_exchange(b1, b2, size) + local units1 = eternath_travellers(b1, size) + local units2 = eternath_travellers(b2, size) - -- we've found which units we want to exchange, now swap them: - local u - for u in units1 do - u.region = b2.region - u.building = b2 - end - for u in units2 do - u.region = b1.region - u.building = b1 - end + gate_exchange(b1, units1, b2, units2) end function eternathgate_action(b) if eternathgate == nil then eternathgate = b else - eternath_exchange(eternathgate, b) + eternath_exchange(eternathgate, b, 10) end return 1 end diff --git a/src/scripts/gates.lua b/src/scripts/gates.lua new file mode 100644 index 000000000..823d9dd79 --- /dev/null +++ b/src/scripts/gates.lua @@ -0,0 +1,12 @@ +function gate_exchange(b1, units1, b2, units2) + -- we've found which units we want to exchange, now swap them: + local u + for u in units1 do + u.region = b2.region + u.building = b2 + end + for u in units2 do + u.region = b1.region + u.building = b1 + end +end diff --git a/src/scripts/wedding-jadee.lua b/src/scripts/wedding-jadee.lua index ec0501ed9..2f8f65df7 100644 --- a/src/scripts/wedding-jadee.lua +++ b/src/scripts/wedding-jadee.lua @@ -2,10 +2,14 @@ -- used on the jadee/wildente wedding island. the two _action functions -- are used as age() functions for a building_action with b:addaction("name") +if gate_exchange==nil then + dofile("gates.lua") +end + hellgate = nil peacegate = nil -function wedding_travellers(b) +local function wedding_travellers(b) local units = {} for u in b.units do @@ -16,20 +20,11 @@ function wedding_travellers(b) return units end -function wedding_exchange(b1, b2) +local function wedding_exchange(b1, b2) local units1 = wedding_travellers(b1) local units2 = wedding_travellers(b2) - -- we've found which units we want to exchange, now swap them: - local u - for u in units1 do - u.region = b2.region - u.building = b2 - end - for u in units2 do - u.region = b1.region - u.building = b1 - end + gate_exchange(b1, units1, b2, units2) end function hellgate_action(b) @@ -45,7 +40,7 @@ function peacegate_action(b) if peacegate == nil then peacegate = b else - gate_exchange(peacegate, b) + wedding_exchange(peacegate, b) end return 1 end