Merge with cracker, also fix version

This commit is contained in:
Simon 2011-02-04 10:24:35 +00:00
commit 9469a3b46a
9 changed files with 151 additions and 75 deletions

View File

@ -8,14 +8,12 @@
#endif
#define SAVE_VERSION 46
#define MINOR_VERSION 0
#define MINOR_VERSION 1
#define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter.
//#define BETA
#define BETA
#define SERVER "powdertoy.co.uk"
#undef PLOSS
#define THUMB_CACHE_SIZE 256
#define IMGCONNS 3
@ -45,11 +43,11 @@ extern unsigned char ZSIZE;
#define ISTP (CELL/2)
#define CFDS (4.0f/CELL)
#define TSTEPP 0.3f
#define TSTEPV 0.4f
#define VADV 0.3f
#define VLOSS 0.999f
#define PLOSS 0.9999f
#define AIR_TSTEPP 0.3f
#define AIR_TSTEPV 0.4f
#define AIR_VADV 0.3f
#define AIR_VLOSS 0.999f
#define AIR_PLOSS 0.9999f
#define GRID_X 5
#define GRID_Y 4

View File

@ -69,6 +69,8 @@ static menu_section msections[] =
{"\xC6", "Radioactive", 0, 1},
{"\xCC", "Special", 0, 1},
{"\xD2", "Life", 0, 1},
{"\xD2", "More Life", 0, 1},
{"\xC8", "", 0, 0},
{"\xC8", "Cracker", 0, 0},
{"\xC8", "Cracker!", 0, 0},
};

View File

