Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
items.qc File Reference
Include dependency graph for items.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define IS_SMALL(def)

Functions

float adjust_respawntime (float normal_respawntime)
 Adjust respawn time according to the number of players.
float ammo_pickupevalfunc (entity player, entity item)
 AUTOCVAR (g_pickup_respawntime_initial_random, int, 1, "for items that don't start spawned; \\\"0\\\" = spawn after their normal respawntime, \\\"1\\\" = spawn after `random * respawntime` with the *same* random, \\\"2\\\" = same as 1 but each item has separate random")
 AUTOCVAR (g_pickup_respawntime_scaling_linear, float, 1.0, "multiply respawn time by `reciprocal / (p + offset) + linear` where `p` is the current number of players, takes effect with 2 or more players present, `linear` can be used to simply scale the respawn time linearly")
 AUTOCVAR (g_pickup_respawntime_scaling_offset, float, 0.0, "multiply respawn time by `reciprocal / (p + offset) + linear` where `p` is the current number of players, takes effect with 2 or more players present, `offset` offsets the curve left or right (NOTE: results are not intuitive and it is recommend to plot the respawn time and the number of items per player to see what's happening)")
 AUTOCVAR (g_pickup_respawntime_scaling_reciprocal, float, 0.0, "multiply respawn time by `reciprocal / (p + offset) + linear` where `p` is the current number of players, takes effect with 2 or more players present, `reciprocal` (with `offset` and `linear` set to \\\"0\\\") can be used to achieve a constant number of items spawned *per player*")
float generic_pickupevalfunc (entity player, entity item)
bool GiveBuff (entity e, Buff thebuff, int op, int val)
float GiveItems (entity e, float beginarg, float endarg)
void GiveRandomWeapons (entity receiver, int num_weapons, string weapon_names, entity ammo_entity)
 Give several random weapons and ammo to the entity.
