@@ -588,6 +588,7 @@ void LuaScriptInterface::initSimulationAPI()
588
588
{" can_move" , simulation_canMove},
589
589
{" parts" , simulation_parts},
590
590
{" pmap" , simulation_pmap},
591
+ {" photons" , simulation_photons},
591
592
{" neighbours" , simulation_neighbours},
592
593
{" neighbors" , simulation_neighbours},
593
594
{NULL , NULL }
@@ -676,7 +677,9 @@ int LuaScriptInterface::simulation_partNeighbours(lua_State * l)
676
677
if (x+rx >= 0 && y+ry >= 0 && x+rx < XRES && y+ry < YRES && (rx || ry))
677
678
{
678
679
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)
680
683
{
681
684
lua_pushinteger (l, n>>8 );
682
685
lua_rawseti (l, -2 , id++);
@@ -691,7 +694,9 @@ int LuaScriptInterface::simulation_partNeighbours(lua_State * l)
691
694
if (x+rx >= 0 && y+ry >= 0 && x+rx < XRES && y+ry < YRES && (rx || ry))
692
695
{
693
696
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)
695
700
{
696
701
lua_pushinteger (l, n>>8 );
697
702
lua_rawseti (l, -2 , id++);
@@ -1056,11 +1061,11 @@ int LuaScriptInterface::simulation_gravMap(lua_State* l)
1056
1061
if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES)
1057
1062
return luaL_error (l, " coordinates out of range (%d,%d)" , x, y);
1058
1063
1059
- /* if (argCount == 2)
1064
+ if (argCount == 2 )
1060
1065
{
1061
- lua_pushnumber(l, luacon_sim->gravmap [y*XRES/CELL+x]);
1066
+ lua_pushnumber (l, luacon_sim->gravp [y*XRES/CELL+x]);
1062
1067
return 1 ;
1063
- }*/
1068
+ }
1064
1069
int width = 1 , height = 1 ;
1065
1070
float value;
1066
1071
luaL_checktype (l, 3 , LUA_TNUMBER);
@@ -1697,18 +1702,29 @@ int LuaScriptInterface::simulation_parts(lua_State * l)
1697
1702
1698
1703
int LuaScriptInterface::simulation_pmap (lua_State * l)
1699
1704
{
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)
1704
1708
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 ))
1707
1711
return 0 ;
1708
1712
lua_pushnumber (l, r>>8 );
1709
1713
return 1 ;
1710
1714
}
1711
1715
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
+ }
1712
1728
1713
1729
int NeighboursClosure (lua_State * l)
1714
1730
{
@@ -1734,6 +1750,8 @@ int NeighboursClosure(lua_State * l)
1734
1750
continue ;
1735
1751
}
1736
1752
i=luacon_sim->pmap [y+sy][x+sx];
1753
+ if (!i)
1754
+ i=luacon_sim->photons [y+sy][x+sx];
1737
1755
} while (!(i&0xFF ));
1738
1756
lua_pushnumber (l, x);
1739
1757
lua_replace (l, lua_upvalueindex (5 ));
0 commit comments