Vp terrain node set: Difference between revisions

From Virtual Paradise Wiki
Jump to navigation Jump to search
(Basic layout)
 
m (Bugfix for negative coordinates)
Line 17: Line 17:
  * Set the height of the terrain node containing the terrain cell coordinate x, z (Note: it will reset the texture, rotation and hole flag!)
  * Set the height of the terrain node containing the terrain cell coordinate x, z (Note: it will reset the texture, rotation and hole flag!)
  */
  */
int tile_from_cell(int val)
{
  return val < 0 ? (val - 32) / 32 : val / 32;
}


void set_terrain_node_height(VPInstance sdk, int x, int z, float height)
void set_terrain_node_height(VPInstance sdk, int x, int z, float height)
Line 22: Line 27:
   int tile_x, tile_z;
   int tile_x, tile_z;


   tile_x = x / 32;
   tile_x = tile_from_cell(x);
   tile_z = z / 32;
   tile_z = tile_from_cell(z);


   int node_x, node_z;
   int node_x, node_z;
  if (node_x < 0)
    node_x -= 8;


   node_x = (x % 32) / 8;
   node_x = (x % 32) / 8;
  if (node_z < 0)
    node_z -= 8;
   node_z = (z % 32) / 8;
   node_z = (z % 32) / 8;



Revision as of 21:08, 13 December 2016

Method call snippet vp_terrain_node_set(instance, tile_x, tile_z, node_x, node_z, cells);

Replace terrain node data.

Parameters

These are the parameters that this method requires:

Parameter Usage
VPInstance
instance
Pointer to the instance this method call is intended for
int
tile_x
Tile X coordinate (with no terrain scaling, divide coordinates in decameter by 32 to get tile coordinates)
int
tile_z
Tile Z coordinate
int
node_x
Node X coordinate (within tile, 0 to 3)
int
node_z
Node Z coordinate
vp_terrain_cell_t*
cells
Pointer to 64 cells (8x8: cells[z*8+x])

Returns

This method returns a return code integer, which indicates whether the call was successful or errored for any reason:

Return code Cause
VP_RC_SUCCESS Successful call (for methods that have a registered callback, it only means the request has been sent)
VP_RC_NOT_IN_WORLD Bot is not currently in a world

Behavior

Examples

/*
 * Set the height of the terrain node containing the terrain cell coordinate x, z (Note: it will reset the texture, rotation and hole flag!)
 */

int tile_from_cell(int val)
{
  return val < 0 ? (val - 32) / 32 : val / 32;
}

void set_terrain_node_height(VPInstance sdk, int x, int z, float height)
{
  int tile_x, tile_z;

  tile_x = tile_from_cell(x);
  tile_z = tile_from_cell(z);

  int node_x, node_z;

  if (node_x < 0)
    node_x -= 8;

  node_x = (x % 32) / 8;

  if (node_z < 0)
    node_z -= 8;

  node_z = (z % 32) / 8;

  struct vp_terrain_cell_t cells[64];

  memset(cells, 0, sizeof(cells));

  for (int i = 0; i < 64; i++)
    cells[i].height = height;

  vp_terrain_node_set(sdk, tile_x, tile_z, node_x, node_z, cells);
}

See also