[MIRROR] Refactors mail, delivery and goodies code (#6432)

* Refactors mail and delivery code (#59730)

- Mail now uses weakreferences to minds, which means the presence of
  mail will not cause harddels, and persist between mindswaps or cloning
  or whatever horrible mob transfer things you've got going on.
- The code for creating a crate of mail has been refactored into a
  single proc, rather than having the same code twice.
- Instead of special casing reagents being delivered, instead
  reagent mail goodies are just regular bottle items like any other.

* Refactors mail, delivery and goodies code

Co-authored-by: coiax <yellowbounder@gmail.com>
This commit is contained in:
SkyratBot
2021-06-22 01:48:42 +02:00
committed by GitHub
parent 1f53e5d6af
commit b37a7f134e
8 changed files with 98 additions and 71 deletions
+2 -28
View File
@@ -246,6 +246,7 @@ GLOBAL_LIST_INIT(blacklisted_cargo_types, typecacheof(list(
//Early return if there's no mail waiting to prevent taking up a slot. We also don't send mails on sundays or holidays.
if(!SSeconomy.mail_waiting || SSeconomy.mail_blocked)
return
//spawn crate
var/list/empty_turfs = list()
for(var/place as anything in shuttle_areas)
@@ -254,35 +255,8 @@ GLOBAL_LIST_INIT(blacklisted_cargo_types, typecacheof(list(
if(shuttle_floor.is_blocked_turf())
continue
empty_turfs += shuttle_floor
var/obj/structure/closet/crate/mail/mailcrate = new(pick(empty_turfs))
//collect recipients
var/list/mail_recipients = list()
for(var/mob/living/carbon/human/player_human in shuffle(GLOB.player_list))
if(player_human.stat == DEAD)
continue
if(!SSjob.GetJob(player_human.mind.assigned_role) || (player_human.mind.assigned_role in GLOB.nonhuman_positions))
continue //this check stops wizards and nuke ops from getting mail, which is hilarious but should definitely not happen
mail_recipients += player_human
//Creates mail for all the mail waiting to arrive, if there's nobody to recieve it it's just junkmail.
for(var/mail_iterator in 1 to SSeconomy.mail_waiting)
var/obj/item/mail/new_mail
if(prob(FULL_CRATE_LETTER_ODDS))
new_mail = new /obj/item/mail(mailcrate)
else
new_mail = new /obj/item/mail/envelope(mailcrate)
var/mob/living/carbon/human/mail_to
if(mail_recipients.len)
mail_to = pick(mail_recipients)
new_mail.initialize_for_recipient(mail_to)
mail_recipients -= mail_to
else
new_mail.junk_mail()
if(new_mail)
SSeconomy.mail_waiting -= 1
mailcrate.update_icon()
return mailcrate
new /obj/structure/closet/crate/mail/economy(pick(empty_turfs))
#undef GOODY_FREE_SHIPPING_MAX
#undef CRATE_TAX