home *** CD-ROM | disk | FTP | other *** search
/ Gambler 19 / GAMBLERCD19.BIN / UTILS / 3D / BRONIE / DUAL_LAU.ZIP / src / g_misc.c < prev    next >
C/C++ Source or Header  |  1998-01-13  |  46KB  |  1,854 lines

  1. // g_misc.c
  2.  
  3. #include "g_local.h"
  4.  
  5.  
  6. /*QUAKED func_group (0 0 0) ?
  7. Used to group brushes together just for editor convenience.
  8. */
  9.  
  10. //=====================================================
  11.  
  12. void Use_Areaportal (edict_t *ent, edict_t *other, edict_t *activator)
  13. {
  14.     ent->count ^= 1;        // toggle state
  15. //    gi.dprintf ("portalstate: %i = %i\n", ent->style, ent->count);
  16.     gi.SetAreaPortalState (ent->style, ent->count);
  17. }
  18.  
  19. /*QUAKED func_areaportal (0 0 0) ?
  20.  
  21. This is a non-visible object that divides the world into
  22. areas that are seperated when this portal is not activated.
  23. Usually enclosed in the middle of a door.
  24. */
  25. void SP_func_areaportal (edict_t *ent)
  26. {
  27.     ent->use = Use_Areaportal;
  28.     ent->count = 0;        // allways start closed;
  29. }
  30.  
  31. //=====================================================
  32.  
  33.  
  34. /*
  35. =================
  36. Misc functions
  37. =================
  38. */
  39. void VelocityForDamage (int damage, vec3_t v)
  40. {
  41.     v[0] = 100.0 * crandom();
  42.     v[1] = 100.0 * crandom();
  43.     v[2] = 200.0 + 100.0 * random();
  44.  
  45.     if (damage < 50)
  46.         VectorScale (v, 0.7, v);
  47.     else 
  48.         VectorScale (v, 1.2, v);
  49. }
  50.  
  51. void ClipGibVelocity (edict_t *ent)
  52. {
  53.     if (ent->velocity[0] < -300)
  54.         ent->velocity[0] = -300;
  55.     else if (ent->velocity[0] > 300)
  56.         ent->velocity[0] = 300;
  57.     if (ent->velocity[1] < -300)
  58.         ent->velocity[1] = -300;
  59.     else if (ent->velocity[1] > 300)
  60.         ent->velocity[1] = 300;
  61.     if (ent->velocity[2] < 200)
  62.         ent->velocity[2] = 200;    // always some upwards
  63.     else if (ent->velocity[2] > 500)
  64.         ent->velocity[2] = 500;
  65. }
  66.  
  67.  
  68. /*
  69. =================
  70. gibs
  71. =================
  72. */
  73. void gib_think (edict_t *self)
  74. {
  75.     self->s.frame++;
  76.     self->nextthink = level.time + FRAMETIME;
  77.  
  78.     if (self->s.frame == 10)
  79.     {
  80.         self->think = G_FreeEdict;
  81.         self->nextthink = level.time + 8 + random()*10;
  82.     }
  83. }
  84.  
  85. void gib_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  86. {
  87.     vec3_t    normal_angles, right;
  88.  
  89.     if (!self->groundentity)
  90.         return;
  91.  
  92.     self->touch = NULL;
  93.  
  94.     if (plane)
  95.     {
  96.         gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/fhit3.wav"), 1, ATTN_NORM, 0);
  97.  
  98.         vectoangles (plane->normal, normal_angles);
  99.         AngleVectors (normal_angles, NULL, right, NULL);
  100.         vectoangles (right, self->s.angles);
  101.  
  102.         if (self->s.modelindex == sm_meat_index)
  103.         {
  104.             self->s.frame++;
  105.             self->think = gib_think;
  106.             self->nextthink = level.time + FRAMETIME;
  107.         }
  108.     }
  109. }
  110.  
  111. void gib_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  112. {
  113.     G_FreeEdict (self);
  114. }
  115.  
  116. void ThrowGib (edict_t *self, char *gibname, int damage, int type)
  117. {
  118.     edict_t *gib;
  119.     vec3_t    vd;
  120.     vec3_t    origin;
  121.     vec3_t    size;
  122.     float    vscale;
  123.  
  124.     gib = G_Spawn();
  125.  
  126.     VectorScale (self->size, 0.5, size);
  127.     VectorAdd (self->absmin, size, origin);
  128.     gib->s.origin[0] = origin[0] + crandom() * size[0];
  129.     gib->s.origin[1] = origin[1] + crandom() * size[1];
  130.     gib->s.origin[2] = origin[2] + crandom() * size[2];
  131.  
  132.     gi.setmodel (gib, gibname);
  133.     gib->solid = SOLID_NOT;
  134.     gib->s.effects |= EF_GIB;
  135.     gib->flags |= FL_NO_KNOCKBACK;
  136.     gib->takedamage = DAMAGE_YES;
  137.     gib->die = gib_die;
  138.  
  139.     if (type == GIB_ORGANIC)
  140.     {
  141.         gib->movetype = MOVETYPE_TOSS;
  142.         gib->touch = gib_touch;
  143.         vscale = 0.5;
  144.     }
  145.     else
  146.     {
  147.         gib->movetype = MOVETYPE_BOUNCE;
  148.         vscale = 1.0;
  149.     }
  150.  
  151.     VelocityForDamage (damage, vd);
  152.     VectorMA (self->velocity, vscale, vd, gib->velocity);
  153.     ClipGibVelocity (gib);
  154.     gib->avelocity[0] = random()*600;
  155.     gib->avelocity[1] = random()*600;
  156.     gib->avelocity[2] = random()*600;
  157.  
  158.     gib->think = G_FreeEdict;
  159.     gib->nextthink = level.time + 10 + random()*10;
  160.  
  161.     gi.linkentity (gib);
  162. }
  163.  
  164. void ThrowHead (edict_t *self, char *gibname, int damage, int type)
  165. {
  166.     vec3_t    vd;
  167.     float    vscale;
  168.  
  169.     self->s.skinnum = 0;
  170.     self->s.frame = 0;
  171.     VectorClear (self->mins);
  172.     VectorClear (self->maxs);
  173.  
  174.     self->s.modelindex2 = 0;
  175.     gi.setmodel (self, gibname);
  176.     self->solid = SOLID_NOT;
  177.     self->s.effects |= EF_GIB;
  178.     self->s.effects &= ~EF_FLIES;
  179.     self->s.sound = 0;
  180.     self->flags |= FL_NO_KNOCKBACK;
  181.     self->svflags &= ~SVF_MONSTER;
  182.     self->takedamage = DAMAGE_YES;
  183.     self->die = gib_die;
  184.  
  185.     if (type == GIB_ORGANIC)
  186.     {
  187.         self->movetype = MOVETYPE_TOSS;
  188.         self->touch = gib_touch;
  189.         vscale = 0.5;
  190.     }
  191.     else
  192.     {
  193.         self->movetype = MOVETYPE_BOUNCE;
  194.         vscale = 1.0;
  195.     }
  196.  
  197.     VelocityForDamage (damage, vd);
  198.     VectorMA (self->velocity, vscale, vd, self->velocity);
  199.     ClipGibVelocity (self);
  200.  
  201.     self->avelocity[YAW] = crandom()*600;
  202.  
  203.     self->think = G_FreeEdict;
  204.     self->nextthink = level.time + 10 + random()*10;
  205.  
  206.     gi.linkentity (self);
  207. }
  208.  
  209.  
  210. void ThrowClientHead (edict_t *self, int damage)
  211. {
  212.     vec3_t    vd;
  213.     char    *gibname;
  214.  
  215.     if (rand()&1)
  216.     {
  217.         gibname = "models/objects/gibs/head2/tris.md2";
  218.         self->s.skinnum = 1;        // second skin is player
  219.     }
  220.     else
  221.     {
  222.         gibname = "models/objects/gibs/skull/tris.md2";
  223.         self->s.skinnum = 0;
  224.     }
  225.  
  226.     self->s.origin[2] += 32;
  227.     self->s.frame = 0;
  228.     gi.setmodel (self, gibname);
  229.     VectorSet (self->mins, -16, -16, 0);
  230.     VectorSet (self->maxs, 16, 16, 16);
  231.  
  232.     self->takedamage = DAMAGE_NO;
  233.     self->solid = SOLID_NOT;
  234.     self->s.effects = EF_GIB;
  235.     self->s.sound = 0;
  236.     self->flags |= FL_NO_KNOCKBACK;
  237.  
  238.     self->movetype = MOVETYPE_BOUNCE;
  239.     VelocityForDamage (damage, vd);
  240.     VectorAdd (self->velocity, vd, self->velocity);
  241.  
  242.     gi.linkentity (self);
  243. }
  244.  
  245.  
  246. /*
  247. =================
  248. debris
  249. =================
  250. */
  251. void debris_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  252. {
  253.     G_FreeEdict (self);
  254. }
  255.  
  256. void ThrowDebris (edict_t *self, char *modelname, float speed, vec3_t origin)
  257. {
  258.     edict_t    *chunk;
  259.     vec3_t    v;
  260.  
  261.     chunk = G_Spawn();
  262.     VectorCopy (origin, chunk->s.origin);
  263.     gi.setmodel (chunk, modelname);
  264.     v[0] = 100 * crandom();
  265.     v[1] = 100 * crandom();
  266.     v[2] = 100 + 100 * crandom();
  267.     VectorMA (self->velocity, speed, v, chunk->velocity);
  268.     chunk->movetype = MOVETYPE_BOUNCE;
  269.     chunk->solid = SOLID_NOT;
  270.     chunk->avelocity[0] = random()*600;
  271.     chunk->avelocity[1] = random()*600;
  272.     chunk->avelocity[2] = random()*600;
  273.     chunk->think = G_FreeEdict;
  274.     chunk->nextthink = level.time + 5 + random()*5;
  275.     chunk->s.frame = 0;
  276.     chunk->flags = 0;
  277.     chunk->classname = "debris";
  278.     chunk->takedamage = DAMAGE_YES;
  279.     chunk->die = debris_die;
  280.     gi.linkentity (chunk);
  281. }
  282.  
  283.  
  284. void BecomeExplosion1 (edict_t *self)
  285. {
  286.     gi.WriteByte (svc_temp_entity);
  287.     gi.WriteByte (TE_EXPLOSION1);
  288.     gi.WritePosition (self->s.origin);
  289.     gi.multicast (self->s.origin, MULTICAST_PVS);
  290.  
  291.     G_FreeEdict (self);
  292. }
  293.  
  294.  
  295. void BecomeExplosion2 (edict_t *self)
  296. {
  297.     gi.WriteByte (svc_temp_entity);
  298.     gi.WriteByte (TE_EXPLOSION2);
  299.     gi.WritePosition (self->s.origin);
  300.     gi.multicast (self->s.origin, MULTICAST_PVS);
  301.  
  302.     G_FreeEdict (self);
  303. }
  304.  
  305.  
  306. /*QUAKED path_corner (.5 .3 0) (-8 -8 -8) (8 8 8) TELEPORT
  307. Target: next path corner
  308. Pathtarget: gets used when an entity that has
  309.     this path_corner targeted touches it
  310. */
  311.  
  312. void path_corner_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  313. {
  314.     vec3_t        v;
  315.     edict_t        *next;
  316.  
  317.     if (other->movetarget != self)
  318.         return;
  319.     
  320.     if (other->enemy)
  321.         return;
  322.  
  323.     if (self->pathtarget)
  324.     {
  325.         char *savetarget;
  326.  
  327.         savetarget = self->target;
  328.         self->target = self->pathtarget;
  329.         G_UseTargets (self, other);
  330.         self->target = savetarget;
  331.     }
  332.  
  333.     if (self->target)
  334.         next = G_PickTarget(self->target);
  335.     else
  336.         next = NULL;
  337.  
  338.     if ((next) && (next->spawnflags & 1))
  339.     {
  340.         VectorCopy (next->s.origin, v);
  341.         v[2] += next->mins[2];
  342.         v[2] -= other->mins[2];
  343.         VectorCopy (v, other->s.origin);
  344.         next = G_PickTarget(next->target);
  345.     }
  346.  
  347.     other->goalentity = other->movetarget = next;
  348.  
  349.     if (self->wait)
  350.     {
  351.         other->monsterinfo.pausetime = level.time + self->wait;
  352.         other->monsterinfo.stand (other);
  353.         return;
  354.     }
  355.  
  356.     if (!other->movetarget)
  357.     {
  358.         other->monsterinfo.pausetime = level.time + 100000000;
  359.         other->monsterinfo.stand (other);
  360.     }
  361.     else
  362.     {
  363.         VectorSubtract (other->goalentity->s.origin, other->s.origin, v);
  364.         other->ideal_yaw = vectoyaw (v);
  365.     }
  366. }
  367.  
  368. void SP_path_corner (edict_t *self)
  369. {
  370.     if (!self->targetname)
  371.     {
  372.         gi.dprintf ("path_corner with no targetname at %s\n", vtos(self->s.origin));
  373.         G_FreeEdict (self);
  374.         return;
  375.     }
  376.  
  377.     self->solid = SOLID_TRIGGER;
  378.     self->touch = path_corner_touch;
  379.     VectorSet (self->mins, -8, -8, -8);
  380.     VectorSet (self->maxs, 8, 8, 8);
  381.     self->svflags |= SVF_NOCLIENT;
  382.     gi.linkentity (self);
  383. }
  384.  
  385.  
  386. /*QUAKED point_combat (0.5 0.3 0) (-8 -8 -8) (8 8 8) Hold
  387. Makes this the target of a monster and it will head here
  388. when first activated before going after the activator.  If
  389. hold is selected, it will stay here.
  390. */
  391. void point_combat_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  392. {
  393.     edict_t    *activator;
  394.  
  395.     if (other->movetarget != self)
  396.         return;
  397.  
  398.     if (self->target)
  399.     {
  400.         other->target = self->target;
  401.         other->goalentity = other->movetarget = G_PickTarget(other->target);
  402.         if (!other->goalentity)
  403.         {
  404.             gi.dprintf("%s at %s target %s does not exist\n", self->classname, vtos(self->s.origin), self->target);
  405.             other->movetarget = self;
  406.         }
  407.         self->target = NULL;
  408.     }
  409.     else if ((self->spawnflags & 1) && !(self->flags & (FL_SWIM|FL_FLY)))
  410.     {
  411.         other->monsterinfo.pausetime = level.time + 100000000;
  412.         other->monsterinfo.aiflags |= AI_STAND_GROUND;
  413.         other->monsterinfo.stand (other);
  414.     }
  415.  
  416.     if (other->movetarget == self)
  417.     {
  418.         other->target = NULL;
  419.         other->movetarget = NULL;
  420.         other->goalentity = other->enemy;
  421.         other->monsterinfo.aiflags &= ~AI_COMBAT_POINT;
  422.     }
  423.  
  424.     if (self->pathtarget)
  425.     {
  426.         char *savetarget;
  427.  
  428.         savetarget = self->target;
  429.         self->target = self->pathtarget;
  430.         if (other->enemy && other->enemy->client)
  431.             activator = other->enemy;
  432.         else if (other->oldenemy && other->oldenemy->client)
  433.             activator = other->oldenemy;
  434.         else if (other->activator && other->activator->client)
  435.             activator = other->activator;
  436.         else
  437.             activator = other;
  438.         G_UseTargets (self, activator);
  439.         self->target = savetarget;
  440.     }
  441. }
  442.  
  443. void SP_point_combat (edict_t *self)
  444. {
  445.     self->solid = SOLID_TRIGGER;
  446.     self->touch = point_combat_touch;
  447.     VectorSet (self->mins, -8, -8, -16);
  448.     VectorSet (self->maxs, 8, 8, 16);
  449.     self->svflags = SVF_NOCLIENT;
  450.     gi.linkentity (self);
  451. }
  452.  
  453.  
  454. /*QUAKED viewthing (0 .5 .8) (-8 -8 -8) (8 8 8)
  455. Just for the debugging level.  Don't use
  456. */
  457. static int robotron[4];
  458.  
  459. void TH_viewthing(edict_t *ent)
  460. {
  461.     ent->s.frame = (ent->s.frame + 1) % 7;
  462. //    ent->s.frame = (ent->s.frame + 1) % 9;
  463.     ent->nextthink = level.time + FRAMETIME;
  464. //    return;
  465.  
  466.     if (ent->spawnflags)
  467.     {
  468.         if (ent->s.frame == 0)
  469.         {
  470.             ent->spawnflags = (ent->spawnflags + 1) % 4 + 1;
  471.             ent->s.modelindex = robotron[ent->spawnflags - 1];
  472.         }
  473.     }
  474. }
  475.  
  476. void SP_viewthing(edict_t *ent)
  477. {
  478.     gi.dprintf ("viewthing spawned\n");
  479.  
  480.     ent->movetype = MOVETYPE_NONE;
  481.     ent->solid = SOLID_BBOX;
  482.     ent->s.renderfx = RF_FRAMELERP;
  483.     VectorSet (ent->mins, -16, -16, -24);
  484.     VectorSet (ent->maxs, 16, 16, 32);
  485. //    ent->s.modelindex = gi.modelindex ("models/player_y/tris.md2");
  486.     ent->s.modelindex = gi.modelindex ("models/objects/banner/tris.md2");
  487.     gi.linkentity (ent);
  488.     ent->nextthink = level.time + 0.5;
  489.     ent->think = TH_viewthing;
  490.     return;
  491. }
  492.  
  493.  
  494. /*QUAKED info_null (0 0.5 0) (-4 -4 -4) (4 4 4)
  495. Used as a positional target for spotlights, etc.
  496. */
  497. void SP_info_null (edict_t *self)
  498. {
  499.     G_FreeEdict (self);
  500. }
  501.  
  502.  
  503. /*QUAKED info_notnull (0 0.5 0) (-4 -4 -4) (4 4 4)
  504. Used as a positional target for lightning.
  505. */
  506. void SP_info_notnull (edict_t *self)
  507. {
  508.     VectorCopy (self->s.origin, self->absmin);
  509.     VectorCopy (self->s.origin, self->absmax);
  510. }
  511.  
  512.  
  513. /*QUAKED light (0 1 0) (-8 -8 -8) (8 8 8) START_OFF
  514. Non-displayed light.
  515. Default light value is 300.
  516. Default style is 0.
  517. If targeted, will toggle between on and off.
  518. Default _cone value is 10 (used to set size of light for spotlights)
  519. */
  520.  
  521. #define START_OFF    1
  522.  
  523. static void light_use (edict_t *self, edict_t *other, edict_t *activator)
  524. {
  525.     if (self->spawnflags & START_OFF)
  526.     {
  527.         gi.configstring (CS_LIGHTS+self->style, "m");
  528.         self->spawnflags &= ~START_OFF;
  529.     }
  530.     else
  531.     {
  532.         gi.configstring (CS_LIGHTS+self->style, "a");
  533.         self->spawnflags |= START_OFF;
  534.     }
  535. }
  536.  
  537. void SP_light (edict_t *self)
  538. {
  539.     // no targeted lights in deathmatch, because they cause global messages
  540.     if (!self->targetname || deathmatch->value)
  541.     {
  542.         G_FreeEdict (self);
  543.         return;
  544.     }
  545.  
  546.     if (self->style >= 32)
  547.     {
  548.         self->use = light_use;
  549.         if (self->spawnflags & START_OFF)
  550.             gi.configstring (CS_LIGHTS+self->style, "a");
  551.         else
  552.             gi.configstring (CS_LIGHTS+self->style, "m");
  553.     }
  554. }
  555.  
  556.  
  557. /*QUAKED func_wall (0 .5 .8) ? TRIGGER_SPAWN TOGGLE START_ON ANIMATED ANIMATED_FAST
  558. This is just a solid wall if not inhibited
  559.  
  560. TRIGGER_SPAWN    the wall will not be present until triggered
  561.                 it will then blink in to existance; it will
  562.                 kill anything that was in it's way
  563.  
  564. TOGGLE            only valid for TRIGGER_SPAWN walls
  565.                 this allows the wall to be turned on and off
  566.  
  567. START_ON        only valid for TRIGGER_SPAWN walls
  568.                 the wall will initially be present
  569. */
  570.  
  571. void func_wall_use (edict_t *self, edict_t *other, edict_t *activator)
  572. {
  573.     if (self->solid == SOLID_NOT)
  574.     {
  575.         self->solid = SOLID_BSP;
  576.         self->svflags &= ~SVF_NOCLIENT;
  577.         KillBox (self);
  578.     }
  579.     else
  580.     {
  581.         self->solid = SOLID_NOT;
  582.         self->svflags |= SVF_NOCLIENT;
  583.     }
  584.     gi.linkentity (self);
  585.  
  586.     if (!(self->spawnflags & 2))
  587.         self->use = NULL;
  588. }
  589.  
  590. void SP_func_wall (edict_t *self)
  591. {
  592.     self->movetype = MOVETYPE_PUSH;
  593.     gi.setmodel (self, self->model);
  594.  
  595.     if (self->spawnflags & 8)
  596.         self->s.effects |= EF_ANIM_ALL;
  597.     if (self->spawnflags & 16)
  598.         self->s.effects |= EF_ANIM_ALLFAST;
  599.  
  600.     // just a wall
  601.     if ((self->spawnflags & 7) == 0)
  602.     {
  603.         self->solid = SOLID_BSP;
  604.         gi.linkentity (self);
  605.         return;
  606.     }
  607.  
  608.     // it must be TRIGGER_SPAWN
  609.     if (!(self->spawnflags & 1))
  610.     {
  611. //        gi.dprintf("func_wall missing TRIGGER_SPAWN\n");
  612.         self->spawnflags |= 1;
  613.     }
  614.  
  615.     // yell if the spawnflags are odd
  616.     if (self->spawnflags & 4)
  617.     {
  618.         if (!(self->spawnflags & 2))
  619.         {
  620.             gi.dprintf("func_wall START_ON without TOGGLE\n");
  621.             self->spawnflags |= 2;
  622.         }
  623.     }
  624.  
  625.     self->use = func_wall_use;
  626.     if (self->spawnflags & 4)
  627.     {
  628.         self->solid = SOLID_BSP;
  629.     }
  630.     else
  631.     {
  632.         self->solid = SOLID_NOT;
  633.         self->svflags |= SVF_NOCLIENT;
  634.     }
  635.     gi.linkentity (self);
  636. }
  637.  
  638.  
  639. /*QUAKED func_object (0 .5 .8) ? TRIGGER_SPAWN ANIMATED ANIMATED_FAST
  640. This is solid bmodel that will fall if it's support it removed.
  641. */
  642.  
  643. void func_object_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  644. {
  645.     // only squash thing we fall on top of
  646.     if (!plane)
  647.         return;
  648.     if (plane->normal[2] < 1.0)
  649.         return;
  650.     if (other->takedamage == DAMAGE_NO)
  651.         return;
  652.     T_Damage (other, self, self, vec3_origin, self->s.origin, vec3_origin, self->dmg, 1, 0);
  653. }
  654.  
  655. void func_object_release (edict_t *self)
  656. {
  657.     self->movetype = MOVETYPE_TOSS;
  658.     self->touch = func_object_touch;
  659. }
  660.  
  661. void func_object_use (edict_t *self, edict_t *other, edict_t *activator)
  662. {
  663.     self->solid = SOLID_BSP;
  664.     self->svflags &= ~SVF_NOCLIENT;
  665.     self->use = NULL;
  666.     KillBox (self);
  667.     func_object_release (self);
  668. }
  669.  
  670. void SP_func_object (edict_t *self)
  671. {
  672.     gi.setmodel (self, self->model);
  673.  
  674.     self->mins[0] += 1;
  675.     self->mins[1] += 1;
  676.     self->mins[2] += 1;
  677.     self->maxs[0] -= 1;
  678.     self->maxs[1] -= 1;
  679.     self->maxs[2] -= 1;
  680.  
  681.     if (!self->dmg)
  682.         self->dmg = 100;
  683.  
  684.     if (self->spawnflags == 0)
  685.     {
  686.         self->solid = SOLID_BSP;
  687.         self->movetype = MOVETYPE_PUSH;
  688.         self->think = func_object_release;
  689.         self->nextthink = level.time + 2 * FRAMETIME;
  690.     }
  691.     else
  692.     {
  693.         self->solid = SOLID_NOT;
  694.         self->movetype = MOVETYPE_PUSH;
  695.         self->use = func_object_use;
  696.         self->svflags |= SVF_NOCLIENT;
  697.     }
  698.  
  699.     if (self->spawnflags & 2)
  700.         self->s.effects |= EF_ANIM_ALL;
  701.     if (self->spawnflags & 4)
  702.         self->s.effects |= EF_ANIM_ALLFAST;
  703.  
  704.     self->clipmask = MASK_MONSTERSOLID;
  705.  
  706.     gi.linkentity (self);
  707. }
  708.  
  709.  
  710. /*QUAKED func_explosive (0 .5 .8) ? Trigger_Spawn ANIMATED ANIMATED_FAST
  711. Any brush that you want to explode or break apart.  If you want an
  712. ex0plosion, set dmg and it will do a radius explosion of that amount
  713. at the center of the bursh.
  714.  
  715. If targeted it will not be shootable.
  716.  
  717. health defaults to 100.
  718.  
  719. mass defaults to 75.  This determines how much debris is emitted when
  720. it explodes.  You get one large chunk per 100 of mass (up to 8) and
  721. one small chunk per 25 of mass (up to 16).  So 800 gives the most.
  722. */
  723. void func_explosive_explode (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  724. {
  725.     vec3_t    origin;
  726.     vec3_t    chunkorigin;
  727.     vec3_t    size;
  728.     int        count;
  729.     int        mass;
  730.  
  731.     // bmodel origins are (0 0 0), we need to adjust that here
  732.     VectorScale (self->size, 0.5, size);
  733.     VectorAdd (self->absmin, size, origin);
  734.     VectorCopy (origin, self->s.origin);
  735.  
  736.     self->takedamage = DAMAGE_NO;
  737.  
  738.     if (self->dmg)
  739.         T_RadiusDamage (self, attacker, self->dmg, NULL, self->dmg+40);
  740.  
  741.     VectorSubtract (self->s.origin, inflictor->s.origin, self->velocity);
  742.     VectorNormalize (self->velocity);
  743.     VectorScale (self->velocity, 150, self->velocity);
  744.  
  745.     // start chunks towards the center
  746.     VectorScale (size, 0.5, size);
  747.  
  748.     mass = self->mass;
  749.     if (!mass)
  750.         mass = 75;
  751.  
  752.     // big chunks
  753.     if (mass >= 100)
  754.     {
  755.         count = mass / 100;
  756.         if (count > 8)
  757.             count = 8;
  758.         while(count--)
  759.         {
  760.             chunkorigin[0] = origin[0] + crandom() * size[0];
  761.             chunkorigin[1] = origin[1] + crandom() * size[1];
  762.             chunkorigin[2] = origin[2] + crandom() * size[2];
  763.             ThrowDebris (self, "models/objects/debris1/tris.md2", 1, chunkorigin);
  764.         }
  765.     }
  766.  
  767.     // small chunks
  768.     count = mass / 25;
  769.     if (count > 16)
  770.         count = 16;
  771.     while(count--)
  772.     {
  773.         chunkorigin[0] = origin[0] + crandom() * size[0];
  774.         chunkorigin[1] = origin[1] + crandom() * size[1];
  775.         chunkorigin[2] = origin[2] + crandom() * size[2];
  776.         ThrowDebris (self, "models/objects/debris2/tris.md2", 2, chunkorigin);
  777.     }
  778.  
  779.     G_UseTargets (self, attacker);
  780.  
  781.     if (self->dmg)
  782.         BecomeExplosion1 (self);
  783.     else
  784.         G_FreeEdict (self);
  785. }
  786.  
  787. void func_explosive_use(edict_t *self, edict_t *other, edict_t *activator)
  788. {
  789.     func_explosive_explode (self, self, other, self->health, vec3_origin);
  790. }
  791.  
  792. void func_explosive_spawn (edict_t *self, edict_t *other, edict_t *activator)
  793. {
  794.     self->solid = SOLID_BSP;
  795.     self->svflags &= ~SVF_NOCLIENT;
  796.     self->use = NULL;
  797.     KillBox (self);
  798.     gi.linkentity (self);
  799. }
  800.  
  801. void SP_func_explosive (edict_t *self)
  802. {
  803.     if (deathmatch->value)
  804.     {    // auto-remove for deathmatch
  805.         G_FreeEdict (self);
  806.         return;
  807.     }
  808.  
  809.     self->movetype = MOVETYPE_PUSH;
  810.  
  811.     gi.modelindex ("models/objects/debris1/tris.md2");
  812.     gi.modelindex ("models/objects/debris2/tris.md2");
  813.  
  814.     gi.setmodel (self, self->model);
  815.  
  816.     if (self->spawnflags & 1)
  817.     {
  818.         self->svflags |= SVF_NOCLIENT;
  819.         self->solid = SOLID_NOT;
  820.         self->use = func_explosive_spawn;
  821.     }
  822.     else
  823.     {
  824.         self->solid = SOLID_BSP;
  825.         if (self->targetname)
  826.             self->use = func_explosive_use;
  827.     }
  828.  
  829.     if (self->spawnflags & 2)
  830.         self->s.effects |= EF_ANIM_ALL;
  831.     if (self->spawnflags & 4)
  832.         self->s.effects |= EF_ANIM_ALLFAST;
  833.  
  834.     if (self->use != func_explosive_use)
  835.     {
  836.         if (!self->health)
  837.             self->health = 100;
  838.         self->die = func_explosive_explode;
  839.         self->takedamage = DAMAGE_YES;
  840.     }
  841.  
  842.     gi.linkentity (self);
  843. }
  844.  
  845.  
  846. /*QUAKED misc_explobox (0 .5 .8) (-16 -16 0) (16 16 40)
  847. Large exploding box.  You can override its mass (100),
  848. health (80), and dmg (150).
  849. */
  850.  
  851. void barrel_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  852.  
  853. {
  854.     float    ratio;
  855.     vec3_t    v;
  856.  
  857.     if ((!other->groundentity) || (other->groundentity == self))
  858.         return;
  859.  
  860.     ratio = (float)other->mass / (float)self->mass;
  861.     VectorSubtract (self->s.origin, other->s.origin, v);
  862.     M_walkmove (self, vectoyaw(v), 20 * ratio * FRAMETIME);
  863. }
  864.  
  865. void barrel_explode (edict_t *self)
  866. {
  867.     vec3_t    org;
  868.     float    spd;
  869.     vec3_t    save;
  870.  
  871.     T_RadiusDamage (self, self->activator, self->dmg, NULL, self->dmg+40);
  872.  
  873.     VectorCopy (self->s.origin, save);
  874.     VectorMA (self->absmin, 0.5, self->size, self->s.origin);
  875.  
  876.     // a few big chunks
  877.     spd = 1.5 * (float)self->dmg / 200.0;
  878.     org[0] = self->s.origin[0] + crandom() * self->size[0];
  879.     org[1] = self->s.origin[1] + crandom() * self->size[1];
  880.     org[2] = self->s.origin[2] + crandom() * self->size[2];
  881.     ThrowDebris (self, "models/objects/debris1/tris.md2", spd, org);
  882.     org[0] = self->s.origin[0] + crandom() * self->size[0];
  883.     org[1] = self->s.origin[1] + crandom() * self->size[1];
  884.     org[2] = self->s.origin[2] + crandom() * self->size[2];
  885.     ThrowDebris (self, "models/objects/debris1/tris.md2", spd, org);
  886.  
  887.     // bottom corners
  888.     spd = 1.75 * (float)self->dmg / 200.0;
  889.     VectorCopy (self->absmin, org);
  890.     ThrowDebris (self, "models/objects/debris3/tris.md2", spd, org);
  891.     VectorCopy (self->absmin, org);
  892.     org[0] += self->size[0];
  893.     ThrowDebris (self, "models/objects/debris3/tris.md2", spd, org);
  894.     VectorCopy (self->absmin, org);
  895.     org[1] += self->size[1];
  896.     ThrowDebris (self, "models/objects/debris3/tris.md2", spd, org);
  897.     VectorCopy (self->absmin, org);
  898.     org[0] += self->size[0];
  899.     org[1] += self->size[1];
  900.     ThrowDebris (self, "models/objects/debris3/tris.md2", spd, org);
  901.  
  902.     // a bunch of little chunks
  903.     spd = 2 * self->dmg / 200;
  904.     org[0] = self->s.origin[0] + crandom() * self->size[0];
  905.     org[1] = self->s.origin[1] + crandom() * self->size[1];
  906.     org[2] = self->s.origin[2] + crandom() * self->size[2];
  907.     ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
  908.     org[0] = self->s.origin[0] + crandom() * self->size[0];
  909.     org[1] = self->s.origin[1] + crandom() * self->size[1];
  910.     org[2] = self->s.origin[2] + crandom() * self->size[2];
  911.     ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
  912.     org[0] = self->s.origin[0] + crandom() * self->size[0];
  913.     org[1] = self->s.origin[1] + crandom() * self->size[1];
  914.     org[2] = self->s.origin[2] + crandom() * self->size[2];
  915.     ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
  916.     org[0] = self->s.origin[0] + crandom() * self->size[0];
  917.     org[1] = self->s.origin[1] + crandom() * self->size[1];
  918.     org[2] = self->s.origin[2] + crandom() * self->size[2];
  919.     ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
  920.     org[0] = self->s.origin[0] + crandom() * self->size[0];
  921.     org[1] = self->s.origin[1] + crandom() * self->size[1];
  922.     org[2] = self->s.origin[2] + crandom() * self->size[2];
  923.     ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
  924.     org[0] = self->s.origin[0] + crandom() * self->size[0];
  925.     org[1] = self->s.origin[1] + crandom() * self->size[1];
  926.     org[2] = self->s.origin[2] + crandom() * self->size[2];
  927.     ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
  928.     org[0] = self->s.origin[0] + crandom() * self->size[0];
  929.     org[1] = self->s.origin[1] + crandom() * self->size[1];
  930.     org[2] = self->s.origin[2] + crandom() * self->size[2];
  931.     ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
  932.     org[0] = self->s.origin[0] + crandom() * self->size[0];
  933.     org[1] = self->s.origin[1] + crandom() * self->size[1];
  934.     org[2] = self->s.origin[2] + crandom() * self->size[2];
  935.     ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
  936.  
  937.     VectorCopy (save, self->s.origin);
  938.     if (self->groundentity)
  939.         BecomeExplosion2 (self);
  940.     else
  941.         BecomeExplosion1 (self);
  942. }
  943.  
  944. void barrel_delay (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  945. {
  946.     self->takedamage = DAMAGE_NO;
  947.     self->nextthink = level.time + 2 * FRAMETIME;
  948.     self->think = barrel_explode;
  949.     self->activator = attacker;
  950. }
  951.  
  952. void SP_misc_explobox (edict_t *self)
  953. {
  954.     if (deathmatch->value)
  955.     {    // auto-remove for deathmatch
  956.         G_FreeEdict (self);
  957.         return;
  958.     }
  959.  
  960.     gi.modelindex ("models/objects/debris1/tris.md2");
  961.     gi.modelindex ("models/objects/debris2/tris.md2");
  962.     gi.modelindex ("models/objects/debris3/tris.md2");
  963.  
  964.     self->solid = SOLID_BBOX;
  965.     self->movetype = MOVETYPE_STEP;
  966.  
  967.     self->model = "models/objects/barrels/tris.md2";
  968.     self->s.modelindex = gi.modelindex (self->model);
  969.     VectorSet (self->mins, -16, -16, 0);
  970.     VectorSet (self->maxs, 16, 16, 40);
  971.  
  972.     if (!self->mass)
  973.         self->mass = 400;
  974.     if (!self->health)
  975.         self->health = 10;
  976.     if (!self->dmg)
  977.         self->dmg = 150;
  978.  
  979.     self->die = barrel_delay;
  980.     self->takedamage = DAMAGE_YES;
  981.     self->monsterinfo.aiflags = AI_NOSTEP;
  982.  
  983.     self->touch = barrel_touch;
  984.  
  985.     self->think = M_droptofloor;
  986.     self->nextthink = level.time + 2 * FRAMETIME;
  987.  
  988.     gi.linkentity (self);
  989. }
  990.  
  991.  
  992. //
  993. // miscellaneous specialty items
  994. //
  995.  
  996. /*QUAKED misc_blackhole (1 .5 0) (-8 -8 -8) (8 8 8)
  997. */
  998.  
  999. void misc_blackhole_use (edict_t *ent, edict_t *other, edict_t *activator)
  1000. {
  1001.     /*
  1002.     gi.WriteByte (svc_temp_entity);
  1003.     gi.WriteByte (TE_BOSSTPORT);
  1004.     gi.WritePosition (ent->s.origin);
  1005.     gi.multicast (ent->s.origin, MULTICAST_PVS);
  1006.     */
  1007.     G_FreeEdict (ent);
  1008. }
  1009.  
  1010. void misc_blackhole_think (edict_t *self)
  1011. {
  1012.     if (++self->s.frame < 19)
  1013.         self->nextthink = level.time + FRAMETIME;
  1014.     else
  1015.     {        
  1016.         self->s.frame = 0;
  1017.         self->nextthink = level.time + FRAMETIME;
  1018.     }
  1019. }
  1020.  
  1021. void SP_misc_blackhole (edict_t *ent)
  1022. {
  1023.     ent->movetype = MOVETYPE_NONE;
  1024.     ent->solid = SOLID_NOT;
  1025.     VectorSet (ent->mins, -64, -64, 0);
  1026.     VectorSet (ent->maxs, 64, 64, 8);
  1027.     ent->s.modelindex = gi.modelindex ("models/objects/black/tris.md2");
  1028.     ent->s.renderfx = RF_TRANSLUCENT;
  1029.     ent->use = misc_blackhole_use;
  1030.     ent->think = misc_blackhole_think;
  1031.     ent->nextthink = level.time + 2 * FRAMETIME;
  1032.     gi.linkentity (ent);
  1033. }
  1034.  
  1035. /*QUAKED misc_eastertank (1 .5 0) (-32 -32 -16) (32 32 32)
  1036. */
  1037.  
  1038. void misc_eastertank_think (edict_t *self)
  1039. {
  1040.     if (++self->s.frame < 293)
  1041.         self->nextthink = level.time + FRAMETIME;
  1042.     else
  1043.     {        
  1044.         self->s.frame = 254;
  1045.         self->nextthink = level.time + FRAMETIME;
  1046.     }
  1047. }
  1048.  
  1049. void SP_misc_eastertank (edict_t *ent)
  1050. {
  1051.     ent->movetype = MOVETYPE_NONE;
  1052.     ent->solid = SOLID_BBOX;
  1053.     VectorSet (ent->mins, -32, -32, -16);
  1054.     VectorSet (ent->maxs, 32, 32, 32);
  1055.     ent->s.modelindex = gi.modelindex ("models/monsters/tank/tris.md2");
  1056.     ent->s.frame = 254;
  1057.     ent->think = misc_eastertank_think;
  1058.     ent->nextthink = level.time + 2 * FRAMETIME;
  1059.     gi.linkentity (ent);
  1060. }
  1061.  
  1062. /*QUAKED misc_easterchick (1 .5 0) (-32 -32 0) (32 32 32)
  1063. */
  1064.  
  1065.  
  1066. void misc_easterchick_think (edict_t *self)
  1067. {
  1068.     if (++self->s.frame < 247)
  1069.         self->nextthink = level.time + FRAMETIME;
  1070.     else
  1071.     {        
  1072.         self->s.frame = 208;
  1073.         self->nextthink = level.time + FRAMETIME;
  1074.     }
  1075. }
  1076.  
  1077. void SP_misc_easterchick (edict_t *ent)
  1078. {
  1079.     ent->movetype = MOVETYPE_NONE;
  1080.     ent->solid = SOLID_BBOX;
  1081.     VectorSet (ent->mins, -32, -32, 0);
  1082.     VectorSet (ent->maxs, 32, 32, 32);
  1083.     ent->s.modelindex = gi.modelindex ("models/monsters/bitch/tris.md2");
  1084.     ent->s.frame = 208;
  1085.     ent->think = misc_easterchick_think;
  1086.     ent->nextthink = level.time + 2 * FRAMETIME;
  1087.     gi.linkentity (ent);
  1088. }
  1089.  
  1090. /*QUAKED misc_easterchick2 (1 .5 0) (-32 -32 0) (32 32 32)
  1091. */
  1092.  
  1093.  
  1094. void misc_easterchick2_think (edict_t *self)
  1095. {
  1096.     if (++self->s.frame < 287)
  1097.         self->nextthink = level.time + FRAMETIME;
  1098.     else
  1099.     {        
  1100.         self->s.frame = 248;
  1101.         self->nextthink = level.time + FRAMETIME;
  1102.     }
  1103. }
  1104.  
  1105. void SP_misc_easterchick2 (edict_t *ent)
  1106. {
  1107.     ent->movetype = MOVETYPE_NONE;
  1108.     ent->solid = SOLID_BBOX;
  1109.     VectorSet (ent->mins, -32, -32, 0);
  1110.     VectorSet (ent->maxs, 32, 32, 32);
  1111.     ent->s.modelindex = gi.modelindex ("models/monsters/bitch/tris.md2");
  1112.     ent->s.frame = 248;
  1113.     ent->think = misc_easterchick2_think;
  1114.     ent->nextthink = level.time + 2 * FRAMETIME;
  1115.     gi.linkentity (ent);
  1116. }
  1117.  
  1118.  
  1119. /*QUAKED monster_commander_body (1 .5 0) (-32 -32 0) (32 32 48)
  1120. Not really a monster, this is the Tank Commander's decapitated body.
  1121. There should be a item_commander_head that has this as it's target.
  1122. */
  1123.  
  1124. void commander_body_think (edict_t *self)
  1125. {
  1126.     if (++self->s.frame < 24)
  1127.         self->nextthink = level.time + FRAMETIME;
  1128.     else
  1129.         self->nextthink = 0;
  1130.  
  1131.     if (self->s.frame == 22)
  1132.         gi.sound (self, CHAN_BODY, gi.soundindex ("tank/thud.wav"), 1, ATTN_NORM, 0);
  1133. }
  1134.  
  1135. void commander_body_use (edict_t *self, edict_t *other, edict_t *activator)
  1136. {
  1137.     self->think = commander_body_think;
  1138.     self->nextthink = level.time + FRAMETIME;
  1139.     gi.sound (self, CHAN_BODY, gi.soundindex ("tank/pain.wav"), 1, ATTN_NORM, 0);
  1140. }
  1141.  
  1142. void commander_body_drop (edict_t *self)
  1143. {
  1144.     self->movetype = MOVETYPE_TOSS;
  1145.     self->s.origin[2] += 2;
  1146. }
  1147.  
  1148. void SP_monster_commander_body (edict_t *self)
  1149. {
  1150.     self->movetype = MOVETYPE_NONE;
  1151.     self->solid = SOLID_BBOX;
  1152.     self->model = "models/monsters/commandr/tris.md2";
  1153.     self->s.modelindex = gi.modelindex (self->model);
  1154.     VectorSet (self->mins, -32, -32, 0);
  1155.     VectorSet (self->maxs, 32, 32, 48);
  1156.     self->use = commander_body_use;
  1157.     self->takedamage = DAMAGE_YES;
  1158.     self->flags = FL_GODMODE;
  1159.     self->s.renderfx |= RF_FRAMELERP;
  1160.     gi.linkentity (self);
  1161.  
  1162.     gi.soundindex ("tank/thud.wav");
  1163.     gi.soundindex ("tank/pain.wav");
  1164.  
  1165.     self->think = commander_body_drop;
  1166.     self->nextthink = level.time + 5 * FRAMETIME;
  1167. }
  1168.  
  1169.  
  1170. /*QUAKED misc_banner (1 .5 0) (-4 -4 -4) (4 4 4)
  1171. The origin is the bottom of the banner.
  1172. The banner is 128 tall.
  1173. */
  1174. void misc_banner_think (edict_t *ent)
  1175. {
  1176.     ent->s.frame = (ent->s.frame + 1) % 16;
  1177.     ent->nextthink = level.time + FRAMETIME;
  1178. }
  1179.  
  1180. void SP_misc_banner (edict_t *ent)
  1181. {
  1182.     ent->movetype = MOVETYPE_NONE;
  1183.     ent->solid = SOLID_NOT;
  1184.     ent->s.modelindex = gi.modelindex ("models/objects/banner/tris.md2");
  1185.     ent->s.frame = rand() % 16;
  1186.     gi.linkentity (ent);
  1187.  
  1188.     ent->think = misc_banner_think;
  1189.     ent->nextthink = level.time + FRAMETIME;
  1190. }
  1191.  
  1192. /*QUAKED misc_deadsoldier (1 .5 0) (-16 -16 0) (16 16 16) ON_BACK ON_STOMACH BACK_DECAP FETAL_POS SIT_DECAP IMPALED
  1193. This is the dead player model. Comes in 6 exciting different poses!
  1194. */
  1195. void misc_deadsoldier_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  1196. {
  1197.     int        n;
  1198.  
  1199.     if (self->health > -80)
  1200.         return;
  1201.  
  1202.     gi.sound (self, CHAN_BODY, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
  1203.     for (n= 0; n < 4; n++)
  1204.         ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
  1205.     ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
  1206. }
  1207.  
  1208. void SP_misc_deadsoldier (edict_t *ent)
  1209. {
  1210.     if (deathmatch->value)
  1211.     {    // auto-remove for deathmatch
  1212.         G_FreeEdict (ent);
  1213.         return;
  1214.     }
  1215.  
  1216.     ent->movetype = MOVETYPE_NONE;
  1217.     ent->solid = SOLID_BBOX;
  1218.     ent->s.modelindex=gi.modelindex ("models/deadbods/dude/tris.md2");
  1219.  
  1220.     // Defaults to frame 0
  1221.     if (ent->spawnflags & 2)
  1222.         ent->s.frame = 1;
  1223.     else if (ent->spawnflags & 4)
  1224.         ent->s.frame = 2;
  1225.     else if (ent->spawnflags & 8)
  1226.         ent->s.frame = 3;
  1227.     else if (ent->spawnflags & 16)
  1228.         ent->s.frame = 4;
  1229.     else if (ent->spawnflags & 32)
  1230.         ent->s.frame = 5;
  1231.     else
  1232.         ent->s.frame = 0;
  1233.  
  1234.     VectorSet (ent->mins, -16, -16, 0);
  1235.     VectorSet (ent->maxs, 16, 16, 16);
  1236.     ent->deadflag = DEAD_DEAD;
  1237.     ent->takedamage = DAMAGE_YES;
  1238.     ent->svflags |= SVF_MONSTER|SVF_DEADMONSTER;
  1239.     ent->die = misc_deadsoldier_die;
  1240.     ent->monsterinfo.aiflags |= AI_GOOD_GUY;
  1241.  
  1242.     gi.linkentity (ent);
  1243. }
  1244.  
  1245. /*QUAKED misc_viper (1 .5 0) (-16 -16 0) (16 16 32)
  1246. This is the Viper for the flyby bombing.
  1247. It is trigger_spawned, so you must have something use it for it to show up.
  1248. There must be a path for it to follow once it is activated.
  1249.  
  1250. "speed"        How fast the Viper should fly
  1251. */
  1252.  
  1253. extern void train_use (edict_t *self, edict_t *other, edict_t *activator);
  1254. extern void func_train_find (edict_t *self);
  1255.  
  1256. void misc_viper_use  (edict_t *self, edict_t *other, edict_t *activator)
  1257. {
  1258.     self->svflags &= ~SVF_NOCLIENT;
  1259.     self->use = train_use;
  1260.     train_use (self, other, activator);
  1261. }
  1262.  
  1263. void SP_misc_viper (edict_t *ent)
  1264. {
  1265.     if (!ent->target)
  1266.     {
  1267.         gi.dprintf ("misc_viper without a target at %s\n", vtos(ent->absmin));
  1268.         G_FreeEdict (ent);
  1269.         return;
  1270.     }
  1271.  
  1272.     if (!ent->speed)
  1273.         ent->speed = 300;
  1274.  
  1275.     ent->movetype = MOVETYPE_PUSH;
  1276.     ent->solid = SOLID_NOT;
  1277.     ent->s.modelindex = gi.modelindex ("models/ships/viper/tris.md2");
  1278.     VectorSet (ent->mins, -16, -16, 0);
  1279.     VectorSet (ent->maxs, 16, 16, 32);
  1280.  
  1281.     ent->think = func_train_find;
  1282.     ent->nextthink = level.time + FRAMETIME;
  1283.     ent->use = misc_viper_use;
  1284.     ent->svflags |= SVF_NOCLIENT;
  1285.     ent->moveinfo.accel = ent->moveinfo.decel = ent->moveinfo.speed = ent->speed;
  1286.  
  1287.     gi.linkentity (ent);
  1288. }
  1289.  
  1290.  
  1291. /*QUAKED misc_bigviper (1 .5 0) (-176 -120 -24) (176 120 72) 
  1292. This is a large stationary viper as seen in Paul's intro
  1293. */
  1294. void SP_misc_bigviper (edict_t *ent)
  1295. {
  1296.     ent->movetype = MOVETYPE_NONE;
  1297.     ent->solid = SOLID_BBOX;
  1298.     VectorSet (ent->mins, -176, -120, -24);
  1299.     VectorSet (ent->maxs, 176, 120, 72);
  1300.     ent->s.modelindex = gi.modelindex ("models/ships/bigviper/tris.md2");
  1301.     gi.linkentity (ent);
  1302. }
  1303.  
  1304.  
  1305. /*QUAKED misc_viper_bomb (1 0 0) (-8 -8 -8) (8 8 8)
  1306. "dmg"    how much boom should the bomb make?
  1307. */
  1308. void misc_viper_bomb_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  1309. {
  1310.     G_UseTargets (self, self->activator);
  1311.  
  1312.     self->s.origin[2] = self->absmin[2] + 1;
  1313.     T_RadiusDamage (self, self, self->dmg, NULL, self->dmg+40);
  1314.     BecomeExplosion2 (self);
  1315. }
  1316.  
  1317. void misc_viper_bomb_prethink (edict_t *self)
  1318. {
  1319.     vec3_t    v;
  1320.     float    diff;
  1321.  
  1322.     self->groundentity = NULL;
  1323.  
  1324.     diff = self->timestamp - level.time;
  1325.     if (diff < -1.0)
  1326.         diff = -1.0;
  1327.  
  1328.     VectorScale (self->moveinfo.dir, 1.0 + diff, v);
  1329.     v[2] = diff;
  1330.  
  1331.     diff = self->s.angles[2];
  1332.     vectoangles (v, self->s.angles);
  1333.     self->s.angles[2] = diff + 10;
  1334. }
  1335.  
  1336. void misc_viper_bomb_use (edict_t *self, edict_t *other, edict_t *activator)
  1337. {
  1338.     edict_t    *viper;
  1339.  
  1340.     self->solid = SOLID_BBOX;
  1341.     self->svflags &= ~SVF_NOCLIENT;
  1342.     self->s.effects |= EF_ROCKET;
  1343.     self->use = NULL;
  1344.     self->movetype = MOVETYPE_TOSS;
  1345.     self->prethink = misc_viper_bomb_prethink;
  1346.     self->touch = misc_viper_bomb_touch;
  1347.     self->activator = activator;
  1348.  
  1349.     viper = G_Find (NULL, FOFS(classname), "misc_viper");
  1350.     VectorScale (viper->moveinfo.dir, viper->moveinfo.speed, self->velocity);
  1351.  
  1352.     self->timestamp = level.time;
  1353.     VectorCopy (viper->moveinfo.dir, self->moveinfo.dir);
  1354. }
  1355.  
  1356. void SP_misc_viper_bomb (edict_t *self)
  1357. {
  1358.     self->movetype = MOVETYPE_NONE;
  1359.     self->solid = SOLID_NOT;
  1360.     VectorSet (self->mins, -8, -8, -8);
  1361.     VectorSet (self->maxs, 8, 8, 8);
  1362.  
  1363.     self->s.modelindex = gi.modelindex ("models/objects/bomb/tris.md2");
  1364.  
  1365.     if (!self->dmg)
  1366.         self->dmg = 1000;
  1367.  
  1368.     self->use = misc_viper_bomb_use;
  1369.     self->svflags |= SVF_NOCLIENT;
  1370.  
  1371.     gi.linkentity (self);
  1372. }
  1373.  
  1374.  
  1375. /*QUAKED misc_strogg_ship (1 .5 0) (-16 -16 0) (16 16 32)
  1376. This is a Storgg ship for the flybys.
  1377. It is trigger_spawned, so you must have something use it for it to show up.
  1378. There must be a path for it to follow once it is activated.
  1379.  
  1380. "speed"        How fast it should fly
  1381. */
  1382.  
  1383. extern void train_use (edict_t *self, edict_t *other, edict_t *activator);
  1384. extern void func_train_find (edict_t *self);
  1385.  
  1386. void misc_strogg_ship_use  (edict_t *self, edict_t *other, edict_t *activator)
  1387. {
  1388.     self->svflags &= ~SVF_NOCLIENT;
  1389.     self->use = train_use;
  1390.     train_use (self, other, activator);
  1391. }
  1392.  
  1393. void SP_misc_strogg_ship (edict_t *ent)
  1394. {
  1395.     if (!ent->target)
  1396.     {
  1397.         gi.dprintf ("%s without a target at %s\n", ent->classname, vtos(ent->absmin));
  1398.         G_FreeEdict (ent);
  1399.         return;
  1400.     }
  1401.  
  1402.     if (!ent->speed)
  1403.         ent->speed = 300;
  1404.  
  1405.     ent->movetype = MOVETYPE_PUSH;
  1406.     ent->solid = SOLID_NOT;
  1407.     ent->s.modelindex = gi.modelindex ("models/ships/strogg1/tris.md2");
  1408.     VectorSet (ent->mins, -16, -16, 0);
  1409.     VectorSet (ent->maxs, 16, 16, 32);
  1410.  
  1411.     ent->think = func_train_find;
  1412.     ent->nextthink = level.time + FRAMETIME;
  1413.     ent->use = misc_strogg_ship_use;
  1414.     ent->svflags |= SVF_NOCLIENT;
  1415.     ent->moveinfo.accel = ent->moveinfo.decel = ent->moveinfo.speed = ent->speed;
  1416.  
  1417.     gi.linkentity (ent);
  1418. }
  1419.  
  1420.  
  1421. /*QUAKED misc_satellite_dish (1 .5 0) (-64 -64 0) (64 64 128)
  1422. */
  1423. void misc_satellite_dish_think (edict_t *self)
  1424. {
  1425.     self->s.frame++;
  1426.     if (self->s.frame < 38)
  1427.         self->nextthink = level.time + FRAMETIME;
  1428. }
  1429.  
  1430. void misc_satellite_dish_use (edict_t *self, edict_t *other, edict_t *activator)
  1431. {
  1432.     self->s.frame = 0;
  1433.     self->think = misc_satellite_dish_think;
  1434.     self->nextthink = level.time + FRAMETIME;
  1435. }
  1436.  
  1437. void SP_misc_satellite_dish (edict_t *ent)
  1438. {
  1439.     ent->movetype = MOVETYPE_NONE;
  1440.     ent->solid = SOLID_BBOX;
  1441.     VectorSet (ent->mins, -64, -64, 0);
  1442.     VectorSet (ent->maxs, 64, 64, 128);
  1443.     ent->s.modelindex = gi.modelindex ("models/objects/satellite/tris.md2");
  1444.     ent->use = misc_satellite_dish_use;
  1445.     gi.linkentity (ent);
  1446. }
  1447.  
  1448.  
  1449. /*QUAKED light_mine1 (0 1 0) (-2 -2 -12) (2 2 12)
  1450. */
  1451. void SP_light_mine1 (edict_t *ent)
  1452. {
  1453.     ent->movetype = MOVETYPE_NONE;
  1454.     ent->solid = SOLID_BBOX;
  1455.     ent->s.modelindex = gi.modelindex ("models/objects/minelite/light1/tris.md2");
  1456.     gi.linkentity (ent);
  1457. }
  1458.  
  1459.  
  1460. /*QUAKED light_mine2 (0 1 0) (-2 -2 -12) (2 2 12)
  1461. */
  1462. void SP_light_mine2 (edict_t *ent)
  1463. {
  1464.     ent->movetype = MOVETYPE_NONE;
  1465.     ent->solid = SOLID_BBOX;
  1466.     ent->s.modelindex = gi.modelindex ("models/objects/minelite/light2/tris.md2");
  1467.     gi.linkentity (ent);
  1468. }
  1469.  
  1470.  
  1471. /*QUAKED misc_gib_arm (1 0 0) (-8 -8 -8) (8 8 8)
  1472. Intended for use with the target_spawner
  1473. */
  1474. void SP_misc_gib_arm (edict_t *ent)
  1475. {
  1476.     gi.setmodel (ent, "models/objects/gibs/arm/tris.md2");
  1477.     ent->solid = SOLID_NOT;
  1478.     ent->s.effects |= EF_GIB;
  1479.     ent->takedamage = DAMAGE_YES;
  1480.     ent->die = gib_die;
  1481.     ent->movetype = MOVETYPE_TOSS;
  1482.     ent->svflags |= SVF_MONSTER;
  1483.     ent->deadflag = DEAD_DEAD;
  1484.     ent->avelocity[0] = random()*200;
  1485.     ent->avelocity[1] = random()*200;
  1486.     ent->avelocity[2] = random()*200;
  1487.     ent->think = G_FreeEdict;
  1488.     ent->nextthink = level.time + 30;
  1489.     gi.linkentity (ent);
  1490. }
  1491.  
  1492. /*QUAKED misc_gib_leg (1 0 0) (-8 -8 -8) (8 8 8)
  1493. Intended for use with the target_spawner
  1494. */
  1495. void SP_misc_gib_leg (edict_t *ent)
  1496. {
  1497.     gi.setmodel (ent, "models/objects/gibs/leg/tris.md2");
  1498.     ent->solid = SOLID_NOT;
  1499.     ent->s.effects |= EF_GIB;
  1500.     ent->takedamage = DAMAGE_YES;
  1501.     ent->die = gib_die;
  1502.     ent->movetype = MOVETYPE_TOSS;
  1503.     ent->svflags |= SVF_MONSTER;
  1504.     ent->deadflag = DEAD_DEAD;
  1505.     ent->avelocity[0] = random()*200;
  1506.     ent->avelocity[1] = random()*200;
  1507.     ent->avelocity[2] = random()*200;
  1508.     ent->think = G_FreeEdict;
  1509.     ent->nextthink = level.time + 30;
  1510.     gi.linkentity (ent);
  1511. }
  1512.  
  1513. /*QUAKED misc_gib_head (1 0 0) (-8 -8 -8) (8 8 8)
  1514. Intended for use with the target_spawner
  1515. */
  1516. void SP_misc_gib_head (edict_t *ent)
  1517. {
  1518.     gi.setmodel (ent, "models/objects/gibs/head/tris.md2");
  1519.     ent->solid = SOLID_NOT;
  1520.     ent->s.effects |= EF_GIB;
  1521.     ent->takedamage = DAMAGE_YES;
  1522.     ent->die = gib_die;
  1523.     ent->movetype = MOVETYPE_TOSS;
  1524.     ent->svflags |= SVF_MONSTER;
  1525.     ent->deadflag = DEAD_DEAD;
  1526.     ent->avelocity[0] = random()*200;
  1527.     ent->avelocity[1] = random()*200;
  1528.     ent->avelocity[2] = random()*200;
  1529.     ent->think = G_FreeEdict;
  1530.     ent->nextthink = level.time + 30;
  1531.     gi.linkentity (ent);
  1532. }
  1533.  
  1534. //=====================================================
  1535.  
  1536. /*QUAKED target_character (0 0 1) ?
  1537. used with target_string (must be on same "team")
  1538. "count" is position in the string (starts at 1)
  1539. */
  1540.  
  1541. void SP_target_character (edict_t *self)
  1542. {
  1543.     self->movetype = MOVETYPE_PUSH;
  1544.     gi.setmodel (self, self->model);
  1545.     self->solid = SOLID_BSP;
  1546.     self->s.frame = 12;
  1547.     gi.linkentity (self);
  1548.     return;
  1549. }
  1550.  
  1551.  
  1552. /*QUAKED target_string (0 0 1) (-8 -8 -8) (8 8 8)
  1553. */
  1554.  
  1555. void target_string_use (edict_t *self, edict_t *other, edict_t *activator)
  1556. {
  1557.     edict_t *e;
  1558.     int        n, l;
  1559.     char    c;
  1560.  
  1561.     l = strlen(self->message);
  1562.     for (e = self->teammaster; e; e = e->teamchain)
  1563.     {
  1564.         if (!e->count)
  1565.             continue;
  1566.         n = e->count - 1;
  1567.         if (n > l)
  1568.         {
  1569.             e->s.frame = 12;
  1570.             continue;
  1571.         }
  1572.  
  1573.         c = self->message[n];
  1574.         if (c >= '0' && c <= '9')
  1575.             e->s.frame = c - '0';
  1576.         else if (c == '-')
  1577.             e->s.frame = 10;
  1578.         else if (c == ':')
  1579.             e->s.frame = 11;
  1580.         else
  1581.             e->s.frame = 12;
  1582.     }
  1583. }
  1584.  
  1585. void SP_target_string (edict_t *self)
  1586. {
  1587.     if (!self->message)
  1588.         self->message = "";
  1589.     self->use = target_string_use;
  1590. }
  1591.  
  1592.  
  1593. /*QUAKED func_clock (0 0 1) (-8 -8 -8) (8 8 8) TIMER_UP TIMER_DOWN START_OFF MULTI_USE
  1594. target a target_string with this
  1595.  
  1596. The default is to be a time of day clock
  1597.  
  1598. TIMER_UP and TIMER_DOWN run for "count" seconds and the fire "pathtarget"
  1599. If START_OFF, this entity must be used before it starts
  1600.  
  1601. "style"        0 "xx"
  1602.             1 "xx:xx"
  1603.             2 "xx:xx:xx"
  1604. */
  1605.  
  1606. #define    CLOCK_MESSAGE_SIZE    16
  1607.  
  1608. // don't let field width of any clock messages change, or it
  1609. // could cause an overwrite after a game load
  1610.  
  1611. static void func_clock_reset (edict_t *self)
  1612. {
  1613.     self->activator = NULL;
  1614.     if (self->spawnflags & 1)
  1615.     {
  1616.         self->health = 0;
  1617.         self->wait = self->count;
  1618.     }
  1619.     else if (self->spawnflags & 2)
  1620.     {
  1621.         self->health = self->count;
  1622.         self->wait = 0;
  1623.     }
  1624. }
  1625.  
  1626. static void func_clock_format_countdown (edict_t *self)
  1627. {
  1628.     if (self->style == 0)
  1629.     {
  1630.         Com_sprintf (self->message, CLOCK_MESSAGE_SIZE, "%2i", self->health);
  1631.         return;
  1632.     }
  1633.  
  1634.     if (self->style == 1)
  1635.     {
  1636.         Com_sprintf(self->message, CLOCK_MESSAGE_SIZE, "%2i:%2i", self->health / 60, self->health % 60);
  1637.         if (self->message[3] == ' ')
  1638.             self->message[3] = '0';
  1639.         return;
  1640.     }
  1641.  
  1642.     if (self->style == 2)
  1643.     {
  1644.         Com_sprintf(self->message, CLOCK_MESSAGE_SIZE, "%2i:%2i:%2i", self->health / 3600, (self->health - (self->health / 3600) * 3600) / 60, self->health % 60);
  1645.         if (self->message[3] == ' ')
  1646.             self->message[3] = '0';
  1647.         if (self->message[6] == ' ')
  1648.             self->message[6] = '0';
  1649.         return;
  1650.     }
  1651. }
  1652.  
  1653. void func_clock_think (edict_t *self)
  1654. {
  1655.     if (!self->enemy)
  1656.     {
  1657.         self->enemy = G_Find (NULL, FOFS(targetname), self->target);
  1658.         if (!self->enemy)
  1659.             return;
  1660.     }
  1661.  
  1662.     if (self->spawnflags & 1)
  1663.     {
  1664.         func_clock_format_countdown (self);
  1665.         self->health++;
  1666.     }
  1667.     else if (self->spawnflags & 2)
  1668.     {
  1669.         func_clock_format_countdown (self);
  1670.         self->health--;
  1671.     }
  1672.     else
  1673.     {
  1674.         struct tm    *ltime;
  1675.         time_t        gmtime;
  1676.  
  1677.         time(&gmtime);
  1678.         ltime = localtime(&gmtime);
  1679.         Com_sprintf (self->message, CLOCK_MESSAGE_SIZE, "%2i:%2i:%2i", ltime->tm_hour, ltime->tm_min, ltime->tm_sec);
  1680.         if (self->message[3] == ' ')
  1681.             self->message[3] = '0';
  1682.         if (self->message[6] == ' ')
  1683.             self->message[6] = '0';
  1684.     }
  1685.  
  1686.     self->enemy->message = self->message;
  1687.     self->enemy->use (self->enemy, self, self);
  1688.  
  1689.     if (((self->spawnflags & 1) && (self->health > self->wait)) ||
  1690.         ((self->spawnflags & 2) && (self->health < self->wait)))
  1691.     {
  1692.         if (self->pathtarget)
  1693.         {
  1694.             char *savetarget;
  1695.             char *savemessage;
  1696.  
  1697.             savetarget = self->target;
  1698.             savemessage = self->message;
  1699.             self->target = self->pathtarget;
  1700.             self->message = NULL;
  1701.             G_UseTargets (self, self->activator);
  1702.             self->target = savetarget;
  1703.             self->message = savemessage;
  1704.         }
  1705.  
  1706.         if (!(self->spawnflags & 8))
  1707.             return;
  1708.  
  1709.         func_clock_reset (self);
  1710.  
  1711.         if (self->spawnflags & 4)
  1712.             return;
  1713.     }
  1714.  
  1715.     self->nextthink = level.time + 1;
  1716. }
  1717.  
  1718. void func_clock_use (edict_t *self, edict_t *other, edict_t *activator)
  1719. {
  1720.     if (!(self->spawnflags & 8))
  1721.         self->use = NULL;
  1722.     if (self->activator)
  1723.         return;
  1724.     self->activator = activator;
  1725.     self->think (self);
  1726. }
  1727.  
  1728. void SP_func_clock (edict_t *self)
  1729. {
  1730.     if (!self->target)
  1731.     {
  1732.         gi.dprintf("%s with no target at %s\n", self->classname, vtos(self->s.origin));
  1733.         G_FreeEdict (self);
  1734.         return;
  1735.     }
  1736.  
  1737.     if ((self->spawnflags & 2) && (!self->count))
  1738.     {
  1739.         gi.dprintf("%s with no count at %s\n", self->classname, vtos(self->s.origin));
  1740.         G_FreeEdict (self);
  1741.         return;
  1742.     }
  1743.  
  1744.     if ((self->spawnflags & 1) && (!self->count))
  1745.         self->count = 60*60;;
  1746.  
  1747.     func_clock_reset (self);
  1748.  
  1749.     self->message = gi.TagMalloc (CLOCK_MESSAGE_SIZE, TAG_LEVEL);
  1750.  
  1751.     self->think = func_clock_think;
  1752.  
  1753.     if (self->spawnflags & 4)
  1754.         self->use = func_clock_use;
  1755.     else
  1756.         self->nextthink = level.time + 1;
  1757. }
  1758.  
  1759. //=================================================================================
  1760.  
  1761. void teleporter_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  1762. {
  1763.     edict_t        *dest;
  1764.     int            i;
  1765.  
  1766.     if (!other->client)
  1767.         return;
  1768.     dest = G_Find (NULL, FOFS(targetname), self->target);
  1769.     if (!dest)
  1770.     {
  1771.         gi.dprintf ("Couldn't find destination\n");
  1772.         return;
  1773.     }
  1774.  
  1775.     // unlink to make sure it can't possibly interfere with KillBox
  1776.     gi.unlinkentity (other);
  1777.  
  1778.     VectorCopy (dest->s.origin, other->s.origin);
  1779.     other->s.origin[2] += 9;
  1780.  
  1781.     // clear the velocity and hold them in place briefly
  1782.     VectorClear (other->velocity);
  1783.     other->client->ps.pmove.teleport_time = 50;
  1784.  
  1785.     // draw the teleport splash at the destination
  1786.     other->s.event = EV_PLAYER_TELEPORT;
  1787.  
  1788.     // set angles
  1789.     for (i=0 ; i<3 ; i++)
  1790.         other->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(dest->s.angles[i] - other->client->resp.cmd_angles[i]);
  1791.  
  1792.     other->s.angles[PITCH] = 0;
  1793.     other->s.angles[YAW] = self->s.angles[YAW];
  1794.     other->s.angles[ROLL] = 0;
  1795.     VectorCopy (self->s.angles, other->client->ps.viewangles);
  1796.     VectorCopy (self->s.angles, other->client->v_angle);
  1797.  
  1798.     // kill anything at the destination
  1799.     if (!KillBox (other))
  1800.     {
  1801.     }
  1802.  
  1803.     gi.linkentity (other);
  1804. }
  1805.  
  1806. /*QUAKED misc_teleporter (1 0 0) (-32 -32 -24) (32 32 -16)
  1807. Stepping onto this disc will teleport players to the targeted misc_teleporter_dest object.
  1808. */
  1809. void SP_misc_teleporter (edict_t *ent)
  1810. {
  1811.     edict_t        *trig;
  1812.  
  1813.     if (!ent->target)
  1814.     {
  1815.         gi.dprintf ("teleporter without a target.\n");
  1816.         G_FreeEdict (ent);
  1817.         return;
  1818.     }
  1819.  
  1820.     gi.setmodel (ent, "models/objects/dmspot/tris.md2");
  1821.     ent->s.skinnum = 1;
  1822.     ent->solid = SOLID_BBOX;
  1823. //    ent->s.effects |= EF_FLIES;
  1824.  
  1825.     VectorSet (ent->mins, -32, -32, -24);
  1826.     VectorSet (ent->maxs, 32, 32, -16);
  1827.     gi.linkentity (ent);
  1828.  
  1829.     trig = G_Spawn ();
  1830.     trig->touch = teleporter_touch;
  1831.     trig->solid = SOLID_TRIGGER;
  1832.     trig->target = ent->target;
  1833.     VectorCopy (ent->s.origin, trig->s.origin);
  1834.     VectorSet (trig->mins, -8, -8, 8);
  1835.     VectorSet (trig->maxs, 8, 8, 24);
  1836.     gi.linkentity (trig);
  1837.     
  1838. }
  1839.  
  1840. /*QUAKED misc_teleporter_dest (1 0 0) (-32 -32 -24) (32 32 -16)
  1841. Point teleporters at these.
  1842. */
  1843. void SP_misc_teleporter_dest (edict_t *ent)
  1844. {
  1845.     gi.setmodel (ent, "models/objects/dmspot/tris.md2");
  1846.     ent->s.skinnum = 0;
  1847.     ent->solid = SOLID_BBOX;
  1848. //    ent->s.effects |= EF_FLIES;
  1849.     VectorSet (ent->mins, -32, -32, -24);
  1850.     VectorSet (ent->maxs, 32, 32, -16);
  1851.     gi.linkentity (ent);
  1852. }
  1853.  
  1854.