/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* ---
*
* multifire.c: Fire at other sectors/ships
- *
+ *
* Known contributors to this file:
* Steve McClure, 2000
- * Markus Armbruster, 2004-2008
+ * Markus Armbruster, 2004-2009
*/
#include <config.h>
struct flist {
struct emp_qelem queue; /* list of fired things */
short type; /* EF_SECTOR, EF_SHIP or EF_LAND */
- short uid;
+ int uid;
coord x, y;
int defdam; /* damage defenders did */
natid victim;
coord fy;
coord x;
coord y;
- int mil;
int dam;
int totaldefdam = 0;
int vshipno;
struct shpstr vship;
struct sctstr vsect;
enum targ_type target;
- int rel;
- struct natstr *natp;
struct nstr_item nbst;
int type;
struct empobj *attgp;
emp_initque(&fired);
emp_initque(&defended);
- if (!(p = getstarg(player->argp[1],
- "Firing from ship(s), sect(s), or land unit(s)? ",
- buf)))
+ p = getstarg(player->argp[1],
+ "Firing from ship(s), sect(s), or land unit(s)? ", buf);
+ if (!p)
return RET_SYN;
type = ef_byname_from(p, ef_with_guns);
if (opt_NO_FORT_FIRE && type == EF_SECTOR) {
pr("Ships, land units or sectors only!\n");
return RET_SYN;
}
- if ((ptr = getstarg(player->argp[2], "Firing from? ", buf)) == 0
- || *ptr == '\0')
- return RET_SYN;
-
- if (!snxtitem(&nbst, type, ptr))
+ if (!snxtitem(&nbst, type, player->argp[2], "Firing from? "))
return RET_SYN;
while (nxtitem(&nbst, &item)) {
ptr = getstarg(player->argp[3], "Firing at? ", buf);
if (!ptr)
- return RET_SYN;
+ return RET_FAIL;
if (!*ptr)
continue;
if (!issector(ptr)) {
continue;
}
}
- if ((mil = fship.shp_item[I_MILIT]) < 1) {
+ if (fship.shp_item[I_MILIT] < 1) {
pr("Not enough military for firing crew.\n");
continue;
}
break;
}
- if (opt_SLOW_WAR) {
- if (target == targ_land) {
- natp = getnatp(player->cnum);
- rel = getrel(natp, vict);
- if ((rel != AT_WAR) && (player->cnum != vict) &&
- (vict) && (vsect.sct_oldown != player->cnum)) {
- pr("You're not at war with them!\n");
- continue;
- }
- }
- }
nfiring++;
switch (target) {
case targ_sub:
putship(vship.shp_uid, &vship);
break;
}
- if ((totaldefdam == 0) && (target == targ_ship))
- if (vship.shp_rflags & RET_HELPLESS)
- retreat_ship(&vship, 'h');
+ if (totaldefdam == 0 && target == targ_ship
+ && (vship.shp_rflags & RET_HELPLESS)
+ && !(vship.shp_rflags & RET_INJURED))
+ retreat_ship(&vship, 'h');
switch (attgp->ef_type) {
case EF_SECTOR:
putsect(&fsect);
struct shpstr ship;
struct lndstr land;
struct nstr_item ni;
- int dam, dam2, rel, rel2;
+ int dam, dam2;
struct sctstr firing;
struct nstr_sect ns;
struct flist *fp;
dam = 0;
snxtitem_dist(&ni, EF_SHIP, ax, ay, 8);
while (nxtitem(&ni, &ship)) {
- if (ship.shp_own == 0)
+ if (!feels_like_helping(ship.shp_own, own, aown))
continue;
if ((mchr[ship.shp_type].m_flags & M_SUB) && type != EF_SHIP)
continue;
- rel = getrel(getnatp(ship.shp_own), own);
- rel2 = getrel(getnatp(ship.shp_own), aown);
- if ((ship.shp_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR)))
- continue;
- /* Don't shoot yourself */
- if (ship.shp_own == aown)
- continue;
if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
erange = torprange(&ship);
if (roundrange(erange) < ni.curdist)
}
snxtitem_dist(&ni, EF_LAND, ax, ay, 8);
while (nxtitem(&ni, &land)) {
- if (land.lnd_own == 0)
- continue;
- /* Don't shoot yourself */
- if (land.lnd_own == aown)
- continue;
-
- rel = getrel(getnatp(land.lnd_own), own);
- rel2 = getrel(getnatp(land.lnd_own), aown);
-
- if ((land.lnd_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR)))
+ if (!feels_like_helping(land.lnd_own, own, aown))
continue;
erange = lnd_fire_range(&land);
if (!opt_NO_FORT_FIRE) {
snxtsct_dist(&ns, ax, ay, 8);
while (nxtsct(&ns, &firing)) {
- if (firing.sct_own == 0)
+ if (!feels_like_helping(firing.sct_own, own, aown))
continue;
- rel = getrel(getnatp(firing.sct_own), own);
- rel2 = getrel(getnatp(firing.sct_own), aown);
- if ((firing.sct_own != own) &&
- ((rel != ALLIED) || (rel2 != AT_WAR)))
- continue;
- /* Don't shoot yourself */
- if (firing.sct_own == aown)
- continue;
erange = fortrange(&firing);
if (roundrange(erange) < ns.curdist)
continue;