Skip to content

Commit

Permalink
probabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
ps1337 committed May 30, 2021
1 parent 9d75e5b commit 686b1da
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CMakeModules/InstallConfig.cmake
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ cpack_add_component_group(JK2SP
DESCRIPTION "Jedi Outcast single player game")

if(WIN32)
include(CPackNSIS)
#include(CPackNSIS)
set(CPACK_NSIS_DISPLAY_NAME "OpenJK")
set(CPACK_NSIS_PACKAGE_NAME "OpenJK")
set(CPACK_NSIS_MUI_ICON "${SharedDir}/icons/icon.ico")
Expand Down
15 changes: 13 additions & 2 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,33 @@ Currently, there is a limit of 100 possible sets per map, which should be enough

If you add a set, make sure you use a unique index in the range of 0-99.

# Probabilities

They can be set for each force level in the `randomizerOptions.json` file.
These are applied when randomizing the force levels, not when randomizing the
actual force powers that are available. This means, that setting something to
`100.00` does *not* make the force power appear every time. Instead, it ensures
the respective for level *in case* the force power is available.

# Additional Notes
* Considering map loading: If you load from a previous save game, **NO** randomization will be performed as the savegame will be treated as is. Quicksaves will be treated the same.
* Please note that for yavin1b, the force powers currently won't get randomized. Starting from yavin2, randomizations kicks in.
* It's intended that sometimes no information on force powers and/or available weapons will be displayed upon map loading. This simplifies randomization at some points in the game.

# Building

Please refer to the original notes on the build process of OpenJK. I added an option to the CMake project which allows you to pass the installation directory with an environment variable. Check the `CMakeList` files for additional info.
1. Please refer to the original notes on the build process of OpenJK.
2. Define WINDOWS_IGNORE_PACKING_MISMATCH

I added an option to the CMake project which allows you to pass the installation directory with an environment variable. Check the `CMakeList` files for additional info.

**After compiling this project, copy the files of the** `files` **folder into the same directory your JKA executable lives in. If you don't do this, the game will crash as intended.** Please refer to the troubleshooting sections in case of problems.

# Credits
Thanks go out to Raven, the JACoders and the JKA speedrunning community.
Additionally, to nlohmann for the great JSON library.

~ Joe Bananas (@JoeBananas1337_)
~ CaptnBanana (@CaptnBanana)

