From 3d3ebd7c5a8ed83ded8a98ef670dfe103543c438 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Mon, 31 Jul 2023 15:36:09 +0200 Subject: [PATCH] Add can_shoot and draw_tracer to util.c --- src/include/util.h | 2 ++ src/util.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/include/util.h b/src/include/util.h index bc73e1c..b4ceebd 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -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); diff --git a/src/util.c b/src/util.c index 05dfdbc..752c821 100644 --- a/src/util.c +++ b/src/util.c @@ -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;