author | Medo <smaxein@googlemail.com> |
Wed, 27 Jun 2012 18:02:45 +0200 | |
changeset 7275 | 15f722e0b96f |
parent 7191 | 9419294e5f33 |
child 7194 | d8e68cbca7ee |
child 7547 | 6e9c5feb88eb |
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 |
||
46 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
|
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 |
||
185 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
|
186 |
var dY, dX: Extended; |
|
187 |
begin |
|
188 |
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
|
189 |
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
|
190 |
dY:= - dY; |
4374 | 191 |
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
|
192 |
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
|
193 |
dX:= - dX; |
4374 | 194 |
DxDy2Angle:= arctan2(dY, dX) * 180 / pi |
195 |
end; |
|
196 |
||
197 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
|
198 |
const _16divPI: Extended = 16/pi; |
|
199 |
var dY, dX: Extended; |
|
200 |
begin |
|
201 |
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
|
202 |
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
|
203 |
dY:= - dY; |
4374 | 204 |
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
|
205 |
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
|
206 |
dX:= - dX; |
4374 | 207 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
208 |
end; |
|
209 |
||
210 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
|
211 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
|
212 |
var dY, dX: Extended; |
|
213 |
begin |
|
214 |
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
|
215 |
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
|
216 |
dY:= - dY; |
4374 | 217 |
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
|
218 |
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
|
219 |
dX:= - dX; |
4374 | 220 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
221 |
end; |
|
222 |
||
6894 | 223 |
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
|
224 |
begin |
6894 | 225 |
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
|
226 |
end; |
cbadb9fa52fc
An experiment - make bazooka AI use float instead of hwFloat - should be as accurate, but faster.
nemo
parents:
5130
diff
changeset
|
227 |
|
4374 | 228 |
|
229 |
procedure SetLittle(var r: hwFloat); |
|
230 |
begin |
|
231 |
r:= SignAs(cLittle, r) |
|
232 |
end; |
|
233 |
||
234 |
||
235 |
function isPowerOf2(i: Longword): boolean; |
|
236 |
begin |
|
4981
0c60ade27a0a
Optimize check (not like it is called much, just ffs; not tested)
unc0rr
parents:
4976
diff
changeset
|
237 |
isPowerOf2:= (i and (i - 1)) = 0 |
4374 | 238 |
end; |
239 |
||
240 |
function toPowerOf2(i: Longword): Longword; |
|
241 |
begin |
|
242 |
toPowerOf2:= 1; |
|
243 |
while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1 |
|
244 |
end; |
|
245 |
||
246 |
||
247 |
function DecodeBase64(s: shortstring): shortstring; |
|
248 |
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
249 |
var i, t, c: Longword; |
|
250 |
begin |
|
251 |
c:= 0; |
|
252 |
for i:= 1 to Length(s) do |
|
253 |
begin |
|
254 |
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
|
255 |
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
|
256 |
inc(c); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
257 |
if t > 0 then |
7074 | 258 |
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
|
259 |
else |
7074 | 260 |
s[i]:= #0 |
4374 | 261 |
end; |
262 |
||
263 |
i:= 1; |
|
264 |
t:= 1; |
|
265 |
while i <= length(s) do |
|
266 |
begin |
|
267 |
DecodeBase64[t ]:= char((byte(s[i ]) shl 2) or (byte(s[i + 1]) shr 4)); |
|
268 |
DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2)); |
|
269 |
DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3]) )); |
|
270 |
inc(t, 3); |
|
271 |
inc(i, 4) |
|
272 |
end; |
|
273 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
274 |
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
|
275 |
t:= t - c; |
4374 | 276 |
|
7074 | 277 |
DecodeBase64[0]:= char(t - 1) |
4374 | 278 |
end; |
279 |
||
280 |
||
281 |
function Str2PChar(const s: shortstring): PChar; |
|
282 |
begin |
|
283 |
CharArray:= s; |
|
284 |
CharArray[Length(s)]:= #0; |
|
285 |
Str2PChar:= @CharArray |
|
286 |
end; |
|
287 |
||
288 |
||
289 |
function endian(independent: LongWord): LongWord; inline; |
|
290 |
begin |
|
291 |
{$IFDEF ENDIAN_LITTLE} |
|
292 |
endian:= independent; |
|
293 |
{$ELSE} |
|
294 |
endian:= (((independent and $FF000000) shr 24) or |
|
295 |
((independent and $00FF0000) shr 8) or |
|
296 |
((independent and $0000FF00) shl 8) or |
|
297 |
((independent and $000000FF) shl 24)) |
|
298 |
{$ENDIF} |
|
299 |
end; |
|
300 |
||
301 |
||
302 |
procedure AddFileLog(s: shortstring); |
|
303 |
begin |
|
4900 | 304 |
s:= s; |
305 |
{$IFDEF DEBUGFILE} |
|
7151 | 306 |
writeln(f, inttostr(GameTicks) + ': ' + s); |
4374 | 307 |
flush(f) |
4900 | 308 |
{$ENDIF} |
4374 | 309 |
end; |
310 |
||
311 |
||
4380 | 312 |
function CheckCJKFont(s: ansistring; font: THWFont): THWFont; |
313 |
var l, i : LongInt; |
|
314 |
u: WideChar; |
|
315 |
tmpstr: array[0..256] of WideChar; |
|
316 |
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
|
317 |
CheckCJKFont:= font; |
4380 | 318 |
|
5639 | 319 |
{$IFNDEF MOBILE} |
4380 | 320 |
// remove chinese fonts for now |
321 |
if (font >= CJKfnt16) or (length(s) = 0) then |
|
322 |
{$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
|
323 |
exit; |
4380 | 324 |
|
325 |
l:= Utf8ToUnicode(@tmpstr, Str2PChar(s), length(s))-1; |
|
326 |
i:= 0; |
|
4737 | 327 |
|
4380 | 328 |
while i < l do |
329 |
begin |
|
330 |
u:= tmpstr[i]; |
|
4737 | 331 |
if (#$1100 <= u) and ( |
332 |
(u <= #$11FF ) or // Hangul Jamo |
|
333 |
((#$2E80 <= u) and (u <= #$2FDF)) or // CJK Radicals Supplement / Kangxi Radicals |
|
4380 | 334 |
((#$2FF0 <= u) and (u <= #$303F)) or // Ideographic Description Characters / CJK Radicals Supplement |
4737 | 335 |
((#$3130 <= u) and (u <= #$318F)) or // Hangul Compatibility Jamo |
4380 | 336 |
((#$31C0 <= u) and (u <= #$31EF)) or // CJK Strokes |
337 |
((#$3200 <= u) and (u <= #$4DBF)) or // Enclosed CJK Letters and Months / CJK Compatibility / CJK Unified Ideographs Extension A |
|
338 |
((#$4E00 <= u) and (u <= #$9FFF)) or // CJK Unified Ideographs |
|
4737 | 339 |
((#$AC00 <= u) and (u <= #$D7AF)) or // Hangul Syllables |
4380 | 340 |
((#$F900 <= u) and (u <= #$FAFF)) or // CJK Compatibility Ideographs |
341 |
((#$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
|
342 |
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
|
343 |
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
|
344 |
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
|
345 |
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
|
346 |
end; |
4380 | 347 |
inc(i) |
348 |
end; |
|
349 |
(* two more to check. pascal WideChar is only 16 bit though |
|
350 |
((#$20000 <= u) and (u >= #$2A6DF)) or // CJK Unified Ideographs Extension B |
|
351 |
((#$2F800 <= u) and (u >= #$2FA1F))) // CJK Compatibility Ideographs Supplement *) |
|
352 |
end; |
|
353 |
||
4385 | 354 |
|
355 |
function GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt; |
|
356 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
357 |
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
|
358 |
(* |
4385 | 359 |
if (Ammoz[at].ejectX <> 0) or (Ammoz[at].ejectY <> 0) then |
360 |
GetLaunchX:= sign(dir) * (8 + hwRound(AngleSin(angle) * Ammoz[at].ejectX) + hwRound(AngleCos(angle) * Ammoz[at].ejectY)) |
|
361 |
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
|
362 |
GetLaunchX:= 0 *) |
4385 | 363 |
end; |
364 |
||
365 |
function GetLaunchY(at: TAmmoType; angle: LongInt): LongInt; |
|
366 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
367 |
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
|
368 |
(* |
4385 | 369 |
if (Ammoz[at].ejectX <> 0) or (Ammoz[at].ejectY <> 0) then |
370 |
GetLaunchY:= hwRound(AngleSin(angle) * Ammoz[at].ejectY) - hwRound(AngleCos(angle) * Ammoz[at].ejectX) - 2 |
|
371 |
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
|
372 |
GetLaunchY:= 0*) |
4385 | 373 |
end; |
374 |
||
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
|
375 |
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
|
376 |
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
|
377 |
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
|
378 |
end; |
4385 | 379 |
|
7151 | 380 |
{$IFNDEF PAS2C} |
381 |
procedure Write(var f: textfile; s: shortstring); |
|
382 |
begin |
|
383 |
system.write(f, s) |
|
384 |
end; |
|
385 |
||
386 |
procedure WriteLn(var f: textfile; s: shortstring); |
|
387 |
begin |
|
388 |
system.writeln(f, s) |
|
389 |
end; |
|
390 |
{$ENDIF} |
|
391 |
||
7027 | 392 |
procedure initModule(isGame: boolean); |
393 |
{$IFDEF DEBUGFILE} |
|
394 |
var logfileBase: shortstring; |
|
395 |
{$IFNDEF MOBILE}var i: LongInt;{$ENDIF} |
|
396 |
{$ENDIF} |
|
4374 | 397 |
begin |
398 |
{$IFDEF DEBUGFILE} |
|
7027 | 399 |
if isGame then |
400 |
logfileBase:= 'game' |
|
401 |
else |
|
402 |
logfileBase:= 'preview'; |
|
4374 | 403 |
{$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
|
404 |
{$IFDEF MOBILE} |
7027 | 405 |
{$IFDEF IPHONEOS} Assign(f,'../Documents/hw-' + logfileBase + '.log'); {$ENDIF} |
406 |
{$IFDEF ANDROID} Assign(f,pathPrefix + '/' + logfileBase + '.log'); {$ENDIF} |
|
4374 | 407 |
Rewrite(f); |
408 |
{$ELSE} |
|
5831 | 409 |
if (UserPathPrefix <> '') then |
4374 | 410 |
begin |
5130
3602ede67ec5
Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents:
5118
diff
changeset
|
411 |
i:= 0; |
3602ede67ec5
Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents:
5118
diff
changeset
|
412 |
while(i < 7) do |
4374 | 413 |
begin |
7027 | 414 |
assign(f, UserPathPrefix + '/Logs/' + logfileBase + inttostr(i) + '.log'); |
4374 | 415 |
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
|
416 |
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
|
417 |
break; |
5130
3602ede67ec5
Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents:
5118
diff
changeset
|
418 |
inc(i) |
4374 | 419 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
420 |
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
|
421 |
f:= stderr; // if everything fails, write to stderr |
4374 | 422 |
end |
423 |
else |
|
424 |
f:= stderr; |
|
425 |
{$ENDIF} |
|
426 |
{$I+} |
|
427 |
{$ENDIF} |
|
428 |
||
429 |
end; |
|
430 |
||
431 |
procedure freeModule; |
|
432 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6444
diff
changeset
|
433 |
recordFileName:= ''; |
4374 | 434 |
|
435 |
{$IFDEF DEBUGFILE} |
|
7151 | 436 |
writeln(f, 'halt at ' + inttostr(GameTicks) + ' ticks. TurnTimeLeft = ' + inttostr(TurnTimeLeft)); |
4374 | 437 |
flush(f); |
438 |
close(f); |
|
439 |
{$ENDIF} |
|
440 |
end; |
|
441 |
||
4453 | 442 |
end. |