DEADSOFTWARE

game: disable shells for server
[d2df-sdl.git] / src / game / g_player.pas
index 68bee9a40a786e8f1f3470eb74f072bcd6d38427..aab6b385b7658f3650a1880468bea002a799d92e 100644 (file)
@@ -74,10 +74,6 @@ const
   TEAM_BLUE         = 2;
   TEAM_COOP         = 3;
 
-  SHELL_BULLET      = 0;
-  SHELL_SHELL       = 1;
-  SHELL_DBLSHELL    = 2;
-
   ANGLE_NONE        = Low(SmallInt);
 
   CORPSE_STATE_REMOVEME = 0;
@@ -201,8 +197,10 @@ type
     FIncCamOld:      Integer;
     FIncCam:         Integer;
     FSlopeOld:       Integer;
-    FShellTimer:     Integer;
-    FShellType:      Byte;
+    {$IFDEF ENABLE_SHELLS}
+      FShellTimer:     Integer;
+      FShellType:      Byte;
+    {$ENDIF}
     FSawSound:       TPlayableSound;
     FSawSoundIdle:   TPlayableSound;
     FSawSoundHit:    TPlayableSound;
@@ -501,20 +499,6 @@ type
     procedure   LoadState (st: TStream); override;
   end;
 
-  PShell = ^TShell;
-  TShell = record
-    alive:    Boolean;
-    SType:    Byte;
-    RAngle:   Integer;
-    Timeout:  Cardinal;
-    Obj:      TObj;
-
-    procedure getMapBox (out x, y, w, h: Integer); inline;
-    procedure moveBy (dx, dy: Integer); inline;
-
-    procedure positionChanged ();  inline; //WARNING! call this after entity position was changed, or coldet will not work right!
-  end;
-
   TCorpse = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
   private
     FMess:          Boolean;
@@ -553,7 +537,6 @@ type
 var
   gPlayers: Array of TPlayer;
   gCorpses: Array of TCorpse;
-  gShells: Array of TShell;
   gTeamStat: TTeamStat;
   gFly: Boolean = False;
   gAimLine: Boolean = False;
@@ -565,14 +548,11 @@ var
   gSpectLatchPID2: Word = 0;
   MAX_RUNVEL: Integer = 8;
   VEL_JUMP: Integer = 10;
-  SHELL_TIMEOUT: Cardinal = 60000;
 
 function  Lerp(X, Y, Factor: Integer): Integer;
 
 procedure g_Corpses_SetMax(Count: Word);
 function  g_Corpses_GetMax(): Word;
-procedure g_Shells_SetMax(Count: Word);
-function  g_Shells_GetMax(): Word;
 
 procedure g_Player_Init();
 procedure g_Player_Free();
@@ -589,7 +569,6 @@ function  g_Player_GetCount(): Byte;
 function  g_Player_GetStats(): TPlayerStatArray;
 function  g_Player_ValidName(Name: String): Boolean;
 function  g_Player_CreateCorpse(Player: TPlayer): Integer;
-procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
 procedure g_Player_UpdatePhysicalObjects();
 procedure g_Player_RemoveAllCorpses();
 procedure g_Player_Corpses_SaveState (st: TStream);
@@ -618,6 +597,9 @@ uses
   {$IFDEF ENABLE_GIBS}
     g_gibs,
   {$ENDIF}
+  {$IFDEF ENABLE_SHELLS}
+    g_shells,
+  {$ENDIF}
   e_log, g_map, g_items, g_console, Math,
   g_options, g_triggers, g_game, g_grid, e_res,
   wadreader, g_monsters, CONFIG, g_language,
@@ -692,8 +674,6 @@ const
 
 var
   MaxCorpses: Word = 20;
-  MaxShells: Word = 300;
-  CurrentShell: Integer = 0;
   BotNames: Array of String;
   BotList: Array of TBotProfile;
   SavedStates: Array of TPlayerSavedState;
@@ -719,21 +699,6 @@ begin
   Result := g_Player_Get(UID1).FTeam = g_Player_Get(UID2).FTeam;
 end;
 
-procedure g_Shells_SetMax(Count: Word);
-begin
-  MaxShells := Count;
-  SetLength(gShells, Count);
-
-  if CurrentShell >= Count then
-    CurrentShell := 0;
-end;
-
-function g_Shells_GetMax(): Word;
-begin
-  Result := MaxShells;
-end;
-
-
 procedure g_Corpses_SetMax(Count: Word);
 begin
   MaxCorpses := Count;
