From 8916a1756aab760b7b7c798b75ed62c01642dfe4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 24 Aug 2019 12:14:43 +0200 Subject: [PATCH 1/4] rule_give is crufty, do not involve it in destroyfaction --- src/kernel/config.c | 1 + src/kernel/unit.c | 10 ---------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index f620cb882..254bbec17 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -534,6 +534,7 @@ int rule_give(void) static int config; static int rule; if (config_changed(&config)) { + /* TODO: No game uses this. Eliminate? */ rule = config_get_int("rules.give.flags", GIVE_DEFAULT); } return rule; diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 2a9a3b5da..4c15683b1 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -239,19 +239,9 @@ int gift_items(unit * u, int flags) region *r = u->region; item **itm_p = &u->items; int retval = 0; - int rule = rule_give(); assert(u->region); - if ((rule & GIVE_ONDEATH) == 0 || !u->faction || (u->faction->flags & FFL_QUIT) == 0) { - if ((rule & GIVE_ALLITEMS) == 0 && (flags & GIFT_FRIENDS)) - flags -= GIFT_FRIENDS; - if ((rule & GIVE_PEASANTS) == 0 && (flags & GIFT_PEASANTS)) - flags -= GIFT_PEASANTS; - if ((rule & GIVE_SELF) == 0 && (flags & GIFT_SELF)) - flags -= GIFT_SELF; - } - if (u->items == NULL || fval(u_race(u), RCF_ILLUSIONARY)) return 0; From 434aa15b9afd4df474ba7e0b1d0428215faa608c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 14 Sep 2019 21:51:13 +0200 Subject: [PATCH 2/4] factions that idle out gift their stuff to friends --- src/kernel/faction.c | 5 ++--- src/spells/combatspells.c | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/kernel/faction.c b/src/kernel/faction.c index b6bd02659..882c1333a 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -408,9 +408,6 @@ void destroyfaction(faction ** fp) f->next = dead_factions; dead_factions = f; - fset(f, FFL_QUIT); - f->_alive = false; - if (f->spellbook) { spellbook_clear(f->spellbook); free(f->spellbook); @@ -463,6 +460,8 @@ void destroyfaction(faction ** fp) setalliance(f, NULL); } + fset(f, FFL_QUIT); + f->_alive = false; funhash(f); /* units of other factions that were disguised as this faction diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 51059b546..f4b8b6954 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -952,8 +952,7 @@ int sp_hero(struct castorder * co) } } - m = - msg_message("cast_hero_effect", "mage spell amount", fi->unit, sp, targets); + m = msg_message("cast_hero_effect", "mage spell amount", fi->unit, sp, targets); message_all(b, m); msg_release(m); From 17ba4e7746f25a2ac93a847a206685bd53bd5ab4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 19 Sep 2019 05:03:01 +0200 Subject: [PATCH 3/4] allow clearing attributes from lua --- src/bind_unit.c | 10 ++++++++++ src/gmtool.c | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/bind_unit.c b/src/bind_unit.c index c5954082b..afbd81afe 100644 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -746,6 +746,15 @@ static int tolua_unit_get_curse(lua_State *L) { return 0; } +static int tolua_unit_clear_attribs(lua_State *L) { + unit *u = (unit *)tolua_tousertype(L, 1, NULL); + const char *name = tolua_tostring(L, 2, NULL); + const attrib_type *at = name ? at_find(name) : NULL; + + a_removeall(&u->attribs, at); + return 0; +} + static int tolua_unit_has_attrib(lua_State *L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); const char *name = tolua_tostring(L, 2, 0); @@ -978,6 +987,7 @@ void tolua_unit_open(lua_State * L) tolua_function(L, TOLUA_CAST "add_order", tolua_unit_add_order); tolua_function(L, TOLUA_CAST "clear_orders", tolua_unit_clear_orders); tolua_function(L, TOLUA_CAST "get_curse", tolua_unit_get_curse); + tolua_function(L, TOLUA_CAST "clear_attribs", tolua_unit_clear_attribs); tolua_function(L, TOLUA_CAST "has_attrib", tolua_unit_has_attrib); /* key-attributes for named flags: */ diff --git a/src/gmtool.c b/src/gmtool.c index 3c75fab7d..d876b22bd 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -441,16 +441,6 @@ static void paint_info_region(window * wnd, const state * st) r->land->trees[1] + r->land->trees[2]); } line++; - if (r->ships && (st->info_flags & IFL_SHIPS)) { - ship *sh; - wattron(win, A_BOLD | COLOR_PAIR(COLOR_YELLOW)); - mvwaddnstr(win, line++, 1, "* ships:", size - 5); - wattroff(win, A_BOLD | COLOR_PAIR(COLOR_YELLOW)); - for (sh = r->ships; sh && line < maxline; sh = sh->next) { - mvwprintw(win, line, 1, "%.4s ", itoa36(sh->no)); - umvwaddnstr(win, line++, 6, (char *)sh->type->_name, size - 5); - } - } if (r->units && (st->info_flags & IFL_FACTIONS)) { unit *u; wattron(win, A_BOLD | COLOR_PAIR(COLOR_YELLOW)); @@ -477,6 +467,16 @@ static void paint_info_region(window * wnd, const state * st) umvwaddnstr(win, line++, 6, unit_getname(u), size - 5); } } + if (r->ships && (st->info_flags & IFL_SHIPS)) { + ship *sh; + wattron(win, A_BOLD | COLOR_PAIR(COLOR_YELLOW)); + mvwaddnstr(win, line++, 1, "* ships:", size - 5); + wattroff(win, A_BOLD | COLOR_PAIR(COLOR_YELLOW)); + for (sh = r->ships; sh && line < maxline; sh = sh->next) { + mvwprintw(win, line, 1, "%.4s ", itoa36(sh->no)); + umvwaddnstr(win, line++, 6, (char *)sh->type->_name, size - 5); + } + } } } From 8433052c649e3a79756edabbe35ea4a69e9babff Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 19 Sep 2019 05:05:13 +0200 Subject: [PATCH 4/4] CID 204092: Memory - illegal accesses (NEGATIVE_RETURNS) --- src/bind_unit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bind_unit.c b/src/bind_unit.c index 921dcc659..45b4d7d0a 100644 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -531,8 +531,8 @@ static int tolua_unit_setskill(lua_State * L) bool rcmod = tolua_toboolean(L, 4, 0); skill_t sk = findskill(skname); - if (rcmod) level -= u_race(u)->bonus[sk]; if (sk != NOSKILL) { + if (rcmod) level -= u_race(u)->bonus[sk]; set_level(u, sk, level); lua_pushinteger(L, level); return 1;