/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* Dave Pare, 1986
* Thomas Ruschak, 1992
* Steve McClure, 1996
+ * Markus Armbruster, 2006
*/
#include <config.h>
-#include <string.h>
-
-#include "misc.h"
-#include "player.h"
-#include "news.h"
+#include "file.h"
#include "land.h"
-#include "sect.h"
-#include "plane.h"
-#include "ship.h"
+#include "map.h"
+#include "misc.h"
#include "nat.h"
-#include "file.h"
-#include "xy.h"
+#include "news.h"
#include "nsc.h"
+#include "optlist.h"
#include "path.h"
+#include "plane.h"
+#include "player.h"
#include "prototypes.h"
-#include "optlist.h"
+#include "sect.h"
#include "server.h"
+#include "ship.h"
+#include "xy.h"
+
+#define FLAK_GUN_MAX 14
static void ac_intercept(struct emp_qelem *, struct emp_qelem *,
struct emp_qelem *, natid, coord, coord);
static void ac_doflak(struct emp_qelem *, struct sctstr *);
static void ac_landflak(struct emp_qelem *, coord, coord);
static void ac_shipflak(struct emp_qelem *, coord, coord);
-static void ac_fireflak(struct emp_qelem *, natid, natid, int);
+static void ac_fireflak(struct emp_qelem *, natid, int);
static void getilist(struct emp_qelem *, natid,
struct emp_qelem *, struct emp_qelem *,
struct emp_qelem *, struct emp_qelem *);
sect.sct_x, sect.sct_y,
dchr[sect.sct_type].d_mnem, 0);
} else if (mission_flags & P_S) {
- satdisp(§, (mission_flags & P_I) ? 10 : 50, 1);
+ satdisp_sect(§, (mission_flags & P_I) ? 10 : 50);
} else {
/* This is borrowed from lookout */
if (sect.sct_own == plane_owner)
mil : roundintby(mil, 25));
PR(plane_owner, "@ %s\n", xyas(x, y, plane_owner));
}
+ if (mission_flags & P_S)
+ satdisp_units(sect.sct_x, sect.sct_y);
} else {
PR(plane_owner, "flying over %s at %s\n",
dchr[sect.sct_type].d_name, xyas(x, y, plane_owner));
if (eff < PLANE_MINEFF) {
sprintf(dmess, " shot down");
disp = 1;
- } else if (eff < 80 && chance((100 - eff) / 100.0) && checkabort) {
+ } else if (eff < 80 && chance((80 - eff) / 100.0) && checkabort) {
sprintf(dmess, " aborted @%2d%%", eff);
disp = 2;
} else if (show == 0) {
getland(pp->pln_land, &land);
take_plane_off_land(pp, &land);
}
- makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
- pp->pln_own = 0;
+ pp->pln_effic = 0;
putplane(pp->pln_uid, pp);
emp_remque(&plp->queue);
free(plp);
plp = (struct plist *)list->q_forw;
plane_owner = plp->plane.pln_own;
- gun = from->sct_item[I_GUN];
+ gun = MIN(FLAK_GUN_MAX, from->sct_item[I_GUN]);
shell = from->sct_item[I_SHELL];
- if (gun > 14)
- gun = 14;
if (gun > shell * 2) {
shell += supply_commod(from->sct_own, from->sct_x, from->sct_y,
I_SHELL, (gun + 1) / 2 - shell);
if (gun > shell * 2)
gun = shell * 2;
- gun = 2.0 * tfact(from->sct_own, gun);
+ gun = roundavg(tfact(from->sct_own, 2.0 * gun));
if (gun > 0) {
PR(plane_owner, "firing %d flak guns in %s...\n",
gun, xyas(from->sct_x, from->sct_y, plane_owner));
if (from->sct_own != 0)
PR(from->sct_own, "firing %d flak guns in %s...\n",
gun, xyas(from->sct_x, from->sct_y, from->sct_own));
- ac_fireflak(list, from->sct_own, 0, gun);
+ ac_fireflak(list, from->sct_own, gun);
}
}
struct nstr_item ni;
struct shpstr ship;
struct mchrstr *mcp;
- int firing;
- int guns;
- int gun;
- int shell;
+ double flak, total, ngun;
+ int gun, shell;
int rel;
struct plist *plp;
natid plane_owner;
plane_owner = plp->plane.pln_own;
memset(nats, 0, sizeof(nats));
- guns = 0;
+ total = ngun = 0;
snxtitem_xy(&ni, EF_SHIP, x, y);
while (!QEMPTY(list) && nxtitem(&ni, &ship)) {
if (ship.shp_own == 0 || ship.shp_own == plane_owner)
continue;
- if (guns >= 14)
- break;
mcp = &mchr[(int)ship.shp_type];
if (mcp->m_flags & M_SUB)
continue;
}
if (gun == 0 || shell == 0)
continue;
- firing = (int)(techfact(ship.shp_tech, gun) * 2.0);
- guns += firing;
+ flak = gun * (ship.shp_effic / 100.0);
+ ngun += flak;
+ total += techfact(ship.shp_tech, flak * 2.0);
if (!nats[ship.shp_own]) {
/* First time here, print the message */
cname(ship.shp_own), xyas(x, y, plane_owner));
nats[ship.shp_own] = 1;
}
- PR(ship.shp_own, "firing %d flak guns from %s...\n",
- firing, prship(&ship));
+ PR(ship.shp_own, "firing %.0f flak guns from %s...\n",
+ flak, prship(&ship));
from = ship.shp_own;
}
- if (guns > 0) {
- if (guns > 14)
- guns = 14;
- guns = 2.0 * tfact(from, guns);
- PR(plane_owner, "Flak! Ships firing %d flak guns...\n", guns);
- ac_fireflak(list, from, 0, guns);
+
+ /* Limit to FLAK_GUN_MAX guns of average tech factor */
+ if (ngun > FLAK_GUN_MAX)
+ total *= FLAK_GUN_MAX / ngun;
+
+ gun = roundavg(total);
+ if (gun > 0) {
+ PR(plane_owner, "Flak! Ships firing %d flak guns...\n", gun);
+ ac_fireflak(list, from, gun);
}
}
struct nstr_item ni;
struct lndstr land;
struct lchrstr *lcp;
- int firing;
- int guns;
+ double flak, total, ngun;
+ int gun;
int rel;
- natid from;
struct plist *plp;
natid plane_owner;
+ natid from;
int nats[MAXNOC];
plp = (struct plist *)list->q_forw;
plane_owner = plp->plane.pln_own;
memset(nats, 0, sizeof(nats));
- guns = 0;
+ total = ngun = 0;
snxtitem_xy(&ni, EF_LAND, x, y);
while (!QEMPTY(list) && nxtitem(&ni, &land)) {
if (land.lnd_own == 0 || land.lnd_own == plane_owner)
continue;
- if (guns >= 14)
- break;
lcp = &lchr[(int)land.lnd_type];
-
- if ((lcp->l_flags & L_FLAK) == 0)
+ if ((lcp->l_flags & L_FLAK) == 0 || land.lnd_aaf == 0)
continue;
-
- if (land.lnd_aaf == 0)
- continue;
-
if (land.lnd_ship >= 0 || land.lnd_land >= 0)
continue;
-
rel = getrel(getnatp(land.lnd_own), plane_owner);
if (rel > HOSTILE)
continue;
- firing = (int)(techfact(land.lnd_tech, land.lnd_aaf) * 3.0);
- guns += firing;
+ flak = land.lnd_aaf * 1.5 * land.lnd_effic / 100.0;
+ ngun += flak;
+ total += techfact(land.lnd_tech, flak * 2.0);
if (!nats[land.lnd_own]) {
/* First time here, print the message */
}
PR(land.lnd_own, "firing flak guns from unit %s (aa rating %d)\n",
prland(&land), land.lnd_aaf);
-
- from = land.lnd_own; /* We always use the last owner as the from */
+ from = land.lnd_own;
}
- if (guns > 0) {
- if (guns > 14)
- guns = 14;
- guns = 2.0 * tfact(from, guns);
- PR(plane_owner, "Flak! Land units firing %d flak guns...\n",
- guns);
- ac_fireflak(list, from, 0, guns);
+
+ /* Limit to FLAK_GUN_MAX guns of average tech factor */
+ if (ngun > FLAK_GUN_MAX)
+ total *= FLAK_GUN_MAX / ngun;
+
+ gun = roundavg(total);
+ if (gun > 0) {
+ PR(plane_owner, "Flak! Land units firing %d flak guns...\n", gun);
+ ac_fireflak(list, from, gun);
}
}
* Called from shipflak, landflak, and doflak.
*/
static void
-ac_fireflak(struct emp_qelem *list, natid from, natid other, int guns)
+ac_fireflak(struct emp_qelem *list, natid from, int guns)
{
- struct plnstr *pp;
struct plist *plp;
int n;
- int diff;
struct emp_qelem *qp;
struct emp_qelem *next;
char msg[255];
plp = (struct plist *)list->q_forw;
for (qp = list->q_forw; qp != list; qp = next) {
- /*
- * fighters don't get shot at by flak
- * non-tactical bombers are harder to hit with flak.
- * ('Cause they're not dive-bombing?)
- */
next = qp->q_forw;
plp = (struct plist *)qp;
- pp = &plp->plane;
- diff = guns - pp->pln_def;
- if ((plp->pcp->pl_flags & P_T) == 0)
- diff--;
- if (plp->pcp->pl_flags & P_X)
- diff -= 2;
- if (plp->pcp->pl_flags & P_H)
- diff -= 1;
- n = ac_flak_dam(diff);
- ac_planedamage(plp, from, n, other, 2, 1, msg);
+ n = ac_flak_dam(guns, plp->plane.pln_def, plp->pcp->pl_flags);
+ ac_planedamage(plp, from, n, 0, 2, 1, msg);
}
}
* Calculate flak damage
*/
int
-ac_flak_dam(int flak)
+ac_flak_dam(int guns, int def, int pl_flags)
{
- int dam;
+ int flak, dam;
float mult;
/* <-7 -7 -6 -5 -4 */
static float flaktable[18] = { 0.132f, 0.20f, 0.20f, 0.25f, 0.30f,
0.70f,0.75f, 0.80f, 0.85f, 1.1305f };
enum { FLAK_MAX = sizeof(flaktable)/sizeof(flaktable[0]) - 1 };
+ flak = guns - def;
+ if ((pl_flags & P_T) == 0)
+ flak--;
+ if (pl_flags & P_X)
+ flak -= 2;
+ if (pl_flags & P_H)
+ flak -= 1;
+
if (flak > 8)
mult = flaktable[FLAK_MAX];
else if (flak < -7)