| 2326 | } |
| 2327 | |
| 2328 | static int units_getUnitsInBox(lua_State *state) { |
| 2329 | vector<df::unit *> units; |
| 2330 | cuboid box; |
| 2331 | |
| 2332 | int max_arg = lua_gettop(state); |
| 2333 | if (max_arg > 3) { |
| 2334 | int x1 = luaL_checkint(state, 1); |
| 2335 | int y1 = luaL_checkint(state, 2); |
| 2336 | int z1 = luaL_checkint(state, 3); |
| 2337 | int x2 = luaL_checkint(state, 4); |
| 2338 | int y2 = luaL_checkint(state, 5); |
| 2339 | int z2 = luaL_checkint(state, 6); |
| 2340 | box = cuboid(x1,y1,z1,x2,y2,z2); |
| 2341 | } |
| 2342 | else { |
| 2343 | df::coord pos1, pos2; |
| 2344 | Lua::CheckDFAssign(state, &pos1, 1); |
| 2345 | Lua::CheckDFAssign(state, &pos2, 2); |
| 2346 | box = cuboid(pos1, pos2); |
| 2347 | } |
| 2348 | |
| 2349 | int fn_arg = max_arg > 3 ? 7 : 3; |
| 2350 | bool ok = false; |
| 2351 | if (max_arg < fn_arg || lua_isnil(state, fn_arg)) // Default filter |
| 2352 | ok = Units::getUnitsInBox(units, box); |
| 2353 | else { |
| 2354 | luaL_checktype(state, fn_arg, LUA_TFUNCTION); |
| 2355 | if (max_arg > fn_arg) // Something after filter on stack |
| 2356 | luaL_argerror(state, fn_arg+1, "too many arguments!"); |
| 2357 | |
| 2358 | ok = Units::getUnitsInBox(units, box, [&state](df::unit *unit) { |
| 2359 | lua_dup(state); // Copy function |
| 2360 | Lua::PushDFObject(state, unit); |
| 2361 | lua_call(state, 1, 1); |
| 2362 | bool ret = lua_toboolean(state, -1); |
| 2363 | lua_pop(state, 1); // Remove return value |
| 2364 | return ret; |
| 2365 | }); |
| 2366 | } |
| 2367 | |
| 2368 | Lua::PushVector(state, units); |
| 2369 | lua_pushboolean(state, ok); |
| 2370 | return 2; |
| 2371 | } |
| 2372 | |
| 2373 | static int units_getCitizens(lua_State *L) { |
| 2374 | bool exclude_residents = lua_toboolean(L, 1); // defaults to false |
nothing calls this directly
no test coverage detected