From a9ca16e7676c5dcfc6ed01c4e4a97377b13a34a6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Mar 2021 08:55:45 +0100 Subject: [PATCH] Testing for C90 compatibility --- src/CMakeLists.txt | 10 ++++++---- src/laws.c | 8 ++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 772b65542..802320d36 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -172,7 +172,7 @@ endif(CURSES_FOUND) if(IWYU_PATH) # set(C_INCLUDE_WHAT_YOU_USE "${IWYU_PATH} -Xiwyu --no_fwd_decls") else(IWYU_PATH) - message(STATUS "Could not find the program include-what-you-use") + # message(STATUS "Could not find the program include-what-you-use") endif() add_library(version STATIC ${VERSION_SRC}) @@ -204,9 +204,6 @@ add_library(game ${ERESSEA_SRC}) target_link_libraries(game ${EXTRA_LIBS} parser version) add_executable(eressea ${SERVER_SRC}) -if (IWYU_PATH) -set_property(TARGET eressea PROPERTY C_INCLUDE_WHAT_YOU_USE ${IWYU_PATH}) -endif(IWYU_PATH) target_link_libraries(eressea game ${TOLUA_LIBRARIES} @@ -275,6 +272,11 @@ target_link_libraries(test_eressea ${IniParser_LIBRARIES} ) +set_target_properties(test_eressea eressea PROPERTIES C_STANDARD 90) +if (IWYU_PATH) +set_target_properties(test_eressea eressea PROPERTIES C_INCLUDE_WHAT_YOU_USE ${IWYU_PATH}) +endif(IWYU_PATH) + add_test(server test_eressea) #add_test(NAME E3 # WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/game-e3 diff --git a/src/laws.c b/src/laws.c index ffdbde1d0..a0c1f22e2 100644 --- a/src/laws.c +++ b/src/laws.c @@ -325,6 +325,10 @@ static double peasant_luck_factor(void) return config_get_flt("rules.peasants.peasantluck.factor", PEASANTLUCK); } +inline int round_births(double growth) { + return (int)growth; +} + int peasant_luck_effect(int peasants, int luck, int maxp, double variance) { int births = 0; @@ -334,7 +338,7 @@ int peasant_luck_effect(int peasants, int luck, int maxp, double variance) mean *= peasant_luck_factor() * peasant_growth_factor(); mean *= ((peasants / (double)maxp < .9) ? 1 : PEASANTFORCE); - births = (int)ceil(normalvariate(mean, variance * mean)); + births = round_births(normalvariate(mean, variance * mean)); if (births <= 0) births = 1; if (births > peasants / 2) @@ -353,7 +357,7 @@ static void peasants(region * r, int rule) if (peasants > 0 && rule > 0) { int luck = 0; double fraction = peasants * peasant_growth_factor(); - int births = (int)ceil(fraction); + int births = round_births(fraction); attrib *a = a_find(r->attribs, &at_peasantluck); if (a != NULL) {