g_misc.c 45 KB

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