From ad296698f92ce00f14cd1f181f5791a5dde15272 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 1 Aug 2009 18:34:20 -0400 Subject: [PATCH] Factor new lnd_sabo() out of sabo() This permits giving seagun(), fortgun() and landunitgun() internal linkage. --- include/land.h | 1 + include/prototypes.h | 3 --- src/lib/commands/sabo.c | 11 +++-------- src/lib/subs/landgun.c | 31 ++++++++++++++++++++++++++++--- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/include/land.h b/include/land.h index 6f5232ff..5f8bbb9a 100644 --- a/include/land.h +++ b/include/land.h @@ -165,6 +165,7 @@ extern int lnd_nxlight(struct lndstr *); extern int lnd_nland(struct lndstr *); extern int lnd_fire(struct lndstr *); +extern int lnd_sabo(struct lndstr *, short *); extern double lnd_fire_range(struct lndstr *); /* src/lib/subs/lndsub.c */ diff --git a/include/prototypes.h b/include/prototypes.h index 9cc98f7a..5f7ad297 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -454,9 +454,6 @@ extern void lnd_oninit(void *); extern void lnd_postread(int, void *); extern void lnd_prewrite(int, void *, void *); /* landgun.c */ -extern double seagun(int, int); -extern double fortgun(int, int); -extern double landunitgun(int, int); extern double torprange(struct shpstr *); extern double fortrange(struct sctstr *); extern int roundrange(double); diff --git a/src/lib/commands/sabo.c b/src/lib/commands/sabo.c index e8af7df0..51cae85a 100644 --- a/src/lib/commands/sabo.c +++ b/src/lib/commands/sabo.c @@ -69,7 +69,6 @@ sabo(void) pr("%s has no shells.\n", prland(&land)); continue; } - --land.lnd_item[I_SHELL]; odds = LND_SPY_DETECT_CHANCE(land.lnd_effic); if (chance(odds)) { @@ -83,13 +82,9 @@ sabo(void) continue; } - dam = fortgun(3 * land.lnd_effic, 7); - if (sect.sct_item[I_SHELL] > 20) - dam += seagun(land.lnd_effic, - random() % (sect.sct_item[I_SHELL] / 10)); - if (sect.sct_item[I_PETROL] > 100) - dam += seagun(land.lnd_effic, - random() % (sect.sct_item[I_PETROL] / 50)); + dam = lnd_sabo(&land, sect.sct_item); + if (dam < 0) + continue; pr("Explosion in %s causes %d damage.\n", xyas(land.lnd_x, land.lnd_y, land.lnd_own), dam); diff --git a/src/lib/subs/landgun.c b/src/lib/subs/landgun.c index cd4298cd..714af4b2 100644 --- a/src/lib/subs/landgun.c +++ b/src/lib/subs/landgun.c @@ -42,7 +42,7 @@ #include "sect.h" #include "ship.h" -double +static double fortgun(int effic, int guns) { double d; @@ -53,7 +53,7 @@ fortgun(int effic, int guns) return d; } -double +static double seagun(int effic, int guns) { double d; @@ -65,7 +65,7 @@ seagun(int effic, int guns) return d; } -double +static double landunitgun(int effic, int guns) { double d; @@ -202,6 +202,31 @@ lnd_fire(struct lndstr *lp) return d; } +/* + * Sabotage with land unit LP. + * Use ammo. + * Return damage if the land unit sabotages, else -1. + */ +int +lnd_sabo(struct lndstr *lp, short item[]) +{ + int dam; + + if (lp->lnd_ship >= 0 || lp->lnd_land >= 0) + return -1; + if (!(lchr[lp->lnd_type].l_flags & L_SPY)) + return -1; + if (!lp->lnd_item[I_SHELL]) + return -1; + lp->lnd_item[I_SHELL]--; + dam = fortgun(3 * lp->lnd_effic, 7); + if (item[I_SHELL] > 20) + dam += seagun(lp->lnd_effic, random() % (item[I_SHELL] / 10)); + if (item[I_PETROL] > 100) + dam += seagun(lp->lnd_effic, random() % (item[I_PETROL] / 50)); + return dam; +} + /* * Return number of guns ship SP can fire. */