-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathlife.dm
638 lines (537 loc) · 18 KB
/
life.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
/mob/living/simple_animal/slime
var/AIproc = 0 // determines if the AI loop is activated
var/Atkcool = 0 // attack cooldown
var/Tempstun = 0 // temporary temperature stuns
var/Discipline = 0 // if a slime has been hit with a freeze gun, or wrestled/attacked off a human, they become disciplined and don't attack anymore for a while
var/SStun = 0 // stun variable
/mob/living/simple_animal/slime/Life(seconds_per_tick = SSMOBS_DT, times_fired)
set invisibility = 0
if (notransform)
return
if(..())
if(buckled)
handle_feeding()
if(!stat) // Slimes in stasis don't lose nutrition, don't change mood and don't respond to speech
handle_nutrition()
if(QDELETED(src)) // Stop if the slime split during handle_nutrition()
return
reagents.remove_all(0.5 * REAGENTS_METABOLISM * reagents.reagent_list.len) //Slimes are such snowflakes
handle_targets()
if (!ckey)
handle_mood()
handle_speech()
// Unlike most of the simple animals, slimes support UNCONSCIOUS
/mob/living/simple_animal/slime/update_stat()
if(stat == UNCONSCIOUS && health > 0)
return
..()
/mob/living/simple_animal/slime/proc/AIprocess() // the master AI process
if(AIproc || stat || client)
return
var/hungry = 0
if (nutrition < get_starve_nutrition())
hungry = 2
else if (nutrition < get_grow_nutrition() && prob(25) || nutrition < get_hunger_nutrition())
hungry = 1
AIproc = 1
while(AIproc && stat != DEAD && (attacked || hungry || rabid || buckled))
if(!(mobility_flags & MOBILITY_MOVE)) //also covers buckling. Not sure why buckled is in the while condition if we're going to immediately break, honestly
break
if(!Target || client)
break
if(Target.health <= -70 || Target.stat == DEAD)
set_target(null)
AIproc = 0
break
if(Target)
if(locate(/mob/living/simple_animal/slime) in Target.buckled_mobs)
set_target(null)
AIproc = 0
break
if(!AIproc)
break
if(Target in view(1,src))
if(!CanFeedon(Target)) //If they're not able to be fed upon, ignore them.
if(!Atkcool)
Atkcool = 1
spawn(45)
Atkcool = 0
if(Target.Adjacent(src))
Target.attack_slime(src)
break
if((Target.mobility_flags & MOBILITY_STAND) && prob(80))
if(Target.client && Target.health >= 20)
if(!Atkcool)
Atkcool = 1
spawn(45)
Atkcool = 0
if(Target.Adjacent(src))
Target.attack_slime(src)
else
if(!Atkcool && Target.Adjacent(src))
Feedon(Target)
else
if(!Atkcool && Target.Adjacent(src))
Feedon(Target)
else if(Target in view(7, src))
if(!Target.Adjacent(src))
// Bug of the month candidate: slimes were attempting to move to target only if it was directly next to them, which caused them to target things, but not approach them
step_to(src, Target)
else
set_target(null)
AIproc = 0
break
var/sleeptime = movement_delay()
if(sleeptime <= 0)
sleeptime = 0.1 SECONDS
sleep(sleeptime + 0.2 SECONDS) // this is about as fast as a player slime can go
AIproc = 0
/mob/living/simple_animal/slime/handle_environment(datum/gas_mixture/environment)
if(!environment)
return
var/loc_temp = get_temperature(environment)
var/heat_capacity_factor = min(1, environment.heat_capacity() / environment.return_volume())
adjust_bodytemperature(adjust_body_temperature(bodytemperature, loc_temp, 1) * heat_capacity_factor)
//Account for massive pressure differences
if(bodytemperature < (T0C + 5)) // start calculating temperature damage etc
if(bodytemperature <= (T0C - 40)) // stun temperature
Tempstun = 1
if(bodytemperature <= (T0C - 50)) // hurt temperature
if(bodytemperature <= 50) // sqrting negative numbers is bad
adjustBruteLoss(200)
else
adjustBruteLoss(round(sqrt(bodytemperature)) * 2)
else
Tempstun = 0
if(stat != DEAD)
var/bz_percentage = environment.total_moles() ? (environment.get_moles(GAS_BZ) / environment.total_moles()) : 0
var/stasis = (bz_percentage >= 0.05 && bodytemperature < (T0C + 100)) || force_stasis
if(stat == CONSCIOUS && stasis)
to_chat(src, span_danger("Nerve gas in the air has put you in stasis!"))
set_stat(UNCONSCIOUS)
powerlevel = 0
rabid = 0
update_mobility()
regenerate_icons()
else if(stat == UNCONSCIOUS && !stasis)
to_chat(src, span_notice("You wake up from the stasis."))
set_stat(CONSCIOUS)
update_mobility()
regenerate_icons()
updatehealth()
return //TODO: DEFERRED
/mob/living/simple_animal/slime/proc/adjust_body_temperature(current, loc_temp, boost)
var/temperature = current
var/difference = abs(current-loc_temp) //get difference
var/increments// = difference/10 //find how many increments apart they are
if(difference > 50)
increments = difference/5
else
increments = difference/10
var/change = increments*boost // Get the amount to change by (x per increment)
var/temp_change
if(current < loc_temp)
temperature = min(loc_temp, temperature+change)
else if(current > loc_temp)
temperature = max(loc_temp, temperature-change)
temp_change = (temperature - current)
return temp_change
/mob/living/simple_animal/slime/handle_status_effects()
..()
if(prob(30) && !stat)
adjustBruteLoss(-1)
/mob/living/simple_animal/slime/proc/handle_feeding()
if(!ismob(buckled))
return
var/mob/M = buckled
if(stat)
Feedstop(silent = TRUE)
if(M.stat == DEAD) // our victim died
if(!client)
if(!rabid && !attacked)
var/mob/last_to_hurt = M.LAssailant?.resolve()
if(last_to_hurt && last_to_hurt != M)
if(prob(50))
add_friendship(last_to_hurt, 1)
else
to_chat(src, "<i>This subject does not have a strong enough life energy anymore...</i>")
if(M.client && ishuman(M))
if(prob(85))
rabid = 1 //we go rabid after finishing to feed on a human with a client.
Feedstop()
return
if(iscarbon(M))
var/mob/living/carbon/C = M
C.adjustCloneLoss(rand(2,4))
C.adjustToxLoss(rand(1,2))
if(prob(10) && C.client)
to_chat(C, "<span class='userdanger'>[pick("You can feel your body becoming weak!", \
"You feel like you're about to die!", \
"You feel every part of your body screaming in agony!", \
"A low, rolling pain passes through your body!", \
"Your body feels as if it's falling apart!", \
"You feel extremely weak!", \
"A sharp, deep pain bathes every inch of your body!")]</span>")
else if(isanimal(M))
var/mob/living/simple_animal/SA = M
var/totaldamage = 0 //total damage done to this unfortunate animal
totaldamage += SA.adjustCloneLoss(rand(2,4))
totaldamage += SA.adjustToxLoss(rand(1,2))
if(totaldamage <= 0) //if we did no(or negative!) damage to it, stop
Feedstop(0, 0)
return
else
Feedstop(0, 0)
return
add_nutrition((rand(7, 15) * CONFIG_GET(number/damage_multiplier)))
//Heal yourself.
adjustBruteLoss(-3)
/mob/living/simple_animal/slime/proc/handle_nutrition()
if(docile) //God as my witness, I will never go hungry again
set_nutrition(700) //fuck you for using the base nutrition var
return
if(prob(15))
adjust_nutrition(-(1 + is_adult))
if(nutrition <= 0)
set_nutrition(0)
if(prob(75))
adjustBruteLoss(rand(0,5))
else if (nutrition >= get_grow_nutrition() && amount_grown < SLIME_EVOLUTION_THRESHOLD)
adjust_nutrition(-20)
amount_grown++
update_mob_action_buttons()
if(amount_grown >= SLIME_EVOLUTION_THRESHOLD && !buckled && !Target && !ckey)
if(is_adult)
Reproduce()
else
Evolve()
/mob/living/simple_animal/slime/proc/add_nutrition(nutrition_to_add = 0)
set_nutrition(min((nutrition + nutrition_to_add), get_max_nutrition()))
if(nutrition >= get_grow_nutrition())
if(powerlevel<10)
if(prob(30-powerlevel*2))
powerlevel++
else if(nutrition >= get_hunger_nutrition() + 100) //can't get power levels unless you're a bit above hunger level.
if(powerlevel<5)
if(prob(25-powerlevel*5))
powerlevel++
/mob/living/simple_animal/slime/proc/handle_targets()
update_mobility()
if(Tempstun)
if(!buckled) // not while they're eating!
mobility_flags &= ~MOBILITY_MOVE
if(attacked > 50)
attacked = 50
if(attacked > 0)
attacked--
if(Discipline > 0)
if(Discipline >= 5 && rabid)
if(prob(60))
rabid = 0
if(prob(10))
Discipline--
if(!client)
if(!(mobility_flags & MOBILITY_MOVE))
return
if(buckled)
return // if it's eating someone already, continue eating!
if(Target)
--target_patience
if (target_patience <= 0 || SStun > world.time || Discipline || attacked || docile) // Tired of chasing or something draws out attention
target_patience = 0
set_target(null)
if(AIproc && SStun > world.time)
return
var/hungry = 0 // determines if the slime is hungry
if (nutrition < get_starve_nutrition())
hungry = 2
else if (nutrition < get_grow_nutrition() && prob(25) || nutrition < get_hunger_nutrition())
hungry = 1
if(hungry == 2 && !client) // if a slime is starving, it starts losing its friends
if(Friends.len > 0 && prob(1))
var/mob/nofriend = pick(Friends)
add_friendship(nofriend, -1)
if(!Target)
if(will_hunt() && hungry || attacked || rabid) // Only add to the list if we need to
var/list/targets = list()
for(var/mob/living/L in view(7,src))
if(isslime(L) || L.stat == DEAD) // Ignore other slimes and dead mobs
continue
if(L in Friends) // No eating friends!
continue
var/ally = FALSE
for(var/F in faction)
if(F == "neutral") //slimes are neutral so other mobs not target them, but they can target neutral mobs
continue
if(F in L.faction)
ally = TRUE
break
if(ally)
continue
if(issilicon(L) && (rabid || attacked)) // They can't eat silicons, but they can glomp them in defence
targets += L // Possible target found!
if(ishuman(L)) //Ignore slime(wo)men
var/mob/living/carbon/human/H = L
if(src.type in H.dna.species.ignored_by)
continue
if(locate(/mob/living/simple_animal/slime) in L.buckled_mobs) // Only one slime can latch on at a time.
continue
targets += L // Possible target found!
if(targets.len > 0)
if(attacked || rabid || hungry == 2)
set_target(targets[1]) // I am attacked and am fighting back or so hungry I don't even care
else
for(var/mob/living/carbon/C in targets)
if(!Discipline && prob(5))
if(ishuman(C) || isalienadult(C))
set_target(C)
break
if(islarva(C) || ismonkey(C))
set_target(C)
break
if (Target)
target_patience = rand(5,7)
if (is_adult)
target_patience += 3
if(!Target) // If we have no target, we are wandering or following orders
if (Leader)
if(holding_still)
holding_still = max(holding_still - 1, 0)
else if((mobility_flags & MOBILITY_MOVE) && isturf(loc))
step_to(src, Leader)
else if(hungry)
if (holding_still)
holding_still = max(holding_still - hungry, 0)
else if((mobility_flags & MOBILITY_MOVE) && isturf(loc) && prob(50))
step(src, pick(GLOB.cardinals))
else
if(holding_still)
holding_still = max(holding_still - 1, 0)
else if (docile && pulledby)
holding_still = 10
else if((mobility_flags & MOBILITY_MOVE) && isturf(loc) && prob(33))
step(src, pick(GLOB.cardinals))
else if(!AIproc)
INVOKE_ASYNC(src, PROC_REF(AIprocess))
/mob/living/simple_animal/slime/handle_automated_movement()
return //slime random movement is currently handled in handle_targets()
/mob/living/simple_animal/slime/handle_automated_speech()
return //slime random speech is currently handled in handle_speech()
/mob/living/simple_animal/slime/proc/handle_mood()
var/newmood = ""
if (rabid || attacked)
newmood = "angry"
else if (docile)
newmood = ":3"
else if (Target)
newmood = "mischievous"
if (!newmood)
if (Discipline && prob(25))
newmood = "pout"
else if (prob(1))
newmood = pick("sad", ":3", "pout")
if ((mood == "sad" || mood == ":3" || mood == "pout") && !newmood)
if(prob(75))
newmood = mood
if (newmood != mood) // This is so we don't redraw them every time
mood = newmood
regenerate_icons()
/mob/living/simple_animal/slime/proc/handle_speech()
//Speech understanding starts here
var/to_say
if (speech_buffer.len > 0)
var/who = speech_buffer[1] // Who said it?
var/phrase = speech_buffer[2] // What did they say?
if ((findtext(phrase, num2text(number)) || findtext(phrase, "slimes"))) // Talking to us
if (findtext(phrase, "hello") || findtext(phrase, "hi"))
to_say = pick("Hello...", "Hi...")
else if (findtext(phrase, "follow"))
if (Leader)
if (Leader == who) // Already following him
to_say = pick("Yes...", "Lead...", "Follow...")
else if (Friends[who] > Friends[Leader]) // VIVA
set_leader(who)
to_say = "Yes... I follow [who]..."
else
to_say = "No... I follow [Leader]..."
else
if (Friends[who] >= SLIME_FRIENDSHIP_FOLLOW)
set_leader(who)
to_say = "I follow..."
else // Not friendly enough
to_say = pick("No...", "I no follow...")
else if (findtext(phrase, "stop"))
if (buckled) // We are asked to stop feeding
if (Friends[who] >= SLIME_FRIENDSHIP_STOPEAT)
Feedstop()
set_target(null)
if (Friends[who] < SLIME_FRIENDSHIP_STOPEAT_NOANGRY)
add_friendship(who, -1)
to_say = "Grrr..." // I'm angry but I do it
else
to_say = "Fine..."
else if (Target) // We are asked to stop chasing
if (Friends[who] >= SLIME_FRIENDSHIP_STOPCHASE)
set_target(null)
if (Friends[who] < SLIME_FRIENDSHIP_STOPCHASE_NOANGRY)
add_friendship(who, -1)
to_say = "Grrr..." // I'm angry but I do it
else
to_say = "Fine..."
else if (Leader) // We are asked to stop following
if (Leader == who)
to_say = "Yes... I stay..."
set_target(null)
else
if (Friends[who] > Friends[Leader])
set_target(null)
to_say = "Yes... I stop..."
else
to_say = "No... keep follow..."
else if (findtext(phrase, "stay"))
if (Leader)
if (Leader == who)
holding_still = Friends[who] * 10
to_say = "Yes... stay..."
else if (Friends[who] > Friends[Leader])
holding_still = (Friends[who] - Friends[Leader]) * 10
to_say = "Yes... stay..."
else
to_say = "No... keep follow..."
else
if (Friends[who] >= SLIME_FRIENDSHIP_STAY)
holding_still = Friends[who] * 10
to_say = "Yes... stay..."
else
to_say = "No... won't stay..."
else if (findtext(phrase, "attack"))
if (rabid && prob(20))
set_target(who)
AIprocess() //Wake up the slime's Target AI, needed otherwise this doesn't work
to_say = "ATTACK!?!?"
else if (Friends[who] >= SLIME_FRIENDSHIP_ATTACK)
for (var/mob/living/L in view(7,src)-list(src,who))
if (findtext(phrase, lowertext(L.name)))
if (isslime(L))
to_say = "NO... [L] slime friend"
add_friendship(who, -1) //Don't ask a slime to attack its friend
else if(!Friends[L] || Friends[L] < 1)
set_target(L)
AIprocess()//Wake up the slime's Target AI, needed otherwise this doesn't work
to_say = "Ok... I attack [Target]"
else
to_say = "No... like [L] ..."
add_friendship(who, -1) //Don't ask a slime to attack its friend
break
else
to_say = "No... no listen"
speech_buffer = list()
//Speech starts here
if (to_say)
say (to_say)
else if(prob(1))
emote(pick("bounce","sway","light","vibrate","jiggle"))
else
var/t = 10
var/slimes_near = 0
var/dead_slimes = 0
var/friends_near = list()
for (var/mob/living/L in view(7,src))
if(isslime(L) && L != src)
++slimes_near
if (L.stat == DEAD)
++dead_slimes
if (L in Friends)
t += 20
friends_near += L
if (nutrition < get_hunger_nutrition())
t += 10
if (nutrition < get_starve_nutrition())
t += 10
if (prob(2) && prob(t))
var/phrases = list()
if (Target)
phrases += "[Target]... look yummy..."
if (nutrition < get_starve_nutrition())
phrases += "So... hungry..."
phrases += "Very... hungry..."
phrases += "Need... food..."
phrases += "Must... eat..."
else if (nutrition < get_hunger_nutrition())
phrases += "Hungry..."
phrases += "Where food?"
phrases += "I want to eat..."
phrases += "Rawr..."
phrases += "Blop..."
phrases += "Blorble..."
if (rabid || attacked)
phrases += "Hrr..."
phrases += "Nhuu..."
phrases += "Unn..."
if (mood == ":3")
phrases += "Purr..."
if (attacked)
phrases += "Grrr..."
if (bodytemperature < T0C)
phrases += "Cold..."
if (bodytemperature < T0C - 30)
phrases += "So... cold..."
phrases += "Very... cold..."
if (bodytemperature < T0C - 50)
phrases += "..."
phrases += "C... c..."
if (buckled)
phrases += "Nom..."
phrases += "Yummy..."
if (powerlevel > 3)
phrases += "Bzzz..."
if (powerlevel > 5)
phrases += "Zap..."
if (powerlevel > 8)
phrases += "Zap... Bzz..."
if (mood == "sad")
phrases += "Bored..."
if (slimes_near)
phrases += "Slime friend..."
if (slimes_near > 1)
phrases += "Slime friends..."
if (dead_slimes)
phrases += "What happened?"
if (!slimes_near)
phrases += "Lonely..."
for (var/M in friends_near)
phrases += "[M]... friend..."
if (nutrition < get_hunger_nutrition())
phrases += "[M]... feed me..."
if(!stat)
say (pick(phrases))
/mob/living/simple_animal/slime/proc/get_max_nutrition() // Can't go above it
if (is_adult)
return 1200
else
return 1000
/mob/living/simple_animal/slime/proc/get_grow_nutrition() // Above it we grow, below it we can eat
if (is_adult)
return 1000
else
return 800
/mob/living/simple_animal/slime/proc/get_hunger_nutrition() // Below it we will always eat
if (is_adult)
return 600
else
return 500
/mob/living/simple_animal/slime/proc/get_starve_nutrition() // Below it we will eat before everything else
if(is_adult)
return 300
else
return 200
/mob/living/simple_animal/slime/proc/will_hunt(hunger = -1) // Check for being stopped from feeding and chasing
if (docile)
return 0
if (hunger == 2 || rabid || attacked)
return 1
if (Leader)
return 0
if (holding_still)
return 0
return 1