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