g_misc.c 50 KB

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