/
dna_console.dm
2013 lines (1702 loc) · 76 KB
/
dna_console.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/// Base timeout for creating mutation activators and other injectors
#define INJECTOR_TIMEOUT 100
/// Maximum number of genetic makeup storage slots in DNA Console
#define NUMBER_OF_BUFFERS 3
/// Timeout for DNA Scramble in DNA Consoles
#define SCRAMBLE_TIMEOUT 600
/// Timeout for using the Joker feature to solve a gene in DNA Console
#define JOKER_TIMEOUT 12000
/// How much time DNA Scanner upgrade tiers remove from JOKER_TIMEOUT
#define JOKER_UPGRADE 3000
/// Maximum value for radiaton strength when pulsing enzymes
#define RADIATION_STRENGTH_MAX 15
/// Larger multipliers will affect the range of values when pulsing enzymes
#define RADIATION_STRENGTH_MULTIPLIER 1
/// Maximum value for the radiation pulse duration when pulsing enzymes
#define RADIATION_DURATION_MAX 30
/// Large values reduce pulse accuracy and may pulse other enzymes than selected
#define RADIATION_ACCURACY_MULTIPLIER 3
/// Special status indicating a scanner occupant is transforming eg. from monkey to human
#define STATUS_TRANSFORMING 4
/// Multiplier for how much radiation received from DNA Console functionality
#define RADIATION_IRRADIATION_MULTIPLIER 1
/// Flag for the mutation ref search system. Search will include scanner occupant
#define SEARCH_OCCUPANT 1
/// Flag for the mutation ref search system. Search will include console storage
#define SEARCH_STORED 2
/// Flag for the mutation ref search system. Search will include diskette storage
#define SEARCH_DISKETTE 4
/// Flag for the mutation ref search system. Search will include advanced injector mutations
#define SEARCH_ADV_INJ 8
/obj/machinery/computer/scan_consolenew
name = "DNA Console"
desc = "Scan DNA."
icon_screen = "dna"
icon_keyboard = "med_key"
density = TRUE
circuit = /obj/item/circuitboard/computer/scan_consolenew
use_power = IDLE_POWER_USE
idle_power_usage = 10
active_power_usage = 400
light_color = LIGHT_COLOR_BLUE
/// Link to the techweb's stored research. Used to retrieve stored mutations
var/datum/techweb/stored_research
/// Maximum number of mutations that DNA Consoles are able to store
var/max_storage = 6
/// Duration for enzyme radiation pulses
var/radduration = 2
/// Strength for enzyme radiation pulses
var/radstrength = 1
/// Maximum number of chromosomes that DNA Consoles are able to store.
var/max_chromosomes = 6
/// Maximum number of enzymes we can store
var/list/genetic_makeup_buffer[NUMBER_OF_BUFFERS]
/// List of all mutations stored on the DNA Console
var/list/stored_mutations = list()
/// List of all chromosomes stored in the DNA Console
var/list/stored_chromosomes = list()
/// Assoc list of all advanced injectors. Keys are injector names. Values are lists of mutations.
var/list/list/injector_selection = list()
/// Maximum number of advanced injectors that DNA Consoles store
var/max_injector_selections = 2
/// Maximum number of mutation that an advanced injector can store
var/max_injector_mutations = 10
/// Maximum total instability of all combined mutations allowed on an advanced injector
var/max_injector_instability = 50
/// World time when injectors are ready to be printed
var/injectorready = 0
/// World time when JOKER algorithm can be used in DNA Consoles
var/jokerready = 0
/// World time when Scramble can be used in DNA Consoles
var/scrambleready = 0
/// Currently stored genetic data diskette
var/obj/item/disk/data/diskette = null
/// Current delayed action, used for delayed enzyme transfer on scanner door close
var/list/delayed_action = null
/// Index of the enzyme being modified during delayed enzyme pulse operations
var/rad_pulse_index = 0
/// World time when the enzyme pulse should complete
var/rad_pulse_timer = 0
/// Used for setting tgui data - Whether the connected DNA Scanner is usable
var/can_use_scanner = FALSE
/// Used for setting tgui data - Whether the current DNA Scanner occupant is viable for genetic modification
var/is_viable_occupant = FALSE
/// Used for setting tgui data - Whether Scramble DNA is ready
var/is_scramble_ready = FALSE
/// Used for setting tgui data - Whether JOKER algorithm is ready
var/is_joker_ready = FALSE
/// Used for setting tgui data - Whether injectors are ready to be printed
var/is_injector_ready = FALSE
/// Used for setting tgui data - Wheher an enzyme pulse operation is ongoing
var/is_pulsing_rads = FALSE
/// Used for setting tgui data - Time until scramble is ready
var/time_to_scramble = 0
/// Used for setting tgui data - Time until joker is ready
var/time_to_joker = 0
/// Used for setting tgui data - Time until injectors are ready
var/time_to_injector = 0
/// Used for setting tgui data - Time until the enzyme pulse is complete
var/time_to_pulse = 0
/// Currently connected DNA Scanner
var/obj/machinery/dna_scannernew/connected_scanner = null
/// Current DNA Scanner occupant
var/mob/living/carbon/scanner_occupant = null
/// Used for setting tgui data - List of occupant mutations
var/list/tgui_occupant_mutations = list()
/// Used for setting tgui data - List of DNA Console stored mutations
var/list/tgui_console_mutations = list()
/// Used for setting tgui data - List of diskette stored mutations
var/list/tgui_diskette_mutations = list()
/// Used for setting tgui data - List of DNA Console chromosomes
var/list/tgui_console_chromosomes = list()
/// Used for setting tgui data - List of occupant mutations
var/list/tgui_genetic_makeup = list()
/// Used for setting tgui data - List of occupant mutations
var/list/tgui_advinjector_mutations = list()
/// State of tgui view, i.e. which tab is currently active, or which genome we're currently looking at.
var/list/list/tgui_view_state = list()
/obj/machinery/computer/scan_consolenew/process()
. = ..()
// This is for pulsing the UI element with radiation as part of genetic makeup
// If rad_pulse_index > 0 then it means we're attempting a rad pulse
if((rad_pulse_index > 0) && (rad_pulse_timer <= world.time))
rad_pulse()
return
/obj/machinery/computer/scan_consolenew/attackby(obj/item/I, mob/user, params)
if(istype(I, /obj/item/multitool))
var/obj/item/multitool/multi = I
if(istype(multi.buffer, /obj/machinery/rnd/server))
var/obj/machinery/rnd/server/serv = multi.buffer
stored_research = serv.stored_research
visible_message("Linked to Server!")
return
// Store chromosomes in the console if there's room
if (istype(I, /obj/item/chromosome))
if(LAZYLEN(stored_chromosomes) < max_chromosomes)
I.forceMove(src)
stored_chromosomes += I
to_chat(user, "<span class='notice'>You insert [I].</span>")
else
to_chat(user, "<span class='warning'>You cannot store any more chromosomes!</span>")
return
// Insert data disk if console disk slot is empty
// Swap data disk if there is one already a disk in the console
if (istype(I, /obj/item/disk/data)) //INSERT SOME DISKETTES
if (!user.transferItemToLoc(I,src))
return
if(diskette)
diskette.forceMove(drop_location())
diskette = null
diskette = I
to_chat(user, "<span class='notice'>You insert [I].</span>")
return
// Recycle non-activator used injectors
// Turn activator used injectors (aka research injectors) to chromosomes
if(istype(I, /obj/item/dnainjector/activator))
var/obj/item/dnainjector/activator/A = I
if(A.used)
to_chat(user,"<span class='notice'>Recycled [I].</span>")
if(A.research)
if(prob(60))
var/c_typepath = generate_chromosome()
var/obj/item/chromosome/CM = new c_typepath (drop_location())
if(LAZYLEN(stored_chromosomes) < max_chromosomes)
CM.forceMove(src)
stored_chromosomes += CM
to_chat(user,"<span class='notice'>[capitalize(CM.name)] added to storage.</span>")
else
to_chat(user, "<span class='warning'>You cannot store any more chromosomes!</span>")
to_chat(user, "<span class='notice'>[capitalize(CM.name)] added on top of the console.</span>")
else
to_chat(user, "<span class='notice'>There was not enough genetic data to extract a viable chromosome.</span>")
qdel(I)
return
return ..()
/obj/machinery/computer/scan_consolenew/Initialize()
. = ..()
// Connect with a nearby DNA Scanner on init
connect_to_scanner()
// Set appropriate ready timers and limits for machines functions
injectorready = world.time + INJECTOR_TIMEOUT
scrambleready = world.time + SCRAMBLE_TIMEOUT
jokerready = world.time + JOKER_TIMEOUT
// Set the default tgui state
set_default_state()
/obj/machinery/computer/scan_consolenew/ui_interact(mob/user, datum/tgui/ui)
// Most of ui_interact is spent setting variables for passing to the tgui
// interface.
// We can also do some general state processing here too as it's a good
// indication that a player is using the console.
var/scanner_op = scanner_operational()
var/can_modify_occ = can_modify_occupant()
// Check for connected AND operational scanner.
if(scanner_op)
can_use_scanner = TRUE
else
can_use_scanner = FALSE
connected_scanner = null
is_viable_occupant = FALSE
// Check for a viable occupant in the scanner.
if(can_modify_occ)
is_viable_occupant = TRUE
else
is_viable_occupant = FALSE
// Populates various buffers for passing to tgui
build_mutation_list(can_modify_occ)
build_genetic_makeup_list()
// Populate variables for passing to tgui interface
is_scramble_ready = (scrambleready < world.time)
time_to_scramble = round((scrambleready - world.time)/10)
is_joker_ready = (jokerready < world.time)
time_to_joker = round((jokerready - world.time)/10)
is_injector_ready = (injectorready < world.time)
time_to_injector = round((injectorready - world.time)/10)
is_pulsing_rads = ((rad_pulse_index > 0) && (rad_pulse_timer > world.time))
time_to_pulse = round((rad_pulse_timer - world.time)/10)
// Attempt to update tgui ui, open and update if needed.
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "DnaConsole")
ui.open()
/obj/machinery/computer/scan_consolenew/ui_assets()
. = ..() || list()
. += get_asset_datum(/datum/asset/simple/genetics)
/obj/machinery/computer/scan_consolenew/ui_data(mob/user)
var/list/data = list()
data["view"] = tgui_view_state
data["storage"] = list()
// This block of code generates the huge data structure passed to the tgui
// interface for displaying all the various bits of console/scanner data
// Should all be very self-explanatory
data["isScannerConnected"] = can_use_scanner
if(can_use_scanner)
data["scannerOpen"] = connected_scanner.state_open
data["scannerLocked"] = connected_scanner.locked
data["radStrength"] = radstrength
data["radDuration"] = radduration
data["stdDevStr"] = radstrength * RADIATION_STRENGTH_MULTIPLIER
switch(RADIATION_ACCURACY_MULTIPLIER / (radduration + (connected_scanner.precision_coeff ** 2))) //hardcoded values from a z-table for a normal distribution
if(0 to 0.25)
data["stdDevAcc"] = ">95 %"
if(0.25 to 0.5)
data["stdDevAcc"] = "68-95 %"
if(0.5 to 0.75)
data["stdDevAcc"] = "55-68 %"
else
data["stdDevAcc"] = "<38 %"
data["isViableSubject"] = is_viable_occupant
if(is_viable_occupant)
data["subjectName"] = scanner_occupant.name
if(scanner_occupant.transformation_timer)
data["subjectStatus"] = STATUS_TRANSFORMING
else
data["subjectStatus"] = scanner_occupant.stat
data["subjectHealth"] = scanner_occupant.health
data["subjectRads"] = scanner_occupant.radiation/(RAD_MOB_SAFE/100)
data["subjectEnzymes"] = scanner_occupant.dna.unique_enzymes
data["isMonkey"] = ismonkey(scanner_occupant)
data["subjectUNI"] = scanner_occupant.dna.uni_identity
data["storage"]["occupant"] = tgui_occupant_mutations
//data["subjectMutations"] = tgui_occupant_mutations
else
data["subjectName"] = null
data["subjectStatus"] = null
data["subjectHealth"] = null
data["subjectRads"] = null
data["subjectEnzymes"] = null
//data["subjectMutations"] = null
data["storage"]["occupant"] = null
data["hasDelayedAction"] = (delayed_action != null)
data["isScrambleReady"] = is_scramble_ready
data["isJokerReady"] = is_joker_ready
data["isInjectorReady"] = is_injector_ready
data["scrambleSeconds"] = time_to_scramble
data["jokerSeconds"] = time_to_joker
data["injectorSeconds"] = time_to_injector
data["isPulsingRads"] = is_pulsing_rads
data["radPulseSeconds"] = time_to_pulse
if(diskette != null)
data["hasDisk"] = TRUE
data["diskCapacity"] = diskette.max_mutations - LAZYLEN(diskette.mutations)
data["diskReadOnly"] = diskette.read_only
//data["diskMutations"] = tgui_diskette_mutations
data["storage"]["disk"] = tgui_diskette_mutations
data["diskHasMakeup"] = (LAZYLEN(diskette.genetic_makeup_buffer) > 0)
data["diskMakeupBuffer"] = diskette.genetic_makeup_buffer.Copy()
else
data["hasDisk"] = FALSE
data["diskCapacity"] = 0
data["diskReadOnly"] = TRUE
//data["diskMutations"] = null
data["storage"]["disk"] = null
data["diskHasMakeup"] = FALSE
data["diskMakeupBuffer"] = null
data["mutationCapacity"] = max_storage - LAZYLEN(stored_mutations)
//data["mutationStorage"] = tgui_console_mutations
data["storage"]["console"] = tgui_console_mutations
data["chromoCapacity"] = max_chromosomes - LAZYLEN(stored_chromosomes)
data["chromoStorage"] = tgui_console_chromosomes
data["makeupCapacity"] = NUMBER_OF_BUFFERS
data["makeupStorage"] = tgui_genetic_makeup
//data["advInjectors"] = tgui_advinjector_mutations
data["storage"]["injector"] = tgui_advinjector_mutations
data["maxAdvInjectors"] = max_injector_selections
return data
/obj/machinery/computer/scan_consolenew/ui_act(action, list/params)
. = ..()
if(.)
return
. = TRUE
add_fingerprint(usr)
usr.set_machine(src)
switch(action)
// Connect this DNA Console to a nearby DNA Scanner
// Usually only activate as an option if there is no connected scanner
if("connect_scanner")
connect_to_scanner()
return
// Toggle the door open/closed status on attached DNA Scanner
if("toggle_door")
// GUARD CHECK - Scanner still connected and operational?
if(!scanner_operational())
return
connected_scanner.toggle_open(usr)
return
// Toggle the door bolts on the attached DNA Scanner
if("toggle_lock")
// GUARD CHECK - Scanner still connected and operational?
if(!scanner_operational())
return
connected_scanner.locked = !connected_scanner.locked
return
// Scramble scanner occupant's DNA
if("scramble_dna")
// GUARD CHECK - Can we genetically modify the occupant? Includes scanner
// operational guard checks.
// GUARD CHECK - Is scramble DNA actually ready?
if(!can_modify_occupant() || !(scrambleready < world.time))
return
scanner_occupant.dna.remove_all_mutations(list(MUT_NORMAL, MUT_EXTRA))
scanner_occupant.dna.generate_dna_blocks()
scrambleready = world.time + SCRAMBLE_TIMEOUT
to_chat(usr,"<span class='notice'>DNA scrambled.</span>")
scanner_occupant.radiation += RADIATION_STRENGTH_MULTIPLIER*50/(connected_scanner.damage_coeff ** 2)
return
// Check whether a specific mutation is eligible for discovery within the
// scanner occupant
// This is additionally done when a mutation's tab is selected in the tgui
// interface. This is because some mutations, such as Monkified on monkeys,
// are infact completed by default but not yet discovered. Likewise, all
// mutations can have their sequence completed while Monkified is still an
// active mutation and thus won't immediately be discovered but could be
// discovered when Monkified is removed
// ---------------------------------------------------------------------- //
// params["alias"] - Alias of a mutation. The alias is the "hidden" name of
// the mutation, for example "Mutation 5" or "Mutation 33"
if("check_discovery")
// GUARD CHECK - Can we genetically modify the occupant? Includes scanner
// operational guard checks.
if(!can_modify_occupant())
return
// GUARD CHECK - Have we somehow cheekily swapped occupants? This is
// unexpected.
if(!(scanner_occupant == connected_scanner.occupant))
return
check_discovery(params["alias"])
return
// Check all mutations of the occupant and check if any are discovered.
// This is called when the Genetic Sequencer is selected. It'll do things
// like immediately discover Monkified without needing to click through
// the mutation tabs and handle cases where mutations are solved but not
// discovered due to the Monkified mutation being active then removed.
if("all_check_discovery")
// GUARD CHECK - Can we genetically modify the occupant? Includes scanner
// operational guard checks.
if(!can_modify_occupant())
return
// GUARD CHECK - Have we somehow cheekily swapped occupants? This is
// unexpected.
if(!(scanner_occupant == connected_scanner.occupant))
return
// Go over all standard mutations and check if they've been discovered.
for(var/mutation_type in scanner_occupant.dna.mutation_index)
var/datum/mutation/human/HM = GET_INITIALIZED_MUTATION(mutation_type)
check_discovery(HM.alias)
return
// Set a gene in a mutation's genetic sequence. Will also check for mutations
// discovery as part of the process.
// ---------------------------------------------------------------------- //
// params["alias"] - Alias of a mutation. The alias is the "hidden" name of
// the mutation, for example "Mutation 5" or "Mutation 33"
// params["gene"] - The letter of the new gene
// params["pos"] - The BYOND index of the letter in the gene sequence to be
// changed. Expects a text string from TGUI and will convert to a number
if("pulse_gene")
// GUARD CHECK - Can we genetically modify the occupant? Includes scanner
// operational guard checks.
if(!can_modify_occupant())
return
// GUARD CHECK - Have we somehow cheekily swapped occupants? This is
// unexpected.
if(!(scanner_occupant == connected_scanner.occupant))
return
// GUARD CHECK - Is the occupant currently undergoing some form of
// transformation? If so, we don't want to be pulsing genes.
if(scanner_occupant.transformation_timer)
to_chat(usr,"<span class='warning'>Gene pulse failed: The scanner occupant undergoing a transformation.</span>")
return
// Resolve mutation's BYOND path from the alias
var/alias = params["alias"]
var/path = GET_MUTATION_TYPE_FROM_ALIAS(alias)
// Make sure the occupant still has this mutation
if(!(path in scanner_occupant.dna.mutation_index))
return
// Resolve BYOND path to genome sequence of scanner occupant
var/sequence = GET_GENE_STRING(path, scanner_occupant.dna)
var/newgene = params["gene"]
if(length(newgene) > 1) // Oh come on
return // fuck off
var/genepos = text2num(params["pos"])
// If the new gene is J, this means we're dealing with a JOKER
// GUARD CHECK - Is JOKER actually ready?
if((newgene == "J") && (jokerready < world.time))
var/truegenes = GET_SEQUENCE(path)
newgene = truegenes[genepos]
jokerready = world.time + JOKER_TIMEOUT - (JOKER_UPGRADE * (connected_scanner.precision_coeff-1))
// If the gene is an X, we want to update the default genes with the new
// X to allow highlighting logic to work on the tgui interface.
if(newgene == "X")
var/defaultseq = scanner_occupant.dna.default_mutation_genes[path]
defaultseq = copytext_char(defaultseq, 1, genepos) + newgene + copytext_char(defaultseq, genepos + 1)
scanner_occupant.dna.default_mutation_genes[path] = defaultseq
// Copy genome to scanner occupant and do some basic mutation checks as
// we've increased the occupant rads
sequence = copytext_char(sequence, 1, genepos) + newgene + copytext_char(sequence, genepos + 1)
scanner_occupant.dna.mutation_index[path] = sequence
scanner_occupant.radiation += RADIATION_STRENGTH_MULTIPLIER/connected_scanner.damage_coeff
scanner_occupant.domutcheck()
// GUARD CHECK - Modifying genetics can lead to edge cases where the
// scanner occupant is qdel'd and replaced with a different entity.
// Examples of this include adding/removing the Monkified mutation which
// qdels the previous entity and creates a brand new one in its place.
// We should redo all of our occupant modification checks again, although
// it is less than ideal.
if(!can_modify_occupant())
return
// Check if we cracked a mutation
check_discovery(alias)
return
// Apply a chromosome to a specific mutation.
// ---------------------------------------------------------------------- //
// params["mutref"] - ATOM Ref of specific mutation to apply the chromo to
// params["chromo"] - Name of the chromosome to apply to the mutation
if("apply_chromo")
// GUARD CHECK - Can we genetically modify the occupant? Includes scanner
// operational guard checks.
if(!can_modify_occupant())
return
// GUARD CHECK - Have we somehow cheekily swapped occupants? This is
// unexpected.
if(!(scanner_occupant == connected_scanner.occupant))
return
var/bref = params["mutref"]
// GUARD CHECK - Only search occupant for this specific ref, since your
// can only apply chromosomes to mutations occupants.
var/datum/mutation/human/HM = get_mut_by_ref(bref, SEARCH_OCCUPANT)
// GUARD CHECK - This should not be possible. Unexpected result
if(!HM)
return
// Look through our stored chromos and compare names to find a
// stored chromo we can apply.
for(var/obj/item/chromosome/CM in stored_chromosomes)
if(CM.can_apply(HM) && (CM.name == params["chromo"]))
stored_chromosomes -= CM
CM.apply(HM)
return
// Print any type of standard injector, limited right now to activators that
// activate a dormant mutation and mutators that forcibly create a new
// MUT_EXTRA mutation
// ---------------------------------------------------------------------- //
// params["mutref"] - ATOM Ref of specific mutation to create an injector of
// params["is_activator"] - Is this an "Activator" style injector, also
// referred to as a "Research" type. Expects a string with 0 or 1, which
// then gets converted to a number.
// params["source"] - The source the request came from.
// Expected results:
// "occupant" - From genetic sequencer
// "console" - From DNA Console storage
// "disk" - From inserted diskette
if("print_injector")
// Because printing mutators and activators share a bunch of code,
// it makes sense to keep them both together and set unique vars
// later in the code
// As a side note, because mutations can contain unique metadata,
// this system uses BYOND Atom Refs to safely and accurately
// identify mutations from big ol' lists
// GUARD CHECK - Is the injector actually ready?
if(world.time < injectorready)
return
var/search_flags = 0
switch(params["source"])
if("occupant")
// GUARD CHECK - Make sure we can modify the occupant before we
// attempt to search them for any given mutation refs. This could
// lead to no search flags being passed to get_mut_by_ref and this
// is intended functionality to prevent any cheese or abuse
if(can_modify_occupant())
search_flags |= SEARCH_OCCUPANT
if("console")
search_flags |= SEARCH_STORED
if("disk")
search_flags |= SEARCH_DISKETTE
var/bref = params["mutref"]
var/datum/mutation/human/HM = get_mut_by_ref(bref, search_flags)
// GUARD CHECK - This should not be possible. Unexpected result
if(!HM)
return
// Create a new DNA Injector and add the appropriate mutations to it
var/obj/item/dnainjector/activator/I = new /obj/item/dnainjector/activator(loc)
I.add_mutations += new HM.type(copymut = HM)
var/is_activator = text2num(params["is_activator"])
// Activators are also called "research" injectors and are used to create
// chromosomes by recycling at the DNA Console
if(is_activator)
I.name = "[HM.name] activator"
I.research = TRUE
// If there's an operational connected scanner, we can use its upgrades
// to improve our injector's radiation generation
if(scanner_operational())
I.damage_coeff = connected_scanner.damage_coeff*4
injectorready = world.time + INJECTOR_TIMEOUT * (1 - 0.1 * connected_scanner.precision_coeff)
else
injectorready = world.time + INJECTOR_TIMEOUT
else
I.name = "[HM.name] mutator"
I.doitanyway = TRUE
// If there's an operational connected scanner, we can use its upgrades
// to improve our injector's radiation generation
if(scanner_operational())
I.damage_coeff = connected_scanner.damage_coeff
injectorready = world.time + INJECTOR_TIMEOUT * 5 * (1 - 0.1 * connected_scanner.precision_coeff)
else
injectorready = world.time + INJECTOR_TIMEOUT * 5
return
// Save a mutation to the console's storage buffer.
// ---------------------------------------------------------------------- //
// params["mutref"] - ATOM Ref of specific mutation to store
// params["source"] - The source the request came from.
// Expected results:
// "occupant" - From genetic sequencer
// "disk" - From inserted diskette
if("save_console")
var/search_flags = 0
switch(params["source"])
if("occupant")
// GUARD CHECK - Make sure we can modify the occupant before we
// attempt to search them for any given mutation refs. This could
// lead to no search flags being passed to get_mut_by_ref and this
// is intended functionality to prevent any cheese or abuse
if(can_modify_occupant())
search_flags |= SEARCH_OCCUPANT
if("disk")
search_flags |= SEARCH_DISKETTE
// GUARD CHECK - Is mutation storage full?
if(LAZYLEN(stored_mutations) >= max_storage)
to_chat(usr,"<span class='warning'>Mutation storage is full.</span>")
return
var/bref = params["mutref"]
var/datum/mutation/human/HM = get_mut_by_ref(bref, search_flags)
// GUARD CHECK - This should not be possible. Unexpected result
if(!HM)
return
var/datum/mutation/human/A = new HM.type()
A.copy_mutation(HM)
stored_mutations += A
to_chat(usr,"<span class='notice'>Mutation successfully stored.</span>")
return
// Save a mutation to the diskette's storage buffer.
// ---------------------------------------------------------------------- //
// params["mutref"] - ATOM Ref of specific mutation to store
// params["source"] - The source the request came from
// Expected results:
// "occupant" - From genetic sequencer
// "console" - From DNA Console storage
if("save_disk")
// GUARD CHECK - This code shouldn't even be callable without a diskette
// inserted. Unexpected result
if(!diskette)
return
// GUARD CHECK - Make sure the disk is not full
if(LAZYLEN(diskette.mutations) >= diskette.max_mutations)
to_chat(usr,"<span class='warning'>Disk storage is full.</span>")
return
// GUARD CHECK - Make sure the disk isn't set to read only, as we're
// attempting to write to it
if(diskette.read_only)
to_chat(usr,"<span class='warning'>Disk is set to read only mode.</span>")
return
var/search_flags = 0
switch(params["source"])
if("occupant")
// GUARD CHECK - Make sure we can modify the occupant before we
// attempt to search them for any given mutation refs. This could
// lead to no search flags being passed to get_mut_by_ref and this
// is intended functionality to prevent any cheese or abuse
if(can_modify_occupant())
search_flags |= SEARCH_OCCUPANT
if("console")
search_flags |= SEARCH_STORED
var/bref = params["mutref"]
var/datum/mutation/human/HM = get_mut_by_ref(bref, search_flags)
// GUARD CHECK - This should not be possible. Unexpected result
if(!HM)
return
var/datum/mutation/human/A = new HM.type()
A.copy_mutation(HM)
diskette.mutations += A
to_chat(usr,"<span class='notice'>Mutation successfully stored to disk.</span>")
return
// Completely removes a MUT_EXTRA mutation or mutation with corrupt gene
// sequence from the scanner occupant
// ---------------------------------------------------------------------- //
// params["mutref"] - ATOM Ref of specific mutation to nullify
if("nullify")
// GUARD CHECK - Can we genetically modify the occupant? Includes scanner
// operational guard checks.
if(!can_modify_occupant())
return
var/bref = params["mutref"]
var/datum/mutation/human/HM = get_mut_by_ref(bref, SEARCH_OCCUPANT)
// GUARD CHECK - This should not be possible. Unexpected result
if(!HM)
return
// GUARD CHECK - Nullify should only be used on scrambled or "extra"
// mutations.
if(!HM.scrambled && !(HM.class == MUT_EXTRA))
return
scanner_occupant.dna.remove_mutation(HM.type)
return
// Deletes saved mutation from console buffer.
// ---------------------------------------------------------------------- //
// params["mutref"] - ATOM Ref of specific mutation to delete
if("delete_console_mut")
var/bref = params["mutref"]
var/datum/mutation/human/HM = get_mut_by_ref(bref, SEARCH_STORED)
if(HM)
stored_mutations.Remove(HM)
qdel(HM)
return
// Deletes saved mutation from disk buffer.
// ---------------------------------------------------------------------- //
// params["mutref"] - ATOM Ref of specific mutation to delete
if("delete_disk_mut")
// GUARD CHECK - This code shouldn't even be callable without a diskette
// inserted. Unexpected result
if(!diskette)
return
// GUARD CHECK - Make sure the disk isn't set to read only, as we're
// attempting to write to it (via deletion)
if(diskette.read_only)
to_chat(usr,"<span class='warning'>Disk is set to read only mode.</span>")
return
var/bref = params["mutref"]
var/datum/mutation/human/HM = get_mut_by_ref(bref, SEARCH_DISKETTE)
if(HM)
diskette.mutations.Remove(HM)
qdel(HM)
return
// Ejects a stored chromosome from the DNA Console
// ---------------------------------------------------------------------- //
// params["chromo"] - Text string of the chromosome name
if("eject_chromo")
var/chromname = params["chromo"]
for(var/obj/item/chromosome/CM in stored_chromosomes)
if(chromname == CM.name)
CM.forceMove(drop_location())
adjust_item_drop_location(CM)
stored_chromosomes -= CM
return
return
// Combines two mutations from the console to try and create a new mutation
// ---------------------------------------------------------------------- //
// params["firstref"] - ATOM Ref of first mutation for combination
// params["secondref"] - ATOM Ref of second mutation for combination
// mutation
if("combine_console")
// GUaRD CHECK - Make sure mutation storage isn't full. If it is, we won't
// be able to store the new combo mutation
if(LAZYLEN(stored_mutations) >= max_storage)
to_chat(usr,"<span class='warning'>Mutation storage is full.</span>")
return
// GUARD CHECK - We're running a research-type operation. If, for some
// reason, somehow the DNA Console has been disconnected from the research
// network - Or was never in it to begin with - don't proceed
if(!stored_research)
return
var/first_bref = params["firstref"]
var/second_bref = params["secondref"]
// GUARD CHECK - Find the source and destination mutations on the console
// and make sure they actually exist.
var/datum/mutation/human/source_mut = get_mut_by_ref(first_bref, SEARCH_STORED | SEARCH_DISKETTE)
if(!source_mut)
return
var/datum/mutation/human/dest_mut = get_mut_by_ref(second_bref, SEARCH_STORED | SEARCH_DISKETTE)
if(!dest_mut)
return
// Attempt to mix the two mutations to get a new type
var/result_path = get_mixed_mutation(source_mut.type, dest_mut.type)
if(!result_path)
return
// If we got a new type, add it to our storage
stored_mutations += new result_path()
to_chat(usr, "<span class='boldnotice'>Success! New mutation has been added to console storage.</span>")
// If it's already discovered, end here. Otherwise, add it to the list of
// discovered mutations.
// We've already checked for stored_research earlier
if(result_path in stored_research.discovered_mutations)
return
var/datum/mutation/human/HM = GET_INITIALIZED_MUTATION(result_path)
stored_research.discovered_mutations += result_path
say("Successfully mutated [HM.name].")
return
// Combines two mutations from the disk to try and create a new mutation
// ---------------------------------------------------------------------- //
// params["firstref"] - ATOM Ref of first mutation for combination
// params["secondref"] - ATOM Ref of second mutation for combination
// mutation
if("combine_disk")
// GUARD CHECK - This code shouldn't even be callable without a diskette
// inserted. Unexpected result
if(!diskette)
return
// GUARD CHECK - Make sure the disk is not full.
if(LAZYLEN(diskette.mutations) >= diskette.max_mutations)
to_chat(usr,"<span class='warning'>Disk storage is full.</span>")
return
// GUARD CHECK - Make sure the disk isn't set to read only, as we're
// attempting to write to it
if(diskette.read_only)
to_chat(usr,"<span class='warning'>Disk is set to read only mode.</span>")
return
// GUARD CHECK - We're running a research-type operation. If, for some
// reason, somehow the DNA Console has been disconnected from the research
// network - Or was never in it to begin with - don't proceed
if(!stored_research)
return
var/first_bref = params["firstref"]
var/second_bref = params["secondref"]
// GUARD CHECK - Find the source and destination mutations on the console
// and make sure they actually exist.
var/datum/mutation/human/source_mut = get_mut_by_ref(first_bref, SEARCH_STORED | SEARCH_DISKETTE)
if(!source_mut)
return
var/datum/mutation/human/dest_mut = get_mut_by_ref(second_bref, SEARCH_STORED | SEARCH_DISKETTE)
if(!dest_mut)
return
// Attempt to mix the two mutations to get a new type
var/result_path = get_mixed_mutation(source_mut.type, dest_mut.type)
if(!result_path)
return
// If we got a new type, add it to our storage
diskette.mutations += new result_path()
to_chat(usr, "<span class='boldnotice'>Success! New mutation has been added to the disk.</span>")
// If it's already discovered, end here. Otherwise, add it to the list of
// discovered mutations
// We've already checked for stored_research earlier
if(result_path in stored_research.discovered_mutations)
return
var/datum/mutation/human/HM = GET_INITIALIZED_MUTATION(result_path)
stored_research.discovered_mutations += result_path
say("Successfully mutated [HM.name].")
return
// Sets the Genetic Makeup pulse strength.
// ---------------------------------------------------------------------- //
// params["val"] - New strength value as text string, converted to number
// later on in code
if("set_pulse_strength")
var/value = round(text2num(params["val"]))
radstrength = WRAP(value, 1, RADIATION_STRENGTH_MAX+1)
return
// Sets the Genetic Makeup pulse duration
// ---------------------------------------------------------------------- //
// params["val"] - New strength value as text string, converted to number
// later on in code
if("set_pulse_duration")
var/value = round(text2num(params["val"]))
radduration = WRAP(value, 1, RADIATION_DURATION_MAX+1)
return
// Saves Genetic Makeup information to disk
// ---------------------------------------------------------------------- //
// params["index"] - The BYOND index of the console genetic makeup buffer to
// copy to disk
if("save_makeup_disk")
// GUARD CHECK - This code shouldn't even be callable without a diskette
// inserted. Unexpected result
if(!diskette)
return
// GUARD CHECK - Make sure the disk isn't set to read only, as we're
// attempting to write to it
if(diskette.read_only)
to_chat(usr,"<span class='warning'>Disk is set to read only mode.</span>")
return
// Convert the index to a number and clamp within the array range
var/buffer_index = text2num(params["index"])
buffer_index = clamp(buffer_index, 1, NUMBER_OF_BUFFERS)
var/list/buffer_slot = genetic_makeup_buffer[buffer_index]
// GUARD CHECK - This should not be possible to activate on a buffer slot
// that doesn't have any genetic data. Unexpected result
if(!istype(buffer_slot))
return
diskette.genetic_makeup_buffer = buffer_slot.Copy()
return
// Loads Genetic Makeup from disk to a console buffer
// ---------------------------------------------------------------------- //
// params["index"] - The BYOND index of the console genetic makeup buffer to
// copy to. Expected as text string, converted to number later
if("load_makeup_disk")
// GUARD CHECK - This code shouldn't even be callable without a diskette
// inserted. Unexpected result
if(!diskette)
return
// GUARD CHECK - This should not be possible to activate on a diskette
// that doesn't have any genetic data. Unexpected result
if(LAZYLEN(diskette.genetic_makeup_buffer) == 0)
return
// Convert the index to a number and clamp within the array range, then
// copy the data from the disk to that buffer
var/buffer_index = text2num(params["index"])
buffer_index = clamp(buffer_index, 1, NUMBER_OF_BUFFERS)
genetic_makeup_buffer[buffer_index] = diskette.genetic_makeup_buffer.Copy()
return
// Deletes genetic makeup buffer from the inserted diskette
if("del_makeup_disk")
// GUARD CHECK - This code shouldn't even be callable without a diskette
// inserted. Unexpected result
if(!diskette)
return
// GUARD CHECK - Make sure the disk isn't set to read only, as we're
// attempting to write (via deletion) to it
if(diskette.read_only)