author | koda |
Sun, 05 Feb 2012 15:52:26 +0100 | |
changeset 6624 | e049b5bb0ad1 |
parent 6580 | 6155187bf599 |
child 6700 | e04da46ee43c |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2004-2011 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 |
*) |
|
18 |
||
4374 | 19 |
{$INCLUDE "options.inc"} |
4976 | 20 |
|
4374 | 21 |
unit uUtils; |
22 |
||
23 |
interface |
|
5661
45618bdce725
Fixed AddFileLog, there's now a log created in /sdcard/Android/data/org.hedgewars.mobile/cache/Data/
Xeli
parents:
5639
diff
changeset
|
24 |
uses uTypes, uFloat, GLunit; |
4374 | 25 |
|
26 |
procedure SplitBySpace(var a, b: shortstring); |
|
27 |
procedure SplitByChar(var a, b: ansistring; c: char); |
|
28 |
||
29 |
function EnumToStr(const en : TGearType) : shortstring; overload; |
|
4453 | 30 |
function EnumToStr(const en : TVisualGearType) : shortstring; overload; |
4374 | 31 |
function EnumToStr(const en : TSound) : shortstring; overload; |
32 |
function EnumToStr(const en : TAmmoType) : shortstring; overload; |
|
33 |
function EnumToStr(const en : THogEffect) : shortstring; overload; |
|
5118 | 34 |
function EnumToStr(const en : TCapGroup) : shortstring; overload; |
4374 | 35 |
|
36 |
function Min(a, b: LongInt): LongInt; inline; |
|
37 |
function Max(a, b: LongInt): LongInt; inline; |
|
38 |
||
39 |
function IntToStr(n: LongInt): shortstring; |
|
40 |
function FloatToStr(n: hwFloat): shortstring; |
|
41 |
||
42 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
|
43 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
|
44 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
|
5151
cbadb9fa52fc
An experiment - make bazooka AI use float instead of hwFloat - should be as accurate, but faster.
nemo
parents:
5130
diff
changeset
|
45 |
function DxDy2AttackAngle(const _dY, _dX: extended): LongInt; |
4374 | 46 |
|
47 |
procedure SetLittle(var r: hwFloat); |
|
48 |
||
49 |
function Str2PChar(const s: shortstring): PChar; |
|
50 |
function DecodeBase64(s: shortstring): shortstring; |
|
51 |
||
52 |
function isPowerOf2(i: Longword): boolean; |
|
53 |
function toPowerOf2(i: Longword): Longword; inline; |
|
54 |
||
55 |
function endian(independent: LongWord): LongWord; inline; |
|
56 |
||
4380 | 57 |
function CheckCJKFont(s: ansistring; font: THWFont): THWFont; |
58 |
||
4374 | 59 |
procedure AddFileLog(s: shortstring); |
60 |
||
4900 | 61 |
function CheckNoTeamOrHH: boolean; inline; |
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4385
diff
changeset
|
62 |
|
4403 | 63 |
function GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt; |
64 |
function GetLaunchY(at: TAmmoType; angle: LongInt): LongInt; |
|
65 |
||
4374 | 66 |
procedure initModule; |
67 |
procedure freeModule; |
|
68 |
||
4385 | 69 |
|
4374 | 70 |
implementation |
71 |
uses typinfo, Math, uConsts, uVariables, SysUtils; |
|
72 |
||
73 |
{$IFDEF DEBUGFILE} |
|
4437
05192cdbce9b
un-break build (wrong merge in uConsole) and update project file with the new sources
koda
parents:
4403
diff
changeset
|
74 |
var f: textfile; |
4374 | 75 |
{$ENDIF} |
76 |
||
77 |
// should this include "strtolower()" for the split string? |
|
78 |
procedure SplitBySpace(var a, b: shortstring); |
|
79 |
var i, t: LongInt; |
|
80 |
begin |
|
81 |
i:= Pos(' ', a); |
|
82 |
if i > 0 then |
|
83 |
begin |
|
84 |
for t:= 1 to Pred(i) do |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
85 |
if (a[t] >= 'A')and(a[t] <= 'Z') then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
86 |
Inc(a[t], 32); |
4374 | 87 |
b:= copy(a, i + 1, Length(a) - i); |
88 |
byte(a[0]):= Pred(i) |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
89 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
90 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
91 |
b:= ''; |
4374 | 92 |
end; |
93 |
||
94 |
procedure SplitByChar(var a, b: ansistring; c: char); |
|
95 |
var i: LongInt; |
|
96 |
begin |
|
97 |
i:= Pos(c, a); |
|
98 |
if i > 0 then |
|
99 |
begin |
|
100 |
b:= copy(a, i + 1, Length(a) - i); |
|
101 |
setlength(a, Pred(i)); |
|
102 |
end else b:= ''; |
|
103 |
end; |
|
104 |
||
105 |
function EnumToStr(const en : TGearType) : shortstring; overload; |
|
106 |
begin |
|
107 |
EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en)) |
|
108 |
end; |
|
4453 | 109 |
function EnumToStr(const en : TVisualGearType) : shortstring; overload; |
110 |
begin |
|
111 |
EnumToStr:= GetEnumName(TypeInfo(TVisualGearType), ord(en)) |
|
112 |
end; |
|
4374 | 113 |
|
114 |
function EnumToStr(const en : TSound) : shortstring; overload; |
|
115 |
begin |
|
116 |
EnumToStr:= GetEnumName(TypeInfo(TSound), ord(en)) |
|
117 |
end; |
|
118 |
||
119 |
function EnumToStr(const en : TAmmoType) : shortstring; overload; |
|
120 |
begin |
|
121 |
EnumToStr:= GetEnumName(TypeInfo(TAmmoType), ord(en)) |
|
122 |
end; |
|
123 |
||
124 |
function EnumToStr(const en: THogEffect) : shortstring; overload; |
|
125 |
begin |
|
5118 | 126 |
EnumToStr := GetEnumName(TypeInfo(THogEffect), ord(en)) |
127 |
end; |
|
128 |
||
129 |
function EnumToStr(const en: TCapGroup) : shortstring; overload; |
|
130 |
begin |
|
131 |
EnumToStr := GetEnumName(TypeInfo(TCapGroup), ord(en)) |
|
4374 | 132 |
end; |
133 |
||
134 |
||
135 |
function Min(a, b: LongInt): LongInt; |
|
136 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
137 |
if a < b then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
138 |
Min:= a |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
139 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
140 |
Min:= b |
4374 | 141 |
end; |
142 |
||
143 |
function Max(a, b: LongInt): LongInt; |
|
144 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
145 |
if a > b then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
146 |
Max:= a |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
147 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
148 |
Max:= b |
4374 | 149 |
end; |
150 |
||
151 |
||
152 |
function IntToStr(n: LongInt): shortstring; |
|
153 |
begin |
|
154 |
str(n, IntToStr) |
|
155 |
end; |
|
156 |
||
157 |
function FloatToStr(n: hwFloat): shortstring; |
|
158 |
begin |
|
159 |
FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue)) |
|
160 |
end; |
|
161 |
||
162 |
||
163 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
|
164 |
var dY, dX: Extended; |
|
165 |
begin |
|
166 |
dY:= _dY.QWordValue / $100000000; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
167 |
if _dY.isNegative then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
168 |
dY:= - dY; |
4374 | 169 |
dX:= _dX.QWordValue / $100000000; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
170 |
if _dX.isNegative then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
171 |
dX:= - dX; |
4374 | 172 |
DxDy2Angle:= arctan2(dY, dX) * 180 / pi |
173 |
end; |
|
174 |
||
175 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
|
176 |
const _16divPI: Extended = 16/pi; |
|
177 |
var dY, dX: Extended; |
|
178 |
begin |
|
179 |
dY:= _dY.QWordValue / $100000000; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
180 |
if _dY.isNegative then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
181 |
dY:= - dY; |
4374 | 182 |
dX:= _dX.QWordValue / $100000000; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
183 |
if _dX.isNegative then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
184 |
dX:= - dX; |
4374 | 185 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
186 |
end; |
|
187 |
||
188 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
|
189 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
|
190 |
var dY, dX: Extended; |
|
191 |
begin |
|
192 |
dY:= _dY.QWordValue / $100000000; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
193 |
if _dY.isNegative then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
194 |
dY:= - dY; |
4374 | 195 |
dX:= _dX.QWordValue / $100000000; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
196 |
if _dX.isNegative then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
197 |
dX:= - dX; |
4374 | 198 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
199 |
end; |
|
200 |
||
5151
cbadb9fa52fc
An experiment - make bazooka AI use float instead of hwFloat - should be as accurate, but faster.
nemo
parents:
5130
diff
changeset
|
201 |
function DxDy2AttackAngle(const _dY, _dX: extended): LongInt; inline; |
cbadb9fa52fc
An experiment - make bazooka AI use float instead of hwFloat - should be as accurate, but faster.
nemo
parents:
5130
diff
changeset
|
202 |
begin |
cbadb9fa52fc
An experiment - make bazooka AI use float instead of hwFloat - should be as accurate, but faster.
nemo
parents:
5130
diff
changeset
|
203 |
DxDy2AttackAngle:= trunc(arctan2(_dY, _dX) * (cMaxAngle/pi)) |
cbadb9fa52fc
An experiment - make bazooka AI use float instead of hwFloat - should be as accurate, but faster.
nemo
parents:
5130
diff
changeset
|
204 |
end; |
cbadb9fa52fc
An experiment - make bazooka AI use float instead of hwFloat - should be as accurate, but faster.
nemo
parents:
5130
diff
changeset
|
205 |
|
4374 | 206 |
|
207 |
procedure SetLittle(var r: hwFloat); |
|
208 |
begin |
|
209 |
r:= SignAs(cLittle, r) |
|
210 |
end; |
|
211 |
||
212 |
||
213 |
function isPowerOf2(i: Longword): boolean; |
|
214 |
begin |
|
4981
0c60ade27a0a
Optimize check (not like it is called much, just ffs; not tested)
unc0rr
parents:
4976
diff
changeset
|
215 |
isPowerOf2:= (i and (i - 1)) = 0 |
4374 | 216 |
end; |
217 |
||
218 |
function toPowerOf2(i: Longword): Longword; |
|
219 |
begin |
|
220 |
toPowerOf2:= 1; |
|
221 |
while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1 |
|
222 |
end; |
|
223 |
||
224 |
||
225 |
function DecodeBase64(s: shortstring): shortstring; |
|
226 |
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
227 |
var i, t, c: Longword; |
|
228 |
begin |
|
229 |
c:= 0; |
|
230 |
for i:= 1 to Length(s) do |
|
231 |
begin |
|
232 |
t:= Pos(s[i], table); |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
233 |
if s[i] = '=' then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
234 |
inc(c); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
235 |
if t > 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
236 |
byte(s[i]):= t - 1 |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
237 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
238 |
byte(s[i]):= 0 |
4374 | 239 |
end; |
240 |
||
241 |
i:= 1; |
|
242 |
t:= 1; |
|
243 |
while i <= length(s) do |
|
244 |
begin |
|
245 |
DecodeBase64[t ]:= char((byte(s[i ]) shl 2) or (byte(s[i + 1]) shr 4)); |
|
246 |
DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2)); |
|
247 |
DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3]) )); |
|
248 |
inc(t, 3); |
|
249 |
inc(i, 4) |
|
250 |
end; |
|
251 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
252 |
if c < 3 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
253 |
t:= t - c; |
4374 | 254 |
|
255 |
byte(DecodeBase64[0]):= t - 1 |
|
256 |
end; |
|
257 |
||
258 |
||
259 |
function Str2PChar(const s: shortstring): PChar; |
|
260 |
const CharArray: array[byte] of Char = ''; |
|
261 |
begin |
|
262 |
CharArray:= s; |
|
263 |
CharArray[Length(s)]:= #0; |
|
264 |
Str2PChar:= @CharArray |
|
265 |
end; |
|
266 |
||
267 |
||
268 |
function endian(independent: LongWord): LongWord; inline; |
|
269 |
begin |
|
270 |
{$IFDEF ENDIAN_LITTLE} |
|
271 |
endian:= independent; |
|
272 |
{$ELSE} |
|
273 |
endian:= (((independent and $FF000000) shr 24) or |
|
274 |
((independent and $00FF0000) shr 8) or |
|
275 |
((independent and $0000FF00) shl 8) or |
|
276 |
((independent and $000000FF) shl 24)) |
|
277 |
{$ENDIF} |
|
278 |
end; |
|
279 |
||
280 |
||
281 |
procedure AddFileLog(s: shortstring); |
|
282 |
begin |
|
4900 | 283 |
s:= s; |
284 |
{$IFDEF DEBUGFILE} |
|
6444 | 285 |
writeln(f, GameTicks, ': ', s); |
4374 | 286 |
flush(f) |
4900 | 287 |
{$ENDIF} |
4374 | 288 |
end; |
289 |
||
290 |
||
4380 | 291 |
function CheckCJKFont(s: ansistring; font: THWFont): THWFont; |
292 |
var l, i : LongInt; |
|
293 |
u: WideChar; |
|
294 |
tmpstr: array[0..256] of WideChar; |
|
295 |
begin |
|
296 |
||
5639 | 297 |
{$IFNDEF MOBILE} |
4380 | 298 |
// remove chinese fonts for now |
299 |
if (font >= CJKfnt16) or (length(s) = 0) then |
|
300 |
{$ENDIF} |
|
301 |
exit(font); |
|
302 |
||
303 |
l:= Utf8ToUnicode(@tmpstr, Str2PChar(s), length(s))-1; |
|
304 |
i:= 0; |
|
4737 | 305 |
|
4380 | 306 |
while i < l do |
307 |
begin |
|
308 |
u:= tmpstr[i]; |
|
4737 | 309 |
if (#$1100 <= u) and ( |
310 |
(u <= #$11FF ) or // Hangul Jamo |
|
311 |
((#$2E80 <= u) and (u <= #$2FDF)) or // CJK Radicals Supplement / Kangxi Radicals |
|
4380 | 312 |
((#$2FF0 <= u) and (u <= #$303F)) or // Ideographic Description Characters / CJK Radicals Supplement |
4737 | 313 |
((#$3130 <= u) and (u <= #$318F)) or // Hangul Compatibility Jamo |
4380 | 314 |
((#$31C0 <= u) and (u <= #$31EF)) or // CJK Strokes |
315 |
((#$3200 <= u) and (u <= #$4DBF)) or // Enclosed CJK Letters and Months / CJK Compatibility / CJK Unified Ideographs Extension A |
|
316 |
((#$4E00 <= u) and (u <= #$9FFF)) or // CJK Unified Ideographs |
|
4737 | 317 |
((#$AC00 <= u) and (u <= #$D7AF)) or // Hangul Syllables |
4380 | 318 |
((#$F900 <= u) and (u <= #$FAFF)) or // CJK Compatibility Ideographs |
319 |
((#$FE30 <= u) and (u <= #$FE4F))) // CJK Compatibility Forms |
|
320 |
then exit(THWFont( ord(font) + ((ord(High(THWFont))+1) div 2) )); |
|
321 |
inc(i) |
|
322 |
end; |
|
323 |
exit(font); |
|
324 |
(* two more to check. pascal WideChar is only 16 bit though |
|
325 |
((#$20000 <= u) and (u >= #$2A6DF)) or // CJK Unified Ideographs Extension B |
|
326 |
((#$2F800 <= u) and (u >= #$2FA1F))) // CJK Compatibility Ideographs Supplement *) |
|
327 |
end; |
|
328 |
||
4385 | 329 |
|
330 |
function GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt; |
|
331 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
332 |
GetLaunchX:= 0 |
4665
fa7ad5f3725f
Make basic training solvable again. Freeze RNG at current version for less of this kind of issue in future, and a bit more savable of seeds. Disable offsets in preparation for release.
nemo
parents:
4453
diff
changeset
|
333 |
(* |
4385 | 334 |
if (Ammoz[at].ejectX <> 0) or (Ammoz[at].ejectY <> 0) then |
335 |
GetLaunchX:= sign(dir) * (8 + hwRound(AngleSin(angle) * Ammoz[at].ejectX) + hwRound(AngleCos(angle) * Ammoz[at].ejectY)) |
|
336 |
else |
|
4665
fa7ad5f3725f
Make basic training solvable again. Freeze RNG at current version for less of this kind of issue in future, and a bit more savable of seeds. Disable offsets in preparation for release.
nemo
parents:
4453
diff
changeset
|
337 |
GetLaunchX:= 0 *) |
4385 | 338 |
end; |
339 |
||
340 |
function GetLaunchY(at: TAmmoType; angle: LongInt): LongInt; |
|
341 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
342 |
GetLaunchY:= 0 |
4665
fa7ad5f3725f
Make basic training solvable again. Freeze RNG at current version for less of this kind of issue in future, and a bit more savable of seeds. Disable offsets in preparation for release.
nemo
parents:
4453
diff
changeset
|
343 |
(* |
4385 | 344 |
if (Ammoz[at].ejectX <> 0) or (Ammoz[at].ejectY <> 0) then |
345 |
GetLaunchY:= hwRound(AngleSin(angle) * Ammoz[at].ejectY) - hwRound(AngleCos(angle) * Ammoz[at].ejectX) - 2 |
|
346 |
else |
|
4665
fa7ad5f3725f
Make basic training solvable again. Freeze RNG at current version for less of this kind of issue in future, and a bit more savable of seeds. Disable offsets in preparation for release.
nemo
parents:
4453
diff
changeset
|
347 |
GetLaunchY:= 0*) |
4385 | 348 |
end; |
349 |
||
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4385
diff
changeset
|
350 |
function CheckNoTeamOrHH: boolean; |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4385
diff
changeset
|
351 |
begin |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4385
diff
changeset
|
352 |
CheckNoTeamOrHH:= (CurrentTeam = nil) or (CurrentHedgehog^.Gear = nil); |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4385
diff
changeset
|
353 |
end; |
4385 | 354 |
|
4374 | 355 |
procedure initModule; |
5661
45618bdce725
Fixed AddFileLog, there's now a log created in /sdcard/Android/data/org.hedgewars.mobile/cache/Data/
Xeli
parents:
5639
diff
changeset
|
356 |
{$IFDEF DEBUGFILE}{$IFNDEF MOBILE}var i: LongInt;{$ENDIF}{$ENDIF} |
4374 | 357 |
begin |
358 |
{$IFDEF DEBUGFILE} |
|
359 |
{$I-} |
|
5661
45618bdce725
Fixed AddFileLog, there's now a log created in /sdcard/Android/data/org.hedgewars.mobile/cache/Data/
Xeli
parents:
5639
diff
changeset
|
360 |
{$IFDEF MOBILE} |
45618bdce725
Fixed AddFileLog, there's now a log created in /sdcard/Android/data/org.hedgewars.mobile/cache/Data/
Xeli
parents:
5639
diff
changeset
|
361 |
{$IFDEF IPHONEOS} Assign(f,'../Documents/hw-' + cLogfileBase + '.log'); {$ENDIF} |
45618bdce725
Fixed AddFileLog, there's now a log created in /sdcard/Android/data/org.hedgewars.mobile/cache/Data/
Xeli
parents:
5639
diff
changeset
|
362 |
{$IFDEF ANDROID} Assign(f,pathPrefix + '/' + cLogfileBase + '.log'); {$ENDIF} |
4374 | 363 |
Rewrite(f); |
364 |
{$ELSE} |
|
5831 | 365 |
if (UserPathPrefix <> '') then |
4374 | 366 |
begin |
5130
3602ede67ec5
Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents:
5118
diff
changeset
|
367 |
i:= 0; |
3602ede67ec5
Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents:
5118
diff
changeset
|
368 |
while(i < 7) do |
4374 | 369 |
begin |
5239 | 370 |
assign(f, UserPathPrefix + '/Logs/' + cLogfileBase + inttostr(i) + '.log'); |
4374 | 371 |
rewrite(f); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
372 |
if IOResult = 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
373 |
break; |
5130
3602ede67ec5
Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents:
5118
diff
changeset
|
374 |
inc(i) |
4374 | 375 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
376 |
if i = 7 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
377 |
f:= stderr; // if everything fails, write to stderr |
4374 | 378 |
end |
379 |
else |
|
380 |
f:= stderr; |
|
381 |
{$ENDIF} |
|
382 |
{$I+} |
|
383 |
{$ENDIF} |
|
384 |
||
385 |
end; |
|
386 |
||
387 |
procedure freeModule; |
|
388 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
389 |
recordFileName:= ''; |
4374 | 390 |
|
391 |
{$IFDEF DEBUGFILE} |
|
392 |
writeln(f, 'halt at ', GameTicks, ' ticks. TurnTimeLeft = ', TurnTimeLeft); |
|
393 |
flush(f); |
|
394 |
close(f); |
|
395 |
{$ENDIF} |
|
396 |
end; |
|
397 |
||
4453 | 398 |
end. |