Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors lootdroppers #3526

Merged
merged 36 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
85ada0d
cut icon
FalloutFalcon Oct 10, 2024
99c53e0
standerdizing the sprites a little for mapping helpers
FalloutFalcon Oct 10, 2024
d767ac4
minr icon tweaks
FalloutFalcon Oct 10, 2024
472c1d6
https://github.com/tgstation/tgstation/pull/82729 and https://github.…
FalloutFalcon Oct 10, 2024
bfad938
plently of tweaks
FalloutFalcon Oct 10, 2024
0be3829
haha repaths
FalloutFalcon Oct 10, 2024
5dac8f4
pick_weight
FalloutFalcon Oct 10, 2024
1ce7220
cola
FalloutFalcon Oct 10, 2024
9da26f2
so much
FalloutFalcon Oct 10, 2024
473bb73
find and replace
FalloutFalcon Oct 10, 2024
f416578
revert this pickweight change, investigate later
FalloutFalcon Oct 10, 2024
34f44a4
it compiles..
FalloutFalcon Oct 10, 2024
c9ee62f
stuff
FalloutFalcon Oct 10, 2024
9ba9638
that should catch most of them
FalloutFalcon Oct 10, 2024
94126cf
mhm
FalloutFalcon Oct 10, 2024
3e60862
small fixes
FalloutFalcon Oct 10, 2024
81c1c8d
mhm
FalloutFalcon Oct 10, 2024
db914df
mgm
FalloutFalcon Oct 10, 2024
707e413
mhm
FalloutFalcon Oct 10, 2024
af046df
this hurts.
FalloutFalcon Oct 10, 2024
a1f35e1
mrhm
FalloutFalcon Oct 10, 2024
77cf9a0
yuh
FalloutFalcon Oct 10, 2024
c6dd007
fixes ci
FalloutFalcon Oct 10, 2024
44e4528
yea
FalloutFalcon Oct 10, 2024
dc7801c
Merge branch 'master' of https://github.com/shiptest-ss13/Shiptest in…
FalloutFalcon Oct 15, 2024
4e77f76
anomaly edits
FalloutFalcon Oct 15, 2024
264be9a
Merge branch 'master' of https://github.com/shiptest-ss13/Shiptest in…
FalloutFalcon Oct 17, 2024
fda859d
yea
FalloutFalcon Oct 17, 2024
658cb0c
Merge branch 'master' of https://github.com/shiptest-ss13/Shiptest in…
FalloutFalcon Oct 18, 2024
dcd63ba
new ship paths fix
FalloutFalcon Oct 18, 2024
2b47cbf
Merge branch 'master' of https://github.com/shiptest-ss13/Shiptest in…
FalloutFalcon Oct 18, 2024
f4742ff
fix xenobio removal conflict
FalloutFalcon Oct 18, 2024
22c3a16
runs Update Paths
FalloutFalcon Oct 18, 2024
596e90f
fixed review
FalloutFalcon Oct 24, 2024
ff26491
Merge branch 'master' of https://github.com/shiptest-ss13/Shiptest in…
FalloutFalcon Oct 24, 2024
d2b4f97
update path
FalloutFalcon Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revert this pickweight change, investigate later
  • Loading branch information
FalloutFalcon committed Oct 10, 2024
commit f416578fb11880cd109943ec2d9b808e13235b1f
42 changes: 25 additions & 17 deletions code/__HELPERS/_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,30 @@
result = first ^ second
return result

/**
* Picks a random element from a list based on a weighting system:
* 1. Adds up the total of weights for each element
* 2. Gets a number between 1 and that total
* 3. For each element in the list, subtracts its weighting from that number
* 4. If that makes the number 0 or less, return that element.
* Will output null sometimes if you use decimals (e.g. 0.1 instead of 10) as rand() uses integers, not floats
**/
/proc/pick_weight(list/list_to_pick)
var/total = 0
var/item
for(item in list_to_pick)
if(!list_to_pick[item])
list_to_pick[item] = 1
total += list_to_pick[item]

