⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p_trail.pas

📁 雷神之锤2(Quake2)Delphi源码
💻 PAS
字号:
{----------------------------------------------------------------------------}
{                                                                            }
{ File(s): g_local.h (part), p_trail.c                                       }
{ Content: Quake2\Game\ list of recent player positions                      }
{                                                                            }
{ Initial conversion by : Clootie (Alexey Barkovoy) - clootie@reactor.ru     }
{ Initial conversion on : 13-Jan-2002                                        }
{                                                                            }
{ This File contains part of convertion of Quake2 source to ObjectPascal.    }
{ More information about this project can be found at:                       }
{ http://www.sulaco.co.za/quake2/                                            }
{                                                                            }
{ Copyright (C) 1997-2001 Id Software, Inc.                                  }
{                                                                            }
{ 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 the Free Software Foundation; either version 2             }
{ of the License, or (at your option) any later version.                     }
{                                                                            }
{ This program is distributed in the hope that it will be useful,            }
{ but WITHOUT ANY WARRANTY; without even the implied warranty of             }
{ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                       }
{                                                                            }
{ See the GNU General Public License for more details.                       }
{                                                                            }
{----------------------------------------------------------------------------}
{ 1) 22-Jan-2002 - Clootie (clootie@reactor.ru)                              }
{    Updated, now unit uses existing code in Q_Shared.pas instead of stubs.  }
{ 2) 25-Feb-2002 - Clootie (clootie@reactor.ru)                              }
{    Cleaned up most external dependencies - only g_ai.pas - "visible" lasts.}
{                                                                            }
{----------------------------------------------------------------------------}
{ * Still dependent (to compile correctly) on:                               }
{ 1) g_ai                                                                    }
{                                                                            }
{----------------------------------------------------------------------------}
{ * TODO:                                                                    }
{ 1) Clootie: Resolve other unit dependencies                                }
{                                                                            }
{----------------------------------------------------------------------------}

// Remove DOT before $DEFINE in next line to allow non-dependable compilation //
{$DEFINE NODEPEND}
// --- non-dependable compilation will use STUBS for some external symbols ---

unit p_trail;

interface

uses
  Q_shared, g_local;

// From g_local.h, line 737
//
// g_ptrail.c
//
procedure PlayerTrail_Init;
procedure PlayerTrail_Add(const spot: vec3_t);
procedure PlayerTrail_New(const spot: vec3_t);
function PlayerTrail_PickFirst(const self: edict_t): edict_p;
function PlayerTrail_PickNext(const self: edict_t): edict_p;
function PlayerTrail_LastSpot: edict_p;

implementation

uses
  CVar, g_main, g_utils{$IFNDEF NODEPEND}, g_ia{$ENDIF};

{$IFDEF NODEPEND}

//From g_local.h, line 720
function visible(const self, other: edict_t): qboolean;
begin Result:= False; end;

{$ENDIF}


(*
==============================================================================

PLAYER TRAIL

==============================================================================

This is a circular list containing the a list of points of where
the player has been recently.  It is used by monsters for pursuit.

.origin		the spot
.owner		forward link
.aiment		backward link
*)

const
  TRAIL_LENGTH  = 8;

var
  trail:        array[0..TRAIL_LENGTH-1] of edict_p;
  trail_head:   Integer;
  trail_active: qboolean = False;

  
//#define NEXT(n)		(((n) + 1) & (TRAIL_LENGTH - 1))
function NEXT(n: Integer): Integer;
begin
  Result:= (n + 1) and (TRAIL_LENGTH - 1);
end;

//#define PREV(n)		(((n) - 1) & (TRAIL_LENGTH - 1))
function PREV(n: Integer): Integer;
begin
  Result:= (n - 1) and (TRAIL_LENGTH - 1);
end;


procedure PlayerTrail_Init;
var
  n: Integer;
begin
  if (deathmatch.value (* FIXME || coop *) <> 0) then Exit;

  for n := 0 to TRAIL_LENGTH - 1 do
  begin
    trail[n] := G_Spawn;
    trail[n].classname := 'player_trail';
  end;

  trail_head := 0;
  trail_active := True;
end;


procedure PlayerTrail_Add(const spot: vec3_t);
var
  temp: vec3_t;
begin
  if not trail_active then Exit;

  VectorCopy(spot, trail[trail_head].s.origin);

  trail[trail_head].timestamp := level.time;

  VectorSubtract(spot, trail[PREV(trail_head)].s.origin, temp);
  trail[trail_head].s.angles[1] := vectoyaw(temp);

  trail_head := NEXT(trail_head);
end;


procedure PlayerTrail_New(const spot: vec3_t);
begin
  if (not trail_active) then Exit;

  PlayerTrail_Init;
  PlayerTrail_Add(spot);
end;


function PlayerTrail_PickFirst(const self: edict_t): edict_p;
var
  marker: Integer;
  n: Integer;
begin
  Result:= nil;
  if (not trail_active) then Exit;

  // for (marker = trail_head, n = TRAIL_LENGTH; n; n--)
  marker := trail_head;
  for n:= TRAIL_LENGTH downto 1 do
  begin
    if (trail[marker].timestamp <= self.monsterinfo.trail_time) then
      marker := NEXT(marker)
    else
      Break;
  end;

  if visible(self, trail[marker]^) then
  begin
    Result:= trail[marker];
    Exit;
  end;

  if visible(self, trail[PREV(marker)]^) then
  begin
    Result:= trail[PREV(marker)];
    Exit;
  end;

  Result:= trail[marker];
