diff --git a/complex.cpp b/complex.cpp index 81149d86..53ab5dcf 100644 --- a/complex.cpp +++ b/complex.cpp @@ -2569,6 +2569,25 @@ EX namespace tortoise { EX string measure(int bits) { return "(" + its(progress(bits)) + "/" + its(tortoise::numbits) + ")"; } + + template void swap_data(T& data, cell *c1, cell *c2) { + changes.map_value(data, c1); + changes.map_value(data, c2); + if(data.count(c1) && data.count(c2)) + swap(data[c1], data[c2]); + else if(data.count(c1)) + data[c2] = data[c1], data.erase(c1); + else if(data.count(c2)) + data[c1] = data[c2], data.erase(c2); + } + + EX void move_baby(cell *c1, cell *c2) { + swap_data(babymap, c1, c2); + } + + EX void move_adult(cell *c1, cell *c2) { + swap_data(emap, c1, c2); + } EX } EX namespace dragon { diff --git a/items.cpp b/items.cpp index 4699a3fa..2fff8b36 100644 --- a/items.cpp +++ b/items.cpp @@ -347,9 +347,8 @@ EX void moveItem1(cell *from, cell *to, bool activateYendor) { yendor::yi[i].actualKey = to; } - if(from->item == itBabyTortoise) { - tortoise::babymap[to] = tortoise::babymap[from]; - tortoise::babymap.erase(from); + if(from->item == itBabyTortoise || to->item == itBabyTortoise) { + tortoise::move_baby(from, to); } eItem i = to->item; diff --git a/monstermove.cpp b/monstermove.cpp index 9b789a5d..298b63b8 100644 --- a/monstermove.cpp +++ b/monstermove.cpp @@ -87,20 +87,14 @@ EX void moveEffect(const movei& mi, eMonster m) { if(cf && m == moKnight) camelot::move_knight(cf, ct); if(cf && m == moTortoise) { - changes.map_value(tortoise::emap, ct); - changes.map_value(tortoise::emap, cf); - tortoise::emap[ct] = tortoise::getb(cf); - tortoise::emap.erase(cf); + tortoise::move_adult(cf, ct); } if(cf && ct->item == itBabyTortoise && !cf->item) { - changes.map_value(tortoise::babymap, ct); - changes.map_value(tortoise::babymap, cf); cf->item = itBabyTortoise; ct->item = itNone; animateMovement(mi.rev(), LAYER_BOAT); - tortoise::babymap[cf] = tortoise::babymap[ct]; - tortoise::babymap.erase(ct); + tortoise::move_baby(cf, ct); } } diff --git a/pcmove.cpp b/pcmove.cpp index e0b206dc..a1bb7f9b 100644 --- a/pcmove.cpp +++ b/pcmove.cpp @@ -517,6 +517,12 @@ void apply_chaos() { princess::move(movei{cb, ca, JUMP}); if(isPrincess(cb) && !isPrincess(ca)) princess::move(movei{ca, cb, JUMP}); + if(ca->monst == moTortoise || cb->monst == moTortoise) { + tortoise::move_adult(ca, cb); + } + if(ca->item == itBabyTortoise || cb->item == itBabyTortoise) { + tortoise::move_baby(ca, cb); + } } bool pcmove::actual_move() {