NS_AREA, /* rectangular area */
NS_ALL, /* everything */
NS_XY, /* one sector area */
- NS_GROUP /* group, i.e. fleet, wing, army */
+ NS_GROUP, /* group, i.e. fleet, wing, army */
+ NS_CARGO /* loaded on the same carrier */
};
/* Sector iterator */
int dist; /* NS_DIST: distance selector */
coord cx, cy; /* NS_DIST: center x-y, NS_XY: xy */
char group; /* NS_GROUP: fleet/wing match */
+ short next; /* NS_CARGO: next item */
int size; /* NS_LIST: size of list */
int index; /* NS_LIST: index */
int list[NS_LSIZE]; /* NS_LIST: item list */
extern void snxtitem_group(struct nstr_item *, int, char);
extern void snxtitem_rewind(struct nstr_item *);
extern int snxtitem_list(struct nstr_item *, int, int *, int);
+extern void snxtitem_cargo(struct nstr_item *, int, int, int);
/* snxtsct.c */
extern int snxtsct(struct nstr_sect *, char *);
extern void snxtsct_area(struct nstr_sect *, struct range *);
#include "player.h"
#include "prototypes.h"
#include "ship.h"
+#include "unit.h"
#include "xy.h"
int
if (np->index >= np->size)
return 0;
np->cur = np->list[np->index];
+ } else if (np->sel == NS_CARGO) {
+ if (np->next < 0)
+ return 0;
+ np->cur = np->next;
+ np->next = unit_cargo_next(np->type, np->next);
} else {
np->cur++;
}
selected = 1;
switch (np->sel) {
case NS_LIST:
- break;
+ case NS_CARGO:
case NS_ALL:
break;
case NS_DIST:
#include "nsc.h"
#include "file.h"
#include "prototypes.h"
+#include "unit.h"
/*
* setup the nstr structure for sector selection.
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);
+}
#include "land.h"
#include "nsc.h"
#include "ship.h"
+#include "unit.h"
#include "update.h"
void *
if (np->index >= np->size)
return 0;
np->cur = np->list[np->index];
+ } else if (np->sel == NS_CARGO) {
+ if (np->next < 0)
+ return 0;
+ np->cur = np->next;
+ np->next = unit_cargo_next(np->type, np->next);
} else {
np->cur++;
}
selected = 1;
switch (np->sel) {
case NS_LIST:
- break;
+ case NS_CARGO:
case NS_ALL:
break;
case NS_DIST: