Skip to content

Commit

Permalink
Ped Randomizer: Add config option for controller player model odds
Browse files Browse the repository at this point in the history
  • Loading branch information
Parik27 committed Jul 30, 2021
1 parent 78a4f66 commit 5e74764
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patreon: parik
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
mkdir output/rainbomizer
cp rainbomizer.asi output/V.Rainbomizer.asi
cp -r ../data output/rainbomizer/data/
rm output/rainbomizer/data/update.sh
rm output/rainbomizer/data/README.md
cp ../config.toml output/rainbomizer/
- name: Upload
uses: actions/upload-artifact@v1
Expand Down
2 changes: 1 addition & 1 deletion build-count.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
471
473
6 changes: 5 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ EnableNoLowBudget = true

# This option makes it so enemy blips are always visible. This helps when the enemies are
# randomized into a small animal that's difficult to locate
EnableBlipsAlwaysVisible = true
EnableBlipsAlwaysVisible = true

# Reduce the odds of the player models being considered to spawn
# (from 0 (no player models) to 100 (some player models))
OddsOfPlayerModels = 20
8 changes: 7 additions & 1 deletion lib/CTheScripts.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public:
static inline void
InvokeNative (uint32_t hash, scrThread::Info *info)
{
if (!m_ScriptHookInfo.bAvailable)
if (!IsScriptHookAvailable ())
return;

m_ScriptHookInfo.mNatives.at (hash).func (info);
Expand All @@ -88,6 +88,12 @@ public:
return m_ScriptHookInfo.mNatives.count (hash);
}

static bool
IsScriptHookAvailable ()
{
return m_ScriptHookInfo.bAvailable;
}

template <typename Ret, typename... Args>
static Ret
InvokeNative (uint32_t hash, Args... args)
Expand Down
5 changes: 5 additions & 0 deletions src/common/configDefault.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const char configDefault[] = R"(
#######################################################
# General Configuration
# Refer to the readme to get the description of all the randomizers.
[Randomizers]
RainbomizerNews = true
Expand Down Expand Up @@ -99,4 +100,8 @@ EnableNoLowBudget = true
# This option makes it so enemy blips are always visible. This helps when the enemies are
# randomized into a small animal that's difficult to locate
EnableBlipsAlwaysVisible = true
# Reduce the odds of the player models being considered to spawn
# (from 0 (no player models) to 100 (some player models))
OddsOfPlayerModels = 20
)";
8 changes: 2 additions & 6 deletions src/misc/colours.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,12 @@ class ColoursRandomizer
static void
RestoreVehicleColourData (CCustomShaderEffectVehicle *shader, CVehicle *veh)
{
try
if (auto *data = LookupMap (mColourData, veh))
{
auto & data = mColourData.at (veh);
CARGB *colours = shader->GetColours ();

for (int i = 0; i < 4; i++)
colours[i] = data.OriginalColours[i];
}
catch (...)
{
colours[i] = data->OriginalColours[i];
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/peds/peds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <scrThread.hh>

#include "CModelInfo.hh"
#include "Utils.hh"
#include "common/logger.hh"

#include <CStreaming.hh>
Expand Down Expand Up @@ -92,7 +93,8 @@ class PedRandomizer

// Random Ped
uint32_t randomPed = PedRandomizer_Streaming::GetRandomLoadedPed (
PR::Config ().EnableNSFWModels);
PR::Config ().EnableNSFWModels,
RandomInt (100) < PR::Config ().OddsOfPlayerModels);

if (randomPed != -1u)
return randomPed;
Expand Down Expand Up @@ -175,7 +177,8 @@ class PedRandomizer
OPTION (IncludeUnusedAbilities),
OPTION (EnableAnimalMotionFixes), OPTION (EnableAnimalFixes),
OPTION (EnablePlayerFixes), OPTION (EnableMainFixes),
OPTION (EnableNoLowBudget), OPTION (EnableBlipsAlwaysVisible)))
OPTION (EnableNoLowBudget), OPTION (EnableBlipsAlwaysVisible),
OPTION (OddsOfPlayerModels)))
return;

if (PR::Config ().ForcedPed.size ())
Expand Down
2 changes: 1 addition & 1 deletion src/peds/peds.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public:
bool EnableMainFixes = true;
bool EnableNoLowBudget = true;
bool EnableBlipsAlwaysVisible = true;

int OddsOfPlayerModels = 20;
} m_Config;

return m_Config;
Expand Down
9 changes: 5 additions & 4 deletions src/peds/peds_Streaming.hh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class PedRandomizer_Streaming

/*******************************************************/
static void
PopulateLoadedPedsSet (std::set<uint32_t> &peds, bool includeNsfw)
PopulateLoadedPedsSet (std::set<uint32_t> &peds, bool includeNsfw,
bool includePlayers = true)
{
auto groups = CStreaming::sm_Instance;

Expand All @@ -107,7 +108,7 @@ class PedRandomizer_Streaming
{"player_one"_joaat, "player_zero"_joaat, "player_two"_joaat})
{
auto index = CStreaming::GetModelIndex (hash);
if (CStreaming::HasModelLoaded (index))
if (includePlayers && CStreaming::HasModelLoaded (index))
peds.insert (index);
}

Expand Down Expand Up @@ -186,10 +187,10 @@ public:

/*******************************************************/
static uint32_t
GetRandomLoadedPed (bool includeNsfw = false)
GetRandomLoadedPed (bool includeNsfw = false, bool includePlayer = true)
{
std::set<uint32_t> peds;
PopulateLoadedPedsSet (peds, includeNsfw);
PopulateLoadedPedsSet (peds, includeNsfw, includePlayer);

if (peds.size () < 1)
return -1;
Expand Down
5 changes: 0 additions & 5 deletions src/peds/peds_Swapper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ class PedRandomizer_ModelSwapper
SWAP_FIELD (GetInitInfo ().m_nDecisionMakerName);
SWAP_FIELD (GetInitInfo ().m_nNavCapabilitiesName);

#ifdef FLYING_BIRDS
SWAP_FIELD (m_nMovementClipSet);
SWAP_FIELD (GetInitInfo ().m_nMotionTaskDataSetName);
#endif

#undef SWAP_FIELD
}

Expand Down

0 comments on commit 5e74764

Please sign in to comment.