hedgewars/PascalExports.pas
branchexperimental3D
changeset 4004 b1c2c2f6fc5e
parent 3989 adffb668f06e
child 4150 050163c35c83
equal deleted inserted replaced
3698:793386610068 4004:b1c2c2f6fc5e
     1 (*
     1 (*
     2  *  PascalExports.pas
     2  * Hedgewars, a free turn based strategy game
     3  *  hwengine
     3  * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  *  Created by Vittorio on 09/01/10.
     5  * This program is free software; you can redistribute it and/or modify
     6  *  Copyright 2009 __MyCompanyName__. All rights reserved.
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
     7  *
     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
     8  *)
    17  *)
     9 
    18 
    10 
       
    11 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    12 
    20 
    13 unit PascalExports;
    21 unit PascalExports;
    14 
    22 
    15 interface
    23 interface
    16 uses uKeys, GLunit, uWorld, uMisc, uConsole, uTeams, uConsts, uChat, uGears, uSound, hwengine;
    24 uses uKeys, GLunit, uWorld, uMisc, uConsole, uTeams, uConsts, uChat, 
       
    25      uGears, uSound, hwengine, uAmmos, uLocale; // don't change the order!
    17 
    26 
    18 {$INCLUDE "config.inc"}
    27 {$INCLUDE "config.inc"}
       
    28 type PPByte = ^PByte;
    19 
    29 
    20 implementation
    30 implementation
    21 
       
    22 {$IFDEF HWLIBRARY}
    31 {$IFDEF HWLIBRARY}
       
    32 var cZoomVal: GLfloat;
    23 
    33 
    24 // retrieve protocol information
    34 // retrieve protocol information
    25 procedure HW_versionInfo(netProto: PShortInt; versionStr: PPChar); cdecl; export;
    35 procedure HW_versionInfo(netProto: PShortInt; versionStr: PPChar); cdecl; export;
    26 begin
    36 begin
    27 // http://bugs.freepascal.org/view.php?id=16156
    37 // http://bugs.freepascal.org/view.php?id=16156
    32 procedure HW_click; cdecl; export;
    42 procedure HW_click; cdecl; export;
    33 begin
    43 begin
    34     leftClick:= true;
    44     leftClick:= true;
    35 end;
    45 end;
    36 
    46 
       
    47 procedure HW_ammoMenu; cdecl; export;
       
    48 begin
       
    49     rightClick:= true;
       
    50 end;
       
    51 
       
    52 procedure HW_zoomSet(value: GLfloat); cdecl; export;
       
    53 begin
       
    54     cZoomVal:= value;
       
    55     ZoomValue:= value;
       
    56 end;
       
    57 
    37 procedure HW_zoomIn; cdecl; export;
    58 procedure HW_zoomIn; cdecl; export;
    38 begin
    59 begin
    39     if wheelDown = false then
    60     if wheelDown = false then
    40         wheelUp:= true;
    61         wheelUp:= true;
    41 end;
    62 end;
    46         wheelDown:= true;
    67         wheelDown:= true;
    47 end;
    68 end;
    48 
    69 
    49 procedure HW_zoomReset; cdecl; export;
    70 procedure HW_zoomReset; cdecl; export;
    50 begin
    71 begin
    51     middleClick:= true;
    72     ZoomValue:= cZoomVal;
       
    73     //middleClick:= true;
    52     // center the camera at current hog
    74     // center the camera at current hog
    53     if CurrentHedgehog <> nil then
    75     if CurrentHedgehog <> nil then
    54         followGear:= CurrentHedgehog^.Gear;
    76         followGear:= CurrentHedgehog^.Gear;
    55 end;
    77 end;
    56 
    78 
    57 procedure HW_ammoMenu; cdecl; export;
    79 function HW_zoomFactor: GLfloat; cdecl; export;
    58 begin
    80 begin
    59     rightClick:= true;
    81     exit( ZoomValue / cDefaultZoomLevel );
       
    82 end;
       
    83 
       
    84 function HW_zoomLevel: LongInt; cdecl; export;
       
    85 begin
       
    86     exit( trunc((ZoomValue - cDefaultZoomLevel) / cZoomDelta) );
    60 end;
    87 end;
    61 
    88 
    62 procedure HW_walkingKeysUp; cdecl; export;
    89 procedure HW_walkingKeysUp; cdecl; export;
    63 begin
    90 begin
    64     leftKey:= false;
    91     leftKey:= false;
   146 begin
   173 begin
   147     isTerminated:= true;
   174     isTerminated:= true;
   148     if closeFrontend then alsoShutdownFrontend:= true;
   175     if closeFrontend then alsoShutdownFrontend:= true;
   149 end;
   176 end;
   150 
   177 
   151 procedure HW_setLandscape(landscape: boolean); cdecl; export;
       
   152 begin
       
   153     if landscape then
       
   154     begin
       
   155         cOffsetY:= 0;
       
   156     end
       
   157     else
       
   158     begin
       
   159         cOffsetY:= 120;
       
   160     end;
       
   161 end;
       
   162 
       
   163 procedure HW_setCursor(x,y: LongInt); cdecl; export;
   178 procedure HW_setCursor(x,y: LongInt); cdecl; export;
   164 begin
   179 begin
   165     CursorPoint.X:= x;
   180     CursorPoint.X:= x;
   166     CursorPoint.Y:= y;
   181     CursorPoint.Y:= y;
   167 end;
   182 end;
   170 begin
   185 begin
   171     x^:= CursorPoint.X;
   186     x^:= CursorPoint.X;
   172     y^:= CursorPoint.Y;
   187     y^:= CursorPoint.Y;
   173 end;
   188 end;
   174 
   189 
       
   190 function HW_isAmmoMenuOpen: boolean; cdecl; export;
       
   191 begin
       
   192     exit(bShowAmmoMenu);
       
   193 end;
       
   194 
       
   195 function HW_isAmmoMenuNotAllowed: boolean; cdecl; export;
       
   196 begin;
       
   197     exit ( (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil) or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) );
       
   198 end;
       
   199 
       
   200 function HW_isPaused: boolean; cdecl; export;
       
   201 begin
       
   202     exit( isPaused );
       
   203 end;
       
   204 
       
   205 function HW_isWaiting: boolean; cdecl; export;
       
   206 begin
       
   207     exit( ReadyTimeLeft > 0 );
       
   208 end;
       
   209 
       
   210 function HW_isWeaponRequiringClick: boolean; cdecl; export;
       
   211 begin
       
   212     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.BotLevel = 0) then
       
   213         exit( (CurrentHedgehog^.Gear^.State and gstHHChooseTarget) <> 0 )
       
   214     else
       
   215         exit(false);
       
   216 end;
       
   217 
       
   218 function HW_isWeaponTimerable: boolean; cdecl; export;
       
   219 begin
       
   220     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Ammo <> nil) and (CurrentHedgehog^.BotLevel = 0) then
       
   221         exit( (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_Timerable) <> 0)
       
   222     else
       
   223         exit(false);
       
   224 end;
       
   225 
       
   226 function HW_isWeaponSwitch: boolean cdecl; export;
       
   227 begin
       
   228     if (CurAmmoGear <> nil) and (CurrentHedgehog^.BotLevel = 0) then
       
   229         exit(CurAmmoGear^.AmmoType = amSwitch)
       
   230     else
       
   231         exit(false)
       
   232 end;
       
   233 
       
   234 function HW_isWeaponRope: boolean cdecl; export;
       
   235 begin
       
   236     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Ammo <> nil) and (CurrentHedgehog^.BotLevel = 0) then
       
   237         exit (CurrentHedgehog^.CurAmmoType = amRope)
       
   238     else
       
   239         exit(false);
       
   240 end;
       
   241 
       
   242 procedure HW_setGrenadeTime(time: LongInt); cdecl; export;
       
   243 begin
       
   244     ParseCommand('/timer ' + inttostr(time), true);
       
   245 end;
       
   246 
   175 procedure HW_setPianoSound(snd: LongInt); cdecl; export;
   247 procedure HW_setPianoSound(snd: LongInt); cdecl; export;
   176 var CurSlot, CurAmmo: LongWord;
   248 begin
   177 begin
       
   178     CurSlot:= CurrentHedgehog^.CurSlot;
       
   179     CurAmmo:= CurrentHedgehog^.CurAmmo;
       
   180     // this most likely won't work in network game
   249     // this most likely won't work in network game
   181     if (CurrentHedgehog^.Ammo^[CurSlot, CurAmmo].AmmoType = amPiano) then
   250     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Ammo <> nil) and (CurrentHedgehog^.BotLevel = 0)
   182         case snd of 
   251        and (CurrentHedgehog^.CurAmmoType = amPiano) then
       
   252         case snd of
   183             0: PlaySound(sndPiano0);
   253             0: PlaySound(sndPiano0);
   184             1: PlaySound(sndPiano1);
   254             1: PlaySound(sndPiano1);
   185             2: PlaySound(sndPiano2);
   255             2: PlaySound(sndPiano2);
   186             3: PlaySound(sndPiano3);
   256             3: PlaySound(sndPiano3);
   187             4: PlaySound(sndPiano4);
   257             4: PlaySound(sndPiano4);
   190             7: PlaySound(sndPiano7);
   260             7: PlaySound(sndPiano7);
   191             else PlaySound(sndPiano8);
   261             else PlaySound(sndPiano8);
   192         end;
   262         end;
   193 end;
   263 end;
   194 
   264 
   195 function HW_isAmmoOpen: boolean; cdecl; export;
   265 function HW_getWeaponNameByIndex(whichone: LongInt): PChar; cdecl; export;
   196 begin
   266 begin
   197     exit(bShowAmmoMenu);
   267     exit (str2pchar(trammo[Ammoz[TAmmoType(whichone+1)].NameId]));
   198 end;
   268 end;
   199 
   269 
   200 function HW_isWeaponRequiringClick: boolean; cdecl; export;
   270 function HW_getWeaponCaptionByIndex(whichone: LongInt): PChar; cdecl; export;
   201 begin
   271 begin
   202     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then
   272     exit (str2pchar(trammoc[Ammoz[TAmmoType(whichone+1)].NameId]));
   203         exit( (CurrentHedgehog^.Gear^.State and gstHHChooseTarget) <> 0 )
   273 end;
   204     else
   274 
   205         exit(false);
   275 function HW_getWeaponDescriptionByIndex(whichone: LongInt): PChar; cdecl; export;
   206 end;
   276 begin
   207 
   277     exit (str2pchar(trammod[Ammoz[TAmmoType(whichone+1)].NameId]));
   208 function HW_isWeaponTimerable: boolean; cdecl; export;
   278 end;
   209 var CurSlot, CurAmmo: LongWord;
   279 
   210 begin
   280 function HW_getNumberOfWeapons:LongInt; cdecl; export;
   211     CurSlot:= CurrentHedgehog^.CurSlot;
   281 begin
   212     CurAmmo:= CurrentHedgehog^.CurAmmo;
   282     exit(ord(high(TAmmoType)));
   213     exit( (CurrentHedgehog^.Ammo^[CurSlot, CurAmmo].Propz and ammoprop_Timerable) <> 0)
   283 end;
   214 end;
   284 
   215 
   285 procedure HW_setWeapon(whichone: LongInt); cdecl; export;
   216 function HW_isWeaponSwitch: boolean cdecl; export;
   286 begin
   217 begin
   287     if (not CurrentTeam^.ExtDriven) and (CurrentTeam^.Hedgehogs[0].BotLevel = 0) then
   218     if CurAmmoGear <> nil then
   288         SetWeapon(TAmmoType(whichone+1));
   219         exit(CurAmmoGear^.AmmoType = amSwitch) 
   289 end;
   220     else
   290 
   221         exit(false)
   291 function HW_isWeaponAnEffect(whichone: LongInt): boolean; cdecl; export;
   222 end;
   292 begin
   223 
   293     exit(Ammoz[TAmmoType(whichone+1)].Ammo.Propz and ammoprop_Effect <> 0)
   224 function HW_isPaused: boolean; cdecl; export;
   294 end;
   225 begin
   295 
   226     exit( isPaused );
   296 function HW_getAmmoCounts(counts: PLongInt): LongInt; cdecl; export;
   227 end;
   297 var a : PHHAmmo;
   228 
   298     slot, index: LongInt;
   229 procedure HW_setGrenadeTime(time: LongInt); cdecl; export;
   299 begin
   230 begin
   300     if (CurrentTeam = nil) or
   231     ParseCommand('/timer ' + inttostr(time), true);
   301        (CurrentHedgehog = nil) or
   232 end;
   302        (CurrentTeam^.ExtDriven) or
   233 
   303        (CurrentTeam^.Hedgehogs[0].BotLevel <> 0) then
   234 //amSwitch
   304         exit(-1);
       
   305 
       
   306     a:= CurrentHedgehog^.Ammo;
       
   307     for slot:= 0 to cMaxSlotIndex do
       
   308         for index:= 0 to cMaxSlotAmmoIndex do
       
   309             if a^[slot,index].Count <> 0 then // yes, ammomenu is hell
       
   310                 counts[ord(a^[slot,index].AmmoType)-1]:= a^[slot,index].Count;
       
   311     exit(0);
       
   312 end;
       
   313 
       
   314 procedure HW_getAmmoDelays (skipTurns: PByte); cdecl; export;
       
   315 var a : TAmmoType;
       
   316 begin
       
   317     for a:= Low(TAmmoType) to High(TAmmoType) do
       
   318         skipTurns[ord(a)-1]:= byte(Ammoz[a].SkipTurns);
       
   319 end;
       
   320 
       
   321 function HW_getTurnsForCurrentTeam: LongInt; cdecl; export;
       
   322 begin
       
   323     exit(CurrentTeam^.Clan^.TurnNumber);
       
   324 end;
       
   325 
       
   326 function HW_getMaxNumberOfHogs: LongInt; cdecl; export;
       
   327 begin
       
   328     exit(cMaxHHIndex+1);
       
   329 end;
       
   330 
       
   331 function HW_getMaxNumberOfTeams: LongInt; cdecl; export;
       
   332 begin
       
   333     exit(cMaxTeams);
       
   334 end;
   235 {$ENDIF}
   335 {$ENDIF}
   236 
   336 
   237 end.
   337 end.
   238 
   338