MCPcopy Create free account
hub / github.com/DFHack/dfhack / addBuilding

Function addBuilding

plugins/building-hacks.cpp:372–417  ·  view source on GitHub ↗

arguments: custom type,impassible fix (bool), consumed power, produced power, list of connection points, update skip(0/nil to disable) table of frames,frame to tick ratio (-1 for machine control)

Source from the content-addressed store, hash-verified

370//arguments: custom type,impassible fix (bool), consumed power, produced power, list of connection points, update skip(0/nil to disable)
371// table of frames,frame to tick ratio (-1 for machine control)
372static int addBuilding(lua_State* L)
373{
374 workshop_hack_data newDefinition;
375 newDefinition.myType=luaL_checkint(L,1);
376 newDefinition.impassible_fix=luaL_checkint(L,2);
377 newDefinition.powerInfo.consumed=luaL_checkint(L,3);
378 newDefinition.powerInfo.produced=luaL_checkint(L,4);
379 newDefinition.needs_power = luaL_optinteger(L, 5, 1);
380 //table of machine connection points
381 luaL_checktype(L,6,LUA_TTABLE);
382 lua_pushvalue(L,6);
383 lua_pushnil(L);
384 while (lua_next(L, -2) != 0) {
385 lua_getfield(L,-1,"x");
386 int x=lua_tonumber(L,-1);
387 lua_pop(L,1);
388 lua_getfield(L,-1,"y");
389 int y=lua_tonumber(L,-1);
390 lua_pop(L,1);
391
392 df::machine_conn_modes modes;
393 modes.whole = -1;
394 newDefinition.connections.can_connect.push_back(modes);//TODO add this too...
395 newDefinition.connections.tiles.push_back(df::coord(x,y,0));
396
397 lua_pop(L,1);
398 }
399 lua_pop(L,1);
400 //updates
401 newDefinition.skip_updates=luaL_optinteger(L,7,0);
402 //animation
403 if(!lua_isnil(L,8))
404 {
405 loadFrames(L,newDefinition,8);
406 newDefinition.frame_skip=luaL_optinteger(L,9,-1);
407 if(newDefinition.frame_skip==0)
408 newDefinition.frame_skip=1;
409 if(newDefinition.frame_skip<0)
410 newDefinition.machine_timing=true;
411 else
412 newDefinition.machine_timing=false;
413 }
414 newDefinition.room_subset=luaL_optinteger(L,10,-1);
415 hacked_workshops[newDefinition.myType]=newDefinition;
416 return 0;
417}
418static void setPower(df::building_workshopst* workshop, int power_produced, int power_consumed)
419{
420 work_hook* ptr = static_cast<work_hook*>(workshop);

Callers

nothing calls this directly

Calls 7

luaL_optintegerFunction · 0.85
luaL_checktypeFunction · 0.85
lua_pushvalueFunction · 0.85
lua_pushnilFunction · 0.85
lua_nextFunction · 0.85
lua_getfieldFunction · 0.85
loadFramesFunction · 0.85

Tested by

no test coverage detected