cosmetix
[k8-i-v-a-n.git] / src / game / wsquare.cpp
blob8abf1662fc2f420aca182b9286a9ae175daaec25
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
12 /* Compiled through wmapset.cpp */
15 wsquare::wsquare (worldmap *WorldMapUnder, v2 Pos) :
16 square(WorldMapUnder, Pos), GWTerrain(0), OWTerrain(0)
21 wsquare::~wsquare () {
22 delete GWTerrain;
23 delete OWTerrain;
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();
38 CalculateLuminance();
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();
65 delete GWTerrain;
66 SetGWTerrain(NewGround);
67 Flags |= DESCRIPTION_CHANGE|NEW_DRAW_REQUEST;
71 void wsquare::ChangeOWTerrain (owterrain *NewOver) {
72 if (OWTerrain && OWTerrain->IsAnimated()) DecStaticAnimatedEntities();
73 delete OWTerrain;
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) {
86 GWTerrain = What;
87 if (What) {
88 What->SetWSquareUnder(this);
89 if (What->IsAnimated()) IncStaticAnimatedEntities();
94 void wsquare::SetOWTerrain (owterrain *What) {
95 OWTerrain = What;
96 if (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();
106 if (OWTerrain) {
107 OWTerrain->AddName(MemorizedDescription, INDEFINITE);
108 MemorizedDescription << " surrounded by ";
109 GWTerrain->AddName(MemorizedDescription, UNARTICLED);
110 } else {
111 GWTerrain->AddName(MemorizedDescription, UNARTICLED);
113 if (Cheat) {
114 festring Continent;
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 {
126 return GWTerrain;
130 oterrain *wsquare::GetOTerrain() const {
131 return OWTerrain;
135 truth wsquare::SignalSeen () {
136 UpdateMemorizedDescription();
137 LastSeen = 1;
138 return true;
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 {
155 return LastSeen;
159 truth wsquare::CanBeSeenFrom (v2 FromPos, sLong MaxDistance, truth) const {
160 return (Pos-FromPos).GetLengthSquare() <= MaxDistance;