summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacksonmj <jacksonmj@jacksonmj.none>2011-01-31 14:05:05 (GMT)
committer jacksonmj <jacksonmj@jacksonmj.none>2011-01-31 14:05:05 (GMT)
commit363a3e38f1c5f7be91a060bbc33595d1c3ee9de4 (patch)
tree0b68f87d8ee2946f1c24c6eefcd285e95f7a8d36 /src
parentcdd7399cc1c009838970ab5dce60c5ad4c332d46 (diff)
parent3babc0586c9b8a0de12962a2cc89c93ea3c7f02f (diff)
downloadpowder-363a3e38f1c5f7be91a060bbc33595d1c3ee9de4.zip
powder-363a3e38f1c5f7be91a060bbc33595d1c3ee9de4.tar.gz
Merge branch 'cracker64' into dev
Conflicts: src/interface.c src/main.c
Diffstat (limited to 'src')
-rw-r--r--src/interface.c14
-rw-r--r--src/main.c586
2 files changed, 325 insertions, 275 deletions
diff --git a/src/interface.c b/src/interface.c
index 221f2d5..af607c1 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -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?
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"
- "Current commands are quit, set, reset, load\n"
+ drawtext(vid_buf, 100, 15, "Welcome to The Powder Toy console v.2 (by cracker64)\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 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"
- "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);
cc = 0;
@@ -3937,9 +3940,10 @@ int console_get_type(char *element)
return i;
if (strcasecmp(element,"C4")==0) return PT_PLEX;
if (strcasecmp(element,"C5")==0) return PT_C5;
+ if (strcasecmp(element,"NONE")==0) return PT_NONE;
for (i=0; i<PT_NUM; i++) {
if (strcasecmp(element,ptypes[i].name)==0)
return i;
}
return -1;
-}
+} \ No newline at end of file
diff --git a/src/main.c b/src/main.c
index ea3ba71..f3dfe07 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1121,7 +1121,7 @@ int main(int argc, char *argv[])
pixel *pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
void *http_ver_check;
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;
#ifdef INTERNAL
int vs = 0;
@@ -1698,279 +1698,16 @@ int main(int argc, char *argv[])
}
if(console_mode)
{
- int nx,ny;
char *console;
- char *console2;
- char *console3;
- char *console4;
- char *console5;
//char error[255] = "error!";
sys_pause = 1;
- console = console_ui(vid_buf,error);
+ console = console_ui(vid_buf,console_error);
console = mystrdup(console);
- strcpy(error,"");
- 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)
- {
- free(console);
- 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);
+ strcpy(console_error,"");
+ if(process_command(vid_buf,console,&console_error)==0)
+ {
+ free(console);
+ break;
}
free(console);
if(!console_mode)
@@ -2766,4 +2503,313 @@ int main(int argc, char *argv[])
http_done();
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;
+}