|
|
@ -9,7 +9,7 @@
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <stack>
|
|
|
|
#include <stack>
|
|
|
|
#include <string>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
using std::vector;
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using std::string;
|
|
|
|
using std::stack;
|
|
|
|
using std::stack;
|
|
|
@ -63,8 +63,8 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
|
|
|
|
static bool filled = false;
|
|
|
|
static bool filled = false;
|
|
|
|
static circle_what what = circle_set;
|
|
|
|
static circle_what what = circle_set;
|
|
|
|
static e_designation type = designation_default;
|
|
|
|
static e_designation type = designation_default;
|
|
|
|
static int r = 0;
|
|
|
|
static int diameter = 0;
|
|
|
|
auto saved_r = r;
|
|
|
|
auto saved_d = diameter;
|
|
|
|
bool force_help = false;
|
|
|
|
bool force_help = false;
|
|
|
|
for(int i = 0; i < parameters.size();i++)
|
|
|
|
for(int i = 0; i < parameters.size();i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -112,14 +112,14 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
type = designation_channel;
|
|
|
|
type = designation_channel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!from_string(r,parameters[i], std::dec))
|
|
|
|
else if (!from_string(diameter,parameters[i], std::dec))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
r = saved_r;
|
|
|
|
diameter = saved_d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(r < 0)
|
|
|
|
if(diameter < 0)
|
|
|
|
r = -r;
|
|
|
|
diameter = -diameter;
|
|
|
|
if(force_help || r == 0)
|
|
|
|
if(force_help || diameter == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
c->con.print( "A command for easy designation of filled and hollow circles.\n"
|
|
|
|
c->con.print( "A command for easy designation of filled and hollow circles.\n"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
@ -137,7 +137,7 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
|
|
|
|
" xstair = staircase up/down\n"
|
|
|
|
" xstair = staircase up/down\n"
|
|
|
|
" chan = dig channel\n"
|
|
|
|
" chan = dig channel\n"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
|
" # = radius in tiles (default = 0)\n"
|
|
|
|
" # = diameter in tiles (default = 0)\n"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
|
"After you have set the options, the command called with no options\n"
|
|
|
|
"After you have set the options, the command called with no options\n"
|
|
|
|
"repeats with the last selected parameters:\n"
|
|
|
|
"repeats with the last selected parameters:\n"
|
|
|
@ -173,10 +173,16 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
|
|
|
|
auto b = MCache.BlockAt(at/16);
|
|
|
|
auto b = MCache.BlockAt(at/16);
|
|
|
|
if(!b || !b->valid)
|
|
|
|
if(!b || !b->valid)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
if(x == 0 || x == x_max - 1)
|
|
|
|
if(x == 0 || x == x_max * 16 - 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//c->con.print("not digging map border\n");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
if(y == 0 || y == y_max - 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if(y == 0 || y == y_max * 16 - 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//c->con.print("not digging map border\n");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
uint16_t tt = MCache.tiletypeAt(at);
|
|
|
|
uint16_t tt = MCache.tiletypeAt(at);
|
|
|
|
t_designation des = MCache.designationAt(at);
|
|
|
|
t_designation des = MCache.designationAt(at);
|
|
|
|
// could be potentially used to locate hidden constructions?
|
|
|
|
// could be potentially used to locate hidden constructions?
|
|
|
@ -242,53 +248,71 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
int f = 1 - r;
|
|
|
|
int r = diameter / 2;
|
|
|
|
int ddF_x = 1;
|
|
|
|
int iter;
|
|
|
|
int ddF_y = -2 * r;
|
|
|
|
bool adjust;
|
|
|
|
int x = 0;
|
|
|
|
if(diameter % 2)
|
|
|
|
int y = r;
|
|
|
|
{
|
|
|
|
if(!filled)
|
|
|
|
// paint center
|
|
|
|
{
|
|
|
|
if(filled)
|
|
|
|
dig(cx, cy + r, cz);
|
|
|
|
{
|
|
|
|
dig(cx, cy - r, cz);
|
|
|
|
lineY(cx - r, cx + r, cy, cz);
|
|
|
|
dig(cx + r, cy, cz);
|
|
|
|
|
|
|
|
dig(cx - r, cy, cz);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lineX(cy-r, cy+r, cx, cz);
|
|
|
|
dig(cx - r, cy, cz);
|
|
|
|
lineY(cx-r, cx+r, cy, cz);
|
|
|
|
dig(cx + r, cy, cz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
adjust = false;
|
|
|
|
while(x < y)
|
|
|
|
iter = 2;
|
|
|
|
{
|
|
|
|
|
|
|
|
if(f >= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
y--;
|
|
|
|
|
|
|
|
ddF_y += 2;
|
|
|
|
|
|
|
|
f += ddF_y;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x++;
|
|
|
|
else
|
|
|
|
ddF_x += 2;
|
|
|
|
|
|
|
|
f += ddF_x;
|
|
|
|
|
|
|
|
if(!filled)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
dig(cx + x, cy + y, cz);
|
|
|
|
adjust = true;
|
|
|
|
dig(cx - x, cy + y, cz);
|
|
|
|
iter = 1;
|
|
|
|
dig(cx + x, cy - y, cz);
|
|
|
|
}
|
|
|
|
dig(cx - x, cy - y, cz);
|
|
|
|
int lastwhole = r;
|
|
|
|
dig(cx + y, cy + x, cz);
|
|
|
|
for(; iter <= diameter - 1; iter +=2)
|
|
|
|
dig(cx - y, cy + x, cz);
|
|
|
|
{
|
|
|
|
dig(cx + y, cy - x, cz);
|
|
|
|
// top, bottom coords
|
|
|
|
dig(cx - y, cy - x, cz);
|
|
|
|
int top = cy - ((iter + 1) / 2) + adjust;
|
|
|
|
|
|
|
|
int bottom = cy + ((iter + 1) / 2);
|
|
|
|
|
|
|
|
// see where the current 'line' intersects the circle
|
|
|
|
|
|
|
|
double val = std::sqrt(diameter*diameter - iter*iter);
|
|
|
|
|
|
|
|
// adjust for circles with odd diameter
|
|
|
|
|
|
|
|
if(!adjust)
|
|
|
|
|
|
|
|
val -= 1;
|
|
|
|
|
|
|
|
// map the found value to the DF grid
|
|
|
|
|
|
|
|
double whole;
|
|
|
|
|
|
|
|
double fraction = std::modf(val / 2.0, & whole);
|
|
|
|
|
|
|
|
if (fraction > 0.5)
|
|
|
|
|
|
|
|
whole += 1.0;
|
|
|
|
|
|
|
|
int right = cx + whole;
|
|
|
|
|
|
|
|
int left = cx - whole + adjust;
|
|
|
|
|
|
|
|
int diff = lastwhole - whole;
|
|
|
|
|
|
|
|
// paint
|
|
|
|
|
|
|
|
if(filled || iter == diameter - 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lineY(left, right, top , cz);
|
|
|
|
|
|
|
|
lineY(left, right, bottom , cz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lineY(cx-x, cx+x, cy+y, cz);
|
|
|
|
dig(left, top, cz);
|
|
|
|
lineY(cx-x, cx+x, cy-y, cz);
|
|
|
|
dig(left, bottom, cz);
|
|
|
|
lineY(cx-y, cx+y, cy+x, cz);
|
|
|
|
dig(right, top, cz);
|
|
|
|
lineY(cx-y, cx+y, cy-x, cz);
|
|
|
|
dig(right, bottom, cz);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!filled && diff > 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int lright = cx + lastwhole;
|
|
|
|
|
|
|
|
int lleft = cx - lastwhole + adjust;
|
|
|
|
|
|
|
|
lineY(lleft + 1, left - 1, top + 1 , cz);
|
|
|
|
|
|
|
|
lineY(right + 1, lright - 1, top + 1 , cz);
|
|
|
|
|
|
|
|
lineY(lleft + 1, left - 1, bottom - 1 , cz);
|
|
|
|
|
|
|
|
lineY(right + 1, lright - 1, bottom - 1 , cz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastwhole = whole;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MCache.WriteAll();
|
|
|
|
MCache.WriteAll();
|
|
|
|
c->Resume();
|
|
|
|
c->Resume();
|
|
|
|