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 materset.cpp */
14
smoke()15 smoke::smoke() : entity(HAS_BE), Next(0) { }
GetSquareUnderEntity(int) const16 square* smoke::GetSquareUnderEntity(int) const { return LSquareUnder; }
17
smoke(gas * Gas,lsquare * LSquareUnder)18 smoke::smoke(gas* Gas, lsquare* LSquareUnder)
19 : entity(HAS_BE), Next(0), Gas(Gas), LSquareUnder(LSquareUnder), Alpha(Gas->GetAlpha())
20 {
21 Gas->SetMotherEntity(this);
22 Picture.resize(16);
23 packcol16 Color = Gas->GetColor();
24 bitmap Temp(TILE_V2, TRANSPARENT_COLOR);
25 Temp.ActivateFastFlag();
26 int Frame[16];
27 int Flags[16];
28
29 for(int c = 0; c < 16; ++c)
30 {
31 Picture[c] = new bitmap(TILE_V2, TRANSPARENT_COLOR);
32 Picture[c]->ActivateFastFlag();
33 Picture[c]->CreateAlphaMap(Alpha);
34 truth Correct = false;
35
36 while(!Correct)
37 {
38 Frame[c] = RAND() & 3;
39 Flags[c] = RAND() & 7;
40 Correct = true;
41
42 for(int i = 0; i < c; ++i)
43 if(Frame[c] == Frame[i] && Flags[c] == Flags[i])
44 {
45 Correct = false;
46 break;
47 }
48 }
49
50 igraph::GetRawGraphic(GR_EFFECT)->MaskedBlit(&Temp, v2(Frame[c] << 4, 32), ZERO_V2, TILE_V2, &Color);
51 Temp.NormalBlit(Picture[c], Flags[c]);
52 }
53
54 LSquareUnder->SignalSmokeAlphaChange(Alpha);
55 }
56
~smoke()57 smoke::~smoke()
58 {
59 for(uint c = 0; c < Picture.size(); ++c)
60 delete Picture[c];
61
62 delete Gas;
63 }
64
Be()65 void smoke::Be()
66 {
67 if(!(RAND() & 7))
68 {
69 LSquareUnder->SendNewDrawRequest();
70 LSquareUnder->SignalSmokeAlphaChange(-1);
71
72 if(!--Alpha)
73 {
74 LSquareUnder->RemoveSmoke(this);
75 SendToHell();
76 return;
77 }
78
79 for(int c = 0; c < 16; ++c)
80 Picture[c]->FillAlpha(Alpha);
81
82 Gas->SetVolume(Gas->GetVolume() - Gas->GetVolume() / 50);
83 }
84
85 character* Char = LSquareUnder->GetCharacter();
86
87 if(Char && !Char->StateIsActivated(GAS_IMMUNITY))
88 Gas->BreatheEffect(Char);
89
90 if(Char && Char->HasFire())
91 if(Gas->ExplosiveEffect(Char))
92 {
93 LSquareUnder->RemoveSmoke(this);
94 SendToHell();
95 return;
96 }
97 }
98
Draw(blitdata & BlitData) const99 void smoke::Draw(blitdata& BlitData) const
100 {
101 Picture[(GET_TICK() >> 1) & 3]->AlphaLuminanceBlit(BlitData);
102 }
103
Save(outputfile & SaveFile) const104 void smoke::Save(outputfile& SaveFile) const
105 {
106 SaveFile << Picture << Gas << Alpha;
107 }
108
Load(inputfile & SaveFile)109 void smoke::Load(inputfile& SaveFile)
110 {
111 LSquareUnder = static_cast<lsquare*>(game::GetSquareInLoad());
112 SaveFile >> Picture >> Gas >> Alpha;
113 Gas->SetMotherEntity(this);
114 }
115
operator <<(outputfile & SaveFile,const smoke * Smoke)116 outputfile& operator<<(outputfile& SaveFile, const smoke* Smoke)
117 {
118 Smoke->Save(SaveFile);
119 return SaveFile;
120 }
121
operator >>(inputfile & SaveFile,smoke * & Smoke)122 inputfile& operator>>(inputfile& SaveFile, smoke*& Smoke)
123 {
124 Smoke = new smoke;
125 Smoke->Load(SaveFile);
126 return SaveFile;
127 }
128
AddBreatheMessage() const129 void smoke::AddBreatheMessage() const
130 {
131 if(Gas->GetBreatheMessage().GetSize())
132 ADD_MESSAGE("%s", Gas->GetBreatheMessage().CStr());
133 }
134
Merge(gas * OtherGas)135 void smoke::Merge(gas* OtherGas)
136 {
137 Gas->EditVolume(OtherGas->GetVolume());
138 LSquareUnder->SignalSmokeAlphaChange(OtherGas->GetAlpha() - Alpha);
139 Alpha = OtherGas->GetAlpha();
140
141 for(int c = 0; c < 16; ++c)
142 Picture[c]->FillAlpha(Alpha);
143
144 delete OtherGas;
145 }
146
IsDangerousToBreathe(ccharacter * Who) const147 truth smoke::IsDangerousToBreathe(ccharacter* Who) const
148 {
149 return (!Who->StateIsActivated(GAS_IMMUNITY)
150 && Who->GetAttribute(WISDOM) >= Gas->GetStepInWisdomLimit());
151 }
152
IsScaryToBreathe(ccharacter * Who) const153 truth smoke::IsScaryToBreathe(ccharacter* Who) const
154 {
155 return (!Who->StateIsActivated(GAS_IMMUNITY)
156 && Gas->GetCategoryFlags() & IS_SCARY);
157 }
158