hedgewars/PascalExports.pas
changeset 7048 0a4c88935902
parent 7047 606acf1f80be
child 7049 35d762458d66
equal deleted inserted replaced
7047:606acf1f80be 7048:0a4c88935902
     1 (*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2004-2012 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, uInputHandler, uSound, uAmmos, uUtils, uCommands;
       
    32 
       
    33 {$INCLUDE "config.inc"}
       
    34 procedure HW_versionInfo(netProto: PLongInt; versionStr: PPChar); cdecl; export;
       
    35 
       
    36 function HW_getNumberOfWeapons:LongInt; cdecl; export;
       
    37 
       
    38 function HW_getMaxNumberOfTeams:LongInt; cdecl; export;
       
    39 
       
    40 function HW_getMaxNumberOfHogs:LongInt; cdecl; export;
       
    41 
       
    42 procedure HW_terminate(closeFrontend: Boolean); cdecl; export;
       
    43 
       
    44 implementation
       
    45 {$IFDEF HWLIBRARY}
       
    46 var cZoomVal: GLfloat;
       
    47 
       
    48 // retrieve protocol information
       
    49 procedure HW_versionInfo(netProto: PLongInt; versionStr: PPChar); cdecl; export;
       
    50 begin
       
    51     netProto^:= cNetProtoVersion;
       
    52     versionStr^:= cVersionString;
       
    53 end;
       
    54 
       
    55 procedure HW_zoomSet(value: GLfloat); cdecl; export;
       
    56 begin
       
    57     cZoomVal:= value;
       
    58     ZoomValue:= value;
       
    59 end;
       
    60 
       
    61 procedure HW_zoomReset; cdecl; export;
       
    62 begin
       
    63     ZoomValue:= cZoomVal;
       
    64     // center the camera at current hog
       
    65     if CurrentHedgehog <> nil then
       
    66         followGear:= CurrentHedgehog^.Gear;
       
    67 end;
       
    68 
       
    69 function HW_zoomFactor: GLfloat; cdecl; export;
       
    70 begin
       
    71     HW_zoomFactor:= ZoomValue / cDefaultZoomLevel;
       
    72 end;
       
    73 
       
    74 function HW_zoomLevel: LongInt; cdecl; export;
       
    75 begin
       
    76     HW_zoomLevel:= trunc((ZoomValue - cDefaultZoomLevel) / cZoomDelta);
       
    77 end;
       
    78 
       
    79 procedure HW_screenshot; cdecl; export;
       
    80 begin
       
    81     flagMakeCapture:= true;
       
    82 end;
       
    83 
       
    84 function HW_isPaused: boolean; cdecl; export;
       
    85 begin
       
    86     HW_isPaused:= isPaused;
       
    87 end;
       
    88 
       
    89 // equivalent to esc+y; when closeFrontend = true the game exits after memory cleanup
       
    90 procedure HW_terminate(closeFrontend: boolean); cdecl; export;
       
    91 begin
       
    92     closeFrontend:= closeFrontend; // avoid hint
       
    93     ParseCommand('forcequit', true);
       
    94 end;
       
    95 
       
    96 function HW_getSDLWindow: pointer; cdecl; export;
       
    97 begin
       
    98     HW_getSDLWindow:={$IFDEF SDL13}SDLwindow{$ELSE}nil{$ENDIF};
       
    99 end;
       
   100 
       
   101 // cursor handling
       
   102 procedure HW_setCursor(x,y: LongInt); cdecl; export;
       
   103 begin
       
   104     CursorPoint.X:= x;
       
   105     CursorPoint.Y:= y;
       
   106 end;
       
   107 
       
   108 procedure HW_getCursor(x,y: PLongInt); cdecl; export;
       
   109 begin
       
   110     x^:= CursorPoint.X;
       
   111     y^:= CursorPoint.Y;
       
   112 end;
       
   113 
       
   114 // ammo menu related functions
       
   115 function HW_isAmmoMenuOpen: boolean; cdecl; export;
       
   116 begin
       
   117     HW_isAmmoMenuOpen:= bShowAmmoMenu;
       
   118 end;
       
   119 
       
   120 function HW_isAmmoMenuNotAllowed: boolean; cdecl; export;
       
   121 begin;
       
   122     HW_isAmmoMenuNotAllowed:= ( (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil) or
       
   123                                 ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) );
       
   124 end;
       
   125 
       
   126 function HW_isWeaponRequiringClick: boolean; cdecl; export;
       
   127 begin
       
   128     HW_isWeaponRequiringClick:= false;
       
   129     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.BotLevel = 0) then
       
   130         HW_isWeaponRequiringClick:= (CurrentHedgehog^.Gear^.State and gstHHChooseTarget) <> 0;
       
   131 end;
       
   132 
       
   133 function HW_isWeaponTimerable: boolean; cdecl; export;
       
   134 begin
       
   135     HW_isWeaponTimerable:= false;
       
   136     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Ammo <> nil) and (CurrentHedgehog^.BotLevel = 0) then
       
   137         HW_isWeaponTimerable:= (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_Timerable) <> 0;
       
   138 end;
       
   139 
       
   140 function HW_isWeaponSwitch: boolean cdecl; export;
       
   141 begin
       
   142     HW_isWeaponSwitch:= false;
       
   143     if (CurAmmoGear <> nil) and (CurrentHedgehog^.BotLevel = 0) then
       
   144         HW_isWeaponSwitch:= (CurAmmoGear^.AmmoType = amSwitch);
       
   145 end;
       
   146 
       
   147 function HW_isWeaponRope: boolean cdecl; export;
       
   148 begin
       
   149     HW_isWeaponRope:= false;
       
   150     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Ammo <> nil) and (CurrentHedgehog^.BotLevel = 0) then
       
   151         HW_isWeaponRope:= (CurrentHedgehog^.CurAmmoType = amRope);
       
   152 end;
       
   153 
       
   154 procedure HW_setGrenadeTime(time: LongInt); cdecl; export;
       
   155 begin
       
   156     ParseCommand('/timer ' + inttostr(time), true);
       
   157 end;
       
   158 
       
   159 function HW_getGrenadeTime: LongInt; cdecl; export;
       
   160 var CurWeapon: PAmmo;
       
   161 begin
       
   162     HW_getGrenadeTime:= 3;
       
   163     if HW_isWeaponTimerable then
       
   164     begin
       
   165         CurWeapon:= GetCurAmmoEntry(CurrentHedgehog^);
       
   166         HW_getGrenadeTime:= CurWeapon^.Timer div 1000;
       
   167     end;
       
   168 end;
       
   169 
       
   170 procedure HW_setPianoSound(snd: LongInt); cdecl; export;
       
   171 begin
       
   172     // this most likely won't work in network game
       
   173     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Ammo <> nil) and (CurrentHedgehog^.BotLevel = 0)
       
   174         and (CurrentHedgehog^.CurAmmoType = amPiano) then
       
   175         case snd of
       
   176             0: PlaySound(sndPiano0);
       
   177             1: PlaySound(sndPiano1);
       
   178             2: PlaySound(sndPiano2);
       
   179             3: PlaySound(sndPiano3);
       
   180             4: PlaySound(sndPiano4);
       
   181             5: PlaySound(sndPiano5);
       
   182             6: PlaySound(sndPiano6);
       
   183             7: PlaySound(sndPiano7);
       
   184             else PlaySound(sndPiano8);
       
   185         end;
       
   186 end;
       
   187 
       
   188 function HW_getWeaponNameByIndex(whichone: LongInt): PChar; cdecl; export;
       
   189 begin
       
   190     HW_getWeaponNameByIndex:= (str2pchar(trammo[Ammoz[TAmmoType(whichone+1)].NameId]));
       
   191 end;
       
   192 
       
   193 function HW_getWeaponCaptionByIndex(whichone: LongInt): PChar; cdecl; export;
       
   194 begin
       
   195     HW_getWeaponCaptionByIndex:= (str2pchar(trammoc[Ammoz[TAmmoType(whichone+1)].NameId]));
       
   196 end;
       
   197 
       
   198 function HW_getWeaponDescriptionByIndex(whichone: LongInt): PChar; cdecl; export;
       
   199 begin
       
   200     HW_getWeaponDescriptionByIndex:= (str2pchar(trammod[Ammoz[TAmmoType(whichone+1)].NameId]));
       
   201 end;
       
   202 
       
   203 function HW_getNumberOfWeapons: LongInt; cdecl; export;
       
   204 begin
       
   205     HW_getNumberOfWeapons:= ord(high(TAmmoType));
       
   206 end;
       
   207 
       
   208 procedure HW_setWeapon(whichone: LongInt); cdecl; export;
       
   209 begin
       
   210     if (CurrentTeam = nil) then exit;
       
   211     if (not CurrentTeam^.ExtDriven) and (CurrentTeam^.Hedgehogs[0].BotLevel = 0) then
       
   212         SetWeapon(TAmmoType(whichone+1));
       
   213 end;
       
   214 
       
   215 function HW_isWeaponAnEffect(whichone: LongInt): boolean; cdecl; export;
       
   216 begin
       
   217     HW_isWeaponAnEffect:= Ammoz[TAmmoType(whichone+1)].Ammo.Propz and ammoprop_Effect <> 0;
       
   218 end;
       
   219 
       
   220 function HW_getAmmoCounts(counts: PLongInt): LongInt; cdecl; export;
       
   221 var a : PHHAmmo;
       
   222     slot, index, res: LongInt;
       
   223 begin
       
   224     HW_getAmmoCounts:= -1;
       
   225     // nil check
       
   226     if (CurrentHedgehog = nil) or (CurrentHedgehog^.Ammo = nil) or (CurrentTeam = nil) then
       
   227         exit;
       
   228     // hog controlled by opponent (net or ai)
       
   229     if (CurrentTeam^.ExtDriven) or (CurrentTeam^.Hedgehogs[0].BotLevel <> 0) then
       
   230         exit;
       
   231 
       
   232     a:= CurrentHedgehog^.Ammo;
       
   233     for slot:= 0 to cMaxSlotIndex do
       
   234         for index:= 0 to cMaxSlotAmmoIndex do
       
   235             if a^[slot,index].Count <> 0 then // yes, ammomenu is hell
       
   236                 counts[ord(a^[slot,index].AmmoType)-1]:= a^[slot,index].Count;
       
   237     HW_getAmmoCounts:= 0;
       
   238 end;
       
   239 
       
   240 procedure HW_getAmmoDelays (skipTurns: PByte); cdecl; export;
       
   241 var a : TAmmoType;
       
   242 begin
       
   243     for a:= Low(TAmmoType) to High(TAmmoType) do
       
   244         skipTurns[ord(a)-1]:= byte(Ammoz[a].SkipTurns);
       
   245 end;
       
   246 
       
   247 function HW_getTurnsForCurrentTeam: LongInt; cdecl; export;
       
   248 begin
       
   249     HW_getTurnsForCurrentTeam:= 0;
       
   250     if (CurrentTeam <> nil) and (CurrentTeam^.Clan <> nil) then
       
   251         HW_getTurnsForCurrentTeam:= CurrentTeam^.Clan^.TurnNumber;
       
   252 end;
       
   253 
       
   254 function HW_getMaxNumberOfHogs: LongInt; cdecl; export;
       
   255 begin
       
   256     HW_getMaxNumberOfHogs:= cMaxHHIndex + 1;
       
   257 end;
       
   258 
       
   259 function HW_getMaxNumberOfTeams: LongInt; cdecl; export;
       
   260 begin
       
   261     HW_getMaxNumberOfTeams:= cMaxTeams;
       
   262 end;
       
   263 
       
   264 procedure HW_memoryWarningCallback; cdecl; export;
       
   265 begin
       
   266     ReleaseSound(false);
       
   267 end;
       
   268 
       
   269 {$ENDIF}
       
   270 
       
   271 end.
       
   272