X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fcommon%2Fweapons%2Fall.qc;h=10d5bd183c5432b96ae64dcca0d2a5d1b8d607b8;hp=e430ec2e78c252dea99cfc5c8fdfcc1a874bce8a;hb=90d9f7c775306324957323d53d5a4ad995d999e3;hpb=2dbcd3c5a4a458b9e83f3b037ca1d951f73755c3 diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index e430ec2e78..10d5bd183c 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -59,11 +59,11 @@ WepSet _WepSet_FromWeapon(int a) { a -= WEP_FIRST; - if (Weapons_MAX > 24) + if (REGISTRY_MAX(Weapons) > 24) if (a >= 24) { a -= 24; - if (Weapons_MAX > 48) + if (REGISTRY_MAX(Weapons) > 48) if (a >= 24) { a -= 24; @@ -76,8 +76,8 @@ WepSet _WepSet_FromWeapon(int a) #ifdef SVQC void WriteWepSet(float dst, WepSet w) { - if (Weapons_MAX > 48) WriteInt72_t(dst, w); - else if (Weapons_MAX > 24) WriteInt48_t(dst, w); + if (REGISTRY_MAX(Weapons) > 48) WriteInt72_t(dst, w); + else if (REGISTRY_MAX(Weapons) > 24) WriteInt48_t(dst, w); else WriteInt24_t(dst, w.x); } #endif @@ -92,8 +92,8 @@ WepSet _WepSet_FromWeapon(int a) } WepSet ReadWepSet() { - if (Weapons_MAX > 48) return ReadInt72_t(); - if (Weapons_MAX > 24) return ReadInt48_t(); + if (REGISTRY_MAX(Weapons) > 48) return ReadInt72_t(); + if (REGISTRY_MAX(Weapons) > 24) return ReadInt48_t(); return ReadInt24_t() * '1 0 0'; } #endif @@ -107,7 +107,7 @@ string W_NameWeaponOrder_MapFunc(string s) int i = stof(s); if (s == "0" || i) { - entity wi = Weapons_from(i); + entity wi = REGISTRY_GET(Weapons, i); if (wi != WEP_Null) return wi.netname; } return s; @@ -123,6 +123,8 @@ string W_UndeprecateName(string s) case "minstanex": return "vaporizer"; case "grenadelauncher": return "mortar"; case "uzi": return "machinegun"; + case "hmg": return "okhmg"; + case "rpc": return "okrpc"; default: return s; } } @@ -142,7 +144,7 @@ string W_NumberWeaponOrder(string order) return mapPriorityList(order, W_NumberWeaponOrder_MapFunc); } -float W_FixWeaponOrder_BuildImpulseList_buf[Weapons_MAX]; +float W_FixWeaponOrder_BuildImpulseList_buf[REGISTRY_MAX(Weapons)]; string W_FixWeaponOrder_BuildImpulseList_order; void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass) { @@ -154,9 +156,9 @@ void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass) float W_FixWeaponOrder_BuildImpulseList_cmp(int i, int j, entity pass) { int si = W_FixWeaponOrder_BuildImpulseList_buf[i]; - Weapon e1 = Weapons_from(si); + Weapon e1 = REGISTRY_GET(Weapons, si); int sj = W_FixWeaponOrder_BuildImpulseList_buf[j]; - Weapon e2 = Weapons_from(sj); + Weapon e2 = REGISTRY_GET(Weapons, sj); int d = (e1.impulse + 9) % 10 - (e2.impulse + 9) % 10; if (d != 0) return -d; // high impulse first! return strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), @@ -192,9 +194,8 @@ string W_FixWeaponOrder_ForceComplete(string order) return W_FixWeaponOrder(order, 1); } -void W_RandomWeapons(entity e, int n) +WepSet W_RandomWeapons(entity e, WepSet remaining, int n) { - WepSet remaining = e.weapons; WepSet result = '0 0 0'; for (int j = 0; j < n; ++j) { @@ -207,35 +208,49 @@ void W_RandomWeapons(entity e, int n) result |= WepSet_FromWeapon(w); remaining &= ~WepSet_FromWeapon(w); } - e.weapons = result; + return result; } string GetAmmoPicture(int ammotype) { switch (ammotype) { - case RESOURCE_SHELLS: return ITEM_Shells.m_icon; - case RESOURCE_BULLETS: return ITEM_Bullets.m_icon; - case RESOURCE_ROCKETS: return ITEM_Rockets.m_icon; - case RESOURCE_CELLS: return ITEM_Cells.m_icon; - case RESOURCE_PLASMA: return ITEM_Plasma.m_icon; - case RESOURCE_FUEL: return ITEM_JetpackFuel.m_icon; + case RES_SHELLS: return ITEM_Shells.m_icon; + case RES_BULLETS: return ITEM_Bullets.m_icon; + case RES_ROCKETS: return ITEM_Rockets.m_icon; + case RES_CELLS: return ITEM_Cells.m_icon; + case RES_PLASMA: return ITEM_Plasma.m_icon; + case RES_FUEL: return ITEM_JetpackFuel.m_icon; default: return ""; // wtf, no ammo type? } } +string GetAmmoName(int ammotype) +{ + switch (ammotype) + { + case RES_SHELLS: return ITEM_Shells.m_name; + case RES_BULLETS: return ITEM_Bullets.m_name; + case RES_ROCKETS: return ITEM_Rockets.m_name; + case RES_CELLS: return ITEM_Cells.m_name; + case RES_PLASMA: return ITEM_Plasma.m_name; + case RES_FUEL: return ITEM_JetpackFuel.m_name; + default: return "batteries"; + } +} + #ifdef CSQC int GetAmmoTypeFromNum(int i) { switch (i) { - case 0: return RESOURCE_SHELLS; - case 1: return RESOURCE_BULLETS; - case 2: return RESOURCE_ROCKETS; - case 3: return RESOURCE_CELLS; - case 4: return RESOURCE_PLASMA; - case 5: return RESOURCE_FUEL; - default: return RESOURCE_NONE; + case 0: return RES_SHELLS; + case 1: return RES_BULLETS; + case 2: return RES_ROCKETS; + case 3: return RES_CELLS; + case 4: return RES_PLASMA; + case 5: return RES_FUEL; + default: return RES_NONE; } } @@ -243,12 +258,12 @@ int GetAmmoStat(int ammotype) { switch (ammotype) { - case RESOURCE_SHELLS: return STAT_SHELLS; - case RESOURCE_BULLETS: return STAT_NAILS; - case RESOURCE_ROCKETS: return STAT_ROCKETS; - case RESOURCE_CELLS: return STAT_CELLS; - case RESOURCE_PLASMA: return STAT_PLASMA.m_id; - case RESOURCE_FUEL: return STAT_FUEL.m_id; + case RES_SHELLS: return STAT_SHELLS; + case RES_BULLETS: return STAT_NAILS; + case RES_ROCKETS: return STAT_ROCKETS; + case RES_CELLS: return STAT_CELLS; + case RES_PLASMA: return STAT_PLASMA.m_id; + case RES_FUEL: return STAT_FUEL.m_id; default: return -1; } } @@ -293,24 +308,21 @@ vector shotorg_adjustfromclient(vector vecs, float y_is_right, float algn) vector shotorg_adjust_values(vector vecs, bool y_is_right, bool visual, int algn) { -#ifdef SVQC string s; -#endif if (visual) { vecs = shotorg_adjustfromclient(vecs, y_is_right, algn); } -#ifdef SVQC - else if (autocvar_g_shootfromeye) + else if (STAT(SHOOTFROMEYE)) { vecs.y = vecs.z = 0; } - else if (autocvar_g_shootfromcenter) + else if (STAT(SHOOTFROMCENTER)) { vecs.y = 0; vecs.z -= 2; } - else if ((s = autocvar_g_shootfromfixedorigin) != "") + else if ((s = G_SHOOTFROMFIXEDORIGIN) != "") { vector v = stov(s); if (y_is_right) v.y = -v.y; @@ -318,7 +330,6 @@ vector shotorg_adjust_values(vector vecs, bool y_is_right, bool visual, int algn vecs.y = v.y; vecs.z = v.z; } -#endif else // just do the same as top { vecs = shotorg_adjustfromclient(vecs, y_is_right, algn); @@ -531,7 +542,7 @@ void CL_WeaponEntity_SetModel(entity this, string name, bool _anim) // make them match perfectly #ifdef SVQC // null during init - if (this.owner) this.owner.stat_shotorg = compressed_shotorg; + if (this.owner) STAT(SHOTORG, this.owner) = compressed_shotorg; this.movedir = decompressShotOrigin(compressed_shotorg); #else this.movedir = decompressShotOrigin(compressed_shotorg); @@ -554,17 +565,27 @@ REGISTER_NET_TEMP(wframe) #ifdef CSQC NET_HANDLE(wframe, bool isNew) { - vector a; - a.x = ReadCoord(); - a.y = ReadCoord(); - a.z = ReadCoord(); + int fr = ReadByte(); + float t = ReadFloat(); int slot = ReadByte(); bool restartanim = ReadByte(); entity wepent = viewmodels[slot]; - if(a.x == wepent.anim_idle_x) // we don't need to enforce idle animation - wepent.animstate_looping = false; + if(fr == WFRAME_IDLE) + wepent.animstate_looping = false; // we don't need to enforce idle animation else + { + vector a = '0 0 0'; + switch(fr) + { + default: + case WFRAME_IDLE: a = wepent.anim_idle; break; + case WFRAME_FIRE1: a = wepent.anim_fire1; break; + case WFRAME_FIRE2: a = wepent.anim_fire2; break; + case WFRAME_RELOAD: a = wepent.anim_reload; break; + } + a.z *= t; anim_set(wepent, a, !restartanim, restartanim, restartanim); + } wepent.state = ReadByte(); wepent.weapon_nextthink = ReadFloat(); switch (wepent.state) @@ -584,15 +605,14 @@ NET_HANDLE(wframe, bool isNew) #endif #ifdef SVQC -void wframe_send(entity actor, entity weaponentity, vector a, bool restartanim) +void wframe_send(entity actor, entity weaponentity, int wepframe, float attackrate, bool restartanim) { if (!IS_REAL_CLIENT(actor)) return; int channel = MSG_ONE; msg_entity = actor; WriteHeader(channel, wframe); - WriteCoord(channel, a.x); - WriteCoord(channel, a.y); - WriteCoord(channel, a.z); + WriteByte(channel, wepframe); + WriteFloat(channel, attackrate); WriteByte(channel, weaponslot(weaponentity.weaponentity_fld)); WriteByte(channel, restartanim); WriteByte(channel, weaponentity.state); @@ -640,19 +660,68 @@ CLIENT_COMMAND(weapon_find, "Show spawn locations of a weapon") }); } default: - { - LOG_INFOF("Incorrect parameters for ^2%s^7", "weapon_find"); - } + LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0)); case CMD_REQUEST_USAGE: { - LOG_INFO("Usage:^3 cl_cmd weapon_find weapon"); - LOG_INFO(" Where 'weapon' is the lowercase weapon name, 'all' or 'unowned'."); + LOG_HELP("Usage:^3 cl_cmd weapon_find weapon"); + LOG_HELP(" Where 'weapon' is the lowercase weapon name, 'all' or 'unowned'."); return; } } } #endif +REGISTER_NET_TEMP(w_muzzleflash) + +#ifdef SVQC +void W_MuzzleFlash(entity actor, .entity weaponentity, entity eff, vector shotorg, vector shotdir) +{ + Send_Effect_Except(eff, shotorg, shotdir * 1000, 1, actor); + + FOREACH_CLIENT(it == actor || (IS_SPEC(it) && it.enemy == actor), + { + if(!IS_REAL_CLIENT(it)) + continue; + int channel = MSG_ONE; + msg_entity = it; + WriteHeader(channel, w_muzzleflash); + WriteByte(channel, weaponslot(weaponentity)); + (Effects_COUNT >= 255) + ? WriteShort(channel, eff.m_id) + : WriteByte(channel, eff.m_id); + }); +} +#elif defined(CSQC) +NET_HANDLE(w_muzzleflash, bool isNew) +{ + return = true; + int slot = ReadByte(); + int net_name = (Effects_COUNT >= 255) ? ReadShort() : ReadByte(); + + if(!autocvar_r_drawviewmodel || autocvar_chase_active) return; + entity wepent = viewmodels[slot]; + entity eff = Effects_from(net_name); + + vector viewangles = getpropertyvec(VF_CL_VIEWANGLES); + vector forward, right, up; + MAKE_VECTORS(viewangles, forward, right, up); + + // get the local player entity to calculate shot origin + entity rlplayer = CSQCModel_server2csqc(player_localentnum - 1); + if(!rlplayer) + rlplayer = csqcplayer; // fall back to the global + + vector md = wepent.movedir; + vector vecs = ((md.x > 0) ? md : '0 0 0'); + vector dv = right * -vecs.y + up * vecs.z; + vector org = rlplayer.origin + rlplayer.view_ofs + dv; + tracebox(org, '0 0 0', '0 0 0', org + forward * (vecs.x + 1), MOVE_NORMAL, rlplayer); + org = trace_endpos - forward * 1; + + pointparticles(eff, org, forward * 1000, 1); +} +#endif + #endif