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

📄 m_gunner.pas

📁 雷神之锤2(Quake2)Delphi源码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
[
  ai_run, 26, NULL,
  ai_run, 9,  NULL,
  ai_run, 9,  NULL,
  ai_run, 9,  NULL,
  ai_run, 15, NULL,
  ai_run, 10, NULL,
  ai_run, 13, NULL,
  ai_run, 6,  NULL
];

const
  gunner_move_run: mmove_t = (FRAME_run01, FRAME_run08, gunner_frames_run, NULL);

procedure gunner_run (self: edict_t);
begin
  if (self.monsterinfo.aiflags = AI_STAND_GROUND) then
    self.monsterinfo.currentmove := gunner_move_stand
  else
    self.monsterinfo.currentmove := gunner_move_run;
end;

const
  gunner_frames_runandshoot: mframe_t =
[
  ai_run, 32, NULL,
  ai_run, 15, NULL,
  ai_run, 10, NULL,
  ai_run, 18, NULL,
  ai_run, 8,  NULL,
  ai_run, 20, NULL
];

const
  gunner_move_runandshoot: mmove_t = (FRAME_runs01, FRAME_runs06, gunner_frames_runandshoot, NULL);

procedure gunner_runandshoot (self: edict_t);
begin
  self.monsterinfo.currentmove := gunner_move_runandshoot;
end;

const
  gunner_frames_pain3: mframe_t =
[
  ai_move, -3, NULL,
  ai_move, 1,   NULL,
  ai_move, 1,   NULL,
  ai_move, 0,   NULL,
  ai_move, 1,   NULL
];

const
  gunner_move_pain3: mmove_t = (FRAME_pain301, FRAME_pain305, gunner_frames_pain3, gunner_run);

const
  gunner_frames_pain2: mframe_t =
[
  ai_move, -2, NULL,
  ai_move, 11, NULL,
  ai_move, 6,   NULL,
  ai_move, 2,   NULL,
  ai_move, -1, NULL,
  ai_move, -7, NULL,
  ai_move, -2, NULL,
  ai_move, -7, NULL
];

const
  gunner_move_pain2: mmove_t = (FRAME_pain201, FRAME_pain208, gunner_frames_pain2, gunner_run);

const
  gunner_frames_pain1: mframe_t =
[
  ai_move, 2,   NULL,
  ai_move, 0,   NULL,
  ai_move, -5, NULL,
  ai_move, 3,   NULL,
  ai_move, -1, NULL,
  ai_move, 0,   NULL,
  ai_move, 0,   NULL,
  ai_move, 0,   NULL,
  ai_move, 0,   NULL,
  ai_move, 1,   NULL,
  ai_move, 1,   NULL,
  ai_move, 2,   NULL,
  ai_move, 1,   NULL,
  ai_move, 0,   NULL,
  ai_move, -2, NULL,
  ai_move, -2, NULL,
  ai_move, 0,   NULL,
  ai_move, 0,   NULL
];

gunner_move_pain1: mmove_t = (FRAME_pain101, FRAME_pain118, gunner_frames_pain1, gunner_run);

procedure gunner_pain (self, other: edict_t; kick: float; damage: integer);
begin
  if self.health < (self.max_health / 2) then
    self.s.skinnum := 1;

  if level.time < self.pain_debounce_time then
    exit;

  self.pain_debounce_time := level.time + 3;

  if random() = 1 then
    gi.sound (self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
  else
    gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);

  if skill.value = 3 then
    exit;    // no pain anims in nightmare

  if damage <= 10 then
    self.monsterinfo.currentmove := gunner_move_pain3
  else if damage <= 25 then
    self.monsterinfo.currentmove := gunner_move_pain2
  else
    self.monsterinfo.currentmove := gunner_move_pain1;
end;

procedure gunner_dead (self: edict_t);
begin
  VectorSet (self.mins, -16, -16, -24);
  VectorSet (self.maxs, 16, 16, -8);
  self.movetype := MOVETYPE_TOSS;
  self.svflags := SVF_DEADMONSTER;
  self.nextthink := 0;
  gi.linkentity (self);
end;

const
  gunner_frames_death: mframe_t =
[
  ai_move, 0,   NULL,
  ai_move, 0,   NULL,
  ai_move, 0,   NULL,
  ai_move, -7, NULL,
  ai_move, -3, NULL,
  ai_move, -5, NULL,
  ai_move, 8,   NULL,
  ai_move, 6,   NULL,
  ai_move, 0,   NULL,
  ai_move, 0,   NULL,
  ai_move, 0,   NULL
];

