]> de.git.xonotic.org Git - voretournament/voretournament.git/blobdiff - data/qcsrc/server/t_items.qc
Fix player names showing for prey
[voretournament/voretournament.git] / data / qcsrc / server / t_items.qc
index 2ad8336226f2e9f8c01c1efa7cb470087605a8cd..5517fa30dfedb8fa859a0eeb6604ce187737384d 100644 (file)
@@ -144,7 +144,6 @@ void Item_Respawn (void)
                sound (self, CHAN_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM);        // play respawn sound\r
        setorigin (self, self.origin);\r
 \r
-       //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);\r
        pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);\r
 }\r
 \r
@@ -220,6 +219,191 @@ void Item_ScheduleInitialRespawn(entity e)
        Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));\r
 }\r
 \r
+.float inithealth, initdmg;\r
+.float item_digestion_step;\r
+void Item_Consumable_Think()\r
+{\r
+       if(self.predator.regurgitate_prepare && time > self.predator.regurgitate_prepare)\r
+       {\r
+               self.predator.regurgitate_prepare = 0;\r
+               self.predator.complain_vore = time + complain_delay_time; // prevent complaining the next frame if this empties our stomach\r
+               Item_Consumable_Remove(self, TRUE);\r
+               return;\r
+       }\r
+       if(self.predator.stat_eaten)\r
+       {\r
+               // prey can't hold consumable items\r
+               Item_Consumable_Remove(self, TRUE);\r
+               return;\r
+       }\r
+\r
+       self.scale = self.health / self.inithealth; // scale matches the item's digestion progress\r
+       self.dmg = self.initdmg * self.scale;\r
+       if(self.health <= 0)\r
+       {\r
+               // this item is done\r
+               Item_Consumable_Remove(self, FALSE);\r
+               return;\r
+       }\r
+\r
+       if(self.predator.digesting)\r
+       {\r
+               if(time > self.item_digestion_step)\r
+               {\r
+                       // if distributed digestion is enabled, reduce digestion strength by the amount of prey in our stomach\r
+                       float damage, damage_offset;\r
+\r
+                       damage_offset = 1;\r
+                       if(cvar("g_balance_vore_digestion_distribute")) // apply distributed digestion damage\r
+                               damage_offset /= (1 - (self.predator.stomach_load / self.predator.stomach_maxload) * bound(0, cvar("g_balance_vore_digestion_distribute"), 1));\r
+                       damage = ceil(cvar("g_balance_vore_digestion_damage_item") / damage_offset);\r
+\r
+                       self.health -= damage;\r
+                       if(self.predator.health + damage <= self.max_health)\r
+                               self.predator.health += damage;\r
+                       else if(self.predator.health < self.max_health)\r
+                               self.predator.health = self.max_health;\r
+                       self.predator.pauserothealth_finished = max(self.predator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));\r
+\r
+                       self.item_digestion_step = time + vore_steptime;\r
+               }\r
+\r
+               if(stov(cvar_string("g_vore_regurgitatecolor_color_digest")))\r
+                       self.colormod = stov(cvar_string("g_vore_regurgitatecolor_color_digest"));\r
+       }\r
+\r
+       self.nextthink = time;\r
+}\r
+\r
+float Item_Consumable_Customizeentityforclient()\r
+{\r
+       if(cvar("g_vore_neighborprey_distance_item") && self.predator == other.predator && !(other.cvar_chase_active || other.classname == "observer"))\r
+       {\r
+               self.alpha = default_player_alpha; // allow seeing neighboring items\r
+               self.effects |= EF_NODEPTHTEST; // don't hide behind the stomach's own EF_NODEPTHTEST\r
+       }\r
+       else\r
+               self.alpha = -1; // hide item\r
+       return TRUE;\r
+}\r
+\r
+void Item_DroppedConsumable_Spawn(entity e);\r
+void Item_Consumable_Remove(entity e, float regurgitate)\r
+{\r
+       if(regurgitate)\r
+       {\r
+               // predator effects, some common to those in Vore_Regurgitate\r
+               PlayerSound(e.predator, playersound_regurgitate, CHAN_VOICE, VOICETYPE_PLAYERSOUND);\r
+               setanim(e.predator, e.predator.anim_pain1, FALSE, TRUE, TRUE); // looks good for swallowing / regurgitating\r
+               pointparticles(particleeffectnum("vore_regurgitate"), e.predator.origin, '0 0 0', 1);\r
+               e.predator.punchangle_x = crandom() * cvar("g_balance_vore_regurgitate_predator_punchangle_item");\r
+               e.predator.punchangle_y = crandom() * cvar("g_balance_vore_regurgitate_predator_punchangle_item");\r
+               e.predator.punchangle_z = crandom() * cvar("g_balance_vore_regurgitate_predator_punchangle_item");\r
+               e.predator.regurgitate_prepare = 0;\r
+               e.predator.action_delay = time + cvar("g_balance_vore_action_delay");\r
+\r
+               Item_DroppedConsumable_Spawn(e);\r
+       }\r
+\r
+       e.nextthink = 0;\r
+       remove(e);\r
+       e = world;\r
+}\r
+\r
+void Item_Consumable_Spawn(entity e, entity pl)\r
+{\r
+       entity item;\r
+       item = spawn();\r
+       item.owner = e;\r
+       item.classname = "consumable";\r
+       item.movetype = MOVETYPE_FOLLOW;\r
+       item.solid = SOLID_NOT;\r
+       setmodel(item, e.model);\r
+       item.health = e.health;\r
+       if(e.inithealth)\r
+       {\r
+               item.inithealth = e.inithealth;\r
+               item.initdmg = e.initdmg;\r
+       }\r
+       else\r
+       {\r
+               item.inithealth = e.health;\r
+               item.initdmg = e.dmg;\r
+       }\r
+       item.max_health = e.max_health;\r
+\r
+       item.predator = pl;\r
+       item.aiment = pl;\r
+       item.view_ofs_x = CONSUMABLE_VIEW_OFS_x + crandom() * cvar("g_vore_neighborprey_distance_item");\r
+       item.view_ofs_y = CONSUMABLE_VIEW_OFS_y + crandom() * cvar("g_vore_neighborprey_distance_item");\r
+       item.view_ofs_z = CONSUMABLE_VIEW_OFS_z + crandom() * cvar("g_vore_neighborprey_distance_item");\r
+       item.angles = randomvec() * 360;\r
+\r
+       item.customizeentityforclient = Item_Consumable_Customizeentityforclient;\r
+       item.think = Item_Consumable_Think;\r
+       item.nextthink = time;\r
+\r
+       if(stov(cvar_string("g_vore_regurgitatecolor_color_normal")))\r
+               item.colormod = stov(cvar_string("g_vore_regurgitatecolor_color_normal"));\r
+\r
+       // predator effects, some common to those in Vore_Swallow\r
+       PlayerSound(pl, playersound_swallow, CHAN_VOICE, VOICETYPE_PLAYERSOUND);\r
+       setanim(pl, pl.anim_pain1, FALSE, TRUE, TRUE); // looks good for swallowing / regurgitating\r
+       pl.punchangle_x = crandom() * cvar("g_balance_vore_swallow_predator_punchangle_item");\r
+       pl.punchangle_y = crandom() * cvar("g_balance_vore_swallow_predator_punchangle_item");\r
+       pl.punchangle_z = crandom() * cvar("g_balance_vore_swallow_predator_punchangle_item");\r
+       pl.regurgitate_prepare = 0;\r
+       pl.action_delay = time + cvar("g_balance_vore_action_delay");\r
+}\r
+\r
+void Item_DroppedConsumable_Touch()\r
+{\r
+       if(time < self.cnt)\r
+               return;\r
+\r
+       // give the consumable item to the player touching it\r
+       if not(other.stomach_load + self.dmg > other.stomach_maxload || other.stomach_load + self.initdmg > other.stomach_maxload)\r
+       if not(!cvar("g_balance_health_consumable_alwayspickup") && other.health >= self.max_health)\r
+       {\r
+               Item_Consumable_Spawn(self, other);\r
+               remove(self);\r
+               self = world;\r
+       }\r
+}\r
+\r
+void Item_DroppedConsumable_Spawn(entity e)\r
+{\r
+       entity item;\r
+       item = spawn();\r
+       item.owner = world;\r
+       item.classname = "droppedconsumable";\r
+       item.movetype = MOVETYPE_TOSS;\r
+       item.solid = SOLID_TRIGGER;\r
+       setmodel(item, e.model);\r
+       item.health = e.health;\r
+       item.inithealth = e.inithealth;\r
+       item.initdmg = e.initdmg;\r
+       item.max_health = e.max_health;\r
+       item.scale = e.scale;\r
+       item.colormod = e.colormod;\r
+\r
+       if(cvar("g_nodepthtestitems"))\r
+               item.effects |= EF_NODEPTHTEST;\r
+\r
+       float scalediff, sz;\r
+       sz = e.scale; // the line below does not work if I define this directly (fteqcc bug?)\r
+       scalediff = cvar("g_healthsize") ? sz / e.predator.scale : sz; // the tighter the gut, the greater the velocity\r
+\r
+       setorigin(item, e.predator.origin);\r
+       item.angles_y = e.predator.angles_y;\r
+       makevectors(e.predator.v_angle);\r
+       item.velocity = v_forward * cvar("g_balance_vore_regurgitate_force") * scalediff;\r
+       e.predator.velocity += -v_forward * cvar("g_balance_vore_regurgitate_predatorforce") * scalediff;\r
+       item.touch = Item_DroppedConsumable_Touch;\r
+       item.cnt = time + 1; // 1 second delay\r
+       SUB_SetFade(item, time + 20, 1);\r
+}\r
+\r
 float Item_GiveTo(entity item, entity player)\r
 {\r
        float _switchweapon;\r
@@ -302,11 +486,22 @@ float Item_GiveTo(entity item, entity player)
                }\r
 \r
                if (item.health)\r
