Files
Bubberstation/code/game/atom/atom_invisibility.dm
Afevis 55f4249785 fixes runtime when trying to remove a nonexistent source ID via RemoveInvisibility() (#83253)
```
[2024-05-15 18:24:21.291] RUNTIME: runtime error: cannot read from list
 - proc name: RemoveInvisibility (/atom/proc/RemoveInvisibility)
 -   source file: code/game/atom/atom_invisibility.dm,66
 -   usr: null
 -   src: the turret (/obj/machinery/porta_turret/ai)
 -   src.loc: the floor (187,33,3) (/turf/open/floor/circuit)
 -   call stack:
 - the turret (/obj/machinery/porta_turret/ai): RemoveInvisibility(/obj/machinery/porta_turret_co... (/obj/machinery/porta_turret_cover))
 - the turret (/obj/machinery/porta_turret_cover): Destroy(0)
 - qdel(the turret (/obj/machinery/porta_turret_cover), 0)
 - the turret (/obj/machinery/porta_turret/ai): atom break("melee")
 - the turret (/obj/machinery/porta_turret/ai): take damage(20, "brute", "melee", 1, 4, 0)
 - the turret (/obj/machinery/porta_turret/ai): take damage(40, "brute", "melee", 1, 4, 0)
 - the turret (/obj/machinery/porta_turret/ai): attack generic(the turret (/mob/living/simple_animal/hostile/mimic/copy/machine), 40, "brute", "melee", 1, 0)
 - the turret (/obj/machinery/porta_turret/ai): attack animal(the turret (/mob/living/simple_animal/hostile/mimic/copy/machine), null)
 - the turret (/mob/living/simple_animal/hostile/mimic/copy/machine): AttackingTarget(the turret (/obj/machinery/porta_turret/ai))
 - the turret (/mob/living/simple_animal/hostile/mimic/copy/machine): AttackingTarget(the turret (/obj/machinery/porta_turret/ai))
 - the turret (/mob/living/simple_animal/hostile/mimic/copy/machine): MeleeAction(1)
 - the turret (/mob/living/simple_animal/hostile/mimic/copy/machine): MoveToTarget(/list (/list))
 - the turret (/mob/living/simple_animal/hostile/mimic/copy/machine): handle automated action()
 - NPC Pool (/datum/controller/subsystem/npcpool): fire(0)
 - NPC Pool (/datum/controller/subsystem/npcpool): ignite(0)
 - Master (/datum/controller/master): RunQueue()
 - Master (/datum/controller/master): Loop(2)
 - Master (/datum/controller/master): StartProcessing(0)
 - 

```
2024-05-16 23:40:23 -06:00

73 lines
2.0 KiB
Plaintext

// Index defines
#define INVISIBILITY_VALUE 1
#define INVISIBILITY_PRIORITY 2
/atom
VAR_PRIVATE/list/invisibility_sources
VAR_PRIVATE/current_invisibility_priority = -INFINITY
/atom/proc/RecalculateInvisibility()
PRIVATE_PROC(TRUE)
if(!invisibility_sources)
current_invisibility_priority = -INFINITY
invisibility = initial(invisibility)
return
var/highest_priority
var/list/highest_priority_invisibility_data
for(var/entry in invisibility_sources)
var/list/priority_data
if(islist(entry))
priority_data = entry
else
priority_data = invisibility_sources[entry]
var/priority = priority_data[INVISIBILITY_PRIORITY]
if(highest_priority > priority) // In the case of equal priorities, we use the last thing in the list so that more recent changes apply first
continue
highest_priority = priority
highest_priority_invisibility_data = priority_data
current_invisibility_priority = highest_priority
invisibility = highest_priority_invisibility_data[INVISIBILITY_VALUE]
/**
* Sets invisibility according to priority.
* If you want to be able to undo the value you set back to what it would be otherwise,
* you should provide an id here and remove it using RemoveInvisibility(id)
*/
/atom/proc/SetInvisibility(desired_value, id, priority=0)
if(!invisibility_sources)
invisibility_sources = list()
if(id)
invisibility_sources[id] = list(desired_value, priority)
else
invisibility_sources += list(list(desired_value, priority))
if(current_invisibility_priority > priority)
return
RecalculateInvisibility()
/// Removes the specified invisibility source from the tracker
/atom/proc/RemoveInvisibility(id)
if(!invisibility_sources?[id])
return
var/list/priority_data = invisibility_sources[id]
invisibility_sources -= id
if(length(invisibility_sources) == 0)
invisibility_sources = null
if(current_invisibility_priority > priority_data[INVISIBILITY_PRIORITY])
return
RecalculateInvisibility()
#undef INVISIBILITY_VALUE
#undef INVISIBILITY_PRIORITY