]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
new toys: start coding it, far from done
authorRudolf Polzer <divverent@xonotic.org>
Mon, 5 Mar 2012 10:02:17 +0000 (11:02 +0100)
committerRudolf Polzer <divverent@xonotic.org>
Mon, 5 Mar 2012 10:02:17 +0000 (11:02 +0100)
qcsrc/server/miscfunctions.qc
qcsrc/server/mutators/mutator_new_toys.qc
qcsrc/server/mutators/mutator_nix.qc

index 48f9b5c199f423523ded455d31217b056d00ac16..9da8a97dfc8902f3bfffe26c91a45051bce21f72 100644 (file)
@@ -751,6 +751,8 @@ float g_weaponforcefactor;
 float g_weaponspreadfactor;
 
 WEPSET_DECLARE_A(start_weapons);
+WEPSET_DECLARE_A(start_weapons_default);
+WEPSET_DECLARE_A(start_weapons_defaultmask);
 float start_items;
 float start_ammo_shells;
 float start_ammo_nails;
@@ -760,6 +762,8 @@ float start_ammo_fuel;
 float start_health;
 float start_armorvalue;
 WEPSET_DECLARE_A(warmup_start_weapons);
+WEPSET_DECLARE_A(warmup_start_weapons_default);
+WEPSET_DECLARE_A(warmup_start_weapons_defaultmask);
 float warmup_start_ammo_shells;
 float warmup_start_ammo_nails;
 float warmup_start_ammo_rockets;
@@ -775,27 +779,34 @@ entity get_weaponinfo(float w);
 float want_weapon(string cvarprefix, entity weaponinfo, float allguns)
 {
        var float i = weaponinfo.weapon;
+       var float d = 0;
 
        if (!i)
                return 0;
 
-       var float t = cvar(strcat(cvarprefix, weaponinfo.netname));
+       if (g_lms || g_ca || allguns)
+               d = (weaponinfo.spawnflags & WEP_FLAG_NORMAL);
+       else if(t < -1)
+               d = 0;
+       else if (g_cts)
+               d = (i == WEP_SHOTGUN);
+       else if (g_nexball)
+               d = 0; // weapon is set a few lines later
+       else
+               d = (i == WEP_LASER || i == WEP_SHOTGUN);
+       if(g_grappling_hook) // if possible, redirect off-hand hook to on-hand hook
+               d |= (i == WEP_HOOK);
 
-       if (t < 0) // "default" weapon selection
-       {
-               if (g_lms || g_ca || allguns)
-                       t = (weaponinfo.spawnflags & WEP_FLAG_NORMAL);
-               else if(t < -1)
-                       t = 0;
-               else if (g_cts)
-                       t = (i == WEP_SHOTGUN);
-               else if (g_nexball)
-                       t = 0; // weapon is set a few lines later
-               else
-                       t = (i == WEP_LASER || i == WEP_SHOTGUN);
-               if(g_grappling_hook) // if possible, redirect off-hand hook to on-hand hook
-                       t |= (i == WEP_HOOK);
-       }
+       var float t = cvar(strcat(cvarprefix, weaponinfo.netname));
+       
+       // bit order in t:
+       // 1: want or not
+       // 2: is default?
+       // 4: is set by default?
+       if(t < 0)
+               t = 4 | (3 * d);
+       else
+               t |= (2 * d);
 
        return t;
 }
@@ -808,6 +819,8 @@ void readplayerstartcvars()
 
        // initialize starting values for players
        WEPSET_CLEAR_A(start_weapons);
+       WEPSET_CLEAR_A(start_weapons_default);
+       WEPSET_CLEAR_A(start_weapons_defaultmask);
        start_items = 0;
        start_ammo_shells = 0;
        start_ammo_nails = 0;
@@ -917,8 +930,13 @@ void readplayerstartcvars()
                for (i = WEP_FIRST; i <= WEP_LAST; ++i)
                {
                        e = get_weaponinfo(i);
-                       if(want_weapon("g_start_weapon_", e, FALSE))
+                       w = want_weapon("g_start_weapon_", e, FALSE);
+                       if(w & 1)
                                WEPSET_OR_AW(start_weapons, i);
+                       if(w & 2)
+                               WEPSET_OR_AW(start_weapons_default, i);
+                       if(w & 4)
+                               WEPSET_OR_AW(start_weapons_defaultmask, i);
                }
        }
 
@@ -977,6 +995,8 @@ void readplayerstartcvars()
                warmup_start_health = start_health;
                warmup_start_armorvalue = start_armorvalue;
                WEPSET_COPY_AA(warmup_start_weapons, start_weapons);
+               WEPSET_COPY_AA(warmup_start_weapons_default, start_weapons_default);
+               WEPSET_COPY_AA(warmup_start_weapons_defaultmask, start_weapons_defaultmask);
 
                if (!g_weaponarena && !g_minstagib && !g_ca)
                {
@@ -991,13 +1011,23 @@ void readplayerstartcvars()
                        for (i = WEP_FIRST; i <= WEP_LAST; ++i)
                        {
                                e = get_weaponinfo(i);
-                               if(want_weapon("g_start_weapon_", e, cvar("g_warmup_allguns")))
+                               w = want_weapon("g_start_weapon_", e, cvar("g_warmup_allguns"));
+                               if(w & 1)
                                        WEPSET_OR_AW(warmup_start_weapons, i);
+                               if(w & 2)
+                                       WEPSET_OR_AW(warmup_start_weapons_default, i);
+                               if(w & 4)
+                                       WEPSET_OR_AW(warmup_start_weapons_defaultmask, i);
                        }
                }
        }
 
