/
Mix.cpp
executable file
·49 lines (37 loc) · 1.16 KB
/
Mix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "ToolClasses.h"
//#TPT-Directive ToolClass Tool_Mix TOOL_MIX 6
Tool_Mix::Tool_Mix()
{
Identifier = "DEFAULT_TOOL_MIX";
Name = "MIX";
Colour = PIXPACK(0xFFD090);
Description = "Mixes particles.";
}
int Tool_Mix::Perform(Simulation * sim, Particle * cpart, int x, int y, float strength)
{
int thisPart = sim->pmap[y][x];
if(!thisPart)
return 0;
if(rand() % 100 != 0)
return 0;
int distance = (int)(std::pow(strength, .5f) * 10);
if(!(sim->elements[thisPart&0xFF].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS)))
return 0;
int newX = x + (rand() % distance) - (distance/2);
int newY = y + (rand() % distance) - (distance/2);
if(newX < 0 || newY < 0 || newX >= XRES || newY >= YRES)
return 0;
int thatPart = sim->pmap[newY][newX];
if(!thatPart)
return 0;
if(!(sim->elements[thatPart&0xFF].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS)))
return 0;
sim->pmap[y][x] = thatPart;
sim->parts[thatPart>>8].x = x;
sim->parts[thatPart>>8].y = y;
sim->pmap[newY][newX] = thisPart;
sim->parts[thisPart>>8].x = newX;
sim->parts[thisPart>>8].y = newY;
return 1;
}
Tool_Mix::~Tool_Mix() {}