Merge branch 'master' into samual/weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / wyvern.qc
1 #ifdef REGISTER_MONSTER
2 REGISTER_MONSTER(
3 /* MON_##id   */ WYVERN,
4 /* function   */ m_wyvern,
5 /* spawnflags */ MONSTER_TYPE_FLY | MONSTER_SIZE_BROKEN | MON_FLAG_RANGED,
6 /* mins,maxs  */ '-20 -20 -58', '20 20 20',
7 /* model      */ "wizard.mdl",
8 /* netname    */ "wyvern",
9 /* fullname   */ _("Wyvern")
10 );
11
12 #else
13 #ifdef SVQC
14 float autocvar_g_monster_wyvern_health;
15 float autocvar_g_monster_wyvern_attack_fireball_damage;
16 float autocvar_g_monster_wyvern_attack_fireball_edgedamage;
17 float autocvar_g_monster_wyvern_attack_fireball_damagetime;
18 float autocvar_g_monster_wyvern_attack_fireball_force;
19 float autocvar_g_monster_wyvern_attack_fireball_radius;
20 float autocvar_g_monster_wyvern_attack_fireball_speed;
21 float autocvar_g_monster_wyvern_speed_stop;
22 float autocvar_g_monster_wyvern_speed_run;
23 float autocvar_g_monster_wyvern_speed_walk;
24
25 const float wyvern_anim_hover   = 0;
26 const float wyvern_anim_fly             = 1;
27 const float wyvern_anim_magic   = 2;
28 const float wyvern_anim_pain    = 3;
29 const float wyvern_anim_death   = 4;
30
31 void wyvern_fireball_explode()
32 {
33         entity e;
34         if(self)
35         {
36                 pointparticles(particleeffectnum("fireball_explode"), self.origin, '0 0 0', 1);
37
38                 RadiusDamage(self, self.realowner, (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);
39
40                 for(e = world; (e = findfloat(e, takedamage, DAMAGE_AIM)); ) if(vlen(e.origin - self.origin) <= (autocvar_g_monster_wyvern_attack_fireball_radius))
41                         Fire_AddDamage(e, self, 5 * Monster_SkillModifier(), (autocvar_g_monster_wyvern_attack_fireball_damagetime), self.projectiledeathtype);
42
43                 remove(self);
44         }
45 }
46
47 void wyvern_fireball_touch()
48 {
49         PROJECTILE_TOUCH;
50
51         wyvern_fireball_explode();
52 }
53
54 void wyvern_fireball()
55 {
56         entity missile = spawn();
57         vector dir = normalize((self.enemy.origin + '0 0 10') - self.origin);
58
59         monster_makevectors(self.enemy);
60
61         missile.owner = missile.realowner = self;
62         missile.solid = SOLID_TRIGGER;
63         missile.movetype = MOVETYPE_FLYMISSILE;
64         missile.projectiledeathtype = DEATH_MONSTER_WYVERN;
65         setsize(missile, '-6 -6 -6', '6 6 6');
66         setorigin(missile, self.origin + self.view_ofs + v_forward * 14);
67         missile.flags = FL_PROJECTILE;
68         missile.velocity = dir * (autocvar_g_monster_wyvern_attack_fireball_speed);
69         missile.avelocity = '300 300 300';
70         missile.nextthink = time + 5;
71         missile.think = wyvern_fireball_explode;
72         missile.enemy = self.enemy;
73         missile.touch = wyvern_fireball_touch;
74         CSQCProjectile(missile, TRUE, PROJECTILE_FIREMINE, TRUE);
75 }
76
77 float wyvern_attack(float attack_type)
78 {
79         switch(attack_type)
80         {
81                 case MONSTER_ATTACK_MELEE:
82                 case MONSTER_ATTACK_RANGED:
83                 {
84                         self.attack_finished_single = time + 1.2;
85
86                         wyvern_fireball();
87
88                         return TRUE;
89                 }
90         }
91
92         return FALSE;
93 }
94
95 void spawnfunc_monster_wyvern()
96 {
97         self.classname = "monster_wyvern";
98
99         if(!monster_initialize(MON_WYVERN)) { remove(self); return; }
100 }
101
102 // compatibility with old spawns
103 void spawnfunc_monster_wizard() { spawnfunc_monster_wyvern(); }
104
105 float m_wyvern(float req)
106 {
107         switch(req)
108         {
109                 case MR_THINK:
110                 {
111                         monster_move((autocvar_g_monster_wyvern_speed_run), (autocvar_g_monster_wyvern_speed_walk), (autocvar_g_monster_wyvern_speed_stop), wyvern_anim_fly, wyvern_anim_hover, wyvern_anim_hover);
112                         return TRUE;
113                 }
114                 case MR_DEATH:
115                 {
116                         self.frame = wyvern_anim_death;
117                         self.velocity_x = -200 + 400 * random();
118                         self.velocity_y = -200 + 400 * random();
119                         self.velocity_z = 100 + 100 * random();
120                         return TRUE;
121                 }
122                 case MR_SETUP:
123                 {
124                         if(!self.health) self.health = (autocvar_g_monster_wyvern_health);
125
126                         self.monster_loot = spawnfunc_item_cells;
127                         self.monster_attackfunc = wyvern_attack;
128                         self.frame = wyvern_anim_hover;
129
130                         return TRUE;
131                 }
132                 case MR_PRECACHE:
133                 {
134                         precache_model("models/monsters/wizard.mdl");
135                         return TRUE;
136                 }
137         }
138
139         return TRUE;
140 }
141
142 #endif // SVQC
143 #ifdef CSQC
144 float m_wyvern(float req)
145 {
146         switch(req)
147         {
148                 case MR_PRECACHE:
149                 {
150                         return TRUE;
151                 }
152         }
153
154         return TRUE;
155 }
156
157 #endif // CSQC
158 #endif // REGISTER_MONSTER