<commit_before>#define NO_REACTION	0
#define REACTING	1

/datum/controller/subsystem/air/var/list/gas_reactions //this is our singleton of all reactions

/proc/init_gas_reactions()
	var/list/reaction_types = list()
	for(var/r in subtypesof(/datum/gas_reaction))
		var/datum/gas_reaction/reaction = r
		if(!initial(reaction.exclude))
			reaction_types += reaction
	reaction_types = sortList(reaction_types, /proc/cmp_gas_reactions)

	. = list()
	for(var/path in reaction_types)
		. += new path

/proc/cmp_gas_reactions(datum/gas_reaction/a, datum/gas_reaction/b) //sorts in descending order of priority
	return initial(b.priority) - initial(a.priority)

/datum/gas_reaction
	//regarding the requirements lists: the minimum or maximum requirements must be non-zero.
	//when in doubt, use MINIMUM_HEAT_CAPACITY.
	var/list/min_requirements
	var/list/max_requirements
	var/exclude = FALSE //do it this way to allow for addition/removal of reactions midmatch in the future
	var/priority = 100 //lower numbers are checked/react later than higher numbers. if two reactions have the same priority they may happen in either order
	var/name = "reaction"
	var/id = "r"

/datum/gas_reaction/New()
	init_reqs()

/datum/gas_reaction/proc/init_reqs()
/datum/gas_reaction/proc/react(datum/gas_mixture/air, atom/location)
	return NO_REACTION

//agent b: converts hot co2 and agent b to oxygen. requires plasma as a catalyst. endothermic
/datum/gas_reaction/agent_b
	priority = 2
	name = "Agent B"
	id = "agent_b"

/datum/gas_reaction/agent_b/init_reqs()
	min_requirements = list(
		"TEMP" = 900,
		"agent_b" = MINIMUM_HEAT_CAPACITY,
		"plasma" = MINIMUM_HEAT_CAPACITY,
		"co2" = MINIMUM_HEAT_CAPACITY
	)


/datum/gas_reaction/agent_b/react(datum/gas_mixture/air)
	var/list/cached_gases = air.gases
	var/reaction_rate = min(cached_gases["co2"][MOLES]*0.75, cached_gases["plasma"][MOLES]*0.25, cached_gases["agent_b"][MOLES]*0.05)

	cached_gases["co2"][MOLES] -= reaction_rate
	cached_gases["agent_b"][MOLES] -= reaction_rate*0.05

	air.assert_gas("o2") //only need to assert oxygen, as this reaction doesn't occur without the other gases existing
	cached_gases["o2"][MOLES] += reaction_rate

	air.temperature -= (reaction_rate*20000)/air.heat_capacity()

	return REACTING

//freon: does a freezy thing?
/datum/gas_reaction/freon
	priority = 1
	name = "Freon"
	id = "freon"

/datum/gas_reaction/freon/init_reqs()
	min_requirements = list("freon" = MOLES_PLASMA_VISIBLE)

/datum/gas_reaction/freon/react(datum/gas_mixture/air, turf/open/location)
	. = NO_REACTION
	if(location && location.freon_gas_act())
		air.gases["freon"][MOLES] -= MOLES_PLASMA_VISIBLE
		. = REACTING

//water vapor: puts out fires?
/datum/gas_reaction/water_vapor<commit_msg>Since you can properly scrub Freon now, it doesn't destroy itself.<commit_after>#define NO_REACTION	0
#define REACTING	1

/datum/controller/subsystem/air/var/list/gas_reactions //this is our singleton of all reactions

/proc/init_gas_reactions()
	var/list/reaction_types = list()
	for(var/r in subtypesof(/datum/gas_reaction))
		var/datum/gas_reaction/reaction = r
		if(!initial(reaction.exclude))
			reaction_types += reaction
	reaction_types = sortList(reaction_types, /proc/cmp_gas_reactions)

	. = list()
	for(var/path in reaction_types)
		. += new path

/proc/cmp_gas_reactions(datum/gas_reaction/a, datum/gas_reaction/b) //sorts in descending order of priority
	return initial(b.priority) - initial(a.priority)

/datum/gas_reaction
	//regarding the requirements lists: the minimum or maximum requirements must be non-zero.
	//when in doubt, use MINIMUM_HEAT_CAPACITY.
	var/list/min_requirements
	var/list/max_requirements
	var/exclude = FALSE //do it this way to allow for addition/removal of reactions midmatch in the future
	var/priority = 100 //lower numbers are checked/react later than higher numbers. if two reactions have the same priority they may happen in either order
	var/name = "reaction"
	var/id = "r"

/datum/gas_reaction/New()
	init_reqs()

/datum/gas_reaction/proc/init_reqs()
/datum/gas_reaction/proc/react(datum/gas_mixture/air, atom/location)
	return NO_REACTION

//agent b: converts hot co2 and agent b to oxygen. requires plasma as a catalyst. endothermic
/datum/gas_reaction/agent_b
	priority = 2
	name = "Agent B"
	id = "agent_b"

/datum/gas_reaction/agent_b/init_reqs()
	min_requirements = list(
		"TEMP" = 900,
		"agent_b" = MINIMUM_HEAT_CAPACITY,
		"plasma" = MINIMUM_HEAT_CAPACITY,
		"co2" = MINIMUM_HEAT_CAPACITY
	)


/datum/gas_reaction/agent_b/react(datum/gas_mixture/air)
	var/list/cached_gases = air.gases
	var/reaction_rate = min(cached_gases["co2"][MOLES]*0.75, cached_gases["plasma"][MOLES]*0.25, cached_gases["agent_b"][MOLES]*0.05)

	cached_gases["co2"][MOLES] -= reaction_rate
	cached_gases["agent_b"][MOLES] -= reaction_rate*0.05

	air.assert_gas("o2") //only need to assert oxygen, as this reaction doesn't occur without the other gases existing
	cached_gases["o2"][MOLES] += reaction_rate

	air.temperature -= (reaction_rate*20000)/air.heat_capacity()

	return REACTING

//freon: does a freezy thing?
/datum/gas_reaction/freon
	priority = 1
	name = "Freon"
	id = "freon"

/datum/gas_reaction/freon/init_reqs()
	min_requirements = list("freon" = MOLES_PLASMA_VISIBLE)

/datum/gas_reaction/freon/react(datum/gas_mixture/air, turf/open/location)
	. = NO_REACTION
	if(location && location.freon_gas_act())
		. = REACTING

//water vapor: puts out fires?
/datum/gas_reaction/water_vapor
{'fraction_non_alphanumeric': 0.11732355637030248, 'fraction_numerical': 0.012098991750687443, 'mean_word_length': 4.885652642934196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3395176', 'n_tokens_mistral': 2133, 'n_tokens_neox': 2007, 'n_words': 433}