more efficient gate toggling algorithm

This commit is contained in:
Zeno Rogue 2018-04-12 11:00:12 +02:00
parent 2dfc12799d
commit e6a5c41c9b
1 changed files with 19 additions and 18 deletions

View File

@ -3136,27 +3136,28 @@ bool makeEmpty(cell *c) {
int numgates = 0;
void toggleGates(cell *ct, eWall type, int rad) {
if(!ct) return;
if(ct->wall == waOpenGate && type == waClosePlate) {
bool onWorm = false;
if(isWorm(ct)) onWorm = true;
for(int i=0; i<ct->type; i++)
if(ct->mov[i] && ct->mov[i]->wall == waOpenGate && isWorm(ct->mov[i])) onWorm = true;
if(!onWorm) {
ct->wall = waClosedGate, numgates++;
if(rad<1) rad=1;
if(ct->item) {
playSound(ct, "hit-crush"+pick123());
addMessage(XLAT("%The1 is crushed!", ct->item));
ct->item = itNone;
void toggleGates(cell *c, eWall type, int rad) {
if(!c) return;
celllister cl(c, rad, 1000000, NULL);
for(cell *ct: cl.lst) {
if(ct->wall == waOpenGate && type == waClosePlate) {
bool onWorm = false;
if(isWorm(ct)) onWorm = true;
for(int i=0; i<ct->type; i++)
if(ct->mov[i] && ct->mov[i]->wall == waOpenGate && isWorm(ct->mov[i])) onWorm = true;
if(!onWorm) {
ct->wall = waClosedGate, numgates++;
if(rad<1) rad=1;
if(ct->item) {
playSound(ct, "hit-crush"+pick123());
addMessage(XLAT("%The1 is crushed!", ct->item));
ct->item = itNone;
}
}
}
if(ct->wall == waClosedGate && type == waOpenPlate)
ct->wall = waOpenGate, rad = 1, numgates++;
}
if(ct->wall == waClosedGate && type == waOpenPlate)
ct->wall = waOpenGate, rad = 1, numgates++;
if(rad) for(int i=0; i<ct->type; i++)
toggleGates(ct->mov[i], type, rad-1);
}
void toggleGates(cell *ct, eWall type) {