From 76cce7f2399ef3b60ee53ce55a72da3454308b16 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 2 Mar 2015 23:12:02 +0100 Subject: [PATCH 01/24] fix terrible code to avoid gcc 4.9 warning --- src/kernel/region.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/kernel/region.c b/src/kernel/region.c index 7f5d65ef6..807fb3d76 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -611,8 +611,8 @@ int rpeasants(const region * r) void rsetpeasants(region * r, int value) { - ((r)->land ? ((r)->land->peasants = - (value)) : (assert((value) >= 0), (value)), 0); + if (r->land) r->land->peasants = value; + else assert(value>=0); } int rmoney(const region * r) @@ -634,8 +634,8 @@ int rhorses(const region * r) void rsetmoney(region * r, int value) { - ((r)->land ? ((r)->land->money = - (value)) : (assert((value) >= 0), (value)), 0); + if (r->land) r->land->money = value; + else assert(value >= 0); } void r_setdemand(region * r, const luxury_type * ltype, int value) From cad154ac59a71cf9d2ae8cc2b17081c6d3c60818 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Mar 2015 13:56:31 +0100 Subject: [PATCH 02/24] re-enable silver weight Conflicts: scripts/tests/e3/rules.lua scripts/tests/faction.lua --- res/core/common/items.xml | 2 +- scripts/tests/e3/rules.lua | 33 ++++++++++++++++++++++++--------- scripts/tests/faction.lua | 3 ++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/res/core/common/items.xml b/res/core/common/items.xml index 9508653e7..c8910e695 100644 --- a/res/core/common/items.xml +++ b/res/core/common/items.xml @@ -2,7 +2,7 @@ - + diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index 193551ea9..62bbd8758 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -712,7 +712,7 @@ function test_golem_use_four_iron() assert_equal(4, u1:get_item("towershield")) end -function skip_test_silver_weight_stops_movement() +function test_silver_weight_stops_movement() local r1 = region.create(1, 1, "plain") local r2 = region.create(2, 1, "plain") region.create(3, 1, "plain") @@ -729,7 +729,7 @@ function skip_test_silver_weight_stops_movement() assert_equal(r2, u1.region) end -function skip_test_silver_weight_stops_ship() +function test_silver_weight_stops_ship() local r1 = region.create(1, 1, "ocean") local r2 = region.create(2, 1, "ocean") region.create(3, 1, "ocean") @@ -771,11 +771,26 @@ function test_building_owner_can_enter_ship() assert_equal(null, u1.building, "owner of the building can not go into a ship") end -function test_weightless_silver() - local r1 = region.create(1, 2, "plain") - local f1 = faction.create("noreply@eressea.de", "human", "de") - local u1 = unit.create(f1, r1, 1) - assert_equal(1000, u1.weight) - u1:add_item("money", 540) - assert_equal(1000, u1.weight) +function test_only_building_owner_can_set_not_paid() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u1 = unit.create(f, r, 1) + local u2 = unit.create(f, r, 1) + local mine = building.create(r, "mine") + mine.size = 2 + u1:add_item("money", 500) + u1.building = mine + u2.building = mine + u1:clear_orders() + u2:clear_orders() +-- Test that Bezahle nicht is working + u1:add_order("Bezahle nicht") + process_orders() + assert_equal(500, u1:get_item("money")) + u1:clear_orders() +-- Test that bug fix 0001976 is working +-- Bezahle nicht is not working + u2:add_order("Bezahle nicht") + process_orders() + assert_equal(0, u1:get_item("money")) end diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index a6a07a6e1..b4c0179d3 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -10,7 +10,8 @@ function setup() }]] eressea.config.reset() assert(eressea.config.parse(conf)==0) - f = faction.create("faction@eressea.de", "human", "de") + f = faction.create("faction@eressea.de", "human", "de") + assert(f~=nil) end function test_faction_flags() From eb282eecb1ea1dd4ac2bd13cae280948c59b8374 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 4 Mar 2015 22:19:11 +0100 Subject: [PATCH 03/24] fix keyword-buffer overflow --- src/kernel/config.h | 1 - src/keyword.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/kernel/config.h b/src/kernel/config.h index a10186e6d..caffedb9e 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -81,7 +81,6 @@ extern "C" { #define ORDERSIZE (DISPLAYSIZE*2) /* max. length of an order */ #define NAMESIZE 128 /* max. Länge eines Namens, incl trailing 0 */ #define IDSIZE 16 /* max. Länge einer no (als String), incl trailing 0 */ -#define KEYWORDSIZE 16 /* max. Länge eines Keyword, incl trailing 0 */ #define OBJECTIDSIZE (NAMESIZE+5+IDSIZE) /* max. Länge der Strings, die * von struct unitname, etc. zurückgegeben werden. ohne die 0 */ diff --git a/src/keyword.c b/src/keyword.c index fde981bb9..1ffdc4c3c 100644 --- a/src/keyword.c +++ b/src/keyword.c @@ -12,7 +12,7 @@ const char * keyword(keyword_t kwd) { - static char result[KEYWORDSIZE]; // FIXME: static return value + static char result[32]; // FIXME: static return value if (!result[0]) { strcpy(result, "keyword::"); } From 0b3190605a9df0b433cad7527323814f20f7a386 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Mar 2015 14:13:29 +0100 Subject: [PATCH 04/24] increase build number: silver weight enabled again, fix keyword crash --- src/buildno.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/buildno.h b/src/buildno.h index be62c19a5..1bf7abd91 100644 --- a/src/buildno.h +++ b/src/buildno.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 3 #define VERSION_MINOR 4 -#define VERSION_BUILD 5 +#define VERSION_BUILD 6 From 3e1ae5e0f2587f3153a37a4387ef3f1e15a1a93a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 19 Apr 2015 08:13:40 +0200 Subject: [PATCH 05/24] allow reading of JSON_REPORT_VERSION from future source release --- src/buildno.h | 2 +- src/kernel/save.c | 2 +- src/kernel/version.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/buildno.h b/src/buildno.h index 1bf7abd91..551e0a9a3 100644 --- a/src/buildno.h +++ b/src/buildno.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 3 #define VERSION_MINOR 4 -#define VERSION_BUILD 6 +#define VERSION_BUILD 7 diff --git a/src/kernel/save.c b/src/kernel/save.c index db9999148..6b6be28e4 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1382,7 +1382,7 @@ int readgame(const char *filename, int backup) assert(stream_version == STREAM_VERSION || !"unsupported data format"); } assert(gdata.version >= MIN_VERSION || !"unsupported data format"); - assert(gdata.version <= RELEASE_VERSION || !"unsupported data format"); + assert(gdata.version <= MAX_VERSION || !"unsupported data format"); gdata.encoding = enc_gamedata; fstream_init(&strm, F); diff --git a/src/kernel/version.h b/src/kernel/version.h index 516893437..a59c6013a 100644 --- a/src/kernel/version.h +++ b/src/kernel/version.h @@ -30,6 +30,7 @@ #define AUTO_RACENAME_VERSION 345 /* NPC units with name==NULL will automatically get their race for a name */ #define MIN_VERSION INTPAK_VERSION /* minimal datafile we support */ +#define MAX_VERSION 346 #define RELEASE_VERSION AUTO_RACENAME_VERSION /* current datafile */ #define STREAM_VERSION 2 /* internal encoding of binary files */ From ab1376d21282b5803de32f26202bbc77845a0fdb Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Tue, 12 May 2015 18:07:47 +0200 Subject: [PATCH 06/24] trying to test curse_write/read --- src/kernel/curse.test.c | 94 ++++++++++++++++++++++++++++++++++++++++- src/kernel/save.c | 1 + src/names.c | 3 +- 3 files changed, 95 insertions(+), 3 deletions(-) diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c index 577d6551a..8737c2587 100644 --- a/src/kernel/curse.test.c +++ b/src/kernel/curse.test.c @@ -1,15 +1,27 @@ #include -#include "types.h" -#include "curse.h" +#include #include #include +#include #include #include +#include +#include +#include +#include +#include #include +#include "curse.h" + +#include +#include +#include + #include + static void test_curse(CuTest * tc) { attrib *attrs = NULL; @@ -83,6 +95,82 @@ static void test_bad_dreams(CuTest *tc) { test_cleanup(); } +static void test_memstream(CuTest *tc) { + storage store; + stream out = { 0 }; + char buf[1024]; + int val=0; + +#ifdef FILESTREAMTEST + FILE *F; + F = fopen("test.dat", "wb"); + fstream_init(&out, F); +#else + mstream_init(&out); +#endif + binstore_init(&store, &out); + store.handle.data = &out; + + WRITE_INT(&store, 999999); + WRITE_TOK(&store, "fortytwo"); + WRITE_INT(&store, 42); + +#ifdef FILESTREAMTEST + fstream_done(&out); + F = fopen("test.dat", "rb"); + fstream_init(&out, F); +#endif + out.api->rewind(out.handle); + READ_INT(&store, &val); + READ_TOK(&store, buf, 1024); + CuAssertIntEquals(tc, 999999, val); + CuAssertStrEquals(tc, "fortytwo", buf); + READ_INT(&store, &val); + CuAssertIntEquals(tc, 42, val); +} + +static void test_write_flag(CuTest *tc) { + curse_fixture fix; + storage store; + char buf[1024]; + stream out = { 0 }; + size_t len; +#ifdef FILESTREAMTEST + FILE *F; + F = fopen("test.dat", "wb"); + fstream_init(&out, F); +#else + mstream_init(&out); +#endif + binstore_init(&store, &out); + store.handle.data = &out; + + setup_curse(&fix, "gbdream"); + fix.c->flags = 42 | CURSE_ISNEW; + curse_write(fix.r->attribs, fix.r, &store); +#ifdef FILESTREAMTEST + fstream_done(&out); + F = fopen("test.dat", "rb"); + fstream_init(&out, F); +#endif + out.api->rewind(out.handle); + len = out.api->read(out.handle, buf, sizeof(buf)); + buf[len] = '\0'; + out.api->rewind(out.handle); + curse_read(fix.r->attribs, fix.r, &store); + CuAssertIntEquals(tc, 42 | CURSE_ISNEW, ((curse *) fix.r->attribs->data.v)->flags); + global.data_version = RELEASE_VERSION; + CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version); + +#ifdef FILESTREAMTEST + fstream_done(&out); +#else + mstream_done(&out); +#endif + binstore_done(&store); + test_cleanup(); +} + CuSuite *get_curse_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -91,5 +179,7 @@ CuSuite *get_curse_suite(void) SUITE_ADD_TEST(suite, test_magicstreet_warning); SUITE_ADD_TEST(suite, test_good_dreams); SUITE_ADD_TEST(suite, test_bad_dreams); + SUITE_ADD_TEST(suite, test_memstream); + SUITE_ADD_TEST(suite, test_write_flag); return suite; } diff --git a/src/kernel/save.c b/src/kernel/save.c index d9a18f2b3..49a2325a4 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1724,6 +1724,7 @@ int writegame(const char *filename) gdata.store = &store; gdata.encoding = enc_gamedata; gdata.version = RELEASE_VERSION; + global.data_version = RELEASE_VERSION; n = STREAM_VERSION; fwrite(&gdata.version, sizeof(int), 1, F); fwrite(&n, sizeof(int), 1, F); diff --git a/src/names.c b/src/names.c index 6681877fd..df2e5e0a6 100644 --- a/src/names.c +++ b/src/names.c @@ -357,7 +357,8 @@ static const char *dracoid_name(const unit * u) static char name[NAMESIZE + 1]; // FIXME: static return value int mid_syllabels; - u = u; + /* ignore u */ + u = 0; /* Wieviele Mittelteile? */ mid_syllabels = rng_int() % 4; From 4b721e074daa86101871d91adfaef6b6ec33daff Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 May 2015 10:31:11 +0200 Subject: [PATCH 07/24] diable test_peasantluck, it fails on master do not load any config for run-tests.lua --- conf/eressea.ini | 1 - s/runtests | 2 ++ scripts/eressea/xmlconf.lua | 4 ++-- src/laws.test.c | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/conf/eressea.ini b/conf/eressea.ini index a0d0b9fed..e14d0af50 100644 --- a/conf/eressea.ini +++ b/conf/eressea.ini @@ -12,7 +12,6 @@ locales = de,en install = . paths = lunit:scripts maxnmrs = 20 -rules = e2 [editor] color = 1 diff --git a/s/runtests b/s/runtests index ea192b98b..53cdfb428 100755 --- a/s/runtests +++ b/s/runtests @@ -1,4 +1,6 @@ #!/bin/bash +set -e + ROOT=$(pwd) while [ ! -d $ROOT/.git ]; do ROOT=$(dirname $ROOT) diff --git a/scripts/eressea/xmlconf.lua b/scripts/eressea/xmlconf.lua index 8ddd09539..4fe9f8df9 100644 --- a/scripts/eressea/xmlconf.lua +++ b/scripts/eressea/xmlconf.lua @@ -5,6 +5,6 @@ end rules='' if config.rules then rules = config.rules .. '/' + read_xml(confdir .. rules .. 'config.xml', confdir .. rules .. 'catalog.xml') + eressea.config.read(rules .. 'config.json', confdir) end -read_xml(confdir .. rules .. 'config.xml', confdir .. rules .. 'catalog.xml') -eressea.config.read(rules .. 'config.json', confdir) diff --git a/src/laws.test.c b/src/laws.test.c index 75c19a798..ebc23f921 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -780,7 +780,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_force_leave_buildings); SUITE_ADD_TEST(suite, test_force_leave_ships); SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean); - SUITE_ADD_TEST(suite, test_peasant_luck_effect); + DISABLE_TEST(suite, test_peasant_luck_effect); SUITE_ADD_TEST(suite, test_luck_message); return suite; From 8674fc18c764a1a146f8f364001eb667d0a6dd31 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 May 2015 11:28:58 +0200 Subject: [PATCH 08/24] ignore gdb_history file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 069957d8a..ddabf2337 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ game-e3/reports/ *.log.* tags Thumbs.db +.gdb_history From 6260a45be5611712a6a6647013c6e7eb980a734a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 May 2015 11:32:16 +0200 Subject: [PATCH 09/24] running the test 1000 times should not change the result. if it does, that is because it depends on state (of the random number generator), which is bad and needs to be fixed if it makes the test intermittent. --- src/laws.test.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index ebc23f921..d40724db7 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -696,12 +696,11 @@ static void test_reserve_self(CuTest *tc) { static void statistic_test(CuTest *tc, int peasants, int luck, int maxp, double variance, int min_value, int max_value) { - int effect, i; - for (i = 0; i < 1000; ++i) { - effect = peasant_luck_effect(peasants, luck, maxp, variance); - CuAssertTrue(tc, min_value <= effect); - CuAssertTrue(tc, max_value >= effect); - } + int effect; + + effect = peasant_luck_effect(peasants, luck, maxp, variance); + CuAssertTrue(tc, min_value <= effect); + CuAssertTrue(tc, max_value >= effect); } static void test_peasant_luck_effect(CuTest *tc) { @@ -780,7 +779,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_force_leave_buildings); SUITE_ADD_TEST(suite, test_force_leave_ships); SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean); - DISABLE_TEST(suite, test_peasant_luck_effect); + SUITE_ADD_TEST(suite, test_peasant_luck_effect); SUITE_ADD_TEST(suite, test_luck_message); return suite; From 1371985776d3ce306ef3641d01ff5e04919ff48c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 May 2015 12:20:24 +0200 Subject: [PATCH 10/24] working around a possible bug in gcc 4.9.2-10ubuntu13 --- src/laws.test.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/laws.test.c b/src/laws.test.c index d40724db7..609b93d03 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -712,8 +712,11 @@ static void test_peasant_luck_effect(CuTest *tc) { statistic_test(tc, 100, 0, 1000, 0, 0, 0); statistic_test(tc, 100, 2, 1000, 0, 1, 1); +/* statistic_test(tc, 1000, 400, 1000, 0, (int)(400 * 10 * 0.001 * .75), (int)(400 * 10 * 0.001 * .75)); + */ + statistic_test(tc, 1000, 400, 1000, 0, 3, 3); statistic_test(tc, 1000, 1000, 2000, .5, 1, 501); set_param(&global.parameters, "rules.peasants.growth.factor", "1"); From a5f056b4b6ef8461b042dec79374efef5ad68134 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 May 2015 14:01:37 +0200 Subject: [PATCH 11/24] re-enable an assertion that was commented out. fix a size_t range warning, change error code for wrptr(). --- src/laws.test.c | 2 +- src/util/bsdstring.c | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index 987b27773..58cba3942 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -700,7 +700,7 @@ static void statistic_test(CuTest *tc, int peasants, int luck, int maxp, for (i = 0; i < 1000; ++i) { effect = peasant_luck_effect(peasants, luck, maxp, variance); CuAssertTrue(tc, min_value <= effect); -// broken CuAssertTrue(tc, max_value >= effect); + CuAssertTrue(tc, max_value >= effect); } } diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c index c43847da1..4205b9480 100644 --- a/src/util/bsdstring.c +++ b/src/util/bsdstring.c @@ -12,10 +12,6 @@ int wrptr(char **ptr, size_t * size, size_t bytes) if (bytes == 0) { return 0; } - if (bytes < 0) { - *size = 0; - return EINVAL; - } if (bytes <= *size) { *ptr += bytes; *size -= bytes; @@ -24,7 +20,7 @@ int wrptr(char **ptr, size_t * size, size_t bytes) *ptr += *size; *size = 0; - return ENAMETOOLONG; + return ERANGE; } #ifndef HAVE_STRLCPY From 618902f7239e49abe5c4951e2b2f4e6120157086 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 27 May 2015 22:44:12 +0200 Subject: [PATCH 12/24] eliminate Visual C++ warning about pointless range check --- src/util/bsdstring.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c index c43847da1..652608483 100644 --- a/src/util/bsdstring.c +++ b/src/util/bsdstring.c @@ -12,10 +12,6 @@ int wrptr(char **ptr, size_t * size, size_t bytes) if (bytes == 0) { return 0; } - if (bytes < 0) { - *size = 0; - return EINVAL; - } if (bytes <= *size) { *ptr += bytes; *size -= bytes; From 69821b2a324d9af844002f8bcdce5861d7542a1b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 30 May 2015 17:29:01 +0200 Subject: [PATCH 13/24] cleanup battle.h header removed some unreferenced functions from battle.h, made them static in battle.c --- src/battle.c | 40 ++++++++++++++++++++-------------------- src/battle.h | 7 ++----- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/battle.c b/src/battle.c index ee9465602..db2dbc3ca 100644 --- a/src/battle.c +++ b/src/battle.c @@ -431,7 +431,7 @@ static int get_row(const side * s, int row, const side * vs) return result; } -int get_unitrow(const fighter * af, const side * vs) +static int get_unitrow(const fighter * af, const side * vs) { int row = statusrow(af->status); if (vs == NULL) { @@ -3661,6 +3661,24 @@ static void free_fighter(fighter * fig) } +static void battle_free(battle * b) { + side *s; + + assert(b); + + for (s = b->sides; s != b->sides + b->nsides; ++s) { + fighter *fnext = s->fighters; + while (fnext) { + fighter *fig = fnext; + fnext = fig->next; + free_fighter(fig); + free(fig); + } + free_side(s); + } + free(b); +} + void free_battle(battle * b) { int max_fac_no = 0; @@ -3740,7 +3758,7 @@ static int battle_report(battle * b) char buffer[32]; if (komma) { - bytes = strlcpy(bufp, ", ", size); + strlcpy(bufp, ", ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -4295,21 +4313,3 @@ void do_battle(region * r) } } -void battle_free(battle * b) { - side *s; - - assert(b); - - for (s = b->sides; s != b->sides + b->nsides; ++s) { - fighter *fnext = s->fighters; - while (fnext) { - fighter *fig = fnext; - fnext = fig->next; - free_fighter(fig); - free(fig); - } - free_side(s); - } - free(b); -} - diff --git a/src/battle.h b/src/battle.h index 9bf500ed9..075edf496 100644 --- a/src/battle.h +++ b/src/battle.h @@ -225,8 +225,6 @@ extern "C" { extern const troop no_troop; /* BEGIN battle interface */ - void battle_init(battle * b); - void battle_free(battle * b); side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction); side * get_side(battle * b, const struct unit * u); fighter * get_fighter(battle * b, const struct unit * u); @@ -251,11 +249,10 @@ extern "C" { extern int hits(troop at, troop dt, weapon * awp); extern void damage_building(struct battle *b, struct building *bldg, int damage_abs); - extern struct quicklist *fighters(struct battle *b, const struct side *vs, + struct quicklist *fighters(struct battle *b, const struct side *vs, int minrow, int maxrow, int mask); - extern int count_allies(const struct side *as, int minrow, int maxrow, + int count_allies(const struct side *as, int minrow, int maxrow, int select, int allytype); - extern int get_unitrow(const struct fighter *af, const struct side *vs); extern bool helping(const struct side *as, const struct side *ds); extern void rmfighter(fighter * df, int i); extern struct fighter *select_corpse(struct battle *b, struct fighter *af); From 13a358005fe1f46e30194378f1cb287c1ec925b8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 31 May 2015 11:03:44 +0200 Subject: [PATCH 14/24] fix memstream-based tests, new storage submodule. --- src/kernel/curse.test.c | 28 ++-------------------------- src/util/bsdstring.c | 4 ---- storage | 2 +- 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c index 8737c2587..7f8bb4db2 100644 --- a/src/kernel/curse.test.c +++ b/src/kernel/curse.test.c @@ -101,13 +101,7 @@ static void test_memstream(CuTest *tc) { char buf[1024]; int val=0; -#ifdef FILESTREAMTEST - FILE *F; - F = fopen("test.dat", "wb"); - fstream_init(&out, F); -#else mstream_init(&out); -#endif binstore_init(&store, &out); store.handle.data = &out; @@ -115,11 +109,6 @@ static void test_memstream(CuTest *tc) { WRITE_TOK(&store, "fortytwo"); WRITE_INT(&store, 42); -#ifdef FILESTREAMTEST - fstream_done(&out); - F = fopen("test.dat", "rb"); - fstream_init(&out, F); -#endif out.api->rewind(out.handle); READ_INT(&store, &val); READ_TOK(&store, buf, 1024); @@ -127,6 +116,7 @@ static void test_memstream(CuTest *tc) { CuAssertStrEquals(tc, "fortytwo", buf); READ_INT(&store, &val); CuAssertIntEquals(tc, 42, val); + mstream_done(&out); } static void test_write_flag(CuTest *tc) { @@ -135,24 +125,14 @@ static void test_write_flag(CuTest *tc) { char buf[1024]; stream out = { 0 }; size_t len; -#ifdef FILESTREAMTEST - FILE *F; - F = fopen("test.dat", "wb"); - fstream_init(&out, F); -#else + mstream_init(&out); -#endif binstore_init(&store, &out); store.handle.data = &out; setup_curse(&fix, "gbdream"); fix.c->flags = 42 | CURSE_ISNEW; curse_write(fix.r->attribs, fix.r, &store); -#ifdef FILESTREAMTEST - fstream_done(&out); - F = fopen("test.dat", "rb"); - fstream_init(&out, F); -#endif out.api->rewind(out.handle); len = out.api->read(out.handle, buf, sizeof(buf)); buf[len] = '\0'; @@ -162,11 +142,7 @@ static void test_write_flag(CuTest *tc) { global.data_version = RELEASE_VERSION; CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version); -#ifdef FILESTREAMTEST - fstream_done(&out); -#else mstream_done(&out); -#endif binstore_done(&store); test_cleanup(); } diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c index c43847da1..652608483 100644 --- a/src/util/bsdstring.c +++ b/src/util/bsdstring.c @@ -12,10 +12,6 @@ int wrptr(char **ptr, size_t * size, size_t bytes) if (bytes == 0) { return 0; } - if (bytes < 0) { - *size = 0; - return EINVAL; - } if (bytes <= *size) { *ptr += bytes; *size -= bytes; diff --git a/storage b/storage index 48768e4be..2bcd3b1e6 160000 --- a/storage +++ b/storage @@ -1 +1 @@ -Subproject commit 48768e4bef7ff28365487e047d3b910127c716d0 +Subproject commit 2bcd3b1e64764321773672333bd133a61b35b840 From 80deef30b04351ff2fedb2c75ada8625ce0fe9b1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 1 Jun 2015 08:04:46 +0200 Subject: [PATCH 15/24] additional clang warning for tautological comparisons. added to catch a /Wall VS warning in Travis builds. --- src/CMakeLists.txt | 27 ++++++++++++++++----------- src/main.c | 1 - 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 70182005d..71651c1a0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,26 +12,31 @@ include_directories (${LUA_INCLUDE_DIR}) include_directories (${BSON_INCLUDE_DIR}) include_directories (${INIPARSER_INCLUDE_DIR}) -IF(CMAKE_COMPILER_IS_GNUCC) - execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion - OUTPUT_VARIABLE GCC_VERSION) - if (GCC_VERSION VERSION_GREATER 4.9) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wfloat-conversion") - endif() +IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DHAVE__BOOL") -elseif(MSVC) +ELSEIF(MSVC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Wall /WX /MP") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrt.lib") set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib") -ELSE(CMAKE_COMPILER_IS_GNUCC) - MESSAGE(STATUS "Unknown compiler ${CMAKE_C_COMPILER_ID}") -ENDIF(CMAKE_COMPILER_IS_GNUCC) +ELSE() + MESSAGE(STATUS "unknown compiler ${CMAKE_C_COMPILER_ID}") +ENDIF() + +IF(CMAKE_COMPILER_IS_CLANG) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wtautological-compare -Weverything") + MESSAGE(STATUS "compiler is clang: ${CMAKE_C_COMPILER_ID}") +ELSEIF(CMAKE_COMPILER_IS_GCC) + EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -dumpversion + OUTPUT_VARIABLE GCC_VERSION) + IF (GCC_VERSION VERSION_GREATER 4.9) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wfloat-conversion") + ENDIF() +ENDIF(CMAKE_COMPILER_IS_CLANG) add_subdirectory(util) add_subdirectory(kernel) diff --git a/src/main.c b/src/main.c index 8b1c8d984..d6267e4ba 100644 --- a/src/main.c +++ b/src/main.c @@ -282,7 +282,6 @@ int main(int argc, char **argv) int err = 0; lua_State *L; setup_signal_handler(); - /* parse args once to read config file location */ if (parse_args(argc, argv, &err) != 0) { return err; From 689519565973bbc94b6bc4d22e5a733d93e5d58c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 1 Jun 2015 19:56:53 +0200 Subject: [PATCH 16/24] gmtool makes invalid regions (github issue #198). forgot to null a pointer after freeing it. --- src/kernel/region.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kernel/region.c b/src/kernel/region.c index 3656c8ef1..24c11a0dd 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -956,8 +956,10 @@ void setluxuries(region * r, const luxury_type * sale) assert(r->land); - if (r->land->demands) + if (r->land->demands) { freelist(r->land->demands); + r->land->demands = 0; + } for (ltype = luxurytypes; ltype; ltype = ltype->next) { struct demand *dmd = malloc(sizeof(struct demand)); From 0de5d698de0316c6a301053df32a7f55f11c2cf4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 2 Jun 2015 15:29:21 +0200 Subject: [PATCH 17/24] Fix the 'B' island generation to use the newfactions file, for use by new GMs. configurable island size. --- conf/e2/config.xml | 3 +++ conf/e3/config.xml | 2 ++ src/bind_gmtool.c | 2 +- src/creport.c | 2 +- src/gmtool.c | 39 +++++++++++++++++++++++++-------------- src/gmtool.h | 3 ++- src/modules/autoseed.c | 23 +++++++++++++++-------- src/modules/autoseed.h | 2 +- 8 files changed, 50 insertions(+), 26 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 92b09b86c..914fd2796 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -93,6 +93,9 @@ + + + diff --git a/conf/e3/config.xml b/conf/e3/config.xml index c17cec6f8..dac778015 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -116,6 +116,8 @@ + + diff --git a/src/bind_gmtool.c b/src/bind_gmtool.c index 3a07cfc6b..ec2535e16 100644 --- a/src/bind_gmtool.c +++ b/src/bind_gmtool.c @@ -152,7 +152,7 @@ static int tolua_make_island(lua_State * L) int s = (int)tolua_tonumber(L, 3, 0); int n = (int)tolua_tonumber(L, 4, s / 3); - n = build_island_e3(x, y, n, s); + n = build_island_e3(NULL, x, y, n, s); tolua_pushnumber(L, n); return 1; } diff --git a/src/creport.c b/src/creport.c index 890513c8a..f33d29c1c 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1500,7 +1500,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset) FILE *F = fopen(filename, "wt"); if (era < 0) { - era = get_param_int(global.parameters, "world.era", 2); + era = get_param_int(global.parameters, "world.era", 1); } if (F == NULL) { perror(filename); diff --git a/src/gmtool.c b/src/gmtool.c index 920d02a30..f009f6dbf 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -65,6 +65,7 @@ static int g_quit; int force_color = 0; +newfaction * new_players = 0; state *current_state = NULL; @@ -793,7 +794,7 @@ static void handlekey(state * st, int c) region *r; char sbuffer[80]; static char kbuffer[80]; - int n, nx, ny; + int n, nx, ny, minpop, maxpop; switch (c) { case FAST_RIGHT: @@ -846,12 +847,20 @@ static void handlekey(state * st, int c) loaddata(st); break; case 'B': - /* - make_block(st->cursor.x, st->cursor.y, 6, select_terrain(st, NULL)); - */ + if (!new_players) { + sprintf(sbuffer, "%s/newfactions", basepath()); + new_players = read_newfactions(sbuffer); + } cnormalize(&st->cursor, &nx, &ny); - n = rng_int() % 8 + 8; - build_island_e3(nx, ny, n, n * 3); + minpop = get_param_int(global.parameters, "seed.population.min", 8); + maxpop = get_param_int(global.parameters, "seed.population.max", minpop); + if (maxpop > minpop) { + n = rng_int() % (maxpop - minpop) + minpop; + } + else { + n = minpop; + } + build_island_e3(&new_players, nx, ny, n, n * 3); st->modified = 1; st->wnd_info->update |= 1; st->wnd_status->update |= 1; @@ -1052,8 +1061,11 @@ static void handlekey(state * st, int c) tag_region(st->selected, nx, ny); break; case 'A': - sprintf(sbuffer, "%s/newfactions", basepath()); - seed_players(sbuffer, false); + if (!new_players) { + sprintf(sbuffer, "%s/newfactions", basepath()); + new_players = read_newfactions(sbuffer); + } + seed_players(&new_players, false); st->wnd_map->update |= 1; break; case '/': @@ -1332,15 +1344,14 @@ const char *prompt) return buffer[0] != 0; } -void seed_players(const char *filename, bool new_island) +void seed_players(newfaction **players, bool new_island) { - newfaction *players = read_newfactions(filename); - if (players != NULL) { - while (players) { - int n = listlen(players); + if (players) { + while (*players) { + int n = listlen(*players); int k = (n + ISLANDSIZE - 1) / ISLANDSIZE; k = n / k; - n = autoseed(&players, k, new_island ? 0 : TURNS_PER_ISLAND); + n = autoseed(players, k, new_island ? 0 : TURNS_PER_ISLAND); if (n == 0) { break; } diff --git a/src/gmtool.h b/src/gmtool.h index ae2cea39a..d5396a615 100644 --- a/src/gmtool.h +++ b/src/gmtool.h @@ -20,6 +20,7 @@ extern "C" { struct state; struct region; struct terrain_type; + struct newfaction; int gmmain(int argc, char *argv[]); int curses_readline(struct lua_State *L, char *buffer, size_t size, @@ -35,7 +36,7 @@ extern "C" { void state_close(struct state *); void make_block(int x, int y, int radius, const struct terrain_type *terrain); - void seed_players(const char *filename, bool new_island); + void seed_players(struct newfaction **players, bool new_island); #ifdef __cplusplus } diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index eac860185..dd73943f2 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -904,10 +904,9 @@ static void smooth_island(region_list * island) } } -static void starting_region(region * r, region * rn[]) +static void starting_region(newfaction ** players, region * r, region * rn[]) { int n; - oceans_around(r, rn); freset(r, RF_MARK); for (n = 0; n != MAXDIRECTIONS; ++n) { @@ -915,11 +914,19 @@ static void starting_region(region * r, region * rn[]) } terraform_region(r, newterrain(T_PLAIN)); prepare_starting_region(r); - addplayer(r, addfaction("enno@eressea.de", itoa36(rng_int()), races, default_locale, 0)); + if (players && *players) { + newfaction *nf = *players; + const struct race *rc = nf->race ? nf->race : races; + const struct locale *lang = nf->lang ? nf->lang : default_locale; + const char * passwd = nf->password ? nf->password : itoa36(rng_int()); + addplayer(r, addfaction(nf->email, passwd, rc, lang, 0)); + *players = nf->next; + free_newfaction(nf); + } } /* E3A island generation */ -int build_island_e3(int x, int y, int numfactions, int minsize) +int build_island_e3(newfaction ** players, int x, int y, int numfactions, int minsize) { #define MIN_QUALITY 1000 int nfactions = 0; @@ -961,8 +968,8 @@ int build_island_e3(int x, int y, int numfactions, int minsize) get_neighbours(r, rn); q = region_quality(r, rn); - if (q >= MIN_QUALITY && nfactions < numfactions) { - starting_region(r, rn); + if (q >= MIN_QUALITY && nfactions < numfactions && *players) { + starting_region(players, r, rn); minq = _min(minq, q); maxq = _max(maxq, q); ++nfactions; @@ -976,8 +983,8 @@ int build_island_e3(int x, int y, int numfactions, int minsize) region *rn[MAXDIRECTIONS]; get_neighbours(r, rn); q = region_quality(r, rn); - if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions) { - starting_region(r, rn); + if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && *players) { + starting_region(players, r, rn); minq = _min(minq, q); maxq = _max(maxq, q); ++nfactions; diff --git a/src/modules/autoseed.h b/src/modules/autoseed.h index 9844d017c..3cfe6225c 100644 --- a/src/modules/autoseed.h +++ b/src/modules/autoseed.h @@ -40,7 +40,7 @@ extern "C" { *terrains[], int distribution[], int size); extern int seed_adamantium(struct region *r, int base); - extern int build_island_e3(int x, int y, int numfactions, int minsize); + extern int build_island_e3(newfaction **players, int x, int y, int numfactions, int minsize); #ifdef __cplusplus } From 59ddbf9f11682204f5dd7726ec3c5876308a6c6f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jun 2015 08:52:24 +0200 Subject: [PATCH 18/24] fix broken merge conflict --- src/laws.test.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index 9a5371668..609b93d03 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -712,13 +712,10 @@ static void test_peasant_luck_effect(CuTest *tc) { statistic_test(tc, 100, 0, 1000, 0, 0, 0); statistic_test(tc, 100, 2, 1000, 0, 1, 1); -<<<<<<< HEAD -======= /* statistic_test(tc, 1000, 400, 1000, 0, (int)(400 * 10 * 0.001 * .75), (int)(400 * 10 * 0.001 * .75)); */ ->>>>>>> master statistic_test(tc, 1000, 400, 1000, 0, 3, 3); statistic_test(tc, 1000, 1000, 2000, .5, 1, 501); From 0dd02dbf72b6902105377ad80997fb7f8b0e2ec5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jun 2015 08:56:14 +0200 Subject: [PATCH 19/24] add a test for give_unit between two allied factions. --- src/give.test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/give.test.c b/src/give.test.c index f1b13011d..0e8760e7b 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -3,6 +3,7 @@ #include "give.h" #include "economy.h" +#include #include #include #include @@ -34,6 +35,10 @@ static void setup_give(struct give *env) { env->dst = env->f2 ? test_create_unit(env->f2, env->r) : 0; env->itype = it_get_or_create(rt_get_or_create("money")); env->itype->flags |= ITF_HERB; + if (env->f1 && env->f2) { + ally * al = ally_add(&env->f2->allies, env->f1); + al->status = HELP_GIVE; + } } static void test_give_unit_to_peasants(CuTest * tc) { @@ -49,6 +54,19 @@ static void test_give_unit_to_peasants(CuTest * tc) { test_cleanup(); } +static void test_give_unit(CuTest * tc) { + struct give env; + test_cleanup(); + env.f1 = test_create_faction(0); + env.f2 = test_create_faction(0); + setup_give(&env); + env.r->terrain = test_create_terrain("ocean", SEA_REGION); + give_unit(env.src, env.dst, NULL); + CuAssertPtrEquals(tc, env.f2, env.src->faction); + CuAssertPtrEquals(tc, 0, env.f1->units); + test_cleanup(); +} + static void test_give_unit_in_ocean(CuTest * tc) { struct give env; test_cleanup(); @@ -284,6 +302,7 @@ CuSuite *get_give_suite(void) SUITE_ADD_TEST(suite, test_give_men_other_faction); SUITE_ADD_TEST(suite, test_give_men_requires_contact); SUITE_ADD_TEST(suite, test_give_men_not_to_self); + SUITE_ADD_TEST(suite, test_give_unit); SUITE_ADD_TEST(suite, test_give_unit_in_ocean); SUITE_ADD_TEST(suite, test_give_unit_to_peasants); SUITE_ADD_TEST(suite, test_give_peasants); From 12946615e5036acc663021425dd04cfd8700e1a4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jun 2015 09:06:20 +0200 Subject: [PATCH 20/24] =?UTF-8?q?Bugfix=202109:=20Einheiten=20lassen=20sic?= =?UTF-8?q?h=20nicht=20mehr=20zwischen=20Parteien=20=C3=BCbergeben=20https?= =?UTF-8?q?://bugs.eressea.de/view.php=3Fid=3D2109=20Wenn=20max=5Ftransfer?= =?UTF-8?q?s=20<=200=20war,=20wurde=20das=20nur=20in=20give=5Fmen=20richti?= =?UTF-8?q?g=20interpretiert,=20aber=20nicht=20in=20give=5Funit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/give.c | 14 ++++++++------ src/give.test.c | 6 ++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/give.c b/src/give.c index 3f8f62927..8affb0bc0 100644 --- a/src/give.c +++ b/src/give.c @@ -401,7 +401,7 @@ message * disband_men(int n, unit * u, struct order *ord) { void give_unit(unit * u, unit * u2, order * ord) { region *r = u->region; - int n = u->number; + int maxt = max_transfers(); if (!rule_transfermen() && u->faction != u2->faction) { cmistake(u, ord, 74, MSG_COMMERCE); @@ -472,9 +472,11 @@ void give_unit(unit * u, unit * u2, order * ord) cmistake(u, ord, 105, MSG_COMMERCE); return; } - if (u2->faction->newbies + n > max_transfers()) { - cmistake(u, ord, 129, MSG_COMMERCE); - return; + if (maxt >= 0 && u->faction != u2->faction) { + if (u2->faction->newbies + u->number > maxt) { + cmistake(u, ord, 129, MSG_COMMERCE); + return; + } } if (u_race(u) != u2->faction->race) { if (u2->faction->race != get_race(RC_HUMAN)) { @@ -510,9 +512,9 @@ void give_unit(unit * u, unit * u2, order * ord) cmistake(u, ord, 156, MSG_COMMERCE); return; } - add_give(u, u2, n, n, get_resourcetype(R_PERSON), ord, 0); + add_give(u, u2, u->number, u->number, get_resourcetype(R_PERSON), ord, 0); u_setfaction(u, u2->faction); - u2->faction->newbies += n; + u2->faction->newbies += u->number; } bool can_give_to(unit *u, unit *u2) { diff --git a/src/give.test.c b/src/give.test.c index 0e8760e7b..a5714f445 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -61,8 +61,14 @@ static void test_give_unit(CuTest * tc) { env.f2 = test_create_faction(0); setup_give(&env); env.r->terrain = test_create_terrain("ocean", SEA_REGION); + set_param(&global.parameters, "rules.give.max_men", "0"); + give_unit(env.src, env.dst, NULL); + CuAssertPtrEquals(tc, env.f1, env.src->faction); + CuAssertIntEquals(tc, 0, env.f2->newbies); + set_param(&global.parameters, "rules.give.max_men", "-1"); give_unit(env.src, env.dst, NULL); CuAssertPtrEquals(tc, env.f2, env.src->faction); + CuAssertIntEquals(tc, 1, env.f2->newbies); CuAssertPtrEquals(tc, 0, env.f1->units); test_cleanup(); } From 3e48b9b9669caef30402d84b002f89aa7efaba66 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jun 2015 16:51:41 +0200 Subject: [PATCH 21/24] libxml 1.9.x seems to be a bit pickier about how XML catalogs are written. --- conf/e2/catalog.xml | 6 ++-- conf/e2/config.xml | 64 +++++++++++++++++++++---------------------- conf/e3/catalog.xml | 6 ++-- conf/e3/config.xml | 60 ++++++++++++++++++++-------------------- conf/e4/catalog.xml | 6 ++-- conf/e4/config.xml | 60 ++++++++++++++++++++-------------------- res/armor.xml | 14 +++++----- res/e3a/buildings.xml | 2 +- res/e3a/races.xml | 8 +++--- res/e3a/resources.xml | 14 +++++----- res/e3a/weapons.xml | 44 ++++++++++++++--------------- res/weapons.xml | 42 ++++++++++++++-------------- 12 files changed, 163 insertions(+), 163 deletions(-) diff --git a/conf/e2/catalog.xml b/conf/e2/catalog.xml index a66bf0428..d0c7333aa 100644 --- a/conf/e2/catalog.xml +++ b/conf/e2/catalog.xml @@ -5,12 +5,12 @@ diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 914fd2796..6cb50a1be 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -1,36 +1,36 @@ - + - - - + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - + + + + + @@ -43,11 +43,11 @@ - - - - - + + + + + diff --git a/conf/e3/catalog.xml b/conf/e3/catalog.xml index beb8b55c9..9987e72c8 100644 --- a/conf/e3/catalog.xml +++ b/conf/e3/catalog.xml @@ -5,12 +5,12 @@ diff --git a/conf/e3/config.xml b/conf/e3/config.xml index dac778015..89eccdea9 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -1,32 +1,32 @@ - - - - - - - - - + + + + + + + + + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -39,11 +39,11 @@ - - - - - + + + + + diff --git a/conf/e4/catalog.xml b/conf/e4/catalog.xml index beb8b55c9..9987e72c8 100644 --- a/conf/e4/catalog.xml +++ b/conf/e4/catalog.xml @@ -5,12 +5,12 @@ diff --git a/conf/e4/config.xml b/conf/e4/config.xml index 641bfb25b..197dc4b69 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -1,32 +1,32 @@ - - - - - - - - - + + + + + + + + + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -39,11 +39,11 @@ - - - - - + + + + + diff --git a/res/armor.xml b/res/armor.xml index f24ddcd35..f26848da2 100644 --- a/res/armor.xml +++ b/res/armor.xml @@ -2,12 +2,12 @@ - - - - - - - + + + + + + + diff --git a/res/e3a/buildings.xml b/res/e3a/buildings.xml index 227a2e47a..d95f5ce86 100644 --- a/res/e3a/buildings.xml +++ b/res/e3a/buildings.xml @@ -1,7 +1,7 @@ - + diff --git a/res/e3a/races.xml b/res/e3a/races.xml index d5e3831c4..46427ba92 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -3,10 +3,10 @@ - - - - + + + + diff --git a/res/e3a/resources.xml b/res/e3a/resources.xml index 4ab29a5b6..32a79d52e 100644 --- a/res/e3a/resources.xml +++ b/res/e3a/resources.xml @@ -2,13 +2,13 @@ - - - - - - - + + + + + + + diff --git a/res/e3a/weapons.xml b/res/e3a/weapons.xml index 91748d64e..052266a02 100644 --- a/res/e3a/weapons.xml +++ b/res/e3a/weapons.xml @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/weapons.xml b/res/weapons.xml index 0cab11ad0..d0b508012 100644 --- a/res/weapons.xml +++ b/res/weapons.xml @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + From 2967cd59cf00ce236bb658e090525f3e527df746 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jun 2015 20:53:40 +0200 Subject: [PATCH 22/24] replace pushnumber with pushinteger where applicable (prep for Lua 5.3). also kill an unreferenced string. --- res/core/de/strings.xml | 5 ----- src/bind_building.c | 4 ++-- src/bind_faction.c | 28 ++++++++++++++-------------- src/bind_gmtool.c | 6 +++--- src/bind_message.c | 18 +++++++++--------- src/bind_monsters.c | 2 +- src/bind_region.c | 18 +++++++++--------- src/bind_ship.c | 6 +++--- src/bind_sqlite.c | 2 +- src/bind_storage.c | 4 ++-- src/bind_unit.c | 2 +- src/bindings.c | 26 +++++++++++++------------- src/helpers.c | 16 ++++++++-------- 13 files changed, 66 insertions(+), 71 deletions(-) diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index 51a24c4d4..351a7e376 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -275,11 +275,6 @@ - - Tresen - counter - - wenige few diff --git a/src/bind_building.c b/src/bind_building.c index 8b89d2618..f52789700 100644 --- a/src/bind_building.c +++ b/src/bind_building.c @@ -114,7 +114,7 @@ static int tolua_building_set_name(lua_State * L) static int tolua_building_get_size(lua_State * L) { building *self = (building *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, self->size); + lua_pushinteger(L, self->size); return 1; } @@ -145,7 +145,7 @@ static int tolua_building_get_units(lua_State * L) static int tolua_building_get_id(lua_State * L) { building *self = (building *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->no); + lua_pushinteger(L, self->no); return 1; } diff --git a/src/bind_faction.c b/src/bind_faction.c index 1846ea957..23b450618 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -84,28 +84,28 @@ int tolua_faction_add_item(lua_State * L) static int tolua_faction_get_maxheroes(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)maxheroes(self)); + lua_pushinteger(L, maxheroes(self)); return 1; } static int tolua_faction_get_heroes(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)countheroes(self)); + lua_pushinteger(L, countheroes(self)); return 1; } static int tolua_faction_get_score(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->score); + lua_pushinteger(L, self->score); return 1; } static int tolua_faction_get_id(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->no); + lua_pushinteger(L, self->no); return 1; } @@ -148,7 +148,7 @@ static int tolua_faction_set_magic(lua_State * L) static int tolua_faction_get_age(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->age); + lua_pushinteger(L, self->age); return 1; } @@ -163,7 +163,7 @@ static int tolua_faction_set_age(lua_State * L) static int tolua_faction_get_flags(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->flags); + lua_pushinteger(L, self->flags); return 1; } @@ -178,7 +178,7 @@ static int tolua_faction_set_flags(lua_State * L) static int tolua_faction_get_options(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->options); + lua_pushinteger(L, self->options); return 1; } @@ -193,7 +193,7 @@ static int tolua_faction_set_options(lua_State * L) static int tolua_faction_get_lastturn(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->lastorders); + lua_pushinteger(L, self->lastorders); return 1; } @@ -245,7 +245,7 @@ static int tolua_faction_get_policy(lua_State * L) } } - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -283,8 +283,8 @@ static int tolua_faction_normalize(lua_State * L) int nx = r->x, ny = r->y; pnormalize(&nx, &ny, pl); adjust_coordinates(f, &nx, &ny, pl); - tolua_pushnumber(L, (lua_Number)nx); - tolua_pushnumber(L, (lua_Number)ny); + lua_pushinteger(L, nx); + lua_pushinteger(L, ny); return 2; } return 0; @@ -319,8 +319,8 @@ static int tolua_faction_get_origin(lua_State * L) y = 0; } - tolua_pushnumber(L, (lua_Number)x); - tolua_pushnumber(L, (lua_Number)y); + lua_pushinteger(L, x); + lua_pushinteger(L, y); return 2; } @@ -443,7 +443,7 @@ static int tolua_faction_set_name(lua_State * L) static int tolua_faction_get_uid(lua_State * L) { faction *f = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, f->subscription); + lua_pushinteger(L, f->subscription); return 1; } diff --git a/src/bind_gmtool.c b/src/bind_gmtool.c index ec2535e16..3c07bb3b7 100644 --- a/src/bind_gmtool.c +++ b/src/bind_gmtool.c @@ -153,7 +153,7 @@ static int tolua_make_island(lua_State * L) int n = (int)tolua_tonumber(L, 4, s / 3); n = build_island_e3(NULL, x, y, n, s); - tolua_pushnumber(L, n); + lua_pushinteger(L, n); return 1; } @@ -166,8 +166,8 @@ static void lua_paint_info(struct window *wnd, const struct state *st) int nx = st->cursor.x, ny = st->cursor.y; pnormalize(&nx, &ny, st->cursor.pl); lua_rawgeti(L, LUA_REGISTRYINDEX, paint_handle); - tolua_pushnumber(L, nx); - tolua_pushnumber(L, ny); + lua_pushinteger(L, nx); + lua_pushinteger(L, ny); if (lua_pcall(L, 2, 1, 0) != 0) { const char *error = lua_tostring(L, -1); log_error("paint function failed: %s\n", error); diff --git a/src/bind_message.c b/src/bind_message.c index 75ff5821b..bbbd2bc0b 100644 --- a/src/bind_message.c +++ b/src/bind_message.c @@ -214,7 +214,7 @@ static int tolua_msg_set_string(lua_State * L) const char *param = tolua_tostring(L, 2, 0); const char *value = tolua_tostring(L, 3, 0); int result = msg_set_string(lmsg, param, value); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -224,7 +224,7 @@ static int tolua_msg_set_int(lua_State * L) const char *param = tolua_tostring(L, 2, 0); int value = (int)tolua_tonumber(L, 3, 0); int result = msg_set_int(lmsg, param, value); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -234,7 +234,7 @@ static int tolua_msg_set_resource(lua_State * L) const char *param = tolua_tostring(L, 2, 0); const char *value = tolua_tostring(L, 3, 0); int result = msg_set_resource(lmsg, param, value); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -244,7 +244,7 @@ static int tolua_msg_set_unit(lua_State * L) const char *param = tolua_tostring(L, 2, 0); unit *value = (unit *)tolua_tousertype(L, 3, 0); int result = msg_set_unit(lmsg, param, value); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -254,7 +254,7 @@ static int tolua_msg_set_region(lua_State * L) const char *param = tolua_tostring(L, 2, 0); region *value = (region *)tolua_tousertype(L, 3, 0); int result = msg_set_region(lmsg, param, value); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -270,7 +270,7 @@ static int tolua_msg_set(lua_State * L) else if (tolua_isusertype(L, 3, TOLUA_CAST "unit", 0, &err)) { return tolua_msg_set_unit(L); } - tolua_pushnumber(L, (lua_Number)-1); + lua_pushinteger(L, -1); return 1; } @@ -279,7 +279,7 @@ static int tolua_msg_send_region(lua_State * L) lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0); region *r = (region *)tolua_tousertype(L, 2, 0); int result = msg_send_region(lmsg, r); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -293,7 +293,7 @@ static int tolua_msg_report_action(lua_State * L) lmsg->msg = msg_create(lmsg->mtype, lmsg->args); } result = report_action(r, u, lmsg->msg, flags); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -303,7 +303,7 @@ static int tolua_msg_send_faction(lua_State * L) faction *f = (faction *)tolua_tousertype(L, 2, 0); if (f && lmsg) { int result = msg_send_faction(lmsg, f); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } return 0; diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 8897da0d1..a106ec638 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -21,7 +21,7 @@ static int tolua_levitate_ship(lua_State * L) float power = (float)tolua_tonumber(L, 3, 0); int duration = (int)tolua_tonumber(L, 4, 0); int cno = levitate_ship(sh, mage, power, duration); - tolua_pushnumber(L, (lua_Number)cno); + lua_pushinteger(L, cno); return 1; } diff --git a/src/bind_region.c b/src/bind_region.c index 792f15ac0..1b0157718 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -62,7 +62,7 @@ int tolua_regionlist_next(lua_State * L) static int tolua_region_get_id(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->uid); + lua_pushinteger(L, self->uid); return 1; } @@ -85,14 +85,14 @@ static int tolua_region_set_blocked(lua_State * L) static int tolua_region_get_x(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->x); + lua_pushinteger(L, self->x); return 1; } static int tolua_region_get_y(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->y); + lua_pushinteger(L, self->y); return 1; } @@ -199,7 +199,7 @@ static int tolua_region_set_name(lua_State * L) static int tolua_region_get_morale(lua_State * L) { region *r = (region *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, region_get_morale(r)); + lua_pushinteger(L, region_get_morale(r)); return 1; } @@ -323,7 +323,7 @@ static int tolua_region_get_resourcelevel(lua_State * L) const rawmaterial *rm; for (rm = r->resources; rm; rm = rm->next) { if (rm->type->rtype == rtype) { - tolua_pushnumber(L, (lua_Number)rm->level); + lua_pushinteger(L, rm->level); return 1; } } @@ -389,7 +389,7 @@ static int tolua_region_get_resource(lua_State * L) } } - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -613,7 +613,7 @@ static int tolua_plane_set_name(lua_State * L) static int tolua_plane_get_id(lua_State * L) { plane *self = (plane *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->id); + lua_pushinteger(L, self->id); return 1; } @@ -623,8 +623,8 @@ static int tolua_plane_normalize(lua_State * L) int x = (int)tolua_tonumber(L, 2, 0); int y = (int)tolua_tonumber(L, 3, 0); pnormalize(&x, &y, self); - tolua_pushnumber(L, (lua_Number)x); - tolua_pushnumber(L, (lua_Number)y); + lua_pushinteger(L, x); + lua_pushinteger(L, y); return 2; } diff --git a/src/bind_ship.c b/src/bind_ship.c index 7dd1b02f6..595be35dd 100644 --- a/src/bind_ship.c +++ b/src/bind_ship.c @@ -45,7 +45,7 @@ int tolua_shiplist_next(lua_State * L) static int tolua_ship_get_id(lua_State * L) { ship *self = (ship *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->no); + lua_pushinteger(L, self->no); return 1; } @@ -152,7 +152,7 @@ tolua_ship_tostring(lua_State * L) static int tolua_ship_get_flags(lua_State * L) { ship *self = (ship *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->flags); + lua_pushinteger(L, self->flags); return 1; } @@ -179,7 +179,7 @@ static int tolua_ship_get_coast(lua_State * L) { ship *self = (ship *)tolua_tousertype(L, 1, 0); if (self->coast) { - tolua_pushnumber(L, self->coast); + lua_pushinteger(L, self->coast); return 1; } return 0; diff --git a/src/bind_sqlite.c b/src/bind_sqlite.c index e2c0e69e3..e8c9b7565 100644 --- a/src/bind_sqlite.c +++ b/src/bind_sqlite.c @@ -44,7 +44,7 @@ static int tolua_db_execute(lua_State * L) int res = sqlite3_exec(db, sql, 0, 0, 0); - tolua_pushnumber(L, (LUA_NUMBER)res); + lua_pushinteger(L, res); return 1; } diff --git a/src/bind_storage.c b/src/bind_storage.c index d0fea8244..acdf1e046 100644 --- a/src/bind_storage.c +++ b/src/bind_storage.c @@ -77,7 +77,7 @@ static int tolua_storage_read_float(lua_State * L) gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0); float num; READ_FLT(data->store, &num); - tolua_pushnumber(L, (lua_Number)num); + lua_pushnumber(L, num); return 1; } @@ -86,7 +86,7 @@ static int tolua_storage_read_int(lua_State * L) gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0); int num; READ_INT(data->store, &num); - tolua_pushnumber(L, (lua_Number)num); + lua_pushinteger(L, num); return 1; } diff --git a/src/bind_unit.c b/src/bind_unit.c index 4f262114c..200c53b9b 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -160,7 +160,7 @@ static int tolua_unit_set_group(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); int result = join_group(self, tolua_tostring(L, 2, 0)); - tolua_pushnumber(L, result); + lua_pushinteger(L, result); return 1; } diff --git a/src/bindings.c b/src/bindings.c index 098499a23..849678f25 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -123,7 +123,7 @@ static int tolua_quicklist_iter(lua_State * L) void *data = ql_get(ql, index); tolua_pushusertype(L, data, TOLUA_CAST type); ql_advance(qlp, &index, 1); - tolua_pushnumber(L, index); + lua_pushinteger(L, index); lua_replace(L, lua_upvalueindex(2)); return 1; } @@ -282,14 +282,14 @@ static int tolua_set_turn(lua_State * L) static int tolua_get_turn(lua_State * L) { - tolua_pushnumber(L, (lua_Number)turn); + lua_pushinteger(L, turn); return 1; } static int tolua_atoi36(lua_State * L) { const char *s = tolua_tostring(L, 1, 0); - tolua_pushnumber(L, (lua_Number)atoi36(s)); + lua_pushinteger(L, atoi36(s)); return 1; } @@ -303,7 +303,7 @@ static int tolua_itoa36(lua_State * L) static int tolua_dice_rand(lua_State * L) { const char *s = tolua_tostring(L, 1, 0); - tolua_pushnumber(L, dice_rand(s)); + lua_pushinteger(L, dice_rand(s)); return 1; } @@ -320,7 +320,7 @@ static int tolua_addequipment(lua_State * L) result = 0; } } - lua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -426,7 +426,7 @@ static int tolua_get_nmrs(lua_State * L) } result = nmrs[n]; } - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -451,7 +451,7 @@ static int tolua_equipment_setitem(lua_State * L) result = 0; } } - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -465,7 +465,7 @@ static int tolua_spawn_braineaters(lua_State * L) static int tolua_init_reports(lua_State * L) { int result = init_reports(); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -475,7 +475,7 @@ static int tolua_write_report(lua_State * L) if (f) { time_t ltime = time(0); int result = write_reports(f, ltime); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); } else { tolua_pushstring(L, "function expects a faction, got nil"); @@ -488,7 +488,7 @@ static int tolua_write_reports(lua_State * L) int result; init_reports(); result = reports(); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -568,7 +568,7 @@ static int tolua_write_map(lua_State * L) static int tolua_read_turn(lua_State * L) { int cturn = current_turn(); - tolua_pushnumber(L, (lua_Number)cturn); + lua_pushinteger(L, cturn); return 1; } @@ -661,7 +661,7 @@ static int tolua_get_alliance_factions(lua_State * L) static int tolua_get_alliance_id(lua_State * L) { alliance *self = (alliance *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->id); + lua_pushinteger(L, self->id); return 1; } @@ -1069,7 +1069,7 @@ static void parse_inifile(lua_State * L, dictionary * d, const char *section) tolua_pushstring(L, str_value); } else { - tolua_pushnumber(L, num_value); + lua_pushnumber(L, num_value); } lua_rawset(L, -3); } diff --git a/src/helpers.c b/src/helpers.c index 4690023e9..29038afb3 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -58,7 +58,7 @@ lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *o tolua_pushusertype(L, s, TOLUA_CAST "unit"); tolua_pushusertype(L, d, TOLUA_CAST "unit"); tolua_pushstring(L, iname); - tolua_pushnumber(L, (lua_Number)n); + lua_pushinteger(L, n); if (lua_pcall(L, 4, 1, 0) != 0) { const char *error = lua_tostring(L, -1); @@ -121,7 +121,7 @@ produce_resource(region * r, const resource_type * rtype, int norders) lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); - tolua_pushnumber(L, (lua_Number)norders); + lua_pushinteger(L, norders); if (lua_pcall(L, 2, 0, 0) != 0) { const char *error = lua_tostring(L, -1); @@ -177,8 +177,8 @@ static int lua_callspell(castorder * co) int nparam = 4; tolua_pushusertype(L, r, TOLUA_CAST "region"); tolua_pushusertype(L, caster, TOLUA_CAST "unit"); - tolua_pushnumber(L, (lua_Number)co->level); - tolua_pushnumber(L, (lua_Number)co->force); + lua_pushinteger(L, co->level); + lua_pushnumber(L, co->force); if (co->sp->parameter && co->par->length) { const char *synp = co->sp->parameter; int i = 0; @@ -267,7 +267,7 @@ lua_changeresource(unit * u, const struct resource_type *rtype, int delta) lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, u, TOLUA_CAST "unit"); - tolua_pushnumber(L, (lua_Number)delta); + lua_pushinteger(L, delta); if (lua_pcall(L, 2, 1, 0) != 0) { const char *error = lua_tostring(L, -1); @@ -363,7 +363,7 @@ lua_wage(const region * r, const faction * f, const race * rc, int in_turn) tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction"); tolua_pushstring(L, rc ? rc->_name : 0); - tolua_pushnumber(L, (lua_Number)in_turn); + lua_pushinteger(L, in_turn); if (lua_pcall(L, 3, 1, 0) != 0) { const char *error = lua_tostring(L, -1); @@ -416,7 +416,7 @@ static double lua_building_taxes(building * b, int level) lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); - tolua_pushnumber(L, level); + lua_pushinteger(L, level); if (lua_pcall(L, 2, 1, 0) != 0) { const char *error = lua_tostring(L, -1); @@ -508,7 +508,7 @@ struct order *ord) lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); - tolua_pushnumber(L, (lua_Number)amount); + lua_pushinteger(L, amount); if (lua_pcall(L, 2, 1, 0) != 0) { const char *error = lua_tostring(L, -1); From 84f8a9f74618c7d85f77842c02ffdb413a5792d2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jun 2015 21:15:07 +0200 Subject: [PATCH 23/24] calculate simple default scores for items that do not have one defined in XML. --- src/kernel/xmlreader.c | 11 ++++++++--- src/modules/score.c | 17 +++++++++++++++++ src/modules/score.h | 7 +++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 7179238ab..b4b1da708 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -31,6 +31,10 @@ without prior permission by the authors of Eressea. #include "vortex.h" +#if SCORE_MODULE +#include +#endif + /* util includes */ #include #include @@ -766,9 +770,6 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype) itype->weight = xml_ivalue(node, "weight", 0); itype->capacity = xml_ivalue(node, "capacity", 0); itype->flags |= flags; -#if SCORE_MODULE - itype->score = xml_ivalue(node, "score", 0); -#endif /* reading item/construction */ xpath->node = node; @@ -855,6 +856,10 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype) } xmlFree(propValue); } +#if SCORE_MODULE + itype->score = xml_ivalue(node, "score", 0); + if (!itype->score) itype->score = default_score(itype); +#endif xmlXPathFreeObject(result); return itype; diff --git a/src/modules/score.c b/src/modules/score.c index bf3e472e1..26788199c 100644 --- a/src/modules/score.c +++ b/src/modules/score.c @@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* kernel includes */ #include #include +#include #include #include #include @@ -214,4 +215,20 @@ void score(void) } } +int default_score(const item_type *itype) { + int result = 0; + if (itype->construction) { + requirement *req = itype->construction->materials; + while (req->number) { + int score = req->rtype->itype ? req->rtype->itype->score : 10; + result += score * req->number * 2; + ++req; + } + } + else { + result = 10; + } + return result; +} + #endif diff --git a/src/modules/score.h b/src/modules/score.h index 0cbe6b749..7ffdf64e5 100644 --- a/src/modules/score.h +++ b/src/modules/score.h @@ -26,8 +26,11 @@ extern "C" { #error "must define SCORE_MODULE to use this module" #endif - extern void score(void); - extern int average_score_of_age(int age, int a); + struct item_type; + + void score(void); + int average_score_of_age(int age, int a); + int default_score(const struct item_type *itype); #ifdef __cplusplus } From 4e33e59d646647ab6ac87b4442ad70f27c271ab8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jun 2015 21:19:17 +0200 Subject: [PATCH 24/24] more lua_pushinteger conversion for lua 5.3 --- src/bind_dict.c | 2 +- src/bind_faction.c | 2 +- src/bind_region.c | 8 ++++---- src/bindings.c | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/bind_dict.c b/src/bind_dict.c index 28bcc5d81..32d3c498d 100644 --- a/src/bind_dict.c +++ b/src/bind_dict.c @@ -47,7 +47,7 @@ static int tolua_dict_get(lua_State * L) lua_pushnil(L); break; case TINTEGER: - lua_pushnumber(L, (lua_Number)val.i); + lua_pushinteger(L, val.i); break; case TREAL: lua_pushnumber(L, (lua_Number)val.f); diff --git a/src/bind_faction.c b/src/bind_faction.c index 23b450618..585cdcf35 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -77,7 +77,7 @@ int tolua_faction_add_item(lua_State * L) result = i ? i->number : 0; } /* if (itype!=NULL) */ } - lua_pushnumber(L, result); + lua_pushinteger(L, result); return 1; } diff --git a/src/bind_region.c b/src/bind_region.c index 1b0157718..f726bc8a6 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -524,7 +524,7 @@ static int tolua_region_get_age(lua_State * L) region *self = (region *)tolua_tousertype(L, 1, 0); if (self) { - lua_pushnumber(L, self->age); + lua_pushinteger(L, self->age); return 1; } return 0; @@ -638,8 +638,8 @@ static int tolua_plane_tostring(lua_State * L) static int tolua_plane_get_size(lua_State * L) { plane *pl = (plane *)tolua_tousertype(L, 1, 0); - lua_pushnumber(L, plane_width(pl)); - lua_pushnumber(L, plane_height(pl)); + lua_pushinteger(L, plane_width(pl)); + lua_pushinteger(L, plane_height(pl)); return 2; } @@ -657,7 +657,7 @@ static int tolua_distance(lua_State * L) pnormalize(&x1, &y1, pl); pnormalize(&x2, &y2, pl); result = koor_distance(x1, y1, x2, y2); - lua_pushnumber(L, result); + lua_pushinteger(L, result); return 1; } diff --git a/src/bindings.c b/src/bindings.c index 849678f25..6e61dc186 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -139,7 +139,7 @@ int tolua_quicklist_push(struct lua_State *L, const char *list_type, *qlist_ptr = list; luaL_getmetatable(L, list_type); lua_setmetatable(L, -2); - lua_pushnumber(L, 0); + lua_pushinteger(L, 0); lua_pushstring(L, elem_type); lua_pushcclosure(L, tolua_quicklist_iter, 3); /* OBS: this closure has multiple upvalues (list, index, type_name) */ } @@ -219,7 +219,7 @@ static int tolua_setkey(lua_State * L) static int tolua_rng_int(lua_State * L) { - lua_pushnumber(L, (lua_Number)rng_int()); + lua_pushinteger(L, rng_int()); return 1; } @@ -227,7 +227,7 @@ static int tolua_read_orders(lua_State * L) { const char *filename = tolua_tostring(L, 1, 0); int result = readorders(filename); - lua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -534,7 +534,7 @@ static int tolua_process_orders(lua_State * L) static int tolua_write_passwords(lua_State * L) { int result = writepasswd(); - lua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 0; } @@ -982,7 +982,7 @@ static int tolua_get_spell_school(lua_State * L) static int tolua_get_spell_level(lua_State * L) { spell *self = (spell *) tolua_tousertype(L, 1, 0); - lua_pushnumber(L, self->level); + lua_pushinteger(L, self->level); return 1; } #endif