g_rogue_newtarg.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. #include "../g_local.h"
  4. //==========================================================
  5. /*QUAKED target_steam (1 0 0) (-8 -8 -8) (8 8 8)
  6. Creates a steam effect (particles w/ velocity in a line).
  7. speed = velocity of particles (default 50)
  8. count = number of particles (default 32)
  9. sounds = color of particles (default 8 for steam)
  10. the color range is from this color to this color + 6
  11. wait = seconds to run before stopping (overrides default
  12. value derived from func_timer)
  13. best way to use this is to tie it to a func_timer that "pokes"
  14. it every second (or however long you set the wait time, above)
  15. note that the width of the base is proportional to the speed
  16. good colors to use:
  17. 6-9 - varying whites (darker to brighter)
  18. 224 - sparks
  19. 176 - blue water
  20. 80 - brown water
  21. 208 - slime
  22. 232 - blood
  23. */
  24. USE(use_target_steam) (edict_t *self, edict_t *other, edict_t *activator) -> void
  25. {
  26. // FIXME - this needs to be a global
  27. static int nextid;
  28. vec3_t point;
  29. if (nextid > 20000)
  30. nextid = nextid % 20000;
  31. nextid++;
  32. // automagically set wait from func_timer unless they set it already, or
  33. // default to 1000 if not called by a func_timer (eek!)
  34. if (!self->wait)
  35. {
  36. if (other)
  37. self->wait = other->wait * 1000;
  38. else
  39. self->wait = 1000;
  40. }
  41. if (self->enemy)
  42. {
  43. point = (self->enemy->absmin + self->enemy->absmax) * 0.5f;
  44. self->movedir = point - self->s.origin;
  45. self->movedir.normalize();
  46. }
  47. point = self->s.origin + (self->movedir * (self->style * 0.5f));
  48. if (self->wait > 100)
  49. {
  50. gi.WriteByte(svc_temp_entity);
  51. gi.WriteByte(TE_STEAM);
  52. gi.WriteShort(nextid);
  53. gi.WriteByte(self->count);
  54. gi.WritePosition(self->s.origin);
  55. gi.WriteDir(self->movedir);
  56. gi.WriteByte(self->sounds & 0xff);
  57. gi.WriteShort((short int) (self->style));
  58. gi.WriteLong((int) (self->wait));
  59. gi.multicast(self->s.origin, MULTICAST_PVS, false);
  60. }
  61. else
  62. {
  63. gi.WriteByte(svc_temp_entity);
  64. gi.WriteByte(TE_STEAM);
  65. gi.WriteShort((short int) -1);
  66. gi.WriteByte(self->count);
  67. gi.WritePosition(self->s.origin);
  68. gi.WriteDir(self->movedir);
  69. gi.WriteByte(self->sounds & 0xff);
  70. gi.WriteShort((short int) (self->style));
  71. gi.multicast(self->s.origin, MULTICAST_PVS, false);
  72. }
  73. }
  74. THINK(target_steam_start) (edict_t *self) -> void
  75. {
  76. edict_t *ent;
  77. self->use = use_target_steam;
  78. if (self->target)
  79. {
  80. ent = G_FindByString<&edict_t::targetname>(nullptr, self->target);
  81. if (!ent)
  82. gi.Com_PrintFmt("{}: target {} not found\n", *self, self->target);
  83. self->enemy = ent;
  84. }
  85. else
  86. {
  87. G_SetMovedir(self->s.angles, self->movedir);
  88. }
  89. if (!self->count)
  90. self->count = 32;
  91. if (!self->style)
  92. self->style = 75;
  93. if (!self->sounds)
  94. self->sounds = 8;
  95. if (self->wait)
  96. self->wait *= 1000; // we want it in milliseconds, not seconds
  97. // paranoia is good
  98. self->sounds &= 0xff;
  99. self->count &= 0xff;
  100. self->svflags = SVF_NOCLIENT;
  101. gi.linkentity(self);
  102. }
  103. void SP_target_steam(edict_t *self)
  104. {
  105. self->style = (int) self->speed;
  106. if (self->target)
  107. {
  108. self->think = target_steam_start;
  109. self->nextthink = level.time + 1_sec;
  110. }
  111. else
  112. target_steam_start(self);
  113. }
  114. //==========================================================
  115. // target_anger
  116. //==========================================================
  117. USE(target_anger_use) (edict_t *self, edict_t *other, edict_t *activator) -> void
  118. {
  119. edict_t *target;
  120. edict_t *t;
  121. t = nullptr;
  122. target = G_FindByString<&edict_t::targetname>(t, self->killtarget);
  123. if (target && self->target)
  124. {
  125. // Make whatever a "good guy" so the monster will try to kill it!
  126. if (!(target->svflags & SVF_MONSTER))
  127. {
  128. target->monsterinfo.aiflags |= AI_GOOD_GUY | AI_DO_NOT_COUNT;
  129. target->svflags |= SVF_MONSTER;
  130. target->health = 300;
  131. }
  132. t = nullptr;
  133. while ((t = G_FindByString<&edict_t::targetname>(t, self->target)))
  134. {
  135. if (t == self)
  136. {
  137. gi.Com_Print("WARNING: entity used itself.\n");
  138. }
  139. else
  140. {
  141. if (t->use)
  142. {
  143. if (t->health <= 0)
  144. return;
  145. t->enemy = target;
  146. t->monsterinfo.aiflags |= AI_TARGET_ANGER;
  147. FoundTarget(t);
  148. }
  149. }
  150. if (!self->inuse)
  151. {
  152. gi.Com_Print("entity was removed while using targets\n");
  153. return;
  154. }
  155. }
  156. }
  157. }
  158. /*QUAKED target_anger (1 0 0) (-8 -8 -8) (8 8 8)
  159. This trigger will cause an entity to be angry at another entity when a player touches it. Target the
  160. entity you want to anger, and killtarget the entity you want it to be angry at.
  161. target - entity to piss off
  162. killtarget - entity to be pissed off at
  163. */
  164. void SP_target_anger(edict_t *self)
  165. {
  166. if (!self->target)
  167. {
  168. gi.Com_Print("target_anger without target!\n");
  169. G_FreeEdict(self);
  170. return;
  171. }
  172. if (!self->killtarget)
  173. {
  174. gi.Com_Print("target_anger without killtarget!\n");
  175. G_FreeEdict(self);
  176. return;
  177. }
  178. self->use = target_anger_use;
  179. self->svflags = SVF_NOCLIENT;
  180. }
  181. // ***********************************
  182. // target_killplayers
  183. // ***********************************
  184. USE(target_killplayers_use) (edict_t *self, edict_t *other, edict_t *activator) -> void
  185. {
  186. level.deadly_kill_box = true;
  187. edict_t *ent, *player;
  188. // kill any visible monsters
  189. for (ent = g_edicts; ent < &g_edicts[globals.num_edicts]; ent++)
  190. {
  191. if (!ent->inuse)
  192. continue;
  193. if (ent->health < 1)
  194. continue;
  195. if (!ent->takedamage)
  196. continue;
  197. for (uint32_t i = 0; i < game.maxclients; i++)
  198. {
  199. player = &g_edicts[1 + i];
  200. if (!player->inuse)
  201. continue;
  202. if (gi.inPVS(player->s.origin, ent->s.origin, false))
  203. {
  204. T_Damage(ent, self, self, vec3_origin, ent->s.origin, vec3_origin,
  205. ent->health, 0, DAMAGE_NO_PROTECTION, MOD_TELEFRAG);
  206. break;
  207. }
  208. }
  209. }
  210. // kill the players
  211. for (uint32_t i = 0; i < game.maxclients; i++)
  212. {
  213. player = &g_edicts[1 + i];
  214. if (!player->inuse)
  215. continue;
  216. // nail it
  217. T_Damage(player, self, self, vec3_origin, self->s.origin, vec3_origin, 100000, 0, DAMAGE_NO_PROTECTION, MOD_TELEFRAG);
  218. }
  219. level.deadly_kill_box = false;
  220. }
  221. /*QUAKED target_killplayers (1 0 0) (-8 -8 -8) (8 8 8)
  222. When triggered, this will kill all the players on the map.
  223. */
  224. void SP_target_killplayers(edict_t *self)
  225. {
  226. self->use = target_killplayers_use;
  227. self->svflags = SVF_NOCLIENT;
  228. }
  229. /*QUAKED target_blacklight (1 0 1) (-16 -16 -24) (16 16 24)
  230. Pulsing black light with sphere in the center
  231. */
  232. THINK(blacklight_think) (edict_t *self) -> void
  233. {
  234. self->s.angles[0] += frandom(10);
  235. self->s.angles[1] += frandom(10);
  236. self->s.angles[2] += frandom(10);
  237. self->nextthink = level.time + FRAME_TIME_MS;
  238. }
  239. void SP_target_blacklight(edict_t *ent)
  240. {
  241. if (deathmatch->integer)
  242. { // auto-remove for deathmatch
  243. G_FreeEdict(ent);
  244. return;
  245. }
  246. ent->mins = {};
  247. ent->maxs = {};
  248. ent->s.effects |= (EF_TRACKERTRAIL | EF_TRACKER);
  249. ent->think = blacklight_think;
  250. ent->s.modelindex = gi.modelindex("models/items/spawngro3/tris.md2");
  251. ent->s.scale = 6.f;
  252. ent->s.skinnum = 0;
  253. ent->nextthink = level.time + FRAME_TIME_MS;
  254. gi.linkentity(ent);
  255. }
  256. /*QUAKED target_orb (1 0 1) (-16 -16 -24) (16 16 24)
  257. Translucent pulsing orb with speckles
  258. */
  259. void SP_target_orb(edict_t *ent)
  260. {
  261. if (deathmatch->integer)
  262. { // auto-remove for deathmatch
  263. G_FreeEdict(ent);
  264. return;
  265. }
  266. ent->mins = {};
  267. ent->maxs = {};
  268. // ent->s.effects |= EF_TRACKERTRAIL;
  269. ent->think = blacklight_think;
  270. ent->nextthink = level.time + 10_hz;
  271. ent->s.skinnum = 1;
  272. ent->s.modelindex = gi.modelindex("models/items/spawngro3/tris.md2");
  273. ent->s.frame = 2;
  274. ent->s.scale = 8.f;
  275. ent->s.effects |= EF_SPHERETRANS;
  276. gi.linkentity(ent);
  277. }