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

📄 g_trigger.pas

📁 delphi编的不错的贪吃蛇
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  end;

  G_UseTargets (self, activator);

  self^.use := Nil;
end;

procedure SP_trigger_key (self: edict_p);
begin
  if (st.item = '') then
  begin
    gi.dprintf('no key item for trigger_key at %s'#10, vtos(self^.s.origin));
    Exit;
  end;
  self^.item := FindItemByClassname (st.item);

  if (self^.item = nil) then
  begin
    gi.dprintf('item %s not found for trigger_key at %s'#10, st.item, vtos(self^.s.origin));
    Exit;
  end;

  if (self^.target = '') then
  begin
    gi.dprintf('%s at %s has no target'#10, self^.classname, vtos(self^.s.origin));
    Exit;
  end;

  gi.soundindex ('misc/keytry.wav');
  gi.soundindex ('misc/keyuse.wav');

  self^.use := trigger_key_use;
end;


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

trigger_counter

==============================================================================
*)

(*QUAKED trigger_counter (.5 .5 .5) ? nomessage
Acts as an intermediary for an action that takes multiple inputs.

If nomessage is not set, t will print '1 more.. ' etc when triggered and 'sequence complete' when finished.

After the counter has been triggered 'count' times (default 2), it will fire all of it's targets and remove itself.
*)

procedure trigger_counter_use(self: edict_p; other: edict_p; activator: edict_p); cdecl;
begin
  if (self^.count = 0) then
    Exit;

  self^.count := self^.count - 1;

  if (self^.count <> 0) then
  begin
    if ((self^.spawnflags and 1) = 0) then
    begin
      gi.centerprintf(activator, '%i more to go...', self^.count);
      gi.sound (activator, CHAN_AUTO, gi.soundindex ('misc/talk1.wav'), 1, ATTN_NORM, 0);
    end;
    Exit;
  end;

  if ((self^.spawnflags and 1) = 0) then
  begin
    gi.centerprintf(activator, 'Sequence completed!');
    gi.sound (activator, CHAN_AUTO, gi.soundindex ('misc/talk1.wav'), 1, ATTN_NORM, 0);
  end;
  self^.activator := activator;
  multi_trigger (self);
end;

procedure SP_trigger_counter (self: edict_p);
begin
  self^.wait := -1;
  if (self^.Count = 0) then
    self^.count := 2;

  self^.use := trigger_counter_use;
end;


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

trigger_always

==============================================================================
*)

(*QUAKED trigger_always (.5 .5 .5) (-8 -8 -8) (8 8 8)
This trigger will always fire.  It is activated by the world.
*)
procedure SP_trigger_always (ent: edict_p);
begin
  // we must have some delay to make sure our use targets are present
  if (ent^.delay < 0.2) then
    ent^.delay := 0.2;
  G_UseTargets(ent, ent);
end;


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

trigger_push

==============================================================================
*)

const PUSH_ONCE	= 1 ;

var windsound: {TODO:smallint} Integer;

procedure trigger_push_touch (self: edict_p; other:edict_p; plane:cplane_p; surf:csurface_p); cdecl;
begin
  if (strcomp(other^.classname, 'grenade') = 0) then
  begin
    VectorScale (self^.movedir, self^.speed * 10, other^.velocity);
  end
  else if (other^.health > 0) then
  begin
    VectorScale (self^.movedir, self^.speed * 10, other^.velocity);

    if (other^.client <> nil) then
    begin
      // don't take falling damage immediately from this
      VectorCopy (other^.velocity, other^.client^.oldvelocity);
      if (other^.fly_sound_debounce_time < level.time) then
      begin
        other^.fly_sound_debounce_time := level.time + 1.5;
        gi.sound (other, CHAN_AUTO, windsound, 1, ATTN_NORM, 0);
      end;
    end;
  end;
  if (self^.spawnflags and PUSH_ONCE) <> 0 then
    G_FreeEdict (self);
end;


(*QUAKED trigger_push (.5 .5 .5) ? PUSH_ONCE
Pushes the player
'speed'		defaults to 1000
*)
procedure SP_trigger_push (self: edict_p);
begin
  InitTrigger (self);
  windsound := gi.soundindex ('misc/windfly.wav');
  self^.touch := trigger_push_touch;
  if (self^.speed = 0) then
    self^.speed := 1000;
  gi.linkentity (self);
end;


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

trigger_hurt

==============================================================================
*)

