1 (*
2  * Hedgewars, a free turn based strategy game
3  * Copyright (c) 2004-2015 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *)
18 
19 {$INCLUDE "options.inc"}
20 
21 (*
22  * When engine is compiled as library this unit will export functions
23  * as C declarations for convenient library usage in your application
24  * and language of choice.
25  *
26  * See also: C declarations on Wikipedia
27  *           https://en.wikipedia.org/wiki/X86_calling_conventions#cdecl
28  *)
29 
30 Library hwLibrary;
31 
32 uses hwengine, uTypes, uConsts, uVariables, uSound, uCommands, uUtils,
33      uLocale{$IFDEF ANDROID}, jni{$ENDIF};
34 
35 {$INCLUDE "config.inc"}
36 
37 // retrieve protocol information
38 procedure HW_versionInfo(netProto: PLongInt; versionStr: PPChar); cdecl; export;
39 begin
40     netProto^:= cNetProtoVersion;
41     versionStr^:= cVersionString;
42 end;
43 
HW_versionStringnull44 function HW_versionString: PChar; cdecl; export;
45 begin
46     exit(cVersionString + '-r' + cRevisionString + ' (' + cHashString + ')');
47 end;
48 
49 // equivalent to esc+y; when closeFrontend = true the game exits after memory cleanup
50 procedure HW_terminate(closeFrontend: boolean); cdecl; export;
51 begin
52     closeFrontend:= closeFrontend; // avoid hint
53     ParseCommand('forcequit', true);
54 end;
55 
HW_getWeaponNameByIndexnull56 function HW_getWeaponNameByIndex(whichone: LongInt): PChar; cdecl; export;
57 begin
58     HW_getWeaponNameByIndex:= (str2pchar(trammo[Ammoz[TAmmoType(whichone+1)].NameId]));
59 end;
60 
61 (*function HW_getWeaponCaptionByIndex(whichone: LongInt): PChar; cdecl; export;
62 begin
63     HW_getWeaponCaptionByIndex:= (str2pchar(trammoc[Ammoz[TAmmoType(whichone+1)].NameId]));
64 end;
65 
66 function HW_getWeaponDescriptionByIndex(whichone: LongInt): PChar; cdecl; export;
67 begin
68     HW_getWeaponDescriptionByIndex:= (str2pchar(trammod[Ammoz[TAmmoType(whichone+1)].NameId]));
69 end;*)
70 
HW_getNumberOfWeaponsnull71 function HW_getNumberOfWeapons: LongInt; cdecl; export;
72 begin
73     HW_getNumberOfWeapons:= ord(high(TAmmoType));
74 end;
75 
HW_getMaxNumberOfHogsnull76 function HW_getMaxNumberOfHogs: LongInt; cdecl; export;
77 begin
78     HW_getMaxNumberOfHogs:= cMaxHHIndex + 1;
79 end;
80 
HW_getMaxNumberOfTeamsnull81 function HW_getMaxNumberOfTeams: LongInt; cdecl; export;
82 begin
83     HW_getMaxNumberOfTeams:= cMaxTeams;
84 end;
85 
86 procedure HW_memoryWarningCallback; cdecl; export;
87 begin
88     ReleaseSound(false);
89 end;
90 
91 {$IFDEF ANDROID}
JNI_HW_versionInfoNetnull92 function JNI_HW_versionInfoNet(env: PJNIEnv; obj: JObject):JInt;cdecl;
93 begin
94     env:= env; // avoid hint
95     obj:= obj; // avoid hint
96     JNI_HW_versionInfoNet:= cNetProtoVersion;
97 end;
98 
JNI_HW_versionInfoVersionnull99 function JNI_HW_versionInfoVersion(env: PJNIEnv; obj: JObject):JString; cdecl;
100 var envderef : JNIEnv;
101 begin
102     obj:= obj; // avoid hint
103     envderef:= @env;
104     JNI_HW_versionInfoVersion := envderef^.NewStringUTF(env, PChar(cVersionString));
105 end;
106 
107 procedure JNI_HW_GenLandPreview(env: PJNIEnv; c: JClass; port: JInt); cdecl;
108 begin
109     GenLandPreview(port);
110 end;
111 
112 exports
113     JNI_HW_versionInfoNet name Java_Prefix+'HWversionInfoNetProto',
114     JNI_HW_versionInfoVersion name Java_Prefix+'HWversionInfoVersion',
115     JNI_HW_GenLandPreview name Java_Prefix + 'HWGenLandPreview',
116     HW_getNumberOfweapons name Java_Prefix + 'HWgetNumberOfWeapons',
117     HW_getMaxNumberOfHogs name Java_Prefix + 'HWgetMaxNumberOfHogs',
118     HW_getMaxNumberOfTeams name Java_Prefix + 'HWgetMaxNumberOfTeams',
119     Game;
120 {$ELSE}
121 exports
122     RunEngine,
123     LoadLocaleWrapper,
124     HW_versionInfo,
125     HW_versionString,
126     HW_terminate,
127     HW_getNumberOfWeapons,
128     HW_getMaxNumberOfHogs,
129     HW_getMaxNumberOfTeams,
130     HW_getWeaponNameByIndex,
131     HW_memoryWarningCallback;
132 {$ENDIF}
133 
134 begin
135 end.
136