@@ -1552,61 +1517,9 @@ begin
   end;
 end;
 
-procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
-begin
-  if (gShells = nil) or (Length(gShells) = 0) then
-    Exit;
-
-  with gShells[CurrentShell] do
-  begin
-    g_Obj_Init(@Obj);
-    Obj.Rect.X := 0;
-    Obj.Rect.Y := 0;
-    if T = SHELL_BULLET then
-    begin
-      Obj.Rect.Width := 4;
-      Obj.Rect.Height := 2;
-    end
-    else
-    begin
-      Obj.Rect.Width := 7;
-      Obj.Rect.Height := 3;
-    end;
-    SType := T;
-    alive := True;
-    Obj.X := fX;
-    Obj.Y := fY;
-    g_Obj_Push(@Obj, dX + Random(4)-Random(4), dY-Random(4));
-    positionChanged(); // this updates spatial accelerators
-    RAngle := Random(360);
-    Timeout := gTime + SHELL_TIMEOUT;
-
-    if CurrentShell >= High(gShells) then
-      CurrentShell := 0
-    else
-      Inc(CurrentShell);
-  end;
-end;
-
 procedure g_Player_UpdatePhysicalObjects();
-var
-  i: Integer;
-  vel: TPoint2i;
-  mr: Word;
-
-  procedure ShellSound_Bounce(X, Y: Integer; T: Byte);
-  var
-    k: Integer;
-  begin
-    k := 1 + Random(2);
-    if T = SHELL_BULLET then
-      g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k), X, Y)
-    else
-      g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k), X, Y);
-  end;
-
+  var i: Integer;
 begin
-// Трупы:
   if gCorpses <> nil then
     for i := 0 to High(gCorpses) do
       if gCorpses[i] <> nil then
@@ -1617,94 +1530,21 @@ begin
           end
         else
           gCorpses[i].Update();
-
-// Гильзы:
-  if gShells <> nil then
-    for i := 0 to High(gShells) do
-      if gShells[i].alive then
-        with gShells[i] do
-        begin
-          Obj.oldX := Obj.X;
-          Obj.oldY := Obj.Y;
-
-          vel := Obj.Vel;
-          mr := g_Obj_Move(@Obj, True, False, True);
-          positionChanged(); // this updates spatial accelerators
-
-          if WordBool(mr and MOVE_FALLOUT) or (gShells[i].Timeout < gTime) then
-          begin
-            alive := False;
-            Continue;
-          end;
-
-        // Отлетает от удара о стену/потолок/пол:
-          if WordBool(mr and MOVE_HITWALL) then
-          begin
-            Obj.Vel.X := -(vel.X div 2);
-            if not WordBool(mr and MOVE_INWATER) then
-              ShellSound_Bounce(Obj.X, Obj.Y, SType);
-          end;
-          if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
-          begin
-            Obj.Vel.Y := -(vel.Y div 2);
-            if Obj.Vel.X <> 0 then Obj.Vel.X := Obj.Vel.X div 2;
-            if (Obj.Vel.X = 0) and (Obj.Vel.Y = 0) then
-            begin
-              if RAngle mod 90 <> 0 then
-                RAngle := (RAngle div 90) * 90;
-            end
-            else if not WordBool(mr and MOVE_INWATER) then
-              ShellSound_Bounce(Obj.X, Obj.Y, SType);
-          end;
-
-          if (Obj.Vel.X >= 0) then
-          begin // Clockwise
-            RAngle := RAngle + Abs(Obj.Vel.X)*8 + Abs(Obj.Vel.Y);
-            if RAngle >= 360 then
-              RAngle := RAngle mod 360;
-          end else begin // Counter-clockwise
-            RAngle := RAngle - Abs(Obj.Vel.X)*8 - Abs(Obj.Vel.Y);
-            if RAngle < 0 then
-              RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
-          end;
-        end;
-end;
-
-procedure TShell.getMapBox (out x, y, w, h: Integer); inline;
-begin
-  x := Obj.X;
-  y := Obj.Y;
-  w := Obj.Rect.Width;
-  h := Obj.Rect.Height;
 end;
 
