From: Mario Date: Sat, 1 Oct 2016 10:34:19 +0000 (+1000) Subject: Unhardcode a few more weapon entity checks X-Git-Tag: xonotic-v0.8.2~326^2~77^2~1 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=b9c4f697a81bb47446239bdfa8ec1fc6083935b5;hp=a18210910c6400ddceffe84b446a7f3c33d4ac87 Unhardcode a few more weapon entity checks --- diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 27921b182d..ac58fd7927 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -451,12 +451,17 @@ vector GetCurrentFov(float fov) zoomspeed = 3.5; zoomdir = button_zoom; - entity wepent = viewmodels[0]; // TODO: unhardcode if(hud == HUD_NORMAL && !spectatee_status) - if(wepent.switchweapon == wepent.activeweapon) - if((wepent.activeweapon == WEP_VORTEX && !WEP_CVAR(vortex, secondary)) || (wepent.activeweapon == WEP_RIFLE && !WEP_CVAR(rifle, secondary))) // do NOT use switchweapon here - zoomdir += button_attack2; + { + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + entity wepent = viewmodels[slot]; + if(wepent.switchweapon == wepent.activeweapon) + if((wepent.activeweapon == WEP_VORTEX && !WEP_CVAR(vortex, secondary)) || (wepent.activeweapon == WEP_RIFLE && !WEP_CVAR(rifle, secondary))) // do NOT use switchweapon here + zoomdir += button_attack2; + } + } if(spectatee_status > 0 || isdemo()) { if(spectatorbutton_zoom) @@ -1943,7 +1948,14 @@ void CSQC_UpdateView(entity this, float w, float h) if(autocvar_cl_reticle) { - Weapon wep = wepent.activeweapon; + bool wep_zoomed = false; + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + entity wepe = viewmodels[slot]; + Weapon wep = wepe.activeweapon; + if(wep != WEP_Null && wep.wr_zoom) + wep_zoomed += wep.wr_zoom(wep, NULL); + } // Draw the aiming reticle for weapons that use it // reticle_type is changed to the item we are zooming / aiming with, to decide which reticle to use // It must be a persisted float for fading out to work properly (you let go of the zoom button for @@ -1953,7 +1965,7 @@ void CSQC_UpdateView(entity this, float w, float h) // no zoom reticle while dead reticle_type = 0; } - else if(wep.wr_zoomreticle(wep) && autocvar_cl_reticle_weapon) + else if(wep_zoomed && autocvar_cl_reticle_weapon) { if(reticle_image != "") { reticle_type = 2; } else { reticle_type = 0; } diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index a83629f969..9d7d11ddba 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -112,8 +112,8 @@ CLASS(Weapon, Object) METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) {} /** (ALL) dump weapon cvars to config in data directory (see: sv_cmd dumpweapons) */ METHOD(Weapon, wr_config, void(Weapon this)) {} - /** (CLIENT) weapon specific zoom reticle */ - METHOD(Weapon, wr_zoomreticle, bool(Weapon this)) { + /** (BOTH) weapon specific zoom reticle */ + METHOD(Weapon, wr_zoom, bool(Weapon this, entity actor)) { // no weapon specific image for this weapon return false; } diff --git a/qcsrc/common/weapons/weapon/rifle.qc b/qcsrc/common/weapons/weapon/rifle.qc index 6dbcd31c28..4794e866a0 100644 --- a/qcsrc/common/weapons/weapon/rifle.qc +++ b/qcsrc/common/weapons/weapon/rifle.qc @@ -241,6 +241,10 @@ METHOD(Rifle, wr_killmessage, Notification(entity thiswep)) return WEAPON_RIFLE_MURDER; } } +METHOD(Rifle, wr_zoom, bool(entity thiswep, entity actor)) +{ + return PHYS_INPUT_BUTTON_ATCK2(actor) && WEP_CVAR(rifle, secondary) == 0; +} #endif #ifdef CSQC @@ -262,7 +266,7 @@ METHOD(Rifle, wr_init, void(entity thiswep)) precache_pic("gfx/reticle_nex"); } } -METHOD(Rifle, wr_zoomreticle, bool(entity thiswep)) +METHOD(Rifle, wr_zoom, bool(entity thiswep, entity actor)) { if(button_zoom || zoomscript_caught) { diff --git a/qcsrc/common/weapons/weapon/vaporizer.qc b/qcsrc/common/weapons/weapon/vaporizer.qc index 5a9a8735fb..0c0b5b0c3f 100644 --- a/qcsrc/common/weapons/weapon/vaporizer.qc +++ b/qcsrc/common/weapons/weapon/vaporizer.qc @@ -501,7 +501,7 @@ METHOD(Vaporizer, wr_init, void(entity thiswep)) precache_pic("gfx/reticle_nex"); } } -METHOD(Vaporizer, wr_zoomreticle, bool(entity thiswep)) +METHOD(Vaporizer, wr_zoom, bool(entity thiswep, entity actor)) { if(button_zoom || zoomscript_caught) { diff --git a/qcsrc/common/weapons/weapon/vortex.qc b/qcsrc/common/weapons/weapon/vortex.qc index 331885b329..1fbb901d51 100644 --- a/qcsrc/common/weapons/weapon/vortex.qc +++ b/qcsrc/common/weapons/weapon/vortex.qc @@ -384,6 +384,10 @@ METHOD(Vortex, wr_killmessage, Notification(entity thiswep)) { return WEAPON_VORTEX_MURDER; } +METHOD(Vortex, wr_zoom, bool(entity thiswep, entity actor)) +{ + return PHYS_INPUT_BUTTON_ATCK2(actor); +} #endif #ifdef CSQC @@ -403,7 +407,7 @@ METHOD(Vortex, wr_init, void(entity thiswep)) precache_pic("gfx/reticle_nex"); } } -METHOD(Vortex, wr_zoomreticle, bool(entity thiswep)) +METHOD(Vortex, wr_zoom, bool(entity thiswep, entity actor)) { if(button_zoom || zoomscript_caught || (!WEP_CVAR(vortex, secondary) && button_attack2)) { diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 205eb0cb39..0d4d1e6204 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -2474,13 +2474,16 @@ void PlayerPreThink (entity this) } // WEAPONTODO: Add weapon request for this - .entity weaponentity = weaponentities[0]; // TODO: unhardcode if (!zoomstate_set) { - SetZoomState(this, - PHYS_INPUT_BUTTON_ZOOM(this) || PHYS_INPUT_BUTTON_ZOOMSCRIPT(this) - || (PHYS_INPUT_BUTTON_ATCK2(this) && this.(weaponentity).m_weapon == WEP_VORTEX) - || (PHYS_INPUT_BUTTON_ATCK2(this) && this.(weaponentity).m_weapon == WEP_RIFLE && WEP_CVAR(rifle, secondary) == 0) - ); + bool wep_zoomed = false; + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + Weapon thiswep = this.(weaponentity).m_weapon; + if(thiswep != WEP_Null && thiswep.wr_zoom) + wep_zoomed += thiswep.wr_zoom(thiswep, this); + } + SetZoomState(this, PHYS_INPUT_BUTTON_ZOOM(this) || PHYS_INPUT_BUTTON_ZOOMSCRIPT(this) || wep_zoomed); } if (this.teamkill_soundtime && time > this.teamkill_soundtime) @@ -2503,6 +2506,7 @@ void PlayerPreThink (entity this) // WEAPONTODO: Move into weaponsystem somehow // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring + .entity weaponentity = weaponentities[0]; if (this.(weaponentity).m_weapon == WEP_Null) this.clip_load = this.clip_size = 0; } diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index 531ad6f530..6b968bc800 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -117,14 +117,15 @@ void GiveFrags (entity attacker, entity targ, float f, int deathtype) string AppendItemcodes(string s, entity player) { - .entity weaponentity = weaponentities[0]; // TODO: unhardcode - - int w = player.(weaponentity).m_weapon.m_id; - //if(w == 0) - // w = player.switchweapon; - if(w == 0) - w = player.(weaponentity).cnt; // previous weapon! - s = strcat(s, ftos(w)); + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + int w = player.(weaponentity).m_weapon.m_id; + if(w == 0) + w = player.(weaponentity).cnt; // previous weapon + if(w != 0 || slot == 0) + s = strcat(s, ftos(w)); + } if(time < player.strength_finished) s = strcat(s, "S"); if(time < player.invincible_finished)