Winterbay
Active member
So I found a bug in BatBrain when you have an elemental form (like coldform).
the current code gives an error about editing a map's contents within foreach.
So I made the following change, which basically uses a couple of temporary variables to get around this mafia limitation.
It no longer breaks and appears to be working correctly with coldform.
(FYI this is the whole function, since I didn't have the original for a diff. The changes occur after the comment:
// if you have an elemental form, all damage to the monster is of that element)
Code:advevent to_event(string id, spread dmg, spread pdmg, string special, int howmanyrounds) { int aoe = 1; advevent res; res.id = id; res.rounds = howmanyrounds; matcher bittles = create_matcher("([a-z!]+?) (.+?)(?:$|, )",special); while (bittles.find()) switch (bittles.group(1)) { case "att": res.att = aoe*eval(bittles.group(2),fvars); break; case "def": res.def = aoe*eval(bittles.group(2),fvars); break; case "stun": res.stun = eval(bittles.group(2),fvars); break; case "mp": if (my_class() == $class[zombie master]) continue; res.mp = eval(bittles.group(2),fvars); break; case "meat": res.meat = eval(bittles.group(2),fvars); break; case "item": string[int] its = split_string(bittles.group(2),"; "); float v; foreach n,it in its { if (contains_text(id,"enthroned") && $ints[3450,4469,1445,1446,1447,1448] contains to_int(to_item(it)) && stolen contains to_item(it)) { v=0; break; } v += item_val(to_item(it)); } res.meat += v/count(its); break; case "aoe": aoe = min(howmanyfoes,to_int(bittles.group(2))); break; case "monster": boolean[monster] mlist; foreach n,mst in split_string(bittles.group(2),"\\|") mlist[to_monster(mst)] = true; if (!(mlist contains m)) return new advevent; break; case "notmonster": boolean[monster] mlist2; foreach n,mst in split_string(bittles.group(2),"\\|") mlist2[to_monster(mst)] = true; if (mlist2 contains m) return new advevent; break; case "phylum": if (m.phylum != to_phylum(bittles.group(2))) return new advevent; break; case "stats": string[int] sts = split_string(bittles.group(2),"\\|"); foreach n,st in sts res.stats[to_class((n+1)*2).primestat] = eval(st,fvars); break; case "!!": res.note = bittles.group(2); break; } res.endscombat = special.contains_text("endscombat"); res.dmg = factor(dmg,aoe); if (eform != $element[none]) { // if you have an elemental form, all damage to the monster is of that element float tmp = res.dmg[eForm]; element[int] toEmpty; foreach el,dm in res.dmg { if (el == eform) continue; toEmpty[count(toEmpty)] = el; tmp += dm; } res.dmg[eForm] = tmp; foreach eKey in toEmpty { res.dmg[toEmpty[eKey]] = 0; } if (res.dmg[$element[none]] > 0) { res.dmg[eform] += res.dmg[$element[none]]; res.dmg[$element[none]] = 0; } } res.pdmg = factor(pdmg,1.0); return res; }
You'll find that I posted a similar fix 2 pages or so back I think