-procedure TShell.moveBy (dx, dy: Integer); inline;
-begin
-  if (dx <> 0) or (dy <> 0) then
-  begin
-    Obj.X += dx;
-    Obj.Y += dy;
-    positionChanged();
-  end;
-end;
-
-procedure TShell.positionChanged (); inline; begin end;
-
-
 procedure g_Player_RemoveAllCorpses();
   var i: Integer;
-  {$IFDEF ENABLE_GIBS}
-    var maxgibs: Integer;
-  {$ENDIF}
 begin
   {$IFDEF ENABLE_GIBS}
-    maxgibs := g_Gibs_GetMax();
+    i := g_Gibs_GetMax();
     g_Gibs_SetMax(0);
-    g_Gibs_SetMax(maxgibs);
+    g_Gibs_SetMax(i);
+  {$ENDIF}
+  {$IFDEF ENABLE_SHELLS}
+    i := g_Shells_GetMax();
+    g_Shells_SetMax(0);
+    g_Shells_SetMax(i);
   {$ENDIF}
-  gShells := nil;
-  SetLength(gShells, MaxShells);
-  CurrentShell := 0;
 
   if gCorpses <> nil then
     for i := 0 to High(gCorpses) do
@@ -1963,7 +1803,9 @@ begin
   FPing := 0;
   FLoss := 0;
   FSavedStateNum := -1;
-  FShellTimer := -1;
+  {$IFDEF ENABLE_SHELLS}
+    FShellTimer := -1;
+  {$ENDIF}
   FFireTime := 0;
   FFirePainTime := 0;
   FFireAttacker := 0;
@@ -2232,8 +2074,9 @@ begin
         FFireAngle := FAngle;
         f := True;
         DidFire := True;
-        g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
-                             GameVelX, GameVelY-2, SHELL_BULLET);
+        {$IFDEF ENABLE_SHELLS}
+          g_Shells_Create(GameX + PLAYER_RECT_CX, GameY + PLAYER_RECT_CX, GameVelX, GameVelY - 2, SHELL_BULLET);
+        {$ENDIF}
       end;
 
     WEAPON_SHOTGUN1:
@@ -2246,8 +2089,10 @@ begin
         FFireAngle := FAngle;
         f := True;
         DidFire := True;
-        FShellTimer := 10;
-        FShellType := SHELL_SHELL;
+        {$IFDEF ENABLE_SHELLS}
+          FShellTimer := 10;
+          FShellType := SHELL_SHELL;
+        {$ENDIF}
       end;
 
     WEAPON_SHOTGUN2:
@@ -2259,8 +2104,10 @@ begin
         FFireAngle := FAngle;
         f := True;
         DidFire := True;
-        FShellTimer := 13;
-        FShellType := SHELL_DBLSHELL;
+        {$IFDEF ENABLE_SHELLS}
+          FShellTimer := 13;
+          FShellType := SHELL_DBLSHELL;
+        {$ENDIF}
       end;
 
     WEAPON_CHAINGUN:
@@ -2273,8 +2120,9 @@ begin
         FFireAngle := FAngle;
         f := True;
         DidFire := True;
-        g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
-                             GameVelX, GameVelY-2, SHELL_BULLET);
+        {$IFDEF ENABLE_SHELLS}
+          g_Shells_Create(GameX + PLAYER_RECT_CX, GameY + PLAYER_RECT_CX, GameVelX, GameVelY - 2, SHELL_BULLET);
+        {$ENDIF}
       end;
 
     WEAPON_ROCKETLAUNCHER:
@@ -2319,8 +2167,9 @@ begin
         FFireAngle := FAngle;
         f := True;
         DidFire := True;
-        g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
-                             GameVelX, GameVelY-2, SHELL_SHELL);
+        {$IFDEF ENABLE_SHELLS}
+          g_Shells_Create(GameX + PLAYER_RECT_CX, GameY + PLAYER_RECT_CX, GameVelX, GameVelY - 2, SHELL_SHELL);
+        {$ENDIF}
       end;
 
     WEAPON_FLAMETHROWER:
@@ -2549,7 +2398,10 @@ begin
       FPhysics := True;
     FAlive := False;
   end;
