Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
cl_survival.qc
Go to the documentation of this file.
1#include "cl_survival.qh"
2
3#include <client/draw.qh>
5
6NET_HANDLE(ENT_CLIENT_SURVIVALSTATUSES, bool isnew)
7{
8 make_pure(this);
9 int sf = ReadByte();
10 if (sf & BIT(0)) // make all players survivors
11 {
12 for (int j = 0; j < maxclients; ++j)
13 if (playerslots[j])
14 playerslots[j].survival_status = SURV_STATUS_PREY;
15 }
16 if (sf & BIT(1)) // receive hunter statuses
17 {
18 for (int i = 1; i <= maxclients; i += 8)
19 {
20 int f = ReadByte();
21 for (int b = 0; b < 8; ++b)
22 {
23 if (!(f & BIT(b))) continue;
24 int j = i - 1 + b;
25 if (playerslots[j])
26 playerslots[j].survival_status = SURV_STATUS_HUNTER;
27 }
28 }
29 }
30
31 // color all players
32 for (int i = 1; i <= maxclients; ++i)
33 {
34 entity e = playerslots[i - 1];
35 if (!e) continue;
36
37 int plcolor = SURV_COLOR_PREY; // default color
38 if(e.survival_status == SURV_STATUS_HUNTER) // if client knows this hunter
39 plcolor = SURV_COLOR_HUNTER;
40
41 e.colormap = 1024 + plcolor; // override scoreboard and player model colors
42 }
43
44 return true;
45}
46
47void HUD_Mod_Survival(vector pos, vector mySize, bool should_draw)
48{
49 if (!should_draw)
50 return;
51
52 mod_active = 1; // survival should always show the mod HUD
53
54 int mystatus = playerslots[player_localnum].survival_status;
55 string player_text = "";
56 vector player_color = '1 1 1';
57 //string player_icon = "";
58
59 if(STAT(GAMESTARTTIME) > time || STAT(ROUNDSTARTTIME) > time || entcs_IsSpectating(player_localnum))
60 return;
61
62 if(mystatus == SURV_STATUS_HUNTER)
63 {
64 player_text = _("Hunter");
65 player_color = '1 0 0';
66 //player_icon = "player_red";
67 }
68 else if(mystatus == SURV_STATUS_PREY)
69 {
70 player_text = _("Survivor");
71 player_color = '0 1 0';
72 //player_icon = "player_neutral";
73 }
74
75 drawstring_aspect(pos, player_text, vec2(mySize.x, mySize.y), player_color, panel_fg_alpha, DRAWFLAG_NORMAL);
76}
77
78REGISTER_MUTATOR(cl_surv, true);
79
80MUTATOR_HOOKFUNCTION(cl_surv, ForcePlayercolors_Skip, CBC_ORDER_LAST)
81{
82 if(!ISGAMETYPE(SURVIVAL))
83 return false;
84
85 entity player = M_ARGV(0, entity);
86 entity e = playerslots[player.entnum - 1];
87 if (e && e.colormap)
88 player.colormap = e.colormap;
89 else
90 player.colormap = 1024 + SURV_COLOR_PREY;
91 return true;
92}
93
94MUTATOR_HOOKFUNCTION(cl_surv, DrawScoreboard)
95{
96 if(!ISGAMETYPE(SURVIVAL))
97 return false;
98
99 // initialize colors of new players
100 for(entity pl = players.sort_next; pl; pl = pl.sort_next)
101 if(pl.gotscores && pl.colormap == 0)
102 pl.colormap = 1024 + SURV_COLOR_PREY;
103 return false;
104}
105
106MUTATOR_HOOKFUNCTION(cl_surv, DrawScoreboard_Force)
107{
108 // show the scoreboard when the round ends, so players can see who the hunter was
109 return STAT(GAME_STOPPED);
110}
#define REGISTER_MUTATOR(...)
Definition base.qh:295
const int CBC_ORDER_LAST
Definition base.qh:11
#define MUTATOR_HOOKFUNCTION(...)
Definition base.qh:335
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void HUD_Mod_Survival(vector pos, vector mySize, bool should_draw)
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition draw.qc:109
entity playerslots[255]
Definition main.qh:84
entity players
Definition main.qh:57
#define ISGAMETYPE(NAME)
Definition main.qh:46
#define M_ARGV(x, type)
Definition events.qh:17
const float DRAWFLAG_NORMAL
float maxclients
float player_localnum
float time
#define entcs_IsSpectating(i)
Definition ent_cs.qh:76
float panel_fg_alpha
Definition hud.qh:169
#define NET_HANDLE(id, param)
Definition net.qh:15
int ReadByte()
#define STAT(...)
Definition stats.qh:82
bool mod_active
Definition modicons.qh:7
#define make_pure(e)
direct use is
Definition oo.qh:13
vector
Definition self.qh:92
const int SURV_COLOR_HUNTER
Definition survival.qh:42
const int SURV_STATUS_HUNTER
Definition survival.qh:38
const int SURV_COLOR_PREY
Definition survival.qh:41
const int SURV_STATUS_PREY
Definition survival.qh:37
#define vec2(...)
Definition vector.qh:90