/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
static int shp_hit_mine(struct shpstr *);
static void shp_stays(natid, char *, struct ulist *);
+static struct ulist *
+shp_find_capable(struct emp_qelem *list, int flags)
+{
+ struct emp_qelem *qp;
+ struct ulist *mlp;
+
+ for (qp = list->q_back; qp != list; qp = qp->q_back) {
+ mlp = (struct ulist *)qp;
+ if (mchr[mlp->unit.ship.shp_type].m_flags & flags)
+ return mlp;
+ }
+ return NULL;
+}
+
void
shp_sel(struct nstr_item *ni, struct emp_qelem *list)
{
{
struct ulist *mlp = malloc(sizeof(struct ulist));
- mlp->chrp = (struct empobj_chr *)&mchr[sp->shp_type];
mlp->unit.ship = *sp;
mlp->mobil = sp->shp_mobil;
emp_insque(&mlp->queue, list);
free(mlp);
}
+/*
+ * Sweep seamines with engineers in SHIP_LIST for ACTOR.
+ * All ships in SHIP_LIST must be in the same sector.
+ * If EXPLICIT is non-zero, this is for an explicit sweep command from
+ * a player. Else it's an automatic "on the move" sweep.
+ * If TAKEMOB is non-zero, require and charge mobility.
+ * Return non-zero when the ships should stop.
+ */
int
-shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor)
+shp_sweep(struct emp_qelem *ship_list, int explicit, int takemob,
+ natid actor)
{
struct emp_qelem *qp;
struct emp_qelem *next;
struct sctstr sect;
int mines, m, max, shells;
int changed = 0;
- int stopping = 0;
+ int stopping = 0, first = 1;
+
+ mlp = shp_find_capable(ship_list, M_SWEEP);
+ if (!mlp) {
+ if (explicit)
+ mpr(actor, "No minesweepers!\n");
+ return 0;
+ }
+
+ getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, §);
+ if (sect.sct_type != SCT_WATER) {
+ if (explicit)
+ mpr(actor, "%s is a %s. No seamines there!\n",
+ xyas(sect.sct_x, sect.sct_y, actor),
+ dchr[sect.sct_type].d_name);
+ return 0;
+ }
for (qp = ship_list->q_back; qp != ship_list; qp = next) {
next = qp->q_back;
mlp = (struct ulist *)qp;
- if (!(((struct mchrstr *)mlp->chrp)->m_flags & M_SWEEP)) {
- if (verbose)
- mpr(actor, "%s doesn't have minesweeping capability!\n",
- prship(&mlp->unit.ship));
- continue;
- }
- if (takemob && mlp->mobil <= 0.0) {
- if (verbose)
- mpr(actor, "%s is out of mobility!\n",
- prship(&mlp->unit.ship));
+ if (!(mchr[mlp->unit.ship.shp_type].m_flags & M_SWEEP))
continue;
- }
- getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, §);
- if (sect.sct_type != SCT_WATER) {
- if (verbose)
- mpr(actor, "%s is not at sea. No mines there!\n",
- prship(&mlp->unit.ship));
- continue;
- }
if (takemob) {
+ if (mlp->mobil <= 0.0) {
+ if (explicit)
+ mpr(actor, "%s is out of mobility!\n",
+ prship(&mlp->unit.ship));
+ continue;
+ }
mlp->mobil -= shp_mobcost(&mlp->unit.ship);
mlp->unit.ship.shp_mobil = (int)mlp->mobil;
}
putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
+ getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, §);
if (!(mines = sect.sct_mines))
continue;
- max = ((struct mchrstr *)mlp->chrp)->m_item[I_SHELL];
+ max = mchr[mlp->unit.ship.shp_type].m_item[I_SHELL];
shells = mlp->unit.ship.shp_item[I_SHELL];
for (m = 0; mines > 0 && m < 5; m++) {
if (chance(0.66)) {
+ if (first) {
+ mpr(actor, "Approaching minefield at %s...\n",
+ xyas(sect.sct_x, sect.sct_y, actor));
+ first = 0;
+ }
mpr(actor, "Sweep...\n");
mines--;
shells = MIN(max, shells + 1);
if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
continue;
if (wantflags &&
- (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
+ (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
continue;
if (nowantflags &&
- ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
+ mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
continue;
++count;
}
if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
continue;
if (wantflags &&
- (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
+ (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
continue;
if (nowantflags &&
- ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
+ mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
continue;
shp_damage_one(mlp, dam);
}
if (newx != mlp->unit.ship.shp_x || newy != mlp->unit.ship.shp_y)
continue;
if (wantflags &&
- (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
+ (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
continue;
if (nowantflags &&
- ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
+ mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
continue;
return 1;
}
mlp = (struct ulist *)qp;
if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
continue;
- if (((struct mchrstr *)mlp->chrp)->m_flags & M_SUB)
+ if (mchr[mlp->unit.ship.shp_type].m_flags & M_SUB)
continue;
- if (!((struct mchrstr *)mlp->chrp)->m_nxlight &&
- !((struct mchrstr *)mlp->chrp)->m_nchoppers &&
- ((struct mchrstr *)mlp->chrp)->m_cost < 1000 &&
- !((struct mchrstr *)mlp->chrp)->m_nplanes &&
- !((struct mchrstr *)mlp->chrp)->m_nland)
+ if (!mchr[mlp->unit.ship.shp_type].m_nxlight &&
+ !mchr[mlp->unit.ship.shp_type].m_nchoppers &&
+ mchr[mlp->unit.ship.shp_type].m_cost < 1000 &&
+ !mchr[mlp->unit.ship.shp_type].m_nplanes &&
+ !mchr[mlp->unit.ship.shp_type].m_nland)
continue;
if (!mvs) {
mvs = mlp;
continue;
}
- if (((struct mchrstr *)mlp->chrp)->m_cost * mlp->unit.ship.shp_effic >
- ((struct mchrstr *)mvs->chrp)->m_cost * mvs->unit.ship.shp_effic)
+ if (mchr[mlp->unit.ship.shp_type].m_cost * mlp->unit.ship.shp_effic >
+ mchr[mvs->unit.ship.shp_type].m_cost * mvs->unit.ship.shp_effic)
mvs = mlp;
}
return mvs;
next = qp->q_back;
mlp = (struct ulist *)qp;
if (wantflags &&
- (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
+ (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
continue;
if (nowantflags &&
- ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
+ mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
continue;
hard = shp_hardtarget(&mlp->unit.ship);
if (hard < easiest)
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
mlp = (struct ulist *)qp;
- if (((struct mchrstr *)mlp->chrp)->m_flags & M_SUB)
+ if (mchr[mlp->unit.ship.shp_type].m_flags & M_SUB)
continue;
if (natp->nat_flags & NF_COASTWATCH)
wu(0, sectp->sct_own,
rad_map_set(mlp->unit.ship.shp_own,
mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
mlp->unit.ship.shp_effic, mlp->unit.ship.shp_tech,
- ((struct mchrstr *)mlp->chrp)->m_vrnge);
+ mchr[mlp->unit.ship.shp_type].m_vrnge);
}
if (QEMPTY(list))
return stopping;