author | unc0rr |
Fri, 25 Jan 2008 21:55:48 +0000 | |
changeset 754 | 94ac14829085 |
parent 753 | 40fc0deb388f |
child 755 | edf26e9554ac |
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 |
|
753 | 21 |
uses uConsts, SDLh, uFloat, GL; |
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); |
753 | 118 |
function Str2PChar(const s: shortstring): PChar; |
119 |
function Surface2Tex(surf: PSDL_Surface): GLuint; |
|
4 | 120 |
|
121 |
var CursorPoint: TPoint; |
|
122 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
123 |
||
124 |
implementation |
|
351 | 125 |
uses uConsole, uStore, uIO, Math, uRandom; |
208 | 126 |
var KBnum: Longword = 0; |
4 | 127 |
{$IFDEF DEBUGFILE} |
128 |
var f: textfile; |
|
129 |
{$ENDIF} |
|
130 |
||
371 | 131 |
function hwSign(r: hwFloat): LongInt; |
4 | 132 |
begin |
351 | 133 |
if r.isNegative then hwSign:= -1 else hwSign:= 1 |
4 | 134 |
end; |
135 |
||
371 | 136 |
function Min(a, b: LongInt): LongInt; |
4 | 137 |
begin |
351 | 138 |
if a < b then Min:= a else Min:= b |
4 | 139 |
end; |
140 |
||
371 | 141 |
function Max(a, b: LongInt): LongInt; |
4 | 142 |
begin |
351 | 143 |
if a > b then Max:= a else Max:= b |
4 | 144 |
end; |
145 |
||
351 | 146 |
procedure OutError(Msg: String; isFatalError: boolean); |
4 | 147 |
begin |
148 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 149 |
WriteLnToConsole(Msg); |
4 | 150 |
if isFatalError then |
151 |
begin |
|
53 | 152 |
SendIPC('E' + GetLastConsoleLine); |
4 | 153 |
SDL_Quit; |
154 |
halt(1) |
|
53 | 155 |
end |
4 | 156 |
end; |
157 |
||
158 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
159 |
begin |
|
70 | 160 |
if not Assert then OutError(Msg, isFatal) |
4 | 161 |
end; |
162 |
||
163 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
164 |
begin |
|
165 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
166 |
end; |
|
167 |
||
188 | 168 |
procedure AdjustColor(var Color: Longword); |
4 | 169 |
begin |
170 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
171 |
end; |
|
172 |
||
316 | 173 |
function IntToStr(n: LongInt): shortstring; |
4 | 174 |
begin |
351 | 175 |
str(n, IntToStr) |
4 | 176 |
end; |
177 |
||
351 | 178 |
function FloatToStr(n: hwFloat): shortstring; |
4 | 179 |
begin |
351 | 180 |
FloatToStr:= cstr(n) |
4 | 181 |
end; |
182 |
||
371 | 183 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
100 | 184 |
const _16divPI: Extended = 16/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; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
191 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
4 | 192 |
end; |
193 |
||
371 | 194 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
100 | 195 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
196 |
var dY, dX: Extended; |
100 | 197 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
198 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
199 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
200 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
201 |
if _dX.isNegative then dX:= - dX; |
438 | 202 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
100 | 203 |
end; |
4 | 204 |
|
208 | 205 |
procedure SetKB(n: Longword); |
206 |
begin |
|
207 |
KBnum:= n |
|
208 |
end; |
|
209 |
||
210 |
procedure SendKB; |
|
211 |
var s: shortstring; |
|
212 |
begin |
|
213 |
if KBnum <> 0 then |
|
214 |
begin |
|
215 |
s:= 'K' + inttostr(KBnum); |
|
216 |
SendIPCRaw(@s, Length(s) + 1) |
|
217 |
end |
|
218 |
end; |
|
219 |
||
351 | 220 |
procedure SetLittle(var r: hwFloat); |
300 | 221 |
begin |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
543
diff
changeset
|
222 |
r:= SignAs(cLittle, r) |
300 | 223 |
end; |
224 |
||
337 | 225 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
226 |
const stc: array [TStatInfoType] of char = 'rDK'; |
|
227 |
begin |
|
228 |
SendIPC('i' + stc[sit] + s) |
|
229 |
end; |
|
230 |
||
351 | 231 |
function rndSign(num: hwFloat): hwFloat; |
232 |
begin |
|
233 |
num.isNegative:= getrandom(2) = 0; |
|
234 |
rndSign:= num |
|
235 |
end; |
|
236 |
||
534 | 237 |
function Str2PChar(const s: shortstring): PChar; |
351 | 238 |
const CharArray: array[byte] of Char = ''; |
239 |
begin |
|
240 |
CharArray:= s; |
|
241 |
CharArray[Length(s)]:= #0; |
|
242 |
Str2PChar:= @CharArray |
|
243 |
end; |
|
244 |
||
4 | 245 |
{$IFDEF DEBUGFILE} |
246 |
procedure AddFileLog(s: shortstring); |
|
247 |
begin |
|
248 |
writeln(f, GameTicks: 6, ': ', s); |
|
249 |
flush(f) |
|
250 |
end; |
|
251 |
||
24 | 252 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
253 |
begin |
|
351 | 254 |
RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
24 | 255 |
end; |
256 |
||
753 | 257 |
function Surface2Tex(surf: PSDL_Surface): GLuint; |
258 |
var mode: LongInt; |
|
259 |
texId: GLuint; |
|
260 |
begin |
|
754 | 261 |
if SDL_MustLock(surf) then |
262 |
SDLTry(SDL_LockSurface(surf) >= 0, true); |
|
263 |
||
753 | 264 |
if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else |
265 |
if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else |
|
266 |
begin |
|
267 |
TryDo(false, 'Surface2Tex: BytePerPixel not in [3, 4]', true); |
|
268 |
Surface2Tex:= 0; |
|
269 |
exit |
|
270 |
end; |
|
271 |
||
272 |
glGenTextures(1, @texId); |
|
273 |
||
274 |
glBindTexture(GL_TEXTURE_2D, texId); |
|
275 |
||
276 |
glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels); |
|
277 |
||
754 | 278 |
if SDL_MustLock(surf) then |
279 |
SDL_UnlockSurface(surf); |
|
280 |
||
753 | 281 |
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); |
282 |
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); |
|
283 |
||
284 |
Surface2Tex:= texId |
|
285 |
end; |
|
286 |
||
337 | 287 |
|
371 | 288 |
var i: LongInt; |
488 | 289 |
{$ENDIF} |
306 | 290 |
|
4 | 291 |
initialization |
351 | 292 |
cDrownSpeed.QWordValue:= 257698038;// 0.06 |
488 | 293 |
cMaxWindSpeed.QWordValue:= 2147484;// 0.0005 |
294 |
cWindSpeed.QWordValue:= 429496;// 0.0001 |
|
351 | 295 |
cGravity:= cMaxWindSpeed; |
296 |
||
488 | 297 |
{$IFDEF DEBUGFILE} |
337 | 298 |
{$I-} |
497 | 299 |
if ParamCount > 0 then |
300 |
for i:= 0 to 7 do |
|
337 | 301 |
begin |
497 | 302 |
Assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt'); |
337 | 303 |
rewrite(f); |
304 |
if IOResult = 0 then break |
|
305 |
end; |
|
306 |
{$I+} |
|
17 | 307 |
|
4 | 308 |
finalization |
309 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
|
310 |
Flush(f); |
|
351 | 311 |
close(f) |
4 | 312 |
{$ENDIF} |
313 |
||
314 |
end. |