Fixed vdig, improved magma create :)

develop
Petr Mrázek 2010-04-15 22:14:55 +02:00
parent 59cdbeefe7
commit 78e1a58867
2 changed files with 111 additions and 41 deletions

@ -33,9 +33,58 @@ int main (void)
#endif #endif
return 1; return 1;
} }
bool end = false;
cout << "Welcome to the liquid spawner. type 'help' for a list of available commands." << endl;
string mode="magma";
int amount = 7;
while(!end)
{
DF.Resume();
string command = "";
cout << mode << ":" << amount << " >";
getline(cin, command);
if(command=="help")
{
cout << "m - switch to magma" << endl
<< "w - switch to water" << endl
<< "return - put liquid" << endl
<< "0-7 - set liquid amount" << endl
<< "q - quit" << endl
<< "help - print this list of commands" << endl;
}
else if(command == "m")
{
mode = "magma";
}
else if(command == "w")
{
mode = "water";
}
else if(command == "q")
{
end = true;
}
// blah blah, bad code, bite me.
else if(command == "0")
amount = 0;
else if(command == "1")
amount = 1;
else if(command == "2")
amount = 2;
else if(command == "3")
amount = 3;
else if(command == "4")
amount = 4;
else if(command == "5")
amount = 5;
else if(command == "6")
amount = 6;
else if(command == "7")
amount = 7;
else// if(command.empty())
{
DF.Suspend();
Maps->Start(); Maps->Start();
if(Position->getCursorCoords(x,y,z)) if(Position->getCursorCoords(x,y,z))
{ {
cout << "cursor coords: " << x << "/" << y << "/" << z << endl; cout << "cursor coords: " << x << "/" << y << "/" << z << endl;
@ -43,8 +92,11 @@ int main (void)
{ {
// place the magma // place the magma
Maps->ReadDesignations((x/16),(y/16),z, &designations); Maps->ReadDesignations((x/16),(y/16),z, &designations);
designations[x%16][y%16].bits.flow_size = 7; designations[x%16][y%16].bits.flow_size = amount;
if(mode == "magma")
designations[x%16][y%16].bits.liquid_type = DFHack::liquid_magma; designations[x%16][y%16].bits.liquid_type = DFHack::liquid_magma;
if(mode == "water")
designations[x%16][y%16].bits.liquid_type = DFHack::liquid_water;
Maps->WriteDesignations(x/16,y/16,z, &designations); Maps->WriteDesignations(x/16,y/16,z, &designations);
// make the magma flow :) // make the magma flow :)
@ -56,13 +108,16 @@ int main (void)
bflags.bits.liquid_2 = true; bflags.bits.liquid_2 = true;
Maps->WriteBlockFlags((x/16),(y/16),z,bflags); Maps->WriteBlockFlags((x/16),(y/16),z,bflags);
Maps->Finish(); Maps->Finish();
cout << "Success" << endl; cout << "OK" << endl;
} }
else else
cout << "Failure 1" << endl; cout << "Not a valid block." << endl;
} }
else else
cout << "Failure 2" << endl; cout << "NO" << endl;
Maps->Finish();
}
}
DF.Detach(); DF.Detach();
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;

