Merge remote branch 'refs/remotes/origin/fruitiex/racefixes'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_hagar.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(HAGAR, w_hagar, IT_ROCKETS, 8, WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "hagar", "hagar", "Hagar");
3 #else
4 #ifdef SVQC
5 // NO bounce protection, as bounces are limited!
6 void W_Hagar_Explode (void)
7 {
8         self.event_damage = SUB_Null;
9         RadiusDamage (self, self.realowner, cvar("g_balance_hagar_primary_damage"), cvar("g_balance_hagar_primary_edgedamage"), cvar("g_balance_hagar_primary_radius"), world, cvar("g_balance_hagar_primary_force"), self.projectiledeathtype, other);
10
11         remove (self);
12 }
13
14 void W_Hagar_Explode2 (void)
15 {
16         self.event_damage = SUB_Null;
17         RadiusDamage (self, self.realowner, cvar("g_balance_hagar_secondary_damage"), cvar("g_balance_hagar_secondary_edgedamage"), cvar("g_balance_hagar_secondary_radius"), world, cvar("g_balance_hagar_secondary_force"), self.projectiledeathtype, other);
18
19         remove (self);
20 }
21
22 void W_Hagar_Touch (void)
23 {
24         PROJECTILE_TOUCH;
25         self.use ();
26 }
27
28 void W_Hagar_Touch2 (void)
29 {
30         PROJECTILE_TOUCH;
31
32         if(self.cnt > 0 || other.takedamage == DAMAGE_AIM) {
33                 self.use();
34         } else {
35                 self.cnt++;
36                 pointparticles(particleeffectnum("hagar_bounce"), self.origin, self.velocity, 1);
37                 self.angles = vectoangles (self.velocity);
38                 self.owner = world;
39                 self.projectiledeathtype |= HITTYPE_BOUNCE;
40         }
41 }
42
43 void W_Hagar_Attack (void)
44 {
45         local entity missile;
46
47         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
48                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_hagar_primary_ammo");
49         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", cvar("g_balance_hagar_primary_damage"));
50
51         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
52
53         missile = spawn ();
54         missile.owner = missile.realowner = self;
55         missile.classname = "missile";
56         missile.bot_dodge = TRUE;
57         missile.bot_dodgerating = cvar("g_balance_hagar_primary_damage");
58         missile.touch = W_Hagar_Touch;
59         missile.use = W_Hagar_Explode;
60         missile.think = adaptor_think2use_hittype_splash;
61         missile.nextthink = time + cvar("g_balance_hagar_primary_lifetime");
62         PROJECTILE_MAKETRIGGER(missile);
63         missile.projectiledeathtype = WEP_HAGAR;
64         setorigin (missile, w_shotorg);
65         setsize(missile, '0 0 0', '0 0 0');
66
67         missile.movetype = MOVETYPE_FLY;
68         W_SETUPPROJECTILEVELOCITY(missile, g_balance_hagar_primary);
69
70         missile.angles = vectoangles (missile.velocity);
71         missile.flags = FL_PROJECTILE;
72
73         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR, TRUE);
74
75         other = missile; MUTATOR_CALLHOOK(EditProjectile);
76 }
77
78 void W_Hagar_Attack2 (void)
79 {
80         local entity missile;
81
82         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
83                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_hagar_secondary_ammo");
84         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", cvar("g_balance_hagar_secondary_damage"));
85         //W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav"); // TODO: move model a little to the right
86
87         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
88
89         missile = spawn ();
90         missile.owner = missile.realowner = self;
91         missile.classname = "missile";
92         missile.bot_dodge = TRUE;
93         missile.bot_dodgerating = cvar("g_balance_hagar_secondary_damage");
94         missile.touch = W_Hagar_Touch2;
95         missile.cnt = 0;
96         missile.use = W_Hagar_Explode2;
97         missile.think = adaptor_think2use_hittype_splash;
98         missile.nextthink = time + cvar("g_balance_hagar_secondary_lifetime_min") + random() * cvar("g_balance_hagar_secondary_lifetime_rand");
99         PROJECTILE_MAKETRIGGER(missile);
100         missile.projectiledeathtype = WEP_HAGAR | HITTYPE_SECONDARY;
101         setorigin (missile, w_shotorg);
102         setsize(missile, '0 0 0', '0 0 0');
103
104         missile.movetype = MOVETYPE_BOUNCEMISSILE;
105         W_SETUPPROJECTILEVELOCITY(missile, g_balance_hagar_secondary);
106
107         missile.angles = vectoangles (missile.velocity);
108         missile.flags = FL_PROJECTILE;
109
110         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR_BOUNCING, TRUE);
111
112         other = missile; MUTATOR_CALLHOOK(EditProjectile);
113 }
114
115 void spawnfunc_weapon_hagar (void)
116 {
117         weapon_defaultspawnfunc(WEP_HAGAR);
118 }
119
120 float w_hagar(float req)
121 {
122         if (req == WR_AIM)
123                 if (random()>0.15)
124                         self.BUTTON_ATCK = bot_aim(cvar("g_balance_hagar_primary_speed"), 0, cvar("g_balance_hagar_primary_lifetime"), FALSE);
125                 else
126                 {
127                         // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
128                         self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_hagar_primary_speed"), 0, cvar("g_balance_hagar_primary_lifetime"), FALSE);
129                 }
130         else if (req == WR_THINK)
131         {
132                 if (self.BUTTON_ATCK)
133                 if (weapon_prepareattack(0, cvar("g_balance_hagar_primary_refire")))
134                 {
135                         W_Hagar_Attack();
136                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_hagar_primary_refire"), w_ready);
137                 }
138                 if (self.BUTTON_ATCK2 && cvar("g_balance_hagar_secondary"))
139                 if (weapon_prepareattack(1, cvar("g_balance_hagar_secondary_refire")))
140                 {
141                         W_Hagar_Attack2();
142                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_hagar_secondary_refire"), w_ready);
143                 }
144         }
145         else if (req == WR_PRECACHE)
146         {
147                 precache_model ("models/weapons/g_hagar.md3");
148                 precache_model ("models/weapons/v_hagar.md3");
149                 precache_model ("models/weapons/h_hagar.iqm");
150                 precache_sound ("weapons/hagar_fire.wav");
151         }
152         else if (req == WR_SETUP)
153                 weapon_setup(WEP_HAGAR);
154         else if (req == WR_CHECKAMMO1)
155                 return self.ammo_rockets >= cvar("g_balance_hagar_primary_ammo");
156         else if (req == WR_CHECKAMMO2)
157                 return self.ammo_rockets >= cvar("g_balance_hagar_secondary_ammo");
158         return TRUE;
159 };
160 #endif
161 #ifdef CSQC
162 float w_hagar(float req)
163 {
164         if(req == WR_IMPACTEFFECT)
165         {
166                 vector org2;
167                 org2 = w_org + w_backoff * 6;
168                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
169                 if(!w_issilent)
170                 {
171                         if (w_random<0.15)
172                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
173                         else if (w_random<0.7)
174                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
175                         else
176                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
177                 }
178         }
179         else if(req == WR_PRECACHE)
180         {
181                 precache_sound("weapons/hagexp1.wav");
182                 precache_sound("weapons/hagexp2.wav");
183                 precache_sound("weapons/hagexp3.wav");
184         }
185         else if (req == WR_SUICIDEMESSAGE)
186                 w_deathtypestring = "%s played with tiny rockets";
187         else if (req == WR_KILLMESSAGE)
188         {
189                 if(w_deathtype & HITTYPE_BOUNCE) // must be secondary; unchecked: SPLASH
190                         w_deathtypestring = "%s hoped %s's missiles wouldn't bounce";
191                 else // unchecked: SPLASH, SECONDARY
192                         w_deathtypestring = "%s was pummeled by %s";
193         }
194         return TRUE;
195 }
196 #endif
197 #endif