Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
powerups.qc File Reference
#include "powerups.qh"
#include <client/draw.qh>
#include <common/items/_mod.qh>
#include <common/util.qh>
Include dependency graph for powerups.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void addPowerupItem (string name, string icon, vector color, float currentTime, float lifeTime, bool isInfinite)
int getPowerupItemAlign (int align, int column, int row, int columns, int rows, bool isVertical)
void HUD_Powerups (bool should_draw)
void HUD_Powerups_Export (int fh)
void resetPowerupItems ()

Variables

float cnt
vector colormod
float count
float lifetime
string message
string netname
entity powerupItems
int powerupItemsCount

Function Documentation

◆ addPowerupItem()

void addPowerupItem ( string name,
string icon,
vector color,
float currentTime,
float lifeTime,
bool isInfinite )

Definition at line 38 of file powerups.qc.

39{
40 if (!powerupItems)
42
43 entity item;
44 for (item = powerupItems; item.count; item = item.chain)
45 if (!item.chain)
46 item.chain = spawn();
47
48 item.message = name;
49 item.netname = icon;
50 item.colormod = color;
51 item.count = currentTime;
52 item.lifetime = lifeTime;
53 item.cnt = isInfinite;
54
56}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
entity powerupItems
Definition powerups.qc:26
int powerupItemsCount
Definition powerups.qc:27
#define spawn
vector color
Definition dynlight.qc:15
string name
Definition menu.qh:30

References color, entity(), name, powerupItems, powerupItemsCount, spawn, and vector.

Referenced by StatusEffect::m_tick().

◆ getPowerupItemAlign()

int getPowerupItemAlign ( int align,
int column,
int row,
int columns,
int rows,
bool isVertical )

Definition at line 58 of file powerups.qc.

59{
60 TC(int, align); TC(int, column); TC(int, row); TC(int, columns); TC(int, rows); TC(bool, isVertical);
61 if (align < 2)
62 return align;
63
64 bool isTop = isVertical && rows > 1 && row == 0;
65 bool isBottom = isVertical && rows > 1 && row == rows - 1;
66 bool isLeft = !isVertical && columns > 1 && column == 0;
67 bool isRight = !isVertical && columns > 1 && column == columns - 1;
68
69 if (isTop || isLeft) return (align == 2) ? 1 : 0;
70 if (isBottom || isRight) return (align == 2) ? 0 : 1;
71
72 return 2;
73}
#define TC(T, sym)
Definition _all.inc:82

References TC.

Referenced by HUD_Powerups().

◆ HUD_Powerups()

void HUD_Powerups ( bool should_draw)

Definition at line 75 of file powerups.qc.

