diff --git a/res/core/spellbooks/cerddor.xml b/res/core/spellbooks/cerddor.xml deleted file mode 100644 index f5158f37f..000000000 --- a/res/core/spellbooks/cerddor.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/res/core/spellbooks/draig.xml b/res/core/spellbooks/draig.xml deleted file mode 100644 index f4c66156b..000000000 --- a/res/core/spellbooks/draig.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/res/core/spellbooks/gray.xml b/res/core/spellbooks/gray.xml deleted file mode 100644 index 36e44cbd0..000000000 --- a/res/core/spellbooks/gray.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/res/core/spellbooks/gwyrrd.xml b/res/core/spellbooks/gwyrrd.xml deleted file mode 100644 index 5e07b8c7f..000000000 --- a/res/core/spellbooks/gwyrrd.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/res/core/spellbooks/illaun.xml b/res/core/spellbooks/illaun.xml deleted file mode 100644 index cbf57aa51..000000000 --- a/res/core/spellbooks/illaun.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/res/core/spellbooks/tybied.xml b/res/core/spellbooks/tybied.xml deleted file mode 100644 index a48d8e768..000000000 --- a/res/core/spellbooks/tybied.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/src/attributes/seenspell.c b/src/attributes/seenspell.c index b6edd3d98..c2b9c7c75 100644 --- a/src/attributes/seenspell.c +++ b/src/attributes/seenspell.c @@ -46,7 +46,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static int read_seenspells(variant *var, void *owner, struct gamedata *data) { - selist *ql; + selist *ql = NULL; storage *store = data->store; spell *sp = 0; char token[32]; diff --git a/src/battle.c b/src/battle.c index fb91a1998..01b865d61 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1539,6 +1539,17 @@ static int get_tactics(const side * as, const side * ds) return result - defense; } +double tactics_chance(const unit *u, int skilldiff) { + double tacch = 0.1 * skilldiff; + if (fval(u->region->terrain, SEA_REGION)) { + const ship *sh = u->ship; + if (sh) { + tacch *= sh->type->tac_bonus; + } + } + return tacch; +} + static troop select_opponent(battle * b, troop at, int mindist, int maxdist) { fighter *af = at.fighter; @@ -1560,12 +1571,7 @@ static troop select_opponent(battle * b, troop at, int mindist, int maxdist) /* percentage chance to get this attack */ if (tactics > 0) { - double tacch = 0.1 * tactics; - if (fval(b->region->terrain, SEA_REGION)) { - ship *sh = at.fighter->unit->ship; - if (sh) - tacch *= sh->type->tac_bonus; - } + double tacch = tactics_chance(af->unit, tactics); if (!chance(tacch)) { dt.fighter = NULL; } diff --git a/src/battle.h b/src/battle.h index f2dd1fea3..c9429a6b3 100644 --- a/src/battle.h +++ b/src/battle.h @@ -270,6 +270,7 @@ extern "C" { const char *sidename(const struct side * s); void battle_message_faction(struct battle * b, struct faction * f, struct message *m); + double tactics_chance(const struct unit *u, int skilldiff); #ifdef __cplusplus } #endif diff --git a/src/battle.test.c b/src/battle.test.c index f293f967d..56ca24ac4 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -665,6 +666,22 @@ static void test_drain_exp(CuTest *tc) test_teardown(); } +static void test_tactics_chance(CuTest *tc) { + unit *u; + ship_type *stype; + + test_setup(); + u = test_create_unit(test_create_faction(NULL), test_create_ocean(0, 0)); + CuAssertDblEquals(tc, 0.1, tactics_chance(u, 1), 0.01); + CuAssertDblEquals(tc, 0.3, tactics_chance(u, 3), 0.01); + stype = test_create_shiptype("brot"); + u->ship = test_create_ship(u->region, stype); + CuAssertDblEquals(tc, 0.2, tactics_chance(u, 2), 0.01); + stype->tac_bonus = 2.0; + CuAssertDblEquals(tc, 0.4, tactics_chance(u, 2), 0.01); + test_teardown(); +} + CuSuite *get_battle_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -681,6 +698,7 @@ CuSuite *get_battle_suite(void) SUITE_ADD_TEST(suite, test_natural_armor); SUITE_ADD_TEST(suite, test_magic_resistance); SUITE_ADD_TEST(suite, test_projectile_armor); + SUITE_ADD_TEST(suite, test_tactics_chance); DISABLE_TEST(suite, test_drain_exp); return suite; } diff --git a/src/kernel/db/sqlite.c b/src/kernel/db/sqlite.c index 965363223..b3090cca0 100644 --- a/src/kernel/db/sqlite.c +++ b/src/kernel/db/sqlite.c @@ -26,7 +26,8 @@ order_data *db_driver_order_load(int id) { order_data * od = NULL; int err; - + + ERRNO_CHECK(); if (g_order_tx_size > 0) { g_order_tx_size = 0; err = sqlite3_exec(g_db, "COMMIT", NULL, NULL, NULL); @@ -45,10 +46,12 @@ order_data *db_driver_order_load(int id) assert(bytes > 0); text = sqlite3_column_text(g_stmt_select, 0); odata_create(&od, 1+(size_t)bytes, (const char *)text); + ERRNO_CHECK(); return od; } } while (err == SQLITE_ROW); assert(err == SQLITE_DONE); + ERRNO_CHECK(); return NULL; } @@ -58,7 +61,9 @@ int db_driver_order_save(order_data *od) sqlite3_int64 id; assert(od && od->_str); - + + ERRNO_CHECK(); + if (g_order_batchsize > 0) { if (g_order_tx_size == 0) { err = sqlite3_exec(g_db, "BEGIN TRANSACTION", NULL, NULL, NULL); @@ -82,7 +87,7 @@ int db_driver_order_save(order_data *od) g_order_tx_size = 0; } } - + ERRNO_CHECK(); return (int)id; } @@ -91,6 +96,7 @@ void db_driver_open(void) int err; const char *dbname; + ERRNO_CHECK(); g_order_batchsize = config_get_int("game.dbbatch", 100); dbname = config_get("game.dbname"); if (!dbname) { @@ -108,16 +114,20 @@ void db_driver_open(void) assert(err == SQLITE_OK); err = sqlite3_prepare_v2(g_db, "SELECT data FROM orders WHERE id = ?", -1, &g_stmt_select, NULL); assert(err == SQLITE_OK); + ERRNO_CHECK(); } void db_driver_close(void) { int err; + ERRNO_CHECK(); err = sqlite3_finalize(g_stmt_select); assert(err == SQLITE_OK); err = sqlite3_finalize(g_stmt_insert); assert(err == SQLITE_OK); err = sqlite3_close(g_db); assert(err == SQLITE_OK); + ERRNO_CHECK(); } + diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 08eefbd12..def6dd1fa 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -127,6 +127,7 @@ ship_type *st_get_or_create(const char * name) { st = (ship_type *)calloc(sizeof(ship_type), 1); st->_name = str_strdup(name); st->storm = 1.0; + st->tac_bonus = 1.0; st_register(st); } return st; diff --git a/src/kernel/ship.h b/src/kernel/ship.h index 2ee1a6d3b..c726b4839 100644 --- a/src/kernel/ship.h +++ b/src/kernel/ship.h @@ -36,6 +36,8 @@ extern "C" { #define SFL_NOCOAST 0x04 #define SFL_SPEEDY 0x08 +#define SFL_DEFAULT 0 + typedef struct ship_type { char *_name; @@ -57,7 +59,7 @@ extern "C" { int at_bonus; /* Ver�ndert den Angriffsskill (default: 0) */ int df_bonus; /* Ver�ndert den Verteidigungskill (default: 0) */ - float tac_bonus; + double tac_bonus; struct terrain_type ** coasts; /* coast that this ship can land on */ diff --git a/src/kernel/ship.test.c b/src/kernel/ship.test.c index aa4dc5755..074876dd5 100644 --- a/src/kernel/ship.test.c +++ b/src/kernel/ship.test.c @@ -369,7 +369,7 @@ static void test_stype_defaults(CuTest *tc) { CuAssertPtrEquals(tc, 0, stype->coasts); CuAssertDblEquals(tc, 0.0, stype->damage, 0.0); CuAssertDblEquals(tc, 1.0, stype->storm, 0.0); - CuAssertDblEquals(tc, 0.0, stype->tac_bonus, 0.0); + CuAssertDblEquals(tc, 1.0, stype->tac_bonus, 0.01); CuAssertIntEquals(tc, 0, stype->cabins); CuAssertIntEquals(tc, 0, stype->cargo); CuAssertIntEquals(tc, 0, stype->combat); diff --git a/src/report.c b/src/report.c index d83fc7eff..74718f7ad 100644 --- a/src/report.c +++ b/src/report.c @@ -96,7 +96,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* libc includes */ #include #include -#include #include #include #include @@ -111,17 +110,6 @@ extern int *storms; extern int weeks_per_month; extern int months_per_year; -static void check_errno(const char * file, int line) { - if (errno) { - char zText[64]; - sprintf(zText, "error %d during report at %s:%d", errno, file, line); - perror(zText); - errno = 0; - } -} - -#define CHECK_ERRNO() check_errno(__FILE__, __LINE__) - static char *gamedate_season(const struct locale *lang) { static char buf[256]; /* FIXME: static return value */ @@ -2195,7 +2183,7 @@ report_plaintext(const char *filename, report_context * ctx, } ch = 0; - CHECK_ERRNO(); + ERRNO_CHECK(); for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem; a = a->next) { const item_type *itype = (const item_type *)a->data.v; @@ -2245,7 +2233,7 @@ report_plaintext(const char *filename, report_context * ctx, } } newline(out); - CHECK_ERRNO(); + ERRNO_CHECK(); centre(out, LOC(f->locale, "nr_alliances"), false); newline(out); @@ -2253,7 +2241,7 @@ report_plaintext(const char *filename, report_context * ctx, rpline(out); - CHECK_ERRNO(); + ERRNO_CHECK(); anyunits = 0; for (r = ctx->first; r != ctx->last; r = r->next) { @@ -2367,7 +2355,7 @@ report_plaintext(const char *filename, report_context * ctx, newline(out); rpline(out); - CHECK_ERRNO(); + ERRNO_CHECK(); } if (!is_monsters(f)) { if (!anyunits) { @@ -2379,7 +2367,7 @@ report_plaintext(const char *filename, report_context * ctx, } } fstream_done(&strm); - CHECK_ERRNO(); + ERRNO_CHECK(); return 0; } diff --git a/src/util/log.c b/src/util/log.c index 51479cb4a..4b29332a8 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -24,6 +24,14 @@ without prior permission by the authors of Eressea. #include #include +void errno_check(const char * file, int line) { + if (errno) { + log_info("errno is %d (%s) at %s:%d", + errno, strerror(errno), file, line); + errno = 0; + } +} + #ifdef STDIO_CP static int stdio_codepage = STDIO_CP; #else diff --git a/src/util/log.h b/src/util/log.h index 06d150751..15872d6dc 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -28,13 +28,17 @@ extern "C" { int log_level(struct log_t *log, int flags); void log_close(void); - extern void log_fatal(const char *format, ...); - extern void log_error(const char *format, ...); - extern void log_warning(const char *format, ...); - extern void log_debug(const char *format, ...); - extern void log_info(const char *format, ...); - extern void log_printf(FILE * ios, const char *format, ...); + void log_fatal(const char *format, ...); + void log_error(const char *format, ...); + void log_warning(const char *format, ...); + void log_debug(const char *format, ...); + void log_info(const char *format, ...); + void log_printf(FILE * ios, const char *format, ...); + void errno_check(const char *file, int line); +#define ERRNO_CHECK() errno_check(__FILE__, __LINE__) + + #define LOG_CPERROR 0x01 #define LOG_CPWARNING 0x02 #define LOG_CPINFO 0x04 diff --git a/src/xmlreader.c b/src/xmlreader.c index eea73e234..6f7447bae 100644 --- a/src/xmlreader.c +++ b/src/xmlreader.c @@ -448,14 +448,19 @@ static int parse_ships(xmlDocPtr doc) for (child = node->children; child; child = child->next) { if (strcmp((const char *)child->name, "modifier") == 0) { - double value = xml_fvalue(child, "value", 0.0); propValue = xmlGetProp(child, BAD_CAST "type"); - if (strcmp((const char *)propValue, "tactics") == 0) - st->tac_bonus = (float)value; - else if (strcmp((const char *)propValue, "attack") == 0) - st->at_bonus = (int)value; - else if (strcmp((const char *)propValue, "defense") == 0) - st->df_bonus = (int)value; + if (strcmp((const char *)propValue, "tactics") == 0) { + st->tac_bonus = xml_fvalue(child, "factor", 1.0); + } + else { + int value = xml_ivalue(child, "value", 0); + if (strcmp((const char *)propValue, "attack") == 0) { + st->at_bonus = (int)value; + } + else if (strcmp((const char *)propValue, "defense") == 0) { + st->df_bonus = (int)value; + } + } xmlFree(propValue); } else if (strcmp((const char *)child->name, "construction") == 0) {