author | Medo <smaxein@googlemail.com> |
Wed, 22 Aug 2012 01:30:56 +0200 | |
changeset 7586 | 33924ff4af50 |
parent 7548 | c7a21fc530de |
child 7565 | 00568d3054d0 |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
6700 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
4976 | 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); |
|
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7151
diff
changeset
|
27 |
procedure SplitByChar(var a, b: shortstring; c: char); |
4374 | 28 |
procedure SplitByChar(var a, b: ansistring; c: char); |
29 |
||
6894 | 30 |
{$IFNDEF PAS2C} |
4374 | 31 |
function EnumToStr(const en : TGearType) : shortstring; overload; |
4453 | 32 |
function EnumToStr(const en : TVisualGearType) : shortstring; overload; |
4374 | 33 |
function EnumToStr(const en : TSound) : shortstring; overload; |
34 |
function EnumToStr(const en : TAmmoType) : shortstring; overload; |
|
35 |
function EnumToStr(const en : THogEffect) : shortstring; overload; |
|
5118 | 36 |
function EnumToStr(const en : TCapGroup) : shortstring; overload; |
6894 | 37 |
{$ENDIF} |
4374 | 38 |
|
39 |
function Min(a, b: LongInt): LongInt; inline; |
|
40 |
function Max(a, b: LongInt): LongInt; inline; |
|
41 |
||
42 |
function IntToStr(n: LongInt): shortstring; |
|
7151 | 43 |
function StrToInt(s: shortstring): LongInt; |
4374 | 44 |
function FloatToStr(n: hwFloat): shortstring; |
45 |
||
7548
c7a21fc530de
This one gets called a lot when drawing rotated sprites
nemo
parents:
7547
diff
changeset
|
46 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; inline; |
4374 | 47 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
48 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
|
6894 | 49 |
function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; |
4374 | 50 |
|
51 |
procedure SetLittle(var r: hwFloat); |
|
52 |
||
53 |
function Str2PChar(const s: shortstring): PChar; |
|
54 |
function DecodeBase64(s: shortstring): shortstring; |
|
55 |
||
56 |
function isPowerOf2(i: Longword): boolean; |
|
57 |
function toPowerOf2(i: Longword): Longword; inline; |
|
58 |
||
59 |
function endian(independent: LongWord): LongWord; inline; |
|
60 |
||
4380 | 61 |
function CheckCJKFont(s: ansistring; font: THWFont): THWFont; |
62 |
||
4374 | 63 |
procedure AddFileLog(s: shortstring); |
64 |
||
4900 | 65 |
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
|
66 |
|
4403 | 67 |
function GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt; |
68 |
function GetLaunchY(at: TAmmoType; angle: LongInt): LongInt; |
|
69 |
||
7151 | 70 |
{$IFNDEF PAS2C} |
71 |
procedure Write(var f: textfile; s: shortstring); |
|
72 |
procedure WriteLn(var f: textfile; s: shortstring); |
|
73 |
{$ENDIF} |
|
74 |
||
7027 | 75 |
procedure initModule(isGame: boolean); |
4374 | 76 |
procedure freeModule; |
77 |
||
4385 | 78 |
|
4374 | 79 |
implementation |
7043
7c080e5ac8d0
Some work to make more units compile after conversion to c
unc0rr
parents:
7028
diff
changeset
|
80 |
uses {$IFNDEF PAS2C}typinfo, {$ENDIF}Math, uConsts, uVariables, SysUtils; |
4374 | 81 |
|
82 |
{$IFDEF DEBUGFILE} |
|
4437
05192cdbce9b
un-break build (wrong merge in uConsole) and update project file with the new sources
koda
parents:
4403
diff
changeset
|
83 |
var f: textfile; |
4374 | 84 |
{$ENDIF} |
7028 | 85 |
var CharArray: array[byte] of Char; |
4374 | 86 |
|
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7151
diff
changeset
|
87 |
procedure SplitBySpace(var a,b: shortstring); |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7151
diff
changeset
|
88 |
begin |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7151
diff
changeset
|
89 |
SplitByChar(a,b,' '); |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7151
diff
changeset
|
90 |
end; |
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7151
diff
changeset
|
91 |
|
4374 | 92 |
// should this include "strtolower()" for the split string? |
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7151
diff
changeset
|
93 |
procedure SplitByChar(var a, b: shortstring; c : char); |
4374 | 94 |
var i, t: LongInt; |
95 |
begin |
|
7191
9419294e5f33
first attempt at implementing support for keys with modifiers
Xeli
parents:
7151
diff
changeset
|
96 |
i:= Pos(c, a); |
4374 | 97 |
if i > 0 then |
98 |
begin |
|
99 |
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
|
100 |
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
|
101 |
Inc(a[t], 32); |
4374 | 102 |
b:= copy(a, i + 1, Length(a) - i); |
7074 | 103 |
a[0]:= char(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
|
104 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
105 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
106 |
b:= ''; |
4374 | 107 |
end; |
108 |
||
109 |
procedure SplitByChar(var a, b: ansistring; c: char); |
|
110 |
var i: LongInt; |
|
111 |
begin |
|
112 |
i:= Pos(c, a); |
|
113 |
if i > 0 then |
|
114 |
begin |
|
115 |
b:= copy(a, i + 1, Length(a) - i); |
|
116 |
setlength(a, Pred(i)); |
|
117 |
end else b:= ''; |
|
118 |
end; |
|
119 |
||
6894 | 120 |
{$IFNDEF PAS2C} |
4374 | 121 |
function EnumToStr(const en : TGearType) : shortstring; overload; |
122 |
begin |
|
123 |
EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en)) |
|
124 |
end; |
|
4453 | 125 |
function EnumToStr(const en : TVisualGearType) : shortstring; overload; |
126 |
begin |
|
127 |
EnumToStr:= GetEnumName(TypeInfo(TVisualGearType), ord(en)) |
|
128 |
end; |
|
4374 | 129 |
|
130 |
function EnumToStr(const en : TSound) : shortstring; overload; |
|
131 |
begin |
|
132 |
EnumToStr:= GetEnumName(TypeInfo(TSound), ord(en)) |
|
133 |
end; |
|
134 |
||
135 |
function EnumToStr(const en : TAmmoType) : shortstring; overload; |
|
136 |
begin |
|
137 |
EnumToStr:= GetEnumName(TypeInfo(TAmmoType), ord(en)) |
|
138 |
end; |
|
139 |
||
140 |
function EnumToStr(const en: THogEffect) : shortstring; overload; |
|
141 |
begin |
|
5118 | 142 |
EnumToStr := GetEnumName(TypeInfo(THogEffect), ord(en)) |
143 |
end; |
|
144 |
||
145 |
function EnumToStr(const en: TCapGroup) : shortstring; overload; |
|
146 |
begin |
|
147 |
EnumToStr := GetEnumName(TypeInfo(TCapGroup), ord(en)) |
|
4374 | 148 |
end; |
6894 | 149 |
{$ENDIF} |
4374 | 150 |
|
151 |
function Min(a, b: LongInt): LongInt; |
|
152 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
153 |
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
|
154 |
Min:= a |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
155 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
156 |
Min:= b |
4374 | 157 |
end; |
158 |
||
159 |
function Max(a, b: LongInt): LongInt; |
|
160 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
161 |
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
|
162 |
Max:= a |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
163 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
164 |
Max:= b |
4374 | 165 |
end; |
166 |
||
167 |
||
168 |
function IntToStr(n: LongInt): shortstring; |
|
169 |
begin |
|
170 |
str(n, IntToStr) |
|
171 |
end; |
|
172 |
||
7151 | 173 |
function StrToInt(s: shortstring): LongInt; |
174 |
var c: LongInt; |
|
175 |
begin |
|
176 |
val(s, StrToInt, c) |
|
177 |
end; |
|
178 |
||
4374 | 179 |
function FloatToStr(n: hwFloat): shortstring; |
180 |
begin |
|
181 |
FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue)) |
|
182 |
end; |
|
183 |
||
184 |
||
7548
c7a21fc530de
This one gets called a lot when drawing rotated sprites
nemo
parents:
7547
diff
changeset
|
185 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; inline; |
4374 | 186 |
var dY, dX: Extended; |
187 |
begin |
|
7547 | 188 |
dY:= hwFloat2Float(_dY); |
189 |
dX:= hwFloat2Float(_dX); |
|
4374 | 190 |
DxDy2Angle:= arctan2(dY, dX) * 180 / pi |
191 |
end; |
|
192 |
||
193 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
|
194 |
const _16divPI: Extended = 16/pi; |
|
195 |
var dY, dX: Extended; |
|
196 |
begin |
|
7547 | 197 |
dY:= hwFloat2Float(_dY); |
198 |
dX:= hwFloat2Float(_dX); |
|
4374 | 199 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
200 |
end; |
|
201 |
||
202 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
|
203 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
|
204 |
var dY, dX: Extended; |
|
205 |
begin |
|
7547 | 206 |
dY:= hwFloat2Float(_dY); |
207 |
dX:= hwFloat2Float(_dX); |
|
4374 | 208 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
209 |
end; |
|
210 |
||
6894 | 211 |
function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; inline; |
5151
cbadb9fa52fc
An experiment - make bazooka AI use float instead of hwFloat - should be as accurate, but faster.
nemo
parents:
5130
diff
changeset
|
212 |
begin |
6894 | 213 |
DxDy2AttackAnglef:= trunc(arctan2(_dY, _dX) * (cMaxAngle/pi)) |
5151
cbadb9fa52fc
An experiment - make bazooka AI use float instead of hwFloat - should be as accurate, but faster.
nemo
parents:
5130
diff
changeset
|
214 |
end; |
cbadb9fa52fc
An experiment - make bazooka AI use float instead of hwFloat - should be as accurate, but faster.
nemo
parents:
5130
diff
changeset
|
215 |
|
4374 | 216 |
|
217 |
procedure SetLittle(var r: hwFloat); |
|
218 |
begin |
|
219 |
r:= SignAs(cLittle, r) |
|
220 |
end; |
|
221 |
||
222 |
||
223 |
function isPowerOf2(i: Longword): boolean; |
|
224 |
begin |
|
4981
0c60ade27a0a
Optimize check (not like it is called much, just ffs; not tested)
unc0rr
parents:
4976
diff
changeset
|
225 |
isPowerOf2:= (i and (i - 1)) = 0 |
4374 | 226 |
end; |
227 |
||
228 |
function toPowerOf2(i: Longword): Longword; |
|
229 |
begin |
|
230 |
toPowerOf2:= 1; |
|
231 |
while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1 |
|
232 |
end; |
|
233 |
||
234 |
||
235 |
function DecodeBase64(s: shortstring): shortstring; |
|
236 |
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
237 |
var i, t, c: Longword; |
|
238 |
begin |
|
239 |
c:= 0; |
|
240 |
for i:= 1 to Length(s) do |
|
241 |
begin |
|
242 |
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
|
243 |
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
|
244 |
inc(c); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
245 |
if t > 0 then |
7074 | 246 |
s[i]:= char(t - 1) |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
247 |
else |
7074 | 248 |
s[i]:= #0 |
4374 | 249 |
end; |
250 |
||
251 |
i:= 1; |
|
252 |
t:= 1; |
|
253 |
while i <= length(s) do |
|
254 |
begin |
|
255 |
DecodeBase64[t ]:= char((byte(s[i ]) shl 2) or (byte(s[i + 1]) shr 4)); |
|
256 |
DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2)); |
|
257 |
DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3]) )); |
|
258 |
inc(t, 3); |
|
259 |
inc(i, 4) |
|
260 |
end; |
|
261 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
262 |
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
|
263 |
t:= t - c; |
4374 | 264 |
|
7074 | 265 |
DecodeBase64[0]:= char(t - 1) |
4374 | 266 |
end; |
267 |
||
268 |
||
269 |
function Str2PChar(const s: shortstring): PChar; |
|
270 |
begin |
|
271 |
CharArray:= s; |
|
272 |
CharArray[Length(s)]:= #0; |
|
273 |
Str2PChar:= @CharArray |
|
274 |
end; |
|
275 |
||
276 |
||
277 |
function endian(independent: LongWord): LongWord; inline; |
|
278 |
begin |
|
279 |
{$IFDEF ENDIAN_LITTLE} |
|
280 |
endian:= independent; |
|
281 |
{$ELSE} |
|
282 |
endian:= (((independent and $FF000000) shr 24) or |
|
283 |
((independent and $00FF0000) shr 8) or |
|
284 |
((independent and $0000FF00) shl 8) or |
|
285 |
((independent and $000000FF) shl 24)) |
|
286 |
{$ENDIF} |
|
287 |
end; |
|
288 |
||
289 |
||
290 |
procedure AddFileLog(s: shortstring); |
|
291 |
begin |
|
4900 | 292 |
s:= s; |
293 |
{$IFDEF DEBUGFILE} |
|
7151 | 294 |
writeln(f, inttostr(GameTicks) + ': ' + s); |
4374 | 295 |
flush(f) |
4900 | 296 |
{$ENDIF} |
4374 | 297 |
end; |
298 |
||
299 |
||
4380 | 300 |
function CheckCJKFont(s: ansistring; font: THWFont): THWFont; |
301 |
var l, i : LongInt; |
|
302 |
u: WideChar; |
|
303 |
tmpstr: array[0..256] of WideChar; |
|
304 |
begin |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6978
diff
changeset
|
305 |
CheckCJKFont:= font; |
4380 | 306 |
|
5639 | 307 |
{$IFNDEF MOBILE} |
4380 | 308 |
// remove chinese fonts for now |
309 |
if (font >= CJKfnt16) or (length(s) = 0) then |
|
310 |
{$ENDIF} |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6978
diff
changeset
|
311 |
exit; |
4380 | 312 |
|
313 |
l:= Utf8ToUnicode(@tmpstr, Str2PChar(s), length(s))-1; |
|
314 |
i:= 0; |
|
4737 | 315 |
|
4380 | 316 |
while i < l do |
317 |
begin |
|
318 |
u:= tmpstr[i]; |
|
4737 | 319 |
if (#$1100 <= u) and ( |
320 |
(u <= #$11FF ) or // Hangul Jamo |
|
321 |
((#$2E80 <= u) and (u <= #$2FDF)) or // CJK Radicals Supplement / Kangxi Radicals |
|
4380 | 322 |
((#$2FF0 <= u) and (u <= #$303F)) or // Ideographic Description Characters / CJK Radicals Supplement |
4737 | 323 |
((#$3130 <= u) and (u <= #$318F)) or // Hangul Compatibility Jamo |
4380 | 324 |
((#$31C0 <= u) and (u <= #$31EF)) or // CJK Strokes |
325 |
((#$3200 <= u) and (u <= #$4DBF)) or // Enclosed CJK Letters and Months / CJK Compatibility / CJK Unified Ideographs Extension A |
|
326 |
((#$4E00 <= u) and (u <= #$9FFF)) or // CJK Unified Ideographs |
|
4737 | 327 |
((#$AC00 <= u) and (u <= #$D7AF)) or // Hangul Syllables |
4380 | 328 |
((#$F900 <= u) and (u <= #$FAFF)) or // CJK Compatibility Ideographs |
329 |
((#$FE30 <= u) and (u <= #$FE4F))) // CJK Compatibility Forms |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6978
diff
changeset
|
330 |
then |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6978
diff
changeset
|
331 |
begin |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6978
diff
changeset
|
332 |
CheckCJKFont:= THWFont( ord(font) + ((ord(High(THWFont))+1) div 2) ); |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6978
diff
changeset
|
333 |
exit; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6978
diff
changeset
|
334 |
end; |
4380 | 335 |
inc(i) |
336 |
end; |
|
337 |
(* two more to check. pascal WideChar is only 16 bit though |
|
338 |
((#$20000 <= u) and (u >= #$2A6DF)) or // CJK Unified Ideographs Extension B |
|
339 |
((#$2F800 <= u) and (u >= #$2FA1F))) // CJK Compatibility Ideographs Supplement *) |
|
340 |
end; |
|
341 |
||
4385 | 342 |
|
343 |
function GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt; |
|
344 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
345 |
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
|
346 |
(* |
4385 | 347 |
if (Ammoz[at].ejectX <> 0) or (Ammoz[at].ejectY <> 0) then |
348 |
GetLaunchX:= sign(dir) * (8 + hwRound(AngleSin(angle) * Ammoz[at].ejectX) + hwRound(AngleCos(angle) * Ammoz[at].ejectY)) |
|
349 |
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
|
350 |
GetLaunchX:= 0 *) |
4385 | 351 |
end; |
352 |
||
353 |
function GetLaunchY(at: TAmmoType; angle: LongInt): LongInt; |
|
354 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
355 |
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
|
356 |
(* |
4385 | 357 |
if (Ammoz[at].ejectX <> 0) or (Ammoz[at].ejectY <> 0) then |
358 |
GetLaunchY:= hwRound(AngleSin(angle) * Ammoz[at].ejectY) - hwRound(AngleCos(angle) * Ammoz[at].ejectX) - 2 |
|
359 |
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
|
360 |
GetLaunchY:= 0*) |
4385 | 361 |
end; |
362 |
||
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
|
363 |
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
|
364 |
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
|
365 |
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
|
366 |
end; |
4385 | 367 |
|
7151 | 368 |
{$IFNDEF PAS2C} |
369 |
procedure Write(var f: textfile; s: shortstring); |
|
370 |
begin |
|
371 |
system.write(f, s) |
|
372 |
end; |
|
373 |
||
374 |
procedure WriteLn(var f: textfile; s: shortstring); |
|
375 |
begin |
|
376 |
system.writeln(f, s) |
|
377 |
end; |
|
378 |
{$ENDIF} |
|
379 |
||
7027 | 380 |
procedure initModule(isGame: boolean); |
381 |
{$IFDEF DEBUGFILE} |
|
382 |
var logfileBase: shortstring; |
|
383 |
{$IFNDEF MOBILE}var i: LongInt;{$ENDIF} |
|
384 |
{$ENDIF} |
|
4374 | 385 |
begin |
386 |
{$IFDEF DEBUGFILE} |
|
7027 | 387 |
if isGame then |
388 |
logfileBase:= 'game' |
|
389 |
else |
|
390 |
logfileBase:= 'preview'; |
|
4374 | 391 |
{$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
|
392 |
{$IFDEF MOBILE} |
7027 | 393 |
{$IFDEF IPHONEOS} Assign(f,'../Documents/hw-' + logfileBase + '.log'); {$ENDIF} |
394 |
{$IFDEF ANDROID} Assign(f,pathPrefix + '/' + logfileBase + '.log'); {$ENDIF} |
|
4374 | 395 |
Rewrite(f); |
396 |
{$ELSE} |
|
5831 | 397 |
if (UserPathPrefix <> '') then |
4374 | 398 |
begin |
5130
3602ede67ec5
Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents:
5118
diff
changeset
|
399 |
i:= 0; |
3602ede67ec5
Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents:
5118
diff
changeset
|
400 |
while(i < 7) do |
4374 | 401 |
begin |
7027 | 402 |
assign(f, UserPathPrefix + '/Logs/' + logfileBase + inttostr(i) + '.log'); |
4374 | 403 |
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
|
404 |
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
|
405 |
break; |
5130
3602ede67ec5
Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents:
5118
diff
changeset
|
406 |
inc(i) |
4374 | 407 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
408 |
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
|
409 |
f:= stderr; // if everything fails, write to stderr |
4374 | 410 |
end |
411 |
else |
|
412 |
f:= stderr; |
|
413 |
{$ENDIF} |
|
414 |
{$I+} |
|
415 |
{$ENDIF} |
|
416 |
||
417 |
end; |
|
418 |
||
419 |
procedure freeModule; |
|
420 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
421 |
recordFileName:= ''; |
4374 | 422 |
|
423 |
{$IFDEF DEBUGFILE} |
|
7151 | 424 |
writeln(f, 'halt at ' + inttostr(GameTicks) + ' ticks. TurnTimeLeft = ' + inttostr(TurnTimeLeft)); |
4374 | 425 |
flush(f); |
426 |
close(f); |
|
427 |
{$ENDIF} |
|
428 |
end; |
|
429 |
||
4453 | 430 |
end. |