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

📄 g_misc.pas

📁 delphi编的不错的贪吃蛇
💻 PAS
📖 第 1 页 / 共 4 页
字号:
begin
  self.movetype := MOVETYPE_NONE;
  self.solid := SOLID_NOT;
  VectorSet(self.mins, -8, -8, -8);
  VectorSet(self.maxs, 8, 8, 8);

  self.s.modelindex := gi.modelindex ('models/objects/bomb/tris.md2');

  if self.dmg = 0 then
    self.dmg := 1000;

  self.use := misc_viper_bomb_use;
  self.svflags := self.svflags OR SVF_NOCLIENT;

  gi.linkentity(self);
end;


(*QUAKED misc_strogg_ship (1 .5 0) (-16 -16 0) (16 16 32)
This is a Storgg ship for the flybys.
It is trigger_spawned, so you must have something use it for it to show up.
There must be a path for it to follow once it is activated.

'speed'    How fast it should fly
*)

procedure misc_strogg_ship_use (self, other, activator: edict_p); cdecl;
begin
  self.svflags := self.svflags AND NOT SVF_NOCLIENT;
  self.use := train_use;
  train_use(self, other, activator);
end;

procedure SP_misc_strogg_ship(ent: edict_p); cdecl;
begin
  if ent.target=Nil then begin
    gi_dprintf('%s without a target at %s'#10, [ent.classname, vtos(ent.absmin)]);
    G_FreeEdict(ent);
    exit;
  end;

  if ent.speed = 0 then
    ent.speed := 300;

  ent.movetype := MOVETYPE_PUSH;
  ent.solid := SOLID_NOT;
  ent.s.modelindex := gi.modelindex('models/ships/strogg1/tris.md2');
  VectorSet(ent.mins, -16, -16, 0);
  VectorSet(ent.maxs, 16, 16, 32);

  ent.think := func_train_find;
  ent.nextthink := level.time + FRAMETIME;
  ent.use := misc_strogg_ship_use;
  ent.svflags := ent.svflags OR SVF_NOCLIENT;
  ent.moveinfo.accel := ent.speed;
  ent.moveinfo.decel := ent.speed;
  ent.moveinfo.speed := ent.speed;

  gi.linkentity(ent);
end;


(*QUAKED misc_satellite_dish (1 .5 0) (-64 -64 0) (64 64 128)
*)
procedure misc_satellite_dish_think(self: edict_p); cdecl;
begin
  Inc(self.s.frame);
  if self.s.frame < 38 then
    self.nextthink := level.time + FRAMETIME;
end;

procedure misc_satellite_dish_use(self, other, activator: edict_p); cdecl;
begin
  self.s.frame := 0;
  self.think := misc_satellite_dish_think;
  self.nextthink := level.time + FRAMETIME;
end;

procedure SP_misc_satellite_dish(ent: edict_p); cdecl;
begin
  ent.movetype := MOVETYPE_NONE;
  ent.solid := SOLID_BBOX;
  VectorSet(ent.mins, -64, -64, 0);
  VectorSet(ent.maxs, 64, 64, 128);
  ent.s.modelindex := gi.modelindex('models/objects/satellite/tris.md2');
  ent.use := misc_satellite_dish_use;
  gi.linkentity(ent);
end;


(*QUAKED light_mine1 (0 1 0) (-2 -2 -12) (2 2 12)
*)
procedure SP_light_mine1(ent: edict_p); cdecl;
begin
  ent.movetype := MOVETYPE_NONE;
  ent.solid := SOLID_BBOX;
  ent.s.modelindex := gi.modelindex('models/objects/minelite/light1/tris.md2');
  gi.linkentity(ent);
end;


(*QUAKED light_mine2 (0 1 0) (-2 -2 -12) (2 2 12)
*)
procedure SP_light_mine2(ent: edict_p); cdecl;
begin
  ent.movetype := MOVETYPE_NONE;
  ent.solid := SOLID_BBOX;
  ent.s.modelindex := gi.modelindex('models/objects/minelite/light2/tris.md2');
  gi.linkentity(ent);
end;


(*QUAKED misc_gib_arm (1 0 0) (-8 -8 -8) (8 8 8)
Intended for use with the target_spawner
*)
procedure SP_misc_gib_arm(ent: edict_p); cdecl;
begin
  gi.setmodel(ent, 'models/objects/gibs/arm/tris.md2');
  ent.solid := SOLID_NOT;
  ent.s.effects := ent.s.effects OR EF_GIB;
  ent.takedamage := DAMAGE_YES;
  ent.die := gib_die;
  ent.movetype := MOVETYPE_TOSS;
  ent.svflags := ent.svflags OR SVF_MONSTER;
  ent.deadflag := DEAD_DEAD;
  ent.avelocity[0] := _random()*200;
  ent.avelocity[1] := _random()*200;
  ent.avelocity[2] := _random()*200;
  ent.think := G_FreeEdict;
  ent.nextthink := level.time + 30;
  gi.linkentity (ent);
end;

(*QUAKED misc_gib_leg (1 0 0) (-8 -8 -8) (8 8 8)
Intended for use with the target_spawner
*)
procedure SP_misc_gib_leg(ent: edict_p); cdecl;
begin
  gi.setmodel (ent, 'models/objects/gibs/leg/tris.md2');
  ent.solid := SOLID_NOT;
  ent.s.effects := ent.s.effects OR EF_GIB;
  ent.takedamage := DAMAGE_YES;
  ent.die := gib_die;
  ent.movetype := MOVETYPE_TOSS;
  ent.svflags := ent.svflags OR SVF_MONSTER;
  ent.deadflag := DEAD_DEAD;
  ent.avelocity[0] := _random()*200;
  ent.avelocity[1] := _random()*200;
  ent.avelocity[2] := _random()*200;
  ent.think := G_FreeEdict;
  ent.nextthink := level.time + 30;
  gi.linkentity (ent);
end;

(*QUAKED misc_gib_head (1 0 0) (-8 -8 -8) (8 8 8)
Intended for use with the target_spawner
*)
procedure SP_misc_gib_head(ent: edict_p); cdecl;
begin
  gi.setmodel (ent, 'models/objects/gibs/head/tris.md2');
  ent.solid := SOLID_NOT;
  ent.s.effects := ent.s.effects OR EF_GIB;
  ent.takedamage := DAMAGE_YES;
  ent.die := gib_die;
  ent.movetype := MOVETYPE_TOSS;
  ent.svflags := ent.svflags OR SVF_MONSTER;
  ent.deadflag := DEAD_DEAD;
  ent.avelocity[0] := _random()*200;
  ent.avelocity[1] := _random()*200;
  ent.avelocity[2] := _random()*200;
  ent.think := G_FreeEdict;
  ent.nextthink := level.time + 30;
  gi.linkentity (ent);
end;

//============================

(*QUAKED target_character (0 0 1) ?
used with target_string (must be on same 'team')
'count' is position in the string (starts at 1)
*)

procedure SP_target_character(self: edict_p); cdecl;
begin
  self.movetype := MOVETYPE_PUSH;
  gi.setmodel (self, self.model);
  self.solid := SOLID_BSP;
  self.s.frame := 12;
  gi.linkentity (self);
  exit;
end;


(*QUAKED target_string (0 0 1) (-8 -8 -8) (8 8 8)
*)

procedure target_string_use(self, other, activator: edict_p); cdecl;
Var e: edict_p; n, l: Integer; c: Char;
begin
  l := strlen(self._message);
  e := self.teammaster;
  while e<>Nil do begin
    if e.count = 0 then begin
      e := e.teamchain;
      continue;
    end;
    n := e.count - 1;
    if n > l then begin
      e.s.frame := 12;
      e := e.teamchain;
      continue;
    end;

    c := self._message[n];
    if (c >= '0') and (c <= '9') then
      e.s.frame := Ord(c) - Ord('0')
    else if (c = '-') then
      e.s.frame := 10
    else if (c = ':') then
      e.s.frame := 11
    else
      e.s.frame := 12;

    e := e.teamchain;
  end;
end;

procedure SP_target_string(self: edict_p); cdecl;
begin
  if self._message = Nil then
    self._message := '';
  self.use := target_string_use;
end;


(*QUAKED func_clock (0 0 1) (-8 -8 -8) (8 8 8) TIMER_UP TIMER_DOWN START_OFF MULTI_USE
target a target_string with this

The default is to be a time of day clock

TIMER_UP and TIMER_DOWN run for 'count' seconds and the fire 'pathtarget'
If START_OFF, this entity must be used before it starts

'style'    0 'xx'
      1 'xx:xx'
      2 'xx:xx:xx'
*)

Const
  CLOCK_MESSAGE_SIZE = 16;

// don't let field width of any clock messages change, or it
// could cause an overwrite after a game load

// CAK - static, so don't put in interface
procedure func_clock_reset(self: edict_p);
begin
  self.activator := Nil;
  if (self.spawnflags AND 1)>0 then begin
    self.health := 0;
    self.wait := self.count;
  end else if (self.spawnflags AND 2)>0 then begin
    self.health := self.count;
    self.wait := 0;
  end;
end;

// CAK - static, so don't put in interface
procedure func_clock_format_countdown(self: edict_p);
begin
  if self.style = 0 then begin
    Com_sprintf(self._message, CLOCK_MESSAGE_SIZE, '%2i', [self.health]);
    exit;
  end;

  if self.style = 1 then begin
    Com_sprintf(self._message, CLOCK_MESSAGE_SIZE, '%2i:%2i', [self.health div 60, self.health mod 60]);
    if self._message[3] = ' ' then
      self._message[3] := '0';
    exit;
  end;

  if self.style = 2 then begin
    Com_sprintf(self._message, CLOCK_MESSAGE_SIZE, '%2i:%2i:%2i', [self.health div 3600, (self.health - (self.health div 3600) * 3600) div 60, self.health mod 60]);
    if self._message[3] = ' ' then
      self._message[3] := '0';
    if self._message[6] = ' ' then
      self._message[6] := '0';
    exit;
  end;
end;

procedure func_clock_think(self: edict_p); cdecl;
Var ltime: TDateTime; Year, Month, Day, Hour, Minute, Second, MilliSecond: Word;
savetarget, savemessage: PChar;
begin
  if self.enemy = Nil then begin
    self.enemy := G_Find(Nil, FOFS_targetname, self.target);
    if self.enemy = Nil then
      exit;
  end;

  if (self.spawnflags AND 1)>0 then begin
    func_clock_format_countdown(self);
    inc(self.health);
  end else if (self.spawnflags AND 2)>0 then begin
    func_clock_format_countdown(self);
    dec(self.health);
  end else begin
    ltime := time();
    DecodeDateTime(ltime, Year, Month, Day, Hour, Minute, Second, MilliSecond);
    Com_sprintf(self._message, CLOCK_MESSAGE_SIZE, '%2i:%2i:%2i', [Hour, Minute, Second]);
    if self._message[3] = ' ' then
      self._message[3] := '0';
    if self._message[6] = ' ' then
      self._message[6] := '0'
  end;

  self.enemy._message := self._message;
  self.enemy.use(self.enemy, self, self);

  if (((self.spawnflags AND 1)>0) and (self.health > self.wait))
  or (((self.spawnflags AND 2)>0) and (self.health < self.wait)) then begin
    if self.pathtarget<>Nil then begin
      savetarget := self.target;
      savemessage := self._message;
      self.target := self.pathtarget;
      self._message := Nil;
      G_UseTargets(self, self.activator);
      self.target := savetarget;
      self._message := savemessage;
    end;

    if (self.spawnflags AND 8)=0 then
      exit;

    func_clock_reset (self);

    if (self.spawnflags AND 4)>0 then
      exit;
  end;

  self.nextthink := level.time + 1;
end;

procedure func_clock_use(self, other, activator: edict_p); cdecl;
begin
  if (self.spawnflags AND 8)=0 then
    self.use := Nil;
  if self.activator<>Nil then
    exit;
  self.activator := activator;
  self.think(self);
end;

procedure SP_func_clock(self: edict_p); cdecl;
begin
  if self.target = Nil then begin
    gi_dprintf('%s with no target at %s'#10, [self.classname, vtos(self.s.origin)]);
    G_FreeEdict(self);
    exit;
  end;

  if ((self.spawnflags AND 2)>0) and (self.count=0) then begin
    gi_dprintf('%s with no count at %s'#10, [self.classname, vtos(self.s.origin)]);
    G_FreeEdict(self);
    exit;
  end;

  if ((self.spawnflags AND 1)>0) and (self.count=0) then
    self.count := 60*60;;

  func_clock_reset(self);

  self._message := gi.TagMalloc(CLOCK_MESSAGE_SIZE, TAG_LEVEL);

  self.think := func_clock_think;

  if (self.spawnflags AND 4)>0 then
    self.use := func_clock_use
  else
    self.nextthink := level.time + 1;
end;

//=========================================

procedure teleporter_touch(self, other: edict_p; plane: cplane_p; surf: csurface_p); cdecl;
Var dest: edict_p; i: Integer;
begin
  if other.client=Nil then
    exit;
  dest := G_Find(Nil, FOFS_targetname, self.target);
  if dest = Nil then begin
    gi.dprintf('Couldn''t find destination'#10);
    exit;
  end;

{$IFDEF CTF}
//ZOID
  CTFPlayerResetGrapple(other);
//ZOID
{$ENDIF}

  // unlink to make sure it can't possibly interfere with KillBox
  gi.unlinkentity(other);

  VectorCopy(dest.s.origin, other.s.origin);
  VectorCopy(dest.s.origin, other.s.old_origin);
  other.s.origin[2] := other.s.origin[2] + 10;

  // clear the velocity and hold them in place briefly
  VectorClear(other.velocity);
  other.client.ps.pmove.pm_time := 160 shr 3;    // hold time
  other.client.ps.pmove.pm_flags := other.client.ps.pmove.pm_flags OR PMF_TIME_TELEPORT;

  // draw the teleport splash at source and on the player
  self.owner.s.event := EV_PLAYER_TELEPORT;
  other.s.event := EV_PLAYER_TELEPORT;

  // set angles
  for i:=0 to 2 do begin
    other.client.ps.pmove.delta_angles[i] := ANGLE2SHORT(dest.s.angles[i] - other.client.resp.cmd_angles[i]);
  end;

  VectorClear(other.s.angles);
  VectorClear(other.client.ps.viewangles);
  VectorClear(other.client.v_angle);

  // kill anything at the destination
  KillBox(other);

  gi.linkentity(other);
end;

(*QUAKED misc_teleporter (1 0 0) (-32 -32 -24) (32 32 -16)
Stepping onto this disc will teleport players to the targeted misc_teleporter_dest object.
*)
procedure SP_misc_teleporter(ent: edict_p); cdecl;
Var trig: edict_p;
begin
  if ent.target = Nil then begin
    gi.dprintf('teleporter without a target.'#10);
    G_FreeEdict(ent);
    exit;
  end;

  gi.setmodel(ent, 'models/objects/dmspot/tris.md2');
  ent.s.skinnum := 1;
  ent.s.effects := EF_TELEPORTER;
  ent.s.sound := gi.soundindex('world/amb10.wav');
  ent.solid := SOLID_BBOX;

  VectorSet(ent.mins, -32, -32, -24);
  VectorSet(ent.maxs, 32, 32, -16);
  gi.linkentity(ent);

  trig := G_Spawn();
  trig.touch := teleporter_touch;
  trig.solid := SOLID_TRIGGER;
  trig.target := ent.target;
  trig.owner := ent;
  VectorCopy(ent.s.origin, trig.s.origin);
  VectorSet(trig.mins, -8, -8, 8);
  VectorSet(trig.maxs, 8, 8, 24);
  gi.linkentity(trig);
end;

(*QUAKED misc_teleporter_dest (1 0 0) (-32 -32 -24) (32 32 -16)
Point teleporters at these.
*)
procedure SP_misc_teleporter_dest(ent: edict_p); cdecl;
begin
  gi.setmodel(ent, 'models/objects/dmspot/tris.md2');
  ent.s.skinnum := 0;
  ent.solid := SOLID_BBOX;
//  ent.s.effects := ent.s.effects OR EF_FLIES;
  VectorSet(ent.mins, -32, -32, -24);
  VectorSet(ent.maxs, 32, 32, -16);
  gi.linkentity(ent);
end;


end.

⌨️ 快捷键说明

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