/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
*
* Known contributors to this file:
* Dave Pare, 1986
- * Markus Armbruster, 2003-2014
+ * Markus Armbruster, 2003-2016
*/
#include <config.h>
#include <ctype.h>
#include "chance.h"
-#include "file.h"
#include "land.h"
#include "misc.h"
#include "nat.h"
#include "ship.h"
#include "xy.h"
+static void
+list_ship(struct shpstr *sp, int first)
+{
+ if (first)
+ pr(" # owner eff type\n");
+ pr("(#%3d) %10.10s %12.12s %s\n", sp->shp_uid,
+ cname(sp->shp_own), effadv(sp->shp_effic), prship(sp));
+}
+
int
shipsatxy(coord x, coord y, int wantflags, int nowantflags, int only_count)
{
- int first;
int ships;
struct nstr_item ni;
struct mchrstr *mp;
struct shpstr ship;
- first = 1;
ships = 0;
snxtitem_xy(&ni, EF_SHIP, x, y);
while (nxtitem(&ni, &ship)) {
if (player->owner)
continue;
- if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
+ if (!ship.shp_own)
continue;
mp = &mchr[(int)ship.shp_type];
if (wantflags) {
if (mp->m_flags & nowantflags)
continue;
}
- if (!only_count) {
- if (first) {
- pr(" # owner eff type\n");
- first = 0;
- }
- pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
- cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
- }
+ if (!only_count)
+ list_ship(&ship, !ships);
ships++;
}
return ships;
int
carriersatxy(coord x, coord y, natid own)
{
- int first;
int ships;
struct nstr_item ni;
struct shpstr ship;
- first = 1;
ships = 0;
snxtitem_xy(&ni, EF_SHIP, x, y);
while (nxtitem(&ni, &ship)) {
- if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
+ if (!ship.shp_own)
continue;
if (relations_with(ship.shp_own, own) != ALLIED)
continue;
if ((carrier_planes(&ship, 0) & (P_L | P_K)) == 0)
continue;
- if (first) {
- pr(" # owner eff type\n");
- first = 0;
- }
- pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
- cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
+ list_ship(&ship, !ships);
ships++;
}
return ships;
}
int
-unitsatxy(coord x, coord y, int wantflags, int nowantflags, int only_count)
+unitsatxy(coord x, coord y, int wantflags, int nowantflags)
{
- int first;
int units;
struct nstr_item ni;
struct lchrstr *lp;
struct lndstr land;
- first = 1;
units = 0;
snxtitem_xy(&ni, EF_LAND, x, y);
while (nxtitem(&ni, &land)) {
- if (land.lnd_effic < LAND_MINEFF || land.lnd_own == 0)
+ if (!land.lnd_own)
continue;
- /* Can't bomb units on ships or other units */
if (land.lnd_ship >= 0 || land.lnd_land >= 0)
continue;
lp = &lchr[(int)land.lnd_type];
continue;
}
- if (lp->l_flags & L_SPY) {
- if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
- continue;
- }
-
- if (!only_count) {
- if (first) {
- pr(" # owner eff type\n");
- first = 0;
- }
- pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
- cname(land.lnd_own), effadv(land.lnd_effic), prland(&land));
- }
+ if (!units)
+ pr(" # owner eff type\n");
+ pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
+ cname(land.lnd_own), effadv(land.lnd_effic), prland(&land));
units++;
}
return units;
int
planesatxy(coord x, coord y, int wantflags, int nowantflags)
{
- int first;
int planes;
struct plnstr plane;
struct nstr_item ni;
struct plchrstr *plp;
planes = 0;
- first = 1;
snxtitem_xy(&ni, EF_PLANE, x, y);
while (nxtitem(&ni, &plane)) {
- if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0)
+ if (!plane.pln_own)
continue;
if (plane.pln_ship >= 0 || plane.pln_land >= 0)
continue;
if (plane.pln_flags & PLN_LAUNCHED)
continue;
plp = &plchr[(int)plane.pln_type];
- if (first) {
+ if (!planes)
pr(" # owner eff type\n");
- first = 0;
- }
if (wantflags) {
if ((plp->pl_flags & wantflags) == 0)
continue;
asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
struct plnstr *pp, struct shiplist **head)
{
- int first;
int ships;
struct nstr_item ni;
struct mchrstr *mp;
struct shpstr ship;
- first = 1;
ships = 0;
snxtitem_xy(&ni, EF_SHIP, x, y);
while (nxtitem(&ni, &ship)) {
if (player->owner)
continue;
- if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
+ if (!ship.shp_own)
continue;
mp = &mchr[(int)ship.shp_type];
if (wantflags) {
continue;
}
add_shiplist(ship.shp_uid, head);
- if (first) {
- pr(" # owner eff type\n");
- first = 0;
- }
- pr("(#%3d) %10.10s %12.12s %s\n", ni.cur,
- cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
+ list_ship(&ship, !ships);
ships++;
}
return ships;
}
+void
+print_shiplist(struct shiplist *head)
+{
+ struct shiplist *s;
+ struct shpstr ship;
+
+ for (s = head; s; s = s->next) {
+ getship(s->uid, &ship);
+ list_ship(&ship, s == head);
+ }
+}
+
int
adj_units(coord x, coord y, natid own)
{
return 0;
}
-
-/*
- * is p a list of ships/planes/units?
- */
-
-int
-islist(char *p)
-{
- for (; *p; p++) {
- if (!isdigit(*p) && *p != '/')
- return 0;
- }
- return 1;
-}