1 /*
2  *
3  *  Iter Vehemens ad Necem (IVAN)
4  *  Copyright (C) Timo Kiviluoto
5  *  Released under the GNU General
6  *  Public License
7  *
8  *  See LICENSING which should be included
9  *  along with this file for more details
10  *
11  */
12 
13 /* Compiled through roomset.cpp */
14 
roomprototype(roomspawner Spawner,cchar * ClassID)15 roomprototype::roomprototype(roomspawner Spawner, cchar* ClassID)
16 : Spawner(Spawner), ClassID(ClassID) { Index = protocontainer<room>::Add(this); }
17 
Save(outputfile & SaveFile) const18 void room::Save(outputfile& SaveFile) const
19 {
20   SaveFile << static_cast<ushort>(GetType());
21   SaveFile << Pos << Size << Index << DivineMaster << MasterID;
22 }
23 
Load(inputfile & SaveFile)24 void room::Load(inputfile& SaveFile)
25 {
26   SaveFile >> Pos >> Size >> Index >> DivineMaster >> MasterID;
27 }
28 
SpawnAndLoad(inputfile & SaveFile) const29 room* roomprototype::SpawnAndLoad(inputfile& SaveFile) const
30 {
31   room* Room = Spawner();
32   Room->Load(SaveFile);
33   return Room;
34 }
35 
DestroyTerrain(character * Who)36 void room::DestroyTerrain(character* Who)
37 {
38   if(Who && MasterIsActive())
39     Who->Hostility(GetMaster());
40 
41   if(Who && Who->IsPlayer() && DivineMaster)
42     game::GetGod(DivineMaster)->AdjustRelation(GetGodRelationAdjustment());
43 }
44 
45 /* returns true if player agrees to continue */
46 
CheckDestroyTerrain(character * Infidel)47 truth room::CheckDestroyTerrain(character* Infidel)
48 {
49   if(!MasterIsActive() || Infidel == GetMaster() || GetMaster()->GetRelation(Infidel) == HOSTILE)
50     return true;
51 
52   ADD_MESSAGE("%s might not like this.", GetMaster()->CHAR_NAME(DEFINITE));
53 
54   if(game::TruthQuestion(CONST_S("Are you sure you want to do this? [y/N]")))
55   {
56     DestroyTerrain(Infidel);
57     return true;
58   }
59   else
60     return false;
61 }
62 
MasterIsActive() const63 truth room::MasterIsActive() const
64 {
65   character* Master = GetMaster();
66   return Master && Master->IsEnabled() && Master->IsConscious();
67 }
68 
CheckKickSquare(ccharacter * Kicker,const lsquare * LSquare) const69 truth room::CheckKickSquare(ccharacter* Kicker, const lsquare* LSquare) const
70 {
71   if(!AllowKick(Kicker, LSquare))
72   {
73     ADD_MESSAGE("That would be vandalism.");
74 
75     if(!game::TruthQuestion(CONST_S("Do you still want to do this? [y/N]")))
76       return false;
77   }
78   return true;
79 }
80 
GetMaster() const81 character* room::GetMaster() const
82 {
83   ulong Tick = game::GetTick();
84 
85   if(LastMasterSearchTick == Tick)
86     return Master;
87   else
88   {
89     LastMasterSearchTick = Tick;
90     return Master = game::SearchCharacter(MasterID);
91   }
92 }
93 
IsOKToDestroyWalls(ccharacter * Infidel) const94 truth room::IsOKToDestroyWalls(ccharacter* Infidel) const
95 {
96   return !MasterIsActive() || Infidel == GetMaster() || GetMaster()->GetRelation(Infidel) == HOSTILE;
97 }
98 
FinalProcessForBone()99 void room::FinalProcessForBone()
100 {
101   if(MasterID)
102   {
103     boneidmap::iterator BI = game::GetBoneCharacterIDMap().find(MasterID);
104 
105     if(BI != game::GetBoneCharacterIDMap().end())
106       MasterID = BI->second;
107     else
108       MasterID = 0;
109   }
110 }
111