extern int shp_nav_one_sector(struct emp_qelem *, int, natid, int);
extern int shp_missile_defense(coord, coord, natid, int);
extern void shp_missdef(struct shpstr *, natid);
+extern double shp_mobcost(struct shpstr *);
extern void shp_set_tech(struct shpstr *, int);
/* snxtitem.c */
extern int snxtitem(struct nstr_item *, int, char *);
struct sctstr sect;
int shell;
short *item;
- double mobcost;
- struct mchrstr *mcp;
/* use 1 shell from everyone */
for (qp = list->q_forw; qp != list; qp = next) {
shell = 0;
item[I_SHELL] = shell;
putship(ship.shp_uid, &ship);
- mcp = &mchr[(int)ship.shp_type];
- mobcost = ship.shp_effic * 0.01 * ship.shp_speed;
- mobcost = (480.0 / (mobcost +
- techfact(ship.shp_tech, mobcost)));
/* mob cost = 1/2 a sect's mob */
- mobcost /= 2.0;
- ship.shp_mobil -= mobcost;
+ ship.shp_mobil -= shp_mobcost(&ship) / 2.0;
}
} else if (fp->type == targ_land) {
getsect(fp->x, fp->y, §);
*len = i;
*nupdates = 1;
- mobcost = sp->shp_effic * 0.01 * sp->shp_speed;
- mobcost = 480.0 / (mobcost + techfact(sp->shp_tech, mobcost));
+ mobcost = shp_mobcost(sp);
mobil = sp->shp_mobil;
while (i) {
if (mobil > 0) {
struct shpstr vship;
struct shpstr sub;
char *ptr;
- double mobcost;
- struct mchrstr *mcp;
struct nstr_item nbst;
char buf[1024];
char *sav;
shells -= SHP_TORP_SHELLS;
sub.shp_item[I_SHELL] = shells;
putship(sub.shp_uid, &sub);
- mcp = &mchr[(int)sub.shp_type];
- mobcost = sub.shp_effic * 0.01 * sub.shp_speed;
- mobcost = (480.0 / (mobcost + techfact(sub.shp_tech, mobcost)));
-
/* Mob cost for a torp is equal to the cost of 1/2 sector of movement */
- mobcost /= 2.0;
- sub.shp_mobil -= mobcost;
+ sub.shp_mobil -= shp_mobcost(&sub) / 2.0;
pr("Whooosh... ");
getship(victno, &vship);
vshipown = vship.shp_own;
int dam;
int shells;
double hitchance;
- double mobcost;
- struct mchrstr *mcp;
shells = sp->shp_item[I_SHELL];
sp->shp_item[I_SHELL] = shells;
putship(sp->shp_uid, sp);
- mcp = &mchr[(int)sp->shp_type];
- mobcost = sp->shp_effic * 0.01 * sp->shp_speed;
- mobcost = (480.0 / (mobcost + techfact(sp->shp_tech, mobcost)));
-
/* Mob cost for a torp is equal to the cost of 1/2 sector of movement */
- mobcost /= 2.0;
- sp->shp_mobil -= mobcost;
+ sp->shp_mobil -= shp_mobcost(sp) / 2.0;
hitchance = DTORP_HITCHANCE(range, sp->shp_visib);
int dam = 0, dam2, mission_flags, tech;
natid plane_owner = 0;
int gun, shell, md, range, air_dam = 0;
- double prb, mobcost, hitchance, vrange;
+ double prb, hitchance, vrange;
getsect(x, y, §);
if (!line_of_sight(NULL, x, y, gp->x, gp->y))
continue;
sp->shp_item[I_SHELL] = shell - SHP_TORP_SHELLS;
- mobcost = sp->shp_effic * 0.01 * sp->shp_speed;
- mobcost = (480.0 / (mobcost +
- techfact(sp->shp_tech, mobcost)));
- sp->shp_mobil -= mobcost;
+ sp->shp_mobil -= shp_mobcost(sp) / 2.0;
putship(sp->shp_uid, sp);
hitchance = DTORP_HITCHANCE(md, sp->shp_visib);
mcp = &mchr[(int)sp->shp_type];
newx = xnorm(sp->shp_x + dx);
newy = ynorm(sp->shp_y + dy);
- mobcost = sp->shp_effic * 0.01 * sp->shp_speed;
- mobcost = 480.0 / (mobcost + techfact(sp->shp_tech, mobcost));
+ mobcost = shp_mobcost(sp);
getsect(newx, newy, §);
if (shp_check_nav(§, sp) != CN_NAVIGABLE ||
int mines, m, max, shells;
int changed = 0;
int stopping = 0;
- double mobcost;
for (qp = ship_list->q_back; qp != ship_list; qp = next) {
next = qp->q_back;
prship(&mlp->ship));
continue;
}
- mobcost = mlp->ship.shp_effic * 0.01 * mlp->ship.shp_speed;
- mobcost = 480.0 / (mobcost +
- techfact(mlp->ship.shp_tech, mobcost));
- mlp->mobil -= mobcost;
+ mlp->mobil -= shp_mobcost(&mlp->ship);
mlp->ship.shp_mobil = (int)mlp->mobil;
putship(mlp->ship.shp_uid, &mlp->ship);
if (!(mines = sect.sct_mines))
shp_mess("is out of mobility", mlp);
continue;
}
- mobcost = mlp->ship.shp_effic * 0.01 * mlp->ship.shp_speed;
- mobcost = 480.0 /
- (mobcost + techfact(mlp->ship.shp_tech, mobcost));
+ mobcost = shp_mobcost(&mlp->ship);
mlp->ship.shp_x = newx;
mlp->ship.shp_y = newy;
if (mlp->mobil - mobcost < -127) {
free(mlp);
}
+double
+shp_mobcost(struct shpstr *sp)
+{
+ double effspd = sp->shp_effic * 0.01 * sp->shp_speed;
+ return 480.0 / (effspd + techfact(sp->shp_tech, effspd));
+}
+
/*
* Set SP's tech to TLEV along with everything else that depends on it.
*/
static void
cost_ship(struct shpstr *sp, struct fltelemstr *ep, struct fltheadstr *fp)
{
- double mobcost;
+ double mobcost = shp_mobcost(sp);
int howfar;
- mobcost = 0.0;
- if (sp->shp_effic > 0) {
- mobcost = sp->shp_effic * sp->shp_speed * 0.01;
- mobcost = 480.0 / (mobcost * (1 + (50 + sp->shp_tech) /
- (double)(200 + sp->shp_tech)));
- }
-/* the next two lines are not necessary since shp_mobquota is unsigned
-and therefore cannot be less than 0.
- if (sp->shp_mobquota<0)
- sp->shp_mobquota=0;
-*/
-
howfar = 0;
if (mobcost > 0) {
howfar = (int)sp->shp_mobil - (int)sp->shp_mobquota;