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