bool GiveResourceValue (entity e, Resource res_type, int op, int val)
void GiveRot (entity e, float v0, float v1,.float rotfield, float rottime,.float regenfield, float regentime)
void GiveSound (entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
bool GiveStatusEffect (entity e, StatusEffect this, int op, float val)
float GiveWeapon (entity e, float wpn, float op, float val)
bool have_pickup_item (entity this)
float healtharmor_pickupevalfunc (entity player, entity item)
void Item_CopyFields (entity this, entity to)
void Item_Damage (entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
void Item_FindTeam (entity this)
bool Item_GiveAmmoTo (entity item, entity player, Resource res_type, float ammomax)
bool Item_GiveTo (entity item, entity player)
bool Item_ItemsTime_Allow (GameItem it)
void Item_ItemsTime_SetTime (entity e, float t)
void Item_ItemsTime_SetTimesForAllPlayers ()
bool Item_ItemsTime_SpectatorOnly (GameItem it)
float Item_ItemsTime_UpdateTime (entity e, float t)
void Item_NotifyWeapon (entity player, entity wep)
void Item_Reset (entity this)
void Item_Respawn (entity this)
void Item_RespawnCountdown (entity this)
void Item_RespawnThink (entity this)
void Item_ScheduleInitialRespawn (entity e)
void Item_ScheduleRespawn (entity e)
void Item_ScheduleRespawnIn (entity e, float t)
void item_setactive (entity this, int act)
void Item_Show (entity e, int mode)
void Item_Think (entity this)
void Item_Touch (entity this, entity toucher)
void item_use (entity this, entity actor, entity trigger)
bool ItemSend (entity this, entity to, int sf)
void ItemUpdate (entity this)
void RemoveItem (entity this)
void setItemGroup (entity this)
bool setItemGroup_cond (entity e)
void setItemGroupCount ()
void StartItem (entity this, entity def)
void UpdateItemAfterTeleport (entity this)
float weapon_pickupevalfunc (entity player, entity item)

Variables

int group_count = 1

Macro Definition Documentation

◆ IS_SMALL

#define IS_SMALL ( def)
Value:
((def.instanceOfHealth && def == ITEM_HealthSmall) || (def.instanceOfArmor && def == ITEM_ArmorSmall))

Definition at line 1248 of file items.qc.

Referenced by setItemGroup(), setItemGroup_cond(), and setItemGroupCount().

Function Documentation

◆ adjust_respawntime()

float adjust_respawntime ( float normal_respawntime)

Adjust respawn time according to the number of players.

Definition at line 357 of file items.qc.

357 {
358 float r = autocvar_g_pickup_respawntime_scaling_reciprocal;
359 float o = autocvar_g_pickup_respawntime_scaling_offset;
360 float l = autocvar_g_pickup_respawntime_scaling_linear;
361
362 if (r == 0 && l == 1) {
363 return normal_respawntime;
364 }
365
368 int players = 0;
369 for (int i = 1; i <= AVAILABLE_TEAMS; ++i)
370 {
371 if (TeamBalance_IsTeamAllowed(balance, i))
372 {
374 }
375 }
376 TeamBalance_Destroy(balance);
377
378 if (players >= 2) {
379 return normal_respawntime * (r / (players + o) + l);
380 } else {
381 return normal_respawntime;
382 }
383}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
entity players
Definition main.qh:57
#define NULL
Definition post.qh:14
#define AVAILABLE_TEAMS
Number of teams that exist currently.
void TeamBalance_Destroy(entity balance)
Destroy the team balance entity.
Definition teamplay.qc:528
int TeamBalance_GetNumberOfPlayers(entity balance, int index)
Returns the number of players (both humans and bots) in a team.
Definition teamplay.qc:875
void TeamBalance_GetTeamCounts(entity balance, entity ignore)
Counts the number of players and various other information about each team.
Definition teamplay.qc:758
entity TeamBalance_CheckAllowedTeams(entity for_whom)
Checks whether the player can join teams according to global configuration and mutator settings.
Definition teamplay.qc:424
bool TeamBalance_IsTeamAllowed(entity balance, int index)
Returns whether the team change to the specified team is allowed.
Definition teamplay.qc:738

References AVAILABLE_TEAMS, entity(), NULL, players, TeamBalance_CheckAllowedTeams(), TeamBalance_Destroy(), TeamBalance_GetNumberOfPlayers(), TeamBalance_GetTeamCounts(), and TeamBalance_IsTeamAllowed().

Referenced by Item_ScheduleRespawn().

◆ ammo_pickupevalfunc()

float ammo_pickupevalfunc ( entity player,
entity item )

Definition at line 909 of file items.qc.

910{
911 entity item_resource = NULL; // pointer to the resource that may be associated with the given item
912 entity wpn = NULL;
913 float c = 0;
914 float rating = 0;
915
916 // detect needed ammo
917 if(item.itemdef.instanceOfWeaponPickup)
918 {
919 entity res = item.itemdef.m_weapon.ammo_type;
920 entity ammo = (res != RES_NONE) ? GetAmmoItem(res) : NULL;
921 if(!ammo)
922 return 0;
923 if(res != RES_NONE && GetResource(item, res))
924 item_resource = res;
925
926 wpn = item;
927 rating = ammo.m_botvalue;
928 }
929 else
930 {
931 FOREACH(Weapons, it != WEP_Null, {
932 if(!(STAT(WEAPONS, player) & (it.m_wepset)))
933 continue;
934 if(it.ammo_type == RES_NONE)
935 continue;
936
937 if(GetResource(item, it.ammo_type))
938 {
939 item_resource = it.ammo_type;
940 break;
941 }
942 });
943 rating = item.bot_pickupbasevalue;
944 }
945
946 float noammorating = 0.5;
947
948 if(item_resource && (GetResource(player, item_resource) < GetResourceLimit(player, item_resource)))
949 c = GetResource(item, item_resource) / max(noammorating, GetResource(player, item_resource));
950
951 rating *= min(c, 2);
952 if(wpn)
953 rating += wpn.bot_pickupbasevalue * 0.1;
954 return rating;
955}
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Weapons
Definition guide.qh:113
#define FOREACH(list, cond, body)
Definition iter.qh:19
#define STAT(...)
Definition stats.qh:94
float min(float f,...)
float max(float f,...)
float GetResourceLimit(entity e, Resource res_type)
Returns the maximum amount of the given resource.
float ammo
Definition sv_turrets.qh:43
entity GetAmmoItem(Resource ammotype)
Definition all.qc:196

References ammo, entity(), FOREACH, GetAmmoItem(), GetResource(), GetResourceLimit(), max(), min(), NULL, STAT, and Weapons.

Referenced by Ammo::float(), FuelRegen::float(), Jetpack::float(), and weapon_pickupevalfunc().

◆ AUTOCVAR() [1/4]

AUTOCVAR ( g_pickup_respawntime_initial_random ,
int ,
1 ,
"for items that don't start spawned; \\\"0\\\" = spawn after their normal respawntime,
\\\"1\\\" = spawn after `random * respawntime` with the *same* random )

◆ AUTOCVAR() [2/4]

AUTOCVAR ( g_pickup_respawntime_scaling_linear ,
float ,
1. 0,
"multiply respawn time by `reciprocal / (p + offset) + linear` where `p` is the current number of players,
takes effect with 2 or more players present,
`linear` can be used to simply scale the respawn time linearly"  )

◆ AUTOCVAR() [3/4]

AUTOCVAR ( g_pickup_respawntime_scaling_offset ,
float ,
0. 0,
"multiply respawn time by `reciprocal / (p + offset) + linear` where `p` is the current number of players,
takes effect with 2 or more players present,
`offset` offsets the curve left or right(NOTE:results are not intuitive and it is recommend to plot the respawn time and the number of items per player to see what 's happening)"  )

◆ AUTOCVAR() [4/4]

AUTOCVAR ( g_pickup_respawntime_scaling_reciprocal ,
float ,
0. 0,
"multiply respawn time by `reciprocal / (p + offset) + linear` where `p` is the current number of players,
takes effect with 2 or more players present,
`reciprocal`(with `offset` and `linear` set to \\\"0\\\") can be used to achieve a constant number of items spawned *per player*"  )

◆ generic_pickupevalfunc()

float generic_pickupevalfunc ( entity player,
entity item )

Definition at line 885 of file items.qc.

885{return item.bot_pickupbasevalue;}

References entity().

Referenced by buff_Init().

◆ GiveBuff()

bool GiveBuff ( entity e,
Buff thebuff,
int op,
int val )

Definition at line 1328 of file items.qc.

1329{
1330 bool had_buff = StatusEffects_active(thebuff, e);
1331 float new_buff_time = ((had_buff) ? StatusEffects_gettime(thebuff, e) : time);
1332 switch (op)
1333 {
1334 case OP_SET:
1335 new_buff_time = time + val;
1336 break;
1337 case OP_MIN:
1338 new_buff_time = max(new_buff_time, time + val);
1339 break;
1340 case OP_MAX:
1341 new_buff_time = min(new_buff_time, time + val);
1342 break;
1343 case OP_PLUS:
1344 new_buff_time += val;
1345 break;
1346 case OP_MINUS:
1347 new_buff_time -= val;
1348 break;
1349 }
1350 if(new_buff_time <= time)
1351 {
1352 if(had_buff) // only trigger removal mechanics if there is an effect to remove!
1354 }
1355 else
1356 {
1357 buff_RemoveAll(e, STATUSEFFECT_REMOVE_CLEAR); // clear old buffs on the player first!
1358 StatusEffects_apply(thebuff, e, new_buff_time, 0);
1359 }
1360 bool have_buff = StatusEffects_active(thebuff, e);
1361 return (had_buff != have_buff);
1362}
@ OP_MIN
Definition bits.qh:79
@ OP_PLUS
Definition bits.qh:81
@ OP_MAX
Definition bits.qh:80
@ OP_SET
Definition bits.qh:78
@ OP_MINUS
Definition bits.qh:82
float time
@ STATUSEFFECT_REMOVE_CLEAR
Effect is being forcibly removed without calling any additional mechanics.
Definition all.qh:30
@ STATUSEFFECT_REMOVE_NORMAL
Effect is being removed by a function, calls regular removal mechanics.
Definition all.qh:28
void StatusEffects_remove(StatusEffect this, entity actor, int removal_type)
float StatusEffects_gettime(StatusEffect this, entity actor)
bool StatusEffects_active(StatusEffect this, entity actor)
void StatusEffects_apply(StatusEffect this, entity actor, float eff_time, int eff_flags)
void buff_RemoveAll(entity actor, int removal_type)
Definition sv_buffs.qc:285

References buff_RemoveAll(), entity(), max(), min(), OP_MAX, OP_MIN, OP_MINUS, OP_PLUS, OP_SET, STATUSEFFECT_REMOVE_CLEAR, STATUSEFFECT_REMOVE_NORMAL, StatusEffects_active(), StatusEffects_apply(), StatusEffects_gettime(), StatusEffects_remove(), and time.

◆ GiveItems()

float GiveItems ( entity e,
float beginarg,
float endarg )

Definition at line 1437 of file items.qc.

1438{
1439 float got, i, val, op;
1440 string cmd;
1441
1442 val = 999;
1443 op = OP_SET;
1444
1445 got = 0;
1446
1447 int _switchweapon = 0;
1448
1449 bool use_cts_autoswitch = (g_cts && (CS_CVAR(e).cvar_cl_autoswitch_cts != -1));
1450 if(CS_CVAR(e).cvar_cl_autoswitch && !use_cts_autoswitch)
1451 {
1452 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1453 {
1454 .entity weaponentity = weaponentities[slot];
1455 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1456 if(e.(weaponentity).m_switchweapon == w_getbestweapon(e, weaponentity))
1457 _switchweapon |= BIT(slot);
1458 }
1459 }
1460
1461 PREGIVE(e, items);
1462 PREGIVE_WEAPONS(e);
1463 PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Strength);
1464 PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Shield);
1465 PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Speed);
1466 PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Invisibility);
1467 //PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Superweapon);
1468 PREGIVE_RESOURCE(e, RES_BULLETS);
1469 PREGIVE_RESOURCE(e, RES_CELLS);
1470 PREGIVE_RESOURCE(e, RES_SHELLS);
1471 PREGIVE_RESOURCE(e, RES_ROCKETS);
1472 PREGIVE_RESOURCE(e, RES_FUEL);
1474 PREGIVE_RESOURCE(e, RES_HEALTH);
1475
1476 Weapon last_wep = WEP_Null;
1477 for(i = beginarg; i < endarg; ++i)
1478 {
1479 cmd = argv(i);
1480
1481 if(cmd == "0" || stof(cmd))
1482 {
1483 val = stof(cmd);
1484 continue;
1485 }
1486 switch(cmd)
1487 {
1488 case "no":
1489 op = OP_MAX;
1490 val = 0;
1491 continue;
1492 case "max":
1493 op = OP_MAX;
1494 continue;
1495 case "min":
1496 op = OP_MIN;
1497 continue;
1498 case "plus":
1499 op = OP_PLUS;
1500 continue;
1501 case "minus":
1502 op = OP_MINUS;
1503 continue;
1504 case "ALL":
1505 got += GiveBit(e, items, ITEM_FuelRegen.m_itemid, op, val);
1506 FOREACH(StatusEffects, it.instanceOfPowerupStatusEffect, got += GiveStatusEffect(e, it, op, val));
1508 case "all":
1509 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1510 got += GiveResourceValue(e, RES_HEALTH, op, val);
1511 got += GiveResourceValue(e, RES_ARMOR, op, val);
1512 case "allweapons":
1513 FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN)),
1514 got += GiveWeapon(e, it.m_id, op, val));
1515 //case "allbuffs": // all buffs makes a player god, do not want!
1516 //FOREACH(StatusEffects, it.instanceOfBuff, got += GiveBuff(e, it, op, val));
1517 case "allammo":
1518 got += GiveResourceValue(e, RES_CELLS, op, val);
1519 got += GiveResourceValue(e, RES_SHELLS, op, val);
1520 got += GiveResourceValue(e, RES_BULLETS, op, val);
1521 got += GiveResourceValue(e, RES_ROCKETS, op, val);
1522 got += GiveResourceValue(e, RES_FUEL, op, val);
1523 break;
1524 case "unlimited_ammo":
1525 // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code
1527 break;
1528 case "unlimited_weapon_ammo":
1529 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1530 break;
1531 case "unlimited_superweapons":
1532 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1533 break;
1534 case "jetpack":
1535 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1536 break;
1537 case "fuel_regen":
1538 got += GiveBit(e, items, ITEM_FuelRegen.m_itemid, op, val);
1539 break;
1540 case "strength":
1541 got += GiveStatusEffect(e, STATUSEFFECT_Strength, op, val);
1542 break;
1543 case "invincible":
1544 case "shield":
1545 got += GiveStatusEffect(e, STATUSEFFECT_Shield, op, val);
1546 break;
1547 case "speed":
1548 got += GiveStatusEffect(e, STATUSEFFECT_Speed, op, val);
1549 break;
1550 case "invisibility":
1551 got += GiveStatusEffect(e, STATUSEFFECT_Invisibility, op, val);
1552 break;
1553 case "superweapons":
1554 got += GiveStatusEffect(e, STATUSEFFECT_Superweapon, op, val);
1555 break;
1556 case "cells":
1557 got += GiveResourceValue(e, RES_CELLS, op, val);
1558 break;
1559 case "shells":
1560 got += GiveResourceValue(e, RES_SHELLS, op, val);
1561 break;
1562 case "nails":
1563 case "bullets":
1564 got += GiveResourceValue(e, RES_BULLETS, op, val);
1565 break;
1566 case "rockets":
1567 got += GiveResourceValue(e, RES_ROCKETS, op, val);
1568 break;
1569 case "health":
1570 got += GiveResourceValue(e, RES_HEALTH, op, val);
1571 break;
1572 case "armor":
1573 got += GiveResourceValue(e, RES_ARMOR, op, val);
1574 break;
1575 case "fuel":
1576 got += GiveResourceValue(e, RES_FUEL, op, val);
1577 break;
1578 default:
1579 FOREACH(StatusEffects, it.instanceOfBuff && buff_Available(it) && Buff_CompatName(cmd) == it.netname,
1580 {
1581 got += GiveBuff(e, it, op, val);
1582 break;
1583 });
1584 FOREACH(Weapons, it != WEP_Null && (cmd == it.netname || cmd == it.m_deprecated_netname), {
1585 got += GiveWeapon(e, it.m_id, op, val);
1586 if(use_cts_autoswitch && CS_CVAR(e).cvar_cl_autoswitch_cts == 1)
1587 if(val > 0 && (op == OP_SET || op == OP_PLUS || op == OP_MIN)) // switch to any given weapons, even if we already had it
1588 last_wep = it; // (... non-CTS autoswitching can switch to a weapon we already have, so CTS autoswitch should be the same)
1589 break;
1590 });
1591 break;
1592 }
1593 val = 999;
1594 op = OP_SET;
1595 }
1596
1597 POSTGIVE_BIT(e, items, ITEM_FuelRegen.m_itemid, SND_ITEMPICKUP, SND_Null);
1598 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND_POWERUP, SND_POWEROFF);
1599 POSTGIVE_BIT(e, items, IT_UNLIMITED_AMMO, SND_POWERUP, SND_POWEROFF);
1600 POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND_ITEMPICKUP, SND_Null);
1601 FOREACH(Weapons, it != WEP_Null, {
1602 POSTGIVE_WEAPON(e, it, SND_WEAPONPICKUP, SND_Null);
1603 if(!(save_weapons & (it.m_wepset)))
1604 if(STAT(WEAPONS, e) & (it.m_wepset))
1605 it.wr_init(it);
1606 });
1607 POSTGIVE_STATUSEFFECT(e, STATUSEFFECT_Strength, SND_POWERUP, SND_POWEROFF);
1608 POSTGIVE_STATUSEFFECT(e, STATUSEFFECT_Shield, SND_POWERUP, SND_POWEROFF);
1609 POSTGIVE_STATUSEFFECT(e, STATUSEFFECT_Speed, SND_POWERUP, SND_POWEROFF);
1610 POSTGIVE_STATUSEFFECT(e, STATUSEFFECT_Invisibility, SND_POWERUP, SND_POWEROFF);
1611 POSTGIVE_RESOURCE(e, RES_BULLETS, 0, SND_ITEMPICKUP, SND_Null);
1612 POSTGIVE_RESOURCE(e, RES_CELLS, 0, SND_ITEMPICKUP, SND_Null);
1613 POSTGIVE_RESOURCE(e, RES_SHELLS, 0, SND_ITEMPICKUP, SND_Null);
1614 POSTGIVE_RESOURCE(e, RES_ROCKETS, 0, SND_ITEMPICKUP, SND_Null);
1618
1619 if(!StatusEffects_active(STATUSEFFECT_Superweapon, e))
1620 {
1621 // also give default superweapon time if player had no superweapons and just got one
1622 if(!g_weaponarena && !(save_weapons & WEPSET_SUPERWEAPONS) && (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
1623 StatusEffects_apply(STATUSEFFECT_Superweapon, e, time + autocvar_g_balance_superweapons_time, 0);
1624 }
1625
1626 if(e.statuseffects)
1628
1629 if(use_cts_autoswitch)
1630 {
1631 // CTS handling: never switch (0), always switch (1)
1632 if(last_wep != WEP_Null)
1633 if(CS_CVAR(e).cvar_cl_autoswitch_cts == 1)
1634 {
1635 // crude hack to enforce switching weapons
1636 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1637 {
1638 .entity weaponentity = weaponentities[slot];
1639 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1640 if(client_hasweapon(e, last_wep, weaponentity, true, false)) // ammo check
1641 W_SwitchWeapon_Force(e, last_wep, weaponentity);
1642 }
1643 }
1644 }
1645 else
1646 {
1647 // non-CTS handling: weaponpriority-based autoswitch
1648 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1649 {
1650 .entity weaponentity = weaponentities[slot];
1651 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1652 if(!(STAT(WEAPONS, e) & WepSet_FromWeapon(e.(weaponentity).m_switchweapon)))
1653 _switchweapon |= BIT(slot);
1654
1655 if(_switchweapon & BIT(slot))
1656 {
1657 Weapon best_wep = w_getbestweapon(e, weaponentity);
1658 if(e.(weaponentity).m_switchweapon != best_wep)
1659 W_SwitchWeapon_Force(e, best_wep, weaponentity);
1660 }
1661 }
1662 }
1663
1664 return got;
1665}
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
ERASEABLE bool GiveBit(entity e,.int fld, int bit, int op, int val)
Definition bits.qh:86
string Buff_CompatName(string buffname)
Definition buffs.qc:4
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:42
const int IT_UNLIMITED_AMMO
Definition item.qh:23
const int IT_UNLIMITED_SUPERWEAPONS
Definition item.qh:24
int items
Definition player.qh:226
#define g_cts
Definition cts.qh:36
void W_SwitchWeapon_Force(Player this, Weapon w,.entity weaponentity)
Definition selection.qc:237
RES_ARMOR
Definition ent_cs.qc:155
float stof(string val,...)
void cmd(string command,...)
string argv(float n)
bool client_hasweapon(entity this, Weapon wpn,.entity weaponentity, float andammo, bool complain)
Definition selection.qc:47
#define w_getbestweapon(ent, wepent)
Definition selection.qh:23
float pauserotfuel_finished
Definition client.qh:340
float pauseregen_finished
Definition client.qh:337
float pauserothealth_finished
Definition client.qh:338
float pauserotarmor_finished
Definition client.qh:339
bool GiveStatusEffect(entity e, StatusEffect this, int op, float val)
Definition items.qc:1404
float GiveWeapon(entity e, float wpn, float op, float val)
Definition items.qc:1297
bool GiveResourceValue(entity e, Resource res_type, int op, int val)
Definition items.qc:1387
float autocvar_g_balance_superweapons_time
Definition items.qh:7
#define POSTGIVE_WEAPON(e, b, snd_incr, snd_decr)
Definition items.qh:109
#define PREGIVE_WEAPONS(e)
Definition items.qh:105
#define POSTGIVE_RESOURCE(e, f, t, snd_incr, snd_decr)
Definition items.qh:112
#define PREGIVE(e, f)
Definition items.qh:106
#define PREGIVE_STATUSEFFECT(e, f)
Definition items.qh:107
#define PREGIVE_RESOURCE(e, f)
Definition items.qh:108
#define POSTGIVE_STATUSEFFECT(e, f, snd_incr, snd_decr)
Definition items.qh:111
#define POSTGIVE_RES_ROT(e, f, t, rotfield, rottime, regenfield, regentime, snd_incr, snd_decr)
Definition items.qh:113
#define POSTGIVE_BIT(e, f, b, snd_incr, snd_decr)
Definition items.qh:110
#define CS_CVAR(this)
Definition state.qh:51
void StatusEffects_update(entity e)
float buff_Available(entity buff)
Definition sv_buffs.qc:256
float autocvar_g_balance_pause_fuel_regen
float autocvar_g_balance_pause_armor_rot
float autocvar_g_balance_pause_health_rot
float autocvar_g_balance_pause_health_regen
float autocvar_g_balance_pause_fuel_rot
WepSet WEPSET_SUPERWEAPONS
Definition all.qh:345
#define WepSet_FromWeapon(it)
Definition all.qh:48
const int MAX_WEAPONSLOTS
Definition weapon.qh:16
entity weaponentities[MAX_WEAPONSLOTS]
Definition weapon.qh:17
const int WEP_FLAG_MUTATORBLOCKED
Definition weapon.qh:261
const int WEP_FLAG_HIDDEN
Definition weapon.qh:258
float g_weaponarena
Definition world.qh:75

References argv(), autocvar_g_balance_pause_armor_rot, autocvar_g_balance_pause_fuel_regen, autocvar_g_balance_pause_fuel_rot, autocvar_g_balance_pause_health_regen, autocvar_g_balance_pause_health_rot, autocvar_g_balance_superweapons_time, BIT, buff_Available(), Buff_CompatName(), client_hasweapon(), cmd(), CS_CVAR, entity(), FOREACH, g_cts, g_weaponarena, GiveBit(), GiveResourceValue(), GiveStatusEffect(), GiveWeapon(), IT_UNLIMITED_AMMO, IT_UNLIMITED_SUPERWEAPONS, items, MAX_WEAPONSLOTS, OP_MAX, OP_MIN, OP_MINUS, OP_PLUS, OP_SET, pauseregen_finished, pauserotarmor_finished, pauserotfuel_finished, pauserothealth_finished, POSTGIVE_BIT, POSTGIVE_RES_ROT, POSTGIVE_RESOURCE, POSTGIVE_STATUSEFFECT, POSTGIVE_WEAPON, PREGIVE, PREGIVE_RESOURCE, PREGIVE_STATUSEFFECT, PREGIVE_WEAPONS, RES_ARMOR, STAT, StatusEffects_active(), StatusEffects_apply(), StatusEffects_update(), stof(), time, w_getbestweapon, W_SwitchWeapon_Force(), weaponentities, Weapons, WEP_FLAG_HIDDEN, WEP_FLAG_MUTATORBLOCKED, WepSet_FromWeapon, and WEPSET_SUPERWEAPONS.

Referenced by CheatCommand(), and target_items_use().

◆ GiveRandomWeapons()

void GiveRandomWeapons ( entity receiver,
int num_weapons,
string weapon_names,
entity ammo_entity )

Give several random weapons and ammo to the entity.

Parameters
[in,out]receiverEntity to give weapons to.
[in]num_weaponsNumber of weapons to give.
[in]weapon_namesNames of weapons to give separated by spaces.
[in]ammoEntity containing the ammo amount for each possible weapon.
Returns
No return.

Definition at line 440 of file items.qc.

442{
443 if (num_weapons == 0)
444 {
445 return;
446 }
447 int num_potential_weapons = tokenize_console(weapon_names);
448 for (int give_attempt = 0; give_attempt < num_weapons; ++give_attempt)
449 {
451 for (int weapon_index = 0; weapon_index < num_potential_weapons;
452 ++weapon_index)
453 {
454 string weapon = argv(weapon_index);
455 FOREACH(Weapons, it != WEP_Null,
456 {
457 // Finding a weapon which player doesn't have.
458 if (!(STAT(WEAPONS, receiver) & it.m_wepset) && (it.netname == weapon))
459 {
460 RandomSelection_AddEnt(it, 1, 1);
461 break;
462 }
463 });
464 }
466 {
467 return;
468 }
469 STAT(WEAPONS, receiver) |= RandomSelection_chosen_ent.m_wepset;
470 if (RandomSelection_chosen_ent.ammo_type == RES_NONE)
471 {
472 continue;
473 }
474 if (GetResource(receiver,
475 RandomSelection_chosen_ent.ammo_type) != 0)
476 {
477 continue;
478 }
479 GiveResource(receiver, RandomSelection_chosen_ent.ammo_type,
480 GetResource(ammo_entity,
481 RandomSelection_chosen_ent.ammo_type));
482 }
483}
#define tokenize_console
float weapon
Definition progsdefs.qc:139
ERASEABLE void RandomSelection_Init()
Definition random.qc:4
#define RandomSelection_AddEnt(e, weight, priority)
Definition random.qh:14
entity RandomSelection_chosen_ent
Definition random.qh:5
void GiveResource(entity receiver, Resource res_type, float amount)
Gives an entity some resource.

References argv(), entity(), FOREACH, GetResource(), GiveResource(), NULL, RandomSelection_AddEnt, RandomSelection_chosen_ent, RandomSelection_Init(), STAT, tokenize_console, weapon, and Weapons.

Referenced by PutPlayerInServer().

◆ GiveResourceValue()

bool GiveResourceValue ( entity e,
Resource res_type,
int op,
int val )

Definition at line 1387 of file items.qc.

1388{
1389 int v0 = GetResource(e, res_type);
1390 float new_val = 0;
1391 switch (op)
1392 {
1393 // min 100 cells = at least 100 cells
1394 case OP_SET: new_val = val; break;
1395 case OP_MIN: new_val = max(v0, val); break;
1396 case OP_MAX: new_val = min(v0, val); break;
1397 case OP_PLUS: new_val = v0 + val; break;
1398 case OP_MINUS: new_val = v0 - val; break;
1399 default: return false;
1400 }
1401
1402 return SetResourceExplicit(e, res_type, new_val);
1403}
SetResourceExplicit(ent, RES_ARMOR, ReadByte() *DEC_FACTOR)) ENTCS_PROP(NAME

References entity(), GetResource(), max(), min(), OP_MAX, OP_MIN, OP_MINUS, OP_PLUS, OP_SET, and SetResourceExplicit().

Referenced by GiveItems().

◆ GiveRot()

void GiveRot ( entity e,
float v0,
float v1,
.float rotfield,
float rottime,
.float regenfield,
float regentime )

Definition at line 1380 of file items.qc.

1381{
1382 if(v0 < v1)
1383 e.(rotfield) = max(e.(rotfield), time + rottime);
1384 else if(v0 > v1)
1385 e.(regenfield) = max(e.(regenfield), time + regentime);
1386}

References entity(), max(), and time.

◆ GiveSound()

void GiveSound ( entity e,
float v0,
float v1,
float t,
Sound snd_incr,
Sound snd_decr )

Definition at line 1364 of file items.qc.

1365{
1366 if(v1 == v0)
1367 return;
1368 if(v1 <= v0 - t)
1369 {
1370 if(snd_decr != NULL)
1371 sound(e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1372 }
1373 else if(v0 >= v0 + t)
1374 {
1375 if(snd_incr != NULL)
1376 sound(e, ((snd_incr == SND_POWERUP) ? CH_TRIGGER_SINGLE : CH_TRIGGER), snd_incr, VOL_BASE, ATTEN_NORM);
1377 }
1378}
const int CH_TRIGGER
Definition sound.qh:12
const int CH_TRIGGER_SINGLE
Definition sound.qh:13
const float VOL_BASE
Definition sound.qh:36
const float ATTEN_NORM
Definition sound.qh:30
#define sound(e, c, s, v, a)
Definition sound.qh:52

References ATTEN_NORM, CH_TRIGGER, CH_TRIGGER_SINGLE, entity(), NULL, sound, and VOL_BASE.

◆ GiveStatusEffect()

bool GiveStatusEffect ( entity e,
StatusEffect this,
int op,
float val )

Definition at line 1404 of file items.qc.

1405{
1406 bool had_eff = StatusEffects_active(this, e);
1407 float new_eff_time = ((had_eff) ? StatusEffects_gettime(this, e) : time);
1408 switch (op)
1409 {
1410 case OP_SET:
1411 new_eff_time = time + val;
1412 break;
1413 case OP_MIN:
1414 new_eff_time = max(new_eff_time, time + val);
1415 break;
1416 case OP_MAX:
1417 new_eff_time = min(new_eff_time, time + val);
1418 break;
1419 case OP_PLUS:
1420 new_eff_time += val;
1421 break;
1422 case OP_MINUS:
1423 new_eff_time -= val;
1424 break;
1425 }
1426 if(new_eff_time <= time)
1427 {
1428 if(had_eff) // only trigger removal mechanics if there is an effect to remove!
1430 }
1431 else
1432 StatusEffects_apply(this, e, new_eff_time, 0);
1433 bool have_eff = StatusEffects_active(this, e);
1434 return (had_eff != have_eff);
1435}

References entity(), max(), min(), OP_MAX, OP_MIN, OP_MINUS, OP_PLUS, OP_SET, STATUSEFFECT_REMOVE_NORMAL, StatusEffects_active(), StatusEffects_apply(), StatusEffects_gettime(), StatusEffects_remove(), and time.

Referenced by GiveItems().

◆ GiveWeapon()

float GiveWeapon ( entity e,
float wpn,
float op,
float val )

Definition at line 1297 of file items.qc.

1298{
1299 WepSet v0, v1;
1301 v0 = (STAT(WEAPONS, e) & s);
1302 switch(op)
1303 {
1304 case OP_SET:
1305 if(val > 0)
1306 STAT(WEAPONS, e) |= s;
1307 else
1308 STAT(WEAPONS, e) &= ~s;
1309 break;
1310 case OP_MIN:
1311 case OP_PLUS:
1312 if(val > 0)
1313 STAT(WEAPONS, e) |= s;
1314 break;
1315 case OP_MAX:
1316 if(val <= 0)
1317 STAT(WEAPONS, e) &= ~s;
1318 break;
1319 case OP_MINUS:
1320 if(val > 0)
1321 STAT(WEAPONS, e) &= ~s;
1322 break;
1323 }
1324 v1 = (STAT(WEAPONS, e) & s);
1325 return (v0 != v1);
1326}
#define REGISTRY_GET(id, i)
Definition registry.qh:62
vector WepSet
Definition weapon.qh:14

References entity(), OP_MAX, OP_MIN, OP_MINUS, OP_PLUS, OP_SET, REGISTRY_GET, STAT, Weapons, and WepSet_FromWeapon.

Referenced by GiveItems().

◆ have_pickup_item()

bool have_pickup_item ( entity this)

Definition at line 112 of file items.qc.

113{
114 if (this.itemdef.spawnflags & ITEM_FLAG_MUTATORBLOCKED)
115 return false;
116
117 if(!this.itemdef.instanceOfPowerup)
118 {
120 return true;
122 return false;
123 if(g_weaponarena)
124 if(STAT(WEAPONS, this) || this.itemdef.instanceOfAmmo) // no item or ammo pickups in weaponarena
125 return false;
126 }
127 return true;
128}
@ ITEM_FLAG_MUTATORBLOCKED
Definition item.qh:121
int autocvar_g_pickup_items
Definition items.qh:11
entity itemdef
Definition items.qh:92

References autocvar_g_pickup_items, entity(), g_weaponarena, ITEM_FLAG_MUTATORBLOCKED, itemdef, and STAT.

Referenced by StartItem().

◆ healtharmor_pickupevalfunc()

float healtharmor_pickupevalfunc ( entity player,
entity item )

Definition at line 957 of file items.qc.

958{
959 float c = 0;
960 float rating = item.bot_pickupbasevalue;
961
962 float itemarmor = GetResource(item, RES_ARMOR);
963 float itemhealth = GetResource(item, RES_HEALTH);
964
965 if(item.item_group)
966 {
967 itemarmor *= min(4, item.item_group_count);
968 itemhealth *= min(4, item.item_group_count);
969 }
970
971 if (itemarmor && (GetResource(player, RES_ARMOR) < item.max_armorvalue))
972 c = itemarmor / max(1, GetResource(player, RES_ARMOR) * 2/3 + GetResource(player, RES_HEALTH) * 1/3);
973
974 if (itemhealth && (GetResource(player, RES_HEALTH) < item.max_health))
975 c = itemhealth / max(1, GetResource(player, RES_HEALTH));
976
977 rating *= min(2, c);
978 return rating;
979}

References entity(), GetResource(), max(), min(), and RES_ARMOR.

Referenced by Armor::float(), and Health::float().

◆ Item_CopyFields()

void Item_CopyFields ( entity this,
entity to )

Definition at line 851 of file items.qc.

852{
853 setorigin(to, this.origin);
854 to.spawnflags = this.spawnflags;
855 to.noalign = ITEM_SHOULD_KEEP_POSITION(this);
856 to.cnt = this.cnt;
857 to.team = this.team;
858 to.spawnfunc_checked = true;
859 // TODO: copy respawn times? this may not be desirable in some cases
860 //to.respawntime = this.respawntime;
861 //to.respawntimejitter = this.respawntimejitter;
862}
float cnt
Definition powerups.qc:24
int team
Definition main.qh:188
int spawnflags
Definition ammo.qh:15
vector origin
#define ITEM_SHOULD_KEEP_POSITION(item)
Returns whether item should keep its position or be dropped to the ground.
Definition spawning.qh:52

References cnt, entity(), ITEM_SHOULD_KEEP_POSITION, origin, spawnflags, and team.

Referenced by instagib_replace_item_with(), lms_replace_with_extralife(), MUTATOR_HOOKFUNCTION(), RandomItems_ReplaceMapItem(), and weapon_defaultspawnfunc().

◆ Item_Damage()

void Item_Damage ( entity this,
entity inflictor,
entity attacker,
float damage,
int deathtype,
.entity weaponentity,
vector hitloc,
vector force )

Definition at line 981 of file items.qc.

982{
983 if(ITEM_DAMAGE_NEEDKILL(deathtype))
984 RemoveItem(this);
985}
void RemoveItem(entity this)
Definition items.qc:865
#define ITEM_DAMAGE_NEEDKILL(dt)
Definition items.qh:123

References entity(), ITEM_DAMAGE_NEEDKILL, RemoveItem(), and vector.

Referenced by StartItem().

◆ Item_FindTeam()

void Item_FindTeam ( entity this)

Definition at line 813 of file items.qc.

814{
815 if(!(this.effects & EF_NOGUNBOB)) // marker for item team search
816 return;
817
818 LOG_TRACE("Initializing item team ", ftos(this.team));
820 IL_EACH(g_items, it.team == this.team,
821 {
822 if(it.itemdef) // is a registered item
823 RandomSelection_AddEnt(it, it.cnt, 0);
824 });
825
827 if (!e)
828 return;
829
830 IL_EACH(g_items, it.team == this.team,
831 {
832 if(it.itemdef) // is a registered item
833 {
834 if(it != e)
835 {
836 Item_Show(it, -1); // make it non-spawned
837 if (it.waypointsprite_attached)
838 WaypointSprite_Kill(it.waypointsprite_attached);
839 it.nextthink = 0; // disable any scheduled powerup spawn
840 }
841 else
842 Item_Reset(it);
843
844 // leave 'this' marked so Item_FindTeam() works when called again via this.reset
845 if(it != this)
846 it.effects &= ~EF_NOGUNBOB;
847 }
848 });
849}
float effects
float EF_NOGUNBOB
#define IL_EACH(this, cond, body)
#define LOG_TRACE(...)
Definition log.qh:74
string ftos(float f)
IntrusiveList g_items
Definition items.qh:119

References EF_NOGUNBOB, effects, entity(), ftos(), g_items, IL_EACH, LOG_TRACE, RandomSelection_chosen_ent, RandomSelection_Init(), and team.

Referenced by StartItem().

◆ Item_GiveAmmoTo()

bool Item_GiveAmmoTo ( entity item,
entity player,
Resource res_type,
float ammomax )

Definition at line 485 of file items.qc.

486{
487 float amount = GetResource(item, res_type);
488 if (amount == 0)
489 {
490 return false;
491 }
492 float player_amount = GetResource(player, res_type);
493 if (item.spawnshieldtime)
494 {
495 if ((player_amount >= ammomax) && (item.pickup_anyway <= 0))
496 return false;
497 }
498 else if (g_weapon_stay == 2)
499 {
500 ammomax = min(amount, ammomax);
501 if(player_amount >= ammomax)
502 return false;
503 }
504 else
505 return false;
506 if (amount < 0)
507 TakeResourceWithLimit(player, res_type, -amount, ammomax);
508 else
509 GiveResourceWithLimit(player, res_type, amount, ammomax);
510 return true;
511}
void TakeResourceWithLimit(entity receiver, Resource res_type, float amount, float limit)
Takes an entity some resource but not less than a limit.
void GiveResourceWithLimit(entity receiver, Resource res_type, float amount, float limit)
Gives an entity some resource but not more than a limit.
float g_weapon_stay
Definition world.qh:109

References entity(), g_weapon_stay, GetResource(), GiveResourceWithLimit(), min(), and TakeResourceWithLimit().

Referenced by Item_GiveTo().

◆ Item_GiveTo()

bool Item_GiveTo ( entity item,
entity player )

Definition at line 522 of file items.qc.

523{
524 // if nothing happens to player, just return without taking the item
525 int _switchweapon = 0;
526 // in case the player has cl_autoswitch enabled do the following:
527 // if the player is using their best weapon before items are given, they
528 // probably want to switch to an even better weapon after items are given
529
530 bool use_cts_autoswitch = (g_cts && item.itemdef.instanceOfWeaponPickup && (CS_CVAR(player).cvar_cl_autoswitch_cts != -1));
531 if (CS_CVAR(player).cvar_cl_autoswitch && !use_cts_autoswitch)
532 {
533 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
534 {
535 .entity weaponentity = weaponentities[slot];
536 if (player.(weaponentity).m_weapon != WEP_Null || slot == 0)
537 {
538 if (player.(weaponentity).m_switchweapon == w_getbestweapon(player, weaponentity))
539 _switchweapon |= BIT(slot);
540
541 if (!(STAT(WEAPONS, player) & WepSet_FromWeapon(player.(weaponentity).m_switchweapon)))
542 _switchweapon |= BIT(slot);
543 }
544 }
545 }
546 bool pickedup = false;
547 pickedup |= Item_GiveAmmoTo(item, player, RES_HEALTH, item.max_health);
548 pickedup |= Item_GiveAmmoTo(item, player, RES_ARMOR, item.max_armorvalue);
549 pickedup |= Item_GiveAmmoTo(item, player, RES_SHELLS, autocvar_g_pickup_shells_max);
550 pickedup |= Item_GiveAmmoTo(item, player, RES_BULLETS, autocvar_g_pickup_nails_max);
551 pickedup |= Item_GiveAmmoTo(item, player, RES_ROCKETS, autocvar_g_pickup_rockets_max);
552 pickedup |= Item_GiveAmmoTo(item, player, RES_CELLS, autocvar_g_pickup_cells_max);
553 pickedup |= Item_GiveAmmoTo(item, player, RES_FUEL, autocvar_g_pickup_fuel_max);
554 if (item.itemdef.instanceOfWeaponPickup)
555 {
556 WepSet w, wp;
557 w = STAT(WEAPONS, item);
558 wp = w & ~STAT(WEAPONS, player);
559
560 if (wp || (item.spawnshieldtime && item.pickup_anyway > 0))
561 {
562 pickedup = true;
563 FOREACH(Weapons, it != WEP_Null, {
564 if(w & (it.m_wepset))
565 Item_NotifyWeapon(player, it);
566
567 if(wp & (it.m_wepset))
568 {
569 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
570 {
571 .entity weaponentity = weaponentities[slot];
572 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
573 W_DropEvent(wr_pickup, player, it.m_id, item, weaponentity);
574 }
575 W_GiveWeapon(player, it.m_id);
576 }
577 });
578 }
579 }
580
581 if (item.itemdef.instanceOfPowerup)
582 {
583 if ((item.itemdef == ITEM_FuelRegen) && !(player.items & IT_FUEL_REGEN))
584 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_FUELREGEN_GOT);
585 else if ((item.itemdef == ITEM_Jetpack) && !(player.items & IT_JETPACK))
586 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_JETPACK_GOT);
587 }
588
589 int its = item.items & ~(player.items) & IT_PICKUPMASK;
590 if (its)
591 {
592 pickedup = true;
593 player.items |= its;
594 // TODO: we probably want to show a message in the console, but not this one!
595 //Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
596 }
597
598 if (item.strength_finished)
599 {
600 pickedup = true;
601 float t = max(time, StatusEffects_gettime(STATUSEFFECT_Strength, player));
603 t += item.strength_finished;
604 else
605 t = max(t, time + item.strength_finished);
606 StatusEffects_apply(STATUSEFFECT_Strength, player, t, 0);
607 }
608 if (item.invincible_finished)
609 {
610 pickedup = true;
611 float t = max(time, StatusEffects_gettime(STATUSEFFECT_Shield, player));
613 t += item.invincible_finished;
614 else
615 t = max(t, time + item.invincible_finished);
616 StatusEffects_apply(STATUSEFFECT_Shield, player, t, 0);
617 }
618 if (item.speed_finished)
619 {
620 pickedup = true;
621 float t = max(time, StatusEffects_gettime(STATUSEFFECT_Speed, player));
623 t += item.speed_finished;
624 else
625 t = max(t, time + item.speed_finished);
626 StatusEffects_apply(STATUSEFFECT_Speed, player, t, 0);
627 }
628 if (item.invisibility_finished)
629 {
630 pickedup = true;
631 float t = max(time, StatusEffects_gettime(STATUSEFFECT_Invisibility, player));
633 t += item.invisibility_finished;
634 else
635 t = max(t, time + item.invisibility_finished);
636 StatusEffects_apply(STATUSEFFECT_Invisibility, player, t, 0);
637 }
638 if (item.superweapons_finished)
639 {
640 pickedup = true;
641 float t = max(time, StatusEffects_gettime(STATUSEFFECT_Superweapon, player));
642 StatusEffects_apply(STATUSEFFECT_Superweapon, player, t + item.superweapons_finished, 0);
643 }
644
645 // always eat teamed entities
646 if(item.team)
647 pickedup = true;
648
649 if (!pickedup)
650 return false;
651
652 if(use_cts_autoswitch)
653 {
654 // CTS handling: never switch (0), always switch (1)
655 if(CS_CVAR(player).cvar_cl_autoswitch_cts == 1)
656 {
657 // crude hack to enforce switching weapons
658 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
659 {
660 .entity weaponentity = weaponentities[slot];
661 Weapon w = REGISTRY_GET(Weapons, item.weapon);
662 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
663 if(client_hasweapon(player, w, weaponentity, true, false)) // ammo check
664 W_SwitchWeapon_Force(player, w, weaponentity);
665 }
666 }
667 }
668 else if(_switchweapon)
669 {
670 // non-CTS handling: weaponpriority-based autoswitch
671 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
672 {
673 .entity weaponentity = weaponentities[slot];
674 if(_switchweapon & BIT(slot))
675 {
676 Weapon best_wep = w_getbestweapon(player, weaponentity);
677 if(player.(weaponentity).m_switchweapon != best_wep)
678 W_SwitchWeapon_Force(player, best_wep, weaponentity);
679 }
680 }
681 }
682
683 return true;
684}
int autocvar_g_pickup_rockets_max
Definition ammo.qh:116
int autocvar_g_pickup_fuel_max
Definition ammo.qh:188
int autocvar_g_pickup_shells_max
Definition ammo.qh:44
int autocvar_g_pickup_cells_max
Definition ammo.qh:152
int autocvar_g_pickup_nails_max
Definition ammo.qh:80
const int IT_JETPACK
Definition item.qh:26
const int IT_PICKUPMASK
Definition item.qh:46
const int IT_FUEL_REGEN
Definition item.qh:28
void Send_Notification(NOTIF broadcast, entity client, MSG net_type, Notification net_name,...count)
Definition all.qc:1500
void Item_NotifyWeapon(entity player, entity wep)
Definition items.qc:513
bool Item_GiveAmmoTo(entity item, entity player, Resource res_type, float ammomax)
Definition items.qc:485
void W_GiveWeapon(entity e, int wep)
Definition common.qc:33
bool autocvar_g_powerups_stack
void W_DropEvent(.void(Weapon, entity actor,.entity) event, entity player, int weapon_type, entity weapon_item,.entity weaponentity)