76{
77 if (!should_draw)
78 return;
79
80 // Initialize items
82 {
84 return;
86 return;
87 }
88
89 // Add items to linked list
91
92 MUTATOR_CALLHOOK(HUD_Powerups_add);
93
95 return;
96
97 // Draw panel background
99
102 else
105
106 // Set drawing area
107 vector pos = panel_pos;
109 bool isVertical = size.y > size.x;
110
112 {
113 pos += '1 1 0' * panel_bg_padding;
114 size -= '2 2 0' * panel_bg_padding;
115 }
116
117 // Find best partitioning of the drawing area
118 const float DESIRED_ASPECT = 6;
119 float aspect = 0, a;
120 int columns = 0, c;
121 int rows = 0, r;
122 int i = 1;
123
124 do
125 {
126 c = floor(powerupItemsCount / i);
127 r = ceil(powerupItemsCount / c);
128 a = isVertical
129 ? (size.y / r) / (size.x / c)
130 : (size.x / c) / (size.y / r);
131
132 if (i == 1 || fabs(DESIRED_ASPECT - a) < fabs(DESIRED_ASPECT - aspect))
133 {
134 aspect = a;
135 columns = c;
136 rows = r;
137 }
138 }
139 while (++i <= powerupItemsCount);
140
141 // Prevent single items from getting too wide
142 if (powerupItemsCount == 1 && aspect > DESIRED_ASPECT)
143 {
144 if (isVertical)
145 {
146 size.y *= 0.5;
147 pos.y += size.y * 0.5;
148 }
149 else
150 {
151 size.x *= 0.5;
152 pos.x += size.x * 0.5;
153 }
154 }
155
156 // Draw items from linked list
157 vector itemPos = pos;
158 vector itemSize = vec2(size.x / columns, size.y / rows);
159 vector textColor = '1 1 1';
160
161 int fullSeconds = 0;
162 int align = 0;
163 int column = 0;
164 int row = 0;
165
167 for (entity item = powerupItems; item.count; item = item.chain)
168 {
169 itemPos = vec2(pos.x + column * itemSize.x, pos.y + row * itemSize.y);
170
171 // Draw progressbar
173 {
174 align = getPowerupItemAlign(autocvar_hud_panel_powerups_baralign, column, row, columns, rows, isVertical);
175 HUD_Panel_DrawProgressBar(itemPos, itemSize, "progressbar", item.count / item.lifetime, isVertical, align, item.colormod, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
176 }
177
178 // Draw icon and text
180 {
181 align = getPowerupItemAlign(autocvar_hud_panel_powerups_iconalign, column, row, columns, rows, isVertical);
182 fullSeconds = ceil(item.count);
183 textColor = '0.6 0.6 0.6' + (item.colormod * 0.4);
184
185 if (item.cnt)
186 DrawNumIcon(itemPos, itemSize, fullSeconds, item.netname, isVertical, true, align, textColor, panel_fg_alpha);
187 else
188 {
189 if (item.count > 1)
190 DrawNumIcon(itemPos, itemSize, fullSeconds, item.netname, isVertical, false, align, textColor, panel_fg_alpha);
191 if (item.count <= 5)
192 DrawNumIcon_expanding(itemPos, itemSize, fullSeconds, item.netname, isVertical, false, align, textColor, panel_fg_alpha, bound(0, (fullSeconds - item.count) * 2, 1));
193 }
194 }
195
196 // Determine next section
197 if (isVertical)
198 {
199 if (++column >= columns)
200 {
201 column = 0;
202 ++row;
203 }
204 }
205 else
206 {
207 if (++row >= rows)
208 {
209 row = 0;
210 ++column;
211 }
212 }
213 }
215}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
#define draw_beginBoldFont()
Definition draw.qh:4
#define draw_endBoldFont()
Definition draw.qh:5
int getPowerupItemAlign(int align, int column, int row, int columns, int rows, bool isVertical)
Definition powerups.qc:58
void resetPowerupItems()
Definition powerups.qc:29
bool autocvar_hud_panel_powerups_dynamichud
Definition powerups.qh:6
bool autocvar_hud_panel_powerups_text
Definition powerups.qh:10
int autocvar_hud_panel_powerups_baralign
Definition powerups.qh:5
bool autocvar_hud_panel_powerups_hide_ondeath
Definition powerups.qh:7
int autocvar_hud_panel_powerups_iconalign
Definition powerups.qh:8
bool autocvar_hud_panel_powerups_progressbar
Definition powerups.qh:9
bool autocvar_hud_panel_powerups
Definition powerups.qh:4
int spectatee_status
the -1 disables HUD panels before CSQC receives necessary data
Definition main.qh:197
const float DRAWFLAG_NORMAL
vector size
v y
Definition ent_cs.qc:121
void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
Definition hud.qc:269
void HUD_Panel_LoadCvars()
Definition hud.qc:215
void DrawNumIcon(vector myPos, vector mySize, float theTime, string icon, bool vertical, bool isInfinite, int icon_right_align, vector color, float theAlpha)
Definition hud.qc:474
void HUD_Scale_Enable()
Definition hud.qc:91
void HUD_Scale_Disable()
Definition hud.qc:84
void DrawNumIcon_expanding(vector myPos, vector mySize, float theTime, string icon, bool vertical, bool isInfinite, int icon_right_align, vector color, float theAlpha, float fadelerp)
Definition hud.qc:393
float autocvar_hud_progressbar_alpha
Definition hud.qh:204
vector panel_size
Definition hud.qh:163
float panel_fg_alpha
Definition hud.qh:169
float panel_bg_padding
Definition hud.qh:174
#define HUD_Panel_DrawBg()
Definition hud.qh:55
vector panel_pos
Definition hud.qh:162
bool autocvar__hud_configure
Definition hud_config.qh:3
#define STAT(...)
Definition stats.qh:82
float ceil(float f)
float bound(float min, float value, float max)
float fabs(float f)
float floor(float f)
vector
Definition self.qh:92
#define vec2(...)
Definition vector.qh:90

References autocvar__hud_configure, autocvar_hud_panel_powerups, autocvar_hud_panel_powerups_baralign, autocvar_hud_panel_powerups_dynamichud, autocvar_hud_panel_powerups_hide_ondeath, autocvar_hud_panel_powerups_iconalign, autocvar_hud_panel_powerups_progressbar, autocvar_hud_panel_powerups_text, autocvar_hud_progressbar_alpha, bound(), ceil(), draw_beginBoldFont, draw_endBoldFont, DRAWFLAG_NORMAL, DrawNumIcon(), DrawNumIcon_expanding(), entity(), fabs(), floor(), getPowerupItemAlign(), HUD_Panel_DrawBg, HUD_Panel_DrawProgressBar(), HUD_Panel_LoadCvars(), HUD_Scale_Disable(), HUD_Scale_Enable(), MUTATOR_CALLHOOK, panel_bg_padding, panel_fg_alpha, panel_pos, panel_size, powerupItems, powerupItemsCount, resetPowerupItems(), size, spectatee_status, STAT, vec2, and vector.

◆ HUD_Powerups_Export()

void HUD_Powerups_Export ( int fh)

Definition at line 9 of file powerups.qc.

10{
11 // allow saving cvars that aesthetically change the panel into hud skin files
12 HUD_Write_Cvar("hud_panel_powerups_iconalign");
13 HUD_Write_Cvar("hud_panel_powerups_baralign");
14 HUD_Write_Cvar("hud_panel_powerups_progressbar");
15 HUD_Write_Cvar("hud_panel_powerups_text");
16}
#define HUD_Write_Cvar(cvar)
Definition hud_config.qh:40

References HUD_Write_Cvar.

◆ resetPowerupItems()

void resetPowerupItems ( )

Definition at line 29 of file powerups.qc.

30{
31 entity item;
32 for (item = powerupItems; item; item = item.chain)
33 item.count = 0;
34
36}

References entity(), powerupItems, and powerupItemsCount.

Referenced by HUD_Powerups().

Variable Documentation

◆ cnt

float cnt

Definition at line 24 of file powerups.qc.

Referenced by a_think(), AppendItemcodes(), AuxiliaryXhair_customize(), AuxiliaryXhair_Draw2D(), basketball_touch(), beam_think(), bumble_raygun_send(), Casing_Draw(), classfield(), classfield(), ClientInit_CheckUpdate(), ClientInit_misc(), ctf_SpawnTeam(), DamageEffect_Think(), dom_controlpoint_setup(), dompoint_captured(), dompointtouch(), DragBox_Think(), Draw_GrapplingHook(), football_touch(), func_breakable_destroy(), func_breakable_setup(), func_pendulum_controller_think(), GameType_GetIcon(), GameType_GetID(), GameType_GetName(), Gib_Draw(), Gib_Touch(), InitBall(), Item_CopyFields(), ka_BallThink_Carried(), ka_TouchEvent(), kh_Controller_Think(), kh_Key_Think(), KillIndicator_Think(), laser_SendEntity(), M_Golem_Attack_Lightning_Think(), ModelEffect_Draw(), Monster_Delay_Action(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), physical_item_damage(), physical_item_think(), physical_item_touch(), PingPLReport_Think(), pointparticles_SendEntity(), Portal_RemoveLater_Think(), Projectile_Draw(), Projectile_DrawTrail(), racer_deadtouch(), racer_rocket_groundhugger(), racer_rocket_tracker(), rainsnow_SendEntity(), RandomSeed_Send(), RandomSeed_Think(), raptor_bomb_burst(), RaptorCBShellfragDraw(), relay_activators_use(), relocate_spawnpoint(), ResetBall(), round_handler_Init(), round_handler_Reset(), round_handler_Think(), SendAuxiliaryXhair(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spiderbot_blowup(), spiderbot_headfade(), spiderbot_rocket_guided(), spiderbot_rocket_unguided(), StartItem(), target_assault_roundend_reset(), target_levelwarp_use(), target_push_send(), tdm_SpawnTeam(), teleport_dest_send(), tka_BallThink_Carried(), tka_TouchEvent(), tmayhem_SpawnTeam(), trigger_gravity_touch(), turret_gib_draw(), turret_hk_missile_think(), turret_targettrigger_touch(), VaporizerBeam_Draw(), vehicles_gib_think(), viewloc_send(), Violence_GibSplash_SendEntity(), W_Arc_Bolt_Touch(), W_Crylink_Touch(), W_Devastator_Think(), W_Fireball_Damage(), W_Fireball_Explode(), W_Fireball_Firemine_Think(), W_Fireball_Think(), W_Hagar_Touch2(), W_LastWeapon(), W_MineLayer_Stick(), W_MineLayer_Think(), W_Mortar_Grenade_Think1(), W_OverkillRocketPropelledChainsaw_Think(), W_Porto_Fail(), W_Porto_Touch(), W_Seeker_Missile_Think(), W_Seeker_Vollycontroller_Think(), W_Shotgun_Melee_Think(), W_Tuba_NoteOff(), W_Tuba_NoteSendEntity(), walker_rocket_think(), WaypointSprite_SendEntity(), and XonoticGametypeList_loadCvars().

◆ colormod

◆ count

float count

Definition at line 22 of file powerups.qc.

Referenced by bot_setnameandstuff(), buff_Init(), classfield(), ClientInit_CheckUpdate(), ClientInit_misc(), counter_use(), cpicon_send(), Ent_RemoveProjectile(), func_breakable_destroy(), func_breakable_setup(), generator_draw(), generator_send(), havocbot_ctf_reset_role(), HUD_ItemsTime(), HUD_Notify(), jumppad_push(), KillIndicator_Think(), Local_Notification(), misc_laser_think(), Monster_Delay_Action(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), ons_ControlPoint_Icon_BuildThink(), ons_ControlPoint_Icon_Damage(), ons_ControlPoint_Icon_Think(), ons_generator_ray_draw(), ons_GeneratorDamage(), Pickup_Update(), PlayerStats_PlayerDetail_Handler(), pointparticles_SendEntity(), Projectile_Draw(), rainsnow_SendEntity(), round_handler_FirstThink(), round_handler_Init(), round_handler_Reset(), round_handler_Think(), Send_Notification(), setItemGroupCount(), spawner_use(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), SUB(), target_changelevel_use(), target_invasion_roundend_use(), target_spawn_cancreate(), trigger_gravity_check_think(), trigger_push_velocity_calculatevelocity(), trigger_push_velocity_send(), trigger_relay_if_use(), void(), void(), W_Devastator_Think(), waypoint_save_hardwiredlinks(), and weapon_defaultspawnfunc().

◆ lifetime

◆ message

◆ netname

◆ powerupItems

entity powerupItems

Definition at line 26 of file powerups.qc.

Referenced by addPowerupItem(), HUD_Powerups(), and resetPowerupItems().

◆ powerupItemsCount

int powerupItemsCount

Definition at line 27 of file powerups.qc.

Referenced by addPowerupItem(), HUD_Powerups(), and resetPowerupItems().