Add can_shoot and draw_tracer to util.c

This commit is contained in:
8dcc 2023-07-31 15:36:09 +02:00
parent 7cf0b30495
commit 3d3ebd7c5a
2 changed files with 19 additions and 0 deletions

View File

@ -34,6 +34,7 @@ cl_entity_t* get_player(int ent_idx);
bool is_alive(cl_entity_t* ent);
bool valid_player(cl_entity_t* ent);
bool is_friend(cl_entity_t* ent);
bool can_shoot(void);
char* get_name(int ent_idx);
game_id get_cur_game(void);
vec3_t vec3(float x, float y, float z);
@ -48,6 +49,7 @@ vec3_t vec_to_ang(vec3_t v);
vec3_t matrix_3x4_origin(matrix_3x4 m);
bool world_to_screen(vec3_t vec, vec2_t screen);
void engine_draw_text(int x, int y, char* s, rgb_t c);
void draw_tracer(vec3_t start, vec3_t end, rgb_t c, float a, float w, float t);
void gl_drawbox(int x, int y, int w, int h, rgb_t c);
void gl_drawline(int x0, int y0, int x1, int y1, float w, rgb_t col);
bool protect_addr(void* ptr, int new_flags);

View File

@ -63,6 +63,10 @@ bool is_friend(cl_entity_t* ent) {
}
}
bool can_shoot(void) {
return g_flNextAttack <= 0.0f && g_flNextPrimaryAttack <= 0.0f;
}
char* get_name(int ent_idx) {
hud_player_info_t info;
i_engine->pfnGetPlayerInfo(ent_idx, &info);
@ -204,6 +208,19 @@ void engine_draw_text(int x, int y, char* s, rgb_t c) {
i_engine->pfnDrawConsoleString(x, y, s);
}
void draw_tracer(vec3_t start, vec3_t end, rgb_t c, float a, float w,
float time) {
static const char* MDL_STR = "sprites/laserbeam.spr";
static int beam_idx = i_engine->pEventAPI->EV_FindModelIndex(MDL_STR);
float r = c.r / 255.f;
float g = c.g / 255.f;
float b = c.b / 255.f;
i_engine->pEfxAPI->R_BeamPoints(start, end, beam_idx, time, w, 0, a, 0, 0,
0, r, g, b);
}
void gl_drawbox(int x, int y, int w, int h, rgb_t c) {
/* Line width */
const int lw = 1;