total = rand(1, total)
for(item in list_to_pick)
total -= list_to_pick[item]
if(total <= 0)
return item

return null

/**
* Picks a random element from a list based on a weighting system.
* For example, given the following list:
Expand All @@ -271,7 +295,7 @@
* and D would have a 0% chance of being picked.
* You should only pass integers in.
*/
/proc/pick_weight(list/list_to_pick)
/proc/pick_weight_allow_zero(list/list_to_pick) //The original pick_weight proc will sometimes pick entries with zero weight. I'm not sure if changing the original will break anything, so I left it be.
if(length(list_to_pick) == 0)
return null

Expand Down Expand Up @@ -330,22 +354,6 @@

return final_list

/proc/pickweightAllowZero(list/L) //The original pick_weight proc will sometimes pick entries with zero weight. I'm not sure if changing the original will break anything, so I left it be.
var/total = 0
var/item
for (item in L)
if (!L[item])
L[item] = 0
total += L[item]

total = rand(0, total)
for (item in L)
total -=L [item]
if (total <= 0 && L[item])
return item

return null

/// Takes a weighted list (see above) and expands it into raw entries
/// This eats more memory, but saves time when actually picking from it
/proc/expand_weights(list/list_to_pick)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/ai_laws.dm
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
var/datum/ai_laws/lawtype
var/list/law_weights = CONFIG_GET(keyed_list/law_weight)
while(!lawtype && law_weights.len)
var/possible_id = pickweightAllowZero(law_weights)
var/possible_id = pick_weight_allow_zero(law_weights)
lawtype = lawid_to_type(possible_id)
if(!lawtype)
law_weights -= possible_id
Expand Down
2 changes: 1 addition & 1 deletion code/game/gamemodes/game_mode.dm
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
reports += config.mode_reports[report_type]
Count++
for(var/i in Count to rand(3,5)) //Between three and five wrong entries on the list.
var/false_report_type = pickweightAllowZero(report_weights)
var/false_report_type = pick_weight_allow_zero(report_weights)
report_weights[false_report_type] = 0 //Make it so the same false report won't be selected twice
reports += config.mode_reports[false_report_type]

Expand Down
2 changes: 2 additions & 0 deletions code/game/objects/effects/spawners/random.dm/maintenance.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
lootcount_override = spawn_loot_count
. = ..()

/* Fucks everything. Investigate further
// In addition, closets that are closed will have the maintenance loot inserted inside.
for(var/obj/structure/closet/closet in get_turf(src))
if(!closet.opened)
closet.take_contents()
*/

/obj/effect/spawner/random/maintenance/two
name = "2 x maintenance loot spawner"
Expand Down
4 changes: 2 additions & 2 deletions code/modules/overmap/objects/dynamic_datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
probabilities = list()
for(var/datum/planet_type/planet_type as anything in subtypesof(/datum/planet_type))
probabilities[initial(planet_type.planet)] = initial(planet_type.weight)
planet = SSmapping.planet_types[force_encounter ? force_encounter : pickweightAllowZero(probabilities)]
planet = SSmapping.planet_types[force_encounter ? force_encounter : pick_weight_allow_zero(probabilities)]


if(planet.planet !=DYNAMIC_WORLD_ASTEROID && planet.planet != DYNAMIC_WORLD_SPACERUIN) //these aren't real planets
Expand Down Expand Up @@ -192,7 +192,7 @@
log_shuttle("[src] [REF(src)] LEVEL_INIT")

// use the ruin type in template if it exists, or pick from ruin list if IT exists; otherwise null
var/selected_ruin = template || (ruin_type ? pickweightAllowZero(SSmapping.ruin_types_probabilities[ruin_type]) : null)
var/selected_ruin = template || (ruin_type ? pick_weight_allow_zero(SSmapping.ruin_types_probabilities[ruin_type]) : null)
var/list/dynamic_encounter_values = SSovermap.spawn_dynamic_encounter(src, selected_ruin)
if(!length(dynamic_encounter_values))
return FALSE
Expand Down