home *** CD-ROM | disk | FTP | other *** search
/ Qu-ake / Qu-ake.iso / qu_ke / monster / 005 / PLATS.QC < prev    next >
Encoding:
Text File  |  1996-11-25  |  8.0 KB  |  369 lines

  1.  
  2.  
  3. void() plat_center_touch;
  4. void() plat_outside_touch;
  5. void() plat_trigger_use;
  6. void() plat_go_up;
  7. void() plat_go_down;
  8. void() plat_crush;
  9. float PLAT_LOW_TRIGGER = 1;
  10.  
  11. void() plat_spawn_inside_trigger =
  12. {
  13.     local entity    trigger;
  14.     local vector    tmin, tmax;
  15.  
  16. //
  17. // middle trigger
  18. //    
  19.     trigger = spawn();
  20.     trigger.touch = plat_center_touch;
  21.     trigger.movetype = MOVETYPE_NONE;
  22.     trigger.solid = SOLID_TRIGGER;
  23.     trigger.enemy = self;
  24.     
  25.     tmin = self.mins + '25 25 0';
  26.     tmax = self.maxs - '25 25 -8';
  27.     tmin_z = tmax_z - (self.pos1_z - self.pos2_z + 8);
  28.     if (self.spawnflags & PLAT_LOW_TRIGGER)
  29.         tmax_z = tmin_z + 8;
  30.     
  31.     if (self.size_x <= 50)
  32.     {
  33.         tmin_x = (self.mins_x + self.maxs_x) / 2;
  34.         tmax_x = tmin_x + 1;
  35.     }
  36.     if (self.size_y <= 50)
  37.     {
  38.         tmin_y = (self.mins_y + self.maxs_y) / 2;
  39.         tmax_y = tmin_y + 1;
  40.     }
  41.     
  42.     setsize (trigger, tmin, tmax);
  43. };
  44.  
  45. void() plat_hit_top =
  46. {
  47.     sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
  48.     self.state = STATE_TOP;
  49.     self.think = plat_go_down;
  50.     self.nextthink = self.ltime + 3;
  51. };
  52.  
  53. void() plat_hit_bottom =
  54. {
  55.     sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
  56.     self.state = STATE_BOTTOM;
  57. };
  58.  
  59. void() plat_go_down =
  60. {
  61.     sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  62.     self.state = STATE_DOWN;
  63.     SUB_CalcMove (self.pos2, self.speed, plat_hit_bottom);
  64. };
  65.  
  66. void() plat_go_up =
  67. {
  68.     sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  69.     self.state = STATE_UP;
  70.     SUB_CalcMove (self.pos1, self.speed, plat_hit_top);
  71. };
  72.  
  73. void() plat_center_touch =
  74. {
  75. // CUJO 1.3 - cujo now triggers platform
  76.     if ((other.classname != "player") && (other.classname != "cujo"))
  77.         return;
  78. // CUJO 1.3 - end
  79.  
  80.     if (other.health <= 0)
  81.         return;
  82.  
  83.     self = self.enemy;
  84.     if (self.state == STATE_BOTTOM)
  85.         plat_go_up ();
  86.     else if (self.state == STATE_TOP)
  87.         self.nextthink = self.ltime + 1;    // delay going down
  88. };
  89.  
  90. void() plat_outside_touch =
  91. {
  92. // CUJO 1.3 - cujo now triggers platform
  93.     if ((other.classname != "player") && (other.classname != "cujo"))
  94.         return;
  95. // CUJO 1.3 - end
  96.  
  97.     if (other.health <= 0)
  98.         return;
  99.         
  100. //dprint ("plat_outside_touch\n");
  101.     self = self.enemy;
  102.     if (self.state == STATE_TOP)
  103.         plat_go_down ();
  104. };
  105.  
  106. void() plat_trigger_use =
  107. {
  108.     if (self.think)
  109.         return;        // allready activated
  110.     plat_go_down();
  111. };
  112.  
  113.  
  114. void() plat_crush =
  115. {
  116. //dprint ("plat_crush\n");
  117.  
  118.     T_Damage (other, self, self, 1);
  119.     
  120.     if (self.state == STATE_UP)
  121.         plat_go_down ();
  122.     else if (self.state == STATE_DOWN)
  123.         plat_go_up ();
  124.     else
  125.         objerror ("plat_crush: bad self.state\n");
  126. };
  127.  
  128. void() plat_use =
  129. {
  130.     self.use = SUB_Null;
  131.     if (self.state != STATE_UP)
  132.         objerror ("plat_use: not in up state");
  133.     plat_go_down();
  134. };
  135.  
  136.  
  137. /*QUAKED func_plat (0 .5 .8) ? PLAT_LOW_TRIGGER
  138. speed    default 150
  139.  
  140. Plats are always drawn in the extended position, so they will light correctly.
  141.  
  142. If the plat is the target of another trigger or button, it will start out disabled in the extended position until it is trigger, when it will lower and become a normal plat.
  143.  
  144. If the "height" key is set, that will determine the amount the plat moves, instead of being implicitly determined by the model's height.
  145. Set "sounds" to one of the following:
  146. 1) base fast
  147. 2) chain slow
  148. */
  149.  
  150.  
  151. void() func_plat =
  152.  
  153. {
  154. local entity t;
  155.  
  156.     if (!self.t_length)
  157.         self.t_length = 80;
  158.     if (!self.t_width)
  159.         self.t_width = 10;
  160.  
  161.     if (self.sounds == 0)
  162.         self.sounds = 2;
  163. // FIX THIS TO LOAD A GENERIC PLAT SOUND
  164.  
  165.     if (self.sounds == 1)
  166.     {
  167.         precache_sound ("plats/plat1.wav");
  168.         precache_sound ("plats/plat2.wav");
  169.         self.noise = "plats/plat1.wav";
  170.         self.noise1 = "plats/plat2.wav";
  171.     }
  172.  
  173.     if (self.sounds == 2)
  174.     {
  175.         precache_sound ("plats/medplat1.wav");
  176.         precache_sound ("plats/medplat2.wav");
  177.         self.noise = "plats/medplat1.wav";
  178.         self.noise1 = "plats/medplat2.wav";
  179.     }
  180.  
  181.  
  182.     self.mangle = self.angles;
  183.     self.angles = '0 0 0';
  184.  
  185.     self.classname = "plat";
  186.     self.solid = SOLID_BSP;
  187.     self.movetype = MOVETYPE_PUSH;
  188.     setorigin (self, self.origin);    
  189.     setmodel (self, self.model);
  190.     setsize (self, self.mins , self.maxs);
  191.  
  192.     self.blocked = plat_crush;
  193.     if (!self.speed)
  194.         self.speed = 150;
  195.  
  196. // pos1 is the top position, pos2 is the bottom
  197.     self.pos1 = self.origin;
  198.     self.pos2 = self.origin;
  199.     if (self.height)
  200.         self.pos2_z = self.origin_z - self.height;
  201.     else
  202.         self.pos2_z = self.origin_z - self.size_z + 8;
  203.  
  204.     self.use = plat_trigger_use;
  205.  
  206.     plat_spawn_inside_trigger ();    // the "start moving" trigger    
  207.  
  208.     if (self.targetname)
  209.     {
  210.         self.state = STATE_UP;
  211.         self.use = plat_use;
  212.     }
  213.     else
  214.     {
  215.         setorigin (self, self.pos2);
  216.         self.state = STATE_BOTTOM;
  217.     }
  218. };
  219.  
  220. //============================================================================
  221.  
  222. void() train_next;
  223. void() func_train_find;
  224.  
  225. void() train_blocked =
  226. {
  227.     if (time < self.attack_finished)
  228.         return;
  229.     self.attack_finished = time + 0.5;
  230.     T_Damage (other, self, self, self.dmg);
  231. };
  232. void() train_use =
  233. {
  234.     if (self.think != func_train_find)
  235.         return;        // already activated
  236.     train_next();
  237. };
  238.  
  239. void() train_wait =
  240. {
  241.     if (self.wait)
  242.     {
  243.         self.nextthink = self.ltime + self.wait;
  244.         sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  245.     }
  246.     else
  247.         self.nextthink = self.ltime + 0.1;
  248.     
  249.     self.think = train_next;
  250. };
  251.  
  252. void() train_next =
  253. {
  254.     local entity    targ;
  255.  
  256.     targ = find (world, targetname, self.target);
  257.     self.target = targ.target;
  258.     if (!self.target)
  259.         objerror ("train_next: no next target");
  260.     if (targ.wait)
  261.         self.wait = targ.wait;
  262.     else
  263.         self.wait = 0;
  264.     sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
  265.     SUB_CalcMove (targ.origin - self.mins, self.speed, train_wait);
  266. };
  267.  
  268. void() func_train_find =
  269.  
  270. {
  271.     local entity    targ;
  272.  
  273.     targ = find (world, targetname, self.target);
  274.     self.target = targ.target;
  275.     setorigin (self, targ.origin - self.mins);
  276.     if (!self.targetname)
  277.     {    // not triggered, so start immediately
  278.         self.nextthink = self.ltime + 0.1;
  279.         self.think = train_next;
  280.     }
  281. };
  282.  
  283. /*QUAKED func_train (0 .5 .8) ?
  284. Trains are moving platforms that players can ride.
  285. The targets origin specifies the min point of the train at each corner.
  286. The train spawns at the first target it is pointing at.
  287. If the train is the target of a button or trigger, it will not begin moving until activated.
  288. speed    default 100
  289. dmg        default    2
  290. sounds
  291. 1) ratchet metal
  292.  
  293. */
  294. void() func_train =
  295. {    
  296.     if (!self.speed)
  297.         self.speed = 100;
  298.     if (!self.target)
  299.         objerror ("func_train without a target");
  300.     if (!self.dmg)
  301.         self.dmg = 2;
  302.  
  303.     if (self.sounds == 0)
  304.     {
  305.         self.noise = ("misc/null.wav");
  306.         precache_sound ("misc/null.wav");
  307.         self.noise1 = ("misc/null.wav");
  308.         precache_sound ("misc/null.wav");
  309.     }
  310.  
  311.     if (self.sounds == 1)
  312.     {
  313.         self.noise = ("plats/train2.wav");
  314.         precache_sound ("plats/train2.wav");
  315.         self.noise1 = ("plats/train1.wav");
  316.         precache_sound ("plats/train1.wav");
  317.     }
  318.  
  319.     self.cnt = 1;
  320.     self.solid = SOLID_BSP;
  321.     self.movetype = MOVETYPE_PUSH;
  322.     self.blocked = train_blocked;
  323.     self.use = train_use;
  324.     self.classname = "train";
  325.  
  326.     setmodel (self, self.model);
  327.     setsize (self, self.mins , self.maxs);
  328.     setorigin (self, self.origin);
  329.  
  330. // start trains on the second frame, to make sure their targets have had
  331. // a chance to spawn
  332.     self.nextthink = self.ltime + 0.1;
  333.     self.think = func_train_find;
  334. };
  335.  
  336. /*QUAKED misc_teleporttrain (0 .5 .8) (-8 -8 -8) (8 8 8)
  337. This is used for the final bos
  338. */
  339. void() misc_teleporttrain =
  340. {    
  341.     if (!self.speed)
  342.         self.speed = 100;
  343.     if (!self.target)
  344.         objerror ("func_train without a target");
  345.  
  346.     self.cnt = 1;
  347.     self.solid = SOLID_NOT;
  348.     self.movetype = MOVETYPE_PUSH;
  349.     self.blocked = train_blocked;
  350.     self.use = train_use;
  351.     self.avelocity = '100 200 300';
  352.  
  353.     self.noise = ("misc/null.wav");
  354.     precache_sound ("misc/null.wav");
  355.     self.noise1 = ("misc/null.wav");
  356.     precache_sound ("misc/null.wav");
  357.  
  358.     precache_model2 ("progs/teleport.mdl");
  359.     setmodel (self, "progs/teleport.mdl");
  360.     setsize (self, self.mins , self.maxs);
  361.     setorigin (self, self.origin);
  362.  
  363. // start trains on the second frame, to make sure their targets have had
  364. // a chance to spawn
  365.     self.nextthink = self.ltime + 0.1;
  366.     self.think = func_train_find;
  367. };
  368.  
  369.