Skip to content

Commit

Permalink
handheld Experimenters give more helpful feedback (tgstation#82235)
Browse files Browse the repository at this point in the history
## About The Pull Request

Handheld experimenters now will tell you if the machine parts are not
high enough tier, not the exact needed tier, if scanned mechs are
missing equipment in arms, and if scanned mech is not hand-crafted.

## Why It's Good For The Game

Helps players (me) understand why I can't scan the kiosk for the
experiment (I didn't read).

## Changelog

:cl:
qol: some experiments now give you more helpful hints at why your
failing
code: changes around some experiment code to make it more understandable
/:cl:
  • Loading branch information
Bilbo367 authored Apr 2, 2024
1 parent cdaeb64 commit e4de9ef
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 56 deletions.
20 changes: 0 additions & 20 deletions code/modules/experisci/experiment/experiments.dm
Original file line number Diff line number Diff line change
Expand Up @@ -323,32 +323,12 @@
///Damage percent that each mech needs to be at for a scan to work.
var/damage_percent

/datum/experiment/scanning/random/mecha_damage_scan/New(datum/techweb/techweb)
. = ..()
damage_percent = rand(15, 95)
//updating the description with the damage_percent var set
description = "Your exosuit fabricators allow for rapid production on a small scale, but the structural integrity of created parts is inferior to those made with more traditional means. Damage a few exosuits to around [damage_percent]% integrity and scan them to help us determine how the armor fails under stress."

/datum/experiment/scanning/random/mecha_damage_scan/final_contributing_index_checks(atom/target, typepath)
var/found_percent = round((target.get_integrity() / target.max_integrity) * 100)
return ..() && ISINRANGE(found_percent, damage_percent - 5, damage_percent + 5)

/datum/experiment/scanning/random/mecha_equipped_scan
name = "Exosuit Materials 2: Load Strain Test"
description = "Exosuit equipment places unique strain upon the structure of the vehicle. Scan exosuits you have assembled from your exosuit fabricator and fully equipped to accelerate our structural stress simulations."
possible_types = list(/obj/vehicle/sealed/mecha)
total_requirement = 2

/datum/experiment/scanning/random/mecha_equipped_scan/final_contributing_index_checks(atom/target, typepath)
var/obj/vehicle/sealed/mecha/stompy = target
if(!istype(stompy))
return FALSE //Not a mech
if(!HAS_TRAIT(stompy,TRAIT_MECHA_CREATED_NORMALLY))
return FALSE //Not hand-crafted
if(!(stompy.equip_by_category[MECHA_L_ARM] && stompy.equip_by_category[MECHA_R_ARM]))
return FALSE //Both arms need be filled
return ..()

/// Scan for organs you didn't start the round with
/datum/experiment/scanning/people/novel_organs
name = "Human Field Research: Divergent Biology"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@
playsound(user, 'sound/machines/buzz-sigh.ogg', 25)
to_chat(user, span_notice("[target] is not related to your currently selected experiment."))


/**
* Hooks on destructive scans to try and run an experiment (When using a handheld handler)
*/
Expand Down
22 changes: 22 additions & 0 deletions code/modules/experisci/experiment/types/random_scanning.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,25 @@

// Fill the experiment as per usual
..()

/datum/experiment/scanning/random/mecha_damage_scan/New(datum/techweb/techweb)
. = ..()
damage_percent = rand(15, 95)
//updating the description with the damage_percent var set
description = "Your exosuit fabricators allow for rapid production on a small scale, but the structural integrity of created parts is inferior to those made with more traditional means. Damage a few exosuits to around [damage_percent]% integrity and scan them to help us determine how the armor fails under stress."

/datum/experiment/scanning/random/mecha_damage_scan/final_contributing_index_checks(datum/component/experiment_handler/experiment_handler, atom/target, typepath)
var/found_percent = round((target.get_integrity() / target.max_integrity) * 100)
return ..() && ISINRANGE(found_percent, damage_percent - 5, damage_percent + 5)

/datum/experiment/scanning/random/mecha_equipped_scan/final_contributing_index_checks(datum/component/experiment_handler/experiment_handler, atom/target, typepath)
var/obj/vehicle/sealed/mecha/stompy = target
if(!istype(stompy))
return FALSE //Not a mech
if(!HAS_TRAIT(stompy,TRAIT_MECHA_CREATED_NORMALLY))
experiment_handler.announce_message("Scanned mech was not made by crew. There is nothing to learn here.")
return FALSE //Not hand-crafted
if(!(stompy.equip_by_category[MECHA_L_ARM] && stompy.equip_by_category[MECHA_R_ARM]))
experiment_handler.announce_message("Scanned mech is missing equipment on their arms to proceed this experiment.")
return FALSE //Both arms need be filled
return ..()
40 changes: 17 additions & 23 deletions code/modules/experisci/experiment/types/scanning.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
/**
* Checks if the scanning experiment is complete
*
* Returns TRUE/FALSE as to if the necessary number of atoms have been
* scanned.
* Returns TRUE/FALSE as to if the necessary number of atoms have been scanned.
*/
/datum/experiment/scanning/is_complete()
. = TRUE
Expand Down Expand Up @@ -84,8 +83,8 @@
* * target - The atom to attempt to scan
*/
/datum/experiment/scanning/perform_experiment_actions(datum/component/experiment_handler/experiment_handler, atom/target)
var/contributing_index_value = get_contributing_index(target)
if (contributing_index_value)
var/contributing_index_value = experiment_requirements(experiment_handler, target)
if (!isnull(contributing_index_value))
if(traits & EXPERIMENT_TRAIT_TYPECACHE)
scanned[contributing_index_value][target.type] = TRUE
else
Expand All @@ -96,7 +95,7 @@
return TRUE

/datum/experiment/scanning/actionable(datum/component/experiment_handler/experiment_handler, atom/target)
return ..() && get_contributing_index(target)
return ..() && !isnull(experiment_requirements(experiment_handler, target))

/**
* Attempts to get the typepath for an atom that would contribute to the experiment
Expand All @@ -106,34 +105,29 @@
* Arguments:
* * target - The atom to attempt to scan
*/
/datum/experiment/scanning/proc/get_contributing_index(atom/target)
var/destructive = traits & EXPERIMENT_TRAIT_DESTRUCTIVE
/datum/experiment/scanning/proc/experiment_requirements(datum/component/experiment_handler/experiment_handler, atom/target)
for (var/req_atom in required_atoms)
if (!istype(target, req_atom))
continue

// Try to select a required atom that this scanned atom would contribute towards
var/selected
var/list/seen = scanned[req_atom]
if (destructive && (req_atom in scanned) && scanned[req_atom] < required_atoms[req_atom])
selected = req_atom
else if (!destructive && seen.len < required_atoms[req_atom] && !(WEAKREF(target) in seen))
selected = req_atom

// Run any additonal checks if necessary
if (selected && final_contributing_index_checks(target, selected))
return selected
if (istype(target, req_atom))
// Try to select a required atom that this scanned atom would contribute towards
var/destructive = traits & EXPERIMENT_TRAIT_DESTRUCTIVE
var/list/seen = scanned[req_atom]
var/selected = destructive && (req_atom in scanned) && seen < required_atoms[req_atom]
if (!selected)
selected = !destructive && seen.len < required_atoms[req_atom] && !(WEAKREF(target) in seen)
// Run any additonal checks if necessary
if (selected && final_contributing_index_checks(experiment_handler, target, selected))
return req_atom

/**
* Performs any additional checks against the atom being considered for selection as a contributing index
*
* This proc is intended to be used to add additional functionality to contributing index checks
* without having to duplicate the iteration structure of get_contributing_index()
* without having to duplicate the iteration structure of experiment_requirements()
* Arguments:
* * target - The atom being scanned
* * typepath - The typepath (selected index) of the target atom
*/
/datum/experiment/scanning/proc/final_contributing_index_checks(atom/target, typepath)
/datum/experiment/scanning/proc/final_contributing_index_checks(datum/component/experiment_handler/experiment_handler, atom/target, typepath)
return TRUE

/**
Expand Down
4 changes: 2 additions & 2 deletions code/modules/experisci/experiment/types/scanning_fish.dm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ GLOBAL_LIST_EMPTY(scanned_fish_by_techweb)
examine_list += message

///Only scannable fish will contribute towards the experiment.
/datum/experiment/scanning/fish/final_contributing_index_checks(obj/item/fish/target, typepath)
/datum/experiment/scanning/fish/final_contributing_index_checks(datum/component/experiment_handler/experiment_handler, obj/item/fish/target, typepath)
return target.experisci_scannable

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ GLOBAL_LIST_EMPTY(scanned_fish_by_techweb)
fish_source_reward = /datum/fish_source/portal/random

///holo fishes are normally unscannable, but this is an experiment for them, so we don't care for the experisci_scannable variable.
/datum/experiment/scanning/fish/holographic/final_contributing_index_checks(obj/item/fish/target, typepath)
/datum/experiment/scanning/fish/holographic/final_contributing_index_checks(datum/component/experiment_handler/experiment_handler, obj/item/fish/target, typepath)
return TRUE

/datum/experiment/scanning/fish/fourth
Expand Down
6 changes: 4 additions & 2 deletions code/modules/experisci/experiment/types/scanning_machinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
. = ..()
.[1] = EXPERIMENT_PROG_INT("Scan samples of the following machines built with parts of tier [required_tier] or better.", points, required_points)[1]

/datum/experiment/scanning/points/machinery_tiered_scan/final_contributing_index_checks(atom/target, typepath)
/datum/experiment/scanning/points/machinery_tiered_scan/final_contributing_index_checks(datum/component/experiment_handler/experiment_handler, atom/target, typepath)
. = ..()
if(!.)
return FALSE
Expand All @@ -26,6 +26,7 @@
for(var/datum/stock_part/datum_stock_part in machine.component_parts)
if(datum_stock_part.tier >= required_tier)
return TRUE
experiment_handler.announce_message("Scanned machine is missing high enough quality parts. Expecting tier [required_tier] parts or better.")
return FALSE

//This experiment type will turn up TRUE if there is a specific part in the scanned machine
Expand All @@ -42,7 +43,7 @@
. = ..()
.[1] = EXPERIMENT_PROG_INT("Scan samples of the following machines upgraded with \a [initial(required_stock_part.name)] to accumulate enough points to complete this experiment.", points, required_points)[1]

/datum/experiment/scanning/points/machinery_pinpoint_scan/final_contributing_index_checks(atom/target, typepath)
/datum/experiment/scanning/points/machinery_pinpoint_scan/final_contributing_index_checks(datum/component/experiment_handler/experiment_handler, atom/target, typepath)
. = ..()
if(!.)
return FALSE
Expand All @@ -56,4 +57,5 @@
for(var/datum/stock_part/datum_stock_part in machine.component_parts)
if(istype(datum_stock_part.physical_object_reference, required_stock_part))
return TRUE
experiment_handler.announce_message("Scanned machine is missing an exact quality part. Expecting tier [required_stock_part.name] part.")
return FALSE
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
var/chosen_material = pick(possible_material_types)
required_materials[req_atom] = chosen_material

/datum/experiment/scanning/random/material/final_contributing_index_checks(atom/target, typepath)
/datum/experiment/scanning/random/material/final_contributing_index_checks(datum/component/experiment_handler/experiment_handler, atom/target, typepath)
return ..() && target.custom_materials && target.has_material_type(required_materials[typepath])

/datum/experiment/scanning/random/material/serialize_progress_stage(atom/target, list/seen_instances)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/experisci/experiment/types/scanning_people.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
required_atoms = list(/mob/living/carbon/human = required_count)
return ..()

/datum/experiment/scanning/people/final_contributing_index_checks(atom/target, typepath)
/datum/experiment/scanning/people/final_contributing_index_checks(datum/component/experiment_handler/experiment_handler, atom/target, typepath)
. = ..()
if(!.)
return FALSE
Expand Down
8 changes: 5 additions & 3 deletions code/modules/experisci/experiment/types/scanning_plants.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
return EXPERIMENT_PROG_INT("Scan samples of a harvested plant.", \
traits & EXPERIMENT_TRAIT_DESTRUCTIVE ? scanned[target] : seen_instances.len, required_atoms[target])

/datum/experiment/scanning/random/plants/traits/final_contributing_index_checks(atom/target, typepath)
/datum/experiment/scanning/random/plants/traits/final_contributing_index_checks(datum/component/experiment_handler/experiment_handler, atom/target, typepath)
if(!istype(target, /obj/item/food/grown))
return FALSE
var/obj/item/food/grown/crop = target
if(possible_plant_genes.len)
return ..() && crop.seed.get_gene(required_genes[typepath])
if(isnull(crop.seed.get_gene(required_genes[typepath])))
experiment_handler.announce_message("Scanned plant is missing required genetics. Please scan a plant with the proper genetics.")
return ..() && !isnull(crop.seed.get_gene(required_genes[typepath]))
return ..()

/datum/experiment/scanning/random/plants/traits/serialize_progress_stage(atom/target, list/seen_instances)
Expand All @@ -35,5 +37,5 @@
return EXPERIMENT_PROG_INT("Scan samples of harvested plants with the trait: [initial(gene.name)].", \
traits & EXPERIMENT_TRAIT_DESTRUCTIVE ? scanned[target] : seen_instances.len, required_atoms[target])

/datum/experiment/scanning/random/plants/wild/final_contributing_index_checks(atom/target, typepath)
/datum/experiment/scanning/random/plants/wild/final_contributing_index_checks(datum/component/experiment_handler/experiment_handler, atom/target, typepath)
return ..() && HAS_TRAIT(target, TRAIT_PLANT_WILDMUTATE)
4 changes: 2 additions & 2 deletions code/modules/experisci/experiment/types/scanning_points.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
var/types_joined = types.Join(", ")
. += EXPERIMENT_PROG_DETAIL("[text2num(point_amt)] point\s: [types_joined]", complete)

/datum/experiment/scanning/points/get_contributing_index(atom/target)
/datum/experiment/scanning/points/experiment_requirements(datum/component/experiment_handler/experiment_handler, atom/target)
var/destructive = traits & EXPERIMENT_TRAIT_DESTRUCTIVE
for (var/req_atom in required_atoms)
if (!istype(target, req_atom))
Expand All @@ -38,7 +38,7 @@
selected = req_atom

// Run any additonal checks if necessary
if (selected && final_contributing_index_checks(target, selected))
if (selected && final_contributing_index_checks(experiment_handler, target, selected))
return selected

/datum/experiment/scanning/points/do_after_experiment(atom/target, typepath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
possible_types = list(/mob/living/basic/cockroach)
traits = EXPERIMENT_TRAIT_DESTRUCTIVE

/datum/experiment/scanning/random/cytology/final_contributing_index_checks(atom/target, typepath)
/datum/experiment/scanning/random/cytology/final_contributing_index_checks(datum/component/experiment_handler/experiment_handler, atom/target, typepath)
return ..() && HAS_TRAIT(target, TRAIT_VATGROWN)

/datum/experiment/scanning/random/cytology/serialize_progress_stage(atom/target, list/seen_instances)
Expand Down

0 comments on commit e4de9ef

Please sign in to comment.