Skip to content

Commit 1456138

Browse files
committed
Human process stuff
1 parent 327c047 commit 1456138

File tree

5 files changed

+104
-55
lines changed

5 files changed

+104
-55
lines changed

code/datums/managed_inventory.dm

+58-30
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
var/list/medical_list
2020
var/list/grenade_list
2121
var/list/engineering_list
22+
var/list/food_list
2223
//damage type specific item lists
2324
var/list/brute_list
2425
var/list/burn_list
@@ -61,6 +62,7 @@
6162
QDEL_NULL(medical_list)
6263
QDEL_NULL(grenade_list)
6364
QDEL_NULL(engineering_list)
65+
QDEL_NULL(food_list)
6466

6567
QDEL_NULL(brute_list)
6668
QDEL_NULL(burn_list)
@@ -82,6 +84,7 @@
8284
medical_list = list()
8385
grenade_list = list()
8486
engineering_list = list()
87+
food_list = list()
8588

8689
brute_list = list()
8790
burn_list = list()
@@ -103,8 +106,6 @@
103106
return
104107
if(equipped_item in equipped_list)
105108
return
106-
RegisterSignal(equipped_item, COMSIG_ATOM_ENTERED, PROC_REF(item_stored))
107-
RegisterSignal(equipped_item, COMSIG_ITEM_REMOVED_INVENTORY, PROC_REF(item_unequipped))
108109
equipped_list += equipped_item
109110

110111
var/list/sort_list = list(equipped_item)
@@ -136,66 +137,85 @@
136137
for(var/obj/item/thing AS in sort_list)
137138
SEND_SIGNAL(thing, COMSIG_INVENTORY_STORED_REMOVAL)
138139

139-
//wrapper due to arg order, can probs remove tho
140+
///Wrapper for sorting a newly stored item
140141
/datum/managed_inventory/proc/item_stored(mob/store_mob, obj/item/new_item, slot)
141142
SIGNAL_HANDLER
142143
sort_item(new_item)
143144

145+
///Sorts an item into any relevant lists
144146
/datum/managed_inventory/proc/sort_item(obj/item/new_item)
145-
if(isgun(new_item))
146-
gun_list_add(new_item)
147+
var/list/chosen_list = get_right_list(new_item)
148+
if(!chosen_list)
147149
return
150+
if(new_item in chosen_list)
151+
return //moved around on our mob
152+
153+
RegisterSignal(new_item, COMSIG_ATOM_ENTERED, PROC_REF(item_stored))
154+
RegisterSignal(new_item, COMSIG_ITEM_REMOVED_INVENTORY, PROC_REF(item_unequipped))
155+
156+
if(chosen_list == gun_list)
157+
gun_list_add(new_item)
158+
if(chosen_list == melee_list)
159+
melee_list_add(new_item)
160+
if(chosen_list == grenade_list)
161+
grenade_list_add(new_item)
162+
if(chosen_list == ammo_list)
163+
ammo_list_add(new_item)
164+
if(chosen_list == medical_list)
165+
medical_list_add(new_item)
166+
if(chosen_list == engineering_list)
167+
engineering_list_add(new_item)
168+
if(chosen_list == food_list)
169+
food_list_add(new_item)
170+
171+
///Finds the right list for an item
172+
/datum/managed_inventory/proc/get_right_list(obj/item/new_item)
173+
if(isgun(new_item))
174+
return gun_list
148175
if((istype(new_item, /obj/item/weapon))) //|| istype(new_item, /obj/item/attachable/bayonetknife) //they are a completely different type, so fuck out due to the force changes. sob
149176
if(istype(new_item, /obj/item/weapon/twohanded/offhand))
150177
return
151-
melee_list_add(new_item)
152-
return
178+
return melee_list
153179
if(istype(new_item, /obj/item/explosive/grenade))
154180
if(istype(new_item, /obj/item/explosive/grenade/flare))
155181
return
156-
grenade_list_add(new_item)
157-
return
182+
return grenade_list
158183
if(istype(new_item, /obj/item/ammo_magazine) || istype(new_item, /obj/item/cell/lasgun))
159-
ammo_list_add(new_item)
160-
return
184+
return ammo_list
161185
if(isitemstack(new_item))
162186
if(istype(new_item, /obj/item/stack/medical))
163-
medical_list_add(new_item)
164-
return
187+
return medical_list
165188
if(istype(new_item, /obj/item/stack/sheet))
166-
engineering_list_add(new_item)
167-
return
189+
return engineering_list
190+
if(isfood(new_item))
191+
return food_list
168192
if(isreagentcontainer(new_item) || istype(new_item, /obj/item/tweezers_advanced) || istype(new_item, /obj/item/tweezers))
169-
medical_list_add(new_item)
170-
return
193+
return medical_list
171194

