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