]> git.jsancho.org Git - lugaru.git/blob - Source/Game.cpp
Fixed a lot of warnings
[lugaru.git] / Source / Game.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program 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.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 #include "Game.h"
23 #include "openal_wrapper.h"
24 #include "SDL_thread.h"
25
26 extern int mainmenu;
27
28 int numdialogues;
29 int numdialogueboxes[max_dialogues];
30 int dialoguetype[max_dialogues];
31 int dialogueboxlocation[max_dialogues][max_dialoguelength];
32 float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
33 int dialogueboxsound[max_dialogues][max_dialoguelength];
34 char dialoguetext[max_dialogues][max_dialoguelength][128];
35 char dialoguename[max_dialogues][max_dialoguelength][64];
36 XYZ dialoguecamera[max_dialogues][max_dialoguelength];
37 XYZ participantlocation[max_dialogues][10];
38 int participantfocus[max_dialogues][max_dialoguelength];
39 int participantaction[max_dialogues][max_dialoguelength];
40 float participantyaw[max_dialogues][10];
41 XYZ participantfacing[max_dialogues][max_dialoguelength][10];
42 float dialoguecamerayaw[max_dialogues][max_dialoguelength];
43 float dialoguecamerapitch[max_dialogues][max_dialoguelength];
44 int indialogue;
45 int whichdialogue;
46 int directing;
47 float dialoguetime;
48 int dialoguegonethrough[20];
49
50 const char *pathtypenames[] = {"keepwalking", "pause"};
51 const char *editortypenames[] = {
52     "active", "sitting", "sitting wall", "sleeping",
53     "dead1", "dead2", "dead3", "dead4"
54 };
55
56 namespace Game
57 {
58 Texture terraintexture;
59 Texture terraintexture2;
60 Texture loadscreentexture;
61 Texture Maparrowtexture;
62 Texture Mapboxtexture;
63 Texture Mapcircletexture;
64 Texture cursortexture;
65 GLuint screentexture = 0;
66 GLuint screentexture2 = 0;
67 Texture Mainmenuitems[10];
68
69 int selected = 0;
70 int keyselect = 0;
71
72 int newdetail = 0;
73 int newscreenwidth = 0;
74 int newscreenheight = 0;
75
76 bool gameon = 0;
77 float deltah = 0;
78 float deltav = 0;
79 int mousecoordh = 0;
80 int mousecoordv = 0;
81 int oldmousecoordh = 0;
82 int oldmousecoordv = 0;
83 float yaw = 0;
84 float pitch = 0;
85 SkyBox *skybox = NULL;
86 bool cameramode = 0;
87 bool firstload = 0;
88
89 Texture hawktexture;
90 float hawkyaw = 0;
91 float hawkcalldelay = 0;
92 float leveltime = 0;
93 float loadtime = 0;
94
95 Model hawk;
96 XYZ hawkcoords;
97 XYZ realhawkcoords;
98
99 Model eye;
100 Model iris;
101 Model cornea;
102
103 bool stealthloading = 0;
104
105 int musictype = 0;
106
107 XYZ mapcenter;
108 float mapradius = 0;
109
110 Text *text = NULL;
111 float fps = 0;
112
113 bool editorenabled = 0;
114 int editortype = 0;
115 float editorsize = 0;
116 float editoryaw = 0;
117 float editorpitch = 0;
118
119 int tryquit = 0;
120
121 XYZ pathpoint[30];
122 int numpathpoints = 0;
123 int numpathpointconnect[30] = {};
124 int pathpointconnect[30][30] = {};
125 int pathpointselected = 0;
126
127 int endgame = 0;
128 bool scoreadded = 0;
129 int numchallengelevels = 0;
130
131 bool console = false;
132 std::string consoletext[15] = {};
133 std::string displaytext[15] = {};
134 float displaytime[15] = {};
135 float displayblinkdelay = 0;
136 bool displayblink = 0;
137 unsigned displayselected = 0;
138 float consoleblinkdelay = 0;
139 bool consoleblink = 0;
140 unsigned consoleselected = 0;
141
142 unsigned short crouchkey = 0, jumpkey = 0, forwardkey = 0, backkey = 0, leftkey = 0, rightkey = 0, drawkey = 0, throwkey = 0, attackkey = 0;
143 unsigned short consolekey = 0;
144
145 int loading = 0;
146
147 int oldenvironment = 0;
148 int targetlevel = 0;
149 float changedelay = 0;
150
151 bool waiting = false;
152 Account* accountactive = NULL;
153 }
154
155 void Game::fireSound(int sound)
156 {
157     emit_sound_at(sound);
158 }
159
160 void Game::inputText(string& str, unsigned* charselected)
161 {
162     SDL_Event evenement;
163
164     if (!waiting) {
165         SDL_StartTextInput();
166         waiting = true;
167     }
168
169     while (SDL_PollEvent(&evenement)) {
170         switch (evenement.type) {
171         case SDL_TEXTEDITING:
172             /* FIXME - We should handle this for complete input method support */
173             break;
174         case SDL_TEXTINPUT:
175             str.insert(*charselected, evenement.text.text);
176             (*charselected) += strlen(evenement.text.text);
177             break;
178         case SDL_KEYDOWN:
179             if (evenement.key.keysym.sym == SDLK_ESCAPE) {
180                 str.clear();
181                 *charselected = 0;
182                 waiting = false;
183             } else if (evenement.key.keysym.sym == SDLK_BACKSPACE) {
184                 if ((*charselected) > 0) {
185                     (*charselected)--;
186                     str.erase(*charselected, 1);
187                 }
188             } else if (evenement.key.keysym.sym == SDLK_DELETE) {
189                 if ((*charselected) < str.size()) {
190                     str.erase(*charselected, 1);
191                 }
192             } else if (evenement.key.keysym.sym == SDLK_HOME) {
193                 (*charselected) = 0;
194             } else if (evenement.key.keysym.sym == SDLK_END) {
195                 (*charselected) = str.size();
196             } else if (evenement.key.keysym.sym == SDLK_LEFT) {
197                 if ((*charselected) != 0)
198                     (*charselected)--;
199             } else if (evenement.key.keysym.sym == SDLK_RIGHT) {
200                 if ((*charselected) < str.size())
201                     (*charselected)++;
202             } else if (evenement.key.keysym.sym == SDLK_RETURN) {
203                 waiting = false;
204             }
205             break;
206         }
207     }
208
209     if (!waiting) {
210         SDL_StopTextInput();
211     }
212 }
213
214 int setKeySelected_thread(void* data)
215 {
216     using namespace Game;
217     int scancode = -1;
218     SDL_Event evenement;
219     while (scancode == -1) {
220         SDL_WaitEvent(&evenement);
221         switch (evenement.type) {
222         case SDL_KEYDOWN:
223             scancode = evenement.key.keysym.scancode;
224             break;
225         case SDL_MOUSEBUTTONDOWN:
226             scancode = SDL_NUM_SCANCODES + evenement.button.button;
227             break;
228         default:
229             break;
230         }
231     }
232     if (scancode != SDL_SCANCODE_ESCAPE) {
233         fireSound();
234         switch (keyselect) {
235         case 0:
236             forwardkey = scancode;
237             break;
238         case 1:
239             backkey = scancode;
240             break;
241         case 2:
242             leftkey = scancode;
243             break;
244         case 3:
245             rightkey = scancode;
246             break;
247         case 4:
248             crouchkey = scancode;
249             break;
250         case 5:
251             jumpkey = scancode;
252             break;
253         case 6:
254             drawkey = scancode;
255             break;
256         case 7:
257             throwkey = scancode;
258             break;
259         case 8:
260             attackkey = scancode;
261             break;
262         case 9:
263             consolekey = scancode;
264             break;
265         default:
266             break;
267         }
268     }
269     keyselect = -1;
270     waiting = false;
271     LoadMenu();
272     return 0;
273 }
274
275 void Game::setKeySelected()
276 {
277     waiting = true;
278     printf("launch thread\n");
279     SDL_Thread* thread = SDL_CreateThread(setKeySelected_thread, NULL, NULL);
280     if ( thread == NULL ) {
281         fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());
282         waiting = false;
283         return;
284     }
285 }