-  FShellTimer := -1;
+
+  {$IFDEF ENABLE_SHELLS}
+    FShellTimer := -1;
+  {$ENDIF}
 
   if (gGameSettings.MaxLives > 0) and Srv and (gLMSRespawn = LMS_RESPAWN_NONE) then
   begin
@@ -3579,7 +3431,9 @@ begin
   FIncCamOld := 0;
   FIncCam := 0;
   FBFGFireCounter := -1;
-  FShellTimer := -1;
+  {$IFDEF ENABLE_SHELLS}
+    FShellTimer := -1;
+  {$ENDIF}
   FPain := 0;
   FLastHit := 0;
   FLastFrag := 0;
@@ -3662,7 +3516,9 @@ begin
   FIncCamOld := 0;
   FIncCam := 0;
   FBFGFireCounter := -1;
-  FShellTimer := -1;
+  {$IFDEF ENABLE_SHELLS}
+    FShellTimer := -1;
+  {$ENDIF}
   FPain := 0;
   FLastHit := 0;
   FSpawnInvul := 0;
@@ -4405,21 +4261,23 @@ begin
         else
           Dec(FReloading[b]);
 
+{$IFDEF ENABLE_SHELLS}
     if FShellTimer > -1 then
       if FShellTimer = 0 then
       begin
         if FShellType = SHELL_SHELL then
-          g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
+          g_Shells_Create(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
                                GameVelX, GameVelY-2, SHELL_SHELL)
         else if FShellType = SHELL_DBLSHELL then
         begin
-          g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
+          g_Shells_Create(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
                                GameVelX+1, GameVelY-2, SHELL_SHELL);
-          g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
+          g_Shells_Create(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
                                GameVelX-1, GameVelY-2, SHELL_SHELL);
         end;
         FShellTimer := -1;
       end else Dec(FShellTimer);
+{$ENDIF}
 
     if (FBFGFireCounter > -1) then
       if FBFGFireCounter = 0 then
@@ -4737,8 +4595,9 @@ begin
       g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX, Gamey);
       FFireAngle := FAngle;
       f := True;
-      g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
-                             GameVelX, GameVelY-2, SHELL_BULLET);
+      {$IFDEF ENABLE_SHELLS}
+        g_Shells_Create(GameX + PLAYER_RECT_CX, GameY + PLAYER_RECT_CX, GameVelX, GameVelY - 2, SHELL_BULLET);
+      {$ENDIF}
     end;
 
     WEAPON_SHOTGUN1:
@@ -4746,8 +4605,10 @@ begin
       g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
       FFireAngle := FAngle;
       f := True;
-      FShellTimer := 10;
-      FShellType := SHELL_SHELL;
+      {$IFDEF ENABLE_SHELLS}
+        FShellTimer := 10;
+        FShellType := SHELL_SHELL;
+      {$ENDIF}
     end;
 
     WEAPON_SHOTGUN2:
@@ -4755,8 +4616,10 @@ begin
       g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex, Gamey);
       FFireAngle := FAngle;
       f := True;
-      FShellTimer := 13;
-      FShellType := SHELL_DBLSHELL;
+      {$IFDEF ENABLE_SHELLS}
+        FShellTimer := 13;
+        FShellType := SHELL_DBLSHELL;
+      {$ENDIF}
     end;
 
     WEAPON_CHAINGUN:
@@ -4764,8 +4627,9 @@ begin
       g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex, Gamey);
       FFireAngle := FAngle;
       f := True;
-      g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
-                             GameVelX, GameVelY-2, SHELL_BULLET);
+      {$IFDEF ENABLE_SHELLS}
+        g_Shells_Create(GameX + PLAYER_RECT_CX, GameY + PLAYER_RECT_CX, GameVelX, GameVelY - 2, SHELL_BULLET);
+      {$ENDIF}
     end;
 
     WEAPON_ROCKETLAUNCHER:
@@ -4794,8 +4658,9 @@ begin
       g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
       FFireAngle := FAngle;
       f := True;
-      g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
-                             GameVelX, GameVelY-2, SHELL_SHELL);
+      {$IFDEF ENABLE_SHELLS}
+        g_Shells_Create(GameX + PLAYER_RECT_CX, GameY + PLAYER_RECT_CX, GameVelX, GameVelY - 2, SHELL_SHELL);
+      {$ENDIF}
     end;
 
     WEAPON_FLAMETHROWER: