summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2011-10-25 10:31:21 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-10-25 10:31:21 (GMT)
commit07a1f21df484a252d54c82262ade6d4117425694 (patch)
tree80df86661553807159f7fda3fbf2506d5df3b5fa /src
parentf01056ee0249ad01ed24824aea39f05083110cd6 (diff)
parentf8d54e66dba5d8448d30f61f84883b4e7e6e1087 (diff)
downloadpowder-07a1f21df484a252d54c82262ade6d4117425694.zip
powder-07a1f21df484a252d54c82262ade6d4117425694.tar.gz
Merge latest with graphicstest
Diffstat (limited to 'src')
-rw-r--r--src/elements/dest.c66
-rw-r--r--src/elements/emp.c125
-rw-r--r--src/elements/ligh.c295
-rw-r--r--src/elements/sprk.c38
-rw-r--r--src/elements/stkm.c69
-rw-r--r--src/graphics.c50
-rw-r--r--src/interface.c48
-rw-r--r--src/luaconsole.c25
-rw-r--r--src/main.c79
-rw-r--r--src/misc.c6
-rw-r--r--src/powder.c128
11 files changed, 840 insertions, 89 deletions
diff --git a/src/elements/dest.c b/src/elements/dest.c
new file mode 100644
index 0000000..a315b09
--- /dev/null
+++ b/src/elements/dest.c
@@ -0,0 +1,66 @@
+#include <element.h>
+
+int update_DEST(UPDATE_FUNC_ARGS) {
+ int r,rx,ry,topv;
+ rx=rand()%5-2;
+ ry=rand()%5-2;
+
+ r = pmap[y+ry][x+rx];
+ if (!r || (r&0xFF)==PT_DEST || (r&0xFF)==PT_DMND)
+ return 0;
+
+ if (parts[i].life<=0 || parts[i].life>37)
+ {
+ parts[i].life=30+rand()%20;
+ parts[i].temp+=20000;
+ pv[y/CELL][x/CELL]+=60.0f;
+ }
+ parts[i].temp+=10000;
+ if ((r&0xFF)==PT_PLUT || (r&0xFF)==PT_DEUT)
+ {
+ pv[y/CELL][x/CELL]+=20.0f;
+ parts[i].temp+=18000;
+ if (rand()%2==0)
+ {
+ float orig_temp = parts[r>>8].temp;
+ create_part(r>>8, x+rx, y+ry, PT_NEUT);
+ parts[r>>8].temp = restrict_flt(orig_temp+40000.0f, MIN_TEMP, MAX_TEMP);
+ pv[y/CELL][x/CELL] += 10.0f;
+ parts[i].life-=4;
+ }
+ }
+ else if ((r&0xFF)==PT_INSL)
+ {
+ create_part(r>>8, x+rx, y+ry, PT_PLSM);
+ }
+ else if (rand()%3==0)
+ {
+ kill_part(r>>8);
+ parts[i].life -= 4*((ptypes[r&0xFF].properties&TYPE_SOLID)?3:1);
+ if (parts[i].life<=0)
+ parts[i].life=1;
+ parts[i].temp+=10000;
+ }
+ else
+ {
+ if (ptypes[r&0xFF].hconduct) parts[r>>8].temp = restrict_flt(parts[r>>8].temp+10000.0f, MIN_TEMP, MAX_TEMP);
+ }
+ topv=pv[y/CELL][x/CELL]/9+parts[r>>8].temp/900;
+ if (topv>40.0f)
+ topv=40.0f;
+ pv[y/CELL][x/CELL]+=40.0f+topv;
+ parts[i].temp = restrict_flt(parts[i].temp, MIN_TEMP, MAX_TEMP);
+ return 0;
+}
+int graphics_DEST(GRAPHICS_FUNC_ARGS)
+{
+ if(cpart->life)
+ {
+ *pixel_mode |= PMODE_LFLARE;
+ }
+ else
+ {
+ *pixel_mode |= PMODE_SPARK;
+ }
+ return 0;
+}
diff --git a/src/elements/emp.c b/src/elements/emp.c
new file mode 100644
index 0000000..201b8e4
--- /dev/null
+++ b/src/elements/emp.c
@@ -0,0 +1,125 @@
+#include <element.h>
+
+int update_EMP(UPDATE_FUNC_ARGS) {
+ int r,rx,ry,ok=0,t,n,nx,ny;
+ if (parts[i].life)
+ return 0;
+ for (rx=-2; rx<3; rx++)
+ 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];
+ if (!r)
+ continue;
+ if ((r&0xFF)==PT_SPRK)
+ {
+ ok=1;
+ break;
+ }
+ }
+ if (!ok)
+ return 0;
+ parts[i].life=220;
+ emp_decor+=3;
+ if (emp_decor>40)
+ emp_decor=40;
+ for (r=0; r<=parts_lastActiveIndex; r++)
+ {
+ t=parts[r].type;
+ rx=parts[r].x;
+ ry=parts[r].y;
+ if (t==PT_SPRK || (t==PT_SWCH && parts[r].life!=0 && parts[r].life!=10) || (t==PT_WIRE && parts[r].ctype>0))
+ {
+ int is_elec=0;
+ if ((parts[r].ctype==PT_PSCN || parts[r].ctype==PT_NSCN || parts[r].ctype==PT_PTCT ||
+ parts[r].ctype==PT_NTCT || parts[r].ctype==PT_INST || parts[r].ctype==PT_SWCH) || t==PT_WIRE || t==PT_SWCH)
+ {
+ is_elec=1;
+ if (ptypes[parts[r].type].hconduct && rand()%100==0)
+ parts[r].temp = restrict_flt(parts[r].temp+3000.0f, MIN_TEMP, MAX_TEMP);
+ if (rand()%80==0)
+ part_change_type(r, rx, ry, PT_BREC);
+ else if (rand()%120==0)
+ part_change_type(r, rx, ry, PT_NTCT);
+ }
+
+ for (nx=-2; nx<3; nx++)
+ for (ny=-2; ny<3; ny++)
+ if (rx+nx>=0 && ry+ny>=0 && rx+nx<XRES && ry+ny<YRES && (rx || ry))
+ {
+ n = pmap[ry+ny][rx+nx];
+ if (!n)
+ continue;
+ /*if ((n&0xFF)==PT_BTRY && rand()%60==0)
+ {
+ part_change_type(n>>8, rx+nx, ry+ny, PT_PLSM);
+ parts[n>>8].life=rand()%100+70;
+ parts[n>>8].temp+=3000;
+ }*/
+
+ //Some elements should only be affected by wire/swch, or by a spark on inst/semiconductor
+ //So not affected by spark on metl, watr etc
+ if (is_elec)
+ {
+ if (((n&0xFF)==PT_METL || (n&0xFF)==PT_BMTL) && rand()%280==0)
+ {
+ parts[n>>8].temp = restrict_flt(parts[n>>8].temp+3000.0f, MIN_TEMP, MAX_TEMP);
+ }
+ if ((n&0xFF)==PT_BMTL && rand()%160==0)
+ {
+ part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL);//TODO: Redundant, was this meant to be BRMT or something?
+ parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
+ }
+ if ((n&0xFF)==PT_METL && rand()%300==0)
+ {
+ part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL);
+ }
+ if ((n&0xFF)==PT_WIFI && rand()%8==0)
+ {
+ //Randomise channel
+ parts[n>>8].temp = rand()%MAX_TEMP;
+ }
+ if ((n&0xFF)==PT_WIFI && rand()%16==0)
+ {
+ create_part(n>>8, rx+nx, ry+ny, PT_BREC);
+ parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
+ }
+ }
+ if ((n&0xFF)==PT_SWCH && rand()%100==0)
+ {
+ part_change_type(n>>8, rx+nx, ry+ny, PT_BREC);
+ }
+ if ((n&0xFF)==PT_SWCH && rand()%100==0)
+ {
+ parts[n>>8].temp = restrict_flt(parts[n>>8].temp+2000.0f, MIN_TEMP, MAX_TEMP);
+ }
+ if ((n&0xFF)==PT_ARAY && rand()%60==0)
+ {
+ create_part(n>>8, rx+nx, ry+ny, PT_BREC);
+ parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
+ }
+ if (t==PT_DLAY && rand()%70==0)
+ {
+ //Randomise delay
+ parts[n>>8].temp = (rand()%256) + 273.15f;
+ }
+ }
+ }
+ }
+ return 0;
+}
+int graphics_EMP(GRAPHICS_FUNC_ARGS)
+{
+ *colr = cpart->life*1.5;
+ *colg = cpart->life*1.5;
+ *colb = 200-cpart->life;
+ if (*colr>255)
+ *colr = 255;
+ if (*colg>255)
+ *colg = 255;
+ if (*colb>255)
+ *colb = 255;
+ if (*colb<=0)
+ *colb = 0;
+ return 0;
+}
diff --git a/src/elements/ligh.c b/src/elements/ligh.c
new file mode 100644
index 0000000..ea4e5ca
--- /dev/null
+++ b/src/elements/ligh.c
@@ -0,0 +1,295 @@
+#include <element.h>
+
+#define LIGHTING_POWER 0.65
+
+int LIGH_nearest_part(int ci, int max_d)
+{
+ int distance = (max_d!=-1)?max_d:MAX_DISTANCE;
+ int ndistance = 0;
+ int id = -1;
+ int i = 0;
+ int cx = (int)parts[ci].x;
+ int cy = (int)parts[ci].y;
+ for (i=0; i<=parts_lastActiveIndex; i++)
+ {
+ if (parts[i].type && !parts[i].life && i!=ci && parts[i].type!=PT_LIGH && parts[i].type!=PT_THDR && parts[i].type!=PT_NEUT && parts[i].type!=PT_PHOT)
+ {
+ ndistance = abs(cx-parts[i].x)+abs(cy-parts[i].y);// Faster but less accurate Older: sqrt(pow(cx-parts[i].x, 2)+pow(cy-parts[i].y, 2));
+ if (ndistance<distance)
+ {
+ distance = ndistance;
+ id = i;
+ }
+ }
+ }
+ return id;
+}
+
+int contact_part(int i, int tp)
+{
+ int x=parts[i].x, y=parts[i].y;
+ int r,rx,ry;
+ for (rx=-2; rx<3; rx++)
+ 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];
+ if (!r)
+ continue;
+ if ((r&0xFF)==tp)
+ return r>>8;
+ }
+ return -1;
+}
+
+void create_line_par(int x1, int y1, int x2, int y2, int c, int temp, int life, int tmp, int tmp2)
+{
+ int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
+ float e, de;
+ if (c==WL_EHOLE || c==WL_ALLOWGAS || c==WL_ALLOWALLELEC || c==WL_ALLOWSOLID || c==WL_ALLOWAIR || c==WL_WALL || c==WL_DESTROYALL || c==WL_ALLOWLIQUID || c==WL_FAN || c==WL_STREAM || c==WL_DETECT || c==WL_EWALL || c==WL_WALLELEC)
+ return; // this function only for particles, no walls
+ if (cp)
+ {
+ y = x1;
+ x1 = y1;
+ y1 = y;
+ y = x2;
+ x2 = y2;
+ y2 = y;
+ }
+ if (x1 > x2)
+ {
+ y = x1;
+ x1 = x2;
+ x2 = y;
+ y = y1;
+ y1 = y2;
+ y2 = y;
+ }
+ dx = x2 - x1;
+ dy = abs(y2 - y1);
+ e = 0.0f;
+ if (dx)
+ de = dy/(float)dx;
+ else
+ de = 0.0f;
+ y = y1;
+ sy = (y1<y2) ? 1 : -1;
+ for (x=x1; x<=x2; x++)
+ {
+ int p;
+ if (cp)
+ p=create_part(-1, y, x, c);
+ else
+ p=create_part(-1, x, y,c);
+ if (p!=-1)
+ {
+ parts[p].life=life;
+ parts[p].temp=temp;
+ parts[p].tmp=tmp;
+ parts[p].tmp2=tmp2;
+ }
+ e += de;
+ if (e >= 0.5f)
+ {
+ y += sy;
+ e -= 1.0f;
+ }
+ }
+}
+
+int update_LIGH(UPDATE_FUNC_ARGS)
+{
+ /*
+ *
+ * tmp2:
+ * -1 - part will be removed
+ * 0 - "branches" of the lightning
+ * 1 - bending
+ * 2 - branching
+ * 3 - transfer spark or make destruction
+ * 4 - first pixel
+ *
+ * life - "thickness" of lighting (but anyway one pixel)
+ *
+ * tmp - angle of lighting
+ *
+ */
+ int r,rx,ry, multipler, powderful;
+ float angle, angle2=-1;
+ int near;
+ powderful = powderful=parts[i].temp*(1+parts[i].life/40)*LIGHTING_POWER;
+ update_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
+ if (aheat_enable)
+ {
+ hv[y/CELL][x/CELL]+=powderful/50;
+ if (hv[y/CELL][x/CELL]>MAX_TEMP)
+ hv[y/CELL][x/CELL]=MAX_TEMP;
+ }
+
+ for (rx=-2; rx<3; rx++)
+ 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];
+ if (!r)
+ continue;
+ if ((r&0xFF)!=PT_LIGH && (r&0xFF)!=PT_TESC)
+ {
+ if ((r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_THDR&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_FIRE&&(r&0xFF)!=PT_NEUT&&(r&0xFF)!=PT_PHOT)
+ {
+ if ((ptypes[r&0xFF].properties&PROP_CONDUCTS) && parts[r>>8].life==0)
+ {
+ create_part(r>>8,x+rx,y+ry,PT_SPRK);
+ }
+ pv[y/CELL][x/CELL] += powderful/400;
+ if (ptypes[r&0xFF].hconduct) parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful/1.5, MIN_TEMP, MAX_TEMP);
+ }
+ if ((r&0xFF)==PT_DEUT || (r&0xFF)==PT_PLUT) // start nuclear reactions
+ {
+ parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful, MIN_TEMP, MAX_TEMP);
+ pv[y/CELL][x/CELL] +=powderful/35;
+ if (rand()%3==0)
+ {
+ part_change_type(r>>8,x+rx,y+ry,PT_NEUT);
+ parts[r>>8].life = rand()%480+480;
+ parts[r>>8].vx=rand()%10-5;
+ parts[r>>8].vy=rand()%10-5;
+ }
+ }
+ if ((r&0xFF)==PT_COAL || (r&0xFF)==PT_BCOL) // ignite coal
+ {
+ if (parts[r>>8].life>100) {
+ parts[r>>8].life = 99;
+ }
+ }
+ if (ptypes[r&0xFF].hconduct)
+ parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful/10, MIN_TEMP, MAX_TEMP);
+ if (((r&0xFF)==PT_STKM && player[2]!=PT_LIGH) || ((r&0xFF)==PT_STKM2 && player2[2]!=PT_LIGH))
+ {
+ parts[r>>8].life-=powderful/100;
+ }
+ }
+ }
+ if (parts[i].tmp2==3)
+ {
+ parts[i].tmp2=0;
+ return 1;
+ }
+
+ if (parts[i].tmp2==-1)
+ {
+ kill_part(i);
+ return 1;
+ }
+ if (parts[i].tmp2<=0 || parts[i].life<=1)
+ {
+ if (parts[i].tmp2>0)
+ parts[i].tmp2=0;
+ parts[i].tmp2--;
+ return 1;
+ }
+ if (parts[i].tmp2<=-2)
+ {
+ kill_part(i);
+ return 1;
+ }
+
+ angle2=-1;
+
+ near = LIGH_nearest_part(i, parts[i].life*2.5);
+ if (near!=-1)
+ {
+ int t=parts[near].type;
+ float n_angle; // angle to nearest part
+ rx=parts[near].x-x;
+ ry=parts[near].y-y;
+ if (rx*rx+ry*ry!=0)
+ n_angle = asin(-ry/sqrt(rx*rx+ry*ry));
+ else
+ n_angle = 0;
+ if (n_angle<0)
+ n_angle+=M_PI*2;
+ if (parts[i].life<5 || fabs(n_angle-parts[i].tmp*M_PI/180)<M_PI*0.8) // lightning strike
+ {
+ create_line_par(x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, parts[i].tmp-90, 0);
+
+ if (t!=PT_TESC)
+ {
+ near=contact_part(near, PT_LIGH);
+ if (near!=-1)
+ {
+ parts[near].tmp2=3;
+ parts[near].life=(int)(1.0*parts[i].life/2-1);
+ parts[near].tmp=parts[i].tmp-180;
+ parts[near].temp=parts[i].temp;
+ }
+ }
+ }
+ else near=-1;
+ }
+
+ //if (parts[i].tmp2==1/* || near!=-1*/)
+ //angle=0;//parts[i].tmp-30+rand()%60;
+ angle = parts[i].tmp-30+rand()%60;
+ if (angle<0)
+ angle+=360;
+ if (angle>=360)
+ angle-=360;
+ if (parts[i].tmp2==2 && near==-1)
+ {
+ angle2=angle+100-rand()%200;
+ if (angle2<0)
+ angle2+=360;
+ if (angle2>=360)
+ angle-=360;
+ }
+
+ multipler=parts[i].life*1.5+rand()%((int)(parts[i].life+1));
+ rx=cos(angle*M_PI/180)*multipler;
+ ry=-sin(angle*M_PI/180)*multipler;
+ create_line_par(x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle, 0);
+
+ if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r&0xFF)==PT_LIGH)
+ {
+ parts[r>>8].tmp2=1+(rand()%200>parts[i].tmp2*parts[i].tmp2/10+60);
+ parts[r>>8].life=(int)(1.0*parts[i].life/1.5-rand()%2);
+ parts[r>>8].tmp=angle;
+ parts[r>>8].temp=parts[i].temp;
+ }
+ }
+
+ if (angle2!=-1)
+ {
+ multipler=parts[i].life*1.5+rand()%((int)(parts[i].life+1));
+ rx=cos(angle2*M_PI/180)*multipler;
+ ry=-sin(angle2*M_PI/180)*multipler;
+ create_line_par(x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle2, 0);
+
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r&0xFF)==PT_LIGH)
+ {
+ parts[r>>8].tmp2=1+(rand()%200>parts[i].tmp2*parts[i].tmp2/10+40);
+ parts[r>>8].life=(int)(1.0*parts[i].life/1.5-rand()%2);
+ parts[r>>8].tmp=angle;
+ parts[r>>8].temp=parts[i].temp;
+ }
+ }
+ }
+
+ parts[i].tmp2=-1;
+ return 1;
+}
+int graphics_LIGH(GRAPHICS_FUNC_ARGS)
+{
+ *colr = 235;
+ *colg = 245;
+ *colb = 255;
+ *pixel_mode |= PMODE_GLOW;
+ return 1;
+}
diff --git a/src/elements/sprk.c b/src/elements/sprk.c
index 2385e26..fdbdb2d 100644
--- a/src/elements/sprk.c
+++ b/src/elements/sprk.c
@@ -32,7 +32,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
}
else if (ct==PT_ETRD&&parts[i].life==1)
{
- nearp = nearest_part(i, PT_ETRD);
+ nearp = nearest_part(i, PT_ETRD, -1);
if (nearp!=-1&&parts_avg(i, nearp, PT_INSL)!=PT_INSL)
{
create_line(x, y, (int)(parts[nearp].x+0.5f), (int)(parts[nearp].y+0.5f), 0, 0, PT_PLSM, 0);
@@ -52,6 +52,42 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
parts[i].temp = 3500;
pv[y/CELL][x/CELL] += 1;
}
+ else if (ct==PT_TESC) // tesla coil code
+ {
+ if (parts[i].tmp>300)
+ parts[i].tmp=300;
+ for (rx=-1; rx<2; rx++)
+ for (ry=-1; ry<2; ry++)
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ {
+ r = pmap[y+ry][x+rx];
+ if (r)
+ continue;
+ if (rand()%(parts[i].tmp*parts[i].tmp/20+6)==0)
+ {
+ int p=create_part(-1, x+rx*2, y+ry*2, PT_LIGH);
+ if (p!=-1)
+ {
+ if(parts[i].tmp<=4) //Prevent Arithmetic errors with zero values
+ continue;
+ parts[p].life=rand()%(2+parts[i].tmp/15)+parts[i].tmp/7;
+ if (parts[i].life>60)
+ parts[i].life=60;
+ parts[p].temp=parts[p].life*parts[i].tmp/2.5;
+ parts[p].tmp2=1;
+ parts[p].tmp=acos(1.0*rx/sqrt(rx*rx+ry*ry))/M_PI*360;
+ parts[i].temp-=parts[i].tmp*2+parts[i].temp/5; // slight self-cooling
+ if (fabs(pv[y/CELL][x/CELL])!=0.0f)
+ {
+ if (fabs(pv[y/CELL][x/CELL])<=0.5f)
+ pv[y/CELL][x/CELL]=0;
+ else
+ pv[y/CELL][x/CELL]-=(pv[y/CELL][x/CELL]>0)?0.5:-0.5;
+ }
+ }
+ }
+ }
+ }
else if (ct==PT_IRON) {
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
diff --git a/src/elements/stkm.c b/src/elements/stkm.c
index 752f167..261c493 100644
--- a/src/elements/stkm.c
+++ b/src/elements/stkm.c
@@ -36,8 +36,9 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) {
float gvx, gvy;
float gx, gy, dl, dr;
- if ((parts[i].ctype>0 && parts[i].ctype<PT_NUM && ptypes[parts[i].ctype].falldown>0) || parts[i].ctype==SPC_AIR || parts[i].ctype == PT_NEUT || parts[i].ctype == PT_PHOT)
+ if ((parts[i].ctype>0 && parts[i].ctype<PT_NUM && ptypes[parts[i].ctype].falldown>0) || parts[i].ctype==SPC_AIR || parts[i].ctype == PT_NEUT || parts[i].ctype == PT_PHOT || parts[i].ctype == PT_LIGH)
playerp[2] = parts[i].ctype;
+ playerp[28]++;
//Tempirature handling
if (parts[i].temp<243)
@@ -213,6 +214,8 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) {
{
playerp[2] = r&0xFF; //Current element
}
+ if ((r&0xFF)==PT_TESC || (r&0xFF)==PT_LIGH)
+ playerp[2] = PT_LIGH;
if ((r&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP
{
if (parts[i].life<=95)
@@ -245,24 +248,23 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) {
{
ry -= 2*(rand()%2)+1;
r = pmap[ry][rx];
- if (ptypes[r&0xFF].state == ST_SOLID)
- {
- create_part(-1, rx, ry, PT_SPRK);
- }
+ if (ptypes[r&0xFF].state == ST_SOLID)
+ {
+ create_part(-1, rx, ry, PT_SPRK);
+ playerp[28] = 0;
+ }
+ else
+ {
+ int np = -1;
+ if (playerp[2] == SPC_AIR)
+ create_parts(rx + 3*((((int)playerp[1])&0x02) == 0x02) - 3*((((int)playerp[1])&0x01) == 0x01), ry, 4, 4, SPC_AIR, 0);
+ else if (playerp[2]==PT_LIGH && playerp[28]<30)//limit lightning creation rate
+ np = -1;
else
+ np = create_part(-1, rx, ry, playerp[2]);
+ if ( (np < NPART) && np>=0)
{
- int np = -1;
- if (playerp[2] == SPC_AIR)
- create_parts(rx + 3*((((int)playerp[1])&0x02) == 0x02) - 3*((((int)playerp[1])&0x01) == 0x01), ry, 4, 4, SPC_AIR, 0);
- else
- np = create_part(-1, rx, ry, playerp[2]);
- if ( (np < NPART) && np>=0 && playerp[2] != PT_PHOT && playerp[2] != SPC_AIR)
- {
- parts[np].vx -= -gvy*(5*((((int)playerp[1])&0x02) == 0x02) - 5*(((int)(playerp[1])&0x01) == 0x01));
- parts[np].vy -= gvx*(5*((((int)playerp[1])&0x02) == 0x02) - 5*(((int)(playerp[1])&0x01) == 0x01));
- parts[i].vx -= (ptypes[(int)playerp[2]].weight*parts[np].vx)/1000;
- }
- if ((np < NPART) && np>=0 && playerp[2] == PT_PHOT)
+ if (playerp[2] == PT_PHOT)
{
int random = abs(rand()%3-1)*3;
if (random==0)
@@ -278,8 +280,35 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) {
parts[np].vx = random;
}
}
-
+ else if (playerp[2] == PT_LIGH)
+ {
+ float angle;
+ int power = 100;
+ if (gvx!=0 || gvy!=0)
+ angle = atan2(gvx, gvy)*180.0f/M_PI;
+ else
+ angle = rand()%360;
+ if (((int)playerp[1])&0x01)
+ angle += 180;
+ if (angle>360)
+ angle-=360;
+ if (angle<0)
+ angle+=360;
+ parts[np].tmp = angle;
+ parts[np].life=rand()%(2+power/15)+power/7;
+ parts[np].temp=parts[np].life*power/2.5;
+ parts[np].tmp2=1;
+ }
+ else if (playerp[2] != SPC_AIR)
+ {
+ parts[np].vx -= -gvy*(5*((((int)playerp[1])&0x02) == 0x02) - 5*(((int)(playerp[1])&0x01) == 0x01));
+ parts[np].vy -= gvx*(5*((((int)playerp[1])&0x02) == 0x02) - 5*(((int)(playerp[1])&0x01) == 0x01));
+ parts[i].vx -= (ptypes[(int)playerp[2]].weight*parts[np].vx)/1000;
+ }
+ playerp[28] = 0;
}
+
+ }
}
//Simulation of joints
@@ -385,12 +414,12 @@ void STKM_interact(float* playerp, int i, int x, int y)
r = pmap[y][x];
if (r)
{
- if ((r&0xFF)==PT_SPRK) //If on charge
+ if ((r&0xFF)==PT_SPRK && playerp[2]!=PT_LIGH) //If on charge
{
parts[i].life -= (int)(rand()*20/RAND_MAX)+32;
}
- if (ptypes[r&0xFF].hconduct && (parts[r>>8].temp>=323 || parts[r>>8].temp<=243))
+ if (ptypes[r&0xFF].hconduct && ((playerp[2]!=PT_LIGH && parts[r>>8].temp>=323) || parts[r>>8].temp<=243))
{
parts[i].life -= 2;
playerp[22] -= 1;
diff --git a/src/graphics.c b/src/graphics.c
index bd8eb17..45d26f3 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -31,6 +31,7 @@ int sdl_scale = 1;
GLuint airProg, zoomTex, vidBuf, airBuf, fireAlpha, glowAlpha, blurAlpha, fireProg, partsFboTex, partsFbo, lensProg, partsTFX, partsTFY, airPV, airVY, airVX;
#endif
+int emp_decor = 0;
int sandcolour_r = 0;
int sandcolour_g = 0;
int sandcolour_b = 0;
@@ -41,7 +42,6 @@ unsigned char fire_g[YRES/CELL][XRES/CELL];
unsigned char fire_b[YRES/CELL][XRES/CELL];
unsigned int fire_alpha[CELL*3][CELL*3];
-pixel *fire_bg;
pixel *pers_bg;
char * flm_data;
@@ -854,6 +854,10 @@ int drawtext(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a
r = 255;
g = b = 0;
break;
+ case 'l':
+ r = 255;
+ g = b = 75;
+ break;
case 'b':
r = g = 0;
b = 255;
@@ -929,10 +933,19 @@ int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, i
r = 255;
g = b = 0;
break;
+ case 'l':
+ r = 255;
+ g = b = 75;
+ break;
case 'b':
r = g = 0;
b = 255;
break;
+ case 't':
+ b = 255;
+ g = 170;
+ r = 32;
+ break;
}
s++;
}
@@ -1325,22 +1338,23 @@ void draw_grav_zones(pixel * vid)
void draw_grav(pixel *vid)
{
- int x, y, i;
+ int x, y, i, ca;
float nx, ny, dist;
for (y=0; y<YRES/CELL; y++)
{
for (x=0; x<XRES/CELL; x++)
{
- if(fabsf(gravx[y][x]) <= 0.001f && fabsf(gravy[y][x]) <= 0.001f)
+ ca = ((y*CELL)*XRES)+(x*CELL);
+ if(fabsf(gravpf[ca]) <= 0.001f && fabsf(gravyf[ca]) <= 0.001f)
continue;
nx = x*CELL;
ny = y*CELL;
- dist = fabsf(gravx[y][x])+fabsf(gravy[y][x]);
+ dist = fabsf(gravyf[ca])+fabsf(gravxf[ca]);
for(i = 0; i < 4; i++)
{
- nx -= gravx[y][x]*0.5f;
- ny -= gravy[y][x]*0.5f;
+ nx -= gravxf[ca]*0.5f;
+ ny -= gravyf[ca]*0.5f;
addpixel(vid, (int)(nx+0.5f), (int)(ny+0.5f), 255, 255, 255, (int)(dist*20.0f));
}
}
@@ -1531,6 +1545,30 @@ void xor_rect(pixel *vid, int x, int y, int w, int h)
}
}
+void draw_other(pixel *vid) // EMP effect
+{
+ int i, j;
+ if (emp_decor>0 && !sys_pause) emp_decor-=emp_decor/25+2;
+ if (emp_decor>40) emp_decor=40;
+ if (emp_decor<0) emp_decor = 0;
+ if (cmode==CM_NOTHING) // no in nothing mode
+ return;
+ if (emp_decor>0)
+ {
+ int r=emp_decor*2.5, g=100+emp_decor*1.5, b=255;
+ int a=(1.0*emp_decor/110)*255;
+ if (r>255) r=255;
+ if (g>255) g=255;
+ if (b>255) g=255;
+ if (a>255) a=255;
+ for (j=0; j<YRES; j++)
+ for (i=0; i<XRES; i++)
+ {
+ drawpixel(vid, i, j, r, g, b, a);
+ }
+ }
+}
+
void prepare_graphicscache()
{
graphicscache = malloc(sizeof(gcache_item)*PT_NUM);
diff --git a/src/interface.c b/src/interface.c
index 6ce057b..229ec88 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -2416,6 +2416,53 @@ int color_menu_ui(pixel *vid_buf, int i, int *cr, int *cg, int *cb, int b, int b
return 0;
}
+int quickoptions_tooltip_fade = 0;
+char * quickoptions_tooltip;
+int quickoptions_tooltip_y = 0;
+void quickoptions_menu(pixel *vid_buf, int b, int bq, int x, int y)
+{
+ int i = 0;
+ x /= sdl_scale;
+ y /= sdl_scale;
+ if(quickoptions_tooltip_fade && quickoptions_tooltip)
+ {
+ drawtext_outline(vid_buf, (XRES - 5) - textwidth(quickoptions_tooltip), quickoptions_tooltip_y, quickoptions_tooltip, 255, 255, 255, quickoptions_tooltip_fade*20, 0, 0, 0, quickoptions_tooltip_fade*15);
+ quickoptions_tooltip_fade--;
+ }
+ while(quickmenu[i].icon!=NULL)
+ {
+ if(quickmenu[i].type == QM_TOGGLE)
+ {
+ drawrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+1, 14, 14, 255, 255, 255, 255);
+ if(*(quickmenu[i].variable))
+ {
+ fillrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+1, 14, 14, 255, 255, 255, 255);
+ drawtext(vid_buf, (XRES+BARSIZE)-11, (i*16)+5, quickmenu[i].icon, 0, 0, 0, 255);
+ }
+ else
+ {
+ fillrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+1, 14, 14, 0, 0, 0, 255);
+ drawtext(vid_buf, (XRES+BARSIZE)-11, (i*16)+5, quickmenu[i].icon, 255, 255, 255, 255);
+ }
+ if(x >= (XRES+BARSIZE)-16 && x <= (XRES+BARSIZE)-2 && y >= (i*16)+1 && y <= (i*16)+15)
+ {
+ quickoptions_tooltip_fade+=2;
+ quickoptions_tooltip = quickmenu[i].name;
+ quickoptions_tooltip_y = (i*16)+5;
+ if(b && !bq)
+ {
+ *(quickmenu[i].variable) = !(*(quickmenu[i].variable));
+ }
+ }
+ }
+ i++;
+ }
+ if(quickoptions_tooltip_fade > 12)
+ quickoptions_tooltip_fade = 12;
+ if(quickoptions_tooltip_fade < 0)
+ quickoptions_tooltip_fade = 0;
+}
+
int sdl_poll(void)
{
SDL_Event event;
@@ -2604,7 +2651,6 @@ void set_cmode(int cm) // sets to given view mode
}
else if (cmode==CM_PERS)
{
- memset(fire_bg, 0, XRES*YRES*PIXELSIZE);
memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
strcpy(itc_msg, "Persistent Display");
}
diff --git a/src/luaconsole.c b/src/luaconsole.c
index 5cc2bb3..c74155b 100644
--- a/src/luaconsole.c
+++ b/src/luaconsole.c
@@ -65,6 +65,7 @@ void luacon_open(){
{"getscript",&luatpt_getscript},
{"setwindowsize",&luatpt_setwindowsize},
{"watertest",&luatpt_togglewater},
+ {"screenshot",&luatpt_screenshot},
{NULL,NULL}
};
@@ -1123,9 +1124,9 @@ int luatpt_setdebug(lua_State* l)
}
int luatpt_setfpscap(lua_State* l)
{
-int fpscap = luaL_optint(l, 1, 0);
-limitFPS = fpscap;
-return 0;
+ int fpscap = luaL_optint(l, 1, 0);
+ limitFPS = fpscap;
+ return 0;
}
int luatpt_getscript(lua_State* l)
{
@@ -1225,4 +1226,22 @@ int luatpt_setwindowsize(lua_State* l)
return 1;
}
+int luatpt_screenshot(lua_State* l)
+{
+ int captureUI = luaL_optint(l, 1, 0);
+ if(vid_buf)
+ {
+ if(captureUI)
+ {
+ dump_frame(vid_buf, XRES+BARSIZE, YRES+MENUSIZE, XRES+BARSIZE);
+ }
+ else
+ {
+ dump_frame(vid_buf, XRES, YRES, XRES+BARSIZE);
+ }
+ return 0;
+ }
+ return luaL_error(l, "Screen buffer does not exist");
+}
+
#endif
diff --git a/src/main.c b/src/main.c
index d2d691e..e2c0fc6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -131,7 +131,7 @@ void play_sound(char *file)
}
static const char *it_msg =
- "\brThe Powder Toy - http://powdertoy.co.uk, irc.freenode.net #powder\n"
+ "\blThe Powder Toy - Version " MTOS(SAVE_VERSION) "." MTOS(MINOR_VERSION) " - http://powdertoy.co.uk, irc.freenode.net #powder\n"
"\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\n"
"\n"
"\bgControl+C/V/X are Copy, Paste and cut respectively.\n"
@@ -153,7 +153,7 @@ static const char *it_msg =
"\n"
"Contributors: \bgStanislaw K Skowronek (\brhttp://powder.unaligned.org\bg, \bbirc.unaligned.org #wtf\bg),\n"
"\bgSimon Robertshaw, Skresanov Savely, cracker64, Catelite, Bryan Hoyle, Nathan Cousins, jacksonmj,\n"
- "\bgLieuwe Mosch, Anthony Boot, Matthew Miller\n"
+ "\bgLieuwe Mosch, Anthony Boot, Matthew Miller, MaksProg\n"
"\n"
"\bgTo use online features such as saving, you need to register at: \brhttp://powdertoy.co.uk/Register.html"
;
@@ -1117,7 +1117,6 @@ void clear_sim(void)
player[27] = 0;
player2[27] = 0;
memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- memset(fire_bg, 0, XRES*YRES*PIXELSIZE);
memset(fire_r, 0, sizeof(fire_r));
memset(fire_g, 0, sizeof(fire_g));
memset(fire_b, 0, sizeof(fire_b));
@@ -1454,6 +1453,7 @@ void start_grav_async()
{
if(!ngrav_enable){
gravthread_done = 0;
+ grav_ready = 0;
pthread_mutex_init (&gravmutex, NULL);
pthread_cond_init(&gravcv, NULL);
pthread_create(&gravthread, NULL, update_grav_async, NULL); //Start asynchronous gravity simulation
@@ -1495,10 +1495,10 @@ int main(int argc, char *argv[])
pfree = 0;
pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
- fire_bg = calloc(XRES*YRES, PIXELSIZE);
prepare_alpha(4, 1.0f);
player[2] = player2[2] = PT_DUST;
+ player[28] = player2[28] = 0;
sprintf(ppmfilename, "%s.ppm", argv[2]);
sprintf(ptifilename, "%s.pti", argv[2]);
@@ -1579,13 +1579,13 @@ int main(int argc, char *argv[])
void *http_ver_check, *http_session_check = NULL;
char *ver_data=NULL, *check_data=NULL, *tmp;
//char console_error[255] = "";
- int result, i, j, bq, bc, fire_fc=0, do_check=0, do_s_check=0, old_version=0, http_ret=0,http_s_ret=0, major, minor, buildnum, is_beta = 0, old_ver_len, new_message_len=0;
+ int result, i, j, bq, bc = 0, fire_fc=0, do_check=0, do_s_check=0, old_version=0, http_ret=0,http_s_ret=0, major, minor, buildnum, is_beta = 0, old_ver_len, new_message_len=0;
#ifdef INTERNAL
int vs = 0;
#endif
int wavelength_gfx = 0;
int x, y, line_x, line_y, b = 0, sl=1, sr=0, su=0, c, lb = 0, lx = 0, ly = 0, lm = 0;//, tx, ty;
- int da = 0, dae = 0, db = 0, it = 2047, mx, my, bsx = 2, bsy = 2;
+ int da = 0, dae = 0, db = 0, it = 2047, mx, my, bsx = 2, bsy = 2, quickoptions_tooltip_fade_invert, it_invert = 0;
float nfvx, nfvy;
int load_mode=0, load_w=0, load_h=0, load_x=0, load_y=0, load_size=0;
void *load_data=NULL;
@@ -1636,7 +1636,6 @@ int main(int argc, char *argv[])
menu_count();
parts = calloc(sizeof(particle), NPART);
cb_parts = calloc(sizeof(particle), NPART);
- fire_bg=calloc(XRES*YRES, PIXELSIZE);
init_can_move();
clear_sim();
@@ -1864,6 +1863,7 @@ int main(int argc, char *argv[])
}
render_parts(part_vbuf); //draw particles
+ draw_other(part_vbuf);
if(debug_flags & (DEBUG_PERFORMANCE_CALC|DEBUG_PERFORMANCE_FRAME))
{
@@ -1890,9 +1890,9 @@ int main(int argc, char *argv[])
if(result) //Did the gravity thread finish?
{
memcpy(th_gravmap, gravmap, sizeof(gravmap)); //Move our current gravmap to be processed other thread
- memcpy(gravy, th_gravy, sizeof(gravy)); //Hmm, Gravy
- memcpy(gravx, th_gravx, sizeof(gravx)); //Move the processed velocity maps to be used
- memcpy(gravp, th_gravp, sizeof(gravp));
+ //memcpy(gravy, th_gravy, sizeof(gravy)); //Hmm, Gravy
+ //memcpy(gravx, th_gravx, sizeof(gravx)); //Move the processed velocity maps to be used
+ //memcpy(gravp, th_gravp, sizeof(gravp));
if (!sys_pause||framerender){ //Only update if not paused
//Switch the full size gravmaps, we don't really need the two above any more
@@ -2435,10 +2435,22 @@ int main(int argc, char *argv[])
if (sdl_key==SDLK_SPACE)
sys_pause = !sys_pause;
if (sdl_key=='u')
-
aheat_enable = !aheat_enable;
- if (sdl_key=='h')
+ if (sdl_key=='h' && !(sdl_mod & KMOD_LCTRL))
+ {
hud_enable = !hud_enable;
+ }
+ if (sdl_key==SDLK_F1 || (sdl_key=='h' && (sdl_mod & KMOD_LCTRL)))
+ {
+ if(!it)
+ {
+ it = 8047;
+ }
+ else
+ {
+ it = 0;
+ }
+ }
if (sdl_key=='n')
pretty_powder = !pretty_powder;
if (sdl_key=='p')
@@ -2633,6 +2645,8 @@ int main(int argc, char *argv[])
luacon_step(x/sdl_scale, y/sdl_scale,sl,sr);
#endif
+ quickoptions_menu(vid_buf, b, bq, x, y);
+
for (i=0; i<SC_TOTAL; i++)//draw all the menu sections
{
draw_menu(vid_buf, i, active_menu);
@@ -2695,13 +2709,13 @@ int main(int argc, char *argv[])
}
if (DEBUG_MODE)
{
- sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C, Life: %d", nametext, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life);
+ sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C, Life: %d, Tmp:%d", nametext, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life, parts[cr>>8].tmp);
sprintf(coordtext, "#%d, X:%d Y:%d", cr>>8, x/sdl_scale, y/sdl_scale);
}
else
{
#ifdef BETA
- sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C, Life: %d", nametext, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life);
+ sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C, Life: %d, Tmp:%d", nametext, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life, parts[cr>>8].tmp);
#else
sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C", nametext, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f);
#endif
@@ -2713,7 +2727,7 @@ int main(int argc, char *argv[])
sprintf(heattext, "Empty, Pressure: %3.2f", pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL]);
if (DEBUG_MODE)
{
- sprintf(coordtext, "X:%d Y:%d. GX: %.2f GY: %.2f", x/sdl_scale, y/sdl_scale, gravx[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], gravy[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL]);
+ sprintf(coordtext, "X:%d Y:%d. GX: %.2f GY: %.2f", x/sdl_scale, y/sdl_scale, gravxf[((y/sdl_scale)*XRES)+(x/sdl_scale)], gravyf[((y/sdl_scale)*XRES)+(x/sdl_scale)]);
}
}
}
@@ -3085,7 +3099,6 @@ int main(int argc, char *argv[])
if (x>=1 && x<=17)
{
search_ui(vid_buf);
- memset(fire_bg, 0, XRES*YRES*PIXELSIZE);
memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
memset(fire_r, 0, sizeof(fire_r));
memset(fire_g, 0, sizeof(fire_g));
@@ -3498,29 +3511,34 @@ int main(int argc, char *argv[])
if (vs)
strappend(uitext, " [FRAME CAPTURE]");
#endif
-
+ quickoptions_tooltip_fade_invert = 255 - (quickoptions_tooltip_fade*20);
+ it_invert = 50 - it;
+ if(it_invert < 0)
+ it_invert = 0;
+ if(it_invert > 50)
+ it_invert = 50;
if (sdl_zoom_trig||zoom_en)
{
if (zoom_x<XRES/2)
{
- fillrect(vid_buf, XRES-20-textwidth(heattext), 266, textwidth(heattext)+8, 15, 0, 0, 0, 140);
- drawtext(vid_buf, XRES-16-textwidth(heattext), 270, heattext, 255, 255, 255, 200);
+ fillrect(vid_buf, XRES-20-textwidth(heattext), 266, textwidth(heattext)+8, 15, 0, 0, 0, quickoptions_tooltip_fade_invert*0.5);
+ drawtext(vid_buf, XRES-16-textwidth(heattext), 270, heattext, 255, 255, 255, quickoptions_tooltip_fade_invert*0.75);
if (DEBUG_MODE)
{
- fillrect(vid_buf, XRES-20-textwidth(coordtext), 280, textwidth(coordtext)+8, 13, 0, 0, 0, 140);
- drawtext(vid_buf, XRES-16-textwidth(coordtext), 282, coordtext, 255, 255, 255, 200);
+ fillrect(vid_buf, XRES-20-textwidth(coordtext), 280, textwidth(coordtext)+8, 13, 0, 0, 0, quickoptions_tooltip_fade_invert*0.5);
+ drawtext(vid_buf, XRES-16-textwidth(coordtext), 282, coordtext, 255, 255, 255, quickoptions_tooltip_fade_invert*0.75);
}
if (wavelength_gfx)
draw_wavelengths(vid_buf,XRES-20-textwidth(heattext),265,2,wavelength_gfx);
}
else
{
- fillrect(vid_buf, 12, 266, textwidth(heattext)+8, 15, 0, 0, 0, 140);
- drawtext(vid_buf, 16, 270, heattext, 255, 255, 255, 200);
+ fillrect(vid_buf, 12, 266, textwidth(heattext)+8, 15, 0, 0, 0, quickoptions_tooltip_fade_invert*0.5);
+ drawtext(vid_buf, 16, 270, heattext, 255, 255, 255, quickoptions_tooltip_fade_invert*0.75);
if (DEBUG_MODE)
{
- fillrect(vid_buf, 12, 280, textwidth(coordtext)+8, 13, 0, 0, 0, 140);
- drawtext(vid_buf, 16, 282, coordtext, 255, 255, 255, 200);
+ fillrect(vid_buf, 12, 280, textwidth(coordtext)+8, 13, 0, 0, 0, quickoptions_tooltip_fade_invert*0.5);
+ drawtext(vid_buf, 16, 282, coordtext, 255, 255, 255, quickoptions_tooltip_fade_invert*0.75);
}
if (wavelength_gfx)
draw_wavelengths(vid_buf,12,265,2,wavelength_gfx);
@@ -3528,19 +3546,18 @@ int main(int argc, char *argv[])
}
else
{
- fillrect(vid_buf, XRES-20-textwidth(heattext), 12, textwidth(heattext)+8, 15, 0, 0, 0, 140);
- drawtext(vid_buf, XRES-16-textwidth(heattext), 16, heattext, 255, 255, 255, 200);
+ fillrect(vid_buf, XRES-20-textwidth(heattext), 12, textwidth(heattext)+8, 15, 0, 0, 0, quickoptions_tooltip_fade_invert*0.5);
+ drawtext(vid_buf, XRES-16-textwidth(heattext), 16, heattext, 255, 255, 255, quickoptions_tooltip_fade_invert*0.75);
if (DEBUG_MODE)
{
- fillrect(vid_buf, XRES-20-textwidth(coordtext), 26, textwidth(coordtext)+8, 11, 0, 0, 0, 140);
- drawtext(vid_buf, XRES-16-textwidth(coordtext), 27, coordtext, 255, 255, 255, 200);
+ fillrect(vid_buf, XRES-20-textwidth(coordtext), 26, textwidth(coordtext)+8, 11, 0, 0, 0, quickoptions_tooltip_fade_invert*0.5);
+ drawtext(vid_buf, XRES-16-textwidth(coordtext), 27, coordtext, 255, 255, 255, quickoptions_tooltip_fade_invert*0.75);
}
if (wavelength_gfx)
draw_wavelengths(vid_buf,XRES-20-textwidth(heattext),11,2,wavelength_gfx);
}
wavelength_gfx = 0;
- fillrect(vid_buf, 12, 12, textwidth(uitext)+8, 15, 0, 0, 0, 140);
- drawtext(vid_buf, 16, 16, uitext, 32, 216, 255, 200);
+ drawtext_outline(vid_buf, 16, 16, uitext, 32, 216, 255, it_invert * 4, 0, 0, 0, it_invert * 4);
}
diff --git a/src/misc.c b/src/misc.c
index 9e5842c..3c8e589 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -122,7 +122,9 @@ void save_presets(int do_update)
{
char * outputdata;
cJSON *root, *userobj, *versionobj;
- root = cJSON_CreateObject();
+ FILE* f;
+
+ root = cJSON_CreateObject();
cJSON_AddStringToObject(root, "Powder Toy Preferences", "Don't modify this file unless you know what you're doing. P.S: editing the admin/mod fields in your user info doesn't give you magical powers");
@@ -163,7 +165,7 @@ void save_presets(int do_update)
outputdata = cJSON_Print(root);
cJSON_Delete(root);
- FILE *f = fopen("powder.pref", "wb");
+ f = fopen("powder.pref", "wb");
if(!f)
return;
fwrite(outputdata, 1, strlen(outputdata), f);
diff --git a/src/powder.c b/src/powder.c
index 077a242..bf31b18 100644
--- a/src/powder.c
+++ b/src/powder.c
@@ -9,8 +9,12 @@ int gravwl_timeout = 0;
int wire_placed = 0;
-float player[28]; //[0] is a command cell, [3]-[18] are legs positions, [19]-[26] are accelerations, [27] shows if player was spawned
-float player2[28];
+int lighting_recreate = 0;
+
+//[0] is a command cell, [3]-[18] are legs positions, [19]-[26] are accelerations, [27] shows if player was spawned
+//[28] is frames since last particle spawn - used when spawning LIGH
+float player[29];
+float player2[29];
particle *parts;
particle *cb_parts;
@@ -96,6 +100,7 @@ void init_can_move()
can_move[t][rt] = 2;
}
}
+ can_move[PT_DEST][PT_DMND] = 0;
can_move[PT_BIZR][PT_FILT] = 2;
can_move[PT_BIZRG][PT_FILT] = 2;
for (t=0;t<PT_NUM;t++)
@@ -272,6 +277,8 @@ int try_move(int i, int x, int y, int nx, int ny)
parts[i].ctype &= 0x1F << temp_bin; //Filter Colour
} else if(parts[r>>8].tmp==2){
parts[i].ctype |= 0x1F << temp_bin; //Add Colour
+ } else if(parts[r>>8].tmp==3){
+ parts[i].ctype &= ~(0x1F << temp_bin); //Subtract Colour
}
}
if (parts[i].type == PT_NEUT && (r&0xFF)==PT_GLAS) {
@@ -842,6 +849,22 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a
parts[i].tmp = 0;
parts[i].tmp2 = 0;
}
+ if (t==PT_LIGH && p==-2)
+ {
+ switch (gravityMode)
+ {
+ default:
+ case 0:
+ parts[i].tmp= 270+rand()%40-20;
+ break;
+ case 1:
+ parts[i].tmp = rand()%360;
+ break;
+ case 2:
+ parts[i].tmp = atan2(x-XCNTR, y-YCNTR)*(180.0f/M_PI)+90;
+ }
+ parts[i].tmp2 = 4;
+ }
if (t==PT_SOAP)
{
parts[i].tmp = -1;
@@ -1258,9 +1281,9 @@ inline int parts_avg(int ci, int ni,int t)
}
-int nearest_part(int ci, int t)
+int nearest_part(int ci, int t, int max_d)
{
- int distance = MAX_DISTANCE;
+ int distance = (max_d!=-1)?max_d:MAX_DISTANCE;
int ndistance = 0;
int id = -1;
int i = 0;
@@ -1268,7 +1291,7 @@ int nearest_part(int ci, int t)
int cy = (int)parts[ci].y;
for (i=0; i<=parts_lastActiveIndex; i++)
{
- if (parts[i].type==t&&!parts[i].life&&i!=ci)
+ if ((parts[i].type==t||(t==-1&&parts[i].type))&&!parts[i].life&&i!=ci)
{
ndistance = abs(cx-parts[i].x)+abs(cy-parts[i].y);// Faster but less accurate Older: sqrt(pow(cx-parts[i].x, 2)+pow(cy-parts[i].y, 2));
if (ndistance<distance)
@@ -1329,10 +1352,33 @@ void update_particles_i(pixel *vid, int start, int inc)
int starti = (start*-1);
int surround[8];
int surround_hconduct[8];
+ int lighting_ok=1;
float pGravX, pGravY, pGravD;
+ if (sys_pause&&lighting_recreate>0)
+ {
+ for (i=0; i<=parts_lastActiveIndex; i++)
+ {
+ if (parts[i].type==PT_LIGH && parts[i].tmp2>0)
+ {
+ lighting_ok=0;
+ break;
+ }
+ }
+ }
+
+ if (lighting_ok)
+ lighting_recreate--;
+
+ if (lighting_recreate<0)
+ lighting_recreate=1;
+
+ if (lighting_recreate>21)
+ lighting_recreate=21;
+
if (sys_pause&&!framerender)//do nothing if paused
return;
+
if (ISGRAV==1)//crappy grav color handling, i will change this someday
{
ISGRAV = 0;
@@ -1687,13 +1733,13 @@ void update_particles_i(pixel *vid, int start, int inc)
if (t==PT_ANAR)
{
// perhaps we should have a ptypes variable for this
- pGravX -= gravx[y/CELL][x/CELL];
- pGravY -= gravy[y/CELL][x/CELL];
+ pGravX -= gravxf[(y*XRES)+x];
+ pGravY -= gravyf[(y*XRES)+x];
}
else if(t!=PT_STKM && t!=PT_STKM2 && !(ptypes[t].properties & TYPE_SOLID))
{
- pGravX += gravx[y/CELL][x/CELL];
- pGravY += gravy[y/CELL][x/CELL];
+ pGravX += gravxf[(y*XRES)+x];
+ pGravY += gravyf[(y*XRES)+x];
}
//velocity updates for the particle
parts[i].vx *= ptypes[t].loss;
@@ -1782,8 +1828,9 @@ void update_particles_i(pixel *vid, int start, int inc)
pt = (c_heat+parts[i].temp*96.645/ptypes[t].hconduct*fabs(ptypes[t].weight))/(c_Cm+96.645/ptypes[t].hconduct*fabs(ptypes[t].weight));
#else
- pt = parts[i].temp = (c_heat+parts[i].temp)/(h_count+1);
+ pt = (c_heat+parts[i].temp)/(h_count+1);
#endif
+ pt = parts[i].temp = restrict_flt(pt, MIN_TEMP, MAX_TEMP);
for (j=0; j<8; j++)
{
parts[surround_hconduct[j]].temp = pt;
@@ -1803,7 +1850,7 @@ void update_particles_i(pixel *vid, int start, int inc)
if (ptransitions[t].tht!=PT_NUM)
t = ptransitions[t].tht;
else if (t==PT_ICEI) {
- if (parts[i].ctype&&parts[i].ctype!=PT_ICEI) {
+ if (parts[i].ctype>0&&parts[i].ctype<PT_NUM&&parts[i].ctype!=PT_ICEI) {
if (ptransitions[parts[i].ctype].tlt==PT_ICEI&&pt<=ptransitions[parts[i].ctype].tlv) s = 0;
else {
t = parts[i].ctype;
@@ -1948,7 +1995,7 @@ void update_particles_i(pixel *vid, int start, int inc)
s = 1;
- gravtot = fabsf(gravy[y/CELL][x/CELL])+fabsf(gravx[y/CELL][x/CELL]);
+ gravtot = fabs(gravyf[(y*XRES)+x])+fabs(gravxf[(y*XRES)+x]);
if (pv[y/CELL][x/CELL]>ptransitions[t].phv&&ptransitions[t].pht>-1) {
// particle type change due to high pressure
if (ptransitions[t].pht!=PT_NUM)
@@ -2312,8 +2359,8 @@ killed:
pGravX = ptGrav * ((float)(nx - XCNTR) / pGravD);
pGravY = ptGrav * ((float)(ny - YCNTR) / pGravD);
}
- pGravX += gravx[ny/CELL][nx/CELL];
- pGravY += gravy[ny/CELL][nx/CELL];
+ pGravX += gravxf[(ny*XRES)+nx];
+ pGravY += gravyf[(ny*XRES)+nx];
if (fabsf(pGravY)>fabsf(pGravX))
mv = fabsf(pGravY);
else
@@ -2371,8 +2418,8 @@ killed:
pGravX = ptGrav * ((float)(nx - XCNTR) / pGravD);
pGravY = ptGrav * ((float)(ny - YCNTR) / pGravD);
}
- pGravX += gravx[ny/CELL][nx/CELL];
- pGravY += gravy[ny/CELL][nx/CELL];
+ pGravX += gravxf[(ny*XRES)+nx];
+ pGravY += gravyf[(ny*XRES)+nx];
if (fabsf(pGravY)>fabsf(pGravX))
mv = fabsf(pGravY);
else
@@ -2566,11 +2613,11 @@ int flood_prop_2(int x, int y, size_t propoffset, void * propvalue, int proptype
{
i = pmap[y][x]>>8;
if(proptype==2){
- *((float*)(((void*)&parts[i])+propoffset)) = *((float*)propvalue);
+ *((float*)(((char*)&parts[i])+propoffset)) = *((float*)propvalue);
} else if(proptype==0) {
- *((int*)(((void*)&parts[i])+propoffset)) = *((int*)propvalue);
+ *((int*)(((char*)&parts[i])+propoffset)) = *((int*)propvalue);
} else if(proptype==1) {
- *((char*)(((void*)&parts[i])+propoffset)) = *((char*)propvalue);
+ *((char*)(((char*)&parts[i])+propoffset)) = *((char*)propvalue);
}
bitmap[(y*XRES)+x] = 1;
}
@@ -2772,10 +2819,23 @@ int flood_water(int x, int y, int i, int originaly, int check)
return 1;
}
+//wrapper around create_part to create TESC with correct tmp value
+int create_part_add_props(int p, int x, int y, int tv, int rx, int ry)
+{
+ p=create_part(p, x, y, tv);
+ if (tv==PT_TESC)
+ {
+ parts[p].tmp=rx*4+ry*4+7;
+ if (parts[p].tmp>300)
+ parts[p].tmp=300;
+ }
+ return p;
+}
+
//this creates particles from a brush, don't use if you want to create one particle
int create_parts(int x, int y, int rx, int ry, int c, int flags)
{
- int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0;//n;
+ int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0, p;//n;
int wall = c - 100;
if (c==SPC_WIND){
@@ -2807,6 +2867,23 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags)
{
gravwl_timeout = 60;
}
+ if (c==PT_LIGH)
+ {
+ if (lighting_recreate>0 && rx+ry>0)
+ return 0;
+ p=create_part(-2, x, y, c);
+ if (p!=-1)
+ {
+ parts[p].life=rx+ry;
+ if (parts[p].life>55)
+ parts[p].life=55;
+ parts[p].temp=parts[p].life*150; // temperature of the lighting shows the power of the lighting
+ lighting_recreate+=parts[p].life/2+1;
+ return 1;
+ }
+ else return 0;
+ }
+
if (dw==1)
{
ry = ry/CELL;
@@ -2921,7 +2998,7 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags)
{
delete_part(x, y, 0);
if (c!=0)
- create_part(-2, x, y, c);
+ create_part_add_props(-2, x, y, c, rx, ry);
}
}
}
@@ -2938,7 +3015,7 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags)
{
delete_part(x+i, y+j, 0);
if (c!=0)
- create_part(-2, x+i, y+j, c);
+ create_part_add_props(-2, x+i, y+j, c, rx, ry);
}
}
return 1;
@@ -2947,14 +3024,14 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags)
//else, no special modes, draw element like normal.
if (rx==0&&ry==0)//workaround for 1pixel brush/floodfill crashing. todo: find a better fix later.
{
- if (create_part(-2, x, y, c)==-1)
+ if (create_part_add_props(-2, x, y, c, rx, ry)==-1)
f = 1;
}
else
for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++)
if (InCurrentBrush(i ,j ,rx ,ry))
- if (create_part(-2, x+i, y+j, c)==-1)
+ if (create_part_add_props(-2, x+i, y+j, c, rx, ry)==-1)
f = 1;
return !f;
}
@@ -3030,7 +3107,8 @@ void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flag
if (e >= 0.5f)
{
y += sy;
- if (c==WL_EHOLE+100 || c==WL_ALLOWGAS+100 || c==WL_ALLOWENERGY+100 || c==WL_ALLOWALLELEC+100 || c==WL_ALLOWSOLID+100 || c==WL_ALLOWAIR+100 || c==WL_WALL+100 || c==WL_DESTROYALL+100 || c==WL_ALLOWLIQUID+100 || c==WL_FAN+100 || c==WL_STREAM+100 || c==WL_DETECT+100 || c==WL_EWALL+100 || c==WL_WALLELEC+100 || !(rx+ry))
+ if ((c==WL_EHOLE+100 || c==WL_ALLOWGAS+100 || c==WL_ALLOWENERGY+100 || c==WL_ALLOWALLELEC+100 || c==WL_ALLOWSOLID+100 || c==WL_ALLOWAIR+100 || c==WL_WALL+100 || c==WL_DESTROYALL+100 || c==WL_ALLOWLIQUID+100 || c==WL_FAN+100 || c==WL_STREAM+100 || c==WL_DETECT+100 || c==WL_EWALL+100 || c==WL_WALLELEC+100 || !(rx+ry))
+ && ((y1<y2) ? (y<=y2) : (y>=y2)))
{
if (cp)
create_parts(y, x, rx, ry, c, flags);