properly set the HITTYPE_BOUNCE flag on all timeout detonations
[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 // NO bounce protection, as bounces are limited!
5 void W_Hagar_Explode (void)
6 {
7         self.event_damage = SUB_Null;
8         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);
9
10         remove (self);
11 }
12
13 void W_Hagar_Explode2 (void)
14 {
15         self.event_damage = SUB_Null;
16         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);
17
18         remove (self);
19 }
20
21 void W_Hagar_Touch (void)
22 {
23         PROJECTILE_TOUCH;
24         self.use ();
25 }
26
27 void W_Hagar_Touch2 (void)
28 {
29         PROJECTILE_TOUCH;
30
31         if(self.cnt > 0 || other.takedamage == DAMAGE_AIM) {
32                 self.use();
33         } else {
34                 self.cnt++;
35                 pointparticles(particleeffectnum("hagar_bounce"), self.origin, self.velocity, 1);
36                 self.angles = vectoangles (self.velocity);
37                 self.owner = world;
38                 self.projectiledeathtype |= HITTYPE_BOUNCE;
39         }
40 }
41
42 void W_Hagar_Attack (void)
43 {
44         local entity missile;
45
46         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
47                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_hagar_primary_ammo");
48         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", cvar("g_balance_hagar_primary_damage"));
49
50         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
51
52         missile = spawn ();
53         missile.owner = missile.realowner = self;
54         missile.classname = "missile";
55         missile.bot_dodge = TRUE;
56         missile.bot_dodgerating = cvar("g_balance_hagar_primary_damage");
57         missile.touch = W_Hagar_Touch;
58         missile.use = W_Hagar_Explode;
59         missile.think = adaptor_think2use_hittype_splash;
60         missile.nextthink = time + cvar("g_balance_hagar_primary_lifetime");
61         PROJECTILE_MAKETRIGGER(missile);
62         missile.projectiledeathtype = WEP_HAGAR;
63         setorigin (missile, w_shotorg);
64         setsize(missile, '0 0 0', '0 0 0');
65
66         missile.movetype = MOVETYPE_FLY;
67         W_SETUPPROJECTILEVELOCITY(missile, g_balance_hagar_primary);
68
69         missile.angles = vectoangles (missile.velocity);
70         missile.flags = FL_PROJECTILE;
71
72         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR, TRUE);
73 }
74
75 void W_Hagar_Attack2 (void)
76 {
77         local entity missile;
78
79         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
80                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_hagar_secondary_ammo");
81         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", cvar("g_balance_hagar_secondary_damage"));
82         //W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav"); // TODO: move model a little to the right
83
84         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
85
86         missile = spawn ();
87         missile.owner = missile.realowner = self;
88         missile.classname = "missile";
89         missile.bot_dodge = TRUE;
90         missile.bot_dodgerating = cvar("g_balance_hagar_secondary_damage");
91         missile.touch = W_Hagar_Touch2;
92         missile.cnt = 0;
93         missile.use = W_Hagar_Explode2;
94         missile.think = adaptor_think2use_hittype_splash;
95         missile.nextthink = time + cvar("g_balance_hagar_secondary_lifetime_min") + random() * cvar("g_balance_hagar_secondary_lifetime_rand");
96         PROJECTILE_MAKETRIGGER(missile);
97         missile.projectiledeathtype = WEP_HAGAR | HITTYPE_SECONDARY;
98         setorigin (missile, w_shotorg);
99         setsize(missile, '0 0 0', '0 0 0');
100
101         missile.movetype = MOVETYPE_BOUNCEMISSILE;
102         W_SETUPPROJECTILEVELOCITY(missile, g_balance_hagar_secondary);
103
104         missile.angles = vectoangles (missile.velocity);
105         missile.flags = FL_PROJECTILE;
106
107         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR_BOUNCING, TRUE);
108 }
109
110 void spawnfunc_weapon_hagar (void)
111 {
112         weapon_defaultspawnfunc(WEP_HAGAR);
113 }
114
115 float w_hagar(float req)
116 {
117         if (req == WR_AIM)
118                 if (random()>0.15)
119                         self.BUTTON_ATCK = bot_aim(cvar("g_balance_hagar_primary_speed"), 0, cvar("g_balance_hagar_primary_lifetime"), FALSE);
120                 else
121                 {
122                         // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
123                         self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_hagar_primary_speed"), 0, cvar("g_balance_hagar_primary_lifetime"), FALSE);
124                 }
125         else if (req == WR_THINK)
126         {
127                 if (self.BUTTON_ATCK)
128                 if (weapon_prepareattack(0, cvar("g_balance_hagar_primary_refire")))
129                 {
130                         W_Hagar_Attack();
131                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_hagar_primary_refire"), w_ready);
132                 }
133                 if (self.BUTTON_ATCK2 && cvar("g_balance_hagar_secondary"))
134                 if (weapon_prepareattack(1, cvar("g_balance_hagar_secondary_refire")))
135                 {
136                         W_Hagar_Attack2();
137                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_hagar_secondary_refire"), w_ready);
138                 }
139         }
140         else if (req == WR_PRECACHE)
141         {
142                 precache_model ("models/weapons/g_hagar.md3");
143                 precache_model ("models/weapons/v_hagar.md3");
144                 precache_model ("models/weapons/h_hagar.iqm");
145                 precache_sound ("weapons/hagar_fire.wav");
146         }
147         else if (req == WR_SETUP)
148                 weapon_setup(WEP_HAGAR);
149         else if (req == WR_CHECKAMMO1)
150                 return self.ammo_rockets >= cvar("g_balance_hagar_primary_ammo");
151         else if (req == WR_CHECKAMMO2)
152                 return self.ammo_rockets >= cvar("g_balance_hagar_secondary_ammo");
153         else if (req == WR_SUICIDEMESSAGE)
154                 w_deathtypestring = "played with tiny rockets";
155         else if (req == WR_KILLMESSAGE)
156         {
157                 if(w_deathtype & HITTYPE_BOUNCE) // must be secondary; unchecked: SPLASH
158                         w_deathtypestring = "hoped #'s missiles wouldn't bounce";
159                 else // unchecked: SPLASH, SECONDARY
160                         w_deathtypestring = "was pummeled by";
161         }
162         return TRUE;
163 };
164 #endif