172195
//boiler plate
173196

174197
///Adds an item to this list
175198
/datum/managed_inventory/proc/gun_list_add(obj/item/new_item)
176-
SIGNAL_HANDLER
177199
if(new_item in gun_list)
178200
return
179201
//I feel like there was some dumb ass reason why I wasn't able to do this... but with testing it works fine??
180202
//might have been relevant for non weapons in storage?
181203
//keep an eye on this.
182204
gun_list += new_item
183-
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(gun_list_removal), TRUE)//COMSIG_MOVABLE_MOVED is sent AFTER COMSIG_ATOM_ENTERED.. this is fucking annoying but eh
205+
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(gun_list_removal))//COMSIG_MOVABLE_MOVED is sent AFTER COMSIG_ATOM_ENTERED.. this is fucking annoying but eh
184206
SEND_SIGNAL(src, COMSIG_INVENTORY_DAT_GUN_ADDED)
185207

186208
///Adds an item to this list
187209
/datum/managed_inventory/proc/melee_list_add(obj/item/new_item)
188-
SIGNAL_HANDLER
189210
if(new_item in melee_list)
190211
return
191212
melee_list += new_item
192-
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(melee_list_removal), TRUE)
213+
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(melee_list_removal))
193214
SEND_SIGNAL(src, COMSIG_INVENTORY_DAT_MELEE_ADDED)
194215

195216
///Adds an item to the relevant med lists
196217
/datum/managed_inventory/proc/medical_list_add(obj/item/new_item)
197-
SIGNAL_HANDLER
198-
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(medical_list_removal), TRUE)
218+
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(medical_list_removal))
199219
var/generic = TRUE
200220
for(var/damtype in GLOB.ai_damtype_to_heal_list)
201221
if(!(new_item.type in GLOB.ai_damtype_to_heal_list[damtype]))
@@ -242,21 +262,23 @@
242262

243263
///Adds an item to this list
244264
/datum/managed_inventory/proc/ammo_list_add(obj/item/new_item)
245-
SIGNAL_HANDLER
246265
ammo_list |= new_item
247-
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(ammo_list_removal), TRUE)
266+
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(ammo_list_removal))
248267

249268
///Adds an item to this list
250269
/datum/managed_inventory/proc/grenade_list_add(obj/item/new_item)
251-
SIGNAL_HANDLER
252270
grenade_list |= new_item
253-
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(grenade_list_removal), TRUE)
271+
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(grenade_list_removal))
254272

255273
///Adds an item to this list
256274
/datum/managed_inventory/proc/engineering_list_add(obj/item/new_item)
257-
SIGNAL_HANDLER
258275
engineering_list |= new_item
259-
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(engineering_list_removal), TRUE)
276+
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(engineering_list_removal))
277+
278+
///Adds an item to this list
279+
/datum/managed_inventory/proc/food_list_add(obj/item/new_item)
280+
food_list |= new_item
281+
RegisterSignals(new_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL), PROC_REF(food_list_removal))
260282

261283
///Removes an item from this list
262284
/datum/managed_inventory/proc/gun_list_removal(obj/item/moving_item)
@@ -317,4 +339,10 @@
317339
engineering_list -= moving_item
318340
UnregisterSignal(moving_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL))
319341

320-
342+
///Removes an item from this list
343+
/datum/managed_inventory/proc/food_list_removal(obj/item/moving_item)
344+
SIGNAL_HANDLER
345+
if(!QDELETED(moving_item) && moving_item.loc == owner)
346+
return //still in inventory
347+
food_list -= moving_item
348+
UnregisterSignal(moving_item, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING, COMSIG_INVENTORY_STORED_REMOVAL))

