Skip to content

Commit cce32ed

Browse files
committed
tpt++: add sim.photons (like sim.pmap but for photons), sim.(part)neighbors also checks photons, fix sim.gravMap 7582acf
1 parent cfbe490 commit cce32ed

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

includes/luascriptinterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ int simulation_elementCount(lua_State* l);
6262
int simulation_canMove(lua_State * l);
6363
int simulation_parts(lua_State * l);
6464
int simulation_pmap(lua_State * l);
65+
int simulation_photons(lua_State * l);
6566
int simulation_neighbours(lua_State * l);
6667
int simulation_stickman(lua_State * l);
6768

src/luascriptinterface.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ void initSimulationAPI(lua_State * l)
208208
{"can_move", simulation_canMove},
209209
{"parts", simulation_parts},
210210
{"pmap", simulation_pmap},
211+
{"photons", simulation_photons},
211212
{"neighbors", simulation_neighbours},
212213
{"neighbours", simulation_neighbours},
213214
{"stickman", simulation_stickman},
@@ -288,7 +289,9 @@ int simulation_partNeighbours(lua_State * l)
288289
if (x+rx >= 0 && y+ry >= 0 && x+rx < XRES && y+ry < YRES && (rx || ry))
289290
{
290291
n = pmap[y+ry][x+rx];
291-
if(n && (n&0xFF) == t)
292+
if (!n || (n&0xFF) != t)
293+
n = photons[y+ry][x+rx];
294+
if (n && (n&0xFF) == t)
292295
{
293296
lua_pushinteger(l, n>>8);
294297
lua_rawseti(l, -2, id++);
@@ -303,7 +306,9 @@ int simulation_partNeighbours(lua_State * l)
303306
if (x+rx >= 0 && y+ry >= 0 && x+rx < XRES && y+ry < YRES && (rx || ry))
304307
{
305308
n = pmap[y+ry][x+rx];
306-
if(n)
309+
if (!n)
310+
n = photons[y+ry][x+rx];
311+
if (n)
307312
{
308313
lua_pushinteger(l, n>>8);
309314
lua_rawseti(l, -2, id++);
@@ -629,11 +634,11 @@ int simulation_gravMap(lua_State* l)
629634
if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES)
630635
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
631636

632-
/*if (argCount == 2)
637+
if (argCount == 2)
633638
{
634-
lua_pushnumber(l, gravmap[y*XRES/CELL+x]);
639+
lua_pushnumber(l, gravp[y*XRES/CELL+x]);
635640
return 1;
636-
}*/
641+
}
637642
luaL_checktype(l, 3, LUA_TNUMBER);
638643
if (argCount == 3)
639644
value = (float)lua_tonumber(l, 3);
@@ -1268,7 +1273,7 @@ int simulation_pmap(lua_State * l)
12681273
{
12691274
int x = luaL_checkint(l, 1);
12701275
int y = luaL_checkint(l, 2);
1271-
if(x < 0 || x >= XRES || y < 0 || y >= YRES)
1276+
if (x < 0 || x >= XRES || y < 0 || y >= YRES)
12721277
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
12731278
int r = pmap[y][x];
12741279
if (!(r&0xFF))
@@ -1277,6 +1282,18 @@ int simulation_pmap(lua_State * l)
12771282
return 1;
12781283
}
12791284

1285+
int simulation_photons(lua_State * l)
1286+
{
1287+
int x = luaL_checkint(l, 1);
1288+
int y = luaL_checkint(l, 2);
1289+
if (x < 0 || x >= XRES || y < 0 || y >= YRES)
1290+
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
1291+
int r = photons[y][x];
1292+
if (!(r&0xFF))
1293+
return 0;
1294+
lua_pushnumber(l, r>>8);
1295+
return 1;
1296+
}
12801297

12811298
int NeighboursClosure(lua_State * l)
12821299
{
@@ -1297,12 +1314,15 @@ int NeighboursClosure(lua_State * l)
12971314
if (y > ry)
12981315
return 0;
12991316
}
1300-
if(!(x || y) || sx+x<0 || sy+y<0 || sx+x>=XRES*CELL || sy+y>=YRES*CELL)
1317+
if (!(x || y) || sx+x<0 || sy+y<0 || sx+x>=XRES*CELL || sy+y>=YRES*CELL)
13011318
{
13021319
continue;
13031320
}
13041321
i = pmap[y+sy][x+sx];
1305-
} while (!(i&0xFF));
1322+
if (!i)
1323+
i = photons[y+sy][x+sx];
1324+
}
1325+
while (!(i&0xFF));
13061326
lua_pushnumber(l, x);
13071327
lua_replace(l, lua_upvalueindex(5));
13081328
lua_pushnumber(l, y);

0 commit comments

Comments
 (0)