From: Lyberta Date: Mon, 21 Aug 2017 00:54:10 +0000 (+0300) Subject: Moved player templates code in server directory. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=99c1b55792c29c17ab274b1a95ee1dd44a71255c;p=xonotic%2Fxonotic-data.pk3dir.git Moved player templates code in server directory. --- diff --git a/qcsrc/common/mutators/mutator/_mod.inc b/qcsrc/common/mutators/mutator/_mod.inc index dc47cc70d6..0d6326fef0 100644 --- a/qcsrc/common/mutators/mutator/_mod.inc +++ b/qcsrc/common/mutators/mutator/_mod.inc @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/qcsrc/common/mutators/mutator/_mod.qh b/qcsrc/common/mutators/mutator/_mod.qh index f5fbe79fe6..917dc6557c 100644 --- a/qcsrc/common/mutators/mutator/_mod.qh +++ b/qcsrc/common/mutators/mutator/_mod.qh @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/qcsrc/common/mutators/mutator/playertemplates/_mod.inc b/qcsrc/common/mutators/mutator/playertemplates/_mod.inc deleted file mode 100644 index 91771cfa56..0000000000 --- a/qcsrc/common/mutators/mutator/playertemplates/_mod.inc +++ /dev/null @@ -1,4 +0,0 @@ -// generated file; do not modify -#ifdef SVQC - #include -#endif diff --git a/qcsrc/common/mutators/mutator/playertemplates/_mod.qh b/qcsrc/common/mutators/mutator/playertemplates/_mod.qh deleted file mode 100644 index b4b3c5a8db..0000000000 --- a/qcsrc/common/mutators/mutator/playertemplates/_mod.qh +++ /dev/null @@ -1,4 +0,0 @@ -// generated file; do not modify -#ifdef SVQC - #include -#endif diff --git a/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc b/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc deleted file mode 100644 index 027c1f26bb..0000000000 --- a/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc +++ /dev/null @@ -1,1077 +0,0 @@ -/// \file -/// \brief Source file that contains implementation of the Player Templates -/// mutator. -/// \author Lyberta -/// \copyright GNU GPLv3 or any later version. - -const string playertemplate_cvar_prefix = "g_player_template_"; - -string PlayerTemplate_GetFullCvarName(string template, string variable) -{ - return strcat(playertemplate_cvar_prefix, template, "_", variable); -} - -string PlayerTemplate_GetDefaultCvarName(string variable) -{ - switch (variable) - { - case "start_health": - { - return "g_balance_health_start"; - } - case "start_armor": - { - return "g_balance_armor_start"; - } - case "start_ammo_shells": - { - return "g_start_ammo_shells"; - } - case "start_ammo_bullets": - { - return "g_start_ammo_nails"; - } - case "start_ammo_rockets": - { - return "g_start_ammo_rockets"; - } - case "start_ammo_cells": - { - return "g_start_ammo_cells"; - } - case "start_ammo_plasma": - { - return "g_start_ammo_plasma"; - } - case "start_ammo_fuel": - { - return "g_start_ammo_fuel"; - } - case "random_start_weapons_count": - { - return "g_random_start_weapons_count"; - } - case "random_start_weapons": - { - return "g_random_start_weapons"; - } - case "random_start_shells": - { - return "g_random_start_shells"; - } - case "random_start_bullets": - { - return "g_random_start_bullets"; - } - case "random_start_rockets": - { - return "g_random_start_rockets"; - } - case "random_start_cells": - { - return "g_random_start_cells"; - } - case "random_start_plasma": - { - return "g_random_start_plasma"; - } - case "health_regen_factor": - { - return "g_balance_health_regen"; - } - case "health_regen_linear": - { - return "g_balance_health_regenlinear"; - } - case "health_rot_factor": - { - return "g_balance_health_rot"; - } - case "health_rot_linear": - { - return "g_balance_health_rotlinear"; - } - case "health_regen_stable": - { - return "g_balance_health_regenstable"; - } - case "health_rot_stable": - { - return "g_balance_health_rotstable"; - } - default: - { - // TODO: Report error. - return ""; - } - } -} - -float PlayerTemplate_GetDefaultFloatValue(string variable) -{ - switch (variable) - { - case "start_health": - case "start_armor": - case "start_ammo_shells": - case "start_ammo_bullets": - case "start_ammo_rockets": - case "start_ammo_cells": - case "start_ammo_plasma": - case "start_ammo_fuel": - case "random_start_weapons_count": - case "random_start_shells": - case "random_start_bullets": - case "random_start_rockets": - case "random_start_cells": - case "random_start_plasma": - case "health_regen_factor": - case "health_regen_linear": - case "health_rot_factor": - case "health_rot_linear": - case "health_regen_stable": - case "health_rot_stable": - { - return cvar(PlayerTemplate_GetDefaultCvarName(variable)); - } - case "unlimited_ammo": - { - return !autocvar_g_use_ammunition; - } - case "default_start_weapons": - { - return 1; - } - case "attack_scale": - case "defense_scale": - { - return 1; - } - case "blaster_self_damage": - { - return 1; - } - default: - { - // TODO: Report error. - return 0; - } - } -} - -string PlayerTemplate_GetDefaultStringValue(string variable) -{ - switch (variable) - { - case "random_start_weapons": - { - cvar_string(PlayerTemplate_GetDefaultCvarName(variable)); - } - case "start_weapons": - { - return ""; - } - default: - { - // TODO: Report error. - return ""; - } - } -} - -float PlayerTemplate_GetFloatValue(string template, string variable) -{ - if (template == "default") - { - return PlayerTemplate_GetDefaultFloatValue(variable); - } - string fullname = PlayerTemplate_GetFullCvarName(template, variable); - if (!(cvar_type(fullname) & CVAR_TYPEFLAG_EXISTS)) - { - return PlayerTemplate_GetDefaultFloatValue(variable); - } - if (cvar_string(fullname) == "default") - { - return PlayerTemplate_GetDefaultFloatValue(variable); - } - return cvar(fullname); -} - -string PlayerTemplate_GetStringValue(string template, string variable) -{ - if (template == "default") - { - return PlayerTemplate_GetDefaultStringValue(variable); - } - string fullname = PlayerTemplate_GetFullCvarName(template, variable); - if (!(cvar_type(fullname) & CVAR_TYPEFLAG_EXISTS)) - { - return PlayerTemplate_GetDefaultStringValue(variable); - } - if (cvar_string(fullname) == "default") - { - return PlayerTemplate_GetDefaultStringValue(variable); - } - return cvar_string(fullname); -} - -float PlayerTemplate_GivePlayerItem(entity player, string template, - string variable) -{ - string value = PlayerTemplate_GetStringValue(template, variable); - if (value == "default") - { - return MUT_ITEMTOUCH_CONTINUE; - } - int numfields = tokenize_console(PlayerTemplate_GetStringValue(template, - variable)); - if (numfields == 0) - { - return MUT_ITEMTOUCH_CONTINUE; - } - for (int i = 1; i < numfields; ++i) - { - switch (i) - { - case 1: - { - GivePlayerHealth(player, stof(argv(i))); - break; - } - case 2: - { - GivePlayerArmor(player, stof(argv(i))); - break; - } - case 3: - { - GivePlayerAmmo(player, ammo_shells, stof(argv(i))); - break; - } - case 4: - { - GivePlayerAmmo(player, ammo_nails, stof(argv(i))); - break; - } - case 5: - { - GivePlayerAmmo(player, ammo_rockets, stof(argv(i))); - break; - } - case 6: - { - GivePlayerAmmo(player, ammo_cells, stof(argv(i))); - break; - } - } - } - switch (argv(0)) - { - case "add": - { - return MUT_ITEMTOUCH_CONTINUE; - } - case "override": - { - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } -} - -void PlayerTemplate_PlayerSpawn(entity player, string template) -{ - if (template == "default") - { - return; - } - // Give health, armor and ammo. - player.health = PlayerTemplate_GetFloatValue(template, "start_health"); - player.armorvalue = PlayerTemplate_GetFloatValue(template, "start_armor"); - if (PlayerTemplate_GetFloatValue(template, "unlimited_ammo")) - { - player.items |= IT_UNLIMITED_AMMO; - } - else - { - player.ammo_shells = PlayerTemplate_GetFloatValue(template, - "start_ammo_shells"); - player.ammo_nails = PlayerTemplate_GetFloatValue(template, - "start_ammo_bullets"); - player.ammo_rockets = PlayerTemplate_GetFloatValue(template, - "start_ammo_rockets"); - player.ammo_cells = PlayerTemplate_GetFloatValue(template, - "start_ammo_cells"); - } - if (autocvar_g_instagib == 1) - { - return; - } - // Give weapons. - if (PlayerTemplate_GetFloatValue(template, "default_start_weapons")) - { - FOREACH(Weapons, it != WEP_Null, - { - if (it.weaponstart) - { - player.weapons |= it.m_wepset; - } - }); - } - int numweapons = tokenize_console(PlayerTemplate_GetStringValue(template, - "start_weapons")); - for (int i = 0; i < numweapons; ++i) - { - string weapon = argv(i); - FOREACH(Weapons, it != WEP_Null, - { - if (it.netname == weapon) - { - player.weapons |= it.m_wepset; - break; - } - }); - } - if (!warmup_stage) - { - GivePlayerRandomWeapons(player, - PlayerTemplate_GetFloatValue(template, - "random_start_weapons_count"), - PlayerTemplate_GetStringValue(template, "random_start_weapons"), - PlayerTemplate_GetFloatValue(template, "random_start_shells"), - PlayerTemplate_GetFloatValue(template, "random_start_bullets"), - PlayerTemplate_GetFloatValue(template, "random_start_rockets"), - PlayerTemplate_GetFloatValue(template, "random_start_cells"), - PlayerTemplate_GetFloatValue(template, "random_start_plasma")); - return; - } - // Give random weapons. - numweapons = tokenize_console(PlayerTemplate_GetStringValue(template, - "random_start_weapons")); - // Give all weapons during warmup stage. - for (int i = 0; i < numweapons; ++i) - { - string weapon = argv(i); - FOREACH(Weapons, it != WEP_Null, - { - if (it.netname == weapon) - { - player.weapons |= it.m_wepset; - break; - } - }); - } -} - -float PlayerTemplate_PlayerRegen(entity player, string template) -{ - if (template == "default") - { - return false; - } - M_ARGV(5, float) = PlayerTemplate_GetFloatValue(template, - "health_regen_factor"); - M_ARGV(6, float) = PlayerTemplate_GetFloatValue(template, - "health_regen_linear"); - M_ARGV(7, float) = PlayerTemplate_GetFloatValue(template, - "health_rot_factor"); - M_ARGV(8, float) = PlayerTemplate_GetFloatValue(template, - "health_rot_linear"); - M_ARGV(9, float) = PlayerTemplate_GetFloatValue(template, - "health_regen_stable"); - M_ARGV(10, float) = PlayerTemplate_GetFloatValue(template, - "health_rot_stable"); - return false; -} - -float PlayerTemplate_ItemTouch(entity player, entity item, string template) -{ - if (template == "default") - { - return MUT_ITEMTOUCH_CONTINUE; - } - switch (item.classname) - { - case "item_health_small": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_health_small"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_HealthSmall, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_health_medium": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_health_medium"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_HealthMedium, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_health_big": - case "item_health_large": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_health_big"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_HealthBig, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_health_mega": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_health_mega"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_HealthMega, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_armor_small": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_armor_small"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_ArmorSmall, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_armor_medium": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_armor_medium"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_ArmorMedium, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_armor_big": - case "item_armor_large": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_armor_big"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_ArmorBig, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_armor_mega": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_armor_mega"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_ArmorMega, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_shells": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_item_shells"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_ITEMPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_bullets": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_item_bullets"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_ITEMPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_rockets": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_item_rockets"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_ITEMPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_cells": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_item_cells"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_ITEMPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "weapon_machinegun": - case "weapon_uzi": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_machinegun"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "weapon_grenadelauncher": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_mortar"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "weapon_electro": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_electro"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "weapon_crylink": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_crylink"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "weapon_nex": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_vortex"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "weapon_hagar": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_hagar"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "weapon_rocketlauncher": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_devastator"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "droppedweapon": - { - float result; - switch (item.weapon) - { - case WEP_SHOTGUN.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_dropped_shotgun"); - break; - } - case WEP_MACHINEGUN.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_dropped_machinegun"); - break; - } - case WEP_MORTAR.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_dropped_mortar"); - break; - } - case WEP_ELECTRO.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_dropped_electro"); - break; - } - case WEP_CRYLINK.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_dropped_crylink"); - break; - } - case WEP_VORTEX.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_dropped_vortex"); - break; - } - case WEP_HAGAR.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_dropped_hagar"); - break; - } - case WEP_DEVASTATOR.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_dropped_devastator"); - break; - } - case WEP_MINE_LAYER.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_dropped_minelayer"); - break; - } - case WEP_HLAC.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_dropped_hlac"); - break; - } - case WEP_RIFLE.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_dropped_rifle"); - break; - } - case WEP_SEEKER.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_dropped_seeker"); - break; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - delete(item); - sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "replacedweapon": - { - float result; - switch (item.weapon) - { - case WEP_MINE_LAYER.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_minelayer"); - break; - } - case WEP_HLAC.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_hlac"); - break; - } - case WEP_RIFLE.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_rifle"); - break; - } - case WEP_SEEKER.m_id: - { - result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_weapon_seeker"); - break; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_strength": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_item_strength"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_Strength, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - case "item_invincible": - { - float result = PlayerTemplate_GivePlayerItem(player, template, - "pickup_item_shield"); - switch (result) - { - case MUT_ITEMTOUCH_CONTINUE: - { - return MUT_ITEMTOUCH_CONTINUE; - } - case MUT_ITEMTOUCH_RETURN: - { - Item_ScheduleRespawn(item); - sound(player, CH_TRIGGER, SND_Shield, VOL_BASE, - ATTEN_NORM); - return MUT_ITEMTOUCH_RETURN; - } - default: - { - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - default: - { - switch (item.netname) - { - case "Vaporizer Ammo": - case "Extra life": - case "Invisibility": - case "Speed": - { - return MUT_ITEMTOUCH_CONTINUE; - } - default: - { - PrintToChatAll(strcat("Unrecognized item, classname: ", - item.classname, " netname: ", item.netname)); - return MUT_ITEMTOUCH_CONTINUE; - } - } - } - } - return MUT_ITEMTOUCH_CONTINUE; -} - -float PlayerTemplate_Damage_Calculate(entity attacker, string attackertemplate, - entity victim, string victimtemplate, float deathtype, float damage) -{ - if (autocvar_g_instagib == 1) - { - return damage; - } - if ((attacker == victim) && (DEATH_ISWEAPON(deathtype, WEP_BLASTER)) && - (PlayerTemplate_GetFloatValue(victimtemplate, "blaster_self_damage") == - 0)) - { - return 0; - } - damage *= PlayerTemplate_GetFloatValue(attackertemplate, "attack_scale"); - damage /= PlayerTemplate_GetFloatValue(victimtemplate, "defense_scale"); - return damage; -} diff --git a/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qh b/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qh deleted file mode 100644 index 5d93700acc..0000000000 --- a/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qh +++ /dev/null @@ -1,79 +0,0 @@ -/// \file -/// \brief Header file that describes the Player Templates mutator. -/// \author Lyberta -/// \copyright GNU GPLv3 or any later version. - -#pragma once - -/// \brief Returns the full name of the player template cvar. -/// \param[in] template Name of the template. -/// \param[in] variable Name of the variable. -/// \return Full name of the variable. -string PlayerTemplate_GetFullCvarName(string template, string variable); - -/// \brief Returns the name of the cvar that is used for default value. -/// \param[in] Name of the player template variable. -/// \return Name of the cvar that is used for default value. -string PlayerTemplate_GetDefaultCvarName(string variable); - -/// \brief Returns the default floating point value of the player template -/// variable. -/// \param[in] variable Name of the variable. -/// \return Default floating point value of the player template variable. -float PlayerTemplate_GetDefaultFloatValue(string variable); - -/// \brief Returns the default string value of the player template variable. -/// \param[in] variable Name of the variable. -/// \return Default string value of the player template variable. -string PlayerTemplate_GetDefaultStringValue(string variable); - -/// \brief Gets the floating point value of the variable from the given -/// template. -/// \param[in] template Name of the template. -/// \param[in] variable Name of the variable. -/// \return Value of the variable. -float PlayerTemplate_GetFloatValue(string template, string variable); - -/// \brief Gets the string value of the variable from the given template. -/// \param[in] template Name of the template. -/// \param[in] variable Name of the variable. -/// \return Value of the variable. -string PlayerTemplate_GetStringValue(string template, string variable); - -/// \brief Gives player items according to the given template's variable. -/// \param[in] player Player to give items to. -/// \param[in] template Name of the template. -/// \param[in] variable Name of the variable. -/// \return Enum value to pass to mutator hook. -float PlayerTemplate_GivePlayerItem(entity player, string template, - string variable); - -/// \brief Setups the player during spawn according to the given template. -/// \param[in] player Player to setup. -/// \param[in] template Name of the template. -/// \return No return. -void PlayerTemplate_PlayerSpawn(entity player, string template); - -/// \brief Regenerates player health according to the given template. -/// \param[in] player Player to regenerate. -/// \param[in] template Name of the template. -/// \return Value to pass to mutator hook. -float PlayerTemplate_PlayerRegen(entity player, string template); - -/// \brief Gives player items according to the given template. -/// \param[in] player Player to give items to. -/// \param[in] item Item which player has picked up. -/// \param[in] template Name of the template. -/// \return Enum value to pass to mutator hook. -float PlayerTemplate_ItemTouch(entity player, entity item, string template); - -/// \brief Changes the damage done using templates' attack and defense scales. -/// \param[in] attacke Attacker entity. -/// \param[in] attackertemplate Template of the attacker. -/// \param[in] victim Victim entity. -/// \param[in] victimtemplate Template of the victim. -/// \param[in] deathtype Type of the damage. -/// \param[in] damage Damage to adjust. -/// \return Adjusted damage. -float PlayerTemplate_Damage_Calculate(entity attacker, string attackertemplate, - entity victim, string victimtemplate, float deathtype, float damage); diff --git a/qcsrc/server/_mod.inc b/qcsrc/server/_mod.inc index 87a8d56892..204d81e5c5 100644 --- a/qcsrc/server/_mod.inc +++ b/qcsrc/server/_mod.inc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/server/_mod.qh b/qcsrc/server/_mod.qh index 2967c110ce..9092faafc0 100644 --- a/qcsrc/server/_mod.qh +++ b/qcsrc/server/_mod.qh @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/server/playertemplates.qc b/qcsrc/server/playertemplates.qc new file mode 100644 index 0000000000..e2de131e74 --- /dev/null +++ b/qcsrc/server/playertemplates.qc @@ -0,0 +1,1079 @@ +/// \file +/// \brief Source file that contains implementation of the Player Templates +/// mutator. +/// \author Lyberta +/// \copyright GNU GPLv3 or any later version. + +const string playertemplate_cvar_prefix = "g_player_template_"; + +string PlayerTemplate_GetFullCvarName(string template, string variable) +{ + return strcat(playertemplate_cvar_prefix, template, "_", variable); +} + +string PlayerTemplate_GetDefaultCvarName(string variable) +{ + switch (variable) + { + case "start_health": + { + return "g_balance_health_start"; + } + case "start_armor": + { + return "g_balance_armor_start"; + } + case "start_ammo_shells": + { + return "g_start_ammo_shells"; + } + case "start_ammo_bullets": + { + return "g_start_ammo_nails"; + } + case "start_ammo_rockets": + { + return "g_start_ammo_rockets"; + } + case "start_ammo_cells": + { + return "g_start_ammo_cells"; + } + case "start_ammo_plasma": + { + return "g_start_ammo_plasma"; + } + case "start_ammo_fuel": + { + return "g_start_ammo_fuel"; + } + case "random_start_weapons_count": + { + return "g_random_start_weapons_count"; + } + case "random_start_weapons": + { + return "g_random_start_weapons"; + } + case "random_start_shells": + { + return "g_random_start_shells"; + } + case "random_start_bullets": + { + return "g_random_start_bullets"; + } + case "random_start_rockets": + { + return "g_random_start_rockets"; + } + case "random_start_cells": + { + return "g_random_start_cells"; + } + case "random_start_plasma": + { + return "g_random_start_plasma"; + } + case "health_regen_factor": + { + return "g_balance_health_regen"; + } + case "health_regen_linear": + { + return "g_balance_health_regenlinear"; + } + case "health_rot_factor": + { + return "g_balance_health_rot"; + } + case "health_rot_linear": + { + return "g_balance_health_rotlinear"; + } + case "health_regen_stable": + { + return "g_balance_health_regenstable"; + } + case "health_rot_stable": + { + return "g_balance_health_rotstable"; + } + default: + { + // TODO: Report error. + return ""; + } + } +} + +float PlayerTemplate_GetDefaultFloatValue(string variable) +{ + switch (variable) + { + case "start_health": + case "start_armor": + case "start_ammo_shells": + case "start_ammo_bullets": + case "start_ammo_rockets": + case "start_ammo_cells": + case "start_ammo_plasma": + case "start_ammo_fuel": + case "random_start_weapons_count": + case "random_start_shells": + case "random_start_bullets": + case "random_start_rockets": + case "random_start_cells": + case "random_start_plasma": + case "health_regen_factor": + case "health_regen_linear": + case "health_rot_factor": + case "health_rot_linear": + case "health_regen_stable": + case "health_rot_stable": + { + return cvar(PlayerTemplate_GetDefaultCvarName(variable)); + } + case "unlimited_ammo": + { + return !autocvar_g_use_ammunition; + } + case "default_start_weapons": + { + return 1; + } + case "attack_scale": + case "defense_scale": + { + return 1; + } + case "blaster_self_damage": + { + return 1; + } + default: + { + // TODO: Report error. + return 0; + } + } +} + +string PlayerTemplate_GetDefaultStringValue(string variable) +{ + switch (variable) + { + case "random_start_weapons": + { + cvar_string(PlayerTemplate_GetDefaultCvarName(variable)); + } + case "start_weapons": + { + return ""; + } + default: + { + // TODO: Report error. + return ""; + } + } +} + +float PlayerTemplate_GetFloatValue(string template, string variable) +{ + if (template == "default") + { + return PlayerTemplate_GetDefaultFloatValue(variable); + } + string fullname = PlayerTemplate_GetFullCvarName(template, variable); + if (!(cvar_type(fullname) & CVAR_TYPEFLAG_EXISTS)) + { + return PlayerTemplate_GetDefaultFloatValue(variable); + } + if (cvar_string(fullname) == "default") + { + return PlayerTemplate_GetDefaultFloatValue(variable); + } + return cvar(fullname); +} + +string PlayerTemplate_GetStringValue(string template, string variable) +{ + if (template == "default") + { + return PlayerTemplate_GetDefaultStringValue(variable); + } + string fullname = PlayerTemplate_GetFullCvarName(template, variable); + if (!(cvar_type(fullname) & CVAR_TYPEFLAG_EXISTS)) + { + return PlayerTemplate_GetDefaultStringValue(variable); + } + if (cvar_string(fullname) == "default") + { + return PlayerTemplate_GetDefaultStringValue(variable); + } + return cvar_string(fullname); +} + +float PlayerTemplate_GivePlayerItem(entity player, string template, + string variable) +{ + string value = PlayerTemplate_GetStringValue(template, variable); + if (value == "default") + { + return MUT_ITEMTOUCH_CONTINUE; + } + int numfields = tokenize_console(PlayerTemplate_GetStringValue(template, + variable)); + if (numfields == 0) + { + return MUT_ITEMTOUCH_CONTINUE; + } + for (int i = 1; i < numfields; ++i) + { + switch (i) + { + case 1: + { + GivePlayerHealth(player, stof(argv(i))); + break; + } + case 2: + { + GivePlayerArmor(player, stof(argv(i))); + break; + } + case 3: + { + GivePlayerAmmo(player, ammo_shells, stof(argv(i))); + break; + } + case 4: + { + GivePlayerAmmo(player, ammo_nails, stof(argv(i))); + break; + } + case 5: + { + GivePlayerAmmo(player, ammo_rockets, stof(argv(i))); + break; + } + case 6: + { + GivePlayerAmmo(player, ammo_cells, stof(argv(i))); + break; + } + } + } + switch (argv(0)) + { + case "add": + { + return MUT_ITEMTOUCH_CONTINUE; + } + case "override": + { + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } +} + +// =========================== Hook handlers ================================= + +void PlayerTemplate_PlayerSpawn(entity player, string template) +{ + if (template == "default") + { + return; + } + // Give health, armor and ammo. + player.health = PlayerTemplate_GetFloatValue(template, "start_health"); + player.armorvalue = PlayerTemplate_GetFloatValue(template, "start_armor"); + if (PlayerTemplate_GetFloatValue(template, "unlimited_ammo")) + { + player.items |= IT_UNLIMITED_AMMO; + } + else + { + player.ammo_shells = PlayerTemplate_GetFloatValue(template, + "start_ammo_shells"); + player.ammo_nails = PlayerTemplate_GetFloatValue(template, + "start_ammo_bullets"); + player.ammo_rockets = PlayerTemplate_GetFloatValue(template, + "start_ammo_rockets"); + player.ammo_cells = PlayerTemplate_GetFloatValue(template, + "start_ammo_cells"); + } + if (autocvar_g_instagib == 1) + { + return; + } + // Give weapons. + if (PlayerTemplate_GetFloatValue(template, "default_start_weapons")) + { + FOREACH(Weapons, it != WEP_Null, + { + if (it.weaponstart) + { + player.weapons |= it.m_wepset; + } + }); + } + int numweapons = tokenize_console(PlayerTemplate_GetStringValue(template, + "start_weapons")); + for (int i = 0; i < numweapons; ++i) + { + string weapon = argv(i); + FOREACH(Weapons, it != WEP_Null, + { + if (it.netname == weapon) + { + player.weapons |= it.m_wepset; + break; + } + }); + } + if (!warmup_stage) + { + GivePlayerRandomWeapons(player, + PlayerTemplate_GetFloatValue(template, + "random_start_weapons_count"), + PlayerTemplate_GetStringValue(template, "random_start_weapons"), + PlayerTemplate_GetFloatValue(template, "random_start_shells"), + PlayerTemplate_GetFloatValue(template, "random_start_bullets"), + PlayerTemplate_GetFloatValue(template, "random_start_rockets"), + PlayerTemplate_GetFloatValue(template, "random_start_cells"), + PlayerTemplate_GetFloatValue(template, "random_start_plasma")); + return; + } + // Give random weapons. + numweapons = tokenize_console(PlayerTemplate_GetStringValue(template, + "random_start_weapons")); + // Give all weapons during warmup stage. + for (int i = 0; i < numweapons; ++i) + { + string weapon = argv(i); + FOREACH(Weapons, it != WEP_Null, + { + if (it.netname == weapon) + { + player.weapons |= it.m_wepset; + break; + } + }); + } +} + +float PlayerTemplate_PlayerRegen(entity player, string template) +{ + if (template == "default") + { + return false; + } + M_ARGV(5, float) = PlayerTemplate_GetFloatValue(template, + "health_regen_factor"); + M_ARGV(6, float) = PlayerTemplate_GetFloatValue(template, + "health_regen_linear"); + M_ARGV(7, float) = PlayerTemplate_GetFloatValue(template, + "health_rot_factor"); + M_ARGV(8, float) = PlayerTemplate_GetFloatValue(template, + "health_rot_linear"); + M_ARGV(9, float) = PlayerTemplate_GetFloatValue(template, + "health_regen_stable"); + M_ARGV(10, float) = PlayerTemplate_GetFloatValue(template, + "health_rot_stable"); + return false; +} + +float PlayerTemplate_ItemTouch(entity player, entity item, string template) +{ + if (template == "default") + { + return MUT_ITEMTOUCH_CONTINUE; + } + switch (item.classname) + { + case "item_health_small": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_health_small"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_HealthSmall, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_health_medium": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_health_medium"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_HealthMedium, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_health_big": + case "item_health_large": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_health_big"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_HealthBig, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_health_mega": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_health_mega"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_HealthMega, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_armor_small": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_armor_small"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_ArmorSmall, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_armor_medium": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_armor_medium"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_ArmorMedium, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_armor_big": + case "item_armor_large": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_armor_big"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_ArmorBig, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_armor_mega": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_armor_mega"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_ArmorMega, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_shells": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_item_shells"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_ITEMPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_bullets": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_item_bullets"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_ITEMPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_rockets": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_item_rockets"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_ITEMPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_cells": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_item_cells"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_ITEMPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "weapon_machinegun": + case "weapon_uzi": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_machinegun"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "weapon_grenadelauncher": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_mortar"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "weapon_electro": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_electro"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "weapon_crylink": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_crylink"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "weapon_nex": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_vortex"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "weapon_hagar": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_hagar"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "weapon_rocketlauncher": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_devastator"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "droppedweapon": + { + float result; + switch (item.weapon) + { + case WEP_SHOTGUN.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_dropped_shotgun"); + break; + } + case WEP_MACHINEGUN.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_dropped_machinegun"); + break; + } + case WEP_MORTAR.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_dropped_mortar"); + break; + } + case WEP_ELECTRO.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_dropped_electro"); + break; + } + case WEP_CRYLINK.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_dropped_crylink"); + break; + } + case WEP_VORTEX.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_dropped_vortex"); + break; + } + case WEP_HAGAR.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_dropped_hagar"); + break; + } + case WEP_DEVASTATOR.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_dropped_devastator"); + break; + } + case WEP_MINE_LAYER.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_dropped_minelayer"); + break; + } + case WEP_HLAC.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_dropped_hlac"); + break; + } + case WEP_RIFLE.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_dropped_rifle"); + break; + } + case WEP_SEEKER.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_dropped_seeker"); + break; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + delete(item); + sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "replacedweapon": + { + float result; + switch (item.weapon) + { + case WEP_MINE_LAYER.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_minelayer"); + break; + } + case WEP_HLAC.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_hlac"); + break; + } + case WEP_RIFLE.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_rifle"); + break; + } + case WEP_SEEKER.m_id: + { + result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_weapon_seeker"); + break; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_WEAPONPICKUP, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_strength": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_item_strength"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_Strength, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + case "item_invincible": + { + float result = PlayerTemplate_GivePlayerItem(player, template, + "pickup_item_shield"); + switch (result) + { + case MUT_ITEMTOUCH_CONTINUE: + { + return MUT_ITEMTOUCH_CONTINUE; + } + case MUT_ITEMTOUCH_RETURN: + { + Item_ScheduleRespawn(item); + sound(player, CH_TRIGGER, SND_Shield, VOL_BASE, + ATTEN_NORM); + return MUT_ITEMTOUCH_RETURN; + } + default: + { + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + default: + { + switch (item.netname) + { + case "Vaporizer Ammo": + case "Extra life": + case "Invisibility": + case "Speed": + { + return MUT_ITEMTOUCH_CONTINUE; + } + default: + { + PrintToChatAll(strcat("Unrecognized item, classname: ", + item.classname, " netname: ", item.netname)); + return MUT_ITEMTOUCH_CONTINUE; + } + } + } + } + return MUT_ITEMTOUCH_CONTINUE; +} + +float PlayerTemplate_Damage_Calculate(entity attacker, string attackertemplate, + entity victim, string victimtemplate, float deathtype, float damage) +{ + if (autocvar_g_instagib == 1) + { + return damage; + } + if ((attacker == victim) && (DEATH_ISWEAPON(deathtype, WEP_BLASTER)) && + (PlayerTemplate_GetFloatValue(victimtemplate, "blaster_self_damage") == + 0)) + { + return 0; + } + damage *= PlayerTemplate_GetFloatValue(attackertemplate, "attack_scale"); + damage /= PlayerTemplate_GetFloatValue(victimtemplate, "defense_scale"); + return damage; +} diff --git a/qcsrc/server/playertemplates.qh b/qcsrc/server/playertemplates.qh new file mode 100644 index 0000000000..619c1b79fc --- /dev/null +++ b/qcsrc/server/playertemplates.qh @@ -0,0 +1,81 @@ +/// \file +/// \brief Header file that describes the Player Templates mutator. +/// \author Lyberta +/// \copyright GNU GPLv3 or any later version. + +#pragma once + +/// \brief Returns the full name of the player template cvar. +/// \param[in] template Name of the template. +/// \param[in] variable Name of the variable. +/// \return Full name of the variable. +string PlayerTemplate_GetFullCvarName(string template, string variable); + +/// \brief Returns the name of the cvar that is used for default value. +/// \param[in] Name of the player template variable. +/// \return Name of the cvar that is used for default value. +string PlayerTemplate_GetDefaultCvarName(string variable); + +/// \brief Returns the default floating point value of the player template +/// variable. +/// \param[in] variable Name of the variable. +/// \return Default floating point value of the player template variable. +float PlayerTemplate_GetDefaultFloatValue(string variable); + +/// \brief Returns the default string value of the player template variable. +/// \param[in] variable Name of the variable. +/// \return Default string value of the player template variable. +string PlayerTemplate_GetDefaultStringValue(string variable); + +/// \brief Gets the floating point value of the variable from the given +/// template. +/// \param[in] template Name of the template. +/// \param[in] variable Name of the variable. +/// \return Value of the variable. +float PlayerTemplate_GetFloatValue(string template, string variable); + +/// \brief Gets the string value of the variable from the given template. +/// \param[in] template Name of the template. +/// \param[in] variable Name of the variable. +/// \return Value of the variable. +string PlayerTemplate_GetStringValue(string template, string variable); + +/// \brief Gives player items according to the given template's variable. +/// \param[in] player Player to give items to. +/// \param[in] template Name of the template. +/// \param[in] variable Name of the variable. +/// \return Enum value to pass to mutator hook. +float PlayerTemplate_GivePlayerItem(entity player, string template, + string variable); + +// =========================== Hook handlers ================================= + +/// \brief Setups the player during spawn according to the given template. +/// \param[in] player Player to setup. +/// \param[in] template Name of the template. +/// \return No return. +void PlayerTemplate_PlayerSpawn(entity player, string template); + +/// \brief Regenerates player health according to the given template. +/// \param[in] player Player to regenerate. +/// \param[in] template Name of the template. +/// \return Value to pass to mutator hook. +float PlayerTemplate_PlayerRegen(entity player, string template); + +/// \brief Gives player items according to the given template. +/// \param[in] player Player to give items to. +/// \param[in] item Item which player has picked up. +/// \param[in] template Name of the template. +/// \return Enum value to pass to mutator hook. +float PlayerTemplate_ItemTouch(entity player, entity item, string template); + +/// \brief Changes the damage done using templates' attack and defense scales. +/// \param[in] attacke Attacker entity. +/// \param[in] attackertemplate Template of the attacker. +/// \param[in] victim Victim entity. +/// \param[in] victimtemplate Template of the victim. +/// \param[in] deathtype Type of the damage. +/// \param[in] damage Damage to adjust. +/// \return Adjusted damage. +float PlayerTemplate_Damage_Calculate(entity attacker, string attackertemplate, + entity victim, string victimtemplate, float deathtype, float damage);