From e110811d01fc7895d1e6c7a3dad41ff8acbdb835 Mon Sep 17 00:00:00 2001 From: Lyberta Date: Wed, 16 Aug 2017 04:12:53 +0300 Subject: [PATCH] Added random start weapons. --- balance-mario.cfg | 7 +++ balance-nexuiz25.cfg | 7 +++ balance-overkill.cfg | 7 +++ balance-samual.cfg | 7 +++ balance-xdf.cfg | 7 +++ balance-xonotic.cfg | 7 +++ balance-xpm.cfg | 7 +++ qcsrc/common/t_items.qc | 81 +++++++++++++++++++++++++++++++++++ qcsrc/common/t_items.qh | 13 ++++++ qcsrc/server/client.qc | 4 ++ qcsrc/server/miscfunctions.qc | 11 +++++ qcsrc/server/miscfunctions.qh | 6 +++ 12 files changed, 164 insertions(+) diff --git a/balance-mario.cfg b/balance-mario.cfg index 42cf31196..eabbff577 100644 --- a/balance-mario.cfg +++ b/balance-mario.cfg @@ -9,6 +9,13 @@ set g_start_ammo_rockets 0 set g_start_ammo_cells 0 set g_start_ammo_plasma 0 set g_start_ammo_fuel 0 +set g_num_random_start_weapons 0 +set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator" +set g_random_start_shells 15 +set g_random_start_bullets 80 +set g_random_start_rockets 40 +set g_random_start_cells 30 +set g_random_start_plasma 30 set g_warmup_start_health 100 "starting values when being in warmup-stage" set g_warmup_start_armor 100 "starting values when being in warmup-stage" set g_warmup_start_ammo_shells 30 "starting values when being in warmup-stage" diff --git a/balance-nexuiz25.cfg b/balance-nexuiz25.cfg index 4967fa7e4..b31df84a6 100644 --- a/balance-nexuiz25.cfg +++ b/balance-nexuiz25.cfg @@ -9,6 +9,13 @@ set g_start_ammo_rockets 0 set g_start_ammo_cells 0 set g_start_ammo_plasma 0 set g_start_ammo_fuel 0 +set g_num_random_start_weapons 0 +set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator" +set g_random_start_shells 15 +set g_random_start_bullets 80 +set g_random_start_rockets 15 +set g_random_start_cells 25 +set g_random_start_plasma 25 set g_warmup_start_health 250 "starting values when being in warmup-stage" set g_warmup_start_armor 100 "starting values when being in warmup-stage" set g_warmup_start_ammo_shells 50 "starting values when being in warmup-stage" diff --git a/balance-overkill.cfg b/balance-overkill.cfg index fc99616f9..eb9fe4fd4 100644 --- a/balance-overkill.cfg +++ b/balance-overkill.cfg @@ -9,6 +9,13 @@ set g_start_ammo_rockets 0 set g_start_ammo_cells 0 set g_start_ammo_plasma 0 set g_start_ammo_fuel 0 +set g_num_random_start_weapons 0 +set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator" +set g_random_start_shells 15 +set g_random_start_bullets 80 +set g_random_start_rockets 40 +set g_random_start_cells 30 +set g_random_start_plasma 30 set g_warmup_start_health 100 "starting values when being in warmup-stage" set g_warmup_start_armor 100 "starting values when being in warmup-stage" set g_warmup_start_ammo_shells 30 "starting values when being in warmup-stage" diff --git a/balance-samual.cfg b/balance-samual.cfg index 4357eff76..f1d81cab1 100644 --- a/balance-samual.cfg +++ b/balance-samual.cfg @@ -9,6 +9,13 @@ set g_start_ammo_rockets 0 set g_start_ammo_cells 0 set g_start_ammo_plasma 0 set g_start_ammo_fuel 0 +set g_num_random_start_weapons 0 +set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator" +set g_random_start_shells 15 +set g_random_start_bullets 80 +set g_random_start_rockets 40 +set g_random_start_cells 30 +set g_random_start_plasma 30 set g_warmup_start_health 100 "starting values when being in warmup-stage" set g_warmup_start_armor 100 "starting values when being in warmup-stage" set g_warmup_start_ammo_shells 30 "starting values when being in warmup-stage" diff --git a/balance-xdf.cfg b/balance-xdf.cfg index a7d6b4374..87643b8b2 100644 --- a/balance-xdf.cfg +++ b/balance-xdf.cfg @@ -9,6 +9,13 @@ set g_start_ammo_rockets 0 set g_start_ammo_cells 0 set g_start_ammo_plasma 0 set g_start_ammo_fuel 0 +set g_num_random_start_weapons 0 +set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator" +set g_random_start_shells 15 +set g_random_start_bullets 80 +set g_random_start_rockets 40 +set g_random_start_cells 30 +set g_random_start_plasma 30 set g_warmup_start_health 100 "starting values when being in warmup-stage" set g_warmup_start_armor 100 "starting values when being in warmup-stage" set g_warmup_start_ammo_shells 30 "starting values when being in warmup-stage" diff --git a/balance-xonotic.cfg b/balance-xonotic.cfg index 5bd1536fe..02b928c90 100644 --- a/balance-xonotic.cfg +++ b/balance-xonotic.cfg @@ -9,6 +9,13 @@ set g_start_ammo_rockets 0 set g_start_ammo_cells 0 set g_start_ammo_plasma 0 set g_start_ammo_fuel 0 +set g_num_random_start_weapons 0 +set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator" +set g_random_start_shells 15 +set g_random_start_bullets 80 +set g_random_start_rockets 40 +set g_random_start_cells 30 +set g_random_start_plasma 30 set g_warmup_start_health 100 "starting values when being in warmup-stage" set g_warmup_start_armor 100 "starting values when being in warmup-stage" set g_warmup_start_ammo_shells 30 "starting values when being in warmup-stage" diff --git a/balance-xpm.cfg b/balance-xpm.cfg index 5c14aa362..9731f7ee0 100644 --- a/balance-xpm.cfg +++ b/balance-xpm.cfg @@ -9,6 +9,13 @@ set g_start_ammo_rockets 0 set g_start_ammo_cells 0 set g_start_ammo_plasma 0 set g_start_ammo_fuel 0 +set g_num_random_start_weapons 0 +set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator" +set g_random_start_shells 15 +set g_random_start_bullets 80 +set g_random_start_rockets 40 +set g_random_start_cells 30 +set g_random_start_plasma 30 set g_warmup_start_health 100 "starting values when being in warmup-stage" set g_warmup_start_armor 100 "starting values when being in warmup-stage" set g_warmup_start_ammo_shells 30 "starting values when being in warmup-stage" diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 61bc7dc57..4c0125afb 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -711,6 +711,87 @@ void GivePlayerAmmo(entity player, .float ammotype, float amount) player.(ammotype) = min(player.(ammotype) + amount, maxvalue); } +void GivePlayerRandomWeapons(entity player, int num_weapons, + string weapon_names, float shells, float bullets, float rockets, + float cells, float plasma) +{ + if (num_weapons == 0) + { + return; + } + int num_potential_weapons = tokenize_console(weapon_names); + for (int i = 0; i < num_weapons; ++i) + { + RandomSelection_Init(); + for (int j = 0; j < num_potential_weapons; ++j) + { + string weapon = argv(j); + FOREACH(Weapons, it != WEP_Null, + { + // Finding a weapon which player doesn't have. + if (!(player.weapons & it.m_wepset) && (it.netname == weapon)) + { + RandomSelection_AddEnt(it, 1, 1); + break; + } + }); + } + if (RandomSelection_chosen_ent == NULL) + { + return; + } + player.weapons |= RandomSelection_chosen_ent.m_wepset; + switch (RandomSelection_chosen_ent.ammo_field) + { + case (ammo_shells): + { + if (player.ammo_shells != 0) + { + break; + } + GivePlayerAmmo(player, ammo_shells, shells); + break; + } + case (ammo_nails): + { + if (player.ammo_nails != 0) + { + break; + } + GivePlayerAmmo(player, ammo_nails, bullets); + break; + } + case (ammo_rockets): + { + if (player.ammo_rockets != 0) + { + break; + } + GivePlayerAmmo(player, ammo_rockets, rockets); + break; + } + case (ammo_cells): + { + if (player.ammo_cells != 0) + { + break; + } + GivePlayerAmmo(player, ammo_cells, cells); + break; + } + case (ammo_plasma): + { + if (player.ammo_plasma != 0) + { + break; + } + GivePlayerAmmo(player, ammo_plasma, plasma); + break; + } + } + } +} + float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode) { if (!item.(ammotype)) diff --git a/qcsrc/common/t_items.qh b/qcsrc/common/t_items.qh index 331d3ac8c..1fc84a032 100644 --- a/qcsrc/common/t_items.qh +++ b/qcsrc/common/t_items.qh @@ -105,6 +105,19 @@ void GivePlayerArmor(entity player, float amount); /// \return No return. void GivePlayerAmmo(entity player, .float ammotype, float amount); +/// \brief Give several random weapons and ammo to the player. +/// \param[in,out] player Player to give weapons to. +/// \param[in] num_weapons Number of weapons to give. +/// \param[in] weapon_names Names of weapons to give separated by spaces. +/// \param[in] shells Amount of shells to give with shell-based weapon. +/// \param[in] bullets Amount of bullets to give with bullet-based weapon. +/// \param[in] rockets Amount of rockets to give with rocket-based weapon. +/// \param[in] cells Amount of cells to give with cell-based weapon. +/// \param[in] cells Amount of plasma to give with plasma-based weapon. +void GivePlayerRandomWeapons(entity player, int num_weapons, + string weapon_names, float shells, float bullets, float rockets, + float cells, float plasma); + float ITEM_MODE_NONE = 0; float ITEM_MODE_HEALTH = 1; float ITEM_MODE_ARMOR = 2; diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index b0eb75ae4..43fd0be91 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -546,6 +546,10 @@ void PutPlayerInServer(entity this) this.health = start_health; this.armorvalue = start_armorvalue; this.weapons = start_weapons; + GivePlayerRandomWeapons(this, num_random_start_weapons, + cvar_string("g_random_start_weapons"), random_start_shells, + random_start_bullets, random_start_rockets, random_start_cells, + random_start_plasma); } SetSpectatee_status(this, 0); diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 78d290c81..1abcf850c 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -643,6 +643,12 @@ void readplayerstartcvars() start_ammo_cells = cvar("g_start_ammo_cells"); start_ammo_plasma = cvar("g_start_ammo_plasma"); start_ammo_fuel = cvar("g_start_ammo_fuel"); + num_random_start_weapons = cvar("g_num_random_start_weapons"); + random_start_shells = cvar("g_random_start_shells"); + random_start_bullets = cvar("g_random_start_bullets"); + random_start_rockets = cvar("g_random_start_rockets"); + random_start_cells = cvar("g_random_start_cells"); + random_start_plasma = cvar("g_random_start_plasma"); } if (warmup_stage) @@ -711,6 +717,11 @@ void readplayerstartcvars() start_ammo_cells = max(0, start_ammo_cells); start_ammo_plasma = max(0, start_ammo_plasma); start_ammo_fuel = max(0, start_ammo_fuel); + random_start_shells = max(0, random_start_shells); + random_start_bullets = max(0, random_start_bullets); + random_start_rockets = max(0, random_start_rockets); + random_start_cells = max(0, random_start_cells); + random_start_plasma = max(0, random_start_plasma); warmup_start_ammo_shells = max(0, warmup_start_ammo_shells); warmup_start_ammo_nails = max(0, warmup_start_ammo_nails); diff --git a/qcsrc/server/miscfunctions.qh b/qcsrc/server/miscfunctions.qh index 1c01a5737..23a5778e0 100644 --- a/qcsrc/server/miscfunctions.qh +++ b/qcsrc/server/miscfunctions.qh @@ -188,6 +188,12 @@ float start_ammo_rockets; float start_ammo_cells; float start_ammo_plasma; float start_ammo_fuel; +int num_random_start_weapons; +float random_start_shells; +float random_start_bullets; +float random_start_rockets; +float random_start_cells; +float random_start_plasma; float start_health; float start_armorvalue; WepSet warmup_start_weapons; -- 2.39.2