save and bone files now can be compressed with ZLib (wow!)
[k8-i-v-a-n.git] / src / game / stack.h
blob574d3efc1c6cc00aafb27438e91f983832167abe
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
12 #ifndef __STACK_H__
13 #define __STACK_H__
15 #include <vector>
17 #include "lsquare.h"
18 #include "slot.h"
21 class felist;
22 class entity;
24 typedef std::vector<item *> itemvector;
25 typedef std::vector<itemvector> itemvectorvector;
28 /* Stack contains an arbitrary number of items in a linked list, which can
29 be browsed using stackiterators like this:
31 for (stackiterator i = Stack->GetBottom(); i.HasItem(); ++i) {
32 item *Item = *i;
33 i->ItemMemberFunction();
36 or using a temporary vector:
38 itemvector ItemVector;
39 Stack->FillItemVector(ItemVector);
41 for (int c = 0; c < ItemVector.size(); ++c) {
42 item *Item = ItemVector[c];
43 ItemVector[c]->ItemMemberFunction();
46 The former is faster and should be used if items can't be removed nor
47 added during the loop (at worst, this could cause a crash), otherwise
48 the latter is necessary.
50 Items are added to stack with Stack->AddItem(Item) and removed by
51 Item->RemoveFromSlot(). A number of Stack->DrawContents() functions
52 is provided as an easy item-selecting GUI.
54 class stackiterator {
55 public:
56 stackiterator (stackslot *Slot) : Slot(Slot) {}
57 stackiterator &operator ++ () { Slot = Slot->Next; return *this; }
58 stackiterator &operator -- () { Slot = Slot->Last; return *this; }
59 truth HasItem () const { return truth(Slot); }
60 item *operator -> () const { return Slot->Item; }
61 item *operator * () const { return Slot->Item; }
62 const stackslot &GetSlot () const { return *Slot; }
64 private:
65 stackslot *Slot;
69 class stack {
70 public:
71 stack (square *, entity *, feuLong = 0);
72 ~stack ();
73 void Load (inputfile &);
74 void Draw (ccharacter *, blitdata &, int) const;
75 void AddItem (item *, truth = true);
76 void RemoveItem (stackslot *);
77 item *GetItem (int) const;
78 void GetVisibleItemsV (ccharacter *Viewer, std::vector<item *> &vi);
79 truth HasSomethingFunny (ccharacter *Viewer, truth seeCorpses=false, truth seeUnstepped=false);
80 void SetSteppedOn (truth v);
81 stackiterator GetBottom () const { return stackiterator(Bottom); }
82 stackiterator GetTop () const { return stackiterator(Top); }
83 int GetItems () const { return Items; }
84 int GetSideItems (int) const;
85 int GetVisibleItems (ccharacter *) const;
86 int GetNativeVisibleItems (ccharacter *) const;
87 int GetVisibleSideItems (ccharacter *, int) const;
88 void SetMotherSquare (square *What) { MotherSquare = What; }
89 item *DrawContents (ccharacter *, cfestring &, int = 0, sorter = 0) const;
90 int DrawContents (itemvector &, ccharacter *, cfestring &, int = 0, sorter = 0) const;
91 int DrawContents (itemvector &, stack *, ccharacter *, cfestring &, cfestring &, cfestring &,
92 cfestring &, col16, int, sorter = 0) const;
93 v2 GetPos () const;
94 void Clean (truth = false);
95 void Save (outputfile &) const;
96 int SearchItem (item *) const;
97 square *GetSquareUnder () const;
98 lsquare *GetLSquareUnder () const { return static_cast<lsquare*>(GetSquareUnder()); }
99 truth SortedItems (ccharacter *, sorter) const;
100 void BeKicked (character *, int, int);
101 void Polymorph (character *);
102 void CheckForStepOnEffect (character *);
103 lsquare *GetLSquareTrulyUnder (int) const;
104 void ReceiveDamage (character *, int, int, int = YOURSELF);
105 void TeleportRandomly (uInt = 0xFFFF);
106 void FillItemVector (itemvector &) const;
107 truth IsOnGround () const;
108 truth RaiseTheDead (character *);
109 truth TryKey (item *, character *);
110 truth Open (character *);
111 void SignalVolumeAndWeightChange ();
112 void CalculateVolumeAndWeight ();
113 sLong GetVolume () const { return Volume; }
114 sLong GetWeight () const { return Weight; }
115 sLong GetWeight (ccharacter *, int) const;
116 entity *GetMotherEntity () const { return MotherEntity; }
117 void SetMotherEntity (entity *What) { MotherEntity = What; }
118 area *GetArea () const { return GetSquareUnder()->GetArea(); }
119 lsquare *GetNearLSquare (v2 Pos) const { return GetLSquareUnder()->GetLevel()->GetLSquare(Pos); }
120 col24 GetEmitation () const { return Emitation; }
121 void SignalEmitationIncrease (int, col24);
122 void SignalEmitationDecrease (int, col24);
123 void CalculateEmitation ();
124 col24 GetSideEmitation (int);
125 truth CanBeSeenBy (ccharacter *, int) const;
126 truth IsDangerous (ccharacter *) const;
127 truth Duplicate (int, feuLong = 0);
128 void MoveItemsTo (stack *);
129 void MoveItemsTo (slot *);
130 item *GetBottomItem (ccharacter *, truth) const;
131 item *GetBottomVisibleItem (ccharacter *) const;
132 item *GetBottomSideItem (ccharacter *, int, truth) const;
133 void Pile (itemvectorvector &, ccharacter *, int, sorter = 0) const;
134 sLong GetTruePrice () const;
135 static int GetSelected () { return Selected; }
136 static void SetSelected (int What) { Selected = What; }
137 truth TakeSomethingFrom (character *, cfestring&);
138 truth PutSomethingIn (character *, cfestring &, sLong, feuLong);
139 truth IsVisible () const { return !(Flags & HIDDEN); }
140 int GetSpoiledItems () const;
141 void SortAllItems (const sortdata &) const;
142 void Search (ccharacter *, int);
143 truth NeedDangerSymbol (ccharacter *) const;
144 void PreProcessForBone ();
145 void PostProcessForBone ();
146 void FinalProcessForBone ();
147 void AddElement (item *, truth = false);
148 void SpillFluid (character *, liquid *, sLong);
149 void AddItems (const itemvector &);
150 void MoveItemsTo (itemvector &, int);
151 void Freeze () { Flags |= FREEZED; }
152 void UnFreeze () { Flags &= ~FREEZED; }
153 void DropSideItems ();
154 truth DetectMaterial (cmaterial *) const;
155 void SetLifeExpectancy (int, int);
156 truth Necromancy (character *);
157 void CalculateEnchantments ();
158 ccharacter *FindCarrier () const;
159 void Haste ();
160 void Slow ();
162 private:
163 void RemoveElement (stackslot *);
164 void AddContentsToList (felist &, ccharacter *, cfestring &, int, int, sorter) const;
165 int SearchChosen (itemvector &, ccharacter *, int, int, int, int, sorter = 0) const;
166 static truth AllowDamage (int, int);
168 private:
169 static int Selected;
170 stackslot *Bottom;
171 stackslot *Top;
172 square *MotherSquare;
173 entity *MotherEntity;
174 sLong Volume;
175 sLong Weight;
176 col24 Emitation : 24;
177 feuLong Flags : 8;
178 int Items;
182 #endif