-       if (g_jetpack || (g_grappling_hook && WEPSET_CONTAINS_AW(start_weapons, WEP_HOOK)))
+       if (g_jetpack)
+               start_items |= IT_JETPACK;
+
+       MUTATOR_CALLHOOK(SetStartItems);
+
+       if ((start_items & IT_JETPACK) || (g_grappling_hook && WEPSET_CONTAINS_AW(start_weapons, WEP_HOOK)))
        {
                g_grappling_hook = 0; // these two can't coexist, as they use the same button
                start_items |= IT_FUEL_REGEN;
@@ -1005,11 +1035,6 @@ void readplayerstartcvars()
                warmup_start_ammo_fuel = max(warmup_start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
        }
 
-       if (g_jetpack)
-               start_items |= IT_JETPACK;
-
-       MUTATOR_CALLHOOK(SetStartItems);
-
        for (i = WEP_FIRST; i <= WEP_LAST; ++i)
        {
                e = get_weaponinfo(i);
index 8a1eeabdd9a58eaa4195152b1a7d46c9aaf868ff..df78d27659e289498e8983f1f3be494caea0c00c 100644 (file)
@@ -41,6 +41,8 @@ There will be two default replacements selectable: "replace all" and "replace ra
 In "replace all" mode, e.g. Nex will have the default replacement "rifle".
 In "replace random" mode, Nex will have the default replacement "nex rifle".
 
+This mutator's replacements run BEFORE regular weaponreplace!
+
 The New Toys guns do NOT get a spawn function, so they can only ever be spawned
 when this mutator is active.
 
@@ -63,3 +65,53 @@ Picking up a "new toys" weapon will not play standard weapon pickup sound, but
 roflsound "New toys, new toys!" sound.
 
 */
+
+string i_herd_yo_liek_weaponreplace(string replacement)
+{
+       string newlist;
+       float n = tokenize_console(replacement);
+       string out = "";
+       for(i = 0; i < n; ++i)
+       {
+               string s = argv(i);
+               string r = cvar_string(strcat("g_weaponreplace_", s));
+               if(r == "")
+                       out = strcat(out, " ", s);
+               else if(r != "0")
+                       out = strcat(out, " ", r);
+       }
+       return substring(out, 1);
+}
+
+MUTATOR_HOOKFUNCTION(nt_SetModname)
+{
+       modname = "NewToys";
+       return 0;
+}
+
+MUTATOR_HOOKFUNCTION(nt_SetStartItems)
+{
+       // rearrange start_weapon_default
+       // apply those bits that are set by start_weapon_defaultmask
+       // same for warmup
+       // TODO
+       return 0;
+}
+
+MUTATOR_DEFINITION(mutator_new_toys)
+{
+       MUTATOR_HOOK(SetModname, nt_SetModname, CBC_ORDER_ANY);
+       MUTATOR_HOOK(SetStartItems, nix_SetStartItems, CBC_ORDER_ANY);
+
+       MUTATOR_ONADD
+       {
+               if(time > 1) // game loads at time 1
+                       error("This cannot be added at runtime\n");
+       }
+       MUTATOR_ONREMOVE
+       {
+               error("This cannot be removed at runtime\n");
+       }
+
+       return 0;
+}
index 76e779c5a5f2c76614ad44f520d464ed2e95d4e1..914df99ccd922ee0ec75849409e8fcc2a8fe4f49 100644 (file)
@@ -158,15 +158,6 @@ MUTATOR_HOOKFUNCTION(nix_ForbidThrowCurrentWeapon)
        return 1; // no throwing in NIX
 }
 
-MUTATOR_HOOKFUNCTION(nix_SetStartItems)
-{
-       NIX_precache();
-       // we do NOT change the start weapons any more, so we can later turn off the mutator!
-       //   start_weapons = 0; // will be done later, when player spawns
-       //   warmup_start_weapons = 0; // will be done later, when player spawns
-       return 0;
-}
-
 MUTATOR_HOOKFUNCTION(nix_BuildMutatorsString)
 {
        ret_string = strcat(ret_string, ":NIX");
@@ -230,7 +221,6 @@ MUTATOR_DEFINITION(mutator_nix)
        entity e;
 
        MUTATOR_HOOK(ForbidThrowCurrentWeapon, nix_ForbidThrowCurrentWeapon, CBC_ORDER_ANY);
-       MUTATOR_HOOK(SetStartItems, nix_SetStartItems, CBC_ORDER_EXCLUSIVE);
        MUTATOR_HOOK(BuildMutatorsString, nix_BuildMutatorsString, CBC_ORDER_ANY);
        MUTATOR_HOOK(BuildMutatorsPrettyString, nix_BuildMutatorsPrettyString, CBC_ORDER_ANY);
        MUTATOR_HOOK(FilterItem, nix_FilterItem, CBC_ORDER_ANY);