Merge branch 'master' into samual/weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / spider.qc
1 #ifdef REGISTER_MONSTER
2 REGISTER_MONSTER(
3 /* MON_##id   */ SPIDER,
4 /* function   */ m_spider,
5 /* spawnflags */ MON_FLAG_MELEE | MON_FLAG_RANGED,
6 /* mins,maxs  */ '-18 -18 -25', '18 18 30',
7 /* model      */ "spider.dpm",
8 /* netname    */ "spider",
9 /* fullname   */ _("Spider")
10 );
11
12 #else
13 #ifdef SVQC
14 float autocvar_g_monster_spider_health;
15 float autocvar_g_monster_spider_attack_bite_damage;
16 float autocvar_g_monster_spider_attack_bite_delay;
17 float autocvar_g_monster_spider_attack_web_damagetime;
18 float autocvar_g_monster_spider_attack_web_speed;
19 float autocvar_g_monster_spider_attack_web_speed_up;
20 float autocvar_g_monster_spider_attack_web_delay;
21 float autocvar_g_monster_spider_speed_stop;
22 float autocvar_g_monster_spider_speed_run;
23 float autocvar_g_monster_spider_speed_walk;
24
25 const float spider_anim_idle            = 0;
26 const float spider_anim_walk            = 1;
27 const float spider_anim_attack          = 2;
28 const float spider_anim_attack2         = 3;
29
30 .float spider_web_delay;
31
32 void spider_web_explode()
33 {
34         entity e;
35         if(self)
36         {
37                 pointparticles(particleeffectnum("electro_impact"), self.origin, '0 0 0', 1);
38                 RadiusDamage(self, self.realowner, 0, 0, 25, world, world, 25, self.projectiledeathtype, world);
39
40                 for(e = findradius(self.origin, 25); e; e = e.chain) if(e != self) if(e.takedamage && e.deadflag == DEAD_NO) if(e.health > 0) if(e.monsterid != MON_SPIDER)
41                         e.spider_slowness = time + (autocvar_g_monster_spider_attack_web_damagetime);
42
43                 remove(self);
44         }
45 }
46
47 void spider_web_touch()
48 {
49         PROJECTILE_TOUCH;
50
51         spider_web_explode();
52 }
53
54 void spider_shootweb()
55 {
56         monster_makevectors(self.enemy);
57
58         sound(self, CH_SHOTS, "weapons/electro_fire2.wav", VOL_BASE, ATTEN_NORM);
59
60         entity proj = spawn ();
61         proj.classname = "plasma";
62         proj.owner = proj.realowner = self;
63         proj.use = spider_web_touch;
64         proj.think = adaptor_think2use_hittype_splash;
65         proj.bot_dodge = TRUE;
66         proj.bot_dodgerating = 0;
67         proj.nextthink = time + 5;
68         PROJECTILE_MAKETRIGGER(proj);
69         proj.projectiledeathtype = DEATH_MONSTER_SPIDER;
70         setorigin(proj, CENTER_OR_VIEWOFS(self));
71
72         //proj.glow_size = 50;
73         //proj.glow_color = 45;
74         proj.movetype = MOVETYPE_BOUNCE;
75         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);
76         proj.touch = spider_web_touch;
77         setsize(proj, '-4 -4 -4', '4 4 4');
78         proj.takedamage = DAMAGE_NO;
79         proj.damageforcescale = 0;
80         proj.health = 500;
81         proj.event_damage = func_null;
82         proj.flags = FL_PROJECTILE;
83         proj.damagedbycontents = TRUE;
84
85         proj.bouncefactor = 0.3;
86         proj.bouncestop = 0.05;
87         proj.missile_flags = MIF_SPLASH | MIF_ARC;
88
89         CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, TRUE);
90 }
91
92 float spider_attack(float attack_type)
93 {
94         switch(attack_type)
95         {
96                 case MONSTER_ATTACK_MELEE:
97                 {
98                         return monster_melee(self.enemy, (autocvar_g_monster_spider_attack_bite_damage), ((random() > 0.5) ? spider_anim_attack : spider_anim_attack2), self.attack_range, (autocvar_g_monster_spider_attack_bite_delay), DEATH_MONSTER_SPIDER, TRUE);
99                 }
100                 case MONSTER_ATTACK_RANGED:
101                 {
102                         if(time >= self.spider_web_delay)
103                         {
104                                 self.frame = spider_anim_attack2;
105                                 self.attack_finished_single = time + (autocvar_g_monster_spider_attack_web_delay);
106                                 spider_shootweb();
107                                 self.spider_web_delay = time + 3;
108                                 return TRUE;
109                         }
110
111                         return FALSE;
112                 }
113         }
114
115         return FALSE;
116 }
117
118 void spawnfunc_monster_spider()
119 {
120         self.classname = "monster_spider";
121
122         if(!monster_initialize(MON_SPIDER)) { remove(self); return; }
123 }
124
125 float m_spider(float req)
126 {
127         switch(req)
128         {
129                 case MR_THINK:
130                 {
131                         monster_move((autocvar_g_monster_spider_speed_run), (autocvar_g_monster_spider_speed_walk), (autocvar_g_monster_spider_speed_stop), spider_anim_walk, spider_anim_walk, spider_anim_idle);
132                         return TRUE;
133                 }
134                 case MR_DEATH:
135                 {
136                         self.frame = spider_anim_attack;
137                         self.angles_x = 180;
138                         return TRUE;
139                 }
140                 case MR_SETUP:
141                 {
142                         if(!self.health) self.health = (autocvar_g_monster_spider_health);
143
144                         self.monster_loot = spawnfunc_item_health_medium;
145                         self.monster_attackfunc = spider_attack;
146                         self.frame = spider_anim_idle;
147
148                         return TRUE;
149                 }
150                 case MR_PRECACHE:
151                 {
152                         precache_model("models/monsters/spider.dpm");
153                         precache_sound ("weapons/electro_fire2.wav");
154                         return TRUE;
155                 }
156         }
157
158         return TRUE;
159 }
160
161 #endif // SVQC
162 #ifdef CSQC
163 float m_spider(float req)
164 {
165         switch(req)
166         {
167                 case MR_PRECACHE:
168                 {
169                         return TRUE;
170                 }
171         }
172
173         return TRUE;
174 }
175
176 #endif // CSQC
177 #endif // REGISTER_MONSTER