summaryrefslogtreecommitdiff
path: root/src/elements
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/elements
parentf01056ee0249ad01ed24824aea39f05083110cd6 (diff)
parentf8d54e66dba5d8448d30f61f84883b4e7e6e1087 (diff)
downloadpowder-07a1f21df484a252d54c82262ade6d4117425694.zip
powder-07a1f21df484a252d54c82262ade6d4117425694.tar.gz
Merge latest with graphicstest
Diffstat (limited to 'src/elements')
-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
5 files changed, 572 insertions, 21 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;