@ -124,8 +124,8 @@ class Block
} }
return true; return true;
} }
bool valid; volatile bool valid;
bool dirty; volatile bool dirty;
DFHack::Maps * m; DFHack::Maps * m;
DFHack::mapblock40d raw; DFHack::mapblock40d raw;
uint32_t x; uint32_t x;
@ -172,11 +172,15 @@ class Layer
return (*iter).second; return (*iter).second;
} }
else else
{
if(blockcoord.x < x_bmax && blockcoord.y < y_bmax)
{ {
Block * nblo = new Block(Maps,blockcoord.x,blockcoord.y,z); Block * nblo = new Block(Maps,blockcoord.x,blockcoord.y,z);
blocks[blockcoord] = nblo; blocks[blockcoord] = nblo;
return nblo; return nblo;
} }
return 0;
}
} }
uint16_t tiletypeAt (Point tilecoord) uint16_t tiletypeAt (Point tilecoord)
@ -242,7 +246,7 @@ class Layer
return true; return true;
} }
private: private:
bool valid; volatile bool valid;
uint32_t z; uint32_t z;
uint32_t x_bmax; uint32_t x_bmax;
uint32_t y_bmax; uint32_t y_bmax;
@ -287,6 +291,9 @@ int main (int argc, const char* argv[])
int32_t cx, cy, cz; int32_t cx, cy, cz;
Maps->getSize(x_max,y_max,z_max); Maps->getSize(x_max,y_max,z_max);
uint32_t tx_max = x_max * 16;
uint32_t ty_max = y_max * 16;
Pos->getCursorCoords(cx,cy,cz); Pos->getCursorCoords(cx,cy,cz);
while(cx == -30000) while(cx == -30000)
{ {
@ -296,10 +303,19 @@ int main (int argc, const char* argv[])
DF.Suspend(); DF.Suspend();
Pos->getCursorCoords(cx,cy,cz); Pos->getCursorCoords(cx,cy,cz);
} }
Point xy ((uint32_t)cx,(uint32_t)cy);
if(xy.x == 0 || xy.x == tx_max - 1 || xy.y == 0 || xy.y == ty_max - 1)
{
cerr << "I won't dig the borders. That would be cheating!" << endl;
DF.Detach();
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
Layer * L = new Layer(Maps,cz); Layer * L = new Layer(Maps,cz);
Point xy ((uint32_t)cx,(uint32_t)cy);
DFHack::t_designation des = L->designationAt(xy); DFHack::t_designation des = L->designationAt(xy);
int16_t tt = L->tiletypeAt(xy); int16_t tt = L->tiletypeAt(xy);
int16_t veinmat = L->materialAt(xy); int16_t veinmat = L->materialAt(xy);
@ -317,8 +333,7 @@ int main (int argc, const char* argv[])
printf("%d/%d/%d tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, des.whole); printf("%d/%d/%d tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, des.whole);
stack <Point> flood; stack <Point> flood;
flood.push(xy); flood.push(xy);
uint32_t tx_max = x_max * 16;
uint32_t ty_max = y_max * 16;
while( !flood.empty() ) while( !flood.empty() )
{ {
@ -335,29 +350,29 @@ int main (int argc, const char* argv[])
if(L->setDesignationAt(current,des)) if(L->setDesignationAt(current,des))
{ {
L->clearMaterialAt(current); L->clearMaterialAt(current);
if(current.x < tx_max) if(current.x < tx_max - 2)
{ {
flood.push(Point(current.x + 1, current.y)); flood.push(Point(current.x + 1, current.y));
if(current.y < ty_max) if(current.y < ty_max - 2)
{ {
flood.push(Point(current.x + 1, current.y + 1)); flood.push(Point(current.x + 1, current.y + 1));
flood.push(Point(current.x, current.y + 1)); flood.push(Point(current.x, current.y + 1));
} }
if(current.y != 0) if(current.y > 1)
{ {
flood.push(Point(current.x + 1, current.y - 1)); flood.push(Point(current.x + 1, current.y - 1));
flood.push(Point(current.x, current.y - 1)); flood.push(Point(current.x, current.y - 1));
} }
} }
if(current.x != 0) if(current.x > 1)
{ {
flood.push(Point(current.x - 1, current.y)); flood.push(Point(current.x - 1, current.y));
if(current.y < ty_max) if(current.y < ty_max - 2)
{ {
flood.push(Point(current.x - 1, current.y + 1)); flood.push(Point(current.x - 1, current.y + 1));
flood.push(Point(current.x, current.y + 1)); flood.push(Point(current.x, current.y + 1));
} }
if(current.y != 0) if(current.y > 1)
{ {
flood.push(Point(current.x - 1, current.y - 1)); flood.push(Point(current.x - 1, current.y - 1));
flood.push(Point(current.x, current.y - 1)); flood.push(Point(current.x, current.y - 1));