@ -86,8 +86,8 @@ void update_air(void)
dp = 0.0f;
dp += vx[y][x-1] - vx[y][x];
dp += vy[y-1][x] - vy[y][x];
pv[y][x] *= PLOSS;
pv[y][x] += dp*TSTEPP;
pv[y][x] *= AIR_PLOSS;
pv[y][x] += dp*AIR_TSTEPP;
}
for (y=0; y<YRES/CELL-1; y++)
@ -96,10 +96,10 @@ void update_air(void)
dx = dy = 0.0f;
dx += pv[y][x] - pv[y][x+1];
dy += pv[y][x] - pv[y+1][x];
vx[y][x] *= VLOSS;
vy[y][x] *= VLOSS;
vx[y][x] += dx*TSTEPV;
vy[y][x] += dy*TSTEPV;
vx[y][x] *= AIR_VLOSS;
vy[y][x] *= AIR_VLOSS;
vx[y][x] += dx*AIR_TSTEPV;
vy[y][x] += dy*AIR_TSTEPV;
if (bmap[y][x]==WL_WALL || bmap[y][x+1]==WL_WALL ||
bmap[y][x]==WL_WALLELEC || bmap[y][x+1]==WL_WALLELEC ||
(bmap[y][x]==WL_EWALL && !emap[y][x]) ||
@ -148,20 +148,20 @@ void update_air(void)
if (i>=2 && i<XRES/CELL-3 &&
j>=2 && j<YRES/CELL-3)
{
dx *= 1.0f - VADV;
dy *= 1.0f - VADV;
dx *= 1.0f - AIR_VADV;
dy *= 1.0f - AIR_VADV;
dx += VADV*(1.0f-tx)*(1.0f-ty)*vx[j][i];
dy += VADV*(1.0f-tx)*(1.0f-ty)*vy[j][i];
dx += AIR_VADV*(1.0f-tx)*(1.0f-ty)*vx[j][i];
dy += AIR_VADV*(1.0f-tx)*(1.0f-ty)*vy[j][i];
dx += VADV*tx*(1.0f-ty)*vx[j][i+1];
dy += VADV*tx*(1.0f-ty)*vy[j][i+1];
dx += AIR_VADV*tx*(1.0f-ty)*vx[j][i+1];
dy += AIR_VADV*tx*(1.0f-ty)*vy[j][i+1];
dx += VADV*(1.0f-tx)*ty*vx[j+1][i];
dy += VADV*(1.0f-tx)*ty*vy[j+1][i];
dx += AIR_VADV*(1.0f-tx)*ty*vx[j+1][i];
dy += AIR_VADV*(1.0f-tx)*ty*vy[j+1][i];
dx += VADV*tx*ty*vx[j+1][i+1];
dy += VADV*tx*ty*vy[j+1][i+1];
dx += AIR_VADV*tx*ty*vx[j+1][i+1];
dy += AIR_VADV*tx*ty*vy[j+1][i+1];
}
if (bmap[y][x] == WL_FAN)

View File

@ -7,9 +7,9 @@ int update_FWRK(UPDATE_FUNC_ARGS) {
np = create_part(-1, x , y-1 , PT_FWRK);
if (np!=-1)
{
parts[r>>8].vy = rand()%8-22;
parts[r>>8].vx = rand()%20-rand()%20;
parts[r>>8].life=rand()%15+25;
parts[np].vy = rand()%8-22;
parts[np].vx = rand()%20-rand()%20;
parts[np].life=rand()%15+25;
kill_part(i);
return 1;
}
@ -33,13 +33,13 @@ int update_FWRK(UPDATE_FUNC_ARGS) {
pv[y/CELL][x/CELL] += 2.00f*CFDS;
if (np!=-1)
{
parts[r>>8].vy = -(rand()%10-1);
parts[r>>8].vx = ((rand()%2)*2-1)*rand()%(5+5)+(parts[i].vx)*2 ;
parts[r>>8].life= rand()%37+18;
parts[r>>8].tmp=q;
parts[r>>8].flags=w;
parts[r>>8].ctype=e;
parts[r>>8].temp= rand()%20+6000;
parts[np].vy = -(rand()%10-1);
parts[np].vx = ((rand()%2)*2-1)*rand()%(5+5)+(parts[i].vx)*2 ;
parts[np].life= rand()%37+18;
parts[np].tmp=q;
parts[np].flags=w;
parts[np].ctype=e;
parts[np].temp= rand()%20+6000;
}
}
}

View File

@ -6,7 +6,8 @@ int update_PHOT(UPDATE_FUNC_ARGS) {
if (1>rand()%10) update_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
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)) {
if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) {
r = pmap[y+ry][x+rx];
if ((r>>8)>=NPART || !r)
continue;
if ((r&0xFF)==PT_ISOZ && 5>(rand()%2000))

View File

@ -25,6 +25,10 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
kill_part(i);
return 1;
}
else if (ct==PT_NTCT || ct==PT_PTCT)
{
update_NPTCT(UPDATE_FUNC_SUBCALL_ARGS);
}
else if (ct==PT_ETRD&&parts[i].life==1)
{
nearp = nearest_part(i, PT_ETRD);
@ -97,12 +101,12 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
// ct = spark from material, rt = spark to material. Make conduct_sprk = 0 if conduction not allowed
if (pavg == PT_INSL) conduct_sprk = 0;
if (!(ptypes[rt].properties&PROP_CONDUCTS||rt==PT_INST)) conduct_sprk = 0;
if (!(ptypes[rt].properties&PROP_CONDUCTS||rt==PT_INST||rt==PT_QRTZ)) conduct_sprk = 0;
if (abs(rx)+abs(ry)>=4 &&ct!=PT_SWCH&&rt!=PT_SWCH)
conduct_sprk = 0;
if (ct==PT_METL && (rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR||(rt==PT_SPRK&&(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT))))
if (ct==PT_METL && (rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR||(rt==PT_SPRK&&(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT))) && pavg!=PT_INSL)
{
parts[r>>8].temp = 473.0f;
if (rt==PT_NTCT||rt==PT_PTCT)

View File

@ -3965,6 +3965,7 @@ int console_parse_type(char *txt, int *element, char *err)
if (strcmp(txt,num)==0)
{
*element = i;
strcpy(err,"");
return 1;
}
}
@ -3976,12 +3977,14 @@ int console_parse_type(char *txt, int *element, char *err)
if (i>=0)
{
*element = i;
strcpy(err,"");
return 1;
}
for (i=1; i<PT_NUM; i++) {
if (strcasecmp(txt,ptypes[i].name)==0)
{
*element = i;
strcpy(err,"");
return 1;
}
}
@ -3991,32 +3994,20 @@ int console_parse_type(char *txt, int *element, char *err)
int console_parse_coords(char *txt, int *x, int *y, char *err)
{
// TODO: use regex?
char *coordtxt;
char num[10] = "";
int nx = -1, ny = -1;
txt = mystrdup(txt);
coordtxt = strtok(txt, ",");
if (coordtxt) nx = atoi(coordtxt);
if (nx>=0 && nx<XRES) sprintf(num,"%d",nx);
if (!coordtxt || strcmp(coordtxt, num)!=0)
sscanf(txt,"%d,%d",&nx,&ny);
if (nx<0 && nx>=XRES)
{
strcpy(err,"Invalid coordinates");
free(txt);
return 0;
}
strcpy(num,"");
coordtxt = strtok(NULL, ",");
if (coordtxt) ny = atoi(coordtxt);
if (ny>=0 && ny<YRES) sprintf(num,"%d",ny);
if (!coordtxt || strcmp(coordtxt, num)!=0)
if (ny<0 && ny>=YRES)
{
strcpy(err,"Invalid coordinates");
free(txt);
return 0;
}
*x = nx;
*y = ny;
free(txt);
return 1;
}
int console_parse_partref(char *txt, int *which, char *err)
@ -4044,6 +4035,7 @@ int console_parse_partref(char *txt, int *which, char *err)
if (i>=0 && i<NPART && parts[i].type)
{
*which = i;
strcpy(err,"");
return 1;
}
strcpy(err,"Particle does not exist");

View File

@ -1780,7 +1780,7 @@ int main(int argc, char *argv[])
console = console_ui(vid_buf,console_error);
console = mystrdup(console);
strcpy(console_error,"");
if(process_command(vid_buf,console,&console_error)==0)
if(process_command(vid_buf,console,&console_error)==-1)
{
free(console);
break;
@ -2626,38 +2626,93 @@ int main(int argc, char *argv[])
return 0;
}
int process_command(pixel *vid_buf,char *console,char *console_error) {
int nx,ny,i,j,k;
char *console2;
char *console3;
char *console4;
char *console5;
int y,x,nx,ny,i,j,k,m;
int do_next = 1;
char xcoord[10];
char ycoord[10];
char console2[15];
char console3[15];
char console4[15];
char console5[15];
//sprintf(console_error, "%s", console);
if(console && strcmp(console, "")!=0 && strncmp(console, " ", 1)!=0)
{
console2 = strtok(console, " ");
console3 = strtok(NULL, " ");
console4 = strtok(NULL, " ");
console5 = strtok(NULL, " ");
sscanf(console,"%s %s %s %s", console2, console3, console4, console5);//why didn't i know about this function?!
if(strcmp(console2, "quit")==0)
{
return 0;
return -1;
}
else if(strcmp(console2, "file")==0 && console3)
{
FILE *f=fopen(console3, "r");
if(f)
{
nx = 0;
ny = 0;
j = 0;
m = 0;
if(console4)
console_parse_coords(console4, &nx , &ny, console_error);
char fileread[5000];//TODO: make this change with file size
char pch[5000];
memset(pch,0,sizeof(pch));
memset(fileread,0,sizeof(fileread));
char tokens[10];
int tokensize;
fread(fileread,1,5000,f);
j = 0;
for(i=0; i<strlen(fileread); i++)
{
if(fileread[i] != '\n')
pch[i-j] = fileread[i];
else
{
process_command(vid_buf, pch, console_error);
pch[i-j] = fileread[i];
if(fileread[i] != ' ')
tokens[i-m] = fileread[i];
}
if(fileread[i] == ' ' || fileread[i] == '\n')
{
if(sregexp(tokens,"^x.[0-9],y.[0-9]")==0)//TODO: fix regex matching to work with x,y ect, right now it has to have a +0 or -0
{
char temp[5];
int starty = 0;
tokensize = strlen(tokens);
x = 0;
y = 0;
sscanf(tokens,"x%d,y%d",&x,&y);
sscanf(tokens,"%s,%s",xcoord,ycoord);
x += nx;
y += ny;
sprintf(xcoord,"%d",x);
sprintf(ycoord,"%d",y);
for(k = 0; k<strlen(xcoord);k++)//rewrite pch with numbers
{
pch[i-j-tokensize+k] = xcoord[k];
starty = k+1;
}
pch[i-j-tokensize+starty] = ',';
starty++;
for(k=0;k<strlen(ycoord);k++)
{
pch[i-j-tokensize+starty+k] = ycoord[k];
}
pch[i-j-tokensize +strlen(xcoord) +1 +strlen(ycoord)] = ' ';
j = j -tokensize +strlen(xcoord) +1 +strlen(ycoord);
}
memset(tokens,0,sizeof(tokens));
m = i+1;
}
if(fileread[i] == '\n')
{
if(do_next)
{
if(strcmp(pch,"else")==0)
do_next = 0;
else
do_next = process_command(vid_buf, pch, console_error);
}
else if(strcmp(pch,"endif")==0 || strcmp(pch,"else")==0)
do_next = 1;
memset(pch,0,sizeof(pch));
j = i+1;
}
@ -2681,6 +2736,22 @@ int process_command(pixel *vid_buf,char *console,char *console_error) {
console_mode = 0;
}
}
else if(strcmp(console2, "if")==0 && console3)
{
if(strcmp(console3, "type")==0)//TODO: add more than just type, and be able to check greater/less than
{
if (console_parse_partref(console4, &i, console_error)
&& console_parse_type(console5, &j, console_error))
{
if(parts[i].type==j)
return 1;
else
return 0;
}
else
return 0;
}
}
else if (strcmp(console2, "create")==0 && console3 && console4)
{
if (console_parse_type(console3, &j, console_error)

View File

@ -1080,7 +1080,7 @@ inline int parts_avg(int ci, int ni,int t)
{
if (t==PT_INSL)//to keep electronics working
{
int pmr = pmap[(int)((parts[ci].y + parts[ni].y)/2)][(int)((parts[ci].x + parts[ni].x)/2)];
int pmr = pmap[((int)(parts[ci].y+0.5f) + (int)(parts[ni].y+0.5f))/2][((int)(parts[ci].x+0.5f) + (int)(parts[ni].x+0.5f))/2];
if ((pmr>>8) < NPART && pmr)
return parts[pmr>>8].type;
else
@ -1113,7 +1113,7 @@ int nearest_part(int ci, int t)
{
if (parts[i].type==t&&!parts[i].life&&i!=ci)
{
ndistance = abs((cx-parts[i].x)+(cy-parts[i].y));// Faster but less accurate Older: sqrt(pow(cx-parts[i].x, 2)+pow(cy-parts[i].y, 2));
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;
@ -1127,7 +1127,7 @@ int nearest_part(int ci, int t)
void update_particles_i(pixel *vid, int start, int inc)
{
int i, j, x, y, t, nx, ny, r, surround_space, s, lt, rt, nt, nnx, nny, q, golnum, goldelete, z, neighbors;
float mv, dx, dy, ix, iy, lx, ly, nrx, nry, dp;
float mv, dx, dy, ix, iy, lx, ly, nrx, nry, dp, ctemph, ctempl;
int fin_x, fin_y, clear_x, clear_y;
float fin_xf, fin_yf, clear_xf, clear_yf;
float nn, ct1, ct2, swappage;
@ -1290,9 +1290,9 @@ void update_particles_i(pixel *vid, int start, int inc)
}
if (ISGOL==1&&++CGOL>=GSPEED)//GSPEED is frames per generation
{
int createdsomething = 0;
CGOL=0;
ISGOL=0;
int createdsomething = 0;
for (nx=CELL; nx<XRES-CELL; nx++)
for (ny=CELL; ny<YRES-CELL; ny++)
{
@ -1522,8 +1522,16 @@ void update_particles_i(pixel *vid, int start, int inc)
parts[surround_hconduct[j]].temp = pt;
}
ctemph = ctempl = pt;
// change boiling point with pressure
if ((ptypes[t].state==ST_LIQUID && ptransitions[t].tht>-1 && ptransitions[t].tht<PT_NUM && ptypes[ptransitions[t].tht].state==ST_GAS)
|| t==PT_LNTG || t==PT_SLTW)
ctemph -= 2.0f*pv[y/CELL][x/CELL];
else if ((ptypes[t].state==ST_GAS && ptransitions[t].tlt>-1 && ptransitions[t].tlt<PT_NUM && ptypes[ptransitions[t].tlt].state==ST_LIQUID)
|| t==PT_WTRV)
ctempl -= 2.0f*pv[y/CELL][x/CELL];
s = 1;
if (pt>ptransitions[t].thv&&ptransitions[t].tht>-1) {
if (ctemph>ptransitions[t].thv&&ptransitions[t].tht>-1) {
// particle type change due to high temperature
if (ptransitions[t].tht!=PT_NUM)
t = ptransitions[t].tht;
@ -1544,7 +1552,7 @@ void update_particles_i(pixel *vid, int start, int inc)
else t = PT_WTRV;
}
else s = 0;
} else if (pt<ptransitions[t].tlv&&ptransitions[t].tlt>-1) {
} else if (ctempl<ptransitions[t].tlv&&ptransitions[t].tlt>-1) {
// particle type change due to low temperature
if (ptransitions[t].tlt!=PT_NUM)
t = ptransitions[t].tlt;
@ -1553,7 +1561,7 @@ void update_particles_i(pixel *vid, int start, int inc)
else t = PT_DSTW;
}
else if (t==PT_LAVA) {
if (parts[i].ctype&&parts[i].ctype!=PT_LAVA) {
if (parts[i].ctype && parts[i].ctype<PT_NUM && parts[i].ctype!=PT_LAVA) {
if (ptransitions[parts[i].ctype].tht==PT_LAVA&&pt>=ptransitions[parts[i].ctype].thv) s = 0;
else if (parts[i].ctype==PT_THRM&&pt>=ptransitions[PT_BMTL].thv) s = 0;
else if (pt>=973.0f) s = 0; // freezing point for lava with any other (not listed in ptransitions as turning into lava) ctype