From 70413bb43c2de07bc0fd1d55ed1364f5ac1606ee Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Jun 2005 09:48:19 +0000 Subject: [PATCH] Noch einmal Strassen reparieren. --- src/common/kernel/build.c | 36 ++++++++++++++++++------------------ src/common/kernel/region.c | 20 ++++++-------------- src/common/kernel/region.h | 4 ++-- src/common/kernel/spell.c | 16 ++++++++-------- src/common/kernel/terrain.h | 2 +- src/eressea/korrektur.c | 2 +- src/eressea/lua/region.cpp | 2 +- 7 files changed, 37 insertions(+), 45 deletions(-) diff --git a/src/common/kernel/build.c b/src/common/kernel/build.c index f9a1b30f5..17ee7e7f8 100644 --- a/src/common/kernel/build.c +++ b/src/common/kernel/build.c @@ -296,11 +296,15 @@ do_siege(void) /* ------------------------------------------------------------- */ static void -destroy_road(unit *u, int n, struct order * ord) +destroy_road(unit *u, int nmax, struct order * ord) { direction_t d = getdirection(u->faction->locale); unit *u2; region *r = u->region; + short n = (short)nmax; + + if (nmax>SHRT_MAX) n = SHRT_MAX; + else if (nmax<0) n = 0; for (u2=r->units;u2;u2=u2->next) { if (u2->faction!=u->faction && getguard(u2)&GUARD_TAX @@ -314,22 +318,18 @@ destroy_road(unit *u, int n, struct order * ord) if (d==NODIRECTION) { cmistake(u, ord, 71, MSG_PRODUCE); } else { -#if 0 - int salvage, divy = 2; -#endif - int willdo = min(n, eff_skill(u, SK_ROAD_BUILDING, r)*u->number); - int road = rroad(r, d); - region * r2 = rconnect(r,d); - willdo = min(willdo, road); - if (willdo==0) { - /* TODO: error message */ - } -#if 0 - salvage = willdo / divy; - change_item(u, I_STONE, salvage); -#endif - rsetroad(r, d, road - willdo); - if (road!=0 && road <= willdo) { + short road = rroad(r, d); + road = min(n, road); + if (road!=0) { + region * r2 = rconnect(r,d); + int willdo = eff_skill(u, SK_ROAD_BUILDING, r)*u->number; + willdo = min(willdo, road); + if (willdo==0) { + /* TODO: error message */ + } + if (willdo>SHRT_MAX) road = 0; + else road = road - (short)willdo; + rsetroad(r, d, road); ADDMSG(&u->faction->msgs, msg_message("destroy_road", "unit from to", u, r, r2)); } @@ -554,7 +554,7 @@ build_road(region * r, unit * u, int size, direction_t d) /* n is now modified by several special effects, so we have to * minimize it again to make sure the road will not grow beyond * maximum. */ - rsetroad(r, d, rroad(r, d) + min(n, left)); + rsetroad(r, d, rroad(r, d) + (short)min(n, left)); if (u->race == new_race[RC_STONEGOLEM]){ int golemsused = n / GOLEM_STONE; diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index 3be3ce100..b5523f677 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -567,9 +567,8 @@ attrib_type at_road = { }; void -rsetroad(region * r, direction_t d, int val) +rsetroad(region * r, direction_t d, short val) { - int rval; border * b; region * r2 = rconnect(r, d); @@ -577,15 +576,11 @@ rsetroad(region * r, direction_t d, int val) b = get_borders(r, r2); while (b && b->type!=&bt_road) b = b->next; if (!b) b = new_border(&bt_road, r, r2); - rval = b->data.i; - if (b->from==r) - rval = (rval & 0xFFFF) | (val<<16); - else - rval = (rval & 0xFFFF0000) | val; - b->data.i = rval; + if (r==b->from) b->data.sa[0] = val; + else b->data.sa[1] = val; } -int +short rroad(const region * r, direction_t d) { int rval; @@ -597,11 +592,8 @@ rroad(const region * r, direction_t d) while (b && b->type!=&bt_road) b = b->next; if (!b) return 0; rval = b->data.i; - if (b->to==r) - rval = (rval & 0xFFFF); - else - rval = (rval & 0xFFFF0000) >> 16; - return rval; + if (r==b->from) return b->data.sa[0]; + return b->data.sa[1]; } boolean diff --git a/src/common/kernel/region.h b/src/common/kernel/region.h index 532a83ebc..1554d6d46 100644 --- a/src/common/kernel/region.h +++ b/src/common/kernel/region.h @@ -189,8 +189,8 @@ void chaoscounts(struct region * r, int delta); void setluxuries(struct region * r, const struct luxury_type * sale); -int rroad(const struct region * r, direction_t d); -void rsetroad(struct region * r, direction_t d, int value); +short rroad(const struct region * r, direction_t d); +void rsetroad(struct region * r, direction_t d, short value); int is_coastregion(struct region *r); diff --git a/src/common/kernel/spell.c b/src/common/kernel/spell.c index 576d04f47..f790513df 100644 --- a/src/common/kernel/spell.c +++ b/src/common/kernel/spell.c @@ -1659,13 +1659,13 @@ sp_create_stonegolem(castorder *co) * (FARCASTING | REGIONSPELL | TESTRESISTANCE) */ -void -destroy_all_roads(region *r, int val) +static void +destroy_all_roads(region *r) { int i; for(i = 0; i < MAXDIRECTIONS; i++){ - rsetroad(r,(direction_t)i, val); + rsetroad(r,(direction_t)i, 0); } } @@ -1710,17 +1710,17 @@ sp_great_drought(castorder *co) switch(rterrain(r)){ case T_PLAIN: rsetterrain(r, T_GRASSLAND); - destroy_all_roads(r, 0); + destroy_all_roads(r); break; case T_SWAMP: rsetterrain(r, T_GRASSLAND); - destroy_all_roads(r, 0); + destroy_all_roads(r); break; case T_GRASSLAND: rsetterrain(r, T_DESERT); - destroy_all_roads(r, 0); + destroy_all_roads(r); break; case T_GLACIER: @@ -1730,9 +1730,9 @@ sp_great_drought(castorder *co) #endif if (rand() % 100 < 50){ rsetterrain(r, T_SWAMP); - destroy_all_roads(r, 0); + destroy_all_roads(r); } else { /* Ozean */ - destroy_all_roads(r, 0); + destroy_all_roads(r); rsetterrain(r, T_OCEAN); /* Einheiten dürfen hier auf keinen Fall gelöscht werden! */ for (u = r->units; u; u = u->next) { diff --git a/src/common/kernel/terrain.h b/src/common/kernel/terrain.h index a122c8c24..6cc1faf20 100644 --- a/src/common/kernel/terrain.h +++ b/src/common/kernel/terrain.h @@ -73,7 +73,7 @@ typedef struct terraindata_t { /* ist NULL, wenn kein Strassenbau möglich */ int quarries; /* abbaubare Steine pro Runde */ - int roadreq; /* Steine fuer Strasse (-1 = nicht machbar) */ + short roadreq; /* Steine fuer Strasse (-1 = nicht machbar) */ int production_max; /* bebaubare Parzellen (10 Leute pro Parzelle) */ /* Achtung: Produktion wird durch Flueche (zB Duerre) beeinflusst. * Die Funktion production(struct region *r) in economic.c ermittelt den diff --git a/src/eressea/korrektur.c b/src/eressea/korrektur.c index a0c57f17c..3230e07c1 100644 --- a/src/eressea/korrektur.c +++ b/src/eressea/korrektur.c @@ -1023,7 +1023,7 @@ fix_attribflags(void) while (a) { if (a->type==&at_guard) { fset(u, UFL_GUARD); - break; + break; } a = a->next; } diff --git a/src/eressea/lua/region.cpp b/src/eressea/lua/region.cpp index 36ae963ba..caeac9cd4 100644 --- a/src/eressea/lua/region.cpp +++ b/src/eressea/lua/region.cpp @@ -119,7 +119,7 @@ region_getresource(const region& r, const char * type) static void region_setroad(region& r, int dir, lua_Number size) { - rsetroad(&r, (direction_t)dir, (int)(terrain[rterrain(&r)].roadreq * size)); + rsetroad(&r, (direction_t)dir, (short)(terrain[rterrain(&r)].roadreq * size)); } static lua_Number