author | unc0rr |
Tue, 16 Jan 2007 22:13:58 +0000 | |
changeset 346 | fc1e0a4f152c |
parent 337 | a46abb65eb0c |
child 351 | 29bc9c36ad5f |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
47 | 3 |
* Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
19 |
unit uMisc; |
|
20 |
interface |
|
21 |
uses uConsts, SDLh; |
|
22 |
{$INCLUDE options.inc} |
|
23 |
var isCursorVisible : boolean = false; |
|
24 |
isTerminated : boolean = false; |
|
25 |
isInLag : boolean = false; |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
26 |
isPaused : boolean = false; |
4 | 27 |
isSoundEnabled : boolean = true; |
72 | 28 |
isSEBackup : boolean = true; |
4 | 29 |
isInMultiShoot : boolean = false; |
30 |
||
39 | 31 |
GameState : TGameState = Low(TGameState); |
4 | 32 |
GameType : TGameType = gmtLocal; |
33 |
GameFlags : Longword = 0; |
|
34 |
TurnTimeLeft : Longword = 0; |
|
95 | 35 |
cHedgehogTurnTime: Longword = 45000; |
143 | 36 |
cMaxAIThinkTime : Longword = 5000; |
4 | 37 |
|
38 |
cCloudsNumber : integer = 9; |
|
39 |
cConsoleHeight : integer = 320; |
|
40 |
cConsoleYAdd : integer = 0; |
|
41 |
cScreenWidth : integer = 1024; |
|
42 |
cScreenHeight : integer = 768; |
|
43 |
cBits : integer = 16; |
|
74 | 44 |
cBitsStr : string[2] = '16'; |
45 |
||
4 | 46 |
cWaterLine : integer = 1024; |
75 | 47 |
cVisibleWater : integer = 128; |
284 | 48 |
cGearScrEdgesDist: integer = 240; |
49 |
cCursorEdgesDist : integer = 40; |
|
47 | 50 |
cTeamHealthWidth : integer = 128; |
4 | 51 |
|
52 |
GameTicks : LongWord = 0; |
|
53 |
||
188 | 54 |
cSkyColor : Longword = 0; |
55 |
cWaterColor : Longword = $005ACE; |
|
56 |
cWhiteColor : Longword = $FFFFFF; |
|
57 |
cConsoleSplitterColor : Longword = $FF0000; |
|
58 |
cColorNearBlack : Longword = 16; |
|
4 | 59 |
cExplosionBorderColor : LongWord = $808080; |
60 |
||
108 | 61 |
cDrownSpeed : Double = 0.06; |
62 |
cMaxWindSpeed : Double = 0.0005; |
|
63 |
cWindSpeed : Double = 0.0001; |
|
64 |
cGravity : Double = 0.0005; |
|
4 | 65 |
|
66 |
cShowFPS : boolean = true; |
|
295 | 67 |
cCaseFactor : Longword = 3; {1..10} |
4 | 68 |
cFullScreen : boolean = true; |
80 | 69 |
cLocaleFName : shortstring = 'en.txt'; |
81 | 70 |
cSeed : shortstring = ''; |
174 | 71 |
cInitVolume : integer = 128; |
72 |
cVolumeDelta : integer = 0; |
|
296 | 73 |
cTimerInterval : Longword = 5; |
308 | 74 |
cHasFocus : boolean = true; |
4 | 75 |
|
76 |
var |
|
77 |
cSendEmptyPacketTime : LongWord = 2000; |
|
78 |
cSendCursorPosTime : LongWord = 50; |
|
13 | 79 |
ShowCrosshair : boolean; |
4 | 80 |
|
81 |
flagMakeCapture: boolean = false; |
|
82 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
83 |
InitStepsFlags: Longword = 0; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
84 |
|
79 | 85 |
AttackBar: integer = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 86 |
|
108 | 87 |
function hwSign(r: Double): integer; |
4 | 88 |
function Min(a, b: integer): integer; |
89 |
function Max(a, b: integer): integer; |
|
90 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
91 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
92 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
316 | 93 |
function IntToStr(n: LongInt): shortstring; |
107 | 94 |
function FloatToStr(n: Double): shortstring; |
4 | 95 |
function DxDy2Angle32(const _dY, _dX: Extended): integer; |
100 | 96 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
4 | 97 |
procedure AdjustColor(var Color: Longword); |
98 |
{$IFDEF DEBUGFILE} |
|
99 |
procedure AddFileLog(s: shortstring); |
|
24 | 100 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
4 | 101 |
{$ENDIF} |
208 | 102 |
procedure SetKB(n: Longword); |
103 |
procedure SendKB; |
|
300 | 104 |
procedure SetLittle(var r: Double); |
306 | 105 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
4 | 106 |
|
107 |
var CursorPoint: TPoint; |
|
108 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
109 |
||
110 |
implementation |
|
100 | 111 |
uses uConsole, uStore, uIO{$IFDEF FPC}, Math{$ENDIF}; |
208 | 112 |
var KBnum: Longword = 0; |
4 | 113 |
{$IFDEF DEBUGFILE} |
114 |
var f: textfile; |
|
115 |
{$ENDIF} |
|
116 |
||
108 | 117 |
function hwSign(r: Double): integer; |
4 | 118 |
begin |
119 |
if r < 0 then Result:= -1 else Result:= 1 |
|
120 |
end; |
|
121 |
||
122 |
function Min(a, b: integer): integer; |
|
123 |
begin |
|
124 |
if a < b then Result:= a else Result:= b |
|
125 |
end; |
|
126 |
||
127 |
function Max(a, b: integer): integer; |
|
128 |
begin |
|
129 |
if a > b then Result:= a else Result:= b |
|
130 |
end; |
|
131 |
||
132 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
133 |
begin |
|
134 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 135 |
WriteLnToConsole(Msg); |
4 | 136 |
if isFatalError then |
137 |
begin |
|
53 | 138 |
SendIPC('E' + GetLastConsoleLine); |
4 | 139 |
SDL_Quit; |
140 |
halt(1) |
|
53 | 141 |
end |
4 | 142 |
end; |
143 |
||
144 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
145 |
begin |
|
70 | 146 |
if not Assert then OutError(Msg, isFatal) |
4 | 147 |
end; |
148 |
||
149 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
150 |
begin |
|
151 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
152 |
end; |
|
153 |
||
188 | 154 |
procedure AdjustColor(var Color: Longword); |
4 | 155 |
begin |
156 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
157 |
end; |
|
158 |
||
316 | 159 |
function IntToStr(n: LongInt): shortstring; |
4 | 160 |
begin |
161 |
str(n, Result) |
|
162 |
end; |
|
163 |
||
107 | 164 |
function FloatToStr(n: Double): shortstring; |
4 | 165 |
begin |
346 | 166 |
//str(n:5:5, Result) |
167 |
str(n, Result) |
|
4 | 168 |
end; |
169 |
||
100 | 170 |
{$IFNDEF FPC} |
107 | 171 |
function arctan2(const Y, X: Double): Double; |
4 | 172 |
asm |
173 |
fld Y |
|
174 |
fld X |
|
175 |
fpatan |
|
176 |
fwait |
|
177 |
end; |
|
100 | 178 |
{$ENDIF} |
4 | 179 |
|
180 |
function DxDy2Angle32(const _dY, _dX: Extended): integer; |
|
100 | 181 |
const _16divPI: Extended = 16/pi; |
182 |
begin |
|
183 |
Result:= trunc(arctan2(_dY, _dX) * _16divPI) and $1f |
|
4 | 184 |
end; |
185 |
||
100 | 186 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
187 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
|
188 |
begin |
|
189 |
Result:= trunc(arctan2(_dY, _dX) * MaxAngleDivPI) mod cMaxAngle |
|
190 |
end; |
|
4 | 191 |
|
208 | 192 |
procedure SetKB(n: Longword); |
193 |
begin |
|
194 |
KBnum:= n |
|
195 |
end; |
|
196 |
||
197 |
procedure SendKB; |
|
198 |
var s: shortstring; |
|
199 |
begin |
|
200 |
if KBnum <> 0 then |
|
201 |
begin |
|
202 |
s:= 'K' + inttostr(KBnum); |
|
203 |
SendIPCRaw(@s, Length(s) + 1) |
|
204 |
end |
|
205 |
end; |
|
206 |
||
300 | 207 |
procedure SetLittle(var r: Double); |
208 |
begin |
|
209 |
if r >= 0 then r:= cLittle else r:= - cLittle |
|
210 |
end; |
|
211 |
||
337 | 212 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
213 |
const stc: array [TStatInfoType] of char = 'rDK'; |
|
214 |
begin |
|
215 |
SendIPC('i' + stc[sit] + s) |
|
216 |
end; |
|
217 |
||
4 | 218 |
{$IFDEF DEBUGFILE} |
219 |
procedure AddFileLog(s: shortstring); |
|
220 |
begin |
|
221 |
writeln(f, GameTicks: 6, ': ', s); |
|
222 |
flush(f) |
|
223 |
end; |
|
224 |
||
24 | 225 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
226 |
begin |
|
227 |
Result:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
228 |
end; |
|
229 |
||
337 | 230 |
|
231 |
var i: integer; |
|
306 | 232 |
|
4 | 233 |
initialization |
337 | 234 |
{$I-} |
235 |
for i:= 0 to 7 do |
|
236 |
begin |
|
237 |
AssignFile(f, 'debug' + inttostr(i) + '.txt'); |
|
238 |
rewrite(f); |
|
239 |
if IOResult = 0 then break |
|
240 |
end; |
|
241 |
{$I+} |
|
17 | 242 |
|
4 | 243 |
finalization |
244 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
|
245 |
Flush(f); |
|
246 |
closefile(f) |
|
247 |
{$ENDIF} |
|
248 |
||
249 |
end. |