pulled some code by cracker which makes output even more awesome :P
This commit is contained in:
commit
9f8811159c
@ -4,7 +4,20 @@ import time
|
||||
# example script
|
||||
|
||||
def noise(typ,amount=50):
|
||||
for xx in range(284,316):
|
||||
for yy in range(184,216):
|
||||
for xx in range(4,612):
|
||||
for yy in range(4,384):
|
||||
if(random.randrange(0,100)<amount):
|
||||
tpt.create(xx,yy,typ)
|
||||
|
||||
def increment(amount=1):
|
||||
for xx in range(4,612):
|
||||
for yy in range(4,384):
|
||||
i = tpt.get_pmap(xx,yy)>>8
|
||||
t = tpt.get_prop(i,"type")+amount
|
||||
if t>=148:
|
||||
t=t-148
|
||||
if t==128:
|
||||
t=129
|
||||
if t==55:
|
||||
t=56
|
||||
tpt.set_type(i=i,settoint=t)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import tpt
|
||||
from tpt import *
|
||||
import sys
|
||||
import code
|
||||
import ctypes
|
||||
@ -8,10 +9,11 @@ print "console module loaded."
|
||||
#redirect stdout like this:
|
||||
class logger:
|
||||
def write(self,txt):
|
||||
txt=txt.split("\n")[-1][:254]
|
||||
txt=txt.strip().split("\n")[-1]
|
||||
repr(txt)
|
||||
tpt.log(txt)
|
||||
#sys.stdout=logger()
|
||||
#sys.stderr=logger()
|
||||
sys.stdout=logger()
|
||||
sys.stderr=logger()
|
||||
|
||||
element={"none":0,"dust":1,"watr":2,"oil":3,"fire":4,"stne":5,"lava":6,"gunp":7,
|
||||
"nitr":8,"clne":9,"gas":10,"plex":11,"goo":12,"icei":13,"metl":14,"sprk":15,
|
||||
@ -95,12 +97,9 @@ def handle(txt):
|
||||
def _handle(txt):
|
||||
#print "handling '%s'"%txt
|
||||
try:
|
||||
sys.stdout.write(repr(eval(tmp,handle.glob)))
|
||||
sys.stdout.write(repr(eval(txt,handle.glob)))
|
||||
except:
|
||||
try:
|
||||
exec txt in handle.glob
|
||||
except Exception as ex:
|
||||
error(ex)
|
||||
|
||||
|
||||
|
@ -2,37 +2,36 @@
|
||||
the console in this version is a python console and will execute any command you enter.
|
||||
the api for interacting with the powder toy is contained in the tpt module and is already imported at startup.
|
||||
currently implemented api functions:
|
||||
tpt.create(x,y,type) create a particle of type <type> at <x>,<y>
|
||||
tpt.reset_velocity() resets all velocity
|
||||
tpt.reset_pressure() resets all pressure
|
||||
tpt.reset_sparks() resets all sparks
|
||||
tpt.set_life(type,life) sets the life of all particles with type <type>
|
||||
to <life>(set <type> to -1 for all)
|
||||
tpt.set_type(type1,type2) sets the type of all particles with type <type1>
|
||||
to <type2>(set <type1> to -1 for all)
|
||||
tpt.set_temp(type,temp) sets the temp of all particles with type <type>
|
||||
to <temp>(set <type> to -1 for all)
|
||||
tpt.set_tmp(type,tmp) sets the tmp of all particles with type <type>
|
||||
to <tmp>(set <type> to -1 for all)
|
||||
tpt.set_x(type,x) sets the x of all particles with type <type>
|
||||
to <x>(set <type> to -1 for all)
|
||||
tpt.set_y(type,y) sets the y of all particles with type <type>
|
||||
to <y>(set <type> to -1 for all)
|
||||
tpt.set_vx(type,vx) sets the vx of all particles with type <type>
|
||||
to <vx>(set <type> to -1 for all)
|
||||
tpt.set_vy(type,vy) sets the vy of all particles with type <type>
|
||||
to <vy>(set <type> to -1 for all)
|
||||
tpt.set_ctype(type,ctype) sets the ctype of all particles with type
|
||||
<type> to <ctype>(set <type> to -1 for all)
|
||||
tpt.pause() pause the game(note that closing the console
|
||||
create(x,y,type) create a particle of type <type> at <x>,<y>
|
||||
reset_velocity() resets all velocity
|
||||
reset_pressure() resets all pressure
|
||||
reset_sparks() resets all sparks
|
||||
|
||||
### USING SET COMMANDS ###
|
||||
the console uses keywords to identify variables of what to set, you can specify x and y coords with x=100 y=100, ect.
|
||||
i is the particle number
|
||||
name will change all of name's type to the setto variable. It needs to be a string "dust" ect, "all" for all.
|
||||
the setto is what the particle(s) will be set to, it is a string for the type/ctype commands, and an int for the rest.
|
||||
you need to set the to* variable and one location/name/coords for it to work.
|
||||
set_type(x=,y=,i=,name="",setto="")
|
||||
set_life()
|
||||
set_temp()
|
||||
set_tmp()
|
||||
set_x()
|
||||
set_y()
|
||||
set_vx()
|
||||
set_vy()
|
||||
set_ctype()
|
||||
|
||||
pause() pause the game(note that closing the console
|
||||
pauses the game)
|
||||
tpt.unpause() unpause the game(note that closing the console
|
||||
unpause() unpause the game(note that closing the console
|
||||
pauses the game)
|
||||
tpt.toggle_pause() toggle pause(note that closing the console
|
||||
toggle_pause() toggle pause(note that closing the console
|
||||
pauses the game)
|
||||
tpt.close_console() closes the console and pauses the game
|
||||
tpt.open_console() opens the console
|
||||
tpt.toggle_console() toggles the console
|
||||
close_console() closes the console and pauses the game
|
||||
open_console() opens the console
|
||||
toggle_console() toggles the console
|
||||
|
||||
NOTE: these functions don't do bounds checking, which means that they CAN AND
|
||||
WILL CRASH the powder toy. be carefull.
|
||||
|
@ -3839,10 +3839,12 @@ struct command_history {
|
||||
};
|
||||
typedef struct command_history command_history;
|
||||
command_history *last_command = NULL;
|
||||
command_history *last_command2 = NULL;
|
||||
char *console_ui(pixel *vid_buf,char error[255],char console_more) {
|
||||
int mx,my,b,cc,ci = -1;
|
||||
pixel *old_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
|
||||
command_history *currentcommand;
|
||||
command_history *currentcommand2;
|
||||
ui_edit ed;
|
||||
ed.x = 15;
|
||||
ed.y = 207;
|
||||
@ -3856,7 +3858,13 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
|
||||
ed.cursor = 0;
|
||||
//fillrect(vid_buf, -1, -1, XRES, 220, 0, 0, 0, 190);
|
||||
memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE);
|
||||
fillrect(old_buf, -1, -1, XRES, 220, 0, 0, 0, 190);
|
||||
fillrect(old_buf, -1, -1, XRES+1, 220, 0, 0, 0, 190);
|
||||
currentcommand2 = malloc(sizeof(command_history));
|
||||
memset(currentcommand2, 0, sizeof(command_history));
|
||||
currentcommand2->prev_command = last_command2;
|
||||
currentcommand2->command = mystrdup(error);
|
||||
last_command2 = currentcommand2;
|
||||
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
cc = 0;
|
||||
while(cc < 80){
|
||||
fillrect(old_buf, -1, -1+cc, XRES+BARSIZE, 2, 0, 0, 0, 160-(cc*2));
|
||||
@ -3869,6 +3877,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
|
||||
my /= sdl_scale;
|
||||
ed.focus = 1;
|
||||
|
||||
//clearrect(vid_buf, 0, 0, XRES+BARSIZE, 220);//anyway to make it transparent?
|
||||
memcpy(vid_buf,old_buf,(XRES+BARSIZE)*YRES*PIXELSIZE);
|
||||
draw_line(vid_buf, 0, 219, XRES+BARSIZE-1, 219, 228, 228, 228, XRES+BARSIZE);
|
||||
drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.3 (by cracker64, python by Doxin)" //TODO: help command
|
||||
@ -3896,9 +3905,31 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
cc = 0;
|
||||
currentcommand2 = last_command2;
|
||||
while(cc < 10)
|
||||
{
|
||||
if(currentcommand2==NULL)
|
||||
break;
|
||||
drawtext(vid_buf, 215, 175-(cc*12), currentcommand2->command, 255, 225, 225, 255);
|
||||
if(currentcommand2->prev_command!=NULL)
|
||||
{
|
||||
if(cc<9) {
|
||||
currentcommand2 = currentcommand2->prev_command;
|
||||
} else if(currentcommand2->prev_command!=NULL) {
|
||||
free(currentcommand2->prev_command);
|
||||
currentcommand2->prev_command = NULL;
|
||||
}
|
||||
cc++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(error && ed.str[0]=='\0')
|
||||
drawtext(vid_buf, 20, 207, error, 255, 127, 127, 200);
|
||||
//if(error && ed.str[0]=='\0')
|
||||
//drawtext(vid_buf, 20, 207, error, 255, 127, 127, 200);
|
||||
if(console_more==0)
|
||||
drawtext(vid_buf, 5, 207, ">", 255, 255, 255, 240);
|
||||
else
|
||||
@ -3915,12 +3946,14 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
|
||||
currentcommand->command = mystrdup(ed.str);
|
||||
last_command = currentcommand;
|
||||
free(old_buf);
|
||||
SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
return currentcommand->command;
|
||||
}
|
||||
if (sdl_key==SDLK_ESCAPE || sdl_key==SDLK_BACKQUOTE)
|
||||
{
|
||||
console_mode = 0;
|
||||
free(old_buf);
|
||||
SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
return NULL;
|
||||
}
|
||||
if(sdl_key==SDLK_UP || sdl_key==SDLK_DOWN)
|
||||
@ -3957,6 +3990,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
|
||||
}
|
||||
console_mode = 0;
|
||||
free(old_buf);
|
||||
SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
331
src/main.c
331
src/main.c
@ -1189,12 +1189,16 @@ char console_error[255] = "";
|
||||
|
||||
//functions callable from python:
|
||||
static PyObject*
|
||||
emb_create(PyObject *self, PyObject *args)
|
||||
emb_create(PyObject *self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
int x,y,t;
|
||||
if(!PyArg_ParseTuple(args, "III:create",&x,&y,&t))
|
||||
char *name = "";
|
||||
char *kwlist[] = {"x","y","t","name", NULL};
|
||||
if(!PyArg_ParseTupleAndKeywords(args, keywds, "II|Is:create",kwlist, &x,&y,&t,&name))
|
||||
return NULL;
|
||||
//
|
||||
if(strcmp(name,"")!=0)
|
||||
console_parse_type(name, &t, console_error);
|
||||
return Py_BuildValue("i",create_part(-1,x,y,t));
|
||||
}
|
||||
//sys_pause = !sys_pause
|
||||
@ -1338,13 +1342,17 @@ emb_reset_sparks(PyObject *self, PyObject *args)
|
||||
return Py_BuildValue("i",1);
|
||||
}
|
||||
|
||||
emb_set_life(PyObject *self, PyObject *args)
|
||||
emb_set_life(PyObject *self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
int i,life,j;
|
||||
if(!PyArg_ParseTuple(args, "II:set_life",&j,&life))
|
||||
int i = -1,life,j,x=-1,y=-1;
|
||||
char *name = "";
|
||||
char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
|
||||
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
|
||||
return NULL;
|
||||
//
|
||||
if(j==-1)
|
||||
if(strcmp(name,"")==0 && x==-1 && y==-1 && i==-1)
|
||||
return Py_BuildValue("s","Need more args(coords,i,or a particle name)");
|
||||
if(strcmp(name,"all")==0)
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1352,7 +1360,7 @@ emb_set_life(PyObject *self, PyObject *args)
|
||||
parts[i].life = life;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(console_parse_type(name, &j, console_error))
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1360,16 +1368,33 @@ emb_set_life(PyObject *self, PyObject *args)
|
||||
parts[i].life = life;
|
||||
}
|
||||
}
|
||||
else if(i!=-1)
|
||||
{
|
||||
if(parts[i].type != PT_NONE)
|
||||
parts[i].life = life;
|
||||
|
||||
}
|
||||
else if(x!=-1 && y!=-1 && x>=0 && x<XRES && y>=0 && y<YRES)
|
||||
{
|
||||
if(parts[pmap[y][x]>>8].type != PT_NONE)
|
||||
parts[pmap[y][x]>>8].life = life;
|
||||
}
|
||||
return Py_BuildValue("i",1);
|
||||
}
|
||||
|
||||
emb_set_type(PyObject *self, PyObject *args)
|
||||
emb_set_type(PyObject *self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
int i,life,j;
|
||||
if(!PyArg_ParseTuple(args, "II:set_type",&j,&life))
|
||||
int i = -1,life,j=-1,x=-1,y=-1;
|
||||
char *name = "";
|
||||
char *type = "";
|
||||
char *kwlist[] = {"setto", "settoint", "from", "i", "x", "y", NULL};
|
||||
if(!PyArg_ParseTupleAndKeywords(args, keywds, "|sIsIII:set_type",kwlist ,&type,&life,&name,&i,&x,&y))
|
||||
return NULL;
|
||||
//
|
||||
if(j==-1)
|
||||
if(strcmp(name,"")==0 && x==-1 && y==-1 && i==-1 && j==-1)
|
||||
return Py_BuildValue("s","Need more args(coords,i,or a particle name)");
|
||||
console_parse_type(type, &life, console_error);
|
||||
if(strcmp(name,"all")==0)
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1377,7 +1402,7 @@ emb_set_type(PyObject *self, PyObject *args)
|
||||
parts[i].type = life;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(console_parse_type(name, &j, console_error))
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1385,16 +1410,31 @@ emb_set_type(PyObject *self, PyObject *args)
|
||||
parts[i].type = life;
|
||||
}
|
||||
}
|
||||
else if(i!=-1)
|
||||
{
|
||||
if(parts[i].type != PT_NONE)
|
||||
parts[i].type = life;
|
||||
|
||||
}
|
||||
else if(x!=-1 && y!=-1 && x>=0 && x<XRES && y>=0 && y<YRES)
|
||||
{
|
||||
if(parts[pmap[y][x]>>8].type != PT_NONE)
|
||||
parts[pmap[y][x]>>8].type = life;
|
||||
}
|
||||
return Py_BuildValue("i",1);
|
||||
}
|
||||
|
||||
emb_set_temp(PyObject *self, PyObject *args)
|
||||
emb_set_temp(PyObject *self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
int i,life,j;
|
||||
if(!PyArg_ParseTuple(args, "II:set_temp",&j,&life))
|
||||
int i = -1,life,j,x=-1,y=-1;
|
||||
char *name = "";
|
||||
char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
|
||||
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
|
||||
return NULL;
|
||||
//
|
||||
if(j==-1)
|
||||
if(strcmp(name,"")==0 && x==-1 && y==-1 && i==-1)
|
||||
return Py_BuildValue("s","Need more args(coords,i,or a particle name)");
|
||||
if(strcmp(name,"all")==0)
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1402,7 +1442,7 @@ emb_set_temp(PyObject *self, PyObject *args)
|
||||
parts[i].temp = life;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(console_parse_type(name, &j, console_error))
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1410,16 +1450,31 @@ emb_set_temp(PyObject *self, PyObject *args)
|
||||
parts[i].temp = life;
|
||||
}
|
||||
}
|
||||
else if(i!=-1)
|
||||
{
|
||||
if(parts[i].type != PT_NONE)
|
||||
parts[i].temp = life;
|
||||
|
||||
}
|
||||
else if(x!=-1 && y!=-1 && x>=0 && x<XRES && y>=0 && y<YRES)
|
||||
{
|
||||
if(parts[pmap[y][x]>>8].type != PT_NONE)
|
||||
parts[pmap[y][x]>>8].temp = life;
|
||||
}
|
||||
return Py_BuildValue("i",1);
|
||||
}
|
||||
|
||||
emb_set_tmp(PyObject *self, PyObject *args)
|
||||
emb_set_tmp(PyObject *self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
int i,life,j;
|
||||
if(!PyArg_ParseTuple(args, "II:set_tmp",&j,&life))
|
||||
int i = -1,life,j,x=-1,y=-1;
|
||||
char *name = "";
|
||||
char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
|
||||
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
|
||||
return NULL;
|
||||
//
|
||||
if(j==-1)
|
||||
if(strcmp(name,"")==0 && x==-1 && y==-1 && i==-1)
|
||||
return Py_BuildValue("s","Need more args(coords,i,or a particle name)");
|
||||
if(strcmp(name,"all")==0)
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1427,7 +1482,7 @@ emb_set_tmp(PyObject *self, PyObject *args)
|
||||
parts[i].tmp = life;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(console_parse_type(name, &j, console_error))
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1435,16 +1490,32 @@ emb_set_tmp(PyObject *self, PyObject *args)
|
||||
parts[i].tmp = life;
|
||||
}
|
||||
}
|
||||
else if(i!=-1)
|
||||
{
|
||||
if(parts[i].type != PT_NONE)
|
||||
parts[i].tmp = life;
|
||||
|
||||
}
|
||||
else if(x!=-1 && y!=-1 && x>=0 && x<XRES && y>=0 && y<YRES)
|
||||
{
|
||||
if(parts[pmap[y][x]>>8].type != PT_NONE)
|
||||
parts[pmap[y][x]>>8].tmp = life;
|
||||
}
|
||||
return Py_BuildValue("i",1);
|
||||
}
|
||||
|
||||
emb_set_x(PyObject *self, PyObject *args)
|
||||
emb_set_x(PyObject *self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
int i,life,j;
|
||||
if(!PyArg_ParseTuple(args, "II:set_x",&j,&life))
|
||||
int i = -1,life,j,x=-1,y=-1;
|
||||
char *name = "";
|
||||
char *type = "";
|
||||
char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
|
||||
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
|
||||
return NULL;
|
||||
//
|
||||
if(j==-1)
|
||||
if(strcmp(name,"")==0 && x==-1 && y==-1 && i==-1)
|
||||
return Py_BuildValue("s","Need more args(coords,i,or a particle name)");
|
||||
if(strcmp(name,"all")==0)
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1452,7 +1523,7 @@ emb_set_x(PyObject *self, PyObject *args)
|
||||
parts[i].x = life;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(console_parse_type(name, &j, console_error))
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1460,16 +1531,31 @@ emb_set_x(PyObject *self, PyObject *args)
|
||||
parts[i].x = life;
|
||||
}
|
||||
}
|
||||
else if(i!=-1)
|
||||
{
|
||||
if(parts[i].type != PT_NONE)
|
||||
parts[i].x = life;
|
||||
|
||||
}
|
||||
else if(x!=-1 && y!=-1 && x>=0 && x<XRES && y>=0 && y<YRES)
|
||||
{
|
||||
if(parts[pmap[y][x]>>8].type != PT_NONE)
|
||||
parts[pmap[y][x]>>8].x = life;
|
||||
}
|
||||
return Py_BuildValue("i",1);
|
||||
}
|
||||
|
||||
emb_set_y(PyObject *self, PyObject *args)
|
||||
emb_set_y(PyObject *self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
int i,life,j;
|
||||
if(!PyArg_ParseTuple(args, "II:set_y",&j,&life))
|
||||
int i = -1,life,j,x=-1,y=-1;
|
||||
char *name = "";
|
||||
char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
|
||||
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
|
||||
return NULL;
|
||||
//
|
||||
if(j==-1)
|
||||
if(strcmp(name,"")==0 && x==-1 && y==-1 && i==-1)
|
||||
return Py_BuildValue("s","Need more args(coords,i,or a particle name)");
|
||||
if(strcmp(name,"all")==0)
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1477,7 +1563,7 @@ emb_set_y(PyObject *self, PyObject *args)
|
||||
parts[i].y = life;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(console_parse_type(name, &j, console_error))
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1485,16 +1571,34 @@ emb_set_y(PyObject *self, PyObject *args)
|
||||
parts[i].y = life;
|
||||
}
|
||||
}
|
||||
else if(i!=-1)
|
||||
{
|
||||
if(parts[i].type != PT_NONE)
|
||||
parts[i].y = life;
|
||||
|
||||
}
|
||||
else if(x!=-1 && y!=-1 && x>=0 && x<XRES && y>=0 && y<YRES)
|
||||
{
|
||||
if(parts[pmap[y][x]>>8].type != PT_NONE)
|
||||
parts[pmap[y][x]>>8].y = life;
|
||||
}
|
||||
return Py_BuildValue("i",1);
|
||||
}
|
||||
|
||||
emb_set_ctype(PyObject *self, PyObject *args)
|
||||
emb_set_ctype(PyObject *self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
int i,life,j;
|
||||
if(!PyArg_ParseTuple(args, "II:set_ctype",&j,&life))
|
||||
int i = -1,life,j,x=-1,y=-1;
|
||||
char *name = "";
|
||||
char *type = "";
|
||||
char *kwlist[] = {"setto", "toctypeint", "from", "i", "x", "y", NULL};
|
||||
if(!PyArg_ParseTupleAndKeywords(args, keywds, "s|IsIII:set_type",kwlist ,&type, &life, &name,&i,&x,&y))
|
||||
return NULL;
|
||||
//
|
||||
if(j==-1)
|
||||
if(strcmp(name,"")==0 && x==-1 && y==-1 && i==-1)
|
||||
return Py_BuildValue("s","Need more args(coords,i,or a particle name)");
|
||||
if(!life)
|
||||
console_parse_type(type, &life, console_error);
|
||||
if(strcmp(name,"all")==0)
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1502,7 +1606,7 @@ emb_set_ctype(PyObject *self, PyObject *args)
|
||||
parts[i].ctype = life;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(console_parse_type(name, &j, console_error))
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1510,16 +1614,31 @@ emb_set_ctype(PyObject *self, PyObject *args)
|
||||
parts[i].ctype = life;
|
||||
}
|
||||
}
|
||||
else if(i!=-1)
|
||||
{
|
||||
if(parts[i].type != PT_NONE)
|
||||
parts[i].ctype = life;
|
||||
|
||||
}
|
||||
else if(x!=-1 && y!=-1 && x>=0 && x<XRES && y>=0 && y<YRES)
|
||||
{
|
||||
if(parts[pmap[y][x]>>8].type != PT_NONE)
|
||||
parts[pmap[y][x]>>8].ctype = life;
|
||||
}
|
||||
return Py_BuildValue("i",1);
|
||||
}
|
||||
|
||||
emb_set_vx(PyObject *self, PyObject *args)
|
||||
emb_set_vx(PyObject *self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
int i,life,j;
|
||||
if(!PyArg_ParseTuple(args, "II:set_vx",&j,&life))
|
||||
int i = -1,life,j,x=-1,y=-1;
|
||||
char *name = "";
|
||||
char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
|
||||
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
|
||||
return NULL;
|
||||
//
|
||||
if(j==-1)
|
||||
if(strcmp(name,"")==0 && x==-1 && y==-1 && i==-1)
|
||||
return Py_BuildValue("s","Need more args(coords,i,or a particle name)");
|
||||
if(strcmp(name,"all")==0)
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1527,7 +1646,7 @@ emb_set_vx(PyObject *self, PyObject *args)
|
||||
parts[i].vx = life;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(console_parse_type(name, &j, console_error))
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1535,16 +1654,31 @@ emb_set_vx(PyObject *self, PyObject *args)
|
||||
parts[i].vx = life;
|
||||
}
|
||||
}
|
||||
else if(i!=-1)
|
||||
{
|
||||
if(parts[i].type != PT_NONE)
|
||||
parts[i].vx = life;
|
||||
|
||||
}
|
||||
else if(x!=-1 && y!=-1 && x>=0 && x<XRES && y>=0 && y<YRES)
|
||||
{
|
||||
if(parts[pmap[y][x]>>8].type != PT_NONE)
|
||||
parts[pmap[y][x]>>8].vx = life;
|
||||
}
|
||||
return Py_BuildValue("i",1);
|
||||
}
|
||||
|
||||
emb_set_vy(PyObject *self, PyObject *args)
|
||||
emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
int i,life,j;
|
||||
if(!PyArg_ParseTuple(args, "II:set_vy",&j,&life))
|
||||
int i = -1,life,j,x=-1,y=-1;
|
||||
char *name = "";
|
||||
char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
|
||||
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
|
||||
return NULL;
|
||||
//
|
||||
if(j==-1)
|
||||
if(strcmp(name,"")==0 && x==-1 && y==-1 && i==-1)
|
||||
return Py_BuildValue("s","Need more args(coords,i,or a particle name)");
|
||||
if(strcmp(name,"all")==0)
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1552,7 +1686,7 @@ emb_set_vy(PyObject *self, PyObject *args)
|
||||
parts[i].vy = life;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(console_parse_type(name, &j, console_error))
|
||||
{
|
||||
for(i=0; i<NPART; i++)
|
||||
{
|
||||
@ -1560,32 +1694,87 @@ emb_set_vy(PyObject *self, PyObject *args)
|
||||
parts[i].vy = life;
|
||||
}
|
||||
}
|
||||
else if(i!=-1)
|
||||
{
|
||||
if(parts[i].type != PT_NONE)
|
||||
parts[i].vy = life;
|
||||
|
||||
}
|
||||
else if(x!=-1 && y!=-1 && x>=0 && x<XRES && y>=0 && y<YRES)
|
||||
{
|
||||
if(parts[pmap[y][x]>>8].type != PT_NONE)
|
||||
parts[pmap[y][x]>>8].vy = life;
|
||||
}
|
||||
return Py_BuildValue("i",1);
|
||||
}
|
||||
emb_get_pmap(PyObject *self, PyObject *args)
|
||||
{
|
||||
int x,y;
|
||||
if(!PyArg_ParseTuple(args, "II:get_pmap",&x,&y))
|
||||
return NULL;
|
||||
//
|
||||
if(x<0 || y<0 || x>=XRES || y>=YRES)
|
||||
return Py_BuildValue("i",-1);
|
||||
|
||||
return Py_BuildValue("I",pmap[y][x]);
|
||||
}
|
||||
emb_get_prop(PyObject *self, PyObject *args)
|
||||
{
|
||||
int i;
|
||||
char *prop = "";
|
||||
if(!PyArg_ParseTuple(args, "Is:get_pmap",&i,&prop))
|
||||
return NULL;
|
||||
//
|
||||
if(parts[i].type)
|
||||
{
|
||||
if(strcmp(prop,"type")==0)
|
||||
return Py_BuildValue("i",parts[i].type);
|
||||
if(strcmp(prop,"life")==0)
|
||||
return Py_BuildValue("i",parts[i].life);
|
||||
if(strcmp(prop,"ctype")==0)
|
||||
return Py_BuildValue("i",parts[i].ctype);
|
||||
if(strcmp(prop,"temp")==0)
|
||||
return Py_BuildValue("i",parts[i].temp);
|
||||
if(strcmp(prop,"tmp")==0)
|
||||
return Py_BuildValue("i",parts[i].tmp);
|
||||
if(strcmp(prop,"vy")==0)
|
||||
return Py_BuildValue("f",parts[i].vy);
|
||||
if(strcmp(prop,"vx")==0)
|
||||
return Py_BuildValue("f",parts[i].vx);
|
||||
if(strcmp(prop,"x")==0)
|
||||
return Py_BuildValue("i",parts[i].x);
|
||||
if(strcmp(prop,"y")==0)
|
||||
return Py_BuildValue("i",parts[i].y);
|
||||
}
|
||||
|
||||
return Py_BuildValue("i",-1);
|
||||
}
|
||||
|
||||
static PyMethodDef EmbMethods[] = { //WARNING! don't forget to register your function here!
|
||||
{"create", emb_create, METH_VARARGS,"create a particle."},
|
||||
{"log", emb_log, METH_VARARGS,"logs an error string to the console."},
|
||||
{"reset_pressure", emb_reset_pressure, METH_VARARGS,"resets all the pressure."},
|
||||
{"reset_velocity", emb_reset_velocity, METH_VARARGS,"resets all the velocity."},
|
||||
{"reset_sparks", emb_reset_sparks, METH_VARARGS,"resets all the sparks."},
|
||||
{"set_life", emb_set_life, METH_VARARGS,"sets life of a specified particle."},
|
||||
{"set_type", emb_set_type, METH_VARARGS,"sets type of a specified particle."},
|
||||
{"set_temp", emb_set_temp, METH_VARARGS,"sets temp of a specified particle."},
|
||||
{"set_tmp", emb_set_tmp, METH_VARARGS,"sets tmp of a specified particle."},
|
||||
{"set_x", emb_set_x, METH_VARARGS,"sets x of a specified particle."},
|
||||
{"set_y", emb_set_y, METH_VARARGS,"sets y of a specified particle."},
|
||||
{"set_ctype", emb_set_y, METH_VARARGS,"sets ctype of a specified particle."},
|
||||
{"set_vx", emb_set_vx, METH_VARARGS,"sets vx of a specified particle."},
|
||||
{"set_vy", emb_set_vy, METH_VARARGS,"sets vy of a specified particle."},
|
||||
{"pause", emb_pause, METH_VARARGS,"pause the game."},
|
||||
{"unpause", emb_unpause, METH_VARARGS,"unpause the game."},
|
||||
{"toggle_pause", emb_toggle_pause, METH_VARARGS,"toggle game pause."},
|
||||
{"open_console", emb_open_console, METH_VARARGS,"open the game console."},
|
||||
{"close_console", emb_close_console, METH_VARARGS,"close the game console."},
|
||||
{"toggle_console", emb_toggle_console, METH_VARARGS,"toggle the game console."},
|
||||
{"console_more", emb_console_more, METH_VARARGS,"turns the more indicator on."},
|
||||
{"console_less", emb_console_less, METH_VARARGS,"turns the more indicator off."},
|
||||
{"create", emb_create, METH_VARARGS|METH_KEYWORDS, "create a particle."},
|
||||
{"log", emb_log, METH_VARARGS, "logs an error string to the console."},
|
||||
{"reset_pressure", emb_reset_pressure, METH_VARARGS, "resets all the pressure."},
|
||||
{"reset_velocity", emb_reset_velocity, METH_VARARGS, "resets all the velocity."},
|
||||
{"reset_sparks", emb_reset_sparks, METH_VARARGS, "resets all the sparks."},
|
||||
{"set_life", emb_set_life, METH_VARARGS|METH_KEYWORDS, "sets life of a specified particle."},
|
||||
{"set_type", emb_set_type, METH_VARARGS|METH_KEYWORDS, "sets type of a specified particle."},
|
||||
{"set_temp", emb_set_temp, METH_VARARGS|METH_KEYWORDS, "sets temp of a specified particle."},
|
||||
{"set_tmp", emb_set_tmp, METH_VARARGS|METH_KEYWORDS, "sets tmp of a specified particle."},
|
||||
{"set_x", emb_set_x, METH_VARARGS|METH_KEYWORDS, "sets x of a specified particle."},
|
||||
{"set_y", emb_set_y, METH_VARARGS|METH_KEYWORDS, "sets y of a specified particle."},
|
||||
{"set_ctype", emb_set_y, METH_VARARGS|METH_KEYWORDS, "sets ctype of a specified particle."},
|
||||
{"set_vx", emb_set_vx, METH_VARARGS|METH_KEYWORDS, "sets vx of a specified particle."},
|
||||
{"set_vy", emb_set_vy, METH_VARARGS|METH_KEYWORDS, "sets vy of a specified particle."},
|
||||
{"pause", emb_pause, METH_VARARGS, "pause the game."},
|
||||
{"unpause", emb_unpause, METH_VARARGS, "unpause the game."},
|
||||
{"toggle_pause", emb_toggle_pause, METH_VARARGS, "toggle game pause."},
|
||||
{"open_console", emb_open_console, METH_VARARGS, "open the game console."},
|
||||
{"close_console", emb_close_console, METH_VARARGS, "close the game console."},
|
||||
{"toggle_console", emb_toggle_console, METH_VARARGS, "toggle the game console."},
|
||||
{"console_more", emb_console_more, METH_VARARGS, "turns the more indicator on."},
|
||||
{"console_less", emb_console_less, METH_VARARGS, "turns the more indicator off."},
|
||||
{"get_pmap", emb_get_pmap, METH_VARARGS, "get the pmap value."},
|
||||
{"get_prop", emb_get_prop, METH_VARARGS, "get some properties."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
@ -2885,9 +3074,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
create_line(lx, ly, x, y, bsx, bsy, c);
|
||||
}
|
||||
lx = x;
|
||||
ly = y;
|
||||
}
|
||||
@ -2912,7 +3099,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
if (sdl_mod & (KMOD_CAPS))
|
||||
c = 0;
|
||||
if (c!=WL_STREAM+100&&c!=SPC_AIR&&c!=SPC_HEAT&&c!=SPC_COOL&&c!=SPC_VACUUM&&c!=PT_WIND&&!REPLACE_MODE)
|
||||
if (c!=WL_STREAM+100&&c!=SPC_AIR&&c!=SPC_HEAT&&c!=SPC_COOL&&c!=SPC_VACUUM&&!REPLACE_MODE&&c!=PT_WIND)
|
||||
flood_parts(x, y, c, -1, -1);
|
||||
if (c==SPC_HEAT || c==SPC_COOL)
|
||||
create_parts(x, y, bsx, bsy, c);
|
||||
|
28
src/powder.c
28
src/powder.c
@ -79,6 +79,9 @@ int eval_move(int pt, int nx, int ny, unsigned *rr)
|
||||
if ((r&0xFF)==PT_VOID || (r&0xFF)==PT_BHOL)
|
||||
return 1;
|
||||
|
||||
if(pt==PT_SPRK)//spark shouldn't move
|
||||
return 0;
|
||||
|
||||
if (pt==PT_PHOT&&(
|
||||
(r&0xFF)==PT_GLAS || (r&0xFF)==PT_PHOT ||
|
||||
(r&0xFF)==PT_CLNE || (r&0xFF)==PT_PCLN ||
|
||||
@ -1135,7 +1138,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;
|
||||
int i, j, x, y, t, nx, ny, r, surround_space, s, lt, rt, nt, nnx, nny, q, golnum, goldelete, z, neighbors, createdsomething;
|
||||
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;
|
||||
@ -1342,14 +1345,14 @@ void update_particles_i(pixel *vid, int start, int inc)
|
||||
if(neighbors==0 || !(ptypes[r&0xFF].properties&PROP_LIFE || !r&0xFF) || (r>>8)>=NPART)
|
||||
continue;
|
||||
for ( golnum = 1; golnum<=NGOL; golnum++)
|
||||
for ( goldelete = 0; goldelete<9; goldelete++)
|
||||
{
|
||||
if (neighbors==goldelete&&gol[nx][ny]==0&&grule[golnum][goldelete]>=2&&gol2[nx][ny][golnum]>=(goldelete%2)+goldelete/2)
|
||||
goldelete = neighbors;
|
||||
if (gol[nx][ny]==0&&grule[golnum][goldelete]>=2&&gol2[nx][ny][golnum]>=(goldelete%2)+goldelete/2)
|
||||
{
|
||||
if (create_part(-1,nx,ny,goltype[golnum-1]))
|
||||
createdsomething = 1;
|
||||
}
|
||||
else if (neighbors-1==goldelete&&gol[nx][ny]==golnum&&(grule[golnum][goldelete]==0||grule[golnum][goldelete]==2))//subtract 1 because it counted itself
|
||||
else if (gol[nx][ny]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))//subtract 1 because it counted itself
|
||||
{
|
||||
if(parts[r>>8].tmp==grule[golnum][9]-1)
|
||||
parts[r>>8].tmp --;
|
||||
@ -2763,7 +2766,7 @@ int flood_parts(int x, int y, int c, int cm, int bm)
|
||||
bm = 0;
|
||||
}
|
||||
|
||||
if (((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm )||( (sdl_mod & (KMOD_CAPS)) && cm!=SLALT))
|
||||
if (((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm )||( (sdl_mod & (KMOD_CAPS)) && cm!=SLALT && !(cm==PT_INST&&co==PT_SPRK)))
|
||||
return 1;
|
||||
|
||||
// go left as far as possible
|
||||
@ -2788,7 +2791,12 @@ int flood_parts(int x, int y, int c, int cm, int bm)
|
||||
// fill span
|
||||
for (x=x1; x<=x2; x++)
|
||||
{
|
||||
if (!create_parts(x, y, 0, 0, co))
|
||||
if(cm==PT_INST&&co==PT_SPRK)
|
||||
{
|
||||
if(create_part(-1,x, y, co)==-1)
|
||||
return 0;
|
||||
}
|
||||
else if (!create_parts(x, y, 0, 0, co))
|
||||
return 0;
|
||||
}
|
||||
// fill children
|
||||
@ -2865,9 +2873,7 @@ int create_parts(int x, int y, int rx, int ry, int c)
|
||||
dw = 1;
|
||||
}
|
||||
if (c == PT_WIND)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (dw==1)
|
||||
{
|
||||
rx = rx/CELL;
|
||||
@ -2939,10 +2945,14 @@ int create_parts(int x, int y, int rx, int ry, int c)
|
||||
for (j=-ry; j<=ry; j++)
|
||||
for (i=-rx; i<=rx; i++)
|
||||
if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx))
|
||||
{
|
||||
if( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES)
|
||||
continue;
|
||||
if (!REPLACE_MODE)
|
||||
create_part(-2, x+i, y+j, c);
|
||||
else if ((pmap[y+j][x+i]&0xFF)==SLALT&&SLALT!=0)
|
||||
create_part(-2, x+i, y+j, c);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -2981,6 +2991,8 @@ int create_parts(int x, int y, int rx, int ry, int c)
|
||||
for (i=-rx; i<=rx; i++)
|
||||
if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx))
|
||||
{
|
||||
if( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES)
|
||||
continue;
|
||||
if ((pmap[y+j][x+i]&0xFF)!=SLALT&&SLALT!=0)
|
||||
continue;
|
||||
if ((pmap[y+j][x+i]))
|
||||
|
Reference in New Issue
Block a user