]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/spider.qc
Weapons: remove useless weapon return values and implementations
[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, "models/monsters/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     MON_ACTION(this, MR_PRECACHE);
22 #endif
23 }
24
25 #include "../../weapons/all.qh"
26
27 CLASS(SpiderAttack, PortoLaunch)
28 /* flags     */ ATTRIB(SpiderAttack, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_HIDDEN);
29 /* impulse   */ ATTRIB(SpiderAttack, impulse, int, 9);
30 /* refname   */ ATTRIB(SpiderAttack, netname, string, "spider");
31 /* wepname   */ ATTRIB(SpiderAttack, message, 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_web_delay;
42
43 float autocvar_g_monster_spider_attack_web_damagetime;
44 float autocvar_g_monster_spider_attack_web_speed;
45 float autocvar_g_monster_spider_attack_web_speed_up;
46 float autocvar_g_monster_spider_attack_web_delay;
47
48 float autocvar_g_monster_spider_attack_bite_damage;
49 float autocvar_g_monster_spider_attack_bite_delay;
50
51 void M_Spider_Attack_Web();
52
53 METHOD(SpiderAttack, wr_think, void(SpiderAttack thiswep, bool fire1, bool fire2)) {
54     SELFPARAM();
55     bool isPlayer = IS_PLAYER(self);
56     if (fire1)
57     if ((!isPlayer && time >= self.spider_web_delay) || weapon_prepareattack(false, autocvar_g_monster_spider_attack_web_delay)) {
58                 if (!isPlayer) {
59                         self.spider_web_delay = time + 3;
60                         setanim(self, self.anim_shoot, true, true, true);
61                         self.attack_finished_single = time + (autocvar_g_monster_spider_attack_web_delay);
62                         self.anim_finished = time + 1;
63                 }
64         if (isPlayer) self.enemy = Monster_FindTarget(self);
65         W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
66         if (!isPlayer) w_shotdir = normalize((self.enemy.origin + '0 0 10') - self.origin);
67                 M_Spider_Attack_Web();
68         weapon_thinkf(WFRAME_FIRE1, 0, w_ready);
69         return;
70     }
71     if (fire2)
72     if (!isPlayer || weapon_prepareattack(true, 0.5)) {
73         if (isPlayer) {
74                 self.enemy = Monster_FindTarget(self);
75                 self.attack_range = 60;
76         }
77         Monster_Attack_Melee(self.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, true);
78         weapon_thinkf(WFRAME_FIRE2, 0, w_ready);
79     }
80 }
81
82 float autocvar_g_monster_spider_health;
83 float autocvar_g_monster_spider_damageforcescale = 0.6;
84 float autocvar_g_monster_spider_speed_stop;
85 float autocvar_g_monster_spider_speed_run;
86 float autocvar_g_monster_spider_speed_walk;
87
88 /*
89 const float spider_anim_idle            = 0;
90 const float spider_anim_walk            = 1;
91 const float spider_anim_attack          = 2;
92 const float spider_anim_attack2         = 3;
93 */
94
95 void M_Spider_Attack_Web_Explode()
96 {SELFPARAM();
97         entity e;
98         if(self)
99         {
100                 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
101                 RadiusDamage(self, self.realowner, 0, 0, 25, world, world, 25, self.projectiledeathtype, world);
102
103                 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.monsterid)
104                         e.spider_slowness = time + (autocvar_g_monster_spider_attack_web_damagetime);
105
106                 remove(self);
107         }
108 }
109
110 void M_Spider_Attack_Web_Touch()
111 {
112         PROJECTILE_TOUCH;
113
114         M_Spider_Attack_Web_Explode();
115 }
116
117 void M_Spider_Attack_Web()
118 {SELFPARAM();
119         monster_makevectors(self.enemy);
120
121         sound(self, CH_SHOTS, SND_ELECTRO_FIRE2, VOL_BASE, ATTEN_NORM);
122
123         entity proj = spawn ();
124         proj.classname = "plasma";
125         proj.owner = proj.realowner = self;
126         proj.use = M_Spider_Attack_Web_Explode;
127         proj.think = adaptor_think2use_hittype_splash;
128         proj.bot_dodge = true;
129         proj.bot_dodgerating = 0;
130         proj.nextthink = time + 5;
131         PROJECTILE_MAKETRIGGER(proj);
132         proj.projectiledeathtype = DEATH_MONSTER_SPIDER;
133         setorigin(proj, CENTER_OR_VIEWOFS(self));
134
135         //proj.glow_size = 50;
136         //proj.glow_color = 45;
137         proj.movetype = MOVETYPE_BOUNCE;
138         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);
139         proj.touch = M_Spider_Attack_Web_Touch;
140         setsize(proj, '-4 -4 -4', '4 4 4');
141         proj.takedamage = DAMAGE_NO;
142         proj.damageforcescale = 0;
143         proj.health = 500;
144         proj.event_damage = func_null;
145         proj.flags = FL_PROJECTILE;
146         proj.damagedbycontents = true;
147
148         proj.bouncefactor = 0.3;
149         proj.bouncestop = 0.05;
150         proj.missile_flags = MIF_SPLASH | MIF_ARC;
151
152         CSQCProjectile(proj, true, PROJECTILE_ELECTRO, true);
153 }
154
155 bool M_Spider_Attack(int attack_type, entity targ)
156 {SELFPARAM();
157         switch(attack_type)
158         {
159                 Weapon wep = WEP_SPIDER_ATTACK;
160                 case MONSTER_ATTACK_MELEE:
161                 {
162                         wep.wr_think(wep, false, true);
163                         return true;
164                 }
165                 case MONSTER_ATTACK_RANGED:
166                 {
167                         wep.wr_think(wep, true, false);
168                         return true;
169                 }
170         }
171
172         return false;
173 }
174
175 void spawnfunc_monster_spider() { Monster_Spawn(MON_SPIDER.monsterid); }
176 #endif // SVQC
177
178                 #ifdef SVQC
179                 METHOD(Spider, mr_think, bool(Spider thismon))
180                 {
181                         return true;
182                 }
183                 METHOD(Spider, mr_pain, bool(Spider thismon))
184                 {
185                         return true;
186                 }
187                 METHOD(Spider, mr_death, bool(Spider thismon))
188                 {
189                         SELFPARAM();
190                         setanim(self, self.anim_melee, false, true, true);
191                         self.angles_x = 180;
192                         return true;
193                 }
194                 #endif
195                 #ifndef MENUQC
196                 METHOD(Spider, mr_anim, bool(Spider thismon))
197                 {
198                         SELFPARAM();
199                         vector none = '0 0 0';
200                         self.anim_walk = animfixfps(self, '1 1 1', none);
201                         self.anim_idle = animfixfps(self, '0 1 1', none);
202                         self.anim_melee = animfixfps(self, '2 1 5', none); // analyze models and set framerate
203                         self.anim_shoot = animfixfps(self, '3 1 5', none); // analyze models and set framerate
204                         self.anim_run = animfixfps(self, '1 1 1', none);
205
206                         return true;
207                 }
208                 #endif
209                 #ifdef SVQC
210                 METHOD(Spider, mr_setup, bool(Spider thismon))
211                 {
212                         SELFPARAM();
213                         if(!self.health) self.health = (autocvar_g_monster_spider_health);
214                         if(!self.speed) { self.speed = (autocvar_g_monster_spider_speed_walk); }
215                         if(!self.speed2) { self.speed2 = (autocvar_g_monster_spider_speed_run); }
216                         if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_spider_speed_stop); }
217                         if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_spider_damageforcescale); }
218
219                         self.monster_loot = spawnfunc_item_health_medium;
220                         self.monster_attackfunc = M_Spider_Attack;
221
222                         return true;
223                 }
224                 METHOD(Spider, mr_precache, bool(Spider thismon))
225                 {
226                         return true;
227                 }
228                 #endif
229
230 #endif