forked from goonstation/goonstation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameticker.dm
840 lines (686 loc) · 30.4 KB
/
gameticker.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
var/global/datum/controller/gameticker/ticker
var/global/current_state = GAME_STATE_WORLD_INIT
/* -- moved to _setup.dm
#define GAME_STATE_PREGAME 1
#define GAME_STATE_SETTING_UP 2
#define GAME_STATE_PLAYING 3
#define GAME_STATE_FINISHED 4
*/
/datum/controller/gameticker
//var/current_state = GAME_STATE_PREGAME
//replaced with global
var/hide_mode = 0
var/datum/game_mode/mode = null
var/event_time = null
var/event = 0
var/list/datum/mind/minds = list()
var/last_readd_lost_minds_to_ticker = 1 // In relation to world time.
var/pregame_timeleft = 0
// this is actually round_elapsed_deciseconds
var/round_elapsed_ticks = 0
var/click_delay = 3
var/datum/ai_laws/centralized_ai_laws
var/skull_key_assigned = 0
var/tmp/useTimeDilation = TIME_DILATION_ENABLED
var/tmp/timeDilationLowerBound = MIN_TICKLAG
var/tmp/timeDilationUpperBound = OVERLOADED_WORLD_TICKLAG
var/tmp/last_tick_realtime = 0
var/tmp/last_tick_byondtime = 0
var/tmp/last_interval_tick_offset = 0 //how far off the last tick (byondtime - realtime)
var/tmp/last_try_dilate = 0
var/tmp/threshold_dilation = TICKLAG_DILATION_THRESHOLD //remove later
var/tmp/threshold_normalization = TICKLAG_NORMALIZATION_THRESHOLD //remove later
/datum/controller/gameticker/proc/pregame()
pregame_timeleft = PREGAME_LOBBY_TICKS
boutput(world, "<B><FONT style='notice'>Welcome to the pre-game lobby!</FONT></B><br>Please, setup your character and select ready. Game will start in [pregame_timeleft] seconds.")
// let's try doing this here, yoloooo
// zamu 20200823: idk if this is even getting called...
//if (mining_controls?.mining_z && mining_controls.mining_z_asteroids_max)
// mining_controls.spawn_mining_z_asteroids()
if(master_mode == "battle_royale")
lobby_titlecard.icon_state += "_battle_royale"
#ifdef I_DONT_WANNA_WAIT_FOR_THIS_PREGAME_SHIT_JUST_GO
for(var/mob/new_player/C in world)
C.ready = 1
pregame_timeleft = 1
#endif
var/did_mapvote = 0
var/obj/overlay/zamujasa/round_start_countdown/timer/title_countdown = new()
while (current_state <= GAME_STATE_PREGAME)
sleep(1 SECOND)
// Start the countdown as normal, but hold it at 30 seconds until setup is complete
if (!game_start_delayed && (pregame_timeleft > 30 || current_state == GAME_STATE_PREGAME))
pregame_timeleft--
if (pregame_timeleft <= 60 && !did_mapvote)
// do it here now instead of before the countdown
// as part of the early start most people might not even see it at 150
// so this makes it show up a minute before the game starts
handle_mapvote()
did_mapvote = 1
if (title_countdown)
title_countdown.update_time(pregame_timeleft)
else if(title_countdown)
title_countdown.update_time(-1)
if(pregame_timeleft <= 0)
current_state = GAME_STATE_SETTING_UP
qdel(title_countdown)
qdel(game_start_countdown)
#ifdef SERVER_SIDE_PROFILING
#ifdef SERVER_SIDE_PROFILING_PREGAME
#warn Profiler will output at pregame stage
var/profile_out = file("data/profile/[time2text(world.realtime, "YYYY-MM-DD hh-mm-ss")]-pregame.log")
profile_out << world.Profile(PROFILE_START, "json")
world.log << "Dumped profiler data."
#endif
#if defined(SERVER_SIDE_PROFILING_INGAME_ONLY)
#warn Profiler reset for ingame stage
// We're in game now, so reset profiler data
world.Profile(PROFILE_RESTART)
#elif !defined(SERVER_SIDE_PROFILING_FULL_ROUND)
#warn Profiler disabled after init
// If we aren't doing ingame or full round then we're done with the profiler
world.Profile(PROFILE_STOP)
#endif
#endif
SPAWN_DBG(0) setup()
/datum/controller/gameticker/proc/setup()
set background = 1
//Create and announce mode
if(master_mode in list("secret","action","intrigue","wizard","alien"))
src.hide_mode = 1
switch(master_mode)
if("random","secret") src.mode = config.pick_random_mode()
if("action") src.mode = config.pick_mode(pick("nuclear","wizard","blob"))
if("intrigue") src.mode = config.pick_mode(pick("mixed_rp", "traitor","changeling","vampire","conspiracy","spy_theft", prob(50); "extended"))
else src.mode = config.pick_mode(master_mode)
if(hide_mode)
#ifdef RP_MODE
boutput(world, "<B>Have fun and RP!</B>")
#else
var/modes = sortList(config.get_used_mode_names())
boutput(world, "<B>The current game mode is a secret!</B>")
boutput(world, "<B>Possibilities:</B> [english_list(modes)]")
#endif
else
src.mode.announce()
// uhh is this where this goes??
src.centralized_ai_laws = new /datum/ai_laws/asimov()
//Configure mode and assign player to special mode stuff
var/can_continue = src.mode.pre_setup()
if(!can_continue)
qdel(mode)
current_state = GAME_STATE_PREGAME
boutput(world, "<B>Error setting up [master_mode].</B> Reverting to pre-game lobby.")
SPAWN_DBG(0) pregame()
return 0
logTheThing("debug", null, null, "Chosen game mode: [mode] ([master_mode]) on map [getMapNameFromID(map_setting)].")
//Tell the participation recorder to queue player data while the round starts up
participationRecorder.setHold()
#ifdef RP_MODE
looc_allowed = 1
boutput(world, "<B>LOOC has been automatically enabled.</B>")
ooc_allowed = 0
boutput(world, "<B>OOC has been automatically disabled until the round ends.</B>")
#else
if (istype(src.mode, /datum/game_mode/construction))
looc_allowed = 1
boutput(world, "<B>LOOC has been automatically enabled.</B>")
else
ooc_allowed = 0
boutput(world, "<B>OOC has been automatically disabled until the round ends.</B>")
#endif
Z_LOG_DEBUG("Game Start", "Animating client colors to black now")
var/list/animateclients = list()
for (var/client/C)
if (!istype(C.mob,/mob/new_player))
continue
var/mob/new_player/P = C.mob
if (P.ready)
Z_LOG_DEBUG("Game Start/Ani", "Animating [P.client]")
animateclients += P.client
animate(P.client, color = "#000000", time = 5, easing = QUAD_EASING | EASE_IN)
// Give said clients time to animate the fadeout before we do this...
sleep(0.5 SECONDS)
//Distribute jobs
distribute_jobs()
//Create player characters and transfer them
create_characters()
add_minds()
// rip collar key, nerds murdered people for you as non-antags and it was annoying
//implant_skull_key() //Solarium
#ifdef CREW_OBJECTIVES
//Create objectives for the non-traitor/nogoodnik crew.
generate_crew_objectives()
#endif
//Equip characters
equip_characters()
Z_LOG_DEBUG("Game Start", "Animating client colors to normal")
for (var/client/C in animateclients)
if (C)
Z_LOG_DEBUG("Game Start/A", "Animating client [C]")
var/target_color = "#FFFFFF"
if(C.color != "#000000")
target_color = C.color
animate(C, color = "#000000", time = 0, flags = ANIMATION_END_NOW)
animate(color = "#000000", time = 10, easing = QUAD_EASING | EASE_IN)
animate(color = target_color, time = 10, easing = QUAD_EASING | EASE_IN)
current_state = GAME_STATE_PLAYING
round_time_check = world.timeofday
SPAWN_DBG(0)
ircbot.event("roundstart")
mode.post_setup()
event_wormhole_buildturflist()
mode.post_post_setup()
for(var/turf/T in landmarks[LANDMARK_ARTIFACT_SPAWN])
var/spawnchance = landmarks[LANDMARK_ARTIFACT_SPAWN][T]
if (prob(spawnchance))
Artifact_Spawn(T)
shippingmarket.get_market_timeleft()
logTheThing("ooc", null, null, "<b>Current round begins</b>")
boutput(world, "<FONT class='notice'><B>Enjoy the game!</B></FONT>")
boutput(world, "<span class='notice'><b>Tip:</b> [pick(tips)]</span>")
//Setup the hub site logging
var hublog_filename = "data/stats/data.txt"
if (fexists(hublog_filename))
fdel(hublog_filename)
hublog = file(hublog_filename)
hublog << ""
//Tell the participation recorder that we're done FAFFING ABOUT
participationRecorder.releaseHold()
SPAWN_DBG (6000) // 10 minutes in
for(var/obj/machinery/power/monitor/smes/E in machine_registry[MACHINES_POWER])
LAGCHECK(LAG_LOW)
if(E.powernet?.avail <= 0)
command_alert("Reports indicate that the engine on-board [station_name()] has not yet been started. Setting up the engine is strongly recommended, or else stationwide power failures may occur.", "Power Grid Warning")
break
processScheduler.start()
if (total_clients() >= OVERLOAD_PLAYERCOUNT)
world.tick_lag = OVERLOADED_WORLD_TICKLAG
//Okay this is kinda stupid, but mapSwitcher.autoVoteDelay which is now set to 30 seconds, (used to be 5 min).
//The voting will happen 30 seconds into the pre-game lobby. This is probably fine to leave. But if someone changes that var then it might start before the lobby timer ends.
/datum/controller/gameticker/proc/handle_mapvote()
var/bustedMapSwitcher = isMapSwitcherBusted()
if (!bustedMapSwitcher)
SPAWN_DBG (mapSwitcher.autoVoteDelay)
//Trigger the automatic map vote
try
mapSwitcher.startMapVote(duration = mapSwitcher.autoVoteDuration)
catch (var/exception/e)
logTheThing("admin", usr ? usr : src, null, "the automated map switch vote couldn't run because: [e.name]")
logTheThing("diary", usr ? usr : src, null, "the automated map switch vote couldn't run because: [e.name]", "admin")
message_admins("[key_name(usr ? usr : src)] the automated map switch vote couldn't run because: [e.name]")
/datum/controller/gameticker
proc/distribute_jobs()
DivideOccupations()
proc/create_characters()
for (var/mob/new_player/player in mobs)
#ifdef TWITCH_BOT_ALLOWED
if (player.twitch_bill_spawn)
player.try_force_into_bill()
continue
#endif
if (player.ready)
if (player.mind && player.mind.ckey)
//Record player participation in this round via the goonhub API
participationRecorder.record(player.mind.ckey)
if (player.mind && player.mind.assigned_role == "AI")
player.close_spawn_windows()
var/mob/living/silicon/ai/A = player.AIize()
A.Equip_Bank_Purchase(A.mind.purchased_bank_item)
else if (player.mind && player.mind.special_role == "wraith")
player.close_spawn_windows()
var/mob/wraith/W = player.make_wraith()
if (W)
W.set_loc(pick_landmark(LANDMARK_OBSERVER))
logTheThing("debug", W, null, "<b>Late join</b>: assigned antagonist role: wraith.")
antagWeighter.record(role = "wraith", ckey = W.ckey)
else if (player.mind && player.mind.special_role == "blob")
player.close_spawn_windows()
var/mob/living/intangible/blob_overmind/B = player.make_blob()
if (B)
B.set_loc(pick_landmark(LANDMARK_OBSERVER))
logTheThing("debug", B, null, "<b>Late join</b>: assigned antagonist role: blob.")
antagWeighter.record(role = "blob", ckey = B.ckey)
else if (player.mind && player.mind.special_role == "flockmind")
player.close_spawn_windows()
var/mob/living/intangible/flock/flockmind/F = player.make_flockmind()
if (F)
F.set_loc(pick_landmark(LANDMARK_OBSERVER))
logTheThing("debug", F, null, "<b>Late join</b>: assigned antagonist role: flockmind.")
antagWeighter.record(role = "flockmind", ckey = F.ckey)
else if (player.mind)
if (player.client.using_antag_token)
player.client.use_antag_token() //Removes a token from the player
player.create_character()
qdel(player)
proc/add_minds(var/periodic_check = 0)
for (var/mob/player in mobs)
// Who cares about NPCs? Adding them here breaks all antagonist objectives
// that attempt to scale with total player count (Convair880).
if (player.mind && !istype(player, /mob/new_player) && player.client)
if (!(player.mind in ticker.minds))
if (periodic_check == 1)
logTheThing("debug", player, null, "<b>Gameticker fallback:</b> re-added player to ticker.minds.")
else
logTheThing("debug", player, null, "<b>Gameticker setup:</b> added player to ticker.minds.")
ticker.minds.Add(player.mind)
proc/implant_skull_key()
//Hello, I will sneak in a solarium thing here.
if(!skull_key_assigned && ticker.minds.len > 5) //Okay enough gaming the system you pricks
var/list/HL = list()
for (var/mob/living/carbon/human/human in mobs)
if (human.client)
HL += human
if(HL.len > 5)
var/mob/living/carbon/human/H = pick(HL)
if(istype(H))
skull_key_assigned = 1
SPAWN_DBG(5 SECONDS)
if(H.organHolder && H.organHolder.skull)
H.organHolder.skull.key = new /obj/item/device/key/skull (H.organHolder.skull)
logTheThing("debug", H, null, "has the dubious pleasure of having a key embedded in their skull.")
else
skull_key_assigned = 0
else if(!skull_key_assigned)
logTheThing("debug", null, null, "<B>SpyGuy/collar key:</B> Did not implant a key because there was not enough players.")
proc/equip_characters()
for(var/mob/living/carbon/human/player in mobs)
if(player.mind && player.mind.assigned_role)
if(player.mind.assigned_role != "MODE")
SPAWN_DBG(0)
player.Equip_Rank(player.mind.assigned_role)
proc/process()
if(current_state != GAME_STATE_PLAYING)
return 0
updateRoundTime()
mode.process()
#ifdef HALLOWEEN
spooktober_GH.update()
#endif
emergency_shuttle.process()
if (useTimeDilation)//TIME_DILATION_ENABLED set this
if (world.time > last_try_dilate + TICKLAG_DILATE_INTERVAL) //interval separate from the process loop. maybe consider moving this for cleanup later (its own process loop with diff. interval?)
last_try_dilate = world.time
last_interval_tick_offset = max(0, (world.timeofday - last_tick_realtime) - (world.time - last_tick_byondtime))
last_tick_realtime = world.timeofday
last_tick_byondtime = world.time
var/dilated_tick_lag = world.tick_lag
if (last_interval_tick_offset >= threshold_dilation)
dilated_tick_lag = min(world.tick_lag + TICKLAG_DILATION_INC, timeDilationUpperBound)
else if (last_interval_tick_offset <= threshold_normalization)
dilated_tick_lag = max(world.tick_lag - TICKLAG_DILATION_DEC, timeDilationLowerBound)
if (world.tick_lag != dilated_tick_lag)
world.tick_lag = dilated_tick_lag
// Minds are sometimes kicked out of the global list, hence the fallback (Convair880).
if (src.last_readd_lost_minds_to_ticker && world.time > src.last_readd_lost_minds_to_ticker + 1800)
src.add_minds(1)
src.last_readd_lost_minds_to_ticker = world.time
if(mode.check_finished())
current_state = GAME_STATE_FINISHED
// This does a little more than just declare - it handles all end of round processing
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] Starting declare_completion.")
try
declare_completion()
catch(var/exception/e)
logTheThing("debug", null, null, "Game Completion Runtime: [e.file]:[e.line] - [e.name] - [e.desc]")
logTheThing("diary", null, null, "Game Completion Runtime: [e.file]:[e.line] - [e.name] - [e.desc]", "debug")
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] Finished declare_completion. The round is now over.")
// Official go-ahead to be an end-of-round asshole
boutput(world, "<h3>The round has ended!</h3><strong style='color: #393;'>Further actions will have no impact on round results. Go hog wild!</strong>")
// i feel like this should probably be a proc call somewhere instead but w/e
if (!ooc_allowed)
ooc_allowed = 1
boutput(world, "<B>OOC is now enabled.</B>")
SPAWN_DBG(5 SECONDS)
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] game-ending spawn happening")
boutput(world, "<span class='bold notice'>A new round will begin soon.</span>")
var/datum/hud/roundend/roundend_countdown = new()
for (var/client/C in clients)
roundend_countdown.add_client(C)
var/roundend_time = 60
while (roundend_time >= 0)
roundend_countdown.update_time(roundend_time)
sleep(1 SECONDS)
roundend_time--
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] one minute delay, game should restart now")
if (game_end_delayed == 1)
roundend_countdown.update_delayed()
message_admins("<span class='internal'>Server would have restarted now, but the restart has been delayed[game_end_delayer ? " by [game_end_delayer]" : null]. Remove the delay for an immediate restart.</span>")
game_end_delayed = 2
var/ircmsg[] = new()
ircmsg["msg"] = "Server would have restarted now, but the restart has been delayed[game_end_delayer ? " by [game_end_delayer]" : null]."
ircbot.export("admin", ircmsg)
else
ircbot.event("roundend")
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] REBOOTING THE SERVER!!!!!!!!!!!!!!!!!")
Reboot_server()
return 1
proc/updateRoundTime()
if (round_time_check)
var/elapsed = world.timeofday - round_time_check
round_time_check = world.timeofday
if (round_time_check == 0) // on the slim chance that this happens exactly on a timeofday rollover
round_time_check = 1 // make it nonzero so it doesn't quit updating
if (elapsed > 0)
ticker.round_elapsed_ticks += elapsed
/datum/controller/gameticker/proc/declare_completion()
//End of round statistic collection for goonhub
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] statlog_traitors")
statlog_traitors()
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] statlog_ailaws")
statlog_ailaws(0)
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] round_end_data")
round_end_data(1) //Export round end packet (normal completion)
var/pets_rescued = 0
for(var/pet in by_cat[TR_CAT_PETS])
if(iscritter(pet))
var/obj/critter/P = pet
if(P.alive && in_centcom(P)) pets_rescued++
else if(ismobcritter(pet))
var/mob/living/critter/P = pet
if(isalive(P) && in_centcom(P)) pets_rescued++
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] Processing end-of-round generic medals")
var/list/all_the_baddies = ticker.mode.traitors + ticker.mode.token_players + ticker.mode.Agimmicks + ticker.mode.former_antagonists
for(var/mob/living/player in mobs)
if (player.client)
if (!isdead(player))
if (in_centcom(player))
player.unlock_medal("100M dash", 1)
if (pets_rescued >= 6)
player.unlock_medal("Noah's Shuttle", 1)
player.unlock_medal("Survivor", 1)
if (player.check_contents_for(/obj/item/gnomechompski))
player.unlock_medal("Guardin' gnome", 1)
if (ishuman(player))
var/mob/living/carbon/human/H = player
if (H && istype(H) && H.implant && H.implant.len > 0)
var/bullets = 0
for (var/obj/item/implant/I in H)
if (istype(I, /obj/item/implant/projectile))
bullets = 1
break
if (bullets > 0)
H.unlock_medal("It's just a flesh wound!", 1)
if (H.limbs && (!H.limbs.l_arm && !H.limbs.r_arm))
H.unlock_medal("Mostly Armless", 1)
#ifdef CREW_OBJECTIVES
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] Processing crew objectives")
var/list/successfulCrew = list()
for (var/datum/mind/crewMind in minds)
if (!crewMind.current || !crewMind.objectives.len)
continue
var/count = 0
var/allComplete = 1
crewMind.all_objs = 1
for (var/datum/objective/crew/CO in crewMind.objectives)
count++
if(CO.check_completion())
crewMind.completed_objs++
boutput(crewMind.current, "<B>Objective #[count]</B>: [CO.explanation_text] <span class='success'><B>Success</B></span>")
logTheThing("diary",crewMind,null,"completed objective: [CO.explanation_text]")
if (!isnull(CO.medal_name) && !isnull(crewMind.current))
crewMind.current.unlock_medal(CO.medal_name, CO.medal_announce)
else
boutput(crewMind.current, "<B>Objective #[count]</B>: [CO.explanation_text] <span class='alert'>Failed</span>")
logTheThing("diary",crewMind,null,"failed objective: [CO.explanation_text]. Bummer!")
allComplete = 0
crewMind.all_objs = 0
if (allComplete && count)
successfulCrew += "[crewMind.current.real_name] ([crewMind.key])"
#endif
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] mode.declare_completion()")
mode.declare_completion()
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] mode.declare_completion() done - calculating score")
score_tracker.calculate_score()
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] score calculated")
var/final_score = score_tracker.final_score_all
if (final_score > 200)
final_score = 200
else if (final_score <= 0)
final_score = 0
else
final_score = 100
boutput(world, score_tracker.escapee_facts())
boutput(world, score_tracker.heisenhat_stats())
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] ai law display")
boutput(world, "<b>AIs and Cyborgs had the following laws at the end of the game:</b><br>[ticker.centralized_ai_laws.format_for_logs()]")
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] resetting gauntlet (why? who cares! the game is over!)")
if (gauntlet_controller.state)
gauntlet_controller.resetArena()
#ifdef CREW_OBJECTIVES
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] displaying completed crew objectives")
if (successfulCrew.len)
boutput(world, "<B>The following crewmembers completed all of their Crew Objectives:</B><br>[successfulCrew.Join("<br>")]<br>Good job!")
else
boutput(world, "<B>Nobody completed all of their Crew Objectives!</B>")
#endif
#ifdef MISCREANTS
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] displaying miscreants")
boutput(world, "<B>Miscreants:</B>")
if(miscreants.len == 0) boutput(world, "None!")
for(var/datum/mind/miscreantMind in miscreants)
if(!miscreantMind.objectives.len)
continue
var/miscreant_info = "[miscreantMind.key]"
if(miscreantMind.current) miscreant_info = "[miscreantMind.current.real_name] ([miscreantMind.key])"
boutput(world, "<B>[miscreant_info] was a miscreant!</B>")
for (var/datum/objective/miscreant/O in miscreantMind.objectives)
boutput(world, "Objective: [O.explanation_text] <B>Maybe</B>")
#endif
// DO THE PERSISTENT_BANK STUFF
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] processing spacebux updates")
var/escape_possible = 1
if (istype(mode, /datum/game_mode/blob) || istype(mode, /datum/game_mode/nuclear) || istype(mode, /datum/game_mode/revolution))
escape_possible = 0
var/time = world.time
logTheThing("debug", null, null, "Revving up the spacebux loop...")
for(var/mob/player in mobs)
if (player?.client && player.mind && !player.mind.joined_observer && !istype(player,/mob/new_player))
logTheThing("debug", null, null, "Iterating on [player.client]")
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] spacebux calc start: [player.mind.ckey]")
var/chui/window/earn_spacebux/bank_earnings = new
//get base wage + initial earnings calculation
var/job_wage = 100
if (wagesystem.jobs.Find(player.mind.assigned_role))
job_wage = wagesystem.jobs[player.mind.assigned_role]
if (isrobot(player))
job_wage = 500
if (isAI(player) || isshell(player))
job_wage = 900
//if part-time, reduce wage
if (player.mind.join_time > 5400) //grace period of 9 mins after roundstart to be a full-time employee
job_wage = (time - player.mind.join_time) / time * job_wage
bank_earnings.part_time = 1
var/earnings = final_score/100 * job_wage * 2 //TODO ECNONMY_REBALANCE: remove the *2
bank_earnings.wage_base = round(job_wage * 2) //TODO ECNONMY_REBALANCE: remove the *2
bank_earnings.wage_after_score = round(earnings)
//check if escaped
//if we are dead - get the location of our corpse
var/player_body_escaped = in_centcom(player)
var/player_loses_held_item = isdead(player) || isVRghost(player) || isghostcritter(player)
if (istype(player,/mob/dead/observer))
player_loses_held_item = 1
var/mob/dead/observer/O = player
if (O.corpse)
player_body_escaped = in_centcom(O.corpse)
else
player_body_escaped = 0
else if (istype(player,/mob/dead/target_observer))
player_loses_held_item = 1
var/mob/dead/target_observer/O = player
if (O.corpse)
player_body_escaped = in_centcom(O.corpse)
else
player_body_escaped = 0
else if (isghostdrone(player))
player_loses_held_item = 1
player_body_escaped = 0
//AI doesn't need to escape
if (isAI(player) || isshell(player))
player_body_escaped = 1
if (isAIeye(player))
var/mob/dead/aieye/E = player
player_loses_held_item = isdead(E.mainframe)
if (!escape_possible)
player_body_escaped = 1
if (istype(mode, /datum/game_mode/nuclear)) //bleh the nuke thing kills everyone
player_loses_held_item = 0
if (player_body_escaped)
bank_earnings.escaped = 1
else
earnings = (earnings/4)
bank_earnings.escaped = 0
player_loses_held_item = 1
//handle traitors
if (player.mind && ticker.mode.traitors.Find(player.mind)) // Roundstart people get the full bonus
earnings = job_wage
bank_earnings.badguy = 1
player_loses_held_item = 0
else if (istype(player.loc, /obj/cryotron) || player.mind && all_the_baddies.Find(player.mind)) // Cryo'd or was a baddie at any point? Keep your shit, but you don't get the extra bux
player_loses_held_item = 0
//some might not actually have a wage
if (isnukeop(player) || (isblob(player) && (player.mind && player.mind.special_role == "blob")) || iswraith(player) || (iswizard(player) && (player.mind && player.mind.special_role == "wizard")) )
bank_earnings.wage_base = 0 //only effects the end of round display
earnings = 800
if (player.mind.completed_objs > 0)
earnings += (player.mind.completed_objs * 50) // CREW OBJECTIVE SBUX, ONE OBJECTIVE
bank_earnings.completed_objs = (player.mind.completed_objs * 50)
if (player.mind.all_objs)
earnings += 100; // ALL CREW OBJECTIVE SBUX BONUS
bank_earnings.all_objs = 100
//pilot's bonus check and reward
var/pilot_bonus = 500 //for receipt
if(!isdead(player) && in_centcom(player))
if (player.buckled)
if (istype(player.buckled,/obj/stool/chair/comfy/shuttle/pilot))
bank_earnings.pilot = 1
earnings += pilot_bonus
else if (isAI(player))
var/mob/living/silicon/ai/M = null
if (isAIeye(player))
M = player:mainframe
else
M = player
var/obj/stool/chair/comfy/shuttle/pilot/O = locate() in M.loc
if (O && !O.buckled_guy) //no double piloting
bank_earnings.pilot = 1
earnings += pilot_bonus
//add_to_bank and show earnings receipt
earnings = round(earnings)
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] spacebux calc finish: [player.mind.ckey]")
SPAWN_DBG(0)
if(player.client)
player.client.add_to_bank(earnings)
// Fix for persistent_bank-is-NaN bug
if (player.client.persistent_bank != player.client.persistent_bank)
player.client.set_persistent_bank(50000)
if (player_loses_held_item)
logTheThing("debug", null, null, "[player.ckey] lost held item")
player.client.set_last_purchase(0)
bank_earnings.pilot_bonus = pilot_bonus
bank_earnings.final_payout = earnings
bank_earnings.held_item = player.client.persistent_bank_item
bank_earnings.new_balance = player.client.persistent_bank
bank_earnings.Subscribe( player.client )
logTheThing("debug", null, null, "Done with spacebux")
for_by_tcl(P, /obj/bookshelf/persistent) //make the bookshelf save its contents
P.build_curr_contents()
logTheThing("debug", null, null, "Done with books")
award_archived_round_xp()
logTheThing("debug", null, null, "Spawned XP")
SPAWN_DBG(0)
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] creds/new")
var/chui/window/crew_credits/creds = new
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] displaying tickets and scores")
for(var/mob/E in mobs)
if(E.client)
if (E.client.preferences.view_tickets)
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] sending tickets to [E.ckey]")
E.showtickets()
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] done sending tickets to [E.ckey]")
if (E.client.preferences.view_score)
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] sending crew credits to [E.ckey]")
creds.Subscribe(E.client)
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] done crew credits to [E.ckey]")
SPAWN_DBG(0) show_xp_summary(E.key, E)
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] done showing tickets/scores")
logTheThing("debug", null, null, "Did credits")
//logTheThing("debug", null, null, "Zamujasa: [world.timeofday] finished spacebux updates")
var/list/playtimes = list() //associative list with the format list("ckeys\[[player_ckey]]" = playtime_in_seconds)
for_by_tcl(P, /datum/player)
if (!P.ckey)
continue
P.log_leave_time() //get our final playtime for the round (wont cause errors with people who already d/ced bc of smart code)
if (!P.current_playtime)
continue
playtimes["ckeys\[[P.ckey]]"] = round((P.current_playtime / (1 SECOND))) //rounds 1/10th seconds to seconds
try
apiHandler.queryAPI("playtime/record-multiple", playtimes)
catch(var/exception/e)
logTheThing("debug", null, null, "playtime was unable to be logged because of: [e.name]")
logTheThing("diary", null, null, "playtime was unable to be logged because of: [e.name]", "debug")
return 1
/////
/////SETTING UP THE GAME
/////
/////
/////MAIN PROCESS PART
/////
/*
/datum/controller/gameticker/proc/game_process()
switch(mode.name)
if("deathmatch","monkey","nuclear emergency","Corporate Restructuring","revolution","traitor",
"wizard","extended")
do
if (!( shuttle_frozen ))
if (src.timing == 1)
src.timeleft -= 10
else
if (src.timing == -1.0)
src.timeleft += 10
if (src.timeleft >= shuttle_time_to_arrive)
src.timeleft = null
src.timing = 0
if (prob(0.5))
spawn_meteors()
if (src.timeleft <= 0 && src.timing)
src.timeup()
sleep(1 SECOND)
while(src.processing)
return
//Standard extended process (incorporates most game modes).
//Put yours in here if you don't know where else to put it.
if("AI malfunction")
do
check_win()
ticker.AItime += 10
sleep(1 SECOND)
if (ticker.AItime == 6000)
boutput(world, "<FONT size = 3><B>Cent. Com. Update</B> AI Malfunction Detected</FONT>")
boutput(world, "<span class='alert'>It seems we have provided you with a malfunctioning AI. We're very sorry.</span>")
while(src.processing)
return
//malfunction process
if("meteor")
do
if (!( shuttle_frozen ))
if (src.timing == 1)
src.timeleft -= 10
else
if (src.timing == -1.0)
src.timeleft += 10
if (src.timeleft >= shuttle_time_to_arrive)
src.timeleft = null
src.timing = 0
for(var/i = 0; i < 10; i++)
spawn_meteors()
if (src.timeleft <= 0 && src.timing)
src.timeup()
sleep(1 SECOND)
while(src.processing)
return
//meteor mode!!! MORE METEORS!!!
else
return
//Anything else, like sandbox, return.
*/