/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
* Known contributors to this file:
* Ken Stevens, 1995
* Steve McClure, 1996-2000
- * Markus Armbruster, 2003-2009
+ * Markus Armbruster, 2003-2011
*/
#include <config.h>
#include "item.h"
#include "misc.h"
#include "mission.h"
+#include "news.h"
#include "nsc.h"
#include "optlist.h"
#include "path.h"
-#include "player.h"
#include "prototypes.h"
#include "queue.h"
#include "xy.h"
static void add_airport(struct emp_qelem *, coord, coord);
static int air_damage(struct emp_qelem *, coord, coord, int, natid,
char *, int);
-static void build_mission_list(struct genlist *, coord, coord, int, natid);
-static void build_mission_list_type(struct genlist *, coord, coord, int,
- int, natid);
+static void build_mission_list(struct genlist[],
+ unsigned char[], unsigned char[],
+ coord, coord, int);
+static void build_mission_list_type(struct genlist[], unsigned char[],
+ coord, coord, int, int);
static void divide(struct emp_qelem *, struct emp_qelem *, coord, coord);
static int dosupport(coord, coord, natid, natid, int);
static int find_airport(struct emp_qelem *, coord, coord);
ground_interdict(coord x, coord y, natid victim, char *s)
{
int cn;
- int dam = 0, newdam, rel;
+ int dam = 0, newdam;
+ unsigned char act[MAXNOC];
struct genlist mi[MAXNOC];
memset(mi, 0, sizeof(mi));
- for (cn = 1; cn < MAXNOC; cn++)
+ act[0] = 0;
+ for (cn = 1; cn < MAXNOC; cn++) {
+ act[cn] = relations_with(cn, victim) <= HOSTILE;
emp_initque((struct emp_qelem *)&mi[cn]);
+ }
- build_mission_list(mi, x, y, MI_INTERDICT, victim);
+ build_mission_list(mi, act, act, x, y, MI_INTERDICT);
for (cn = 1; cn < MAXNOC; cn++) {
- rel = getrel(getnatp(cn), victim);
- if (rel > HOSTILE)
- continue;
-
if (QEMPTY(&mi[cn].queue))
continue;
unit_interdict(coord x, coord y, natid victim, char *s, int hardtarget,
int mission)
{
- int cn, newdam, osubs;
+ int cn, rel, newdam, osubs;
int dam = -1;
+ unsigned char plane_act[MAXNOC], other_act[MAXNOC];
struct genlist mi[MAXNOC];
memset(mi, 0, sizeof(mi));
- for (cn = 1; cn < MAXNOC; cn++)
+ other_act[0] = plane_act[0] = 0;
+ for (cn = 1; cn < MAXNOC; cn++) {
+ rel = relations_with(cn, victim);
+ other_act[cn] = rel <= HOSTILE;
+ plane_act[cn] = mission == MI_SINTERDICT
+ ? rel <= NEUTRAL : other_act[cn];
emp_initque((struct emp_qelem *)&mi[cn]);
+ }
- build_mission_list(mi, x, y, mission, victim);
+ build_mission_list(mi, other_act, plane_act, x, y, mission);
for (cn = 1; cn < MAXNOC; cn++) {
- if (cn == victim)
- continue;
- if (mission == MI_SINTERDICT) {
- if (getrel(getnatp(cn), victim) >= FRIENDLY)
- continue;
- } else if (getrel(getnatp(cn), victim) > HOSTILE)
- continue;
-
if (QEMPTY(&mi[cn].queue))
continue;
return dosupport(x, y, victim, actee, MI_DSUPPORT);
}
+/*
+ * Perform support missions in X,Y against VICTIM for ACTEE.
+ * MISSION is either MI_OSUPPORT or MI_DSUPPORT.
+ * Return total damage.
+ */
static int
dosupport(coord x, coord y, natid victim, natid actee, int mission)
{
int cn;
+ unsigned char act[MAXNOC];
struct genlist mi[MAXNOC];
- int rel, newdam;
+ int newdam;
int dam = 0;
memset(mi, 0, sizeof(mi));
- for (cn = 1; cn < MAXNOC; cn++)
+ act[0] = 0;
+ for (cn = 1; cn < MAXNOC; cn++) {
+ act[cn] = feels_like_helping(cn, actee, victim);
emp_initque((struct emp_qelem *)&mi[cn]);
+ }
- build_mission_list(mi, x, y, MI_SUPPORT, victim);
- build_mission_list(mi, x, y, mission, victim);
+ build_mission_list(mi, act, act, x, y, MI_SUPPORT);
+ build_mission_list(mi, act, act, x, y, mission);
for (cn = 1; cn < MAXNOC; cn++) {
- rel = getrel(getnatp(cn), actee);
- if ((cn != actee) && (rel != ALLIED))
- continue;
- rel = getrel(getnatp(cn), victim);
- if ((cn != actee) && (rel != AT_WAR))
- continue;
-
if (QEMPTY(&mi[cn].queue))
continue;
}
static void
-build_mission_list(struct genlist *mi, coord x, coord y, int mission,
- natid victim)
+build_mission_list(struct genlist mi[],
+ unsigned char other_act[], unsigned char plane_act[],
+ coord x, coord y, int mission)
{
- build_mission_list_type(mi, x, y, mission, EF_LAND, victim);
- build_mission_list_type(mi, x, y, mission, EF_SHIP, victim);
- build_mission_list_type(mi, x, y, mission, EF_PLANE, victim);
+ build_mission_list_type(mi, other_act, x, y, mission, EF_LAND);
+ build_mission_list_type(mi, other_act, x, y, mission, EF_SHIP);
+ build_mission_list_type(mi, plane_act, x, y, mission, EF_PLANE);
}
static void
-build_mission_list_type(struct genlist *mi, coord x, coord y, int mission,
- int type, natid victim)
+build_mission_list_type(struct genlist mi[], unsigned char act[],
+ coord x, coord y, int mission, int type)
{
struct nstr_item ni;
struct genlist *glp;
struct empobj *gp;
union empobj_storage item;
- int relat;
snxtitem_all(&ni, type);
while (nxtitem(&ni, &item)) {
gp = (struct empobj *)&item;
- if (gp->own == 0)
+ if (!act[gp->own])
continue;
if (gp->mobil < 1)
(gp->mission != MI_INTERDICT))
continue;
- relat = getrel(getnatp(gp->own), victim);
- if (mission == MI_SINTERDICT) {
- if (relat >= FRIENDLY)
- continue;
- else if (type != EF_PLANE && relat > HOSTILE)
- continue;
- } else if (relat > HOSTILE)
- continue;
-
if (!in_oparea(gp, x, y))
continue;
targeting_ships);
} else if (glp->thing->ef_type == EF_PLANE) {
pcp = &plchr[glp->thing->type];
- if (pcp->pl_flags & P_M)
- /* units have their own missile interdiction */
- if (hardtarget != SECT_HARDTARGET || pcp->pl_flags & P_MAR)
- continue;
-
- /* save planes for later */
- plp = malloc(sizeof(struct plist));
-
- memset(plp, 0, sizeof(struct plist));
- plp->pcp = pcp;
- memcpy(&plp->plane, glp->thing, sizeof(struct plnstr));
- if (plp->pcp->pl_flags & P_M)
- emp_insque(&plp->queue, &missiles);
- else
- emp_insque(&plp->queue, &bombers);
+ if ((pcp->pl_flags & P_M)
+ && (hardtarget != SECT_HARDTARGET
+ || (pcp->pl_flags & P_MAR)))
+ ; /* units have their own missile interdiction */
+ else {
+ /* save planes for later */
+ plp = malloc(sizeof(struct plist));
+
+ memset(plp, 0, sizeof(struct plist));
+ plp->pcp = pcp;
+ memcpy(&plp->plane, glp->thing, sizeof(struct plnstr));
+ if (plp->pcp->pl_flags & P_M)
+ emp_insque(&plp->queue, &missiles);
+ else
+ emp_insque(&plp->queue, &bombers);
+ }
} else {
CANT_REACH();
break;
{
struct emp_qelem *qp, *newqp, escorts, airp, b, e;
struct plist *plp;
- int plane_owner, performed, air_dam, md;
+ int plane_owner, performed, air_dam;
+ size_t md;
emp_initque(&escorts);
emp_initque(&airp);
performed = air_dam = 0;
for (qp = airp.q_forw; qp != (&airp); qp = qp->q_forw) {
struct airport *air;
- char buf[512];
- char *pp;
+ char buf[1024];
air = (struct airport *)qp;
- md = mapdist(x, y, air->x, air->y);
emp_initque(&b);
emp_initque(&e);
/* Split off the escorts at this base into e */
divide(&escorts, &e, air->x, air->y);
- mission_pln_arm(&b, air->x, air->y, 2 * md, 'p', NULL);
+ if (path_find(air->x, air->y, x, y, plane_owner, MOB_FLY) < 0)
+ continue;
+ md = path_find_route(buf, sizeof(buf), air->x, air->y, x, y);
+ if (md >= sizeof(buf))
+ continue;
+ mission_pln_arm(&b, air->x, air->y, 2 * md, 'p', NULL);
if (QEMPTY(&b))
continue;
-
mission_pln_arm(&e, air->x, air->y, 2 * md, 'e', NULL);
- pp = BestAirPath(buf, air->x, air->y, x, y);
- if (CANT_HAPPEN(!pp))
- continue;
performed = 1;
wu(0, plane_owner, "Flying %s mission from %s to %s\n",
mission_name(mission),
xyas(x, y, air->own));
}
- ac_encounter(&b, &e, air->x, air->y, pp, 0);
+ ac_encounter(&b, &e, air->x, air->y, buf, 0);
if (!QEMPTY(&b))
air_dam +=
prplane(pp), xyas(x, y, pp->pln_own));
continue;
}
- if (getrel(getnatp(pp->pln_own), victim) > HOSTILE) {
+ if (relations_with(pp->pln_own, victim) > HOSTILE) {
wu(0, pp->pln_own,
"\t%s tracks %s %s at %s\n",
prplane(pp), cname(victim), s, xyas(x, y, pp->pln_own));