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