@@ -266,9 +266,9 @@ struct work_hook : df::building_workshopst{
266266 }
267267 INTERPOSE_NEXT (updateAction)();
268268 }
269- DEFINE_VMETHOD_INTERPOSE (void , drawBuilding, (int32_t unk1 ,df::building_drawbuffer *db, int16_t unk2 ))
269+ DEFINE_VMETHOD_INTERPOSE (void , drawBuilding, (uint32_t curtick ,df::building_drawbuffer *db, int16_t z_offset ))
270270 {
271- INTERPOSE_NEXT (drawBuilding)(unk1 ,db, unk2 );
271+ INTERPOSE_NEXT (drawBuilding)(curtick ,db, z_offset );
272272
273273 if (auto def = find_def ())
274274 {
@@ -291,12 +291,11 @@ struct work_hook : df::building_workshopst{
291291 }
292292 }
293293 }
294- int w=db->x2 -db->x1 +1 ;
295294 std::vector<graphic_tile> &cur_frame=def->frames [frame];
296295 for (size_t i=0 ;i<cur_frame.size ();i++)
297296 {
298- int tx = i % w ;
299- int ty = i / w ;
297+ int tx = i % 31 ;
298+ int ty = i / 31 ;
300299 const auto & cf = cur_frame[i];
301300 if (cf.tile >=0 )
302301 {
@@ -305,14 +304,14 @@ struct work_hook : df::building_workshopst{
305304 db->bright [tx][ty]= cf.bright ;
306305 db->fore [tx][ty]= cf.fore ;
307306 }
308- if (cf.graphics_tile >= 0 )
307+ if (cf.graphics_tile != - 1 )
309308 db->building_one_texpos [tx][ty] = cf.graphics_tile ;
310- if (cf.overlay_tile >= 0 )
309+ if (cf.overlay_tile != - 1 )
311310 db->building_two_texpos [tx][ty] = cf.overlay_tile ;
312- if (cf.item_tile >= 0 )
311+ if (cf.item_tile != - 1 )
313312 db->item_texpos [tx][ty] = cf.item_tile ;
314313 // only first line has signpost graphics
315- if (cf.item_tile >= 0 && ty==0 )
314+ if (cf.item_tile != - 1 && ty==0 )
316315 db->signpost_texpos [tx] = cf.signpost_tile ;
317316 }
318317 }
@@ -342,24 +341,26 @@ static void loadFrames(lua_State* L,workshop_hack_data& def,int stack_pos)
342341 const int max_idx = 31 * 31 ;
343342
344343 luaL_checktype (L,stack_pos,LUA_TTABLE);
345- lua_pushvalue (L,stack_pos);
346- lua_pushnil (L);
347- while (lua_next (L, -2 ) != 0 ) {
348- luaL_checktype (L,-1 ,LUA_TTABLE);
344+
345+ int frame_index = 1 ;
346+
347+ while (lua_geti (L,stack_pos,frame_index) != LUA_TNIL) { // get frame[i]
348+ luaL_checktype (L,-1 ,LUA_TTABLE); // ensure that it's a table
349349 std::vector<graphic_tile> frame (max_idx);
350350
351351 for (int idx = 0 ; idx < max_idx; idx++)
352352 {
353353 auto & t = frame[idx];
354- lua_geti (L, -1 , idx);
355- // allow sparse indexing
356- if (lua_isnil (L, -1 ))
354+ lua_geti (L, -1 , idx); // get tile at idx i.e. frame[i][idx] where idx=x+y*31
355+
356+ if (lua_isnil (L, -1 ))// allow sparse indexing
357357 {
358- lua_pop (L, 1 );
358+ lua_pop (L, 1 ); // pop current tile (nil in this case)
359359 continue ;
360360 }
361361 else
362362 {
363+ // load up tile, color, optionally graphics stuff
363364 lua_geti (L, -1 , 1 );
364365 // not sure why would anyone do nil tile, but for api consitency lets allow it
365366 t.tile = luaL_optinteger (L,-1 ,-1 );
@@ -392,13 +393,16 @@ static void loadFrames(lua_State* L,workshop_hack_data& def,int stack_pos)
392393 lua_geti (L, -1 , 8 );
393394 t.item_tile = luaL_optinteger (L, -1 , -1 );
394395 lua_pop (L, 1 );
396+
397+ lua_pop (L, 1 ); // pop current tile
395398 }
396399 frame.push_back (t);
397- lua_pop (L,1 );
398400 }
399401 def.frames .push_back (frame);
402+ frame_index++;
403+ lua_pop (L, 1 ); // pop current frame
400404 }
401- lua_pop (L, 1 );
405+
402406 return ;
403407}
404408// arguments: custom type,impassible fix (bool), consumed power, produced power, list of connection points, update skip(0/nil to disable)
0 commit comments