X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Ft_items.qc;h=454965ed658e67f515f85226ecdd88a6b344fb71;hb=d032c6d2d46fb6f1eab6329e75fe9f2330a42597;hp=ecc76cf11c6f0e10d88262ccbee53dfaaf899735;hpb=0a662cca65d7a8ecfb168681cfb91fb3c1b7a7d1;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index ecc76cf11..454965ed6 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -682,191 +682,109 @@ void Item_ScheduleInitialRespawn(entity e) Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : ITEM_RESPAWNTIME_INITIAL(e))); } -int GetResourceType(.float resource_property) +void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names, + float shells, float bullets, float rockets, float cells, float plasma) { - switch (resource_property) - { - case health: { return RESOURCE_HEALTH; } - case armorvalue: { return RESOURCE_ARMOR; } - case ammo_shells: { return RESOURCE_SHELLS; } - case ammo_nails: { return RESOURCE_BULLETS; } - case ammo_rockets: { return RESOURCE_ROCKETS; } - case ammo_cells: { return RESOURCE_CELLS; } - case ammo_plasma: { return RESOURCE_PLASMA; } - case ammo_fuel: { return RESOURCE_FUEL; } - } - error("GetResourceType: Invalid property."); - return 0; -} - -.float GetResourceProperty(int resource_type) -{ - switch (resource_type) - { - case RESOURCE_HEALTH: { return health; } - case RESOURCE_ARMOR: { return armorvalue; } - case RESOURCE_SHELLS: { return ammo_shells; } - case RESOURCE_BULLETS: { return ammo_nails; } - case RESOURCE_ROCKETS: { return ammo_rockets; } - case RESOURCE_CELLS: { return ammo_cells; } - case RESOURCE_PLASMA: { return ammo_plasma; } - case RESOURCE_FUEL: { return ammo_fuel; } - } - error("GetResourceProperty: Invalid resource type."); - return health; -} - -float GetResourceLimit(int resource_type) -{ - float limit; - switch (resource_type) - { - case RESOURCE_HEALTH: - { - limit = autocvar_g_balance_health_limit; - break; - } - case RESOURCE_ARMOR: - { - limit = autocvar_g_balance_armor_limit; - break; - } - case RESOURCE_SHELLS: - { - limit = g_pickup_shells_max; - break; - } - case RESOURCE_BULLETS: - { - limit = g_pickup_nails_max; - break; - } - case RESOURCE_ROCKETS: - { - limit = g_pickup_rockets_max; - break; - } - case RESOURCE_CELLS: - { - limit = g_pickup_cells_max; - break; - } - case RESOURCE_PLASMA: - { - limit = g_pickup_plasma_max; - break; - } - case RESOURCE_FUEL: - { - limit = g_pickup_fuel_max; - break; - } - default: - { - error("GetResourceLimit: Invalid resource type."); - return 0; - } - } - MUTATOR_CALLHOOK(GetResourceLimit, resource_type, limit); - limit = M_ARGV(1, float); - if (limit > RESOURCE_AMOUNT_HARD_LIMIT) - { - limit = RESOURCE_AMOUNT_HARD_LIMIT; - } - return limit; -} - -void GivePlayerResource(entity player, int resource_type, float amount) -{ - if (amount == 0) + if (num_weapons == 0) { return; } - bool forbid = MUTATOR_CALLHOOK(GivePlayerResource, player, resource_type, - amount); - if (forbid) + int num_potential_weapons = tokenize_console(weapon_names); + for (int i = 0; i < num_weapons; ++i) { - return; - } - resource_type = M_ARGV(1, int); - amount = M_ARGV(2, float); - .float resource_property = GetResourceProperty(resource_type); - float max_amount = GetResourceLimit(resource_type); - player.(resource_property) = bound(player.(resource_property), - player.(resource_property) + amount, max_amount); - switch (resource_type) - { - case RESOURCE_HEALTH: + RandomSelection_Init(); + for (int j = 0; j < num_potential_weapons; ++j) { - player.pauserothealth_finished = max(player.pauserothealth_finished, - time + autocvar_g_balance_pause_health_rot); - return; + string weapon = argv(j); + FOREACH(Weapons, it != WEP_Null, + { + // Finding a weapon which player doesn't have. + if (!(receiver.weapons & it.m_wepset) && (it.netname == weapon)) + { + RandomSelection_AddEnt(it, 1, 1); + break; + } + }); } - case RESOURCE_ARMOR: + if (RandomSelection_chosen_ent == NULL) { - player.pauserotarmor_finished = max(player.pauserotarmor_finished, - time + autocvar_g_balance_pause_armor_rot); return; } - case RESOURCE_FUEL: + receiver.weapons |= RandomSelection_chosen_ent.m_wepset; + switch (RandomSelection_chosen_ent.ammo_field) { - player.pauserotfuel_finished = max(player.pauserotfuel_finished, - time + autocvar_g_balance_pause_fuel_rot); - return; + case (ammo_shells): + { + if (GetResourceAmount(receiver, RESOURCE_SHELLS) != 0) + { + break; + } + GiveResource(receiver, RESOURCE_SHELLS, shells); + break; + } + case (ammo_nails): + { + if (GetResourceAmount(receiver, RESOURCE_BULLETS) != 0) + { + break; + } + GiveResource(receiver, RESOURCE_BULLETS, bullets); + break; + } + case (ammo_rockets): + { + if (GetResourceAmount(receiver, RESOURCE_ROCKETS) != 0) + { + break; + } + GiveResource(receiver, RESOURCE_ROCKETS, rockets); + break; + } + case (ammo_cells): + { + if (GetResourceAmount(receiver, RESOURCE_CELLS) != 0) + { + break; + } + GiveResource(receiver, RESOURCE_CELLS, cells); + break; + } + case (ammo_plasma): + { + if (GetResourceAmount(receiver, RESOURCE_PLASMA) != 0) + { + break; + } + GiveResource(receiver, RESOURCE_PLASMA, plasma); + break; + } } } } -void GivePlayerResourceViaProperty(entity player, .float resource_property, - float amount) -{ - GivePlayerResource(player, GetResourceType(resource_property), amount); -} - -void GivePlayerHealth(entity player, float amount) -{ - GivePlayerResource(player, RESOURCE_HEALTH, amount); -} - -void GivePlayerArmor(entity player, float amount) +float Item_GiveAmmoTo(entity item, entity player, int resource_type, float ammomax) { - GivePlayerResource(player, RESOURCE_ARMOR, amount); -} - -void GivePlayerFuel(entity player, float amount) -{ - GivePlayerResource(player, RESOURCE_FUEL, amount); -} - -float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax) -{ - if (!item.(ammotype)) + float amount = GetResourceAmount(item, resource_type); + if (amount == 0) + { return false; - + } + float player_amount = GetResourceAmount(player, resource_type); if (item.spawnshieldtime) { - if ((player.(ammotype) < ammomax) || item.pickup_anyway > 0) + if ((player_amount >= ammomax) && (item.pickup_anyway <= 0)) { - float amount = item.(ammotype); - if ((player.(ammotype) + amount) > ammomax) - { - amount = ammomax - player.(ammotype); - } - GivePlayerResourceViaProperty(player, ammotype, amount); - return true; + return false; } + GiveResourceWithLimit(player, resource_type, amount, ammomax); + return true; } - else if(g_weapon_stay == 2) + if (g_weapon_stay != 2) { - float mi = min(item.(ammotype), ammomax); - if (player.(ammotype) < mi) - { - GivePlayerResourceViaProperty(player, ammotype, mi - - player.(ammotype)); - } - return true; + return false; } - return false; + GiveResourceWithLimit(player, resource_type, amount, min(amount, ammomax)); + return true; } float Item_GiveTo(entity item, entity player) @@ -895,14 +813,14 @@ float Item_GiveTo(entity item, entity player) } } } - pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health); - pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue); - pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max); - pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max); - pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max); - pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max); - pickedup |= Item_GiveAmmoTo(item, player, ammo_plasma, g_pickup_plasma_max); - pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max); + pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_HEALTH, item.max_health); + pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_ARMOR, item.max_armorvalue); + pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_SHELLS, g_pickup_shells_max); + pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_BULLETS, g_pickup_nails_max); + pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_ROCKETS, g_pickup_rockets_max); + pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_CELLS, g_pickup_cells_max); + pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_PLASMA, g_pickup_plasma_max); + pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_FUEL, g_pickup_fuel_max); if (item.itemdef.instanceOfWeaponPickup) { WepSet w;