]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/spider.qc
c477d3ea66718b6f3cb70d86fc93ee243b268928
[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     SELFPARAM();
60         if (time >= this.spider_slowness)
61                 return false;
62         PHYS_MAXSPEED(this) *= 0.5; // half speed while slow from spider
63         PHYS_MAXAIRSPEED(this) *= 0.5;
64         PHYS_AIRSPEEDLIMIT_NONQW(this) *= 0.5;
65         PHYS_AIRSTRAFEACCELERATE(this) *= 0.5;
66         return false;
67 }
68
69 MUTATOR_HOOKFUNCTION(spiderweb, MonsterMove)
70 {
71     SELFPARAM();
72         if(time < self.spider_slowness)
73         {
74                 monster_speed_run *= 0.5;
75                 monster_speed_walk *= 0.5;
76         }
77         return false;
78 }
79
80 MUTATOR_HOOKFUNCTION(spiderweb, PlayerSpawn)
81 {
82     SELFPARAM();
83         self.spider_slowness = 0;
84         return false;
85 }
86
87 MUTATOR_HOOKFUNCTION(spiderweb, MonsterSpawn)
88 {
89     SELFPARAM();
90         self.spider_slowness = 0;
91         return false;
92 }
93
94 SOUND(SpiderAttack_FIRE, W_Sound("electro_fire"));
95 METHOD(SpiderAttack, wr_think, void(SpiderAttack thiswep, entity actor, .entity weaponentity, int fire))
96 {
97     SELFPARAM();
98     TC(SpiderAttack, thiswep);
99     bool isPlayer = IS_PLAYER(actor);
100     if (fire & 1)
101     if ((!isPlayer && time >= actor.spider_web_delay) || weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_monster_spider_attack_web_delay)) {
102                 if (!isPlayer) {
103                         actor.spider_web_delay = time + 3;
104                         setanim(actor, actor.anim_shoot, true, true, true);
105                         actor.attack_finished_single[0] = time + (autocvar_g_monster_spider_attack_web_delay);
106                         actor.anim_finished = time + 1;
107                 }
108         if (isPlayer) actor.enemy = Monster_FindTarget(actor);
109         W_SetupShot_Dir(actor, v_forward, false, 0, SND_SpiderAttack_FIRE, CH_WEAPON_B, 0);
110         if (!isPlayer) w_shotdir = normalize((actor.enemy.origin + '0 0 10') - actor.origin);
111                 M_Spider_Attack_Web(actor);
112         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready);
113         return;
114     }
115     if (fire & 2)
116     if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, true, 0.5)) {
117         if (isPlayer) {
118                 actor.enemy = Monster_FindTarget(actor);
119                 actor.attack_range = 60;
120         }
121         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);
122         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready);
123     }
124 }
125
126 float autocvar_g_monster_spider_health;
127 float autocvar_g_monster_spider_damageforcescale = 0.6;
128 float autocvar_g_monster_spider_speed_stop;
129 float autocvar_g_monster_spider_speed_run;
130 float autocvar_g_monster_spider_speed_walk;
131
132 /*
133 const float spider_anim_idle            = 0;
134 const float spider_anim_walk            = 1;
135 const float spider_anim_attack          = 2;
136 const float spider_anim_attack2         = 3;
137 */
138
139 void M_Spider_Attack_Web_Explode()
140 {SELFPARAM();
141         entity e;
142         if(self)
143         {
144                 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
145                 RadiusDamage(self, self.realowner, 0, 0, 25, world, world, 25, self.projectiledeathtype, world);
146
147                 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)
148                         e.spider_slowness = time + (autocvar_g_monster_spider_attack_web_damagetime);
149
150                 remove(self);
151         }
152 }
153
154 void M_Spider_Attack_Web_Explode_use(entity this, entity actor, entity trigger)
155 {
156         WITHSELF(this, M_Spider_Attack_Web_Explode());
157 }
158
159 void M_Spider_Attack_Web_Touch()
160 {
161         PROJECTILE_TOUCH;
162
163         M_Spider_Attack_Web_Explode();
164 }
165
166 void adaptor_think2use_hittype_splash();
167
168 void M_Spider_Attack_Web(entity this)
169 {
170         monster_makevectors(this, this.enemy);
171
172         sound(this, CH_SHOTS, SND_ELECTRO_FIRE2, VOL_BASE, ATTEN_NORM);
173
174         entity proj = new(plasma);
175         proj.owner = proj.realowner = this;
176         proj.use1 = M_Spider_Attack_Web_Explode_use;
177         proj.think = adaptor_think2use_hittype_splash;
178         proj.bot_dodge = true;
179         proj.bot_dodgerating = 0;
180         proj.nextthink = time + 5;
181         PROJECTILE_MAKETRIGGER(proj);
182         proj.projectiledeathtype = DEATH_MONSTER_SPIDER.m_id;
183         setorigin(proj, CENTER_OR_VIEWOFS(this));
184
185         //proj.glow_size = 50;
186         //proj.glow_color = 45;
187         proj.movetype = MOVETYPE_BOUNCE;
188         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);
189         proj.touch = M_Spider_Attack_Web_Touch;
190         setsize(proj, '-4 -4 -4', '4 4 4');
191         proj.takedamage = DAMAGE_NO;
192         proj.damageforcescale = 0;
193         proj.health = 500;
194         proj.event_damage = func_null;
195         proj.flags = FL_PROJECTILE;
196         proj.damagedbycontents = true;
197
198         proj.bouncefactor = 0.3;
199         proj.bouncestop = 0.05;
200         proj.missile_flags = MIF_SPLASH | MIF_ARC;
201
202         CSQCProjectile(proj, true, PROJECTILE_ELECTRO, true);
203 }
204
205 bool M_Spider_Attack(int attack_type, entity actor, entity targ)
206 {
207     .entity weaponentity = weaponentities[0];
208         switch(attack_type)
209         {
210                 Weapon wep = WEP_SPIDER_ATTACK;
211                 case MONSTER_ATTACK_MELEE:
212                 {
213                         wep.wr_think(wep, actor, weaponentity, 2);
214                         return true;
215                 }
216                 case MONSTER_ATTACK_RANGED:
217                 {
218                         wep.wr_think(wep, actor, weaponentity, 1);
219                         return true;
220                 }
221         }
222
223         return false;
224 }
225
226 spawnfunc(monster_spider) { Monster_Spawn(this, MON_SPIDER.monsterid); }
227 #endif // SVQC
228
229 #ifdef SVQC
230 METHOD(Spider, mr_think, bool(Spider this, entity actor))
231 {
232     TC(Spider, this);
233     return true;
234 }
235
236 METHOD(Spider, mr_pain, bool(Spider this, entity actor))
237 {
238     TC(Spider, this);
239     return true;
240 }
241
242 METHOD(Spider, mr_death, bool(Spider this, entity actor))
243 {
244     TC(Spider, this);
245     setanim(actor, actor.anim_melee, false, true, true);
246     actor.angles_x = 180;
247     return true;
248 }
249 #endif
250 #ifndef MENUQC
251 METHOD(Spider, mr_anim, bool(Spider this, entity actor))
252 {
253     TC(Spider, this);
254     vector none = '0 0 0';
255     actor.anim_walk = animfixfps(actor, '1 1 1', none);
256     actor.anim_idle = animfixfps(actor, '0 1 1', none);
257     actor.anim_melee = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
258     actor.anim_shoot = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
259     actor.anim_run = animfixfps(actor, '1 1 1', none);
260     return true;
261 }
262 #endif
263 #ifdef SVQC
264 spawnfunc(item_health_medium);
265 METHOD(Spider, mr_setup, bool(Spider this, entity actor))
266 {
267     TC(Spider, this);
268     if(!actor.health) actor.health = (autocvar_g_monster_spider_health);
269     if(!actor.speed) { actor.speed = (autocvar_g_monster_spider_speed_walk); }
270     if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_spider_speed_run); }
271     if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_spider_speed_stop); }
272     if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_spider_damageforcescale); }
273
274     actor.monster_loot = spawnfunc_item_health_medium;
275     actor.monster_attackfunc = M_Spider_Attack;
276
277     return true;
278 }
279
280 METHOD(Spider, mr_precache, bool(Spider this))
281 {
282     TC(Spider, this);
283     return true;
284 }
285 #endif
286
287 #endif