const
  gunner_move_death: mmove_t = (FRAME_death01, FRAME_death11, gunner_frames_death, gunner_dead);

procedure gunner_die (self, inflictor, attacker: edict_t; damage: integer; point: vec3_t);
  var n: integer;
begin
// check for gib
  if self.health <= self.gib_health then
    begin
    gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
    for n := 0 to n := 1 do
      ThrowGib (self, 'models/objects/gibs/bone/tris.md2', damage, GIB_ORGANIC);
    for n := 0 to n := 3 do
      ThrowGib (self, 'models/objects/gibs/sm_meat/tris.md2', damage, GIB_ORGANIC);
    ThrowHead (self, 'models/objects/gibs/head2/tris.md2', damage, GIB_ORGANIC);
    self.deadflag := DEAD_DEAD;
    exit;
    end;

  if self.deadflag = DEAD_DEAD then Exit;

// regular death
  gi.sound (self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
  self.deadflag := DEAD_DEAD;
  self.takedamage := DAMAGE_YES;
  self.monsterinfo.currentmove := gunner_move_death;
end;


procedure gunner_duck_down (self: edict_t);
begin
  if self.monsterinfo.aiflags = AI_DUCKED then Exit;

  self.monsterinfo.aiflags := AI_DUCKED;
  if skill.value >= 2 then
    if random() > 0.5 then
      GunnerGrenade (self);

  self.maxs[2] := 32;
  self.takedamage := DAMAGE_YES;
  self.monsterinfo.pausetime := level.time + 1;
  gi.linkentity (self);
end;

procedure gunner_duck_hold (self: edict_t);
begin
  if level.time >= self.monsterinfo.pausetime then
    self.monsterinfo.aiflags := AI_HOLD_FRAME;
  else
    self.monsterinfo.aiflags := AI_HOLD_FRAME;
end;

procedure gunner_duck_up (self: edict_t);
begin
  self.monsterinfo.aiflags := AI_DUCKED;
  self.maxs[2] := 32;
  self.takedamage := DAMAGE_AIM;
  gi.linkentity (self);
end;

const
  gunner_frames_duck: mframe_t =
[
  ai_move, 1,  gunner_duck_down,
  ai_move, 1,  NULL,
  ai_move, 1,  gunner_duck_hold,
  ai_move, 0,  NULL,
  ai_move, -1, NULL,
  ai_move, -1, NULL,
  ai_move, 0,  gunner_duck_up,
  ai_move, -1, NULL
];
  gunner_move_duck: mmove_t = (FRAME_duck01, FRAME_duck08, gunner_frames_duck, gunner_run);

procedure gunner_dodge (self, attacker: edict_t; eta: float);
begin
  if random() > 0.25 then exit;

  if self.enemy then
    self.enemy := attacker;

  self.monsterinfo.currentmove := gunner_move_duck;
end;


procedure gunner_opengun (self: edict_t);
begin
  gi.sound (self, CHAN_VOICE, sound_open, 1, ATTN_IDLE, 0);
end;

procedure GunnerFire (self: edict_t);
var
  start,
  forward, right,
  target, aim: vec3_t;
  flash_number: integer;
begin
  flash_number = MZ2_GUNNER_MACHINEGUN_1 + (self.s.frame - FRAME_attak216);

  AngleVectors (self.s.angles, forward, right, NULL);
  G_ProjectSource (self.s.origin, monster_flash_offset[flash_number], forward, right, start);

  // project enemy back a bit and target there
  VectorCopy (self.enemy.s.origin, target);
  VectorMA (target, -0.2, self.enemy.velocity, target);
  target[2] := self.enemy.viewheight;

  VectorSubtract (target, start, aim);
  VectorNormalize (aim);
  monster_fire_bullet (self, start, aim, 3, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
end;

procedure GunnerGrenade (self: edict_t);
var
  start,
  forward, right, aim: vec3_t;
  flash_number: integer;
begin

  if (self->s.frame == FRAME_attak105)
    flash_number = MZ2_GUNNER_GRENADE_1;
  else if (self->s.frame == FRAME_attak108)
    flash_number = MZ2_GUNNER_GRENADE_2;
  else if (self->s.frame == FRAME_attak111)
    flash_number = MZ2_GUNNER_GRENADE_3;
  else // (self->s.frame == FRAME_attak114)
    flash_number = MZ2_GUNNER_GRENADE_4;

  AngleVectors (self->s.angles, forward, right, NULL);
  G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);

  //FIXME : do a spread -225 -75 75 225 degrees around forward
  VectorCopy (forward, aim);

  monster_fire_grenade (self, start, aim, 50, 600, flash_number);
end;

mframe_t gunner_frames_attack_chain [] =
{
  /*
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  */
  ai_charge, 0, gunner_opengun,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL
};
  gunner_move_attack_chain: mmove_t = (FRAME_attak209, FRAME_attak215, gunner_frames_attack_chain, gunner_fire_chain);

mframe_t gunner_frames_fire_chain [] =
{
  ai_charge,   0, GunnerFire,
  ai_charge,   0, GunnerFire,
  ai_charge,   0, GunnerFire,
  ai_charge,   0, GunnerFire,
  ai_charge,   0, GunnerFire,
  ai_charge,   0, GunnerFire,
  ai_charge,   0, GunnerFire,
  ai_charge,   0, GunnerFire
};
  gunner_move_fire_chain: mmove_t = (FRAME_attak216, FRAME_attak223, gunner_frames_fire_chain, gunner_refire_chain);

mframe_t gunner_frames_endfire_chain [] =
{
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL
};
  gunner_move_endfire_chain: mmove_t = (FRAME_attak224, FRAME_attak230, gunner_frames_endfire_chain, gunner_run);

mframe_t gunner_frames_attack_grenade [] =
{
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, GunnerGrenade,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, GunnerGrenade,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, GunnerGrenade,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, GunnerGrenade,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL,
  ai_charge, 0, NULL
};
  gunner_move_attack_grenade: mmove_t = (FRAME_attak101, FRAME_attak121, gunner_frames_attack_grenade, gunner_run);

procedure gunner_attack(self: edict_t);
begin
  if (range (self, self->enemy) == RANGE_MELEE)
  {
    self->monsterinfo.currentmove = &gunner_move_attack_chain;
  }
  else
  {
    if (random() <= 0.5)
      self->monsterinfo.currentmove = &gunner_move_attack_grenade;
    else
      self->monsterinfo.currentmove = &gunner_move_attack_chain;
  }
end;

procedure gunner_fire_chain(self: edict_t);
begin
  self->monsterinfo.currentmove = &gunner_move_fire_chain;
end;

procedure gunner_refire_chain(self: edict_t);
begin
  if (self->enemy->health > 0)
    if ( visible (self, self->enemy) )
      if (random() <= 0.5)
      {
        self->monsterinfo.currentmove = &gunner_move_fire_chain;
        return;
      }
  self->monsterinfo.currentmove = &gunner_move_endfire_chain;
end;

// QUAKED monster_gunner (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight

procedure SP_monster_gunner (self: edict_t);
begin
  if (deathmatch->value)
  {
    G_FreeEdict (self);
    return;
  }

  sound_death = gi.soundindex ("gunner/death1.wav");  
  sound_pain = gi.soundindex ("gunner/gunpain2.wav");  
  sound_pain2 = gi.soundindex ("gunner/gunpain1.wav");  
  sound_idle = gi.soundindex ("gunner/gunidle1.wav");  
  sound_open = gi.soundindex ("gunner/gunatck1.wav");  
  sound_search = gi.soundindex ("gunner/gunsrch1.wav");  
  sound_sight = gi.soundindex ("gunner/sight1.wav");  

  gi.soundindex ("gunner/gunatck2.wav");
  gi.soundindex ("gunner/gunatck3.wav");

  self->movetype = MOVETYPE_STEP;
  self->solid = SOLID_BBOX;
  self->s.modelindex = gi.modelindex ("models/monsters/gunner/tris.md2");
  VectorSet (self->mins, -16, -16, -24);
  VectorSet (self->maxs, 16, 16, 32);

  self->health = 175;
  self->gib_health = -70;
  self->mass = 200;

  self->pain = gunner_pain;
  self->die = gunner_die;

  self->monsterinfo.stand = gunner_stand;
  self->monsterinfo.walk = gunner_walk;
  self->monsterinfo.run = gunner_run;
  self->monsterinfo.dodge = gunner_dodge;
  self->monsterinfo.attack = gunner_attack;
  self->monsterinfo.melee = NULL;
  self->monsterinfo.sight = gunner_sight;
  self->monsterinfo.search = gunner_search;

  gi.linkentity (self);

  self->monsterinfo.currentmove = &gunner_move_stand;  
  self->monsterinfo.scale = MODEL_SCALE;

  walkmonster_start (self);
end;

end.

⌨️ 快捷键说明

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