Some changes to soap.

This commit is contained in:
savask 2011-04-21 09:19:44 +07:00 committed by Simon Robertshaw
parent 5aefd0cb01
commit 3ea306cc77
3 changed files with 99 additions and 48 deletions

View File

@ -1,25 +1,70 @@
#include <element.h> #include <element.h>
int update_SOAP(UPDATE_FUNC_ARGS) { void detach(int i)
int r, rx, ry, wc; {
if ((parts[i].ctype&2) == 2)
{
if ((parts[parts[i].tmp].ctype&4) == 4)
parts[parts[i].tmp].ctype ^= 4;
}
wc = -1; if ((parts[i].ctype&4) == 4)
{
if ((parts[parts[i].tmp2].ctype&2) == 2)
parts[parts[i].tmp2].ctype ^= 2;
}
parts[i].ctype = 0;
}
int update_SOAP(UPDATE_FUNC_ARGS)
{
int r, rx, ry;
//0x01 - bubble on/off //0x01 - bubble on/off
//0x02 - first mate yes/no //0x02 - first mate yes/no
//0x04 - second mate yes/no //0x04 - "back" mate yes/no
if (pv[y/CELL][x/CELL]>0.5f) if ((parts[i].ctype&1) == 1)
parts[i].ctype |= 0x01;
if (parts[i].ctype&0x01 == 0x01)
{ {
if (parts[i].life<=0)
{
if ((parts[i].ctype&6) == 0)
parts[i].ctype = 0;
if ((parts[i].ctype&6) != 6 && parts[i].ctype>1)
{
int target;
target = i;
while((parts[target].ctype&6) != 6 && parts[target].ctype>1)
{
if ((parts[target].ctype&2) == 2)
{
target = parts[target].tmp;
detach(target);
}
if ((parts[target].ctype&4) == 4)
{
target = parts[target].tmp2;
detach(target);
}
}
}
if ((parts[i].ctype&6) == 6 && (parts[parts[i].tmp].ctype&6) == 6 && parts[parts[i].tmp].tmp == i)
detach(i);
}
parts[i].vy -= 0.1f; parts[i].vy -= 0.1f;
parts[i].vy *= 0.5f; parts[i].vy *= 0.5f;
parts[i].vx *= 0.5f; parts[i].vx *= 0.5f;
if(parts[i].ctype&0x02 != 0x02) if((parts[i].ctype&2) != 2)
{ {
for (rx=-2; rx<3; rx++) for (rx=-2; rx<3; rx++)
for (ry=-2; ry<3; ry++) for (ry=-2; ry<3; ry++)
@ -29,33 +74,39 @@ int update_SOAP(UPDATE_FUNC_ARGS) {
if ((r>>8)>=NPART || !r) if ((r>>8)>=NPART || !r)
continue; continue;
if ((parts[r>>8].type == PT_SOAP) && (parts[r>>8].ctype&0x01==0x01) if ((r&0xFF) != PT_SOAP || (parts[r>>8].ctype == 0 && (r&0xFF) == PT_SOAP))
&& (parts[r>>8].ctype&0x04!=0x04))
{ {
if (parts[r>>8].ctype&0x02 == 0x02) detach(i);
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[i].tmp = r>>8;
parts[r>>8].tmp2 = i; parts[r>>8].tmp2 = i;
parts[i].ctype |= 0x02; parts[i].ctype |= 2;
parts[r>>8].ctype |= 0x04; parts[r>>8].ctype |= 4;
} }
else else
{ {
if (parts[i].ctype&0x02!=0x02) if ((parts[i].ctype&2) != 2)
{ {
parts[i].tmp = r>>8; parts[i].tmp = r>>8;
parts[r>>8].tmp2 = i; parts[r>>8].tmp2 = i;
parts[i].ctype |= 0x02; parts[i].ctype |= 2;
parts[r>>8].ctype |= 0x04; parts[r>>8].ctype |= 4;
}
}
} }
} }
} }
} if((parts[i].ctype&2) == 2)
}
else
{ {
float d, dx, dy; float d, dx, dy;
@ -64,43 +115,38 @@ int update_SOAP(UPDATE_FUNC_ARGS) {
d = 9/(pow(dx, 2)+pow(dy, 2)+9)-0.5; d = 9/(pow(dx, 2)+pow(dy, 2)+9)-0.5;
parts[parts[i].tmp].x -= dx*d; parts[parts[i].tmp].vx -= dx*d;
parts[parts[i].tmp].y -= dy*d; parts[parts[i].tmp].vy -= dy*d;
parts[i].x += dx*d; parts[i].vx += dx*d;
parts[i].y += dy*d; parts[i].vy += dy*d;
if ((parts[parts[i].tmp].ctype&0x02 == 0x02) && (parts[parts[i].tmp].ctype&0x01 == 0x01)) 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))
{ {
float d, dx, dy;
int ii; int ii;
ii = parts[parts[i].tmp].tmp; ii = parts[parts[parts[i].tmp].tmp].tmp;
dx = parts[ii].x - parts[parts[i].tmp].x; dx = parts[ii].x - parts[parts[i].tmp].x;
dy = parts[ii].y - parts[parts[i].tmp].y; dy = parts[ii].y - parts[parts[i].tmp].y;
d = 36/(pow(dx, 2)+pow(dy, 2)+36)-0.5; d = 81/(pow(dx, 2)+pow(dy, 2)+81)-0.5;
parts[parts[i].tmp].x -= dx*d*0.5f; parts[parts[i].tmp].vx -= dx*d*0.5f;
parts[parts[i].tmp].y -= dy*d*0.5f; parts[parts[i].tmp].vy -= dy*d*0.5f;
parts[ii].x += dx*d*0.5f; parts[ii].vx += dx*d*0.5f;
parts[ii].y += dy*d*0.5f; parts[ii].vy += dy*d*0.5f;
} }
} }
} }
else else
{ {
for (rx=-2; rx<3; rx++) if (pv[y/CELL][x/CELL]>0.5f || pv[y/CELL][x/CELL]<(-0.5f))
for (ry=-2; ry<3; ry++)
if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{ {
r = pmap[y+ry][x+rx]; parts[i].ctype = 1;
if ((r>>8)>=NPART || !r) parts[i].life = 5;
continue;
} }
} }