References autocvar_g_pickup_cells_max, autocvar_g_pickup_fuel_max, autocvar_g_pickup_nails_max, autocvar_g_pickup_rockets_max, autocvar_g_pickup_shells_max, autocvar_g_powerups_stack, BIT, client_hasweapon(), CS_CVAR, entity(), FOREACH, g_cts, IT_FUEL_REGEN, IT_JETPACK, IT_PICKUPMASK, Item_GiveAmmoTo(), Item_NotifyWeapon(), max(), MAX_WEAPONSLOTS, REGISTRY_GET, RES_ARMOR, Send_Notification(), STAT, StatusEffects_apply(), StatusEffects_gettime(), time, W_DropEvent(), w_getbestweapon, W_GiveWeapon(), W_SwitchWeapon_Force(), weaponentities, Weapons, and WepSet_FromWeapon.

Referenced by Pickup::giveTo(), and WeaponPickup::giveTo().

◆ Item_ItemsTime_Allow()

bool Item_ItemsTime_Allow ( GameItem it)

Definition at line 66 of file itemstime.qc.

67{
68 return (it.instanceOfPowerup || Item_ItemsTime_SpectatorOnly(it));
69}
bool Item_ItemsTime_SpectatorOnly(GameItem it)
Definition itemstime.qc:58

