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

📄 g_weapon.pas

📁 雷神之锤2(Quake2)Delphi源码
💻 PAS
📖 第 1 页 / 共 3 页
字号:

// (GAME=CTF)
//procedure fire_rocket (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius, int radius_damage);
procedure fire_rocket (self : edict_p; start, dir : vec3_t; damage, speed : integer; damage_radius, radius_damage : float);
var
  rocket : edict_p;
begin
//Y  rocket := G_Spawn();
  VectorCopy (start, rocket.s.origin);
  VectorCopy (dir, rocket.movedir);
(*Y  vectoangles (dir, rocket.s.angles);
  VectorScale (dir, speed, rocket.velocity);*)
  rocket.movetype := MOVETYPE_FLYMISSILE;
  rocket.clipmask := MASK_SHOT;
  rocket.solid := SOLID_BBOX;
  rocket.s.effects := rocket.s.effects OR EF_ROCKET;
  VectorClear (rocket.mins);
  VectorClear (rocket.maxs);
  rocket.s.modelindex := gi.modelindex ('models/objects/rocket/tris.md2');
  rocket.owner := self;
  rocket.touch := rocket_touch;
  rocket.nextthink := level.time + 8000/speed;
//Y  rocket.think := G_FreeEdict;
  rocket.dmg := damage;
(*Y  rocket.radius_dmg := radius_damage;
  rocket.dmg_radius := damage_radius;*)
  rocket.s.sound := gi.soundindex ('weapons/rockfly.wav');
  rocket.classname := 'rocket';

  if (self.client <> Nil) then
    check_dodge (self, rocket.s.origin, dir, speed);

  gi.linkentity (rocket);
end;//procedure (GAME=CTF)


{*
=================
fire_rail
=================
*}
// (GAME=CTF)
//procedure fire_rail (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick);
procedure fire_rail (self : edict_p; start, aimdir : vec3_t; damage, kick : integer);
var
  from,
  end_   : vec3_t;
  tr     : trace_t;
  ignore : edict_p;
  mask   : integer;
  water  : qboolean;
begin
  VectorMA (start, 8192, aimdir, end_);
  VectorCopy (start, from);
  ignore := self;
  water := false;
  mask := MASK_SHOT or CONTENTS_SLIME OR CONTENTS_LAVA;
  while (ignore <> Nil) do
  begin
//Y    tr := gi.trace (from, Nil, NULL, end_, ignore, mask);

//    if (tr.contents & (CONTENTS_SLIME|CONTENTS_LAVA))
    if ( (tr.contents AND (CONTENTS_SLIME OR CONTENTS_LAVA)) <> 0 )
    then begin
//      mask &= ~(CONTENTS_SLIME|CONTENTS_LAVA);
      mask := mask AND (NOT (CONTENTS_SLIME OR CONTENTS_LAVA));
      water := true;
    end
    else begin
//      if ((tr.ent.svflags & SVF_MONSTER) OR (tr.ent.client))
      if ( ((tr.ent.svflags AND SVF_MONSTER) <> 0) OR (tr.ent.client <> Nil) )
      then ignore := tr.ent
      else ignore := Nil;

(*Y      if ((tr.ent <> self) AND (tr.ent.takedamage)) then
        T_Damage (tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, 0, MOD_RAILGUN);*)
    end;

    VectorCopy (tr.endpos, from);
  end;//while

  // send gun puff / flash
  gi.WriteByte (svc_temp_entity);
//Y  gi.WriteByte (TE_RAILTRAIL);
  gi.WritePosition (start);
  gi.WritePosition (tr.endpos);
  gi.multicast (self.s.origin, MULTICAST_PHS);
//idsoft  gi.multicast (start, MULTICAST_PHS);
  if (water) then
  begin
    gi.WriteByte (svc_temp_entity);
//Y    gi.WriteByte (TE_RAILTRAIL);
    gi.WritePosition (start);
    gi.WritePosition (tr.endpos);
    gi.multicast (tr.endpos, MULTICAST_PHS);
  end;

  if (self.client <> Nil) then
//Y    PlayerNoise (self, tr.endpos, PNOISE_IMPACT);
end;//procedure (GAME=CTF)


{*
=================
fire_bfg
=================
*}
// (GAME=CTF)
//procedure bfg_explode (edict_t *self);
procedure bfg_explode (self : edict_p); cdecl;
var
  ent    : edict_p;
  v      : vec3_t;
  points,
  dist   : float;
