Merge branch 'cracker64' into dev

Conflicts:
	src/interface.c
	src/main.c
This commit is contained in:
jacksonmj 2011-01-31 14:05:05 +00:00
commit 363a3e38f1
2 changed files with 324 additions and 274 deletions

View File

@ -3840,12 +3840,15 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show
clearrect(vid_buf, 0, 0, XRES+BARSIZE, 220);//anyway to make it transparent? clearrect(vid_buf, 0, 0, XRES+BARSIZE, 220);//anyway to make it transparent?
draw_line(vid_buf, 1, 219, XRES, 219, 228, 228, 228, XRES+BARSIZE); draw_line(vid_buf, 1, 219, XRES, 219, 228, 228, 228, XRES+BARSIZE);
drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.1 (by cracker64)\n" drawtext(vid_buf, 100, 15, "Welcome to The Powder Toy console v.2 (by cracker64)\n"
"Current commands are quit, set, reset, load\n" "Current commands are quit, set, reset, load, create, file\n"
"You can set type, temp, ctype, life, x, y, vx, vy using this format ('set life particle# 9001')\n" "You can set type, temp, ctype, life, x, y, vx, vy using this format ('set life particle# 9001')\n"
"You can also use 'all' instead of a particle number to do it to everything\n" "You can also use 'all' instead of a particle number to do it to everything.\n"
"You can now use particle names (ex. set type all deut)\n"
"Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n" "Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n"
"To load a save use load saveID (ex. load 1337)" "To load a save use load saveID (ex. load 1337)\n"
"Create particles with 'create deut x y' where x and y are the coords\n"
"Run scripts from file 'file filename'"
,255, 187, 187, 255); ,255, 187, 187, 255);
cc = 0; cc = 0;
@ -3937,6 +3940,7 @@ int console_get_type(char *element)
return i; return i;
if (strcasecmp(element,"C4")==0) return PT_PLEX; if (strcasecmp(element,"C4")==0) return PT_PLEX;
if (strcasecmp(element,"C5")==0) return PT_C5; if (strcasecmp(element,"C5")==0) return PT_C5;
if (strcasecmp(element,"NONE")==0) return PT_NONE;
for (i=0; i<PT_NUM; i++) { for (i=0; i<PT_NUM; i++) {
if (strcasecmp(element,ptypes[i].name)==0) if (strcasecmp(element,ptypes[i].name)==0)
return i; return i;

View File

@ -1121,7 +1121,7 @@ int main(int argc, char *argv[])
pixel *pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE); pixel *pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
void *http_ver_check; void *http_ver_check;
char *ver_data=NULL, *tmp; char *ver_data=NULL, *tmp;
char error[255] = ""; char console_error[255] = "";
int i, j, bq, fire_fc=0, do_check=0, old_version=0, http_ret=0, major, minor, old_ver_len; int i, j, bq, fire_fc=0, do_check=0, old_version=0, http_ret=0, major, minor, old_ver_len;
#ifdef INTERNAL #ifdef INTERNAL
int vs = 0; int vs = 0;
@ -1698,280 +1698,17 @@ int main(int argc, char *argv[])
} }
if(console_mode) if(console_mode)
{ {
int nx,ny;
char *console; char *console;
char *console2;
char *console3;
char *console4;
char *console5;
//char error[255] = "error!"; //char error[255] = "error!";
sys_pause = 1; sys_pause = 1;
console = console_ui(vid_buf,error); console = console_ui(vid_buf,console_error);
console = mystrdup(console); console = mystrdup(console);
strcpy(error,""); strcpy(console_error,"");
if(console && strcmp(console, "")!=0 && strncmp(console, " ", 1)!=0) if(process_command(vid_buf,console,&console_error)==0)
{
console2 = strtok(console, " ");
console3 = strtok(NULL, " ");
console4 = strtok(NULL, " ");
console5 = strtok(NULL, " ");
if(strcmp(console2, "quit")==0)
{ {
free(console); free(console);
break; break;
} }
else if(strcmp(console2, "load")==0 && console3)
{
j = atoi(console3);
if(j)
{
open_ui(vid_buf, console3, NULL);
console_mode = 0;
}
}
else if(strcmp(console2, "reset")==0 && console3)
{
if(strcmp(console3, "pressure")==0)
{
for (nx = 0; nx<XRES/CELL; nx++)
for (ny = 0; ny<YRES/CELL; ny++)
{
pv[ny][nx] = 0;
}
}
else if(strcmp(console3, "velocity")==0)
{
for (nx = 0; nx<XRES/CELL; nx++)
for (ny = 0; ny<YRES/CELL; ny++)
{
vx[ny][nx] = 0;
vy[ny][nx] = 0;
}
}
else if(strcmp(console3, "sparks")==0)
{
for(i=0; i<NPART; i++)
{
if(parts[i].type==PT_SPRK)
{
parts[i].type = parts[i].ctype;
parts[i].life = 4;
}
}
}
else if(strcmp(console3, "temp")==0)
{
for(i=0; i<NPART; i++)
{
if(parts[i].type)
{
parts[i].temp = ptypes[parts[i].type].heat;
}
}
}
}
else if(strcmp(console2, "set")==0 && console3 && console4 && console5)
{
if(strcmp(console3, "life")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].life = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].life = j;
}
}
}
if(strcmp(console3, "type")==0)
{
if(strcmp(console4, "all")==0)
{
j = console_get_type(console5);
if (j<0)
sprintf(error, "Particle type not recognised", console2);
else
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].type = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = console_get_type(console5);
if (j<0)
sprintf(error, "Particle type not recognised", console2);
else
parts[i].type = j;
}
}
}
if(strcmp(console3, "temp")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].temp = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].temp = j;
}
}
}
if(strcmp(console3, "tmp")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].tmp = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].tmp = j;
}
}
}
if(strcmp(console3, "x")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].x = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].x = j;
}
}
}
if(strcmp(console3, "y")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].y = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].y = j;
}
}
}
if(strcmp(console3, "ctype")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].ctype = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].ctype = j;
}
}
}
if(strcmp(console3, "vx")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].vx = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].vx = j;
}
}
}
if(strcmp(console3, "vy")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].vy = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].vy = j;
}
}
}
}
else
sprintf(error, "Invalid Command", console2);
}
free(console); free(console);
if(!console_mode) if(!console_mode)
hud_enable = 1; hud_enable = 1;
@ -2766,4 +2503,313 @@ int main(int argc, char *argv[])
http_done(); http_done();
return 0; return 0;
} }
int process_command(pixel *vid_buf,char *console,char *console_error) { //TODO: delete with coords, have 'set' work with coords as well
int nx,ny,i,j;
char *console2;
char *console3;
char *console4;
char *console5;
//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, " ");
if(strcmp(console2, "quit")==0)
{
return 0;
}
else if(strcmp(console2, "file")==0 && console3)
{
FILE *f=fopen(console3, "r");
if(f)
{
char fileread[5000];//TODO: make this change with file size
char pch[5000];
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);
memset(pch,0,sizeof(pch));
j = i+1;
}
}
//sprintf(console_error, "%s exists", console3);
fclose(f);
}
else
sprintf(console_error, "%s does not exist", console3);
}
else if(strcmp(console2, "load")==0 && console3)
{
j = atoi(console3);
if(j)
{
open_ui(vid_buf, console3, NULL);
console_mode = 0;
}
}
else if(strcmp(console2, "create")==0 && console3 && console4 && console5)
{
j = console_get_type(console3);
if (j<0)
sprintf(console_error, "Particle type not recognised", console2);
nx = atoi(console4);
ny = atoi(console5);
if(ny < 0 || nx < 0 || ny > YRES || nx > XRES)
sprintf(console_error, "Invalid Coordinates", console2);
else
create_part(-1,nx,ny,j);
}
else if(strcmp(console2, "reset")==0 && console3)
{
if(strcmp(console3, "pressure")==0)
{
for (nx = 0; nx<XRES/CELL; nx++)
for (ny = 0; ny<YRES/CELL; ny++)
{
pv[ny][nx] = 0;
}
}
else if(strcmp(console3, "velocity")==0)
{
for (nx = 0; nx<XRES/CELL; nx++)
for (ny = 0; ny<YRES/CELL; ny++)
{
vx[ny][nx] = 0;
vy[ny][nx] = 0;
}
}
else if(strcmp(console3, "sparks")==0)
{
for(i=0; i<NPART; i++)
{
if(parts[i].type==PT_SPRK)
{
parts[i].type = parts[i].ctype;
parts[i].life = 4;
}
}
}
else if(strcmp(console3, "temp")==0)
{
for(i=0; i<NPART; i++)
{
if(parts[i].type)
{
parts[i].temp = ptypes[parts[i].type].heat;
}
}
}
}
else if(strcmp(console2, "set")==0 && console3 && console4 && console5)
{
if(strcmp(console3, "life")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].life = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].life = j;
}
}
}
if(strcmp(console3, "type")==0)
{
if(strcmp(console4, "all")==0)
{
j = console_get_type(console5);
if (j<0)
sprintf(console_error, "Particle type not recognised", console2);
else
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].type = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = console_get_type(console5);
if (j<0)
sprintf(console_error, "Particle type not recognised", console2);
else
parts[i].type = j;
}
}
}
if(strcmp(console3, "temp")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].temp = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].temp = j;
}
}
}
if(strcmp(console3, "tmp")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].tmp = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].tmp = j;
}
}
}
if(strcmp(console3, "x")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].x = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].x = j;
}
}
}
if(strcmp(console3, "y")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].y = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].y = j;
}
}
}
if(strcmp(console3, "ctype")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].ctype = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].ctype = j;
}
}
}
if(strcmp(console3, "vx")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].vx = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].vx = j;
}
}
}
if(strcmp(console3, "vy")==0)
{
if(strcmp(console4, "all")==0)
{
j = atoi(console5);
for(i=0; i<NPART; i++)
{
if(parts[i].type)
parts[i].vy = j;
}
}
else
{
i = atoi(console4);
if(parts[i].type)
{
j = atoi(console5);
parts[i].vy = j;
}
}
}
}
else
sprintf(console_error, "Invalid Command", console2);
}
return 1;
}