7474150cc78903d3b1c30e2defed4fdb57ed5326
[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     MON_ACTION(this, MR_PRECACHE);
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);
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, bool(WyvernAttack thiswep, bool fire1, bool fire2)) {
52     SELFPARAM();
53
54     if (fire1)
55     if (time > self.attack_finished_single || weapon_prepareattack(false, 1.2)) {
56         if (IS_PLAYER(self)) W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
57                 if (IS_MONSTER(self)) {
58                         self.attack_finished_single = time + 1.2;
59                         self.anim_finished = time + 1.2;
60                         monster_makevectors(self.enemy);
61                 }
62
63                 entity missile = spawn();
64                 missile.owner = missile.realowner = self;
65                 missile.solid = SOLID_TRIGGER;
66                 missile.movetype = MOVETYPE_FLYMISSILE;
67                 missile.projectiledeathtype = DEATH_MONSTER_WYVERN;
68                 setsize(missile, '-6 -6 -6', '6 6 6');
69                 setorigin(missile, self.origin + self.view_ofs + v_forward * 14);
70                 missile.flags = FL_PROJECTILE;
71                 missile.velocity = w_shotdir * (autocvar_g_monster_wyvern_attack_fireball_speed);
72                 missile.avelocity = '300 300 300';
73                 missile.nextthink = time + 5;
74                 missile.think = M_Wyvern_Attack_Fireball_Explode;
75                 missile.touch = M_Wyvern_Attack_Fireball_Touch;
76                 CSQCProjectile(missile, true, PROJECTILE_FIREMINE, true);
77
78         weapon_thinkf(WFRAME_FIRE1, 0, w_ready);
79         return true;
80     }
81     return true;
82 }
83
84 METHOD(WyvernAttack, wr_checkammo1, bool(WyvernAttack thiswep)) {
85         return true;
86 }
87
88 float autocvar_g_monster_wyvern_health;
89 float autocvar_g_monster_wyvern_damageforcescale = 0.6;
90 float autocvar_g_monster_wyvern_speed_stop;
91 float autocvar_g_monster_wyvern_speed_run;
92 float autocvar_g_monster_wyvern_speed_walk;
93
94 /*
95 const float wyvern_anim_hover   = 0;
96 const float wyvern_anim_fly             = 1;
97 const float wyvern_anim_magic   = 2;
98 const float wyvern_anim_pain    = 3;
99 const float wyvern_anim_death   = 4;
100 */
101
102 void M_Wyvern_Attack_Fireball_Explode()
103 {
104         SELFPARAM();
105         Send_Effect(EFFECT_FIREBALL_EXPLODE, self.origin, '0 0 0', 1);
106
107         entity owner = self.realowner;
108
109         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);
110
111         for (entity e = world; (e = findfloat(e, takedamage, DAMAGE_AIM)); )
112         if (vlen(e.origin - self.origin) <= (autocvar_g_monster_wyvern_attack_fireball_radius))
113                 Fire_AddDamage(e, owner, 5 * MONSTER_SKILLMOD(owner), (autocvar_g_monster_wyvern_attack_fireball_damagetime), self.projectiledeathtype);
114
115         remove(self);
116 }
117
118 void M_Wyvern_Attack_Fireball_Touch()
119 {
120         PROJECTILE_TOUCH;
121
122         M_Wyvern_Attack_Fireball_Explode();
123 }
124
125 float M_Wyvern_Attack(float attack_type, entity targ)
126 {
127         SELFPARAM();
128         switch(attack_type)
129         {
130                 case MONSTER_ATTACK_MELEE:
131                 case MONSTER_ATTACK_RANGED:
132                 {
133                         w_shotdir = normalize((self.enemy.origin + '0 0 10') - self.origin);
134                         Weapon wep = WEP_WYVERN_ATTACK;
135                         wep.wr_think(wep, true, false);
136                         return true;
137                 }
138         }
139
140         return false;
141 }
142
143 void spawnfunc_monster_wyvern() { Monster_Spawn(MON_WYVERN.monsterid); }
144 #endif // SVQC
145
146                 #ifdef SVQC
147                 METHOD(Wyvern, mr_think, bool(Wyvern thismon))
148                 {
149                         return true;
150                 }
151                 METHOD(Wyvern, mr_pain, bool(Wyvern thismon))
152                 {
153                         SELFPARAM();
154                         self.pain_finished = time + 0.5;
155                         setanim(self, self.anim_pain1, true, true, false);
156                         return true;
157                 }
158                 METHOD(Wyvern, mr_death, bool(Wyvern thismon))
159                 {
160                         SELFPARAM();
161                         setanim(self, self.anim_die1, false, true, true);
162                         self.velocity_x = -200 + 400 * random();
163                         self.velocity_y = -200 + 400 * random();
164                         self.velocity_z = 100 + 100 * random();
165                         return true;
166                 }
167                 #endif
168                 #ifndef MENUQC
169                 METHOD(Wyvern, mr_anim, bool(Wyvern thismon))
170                 {
171                         SELFPARAM();
172                         vector none = '0 0 0';
173                         self.anim_die1 = animfixfps(self, '4 1 0.5', none); // 2 seconds
174                         self.anim_walk = animfixfps(self, '1 1 1', none);
175                         self.anim_idle = animfixfps(self, '0 1 1', none);
176                         self.anim_pain1 = animfixfps(self, '3 1 2', none); // 0.5 seconds
177                         self.anim_shoot = animfixfps(self, '2 1 5', none); // analyze models and set framerate
178                         self.anim_run = animfixfps(self, '1 1 1', none);
179
180                         return true;
181                 }
182                 #endif
183                 #ifdef SVQC
184                 METHOD(Wyvern, mr_setup, bool(Wyvern thismon))
185                 {
186                         SELFPARAM();
187                         if(!self.health) self.health = (autocvar_g_monster_wyvern_health);
188                         if(!self.speed) { self.speed = (autocvar_g_monster_wyvern_speed_walk); }
189                         if(!self.speed2) { self.speed2 = (autocvar_g_monster_wyvern_speed_run); }
190                         if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_wyvern_speed_stop); }
191                         if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_wyvern_damageforcescale); }
192
193                         self.monster_loot = spawnfunc_item_cells;
194                         self.monster_attackfunc = M_Wyvern_Attack;
195
196                         return true;
197                 }
198                 METHOD(Wyvern, mr_precache, bool(Wyvern thismon))
199                 {
200                         return true;
201                 }
202                 #endif
203
204 #endif