author | unc0rr |
Sun, 10 Dec 2006 15:55:53 +0000 | |
changeset 295 | 8834f3cb620e |
parent 284 | 22ce72bd637f |
child 296 | 607912ccc5af |
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; |
|
295 | 68 |
cCaseFactor : Longword = 3; {1..10} |
4 | 69 |
cFullScreen : boolean = true; |
80 | 70 |
cLocaleFName : shortstring = 'en.txt'; |
81 | 71 |
cSeed : shortstring = ''; |
174 | 72 |
cInitVolume : integer = 128; |
73 |
cVolumeDelta : integer = 0; |
|
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; |
|
4 | 108 |
|
109 |
var CursorPoint: TPoint; |
|
110 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
111 |
||
112 |
implementation |
|
100 | 113 |
uses uConsole, uStore, uIO{$IFDEF FPC}, Math{$ENDIF}; |
208 | 114 |
var KBnum: Longword = 0; |
4 | 115 |
{$IFDEF DEBUGFILE} |
116 |
var f: textfile; |
|
117 |
{$ENDIF} |
|
118 |
||
108 | 119 |
function hwSign(r: Double): integer; |
4 | 120 |
begin |
121 |
if r < 0 then Result:= -1 else Result:= 1 |
|
122 |
end; |
|
123 |
||
124 |
function Min(a, b: integer): integer; |
|
125 |
begin |
|
126 |
if a < b then Result:= a else Result:= b |
|
127 |
end; |
|
128 |
||
129 |
function Max(a, b: integer): integer; |
|
130 |
begin |
|
131 |
if a > b then Result:= a else Result:= b |
|
132 |
end; |
|
133 |
||
134 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
135 |
begin |
|
136 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 137 |
WriteLnToConsole(Msg); |
4 | 138 |
if isFatalError then |
139 |
begin |
|
53 | 140 |
SendIPC('E' + GetLastConsoleLine); |
4 | 141 |
SDL_Quit; |
142 |
halt(1) |
|
53 | 143 |
end |
4 | 144 |
end; |
145 |
||
146 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
147 |
begin |
|
70 | 148 |
if not Assert then OutError(Msg, isFatal) |
4 | 149 |
end; |
150 |
||
151 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
152 |
begin |
|
153 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
154 |
end; |
|
155 |
||
188 | 156 |
procedure AdjustColor(var Color: Longword); |
4 | 157 |
begin |
158 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
159 |
end; |
|
160 |
||
161 |
function IntToStr(n: integer): shortstring; |
|
162 |
begin |
|
163 |
str(n, Result) |
|
164 |
end; |
|
165 |
||
107 | 166 |
function FloatToStr(n: Double): shortstring; |
4 | 167 |
begin |
53 | 168 |
str(n:5:5, Result) |
4 | 169 |
end; |
170 |
||
100 | 171 |
{$IFNDEF FPC} |
107 | 172 |
function arctan2(const Y, X: Double): Double; |
4 | 173 |
asm |
174 |
fld Y |
|
175 |
fld X |
|
176 |
fpatan |
|
177 |
fwait |
|
178 |
end; |
|
100 | 179 |
{$ENDIF} |
4 | 180 |
|
181 |
function DxDy2Angle32(const _dY, _dX: Extended): integer; |
|
100 | 182 |
const _16divPI: Extended = 16/pi; |
183 |
begin |
|
184 |
Result:= trunc(arctan2(_dY, _dX) * _16divPI) and $1f |
|
4 | 185 |
end; |
186 |
||
100 | 187 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
188 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
|
189 |
begin |
|
190 |
Result:= trunc(arctan2(_dY, _dX) * MaxAngleDivPI) mod cMaxAngle |
|
191 |
end; |
|
4 | 192 |
|
208 | 193 |
procedure SetKB(n: Longword); |
194 |
begin |
|
195 |
KBnum:= n |
|
196 |
end; |
|
197 |
||
198 |
procedure SendKB; |
|
199 |
var s: shortstring; |
|
200 |
begin |
|
201 |
if KBnum <> 0 then |
|
202 |
begin |
|
203 |
s:= 'K' + inttostr(KBnum); |
|
204 |
SendIPCRaw(@s, Length(s) + 1) |
|
205 |
end |
|
206 |
end; |
|
207 |
||
4 | 208 |
{$IFDEF DEBUGFILE} |
209 |
procedure AddFileLog(s: shortstring); |
|
210 |
begin |
|
211 |
writeln(f, GameTicks: 6, ': ', s); |
|
212 |
flush(f) |
|
213 |
end; |
|
214 |
||
24 | 215 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
216 |
begin |
|
217 |
Result:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
218 |
end; |
|
219 |
||
4 | 220 |
initialization |
108 | 221 |
AssignFile(f, 'debug.txt'); |
4 | 222 |
rewrite(f); |
17 | 223 |
|
4 | 224 |
finalization |
225 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
|
226 |
Flush(f); |
|
227 |
closefile(f) |
|
228 |
{$ENDIF} |
|
229 |
||
230 |
end. |