From 2ed29bfc15290c69fc773838f7b70145b9a675cc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 15 Jul 2009 20:13:27 +0000 Subject: [PATCH] - fishing implemented - bugfix shipweight - --- src/common/gamecode/creport.c | 9 ++++++--- src/common/gamecode/economy.c | 24 ------------------------ src/common/gamecode/laws.c | 22 +++++++++++++++++++++- src/common/kernel/move.c | 34 ++++++++++++++++++++++++---------- src/common/kernel/ship.c | 30 ++++++++++++++++++++++-------- src/common/kernel/ship.h | 1 + src/res/e3a/ships.xml | 24 ++++++++++++------------ 7 files changed, 86 insertions(+), 58 deletions(-) diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index b8de0baaf..f347bee61 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -607,16 +607,19 @@ cr_output_ship(FILE * F, const ship * sh, const unit * u, int fcaptain, const fa /* calculate cargo */ if (u && (u->faction == f || omniscient(f))) { - int n = 0, p = 0, c = shipcapacity(sh); + static int rule_capacity = -1; + int n = 0, p = 0; + int mweight = shipcapacity(sh); + int mcabins = sh->type->cabins; getshipweight(sh, &n, &p); fprintf(F, "%d;cargo\n", n); - fprintf(F, "%d;capacity\n", c); + fprintf(F, "%d;capacity\n", mcabins); fprintf(F, "%d;speed\n", shipspeed(sh, u)); n = (n+99) / 100; /* 1 Silber = 1 GE */ fprintf(F, "%d;Ladung\n", n); - fprintf(F, "%d;MaxLadung\n", c / 100); + fprintf(F, "%d;MaxLadung\n", mweight / 100); } /* shore */ w = NODIRECTION; diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index dc00491d3..8c35cc753 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -3234,27 +3234,6 @@ peasant_taxes(region * r) } } -static void fishing(region * r) { - ship * sh; - for (sh=r->ships;sh;sh=sh->next) { - if (sh->type->fishing>0) { - unit * u = captain(sh); - if (u) { - int weight, cabins; - int cap = shipcapacity(sh); - getshipweight(sh, &weight, &cabins); - if (cap>weight) { - int fishes = MIN(cap-weight, sh->type->fishing*i_silver->weight); - fishes /= i_silver->weight; - i_change(&u->items, i_silver, fishes); - ADDMSG(&u->faction->msgs, msg_message("income_fishing", - "unit region amount", u, r, fishes)); - } - } - } - } -} - void produce(void) { @@ -3288,9 +3267,6 @@ produce(void) peasant_taxes(r); } - if (r->ships && fval(r->terrain, SEA_REGION)) { - fishing(r); - } buyorders = 0; sellorders = 0; working = 0; diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 3bdf576c2..9f4007997 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -221,11 +221,31 @@ get_food(region *r) * jede Einheit genug Silber für ihren Unterhalt hat. */ for (u = r->units; u; u = u->next) { - int need = lifestyle(u); + int style = lifestyle(u); + int need = style; /* Erstmal zurücksetzen */ freset(u, UFL_HUNGER); + if (u->ship && (u->ship->flags&SF_FISHING)) { + unit * v; + int c = 2; + for (v=r->units;c>0 && v;v=v->next) { + if (v->ship==u->ship) { + if (u==v) { + if (u->number==c) { + need = 0; + } else { + int x = MIN(c, u->number); + int save = (style * x) / u->number; + need -= save; + } + } + c -= v->number; + } + } + } + if (food_rules&1) { /* if the region is owned, and the owner is nice, then we'll get * food from the peasants - should not be used with WORK */ diff --git a/src/common/kernel/move.c b/src/common/kernel/move.c index ba3bb6c55..407f4f2ea 100644 --- a/src/common/kernel/move.c +++ b/src/common/kernel/move.c @@ -459,19 +459,29 @@ canride(unit * u) static boolean cansail(const region * r, ship * sh) { - int n = 0, p = 0; + /* 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 false; + } else { + static int rule_capacity = -1; + int n = 0, p = 0; + int mweight = shipcapacity(sh); + int mcabins = sh->type->cabins; - if (sh->type->construction && sh->size!=sh->type->construction->maxsize) - return false; - getshipweight(sh, &n, &p); + if (rule_capacity<0) { + rule_capacity = get_param_int(global.parameters, "rules.ship.capacity", 0); + } + if (rule_capacity!=0) { + mcabins *= PERSON_WEIGHT; + } + getshipweight(sh, &n, &p); - if (n > shipcapacity(sh)) return false; - if (p > sh->type->cabins) return false; - - return true; + if (n > mweight) return false; + if (p > mcabins) return false; + } + return true; } int @@ -730,6 +740,10 @@ drifting_ships(region * r) int d_offset; direction_t dir = 0; + if (sh->type->fishing>0) { + sh->flags |= SF_FISHING; + } + /* Schiff schon abgetrieben oder durch Zauber geschützt? */ if (fval(sh, SF_DRIFTED) || is_cursed(sh->attribs, C_SHIP_NODRIFT, 0)) { shp = &sh->next; diff --git a/src/common/kernel/ship.c b/src/common/kernel/ship.c index acf9546dd..d18ec118f 100644 --- a/src/common/kernel/ship.c +++ b/src/common/kernel/ship.c @@ -20,6 +20,7 @@ #include "build.h" #include "unit.h" #include "item.h" +#include "race.h" #include "region.h" #include "skill.h" @@ -267,14 +268,27 @@ shipcapacity (const ship * sh) void getshipweight(const ship * sh, int *sweight, int *scabins) { - unit * u; - *sweight = 0; - *scabins = 0; - for (u = sh->region->units; u; u = u->next) - if (u->ship == sh) { - *sweight += weight(u); - *scabins += u->number; - } + static int rule_capacity = -1; + unit * u; + + *sweight = 0; + *scabins = 0; + + if (rule_capacity<0) { + rule_capacity = get_param_int(global.parameters, "rules.ship.capacity", 0); + } + for (u = sh->region->units; u; u = u->next) { + if (u->ship == sh) { + *sweight += weight(u); + if (rule_capacity==0) { + *scabins += u->number; + } else { + /* weight goes into number of cabins, not cargo */ + scabins += u->number * u->race->weight; + sweight -= u->number * u->race->weight; + } + } + } } unit * diff --git a/src/common/kernel/ship.h b/src/common/kernel/ship.h index 664e35a29..e51b77a3e 100644 --- a/src/common/kernel/ship.h +++ b/src/common/kernel/ship.h @@ -72,6 +72,7 @@ extern void st_register(const ship_type * type); #define SF_MOVED 1<<1 #define SF_DAMAGED 1<<2 /* for use in combat */ #define SF_SELECT 1<<3 /* previously FL_DH */ +#define SF_FISHING 1<<4 /* was on an ocean, can fish */ typedef struct ship { struct ship *next; diff --git a/src/res/e3a/ships.xml b/src/res/e3a/ships.xml index 75531db24..cdcdda881 100644 --- a/src/res/e3a/ships.xml +++ b/src/res/e3a/ships.xml @@ -1,6 +1,6 @@ - + @@ -17,7 +17,7 @@ - + @@ -27,7 +27,7 @@ - + @@ -44,7 +44,7 @@ - + @@ -62,7 +62,7 @@ - + @@ -80,7 +80,7 @@ - + @@ -90,7 +90,7 @@ - + @@ -98,7 +98,7 @@ - + @@ -107,7 +107,7 @@ - + @@ -117,7 +117,7 @@ - + @@ -128,7 +128,7 @@ - + @@ -139,7 +139,7 @@ - +