From: Lyberta Date: Sat, 26 Aug 2017 23:09:41 +0000 (+0300) Subject: Merged Lyberta/GivePlayerAmmo into Lyberta/RandomStartWeapons. X-Git-Tag: xonotic-v0.8.5~2459^2~21 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e98ed192eac2c7983d5395418f3e9396024fa9ba;p=xonotic%2Fxonotic-data.pk3dir.git Merged Lyberta/GivePlayerAmmo into Lyberta/RandomStartWeapons. --- e98ed192eac2c7983d5395418f3e9396024fa9ba diff --cc qcsrc/common/t_items.qc index 4c0125afb,6ee7c1d8b..79552505a --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@@ -702,97 -749,17 +749,98 @@@ void GivePlayerAmmo(entity player, .flo maxvalue = g_pickup_nails_max; break; } - case ammo_fuel: - { - maxvalue = g_pickup_fuel_max; - break; - } } - player.(ammotype) = min(player.(ammotype) + amount, maxvalue); + player.(ammotype) = min(player.(ammotype) + amount, + min(maxvalue, ITEM_COUNT_HARD_LIMIT)); + } + + void GivePlayerFuel(entity player, float amount) + { + GivePlayerResource(player, ammo_fuel, amount); } +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) + float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax) { if (!item.(ammotype)) return false; diff --cc qcsrc/common/t_items.qh index 009fc926a,14cbd8e3f..af7d91758 --- a/qcsrc/common/t_items.qh +++ b/qcsrc/common/t_items.qh @@@ -105,25 -115,13 +115,27 @@@ void GivePlayerArmor(entity player, flo /// \return No return. void GivePlayerAmmo(entity player, .float ammotype, float amount); + /// \brief Gives fuel to the player. + /// \param[in,out] player Player to give fuel to. + /// \param[in] amount Amount of fuel to give. + /// \return No return. + void GivePlayerFuel(entity player, 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. +/// \return No return. +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; - float ITEM_MODE_FUEL = 3; - float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode); + float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax); float Item_GiveTo(entity item, entity player);