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