diff --git a/src/elements/soap.c b/src/elements/soap.c index c8b5078df..6b69778de 100644 --- a/src/elements/soap.c +++ b/src/elements/soap.c @@ -15,6 +15,27 @@ #include +void attach(int i1, int i2) +{ + if (!(parts[i2].ctype&4)) + { + parts[i1].ctype |= 2; + parts[i1].tmp = i2; + + parts[i2].ctype |= 4; + parts[i2].tmp2 = i1; + } + else + if (!(parts[i2].ctype&2)) + { + parts[i1].ctype |= 4; + parts[i1].tmp2= i2; + + parts[i2].ctype |= 2; + parts[i2].tmp = i1; + } +} + int update_SOAP(UPDATE_FUNC_ARGS) { int r, rx, ry, nr, ng, nb, na; @@ -25,7 +46,7 @@ int update_SOAP(UPDATE_FUNC_ARGS) //0x02 - first mate yes/no //0x04 - "back" mate yes/no - if ((parts[i].ctype&1) == 1) + if (parts[i].ctype&1) { if (parts[i].temp>0) { @@ -39,13 +60,13 @@ int update_SOAP(UPDATE_FUNC_ARGS) while((parts[target].ctype&6) != 6 && (parts[target].ctype&6)) { - if ((parts[target].ctype&2) == 2) + if (parts[target].ctype&2) { target = parts[target].tmp; detach(target); } - if ((parts[target].ctype&4) == 4) + if (parts[target].ctype&4) { target = parts[target].tmp2; detach(target); @@ -66,7 +87,7 @@ int update_SOAP(UPDATE_FUNC_ARGS) parts[i].vx *= 0.5f; } - if((parts[i].ctype&2) != 2) + if (!(parts[i].ctype&2)) { for (rx=-2; rx<3; rx++) for (ry=-2; ry<3; ry++) @@ -76,29 +97,8 @@ int update_SOAP(UPDATE_FUNC_ARGS) if (!r) continue; - if ((parts[r>>8].type == PT_SOAP) && ((parts[r>>8].ctype&1) == 1) - && ((parts[r>>8].ctype&4) != 4)) - { - if ((parts[r>>8].ctype&2) == 2) - { - parts[i].tmp = r>>8; - parts[r>>8].tmp2 = i; - - parts[i].ctype |= 2; - parts[r>>8].ctype |= 4; - } - else - { - if ((parts[i].ctype&2) != 2) - { - parts[i].tmp = r>>8; - parts[r>>8].tmp2 = i; - - parts[i].ctype |= 2; - parts[r>>8].ctype |= 4; - } - } - } + if ((parts[r>>8].type == PT_SOAP) && (parts[r>>8].ctype&1) && !(parts[r>>8].ctype&4)) + attach(i, r>>8); } } else @@ -116,9 +116,7 @@ int update_SOAP(UPDATE_FUNC_ARGS) { if (bmap[(y+ry)/CELL][(x+rx)/CELL] || (r && ptypes[r&0xFF].state != ST_GAS - && (r&0xFF) != PT_SOAP && (r&0xFF) != PT_GLAS) - || (parts[r>>8].ctype == 0 && (r&0xFF) == PT_SOAP - && (abs(parts[r>>8].vx)<2 || abs(parts[r>>8].vy)<2))) + && (r&0xFF) != PT_SOAP && (r&0xFF) != PT_GLAS)) { detach(i); continue; @@ -150,7 +148,7 @@ int update_SOAP(UPDATE_FUNC_ARGS) } } - if((parts[i].ctype&2) == 2) + if(parts[i].ctype&2) { float d, dx, dy; @@ -165,8 +163,8 @@ int update_SOAP(UPDATE_FUNC_ARGS) parts[i].vx += dx*d; parts[i].vy += dy*d; - if (((parts[parts[i].tmp].ctype&2) == 2) && ((parts[parts[i].tmp].ctype&1) == 1) - && ((parts[parts[parts[i].tmp].tmp].ctype&2) == 2) && ((parts[parts[parts[i].tmp].tmp].ctype&1) == 1)) + if ((parts[parts[i].tmp].ctype&2) && (parts[parts[i].tmp].ctype&1) + && (parts[parts[parts[i].tmp].tmp].ctype&2) && (parts[parts[parts[i].tmp].tmp].ctype&1)) { int ii; diff --git a/src/graphics.c b/src/graphics.c index c7611ff6f..8992ea839 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -2010,7 +2010,7 @@ void render_parts(pixel *vid) if (t==PT_SOAP) { if ((parts[i].ctype&7) == 7) - draw_line(vid, nx, ny, (int)(parts[parts[i].tmp].x+0.5f), (int)(parts[parts[i].tmp].y+0.5f), 245, 245, 220, XRES+BARSIZE); + draw_line(vid, nx, ny, (int)(parts[parts[i].tmp].x+0.5f), (int)(parts[parts[i].tmp].y+0.5f), colr, colg, colb, XRES+BARSIZE); } if(pixel_mode & PSPEC_STICKMAN) {