(*QUAKED trigger_hurt (.5 .5 .5) ? START_OFF TOGGLE SILENT NO_PROTECTION SLOW
Any entity that touches this will be hurt.

It does dmg points of damage each server frame

SILENT			supresses playing the sound
SLOW			changes the damage rate to once per second
NO_PROTECTION	*nothing* stops the damage

'dmg'			default 5 (whole numbers only)

*)
procedure hurt_use (Self : edict_p ; other : edict_p ; activator : edict_p); cdecl;
begin
  if (self^.solid = SOLID_NOT) then
    self^.solid := SOLID_TRIGGER
  else
    self^.solid := SOLID_NOT;
  gi.linkentity (self);

  if ((self^.spawnflags and 2) = 0) then
    self^.use := Nil;
end;


procedure hurt_touch (self: edict_p; other: edict_p; plane: cplane_p; surf: csurface_p); cdecl;
var
  dflags: {TODO:smallint} Integer;
begin
  if (other^.takedamage = DAMAGE_NO) then
    Exit;

  if (self^.timestamp > level.time) then
    Exit;

  if (self^.spawnflags and 16) <> 0 then
    self^.timestamp := level.time + 1
  else
    self^.timestamp := level.time + FRAMETIME;

  if ((self^.spawnflags and 4) = 0) then
  begin
    if ((level.framenum mod 10) = 0) then
      gi.sound (other, CHAN_AUTO, self^.noise_index, 1, ATTN_NORM, 0);
  end;

  if (self^.spawnflags and 8) <> 0 then
    dflags := DAMAGE_NO_PROTECTION
  else
    dflags := 0;
  T_Damage (other, self, self, vec3_origin, other^.s.origin, vec3_origin, self^.dmg, self^.dmg, dflags, MOD_TRIGGER_HURT);
end;

procedure SP_trigger_hurt (self: edict_p);
begin
  InitTrigger (self);

  self^.noise_index := gi.soundindex ('world/electro.wav');
  self^.touch := hurt_touch;

  if (self^.dmg = 0) then
    self^.dmg := 5;

  if (self^.spawnflags and 1) <> 0 then
    self^.solid := SOLID_NOT
  else
    self^.solid := SOLID_TRIGGER;

  if (self^.spawnflags and 2) <> 0 then
    self^.use := hurt_use;

  gi.linkentity (self);
end;


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

trigger_gravity

==============================================================================
*)

(*QUAKED trigger_gravity (.5 .5 .5) ?
Changes the touching entites gravity to
the value of 'gravity'.  1.0 is standard
gravity for the level.
*)

procedure trigger_gravity_touch ( self: edict_p; other: edict_p; plane: cplane_p; surf: csurface_p); cdecl;
begin
  other^.gravity := self^.gravity;
end;

procedure SP_trigger_gravity (self: edict_p);
begin
  if (st.gravity = '') then
  begin
    gi.dprintf('trigger_gravity without gravity set at %s'#10, vtos(self^.s.origin));
    G_FreeEdict  (self);
    Exit;
  end;

  InitTrigger (self);
  self^.gravity := atoi(st.gravity);
  self^.touch := trigger_gravity_touch;
end;


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

trigger_monsterjump

==============================================================================
*)

(*QUAKED trigger_monsterjump (.5 .5 .5) ?
Walking monsters that touch this will jump in the direction of the trigger's angle
'speed' default to 200, the speed thrown forward
'height' default to 200, the speed thrown upwards
*)

procedure trigger_monsterjump_touch (self: edict_p; other: edict_p; plane: cplane_p; surf: csurface_p); cdecl;
begin
  if (other^.flags and (FL_FLY or FL_SWIM)) <> 0 then
    Exit;
  if (other^.svflags and SVF_DEADMONSTER) <> 0 then
    Exit;
  if ((other^.svflags and SVF_MONSTER) = 0) then
    Exit;

// set XY even if not on ground, so the jump will clear lips
  other^.velocity[0] := self^.movedir[0] * self^.speed;
  other^.velocity[1] := self^.movedir[1] * self^.speed;

  if (other^.groundentity = nil) then
    Exit;

  other^.groundentity := Nil;
  other^.velocity[2] := self^.movedir[2];
end;

procedure SP_trigger_monsterjump (self: edict_p);
begin
  if (self^.speed = 0) then
    self^.speed := 200;
  if (st.Height = 0) then
    st.height := 200;
  if (self^.s.angles[q_shared.YAW] = 0) then
    self^.s.angles[q_shared.YAW] := 360;
  InitTrigger (self);
  self^.touch := trigger_monsterjump_touch;
  self^.movedir[2] := st.height;
end;

end.

⌨️ 快捷键说明

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