author | unc0rr |
Wed, 30 May 2007 20:48:57 +0000 | |
changeset 533 | eebb7684ac22 |
parent 529 | 812682c1ab62 |
child 534 | 92fb2b0d5117 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
393 | 3 |
* Copyright (c) 2004-2007 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 |
|
351 | 21 |
uses uConsts, SDLh, uFloat; |
4 | 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; |
433 | 36 |
cMaxAIThinkTime : Longword = 9000; |
4 | 37 |
|
371 | 38 |
cCloudsNumber : LongInt = 9; |
39 |
cConsoleHeight : LongInt = 320; |
|
40 |
cConsoleYAdd : LongInt = 0; |
|
41 |
cScreenWidth : LongInt = 1024; |
|
42 |
cScreenHeight : LongInt = 768; |
|
43 |
cBits : LongInt = 16; |
|
74 | 44 |
cBitsStr : string[2] = '16'; |
45 |
||
371 | 46 |
cWaterLine : LongInt = 1024; |
47 |
cVisibleWater : LongInt = 128; |
|
48 |
cGearScrEdgesDist: LongInt = 240; |
|
49 |
cCursorEdgesDist : LongInt = 40; |
|
50 |
cTeamHealthWidth : LongInt = 128; |
|
529 | 51 |
cAltDamage : boolean = true; |
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 |
||
62 |
cShowFPS : boolean = true; |
|
295 | 63 |
cCaseFactor : Longword = 3; {1..10} |
4 | 64 |
cFullScreen : boolean = true; |
80 | 65 |
cLocaleFName : shortstring = 'en.txt'; |
81 | 66 |
cSeed : shortstring = ''; |
371 | 67 |
cInitVolume : LongInt = 128; |
68 |
cVolumeDelta : LongInt = 0; |
|
296 | 69 |
cTimerInterval : Longword = 5; |
351 | 70 |
cHasFocus : boolean = true; |
4 | 71 |
|
72 |
var |
|
73 |
cSendEmptyPacketTime : LongWord = 2000; |
|
74 |
cSendCursorPosTime : LongWord = 50; |
|
13 | 75 |
ShowCrosshair : boolean; |
351 | 76 |
cDrownSpeed, |
77 |
cMaxWindSpeed, |
|
78 |
cWindSpeed, |
|
79 |
cGravity: hwFloat; |
|
4 | 80 |
|
81 |
flagMakeCapture: boolean = false; |
|
82 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
83 |
InitStepsFlags: Longword = 0; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
84 |
|
371 | 85 |
AttackBar: LongInt = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 86 |
|
371 | 87 |
function hwSign(r: hwFloat): LongInt; |
88 |
function Min(a, b: LongInt): LongInt; |
|
89 |
function Max(a, b: LongInt): LongInt; |
|
351 | 90 |
function rndSign(num: hwFloat): hwFloat; |
91 |
procedure OutError(Msg: String; isFatalError: boolean); |
|
4 | 92 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
93 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
316 | 94 |
function IntToStr(n: LongInt): shortstring; |
351 | 95 |
function FloatToStr(n: hwFloat): shortstring; |
371 | 96 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
97 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
|
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} |
208 | 103 |
procedure SetKB(n: Longword); |
104 |
procedure SendKB; |
|
351 | 105 |
procedure SetLittle(var r: hwFloat); |
306 | 106 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
351 | 107 |
function Str2PChar(var s: shortstring): PChar; |
4 | 108 |
|
109 |
var CursorPoint: TPoint; |
|
110 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
111 |
||
112 |
implementation |
|
351 | 113 |
uses uConsole, uStore, uIO, Math, uRandom; |
208 | 114 |
var KBnum: Longword = 0; |
4 | 115 |
{$IFDEF DEBUGFILE} |
116 |
var f: textfile; |
|
117 |
{$ENDIF} |
|
118 |
||
371 | 119 |
function hwSign(r: hwFloat): LongInt; |
4 | 120 |
begin |
351 | 121 |
if r.isNegative then hwSign:= -1 else hwSign:= 1 |
4 | 122 |
end; |
123 |
||
371 | 124 |
function Min(a, b: LongInt): LongInt; |
4 | 125 |
begin |
351 | 126 |
if a < b then Min:= a else Min:= b |
4 | 127 |
end; |
128 |
||
371 | 129 |
function Max(a, b: LongInt): LongInt; |
4 | 130 |
begin |
351 | 131 |
if a > b then Max:= a else Max:= b |
4 | 132 |
end; |
133 |
||
351 | 134 |
procedure OutError(Msg: String; isFatalError: boolean); |
4 | 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 |
||
316 | 161 |
function IntToStr(n: LongInt): shortstring; |
4 | 162 |
begin |
351 | 163 |
str(n, IntToStr) |
4 | 164 |
end; |
165 |
||
351 | 166 |
function FloatToStr(n: hwFloat): shortstring; |
4 | 167 |
begin |
351 | 168 |
FloatToStr:= cstr(n) |
4 | 169 |
end; |
170 |
||
371 | 171 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
100 | 172 |
const _16divPI: Extended = 16/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
173 |
var dY, dX: Extended; |
100 | 174 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
175 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
176 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
177 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
178 |
if _dX.isNegative then dX:= - dX; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
179 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
4 | 180 |
end; |
181 |
||
371 | 182 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
100 | 183 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
184 |
var dY, dX: Extended; |
100 | 185 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
186 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
187 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
188 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
189 |
if _dX.isNegative then dX:= - dX; |
438 | 190 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
100 | 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 |
||
351 | 208 |
procedure SetLittle(var r: hwFloat); |
300 | 209 |
begin |
351 | 210 |
if not r.isNegative then r:= cLittle else r:= - cLittle |
300 | 211 |
end; |
212 |
||
337 | 213 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
214 |
const stc: array [TStatInfoType] of char = 'rDK'; |
|
215 |
begin |
|
216 |
SendIPC('i' + stc[sit] + s) |
|
217 |
end; |
|
218 |
||
351 | 219 |
function rndSign(num: hwFloat): hwFloat; |
220 |
begin |
|
221 |
num.isNegative:= getrandom(2) = 0; |
|
222 |
rndSign:= num |
|
223 |
end; |
|
224 |
||
225 |
function Str2PChar(var s: shortstring): PChar; |
|
226 |
const CharArray: array[byte] of Char = ''; |
|
227 |
begin |
|
228 |
CharArray:= s; |
|
229 |
CharArray[Length(s)]:= #0; |
|
230 |
Str2PChar:= @CharArray |
|
231 |
end; |
|
232 |
||
4 | 233 |
{$IFDEF DEBUGFILE} |
234 |
procedure AddFileLog(s: shortstring); |
|
235 |
begin |
|
236 |
writeln(f, GameTicks: 6, ': ', s); |
|
237 |
flush(f) |
|
238 |
end; |
|
239 |
||
24 | 240 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
241 |
begin |
|
351 | 242 |
RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
24 | 243 |
end; |
244 |
||
337 | 245 |
|
371 | 246 |
var i: LongInt; |
488 | 247 |
{$ENDIF} |
306 | 248 |
|
4 | 249 |
initialization |
351 | 250 |
cDrownSpeed.QWordValue:= 257698038;// 0.06 |
488 | 251 |
cMaxWindSpeed.QWordValue:= 2147484;// 0.0005 |
252 |
cWindSpeed.QWordValue:= 429496;// 0.0001 |
|
351 | 253 |
cGravity:= cMaxWindSpeed; |
254 |
||
488 | 255 |
{$IFDEF DEBUGFILE} |
337 | 256 |
{$I-} |
497 | 257 |
if ParamCount > 0 then |
258 |
for i:= 0 to 7 do |
|
337 | 259 |
begin |
497 | 260 |
Assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt'); |
337 | 261 |
rewrite(f); |
262 |
if IOResult = 0 then break |
|
263 |
end; |
|
264 |
{$I+} |
|
17 | 265 |
|
4 | 266 |
finalization |
267 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
|
268 |
Flush(f); |
|
351 | 269 |
close(f) |
4 | 270 |
{$ENDIF} |
271 |
||
272 |
end. |