Skip to content

Commit 7582acf

Browse files
committed
add sim.photons (like sim.pmap but for photons), sim.(part)neighbors also checks photons, fix sim.gravMap
1 parent 12f00db commit 7582acf

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/lua/LuaScriptInterface.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ void LuaScriptInterface::initSimulationAPI()
588588
{"can_move", simulation_canMove},
589589
{"parts", simulation_parts},
590590
{"pmap", simulation_pmap},
591+
{"photons", simulation_photons},
591592
{"neighbours", simulation_neighbours},
592593
{"neighbors", simulation_neighbours},
593594
{NULL, NULL}
@@ -676,7 +677,9 @@ int LuaScriptInterface::simulation_partNeighbours(lua_State * l)
676677
if (x+rx >= 0 && y+ry >= 0 && x+rx < XRES && y+ry < YRES && (rx || ry))
677678
{
678679
n = luacon_sim->pmap[y+ry][x+rx];
679-
if(n && (n&0xFF) == t)
680+
if (!n || (n&0xFF) != t)
681+
n = luacon_sim->photons[y+ry][x+rx];
682+
if (n && (n&0xFF) == t)
680683
{
681684
lua_pushinteger(l, n>>8);
682685
lua_rawseti(l, -2, id++);
@@ -691,7 +694,9 @@ int LuaScriptInterface::simulation_partNeighbours(lua_State * l)
691694
if (x+rx >= 0 && y+ry >= 0 && x+rx < XRES && y+ry < YRES && (rx || ry))
692695
{
693696
n = luacon_sim->pmap[y+ry][x+rx];
694-
if(n)
697+
if (!n)
698+
n = luacon_sim->photons[y+ry][x+rx];
699+
if (n)
695700
{
696701
lua_pushinteger(l, n>>8);
697702
lua_rawseti(l, -2, id++);
@@ -1056,11 +1061,11 @@ int LuaScriptInterface::simulation_gravMap(lua_State* l)
10561061
if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES)
10571062
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
10581063

1059-
/*if (argCount == 2)
1064+
if (argCount == 2)
10601065
{
1061-
lua_pushnumber(l, luacon_sim->gravmap[y*XRES/CELL+x]);
1066+
lua_pushnumber(l, luacon_sim->gravp[y*XRES/CELL+x]);
10621067
return 1;
1063-
}*/
1068+
}
10641069
int width = 1, height = 1;
10651070
float value;
10661071
luaL_checktype(l, 3, LUA_TNUMBER);
@@ -1697,18 +1702,29 @@ int LuaScriptInterface::simulation_parts(lua_State * l)
16971702

16981703
int LuaScriptInterface::simulation_pmap(lua_State * l)
16991704
{
1700-
int x=luaL_checkint(l, 1);
1701-
int y=luaL_checkint(l, 2);
1702-
int r;
1703-
if(x < 0 || x >= XRES || y < 0 || y >= YRES)
1705+
int x = luaL_checkint(l, 1);
1706+
int y = luaL_checkint(l, 2);
1707+
if (x < 0 || x >= XRES || y < 0 || y >= YRES)
17041708
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
1705-
r=luacon_sim->pmap[y][x];
1706-
if(!(r&0xFF))
1709+
int r = luacon_sim->pmap[y][x];
1710+
if (!(r&0xFF))
17071711
return 0;
17081712
lua_pushnumber(l, r>>8);
17091713
return 1;
17101714
}
17111715

1716+
int LuaScriptInterface::simulation_photons(lua_State * l)
1717+
{
1718+
int x = luaL_checkint(l, 1);
1719+
int y = luaL_checkint(l, 2);
1720+
if (x < 0 || x >= XRES || y < 0 || y >= YRES)
1721+
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
1722+
int r = luacon_sim->photons[y][x];
1723+
if (!(r&0xFF))
1724+
return 0;
1725+
lua_pushnumber(l, r>>8);
1726+
return 1;
1727+
}
17121728

17131729
int NeighboursClosure(lua_State * l)
17141730
{
@@ -1734,6 +1750,8 @@ int NeighboursClosure(lua_State * l)
17341750
continue;
17351751
}
17361752
i=luacon_sim->pmap[y+sy][x+sx];
1753+
if(!i)
1754+
i=luacon_sim->photons[y+sy][x+sx];
17371755
} while(!(i&0xFF));
17381756
lua_pushnumber(l, x);
17391757
lua_replace(l, lua_upvalueindex(5));

src/lua/LuaScriptInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class LuaScriptInterface: public CommandInterface
9797
static int simulation_canMove(lua_State * l);
9898
static int simulation_parts(lua_State * l);
9999
static int simulation_pmap(lua_State * l);
100+
static int simulation_photons(lua_State * l);
100101
static int simulation_neighbours(lua_State * l);
101102

102103
//Renderer

0 commit comments

Comments
 (0)