author | unc0rr |
Sun, 21 Oct 2007 15:39:21 +0000 | |
changeset 622 | cedd47d956ec |
parent 614 | 0e04504bc140 |
child 626 | a30171dbcd19 |
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; |
|
614 | 64 |
cCaseFactor : Longword = 6; {0..9} |
622 | 65 |
cLandAdditions: Longword = 4; |
4 | 66 |
cFullScreen : boolean = true; |
80 | 67 |
cLocaleFName : shortstring = 'en.txt'; |
81 | 68 |
cSeed : shortstring = ''; |
371 | 69 |
cInitVolume : LongInt = 128; |
70 |
cVolumeDelta : LongInt = 0; |
|
296 | 71 |
cTimerInterval : Longword = 5; |
351 | 72 |
cHasFocus : boolean = true; |
614 | 73 |
cInactDelay : Longword = 1500; |
4 | 74 |
|
614 | 75 |
{$WARNINGS OFF} |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
539
diff
changeset
|
76 |
cAirPlaneSpeed: hwFloat = (isNegative: false; QWordValue: 6012954214); // 1.4 |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
539
diff
changeset
|
77 |
cBombsSpeed : hwFloat = (isNegative: false; QWordValue: 429496729); |
614 | 78 |
{$WARNINGS ON} |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
539
diff
changeset
|
79 |
|
4 | 80 |
var |
81 |
cSendEmptyPacketTime : LongWord = 2000; |
|
82 |
cSendCursorPosTime : LongWord = 50; |
|
13 | 83 |
ShowCrosshair : boolean; |
351 | 84 |
cDrownSpeed, |
85 |
cMaxWindSpeed, |
|
86 |
cWindSpeed, |
|
87 |
cGravity: hwFloat; |
|
4 | 88 |
|
89 |
flagMakeCapture: boolean = false; |
|
90 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
91 |
InitStepsFlags: Longword = 0; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
92 |
|
564 | 93 |
RealTicks: Longword = 0; |
94 |
||
371 | 95 |
AttackBar: LongInt = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 96 |
|
371 | 97 |
function hwSign(r: hwFloat): LongInt; |
534 | 98 |
function Min(a, b: LongInt): LongInt; |
371 | 99 |
function Max(a, b: LongInt): LongInt; |
351 | 100 |
function rndSign(num: hwFloat): hwFloat; |
101 |
procedure OutError(Msg: String; isFatalError: boolean); |
|
4 | 102 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
103 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
316 | 104 |
function IntToStr(n: LongInt): shortstring; |
351 | 105 |
function FloatToStr(n: hwFloat): shortstring; |
371 | 106 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
107 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
|
4 | 108 |
procedure AdjustColor(var Color: Longword); |
109 |
{$IFDEF DEBUGFILE} |
|
110 |
procedure AddFileLog(s: shortstring); |
|
24 | 111 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
4 | 112 |
{$ENDIF} |
208 | 113 |
procedure SetKB(n: Longword); |
114 |
procedure SendKB; |
|
351 | 115 |
procedure SetLittle(var r: hwFloat); |
306 | 116 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
534 | 117 |
function Str2PChar(const s: shortstring): PChar; |
4 | 118 |
|
119 |
var CursorPoint: TPoint; |
|
120 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
121 |
||
122 |
implementation |
|
351 | 123 |
uses uConsole, uStore, uIO, Math, uRandom; |
208 | 124 |
var KBnum: Longword = 0; |
4 | 125 |
{$IFDEF DEBUGFILE} |
126 |
var f: textfile; |
|
127 |
{$ENDIF} |
|
128 |
||
371 | 129 |
function hwSign(r: hwFloat): LongInt; |
4 | 130 |
begin |
351 | 131 |
if r.isNegative then hwSign:= -1 else hwSign:= 1 |
4 | 132 |
end; |
133 |
||
371 | 134 |
function Min(a, b: LongInt): LongInt; |
4 | 135 |
begin |
351 | 136 |
if a < b then Min:= a else Min:= b |
4 | 137 |
end; |
138 |
||
371 | 139 |
function Max(a, b: LongInt): LongInt; |
4 | 140 |
begin |
351 | 141 |
if a > b then Max:= a else Max:= b |
4 | 142 |
end; |
143 |
||
351 | 144 |
procedure OutError(Msg: String; isFatalError: boolean); |
4 | 145 |
begin |
146 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 147 |
WriteLnToConsole(Msg); |
4 | 148 |
if isFatalError then |
149 |
begin |
|
53 | 150 |
SendIPC('E' + GetLastConsoleLine); |
4 | 151 |
SDL_Quit; |
152 |
halt(1) |
|
53 | 153 |
end |
4 | 154 |
end; |
155 |
||
156 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
157 |
begin |
|
70 | 158 |
if not Assert then OutError(Msg, isFatal) |
4 | 159 |
end; |
160 |
||
161 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
162 |
begin |
|
163 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
164 |
end; |
|
165 |
||
188 | 166 |
procedure AdjustColor(var Color: Longword); |
4 | 167 |
begin |
168 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
169 |
end; |
|
170 |
||
316 | 171 |
function IntToStr(n: LongInt): shortstring; |
4 | 172 |
begin |
351 | 173 |
str(n, IntToStr) |
4 | 174 |
end; |
175 |
||
351 | 176 |
function FloatToStr(n: hwFloat): shortstring; |
4 | 177 |
begin |
351 | 178 |
FloatToStr:= cstr(n) |
4 | 179 |
end; |
180 |
||
371 | 181 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
100 | 182 |
const _16divPI: Extended = 16/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
183 |
var dY, dX: Extended; |
100 | 184 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
185 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
186 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
187 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
188 |
if _dX.isNegative then dX:= - dX; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
189 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
4 | 190 |
end; |
191 |
||
371 | 192 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
100 | 193 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
194 |
var dY, dX: Extended; |
100 | 195 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
196 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
197 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
198 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
199 |
if _dX.isNegative then dX:= - dX; |
438 | 200 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
100 | 201 |
end; |
4 | 202 |
|
208 | 203 |
procedure SetKB(n: Longword); |
204 |
begin |
|
205 |
KBnum:= n |
|
206 |
end; |
|
207 |
||
208 |
procedure SendKB; |
|
209 |
var s: shortstring; |
|
210 |
begin |
|
211 |
if KBnum <> 0 then |
|
212 |
begin |
|
213 |
s:= 'K' + inttostr(KBnum); |
|
214 |
SendIPCRaw(@s, Length(s) + 1) |
|
215 |
end |
|
216 |
end; |
|
217 |
||
351 | 218 |
procedure SetLittle(var r: hwFloat); |
300 | 219 |
begin |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
543
diff
changeset
|
220 |
r:= SignAs(cLittle, r) |
300 | 221 |
end; |
222 |
||
337 | 223 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
224 |
const stc: array [TStatInfoType] of char = 'rDK'; |
|
225 |
begin |
|
226 |
SendIPC('i' + stc[sit] + s) |
|
227 |
end; |
|
228 |
||
351 | 229 |
function rndSign(num: hwFloat): hwFloat; |
230 |
begin |
|
231 |
num.isNegative:= getrandom(2) = 0; |
|
232 |
rndSign:= num |
|
233 |
end; |
|
234 |
||
534 | 235 |
function Str2PChar(const s: shortstring): PChar; |
351 | 236 |
const CharArray: array[byte] of Char = ''; |
237 |
begin |
|
238 |
CharArray:= s; |
|
239 |
CharArray[Length(s)]:= #0; |
|
240 |
Str2PChar:= @CharArray |
|
241 |
end; |
|
242 |
||
4 | 243 |
{$IFDEF DEBUGFILE} |
244 |
procedure AddFileLog(s: shortstring); |
|
245 |
begin |
|
246 |
writeln(f, GameTicks: 6, ': ', s); |
|
247 |
flush(f) |
|
248 |
end; |
|
249 |
||
24 | 250 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
251 |
begin |
|
351 | 252 |
RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
24 | 253 |
end; |
254 |
||
337 | 255 |
|
371 | 256 |
var i: LongInt; |
488 | 257 |
{$ENDIF} |
306 | 258 |
|
4 | 259 |
initialization |
351 | 260 |
cDrownSpeed.QWordValue:= 257698038;// 0.06 |
488 | 261 |
cMaxWindSpeed.QWordValue:= 2147484;// 0.0005 |
262 |
cWindSpeed.QWordValue:= 429496;// 0.0001 |
|
351 | 263 |
cGravity:= cMaxWindSpeed; |
264 |
||
488 | 265 |
{$IFDEF DEBUGFILE} |
337 | 266 |
{$I-} |
497 | 267 |
if ParamCount > 0 then |
268 |
for i:= 0 to 7 do |
|
337 | 269 |
begin |
497 | 270 |
Assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt'); |
337 | 271 |
rewrite(f); |
272 |
if IOResult = 0 then break |
|
273 |
end; |
|
274 |
{$I+} |
|
17 | 275 |
|
4 | 276 |
finalization |
277 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
|
278 |
Flush(f); |
|
351 | 279 |
close(f) |
4 | 280 |
{$ENDIF} |
281 |
||
282 |
end. |