author | unc0rr |
Thu, 07 Jun 2007 18:09:54 +0000 | |
changeset 539 | 6a9bf1852bbc |
parent 534 | 92fb2b0d5117 |
child 543 | 465e2ec8f05f |
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'; |
539
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
534
diff
changeset
|
45 |
cTagsMask : byte = 7; |
74 | 46 |
|
371 | 47 |
cWaterLine : LongInt = 1024; |
48 |
cVisibleWater : LongInt = 128; |
|
49 |
cGearScrEdgesDist: LongInt = 240; |
|
50 |
cCursorEdgesDist : LongInt = 40; |
|
51 |
cTeamHealthWidth : LongInt = 128; |
|
529 | 52 |
cAltDamage : boolean = true; |
4 | 53 |
|
54 |
GameTicks : LongWord = 0; |
|
55 |
||
188 | 56 |
cSkyColor : Longword = 0; |
57 |
cWaterColor : Longword = $005ACE; |
|
58 |
cWhiteColor : Longword = $FFFFFF; |
|
59 |
cConsoleSplitterColor : Longword = $FF0000; |
|
60 |
cColorNearBlack : Longword = 16; |
|
4 | 61 |
cExplosionBorderColor : LongWord = $808080; |
62 |
||
63 |
cShowFPS : boolean = true; |
|
295 | 64 |
cCaseFactor : Longword = 3; {1..10} |
4 | 65 |
cFullScreen : boolean = true; |
80 | 66 |
cLocaleFName : shortstring = 'en.txt'; |
81 | 67 |
cSeed : shortstring = ''; |
371 | 68 |
cInitVolume : LongInt = 128; |
69 |
cVolumeDelta : LongInt = 0; |
|
296 | 70 |
cTimerInterval : Longword = 5; |
351 | 71 |
cHasFocus : boolean = true; |
4 | 72 |
|
73 |
var |
|
74 |
cSendEmptyPacketTime : LongWord = 2000; |
|
75 |
cSendCursorPosTime : LongWord = 50; |
|
13 | 76 |
ShowCrosshair : boolean; |
351 | 77 |
cDrownSpeed, |
78 |
cMaxWindSpeed, |
|
79 |
cWindSpeed, |
|
80 |
cGravity: hwFloat; |
|
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 |
|
371 | 86 |
AttackBar: LongInt = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 87 |
|
371 | 88 |
function hwSign(r: hwFloat): LongInt; |
534 | 89 |
function Min(a, b: LongInt): LongInt; |
371 | 90 |
function Max(a, b: LongInt): LongInt; |
351 | 91 |
function rndSign(num: hwFloat): hwFloat; |
92 |
procedure OutError(Msg: String; isFatalError: boolean); |
|
4 | 93 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
94 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
316 | 95 |
function IntToStr(n: LongInt): shortstring; |
351 | 96 |
function FloatToStr(n: hwFloat): shortstring; |
371 | 97 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
98 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
|
4 | 99 |
procedure AdjustColor(var Color: Longword); |
100 |
{$IFDEF DEBUGFILE} |
|
101 |
procedure AddFileLog(s: shortstring); |
|
24 | 102 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
4 | 103 |
{$ENDIF} |
208 | 104 |
procedure SetKB(n: Longword); |
105 |
procedure SendKB; |
|
351 | 106 |
procedure SetLittle(var r: hwFloat); |
306 | 107 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
534 | 108 |
function Str2PChar(const s: shortstring): PChar; |
4 | 109 |
|
110 |
var CursorPoint: TPoint; |
|
111 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
112 |
||
113 |
implementation |
|
351 | 114 |
uses uConsole, uStore, uIO, Math, uRandom; |
208 | 115 |
var KBnum: Longword = 0; |
4 | 116 |
{$IFDEF DEBUGFILE} |
117 |
var f: textfile; |
|
118 |
{$ENDIF} |
|
119 |
||
371 | 120 |
function hwSign(r: hwFloat): LongInt; |
4 | 121 |
begin |
351 | 122 |
if r.isNegative then hwSign:= -1 else hwSign:= 1 |
4 | 123 |
end; |
124 |
||
371 | 125 |
function Min(a, b: LongInt): LongInt; |
4 | 126 |
begin |
351 | 127 |
if a < b then Min:= a else Min:= b |
4 | 128 |
end; |
129 |
||
371 | 130 |
function Max(a, b: LongInt): LongInt; |
4 | 131 |
begin |
351 | 132 |
if a > b then Max:= a else Max:= b |
4 | 133 |
end; |
134 |
||
351 | 135 |
procedure OutError(Msg: String; isFatalError: boolean); |
4 | 136 |
begin |
137 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 138 |
WriteLnToConsole(Msg); |
4 | 139 |
if isFatalError then |
140 |
begin |
|
53 | 141 |
SendIPC('E' + GetLastConsoleLine); |
4 | 142 |
SDL_Quit; |
143 |
halt(1) |
|
53 | 144 |
end |
4 | 145 |
end; |
146 |
||
147 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
148 |
begin |
|
70 | 149 |
if not Assert then OutError(Msg, isFatal) |
4 | 150 |
end; |
151 |
||
152 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
153 |
begin |
|
154 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
155 |
end; |
|
156 |
||
188 | 157 |
procedure AdjustColor(var Color: Longword); |
4 | 158 |
begin |
159 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
160 |
end; |
|
161 |
||
316 | 162 |
function IntToStr(n: LongInt): shortstring; |
4 | 163 |
begin |
351 | 164 |
str(n, IntToStr) |
4 | 165 |
end; |
166 |
||
351 | 167 |
function FloatToStr(n: hwFloat): shortstring; |
4 | 168 |
begin |
351 | 169 |
FloatToStr:= cstr(n) |
4 | 170 |
end; |
171 |
||
371 | 172 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
100 | 173 |
const _16divPI: Extended = 16/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
174 |
var dY, dX: Extended; |
100 | 175 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
176 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
177 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
178 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
179 |
if _dX.isNegative then dX:= - dX; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
180 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
4 | 181 |
end; |
182 |
||
371 | 183 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
100 | 184 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
185 |
var dY, dX: Extended; |
100 | 186 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
187 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
188 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
189 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
190 |
if _dX.isNegative then dX:= - dX; |
438 | 191 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
100 | 192 |
end; |
4 | 193 |
|
208 | 194 |
procedure SetKB(n: Longword); |
195 |
begin |
|
196 |
KBnum:= n |
|
197 |
end; |
|
198 |
||
199 |
procedure SendKB; |
|
200 |
var s: shortstring; |
|
201 |
begin |
|
202 |
if KBnum <> 0 then |
|
203 |
begin |
|
204 |
s:= 'K' + inttostr(KBnum); |
|
205 |
SendIPCRaw(@s, Length(s) + 1) |
|
206 |
end |
|
207 |
end; |
|
208 |
||
351 | 209 |
procedure SetLittle(var r: hwFloat); |
300 | 210 |
begin |
351 | 211 |
if not r.isNegative then r:= cLittle else r:= - cLittle |
300 | 212 |
end; |
213 |
||
337 | 214 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
215 |
const stc: array [TStatInfoType] of char = 'rDK'; |
|
216 |
begin |
|
217 |
SendIPC('i' + stc[sit] + s) |
|
218 |
end; |
|
219 |
||
351 | 220 |
function rndSign(num: hwFloat): hwFloat; |
221 |
begin |
|
222 |
num.isNegative:= getrandom(2) = 0; |
|
223 |
rndSign:= num |
|
224 |
end; |
|
225 |
||
534 | 226 |
function Str2PChar(const s: shortstring): PChar; |
351 | 227 |
const CharArray: array[byte] of Char = ''; |
228 |
begin |
|
229 |
CharArray:= s; |
|
230 |
CharArray[Length(s)]:= #0; |
|
231 |
Str2PChar:= @CharArray |
|
232 |
end; |
|
233 |
||
4 | 234 |
{$IFDEF DEBUGFILE} |
235 |
procedure AddFileLog(s: shortstring); |
|
236 |
begin |
|
237 |
writeln(f, GameTicks: 6, ': ', s); |
|
238 |
flush(f) |
|
239 |
end; |
|
240 |
||
24 | 241 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
242 |
begin |
|
351 | 243 |
RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
24 | 244 |
end; |
245 |
||
337 | 246 |
|
371 | 247 |
var i: LongInt; |
488 | 248 |
{$ENDIF} |
306 | 249 |
|
4 | 250 |
initialization |
351 | 251 |
cDrownSpeed.QWordValue:= 257698038;// 0.06 |
488 | 252 |
cMaxWindSpeed.QWordValue:= 2147484;// 0.0005 |
253 |
cWindSpeed.QWordValue:= 429496;// 0.0001 |
|
351 | 254 |
cGravity:= cMaxWindSpeed; |
255 |
||
488 | 256 |
{$IFDEF DEBUGFILE} |
337 | 257 |
{$I-} |
497 | 258 |
if ParamCount > 0 then |
259 |
for i:= 0 to 7 do |
|
337 | 260 |
begin |
497 | 261 |
Assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt'); |
337 | 262 |
rewrite(f); |
263 |
if IOResult = 0 then break |
|
264 |
end; |
|
265 |
{$I+} |
|
17 | 266 |
|
4 | 267 |
finalization |
268 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
|
269 |
Flush(f); |
|
351 | 270 |
close(f) |
4 | 271 |
{$ENDIF} |
272 |
||
273 |
end. |