29e9c2a570cd50ca532b6bcccef2ce20760edae1
[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         IL_PUSH(g_bot_dodge, missile);
144         missile.missile_flags = MIF_SPLASH;
145         missile.projectiledeathtype = atk_deathtype;
146         setthink(missile, W_Blaster_Think);
147         missile.nextthink = time + atk_delay;
148
149         MUTATOR_CALLHOOK(EditProjectile, actor, missile);
150
151         if (time >= missile.nextthink)
152         {
153                 getthink(missile)(missile);
154         }
155 }
156
157 METHOD(Blaster, wr_aim, void(entity thiswep, entity actor))
158 {
159     if(WEP_CVAR(blaster, secondary))
160     {
161         if((random() * (WEP_CVAR_PRI(blaster, damage) + WEP_CVAR_SEC(blaster, damage))) > WEP_CVAR_PRI(blaster, damage))
162             { PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, WEP_CVAR_SEC(blaster, speed), 0, WEP_CVAR_SEC(blaster, lifetime), false); }
163         else
164             { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, WEP_CVAR_PRI(blaster, speed), 0, WEP_CVAR_PRI(blaster, lifetime), false); }
165     }
166     else
167         { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, WEP_CVAR_PRI(blaster, speed), 0, WEP_CVAR_PRI(blaster, lifetime), false); }
168 }
169
170 METHOD(Blaster, wr_think, void(Blaster thiswep, entity actor, .entity weaponentity, int fire))
171 {
172     if(fire & 1)
173     {
174         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(blaster, refire)))
175         {
176             W_Blaster_Attack(
177                 actor,
178                 weaponentity,
179                 WEP_BLASTER.m_id,
180                 WEP_CVAR_PRI(blaster, shotangle),
181                 WEP_CVAR_PRI(blaster, damage),
182                 WEP_CVAR_PRI(blaster, edgedamage),
183                 WEP_CVAR_PRI(blaster, radius),
184                 WEP_CVAR_PRI(blaster, force),
185                 WEP_CVAR_PRI(blaster, speed),
186                 WEP_CVAR_PRI(blaster, spread),
187                 WEP_CVAR_PRI(blaster, delay),
188                 WEP_CVAR_PRI(blaster, lifetime)
189             );
190             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(blaster, animtime), w_ready);
191         }
192     }
193     else if(fire & 2)
194     {
195         switch(WEP_CVAR(blaster, secondary))
196         {
197             case 0: // switch to last used weapon
198             {
199                 if(actor.(weaponentity).m_switchweapon == WEP_BLASTER) // don't do this if already switching
200                     W_LastWeapon(actor, weaponentity);
201                 break;
202             }
203
204             case 1: // normal projectile secondary
205             {
206                 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(blaster, refire)))
207                 {
208                     W_Blaster_Attack(
209                         actor,
210                         weaponentity,
211                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
212                         WEP_CVAR_SEC(blaster, shotangle),
213                         WEP_CVAR_SEC(blaster, damage),
214                         WEP_CVAR_SEC(blaster, edgedamage),
215                         WEP_CVAR_SEC(blaster, radius),
216                         WEP_CVAR_SEC(blaster, force),
217                         WEP_CVAR_SEC(blaster, speed),
218                         WEP_CVAR_SEC(blaster, spread),
219                         WEP_CVAR_SEC(blaster, delay),
220                         WEP_CVAR_SEC(blaster, lifetime)
221                     );
222                     weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(blaster, animtime), w_ready);
223                 }
224
225                 break;
226             }
227         }
228     }
229 }
230
231 METHOD(Blaster, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
232 {
233     return true; // infinite ammo
234 }
235
236 METHOD(Blaster, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
237 {
238     return true; // blaster has infinite ammo
239 }
240
241 METHOD(Blaster, wr_suicidemessage, Notification(entity thiswep))
242 {
243     return WEAPON_BLASTER_SUICIDE;
244 }
245
246 METHOD(Blaster, wr_killmessage, Notification(entity thiswep))
247 {
248     return WEAPON_BLASTER_MURDER;
249 }
250
251 #endif
252 #ifdef CSQC
253
254 METHOD(Blaster, wr_impacteffect, void(entity thiswep, entity actor))
255 {
256     vector org2;
257     org2 = w_org + w_backoff * 6;
258     pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
259     if(!w_issilent) { sound(actor, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM); }
260 }
261
262 #endif
263 #endif