View File

@ -1498,8 +1498,8 @@ void draw_parts(pixel *vid)
if (t==PT_SOAP) if (t==PT_SOAP)
{ {
//if ((parts[i].ctype&0x01 == 0x01) && (parts[i].ctype&0x02 == 0x02)) if (((parts[i].ctype&1) == 1) && ((parts[i].ctype&2) == 2))
// 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), 245, 245, 220, XRES+BARSIZE);
} }
if (cmode!=CM_HEAT) if (cmode!=CM_HEAT)

View File

@ -464,11 +464,11 @@ void kill_part(int i)//kills particle number i
} }
if (parts[i].type == PT_SOAP) if (parts[i].type == PT_SOAP)
{ {
if (parts[i].ctype&0x02 == 0x02) if ((parts[i].ctype&2) == 2)
parts[parts[i].tmp].ctype ^= 0x04; parts[parts[i].tmp].ctype ^= 4;
if (parts[i].ctype&0x04 == 0x04) if ((parts[i].ctype&4) == 4)
parts[parts[i].tmp2].ctype ^= 0x02; parts[parts[i].tmp2].ctype ^= 2;
} }
if (x>=0 && y>=0 && x<XRES && y<YRES) { if (x>=0 && y>=0 && x<XRES && y<YRES) {
if ((pmap[y][x]>>8)==i) if ((pmap[y][x]>>8)==i)
@ -648,6 +648,11 @@ inline int create_part(int p, int x, int y, int t)//the function for creating a
parts[i].tmp = 0; parts[i].tmp = 0;
parts[i].tmp2 = 0; parts[i].tmp2 = 0;
} }
if (t==PT_SOAP)
{
parts[i].tmp = -1;
parts[i].tmp2 = -1;
}
//now set various properties that we want at spawn. //now set various properties that we want at spawn.
if (t==PT_ACID) if (t==PT_ACID)
{ {
@ -1353,7 +1358,7 @@ void update_particles_i(pixel *vid, int start, int inc)
if (!(parts[i].life==10&&(t==PT_SWCH||t==PT_LCRY||t==PT_PCLN||t==PT_HSWC||t==PT_PUMP))) if (!(parts[i].life==10&&(t==PT_SWCH||t==PT_LCRY||t==PT_PCLN||t==PT_HSWC||t==PT_PUMP)))
parts[i].life--; parts[i].life--;
//this if is for stopping death when life hits 0 //this if is for stopping death when life hits 0
if (parts[i].life<=0 && !(ptypes[t].properties&PROP_CONDUCTS) && t!=PT_ARAY && t!=PT_FIRW && t!=PT_SWCH && t!=PT_PCLN && t!=PT_HSWC && t!=PT_PUMP && t!=PT_SPRK && t!=PT_LAVA && t!=PT_LCRY && t!=PT_QRTZ && t!=PT_GLOW && t!= PT_FOG && t!=PT_PIPE && t!=PT_FRZW &&!(t==PT_ICEI&&parts[i].ctype==PT_FRZW)&&t!=PT_INST && t!=PT_SHLD1&& t!=PT_SHLD2&& t!=PT_SHLD3&& t!=PT_SHLD4 && t!=PT_SING) if (parts[i].life<=0 && !(ptypes[t].properties&PROP_CONDUCTS) && t!=PT_SOAP && t!=PT_ARAY && t!=PT_FIRW && t!=PT_SWCH && t!=PT_PCLN && t!=PT_HSWC && t!=PT_PUMP && t!=PT_SPRK && t!=PT_LAVA && t!=PT_LCRY && t!=PT_QRTZ && t!=PT_GLOW && t!= PT_FOG && t!=PT_PIPE && t!=PT_FRZW &&!(t==PT_ICEI&&parts[i].ctype==PT_FRZW)&&t!=PT_INST && t!=PT_SHLD1&& t!=PT_SHLD2&& t!=PT_SHLD3&& t!=PT_SHLD4 && t!=PT_SING)
{ {
kill_part(i); kill_part(i);
continue; continue;