]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/blaster.qc
Merge branch 'master' into Mario/invasion_types
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / blaster.qc
1 #include "blaster.qh"
2
3 #ifdef SVQC
4 spawnfunc(weapon_blaster) { weapon_defaultspawnfunc(this, WEP_BLASTER); }
5 spawnfunc(weapon_laser) { spawnfunc_weapon_blaster(this); }
6
7 void W_Blaster_Touch(entity this, entity toucher)
8 {
9         PROJECTILE_TOUCH(this, toucher);
10
11         this.event_damage = func_null;
12
13         RadiusDamage(
14                 this,
15                 this.realowner,
16                 this.blaster_damage,
17                 this.blaster_edgedamage,
18                 this.blaster_radius,
19                 NULL,
20                 NULL,
21                 this.blaster_force,
22                 this.projectiledeathtype,
23                 toucher
24         );
25
26         delete(this);
27 }
28
29 void W_Blaster_Think(entity this)
30 {
31         set_movetype(this, MOVETYPE_FLY);
32         setthink(this, SUB_Remove);
33         this.nextthink = time + this.blaster_lifetime;
34         CSQCProjectile(this, true, PROJECTILE_BLASTER, true);
35 }
36
37 void W_Blaster_Attack(
38         entity actor,
39         .entity weaponentity,
40         float atk_deathtype,
41         float atk_shotangle,
42         float atk_damage,
43         float atk_edgedamage,
44         float atk_radius,
45         float atk_force,
46         float atk_speed,
47         float atk_spread,
48         float atk_delay,
49         float atk_lifetime)
50 {
51         vector s_forward = v_forward * cos(atk_shotangle * DEG2RAD) + v_up * sin(atk_shotangle * DEG2RAD);
52
53         W_SetupShot_Dir(actor, weaponentity, s_forward, false, 3, SND_LASERGUN_FIRE, CH_WEAPON_B, atk_damage);
54         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
55
56         entity missile = new(blasterbolt);
57         missile.owner = missile.realowner = actor;
58         missile.bot_dodge = true;
59         missile.bot_dodgerating = atk_damage;
60         PROJECTILE_MAKETRIGGER(missile);
61
62         missile.blaster_damage = atk_damage;
63         missile.blaster_edgedamage = atk_edgedamage;
64         missile.blaster_radius = atk_radius;
65         missile.blaster_force = atk_force;
66         missile.blaster_lifetime = atk_lifetime;
67
68         setorigin(missile, w_shotorg);
69         setsize(missile, '0 0 0', '0 0 0');
70
71         W_SetupProjVelocity_Explicit(
72                 missile,
73                 w_shotdir,
74                 v_up,
75                 atk_speed,
76                 0,
77                 0,
78                 atk_spread,
79                 false
80         );
81
82         missile.angles = vectoangles(missile.velocity);
83
84         //missile.glow_color = 250; // 244, 250
85         //missile.glow_size = 120;
86
87         settouch(missile, W_Blaster_Touch);
88         missile.flags = FL_PROJECTILE;
89         IL_PUSH(g_projectiles, missile);
90         IL_PUSH(g_bot_dodge, missile);
91         missile.missile_flags = MIF_SPLASH;
92         missile.projectiledeathtype = atk_deathtype;
93         setthink(missile, W_Blaster_Think);
94         missile.nextthink = time + atk_delay;
95
96         MUTATOR_CALLHOOK(EditProjectile, actor, missile);
97
98         if (time >= missile.nextthink)
99         {
100                 getthink(missile)(missile);
101         }
102 }
103
104 METHOD(Blaster, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
105 {
106     if(WEP_CVAR(blaster, secondary))
107     {
108         if((random() * (WEP_CVAR_PRI(blaster, damage) + WEP_CVAR_SEC(blaster, damage))) > WEP_CVAR_PRI(blaster, damage))
109             { PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, WEP_CVAR_SEC(blaster, speed), 0, WEP_CVAR_SEC(blaster, lifetime), false); }
110         else
111             { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, WEP_CVAR_PRI(blaster, speed), 0, WEP_CVAR_PRI(blaster, lifetime), false); }
112     }
113     else
114         { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, WEP_CVAR_PRI(blaster, speed), 0, WEP_CVAR_PRI(blaster, lifetime), false); }
115 }
116
117 METHOD(Blaster, wr_think, void(Blaster thiswep, entity actor, .entity weaponentity, int fire))
118 {
119     if(fire & 1)
120     {
121         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(blaster, refire)))
122         {
123             W_Blaster_Attack(
124                 actor,
125                 weaponentity,
126                 WEP_BLASTER.m_id,
127                 WEP_CVAR_PRI(blaster, shotangle),
128                 WEP_CVAR_PRI(blaster, damage),
129                 WEP_CVAR_PRI(blaster, edgedamage),
130                 WEP_CVAR_PRI(blaster, radius),
131                 WEP_CVAR_PRI(blaster, force),
132                 WEP_CVAR_PRI(blaster, speed),
133                 WEP_CVAR_PRI(blaster, spread),
134                 WEP_CVAR_PRI(blaster, delay),
135                 WEP_CVAR_PRI(blaster, lifetime)
136             );
137             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(blaster, animtime), w_ready);
138         }
139     }
140     else if(fire & 2)
141     {
142         switch(WEP_CVAR(blaster, secondary))
143         {
144             case 0: // switch to last used weapon
145             {
146                 if(actor.(weaponentity).m_switchweapon == WEP_BLASTER) // don't do this if already switching
147                     W_LastWeapon(actor, weaponentity);
148                 break;
149             }
150
151             case 1: // normal projectile secondary
152             {
153                 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(blaster, refire)))
154                 {
155                     W_Blaster_Attack(
156                         actor,
157                         weaponentity,
158                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
159                         WEP_CVAR_SEC(blaster, shotangle),
160                         WEP_CVAR_SEC(blaster, damage),
161                         WEP_CVAR_SEC(blaster, edgedamage),
162                         WEP_CVAR_SEC(blaster, radius),
163                         WEP_CVAR_SEC(blaster, force),
164                         WEP_CVAR_SEC(blaster, speed),
165                         WEP_CVAR_SEC(blaster, spread),
166                         WEP_CVAR_SEC(blaster, delay),
167                         WEP_CVAR_SEC(blaster, lifetime)
168                     );
169                     weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(blaster, animtime), w_ready);
170                 }
171
172                 break;
173             }
174         }
175     }
176 }
177
178 METHOD(Blaster, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
179 {
180     return true; // infinite ammo
181 }
182
183 METHOD(Blaster, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
184 {
185     return true; // blaster has infinite ammo
186 }
187
188 METHOD(Blaster, wr_suicidemessage, Notification(entity thiswep))
189 {
190     return WEAPON_BLASTER_SUICIDE;
191 }
192
193 METHOD(Blaster, wr_killmessage, Notification(entity thiswep))
194 {
195     return WEAPON_BLASTER_MURDER;
196 }
197
198 #endif
199 #ifdef CSQC
200
201 METHOD(Blaster, wr_impacteffect, void(entity thiswep, entity actor))
202 {
203     vector org2;
204     org2 = w_org + w_backoff * 6;
205     pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
206     if(!w_issilent) { sound(actor, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM); }
207 }
208
209 #endif