PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/game/w_force.c

https://bitbucket.org/bshaw/jk3game_sdk_mingw
C | 5792 lines | 4895 code | 676 blank | 221 comment | 1433 complexity | 9246377cd634bd52cdb23d9f264484b0 MD5 | raw file
  1. //#include "g_local.h"
  2. #include "b_local.h"
  3. #include "w_saber.h"
  4. #include "ai_main.h"
  5. #include "../ghoul2/G2.h"
  6. #define METROID_JUMP 1
  7. //NEEDED FOR MIND-TRICK on NPCS=========================================================
  8. extern void NPC_PlayConfusionSound( gentity_t *self );
  9. extern void NPC_Jedi_PlayConfusionSound( gentity_t *self );
  10. extern void NPC_UseResponse( gentity_t *self, gentity_t *user, qboolean useWhenDone );
  11. //NEEDED FOR MIND-TRICK on NPCS=========================================================
  12. extern void Jedi_Decloak( gentity_t *self );
  13. extern vmCvar_t g_saberRestrictForce;
  14. #include "../namespace_begin.h"
  15. extern qboolean BG_FullBodyTauntAnim( int anim );
  16. #include "../namespace_end.h"
  17. extern bot_state_t *botstates[MAX_CLIENTS];
  18. int speedLoopSound = 0;
  19. int rageLoopSound = 0;
  20. int protectLoopSound = 0;
  21. int absorbLoopSound = 0;
  22. int seeLoopSound = 0;
  23. int ysalamiriLoopSound = 0;
  24. #define FORCE_VELOCITY_DAMAGE 0
  25. int ForceShootDrain( gentity_t *self );
  26. gentity_t *G_PreDefSound(vec3_t org, int pdSound)
  27. {
  28. gentity_t *te;
  29. te = G_TempEntity( org, EV_PREDEFSOUND );
  30. te->s.eventParm = pdSound;
  31. VectorCopy(org, te->s.origin);
  32. return te;
  33. }
  34. const int forcePowerMinRank[NUM_FORCE_POWER_LEVELS][NUM_FORCE_POWERS] = //0 == neutral
  35. {
  36. {
  37. 999,//FP_HEAL,//instant
  38. 999,//FP_LEVITATION,//hold/duration
  39. 999,//FP_SPEED,//duration
  40. 999,//FP_PUSH,//hold/duration
  41. 999,//FP_PULL,//hold/duration
  42. 999,//FP_TELEPATHY,//instant
  43. 999,//FP_GRIP,//hold/duration
  44. 999,//FP_LIGHTNING,//hold/duration
  45. 999,//FP_RAGE,//duration
  46. 999,//FP_PROTECT,//duration
  47. 999,//FP_ABSORB,//duration
  48. 999,//FP_TEAM_HEAL,//instant
  49. 999,//FP_TEAM_FORCE,//instant
  50. 999,//FP_DRAIN,//hold/duration
  51. 999,//FP_SEE,//duration
  52. 999,//FP_SABER_OFFENSE,
  53. 999,//FP_SABER_DEFENSE,
  54. 999//FP_SABERTHROW,
  55. //NUM_FORCE_POWERS
  56. },
  57. {
  58. 10,//FP_HEAL,//instant
  59. 0,//FP_LEVITATION,//hold/duration
  60. 0,//FP_SPEED,//duration
  61. 0,//FP_PUSH,//hold/duration
  62. 0,//FP_PULL,//hold/duration
  63. 10,//FP_TELEPATHY,//instant
  64. 15,//FP_GRIP,//hold/duration
  65. 10,//FP_LIGHTNING,//hold/duration
  66. 15,//FP_RAGE,//duration
  67. 15,//FP_PROTECT,//duration
  68. 15,//FP_ABSORB,//duration
  69. 10,//FP_TEAM_HEAL,//instant
  70. 10,//FP_TEAM_FORCE,//instant
  71. 10,//FP_DRAIN,//hold/duration
  72. 5,//FP_SEE,//duration
  73. 0,//FP_SABER_OFFENSE,
  74. 0,//FP_SABER_DEFENSE,
  75. 0//FP_SABERTHROW,
  76. //NUM_FORCE_POWERS
  77. },
  78. {
  79. 10,//FP_HEAL,//instant
  80. 0,//FP_LEVITATION,//hold/duration
  81. 0,//FP_SPEED,//duration
  82. 0,//FP_PUSH,//hold/duration
  83. 0,//FP_PULL,//hold/duration
  84. 10,//FP_TELEPATHY,//instant
  85. 15,//FP_GRIP,//hold/duration
  86. 10,//FP_LIGHTNING,//hold/duration
  87. 15,//FP_RAGE,//duration
  88. 15,//FP_PROTECT,//duration
  89. 15,//FP_ABSORB,//duration
  90. 10,//FP_TEAM_HEAL,//instant
  91. 10,//FP_TEAM_FORCE,//instant
  92. 10,//FP_DRAIN,//hold/duration
  93. 5,//FP_SEE,//duration
  94. 5,//FP_SABER_OFFENSE,
  95. 5,//FP_SABER_DEFENSE,
  96. 5//FP_SABERTHROW,
  97. //NUM_FORCE_POWERS
  98. },
  99. {
  100. 10,//FP_HEAL,//instant
  101. 0,//FP_LEVITATION,//hold/duration
  102. 0,//FP_SPEED,//duration
  103. 0,//FP_PUSH,//hold/duration
  104. 0,//FP_PULL,//hold/duration
  105. 10,//FP_TELEPATHY,//instant
  106. 15,//FP_GRIP,//hold/duration
  107. 10,//FP_LIGHTNING,//hold/duration
  108. 15,//FP_RAGE,//duration
  109. 15,//FP_PROTECT,//duration
  110. 15,//FP_ABSORB,//duration
  111. 10,//FP_TEAM_HEAL,//instant
  112. 10,//FP_TEAM_FORCE,//instant
  113. 10,//FP_DRAIN,//hold/duration
  114. 5,//FP_SEE,//duration
  115. 10,//FP_SABER_OFFENSE,
  116. 10,//FP_SABER_DEFENSE,
  117. 10//FP_SABERTHROW,
  118. //NUM_FORCE_POWERS
  119. }
  120. };
  121. const int mindTrickTime[NUM_FORCE_POWER_LEVELS] =
  122. {
  123. 0,//none
  124. 5000,
  125. 10000,
  126. 15000
  127. };
  128. void WP_InitForcePowers( gentity_t *ent )
  129. {
  130. int i;
  131. int i_r;
  132. int maxRank = g_maxForceRank.integer;
  133. qboolean warnClient = qfalse;
  134. qboolean warnClientLimit = qfalse;
  135. char userinfo[MAX_INFO_STRING];
  136. char forcePowers[256];
  137. char readBuf[256];
  138. int lastFPKnown = -1;
  139. qboolean didEvent = qfalse;
  140. if (!maxRank)
  141. { //if server has no max rank, default to max (50)
  142. maxRank = FORCE_MASTERY_JEDI_MASTER;
  143. }
  144. else if (maxRank >= NUM_FORCE_MASTERY_LEVELS)
  145. {//ack, prevent user from being dumb
  146. maxRank = FORCE_MASTERY_JEDI_MASTER;
  147. trap_Cvar_Set( "g_maxForceRank", va("%i", maxRank) );
  148. }
  149. /*
  150. if (g_forcePowerDisable.integer)
  151. {
  152. maxRank = FORCE_MASTERY_UNINITIATED;
  153. }
  154. */
  155. //rww - don't do this
  156. if ( !ent || !ent->client )
  157. {
  158. return;
  159. }
  160. ent->client->ps.fd.saberAnimLevel = ent->client->sess.saberLevel;
  161. if (ent->client->ps.fd.saberAnimLevel < FORCE_LEVEL_1 ||
  162. ent->client->ps.fd.saberAnimLevel > FORCE_LEVEL_3)
  163. {
  164. ent->client->ps.fd.saberAnimLevel = FORCE_LEVEL_1;
  165. }
  166. if (!speedLoopSound)
  167. { //so that the client configstring is already modified with this when we need it
  168. speedLoopSound = G_SoundIndex("sound/weapons/force/speedloop.wav");
  169. }
  170. if (!rageLoopSound)
  171. {
  172. rageLoopSound = G_SoundIndex("sound/weapons/force/rageloop.wav");
  173. }
  174. if (!absorbLoopSound)
  175. {
  176. absorbLoopSound = G_SoundIndex("sound/weapons/force/absorbloop.wav");
  177. }
  178. if (!protectLoopSound)
  179. {
  180. protectLoopSound = G_SoundIndex("sound/weapons/force/protectloop.wav");
  181. }
  182. if (!seeLoopSound)
  183. {
  184. seeLoopSound = G_SoundIndex("sound/weapons/force/seeloop.wav");
  185. }
  186. if (!ysalamiriLoopSound)
  187. {
  188. ysalamiriLoopSound = G_SoundIndex("sound/player/nullifyloop.wav");
  189. }
  190. if (ent->s.eType == ET_NPC)
  191. { //just stop here then.
  192. return;
  193. }
  194. i = 0;
  195. while (i < NUM_FORCE_POWERS)
  196. {
  197. ent->client->ps.fd.forcePowerLevel[i] = 0;
  198. ent->client->ps.fd.forcePowersKnown &= ~(1 << i);
  199. i++;
  200. }
  201. ent->client->ps.fd.forcePowerSelected = -1;
  202. ent->client->ps.fd.forceSide = 0;
  203. if (g_gametype.integer == GT_SIEGE &&
  204. ent->client->siegeClass != -1)
  205. { //Then use the powers for this class, and skip all this nonsense.
  206. i = 0;
  207. while (i < NUM_FORCE_POWERS)
  208. {
  209. ent->client->ps.fd.forcePowerLevel[i] = bgSiegeClasses[ent->client->siegeClass].forcePowerLevels[i];
  210. if (!ent->client->ps.fd.forcePowerLevel[i])
  211. {
  212. ent->client->ps.fd.forcePowersKnown &= ~(1 << i);
  213. }
  214. else
  215. {
  216. ent->client->ps.fd.forcePowersKnown |= (1 << i);
  217. }
  218. i++;
  219. }
  220. if (!ent->client->sess.setForce)
  221. {
  222. //bring up the class selection menu
  223. trap_SendServerCommand(ent-g_entities, "scl");
  224. }
  225. ent->client->sess.setForce = qtrue;
  226. return;
  227. }
  228. if (ent->s.eType == ET_NPC && ent->s.number >= MAX_CLIENTS)
  229. { //rwwFIXMEFIXME: Temp
  230. strcpy(userinfo, "forcepowers\\7-1-333003000313003120");
  231. }
  232. else
  233. {
  234. trap_GetUserinfo( ent->s.number, userinfo, sizeof( userinfo ) );
  235. }
  236. Q_strncpyz( forcePowers, Info_ValueForKey (userinfo, "forcepowers"), sizeof( forcePowers ) );
  237. if ( (ent->r.svFlags & SVF_BOT) && botstates[ent->s.number] )
  238. { //if it's a bot just copy the info directly from its personality
  239. Com_sprintf(forcePowers, sizeof(forcePowers), "%s\0", botstates[ent->s.number]->forceinfo);
  240. }
  241. //rww - parse through the string manually and eat out all the appropriate data
  242. i = 0;
  243. if (g_forceBasedTeams.integer)
  244. {
  245. if (ent->client->sess.sessionTeam == TEAM_RED)
  246. {
  247. warnClient = !(BG_LegalizedForcePowers(forcePowers, maxRank, HasSetSaberOnly(), FORCE_DARKSIDE, g_gametype.integer, g_forcePowerDisable.integer));
  248. }
  249. else if (ent->client->sess.sessionTeam == TEAM_BLUE)
  250. {
  251. warnClient = !(BG_LegalizedForcePowers(forcePowers, maxRank, HasSetSaberOnly(), FORCE_LIGHTSIDE, g_gametype.integer, g_forcePowerDisable.integer));
  252. }
  253. else
  254. {
  255. warnClient = !(BG_LegalizedForcePowers(forcePowers, maxRank, HasSetSaberOnly(), 0, g_gametype.integer, g_forcePowerDisable.integer));
  256. }
  257. }
  258. else
  259. {
  260. warnClient = !(BG_LegalizedForcePowers(forcePowers, maxRank, HasSetSaberOnly(), 0, g_gametype.integer, g_forcePowerDisable.integer));
  261. }
  262. i_r = 0;
  263. while (forcePowers[i] && forcePowers[i] != '-')
  264. {
  265. readBuf[i_r] = forcePowers[i];
  266. i_r++;
  267. i++;
  268. }
  269. readBuf[i_r] = 0;
  270. //THE RANK
  271. ent->client->ps.fd.forceRank = atoi(readBuf);
  272. i++;
  273. i_r = 0;
  274. while (forcePowers[i] && forcePowers[i] != '-')
  275. {
  276. readBuf[i_r] = forcePowers[i];
  277. i_r++;
  278. i++;
  279. }
  280. readBuf[i_r] = 0;
  281. //THE SIDE
  282. ent->client->ps.fd.forceSide = atoi(readBuf);
  283. i++;
  284. if ( g_gametype.integer != GT_SIEGE && (ent->r.svFlags & SVF_BOT) && botstates[ent->s.number] )
  285. { //hmm..I'm going to cheat here.
  286. int oldI = i;
  287. i_r = 0;
  288. while (forcePowers[i] && forcePowers[i] != '\n' &&
  289. i_r < NUM_FORCE_POWERS)
  290. {
  291. if (ent->client->ps.fd.forceSide == FORCE_LIGHTSIDE)
  292. {
  293. if (i_r == FP_ABSORB)
  294. {
  295. forcePowers[i] = '3';
  296. }
  297. if (botstates[ent->s.number]->settings.skill >= 4)
  298. { //cheat and give them more stuff
  299. if (i_r == FP_HEAL)
  300. {
  301. forcePowers[i] = '3';
  302. }
  303. else if (i_r == FP_PROTECT)
  304. {
  305. forcePowers[i] = '3';
  306. }
  307. }
  308. }
  309. else if (ent->client->ps.fd.forceSide == FORCE_DARKSIDE)
  310. {
  311. if (botstates[ent->s.number]->settings.skill >= 4)
  312. {
  313. if (i_r == FP_GRIP)
  314. {
  315. forcePowers[i] = '3';
  316. }
  317. else if (i_r == FP_LIGHTNING)
  318. {
  319. forcePowers[i] = '3';
  320. }
  321. else if (i_r == FP_RAGE)
  322. {
  323. forcePowers[i] = '3';
  324. }
  325. else if (i_r == FP_DRAIN)
  326. {
  327. forcePowers[i] = '3';
  328. }
  329. }
  330. }
  331. if (i_r == FP_PUSH)
  332. {
  333. forcePowers[i] = '3';
  334. }
  335. else if (i_r == FP_PULL)
  336. {
  337. forcePowers[i] = '3';
  338. }
  339. i++;
  340. i_r++;
  341. }
  342. i = oldI;
  343. }
  344. i_r = 0;
  345. while (forcePowers[i] && forcePowers[i] != '\n' &&
  346. i_r < NUM_FORCE_POWERS)
  347. {
  348. readBuf[0] = forcePowers[i];
  349. readBuf[1] = 0;
  350. ent->client->ps.fd.forcePowerLevel[i_r] = atoi(readBuf);
  351. if (ent->client->ps.fd.forcePowerLevel[i_r])
  352. {
  353. ent->client->ps.fd.forcePowersKnown |= (1 << i_r);
  354. }
  355. else
  356. {
  357. ent->client->ps.fd.forcePowersKnown &= ~(1 << i_r);
  358. }
  359. i++;
  360. i_r++;
  361. }
  362. //THE POWERS
  363. if (ent->s.eType != ET_NPC)
  364. {
  365. if (HasSetSaberOnly())
  366. {
  367. gentity_t *te = G_TempEntity( vec3_origin, EV_SET_FREE_SABER );
  368. te->r.svFlags |= SVF_BROADCAST;
  369. te->s.eventParm = 1;
  370. }
  371. else
  372. {
  373. gentity_t *te = G_TempEntity( vec3_origin, EV_SET_FREE_SABER );
  374. te->r.svFlags |= SVF_BROADCAST;
  375. te->s.eventParm = 0;
  376. }
  377. if (g_forcePowerDisable.integer)
  378. {
  379. gentity_t *te = G_TempEntity( vec3_origin, EV_SET_FORCE_DISABLE );
  380. te->r.svFlags |= SVF_BROADCAST;
  381. te->s.eventParm = 1;
  382. }
  383. else
  384. {
  385. gentity_t *te = G_TempEntity( vec3_origin, EV_SET_FORCE_DISABLE );
  386. te->r.svFlags |= SVF_BROADCAST;
  387. te->s.eventParm = 0;
  388. }
  389. }
  390. //rww - It seems we currently want to always do this, even if the player isn't exceeding the max
  391. //rank, so..
  392. // if (g_gametype.integer == GT_DUEL || g_gametype.integer == GT_POWERDUEL)
  393. // { //totally messes duel up to force someone into spec mode, and besides, each "round" is
  394. //counted as a full restart
  395. // ent->client->sess.setForce = qtrue;
  396. // }
  397. if (ent->s.eType == ET_NPC)
  398. {
  399. ent->client->sess.setForce = qtrue;
  400. }
  401. else if (g_gametype.integer == GT_SIEGE)
  402. {
  403. if (!ent->client->sess.setForce)
  404. {
  405. ent->client->sess.setForce = qtrue;
  406. //bring up the class selection menu
  407. trap_SendServerCommand(ent-g_entities, "scl");
  408. }
  409. }
  410. else
  411. {
  412. if (warnClient || !ent->client->sess.setForce)
  413. { //the client's rank is too high for the server and has been autocapped, so tell them
  414. if (g_gametype.integer != GT_HOLOCRON && g_gametype.integer != GT_JEDIMASTER )
  415. {
  416. #ifdef EVENT_FORCE_RANK
  417. gentity_t *te = G_TempEntity( vec3_origin, EV_GIVE_NEW_RANK );
  418. te->r.svFlags |= SVF_BROADCAST;
  419. te->s.trickedentindex = ent->s.number;
  420. te->s.eventParm = maxRank;
  421. te->s.bolt1 = 0;
  422. #endif
  423. didEvent = qtrue;
  424. // if (!(ent->r.svFlags & SVF_BOT) && g_gametype.integer != GT_DUEL && g_gametype.integer != GT_POWERDUEL && ent->s.eType != ET_NPC)
  425. if (!(ent->r.svFlags & SVF_BOT) && ent->s.eType != ET_NPC)
  426. {
  427. if (!g_teamAutoJoin.integer)
  428. {
  429. //Make them a spectator so they can set their powerups up without being bothered.
  430. ent->client->sess.sessionTeam = TEAM_SPECTATOR;
  431. ent->client->sess.spectatorState = SPECTATOR_FREE;
  432. ent->client->sess.spectatorClient = 0;
  433. ent->client->pers.teamState.state = TEAM_BEGIN;
  434. trap_SendServerCommand(ent-g_entities, "spc"); // Fire up the profile menu
  435. }
  436. }
  437. #ifdef EVENT_FORCE_RANK
  438. te->s.bolt2 = ent->client->sess.sessionTeam;
  439. #else
  440. //Event isn't very reliable, I made it a string. This way I can send it to just one
  441. //client also, as opposed to making a broadcast event.
  442. trap_SendServerCommand(ent->s.number, va("nfr %i %i %i", maxRank, 1, ent->client->sess.sessionTeam));
  443. //Arg1 is new max rank, arg2 is non-0 if force menu should be shown, arg3 is the current team
  444. #endif
  445. }
  446. ent->client->sess.setForce = qtrue;
  447. }
  448. if (!didEvent )
  449. {
  450. #ifdef EVENT_FORCE_RANK
  451. gentity_t *te = G_TempEntity( vec3_origin, EV_GIVE_NEW_RANK );
  452. te->r.svFlags |= SVF_BROADCAST;
  453. te->s.trickedentindex = ent->s.number;
  454. te->s.eventParm = maxRank;
  455. te->s.bolt1 = 1;
  456. te->s.bolt2 = ent->client->sess.sessionTeam;
  457. #else
  458. trap_SendServerCommand(ent->s.number, va("nfr %i %i %i", maxRank, 0, ent->client->sess.sessionTeam));
  459. #endif
  460. }
  461. if (warnClientLimit)
  462. { //the server has one or more force powers disabled and the client is using them in his config
  463. //trap_SendServerCommand(ent-g_entities, va("print \"The server has one or more force powers that you have chosen disabled.\nYou will not be able to use the disable force power(s) while playing on this server.\n\""));
  464. }
  465. }
  466. i = 0;
  467. while (i < NUM_FORCE_POWERS)
  468. {
  469. if ((ent->client->ps.fd.forcePowersKnown & (1 << i)) &&
  470. !ent->client->ps.fd.forcePowerLevel[i])
  471. { //err..
  472. ent->client->ps.fd.forcePowersKnown &= ~(1 << i);
  473. }
  474. else
  475. {
  476. if (i != FP_LEVITATION && i != FP_SABER_OFFENSE && i != FP_SABER_DEFENSE && i != FP_SABERTHROW)
  477. {
  478. lastFPKnown = i;
  479. }
  480. }
  481. i++;
  482. }
  483. if (ent->client->ps.fd.forcePowersKnown & ent->client->sess.selectedFP)
  484. {
  485. ent->client->ps.fd.forcePowerSelected = ent->client->sess.selectedFP;
  486. }
  487. if (!(ent->client->ps.fd.forcePowersKnown & (1 << ent->client->ps.fd.forcePowerSelected)))
  488. {
  489. if (lastFPKnown != -1)
  490. {
  491. ent->client->ps.fd.forcePowerSelected = lastFPKnown;
  492. }
  493. else
  494. {
  495. ent->client->ps.fd.forcePowerSelected = 0;
  496. }
  497. }
  498. while (i < NUM_FORCE_POWERS)
  499. {
  500. ent->client->ps.fd.forcePowerBaseLevel[i] = ent->client->ps.fd.forcePowerLevel[i];
  501. i++;
  502. }
  503. ent->client->ps.fd.forceUsingAdded = 0;
  504. }
  505. void WP_SpawnInitForcePowers( gentity_t *ent )
  506. {
  507. int i = 0;
  508. ent->client->ps.saberAttackChainCount = 0;
  509. i = 0;
  510. while (i < NUM_FORCE_POWERS)
  511. {
  512. if (ent->client->ps.fd.forcePowersActive & (1 << i))
  513. {
  514. WP_ForcePowerStop(ent, i);
  515. }
  516. i++;
  517. }
  518. ent->client->ps.fd.forceDeactivateAll = 0;
  519. ent->client->ps.fd.forcePower = ent->client->ps.fd.forcePowerMax = FORCE_POWER_MAX;
  520. ent->client->ps.fd.forcePowerRegenDebounceTime = 0;
  521. ent->client->ps.fd.forceGripEntityNum = ENTITYNUM_NONE;
  522. ent->client->ps.fd.forceMindtrickTargetIndex = 0;
  523. ent->client->ps.fd.forceMindtrickTargetIndex2 = 0;
  524. ent->client->ps.fd.forceMindtrickTargetIndex3 = 0;
  525. ent->client->ps.fd.forceMindtrickTargetIndex4 = 0;
  526. ent->client->ps.holocronBits = 0;
  527. i = 0;
  528. while (i < NUM_FORCE_POWERS)
  529. {
  530. ent->client->ps.holocronsCarried[i] = 0;
  531. i++;
  532. }
  533. if (g_gametype.integer == GT_HOLOCRON)
  534. {
  535. i = 0;
  536. while (i < NUM_FORCE_POWERS)
  537. {
  538. ent->client->ps.fd.forcePowerLevel[i] = FORCE_LEVEL_0;
  539. i++;
  540. }
  541. if (HasSetSaberOnly())
  542. {
  543. if (ent->client->ps.fd.forcePowerLevel[FP_SABER_OFFENSE] < FORCE_LEVEL_1)
  544. {
  545. ent->client->ps.fd.forcePowerLevel[FP_SABER_OFFENSE] = FORCE_LEVEL_1;
  546. }
  547. if (ent->client->ps.fd.forcePowerLevel[FP_SABER_DEFENSE] < FORCE_LEVEL_1)
  548. {
  549. ent->client->ps.fd.forcePowerLevel[FP_SABER_DEFENSE] = FORCE_LEVEL_1;
  550. }
  551. }
  552. }
  553. i = 0;
  554. while (i < NUM_FORCE_POWERS)
  555. {
  556. ent->client->ps.fd.forcePowerDebounce[i] = 0;
  557. ent->client->ps.fd.forcePowerDuration[i] = 0;
  558. i++;
  559. }
  560. ent->client->ps.fd.forcePowerRegenDebounceTime = 0;
  561. ent->client->ps.fd.forceJumpZStart = 0;
  562. ent->client->ps.fd.forceJumpCharge = 0;
  563. ent->client->ps.fd.forceJumpSound = 0;
  564. ent->client->ps.fd.forceGripDamageDebounceTime = 0;
  565. ent->client->ps.fd.forceGripBeingGripped = 0;
  566. ent->client->ps.fd.forceGripCripple = 0;
  567. ent->client->ps.fd.forceGripUseTime = 0;
  568. ent->client->ps.fd.forceGripSoundTime = 0;
  569. ent->client->ps.fd.forceGripStarted = 0;
  570. ent->client->ps.fd.forceHealTime = 0;
  571. ent->client->ps.fd.forceHealAmount = 0;
  572. ent->client->ps.fd.forceRageRecoveryTime = 0;
  573. ent->client->ps.fd.forceDrainEntNum = ENTITYNUM_NONE;
  574. ent->client->ps.fd.forceDrainTime = 0;
  575. i = 0;
  576. while (i < NUM_FORCE_POWERS)
  577. {
  578. if ((ent->client->ps.fd.forcePowersKnown & (1 << i)) &&
  579. !ent->client->ps.fd.forcePowerLevel[i])
  580. { //make sure all known powers are cleared if we have level 0 in them
  581. ent->client->ps.fd.forcePowersKnown &= ~(1 << i);
  582. }
  583. i++;
  584. }
  585. if (g_gametype.integer == GT_SIEGE &&
  586. ent->client->siegeClass != -1)
  587. { //Then use the powers for this class.
  588. i = 0;
  589. while (i < NUM_FORCE_POWERS)
  590. {
  591. ent->client->ps.fd.forcePowerLevel[i] = bgSiegeClasses[ent->client->siegeClass].forcePowerLevels[i];
  592. if (!ent->client->ps.fd.forcePowerLevel[i])
  593. {
  594. ent->client->ps.fd.forcePowersKnown &= ~(1 << i);
  595. }
  596. else
  597. {
  598. ent->client->ps.fd.forcePowersKnown |= (1 << i);
  599. }
  600. i++;
  601. }
  602. }
  603. }
  604. #include "../namespace_begin.h"
  605. extern qboolean BG_InKnockDown( int anim ); //bg_pmove.c
  606. #include "../namespace_end.h"
  607. int ForcePowerUsableOn(gentity_t *attacker, gentity_t *other, forcePowers_t forcePower)
  608. {
  609. if (other && other->client && BG_HasYsalamiri(g_gametype.integer, &other->client->ps))
  610. {
  611. return 0;
  612. }
  613. if (attacker && attacker->client && !BG_CanUseFPNow(g_gametype.integer, &attacker->client->ps, level.time, forcePower))
  614. {
  615. return 0;
  616. }
  617. //Dueling fighters cannot use force powers on others, with the exception of force push when locked with each other
  618. if (attacker && attacker->client && attacker->client->ps.duelInProgress)
  619. {
  620. return 0;
  621. }
  622. if (other && other->client && other->client->ps.duelInProgress)
  623. {
  624. return 0;
  625. }
  626. if (forcePower == FP_GRIP)
  627. {
  628. if (other && other->client &&
  629. (other->client->ps.fd.forcePowersActive & (1<<FP_ABSORB)))
  630. { //don't allow gripping to begin with if they are absorbing
  631. //play sound indicating that attack was absorbed
  632. if (other->client->forcePowerSoundDebounce < level.time)
  633. {
  634. gentity_t *abSound = G_PreDefSound(other->client->ps.origin, PDSOUND_ABSORBHIT);
  635. abSound->s.trickedentindex = other->s.number;
  636. other->client->forcePowerSoundDebounce = level.time + 400;
  637. }
  638. return 0;
  639. }
  640. else if (other && other->client &&
  641. other->client->ps.weapon == WP_SABER &&
  642. BG_SaberInSpecial(other->client->ps.saberMove))
  643. { //don't grip person while they are in a special or some really bad things can happen.
  644. return 0;
  645. }
  646. }
  647. if (other && other->client &&
  648. (forcePower == FP_PUSH ||
  649. forcePower == FP_PULL))
  650. {
  651. if (BG_InKnockDown(other->client->ps.legsAnim))
  652. {
  653. return 0;
  654. }
  655. }
  656. if (other && other->client && other->s.eType == ET_NPC &&
  657. other->s.NPC_class == CLASS_VEHICLE)
  658. { //can't use the force on vehicles.. except lightning
  659. if (forcePower == FP_LIGHTNING)
  660. {
  661. return 1;
  662. }
  663. else
  664. {
  665. return 0;
  666. }
  667. }
  668. if (other && other->client && other->s.eType == ET_NPC &&
  669. g_gametype.integer == GT_SIEGE)
  670. { //can't use powers at all on npc's normally in siege...
  671. return 0;
  672. }
  673. return 1;
  674. }
  675. qboolean WP_ForcePowerAvailable( gentity_t *self, forcePowers_t forcePower, int overrideAmt )
  676. {
  677. int drain = overrideAmt ? overrideAmt :
  678. forcePowerNeeded[self->client->ps.fd.forcePowerLevel[forcePower]][forcePower];
  679. if (self->client->ps.fd.forcePowersActive & (1 << forcePower))
  680. { //we're probably going to deactivate it..
  681. return qtrue;
  682. }
  683. if ( forcePower == FP_LEVITATION )
  684. {
  685. return qtrue;
  686. }
  687. if ( !drain )
  688. {
  689. return qtrue;
  690. }
  691. if ((forcePower == FP_DRAIN || forcePower == FP_LIGHTNING) &&
  692. self->client->ps.fd.forcePower >= 25)
  693. { //it's ok then, drain/lightning are actually duration
  694. return qtrue;
  695. }
  696. if ( self->client->ps.fd.forcePower < drain )
  697. {
  698. return qfalse;
  699. }
  700. return qtrue;
  701. }
  702. qboolean WP_ForcePowerInUse( gentity_t *self, forcePowers_t forcePower )
  703. {
  704. if ( (self->client->ps.fd.forcePowersActive & ( 1 << forcePower )) )
  705. {//already using this power
  706. return qtrue;
  707. }
  708. return qfalse;
  709. }
  710. qboolean WP_ForcePowerUsable( gentity_t *self, forcePowers_t forcePower )
  711. {
  712. if (BG_HasYsalamiri(g_gametype.integer, &self->client->ps))
  713. {
  714. return qfalse;
  715. }
  716. if (self->health <= 0 || self->client->ps.stats[STAT_HEALTH] <= 0 ||
  717. (self->client->ps.eFlags & EF_DEAD))
  718. {
  719. return qfalse;
  720. }
  721. if (self->client->ps.pm_flags & PMF_FOLLOW)
  722. { //specs can't use powers through people
  723. return qfalse;
  724. }
  725. if (self->client->sess.sessionTeam == TEAM_SPECTATOR)
  726. {
  727. return qfalse;
  728. }
  729. if (self->client->tempSpectate >= level.time)
  730. {
  731. return qfalse;
  732. }
  733. if (!BG_CanUseFPNow(g_gametype.integer, &self->client->ps, level.time, forcePower))
  734. {
  735. return qfalse;
  736. }
  737. if ( !(self->client->ps.fd.forcePowersKnown & ( 1 << forcePower )) )
  738. {//don't know this power
  739. return qfalse;
  740. }
  741. if ( (self->client->ps.fd.forcePowersActive & ( 1 << forcePower )) )
  742. {//already using this power
  743. if (forcePower != FP_LEVITATION)
  744. {
  745. return qfalse;
  746. }
  747. }
  748. if (forcePower == FP_LEVITATION && self->client->fjDidJump)
  749. {
  750. return qfalse;
  751. }
  752. if (!self->client->ps.fd.forcePowerLevel[forcePower])
  753. {
  754. return qfalse;
  755. }
  756. if ( g_debugMelee.integer )
  757. {
  758. if ( (self->client->ps.pm_flags&PMF_STUCK_TO_WALL) )
  759. {//no offensive force powers when stuck to wall
  760. switch ( forcePower )
  761. {
  762. case FP_GRIP:
  763. case FP_LIGHTNING:
  764. case FP_DRAIN:
  765. case FP_SABER_OFFENSE:
  766. case FP_SABER_DEFENSE:
  767. case FP_SABERTHROW:
  768. return qfalse;
  769. break;
  770. }
  771. }
  772. }
  773. if ( !self->client->ps.saberHolstered )
  774. {
  775. if ( (self->client->saber[0].saberFlags&SFL_TWO_HANDED) )
  776. {
  777. if ( g_saberRestrictForce.integer )
  778. {
  779. switch ( forcePower )
  780. {
  781. case FP_PUSH:
  782. case FP_PULL:
  783. case FP_TELEPATHY:
  784. case FP_GRIP:
  785. case FP_LIGHTNING:
  786. case FP_DRAIN:
  787. return qfalse;
  788. break;
  789. }
  790. }
  791. }
  792. if ( (self->client->saber[0].saberFlags&SFL_TWO_HANDED)
  793. || (self->client->saber[0].model && self->client->saber[0].model[0]) )
  794. {//this saber requires the use of two hands OR our other hand is using an active saber too
  795. if ( (self->client->saber[0].forceRestrictions&(1<<forcePower)) )
  796. {//this power is verboten when using this saber
  797. return qfalse;
  798. }
  799. }
  800. if ( self->client->saber[0].model
  801. && self->client->saber[0].model[0] )
  802. {//both sabers on
  803. if ( g_saberRestrictForce.integer )
  804. {
  805. switch ( forcePower )
  806. {
  807. case FP_PUSH:
  808. case FP_PULL:
  809. case FP_TELEPATHY:
  810. case FP_GRIP:
  811. case FP_LIGHTNING:
  812. case FP_DRAIN:
  813. return qfalse;
  814. break;
  815. }
  816. }
  817. if ( (self->client->saber[1].forceRestrictions&(1<<forcePower)) )
  818. {//this power is verboten when using this saber
  819. return qfalse;
  820. }
  821. }
  822. }
  823. return WP_ForcePowerAvailable( self, forcePower, 0 ); // OVERRIDEFIXME
  824. }
  825. int WP_AbsorbConversion(gentity_t *attacked, int atdAbsLevel, gentity_t *attacker, int atPower, int atPowerLevel, int atForceSpent)
  826. {
  827. int getLevel = 0;
  828. int addTot = 0;
  829. gentity_t *abSound;
  830. if (atPower != FP_LIGHTNING &&
  831. atPower != FP_DRAIN &&
  832. atPower != FP_GRIP &&
  833. atPower != FP_PUSH &&
  834. atPower != FP_PULL)
  835. { //Only these powers can be absorbed
  836. return -1;
  837. }
  838. if (!atdAbsLevel)
  839. { //looks like attacker doesn't have any absorb power
  840. return -1;
  841. }
  842. if (!(attacked->client->ps.fd.forcePowersActive & (1 << FP_ABSORB)))
  843. { //absorb is not active
  844. return -1;
  845. }
  846. //Subtract absorb power level from the offensive force power
  847. getLevel = atPowerLevel;
  848. getLevel -= atdAbsLevel;
  849. if (getLevel < 0)
  850. {
  851. getLevel = 0;
  852. }
  853. //let the attacker absorb an amount of force used in this attack based on his level of absorb
  854. addTot = (atForceSpent/3)*attacked->client->ps.fd.forcePowerLevel[FP_ABSORB];
  855. if (addTot < 1 && atForceSpent >= 1)
  856. {
  857. addTot = 1;
  858. }
  859. attacked->client->ps.fd.forcePower += addTot;
  860. if (attacked->client->ps.fd.forcePower > 100)
  861. {
  862. attacked->client->ps.fd.forcePower = 100;
  863. }
  864. //play sound indicating that attack was absorbed
  865. if (attacked->client->forcePowerSoundDebounce < level.time)
  866. {
  867. abSound = G_PreDefSound(attacked->client->ps.origin, PDSOUND_ABSORBHIT);
  868. abSound->s.trickedentindex = attacked->s.number;
  869. attacked->client->forcePowerSoundDebounce = level.time + 400;
  870. }
  871. return getLevel;
  872. }
  873. void WP_ForcePowerRegenerate( gentity_t *self, int overrideAmt )
  874. { //called on a regular interval to regenerate force power.
  875. if ( !self->client )
  876. {
  877. return;
  878. }
  879. if ( overrideAmt )
  880. { //custom regen amount
  881. self->client->ps.fd.forcePower += overrideAmt;
  882. }
  883. else
  884. { //otherwise, just 1
  885. self->client->ps.fd.forcePower++;
  886. }
  887. if ( self->client->ps.fd.forcePower > self->client->ps.fd.forcePowerMax )
  888. { //cap it off at the max (default 100)
  889. self->client->ps.fd.forcePower = self->client->ps.fd.forcePowerMax;
  890. }
  891. }
  892. void WP_ForcePowerStart( gentity_t *self, forcePowers_t forcePower, int overrideAmt )
  893. { //activate the given force power
  894. int duration = 0;
  895. qboolean hearable = qfalse;
  896. float hearDist = 0;
  897. if (!WP_ForcePowerAvailable( self, forcePower, overrideAmt ))
  898. {
  899. return;
  900. }
  901. if ( BG_FullBodyTauntAnim( self->client->ps.legsAnim ) )
  902. {//stop taunt
  903. self->client->ps.legsTimer = 0;
  904. }
  905. if ( BG_FullBodyTauntAnim( self->client->ps.torsoAnim ) )
  906. {//stop taunt
  907. self->client->ps.torsoTimer = 0;
  908. }
  909. //hearable and hearDist are merely for the benefit of bots, and not related to if a sound is actually played.
  910. //If duration is set, the force power will assume to be timer-based.
  911. switch( (int)forcePower )
  912. {
  913. case FP_HEAL:
  914. hearable = qtrue;
  915. hearDist = 256;
  916. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  917. break;
  918. case FP_LEVITATION:
  919. hearable = qtrue;
  920. hearDist = 256;
  921. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  922. break;
  923. case FP_SPEED:
  924. hearable = qtrue;
  925. hearDist = 256;
  926. if (self->client->ps.fd.forcePowerLevel[FP_SPEED] == FORCE_LEVEL_1)
  927. {
  928. duration = 10000;
  929. }
  930. else if (self->client->ps.fd.forcePowerLevel[FP_SPEED] == FORCE_LEVEL_2)
  931. {
  932. duration = 15000;
  933. }
  934. else if (self->client->ps.fd.forcePowerLevel[FP_SPEED] == FORCE_LEVEL_3)
  935. {
  936. duration = 20000;
  937. }
  938. else //shouldn't get here
  939. {
  940. break;
  941. }
  942. if (overrideAmt)
  943. {
  944. duration = overrideAmt;
  945. }
  946. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  947. break;
  948. case FP_PUSH:
  949. hearable = qtrue;
  950. hearDist = 256;
  951. break;
  952. case FP_PULL:
  953. hearable = qtrue;
  954. hearDist = 256;
  955. break;
  956. case FP_TELEPATHY:
  957. hearable = qtrue;
  958. hearDist = 256;
  959. if (self->client->ps.fd.forcePowerLevel[FP_TELEPATHY] == FORCE_LEVEL_1)
  960. {
  961. duration = 20000;
  962. }
  963. else if (self->client->ps.fd.forcePowerLevel[FP_TELEPATHY] == FORCE_LEVEL_2)
  964. {
  965. duration = 25000;
  966. }
  967. else if (self->client->ps.fd.forcePowerLevel[FP_TELEPATHY] == FORCE_LEVEL_3)
  968. {
  969. duration = 30000;
  970. }
  971. else //shouldn't get here
  972. {
  973. break;
  974. }
  975. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  976. break;
  977. case FP_GRIP:
  978. hearable = qtrue;
  979. hearDist = 256;
  980. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  981. self->client->ps.powerups[PW_DISINT_4] = level.time + 60000;
  982. break;
  983. case FP_LIGHTNING:
  984. hearable = qtrue;
  985. hearDist = 512;
  986. duration = overrideAmt;
  987. overrideAmt = 0;
  988. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  989. self->client->ps.activeForcePass = self->client->ps.fd.forcePowerLevel[FP_LIGHTNING];
  990. break;
  991. case FP_RAGE:
  992. hearable = qtrue;
  993. hearDist = 256;
  994. if (self->client->ps.fd.forcePowerLevel[FP_RAGE] == FORCE_LEVEL_1)
  995. {
  996. duration = 8000;
  997. }
  998. else if (self->client->ps.fd.forcePowerLevel[FP_RAGE] == FORCE_LEVEL_2)
  999. {
  1000. duration = 14000;
  1001. }
  1002. else if (self->client->ps.fd.forcePowerLevel[FP_RAGE] == FORCE_LEVEL_3)
  1003. {
  1004. duration = 20000;
  1005. }
  1006. else //shouldn't get here
  1007. {
  1008. break;
  1009. }
  1010. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  1011. break;
  1012. case FP_PROTECT:
  1013. hearable = qtrue;
  1014. hearDist = 256;
  1015. duration = 20000;
  1016. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  1017. break;
  1018. case FP_ABSORB:
  1019. hearable = qtrue;
  1020. hearDist = 256;
  1021. duration = 20000;
  1022. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  1023. break;
  1024. case FP_TEAM_HEAL:
  1025. hearable = qtrue;
  1026. hearDist = 256;
  1027. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  1028. break;
  1029. case FP_TEAM_FORCE:
  1030. hearable = qtrue;
  1031. hearDist = 256;
  1032. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  1033. break;
  1034. case FP_DRAIN:
  1035. hearable = qtrue;
  1036. hearDist = 256;
  1037. duration = overrideAmt;
  1038. overrideAmt = 0;
  1039. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  1040. //self->client->ps.activeForcePass = self->client->ps.fd.forcePowerLevel[FP_DRAIN];
  1041. break;
  1042. case FP_SEE:
  1043. hearable = qtrue;
  1044. hearDist = 256;
  1045. if (self->client->ps.fd.forcePowerLevel[FP_SEE] == FORCE_LEVEL_1)
  1046. {
  1047. duration = 10000;
  1048. }
  1049. else if (self->client->ps.fd.forcePowerLevel[FP_SEE] == FORCE_LEVEL_2)
  1050. {
  1051. duration = 20000;
  1052. }
  1053. else if (self->client->ps.fd.forcePowerLevel[FP_SEE] == FORCE_LEVEL_3)
  1054. {
  1055. duration = 30000;
  1056. }
  1057. else //shouldn't get here
  1058. {
  1059. break;
  1060. }
  1061. self->client->ps.fd.forcePowersActive |= ( 1 << forcePower );
  1062. break;
  1063. case FP_SABER_OFFENSE:
  1064. break;
  1065. case FP_SABER_DEFENSE:
  1066. break;
  1067. case FP_SABERTHROW:
  1068. break;
  1069. default:
  1070. break;
  1071. }
  1072. if ( duration )
  1073. {
  1074. self->client->ps.fd.forcePowerDuration[forcePower] = level.time + duration;
  1075. }
  1076. else
  1077. {
  1078. self->client->ps.fd.forcePowerDuration[forcePower] = 0;
  1079. }
  1080. if (hearable)
  1081. {
  1082. self->client->ps.otherSoundLen = hearDist;
  1083. self->client->ps.otherSoundTime = level.time + 100;
  1084. }
  1085. self->client->ps.fd.forcePowerDebounce[forcePower] = 0;
  1086. if ((int)forcePower == FP_SPEED && overrideAmt)
  1087. {
  1088. BG_ForcePowerDrain( &self->client->ps, forcePower, overrideAmt*0.025 );
  1089. }
  1090. else if ((int)forcePower != FP_GRIP && (int)forcePower != FP_DRAIN)
  1091. { //grip and drain drain as damage is done
  1092. BG_ForcePowerDrain( &self->client->ps, forcePower, overrideAmt );
  1093. }
  1094. }
  1095. void ForceHeal( gentity_t *self )
  1096. {
  1097. if ( self->health <= 0 )
  1098. {
  1099. return;
  1100. }
  1101. if ( !WP_ForcePowerUsable( self, FP_HEAL ) )
  1102. {
  1103. return;
  1104. }
  1105. if ( self->health >= self->client->ps.stats[STAT_MAX_HEALTH])
  1106. {
  1107. return;
  1108. }
  1109. if (self->client->ps.fd.forcePowerLevel[FP_HEAL] == FORCE_LEVEL_3)
  1110. {
  1111. self->health += 25; //This was 50, but that angered the Balance God.
  1112. if (self->health > self->client->ps.stats[STAT_MAX_HEALTH])
  1113. {
  1114. self->health = self->client->ps.stats[STAT_MAX_HEALTH];
  1115. }
  1116. BG_ForcePowerDrain( &self->client->ps, FP_HEAL, 0 );
  1117. }
  1118. else if (self->client->ps.fd.forcePowerLevel[FP_HEAL] == FORCE_LEVEL_2)
  1119. {
  1120. self->health += 10;
  1121. if (self->health > self->client->ps.stats[STAT_MAX_HEALTH])
  1122. {
  1123. self->health = self->client->ps.stats[STAT_MAX_HEALTH];
  1124. }
  1125. BG_ForcePowerDrain( &self->client->ps, FP_HEAL, 0 );
  1126. }
  1127. else
  1128. {
  1129. self->health += 5;
  1130. if (self->health > self->client->ps.stats[STAT_MAX_HEALTH])
  1131. {
  1132. self->health = self->client->ps.stats[STAT_MAX_HEALTH];
  1133. }
  1134. BG_ForcePowerDrain( &self->client->ps, FP_HEAL, 0 );
  1135. }
  1136. /*
  1137. else
  1138. {
  1139. WP_ForcePowerStart( self, FP_HEAL, 0 );
  1140. }
  1141. */
  1142. //NOTE: Decided to make all levels instant.
  1143. G_Sound( self, CHAN_ITEM, G_SoundIndex("sound/weapons/force/heal.wav") );
  1144. }
  1145. void WP_AddToClientBitflags(gentity_t *ent, int entNum)
  1146. {
  1147. if (!ent)
  1148. {
  1149. return;
  1150. }
  1151. if (entNum > 47)
  1152. {
  1153. ent->s.trickedentindex4 |= (1 << (entNum-48));
  1154. }
  1155. else if (entNum > 31)
  1156. {
  1157. ent->s.trickedentindex3 |= (1 << (entNum-32));
  1158. }
  1159. else if (entNum > 15)
  1160. {
  1161. ent->s.trickedentindex2 |= (1 << (entNum-16));
  1162. }
  1163. else
  1164. {
  1165. ent->s.trickedentindex |= (1 << entNum);
  1166. }
  1167. }
  1168. void ForceTeamHeal( gentity_t *self )
  1169. {
  1170. float radius = 256;
  1171. int i = 0;
  1172. gentity_t *ent;
  1173. vec3_t a;
  1174. int numpl = 0;
  1175. int pl[MAX_CLIENTS];
  1176. int healthadd = 0;
  1177. gentity_t *te = NULL;
  1178. if ( self->health <= 0 )
  1179. {
  1180. return;
  1181. }
  1182. if ( !WP_ForcePowerUsable( self, FP_TEAM_HEAL ) )
  1183. {
  1184. return;
  1185. }
  1186. if (self->client->ps.fd.forcePowerDebounce[FP_TEAM_HEAL] >= level.time)
  1187. {
  1188. return;
  1189. }
  1190. if (self->client->ps.fd.forcePowerLevel[FP_TEAM_HEAL] == FORCE_LEVEL_2)
  1191. {
  1192. radius *= 1.5;
  1193. }
  1194. if (self->client->ps.fd.forcePowerLevel[FP_TEAM_HEAL] == FORCE_LEVEL_3)
  1195. {
  1196. radius *= 2;
  1197. }
  1198. while (i < MAX_CLIENTS)
  1199. {
  1200. ent = &g_entities[i];
  1201. if (ent && ent->client && self != ent && OnSameTeam(self, ent) && ent->client->ps.stats[STAT_HEALTH] < ent->client->ps.stats[STAT_MAX_HEALTH] && ent->client->ps.stats[STAT_HEALTH] > 0 && ForcePowerUsableOn(self, ent, FP_TEAM_HEAL) &&
  1202. trap_InPVS(self->client->ps.origin, ent->client->ps.origin))
  1203. {
  1204. VectorSubtract(self->client->ps.origin, ent->client->ps.origin, a);
  1205. if (VectorLength(a) <= radius)
  1206. {
  1207. pl[numpl] = i;
  1208. numpl++;
  1209. }
  1210. }
  1211. i++;
  1212. }
  1213. if (numpl < 1)
  1214. {
  1215. return;
  1216. }
  1217. if (numpl == 1)
  1218. {
  1219. healthadd = 50;
  1220. }
  1221. else if (numpl == 2)
  1222. {
  1223. healthadd = 33;
  1224. }
  1225. else
  1226. {
  1227. healthadd = 25;
  1228. }
  1229. self->client->ps.fd.forcePowerDebounce[FP_TEAM_HEAL] = level.time + 2000;
  1230. i = 0;
  1231. while (i < numpl)
  1232. {
  1233. if (g_entities[pl[i]].client->ps.stats[STAT_HEALTH] > 0 &&
  1234. g_entities[pl[i]].health > 0)
  1235. {
  1236. g_entities[pl[i]].client->ps.stats[STAT_HEALTH] += healthadd;
  1237. if (g_entities[pl[i]].client->ps.stats[STAT_HEALTH] > g_entities[pl[i]].client->ps.stats[STAT_MAX_HEALTH])
  1238. {
  1239. g_entities[pl[i]].client->ps.stats[STAT_HEALTH] = g_entities[pl[i]].client->ps.stats[STAT_MAX_HEALTH];
  1240. }
  1241. g_entities[pl[i]].health = g_entities[pl[i]].client->ps.stats[STAT_HEALTH];
  1242. //At this point we know we got one, so add him into the collective event client bitflag
  1243. if (!te)
  1244. {
  1245. te = G_TempEntity( self->client->ps.origin, EV_TEAM_POWER);
  1246. te->s.eventParm = 1; //eventParm 1 is heal, eventParm 2 is force regen
  1247. //since we had an extra check above, do the drain now because we got at least one guy
  1248. BG_ForcePowerDrain( &self->client->ps, FP_TEAM_HEAL, forcePowerNeeded[self->client->ps.fd.forcePowerLevel[FP_TEAM_HEAL]][FP_TEAM_HEAL] );
  1249. }
  1250. WP_AddToClientBitflags(te, pl[i]);
  1251. //Now cramming it all into one event.. doing this many g_sound events at once was a Bad Thing.
  1252. }
  1253. i++;
  1254. }
  1255. }
  1256. void ForceTeamForceReplenish( gentity_t *self )
  1257. {
  1258. float radius = 256;
  1259. int i = 0;
  1260. gentity_t *ent;
  1261. vec3_t a;
  1262. int numpl = 0;
  1263. int pl[MAX_CLIENTS];
  1264. int poweradd = 0;
  1265. gentity_t *te = NULL;
  1266. if ( self->health <= 0 )
  1267. {
  1268. return;
  1269. }
  1270. if ( !WP_ForcePowerUsable( self, FP_TEAM_FORCE ) )
  1271. {
  1272. return;
  1273. }
  1274. if (self->client->ps.fd.forcePowerDebounce[FP_TEAM_FORCE] >= level.time)
  1275. {
  1276. return;
  1277. }
  1278. if (self->client->ps.fd.forcePowerLevel[FP_TEAM_FORCE] == FORCE_LEVEL_2)
  1279. {
  1280. radius *= 1.5;
  1281. }
  1282. if (self->client->ps.fd.forcePowerLevel[FP_TEAM_FORCE] == FORCE_LEVEL_3)
  1283. {
  1284. radius *= 2;
  1285. }
  1286. while (i < MAX_CLIENTS)
  1287. {
  1288. ent = &g_entities[i];
  1289. if (ent && ent->client && self != ent && OnSameTeam(self, ent) && ent->client->ps.fd.forcePower < 100 && ForcePowerUsableOn(self, ent, FP_TEAM_FORCE) &&
  1290. trap_InPVS(self->client->ps.origin, ent->client->ps.origin))
  1291. {
  1292. VectorSubtract(self->client->ps.origin, ent->client->ps.origin, a);
  1293. if (VectorLength(a) <= radius)
  1294. {
  1295. pl[numpl] = i;
  1296. numpl++;
  1297. }
  1298. }
  1299. i++;
  1300. }
  1301. if (numpl < 1)
  1302. {
  1303. return;
  1304. }
  1305. if (numpl == 1)
  1306. {
  1307. poweradd = 50;
  1308. }
  1309. else if (numpl == 2)
  1310. {
  1311. poweradd = 33;
  1312. }
  1313. else
  1314. {
  1315. poweradd = 25;
  1316. }
  1317. self->client->ps.fd.forcePowerDebounce[FP_TEAM_FORCE] = level.time + 2000;
  1318. BG_ForcePowerDrain( &self->client->ps, FP_TEAM_FORCE, forcePowerNeeded[self->client->ps.fd.forcePowerLevel[FP_TEAM_FORCE]][FP_TEAM_FORCE] );
  1319. i = 0;
  1320. while (i < numpl)
  1321. {
  1322. g_entities[pl[i]].client->ps.fd.forcePower += poweradd;
  1323. if (g_entities[pl[i]].client->ps.fd.forcePower > 100)
  1324. {
  1325. g_entities[pl[i]].client->ps.fd.forcePower = 100;
  1326. }
  1327. //At this point we know we got one, so add him into the collective event client bitflag
  1328. if (!te)
  1329. {
  1330. te = G_TempEntity( self->client->ps.origin, EV_TEAM_POWER);
  1331. te->s.eventParm = 2; //eventParm 1 is heal, eventParm 2 is force regen
  1332. }
  1333. WP_AddToClientBitflags(te, pl[i]);
  1334. //Now cramming it all into one event.. doing this many g_sound events at once was a Bad Thing.
  1335. i++;
  1336. }
  1337. }
  1338. void ForceGrip( gentity_t *self )
  1339. {
  1340. trace_t tr;
  1341. vec3_t tfrom, tto, fwd;
  1342. if ( self->health <= 0 )
  1343. {
  1344. return;
  1345. }
  1346. if (self->client->ps.forceHandExtend != HANDEXTEND_NONE)
  1347. {
  1348. return;
  1349. }
  1350. if (self->client->ps.weaponTime > 0)
  1351. {
  1352. return;
  1353. }
  1354. if (self->client->ps.fd.forceGripUseTime > level.time)
  1355. {
  1356. return;
  1357. }
  1358. if ( !WP_ForcePowerUsable( self, FP_GRIP ) )
  1359. {
  1360. return;
  1361. }
  1362. VectorCopy(self->client->ps.origin, tfrom);
  1363. tfrom[2] += self->client->ps.viewheight;
  1364. AngleVectors(self->client->ps.viewangles, fwd, NULL, NULL);
  1365. tto[0] = tfrom[0] + fwd[0]*MAX_GRIP_DISTANCE;
  1366. tto[1] = tfrom[1] + fwd[1]*MAX_GRIP_DISTANCE;
  1367. tto[2] = tfrom[2] + fwd[2]*MAX_GRIP_DISTANCE;
  1368. trap_Trace(&tr, tfrom, NULL, NULL, tto, self->s.number, MASK_PLAYERSOLID);
  1369. if ( tr.fraction != 1.0 &&
  1370. tr.entityNum != ENTITYNUM_NONE &&
  1371. g_entities[tr.entityNum].client &&
  1372. !g_entities[tr.entityNum].client->ps.fd.forceGripCripple &&
  1373. g_entities[tr.entityNum].client->ps.fd.forceGripBeingGripped < level.time &&
  1374. ForcePowerUsableOn(self, &g_entities[tr.entityNum], FP_GRIP) &&
  1375. (g_friendlyFire.integer || !OnSameTeam(self, &g_entities[tr.entityNum])) ) //don't grip someone who's still crippled
  1376. {
  1377. if (g_entities[tr.entityNum].s.number < MAX_CLIENTS && g_entities[tr.entityNum].client->ps.m_iVehicleNum)
  1378. { //a player on a vehicle
  1379. gentity_t *vehEnt = &g_entities[g_entities[tr.entityNum].client->ps.m_iVehicleNum];
  1380. if (vehEnt->inuse && vehEnt->client && vehEnt->m_pVehicle)
  1381. {
  1382. if (vehEnt->m_pVehicle->m_pVehicleInfo->type == VH_SPEEDER ||
  1383. vehEnt->m_pVehicle->m_pVehicleInfo->type == VH_ANIMAL)
  1384. { //push the guy off
  1385. vehEnt->m_pVehicle->m_pVehicleInfo->Eject(vehEnt->m_pVehicle, (bgEntity_t *)&g_entities[tr.entityNum], qfalse);
  1386. }
  1387. }
  1388. }
  1389. self->client->ps.fd.forceGripEntityNum = tr.entityNum;
  1390. g_entities[tr.entityNum].client->ps.fd.forceGripStarted = level.time;
  1391. self->client->ps.fd.forceGripDamageDebounceTime = 0;
  1392. self->client->ps.forceHandExtend = HANDEXTEND_FORCE_HOLD;
  1393. self->client->ps.forceHandExtendTime = level.time + 5000;
  1394. }
  1395. else
  1396. {
  1397. self->client->ps.fd.forceGripEntityNum = ENTITYNUM_NONE;
  1398. return;
  1399. }
  1400. }
  1401. void ForceSpeed( gentity_t *self, int forceDuration )
  1402. {
  1403. if ( self->health <= 0 )
  1404. {
  1405. return;
  1406. }
  1407. if (self->client->ps.forceAllowDeactivateTime < level.time &&
  1408. (self->client->ps.fd.forcePowersActive & (1 << FP_SPEED)) )
  1409. {
  1410. WP_ForcePowerStop( self, FP_SPEED );
  1411. return;
  1412. }
  1413. if ( !WP_ForcePowerUsable( self, FP_SPEED ) )
  1414. {
  1415. return;
  1416. }
  1417. if ( self->client->holdingObjectiveItem >= MAX_CLIENTS
  1418. && self->client->holdingObjectiveItem < ENTITYNUM_WORLD )
  1419. {//holding Siege item
  1420. if ( g_entities[self->client->holdingObjectiveItem].genericValue15 )
  1421. {//disables force powers
  1422. return;
  1423. }
  1424. }
  1425. self->client->ps.forceAllowDeactivateTime = level.time + 1500;
  1426. WP_ForcePowerStart( self, FP_SPEED, forceDuration );
  1427. G_Sound( self, CHAN_BODY, G_SoundIndex("sound/weapons/force/speed.wav") );
  1428. G_Sound( self, TRACK_CHANNEL_2, speedLoopSound );
  1429. }
  1430. void ForceSeeing( gentity_t *self )
  1431. {
  1432. if ( self->health <= 0 )
  1433. {
  1434. return;
  1435. }
  1436. if (self->client->ps.forceAllowDeactivateTime < level.time &&
  1437. (self->client->ps.fd.forcePowersActive & (1 << FP_SEE)) )
  1438. {
  1439. WP_ForcePowerStop( self, FP_SEE );
  1440. return;
  1441. }
  1442. if ( !WP_ForcePowerUsable( self, FP_SEE ) )
  1443. {
  1444. return;
  1445. }
  1446. self->client->ps.forceAllowDeactivateTime = level.time + 1500;
  1447. WP_ForcePowerStart( self, FP_SEE, 0 );
  1448. G_Sound( self, CHAN_AUTO, G_SoundIndex("sound/weapons/force/see.wav") );
  1449. G_Sound( self, TRACK_CHANNEL_5, seeLoopSound );
  1450. }
  1451. void ForceProtect( gentity_t *self )
  1452. {
  1453. if ( self->health <= 0 )
  1454. {
  1455. return;
  1456. }
  1457. if (self->client->ps.forceAllowDeactivateTime < level.time &&
  1458. (self->client->ps.fd.forcePowersActive & (1 << FP_PROTECT)) )
  1459. {
  1460. WP_ForcePowerStop( self, FP_PROTECT );
  1461. return;
  1462. }
  1463. if ( !WP_ForcePowerUsable( self, FP_PROTECT ) )
  1464. {
  1465. return;
  1466. }
  1467. // Make sure to turn off Force Rage and Force Absorb.
  1468. if (self->client->ps.fd.forcePowersActive & (1 << FP_RAGE) )
  1469. {
  1470. WP_ForcePowerStop( self, FP_RAGE );
  1471. }
  1472. if (self->client->ps.fd.forcePowersActive & (1 << FP_ABSORB) )
  1473. {
  1474. WP_ForcePowerStop( self, FP_ABSORB );
  1475. }
  1476. self->client->ps.forceAllowDeactivateTime = level.time + 1500;
  1477. WP_ForcePowerStart( self, FP_PROTECT, 0 );
  1478. G_PreDefSound(self->client->ps.origin, PDSOUND_PROTECT);
  1479. G_Sound( self, TRACK_CHANNEL_3, protectLoopSound );
  1480. }
  1481. void ForceAbsorb( gentity_t *self )
  1482. {
  1483. if ( self->health <= 0 )
  1484. {
  1485. return;
  1486. }
  1487. if (self->client->ps.forceAllowDeactivateTime < level.time &&
  1488. (self->client->ps.fd.forcePowersActive & (1 << FP_ABSORB)) )
  1489. {
  1490. WP_ForcePowerStop( self, FP_ABSORB );
  1491. return;
  1492. }
  1493. if ( !WP_ForcePowerUsable( self, FP_ABSORB ) )
  1494. {
  1495. return;
  1496. }
  1497. // Make sure to turn off Force Rage and Force Protection.
  1498. if (self->client->ps.fd.forcePowersActive & (1 << FP_RAGE) )
  1499. {
  1500. WP_ForcePowerStop( self, FP_RAGE );
  1501. }
  1502. if (self->client->ps.fd.forcePowersActive & (1 << FP_PROTECT) )
  1503. {
  1504. WP_ForcePowerStop( self, FP_PROTECT );
  1505. }
  1506. self->client->ps.forceAllowDeactivateTime = level.time + 1500;
  1507. WP_ForcePowerStart( self, FP_ABSORB, 0 );
  1508. G_PreDefSound(self->client->ps.origin, PDSOUND_ABSORB);
  1509. G_Sound( self, TRACK_CHANNEL_3, absorbLoopSound );
  1510. }
  1511. void ForceRage( gentity_t *self )
  1512. {
  1513. if ( self->health <= 0 )
  1514. {
  1515. return;
  1516. }
  1517. if (self->client->ps.forceAllowDeactivateTime < level.time &&
  1518. (self->client->ps.fd.forcePowersActive & (1 << FP_RAGE)) )
  1519. {
  1520. WP_ForcePowerStop( self, FP_RAGE );
  1521. return;
  1522. }
  1523. if ( !WP_ForcePowerUsable( self, FP_RAGE ) )
  1524. {
  1525. return;
  1526. }
  1527. if (self->client->ps.fd.forceRageRecoveryTime >= level.time)
  1528. {
  1529. return;
  1530. }
  1531. if (self->health < 10)
  1532. {
  1533. return;
  1534. }
  1535. // Make sure to turn off Force Protection and Force Absorb.
  1536. if (self->client->ps.fd.forcePowersActive & (1 << FP_PROTECT) )
  1537. {
  1538. WP_ForcePowerStop( self, FP_PROTECT );
  1539. }
  1540. if (self->client->ps.fd.forcePowersActive & (1 << FP_ABSORB) )
  1541. {
  1542. WP_ForcePowerStop( self, FP_ABSORB );
  1543. }
  1544. self->client->ps.forceAllowDeactivateTime = level.time + 1500;
  1545. WP_ForcePowerStart( self, FP_RAGE, 0 );
  1546. G_Sound( self, TRACK_CHANNEL_4, G_SoundIndex("sound/weapons/force/rage.wav") );
  1547. G_Sound( self, TRACK_CHANNEL_3, rageLoopSound );
  1548. }
  1549. void ForceLightning( gentity_t *self )
  1550. {
  1551. if ( self->health <= 0 )
  1552. {
  1553. return;
  1554. }
  1555. if ( self->client->ps.fd.forcePower < 25 || !WP_ForcePowerUsable( self, FP_LIGHTNING ) )
  1556. {
  1557. return;
  1558. }
  1559. if ( self->client->ps.fd.forcePowerDebounce[FP_LIGHTNING] > level.time )
  1560. {//stops it while using it and also after using it, up to 3 second delay
  1561. return;
  1562. }
  1563. if (self->client->ps.forceHandExtend != HANDEXTEND_NONE)
  1564. {
  1565. return;
  1566. }
  1567. if (self->client->ps.weaponTime > 0)
  1568. {
  1569. return;
  1570. }
  1571. //Shoot lightning from hand
  1572. //using grip anim now, to extend the burst time
  1573. self->client->ps.forceHandExtend = HANDEXTEND_FORCE_HOLD;
  1574. self->client->ps.forceHandExtendTime = level.time + 20000;
  1575. G_Sound( self, CHAN_BODY, G_SoundIndex("sound/weapons/force/lightning") );
  1576. WP_ForcePowerStart( self, FP_LIGHTNING, 500 );
  1577. }
  1578. void ForceLightningDamage( gentity_t *self, gentity_t *traceEnt, vec3_t dir, vec3_t impactPoint )
  1579. {
  1580. self->client->dangerTime = level.time;
  1581. self->client->ps.eFlags &= ~EF_INVULNERABLE;
  1582. self->client->invulnerableTimer = 0;
  1583. if ( traceEnt && traceEnt->takedamage )
  1584. {
  1585. if (!traceEnt->client && traceEnt->s.eType == ET_NPC)
  1586. { //g2animent
  1587. if (traceEnt->s.genericenemyindex < level.time)
  1588. {
  1589. traceEnt->s.genericenemyindex = level.time + 2000;
  1590. }
  1591. }
  1592. if ( traceEnt->client )
  1593. {//an enemy or object
  1594. if (traceEnt->client->noLightningTime >= level.time)
  1595. { //give them power and don't hurt them.
  1596. traceEnt->client->ps.fd.forcePower++;
  1597. if (traceEnt->client->ps.fd.forcePower > 100)
  1598. {
  1599. traceEnt->client->ps.fd.forcePower = 100;
  1600. }
  1601. return;
  1602. }
  1603. if (ForcePowerUsableOn(self, traceEnt, FP_LIGHTNING))
  1604. {
  1605. int dmg = Q_irand(1,2); //Q_irand( 1, 3 );
  1606. int modPowerLevel = -1;
  1607. if (traceEnt->client)
  1608. {
  1609. modPowerLevel = WP_AbsorbConversion(traceEnt, traceEnt->client->ps.fd.forcePowerLevel[FP_ABSORB], self, FP_LIGHTNING, self->client->ps.fd.forcePowerLevel[FP_LIGHTNING], 1);
  1610. }
  1611. if (modPowerLevel != -1)
  1612. {
  1613. if (!modPowerLevel)
  1614. {
  1615. dmg = 0;
  1616. traceEnt->client->noLightningTime = level.time + 400;
  1617. }
  1618. else if (modPowerLevel == 1)
  1619. {
  1620. dmg = 1;
  1621. traceEnt->client->noLightningTime = level.time + 300;
  1622. }
  1623. else if (modPowerLevel == 2)
  1624. {
  1625. dmg = 1;
  1626. traceEnt->client->noLightningTime = level.time + 100;
  1627. }
  1628. }
  1629. if ( self->client->ps.weapon == WP_MELEE
  1630. && self->client->ps.fd.forcePowerLevel[FP_LIGHTNING] > FORCE_LEVEL_2 )
  1631. {//2-handed lightning
  1632. //jackin' 'em up, Palpatine-style
  1633. dmg *= 2;
  1634. }
  1635. if (dmg)
  1636. {
  1637. //rww - Shields can now absorb lightning too.
  1638. G_Damage( traceEnt, self, self, dir, impactPoint, dmg, 0, MOD_FORCE_DARK );
  1639. }
  1640. if ( traceEnt->client )
  1641. {
  1642. if ( !Q_irand( 0, 2 ) )
  1643. {
  1644. G_Sound( traceEnt, CHAN_BODY, G_SoundIndex( va("sound/weapons/force/lightninghit%i", Q_irand(1, 3) )) );
  1645. }
  1646. if (traceEnt->client->ps.electrifyTime < (level.time + 400))
  1647. { //only update every 400ms to reduce bandwidth usage (as it is passing a 32-bit time value)
  1648. traceEnt->client->ps.electrifyTime = level.time + 800;
  1649. }
  1650. if ( traceEnt->client->ps.powerups[PW_CLOAKED] )
  1651. {//disable cloak temporarily
  1652. Jedi_Decloak( traceEnt );
  1653. traceEnt->client->cloakToggleTime = level.time + Q_irand( 3000, 10000 );
  1654. }
  1655. }
  1656. }
  1657. }
  1658. }
  1659. }
  1660. void ForceShootLightning( gentity_t *self )
  1661. {
  1662. trace_t tr;
  1663. vec3_t end, forward;
  1664. gentity_t *traceEnt;
  1665. if ( self->health <= 0 )
  1666. {
  1667. return;
  1668. }
  1669. AngleVectors( self->client->ps.viewangles, forward, NULL, NULL );
  1670. VectorNormalize( forward );
  1671. if ( self->client->ps.fd.forcePowerLevel[FP_LIGHTNING] > FORCE_LEVEL_2 )
  1672. {//arc
  1673. vec3_t center, mins, maxs, dir, ent_org, size, v;
  1674. float radius = FORCE_LIGHTNING_RADIUS, dot, dist;
  1675. gentity_t *entityList[MAX_GENTITIES];
  1676. int iEntityList[MAX_GENTITIES];
  1677. int e, numListedEntities, i;
  1678. VectorCopy( self->client->ps.origin, center );
  1679. for ( i = 0 ; i < 3 ; i++ )
  1680. {
  1681. mins[i] = center[i] - radius;
  1682. maxs[i] = center[i] + radius;
  1683. }
  1684. numListedEntities = trap_EntitiesInBox( mins, maxs, iEntityList, MAX_GENTITIES );
  1685. i = 0;
  1686. while (i < numListedEntities)
  1687. {
  1688. entityList[i] = &g_entities[iEntityList[i]];
  1689. i++;
  1690. }
  1691. for ( e = 0 ; e < numListedEntities ; e++ )
  1692. {
  1693. traceEnt = entityList[e];
  1694. if ( !traceEnt )
  1695. continue;
  1696. if ( traceEnt == self )
  1697. continue;
  1698. if ( traceEnt->r.ownerNum == self->s.number && traceEnt->s.weapon != WP_THERMAL )//can push your own thermals
  1699. continue;
  1700. if ( !traceEnt->inuse )
  1701. continue;
  1702. if ( !traceEnt->takedamage )
  1703. continue;
  1704. if ( traceEnt->health <= 0 )//no torturing corpses
  1705. continue;
  1706. if ( !g_friendlyFire.integer && OnSameTeam(self, traceEnt))
  1707. continue;
  1708. //this is all to see if we need to start a saber attack, if it's in flight, this doesn't matter
  1709. // find the distance from the edge of the bounding box
  1710. for ( i = 0 ; i < 3 ; i++ )
  1711. {
  1712. if ( center[i] < traceEnt->r.absmin[i] )
  1713. {
  1714. v[i] = traceEnt->r.absmin[i] - center[i];
  1715. } else if ( center[i] > traceEnt->r.absmax[i] )
  1716. {
  1717. v[i] = center[i] - traceEnt->r.absmax[i];
  1718. } else
  1719. {
  1720. v[i] = 0;
  1721. }
  1722. }
  1723. VectorSubtract( traceEnt->r.absmax, traceEnt->r.absmin, size );
  1724. VectorMA( traceEnt->r.absmin, 0.5, size, ent_org );
  1725. //see if they're in front of me
  1726. //must be within the forward cone
  1727. VectorSubtract( ent_org, center, dir );
  1728. VectorNormalize( dir );
  1729. if ( (dot = DotProduct( dir, forward )) < 0.5 )
  1730. continue;
  1731. //must be close enough
  1732. dist = VectorLength( v );
  1733. if ( dist >= radius )
  1734. {
  1735. continue;
  1736. }
  1737. //in PVS?
  1738. if ( !traceEnt->r.bmodel && !trap_InPVS( ent_org, self->client->ps.origin ) )
  1739. {//must be in PVS
  1740. continue;
  1741. }
  1742. //Now check and see if we can actually hit it
  1743. trap_Trace( &tr, self->client->ps.origin, vec3_origin, vec3_origin, ent_org, self->s.number, MASK_SHOT );
  1744. if ( tr.fraction < 1.0f && tr.entityNum != traceEnt->s.number )
  1745. {//must have clear LOS
  1746. continue;
  1747. }
  1748. // ok, we are within the radius, add us to the incoming list
  1749. ForceLightningDamage( self, traceEnt, dir, ent_org );
  1750. }
  1751. }
  1752. else
  1753. {//trace-line
  1754. VectorMA( self->client->ps.origin, 2048, forward, end );
  1755. trap_Trace( &tr, self->client->ps.origin, vec3_origin, vec3_origin, end, self->s.number, MASK_SHOT );
  1756. if ( tr.entityNum == ENTITYNUM_NONE || tr.fraction == 1.0 || tr.allsolid || tr.startsolid )
  1757. {
  1758. return;
  1759. }
  1760. traceEnt = &g_entities[tr.entityNum];
  1761. ForceLightningDamage( self, traceEnt, forward, tr.endpos );
  1762. }
  1763. }
  1764. void ForceDrain( gentity_t *self )
  1765. {
  1766. if ( self->health <= 0 )
  1767. {
  1768. return;
  1769. }
  1770. if (self->client->ps.forceHandExtend != HANDEXTEND_NONE)
  1771. {
  1772. return;
  1773. }
  1774. if (self->client->ps.weaponTime > 0)
  1775. {
  1776. return;
  1777. }
  1778. if ( self->client->ps.fd.forcePower < 25 || !WP_ForcePowerUsable( self, FP_DRAIN ) )
  1779. {
  1780. return;
  1781. }
  1782. if ( self->client->ps.fd.forcePowerDebounce[FP_DRAIN] > level.time )
  1783. {//stops it while using it and also after using it, up to 3 second delay
  1784. return;
  1785. }
  1786. // self->client->ps.forceHandExtend = HANDEXTEND_FORCEPUSH;
  1787. // self->client->ps.forceHandExtendTime = level.time + 1000;
  1788. self->client->ps.forceHandExtend = HANDEXTEND_FORCE_HOLD;
  1789. self->client->ps.forceHandExtendTime = level.time + 20000;
  1790. G_Sound( self, CHAN_BODY, G_SoundIndex("sound/weapons/force/drain.wav") );
  1791. WP_ForcePowerStart( self, FP_DRAIN, 500 );
  1792. }
  1793. void ForceDrainDamage( gentity_t *self, gentity_t *traceEnt, vec3_t dir, vec3_t impactPoint )
  1794. {
  1795. gentity_t *tent;
  1796. self->client->dangerTime = level.time;
  1797. self->client->ps.eFlags &= ~EF_INVULNERABLE;
  1798. self->client->invulnerableTimer = 0;
  1799. if ( traceEnt && traceEnt->takedamage )
  1800. {
  1801. if ( traceEnt->client && (!OnSameTeam(self, traceEnt) || g_friendlyFire.integer) && self->client->ps.fd.forceDrainTime < level.time && traceEnt->client->ps.fd.forcePower )
  1802. {//an enemy or object
  1803. if (!traceEnt->client && traceEnt->s.eType == ET_NPC)
  1804. { //g2animent
  1805. if (traceEnt->s.genericenemyindex < level.time)
  1806. {
  1807. traceEnt->s.genericenemyindex = level.time + 2000;
  1808. }
  1809. }
  1810. if (ForcePowerUsableOn(self, traceEnt, FP_DRAIN))
  1811. {
  1812. int modPowerLevel = -1;
  1813. int dmg = 0; //Q_irand( 1, 3 );
  1814. if (self->client->ps.fd.forcePowerLevel[FP_DRAIN] == FORCE_LEVEL_1)
  1815. {
  1816. dmg = 2; //because it's one-shot
  1817. }
  1818. else if (self->client->ps.fd.forcePowerLevel[FP_DRAIN] == FORCE_LEVEL_2)
  1819. {
  1820. dmg = 3;
  1821. }
  1822. else if (self->client->ps.fd.forcePowerLevel[FP_DRAIN] == FORCE_LEVEL_3)
  1823. {
  1824. dmg = 4;
  1825. }
  1826. if (traceEnt->client)
  1827. {
  1828. modPowerLevel = WP_AbsorbConversion(traceEnt, traceEnt->client->ps.fd.forcePowerLevel[FP_ABSORB], self, FP_DRAIN, self->client->ps.fd.forcePowerLevel[FP_DRAIN], 1);
  1829. }
  1830. if (modPowerLevel != -1)
  1831. {
  1832. if (!modPowerLevel)
  1833. {
  1834. dmg = 0;
  1835. }
  1836. else if (modPowerLevel == 1)
  1837. {
  1838. dmg = 1;
  1839. }
  1840. else if (modPowerLevel == 2)
  1841. {
  1842. dmg = 2;
  1843. }
  1844. }
  1845. //G_Damage( traceEnt, self, self, dir, impactPoint, dmg, 0, MOD_FORCE_DARK );
  1846. if (dmg)
  1847. {
  1848. traceEnt->client->ps.fd.forcePower -= (dmg);
  1849. }
  1850. if (traceEnt->client->ps.fd.forcePower < 0)
  1851. {
  1852. traceEnt->client->ps.fd.forcePower = 0;
  1853. }
  1854. if (self->client->ps.stats[STAT_HEALTH] < self->client->ps.stats[STAT_MAX_HEALTH] &&
  1855. self->health > 0 && self->client->ps.stats[STAT_HEALTH] > 0)
  1856. {
  1857. self->health += dmg;
  1858. if (self->health > self->client->ps.stats[STAT_MAX_HEALTH])
  1859. {
  1860. self->health = self->client->ps.stats[STAT_MAX_HEALTH];
  1861. }
  1862. self->client->ps.stats[STAT_HEALTH] = self->health;
  1863. }
  1864. traceEnt->client->ps.fd.forcePowerRegenDebounceTime = level.time + 800; //don't let the client being drained get force power back right away
  1865. //Drain the standard amount since we just drained someone else
  1866. /*
  1867. if (self->client->ps.fd.forcePowerLevel[FP_DRAIN] == FORCE_LEVEL_1)
  1868. {
  1869. BG_ForcePowerDrain( &self->client->ps, FP_DRAIN, 0 );
  1870. }
  1871. else
  1872. {
  1873. BG_ForcePowerDrain( &self->client->ps, FP_DRAIN, forcePowerNeeded[self->client->ps.fd.forcePowerLevel[FP_DRAIN]][FP_DRAIN]/5 );
  1874. }
  1875. if (self->client->ps.fd.forcePowerLevel[FP_DRAIN] == FORCE_LEVEL_1)
  1876. {
  1877. self->client->ps.fd.forceDrainTime = level.time + 100;
  1878. }
  1879. else
  1880. {
  1881. self->client->ps.fd.forceDrainTime = level.time + 20;
  1882. }
  1883. if ( traceEnt->client )
  1884. {
  1885. if ( !Q_irand( 0, 2 ) )
  1886. {
  1887. //G_Sound( traceEnt, CHAN_BODY, G_SoundIndex( "sound/weapons/force/lightninghit.wav" ) );
  1888. }
  1889. // traceEnt->s.powerups |= ( 1 << PW_DISINT_1 );
  1890. // traceEnt->client->ps.powerups[PW_DISINT_1] = level.time + 500;
  1891. }
  1892. */
  1893. if (traceEnt->client->forcePowerSoundDebounce < level.time)
  1894. {
  1895. tent = G_TempEntity( impactPoint, EV_FORCE_DRAINED);
  1896. tent->s.eventParm = DirToByte(dir);
  1897. tent->s.owner = traceEnt->s.number;
  1898. traceEnt->client->forcePowerSoundDebounce = level.time + 400;
  1899. }
  1900. }
  1901. }
  1902. }
  1903. }
  1904. int ForceShootDrain( gentity_t *self )
  1905. {
  1906. trace_t tr;
  1907. vec3_t end, forward;
  1908. gentity_t *traceEnt;
  1909. int gotOneOrMore = 0;
  1910. if ( self->health <= 0 )
  1911. {
  1912. return 0;
  1913. }
  1914. AngleVectors( self->client->ps.viewangles, forward, NULL, NULL );
  1915. VectorNormalize( forward );
  1916. if ( self->client->ps.fd.forcePowerLevel[FP_DRAIN] > FORCE_LEVEL_2 )
  1917. {//arc
  1918. vec3_t center, mins, maxs, dir, ent_org, size, v;
  1919. float radius = MAX_DRAIN_DISTANCE, dot, dist;
  1920. gentity_t *entityList[MAX_GENTITIES];
  1921. int iEntityList[MAX_GENTITIES];
  1922. int e, numListedEntities, i;
  1923. VectorCopy( self->client->ps.origin, center );
  1924. for ( i = 0 ; i < 3 ; i++ )
  1925. {
  1926. mins[i] = center[i] - radius;
  1927. maxs[i] = center[i] + radius;
  1928. }
  1929. numListedEntities = trap_EntitiesInBox( mins, maxs, iEntityList, MAX_GENTITIES );
  1930. i = 0;
  1931. while (i < numListedEntities)
  1932. {
  1933. entityList[i] = &g_entities[iEntityList[i]];
  1934. i++;
  1935. }
  1936. for ( e = 0 ; e < numListedEntities ; e++ )
  1937. {
  1938. traceEnt = entityList[e];
  1939. if ( !traceEnt )
  1940. continue;
  1941. if ( traceEnt == self )
  1942. continue;
  1943. if ( !traceEnt->inuse )
  1944. continue;
  1945. if ( !traceEnt->takedamage )
  1946. continue;
  1947. if ( traceEnt->health <= 0 )//no torturing corpses
  1948. continue;
  1949. if ( !traceEnt->client )
  1950. continue;
  1951. if ( !traceEnt->client->ps.fd.forcePower )
  1952. continue;
  1953. if (OnSameTeam(self, traceEnt) && !g_friendlyFire.integer)
  1954. continue;
  1955. //this is all to see if we need to start a saber attack, if it's in flight, this doesn't matter
  1956. // find the distance from the edge of the bounding box
  1957. for ( i = 0 ; i < 3 ; i++ )
  1958. {
  1959. if ( center[i] < traceEnt->r.absmin[i] )
  1960. {
  1961. v[i] = traceEnt->r.absmin[i] - center[i];
  1962. } else if ( center[i] > traceEnt->r.absmax[i] )
  1963. {
  1964. v[i] = center[i] - traceEnt->r.absmax[i];
  1965. } else
  1966. {
  1967. v[i] = 0;
  1968. }
  1969. }
  1970. VectorSubtract( traceEnt->r.absmax, traceEnt->r.absmin, size );
  1971. VectorMA( traceEnt->r.absmin, 0.5, size, ent_org );
  1972. //see if they're in front of me
  1973. //must be within the forward cone
  1974. VectorSubtract( ent_org, center, dir );
  1975. VectorNormalize( dir );
  1976. if ( (dot = DotProduct( dir, forward )) < 0.5 )
  1977. continue;
  1978. //must be close enough
  1979. dist = VectorLength( v );
  1980. if ( dist >= radius )
  1981. {
  1982. continue;
  1983. }
  1984. //in PVS?
  1985. if ( !traceEnt->r.bmodel && !trap_InPVS( ent_org, self->client->ps.origin ) )
  1986. {//must be in PVS
  1987. continue;
  1988. }
  1989. //Now check and see if we can actually hit it
  1990. trap_Trace( &tr, self->client->ps.origin, vec3_origin, vec3_origin, ent_org, self->s.number, MASK_SHOT );
  1991. if ( tr.fraction < 1.0f && tr.entityNum != traceEnt->s.number )
  1992. {//must have clear LOS
  1993. continue;
  1994. }
  1995. // ok, we are within the radius, add us to the incoming list
  1996. ForceDrainDamage( self, traceEnt, dir, ent_org );
  1997. gotOneOrMore = 1;
  1998. }
  1999. }
  2000. else
  2001. {//trace-line
  2002. VectorMA( self->client->ps.origin, 2048, forward, end );
  2003. trap_Trace( &tr, self->client->ps.origin, vec3_origin, vec3_origin, end, self->s.number, MASK_SHOT );
  2004. if ( tr.entityNum == ENTITYNUM_NONE || tr.fraction == 1.0 || tr.allsolid || tr.startsolid || !g_entities[tr.entityNum].client || !g_entities[tr.entityNum].inuse )
  2005. {
  2006. return 0;
  2007. }
  2008. traceEnt = &g_entities[tr.entityNum];
  2009. ForceDrainDamage( self, traceEnt, forward, tr.endpos );
  2010. gotOneOrMore = 1;
  2011. }
  2012. self->client->ps.activeForcePass = self->client->ps.fd.forcePowerLevel[FP_DRAIN] + FORCE_LEVEL_3;
  2013. BG_ForcePowerDrain( &self->client->ps, FP_DRAIN, 5 ); //used to be 1, but this did, too, anger the God of Balance.
  2014. self->client->ps.fd.forcePowerRegenDebounceTime = level.time + 500;
  2015. return gotOneOrMore;
  2016. }
  2017. void ForceJumpCharge( gentity_t *self, usercmd_t *ucmd )
  2018. { //I guess this is unused now. Was used for the "charge" jump type.
  2019. float forceJumpChargeInterval = forceJumpStrength[0] / (FORCE_JUMP_CHARGE_TIME/FRAMETIME);
  2020. if ( self->health <= 0 )
  2021. {
  2022. return;
  2023. }
  2024. if (!self->client->ps.fd.forceJumpCharge && self->client->ps.groundEntityNum == ENTITYNUM_NONE)
  2025. {
  2026. return;
  2027. }
  2028. if (self->client->ps.fd.forcePower < forcePowerNeeded[self->client->ps.fd.forcePowerLevel[FP_LEVITATION]][FP_LEVITATION])
  2029. {
  2030. G_MuteSound(self->client->ps.fd.killSoundEntIndex[TRACK_CHANNEL_1-50], CHAN_VOICE);
  2031. return;
  2032. }
  2033. if (!self->client->ps.fd.forceJumpCharge)
  2034. {
  2035. self->client->ps.fd.forceJumpAddTime = 0;
  2036. }
  2037. if (self->client->ps.fd.forceJumpAddTime >= level.time)
  2038. {
  2039. return;
  2040. }
  2041. //need to play sound
  2042. if ( !self->client->ps.fd.forceJumpCharge )
  2043. {
  2044. G_Sound( self, TRACK_CHANNEL_1, G_SoundIndex("sound/weapons/force/jumpbuild.wav") );
  2045. }
  2046. //Increment
  2047. if (self->client->ps.fd.forceJumpAddTime < level.time)
  2048. {
  2049. self->client->ps.fd.forceJumpCharge += forceJumpChargeInterval*50;
  2050. self->client->ps.fd.forceJumpAddTime = level.time + 500;
  2051. }
  2052. //clamp to max strength for current level
  2053. if ( self->client->ps.fd.forceJumpCharge > forceJumpStrength[self->client->ps.fd.forcePowerLevel[FP_LEVITATION]] )
  2054. {
  2055. self->client->ps.fd.forceJumpCharge = forceJumpStrength[self->client->ps.fd.forcePowerLevel[FP_LEVITATION]];
  2056. G_MuteSound(self->client->ps.fd.killSoundEntIndex[TRACK_CHANNEL_1-50], CHAN_VOICE);
  2057. }
  2058. //clamp to max available force power
  2059. if ( self->client->ps.fd.forceJumpCharge/forceJumpChargeInterval/(FORCE_JUMP_CHARGE_TIME/FRAMETIME)*forcePowerNeeded[self->client->ps.fd.forcePowerLevel[FP_LEVITATION]][FP_LEVITATION] > self->client->ps.fd.forcePower )
  2060. {//can't use more than you have
  2061. G_MuteSound(self->client->ps.fd.killSoundEntIndex[TRACK_CHANNEL_1-50], CHAN_VOICE);
  2062. self->client->ps.fd.forceJumpCharge = self->client->ps.fd.forcePower*forceJumpChargeInterval/(FORCE_JUMP_CHARGE_TIME/FRAMETIME);
  2063. }
  2064. //G_Printf("%f\n", self->client->ps.fd.forceJumpCharge);
  2065. }
  2066. int WP_GetVelocityForForceJump( gentity_t *self, vec3_t jumpVel, usercmd_t *ucmd )
  2067. {
  2068. float pushFwd = 0, pushRt = 0;
  2069. vec3_t view, forward, right;
  2070. VectorCopy( self->client->ps.viewangles, view );
  2071. view[0] = 0;
  2072. AngleVectors( view, forward, right, NULL );
  2073. if ( ucmd->forwardmove && ucmd->rightmove )
  2074. {
  2075. if ( ucmd->forwardmove > 0 )
  2076. {
  2077. pushFwd = 50;
  2078. }
  2079. else
  2080. {
  2081. pushFwd = -50;
  2082. }
  2083. if ( ucmd->rightmove > 0 )
  2084. {
  2085. pushRt = 50;
  2086. }
  2087. else
  2088. {
  2089. pushRt = -50;
  2090. }
  2091. }
  2092. else if ( ucmd->forwardmove || ucmd->rightmove )
  2093. {
  2094. if ( ucmd->forwardmove > 0 )
  2095. {
  2096. pushFwd = 100;
  2097. }
  2098. else if ( ucmd->forwardmove < 0 )
  2099. {
  2100. pushFwd = -100;
  2101. }
  2102. else if ( ucmd->rightmove > 0 )
  2103. {
  2104. pushRt = 100;
  2105. }
  2106. else if ( ucmd->rightmove < 0 )
  2107. {
  2108. pushRt = -100;
  2109. }
  2110. }
  2111. G_MuteSound(self->client->ps.fd.killSoundEntIndex[TRACK_CHANNEL_1-50], CHAN_VOICE);
  2112. G_PreDefSound(self->client->ps.origin, PDSOUND_FORCEJUMP);
  2113. if (self->client->ps.fd.forceJumpCharge < JUMP_VELOCITY+40)
  2114. { //give him at least a tiny boost from just a tap
  2115. self->client->ps.fd.forceJumpCharge = JUMP_VELOCITY+400;
  2116. }
  2117. if (self->client->ps.velocity[2] < -30)
  2118. { //so that we can get a good boost when force jumping in a fall
  2119. self->client->ps.velocity[2] = -30;
  2120. }
  2121. VectorMA( self->client->ps.velocity, pushFwd, forward, jumpVel );
  2122. VectorMA( self->client->ps.velocity, pushRt, right, jumpVel );
  2123. jumpVel[2] += self->client->ps.fd.forceJumpCharge;
  2124. if ( pushFwd > 0 && self->client->ps.fd.forceJumpCharge > 200 )
  2125. {
  2126. return FJ_FORWARD;
  2127. }
  2128. else if ( pushFwd < 0 && self->client->ps.fd.forceJumpCharge > 200 )
  2129. {
  2130. return FJ_BACKWARD;
  2131. }
  2132. else if ( pushRt > 0 && self->client->ps.fd.forceJumpCharge > 200 )
  2133. {
  2134. return FJ_RIGHT;
  2135. }
  2136. else if ( pushRt < 0 && self->client->ps.fd.forceJumpCharge > 200 )
  2137. {
  2138. return FJ_LEFT;
  2139. }
  2140. else
  2141. {
  2142. return FJ_UP;
  2143. }
  2144. }
  2145. void ForceJump( gentity_t *self, usercmd_t *ucmd )
  2146. {
  2147. float forceJumpChargeInterval;
  2148. vec3_t jumpVel;
  2149. if ( self->client->ps.fd.forcePowerDuration[FP_LEVITATION] > level.time )
  2150. {
  2151. return;
  2152. }
  2153. if ( !WP_ForcePowerUsable( self, FP_LEVITATION ) )
  2154. {
  2155. return;
  2156. }
  2157. if ( self->s.groundEntityNum == ENTITYNUM_NONE )
  2158. {
  2159. return;
  2160. }
  2161. if ( self->health <= 0 )
  2162. {
  2163. return;
  2164. }
  2165. self->client->fjDidJump = qtrue;
  2166. forceJumpChargeInterval = forceJumpStrength[self->client->ps.fd.forcePowerLevel[FP_LEVITATION]]/(FORCE_JUMP_CHARGE_TIME/FRAMETIME);
  2167. WP_GetVelocityForForceJump( self, jumpVel, ucmd );
  2168. //FIXME: sound effect
  2169. self->client->ps.fd.forceJumpZStart = self->client->ps.origin[2];//remember this for when we land
  2170. VectorCopy( jumpVel, self->client->ps.velocity );
  2171. //wasn't allowing them to attack when jumping, but that was annoying
  2172. //self->client->ps.weaponTime = self->client->ps.torsoAnimTimer;
  2173. WP_ForcePowerStart( self, FP_LEVITATION, self->client->ps.fd.forceJumpCharge/forceJumpChargeInterval/(FORCE_JUMP_CHARGE_TIME/FRAMETIME)*forcePowerNeeded[self->client->ps.fd.forcePowerLevel[FP_LEVITATION]][FP_LEVITATION] );
  2174. //self->client->ps.fd.forcePowerDuration[FP_LEVITATION] = level.time + self->client->ps.weaponTime;
  2175. self->client->ps.fd.forceJumpCharge = 0;
  2176. self->client->ps.forceJumpFlip = qtrue;
  2177. }
  2178. void WP_AddAsMindtricked(forcedata_t *fd, int entNum)
  2179. {
  2180. if (!fd)
  2181. {
  2182. return;
  2183. }
  2184. if (entNum > 47)
  2185. {
  2186. fd->forceMindtrickTargetIndex4 |= (1 << (entNum-48));
  2187. }
  2188. else if (entNum > 31)
  2189. {
  2190. fd->forceMindtrickTargetIndex3 |= (1 << (entNum-32));
  2191. }
  2192. else if (entNum > 15)
  2193. {
  2194. fd->forceMindtrickTargetIndex2 |= (1 << (entNum-16));
  2195. }
  2196. else
  2197. {
  2198. fd->forceMindtrickTargetIndex |= (1 << entNum);
  2199. }
  2200. }
  2201. qboolean ForceTelepathyCheckDirectNPCTarget( gentity_t *self, trace_t *tr, qboolean *tookPower )
  2202. {
  2203. gentity_t *traceEnt;
  2204. qboolean targetLive = qfalse, mindTrickDone = qfalse;
  2205. vec3_t tfrom, tto, fwd;
  2206. float radius = MAX_TRICK_DISTANCE;
  2207. //Check for a direct usage on NPCs first
  2208. VectorCopy(self->client->ps.origin, tfrom);
  2209. tfrom[2] += self->client->ps.viewheight;
  2210. AngleVectors(self->client->ps.viewangles, fwd, NULL, NULL);
  2211. tto[0] = tfrom[0] + fwd[0]*radius/2;
  2212. tto[1] = tfrom[1] + fwd[1]*radius/2;
  2213. tto[2] = tfrom[2] + fwd[2]*radius/2;
  2214. trap_Trace( tr, tfrom, NULL, NULL, tto, self->s.number, MASK_PLAYERSOLID );
  2215. if ( tr->entityNum == ENTITYNUM_NONE
  2216. || tr->fraction == 1.0f
  2217. || tr->allsolid
  2218. || tr->startsolid )
  2219. {
  2220. return qfalse;
  2221. }
  2222. traceEnt = &g_entities[tr->entityNum];
  2223. if( traceEnt->NPC
  2224. && traceEnt->NPC->scriptFlags & SCF_NO_FORCE )
  2225. {
  2226. return qfalse;
  2227. }
  2228. if ( traceEnt && traceEnt->client )
  2229. {
  2230. switch ( traceEnt->client->NPC_class )
  2231. {
  2232. case CLASS_GALAKMECH://cant grip him, he's in armor
  2233. case CLASS_ATST://much too big to grip!
  2234. //no droids either
  2235. case CLASS_PROBE:
  2236. case CLASS_GONK:
  2237. case CLASS_R2D2:
  2238. case CLASS_R5D2:
  2239. case CLASS_MARK1:
  2240. case CLASS_MARK2:
  2241. case CLASS_MOUSE:
  2242. case CLASS_SEEKER:
  2243. case CLASS_REMOTE:
  2244. case CLASS_PROTOCOL:
  2245. case CLASS_BOBAFETT:
  2246. case CLASS_RANCOR:
  2247. break;
  2248. default:
  2249. targetLive = qtrue;
  2250. break;
  2251. }
  2252. }
  2253. if ( traceEnt->s.number < MAX_CLIENTS )
  2254. {//a regular client
  2255. return qfalse;
  2256. }
  2257. if ( targetLive && traceEnt->NPC )
  2258. {//hit an organic non-player
  2259. vec3_t eyeDir;
  2260. if ( G_ActivateBehavior( traceEnt, BSET_MINDTRICK ) )
  2261. {//activated a script on him
  2262. //FIXME: do the visual sparkles effect on their heads, still?
  2263. WP_ForcePowerStart( self, FP_TELEPATHY, 0 );
  2264. }
  2265. else if ( (self->NPC && traceEnt->client->playerTeam != self->client->playerTeam)
  2266. || (!self->NPC && traceEnt->client->playerTeam != self->client->sess.sessionTeam) )
  2267. {//an enemy
  2268. int override = 0;
  2269. if ( (traceEnt->NPC->scriptFlags&SCF_NO_MIND_TRICK) )
  2270. {
  2271. }
  2272. else if ( traceEnt->s.weapon != WP_SABER
  2273. && traceEnt->client->NPC_class != CLASS_REBORN )
  2274. {//haha! Jedi aren't easily confused!
  2275. if ( self->client->ps.fd.forcePowerLevel[FP_TELEPATHY] > FORCE_LEVEL_2 )
  2276. {//turn them to our side
  2277. //if mind trick 3 and aiming at an enemy need more force power
  2278. if ( traceEnt->s.weapon != WP_NONE )
  2279. {//don't charm people who aren't capable of fighting... like ugnaughts and droids
  2280. int newPlayerTeam, newEnemyTeam;
  2281. if ( traceEnt->enemy )
  2282. {
  2283. G_ClearEnemy( traceEnt );
  2284. }
  2285. if ( traceEnt->NPC )
  2286. {
  2287. //traceEnt->NPC->tempBehavior = BS_FOLLOW_LEADER;
  2288. traceEnt->client->leader = self;
  2289. }
  2290. //FIXME: maybe pick an enemy right here?
  2291. if ( self->NPC )
  2292. {//NPC
  2293. newPlayerTeam = self->client->playerTeam;
  2294. newEnemyTeam = self->client->enemyTeam;
  2295. }
  2296. else
  2297. {//client/bot
  2298. if ( self->client->sess.sessionTeam == TEAM_BLUE )
  2299. {//rebel
  2300. newPlayerTeam = NPCTEAM_PLAYER;
  2301. newEnemyTeam = NPCTEAM_ENEMY;
  2302. }
  2303. else if ( self->client->sess.sessionTeam == TEAM_RED )
  2304. {//imperial
  2305. newPlayerTeam = NPCTEAM_ENEMY;
  2306. newEnemyTeam = NPCTEAM_PLAYER;
  2307. }
  2308. else
  2309. {//neutral - wan't attack anyone
  2310. newPlayerTeam = NPCTEAM_NEUTRAL;
  2311. newEnemyTeam = NPCTEAM_NEUTRAL;
  2312. }
  2313. }
  2314. //store these for retrieval later
  2315. traceEnt->genericValue1 = traceEnt->client->playerTeam;
  2316. traceEnt->genericValue2 = traceEnt->client->enemyTeam;
  2317. traceEnt->genericValue3 = traceEnt->s.teamowner;
  2318. //set the new values
  2319. traceEnt->client->playerTeam = newPlayerTeam;
  2320. traceEnt->client->enemyTeam = newEnemyTeam;
  2321. traceEnt->s.teamowner = newPlayerTeam;
  2322. //FIXME: need a *charmed* timer on this...? Or do TEAM_PLAYERS assume that "confusion" means they should switch to team_enemy when done?
  2323. traceEnt->NPC->charmedTime = level.time + mindTrickTime[self->client->ps.fd.forcePowerLevel[FP_TELEPATHY]];
  2324. }
  2325. }
  2326. else
  2327. {//just confuse them
  2328. //somehow confuse them? Set don't fire to true for a while? Drop their aggression? Maybe just take their enemy away and don't let them pick one up for a while unless shot?
  2329. traceEnt->NPC->confusionTime = level.time + mindTrickTime[self->client->ps.fd.forcePowerLevel[FP_TELEPATHY]];//confused for about 10 seconds
  2330. NPC_PlayConfusionSound( traceEnt );
  2331. if ( traceEnt->enemy )
  2332. {
  2333. G_ClearEnemy( traceEnt );
  2334. }
  2335. }
  2336. }
  2337. else
  2338. {
  2339. NPC_Jedi_PlayConfusionSound( traceEnt );
  2340. }
  2341. WP_ForcePowerStart( self, FP_TELEPATHY, override );
  2342. }
  2343. else if ( traceEnt->client->playerTeam == self->client->playerTeam )
  2344. {//an ally
  2345. //maybe just have him look at you? Respond? Take your enemy?
  2346. if ( traceEnt->client->ps.pm_type < PM_DEAD && traceEnt->NPC!=NULL && !(traceEnt->NPC->scriptFlags&SCF_NO_RESPONSE) )
  2347. {
  2348. NPC_UseResponse( traceEnt, self, qfalse );
  2349. WP_ForcePowerStart( self, FP_TELEPATHY, 1 );
  2350. }
  2351. }//NOTE: no effect on TEAM_NEUTRAL?
  2352. AngleVectors( traceEnt->client->renderInfo.eyeAngles, eyeDir, NULL, NULL );
  2353. VectorNormalize( eyeDir );
  2354. G_PlayEffectID( G_EffectIndex( "force/force_touch" ), traceEnt->client->renderInfo.eyePoint, eyeDir );
  2355. //make sure this plays and that you cannot press fire for about 1 second after this
  2356. //FIXME: BOTH_FORCEMINDTRICK or BOTH_FORCEDISTRACT
  2357. //NPC_SetAnim( self, SETANIM_TORSO, BOTH_MINDTRICK1, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_RESTART|SETANIM_FLAG_HOLD );
  2358. //FIXME: build-up or delay this until in proper part of anim
  2359. mindTrickDone = qtrue;
  2360. }
  2361. else
  2362. {
  2363. if ( self->client->ps.fd.forcePowerLevel[FP_TELEPATHY] > FORCE_LEVEL_1 && tr->fraction * 2048 > 64 )
  2364. {//don't create a diversion less than 64 from you of if at power level 1
  2365. //use distraction anim instead
  2366. G_PlayEffectID( G_EffectIndex( "force/force_touch" ), tr->endpos, tr->plane.normal );
  2367. //FIXME: these events don't seem to always be picked up...?
  2368. AddSoundEvent( self, tr->endpos, 512, AEL_SUSPICIOUS, qtrue );//, qtrue );
  2369. AddSightEvent( self, tr->endpos, 512, AEL_SUSPICIOUS, 50 );
  2370. WP_ForcePowerStart( self, FP_TELEPATHY, 0 );
  2371. *tookPower = qtrue;
  2372. }
  2373. //NPC_SetAnim( self, SETANIM_TORSO, BOTH_MINDTRICK2, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_RESTART|SETANIM_FLAG_HOLD );
  2374. }
  2375. //self->client->ps.saberMove = self->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  2376. self->client->ps.saberBlocked = BLOCKED_NONE;
  2377. self->client->ps.weaponTime = 1000;
  2378. /*
  2379. if ( self->client->ps.fd.forcePowersActive&(1<<FP_SPEED) )
  2380. {
  2381. self->client->ps.weaponTime = floor( self->client->ps.weaponTime * g_timescale->value );
  2382. }
  2383. */
  2384. return qtrue;
  2385. }
  2386. void ForceTelepathy(gentity_t *self)
  2387. {
  2388. trace_t tr;
  2389. vec3_t tto, thispush_org, a;
  2390. vec3_t mins, maxs, fwdangles, forward, right, center;
  2391. int i;
  2392. float visionArc = 0;
  2393. float radius = MAX_TRICK_DISTANCE;
  2394. qboolean tookPower = qfalse;
  2395. if ( self->health <= 0 )
  2396. {
  2397. return;
  2398. }
  2399. if (self->client->ps.forceHandExtend != HANDEXTEND_NONE)
  2400. {
  2401. return;
  2402. }
  2403. if (self->client->ps.weaponTime > 0)
  2404. {
  2405. return;
  2406. }
  2407. if (self->client->ps.powerups[PW_REDFLAG] ||
  2408. self->client->ps.powerups[PW_BLUEFLAG])
  2409. { //can't mindtrick while carrying the flag
  2410. return;
  2411. }
  2412. if (self->client->ps.forceAllowDeactivateTime < level.time &&
  2413. (self->client->ps.fd.forcePowersActive & (1 << FP_TELEPATHY)) )
  2414. {
  2415. WP_ForcePowerStop( self, FP_TELEPATHY );
  2416. return;
  2417. }
  2418. if ( !WP_ForcePowerUsable( self, FP_TELEPATHY ) )
  2419. {
  2420. return;
  2421. }
  2422. if ( ForceTelepathyCheckDirectNPCTarget( self, &tr, &tookPower ) )
  2423. {//hit an NPC directly
  2424. self->client->ps.forceAllowDeactivateTime = level.time + 1500;
  2425. G_Sound( self, CHAN_AUTO, G_SoundIndex("sound/weapons/force/distract.wav") );
  2426. self->client->ps.forceHandExtend = HANDEXTEND_FORCEPUSH;
  2427. self->client->ps.forceHandExtendTime = level.time + 1000;
  2428. return;
  2429. }
  2430. if (self->client->ps.fd.forcePowerLevel[FP_TELEPATHY] == FORCE_LEVEL_2)
  2431. {
  2432. visionArc = 180;
  2433. }
  2434. else if (self->client->ps.fd.forcePowerLevel[FP_TELEPATHY] == FORCE_LEVEL_3)
  2435. {
  2436. visionArc = 360;
  2437. radius = MAX_TRICK_DISTANCE*2.0f;
  2438. }
  2439. VectorCopy( self->client->ps.viewangles, fwdangles );
  2440. AngleVectors( fwdangles, forward, right, NULL );
  2441. VectorCopy( self->client->ps.origin, center );
  2442. for ( i = 0 ; i < 3 ; i++ )
  2443. {
  2444. mins[i] = center[i] - radius;
  2445. maxs[i] = center[i] + radius;
  2446. }
  2447. if (self->client->ps.fd.forcePowerLevel[FP_TELEPATHY] == FORCE_LEVEL_1)
  2448. {
  2449. if (tr.fraction != 1.0 &&
  2450. tr.entityNum != ENTITYNUM_NONE &&
  2451. g_entities[tr.entityNum].inuse &&
  2452. g_entities[tr.entityNum].client &&
  2453. g_entities[tr.entityNum].client->pers.connected &&
  2454. g_entities[tr.entityNum].client->sess.sessionTeam != TEAM_SPECTATOR)
  2455. {
  2456. WP_AddAsMindtricked(&self->client->ps.fd, tr.entityNum);
  2457. if ( !tookPower )
  2458. {
  2459. WP_ForcePowerStart( self, FP_TELEPATHY, 0 );
  2460. }
  2461. G_Sound( self, CHAN_AUTO, G_SoundIndex("sound/weapons/force/distract.wav") );
  2462. self->client->ps.forceHandExtend = HANDEXTEND_FORCEPUSH;
  2463. self->client->ps.forceHandExtendTime = level.time + 1000;
  2464. return;
  2465. }
  2466. else
  2467. {
  2468. return;
  2469. }
  2470. }
  2471. else //level 2 & 3
  2472. {
  2473. gentity_t *ent;
  2474. int entityList[MAX_GENTITIES];
  2475. int numListedEntities;
  2476. int e = 0;
  2477. qboolean gotatleastone = qfalse;
  2478. numListedEntities = trap_EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
  2479. while (e < numListedEntities)
  2480. {
  2481. ent = &g_entities[entityList[e]];
  2482. if (ent)
  2483. { //not in the arc, don't consider it
  2484. if (ent->client)
  2485. {
  2486. VectorCopy(ent->client->ps.origin, thispush_org);
  2487. }
  2488. else
  2489. {
  2490. VectorCopy(ent->s.pos.trBase, thispush_org);
  2491. }
  2492. VectorCopy(self->client->ps.origin, tto);
  2493. tto[2] += self->client->ps.viewheight;
  2494. VectorSubtract(thispush_org, tto, a);
  2495. vectoangles(a, a);
  2496. if (!ent->client)
  2497. {
  2498. entityList[e] = ENTITYNUM_NONE;
  2499. }
  2500. else if (!InFieldOfVision(self->client->ps.viewangles, visionArc, a))
  2501. { //only bother with arc rules if the victim is a client
  2502. entityList[e] = ENTITYNUM_NONE;
  2503. }
  2504. else if (!ForcePowerUsableOn(self, ent, FP_TELEPATHY))
  2505. {
  2506. entityList[e] = ENTITYNUM_NONE;
  2507. }
  2508. else if (OnSameTeam(self, ent))
  2509. {
  2510. entityList[e] = ENTITYNUM_NONE;
  2511. }
  2512. }
  2513. ent = &g_entities[entityList[e]];
  2514. if (ent && ent != self && ent->client)
  2515. {
  2516. gotatleastone = qtrue;
  2517. WP_AddAsMindtricked(&self->client->ps.fd, ent->s.number);
  2518. }
  2519. e++;
  2520. }
  2521. if (gotatleastone)
  2522. {
  2523. self->client->ps.forceAllowDeactivateTime = level.time + 1500;
  2524. if ( !tookPower )
  2525. {
  2526. WP_ForcePowerStart( self, FP_TELEPATHY, 0 );
  2527. }
  2528. G_Sound( self, CHAN_AUTO, G_SoundIndex("sound/weapons/force/distract.wav") );
  2529. self->client->ps.forceHandExtend = HANDEXTEND_FORCEPUSH;
  2530. self->client->ps.forceHandExtendTime = level.time + 1000;
  2531. }
  2532. }
  2533. }
  2534. void GEntity_UseFunc( gentity_t *self, gentity_t *other, gentity_t *activator )
  2535. {
  2536. GlobalUse(self, other, activator);
  2537. }
  2538. qboolean CanCounterThrow(gentity_t *self, gentity_t *thrower, qboolean pull)
  2539. {
  2540. int powerUse = 0;
  2541. if (self->client->ps.forceHandExtend != HANDEXTEND_NONE)
  2542. {
  2543. return 0;
  2544. }
  2545. if (self->client->ps.weaponTime > 0)
  2546. {
  2547. return 0;
  2548. }
  2549. if ( self->health <= 0 )
  2550. {
  2551. return 0;
  2552. }
  2553. if ( self->client->ps.powerups[PW_DISINT_4] > level.time )
  2554. {
  2555. return 0;
  2556. }
  2557. if (self->client->ps.weaponstate == WEAPON_CHARGING ||
  2558. self->client->ps.weaponstate == WEAPON_CHARGING_ALT)
  2559. { //don't autodefend when charging a weapon
  2560. return 0;
  2561. }
  2562. if (g_gametype.integer == GT_SIEGE &&
  2563. pull &&
  2564. thrower && thrower->client)
  2565. { //in siege, pull will affect people if they are not facing you, so they can't run away so much
  2566. vec3_t d;
  2567. float a;
  2568. VectorSubtract(thrower->client->ps.origin, self->client->ps.origin, d);
  2569. vectoangles(d, d);
  2570. a = AngleSubtract(d[YAW], self->client->ps.viewangles[YAW]);
  2571. if (a > 60.0f || a < -60.0f)
  2572. { //if facing more than 60 degrees away they cannot defend
  2573. return 0;
  2574. }
  2575. }
  2576. if (pull)
  2577. {
  2578. powerUse = FP_PULL;
  2579. }
  2580. else
  2581. {
  2582. powerUse = FP_PUSH;
  2583. }
  2584. if ( !WP_ForcePowerUsable( self, powerUse ) )
  2585. {
  2586. return 0;
  2587. }
  2588. if (self->client->ps.groundEntityNum == ENTITYNUM_NONE)
  2589. { //you cannot counter a push/pull if you're in the air
  2590. return 0;
  2591. }
  2592. return 1;
  2593. }
  2594. qboolean G_InGetUpAnim(playerState_t *ps)
  2595. {
  2596. switch( (ps->legsAnim) )
  2597. {
  2598. case BOTH_GETUP1:
  2599. case BOTH_GETUP2:
  2600. case BOTH_GETUP3:
  2601. case BOTH_GETUP4:
  2602. case BOTH_GETUP5:
  2603. case BOTH_FORCE_GETUP_F1:
  2604. case BOTH_FORCE_GETUP_F2:
  2605. case BOTH_FORCE_GETUP_B1:
  2606. case BOTH_FORCE_GETUP_B2:
  2607. case BOTH_FORCE_GETUP_B3:
  2608. case BOTH_FORCE_GETUP_B4:
  2609. case BOTH_FORCE_GETUP_B5:
  2610. case BOTH_GETUP_BROLL_B:
  2611. case BOTH_GETUP_BROLL_F:
  2612. case BOTH_GETUP_BROLL_L:
  2613. case BOTH_GETUP_BROLL_R:
  2614. case BOTH_GETUP_FROLL_B:
  2615. case BOTH_GETUP_FROLL_F:
  2616. case BOTH_GETUP_FROLL_L:
  2617. case BOTH_GETUP_FROLL_R:
  2618. return qtrue;
  2619. }
  2620. switch( (ps->torsoAnim) )
  2621. {
  2622. case BOTH_GETUP1:
  2623. case BOTH_GETUP2:
  2624. case BOTH_GETUP3:
  2625. case BOTH_GETUP4:
  2626. case BOTH_GETUP5:
  2627. case BOTH_FORCE_GETUP_F1:
  2628. case BOTH_FORCE_GETUP_F2:
  2629. case BOTH_FORCE_GETUP_B1:
  2630. case BOTH_FORCE_GETUP_B2:
  2631. case BOTH_FORCE_GETUP_B3:
  2632. case BOTH_FORCE_GETUP_B4:
  2633. case BOTH_FORCE_GETUP_B5:
  2634. case BOTH_GETUP_BROLL_B:
  2635. case BOTH_GETUP_BROLL_F:
  2636. case BOTH_GETUP_BROLL_L:
  2637. case BOTH_GETUP_BROLL_R:
  2638. case BOTH_GETUP_FROLL_B:
  2639. case BOTH_GETUP_FROLL_F:
  2640. case BOTH_GETUP_FROLL_L:
  2641. case BOTH_GETUP_FROLL_R:
  2642. return qtrue;
  2643. }
  2644. return qfalse;
  2645. }
  2646. void G_LetGoOfWall( gentity_t *ent )
  2647. {
  2648. if ( !ent || !ent->client )
  2649. {
  2650. return;
  2651. }
  2652. ent->client->ps.pm_flags &= ~PMF_STUCK_TO_WALL;
  2653. if ( BG_InReboundJump( ent->client->ps.legsAnim )
  2654. || BG_InReboundHold( ent->client->ps.legsAnim ) )
  2655. {
  2656. ent->client->ps.legsTimer = 0;
  2657. }
  2658. if ( BG_InReboundJump( ent->client->ps.torsoAnim )
  2659. || BG_InReboundHold( ent->client->ps.torsoAnim ) )
  2660. {
  2661. ent->client->ps.torsoTimer = 0;
  2662. }
  2663. }
  2664. float forcePushPullRadius[NUM_FORCE_POWER_LEVELS] =
  2665. {
  2666. 0,//none
  2667. 384,//256,
  2668. 448,//384,
  2669. 512
  2670. };
  2671. //rwwFIXMEFIXME: incorporate this into the below function? Currently it's only being used by jedi AI
  2672. extern void Touch_Button(gentity_t *ent, gentity_t *other, trace_t *trace );
  2673. void ForceThrow( gentity_t *self, qboolean pull )
  2674. {
  2675. //shove things in front of you away
  2676. float dist;
  2677. gentity_t *ent;
  2678. int entityList[MAX_GENTITIES];
  2679. gentity_t *push_list[MAX_GENTITIES];
  2680. int numListedEntities;
  2681. vec3_t mins, maxs;
  2682. vec3_t v;
  2683. int i, e;
  2684. int ent_count = 0;
  2685. int radius = 1024; //since it's view-based now. //350;
  2686. int powerLevel;
  2687. int visionArc;
  2688. int pushPower;
  2689. int pushPowerMod;
  2690. vec3_t center, ent_org, size, forward, right, end, dir, fwdangles = {0};
  2691. float dot1;
  2692. trace_t tr;
  2693. int x;
  2694. vec3_t pushDir;
  2695. vec3_t thispush_org;
  2696. vec3_t tfrom, tto, fwd, a;
  2697. float knockback = pull?0:200;
  2698. int powerUse = 0;
  2699. visionArc = 0;
  2700. if (self->client->ps.forceHandExtend != HANDEXTEND_NONE && (self->client->ps.forceHandExtend != HANDEXTEND_KNOCKDOWN || !G_InGetUpAnim(&self->client->ps)))
  2701. {
  2702. return;
  2703. }
  2704. if (!g_useWhileThrowing.integer && self->client->ps.saberInFlight)
  2705. {
  2706. return;
  2707. }
  2708. if (self->client->ps.weaponTime > 0)
  2709. {
  2710. return;
  2711. }
  2712. if ( self->health <= 0 )
  2713. {
  2714. return;
  2715. }
  2716. if ( self->client->ps.powerups[PW_DISINT_4] > level.time )
  2717. {
  2718. return;
  2719. }
  2720. if (pull)
  2721. {
  2722. powerUse = FP_PULL;
  2723. }
  2724. else
  2725. {
  2726. powerUse = FP_PUSH;
  2727. }
  2728. if ( !WP_ForcePowerUsable( self, powerUse ) )
  2729. {
  2730. return;
  2731. }
  2732. if (!pull && self->client->ps.saberLockTime > level.time && self->client->ps.saberLockFrame)
  2733. {
  2734. G_Sound( self, CHAN_BODY, G_SoundIndex( "sound/weapons/force/push.wav" ) );
  2735. self->client->ps.powerups[PW_DISINT_4] = level.time + 1500;
  2736. self->client->ps.saberLockHits += self->client->ps.fd.forcePowerLevel[FP_PUSH]*2;
  2737. WP_ForcePowerStart( self, FP_PUSH, 0 );
  2738. return;
  2739. }
  2740. WP_ForcePowerStart( self, powerUse, 0 );
  2741. //make sure this plays and that you cannot press fire for about 1 second after this
  2742. if ( pull )
  2743. {
  2744. G_Sound( self, CHAN_BODY, G_SoundIndex( "sound/weapons/force/pull.wav" ) );
  2745. if (self->client->ps.forceHandExtend == HANDEXTEND_NONE)
  2746. {
  2747. self->client->ps.forceHandExtend = HANDEXTEND_FORCEPULL;
  2748. if ( g_gametype.integer == GT_SIEGE && self->client->ps.weapon == WP_SABER )
  2749. {//hold less so can attack right after a pull
  2750. self->client->ps.forceHandExtendTime = level.time + 200;
  2751. }
  2752. else
  2753. {
  2754. self->client->ps.forceHandExtendTime = level.time + 400;
  2755. }
  2756. }
  2757. self->client->ps.powerups[PW_DISINT_4] = self->client->ps.forceHandExtendTime + 200;
  2758. self->client->ps.powerups[PW_PULL] = self->client->ps.powerups[PW_DISINT_4];
  2759. }
  2760. else
  2761. {
  2762. G_Sound( self, CHAN_BODY, G_SoundIndex( "sound/weapons/force/push.wav" ) );
  2763. if (self->client->ps.forceHandExtend == HANDEXTEND_NONE)
  2764. {
  2765. self->client->ps.forceHandExtend = HANDEXTEND_FORCEPUSH;
  2766. self->client->ps.forceHandExtendTime = level.time + 1000;
  2767. }
  2768. else if (self->client->ps.forceHandExtend == HANDEXTEND_KNOCKDOWN && G_InGetUpAnim(&self->client->ps))
  2769. {
  2770. if (self->client->ps.forceDodgeAnim > 4)
  2771. {
  2772. self->client->ps.forceDodgeAnim -= 8;
  2773. }
  2774. self->client->ps.forceDodgeAnim += 8; //special case, play push on upper torso, but keep playing current knockdown anim on legs
  2775. }
  2776. self->client->ps.powerups[PW_DISINT_4] = level.time + 1100;
  2777. self->client->ps.powerups[PW_PULL] = 0;
  2778. }
  2779. VectorCopy( self->client->ps.viewangles, fwdangles );
  2780. AngleVectors( fwdangles, forward, right, NULL );
  2781. VectorCopy( self->client->ps.origin, center );
  2782. for ( i = 0 ; i < 3 ; i++ )
  2783. {
  2784. mins[i] = center[i] - radius;
  2785. maxs[i] = center[i] + radius;
  2786. }
  2787. if (pull)
  2788. {
  2789. powerLevel = self->client->ps.fd.forcePowerLevel[FP_PULL];
  2790. pushPower = 256*self->client->ps.fd.forcePowerLevel[FP_PULL];
  2791. }
  2792. else
  2793. {
  2794. powerLevel = self->client->ps.fd.forcePowerLevel[FP_PUSH];
  2795. pushPower = 256*self->client->ps.fd.forcePowerLevel[FP_PUSH];
  2796. }
  2797. if (!powerLevel)
  2798. { //Shouldn't have made it here..
  2799. return;
  2800. }
  2801. if (powerLevel == FORCE_LEVEL_2)
  2802. {
  2803. visionArc = 60;
  2804. }
  2805. else if (powerLevel == FORCE_LEVEL_3)
  2806. {
  2807. visionArc = 180;
  2808. }
  2809. if (powerLevel == FORCE_LEVEL_1)
  2810. { //can only push/pull targeted things at level 1
  2811. VectorCopy(self->client->ps.origin, tfrom);
  2812. tfrom[2] += self->client->ps.viewheight;
  2813. AngleVectors(self->client->ps.viewangles, fwd, NULL, NULL);
  2814. tto[0] = tfrom[0] + fwd[0]*radius/2;
  2815. tto[1] = tfrom[1] + fwd[1]*radius/2;
  2816. tto[2] = tfrom[2] + fwd[2]*radius/2;
  2817. trap_Trace(&tr, tfrom, NULL, NULL, tto, self->s.number, MASK_PLAYERSOLID);
  2818. if (tr.fraction != 1.0 &&
  2819. tr.entityNum != ENTITYNUM_NONE)
  2820. {
  2821. if (!g_entities[tr.entityNum].client && g_entities[tr.entityNum].s.eType == ET_NPC)
  2822. { //g2animent
  2823. if (g_entities[tr.entityNum].s.genericenemyindex < level.time)
  2824. {
  2825. g_entities[tr.entityNum].s.genericenemyindex = level.time + 2000;
  2826. }
  2827. }
  2828. numListedEntities = 0;
  2829. entityList[numListedEntities] = tr.entityNum;
  2830. if (pull)
  2831. {
  2832. if (!ForcePowerUsableOn(self, &g_entities[tr.entityNum], FP_PULL))
  2833. {
  2834. return;
  2835. }
  2836. }
  2837. else
  2838. {
  2839. if (!ForcePowerUsableOn(self, &g_entities[tr.entityNum], FP_PUSH))
  2840. {
  2841. return;
  2842. }
  2843. }
  2844. numListedEntities++;
  2845. }
  2846. else
  2847. {
  2848. //didn't get anything, so just
  2849. return;
  2850. }
  2851. }
  2852. else
  2853. {
  2854. numListedEntities = trap_EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
  2855. e = 0;
  2856. while (e < numListedEntities)
  2857. {
  2858. ent = &g_entities[entityList[e]];
  2859. if (!ent->client && ent->s.eType == ET_NPC)
  2860. { //g2animent
  2861. if (ent->s.genericenemyindex < level.time)
  2862. {
  2863. ent->s.genericenemyindex = level.time + 2000;
  2864. }
  2865. }
  2866. if (ent)
  2867. {
  2868. if (ent->client)
  2869. {
  2870. VectorCopy(ent->client->ps.origin, thispush_org);
  2871. }
  2872. else
  2873. {
  2874. VectorCopy(ent->s.pos.trBase, thispush_org);
  2875. }
  2876. }
  2877. if (ent)
  2878. { //not in the arc, don't consider it
  2879. VectorCopy(self->client->ps.origin, tto);
  2880. tto[2] += self->client->ps.viewheight;
  2881. VectorSubtract(thispush_org, tto, a);
  2882. vectoangles(a, a);
  2883. if (ent->client && !InFieldOfVision(self->client->ps.viewangles, visionArc, a) &&
  2884. ForcePowerUsableOn(self, ent, powerUse))
  2885. { //only bother with arc rules if the victim is a client
  2886. entityList[e] = ENTITYNUM_NONE;
  2887. }
  2888. else if (ent->client)
  2889. {
  2890. if (pull)
  2891. {
  2892. if (!ForcePowerUsableOn(self, ent, FP_PULL))
  2893. {
  2894. entityList[e] = ENTITYNUM_NONE;
  2895. }
  2896. }
  2897. else
  2898. {
  2899. if (!ForcePowerUsableOn(self, ent, FP_PUSH))
  2900. {
  2901. entityList[e] = ENTITYNUM_NONE;
  2902. }
  2903. }
  2904. }
  2905. }
  2906. e++;
  2907. }
  2908. }
  2909. for ( e = 0 ; e < numListedEntities ; e++ )
  2910. {
  2911. if (entityList[e] != ENTITYNUM_NONE &&
  2912. entityList[e] >= 0 &&
  2913. entityList[e] < MAX_GENTITIES)
  2914. {
  2915. ent = &g_entities[entityList[e]];
  2916. }
  2917. else
  2918. {
  2919. ent = NULL;
  2920. }
  2921. if (!ent)
  2922. continue;
  2923. if (ent == self)
  2924. continue;
  2925. if (ent->client && OnSameTeam(ent, self))
  2926. {
  2927. continue;
  2928. }
  2929. if ( !(ent->inuse) )
  2930. continue;
  2931. if ( ent->s.eType != ET_MISSILE )
  2932. {
  2933. if ( ent->s.eType != ET_ITEM )
  2934. {
  2935. //FIXME: need pushable objects
  2936. if ( Q_stricmp( "func_button", ent->classname ) == 0 )
  2937. {//we might push it
  2938. if ( pull || !(ent->spawnflags&SPF_BUTTON_FPUSHABLE) )
  2939. {//not force-pushable, never pullable
  2940. continue;
  2941. }
  2942. }
  2943. else
  2944. {
  2945. if ( ent->s.eFlags & EF_NODRAW )
  2946. {
  2947. continue;
  2948. }
  2949. if ( !ent->client )
  2950. {
  2951. if ( Q_stricmp( "lightsaber", ent->classname ) != 0 )
  2952. {//not a lightsaber
  2953. if ( Q_stricmp( "func_door", ent->classname ) != 0 || !(ent->spawnflags & 2/*MOVER_FORCE_ACTIVATE*/) )
  2954. {//not a force-usable door
  2955. if ( Q_stricmp( "func_static", ent->classname ) != 0 || (!(ent->spawnflags&1/*F_PUSH*/)&&!(ent->spawnflags&2/*F_PULL*/)) )
  2956. {//not a force-usable func_static
  2957. if ( Q_stricmp( "limb", ent->classname ) )
  2958. {//not a limb
  2959. continue;
  2960. }
  2961. }
  2962. }
  2963. else if ( ent->moverState != MOVER_POS1 && ent->moverState != MOVER_POS2 )
  2964. {//not at rest
  2965. continue;
  2966. }
  2967. }
  2968. }
  2969. else if ( ent->client->NPC_class == CLASS_GALAKMECH
  2970. || ent->client->NPC_class == CLASS_ATST
  2971. || ent->client->NPC_class == CLASS_RANCOR )
  2972. {//can't push ATST or Galak or Rancor
  2973. continue;
  2974. }
  2975. }
  2976. }
  2977. }
  2978. else
  2979. {
  2980. if ( ent->s.pos.trType == TR_STATIONARY && (ent->s.eFlags&EF_MISSILE_STICK) )
  2981. {//can't force-push/pull stuck missiles (detpacks, tripmines)
  2982. continue;
  2983. }
  2984. if ( ent->s.pos.trType == TR_STATIONARY && ent->s.weapon != WP_THERMAL )
  2985. {//only thermal detonators can be pushed once stopped
  2986. continue;
  2987. }
  2988. }
  2989. //this is all to see if we need to start a saber attack, if it's in flight, this doesn't matter
  2990. // find the distance from the edge of the bounding box
  2991. for ( i = 0 ; i < 3 ; i++ )
  2992. {
  2993. if ( center[i] < ent->r.absmin[i] )
  2994. {
  2995. v[i] = ent->r.absmin[i] - center[i];
  2996. } else if ( center[i] > ent->r.absmax[i] )
  2997. {
  2998. v[i] = center[i] - ent->r.absmax[i];
  2999. } else
  3000. {
  3001. v[i] = 0;
  3002. }
  3003. }
  3004. VectorSubtract( ent->r.absmax, ent->r.absmin, size );
  3005. VectorMA( ent->r.absmin, 0.5, size, ent_org );
  3006. VectorSubtract( ent_org, center, dir );
  3007. VectorNormalize( dir );
  3008. if ( (dot1 = DotProduct( dir, forward )) < 0.6 )
  3009. continue;
  3010. dist = VectorLength( v );
  3011. //Now check and see if we can actually deflect it
  3012. //method1
  3013. //if within a certain range, deflect it
  3014. if ( dist >= radius )
  3015. {
  3016. continue;
  3017. }
  3018. //in PVS?
  3019. if ( !ent->r.bmodel && !trap_InPVS( ent_org, self->client->ps.origin ) )
  3020. {//must be in PVS
  3021. continue;
  3022. }
  3023. //really should have a clear LOS to this thing...
  3024. trap_Trace( &tr, self->client->ps.origin, vec3_origin, vec3_origin, ent_org, self->s.number, MASK_SHOT );
  3025. if ( tr.fraction < 1.0f && tr.entityNum != ent->s.number )
  3026. {//must have clear LOS
  3027. //try from eyes too before you give up
  3028. vec3_t eyePoint;
  3029. VectorCopy(self->client->ps.origin, eyePoint);
  3030. eyePoint[2] += self->client->ps.viewheight;
  3031. trap_Trace( &tr, eyePoint, vec3_origin, vec3_origin, ent_org, self->s.number, MASK_SHOT );
  3032. if ( tr.fraction < 1.0f && tr.entityNum != ent->s.number )
  3033. {
  3034. continue;
  3035. }
  3036. }
  3037. // ok, we are within the radius, add us to the incoming list
  3038. push_list[ent_count] = ent;
  3039. ent_count++;
  3040. }
  3041. if ( ent_count )
  3042. {
  3043. //method1:
  3044. for ( x = 0; x < ent_count; x++ )
  3045. {
  3046. int modPowerLevel = powerLevel;
  3047. if (push_list[x]->client)
  3048. {
  3049. modPowerLevel = WP_AbsorbConversion(push_list[x], push_list[x]->client->ps.fd.forcePowerLevel[FP_ABSORB], self, powerUse, powerLevel, forcePowerNeeded[self->client->ps.fd.forcePowerLevel[powerUse]][powerUse]);
  3050. if (modPowerLevel == -1)
  3051. {
  3052. modPowerLevel = powerLevel;
  3053. }
  3054. }
  3055. pushPower = 256*modPowerLevel;
  3056. if (push_list[x]->client)
  3057. {
  3058. VectorCopy(push_list[x]->client->ps.origin, thispush_org);
  3059. }
  3060. else
  3061. {
  3062. VectorCopy(push_list[x]->s.origin, thispush_org);
  3063. }
  3064. if ( push_list[x]->client )
  3065. {//FIXME: make enemy jedi able to hunker down and resist this?
  3066. int otherPushPower = push_list[x]->client->ps.fd.forcePowerLevel[powerUse];
  3067. qboolean canPullWeapon = qtrue;
  3068. float dirLen = 0;
  3069. if ( g_debugMelee.integer )
  3070. {
  3071. if ( (push_list[x]->client->ps.pm_flags&PMF_STUCK_TO_WALL) )
  3072. {//no resistance if stuck to wall
  3073. //push/pull them off the wall
  3074. otherPushPower = 0;
  3075. G_LetGoOfWall( push_list[x] );
  3076. }
  3077. }
  3078. knockback = pull?0:200;
  3079. pushPowerMod = pushPower;
  3080. if (push_list[x]->client->pers.cmd.forwardmove ||
  3081. push_list[x]->client->pers.cmd.rightmove)
  3082. { //if you are moving, you get one less level of defense
  3083. otherPushPower--;
  3084. if (otherPushPower < 0)
  3085. {
  3086. otherPushPower = 0;
  3087. }
  3088. }
  3089. if (otherPushPower && CanCounterThrow(push_list[x], self, pull))
  3090. {
  3091. if ( pull )
  3092. {
  3093. G_Sound( push_list[x], CHAN_BODY, G_SoundIndex( "sound/weapons/force/pull.wav" ) );
  3094. push_list[x]->client->ps.forceHandExtend = HANDEXTEND_FORCEPULL;
  3095. push_list[x]->client->ps.forceHandExtendTime = level.time + 400;
  3096. }
  3097. else
  3098. {
  3099. G_Sound( push_list[x], CHAN_BODY, G_SoundIndex( "sound/weapons/force/push.wav" ) );
  3100. push_list[x]->client->ps.forceHandExtend = HANDEXTEND_FORCEPUSH;
  3101. push_list[x]->client->ps.forceHandExtendTime = level.time + 1000;
  3102. }
  3103. push_list[x]->client->ps.powerups[PW_DISINT_4] = push_list[x]->client->ps.forceHandExtendTime + 200;
  3104. if (pull)
  3105. {
  3106. push_list[x]->client->ps.powerups[PW_PULL] = push_list[x]->client->ps.powerups[PW_DISINT_4];
  3107. }
  3108. else
  3109. {
  3110. push_list[x]->client->ps.powerups[PW_PULL] = 0;
  3111. }
  3112. //Make a counter-throw effect
  3113. if (otherPushPower >= modPowerLevel)
  3114. {
  3115. pushPowerMod = 0;
  3116. canPullWeapon = qfalse;
  3117. }
  3118. else
  3119. {
  3120. int powerDif = (modPowerLevel - otherPushPower);
  3121. if (powerDif >= 3)
  3122. {
  3123. pushPowerMod -= pushPowerMod*0.2;
  3124. }
  3125. else if (powerDif == 2)
  3126. {
  3127. pushPowerMod -= pushPowerMod*0.4;
  3128. }
  3129. else if (powerDif == 1)
  3130. {
  3131. pushPowerMod -= pushPowerMod*0.8;
  3132. }
  3133. if (pushPowerMod < 0)
  3134. {
  3135. pushPowerMod = 0;
  3136. }
  3137. }
  3138. }
  3139. //shove them
  3140. if ( pull )
  3141. {
  3142. VectorSubtract( self->client->ps.origin, thispush_org, pushDir );
  3143. if (push_list[x]->client && VectorLength(pushDir) <= 256)
  3144. {
  3145. int randfact = 0;
  3146. if (modPowerLevel == FORCE_LEVEL_1)
  3147. {
  3148. randfact = 3;
  3149. }
  3150. else if (modPowerLevel == FORCE_LEVEL_2)
  3151. {
  3152. randfact = 7;
  3153. }
  3154. else if (modPowerLevel == FORCE_LEVEL_3)
  3155. {
  3156. randfact = 10;
  3157. }
  3158. if (!OnSameTeam(self, push_list[x]) && Q_irand(1, 10) <= randfact && canPullWeapon)
  3159. {
  3160. vec3_t uorg, vecnorm;
  3161. VectorCopy(self->client->ps.origin, uorg);
  3162. uorg[2] += 64;
  3163. VectorSubtract(uorg, thispush_org, vecnorm);
  3164. VectorNormalize(vecnorm);
  3165. TossClientWeapon(push_list[x], vecnorm, 500);
  3166. }
  3167. }
  3168. }
  3169. else
  3170. {
  3171. VectorSubtract( thispush_org, self->client->ps.origin, pushDir );
  3172. }
  3173. if ((modPowerLevel > otherPushPower || push_list[x]->client->ps.m_iVehicleNum) && push_list[x]->client)
  3174. {
  3175. if (modPowerLevel == FORCE_LEVEL_3 &&
  3176. push_list[x]->client->ps.forceHandExtend != HANDEXTEND_KNOCKDOWN)
  3177. {
  3178. dirLen = VectorLength(pushDir);
  3179. if (BG_KnockDownable(&push_list[x]->client->ps) &&
  3180. dirLen <= (64*((modPowerLevel - otherPushPower)-1)))
  3181. { //can only do a knockdown if fairly close
  3182. push_list[x]->client->ps.forceHandExtend = HANDEXTEND_KNOCKDOWN;
  3183. push_list[x]->client->ps.forceHandExtendTime = level.time + 700;
  3184. push_list[x]->client->ps.forceDodgeAnim = 0; //this toggles between 1 and 0, when it's 1 we should play the get up anim
  3185. push_list[x]->client->ps.quickerGetup = qtrue;
  3186. }
  3187. else if (push_list[x]->s.number < MAX_CLIENTS && push_list[x]->client->ps.m_iVehicleNum &&
  3188. dirLen <= 128.0f )
  3189. { //a player on a vehicle
  3190. gentity_t *vehEnt = &g_entities[push_list[x]->client->ps.m_iVehicleNum];
  3191. if (vehEnt->inuse && vehEnt->client && vehEnt->m_pVehicle)
  3192. {
  3193. if (vehEnt->m_pVehicle->m_pVehicleInfo->type == VH_SPEEDER ||
  3194. vehEnt->m_pVehicle->m_pVehicleInfo->type == VH_ANIMAL)
  3195. { //push the guy off
  3196. vehEnt->m_pVehicle->m_pVehicleInfo->Eject(vehEnt->m_pVehicle, (bgEntity_t *)push_list[x], qfalse);
  3197. }
  3198. }
  3199. }
  3200. }
  3201. }
  3202. if (!dirLen)
  3203. {
  3204. dirLen = VectorLength(pushDir);
  3205. }
  3206. VectorNormalize(pushDir);
  3207. if (push_list[x]->client)
  3208. {
  3209. //escape a force grip if we're in one
  3210. if (self->client->ps.fd.forceGripBeingGripped > level.time)
  3211. { //force the enemy to stop gripping me if I managed to push him
  3212. if (push_list[x]->client->ps.fd.forceGripEntityNum == self->s.number)
  3213. {
  3214. if (modPowerLevel >= push_list[x]->client->ps.fd.forcePowerLevel[FP_GRIP])
  3215. { //only break the grip if our push/pull level is >= their grip level
  3216. WP_ForcePowerStop(push_list[x], FP_GRIP);
  3217. self->client->ps.fd.forceGripBeingGripped = 0;
  3218. push_list[x]->client->ps.fd.forceGripUseTime = level.time + 1000; //since we just broke out of it..
  3219. }
  3220. }
  3221. }
  3222. push_list[x]->client->ps.otherKiller = self->s.number;
  3223. push_list[x]->client->ps.otherKillerTime = level.time + 5000;
  3224. push_list[x]->client->ps.otherKillerDebounceTime = level.time + 100;
  3225. pushPowerMod -= (dirLen*0.7);
  3226. if (pushPowerMod < 16)
  3227. {
  3228. pushPowerMod = 16;
  3229. }
  3230. //fullbody push effect
  3231. push_list[x]->client->pushEffectTime = level.time + 600;
  3232. push_list[x]->client->ps.velocity[0] = pushDir[0]*pushPowerMod;
  3233. push_list[x]->client->ps.velocity[1] = pushDir[1]*pushPowerMod;
  3234. if ((int)push_list[x]->client->ps.velocity[2] == 0)
  3235. { //if not going anywhere vertically, boost them up a bit
  3236. push_list[x]->client->ps.velocity[2] = pushDir[2]*pushPowerMod;
  3237. if (push_list[x]->client->ps.velocity[2] < 128)
  3238. {
  3239. push_list[x]->client->ps.velocity[2] = 128;
  3240. }
  3241. }
  3242. else
  3243. {
  3244. push_list[x]->client->ps.velocity[2] = pushDir[2]*pushPowerMod;
  3245. }
  3246. }
  3247. }
  3248. else if ( push_list[x]->s.eType == ET_MISSILE && push_list[x]->s.pos.trType != TR_STATIONARY && (push_list[x]->s.pos.trType != TR_INTERPOLATE||push_list[x]->s.weapon != WP_THERMAL) )//rolling and stationary thermal detonators are dealt with below
  3249. {
  3250. if ( pull )
  3251. {//deflect rather than reflect?
  3252. }
  3253. else
  3254. {
  3255. G_ReflectMissile( self, push_list[x], forward );
  3256. }
  3257. }
  3258. else if ( !Q_stricmp( "func_static", push_list[x]->classname ) )
  3259. {//force-usable func_static
  3260. if ( !pull && (push_list[x]->spawnflags&1/*F_PUSH*/) )
  3261. {
  3262. GEntity_UseFunc( push_list[x], self, self );
  3263. }
  3264. else if ( pull && (push_list[x]->spawnflags&2/*F_PULL*/) )
  3265. {
  3266. GEntity_UseFunc( push_list[x], self, self );
  3267. }
  3268. }
  3269. else if ( !Q_stricmp( "func_door", push_list[x]->classname ) && (push_list[x]->spawnflags&2) )
  3270. {//push/pull the door
  3271. vec3_t pos1, pos2;
  3272. vec3_t trFrom;
  3273. VectorCopy(self->client->ps.origin, trFrom);
  3274. trFrom[2] += self->client->ps.viewheight;
  3275. AngleVectors( self->client->ps.viewangles, forward, NULL, NULL );
  3276. VectorNormalize( forward );
  3277. VectorMA( trFrom, radius, forward, end );
  3278. trap_Trace( &tr, trFrom, vec3_origin, vec3_origin, end, self->s.number, MASK_SHOT );
  3279. if ( tr.entityNum != push_list[x]->s.number || tr.fraction == 1.0 || tr.allsolid || tr.startsolid )
  3280. {//must be pointing right at it
  3281. continue;
  3282. }
  3283. if ( VectorCompare( vec3_origin, push_list[x]->s.origin ) )
  3284. {//does not have an origin brush, so pos1 & pos2 are relative to world origin, need to calc center
  3285. VectorSubtract( push_list[x]->r.absmax, push_list[x]->r.absmin, size );
  3286. VectorMA( push_list[x]->r.absmin, 0.5, size, center );
  3287. if ( (push_list[x]->spawnflags&1) && push_list[x]->moverState == MOVER_POS1 )
  3288. {//if at pos1 and started open, make sure we get the center where it *started* because we're going to add back in the relative values pos1 and pos2
  3289. VectorSubtract( center, push_list[x]->pos1, center );
  3290. }
  3291. else if ( !(push_list[x]->spawnflags&1) && push_list[x]->moverState == MOVER_POS2 )
  3292. {//if at pos2, make sure we get the center where it *started* because we're going to add back in the relative values pos1 and pos2
  3293. VectorSubtract( center, push_list[x]->pos2, center );
  3294. }
  3295. VectorAdd( center, push_list[x]->pos1, pos1 );
  3296. VectorAdd( center, push_list[x]->pos2, pos2 );
  3297. }
  3298. else
  3299. {//actually has an origin, pos1 and pos2 are absolute
  3300. VectorCopy( push_list[x]->r.currentOrigin, center );
  3301. VectorCopy( push_list[x]->pos1, pos1 );
  3302. VectorCopy( push_list[x]->pos2, pos2 );
  3303. }
  3304. if ( Distance( pos1, trFrom ) < Distance( pos2, trFrom ) )
  3305. {//pos1 is closer
  3306. if ( push_list[x]->moverState == MOVER_POS1 )
  3307. {//at the closest pos
  3308. if ( pull )
  3309. {//trying to pull, but already at closest point, so screw it
  3310. continue;
  3311. }
  3312. }
  3313. else if ( push_list[x]->moverState == MOVER_POS2 )
  3314. {//at farthest pos
  3315. if ( !pull )
  3316. {//trying to push, but already at farthest point, so screw it
  3317. continue;
  3318. }
  3319. }
  3320. }
  3321. else
  3322. {//pos2 is closer
  3323. if ( push_list[x]->moverState == MOVER_POS1 )
  3324. {//at the farthest pos
  3325. if ( !pull )
  3326. {//trying to push, but already at farthest point, so screw it
  3327. continue;
  3328. }
  3329. }
  3330. else if ( push_list[x]->moverState == MOVER_POS2 )
  3331. {//at closest pos
  3332. if ( pull )
  3333. {//trying to pull, but already at closest point, so screw it
  3334. continue;
  3335. }
  3336. }
  3337. }
  3338. GEntity_UseFunc( push_list[x], self, self );
  3339. }
  3340. else if ( Q_stricmp( "func_button", push_list[x]->classname ) == 0 )
  3341. {//pretend you pushed it
  3342. Touch_Button( push_list[x], self, NULL );
  3343. continue;
  3344. }
  3345. }
  3346. }
  3347. //attempt to break any leftover grips
  3348. //if we're still in a current grip that wasn't broken by the push, it will still remain
  3349. self->client->dangerTime = level.time;
  3350. self->client->ps.eFlags &= ~EF_INVULNERABLE;
  3351. self->client->invulnerableTimer = 0;
  3352. if (self->client->ps.fd.forceGripBeingGripped > level.time)
  3353. {
  3354. self->client->ps.fd.forceGripBeingGripped = 0;
  3355. }
  3356. }
  3357. void WP_ForcePowerStop( gentity_t *self, forcePowers_t forcePower )
  3358. {
  3359. int wasActive = self->client->ps.fd.forcePowersActive;
  3360. self->client->ps.fd.forcePowersActive &= ~( 1 << forcePower );
  3361. switch( (int)forcePower )
  3362. {
  3363. case FP_HEAL:
  3364. self->client->ps.fd.forceHealAmount = 0;
  3365. self->client->ps.fd.forceHealTime = 0;
  3366. break;
  3367. case FP_LEVITATION:
  3368. break;
  3369. case FP_SPEED:
  3370. if (wasActive & (1 << FP_SPEED))
  3371. {
  3372. G_MuteSound(self->client->ps.fd.killSoundEntIndex[TRACK_CHANNEL_2-50], CHAN_VOICE);
  3373. }
  3374. break;
  3375. case FP_PUSH:
  3376. break;
  3377. case FP_PULL:
  3378. break;
  3379. case FP_TELEPATHY:
  3380. if (wasActive & (1 << FP_TELEPATHY))
  3381. {
  3382. G_Sound( self, CHAN_AUTO, G_SoundIndex("sound/weapons/force/distractstop.wav") );
  3383. }
  3384. self->client->ps.fd.forceMindtrickTargetIndex = 0;
  3385. self->client->ps.fd.forceMindtrickTargetIndex2 = 0;
  3386. self->client->ps.fd.forceMindtrickTargetIndex3 = 0;
  3387. self->client->ps.fd.forceMindtrickTargetIndex4 = 0;
  3388. break;
  3389. case FP_SEE:
  3390. if (wasActive & (1 << FP_SEE))
  3391. {
  3392. G_MuteSound(self->client->ps.fd.killSoundEntIndex[TRACK_CHANNEL_5-50], CHAN_VOICE);
  3393. }
  3394. break;
  3395. case FP_GRIP:
  3396. self->client->ps.fd.forceGripUseTime = level.time + 3000;
  3397. if (self->client->ps.fd.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_1 &&
  3398. g_entities[self->client->ps.fd.forceGripEntityNum].client &&
  3399. g_entities[self->client->ps.fd.forceGripEntityNum].health > 0 &&
  3400. g_entities[self->client->ps.fd.forceGripEntityNum].inuse &&
  3401. (level.time - g_entities[self->client->ps.fd.forceGripEntityNum].client->ps.fd.forceGripStarted) > 500)
  3402. { //if we had our throat crushed in for more than half a second, gasp for air when we're let go
  3403. if (wasActive & (1 << FP_GRIP))
  3404. {
  3405. G_EntitySound( &g_entities[self->client->ps.fd.forceGripEntityNum], CHAN_VOICE, G_SoundIndex("*gasp.wav") );
  3406. }
  3407. }
  3408. if (g_entities[self->client->ps.fd.forceGripEntityNum].client &&
  3409. g_entities[self->client->ps.fd.forceGripEntityNum].inuse)
  3410. {
  3411. g_entities[self->client->ps.fd.forceGripEntityNum].client->ps.forceGripChangeMovetype = PM_NORMAL;
  3412. }
  3413. if (self->client->ps.forceHandExtend == HANDEXTEND_FORCE_HOLD)
  3414. {
  3415. self->client->ps.forceHandExtendTime = 0;
  3416. }
  3417. self->client->ps.fd.forceGripEntityNum = ENTITYNUM_NONE;
  3418. self->client->ps.powerups[PW_DISINT_4] = 0;
  3419. break;
  3420. case FP_LIGHTNING:
  3421. if ( self->client->ps.fd.forcePowerLevel[FP_LIGHTNING] < FORCE_LEVEL_2 )
  3422. {//don't do it again for 3 seconds, minimum... FIXME: this should be automatic once regeneration is slower (normal)
  3423. self->client->ps.fd.forcePowerDebounce[FP_LIGHTNING] = level.time + 3000;
  3424. }
  3425. else
  3426. {
  3427. self->client->ps.fd.forcePowerDebounce[FP_LIGHTNING] = level.time + 1500;
  3428. }
  3429. if (self->client->ps.forceHandExtend == HANDEXTEND_FORCE_HOLD)
  3430. {
  3431. self->client->ps.forceHandExtendTime = 0; //reset hand position
  3432. }
  3433. self->client->ps.activeForcePass = 0;
  3434. break;
  3435. case FP_RAGE:
  3436. self->client->ps.fd.forceRageRecoveryTime = level.time + 10000;
  3437. if (wasActive & (1 << FP_RAGE))
  3438. {
  3439. G_MuteSound(self->client->ps.fd.killSoundEntIndex[TRACK_CHANNEL_3-50], CHAN_VOICE);
  3440. }
  3441. break;
  3442. case FP_ABSORB:
  3443. if (wasActive & (1 << FP_ABSORB))
  3444. {
  3445. G_MuteSound(self->client->ps.fd.killSoundEntIndex[TRACK_CHANNEL_3-50], CHAN_VOICE);
  3446. }
  3447. break;
  3448. case FP_PROTECT:
  3449. if (wasActive & (1 << FP_PROTECT))
  3450. {
  3451. G_MuteSound(self->client->ps.fd.killSoundEntIndex[TRACK_CHANNEL_3-50], CHAN_VOICE);
  3452. }
  3453. break;
  3454. case FP_DRAIN:
  3455. if ( self->client->ps.fd.forcePowerLevel[FP_DRAIN] < FORCE_LEVEL_2 )
  3456. {//don't do it again for 3 seconds, minimum...
  3457. self->client->ps.fd.forcePowerDebounce[FP_DRAIN] = level.time + 3000;
  3458. }
  3459. else
  3460. {
  3461. self->client->ps.fd.forcePowerDebounce[FP_DRAIN] = level.time + 1500;
  3462. }
  3463. if (self->client->ps.forceHandExtend == HANDEXTEND_FORCE_HOLD)
  3464. {
  3465. self->client->ps.forceHandExtendTime = 0; //reset hand position
  3466. }
  3467. self->client->ps.activeForcePass = 0;
  3468. default:
  3469. break;
  3470. }
  3471. }
  3472. void DoGripAction(gentity_t *self, forcePowers_t forcePower)
  3473. {
  3474. gentity_t *gripEnt;
  3475. int gripLevel = 0;
  3476. trace_t tr;
  3477. vec3_t a;
  3478. vec3_t fwd, fwd_o, start_o, nvel;
  3479. self->client->dangerTime = level.time;
  3480. self->client->ps.eFlags &= ~EF_INVULNERABLE;
  3481. self->client->invulnerableTimer = 0;
  3482. gripEnt = &g_entities[self->client->ps.fd.forceGripEntityNum];
  3483. if (!gripEnt || !gripEnt->client || !gripEnt->inuse || gripEnt->health < 1 || !ForcePowerUsableOn(self, gripEnt, FP_GRIP))
  3484. {
  3485. WP_ForcePowerStop(self, forcePower);
  3486. self->client->ps.fd.forceGripEntityNum = ENTITYNUM_NONE;
  3487. if (gripEnt && gripEnt->client && gripEnt->inuse)
  3488. {
  3489. gripEnt->client->ps.forceGripChangeMovetype = PM_NORMAL;
  3490. }
  3491. return;
  3492. }
  3493. VectorSubtract(gripEnt->client->ps.origin, self->client->ps.origin, a);
  3494. trap_Trace(&tr, self->client->ps.origin, NULL, NULL, gripEnt->client->ps.origin, self->s.number, MASK_PLAYERSOLID);
  3495. gripLevel = WP_AbsorbConversion(gripEnt, gripEnt->client->ps.fd.forcePowerLevel[FP_ABSORB], self, FP_GRIP, self->client->ps.fd.forcePowerLevel[FP_GRIP], forcePowerNeeded[self->client->ps.fd.forcePowerLevel[FP_GRIP]][FP_GRIP]);
  3496. if (gripLevel == -1)
  3497. {
  3498. gripLevel = self->client->ps.fd.forcePowerLevel[FP_GRIP];
  3499. }
  3500. if (!gripLevel)
  3501. {
  3502. WP_ForcePowerStop(self, forcePower);
  3503. return;
  3504. }
  3505. if (VectorLength(a) > MAX_GRIP_DISTANCE)
  3506. {
  3507. WP_ForcePowerStop(self, forcePower);
  3508. return;
  3509. }
  3510. if ( !InFront( gripEnt->client->ps.origin, self->client->ps.origin, self->client->ps.viewangles, 0.9f ) &&
  3511. gripLevel < FORCE_LEVEL_3)
  3512. {
  3513. WP_ForcePowerStop(self, forcePower);
  3514. return;
  3515. }
  3516. if (tr.fraction != 1.0f &&
  3517. tr.entityNum != gripEnt->s.number /*&&
  3518. gripLevel < FORCE_LEVEL_3*/)
  3519. {
  3520. WP_ForcePowerStop(self, forcePower);
  3521. return;
  3522. }
  3523. if (self->client->ps.fd.forcePowerDebounce[FP_GRIP] < level.time)
  3524. { //2 damage per second while choking, resulting in 10 damage total (not including The Squeeze<tm>)
  3525. self->client->ps.fd.forcePowerDebounce[FP_GRIP] = level.time + 1000;
  3526. G_Damage(gripEnt, self, self, NULL, NULL, 2, DAMAGE_NO_ARMOR, MOD_FORCE_DARK);
  3527. }
  3528. Jetpack_Off(gripEnt); //make sure the guy being gripped has his jetpack off.
  3529. if (gripLevel == FORCE_LEVEL_1)
  3530. {
  3531. gripEnt->client->ps.fd.forceGripBeingGripped = level.time + 1000;
  3532. if ((level.time - gripEnt->client->ps.fd.forceGripStarted) > 5000)
  3533. {
  3534. WP_ForcePowerStop(self, forcePower);
  3535. }
  3536. return;
  3537. }
  3538. if (gripLevel == FORCE_LEVEL_2)
  3539. {
  3540. gripEnt->client->ps.fd.forceGripBeingGripped = level.time + 1000;
  3541. if (gripEnt->client->ps.forceGripMoveInterval < level.time)
  3542. {
  3543. gripEnt->client->ps.velocity[2] = 30;
  3544. gripEnt->client->ps.forceGripMoveInterval = level.time + 300; //only update velocity every 300ms, so as to avoid heavy bandwidth usage
  3545. }
  3546. gripEnt->client->ps.otherKiller = self->s.number;
  3547. gripEnt->client->ps.otherKillerTime = level.time + 5000;
  3548. gripEnt->client->ps.otherKillerDebounceTime = level.time + 100;
  3549. gripEnt->client->ps.forceGripChangeMovetype = PM_FLOAT;
  3550. if ((level.time - gripEnt->client->ps.fd.forceGripStarted) > 3000 && !self->client->ps.fd.forceGripDamageDebounceTime)
  3551. { //if we managed to lift him into the air for 2 seconds, give him a crack
  3552. self->client->ps.fd.forceGripDamageDebounceTime = 1;
  3553. G_Damage(gripEnt, self, self, NULL, NULL, 20, DAMAGE_NO_ARMOR, MOD_FORCE_DARK);
  3554. //Must play custom sounds on the actual entity. Don't use G_Sound (it creates a temp entity for the sound)
  3555. G_EntitySound( gripEnt, CHAN_VOICE, G_SoundIndex(va( "*choke%d.wav", Q_irand( 1, 3 ) )) );
  3556. gripEnt->client->ps.forceHandExtend = HANDEXTEND_CHOKE;
  3557. gripEnt->client->ps.forceHandExtendTime = level.time + 2000;
  3558. if (gripEnt->client->ps.fd.forcePowersActive & (1 << FP_GRIP))
  3559. { //choking, so don't let him keep gripping himself
  3560. WP_ForcePowerStop(gripEnt, FP_GRIP);
  3561. }
  3562. }
  3563. else if ((level.time - gripEnt->client->ps.fd.forceGripStarted) > 4000)
  3564. {
  3565. WP_ForcePowerStop(self, forcePower);
  3566. }
  3567. return;
  3568. }
  3569. if (gripLevel == FORCE_LEVEL_3)
  3570. {
  3571. gripEnt->client->ps.fd.forceGripBeingGripped = level.time + 1000;
  3572. gripEnt->client->ps.otherKiller = self->s.number;
  3573. gripEnt->client->ps.otherKillerTime = level.time + 5000;
  3574. gripEnt->client->ps.otherKillerDebounceTime = level.time + 100;
  3575. gripEnt->client->ps.forceGripChangeMovetype = PM_FLOAT;
  3576. if (gripEnt->client->ps.forceGripMoveInterval < level.time)
  3577. {
  3578. float nvLen = 0;
  3579. VectorCopy(gripEnt->client->ps.origin, start_o);
  3580. AngleVectors(self->client->ps.viewangles, fwd, NULL, NULL);
  3581. fwd_o[0] = self->client->ps.origin[0] + fwd[0]*128;
  3582. fwd_o[1] = self->client->ps.origin[1] + fwd[1]*128;
  3583. fwd_o[2] = self->client->ps.origin[2] + fwd[2]*128;
  3584. fwd_o[2] += 16;
  3585. VectorSubtract(fwd_o, start_o, nvel);
  3586. nvLen = VectorLength(nvel);
  3587. if (nvLen < 16)
  3588. { //within x units of desired spot
  3589. VectorNormalize(nvel);
  3590. gripEnt->client->ps.velocity[0] = nvel[0]*8;
  3591. gripEnt->client->ps.velocity[1] = nvel[1]*8;
  3592. gripEnt->client->ps.velocity[2] = nvel[2]*8;
  3593. }
  3594. else if (nvLen < 64)
  3595. {
  3596. VectorNormalize(nvel);
  3597. gripEnt->client->ps.velocity[0] = nvel[0]*128;
  3598. gripEnt->client->ps.velocity[1] = nvel[1]*128;
  3599. gripEnt->client->ps.velocity[2] = nvel[2]*128;
  3600. }
  3601. else if (nvLen < 128)
  3602. {
  3603. VectorNormalize(nvel);
  3604. gripEnt->client->ps.velocity[0] = nvel[0]*256;
  3605. gripEnt->client->ps.velocity[1] = nvel[1]*256;
  3606. gripEnt->client->ps.velocity[2] = nvel[2]*256;
  3607. }
  3608. else if (nvLen < 200)
  3609. {
  3610. VectorNormalize(nvel);
  3611. gripEnt->client->ps.velocity[0] = nvel[0]*512;
  3612. gripEnt->client->ps.velocity[1] = nvel[1]*512;
  3613. gripEnt->client->ps.velocity[2] = nvel[2]*512;
  3614. }
  3615. else
  3616. {
  3617. VectorNormalize(nvel);
  3618. gripEnt->client->ps.velocity[0] = nvel[0]*700;
  3619. gripEnt->client->ps.velocity[1] = nvel[1]*700;
  3620. gripEnt->client->ps.velocity[2] = nvel[2]*700;
  3621. }
  3622. gripEnt->client->ps.forceGripMoveInterval = level.time + 300; //only update velocity every 300ms, so as to avoid heavy bandwidth usage
  3623. }
  3624. if ((level.time - gripEnt->client->ps.fd.forceGripStarted) > 3000 && !self->client->ps.fd.forceGripDamageDebounceTime)
  3625. { //if we managed to lift him into the air for 2 seconds, give him a crack
  3626. self->client->ps.fd.forceGripDamageDebounceTime = 1;
  3627. G_Damage(gripEnt, self, self, NULL, NULL, 40, DAMAGE_NO_ARMOR, MOD_FORCE_DARK);
  3628. //Must play custom sounds on the actual entity. Don't use G_Sound (it creates a temp entity for the sound)
  3629. G_EntitySound( gripEnt, CHAN_VOICE, G_SoundIndex(va( "*choke%d.wav", Q_irand( 1, 3 ) )) );
  3630. gripEnt->client->ps.forceHandExtend = HANDEXTEND_CHOKE;
  3631. gripEnt->client->ps.forceHandExtendTime = level.time + 2000;
  3632. if (gripEnt->client->ps.fd.forcePowersActive & (1 << FP_GRIP))
  3633. { //choking, so don't let him keep gripping himself
  3634. WP_ForcePowerStop(gripEnt, FP_GRIP);
  3635. }
  3636. }
  3637. else if ((level.time - gripEnt->client->ps.fd.forceGripStarted) > 4000)
  3638. {
  3639. WP_ForcePowerStop(self, forcePower);
  3640. }
  3641. return;
  3642. }
  3643. }
  3644. qboolean G_IsMindTricked(forcedata_t *fd, int client)
  3645. {
  3646. int checkIn;
  3647. int trickIndex1, trickIndex2, trickIndex3, trickIndex4;
  3648. int sub = 0;
  3649. if (!fd)
  3650. {
  3651. return qfalse;
  3652. }
  3653. trickIndex1 = fd->forceMindtrickTargetIndex;
  3654. trickIndex2 = fd->forceMindtrickTargetIndex2;
  3655. trickIndex3 = fd->forceMindtrickTargetIndex3;
  3656. trickIndex4 = fd->forceMindtrickTargetIndex4;
  3657. if (client > 47)
  3658. {
  3659. checkIn = trickIndex4;
  3660. sub = 48;
  3661. }
  3662. else if (client > 31)
  3663. {
  3664. checkIn = trickIndex3;
  3665. sub = 32;
  3666. }
  3667. else if (client > 15)
  3668. {
  3669. checkIn = trickIndex2;
  3670. sub = 16;
  3671. }
  3672. else
  3673. {
  3674. checkIn = trickIndex1;
  3675. }
  3676. if (checkIn & (1 << (client-sub)))
  3677. {
  3678. return qtrue;
  3679. }
  3680. return qfalse;
  3681. }
  3682. static void RemoveTrickedEnt(forcedata_t *fd, int client)
  3683. {
  3684. if (!fd)
  3685. {
  3686. return;
  3687. }
  3688. if (client > 47)
  3689. {
  3690. fd->forceMindtrickTargetIndex4 &= ~(1 << (client-48));
  3691. }
  3692. else if (client > 31)
  3693. {
  3694. fd->forceMindtrickTargetIndex3 &= ~(1 << (client-32));
  3695. }
  3696. else if (client > 15)
  3697. {
  3698. fd->forceMindtrickTargetIndex2 &= ~(1 << (client-16));
  3699. }
  3700. else
  3701. {
  3702. fd->forceMindtrickTargetIndex &= ~(1 << client);
  3703. }
  3704. }
  3705. extern int g_LastFrameTime;
  3706. extern int g_TimeSinceLastFrame;
  3707. static void WP_UpdateMindtrickEnts(gentity_t *self)
  3708. {
  3709. int i = 0;
  3710. while (i < MAX_CLIENTS)
  3711. {
  3712. if (G_IsMindTricked(&self->client->ps.fd, i))
  3713. {
  3714. gentity_t *ent = &g_entities[i];
  3715. if ( !ent || !ent->client || !ent->inuse || ent->health < 1 ||
  3716. (ent->client->ps.fd.forcePowersActive & (1 << FP_SEE)) )
  3717. {
  3718. RemoveTrickedEnt(&self->client->ps.fd, i);
  3719. }
  3720. else if ((level.time - self->client->dangerTime) < g_TimeSinceLastFrame*4)
  3721. { //Untrick this entity if the tricker (self) fires while in his fov
  3722. if (trap_InPVS(ent->client->ps.origin, self->client->ps.origin) &&
  3723. OrgVisible(ent->client->ps.origin, self->client->ps.origin, ent->s.number))
  3724. {
  3725. RemoveTrickedEnt(&self->client->ps.fd, i);
  3726. }
  3727. }
  3728. else if (BG_HasYsalamiri(g_gametype.integer, &ent->client->ps))
  3729. {
  3730. RemoveTrickedEnt(&self->client->ps.fd, i);
  3731. }
  3732. }
  3733. i++;
  3734. }
  3735. if (!self->client->ps.fd.forceMindtrickTargetIndex &&
  3736. !self->client->ps.fd.forceMindtrickTargetIndex2 &&
  3737. !self->client->ps.fd.forceMindtrickTargetIndex3 &&
  3738. !self->client->ps.fd.forceMindtrickTargetIndex4)
  3739. { //everyone who we had tricked is no longer tricked, so stop the power
  3740. WP_ForcePowerStop(self, FP_TELEPATHY);
  3741. }
  3742. else if (self->client->ps.powerups[PW_REDFLAG] ||
  3743. self->client->ps.powerups[PW_BLUEFLAG])
  3744. {
  3745. WP_ForcePowerStop(self, FP_TELEPATHY);
  3746. }
  3747. }
  3748. static void WP_ForcePowerRun( gentity_t *self, forcePowers_t forcePower, usercmd_t *cmd )
  3749. {
  3750. extern usercmd_t ucmd;
  3751. switch( (int)forcePower )
  3752. {
  3753. case FP_HEAL:
  3754. if (self->client->ps.fd.forcePowerLevel[FP_HEAL] == FORCE_LEVEL_1)
  3755. {
  3756. if (self->client->ps.velocity[0] || self->client->ps.velocity[1] || self->client->ps.velocity[2])
  3757. {
  3758. WP_ForcePowerStop( self, forcePower );
  3759. break;
  3760. }
  3761. }
  3762. if (self->health < 1 || self->client->ps.stats[STAT_HEALTH] < 1)
  3763. {
  3764. WP_ForcePowerStop( self, forcePower );
  3765. break;
  3766. }
  3767. if (self->client->ps.fd.forceHealTime > level.time)
  3768. {
  3769. break;
  3770. }
  3771. if ( self->health > self->client->ps.stats[STAT_MAX_HEALTH])
  3772. { //rww - we might start out over max_health and we don't want force heal taking us down to 100 or whatever max_health is
  3773. WP_ForcePowerStop( self, forcePower );
  3774. break;
  3775. }
  3776. self->client->ps.fd.forceHealTime = level.time + 1000;
  3777. self->health++;
  3778. self->client->ps.fd.forceHealAmount++;
  3779. if ( self->health > self->client->ps.stats[STAT_MAX_HEALTH]) // Past max health
  3780. {
  3781. self->health = self->client->ps.stats[STAT_MAX_HEALTH];
  3782. WP_ForcePowerStop( self, forcePower );
  3783. }
  3784. if ( (self->client->ps.fd.forcePowerLevel[FP_HEAL] == FORCE_LEVEL_1 && self->client->ps.fd.forceHealAmount >= 25) ||
  3785. (self->client->ps.fd.forcePowerLevel[FP_HEAL] == FORCE_LEVEL_2 && self->client->ps.fd.forceHealAmount >= 33))
  3786. {
  3787. WP_ForcePowerStop( self, forcePower );
  3788. }
  3789. break;
  3790. case FP_SPEED:
  3791. //This is handled in PM_WalkMove and PM_StepSlideMove
  3792. if ( self->client->holdingObjectiveItem >= MAX_CLIENTS
  3793. && self->client->holdingObjectiveItem < ENTITYNUM_WORLD )
  3794. {
  3795. if ( g_entities[self->client->holdingObjectiveItem].genericValue15 )
  3796. {//disables force powers
  3797. WP_ForcePowerStop( self, forcePower );
  3798. }
  3799. }
  3800. /*
  3801. if ( self->client->ps.powerups[PW_REDFLAG]
  3802. || self->client->ps.powerups[PW_BLUEFLAG]
  3803. || self->client->ps.powerups[PW_NEUTRALFLAG] )
  3804. {//no force speed when carrying flag
  3805. WP_ForcePowerStop( self, forcePower );
  3806. }
  3807. */
  3808. break;
  3809. case FP_GRIP:
  3810. if (self->client->ps.forceHandExtend != HANDEXTEND_FORCE_HOLD)
  3811. {
  3812. WP_ForcePowerStop(self, FP_GRIP);
  3813. break;
  3814. }
  3815. if (self->client->ps.fd.forcePowerDebounce[FP_PULL] < level.time)
  3816. { //This is sort of not ideal. Using the debounce value reserved for pull for this because pull doesn't need it.
  3817. BG_ForcePowerDrain( &self->client->ps, forcePower, 1 );
  3818. self->client->ps.fd.forcePowerDebounce[FP_PULL] = level.time + 100;
  3819. }
  3820. if (self->client->ps.fd.forcePower < 1)
  3821. {
  3822. WP_ForcePowerStop(self, FP_GRIP);
  3823. break;
  3824. }
  3825. DoGripAction(self, forcePower);
  3826. break;
  3827. case FP_LEVITATION:
  3828. if ( self->client->ps.groundEntityNum != ENTITYNUM_NONE && !self->client->ps.fd.forceJumpZStart )
  3829. {//done with jump
  3830. WP_ForcePowerStop( self, forcePower );
  3831. }
  3832. break;
  3833. case FP_RAGE:
  3834. if (self->health < 1)
  3835. {
  3836. WP_ForcePowerStop(self, forcePower);
  3837. break;
  3838. }
  3839. if (self->client->ps.forceRageDrainTime < level.time)
  3840. {
  3841. int addTime = 400;
  3842. self->health -= 2;
  3843. if (self->client->ps.fd.forcePowerLevel[FP_RAGE] == FORCE_LEVEL_1)
  3844. {
  3845. addTime = 150;
  3846. }
  3847. else if (self->client->ps.fd.forcePowerLevel[FP_RAGE] == FORCE_LEVEL_2)
  3848. {
  3849. addTime = 300;
  3850. }
  3851. else if (self->client->ps.fd.forcePowerLevel[FP_RAGE] == FORCE_LEVEL_3)
  3852. {
  3853. addTime = 450;
  3854. }
  3855. self->client->ps.forceRageDrainTime = level.time + addTime;
  3856. }
  3857. if (self->health < 1)
  3858. {
  3859. self->health = 1;
  3860. WP_ForcePowerStop(self, forcePower);
  3861. }
  3862. self->client->ps.stats[STAT_HEALTH] = self->health;
  3863. break;
  3864. case FP_DRAIN:
  3865. if (self->client->ps.forceHandExtend != HANDEXTEND_FORCE_HOLD)
  3866. {
  3867. WP_ForcePowerStop(self, forcePower);
  3868. break;
  3869. }
  3870. if ( self->client->ps.fd.forcePowerLevel[FP_DRAIN] > FORCE_LEVEL_1 )
  3871. {//higher than level 1
  3872. if ( (cmd->buttons & BUTTON_FORCE_DRAIN) || ((cmd->buttons & BUTTON_FORCEPOWER) && self->client->ps.fd.forcePowerSelected == FP_DRAIN) )
  3873. {//holding it keeps it going
  3874. self->client->ps.fd.forcePowerDuration[FP_DRAIN] = level.time + 500;
  3875. }
  3876. }
  3877. // OVERRIDEFIXME
  3878. if ( !WP_ForcePowerAvailable( self, forcePower, 0 ) || self->client->ps.fd.forcePowerDuration[FP_DRAIN] < level.time ||
  3879. self->client->ps.fd.forcePower < 25)
  3880. {
  3881. WP_ForcePowerStop( self, forcePower );
  3882. }
  3883. else
  3884. {
  3885. ForceShootDrain( self );
  3886. }
  3887. break;
  3888. case FP_LIGHTNING:
  3889. if (self->client->ps.forceHandExtend != HANDEXTEND_FORCE_HOLD)
  3890. { //Animation for hand extend doesn't end with hand out, so we have to limit lightning intervals by animation intervals (once hand starts to go in in animation, lightning should stop)
  3891. WP_ForcePowerStop(self, forcePower);
  3892. break;
  3893. }
  3894. if ( self->client->ps.fd.forcePowerLevel[FP_LIGHTNING] > FORCE_LEVEL_1 )
  3895. {//higher than level 1
  3896. if ( (cmd->buttons & BUTTON_FORCE_LIGHTNING) || ((cmd->buttons & BUTTON_FORCEPOWER) && self->client->ps.fd.forcePowerSelected == FP_LIGHTNING) )
  3897. {//holding it keeps it going
  3898. self->client->ps.fd.forcePowerDuration[FP_LIGHTNING] = level.time + 500;
  3899. }
  3900. }
  3901. // OVERRIDEFIXME
  3902. if ( !WP_ForcePowerAvailable( self, forcePower, 0 ) || self->client->ps.fd.forcePowerDuration[FP_LIGHTNING] < level.time ||
  3903. self->client->ps.fd.forcePower < 25)
  3904. {
  3905. WP_ForcePowerStop( self, forcePower );
  3906. }
  3907. else
  3908. {
  3909. ForceShootLightning( self );
  3910. BG_ForcePowerDrain( &self->client->ps, forcePower, 0 );
  3911. }
  3912. break;
  3913. case FP_TELEPATHY:
  3914. if ( self->client->holdingObjectiveItem >= MAX_CLIENTS
  3915. && self->client->holdingObjectiveItem < ENTITYNUM_WORLD
  3916. && g_entities[self->client->holdingObjectiveItem].genericValue15 )
  3917. { //if force hindered can't mindtrick whilst carrying a siege item
  3918. WP_ForcePowerStop( self, FP_TELEPATHY );
  3919. }
  3920. else
  3921. {
  3922. WP_UpdateMindtrickEnts(self);
  3923. }
  3924. break;
  3925. case FP_SABER_OFFENSE:
  3926. break;
  3927. case FP_SABER_DEFENSE:
  3928. break;
  3929. case FP_SABERTHROW:
  3930. break;
  3931. case FP_PROTECT:
  3932. if (self->client->ps.fd.forcePowerDebounce[forcePower] < level.time)
  3933. {
  3934. BG_ForcePowerDrain( &self->client->ps, forcePower, 1 );
  3935. if (self->client->ps.fd.forcePower < 1)
  3936. {
  3937. WP_ForcePowerStop(self, forcePower);
  3938. }
  3939. self->client->ps.fd.forcePowerDebounce[forcePower] = level.time + 300;
  3940. }
  3941. break;
  3942. case FP_ABSORB:
  3943. if (self->client->ps.fd.forcePowerDebounce[forcePower] < level.time)
  3944. {
  3945. BG_ForcePowerDrain( &self->client->ps, forcePower, 1 );
  3946. if (self->client->ps.fd.forcePower < 1)
  3947. {
  3948. WP_ForcePowerStop(self, forcePower);
  3949. }
  3950. self->client->ps.fd.forcePowerDebounce[forcePower] = level.time + 600;
  3951. }
  3952. break;
  3953. default:
  3954. break;
  3955. }
  3956. }
  3957. int WP_DoSpecificPower( gentity_t *self, usercmd_t *ucmd, forcePowers_t forcepower)
  3958. {
  3959. int powerSucceeded;
  3960. powerSucceeded = 1;
  3961. // OVERRIDEFIXME
  3962. if ( !WP_ForcePowerAvailable( self, forcepower, 0 ) )
  3963. {
  3964. return 0;
  3965. }
  3966. switch(forcepower)
  3967. {
  3968. case FP_HEAL:
  3969. powerSucceeded = 0; //always 0 for nonhold powers
  3970. if (self->client->ps.fd.forceButtonNeedRelease)
  3971. { //need to release before we can use nonhold powers again
  3972. break;
  3973. }
  3974. ForceHeal(self);
  3975. self->client->ps.fd.forceButtonNeedRelease = 1;
  3976. break;
  3977. case FP_LEVITATION:
  3978. //if leave the ground by some other means, cancel the force jump so we don't suddenly jump when we land.
  3979. if ( self->client->ps.groundEntityNum == ENTITYNUM_NONE )
  3980. {
  3981. self->client->ps.fd.forceJumpCharge = 0;
  3982. G_MuteSound( self->client->ps.fd.killSoundEntIndex[TRACK_CHANNEL_1-50], CHAN_VOICE );
  3983. //This only happens if the groundEntityNum == ENTITYNUM_NONE when the button is actually released
  3984. }
  3985. else
  3986. {//still on ground, so jump
  3987. ForceJump( self, ucmd );
  3988. }
  3989. break;
  3990. case FP_SPEED:
  3991. powerSucceeded = 0; //always 0 for nonhold powers
  3992. if (self->client->ps.fd.forceButtonNeedRelease)
  3993. { //need to release before we can use nonhold powers again
  3994. break;
  3995. }
  3996. ForceSpeed(self, 0);
  3997. self->client->ps.fd.forceButtonNeedRelease = 1;
  3998. break;
  3999. case FP_GRIP:
  4000. if (self->client->ps.fd.forceGripEntityNum == ENTITYNUM_NONE)
  4001. {
  4002. ForceGrip( self );
  4003. }
  4004. if (self->client->ps.fd.forceGripEntityNum != ENTITYNUM_NONE)
  4005. {
  4006. if (!(self->client->ps.fd.forcePowersActive & (1 << FP_GRIP)))
  4007. {
  4008. WP_ForcePowerStart( self, FP_GRIP, 0 );
  4009. BG_ForcePowerDrain( &self->client->ps, FP_GRIP, GRIP_DRAIN_AMOUNT );
  4010. }
  4011. }
  4012. else
  4013. {
  4014. powerSucceeded = 0;
  4015. }
  4016. break;
  4017. case FP_LIGHTNING:
  4018. ForceLightning(self);
  4019. break;
  4020. case FP_PUSH:
  4021. powerSucceeded = 0; //always 0 for nonhold powers
  4022. if (self->client->ps.fd.forceButtonNeedRelease && !(self->r.svFlags & SVF_BOT))
  4023. { //need to release before we can use nonhold powers again
  4024. break;
  4025. }
  4026. ForceThrow(self, qfalse);
  4027. self->client->ps.fd.forceButtonNeedRelease = 1;
  4028. break;
  4029. case FP_PULL:
  4030. powerSucceeded = 0; //always 0 for nonhold powers
  4031. if (self->client->ps.fd.forceButtonNeedRelease)
  4032. { //need to release before we can use nonhold powers again
  4033. break;
  4034. }
  4035. ForceThrow(self, qtrue);
  4036. self->client->ps.fd.forceButtonNeedRelease = 1;
  4037. break;
  4038. case FP_TELEPATHY:
  4039. powerSucceeded = 0; //always 0 for nonhold powers
  4040. if (self->client->ps.fd.forceButtonNeedRelease)
  4041. { //need to release before we can use nonhold powers again
  4042. break;
  4043. }
  4044. ForceTelepathy(self);
  4045. self->client->ps.fd.forceButtonNeedRelease = 1;
  4046. break;
  4047. case FP_RAGE:
  4048. powerSucceeded = 0; //always 0 for nonhold powers
  4049. if (self->client->ps.fd.forceButtonNeedRelease)
  4050. { //need to release before we can use nonhold powers again
  4051. break;
  4052. }
  4053. ForceRage(self);
  4054. self->client->ps.fd.forceButtonNeedRelease = 1;
  4055. break;
  4056. case FP_PROTECT:
  4057. powerSucceeded = 0; //always 0 for nonhold powers
  4058. if (self->client->ps.fd.forceButtonNeedRelease)
  4059. { //need to release before we can use nonhold powers again
  4060. break;
  4061. }
  4062. ForceProtect(self);
  4063. self->client->ps.fd.forceButtonNeedRelease = 1;
  4064. break;
  4065. case FP_ABSORB:
  4066. powerSucceeded = 0; //always 0 for nonhold powers
  4067. if (self->client->ps.fd.forceButtonNeedRelease)
  4068. { //need to release before we can use nonhold powers again
  4069. break;
  4070. }
  4071. ForceAbsorb(self);
  4072. self->client->ps.fd.forceButtonNeedRelease = 1;
  4073. break;
  4074. case FP_TEAM_HEAL:
  4075. powerSucceeded = 0; //always 0 for nonhold powers
  4076. if (self->client->ps.fd.forceButtonNeedRelease)
  4077. { //need to release before we can use nonhold powers again
  4078. break;
  4079. }
  4080. ForceTeamHeal(self);
  4081. self->client->ps.fd.forceButtonNeedRelease = 1;
  4082. break;
  4083. case FP_TEAM_FORCE:
  4084. powerSucceeded = 0; //always 0 for nonhold powers
  4085. if (self->client->ps.fd.forceButtonNeedRelease)
  4086. { //need to release before we can use nonhold powers again
  4087. break;
  4088. }
  4089. ForceTeamForceReplenish(self);
  4090. self->client->ps.fd.forceButtonNeedRelease = 1;
  4091. break;
  4092. case FP_DRAIN:
  4093. ForceDrain(self);
  4094. break;
  4095. case FP_SEE:
  4096. powerSucceeded = 0; //always 0 for nonhold powers
  4097. if (self->client->ps.fd.forceButtonNeedRelease)
  4098. { //need to release before we can use nonhold powers again
  4099. break;
  4100. }
  4101. ForceSeeing(self);
  4102. self->client->ps.fd.forceButtonNeedRelease = 1;
  4103. break;
  4104. case FP_SABER_OFFENSE:
  4105. break;
  4106. case FP_SABER_DEFENSE:
  4107. break;
  4108. case FP_SABERTHROW:
  4109. break;
  4110. default:
  4111. break;
  4112. }
  4113. return powerSucceeded;
  4114. }
  4115. void FindGenericEnemyIndex(gentity_t *self)
  4116. { //Find another client that would be considered a threat.
  4117. int i = 0;
  4118. float tlen;
  4119. gentity_t *ent;
  4120. gentity_t *besten = NULL;
  4121. float blen = 99999999;
  4122. vec3_t a;
  4123. while (i < MAX_CLIENTS)
  4124. {
  4125. ent = &g_entities[i];
  4126. if (ent && ent->client && ent->s.number != self->s.number && ent->health > 0 && !OnSameTeam(self, ent) && ent->client->ps.pm_type != PM_INTERMISSION && ent->client->ps.pm_type != PM_SPECTATOR)
  4127. {
  4128. VectorSubtract(ent->client->ps.origin, self->client->ps.origin, a);
  4129. tlen = VectorLength(a);
  4130. if (tlen < blen &&
  4131. InFront(ent->client->ps.origin, self->client->ps.origin, self->client->ps.viewangles, 0.8f ) &&
  4132. OrgVisible(self->client->ps.origin, ent->client->ps.origin, self->s.number))
  4133. {
  4134. blen = tlen;
  4135. besten = ent;
  4136. }
  4137. }
  4138. i++;
  4139. }
  4140. if (!besten)
  4141. {
  4142. return;
  4143. }
  4144. self->client->ps.genericEnemyIndex = besten->s.number;
  4145. }
  4146. void SeekerDroneUpdate(gentity_t *self)
  4147. {
  4148. vec3_t org, elevated, dir, a, endir;
  4149. gentity_t *en;
  4150. float angle;
  4151. float prefig = 0;
  4152. trace_t tr;
  4153. if (!(self->client->ps.eFlags & EF_SEEKERDRONE))
  4154. {
  4155. self->client->ps.genericEnemyIndex = -1;
  4156. return;
  4157. }
  4158. if (self->health < 1)
  4159. {
  4160. VectorCopy(self->client->ps.origin, elevated);
  4161. elevated[2] += 40;
  4162. angle = ((level.time / 12) & 255) * (M_PI * 2) / 255; //magical numbers make magic happen
  4163. dir[0] = cos(angle) * 20;
  4164. dir[1] = sin(angle) * 20;
  4165. dir[2] = cos(angle) * 5;
  4166. VectorAdd(elevated, dir, org);
  4167. a[ROLL] = 0;
  4168. a[YAW] = 0;
  4169. a[PITCH] = 1;
  4170. G_PlayEffect(EFFECT_SPARK_EXPLOSION, org, a);
  4171. self->client->ps.eFlags -= EF_SEEKERDRONE;
  4172. self->client->ps.genericEnemyIndex = -1;
  4173. return;
  4174. }
  4175. if (self->client->ps.droneExistTime >= level.time &&
  4176. self->client->ps.droneExistTime < (level.time+5000))
  4177. {
  4178. self->client->ps.genericEnemyIndex = 1024+self->client->ps.droneExistTime;
  4179. if (self->client->ps.droneFireTime < level.time)
  4180. {
  4181. G_Sound( self, CHAN_BODY, G_SoundIndex("sound/weapons/laser_trap/warning.wav") );
  4182. self->client->ps.droneFireTime = level.time + 100;
  4183. }
  4184. return;
  4185. }
  4186. else if (self->client->ps.droneExistTime < level.time)
  4187. {
  4188. VectorCopy(self->client->ps.origin, elevated);
  4189. elevated[2] += 40;
  4190. prefig = (self->client->ps.droneExistTime-level.time)/80;
  4191. if (prefig > 55)
  4192. {
  4193. prefig = 55;
  4194. }
  4195. else if (prefig < 1)
  4196. {
  4197. prefig = 1;
  4198. }
  4199. elevated[2] -= 55-prefig;
  4200. angle = ((level.time / 12) & 255) * (M_PI * 2) / 255; //magical numbers make magic happen
  4201. dir[0] = cos(angle) * 20;
  4202. dir[1] = sin(angle) * 20;
  4203. dir[2] = cos(angle) * 5;
  4204. VectorAdd(elevated, dir, org);
  4205. a[ROLL] = 0;
  4206. a[YAW] = 0;
  4207. a[PITCH] = 1;
  4208. G_PlayEffect(EFFECT_SPARK_EXPLOSION, org, a);
  4209. self->client->ps.eFlags -= EF_SEEKERDRONE;
  4210. self->client->ps.genericEnemyIndex = -1;
  4211. return;
  4212. }
  4213. if (self->client->ps.genericEnemyIndex == -1)
  4214. {
  4215. self->client->ps.genericEnemyIndex = ENTITYNUM_NONE;
  4216. }
  4217. if (self->client->ps.genericEnemyIndex != ENTITYNUM_NONE && self->client->ps.genericEnemyIndex != -1)
  4218. {
  4219. en = &g_entities[self->client->ps.genericEnemyIndex];
  4220. if (!en || !en->client)
  4221. {
  4222. self->client->ps.genericEnemyIndex = ENTITYNUM_NONE;
  4223. }
  4224. else if (en->s.number == self->s.number)
  4225. {
  4226. self->client->ps.genericEnemyIndex = ENTITYNUM_NONE;
  4227. }
  4228. else if (en->health < 1)
  4229. {
  4230. self->client->ps.genericEnemyIndex = ENTITYNUM_NONE;
  4231. }
  4232. else if (OnSameTeam(self, en))
  4233. {
  4234. self->client->ps.genericEnemyIndex = ENTITYNUM_NONE;
  4235. }
  4236. else
  4237. {
  4238. if (!InFront(en->client->ps.origin, self->client->ps.origin, self->client->ps.viewangles, 0.8f ))
  4239. {
  4240. self->client->ps.genericEnemyIndex = ENTITYNUM_NONE;
  4241. }
  4242. else if (!OrgVisible(self->client->ps.origin, en->client->ps.origin, self->s.number))
  4243. {
  4244. self->client->ps.genericEnemyIndex = ENTITYNUM_NONE;
  4245. }
  4246. }
  4247. }
  4248. if (self->client->ps.genericEnemyIndex == ENTITYNUM_NONE || self->client->ps.genericEnemyIndex == -1)
  4249. {
  4250. FindGenericEnemyIndex(self);
  4251. }
  4252. if (self->client->ps.genericEnemyIndex != ENTITYNUM_NONE && self->client->ps.genericEnemyIndex != -1)
  4253. {
  4254. en = &g_entities[self->client->ps.genericEnemyIndex];
  4255. VectorCopy(self->client->ps.origin, elevated);
  4256. elevated[2] += 40;
  4257. angle = ((level.time / 12) & 255) * (M_PI * 2) / 255; //magical numbers make magic happen
  4258. dir[0] = cos(angle) * 20;
  4259. dir[1] = sin(angle) * 20;
  4260. dir[2] = cos(angle) * 5;
  4261. VectorAdd(elevated, dir, org);
  4262. //org is now where the thing should be client-side because it uses the same time-based offset
  4263. if (self->client->ps.droneFireTime < level.time)
  4264. {
  4265. trap_Trace(&tr, org, NULL, NULL, en->client->ps.origin, -1, MASK_SOLID);
  4266. if (tr.fraction == 1 && !tr.startsolid && !tr.allsolid)
  4267. {
  4268. VectorSubtract(en->client->ps.origin, org, endir);
  4269. VectorNormalize(endir);
  4270. WP_FireGenericBlasterMissile(self, org, endir, 0, 15, 2000, MOD_BLASTER);
  4271. G_SoundAtLoc( org, CHAN_WEAPON, G_SoundIndex("sound/weapons/bryar/fire.wav") );
  4272. self->client->ps.droneFireTime = level.time + Q_irand(400, 700);
  4273. }
  4274. }
  4275. }
  4276. }
  4277. void HolocronUpdate(gentity_t *self)
  4278. { //keep holocron status updated in holocron mode
  4279. int i = 0;
  4280. int noHRank = 0;
  4281. if (noHRank < FORCE_LEVEL_0)
  4282. {
  4283. noHRank = FORCE_LEVEL_0;
  4284. }
  4285. if (noHRank > FORCE_LEVEL_3)
  4286. {
  4287. noHRank = FORCE_LEVEL_3;
  4288. }
  4289. trap_Cvar_Update(&g_MaxHolocronCarry);
  4290. while (i < NUM_FORCE_POWERS)
  4291. {
  4292. if (self->client->ps.holocronsCarried[i])
  4293. { //carrying it, make sure we have the power
  4294. self->client->ps.holocronBits |= (1 << i);
  4295. self->client->ps.fd.forcePowersKnown |= (1 << i);
  4296. self->client->ps.fd.forcePowerLevel[i] = FORCE_LEVEL_3;
  4297. }
  4298. else
  4299. { //otherwise, make sure the power is cleared from us
  4300. self->client->ps.fd.forcePowerLevel[i] = 0;
  4301. if (self->client->ps.holocronBits & (1 << i))
  4302. {
  4303. self->client->ps.holocronBits -= (1 << i);
  4304. }
  4305. if ((self->client->ps.fd.forcePowersKnown & (1 << i)) && i != FP_LEVITATION && i != FP_SABER_OFFENSE)
  4306. {
  4307. self->client->ps.fd.forcePowersKnown -= (1 << i);
  4308. }
  4309. if ((self->client->ps.fd.forcePowersActive & (1 << i)) && i != FP_LEVITATION && i != FP_SABER_OFFENSE)
  4310. {
  4311. WP_ForcePowerStop(self, i);
  4312. }
  4313. if (i == FP_LEVITATION)
  4314. {
  4315. if (noHRank >= FORCE_LEVEL_1)
  4316. {
  4317. self->client->ps.fd.forcePowerLevel[i] = noHRank;
  4318. }
  4319. else
  4320. {
  4321. self->client->ps.fd.forcePowerLevel[i] = FORCE_LEVEL_1;
  4322. }
  4323. }
  4324. else if (i == FP_SABER_OFFENSE)
  4325. {
  4326. self->client->ps.fd.forcePowersKnown |= (1 << i);
  4327. if (noHRank >= FORCE_LEVEL_1)
  4328. {
  4329. self->client->ps.fd.forcePowerLevel[i] = noHRank;
  4330. }
  4331. else
  4332. {
  4333. self->client->ps.fd.forcePowerLevel[i] = FORCE_LEVEL_1;
  4334. }
  4335. }
  4336. else
  4337. {
  4338. self->client->ps.fd.forcePowerLevel[i] = FORCE_LEVEL_0;
  4339. }
  4340. }
  4341. i++;
  4342. }
  4343. if (HasSetSaberOnly())
  4344. { //if saberonly, we get these powers no matter what (still need the holocrons for level 3)
  4345. if (self->client->ps.fd.forcePowerLevel[FP_SABER_OFFENSE] < FORCE_LEVEL_1)
  4346. {
  4347. self->client->ps.fd.forcePowerLevel[FP_SABER_OFFENSE] = FORCE_LEVEL_1;
  4348. }
  4349. if (self->client->ps.fd.forcePowerLevel[FP_SABER_DEFENSE] < FORCE_LEVEL_1)
  4350. {
  4351. self->client->ps.fd.forcePowerLevel[FP_SABER_DEFENSE] = FORCE_LEVEL_1;
  4352. }
  4353. }
  4354. }
  4355. void JediMasterUpdate(gentity_t *self)
  4356. { //keep jedi master status updated for JM gametype
  4357. int i = 0;
  4358. trap_Cvar_Update(&g_MaxHolocronCarry);
  4359. while (i < NUM_FORCE_POWERS)
  4360. {
  4361. if (self->client->ps.isJediMaster)
  4362. {
  4363. self->client->ps.fd.forcePowersKnown |= (1 << i);
  4364. self->client->ps.fd.forcePowerLevel[i] = FORCE_LEVEL_3;
  4365. if (i == FP_TEAM_HEAL || i == FP_TEAM_FORCE ||
  4366. i == FP_DRAIN || i == FP_ABSORB)
  4367. { //team powers are useless in JM, absorb is too because no one else has powers to absorb. Drain is just
  4368. //relatively useless in comparison, because its main intent is not to heal, but rather to cripple others
  4369. //by draining their force at the same time. And no one needs force in JM except the JM himself.
  4370. self->client->ps.fd.forcePowersKnown &= ~(1 << i);
  4371. self->client->ps.fd.forcePowerLevel[i] = 0;
  4372. }
  4373. if (i == FP_TELEPATHY)
  4374. { //this decision was made because level 3 mindtrick allows the JM to just hide too much, and no one else has force
  4375. //sight to counteract it. Since the JM himself is the focus of gameplay in this mode, having him hidden for large
  4376. //durations is indeed a bad thing.
  4377. self->client->ps.fd.forcePowerLevel[i] = FORCE_LEVEL_2;
  4378. }
  4379. }
  4380. else
  4381. {
  4382. if ((self->client->ps.fd.forcePowersKnown & (1 << i)) && i != FP_LEVITATION)
  4383. {
  4384. self->client->ps.fd.forcePowersKnown -= (1 << i);
  4385. }
  4386. if ((self->client->ps.fd.forcePowersActive & (1 << i)) && i != FP_LEVITATION)
  4387. {
  4388. WP_ForcePowerStop(self, i);
  4389. }
  4390. if (i == FP_LEVITATION)
  4391. {
  4392. self->client->ps.fd.forcePowerLevel[i] = FORCE_LEVEL_1;
  4393. }
  4394. else
  4395. {
  4396. self->client->ps.fd.forcePowerLevel[i] = FORCE_LEVEL_0;
  4397. }
  4398. }
  4399. i++;
  4400. }
  4401. }
  4402. qboolean WP_HasForcePowers( const playerState_t *ps )
  4403. {
  4404. int i;
  4405. if ( ps )
  4406. {
  4407. for ( i = 0; i < NUM_FORCE_POWERS; i++ )
  4408. {
  4409. if ( i == FP_LEVITATION )
  4410. {
  4411. if ( ps->fd.forcePowerLevel[i] > FORCE_LEVEL_1 )
  4412. {
  4413. return qtrue;
  4414. }
  4415. }
  4416. else if ( ps->fd.forcePowerLevel[i] > FORCE_LEVEL_0 )
  4417. {
  4418. return qtrue;
  4419. }
  4420. }
  4421. }
  4422. return qfalse;
  4423. }
  4424. //try a special roll getup move
  4425. qboolean G_SpecialRollGetup(gentity_t *self)
  4426. { //fixme: currently no knockdown will actually land you on your front... so froll's are pretty useless at the moment.
  4427. qboolean rolled = qfalse;
  4428. /*
  4429. if (self->client->ps.weapon != WP_SABER &&
  4430. self->client->ps.weapon != WP_MELEE)
  4431. { //can't do acrobatics without saber selected
  4432. return qfalse;
  4433. }
  4434. */
  4435. if (/*!self->client->pers.cmd.upmove &&*/
  4436. self->client->pers.cmd.rightmove > 0 &&
  4437. !self->client->pers.cmd.forwardmove)
  4438. {
  4439. G_SetAnim(self, &self->client->pers.cmd, SETANIM_BOTH, BOTH_GETUP_BROLL_R, SETANIM_FLAG_OVERRIDE | SETANIM_FLAG_HOLD, 0);
  4440. rolled = qtrue;
  4441. }
  4442. else if (/*!self->client->pers.cmd.upmove &&*/
  4443. self->client->pers.cmd.rightmove < 0 &&
  4444. !self->client->pers.cmd.forwardmove)
  4445. {
  4446. G_SetAnim(self, &self->client->pers.cmd, SETANIM_BOTH, BOTH_GETUP_BROLL_L, SETANIM_FLAG_OVERRIDE | SETANIM_FLAG_HOLD, 0);
  4447. rolled = qtrue;
  4448. }
  4449. else if (/*self->client->pers.cmd.upmove > 0 &&*/
  4450. !self->client->pers.cmd.rightmove &&
  4451. self->client->pers.cmd.forwardmove > 0)
  4452. {
  4453. G_SetAnim(self, &self->client->pers.cmd, SETANIM_BOTH, BOTH_GETUP_BROLL_F, SETANIM_FLAG_OVERRIDE | SETANIM_FLAG_HOLD, 0);
  4454. rolled = qtrue;
  4455. }
  4456. else if (/*self->client->pers.cmd.upmove > 0 &&*/
  4457. !self->client->pers.cmd.rightmove &&
  4458. self->client->pers.cmd.forwardmove < 0)
  4459. {
  4460. G_SetAnim(self, &self->client->pers.cmd, SETANIM_BOTH, BOTH_GETUP_BROLL_B, SETANIM_FLAG_OVERRIDE | SETANIM_FLAG_HOLD, 0);
  4461. rolled = qtrue;
  4462. }
  4463. else if (self->client->pers.cmd.upmove)
  4464. {
  4465. G_PreDefSound(self->client->ps.origin, PDSOUND_FORCEJUMP);
  4466. self->client->ps.forceDodgeAnim = 2;
  4467. self->client->ps.forceHandExtendTime = level.time + 500;
  4468. //self->client->ps.velocity[2] = 300;
  4469. }
  4470. if (rolled)
  4471. {
  4472. G_EntitySound( self, CHAN_VOICE, G_SoundIndex("*jump1.wav") );
  4473. }
  4474. return rolled;
  4475. }
  4476. void WP_ForcePowersUpdate( gentity_t *self, usercmd_t *ucmd )
  4477. {
  4478. qboolean usingForce = qfalse;
  4479. int i, holo, holoregen;
  4480. int prepower = 0;
  4481. //see if any force powers are running
  4482. if ( !self )
  4483. {
  4484. return;
  4485. }
  4486. if ( !self->client )
  4487. {
  4488. return;
  4489. }
  4490. if (self->client->ps.pm_flags & PMF_FOLLOW)
  4491. { //not a "real" game client, it's a spectator following someone
  4492. return;
  4493. }
  4494. if (self->client->sess.sessionTeam == TEAM_SPECTATOR)
  4495. {
  4496. return;
  4497. }
  4498. /*
  4499. if (self->client->ps.fd.saberAnimLevel > self->client->ps.fd.forcePowerLevel[FP_SABER_OFFENSE])
  4500. {
  4501. self->client->ps.fd.saberAnimLevel = self->client->ps.fd.forcePowerLevel[FP_SABER_OFFENSE];
  4502. }
  4503. else if (!self->client->ps.fd.saberAnimLevel)
  4504. {
  4505. self->client->ps.fd.saberAnimLevel = FORCE_LEVEL_1;
  4506. }
  4507. */
  4508. //The stance in relation to power level is no longer applicable with the crazy new akimbo/staff stances.
  4509. if (!self->client->ps.fd.saberAnimLevel)
  4510. {
  4511. self->client->ps.fd.saberAnimLevel = FORCE_LEVEL_1;
  4512. }
  4513. if (g_gametype.integer != GT_SIEGE)
  4514. {
  4515. if (!(self->client->ps.fd.forcePowersKnown & (1 << FP_LEVITATION)))
  4516. {
  4517. self->client->ps.fd.forcePowersKnown |= (1 << FP_LEVITATION);
  4518. }
  4519. if (self->client->ps.fd.forcePowerLevel[FP_LEVITATION] < FORCE_LEVEL_1)
  4520. {
  4521. self->client->ps.fd.forcePowerLevel[FP_LEVITATION] = FORCE_LEVEL_1;
  4522. }
  4523. }
  4524. if (self->client->ps.fd.forcePowerSelected < 0)
  4525. { //bad
  4526. self->client->ps.fd.forcePowerSelected = 0;
  4527. }
  4528. if ( ((self->client->sess.selectedFP != self->client->ps.fd.forcePowerSelected) ||
  4529. (self->client->sess.saberLevel != self->client->ps.fd.saberAnimLevel)) &&
  4530. !(self->r.svFlags & SVF_BOT) )
  4531. {
  4532. if (self->client->sess.updateUITime < level.time)
  4533. { //a bit hackish, but we don't want the client to flood with userinfo updates if they rapidly cycle
  4534. //through their force powers or saber attack levels
  4535. self->client->sess.selectedFP = self->client->ps.fd.forcePowerSelected;
  4536. self->client->sess.saberLevel = self->client->ps.fd.saberAnimLevel;
  4537. }
  4538. }
  4539. if (!g_LastFrameTime)
  4540. {
  4541. g_LastFrameTime = level.time;
  4542. }
  4543. if (self->client->ps.forceHandExtend == HANDEXTEND_KNOCKDOWN)
  4544. {
  4545. self->client->ps.zoomFov = 0;
  4546. self->client->ps.zoomMode = 0;
  4547. self->client->ps.zoomLocked = qfalse;
  4548. self->client->ps.zoomTime = 0;
  4549. }
  4550. if (self->client->ps.forceHandExtend == HANDEXTEND_KNOCKDOWN &&
  4551. self->client->ps.forceHandExtendTime >= level.time)
  4552. {
  4553. self->client->ps.saberMove = 0;
  4554. self->client->ps.saberBlocking = 0;
  4555. self->client->ps.saberBlocked = 0;
  4556. self->client->ps.weaponTime = 0;
  4557. self->client->ps.weaponstate = WEAPON_READY;
  4558. }
  4559. else if (self->client->ps.forceHandExtend != HANDEXTEND_NONE &&
  4560. self->client->ps.forceHandExtendTime < level.time)
  4561. {
  4562. if (self->client->ps.forceHandExtend == HANDEXTEND_KNOCKDOWN &&
  4563. !self->client->ps.forceDodgeAnim)
  4564. {
  4565. if (self->health < 1 || (self->client->ps.eFlags & EF_DEAD))
  4566. {
  4567. self->client->ps.forceHandExtend = HANDEXTEND_NONE;
  4568. }
  4569. else if (G_SpecialRollGetup(self))
  4570. {
  4571. self->client->ps.forceHandExtend = HANDEXTEND_NONE;
  4572. }
  4573. else
  4574. { //hmm.. ok.. no more getting up on your own, you've gotta push something, unless..
  4575. if ((level.time-self->client->ps.forceHandExtendTime) > 4000)
  4576. { //4 seconds elapsed, I guess they're too dumb to push something to get up!
  4577. if (self->client->pers.cmd.upmove &&
  4578. self->client->ps.fd.forcePowerLevel[FP_LEVITATION] > FORCE_LEVEL_1)
  4579. { //force getup
  4580. G_PreDefSound(self->client->ps.origin, PDSOUND_FORCEJUMP);
  4581. self->client->ps.forceDodgeAnim = 2;
  4582. self->client->ps.forceHandExtendTime = level.time + 500;
  4583. //self->client->ps.velocity[2] = 400;
  4584. }
  4585. else if (self->client->ps.quickerGetup)
  4586. {
  4587. G_EntitySound( self, CHAN_VOICE, G_SoundIndex("*jump1.wav") );
  4588. self->client->ps.forceDodgeAnim = 3;
  4589. self->client->ps.forceHandExtendTime = level.time + 500;
  4590. self->client->ps.velocity[2] = 300;
  4591. }
  4592. else
  4593. {
  4594. self->client->ps.forceDodgeAnim = 1;
  4595. self->client->ps.forceHandExtendTime = level.time + 1000;
  4596. }
  4597. }
  4598. }
  4599. self->client->ps.quickerGetup = qfalse;
  4600. }
  4601. else if (self->client->ps.forceHandExtend == HANDEXTEND_POSTTHROWN)
  4602. {
  4603. if (self->health < 1 || (self->client->ps.eFlags & EF_DEAD))
  4604. {
  4605. self->client->ps.forceHandExtend = HANDEXTEND_NONE;
  4606. }
  4607. else if (self->client->ps.groundEntityNum != ENTITYNUM_NONE && !self->client->ps.forceDodgeAnim)
  4608. {
  4609. self->client->ps.forceDodgeAnim = 1;
  4610. self->client->ps.forceHandExtendTime = level.time + 1000;
  4611. G_EntitySound( self, CHAN_VOICE, G_SoundIndex("*jump1.wav") );
  4612. self->client->ps.velocity[2] = 100;
  4613. }
  4614. else if (!self->client->ps.forceDodgeAnim)
  4615. {
  4616. self->client->ps.forceHandExtendTime = level.time + 100;
  4617. }
  4618. else
  4619. {
  4620. self->client->ps.forceHandExtend = HANDEXTEND_WEAPONREADY;
  4621. }
  4622. }
  4623. else
  4624. {
  4625. self->client->ps.forceHandExtend = HANDEXTEND_WEAPONREADY;
  4626. }
  4627. }
  4628. if (g_gametype.integer == GT_HOLOCRON)
  4629. {
  4630. HolocronUpdate(self);
  4631. }
  4632. if (g_gametype.integer == GT_JEDIMASTER)
  4633. {
  4634. JediMasterUpdate(self);
  4635. }
  4636. SeekerDroneUpdate(self);
  4637. if (self->client->ps.powerups[PW_FORCE_BOON])
  4638. {
  4639. prepower = self->client->ps.fd.forcePower;
  4640. }
  4641. if (self && self->client && (BG_HasYsalamiri(g_gametype.integer, &self->client->ps) ||
  4642. self->client->ps.fd.forceDeactivateAll || self->client->tempSpectate >= level.time))
  4643. { //has ysalamiri.. or we want to forcefully stop all his active powers
  4644. i = 0;
  4645. while (i < NUM_FORCE_POWERS)
  4646. {
  4647. if ((self->client->ps.fd.forcePowersActive & (1 << i)) && i != FP_LEVITATION)
  4648. {
  4649. WP_ForcePowerStop(self, i);
  4650. }
  4651. i++;
  4652. }
  4653. if (self->client->tempSpectate >= level.time)
  4654. {
  4655. self->client->ps.fd.forcePower = 100;
  4656. self->client->ps.fd.forceRageRecoveryTime = 0;
  4657. }
  4658. self->client->ps.fd.forceDeactivateAll = 0;
  4659. if (self->client->ps.fd.forceJumpCharge)
  4660. {
  4661. G_MuteSound(self->client->ps.fd.killSoundEntIndex[TRACK_CHANNEL_1-50], CHAN_VOICE);
  4662. self->client->ps.fd.forceJumpCharge = 0;
  4663. }
  4664. }
  4665. else
  4666. { //otherwise just do a check through them all to see if they need to be stopped for any reason.
  4667. i = 0;
  4668. while (i < NUM_FORCE_POWERS)
  4669. {
  4670. if ((self->client->ps.fd.forcePowersActive & (1 << i)) && i != FP_LEVITATION &&
  4671. !BG_CanUseFPNow(g_gametype.integer, &self->client->ps, level.time, i))
  4672. {
  4673. WP_ForcePowerStop(self, i);
  4674. }
  4675. i++;
  4676. }
  4677. }
  4678. i = 0;
  4679. if (self->client->ps.powerups[PW_FORCE_ENLIGHTENED_LIGHT] || self->client->ps.powerups[PW_FORCE_ENLIGHTENED_DARK])
  4680. { //enlightenment
  4681. if (!self->client->ps.fd.forceUsingAdded)
  4682. {
  4683. i = 0;
  4684. while (i < NUM_FORCE_POWERS)
  4685. {
  4686. self->client->ps.fd.forcePowerBaseLevel[i] = self->client->ps.fd.forcePowerLevel[i];
  4687. if (!forcePowerDarkLight[i] ||
  4688. self->client->ps.fd.forceSide == forcePowerDarkLight[i])
  4689. {
  4690. self->client->ps.fd.forcePowerLevel[i] = FORCE_LEVEL_3;
  4691. self->client->ps.fd.forcePowersKnown |= (1 << i);
  4692. }
  4693. i++;
  4694. }
  4695. self->client->ps.fd.forceUsingAdded = 1;
  4696. }
  4697. }
  4698. else if (self->client->ps.fd.forceUsingAdded)
  4699. { //we don't have enlightenment but we're still using enlightened powers, so clear them back to how they should be.
  4700. i = 0;
  4701. while (i < NUM_FORCE_POWERS)
  4702. {
  4703. self->client->ps.fd.forcePowerLevel[i] = self->client->ps.fd.forcePowerBaseLevel[i];
  4704. if (!self->client->ps.fd.forcePowerLevel[i])
  4705. {
  4706. if (self->client->ps.fd.forcePowersActive & (1 << i))
  4707. {
  4708. WP_ForcePowerStop(self, i);
  4709. }
  4710. self->client->ps.fd.forcePowersKnown &= ~(1 << i);
  4711. }
  4712. i++;
  4713. }
  4714. self->client->ps.fd.forceUsingAdded = 0;
  4715. }
  4716. i = 0;
  4717. if (!(self->client->ps.fd.forcePowersActive & (1 << FP_TELEPATHY)))
  4718. { //clear the mindtrick index values
  4719. self->client->ps.fd.forceMindtrickTargetIndex = 0;
  4720. self->client->ps.fd.forceMindtrickTargetIndex2 = 0;
  4721. self->client->ps.fd.forceMindtrickTargetIndex3 = 0;
  4722. self->client->ps.fd.forceMindtrickTargetIndex4 = 0;
  4723. }
  4724. if (self->health < 1)
  4725. {
  4726. self->client->ps.fd.forceGripBeingGripped = 0;
  4727. }
  4728. if (self->client->ps.fd.forceGripBeingGripped > level.time)
  4729. {
  4730. self->client->ps.fd.forceGripCripple = 1;
  4731. //keep the saber off during this period
  4732. if (self->client->ps.weapon == WP_SABER && !self->client->ps.saberHolstered)
  4733. {
  4734. Cmd_ToggleSaber_f(self);
  4735. }
  4736. }
  4737. else
  4738. {
  4739. self->client->ps.fd.forceGripCripple = 0;
  4740. }
  4741. if (self->client->ps.fd.forceJumpSound)
  4742. {
  4743. G_PreDefSound(self->client->ps.origin, PDSOUND_FORCEJUMP);
  4744. self->client->ps.fd.forceJumpSound = 0;
  4745. }
  4746. if (self->client->ps.fd.forceGripCripple)
  4747. {
  4748. if (self->client->ps.fd.forceGripSoundTime < level.time)
  4749. {
  4750. G_PreDefSound(self->client->ps.origin, PDSOUND_FORCEGRIP);
  4751. self->client->ps.fd.forceGripSoundTime = level.time + 1000;
  4752. }
  4753. }
  4754. if (self->client->ps.fd.forcePowersActive & (1 << FP_SPEED))
  4755. {
  4756. self->client->ps.powerups[PW_SPEED] = level.time + 100;
  4757. }
  4758. if ( self->health <= 0 )
  4759. {//if dead, deactivate any active force powers
  4760. for ( i = 0; i < NUM_FORCE_POWERS; i++ )
  4761. {
  4762. if ( self->client->ps.fd.forcePowerDuration[i] || (self->client->ps.fd.forcePowersActive&( 1 << i )) )
  4763. {
  4764. WP_ForcePowerStop( self, (forcePowers_t)i );
  4765. self->client->ps.fd.forcePowerDuration[i] = 0;
  4766. }
  4767. }
  4768. goto powersetcheck;
  4769. }
  4770. if (self->client->ps.groundEntityNum != ENTITYNUM_NONE)
  4771. {
  4772. self->client->fjDidJump = qfalse;
  4773. }
  4774. if (self->client->ps.fd.forceJumpCharge && self->client->ps.groundEntityNum == ENTITYNUM_NONE && self->client->fjDidJump)
  4775. { //this was for the "charge" jump method... I guess
  4776. if (ucmd->upmove < 10 && (!(ucmd->buttons & BUTTON_FORCEPOWER) || self->client->ps.fd.forcePowerSelected != FP_LEVITATION))
  4777. {
  4778. G_MuteSound(self->client->ps.fd.killSoundEntIndex[TRACK_CHANNEL_1-50], CHAN_VOICE);
  4779. self->client->ps.fd.forceJumpCharge = 0;
  4780. }
  4781. }
  4782. #ifndef METROID_JUMP
  4783. else if ( (ucmd->upmove > 10) && (self->client->ps.pm_flags & PMF_JUMP_HELD) && self->client->ps.groundTime && (level.time - self->client->ps.groundTime) > 150 && !BG_HasYsalamiri(g_gametype.integer, &self->client->ps) && BG_CanUseFPNow(g_gametype.integer, &self->client->ps, level.time, FP_LEVITATION) )
  4784. {//just charging up
  4785. ForceJumpCharge( self, ucmd );
  4786. usingForce = qtrue;
  4787. }
  4788. else if (ucmd->upmove < 10 && self->client->ps.groundEntityNum == ENTITYNUM_NONE && self->client->ps.fd.forceJumpCharge)
  4789. {
  4790. self->client->ps.pm_flags &= ~(PMF_JUMP_HELD);
  4791. }
  4792. #endif
  4793. if (!(self->client->ps.pm_flags & PMF_JUMP_HELD) && self->client->ps.fd.forceJumpCharge)
  4794. {
  4795. if (!(ucmd->buttons & BUTTON_FORCEPOWER) ||
  4796. self->client->ps.fd.forcePowerSelected != FP_LEVITATION)
  4797. {
  4798. if (WP_DoSpecificPower( self, ucmd, FP_LEVITATION ))
  4799. {
  4800. usingForce = qtrue;
  4801. }
  4802. }
  4803. }
  4804. if ( ucmd->buttons & BUTTON_FORCEGRIP )
  4805. { //grip is one of the powers with its own button.. if it's held, call the specific grip power function.
  4806. if (WP_DoSpecificPower( self, ucmd, FP_GRIP ))
  4807. {
  4808. usingForce = qtrue;
  4809. }
  4810. else
  4811. { //don't let recharge even if the grip misses if the player still has the button down
  4812. usingForce = qtrue;
  4813. }
  4814. }
  4815. else
  4816. { //see if we're using it generically.. if not, stop.
  4817. if (self->client->ps.fd.forcePowersActive & (1 << FP_GRIP))
  4818. {
  4819. if (!(ucmd->buttons & BUTTON_FORCEPOWER) || self->client->ps.fd.forcePowerSelected != FP_GRIP)
  4820. {
  4821. WP_ForcePowerStop(self, FP_GRIP);
  4822. }
  4823. }
  4824. }
  4825. if ( ucmd->buttons & BUTTON_FORCE_LIGHTNING )
  4826. { //lightning
  4827. WP_DoSpecificPower(self, ucmd, FP_LIGHTNING);
  4828. usingForce = qtrue;
  4829. }
  4830. else
  4831. { //see if we're using it generically.. if not, stop.
  4832. if (self->client->ps.fd.forcePowersActive & (1 << FP_LIGHTNING))
  4833. {
  4834. if (!(ucmd->buttons & BUTTON_FORCEPOWER) || self->client->ps.fd.forcePowerSelected != FP_LIGHTNING)
  4835. {
  4836. WP_ForcePowerStop(self, FP_LIGHTNING);
  4837. }
  4838. }
  4839. }
  4840. if ( ucmd->buttons & BUTTON_FORCE_DRAIN )
  4841. { //drain
  4842. WP_DoSpecificPower(self, ucmd, FP_DRAIN);
  4843. usingForce = qtrue;
  4844. }
  4845. else
  4846. { //see if we're using it generically.. if not, stop.
  4847. if (self->client->ps.fd.forcePowersActive & (1 << FP_DRAIN))
  4848. {
  4849. if (!(ucmd->buttons & BUTTON_FORCEPOWER) || self->client->ps.fd.forcePowerSelected != FP_DRAIN)
  4850. {
  4851. WP_ForcePowerStop(self, FP_DRAIN);
  4852. }
  4853. }
  4854. }
  4855. if ( (ucmd->buttons & BUTTON_FORCEPOWER) &&
  4856. BG_CanUseFPNow(g_gametype.integer, &self->client->ps, level.time, self->client->ps.fd.forcePowerSelected))
  4857. {
  4858. if (self->client->ps.fd.forcePowerSelected == FP_LEVITATION)
  4859. {
  4860. ForceJumpCharge( self, ucmd );
  4861. usingForce = qtrue;
  4862. }
  4863. else if (WP_DoSpecificPower( self, ucmd, self->client->ps.fd.forcePowerSelected ))
  4864. {
  4865. usingForce = qtrue;
  4866. }
  4867. else if (self->client->ps.fd.forcePowerSelected == FP_GRIP)
  4868. {
  4869. usingForce = qtrue;
  4870. }
  4871. }
  4872. else
  4873. {
  4874. self->client->ps.fd.forceButtonNeedRelease = 0;
  4875. }
  4876. for ( i = 0; i < NUM_FORCE_POWERS; i++ )
  4877. {
  4878. if ( self->client->ps.fd.forcePowerDuration[i] )
  4879. {
  4880. if ( self->client->ps.fd.forcePowerDuration[i] < level.time )
  4881. {
  4882. if ( (self->client->ps.fd.forcePowersActive&( 1 << i )) )
  4883. {//turn it off
  4884. WP_ForcePowerStop( self, (forcePowers_t)i );
  4885. }
  4886. self->client->ps.fd.forcePowerDuration[i] = 0;
  4887. }
  4888. }
  4889. if ( (self->client->ps.fd.forcePowersActive&( 1 << i )) )
  4890. {
  4891. usingForce = qtrue;
  4892. WP_ForcePowerRun( self, (forcePowers_t)i, ucmd );
  4893. }
  4894. }
  4895. if ( self->client->ps.saberInFlight && self->client->ps.saberEntityNum )
  4896. {//don't regen force power while throwing saber
  4897. if ( self->client->ps.saberEntityNum < ENTITYNUM_NONE && self->client->ps.saberEntityNum > 0 )//player is 0
  4898. {//
  4899. if ( &g_entities[self->client->ps.saberEntityNum] != NULL && g_entities[self->client->ps.saberEntityNum].s.pos.trType == TR_LINEAR )
  4900. {//fell to the ground and we're trying to pull it back
  4901. usingForce = qtrue;
  4902. }
  4903. }
  4904. }
  4905. if ( !self->client->ps.fd.forcePowersActive || self->client->ps.fd.forcePowersActive == (1 << FP_DRAIN) )
  4906. {//when not using the force, regenerate at 1 point per half second
  4907. if ( !self->client->ps.saberInFlight && self->client->ps.fd.forcePowerRegenDebounceTime < level.time &&
  4908. (self->client->ps.weapon != WP_SABER || !BG_SaberInSpecial(self->client->ps.saberMove)) )
  4909. {
  4910. if (g_gametype.integer != GT_HOLOCRON || g_MaxHolocronCarry.value)
  4911. {
  4912. //if (!g_trueJedi.integer || self->client->ps.weapon == WP_SABER)
  4913. //let non-jedi force regen since we're doing a more strict jedi/non-jedi thing... this gives dark jedi something to drain
  4914. {
  4915. if (self->client->ps.powerups[PW_FORCE_BOON])
  4916. {
  4917. WP_ForcePowerRegenerate( self, 6 );
  4918. }
  4919. else if (self->client->ps.isJediMaster && g_gametype.integer == GT_JEDIMASTER)
  4920. {
  4921. WP_ForcePowerRegenerate( self, 4 ); //jedi master regenerates 4 times as fast
  4922. }
  4923. else
  4924. {
  4925. WP_ForcePowerRegenerate( self, 0 );
  4926. }
  4927. }
  4928. /*
  4929. else if (g_trueJedi.integer && self->client->ps.weapon != WP_SABER)
  4930. {
  4931. self->client->ps.fd.forcePower = 0;
  4932. }
  4933. */
  4934. }
  4935. else
  4936. { //regenerate based on the number of holocrons carried
  4937. holoregen = 0;
  4938. holo = 0;
  4939. while (holo < NUM_FORCE_POWERS)
  4940. {
  4941. if (self->client->ps.holocronsCarried[holo])
  4942. {
  4943. holoregen++;
  4944. }
  4945. holo++;
  4946. }
  4947. WP_ForcePowerRegenerate(self, holoregen);
  4948. }
  4949. if (g_gametype.integer == GT_SIEGE)
  4950. {
  4951. if (self->client->holdingObjectiveItem &&
  4952. g_entities[self->client->holdingObjectiveItem].inuse &&
  4953. g_entities[self->client->holdingObjectiveItem].genericValue15)
  4954. { //1 point per 7 seconds.. super slow
  4955. self->client->ps.fd.forcePowerRegenDebounceTime = level.time + 7000;
  4956. }
  4957. else if (self->client->siegeClass != -1 &&
  4958. (bgSiegeClasses[self->client->siegeClass].classflags & (1<<CFL_FASTFORCEREGEN)))
  4959. { //if this is siege and our player class has the fast force regen ability, then recharge with 1/5th the usual delay
  4960. self->client->ps.fd.forcePowerRegenDebounceTime = level.time + (g_forceRegenTime.integer*0.2);
  4961. }
  4962. else
  4963. {
  4964. self->client->ps.fd.forcePowerRegenDebounceTime = level.time + g_forceRegenTime.integer;
  4965. }
  4966. }
  4967. else
  4968. {
  4969. if ( g_gametype.integer == GT_POWERDUEL && self->client->sess.duelTeam == DUELTEAM_LONE )
  4970. {
  4971. if ( g_duel_fraglimit.integer )
  4972. {
  4973. self->client->ps.fd.forcePowerRegenDebounceTime = level.time + (g_forceRegenTime.integer*
  4974. (0.6 + (.3 * (float)self->client->sess.wins / (float)g_duel_fraglimit.integer)));
  4975. }
  4976. else
  4977. {
  4978. self->client->ps.fd.forcePowerRegenDebounceTime = level.time + (g_forceRegenTime.integer*0.7);
  4979. }
  4980. }
  4981. else
  4982. {
  4983. self->client->ps.fd.forcePowerRegenDebounceTime = level.time + g_forceRegenTime.integer;
  4984. }
  4985. }
  4986. }
  4987. }
  4988. powersetcheck:
  4989. if (prepower && self->client->ps.fd.forcePower < prepower)
  4990. {
  4991. int dif = ((prepower - self->client->ps.fd.forcePower)/2);
  4992. if (dif < 1)
  4993. {
  4994. dif = 1;
  4995. }
  4996. self->client->ps.fd.forcePower = (prepower-dif);
  4997. }
  4998. }
  4999. qboolean Jedi_DodgeEvasion( gentity_t *self, gentity_t *shooter, trace_t *tr, int hitLoc )
  5000. {
  5001. int dodgeAnim = -1;
  5002. if ( !self || !self->client || self->health <= 0 )
  5003. {
  5004. return qfalse;
  5005. }
  5006. if (!g_forceDodge.integer)
  5007. {
  5008. return qfalse;
  5009. }
  5010. if (g_forceDodge.integer != 2)
  5011. {
  5012. if (!(self->client->ps.fd.forcePowersActive & (1 << FP_SEE)))
  5013. {
  5014. return qfalse;
  5015. }
  5016. }
  5017. if ( self->client->ps.groundEntityNum == ENTITYNUM_NONE )
  5018. {//can't dodge in mid-air
  5019. return qfalse;
  5020. }
  5021. if ( self->client->ps.weaponTime > 0 || self->client->ps.forceHandExtend != HANDEXTEND_NONE )
  5022. {//in some effect that stops me from moving on my own
  5023. return qfalse;
  5024. }
  5025. if (g_forceDodge.integer == 2)
  5026. {
  5027. if (self->client->ps.fd.forcePowersActive)
  5028. { //for now just don't let us dodge if we're using a force power at all
  5029. return qfalse;
  5030. }
  5031. }
  5032. if (g_forceDodge.integer == 2)
  5033. {
  5034. if ( !WP_ForcePowerUsable( self, FP_SPEED ) )
  5035. {//make sure we have it and have enough force power
  5036. return qfalse;
  5037. }
  5038. }
  5039. if (g_forceDodge.integer == 2)
  5040. {
  5041. if ( Q_irand( 1, 7 ) > self->client->ps.fd.forcePowerLevel[FP_SPEED] )
  5042. {//more likely to fail on lower force speed level
  5043. return qfalse;
  5044. }
  5045. }
  5046. else
  5047. {
  5048. //We now dodge all the time, but only on level 3
  5049. if (self->client->ps.fd.forcePowerLevel[FP_SEE] < FORCE_LEVEL_3)
  5050. {//more likely to fail on lower force sight level
  5051. return qfalse;
  5052. }
  5053. }
  5054. switch( hitLoc )
  5055. {
  5056. case HL_NONE:
  5057. return qfalse;
  5058. break;
  5059. case HL_FOOT_RT:
  5060. case HL_FOOT_LT:
  5061. case HL_LEG_RT:
  5062. case HL_LEG_LT:
  5063. return qfalse;
  5064. case HL_BACK_RT:
  5065. dodgeAnim = BOTH_DODGE_FL;
  5066. break;
  5067. case HL_CHEST_RT:
  5068. dodgeAnim = BOTH_DODGE_FR;
  5069. break;
  5070. case HL_BACK_LT:
  5071. dodgeAnim = BOTH_DODGE_FR;
  5072. break;
  5073. case HL_CHEST_LT:
  5074. dodgeAnim = BOTH_DODGE_FR;
  5075. break;
  5076. case HL_BACK:
  5077. case HL_CHEST:
  5078. case HL_WAIST:
  5079. dodgeAnim = BOTH_DODGE_FL;
  5080. break;
  5081. case HL_ARM_RT:
  5082. case HL_HAND_RT:
  5083. dodgeAnim = BOTH_DODGE_L;
  5084. break;
  5085. case HL_ARM_LT:
  5086. case HL_HAND_LT:
  5087. dodgeAnim = BOTH_DODGE_R;
  5088. break;
  5089. case HL_HEAD:
  5090. dodgeAnim = BOTH_DODGE_FL;
  5091. break;
  5092. default:
  5093. return qfalse;
  5094. }
  5095. if ( dodgeAnim != -1 )
  5096. {
  5097. //Our own happy way of forcing an anim:
  5098. self->client->ps.forceHandExtend = HANDEXTEND_DODGE;
  5099. self->client->ps.forceDodgeAnim = dodgeAnim;
  5100. self->client->ps.forceHandExtendTime = level.time + 300;
  5101. self->client->ps.powerups[PW_SPEEDBURST] = level.time + 100;
  5102. if (g_forceDodge.integer == 2)
  5103. {
  5104. ForceSpeed( self, 500 );
  5105. }
  5106. else
  5107. {
  5108. G_Sound( self, CHAN_BODY, G_SoundIndex("sound/weapons/force/speed.wav") );
  5109. }
  5110. return qtrue;
  5111. }
  5112. return qfalse;
  5113. }