static PyObject* emb_set_ctype(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; char *type = ""; char *kwlist[] = {"setto", "settoint", "setfrom", "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) 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++) { if (parts[i].type) parts[i].ctype = life; } } else if (console_parse_type(name, &j, console_error)) { for (i=0; i<NPART; i++) { if (parts[i].type == j) 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); }
static PyObject* emb_create(PyObject *self, PyObject *args, PyObject *keywds) { int 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)); }
int luatpt_create(lua_State* l) { int x, y, retid, t = 0; char * name; x = abs(luaL_optint(l, 1, 0)); y = abs(luaL_optint(l, 2, 0)); if(x < XRES && y < YRES){ if(lua_isnumber(l, 3)){ t = luaL_optint(l, 3, 0); if(t >= PT_NUM) return -1; } else { name = luaL_optstring(l, 3, "dust"); if (name[0]!=0) console_parse_type(name, &t, console_error); } retid = create_part(-1, x, y, t); if(retid==-1) return -1; lua_pushinteger(l, retid); return 1; } return -1; }
int luatpt_set_property(lua_State* l) { char *prop, *name; int i, x, y, w, h, t, format, nx, ny, partsel = 0, acount; float f; size_t offset; acount = lua_gettop(l); prop = luaL_optstring(l, 1, ""); if(lua_isnumber(l, 3)) i = luaL_optint(l, 3, -1); else i = -1; if(lua_isnumber(l, 4)) y = luaL_optint(l, 4, -1); else y = -1; if(lua_isnumber(l, 5)) w = luaL_optint(l, 5, -1); else w = -1; if(lua_isnumber(l, 6)) h = luaL_optint(l, 6, -1); else h = -1; if (strcmp(prop,"type")==0){ offset = offsetof(particle, type); format = 3; } else if (strcmp(prop,"life")==0){ offset = offsetof(particle, life); format = 1; } else if (strcmp(prop,"ctype")==0){ offset = offsetof(particle, ctype); format = 3; } else if (strcmp(prop,"temp")==0){ offset = offsetof(particle, temp); format = 2; } else if (strcmp(prop,"tmp")==0){ offset = offsetof(particle, tmp); format = 1; } else if (strcmp(prop,"vy")==0){ offset = offsetof(particle, vy); format = 2; } else if (strcmp(prop,"vx")==0){ offset = offsetof(particle, vx); format = 2; } else if (strcmp(prop,"x")==0){ offset = offsetof(particle, x); format = 2; } else if (strcmp(prop,"y")==0){ offset = offsetof(particle, y); format = 2; } else { lua_pushstring(l, "invalid property"); lua_error(l); } if(acount>2){ if(!lua_isnumber(l, acount) && lua_isstring(l, acount)){ name = luaL_optstring(l, acount, "none"); if (name[0]!=0) console_parse_type(name, &partsel, console_error); } } if(lua_isnumber(l, 2)){ if(format==2){ f = luaL_optnumber(l, 2, 0); } else { t = luaL_optint(l, 2, 0); } if(t >= PT_NUM && format == 3) return -1; } else { name = luaL_optstring(l, 2, "dust"); if (name[0]!=0) console_parse_type(name, &t, console_error); } if(i == -1 || (w != -1 && h != -1)){ // Got a region if(i == -1){ i = 0; y = 0; w = XRES; h = YRES; } x = i; for (nx = x; nx<x+w; nx++) for (ny = y; ny<y+h; ny++){ i = pmap[ny][nx]>>8; if (i < 0 || i >= NPART || (partsel && partsel != parts[i].type)) continue; if(format==2){ *((float*)(((void*)&parts[i])+offset)) = f; } else { *((int*)(((void*)&parts[i])+offset)) = t; } } } else { // Got coords or particle index if(i != -1 && y != -1){