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