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