From 837da8ae984343b2577c04d1453efa9e12fdd212 Mon Sep 17 00:00:00 2001 From: Quietust Date: Tue, 25 Mar 2014 13:30:45 -0500 Subject: [PATCH] Fix siege-engine to compile on Windows - don't have C++11, and pow() is picky about arg types --- plugins/siege-engine.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/siege-engine.cpp b/plugins/siege-engine.cpp index 2c79cc5e3..4e9550584 100644 --- a/plugins/siege-engine.cpp +++ b/plugins/siege-engine.cpp @@ -252,6 +252,16 @@ static double random_error() return (rng.drandom0() + rng.drandom0() + rng.drandom0()) * 2.0 - 3.0; } +// round() is only available in C++11 +static int int_round (double val) +{ + double frac = val - floor(val); + if (frac < 0.5) + return (int)floor(val); + else + return (int)ceil(val); +} + static const int WEAR_TICKS = 806400; static bool apply_impact_damage(df::item *item, int minv, int maxv) @@ -385,7 +395,7 @@ static EngineInfo *find_engine(df::building *bld, bool create = false) obj->fire_range = get_engine_range(ebld, obj->quality); // Base coefficients per engine type, plus 6% exponential bonus per quality level - obj->sigma_coeff = (obj->is_catapult ? 30.0 : 48.0) * pow(1.06, obj->quality); + obj->sigma_coeff = (obj->is_catapult ? 30.0 : 48.0) * pow(1.06f, obj->quality); obj->ammo_vector_id = job_item_vector_id::BOULDER; obj->ammo_item_type = item_type::BOULDER; @@ -1513,8 +1523,8 @@ struct projectile_hook : df::proj_itemst { // Otherwise use a normal distribution to simulate errors double sigma = point_distance(path.origin - path.goal) / (engine->sigma_coeff * skill); - int dx = (int)round(random_error() * sigma); - int dy = (int)round(random_error() * sigma); + int dx = int_round(random_error() * sigma); + int dy = int_round(random_error() * sigma); if (dx == 0 && dy == 0) {