diff --git a/source/src/command.cpp b/source/src/command.cpp index 735b69e5..a4e0b21c 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -822,8 +822,9 @@ void writecfg() if(!f) return; fprintf(f, "// automatically written on exit, DO NOT MODIFY\n// delete this file to have defaults.cfg overwrite these settings\n// modify settings in game, or put settings in autoexec.cfg to override anything\n\n"); fprintf(f, "name %s\nskin %d\n", player1->name, player1->nextskin); - extern Texture *crosshair; - fprintf(f, "loadcrosshair %s\n", crosshair->name+strlen("packages/misc/crosshairs/")); + extern Texture *defaultcrosshair, *crosshairs[NUMGUNS]; + fprintf(f, "loadcrosshair -1 %s\n", defaultcrosshair->name+strlen("packages/misc/crosshairs/")); + loopi(NUMGUNS) if(crosshairs[i]) fprintf(f, "loadcrosshair %d %s\n", i, crosshairs[i]->name+strlen("packages/misc/crosshairs/")); extern int lowfps, highfps; fprintf(f, "fpsrange %d %d\n", lowfps, highfps); fprintf(f, "\n"); diff --git a/source/src/protos.h b/source/src/protos.h index cedf1732..f9c28d23 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -227,7 +227,7 @@ extern void gl_drawframe(int w, int h, float changelod, float curfps); extern void clearminimap(); extern void rendercursor(int x, int y, int w); extern void renderaboveheadicon(playerent *p); -extern void drawcrosshair(playerent *p, bool showteamwarning); +extern void drawcrosshair(playerent *p, bool showteamwarning, int weaponspecific = -1, struct color *c = NULL, float size = -1.0f); extern void drawscope(); extern float dynfov(); diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index 5372b070..7e3dc3e1 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -123,27 +123,41 @@ void drawscope() glEnd(); } -Texture *crosshair = NULL; +Texture *defaultcrosshair = NULL; +Texture *crosshairs[NUMGUNS] = { NULL }; // weapon specific crosshairs -void loadcrosshair(char *c) +Texture *loadcrosshairtexture(const char *c) { s_sprintfd(p)("packages/misc/crosshairs/%s", c); - crosshair = textureload(p, 3); + Texture *crosshair = textureload(p, 3); if(crosshair==notexture) crosshair = textureload("packages/misc/crosshairs/default.png", 3); + return crosshair; } -COMMAND(loadcrosshair, ARG_1STR); +void loadcrosshair(char *w, char *c) +{ + int weapon = atoi(w); + if(weapon>NUMGUNS) return; + if(weapon<0) defaultcrosshair = loadcrosshairtexture(c); + else crosshairs[weapon] = loadcrosshairtexture(c); +} -void drawcrosshair(playerent *p, bool showteamwarning) +COMMAND(loadcrosshair, ARG_2STR); + +void drawcrosshair(playerent *p, bool showteamwarning, int weaponspecific, color *c, float size) { static Texture *teammatetex = NULL; if(!teammatetex) teammatetex = textureload("packages/misc/teammate.png", 3); - if(!crosshair) crosshair = textureload("packages/misc/crosshairs/default.png", 3); + + if(!defaultcrosshair) defaultcrosshair = loadcrosshairtexture("default.png"); + Texture *crosshair = weaponspecific>=0 && crosshairs[weaponspecific] ? crosshairs[weaponspecific] : defaultcrosshair; + if(crosshair->bpp==32) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); else glBlendFunc(GL_ONE, GL_ONE); glBindTexture(GL_TEXTURE_2D, showteamwarning ? teammatetex->id : crosshair->id); glColor3ub(255,255,255); - if(crosshairfx) + if(c) glColor3f(c->r, c->g, c->b); + else if(crosshairfx) { if(showteamwarning) glColor3ub(255, 0, 0); else if(!m_osok) @@ -152,7 +166,8 @@ void drawcrosshair(playerent *p, bool showteamwarning) else if(p->health<=50) glColor3ub(255,128,0); } } - float chsize = (float)crosshairsize * (p->weaponsel->type==GUN_ASSAULT && p->weaponsel->shots > 3 ? 1.4f : 1.0f) * (showteamwarning ? 2.0f : 1.0f); + float s = size>0 ? size : (float)crosshairsize; + float chsize = s * (p->weaponsel->type==GUN_ASSAULT && p->weaponsel->shots > 3 ? 1.4f : 1.0f) * (showteamwarning ? 2.0f : 1.0f); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(VIRTW/2 - chsize, VIRTH/2 - chsize); glTexCoord2f(1, 0); glVertex2f(VIRTW/2 + chsize, VIRTH/2 - chsize); diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index d7b222a6..5bd3a469 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -645,7 +645,7 @@ void weapon::onselecting() } void weapon::renderhudmodel() { renderhudmodel(owner->lastaction); } -void weapon::renderaimhelp(bool teamwarning) { drawcrosshair(owner, teamwarning); } +void weapon::renderaimhelp(bool teamwarning) { drawcrosshair(owner, teamwarning, type); } int weapon::dynspread() { return info.spread; } float weapon::dynrecoil() { return info.recoil; } bool weapon::selectable() { return this != owner->weaponsel && owner->state == CS_ALIVE && !owner->weaponchanging; } @@ -1029,7 +1029,16 @@ void sniperrifle::onselecting() { weapon::onselecting(); scoped = false; } void sniperrifle::ondeselecting() { scoped = false; } void sniperrifle::onownerdies() { scoped = false; } void sniperrifle::renderhudmodel() { if(!scoped) weapon::renderhudmodel(); } -void sniperrifle::renderaimhelp(bool teamwarning) { if(scoped) drawscope(); if(teamwarning) drawcrosshair(owner, teamwarning); } + +void sniperrifle::renderaimhelp(bool teamwarning) +{ + if(scoped) + { + drawscope(); + color c(1.0f, 0.0f, 0.0f); + drawcrosshair(owner, teamwarning, type, &c, 30.0f); + } +} void sniperrifle::setscope(bool enable) { if(this == owner->weaponsel && !reloading && owner->state == CS_ALIVE) scoped = enable; }