References Item_ItemsTime_SpectatorOnly().

Referenced by HUD_ItemsTime(), Item_ItemsTime_ResetTimes(), Item_ItemsTime_ResetTimesForPlayer(), Item_ItemsTime_SetTimesForPlayer(), Item_Respawn(), and Item_ScheduleRespawnIn().

◆ Item_ItemsTime_SetTime()

void Item_ItemsTime_SetTime ( entity e,
float t )

Definition at line 107 of file itemstime.qc.

108{
110 return;
111
112 GameItem item = e.itemdef;
113 if (item.instanceOfGameItem)
114 {
115 if (!item.instanceOfWeaponPickup)
116 it_times[item.m_id] = t;
117 else if (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS)
118 it_times[REGISTRY_MAX(Items)] = t;
119 }
120}
int m_id
Definition item.qh:127
float it_times[REGISTRY_MAX(Items)+1]
Definition itemstime.qc:74
int autocvar_sv_itemstime
Definition itemstime.qh:4
#define REGISTRY_MAX(id)
Definition registry.qh:17

References autocvar_sv_itemstime, entity(), it_times, GameItem::m_id, REGISTRY_MAX, STAT, and WEPSET_SUPERWEAPONS.

Referenced by Item_Respawn(), Item_ScheduleRespawnIn(), and StartItem().