-               if (player.health < item.max_health)\r
                {\r
-                       pickedup = TRUE;\r
-                       player.health = min(player.health + item.health, item.max_health);\r
-                       player.pauserothealth_finished = max(player.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));\r
+                       if(item.dmg && cvar("g_vore")) // consumable item, only if the vore system is enabled\r
+                       {\r
+                               if(player.stomach_load + item.dmg <= player.stomach_maxload)\r
+                               if not(!cvar("g_balance_health_consumable_alwayspickup") && player.health >= item.max_health)\r
+                               {\r
+                                       pickedup = TRUE;\r
+                                       Item_Consumable_Spawn(self, player);\r
+                               }\r
+                       }\r
+                       else if (player.health < item.max_health)\r
+                       {\r
+                               pickedup = TRUE;\r
+                               player.health = min(player.health + item.health, item.max_health);\r
+                               player.pauserothealth_finished = max(player.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));\r
+                       }\r
                }\r
                if (item.armorvalue)\r
                if (player.armorvalue < item.max_armorvalue)\r
@@ -868,6 +1063,7 @@ void spawnfunc_item_health_small (void) {
                self.max_health = g_pickup_healthsmall_max;\r
        if(!self.health)\r
                self.health = g_pickup_healthsmall;\r
+       self.dmg = g_pickup_healthsmall_consumable;\r
        StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "5 Health", IT_5HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);\r
 }\r
 \r
@@ -876,6 +1072,7 @@ void spawnfunc_item_health_medium (void) {
                self.max_health = g_pickup_healthmedium_max;\r
        if(!self.health)\r
                self.health = g_pickup_healthmedium;\r
+       self.dmg = g_pickup_healthmedium_consumable;\r
        StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "25 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);\r
 }\r
 \r
@@ -884,6 +1081,7 @@ void spawnfunc_item_health_large (void) {
                self.max_health = g_pickup_healthlarge_max;\r
        if(!self.health)\r
                self.health = g_pickup_healthlarge;\r
+       self.dmg = g_pickup_healthlarge_consumable;\r
        StartItem ("models/items/g_h50.md3", "misc/largehealth.wav", g_pickup_respawntime_medium, g_pickup_respawntimejitter_medium, "50 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);\r
 }\r
 \r
@@ -898,6 +1096,7 @@ void spawnfunc_item_health_mega (void) {
                self.max_health = g_pickup_healthmega_max;\r
        if(!self.health)\r
                self.health = g_pickup_healthmega;\r
+       self.dmg = g_pickup_healthmega_consumable;\r
        StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "100 Health", IT_HEALTH, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH);\r
 }\r
 \r