]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/blaster.qc
Merge branch 'TimePath/globalforces' into 'master'
[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(entity this, entity toucher)
60 {
61         PROJECTILE_TOUCH(this, toucher);
62
63         this.event_damage = func_null;
64
65         RadiusDamage(
66                 this,
67                 this.realowner,
68                 this.blaster_damage,
69                 this.blaster_edgedamage,
70                 this.blaster_radius,
71                 NULL,
72                 NULL,
73                 this.blaster_force,
74                 this.projectiledeathtype,
75                 toucher
76         );
77
78         delete(this);
79 }
80
81 void W_Blaster_Think(entity this)
82 {
83         set_movetype(this, MOVETYPE_FLY);
84         setthink(this, SUB_Remove);
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         .entity weaponentity,
92         float atk_deathtype,
93         float atk_shotangle,
94         float atk_damage,
95         float atk_edgedamage,
96         float atk_radius,
97         float atk_force,
98         float atk_speed,
99         float atk_spread,
100         float atk_delay,
101         float atk_lifetime)
102 {
103         vector s_forward = v_forward * cos(atk_shotangle * DEG2RAD) + v_up * sin(atk_shotangle * DEG2RAD);
104
105         W_SetupShot_Dir(actor, weaponentity, s_forward, false, 3, SND_LASERGUN_FIRE, CH_WEAPON_B, atk_damage);
106         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
107
108         entity missile = new(blasterbolt);
109         missile.owner = missile.realowner = actor;
110         missile.bot_dodge = true;
111         missile.bot_dodgerating = atk_damage;
112         PROJECTILE_MAKETRIGGER(missile);
113
114         missile.blaster_damage = atk_damage;
115         missile.blaster_edgedamage = atk_edgedamage;
116         missile.blaster_radius = atk_radius;
117         missile.blaster_force = atk_force;
118         missile.blaster_lifetime = atk_lifetime;
119
120         setorigin(missile, w_shotorg);
121         setsize(missile, '0 0 0', '0 0 0');
122
123         W_SetupProjVelocity_Explicit(
124                 missile,
125                 w_shotdir,
126                 v_up,
127                 atk_speed,
128                 0,
129                 0,
130                 atk_spread,
131                 false
132         );
133
134         missile.angles = vectoangles(missile.velocity);
135
136         //missile.glow_color = 250; // 244, 250
137         //missile.glow_size = 120;
138
139         settouch(missile, W_Blaster_Touch);
140         missile.flags = FL_PROJECTILE;
141         IL_PUSH(g_projectiles, missile);
142         missile.missile_flags = MIF_SPLASH;
143         missile.projectiledeathtype = atk_deathtype;
144         setthink(missile, W_Blaster_Think);
145         missile.nextthink = time + atk_delay;
146
147         MUTATOR_CALLHOOK(EditProjectile, actor, missile);
148
149         if (time >= missile.nextthink)
150         {
151                 getthink(missile)(missile);
152         }
153 }
154
155 METHOD(Blaster, wr_aim, void(entity thiswep, entity actor))
156 {
157     if(WEP_CVAR(blaster, secondary))
158     {
159         if((random() * (WEP_CVAR_PRI(blaster, damage) + WEP_CVAR_SEC(blaster, damage))) > WEP_CVAR_PRI(blaster, damage))
160             { PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, WEP_CVAR_SEC(blaster, speed), 0, WEP_CVAR_SEC(blaster, lifetime), false); }
161         else
162             { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, WEP_CVAR_PRI(blaster, speed), 0, WEP_CVAR_PRI(blaster, lifetime), false); }
163     }
164     else
165         { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, WEP_CVAR_PRI(blaster, speed), 0, WEP_CVAR_PRI(blaster, lifetime), false); }
166 }
167
168 METHOD(Blaster, wr_think, void(Blaster thiswep, entity actor, .entity weaponentity, int fire))
169 {
170     if(fire & 1)
171     {
172         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(blaster, refire)))
173         {
174             W_Blaster_Attack(
175                 actor,
176                 weaponentity,
177                 WEP_BLASTER.m_id,
178                 WEP_CVAR_PRI(blaster, shotangle),
179                 WEP_CVAR_PRI(blaster, damage),
180                 WEP_CVAR_PRI(blaster, edgedamage),
181                 WEP_CVAR_PRI(blaster, radius),
182                 WEP_CVAR_PRI(blaster, force),
183                 WEP_CVAR_PRI(blaster, speed),
184                 WEP_CVAR_PRI(blaster, spread),
185                 WEP_CVAR_PRI(blaster, delay),
186                 WEP_CVAR_PRI(blaster, lifetime)
187             );
188             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(blaster, animtime), w_ready);
189         }
190     }
191     else if(fire & 2)
192     {
193         switch(WEP_CVAR(blaster, secondary))
194         {
195             case 0: // switch to last used weapon
196             {
197                 if(PS(actor).m_switchweapon == WEP_BLASTER) // don't do this if already switching
198                     W_LastWeapon(actor);
199                 break;
200             }
201
202             case 1: // normal projectile secondary
203             {
204                 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(blaster, refire)))
205                 {
206                     W_Blaster_Attack(
207                         actor,
208                         weaponentity,
209                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
210                         WEP_CVAR_SEC(blaster, shotangle),
211                         WEP_CVAR_SEC(blaster, damage),
212                         WEP_CVAR_SEC(blaster, edgedamage),
213                         WEP_CVAR_SEC(blaster, radius),
214                         WEP_CVAR_SEC(blaster, force),
215                         WEP_CVAR_SEC(blaster, speed),
216                         WEP_CVAR_SEC(blaster, spread),
217                         WEP_CVAR_SEC(blaster, delay),
218                         WEP_CVAR_SEC(blaster, lifetime)
219                     );
220                     weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(blaster, animtime), w_ready);
221                 }
222
223                 break;
224             }
225         }
226     }
227 }
228
229 METHOD(Blaster, wr_setup, void(entity thiswep, entity actor))
230 {
231     actor.ammo_field = ammo_none;
232 }
233
234 METHOD(Blaster, wr_checkammo1, bool(entity thiswep, entity actor))
235 {
236     return true; // infinite ammo
237 }
238
239 METHOD(Blaster, wr_checkammo2, bool(entity thiswep, entity actor))
240 {
241     return true; // blaster has infinite ammo
242 }
243
244 METHOD(Blaster, wr_suicidemessage, Notification(entity thiswep))
245 {
246     return WEAPON_BLASTER_SUICIDE;
247 }
248
249 METHOD(Blaster, wr_killmessage, Notification(entity thiswep))
250 {
251     return WEAPON_BLASTER_MURDER;
252 }
253
254 #endif
255 #ifdef CSQC
256
257 METHOD(Blaster, wr_impacteffect, void(entity thiswep, entity actor))
258 {
259     vector org2;
260     org2 = w_org + w_backoff * 6;
261     pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
262     if(!w_issilent) { sound(actor, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM); }
263 }
264
265 #endif
266 #endif