summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgumi <git@gumi.ca>2018-07-29 13:13:56 -0400
committergumi <git@gumi.ca>2018-07-29 13:13:56 -0400
commitb1944fc9205c72ac94cc87271bd1d4a16318f4a7 (patch)
treedb8c471491da20e57e0777bffd702442056f7a5e
parentfe4176db36f94036105e841dc56e5dee85e96318 (diff)
downloadserverdata-b1944fc9205c72ac94cc87271bd1d4a16318f4a7.tar.gz
serverdata-b1944fc9205c72ac94cc87271bd1d4a16318f4a7.tar.bz2
serverdata-b1944fc9205c72ac94cc87271bd1d4a16318f4a7.tar.xz
serverdata-b1944fc9205c72ac94cc87271bd1d4a16318f4a7.zip
fix some edge cases in relative_array_random()
-rw-r--r--npc/functions/RNGesus.txt10
1 files changed, 7 insertions, 3 deletions
diff --git a/npc/functions/RNGesus.txt b/npc/functions/RNGesus.txt
index 7d2ff7c7..6883f8f1 100644
--- a/npc/functions/RNGesus.txt
+++ b/npc/functions/RNGesus.txt
@@ -44,9 +44,9 @@ function script relative_array_random {
for (.@i = .@initial_index + 1; .@i < .@size; .@i += 2) {
if (.@is_str) {
- .@total_prob += atoi(getelementofarray(getarg(0), .@i));
+ .@total_prob += max(1, atoi(getelementofarray(getarg(0), .@i)));
} else {
- .@total_prob += getelementofarray(getarg(0), .@i);
+ .@total_prob += max(1, getelementofarray(getarg(0), .@i));
}
}
@@ -54,7 +54,7 @@ function script relative_array_random {
set(getelementofarray(getarg(0), 0), .@total_prob);
}
- .@target_sum = rand(.@total_prob);
+ .@target_sum = rand(0, .@total_prob);
for (.@i = .@initial_index; .@sum < .@target_sum; .@i += 2) {
if (.@is_str) {
@@ -62,6 +62,10 @@ function script relative_array_random {
} else {
.@sum += getelementofarray(getarg(0), .@i + 1);
}
+
+ if (.@sum >= .@target_sum) {
+ break;
+ }
}
freeloop(false);