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

Function regrass_tile

plugins/regrass.cpp:345–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

343}
344
345int regrass_tile(color_ostream &out, const regrass_options &options, df::map_block *block, int tx, int ty)
346{ // Regrass single tile. Return 1 if tile success, else 0.
347 CHECK_NULL_POINTER(block);
348 if (!is_valid_tile_coord(df::coord2d(tx, ty))) {
349 out.printerr("({}, {}) not in range 0-15!\n", tx, ty);
350 return 0;
351 }
352
353 DEBUG(log, out).print("Regrass tile ({}, {}, {})\n",
354 block->map_pos.x + tx, block->map_pos.y + ty, block->map_pos.z);
355 if (!regrass_events(out, options, block, tx, ty))
356 return 0;
357
358 auto tt = block->tiletype[tx][ty];
359 auto mat = tileMaterial(tt);
360 auto shape = tileShape(tt);
361
362 if (mat == tiletype_material::GRASS_LIGHT ||
363 mat == tiletype_material::GRASS_DARK ||
364 mat == tiletype_material::PLANT ||
365 mat == tiletype_material::TREE)
366 { // Already appropriate tile.
367 TRACE(log, out).print("Tiletype no change.\n");
368 return 1;
369 }
370
371 if (shape == tiletype_shape::FLOOR)
372 { // Floor (including ashes).
373 DEBUG(log, out).print("Tiletype to random grass floor.\n");
374 block->tiletype[tx][ty] = findRandomVariant((rand() & 1) ? tiletype::GrassLightFloor1 : tiletype::GrassDarkFloor1);
375 }
376 else
377 { // Ramp or stairs.
378 auto new_mat = (rand() & 1) ? tiletype_material::GRASS_LIGHT : tiletype_material::GRASS_DARK;
379 auto new_tt = findTileType(shape, new_mat, tiletype_variant::NONE, tiletype_special::NONE, nullptr);
380 DEBUG(log, out).print("Tiletype to {}.\n", ENUM_KEY_STR(tiletype, new_tt));
381 block->tiletype[tx][ty] = new_tt;
382 }
383 return 1;
384}
385
386int regrass_cuboid(color_ostream &out, const regrass_options &options, const cuboid &bounds)
387{ // Regrass all tiles in the defined cuboid.

Callers 3

regrass_cuboidFunction · 0.85
regrass_blockFunction · 0.85
df_regrassFunction · 0.85

Calls 7

is_valid_tile_coordFunction · 0.85
regrass_eventsFunction · 0.85
tileMaterialFunction · 0.85
tileShapeFunction · 0.85
findRandomVariantFunction · 0.85
findTileTypeFunction · 0.85
printMethod · 0.45

Tested by

no test coverage detected