code/modules/ai/ai_behaviors/ai_behavior.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ Registers signals, handles the pathfinding element addition/removal alongside ma
6464
mob_parent = parent_to_assign
6565
set_escorted_atom(null, escorted_atom)
6666
//We always use the escorted atom as our reference point for looking for target. So if we don't have any escorted atom, we take ourselve as the reference
67-
START_PROCESSING(SSprocessing, src)
6867
if(is_offered_on_creation)
6968
LAZYOR(GLOB.ssd_living_mobs, mob_parent)
7069

@@ -79,6 +78,7 @@ Registers signals, handles the pathfinding element addition/removal alongside ma
7978

8079
///Register ai behaviours
8180
/datum/ai_behavior/proc/start_ai()
81+
START_PROCESSING(SSprocessing, src)
8282
if(escorted_atom)
8383
global_set_escorted_atom(null, escorted_atom)
8484
RegisterSignal(SSdcs, COMSIG_GLOB_AI_GOAL_SET, PROC_REF(set_goal_node))

code/modules/ai/ai_behaviors/human_mobs/helper_procs.dm

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
return FALSE
2828
return TRUE
2929

30+
/obj/item/reagent_containers/food/ai_should_use(mob/living/target, mob/living/user)
31+
if(!ishuman(target))
32+
return FALSE
33+
var/mob/living/carbon/human/human_target = target
34+
if((reagents.get_reagent_amount(/datum/reagent/consumable/nutriment) * 37.5) + human_target.nutrition >= NUTRITION_OVERFED)
35+
return FALSE
36+
return TRUE
37+
3038
///AI uses this item in some manner, such as consuming or activating it
3139
/obj/item/proc/ai_use(mob/living/target, mob/living/user)
3240
return FALSE
@@ -69,6 +77,14 @@
6977
attack_self(user)
7078
return TRUE
7179

80+
/obj/item/reagent_containers/food/ai_use(mob/living/target, mob/living/user)
81+
target.attackby(src, user)
82+
83+
/obj/item/reagent_containers/food/snacks/ai_use(mob/living/target, mob/living/user)
84+
if(package)
85+
attack_self(user)
86+
return ..()
87+
7288
///AI mob interaction with this atom, such as picking it up
7389
/atom/proc/do_ai_interact(mob/living/interactor)
7490
interactor.UnarmedAttack(src, TRUE) //only used for picking up items atm

code/modules/ai/ai_behaviors/human_mobs/human_mob.dm

+12-1
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,20 @@
8787
if(mob_parent.do_actions)
8888
return ..()
8989

90+
if(human_parent.lying_angle)
91+
INVOKE_ASYNC(human_parent, TYPE_PROC_REF(/mob/living/carbon/human, get_up))
92+
9093
if((medical_rating >= AI_MED_MEDIC) && medic_process())
9194
return
9295

96+
var/mob/living/carbon/human/human_parent = mob_parent
97+
if((human_parent.nutrition <= NUTRITION_HUNGRY) && length(mob_inventory.food_list) && (human_parent.nutrition + (37.5 * human_parent.reagents.get_reagent_amount(/datum/reagent/consumable/nutriment)) < NUTRITION_WELLFED))
98+
var/obj/item/reagent_containers/food/food = mob_inventory.food_list[1]
99+
food.ai_use(mob_parent, mob_parent)
100+
101+
if(mob_parent.buckled && !istype(mob_parent.buckled, /obj/structure/droppod)) //unbuckling from your pod midflight is not ideal
102+
mob_parent.buckled.unbuckle_mob(mob_parent)
103+
93104
for(var/datum/action/action in ability_list)
94105
if(!action.ai_should_use(atom_to_walk_to)) //todo: some of these probably should be aimmed at combat_target somehow...
95106
continue
@@ -383,7 +394,7 @@
383394
human_ai_state_flags &= ~(HUMAN_AI_ANY_HEALING)
384395
late_initialize()
385396
return
386-
if(current_action == MOVING_TO_SAFETY)
397+
if((current_action == MOVING_TO_SAFETY) || !combat_target)
387398
if(attacker && attacker.faction != mob_parent.faction)
388399
set_combat_target(attacker)
389400
return

code/modules/reagents/reagent_containers/food/snacks.dm

