]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/vehicle/raptor_weapons.qc
Merge branch 'master' into terencehill/translate_colors_2
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle / raptor_weapons.qc
1 #include "raptor_weapons.qh"
2
3 #ifdef IMPLEMENTATION
4
5 #ifdef SVQC
6
7 METHOD(RaptorCannon, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) {
8     bool isPlayer = IS_PLAYER(actor);
9     entity player = isPlayer ? actor : actor.owner;
10     entity veh = player.vehicle;
11     // 1 [wait] 1 [wait] 2 [wait] 2 [wait] [wait]
12     float t = autocvar_g_vehicle_raptor_cannon_refire * (1 + veh.misc_bulletcounter == 4);
13     if (fire & 1)
14     if (weapon_prepareattack(thiswep, player, weaponentity, false, t)) {
15         if (isPlayer) W_SetupShot_Dir(player, v_forward, false, 0, SND_Null, CH_WEAPON_B, 0);
16         vector org = w_shotorg;
17         vector dir = w_shotdir;
18         if (veh) {
19             veh.misc_bulletcounter += 1;
20             org = (veh.misc_bulletcounter <= 2) ? gettaginfo(veh.gun1, gettagindex(veh.gun1, "fire1"))
21               : (((veh.misc_bulletcounter == 4) ? veh.misc_bulletcounter = 0 : 0), gettaginfo(veh.gun2, gettagindex(veh.gun2, "fire1")));
22             dir = v_forward;
23             veh.vehicle_energy -= autocvar_g_vehicle_raptor_cannon_cost;
24             actor.cnt = time;
25         }
26         vehicles_projectile(veh, EFFECT_RAPTOR_MUZZLEFLASH.eent_eff_name, SND_LASERGUN_FIRE,
27                                org, normalize(dir + randomvec() * autocvar_g_vehicle_raptor_cannon_spread) * autocvar_g_vehicle_raptor_cannon_speed,
28                                autocvar_g_vehicle_raptor_cannon_damage, autocvar_g_vehicle_raptor_cannon_radius, autocvar_g_vehicle_raptor_cannon_force,  0,
29                                DEATH_VH_RAPT_CANNON.m_id, PROJECTILE_RAPTORCANNON, 0, true, true, player);
30         weapon_thinkf(player, weaponentity, WFRAME_FIRE1, 0, w_ready);
31     }
32 }
33 METHOD(RaptorCannon, wr_checkammo1, bool(RacerAttack thiswep)) {
34     SELFPARAM();
35     bool isPlayer = IS_PLAYER(self);
36     entity player = isPlayer ? self : self.owner;
37     entity veh = player.vehicle;
38     return isPlayer || veh.vehicle_energy >= autocvar_g_vehicle_raptor_cannon_cost;
39 }
40
41
42 void raptor_bombdrop();
43 METHOD(RaptorBomb, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) {
44     bool isPlayer = IS_PLAYER(actor);
45     entity player = isPlayer ? actor : actor.owner;
46     entity veh = player.vehicle;
47     if (fire & 2)
48     if (!isPlayer || weapon_prepareattack(thiswep, player, weaponentity, true, autocvar_g_vehicle_raptor_bombs_refire)) {
49         if (veh) setself(veh);
50         raptor_bombdrop();
51         weapon_thinkf(player, weaponentity, WFRAME_FIRE2, 0, w_ready);
52     }
53 }
54
55 void raptor_flare_think();
56 void raptor_flare_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force);
57 void raptor_flare_touch();
58
59 METHOD(RaptorFlare, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) {
60     bool isPlayer = IS_PLAYER(actor);
61     entity player = isPlayer ? actor : actor.owner;
62     entity veh = player.vehicle;
63     if (fire & 2)
64     if (!isPlayer || weapon_prepareattack(thiswep, player, weaponentity, true, autocvar_g_vehicle_raptor_flare_refire)) {
65         for(int i = 0; i < 3; ++i) {
66             entity _flare = spawn();
67             setmodel(_flare, MDL_VEH_RAPTOR_FLARE);
68             _flare.effects = EF_LOWPRECISION | EF_FLAME;
69             _flare.scale = 0.5;
70             setorigin(_flare, actor.origin - '0 0 16');
71             _flare.movetype = MOVETYPE_TOSS;
72             _flare.gravity = 0.15;
73             _flare.velocity = 0.25 * actor.velocity + (v_forward + randomvec() * 0.25)* -500;
74             _flare.think = raptor_flare_think;
75             _flare.nextthink = time;
76             _flare.owner = veh ? veh : player;
77             _flare.solid = SOLID_CORPSE;
78             _flare.takedamage = DAMAGE_YES;
79             _flare.event_damage = raptor_flare_damage;
80             _flare.health = 20;
81             _flare.tur_impacttime = time + autocvar_g_vehicle_raptor_flare_lifetime;
82             _flare.touch = raptor_flare_touch;
83         }
84         weapon_thinkf(player, weaponentity, WFRAME_FIRE2, 0, w_ready);
85     }
86 }
87
88
89 void raptor_bomblet_boom()
90 {SELFPARAM();
91     RadiusDamage (self, self.realowner, autocvar_g_vehicle_raptor_bomblet_damage,
92                                     autocvar_g_vehicle_raptor_bomblet_edgedamage,
93                                     autocvar_g_vehicle_raptor_bomblet_radius, world, world,
94                                     autocvar_g_vehicle_raptor_bomblet_force, DEATH_VH_RAPT_BOMB.m_id, world);
95     remove(self);
96 }
97
98 void raptor_bomblet_touch()
99 {SELFPARAM();
100     if(other == self.owner)
101         return;
102
103     PROJECTILE_TOUCH;
104     self.think = raptor_bomblet_boom;
105     self.nextthink = time + random() * autocvar_g_vehicle_raptor_bomblet_explode_delay;
106 }
107
108 void raptor_bomb_burst()
109 {SELFPARAM();
110     if(self.cnt > time)
111     if(autocvar_g_vehicle_raptor_bomblet_alt)
112     {
113         self.nextthink = time;
114         traceline(self.origin, self.origin + (normalize(self.velocity) * autocvar_g_vehicle_raptor_bomblet_alt), MOVE_NORMAL, self);
115         if((trace_fraction == 1.0) || (vdist(self.origin - self.owner.origin, <, autocvar_g_vehicle_raptor_bomblet_radius)))
116         {
117             UpdateCSQCProjectile(self);
118             return;
119         }
120     }
121
122     entity bomblet;
123     float i;
124
125     Damage_DamageInfo(self.origin, 0, 0, 0, '0 0 0', DEATH_VH_RAPT_FRAGMENT.m_id, 0, self);
126
127     for(i = 0; i < autocvar_g_vehicle_raptor_bomblets; ++i)
128     {
129         bomblet = spawn();
130         setorigin(bomblet, self.origin);
131
132         bomblet.movetype        = MOVETYPE_TOSS;
133         bomblet.touch      = raptor_bomblet_touch;
134         bomblet.think      = raptor_bomblet_boom;
135         bomblet.nextthink   = time + 5;
136         bomblet.owner      = self.owner;
137         bomblet.realowner   = self.realowner;
138         bomblet.velocity        = normalize(normalize(self.velocity) + (randomvec() * autocvar_g_vehicle_raptor_bomblet_spread)) * vlen(self.velocity);
139
140         PROJECTILE_MAKETRIGGER(bomblet);
141         CSQCProjectile(bomblet, true, PROJECTILE_RAPTORBOMBLET, true);
142     }
143
144     remove(self);
145 }
146
147 void raptor_bombdrop()
148 {SELFPARAM();
149     entity bomb_1, bomb_2;
150
151     bomb_1 = spawn();
152     bomb_2 = spawn();
153
154     vector org = gettaginfo(self, gettagindex(self, "bombmount_left"));
155     setorigin(bomb_1, org);
156     org = gettaginfo(self, gettagindex(self, "bombmount_right"));
157     setorigin(bomb_2, org);
158
159     bomb_1.movetype      = bomb_2.movetype   = MOVETYPE_BOUNCE;
160     bomb_1.velocity      = bomb_2.velocity   = self.velocity;
161     bomb_1.touch                = bomb_2.touch    = raptor_bomb_burst;
162     bomb_1.think                = bomb_2.think    = raptor_bomb_burst;
163     bomb_1.cnt            = bomb_2.cnt          = time + 10;
164
165     if(autocvar_g_vehicle_raptor_bomblet_alt)
166         bomb_1.nextthink = bomb_2.nextthink  = time;
167     else
168         bomb_1.nextthink = bomb_2.nextthink  = time + autocvar_g_vehicle_raptor_bomblet_time;
169
170     bomb_1.owner         = bomb_2.owner   = self;
171     bomb_1.realowner = bomb_2.realowner  = self.owner;
172     bomb_1.solid         = bomb_2.solid   = SOLID_BBOX;
173     bomb_1.gravity   = bomb_2.gravity   = 1;
174
175     PROJECTILE_MAKETRIGGER(bomb_1);
176     PROJECTILE_MAKETRIGGER(bomb_2);
177
178     CSQCProjectile(bomb_1, true, PROJECTILE_RAPTORBOMB, true);
179     CSQCProjectile(bomb_2, true, PROJECTILE_RAPTORBOMB, true);
180 }
181
182 void raptor_flare_touch()
183 {SELFPARAM();
184     remove(self);
185 }
186
187 void raptor_flare_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
188 {
189     this.health -= damage;
190     if(this.health <= 0)
191         remove(this);
192 }
193
194 void raptor_flare_think()
195 {SELFPARAM();
196     self.nextthink = time + 0.1;
197     entity _missile = findchainentity(enemy, self.owner);
198     while(_missile)
199     {
200         if(_missile.flags & FL_PROJECTILE)
201         if(vdist(self.origin - _missile.origin, <, autocvar_g_vehicle_raptor_flare_range))
202         if(random() > autocvar_g_vehicle_raptor_flare_chase)
203             _missile.enemy = self;
204         _missile = _missile.chain;
205     }
206
207     if(self.tur_impacttime < time)
208         remove(self);
209 }
210
211 #endif
212
213 #ifdef CSQC
214
215 void RaptorCBShellfragDraw(entity this)
216 {
217     if(wasfreed(this))
218         return;
219
220     Movetype_Physics_MatchTicrate(this, autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
221     this.move_avelocity += randomvec() * 15;
222     this.renderflags = 0;
223
224     if(this.cnt < time)
225         this.alpha = bound(0, this.nextthink - time, 1);
226
227     if(this.alpha < ALPHA_MIN_VISIBLE)
228         remove(this);
229 }
230
231 void RaptorCBShellfragToss(vector _org, vector _vel, vector _ang)
232 {SELFPARAM();
233     entity sfrag;
234
235     sfrag = spawn();
236     setmodel(sfrag, MDL_VEH_RAPTOR_CB_FRAGMENT);
237     setorigin(sfrag, _org);
238
239     sfrag.move_movetype = MOVETYPE_BOUNCE;
240     sfrag.gravity = 0.15;
241     sfrag.solid = SOLID_CORPSE;
242
243     sfrag.draw = RaptorCBShellfragDraw;
244
245     sfrag.move_origin = sfrag.origin = _org;
246     sfrag.move_velocity = _vel;
247     sfrag.move_avelocity = prandomvec() * vlen(sfrag.move_velocity);
248     sfrag.angles = self.move_angles = _ang;
249
250     sfrag.move_time = time;
251     sfrag.damageforcescale = 4;
252
253     sfrag.nextthink = time + 3;
254     sfrag.cnt = time + 2;
255     sfrag.alpha = 1;
256     sfrag.drawmask = MASK_NORMAL;
257 }
258
259 #endif
260
261 #endif