Skip to content

Commit

Permalink
Adds saltpetre crystals, which grind into saltpetre (ParadiseSS13#25050)
Browse files Browse the repository at this point in the history
* Added saltpeter crystal, a way to make them, and sprites.

* comment changes

* forgot to undef

* actually undefing this time

* raises saltpeter crystal yield when ground to 8

I did some play testing and it simply takes too many clicks to pump in the ammonia required to get the amount of saltpeter you need.

* The compost bin being full of compost no longer hinders your saltpetre production

* rebuild TGUI

* Allows the compost bin to accept ammonia directly from plants that contain it

* adding the K back to KNO3

* Minor ui adjustments

* Compost bin can use ash now

* I am made of stupid.

* fixing a tiny little offset in the biomass bar

* Icon update, new description for Saltpetre crystals, style fixes and recompile tgui

* period

* minor changes

* rebuild TGUI

* Apply suggestions from code review

Signed-off-by: Matt <[email protected]>

---------

Signed-off-by: Matt <[email protected]>
Co-authored-by: Burzah <[email protected]>
  • Loading branch information
Migratingcocofruit and Burzah authored May 28, 2024
1 parent ae10972 commit 88d236d
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 43 deletions.
14 changes: 14 additions & 0 deletions code/game/objects/items/stacks/sheets/sheet_types.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Brass (clockwork cult)
* Bones
* Plastic
* Saltpetre Crystal
*/

/*
Expand Down Expand Up @@ -692,3 +693,16 @@ GLOBAL_LIST_INIT(plastic_recipes, list(

/obj/item/stack/sheet/plastic/five
amount = 5

/*
* Saltpetre crystal
*/

/obj/item/stack/sheet/saltpetre_crystal
name = "saltpetre crystal"
desc = "A bunch of saltpetre crystals. Can be ground to get liquid saltpetre that can be used to dope hydroponics trays and soil plots."
singular_name = "saltpetre crystal"
icon = 'icons/obj/stacks/organic.dmi'
icon_state = "sheet-saltpetre"
item_state = "sheet-saltpetre"
origin_tech = "materials=1;biotech=1"
138 changes: 121 additions & 17 deletions code/modules/hydroponics/compost_bin.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#define SOIL_COST 25
#define DECAY 0.2
#define MIN_CONVERSION 10
#define BIOMASS_POTASH_RATIO 6
#define BIOMASS_POTASSIUM_RATIO 8
#define POTASH_SALPETRE_MULT 2

/**
* # compost bin
* used to make soil from plants.
Expand All @@ -20,10 +24,20 @@
var/biomass = 0
/// amount of compost in the compost bin
var/compost = 0
/// amount of potassium in the compost bin
var/potassium = 0
/// amount of potash in the compost bin
var/potash = 0
/// amount of saltpetre in the compost bin
var/saltpetre = 0
/// The maximum amount of biomass the compost bin can store.
var/biomass_capacity = 1500
/// The maximum amount of compost the compost bin can store.
var/compost_capacity = 1500
/// The maximum amount of potassium the compost bin can store.
var/potassium_capacity = 200
/// The maximum amount of potash the compost bin can store.
var/potash_capacity = 500

/obj/machinery/compost_bin/on_deconstruction()
// returns wood instead of the non-existent components
Expand All @@ -39,11 +53,15 @@
// no panel either
return default_deconstruction_crowbar(user, I, ignore_panel = TRUE)

// Accepts inserted plants and converts them to biomass
// Accepts inserted plants and converts them to biomass and potassium
/obj/machinery/compost_bin/proc/make_biomass(obj/item/food/snacks/grown/O)
// calculate biomass from plant nutriment and plant matter
var/plant_biomass = O.reagents.get_reagent_amount("nutriment") + O.reagents.get_reagent_amount("plantmatter")
biomass += clamp(plant_biomass * 10, 1, biomass_capacity - biomass)
var/plant_potassium = O.reagents.get_reagent_amount("potassium")
var/plant_potash = O.reagents.get_reagent_amount("ash")
biomass += min(max(plant_biomass * 10, 1), biomass_capacity - biomass)
potassium += min(potassium_capacity - potassium, plant_potassium)
potash += min(potash_capacity - potash, plant_potash)
//plant delenda est
qdel(O)

Expand All @@ -53,30 +71,37 @@
return ..()

if(istype(O, /obj/item/storage/bag/plants))
if(biomass >= biomass_capacity)
to_chat(user, "<span class='warning'>[src] can't hold any more biomass!</span>")
if(biomass >= biomass_capacity && potassium >= potassium_capacity)
to_chat(user, "<span class='warning'>[src] can't hold any more biomass, and it's contents are saturated with potassium!</span>")
return

var/obj/item/storage/bag/plants/PB = O
for(var/obj/item/food/snacks/grown/G in PB.contents)
// if the plant contains either potassium, plantmatter and nutriment and the compost bin has space for any of those.
if((G.reagents.get_reagent_amount("potassium") && potassium <= potassium_capacity) || ((G.reagents.get_reagent_amount("plantmatter") || G.reagents.get_reagent_amount("nutriment")) && biomass <= biomass_capacity))
PB.remove_from_storage(G, src)
make_biomass(G)

PB.remove_from_storage(G, src)
make_biomass(G)

if(biomass >= biomass_capacity)
to_chat(user, "<span class='info'>You fill [src] to its capacity.</span>")
if(biomass >= biomass_capacity && potassium >= potassium_capacity)
break

if(biomass < biomass_capacity)
if(biomass >= biomass_capacity)
to_chat(user, "<span class='info'>You fill [src] to its capacity.</span>")
else
to_chat(user, "<span class='info'>You empty [PB] into [src].</span>")

if(potassium == potassium_capacity)
to_chat(user, "<span class='info'>You have saturated the contents of [src] with potassium.</span>")
else if(potassium >= potassium_capacity * 0.95)
to_chat(user, "<span class='info'>You have very nearly saturated the contents of [src] with potassium.</span>")

SStgui.update_uis(src)
update_icon_state()
return TRUE

if(istype(O, /obj/item/food/snacks/grown))
if(biomass >= biomass_capacity)
to_chat(user, "<span class='warning'>[src] can't hold any more plants!</span>")
if(biomass >= biomass_capacity && potassium >= potassium_capacity)
to_chat(user, "<span class='warning'>[src] can't hold any more biomass, and its contents are saturated with potassium!</span>")
return
if(!user.unEquip(O))
return
Expand All @@ -87,20 +112,92 @@
SStgui.update_uis(src)
update_icon_state()
return TRUE
if(istype(O, /obj/item/reagent_containers))
var/proportion = 0
var/obj/item/reagent_containers/B = O
if(B.reagents.total_volume <= 0)
to_chat(user, "<span class='warning'>[B] is empty!</span>")
return
if(potassium >= potassium_capacity && potash >= potash_capacity)
to_chat(user, "<span class='warning'>The contents of [src] are saturated with potassium and it cannot hold more potash!</span>")
return
// Won't pour in more than the amount of potassium that can be accepted, even if the beaker is not filled with pure potassium.
proportion = min(min(B.reagents.total_volume, B.amount_per_transfer_from_this), potassium_capacity - potassium) / B.reagents.total_volume

// Since the character may not know what's in the beaker, I'm assuming it is assuming the beaker is full of pure potassium and pours according to that.
for(var/E in B.reagents.reagent_list)
var/datum/reagent/R = E
switch(R.id)
if("potassium")
potassium += min(R.volume * proportion, potassium_capacity - potassium)
if("ash")
potash += min(R.volume * proportion, potash_capacity - potash)
if("nutriment")
biomass += min(R.volume * proportion, biomass_capacity - biomass)
if("plantmatter")
biomass += min(R.volume * proportion, biomass_capacity - biomass)

B.reagents.remove_reagent(R.id, R.volume * proportion)

if(proportion == 1)
to_chat(user, "<span class='info'>You empty [B] into [src].</span>")
else
to_chat(user, "<span class='info'>You pour some of [B] into [src].</span>")
if(potassium == potassium_capacity)
to_chat(user, "<span class='info'>You have saturated the contents of [src] with potassium.</span>")
else if(potassium >= potassium_capacity * 0.95)
to_chat(user, "<span class='info'>You have very nearly saturated the contents of [src] with potassium.</span>")

if(potash == potash_capacity)
to_chat(user, "<span class='info'>[src] has been filled with potash.</span>")
else if(potash >= potash_capacity * 0.95)
to_chat(user, "<span class='info'>[src] has been nearly filled with potash.</span>")

SStgui.update_uis(src)
update_icon_state()

return TRUE

to_chat(user, "<span class='warning'>You cannot put this in [name]!</span>")
to_chat(user, "<span class='warning'>You cannot put this in [src]!</span>")

//Compost compostable material if there is any
/obj/machinery/compost_bin/process()
if(compost >= compost_capacity || biomass <= 0)
if((compost >= compost_capacity && potassium <= 0) || biomass <= 0)
return
process_counter++
if(process_counter < 5)
return
process_counter = 0
//converts 20% of the biomass to compost each cycle, unless there isn't enough compost space or there is 10 or less biomass
var/conversion_amount = clamp(DECAY * biomass, min(MIN_CONVERSION, biomass), compost_capacity - compost)
biomass -= conversion_amount
//Converts up to 20% of the biomass to compost each cycle, minimum of 10 converted.
//In the presence of potassium will create saltpetre crystals instead. Using at most the amount of biomass that would've been used for compost
//And making compost from whatever part of that amount it didn't use.
var/conversion_amount = max(DECAY * biomass, min(MIN_CONVERSION, biomass))
var/potash_saltpetre_conversion = 0
var/potassium_saltpetre_conversion = 0
var/used_potassium = 0
var/used_potash = 0

if(potash > 0)
potash_saltpetre_conversion = min(conversion_amount, potash * BIOMASS_POTASH_RATIO)
used_potash = potash_saltpetre_conversion / BIOMASS_POTASH_RATIO
saltpetre += used_potash * POTASH_SALPETRE_MULT
conversion_amount -= potash_saltpetre_conversion
potash -= used_potash

if(potassium > 0)
potassium_saltpetre_conversion = min(conversion_amount, potassium * BIOMASS_POTASSIUM_RATIO)
used_potassium = potassium_saltpetre_conversion / BIOMASS_POTASSIUM_RATIO
saltpetre += used_potassium
conversion_amount -= potassium_saltpetre_conversion
potassium -= used_potassium

if(saltpetre / 4 >= 1)
new /obj/item/stack/sheet/saltpetre_crystal(loc, round(saltpetre / 4))
saltpetre -= round(saltpetre)

conversion_amount = min(conversion_amount, compost_capacity - compost)

biomass -= conversion_amount + potash_saltpetre_conversion + potassium_saltpetre_conversion
compost += conversion_amount
update_icon_state()
SStgui.update_uis(src)
Expand Down Expand Up @@ -134,6 +231,10 @@
data["biomass_capacity"] = biomass_capacity
data["compost"] = compost
data["compost_capacity"] = compost_capacity
data["potassium"] = potassium
data["potassium_capacity"] = potassium_capacity
data["potash"] = potash
data["potash_capacity"] = potash_capacity
return data

// calls functions according to ui interaction(just making compost for now)
Expand Down Expand Up @@ -161,3 +262,6 @@
#undef SOIL_COST
#undef DECAY
#undef MIN_CONVERSION
#undef BIOMASS_POTASH_RATIO
#undef BIOMASS_POTASSIUM_RATIO
#undef POTASH_SALPETRE_MULT
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/obj/item/stack/sheet/mineral/tranquillite = list("nothing" = 20),
/obj/item/stack/sheet/mineral/silver = list("silver" = 20),
/obj/item/stack/sheet/mineral/gold = list("gold" = 20),
/obj/item/stack/sheet/saltpetre_crystal = list("saltpetre" = 8),

// Blender Stuff
/obj/item/food/snacks/grown/tomato = list("ketchup" = 0),
Expand Down
Binary file modified icons/obj/stacks/organic.dmi
Binary file not shown.
61 changes: 52 additions & 9 deletions tgui/packages/tgui/interfaces/CompostBin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,31 @@ import { Window } from '../layouts';

export const CompostBin = (props, context) => {
const { act, data } = useBackend(context);
const { biomass, compost, biomass_capacity, compost_capacity } = data;
const {
biomass,
compost,
biomass_capacity,
compost_capacity,
potassium,
potassium_capacity,
potash,
potash_capacity,
} = data;

let [vendAmount, setVendAmount] = useSharedState(context, 'vendAmount', 1);

return (
<Window width={300} height={175}>
<Window width={360} height={250}>
<Window.Content>
<Stack fill vertical>
<Section label="Resources">
<Stack>
<LabeledList>
<LabeledList.Item label="Biomass">
<ProgressBar
ml={1}
width={17}
ml={0.5}
mt={1}
width={20}
value={biomass}
minValue={0}
maxValue={biomass_capacity}
Expand All @@ -42,15 +52,11 @@ export const CompostBin = (props, context) => {
{biomass} / {biomass_capacity} Units
</ProgressBar>
</LabeledList.Item>
</LabeledList>
</Stack>
<Stack>
<LabeledList>
<LabeledList.Item label="Compost">
<ProgressBar
ml={0.5}
mt={1}
width={17}
width={20}
value={compost}
minValue={0}
maxValue={compost_capacity}
Expand All @@ -66,6 +72,43 @@ export const CompostBin = (props, context) => {
{compost} / {compost_capacity} Units
</ProgressBar>
</LabeledList.Item>
<LabeledList.Item label="Potassium">
<ProgressBar
ml={0.5}
mt={1}
width={20}
value={potassium}
minValue={0}
maxValue={potassium_capacity}
ranges={{
good: [potassium_capacity * 0.5, Infinity],
average: [
potassium_capacity * 0.25,
potassium_capacity * 0.5,
],
bad: [-Infinity, potassium_capacity * 0.25],
}}
>
{potassium} / {potassium_capacity} Units
</ProgressBar>
</LabeledList.Item>
<LabeledList.Item label="Potash">
<ProgressBar
ml={0.5}
mt={1}
width={20}
value={potash}
minValue={0}
maxValue={potash_capacity}
ranges={{
good: [potash_capacity * 0.5, Infinity],
average: [potash_capacity * 0.25, potash_capacity * 0.5],
bad: [-Infinity, potash_capacity * 0.25],
}}
>
{potash} / {potash_capacity} Units
</ProgressBar>
</LabeledList.Item>
</LabeledList>
</Stack>
</Section>
Expand Down
34 changes: 17 additions & 17 deletions tgui/public/tgui.bundle.js

Large diffs are not rendered by default.

0 comments on commit 88d236d

Please sign in to comment.