1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-24 17:10:36 +00:00

fixed bugs with manual celllisters

This commit is contained in:
Zeno Rogue 2018-06-28 13:35:03 +02:00
parent d11044a80a
commit cf8dffd6b8
8 changed files with 38 additions and 37 deletions

View File

@ -104,7 +104,7 @@ namespace whirlwind {
}
}
void moveAt(cell *c, celllister& cl) {
void moveAt(cell *c, manual_celllister& cl) {
if(cl.listed(c)) return;
calcdirs(c);
if(qdirs != 1) return;
@ -143,7 +143,7 @@ namespace whirlwind {
}
void move() {
celllister cl(manual);
manual_celllister cl;
for(int i=0; i<isize(dcal); i++) {
cell *c = dcal[i];
moveAt(c, cl);
@ -349,7 +349,7 @@ namespace elec {
c->wall = waMetal; */
}
void listChargedCells(cell *c, celllister& cl, eCharge last = ecConductor) {
void listChargedCells(cell *c, manual_celllister& cl, eCharge last = ecConductor) {
if(cl.listed(c)) return;
eCharge here = getCharge(c);
/* if(c->cpdist <= 2) {
@ -370,8 +370,10 @@ namespace elec {
void init() {
chargecells.clear();
if(!haveelec && !afterOrb) return;
celllister cl(manual);
for(int i=0; i<isize(dcal); i++) listChargedCells(dcal[i], cl);
if(1) {
manual_celllister cl;
for(int i=0; i<isize(dcal); i++) listChargedCells(dcal[i], cl);
}
charges.resize(2);
charges[0].lowlink = 0; charges[1].lowlink = 1;
@ -1011,7 +1013,7 @@ namespace whirlpool {
generate(wto);
}
void moveAt(cell *c, celllister& cl) {
void moveAt(cell *c, manual_celllister& cl) {
if(c->land != laWhirlpool) return;
if(cl.listed(c)) return;
if(!(euclid || c->master->alt)) return;
@ -1038,7 +1040,7 @@ namespace whirlpool {
}
void move() {
celllister cl(manual);
manual_celllister cl;
for(int i=0; i<isize(dcal); i++) {
cell *c = dcal[i];
moveAt(c, cl);
@ -1793,7 +1795,7 @@ namespace heat {
vector<cell*> offscreen2;
celllister cl(manual);
manual_celllister cl;
int gr = gamerange();
@ -1940,7 +1942,7 @@ namespace heat {
vector<cell*> offscreen2;
celllister cl(manual);
manual_celllister cl;
vector<cell*>& allcells = currentmap->allcells();
@ -2837,7 +2839,7 @@ namespace prairie {
if(c2) c->mondir = neighborId(c, c2);
}
void moveAt(cell *c, celllister& cl) {
void moveAt(cell *c, manual_celllister& cl) {
if(!cl.add(c)) return;
vector<cell*> whirlline;
whirlline.push_back(c);
@ -2888,7 +2890,7 @@ namespace prairie {
}
void move() {
celllister cl(manual);
manual_celllister cl;
for(int i=0; i<isize(dcal); i++) {
cell *c = dcal[i];
if(isriver(c)) moveAt(c, cl);

View File

@ -5766,7 +5766,7 @@ void moveNormals(eMonster param) {
}
}
void markAmbush(cell *c, celllister& cl) {
void markAmbush(cell *c, manual_celllister& cl) {
if(!cl.add(c)) return;
forCellEx(c2, c)
if(c2->cpdist < c->cpdist)
@ -5778,7 +5778,7 @@ bool ambushed;
void checkAmbushState() {
if(havewhat & HF_HUNTER) {
celllister cl(manual);
manual_celllister cl;
for(cell *c: dcal) {
if(c->monst == moHunterDog) {
if(c->cpdist > ambush_distance)

31
hyper.h
View File

@ -2543,13 +2543,10 @@ extern vector<hrmap*> allmaps;
// list all cells in distance at most maxdist, or until when maxcount cells are reached
extern struct manual_t {} manual;
struct celllister {
struct manual_celllister {
vector<cell*> lst;
vector<int> tmps;
vector<int> dists;
bool listed(cell *c) {
return c->listindex >= 0 && c->listindex < isize(lst) && lst[c->listindex] == c;
}
@ -2557,29 +2554,31 @@ struct celllister {
bool add(cell *c) {
if(listed(c)) return false;
tmps.push_back(c->listindex);
lst.push_back(c);
c->listindex = isize(lst);
lst.push_back(c);
return true;
}
void add(cell *c, int d) {
~manual_celllister() {
for(int i=0; i<isize(lst); i++) lst[i]->listindex = tmps[i];
}
};
struct celllister : manual_celllister {
vector<int> dists;
void add_at(cell *c, int d) {
if(add(c)) dists.push_back(d);
}
~celllister() {
for(int i=0; i<isize(lst); i++) lst[i]->listindex = tmps[i];
}
celllister(manual_t) {
}
celllister(cell *orig, int maxdist, int maxcount, cell *breakon) {
add(orig, 0);
add_at(orig, 0);
cell *last = orig;
for(int i=0; i<isize(lst); i++) {
cell *c = lst[i];
if(maxdist) forCellCM(c2, c) {
add(c2, dists[i]+1);
add_at(c2, dists[i]+1);
if(c2 == breakon) return;
}
if(c == last) {

View File

@ -60,7 +60,7 @@ bool reptilecheat = false;
#define ONEMPTY if(d == 7 && passable(c, NULL, 0) && !safety)
bool blizzard_no_escape1(cell *c, celllister &cl) {
bool blizzard_no_escape1(cell *c, manual_celllister &cl) {
if(!cl.add(c)) return true;
if(c->item == itOrbSafety)
return false;
@ -76,7 +76,7 @@ bool blizzard_no_escape1(cell *c, celllister &cl) {
}
bool blizzard_no_escape(cell *c) {
celllister cl(manual);
manual_celllister cl;
return blizzard_no_escape1(c, cl);
}

View File

@ -621,7 +621,7 @@ namespace mapeditor {
vector<pair<cellwalker, cellwalker> > spill_list;
void list_spill(cellwalker tgt, cellwalker src, celllister& cl) {
void list_spill(cellwalker tgt, cellwalker src, manual_celllister& cl) {
spill_list.clear(); sval++;
spill_list.emplace_back(tgt, src);
int crad = 0, nextstepat = 0;
@ -668,7 +668,7 @@ namespace mapeditor {
}
#endif
void editAt(cellwalker where, celllister& cl) {
void editAt(cellwalker where, manual_celllister& cl) {
if(painttype == 4 && radius) {
if(where.c->type != copysource.c->type) return;
@ -685,7 +685,7 @@ namespace mapeditor {
void allInPattern(cellwalker where) {
celllister cl(manual);
manual_celllister cl;
if(!patterns::whichPattern) {
editAt(where, cl);
return;

View File

@ -242,7 +242,7 @@ int getSeepcount() {
}
bool canReachPlayer(cell *cf, eMonster m) {
celllister cl(manual);
manual_celllister cl;
cl.add(cf);
for(int i=0; i<isize(cl.lst) && i < 10000; i++) {
cell *c = cl.lst[i];

View File

@ -247,7 +247,7 @@ bool distanceBound(cell *c1, cell *c2, int d) {
}
void checkFreedom(cell *cf) {
celllister cl(manual);
manual_celllister cl;
cl.add(cf);
for(int i=0; i<isize(cl.lst); i++) {
cell *c = cl.lst[i];

View File

@ -1011,7 +1011,7 @@ namespace peace {
clister.emplace_back(cp, cp);
int id = 0;
celllister cl(manual);
manual_celllister cl;
while(id < isize(clister)) {
cell *c = clister[id].first;
cell *fr = clister[id].second;