shield.qc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* Copyright (C) 1996-2022 id Software LLC
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  13. See file, 'COPYING', for details.
  14. */
  15. // Shield
  16. //
  17. // ===================
  18. // shield_think
  19. // ===================
  20. void() shield_think =
  21. {
  22. if ( self.owner.shield_death_time < time)
  23. {
  24. self.owner.shield_entity = world;
  25. remove (self);
  26. return;
  27. }
  28. if ( (self.owner.shield_death_time - 0.25) <= time)
  29. {
  30. self.model = string_null;
  31. }
  32. else
  33. {
  34. setorigin ( self, self.owner.origin );
  35. self.v_angle = self.owner.v_angle;
  36. self.angles = self.owner.angles;
  37. }
  38. self.think = shield_think;
  39. self.nextthink = time + 0.05;
  40. };
  41. // ===================
  42. // shield_spawn
  43. // ===================
  44. void(entity shieldOwner, vector dir) shield_spawn =
  45. {
  46. local entity newShield;
  47. if ( shieldOwner.shield_death_time > time)
  48. {
  49. return;
  50. }
  51. newShield = spawn ();
  52. newShield.owner = shieldOwner;
  53. newShield.solid = SOLID_NOT;
  54. newShield.takedamage = DAMAGE_NO;
  55. newShield.movetype = MOVETYPE_NONE;
  56. newShield.classname = "power_shield";
  57. // time for shield to live
  58. // shieldOwner.shield_death_time = time + 0.5;
  59. shieldOwner.shield_death_time = time + 0.3;
  60. shieldOwner.shield_entity = newShield;
  61. newShield.v_angle = shieldOwner.v_angle;
  62. newShield.angles = shieldOwner.angles;
  63. setorigin (newShield, shieldOwner.origin);
  64. setmodel (newShield, "progs/p_shield.mdl");
  65. setsize (newShield, '0 0 0', '0 0 0');
  66. newShield.nextthink = time + 0.1;
  67. newShield.think = shield_think;
  68. };
  69. // ===================
  70. // shield_hit
  71. // ===================
  72. float(entity targ, entity inflictor, entity attacker, float damage) shield_hit=
  73. {
  74. local vector dir;
  75. local float save;
  76. local float hitAngle;
  77. dir = inflictor.origin - targ.origin;
  78. save = vectoyaw ( dir );
  79. makevectors (targ.angles);
  80. hitAngle = save - vectoyaw ( v_forward );
  81. if(hitAngle > 90 && hitAngle < 270)
  82. {
  83. return damage;
  84. }
  85. else if(hitAngle < -90 && hitAngle > -270 )
  86. {
  87. return damage;
  88. }
  89. shield_spawn ( targ, dir);
  90. if (targ.shieldSoundTime < time)
  91. {
  92. sound (targ, CHAN_ITEM, "shield/hit.wav", 1, ATTN_NORM);
  93. targ.shieldSoundTime = time + 0.5;
  94. }
  95. if (inflictor.classname == "lava_spike")
  96. save = damage * 0.70;
  97. else
  98. save = damage * 0.30;
  99. return save;
  100. };