3 float magicear_matched;
4 float W_Tuba_HasPlayed(entity pl, string melody, float instrument, float ignorepitch, float mintempo, float maxtempo);
5 string trigger_magicear_processmessage(entity ear, entity source, float teamsay, entity privatesay, string msgin)
7 float domatch, dotrigger, matchstart, l;
11 magicear_matched = false;
13 dotrigger = ((IS_PLAYER(source)) && (!IS_DEAD(source)) && ((ear.radius == 0) || (vdist(source.origin - ear.origin, <=, ear.radius))));
14 domatch = ((ear.spawnflags & 32) || dotrigger);
21 // we are in TUBA mode!
22 if (!(ear.spawnflags & 256))
25 if(!W_Tuba_HasPlayed(source, ear.message, ear.movedir_x, !(ear.spawnflags & 512), ear.movedir_y, ear.movedir_z))
28 magicear_matched = true;
32 savemessage = ear.message;
33 ear.message = string_null;
34 SUB_UseTargets(ear, source, NULL);
35 ear.message = savemessage;
44 if(ear.spawnflags & 256) // ENOTUBA
49 if(ear.spawnflags & 4)
55 if(ear.spawnflags & 1)
58 if(ear.spawnflags & 2)
61 if(ear.spawnflags & 8)
66 l = strlen(ear.message);
68 if(ear.spawnflags & 128)
71 msg = strdecolorize(msgin);
73 if(substring(ear.message, 0, 1) == "*")
75 if(substring(ear.message, -1, 1) == "*")
78 // as we need multi-replacement here...
79 s = substring(ear.message, 1, -2);
81 if(strstrofs(msg, s, 0) >= 0)
82 matchstart = -2; // we use strreplace on s
87 s = substring(ear.message, 1, -1);
89 if(substring(msg, -l, l) == s)
90 matchstart = strlen(msg) - l;
95 if(substring(ear.message, -1, 1) == "*")
98 s = substring(ear.message, 0, -2);
100 if(substring(msg, 0, l) == s)
107 if(msg == ear.message)
112 if(matchstart == -1) // no match
115 magicear_matched = true;
119 savemessage = ear.message;
120 ear.message = string_null;
121 SUB_UseTargets(ear, source, NULL);
122 ear.message = savemessage;
125 if(ear.spawnflags & 16)
129 else if(ear.netname != "")
132 return strreplace(s, ear.netname, msg);
135 substring(msg, 0, matchstart),
137 substring(msg, matchstart + l, -1)
145 string trigger_magicear_processmessage_forallears(entity source, float teamsay, entity privatesay, string msgin)
149 for(ear = magicears; ear; ear = ear.enemy)
151 msgout = trigger_magicear_processmessage(ear, source, teamsay, privatesay, msgin);
152 if(!(ear.spawnflags & 64))
160 spawnfunc(trigger_magicear)
162 this.enemy = magicears;
165 // actually handled in "say" processing
168 // 2 = ignore teamsay
170 // 8 = ignore tell to unknown player
171 // 16 = let netname replace the whole message (otherwise, netname is a word replacement if set)
172 // 32 = perform the replacement even if outside the radius or dead
173 // 64 = continue replacing/triggering even if this one matched
174 // 128 = don't decolorize message before matching
175 // 256 = message is a tuba note sequence (pitch.duration pitch.duration ...)
176 // 512 = tuba notes must be exact right pitch, no transposing
186 // if set, replacement for the matched text
188 // "hearing distance"
192 // for spawnflags 256, defines 'instrument+1 mintempo maxtempo' (zero component doesn't matter)
194 this.movedir_x -= 1; // map to tuba instrument numbers