mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-13 03:33:21 +00:00
Updates chemistry colors
This commit is contained in:
@@ -435,6 +435,34 @@ datum/projectile_data
|
|||||||
var/b = mixOneColor(weights, blues)
|
var/b = mixOneColor(weights, blues)
|
||||||
return rgb(r,g,b)
|
return rgb(r,g,b)
|
||||||
|
|
||||||
|
/proc/mixOneColor(var/list/weight, var/list/color)
|
||||||
|
if (!weight || !color || length(weight)!=length(color))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
var/contents = length(weight)
|
||||||
|
var/i
|
||||||
|
|
||||||
|
//normalize weights
|
||||||
|
var/listsum = 0
|
||||||
|
for(i=1; i<=contents; i++)
|
||||||
|
listsum += weight[i]
|
||||||
|
for(i=1; i<=contents; i++)
|
||||||
|
weight[i] /= listsum
|
||||||
|
|
||||||
|
//mix them
|
||||||
|
var/mixedcolor = 0
|
||||||
|
for(i=1; i<=contents; i++)
|
||||||
|
mixedcolor += weight[i]*color[i]
|
||||||
|
mixedcolor = round(mixedcolor)
|
||||||
|
|
||||||
|
//until someone writes a formal proof for this algorithm, let's keep this in
|
||||||
|
// if(mixedcolor<0x00 || mixedcolor>0xFF)
|
||||||
|
// return 0
|
||||||
|
//that's not the kind of operation we are running here, nerd
|
||||||
|
mixedcolor=min(max(mixedcolor,0),255)
|
||||||
|
|
||||||
|
return mixedcolor
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the highest and lowest pressures from the tiles in cardinal directions
|
* Gets the highest and lowest pressures from the tiles in cardinal directions
|
||||||
* around us, then checks the difference.
|
* around us, then checks the difference.
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
if(80 to 90) filling.icon_state = "reagent80"
|
if(80 to 90) filling.icon_state = "reagent80"
|
||||||
if(91 to INFINITY) filling.icon_state = "reagent100"
|
if(91 to INFINITY) filling.icon_state = "reagent100"
|
||||||
|
|
||||||
filling.icon += mix_color_from_reagents(reagents.reagent_list)
|
filling.icon += reagents.get_color()
|
||||||
overlays += filling
|
overlays += filling
|
||||||
|
|
||||||
/obj/machinery/iv_drip/MouseDrop(over_object, src_location, over_location)
|
/obj/machinery/iv_drip/MouseDrop(over_object, src_location, over_location)
|
||||||
|
|||||||
@@ -155,7 +155,7 @@
|
|||||||
|
|
||||||
|
|
||||||
//build smoke icon
|
//build smoke icon
|
||||||
var/color = mix_color_from_reagents(chemholder.reagents.reagent_list)
|
var/color = chemholder.reagents.get_color()
|
||||||
var/icon/I
|
var/icon/I
|
||||||
if(color)
|
if(color)
|
||||||
I = icon('icons/effects/chemsmoke.dmi')
|
I = icon('icons/effects/chemsmoke.dmi')
|
||||||
|
|||||||
@@ -1,66 +1,23 @@
|
|||||||
/proc/mix_color_from_reagents(var/list/reagent_list)
|
/datum/reagents/proc/get_color()
|
||||||
if(!reagent_list || !length(reagent_list))
|
if(!reagent_list || !reagent_list.len)
|
||||||
return 0
|
return "#ffffffff"
|
||||||
|
if(reagent_list.len == 1) // It's pretty common and saves a lot of work
|
||||||
|
var/datum/reagent/R = reagent_list[1]
|
||||||
|
return R.color
|
||||||
|
|
||||||
var/contents = length(reagent_list)
|
var/list/colors = list(0, 0, 0, 0)
|
||||||
var/list/weight = new /list(contents)
|
var/tot_w = 0
|
||||||
var/list/redcolor = new /list(contents)
|
for(var/datum/reagent/R in reagent_list)
|
||||||
var/list/greencolor = new /list(contents)
|
var/hex = uppertext(R.color)
|
||||||
var/list/bluecolor = new /list(contents)
|
if(length(hex) == 7)
|
||||||
var/i
|
hex += "FF"
|
||||||
|
if(length(hex) != 9) // PANIC PANIC PANIC
|
||||||
|
warning("Reagent [R.id] has an incorrect color set ([R.color])")
|
||||||
|
hex = "#FFFFFFFF"
|
||||||
|
colors[1] += hex2num(copytext(hex, 2, 4)) * R.volume * R.color_weight
|
||||||
|
colors[2] += hex2num(copytext(hex, 4, 6)) * R.volume * R.color_weight
|
||||||
|
colors[3] += hex2num(copytext(hex, 6, 8)) * R.volume * R.color_weight
|
||||||
|
colors[4] += hex2num(copytext(hex, 8, 10)) * R.volume * R.color_weight
|
||||||
|
tot_w += R.volume * R.color_weight
|
||||||
|
|
||||||
//fill the list of weights
|
return rgb(colors[1] / tot_w, colors[2] / tot_w, colors[3] / tot_w, colors[4] / tot_w)
|
||||||
for(i=1; i<=contents; i++)
|
|
||||||
var/datum/reagent/re = reagent_list[i]
|
|
||||||
var/reagentweight = re.volume
|
|
||||||
if(istype(re, /datum/reagent/paint))
|
|
||||||
reagentweight *= 20 //Paint colours a mixture twenty times as much
|
|
||||||
weight[i] = reagentweight
|
|
||||||
|
|
||||||
|
|
||||||
//fill the lists of colours
|
|
||||||
for(i=1; i<=contents; i++)
|
|
||||||
var/datum/reagent/re = reagent_list[i]
|
|
||||||
var/hue = re.color
|
|
||||||
if(length(hue) != 7)
|
|
||||||
return 0
|
|
||||||
redcolor[i]=hex2num(copytext(hue,2,4))
|
|
||||||
greencolor[i]=hex2num(copytext(hue,4,6))
|
|
||||||
bluecolor[i]=hex2num(copytext(hue,6,8))
|
|
||||||
|
|
||||||
//mix all the colors
|
|
||||||
var/red = mixOneColor(weight,redcolor)
|
|
||||||
var/green = mixOneColor(weight,greencolor)
|
|
||||||
var/blue = mixOneColor(weight,bluecolor)
|
|
||||||
|
|
||||||
//assemble all the pieces
|
|
||||||
var/finalcolor = rgb(red, green, blue)
|
|
||||||
return finalcolor
|
|
||||||
|
|
||||||
/proc/mixOneColor(var/list/weight, var/list/color)
|
|
||||||
if (!weight || !color || length(weight)!=length(color))
|
|
||||||
return 0
|
|
||||||
|
|
||||||
var/contents = length(weight)
|
|
||||||
var/i
|
|
||||||
|
|
||||||
//normalize weights
|
|
||||||
var/listsum = 0
|
|
||||||
for(i=1; i<=contents; i++)
|
|
||||||
listsum += weight[i]
|
|
||||||
for(i=1; i<=contents; i++)
|
|
||||||
weight[i] /= listsum
|
|
||||||
|
|
||||||
//mix them
|
|
||||||
var/mixedcolor = 0
|
|
||||||
for(i=1; i<=contents; i++)
|
|
||||||
mixedcolor += weight[i]*color[i]
|
|
||||||
mixedcolor = round(mixedcolor)
|
|
||||||
|
|
||||||
//until someone writes a formal proof for this algorithm, let's keep this in
|
|
||||||
// if(mixedcolor<0x00 || mixedcolor>0xFF)
|
|
||||||
// return 0
|
|
||||||
//that's not the kind of operation we are running here, nerd
|
|
||||||
mixedcolor=min(max(mixedcolor,0),255)
|
|
||||||
|
|
||||||
return mixedcolor
|
|
||||||
@@ -470,47 +470,9 @@ datum
|
|||||||
|
|
||||||
var/datum/reagent/R = A
|
var/datum/reagent/R = A
|
||||||
if (R.id == reagent)
|
if (R.id == reagent)
|
||||||
|
R.on_merge(data, amount)
|
||||||
R.volume += amount
|
R.volume += amount
|
||||||
update_total()
|
update_total()
|
||||||
|
|
||||||
// mix dem viruses
|
|
||||||
if(R.id == "blood" && reagent == "blood")
|
|
||||||
if(R.data && data)
|
|
||||||
|
|
||||||
if(R.data["viruses"] || data["viruses"])
|
|
||||||
|
|
||||||
var/list/mix1 = R.data["viruses"]
|
|
||||||
var/list/mix2 = data["viruses"]
|
|
||||||
|
|
||||||
// Stop issues with the list changing during mixing.
|
|
||||||
var/list/to_mix = list()
|
|
||||||
|
|
||||||
for(var/datum/disease/advance/AD in mix1)
|
|
||||||
to_mix += AD
|
|
||||||
for(var/datum/disease/advance/AD in mix2)
|
|
||||||
to_mix += AD
|
|
||||||
|
|
||||||
var/datum/disease/advance/AD = Advance_Mix(to_mix)
|
|
||||||
if(AD)
|
|
||||||
var/list/preserve = list(AD)
|
|
||||||
for(var/D in R.data["viruses"])
|
|
||||||
if(!istype(D, /datum/disease/advance))
|
|
||||||
preserve += D
|
|
||||||
R.data["viruses"] = preserve
|
|
||||||
if(R.id == "paint" && reagent == "paint")
|
|
||||||
if(R.color && data)
|
|
||||||
var/list/mix = new /list(2)
|
|
||||||
//fill the list
|
|
||||||
var/datum/reagent/paint/P = chemical_reagents_list["paint"]
|
|
||||||
var/datum/reagent/paint/P1 = new P.type()
|
|
||||||
P1.color = R.color
|
|
||||||
P1.volume = R.volume - amount //since we just increased that
|
|
||||||
var/datum/reagent/paint/P2 = new P.type()
|
|
||||||
P2.color = data
|
|
||||||
P2.volume = amount
|
|
||||||
mix[1] = P1
|
|
||||||
mix[2] = P2
|
|
||||||
R.color = mix_color_from_reagents(mix)
|
|
||||||
if(!safety)
|
if(!safety)
|
||||||
handle_reactions()
|
handle_reactions()
|
||||||
my_atom.on_reagent_change()
|
my_atom.on_reagent_change()
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ datum
|
|||||||
var/glass_desc = null
|
var/glass_desc = null
|
||||||
var/glass_center_of_mass = null
|
var/glass_center_of_mass = null
|
||||||
//var/list/viruses = list()
|
//var/list/viruses = list()
|
||||||
var/color = "#000000" // rgb: 0, 0, 0 (does not support alpha channels - yet!)
|
var/color = "#000000" // rgb: 0, 0, 0, 0 - supports alpha channels
|
||||||
|
var/color_weight = 1
|
||||||
|
|
||||||
proc
|
proc
|
||||||
reaction_mob(var/mob/M, var/method=TOUCH, var/volume) //By default we have a chance to transfer some
|
reaction_mob(var/mob/M, var/method=TOUCH, var/volume) //By default we have a chance to transfer some
|
||||||
@@ -89,7 +90,7 @@ datum
|
|||||||
return
|
return
|
||||||
|
|
||||||
// Called when two reagents of the same are mixing. <-- Blatant lies
|
// Called when two reagents of the same are mixing. <-- Blatant lies
|
||||||
on_merge(var/data)
|
on_merge(var/newdata, var/newamount)
|
||||||
return
|
return
|
||||||
|
|
||||||
on_update(var/atom/A)
|
on_update(var/atom/A)
|
||||||
@@ -135,9 +136,32 @@ datum
|
|||||||
var/mob/living/carbon/C = M
|
var/mob/living/carbon/C = M
|
||||||
C.antibodies |= self.data["antibodies"]
|
C.antibodies |= self.data["antibodies"]
|
||||||
|
|
||||||
on_merge(var/data)
|
on_merge(var/newdata, var/newamount)
|
||||||
if(data["blood_colour"])
|
if(!data || !newdata)
|
||||||
color = data["blood_colour"]
|
return
|
||||||
|
if(newdata["blood_colour"])
|
||||||
|
color = newdata["blood_colour"]
|
||||||
|
if(data && newdata)
|
||||||
|
if(data["viruses"] || newdata["viruses"])
|
||||||
|
|
||||||
|
var/list/mix1 = data["viruses"]
|
||||||
|
var/list/mix2 = newdata["viruses"]
|
||||||
|
|
||||||
|
// Stop issues with the list changing during mixing.
|
||||||
|
var/list/to_mix = list()
|
||||||
|
|
||||||
|
for(var/datum/disease/advance/AD in mix1)
|
||||||
|
to_mix += AD
|
||||||
|
for(var/datum/disease/advance/AD in mix2)
|
||||||
|
to_mix += AD
|
||||||
|
|
||||||
|
var/datum/disease/advance/AD = Advance_Mix(to_mix)
|
||||||
|
if(AD)
|
||||||
|
var/list/preserve = list(AD)
|
||||||
|
for(var/D in data["viruses"])
|
||||||
|
if(!istype(D, /datum/disease/advance))
|
||||||
|
preserve += D
|
||||||
|
data["viruses"] = preserve
|
||||||
return ..()
|
return ..()
|
||||||
|
|
||||||
on_update(var/atom/A)
|
on_update(var/atom/A)
|
||||||
@@ -204,7 +228,7 @@ datum
|
|||||||
id = "water"
|
id = "water"
|
||||||
description = "A ubiquitous chemical substance that is composed of hydrogen and oxygen."
|
description = "A ubiquitous chemical substance that is composed of hydrogen and oxygen."
|
||||||
reagent_state = LIQUID
|
reagent_state = LIQUID
|
||||||
color = "#0064C8" // rgb: 0, 100, 200
|
color = "#0064C877" // rgb: 0, 100, 200
|
||||||
custom_metabolism = 0.01
|
custom_metabolism = 0.01
|
||||||
|
|
||||||
glass_icon_state = "glass_clear"
|
glass_icon_state = "glass_clear"
|
||||||
@@ -1593,6 +1617,11 @@ datum
|
|||||||
reagent_state = LIQUID
|
reagent_state = LIQUID
|
||||||
color = "#808080"
|
color = "#808080"
|
||||||
overdose = 15
|
overdose = 15
|
||||||
|
color_weight = 20
|
||||||
|
|
||||||
|
New()
|
||||||
|
..()
|
||||||
|
data = color
|
||||||
|
|
||||||
reaction_turf(var/turf/T, var/volume)
|
reaction_turf(var/turf/T, var/volume)
|
||||||
..()
|
..()
|
||||||
@@ -1610,6 +1639,35 @@ datum
|
|||||||
//painting ghosts: not allowed
|
//painting ghosts: not allowed
|
||||||
M.color = color
|
M.color = color
|
||||||
|
|
||||||
|
on_merge(var/newdata, var/newamount)
|
||||||
|
if(!data || !newdata)
|
||||||
|
return
|
||||||
|
var/list/colors = list(0, 0, 0, 0)
|
||||||
|
var/tot_w = 0
|
||||||
|
|
||||||
|
var/hex1 = uppertext(color)
|
||||||
|
var/hex2 = uppertext(newdata)
|
||||||
|
if(length(hex1) == 7)
|
||||||
|
hex1 += "FF"
|
||||||
|
if(length(hex2) == 7)
|
||||||
|
hex2 += "FF"
|
||||||
|
if(length(hex1) != 9 || length(hex2) != 9)
|
||||||
|
return
|
||||||
|
colors[1] += hex2num(copytext(hex1, 2, 4)) * volume
|
||||||
|
colors[2] += hex2num(copytext(hex1, 4, 6)) * volume
|
||||||
|
colors[3] += hex2num(copytext(hex1, 6, 8)) * volume
|
||||||
|
colors[4] += hex2num(copytext(hex1, 8, 10)) * volume
|
||||||
|
tot_w += volume
|
||||||
|
colors[1] += hex2num(copytext(hex2, 2, 4)) * newamount
|
||||||
|
colors[2] += hex2num(copytext(hex2, 4, 6)) * newamount
|
||||||
|
colors[3] += hex2num(copytext(hex2, 6, 8)) * newamount
|
||||||
|
colors[4] += hex2num(copytext(hex2, 8, 10)) * newamount
|
||||||
|
tot_w += newamount
|
||||||
|
|
||||||
|
color = rgb(colors[1] / tot_w, colors[2] / tot_w, colors[3] / tot_w, colors[4] / tot_w)
|
||||||
|
data = color
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////Poison stuff///////////////////////
|
//////////////////////////Poison stuff///////////////////////
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@
|
|||||||
if(80 to 90) filling.icon_state = "[icon_state]80"
|
if(80 to 90) filling.icon_state = "[icon_state]80"
|
||||||
if(91 to INFINITY) filling.icon_state = "[icon_state]100"
|
if(91 to INFINITY) filling.icon_state = "[icon_state]100"
|
||||||
|
|
||||||
filling.color = mix_color_from_reagents(reagents.reagent_list)
|
filling.color = reagents.get_color()
|
||||||
overlays += filling
|
overlays += filling
|
||||||
|
|
||||||
if (!is_open_container())
|
if (!is_open_container())
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
if(80 to 90) filling.icon_state = "[icon_state]-80"
|
if(80 to 90) filling.icon_state = "[icon_state]-80"
|
||||||
if(91 to INFINITY) filling.icon_state = "[icon_state]-100"
|
if(91 to INFINITY) filling.icon_state = "[icon_state]-100"
|
||||||
|
|
||||||
filling.color = mix_color_from_reagents(reagents.reagent_list)
|
filling.color = reagents.get_color()
|
||||||
overlays += filling
|
overlays += filling
|
||||||
|
|
||||||
if (!is_open_container())
|
if (!is_open_container())
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
var/obj/D = new/obj()
|
var/obj/D = new/obj()
|
||||||
D.create_reagents(amount_per_transfer_from_this)
|
D.create_reagents(amount_per_transfer_from_this)
|
||||||
reagents.trans_to(D, amount_per_transfer_from_this)
|
reagents.trans_to(D, amount_per_transfer_from_this)
|
||||||
D.icon += mix_color_from_reagents(D.reagents.reagent_list)
|
D.icon += D.reagents.get_color()
|
||||||
spawn(0)
|
spawn(0)
|
||||||
D.reagents.reaction(A)
|
D.reagents.reaction(A)
|
||||||
sleep(5)
|
sleep(5)
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
var/obj/effect/decal/chempuff/D = new/obj/effect/decal/chempuff(get_turf(src))
|
var/obj/effect/decal/chempuff/D = new/obj/effect/decal/chempuff(get_turf(src))
|
||||||
D.create_reagents(amount_per_transfer_from_this)
|
D.create_reagents(amount_per_transfer_from_this)
|
||||||
reagents.trans_to(D, amount_per_transfer_from_this, 1/spray_size)
|
reagents.trans_to(D, amount_per_transfer_from_this, 1/spray_size)
|
||||||
D.icon += mix_color_from_reagents(D.reagents.reagent_list)
|
D.icon += D.reagents.get_color()
|
||||||
|
|
||||||
var/turf/A_turf = get_turf(A)//BS12
|
var/turf/A_turf = get_turf(A)//BS12
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@
|
|||||||
D.create_reagents(amount_per_transfer_from_this)
|
D.create_reagents(amount_per_transfer_from_this)
|
||||||
src.reagents.trans_to(D, amount_per_transfer_from_this)
|
src.reagents.trans_to(D, amount_per_transfer_from_this)
|
||||||
|
|
||||||
D.icon += mix_color_from_reagents(D.reagents.reagent_list)
|
D.icon += D.reagents.get_color()
|
||||||
|
|
||||||
Sprays[i] = D
|
Sprays[i] = D
|
||||||
|
|
||||||
|
|||||||
@@ -222,7 +222,7 @@
|
|||||||
|
|
||||||
filling.icon_state = "syringe[rounded_vol]"
|
filling.icon_state = "syringe[rounded_vol]"
|
||||||
|
|
||||||
filling.color = mix_color_from_reagents(reagents.reagent_list)
|
filling.color = reagents.get_color()
|
||||||
overlays += filling
|
overlays += filling
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user