1414#include " gravity.h"
1515#include " powdergraphics.h"
1616
17+ #include " game/Brush.h"
1718#include " game/Menus.h"
1819#include " simulation/Simulation.h"
20+ #include " simulation/WallNumbers.h"
21+ #include " simulation/Tool.h"
1922
2023/*
2124
@@ -39,6 +42,15 @@ void initSimulationAPI(lua_State * l)
3942 {" velocityX" , simulation_velocityX},
4043 {" velocityY" , simulation_velocityY},
4144 {" gravMap" , simulation_gravMap},
45+ {" createParts" , simulation_createParts},
46+ {" createLine" , simulation_createLine},
47+ {" createBox" , simulation_createBox},
48+ {" floodParts" , simulation_floodParts},
49+ {" createWalls" , simulation_createWalls},
50+ {" createWallLine" , simulation_createWallLine},
51+ {" createWallBox" , simulation_createWallBox},
52+ {" floodWalls" , simulation_floodWalls},
53+ {" clearSim" , simulation_clearSim},
4254 {" elementCount" , simulation_elementCount},
4355 {NULL , NULL }
4456 };
@@ -356,6 +368,136 @@ int simulation_gravMap(lua_State* l)
356368 return 0 ;
357369}
358370
371+ int simulation_createParts (lua_State * l)
372+ {
373+ int x = luaL_optint (l,1 ,-1 );
374+ int y = luaL_optint (l,2 ,-1 );
375+ int rx = luaL_optint (l,3 ,5 );
376+ int ry = luaL_optint (l,4 ,5 );
377+ int c = luaL_optint (l,5 ,((ElementTool*)activeTools[0 ])->GetID ());
378+ int brush = luaL_optint (l,6 ,CIRCLE_BRUSH), oldBrush = currentBrush->GetShape ();
379+ int flags = luaL_optint (l,7 ,get_brush_flags ());
380+ if (brush < 0 || brush >= BRUSH_NUM)
381+ return luaL_error (l, " Invalid brush id '%d'" , brush);
382+
383+ currentBrush->SetShape (brush);
384+ int ret = globalSim->CreateParts (x, y, rx, ry, c, flags, true );
385+ currentBrush->SetShape (oldBrush);
386+ lua_pushinteger (l, ret);
387+ return 1 ;
388+ }
389+
390+ int simulation_createLine (lua_State * l)
391+ {
392+ int x1 = luaL_optint (l,1 ,-1 );
393+ int y1 = luaL_optint (l,2 ,-1 );
394+ int x2 = luaL_optint (l,3 ,-1 );
395+ int y2 = luaL_optint (l,4 ,-1 );
396+ int rx = luaL_optint (l,5 ,5 );
397+ int ry = luaL_optint (l,6 ,5 );
398+ int c = luaL_optint (l,7 ,((ElementTool*)activeTools[0 ])->GetID ());
399+ int brush = luaL_optint (l,8 ,CIRCLE_BRUSH), oldBrush = currentBrush->GetShape ();
400+ int flags = luaL_optint (l,9 ,get_brush_flags ());
401+ if (brush < 0 || brush >= BRUSH_NUM)
402+ return luaL_error (l, " Invalid brush id '%d'" , brush);
403+
404+ currentBrush->SetShape (brush);
405+ globalSim->CreateLine (x1, y1, x2, y2, rx, ry, c, flags);
406+ currentBrush->SetShape (oldBrush);
407+ return 0 ;
408+ }
409+
410+ int simulation_createBox (lua_State * l)
411+ {
412+ int x1 = luaL_optint (l,1 ,-1 );
413+ int y1 = luaL_optint (l,2 ,-1 );
414+ int x2 = luaL_optint (l,3 ,-1 );
415+ int y2 = luaL_optint (l,4 ,-1 );
416+ int c = luaL_optint (l,5 ,((ElementTool*)activeTools[0 ])->GetID ());
417+ int flags = luaL_optint (l,6 ,get_brush_flags ());
418+
419+ globalSim->CreateBox (x1, y1, x2, y2, c, flags);
420+ return 0 ;
421+ }
422+
423+ int simulation_floodParts (lua_State * l)
424+ {
425+ int x = luaL_optint (l,1 ,-1 );
426+ int y = luaL_optint (l,2 ,-1 );
427+ int c = luaL_optint (l,3 ,((ElementTool*)activeTools[0 ])->GetID ());
428+ int cm = luaL_optint (l,4 ,-1 );
429+ int flags = luaL_optint (l,5 ,get_brush_flags ());
430+
431+ int ret = globalSim->FloodParts (x, y, c, cm, flags);
432+ lua_pushinteger (l, ret);
433+ return 1 ;
434+ }
435+
436+ int simulation_createWalls (lua_State * l)
437+ {
438+ int x = luaL_optint (l,1 ,-1 )/CELL;
439+ int y = luaL_optint (l,2 ,-1 )/CELL;
440+ int rx = luaL_optint (l,3 ,0 )/CELL;
441+ int ry = luaL_optint (l,4 ,0 )/CELL;
442+ int c = luaL_optint (l,5 ,WL_WALL);
443+ if (c < 0 || c >= WALLCOUNT)
444+ return luaL_error (l, " Unrecognised wall id '%d'" , c);
445+
446+ globalSim->CreateWallBox (x-rx, y-ry, x+rx, y+ry, c);
447+ lua_pushinteger (l, 1 );
448+ return 1 ;
449+ }
450+
451+ int simulation_createWallLine (lua_State * l)
452+ {
453+ int x1 = luaL_optint (l,1 ,-1 )/CELL;
454+ int y1 = luaL_optint (l,2 ,-1 )/CELL;
455+ int x2 = luaL_optint (l,3 ,-1 )/CELL;
456+ int y2 = luaL_optint (l,4 ,-1 )/CELL;
457+ int rx = luaL_optint (l,5 ,0 )/CELL;
458+ int ry = luaL_optint (l,6 ,0 )/CELL;
459+ int c = luaL_optint (l,7 ,WL_WALL);
460+ if (c < 0 || c >= WALLCOUNT)
461+ return luaL_error (l, " Unrecognised wall id '%d'" , c);
462+
463+ globalSim->CreateWallLine (x1-rx, y1-rx, x2-rx, y2-rx, rx*2 , ry*2 , c);
464+ return 0 ;
465+ }
466+
467+ int simulation_createWallBox (lua_State * l)
468+ {
469+ int x1 = luaL_optint (l,1 ,-1 )/CELL;
470+ int y1 = luaL_optint (l,2 ,-1 )/CELL;
471+ int x2 = luaL_optint (l,3 ,-1 )/CELL;
472+ int y2 = luaL_optint (l,4 ,-1 )/CELL;
473+ int c = luaL_optint (l,5 ,WL_WALL);
474+ if (c < 0 || c >= WALLCOUNT)
475+ return luaL_error (l, " Unrecognised wall id '%d'" , c);
476+
477+ globalSim->CreateWallBox (x1, y1, x2, y2, c);
478+ return 0 ;
479+ }
480+
481+ int simulation_floodWalls (lua_State * l)
482+ {
483+ int x = luaL_optint (l,1 ,-1 )/CELL;
484+ int y = luaL_optint (l,2 ,-1 )/CELL;
485+ int c = luaL_optint (l,3 ,WL_WALL);
486+ int bm = luaL_optint (l,4 ,-1 );
487+ if (c < 0 || c >= WALLCOUNT)
488+ return luaL_error (l, " Unrecognised wall id '%d'" , c);
489+
490+ int ret = globalSim->FloodWalls (x, y, c, bm);
491+ lua_pushinteger (l, ret);
492+ return 1 ;
493+ }
494+
495+ int simulation_clearSim (lua_State * l)
496+ {
497+ clear_sim ();
498+ return 0 ;
499+ }
500+
359501int simulation_elementCount (lua_State* l)
360502{
361503 int element = luaL_checkint (l, 1 );
0 commit comments