Map block flags added to the API

Added a RAMP_TOP tile shape, ramp characters for veinlook
Merged in the magma_create util by Aleric, tweaked it a bit, made it use the block flags
develop
Petr Mrázek 2010-03-26 00:42:07 +01:00
parent 99760d5ae0
commit f0edb0c33d
7 changed files with 70 additions and 9 deletions

@ -100,8 +100,15 @@ int puttile(int x, int y, int tiletype, int color)
znak = '='; znak = '=';
break; break;
case RAMP: case RAMP:
znak = '^'; attron(COLOR_PAIR(color));
break; mvwaddwstr(stdscr, y, x, L"\u25B2");
attroff(COLOR_PAIR(color));
return 0;
case RAMP_TOP:
attron(COLOR_PAIR(color));
mvwaddwstr(stdscr, y, x, L"\u25BC");
attroff(COLOR_PAIR(color));
return 0;
case FLOOR: case FLOOR:
znak = '.'; znak = '.';
break; break;

@ -352,7 +352,7 @@ bool API::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer)
g_pProcess->read (addr + d->biome_stuffs, sizeof (buffer->biome_indices), (uint8_t *) buffer->biome_indices); g_pProcess->read (addr + d->biome_stuffs, sizeof (buffer->biome_indices), (uint8_t *) buffer->biome_indices);
buffer->origin = addr; buffer->origin = addr;
uint32_t addr_of_struct = g_pProcess->readDWord(addr); uint32_t addr_of_struct = g_pProcess->readDWord(addr);
buffer->dirty_dword = g_pProcess->readDWord(addr_of_struct); buffer->blockflags.whole = g_pProcess->readDWord(addr_of_struct);
return true; return true;
} }
return false; return false;
@ -399,8 +399,30 @@ bool API::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit)
return false; return false;
} }
/// read/write the block flags
bool API::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags &blockflags)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if(addr)
{
uint32_t addr_of_struct = g_pProcess->readDWord(addr);
blockflags.whole = g_pProcess->readDWord(addr_of_struct);
return true;
}
return false;
}
bool API::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags blockflags)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
uint32_t addr_of_struct = g_pProcess->readDWord(addr);
g_pProcess->writeDWord (addr_of_struct, blockflags.whole);
return true;
}
return false;
}
// 256 * sizeof(uint32_t)
bool API::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer) bool API::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
{ {
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];

@ -161,6 +161,10 @@ namespace DFHack
bool ReadDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool &dirtybit); bool ReadDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool &dirtybit);
bool WriteDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool dirtybit); bool WriteDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool dirtybit);
/// read/write the block flags
bool ReadBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_blockflags &blockflags);
bool WriteBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_blockflags blockflags);
/// read region offsets of a block - used for determining layer stone matgloss /// read region offsets of a block - used for determining layer stone matgloss
bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, biome_indices40d *buffer); bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, biome_indices40d *buffer);

@ -42,6 +42,7 @@ namespace DFHack
STAIR_UPDOWN, STAIR_UPDOWN,
RAMP, RAMP,
RAMP_TOP,
FLOOR, FLOOR,
TREE_DEAD, TREE_DEAD,
@ -95,7 +96,7 @@ namespace DFHack
{ {
// 0 // 0
{"void",EMPTY, AIR, VAR_1}, {"void",EMPTY, AIR, VAR_1},
{"ramp top",EMPTY, AIR, VAR_1}, {"ramp top",RAMP_TOP, AIR, VAR_1},
{"pool",FLOOR, SOIL, VAR_1}, {"pool",FLOOR, SOIL, VAR_1},
{0, EMPTY, AIR, VAR_1}, {0, EMPTY, AIR, VAR_1},
{0, EMPTY, AIR, VAR_1}, {0, EMPTY, AIR, VAR_1},

@ -828,6 +828,24 @@ union t_occupancy
naked_occupancy_grouped unibits; naked_occupancy_grouped unibits;
}; };
// map block flags
struct naked_blockflags
{
unsigned int designated : 1;// designated for jobs (digging and stuff like that)
unsigned int unk_1 : 1; // possibly related to the designated flag
// two flags required for liquid flow. no idea why
unsigned int liquid_1 : 1;
unsigned int liquid_2 : 1;
unsigned int unk_2: 28; // rest of the flags is completely unknown
// there's a possibility that this flags field is shorter than 32 bits
};
union t_blockflags
{
uint32_t whole;
naked_blockflags bits;
};
typedef int16_t tiletypes40d [16][16]; typedef int16_t tiletypes40d [16][16];
typedef DFHack::t_designation designations40d [16][16]; typedef DFHack::t_designation designations40d [16][16];
typedef DFHack::t_occupancy occupancies40d [16][16]; typedef DFHack::t_occupancy occupancies40d [16][16];
@ -841,7 +859,7 @@ typedef struct
// really a '7', but I use 8 to make it neater :) // really a '7', but I use 8 to make it neater :)
biome_indices40d biome_indices; biome_indices40d biome_indices;
uint32_t origin; // the address where it came from uint32_t origin; // the address where it came from
uint32_t dirty_dword; // bit 1 set means that the block is to be included in job checks t_blockflags blockflags;
} mapblock40d; } mapblock40d;
struct t_viewscreen struct t_viewscreen

