Skip to content

Commit b82242a

Browse files
committed
Revert "use /datum/rng for storyteller stuff"
This reverts commit 3f2ec97.
1 parent 3f2ec97 commit b82242a

File tree

4 files changed

+11
-32
lines changed

4 files changed

+11
-32
lines changed

code/__HELPERS/aneri/rand/instanced.dm

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,12 @@
4242
CRASH("Attempted to do a pick from a non-list")
4343
return ANERI_CALL(instanced_pick)(src, choices)
4444

45-
/datum/rng/proc/pick_n_take(list/choices)
46-
RETURN_TYPE(choices[_].type)
47-
var/len = length(choices)
48-
if(!len)
49-
return
50-
var/picked = rand(1, len)
51-
. = choices[picked]
52-
choices.Cut(picked, picked + 1) //Cut is far more efficient that Remove()
53-
5445
/datum/rng/proc/pick_weighted(list/choices)
5546
RETURN_TYPE(choices[_].type)
5647
if(!islist(choices))
5748
CRASH("Attempted to do a weighted pick from a non-list")
5849
return ANERI_CALL(instanced_pick_weighted)(src, choices)
5950

60-
/datum/rng/proc/pick_weighted_n_take(list/choices)
61-
RETURN_TYPE(choices[_].type)
62-
. = pick_weighted(choices)
63-
choices -= .
64-
6551
/datum/rng/proc/chance(percent) // "prob" is a reserved word, so we do "chance" instead
6652
return ANERI_CALL(instanced_prob)(src, percent)
6753

monkestation/code/modules/storytellers/converted_events/_base_event.dm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@
264264

265265
while(length(weighted_candidates) && length(candidates) < antag_count) //both of these pick_n_take from weighted_candidates so this should be fine
266266
if(prompted_picking)
267-
var/picked_ckey = SSgamemode.rng.pick_weighted_n_take(weighted_candidates)
267+
var/picked_ckey = pick_n_take_weighted(weighted_candidates)
268268
var/client/picked_client = GLOB.directory[picked_ckey]
269269
if(QDELETED(picked_client))
270270
continue
@@ -283,7 +283,7 @@
283283
show_candidate_amount = FALSE,
284284
)
285285
else
286-
var/picked_ckey = SSgamemode.rng.pick_weighted_n_take(weighted_candidates)
286+
var/picked_ckey = pick_n_take_weighted(weighted_candidates)
287287
var/client/picked_client = GLOB.directory[picked_ckey]
288288
if(QDELETED(picked_client))
289289
continue
@@ -298,7 +298,7 @@
298298
message_admins("A roleset event got fewer antags then its antag_count and may not function correctly.")
299299
break
300300

301-
var/mob/candidate = SSgamemode.rng.pick_weighted_n_take(candidates)
301+
var/mob/candidate = pick_n_take(candidates)
302302
log_storyteller("Antag event spawned mob: [candidate], special role: [candidate.mind?.special_role ? candidate.mind.special_role : "none"]")
303303

304304
candidate.client?.prefs.reset_antag_rep()

monkestation/code/modules/storytellers/gamemode_subsystem.dm

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,11 @@ SUBSYSTEM_DEF(gamemode)
162162
/// Are we able to run roundstart events
163163
var/can_run_roundstart = TRUE
164164
var/list/triggered_round_events = list()
165-
var/datum/rng/rng
166165

167166
/datum/controller/subsystem/gamemode/Initialize(time, zlevel)
168167
#if defined(UNIT_TESTS) || defined(AUTOWIKI) // lazy way of doing this but idc
169168
CONFIG_SET(flag/disable_storyteller, TRUE)
170169
#endif
171-
rng = new
172-
173170
// Populate event pools
174171
for(var/track in event_tracks)
175172
event_pools[track] = list()
@@ -204,16 +201,12 @@ SUBSYSTEM_DEF(gamemode)
204201
return SS_INIT_NO_NEED
205202
return SS_INIT_SUCCESS
206203

