X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fweapons%2Fweapon%2Ftuba.qc;h=43e5ca24eebb010ece7cfe76ad52dd712ed29b62;hb=5ab697b0184201b9fb2fe49fb33699cbde5d7f18;hp=2570c7ba783b0a9d50342b5c897a73bb735ff2af;hpb=bf094df0de66898cb15780dbf136bf93b0761857;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/weapons/weapon/tuba.qc b/qcsrc/common/weapons/weapon/tuba.qc index 2570c7ba7..43e5ca24e 100644 --- a/qcsrc/common/weapons/weapon/tuba.qc +++ b/qcsrc/common/weapons/weapon/tuba.qc @@ -1,77 +1,32 @@ -#ifndef IMPLEMENTATION -CLASS(Tuba, Weapon) -/* impulse */ ATTRIB(Tuba, impulse, int, 1); -/* flags */ ATTRIB(Tuba, spawnflags, int, WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH); -/* rating */ ATTRIB(Tuba, bot_pickupbasevalue, float, BOT_PICKUP_RATING_MID); -/* color */ ATTRIB(Tuba, wpcolor, vector, '0 1 0'); -/* modelname */ ATTRIB(Tuba, mdl, string, "tuba"); -#ifdef GAMEQC -/* model */ ATTRIB(Tuba, m_model, Model, MDL_TUBA_ITEM); -#endif -/* crosshair */ ATTRIB(Tuba, w_crosshair, string, "gfx/crosshairtuba"); -/* crosshair */ //ATTRIB(Tuba, w_crosshair_size, float, 0.65); -/* wepimg */ ATTRIB(Tuba, model2, string, "weapontuba"); -/* refname */ ATTRIB(Tuba, netname, string, "tuba"); -/* xgettext:no-c-format */ -/* wepname */ ATTRIB(Tuba, m_name, string, _("@!#%'n Tuba")); - -#define X(BEGIN, P, END, class, prefix) \ - BEGIN(class) \ - P(class, prefix, animtime, float, NONE) \ - P(class, prefix, attenuation, float, NONE) \ - P(class, prefix, damage, float, NONE) \ - P(class, prefix, edgedamage, float, NONE) \ - P(class, prefix, fadetime, float, NONE) \ - P(class, prefix, force, float, NONE) \ - P(class, prefix, pitchstep, float, NONE) \ - P(class, prefix, radius, float, NONE) \ - P(class, prefix, refire, float, NONE) \ - P(class, prefix, switchdelay_drop, float, NONE) \ - P(class, prefix, switchdelay_raise, float, NONE) \ - P(class, prefix, volume, float, NONE) \ - P(class, prefix, weaponreplace, string, NONE) \ - P(class, prefix, weaponstartoverride, float, NONE) \ - P(class, prefix, weaponstart, float, NONE) \ - P(class, prefix, weaponthrowable, float, NONE) \ - END() - W_PROPS(X, Tuba, tuba) -#undef X -ENDCLASS(Tuba) -REGISTER_WEAPON(TUBA, tuba, NEW(Tuba)); -#endif - -#ifdef IMPLEMENTATION +#include "tuba.qh" #ifdef SVQC .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]; -spawnfunc(weapon_tuba) { weapon_defaultspawnfunc(this, WEP_TUBA); } - -bool W_Tuba_HasPlayed(entity pl, string melody, int instrument, bool ignorepitch, float mintempo, float maxtempo) +bool W_Tuba_HasPlayed(entity pl, .entity weaponentity, string melody, int instrument, bool ignorepitch, float mintempo, float maxtempo) { float i, j, mmin, mmax, nolength; float n = tokenize_console(melody); - if(n > pl.tuba_lastnotes_cnt) + if(n > pl.(weaponentity).tuba_lastnotes_cnt) return false; float pitchshift = 0; if(instrument >= 0) - if(pl.tuba_instrument != instrument) + if(pl.(weaponentity).tuba_instrument != instrument) return false; // verify notes... nolength = false; for(i = 0; i < n; ++i) { - vector v = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]); + vector v = pl.(weaponentity).(tuba_lastnotes[(pl.(weaponentity).tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]); float ai = stof(argv(n - i - 1)); float np = floor(ai); if(ai == np) @@ -108,13 +63,13 @@ bool W_Tuba_HasPlayed(entity pl, string melody, int instrument, bool ignorepitch for(i = 0; i < n; ++i) { - vector vi = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]); + vector vi = pl.(weaponentity).(tuba_lastnotes[(pl.(weaponentity).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[(pl.tuba_lastnotes_last - j + MAX_TUBANOTES) % MAX_TUBANOTES]); + vector vj = pl.(weaponentity).(tuba_lastnotes[(pl.(weaponentity).tuba_lastnotes_last - j + MAX_TUBANOTES) % MAX_TUBANOTES]); float aj = stof(argv(n - j - 1)); tj -= (aj - floor(aj)); @@ -141,7 +96,7 @@ bool W_Tuba_HasPlayed(entity pl, string melody, int instrument, bool ignorepitch return false; } - pl.tuba_lastnotes_cnt = 0; + pl.(weaponentity).tuba_lastnotes_cnt = 0; return true; } @@ -153,12 +108,13 @@ void W_Tuba_NoteOff(entity this) // on: this.spawnshieldtime // off: time // note: this.cnt - if (actor.tuba_note == this) + .entity weaponentity = this.weaponentity_fld; + if (actor.(weaponentity).tuba_note == this) { - actor.tuba_lastnotes_last = (actor.tuba_lastnotes_last + 1) % MAX_TUBANOTES; - actor.(tuba_lastnotes[actor.tuba_lastnotes_last]) = eX * this.spawnshieldtime + eY * time + eZ * this.cnt; - actor.tuba_note = NULL; - actor.tuba_lastnotes_cnt = bound(0, actor.tuba_lastnotes_cnt + 1, MAX_TUBANOTES); + actor.(weaponentity).tuba_lastnotes_last = (actor.(weaponentity).tuba_lastnotes_last + 1) % MAX_TUBANOTES; + actor.(weaponentity).(tuba_lastnotes[actor.(weaponentity).tuba_lastnotes_last]) = vec3(this.spawnshieldtime, time, this.cnt); + actor.(weaponentity).tuba_note = NULL; + actor.(weaponentity).tuba_lastnotes_cnt = bound(0, actor.(weaponentity).tuba_lastnotes_cnt + 1, MAX_TUBANOTES); string s = trigger_magicear_processmessage_forallears(actor, 0, NULL, string_null); if (s != "") @@ -185,10 +141,10 @@ void W_Tuba_NoteOff(entity this) int W_Tuba_GetNote(entity pl, int hittype) { float movestate = 5; - if (pl.movement.x < 0) movestate -= 3; - else if (pl.movement.x > 0) movestate += 3; - if (pl.movement.y < 0) movestate -= 1; - else if (pl.movement.y > 0) movestate += 1; + if (CS(pl).movement.x < 0) movestate -= 3; + else if (CS(pl).movement.x > 0) movestate += 3; + if (CS(pl).movement.y < 0) movestate -= 1; + else if (CS(pl).movement.y > 0) movestate += 1; int note = 0; switch (movestate) @@ -267,9 +223,7 @@ bool W_Tuba_NoteSendEntity(entity this, entity to, int sf) } if (sf & 2) { - WriteCoord(MSG_ENTITY, this.origin.x); - WriteCoord(MSG_ENTITY, this.origin.y); - WriteCoord(MSG_ENTITY, this.origin.z); + WriteVector(MSG_ENTITY, this.origin); } return true; } @@ -311,55 +265,60 @@ void W_Tuba_NoteThink(entity this) void W_Tuba_NoteOn(entity actor, .entity weaponentity, float hittype) { - vector o; - float n; - - W_SetupShot(actor, weaponentity, false, 2, SND_Null, 0, WEP_CVAR(tuba, damage)); - - n = W_Tuba_GetNote(actor, hittype); + float n = W_Tuba_GetNote(actor, hittype); - hittype = 0; - if(actor.tuba_instrument & 1) + hittype = HITTYPE_SOUND; + if(actor.(weaponentity).tuba_instrument & 1) hittype |= HITTYPE_SECONDARY; - if(actor.tuba_instrument & 2) + if(actor.(weaponentity).tuba_instrument & 2) hittype |= HITTYPE_BOUNCE; - if(actor.tuba_note) + W_SetupShot(actor, weaponentity, false, 2, SND_Null, 0, WEP_CVAR(tuba, damage), hittype | WEP_TUBA.m_id); + + if(actor.(weaponentity).tuba_note) { - if(actor.tuba_note.cnt != n || actor.tuba_note.tuba_instrument != actor.tuba_instrument) + if(actor.(weaponentity).tuba_note.cnt != n || actor.(weaponentity).tuba_note.tuba_instrument != actor.(weaponentity).tuba_instrument) { - W_Tuba_NoteOff(actor.tuba_note); + W_Tuba_NoteOff(actor.(weaponentity).tuba_note); } } - if(!actor.tuba_note) + if(!actor.(weaponentity).tuba_note) { - actor.tuba_note = new(tuba_note); - actor.tuba_note.owner = actor.tuba_note.realowner = actor; - actor.tuba_note.cnt = n; - actor.tuba_note.tuba_instrument = actor.tuba_instrument; - setthink(actor.tuba_note, W_Tuba_NoteThink); - actor.tuba_note.nextthink = time; - actor.tuba_note.spawnshieldtime = time; - Net_LinkEntity(actor.tuba_note, false, 0, W_Tuba_NoteSendEntity); + entity note = new(tuba_note); + note.weaponentity_fld = weaponentity; + actor.(weaponentity).tuba_note = note; + note.owner = note.realowner = actor; + note.cnt = n; + note.tuba_instrument = actor.(weaponentity).tuba_instrument; + setthink(note, W_Tuba_NoteThink); + note.nextthink = time; + note.spawnshieldtime = time; + Net_LinkEntity(note, false, 0, W_Tuba_NoteSendEntity); } - actor.tuba_note.teleport_time = time + WEP_CVAR(tuba, refire) * 2 * W_WeaponRateFactor(actor); // so it can get prolonged safely + actor.(weaponentity).tuba_note.teleport_time = time + WEP_CVAR(tuba, refire) * 2 * W_WeaponRateFactor(actor); // so it can get prolonged safely //sound(actor, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation); - RadiusDamage(actor, actor, WEP_CVAR(tuba, damage), WEP_CVAR(tuba, edgedamage), WEP_CVAR(tuba, radius), NULL, NULL, WEP_CVAR(tuba, force), hittype | WEP_TUBA.m_id, NULL); + RadiusDamage(actor, actor, WEP_CVAR(tuba, damage), WEP_CVAR(tuba, edgedamage), WEP_CVAR(tuba, radius), NULL, NULL, WEP_CVAR(tuba, force), hittype | WEP_TUBA.m_id, weaponentity, NULL); - o = gettaginfo(actor.exteriorweaponentity, 0); - if(time > actor.tuba_smoketime) + if(time > actor.(weaponentity).tuba_smoketime) { - Send_Effect(EFFECT_SMOKE_RING, o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1); - actor.tuba_smoketime = time + 0.25; + // FIXME gettaginfo(actor.(weaponentity), 0) doesn't return the real origin of the weapon + vector org = gettaginfo(actor.(weaponentity), 0); + if(actor.(weaponentity).tuba_instrument == 1) + Send_Effect(EFFECT_SMOKE_RING, org + v_up * 25 + v_right * 10 + v_forward * 14, v_up * 100, 1); + else if(actor.(weaponentity).tuba_instrument == 2) + Send_Effect(EFFECT_SMOKE_RING, org + v_up * 50 + v_right * 10 + v_forward * 45, v_up * 100, 1); + else + Send_Effect(EFFECT_SMOKE_RING, org + v_up * 40 + v_right * 10 + v_forward * 14, v_up * 100, 1); + actor.(weaponentity).tuba_smoketime = time + 0.25; } } #endif #ifdef SVQC -METHOD(Tuba, wr_aim, void(Tuba this, entity actor)) +METHOD(Tuba, wr_aim, void(Tuba this, entity actor, .entity weaponentity)) { // bots cannot play the Tuba well yet // I think they should start with the recorder first @@ -386,69 +345,46 @@ METHOD(Tuba, wr_think, void(Tuba this, entity actor, .entity weaponentity, int f W_Tuba_NoteOn(actor, weaponentity, HITTYPE_SECONDARY); weapon_thinkf(actor, weaponentity, WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready); } - if (actor.tuba_note) + if (actor.(weaponentity).tuba_note) { if (!(fire & 1) && !(fire & 2)) { - W_Tuba_NoteOff(actor.tuba_note); + W_Tuba_NoteOff(actor.(weaponentity).tuba_note); } } } -METHOD(Tuba, wr_setup, void(Tuba this, entity actor)) +METHOD(Tuba, wr_setup, void(Tuba this, entity actor, .entity weaponentity)) { - actor.ammo_field = ammo_none; - actor.tuba_instrument = 0; + actor.(weaponentity).tuba_instrument = 0; } -#endif -REGISTER_NET_S2C(tuba_instrument) -#ifdef CSQC -NET_HANDLE(tuba_instrument, bool) -{ - int i = ReadByte(); - return = true; - string s = (i == 0) ? "tuba" : - (i == 1) ? "akordeon" : - "kleinbottle" ; - CL_WeaponEntity_SetModel(viewmodel, s, true); -} -#endif -#ifdef SVQC -void tuba_instrument_send(entity this, int instr) -{ - msg_entity = this; - int chan = MSG_ONE; - WriteHeader(chan, tuba_instrument); - WriteByte(chan, instr); -} -SPECTATE_COPY() -{ - if (this.tuba_instrument != spectatee.tuba_instrument) - tuba_instrument_send(this, this.tuba_instrument = spectatee.tuba_instrument); -} METHOD(Tuba, wr_reload, void(Tuba this, entity actor, .entity weaponentity)) { // switch to alternate instruments :) if (actor.(weaponentity).state == WS_READY) { - switch (actor.tuba_instrument) + switch (actor.(weaponentity).tuba_instrument) { case 0: - actor.tuba_instrument = 1; - actor.weaponname = "akordeon"; + actor.(weaponentity).tuba_instrument = 1; + actor.(weaponentity).weaponname = "akordeon"; break; case 1: - actor.tuba_instrument = 2; - actor.weaponname = "kleinbottle"; + actor.(weaponentity).tuba_instrument = 2; + actor.(weaponentity).weaponname = "kleinbottle"; break; case 2: - actor.tuba_instrument = 0; - actor.weaponname = "tuba"; + actor.(weaponentity).tuba_instrument = 0; + actor.(weaponentity).weaponname = "tuba"; break; } - tuba_instrument_send(actor, actor.tuba_instrument); - W_SetupShot(actor, weaponentity, false, 0, SND_Null, 0, 0); + int hittype = 0; + if(actor.(weaponentity).tuba_instrument & 1) + hittype |= HITTYPE_SECONDARY; + if(actor.(weaponentity).tuba_instrument & 2) + hittype |= HITTYPE_BOUNCE; + W_SetupShot(actor, weaponentity, false, 0, SND_Null, 0, 0, hittype | WEP_TUBA.m_id); Send_Effect(EFFECT_TELEPORT, w_shotorg, '0 0 0', 1); actor.(weaponentity).state = WS_INUSE; weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, 0.5, w_ready); @@ -459,8 +395,8 @@ METHOD(Tuba, wr_reload, void(Tuba this, entity actor, .entity weaponentity)) #ifdef SVQC // infinite ammo -METHOD(Tuba, wr_checkammo1, bool(Tuba this, entity actor)) { return true; } -METHOD(Tuba, wr_checkammo2, bool(Tuba this, entity actor)) { return true; } +METHOD(Tuba, wr_checkammo1, bool(Tuba this, entity actor, .entity weaponentity)) { return true; } +METHOD(Tuba, wr_checkammo2, bool(Tuba this, entity actor, .entity weaponentity)) { return true; } METHOD(Tuba, wr_suicidemessage, Notification(Tuba this)) { @@ -481,6 +417,15 @@ METHOD(Tuba, wr_killmessage, Notification(Tuba this)) return WEAPON_TUBA_MURDER; } +#elif defined(CSQC) + +METHOD(Tuba, wr_viewmodel, string(Tuba this, entity wep)) +{ + return (wep.tuba_instrument == 0) ? "tuba" : + (wep.tuba_instrument == 1) ? "akordeon" : + "kleinbottle"; +} + #endif #ifdef CSQC @@ -491,13 +436,6 @@ const int TUBA_MIN = -18; const int TUBA_MAX = 27; const int TUBA_INSTRUMENTS = 3; -entityclass(Tuba); -class(Tuba) .int note; -class(Tuba) .bool tuba_attenuate; -class(Tuba) .float tuba_volume; -class(Tuba) .float tuba_volume_initial; -class(Tuba) .int tuba_instrument; - int Tuba_PitchStep; void tubasound(entity e, bool restart) @@ -516,23 +454,23 @@ void tubasound(entity e, bool restart) if (restart) { snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep); } - speed1 = pow(2.0, (m - Tuba_PitchStep) / 12.0); + speed1 = (2.0 ** ((m - Tuba_PitchStep) / 12.0)); } else if (e.note - m + Tuba_PitchStep > TUBA_MAX) { if (restart) { snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m); } - speed1 = pow(2.0, m / 12.0); + speed1 = (2.0 ** (m / 12.0)); } else { if (restart) { snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m); } vol1 = cos(M_PI_2 * m / Tuba_PitchStep); - speed1 = pow(2.0, m / 12.0); + speed1 = (2.0 ** (m / 12.0)); if (restart) { snd2 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep); } vol2 = sin(M_PI_2 * m / Tuba_PitchStep); - speed2 = pow(2.0, (m - Tuba_PitchStep) / 12.0); + speed2 = (2.0 ** ((m - Tuba_PitchStep) / 12.0)); } } else if (restart) { snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note); @@ -618,9 +556,7 @@ NET_HANDLE(ENT_CLIENT_TUBANOTE, bool isNew) } if (f & 2) { - this.enemy.origin_x = ReadCoord(); - this.enemy.origin_y = ReadCoord(); - this.enemy.origin_z = ReadCoord(); + this.enemy.origin = ReadVector(); setorigin(this.enemy, this.enemy.origin); if (this.enemy.enemy) { setorigin(this.enemy.enemy, this.enemy.origin); @@ -657,4 +593,3 @@ PRECACHE(Tuba) } #endif -#endif