SHARE
TWEET

Untitled

a guest Nov 8th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /obj/bookshelf
  2.     name = "bookshelf"
  3.     desc = "A storage unit designed to fit a lot of books. Been a while since you've seen one of these!"
  4.     icon = 'icons/obj/bookshelf.dmi'
  5.     icon_state = "bookshelf_empty"
  6.     anchored = 1
  7.     density = 1
  8.     var/variant = 1 //just used for normal shelves
  9.     var/update_icon_suffix = "" //set to either "1" or "2" in New()
  10.     var/capacity = 17 //how many books can it hold?
  11.     var/top_shelf_cap = 6
  12.     var/middle_shelf_cap = 5
  13.     var/bottom_shelf_cap = 6
  14.     var/list/bookshelf_contents = list() //idk if its important to have ordered bookshelf contents?
  15.  
  16.     //this is where we store pixel offsets (i know its ugly, sorry, but i promise this cuts down on duplicate code4
  17.     //this one especially is a bit messy but thats because theres 2 variants on the same object i had to capture
  18.     var/shelf_overlay_list = list(list(7,16,9,21),\
  19.     list(7,16,12,21),\
  20.     list(7,16,16,21),\
  21.     list(7,16,19,21),\
  22.     list(7,16,22,21),\
  23.     list(7,16,25,21),\
  24.     list(7,9,10,14),\
  25.     list(7,9,14,14),\
  26.     list(7,9,18,14),\
  27.     list(7,9,21,14),\
  28.     list(7,9,25,14),\
  29.     list(7,2,9,7),\
  30.     list(7,2,12,7),\
  31.     list(7,2,16,7),\
  32.     list(7,2,19,7),\
  33.     list(7,2,22,7),\
  34.     list(7,2,25,7),\
  35.     list("sideways"),\
  36.     list("sideways"),\
  37.     list(7,16,15,21),\
  38.     list(7,16,19,21),\
  39.     list(7,16,22,21),\
  40.     list(7,16,25,21),\
  41.     list(7,9,12,14),\
  42.     list("sideways"),\
  43.     list("sideways"),\
  44.     list(7,9,21,14),\
  45.     list(7,9,25,14),\
  46.     list(7,2,9,7),\
  47.     list(7,2,13,7),\
  48.     list(7,2,16,7),\
  49.     list(7,2,19,7),\
  50.     list(7,2,22,7),\
  51.     list(7,2,25,7))
  52.  
  53.     New()
  54.         ..()
  55.         if (variant)
  56.             update_icon_suffix = "[rand(1,2)]"
  57.  
  58.     proc/add_to_bookshelf(var/obj/item/W)
  59.         bookshelf_contents += W
  60.         W.set_loc(src)
  61.  
  62.     proc/take_off_bookshelf(var/obj/item/W)
  63.         bookshelf_contents -= W
  64.         W.set_loc(get_turf(src))
  65.  
  66. ///////////////////////////////////////////////
  67. //icon crap its garbage just dont look ok? ok//
  68. ///////////////////////////////////////////////
  69.  
  70. //sorry this whole thing is a bit messy but i commented the first part so hopefully its easier to understand?
  71. //only reason i did it like this is i felt like having 100+ iconstates would be really dumb and hard to work with
  72. //this is polished up A LOT from the last version
  73. //~adhara <3
  74.  
  75.     proc/update_icon()
  76.         ClearSpecificOverlays("top_shelf", "middle_shelf", "bottom_shelf") //lets avoid any weird ghosts
  77.         var/image/top_image = null //initialise these 3 so we can set them inside of the conditionals
  78.         var/image/middle_image = null
  79.         var/image/bottom_image = null
  80.  
  81.         if (bookshelf_contents.len) //were almost always drawing the top shelf
  82.             var/icon/top = new(src.icon, "bookshelf_full_[update_icon_suffix]") //makes a new icon that we can crop from the full bookshelf icon
  83.             var/list/top_crop = list() //creating this rn so we can modify it in an if thing while also being able to reference it outside of those ifs
  84.             if (bookshelf_contents.len > top_shelf_cap) //lets see how to call our crop location proc, it returns a list of pixels that we crop to
  85.                 top_crop = book_overlay_logic_center(top_shelf_cap) //if theres more books on the shelf than on the top row, just generate the top row
  86.             else
  87.                 top_crop = book_overlay_logic_center(bookshelf_contents.len) //if theres less than the shelf capacity, lets get the pixel locations for that
  88.             if ("sideways" in top_crop) //some shelves have sideways books, i have custom icons for that scenario that we'll use instead of a crop
  89.                 if (bookshelf_contents.len == 1) //values for which there are sideways books in the full book icon
  90.                     top_image = SafeGetOverlayImage("top_shelf", src.icon, "2_sideways_1")
  91.                 else
  92.                     top_image = SafeGetOverlayImage("top_shelf", src.icon, "2_sideways_2")
  93.             else
  94.                 top.Crop(top_crop[1], top_crop[2], top_crop[3], top_crop[4]) //this crops our icon, but it resets offsets back to 1,1
  95.                 top_image = image(top) //sets the image we made at the beginning to our cropped icon, we'll fix the offsets later
  96.  
  97.         if (bookshelf_contents.len > top_shelf_cap) //is the top shelf full? move onto the middle shelf
  98.             var/icon/middle = new(src.icon, "bookshelf_full_[update_icon_suffix]")
  99.             var/list/middle_crop = list()
  100.             if (bookshelf_contents.len > (top_shelf_cap + middle_shelf_cap))
  101.                 middle_crop = book_overlay_logic_center(top_shelf_cap + middle_shelf_cap)
  102.             else
  103.                 middle_crop = book_overlay_logic_center(bookshelf_contents.len)
  104.             if ("sideways" in middle_crop)
  105.                 switch(bookshelf_contents.len)
  106.                     if (8)
  107.                         middle_image = SafeGetOverlayImage("middle_shelf", src.icon, "2_sideways_3")
  108.                     if (9)
  109.                         middle_image = SafeGetOverlayImage("middle_shelf", src.icon, "2_sideways_4")
  110.                     if (10)
  111.                         middle_image = SafeGetOverlayImage("middle_shelf", src.icon, "wall_sideways_1")
  112.                     if (11)
  113.                         middle_image = SafeGetOverlayImage("middle_shelf", src.icon, "wall_sideways_2")
  114.             else
  115.                 middle.Crop(middle_crop[1], middle_crop[2], middle_crop[3], middle_crop[4])
  116.                 middle_image = image(middle)
  117.  
  118.         if (bookshelf_contents.len > (top_shelf_cap + middle_shelf_cap)) //is the middle shelf full? move onto the bottom shelf
  119.             var/icon/bottom = new(src.icon, "bookshelf_full_[update_icon_suffix]")
  120.             var/list/bottom_crop = book_overlay_logic_center(bookshelf_contents.len) //dont need the if because the bottom shelf is the last shelf!!
  121.             if ("sideways" in bottom_crop)
  122.                 if (bookshelf_contents.len == 26)
  123.                     bottom_image = SafeGetOverlayImage("bottom_shelf", src.icon, "wall_sideways_3")
  124.                 else
  125.                     bottom_image = SafeGetOverlayImage("bottom_shelf", src.icon, "wall_sideways_4")
  126.             else
  127.                 bottom.Crop(bottom_crop[1], bottom_crop[2], bottom_crop[3], bottom_crop[4])
  128.                 bottom_image = image(bottom)
  129.  
  130.         if (top_image) //now we handle offsets and updating the icon
  131.             switch(update_icon_suffix) //theres so many variants with different pixel offsets that this is best, i think
  132.                 if ("1")
  133.                     top_image.pixel_x += 6
  134.                     top_image.pixel_y += 15
  135.                 if ("2")
  136.                     top_image.pixel_x += 6
  137.                     top_image.pixel_y += 15
  138.                 if ("wall")
  139.                     top_image.pixel_y += 16
  140.                 if ("L")
  141.                     top_image.pixel_x += 1
  142.                     top_image.pixel_y += 16
  143.                 if ("R")
  144.                     top_image.pixel_x += 1
  145.                     top_image.pixel_y += 16
  146.             UpdateOverlays(top_image, "top_shelf")
  147.  
  148.         if (middle_image)
  149.             switch(update_icon_suffix)
  150.                 if ("1")
  151.                     middle_image.pixel_x += 6
  152.                     middle_image.pixel_y += 8
  153.                 if ("2")
  154.                     middle_image.pixel_x += 6
  155.                     middle_image.pixel_y += 8
  156.                 if ("wall")
  157.                     middle_image.pixel_y += 9
  158.                 if ("L")
  159.                     middle_image.pixel_x += 1
  160.                     middle_image.pixel_y += 9
  161.                 if ("R")
  162.                     middle_image.pixel_x += 1
  163.                     middle_image.pixel_y += 9
  164.             UpdateOverlays(middle_image, "middle_shelf")
  165.  
  166.         if (bottom_image)
  167.             switch(update_icon_suffix)
  168.                 if ("1")
  169.                     bottom_image.pixel_x += 6
  170.                     bottom_image.pixel_y += 1
  171.                 if ("2")
  172.                     bottom_image.pixel_x += 6
  173.                     bottom_image.pixel_y += 1
  174.                 if ("wall")
  175.                     bottom_image.pixel_y += 2
  176.                 if ("L")
  177.                     bottom_image.pixel_x += 1
  178.                     bottom_image.pixel_y += 2
  179.                 if ("R")
  180.                     bottom_image.pixel_x += 1
  181.                     bottom_image.pixel_y += 2
  182.             UpdateOverlays(bottom_image, "bottom_shelf")
  183.  
  184.     proc/book_overlay_logic_center(var/book_count) //this proc lets us just go through and get coordinates of where to crop our book image to
  185.         if (variant && update_icon_suffix == "2")
  186.             book_count += 17 //to deal with variants on the og bookshelves
  187.         return shelf_overlay_list[book_count]
  188.  
  189.     attackby(obj/item/W as obj, mob/user as mob)
  190.         if (istype(W, /obj/item/paper/book))
  191.             if (!(bookshelf_contents.len >= capacity))
  192.                 boutput(user, "you shelf the book")
  193.                 user.drop_item()
  194.                 add_to_bookshelf(W)
  195.                 update_icon()
  196.             else
  197.                 boutput(user, "too full")
  198.         else
  199.             boutput(user, "not a book")
  200.  
  201.     attack_hand(mob/user as mob)
  202.         if (bookshelf_contents.len > 0)
  203.             var/book_sel = input("What book would you like to take off \the [src]?", "[src]") as null|anything in bookshelf_contents
  204.             if (!book_sel)
  205.                 return
  206.             boutput(user, "you deshelf the book")
  207.             take_off_bookshelf(book_sel)
  208.             user.put_in_hand_or_drop(book_sel)
  209.             update_icon()
  210.         else
  211.             boutput(user, "shelf is empty ding dong")
  212.  
  213. /obj/bookshelf/long
  214.     icon_state = "bookshelf_empty_long"
  215.     variant = 0
  216.     update_icon_suffix = "wall"
  217.     top_shelf_cap = 9
  218.     middle_shelf_cap = 10
  219.     bottom_shelf_cap = 10
  220.     capacity = 29
  221.  
  222.     shelf_overlay_list = list(list(1,17,3,22),\
  223.     list(1,17,7,22),\
  224.     list(1,17,10,22),\
  225.     list(1,17,14,22),\
  226.     list(1,17,20,22),\
  227.     list(1,17,26,22),\
  228.     list(1,17,29,22),\
  229.     list(1,17,32,22),\
  230.     list("sideways"),\
  231.     list("sideways"),\
  232.     list(1,10,10,15),\
  233.     list(1,10,13,15),\
  234.     list(1,10,16,15),\
  235.     list(1,10,19,15),\
  236.     list(1,10,22,15),\
  237.     list(1,10,25,15),\
  238.     list(1,10,29,15),\
  239.     list(1,10,32,15),\
  240.     list(1,3,3,8),\
  241.     list(1,3,6,8),\
  242.     list(1,3,9,8),\
  243.     list(1,3,12,8),\
  244.     list(1,3,16,8),\
  245.     list(1,3,19,8),\
  246.     list("sideways"),\
  247.     list("sideways"),\
  248.     list(1,3,28,8),\
  249.     list(1,3,32,8))
  250.  
  251. /obj/bookshelf/long/end_left
  252.     icon_state = "bookshelf_empty_end_L"
  253.     update_icon_suffix = "L"
  254.     top_shelf_cap = 9
  255.     middle_shelf_cap = 9
  256.     bottom_shelf_cap = 9
  257.     capacity = 27
  258.  
  259.     shelf_overlay_list = list(list(2,17,4,22),\
  260.     list(2,17,7,22),\
  261.     list(2,17,11,22),\
  262.     list(2,17,14,22),\
  263.     list(2,17,17,22),\
  264.     list(2,17,21,22),\
  265.     list(2,17,24,22),\
  266.     list(2,17,28,22),\
  267.     list(2,17,32,22),\
  268.     list(2,10,4,15),\
  269.     list(2,10,8,15),\
  270.     list(2,10,11,15),\
  271.     list(2,10,14,15),\
  272.     list(2,10,17,15),\
  273.     list(2,10,20,15),\
  274.     list(2,10,24,15),\
  275.     list(2,10,28,15),\
  276.     list(2,10,32,15),\
  277.     list(2,3,5,8),\
  278.     list(2,3,8,8),\
  279.     list(2,3,12,8),\
  280.     list(2,3,15,8),\
  281.     list(2,3,19,8),\
  282.     list(2,3,22,8),\
  283.     list(2,3,25,8),\
  284.     list(2,3,28,8),\
  285.     list(2,3,32,8))
  286.  
  287. /obj/bookshelf/long/end_right
  288.     icon_state = "bookshelf_empty_end_R"
  289.     update_icon_suffix = "R"
  290.     top_shelf_cap = 9
  291.     middle_shelf_cap = 9
  292.     bottom_shelf_cap = 9
  293.     capacity = 27
  294.  
  295.     shelf_overlay_list = list(list(1,17,4,22),\
  296.     list(1,17,7,22),\
  297.     list(1,17,10,22),\
  298.     list(1,17,13,22),\
  299.     list(1,17,16,22),\
  300.     list(1,17,20,22),\
  301.     list(1,17,23,22),\
  302.     list(1,17,27,22),\
  303.     list(1,17,31,22),\
  304.     list(1,10,3,15),\
  305.     list(1,10,7,15),\
  306.     list(1,10,11,15),\
  307.     list(1,10,15,15),\
  308.     list(1,10,19,15),\
  309.     list(1,10,22,15),\
  310.     list(1,10,25,15),\
  311.     list(1,10,28,15),\
  312.     list(1,10,31,15),\
  313.     list(1,3,4,8),\
  314.     list(1,3,8,8),\
  315.     list(1,3,11,8),\
  316.     list(1,3,14,8),\
  317.     list(1,3,18,8),\
  318.     list(1,3,21,8),\
  319.     list(1,3,24,8),\
  320.     list(1,3,27,8),\
  321.     list(1,3,31,8))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top