begin
  if (self.s.frame = 0) then
  begin
    // the BFG effect
    ent := Nil;
(*Y{Y}    while ((ent = findradius(ent, self.s.origin, self.dmg_radius)) != NULL)
    begin
      if (!ent.takedamage) then
        Continue;
      if (ent = self.owner) then
        Continue;
      if (!CanDamage (ent, self)) then
        Continue;
      if (!CanDamage (ent, self.owner)) then
        Continue;

      VectorAdd (ent.mins, ent.maxs, v);
      VectorMA (ent.s.origin, 0.5, v, v);
      VectorSubtract (self.s.origin, v, v);
      dist := VectorLength(v);
      points := self.radius_dmg * (1.0 - sqrt(dist/self.dmg_radius));
      if (ent = self.owner) then
        points := points * 0.5;

      gi.WriteByte (svc_temp_entity);
      gi.WriteByte (TE_BFG_EXPLOSION);
      gi.WritePosition (ent.s.origin);
      gi.multicast (ent.s.origin, MULTICAST_PHS);
      T_Damage (ent, self, self.owner, self.velocity, ent.s.origin, vec3_origin, (int)points, 0, DAMAGE_ENERGY, MOD_BFG_EFFECT);
    end;//while*)
  end;

  self.nextthink := level.time + FRAMETIME;
  Inc(self.s.frame);
  if (self.s.frame = 5) then
//Y    self.think := G_FreeEdict;
end;//procedure (GAME=CTF)

// (GAME=CTF)
//procedure bfg_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf);
procedure bfg_touch (self, other : edict_p; plane : cplane_p; surf : csurface_p); cdecl;
begin
  if (other = self.owner) then
    Exit;

//  if (surf && (surf.flags & SURF_SKY)) then
  if (surf <> Nil) AND ((surf.flags AND SURF_SKY) <> 0) then
  begin
//Y    G_FreeEdict (self);
    Exit;
  end;

(*Y  if (self.owner.client <> Nil) then
    PlayerNoise (self.owner, self.s.origin, PNOISE_IMPACT);

  // core explosion - prevents firing it into the wall/floor
  if (other.takedamage) then
    T_Damage (other, self, self.owner, self.velocity, self.s.origin, plane.normal, 200, 0, 0, MOD_BFG_BLAST);
  T_RadiusDamage(self, self.owner, 200, other, 100, MOD_BFG_BLAST);*)

  gi.sound (self, CHAN_VOICE, gi.soundindex ('weapons/bfg__x1b.wav'), 1, ATTN_NORM, 0);
  self.solid := SOLID_NOT;
  self.touch := Nil;
  VectorMA (self.s.origin, -1 * FRAMETIME, self.velocity, self.s.origin);
  VectorClear (self.velocity);
  self.s.modelindex := gi.modelindex ('sprites/s_bfg3.sp2');
  self.s.frame := 0;
  self.s.sound := 0;
//  self.s.effects &= ~EF_ANIM_ALLFAST;
  self.s.effects := self.s.effects AND (NOT EF_ANIM_ALLFAST);
  self.think := bfg_explode;
  self.nextthink := level.time + FRAMETIME;
  self.enemy := other;

  gi.WriteByte (svc_temp_entity);
//Y  gi.WriteByte (TE_BFG_BIGEXPLOSION);
  gi.WritePosition (self.s.origin);
  gi.multicast (self.s.origin, MULTICAST_PVS);
end;//procedure (GAME=CTF)

// (GAME <> CTF)
//procedure bfg_think (edict_t *self);
procedure bfg_think (self : edict_p); cdecl;
var
  ent,
  ignore : edict_p;
  point,
  dir,
  start,
  end_   : vec3_t;
  dmg    : integer;
  tr     : trace_t;
begin
  if (deathmatch.value <> 0)
  then dmg := 5
  else dmg := 10;

  ent := Nil;
//Y  while ((ent = findradius(ent, self.s.origin, 256)) != NULL)
  begin
(*Y    if (ent = self) then
      Continue;

    if (ent = self.owner) then
      Continue;

    if (!ent.takedamage) then
      Continue;

//    if (!(ent.svflags & SVF_MONSTER) AND (!ent.client) AND (strcmp(ent.classname, 'misc_explobox') <> 0)) then
    if ( ((ent.svflags AND SVF_MONSTER) = 0) AND
         (ent.client = Nil) AND
         (strcmp(ent.classname, 'misc_explobox') <> 0) ) then
      Continue;*)

//only CFT
{$IFDEF CTF}
//ZOID
(*Y    //don't target players in CTF
    if (ctf.value) AND (ent.client) AND (self.owner.client) AND
       (ent.client.resp.ctf_team = self.owner.client.resp.ctf_team) then
      Continue;*)
//ZOID
{$ENDIF}

    VectorMA (ent.absmin, 0.5, ent.size, point);

    VectorSubtract (point, self.s.origin, dir);
    VectorNormalize (dir);

    ignore := self;
    VectorCopy (self.s.origin, start);
    VectorMA (start, 2048, dir, end_);
    while True do
    begin
//Y      tr := gi.trace (start, NULL, NULL, end_, ignore, CONTENTS_SOLID or CONTENTS_MONSTER or CONTENTS_DEADMONSTER);

      if (tr.ent=Nil) then
        break;

      // hurt it if we can
//      if ((tr.ent.takedamage) AND !(tr.ent.flags & FL_IMMUNE_LASER) AND (tr.ent <> self.owner)) then
(*Y      if ( (tr.ent.takedamage) AND
           ((tr.ent.flags AND FL_IMMUNE_LASER) = 0) AND
           (tr.ent <> self.owner) ) then
        T_Damage (tr.ent, self, self.owner, dir, tr.endpos, vec3_origin, dmg, 1, DAMAGE_ENERGY, MOD_BFG_LASER);*)

      // if we hit something that's not a monster or player we're done
//      if (!(tr.ent.svflags & SVF_MONSTER) AND (!tr.ent.client)) then
      if ( ((tr.ent.svflags AND SVF_MONSTER) = 0) AND (tr.ent.client=Nil) ) then
      begin
        gi.WriteByte (svc_temp_entity);
//Y        gi.WriteByte (TE_LASER_SPARKS);
        gi.WriteByte (4);
        gi.WritePosition (tr.endpos);
        gi.WriteDir (tr.plane.normal);
        gi.WriteByte (self.s.skinnum);
        gi.multicast (tr.endpos, MULTICAST_PVS);
        break;
      end;

      ignore := tr.ent;
      VectorCopy (tr.endpos, start);
    end;//while

    gi.WriteByte (svc_temp_entity);
//Y    gi.WriteByte (TE_BFG_LASER);
    gi.WritePosition (self.s.origin);
    gi.WritePosition (tr.endpos);
    gi.multicast (self.s.origin, MULTICAST_PHS);
  end;//while

  self.nextthink := level.time + FRAMETIME;
end;//procedure (GAME <> CTF)
                          
// (GAME=CTF)
//procedure fire_bfg (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius);
procedure fire_bfg (self : edict_p; start, dir : vec3_t; damage, speed : integer; damage_radius : float);
var
  bfg : edict_p;
begin
//Y  bfg := G_Spawn();
  VectorCopy (start, bfg.s.origin);
  VectorCopy (dir, bfg.movedir);
//Y  vectoangles (dir, bfg.s.angles);
  VectorScale (dir, speed, bfg.velocity);
  bfg.movetype := MOVETYPE_FLYMISSILE;
  bfg.clipmask := MASK_SHOT;
  bfg.solid := SOLID_BBOX;
//  bfg->s.effects |= EF_BFG | EF_ANIM_ALLFAST;
  bfg.s.effects := bfg.s.effects OR EF_BFG OR EF_ANIM_ALLFAST;
  VectorClear (bfg.mins);
  VectorClear (bfg.maxs);
  bfg.s.modelindex := gi.modelindex ('sprites/s_bfg1.sp2');
  bfg.owner := self;
  bfg.touch := bfg_touch;
  bfg.nextthink := level.time + 8000/speed;
//Y  bfg.think := G_FreeEdict;
  bfg.radius_dmg := damage;
  bfg.dmg_radius := damage_radius;
  bfg.classname := 'bfg blast';
  bfg.s.sound := gi.soundindex ('weapons/bfg__l1a.wav');

  bfg.think := bfg_think;
  bfg.nextthink := level.time + FRAMETIME;
  bfg.teammaster := bfg;
  bfg.teamchain := Nil;

  if (self.client <> Nil) then
    check_dodge (self, bfg.s.origin, dir, speed);

  gi.linkentity (bfg);
end;//procedure (GAME=CTF)

// End of file
end.



My current problems:
--------------------
1) all local variable

2) C2PAS: "if" & "for"

3) CTF: variable ctf

4) OK!

⌨️ 快捷键说明

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