rooms separated
[k8-i-v-a-n.git] / src / game / rooms / room_vault.cpp
blobd643f498bc3b32dba56c8063f177c6c47208b337
1 #ifdef HEADER_PHASE
2 ROOM(vault, room) {
3 public:
4 vault();
5 virtual void Enter(character*);
6 virtual truth PickupItem(character*, item*, int);
7 virtual truth DropItem(character*, item*, int);
8 virtual void KickSquare(character*, lsquare*);
9 virtual truth ConsumeItem(character*, item*, int);
10 virtual void SetEntered(truth What) { Entered = What; }
11 virtual void Save(outputfile&) const;
12 virtual void Load(inputfile&);
13 virtual truth AllowDropGifts() const { return false; }
14 virtual truth Drink(character*) const;
15 virtual truth HasDrinkHandler() const { return true; }
16 virtual truth Dip(character*) const;
17 virtual truth HasDipHandler() const { return true; }
18 virtual void TeleportSquare(character*, lsquare*);
19 virtual truth AllowSpoil(citem*) const { return false; }
20 virtual int GetGodRelationAdjustment() const { return -150; }
21 virtual truth AllowKick(ccharacter*,const lsquare*) const;
22 virtual void HostileAction(character*) const;
23 virtual truth AllowAltarPolymorph() const { return false; }
24 virtual truth AllowFoodSearch() const { return false; }
25 virtual void AddItemEffect(item*);
26 character* FindRandomExplosiveReceiver() const;
27 protected:
28 truth Entered;
32 #else
36 vault::vault () {
37 SetEntered(false);
42 void vault::Enter (character *Visitor) {
43 if (Visitor->IsPlayer() && !Entered) {
44 ADD_MESSAGE("You enter a well-guarded vault. Everyone eyes you like an animal looking at a fresh piece piece of meat.");
45 Entered = true;
51 truth vault::PickupItem (character *Visitor, item *Item, int) {
52 if (game::GetStoryState() == 2 || game::GetTeam(KHARAZ_ARAD_TEAM)->GetRelation(Visitor->GetTeam()) == HOSTILE) return true;
53 if (Visitor->IsPlayer()) {
54 if (Item->IsHeadOfElpuri() || Item->IsGoldenEagleShirt() || Item->IsPetrussNut() || !Item->GetTruePrice() || Item->IsEncryptedScroll()) return true;
55 ADD_MESSAGE("Picking up property of the Vault is prohibited.");
56 if (game::TruthQuestion(CONST_S("Do you still want to do this? [y/N]"))) {
57 Visitor->GetTeam()->Hostility(game::GetTeam(KHARAZ_ARAD_TEAM));
58 return true;
61 return false;
66 truth vault::DropItem (character *Visitor, item *Item, int) {
67 if (game::GetStoryState() == 2 || game::GetTeam(KHARAZ_ARAD_TEAM)->GetRelation(Visitor->GetTeam()) == HOSTILE) return true;
68 if (Visitor->IsPlayer()) {
69 if (Item->IsHeadOfElpuri() || Item->IsGoldenEagleShirt() || Item->IsPetrussNut() || Item->IsTheAvatar() || Item->IsEncryptedScroll()) {
70 ADD_MESSAGE("Donating this to the Vault wouldn't be wise. You may still need it.");
71 return false;
73 if (game::TruthQuestion(CONST_S("Do you wish to donate this item to the Vault? [y/N]"))) return true;
75 return false;
80 void vault::KickSquare (character *Kicker, lsquare *Square) {
81 if (!AllowKick(Kicker, Square) && Kicker->IsPlayer() && game::GetStoryState() != 2 && game::GetTeam(KHARAZ_ARAD_TEAM)->GetRelation(Kicker->GetTeam()) != HOSTILE) {
82 ADD_MESSAGE("You have harmed the property of the Vault!");
83 Kicker->GetTeam()->Hostility(game::GetTeam(KHARAZ_ARAD_TEAM));
89 truth vault::ConsumeItem (character *HungryMan, item *, int) {
90 if (game::GetStoryState() == 2 || game::GetTeam(KHARAZ_ARAD_TEAM)->GetRelation(HungryMan->GetTeam()) == HOSTILE) return true;
91 if (HungryMan->IsPlayer()) {
92 ADD_MESSAGE("Eating the property of the Cathedral is forbidden.");
93 if (game::TruthQuestion(CONST_S("Do you still want to do this? [y/N]"))) {
94 HungryMan->GetTeam()->Hostility(game::GetTeam(KHARAZ_ARAD_TEAM));
95 return true;
98 return false;
103 void vault::Save (outputfile &SaveFile) const {
104 room::Save(SaveFile);
105 SaveFile << Entered;
110 void vault::Load (inputfile &SaveFile) {
111 room::Load(SaveFile);
112 SaveFile >> Entered;
117 truth vault::Drink (character *Thirsty) const {
118 if (game::GetStoryState() == 2 || game::GetTeam(KHARAZ_ARAD_TEAM)->GetRelation(Thirsty->GetTeam()) == HOSTILE)
119 return game::TruthQuestion(CONST_S("Do you want to drink? [y/N]"));
120 if (Thirsty->IsPlayer()) {
121 ADD_MESSAGE("Drinking property of the Cathedral is prohibited.");
122 if (game::TruthQuestion(CONST_S("Do you still want to do this? [y/N]"))) {
123 Thirsty->GetTeam()->Hostility(game::GetTeam(KHARAZ_ARAD_TEAM));
124 return true;
127 return false;
132 void vault::TeleportSquare (character *Teleporter, lsquare *Square) {
133 if (game::GetStoryState() == 2 || !Teleporter || game::GetTeam(KHARAZ_ARAD_TEAM)->GetRelation(Teleporter->GetTeam()) == HOSTILE) return;
134 if (Teleporter->IsPlayer() && Square->GetStack()->GetItems()) {
135 ADD_MESSAGE("You have done unnatural things to the property of the Cathedral!");
136 Teleporter->GetTeam()->Hostility(game::GetTeam(KHARAZ_ARAD_TEAM));
142 truth vault::Dip (character *Thirsty) const {
143 if (game::GetStoryState() == 2 || game::GetTeam(KHARAZ_ARAD_TEAM)->GetRelation(Thirsty->GetTeam()) == HOSTILE) return true;
144 if (Thirsty->IsPlayer()) {
145 /* What if it's not water? */
146 ADD_MESSAGE("Stealing the precious water of the Cathedral is prohibited.");
147 if (game::TruthQuestion(CONST_S("Are you sure you want to dip? [y/N]"))) {
148 Thirsty->GetTeam()->Hostility(game::GetTeam(KHARAZ_ARAD_TEAM));
149 return true;
152 return false;
157 truth vault::AllowKick (ccharacter *Char, const lsquare *LSquare) const {
158 return game::GetTeam(KHARAZ_ARAD_TEAM)->GetRelation(Char->GetTeam()) == HOSTILE || !LSquare->GetStack()->GetItems();
163 void vault::HostileAction (character *Guilty) const {
164 if (game::GetStoryState() != 2 && Guilty) Guilty->GetTeam()->Hostility(game::GetTeam(KHARAZ_ARAD_TEAM));
169 void vault::AddItemEffect (item *Dropped) {
170 if (!Dropped->IsExplosive()) return;
171 truth SeenBeforeTeleport = Dropped->CanBeSeenByPlayer();
172 character *KamikazeDwarf = FindRandomExplosiveReceiver();
173 if (KamikazeDwarf) {
174 Dropped->MoveTo(KamikazeDwarf->GetStack());
175 if (KamikazeDwarf->CanBeSeenByPlayer()) {
176 if (SeenBeforeTeleport)
177 ADD_MESSAGE("%s disappears and reappears in %s's inventory.", Dropped->GetName(DEFINITE).CStr(), KamikazeDwarf->GetName(DEFINITE).CStr());
178 else
179 ADD_MESSAGE("%s appears in %s's inventory.", Dropped->GetName(DEFINITE).CStr(), KamikazeDwarf->GetName(DEFINITE).CStr());
180 } else if (SeenBeforeTeleport) ADD_MESSAGE("%s disappears.", Dropped->GetName(DEFINITE).CStr());
181 } else {
182 /* position is in kamikaze dwarf room */
183 Dropped->RemoveFromSlot();
184 game::GetCurrentLevel()->GetLSquare(18,21)->GetStack()->AddItem(Dropped, false);
185 if (Dropped->CanBeSeenByPlayer()) {
186 if (SeenBeforeTeleport)
187 ADD_MESSAGE("%s disappears and reappears in the kamikaze dwarf room.", Dropped->GetName(DEFINITE).CStr());
188 else
189 ADD_MESSAGE("%s appears in the kamikaze dwarf room.", Dropped->GetName(DEFINITE).CStr());
190 } else if (SeenBeforeTeleport) ADD_MESSAGE("%s disappears.", Dropped->GetNameSingular().CStr());
196 character *vault::FindRandomExplosiveReceiver () const {
197 std::vector<character *> ListOfDwarfs;
198 for (std::list<character *>::const_iterator i = game::GetTeam(KHARAZ_ARAD_TEAM)->GetMember().begin();
199 i != game::GetTeam(KHARAZ_ARAD_TEAM)->GetMember().end(); ++i)
200 if ((*i)->IsEnabled() && (*i)->IsKamikazeDwarf()) ListOfDwarfs.push_back(*i);
201 if (ListOfDwarfs.empty()) return 0;
202 return ListOfDwarfs[RAND_N(ListOfDwarfs.size())];
204 #endif