1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #include <client/ScorchedClient.h>
22 #include <landscapemap/LandscapeMaps.h>
23 #include <landscape/Wall.h>
24 #include <sound/SoundUtils.h>
25 #include <image/ImageFactory.h>
26 #include <common/Defines.h>
27 
Wall()28 Wall::Wall() : texture_(ImageID(S3D::eModLocation,
29 	"data/textures/bordershield/grid.bmp",
30 	"data/textures/bordershield/grid.bmp",
31 	false))
32 {
33 	for (int i=0; i<4; i++) fadeTime_[i] = 0.0f;
34 }
35 
~Wall()36 Wall::~Wall()
37 {
38 }
39 
draw()40 void Wall::draw()
41 {
42 	float arenaX = (float) ScorchedClient::instance()->getLandscapeMaps().
43 			getGroundMaps().getArenaX();
44 	float arenaY = (float) ScorchedClient::instance()->getLandscapeMaps().
45 			getGroundMaps().getArenaY();
46 	float arenaWidth = (float) ScorchedClient::instance()->getLandscapeMaps().
47 			getGroundMaps().getArenaWidth();
48 	float arenaHeight = (float) ScorchedClient::instance()->getLandscapeMaps().
49 			getGroundMaps().getArenaHeight();
50 
51 	Vector botA(arenaX, arenaY, 0.0f);
52 	Vector botB(arenaX + arenaWidth, arenaY, 0.0f);
53 	Vector botC(arenaX + arenaWidth, arenaY + arenaHeight, 0.0f);
54 	Vector botD(arenaX, arenaY + arenaHeight, 0.0f);
55 	Vector topA(arenaX, arenaY, 256.0f);
56 	Vector topB(arenaX + arenaWidth, arenaY, 256.0f);
57 	Vector topC(arenaX + arenaWidth, arenaY + arenaHeight, 256.0f);
58 	Vector topD(arenaX, arenaY + arenaHeight, 256.0f);
59 
60 	if (fadeTime_[OptionsTransient::LeftSide] > 0.0f ||
61 		fadeTime_[OptionsTransient::BotSide] > 0.0f ||
62 		fadeTime_[OptionsTransient::RightSide] > 0.0f ||
63 		fadeTime_[OptionsTransient::TopSide] > 0.0f)
64 	{
65 		GLState currentState(GLState::BLEND_ON | GLState::TEXTURE_ON);
66 
67 		texture_.draw();
68 		drawWall(botA, botB, topB, topA, fadeTime_[OptionsTransient::TopSide]);
69 		drawWall(botB, botC, topC, topB, fadeTime_[OptionsTransient::RightSide]);
70 		drawWall(botC, botD, topD, topC, fadeTime_[OptionsTransient::BotSide]);
71 		drawWall(botD, botA, topA, topD, fadeTime_[OptionsTransient::LeftSide]);
72 	}
73 }
74 
drawWall(Vector & cornerA,Vector & cornerB,Vector & cornerC,Vector & cornerD,float fade)75 void Wall::drawWall(Vector &cornerA, Vector &cornerB,
76 						 Vector &cornerC, Vector &cornerD,
77 						 float fade)
78 {
79 	if (fade <= 0.0f) return;
80 
81 	int rot = 0;//int(fade * 75) % 2;
82 	float pos = float(int(fade * 75) % 2) * 5.0f;
83 
84 	Vector &wallColor = ScorchedClient::instance()->getOptionsTransient().getWallColor();
85 	glColor4f(wallColor[0], wallColor[1], wallColor[2], fade);
86 	glBegin(GL_QUADS);
87 		// Don't draw the wall if we are behind it
88 		// as its z-ordering obscures other objects
89 		/*switch(rot)
90 		{
91 		case 0: glTexCoord2f(20.0f + pos, 20.0f + pos); break;
92 		case 1: glTexCoord2f(0.0f + pos, 20.0f + pos); break;
93 		}
94 		glVertex3fv(cornerA);
95 		switch(rot)
96 		{
97 		case 0: glTexCoord2f(0.0f + pos, 20.0f + pos); break;
98 		case 1: glTexCoord2f(0.0f + pos, 0.0f + pos); break;
99 		}
100 		glVertex3fv(cornerB);
101 		switch(rot)
102 		{
103 		case 0: glTexCoord2f(0.0f, 0.0f); break;
104 		case 1: glTexCoord2f(20.0f, 0.0f); break;
105 		}
106 		glVertex3fv(cornerC);
107 		switch(rot)
108 		{
109 		case 0: glTexCoord2f(20.0f, 0.0f); break;
110 		case 1: glTexCoord2f(20.0f, 20.0f); break;
111 		}
112 		glVertex3fv(cornerD);*/
113 
114 		switch(rot)
115 		{
116 		case 0: glTexCoord2f(20.0f + pos, 0.0f + pos); break;
117 		case 1: glTexCoord2f(20.0f + pos, 20.0f + pos); break;
118 		}
119 		glVertex3fv(cornerD);
120 		switch(rot)
121 		{
122 		case 0: glTexCoord2f(0.0f + pos, 0.0f + pos); break;
123 		case 1: glTexCoord2f(20.0f + pos, 0.0f + pos); break;
124 		}
125 		glVertex3fv(cornerC);
126 		switch(rot)
127 		{
128 		case 0: glTexCoord2f(0.0f, 20.0f); break;
129 		case 1: glTexCoord2f(0.0f, 0.0f); break;
130 		}
131 		glVertex3fv(cornerB);
132 		switch(rot)
133 		{
134 		case 0: glTexCoord2f(20.0f, 20.0f); break;
135 		case 1: glTexCoord2f(0.0f, 20.0f); break;
136 		}
137 		glVertex3fv(cornerA);
138 	glEnd();
139 }
140 
wallHit(Vector & position,OptionsTransient::WallSide side)141 void Wall::wallHit(Vector &position, OptionsTransient::WallSide side)
142 {
143 	fadeTime_[side] = 1.0f;
144 	CACHE_SOUND(sound, S3D::getModFile("data/wav/shield/hit2.wav"));
145 	SoundUtils::playAbsoluteSound(VirtualSoundPriority::eAction,
146 		sound, position);
147 }
148 
simulate(float time)149 void Wall::simulate(float time)
150 {
151 	fadeTime_[OptionsTransient::LeftSide] -= time / 2.0f;
152 	fadeTime_[OptionsTransient::BotSide] -= time / 2.0f;
153 	fadeTime_[OptionsTransient::TopSide] -= time / 2.0f;
154 	fadeTime_[OptionsTransient::RightSide] -= time / 2.0f;
155 }
156