Method code for $has_reactions.set_active()

[Turn on line numbering]
arg id;
var ra, key, e, inserted, chance, times;

if (!reactions || !dict_contains(reactions, id))
    throw(~noreaction, "No reaction with id '" + id + "'.");
if (!active)
    active = #[];
[key, chance, times] = sublist(reactions[id], 3, 3);
if (dict_contains(active, key)) {
    ra = active[key];
    if (ra.contains(id))
        return .update_active(key, id, [chance, times]);
    active = dict_del(active, key);
    ra = map e in (ra) to (e);
} else {
    ra = [];
}
for e in [1 .. listlen(ra)] {
    if (ra[e][2][1] < chance) {
        ra = insert(ra, e, [id, [chance, times]]);
        inserted++;
    }
}
if (!inserted)
    ra += [[id, [chance, times]]];
active = dict_add(active, key, hash e in (ra) to (e));

["// Created 23-Aug-1995 as a part of ColdCore, see: @help Credit"]

the Cold Dark