g_func.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049
  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "g_local.h"
  16. /*
  17. =========================================================
  18. PLATS
  19. movement options:
  20. linear
  21. smooth start, hard stop
  22. smooth start, smooth stop
  23. start
  24. end
  25. acceleration
  26. speed
  27. deceleration
  28. begin sound
  29. end sound
  30. target fired when reaching end
  31. wait at end
  32. object characteristics that use move segments
  33. ---------------------------------------------
  34. movetype_push, or movetype_stop
  35. action when touched
  36. action when blocked
  37. action when used
  38. disabled?
  39. auto trigger spawning
  40. =========================================================
  41. */
  42. #define PLAT_LOW_TRIGGER 1
  43. #define STATE_TOP 0
  44. #define STATE_BOTTOM 1
  45. #define STATE_UP 2
  46. #define STATE_DOWN 3
  47. #define DOOR_START_OPEN 1
  48. #define DOOR_REVERSE 2
  49. #define DOOR_CRUSHER 4
  50. #define DOOR_NOMONSTER 8
  51. #define DOOR_TOGGLE 32
  52. #define DOOR_X_AXIS 64
  53. #define DOOR_Y_AXIS 128
  54. //
  55. // Support routines for movement (changes in origin using velocity)
  56. //
  57. void Move_Done (edict_t *ent)
  58. {
  59. VectorClear (ent->velocity);
  60. ent->moveinfo.endfunc (ent);
  61. }
  62. void Move_Final (edict_t *ent)
  63. {
  64. if (ent->moveinfo.remaining_distance == 0)
  65. {
  66. Move_Done (ent);
  67. return;
  68. }
  69. VectorScale (ent->moveinfo.dir, ent->moveinfo.remaining_distance / FRAMETIME, ent->velocity);
  70. ent->think = Move_Done;
  71. ent->nextthink = level.time + FRAMETIME;
  72. }
  73. void Move_Begin (edict_t *ent)
  74. {
  75. float frames;
  76. if ((ent->moveinfo.speed * FRAMETIME) >= ent->moveinfo.remaining_distance)
  77. {
  78. Move_Final (ent);
  79. return;
  80. }
  81. VectorScale (ent->moveinfo.dir, ent->moveinfo.speed, ent->velocity);
  82. frames = floor((ent->moveinfo.remaining_distance / ent->moveinfo.speed) / FRAMETIME);
  83. ent->moveinfo.remaining_distance -= frames * ent->moveinfo.speed * FRAMETIME;
  84. ent->nextthink = level.time + (frames * FRAMETIME);
  85. ent->think = Move_Final;
  86. }
  87. void Think_AccelMove (edict_t *ent);
  88. void Move_Calc (edict_t *ent, vec3_t dest, void(*func)(edict_t*))
  89. {
  90. VectorClear (ent->velocity);
  91. VectorSubtract (dest, ent->s.origin, ent->moveinfo.dir);
  92. ent->moveinfo.remaining_distance = VectorNormalize (ent->moveinfo.dir);
  93. ent->moveinfo.endfunc = func;
  94. if (ent->moveinfo.speed == ent->moveinfo.accel && ent->moveinfo.speed == ent->moveinfo.decel)
  95. {
  96. if (level.current_entity == ((ent->flags & FL_TEAMSLAVE) ? ent->teammaster : ent))
  97. {
  98. Move_Begin (ent);
  99. }
  100. else
  101. {
  102. ent->nextthink = level.time + FRAMETIME;
  103. ent->think = Move_Begin;
  104. }
  105. }
  106. else
  107. {
  108. // accelerative
  109. ent->moveinfo.current_speed = 0;
  110. ent->think = Think_AccelMove;
  111. ent->nextthink = level.time + FRAMETIME;
  112. }
  113. }
  114. //
  115. // Support routines for angular movement (changes in angle using avelocity)
  116. //
  117. void AngleMove_Done (edict_t *ent)
  118. {
  119. VectorClear (ent->avelocity);
  120. ent->moveinfo.endfunc (ent);
  121. }
  122. void AngleMove_Final (edict_t *ent)
  123. {
  124. vec3_t move;
  125. if (ent->moveinfo.state == STATE_UP)
  126. VectorSubtract (ent->moveinfo.end_angles, ent->s.angles, move);
  127. else
  128. VectorSubtract (ent->moveinfo.start_angles, ent->s.angles, move);
  129. if (VectorCompare (move, vec3_origin))
  130. {
  131. AngleMove_Done (ent);
  132. return;
  133. }
  134. VectorScale (move, 1.0/FRAMETIME, ent->avelocity);
  135. ent->think = AngleMove_Done;
  136. ent->nextthink = level.time + FRAMETIME;
  137. }
  138. void AngleMove_Begin (edict_t *ent)
  139. {
  140. vec3_t destdelta;
  141. float len;
  142. float traveltime;
  143. float frames;
  144. // set destdelta to the vector needed to move
  145. if (ent->moveinfo.state == STATE_UP)
  146. VectorSubtract (ent->moveinfo.end_angles, ent->s.angles, destdelta);
  147. else
  148. VectorSubtract (ent->moveinfo.start_angles, ent->s.angles, destdelta);
  149. // calculate length of vector
  150. len = VectorLength (destdelta);
  151. // divide by speed to get time to reach dest
  152. traveltime = len / ent->moveinfo.speed;
  153. if (traveltime < FRAMETIME)
  154. {
  155. AngleMove_Final (ent);
  156. return;
  157. }
  158. frames = floor(traveltime / FRAMETIME);
  159. // scale the destdelta vector by the time spent traveling to get velocity
  160. VectorScale (destdelta, 1.0 / traveltime, ent->avelocity);
  161. // set nextthink to trigger a think when dest is reached
  162. ent->nextthink = level.time + frames * FRAMETIME;
  163. ent->think = AngleMove_Final;
  164. }
  165. void AngleMove_Calc (edict_t *ent, void(*func)(edict_t*))
  166. {
  167. VectorClear (ent->avelocity);
  168. ent->moveinfo.endfunc = func;
  169. if (level.current_entity == ((ent->flags & FL_TEAMSLAVE) ? ent->teammaster : ent))
  170. {
  171. AngleMove_Begin (ent);
  172. }
  173. else
  174. {
  175. ent->nextthink = level.time + FRAMETIME;
  176. ent->think = AngleMove_Begin;
  177. }
  178. }
  179. /*
  180. ==============
  181. Think_AccelMove
  182. The team has completed a frame of movement, so
  183. change the speed for the next frame
  184. ==============
  185. */
  186. #define AccelerationDistance(target, rate) (target * ((target / rate) + 1) / 2)
  187. void plat_CalcAcceleratedMove(moveinfo_t *moveinfo)
  188. {
  189. float accel_dist;
  190. float decel_dist;
  191. moveinfo->move_speed = moveinfo->speed;
  192. if (moveinfo->remaining_distance < moveinfo->accel)
  193. {
  194. moveinfo->current_speed = moveinfo->remaining_distance;
  195. return;
  196. }
  197. accel_dist = AccelerationDistance (moveinfo->speed, moveinfo->accel);
  198. decel_dist = AccelerationDistance (moveinfo->speed, moveinfo->decel);
  199. if ((moveinfo->remaining_distance - accel_dist - decel_dist) < 0)
  200. {
  201. float f;
  202. f = (moveinfo->accel + moveinfo->decel) / (moveinfo->accel * moveinfo->decel);
  203. moveinfo->move_speed = (-2 + sqrt(4 - 4 * f * (-2 * moveinfo->remaining_distance))) / (2 * f);
  204. decel_dist = AccelerationDistance (moveinfo->move_speed, moveinfo->decel);
  205. }
  206. moveinfo->decel_distance = decel_dist;
  207. };
  208. void plat_Accelerate (moveinfo_t *moveinfo)
  209. {
  210. // are we decelerating?
  211. if (moveinfo->remaining_distance <= moveinfo->decel_distance)
  212. {
  213. if (moveinfo->remaining_distance < moveinfo->decel_distance)
  214. {
  215. if (moveinfo->next_speed)
  216. {
  217. moveinfo->current_speed = moveinfo->next_speed;
  218. moveinfo->next_speed = 0;
  219. return;
  220. }
  221. if (moveinfo->current_speed > moveinfo->decel)
  222. moveinfo->current_speed -= moveinfo->decel;
  223. }
  224. return;
  225. }
  226. // are we at full speed and need to start decelerating during this move?
  227. if (moveinfo->current_speed == moveinfo->move_speed)
  228. if ((moveinfo->remaining_distance - moveinfo->current_speed) < moveinfo->decel_distance)
  229. {
  230. float p1_distance;
  231. float p2_distance;
  232. float distance;
  233. p1_distance = moveinfo->remaining_distance - moveinfo->decel_distance;
  234. p2_distance = moveinfo->move_speed * (1.0 - (p1_distance / moveinfo->move_speed));
  235. distance = p1_distance + p2_distance;
  236. moveinfo->current_speed = moveinfo->move_speed;
  237. moveinfo->next_speed = moveinfo->move_speed - moveinfo->decel * (p2_distance / distance);
  238. return;
  239. }
  240. // are we accelerating?
  241. if (moveinfo->current_speed < moveinfo->speed)
  242. {
  243. float old_speed;
  244. float p1_distance;
  245. float p1_speed;
  246. float p2_distance;
  247. float distance;
  248. old_speed = moveinfo->current_speed;
  249. // figure simple acceleration up to move_speed
  250. moveinfo->current_speed += moveinfo->accel;
  251. if (moveinfo->current_speed > moveinfo->speed)
  252. moveinfo->current_speed = moveinfo->speed;
  253. // are we accelerating throughout this entire move?
  254. if ((moveinfo->remaining_distance - moveinfo->current_speed) >= moveinfo->decel_distance)
  255. return;
  256. // during this move we will accelrate from current_speed to move_speed
  257. // and cross over the decel_distance; figure the average speed for the
  258. // entire move
  259. p1_distance = moveinfo->remaining_distance - moveinfo->decel_distance;
  260. p1_speed = (old_speed + moveinfo->move_speed) / 2.0;
  261. p2_distance = moveinfo->move_speed * (1.0 - (p1_distance / p1_speed));
  262. distance = p1_distance + p2_distance;
  263. moveinfo->current_speed = (p1_speed * (p1_distance / distance)) + (moveinfo->move_speed * (p2_distance / distance));
  264. moveinfo->next_speed = moveinfo->move_speed - moveinfo->decel * (p2_distance / distance);
  265. return;
  266. }
  267. // we are at constant velocity (move_speed)
  268. return;
  269. };
  270. void Think_AccelMove (edict_t *ent)
  271. {
  272. ent->moveinfo.remaining_distance -= ent->moveinfo.current_speed;
  273. if (ent->moveinfo.current_speed == 0) // starting or blocked
  274. plat_CalcAcceleratedMove(&ent->moveinfo);
  275. plat_Accelerate (&ent->moveinfo);
  276. // will the entire move complete on next frame?
  277. if (ent->moveinfo.remaining_distance <= ent->moveinfo.current_speed)
  278. {
  279. Move_Final (ent);
  280. return;
  281. }
  282. VectorScale (ent->moveinfo.dir, ent->moveinfo.current_speed*10, ent->velocity);
  283. ent->nextthink = level.time + FRAMETIME;
  284. ent->think = Think_AccelMove;
  285. }
  286. void plat_go_down (edict_t *ent);
  287. void plat_hit_top (edict_t *ent)
  288. {
  289. if (!(ent->flags & FL_TEAMSLAVE))
  290. {
  291. if (ent->moveinfo.sound_end)
  292. gi.sound (ent, CHAN_NO_PHS_ADD+CHAN_VOICE, ent->moveinfo.sound_end, 1, ATTN_STATIC, 0);
  293. ent->s.sound = 0;
  294. }
  295. ent->moveinfo.state = STATE_TOP;
  296. ent->think = plat_go_down;
  297. ent->nextthink = level.time + 3;
  298. }
  299. void plat_hit_bottom (edict_t *ent)
  300. {
  301. if (!(ent->flags & FL_TEAMSLAVE))
  302. {
  303. if (ent->moveinfo.sound_end)
  304. gi.sound (ent, CHAN_NO_PHS_ADD+CHAN_VOICE, ent->moveinfo.sound_end, 1, ATTN_STATIC, 0);
  305. ent->s.sound = 0;
  306. }
  307. ent->moveinfo.state = STATE_BOTTOM;
  308. }
  309. void plat_go_down (edict_t *ent)
  310. {
  311. if (!(ent->flags & FL_TEAMSLAVE))
  312. {
  313. if (ent->moveinfo.sound_start)
  314. gi.sound (ent, CHAN_NO_PHS_ADD+CHAN_VOICE, ent->moveinfo.sound_start, 1, ATTN_STATIC, 0);
  315. ent->s.sound = ent->moveinfo.sound_middle;
  316. }
  317. ent->moveinfo.state = STATE_DOWN;
  318. Move_Calc (ent, ent->moveinfo.end_origin, plat_hit_bottom);
  319. }
  320. void plat_go_up (edict_t *ent)
  321. {
  322. if (!(ent->flags & FL_TEAMSLAVE))
  323. {
  324. if (ent->moveinfo.sound_start)
  325. gi.sound (ent, CHAN_NO_PHS_ADD+CHAN_VOICE, ent->moveinfo.sound_start, 1, ATTN_STATIC, 0);
  326. ent->s.sound = ent->moveinfo.sound_middle;
  327. }
  328. ent->moveinfo.state = STATE_UP;
  329. Move_Calc (ent, ent->moveinfo.start_origin, plat_hit_top);
  330. }
  331. void plat_blocked (edict_t *self, edict_t *other)
  332. {
  333. if (!(other->svflags & SVF_MONSTER) && (!other->client) )
  334. {
  335. // give it a chance to go away on it's own terms (like gibs)
  336. T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
  337. // if it's still there, nuke it
  338. if (other)
  339. BecomeExplosion1 (other);
  340. return;
  341. }
  342. T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
  343. if (self->moveinfo.state == STATE_UP)
  344. plat_go_down (self);
  345. else if (self->moveinfo.state == STATE_DOWN)
  346. plat_go_up (self);
  347. }
  348. void Use_Plat (edict_t *ent, edict_t *other, edict_t *activator)
  349. {
  350. if (ent->think)
  351. return; // already down
  352. plat_go_down (ent);
  353. }
  354. void Touch_Plat_Center (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
  355. {
  356. if (!other->client)
  357. return;
  358. if (other->health <= 0)
  359. return;
  360. ent = ent->enemy; // now point at the plat, not the trigger
  361. if (ent->moveinfo.state == STATE_BOTTOM)
  362. plat_go_up (ent);
  363. else if (ent->moveinfo.state == STATE_TOP)
  364. ent->nextthink = level.time + 1; // the player is still on the plat, so delay going down
  365. }
  366. void plat_spawn_inside_trigger (edict_t *ent)
  367. {
  368. edict_t *trigger;
  369. vec3_t tmin, tmax;
  370. //
  371. // middle trigger
  372. //
  373. trigger = G_Spawn();
  374. trigger->touch = Touch_Plat_Center;
  375. trigger->movetype = MOVETYPE_NONE;
  376. trigger->solid = SOLID_TRIGGER;
  377. trigger->enemy = ent;
  378. tmin[0] = ent->mins[0] + 25;
  379. tmin[1] = ent->mins[1] + 25;
  380. tmin[2] = ent->mins[2];
  381. tmax[0] = ent->maxs[0] - 25;
  382. tmax[1] = ent->maxs[1] - 25;
  383. tmax[2] = ent->maxs[2] + 8;
  384. tmin[2] = tmax[2] - (ent->pos1[2] - ent->pos2[2] + st.lip);
  385. if (ent->spawnflags & PLAT_LOW_TRIGGER)
  386. tmax[2] = tmin[2] + 8;
  387. if (tmax[0] - tmin[0] <= 0)
  388. {
  389. tmin[0] = (ent->mins[0] + ent->maxs[0]) *0.5;
  390. tmax[0] = tmin[0] + 1;
  391. }
  392. if (tmax[1] - tmin[1] <= 0)
  393. {
  394. tmin[1] = (ent->mins[1] + ent->maxs[1]) *0.5;
  395. tmax[1] = tmin[1] + 1;
  396. }
  397. VectorCopy (tmin, trigger->mins);
  398. VectorCopy (tmax, trigger->maxs);
  399. gi.linkentity (trigger);
  400. }
  401. /*QUAKED func_plat (0 .5 .8) ? PLAT_LOW_TRIGGER
  402. speed default 150
  403. Plats are always drawn in the extended position, so they will light correctly.
  404. 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.
  405. "speed" overrides default 200.
  406. "accel" overrides default 500
  407. "lip" overrides default 8 pixel lip
  408. If the "height" key is set, that will determine the amount the plat moves, instead of being implicitly determoveinfoned by the model's height.
  409. Set "sounds" to one of the following:
  410. 1) base fast
  411. 2) chain slow
  412. */
  413. void SP_func_plat (edict_t *ent)
  414. {
  415. VectorClear (ent->s.angles);
  416. ent->solid = SOLID_BSP;
  417. ent->movetype = MOVETYPE_PUSH;
  418. gi.setmodel (ent, ent->model);
  419. ent->blocked = plat_blocked;
  420. if (!ent->speed)
  421. ent->speed = 20;
  422. else
  423. ent->speed *= 0.1;
  424. if (!ent->accel)
  425. ent->accel = 5;
  426. else
  427. ent->accel *= 0.1;
  428. if (!ent->decel)
  429. ent->decel = 5;
  430. else
  431. ent->decel *= 0.1;
  432. if (!ent->dmg)
  433. ent->dmg = 2;
  434. if (!st.lip)
  435. st.lip = 8;
  436. // pos1 is the top position, pos2 is the bottom
  437. VectorCopy (ent->s.origin, ent->pos1);
  438. VectorCopy (ent->s.origin, ent->pos2);
  439. if (st.height)
  440. ent->pos2[2] -= st.height;
  441. else
  442. ent->pos2[2] -= (ent->maxs[2] - ent->mins[2]) - st.lip;
  443. ent->use = Use_Plat;
  444. plat_spawn_inside_trigger (ent); // the "start moving" trigger
  445. if (ent->targetname)
  446. {
  447. ent->moveinfo.state = STATE_UP;
  448. }
  449. else
  450. {
  451. VectorCopy (ent->pos2, ent->s.origin);
  452. gi.linkentity (ent);
  453. ent->moveinfo.state = STATE_BOTTOM;
  454. }
  455. ent->moveinfo.speed = ent->speed;
  456. ent->moveinfo.accel = ent->accel;
  457. ent->moveinfo.decel = ent->decel;
  458. ent->moveinfo.wait = ent->wait;
  459. VectorCopy (ent->pos1, ent->moveinfo.start_origin);
  460. VectorCopy (ent->s.angles, ent->moveinfo.start_angles);
  461. VectorCopy (ent->pos2, ent->moveinfo.end_origin);
  462. VectorCopy (ent->s.angles, ent->moveinfo.end_angles);
  463. ent->moveinfo.sound_start = gi.soundindex ("plats/pt1_strt.wav");
  464. ent->moveinfo.sound_middle = gi.soundindex ("plats/pt1_mid.wav");
  465. ent->moveinfo.sound_end = gi.soundindex ("plats/pt1_end.wav");
  466. }
  467. //====================================================================
  468. /*QUAKED func_rotating (0 .5 .8) ? START_ON REVERSE X_AXIS Y_AXIS TOUCH_PAIN STOP ANIMATED ANIMATED_FAST
  469. You need to have an origin brush as part of this entity. The center of that brush will be
  470. the point around which it is rotated. It will rotate around the Z axis by default. You can
  471. check either the X_AXIS or Y_AXIS box to change that.
  472. "speed" determines how fast it moves; default value is 100.
  473. "dmg" damage to inflict when blocked (2 default)
  474. REVERSE will cause the it to rotate in the opposite direction.
  475. STOP mean it will stop moving instead of pushing entities
  476. */
  477. void rotating_blocked (edict_t *self, edict_t *other)
  478. {
  479. T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
  480. }
  481. void rotating_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  482. {
  483. if (self->avelocity[0] || self->avelocity[1] || self->avelocity[2])
  484. T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
  485. }
  486. void rotating_use (edict_t *self, edict_t *other, edict_t *activator)
  487. {
  488. if (!VectorCompare (self->avelocity, vec3_origin))
  489. {
  490. self->s.sound = 0;
  491. VectorClear (self->avelocity);
  492. self->touch = NULL;
  493. }
  494. else
  495. {
  496. self->s.sound = self->moveinfo.sound_middle;
  497. VectorScale (self->movedir, self->speed, self->avelocity);
  498. if (self->spawnflags & 16)
  499. self->touch = rotating_touch;
  500. }
  501. }
  502. void SP_func_rotating (edict_t *ent)
  503. {
  504. ent->solid = SOLID_BSP;
  505. if (ent->spawnflags & 32)
  506. ent->movetype = MOVETYPE_STOP;
  507. else
  508. ent->movetype = MOVETYPE_PUSH;
  509. // set the axis of rotation
  510. VectorClear(ent->movedir);
  511. if (ent->spawnflags & 4)
  512. ent->movedir[2] = 1.0;
  513. else if (ent->spawnflags & 8)
  514. ent->movedir[0] = 1.0;
  515. else // Z_AXIS
  516. ent->movedir[1] = 1.0;
  517. // check for reverse rotation
  518. if (ent->spawnflags & 2)
  519. VectorNegate (ent->movedir, ent->movedir);
  520. if (!ent->speed)
  521. ent->speed = 100;
  522. if (!ent->dmg)
  523. ent->dmg = 2;
  524. // ent->moveinfo.sound_middle = "doors/hydro1.wav";
  525. ent->use = rotating_use;
  526. if (ent->dmg)
  527. ent->blocked = rotating_blocked;
  528. if (ent->spawnflags & 1)
  529. ent->use (ent, NULL, NULL);
  530. if (ent->spawnflags & 64)
  531. ent->s.effects |= EF_ANIM_ALL;
  532. if (ent->spawnflags & 128)
  533. ent->s.effects |= EF_ANIM_ALLFAST;
  534. gi.setmodel (ent, ent->model);
  535. gi.linkentity (ent);
  536. }
  537. /*
  538. ======================================================================
  539. BUTTONS
  540. ======================================================================
  541. */
  542. /*QUAKED func_button (0 .5 .8) ?
  543. When a button is touched, it moves some distance in the direction of it's angle, triggers all of it's targets, waits some time, then returns to it's original position where it can be triggered again.
  544. "angle" determines the opening direction
  545. "target" all entities with a matching targetname will be used
  546. "speed" override the default 40 speed
  547. "wait" override the default 1 second wait (-1 = never return)
  548. "lip" override the default 4 pixel lip remaining at end of move
  549. "health" if set, the button must be killed instead of touched
  550. "sounds"
  551. 1) silent
  552. 2) steam metal
  553. 3) wooden clunk
  554. 4) metallic click
  555. 5) in-out
  556. */
  557. void button_done (edict_t *self)
  558. {
  559. self->moveinfo.state = STATE_BOTTOM;
  560. self->s.effects &= ~EF_ANIM23;
  561. self->s.effects |= EF_ANIM01;
  562. }
  563. void button_return (edict_t *self)
  564. {
  565. self->moveinfo.state = STATE_DOWN;
  566. Move_Calc (self, self->moveinfo.start_origin, button_done);
  567. self->s.frame = 0;
  568. if (self->health)
  569. self->takedamage = DAMAGE_YES;
  570. }
  571. void button_wait (edict_t *self)
  572. {
  573. self->moveinfo.state = STATE_TOP;
  574. self->s.effects &= ~EF_ANIM01;
  575. self->s.effects |= EF_ANIM23;
  576. G_UseTargets (self, self->activator);
  577. self->s.frame = 1;
  578. if (self->moveinfo.wait >= 0)
  579. {
  580. self->nextthink = level.time + self->moveinfo.wait;
  581. self->think = button_return;
  582. }
  583. }
  584. void button_fire (edict_t *self)
  585. {
  586. if (self->moveinfo.state == STATE_UP || self->moveinfo.state == STATE_TOP)
  587. return;
  588. self->moveinfo.state = STATE_UP;
  589. if (self->moveinfo.sound_start && !(self->flags & FL_TEAMSLAVE))
  590. gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
  591. Move_Calc (self, self->moveinfo.end_origin, button_wait);
  592. }
  593. void button_use (edict_t *self, edict_t *other, edict_t *activator)
  594. {
  595. self->activator = activator;
  596. button_fire (self);
  597. }
  598. void button_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  599. {
  600. if (!other->client)
  601. return;
  602. if (other->health <= 0)
  603. return;
  604. self->activator = other;
  605. button_fire (self);
  606. }
  607. void button_killed (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  608. {
  609. self->activator = attacker;
  610. self->health = self->max_health;
  611. self->takedamage = DAMAGE_NO;
  612. button_fire (self);
  613. }
  614. void SP_func_button (edict_t *ent)
  615. {
  616. vec3_t abs_movedir;
  617. float dist;
  618. G_SetMovedir (ent->s.angles, ent->movedir);
  619. ent->movetype = MOVETYPE_STOP;
  620. ent->solid = SOLID_BSP;
  621. gi.setmodel (ent, ent->model);
  622. if (ent->sounds != 1)
  623. ent->moveinfo.sound_start = gi.soundindex ("switches/butn2.wav");
  624. if (!ent->speed)
  625. ent->speed = 40;
  626. if (!ent->accel)
  627. ent->accel = ent->speed;
  628. if (!ent->decel)
  629. ent->decel = ent->speed;
  630. if (!ent->wait)
  631. ent->wait = 3;
  632. if (!st.lip)
  633. st.lip = 4;
  634. VectorCopy (ent->s.origin, ent->pos1);
  635. abs_movedir[0] = fabs(ent->movedir[0]);
  636. abs_movedir[1] = fabs(ent->movedir[1]);
  637. abs_movedir[2] = fabs(ent->movedir[2]);
  638. dist = abs_movedir[0] * ent->size[0] + abs_movedir[1] * ent->size[1] + abs_movedir[2] * ent->size[2] - st.lip;
  639. VectorMA (ent->pos1, dist, ent->movedir, ent->pos2);
  640. ent->use = button_use;
  641. ent->s.effects |= EF_ANIM01;
  642. if (ent->health)
  643. {
  644. ent->max_health = ent->health;
  645. ent->die = button_killed;
  646. ent->takedamage = DAMAGE_YES;
  647. }
  648. else if (! ent->targetname)
  649. ent->touch = button_touch;
  650. ent->moveinfo.state = STATE_BOTTOM;
  651. ent->moveinfo.speed = ent->speed;
  652. ent->moveinfo.accel = ent->accel;
  653. ent->moveinfo.decel = ent->decel;
  654. ent->moveinfo.wait = ent->wait;
  655. VectorCopy (ent->pos1, ent->moveinfo.start_origin);
  656. VectorCopy (ent->s.angles, ent->moveinfo.start_angles);
  657. VectorCopy (ent->pos2, ent->moveinfo.end_origin);
  658. VectorCopy (ent->s.angles, ent->moveinfo.end_angles);
  659. gi.linkentity (ent);
  660. }
  661. /*
  662. ======================================================================
  663. DOORS
  664. spawn a trigger surrounding the entire team unless it is
  665. already targeted by another
  666. ======================================================================
  667. */
  668. /*QUAKED func_door (0 .5 .8) ? START_OPEN x CRUSHER NOMONSTER ANIMATED TOGGLE ANIMATED_FAST
  669. TOGGLE wait in both the start and end states for a trigger event.
  670. START_OPEN the door to moves to its destination when spawned, and operate in reverse. It is used to temporarily or permanently close off an area when triggered (not useful for touch or takedamage doors).
  671. NOMONSTER monsters will not trigger this door
  672. "message" is printed when the door is touched if it is a trigger door and it hasn't been fired yet
  673. "angle" determines the opening direction
  674. "targetname" if set, no touch field will be spawned and a remote button or trigger field activates the door.
  675. "health" if set, door must be shot open
  676. "speed" movement speed (100 default)
  677. "wait" wait before returning (3 default, -1 = never return)
  678. "lip" lip remaining at end of move (8 default)
  679. "dmg" damage to inflict when blocked (2 default)
  680. "sounds"
  681. 1) silent
  682. 2) light
  683. 3) medium
  684. 4) heavy
  685. */
  686. void door_use_areaportals (edict_t *self, qboolean open)
  687. {
  688. edict_t *t = NULL;
  689. if (!self->target)
  690. return;
  691. while ((t = G_Find (t, FOFS(targetname), self->target)))
  692. {
  693. if (Q_stricmp(t->classname, "func_areaportal") == 0)
  694. {
  695. gi.SetAreaPortalState (t->style, open);
  696. }
  697. }
  698. }
  699. void door_go_down (edict_t *self);
  700. void door_hit_top (edict_t *self)
  701. {
  702. if (!(self->flags & FL_TEAMSLAVE))
  703. {
  704. if (self->moveinfo.sound_end)
  705. gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_end, 1, ATTN_STATIC, 0);
  706. self->s.sound = 0;
  707. }
  708. self->moveinfo.state = STATE_TOP;
  709. if (self->spawnflags & DOOR_TOGGLE)
  710. return;
  711. if (self->moveinfo.wait >= 0)
  712. {
  713. self->think = door_go_down;
  714. self->nextthink = level.time + self->moveinfo.wait;
  715. }
  716. }
  717. void door_hit_bottom (edict_t *self)
  718. {
  719. if (!(self->flags & FL_TEAMSLAVE))
  720. {
  721. if (self->moveinfo.sound_end)
  722. gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_end, 1, ATTN_STATIC, 0);
  723. self->s.sound = 0;
  724. }
  725. self->moveinfo.state = STATE_BOTTOM;
  726. door_use_areaportals (self, false);
  727. }
  728. void door_go_down (edict_t *self)
  729. {
  730. if (!(self->flags & FL_TEAMSLAVE))
  731. {
  732. if (self->moveinfo.sound_start)
  733. gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
  734. self->s.sound = self->moveinfo.sound_middle;
  735. }
  736. if (self->max_health)
  737. {
  738. self->takedamage = DAMAGE_YES;
  739. self->health = self->max_health;
  740. }
  741. self->moveinfo.state = STATE_DOWN;
  742. if (strcmp(self->classname, "func_door") == 0)
  743. Move_Calc (self, self->moveinfo.start_origin, door_hit_bottom);
  744. else if (strcmp(self->classname, "func_door_rotating") == 0)
  745. AngleMove_Calc (self, door_hit_bottom);
  746. }
  747. void door_go_up (edict_t *self, edict_t *activator)
  748. {
  749. if (self->moveinfo.state == STATE_UP)
  750. return; // already going up
  751. if (self->moveinfo.state == STATE_TOP)
  752. { // reset top wait time
  753. if (self->moveinfo.wait >= 0)
  754. self->nextthink = level.time + self->moveinfo.wait;
  755. return;
  756. }
  757. if (!(self->flags & FL_TEAMSLAVE))
  758. {
  759. if (self->moveinfo.sound_start)
  760. gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
  761. self->s.sound = self->moveinfo.sound_middle;
  762. }
  763. self->moveinfo.state = STATE_UP;
  764. if (strcmp(self->classname, "func_door") == 0)
  765. Move_Calc (self, self->moveinfo.end_origin, door_hit_top);
  766. else if (strcmp(self->classname, "func_door_rotating") == 0)
  767. AngleMove_Calc (self, door_hit_top);
  768. G_UseTargets (self, activator);
  769. door_use_areaportals (self, true);
  770. }
  771. void door_use (edict_t *self, edict_t *other, edict_t *activator)
  772. {
  773. edict_t *ent;
  774. if (self->flags & FL_TEAMSLAVE)
  775. return;
  776. if (self->spawnflags & DOOR_TOGGLE)
  777. {
  778. if (self->moveinfo.state == STATE_UP || self->moveinfo.state == STATE_TOP)
  779. {
  780. // trigger all paired doors
  781. for (ent = self ; ent ; ent = ent->teamchain)
  782. {
  783. ent->message = NULL;
  784. ent->touch = NULL;
  785. door_go_down (ent);
  786. }
  787. return;
  788. }
  789. }
  790. // trigger all paired doors
  791. for (ent = self ; ent ; ent = ent->teamchain)
  792. {
  793. ent->message = NULL;
  794. ent->touch = NULL;
  795. door_go_up (ent, activator);
  796. }
  797. };
  798. void Touch_DoorTrigger (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  799. {
  800. if (other->health <= 0)
  801. return;
  802. if (!(other->svflags & SVF_MONSTER) && (!other->client))
  803. return;
  804. if ((self->owner->spawnflags & DOOR_NOMONSTER) && (other->svflags & SVF_MONSTER))
  805. return;
  806. if (level.time < self->touch_debounce_time)
  807. return;
  808. self->touch_debounce_time = level.time + 1.0;
  809. door_use (self->owner, other, other);
  810. }
  811. void Think_CalcMoveSpeed (edict_t *self)
  812. {
  813. edict_t *ent;
  814. float min;
  815. float time;
  816. float newspeed;
  817. float ratio;
  818. float dist;
  819. if (self->flags & FL_TEAMSLAVE)
  820. return; // only the team master does this
  821. // find the smallest distance any member of the team will be moving
  822. min = fabs(self->moveinfo.distance);
  823. for (ent = self->teamchain; ent; ent = ent->teamchain)
  824. {
  825. dist = fabs(ent->moveinfo.distance);
  826. if (dist < min)
  827. min = dist;
  828. }
  829. time = min / self->moveinfo.speed;
  830. // adjust speeds so they will all complete at the same time
  831. for (ent = self; ent; ent = ent->teamchain)
  832. {
  833. newspeed = fabs(ent->moveinfo.distance) / time;
  834. ratio = newspeed / ent->moveinfo.speed;
  835. if (ent->moveinfo.accel == ent->moveinfo.speed)
  836. ent->moveinfo.accel = newspeed;
  837. else
  838. ent->moveinfo.accel *= ratio;
  839. if (ent->moveinfo.decel == ent->moveinfo.speed)
  840. ent->moveinfo.decel = newspeed;
  841. else
  842. ent->moveinfo.decel *= ratio;
  843. ent->moveinfo.speed = newspeed;
  844. }
  845. }
  846. void Think_SpawnDoorTrigger (edict_t *ent)
  847. {
  848. edict_t *other;
  849. vec3_t mins, maxs;
  850. if (ent->flags & FL_TEAMSLAVE)
  851. return; // only the team leader spawns a trigger
  852. VectorCopy (ent->absmin, mins);
  853. VectorCopy (ent->absmax, maxs);
  854. for (other = ent->teamchain ; other ; other=other->teamchain)
  855. {
  856. AddPointToBounds (other->absmin, mins, maxs);
  857. AddPointToBounds (other->absmax, mins, maxs);
  858. }
  859. // expand
  860. mins[0] -= 60;
  861. mins[1] -= 60;
  862. maxs[0] += 60;
  863. maxs[1] += 60;
  864. other = G_Spawn ();
  865. VectorCopy (mins, other->mins);
  866. VectorCopy (maxs, other->maxs);
  867. other->owner = ent;
  868. other->solid = SOLID_TRIGGER;
  869. other->movetype = MOVETYPE_NONE;
  870. other->touch = Touch_DoorTrigger;
  871. gi.linkentity (other);
  872. if (ent->spawnflags & DOOR_START_OPEN)
  873. door_use_areaportals (ent, true);
  874. Think_CalcMoveSpeed (ent);
  875. }
  876. void door_blocked (edict_t *self, edict_t *other)
  877. {
  878. edict_t *ent;
  879. if (!(other->svflags & SVF_MONSTER) && (!other->client) )
  880. {
  881. // give it a chance to go away on it's own terms (like gibs)
  882. T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
  883. // if it's still there, nuke it
  884. if (other)
  885. BecomeExplosion1 (other);
  886. return;
  887. }
  888. T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
  889. if (self->spawnflags & DOOR_CRUSHER)
  890. return;
  891. // if a door has a negative wait, it would never come back if blocked,
  892. // so let it just squash the object to death real fast
  893. if (self->moveinfo.wait >= 0)
  894. {
  895. if (self->moveinfo.state == STATE_DOWN)
  896. {
  897. for (ent = self->teammaster ; ent ; ent = ent->teamchain)
  898. door_go_up (ent, ent->activator);
  899. }
  900. else
  901. {
  902. for (ent = self->teammaster ; ent ; ent = ent->teamchain)
  903. door_go_down (ent);
  904. }
  905. }
  906. }
  907. void door_killed (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  908. {
  909. edict_t *ent;
  910. for (ent = self->teammaster ; ent ; ent = ent->teamchain)
  911. {
  912. ent->health = ent->max_health;
  913. ent->takedamage = DAMAGE_NO;
  914. }
  915. door_use (self->teammaster, attacker, attacker);
  916. }
  917. void door_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  918. {
  919. if (!other->client)
  920. return;
  921. if (level.time < self->touch_debounce_time)
  922. return;
  923. self->touch_debounce_time = level.time + 5.0;
  924. gi.centerprintf (other, "%s", self->message);
  925. gi.sound (other, CHAN_AUTO, gi.soundindex ("misc/talk1.wav"), 1, ATTN_NORM, 0);
  926. }
  927. void SP_func_door (edict_t *ent)
  928. {
  929. vec3_t abs_movedir;
  930. if (ent->sounds != 1)
  931. {
  932. ent->moveinfo.sound_start = gi.soundindex ("doors/dr1_strt.wav");
  933. ent->moveinfo.sound_middle = gi.soundindex ("doors/dr1_mid.wav");
  934. ent->moveinfo.sound_end = gi.soundindex ("doors/dr1_end.wav");
  935. }
  936. G_SetMovedir (ent->s.angles, ent->movedir);
  937. ent->movetype = MOVETYPE_PUSH;
  938. ent->solid = SOLID_BSP;
  939. gi.setmodel (ent, ent->model);
  940. ent->blocked = door_blocked;
  941. ent->use = door_use;
  942. if (!ent->speed)
  943. ent->speed = 100;
  944. if (deathmatch->value)
  945. ent->speed *= 2;
  946. if (!ent->accel)
  947. ent->accel = ent->speed;
  948. if (!ent->decel)
  949. ent->decel = ent->speed;
  950. if (!ent->wait)
  951. ent->wait = 3;
  952. if (!st.lip)
  953. st.lip = 8;
  954. if (!ent->dmg)
  955. ent->dmg = 2;
  956. // calculate second position
  957. VectorCopy (ent->s.origin, ent->pos1);
  958. abs_movedir[0] = fabs(ent->movedir[0]);
  959. abs_movedir[1] = fabs(ent->movedir[1]);
  960. abs_movedir[2] = fabs(ent->movedir[2]);
  961. ent->moveinfo.distance = abs_movedir[0] * ent->size[0] + abs_movedir[1] * ent->size[1] + abs_movedir[2] * ent->size[2] - st.lip;
  962. VectorMA (ent->pos1, ent->moveinfo.distance, ent->movedir, ent->pos2);
  963. // if it starts open, switch the positions
  964. if (ent->spawnflags & DOOR_START_OPEN)
  965. {
  966. VectorCopy (ent->pos2, ent->s.origin);
  967. VectorCopy (ent->pos1, ent->pos2);
  968. VectorCopy (ent->s.origin, ent->pos1);
  969. }
  970. ent->moveinfo.state = STATE_BOTTOM;
  971. if (ent->health)
  972. {
  973. ent->takedamage = DAMAGE_YES;
  974. ent->die = door_killed;
  975. ent->max_health = ent->health;
  976. }
  977. else if (ent->targetname && ent->message)
  978. {
  979. gi.soundindex ("misc/talk.wav");
  980. ent->touch = door_touch;
  981. }
  982. ent->moveinfo.speed = ent->speed;
  983. ent->moveinfo.accel = ent->accel;
  984. ent->moveinfo.decel = ent->decel;
  985. ent->moveinfo.wait = ent->wait;
  986. VectorCopy (ent->pos1, ent->moveinfo.start_origin);
  987. VectorCopy (ent->s.angles, ent->moveinfo.start_angles);
  988. VectorCopy (ent->pos2, ent->moveinfo.end_origin);
  989. VectorCopy (ent->s.angles, ent->moveinfo.end_angles);
  990. if (ent->spawnflags & 16)
  991. ent->s.effects |= EF_ANIM_ALL;
  992. if (ent->spawnflags & 64)
  993. ent->s.effects |= EF_ANIM_ALLFAST;
  994. // to simplify logic elsewhere, make non-teamed doors into a team of one
  995. if (!ent->team)
  996. ent->teammaster = ent;
  997. gi.linkentity (ent);
  998. ent->nextthink = level.time + FRAMETIME;
  999. if (ent->health || ent->targetname)
  1000. ent->think = Think_CalcMoveSpeed;
  1001. else
  1002. ent->think = Think_SpawnDoorTrigger;
  1003. }
  1004. /*QUAKED func_door_rotating (0 .5 .8) ? START_OPEN REVERSE CRUSHER NOMONSTER ANIMATED TOGGLE X_AXIS Y_AXIS
  1005. TOGGLE causes the door to wait in both the start and end states for a trigger event.
  1006. START_OPEN the door to moves to its destination when spawned, and operate in reverse. It is used to temporarily or permanently close off an area when triggered (not useful for touch or takedamage doors).
  1007. NOMONSTER monsters will not trigger this door
  1008. You need to have an origin brush as part of this entity. The center of that brush will be
  1009. the point around which it is rotated. It will rotate around the Z axis by default. You can
  1010. check either the X_AXIS or Y_AXIS box to change that.
  1011. "distance" is how many degrees the door will be rotated.
  1012. "speed" determines how fast the door moves; default value is 100.
  1013. REVERSE will cause the door to rotate in the opposite direction.
  1014. "message" is printed when the door is touched if it is a trigger door and it hasn't been fired yet
  1015. "angle" determines the opening direction
  1016. "targetname" if set, no touch field will be spawned and a remote button or trigger field activates the door.
  1017. "health" if set, door must be shot open
  1018. "speed" movement speed (100 default)
  1019. "wait" wait before returning (3 default, -1 = never return)
  1020. "dmg" damage to inflict when blocked (2 default)
  1021. "sounds"
  1022. 1) silent
  1023. 2) light
  1024. 3) medium
  1025. 4) heavy
  1026. */
  1027. void SP_func_door_rotating (edict_t *ent)
  1028. {
  1029. VectorClear (ent->s.angles);
  1030. // set the axis of rotation
  1031. VectorClear(ent->movedir);
  1032. if (ent->spawnflags & DOOR_X_AXIS)
  1033. ent->movedir[2] = 1.0;
  1034. else if (ent->spawnflags & DOOR_Y_AXIS)
  1035. ent->movedir[0] = 1.0;
  1036. else // Z_AXIS
  1037. ent->movedir[1] = 1.0;
  1038. // check for reverse rotation
  1039. if (ent->spawnflags & DOOR_REVERSE)
  1040. VectorNegate (ent->movedir, ent->movedir);
  1041. if (!st.distance)
  1042. {
  1043. gi.dprintf("%s at %s with no distance set\n", ent->classname, vtos(ent->s.origin));
  1044. st.distance = 90;
  1045. }
  1046. VectorCopy (ent->s.angles, ent->pos1);
  1047. VectorMA (ent->s.angles, st.distance, ent->movedir, ent->pos2);
  1048. ent->moveinfo.distance = st.distance;
  1049. ent->movetype = MOVETYPE_PUSH;
  1050. ent->solid = SOLID_BSP;
  1051. gi.setmodel (ent, ent->model);
  1052. ent->blocked = door_blocked;
  1053. ent->use = door_use;
  1054. if (!ent->speed)
  1055. ent->speed = 100;
  1056. if (!ent->accel)
  1057. ent->accel = ent->speed;
  1058. if (!ent->decel)
  1059. ent->decel = ent->speed;
  1060. if (!ent->wait)
  1061. ent->wait = 3;
  1062. if (!ent->dmg)
  1063. ent->dmg = 2;
  1064. if (ent->sounds != 1)
  1065. {
  1066. ent->moveinfo.sound_start = gi.soundindex ("doors/dr1_strt.wav");
  1067. ent->moveinfo.sound_middle = gi.soundindex ("doors/dr1_mid.wav");
  1068. ent->moveinfo.sound_end = gi.soundindex ("doors/dr1_end.wav");
  1069. }
  1070. // if it starts open, switch the positions
  1071. if (ent->spawnflags & DOOR_START_OPEN)
  1072. {
  1073. VectorCopy (ent->pos2, ent->s.angles);
  1074. VectorCopy (ent->pos1, ent->pos2);
  1075. VectorCopy (ent->s.angles, ent->pos1);
  1076. VectorNegate (ent->movedir, ent->movedir);
  1077. }
  1078. if (ent->health)
  1079. {
  1080. ent->takedamage = DAMAGE_YES;
  1081. ent->die = door_killed;
  1082. ent->max_health = ent->health;
  1083. }
  1084. if (ent->targetname && ent->message)
  1085. {
  1086. gi.soundindex ("misc/talk.wav");
  1087. ent->touch = door_touch;
  1088. }
  1089. ent->moveinfo.state = STATE_BOTTOM;
  1090. ent->moveinfo.speed = ent->speed;
  1091. ent->moveinfo.accel = ent->accel;
  1092. ent->moveinfo.decel = ent->decel;
  1093. ent->moveinfo.wait = ent->wait;
  1094. VectorCopy (ent->s.origin, ent->moveinfo.start_origin);
  1095. VectorCopy (ent->pos1, ent->moveinfo.start_angles);
  1096. VectorCopy (ent->s.origin, ent->moveinfo.end_origin);
  1097. VectorCopy (ent->pos2, ent->moveinfo.end_angles);
  1098. if (ent->spawnflags & 16)
  1099. ent->s.effects |= EF_ANIM_ALL;
  1100. // to simplify logic elsewhere, make non-teamed doors into a team of one
  1101. if (!ent->team)
  1102. ent->teammaster = ent;
  1103. gi.linkentity (ent);
  1104. ent->nextthink = level.time + FRAMETIME;
  1105. if (ent->health || ent->targetname)
  1106. ent->think = Think_CalcMoveSpeed;
  1107. else
  1108. ent->think = Think_SpawnDoorTrigger;
  1109. }
  1110. /*QUAKED func_water (0 .5 .8) ? START_OPEN
  1111. func_water is a moveable water brush. It must be targeted to operate. Use a non-water texture at your own risk.
  1112. START_OPEN causes the water to move to its destination when spawned and operate in reverse.
  1113. "angle" determines the opening direction (up or down only)
  1114. "speed" movement speed (25 default)
  1115. "wait" wait before returning (-1 default, -1 = TOGGLE)
  1116. "lip" lip remaining at end of move (0 default)
  1117. "sounds" (yes, these need to be changed)
  1118. 0) no sound
  1119. 1) water
  1120. 2) lava
  1121. */
  1122. void SP_func_water (edict_t *self)
  1123. {
  1124. vec3_t abs_movedir;
  1125. G_SetMovedir (self->s.angles, self->movedir);
  1126. self->movetype = MOVETYPE_PUSH;
  1127. self->solid = SOLID_BSP;
  1128. gi.setmodel (self, self->model);
  1129. switch (self->sounds)
  1130. {
  1131. default:
  1132. break;
  1133. case 1: // water
  1134. self->moveinfo.sound_start = gi.soundindex ("world/mov_watr.wav");
  1135. self->moveinfo.sound_end = gi.soundindex ("world/stp_watr.wav");
  1136. break;
  1137. case 2: // lava
  1138. self->moveinfo.sound_start = gi.soundindex ("world/mov_watr.wav");
  1139. self->moveinfo.sound_end = gi.soundindex ("world/stp_watr.wav");
  1140. break;
  1141. }
  1142. // calculate second position
  1143. VectorCopy (self->s.origin, self->pos1);
  1144. abs_movedir[0] = fabs(self->movedir[0]);
  1145. abs_movedir[1] = fabs(self->movedir[1]);
  1146. abs_movedir[2] = fabs(self->movedir[2]);
  1147. self->moveinfo.distance = abs_movedir[0] * self->size[0] + abs_movedir[1] * self->size[1] + abs_movedir[2] * self->size[2] - st.lip;
  1148. VectorMA (self->pos1, self->moveinfo.distance, self->movedir, self->pos2);
  1149. // if it starts open, switch the positions
  1150. if (self->spawnflags & DOOR_START_OPEN)
  1151. {
  1152. VectorCopy (self->pos2, self->s.origin);
  1153. VectorCopy (self->pos1, self->pos2);
  1154. VectorCopy (self->s.origin, self->pos1);
  1155. }
  1156. VectorCopy (self->pos1, self->moveinfo.start_origin);
  1157. VectorCopy (self->s.angles, self->moveinfo.start_angles);
  1158. VectorCopy (self->pos2, self->moveinfo.end_origin);
  1159. VectorCopy (self->s.angles, self->moveinfo.end_angles);
  1160. self->moveinfo.state = STATE_BOTTOM;
  1161. if (!self->speed)
  1162. self->speed = 25;
  1163. self->moveinfo.accel = self->moveinfo.decel = self->moveinfo.speed = self->speed;
  1164. if (!self->wait)
  1165. self->wait = -1;
  1166. self->moveinfo.wait = self->wait;
  1167. self->use = door_use;
  1168. if (self->wait == -1)
  1169. self->spawnflags |= DOOR_TOGGLE;
  1170. self->classname = "func_door";
  1171. gi.linkentity (self);
  1172. }
  1173. #define TRAIN_START_ON 1
  1174. #define TRAIN_TOGGLE 2
  1175. #define TRAIN_BLOCK_STOPS 4
  1176. /*QUAKED func_train (0 .5 .8) ? START_ON TOGGLE BLOCK_STOPS
  1177. Trains are moving platforms that players can ride.
  1178. The targets origin specifies the min point of the train at each corner.
  1179. The train spawns at the first target it is pointing at.
  1180. If the train is the target of a button or trigger, it will not begin moving until activated.
  1181. speed default 100
  1182. dmg default 2
  1183. noise looping sound to play when the train is in motion
  1184. */
  1185. void train_next (edict_t *self);
  1186. void train_blocked (edict_t *self, edict_t *other)
  1187. {
  1188. if (!(other->svflags & SVF_MONSTER) && (!other->client) )
  1189. {
  1190. // give it a chance to go away on it's own terms (like gibs)
  1191. T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
  1192. // if it's still there, nuke it
  1193. if (other)
  1194. BecomeExplosion1 (other);
  1195. return;
  1196. }
  1197. if (level.time < self->touch_debounce_time)
  1198. return;
  1199. if (!self->dmg)
  1200. return;
  1201. self->touch_debounce_time = level.time + 0.5;
  1202. T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
  1203. }
  1204. void train_wait (edict_t *self)
  1205. {
  1206. if (self->target_ent->pathtarget)
  1207. {
  1208. char *savetarget;
  1209. edict_t *ent;
  1210. ent = self->target_ent;
  1211. savetarget = ent->target;
  1212. ent->target = ent->pathtarget;
  1213. G_UseTargets (ent, self->activator);
  1214. ent->target = savetarget;
  1215. // make sure we didn't get killed by a killtarget
  1216. if (!self->inuse)
  1217. return;
  1218. }
  1219. if (self->moveinfo.wait)
  1220. {
  1221. if (self->moveinfo.wait > 0)
  1222. {
  1223. self->nextthink = level.time + self->moveinfo.wait;
  1224. self->think = train_next;
  1225. }
  1226. else if (self->spawnflags & TRAIN_TOGGLE) // && wait < 0
  1227. {
  1228. train_next (self);
  1229. self->spawnflags &= ~TRAIN_START_ON;
  1230. VectorClear (self->velocity);
  1231. self->nextthink = 0;
  1232. }
  1233. if (!(self->flags & FL_TEAMSLAVE))
  1234. {
  1235. if (self->moveinfo.sound_end)
  1236. gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_end, 1, ATTN_STATIC, 0);
  1237. self->s.sound = 0;
  1238. }
  1239. }
  1240. else
  1241. {
  1242. train_next (self);
  1243. }
  1244. }
  1245. void train_next (edict_t *self)
  1246. {
  1247. edict_t *ent;
  1248. vec3_t dest;
  1249. qboolean first;
  1250. first = true;
  1251. again:
  1252. if (!self->target)
  1253. {
  1254. // gi.dprintf ("train_next: no next target\n");
  1255. return;
  1256. }
  1257. ent = G_PickTarget (self->target);
  1258. if (!ent)
  1259. {
  1260. gi.dprintf ("train_next: bad target %s\n", self->target);
  1261. return;
  1262. }
  1263. self->target = ent->target;
  1264. // check for a teleport path_corner
  1265. if (ent->spawnflags & 1)
  1266. {
  1267. if (!first)
  1268. {
  1269. gi.dprintf ("connected teleport path_corners, see %s at %s\n", ent->classname, vtos(ent->s.origin));
  1270. return;
  1271. }
  1272. first = false;
  1273. VectorSubtract (ent->s.origin, self->mins, self->s.origin);
  1274. VectorCopy (self->s.origin, self->s.old_origin);
  1275. self->s.event = EV_OTHER_TELEPORT;
  1276. gi.linkentity (self);
  1277. goto again;
  1278. }
  1279. self->moveinfo.wait = ent->wait;
  1280. self->target_ent = ent;
  1281. if (!(self->flags & FL_TEAMSLAVE))
  1282. {
  1283. if (self->moveinfo.sound_start)
  1284. gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
  1285. self->s.sound = self->moveinfo.sound_middle;
  1286. }
  1287. VectorSubtract (ent->s.origin, self->mins, dest);
  1288. self->moveinfo.state = STATE_TOP;
  1289. VectorCopy (self->s.origin, self->moveinfo.start_origin);
  1290. VectorCopy (dest, self->moveinfo.end_origin);
  1291. Move_Calc (self, dest, train_wait);
  1292. self->spawnflags |= TRAIN_START_ON;
  1293. }
  1294. void train_resume (edict_t *self)
  1295. {
  1296. edict_t *ent;
  1297. vec3_t dest;
  1298. ent = self->target_ent;
  1299. VectorSubtract (ent->s.origin, self->mins, dest);
  1300. self->moveinfo.state = STATE_TOP;
  1301. VectorCopy (self->s.origin, self->moveinfo.start_origin);
  1302. VectorCopy (dest, self->moveinfo.end_origin);
  1303. Move_Calc (self, dest, train_wait);
  1304. self->spawnflags |= TRAIN_START_ON;
  1305. }
  1306. void func_train_find (edict_t *self)
  1307. {
  1308. edict_t *ent;
  1309. if (!self->target)
  1310. {
  1311. gi.dprintf ("train_find: no target\n");
  1312. return;
  1313. }
  1314. ent = G_PickTarget (self->target);
  1315. if (!ent)
  1316. {
  1317. gi.dprintf ("train_find: target %s not found\n", self->target);
  1318. return;
  1319. }
  1320. self->target = ent->target;
  1321. VectorSubtract (ent->s.origin, self->mins, self->s.origin);
  1322. gi.linkentity (self);
  1323. // if not triggered, start immediately
  1324. if (!self->targetname)
  1325. self->spawnflags |= TRAIN_START_ON;
  1326. if (self->spawnflags & TRAIN_START_ON)
  1327. {
  1328. self->nextthink = level.time + FRAMETIME;
  1329. self->think = train_next;
  1330. self->activator = self;
  1331. }
  1332. }
  1333. void train_use (edict_t *self, edict_t *other, edict_t *activator)
  1334. {
  1335. self->activator = activator;
  1336. if (self->spawnflags & TRAIN_START_ON)
  1337. {
  1338. if (!(self->spawnflags & TRAIN_TOGGLE))
  1339. return;
  1340. self->spawnflags &= ~TRAIN_START_ON;
  1341. VectorClear (self->velocity);
  1342. self->nextthink = 0;
  1343. }
  1344. else
  1345. {
  1346. if (self->target_ent)
  1347. train_resume(self);
  1348. else
  1349. train_next(self);
  1350. }
  1351. }
  1352. void SP_func_train (edict_t *self)
  1353. {
  1354. self->movetype = MOVETYPE_PUSH;
  1355. VectorClear (self->s.angles);
  1356. self->blocked = train_blocked;
  1357. if (self->spawnflags & TRAIN_BLOCK_STOPS)
  1358. self->dmg = 0;
  1359. else
  1360. {
  1361. if (!self->dmg)
  1362. self->dmg = 100;
  1363. }
  1364. self->solid = SOLID_BSP;
  1365. gi.setmodel (self, self->model);
  1366. if (st.noise)
  1367. self->moveinfo.sound_middle = gi.soundindex (st.noise);
  1368. if (!self->speed)
  1369. self->speed = 100;
  1370. self->moveinfo.speed = self->speed;
  1371. self->moveinfo.accel = self->moveinfo.decel = self->moveinfo.speed;
  1372. self->use = train_use;
  1373. gi.linkentity (self);
  1374. if (self->target)
  1375. {
  1376. // start trains on the second frame, to make sure their targets have had
  1377. // a chance to spawn
  1378. self->nextthink = level.time + FRAMETIME;
  1379. self->think = func_train_find;
  1380. }
  1381. else
  1382. {
  1383. gi.dprintf ("func_train without a target at %s\n", vtos(self->absmin));
  1384. }
  1385. }
  1386. /*QUAKED trigger_elevator (0.3 0.1 0.6) (-8 -8 -8) (8 8 8)
  1387. */
  1388. void trigger_elevator_use (edict_t *self, edict_t *other, edict_t *activator)
  1389. {
  1390. edict_t *target;
  1391. if (self->movetarget->nextthink)
  1392. {
  1393. // gi.dprintf("elevator busy\n");
  1394. return;
  1395. }
  1396. if (!other->pathtarget)
  1397. {
  1398. gi.dprintf("elevator used with no pathtarget\n");
  1399. return;
  1400. }
  1401. target = G_PickTarget (other->pathtarget);
  1402. if (!target)
  1403. {
  1404. gi.dprintf("elevator used with bad pathtarget: %s\n", other->pathtarget);
  1405. return;
  1406. }
  1407. self->movetarget->target_ent = target;
  1408. train_resume (self->movetarget);
  1409. }
  1410. void trigger_elevator_init (edict_t *self)
  1411. {
  1412. if (!self->target)
  1413. {
  1414. gi.dprintf("trigger_elevator has no target\n");
  1415. return;
  1416. }
  1417. self->movetarget = G_PickTarget (self->target);
  1418. if (!self->movetarget)
  1419. {
  1420. gi.dprintf("trigger_elevator unable to find target %s\n", self->target);
  1421. return;
  1422. }
  1423. if (strcmp(self->movetarget->classname, "func_train") != 0)
  1424. {
  1425. gi.dprintf("trigger_elevator target %s is not a train\n", self->target);
  1426. return;
  1427. }
  1428. self->use = trigger_elevator_use;
  1429. self->svflags = SVF_NOCLIENT;
  1430. }
  1431. void SP_trigger_elevator (edict_t *self)
  1432. {
  1433. self->think = trigger_elevator_init;
  1434. self->nextthink = level.time + FRAMETIME;
  1435. }
  1436. /*QUAKED func_timer (0.3 0.1 0.6) (-8 -8 -8) (8 8 8) START_ON
  1437. "wait" base time between triggering all targets, default is 1
  1438. "random" wait variance, default is 0
  1439. so, the basic time between firing is a random time between
  1440. (wait - random) and (wait + random)
  1441. "delay" delay before first firing when turned on, default is 0
  1442. "pausetime" additional delay used only the very first time
  1443. and only if spawned with START_ON
  1444. These can used but not touched.
  1445. */
  1446. void func_timer_think (edict_t *self)
  1447. {
  1448. G_UseTargets (self, self->activator);
  1449. self->nextthink = level.time + self->wait + crandom() * self->random;
  1450. }
  1451. void func_timer_use (edict_t *self, edict_t *other, edict_t *activator)
  1452. {
  1453. self->activator = activator;
  1454. // if on, turn it off
  1455. if (self->nextthink)
  1456. {
  1457. self->nextthink = 0;
  1458. return;
  1459. }
  1460. // turn it on
  1461. if (self->delay)
  1462. self->nextthink = level.time + self->delay;
  1463. else
  1464. func_timer_think (self);
  1465. }
  1466. void SP_func_timer (edict_t *self)
  1467. {
  1468. if (!self->wait)
  1469. self->wait = 1.0;
  1470. self->use = func_timer_use;
  1471. self->think = func_timer_think;
  1472. if (self->random >= self->wait)
  1473. {
  1474. self->random = self->wait - FRAMETIME;
  1475. gi.dprintf("func_timer at %s has random >= wait\n", vtos(self->s.origin));
  1476. }
  1477. if (self->spawnflags & 1)
  1478. {
  1479. self->nextthink = level.time + 1.0 + st.pausetime + self->delay + self->wait + crandom() * self->random;
  1480. self->activator = self;
  1481. }
  1482. self->svflags = SVF_NOCLIENT;
  1483. }
  1484. /*QUAKED func_conveyor (0 .5 .8) ? START_ON TOGGLE
  1485. Conveyors are stationary brushes that move what's on them.
  1486. The brush should be have a surface with at least one current content enabled.
  1487. speed default 100
  1488. */
  1489. void func_conveyor_use (edict_t *self, edict_t *other, edict_t *activator)
  1490. {
  1491. if (self->spawnflags & 1)
  1492. {
  1493. self->speed = 0;
  1494. self->spawnflags &= ~1;
  1495. }
  1496. else
  1497. {
  1498. self->speed = self->count;
  1499. self->spawnflags |= 1;
  1500. }
  1501. if (!(self->spawnflags & 2))
  1502. self->count = 0;
  1503. }
  1504. void SP_func_conveyor (edict_t *self)
  1505. {
  1506. if (!self->speed)
  1507. self->speed = 100;
  1508. if (!(self->spawnflags & 1))
  1509. {
  1510. self->count = self->speed;
  1511. self->speed = 0;
  1512. }
  1513. self->use = func_conveyor_use;
  1514. gi.setmodel (self, self->model);
  1515. self->solid = SOLID_BSP;
  1516. gi.linkentity (self);
  1517. }
  1518. /*QUAKED func_door_secret (0 .5 .8) ? always_shoot 1st_left 1st_down
  1519. A secret door. Slide back and then to the side.
  1520. open_once doors never closes
  1521. 1st_left 1st move is left of arrow
  1522. 1st_down 1st move is down from arrow
  1523. always_shoot door is shootebale even if targeted
  1524. "angle" determines the direction
  1525. "dmg" damage to inflic when blocked (default 2)
  1526. "wait" how long to hold in the open position (default 5, -1 means hold)
  1527. */
  1528. #define SECRET_ALWAYS_SHOOT 1
  1529. #define SECRET_1ST_LEFT 2
  1530. #define SECRET_1ST_DOWN 4
  1531. void door_secret_move1 (edict_t *self);
  1532. void door_secret_move2 (edict_t *self);
  1533. void door_secret_move3 (edict_t *self);
  1534. void door_secret_move4 (edict_t *self);
  1535. void door_secret_move5 (edict_t *self);
  1536. void door_secret_move6 (edict_t *self);
  1537. void door_secret_done (edict_t *self);
  1538. void door_secret_use (edict_t *self, edict_t *other, edict_t *activator)
  1539. {
  1540. // make sure we're not already moving
  1541. if (!VectorCompare(self->s.origin, vec3_origin))
  1542. return;
  1543. Move_Calc (self, self->pos1, door_secret_move1);
  1544. door_use_areaportals (self, true);
  1545. }
  1546. void door_secret_move1 (edict_t *self)
  1547. {
  1548. self->nextthink = level.time + 1.0;
  1549. self->think = door_secret_move2;
  1550. }
  1551. void door_secret_move2 (edict_t *self)
  1552. {
  1553. Move_Calc (self, self->pos2, door_secret_move3);
  1554. }
  1555. void door_secret_move3 (edict_t *self)
  1556. {
  1557. if (self->wait == -1)
  1558. return;
  1559. self->nextthink = level.time + self->wait;
  1560. self->think = door_secret_move4;
  1561. }
  1562. void door_secret_move4 (edict_t *self)
  1563. {
  1564. Move_Calc (self, self->pos1, door_secret_move5);
  1565. }
  1566. void door_secret_move5 (edict_t *self)
  1567. {
  1568. self->nextthink = level.time + 1.0;
  1569. self->think = door_secret_move6;
  1570. }
  1571. void door_secret_move6 (edict_t *self)
  1572. {
  1573. Move_Calc (self, vec3_origin, door_secret_done);
  1574. }
  1575. void door_secret_done (edict_t *self)
  1576. {
  1577. if (!(self->targetname) || (self->spawnflags & SECRET_ALWAYS_SHOOT))
  1578. {
  1579. self->health = 0;
  1580. self->takedamage = DAMAGE_YES;
  1581. }
  1582. door_use_areaportals (self, false);
  1583. }
  1584. void door_secret_blocked (edict_t *self, edict_t *other)
  1585. {
  1586. if (!(other->svflags & SVF_MONSTER) && (!other->client) )
  1587. {
  1588. // give it a chance to go away on it's own terms (like gibs)
  1589. T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
  1590. // if it's still there, nuke it
  1591. if (other)
  1592. BecomeExplosion1 (other);
  1593. return;
  1594. }
  1595. if (level.time < self->touch_debounce_time)
  1596. return;
  1597. self->touch_debounce_time = level.time + 0.5;
  1598. T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
  1599. }
  1600. void door_secret_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  1601. {
  1602. self->takedamage = DAMAGE_NO;
  1603. door_secret_use (self, attacker, attacker);
  1604. }
  1605. void SP_func_door_secret (edict_t *ent)
  1606. {
  1607. vec3_t forward, right, up;
  1608. float side;
  1609. float width;
  1610. float length;
  1611. ent->moveinfo.sound_start = gi.soundindex ("doors/dr1_strt.wav");
  1612. ent->moveinfo.sound_middle = gi.soundindex ("doors/dr1_mid.wav");
  1613. ent->moveinfo.sound_end = gi.soundindex ("doors/dr1_end.wav");
  1614. ent->movetype = MOVETYPE_PUSH;
  1615. ent->solid = SOLID_BSP;
  1616. gi.setmodel (ent, ent->model);
  1617. ent->blocked = door_secret_blocked;
  1618. ent->use = door_secret_use;
  1619. if (!(ent->targetname) || (ent->spawnflags & SECRET_ALWAYS_SHOOT))
  1620. {
  1621. ent->health = 0;
  1622. ent->takedamage = DAMAGE_YES;
  1623. ent->die = door_secret_die;
  1624. }
  1625. if (!ent->dmg)
  1626. ent->dmg = 2;
  1627. if (!ent->wait)
  1628. ent->wait = 5;
  1629. ent->moveinfo.accel =
  1630. ent->moveinfo.decel =
  1631. ent->moveinfo.speed = 50;
  1632. // calculate positions
  1633. AngleVectors (ent->s.angles, forward, right, up);
  1634. VectorClear (ent->s.angles);
  1635. side = 1.0 - (ent->spawnflags & SECRET_1ST_LEFT);
  1636. if (ent->spawnflags & SECRET_1ST_DOWN)
  1637. width = fabs(DotProduct(up, ent->size));
  1638. else
  1639. width = fabs(DotProduct(right, ent->size));
  1640. length = fabs(DotProduct(forward, ent->size));
  1641. if (ent->spawnflags & SECRET_1ST_DOWN)
  1642. VectorMA (ent->s.origin, -1 * width, up, ent->pos1);
  1643. else
  1644. VectorMA (ent->s.origin, side * width, right, ent->pos1);
  1645. VectorMA (ent->pos1, length, forward, ent->pos2);
  1646. if (ent->health)
  1647. {
  1648. ent->takedamage = DAMAGE_YES;
  1649. ent->die = door_killed;
  1650. ent->max_health = ent->health;
  1651. }
  1652. else if (ent->targetname && ent->message)
  1653. {
  1654. gi.soundindex ("misc/talk.wav");
  1655. ent->touch = door_touch;
  1656. }
  1657. ent->classname = "func_door";
  1658. gi.linkentity (ent);
  1659. }
  1660. /*QUAKED func_killbox (1 0 0) ?
  1661. Kills everything inside when fired, irrespective of protection.
  1662. */
  1663. void use_killbox (edict_t *self, edict_t *other, edict_t *activator)
  1664. {
  1665. KillBox (self);
  1666. }
  1667. void SP_func_killbox (edict_t *ent)
  1668. {
  1669. gi.setmodel (ent, ent->model);
  1670. ent->use = use_killbox;
  1671. ent->svflags = SVF_NOCLIENT;
  1672. }