Hook: merge offhand and weapon behaviour
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / wyvern.qc
1 #ifndef WYVERN_H
2 #define WYVERN_H
3
4 #ifndef MENUQC
5 MODEL(MON_WYVERN, "models/monsters/wizard.mdl");
6 #endif
7
8 CLASS(Wyvern, Monster)
9     ATTRIB(Wyvern, spawnflags, int, MONSTER_TYPE_FLY | MONSTER_SIZE_BROKEN | MON_FLAG_RANGED | MON_FLAG_RIDE);
10     ATTRIB(Wyvern, mins, vector, '-20 -20 -58');
11     ATTRIB(Wyvern, maxs, vector, '20 20 20');
12 #ifndef MENUQC
13     ATTRIB(Wyvern, m_model, Model, MDL_MON_WYVERN);
14 #endif
15     ATTRIB(Wyvern, netname, string, "wyvern");
16     ATTRIB(Wyvern, monster_name, string, _("Wyvern"));
17 ENDCLASS(Wyvern)
18
19 REGISTER_MONSTER(WYVERN, NEW(Wyvern)) {
20 #ifndef MENUQC
21     this.mr_precache(this);
22 #endif
23 }
24
25 #include "../../weapons/all.qh"
26
27 CLASS(WyvernAttack, PortoLaunch)
28 /* flags     */ ATTRIB(WyvernAttack, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED);
29 /* impulse   */ ATTRIB(WyvernAttack, impulse, int, 9);
30 /* refname   */ ATTRIB(WyvernAttack, netname, string, "wyvern");
31 /* wepname   */ ATTRIB(WyvernAttack, message, string, _("Wyvern attack"));
32 ENDCLASS(WyvernAttack)
33 REGISTER_WEAPON(WYVERN_ATTACK, NEW(WyvernAttack));
34
35 #endif
36
37 #ifdef IMPLEMENTATION
38
39 #ifdef SVQC
40
41 float autocvar_g_monster_wyvern_attack_fireball_damage;
42 float autocvar_g_monster_wyvern_attack_fireball_edgedamage;
43 float autocvar_g_monster_wyvern_attack_fireball_damagetime;
44 float autocvar_g_monster_wyvern_attack_fireball_force;
45 float autocvar_g_monster_wyvern_attack_fireball_radius;
46 float autocvar_g_monster_wyvern_attack_fireball_speed;
47
48 void M_Wyvern_Attack_Fireball_Explode();
49 void M_Wyvern_Attack_Fireball_Touch();
50
51 METHOD(WyvernAttack, wr_think, void(WyvernAttack thiswep, entity actor, bool fire1, bool fire2)) {
52     if (fire1)
53     if (time > actor.attack_finished_single || weapon_prepareattack(thiswep, actor, false, 1.2)) {
54         if (IS_PLAYER(actor)) W_SetupShot_Dir(actor, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
55                 if (IS_MONSTER(actor)) {
56                         actor.attack_finished_single = time + 1.2;
57                         actor.anim_finished = time + 1.2;
58                         monster_makevectors(actor.enemy);
59                 }
60
61                 entity missile = spawn();
62                 missile.owner = missile.realowner = actor;
63                 missile.solid = SOLID_TRIGGER;
64                 missile.movetype = MOVETYPE_FLYMISSILE;
65                 missile.projectiledeathtype = DEATH_MONSTER_WYVERN;
66                 setsize(missile, '-6 -6 -6', '6 6 6');
67                 setorigin(missile, actor.origin + actor.view_ofs + v_forward * 14);
68                 missile.flags = FL_PROJECTILE;
69                 missile.velocity = w_shotdir * (autocvar_g_monster_wyvern_attack_fireball_speed);
70                 missile.avelocity = '300 300 300';
71                 missile.nextthink = time + 5;
72                 missile.think = M_Wyvern_Attack_Fireball_Explode;
73                 missile.touch = M_Wyvern_Attack_Fireball_Touch;
74                 CSQCProjectile(missile, true, PROJECTILE_FIREMINE, true);
75
76         weapon_thinkf(actor, WFRAME_FIRE1, 0, w_ready);
77     }
78 }
79
80 METHOD(WyvernAttack, wr_checkammo1, bool(WyvernAttack thiswep)) {
81         return true;
82 }
83
84 float autocvar_g_monster_wyvern_health;
85 float autocvar_g_monster_wyvern_damageforcescale = 0.6;
86 float autocvar_g_monster_wyvern_speed_stop;
87 float autocvar_g_monster_wyvern_speed_run;
88 float autocvar_g_monster_wyvern_speed_walk;
89
90 /*
91 const float wyvern_anim_hover   = 0;
92 const float wyvern_anim_fly             = 1;
93 const float wyvern_anim_magic   = 2;
94 const float wyvern_anim_pain    = 3;
95 const float wyvern_anim_death   = 4;
96 */
97
98 void M_Wyvern_Attack_Fireball_Explode()
99 {
100         SELFPARAM();
101         Send_Effect(EFFECT_FIREBALL_EXPLODE, self.origin, '0 0 0', 1);
102
103         entity owner = self.realowner;
104
105         RadiusDamage(self, owner, autocvar_g_monster_wyvern_attack_fireball_damage, autocvar_g_monster_wyvern_attack_fireball_edgedamage, autocvar_g_monster_wyvern_attack_fireball_force, world, world, autocvar_g_monster_wyvern_attack_fireball_radius, self.projectiledeathtype, world);
106
107         for (entity e = world; (e = findfloat(e, takedamage, DAMAGE_AIM)); )
108         if (vlen(e.origin - self.origin) <= (autocvar_g_monster_wyvern_attack_fireball_radius))
109                 Fire_AddDamage(e, owner, 5 * MONSTER_SKILLMOD(owner), (autocvar_g_monster_wyvern_attack_fireball_damagetime), self.projectiledeathtype);
110
111         remove(self);
112 }
113
114 void M_Wyvern_Attack_Fireball_Touch()
115 {
116         PROJECTILE_TOUCH;
117
118         M_Wyvern_Attack_Fireball_Explode();
119 }
120
121 float M_Wyvern_Attack(float attack_type, entity targ)
122 {
123         SELFPARAM();
124         switch(attack_type)
125         {
126                 case MONSTER_ATTACK_MELEE:
127                 case MONSTER_ATTACK_RANGED:
128                 {
129                         w_shotdir = normalize((self.enemy.origin + '0 0 10') - self.origin);
130                         Weapon wep = WEP_WYVERN_ATTACK;
131                         wep.wr_think(wep, self, true, false);
132                         return true;
133                 }
134         }
135
136         return false;
137 }
138
139 spawnfunc(monster_wyvern) { Monster_Spawn(MON_WYVERN.monsterid); }
140 #endif // SVQC
141
142                 #ifdef SVQC
143                 METHOD(Wyvern, mr_think, bool(Wyvern thismon))
144                 {
145                         return true;
146                 }
147                 METHOD(Wyvern, mr_pain, bool(Wyvern thismon))
148                 {
149                         SELFPARAM();
150                         self.pain_finished = time + 0.5;
151                         setanim(self, self.anim_pain1, true, true, false);
152                         return true;
153                 }
154                 METHOD(Wyvern, mr_death, bool(Wyvern thismon))
155                 {
156                         SELFPARAM();
157                         setanim(self, self.anim_die1, false, true, true);
158                         self.velocity_x = -200 + 400 * random();
159                         self.velocity_y = -200 + 400 * random();
160                         self.velocity_z = 100 + 100 * random();
161                         return true;
162                 }
163                 #endif
164                 #ifndef MENUQC
165                 METHOD(Wyvern, mr_anim, bool(Wyvern thismon))
166                 {
167                         SELFPARAM();
168                         vector none = '0 0 0';
169                         self.anim_die1 = animfixfps(self, '4 1 0.5', none); // 2 seconds
170                         self.anim_walk = animfixfps(self, '1 1 1', none);
171                         self.anim_idle = animfixfps(self, '0 1 1', none);
172                         self.anim_pain1 = animfixfps(self, '3 1 2', none); // 0.5 seconds
173                         self.anim_shoot = animfixfps(self, '2 1 5', none); // analyze models and set framerate
174                         self.anim_run = animfixfps(self, '1 1 1', none);
175
176                         return true;
177                 }
178                 #endif
179                 #ifdef SVQC
180                 METHOD(Wyvern, mr_setup, bool(Wyvern thismon))
181                 {
182                         SELFPARAM();
183                         if(!self.health) self.health = (autocvar_g_monster_wyvern_health);
184                         if(!self.speed) { self.speed = (autocvar_g_monster_wyvern_speed_walk); }
185                         if(!self.speed2) { self.speed2 = (autocvar_g_monster_wyvern_speed_run); }
186                         if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_wyvern_speed_stop); }
187                         if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_wyvern_damageforcescale); }
188
189                         self.monster_loot = spawnfunc_item_cells;
190                         self.monster_attackfunc = M_Wyvern_Attack;
191
192                         return true;
193                 }
194                 METHOD(Wyvern, mr_precache, bool(Wyvern thismon))
195                 {
196                         return true;
197                 }
198                 #endif
199
200 #endif