* ---
*
* snxtitem.c: Arrange item selection using one of many criteria.
- *
+ *
* Known contributors to this file:
* Dave Pare, 1989
+ * Markus Armbruster, 2008
*/
#include <config.h>
#include "nsc.h"
#include "file.h"
#include "prototypes.h"
+#include "unit.h"
/*
* setup the nstr structure for sector selection.
* instead.
*/
int
-snxtitem(struct nstr_item *np, int type, char *str)
+snxtitem(struct nstr_item *np, int type, char *str, char *prompt)
{
struct range range;
int list[NS_LSIZE];
- int n;
+ int cnum, n;
coord cx, cy;
int dist;
int flags;
- char natnumber[16];
- char prompt[128];
+ char promptbuf[128];
char buf[1024];
np->type = EF_BAD;
np->sel = NS_UNDEF;
if (str == 0) {
- sprintf(prompt, "%s(s)? ", ef_nameof(type));
+ if (!prompt) {
+ sprintf(promptbuf, "%s(s)? ", ef_nameof(type));
+ prompt = promptbuf;
+ }
str = getstring(prompt, buf);
if (str == 0)
return 0;
return 0;
}
if (type == EF_NATION && isalpha(*str)) {
- sprintf(natnumber, "%d", natarg(str, NULL));
- str = natnumber;
+ cnum = natarg(str, NULL);
+ if (cnum < 0)
+ return 0;
+ sprintf(buf, "%d", cnum);
+ str = buf;
}
flags = ef_flags(type);
switch (sarg_type(str)) {
default:
return 0;
}
- np->flags = flags;
if (player->condarg == 0)
return 1;
n = nstr_comp(np->cond, sizeof(np->cond) / sizeof(*np->cond), type,
np->sel = NS_AREA;
np->index = -1;
np->range = *range;
- np->read = ef_read;
- np->flags = ef_flags(type);
xysize_range(&np->range);
}
snxtitem_dist(struct nstr_item *np, int type, int cx, int cy,
int dist)
{
- struct range range;
-
memset(np, 0, sizeof(*np));
- xydist_range(cx, cy, dist, &range);
+ xydist_range(cx, cy, dist, &np->range);
np->cur = -1;
np->type = type;
np->sel = NS_DIST;
np->cx = cx;
np->cy = cy;
np->index = -1;
- np->range = range;
np->dist = dist;
- np->read = ef_read;
- np->flags = ef_flags(type);
-#if 0
- /* This is no longer proper. */
- /* It did the wrong thing for small, hitech worlds. */
- xysize_range(&np->range);
-#endif
}
void
np->cy = ynorm(y);
np->index = -1;
np->dist = 0;
- np->read = ef_read;
- np->flags = ef_flags(type);
}
void
np->sel = NS_ALL;
np->type = type;
np->index = -1;
- np->read = ef_read;
- np->flags = ef_flags(type);
xysize_range(&np->range);
}
np->group = group;
np->type = type;
np->index = -1;
- np->read = ef_read;
- np->flags = ef_flags(type);
xysize_range(&np->range);
}
np->type = type;
np->sel = NS_LIST;
np->index = -1;
- np->read = ef_read;
- np->flags = ef_flags(type);
if (len <= 0 || len > NS_LSIZE)
return 0;
for (i = 0; i < len; i++)
np->size = len;
return 1;
}
+
+/*
+ * Initialize NP to iterate over the items of type TYPE in a carrier.
+ * The carrier has file type CARRIER_TYPE and uid CARRIER_UID.
+ * Note: you can take an item gotten with nxtitem() off its carrier
+ * without disturbing the iterator. Whether the iterator will pick up
+ * stuff you load onto the carrier during iteration is unspecified.
+ */
+void
+snxtitem_cargo(struct nstr_item *np, int type,
+ int carrier_type, int carrier_uid)
+{
+ memset(np, 0, sizeof(*np));
+ np->cur = -1;
+ np->type = type;
+ np->sel = NS_CARGO;
+ np->next = unit_cargo_first(carrier_type, carrier_uid, type);
+}