Skip to content

Commit

Permalink
Randomize weapon mods
Browse files Browse the repository at this point in the history
  • Loading branch information
theastropath committed Aug 2, 2023
1 parent f3ca1ed commit b56310e
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions DXRCore/DeusEx/Classes/DXRando.uc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function vanilla_modules()
modules_to_load[i++] = "DXRPlayerStats";
modules_to_load[i++] = "DXRMapVariants";
modules_to_load[i++] = "DXRStartMap";
modules_to_load[i++] = "DXRWeaponMods";
}

function hx_modules()
Expand Down
120 changes: 120 additions & 0 deletions DXRModules/DeusEx/Classes/DXRWeaponMods.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
class DXRWeaponMods extends DXRActorsBase transient;

struct RandomModStruct { var class<#var(prefix)WeaponMod> type; var float chance; };
var RandomModStruct randommods[8];

var config float min_rate_adjust, max_rate_adjust;

function class<#var(prefix)WeaponMod> PickRandomMod()
{
local class<#var(prefix)WeaponMod> newmod;
local float r;
local int i;

newmod=None;

r = initchance();
for (i=0;i<ArrayCount(randommods);i++){
if(chance(randommods[i].chance,r)) newmod = randommods[i].type;
}

if (newmod==None){
//Shouldn't happen, but...
err("Failed to pick a random weapon mod");
newmod=randommods[0].type;
}

return newmod;
}

function AddRandomMod(class<#var(prefix)WeaponMod> mod, float c)
{
local int i;
for(i=0;i < ArrayCount(randommods);i++){
if (randommods[i].type==None){
randommods[i].type=mod;
randommods[i].chance=rngrangeseeded(c,min_rate_adjust,max_rate_adjust,mod.name);
return;
}
}
}

function CheckConfig()
{
local float total;
local int i;

Super.CheckConfig();

//This is the vanilla count of each mod through the game
AddRandomMod(class'#var(prefix)WeaponModAccuracy',14);
AddRandomMod(class'#var(prefix)WeaponModClip',10);
AddRandomMod(class'#var(prefix)WeaponModRange',7);
AddRandomMod(class'#var(prefix)WeaponModRecoil',10);
AddRandomMod(class'#var(prefix)WeaponModReload',8);
AddRandomMod(class'#var(prefix)WeaponModScope',3);
AddRandomMod(class'#var(prefix)WeaponModSilencer',5);
AddRandomMod(class'#var(prefix)WeaponModLaser',6);

//Scale to 100%
total=0;
for(i=0;i<ArrayCount(randommods);i++)
{
total += randommods[i].chance;
}
for(i=0;i<ArrayCount(randommods);i++)
{
randommods[i].chance *= 100.0/total;
}
}

function FirstEntry()
{
local #var(prefix)WeaponMod mod;
local #var(prefix)WeaponMod mods[16];
local Containers container;
local class<#var(prefix)WeaponMod> newMod;
local int i;

Super.FirstEntry();

SetSeed("RandoWeaponMods");

i=0;
foreach AllActors(class'#var(prefix)WeaponMod',mod)
{
if (mod.Owner==None){
mods[i++]=mod;
}
}

for (i=0;mods[i]!=None;i++){
mod = #var(prefix)WeaponMod(SpawnReplacement(mods[i],PickRandomMod(),True));
if (mod!=None){
mods[i].Destroy();
} else {
err("Failed to replace weapon mod "$mods[i].Name);
}
}

//Technically any decoration can contain objects, but I think DX only puts them in containers
foreach AllActors(class'Containers',container)
{
//I don't know if anything has anything in contents2 or contents3, but can't hurt...
if(ClassIsChildOf(container.contents,class'#var(prefix)WeaponMod')){
container.contents = PickRandomMod();
}
if(ClassIsChildOf(container.content2,class'#var(prefix)WeaponMod')){
container.content2 = PickRandomMod();
}
if(ClassIsChildOf(container.content3,class'#var(prefix)WeaponMod')){
container.content3 = PickRandomMod();
}
}
}

defaultproperties
{
min_rate_adjust=0.3
max_rate_adjust=1.75
}

0 comments on commit b56310e

Please sign in to comment.