◆ Item_ItemsTime_SetTimesForAllPlayers()

void Item_ItemsTime_SetTimesForAllPlayers ( )

Definition at line 122 of file itemstime.qc.

123{
126 );
127}
bool warmup_stage
Definition main.qh:120
#define IS_PLAYER(s)
Definition player.qh:242
void Item_ItemsTime_SetTimesForPlayer(entity e)
Definition itemstime.qc:99
#define IS_REAL_CLIENT(v)
Definition utils.qh:17
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:52

References autocvar_sv_itemstime, FOREACH_CLIENT, IS_PLAYER, IS_REAL_CLIENT, Item_ItemsTime_SetTimesForPlayer(), and warmup_stage.

Referenced by Item_Respawn(), Item_ScheduleRespawnIn(), and MUTATOR_HOOKFUNCTION().

◆ Item_ItemsTime_SpectatorOnly()

bool Item_ItemsTime_SpectatorOnly ( GameItem it)

Definition at line 58 of file itemstime.qc.

59{
60 return (false
61 || it == ITEM_ArmorMega || (it == ITEM_ArmorBig && !hud_panel_itemstime_hidebig)
62 || it == ITEM_HealthMega || (it == ITEM_HealthBig && !hud_panel_itemstime_hidebig)
63 );
64}
#define hud_panel_itemstime_hidebig
Definition itemstime.qc:53

References hud_panel_itemstime_hidebig.

Referenced by Item_ItemsTime_Allow(), and Item_RespawnCountdown().

◆ Item_ItemsTime_UpdateTime()

float Item_ItemsTime_UpdateTime ( entity e,
float t )

Definition at line 129 of file itemstime.qc.

130{
131 bool isavailable = (t == 0);
132 IL_EACH(g_items, it != e,
133 {
134 if(!(it.itemdef == e.itemdef
135 || ((STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS) && (STAT(WEAPONS, it) & WEPSET_SUPERWEAPONS))))
136 {
137 continue;
138 }
139 if (it.scheduledrespawntime <= time)
140 isavailable = true;
141 else if (t == 0 || it.scheduledrespawntime < t)
142 t = it.scheduledrespawntime;
143 });
144 if (isavailable)
145 t = -t; // let know the client there's another available item
146 return t;
147}

References entity(), g_items, IL_EACH, STAT, time, and WEPSET_SUPERWEAPONS.

Referenced by Item_Respawn(), and Item_ScheduleRespawnIn().

◆ Item_NotifyWeapon()

void Item_NotifyWeapon ( entity player,
entity wep )

Definition at line 513 of file items.qc.

514{
515 FOREACH_CLIENT(IS_REAL_CLIENT(it) && (it == player || (IS_SPEC(it) && it.enemy == player)), {
516 msg_entity = it;
517 WriteHeader(MSG_ONE, TE_CSQC_WEAPONPICKUP);
518 WriteRegistered(Weapons, MSG_ONE, wep);
519 });
520}
#define IS_SPEC(v)
Definition utils.qh:10

References entity(), FOREACH_CLIENT, IS_REAL_CLIENT, and IS_SPEC.

Referenced by Item_GiveTo().

◆ Item_Reset()

void Item_Reset ( entity this)

Definition at line 783 of file items.qc.

784{
785 if (this.targetname != "" && !(this.spawnflags & 16)) // q3compat
786 {
787 Item_Show(this, -1);
790 this.nextthink = 0;
791 return;
792 }
793
794 Item_Show(this, !this.state);
795
796 if (ITEM_IS_LOOT(this))
797 {
798 return;
799 }
800 setthink(this, Item_Think);
801 this.nextthink = time;
802 this.active = ACTIVE_ACTIVE;
804 {
806 }
807 if (this.itemdef.instanceOfPowerup || (STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
808 {
810 }
811}
float nextthink
int state
int active
Definition defs.qh:34
const int ACTIVE_ACTIVE
Definition defs.qh:37
#define ITEM_IS_LOOT(item)
Returns whether the item is loot.
Definition spawning.qh:39
#define setthink(e, f)
void Item_ScheduleInitialRespawn(entity e)
Definition items.qc:405
void Item_Think(entity this)
Definition items.qc:192
void Item_Show(entity e, int mode)
Definition items.qc:130
string targetname
Definition triggers.qh:56
void WaypointSprite_Kill(entity wp)
entity waypointsprite_attached

References active, ACTIVE_ACTIVE, entity(), ITEM_IS_LOOT, Item_ScheduleInitialRespawn(), Item_Show(), Item_Think(), itemdef, nextthink, setthink, spawnflags, STAT, state, targetname, time, waypointsprite_attached, WaypointSprite_Kill(), and WEPSET_SUPERWEAPONS.

Referenced by StartItem().

◆ Item_Respawn()

void Item_Respawn ( entity this)

Definition at line 241 of file items.qc.

242{
243 Item_Show(this, 1);
244 sound(this, CH_TRIGGER, this.itemdef.m_respawnsound, VOL_BASE, ATTEN_NORM); // play respawn sound
245
246 if (Item_ItemsTime_Allow(this.itemdef) || (STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS))
247 {
248 float t = Item_ItemsTime_UpdateTime(this, 0);
249 Item_ItemsTime_SetTime(this, t);
251 }
252
253 setthink(this, Item_Think);
254 this.nextthink = time;
255}
float Item_ItemsTime_UpdateTime(entity e, float t)
Definition itemstime.qc:129
void Item_ItemsTime_SetTimesForAllPlayers()
Definition itemstime.qc:122
void Item_ItemsTime_SetTime(entity e, float t)
Definition itemstime.qc:107
bool Item_ItemsTime_Allow(GameItem it)
Definition itemstime.qc:66

References ATTEN_NORM, CH_TRIGGER, entity(), Item_ItemsTime_Allow(), Item_ItemsTime_SetTime(), Item_ItemsTime_SetTimesForAllPlayers(), Item_ItemsTime_UpdateTime(), Item_Show(), Item_Think(), itemdef, nextthink, setthink, sound, STAT, time, VOL_BASE, and WEPSET_SUPERWEAPONS.

Referenced by Item_RespawnCountdown(), Item_RespawnThink(), and item_use().

◆ Item_RespawnCountdown()

void Item_RespawnCountdown ( entity this)

Definition at line 257 of file items.qc.

258{
260 {
263 Item_Respawn(this);
264 }
265 else
266 {
267 this.nextthink = time + 1;
268 ++this.item_respawncounter;
269 if(this.item_respawncounter == 1)
270 {
271 do {
272 {
273 entity wi = REGISTRY_GET(Weapons, this.weapon);
274 if (wi != WEP_Null) {
275 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Weapon);
276 wp.wp_extra = wi.m_id;
277 break;
278 }
279 }
280 {
281 entity ii = this.itemdef;
282 if (ii != NULL) {
283 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Item);
284 wp.wp_extra = ii.m_id;
285 break;
286 }
287 }
288 } while (0);
289 bool mutator_returnvalue = MUTATOR_CALLHOOK(Item_RespawnCountdown, this);
291 {
292 GameItem def = this.itemdef;
293 if (Item_ItemsTime_SpectatorOnly(def) && !mutator_returnvalue)
296 }
297 }
298
300 {
302 if(this.waypointsprite_attached.waypointsprite_visible_for_player(this.waypointsprite_attached, it, it))
303 {
304 msg_entity = it;
305 soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM, 0); // play respawn sound
306 }
307 });
308
310 //WaypointSprite_UpdateHealth(this.waypointsprite_attached, this.item_respawncounter);
311 }
312 }
313}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
float MSG_ONE
Definition menudefs.qc:56
entity msg_entity
Definition progsdefs.qc:63
bool Item_ItemsTime_SpectatorOnly(GameItem it)
Definition itemstime.qc:58
void Item_RespawnCountdown(entity this)
Definition items.qc:257
void Item_Respawn(entity this)
Definition items.qc:241
float item_respawncounter
Definition items.qh:35
const float ITEM_RESPAWN_TICKS
Definition items.qh:19
void soundto(int _dest, entity e, int chan, string samp, float vol, float _atten, float _pitch)
Definition all.qc:74
#define SND(id)
Definition all.qh:35
void WaypointSprite_Ping(entity e)
entity WaypointSprite_Spawn(entity spr, float _lifetime, float maxdistance, entity ref, vector ofs, entity showto, float t, entity own,.entity ownfield, float hideable, entity icon)
void WaypointSprite_UpdateBuildFinished(entity e, float f)
void WaypointSprite_UpdateRule(entity e, float t, float r)
const int SPRITERULE_SPECTATOR

References ATTEN_NORM, CH_TRIGGER, entity(), FOREACH_CLIENT, IS_REAL_CLIENT, Item_ItemsTime_SpectatorOnly(), Item_Respawn(), ITEM_RESPAWN_TICKS, Item_RespawnCountdown(), item_respawncounter, itemdef, msg_entity, MSG_ONE, MUTATOR_CALLHOOK, nextthink, NULL, REGISTRY_GET, SND, soundto(), SPRITERULE_SPECTATOR, time, VOL_BASE, waypointsprite_attached, WaypointSprite_Kill(), WaypointSprite_Ping(), WaypointSprite_Spawn(), WaypointSprite_UpdateBuildFinished(), WaypointSprite_UpdateRule(), weapon, and Weapons.

Referenced by Item_RespawnCountdown(), Item_ScheduleRespawnIn(), MUTATOR_HOOKABLE(), and MUTATOR_HOOKFUNCTION().

◆ Item_RespawnThink()

void Item_RespawnThink ( entity this)

Definition at line 315 of file items.qc.

316{
317 this.nextthink = time;
318 if(this.origin != this.oldorigin)
319 ItemUpdate(this);
320
321 if(time >= this.wait)
322 Item_Respawn(this);
323}
float wait
Definition items.qc:17
vector oldorigin
void ItemUpdate(entity this)
Definition items.qc:100

References entity(), Item_Respawn(), ItemUpdate(), nextthink, oldorigin, origin, time, and wait.

Referenced by Item_ScheduleRespawnIn().

◆ Item_ScheduleInitialRespawn()

void Item_ScheduleInitialRespawn ( entity e)

Definition at line 405 of file items.qc.

406{
407 Item_Show(e, 0);
408
409 float spawn_in;
410 if (autocvar_g_pickup_respawntime_initial_random == 0)
411 {
412 // range: respawntime .. respawntime + respawntimejitter
413 spawn_in = e.respawntime + random() * e.respawntimejitter;
414 }
415 else
416 {
417 float rnd;
418 if (autocvar_g_pickup_respawntime_initial_random == 1)
419 {
420 static float shared_random = 0;
421 // NOTE this code works only if items are scheduled at the same time (normal case)
422 // NOTE2 random() can't return exactly 1 so this check always work as intended
423 if (!shared_random || floor(time) > shared_random)
424 shared_random = floor(time) + random();
425 rnd = shared_random - floor(time);
426 }
427 else
428 rnd = random();
429
430 // range:
431 // if respawntime >= ITEM_RESPAWN_TICKS: ITEM_RESPAWN_TICKS .. respawntime + respawntimejitter
432 // else: 0 .. ITEM_RESPAWN_TICKS
433 // this is to prevent powerups spawning unexpectedly without waypoints
434 spawn_in = ITEM_RESPAWN_TICKS + rnd * (e.respawntime + e.respawntimejitter - ITEM_RESPAWN_TICKS);
435 }
436
437 Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : spawn_in));
438}
float game_starttime
Definition stats.qh:82
float random(void)
float floor(float f)
void Item_ScheduleRespawnIn(entity e, float t)
Definition items.qc:325

