Make the item iterator capable of iterating over a cargo list

New snxtitem_cargo() initializes an iterator for a cargo list, with
new enum ns_seltype member NS_GROUP and new struct nstr_item member
next.  Extend nxtitem() and nxtitemp() to step through the list.
This commit is contained in:
Markus Armbruster 2008-09-12 18:46:54 -04:00
parent 7a4b7f75a0
commit e7f5b517a0
5 changed files with 37 additions and 3 deletions

View file

@ -41,6 +41,7 @@
#include "nsc.h"
#include "file.h"
#include "prototypes.h"
#include "unit.h"
/*
* setup the nstr structure for sector selection.
@ -222,3 +223,21 @@ snxtitem_list(struct nstr_item *np, int type, int *list, int len)
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);
}