-
Notifications
You must be signed in to change notification settings - Fork 3
/
hudfragmessages.patch
201 lines (197 loc) · 7.24 KB
/
hudfragmessages.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
Index: src/fpsgame/fps.cpp
===================================================================
--- src/fpsgame/fps.cpp (revision 6488)
+++ src/fpsgame/fps.cpp (working copy)
@@ -34,9 +34,11 @@
{
if(arg[0] ? player1->state==CS_SPECTATOR : following>=0)
{
+ int ofollowing = following;
following = arg[0] ? parseplayer(arg) : -1;
if(following==player1->clientnum) following = -1;
followdir = 0;
+ if(following!=ofollowing) clearfragmessages();
conoutf("follow %s", following>=0 ? "on" : "off");
}
}
@@ -55,6 +57,7 @@
cur = (cur + dir + clients.length()) % clients.length();
if(clients[cur] && clients[cur]->state!=CS_SPECTATOR)
{
+ if(following!=cur) clearfragmessages();
if(following<0) conoutf("follow on");
following = cur;
followdir = dir;
@@ -115,6 +118,7 @@
if(following<0) return;
following = -1;
followdir = 0;
+ clearfragmessages();
conoutf("follow off");
}
@@ -496,6 +500,15 @@
if(d==player1) conoutf(contype, "\f2%s got fragged by %s", dname, aname);
else conoutf(contype, "\f2%s fragged %s", aname, dname);
}
+ if(hudfragmessageforcecolors && !m_teammode)
+ {
+ dname = colorname(d, NULL, d==h ? "\fs\f1" : "\fs\f3", "\fr", NULL);
+ aname = colorname(actor, NULL, actor==h ? "\fs\f1" : "\fs\f3", "\fr", NULL);
+ }
+ if(h==player1 && d==player1) dname = "\fs\f2you\fr";
+ if(h==player1 && actor==player1) aname = "\fs\f2you\fr";
+ if(d==actor) addfragmessage(contype, NULL, dname, HICON_TOKEN-HICON_FIST);
+ else addfragmessage(contype, aname, dname, d->lasthitpushgun);
deathstate(d);
ai::killed(d, actor);
}
@@ -1091,6 +1104,7 @@
{
if(gameclock) drawgameclock(w, h);
if(hudscore) drawhudscore(w, h);
+ if(hudfragmessages==1 || (hudfragmessages==2 && !m_insta)) drawfragmessages(w, h);
}
}
Index: src/p1xbraten/fragmessages.cpp
===================================================================
--- src/p1xbraten/fragmessages.cpp (nonexistent)
+++ src/p1xbraten/fragmessages.cpp (working copy)
@@ -0,0 +1,77 @@
+#include "game.h"
+
+namespace game {
+ vector<fragmessage> fragmessages; // oldest first, newest at the end
+
+ MOD(VARP, hudfragmessages, 0, 1, 2);
+ MOD(VARFP, maxhudfragmessages, 1, 3, 10, { fragmessages.growbuf(maxhudfragmessages); fragmessages.shrink(min(fragmessages.length(), maxhudfragmessages)); });
+ MOD(FVARP, hudfragmessageduration, 0, 2.0f, 10.0f); // in seconds
+ MOD(VARP, hudfragmessagefade, 0, 1, 1);
+ MOD(FVARP, hudfragmessagex, 0, 0.5f, 1.0f);
+ MOD(FVARP, hudfragmessagey, 0, 0.25f, 1.0f);
+ MOD(FVARP, hudfragmessagescale, 0.1f, 0.5f, 1.0f);
+ MOD(VARP, hudfragmessagestackdir, -1, 0, 1); // -1 = upwards, 1 = downwards
+ MOD(HVARP, hudfragmessagefilter, 0, 0x2800, 0x7FFFFFF); // default: own frags + teamkills
+ MOD(VARP, hudfragmessageforcecolors, 0, 1, 1);
+
+ void addfragmessage(int contype, const char *aname, const char *vname, int gun)
+ {
+ if(!(contype&hudfragmessagefilter)) return;
+ if(fragmessages.length()>=maxhudfragmessages) fragmessages.remove(0, fragmessages.length()-maxhudfragmessages+1);
+ fragmessages.add(fragmessage(aname, vname, gun));
+ }
+
+ void clearfragmessages()
+ {
+ fragmessages.shrink(0);
+ }
+
+ void drawfragmessages(int w, int h)
+ {
+ if(fragmessages.empty()) return;
+
+ float stepsize = (3*HICON_SIZE)/2;
+ float stackdir = hudfragmessagestackdir ? hudfragmessagestackdir : (hudfragmessagey>0.5 ? 1 : -1); // default: towards closest edge
+ vec2 origin = vec2(hudfragmessagex, hudfragmessagey).mul(vec2(w, h).div(hudfragmessagescale));
+
+ pushhudmatrix();
+ hudmatrix.scale(hudfragmessagescale, hudfragmessagescale, 1);
+ flushhudmatrix();
+
+ int showmillis = (int)(hudfragmessageduration*1000.0f);
+
+ for(int i = fragmessages.length()-1; i>=0; i--)
+ {
+ fragmessage &m = fragmessages[i];
+
+ if(lastmillis-m.fragtime > showmillis + (hudfragmessagefade ? 255 : 0))
+ {
+ // all messages before i are older, so remove all of them
+ fragmessages.remove(0, i+1);
+ break;
+ }
+
+ int alpha = 255 - max(0, lastmillis-m.fragtime-showmillis);
+
+ vec2 drawposcenter = vec2(0, (fragmessages.length()-1-i)*stackdir*stepsize).add(origin);
+
+ int tw, th; vec2 drawpos;
+ if(m.attackername[0])
+ {
+ text_bounds(m.attackername, tw, th);
+ drawpos = vec2(-2*(tw+HICON_SIZE), -th).div(2).add(drawposcenter);
+ draw_text(m.attackername, drawpos.x, drawpos.y, 0xFF, 0xFF, 0xFF, alpha);
+ }
+
+ drawpos = vec2(drawposcenter).sub(HICON_SIZE / 2);
+ gle::color(bvec(0xFF, 0xFF, 0xFF), alpha);
+ drawicon(HICON_FIST + m.weapon, drawpos.x, drawpos.y);
+
+ text_bounds(m.victimname, tw, th);
+ drawpos = vec2(2*HICON_SIZE, -th).div(2).add(drawposcenter);
+ draw_text(m.victimname, drawpos.x, drawpos.y, 0xFF, 0xFF, 0xFF, alpha);
+ }
+
+ pophudmatrix();
+ }
+}
Index: src/p1xbraten/fragmessages.h
===================================================================
--- src/p1xbraten/fragmessages.h (nonexistent)
+++ src/p1xbraten/fragmessages.h (working copy)
@@ -0,0 +1,29 @@
+#ifndef __FRAGMESSAGES_H__
+#define __FRAGMESSAGES_H__
+
+#include "game.h"
+
+namespace game {
+ struct fragmessage {
+ string attackername, victimname;
+ int weapon;
+ int fragtime;
+
+ fragmessage(const char *aname, const char *vname, int fragweapon)
+ {
+ copystring(attackername, aname ? aname : "");
+ copystring(victimname, vname);
+ weapon = fragweapon;
+ fragtime = lastmillis;
+ }
+ };
+
+ extern vector<fragmessage> fragmessages;
+ extern int hudfragmessages;
+ extern int hudfragmessageforcecolors;
+ extern void addfragmessage(int contype, const char *aname, const char *vname, int gun);
+ extern void clearfragmessages();
+ extern void drawfragmessages(int w, int h);
+}
+
+#endif
Index: src/fpsgame/game.h
===================================================================
--- src/fpsgame/game.h (revision 6488)
+++ src/fpsgame/game.h (working copy)
@@ -543,6 +543,7 @@
int respawned, suicided;
int lastpain;
int lastaction, lastattackgun;
+ int lasthitpushgun;
bool attacking;
int attacksound, attackchan, idlesound, idlechan;
int lasttaunt;
@@ -578,6 +579,7 @@
vec push(dir);
push.mul((actor==this && guns[gun].exprad ? EXP_SELFPUSH : 1.0f)*guns[gun].hitpush*damage/weight);
vel.add(push);
+ lasthitpushgun = gun;
}
void stopattacksound()
@@ -846,6 +848,8 @@
extern vec hudgunorigin(int gun, const vec &from, const vec &to, fpsent *d);
}
+#include "fragmessages.h"
+
namespace server
{
extern const char *modename(int n, const char *unknown = "unknown");