1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
/*
* PROPRIETARY INFORMATION. This software is proprietary to POWDER
* Development, and is not to be reproduced, transmitted, or disclosed
* in any way without written permission.
*
* Produced by: Jeff Lait
*
* POWDER Development
*
* NAME: itemstack.h ( POWDER Library, C++ )
*
* COMMENTS:
* This provides a method to get a stack of items,
* for example, all the items at a given square.
* It avoids dynamic allocation up to the minsize,
* but will happily transparently go to dynamic allocation
* where necessary.
*/
#ifndef __itemstack_h__
#define __itemstack_h__
class ITEM;
class MOB;
#define PTRSTACK_MINSIZE 20
template <typename PTR>
class PTRSTACK
{
public:
PTRSTACK();
~PTRSTACK();
void append(PTR item);
// Reverses the order of the stack.
void reverse();
// Empties the stack
void clear();
// Collapses all entries that evaluate ! as true (ie, zero)
void collapse();
PTR operator()(int idx) const;
int entries() const;
void set(int idx, PTR item);
void setEntries(int entries);
private:
PTR *myExtraList;
int myEntries;
int myExtraSize;
PTR myLocal[PTRSTACK_MINSIZE];
};
typedef PTRSTACK<ITEM *> ITEMSTACK;
typedef PTRSTACK<MOB *> MOBSTACK;
// For crappy platforms:
#include "itemstack.cpp"
#endif
|