References entity(), floor(), game_starttime, ITEM_RESPAWN_TICKS, Item_ScheduleRespawnIn(), Item_Show(), max(), random(), and time.

Referenced by Item_Reset().

◆ Item_ScheduleRespawn()

void Item_ScheduleRespawn ( entity e)

Definition at line 385 of file items.qc.

386{
387 if(e.respawntime > 0)
388 {
389 Item_Show(e, 0);
390
391 float adjusted_respawntime = adjust_respawntime(e.respawntime);
392 //LOG_INFOF("item %s will respawn in %f", e.classname, adjusted_respawntime);
393
394 // range: adjusted_respawntime - respawntimejitter .. adjusted_respawntime + respawntimejitter
395 float respawn_in = adjusted_respawntime + crandom() * e.respawntimejitter;
396 Item_ScheduleRespawnIn(e, respawn_in);
397 }
398 else // if respawntime is -1, this item does not respawn
399 Item_Show(e, -1);
400}
#define crandom()
Returns a random number between -1.0 and 1.0.
Definition random.qh:32
float adjust_respawntime(float normal_respawntime)
Adjust respawn time according to the number of players.
Definition items.qc:357

References adjust_respawntime(), crandom, entity(), Item_ScheduleRespawnIn(), and Item_Show().

Referenced by Item_ScheduleRespawnIn(), MUTATOR_HOOKABLE(), MUTATOR_HOOKFUNCTION(), and MUTATOR_HOOKFUNCTION().

◆ Item_ScheduleRespawnIn()

void Item_ScheduleRespawnIn ( entity e,
float t )

Definition at line 325 of file items.qc.

326{
327 // if the respawn time is longer than 10 seconds, show a waypoint, otherwise, just respawn normally
328 bool set_itemstime = Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS);
329 if ((set_itemstime || MUTATOR_CALLHOOK(Item_ScheduleRespawn, e, t)) && (t - ITEM_RESPAWN_TICKS) > 0)
330 {
332 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
333 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
334 e.item_respawncounter = 0;
335 }
336 else
337 {
339 e.nextthink = time;
340 e.scheduledrespawntime = time + t;
341 e.wait = time + t;
342 }
343
344 if (set_itemstime)
345 {
346 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
349 }
350}
void Item_ScheduleRespawn(entity e)
Definition items.qc:385
void Item_RespawnThink(entity this)
Definition items.qc:315

References entity(), Item_ItemsTime_Allow(), Item_ItemsTime_SetTime(), Item_ItemsTime_SetTimesForAllPlayers(), Item_ItemsTime_UpdateTime(), ITEM_RESPAWN_TICKS, Item_RespawnCountdown(), Item_RespawnThink(), Item_ScheduleRespawn(), max(), MUTATOR_CALLHOOK, setthink, STAT, time, and WEPSET_SUPERWEAPONS.

Referenced by Item_ScheduleInitialRespawn(), and Item_ScheduleRespawn().

◆ item_setactive()

void item_setactive ( entity this,
int act )

Definition at line 995 of file items.qc.

996{
997 int old_status = this.active;
998 if(act == ACTIVE_TOGGLE)
1000 else
1001 this.active = act;
1002
1003 if(this.active != old_status)
1004 Item_Show(this, ((this.active == ACTIVE_ACTIVE) ? 1 : -1));
1005}
const int ACTIVE_TOGGLE
Definition defs.qh:40
const int ACTIVE_NOT
Definition defs.qh:36

References active, ACTIVE_ACTIVE, ACTIVE_NOT, ACTIVE_TOGGLE, entity(), and Item_Show().

Referenced by StartItem().

◆ Item_Show()

void Item_Show ( entity e,
int mode )

Definition at line 130 of file items.qc.

131{
133 e.ItemStatus &= ~ITS_STAYWEP;
134 entity def = e.itemdef;
135 if (mode > 0)
136 {
137 // make the item look normal, and be touchable
138 e.model = e.mdl;
139 e.solid = SOLID_TRIGGER;
140 e.spawnshieldtime = 1;
141 e.ItemStatus |= ITS_AVAILABLE;
142 }
143 else if (mode < 0)
144 {
145 // hide the item completely
146 e.model = string_null;
147 e.solid = SOLID_NOT;
148 e.spawnshieldtime = 1;
149 e.ItemStatus &= ~ITS_AVAILABLE;
150 }
151 else
152 {
153 bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.m_wepset & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
154 || e.team // weapon stay isn't supported for teamed weapons
155 ;
156 if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
157 {
158 // make the item translucent and not touchable
159 e.model = e.mdl;
160 e.solid = SOLID_TRIGGER; // can STILL be picked up!
161 e.effects |= EF_STARDUST;
162 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
163 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
164 }
165 else
166 {
167 e.solid = SOLID_NOT;
168 e.spawnshieldtime = 1;
169 e.ItemStatus &= ~ITS_AVAILABLE;
170 }
171 }
172
173 if (def.m_glow)
174 e.ItemStatus |= ITS_GLOW;
175
177 e.effects |= EF_NODEPTHTEST;
178
180 e.ItemStatus |= ITS_ALLOWFB;
181 else
182 e.ItemStatus &= ~ITS_ALLOWFB;
183
185 e.ItemStatus |= ITS_ALLOWSI;
186
187 // relink entity (because solid may have changed)
188 setorigin(e, e.origin);
189 e.SendFlags |= ISF_STATUS;
190}
const int ITS_STAYWEP
Definition item.qh:62
const int ITS_ALLOWSI
Definition item.qh:67
const int ITS_ALLOWFB
Definition item.qh:66
const int ITS_GLOW
Definition item.qh:68
const int ITS_AVAILABLE
Definition item.qh:65
const int ISF_STATUS
Definition item.qh:52
const float EF_STARDUST
const float SOLID_TRIGGER
const float EF_ADDITIVE
const float EF_FULLBRIGHT
const float SOLID_NOT
const float EF_NODEPTHTEST
#define false
Definition csprogsdefs.qh:6
string string_null
Definition nil.qh:9
float autocvar_sv_simple_items
Definition items.qh:15
bool autocvar_g_fullbrightitems
Definition items.qh:8
bool autocvar_g_nodepthtestitems
Definition items.qh:12

References autocvar_g_fullbrightitems, autocvar_g_nodepthtestitems, autocvar_sv_simple_items, EF_ADDITIVE, EF_FULLBRIGHT, EF_NODEPTHTEST, EF_STARDUST, entity(), g_weapon_stay, ISF_STATUS, ITS_ALLOWFB, ITS_ALLOWSI, ITS_AVAILABLE, ITS_GLOW, ITS_STAYWEP, SOLID_NOT, SOLID_TRIGGER, string_null, and WEPSET_SUPERWEAPONS.

Referenced by Item_Reset(), Item_Respawn(), Item_ScheduleInitialRespawn(), Item_ScheduleRespawn(), item_setactive(), and Item_Touch().

◆ Item_Think()

void Item_Think ( entity this)

Definition at line 192 of file items.qc.

193{
194 if (ITEM_IS_LOOT(this))
195 {
196 if (time < this.wait - IT_DESPAWNFX_TIME)
197 this.nextthink = min(time + IT_UPDATE_INTERVAL, this.wait - IT_DESPAWNFX_TIME); // ensuring full time for effects
198 else
199 {
200 // despawning soon, start effects
201 this.ItemStatus |= ITS_EXPIRING;
202 this.SendFlags |= ISF_STATUS;
203 if (time < this.wait - IT_UPDATE_INTERVAL)
205 else
206 {
207 setthink(this, RemoveItem);
208 this.nextthink = this.wait;
209 }
210 }
211
212 if (this.itemdef.instanceOfPowerup)
214
215 // caution: kludge FIXME (with sv_legacy_bbox_expand)
216 // this works around prediction errors caused by bbox discrepancy between SVQC and CSQC
217 if (this.velocity == '0 0 0' && IS_ONGROUND(this))
218 this.gravity = 0; // don't send ISF_DROP anymore
219
220 // send slow updates even if the item didn't move
221 // recovers prediction desyncs where server thinks item stopped, client thinks it didn't
222 ItemUpdate(this);
223 }
224 else
225 {
226 // bones_was_here: TODO: predict movers, enable client prediction of items with a groundentity,
227 // and then send those less often too (and not all on the same frame)
228 this.nextthink = time;
229
230 if(this.origin != this.oldorigin)
231 ItemUpdate(this);
232 }
233}
float gravity
Definition items.qh:17
const int ITS_EXPIRING
Definition item.qh:69
const float IT_UPDATE_INTERVAL
Definition item.qh:76
int ItemStatus
Definition item.qh:61
const float IT_DESPAWNFX_TIME
Definition item.qh:72
vector velocity
int SendFlags
Definition net.qh:159
#define IS_ONGROUND(s)
Definition movetypes.qh:16
void powerups_DropItem_Think(entity this)

References entity(), gravity, IS_ONGROUND, ISF_STATUS, IT_DESPAWNFX_TIME, IT_UPDATE_INTERVAL, ITEM_IS_LOOT, itemdef, ItemStatus, ItemUpdate(), ITS_EXPIRING, min(), nextthink, oldorigin, origin, powerups_DropItem_Think(), RemoveItem(), SendFlags, setthink, time, velocity, and wait.

Referenced by Item_Reset(), Item_Respawn(), and StartItem().

◆ Item_Touch()

void Item_Touch ( entity this,
entity toucher )

Definition at line 686 of file items.qc.

