From 00ca4126340d22407761cb407dd9da7f1a1057a3 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Sat, 11 Jun 2016 16:50:55 +0200 Subject: [PATCH 1/7] show item and race if possible --- src/laws.c | 10 ++++++---- src/laws.test.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/laws.c b/src/laws.c index 203970dc4..9cd0a6f27 100755 --- a/src/laws.c +++ b/src/laws.c @@ -2390,6 +2390,7 @@ static void display_race(unit * u, const race * rc) static void reshow_other(unit * u, struct order *ord, const char *s) { int err = 21; + bool found = false; if (s) { const spell *sp = 0; @@ -2426,7 +2427,7 @@ static void reshow_other(unit * u, struct order *ord, const char *s) { else { display_item(u, itype); } - return; + found = true; } if (sp) { @@ -2437,15 +2438,16 @@ static void reshow_other(unit * u, struct order *ord, const char *s) { if (a != NULL) { a_remove(&u->faction->attribs, a); } - return; + found = true; } if (rc && u_race(u) == rc) { display_race(u, rc); - return; + found = true; } } - cmistake(u, ord, err, MSG_EVENT); + if (!found) + cmistake(u, ord, err, MSG_EVENT); } static void reshow(unit * u, struct order *ord, const char *s, param_t p) diff --git a/src/laws.test.c b/src/laws.test.c index 623717619..aeee60ad7 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1329,6 +1329,48 @@ static void test_show_race(CuTest *tc) { test_cleanup(); } +static void test_show_both(CuTest *tc) { + order *ord; + race * rc; + unit *u; + struct locale *loc; + message * msg; + + test_cleanup(); + + mt_register(mt_new_va("msg_event", "string:string", 0)); + mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", 0)); + rc = test_create_race("elf"); + test_create_itemtype("elvenhorse"); + + loc = get_or_create_locale("de"); + locale_setstring(loc, "elvenhorse", "Elfenpferd"); + locale_setstring(loc, "elvenhorse_p", "Elfenpferde"); + locale_setstring(loc, "iteminfo::elvenhorse", "Hiyaa!"); + locale_setstring(loc, "race::elf_p", "Elfen"); + locale_setstring(loc, "race::elf", "Elf"); + init_locale(loc); + + CuAssertPtrNotNull(tc, finditemtype("elf", loc)); + CuAssertPtrNotNull(tc, findrace("elf", loc)); + + u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); + u->faction->locale = loc; + i_change(&u->items, finditemtype("elfenpferd", loc), 1); + ord = create_order(K_RESHOW, loc, "Elf"); + reshow_cmd(u, ord); + CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error36") == NULL); + msg = test_find_messagetype(u->faction->msgs, "msg_event"); + CuAssertPtrNotNull(tc, msg); + CuAssertTrue(tc, memcmp("Elf:", msg->parameters[0].v, 4) == 0); + msg = test_find_messagetype(u->faction->msgs, "displayitem"); + CuAssertPtrNotNull(tc, msg); + CuAssertTrue(tc, memcmp("Hiyaa!", msg->parameters[2].v, 4) == 0); + test_clear_messages(u->faction); + free_order(ord); + test_cleanup(); +} + static int low_wage(const region * r, const faction * f, const race * rc, int in_turn) { return 1; } @@ -1466,6 +1508,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_show_without_item); SUITE_ADD_TEST(suite, test_show_elf); SUITE_ADD_TEST(suite, test_show_race); + SUITE_ADD_TEST(suite, test_show_both); SUITE_ADD_TEST(suite, test_immigration); SUITE_ADD_TEST(suite, test_demon_hunger); From 7b0ec466fa7c6967858d729523698d0fb3ea06d4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 May 2017 13:09:54 +0200 Subject: [PATCH 2/7] only enable certain pragmas for MSVC 2015 and later --- src/platform.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform.h b/src/platform.h index 97d254e2d..9e2ecfadb 100644 --- a/src/platform.h +++ b/src/platform.h @@ -15,11 +15,13 @@ #define NO_MKDIR #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES +#if _MSC_VER >= 1900 #pragma warning(disable: 4710 4820) #pragma warning(disable: 4100) // unreferenced formal parameter #pragma warning(disable: 4456) // declaration hides previous #pragma warning(disable: 4457) // declaration hides function parameter #pragma warning(disable: 4459) // declaration hides global +#endif #else /* assume gcc */ #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L # define va_copy(a,b) __va_copy(a,b) From efb0501b203418e929a98b875e8cbf244c68b97c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 12 Jul 2016 17:19:47 +0200 Subject: [PATCH 3/7] additional testing --- src/laws.test.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/laws.test.c b/src/laws.test.c index 36aafb4cb..34590be67 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1369,12 +1369,13 @@ static void test_show_elf(CuTest *tc) { unit *u; struct locale *loc; message * msg; + const struct item_type *itype; test_setup(); mt_register(mt_new_va("msg_event", "string:string", 0)); rc = test_create_race("elf"); - test_create_itemtype("elvenhorse"); + itype = test_create_itemtype("elvenhorse"); loc = test_create_locale(); locale_setstring(loc, "elvenhorse", "Elfenpferd"); @@ -1389,12 +1390,22 @@ static void test_show_elf(CuTest *tc) { u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); u->faction->locale = loc; ord = create_order(K_RESHOW, loc, "Elf"); + reshow_cmd(u, ord); CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error36") == NULL); msg = test_find_messagetype(u->faction->msgs, "msg_event"); CuAssertPtrNotNull(tc, msg); CuAssertTrue(tc, memcmp("Elf:", msg->parameters[0].v, 4) == 0); test_clear_messages(u->faction); + + i_change(&u->items, itype, 1); + reshow_cmd(u, ord); + CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error36") == NULL); + msg = test_find_messagetype(u->faction->msgs, "msg_event"); + CuAssertPtrNotNull(tc, msg); + CuAssertTrue(tc, memcmp("Elf:", msg->parameters[0].v, 4) == 0); + test_clear_messages(u->faction); + free_order(ord); test_cleanup(); } From bc0726da18df30c9ef1772435d1c38bf1406f7b2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 May 2017 14:52:46 +0200 Subject: [PATCH 4/7] remove duplicate test --- src/laws.test.c | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index 66f6088ae..7e5df0b56 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1363,53 +1363,6 @@ static void test_show_without_item(CuTest *tc) test_cleanup(); } -static void test_show_elf(CuTest *tc) { - order *ord; - race * rc; - unit *u; - struct locale *loc; - message * msg; - const struct item_type *itype; - - test_setup(); - - mt_register(mt_new_va("msg_event", "string:string", 0)); - rc = test_create_race("elf"); - itype = test_create_itemtype("elvenhorse"); - - loc = test_create_locale(); - locale_setstring(loc, "elvenhorse", "Elfenpferd"); - locale_setstring(loc, "elvenhorse_p", "Elfenpferde"); - locale_setstring(loc, "race::elf_p", "Elfen"); - locale_setstring(loc, "race::elf", "Elf"); - init_locale(loc); - - CuAssertPtrNotNull(tc, finditemtype("elf", loc)); - CuAssertPtrNotNull(tc, findrace("elf", loc)); - - u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); - u->faction->locale = loc; - ord = create_order(K_RESHOW, loc, "Elf"); - - reshow_cmd(u, ord); - CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error36") == NULL); - msg = test_find_messagetype(u->faction->msgs, "msg_event"); - CuAssertPtrNotNull(tc, msg); - CuAssertTrue(tc, memcmp("Elf:", msg->parameters[0].v, 4) == 0); - test_clear_messages(u->faction); - - i_change(&u->items, itype, 1); - reshow_cmd(u, ord); - CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error36") == NULL); - msg = test_find_messagetype(u->faction->msgs, "msg_event"); - CuAssertPtrNotNull(tc, msg); - CuAssertTrue(tc, memcmp("Elf:", msg->parameters[0].v, 4) == 0); - test_clear_messages(u->faction); - - free_order(ord); - test_cleanup(); -} - static void test_show_race(CuTest *tc) { order *ord; race * rc; @@ -1664,7 +1617,6 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_name_building); SUITE_ADD_TEST(suite, test_name_ship); SUITE_ADD_TEST(suite, test_show_without_item); - SUITE_ADD_TEST(suite, test_show_elf); SUITE_ADD_TEST(suite, test_show_race); SUITE_ADD_TEST(suite, test_show_both); SUITE_ADD_TEST(suite, test_immigration); From 37aded9b1d1ace41db45d87e71d679b0bba9d3af Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 May 2017 16:12:13 +0200 Subject: [PATCH 5/7] remove unused function --- src/laws.test.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index 7e5df0b56..4d6adbfe9 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1446,10 +1446,6 @@ static void test_show_both(CuTest *tc) { test_cleanup(); } -static int low_wage(const region * r, const faction * f, const race * rc, int in_turn) { - return 1; -} - static void test_immigration(CuTest * tc) { region *r; From a3f655f3226a0799a2cb311c6d8d6bc32763240c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 22 May 2017 21:35:25 +0200 Subject: [PATCH 6/7] fix bogus warnings --- src/kernel/building.c | 9 +++++---- src/kernel/ship.c | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/kernel/building.c b/src/kernel/building.c index 92a4fd6f1..bcc914cca 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -75,15 +75,16 @@ static building_type *bt_find_i(const char *name) if (match) { cb_get_kv(match, &btype, sizeof(btype)); } - else { - log_warning("st_find: could not find ship '%s'\n", name); - } return btype; } const building_type *bt_find(const char *name) { - return bt_find_i(name); + building_type *btype = bt_find_i(name); + if (!btype) { + log_warning("bt_find: could not find building '%s'\n", name); + } + return btype; } static int bt_changes = 1; diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 3a7608789..220c16619 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -97,14 +97,15 @@ static ship_type *st_find_i(const char *name) if (match) { cb_get_kv(match, &st, sizeof(st)); } - else { - log_warning("st_find: could not find ship '%s'\n", name); - } return st; } const ship_type *st_find(const char *name) { - return st_find_i(name); + ship_type *st = st_find_i(name); + if (!st) { + log_warning("st_find: could not find ship '%s'\n", name); + } + return st; } static void st_register(ship_type *stype) { From 8e15487a1eeae5f4b3706d8a40ffdcf2fc59f15e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 26 May 2017 06:27:25 +0200 Subject: [PATCH 7/7] BUG 2328: wrong calendar seasons. --- conf/calendar.json | 7 ++++--- scripts/tests/e2/e2features.lua | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/conf/calendar.json b/conf/calendar.json index 8a134dc40..43b01351a 100644 --- a/conf/calendar.json +++ b/conf/calendar.json @@ -2,17 +2,18 @@ "calendar" : { "months" : [ { "storm" : 60, "season" : 2 }, - { "storm" : 10, "season" : 2 }, - { "storm" : 60, "season" : 3 }, { "storm" : 10, "season" : 3 }, + { "storm" : 60, "season" : 3 }, + { "storm" : 10, "season" : 0 }, { "storm" : 60, "season" : 0 }, { "storm" : 80, "season" : 0 }, { "storm" : 50, "season" : 1 }, { "storm" : 30, "season" : 1 }, - { "storm" : 60, "season" : 1 } + + { "storm" : 60, "season" : 2 } ], "weeks" : [ "firstweek", "secondweek", "thirdweek" diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index 6495bd5e6..1a4047d63 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -404,3 +404,7 @@ function test_demonstealth() desc = u:show() assert_equal(nil, string.find(desc, "Drache")) end + +function test_calendar_season_2328() + assert_equal("fall", get_season(1026)) +end