Implement full digest feature. When enabled, the pred doesn't spit the prey's dead...
[voretournament/voretournament.git] / data / qcsrc / server / vore.qc
1 .float regurgitate_prepare;\r
2 .float system_delay, swallow_delay, digest_button_delay_time, regurgitate_button_delay_time;\r
3 .float complain_vore;\r
4 .float vore_oldmovetype, vore_oldsolid, vore_oldstomachload;\r
5 \r
6 const float system_delay_time = 0.1;\r
7 const float complain_delay_time = 1;\r
8 const float button_delay_time = 0.5;\r
9 const float steptime = 0.1;\r
10 \r
11 entity Swallow_player_check()\r
12 {\r
13         // check if we can swallow a player instead of firing our weapon\r
14 \r
15         vector w_shotorg, w_shotdir;\r
16         w_shotorg = self.origin + self.view_ofs;\r
17         w_shotdir = v_forward;\r
18 \r
19         WarpZone_traceline_antilag(self, w_shotorg, w_shotorg + w_shotdir * cvar("g_balance_vore_swallow_range"), FALSE, self, ANTILAG_LATENCY(self));\r
20         if(trace_fraction < 1)\r
21         if(trace_ent.classname == "player")\r
22                 return trace_ent;\r
23         return world;\r
24 }\r
25 \r
26 float Swallow_condition_check(entity prey)\r
27 {\r
28         // checks the necessary conditions for swallowing a player\r
29 \r
30         if(prey != self)\r
31         if(prey.classname == "player" && prey.predator.classname != "player" && prey.deadflag == DEAD_NO) // we can't swallow someone who's already in someone else's stomach\r
32         if(self.classname == "player" && self.predator.classname != "player" && self.deadflag == DEAD_NO) // we can't swallow players while inside someone's stomach ourselves\r
33         if(!self.BUTTON_REGURGITATE && self.swallow_delay < time)\r
34         if not(vlen(self.velocity) > cvar("g_balance_vore_regurgitate_speedcap"))\r
35         {\r
36                 if(teams_matter && prey.team == self.team && !cvar("g_vore_teamvore"))\r
37                 {\r
38                         if(time > self.complain_vore)\r
39                         {\r
40                                 play2(self, "misc/unavailable.wav");\r
41                                 sprint(self, "You cannot swallow your team mates\n");\r
42                                 self.complain_vore = time + complain_delay_time;\r
43                         }\r
44                         return FALSE;\r
45                 }\r
46 \r
47                 if(self.stomach_load >= cvar("g_balance_vore_swallow_limit"))\r
48                 {\r
49                         if(time > self.complain_vore)\r
50                         {\r
51                                 play2(self, "misc/unavailable.wav");\r
52                                 sprint(self, strcat("You cannot swallow more than ^2", cvar_string("g_balance_vore_swallow_limit"), "^7 players at a time\n"));\r
53                                 self.complain_vore = time + complain_delay_time;\r
54                         }\r
55                         return FALSE;\r
56                 }\r
57 \r
58                 if(cvar("g_vore_biggergut"))\r
59                 if(prey.stomach_load > self.stomach_load)\r
60                 {\r
61                         if(time > self.complain_vore)\r
62                         {\r
63                                 play2(self, "misc/unavailable.wav");\r
64                                 sprint(self, "You cannot swallow someone with a bigger stomach than yours\n");\r
65                                 self.complain_vore = time + complain_delay_time;\r
66                         }\r
67                         return FALSE;\r
68                 }\r
69 \r
70                 return TRUE;\r
71         }\r
72         return FALSE;\r
73 }\r
74 \r
75 float Vore_CanLeave()\r
76 {\r
77         if(self.predator.classname == "player")\r
78         {\r
79                 if(!cvar("g_vore_kick")) // you are defenseless in the stomach if you can't kick, so allow leaving\r
80                         return TRUE;\r
81                 if(teams_matter && self.team == self.predator.team)\r
82                         return TRUE;\r
83                 if(g_rpg && cvar("g_rpg_canleave"))\r
84                         return TRUE;\r
85         }\r
86         return FALSE;\r
87 }\r
88 \r
89 // make the camera smoothly lower itself when we get swallowed\r
90 // our aim is going from the normal view offset to half of the view offset (because half is the best positioning for the stomach model)\r
91 .float cameraeffect_current, cameraeffect_target;\r
92 void Vore_CameraEffect_Set(entity e)\r
93 {\r
94         e.cameraeffect_current = 1;\r
95         e.cameraeffect_target = 2;\r
96 }\r
97 void Vore_CameraEffect_Apply()\r
98 {\r
99         if(self.predator.classname != "player")\r
100                 return;\r
101 \r
102         if(self.cvar_cl_vore_cameraspeed)\r
103         {\r
104                 local float step;\r
105                 step = self.cvar_cl_vore_cameraspeed * frametime;\r
106 \r
107                 // not sure if these maths are good, as the effect should be smoother\r
108                 if(self.cameraeffect_current >= self.cameraeffect_target + step)\r
109                         self.cameraeffect_current -= step;\r
110                 else if(self.cameraeffect_current <= self.cameraeffect_target - step)\r
111                         self.cameraeffect_current += step;\r
112         }\r
113         else\r
114                 self.cameraeffect_current = self.cameraeffect_target;\r
115 \r
116         self.view_ofs_z = PL_VIEW_OFS_z / self.cameraeffect_current;\r
117 }\r
118 \r
119 .float gurgle_oldstomachload;\r
120 void Vore_Gurglesound()\r
121 {\r
122         if(time > self.gurglesound_finished || self.gurgle_oldstomachload != self.stomach_load)\r
123         {\r
124                 GlobalSound(self.playersound_gurgle, CHAN_TRIGGER, VOICETYPE_GURGLE);\r
125 \r
126                 self.gurglesound_finished = time + 11; // yes, hard coded sound length. I know it's bad but what can I do?\r
127                 self.gurgle_oldstomachload = self.stomach_load;\r
128         }\r
129 }\r
130 \r
131 void Vore_Weight_apply(entity e)\r
132 {\r
133         // apply stomach weight that makes you heavier the more you eat\r
134         // slowing the player is done in cl_physics.qc\r
135 \r
136         if(e.stomach_load != e.vore_oldstomachload)\r
137                 e.gravity += 1 + (e.stomach_load * cvar("g_balance_vore_weight_gravity") - e.vore_oldstomachload);\r
138         if(e.gravity == 0)\r
139                 e.gravity = 0.00001; // 0 becomes 1 for gravity, so do this to allow 0 gravity\r
140         e.vore_oldstomachload = e.stomach_load;\r
141 }\r
142 \r
143 .entity pusher;\r
144 .float pushltime;\r
145 void Vore_Swallow(entity e)\r
146 {\r
147         // this player is being swallowed by another player, apply the proper changes\r
148 \r
149         e.vore_oldmovetype = e.movetype;\r
150         e.vore_oldsolid = e.solid;\r
151 \r
152         e.predator = self;\r
153         setorigin(e, e.predator.origin);\r
154         e.velocity = '0 0 0';\r
155         e.movetype = MOVETYPE_FOLLOW;\r
156         e.solid = SOLID_NOT;\r
157         e.alpha = -1; // best way of hiding the eaten player\r
158         e.aiment = e.predator; // follow the predator, automatically unset when regurgitated\r
159 \r
160         // drop keys (KH) and flags (CTF) when we get swallowed\r
161         kh_Key_DropAll(e, FALSE);\r
162         if(e.flagcarried)\r
163                 DropFlag(e.flagcarried, world, e.predator);\r
164 \r
165         Vore_CameraEffect_Set(e);\r
166 \r
167         if(stov(cvar_string("g_vore_regurgitatecolor_release")))\r
168                 e.colormod = stov(cvar_string("g_vore_regurgitatecolor_release"));\r
169 \r
170         if(teams_matter && e.team == e.predator.team)\r
171         {\r
172                 centerprint(e, "^3You have been swallowed by a team mate, don't kick!");\r
173                 centerprint(e.predator, "^3You have swallowed a team mate, use caution!");\r
174         }\r
175 \r
176         PlayerSound(e.predator, playersound_swallow, CHAN_PAIN, VOICETYPE_PLAYERSOUND);\r
177         setanim(e.predator, e.predator.anim_pain1, FALSE, TRUE, TRUE); // looks good for swallowing / regurgitating\r
178         e.predator.punchangle_x -= e.predator.cvar_cl_vore_punchangle;\r
179         e.predator.stomach_load += 1;\r
180         e.predator.regurgitate_prepare = 0;\r
181         e.predator.spawnshieldtime = 0; // lose spawn shield when we vore\r
182         Vore_Weight_apply(e.predator);\r
183 \r
184         // block firing for a small amount of time, or we'll be firing the next frame after we swallow\r
185         e.predator.weapon_delay = time + button_delay_time;\r
186         e.predator.swallow_delay = time + cvar("g_balance_vore_swallow_delay");\r
187         e.system_delay = e.predator.system_delay = time + system_delay_time;\r
188 }\r
189 \r
190 void Vore_Regurgitate(entity e)\r
191 {\r
192         // this player is being regurgitated by their predator, apply the proper changes\r
193 \r
194         e.movetype = e.vore_oldmovetype;\r
195         if(e.health > 0) // leave SOLID_NOT for dead bodies\r
196                 e.solid = e.vore_oldsolid;\r
197         e.view_ofs_z = PL_VIEW_OFS_z;\r
198         e.alpha = default_player_alpha;\r
199 \r
200         // apply velocities\r
201         local vector oldforward, oldright, oldup;\r
202         oldforward = v_forward;\r
203         oldright = v_right;\r
204         oldup = v_up;\r
205         makevectors(e.predator.v_angle);\r
206         e.velocity = v_forward * cvar("g_balance_vore_regurgitate_force");\r
207         e.predator.velocity += -v_forward * cvar("g_balance_vore_regurgitate_predatorforce");\r
208         v_forward = oldforward;\r
209         v_right = oldright;\r
210         v_up = oldup;\r
211 \r
212         e.pusher = e.predator; // allows us to frag players by regurgitating them in deadly pits\r
213         e.pushltime = time + cvar("g_maxpushtime");\r
214 \r
215         PlayerSound(e.predator, playersound_regurgitate, CHAN_PAIN, VOICETYPE_PLAYERSOUND);\r
216         setanim(e.predator, e.predator.anim_pain1, FALSE, TRUE, TRUE); // looks good for swallowing / regurgitating\r
217         pointparticles(particleeffectnum("regurgitate"), e.predator.origin, '0 0 0', 1);\r
218         e.predator.punchangle_x += e.predator.cvar_cl_vore_punchangle;\r
219         e.predator.stomach_load -= 1;\r
220         e.predator.regurgitate_prepare = 0;\r
221         e.predator.swallow_delay = time + cvar("g_balance_vore_swallow_delay");\r
222         Vore_Weight_apply(e.predator);\r
223 \r
224         // block firing for a small amount of time, or we'll be firing the next frame\r
225         e.weapon_delay = time + button_delay_time;\r
226         e.system_delay = e.predator.system_delay = time + system_delay_time;\r
227         e.predator = world;\r
228 }\r
229 \r
230 void Vore_DeadPrey_Configure(entity e)\r
231 {\r
232         // ran when the fulldigest feature is enabled and prey stays inside the stomach after dying\r
233 \r
234         if(e.fakepredator.classname == "player")\r
235                 return;\r
236 \r
237         // this entity is pretty much like e.predator but for dead prey, to avoid some conflicts\r
238         e.fakepredator = e.predator;\r
239 \r
240         // first release the prey from the predator, as dead prey needs to be attached to predators differently\r
241         // the predator's stomach load is also decreased, as our dead prey doesn't count as actual prey any more\r
242         e.predator.stomach_load -= 1;\r
243         Vore_Weight_apply(e.predator);\r
244         e.predator = world;\r
245 \r
246         // now, keep our dead prey inside the predator's stomach\r
247         e.movetype = MOVETYPE_FOLLOW;\r
248         e.aiment = e.fakepredator;\r
249         e.alpha = -1;\r
250 }\r
251 \r
252 void Vore_DeadPrey_Detach(entity e)\r
253 {\r
254         // ran when dead prey must be detached from the stomach (eg: they are respawning)\r
255 \r
256         if(e.fakepredator.classname != "player")\r
257                 return;\r
258 \r
259         e.movetype = e.vore_oldmovetype;\r
260         e.view_ofs_z = PL_VIEW_OFS_z;\r
261         e.alpha = default_player_alpha;\r
262 \r
263         // if we disconnect dead prey from the predator, gib it's body\r
264         if(e.health <= 0)\r
265                 e.health = -1000;\r
266 \r
267         e.fakepredator = world;\r
268 }\r
269 \r
270 void Vore_ChoosePreyRelease(entity e)\r
271 {\r
272         // if the fulldigest feature is on, we don't spit a dead prey's carcass out\r
273         if(e.health <= 0 && cvar("g_vore_fulldigest"))\r
274         {\r
275                 Vore_DeadPrey_Configure(e);\r
276 \r
277                 // if the predator's dead, we detach the dead prey from him\r
278                 if(e.fakepredator.deadflag != DEAD_NO)\r
279                         Vore_DeadPrey_Detach(e);\r
280         }\r
281         else\r
282                 Vore_Regurgitate(e);\r
283 }\r
284 \r
285 void Vore_Disconnect()\r
286 {\r
287         // frees prey from their predators when someone disconnects or goes spectating, or in other circumstances\r
288 \r
289         // prey disconnects or goes spectating while inside someone's belly\r
290         if(self.predator.classname == "player")\r
291                 Vore_ChoosePreyRelease(self);\r
292 \r
293         // pred disconnects or goes spectating with players in their belly\r
294         else if(self.stomach_load > 0)\r
295         {\r
296                 entity head;\r
297                 FOR_EACH_PLAYER(head)\r
298                 {\r
299                         if(head.predator == self)\r
300                                 Vore_ChoosePreyRelease(head);\r
301                 }\r
302                 Vore_Gurglesound(); // stop the gurgling sound\r
303         }\r
304 \r
305         self.stomach_load = self.gravity = 0; // prevents a bug\r
306 }\r
307 \r
308 .float digestion_step;\r
309 void Vore_Digest()\r
310 {\r
311         // apply digestion to prey\r
312 \r
313         if(time > self.predator.digestion_step)\r
314         {\r
315                 Damage(self, self.predator, self.predator, cvar("g_balance_vore_digestion_damage"), DEATH_DIGESTION, self.origin, '0 0 0');\r
316                 if(cvar("g_balance_vore_digestion_vampire") && self.predator.health < cvar("g_balance_vore_digestion_vampire_stable"))\r
317                         self.predator.health += cvar("g_balance_vore_digestion_vampire");\r
318 \r
319                 if (self.predator.digestsound_finished < time)\r
320                 {\r
321                         PlayerSound (self.predator, playersound_digest, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);\r
322                         self.predator.digestsound_finished = time + 0.5;\r
323                 }\r
324                 self.predator.digestion_step = time + steptime;\r
325         }\r
326 \r
327         if(self.health <= 0)\r
328         if(stov(cvar_string("g_vore_regurgitatecolor_digest")))\r
329                 self.colormod = stov(cvar_string("g_vore_regurgitatecolor_digest"));\r
330 }\r
331 \r
332 .float teamheal_step;\r
333 void Vore_Teamheal()\r
334 {\r
335         // apply teamheal\r
336 \r
337         if(cvar("g_balance_vore_teamheal") && self.health < cvar("g_balance_vore_teamheal_stable"))\r
338         if(time > self.teamheal_step)\r
339         {\r
340                 self.health += cvar("g_balance_vore_teamheal");\r
341                 self.teamheal_step = time + steptime;\r
342         }\r
343 }\r
344 \r
345 .float stomachkick_delay;\r
346 void Vore_StomachKick()\r
347 {\r
348         // allows prey to kick the predator's stomach and do some damage or attempt to escape\r
349 \r
350         if(time > self.stomachkick_delay)\r
351         {\r
352                 float damage;\r
353                 damage = ceil(random() * (cvar("g_balance_vore_kick_damage_max") - cvar("g_balance_vore_kick_damage_min")) + cvar("g_balance_vore_kick_damage_min"));\r
354                 Damage(self.predator, self, self, damage, DEATH_STOMACHKICK, self.predator.origin, v_forward * cvar("g_balance_vore_kick_force"));\r
355                 sound(self.predator, CHAN_PROJECTILE, "weapons/stomachkick.ogg", VOL_BASE, ATTN_NORM);\r
356 \r
357                 if(random() < cvar("g_balance_vore_kick_escapeprobability"))\r
358                         Vore_Regurgitate(self);\r
359 \r
360                 self.stomachkick_delay = time + cvar("g_balance_vore_kick_delay");\r
361         }\r
362 }\r
363 \r
364 void Vore_StomachLeave()\r
365 {\r
366         // allows players to get out of their predator at will in some circumstances, such as team mates\r
367 \r
368         if(Vore_CanLeave())\r
369                 Vore_Regurgitate(self);\r
370         else if(time > self.complain_vore)\r
371         {\r
372                 play2(self, "misc/unavailable.wav");\r
373                 sprint(self, strcat("You cannot get out of ", self.predator.netname, "\n"));\r
374                 self.complain_vore = time + complain_delay_time;\r
375         }\r
376 }\r
377 \r
378 void Vore()\r
379 {\r
380         // main vore code, this is where it all happens\r
381 \r
382         if(!cvar("g_vore")) // the vore system is disabled\r
383         {\r
384                 Vore_Disconnect();\r
385                 return;\r
386         }\r
387 \r
388         // wash the goo away from players once they leave the stomach\r
389         if(self.predator.classname != "player")\r
390         if(stov(cvar_string("g_vore_regurgitatecolor_release")))\r
391         if(self.colormod)\r
392         if(cvar("g_vore_regurgitatecolor_release_fade"))\r
393         {\r
394                 self.colormod_x += cvar("g_vore_regurgitatecolor_release_fade") * frametime;\r
395                 if(self.colormod_x > 1)\r
396                         self.colormod_x = 1;\r
397                 self.colormod_y += cvar("g_vore_regurgitatecolor_release_fade") * frametime;\r
398                 if(self.colormod_y > 1)\r
399                         self.colormod_y = 1;\r
400                 self.colormod_z += cvar("g_vore_regurgitatecolor_release_fade") * frametime;\r
401                 if(self.colormod_z > 1)\r
402                         self.colormod_z = 1;\r
403         }\r
404 \r
405         // set all vore related stats\r
406         if(self.predator.classname == "player")\r
407         {\r
408                 self.stat_stomachload = self.predator.stomach_load; // necessary for the stomach board\r
409                 self.stat_digesting = self.predator.digesting; // necessary for the stomach board\r
410                 self.stat_eaten = num_for_edict(self.predator);\r
411         }\r
412         else\r
413         {\r
414                 self.stat_stomachload = self.stomach_load;\r
415                 self.stat_digesting = self.digesting;\r
416                 self.stat_eaten = 0;\r
417         }\r
418         self.stat_canleave = Vore_CanLeave();\r
419 \r
420         // don't allow a player inside a player inside another player :)\r
421         // prevent this by checking if such has happened, and taking the proper measures\r
422         // this code has a high priority and must not be stopped by any delay, so run it here\r
423         if(self.predator.predator.classname == "player")\r
424         {\r
425                 entity target_predator, target_predator_predator, oldself;\r
426                 target_predator = self.predator;\r
427                 target_predator_predator = self.predator.predator;\r
428 \r
429                 Vore_Regurgitate(self);\r
430 \r
431                 // now steal our prey's prey if this probability applies\r
432                 if(random() < cvar("g_balance_vore_swallow_stealprey"))\r
433                 {\r
434                         oldself = self;\r
435                         self = target_predator_predator;\r
436                         if(Swallow_condition_check(oldself))\r
437                         if not(teams_matter && self.team == target_predator.team) // don't steal a team mate's prey\r
438                         if not(teams_matter && self.team == oldself.team) // if the prey we would be stealing is a team mate, don't do it\r
439                                 Vore_Swallow(oldself);\r
440                         self = oldself;\r
441                 }\r
442         }\r
443 \r
444         // apply delays and skip the vore system under some circumstances\r
445         if(time < game_starttime || (time < warmup && !inWarmupStage)) // don't allow vore before a round begins\r
446         {\r
447                 Vore_Disconnect();\r
448                 return;\r
449         }\r
450         if(self.spectatee_status)\r
451                 return;\r
452         if(time < self.system_delay)\r
453                 return;\r
454 \r
455 // --------------------------------\r
456 // Code that addresses predators:\r
457 // --------------------------------\r
458 \r
459         entity prey;\r
460         prey = Swallow_player_check();\r
461 \r
462         // attempt to swallow our new prey if we pressed the attack button, and there's any in range\r
463         if(self.BUTTON_ATCK)\r
464         if(Swallow_condition_check(prey))\r
465                 Vore_Swallow(prey);\r
466 \r
467         // toggle digestion, if the player has someone in their stomach\r
468         if(self.BUTTON_DIGEST && cvar("g_vore_digestion"))\r
469         {\r
470                 if(self.stomach_load)\r
471                 {\r
472                         if(time > self.digest_button_delay_time)\r
473                         {\r
474                                 self.digesting = !self.digesting;\r
475                                 self.digest_button_delay_time = time + button_delay_time;\r
476                         }\r
477                 }\r
478                 else if(time > self.complain_vore)\r
479                 {\r
480                         play2(self, "misc/unavailable.wav");\r
481                         sprint(self, "There is nothing to digest\n");\r
482                         self.complain_vore = time + complain_delay_time;\r
483                 }\r
484         }\r
485         if(!self.stomach_load || !cvar("g_vore_digestion"))\r
486                 self.digesting = FALSE;\r
487 \r
488         // predator wishes to regurgitate his prey\r
489         if(self.BUTTON_REGURGITATE)\r
490         {\r
491                 if(self.stomach_load)\r
492                 {\r
493                         if(time > self.regurgitate_button_delay_time)\r
494                         {\r
495                                 self.regurgitate_prepare = time + cvar("g_balance_vore_regurgitate_delay");\r
496                                 PlayerSound(self, playersound_regurgitate_prepare, CHAN_VOICE, VOICETYPE_PLAYERSOUND);\r
497                                 self.regurgitate_button_delay_time = time + button_delay_time;\r
498                         }\r
499                 }\r
500                 else if(time > self.complain_vore)\r
501                 {\r
502                         play2(self, "misc/unavailable.wav");\r
503                         sprint(self, "There is nothing to regurgitate\n");\r
504                         self.complain_vore = time + complain_delay_time;\r
505                 }\r
506         }\r
507 \r
508         if(cvar("g_vore_gurglesound"))\r
509                 Vore_Gurglesound();\r
510 \r
511 // --------------------------------\r
512 // Code that addresses the prey:\r
513 // --------------------------------\r
514 \r
515         if(self.deadflag)\r
516         {\r
517                 Vore_ChoosePreyRelease(self);\r
518                 return;\r
519         }\r
520         if(self.predator.classname != "player")\r
521                 return;\r
522         if(self.predator.deadflag)\r
523                 Vore_Regurgitate(self);\r
524         else if(vlen(self.predator.velocity) > cvar("g_balance_vore_regurgitate_speedcap"))\r
525                 Vore_Regurgitate(self);\r
526 \r
527         // apply delayed regurgitating if it was scheduled\r
528         if(self.predator.regurgitate_prepare && time > self.predator.regurgitate_prepare)\r
529         {\r
530                 self.predator.regurgitate_prepare = 0;\r
531                 self.predator.complain_vore = time + complain_delay_time; // prevent complaining the next frame if this empties our stomach\r
532                 Vore_Regurgitate(self);\r
533         }\r
534 \r
535         // execute digesting and team healing\r
536         if(self.predator.digesting == TRUE)\r
537                 Vore_Digest();\r
538         if(teams_matter && self.team == self.predator.team)\r
539         if(cvar("g_balance_vore_teamheal") && cvar("g_vore_teamvore"))\r
540                 Vore_Teamheal();\r
541 \r
542         // execute prey commands\r
543         if(self.BUTTON_ATCK && cvar("g_vore_kick"))\r
544                 Vore_StomachKick();\r
545         if(self.BUTTON_JUMP)\r
546                 Vore_StomachLeave();\r
547 \r
548         Vore_CameraEffect_Apply();\r
549 }