(M_TORP_SHELLS): New.

(perform_mission, torp, fire_torp, quiet_bigdef, use_ammo): Use it.
Closes #917459.
This commit is contained in:
Markus Armbruster 2004-05-09 20:55:30 +00:00
parent a6bd408323
commit d7e697b1f9
4 changed files with 26 additions and 24 deletions

View file

@ -180,7 +180,7 @@ struct mchrstr {
#define M_CHOPPER bit(16) /* can hold choppers */ #define M_CHOPPER bit(16) /* can hold choppers */
#define M_OILER bit(17) /* can re-fuel ships */ #define M_OILER bit(17) /* can re-fuel ships */
#define M_SUPPLY bit(18) /* Can supply units/sects/ships */ #define M_SUPPLY bit(18) /* Can supply units/sects/ships */
/* M_XUNIT will be automatically set in init_global() if m_nland > 0 */ /* M_UNIT will be automatically set in init_global() if m_nland > 0 */
#define M_UNIT bit(19) /* Can carry units */ #define M_UNIT bit(19) /* Can carry units */
#define M_ANTIMISSILE bit(20) /* Shoot down missile */ #define M_ANTIMISSILE bit(20) /* Shoot down missile */
@ -218,4 +218,8 @@ struct mlist {
#define CN_CONSTRUCTION (2) #define CN_CONSTRUCTION (2)
#define CN_ERROR (-1) #define CN_ERROR (-1)
enum {
M_TORP_SHELLS = 3 /* number of shells used by a torpedo */
};
#endif /* _SHIP_H_ */ #endif /* _SHIP_H_ */

View file

@ -811,10 +811,10 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
continue; continue;
if (mchr[(int)ship.shp_type].m_flags & M_SUB) { if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
if (shell < 3) if (shell < M_TORP_SHELLS)
shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y, shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
I_SHELL, 3 - shell); I_SHELL, M_TORP_SHELLS - shell);
if (shell < 3) if (shell < M_TORP_SHELLS)
continue; continue;
if (gun < 1) if (gun < 1)
continue; continue;
@ -1008,7 +1008,7 @@ use_ammo(struct emp_qelem *list)
item = ship.shp_item; item = ship.shp_item;
if (mchr[(int)ship.shp_type].m_flags & M_SUB) { if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
shell = item[I_SHELL]; shell = item[I_SHELL];
shell--; shell -= M_TORP_SHELLS - 1;
if (shell < 0) if (shell < 0)
shell = 0; shell = 0;
item[I_SHELL] = shell; item[I_SHELL] = shell;

View file

@ -88,11 +88,10 @@ torp(void)
if ((mchr[(int)sub.shp_type].m_flags & M_TORP) == 0) if ((mchr[(int)sub.shp_type].m_flags & M_TORP) == 0)
continue; continue;
shells = sub.shp_item[I_SHELL]; shells = sub.shp_item[I_SHELL];
if (shells < 3) if (shells < M_TORP_SHELLS)
shells += shells += supply_commod(sub.shp_own, sub.shp_x, sub.shp_y,
supply_commod(sub.shp_own, sub.shp_x, sub.shp_y, I_SHELL, I_SHELL, M_TORP_SHELLS - shells);
3 - shells); if (sub.shp_item[I_GUN] == 0 || shells < M_TORP_SHELLS)
if (sub.shp_item[I_GUN] == 0 || shells < 3)
continue; continue;
if (sub.shp_item[I_MILIT] < 1) if (sub.shp_item[I_MILIT] < 1)
continue; continue;
@ -116,11 +115,10 @@ torp(void)
continue; continue;
} }
shells = sub.shp_item[I_SHELL]; shells = sub.shp_item[I_SHELL];
if (shells < 3) if (shells < M_TORP_SHELLS)
shells += shells += supply_commod(sub.shp_own, sub.shp_x, sub.shp_y,
supply_commod(sub.shp_own, sub.shp_x, sub.shp_y, I_SHELL, I_SHELL, M_TORP_SHELLS - shells);
3 - shells); if (sub.shp_item[I_GUN] == 0 || shells < M_TORP_SHELLS) {
if (sub.shp_item[I_GUN] == 0 || shells < 3) {
pr("Ship #%d has insufficient armament\n", sub.shp_uid); pr("Ship #%d has insufficient armament\n", sub.shp_uid);
continue; continue;
} }
@ -169,7 +167,7 @@ torp(void)
techfact(sub.shp_tech, ((double)sub.shp_frnge)); techfact(sub.shp_tech, ((double)sub.shp_frnge));
erange = (double)roundrange(erange); erange = (double)roundrange(erange);
pr("Effective torpedo range is %.1f\n", erange); pr("Effective torpedo range is %.1f\n", erange);
shells -= 3; shells -= M_TORP_SHELLS;
sub.shp_item[I_SHELL] = shells; sub.shp_item[I_SHELL] = shells;
putship(sub.shp_uid, &sub); putship(sub.shp_uid, &sub);
mcp = &mchr[(int)sub.shp_type]; mcp = &mchr[(int)sub.shp_type];
@ -409,11 +407,11 @@ fire_torp(struct shpstr *sp, struct shpstr *targ, int range, int ntargets)
shells = sp->shp_item[I_SHELL]; shells = sp->shp_item[I_SHELL];
if (shells < 3) if (shells < M_TORP_SHELLS)
shells += supply_commod(sp->shp_own, sp->shp_x, sp->shp_y, I_SHELL, shells += supply_commod(sp->shp_own, sp->shp_x, sp->shp_y, I_SHELL,
3 - shells); M_TORP_SHELLS - shells);
if (sp->shp_item[I_GUN] == 0 || shells < 3) if (sp->shp_item[I_GUN] == 0 || shells < M_TORP_SHELLS)
return 0; return 0;
if (sp->shp_item[I_MILIT] < 1) if (sp->shp_item[I_MILIT] < 1)
@ -426,7 +424,7 @@ fire_torp(struct shpstr *sp, struct shpstr *targ, int range, int ntargets)
return 0; return 0;
/* All set.. fire! */ /* All set.. fire! */
shells -= 3; shells -= M_TORP_SHELLS;
sp->shp_item[I_SHELL] = shells; sp->shp_item[I_SHELL] = shells;
putship(sp->shp_uid, sp); putship(sp->shp_uid, sp);

