hedgewars/PascalExports.pas
branchhedgeroid
changeset 7855 ddcdedd3330b
parent 6350 41b0a9955c47
parent 7854 0b447175594f
child 7857 2bc61f8841a1
equal deleted inserted replaced
6350:41b0a9955c47 7855:ddcdedd3330b
     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 
       
    19 {$INCLUDE "options.inc"}
       
    20 
       
    21 unit PascalExports;
       
    22 (*
       
    23  * If the engine is compiled as library this unit will export functions
       
    24  * as C declarations for convenient library usage in your application and
       
    25  * language of choice.
       
    26  *
       
    27  * See also: C declarations on wikipedia
       
    28  *           http://en.wikipedia.org/wiki/X86_calling_conventions#cdecl
       
    29  *)
       
    30 interface
       
    31 uses uTypes, uConsts, uVariables, GLunit, uKeys, uSound, uAmmos, uUtils, uCommands;
       
    32 
       
    33 {$INCLUDE "config.inc"}
       
    34 procedure HW_versionInfo(netProto: PLongInt; versionStr: PPChar); cdecl; export;
       
    35 function HW_getNumberOfWeapons:LongInt; cdecl; export;
       
    36 function HW_getMaxNumberOfTeams:LongInt; cdecl; export;
       
    37 function HW_getMaxNumberOfHogs:LongInt; cdecl; export;
       
    38 procedure HW_terminate(closeFrontend: Boolean); cdecl; export;
       
    39 
       
    40 implementation
       
    41 {$IFDEF HWLIBRARY}
       
    42 var cZoomVal: GLfloat;
       
    43 
       
    44 // retrieve protocol information
       
    45 procedure HW_versionInfo(netProto: PLongInt; versionStr: PPChar); cdecl; export;
       
    46 begin
       
    47     netProto^:= cNetProtoVersion;
       
    48     versionStr^:= cVersionString;
       
    49 end;
       
    50 
       
    51 // emulate mouse/keyboard input
       
    52 procedure HW_click; cdecl; export;
       
    53 begin
       
    54     leftClick:= true;
       
    55 end;
       
    56 
       
    57 procedure HW_ammoMenu; cdecl; export;
       
    58 begin
       
    59     rightClick:= true;
       
    60 end;
       
    61 
       
    62 procedure HW_zoomSet(value: GLfloat); cdecl; export;
       
    63 begin
       
    64     cZoomVal:= value;
       
    65     ZoomValue:= value;
       
    66 end;
       
    67 
       
    68 procedure HW_zoomIn; cdecl; export;
       
    69 begin
       
    70     if wheelDown = false then
       
    71         wheelUp:= true;
       
    72 end;
       
    73 
       
    74 procedure HW_zoomOut; cdecl; export;
       
    75 begin
       
    76     if wheelUp = false then
       
    77         wheelDown:= true;
       
    78 end;
       
    79 
       
    80 procedure HW_zoomReset; cdecl; export;
       
    81 begin
       
    82     ZoomValue:= cZoomVal;
       
    83     // center the camera at current hog
       
    84     if CurrentHedgehog <> nil then
       
    85         followGear:= CurrentHedgehog^.Gear;
       
    86 end;
       
    87 
       
    88 function HW_zoomFactor: GLfloat; cdecl; export;
       
    89 begin
       
    90     exit( ZoomValue / cDefaultZoomLevel );
       
    91 end;
       
    92 
       
    93 function HW_zoomLevel: LongInt; cdecl; export;
       
    94 begin
       
    95     exit( trunc((ZoomValue - cDefaultZoomLevel) / cZoomDelta) );
       
    96 end;
       
    97 
       
    98 procedure HW_walkingKeysUp; cdecl; export;
       
    99 begin
       
   100     leftKey:= false;
       
   101     rightKey:= false;
       
   102     upKey:= false;
       
   103     downKey:= false;
       
   104     preciseKey:= false;
       
   105 end;
       
   106 
       
   107 procedure HW_otherKeysUp; cdecl; export;
       
   108 begin
       
   109     spaceKey:= false;
       
   110     enterKey:= false;
       
   111     backspaceKey:= false;
       
   112 end;
       
   113 
       
   114 procedure HW_allKeysUp; cdecl; export;
       
   115 begin
       
   116     // set all keys to released
       
   117     uKeys.initModule;
       
   118 end;
       
   119 
       
   120 procedure HW_walkLeft; cdecl; export;
       
   121 begin
       
   122     leftKey:= true;
       
   123 end;
       
   124 
       
   125 procedure HW_walkRight; cdecl; export;
       
   126 begin
       
   127     rightKey:= true;
       
   128 end;
       
   129 
       
   130 procedure HW_preciseSet(status:boolean); cdecl; export;
       
   131 begin
       
   132     preciseKey:= status;
       
   133 end;
       
   134 
       
   135 procedure HW_aimUp; cdecl; export;
       
   136 begin
       
   137     upKey:= true;
       
   138 end;
       
   139 
       
   140 procedure HW_aimDown; cdecl; export;
       
   141 begin
       
   142     downKey:= true;
       
   143 end;
       
   144 
       
   145 procedure HW_shoot; cdecl; export;
       
   146 begin
       
   147     spaceKey:= true;
       
   148 end;
       
   149 
       
   150 procedure HW_jump; cdecl; export;
       
   151 begin
       
   152     enterKey:= true;
       
   153 end;
       
   154 
       
   155 procedure HW_backjump; cdecl; export;
       
   156 begin
       
   157     backspaceKey:= true;
       
   158 end;
       
   159 
       
   160 procedure HW_tab; cdecl; export;
       
   161 begin
       
   162     tabKey:= true;
       
   163 end;
       
   164 
       
   165 procedure HW_chat; cdecl; export;
       
   166 begin
       
   167     chatAction:= true;
       
   168 end;
       
   169 
       
   170 procedure HW_screenshot; cdecl; export;
       
   171 begin
       
   172     flagMakeCapture:= true;
       
   173 end;
       
   174 
       
   175 procedure HW_pause; cdecl; export;
       
   176 begin
       
   177     if isPaused = false then
       
   178         pauseAction:= true;
       
   179 end;
       
   180 
       
   181 procedure HW_pauseToggle; cdecl; export;
       
   182 begin
       
   183     pauseAction:= true;
       
   184 end;
       
   185 
       
   186 function HW_isPaused: boolean; cdecl; export;
       
   187 begin
       
   188     exit( isPaused );
       
   189 end;
       
   190 
       
   191 // equivalent to esc+y; when closeFrontend = true the game exits after memory cleanup
       
   192 procedure HW_terminate(closeFrontend: boolean); cdecl; export;
       
   193 begin
       
   194     alsoShutdownFrontend:= closeFrontend;
       
   195     ParseCommand('forcequit', true);
       
   196 end;
       
   197 
       
   198 function HW_getSDLWindow: pointer; cdecl; export;
       
   199 begin
       
   200 {$IFDEF SDL13}
       
   201     exit( SDLwindow );
       
   202 {$ELSE}
       
   203     exit( nil );
       
   204 {$ENDIF}
       
   205 end;
       
   206 
       
   207 // cursor handling
       
   208 procedure HW_setCursor(x,y: LongInt); cdecl; export;
       
   209 begin
       
   210     CursorPoint.X:= x;
       
   211     CursorPoint.Y:= y;
       
   212 end;
       
   213 
       
   214 procedure HW_getCursor(x,y: PLongInt); cdecl; export;
       
   215 begin
       
   216     x^:= CursorPoint.X;
       
   217     y^:= CursorPoint.Y;
       
   218 end;
       
   219 
       
   220 // ammo menu related functions
       
   221 function HW_isAmmoMenuOpen: boolean; cdecl; export;
       
   222 begin
       
   223     exit( bShowAmmoMenu );
       
   224 end;
       
   225 
       
   226 function HW_isAmmoMenuNotAllowed: boolean; cdecl; export;
       
   227 begin;
       
   228     exit( (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil) or
       
   229           ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) );
       
   230 end;
       
   231 
       
   232 function HW_isWeaponRequiringClick: boolean; cdecl; export;
       
   233 begin
       
   234     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.BotLevel = 0) then
       
   235         exit( (CurrentHedgehog^.Gear^.State and gstHHChooseTarget) <> 0 )
       
   236     else
       
   237         exit(false);
       
   238 end;
       
   239 
       
   240 function HW_isWeaponTimerable: boolean; cdecl; export;
       
   241 begin
       
   242     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Ammo <> nil) and (CurrentHedgehog^.BotLevel = 0) then
       
   243         exit( (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_Timerable) <> 0)
       
   244     else
       
   245         exit(false);
       
   246 end;
       
   247 
       
   248 function HW_isWeaponSwitch: boolean cdecl; export;
       
   249 begin
       
   250     if (CurAmmoGear <> nil) and (CurrentHedgehog^.BotLevel = 0) then
       
   251         exit(CurAmmoGear^.AmmoType = amSwitch)
       
   252     else
       
   253         exit(false)
       
   254 end;
       
   255 
       
   256 function HW_isWeaponRope: boolean cdecl; export;
       
   257 begin
       
   258     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Ammo <> nil) and (CurrentHedgehog^.BotLevel = 0) then
       
   259         exit(CurrentHedgehog^.CurAmmoType = amRope)
       
   260     else
       
   261         exit(false);
       
   262 end;
       
   263 
       
   264 procedure HW_setGrenadeTime(time: LongInt); cdecl; export;
       
   265 begin
       
   266     ParseCommand('/timer ' + inttostr(time), true);
       
   267 end;
       
   268 
       
   269 procedure HW_setPianoSound(snd: LongInt); cdecl; export;
       
   270 begin
       
   271     // this most likely won't work in network game
       
   272     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Ammo <> nil) and (CurrentHedgehog^.BotLevel = 0)
       
   273        and (CurrentHedgehog^.CurAmmoType = amPiano) then
       
   274         case snd of
       
   275             0: PlaySound(sndPiano0);
       
   276             1: PlaySound(sndPiano1);
       
   277             2: PlaySound(sndPiano2);
       
   278             3: PlaySound(sndPiano3);
       
   279             4: PlaySound(sndPiano4);
       
   280             5: PlaySound(sndPiano5);
       
   281             6: PlaySound(sndPiano6);
       
   282             7: PlaySound(sndPiano7);
       
   283             else PlaySound(sndPiano8);
       
   284         end;
       
   285 end;
       
   286 
       
   287 function HW_getWeaponNameByIndex(whichone: LongInt): PChar; cdecl; export;
       
   288 begin
       
   289     exit(str2pchar(trammo[Ammoz[TAmmoType(whichone+1)].NameId]));
       
   290 end;
       
   291 
       
   292 function HW_getWeaponCaptionByIndex(whichone: LongInt): PChar; cdecl; export;
       
   293 begin
       
   294     exit(str2pchar(trammoc[Ammoz[TAmmoType(whichone+1)].NameId]));
       
   295 end;
       
   296 
       
   297 function HW_getWeaponDescriptionByIndex(whichone: LongInt): PChar; cdecl; export;
       
   298 begin
       
   299     exit(str2pchar(trammod[Ammoz[TAmmoType(whichone+1)].NameId]));
       
   300 end;
       
   301 
       
   302 function HW_getNumberOfWeapons:LongInt; cdecl; export;
       
   303 begin
       
   304     exit(ord(high(TAmmoType)));
       
   305 end;
       
   306 
       
   307 procedure HW_setWeapon(whichone: LongInt); cdecl; export;
       
   308 begin
       
   309     if (CurrentTeam = nil) then exit;
       
   310     if (not CurrentTeam^.ExtDriven) and (CurrentTeam^.Hedgehogs[0].BotLevel = 0) then
       
   311         SetWeapon(TAmmoType(whichone+1));
       
   312 end;
       
   313 
       
   314 function HW_isWeaponAnEffect(whichone: LongInt): boolean; cdecl; export;
       
   315 begin
       
   316     exit(Ammoz[TAmmoType(whichone+1)].Ammo.Propz and ammoprop_Effect <> 0)
       
   317 end;
       
   318 
       
   319 function HW_getAmmoCounts(counts: PLongInt): LongInt; cdecl; export;
       
   320 var a : PHHAmmo;
       
   321     slot, index: LongInt;
       
   322 begin
       
   323     // nil check
       
   324     if (CurrentHedgehog = nil) or (CurrentHedgehog^.Ammo = nil) or (CurrentTeam = nil) then
       
   325         exit(-1);
       
   326     // hog controlled by opponent (net or ai)
       
   327     if (CurrentTeam^.ExtDriven) or (CurrentTeam^.Hedgehogs[0].BotLevel <> 0) then
       
   328         exit(1);
       
   329 
       
   330     a:= CurrentHedgehog^.Ammo;
       
   331     for slot:= 0 to cMaxSlotIndex do
       
   332         for index:= 0 to cMaxSlotAmmoIndex do
       
   333             if a^[slot,index].Count <> 0 then // yes, ammomenu is hell
       
   334                 counts[ord(a^[slot,index].AmmoType)-1]:= a^[slot,index].Count;
       
   335     exit(0);
       
   336 end;
       
   337 
       
   338 procedure HW_getAmmoDelays (skipTurns: PByte); cdecl; export;
       
   339 var a : TAmmoType;
       
   340 begin
       
   341     for a:= Low(TAmmoType) to High(TAmmoType) do
       
   342         skipTurns[ord(a)-1]:= byte(Ammoz[a].SkipTurns);
       
   343 end;
       
   344 
       
   345 function HW_getTurnsForCurrentTeam: LongInt; cdecl; export;
       
   346 begin
       
   347     if (CurrentTeam <> nil) and (CurrentTeam^.Clan <> nil) then
       
   348         exit(CurrentTeam^.Clan^.TurnNumber)
       
   349     else
       
   350         exit(0);
       
   351 end;
       
   352 
       
   353 function HW_getMaxNumberOfHogs: LongInt; cdecl; export;
       
   354 begin
       
   355     exit(cMaxHHIndex+1);
       
   356 end;
       
   357 
       
   358 function HW_getMaxNumberOfTeams: LongInt; cdecl; export;
       
   359 begin
       
   360     exit(cMaxTeams);
       
   361 end;
       
   362 {$ENDIF}
       
   363 
       
   364 end.
       
   365