summaryrefslogtreecommitdiff
path: root/src/simulation/tools/SolidTool.cpp
blob: 1cbfa461f86f4f5fe1f5efb8d6cf75034e86d428 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "ToolClasses.h"
//#TPT-Directive ToolClass Tool_Solid TOOL_SOLID 6
//#TPT-Directive ToolHeader Tool_Solid int LastSolid
//#TPT-Directive ToolHeader Tool_Solid virtual int Start(Simulation * sim, Particle * cpart, int x, int y)
Tool_Solid::Tool_Solid()
{
    Identifier = "DEFAULT_TOOL_SOLID";
    Name = "SLD";
    Colour = PIXPACK(0xA0A080);
    Description = "Makes affected particles into a solid.";
    LastSolid = -1;
}

int Tool_Solid::Start(Simulation * sim, Particle * cpart, int x, int y) {
    if(cpart && cpart->sld)
        LastSolid = cpart->sld - 1;
    else
        LastSolid = -1;
    return 1;
}

int Tool_Solid::Perform(Simulation * sim, Particle * cpart, int x, int y, float strength)
{
    int solid_index = LastSolid, i;

    if(!cpart || cpart->sld ||
       !(sim->elements[cpart->type].Properties & TYPE_SOLID))
        return 0;

    if(solid_index == -1)
        for(i=0; i<NSOLID; i++)
            if(sim->solids[i].first == -1) {
                solid_index = i;
                break;
            }
    if(solid_index == -1)
        return 0;
    LastSolid = solid_index;

    Solid *sld = sim->solids + solid_index;

    cpart->sld = solid_index + 1;
    if(sld->first == -1) {
        sld->vx = sld->vy = sld->vrot = 0.0f;
        sld->cx = x;
        sld->cy = y;
        sld->cdx = x;
        sld->cdy = y;
        sld->ax = sld->ay = sld->arot = sld->arad = 0.0f;
        sld->an = 0;
        sld->bf = 0;
        sld->bpx[0] = -10000;
        sld->bpx[1] =  10000;
        sld->bpy[2] = -10000;
        sld->bpy[3] =  10000;
        sld->first = cpart - sim->parts;
    }

    cpart->snext = -1;
    cpart->sprev = sld->last;
    if(sld->last != -1)
        sim->parts[sld->last].snext = cpart - sim->parts;
    sld->last = cpart - sim->parts;
    return 1;
}

Tool_Solid::~Tool_Solid() {}