Find and delete a light source. Assumes at most one light source is attached to an object at a time. */
| 96 | /* Find and delete a light source. |
| 97 | Assumes at most one light source is attached to an object at a time. */ |
| 98 | void |
| 99 | del_light_source(int type, anything *id) |
| 100 | { |
| 101 | light_source *curr; |
| 102 | anything tmp_id; |
| 103 | |
| 104 | tmp_id = cg.zeroany; |
| 105 | /* need to be prepared for dealing a with light source which |
| 106 | has only been partially restored during a level change |
| 107 | (in particular: chameleon vs prot. from shape changers) */ |
| 108 | switch (type) { |
| 109 | case LS_NONE: |
| 110 | impossible("del_light_source:type=none"); |
| 111 | tmp_id.a_uint = 0; |
| 112 | break; |
| 113 | case LS_OBJECT: |
| 114 | tmp_id.a_uint = id->a_obj ? id->a_obj->o_id : 0; |
| 115 | break; |
| 116 | case LS_MONSTER: |
| 117 | tmp_id.a_uint = id->a_monst->m_id; |
| 118 | break; |
| 119 | default: |
| 120 | tmp_id.a_uint = 0; |
| 121 | break; |
| 122 | } |
| 123 | |
| 124 | /* find the light source from its id */ |
| 125 | for (curr = gl.light_base; curr; curr = curr->next) { |
| 126 | if (curr->type != type) |
| 127 | continue; |
| 128 | if (curr->id.a_obj |
| 129 | == ((curr->flags & LSF_NEEDS_FIXUP) ? tmp_id.a_obj : id->a_obj)) |
| 130 | break; |
| 131 | } |
| 132 | if (curr) { |
| 133 | delete_ls(curr); |
| 134 | } else { |
| 135 | impossible("del_light_source: not found type=%d, id=%s", type, |
| 136 | fmt_ptr((genericptr_t) id->a_obj)); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /* remove a light source from the light_base list and free it */ |
| 141 | staticfn void |
no test coverage detected