g_misc.c 44 KB

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