Noch einmal Strassen reparieren.

This commit is contained in:
Enno Rehling 2005-06-12 09:48:19 +00:00
parent 032cc5eadf
commit 70413bb43c
7 changed files with 37 additions and 45 deletions

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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) {

View File

@ -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

View File

@ -1023,7 +1023,7 @@ fix_attribflags(void)
while (a) {
if (a->type==&at_guard) {
fset(u, UFL_GUARD);
break;
break;
}
a = a->next;
}

View File

@ -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