a get_pmap and get_prop function for python so fancier scripts can be made. Made a demo of increasing element type by one, import example, example.increment()

This commit is contained in:
Cracker64 2011-03-02 23:30:04 -05:00
parent 673f6d0f9b
commit 9e8b7440ba
3 changed files with 73 additions and 8 deletions

View File

@ -8,3 +8,16 @@ def noise(typ,amount=50):
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)

View File

@ -3858,12 +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));
@ -3945,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)
@ -3987,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;
}

View File

@ -1193,12 +1193,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
@ -1384,14 +1388,14 @@ emb_set_life(PyObject *self, PyObject *args, PyObject *keywds)
emb_set_type(PyObject *self, PyObject *args, PyObject *keywds)
{
int i = -1,life,j,x=-1,y=-1;
int i = -1,life,j=-1,x=-1,y=-1;
char *name = "";
char *type = "";
char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
if(!PyArg_ParseTupleAndKeywords(args, keywds, "s|sIII:set_type",kwlist ,&type,&name,&i,&x,&y))
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(strcmp(name,"")==0 && x==-1 && y==-1 && i==-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)
@ -1707,9 +1711,51 @@ emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds)
}
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."},
{"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."},
@ -1731,6 +1777,8 @@ static PyMethodDef EmbMethods[] = { //WARNING! don't forget to register your fun
{"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}
};