author | unc0rr |
Tue, 05 Dec 2006 17:27:27 +0000 | |
changeset 288 | 929c44745fd9 |
parent 284 | 22ce72bd637f |
child 295 | 8834f3cb620e |
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; |
|
188 | 41 |
cTimerInterval : Longword = 5; |
4 | 42 |
cScreenWidth : integer = 1024; |
43 |
cScreenHeight : integer = 768; |
|
44 |
cBits : integer = 16; |
|
74 | 45 |
cBitsStr : string[2] = '16'; |
46 |
||
4 | 47 |
cWaterLine : integer = 1024; |
75 | 48 |
cVisibleWater : integer = 128; |
284 | 49 |
cGearScrEdgesDist: integer = 240; |
50 |
cCursorEdgesDist : integer = 40; |
|
47 | 51 |
cTeamHealthWidth : integer = 128; |
4 | 52 |
|
53 |
GameTicks : LongWord = 0; |
|
54 |
||
188 | 55 |
cSkyColor : Longword = 0; |
56 |
cWaterColor : Longword = $005ACE; |
|
57 |
cWhiteColor : Longword = $FFFFFF; |
|
58 |
cConsoleSplitterColor : Longword = $FF0000; |
|
59 |
cColorNearBlack : Longword = 16; |
|
4 | 60 |
cExplosionBorderColor : LongWord = $808080; |
61 |
||
108 | 62 |
cDrownSpeed : Double = 0.06; |
63 |
cMaxWindSpeed : Double = 0.0005; |
|
64 |
cWindSpeed : Double = 0.0001; |
|
65 |
cGravity : Double = 0.0005; |
|
4 | 66 |
|
67 |
cShowFPS : boolean = true; |
|
68 |
cFullScreen : boolean = true; |
|
80 | 69 |
cLocaleFName : shortstring = 'en.txt'; |
81 | 70 |
cSeed : shortstring = ''; |
174 | 71 |
cInitVolume : integer = 128; |
72 |
cVolumeDelta : integer = 0; |
|
4 | 73 |
|
74 |
const |
|
75 |
cMaxPower = 1500; |
|
76 |
cMaxAngle = 2048; |
|
77 |
cPowerDivisor = 1500; |
|
78 |
||
79 |
var |
|
80 |
cSendEmptyPacketTime : LongWord = 2000; |
|
81 |
cSendCursorPosTime : LongWord = 50; |
|
13 | 82 |
ShowCrosshair : boolean; |
4 | 83 |
|
84 |
flagMakeCapture: boolean = false; |
|
85 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
86 |
InitStepsFlags: Longword = 0; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
87 |
|
79 | 88 |
AttackBar: integer = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 89 |
|
108 | 90 |
function hwSign(r: Double): integer; |
4 | 91 |
function Min(a, b: integer): integer; |
92 |
function Max(a, b: integer): integer; |
|
93 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
94 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
95 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
96 |
function IntToStr(n: integer): shortstring; |
|
107 | 97 |
function FloatToStr(n: Double): shortstring; |
4 | 98 |
function DxDy2Angle32(const _dY, _dX: Extended): integer; |
100 | 99 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
4 | 100 |
procedure AdjustColor(var Color: Longword); |
101 |
{$IFDEF DEBUGFILE} |
|
102 |
procedure AddFileLog(s: shortstring); |
|
24 | 103 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
4 | 104 |
{$ENDIF} |
208 | 105 |
procedure SetKB(n: Longword); |
106 |
procedure SendKB; |
|
4 | 107 |
|
108 |
var CursorPoint: TPoint; |
|
109 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
110 |
||
111 |
implementation |
|
100 | 112 |
uses uConsole, uStore, uIO{$IFDEF FPC}, Math{$ENDIF}; |
208 | 113 |
var KBnum: Longword = 0; |
4 | 114 |
{$IFDEF DEBUGFILE} |
115 |
var f: textfile; |
|
116 |
{$ENDIF} |
|
117 |
||
108 | 118 |
function hwSign(r: Double): integer; |
4 | 119 |
begin |
120 |
if r < 0 then Result:= -1 else Result:= 1 |
|
121 |
end; |
|
122 |
||
123 |
function Min(a, b: integer): integer; |
|
124 |
begin |
|
125 |
if a < b then Result:= a else Result:= b |
|
126 |
end; |
|
127 |
||
128 |
function Max(a, b: integer): integer; |
|
129 |
begin |
|
130 |
if a > b then Result:= a else Result:= b |
|
131 |
end; |
|
132 |
||
133 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
134 |
begin |
|
135 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 136 |
WriteLnToConsole(Msg); |
4 | 137 |
if isFatalError then |
138 |
begin |
|
53 | 139 |
SendIPC('E' + GetLastConsoleLine); |
4 | 140 |
SDL_Quit; |
141 |
halt(1) |
|
53 | 142 |
end |
4 | 143 |
end; |
144 |
||
145 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
146 |
begin |
|
70 | 147 |
if not Assert then OutError(Msg, isFatal) |
4 | 148 |
end; |
149 |
||
150 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
151 |
begin |
|
152 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
153 |
end; |
|
154 |
||
188 | 155 |
procedure AdjustColor(var Color: Longword); |
4 | 156 |
begin |
157 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
158 |
end; |
|
159 |
||
160 |
function IntToStr(n: integer): shortstring; |
|
161 |
begin |
|
162 |
str(n, Result) |
|
163 |
end; |
|
164 |
||
107 | 165 |
function FloatToStr(n: Double): shortstring; |
4 | 166 |
begin |
53 | 167 |
str(n:5:5, 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 |
||
4 | 207 |
{$IFDEF DEBUGFILE} |
208 |
procedure AddFileLog(s: shortstring); |
|
209 |
begin |
|
210 |
writeln(f, GameTicks: 6, ': ', s); |
|
211 |
flush(f) |
|
212 |
end; |
|
213 |
||
24 | 214 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
215 |
begin |
|
216 |
Result:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
217 |
end; |
|
218 |
||
4 | 219 |
initialization |
108 | 220 |
AssignFile(f, 'debug.txt'); |
4 | 221 |
rewrite(f); |
17 | 222 |
|
4 | 223 |
finalization |
224 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
|
225 |
Flush(f); |
|
226 |
closefile(f) |
|
227 |
{$ENDIF} |
|
228 |
||
229 |
end. |