author | unc0rr |
Thu, 12 Oct 2006 18:52:00 +0000 | |
changeset 196 | 993cf173218b |
parent 188 | a7c2a61524c2 |
child 208 | a049157d673a |
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; |
|
26 |
isSoundEnabled : boolean = true; |
|
72 | 27 |
isSEBackup : boolean = true; |
4 | 28 |
isInMultiShoot : boolean = false; |
29 |
||
39 | 30 |
GameState : TGameState = Low(TGameState); |
4 | 31 |
GameType : TGameType = gmtLocal; |
32 |
GameFlags : Longword = 0; |
|
33 |
TurnTimeLeft : Longword = 0; |
|
95 | 34 |
cHedgehogTurnTime: Longword = 45000; |
143 | 35 |
cMaxAIThinkTime : Longword = 5000; |
4 | 36 |
|
37 |
cCloudsNumber : integer = 9; |
|
38 |
cConsoleHeight : integer = 320; |
|
39 |
cConsoleYAdd : integer = 0; |
|
188 | 40 |
cTimerInterval : Longword = 5; |
4 | 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; |
4 | 48 |
cScreenEdgesDist : integer = 240; |
47 | 49 |
cTeamHealthWidth : integer = 128; |
4 | 50 |
|
51 |
GameTicks : LongWord = 0; |
|
52 |
||
188 | 53 |
cSkyColor : Longword = 0; |
54 |
cWaterColor : Longword = $005ACE; |
|
55 |
cWhiteColor : Longword = $FFFFFF; |
|
56 |
cConsoleSplitterColor : Longword = $FF0000; |
|
57 |
cColorNearBlack : Longword = 16; |
|
4 | 58 |
cExplosionBorderColor : LongWord = $808080; |
59 |
||
108 | 60 |
cDrownSpeed : Double = 0.06; |
61 |
cMaxWindSpeed : Double = 0.0005; |
|
62 |
cWindSpeed : Double = 0.0001; |
|
63 |
cGravity : Double = 0.0005; |
|
4 | 64 |
|
65 |
cShowFPS : boolean = true; |
|
66 |
cFullScreen : boolean = true; |
|
80 | 67 |
cLocaleFName : shortstring = 'en.txt'; |
81 | 68 |
cSeed : shortstring = ''; |
174 | 69 |
cInitVolume : integer = 128; |
70 |
cVolumeDelta : integer = 0; |
|
4 | 71 |
|
72 |
const |
|
73 |
cMaxPower = 1500; |
|
74 |
cMaxAngle = 2048; |
|
75 |
cPowerDivisor = 1500; |
|
76 |
||
77 |
var |
|
78 |
cSendEmptyPacketTime : LongWord = 2000; |
|
79 |
cSendCursorPosTime : LongWord = 50; |
|
13 | 80 |
ShowCrosshair : boolean; |
4 | 81 |
|
82 |
flagMakeCapture: boolean = false; |
|
83 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
84 |
InitStepsFlags: Longword = 0; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
85 |
|
79 | 86 |
AttackBar: integer = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 87 |
|
108 | 88 |
function hwSign(r: Double): integer; |
4 | 89 |
function Min(a, b: integer): integer; |
90 |
function Max(a, b: integer): integer; |
|
91 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
92 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
93 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
94 |
function IntToStr(n: integer): shortstring; |
|
107 | 95 |
function FloatToStr(n: Double): shortstring; |
4 | 96 |
function DxDy2Angle32(const _dY, _dX: Extended): integer; |
100 | 97 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
4 | 98 |
procedure AdjustColor(var Color: Longword); |
99 |
{$IFDEF DEBUGFILE} |
|
100 |
procedure AddFileLog(s: shortstring); |
|
24 | 101 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
4 | 102 |
{$ENDIF} |
103 |
||
104 |
var CursorPoint: TPoint; |
|
105 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
106 |
||
107 |
implementation |
|
100 | 108 |
uses uConsole, uStore, uIO{$IFDEF FPC}, Math{$ENDIF}; |
4 | 109 |
{$IFDEF DEBUGFILE} |
110 |
var f: textfile; |
|
111 |
{$ENDIF} |
|
112 |
||
108 | 113 |
function hwSign(r: Double): integer; |
4 | 114 |
begin |
115 |
if r < 0 then Result:= -1 else Result:= 1 |
|
116 |
end; |
|
117 |
||
118 |
function Min(a, b: integer): integer; |
|
119 |
begin |
|
120 |
if a < b then Result:= a else Result:= b |
|
121 |
end; |
|
122 |
||
123 |
function Max(a, b: integer): integer; |
|
124 |
begin |
|
125 |
if a > b then Result:= a else Result:= b |
|
126 |
end; |
|
127 |
||
128 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
129 |
begin |
|
130 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 131 |
WriteLnToConsole(Msg); |
4 | 132 |
if isFatalError then |
133 |
begin |
|
53 | 134 |
SendIPC('E' + GetLastConsoleLine); |
4 | 135 |
SDL_Quit; |
136 |
halt(1) |
|
53 | 137 |
end |
4 | 138 |
end; |
139 |
||
140 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
141 |
begin |
|
70 | 142 |
if not Assert then OutError(Msg, isFatal) |
4 | 143 |
end; |
144 |
||
145 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
146 |
begin |
|
147 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
148 |
end; |
|
149 |
||
188 | 150 |
procedure AdjustColor(var Color: Longword); |
4 | 151 |
begin |
152 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
153 |
end; |
|
154 |
||
155 |
function IntToStr(n: integer): shortstring; |
|
156 |
begin |
|
157 |
str(n, Result) |
|
158 |
end; |
|
159 |
||
107 | 160 |
function FloatToStr(n: Double): shortstring; |
4 | 161 |
begin |
53 | 162 |
str(n:5:5, Result) |
4 | 163 |
end; |
164 |
||
100 | 165 |
{$IFNDEF FPC} |
107 | 166 |
function arctan2(const Y, X: Double): Double; |
4 | 167 |
asm |
168 |
fld Y |
|
169 |
fld X |
|
170 |
fpatan |
|
171 |
fwait |
|
172 |
end; |
|
100 | 173 |
{$ENDIF} |
4 | 174 |
|
175 |
function DxDy2Angle32(const _dY, _dX: Extended): integer; |
|
100 | 176 |
const _16divPI: Extended = 16/pi; |
177 |
begin |
|
178 |
Result:= trunc(arctan2(_dY, _dX) * _16divPI) and $1f |
|
4 | 179 |
end; |
180 |
||
100 | 181 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
182 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
|
183 |
begin |
|
184 |
Result:= trunc(arctan2(_dY, _dX) * MaxAngleDivPI) mod cMaxAngle |
|
185 |
end; |
|
4 | 186 |
|
187 |
{$IFDEF DEBUGFILE} |
|
188 |
procedure AddFileLog(s: shortstring); |
|
189 |
begin |
|
190 |
writeln(f, GameTicks: 6, ': ', s); |
|
191 |
flush(f) |
|
192 |
end; |
|
193 |
||
24 | 194 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
195 |
begin |
|
196 |
Result:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
197 |
end; |
|
198 |
||
4 | 199 |
initialization |
108 | 200 |
AssignFile(f, 'debug.txt'); |
4 | 201 |
rewrite(f); |
17 | 202 |
|
4 | 203 |
finalization |
204 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
|
205 |
Flush(f); |
|
206 |
closefile(f) |
|
207 |
{$ENDIF} |
|
208 |
||
209 |
end. |