The Powder Toy

Functions

When you are modding TPT++ and come to writing the update routine, there are a few functions you will need to use. A reference of those is shown below.

sim->create_part(int p, int x, int y, int t);

What it does: Creates a particle at a given coordinate.

int p - How the particle is created. -1 means from the code (will only create a particle if the space is empty). This is the normal way to create a particle, -2 is from the brush (don't use this), -3 means it will ignore any particles in the space and draw it anyway, and any positive number will override the particle at that index with this newly created particle.

int x - Particle's x coordinate

int y - Particle's y coordinate

int t - Particle's type. Use a pre-defined value, such as PT_INST.

sim->kill_part(int i) - Deletes particle with index i

What it does: Deletes a particle without the given x and y, using its index instead.

int i - The particle's index. Passed into the function as 'i'.

sim->delete_part(int x, int y, int flags);

What it does: Deletes a particle at location (x, y)

int x - Particle's x coordinate

int y - Particle's y coordinate

int flags - Un-useful value, leave it as 0

sim->part_change_type(int i, int x, int y, int t);

What it does: Changes type of particle i. Do not manually set parts[].type, use this function instead.

int i - The particle's index.

int x - Particle's x coordinate. Pass in parts[i].x here.

int y - Particle's y coordinate. Pass in parts[i].y here.

int t - Particle's type. Use a pre-defined value, such as PT_INST.

sim->clear_area(int x, int y, int w, int h);

What it does: Clears a rectangle with specified height and width.

int x - Top left corner's x coordinate (from left towards the right)

int y - Top left corner's y coordinate (from top downwards!)

int w - The width of the rectangle

int h - The height of the rectangle

sim->CreateBox(int x1, int y1, int x2, int y2, int t, int flags)

What it does: Utility function, creates a rectangle of a given particle.

For some reason, this uses a different way to specify a rectangle than the deleting equivalent.

size_t propoffset - This is a value returned by the function offsetof(Particle, <property>).

Replace <property> with what you want, for example tmp or ctype.

PropertyValue propvalue - A c++ union, which holds the property you want to set. You may declare PropertyValue value;, then do value.Integer = 2; in order to use this. The other two properties you can set are .Float (if setting temperature or veloticy) and .UInteger (if setting decoration color)

StructProperty::PropertyType proptype - What kind of type the value you provided is.

For example, if you had a temperature number (as an integer), then you could use StructProperty::Integer.