From: TimePath Date: Sat, 5 Dec 2015 09:57:09 +0000 (+1100) Subject: Weapons: make WepSet_FromWeapon more verbose, making Weapons_from uses more obvious X-Git-Tag: xonotic-v0.8.2~1551 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=641ed8c088e442fd907fd864c5934ae050a0c9c7;p=xonotic%2Fxonotic-data.pk3dir.git Weapons: make WepSet_FromWeapon more verbose, making Weapons_from uses more obvious --- diff --git a/qcsrc/client/hud/hud.qh b/qcsrc/client/hud/hud.qh index 764a526b9..d30a87273 100644 --- a/qcsrc/client/hud/hud.qh +++ b/qcsrc/client/hud/hud.qh @@ -77,8 +77,8 @@ float complain_weapon_time; int ps_primary, ps_secondary; int ts_primary, ts_secondary; -int last_switchweapon; -int last_activeweapon; +Weapon last_switchweapon; +Weapon last_activeweapon; float weapontime; float weaponprevtime; diff --git a/qcsrc/client/hud/panel/ammo.qc b/qcsrc/client/hud/panel/ammo.qc index 80cfdd69c..6c37aa13a 100644 --- a/qcsrc/client/hud/panel/ammo.qc +++ b/qcsrc/client/hud/panel/ammo.qc @@ -158,6 +158,7 @@ void HUD_Ammo() ammo_size.y = newSize; } + Weapon wep = switchweapon; int i; bool infinite_ammo = (getstati(STAT_ITEMS, 0, 24) & IT_UNLIMITED_WEAPON_AMMO); row = column = 0; @@ -172,7 +173,7 @@ void HUD_Ammo() DrawAmmoItem( pos, ammo_size, - (get_weaponinfo(switchweapon)).ammo_field, + wep.ammo_field, true, infinite_ammo ); @@ -196,7 +197,7 @@ void HUD_Ammo() pos + eX * column * (ammo_size.x + offset.x) + eY * row * (ammo_size.y + offset.y), ammo_size, ammotype, - ((get_weaponinfo(switchweapon)).ammo_field == ammotype), + (wep.ammo_field == ammotype), infinite_ammo ); diff --git a/qcsrc/client/hud/panel/notify.qc b/qcsrc/client/hud/panel/notify.qc index 821c993fa..3c4b9c105 100644 --- a/qcsrc/client/hud/panel/notify.qc +++ b/qcsrc/client/hud/panel/notify.qc @@ -106,7 +106,7 @@ void HUD_Notify() { attacker = sprintf(_("Player %d"), count + 1); victim = sprintf(_("Player %d"), count + 2); - icon = get_weaponinfo(min(WEP_FIRST + count * 2, WEP_LAST)).model2; + icon = Weapons_from(min(WEP_FIRST + count * 2, WEP_LAST)).model2; alpha = bound(0, 1.2 - count / entry_count, 1); } else diff --git a/qcsrc/client/hud/panel/weapons.qc b/qcsrc/client/hud/panel/weapons.qc index 818663242..8970332cd 100644 --- a/qcsrc/client/hud/panel/weapons.qc +++ b/qcsrc/client/hud/panel/weapons.qc @@ -77,18 +77,10 @@ void HUD_Weapons() weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " "); weapon_cnt = 0; - for(i = WEP_FIRST; i <= WEP_LAST; ++i) - { - setself(get_weaponinfo(i)); - if(self.impulse >= 0) - { - weaponorder[weapon_cnt] = self; - ++weapon_cnt; - } - } + FOREACH(Weapons, it != WEP_Null && it.impulse >= 0, LAMBDA(weaponorder[weapon_cnt++] = it)); for(i = weapon_cnt; i < Weapons_MAX; ++i) - weaponorder[i] = world; - heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world); + weaponorder[i] = NULL; + heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, NULL); weaponorder_cmp_str = string_null; } @@ -100,7 +92,7 @@ void HUD_Weapons() { if(!weapons_stat) for(i = WEP_FIRST; i <= WEP_LAST; i += floor((WEP_LAST-WEP_FIRST)/5)) - weapons_stat |= WepSet_FromWeapon(i); + weapons_stat |= WepSet_FromWeapon(Weapons_from(i)); #if 0 /// debug code @@ -109,7 +101,7 @@ void HUD_Weapons() weapons_stat = '0 0 0'; float countw = 1 + floor((floor(time * cvar("wep_add"))) % (Weapons_COUNT - 1)); for(i = WEP_FIRST; i <= countw; ++i) - weapons_stat |= WepSet_FromWeapon(i); + weapons_stat |= WepSet_FromWeapon(Weapons_from(i)); } #endif } @@ -126,7 +118,7 @@ void HUD_Weapons() // do we own this weapon? weapon_count = 0; for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i) - if((weapons_stat & WepSet_FromWeapon(weaponorder[i].weapon)) || (weaponorder[i].weapon == complain_weapon)) + if((weapons_stat & WepSet_FromWeapon(Weapons_from(weaponorder[i].weapon))) || (weaponorder[i].weapon == complain_weapon)) ++weapon_count; @@ -140,11 +132,10 @@ void HUD_Weapons() // get the all-weapons layout int nHidden = 0; WepSet weapons_stat = WepSet_GetFromStat(); - for (int i = WEP_FIRST; i <= WEP_LAST; ++i) { - Weapon w = get_weaponinfo(i); - if (weapons_stat & w.m_wepset) continue; - if (w.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1; - } + FOREACH(Weapons, it != WEP_Null, LAMBDA( + if (weapons_stat & it.m_wepset) continue; + if (it.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1; + )); vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1) - nHidden, padded_panel_size, aspect); columns = table_size.x; rows = table_size.y; @@ -348,14 +339,14 @@ void HUD_Weapons() // retrieve information about the current weapon to be drawn setself(weaponorder[i]); weapon_id = self.impulse; - isCurrent = (self.weapon == switchweapon); + isCurrent = (self.weapon == switchweapon.m_id); // skip if this weapon doesn't exist if(!self || weapon_id < 0) { continue; } // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon if(autocvar_hud_panel_weapons_onlyowned) - if (!((weapons_stat & WepSet_FromWeapon(self.weapon)) || (self.weapon == complain_weapon))) + if (!((weapons_stat & WepSet_FromWeapon(Weapons_from(self.weapon))) || (self.weapon == complain_weapon))) continue; // figure out the drawing position of weapon @@ -379,7 +370,7 @@ void HUD_Weapons() } // drawing all the weapon items - if(weapons_stat & WepSet_FromWeapon(self.weapon)) + if(weapons_stat & WepSet_FromWeapon(Weapons_from(self.weapon))) { // draw the weapon image if(isCurrent) diff --git a/qcsrc/client/main.qh b/qcsrc/client/main.qh index a6aebc61c..91d5de09b 100644 --- a/qcsrc/client/main.qh +++ b/qcsrc/client/main.qh @@ -2,6 +2,7 @@ #define CLIENT_MAIN_H #include "../common/constants.qh" +#include "../common/weapons/all.qh" // -------------------------------------------------------------------------- // MENU Functionality @@ -94,9 +95,9 @@ bool button_zoom; bool spectatorbutton_zoom; bool button_attack2; -int activeweapon; -int switchingweapon; -#define switchweapon STAT(SWITCHWEAPON) +Weapon activeweapon; +Weapon switchingweapon; +Weapon switchweapon; float current_viewzoom; float zoomin_effect; float warmup_stage; diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index 1f864a540..4d9a8c69d 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -1001,17 +1001,15 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size) WepSet weapons_inmap = WepSet_GetFromStat_InMap(); float initial_posx = pos.x; int disownedcnt = 0; - for (int i = WEP_FIRST; i <= WEP_LAST; ++i) { - Weapon e = get_weaponinfo(i); - setself(e); - if (!self.weapon) continue; + FOREACH(Weapons, it != WEP_Null, LAMBDA( + if (!it.weapon) continue; int weapon_stats = weapon_accuracy[i - WEP_FIRST]; - WepSet set = e.m_wepset; + WepSet set = it.m_wepset; if (weapon_stats < 0 && !(weapons_stat & set || weapons_inmap & set)) ++disownedcnt; - } + )); int weapon_cnt = (Weapons_COUNT - 1) - disownedcnt; if (weapon_cnt <= 0) return pos; @@ -1065,13 +1063,11 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size) vector tmpos = pos; int column = 0; - for (int i = WEP_FIRST; i <= WEP_LAST; ++i) { - Weapon e = get_weaponinfo(i); - setself(e); - if (!self.weapon) continue; + FOREACH(Weapons, it != WEP_Null, LAMBDA( + if (!it.weapon) continue; int weapon_stats = weapon_accuracy[i - WEP_FIRST]; - WepSet set = e.m_wepset; + WepSet set = it.m_wepset; if (weapon_stats < 0 && !(weapons_stat & set || weapons_inmap & set)) continue; @@ -1082,7 +1078,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size) weapon_alpha = 0.2 * scoreboard_alpha_fg; // weapon icon - drawpic_aspect_skin(tmpos, self.model2, '1 0 0' * weapon_width + '0 1 0' * weapon_height, '1 1 1', weapon_alpha, DRAWFLAG_NORMAL); + drawpic_aspect_skin(tmpos, it.model2, '1 0 0' * weapon_width + '0 1 0' * weapon_height, '1 1 1', weapon_alpha, DRAWFLAG_NORMAL); // the accuracy if (weapon_stats >= 0) { weapons_with_stats += 1; @@ -1107,7 +1103,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size) pos.y += height; } ++column; - } + )); if (weapons_with_stats) average_accuracy = floor((average_accuracy * 100 / weapons_with_stats) + 0.5); diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 112aec6c2..85fea0d1b 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -276,7 +276,7 @@ void viewmodel_draw(entity this) float a = this.alpha; int c = stof(getplayerkeyvalue(current_player, "colors")); vector g; - Weapon wep = Weapons_from(activeweapon); + Weapon wep = activeweapon; if (!(g = wep.wr_glow(wep))) g = colormapPaletteColor(c & 0x0F, true) * 2; entity me = CSQCModel_server2csqc(player_localentnum - 1); int fx = ((me.csqcmodel_effects & EFMASK_CHEAP) @@ -293,7 +293,7 @@ void viewmodel_draw(entity this) } { static string name_last; - string name = Weapons_from(activeweapon).mdl; + string name = wep.mdl; if (name != name_last) { name_last = name; @@ -348,7 +348,7 @@ void Porto_Draw(entity this) vector p, dir, ang, q, nextdir; float portal_number, portal1_idx; - if(activeweapon != WEP_PORTO.m_id || spectatee_status || gametype == MAPINFO_TYPE_NEXBALL) + if(activeweapon != WEP_PORTO || spectatee_status || gametype == MAPINFO_TYPE_NEXBALL) return; if(g_balance_porto_secondary) return; @@ -448,7 +448,7 @@ vector GetCurrentFov(float fov) zoomdir = button_zoom; if(hud == HUD_NORMAL) if(switchweapon == activeweapon) - if((activeweapon == WEP_VORTEX.m_id && vortex_scope) || (activeweapon == WEP_RIFLE.m_id && rifle_scope)) // do NOT use switchweapon here + if((activeweapon == WEP_VORTEX && vortex_scope) || (activeweapon == WEP_RIFLE && rifle_scope)) // do NOT use switchweapon here zoomdir += button_attack2; if(spectatee_status > 0 || isdemo()) { @@ -635,17 +635,17 @@ float TrueAimCheck() switch(activeweapon) // WEAPONTODO { - case WEP_TUBA.m_id: // no aim - case WEP_PORTO.m_id: // shoots from eye - case WEP_NEXBALL.m_id: // shoots from eye - case WEP_HOOK.m_id: // no trueaim - case WEP_MORTAR.m_id: // toss curve + case WEP_TUBA: // no aim + case WEP_PORTO: // shoots from eye + case WEP_NEXBALL: // shoots from eye + case WEP_HOOK: // no trueaim + case WEP_MORTAR: // toss curve return SHOTTYPE_HITWORLD; - case WEP_VORTEX.m_id: - case WEP_VAPORIZER.m_id: + case WEP_VORTEX: + case WEP_VAPORIZER: mv = MOVE_NORMAL; break; - case WEP_RIFLE.m_id: + case WEP_RIFLE: ta = trueaim_rifle; mv = MOVE_NORMAL; if(zoomscript_caught) @@ -654,19 +654,19 @@ float TrueAimCheck() return EnemyHitCheck(); } break; - case WEP_DEVASTATOR.m_id: // projectile has a size! + case WEP_DEVASTATOR: // projectile has a size! mi = '-3 -3 -3'; ma = '3 3 3'; break; - case WEP_FIREBALL.m_id: // projectile has a size! + case WEP_FIREBALL: // projectile has a size! mi = '-16 -16 -16'; ma = '16 16 16'; break; - case WEP_SEEKER.m_id: // projectile has a size! + case WEP_SEEKER: // projectile has a size! mi = '-2 -2 -2'; ma = '2 2 2'; break; - case WEP_ELECTRO.m_id: // projectile has a size! + case WEP_ELECTRO: // projectile has a size! mi = '0 0 -3'; ma = '0 0 -3'; break; @@ -813,7 +813,7 @@ void HitSound() static float hitsound_time_prev = 0; // HACK: the only way to get the arc to sound consistent with pitch shift is to ignore cl_hitsound_antispam_time - float arc_hack = activeweapon == WEP_ARC.m_id && autocvar_cl_hitsound >= 2; + float arc_hack = activeweapon == WEP_ARC && autocvar_cl_hitsound >= 2; if (arc_hack || COMPARE_INCREASING(time, hitsound_time_prev) > autocvar_cl_hitsound_antispam_time) { if (autocvar_cl_hitsound && unaccounted_damage) @@ -919,7 +919,7 @@ void HUD_Crosshair() if(autocvar_crosshair_per_weapon || (autocvar_crosshair_color_special == 1)) { - e = get_weaponinfo(switchingweapon); + e = switchingweapon; if(e) { if(autocvar_crosshair_per_weapon) @@ -1149,7 +1149,7 @@ void HUD_Crosshair() // handle the values - if (autocvar_crosshair_ring && activeweapon == WEP_VORTEX.m_id && vortex_charge && autocvar_crosshair_ring_vortex) // ring around crosshair representing velocity-dependent damage for the vortex + if (autocvar_crosshair_ring && activeweapon == WEP_VORTEX && vortex_charge && autocvar_crosshair_ring_vortex) // ring around crosshair representing velocity-dependent damage for the vortex { if (vortex_chargepool || use_vortex_chargepool) { use_vortex_chargepool = 1; @@ -1169,14 +1169,14 @@ void HUD_Crosshair() ring_rgb = wcross_color; ring_image = "gfx/crosshair_ring_nexgun.tga"; } - else if (autocvar_crosshair_ring && activeweapon == WEP_MINE_LAYER.m_id && minelayer_maxmines && autocvar_crosshair_ring_minelayer) + else if (autocvar_crosshair_ring && activeweapon == WEP_MINE_LAYER && minelayer_maxmines && autocvar_crosshair_ring_minelayer) { ring_value = bound(0, STAT(LAYED_MINES) / minelayer_maxmines, 1); // if you later need to use the count of bullets in another place, then add a float for it. For now, no need to. ring_alpha = autocvar_crosshair_ring_minelayer_alpha; ring_rgb = wcross_color; ring_image = "gfx/crosshair_ring.tga"; } - else if (activeweapon == WEP_HAGAR.m_id && STAT(HAGAR_LOAD) && autocvar_crosshair_ring_hagar) + else if (activeweapon == WEP_HAGAR && STAT(HAGAR_LOAD) && autocvar_crosshair_ring_hagar) { ring_value = bound(0, STAT(HAGAR_LOAD) / hagar_maxrockets, 1); ring_alpha = autocvar_crosshair_ring_hagar_alpha; @@ -1199,12 +1199,12 @@ void HUD_Crosshair() // Note: This is to stop Taoki from complaining that the image doesn't match all potential balances. // if a new image for another weapon is added, add the code (and its respective file/value) here - if ((activeweapon == WEP_RIFLE.m_id) && (weapon_clipsize == 80)) + if ((activeweapon == WEP_RIFLE) && (weapon_clipsize == 80)) ring_image = "gfx/crosshair_ring_rifle.tga"; else ring_image = "gfx/crosshair_ring.tga"; } - else if ( autocvar_crosshair_ring && autocvar_crosshair_ring_arc && arc_heat && activeweapon == WEP_ARC.m_id ) + else if ( autocvar_crosshair_ring && autocvar_crosshair_ring_arc && arc_heat && activeweapon == WEP_ARC ) { ring_value = arc_heat; ring_alpha = (1-arc_heat)*autocvar_crosshair_ring_arc_cold_alpha + @@ -1707,10 +1707,12 @@ void CSQC_UpdateView(float w, float h) ColorTranslateMode = autocvar_cl_stripcolorcodes; // currently switching-to weapon (for crosshair) - switchingweapon = STAT(SWITCHINGWEAPON); + switchingweapon = Weapons_from(STAT(SWITCHINGWEAPON)); // actually active weapon (for zoom) - activeweapon = getstati(STAT_ACTIVEWEAPON); + activeweapon = Weapons_from(getstati(STAT_ACTIVEWEAPON)); + + switchweapon = Weapons_from(STAT(SWITCHWEAPON)); f = (serverflags & SERVERFLAG_TEAMPLAY); if(f != teamplay) @@ -1739,7 +1741,7 @@ void CSQC_UpdateView(float w, float h) { last_activeweapon = activeweapon; - e = get_weaponinfo(activeweapon); + e = activeweapon; if(e.netname != "") localcmd(strcat("\ncl_hook_activeweapon ", e.netname), "\n"); else @@ -1872,7 +1874,7 @@ void CSQC_UpdateView(float w, float h) if(autocvar_cl_reticle) { - Weapon wep = get_weaponinfo(activeweapon); + Weapon wep = activeweapon; // 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 diff --git a/qcsrc/common/deathtypes/all.qh b/qcsrc/common/deathtypes/all.qh index dcf64b11f..3c953bcf9 100644 --- a/qcsrc/common/deathtypes/all.qh +++ b/qcsrc/common/deathtypes/all.qh @@ -40,7 +40,7 @@ const int DT_FIRST = BIT(13); #define DEATH_ISVEHICLE(t) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)).death_msgextra == "vehicle") #define DEATH_ISTURRET(t) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)).death_msgextra == "turret") #define DEATH_ISMONSTER(t) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)).death_msgextra == "monster") -#define DEATH_WEAPONOF(t) (DEATH_ISSPECIAL(t) ? WEP_Null : get_weaponinfo((t) & DEATH_WEAPONMASK)) +#define DEATH_WEAPONOF(t) (DEATH_ISSPECIAL(t) ? WEP_Null : Weapons_from((t) & DEATH_WEAPONMASK)) #define DEATH_ISWEAPON(t, w) (DEATH_WEAPONOF(t) == (w)) string Deathtype_Name(int deathtype); diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc b/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc index 8c8237aee..9cafd1a23 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc +++ b/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc @@ -1342,7 +1342,7 @@ void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float s for(i = WEP_FIRST; i <= WEP_LAST ; ++i) { // Find weapon - if(self.weapons & WepSet_FromWeapon(i)) + if(self.weapons & WepSet_FromWeapon(Weapons_from(i))) if(++c>=4) break; } diff --git a/qcsrc/common/mutators/mutator/new_toys/new_toys.qc b/qcsrc/common/mutators/mutator/new_toys/new_toys.qc index 5235e58e6..2a0df8c64 100644 --- a/qcsrc/common/mutators/mutator/new_toys/new_toys.qc +++ b/qcsrc/common/mutators/mutator/new_toys/new_toys.qc @@ -79,14 +79,14 @@ REGISTER_MUTATOR(nt, cvar("g_new_toys") && !cvar("g_instagib") && !cvar("g_overk // mark the guns as ok to use by e.g. impulse 99 for(int i = WEP_FIRST; i <= WEP_LAST; ++i) if(nt_IsNewToy(i)) - get_weaponinfo(i).spawnflags &= ~WEP_FLAG_MUTATORBLOCKED; + Weapons_from(i).spawnflags &= ~WEP_FLAG_MUTATORBLOCKED; } MUTATOR_ONROLLBACK_OR_REMOVE { for(int i = WEP_FIRST; i <= WEP_LAST; ++i) if(nt_IsNewToy(i)) - get_weaponinfo(i).spawnflags |= WEP_FLAG_MUTATORBLOCKED; + Weapons_from(i).spawnflags |= WEP_FLAG_MUTATORBLOCKED; } MUTATOR_ONREMOVE @@ -168,7 +168,7 @@ MUTATOR_HOOKFUNCTION(nt, SetStartItems) for(i = WEP_FIRST; i <= WEP_LAST; ++i) { - entity e = get_weaponinfo(i); + entity e = Weapons_from(i); if(!e.weapon) continue; @@ -177,7 +177,7 @@ MUTATOR_HOOKFUNCTION(nt, SetStartItems) for (j = 0; j < n; ++j) for (k = WEP_FIRST; k <= WEP_LAST; ++k) { - Weapon w = get_weaponinfo(k); + Weapon w = Weapons_from(k); if (w.netname == argv(j)) { WepSet seti = e.m_wepset; diff --git a/qcsrc/common/mutators/mutator/nix/nix.qc b/qcsrc/common/mutators/mutator/nix/nix.qc index 73b08bce8..a07ad44ca 100644 --- a/qcsrc/common/mutators/mutator/nix/nix.qc +++ b/qcsrc/common/mutators/mutator/nix/nix.qc @@ -45,7 +45,7 @@ REGISTER_MUTATOR(nix, cvar("g_nix") && !cvar("g_instagib") && !cvar("g_overkill" for (int i = WEP_FIRST; i <= WEP_LAST; ++i) if (NIX_CanChooseWeapon(i)) { - Weapon w = get_weaponinfo(i); + Weapon w = Weapons_from(i); w.wr_init(w); } } @@ -78,7 +78,7 @@ REGISTER_MUTATOR(nix, cvar("g_nix") && !cvar("g_instagib") && !cvar("g_overkill" bool NIX_CanChooseWeapon(int wpn) { - entity e = get_weaponinfo(wpn); + entity e = Weapons_from(wpn); if(!e.weapon) // skip dummies return false; if(g_weaponarena) @@ -124,12 +124,12 @@ void NIX_GiveCurrentWeapon() nix_nextchange = time; // start the first round now! else nix_nextchange = time + autocvar_g_balance_nix_roundtime; - // Weapon w = get_weaponinfo(nix_weapon); + // Weapon w = Weapons_from(nix_weapon); // w.wr_init(w); // forget it, too slow } // get weapon info - entity e = get_weaponinfo(nix_weapon); + entity e = Weapons_from(nix_weapon); if(nix_nextchange != self.nix_lastchange_id) // this shall only be called once per round! { diff --git a/qcsrc/common/mutators/mutator/overkill/hmg.qc b/qcsrc/common/mutators/mutator/overkill/hmg.qc index 7f2341fb0..8341f7c71 100644 --- a/qcsrc/common/mutators/mutator/overkill/hmg.qc +++ b/qcsrc/common/mutators/mutator/overkill/hmg.qc @@ -61,8 +61,7 @@ void W_HeavyMachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weapone return; } - Weapon w = get_weaponinfo(actor.weapon); - if(!w.wr_checkammo1(w)) + if(!thiswep.wr_checkammo1(thiswep)) if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { W_SwitchWeapon_Force(actor, w_getbestweapon(actor)); @@ -108,8 +107,7 @@ void W_HeavyMachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weapone METHOD(HeavyMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { if(WEP_CVAR(hmg, reload_ammo) && actor.clip_load < WEP_CVAR(hmg, ammo)) { // forced reload - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } else { if (fire & 1) diff --git a/qcsrc/common/mutators/mutator/overkill/overkill.qc b/qcsrc/common/mutators/mutator/overkill/overkill.qc index 5528bdf80..05b6ddde3 100644 --- a/qcsrc/common/mutators/mutator/overkill/overkill.qc +++ b/qcsrc/common/mutators/mutator/overkill/overkill.qc @@ -63,7 +63,7 @@ void ok_DecreaseCharge(entity ent, int wep) { if(!ent.ok_use_ammocharge) return; - entity wepent = get_weaponinfo(wep); + entity wepent = Weapons_from(wep); if(wepent.weapon == 0) return; // dummy @@ -73,7 +73,7 @@ void ok_DecreaseCharge(entity ent, int wep) void ok_IncreaseCharge(entity ent, int wep) { - entity wepent = get_weaponinfo(wep); + entity wepent = Weapons_from(wep); if(wepent.weapon == 0) return; // dummy @@ -87,7 +87,7 @@ float ok_CheckWeaponCharge(entity ent, int wep) { if(!ent.ok_use_ammocharge) return true; - entity wepent = get_weaponinfo(wep); + entity wepent = Weapons_from(wep); if(wepent.weapon == 0) return 0; // dummy @@ -229,7 +229,7 @@ MUTATOR_HOOKFUNCTION(ok, PlayerPreThink) self.ok_notice_time = time + 2; play2(self, SND(DRYFIRE)); } - Weapon wpn = get_weaponinfo(self.weapon); + Weapon wpn = Weapons_from(self.weapon); .entity weaponentity = weaponentities[0]; // TODO: unhardcode if(self.(weaponentity).state != WS_CLEAR) w_ready(wpn, self, weaponentity, (self.BUTTON_ATCK ? 1 : 0) | (self.BUTTON_ATCK2 ? 2 : 0)); diff --git a/qcsrc/common/mutators/mutator/overkill/rpc.qc b/qcsrc/common/mutators/mutator/overkill/rpc.qc index 05aa9239d..94f1bd10c 100644 --- a/qcsrc/common/mutators/mutator/overkill/rpc.qc +++ b/qcsrc/common/mutators/mutator/overkill/rpc.qc @@ -156,8 +156,7 @@ void W_RocketPropelledChainsaw_Attack (Weapon thiswep) METHOD(RocketPropelledChainsaw, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { if(WEP_CVAR(rpc, reload_ammo) && actor.clip_load < WEP_CVAR(rpc, ammo)) { - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } else { if (fire & 1) diff --git a/qcsrc/common/mutators/mutator/pinata/pinata.qc b/qcsrc/common/mutators/mutator/pinata/pinata.qc index a806b2958..99c1321c1 100644 --- a/qcsrc/common/mutators/mutator/pinata/pinata.qc +++ b/qcsrc/common/mutators/mutator/pinata/pinata.qc @@ -4,7 +4,7 @@ REGISTER_MUTATOR(pinata, cvar("g_pinata") && !cvar("g_instagib") && !cvar("g_ove MUTATOR_HOOKFUNCTION(pinata, PlayerDies) {SELFPARAM(); for(int j = WEP_FIRST; j <= WEP_LAST; ++j) - if(self.weapons & WepSet_FromWeapon(j)) + if(self.weapons & WepSet_FromWeapon(Weapons_from(j))) if(self.switchweapon != j) if(W_IsWeaponThrowable(j)) W_ThrowNewWeapon(self, j, false, self.origin + (self.mins + self.maxs) * 0.5, randomvec() * 175 + '0 0 325'); diff --git a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc index fd21947d6..9db086a8b 100644 --- a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc +++ b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc @@ -221,7 +221,7 @@ void Ent_WaypointSprite() float spritelookupblinkvalue(string s) {SELFPARAM(); if (s == WP_Weapon.netname) { - if (get_weaponinfo(self.wp_extra).spawnflags & WEP_FLAG_SUPERWEAPON) + if (Weapons_from(self.wp_extra).spawnflags & WEP_FLAG_SUPERWEAPON) return 2; } if (s == WP_Item.netname) return Items_from(self.wp_extra).m_waypointblink; @@ -231,7 +231,7 @@ float spritelookupblinkvalue(string s) vector spritelookupcolor(entity this, string s, vector def) { - if (s == WP_Weapon.netname || s == RADARICON_Weapon.netname) return get_weaponinfo(this.wp_extra).wpcolor; + if (s == WP_Weapon.netname || s == RADARICON_Weapon.netname) return Weapons_from(this.wp_extra).wpcolor; if (s == WP_Item.netname || s == RADARICON_Item.netname) return Items_from(this.wp_extra).m_color; if (MUTATOR_CALLHOOK(WP_Format, this, s)) { @@ -243,7 +243,7 @@ vector spritelookupcolor(entity this, string s, vector def) string spritelookuptext(string s) {SELFPARAM(); if (s == WP_RaceStartFinish.netname) return (race_checkpointtime || race_mycheckpointtime) ? _("Finish") : _("Start"); - if (s == WP_Weapon.netname) return get_weaponinfo(self.wp_extra).m_name; + if (s == WP_Weapon.netname) return Weapons_from(self.wp_extra).m_name; if (s == WP_Item.netname) return Items_from(self.wp_extra).m_waypoint; if (s == WP_Monster.netname) return get_monsterinfo(self.wp_extra).monster_name; if (MUTATOR_CALLHOOK(WP_Format, this, s)) diff --git a/qcsrc/common/playerstats.qc b/qcsrc/common/playerstats.qc index 7584e3353..2d9398ad7 100644 --- a/qcsrc/common/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -106,23 +106,16 @@ float PlayerStats_GameReport_Event(string prefix, string event_id, float value) void PlayerStats_GameReport_Accuracy(entity p) { - int i; - - for(i = WEP_FIRST; i <= WEP_LAST; ++i) - { - entity w = get_weaponinfo(i); - - #define ACCMAC(suffix,field) \ - PS_GR_P_ADDVAL(p, sprintf("acc-%s-%s", w.netname, suffix), p.accuracy.(field[i-1])); - + #define ACCMAC(suffix, field) \ + PS_GR_P_ADDVAL(p, sprintf("acc-%s-%s", it.netname, suffix), p.accuracy.(field[i-1])); + FOREACH(Weapons, it != WEP_Null, LAMBDA( ACCMAC("hit", accuracy_hit) ACCMAC("fired", accuracy_fired) ACCMAC("cnt-hit", accuracy_cnt_hit) ACCMAC("cnt-fired", accuracy_cnt_fired) ACCMAC("frags", accuracy_frags) - - #undef ACCMAC - } + )); + #undef ACCMAC } void PlayerStats_GameReport_FinalizePlayer(entity p) @@ -240,17 +233,13 @@ void PlayerStats_GameReport_Init() // initiated before InitGameplayMode so that PlayerStats_GameReport_AddEvent(PLAYERSTATS_RANK); // accuracy stats - entity w; - float i; - for(i = WEP_FIRST; i <= WEP_LAST; ++i) - { - w = get_weaponinfo(i); - PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-hit")); - PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-fired")); - PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-cnt-hit")); - PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-cnt-fired")); - PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-frags")); - } + FOREACH(Weapons, it != WEP_Null, LAMBDA( + PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-hit")); + PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-fired")); + PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-cnt-hit")); + PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-cnt-fired")); + PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-frags")); + )); PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3); PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5); diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index a12e8556a..fc3bd9167 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -101,10 +101,10 @@ string W_FixWeaponOrder(string order, float complete) } string W_NameWeaponOrder_MapFunc(string s) { - entity wi; - if (s == "0" || stof(s)) + int i = stof(s); + if (s == "0" || i) { - wi = get_weaponinfo(stof(s)); + entity wi = Weapons_from(i); if (wi != WEP_Null) return wi.netname; } return s; @@ -129,11 +129,9 @@ string W_NameWeaponOrder(string order) } string W_NumberWeaponOrder_MapFunc(string s) { - int i; if (s == "0" || stof(s)) return s; s = W_UndeprecateName(s); - for (i = WEP_FIRST; i <= WEP_LAST; ++i) - if (s == get_weaponinfo(i).netname) return ftos(i); + FOREACH(Weapons, it != WEP_Null && it.netname == s, LAMBDA(return ftos(i))); return s; } string W_NumberWeaponOrder(string order) @@ -152,17 +150,17 @@ void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass) } float W_FixWeaponOrder_BuildImpulseList_cmp(int i, int j, entity pass) { - entity e1, e2; - float d; - e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]); - e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]); - d = (e1.impulse + 9) % 10 - (e2.impulse + 9) % 10; + int si = W_FixWeaponOrder_BuildImpulseList_buf[i]; + Weapon e1 = Weapons_from(si); + int sj = W_FixWeaponOrder_BuildImpulseList_buf[j]; + Weapon e2 = Weapons_from(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, " "), - sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0) + sprintf(" %d ", si), 0) - strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), - sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0) + sprintf(" %d ", sj), 0) ; // low char index first! } string W_FixWeaponOrder_BuildImpulseList(string o) @@ -202,9 +200,10 @@ void W_RandomWeapons(entity e, float n) { RandomSelection_Init(); for (j = WEP_FIRST; j <= WEP_LAST; ++j) - if (remaining & WepSet_FromWeapon(j)) RandomSelection_Add(world, j, string_null, 1, 1); - result |= WepSet_FromWeapon(RandomSelection_chosen_float); - remaining &= ~WepSet_FromWeapon(RandomSelection_chosen_float); + if (remaining & WepSet_FromWeapon(Weapons_from(j))) RandomSelection_Add(NULL, j, string_null, 1, 1); + Weapon w = Weapons_from(RandomSelection_chosen_float); + result |= WepSet_FromWeapon(w); + remaining &= ~WepSet_FromWeapon(w); } e.weapons = result; } diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 47568b31a..7e4d390ba 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -32,13 +32,12 @@ WepSet ReadWepSet(); REGISTRY(Weapons, 72) // Increase as needed. Can be up to 72. #define Weapons_from(i) _Weapons_from(i, WEP_Null) -#define get_weaponinfo(i) Weapons_from(i) REGISTER_REGISTRY(Weapons) STATIC_INIT(WeaponPickup) { FOREACH(Weapons, true, LAMBDA(it.m_pickup = NEW(WeaponPickup, it))); } .WepSet m_wepset; #define WEPSET(id) (WEP_##id.m_wepset) -#define WepSet_FromWeapon(i) (Weapons_from(i).m_wepset) +#define WepSet_FromWeapon(it) ((it).m_wepset) WepSet _WepSet_FromWeapon(int i); STATIC_INIT(WepSets) { @@ -169,7 +168,7 @@ STATIC_INIT(register_weapons_done) for (int i = Weapons_MAX - 1; i >= 1; --i) if (Weapons_from(i)) weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i)); - weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1)); + weaponorder_byid = strzone(substring(weaponorder_byid, 1, -1)); } #ifndef MENUQC diff --git a/qcsrc/common/weapons/config.qc b/qcsrc/common/weapons/config.qc index 3ee4a684a..ad90baa6f 100644 --- a/qcsrc/common/weapons/config.qc +++ b/qcsrc/common/weapons/config.qc @@ -24,17 +24,15 @@ float W_Config_Queue_Compare(int root, int child, entity pass) void Dump_Weapon_Settings() { - int i, x, totalsettings = 0; - for(i = WEP_FIRST; i <= WEP_LAST; ++i) - { + int totalweapons = 0, totalsettings = 0; + FOREACH(Weapons, it != WEP_Null, LAMBDA( // step 1: clear the queue WEP_CONFIG_COUNT = 0; - for(x = 0; x <= MAX_WEP_CONFIG; ++x) + for (int x = 0; x <= MAX_WEP_CONFIG; ++x) { wep_config_queue[x] = string_null; } // step 2: build new queue - Weapon w = get_weaponinfo(i); - w.wr_config(w); + it.wr_config(it); // step 3: sort queue heapsort(WEP_CONFIG_COUNT, W_Config_Queue_Swap, W_Config_Queue_Compare, world); @@ -43,22 +41,23 @@ void Dump_Weapon_Settings() WEP_CONFIG_WRITETOFILE(sprintf( "// {{{ #%d: %s%s\n", i, - WEP_NAME(i), - (((get_weaponinfo(i)).spawnflags & WEP_FLAG_MUTATORBLOCKED) ? " (MUTATOR WEAPON)" : "") + it.m_name, + ((it.spawnflags & WEP_FLAG_MUTATORBLOCKED) ? " (MUTATOR WEAPON)" : "") )); - for(x = 0; x <= WEP_CONFIG_COUNT; ++x) { WEP_CONFIG_WRITETOFILE(wep_config_queue[x]); } + for (int x = 0; x <= WEP_CONFIG_COUNT; ++x) { WEP_CONFIG_WRITETOFILE(wep_config_queue[x]); } WEP_CONFIG_WRITETOFILE("// }}}\n"); // step 5: debug info - LOG_INFO(sprintf("#%d: %s: %d settings...\n", i, WEP_NAME(i), WEP_CONFIG_COUNT)); + LOG_INFO(sprintf("#%d: %s: %d settings...\n", i, it.m_name, WEP_CONFIG_COUNT)); + totalweapons += 1; totalsettings += WEP_CONFIG_COUNT; - } + )); // clear queue now that we're finished WEP_CONFIG_COUNT = 0; - for(x = 0; x <= MAX_WEP_CONFIG; ++x) + for(int x = 0; x <= MAX_WEP_CONFIG; ++x) { wep_config_queue[x] = string_null; } // extra information - LOG_INFO(sprintf("Totals: %d weapons, %d settings\n", (i - 1), totalsettings)); + LOG_INFO(sprintf("Totals: %d weapons, %d settings\n", totalweapons, totalsettings)); } diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index 3f09e914a..bc98da433 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -218,6 +218,6 @@ string W_Model(string w_mdl); // other useful macros #define WEP_AMMO(wpn) (WEP_##wpn.ammo_field) // only used inside weapon files/with direct name, don't duplicate prefix -#define WEP_NAME(wpn) ((get_weaponinfo(wpn)).m_name) +#define WEP_NAME(wpn) ((Weapons_from(wpn)).m_name) #endif diff --git a/qcsrc/common/weapons/weapon/crylink.qc b/qcsrc/common/weapons/weapon/crylink.qc index 209bd2dd0..300622289 100644 --- a/qcsrc/common/weapons/weapon/crylink.qc +++ b/qcsrc/common/weapons/weapon/crylink.qc @@ -575,8 +575,7 @@ void W_Crylink_Attack2(Weapon thiswep) METHOD(Crylink, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { if(autocvar_g_balance_crylink_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(crylink, ammo), WEP_CVAR_SEC(crylink, ammo))) { // forced reload - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } if(fire & 1) diff --git a/qcsrc/common/weapons/weapon/devastator.qc b/qcsrc/common/weapons/weapon/devastator.qc index d6ffd50d6..6a841c9eb 100644 --- a/qcsrc/common/weapons/weapon/devastator.qc +++ b/qcsrc/common/weapons/weapon/devastator.qc @@ -526,8 +526,7 @@ void W_Devastator_Attack(Weapon thiswep) METHOD(Devastator, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { if(WEP_CVAR(devastator, reload_ammo) && actor.clip_load < WEP_CVAR(devastator, ammo)) { // forced reload - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } else { if(fire & 1) { diff --git a/qcsrc/common/weapons/weapon/electro.qc b/qcsrc/common/weapons/weapon/electro.qc index 0f48bb259..30dd6d74a 100644 --- a/qcsrc/common/weapons/weapon/electro.qc +++ b/qcsrc/common/weapons/weapon/electro.qc @@ -461,8 +461,7 @@ void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, i if(!ammo_amount) { - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); return; } } diff --git a/qcsrc/common/weapons/weapon/hagar.qc b/qcsrc/common/weapons/weapon/hagar.qc index 859b54c95..a5066017a 100644 --- a/qcsrc/common/weapons/weapon/hagar.qc +++ b/qcsrc/common/weapons/weapon/hagar.qc @@ -386,8 +386,7 @@ void W_Hagar_Attack2_Load(Weapon thiswep, .entity weaponentity) self.hagar_warning = false; // we aren't checking ammo during an attack, so we must do it here - Weapon w = get_weaponinfo(self.weapon); - if(!(w.wr_checkammo1(w) + w.wr_checkammo2(w))) + if(!(thiswep.wr_checkammo1(thiswep) + thiswep.wr_checkammo2(thiswep))) if(!(self.items & IT_UNLIMITED_WEAPON_AMMO)) { // note: this doesn't force the switch @@ -412,8 +411,7 @@ void W_Hagar_Attack2_Load(Weapon thiswep, .entity weaponentity) if(loadable_secondary) W_Hagar_Attack2_Load(thiswep, weaponentity); // must always run each frame if(autocvar_g_balance_hagar_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo))) { // forced reload - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } else if((fire & 1) && !actor.hagar_load && !actor.hagar_loadblock) // not while secondary is loaded or awaiting reset { if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(hagar, refire))) diff --git a/qcsrc/common/weapons/weapon/hlac.qc b/qcsrc/common/weapons/weapon/hlac.qc index 252cc96e3..f99c70073 100644 --- a/qcsrc/common/weapons/weapon/hlac.qc +++ b/qcsrc/common/weapons/weapon/hlac.qc @@ -169,8 +169,7 @@ void W_HLAC_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int if(actor.BUTTON_ATCK) { - Weapon w = get_weaponinfo(actor.weapon); - if(!w.wr_checkammo1(w)) + if(!thiswep.wr_checkammo1(thiswep)) if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { W_SwitchWeapon_Force(actor, w_getbestweapon(actor)); @@ -213,8 +212,7 @@ void W_HLAC_Attack2_Frame(Weapon thiswep) METHOD(HLAC, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { if(autocvar_g_balance_hlac_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo))) { // forced reload - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } else if(fire & 1) { if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(hlac, refire))) diff --git a/qcsrc/common/weapons/weapon/machinegun.qc b/qcsrc/common/weapons/weapon/machinegun.qc index 553381818..7e79bc929 100644 --- a/qcsrc/common/weapons/weapon/machinegun.qc +++ b/qcsrc/common/weapons/weapon/machinegun.qc @@ -146,8 +146,7 @@ void W_MachineGun_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentit } if(actor.BUTTON_ATCK) { - Weapon w = get_weaponinfo(actor.weapon); - if(!w.wr_checkammo2(w)) + if(!thiswep.wr_checkammo2(thiswep)) if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { W_SwitchWeapon_Force(actor, w_getbestweapon(actor)); @@ -173,8 +172,7 @@ void W_MachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity return; } - Weapon w = get_weaponinfo(actor.weapon); - if(!w.wr_checkammo1(w)) + if(!thiswep.wr_checkammo1(thiswep)) if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { W_SwitchWeapon_Force(actor, w_getbestweapon(actor)); @@ -252,8 +250,7 @@ void W_MachineGun_Attack_Burst(Weapon thiswep, entity actor, .entity weaponentit METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { if(WEP_CVAR(machinegun, reload_ammo) && actor.clip_load < min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo))) { // forced reload - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } else if(WEP_CVAR(machinegun, mode) == 1) { @@ -267,8 +264,7 @@ void W_MachineGun_Attack_Burst(Weapon thiswep, entity actor, .entity weaponentit if(fire & 2) if(weapon_prepareattack(thiswep, actor, weaponentity, true, 0)) { - Weapon w = get_weaponinfo(actor.weapon); - if(!w.wr_checkammo2(w)) + if(!thiswep.wr_checkammo2(thiswep)) if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { W_SwitchWeapon_Force(actor, w_getbestweapon(actor)); diff --git a/qcsrc/common/weapons/weapon/minelayer.qc b/qcsrc/common/weapons/weapon/minelayer.qc index 1365e61b9..2f1459f83 100644 --- a/qcsrc/common/weapons/weapon/minelayer.qc +++ b/qcsrc/common/weapons/weapon/minelayer.qc @@ -506,8 +506,7 @@ float W_MineLayer_PlacedMines(float detonate) { // not if we're holding the minelayer without enough ammo, but can detonate existing mines if(!(W_MineLayer_PlacedMines(false) && actor.WEP_AMMO(MINE_LAYER) < WEP_CVAR(minelayer, ammo))) { - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } } else if(fire & 1) diff --git a/qcsrc/common/weapons/weapon/mortar.qc b/qcsrc/common/weapons/weapon/mortar.qc index 36a3c0c9e..223d13ffb 100644 --- a/qcsrc/common/weapons/weapon/mortar.qc +++ b/qcsrc/common/weapons/weapon/mortar.qc @@ -335,8 +335,7 @@ void W_Mortar_Attack2(Weapon thiswep) METHOD(Mortar, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { if(autocvar_g_balance_mortar_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo))) { // forced reload - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } else if(fire & 1) { if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(mortar, refire))) diff --git a/qcsrc/common/weapons/weapon/rifle.qc b/qcsrc/common/weapons/weapon/rifle.qc index be9788fcc..a639747db 100644 --- a/qcsrc/common/weapons/weapon/rifle.qc +++ b/qcsrc/common/weapons/weapon/rifle.qc @@ -161,8 +161,7 @@ void W_Rifle_BulletHail(.entity weaponentity, float mode, void() AttackFunc, WFR METHOD(Rifle, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { if(autocvar_g_balance_rifle_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(rifle, ammo), WEP_CVAR_SEC(rifle, ammo))) { // forced reload - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } else { actor.rifle_accumulator = bound(time - WEP_CVAR(rifle, bursttime), actor.rifle_accumulator, time); @@ -179,8 +178,7 @@ void W_Rifle_BulletHail(.entity weaponentity, float mode, void() AttackFunc, WFR if(WEP_CVAR(rifle, secondary)) { if(WEP_CVAR_SEC(rifle, reload)) { - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } else { if(weapon_prepareattack_check(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(rifle, refire))) diff --git a/qcsrc/common/weapons/weapon/seeker.qc b/qcsrc/common/weapons/weapon/seeker.qc index 533b7c944..01c7feb88 100644 --- a/qcsrc/common/weapons/weapon/seeker.qc +++ b/qcsrc/common/weapons/weapon/seeker.qc @@ -607,8 +607,7 @@ void W_Seeker_Fire_Tag(Weapon thiswep) METHOD(Seeker, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { if(autocvar_g_balance_seeker_reload_ammo && actor.clip_load < min(WEP_CVAR(seeker, missile_ammo), WEP_CVAR(seeker, tag_ammo))) { // forced reload - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } else if(fire & 1) { if(WEP_CVAR(seeker, type) == 1) diff --git a/qcsrc/common/weapons/weapon/shotgun.qc b/qcsrc/common/weapons/weapon/shotgun.qc index 3ac26958a..c50eff100 100644 --- a/qcsrc/common/weapons/weapon/shotgun.qc +++ b/qcsrc/common/weapons/weapon/shotgun.qc @@ -197,8 +197,7 @@ void W_Shotgun_Attack2(Weapon thiswep, entity actor, .entity weaponentity, int f // alternate secondary weapon frames void W_Shotgun_Attack3_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire) { - Weapon w = get_weaponinfo(actor.weapon); - if (!w.wr_checkammo2(w)) + if (!thiswep.wr_checkammo2(thiswep)) if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { W_SwitchWeapon_Force(actor, w_getbestweapon(actor)); @@ -212,8 +211,7 @@ void W_Shotgun_Attack3_Frame2(Weapon thiswep, entity actor, .entity weaponentity } void W_Shotgun_Attack3_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire) { - Weapon w = get_weaponinfo(actor.weapon); - if (!w.wr_checkammo2(w)) + if (!thiswep.wr_checkammo2(thiswep)) if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { W_SwitchWeapon_Force(actor, w_getbestweapon(actor)); @@ -240,8 +238,7 @@ void W_Shotgun_Attack3_Frame1(Weapon thiswep, entity actor, .entity weaponentity { // don't force reload an empty shotgun if its melee attack is active if(WEP_CVAR(shotgun, secondary) < 2) { - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } } else diff --git a/qcsrc/common/weapons/weapon/vaporizer.qc b/qcsrc/common/weapons/weapon/vaporizer.qc index a3c4c1f97..7ab692f24 100644 --- a/qcsrc/common/weapons/weapon/vaporizer.qc +++ b/qcsrc/common/weapons/weapon/vaporizer.qc @@ -347,11 +347,9 @@ void W_RocketMinsta_Attack3 () float vaporizer_ammo = ((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo)); // if the laser uses load, we also consider its ammo for reloading if(WEP_CVAR(vaporizer, reload_ammo) && WEP_CVAR_SEC(vaporizer, ammo) && actor.clip_load < min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo))) { // forced reload - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } else if(WEP_CVAR(vaporizer, reload_ammo) && actor.clip_load < vaporizer_ammo) { // forced reload - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } if((fire & 1) && (actor.ammo_cells || !autocvar_g_rm) && !forbidWeaponUse(actor)) { diff --git a/qcsrc/common/weapons/weapon/vortex.qc b/qcsrc/common/weapons/weapon/vortex.qc index a3caf7aab..ded0eede4 100644 --- a/qcsrc/common/weapons/weapon/vortex.qc +++ b/qcsrc/common/weapons/weapon/vortex.qc @@ -230,8 +230,7 @@ void W_Vortex_Attack(Weapon thiswep, float issecondary) } if(autocvar_g_balance_vortex_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo))) { // forced reload - Weapon w = get_weaponinfo(actor.weapon); - w.wr_reload(w); + thiswep.wr_reload(thiswep); } else { if(fire & 1) diff --git a/qcsrc/dpdefs/doc.md b/qcsrc/dpdefs/doc.md new file mode 100644 index 000000000..4ee55324e --- /dev/null +++ b/qcsrc/dpdefs/doc.md @@ -0,0 +1,224 @@ +# CSQC + +``` + +// input: +// self +.void() predraw; + +// input: +// time +// self +.void() think; + +// 0 = keydown, key, character (EXT_CSQC) +// 1 = keyup, key, character (EXT_CSQC) +// 2 = mousemove relative, x, y (EXT_CSQC) +// 3 = mousemove absolute, x, y (DP_CSQC) +bool CSQC_InputEvent(int eventtype, int x, int y); + +void CSQC_UpdateView(int width, int height); +bool CSQC_ConsoleCommand(string cmd); +bool CSQC_Parse_TempEntity(); +bool CSQC_Parse_StuffCmd(string msg); +bool CSQC_Parse_Print(string msg); +bool CSQC_Parse_CenterPrint(string msg); +bool CSQC_Event_Sound(int ent, int channel, string sample, float volume, float attenuation, vector pos, float speed, int flags); + +entity CSQC_Ent_Spawn(int entnum); +void CSQC_Ent_Update(bool isnew); +void CSQC_Ent_Remove(); + +void CSQC_Init(); +void CSQC_Shutdown(); + +// input: +// time +// self +// v_forward: forward +// v_right: right +// v_up: up +// output: +// origin +// v_forward: forward +// v_right: right +// v_up: up +// trace_endpos: visorigin +.vector camera_transform(vector pos, vector ang); + +``` + +# SVQC + +``` + +.entity clientcamera; + +// input: +// time +// self +void ClientDisconnect(); + +// input: +// time +void SV_Shutdown(); + +// input: +// time +void SV_PausedTic(float elapsed); + +// input: +// time +// self +void SV_ChangeTeam(int color); + +// input: +// time +// self +void ClientKill(); + +// input: +// time +// self +void RestoreGame(); + +// input: +// time +// self +// parm1..n +void ClientConnect(); + +// input: +// time +// self +// parm1..n +void PutClientInServer(); + +// return false to remove +.bool SendEntity(entity to, int sf); + +// input: +// time +// self +void SV_OnEntityPreSpawnFunction(); + +// input: +// time +// self +void SV_OnEntityNoSpawnFunction(); + +// input: +// time +// self +void SV_OnEntityPostSpawnFunction(); + +// input: +// time +// output: +// parm1..n +void SetNewParms(); + +// input: +// +.bool customizeentityforclient(); + +// input: +// time +// self +// output: +// parm1..n +void SetChangeParms(); + +// input: +// time +// self +// other +// trace_allsolid +// trace_startsolid +// trace_fraction +// trace_inwater +// trace_inopen +// trace_endpos: self.origin +// trace_plane_normal +// trace_plane_dist +// trace_ent: other +// trace_dpstartcontents +// trace_dphitcontents +// trace_dphitq3surfaceflags +// trace_dphittexturename +.void touch(); + +// when .watertype changes: +.void contentstransition(int prev, int current); + +// input: +// time +// self +// other +.void blocked(); + +// input: +// time +// self +.void movetypesteplandevent(vector vel); + +// input: +// time +// self +void PlayerPreThink(); + +// input: +// time +// self +void PlayerPostThink(); + +// input: +// time +// frametime +void StartFrame(); + +// input: +// time +void EndFrame(); + +// input: +// time +// self +void SV_PlayerPhysics(); + +// input: +// time +// self +void SV_ParseClientCommand(string cmd); + +``` + +# MENUQC + +``` + +void m_keydown(int key, int ascii); + +void m_keyup(int key, int ascii); + +void m_draw(int width, int height); + +void m_toggle(int mode); + +int m_gethostcachecategory(int entry); + +void m_shutdown(); + +void m_init(); + +``` + +# All + +``` + +void URI_Get_Callback(int id, int status, string data); + +void GameCommand(string cmd); + +``` diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc index 2f3cd47b0..8b9ddf9b2 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc @@ -52,7 +52,7 @@ string WeaponArenaString() { for(j = WEP_FIRST; j <= WEP_LAST; ++j) { - e = get_weaponinfo(j); + e = Weapons_from(j); if(argv(i) == e.netname) s = strcat(s, " & ", e.m_name); } @@ -253,7 +253,7 @@ void XonoticMutatorsDialog_fill(entity me) e.cvarOffValue = "0"; for(i = WEP_FIRST, j = 0; i <= WEP_LAST; ++i) { - w = get_weaponinfo(i); + w = Weapons_from(i); if(w.spawnflags & WEP_FLAG_HIDDEN) continue; if((j & 1) == 0) diff --git a/qcsrc/menu/xonotic/keybinder.qc b/qcsrc/menu/xonotic/keybinder.qc index a64c77b0f..112a34682 100644 --- a/qcsrc/menu/xonotic/keybinder.qc +++ b/qcsrc/menu/xonotic/keybinder.qc @@ -78,26 +78,21 @@ void Xonotic_KeyBinds_Read() int i; - #define ADD_TO_W_LIST(pred) do { \ - for(i = WEP_FIRST; i <= WEP_LAST; ++i) \ - { \ - wep = get_weaponinfo(i); \ - if(wep.impulse == imp && (pred)) \ - w_list = strcat(w_list, WEP_NAME(i), " / "); \ - } \ - } while(0) - - int imp; - entity wep; - string w_list = ""; - for(imp = 1; imp <= 9; ++imp) + #define ADD_TO_W_LIST(pred) \ + FOREACH(Weapons, it != WEP_Null, LAMBDA( \ + if (it.impulse != imp) continue; \ + if (!(pred)) continue; \ + w_list = strcat(w_list, it.m_name, " / "); \ + )) + + for(int imp = 1; imp <= 9; ++imp) { - ADD_TO_W_LIST(!(wep.flags & WEP_FLAG_MUTATORBLOCKED) && !(wep.flags & WEP_FLAG_SUPERWEAPON)); - ADD_TO_W_LIST(wep.flags & WEP_FLAG_SUPERWEAPON); - ADD_TO_W_LIST(wep.flags & WEP_FLAG_MUTATORBLOCKED); + string w_list = ""; + ADD_TO_W_LIST(!(it.flags & WEP_FLAG_MUTATORBLOCKED) && !(it.flags & WEP_FLAG_SUPERWEAPON)); + ADD_TO_W_LIST(it.flags & WEP_FLAG_SUPERWEAPON); + ADD_TO_W_LIST(it.flags & WEP_FLAG_MUTATORBLOCKED); if(w_list) KEYBIND_DEF(strcat("weapon_group_", itos(imp)), substring(w_list, 0, -4)); - w_list = ""; if(imp == 0) break; if(imp == 9) diff --git a/qcsrc/menu/xonotic/weaponslist.qc b/qcsrc/menu/xonotic/weaponslist.qc index c1189dd9b..8a3fbd670 100644 --- a/qcsrc/menu/xonotic/weaponslist.qc +++ b/qcsrc/menu/xonotic/weaponslist.qc @@ -87,7 +87,7 @@ string XonoticWeaponsList_toString(entity me) s = ""; for(i = 0; i < n; ++i) { - e = get_weaponinfo(stof(argv(i))); + e = Weapons_from(stof(argv(i))); s = strcat(s, e.m_name, ", "); } return substring(s, 0, strlen(s) - 2); @@ -102,7 +102,7 @@ void XonoticWeaponsList_drawListBoxItem(entity me, int i, vector absSize, bool i me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } - e = get_weaponinfo(stof(argv(i))); + e = Weapons_from(stof(argv(i))); string msg = e.m_name; if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED) msg = strcat(msg, "*"); diff --git a/qcsrc/server/bot/havocbot/havocbot.qc b/qcsrc/server/bot/havocbot/havocbot.qc index dd0109ce2..9a74d3841 100644 --- a/qcsrc/server/bot/havocbot/havocbot.qc +++ b/qcsrc/server/bot/havocbot/havocbot.qc @@ -104,7 +104,7 @@ void havocbot_ai() if(self.weapons) { - Weapon w = get_weaponinfo(self.weapon); + Weapon w = Weapons_from(self.weapon); w.wr_aim(w); if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(self)) { @@ -173,7 +173,7 @@ void havocbot_ai() { for (int i = WEP_FIRST; i <= WEP_LAST; ++i) { - entity e = get_weaponinfo(i); + entity e = Weapons_from(i); if ((self.weapons & (e.m_wepset)) && (e.spawnflags & WEP_FLAG_RELOADABLE) && (self.weapon_load[i] < e.reloading_ammo)) self.switchweapon = i; } @@ -995,7 +995,7 @@ float havocbot_chooseweapon_checkreload(int new_weapon) float i, other_weapon_available = false; for(i = WEP_FIRST; i <= WEP_LAST; ++i) { - Weapon w = get_weaponinfo(i); + Weapon w = Weapons_from(i); // if we are out of ammo for all other weapons, it's an emergency to switch to anything else if (w.wr_checkammo1(w) + w.wr_checkammo2(w)) other_weapon_available = true; diff --git a/qcsrc/server/cl_impulse.qc b/qcsrc/server/cl_impulse.qc index ab5ad3b52..05cd17d0d 100644 --- a/qcsrc/server/cl_impulse.qc +++ b/qcsrc/server/cl_impulse.qc @@ -139,7 +139,7 @@ void ImpulseCommands () break; case 20: if(!forbidWeaponUse(self)) { - Weapon w = get_weaponinfo(self.weapon); + Weapon w = Weapons_from(self.weapon); w.wr_reload(w); } break; diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc index 1b0e46038..d7ce1f66a 100644 --- a/qcsrc/server/cl_player.qc +++ b/qcsrc/server/cl_player.qc @@ -482,7 +482,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtyp if(DIFF_TEAM(self, attacker)) { if(DEATH_ISSPECIAL(deathtype)) - awep = get_weaponinfo(attacker.weapon); + awep = Weapons_from(attacker.weapon); else awep = DEATH_WEAPONOF(deathtype); valid_damage_for_weaponstats = 1; @@ -548,7 +548,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtyp MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, self, deathtype); excess = frag_damage; - Weapon wep = get_weaponinfo(self.weapon); + Weapon wep = Weapons_from(self.weapon); wep.wr_playerdeath(wep); RemoveGrapplingHook(self); @@ -631,7 +631,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtyp // reset fields the weapons may use just in case for (j = WEP_FIRST; j <= WEP_LAST; ++j) { - Weapon w = get_weaponinfo(j); + Weapon w = Weapons_from(j); w.wr_resetplayer(w); for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index dcd75023e..dfabd9d3d 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -61,8 +61,8 @@ void GiveFrags (entity attacker, entity targ, float f, int deathtype) { // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon Weapon culprit = DEATH_WEAPONOF(deathtype); - if(!culprit) culprit = get_weaponinfo(attacker.weapon); - else if(!(attacker.weapons & (culprit.m_wepset))) culprit = get_weaponinfo(attacker.weapon); + if(!culprit) culprit = Weapons_from(attacker.weapon); + else if(!(attacker.weapons & (culprit.m_wepset))) culprit = Weapons_from(attacker.weapon); if(g_weaponarena_random_with_blaster && culprit == WEP_BLASTER) // WEAPONTODO: Shouldn't this be in a mutator? { @@ -95,7 +95,7 @@ void GiveFrags (entity attacker, entity targ, float f, int deathtype) } // after a frag, choose another random weapon set - if (!(attacker.weapons & WepSet_FromWeapon(attacker.weapon))) + if (!(attacker.weapons & WepSet_FromWeapon(Weapons_from(attacker.weapon)))) W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker)); } diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index ddf10818f..e7eed32b4 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -526,7 +526,7 @@ void readplayerstartcvars() g_weaponarena_list = "All Weapons"; for (j = WEP_FIRST; j <= WEP_LAST; ++j) { - e = get_weaponinfo(j); + e = Weapons_from(j); if (!(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)) g_weaponarena_weapons |= (e.m_wepset); } @@ -537,7 +537,7 @@ void readplayerstartcvars() g_weaponarena_list = "Most Weapons"; for (j = WEP_FIRST; j <= WEP_LAST; ++j) { - e = get_weaponinfo(j); + e = Weapons_from(j); if (!(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)) if (e.spawnflags & WEP_FLAG_NORMAL) g_weaponarena_weapons |= (e.m_wepset); @@ -558,7 +558,7 @@ void readplayerstartcvars() s = argv(i); for (j = WEP_FIRST; j <= WEP_LAST; ++j) { - e = get_weaponinfo(j); + e = Weapons_from(j); if (e.netname == s) { g_weaponarena_weapons |= (e.m_wepset); @@ -590,7 +590,7 @@ void readplayerstartcvars() { for (i = WEP_FIRST; i <= WEP_LAST; ++i) { - e = get_weaponinfo(i); + e = Weapons_from(i); int w = want_weapon(e, false); WepSet s = e.m_wepset; if(w & 1) @@ -653,7 +653,7 @@ void readplayerstartcvars() warmup_start_weapons_defaultmask = '0 0 0'; for (i = WEP_FIRST; i <= WEP_LAST; ++i) { - e = get_weaponinfo(i); + e = Weapons_from(i); int w = want_weapon(e, g_warmup_allguns); WepSet s = (e.m_wepset); if(w & 1) @@ -683,7 +683,7 @@ void readplayerstartcvars() precache_weapons |= warmup_start_weapons; for (i = WEP_FIRST; i <= WEP_LAST; ++i) { - e = get_weaponinfo(i); + e = Weapons_from(i); if(precache_weapons & (e.m_wepset)) { e.wr_init(e); } diff --git a/qcsrc/server/miscfunctions.qh b/qcsrc/server/miscfunctions.qh index 0976e60e5..819833867 100644 --- a/qcsrc/server/miscfunctions.qh +++ b/qcsrc/server/miscfunctions.qh @@ -340,7 +340,7 @@ void readlevelcvars() game_starttime = time + cvar("g_start_delay"); for(int i = WEP_FIRST; i <= WEP_LAST; ++i) { - Weapon w = get_weaponinfo(i); + Weapon w = Weapons_from(i); w.wr_init(w); } diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index 3fb6998e9..97f63fc29 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -491,7 +491,7 @@ void Item_RespawnCountdown () MUTATOR_CALLHOOK(Item_RespawnCountdown, string_null, '0 0 0'); do { { - entity wi = get_weaponinfo(self.weapon); + entity wi = Weapons_from(self.weapon); if (wi.m_id) { entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Weapon); wp.wp_extra = wi.m_id; @@ -645,7 +645,7 @@ float Item_GiveTo(entity item, entity player) if (player.switchweapon == w_getbestweapon(player)) _switchweapon = true; - if (!(player.weapons & WepSet_FromWeapon(player.switchweapon))) + if (!(player.weapons & WepSet_FromWeapon(Weapons_from(player.switchweapon)))) _switchweapon = true; pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL); @@ -667,7 +667,7 @@ float Item_GiveTo(entity item, entity player) { pickedup = true; for(i = WEP_FIRST; i <= WEP_LAST; ++i) - if(it & WepSet_FromWeapon(i)) + if(it & WepSet_FromWeapon(Weapons_from(i))) { W_DropEvent(wr_pickup, player, i, item); W_GiveWeapon(player, i); @@ -929,7 +929,7 @@ float commodity_pickupevalfunc(entity player, entity item) // Detect needed ammo for(i = WEP_FIRST; i <= WEP_LAST ; ++i) { - wi = get_weaponinfo(i); + wi = Weapons_from(i); if (!(player.weapons & (wi.m_wepset))) continue; @@ -1023,7 +1023,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default } if(weaponid) - this.weapons = WepSet_FromWeapon(weaponid); + this.weapons = WepSet_FromWeapon(Weapons_from(weaponid)); this.flags = FL_ITEM | itemflags; @@ -1126,7 +1126,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default this.is_item = true; } - weaponsInMap |= WepSet_FromWeapon(weaponid); + weaponsInMap |= WepSet_FromWeapon(Weapons_from(weaponid)); precache_model(this.model); precache_sound(this.item_pickupsound); @@ -1442,13 +1442,13 @@ spawnfunc(target_items) { for(j = WEP_FIRST; j <= WEP_LAST; ++j) { - e = get_weaponinfo(j); + e = Weapons_from(j); s = W_UndeprecateName(argv(i)); if(s == e.netname) { self.weapons |= (e.m_wepset); if(self.spawnflags == 0 || self.spawnflags == 2) { - Weapon w = get_weaponinfo(e.weapon); + Weapon w = Weapons_from(e.weapon); w.wr_init(w); } break; @@ -1504,7 +1504,7 @@ spawnfunc(target_items) if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor"); for(j = WEP_FIRST; j <= WEP_LAST; ++j) { - e = get_weaponinfo(j); + e = Weapons_from(j); if(e.weapon) self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & (e.m_wepset)), e.netname); } @@ -1517,10 +1517,10 @@ spawnfunc(target_items) { for(j = WEP_FIRST; j <= WEP_LAST; ++j) { - e = get_weaponinfo(j); + e = Weapons_from(j); if(argv(i) == e.netname) { - Weapon w = get_weaponinfo(e.weapon); + Weapon w = Weapons_from(e.weapon); w.wr_init(w); break; } @@ -1562,7 +1562,7 @@ spawnfunc(item_jetpack) float GiveWeapon(entity e, float wpn, float op, float val) { WepSet v0, v1; - WepSet s = WepSet_FromWeapon(wpn); + WepSet s = WepSet_FromWeapon(Weapons_from(wpn)); v0 = (e.weapons & s); switch(op) { @@ -1688,7 +1688,7 @@ float GiveItems(entity e, float beginarg, float endarg) case "allweapons": for(j = WEP_FIRST; j <= WEP_LAST; ++j) { - wi = get_weaponinfo(j); + wi = Weapons_from(j); if(wi.weapon) if (!(wi.spawnflags & WEP_FLAG_MUTATORBLOCKED)) got += GiveWeapon(e, j, op, val); @@ -1753,7 +1753,7 @@ float GiveItems(entity e, float beginarg, float endarg) default: for(j = WEP_FIRST; j <= WEP_LAST; ++j) { - wi = get_weaponinfo(j); + wi = Weapons_from(j); if(cmd == wi.netname) { got += GiveWeapon(e, j, op, val); @@ -1774,13 +1774,13 @@ float GiveItems(entity e, float beginarg, float endarg) POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND(ITEMPICKUP), string_null); for(j = WEP_FIRST; j <= WEP_LAST; ++j) { - wi = get_weaponinfo(j); + wi = Weapons_from(j); if(wi.weapon) { - POSTGIVE_WEAPON(e, j, SND(WEAPONPICKUP), string_null); + POSTGIVE_WEAPON(e, Weapons_from(j), SND(WEAPONPICKUP), string_null); if (!(save_weapons & (wi.m_wepset))) if(e.weapons & (wi.m_wepset)) { - Weapon w = get_weaponinfo(wi.weapon); + Weapon w = Weapons_from(wi.weapon); w.wr_init(w); } } @@ -1813,7 +1813,7 @@ float GiveItems(entity e, float beginarg, float endarg) else e.superweapons_finished += time; - if (!(e.weapons & WepSet_FromWeapon(e.switchweapon))) + if (!(e.weapons & WepSet_FromWeapon(Weapons_from(e.switchweapon)))) _switchweapon = true; if(_switchweapon) W_SwitchWeapon_Force(e, w_getbestweapon(e)); diff --git a/qcsrc/server/weapons/common.qc b/qcsrc/server/weapons/common.qc index ef3d185c0..b100259ef 100644 --- a/qcsrc/server/weapons/common.qc +++ b/qcsrc/server/weapons/common.qc @@ -14,7 +14,7 @@ void W_GiveWeapon (entity e, float wep) if (!wep) return; - e.weapons |= WepSet_FromWeapon(wep); + e.weapons |= WepSet_FromWeapon(Weapons_from(wep)); setself(e); diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index 8efa15b32..b301da6f2 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -26,7 +26,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) // ignore hook button when using other offhand equipment if (cl.offhand != OFFHAND_HOOK) - if (wpn == WEP_HOOK.m_id && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn))) + if (wpn == WEP_HOOK.m_id && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(Weapons_from(wpn)))) complain = 0; if(complain) @@ -38,7 +38,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) sprint(self, "Invalid weapon\n"); return false; } - if (cl.weapons & WepSet_FromWeapon(wpn)) + if (cl.weapons & WepSet_FromWeapon(Weapons_from(wpn))) { if (andammo) { @@ -49,7 +49,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) else { setself(cl); - Weapon w = get_weaponinfo(wpn); + Weapon w = Weapons_from(wpn); f = w.wr_checkammo1(w) + w.wr_checkammo2(w); // always allow selecting the Mine Layer if we placed mines, so that we can detonate them @@ -77,7 +77,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) { // DRESK - 3/16/07 // Report Proper Weapon Status / Modified Weapon Ownership Message - if (weaponsInMap & WepSet_FromWeapon(wpn)) + if (weaponsInMap & WepSet_FromWeapon(Weapons_from(wpn))) { Send_WeaponComplain(cl, wpn, 1); @@ -139,7 +139,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa while(rest != "") { weaponwant = stof(car(rest)); rest = cdr(rest); - wep = get_weaponinfo(weaponwant); + wep = Weapons_from(weaponwant); wepset = wep.m_wepset; if(imp >= 0) if(wep.impulse != imp) @@ -148,7 +148,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa float i, have_other = false; for(i = WEP_FIRST; i <= WEP_LAST; ++i) { - Weapon e = get_weaponinfo(i); + Weapon e = Weapons_from(i); if(i != weaponwant) if(e.impulse == imp || imp < 0) if((pl.weapons & (e.m_wepset)) || (weaponsInMap & (e.m_wepset))) @@ -197,7 +197,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa while(rest != "") { weaponwant = stof(car(rest)); rest = cdr(rest); - wep = get_weaponinfo(weaponwant); + wep = Weapons_from(weaponwant); wepset = wep.m_wepset; if(imp >= 0) if(wep.impulse != imp) @@ -206,7 +206,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa float i, have_other = false; for(i = WEP_FIRST; i <= WEP_LAST; ++i) { - Weapon w = get_weaponinfo(i); + Weapon w = Weapons_from(i); if(i != weaponwant) if(w.impulse == imp || imp < 0) if((pl.weapons & (w.m_wepset)) || (weaponsInMap & (w.m_wepset))) @@ -242,7 +242,7 @@ void W_SwitchToOtherWeapon(entity pl) { // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway) int ww; - WepSet set = WepSet_FromWeapon(pl.weapon); + WepSet set = WepSet_FromWeapon(Weapons_from(pl.weapon)); if(pl.weapons & set) { pl.weapons &= ~set; @@ -265,7 +265,7 @@ void W_SwitchWeapon(float imp) self.selectweapon = imp; // update selectweapon ANYWAY } else if(!forbidWeaponUse(self)) { - Weapon w = get_weaponinfo(self.weapon); + Weapon w = Weapons_from(self.weapon); w.wr_reload(w); } } diff --git a/qcsrc/server/weapons/spawning.qc b/qcsrc/server/weapons/spawning.qc index 923c2aa4a..c362913d4 100644 --- a/qcsrc/server/weapons/spawning.qc +++ b/qcsrc/server/weapons/spawning.qc @@ -18,7 +18,7 @@ string W_Apply_Weaponreplace(string in) for(j = WEP_FIRST; j <= WEP_LAST; ++j) { - e = get_weaponinfo(j); + e = Weapons_from(j); if(e.netname == s) { replacement = e.weaponreplace; @@ -64,7 +64,7 @@ void weapon_defaultspawnfunc(entity this, Weapon e) int j; for (j = WEP_FIRST; j <= WEP_LAST; ++j) { - e = get_weaponinfo(j); + e = Weapons_from(j); if (e.netname == s) { entity replacement = spawn(); @@ -87,7 +87,7 @@ void weapon_defaultspawnfunc(entity this, Weapon e) int j; for (j = WEP_FIRST; j <= WEP_LAST; ++j) { - e = get_weaponinfo(j); + e = Weapons_from(j); if (e.netname == s) { wpn = j; @@ -107,7 +107,7 @@ void weapon_defaultspawnfunc(entity this, Weapon e) } } - e = get_weaponinfo(wpn); + e = Weapons_from(wpn); if (!this.respawntime) { diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index 6f4546e01..652ec9200 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -34,7 +34,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto {SELFPARAM(); float thisammo, i; string s; - Weapon info = get_weaponinfo(wpn); + Weapon info = Weapons_from(wpn); var .int ammotype = info.ammo_field; entity wep = new(droppedweapon); @@ -47,7 +47,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto W_DropEvent(wr_drop,own,wpn,wep); - if(WepSet_FromWeapon(wpn) & WEPSET_SUPERWEAPONS) + if(WepSet_FromWeapon(Weapons_from(wpn)) & WEPSET_SUPERWEAPONS) { if(own.items & IT_UNLIMITED_SUPERWEAPONS) { @@ -58,7 +58,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto float superweapons = 1; for(i = WEP_FIRST; i <= WEP_LAST; ++i) { - WepSet set = WepSet_FromWeapon(i); + WepSet set = WepSet_FromWeapon(Weapons_from(i)); if ((set & WEPSET_SUPERWEAPONS) && (own.weapons & set)) ++superweapons; } if(superweapons <= 1) @@ -148,17 +148,17 @@ bool W_IsWeaponThrowable(bool w) return false; #if 0 - if(start_weapons & WepSet_FromWeapon(w)) + if(start_weapons & WepSet_FromWeapon(Weapons_from(w))) { // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo) if(start_items & IT_UNLIMITED_WEAPON_AMMO) return false; - if((get_weaponinfo(w)).ammo_field == ammo_none) + if((Weapons_from(w)).ammo_field == ammo_none) return false; } return true; #else - return (get_weaponinfo(w)).weaponthrowable; + return (Weapons_from(w)).weaponthrowable; #endif } @@ -178,7 +178,7 @@ void W_ThrowWeapon(vector velo, vector delta, float doreduce) if(!W_IsWeaponThrowable(w)) return; - WepSet set = WepSet_FromWeapon(w); + WepSet set = WepSet_FromWeapon(Weapons_from(w)); if(!(self.weapons & set)) return; self.weapons &= ~set; @@ -191,7 +191,7 @@ void W_ThrowWeapon(vector velo, vector delta, float doreduce) void SpawnThrownWeapon(vector org, float w) {SELFPARAM(); - if(self.weapons & WepSet_FromWeapon(self.weapon)) + if(self.weapons & WepSet_FromWeapon(Weapons_from(self.weapon))) if(W_IsWeaponThrowable(self.weapon)) W_ThrowNewWeapon(self, self.weapon, false, org, randomvec() * 125 + '0 0 200'); } diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index 7e10c8a60..7607ae18c 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -518,7 +518,7 @@ void W_WeaponFrame(entity actor) // server framerate is very low and the weapon fire rate very high for (int c = 0; c < W_TICSPERFRAME; ++c) { - if (w && !(actor.weapons & WepSet_FromWeapon(w))) + if (w && !(actor.weapons & WepSet_FromWeapon(Weapons_from(w)))) { if (actor.weapon == actor.switchweapon) W_SwitchWeapon_Force(actor, w_getbestweapon(actor)); w = 0;