]> git.pond.sub.org Git - empserver/commitdiff
(shp_mobcost): New.
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 20 May 2006 19:28:29 +0000 (19:28 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 20 May 2006 19:28:29 +0000 (19:28 +0000)
(use_ammo, eta_calc, torp, fire_torp, perform_mission, retreat_ship1)
(shp_sweep, shp_nav_one_sector, cost_ship): Use it.

(perform_mission): Fix mobility cost of torpedo: charged full sector
cost instead of half.

include/prototypes.h
src/lib/commands/mfir.c
src/lib/commands/orde.c
src/lib/commands/torp.c
src/lib/subs/mission.c
src/lib/subs/retreat.c
src/lib/subs/shpsub.c
src/lib/update/sail.c

index 6c181cf154ddf58a77144198249f07e32840bd20..8701cae7511483b7234c0ab32cd3636c92b5f1aa 100644 (file)
@@ -673,6 +673,7 @@ extern void shp_view(struct emp_qelem *);
 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 *);
index 70cd0f4abe35cf64013e11811d89a432db40d8d5..e645b79d40a2b9bea00314638cb845771eca44f0 100644 (file)
@@ -958,8 +958,6 @@ use_ammo(struct emp_qelem *list)
     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) {
@@ -975,13 +973,8 @@ use_ammo(struct emp_qelem *list)
                    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, &sect);
index f087ea6af35b3b46f4c30850a6e39f27e09653c4..72fe1d978624ba6643346b5653c6bbe885a80eaf 100644 (file)
@@ -330,8 +330,7 @@ eta_calc(struct shpstr *sp, char *path, int *len, int *nupdates)
     *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) {
index 4e563955cbda6e410e179b592141d047d5b0e2a2..747faabf359504b3ff67a6d80189b768d5f53daa 100644 (file)
@@ -71,8 +71,6 @@ torp(void)
     struct shpstr vship;
     struct shpstr sub;
     char *ptr;
-    double mobcost;
-    struct mchrstr *mcp;
     struct nstr_item nbst;
     char buf[1024];
     char *sav;
@@ -169,13 +167,8 @@ torp(void)
        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;
@@ -389,8 +382,6 @@ fire_torp(struct shpstr *sp, struct shpstr *targ, int range, int ntargets)
     int dam;
     int shells;
     double hitchance;
-    double mobcost;
-    struct mchrstr *mcp;
 
     shells = sp->shp_item[I_SHELL];
 
@@ -415,13 +406,8 @@ fire_torp(struct shpstr *sp, struct shpstr *targ, int range, int ntargets)
     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);
 
index 5765665dbcddcd6188e2cc8855e91cad39b85ab3..74c568f6cb40de64ea0e79584ee856eca4ceea8e 100644 (file)
@@ -437,7 +437,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
     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, &sect);
 
@@ -559,10 +559,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
                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);
 
index 7d9f1acc80d957fc7a2f0c333d90920116664074..ea9ecce93e424e91d9011044548f36effa688030 100644 (file)
@@ -246,8 +246,7 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
        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, &sect);
        if (shp_check_nav(&sect, sp) != CN_NAVIGABLE ||
index 58a0db8c150cb4b9792f56cb23578cd15a86c729..eb2a4ec66503fdc7aa38f0f8e5f6e85e9e681440 100644 (file)
@@ -219,7 +219,6 @@ shp_sweep(struct emp_qelem *ship_list, int verbose, natid actor)
     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;
@@ -242,10 +241,7 @@ shp_sweep(struct emp_qelem *ship_list, int verbose, natid actor)
                    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))
@@ -859,9 +855,7 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
            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) {
@@ -1062,6 +1056,13 @@ shp_missdef(struct shpstr *sp, natid victim)
        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.
  */
index 4c24f5d2e7f28712d8ef4499d94f5405f28b1521..1f746087d6d06a1db5a8a184dcd9957f2d928f4d 100644 (file)
@@ -55,21 +55,9 @@ static void fltp_to_list(struct fltheadstr *, struct emp_qelem *);
 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;