X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fw_tuba.qc;h=a02061e8b80f741a27e419a786940dc157f9b1c3;hb=3c39aa374dfbbeb40759ed764bad0f9cd8e2aa8c;hp=243b32b20e2b0bdbb3b787dec2275f6bba515d79;hpb=55d5f004b38c1e911afa6ae0b244ae70b7c3fdab;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/w_tuba.qc b/qcsrc/server/w_tuba.qc index 243b32b20..a02061e8b 100644 --- a/qcsrc/server/w_tuba.qc +++ b/qcsrc/server/w_tuba.qc @@ -1,11 +1,140 @@ #ifdef REGISTER_WEAPON -REGISTER_WEAPON(TUBA, w_tuba, 0, 1, WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "tuba", "tuba", "@!#%'n Tuba"); +REGISTER_WEAPON(TUBA, w_tuba, 0, 1, WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "tuba", "tuba", _("@!#%'n Tuba")) #else #ifdef SVQC //#define TUBA_NOTE(n) strcat("weapons/tuba_note", ftos(n), ".wav") -.float tuba_notecount; .entity tuba_note; .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 instrument, float ignorepitch, float mintempo, float maxtempo) +{ + float i, j, mmin, mmax, nolength; + float n = tokenize_console(melody); + if(n > pl.tuba_lastnotes_cnt) + 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) + { + vector v = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - i + MAX_TUBANOTES, MAX_TUBANOTES)]); + float ai = stof(argv(n - i - 1)); + float np = floor(ai); + if(ai == np) + nolength = TRUE; + // n counts the last played notes BACKWARDS + // _x is start + // _y is end + // _z is note pitch + if(ignorepitch && i == 0) + { + pitchshift = np - v_z; + } + else + { + if(v_z + pitchshift != np) + return FALSE; + } + } + + // now we know the right NOTES were played + if(!nolength) + { + // verify rhythm... + float ti = 0; + 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) + { + vector vi = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - i + MAX_TUBANOTES, MAX_TUBANOTES)]); + float ai = stof(argv(n - i - 1)); + ti -= 1 / (ai - floor(ai)); + float tj = ti; + for(j = i+1; j < n; ++j) + { + vector vj = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - j + MAX_TUBANOTES, MAX_TUBANOTES)]); + float aj = stof(argv(n - j - 1)); + tj -= (aj - floor(aj)); + + // note i should be at m*ti+b + // note j should be at m*tj+b + // so: + // we have a LINE l, so that + // vi_x <= l(ti) <= vi_y + // vj_x <= l(tj) <= vj_y + // what is m? + + // vi_x <= vi_y <= vj_x <= vj_y + // ti <= tj + //print(sprintf("first note: %f to %f, should be %f\n", vi_x, vi_y, ti)); + //print(sprintf("second note: %f to %f, should be %f\n", vj_x, vj_y, tj)); + //print(sprintf("m1 = %f\n", (vi_x - vj_y) / (ti - tj))); + //print(sprintf("m2 = %f\n", (vi_y - vj_x) / (ti - tj))); + mmin = max(mmin, (vi_x - vj_y) / (ti - tj)); // lower bound + mmax = min(mmax, (vi_y - vj_x) / (ti - tj)); // upper bound + } + } + + if(mmin > mmax) // rhythm fail + return FALSE; + } + + 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); + + 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); +} float Tuba_GetNote(entity pl, float hittype) { @@ -48,7 +177,7 @@ float Tuba_GetNote(entity pl, float hittype) // kind of tuba currently is player slot number, or team number if in // teamplay // that way, holes in the range of notes are "plugged" - if(teams_matter) + if(teamplay) { if(pl.team == COLOR_TEAM2 || pl.team == COLOR_TEAM4) note += 3; @@ -76,9 +205,24 @@ float Tuba_GetNote(entity pl, float hittype) 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 & 1) | ((self.cnt + 42) * 2)); + WriteByte(MSG_ENTITY, sf); if(sf & 1) + { + WriteChar(MSG_ENTITY, self.cnt); + f = 0; + if(self.realowner != to) + f |= 1; + f |= 2 * self.tuba_instrument; + WriteByte(MSG_ENTITY, f); + } + if(sf & 2) { WriteCoord(MSG_ENTITY, self.origin_x); WriteCoord(MSG_ENTITY, self.origin_y); @@ -89,89 +233,86 @@ float W_Tuba_NoteSendEntity(entity to, float sf) void W_Tuba_NoteThink() { - float needchange, dist_mult; + float dist_mult; float vol0, vol1; vector dir0, dir1; vector v; entity e; if(time > self.teleport_time) { - self.owner.tuba_note = world; - remove(self); + W_Tuba_NoteOff(); return; } self.nextthink = time; - dist_mult = cvar("g_balance_tuba_attenuation") / cvar("snd_soundradius"); - needchange = 0; + dist_mult = autocvar_g_balance_tuba_attenuation / autocvar_snd_soundradius; FOR_EACH_REALCLIENT(e) - if(e != self.owner) + if(e != self.realowner) { v = self.origin - (e.origin + e.view_ofs); vol0 = max(0, 1 - vlen(v) * dist_mult); dir0 = normalize(v); - v = self.owner.origin - (e.origin + e.view_ofs); + v = self.realowner.origin - (e.origin + e.view_ofs); vol1 = max(0, 1 - vlen(v) * dist_mult); dir1 = normalize(v); if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume { - setorigin(self, self.owner.origin); - self.SendFlags |= 1; + setorigin(self, self.realowner.origin); + self.SendFlags |= 2; break; } if(dir0 * dir1 < 0.9994) // 2 degrees change in angle { - setorigin(self, self.owner.origin); - self.SendFlags |= 1; + setorigin(self, self.realowner.origin); + self.SendFlags |= 2; break; } } } -void W_Tuba_Attack(float hittype) +void W_Tuba_NoteOn(float hittype) { vector o; - float c, n; - W_SetupShot(self, FALSE, 2, "", cvar("g_balance_tuba_damage")); - if(self.tuba_notecount) - { - self.tuba_notecount = FALSE; - c = CHAN_WEAPON; - } - else - { - self.tuba_notecount = TRUE; - c = CHAN_WEAPON2; - } + 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) + if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument) { - /* - self.tuba_note.cnt = n; - self.tuba_note.SendFlags |= 2; - */ - remove(self.tuba_note); - self.tuba_note = world; + entity oldself = self; + self = self.tuba_note; + W_Tuba_NoteOff(); + self = oldself; } } if not(self.tuba_note) { self.tuba_note = spawn(); - self.tuba_note.owner = self; + self.tuba_note.owner = self.tuba_note.realowner = self; self.tuba_note.cnt = n; + 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); } - self.tuba_note.teleport_time = time + cvar("g_balance_tuba_refire") * 2; // so it can get prolonged safely + self.tuba_note.teleport_time = time + autocvar_g_balance_tuba_refire * 2 * W_WeaponRateFactor(); // so it can get prolonged safely - //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), cvar("g_balance_tuba_attenuation")); - RadiusDamage(self, self, cvar("g_balance_tuba_damage"), cvar("g_balance_tuba_edgedamage"), cvar("g_balance_tuba_radius"), world, cvar("g_balance_tuba_force"), hittype | WEP_TUBA, world); + //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation); + RadiusDamage(self, self, autocvar_g_balance_tuba_damage, autocvar_g_balance_tuba_edgedamage, autocvar_g_balance_tuba_radius, world, autocvar_g_balance_tuba_force, hittype | WEP_TUBA, world); o = gettaginfo(self.exteriorweaponentity, 0); if(time > self.tuba_smoketime) @@ -192,7 +333,7 @@ float w_tuba(float req) { // bots cannot play the Tuba well yet // I think they should start with the recorder first - if(vlen(self.origin - self.enemy.origin) < cvar("g_balance_tuba_radius")) + if(vlen(self.origin - self.enemy.origin) < autocvar_g_balance_tuba_radius) { if(random() > 0.5) self.BUTTON_ATCK = 1; @@ -203,25 +344,27 @@ float w_tuba(float req) else if (req == WR_THINK) { if (self.BUTTON_ATCK) - if (weapon_prepareattack(0, cvar("g_balance_tuba_refire"))) + if (weapon_prepareattack(0, autocvar_g_balance_tuba_refire)) { - W_Tuba_Attack(0); - //weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_tuba_animtime"), w_ready); - weapon_thinkf(WFRAME_IDLE, cvar("g_balance_tuba_animtime"), w_ready); + 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, cvar("g_balance_tuba_refire"))) + if (weapon_prepareattack(1, autocvar_g_balance_tuba_refire)) { - W_Tuba_Attack(HITTYPE_SECONDARY); - //weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_tuba_animtime"), w_ready); - weapon_thinkf(WFRAME_IDLE, cvar("g_balance_tuba_animtime"), w_ready); + 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); } if(self.tuba_note) { 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; } } } @@ -230,19 +373,48 @@ 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) // precache_sound(TUBA_NOTE(i)); } else if (req == WR_SETUP) + { weapon_setup(WEP_TUBA); + self.current_ammo = ammo_none; + self.tuba_instrument = 0; + } + else if (req == WR_RELOAD) + { + // switch to alternate instruments :) + if(self.weaponentity.state == WS_READY) + { + switch(self.tuba_instrument) + { + case 0: + self.tuba_instrument = 1; + 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; + weapon_thinkf(WFRAME_RELOAD, 0.5, w_ready); + } + } else if (req == WR_CHECKAMMO1) return TRUE; // TODO use fuel? else if (req == WR_CHECKAMMO2) return TRUE; // TODO use fuel? return TRUE; -}; +} #endif #ifdef CSQC float w_tuba(float req) @@ -257,11 +429,45 @@ float w_tuba(float req) } else if (req == WR_SUICIDEMESSAGE) { - w_deathtypestring = "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 = "died of #'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; }