687{
688 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
689 if (ITEM_IS_LOOT(this))
690 {
692 {
693 this.SendFlags |= ISF_REMOVEFX;
694 RemoveItem(this);
695 return;
696 }
697 }
698
699 if(!(toucher.flags & FL_PICKUPITEMS)
700 || IS_DEAD(toucher)
701 || (this.solid != SOLID_TRIGGER)
702 || (this.owner == toucher)
703 || (time < this.item_spawnshieldtime)
704 ) { return; }
705
706 switch (MUTATOR_CALLHOOK(ItemTouch, this, toucher))
707 {
708 case MUT_ITEMTOUCH_RETURN: { return; }
709 case MUT_ITEMTOUCH_PICKUP: { toucher = M_ARGV(1, entity); goto pickup; }
710 }
711
712 toucher = M_ARGV(1, entity);
713
714 if (ITEM_IS_EXPIRING(this))
715 {
718 this.speed_finished = max(0, this.speed_finished - time);
721 }
722 bool gave = ITEM_HANDLE(Pickup, this.itemdef, this, toucher);
723 if (!gave)
724 {
725 if (ITEM_IS_EXPIRING(this))
726 {
727 // undo what we did above
728 this.strength_finished += time;
730 this.speed_finished += time;
733 }
734 return;
735 }
736
737LABEL(pickup)
738
739 if(this.target != "" && this.target != "###item###") // q3compat
741
742 GameItem def = this.itemdef;
743 int ch = ((def.instanceOfPowerup && def.m_itemid != IT_RESOURCE) ? CH_TRIGGER_SINGLE : CH_TRIGGER);
745
746 MUTATOR_CALLHOOK(ItemTouched, this, toucher);
747 if (wasfreed(this))
748 {
749 return;
750 }
751
752 if (ITEM_IS_LOOT(this))
753 {
754 this.SendFlags |= ISF_REMOVEFX;
755 RemoveItem(this);
756 return;
757 }
758 if (!this.spawnshieldtime)
759 {
760 return;
761 }
762 entity e;
763 if (this.team)
764 {
766 IL_EACH(g_items, it.team == this.team,
767 {
768 if (it.itemdef) // is a registered item
769 {
770 Item_Show(it, -1);
771 it.scheduledrespawntime = 0;
772 RandomSelection_AddEnt(it, it.cnt, 0);
773 }
774 });
776 Item_Show(e, 1); // reset its state so it is visible (extra sendflags doesn't matter, this happens anyway)
777 }
778 else
779 e = this;
781}
entity owner
Definition main.qh:87
float strength_finished
Definition item.qh:93
const int IT_RESOURCE
Definition item.qh:30
float invincible_finished
Definition item.qh:94
const int ISF_REMOVEFX
Definition item.qh:49
#define ITEM_HANDLE(signal,...)
Definition item.qh:125
#define M_ARGV(x, type)
Definition events.qh:17
#define IS_DEAD(s)
Definition player.qh:244
#define LABEL(id)
Definition compiler.qh:34
const int FL_PICKUPITEMS
Definition constants.qh:80
float solid
float spawnshieldtime
Definition damage.qh:61
float invisibility_finished
#define ITEM_IS_EXPIRING(item)
Returns whether the item is expiring (i.e.
Definition spawning.qh:58
void SUB_UseTargets(entity this, entity actor, entity trigger)
Definition triggers.qc:344
float speed_finished
Definition speed.qh:17
entity entity toucher
Definition self.qh:76
#define ITEM_TOUCH_NEEDKILL()
Definition items.qh:122
float superweapons_finished
Definition items.qh:39
float item_spawnshieldtime
Definition items.qh:42
string item_pickupsound
Definition items.qh:22
@ MUT_ITEMTOUCH_PICKUP
Definition events.qh:736
@ MUT_ITEMTOUCH_RETURN
Definition events.qh:735
#define _sound(e, c, s, v, a)
Definition sound.qh:43
string target
Definition triggers.qh:55

References _sound, ATTEN_NORM, CH_TRIGGER, CH_TRIGGER_SINGLE, entity(), FL_PICKUPITEMS, g_items, IL_EACH, invincible_finished, invisibility_finished, IS_DEAD, ISF_REMOVEFX, IT_RESOURCE, ITEM_HANDLE, ITEM_IS_EXPIRING, ITEM_IS_LOOT, item_pickupsound, Item_Show(), item_spawnshieldtime, ITEM_TOUCH_NEEDKILL, itemdef, LABEL, M_ARGV, max(), MUT_ITEMTOUCH_PICKUP, MUT_ITEMTOUCH_RETURN, MUTATOR_CALLHOOK, NULL, owner, RandomSelection_chosen_ent, RandomSelection_Init(), RemoveItem(), SendFlags, solid, SOLID_TRIGGER, spawnshieldtime, speed_finished, strength_finished, SUB_UseTargets(), superweapons_finished, target, team, time, toucher, and VOL_BASE.

Referenced by StartItem().

◆ item_use()

void item_use ( entity this,
entity actor,
entity trigger )

Definition at line 987 of file items.qc.

988{
989 if (this.spawnflags & 16)
990 gettouch(this)(this, actor);
991 else // q3compat
992 Item_Respawn(this);
993}
#define gettouch(e)
Definition self.qh:78

References entity(), gettouch, Item_Respawn(), and spawnflags.

Referenced by StartItem().

◆ ItemSend()

bool ItemSend ( entity this,
entity to,
int sf )

Definition at line 31 of file items.qc.

32{
33 if(this.gravity)
34 sf |= ISF_DROP;
35 else
36 sf &= ~ISF_DROP;
37
38 // if this item is being spawned (in CSQC's perspective)
39 // reuse ISF_SIZE and ISF_SIZE2 to also tell CSQC its bbox size
40 if(sf & ISF_SIZE)
41 {
42 if(this.maxs == ITEM_S_MAXS) // Small
43 {
44 sf |= ISF_SIZE;
45 sf &= ~ISF_SIZE2;
46 }
47 else if(this.maxs == ITEM_L_MAXS) // Large
48 {
49 sf &= ~ISF_SIZE;
50 sf |= ISF_SIZE2;
51 }
52 else // Default
53 sf |= ISF_SIZE | ISF_SIZE2;
54 }
55
56 WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
58
59 //WriteByte(MSG_ENTITY, this.cnt);
60 if(sf & ISF_LOCATION)
61 {
62 WriteVector(MSG_ENTITY, this.origin);
63 }
64
65 if(sf & ISF_ANGLES)
66 {
67 WriteAngleVector(MSG_ENTITY, this.angles);
68 }
69
70 if(sf & ISF_STATUS)
72
73 if(sf & (ISF_SIZE | ISF_SIZE2)) // always true when it's spawned (in CSQC's perspective)
74 {
75 WriteShort(MSG_ENTITY, bound(0, this.fade_end, 32767));
76
77 if(this.mdl == "")
78 LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, "expect a crash just about now");
79
81 WriteByte(MSG_ENTITY, bound(0, this.skin, 255));
82 }
83
84 if(sf & ISF_COLORMAP)
85 {
87 WriteByte(MSG_ENTITY, this.glowmod.x * 255.0);
88 WriteByte(MSG_ENTITY, this.glowmod.y * 255.0);
89 WriteByte(MSG_ENTITY, this.glowmod.z * 255.0);
90 }
91
92 if(sf & ISF_DROP)
93 {
94 WriteVector(MSG_ENTITY, this.velocity);
95 }
96
97 return true;
98}
float fade_end
Definition item.qh:87
const int ISF_COLORMAP
Definition item.qh:53
string mdl
Definition item.qh:89
const int ISF_SIZE2
Definition item.qh:51
const vector ITEM_S_MAXS
Definition item.qh:81
const vector ITEM_L_MAXS
Definition item.qh:84
const int ISF_ANGLES
Definition item.qh:55
const int ISF_SIZE
Definition item.qh:56
const int ISF_LOCATION
Definition item.qh:50
const int ISF_DROP
Definition item.qh:54
string classname
vector maxs
float colormap
vector glowmod
WriteString(chan, ent.netname)
ent angles
Definition ent_cs.qc:146
WriteByte(chan, ent.angles.y/DEC_FACTOR)
skin
Definition ent_cs.qc:168
const int MSG_ENTITY
Definition net.qh:156
#define WriteHeader(to, id)
Definition net.qh:265
float bound(float min, float value, float max)
void WriteShort(float data, float dest, float desto)

References angles, bound(), classname, colormap, entity(), fade_end, glowmod, gravity, ISF_ANGLES, ISF_COLORMAP, ISF_DROP, ISF_LOCATION, ISF_SIZE, ISF_SIZE2, ISF_STATUS, ITEM_L_MAXS, ITEM_S_MAXS, ItemStatus, LOG_TRACE, maxs, mdl, MSG_ENTITY, origin, skin, velocity, WriteByte(), WriteHeader, WriteShort(), and WriteString().

Referenced by StartItem(), UpdateCSQCProjectile(), and UpdateItemAfterTeleport().

◆ ItemUpdate()

void ItemUpdate ( entity this)

Definition at line 100 of file items.qc.

101{
102 this.oldorigin = this.origin;
103 this.SendFlags |= ISF_LOCATION;
104}

References entity(), ISF_LOCATION, oldorigin, origin, and SendFlags.

Referenced by Item_RespawnThink(), Item_Think(), UpdateCSQCProjectile(), and UpdateItemAfterTeleport().

◆ RemoveItem()

void RemoveItem ( entity this)

Definition at line 865 of file items.qc.

866{
867 if(wasfreed(this) || !this) { return; }
870
871 if (this.SendFlags & ISF_REMOVEFX)
872 {
873 // delay removal until ISF_REMOVEFX has been sent
874 setthink(this, RemoveItem);
875 this.nextthink = time + 2 * autocvar_sys_ticrate; // micro optimisation: next frame will be too soon
876 this.solid = SOLID_NOT; // untouchable
877 }
878 else
879 delete(this);
880}
float autocvar_sys_ticrate
Definition main.qh:17

References autocvar_sys_ticrate, entity(), ISF_REMOVEFX, nextthink, RemoveItem(), SendFlags, setthink, solid, SOLID_NOT, time, waypointsprite_attached, and WaypointSprite_Kill().

Referenced by Item_Damage(), Item_Think(), Item_Touch(), RemoveItem(), and StartItem().

◆ setItemGroup()

void setItemGroup ( entity this)

Definition at line 1255 of file items.qc.

1256{
1257 if (!IS_SMALL(this.itemdef) || ITEM_IS_LOOT(this))
1258 return;
1259
1261 for (entity head = WarpZone_SearchInRadius(this.origin, 120, MOVE_NOTHING, setItemGroup_cond); head; head = head.chain)
1262 {
1263 if (!this.item_group)
1264 {
1265 if (!head.item_group)
1266 {
1267 head.item_group = group_count;
1268 ++group_count;
1269 }
1270 this.item_group = head.item_group;
1271 }
1272 else // spawning item is already part of a item_group X
1273 {
1274 if (!head.item_group)
1275 head.item_group = this.item_group;
1276 else if (head.item_group != this.item_group) // found an item near the spawning item that is part of a different item_group Y
1277 {
1278 int grY = head.item_group;
1279 // move all items of item_group Y to item_group X
1280 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == grY, it.item_group = this.item_group);
1281 }
1282 }
1283 }
1284}
entity WarpZone_SearchInRadius(vector org, float rad, float nomonsters, WarpZone_FindRadius_cond_callback_t cb)
Modified findradius aware of warpzones, that only includes entities that meet the "cb" criteria.
Definition common.qc:680
noref entity WarpZone_SearchInRadius_otherent
Free to use in the callback.
Definition common.qh:71
#define MOVE_NOTHING
Definition common.qh:35
bool setItemGroup_cond(entity e)
Definition items.qc:1251
#define IS_SMALL(def)
Definition items.qc:1248
int group_count
Definition items.qc:1249
int item_group
Definition items.qh:95

References entity(), g_items, group_count, IL_EACH, IS_SMALL, item_group, ITEM_IS_LOOT, itemdef, MOVE_NOTHING, origin, setItemGroup_cond(), WarpZone_SearchInRadius(), and WarpZone_SearchInRadius_otherent.

Referenced by StartItem().

◆ setItemGroup_cond()

bool setItemGroup_cond ( entity e)

Definition at line 1251 of file items.qc.

1252{
1253 return (IS_SMALL(e.itemdef) && e != WarpZone_SearchInRadius_otherent);
1254}

References entity(), IS_SMALL, and WarpZone_SearchInRadius_otherent.

Referenced by setItemGroup().

◆ setItemGroupCount()

void setItemGroupCount ( )

Definition at line 1286 of file items.qc.

1287{
1288 for (int k = 1; k <= group_count; ++k)
1289 {
1290 int count = 0;
1291 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { ++count; });
1292 if (count)
1293 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { it.item_group_count = count; });
1294 }
1295}
float count
Definition powerups.qc:22

References count, g_items, group_count, IL_EACH, and IS_SMALL.

Referenced by bot_spawn().

◆ StartItem()

void StartItem ( entity this,
entity def )

Definition at line 1007 of file items.qc.

1008{
1009 if (def.m_spawnfunc_hookreplace)
1010 def = def.m_spawnfunc_hookreplace(def, this);
1011 this.itemdef = def;
1012 if (def.m_canonical_spawnfunc != "") // FIXME why do weapons set itemdef to an entity that doesn't have this?
1013 this.classname = def.m_canonical_spawnfunc;
1014
1015 startitem_failed = true; // early return means failure
1016
1017 // some mutators check for resources set by m_iteminit in FilterItem
1018 if(def.m_iteminit)
1019 def.m_iteminit(def, this);
1020
1021 // also checked by some mutators in FilterItem
1022 this.items = def.m_itemid;
1023 this.weapon = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
1024 if(this.weapon)
1025 STAT(WEAPONS, this) = WepSet_FromWeapon(REGISTRY_GET(Weapons, this.weapon));
1026 this.flags = FL_ITEM | def.m_itemflags;
1027
1028 // FilterItem may change any field of a specific instance of an item, but
1029 // it must not change any itemdef field (would cause mutators to break other mutators),
1030 // and must not convert items into different ones (StartItem could be refactored to support that).
1031 if(MUTATOR_CALLHOOK(FilterItem, this))
1032 {
1033 delete(this);
1034 return;
1035 }
1036
1037 if (!this.item_model_ent)
1038 this.item_model_ent = def.m_model;
1039
1040 if (!this.item_pickupsound_ent)
1041 this.item_pickupsound_ent = def.m_sound;
1042 if (!this.item_pickupsound && this.item_pickupsound_ent)
1044 if (this.item_pickupsound == "")
1045 LOG_WARNF("No pickup sound set for a %s", this.classname);
1046
1047 if(!this.pickup_anyway && def.m_pickupanyway)
1048 this.pickup_anyway = def.m_pickupanyway;
1049
1050 // bones_was_here TODO: implement sv_cullentities_dist and replace g_items_maxdist with it
1051 if(!this.fade_end)
1053
1054 // bones_was_here TODO: can we do this after we're sure the entity won't be deleted?
1055 IL_PUSH(g_items, this);
1056
1057 this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1058 setmodel(this, MDL_Null); // precision set below
1059 // set item size before we spawn a waypoint or droptofloor or MoveOutOfSolid
1060 setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
1061
1062 if (ITEM_IS_LOOT(this))
1063 {
1064 this.reset = RemoveItem;
1065
1067 this.gravity = 1;
1068
1069 setthink(this, Item_Think);
1072
1073 this.owner = NULL; // anyone can pick this up, including the player who threw it
1074 this.item_spawnshieldtime = time + 0.5; // but not straight away
1075
1076 this.takedamage = DAMAGE_YES;
1077 this.event_damage = Item_Damage;
1078 // enable this to have thrown items burn in lava
1079 //this.damagedbycontents = true;
1080 //IL_PUSH(g_damagedbycontents, this);
1081
1082 if (ITEM_IS_EXPIRING(this))
1083 {
1084 // if item is worthless after a timer, have it expire then
1086 }
1087
1088 // most loot items have a bigger horizontal size than a player
1089 nudgeoutofsolid_OrFallback(this);
1090
1091 // don't drop if in a NODROP zone (such as lava)
1092 traceline(this.origin, this.origin, MOVE_NORMAL, this);
1094 {
1095 delete(this);
1096 return;
1097 }
1098 }
1099 else
1100 {
1101 // must be done after def.m_iteminit() as that may set ITEM_FLAG_MUTATORBLOCKED
1102 if(!have_pickup_item(this))
1103 {
1104 delete(this);
1105 return;
1106 }
1107
1108 // must be done before Item_Reset() and after MUTATORBLOCKED check (blocked items may be uninitialised)
1109 if(!this.respawntime)
1110 {
1111 if (def.m_respawntime)
1112 this.respawntime = def.m_respawntime;
1113 else
1114 LOG_WARNF("Default respawntime for a %s is unavailable from its itemdef", this.classname);
1115 }
1116
1117 this.reset = Item_Reset;
1118
1119 if(this.angles != '0 0 0')
1120 this.SendFlags |= ISF_ANGLES;
1121
1122 if(q3compat)
1123 {
1124 if (!this.team)
1125 {
1126 string t = GetField_fullspawndata(this, "team", false);
1127 // bones_was_here: this hack is cheaper than changing to a .string strcmp()
1128 if(t) this.team = crc16(false, t);
1129 }
1130
1131 // In Q3 the origin is in the middle of the bbox ("radius" 15), in Xon it's at the bottom
1132 // so we need to offset vertically (only for items placed by the mapper).
1133 this.origin.z += -15 - this.mins.z;
1134 setorigin(this, this.origin);
1135 }
1136
1137 // it's a level item
1138 if(this.spawnflags & 1)
1139 this.noalign = 1;
1140 if (this.noalign > 0)
1142 else
1144 // do item filtering according to gametype and other things
1145 if (this.noalign <= 0)
1146 {
1147 if (!this.noalign)
1150 }
1151
1152 if (this.targetname != "")
1153 this.use = item_use;
1154
1155 this.setactive = item_setactive;
1156 this.active = ACTIVE_ACTIVE;
1157
1158 if(autocvar_spawn_debug >= 2)
1159 {
1160 for (entity head = WarpZone_FindRadius(this.origin, 3); head; head = head.chain)
1161 if (head.is_item) // why not flags & fl_item?
1162 {
1163 LOG_TRACE("XXX Found duplicated item: ", def.m_name, vtos(this.origin));
1164 LOG_TRACE(" vs ", head.netname, vtos(head.origin));
1165 error("Mapper sucks.");
1166 }
1167 this.is_item = true;
1168 }
1169
1171
1172 if ( def.instanceOfPowerup
1173 || def.instanceOfWeaponPickup
1174 || (def.instanceOfHealth && def != ITEM_HealthSmall)
1175 || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1176 || (def.m_itemid & (IT_KEY1 | IT_KEY2))
1177 )
1178 {
1179 if(!this.target || this.target == "")
1180 this.target = "###item###"; // for finding the nearest item using findnearest
1181 }
1182
1183 Item_ItemsTime_SetTime(this, 0);
1184
1185 this.glowmod = def.m_color;
1186 }
1187
1188 this.bot_pickup = true;
1189 this.bot_pickupevalfunc = def.m_pickupevalfunc;
1190 this.bot_pickupbasevalue = def.m_botvalue;
1191 this.netname = def.m_name;
1192 settouch(this, Item_Touch);
1193 //this.effects |= EF_LOWPRECISION;
1194
1195 // support skinned models for powerups
1196 if(!this.skin)
1197 this.skin = def.m_skin;
1198
1199 if (!(this.spawnflags & 1024)) {
1200 if(def.instanceOfPowerup)
1201 this.ItemStatus |= ITS_ANIMATE1;
1202
1203 if(GetResource(this, RES_ARMOR) || GetResource(this, RES_HEALTH))
1204 this.ItemStatus |= ITS_ANIMATE2;
1205 }
1206
1207 if(def.instanceOfWeaponPickup)
1208 {
1209 if (!ITEM_IS_LOOT(this)) // if dropped, colormap is already set up nicely
1210 this.colormap = 1024; // color shirt=0 pants=0 grey
1211 if (!(this.spawnflags & 1024))
1212 this.ItemStatus |= ITS_ANIMATE1;
1213 this.SendFlags |= ISF_COLORMAP;
1214 }
1215
1216 this.state = 0;
1217 if(this.team)
1218 {
1219 if(!this.cnt)
1220 this.cnt = 1; // item probability weight
1221
1222 this.effects |= EF_NOGUNBOB; // marker for item team search
1224 this.reset = Item_FindTeam;
1225 }
1226 else
1227 Item_Reset(this);
1228
1229 Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1230
1231 // call this hook after everything else has been done
1232 if (MUTATOR_CALLHOOK(Item_Spawn, this))
1233 {
1234 delete(this);
1235 return;
1236 }
1237
1238 // we should be sure this item will spawn before loading its assets
1239 // CSQC handles model precaching: it may not use this model (eg simple items) and may not have connected yet
1240 //precache_model(this.mdl);
1242
1243 setItemGroup(this);
1244
1245 startitem_failed = false;
1246}
void waypoint_spawnforitem(entity e)
float bot_pickup
Definition api.qh:43
float bot_pickupbasevalue
Definition bot.qh:68
string netname
Definition powerups.qc:20
const int ITS_ANIMATE1
Definition item.qh:63
const int ITS_ANIMATE2
Definition item.qh:64
#define setmodel(this, m)
Definition model.qh:26
vector weaponsInMap
all the weapons actually spawned in the map, does not include filtered items
Definition stats.qh:53
const int INITPRIO_FINDTARGET
Definition constants.qh:89
const int FL_ITEM
Definition constants.qh:69
float flags
float DPCONTENTS_NODROP
const float MOVE_NORMAL
vector mins
float trace_dpstartcontents
#define use
model
Definition ent_cs.qc:164
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
bool startitem_failed
Definition spawning.qh:7
void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc)
Definition net.qh:167
#define WarpZone_FindRadius(org, radius)
Modified findradius aware of warpzones.
Definition common.qh:73
#define LOG_WARNF(...)
Definition log.qh:59
string precache_sound(string sample)
string vtos(vector v)
string strzone(string s)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_NONE
Definition movetypes.qh:133
const int MOVETYPE_TOSS
Definition movetypes.qh:139
#define error
Definition pre.qh:6
q3compat
Definition quake3.qc:59
#define settouch(e, f)
Definition self.qh:77
int autocvar_spawn_debug
Definition client.qh:51
bool ItemSend(entity this, entity to, int sf)
Definition items.qc:31
void Item_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
Definition items.qc:981
void setItemGroup(entity this)
Definition items.qc:1255
void item_use(entity this, entity actor, entity trigger)
Definition items.qc:987
void Item_FindTeam(entity this)
Definition items.qc:813
bool have_pickup_item(entity this)
Definition items.qc:112
void Item_Reset(entity this)
Definition items.qc:783
void item_setactive(entity this, int act)
Definition items.qc:995
void Item_Touch(entity this, entity toucher)
Definition items.qc:686
entity item_pickupsound_ent
Definition items.qh:23
entity item_model_ent
Definition items.qh:24
bool noalign
Definition items.qh:37
float pickup_anyway
Definition items.qh:27
float autocvar_g_items_maxdist
Definition items.qh:9
bool is_item
Definition items.qh:91
float respawntime
Definition items.qh:31
float autocvar_g_items_dropped_lifetime
Definition items.qh:10
string GetField_fullspawndata(entity e, string fieldname, bool vfspath)
Retrieves the value of a map entity field from fullspawndata.
Definition main.qc:451
#define Sound_fixpath(this)
Definition sound.qh:141
const int DAMAGE_YES
Definition subs.qh:80
vector pos1
Definition subs.qh:50
float takedamage
Definition subs.qh:78
#define IT_KEY1
Definition sys-pre.qh:20
#define IT_KEY2
Definition sys-pre.qh:21
void DropToFloor_QC_DelayedInit(entity this)
Definition world.qc:2402
void InitializeEntity(entity e, void(entity this) func, int order)
Definition world.qc:2204

References active, ACTIVE_ACTIVE, angles, autocvar_g_items_dropped_lifetime, autocvar_g_items_maxdist, autocvar_spawn_debug, bot_pickup, bot_pickupbasevalue, classname, cnt, colormap, DAMAGE_YES, DPCONTENTS_NODROP, DropToFloor_QC_DelayedInit(), EF_NOGUNBOB, effects, entity(), error, fade_end, FL_ITEM, flags, g_items, GetField_fullspawndata(), GetResource(), glowmod, gravity, have_pickup_item(), IL_PUSH(), InitializeEntity(), INITPRIO_FINDTARGET, invincible_finished, is_item, ISF_ANGLES, ISF_COLORMAP, IT_KEY1, IT_KEY2, IT_UPDATE_INTERVAL, Item_Damage(), Item_FindTeam(), ITEM_IS_EXPIRING, ITEM_IS_LOOT, Item_ItemsTime_SetTime(), item_model_ent, item_pickupsound, item_pickupsound_ent, Item_Reset(), item_setactive(), item_spawnshieldtime, Item_Think(), Item_Touch(), item_use(), itemdef, items, ItemSend(), ItemStatus, ITS_ANIMATE1, ITS_ANIMATE2, LOG_TRACE, LOG_WARNF, max(), mdl, mins, model, MOVE_NORMAL, MOVETYPE_NONE, MOVETYPE_TOSS, MUTATOR_CALLHOOK, Net_LinkEntity(), netname, nextthink, noalign, NULL, origin, owner, pickup_anyway, pos1, precache_sound(), q3compat, REGISTRY_GET, RemoveItem(), RES_ARMOR, respawntime, SendFlags, set_movetype(), setItemGroup(), setmodel, setthink, settouch, skin, Sound_fixpath, spawnflags, startitem_failed, STAT, state, strength_finished, strzone(), superweapons_finished, takedamage, target, targetname, team, time, trace_dpstartcontents, use, vtos(), wait, WarpZone_FindRadius, waypoint_spawnforitem(), weapon, Weapons, weaponsInMap, and WepSet_FromWeapon.

Referenced by instagib_replace_item_with(), Item_Initialise(), lms_replace_with_extralife(), and weapon_defaultspawnfunc().

◆ UpdateItemAfterTeleport()

void UpdateItemAfterTeleport ( entity this)

Definition at line 106 of file items.qc.

107{
108 if(getSendEntity(this) == ItemSend)
109 ItemUpdate(this);
110}
#define getSendEntity(e)

References entity(), getSendEntity, ItemSend(), and ItemUpdate().

Referenced by TeleportPlayer(), and WarpZone_PostTeleportPlayer_Callback().

◆ weapon_pickupevalfunc()

float weapon_pickupevalfunc ( entity player,
entity item )

Definition at line 887 of file items.qc.

888{
889 // See if I have it already
890 if(STAT(WEAPONS, player) & STAT(WEAPONS, item))
891 {
892 // If I can pick it up
893 if(!item.spawnshieldtime)
894 return 0;
895 return ammo_pickupevalfunc(player, item);
896 }
897
898 // reduce weapon value if bot already got a good arsenal
899 float c = 1;
900 int weapons_value = 0;
901 FOREACH(Weapons, it != WEP_Null && (STAT(WEAPONS, player) & it.m_wepset), {
902 weapons_value += it.bot_pickupbasevalue;
903 });
904 c -= bound(0, weapons_value / 20000, 1) * 0.5;
905
906 return item.bot_pickupbasevalue * c;
907}
float ammo_pickupevalfunc(entity player, entity item)
Definition items.qc:909

References ammo_pickupevalfunc(), bound(), entity(), FOREACH, STAT, and Weapons.

Variable Documentation

◆ group_count

int group_count = 1

Definition at line 1249 of file items.qc.

Referenced by setItemGroup(), and setItemGroupCount().