]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/blaster.qc
2f24e9e254bcb495b4c53782f4434771ed1269b8
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / blaster.qc
1 #include "blaster.qh"
2 #ifndef IMPLEMENTATION
3 CLASS(Blaster, Weapon)
4 /* ammotype  */ //ATTRIB(Blaster, ammo_field, .int, ammo_none);
5 /* impulse   */ ATTRIB(Blaster, impulse, int, 1);
6 /* flags     */ ATTRIB(Blaster, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
7 /* rating    */ ATTRIB(Blaster, bot_pickupbasevalue, float, 0);
8 /* color     */ ATTRIB(Blaster, wpcolor, vector, '1 0.5 0.5');
9 /* modelname */ ATTRIB(Blaster, mdl, string, "laser");
10 #ifdef GAMEQC
11 /* model     */ ATTRIB(Blaster, m_model, Model, MDL_BLASTER_ITEM);
12 #endif
13 /* crosshair */ ATTRIB(Blaster, w_crosshair, string, "gfx/crosshairlaser");
14 /* crosshair */ ATTRIB(Blaster, w_crosshair_size, float, 0.5);
15 /* wepimg    */ ATTRIB(Blaster, model2, string, "weaponlaser");
16 /* refname   */ ATTRIB(Blaster, netname, string, "blaster");
17 /* wepname   */ ATTRIB(Blaster, m_name, string, _("Blaster"));
18
19 #define X(BEGIN, P, END, class, prefix) \
20         BEGIN(class) \
21                 P(class, prefix, animtime, float, BOTH) \
22                 P(class, prefix, damage, float, BOTH) \
23                 P(class, prefix, delay, float, BOTH) \
24                 P(class, prefix, edgedamage, float, BOTH) \
25                 P(class, prefix, force, float, BOTH) \
26                 P(class, prefix, force_zscale, float, BOTH) \
27                 P(class, prefix, lifetime, float, BOTH) \
28                 P(class, prefix, radius, float, BOTH) \
29                 P(class, prefix, refire, float, BOTH) \
30                 P(class, prefix, secondary, float, NONE) \
31                 P(class, prefix, shotangle, float, BOTH) \
32                 P(class, prefix, speed, float, BOTH) \
33                 P(class, prefix, spread, float, BOTH) \
34         P(class, prefix, switchdelay_drop, float, NONE) \
35                 P(class, prefix, switchdelay_raise, float, NONE) \
36         P(class, prefix, weaponreplace, string, NONE) \
37         P(class, prefix, weaponstartoverride, float, NONE) \
38         P(class, prefix, weaponstart, float, NONE) \
39         P(class, prefix, weaponthrowable, float, NONE) \
40         END()
41         W_PROPS(X, Blaster, blaster)
42 #undef X
43
44 ENDCLASS(Blaster)
45 REGISTER_WEAPON(BLASTER, blaster, NEW(Blaster));
46
47 #ifdef SVQC
48 .float blaster_damage;
49 .float blaster_edgedamage;
50 .float blaster_radius;
51 .float blaster_force;
52 .float blaster_lifetime;
53 #endif
54 #endif
55 #ifdef IMPLEMENTATION
56 #ifdef SVQC
57 spawnfunc(weapon_blaster) { weapon_defaultspawnfunc(this, WEP_BLASTER); }
58 spawnfunc(weapon_laser) { spawnfunc_weapon_blaster(this); }
59
60 void W_Blaster_Touch(entity this, entity toucher)
61 {
62         PROJECTILE_TOUCH(this, toucher);
63
64         this.event_damage = func_null;
65
66         RadiusDamage(
67                 this,
68                 this.realowner,
69                 this.blaster_damage,
70                 this.blaster_edgedamage,
71                 this.blaster_radius,
72                 NULL,
73                 NULL,
74                 this.blaster_force,
75                 this.projectiledeathtype,
76                 toucher
77         );
78
79         delete(this);
80 }
81
82 void W_Blaster_Think(entity this)
83 {
84         set_movetype(this, MOVETYPE_FLY);
85         setthink(this, SUB_Remove);
86         this.nextthink = time + this.blaster_lifetime;
87         CSQCProjectile(this, true, PROJECTILE_BLASTER, true);
88 }
89
90 void W_Blaster_Attack(
91         entity actor,
92         .entity weaponentity,
93         float atk_deathtype,
94         float atk_shotangle,
95         float atk_damage,
96         float atk_edgedamage,
97         float atk_radius,
98         float atk_force,
99         float atk_speed,
100         float atk_spread,
101         float atk_delay,
102         float atk_lifetime)
103 {
104         vector s_forward = v_forward * cos(atk_shotangle * DEG2RAD) + v_up * sin(atk_shotangle * DEG2RAD);
105
106         W_SetupShot_Dir(actor, weaponentity, s_forward, false, 3, SND_LASERGUN_FIRE, CH_WEAPON_B, atk_damage);
107         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
108
109         entity missile = new(blasterbolt);
110         missile.owner = missile.realowner = actor;
111         missile.bot_dodge = true;
112         missile.bot_dodgerating = atk_damage;
113         PROJECTILE_MAKETRIGGER(missile);
114
115         missile.blaster_damage = atk_damage;
116         missile.blaster_edgedamage = atk_edgedamage;
117         missile.blaster_radius = atk_radius;
118         missile.blaster_force = atk_force;
119         missile.blaster_lifetime = atk_lifetime;
120
121         setorigin(missile, w_shotorg);
122         setsize(missile, '0 0 0', '0 0 0');
123
124         W_SetupProjVelocity_Explicit(
125                 missile,
126                 w_shotdir,
127                 v_up,
128                 atk_speed,
129                 0,
130                 0,
131                 atk_spread,
132                 false
133         );
134
135         missile.angles = vectoangles(missile.velocity);
136
137         //missile.glow_color = 250; // 244, 250
138         //missile.glow_size = 120;
139
140         settouch(missile, W_Blaster_Touch);
141         missile.flags = FL_PROJECTILE;
142         IL_PUSH(g_projectiles, missile);
143         missile.missile_flags = MIF_SPLASH;
144         missile.projectiledeathtype = atk_deathtype;
145         setthink(missile, W_Blaster_Think);
146         missile.nextthink = time + atk_delay;
147
148         MUTATOR_CALLHOOK(EditProjectile, actor, missile);
149
150         if (time >= missile.nextthink)
151         {
152                 getthink(missile)(missile);
153         }
154 }
155
156 METHOD(Blaster, wr_aim, void(entity thiswep, entity actor))
157 {
158     if(WEP_CVAR(blaster, secondary))
159     {
160         if((random() * (WEP_CVAR_PRI(blaster, damage) + WEP_CVAR_SEC(blaster, damage))) > WEP_CVAR_PRI(blaster, damage))
161             { PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, WEP_CVAR_SEC(blaster, speed), 0, WEP_CVAR_SEC(blaster, lifetime), false); }
162         else
163             { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, WEP_CVAR_PRI(blaster, speed), 0, WEP_CVAR_PRI(blaster, lifetime), false); }
164     }
165     else
166         { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, WEP_CVAR_PRI(blaster, speed), 0, WEP_CVAR_PRI(blaster, lifetime), false); }
167 }
168
169 METHOD(Blaster, wr_think, void(Blaster thiswep, entity actor, .entity weaponentity, int fire))
170 {
171     if(fire & 1)
172     {
173         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(blaster, refire)))
174         {
175             W_Blaster_Attack(
176                 actor,
177                 weaponentity,
178                 WEP_BLASTER.m_id,
179                 WEP_CVAR_PRI(blaster, shotangle),
180                 WEP_CVAR_PRI(blaster, damage),
181                 WEP_CVAR_PRI(blaster, edgedamage),
182                 WEP_CVAR_PRI(blaster, radius),
183                 WEP_CVAR_PRI(blaster, force),
184                 WEP_CVAR_PRI(blaster, speed),
185                 WEP_CVAR_PRI(blaster, spread),
186                 WEP_CVAR_PRI(blaster, delay),
187                 WEP_CVAR_PRI(blaster, lifetime)
188             );
189             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(blaster, animtime), w_ready);
190         }
191     }
192     else if(fire & 2)
193     {
194         switch(WEP_CVAR(blaster, secondary))
195         {
196             case 0: // switch to last used weapon
197             {
198                 if(PS(actor).m_switchweapon == WEP_BLASTER) // don't do this if already switching
199                     W_LastWeapon(actor);
200                 break;
201             }
202
203             case 1: // normal projectile secondary
204             {
205                 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(blaster, refire)))
206                 {
207                     W_Blaster_Attack(
208                         actor,
209                         weaponentity,
210                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
211                         WEP_CVAR_SEC(blaster, shotangle),
212                         WEP_CVAR_SEC(blaster, damage),
213                         WEP_CVAR_SEC(blaster, edgedamage),
214                         WEP_CVAR_SEC(blaster, radius),
215                         WEP_CVAR_SEC(blaster, force),
216                         WEP_CVAR_SEC(blaster, speed),
217                         WEP_CVAR_SEC(blaster, spread),
218                         WEP_CVAR_SEC(blaster, delay),
219                         WEP_CVAR_SEC(blaster, lifetime)
220                     );
221                     weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(blaster, animtime), w_ready);
222                 }
223
224                 break;
225             }
226         }
227     }
228 }
229
230 METHOD(Blaster, wr_setup, void(entity thiswep, entity actor))
231 {
232     actor.ammo_field = ammo_none;
233 }
234
235 METHOD(Blaster, wr_checkammo1, bool(entity thiswep, entity actor))
236 {
237     return true; // infinite ammo
238 }
239
240 METHOD(Blaster, wr_checkammo2, bool(entity thiswep, entity actor))
241 {
242     return true; // blaster has infinite ammo
243 }
244
245 METHOD(Blaster, wr_suicidemessage, Notification(entity thiswep))
246 {
247     return WEAPON_BLASTER_SUICIDE;
248 }
249
250 METHOD(Blaster, wr_killmessage, Notification(entity thiswep))
251 {
252     return WEAPON_BLASTER_MURDER;
253 }
254
255 #endif
256 #ifdef CSQC
257
258 METHOD(Blaster, wr_impacteffect, void(entity thiswep, entity actor))
259 {
260     vector org2;
261     org2 = w_org + w_backoff * 6;
262     pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
263     if(!w_issilent) { sound(actor, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM); }
264 }
265
266 #endif
267 #endif