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