Vp terrain node set: Difference between revisions

From Virtual Paradise Wiki
Jump to navigation Jump to search
Sleepy E (talk | contribs)
Basic layout
 
Sleepy E (talk | contribs)
m Added reference number attribute
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:
   {{sdk parameter row|int                |node_z |Node Z coordinate}}
   {{sdk parameter row|int                |node_z |Node Z coordinate}}
   {{sdk parameter row|vp_terrain_cell_t* |cells  |Pointer to 64 cells (8x8: cells[z*8+x])}}
   {{sdk parameter row|vp_terrain_cell_t* |cells  |Pointer to 64 cells (8x8: cells[z*8+x])}}
|attributes=
  {{sdk attribute row|int      |reference_number      |Is passed to the callback to identify for which method call it is fired}}
|returncodes=
|returncodes=
   {{sdk return code row|NOT_IN_WORLD |Bot is not currently in a world}}
   {{sdk return code row|NOT_IN_WORLD |Bot is not currently in a world}}
Line 17: Line 19:
  * 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 29:
   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;



Latest revision as of 23:29, 31 July 2018

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])

Used attributes

This method uses data set in these attributes when called:

Attribute Usage
VP_REFERENCE_NUMBER Is passed to the callback to identify for which method call it is fired

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