View file

@ -562,11 +562,11 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
if (gun < 1) if (gun < 1)
continue; continue;
shell = sp->shp_item[I_SHELL]; shell = sp->shp_item[I_SHELL];
if (shell < 3) if (shell < M_TORP_SHELLS)
shell += supply_commod(sp->shp_own, shell += supply_commod(sp->shp_own,
sp->shp_x, sp->shp_y, I_SHELL, sp->shp_x, sp->shp_y, I_SHELL,
3 - shell); M_TORP_SHELLS - shell);
if (shell < 3) if (shell < M_TORP_SHELLS)
continue; continue;
range = sp->shp_effic * techfact(sp->shp_tech, range = sp->shp_effic * techfact(sp->shp_tech,
@ -579,7 +579,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
if (!line_of_sight((s_char **)0, x, y, gp->x, gp->y)) if (!line_of_sight((s_char **)0, x, y, gp->x, gp->y))
continue; continue;
sp->shp_item[I_SHELL] = shell - 3; sp->shp_item[I_SHELL] = shell - M_TORP_SHELLS;
mobcost = sp->shp_effic * 0.01 * sp->shp_speed; mobcost = sp->shp_effic * 0.01 * sp->shp_speed;
mobcost = (480.0 / (mobcost + mobcost = (480.0 / (mobcost +
techfact(sp->shp_tech, mobcost))); techfact(sp->shp_tech, mobcost)));