/
photography.dm
293 lines (249 loc) · 8.1 KB
/
photography.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
/* Photography!
* Contains:
* Camera
* Camera Film
* Photos
* Photo Albums
*/
/*******
* film *
*******/
/obj/item/device/camera_film
name = "film cartridge"
icon = 'icons/obj/tools/photography.dmi'
desc = "A camera film cartridge. Insert it into a camera to reload it."
icon_state = "film"
item_state = "electropack"
w_class = ITEM_SIZE_TINY
/********
* photo *
********/
var/global/photo_count = 0
/obj/item/photo
name = "photo"
icon = 'icons/obj/tools/photography.dmi'
icon_state = "photo"
item_state = "paper"
randpixel = 10
w_class = ITEM_SIZE_TINY
var/id
var/icon/img //Big photo image
var/scribble //Scribble on the back.
var/image/tiny
var/photo_size = 3
/obj/item/photo/Initialize()
. = ..()
id = photo_count++
/obj/item/photo/attack_self(mob/user as mob)
examinate(user, src)
/obj/item/photo/on_update_icon()
ClearOverlays()
var/scale = 8/(photo_size*32)
var/image/small_img = image(img)
small_img.SetTransform(scale = scale)
small_img.pixel_x = -32*(photo_size-1)/2 - 3
small_img.pixel_y = -32*(photo_size-1)/2
AddOverlays(small_img)
tiny = image(img)
tiny.SetTransform(scale = 0.5 * scale)
tiny.underlays += image('icons/obj/bureaucracy.dmi',"photo")
tiny.pixel_x = -32*(photo_size-1)/2 - 3
tiny.pixel_y = -32*(photo_size-1)/2 + 3
/obj/item/photo/use_tool(obj/item/item, mob/living/user, list/click_params)
if(istype(item, /obj/item/pen))
var/txt = sanitize(input(user, "What would you like to write on the back?", "Photo Writing", null) as text, 128)
if(loc == user && user.stat == 0)
scribble = txt
return TRUE
return ..()
/obj/item/photo/examine(mob/user, distance)
. = TRUE
if(!img)
return
if(distance <= 1)
show(user)
to_chat(user, desc)
else
to_chat(user, SPAN_NOTICE("It is too far away."))
/obj/item/photo/proc/show(mob/user as mob)
send_rsc(user, img, "tmp_photo_[id].png")
var/output = "<html><head><title>[name]</title></head>"
output += "<body style='overflow:hidden;margin:0;text-align:center'>"
output += "<img src='tmp_photo_[id].png' width='[64*photo_size]' style='-ms-interpolation-mode:nearest-neighbor' />"
output += "[scribble ? "<br>Written on the back:<br><i>[scribble]</i>" : ""]"
output += "</body></html>"
show_browser(user, output, "window=book;size=[64*photo_size]x[scribble ? 400 : 64*photo_size]")
onclose(user, "[name]")
return
/obj/item/photo/verb/rename()
set name = "Rename photo"
set category = "Object"
set src in usr
var/n_name = sanitizeSafe(input(usr, "What would you like to label the photo?", "Photo Labelling", null) as text, MAX_NAME_LEN)
//loc.loc check is for making possible renaming photos in clipboards
if(!n_name || !CanInteract(usr, GLOB.deep_inventory_state))
return
SetName("[(n_name ? text("[n_name]") : "photo")]")
add_fingerprint(usr)
return
/**************
* photo album *
**************/
/obj/item/storage/photo_album
name = "Photo album"
icon = 'icons/obj/tools/photography.dmi'
icon_state = "album"
item_state = "briefcase"
w_class = ITEM_SIZE_NORMAL //same as book
storage_slots = DEFAULT_BOX_STORAGE //yes, that's storage_slots. Photos are w_class 1 so this has as many slots equal to the number of photos you could put in a box
contents_allowed = list(/obj/item/photo)
/obj/item/storage/photo_album/MouseDrop(obj/over_object as obj)
if((istype(usr, /mob/living/carbon/human)))
var/mob/M = usr
if(!( istype(over_object, /obj/screen) ))
return ..()
playsound(loc, "rustle", 50, 1, -5)
if((!( M.restrained() ) && !( M.stat ) && M.back == src))
switch(over_object.name)
if("r_hand")
if(M.unEquip(src))
M.put_in_r_hand(src)
if("l_hand")
if(M.unEquip(src))
M.put_in_l_hand(src)
add_fingerprint(usr)
return
if(over_object == usr && in_range(src, usr) || usr.contents.Find(src))
if(usr.s_active)
usr.s_active.close(usr)
show_to(usr)
return
return
/*********
* camera *
*********/
/obj/item/device/camera
name = "camera"
icon = 'icons/obj/tools/photography.dmi'
desc = "A polaroid camera."
icon_state = "camera"
item_state = "electropack"
w_class = ITEM_SIZE_SMALL
obj_flags = OBJ_FLAG_CONDUCTIBLE
slot_flags = SLOT_BELT
matter = list(MATERIAL_ALUMINIUM = 1000, MATERIAL_PLASTIC = 750)
var/pictures_max = 10
var/pictures_left = 10
var/on = 1
var/icon_on = "camera"
var/icon_off = "camera_off"
var/size = 3
/obj/item/device/camera/on_update_icon()
var/datum/extension/base_icon_state/bis = get_extension(src, /datum/extension/base_icon_state)
if(on)
icon_state = "[bis.base_icon_state]"
else
icon_state = "[bis.base_icon_state]_off"
/obj/item/device/camera/Initialize()
set_extension(src, /datum/extension/base_icon_state, icon_state)
update_icon()
. = ..()
/obj/item/device/camera/verb/change_size()
set name = "Set Photo Focus"
set category = "Object"
var/nsize = input("Photo Size","Pick a size of resulting photo.") as null|anything in list(1,3,5,7)
if(nsize)
size = nsize
to_chat(usr, SPAN_NOTICE("Camera will now take [size]x[size] photos."))
/obj/item/device/camera/attack_self(mob/user as mob)
on = !on
update_icon()
to_chat(user, "You switch the camera [on ? "on" : "off"].")
return
/obj/item/device/camera/use_tool(obj/item/tool, mob/user, list/click_params)
// Camera Film - Add film
if (istype(tool, /obj/item/device/camera_film))
if (pictures_left)
USE_FEEDBACK_FAILURE("\The [src] already has film in it.")
return TRUE
pictures_left = pictures_max
user.visible_message(
SPAN_NOTICE("\The [user] adds \a [tool] to \a [src]."),
SPAN_NOTICE("You add \the [tool] to \the [src]."),
range = 2
)
qdel(tool)
return TRUE
return ..()
/obj/item/device/camera/proc/get_mobs(turf/the_turf as turf)
var/mob_detail
for(var/mob/living/carbon/A in the_turf)
if(A.invisibility) continue
var/holding = null
var/list/held_items = A.GetAllHeld()
if (length(held_items))
holding = "They are holding [english_list(A.GetAllHeld())]"
if(!mob_detail)
mob_detail = "You can see [A] on the photo[(A.health / A.maxHealth) < 0.75 ? " - [A] looks hurt":""].[holding ? " [holding]":"."]. "
else
mob_detail += "You can also see [A] on the photo[(A.health / A.maxHealth)< 0.75 ? " - [A] looks hurt":""].[holding ? " [holding]":"."]."
return mob_detail
/obj/item/device/camera/afterattack(atom/target as mob|obj|turf|area, mob/user as mob, flag)
if(!on || !pictures_left || ismob(target.loc)) return
captureimage(target, user, flag)
playsound(loc, pick('sound/items/polaroid1.ogg', 'sound/items/polaroid2.ogg'), 75, 1, -3)
pictures_left--
to_chat(user, SPAN_NOTICE("[pictures_left] photos left."))
on = 0
update_icon()
/obj/item/device/camera/examine(mob/user)
. = ..()
to_chat(user, "It has [pictures_left] photo\s left.")
//Proc for capturing check
/mob/living/proc/can_capture_turf(turf/T)
var/viewer = src
if(src.client) //To make shooting through security cameras possible
viewer = src.client.eye
var/can_see = (T in view(viewer))
return can_see
/obj/item/device/camera/proc/captureimage(atom/target, mob/living/user, flag)
var/x_c = target.x - (size-1)/2
var/y_c = target.y + (size-1)/2
var/z_c = target.z
var/mobs = ""
for(var/i = 1 to size)
for(var/j = 1 to size)
var/turf/T = locate(x_c, y_c, z_c)
if(user.can_capture_turf(T))
mobs += get_mobs(T)
x_c++
y_c--
x_c = x_c - size
var/obj/item/photo/p = createpicture(target, user, mobs, flag)
printpicture(user, p)
/obj/item/device/camera/proc/createpicture(atom/target, mob/user, mobs, flag)
var/x_c = target.x - (size-1)/2
var/y_c = target.y - (size-1)/2
var/z_c = target.z
var/icon/photoimage = generate_image(x_c, y_c, z_c, size, CAPTURE_MODE_REGULAR, user, 0)
var/obj/item/photo/p = new()
p.img = photoimage
p.desc = mobs
p.photo_size = size
p.update_icon()
return p
/obj/item/device/camera/proc/printpicture(mob/user, obj/item/photo/p)
if(!user.put_in_inactive_hand(p))
p.dropInto(loc)
/obj/item/photo/proc/copy(copy_id = 0)
var/obj/item/photo/p = new/obj/item/photo()
p.SetName(name) // Do this first, manually, to make sure listeners are alerted properly.
p.appearance = appearance
p.tiny = new
p.tiny.appearance = tiny.appearance
p.img = icon(img)
p.photo_size = photo_size
p.scribble = scribble
if(copy_id)
p.id = id
return p