X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fw_tuba.qc;h=1e47a3b3d1b36a512a910b793a02fc04be498de4;hb=35398531db0c3d301cf1604d10dd79f4a7268655;hp=987e7b41e2570b6480e4d141aa546fcd3dc6ccec;hpb=88296a0f82b51a5b98d15f7be8032cdf584eec99;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/w_tuba.qc b/qcsrc/server/w_tuba.qc index 987e7b41e..1e47a3b3d 100644 --- a/qcsrc/server/w_tuba.qc +++ b/qcsrc/server/w_tuba.qc @@ -7,6 +7,53 @@ REGISTER_WEAPON(TUBA, w_tuba, 0, 1, WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH, BOT_PICKU .float tuba_smoketime; .float tuba_instrument; +#define MAX_TUBANOTES 32 +.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: + // on: self.spawnshieldtime + // off: time + // note: self.cnt + if(self.owner.tuba_note == self) + { + 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); +} + float Tuba_GetNote(entity pl, float hittype) { float note; @@ -78,6 +125,10 @@ float W_Tuba_NoteSendEntity(entity to, float sf) { float f; + msg_entity = to; + if(!sound_allowed(MSG_ONE, self.realowner)) + return FALSE; + WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE); WriteByte(MSG_ENTITY, sf); if(sf & 1) @@ -107,8 +158,7 @@ void W_Tuba_NoteThink() entity e; if(time > self.teleport_time) { - self.realowner.tuba_note = world; - remove(self); + W_Tuba_NoteOff(); return; } self.nextthink = time; @@ -137,20 +187,31 @@ void W_Tuba_NoteThink() } } -void W_Tuba_Attack(float hittype) +void W_Tuba_NoteOn(float hittype) { vector o; float n; + W_SetupShot(self, FALSE, 2, "", 0, autocvar_g_balance_tuba_damage); n = Tuba_GetNote(self, hittype); + hittype = 0; + if(self.tuba_instrument & 1) + hittype |= HITTYPE_SECONDARY; + if(self.tuba_instrument & 2) + hittype |= HITTYPE_BOUNCE; + if(self.tuba_instrument & 4) + hittype |= HITTYPE_HEADSHOT; + if(self.tuba_note) { if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument) { - remove(self.tuba_note); - self.tuba_note = world; + entity oldself = self; + self = self.tuba_note; + W_Tuba_NoteOff(); + self = oldself; } } @@ -162,6 +223,7 @@ void W_Tuba_Attack(float hittype) self.tuba_note.tuba_instrument = self.tuba_instrument; self.tuba_note.think = W_Tuba_NoteThink; self.tuba_note.nextthink = time; + self.tuba_note.spawnshieldtime = time; Net_LinkEntity(self.tuba_note, FALSE, 0, W_Tuba_NoteSendEntity); } @@ -202,14 +264,14 @@ float w_tuba(float req) if (self.BUTTON_ATCK) if (weapon_prepareattack(0, autocvar_g_balance_tuba_refire)) { - W_Tuba_Attack(0); + W_Tuba_NoteOn(0); //weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_tuba_animtime, w_ready); weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_tuba_animtime, w_ready); } if (self.BUTTON_ATCK2) if (weapon_prepareattack(1, autocvar_g_balance_tuba_refire)) { - W_Tuba_Attack(HITTYPE_SECONDARY); + W_Tuba_NoteOn(HITTYPE_SECONDARY); //weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_tuba_animtime, w_ready); weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_tuba_animtime, w_ready); } @@ -217,8 +279,10 @@ float w_tuba(float req) { if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2) { - remove(self.tuba_note); - self.tuba_note = world; + entity oldself = self; + self = self.tuba_note; + W_Tuba_NoteOff(); + self = oldself; } } } @@ -227,6 +291,9 @@ float w_tuba(float req) precache_model ("models/weapons/g_tuba.md3"); precache_model ("models/weapons/v_tuba.md3"); precache_model ("models/weapons/h_tuba.iqm"); + precache_model ("models/weapons/g_akordeon.md3"); + precache_model ("models/weapons/v_akordeon.md3"); + precache_model ("models/weapons/h_akordeon.iqm"); //float i; //for(i = -18; i <= +27; ++i) @@ -240,22 +307,20 @@ float w_tuba(float req) } else if (req == WR_RELOAD) { - // TODO switch to alternate instruments :) + // switch to alternate instruments :) if(self.weaponentity.state == WS_READY) { - /* switch(self.tuba_instrument) { case 0: self.tuba_instrument = 1; - self.weaponname = "laser"; + self.weaponname = "akordeon"; break; case 1: self.tuba_instrument = 0; self.weaponname = "tuba"; break; } - */ W_SetupShot(self, FALSE, 0, "", 0, 0); pointparticles(particleeffectnum("teleport"), w_shotorg, '0 0 0', 1); self.weaponentity.state = WS_INUSE; @@ -267,7 +332,7 @@ float w_tuba(float req) else if (req == WR_CHECKAMMO2) return TRUE; // TODO use fuel? return TRUE; -}; +} #endif #ifdef CSQC float w_tuba(float req) @@ -282,11 +347,45 @@ float w_tuba(float req) } else if (req == WR_SUICIDEMESSAGE) { - w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Tuba"); + float instr; + instr = 0; + if(w_deathtype & HITTYPE_SECONDARY) + instr |= 1; + if(w_deathtype & HITTYPE_BOUNCE) + instr |= 2; + if(w_deathtype & HITTYPE_HEADSHOT) + instr |= 4; + switch(instr) + { + default: + case 0: // Tuba + w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Tuba"); + break; + case 1: // Accordeon + w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Accordeon"); + break; + } } else if (req == WR_KILLMESSAGE) { - w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Tuba"); + float instr; + instr = 0; + if(w_deathtype & HITTYPE_SECONDARY) + instr |= 1; + if(w_deathtype & HITTYPE_BOUNCE) + instr |= 2; + if(w_deathtype & HITTYPE_HEADSHOT) + instr |= 4; + switch(instr) + { + default: + case 0: // Tuba + w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Tuba"); + break; + case 1: // Accordeon + w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Accordeon"); + break; + } } return TRUE; }