Skip to content

Commit

Permalink
add frag message limit and X position
Browse files Browse the repository at this point in the history
  • Loading branch information
sauerbraten committed Dec 3, 2020
1 parent a9d6829 commit 9b107d1
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ undo-patches:
$(PATCH) --reverse < patches/macos_builds.patch
$(PATCH) --reverse < patches/scoreboard.patch
$(PATCH) --reverse < patches/moviehud.patch
$(PATCH) < patches/hudfragmessages.patch
$(PATCH) --reverse < patches/hudfragmessages.patch
unix2dos src/vcpp/sauerbraten.vcxproj

clean-sauer: check-env
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ a.k.a. Features
- adds the following variables:
- `hudfragmessages`: when 0, no frag messages are shown
- `hudfragmessageduration`: how long each message will be shown, in milliseconds, between 100 (= 0.1s) and 10,000 (= 10s)
- `maxhudfragmessages`: how many messages to show at most (between 1 and 10)
- `hudfragmessagex`: horizontal position (between 0 and 1) where messages will appear
- `hudfragmessagey`: vertical position (between 0 and 1) where the newest message will appear
when hudfragmessagey<=0.5 (new messages appearing in the upper half of the screen), older messages will be stacked above newer ones, otherwise (new messages appear in the lower half), older messages are shown below newer ones
- `hudfragmessagescale`: size of the messages, between 0.0 and 1.0
Expand Down
29 changes: 19 additions & 10 deletions patches/hudfragmessages.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Index: src/Makefile
===================================================================
--- src/Makefile (revision 6469)
--- src/Makefile (revision 6471)
+++ src/Makefile (working copy)
@@ -125,6 +125,7 @@
fpsgame/client.o \
Expand All @@ -22,14 +22,14 @@ Index: src/Makefile
shared/crypto-standalone.o: shared/ents.h shared/command.h shared/iengine.h
Index: src/fpsgame/fps.cpp
===================================================================
--- src/fpsgame/fps.cpp (revision 6469)
--- src/fpsgame/fps.cpp (revision 6471)
+++ src/fpsgame/fps.cpp (working copy)
@@ -495,6 +495,8 @@
{
if(d==player1) conoutf(contype, "\f2%s got fragged by %s", dname, aname);
else conoutf(contype, "\f2%s fragged %s", aname, dname);
+ actor->fragmessages->add(fragmessage(aname, dname, d->lasthitpushgun));
+ d->fragmessages->add(fragmessage(aname, dname, d->lasthitpushgun));
+ addfragmessage(actor, aname, dname, d->lasthitpushgun);
+ addfragmessage(d, aname, dname, d->lasthitpushgun);
}
deathstate(d);
ai::killed(d, actor);
Expand Down Expand Up @@ -70,23 +70,31 @@ Index: src/fpsgame/fragmessages.cpp
===================================================================
--- src/fpsgame/fragmessages.cpp (nonexistent)
+++ src/fpsgame/fragmessages.cpp (working copy)
@@ -0,0 +1,54 @@
@@ -0,0 +1,62 @@
+#include "game.h"
+#include "fragmessage_type.h"
+
+namespace game {
+ VARP(hudfragmessages, 0, 1, 1);
+ VARP(hudfragmessageduration, 0, 1000, 10000);
+ VARP(maxhudfragmessages, 1, 3, 10);
+ FVARP(hudfragmessagex, 0, 0.5f, 1.0f);
+ FVARP(hudfragmessagey, 0, 0.25f, 1.0f);
+ FVARP(hudfragmessagescale, 0.1f, 0.5f, 1.0f);
+
+ void addfragmessage(fpsent *c, const char *aname, const char *vname, int gun)
+ {
+ if(c->fragmessages->length()>=maxhudfragmessages) c->fragmessages->remove(0);
+ c->fragmessages->add(fragmessage(aname, vname, gun));
+ }
+
+ void drawfragmessages(fpsent *d, int w, int h)
+ {
+ if(d->fragmessages->empty()) return;
+
+ float stepsize = (3*HICON_SIZE)/2;
+ float stepdir = hudfragmessagey>0.5 ? 1 : -1;
+ vec2 origin = vec2(.5f, hudfragmessagey).mul(vec2(w, h).div(hudfragmessagescale));
+ vec2 origin = vec2(hudfragmessagex, hudfragmessagey).mul(vec2(w, h).div(hudfragmessagescale));
+
+ pushhudmatrix();
+ hudmatrix.scale(hudfragmessagescale, hudfragmessagescale, 1);
Expand Down Expand Up @@ -130,7 +138,7 @@ Index: src/fpsgame/fragmessages.h
===================================================================
--- src/fpsgame/fragmessages.h (nonexistent)
+++ src/fpsgame/fragmessages.h (working copy)
@@ -0,0 +1,12 @@
@@ -0,0 +1,13 @@
+#ifndef __FRAGMESSAGES_H__
+#define __FRAGMESSAGES_H__
+
Expand All @@ -139,14 +147,15 @@ Index: src/fpsgame/fragmessages.h
+namespace game {
+ extern vector<fragmessage> fragmessages;
+ extern int hudfragmessages;
+ extern void addfragmessage(fpsent *c, const char *aname, const char *vname, int gun);
+ extern void drawfragmessages(fpsent *d, int w, int h);
+}
+
+#endif
\ No newline at end of file
Index: src/fpsgame/game.h
===================================================================
--- src/fpsgame/game.h (revision 6469)
--- src/fpsgame/game.h (revision 6471)
+++ src/fpsgame/game.h (working copy)
@@ -535,6 +535,8 @@
}
Expand All @@ -162,7 +171,7 @@ Index: src/fpsgame/game.h
int lastpain;
int lastaction, lastattackgun;
+ int lasthitpushgun;
+ vector<fragmessage> *fragmessages;
+ vector<fragmessage> *fragmessages; // oldest first, newest at the end
bool attacking;
int attacksound, attackchan, idlesound, idlechan;
int lasttaunt;
Expand Down Expand Up @@ -201,7 +210,7 @@ Index: src/fpsgame/game.h
extern const char *modename(int n, const char *unknown = "unknown");
Index: src/vcpp/sauerbraten.vcxproj
===================================================================
--- src/vcpp/sauerbraten.vcxproj (revision 6470)
--- src/vcpp/sauerbraten.vcxproj (revision 6471)
+++ src/vcpp/sauerbraten.vcxproj (working copy)
@@ -1078,6 +1078,20 @@
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)game.pch</PrecompiledHeaderOutputFile>
Expand Down
4 changes: 2 additions & 2 deletions src/fpsgame/fps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ namespace game
{
if(d==player1) conoutf(contype, "\f2%s got fragged by %s", dname, aname);
else conoutf(contype, "\f2%s fragged %s", aname, dname);
actor->fragmessages->add(fragmessage(aname, dname, d->lasthitpushgun));
d->fragmessages->add(fragmessage(aname, dname, d->lasthitpushgun));
addfragmessage(actor, aname, dname, d->lasthitpushgun);
addfragmessage(d, aname, dname, d->lasthitpushgun);
}
deathstate(d);
ai::killed(d, actor);
Expand Down
10 changes: 9 additions & 1 deletion src/fpsgame/fragmessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
namespace game {
VARP(hudfragmessages, 0, 1, 1);
VARP(hudfragmessageduration, 0, 1000, 10000);
VARP(maxhudfragmessages, 1, 3, 10);
FVARP(hudfragmessagex, 0, 0.5f, 1.0f);
FVARP(hudfragmessagey, 0, 0.25f, 1.0f);
FVARP(hudfragmessagescale, 0.1f, 0.5f, 1.0f);

void addfragmessage(fpsent *c, const char *aname, const char *vname, int gun)
{
if(c->fragmessages->length()>=maxhudfragmessages) c->fragmessages->remove(0);
c->fragmessages->add(fragmessage(aname, vname, gun));
}

void drawfragmessages(fpsent *d, int w, int h)
{
if(d->fragmessages->empty()) return;

float stepsize = (3*HICON_SIZE)/2;
float stepdir = hudfragmessagey>0.5 ? 1 : -1;
vec2 origin = vec2(.5f, hudfragmessagey).mul(vec2(w, h).div(hudfragmessagescale));
vec2 origin = vec2(hudfragmessagex, hudfragmessagey).mul(vec2(w, h).div(hudfragmessagescale));

pushhudmatrix();
hudmatrix.scale(hudfragmessagescale, hudfragmessagescale, 1);
Expand Down
1 change: 1 addition & 0 deletions src/fpsgame/fragmessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace game {
extern vector<fragmessage> fragmessages;
extern int hudfragmessages;
extern void addfragmessage(fpsent *c, const char *aname, const char *vname, int gun);
extern void drawfragmessages(fpsent *d, int w, int h);
}

Expand Down
2 changes: 1 addition & 1 deletion src/fpsgame/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ struct fpsent : dynent, fpsstate
int lastpain;
int lastaction, lastattackgun;
int lasthitpushgun;
vector<fragmessage> *fragmessages;
vector<fragmessage> *fragmessages; // oldest first, newest at the end
bool attacking;
int attacksound, attackchan, idlesound, idlechan;
int lasttaunt;
Expand Down

0 comments on commit 9b107d1

Please sign in to comment.