end;


function PlayerTrail_PickNext(const self: edict_t): edict_p;
var
  marker: Integer;
  n: Integer;
begin
  Result:= nil;
  if not trail_active then Exit;

  // for (marker = trail_head, n = TRAIL_LENGTH; n; n--)
  marker := trail_head;
  for n:= TRAIL_LENGTH downto 1 do
  begin
    if (trail[marker].timestamp <= self.monsterinfo.trail_time) then
      marker := NEXT(marker)
    else
      Break;
  end;

  Result:= trail[marker];
end;


function PlayerTrail_LastSpot: edict_p;
begin
  Result:= trail[PREV(trail_head)];
end;

end.

amenum;
	float		time;

	char		level_name[MAX_QPATH];	// the descriptive name (Outer Base, etc)
	char		mapname[MAX_QPATH];		// the server name (base1, etc)
	char		nextmap[MAX_QPATH];		// go here when fraglimit is hit

	// intermission state
	float		intermissiontime;		// time the intermission was started
	char		*changemap;
	int			exitintermission;
	vec3_t		intermission_origin;
	vec3_t		intermission_angle;

	edict_t		*sight_client;	// changed once each frame for coop games

	edict_t		*sight_entity;
	int			sight_entity_framenum;
	edict_t		*sound_entity;
	int			sound_entity_framenum;
	edict_t		*sound2_entity;
	int			sound2_entity_framenum;

	int			pic_health;

	int			total_secrets;
	int			found_secrets;

	int			total_goals;
	int			found_goals;

	int			total_monsters;
	int			killed_monsters;

	edict_t		*current_entity;	// entity running from G_RunFrame
	int			body_que;			// dead bodies

	int			power_cubes;		// ugly necessity for coop
} end;

//From g_local.h, line 720
function visible(const self, other: edict_t): qboolean;
begin Result:= False; end;

// From g_main.c, line 24
var
  level: level_locals_t;

// From g_utils
function vectoyaw(vec: vec3_t): Single;
begin Result:= 0; end;

{$ENDIF}


(*
==============================================================================

PLAYER TRAIL

==============================================================================

This is a circular list containing the a list of points of where
the player has been recently.  It is used by monsters for pursuit.

.origin		the spot
.owner		forward link
.aiment		backward link
*)

const
  TRAIL_LENGTH  = 8;

var
  trail:        array[0..TRAIL_LENGTH-1] of edict_p;
  trail_head:   Integer;
  trail_active: qboolean = False;

  
//#define NEXT(n)		(((n) + 1) & (TRAIL_LENGTH - 1))
function NEXT(n: Integer): Integer;
begin
  Result:= (n + 1) and (TRAIL_LENGTH - 1);
end;

//#define PREV(n)		(((n) - 1) & (TRAIL_LENGTH - 1))
function PREV(n: Integer): Integer;
begin
  Result:= (n - 1) and (TRAIL_LENGTH - 1);
end;


procedure PlayerTrail_Init;
var
  n: Integer;
begin
  if (deathmatch.value (* FIXME || coop *) <> 0) then Exit;

  for n := 0 to TRAIL_LENGTH - 1 do
  begin
    trail[n] := G_Spawn;
    trail[n].classname := 'player_trail';
  end;

  trail_head := 0;
  trail_active := True;
end;


procedure PlayerTrail_Add(const spot: vec3_t);
var
  temp: vec3_t;
begin
  if not trail_active then Exit;

  VectorCopy(spot, trail[trail_head].s.origin);

  trail[trail_head].timestamp := level.time;

  VectorSubtract(spot, trail[PREV(trail_head)].s.origin, temp);
  trail[trail_head].s.angles[1] := vectoyaw(temp);

  trail_head := NEXT(trail_head);
end;


procedure PlayerTrail_New(const spot: vec3_t);
begin
  if (not trail_active) then Exit;

  PlayerTrail_Init;
  PlayerTrail_Add(spot);
end;


function PlayerTrail_PickFirst(const self: edict_t): edict_p;
var
  marker: Integer;
  n: Integer;
begin
  Result:= nil;
  if (not trail_active) then Exit;

  // for (marker = trail_head, n = TRAIL_LENGTH; n; n--)
  marker := trail_head;
  for n:= TRAIL_LENGTH downto 1 do
  begin
    if (trail[marker].timestamp <= self.monsterinfo.trail_time) then
      marker := NEXT(marker)
    else
      Break;
  end;

  if visible(self, trail[marker]^) then
  begin
    Result:= trail[marker];
    Exit;
  end;

  if visible(self, trail[PREV(marker)]^) then
  begin
    Result:= trail[PREV(marker)];
    Exit;
  end;

  Result:= trail[marker];
end;


function PlayerTrail_PickNext(const self: edict_t): edict_p;
var
  marker: Integer;
  n: Integer;
begin
  Result:= nil;
  if not trail_active then Exit;

  // for (marker = trail_head, n = TRAIL_LENGTH; n; n--)
  marker := trail_head;
  for n:= TRAIL_LENGTH downto 1 do
  begin
    if (trail[marker].timestamp <= self.monsterinfo.trail_time) then
      marker := NEXT(marker)
    else
      Break;
  end;

  Result:= trail[marker];
end;


function PlayerTrail_LastSpot: edict_p;
begin
  Result:= trail[PREV(trail_head)];
end;

end.
unction PlayerTrail_LastSpot: edict_p;
begin
  Result:= trail[PREV(trail_head)];
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -