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

Go to the source code of this file.

Functions

 spawnfunc (target_items)
void target_items_use (entity this, entity actor, entity trigger)

Function Documentation

◆ spawnfunc()

spawnfunc ( target_items )

Definition at line 32 of file items.qc.

33{
34 this.use = target_items_use;
35 if(!this.strength_finished)
37 if(!this.invincible_finished)
39 if(!this.speed_finished)
41 if(!this.invisibility_finished)
43 if(!this.superweapons_finished)
45
46 string str;
47 int n = tokenize_console(this.netname);
48 if(argv(0) == "give")
49 {
51 }
52 else
53 {
54 for(int j = 0; j < n; ++j)
55 {
56 // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code
57 if (argv(j) == "unlimited_ammo") this.items |= IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS;
58 else if(argv(j) == "unlimited_weapon_ammo") this.items |= IT_UNLIMITED_AMMO;
59 else if(argv(j) == "unlimited_superweapons") this.items |= IT_UNLIMITED_SUPERWEAPONS;
60 else if(argv(j) == "strength") this.items |= ITEM_Strength.m_itemid;
61 else if(argv(j) == "invincible") this.items |= ITEM_Shield.m_itemid;
62 else if(argv(j) == "speed") this.items |= ITEM_Speed.m_itemid;
63 else if(argv(j) == "invisibility") this.items |= ITEM_Invisibility.m_itemid;
64 else if(argv(j) == "superweapons") this.items |= IT_SUPERWEAPON;
65 else if(argv(j) == "jetpack") this.items |= ITEM_Jetpack.m_itemid;
66 else if(argv(j) == "fuel_regen") this.items |= ITEM_FuelRegen.m_itemid;
67 else
68 {
69 FOREACH(StatusEffects, it.instanceOfBuff,
70 {
71 string s = Buff_CompatName(argv(j));
72 if(s == it.netname)
73 {
74 this.buffdef = it;
75 if(!this.buffs_finished)
76 this.buffs_finished = it.m_time(it);
77 break;
78 }
79 });
80 FOREACH(Weapons, it != WEP_Null, {
81 string s = argv(j);
82 if(s == it.netname || s == it.m_deprecated_netname)
83 {
84 STAT(WEAPONS, this) |= (it.m_wepset);
85 if(this.spawnflags == 0 || this.spawnflags == 2)
86 it.wr_init(it);
87 break;
88 }
89 });
90 }
91 }
92
93 string itemprefix, valueprefix;
94 // bones_was_here: this is inconsistent with entities.ent documentation, what's the intended behaviour?
95 // Knowing that should allow some optimising (target_items is much slower than target_give when triggered).
96 // spawnflags is supposed to be a bitfield, target_items breaks the standard :/
97 if(this.spawnflags == 0)
98 {
99 itemprefix = "";
100 valueprefix = "";
101 }
102 else if(this.spawnflags == 1)
103 {
104 itemprefix = "max ";
105 valueprefix = "max ";
106 }
107 else if(this.spawnflags == 2)
108 {
109 itemprefix = "min ";
110 valueprefix = "min ";
111 }
112 else if(this.spawnflags == 4)
113 {
114 itemprefix = "minus ";
115 valueprefix = "max ";
116 }
117 else
118 {
119 error("invalid spawnflags");
120 itemprefix = valueprefix = string_null;
121 }
122
123 str = "";
124 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & IT_UNLIMITED_AMMO), "unlimited_weapon_ammo");
125 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
126 str = sprintf("%s %s%d %s", str, valueprefix, this.strength_finished * boolean(this.items & ITEM_Strength.m_itemid), "strength");
127 str = sprintf("%s %s%d %s", str, valueprefix, this.invincible_finished * boolean(this.items & ITEM_Shield.m_itemid), "invincible");
128 str = sprintf("%s %s%d %s", str, valueprefix, this.invisibility_finished * boolean(this.items & ITEM_Invisibility.m_itemid), "invisibility");
129 str = sprintf("%s %s%d %s", str, valueprefix, this.speed_finished * boolean(this.items & ITEM_Speed.m_itemid), "speed");
130 str = sprintf("%s %s%d %s", str, valueprefix, this.superweapons_finished * boolean(this.items & IT_SUPERWEAPON), "superweapons");
131 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & ITEM_Jetpack.m_itemid), "jetpack");
132 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & ITEM_FuelRegen.m_itemid), "fuel_regen");
133 float res;
134 res = GetResource(this, RES_SHELLS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "shells");
135 res = GetResource(this, RES_BULLETS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "nails");
136 res = GetResource(this, RES_ROCKETS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "rockets");
137 res = GetResource(this, RES_CELLS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "cells");
138 res = GetResource(this, RES_FUEL); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "fuel");
139 res = GetResource(this, RES_HEALTH); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "health");
140 res = GetResource(this, RES_ARMOR); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "armor");
141 FOREACH(StatusEffects, it.instanceOfBuff, str = sprintf("%s %s%d %s", str, valueprefix, this.buffs_finished * boolean(this.buffdef == it), it.netname));
142 FOREACH(Weapons, it != WEP_Null, str = sprintf("%s %s%d %s", str, itemprefix, !!(STAT(WEAPONS, this) & (it.m_wepset)), it.netname));
143 }
144 this.netname = strzone(str);
145
146 n = tokenize_console(this.netname);
147 for(int j = 0; j < n; ++j)
148 {
149 string cmd = argv(j);
150 FOREACH(Weapons, it != WEP_Null && (cmd == it.netname || cmd == it.m_deprecated_netname), {
151 it.wr_init(it);
152 break;
153 });
154 }
155}
entity buffdef
Definition buffs.qh:60
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
string netname
Definition powerups.qc:20
int spawnflags
Definition ammo.qh:15
float strength_finished
Definition item.qh:93
const int IT_SUPERWEAPON
Definition item.qh:41
float buffs_finished
Definition item.qh:95
const int IT_UNLIMITED_AMMO
Definition item.qh:23
const int IT_UNLIMITED_SUPERWEAPONS
Definition item.qh:24
float invincible_finished
Definition item.qh:94
void target_items_use(entity this, entity actor, entity trigger)
Definition items.qc:3
int items
Definition player.qh:226
#define use
#define argv_end_index
#define tokenize_console
#define argv_start_index
RES_ARMOR
Definition ent_cs.qc:130
Weapons
Definition guide.qh:113
float invisibility_finished
float autocvar_g_balance_powerup_invisibility_time
#define FOREACH(list, cond, body)
Definition iter.qh:19
#define STAT(...)
Definition stats.qh:82
string substring(string s, float start, float length)
void cmd(string command,...)
string strzone(string s)
string argv(float n)
float max(float f,...)
float speed_finished
Definition speed.qh:17
float autocvar_g_balance_powerup_speed_time
Definition speed.qh:22
string string_null
Definition nil.qh:9
#define error
Definition pre.qh:6
float autocvar_g_balance_superweapons_time
Definition items.qh:7
float superweapons_finished
Definition items.qh:39
float autocvar_g_balance_powerup_invincible_time
Definition shield.qh:20
float autocvar_g_balance_powerup_strength_time
Definition strength.qh:22

References argv(), argv_end_index, argv_start_index, autocvar_g_balance_powerup_invincible_time, autocvar_g_balance_powerup_invisibility_time, autocvar_g_balance_powerup_speed_time, autocvar_g_balance_powerup_strength_time, autocvar_g_balance_superweapons_time, buffdef, buffs_finished, error, FOREACH, GetResource(), invincible_finished, invisibility_finished, IT_SUPERWEAPON, IT_UNLIMITED_AMMO, IT_UNLIMITED_SUPERWEAPONS, items, max(), netname, RES_ARMOR, spawnflags, speed_finished, STAT, strength_finished, string_null, substring(), superweapons_finished, target_items_use(), tokenize_console, use, and Weapons.

◆ target_items_use()

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

Definition at line 3 of file items.qc.

4{
5 // bones_was_here: why is EXACTTRIGGER_TOUCH here?
6 // target_items has no bmodel (according to entities.ent), no touch func, and is SOLID_NOT
7
8 if(ITEM_IS_LOOT(actor))
9 {
10 EXACTTRIGGER_TOUCH(this, trigger);
11 delete(actor);
12 return;
13 }
14
15 if (!IS_PLAYER(actor) || IS_DEAD(actor))
16 return;
17
18 if(trigger.solid == SOLID_TRIGGER)
19 {
20 EXACTTRIGGER_TOUCH(this, trigger);
21 }
22
23 IL_EACH(g_items, it.enemy == actor && ITEM_IS_LOOT(it),
24 {
25 delete(it);
26 });
27
28 if(GiveItems(actor, 0, tokenize_console(this.netname)))
29 centerprint(actor, this.message);
30}
string message
Definition powerups.qc:19
#define IS_DEAD(s)
Definition player.qh:244
#define IS_PLAYER(s)
Definition player.qh:242
const float SOLID_TRIGGER
#define IL_EACH(this, cond, body)
#define ITEM_IS_LOOT(item)
Returns whether the item is loot.
Definition spawning.qh:39
#define EXACTTRIGGER_TOUCH(e, t)
Definition common.qh:115
void centerprint(string text,...)
float GiveItems(entity e, float beginarg, float endarg)
Definition items.qc:1435
IntrusiveList g_items
Definition items.qh:119

References centerprint(), entity(), EXACTTRIGGER_TOUCH, g_items, GiveItems(), IL_EACH, IS_DEAD, IS_PLAYER, ITEM_IS_LOOT, message, netname, SOLID_TRIGGER, and tokenize_console.

Referenced by spawnfunc().