From 35398531db0c3d301cf1604d10dd79f4a7268655 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sat, 19 Nov 2011 16:28:26 +0100 Subject: [PATCH] add a simple test function for last tuba notes --- qcsrc/server/w_tuba.qc | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/qcsrc/server/w_tuba.qc b/qcsrc/server/w_tuba.qc index fb240bd369..1e47a3b3d1 100644 --- a/qcsrc/server/w_tuba.qc +++ b/qcsrc/server/w_tuba.qc @@ -8,9 +8,32 @@ REGISTER_WEAPON(TUBA, w_tuba, 0, 1, WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH, BOT_PICKU .float tuba_instrument; #define MAX_TUBANOTES 32 -.float tuba_lastnotes_pos; +.float tuba_lastnotes_last; +.float tuba_lastnotes_cnt; // over .vector tuba_lastnotes[MAX_TUBANOTES]; +float W_Tuba_HasPlayed(entity pl, string melody) +{ + float i; + float n = tokenize_console(melody); + if(n > pl.tuba_lastnotes_cnt) + return FALSE; + for(i = 0; i < n; ++i) + { + vector v = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - i + MAX_TUBANOTES, MAX_TUBANOTES)]); + float ai = stof(argv(n - i - 1)); + // n counts the last played notes BACKWARDS + // _x is start + // _y is end + // _z is note pitch + if(v_z != floor(ai)) + return FALSE; + // FIXME verify rhythm + } + pl.tuba_lastnotes_cnt = 0; + return TRUE; +} + void W_Tuba_NoteOff() { // we have a note: @@ -19,9 +42,14 @@ void W_Tuba_NoteOff() // note: self.cnt if(self.owner.tuba_note == self) { - self.owner.(tuba_lastnotes[self.owner.tuba_lastnotes_pos]) = eX * self.spawnshieldtime + eY * time + eZ * self.cnt; - self.owner.tuba_lastnotes_pos = mod(self.owner.tuba_lastnotes_pos + 1, MAX_TUBANOTES); + self.owner.tuba_lastnotes_last = mod(self.owner.tuba_lastnotes_last + 1, MAX_TUBANOTES); + self.owner.(tuba_lastnotes[self.owner.tuba_lastnotes_last]) = eX * self.spawnshieldtime + eY * time + eZ * self.cnt; 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 0 4 2")) + dprint("Someone knows how to play Loom!\n"); } remove(self); } -- 2.39.2