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

📄 g_target.pas

📁 雷神之锤2(Quake2)Delphi源码
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{----------------------------------------------------------------------------}
{                                                                            }
{ File(s): g_target.pas                                                      }
{                                                                            }
{ Initial conversion by : Jose M. Navarro (jose.man@airtel.net)              }
{ Initial conversion on : 10-Jul-2002                                        }
{                                                                            }
{ NOTE: This file (Game\g_target.pas) is compatible with same name file in   } 
{ CTF directory (CTF\g_target.pas)                                           } 
{                                                                            }
{ 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 puC:\Documents and Settings\PCDELPHI4.PC-DELPHI4\Escritorio\g_target.c
blished 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.                       }
{                                                                            }
{----------------------------------------------------------------------------}
{ Updated on :                                                               }
{ Updated by :                                                               }
{                                                                            }
{----------------------------------------------------------------------------}
{ * Still dependent (to compile correctly) on:                               }
{ 1.- gi.dprintf replaced with gi_dprintfand temporary                       }
{ 2.- gi.bprintf replaced with gi_bprintf temporary                          }
{ 3.- Following functions included for avoid include unit in uses clause.    }
{     Taken from g_utils.pas:                                                }
{         function vtos                                                      }
{         procedure G_FreeEdict                                              }
{         procedure G_UseTargets                                             }
{         procedure G_SetMovedir                                             }
{         function G_Spawn                                                   }
{         function KillBox                                                   }
{         function G_Find                                                    }
{                                                                            }
{      Taken from g_combat.pas                                               }
{         procedure T_RadiusDamage                                           }
{         procedure T_Damage                                                 }
{                                                                            }
{      taken from p_hud.pas                                                  }
{         procedure BeginIntermission                                        }
{                                                                            }
{      taken from p_weapon.pas                                               }
{         procedure fire_blaster                                             }
{                                                                            }
{      taken from g_save                                                     }
{         function FOFS_targetname                                           }
{                                                                            }
{----------------------------------------------------------------------------}
{ * TODO:                                                                    }
{ Some lines (marqued with //???? are comented because could not be          }
{ translated:                                                                }
{    縒here is declared "deathmatch" and "coop" variables.                   }
{        All references has beed commented                                   }
{    Some assignment are incompatibles:                                      }
{        char := single expression                                           }
{        char := char + single expression                                    }
{        and more...                                                         }
{                                                                            }
{----------------------------------------------------------------------------}
unit g_target;

interface

uses g_local, GameUnit, q_shared;

{$Include ..\JEDI.inc}

//==========================================================
// TEMPORARY
//==========================================================

//==========================================================
procedure Use_Target_Tent(ent: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_temp_entity(ent: edict_p);

//==========================================================
// QUAKED target_speaker
procedure Use_Target_Speaker(ent: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_speaker(ent: edict_p);

//==========================================================
// QUAKED target_help
procedure Use_Target_Help(ent: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_help(ent: edict_p);

//==========================================================
// QUAKED target_secret
procedure use_target_secret(ent: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_secret(ent: edict_p);

//==========================================================
// QUAKED target_goal
procedure use_target_goal(ent: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_goal(ent: edict_p);

//==========================================================
// QUAKED target_explosion
procedure target_explosion_explode(self: edict_p);
procedure use_target_explosion(self: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_explosion(ent: edict_p);


//==========================================================
// QUAKED target_changelevel
procedure use_target_changelevel(self: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_changelevel(ent: edict_p);

//==========================================================
// QUAKED target_splash
procedure use_target_splash(self: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_splash(self: edict_p);

//==========================================================
// QUAKED target_spawner
procedure ED_CallSpawn(ent: edict_p);
procedure use_target_spawner(self: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_spawner(self: edict_p);

//==========================================================
// QUAKED target_blaster
procedure use_target_blaster(self: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_blaster(self: edict_p);

//==========================================================
// QUAKED target_crosslevel_trigger
procedure trigger_crosslevel_trigger_use(self: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_crosslevel_trigger(self: edict_p);

//==========================================================
// QUAKED target_crosslevel_target
procedure target_crosslevel_target_think(self: edict_p);
procedure SP_target_crosslevel_target(self: edict_p);

//==========================================================
// QUAKED target_laser
procedure target_laser_think(self: edict_p);
procedure target_laser_on(self: edict_p);
procedure target_laser_off(self: edict_p);
procedure target_laser_use(self: edict_p; other: edict_p; activator: edict_p);
procedure target_laser_start(self: edict_p);
procedure SP_target_laser(self: edict_p);

//==========================================================
// QUAKED target_lightramp
procedure target_lightramp_think(self: edict_p);
procedure target_lightramp_use(self: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_lightramp(self: edict_p);

//==========================================================
// QUAKED target_earthquake
procedure target_earthquake_think(self: edict_p);
procedure target_earthquake_use(self: edict_p; other: edict_p; activator: edict_p);
procedure SP_target_earthquake(self: edict_p);

implementation

uses SysUtils;

//==========================================================
// TEMPORARY: REMOVE WHEN OK
//==========================================================

(* VectorToString Taken from g_utils.pas *)
function vtos(const v: vec3_t): PChar;
begin
end;

(* G_FreeEdict: taken from g_utils *)
procedure G_FreeEdict(ed: edict_p); cdecl;
begin
end;

(* G_UseTargets: taken from g_utils *)
procedure G_UseTargets(ent: edict_p; activator: edict_p);
begin
end;

(* G_SetMovedir: taken from g_utils *)
procedure G_SetMovedir(var angles: vec3_t; out movedir: vec3_t);
begin
end;

(* G_Spawn: taken from g_utils *)
function G_Spawn: edict_p;
begin
end;

(* KillBox: taken from g_utils *)
function KillBox(ent: edict_p): qboolean;
begin
end;

(* G_Find: taken from g_utils *)
function G_Find(from: edict_p; fieldofs: Integer; match: PChar): edict_p;
begin
end;


(* T_RadiusDamage: Taken from g_combat.pas *)
procedure T_RadiusDamage(inflictor, attacker: edict_p; damage: single; ignore: edict_p; radius: single; mofd: Integer);
begin
end;

(* T_Damage: Taken from g_combat *)
procedure T_Damage(targ, inflictor, attacker: edict_p; dir, point, normal: vec3_t; damage, knockback, dflags, mofd: Integer);
begin
end;

(* BeginIntermission: taken from p_hud *)
procedure BeginIntermission(targ: edict_p);
begin
end;

(* fire_blaster: taken from p_weapon *)
procedure fire_blaster(self : edict_p; start, dir : vec3_t; damage, speed, effect : single; hyper : qboolean);
begin
end;

(* FOFS_targetname: taken from g_save *)
function FOFS_targetname: Integer;
begin
  Result:=Integer(@edict_p(Ptr(0)).targetname);
end;
//==========================================================
// END TEMPORARY
//==========================================================




//==========================================================
{QUAKED target_temp_entity (1 0 0) (-8 -8 -8) (8 8 8)
Fire an origin based temp entity event to the clients.
"style"		type byte
}
procedure Use_Target_Tent(ent: edict_p; other: edict_p; activator: edict_p);
begin
  gi.WriteByte(svc_temp_entity);
  gi.WriteByte(ent^.style);
  gi.WritePosition(ent^.s.origin);
  gi.multicast(ent^.s.origin, MULTICAST_PVS);
end;

procedure SP_target_temp_entity(ent: edict_p);
begin
  ent^.use := @Use_Target_Tent;
end;


//==========================================================
{ QUAKED target_speaker (1 0 0) (-8 -8 -8) (8 8 8) looped-on looped-off reliable
"noise"		wav file to play
"attenuation"
-1 = none, send to whole level
1 = normal fighting sounds
2 = idle sound level
3 = ambient sound level
"volume"	0.0 to 1.0

Normal sounds play each time the target is used.  The reliable flag can be set for crucial voiceovers.

Looped sounds are allways atten 3 / vol 1, and the use function toggles it on/off.
Multiple identical looping sounds will just increase volume without any speed cost.
}
procedure Use_Target_Speaker(ent: edict_p; other: edict_p; activator: edict_p);
var
  chan: integer;
begin
  if (ent^.spawnflags and 3) <> 0 then
  begin  // looping sound toggles
    if ent^.s.sound <> 0 then
      ent^.s.sound := 0	// turn it off
    else
      ent^.s.sound := ent^.noise_index;	// start it
  end
  else
  begin  // normal sound
    if (ent^.spawnflags and 4) <> 0 then
      chan := CHAN_VOICE or CHAN_RELIABLE
    else
      chan := CHAN_VOICE;
    // use a positioned_sound, because this entity won't normally be
    // sent to any clients because it is invisible
    gi.positioned_sound(ent^.s.origin, ent, chan, ent^.noise_index, ent^.volume, ent^.attenuation, 0);
  end;
end;

procedure SP_target_speaker(ent: edict_p);
var
  buffer: array[0..MAX_QPATH-1] of char;
begin
  if st.noise = nil then
  begin
    gi_dprintf('target_speaker with no noise set at %s'#10, [vtos(ent^.s.origin)]);
    exit;
  end;
  if Pos('.wav', st.noise) = 0 then // was ( !strstr( st.noise, ".wav" ) )
    Com_sprintf(buffer, sizeof(buffer), '%s.wav', [st.noise])
  else
    StrLCopy(buffer, st.noise, sizeof(buffer)); // I convert strncpy as StrLCopy
  ent^.noise_index := gi.soundindex(buffer);

  if ent^.volume = 0 then
    ent^.volume := 1.0;

  if ent^.attenuation = 0 then
    ent^.attenuation := 1.0
  else if ent^.attenuation = -1 then	// use -1 so 0 defaults to 1
    ent^.attenuation := 0;

  // check for prestarted looping sound
  if (ent^.spawnflags and 1) <> 0 then
    ent^.s.sound := ent^.noise_index;

  ent^.use := @Use_Target_Speaker;

  // must link the entity so we get areas and clusters so
  // the server can determine who to send updates to
  gi.linkentity(ent);
end;


//==========================================================
{ QUAKED target_help (1 0 1) (-16 -16 -24) (16 16 24) help1
When fired, the "message" key becomes the current personal computer string, and the message light will be set on all clients status bars.
}
procedure Use_Target_Help(ent: edict_p; other: edict_p; activator: edict_p);
begin
  if (ent^.spawnflags and 1) <> 0 then
    StrLCopy(game.helpmessage1, ent^._message, sizeof(game.helpmessage2) - 1)
  else
    StrLCopy(game.helpmessage2, ent^._message, sizeof(game.helpmessage1) - 1);

  Inc(game.helpchanged);
end;

procedure SP_target_help(ent: edict_p);
begin
//????
  if {deathmatch^.value} false then
  begin  // auto-remove for deathmatch
    G_FreeEdict(ent);
    exit;

⌨️ 快捷键说明

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