+17-23
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,15 @@
2727
else
2828
reagents.add_reagent(rid, amount, data)
2929

30-
/obj/item/reagent_containers/food/snacks/proc/On_Consume(mob/M)
31-
if(!usr)
32-
return
33-
30+
///Handles effects when the snack is finished
31+
/obj/item/reagent_containers/food/snacks/proc/On_Consume(mob/consumer)
3432
if(reagents.total_volume)
3533
return
3634

37-
balloon_alert_to_viewers("Eats \the [src]")
38-
39-
usr.dropItemToGround(src) //so icons update :[
40-
35+
consumer.dropItemToGround(src)
4136
if(trash)
42-
var/obj/item/T = new trash
43-
usr.put_in_hands(T)
44-
37+
var/obj/item/new_trash = new trash
38+
consumer.put_in_hands(new_trash)
4539
qdel(src)
4640

4741
/obj/item/reagent_containers/food/snacks/attack_self(mob/user as mob)
@@ -53,7 +47,7 @@
5347
attack_hand(xeno_attacker)
5448

5549
/obj/item/reagent_containers/food/snacks/attack(mob/M, mob/user, def_zone)
56-
if(!reagents.total_volume) //Shouldn't be needed but it checks to see if it has anything left in it.
50+
if(!reagents?.total_volume) //Shouldn't be needed but it checks to see if it has anything left in it.
5751
balloon_alert(user, "None of [src] left")
5852
M.dropItemToGround(src) //so icons update :[
5953
qdel(src)
@@ -692,9 +686,9 @@
692686
. = ..()
693687
unpopped = rand(1,10)
694688

695-
/obj/item/reagent_containers/food/snacks/popcorn/On_Consume()
689+
/obj/item/reagent_containers/food/snacks/popcorn/On_Consume(mob/consumer)
696690
if(prob(unpopped)) //lol ...what's the point?
697-
to_chat(usr, span_warning("You bite down on an un-popped kernel!"))
691+
to_chat(consumer, span_warning("You bite down on an un-popped kernel!"))
698692
unpopped = max(0, unpopped-1)
699693
return ..()
700694

@@ -855,22 +849,22 @@
855849
balloon_alert_to_viewers("unwraps [src]")
856850
package = FALSE
857851

858-
/obj/item/reagent_containers/food/snacks/monkeycube/On_Consume(mob/M)
859-
to_chat(M, span_warning("Something inside of you suddently expands!</span>"))
860-
balloon_alert_to_viewers("eats [src]", ignored_mobs = M)
861-
usr.dropItemToGround(src)
862-
if(!ishuman(M))
852+
/obj/item/reagent_containers/food/snacks/monkeycube/On_Consume(mob/consumer)
853+
to_chat(consumer, span_warning("Something inside of you suddently expands!</span>"))
854+
balloon_alert_to_viewers("eats [src]", ignored_mobs = consumer)
855+
consumer.dropItemToGround(src)
856+
if(!ishuman(consumer))
863857
return ..()
864858
//Do not try to understand.
865-
var/obj/item/surprise = new(M)
859+
var/obj/item/surprise = new(consumer)
866860
var/mob/ook = monkey_type
867861
surprise.icon = initial(ook.icon)
868862
surprise.icon_state = initial(ook.icon_state)
869863
surprise.name = "malformed [initial(ook.name)]"
870864
surprise.desc = "Looks like \a very deformed [initial(ook.name)], a little small for its kind. It shows no signs of life."
871865
surprise.transform *= 0.6
872-
surprise.add_mob_blood(M)
873-
var/mob/living/carbon/human/H = M
866+
surprise.add_mob_blood(consumer)
867+
var/mob/living/carbon/human/H = consumer
874868
var/datum/limb/E = H.get_limb("chest")
875869
E.fracture()
876870
for (var/datum/internal_organ/I in E.internal_organs)
@@ -880,7 +874,7 @@
880874
E.cavity = 0
881875
else //someone is having a bad day
882876
E.createwound(CUT, 30)
883-
surprise.embed_into(M, E)
877+
surprise.embed_into(consumer, E)
884878
qdel(src)
885879

886880
/obj/item/reagent_containers/food/snacks/monkeycube/proc/Expand()

0 commit comments

Comments
 (0)