207-
/datum/controller/subsystem/gamemode/Shutdown()
208-
. = ..()
209-
QDEL_NULL(rng)
210-
211204
/datum/controller/subsystem/gamemode/fire(resumed = FALSE)
212205
if(SSticker.round_start_time && (world.time - SSticker.round_start_time) >= ROUNDSTART_VALID_TIMEFRAME)
213206
can_run_roundstart = FALSE
214207
else if(current_roundstart_event && length(current_roundstart_event.preferred_events)) //note that this implementation is made for preferred_events being other roundstart events
215208
var/list/preferred_copy = current_roundstart_event.preferred_events.Copy()
216-
var/datum/round_event_control/selected_event = rng.pick_weighted(preferred_copy)
209+
var/datum/round_event_control/selected_event = pick_weight(preferred_copy)
217210
var/player_count = get_active_player_count(alive_check = TRUE, afk_check = TRUE, human_check = TRUE)
218211
if(ispath(selected_event)) //get the instances if we dont have them
219212
current_roundstart_event.preferred_events = list()
@@ -228,7 +221,7 @@ SUBSYSTEM_DEF(gamemode)
228221
var/sanity = 0
229222
while(!selected_event && length(preferred_copy) && sanity < 100)
230223
sanity++
231-
selected_event = rng.pick_weighted(preferred_copy)
224+
selected_event = pick_weight(preferred_copy)
232225
if(!selected_event.can_spawn_event(player_count))
233226
preferred_copy -= selected_event
234227
selected_event = null
@@ -399,7 +392,7 @@ SUBSYSTEM_DEF(gamemode)
399392
var/calc_value = base_amt + (gain_amt * ready_players)
400393
calc_value *= roundstart_point_multipliers[track]
401394
calc_value *= current_storyteller.starting_point_multipliers[track]
402-
calc_value *= (rng.ranged_uint(100 - current_storyteller.roundstart_points_variance, 100 + current_storyteller.roundstart_points_variance) / 100)
395+
calc_value *= (rand(100 - current_storyteller.roundstart_points_variance,100 + current_storyteller.roundstart_points_variance)/100)
403396
event_track_points[track] = round(calc_value)
404397

405398
/// If the storyteller guarantees an antagonist roll, add points to make it so.
@@ -696,7 +689,7 @@ ADMIN_VERB(forceGamemode, R_FUN, FALSE, "Open Gamemode Panel", "Opens the gamemo
696689
var/list/possible = subtypesof(/datum/station_goal)
697690
var/goal_weights = 0
698691
while(possible.len && goal_weights < 1) // station goal budget is 1
699-
var/datum/station_goal/picked = rng.pick_n_take(possible)
692+
var/datum/station_goal/picked = pick_n_take(possible)
700693
goal_weights += initial(picked.weight)
701694
GLOB.station_goals += new picked
702695

@@ -780,7 +773,7 @@ ADMIN_VERB(forceGamemode, R_FUN, FALSE, "Open Gamemode Panel", "Opens the gamemo
780773
return
781774
if(length(GLOB.clients) > MAX_POP_FOR_STORYTELLER_VOTE)
782775
secret_storyteller = TRUE
783-
selected_storyteller = rng.pick_weighted(get_valid_storytellers(TRUE))
776+
selected_storyteller = pick_weight(get_valid_storytellers(TRUE))
784777
return
785778
SSvote.initiate_vote(/datum/vote/storyteller, "pick round storyteller", forced = TRUE)
786779

@@ -796,7 +789,7 @@ ADMIN_VERB(forceGamemode, R_FUN, FALSE, "Open Gamemode Panel", "Opens the gamemo
796789
var/added_storytellers = 0
797790
while(added_storytellers < DEFAULT_STORYTELLER_VOTE_OPTIONS && length(pick_from))
798791
added_storytellers++
799-
var/picked_storyteller = rng.pick_weighted(pick_from)
792+
var/picked_storyteller = pick_weight(pick_from)
800793
final_choices[picked_storyteller] = 0
801794
pick_from -= picked_storyteller
802795
return final_choices

monkestation/code/modules/storytellers/storytellers/_storyteller.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
message_admins("Storyteller failed to pick an event for track of [track].")
136136
mode.event_track_points[track] *= TRACK_FAIL_POINT_PENALTY_MULTIPLIER
137137
return
138-
picked_event = SSgamemode.rng.pick_weighted(valid_events)
138+
picked_event = pick_weight(valid_events)
139139
if(!picked_event)
140140
if(length(valid_events))
141141
var/added_string = ""
@@ -176,7 +176,7 @@
176176
// Perhaps use some bell curve instead of a flat variance?
177177
var/total_cost = bought_event.cost * mode.point_thresholds[track]
178178
if(!bought_event.roundstart)
179-
total_cost *= (1 + (SSgamemode.rng.ranged_int(-cost_variance, cost_variance) / 100)) //Apply cost variance if not roundstart event
179+
total_cost *= (1 + (rand(-cost_variance, cost_variance)/100)) //Apply cost variance if not roundstart event
180180
mode.event_track_points[track] = max(mode.event_track_points[track] - total_cost, 0)
181181
message_admins("Storyteller purchased and triggered [bought_event] event, on [track] track, for [total_cost] cost.")
182182
if(bought_event.roundstart)

0 commit comments

Comments
 (0)