some changes to LIGH creation (mostly from lua)

This commit is contained in:
jacob1 2015-05-11 20:50:10 -04:00
parent fef767335f
commit 8e7e8e0670
4 changed files with 78 additions and 64 deletions

View File

@ -114,11 +114,7 @@ WindTool::WindTool(int id, string name, string description, int r, int g, int b,
Tool(id, name, description, r, g, b, identifier, textureGen)
{
}
WindTool::~WindTool() {}
void WindTool::Draw(Simulation * sim, Brush * brush, ui::Point position)
{
}
void WindTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging)
{
int radiusX, radiusY, sizeX, sizeY;
@ -146,39 +142,15 @@ void WindTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui
}
}
}
void WindTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {}
void WindTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {}
void Element_LIGH_Tool::Draw(Simulation * sim, Brush * brush, ui::Point position)
void Element_LIGH_Tool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging)
{
if(sim->currentTick >= nextUse)
{
int p = sim->create_part(-2, position.X, position.Y, toolID);
if (p != -1)
{
sim->parts[p].life = brush->GetRadius().X+brush->GetRadius().Y;
if (sim->parts[p].life > 55)
sim->parts[p].life = 55;
sim->parts[p].temp = sim->parts[p].life*150; // temperature of the lighting shows the power of the lighting
nextUse = sim->currentTick+sim->parts[p].life/4;
}
}
if (dragging)
sim->CreateParts(position1.X, position1.Y, brush->GetRadius().X, brush->GetRadius().Y, PT_LIGH);
}
Element_TESC_Tool::Element_TESC_Tool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int)):
ElementTool(id, name, description, r, g, b, identifier, textureGen)
{
}
void Element_TESC_Tool::Draw(Simulation * sim, Brush * brush, ui::Point position){
int radiusInfo = brush->GetRadius().X*4+brush->GetRadius().Y*4+7;
sim->CreateParts(position.X, position.Y, toolID | (radiusInfo << 8), brush);
}
void Element_TESC_Tool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging) {
int radiusInfo = brush->GetRadius().X*4+brush->GetRadius().Y*4+7;
sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, toolID | (radiusInfo << 8), brush);
}
void Element_TESC_Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
int radiusInfo = brush->GetRadius().X*4+brush->GetRadius().Y*4+7;
sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID | (radiusInfo << 8));

View File

@ -104,17 +104,13 @@ public:
class Element_LIGH_Tool: public Tool
{
int nextUse;
public:
Element_LIGH_Tool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
Tool(id, name, description, r, g, b, identifier, textureGen),
nextUse(0)
{
}
virtual ~Element_LIGH_Tool() {}
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
Tool(id, name, description, r, g, b, identifier, textureGen)
{ }
virtual ~Element_LIGH_Tool() { }
virtual void Click(Simulation * sim, Brush * brush, ui::Point position) { }
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false) { }
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false);
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { }
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { }
};
@ -134,10 +130,10 @@ public:
class Element_TESC_Tool: public ElementTool
{
public:
Element_TESC_Tool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
Element_TESC_Tool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
ElementTool(id, name, description, r, g, b, identifier, textureGen)
{ }
virtual ~Element_TESC_Tool() {}
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false);
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2);
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position);
};
@ -146,11 +142,10 @@ class PlopTool: public ElementTool
{
public:
PlopTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
ElementTool(id, name, description, r, g, b, identifier, textureGen)
{
}
virtual ~PlopTool() {}
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) {}
ElementTool(id, name, description, r, g, b, identifier, textureGen)
{ }
virtual ~PlopTool() { }
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) { }
virtual void Click(Simulation * sim, Brush * brush, ui::Point position);
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false) { }
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { }
@ -172,11 +167,11 @@ class WindTool: public Tool
{
public:
WindTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
virtual ~WindTool();
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
virtual ~WindTool() { }
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) { }
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false);
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2);
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position);
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { }
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { }
};
#endif /* TOOL_H_ */

View File

