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
12 /* Compiled through wmapset.cpp */
15 wsquare::wsquare (worldmap
*WorldMapUnder
, v2 Pos
) :
16 square(WorldMapUnder
, Pos
), GWTerrain(0), OWTerrain(0)
21 wsquare::~wsquare () {
27 void wsquare::Save (outputfile
&SaveFile
) const {
28 square::Save(SaveFile
);
29 SaveFile
<< GWTerrain
<< OWTerrain
;
30 SaveFile
.Put(!!LastSeen
);
34 void wsquare::Load (inputfile
&SaveFile
) {
35 square::Load(SaveFile
);
36 SaveFile
>> GWTerrain
>> OWTerrain
;
37 LastSeen
= SaveFile
.Get();
42 void wsquare::Draw (blitdata
&BlitData
) {
43 if (Flags
& NEW_DRAW_REQUEST
|| AnimatedEntities
) {
44 BlitData
.Luminance
= ivanconfig::ApplyContrastTo(Luminance
);
45 GWTerrain
->Draw(BlitData
);
46 if (OWTerrain
) OWTerrain
->Draw(BlitData
);
47 if (Character
&& Character
->CanBeSeenByPlayer()) {
48 BlitData
.Luminance
= ivanconfig::GetContrastLuminance();
49 BlitData
.CustomData
= Character
->GetSquareIndex(Pos
)|ALLOW_ANIMATE
|ALLOW_ALPHA
;
50 Character
->Draw(BlitData
);
52 Flags
&= ~STRONG_NEW_DRAW_REQUEST
;
57 void wsquare::ChangeWTerrain (gwterrain
*NewGround
, owterrain
*NewOver
) {
58 ChangeGWTerrain(NewGround
);
59 ChangeOWTerrain(NewOver
);
63 void wsquare::ChangeGWTerrain (gwterrain
*NewGround
) {
64 if (GWTerrain
->IsAnimated()) DecStaticAnimatedEntities();
66 SetGWTerrain(NewGround
);
67 Flags
|= DESCRIPTION_CHANGE
|NEW_DRAW_REQUEST
;
71 void wsquare::ChangeOWTerrain (owterrain
*NewOver
) {
72 if (OWTerrain
&& OWTerrain
->IsAnimated()) DecStaticAnimatedEntities();
74 SetOWTerrain(NewOver
);
75 Flags
|= DESCRIPTION_CHANGE
|NEW_DRAW_REQUEST
;
79 void wsquare::SetWTerrain (gwterrain
*NewGround
, owterrain
*NewOver
) {
80 SetGWTerrain(NewGround
);
81 SetOWTerrain(NewOver
);
85 void wsquare::SetGWTerrain (gwterrain
*What
) {
88 What
->SetWSquareUnder(this);
89 if (What
->IsAnimated()) IncStaticAnimatedEntities();
94 void wsquare::SetOWTerrain (owterrain
*What
) {
97 What
->SetWSquareUnder(this);
98 if (What
->IsAnimated()) IncStaticAnimatedEntities();
103 void wsquare::UpdateMemorizedDescription (truth Cheat
) {
104 if (Flags
& DESCRIPTION_CHANGE
|| Cheat
) {
105 MemorizedDescription
.Empty();
107 OWTerrain
->AddName(MemorizedDescription
, INDEFINITE
);
108 MemorizedDescription
<< " surrounded by ";
109 GWTerrain
->AddName(MemorizedDescription
, UNARTICLED
);
111 GWTerrain
->AddName(MemorizedDescription
, UNARTICLED
);
115 if (GetWorldMap()->GetContinentUnder(Pos
)) Continent
<< ", continent " << GetWorldMap()->GetContinentUnder(Pos
)->GetName();
116 MemorizedDescription
<< " (pos " << Pos
.X
<< ':' << Pos
.Y
117 << Continent
<< ", height "
118 << GetWorldMap()->GetAltitude(Pos
) << " m)";
120 Flags
&= ~DESCRIPTION_CHANGE
;
125 gterrain
*wsquare::GetGTerrain () const {
130 oterrain
*wsquare::GetOTerrain() const {
135 truth
wsquare::SignalSeen () {
136 UpdateMemorizedDescription();
142 void wsquare::CalculateLuminance () {
143 double T
= log(1.0 + fabs(GetWorldMap()->GetAltitude(Pos
)) / 500.);
144 int Element
= Min((128 - int(37.5 * T
)), 255);
145 Luminance
= MakeRGB24(Element
, Element
, Element
);
149 int wsquare::GetWalkability () const {
150 return (OWTerrain
? OWTerrain
->GetWalkability() & GWTerrain
->GetWalkability() : GWTerrain
->GetWalkability());
154 truth
wsquare::CanBeSeenByPlayer (truth
) const {
159 truth
wsquare::CanBeSeenFrom (v2 FromPos
, sLong MaxDistance
, truth
) const {
160 return (Pos
-FromPos
).GetLengthSquare() <= MaxDistance
;