author | unc0rr |
Sat, 08 Jul 2006 21:40:03 +0000 | |
changeset 74 | 42257fee61ae |
parent 72 | aeb2ac1878dc |
child 79 | 29b477319854 |
permissions | -rw-r--r-- |
51 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*) |
|
33 |
||
34 |
program hwengine; |
|
35 |
{$APPTYPE CONSOLE} |
|
36 |
uses |
|
37 |
SDLh, |
|
38 |
uConsts in 'uConsts.pas', |
|
39 |
uGame in 'uGame.pas', |
|
40 |
uMisc in 'uMisc.pas', |
|
41 |
uStore in 'uStore.pas', |
|
42 |
uWorld in 'uWorld.pas', |
|
43 |
uIO in 'uIO.pas', |
|
44 |
uGears in 'uGears.pas', |
|
45 |
uConsole in 'uConsole.pas', |
|
46 |
uKeys in 'uKeys.pas', |
|
47 |
uTeams in 'uTeams.pas', |
|
48 |
uSound in 'uSound.pas', |
|
49 |
uRandom in 'uRandom.pas', |
|
50 |
uAI in 'uAI.pas', |
|
51 |
uCollisions in 'uCollisions.pas', |
|
52 |
uLand in 'uLand.pas', |
|
53 |
uLandTemplates in 'uLandTemplates.pas', |
|
54 | 54 |
uLandObjects in 'uLandObjects.pas', |
64 | 55 |
uLandGraphics in 'uLandGraphics.pas', |
56 |
uAIMisc in 'uAIMisc.pas', |
|
57 |
uAIAmmoTests in 'uAIAmmoTests.pas', |
|
58 |
uAIActions in 'uAIActions.pas'; |
|
51 | 59 |
|
60 |
{$INCLUDE options.inc} |
|
61 |
||
62 |
// also: GSHandlers.inc |
|
63 |
// CCHandlers.inc |
|
64 |
// HHHandlers.inc |
|
65 |
||
66 |
||
67 |
procedure OnDestroy; forward; |
|
68 |
||
69 |
//////////////////////////////// |
|
70 |
procedure DoTimer(Lag: integer); // - обработка таймера |
|
71 |
var s: string; |
|
72 |
begin |
|
73 |
case GameState of |
|
74 |
gsLandGen: begin |
|
75 |
GenMap; |
|
76 |
GameState:= gsStart; |
|
77 |
end; |
|
78 |
gsStart: begin |
|
79 |
AssignHHCoords; |
|
80 |
AddMiscGears; |
|
81 |
AdjustColor(cColorNearBlack); |
|
56 | 82 |
AdjustColor(cWaterColor); |
51 | 83 |
AdjustColor(cWhiteColor); |
84 |
StoreLoad; |
|
85 |
AdjustColor(cConsoleSplitterColor); |
|
86 |
ResetKbd; |
|
87 |
SoundLoad; |
|
88 |
PlayMusic; |
|
72 | 89 |
if GameType = gmtSave then |
90 |
begin |
|
91 |
isSEBackup:= isSoundEnabled; |
|
92 |
isSoundEnabled:= false |
|
93 |
end; |
|
51 | 94 |
GameState:= gsGame |
95 |
end; |
|
96 |
gsGame : begin |
|
97 |
ProcessKbd; |
|
98 |
DoGameTick(Lag); |
|
99 |
DrawWorld(Lag, SDLPrimSurface); |
|
100 |
end; |
|
101 |
gsConsole: begin |
|
102 |
DoGameTick(Lag); |
|
103 |
DrawWorld(Lag, SDLPrimSurface); |
|
104 |
DrawConsole(SDLPrimSurface); |
|
105 |
end; |
|
106 |
gsExit : begin |
|
107 |
OnDestroy; |
|
108 |
end; |
|
109 |
end; |
|
110 |
SDL_Flip(SDLPrimSurface); |
|
111 |
if flagMakeCapture then |
|
112 |
begin |
|
113 |
flagMakeCapture:= false; |
|
114 |
s:= 'hw_' + ParamStr(5) + '_' + inttostr(GameTicks) + '.bmp'; |
|
115 |
WriteLnToConsole('Saving ' + s); |
|
116 |
SDL_SaveBMP_RW(SDLPrimSurface, SDL_RWFromFile(PChar(s), 'wb'), 1) |
|
117 |
end; |
|
118 |
end; |
|
119 |
||
120 |
//////////////////// |
|
121 |
procedure OnDestroy; // - очищаем память |
|
122 |
begin |
|
123 |
{$IFDEF DEBUGFILE}AddFileLog('Freeing resources...');{$ENDIF} |
|
124 |
if isSoundEnabled then ReleaseSound; |
|
125 |
StoreRelease; |
|
126 |
CloseIPC; |
|
127 |
TTF_Quit; |
|
128 |
SDL_Quit; |
|
129 |
halt |
|
130 |
end; |
|
131 |
||
132 |
/////////////////// |
|
133 |
procedure MainLoop; |
|
134 |
var PrevTime, |
|
135 |
CurrTime: Cardinal; |
|
136 |
event: TSDL_Event; |
|
137 |
begin |
|
138 |
PrevTime:= SDL_GetTicks; |
|
139 |
repeat |
|
140 |
while SDL_PollEvent(@event) <> 0 do |
|
141 |
case event.type_ of |
|
142 |
SDL_KEYDOWN: case GameState of |
|
143 |
gsGame: if event.key.keysym.sym = 96 then |
|
144 |
begin |
|
145 |
cConsoleYAdd:= cConsoleHeight; |
|
146 |
GameState:= gsConsole |
|
147 |
end; |
|
148 |
gsConsole: KeyPressConsole(event.key.keysym.sym); |
|
149 |
end; |
|
150 |
SDL_QUITEV: isTerminated:= true |
|
151 |
end; |
|
152 |
CurrTime:= SDL_GetTicks; |
|
153 |
if PrevTime + cTimerInterval <= CurrTime then |
|
154 |
begin |
|
155 |
DoTimer(CurrTime - PrevTime); |
|
156 |
PrevTime:= CurrTime |
|
157 |
end else {sleep(1)}; |
|
158 |
IPCCheckSock |
|
159 |
until isTerminated |
|
160 |
end; |
|
161 |
||
162 |
//////////////////// |
|
163 |
procedure GetParams; |
|
164 |
var c: integer; |
|
165 |
{$IFDEF DEBUGFILE} |
|
166 |
i: integer; |
|
167 |
begin |
|
168 |
for i:= 0 to ParamCount do |
|
169 |
AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
|
170 |
{$ELSE} |
|
171 |
begin |
|
172 |
{$ENDIF} |
|
173 |
if ParamCount=6 then |
|
174 |
begin |
|
175 |
val(ParamStr(1), cScreenWidth, c); |
|
176 |
val(ParamStr(2), cScreenHeight, c); |
|
74 | 177 |
cBitsStr:= ParamStr(3); |
178 |
val(cBitsStr, cBits, c); |
|
51 | 179 |
val(ParamStr(4), ipcPort, c); |
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
180 |
cFullScreen:= ParamStr(5) = '1'; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
181 |
isSoundEnabled:= ParamStr(6) = '1'; |
51 | 182 |
end else OutError(errmsgShouldntRun, true); |
183 |
end; |
|
184 |
||
185 |
procedure ShowMainWindow; |
|
186 |
var flags: Longword; |
|
187 |
begin |
|
188 |
flags:= SDL_HWSURFACE or SDL_DOUBLEBUF or SDL_HWACCEL; |
|
189 |
if cFullScreen then flags:= flags or SDL_FULLSCREEN |
|
190 |
else SDL_WM_SetCaption('Hedgewars', nil); |
|
191 |
SDLPrimSurface:= SDL_SetVideoMode(cScreenWidth, cScreenHeight, cBits, flags); |
|
192 |
TryDo(SDLPrimSurface <> nil, errmsgCreateSurface, true); |
|
193 |
PixelFormat:= SDLPrimSurface.format; |
|
194 |
SDL_ShowCursor(0); |
|
195 |
end; |
|
196 |
//////////////////////////////////////////////////////////////////////////////// |
|
197 |
/////////////////////////////// m a i n //////////////////////////////////////// |
|
198 |
//////////////////////////////////////////////////////////////////////////////// |
|
199 |
||
200 |
begin |
|
74 | 201 |
WriteLnToConsole('-= HedgeWars 0.2 =-'); |
51 | 202 |
WriteLnToConsole(' -= by unC0Rr =- '); |
203 |
GetParams; |
|
204 |
Randomize; |
|
205 |
||
206 |
WriteToConsole('Init SDL... '); |
|
207 |
SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true); |
|
208 |
WriteLnToConsole(msgOK); |
|
209 |
||
210 |
WriteToConsole('Init SDL_ttf... '); |
|
211 |
SDLTry(TTF_Init >= 0, true); |
|
212 |
WriteLnToConsole(msgOK); |
|
213 |
||
214 |
ShowMainWindow; |
|
215 |
||
216 |
InitKbdKeyTable; |
|
217 |
InitIPC; |
|
218 |
WriteLnToConsole(msgGettingConfig); |
|
219 |
SendIPCAndWaitReply('C'); // запрос конфига игры |
|
220 |
InitTeams; |
|
221 |
||
222 |
if isSoundEnabled then InitSound; |
|
223 |
InitWorld; |
|
224 |
||
225 |
StoreInit; |
|
226 |
||
227 |
isDeveloperMode:= false; |
|
228 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
229 |
TryDo(InitStepsFlags = cifAllInited, |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
230 |
'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
231 |
true); |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
232 |
|
51 | 233 |
MainLoop |
234 |
||
235 |
end. |