From b89fa48bf6faceabab9ee7ab86e614d8045b2186 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sat, 19 Nov 2011 17:41:30 +0100 Subject: [PATCH] magicear: support tuba notes --- qcsrc/server/g_triggers.qc | 35 +++++++++++++++++++++++++++++++++++ qcsrc/server/w_tuba.qc | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/qcsrc/server/g_triggers.qc b/qcsrc/server/g_triggers.qc index 0ab2b4233..5318182e8 100644 --- a/qcsrc/server/g_triggers.qc +++ b/qcsrc/server/g_triggers.qc @@ -1908,6 +1908,7 @@ void spawnfunc_trigger_disablerelay() } float magicear_matched; +float W_Tuba_HasPlayed(entity pl, string melody, float instrument, float ignorepitch, float mintempo, float maxtempo); string trigger_magicear_processmessage(entity ear, entity source, float teamsay, entity privatesay, string msgin) { float domatch, dotrigger, matchstart, l; @@ -1921,6 +1922,34 @@ string trigger_magicear_processmessage(entity ear, entity source, float teamsay, if not(domatch) return msgin; + if not(msgin) + { + // we are in TUBA mode! + if not(ear.spawnflags & 256) + return msgin; + + if(!W_Tuba_HasPlayed(self, self.message, !(ear.spawnflags & 256), ear.movedir_x, ear.movedir_y, ear.movedir_z)) + return msgin; + + magicear_matched = TRUE; + + if(dotrigger) + { + oldself = activator = self; + self = ear; + SUB_UseTargets(); + self = oldself; + } + + if(ear.netname != "") + return ear.netname; + + return msgin; + } + + if(ear.spawnflags & 256) // ENOTUBA + return msgin; + if(privatesay) { if(ear.spawnflags & 4) @@ -2048,6 +2077,8 @@ void spawnfunc_trigger_magicear() // 16 = let netname replace the whole message (otherwise, netname is a word replacement if set) // 32 = perform the replacement even if outside the radius or dead // 64 = continue replacing/triggering even if this one matched + // 128 = don't decolorize message before matching + // 256 = message is a tuba note sequence (pitch.duration pitch.duration ...) // message: either // *pattern* // or @@ -2062,6 +2093,10 @@ void spawnfunc_trigger_magicear() // "hearing distance" // target: // what to trigger + // movedir: + // for spawnflags 256, defines 'instrument+1 mintempo maxtempo' (zero component doesn't matter) + + self.movedir_x -= 1; // map to tuba instrument numbers } void relay_activators_use() diff --git a/qcsrc/server/w_tuba.qc b/qcsrc/server/w_tuba.qc index a70926c8a..32a796075 100644 --- a/qcsrc/server/w_tuba.qc +++ b/qcsrc/server/w_tuba.qc @@ -12,7 +12,7 @@ REGISTER_WEAPON(TUBA, w_tuba, 0, 1, WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH, BOT_PICKU .float tuba_lastnotes_cnt; // over .vector tuba_lastnotes[MAX_TUBANOTES]; -float W_Tuba_HasPlayed(entity pl, string melody, float ignorepitch, float mintempo, float maxtempo) +float W_Tuba_HasPlayed(entity pl, string melody, float instrument, float ignorepitch, float mintempo, float maxtempo) { float i, j, mmin, mmax, nolength; float n = tokenize_console(melody); @@ -20,6 +20,10 @@ float W_Tuba_HasPlayed(entity pl, string melody, float ignorepitch, float mintem return FALSE; float pitchshift = 0; + if(instrument >= 0) + if(pl.tuba_instrument != instrument) + return FALSE; + // verify notes... nolength = FALSE; for(i = 0; i < n; ++i) @@ -49,8 +53,14 @@ float W_Tuba_HasPlayed(entity pl, string melody, float ignorepitch, float mintem { // verify rhythm... float ti = 0; - mmin = 240 / maxtempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec - mmax = 240 / mintempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec + if(maxtempo > 0) + mmin = 240 / maxtempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec + else + mmin = 0; + if(mintempo > 0) + mmax = 240 / mintempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec + else + mmax = 240; // you won't try THAT hard... (tempo 1) //print(sprintf("initial tempo rules: %f %f\n", mmin, mmax)); for(i = 0; i < n; ++i) @@ -91,6 +101,7 @@ float W_Tuba_HasPlayed(entity pl, string melody, float ignorepitch, float mintem } pl.tuba_lastnotes_cnt = 0; + return TRUE; } @@ -107,9 +118,22 @@ void W_Tuba_NoteOff() self.owner.tuba_note = world; self.owner.tuba_lastnotes_cnt = bound(0, self.owner.tuba_lastnotes_cnt + 1, MAX_TUBANOTES); - // debug - if(W_Tuba_HasPlayed(self.owner, "4.25 0.25 4.25 2.25", TRUE, 50, 130)) - dprint("Someone knows how to play Loom!\n"); + string s; + s = trigger_magicear_processmessage_forallears(self.owner, 0, world, string_null); + if(s != "") + { + // simulate a server message + switch(self.tuba_instrument) + { + default: + case 0: // Tuba + bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%%'n Tuba: ^7", s, "\n")); + break; + case 1: + bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%%'n Accordeon: ^7", s, "\n")); + break; + } + } } remove(self); } -- 2.39.2