]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/spider.qc
Propagate sound references
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / spider.qc
1 #ifndef SPIDER_H
2 #define SPIDER_H
3
4 #ifndef MENUQC
5 MODEL(MON_SPIDER, M_Model("spider.dpm"));
6 #endif
7
8 CLASS(Spider, Monster)
9     ATTRIB(Spider, spawnflags, int, MON_FLAG_MELEE | MON_FLAG_RANGED | MON_FLAG_RIDE);
10     ATTRIB(Spider, mins, vector, '-18 -18 -25');
11     ATTRIB(Spider, maxs, vector, '18 18 30');
12 #ifndef MENUQC
13     ATTRIB(Spider, m_model, Model, MDL_MON_SPIDER);
14 #endif
15     ATTRIB(Spider, netname, string, "spider");
16     ATTRIB(Spider, monster_name, string, _("Spider"));
17 ENDCLASS(Spider)
18
19 REGISTER_MONSTER(SPIDER, NEW(Spider)) {
20 #ifndef MENUQC
21     this.mr_precache(this);
22 #endif
23 }
24
25 #include <common/weapons/all.qh>
26
27 CLASS(SpiderAttack, PortoLaunch)
28 /* flags     */ ATTRIB(SpiderAttack, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED);
29 /* impulse   */ ATTRIB(SpiderAttack, impulse, int, 9);
30 /* refname   */ ATTRIB(SpiderAttack, netname, string, "spider");
31 /* wepname   */ ATTRIB(SpiderAttack, m_name, string, _("Spider attack"));
32 ENDCLASS(SpiderAttack)
33 REGISTER_WEAPON(SPIDER_ATTACK, NEW(SpiderAttack));
34
35 #endif
36
37 #ifdef IMPLEMENTATION
38
39 #ifdef SVQC
40
41 .float spider_slowness; // effect time of slowness inflicted by spiders
42
43 .float spider_web_delay;
44
45 float autocvar_g_monster_spider_attack_web_damagetime;
46 float autocvar_g_monster_spider_attack_web_speed;
47 float autocvar_g_monster_spider_attack_web_speed_up;
48 float autocvar_g_monster_spider_attack_web_delay;
49
50 float autocvar_g_monster_spider_attack_bite_damage;
51 float autocvar_g_monster_spider_attack_bite_delay;
52
53 void M_Spider_Attack_Web(entity this);
54
55 REGISTER_MUTATOR(spiderweb, true);
56
57 MUTATOR_HOOKFUNCTION(spiderweb, PlayerPhysics)
58 {
59         if (time >= self.spider_slowness)
60                 return false;
61         PHYS_MAXSPEED(self) *= 0.5; // half speed while slow from spider
62         PHYS_MAXAIRSPEED(self) *= 0.5;
63         PHYS_AIRSPEEDLIMIT_NONQW(self) *= 0.5;
64         PHYS_AIRSTRAFEACCELERATE(self) *= 0.5;
65         return false;
66 }
67
68 MUTATOR_HOOKFUNCTION(spiderweb, MonsterMove)
69 {
70         if(time < self.spider_slowness)
71         {
72                 monster_speed_run *= 0.5;
73                 monster_speed_walk *= 0.5;
74         }
75         return false;
76 }
77
78 MUTATOR_HOOKFUNCTION(spiderweb, PlayerSpawn)
79 {
80         self.spider_slowness = 0;
81         return false;
82 }
83
84 MUTATOR_HOOKFUNCTION(spiderweb, MonsterSpawn)
85 {
86         self.spider_slowness = 0;
87         return false;
88 }
89
90 SOUND(SpiderAttack_FIRE, W_Sound("electro_fire"));
91 METHOD(SpiderAttack, wr_think, void(SpiderAttack thiswep, entity actor, .entity weaponentity, int fire))
92 {
93     TC(SpiderAttack, thiswep);
94     bool isPlayer = IS_PLAYER(actor);
95     if (fire & 1)
96     if ((!isPlayer && time >= actor.spider_web_delay) || weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_monster_spider_attack_web_delay)) {
97                 if (!isPlayer) {
98                         actor.spider_web_delay = time + 3;
99                         setanim(actor, actor.anim_shoot, true, true, true);
100                         actor.attack_finished_single[0] = time + (autocvar_g_monster_spider_attack_web_delay);
101                         actor.anim_finished = time + 1;
102                 }
103         if (isPlayer) actor.enemy = Monster_FindTarget(actor);
104         W_SetupShot_Dir(actor, v_forward, false, 0, SND_SpiderAttack_FIRE, CH_WEAPON_B, 0);
105         if (!isPlayer) w_shotdir = normalize((actor.enemy.origin + '0 0 10') - actor.origin);
106                 M_Spider_Attack_Web(actor);
107         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready);
108         return;
109     }
110     if (fire & 2)
111     if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, true, 0.5)) {
112         if (isPlayer) {
113                 actor.enemy = Monster_FindTarget(actor);
114                 actor.attack_range = 60;
115         }
116         Monster_Attack_Melee(actor, actor.enemy, (autocvar_g_monster_spider_attack_bite_damage), ((random() > 0.5) ? self.anim_melee : self.anim_shoot), self.attack_range, (autocvar_g_monster_spider_attack_bite_delay), DEATH_MONSTER_SPIDER.m_id, true);
117         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready);
118     }
119 }
120
121 float autocvar_g_monster_spider_health;
122 float autocvar_g_monster_spider_damageforcescale = 0.6;
123 float autocvar_g_monster_spider_speed_stop;
124 float autocvar_g_monster_spider_speed_run;
125 float autocvar_g_monster_spider_speed_walk;
126
127 /*
128 const float spider_anim_idle            = 0;
129 const float spider_anim_walk            = 1;
130 const float spider_anim_attack          = 2;
131 const float spider_anim_attack2         = 3;
132 */
133
134 void M_Spider_Attack_Web_Explode()
135 {SELFPARAM();
136         entity e;
137         if(self)
138         {
139                 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
140                 RadiusDamage(self, self.realowner, 0, 0, 25, world, world, 25, self.projectiledeathtype, world);
141
142                 for(e = findradius(self.origin, 25); e; e = e.chain) if(e != self) if(e.takedamage && !IS_DEAD(e)) if(e.health > 0) if(e.monsterid != MON_SPIDER.monsterid)
143                         e.spider_slowness = time + (autocvar_g_monster_spider_attack_web_damagetime);
144
145                 remove(self);
146         }
147 }
148
149 void M_Spider_Attack_Web_Touch()
150 {
151         PROJECTILE_TOUCH;
152
153         M_Spider_Attack_Web_Explode();
154 }
155
156 void adaptor_think2use_hittype_splash();
157
158 void M_Spider_Attack_Web(entity this)
159 {
160         monster_makevectors(this, this.enemy);
161
162         sound(this, CH_SHOTS, SND_ELECTRO_FIRE2, VOL_BASE, ATTEN_NORM);
163
164         entity proj = new(plasma);
165         proj.owner = proj.realowner = this;
166         proj.use = M_Spider_Attack_Web_Explode;
167         proj.think = adaptor_think2use_hittype_splash;
168         proj.bot_dodge = true;
169         proj.bot_dodgerating = 0;
170         proj.nextthink = time + 5;
171         PROJECTILE_MAKETRIGGER(proj);
172         proj.projectiledeathtype = DEATH_MONSTER_SPIDER.m_id;
173         setorigin(proj, CENTER_OR_VIEWOFS(this));
174
175         //proj.glow_size = 50;
176         //proj.glow_color = 45;
177         proj.movetype = MOVETYPE_BOUNCE;
178         W_SetupProjVelocity_Explicit(proj, v_forward, v_up, (autocvar_g_monster_spider_attack_web_speed), (autocvar_g_monster_spider_attack_web_speed_up), 0, 0, false);
179         proj.touch = M_Spider_Attack_Web_Touch;
180         setsize(proj, '-4 -4 -4', '4 4 4');
181         proj.takedamage = DAMAGE_NO;
182         proj.damageforcescale = 0;
183         proj.health = 500;
184         proj.event_damage = func_null;
185         proj.flags = FL_PROJECTILE;
186         proj.damagedbycontents = true;
187
188         proj.bouncefactor = 0.3;
189         proj.bouncestop = 0.05;
190         proj.missile_flags = MIF_SPLASH | MIF_ARC;
191
192         CSQCProjectile(proj, true, PROJECTILE_ELECTRO, true);
193 }
194
195 bool M_Spider_Attack(int attack_type, entity actor, entity targ)
196 {
197     .entity weaponentity = weaponentities[0];
198         switch(attack_type)
199         {
200                 Weapon wep = WEP_SPIDER_ATTACK;
201                 case MONSTER_ATTACK_MELEE:
202                 {
203                         wep.wr_think(wep, actor, weaponentity, 2);
204                         return true;
205                 }
206                 case MONSTER_ATTACK_RANGED:
207                 {
208                         wep.wr_think(wep, actor, weaponentity, 1);
209                         return true;
210                 }
211         }
212
213         return false;
214 }
215
216 spawnfunc(monster_spider) { Monster_Spawn(this, MON_SPIDER.monsterid); }
217 #endif // SVQC
218
219 #ifdef SVQC
220 METHOD(Spider, mr_think, bool(Spider this, entity actor))
221 {
222     TC(Spider, this);
223     return true;
224 }
225
226 METHOD(Spider, mr_pain, bool(Spider this, entity actor))
227 {
228     TC(Spider, this);
229     return true;
230 }
231
232 METHOD(Spider, mr_death, bool(Spider this, entity actor))
233 {
234     TC(Spider, this);
235     setanim(actor, actor.anim_melee, false, true, true);
236     actor.angles_x = 180;
237     return true;
238 }
239 #endif
240 #ifndef MENUQC
241 METHOD(Spider, mr_anim, bool(Spider this, entity actor))
242 {
243     TC(Spider, this);
244     vector none = '0 0 0';
245     actor.anim_walk = animfixfps(actor, '1 1 1', none);
246     actor.anim_idle = animfixfps(actor, '0 1 1', none);
247     actor.anim_melee = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
248     actor.anim_shoot = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
249     actor.anim_run = animfixfps(actor, '1 1 1', none);
250     return true;
251 }
252 #endif
253 #ifdef SVQC
254 spawnfunc(item_health_medium);
255 METHOD(Spider, mr_setup, bool(Spider this, entity actor))
256 {
257     TC(Spider, this);
258     if(!actor.health) actor.health = (autocvar_g_monster_spider_health);
259     if(!actor.speed) { actor.speed = (autocvar_g_monster_spider_speed_walk); }
260     if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_spider_speed_run); }
261     if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_spider_speed_stop); }
262     if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_spider_damageforcescale); }
263
264     actor.monster_loot = spawnfunc_item_health_medium;
265     actor.monster_attackfunc = M_Spider_Attack;
266
267     return true;
268 }
269
270 METHOD(Spider, mr_precache, bool(Spider this))
271 {
272     TC(Spider, this);
273     return true;
274 }
275 #endif
276
277 #endif