Fix MLRS and Hellion (animations and logic)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / units / unit_mlrs.qc
1 void spawnfunc_turret_mlrs();
2 void turret_mlrs_dinit();
3 void turret_mlrs_attack();
4 void turret_mlrs_rocket_explode();
5 void turret_mlrs_rocket_touch();
6
7 void turret_mlrs_postthink()
8 {
9     // 0 = full, 6 = empty
10     self.tur_head.frame = bound(0, 6 - floor(0.1 + self.ammo / self.shot_dmg), 6);
11     if(self.tur_head.frame < 0)
12     {
13         dprint("ammo:",ftos(self.ammo),"\n");
14         dprint("shot_dmg:",ftos(self.shot_dmg),"\n");
15     }
16     
17 }
18
19 void turret_mlrs_attack()
20 {
21     entity missile;
22
23     turret_tag_fire_update();
24
25     sound (self, CHAN_WEAPON, "weapons/rocket_fire.wav", VOL_BASE, ATTN_NORM);
26
27     missile                    = spawn ();
28     setsize (missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
29     setorigin(missile, self.tur_shotorg);
30     missile.classname          = "mlrs_missile";
31     missile.owner              = self;
32     missile.bot_dodge          = TRUE;
33     missile.bot_dodgerating    = self.shot_dmg;
34     missile.takedamage         = DAMAGE_NO;
35     missile.damageforcescale   = 4;
36     missile.think              = turret_mlrs_rocket_explode;
37     missile.nextthink          = time + max(self.tur_impacttime,(self.shot_radius * 2) / self.shot_speed);
38     missile.solid              = SOLID_BBOX;
39     missile.movetype           = MOVETYPE_FLYMISSILE;
40     missile.velocity           = normalize(self.tur_shotdir_updated + randomvec() * self.shot_spread) * self.shot_speed;
41     missile.angles             = vectoangles(missile.velocity);
42     missile.touch              = turret_mlrs_rocket_touch;
43     missile.flags              = FL_PROJECTILE;
44     missile.solid              = SOLID_BBOX;
45     missile.enemy              = self.enemy;
46
47         CSQCProjectile(missile, TRUE, PROJECTILE_ROCKET, FALSE); // no cull, fly sound
48
49     te_explosion (missile.origin);
50 }
51
52 void turret_mlrs_rocket_touch()
53 {
54     if( (other == self.owner) || (other == self.owner.tur_head) )
55         return;
56
57     PROJECTILE_TOUCH;
58
59     turret_mlrs_rocket_explode();
60 }
61
62 void turret_mlrs_rocket_explode()
63 {
64     vector org2;
65
66     if(self.event_damage != SUB_Null)
67     {
68         self.event_damage = SUB_Null;
69         self.think = turret_mlrs_rocket_explode;
70         self.nextthink = time;
71         return;
72     }
73
74
75     sound (self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
76     org2 = findbetterlocation (self.origin, 16);
77     pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
78     //w_deathtypestring = "dident escape the rocket barrage";
79 #ifdef TURRET_DEBUG
80     float d;
81
82     d = RadiusDamage (self, self.owner, self.owner.shot_dmg, 0, self.owner.shot_radius, world, self.owner.shot_force, DEATH_TURRET, world);
83     self.owner.tur_dbg_dmg_t_h = self.owner.tur_dbg_dmg_t_h + d; //self.owner.shot_dmg;
84     self.owner.tur_dbg_dmg_t_f = self.owner.tur_dbg_dmg_t_f + self.owner.shot_dmg;
85 #else
86     RadiusDamage (self, self.owner, self.owner.shot_dmg, self.owner.shot_dmg * 0.5, self.owner.shot_radius, world, self.owner.shot_force, DEATH_TURRET, world);
87 #endif
88
89     // Target dead, Tell turret.
90     if ((self.enemy.deadflag != DEAD_NO) && (self.enemy == self.owner.enemy))
91         self.owner.enemy = world;
92
93     remove (self);
94 }
95
96 void turret_mlrs_dinit()
97 {
98     if (self.netname == "")      self.netname  = "MLRS turret";
99
100     self.turrcaps_flags = TFL_TURRCAPS_RADIUSDMG | TFL_TURRCAPS_MEDPROJ | TFL_TURRCAPS_PLAYERKILL;
101     self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;
102     self.aim_flags = TFL_AIM_LEAD | TFL_AIM_SHOTTIMECOMPENSATE;// | TFL_AIM_GROUND2;
103
104     if (turret_stdproc_init("mlrs_std",0,"models/turrets/base.md3","models/turrets/mlrs.md3") == 0)
105     {
106         remove(self);
107         return;
108     }
109
110     self.damage_flags |= TFL_DMG_HEADSHAKE;
111     self.shoot_flags  |= TFL_SHOOT_VOLLYALWAYS;
112     self.volly_counter = self.shot_volly;
113
114     if (!turret_tag_fire_update())
115         dprint("Warning: Turret ",self.classname, " faild to initialize md3 tags\n");
116
117     // Our fire routine
118     self.turret_firefunc  = turret_mlrs_attack;
119     self.turret_postthink = turret_mlrs_postthink;
120
121 }
122
123 /*QUAKED turret_mlrs (0 .5 .8) ?
124 */
125
126 void spawnfunc_turret_mlrs()
127 {
128     precache_model ("models/turrets/mlrs.md3");
129     precache_model ("models/turrets/base.md3");
130
131     self.think = turret_mlrs_dinit;
132     self.nextthink = time + 0.5;
133 }
134
135