author | unc0rr |
Thu, 14 Dec 2006 20:06:46 +0000 | |
changeset 300 | be94799f33d2 |
parent 296 | 607912ccc5af |
child 304 | 8096e69e839e |
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; |
4 | 74 |
|
75 |
const |
|
76 |
cMaxPower = 1500; |
|
77 |
cMaxAngle = 2048; |
|
78 |
cPowerDivisor = 1500; |
|
79 |
||
80 |
var |
|
81 |
cSendEmptyPacketTime : LongWord = 2000; |
|
82 |
cSendCursorPosTime : LongWord = 50; |
|
13 | 83 |
ShowCrosshair : boolean; |
4 | 84 |
|
85 |
flagMakeCapture: boolean = false; |
|
86 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
87 |
InitStepsFlags: Longword = 0; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
88 |
|
79 | 89 |
AttackBar: integer = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 90 |
|
108 | 91 |
function hwSign(r: Double): integer; |
4 | 92 |
function Min(a, b: integer): integer; |
93 |
function Max(a, b: integer): integer; |
|
94 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
95 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
96 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
97 |
function IntToStr(n: integer): shortstring; |
|
107 | 98 |
function FloatToStr(n: Double): shortstring; |
4 | 99 |
function DxDy2Angle32(const _dY, _dX: Extended): integer; |
100 | 100 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
4 | 101 |
procedure AdjustColor(var Color: Longword); |
102 |
{$IFDEF DEBUGFILE} |
|
103 |
procedure AddFileLog(s: shortstring); |
|
24 | 104 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
4 | 105 |
{$ENDIF} |
208 | 106 |
procedure SetKB(n: Longword); |
107 |
procedure SendKB; |
|
300 | 108 |
procedure SetLittle(var r: Double); |
4 | 109 |
|
110 |
var CursorPoint: TPoint; |
|
111 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
112 |
||
113 |
implementation |
|
100 | 114 |
uses uConsole, uStore, uIO{$IFDEF FPC}, Math{$ENDIF}; |
208 | 115 |
var KBnum: Longword = 0; |
4 | 116 |
{$IFDEF DEBUGFILE} |
117 |
var f: textfile; |
|
118 |
{$ENDIF} |
|
119 |
||
108 | 120 |
function hwSign(r: Double): integer; |
4 | 121 |
begin |
122 |
if r < 0 then Result:= -1 else Result:= 1 |
|
123 |
end; |
|
124 |
||
125 |
function Min(a, b: integer): integer; |
|
126 |
begin |
|
127 |
if a < b then Result:= a else Result:= b |
|
128 |
end; |
|
129 |
||
130 |
function Max(a, b: integer): integer; |
|
131 |
begin |
|
132 |
if a > b then Result:= a else Result:= b |
|
133 |
end; |
|
134 |
||
135 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
136 |
begin |
|
137 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 138 |
WriteLnToConsole(Msg); |
4 | 139 |
if isFatalError then |
140 |
begin |
|
53 | 141 |
SendIPC('E' + GetLastConsoleLine); |
4 | 142 |
SDL_Quit; |
143 |
halt(1) |
|
53 | 144 |
end |
4 | 145 |
end; |
146 |
||
147 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
148 |
begin |
|
70 | 149 |
if not Assert then OutError(Msg, isFatal) |
4 | 150 |
end; |
151 |
||
152 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
153 |
begin |
|
154 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
155 |
end; |
|
156 |
||
188 | 157 |
procedure AdjustColor(var Color: Longword); |
4 | 158 |
begin |
159 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
160 |
end; |
|
161 |
||
162 |
function IntToStr(n: integer): shortstring; |
|
163 |
begin |
|
164 |
str(n, Result) |
|
165 |
end; |
|
166 |
||
107 | 167 |
function FloatToStr(n: Double): shortstring; |
4 | 168 |
begin |
53 | 169 |
str(n:5:5, Result) |
4 | 170 |
end; |
171 |
||
100 | 172 |
{$IFNDEF FPC} |
107 | 173 |
function arctan2(const Y, X: Double): Double; |
4 | 174 |
asm |
175 |
fld Y |
|
176 |
fld X |
|
177 |
fpatan |
|
178 |
fwait |
|
179 |
end; |
|
100 | 180 |
{$ENDIF} |
4 | 181 |
|
182 |
function DxDy2Angle32(const _dY, _dX: Extended): integer; |
|
100 | 183 |
const _16divPI: Extended = 16/pi; |
184 |
begin |
|
185 |
Result:= trunc(arctan2(_dY, _dX) * _16divPI) and $1f |
|
4 | 186 |
end; |
187 |
||
100 | 188 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
189 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
|
190 |
begin |
|
191 |
Result:= trunc(arctan2(_dY, _dX) * MaxAngleDivPI) mod cMaxAngle |
|
192 |
end; |
|
4 | 193 |
|
208 | 194 |
procedure SetKB(n: Longword); |
195 |
begin |
|
196 |
KBnum:= n |
|
197 |
end; |
|
198 |
||
199 |
procedure SendKB; |
|
200 |
var s: shortstring; |
|
201 |
begin |
|
202 |
if KBnum <> 0 then |
|
203 |
begin |
|
204 |
s:= 'K' + inttostr(KBnum); |
|
205 |
SendIPCRaw(@s, Length(s) + 1) |
|
206 |
end |
|
207 |
end; |
|
208 |
||
300 | 209 |
procedure SetLittle(var r: Double); |
210 |
begin |
|
211 |
if r >= 0 then r:= cLittle else r:= - cLittle |
|
212 |
end; |
|
213 |
||
4 | 214 |
{$IFDEF DEBUGFILE} |
215 |
procedure AddFileLog(s: shortstring); |
|
216 |
begin |
|
217 |
writeln(f, GameTicks: 6, ': ', s); |
|
218 |
flush(f) |
|
219 |
end; |
|
220 |
||
24 | 221 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
222 |
begin |
|
223 |
Result:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
224 |
end; |
|
225 |
||
4 | 226 |
initialization |
108 | 227 |
AssignFile(f, 'debug.txt'); |
4 | 228 |
rewrite(f); |
17 | 229 |
|
4 | 230 |
finalization |
231 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
|
232 |
Flush(f); |
|
233 |
closefile(f) |
|
234 |
{$ENDIF} |
|
235 |
||
236 |
end. |