# Todos
* Clean this project from MP files and folders
Expand Down
162 changes: 126 additions & 36 deletions code/ui/globalShuffledTiers.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ const static std::vector<int> FORCE_POWERS_CORE = {


const static std::vector<int> ALL_WEAPONS = {
WP_SABER,

WP_BLASTER_PISTOL,
WP_BLASTER,
WP_DISRUPTOR,
Expand Down Expand Up @@ -618,6 +620,81 @@ static void _updateForceData(playerState_t *pState) {
}
}

static double getProb(int fp, int lvl) {

std::string lvlstr = "LVL1";
switch (lvl) {
case 1:
lvlstr = "LVL1";
break;
case 2:
lvlstr = "LVL2";
break;
case 3:
lvlstr = "LVL3";

default:
break;
}

std::string fpstr = "FP_JUMP";
switch (fp) {
case FP_LEVITATION:
fpstr = "FP_JUMP";
break;
case FP_PUSH:
fpstr = "FP_PUSH";
break;
case FP_PULL:
fpstr = "FP_PULL";
break;
case FP_SABERTHROW:
fpstr = "FP_SABERTHROW";
break;
case FP_SABER_DEFENSE:
fpstr = "FP_SABER_DEFENSE";
break;
case FP_SABER_OFFENSE:
fpstr = "FP_SABER_OFFENSE";
break;
case FP_SEE:
fpstr = "FP_SENSE";
break;
case FP_SPEED:
fpstr = "FP_SPEED";
break;
case FP_HEAL:
fpstr = "FP_HEAL";
break;
case FP_TELEPATHY:
fpstr = "FP_MINDTRICK";
break;
case FP_GRIP:
fpstr = "FP_GRIP";
break;
case FP_LIGHTNING:
fpstr = "FP_LIGHTNING";
break;
case FP_RAGE:
fpstr = "FP_RAGE";
break;
case FP_PROTECT:
fpstr = "FP_PROTECT";
break;
case FP_ABSORB:
fpstr = "FP_ABSORB";
break;
case FP_DRAIN:
fpstr = "FP_DRAIN";
break;

default:
break;
}

return SETTINGS_JSON.at("probability").at(fpstr).at(lvlstr);
}

// returns the known force powers
static void randomizeForcePowers(playerState_t* pState, std::string mapname = "") {

Expand Down Expand Up @@ -685,34 +762,29 @@ static void randomizeForcePowers(playerState_t* pState, std::string mapname = ""
if (TIER_MISSIONS_COMPLETED >= 5 && TIER_MISSIONS_COMPLETED < 10) { corePointsToSpend = fps_core_shuffled.size() * 2; }
if (TIER_MISSIONS_COMPLETED >= 10) { corePointsToSpend = fps_core_shuffled.size() * 3; }

// core
for (auto fp : fps_core_shuffled) {

// finished
if (corePointsToSpend <= 0) { break; }

int randomLevel = Q_min(GET_RANDOM(1, 3), corePointsToSpend);

// don't make it too easy ;)
if (fp == FP_LEVITATION) {
int randNo = GET_RANDOM(0, 100);

if (randNo > (100 - _forceJumpOneProbability)) {
randomLevel = 1;
}
int randomLevel = 0;
int randNo = GET_RANDOM(0, 100);

if (randNo > (100 - _forceJumpTwoProbability)) {
randomLevel = 2;
}
if (randNo <= (getProb(fp, 1))) {
randomLevel = 1;
}

if (randomLevel > (100 - _forceJumpThreeProbability)) {
randomLevel = 3;
}
if (randNo > (getProb(fp, 1))) {
randomLevel = 2;
}

if (randomLevel > (getProb(fp, 1) + getProb(fp, 2))) {
randomLevel = 3;
}

corePointsToSpend -= randomLevel;


pState->forcePowerLevel[fp] = randomLevel;

// enable or disable the force power
Expand All @@ -726,12 +798,26 @@ static void randomizeForcePowers(playerState_t* pState, std::string mapname = ""
}
}

// player
for (auto fp : fps_player_shuffled) {

// finished
if (playerPointsToSpend <= 0) { break; }

int randomLevel = Q_min(GET_RANDOM(1, 3), playerPointsToSpend);
int randomLevel = 0;
int randNo = GET_RANDOM(0, 100);

if (randNo <= (getProb(fp, 1))) {
randomLevel = 1;
}

if (randNo > (getProb(fp, 1))) {
randomLevel = 2;
}

if (randomLevel > (getProb(fp, 1) + getProb(fp, 2))) {
randomLevel = 3;
}
playerPointsToSpend -= randomLevel;

pState->forcePowerLevel[fp] = randomLevel;
Expand All @@ -757,27 +843,18 @@ static void randomizeForcePowers(playerState_t* pState, std::string mapname = ""
if (GET_RANDOM_MAX(100) > 60) { continue; }

int randomLevel = 0;
// don't make it too easy ;)
if (fp == FP_LEVITATION) {
int randNo = GET_RANDOM(0, 100);
int randNo = GET_RANDOM(0, 100);

if (randNo > (100 - _forceJumpOneProbability)) {
randomLevel = 1;
}

if (randNo > (100 - _forceJumpTwoProbability)) {
randomLevel = 2;
}

if (randomLevel > (100 - _forceJumpThreeProbability)) {
randomLevel = 3;
}

} else {
if (randNo <= (getProb(fp, 1))) {
randomLevel = 1;
}

if (randNo > (getProb(fp, 1))) {
randomLevel = 2;
}

// from 0..3
randomLevel = GET_RANDOM(0, GET_RANDOM(1, 3));
if (randomLevel > (getProb(fp, 1) + getProb(fp, 2))) {
randomLevel = 3;
}

pState->forcePowerLevel[fp] = randomLevel;
Expand All @@ -803,7 +880,20 @@ static void randomizeForcePowers(playerState_t* pState, std::string mapname = ""
for (auto fp : fps_player_shuffled) {
if (maxPoints == 0) { break; }

int randomLevel = Q_min(GET_RANDOM(0, GET_RANDOM(1, GET_RANDOM(2, 3))), maxPoints);
int randomLevel = 0;
int randNo = GET_RANDOM(0, 100);

if (randNo <= (getProb(fp, 1))) {
randomLevel = 1;
}

if (randNo > (getProb(fp, 1))) {
randomLevel = 2;
}

if (randomLevel > (getProb(fp, 1) + getProb(fp, 2))) {
randomLevel = 3;
}

maxPoints -= randomLevel;

Expand Down
83 changes: 83 additions & 0 deletions files/randomizerOptions.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,89 @@
"forceRandomizationMode" : 0,
"weaponRandomizationMode" : 0,

"probability": {
"FP_HEAL": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_JUMP": {
"LVL1": 60.0,
"LVL2": 30.0,
"LVL3": 10.0
},
"FP_SPEED": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_PUSH": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_PULL": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_MINDTRICK": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_GRIP": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_LIGHTNING": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_SABERTHROW": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_SABER_DEFENSE": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_SABER_OFFENSE": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_RAGE": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_PROTECT": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_ABSORB": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_DRAIN": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
},
"FP_SENSE": {
"LVL1": 33.0,
"LVL2": 33.0,
"LVL3": 33.0
}
},

"weapons": {
"t1_sour_0": {
"WP_SABER" : 1,
Expand Down

0 comments on commit 686b1da

Please sign in to comment.