1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-09-01 18:27:55 +00:00

refactored whirlline loop detection

This commit is contained in:
Zeno Rogue
2021-08-08 19:13:09 +02:00
parent 025893e946
commit a6151f185f
3 changed files with 24 additions and 9 deletions

View File

@@ -865,4 +865,25 @@ EX void monstersTurn() {
#endif
}
/** check if whirlline is looped, if yes, remove the repeat; may not detect loops immediately */
EX bool looped(vector<cell*>& whirlline) {
if(isize(whirlline) == 1)
return false;
if(whirlline.back() == whirlline.front()) {
whirlline.pop_back();
return true;
}
int pos = isize(whirlline)/2;
if(isize(whirlline) > 2 && whirlline.back() == whirlline[pos]) {
while(pos && whirlline.back() == whirlline[pos])
whirlline.pop_back();
/* something weird must have happened... */
static bool once = true;
if(once) addMessage("warning: a looped line");
once = false;
return true;
}
return false;
}
}