@@ -266,9 +266,9 @@ struct work_hook : df::building_workshopst{
266
266
}
267
267
INTERPOSE_NEXT (updateAction)();
268
268
}
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 ))
270
270
{
271
- INTERPOSE_NEXT (drawBuilding)(unk1 ,db, unk2 );
271
+ INTERPOSE_NEXT (drawBuilding)(curtick ,db, z_offset );
272
272
273
273
if (auto def = find_def ())
274
274
{
@@ -291,12 +291,11 @@ struct work_hook : df::building_workshopst{
291
291
}
292
292
}
293
293
}
294
- int w=db->x2 -db->x1 +1 ;
295
294
std::vector<graphic_tile> &cur_frame=def->frames [frame];
296
295
for (size_t i=0 ;i<cur_frame.size ();i++)
297
296
{
298
- int tx = i % w ;
299
- int ty = i / w ;
297
+ int tx = i % 31 ;
298
+ int ty = i / 31 ;
300
299
const auto & cf = cur_frame[i];
301
300
if (cf.tile >=0 )
302
301
{
@@ -305,14 +304,14 @@ struct work_hook : df::building_workshopst{
305
304
db->bright [tx][ty]= cf.bright ;
306
305
db->fore [tx][ty]= cf.fore ;
307
306
}
308
- if (cf.graphics_tile >= 0 )
307
+ if (cf.graphics_tile != - 1 )
309
308
db->building_one_texpos [tx][ty] = cf.graphics_tile ;
310
- if (cf.overlay_tile >= 0 )
309
+ if (cf.overlay_tile != - 1 )
311
310
db->building_two_texpos [tx][ty] = cf.overlay_tile ;
312
- if (cf.item_tile >= 0 )
311
+ if (cf.item_tile != - 1 )
313
312
db->item_texpos [tx][ty] = cf.item_tile ;
314
313
// only first line has signpost graphics
315
- if (cf.item_tile >= 0 && ty==0 )
314
+ if (cf.item_tile != - 1 && ty==0 )
316
315
db->signpost_texpos [tx] = cf.signpost_tile ;
317
316
}
318
317
}
@@ -342,24 +341,26 @@ static void loadFrames(lua_State* L,workshop_hack_data& def,int stack_pos)
342
341
const int max_idx = 31 * 31 ;
343
342
344
343
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
349
349
std::vector<graphic_tile> frame (max_idx);
350
350
351
351
for (int idx = 0 ; idx < max_idx; idx++)
352
352
{
353
353
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
357
357
{
358
- lua_pop (L, 1 );
358
+ lua_pop (L, 1 ); // pop current tile (nil in this case)
359
359
continue ;
360
360
}
361
361
else
362
362
{
363
+ // load up tile, color, optionally graphics stuff
363
364
lua_geti (L, -1 , 1 );
364
365
// not sure why would anyone do nil tile, but for api consitency lets allow it
365
366
t.tile = luaL_optinteger (L,-1 ,-1 );
@@ -392,13 +393,16 @@ static void loadFrames(lua_State* L,workshop_hack_data& def,int stack_pos)
392
393
lua_geti (L, -1 , 8 );
393
394
t.item_tile = luaL_optinteger (L, -1 , -1 );
394
395
lua_pop (L, 1 );
396
+
397
+ lua_pop (L, 1 ); // pop current tile
395
398
}
396
399
frame.push_back (t);
397
- lua_pop (L,1 );
398
400
}
399
401
def.frames .push_back (frame);
402
+ frame_index++;
403
+ lua_pop (L, 1 ); // pop current frame
400
404
}
401
- lua_pop (L, 1 );
405
+
402
406
return ;
403
407
}
404
408
// arguments: custom type,impassible fix (bool), consumed power, produced power, list of connection points, update skip(0/nil to disable)
0 commit comments