author | nemo |
Sun, 28 Mar 2010 02:49:39 +0000 | |
changeset 3133 | 1ab5f18f4df8 |
parent 3115 | 831bd0f7050d |
child 3165 | 3ec07a7d8456 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2947 | 2 |
* Hedgewars, a free turn based strategy game |
3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
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 |
|
8 |
* |
|
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. |
|
13 |
* |
|
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 |
|
17 |
*) |
|
4 | 18 |
|
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uMisc; |
22 |
interface |
|
2630 | 23 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
24 |
uses SDLh, uConsts, uFloat, |
2152 | 25 |
{$IFDEF GLES11} |
2947 | 26 |
gles11; |
1906 | 27 |
{$ELSE} |
2947 | 28 |
GL; |
1906 | 29 |
{$ENDIF} |
2697 | 30 |
|
1054 | 31 |
var |
2947 | 32 |
isCursorVisible : boolean; |
33 |
isTerminated : boolean; |
|
34 |
isInLag : boolean; |
|
35 |
isPaused : boolean; |
|
36 |
isSoundEnabled : boolean; |
|
37 |
isMusicEnabled : boolean; |
|
38 |
isSEBackup : boolean; |
|
39 |
isInMultiShoot : boolean; |
|
40 |
isSpeed : boolean; |
|
3107 | 41 |
isFirstFrame : boolean; |
1560
e140bc57ff68
Quick replay round to spectators until current move
unc0rr
parents:
1530
diff
changeset
|
42 |
|
2947 | 43 |
fastUntilLag : boolean; |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1861
diff
changeset
|
44 |
|
2947 | 45 |
GameState : TGameState; |
46 |
GameType : TGameType; |
|
47 |
GameFlags : Longword; |
|
48 |
TrainingFlags : Longword; |
|
49 |
TurnTimeLeft : Longword; |
|
50 |
cSuddenDTurns : LongInt; |
|
51 |
cDamagePercent : LongInt; |
|
52 |
cMineDudPercent : LongWord; |
|
53 |
cTemplateFilter : LongInt; |
|
3133 | 54 |
cMapGen : LongInt; |
55 |
cMazeSize : LongInt; |
|
4 | 56 |
|
2947 | 57 |
cHedgehogTurnTime: Longword; |
58 |
cMinesTime : LongInt; |
|
59 |
cMaxAIThinkTime : Longword; |
|
74 | 60 |
|
2947 | 61 |
cCloudsNumber : LongInt; |
62 |
cScreenWidth : LongInt; |
|
63 |
cScreenHeight : LongInt; |
|
64 |
cInitWidth : LongInt; |
|
65 |
cInitHeight : LongInt; |
|
66 |
cVSyncInUse : boolean; |
|
67 |
cBits : LongInt; |
|
68 |
cBitsStr : string[2]; |
|
69 |
cTagsMask : byte; |
|
70 |
zoom : GLfloat; |
|
71 |
ZoomValue : GLfloat; |
|
4 | 72 |
|
2947 | 73 |
cWaterLine : LongInt; |
74 |
cGearScrEdgesDist: LongInt; |
|
75 |
cAltDamage : boolean; |
|
1054 | 76 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
77 |
GameTicks : LongWord; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
78 |
TrainingTimeInc : Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
79 |
TrainingTimeInD : Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
80 |
TrainingTimeInM : Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
81 |
TrainingTimeMax : Longword; |
2666 | 82 |
|
2947 | 83 |
TimeTrialStartTime: Longword; |
84 |
TimeTrialStopTime : Longword; |
|
85 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
86 |
recordFileName : shortstring; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
87 |
cShowFPS : boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
88 |
cCaseFactor : Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
89 |
cLandAdditions : Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
90 |
cExplosives : Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
91 |
cFullScreen : boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
92 |
cReducedQuality : boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
93 |
cLocaleFName : shortstring; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
94 |
cSeed : shortstring; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
95 |
cInitVolume : LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
96 |
cVolumeDelta : LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
97 |
cTimerInterval : Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
98 |
cHasFocus : boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
99 |
cInactDelay : Longword; |
4 | 100 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
101 |
bBetweenTurns : boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
102 |
cHealthDecrease : LongWord; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
103 |
bWaterRising : Boolean; |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
539
diff
changeset
|
104 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
105 |
ShowCrosshair : boolean; |
2947 | 106 |
CursorMovementX : Integer; |
107 |
CursorMovementY : Integer; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
108 |
cDrownSpeed : hwFloat; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
109 |
cMaxWindSpeed : hwFloat; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
110 |
cWindSpeed : hwFloat; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
111 |
cGravity : hwFloat; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
112 |
cDamageModifier : hwFloat; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
113 |
cLaserSighting : boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
114 |
cVampiric : boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
115 |
cArtillery : boolean; |
2947 | 116 |
WeaponTooltipTex : PTexture; |
117 |
cWeaponTooltips: boolean; |
|
4 | 118 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
119 |
flagMakeCapture : boolean; |
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
120 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
121 |
InitStepsFlags : Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
122 |
RealTicks : Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
123 |
AttackBar : LongInt; |
836 | 124 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
125 |
WaterColorArray : array[0..3] of HwColor4f; |
4 | 126 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
127 |
CursorPoint : TPoint; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
128 |
TargetPoint : TPoint; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
129 |
|
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
130 |
TextureList : PTexture; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
131 |
|
3107 | 132 |
ScreenFade : TScreenFade; |
3115 | 133 |
ScreenFadeValue : LongInt; |
134 |
ScreenFadeSpeed : LongInt; |
|
3107 | 135 |
|
2630 | 136 |
|
3038 | 137 |
procedure initModule; |
138 |
procedure freeModule; |
|
2747 | 139 |
procedure SplitBySpace(var a, b: shortstring); |
2905 | 140 |
procedure SplitByChar(var a, b: ansistring; c: char); |
2428 | 141 |
procedure movecursor(dx, dy: Integer); |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
142 |
function hwSign(r: hwFloat): LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
143 |
function Min(a, b: LongInt): LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
144 |
function Max(a, b: LongInt): LongInt; |
2905 | 145 |
procedure OutError(Msg: shortstring; isFatalError: boolean); |
146 |
procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); |
|
4 | 147 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
148 |
function IntToStr(n: LongInt): shortstring; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
149 |
function FloatToStr(n: hwFloat): shortstring; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
150 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
151 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
152 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
4 | 153 |
procedure AdjustColor(var Color: Longword); |
208 | 154 |
procedure SetKB(n: Longword); |
155 |
procedure SendKB; |
|
351 | 156 |
procedure SetLittle(var r: hwFloat); |
306 | 157 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
753 | 158 |
function Str2PChar(const s: shortstring): PChar; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
159 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2279
diff
changeset
|
160 |
function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture; |
759 | 161 |
procedure FreeTexture(tex: PTexture); |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
916
diff
changeset
|
162 |
function toPowerOf2(i: Longword): Longword; |
2670 | 163 |
function DecodeBase64(s: shortstring): shortstring; |
164 |
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
|
165 |
function endian(independent: LongWord): LongWord; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
166 |
{$IFDEF DEBUGFILE} |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
167 |
procedure AddFileLog(s: shortstring); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
168 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
169 |
{$ENDIF} |
2163
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2162
diff
changeset
|
170 |
{$IFNDEF IPHONEOS} |
2735 | 171 |
procedure MakeScreenshot(filename: shortstring); |
2163
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2162
diff
changeset
|
172 |
{$ENDIF} |
4 | 173 |
|
174 |
implementation |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
175 |
uses Math, uConsole, uStore, uIO, uRandom, uSound; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
176 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
177 |
var KBnum: Longword; |
4 | 178 |
{$IFDEF DEBUGFILE} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
179 |
f: textfile; |
4 | 180 |
{$ENDIF} |
181 |
||
2747 | 182 |
// should this include "strtolower()" for the split string? |
183 |
procedure SplitBySpace(var a, b: shortstring); |
|
184 |
var i, t: LongInt; |
|
185 |
begin |
|
186 |
i:= Pos(' ', a); |
|
187 |
if i > 0 then |
|
2947 | 188 |
begin |
189 |
for t:= 1 to Pred(i) do |
|
190 |
if (a[t] >= 'A')and(a[t] <= 'Z') then Inc(a[t], 32); |
|
191 |
b:= copy(a, i + 1, Length(a) - i); |
|
192 |
byte(a[0]):= Pred(i) |
|
193 |
end else b:= ''; |
|
2747 | 194 |
end; |
195 |
||
2905 | 196 |
procedure SplitByChar(var a, b: ansistring; c: char); |
2747 | 197 |
var i: LongInt; |
198 |
begin |
|
199 |
i:= Pos(c, a); |
|
200 |
if i > 0 then |
|
2947 | 201 |
begin |
202 |
b:= copy(a, i + 1, Length(a) - i); |
|
203 |
setlength(a, Pred(i)); |
|
204 |
end else b:= ''; |
|
2747 | 205 |
end; |
206 |
||
2428 | 207 |
procedure movecursor(dx, dy: Integer); |
208 |
var x, y: LongInt; |
|
209 |
begin |
|
210 |
if (dx = 0) and (dy = 0) then exit; |
|
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
211 |
|
2428 | 212 |
SDL_GetMouseState(@x, @y); |
213 |
Inc(x, dx); |
|
214 |
Inc(y, dy); |
|
215 |
SDL_WarpMouse(x, y); |
|
216 |
end; |
|
217 |
||
371 | 218 |
function hwSign(r: hwFloat): LongInt; |
4 | 219 |
begin |
2389 | 220 |
// yes, we have negative zero for a reason |
221 |
if r.isNegative then hwSign:= -1 else hwSign:= 1 |
|
4 | 222 |
end; |
223 |
||
371 | 224 |
function Min(a, b: LongInt): LongInt; |
4 | 225 |
begin |
351 | 226 |
if a < b then Min:= a else Min:= b |
4 | 227 |
end; |
228 |
||
371 | 229 |
function Max(a, b: LongInt): LongInt; |
4 | 230 |
begin |
351 | 231 |
if a > b then Max:= a else Max:= b |
4 | 232 |
end; |
233 |
||
2905 | 234 |
procedure OutError(Msg: shortstring; isFatalError: boolean); |
4 | 235 |
begin |
236 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 237 |
WriteLnToConsole(Msg); |
4 | 238 |
if isFatalError then |
2947 | 239 |
begin |
240 |
SendIPC('E' + GetLastConsoleLine); |
|
241 |
SDL_Quit; |
|
242 |
halt(1) |
|
243 |
end |
|
4 | 244 |
end; |
245 |
||
2905 | 246 |
procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); |
4 | 247 |
begin |
70 | 248 |
if not Assert then OutError(Msg, isFatal) |
4 | 249 |
end; |
250 |
||
251 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
252 |
begin |
|
253 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
254 |
end; |
|
255 |
||
188 | 256 |
procedure AdjustColor(var Color: Longword); |
4 | 257 |
begin |
258 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
259 |
end; |
|
260 |
||
316 | 261 |
function IntToStr(n: LongInt): shortstring; |
4 | 262 |
begin |
351 | 263 |
str(n, IntToStr) |
4 | 264 |
end; |
265 |
||
351 | 266 |
function FloatToStr(n: hwFloat): shortstring; |
4 | 267 |
begin |
1346 | 268 |
FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue)) |
4 | 269 |
end; |
270 |
||
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
271 |
procedure SetTextureParameters(enableClamp: Boolean); |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
272 |
begin |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
273 |
if enableClamp and not cReducedQuality then |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
274 |
begin |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
275 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
276 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
277 |
end; |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
278 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
279 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
280 |
end; |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
281 |
|
775 | 282 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
283 |
var dY, dX: Extended; |
|
284 |
begin |
|
285 |
dY:= _dY.QWordValue / $100000000; |
|
286 |
if _dY.isNegative then dY:= - dY; |
|
287 |
dX:= _dX.QWordValue / $100000000; |
|
288 |
if _dX.isNegative then dX:= - dX; |
|
289 |
DxDy2Angle:= arctan2(dY, dX) * 180 / pi |
|
290 |
end; |
|
291 |
||
371 | 292 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
100 | 293 |
const _16divPI: Extended = 16/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
294 |
var dY, dX: Extended; |
100 | 295 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
296 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
297 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
298 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
299 |
if _dX.isNegative then dX:= - dX; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
300 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
4 | 301 |
end; |
302 |
||
371 | 303 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
100 | 304 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
305 |
var dY, dX: Extended; |
100 | 306 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
307 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
308 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
309 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
310 |
if _dX.isNegative then dX:= - dX; |
438 | 311 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
100 | 312 |
end; |
4 | 313 |
|
208 | 314 |
procedure SetKB(n: Longword); |
315 |
begin |
|
316 |
KBnum:= n |
|
317 |
end; |
|
318 |
||
319 |
procedure SendKB; |
|
320 |
var s: shortstring; |
|
321 |
begin |
|
322 |
if KBnum <> 0 then |
|
2947 | 323 |
begin |
324 |
s:= 'K' + inttostr(KBnum); |
|
325 |
SendIPCRaw(@s, Length(s) + 1) |
|
326 |
end |
|
208 | 327 |
end; |
328 |
||
351 | 329 |
procedure SetLittle(var r: hwFloat); |
300 | 330 |
begin |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
543
diff
changeset
|
331 |
r:= SignAs(cLittle, r) |
300 | 332 |
end; |
333 |
||
337 | 334 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
1625 | 335 |
const stc: array [TStatInfoType] of char = 'rDkKH'; |
2382 | 336 |
var buf: shortstring; |
337 | 337 |
begin |
2382 | 338 |
buf:= 'i' + stc[sit] + s; |
339 |
SendIPCRaw(@buf[0], length(buf) + 1) |
|
337 | 340 |
end; |
341 |
||
534 | 342 |
function Str2PChar(const s: shortstring): PChar; |
351 | 343 |
const CharArray: array[byte] of Char = ''; |
344 |
begin |
|
345 |
CharArray:= s; |
|
346 |
CharArray[Length(s)]:= #0; |
|
347 |
Str2PChar:= @CharArray |
|
348 |
end; |
|
349 |
||
771 | 350 |
function isPowerOf2(i: Longword): boolean; |
351 |
begin |
|
352 |
if i = 0 then exit(true); |
|
353 |
while (i and 1) = 0 do i:= i shr 1; |
|
354 |
isPowerOf2:= (i = 1) |
|
355 |
end; |
|
356 |
||
357 |
function toPowerOf2(i: Longword): Longword; |
|
358 |
begin |
|
359 |
toPowerOf2:= 1; |
|
360 |
while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1 |
|
361 |
end; |
|
362 |
||
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
363 |
procedure ResetVertexArrays(texture: PTexture); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
364 |
begin |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
365 |
with texture^ do |
2947 | 366 |
begin |
367 |
vb[0].X:= 0; |
|
368 |
vb[0].Y:= 0; |
|
369 |
vb[1].X:= w; |
|
370 |
vb[1].Y:= 0; |
|
371 |
vb[2].X:= w; |
|
372 |
vb[2].Y:= h; |
|
373 |
vb[3].X:= 0; |
|
374 |
vb[3].Y:= h; |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
375 |
|
2947 | 376 |
tb[0].X:= 0; |
377 |
tb[0].Y:= 0; |
|
378 |
tb[1].X:= rx; |
|
379 |
tb[1].Y:= 0; |
|
380 |
tb[2].X:= rx; |
|
381 |
tb[2].Y:= ry; |
|
382 |
tb[3].X:= 0; |
|
383 |
tb[3].Y:= ry |
|
384 |
end; |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
385 |
end; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
386 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
387 |
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
|
388 |
begin |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
389 |
new(NewTexture); |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
390 |
NewTexture^.PrevTexture:= nil; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
391 |
NewTexture^.NextTexture:= nil; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
392 |
if TextureList <> nil then |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
393 |
begin |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
394 |
TextureList^.PrevTexture:= NewTexture; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
395 |
NewTexture^.NextTexture:= TextureList |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
396 |
end; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
397 |
TextureList:= NewTexture; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
398 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
399 |
NewTexture^.w:= width; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
400 |
NewTexture^.h:= height; |
1896 | 401 |
NewTexture^.rx:= 1.0; |
402 |
NewTexture^.ry:= 1.0; |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
403 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
404 |
ResetVertexArrays(NewTexture); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
405 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
406 |
glGenTextures(1, @NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
407 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
408 |
glBindTexture(GL_TEXTURE_2D, NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
409 |
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
|
410 |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
411 |
SetTextureParameters(true); |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
412 |
end; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
413 |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2279
diff
changeset
|
414 |
function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture; |
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
415 |
var tw, th, x, y: Longword; |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
416 |
tmpp: pointer; |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
417 |
fromP4, toP4: PLongWordArray; |
753 | 418 |
begin |
755 | 419 |
new(Surface2Tex); |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
420 |
Surface2Tex^.PrevTexture:= nil; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
421 |
Surface2Tex^.NextTexture:= nil; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
422 |
if TextureList <> nil then |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
423 |
begin |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
424 |
TextureList^.PrevTexture:= Surface2Tex; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
425 |
Surface2Tex^.NextTexture:= TextureList |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
426 |
end; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
427 |
TextureList:= Surface2Tex; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
428 |
|
755 | 429 |
Surface2Tex^.w:= surf^.w; |
430 |
Surface2Tex^.h:= surf^.h; |
|
431 |
||
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
432 |
if (surf^.format^.BytesPerPixel <> 4) then |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
433 |
begin |
2947 | 434 |
TryDo(false, 'Surface2Tex failed, expecting 32 bit surface', true); |
435 |
Surface2Tex^.id:= 0; |
|
436 |
exit |
|
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
437 |
end; |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
438 |
|
753 | 439 |
|
755 | 440 |
glGenTextures(1, @Surface2Tex^.id); |
753 | 441 |
|
755 | 442 |
glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); |
753 | 443 |
|
771 | 444 |
if SDL_MustLock(surf) then |
2947 | 445 |
SDLTry(SDL_LockSurface(surf) >= 0, true); |
771 | 446 |
|
2428 | 447 |
if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then |
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
448 |
begin |
2947 | 449 |
tw:= toPowerOf2(Surf^.w); |
450 |
th:= toPowerOf2(Surf^.h); |
|
1896 | 451 |
|
2947 | 452 |
Surface2Tex^.rx:= Surf^.w / tw; |
453 |
Surface2Tex^.ry:= Surf^.h / th; |
|
2376 | 454 |
|
2947 | 455 |
GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); |
1896 | 456 |
|
2947 | 457 |
fromP4:= Surf^.pixels; |
458 |
toP4:= tmpp; |
|
771 | 459 |
|
2947 | 460 |
for y:= 0 to Pred(Surf^.h) do |
461 |
begin |
|
462 |
for x:= 0 to Pred(Surf^.w) do toP4^[x]:= fromP4^[x]; |
|
463 |
for x:= Surf^.w to Pred(tw) do toP4^[x]:= 0; |
|
464 |
toP4:= @(toP4^[tw]); |
|
465 |
fromP4:= @(fromP4^[Surf^.pitch div 4]); |
|
466 |
end; |
|
1896 | 467 |
|
2947 | 468 |
for y:= Surf^.h to Pred(th) do |
469 |
begin |
|
470 |
for x:= 0 to Pred(tw) do toP4^[x]:= 0; |
|
471 |
toP4:= @(toP4^[tw]); |
|
472 |
end; |
|
771 | 473 |
|
2947 | 474 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpp); |
2376 | 475 |
|
2947 | 476 |
FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
477 |
end |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
478 |
else |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
479 |
begin |
2947 | 480 |
Surface2Tex^.rx:= 1.0; |
481 |
Surface2Tex^.ry:= 1.0; |
|
482 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf^.w, surf^.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf^.pixels); |
|
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
483 |
end; |
753 | 484 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
485 |
ResetVertexArrays(Surface2Tex); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
486 |
|
754 | 487 |
if SDL_MustLock(surf) then |
2947 | 488 |
SDL_UnlockSurface(surf); |
754 | 489 |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
490 |
SetTextureParameters(enableClamp); |
753 | 491 |
end; |
492 |
||
759 | 493 |
procedure FreeTexture(tex: PTexture); |
494 |
begin |
|
2000
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
495 |
if tex <> nil then |
2947 | 496 |
begin |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
497 |
if tex^.NextTexture <> nil then tex^.NextTexture^.PrevTexture:= tex^.PrevTexture; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
498 |
if tex^.PrevTexture <> nil then tex^.PrevTexture^.NextTexture:= tex^.NextTexture |
2947 | 499 |
else TextureList:= tex^.NextTexture; |
500 |
glDeleteTextures(1, @tex^.id); |
|
501 |
Dispose(tex) |
|
502 |
end |
|
759 | 503 |
end; |
337 | 504 |
|
949 | 505 |
function DecodeBase64(s: shortstring): shortstring; |
506 |
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
507 |
var i, t, c: Longword; |
|
508 |
begin |
|
509 |
c:= 0; |
|
510 |
for i:= 1 to Length(s) do |
|
2947 | 511 |
begin |
512 |
t:= Pos(s[i], table); |
|
513 |
if s[i] = '=' then inc(c); |
|
514 |
if t > 0 then byte(s[i]):= t - 1 else byte(s[i]):= 0 |
|
515 |
end; |
|
949 | 516 |
|
517 |
i:= 1; |
|
518 |
t:= 1; |
|
519 |
while i <= length(s) do |
|
2947 | 520 |
begin |
521 |
DecodeBase64[t ]:= char((byte(s[i ]) shl 2) or (byte(s[i + 1]) shr 4)); |
|
522 |
DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2)); |
|
523 |
DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3]) )); |
|
524 |
inc(t, 3); |
|
525 |
inc(i, 4) |
|
526 |
end; |
|
949 | 527 |
|
528 |
if c < 3 then t:= t - c; |
|
529 |
||
530 |
byte(DecodeBase64[0]):= t - 1 |
|
531 |
end; |
|
532 |
||
2163
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2162
diff
changeset
|
533 |
{$IFNDEF IPHONEOS} |
2735 | 534 |
procedure MakeScreenshot(filename: shortstring); |
1080 | 535 |
var p: Pointer; |
2947 | 536 |
size: Longword; |
537 |
f: file; |
|
2735 | 538 |
{$IFNDEF WIN32} |
2947 | 539 |
// TGA Header |
540 |
head: array[0..8] of Word = (0, 2, 0, 0, 0, 0, 0, 0, 24); |
|
2735 | 541 |
{$ELSE} |
2947 | 542 |
// Windows Bitmap Header |
543 |
head: array[0..53] of Byte = ( |
|
544 |
$42, $4D, // identifier ("BM") |
|
545 |
0, 0, 0, 0, // file size |
|
546 |
0, 0, 0, 0, // reserved |
|
547 |
54, 0, 0, 0, // starting offset |
|
548 |
40, 0, 0, 0, // header size |
|
549 |
0, 0, 0, 0, // width |
|
550 |
0, 0, 0, 0, // height |
|
551 |
1, 0, // color planes |
|
552 |
24, 0, // bit depth |
|
553 |
0, 0, 0, 0, // compression method (uncompressed) |
|
554 |
0, 0, 0, 0, // image size |
|
555 |
96, 0, 0, 0, // horizontal resolution |
|
556 |
96, 0, 0, 0, // vertical resolution |
|
557 |
0, 0, 0, 0, // number of colors (all) |
|
558 |
0, 0, 0, 0 // number of important colors |
|
559 |
); |
|
2735 | 560 |
{$ENDIF} |
1080 | 561 |
begin |
2745 | 562 |
playSound(sndShutter); |
1080 | 563 |
|
3107 | 564 |
// flash |
565 |
ScreenFade:= sfFromWhite; |
|
566 |
ScreenFadeValue:= sfMax; |
|
567 |
ScreenFadeSpeed:= 5; |
|
568 |
||
1080 | 569 |
size:= cScreenWidth * cScreenHeight * 3; |
570 |
p:= GetMem(size); |
|
571 |
||
2735 | 572 |
// update header information and file name |
573 |
{$IFNDEF WIN32} |
|
574 |
filename:= ParamStr(1) + '/' + filename + '.tga'; |
|
575 |
||
576 |
head[6]:= cScreenWidth; |
|
577 |
head[7]:= cScreenHeight; |
|
578 |
{$ELSE} |
|
579 |
filename:= ParamStr(1) + '/' + filename + '.bmp'; |
|
580 |
||
581 |
head[$02]:= (size + 54) and $ff; |
|
582 |
head[$03]:= ((size + 54) shr 8) and $ff; |
|
583 |
head[$04]:= ((size + 54) shr 16) and $ff; |
|
584 |
head[$05]:= ((size + 54) shr 24) and $ff; |
|
585 |
head[$12]:= cScreenWidth and $ff; |
|
586 |
head[$13]:= (cScreenWidth shr 8) and $ff; |
|
587 |
head[$14]:= (cScreenWidth shr 16) and $ff; |
|
588 |
head[$15]:= (cScreenWidth shr 24) and $ff; |
|
589 |
head[$16]:= cScreenHeight and $ff; |
|
590 |
head[$17]:= (cScreenHeight shr 8) and $ff; |
|
591 |
head[$18]:= (cScreenHeight shr 16) and $ff; |
|
592 |
head[$19]:= (cScreenHeight shr 24) and $ff; |
|
593 |
head[$22]:= size and $ff; |
|
594 |
head[$23]:= (size shr 8) and $ff; |
|
595 |
head[$24]:= (size shr 16) and $ff; |
|
596 |
head[$25]:= (size shr 24) and $ff; |
|
597 |
{$ENDIF} |
|
2163
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2162
diff
changeset
|
598 |
|
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2162
diff
changeset
|
599 |
//remember that opengles operates on a single surface, so GL_FRONT *should* be implied |
1080 | 600 |
glReadBuffer(GL_FRONT); |
601 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p); |
|
602 |
||
603 |
{$I-} |
|
2735 | 604 |
Assign(f, filename); |
1080 | 605 |
Rewrite(f, 1); |
606 |
if IOResult = 0 then |
|
2947 | 607 |
begin |
608 |
BlockWrite(f, head, sizeof(head)); |
|
609 |
BlockWrite(f, p^, size); |
|
610 |
Close(f); |
|
611 |
end; |
|
1080 | 612 |
{$I+} |
613 |
||
614 |
FreeMem(p) |
|
615 |
end; |
|
2163
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2162
diff
changeset
|
616 |
{$ENDIF} |
1080 | 617 |
|
949 | 618 |
{$IFDEF DEBUGFILE} |
619 |
procedure AddFileLog(s: shortstring); |
|
620 |
begin |
|
621 |
writeln(f, GameTicks: 6, ': ', s); |
|
622 |
flush(f) |
|
623 |
end; |
|
624 |
||
625 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
|
626 |
begin |
|
627 |
RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
628 |
end; |
|
2242 | 629 |
{$ENDIF} |
306 | 630 |
|
2619 | 631 |
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
632 |
{* for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7 *} |
|
633 |
var convertedSurf: PSDL_Surface = nil; |
|
634 |
begin |
|
2947 | 635 |
if (tmpsurf^.format^.bitsperpixel = 24) or ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) then |
636 |
begin |
|
637 |
convertedSurf:= SDL_ConvertSurface(tmpsurf, @conversionFormat, SDL_SWSURFACE); |
|
638 |
SDL_FreeSurface(tmpsurf); |
|
639 |
exit(convertedSurf); |
|
640 |
end; |
|
2705
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2699
diff
changeset
|
641 |
|
2947 | 642 |
exit(tmpsurf); |
2619 | 643 |
end; |
644 |
||
2670 | 645 |
function endian(independent: LongWord): LongWord; |
646 |
begin |
|
647 |
{$IFDEF ENDIAN_LITTLE} |
|
648 |
endian:= independent; |
|
649 |
{$ELSE} |
|
650 |
endian:= (((independent and $FF000000) shr 24) or |
|
2947 | 651 |
((independent and $00FF0000) shr 8) or |
652 |
((independent and $0000FF00) shl 8) or |
|
653 |
((independent and $000000FF) shl 24)) |
|
2670 | 654 |
{$ENDIF} |
655 |
end; |
|
2630 | 656 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
657 |
|
3038 | 658 |
procedure initModule; |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2797
diff
changeset
|
659 |
{$IFNDEF IPHONEOS}var i: LongInt;{$ENDIF} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
660 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
661 |
cDrownSpeed.QWordValue := 257698038; // 0.06 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
662 |
cMaxWindSpeed.QWordValue:= 2147484; // 0.0005 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
663 |
cWindSpeed.QWordValue := 429496; // 0.0001 |
2947 | 664 |
cGravity := cMaxWindSpeed; |
665 |
cDamageModifier := _1; |
|
666 |
TargetPoint := cTargetPointRef; |
|
667 |
TextureList := nil; |
|
668 |
||
669 |
// int, longint longword and byte |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
670 |
CursorMovementX := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
671 |
CursorMovementY := 0; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
672 |
GameTicks := 0; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
673 |
TrainingTimeInc := 10000; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
674 |
TrainingTimeInD := 500; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
675 |
TrainingTimeInM := 5000; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
676 |
TrainingTimeMax := 60000; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
677 |
TimeTrialStartTime := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
678 |
TimeTrialStopTime := 0; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
679 |
cWaterLine := LAND_HEIGHT; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
680 |
cGearScrEdgesDist := 240; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
681 |
cHealthDecrease := 0; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
682 |
|
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
683 |
GameFlags := 0; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
684 |
TrainingFlags := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
685 |
TurnTimeLeft := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
686 |
cSuddenDTurns := 15; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
687 |
cDamagePercent := 100; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
688 |
cMineDudPercent := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
689 |
cTemplateFilter := 0; |
3133 | 690 |
cMapGen := 0;//MAPGEN_REGULAR |
691 |
cMazeSize := 0; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
692 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
693 |
cHedgehogTurnTime := 45000; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
694 |
cMinesTime := 3000; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
695 |
cMaxAIThinkTime := 9000; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
696 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
697 |
cCloudsNumber := 9; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
698 |
cScreenWidth := 1024; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
699 |
cScreenHeight := 768; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
700 |
cInitWidth := cScreenWidth; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
701 |
cInitHeight := cScreenHeight; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
702 |
cBits := 32; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
703 |
cTagsMask := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
704 |
KBnum := 0; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
705 |
InitStepsFlags := 0; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
706 |
RealTicks := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
707 |
AttackBar := 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
2947 | 708 |
|
709 |
// tgametype and glfloat and string |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
710 |
GameState := Low(TGameState); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
711 |
GameType := gmtLocal; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
712 |
zoom := 2.0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
713 |
ZoomValue := 2.0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
714 |
cBitsStr := '32'; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
715 |
WeaponTooltipTex:= nil; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
716 |
|
2947 | 717 |
// booleans |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
718 |
cLaserSighting := false; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
719 |
cVampiric := false; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
720 |
cArtillery := false; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
721 |
flagMakeCapture := false; |
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
722 |
bBetweenTurns := false; |
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
723 |
bWaterRising := false; |
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
724 |
isCursorVisible := false; |
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
725 |
isTerminated := false; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
726 |
isInLag := false; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
727 |
isPaused := false; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
728 |
isMusicEnabled := false; |
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
729 |
isInMultiShoot := false; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
730 |
isSpeed := false; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
731 |
fastUntilLag := false; |
3107 | 732 |
isFirstFrame := true; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
733 |
cVSyncInUse := true; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
734 |
isSoundEnabled := true; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
735 |
isSEBackup := true; |
2947 | 736 |
|
737 |
// init flags |
|
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
738 |
recordFileName := ''; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
739 |
cShowFPS := false; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
740 |
cCaseFactor := 5; {0..9} |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
741 |
cLandAdditions := 4; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
742 |
cExplosives := 2; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
743 |
cFullScreen := false; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
744 |
cReducedQuality := false; |
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
745 |
cLocaleFName := 'en.txt'; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
746 |
cSeed := ''; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
747 |
cInitVolume := 50; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
748 |
cVolumeDelta := 0; |
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
749 |
cTimerInterval := 8; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
750 |
cHasFocus := true; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
751 |
cInactDelay := 1250; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
752 |
cAltDamage := true; |
3107 | 753 |
|
754 |
ScreenFade := sfNone; |
|
488 | 755 |
{$IFDEF DEBUGFILE} |
337 | 756 |
{$I-} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
757 |
{$IFDEF IPHONEOS} |
2947 | 758 |
f:= stderr; |
2630 | 759 |
{$ELSE} |
2947 | 760 |
if ParamStr(1) <> '' then |
761 |
begin |
|
762 |
for i:= 0 to 7 do |
|
763 |
begin |
|
764 |
assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt'); |
|
765 |
rewrite(f); |
|
766 |
if IOResult = 0 then break; |
|
767 |
end; |
|
768 |
if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr |
|
769 |
end |
|
770 |
else |
|
771 |
f:= stderr; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
772 |
{$ENDIF} |
337 | 773 |
{$I+} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
774 |
{$ENDIF} |
17 | 775 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
776 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
777 |
|
3038 | 778 |
procedure freeModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
779 |
begin |
2947 | 780 |
//uRandom.DumpBuffer; |
781 |
while TextureList <> nil do FreeTexture(TextureList); |
|
2154
3d2917be12c3
Change default output to stderr since /tmp doesn't exist under windows and is useless under iphoneos, add a couple of extra parameters
nemo
parents:
2152
diff
changeset
|
782 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
783 |
{$IFDEF DEBUGFILE} |
2947 | 784 |
writeln(f, 'halt at ', GameTicks, ' ticks. TurnTimeLeft = ', TurnTimeLeft); |
785 |
flush(f); |
|
786 |
close(f); |
|
4 | 787 |
{$ENDIF} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
788 |
end; |
4 | 789 |
|
790 |
end. |