'g'o should not miss items in corners anymore
[k8-i-v-a-n.git] / src / game / square.cpp
blob34f57ade3e5c6219a3a3c6dfcfa389e0e4f6add1
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 areaset.cpp */
15 square::square(area* AreaUnder, v2 Pos) : AreaUnder(AreaUnder), Character(0), Pos(Pos), Luminance(0), Flags(IS_TRANSPARENT|MEMORIZED_UPDATE_REQUEST|DESCRIPTION_CHANGE), StaticAnimatedEntities(0), AnimatedEntities(0), LastSeen(0) { }
17 square::~square()
19 character* Char = GetCharacter();
21 if(Char)
23 for(int c = 0; c < Char->GetSquaresUnder(); ++c)
24 Char->GetSquareUnder(c)->Character = 0;
26 delete Char;
30 void square::Save(outputfile& SaveFile) const
32 if(!Character || Character->IsMainPos(Pos))
33 SaveFile << Character;
35 SaveFile << StaticAnimatedEntities << AnimatedEntities << MemorizedDescription;
38 void square::Load(inputfile& SaveFile)
40 if(!Character)
41 SaveFile >> Character;
43 SaveFile >> StaticAnimatedEntities >> AnimatedEntities >> MemorizedDescription;
46 void square::AddCharacter(character* Guy)
48 Character = Guy;
49 Flags |= STRONG_NEW_DRAW_REQUEST;
51 if(Guy->IsAnimated())
52 IncAnimatedEntities();
54 Guy->CheckIfSeen();
57 void square::RemoveCharacter()
59 if(Character && Character->IsAnimated())
60 DecAnimatedEntities();
62 Character = 0;
63 Flags |= STRONG_NEW_DRAW_REQUEST;
66 cchar* square::SurviveMessage(character* Char) const
68 if(GetOTerrain() && !Char->CanMoveOn(GetOTerrain()))
69 return GetOTerrain()->SurviveMessage();
70 else
71 return GetGTerrain()->SurviveMessage();
74 cchar* square::MonsterSurviveMessage(character* Char) const
76 if(GetOTerrain() && !Char->CanMoveOn(GetOTerrain()))
77 return GetOTerrain()->MonsterSurviveMessage();
78 else
79 return GetGTerrain()->MonsterSurviveMessage();
82 cchar* square::DeathMessage(character* Char) const
84 if(GetOTerrain() && !Char->CanMoveOn(GetOTerrain()))
85 return GetOTerrain()->DeathMessage();
86 else
87 return GetGTerrain()->DeathMessage();
90 cchar* square::MonsterDeathVerb(character* Char) const
92 if(GetOTerrain() && !Char->CanMoveOn(GetOTerrain()))
93 return GetOTerrain()->MonsterDeathVerb();
94 else
95 return GetGTerrain()->MonsterDeathVerb();
98 cchar* square::ScoreEntry(character* Char) const
100 if(GetOTerrain() && !Char->CanMoveOn(GetOTerrain()))
101 return GetOTerrain()->ScoreEntry();
102 else
103 return GetGTerrain()->ScoreEntry();
106 truth square::IsFatalToStay() const
108 return GetGTerrain()->IsFatalToStay() || (GetOTerrain() && GetOTerrain()->IsFatalToStay());
111 int square::GetEntryDifficulty() const
113 return GetGTerrain()->GetEntryDifficulty();
116 int square::GetRestModifier() const
118 return GetOTerrain() ? GetOTerrain()->GetRestModifier() : 1;
121 truth square::CanBeSeenBy(ccharacter* Who, truth IgnoreDarkness) const
123 if(Who->IsPlayer())
124 return CanBeSeenByPlayer(IgnoreDarkness);
125 else
126 return CanBeSeenFrom(Who->GetPos(), Who->GetLOSRangeSquare(), IgnoreDarkness);
129 void square::SurviveEffect(character* Who)
131 if(GetOTerrain())
132 GetOTerrain()->SurviveEffect(Who);
134 GetGTerrain()->SurviveEffect(Who);
137 square* square::GetNeighbourSquare(int I) const
139 return AreaUnder->GetNeighbourSquare(Pos, I);
142 square* square::GetNearSquare(v2 Pos) const
144 return AreaUnder->GetSquare(Pos);