author | unc0rr |
Sun, 15 Mar 2009 17:47:06 +0000 | |
changeset 1895 | 7ba647a88b2f |
parent 1888 | e76274ce7365 |
child 1896 | fdacad5d0acc |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 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} |
1054 | 23 |
var |
24 |
isCursorVisible : boolean = false; |
|
25 |
isTerminated : boolean = false; |
|
26 |
isInLag : boolean = false; |
|
27 |
isPaused : boolean = false; |
|
28 |
isSoundEnabled : boolean = true; |
|
1128 | 29 |
isMusicEnabled : boolean = false; |
1054 | 30 |
isSEBackup : boolean = true; |
31 |
isInMultiShoot : boolean = false; |
|
32 |
isSpeed : boolean = false; |
|
4 | 33 |
|
1560
e140bc57ff68
Quick replay round to spectators until current move
unc0rr
parents:
1530
diff
changeset
|
34 |
fastUntilLag : boolean = false; |
e140bc57ff68
Quick replay round to spectators until current move
unc0rr
parents:
1530
diff
changeset
|
35 |
|
1054 | 36 |
GameState : TGameState = Low(TGameState); |
37 |
GameType : TGameType = gmtLocal; |
|
38 |
GameFlags : Longword = 0; |
|
39 |
TurnTimeLeft : Longword = 0; |
|
1784 | 40 |
cSuddenDTurns : LongInt = 15; |
1895 | 41 |
cDamagePercent : LongInt = 100; |
1797 | 42 |
cTemplateFilter : LongInt = 0; |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1861
diff
changeset
|
43 |
|
1054 | 44 |
cHedgehogTurnTime: Longword = 45000; |
45 |
cMaxAIThinkTime : Longword = 9000; |
|
4 | 46 |
|
1054 | 47 |
cCloudsNumber : LongInt = 9; |
48 |
cScreenWidth : LongInt = 1024; |
|
49 |
cScreenHeight : LongInt = 768; |
|
1121
d595dc56b4f3
Remember initial resolution settings to use when switching to fullscreen mode
unc0rr
parents:
1080
diff
changeset
|
50 |
cInitWidth : LongInt = 1024; |
d595dc56b4f3
Remember initial resolution settings to use when switching to fullscreen mode
unc0rr
parents:
1080
diff
changeset
|
51 |
cInitHeight : LongInt = 768; |
1054 | 52 |
cBits : LongInt = 16; |
53 |
cBitsStr : string[2] = '16'; |
|
54 |
cTagsMask : byte = 7; |
|
74 | 55 |
|
1760 | 56 |
cWaterLine : LongInt = LAND_HEIGHT; |
1054 | 57 |
cVisibleWater : LongInt = 128; |
58 |
cGearScrEdgesDist: LongInt = 240; |
|
1530 | 59 |
cCursorEdgesDist : LongInt = 100; |
1054 | 60 |
cTeamHealthWidth : LongInt = 128; |
61 |
cAltDamage : boolean = true; |
|
4 | 62 |
|
1054 | 63 |
GameTicks : LongWord = 0; |
64 |
||
65 |
cSkyColor : Longword = 0; |
|
66 |
cWhiteColor : Longword = $FFFFFFFF; |
|
67 |
cColorNearBlack : Longword = $FF000010; |
|
68 |
cExplosionBorderColor : LongWord = $808080; |
|
4 | 69 |
|
1054 | 70 |
cShowFPS : boolean = true; |
1298 | 71 |
cCaseFactor : Longword = 5; {0..9} |
1054 | 72 |
cLandAdditions: Longword = 4; |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1861
diff
changeset
|
73 |
cFullScreen : boolean = false; |
1812 | 74 |
cReducedQuality : boolean = false; |
1054 | 75 |
cLocaleFName : shortstring = 'en.txt'; |
76 |
cSeed : shortstring = ''; |
|
77 |
cInitVolume : LongInt = 128; |
|
78 |
cVolumeDelta : LongInt = 0; |
|
79 |
cTimerInterval : Longword = 5; |
|
80 |
cHasFocus : boolean = true; |
|
1057 | 81 |
cInactDelay : Longword = 1250; |
4 | 82 |
|
1054 | 83 |
bBetweenTurns: boolean = false; |
1055
9af540b23409
Water rises after 25 mins of round, health is decreased after 20 mins
unc0rr
parents:
1054
diff
changeset
|
84 |
cHealthDecrease: LongWord = 0; |
9af540b23409
Water rises after 25 mins of round, health is decreased after 20 mins
unc0rr
parents:
1054
diff
changeset
|
85 |
bWaterRising : Boolean = false; |
4 | 86 |
|
614 | 87 |
{$WARNINGS OFF} |
1124 | 88 |
cAirPlaneSpeed: hwFloat = (isNegative: false; QWordValue: 3006477107); // 1.4 |
1054 | 89 |
cBombsSpeed : hwFloat = (isNegative: false; QWordValue: 429496729); |
614 | 90 |
{$WARNINGS ON} |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
539
diff
changeset
|
91 |
|
4 | 92 |
var |
1054 | 93 |
cSendEmptyPacketTime : LongWord = 2000; |
94 |
cSendCursorPosTime : LongWord = 50; |
|
95 |
ShowCrosshair : boolean; |
|
96 |
cDrownSpeed, |
|
97 |
cMaxWindSpeed, |
|
98 |
cWindSpeed, |
|
99 |
cGravity: hwFloat; |
|
1849 | 100 |
cDamageModifier: hwFloat; |
1854 | 101 |
cLaserSighting: boolean; |
4 | 102 |
|
1054 | 103 |
flagMakeCapture: boolean = false; |
4 | 104 |
|
1054 | 105 |
InitStepsFlags: Longword = 0; |
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
106 |
|
1054 | 107 |
RealTicks: Longword = 0; |
836 | 108 |
|
1054 | 109 |
AttackBar: LongInt = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 110 |
|
371 | 111 |
function hwSign(r: hwFloat): LongInt; |
802
ed5450a89b96
Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
788
diff
changeset
|
112 |
function Min(a, b: LongInt): LongInt; |
371 | 113 |
function Max(a, b: LongInt): LongInt; |
351 | 114 |
procedure OutError(Msg: String; isFatalError: boolean); |
4 | 115 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
116 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
316 | 117 |
function IntToStr(n: LongInt): shortstring; |
351 | 118 |
function FloatToStr(n: hwFloat): shortstring; |
775 | 119 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
371 | 120 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
121 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
|
4 | 122 |
procedure AdjustColor(var Color: Longword); |
123 |
{$IFDEF DEBUGFILE} |
|
124 |
procedure AddFileLog(s: shortstring); |
|
24 | 125 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
4 | 126 |
{$ENDIF} |
208 | 127 |
procedure SetKB(n: Longword); |
128 |
procedure SendKB; |
|
351 | 129 |
procedure SetLittle(var r: hwFloat); |
306 | 130 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
753 | 131 |
function Str2PChar(const s: shortstring): PChar; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
132 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
755 | 133 |
function Surface2Tex(surf: PSDL_Surface): PTexture; |
759 | 134 |
procedure FreeTexture(tex: PTexture); |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
916
diff
changeset
|
135 |
function toPowerOf2(i: Longword): Longword; |
949 | 136 |
function DecodeBase64(s: shortstring): shortstring; |
1080 | 137 |
procedure MakeScreenshot(s: shortstring); |
1861 | 138 |
function modifyDamage(dmg: Longword): Longword; |
4 | 139 |
|
140 |
var CursorPoint: TPoint; |
|
141 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
142 |
||
143 |
implementation |
|
771 | 144 |
uses uConsole, uStore, uIO, Math, uRandom, GLU; |
208 | 145 |
var KBnum: Longword = 0; |
4 | 146 |
{$IFDEF DEBUGFILE} |
147 |
var f: textfile; |
|
148 |
{$ENDIF} |
|
149 |
||
371 | 150 |
function hwSign(r: hwFloat): LongInt; |
4 | 151 |
begin |
351 | 152 |
if r.isNegative then hwSign:= -1 else hwSign:= 1 |
4 | 153 |
end; |
154 |
||
371 | 155 |
function Min(a, b: LongInt): LongInt; |
4 | 156 |
begin |
351 | 157 |
if a < b then Min:= a else Min:= b |
4 | 158 |
end; |
159 |
||
371 | 160 |
function Max(a, b: LongInt): LongInt; |
4 | 161 |
begin |
351 | 162 |
if a > b then Max:= a else Max:= b |
4 | 163 |
end; |
164 |
||
351 | 165 |
procedure OutError(Msg: String; isFatalError: boolean); |
4 | 166 |
begin |
167 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 168 |
WriteLnToConsole(Msg); |
4 | 169 |
if isFatalError then |
170 |
begin |
|
53 | 171 |
SendIPC('E' + GetLastConsoleLine); |
4 | 172 |
SDL_Quit; |
173 |
halt(1) |
|
53 | 174 |
end |
4 | 175 |
end; |
176 |
||
177 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
178 |
begin |
|
70 | 179 |
if not Assert then OutError(Msg, isFatal) |
4 | 180 |
end; |
181 |
||
182 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
183 |
begin |
|
184 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
185 |
end; |
|
186 |
||
188 | 187 |
procedure AdjustColor(var Color: Longword); |
4 | 188 |
begin |
189 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
190 |
end; |
|
191 |
||
316 | 192 |
function IntToStr(n: LongInt): shortstring; |
4 | 193 |
begin |
351 | 194 |
str(n, IntToStr) |
4 | 195 |
end; |
196 |
||
351 | 197 |
function FloatToStr(n: hwFloat): shortstring; |
4 | 198 |
begin |
1346 | 199 |
FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue)) |
4 | 200 |
end; |
201 |
||
775 | 202 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
203 |
var dY, dX: Extended; |
|
204 |
begin |
|
205 |
dY:= _dY.QWordValue / $100000000; |
|
206 |
if _dY.isNegative then dY:= - dY; |
|
207 |
dX:= _dX.QWordValue / $100000000; |
|
208 |
if _dX.isNegative then dX:= - dX; |
|
209 |
DxDy2Angle:= arctan2(dY, dX) * 180 / pi |
|
210 |
end; |
|
211 |
||
371 | 212 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
100 | 213 |
const _16divPI: Extended = 16/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
214 |
var dY, dX: Extended; |
100 | 215 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
216 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
217 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
218 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
219 |
if _dX.isNegative then dX:= - dX; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
220 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
4 | 221 |
end; |
222 |
||
371 | 223 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
100 | 224 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
225 |
var dY, dX: Extended; |
100 | 226 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
227 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
228 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
229 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
230 |
if _dX.isNegative then dX:= - dX; |
438 | 231 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
100 | 232 |
end; |
4 | 233 |
|
208 | 234 |
procedure SetKB(n: Longword); |
235 |
begin |
|
236 |
KBnum:= n |
|
237 |
end; |
|
238 |
||
239 |
procedure SendKB; |
|
240 |
var s: shortstring; |
|
241 |
begin |
|
242 |
if KBnum <> 0 then |
|
243 |
begin |
|
244 |
s:= 'K' + inttostr(KBnum); |
|
245 |
SendIPCRaw(@s, Length(s) + 1) |
|
246 |
end |
|
247 |
end; |
|
248 |
||
351 | 249 |
procedure SetLittle(var r: hwFloat); |
300 | 250 |
begin |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
543
diff
changeset
|
251 |
r:= SignAs(cLittle, r) |
300 | 252 |
end; |
253 |
||
337 | 254 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
1625 | 255 |
const stc: array [TStatInfoType] of char = 'rDkKH'; |
337 | 256 |
begin |
257 |
SendIPC('i' + stc[sit] + s) |
|
258 |
end; |
|
259 |
||
534 | 260 |
function Str2PChar(const s: shortstring): PChar; |
351 | 261 |
const CharArray: array[byte] of Char = ''; |
262 |
begin |
|
263 |
CharArray:= s; |
|
264 |
CharArray[Length(s)]:= #0; |
|
265 |
Str2PChar:= @CharArray |
|
266 |
end; |
|
267 |
||
771 | 268 |
function isPowerOf2(i: Longword): boolean; |
269 |
begin |
|
270 |
if i = 0 then exit(true); |
|
271 |
while (i and 1) = 0 do i:= i shr 1; |
|
272 |
isPowerOf2:= (i = 1) |
|
273 |
end; |
|
274 |
||
275 |
function toPowerOf2(i: Longword): Longword; |
|
276 |
begin |
|
277 |
toPowerOf2:= 1; |
|
278 |
while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1 |
|
279 |
end; |
|
280 |
||
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
281 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
282 |
begin |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
283 |
new(NewTexture); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
284 |
NewTexture^.w:= width; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
285 |
NewTexture^.h:= height; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
286 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
287 |
glGenTextures(1, @NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
288 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
289 |
glBindTexture(GL_TEXTURE_2D, NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
290 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
291 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
292 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
293 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
294 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
295 |
end; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
296 |
|
755 | 297 |
function Surface2Tex(surf: PSDL_Surface): PTexture; |
753 | 298 |
var mode: LongInt; |
771 | 299 |
tw, th: Longword; |
300 |
tmpp: pointer; |
|
753 | 301 |
begin |
755 | 302 |
new(Surface2Tex); |
303 |
Surface2Tex^.w:= surf^.w; |
|
304 |
Surface2Tex^.h:= surf^.h; |
|
305 |
||
753 | 306 |
if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else |
307 |
if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else |
|
308 |
begin |
|
869 | 309 |
TryDo(false, 'Surface2Tex: BytesPerPixel not in [3, 4]', true); |
755 | 310 |
Surface2Tex^.id:= 0; |
753 | 311 |
exit |
312 |
end; |
|
313 |
||
755 | 314 |
glGenTextures(1, @Surface2Tex^.id); |
753 | 315 |
|
755 | 316 |
glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); |
753 | 317 |
|
771 | 318 |
if SDL_MustLock(surf) then |
319 |
SDLTry(SDL_LockSurface(surf) >= 0, true); |
|
320 |
||
321 |
if not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h)) then |
|
322 |
begin |
|
323 |
tw:= toPowerOf2(Surf^.w); |
|
324 |
th:= toPowerOf2(Surf^.h); |
|
325 |
||
326 |
GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); |
|
327 |
||
328 |
gluScaleImage(mode, Surf^.w, Surf^.h, GL_UNSIGNED_BYTE, |
|
329 |
Surf^.pixels, tw, th, GL_UNSIGNED_BYTE, |
|
330 |
tmpp); |
|
331 |
||
332 |
glTexImage2D(GL_TEXTURE_2D, 0, mode, tw, th, 0, mode, GL_UNSIGNED_BYTE, tmpp); |
|
333 |
||
334 |
FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
|
335 |
end else |
|
336 |
glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels); |
|
753 | 337 |
|
754 | 338 |
if SDL_MustLock(surf) then |
339 |
SDL_UnlockSurface(surf); |
|
340 |
||
788
00720357601f
- Get rid of PageSimpleGame, now pressing 'quick game' just starts round
unc0rr
parents:
785
diff
changeset
|
341 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
00720357601f
- Get rid of PageSimpleGame, now pressing 'quick game' just starts round
unc0rr
parents:
785
diff
changeset
|
342 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
753 | 343 |
end; |
344 |
||
759 | 345 |
procedure FreeTexture(tex: PTexture); |
346 |
begin |
|
347 |
glDeleteTextures(1, @tex^.id); |
|
348 |
dispose(tex) |
|
349 |
end; |
|
337 | 350 |
|
949 | 351 |
function DecodeBase64(s: shortstring): shortstring; |
352 |
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
353 |
var i, t, c: Longword; |
|
354 |
begin |
|
355 |
c:= 0; |
|
356 |
for i:= 1 to Length(s) do |
|
357 |
begin |
|
358 |
t:= Pos(s[i], table); |
|
359 |
if s[i] = '=' then inc(c); |
|
360 |
if t > 0 then byte(s[i]):= t - 1 else byte(s[i]):= 0 |
|
361 |
end; |
|
362 |
||
363 |
i:= 1; |
|
364 |
t:= 1; |
|
365 |
while i <= length(s) do |
|
366 |
begin |
|
367 |
DecodeBase64[t ]:= char((byte(s[i ]) shl 2) or (byte(s[i + 1]) shr 4)); |
|
368 |
DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2)); |
|
369 |
DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3]) )); |
|
370 |
inc(t, 3); |
|
371 |
inc(i, 4) |
|
372 |
end; |
|
373 |
||
374 |
if c < 3 then t:= t - c; |
|
375 |
||
376 |
byte(DecodeBase64[0]):= t - 1 |
|
377 |
end; |
|
378 |
||
1080 | 379 |
const GL_BGR = $80E0; // some opengl headers don't have that const (?) |
380 |
procedure MakeScreenshot(s: shortstring); |
|
381 |
const head: array[0..8] of Word = (0, 2, 0, 0, 0, 0, 0, 0, 24); |
|
382 |
var p: Pointer; |
|
383 |
size: Longword; |
|
384 |
f: file; |
|
385 |
begin |
|
386 |
head[6]:= cScreenWidth; |
|
387 |
head[7]:= cScreenHeight; |
|
388 |
||
389 |
size:= cScreenWidth * cScreenHeight * 3; |
|
390 |
p:= GetMem(size); |
|
391 |
||
392 |
glReadBuffer(GL_FRONT); |
|
393 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p); |
|
394 |
||
395 |
{$I-} |
|
396 |
Assign(f, s); |
|
397 |
Rewrite(f, 1); |
|
398 |
if IOResult = 0 then |
|
399 |
begin |
|
400 |
BlockWrite(f, head, sizeof(head)); |
|
401 |
BlockWrite(f, p^, size); |
|
402 |
Close(f); |
|
403 |
end; |
|
404 |
{$I+} |
|
405 |
||
406 |
FreeMem(p) |
|
407 |
end; |
|
408 |
||
1861 | 409 |
function modifyDamage(dmg: Longword): Longword; |
410 |
begin |
|
1895 | 411 |
ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent) |
1861 | 412 |
end; |
413 |
||
949 | 414 |
{$IFDEF DEBUGFILE} |
415 |
procedure AddFileLog(s: shortstring); |
|
416 |
begin |
|
417 |
writeln(f, GameTicks: 6, ': ', s); |
|
418 |
flush(f) |
|
419 |
end; |
|
420 |
||
421 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
|
422 |
begin |
|
423 |
RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
424 |
end; |
|
425 |
||
371 | 426 |
var i: LongInt; |
488 | 427 |
{$ENDIF} |
306 | 428 |
|
4 | 429 |
initialization |
351 | 430 |
cDrownSpeed.QWordValue:= 257698038;// 0.06 |
488 | 431 |
cMaxWindSpeed.QWordValue:= 2147484;// 0.0005 |
432 |
cWindSpeed.QWordValue:= 429496;// 0.0001 |
|
351 | 433 |
cGravity:= cMaxWindSpeed; |
1849 | 434 |
cDamageModifier:= _1; |
1854 | 435 |
cLaserSighting:= false; |
351 | 436 |
|
488 | 437 |
{$IFDEF DEBUGFILE} |
337 | 438 |
{$I-} |
497 | 439 |
if ParamCount > 0 then |
440 |
for i:= 0 to 7 do |
|
337 | 441 |
begin |
497 | 442 |
Assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt'); |
337 | 443 |
rewrite(f); |
444 |
if IOResult = 0 then break |
|
445 |
end; |
|
446 |
{$I+} |
|
17 | 447 |
|
4 | 448 |
finalization |
916 | 449 |
//uRandom.DumpBuffer; |
4 | 450 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
451 |
Flush(f); |
|
351 | 452 |
close(f) |
4 | 453 |
{$ENDIF} |
454 |
||
455 |
end. |