moved almost all hardcoded constants to "define.dat"
[k8-i-v-a-n.git] / src / game / slot.cpp
blobfec883d1ff6d163567fc23a716f47b11f192b5b6
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
13 /* Compiled through slotset.cpp */
15 void slot::Save(outputfile& SaveFile) const
17 SaveFile << Item;
20 void slot::Load(inputfile& SaveFile)
22 SaveFile >> Item;
24 if(Item)
25 Item->SetMainSlot(this);
28 void stackslot::Load(inputfile& SaveFile)
30 SaveFile >> Item;
32 if(Item)
33 Item->SignalStackAdd(this, &stack::AddElement);
36 void stackslot::Empty()
38 GetMotherStack()->RemoveItem(this);
41 void bodypartslot::Empty()
43 col24 Emitation = Item->GetEmitation();
44 static_cast<bodypart*>(Item)->SetMaster(0);
45 Item = 0;
46 GetMaster()->CalculateEquipmentState();
47 SignalVolumeAndWeightChange();
48 SignalEmitationDecrease(Emitation);
50 if(!GetMaster()->IsInitializing())
52 GetMaster()->CalculateHP();
53 GetMaster()->CalculateMaxHP();
57 void gearslot::Empty()
59 citem* Old = Item;
60 Item = 0;
61 col24 Emitation = Old->GetEmitation();
62 SignalVolumeAndWeightChange();
63 GetBodyPart()->SignalEquipmentRemoval(this, Old);
64 SignalEmitationDecrease(Emitation);
67 void gearslot::Init(bodypart* BodyPart, int I)
69 SetBodyPart(BodyPart);
70 SetEquipmentIndex(I);
73 void stackslot::AddFriendItem(item* Item) const
75 Item->RemoveFromSlot();
76 GetMotherStack()->AddItem(Item);
79 void bodypartslot::AddFriendItem(item* Item) const
81 Item->RemoveFromSlot();
83 if(!game::IsInWilderness())
84 GetMaster()->GetStackUnder()->AddItem(Item);
85 else
86 GetMaster()->GetStack()->AddItem(Item);
89 void gearslot::AddFriendItem(item* Item) const
91 Item->RemoveFromSlot();
93 if(!game::IsInWilderness())
94 GetBodyPart()->GetLSquareUnder()->AddItem(Item);
95 else
96 GetBodyPart()->GetMaster()->GetStack()->AddItem(Item);
99 truth stackslot::IsOnGround() const
101 return GetMotherStack()->IsOnGround();
104 void stackslot::SignalVolumeAndWeightChange()
106 GetMotherStack()->SignalVolumeAndWeightChange();
109 void bodypartslot::SignalVolumeAndWeightChange()
111 GetMaster()->SignalVolumeAndWeightChange();
112 GetMaster()->SignalBodyPartVolumeAndWeightChange();
115 void gearslot::SignalVolumeAndWeightChange()
117 GetBodyPart()->SignalVolumeAndWeightChange();
120 void stackslot::PutInItem(item* What)
122 Item = What;
124 if(Item)
126 Item->SignalStackAdd(this, &stack::AddItem);
127 SignalVolumeAndWeightChange();
128 SignalEmitationIncrease(Item->GetEmitation());
132 void bodypartslot::PutInItem(item* What)
134 Item = What;
136 if(Item)
138 Item->SetMainSlot(this);
139 static_cast<bodypart*>(Item)->SetMaster(GetMaster());
141 if(!GetMaster()->IsInitializing())
143 SignalVolumeAndWeightChange();
144 SignalEmitationIncrease(Item->GetEmitation());
145 static_cast<bodypart*>(Item)->CalculateMaxHP(0);
146 GetMaster()->CalculateHP();
147 GetMaster()->CalculateMaxHP();
152 void gearslot::PutInItem(item* What)
154 Item = What;
156 if(Item)
158 Item->SetMainSlot(this);
159 GetBodyPart()->SignalEquipmentAdd(this);
160 SignalVolumeAndWeightChange();
161 SignalEmitationIncrease(Item->GetEmitation());
165 square* stackslot::GetSquareUnder(int) const
167 return GetMotherStack()->GetSquareUnder();
170 square* bodypartslot::GetSquareUnder(int I) const
172 return GetMaster()->GetSquareUnder(I);
175 square* gearslot::GetSquareUnder(int) const
177 return GetBodyPart()->GetSquareUnder();
180 void stackslot::SignalEmitationIncrease(col24 Emitation)
182 GetMotherStack()->SignalEmitationIncrease(Item->GetSquarePosition(), Emitation);
185 void bodypartslot::SignalEmitationIncrease(col24 Emitation)
187 GetMaster()->SignalEmitationIncrease(Emitation);
190 void gearslot::SignalEmitationIncrease(col24 Emitation)
192 GetBodyPart()->SignalEmitationIncrease(Emitation);
195 void stackslot::SignalEmitationDecrease(col24 Emitation)
197 GetMotherStack()->SignalEmitationDecrease(Item->GetSquarePosition(), Emitation);
200 void bodypartslot::SignalEmitationDecrease(col24 Emitation)
202 GetMaster()->SignalEmitationDecrease(Emitation);
205 void gearslot::SignalEmitationDecrease(col24 Emitation)
207 GetBodyPart()->SignalEmitationDecrease(Emitation);
210 void bodypartslot::Load(inputfile& SaveFile)
212 slot::Load(SaveFile);
214 if(Item)
215 static_cast<bodypart*>(Item)->SetMaster(GetMaster());
218 void slot::DonateTo(item* Item)
220 Empty();
221 PutInItem(Item);
224 void stackslot::DonateTo(item* Item) // could be optimized
226 AddFriendItem(Item);
227 Empty();
230 truth stackslot::CanBeSeenBy(ccharacter* Viewer) const
232 return GetMotherStack()->CanBeSeenBy(Viewer, Item->GetSquarePosition());
235 truth bodypartslot::CanBeSeenBy(ccharacter* Viewer) const
237 return GetMaster()->CanBeSeenBy(Viewer);
240 truth gearslot::CanBeSeenBy(ccharacter* Viewer) const
242 return GetBodyPart()->CanBeSeenBy(Viewer);
245 void gearslot::SignalEnchantmentChange()
247 GetBodyPart()->SignalEnchantmentChange();
250 truth stackslot::IsVisible() const
252 return GetMotherStack()->IsVisible();
255 ccharacter* stackslot::FindCarrier() const
257 return GetMotherStack()->FindCarrier();
260 ccharacter* gearslot::FindCarrier() const
262 return GetBodyPart()->FindCarrier();