From b72f48c044234b427497a1be12d37a06414736b0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Apr 2015 11:41:50 +0200 Subject: [PATCH] enhanced ship speed for selected ships (currently none). --- src/kernel/jsonconf.c | 3 +++ src/kernel/jsonconf.test.c | 6 +++++- src/kernel/ship.c | 7 +++++-- src/kernel/ship.h | 1 + src/kernel/ship.test.c | 4 +--- src/kernel/xmlreader.c | 2 +- src/move.c | 4 ++-- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 8db61376c..f9a025432 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -323,6 +323,9 @@ static void json_ship(cJSON *json, ship_type *st) { if (strcmp(child->string, "range") == 0) { st->range = child->valueint; } + else if (strcmp(child->string, "maxrange") == 0) { + st->range_max = child->valueint; + } else { log_error("ship %s contains unknown attribute %s", json->string, child->string); } diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index bbe222fb6..50cba3891 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -155,7 +155,9 @@ static void test_ships(CuTest * tc) { const char * data = "{\"ships\": { \"boat\" : { " "\"construction\" : { \"maxsize\" : 20, \"reqsize\" : 10, \"minskill\" : 1 }," - "\"coasts\" : [ \"plain\" ]" + "\"coasts\" : [ \"plain\" ]," + "\"range\" : 8," + "\"maxrange\" : 16" "}}}"; cJSON *json = cJSON_Parse(data); @@ -175,6 +177,8 @@ static void test_ships(CuTest * tc) CuAssertIntEquals(tc, 10, st->construction->reqsize); CuAssertIntEquals(tc, 20, st->construction->maxsize); CuAssertIntEquals(tc, 1, st->construction->minskill); + CuAssertIntEquals(tc, 8, st->range); + CuAssertIntEquals(tc, 16, st->range_max); ter = get_terrain("plain"); CuAssertPtrNotNull(tc, ter); diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 373f58015..13f5605c5 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -336,8 +336,11 @@ int shipspeed(const ship * sh, const unit * u) } bonus = ShipSpeedBonus(u); - if (bonus > 0) { - // + if (bonus > 0 && sh->type->range_max>sh->type->range) { + int crew = crew_skill(sh); + int crew_bonus = (crew / sh->type->sumskill / 2) - 1; + bonus = _min(bonus, crew_bonus); + bonus = _min(bonus, sh->type->range_max - sh->type->range); } k += bonus; diff --git a/src/kernel/ship.h b/src/kernel/ship.h index 0d84935c3..be873ab99 100644 --- a/src/kernel/ship.h +++ b/src/kernel/ship.h @@ -127,6 +127,7 @@ extern "C" { int shipspeed(const struct ship *sh, const struct unit *u); int crew_skill(const struct ship *sh); + int crew_skill(const struct ship *sh); #ifdef __cplusplus } #endif diff --git a/src/kernel/ship.test.c b/src/kernel/ship.test.c index 05a735d26..dfc601682 100644 --- a/src/kernel/ship.test.c +++ b/src/kernel/ship.test.c @@ -400,8 +400,6 @@ static ship *setup_ship(void) { ship_type *stype; ship *sh; - test_cleanup(); - test_create_world(); r = test_create_region(0, 0, test_create_terrain("ocean", 0)); stype = test_create_shiptype("longboat"); stype->cptskill = 1; @@ -557,7 +555,6 @@ static void test_shipspeed(CuTest *tc) { set_level(crew, SK_SAILING, (stype->sumskill - stype->cptskill) * 11); set_level(cap, SK_SAILING, stype->cptskill + 10); CuAssertIntEquals_Msg(tc, "regular skills should not exceed sh.range", 2, shipspeed(sh, cap)); - } CuSuite *get_ship_suite(void) @@ -574,6 +571,7 @@ CuSuite *get_ship_suite(void) SUITE_ADD_TEST(suite, test_shipowner_goes_to_other_after_leave); SUITE_ADD_TEST(suite, test_shipowner_goes_to_same_faction_after_leave); SUITE_ADD_TEST(suite, test_shipowner_goes_to_empty_unit_after_leave); + SUITE_ADD_TEST(suite, test_crew_skill); SUITE_ADD_TEST(suite, test_shipspeed); SUITE_ADD_TEST(suite, test_shipspeed_stormwind); SUITE_ADD_TEST(suite, test_shipspeed_nodrift); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index f70935985..da1fed792 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -509,7 +509,7 @@ static int parse_ships(xmlDocPtr doc) st->minskill = xml_ivalue(node, "minskill", st->minskill); st->sumskill = xml_ivalue(node, "sumskill", st->sumskill); st->range = xml_ivalue(node, "range", st->range); - st->range_max = xml_ivalue(node, "range_max", st->range_max); + st->range_max = xml_ivalue(node, "maxrange", st->range_max); st->storm = xml_fvalue(node, "storm", st->storm); /* reading eressea/ships/ship/construction */ diff --git a/src/move.c b/src/move.c index 7d6f69371..4fd9e6dab 100644 --- a/src/move.c +++ b/src/move.c @@ -469,9 +469,9 @@ static bool cansail(const region * r, ship * sh) return true; } -int enoughsailors(const ship * sh, int sumskill) +int enoughsailors(const ship * sh, int crew_skill) { - return sumskill >= sh->type->sumskill; + return crew_skill >= sh->type->sumskill; } /* ------------------------------------------------------------- */