--- src/lib/commands/fort.c Sat Mar 11 05:36:44 2000 +++ src/lib/commands/fort.c Sat May 3 14:58:55 2003 @@ -50,8 +50,7 @@ int nunits; struct nstr_item ni; struct lndstr land; - int fort_amt, hard_amt, mob_used; - int eng; + int fort_amt, hard_amt; s_char *p; extern int land_mob_max; s_char buf[1024]; @@ -95,38 +94,7 @@ nunits++; - hard_amt = min(land.lnd_mobil, hard_amt); - - if ((land.lnd_harden + hard_amt) > land_mob_max) - hard_amt = land_mob_max - land.lnd_harden; - - eng = is_engineer(land.lnd_x, land.lnd_y); - - if (eng) - hard_amt = ((float)hard_amt * 1.5); - - if ((land.lnd_harden + hard_amt) > land_mob_max) - hard_amt = land_mob_max - land.lnd_harden; - - /* Ok, set the mobility used */ - mob_used = hard_amt; - - /* Now, if an engineer helped, it's really only 2/3rds of - that */ - if (eng) - mob_used = (int)((float)mob_used / 1.5); - - /* If we increased it, but not much, we gotta take at least 1 - mob point. */ - if (mob_used <= 0 && hard_amt > 0) - mob_used = 1; - - land.lnd_mobil -= mob_used; - if (land.lnd_mobil < 0) - land.lnd_mobil = 0; - - land.lnd_harden += hard_amt; - land.lnd_harden = min(land.lnd_harden, land_mob_max); + land_harden(&land, hard_amt); pr("%s hardened to %d\n", prland(&land), land.lnd_harden); @@ -142,19 +110,4 @@ }else pr("%d unit%s\n", nunits, splur(nunits)); return RET_OK; -} - -int -is_engineer(int x, int y) -{ - struct nstr_item ni; - struct lndstr land; - - snxtitem_xy(&ni, EF_LAND, x,y); - while(nxtitem(&ni, (s_char *)&land)){ - if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER) - return 1; - } - - return 0; } --- src/lib/common/land.c Sat Mar 11 05:36:34 2000 +++ src/lib/common/land.c Sat May 3 15:26:54 2003 @@ -96,3 +96,66 @@ return 0; } + +int +has_friendly_engineer(int x, int y, natid cn) +{ + struct nstr_item ni; + struct lndstr land; + + snxtitem_xy(&ni, EF_LAND, x,y); + while(nxtitem(&ni, (s_char *)&land)) { + if ((lchr[(int)land.lnd_type].l_flags & L_ENGINEER) + && (land.lnd_own == cn + || getrel(getnatp(land.lnd_own), cn) >= FRIENDLY)) + { + return 1; + } + } + + return 0; +} + +/* returns amount of mob actually used to harden. */ +int +land_harden(struct lndstr * lp, int mob_to_use) +{ + int amount, eng; + extern int land_mob_max; + + /* units on a ship can't be fortified. */ + if (lp->lnd_ship >= 0) + return 0; + + mob_to_use = min(mob_to_use, lp->lnd_mobil); + + amount = mob_to_use; + + eng = has_friendly_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own); + + if (eng) + amount = (int)((float)amount * 1.5); + + if (amount + lp->lnd_harden > land_mob_max) + amount = land_mob_max - lp->lnd_harden; + + lp->lnd_harden += amount; + + mob_to_use = amount; + + /* Now, if an engineer helped, it's really only 2/3rds of + that */ + if (eng) + mob_to_use = (int)((float)mob_to_use / 1.5); + + /* If we increased it, but not much, we gotta take at least 1 + mob point. */ + if (mob_to_use <= 0 && amount > 0) + mob_to_use = 1; + + lp->lnd_mobil -= mob_to_use; + if (lp->lnd_mobil < 0) + lp->lnd_mobil = 0; + + return amount; +} --- include/prototypes.h Mon Aug 7 20:59:08 2000 +++ include/prototypes.h Wed Apr 30 20:27:22 2003 @@ -170,7 +170,8 @@ extern int foll(void ); extern int force(void ); extern int fort(void ); -extern int is_engineer(int , int ); +extern int has_friendly_engineer(int , int ); +extern int land_harden(struct lndstr *, int ); extern int fuel(void ); extern int give(void ); extern int grin(void ); --- src/lib/update/mobility.c Sat Mar 11 05:36:22 2000 +++ src/lib/update/mobility.c Sat May 3 15:29:12 2003 @@ -398,17 +398,27 @@ extern int land_mob_max; extern float land_mob_scale; int newfuel=0; - register int value; - int can_add,have_fuel_for,total_add; double d; extern int fuel_mult; + /* + * We must use these variables because lnd_mobil and lnd_harden + * are of type s_char and might not be large enough to contain + * temporary results. + */ + register int value; + int can_add,have_fuel_for,total_add; + if (lp->lnd_own == 0) return; if (lp->lnd_mobil >= land_mob_max) { - lp->lnd_mobil = land_mob_max; - return; + lp->lnd_mobil = land_mob_max; + if (lp->lnd_harden >= land_mob_max) + { + lp->lnd_harden = land_mob_max; + return; + } } /* @@ -435,8 +445,15 @@ } else { value = lp->lnd_mobil + ((float)etus * land_mob_scale); } + if (value > land_mob_max) + { + if (lp->lnd_harden < land_mob_max) + land_harden(lp, value - land_mob_max); + value = land_mob_max; + } + lp->lnd_mobil = value; return; /* Done! */ @@ -453,7 +470,12 @@ value = lp->lnd_mobil + ((float)etus * land_mob_scale); } if (value > land_mob_max) + { + if (lp->lnd_harden < land_mob_max) + land_harden(lp, value - land_mob_max); + value = land_mob_max; + } lp->lnd_mobil = value; } else { @@ -513,7 +535,11 @@ lp->lnd_fuel -= (u_char)ldround(d,1); lp->lnd_fuel = (u_char)min(lp->lnd_fuel, lp->lnd_fuelc); - if(total_add + lp->lnd_mobil > land_mob_max) { + + if (total_add + lp->lnd_mobil > land_mob_max) { + if (lp->lnd_harden < land_mob_max) + land_harden(lp, total_add + lp->lnd_mobil - land_mob_max); + total_add = land_mob_max - lp->lnd_mobil; } --- info/Commands/fortify.t Mon Feb 21 15:19:29 2000 +++ info/Commands/fortify.t Sat May 3 15:44:26 2003 @@ -11,8 +11,11 @@ A fully fortified unit is twice as hard to hurt as it normally would be, and is twice as strong on the defense. .s1 -Units fortifying in a sector containing an engineering unit -are better at it. Experiment and find out. +Supplying a negative amount as the number of mobility to use, fortifies +the units for all mobility available above the absolute amount given. +.s1 +Units fortifying in a sector containing a friendly engineering unit +are better at it. Mobility cost is only 2/3 of the normal cost. .s1 If a unit moves or retreats, it loses all fortification value. A unit that reacts to defend a sector, on the other hand, does NOT @@ -23,5 +26,9 @@ Note that fortification will not help a unit fight Guerrillas in an occupied sector (see info Guerrilla). Also note that fortifying a unit does not affect it's mission status. +.s1 +During the update, units will use "spare" mobility to fortify themselves +automatically. It is as if "fortify * -67" were issued just before the +update. .s1 .SA "bomb, Unit-types, LandUnits" --- info/Concepts/Update-sequence.t Thu Feb 4 03:43:08 1999 +++ info/Concepts/Update-sequence.t Sat May 3 15:59:56 2003 @@ -45,11 +45,12 @@ c) If ship maintenance is not yet done, do it now d) If ship building is not yet done, do it now - e) If plane maintenance is not yet done, do it now - f) If plane building is not yet done, do it now - g) If unit maintenance is not yet done, do it now - h) If unit building is not yet done, do it now - i) produce for all sectors that have not yet produced + e) sail paths are sailed and orders are carried out + f) If plane maintenance is not yet done, do it now + g) If plane building is not yet done, do it now + h) If unit maintenance is not yet done, do it now + i) If unit building is not yet done, do it now + j) produce for all sectors that have not yet produced a) if the sector is a cap, it costs $$ equal to the # of etus: np->nat_money -= etus; b) people in non-sanctuary sectors eat @@ -93,6 +94,8 @@ d) Add mobility to land units 1) Units with negative mobility have their mob halved (-100 goes to -50) 2) Mobility is added + 3) If new mobility of a unit is greater than maximum, try using the + surplus for fortifying it. .fi .s1 .SA "Innards, Update"