From f5800c7831582e54821e1f9dd540a999a00f22a4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 12 Oct 2009 18:24:38 +0000 Subject: [PATCH] http://bugs.eressea.de/view.php?id=1644 rounding error calculating ship damage --- src/common/kernel/ship.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/common/kernel/ship.c b/src/common/kernel/ship.c index e48946563..f0619cb35 100644 --- a/src/common/kernel/ship.c +++ b/src/common/kernel/ship.c @@ -246,23 +246,20 @@ shipname(const ship * sh) int shipcapacity (const ship * sh) { - int i; + int i = sh->type->cargo; - /* sonst ist construction:: size nicht ship_type::maxsize */ - assert(!sh->type->construction || sh->type->construction->improvement==NULL); + /* sonst ist construction:: size nicht ship_type::maxsize */ + assert(!sh->type->construction || sh->type->construction->improvement==NULL); - if (sh->type->construction && sh->size!=sh->type->construction->maxsize) - return 0; + if (sh->type->construction && sh->size!=sh->type->construction->maxsize) + return 0; #ifdef SHIPDAMAGE - i = ((sh->size * DAMAGE_SCALE - sh->damage) / DAMAGE_SCALE) - * sh->type->cargo / sh->size; - i += ((sh->size * DAMAGE_SCALE - sh->damage) % DAMAGE_SCALE) - * sh->type->cargo / (sh->size*DAMAGE_SCALE); -#else - i = sh->type->cargo; + if (sh->damage) { + i = (int)ceil(i * (1.0 - sh->damage / sh->size / (double)DAMAGE_SCALE)); + } #endif - return i; + return i; } void