@ -64,7 +64,7 @@ inline void ReadBlockByAddress (void * data)
memcpy(&(SHMDATA(mapblock40d)->designation), ((char *) block) + offsets.designation_offset, sizeof(SHMDATA(mapblock40d)->designation)); memcpy(&(SHMDATA(mapblock40d)->designation), ((char *) block) + offsets.designation_offset, sizeof(SHMDATA(mapblock40d)->designation));
memcpy(&(SHMDATA(mapblock40d)->occupancy), ((char *) block) + offsets.occupancy_offset, sizeof(SHMDATA(mapblock40d)->occupancy)); memcpy(&(SHMDATA(mapblock40d)->occupancy), ((char *) block) + offsets.occupancy_offset, sizeof(SHMDATA(mapblock40d)->occupancy));
memcpy(&(SHMDATA(mapblock40d)->biome_indices), ((char *) block) + offsets.biome_stuffs, sizeof(SHMDATA(mapblock40d)->biome_indices)); memcpy(&(SHMDATA(mapblock40d)->biome_indices), ((char *) block) + offsets.biome_stuffs, sizeof(SHMDATA(mapblock40d)->biome_indices));
SHMDATA(mapblock40d)->dirty_dword = *block->ptr_to_dirty; SHMDATA(mapblock40d)->blockflags.whole = *block->ptr_to_dirty;
SHMDATA(mapblock40d)->origin = (uint32_t)block; SHMDATA(mapblock40d)->origin = (uint32_t)block;
SHMHDR->error = false; SHMHDR->error = false;

@ -30,11 +30,20 @@ int main (void)
cout << "cursor coords: " << x << "/" << y << "/" << z << endl; cout << "cursor coords: " << x << "/" << y << "/" << z << endl;
if(DF.isValidBlock(x/16,y/16,z)) if(DF.isValidBlock(x/16,y/16,z))
{ {
DF.ReadDesignations((x/16),(y/16),(z/16), &designations); // place the magma
DF.ReadDesignations((x/16),(y/16),z, &designations);
designations[x%16][y%16].bits.flow_size = 7; designations[x%16][y%16].bits.flow_size = 7;
designations[x%16][y%16].bits.liquid_type = DFHack::liquid_magma; designations[x%16][y%16].bits.liquid_type = DFHack::liquid_magma;
DF.WriteDesignations(x/16,y/16,z, &designations); DF.WriteDesignations(x/16,y/16,z, &designations);
// make the magma flow :)
DFHack::t_blockflags bflags;
DF.ReadBlockFlags((x/16),(y/16),z,bflags);
// 0x00000001 = job-designated
// 0x0000000C = run flows? - both bit 3 and 4 required for making magma placed on a glacier flow
bflags.bits.liquid_1 = true;
bflags.bits.liquid_2 = true;
DF.WriteBlockFlags((x/16),(y/16),z,bflags);
cout << "Success" << endl; cout << "Success" << endl;
} }
else else