}
void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
- float shells, float bullets, float rockets, float cells, float plasma)
+ entity ammo_entity)
{
if (num_weapons == 0)
{
return;
}
int num_potential_weapons = tokenize_console(weapon_names);
- for (int i = 0; i < num_weapons; ++i)
+ for (int give_attempt = 0; give_attempt < num_weapons; ++give_attempt)
{
RandomSelection_Init();
- for (int j = 0; j < num_potential_weapons; ++j)
+ for (int weapon_index = 0; weapon_index < num_potential_weapons;
+ ++weapon_index)
{
- string weapon = argv(j);
+ string weapon = argv(weapon_index);
FOREACH(Weapons, it != WEP_Null,
{
// Finding a weapon which player doesn't have.
return;
}
receiver.weapons |= RandomSelection_chosen_ent.m_wepset;
- switch (RandomSelection_chosen_ent.ammo_field)
+ if (RandomSelection_chosen_ent.ammo_type == RESOURCE_NONE)
{
- case (ammo_shells):
- {
- if (receiver.ammo_shells != 0)
- {
- break;
- }
- GiveResource(receiver, RESOURCE_SHELLS, shells);
- break;
- }
- case (ammo_nails):
- {
- if (receiver.ammo_nails != 0)
- {
- break;
- }
- GiveResource(receiver, RESOURCE_BULLETS, bullets);
- break;
- }
- case (ammo_rockets):
- {
- if (receiver.ammo_rockets != 0)
- {
- break;
- }
- GiveResource(receiver, RESOURCE_ROCKETS, rockets);
- break;
- }
- case (ammo_cells):
- {
- if (receiver.ammo_cells != 0)
- {
- break;
- }
- GiveResource(receiver, RESOURCE_CELLS, cells);
- break;
- }
- case (ammo_plasma):
- {
- if (receiver.ammo_plasma != 0)
- {
- break;
- }
- GiveResource(receiver, RESOURCE_PLASMA, plasma);
- break;
- }
+ continue;
+ }
+ if (GetResourceAmount(receiver,
+ RandomSelection_chosen_ent.ammo_type) != 0)
+ {
+ continue;
}
+ GiveResource(receiver, RandomSelection_chosen_ent.ammo_type,
+ GetResourceAmount(ammo_entity,
+ RandomSelection_chosen_ent.ammo_type));
}
}
-float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax)
+float Item_GiveAmmoTo(entity item, entity player, int resource_type, 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);
- }
- GiveResource(player, GetResourceType(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)
- {
- GiveResource(player, GetResourceType(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)
}
}
}
- 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;
if(it.itemdef) // is a registered item
{
Item_Show(it, -1);
+ it.scheduledrespawntime = 0;
RandomSelection_AddEnt(it, it.cnt, 0);
}
});
if(!(player.weapons & (it.m_wepset)))
continue;
- switch(it.ammo_field)
+ switch(it.ammo_type)
{
- case ammo_shells: need_shells = true; break;
- case ammo_nails: need_nails = true; break;
- case ammo_rockets: need_rockets = true; break;
- case ammo_cells: need_cells = true; break;
- case ammo_plasma: need_plasma = true; break;
- case ammo_fuel: need_fuel = true; break;
+ case RESOURCE_SHELLS: need_shells = true; break;
+ case RESOURCE_BULLETS: need_nails = true; break;
+ case RESOURCE_ROCKETS: need_rockets = true; break;
+ case RESOURCE_CELLS: need_cells = true; break;
+ case RESOURCE_PLASMA: need_plasma = true; break;
+ case RESOURCE_FUEL: need_fuel = true; break;
}
});
rating = item.bot_pickupbasevalue;