2 float magicear_matched;
3 float W_Tuba_HasPlayed(entity pl, string melody, float instrument, float ignorepitch, float mintempo, float maxtempo);
4 string trigger_magicear_processmessage(entity ear, entity source, float teamsay, entity privatesay, string msgin)
6 float domatch, dotrigger, matchstart, l;
10 magicear_matched = false;
12 dotrigger = ((IS_PLAYER(source)) && (!IS_DEAD(source)) && ((ear.radius == 0) || (vdist(source.origin - ear.origin, <=, ear.radius))));
13 domatch = ((ear.spawnflags & 32) || dotrigger);
20 // we are in TUBA mode!
21 if (!(ear.spawnflags & 256))
24 if(!W_Tuba_HasPlayed(source, ear.message, ear.movedir_x, !(ear.spawnflags & 512), ear.movedir_y, ear.movedir_z))
27 magicear_matched = true;
31 savemessage = ear.message;
32 ear.message = string_null;
33 SUB_UseTargets(ear, source, NULL);
34 ear.message = savemessage;
43 if(ear.spawnflags & 256) // ENOTUBA
48 if(ear.spawnflags & 4)
54 if(ear.spawnflags & 1)
57 if(ear.spawnflags & 2)
60 if(ear.spawnflags & 8)
65 l = strlen(ear.message);
67 if(ear.spawnflags & 128)
70 msg = strdecolorize(msgin);
72 if(substring(ear.message, 0, 1) == "*")
74 if(substring(ear.message, -1, 1) == "*")
77 // as we need multi-replacement here...
78 s = substring(ear.message, 1, -2);
80 if(strstrofs(msg, s, 0) >= 0)
81 matchstart = -2; // we use strreplace on s
86 s = substring(ear.message, 1, -1);
88 if(substring(msg, -l, l) == s)
89 matchstart = strlen(msg) - l;
94 if(substring(ear.message, -1, 1) == "*")
97 s = substring(ear.message, 0, -2);
99 if(substring(msg, 0, l) == s)
106 if(msg == ear.message)
111 if(matchstart == -1) // no match
114 magicear_matched = true;
118 savemessage = ear.message;
119 ear.message = string_null;
120 SUB_UseTargets(ear, source, NULL);
121 ear.message = savemessage;
124 if(ear.spawnflags & 16)
128 else if(ear.netname != "")
131 return strreplace(s, ear.netname, msg);
134 substring(msg, 0, matchstart),
136 substring(msg, matchstart + l, -1)
144 string trigger_magicear_processmessage_forallears(entity source, float teamsay, entity privatesay, string msgin)
148 for(ear = magicears; ear; ear = ear.enemy)
150 msgout = trigger_magicear_processmessage(ear, source, teamsay, privatesay, msgin);
151 if(!(ear.spawnflags & 64))
159 spawnfunc(trigger_magicear)
161 this.enemy = magicears;
164 // actually handled in "say" processing
167 // 2 = ignore teamsay
169 // 8 = ignore tell to unknown player
170 // 16 = let netname replace the whole message (otherwise, netname is a word replacement if set)
171 // 32 = perform the replacement even if outside the radius or dead
172 // 64 = continue replacing/triggering even if this one matched
173 // 128 = don't decolorize message before matching
174 // 256 = message is a tuba note sequence (pitch.duration pitch.duration ...)
175 // 512 = tuba notes must be exact right pitch, no transposing
185 // if set, replacement for the matched text
187 // "hearing distance"
191 // for spawnflags 256, defines 'instrument+1 mintempo maxtempo' (zero component doesn't matter)
193 this.movedir_x -= 1; // map to tuba instrument numbers