From 9b9d6283744c2164d90fece77366adf8d13abcd3 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Mon, 8 Aug 2011 14:57:32 +0100 Subject: [PATCH] Improvements to Wire --- includes/powder.h | 2 ++ src/elements/wire.c | 30 +++++++++++++++++++----------- src/powder.c | 31 ++++++++++++++++++------------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/includes/powder.h b/includes/powder.h index 59549523a..23f4217e2 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -936,6 +936,8 @@ particle portalp[CHANNELS][8][80]; const particle emptyparticle; int wireless[CHANNELS][2]; +extern int ISWIRE; + extern int gravwl_timeout; extern float player[28]; diff --git a/src/elements/wire.c b/src/elements/wire.c index 920ddc978..f56e4696f 100644 --- a/src/elements/wire.c +++ b/src/elements/wire.c @@ -2,7 +2,6 @@ int update_WIRE(UPDATE_FUNC_ARGS) { int s,r,rx,ry,count; - s=pmap[y][x]; /* 0: wire 1: spark head @@ -10,23 +9,32 @@ int update_WIRE(UPDATE_FUNC_ARGS) { tmp is previous state, ctype is current state */ - //parts[s>>8].tmp=parts[s>>8].ctype; - parts[s>>8].ctype=0; - if(parts[s>>8].tmp==1){parts[s>>8].ctype=2; return 0;} - if(parts[s>>8].tmp==2){parts[s>>8].ctype=0; return 0;} + //parts[i].tmp=parts[i].ctype; + parts[i].ctype=0; + if(parts[i].tmp==1) + { + parts[i].ctype=2; + } + if(parts[i].tmp==2) + { + parts[i].ctype=0; + } count=0; for(rx=-1; rx<2; rx++) for(ry=-1; ry<2; ry++) + { + if(x+rx>=0 && y+ry>0 && x+rx=0 && y+ry>0 && x+rx>8].ctype==PT_PSCN){parts[s>>8].ctype=1; parts[r>>8].life=0; return 0;} - if((r&0xFF)==PT_WIRE && parts[r>>8].tmp==1){count++;} - } + if ((r>>8)>=NPART || !r) + continue; + if((r&0xFF)==PT_SPRK && parts[r>>8].ctype==PT_PSCN){parts[i].ctype=1; parts[r>>8].life=0; return 0;} + else if((r&0xFF)==PT_NSCN && parts[i].tmp==1){create_part(-1, x+rx, y+ry, PT_SPRK);} + else if((r&0xFF)==PT_WIRE && parts[r>>8].tmp==1 && !parts[i].tmp){count++;} } + } if(count==1 || count==2) - parts[s>>8].ctype=1; + parts[i].ctype=1; return 0; } diff --git a/src/powder.c b/src/powder.c index 8e5139a5a..4add0b60f 100644 --- a/src/powder.c +++ b/src/powder.c @@ -7,6 +7,8 @@ int gravwl_timeout = 0; +int ISWIRE = 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]; @@ -709,11 +711,6 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a if (t==PT_SPRK) { - if((pmap[y][x]>>8)==PT_WIRE) - { - parts[pmap[y][x]>>8].ctype=1; - return -1; - } if ((pmap[y][x]>>8)>=NPART || !((pmap[y][x]&0xFF)==PT_INST||(ptypes[pmap[y][x]&0xFF].properties&PROP_CONDUCTS))) return -1; if (parts[pmap[y][x]>>8].life!=0) @@ -1472,14 +1469,18 @@ void update_particles_i(pixel *vid, int start, int inc) } } //wire! - for (nx=0; nx>8)>=NPART || !r) - continue; - parts[r>>8].tmp=parts[r>>8].ctype; - } + if(ISWIRE == 1) + { + ISWIRE = 0; + for (nx=0; nx>8)>=NPART || !r) + continue; + parts[r>>8].tmp=parts[r>>8].ctype; + } + } //game of life! if (ISGOL==1&&++CGOL>=GSPEED)//GSPEED is frames per generation { @@ -1887,6 +1888,10 @@ void update_particles_i(pixel *vid, int start, int inc) parts[i].temp = restrict_flt(parts[i].temp-50.0f, MIN_TEMP, MAX_TEMP); ISGOL=1;//means there is a life particle on screen } + if (t==PT_WIRE) + { + ISWIRE = 1; + } //spark updates from walls if ((ptypes[t].properties&PROP_CONDUCTS) || t==PT_SPRK) {