@ -1256,16 +1256,36 @@ int Simulation::CreateParts(int positionX, int positionY, int c, Brush * cBrush,
{
if (flags == -1)
flags = replaceModeFlags;
if(cBrush)
if (cBrush)
{
int radiusX = cBrush->GetRadius().X, radiusY = cBrush->GetRadius().Y, sizeX = cBrush->GetSize().X, sizeY = cBrush->GetSize().Y;
unsigned char *bitmap = cBrush->GetBitmap();
for(int y = sizeY-1; y >=0; y--)
// special case for LIGH
if (c == PT_LIGH)
{
for(int x = 0; x < sizeX; x++)
if (currentTick < lightningRecreate)
return 1;
int newlife = radiusX + radiusY;
if (newlife > 55)
newlife = 55;
c = c|newlife<<8;
lightningRecreate = currentTick+newlife/4;
return CreatePartFlags(positionX, positionY, c, flags);
}
else if (c == PT_TESC)
{
int newtmp = (radiusX*4+radiusY*4+7);
if (newtmp > 300)
newtmp = 300;
c = c|newtmp<<8;
}
for (int y = sizeY-1; y >=0; y--)
{
for (int x = 0; x < sizeX; x++)
{
if(bitmap[(y*sizeX)+x] && (positionX+(x-radiusX) >= 0 && positionY+(y-radiusY) >= 0 && positionX+(x-radiusX) < XRES && positionY+(y-radiusY) < YRES))
if (bitmap[(y*sizeX)+x] && (positionX+(x-radiusX) >= 0 && positionY+(y-radiusY) >= 0 && positionX+(x-radiusX) < XRES && positionY+(y-radiusY) < YRES))
{
CreatePartFlags(positionX+(x-radiusX), positionY+(y-radiusY), c, flags);
}
@ -1277,16 +1297,36 @@ int Simulation::CreateParts(int positionX, int positionY, int c, Brush * cBrush,
int Simulation::CreateParts(int x, int y, int rx, int ry, int c, int flags)
{
int i, j, f = 0;
bool created = false;
if (flags == -1)
flags = replaceModeFlags;
for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++)
// special case for LIGH
if (c == PT_LIGH)
{
if (currentTick < lightningRecreate)
return 1;
int newlife = rx + ry;
if (newlife > 55)
newlife = 55;
c = c|newlife<<8;
lightningRecreate = currentTick+newlife/4;
rx = ry = 0;
}
else if (c == PT_TESC)
{
int newtmp = (rx*4+ry*4+7);
if (newtmp > 300)
newtmp = 300;
c = c|newtmp<<8;
}
for (int j = -ry; j <= ry; j++)
for (int i = -rx; i <= rx; i++)
if (CreatePartFlags(x+i, y+j, c, flags))
f = 1;
return !f;
created = true;
return !created;
}
int Simulation::CreatePartFlags(int x, int y, int c, int flags)
@ -3041,11 +3081,16 @@ int Simulation::create_part(int p, int x, int y, int tv)
case PT_LIGH:
{
float gx, gy, gsize;
if (p!=-2)
if (v >= 0)
{
parts[i].life=30;
parts[i].temp=parts[i].life*150.0f; // temperature of the lighting shows the power of the lighting
if (v > 55)
v = 55;
parts[i].life = v;
}
else
parts[i].life = 30;
parts[i].temp = parts[i].life*150.0f; // temperature of the lightning shows the power of the lightning
GetGravityField(x, y, 1.0f, 1.0f, gx, gy);
gsize = gx*gx+gy*gy;
if (gsize<0.0016f)
@ -4896,6 +4941,7 @@ Simulation::Simulation():
ISWIRE(0),
force_stacking_check(0),
emp_decor(0),
lightningRecreate(0),
gravWallChanged(false),
edgeMode(0),
gravityMode(0),

View File

@ -62,6 +62,7 @@ public:
int ISWIRE;
int force_stacking_check;
int emp_decor;
int lightningRecreate;
//Stickman
playerst player;
playerst player2;