From 3dc3a443ae2272c2fd7fab60ca40c076b14d5c88 Mon Sep 17 00:00:00 2001 From: eihrul Date: Thu, 1 Feb 2024 19:36:28 +0100 Subject: [PATCH] svn r6856 Co-authored-by: Nieb --- patches/chat_highlight_words.patch | 2 +- patches/colors.patch | 2 +- patches/serverlogging.patch | 4 +- patches/zenmode.patch | 4 +- src/engine/octaedit.cpp | 4 +- src/engine/rendermodel.cpp | 4 +- src/engine/world.cpp | 74 +++++++++++++++--------------- src/fpsgame/client.cpp | 10 ++-- src/fpsgame/fps.cpp | 12 +++-- src/fpsgame/server.cpp | 17 +++++-- src/shared/tools.cpp | 17 +++++++ src/shared/tools.h | 2 + 12 files changed, 94 insertions(+), 58 deletions(-) diff --git a/patches/chat_highlight_words.patch b/patches/chat_highlight_words.patch index 68f7fc3..69c16ec 100644 --- a/patches/chat_highlight_words.patch +++ b/patches/chat_highlight_words.patch @@ -53,7 +53,7 @@ Index: src/fpsgame/client.cpp @@ -1343,6 +1348,7 @@ if(t->state!=CS_DEAD && t->state!=CS_SPECTATOR) particle_textcopy(t->abovehead(), text, PART_TEXT, 2000, 0x6496FF, 4.0f, -8); - conoutf(CON_TEAMCHAT, "\fs\f8[team]\fr %s: \f8%s", chatcolorname(t), text); + conoutf(CON_TEAMCHAT, "\fs\f8[%s]\fr %s: \f8%s", t->state==CS_SPECTATOR ? "spec" : "team", chatcolorname(t), text); + if(!hasfocus) loopv(chathighlightwords) if(strstr(text, chathighlightwords[i])) { playsoundname(chathighlightsound); break; } break; } diff --git a/patches/colors.patch b/patches/colors.patch index 0d0a9de..b10e108 100644 --- a/patches/colors.patch +++ b/patches/colors.patch @@ -199,7 +199,7 @@ Index: src/fpsgame/client.cpp if(t->state!=CS_DEAD && t->state!=CS_SPECTATOR) - particle_textcopy(t->abovehead(), text, PART_TEXT, 2000, 0x6496FF, 4.0f, -8); + particle_textcopy(t->abovehead(), text, PART_TEXT, 2000, COL_BLUE, 4.0f, -8); - conoutf(CON_TEAMCHAT, "\fs\f8[team]\fr %s: \f8%s", chatcolorname(t), text); + conoutf(CON_TEAMCHAT, "\fs\f8[%s]\fr %s: \f8%s", t->state==CS_SPECTATOR ? "spec" : "team", chatcolorname(t), text); break; } Index: src/fpsgame/collect.h diff --git a/patches/serverlogging.patch b/patches/serverlogging.patch index a91669b..a572a92 100644 --- a/patches/serverlogging.patch +++ b/patches/serverlogging.patch @@ -150,8 +150,8 @@ Index: src/fpsgame/server.cpp if(t==cq || t->state.state==CS_SPECTATOR || t->state.aitype != AI_NONE || strcmp(cq->team, t->team)) continue; sendf(t->clientnum, 1, "riis", N_SAYTEAM, cq->clientnum, text); } -- if(isdedicatedserver() && cq) logoutf("%s <%s>: %s", colorname(cq), cq->team, text); -+ if(isdedicatedserver() && cq) logoutf("%s (cn %d) <%s>: %s", colorname(cq), cq->clientnum, cq->team, text); +- if(isdedicatedserver() && cq) logoutf("%s <%s>: %s", colorname(cq), ci->state.state==CS_SPECTATOR ? "spec" : cq->team, text); ++ if(isdedicatedserver() && cq) logoutf("%s (cn %d) <%s>: %s", colorname(cq), cq->clientnum, ci->state.state==CS_SPECTATOR ? "spec" : cq->team, text); break; } diff --git a/patches/zenmode.patch b/patches/zenmode.patch index bbb71e3..d485e8f 100644 --- a/patches/zenmode.patch +++ b/patches/zenmode.patch @@ -86,8 +86,8 @@ Index: src/fpsgame/client.cpp @@ -1342,3 +1355,3 @@ if(t->state!=CS_DEAD && t->state!=CS_SPECTATOR) particle_textcopy(t->abovehead(), text, PART_TEXT, 2000, COL_BLUE, 4.0f, -8); -- conoutf(CON_TEAMCHAT, "\fs\f8[team]\fr %s: \f8%s", chatcolorname(t), text); -+ conoutf(CON_TEAMCHAT + (t->state==CS_SPECTATOR ? CON_NONZEN : 0), "\fs\f8[team]\fr %s: \f8%s", chatcolorname(t), text); +- conoutf(CON_TEAMCHAT, "\fs\f8[%s]\fr %s: \f8%s", t->state==CS_SPECTATOR ? "spec" : "team", chatcolorname(t), text); ++ conoutf(CON_TEAMCHAT + (t->state==CS_SPECTATOR ? CON_NONZEN : 0), "\fs\f8[%s]\fr %s: \f8%s", t->state==CS_SPECTATOR ? "spec" : "team", chatcolorname(t), text); @@ -1400,11 +1413,11 @@ if(d->name[0]) // already connected { diff --git a/src/engine/octaedit.cpp b/src/engine/octaedit.cpp index 12fbea2..bc1ec16 100644 --- a/src/engine/octaedit.cpp +++ b/src/engine/octaedit.cpp @@ -178,7 +178,7 @@ void toggleedit(bool force) cancelsel(); stoppaintblendmap(); keyrepeat(editmode); - editing = entediting = editmode; + editing = editmode; extern int fullbright; if(fullbright) { initlights(); lightents(); } if(!force) game::edittoggled(editmode); @@ -298,6 +298,8 @@ cube &blockcube(int x, int y, int z, const block3 &b, int rgrid) // looks up a w int selchildcount = 0, selchildmat = -1; ICOMMAND(havesel, "", (), intret(havesel ? selchildcount : 0)); +ICOMMAND(selchildcount, "", (), { if(selchildcount < 0) result(tempformatstring("1/%d", -selchildcount)); else intret(selchildcount); }); +ICOMMAND(selchildmat, "s", (char *prefix), { if(selchildmat > 0) result(getmaterialdesc(selchildmat, prefix)); }); void countselchild(cube *c, const ivec &cor, int size) { diff --git a/src/engine/rendermodel.cpp b/src/engine/rendermodel.cpp index dc05e69..66ca0c9 100644 --- a/src/engine/rendermodel.cpp +++ b/src/engine/rendermodel.cpp @@ -517,9 +517,9 @@ void renderellipse(vec &o, float xradius, float yradius, float yaw) gle::colorf(0.5f, 0.5f, 0.5f); gle::defvertex(); gle::begin(GL_LINE_LOOP); - loopi(15) + loopi(16) { - const vec2 &sc = sincos360[i*(360/15)]; + const vec2 &sc = sincos360[(i*360+8)/16]; gle::attrib(vec(xradius*sc.x, yradius*sc.y, 0).rotate_around_z((yaw+90)*RAD).add(o)); } xtraverts += gle::end(); diff --git a/src/engine/world.cpp b/src/engine/world.cpp index 8b30f2f..2ca088b 100644 --- a/src/engine/world.cpp +++ b/src/engine/world.cpp @@ -127,7 +127,7 @@ void modifyoctaentity(int flags, int id, extentity &e, cube *c, const ivec &cor, oe.other.removeobj(id); break; } - if(oe.mapmodels.empty() && oe.other.empty()) + if(oe.mapmodels.empty() && oe.other.empty()) freeoctaentities(c[i]); } if(c[i].ext && c[i].ext->ents) c[i].ext->ents->query = NULL; @@ -152,7 +152,7 @@ static bool modifyoctaent(int flags, int id, extentity &e) ivec o, r; if(!getentboundingbox(e, o, r)) return false; - if(!insideworld(e.o)) + if(!insideworld(e.o)) { int idx = outsideents.find(id); if(flags&MODOE_ADD) @@ -224,7 +224,7 @@ static inline void findents(cube *c, const ivec &o, int size, const ivec &bo, co loopoctabox(o, size, bo, br) { if(c[i].ext && c[i].ext->ents) findents(*c[i].ext->ents, low, high, notspawned, pos, invradius, found); - if(c[i].children && size > octaentsize) + if(c[i].children && size > octaentsize) { ivec co(i, o, size); findents(c[i].children, co, size>>1, bo, br, low, high, notspawned, pos, invradius, found); @@ -275,7 +275,7 @@ int entlooplevel = 0; int efocus = -1, enthover = -1, entorient = -1, oldhover = -1; bool undonext = true; -VARF(entediting, 0, 0, 1, { if(!entediting) { entcancel(); efocus = enthover = -1; } }); +VARF(entediting, 0, 1, 1, { if(!entediting) { entcancel(); efocus = enthover = -1; } }); bool noentedit() { @@ -368,8 +368,8 @@ void attachentity(extentity &e) if(a->attached) continue; switch(e.type) { - case ET_SPOTLIGHT: - if(a->type!=ET_LIGHT) continue; + case ET_SPOTLIGHT: + if(a->type!=ET_LIGHT) continue; break; default: @@ -479,30 +479,30 @@ void entrotate(int *cw) ); } -void entselectionbox(const entity &e, vec &eo, vec &es) +void entselectionbox(const entity &e, vec &eo, vec &es) { model *m = NULL; const char *mname = entities::entmodel(e); if(mname && (m = loadmodel(mname))) - { + { m->collisionbox(eo, es); if(es.x > es.y) es.y = es.x; else es.x = es.y; // square es.z = (es.z + eo.z + 1 + entselradius)/2; // enclose ent radius box and model box eo.x += e.o.x; eo.y += e.o.y; eo.z = e.o.z - entselradius + es.z; - } + } else if(e.type == ET_MAPMODEL && (m = loadmapmodel(e.attr2))) { mmcollisionbox(e, m, eo, es); es.max(entselradius); eo.add(e.o); - } + } else { es = vec(entselradius); eo = e.o; - } + } eo.sub(es); es.mul(2); } @@ -527,19 +527,19 @@ void entdrag(const vec &ray) int d = dimension(entorient), dc= dimcoord(entorient); - entfocus(entgroup.last(), + entfocus(entgroup.last(), entselectionbox(e, eo, es); if(!editmoveplane(e.o, ray, d, eo[d] + (dc ? es[d] : 0), handle, v, entmoving==1)) - return; + return; ivec g(v); int z = g[d]&(~(sel.grid-1)); g.add(sel.grid/2).mask(~(sel.grid-1)); g[d] = z; - + r = (entselsnap ? g[R[d]] : v[R[d]]) - e.o[R[d]]; - c = (entselsnap ? g[C[d]] : v[C[d]]) - e.o[C[d]]; + c = (entselsnap ? g[C[d]] : v[C[d]]) - e.o[C[d]]; ); if(entmoving==1) makeundoent(); @@ -554,10 +554,10 @@ void renderentring(const extentity &e, float radius, int axis) if(radius <= 0) return; gle::defvertex(); gle::begin(GL_LINE_LOOP); - loopi(15) + loopi(16) { vec p(e.o); - const vec2 &sc = sincos360[i*(360/15)]; + const vec2 &sc = sincos360[(i*360+8)/16]; p[axis>=2 ? 1 : 0] += radius*sc.x; p[axis>=1 ? 2 : 1] += radius*sc.y; gle::attrib(p); @@ -644,7 +644,7 @@ void renderentradius(extentity &e, bool color) vec dir = vec(e.o).sub(e.attached->o).normalize(); float angle = clamp(int(e.attr1), 1, 89); renderentattachment(e); - renderentcone(*e.attached, dir, radius, angle); + renderentcone(*e.attached, dir, radius, angle); } break; @@ -673,7 +673,7 @@ void renderentradius(extentity &e, bool color) } default: - if(e.type>=ET_GAMESPECIFIC) + if(e.type>=ET_GAMESPECIFIC) { if(color) gle::colorf(0, 1, 1); entities::entradius(e, color); @@ -706,7 +706,7 @@ static void renderentbox(const vec &eo, vec es) } void renderentselection(const vec &o, const vec &ray, bool entmoving) -{ +{ if(noentedit()) return; vec eo, es; @@ -731,8 +731,8 @@ void renderentselection(const vec &o, const vec &ray, bool entmoving) { vec a, b; gle::colorub(20, 20, 20); - (a = eo).x = eo.x - fmod(eo.x, worldsize); (b = es).x = a.x + worldsize; boxs3D(a, b, 1); - (a = eo).y = eo.y - fmod(eo.y, worldsize); (b = es).y = a.x + worldsize; boxs3D(a, b, 1); + (a = eo).x = eo.x - fmod(eo.x, worldsize); (b = es).x = a.x + worldsize; boxs3D(a, b, 1); + (a = eo).y = eo.y - fmod(eo.y, worldsize); (b = es).y = a.x + worldsize; boxs3D(a, b, 1); (a = eo).z = eo.z - fmod(eo.z, worldsize); (b = es).z = a.x + worldsize; boxs3D(a, b, 1); } gle::colorub(150,0,0); @@ -810,11 +810,11 @@ void entpush(int *dir) if(noentedit()) return; int d = dimension(entorient); int s = dimcoord(entorient) ? -*dir : *dir; - if(entmoving) + if(entmoving) { groupeditpure(e.o[d] += float(s*sel.grid)); // editdrag supplies the undo } - else + else groupedit(e.o[d] += float(s*sel.grid)); if(entitysurf==1) { @@ -824,7 +824,7 @@ void entpush(int *dir) } VAR(entautoviewdist, 0, 25, 100); -void entautoview(int *dir) +void entautoview(int *dir) { if(!haveselent()) return; static int s = 0; @@ -996,7 +996,7 @@ void entcopy() if(noentedit()) return; entcopygrid = sel.grid; entcopybuf.shrink(0); - loopv(entgroup) + loopv(entgroup) entfocus(entgroup[i], entcopybuf.add(e).o.sub(vec(sel.o))); } @@ -1046,9 +1046,9 @@ void printent(extentity &e, char *buf, int len) switch(e.type) { case ET_PARTICLES: - if(printparticles(e, buf, len)) return; + if(printparticles(e, buf, len)) return; break; - + default: if(e.type >= ET_GAMESPECIFIC && entities::printent(e, buf, len)) return; break; @@ -1089,9 +1089,9 @@ void enttype(char *type, int *numargs) { if(*numargs >= 1) { - int typeidx = findtype(type); + int typeidx = findtype(type); if(typeidx != ET_EMPTY) groupedit(e.type = typeidx); - } + } else entfocus(efocus, { result(entities::entname(e.type)); @@ -1112,7 +1112,7 @@ void entattr(int *attr, int *val, int *numargs) case 3: e.attr4 = *val; break; case 4: e.attr5 = *val; break; } - ); + ); } else entfocus(efocus, { @@ -1134,7 +1134,7 @@ int findentity(int type, int index, int attr1, int attr2) { const vector &ents = entities::getents(); if(index > ents.length()) index = ents.length(); - else for(int i = index; i16 ? 16 : scale), true, false); setvar("mapsize", 1< &ents = entities::getents(); loopv(ents) ents[i]->o.sub(vec(offset)); shrinkblendmap(octant); - + allchanged(); conoutf("shrunk map to size %d", worldscale); diff --git a/src/fpsgame/client.cpp b/src/fpsgame/client.cpp index c5cecd0..da864c9 100644 --- a/src/fpsgame/client.cpp +++ b/src/fpsgame/client.cpp @@ -352,10 +352,10 @@ namespace game bool isspectator(int cn) { - fpsent *d = getclient(cn); + fpsent *d = cn<0 ? player1 : getclient(cn); return d && d->state==CS_SPECTATOR; } - ICOMMAND(isspectator, "i", (int *cn), intret(isspectator(*cn) ? 1 : 0)); + ICOMMAND(isspectator, "b", (int *cn), intret(isspectator(*cn) ? 1 : 0)); bool isai(int cn, int type) { @@ -1004,12 +1004,12 @@ namespace game } VARP(teamcolorchat, 0, 1, 1); - const char *chatcolorname(fpsent *d) { return teamcolorchat ? teamcolorname(d, NULL) : colorname(d); } + const char *chatcolorname(fpsent *d) { return teamcolorchat && (d!=player1 || d->state!=CS_SPECTATOR) ? teamcolorname(d, NULL) : colorname(d); } void toserver(char *text) { conoutf(CON_CHAT, "%s:\f0 %s", chatcolorname(player1), text); addmsg(N_TEXT, "rcs", player1, text); if(demorecord) recordmsg(N_TEXT, "rcs", player1, text); } COMMANDN(say, toserver, "C"); - void sayteam(char *text) { conoutf(CON_TEAMCHAT, "\fs\f8[team]\fr %s: \f8%s", chatcolorname(player1), text); addmsg(N_SAYTEAM, "rcs", player1, text); } + void sayteam(char *text) { conoutf(CON_TEAMCHAT, "\fs\f8[%s]\fr %s: \f8%s", player1->state==CS_SPECTATOR ? "spec" : "team", chatcolorname(player1), text); addmsg(N_SAYTEAM, "rcs", player1, text); } COMMAND(sayteam, "C"); ICOMMAND(servcmd, "C", (char *cmd), addmsg(N_SERVCMD, "rs", cmd)); @@ -1447,7 +1447,7 @@ namespace game if(!t || isignored(t->clientnum)) break; if(t->state!=CS_DEAD && t->state!=CS_SPECTATOR) particle_textcopy(t->abovehead(), text, PART_TEXT, 2000, COL_BLUE, 4.0f, -8); - conoutf(CON_TEAMCHAT + (t->state==CS_SPECTATOR ? CON_NONZEN : 0), "\fs\f8[team]\fr %s: \f8%s", chatcolorname(t), text); + conoutf(CON_TEAMCHAT + (t->state==CS_SPECTATOR ? CON_NONZEN : 0), "\fs\f8[%s]\fr %s: \f8%s", t->state==CS_SPECTATOR ? "spec" : "team", chatcolorname(t), text); if(!hasfocus) loopv(chathighlightwords) if(strstr(text, chathighlightwords[i])) { playsoundname(chathighlightsound); break; } break; } diff --git a/src/fpsgame/fps.cpp b/src/fpsgame/fps.cpp index e170bc9..c208e27 100644 --- a/src/fpsgame/fps.cpp +++ b/src/fpsgame/fps.cpp @@ -1090,9 +1090,13 @@ namespace game pophudmatrix(); } - static inline bool ammobargunvisible(const fpsent *d, int gun) + static inline bool ammobargunvisible(const fpsent *d, int gun, bool hideempty) { - return d->ammo[gun] > 0 || d->gunselect == gun; + if(d->ammo[gun] > 0 || d->gunselect == gun) return true; + if(hideempty) return false; + if(m_efficiency) return gun!=GUN_PISTOL; + if(m_insta) return gun==GUN_RIFLE; + return true; } void drawammobar(int w, int h, fpsent *p) @@ -1101,7 +1105,7 @@ namespace game int NUMPLAYERGUNS = GUN_PISTOL - GUN_SG + 1; int numvisibleguns = NUMPLAYERGUNS; - if(ammobarhideempty) loopi(NUMPLAYERGUNS) if(!ammobargunvisible(p, GUN_SG + i)) numvisibleguns--; + loopi(NUMPLAYERGUNS) if(!ammobargunvisible(p, GUN_SG + i, ammobarhideempty!=0)) numvisibleguns--; vec2 origin = vec2(ammobarx, ammobary).mul(vec2(w, h).div(ammobarscale)); vec2 offsetdir = ammobarhorizontal ? vec2(1, 0) : vec2(0, 1); @@ -1113,7 +1117,7 @@ namespace game flushhudmatrix(); int numskippedguns = 0; - loopi(NUMPLAYERGUNS) if(ammobargunvisible(p, GUN_SG + i) || !ammobarhideempty) + loopi(NUMPLAYERGUNS) if(ammobargunvisible(p, GUN_SG + i, ammobarhideempty!=0)) { float offset = initialoffset + (i - numskippedguns) * stepsize; vec2 drawpos = vec2(offsetdir).mul(offset).add(origin); diff --git a/src/fpsgame/server.cpp b/src/fpsgame/server.cpp index aeb1ee3..2b28674 100644 --- a/src/fpsgame/server.cpp +++ b/src/fpsgame/server.cpp @@ -312,6 +312,7 @@ namespace server } }); SVAR(servermotd, ""); + VAR(specchat, 0, 0, 1); struct teamkillkick { @@ -3116,15 +3117,25 @@ namespace server case N_SAYTEAM: { getstring(text, p); - if(!ci || !cq || (ci->state.state==CS_SPECTATOR && !ci->local && !ci->privilege) || !m_teammode || !cq->team[0]) break; + if(!ci || !cq) break; + if(ci->state.state==CS_SPECTATOR) + { + if(!specchat && !ci->local && !ci->privilege) break; + } + else if (!m_teammode || !cq->team[0]) break; filtertext(text, text, true, true); loopv(clients) { clientinfo *t = clients[i]; - if(t==cq || t->state.state==CS_SPECTATOR || t->state.aitype != AI_NONE || strcmp(cq->team, t->team)) continue; + if(t==cq || t->state.aitype != AI_NONE) continue; + if(t->state.state==CS_SPECTATOR) + { + if(ci->state.state!=CS_SPECTATOR) continue; + } + else if(ci->state.state==CS_SPECTATOR || strcmp(cq->team, t->team)) continue; sendf(t->clientnum, 1, "riis", N_SAYTEAM, cq->clientnum, text); } - if(isdedicatedserver() && cq) logoutf("%s (cn %d) <%s>: %s", colorname(cq), cq->clientnum, cq->team, text); + if(isdedicatedserver() && cq) logoutf("%s (cn %d) <%s>: %s", colorname(cq), cq->clientnum, ci->state.state==CS_SPECTATOR ? "spec" : cq->team, text); break; } diff --git a/src/shared/tools.cpp b/src/shared/tools.cpp index ca82e8f..092d7c4 100644 --- a/src/shared/tools.cpp +++ b/src/shared/tools.cpp @@ -34,6 +34,23 @@ void *operator new[](size_t size, bool err) return p; } +////////////////////////// strings //////////////////////////////////////// + +static string tmpstr[4]; +static int tmpidx = 0; + +char *tempformatstring(const char *fmt, ...) +{ + tmpidx = (tmpidx+1)%4; + + va_list v; + va_start(v, fmt); + vformatstring(tmpstr[tmpidx], fmt, v); + va_end(v); + + return tmpstr[tmpidx]; +} + ////////////////////////// rnd numbers //////////////////////////////////////// #define N (624) diff --git a/src/shared/tools.h b/src/shared/tools.h index b2a34bf..a5064a4 100644 --- a/src/shared/tools.h +++ b/src/shared/tools.h @@ -211,6 +211,8 @@ template inline void concformatstring(char (&d)[N], const char *fmt, . va_end(v); } +extern char *tempformatstring(const char *fmt, ...) PRINTFARGS(1, 2); + #define defformatstring(d,...) string d; formatstring(d, __VA_ARGS__) #define defvformatstring(d,last,fmt) string d; { va_list ap; va_start(ap, last); vformatstring(d, fmt, ap); va_end(ap); }