DEADSOFTWARE

Added new OpenGL ES wrapper
[d2df-sdl.git] / src / game / g_player.pas
index 14a2fdcd4d17d4fb9c3478ce9383303c7fe14986..355ecf323985108f69d23d047c3a34399fb77dcc 100644 (file)
@@ -1,4 +1,4 @@
-(* Copyright (C)  DooM 2D:Forever Developers
+(* Copyright (C)  Doom 2D: Forever Developers
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@ interface
 
 uses
   SysUtils, Classes,
-  mempool,
+  {$IFDEF USE_MEMPOOL}mempool,{$ENDIF}
   e_graphics, g_playermodel, g_basic, g_textures,
   g_weapons, g_phys, g_sound, g_saveload, MAPDEF,
   g_panel;
@@ -135,7 +135,7 @@ type
     Time: Word;
   end;
 
-  TPlayer = class(TPoolObject)
+  TPlayer = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
   private
     FIamBot:    Boolean;
     FUID:       Word;
@@ -176,6 +176,7 @@ type
     FSavedState: TPlayerSavedState;
 
     FModel:     TPlayerModel;
+    FPunchAnim: TAnimation;
     FActionPrior:    Byte;
     FActionAnim:     Byte;
     FActionForce:    Boolean;
@@ -213,6 +214,7 @@ type
     procedure SetAction(Action: Byte; Force: Boolean = False);
     procedure OnDamage(Angle: SmallInt); virtual;
     function firediry(): Integer;
+    procedure DoPunch();
 
     procedure Run(Direction: TDirection);
     procedure NextWeapon();
@@ -491,7 +493,7 @@ type
     procedure positionChanged ();  inline; //WARNING! call this after entity position was changed, or coldet will not work right!
   end;
 
-  TCorpse = class(TPoolObject)
+  TCorpse = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
   private
     FModelName:     String;
     FMess:          Boolean;
@@ -586,10 +588,14 @@ procedure g_Bot_RemoveAll();
 implementation
 
 uses
+{$INCLUDE ../nogl/noGLuses.inc}
+{$IFDEF ENABLE_HOLMES}
+  g_holmes,
+{$ENDIF}
   e_log, g_map, g_items, g_console, g_gfx, Math,
   g_options, g_triggers, g_menu, g_game, g_grid,
   wadreader, g_main, g_monsters, CONFIG, g_language,
-  g_net, g_netmsg, g_window, GL, g_holmes,
+  g_net, g_netmsg, g_window,
   utils, xstreams;
 
 const PLR_SAVE_VERSION = 0;
@@ -987,7 +993,7 @@ end;
 
 procedure g_Bot_Add(Team, Difficult: Byte);
 var
-  m: SArray;
+  m: SSArray;
   _name, _model: String;
   a, tr, tb: Integer;
 begin
@@ -1084,7 +1090,7 @@ end;
 
 procedure g_Bot_AddList(Team: Byte; lName: ShortString; num: Integer = -1);
 var
-  m: SArray;
+  m: SSArray;
   _name, _model: String;
   a: Integer;
 begin
@@ -1221,7 +1227,7 @@ var
   s: String;
   a, b: Integer;
   config: TConfig;
-  sa: SArray;
+  sa: SSArray;
 begin
   BotNames := nil;
 
@@ -2246,6 +2252,8 @@ begin
   FJetSoundOn.Free();
   FJetSoundOff.Free();
   FModel.Free();
+  if FPunchAnim <> nil then
+    FPunchAnim.Free();
 
   inherited;
 end;
@@ -2336,9 +2344,19 @@ var
   ID: DWORD;
   w, h: Word;
   dr: Boolean;
+  Mirror: TMirrorType;
 begin
   if FAlive then
   begin
+    if Direction = TDirection.D_RIGHT then
+      Mirror := TMirrorType.None
+    else
+      Mirror := TMirrorType.Horizontal;
+
+    if FPunchAnim <> nil then
+      FPunchAnim.Draw(FObj.X+IfThen(Direction = TDirection.D_LEFT, 15-FObj.Rect.X, FObj.Rect.X-15),
+                      FObj.Y+FObj.Rect.Y-11, Mirror);
+
     if (FMegaRulez[MR_INVUL] > gTime) and (gPlayerDrawn <> Self) then
       if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then
       begin
@@ -2395,10 +2413,13 @@ procedure TPlayer.DrawAim();
   var
     ex, ey: Integer;
   begin
+
+{$IFDEF ENABLE_HOLMES}
     if isValidViewPort and (self = gPlayer1) then
     begin
       g_Holmes_plrLaser(ax0, ay0, ax1, ay1);
     end;
+{$ENDIF}
 
     e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
     if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
@@ -2773,6 +2794,17 @@ begin
   e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
 end;
 
+procedure TPlayer.DoPunch();
+var
+  id: DWORD;
+begin
+  if FPunchAnim = nil then begin
+    g_Frames_Get(id, 'FRAMES_PUNCH');
+    FPunchAnim := TAnimation.Create(id, False, 1);
+  end else
+    FPunchAnim.reset();
+end;
+
 procedure TPlayer.Fire();
 var
   f, DidFire: Boolean;
@@ -2816,15 +2848,19 @@ begin
         locobj.Accel.X := xd-wx;
         locobj.Accel.y := yd-wy;
 
+        DoPunch();
+
         if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
           g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
         else
           g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
 
-        if gFlash = 1 then
-          if FPain < 50 then
-            FPain := min(FPain + 25, 50);
-      end else g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
+        if (gFlash = 1) and (FPain < 50) then FPain := min(FPain + 25, 50);
+      end
+      else
+      begin
+        g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
+      end;
 
       DidFire := True;
       FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
@@ -4308,6 +4344,12 @@ var
   Anim: TAnimation;
   ID: DWORD;
 begin
+  FIncCam := 0;
+  FBFGFireCounter := -1;
+  FShellTimer := -1;
+  FPain := 0;
+  FLastHit := 0;
+
   if not g_Game_IsServer then
     Exit;
   if FDummy then
@@ -4412,12 +4454,6 @@ begin
   else
     FAngle := 0;
 
-  FIncCam := 0;
-  FBFGFireCounter := -1;
-  FShellTimer := -1;
-  FPain := 0;
-  FLastHit := 0;
-
   SetAction(A_STAND, True);
   FModel.Direction := FDirection;
 
@@ -4450,6 +4486,11 @@ begin
   FSpectatePlayer := -1;
   FSpawned := True;
 
+  if (gPlayer1 = nil) and (gLMSPID1 = FUID) then
+    gPlayer1 := self;
+  if (gPlayer2 = nil) and (gLMSPID2 = FUID) then
+    gPlayer2 := self;
+
   if g_Game_IsNet then
   begin
     MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
@@ -4741,6 +4782,9 @@ begin
       FLoss := 0;
     end;
 
+  if FAlive and (FPunchAnim <> nil) then
+    FPunchAnim.Update();
+
   if FAlive and (gFly or FJetpack) then
     FlySmoke();
 
@@ -5266,6 +5310,8 @@ begin
         locobj.Accel.X := xd-wx;
         locobj.Accel.y := yd-wy;
 
+        DoPunch();
+
         if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
           g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
         else