]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/spider.qc
Merge branch 'master' into Mario/entrap_nade
[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     entity player = M_ARGV(0, entity);
60
61         if (time >= player.spider_slowness)
62                 return false;
63         PHYS_MAXSPEED(player) *= 0.5; // half speed while slow from spider
64         PHYS_MAXAIRSPEED(player) *= 0.5;
65         PHYS_AIRSPEEDLIMIT_NONQW(player) *= 0.5;
66         PHYS_AIRSTRAFEACCELERATE(player) *= 0.5;
67 }
68
69 MUTATOR_HOOKFUNCTION(spiderweb, MonsterMove)
70 {
71     entity mon = M_ARGV(0, entity);
72
73         if(time < mon.spider_slowness)
74         {
75                 M_ARGV(1, float) *= 0.5; // run speed
76                 M_ARGV(2, float) *= 0.5; // walk speed
77         }
78 }
79
80 MUTATOR_HOOKFUNCTION(spiderweb, PlayerSpawn)
81 {
82         entity player = M_ARGV(0, entity);
83
84         player.spider_slowness = 0;
85         return false;
86 }
87
88 MUTATOR_HOOKFUNCTION(spiderweb, MonsterSpawn)
89 {
90     entity mon = M_ARGV(0, entity);
91
92         mon.spider_slowness = 0;
93 }
94
95 SOUND(SpiderAttack_FIRE, W_Sound("electro_fire"));
96 METHOD(SpiderAttack, wr_think, void(SpiderAttack thiswep, entity actor, .entity weaponentity, int fire))
97 {
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) ? actor.anim_melee : actor.anim_shoot), actor.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(entity this)
140 {
141         if(this)
142         {
143                 Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
144                 RadiusDamage(this, this.realowner, 0, 0, 25, NULL, NULL, 25, this.projectiledeathtype, NULL);
145
146                 for(entity e = findradius(this.origin, 25); e; e = e.chain) if(e != this) if(e.takedamage && !IS_DEAD(e)) if(e.health > 0) if(e.monsterid != MON_SPIDER.monsterid)
147                         e.spider_slowness = time + (autocvar_g_monster_spider_attack_web_damagetime);
148
149                 remove(this);
150         }
151 }
152
153 void M_Spider_Attack_Web_Explode_use(entity this, entity actor, entity trigger)
154 {
155         M_Spider_Attack_Web_Explode(this);
156 }
157
158 void M_Spider_Attack_Web_Touch(entity this)
159 {
160         PROJECTILE_TOUCH(this);
161
162         M_Spider_Attack_Web_Explode(this);
163 }
164
165 void adaptor_think2use_hittype_splash(entity this);
166
167 void M_Spider_Attack_Web(entity this)
168 {
169         monster_makevectors(this, this.enemy);
170
171         sound(this, CH_SHOTS, SND_ELECTRO_FIRE2, VOL_BASE, ATTEN_NORM);
172
173         entity proj = new(plasma);
174         proj.owner = proj.realowner = this;
175         proj.use = M_Spider_Attack_Web_Explode_use;
176         setthink(proj, adaptor_think2use_hittype_splash);
177         proj.bot_dodge = true;
178         proj.bot_dodgerating = 0;
179         proj.nextthink = time + 5;
180         PROJECTILE_MAKETRIGGER(proj);
181         proj.projectiledeathtype = DEATH_MONSTER_SPIDER.m_id;
182         setorigin(proj, CENTER_OR_VIEWOFS(this));
183
184         //proj.glow_size = 50;
185         //proj.glow_color = 45;
186         proj.movetype = MOVETYPE_BOUNCE;
187         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);
188         settouch(proj, M_Spider_Attack_Web_Touch);
189         setsize(proj, '-4 -4 -4', '4 4 4');
190         proj.takedamage = DAMAGE_NO;
191         proj.damageforcescale = 0;
192         proj.health = 500;
193         proj.event_damage = func_null;
194         proj.flags = FL_PROJECTILE;
195         proj.damagedbycontents = true;
196
197         proj.bouncefactor = 0.3;
198         proj.bouncestop = 0.05;
199         proj.missile_flags = MIF_SPLASH | MIF_ARC;
200
201         CSQCProjectile(proj, true, PROJECTILE_ELECTRO, true);
202 }
203
204 bool M_Spider_Attack(int attack_type, entity actor, entity targ)
205 {
206     .entity weaponentity = weaponentities[0];
207         switch(attack_type)
208         {
209                 Weapon wep = WEP_SPIDER_ATTACK;
210                 case MONSTER_ATTACK_MELEE:
211                 {
212                         wep.wr_think(wep, actor, weaponentity, 2);
213                         return true;
214                 }
215                 case MONSTER_ATTACK_RANGED:
216                 {
217                         wep.wr_think(wep, actor, weaponentity, 1);
218                         return true;
219                 }
220         }
221
222         return false;
223 }
224
225 spawnfunc(monster_spider) { Monster_Spawn(this, MON_SPIDER.monsterid); }
226 #endif // SVQC
227
228 #ifdef SVQC
229 METHOD(Spider, mr_think, bool(Spider this, entity actor))
230 {
231     TC(Spider, this);
232     return true;
233 }
234
235 METHOD(Spider, mr_pain, float(Spider this, entity actor, float damage_take, entity attacker, float deathtype))
236 {
237     TC(Spider, this);
238     return damage_take;
239 }
240
241 METHOD(Spider, mr_death, bool(Spider this, entity actor))
242 {
243     TC(Spider, this);
244     setanim(actor, actor.anim_melee, false, true, true);
245     actor.angles_x = 180;
246     return true;
247 }
248 #endif
249 #ifndef MENUQC
250 METHOD(Spider, mr_anim, bool(Spider this, entity actor))
251 {
252     TC(Spider, this);
253     vector none = '0 0 0';
254     actor.anim_walk = animfixfps(actor, '1 1 1', none);
255     actor.anim_idle = animfixfps(actor, '0 1 1', none);
256     actor.anim_melee = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
257     actor.anim_shoot = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
258     actor.anim_run = animfixfps(actor, '1 1 1', none);
259     return true;
260 }
261 #endif
262 #ifdef SVQC
263 spawnfunc(item_health_medium);
264 METHOD(Spider, mr_setup, bool(Spider this, entity actor))
265 {
266     TC(Spider, this);
267     if(!actor.health) actor.health = (autocvar_g_monster_spider_health);
268     if(!actor.speed) { actor.speed = (autocvar_g_monster_spider_speed_walk); }
269     if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_spider_speed_run); }
270     if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_spider_speed_stop); }
271     if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_spider_damageforcescale); }
272
273     actor.monster_loot = spawnfunc_item_health_medium;
274     actor.monster_attackfunc = M_Spider_Attack;
275
276     return true;
277 }
278
279 METHOD(Spider, mr_precache, bool(Spider this))
280 {
281     TC(Spider, this);
282     return true;
283 }
284 #endif
285
286 #endif