Support for reading/writing temperature, extended veinlook

develop
Petr Mrázek 2010-04-17 15:30:25 +02:00
parent 52b9ed3afe
commit caa482fbd1
6 changed files with 189 additions and 29 deletions

@ -199,6 +199,7 @@ namespace DFHack
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];
typedef uint8_t biome_indices40d [16]; typedef uint8_t biome_indices40d [16];
typedef uint16_t t_temperatures [16][16];
typedef struct typedef struct
{ {
@ -290,6 +291,10 @@ namespace DFHack
bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer); bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer);
bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer); bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer);
/// read/write temperatures
bool ReadTemperatures(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_temperatures *temp1, t_temperatures *temp2);
bool WriteTemperatures (uint32_t blockx, uint32_t blocky, uint32_t blockz, t_temperatures *temp1, t_temperatures *temp2);
/// read/write block occupancies /// read/write block occupancies
bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer); bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer);
bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer); bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer);

@ -70,11 +70,13 @@ Maps::Maps(APIPrivate* _d)
off.x_count_offset = mem->getAddress ("x_count_block"); off.x_count_offset = mem->getAddress ("x_count_block");
off.y_count_offset = mem->getAddress ("y_count_block"); off.y_count_offset = mem->getAddress ("y_count_block");
off.z_count_offset = mem->getAddress ("z_count_block"); off.z_count_offset = mem->getAddress ("z_count_block");
off.tile_type_offset = mem->getOffset ("type"); off.tile_type_offset = mem->getOffset ("map_data_type");
off.designation_offset = mem->getOffset ("designation"); off.designation_offset = mem->getOffset ("map_data_designation");
off.occupancy_offset = mem->getOffset("occupancy"); off.occupancy_offset = mem->getOffset("map_data_occupancy");
off.biome_stuffs = mem->getOffset ("biome_stuffs"); off.biome_stuffs = mem->getOffset ("map_data_biome_stuffs");
off.veinvector = mem->getOffset ("v_vein"); off.veinvector = mem->getOffset ("map_data_vein_vector");
off.temperature1_offset = mem->getOffset ("map_data_temperature1_offset");
off.temperature2_offset = mem->getOffset ("map_data_temperature2_offset");
// these can fail and will be found when looking at the actual veins later // these can fail and will be found when looking at the actual veins later
// basically a cache // basically a cache
@ -357,6 +359,36 @@ bool Maps::WriteOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *b
return false; return false;
} }
/*
* Temperatures
*/
bool Maps::ReadTemperatures(uint32_t x, uint32_t y, uint32_t z, t_temperatures *temp1, t_temperatures *temp2)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
if(temp1)
g_pProcess->read (addr + d->offsets.temperature1_offset, sizeof (t_temperatures), (uint8_t *) temp1);
if(temp2)
g_pProcess->read (addr + d->offsets.temperature2_offset, sizeof (t_temperatures), (uint8_t *) temp2);
return true;
}
return false;
}
bool Maps::WriteTemperatures (uint32_t x, uint32_t y, uint32_t z, t_temperatures *temp1, t_temperatures *temp2)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
if(temp1)
g_pProcess->write (addr + d->offsets.temperature1_offset, sizeof (t_temperatures), (uint8_t *) temp1);
if(temp2)
g_pProcess->write (addr + d->offsets.temperature2_offset, sizeof (t_temperatures), (uint8_t *) temp2);
return true;
}
return false;
}
/* /*
* Region Offsets - used for layer geology * Region Offsets - used for layer geology
*/ */

@ -47,6 +47,8 @@ typedef struct
uint32_t occupancy_offset;// = d->offset_descriptor->getOffset ("occupancy"); uint32_t occupancy_offset;// = d->offset_descriptor->getOffset ("occupancy");
uint32_t biome_stuffs;// = d->offset_descriptor->getOffset ("biome_stuffs"); uint32_t biome_stuffs;// = d->offset_descriptor->getOffset ("biome_stuffs");
uint32_t veinvector;// = d->offset_descriptor->getOffset ("v_vein"); uint32_t veinvector;// = d->offset_descriptor->getOffset ("v_vein");
uint32_t temperature1_offset;
uint32_t temperature2_offset;
uint32_t vein_mineral_vptr; uint32_t vein_mineral_vptr;
uint32_t vein_ice_vptr; uint32_t vein_ice_vptr;
uint32_t vein_spatter_vptr; uint32_t vein_spatter_vptr;

@ -14,6 +14,7 @@ using namespace std;
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
#include <locale.h> #include <locale.h>
#include <math.h>
#include <DFTypes.h> #include <DFTypes.h>
#include <DFTileTypes.h> #include <DFTileTypes.h>
@ -30,6 +31,22 @@ string error;
API * pDF = 0; API * pDF = 0;
struct t_tempz
{
int32_t limit;
int character;
};
t_tempz temp_limits[]=
{
{50, '.'},
{100, '+'},
{500, '*'},
{1000, '#'},
{2000, '!'}
};
#define NUM_LIMITS 5
static void finish(int sig); static void finish(int sig);
int gotoxy(int x, int y) int gotoxy(int x, int y)
@ -315,6 +332,8 @@ main(int argc, char *argv[])
vector<t_vein> veinVector; vector<t_vein> veinVector;
vector<t_frozenliquidvein> IceVeinVector; vector<t_frozenliquidvein> IceVeinVector;
vector<t_spattervein> splatter; vector<t_spattervein> splatter;
t_temperatures b_temp1;
t_temperatures b_temp2;
DFHack::Materials * Mats = 0; DFHack::Materials * Mats = 0;
DFHack::Maps * Maps = 0; DFHack::Maps * Maps = 0;
@ -392,6 +411,13 @@ main(int argc, char *argv[])
uint32_t blockaddr2 = 0; uint32_t blockaddr2 = 0;
t_blockflags bflags; t_blockflags bflags;
bflags.whole = 0; bflags.whole = 0;
enum e_tempmode
{
TEMP_NO,
TEMP_1,
TEMP_2
};
e_tempmode temperature = TEMP_NO;
// resume so we don't block DF while we wait for input // resume so we don't block DF while we wait for input
DF.Resume(); DF.Resume();
@ -451,6 +477,15 @@ main(int argc, char *argv[])
case 't': case 't':
dotwiddle = true; dotwiddle = true;
break; break;
case 'b':
temperature = TEMP_NO;
break;
case 'n':
temperature = TEMP_1;
break;
case 'm':
temperature = TEMP_2;
break;
default: default:
break; break;
} }
@ -520,6 +555,9 @@ main(int argc, char *argv[])
} }
Maps->WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation)); Maps->WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation));
} }
// read temperature data
Maps->ReadTemperatures(cursorX+i,cursorY+j,cursorZ,&b_temp1, &b_temp2 );
if(dotwiddle) if(dotwiddle)
{ {
bitset<32> bs = Block->designation[0][0].whole; bitset<32> bs = Block->designation[0][0].whole;
@ -528,6 +566,7 @@ main(int argc, char *argv[])
Maps->WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation)); Maps->WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation));
dotwiddle = false; dotwiddle = false;
} }
// do a dump of the block data // do a dump of the block data
if(dump) if(dump)
{ {
@ -588,11 +627,11 @@ main(int argc, char *argv[])
} }
*/ */
} }
gotoxy(0,48); gotoxy(50,0);
cprintf("arrow keys, PGUP, PGDN = navigate"); cprintf("arrow keys, PGUP, PGDN = navigate");
gotoxy(0,49); gotoxy(50,1);
cprintf("+,- = switch vein"); cprintf("+,- = switch vein");
gotoxy(0,50); gotoxy(50,2);
uint32_t mineralsize = veinVector.size(); uint32_t mineralsize = veinVector.size();
uint32_t icesize = IceVeinVector.size(); uint32_t icesize = IceVeinVector.size();
uint32_t splattersize = splatter.size(); uint32_t splattersize = splatter.size();
@ -630,7 +669,7 @@ main(int argc, char *argv[])
} }
} }
} }
gotoxy(0,51); gotoxy(50,3);
cprintf("Mineral: %s",stonetypes[veinVector[vein].type].id); cprintf("Mineral: %s",stonetypes[veinVector[vein].type].id);
} }
else if (vein < mineralsize + icesize) else if (vein < mineralsize + icesize)
@ -650,7 +689,7 @@ main(int argc, char *argv[])
attroff(A_STANDOUT); attroff(A_STANDOUT);
} }
} }
gotoxy(0,51); gotoxy(50,3);
cprintf("ICE"); cprintf("ICE");
} }
else else
@ -670,25 +709,78 @@ main(int argc, char *argv[])
} }
} }
} }
gotoxy(0,51); gotoxy(50,3);
cprintf("Spatter: %s",PrintSplatterType(splatter[realvein].mat1,splatter[realvein].mat2,creature_types).c_str()); cprintf("Spatter: %s",PrintSplatterType(splatter[realvein].mat1,splatter[realvein].mat2,creature_types).c_str());
} }
} }
} }
mapblock40d * Block = &blocks[1][1]; mapblock40d * Block = &blocks[1][1];
for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++) t_temperatures * ourtemp;
if(temperature == TEMP_NO)
{ {
if((Block->occupancy[x][y].whole & (1 << twiddle))) for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++)
{ {
putch(x + 16,y + 16,'@',COLOR_WHITE); if((Block->occupancy[x][y].whole & (1 << twiddle)))
{
putch(x + 16,y + 16,'@',COLOR_WHITE);
}
}
}
else
{
if(temperature == TEMP_1)
ourtemp = &b_temp1;
else if(temperature == TEMP_2)
ourtemp = &b_temp2;
uint64_t sum = 0;
uint16_t min, max;
min = max = (*ourtemp)[0][0];
for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++)
{
uint16_t temp = (*ourtemp)[x][y];
if(temp < min) min = temp;
if(temp > max) max = temp;
sum += temp;
}
uint64_t average = sum/256;
gotoxy (50,8);
if(temperature == TEMP_1)
cprintf ("temperature1 [°U] (min,avg,max): %d,%d,%d", min, average, max);
else if(temperature == TEMP_2)
cprintf ("temperature2 [°U] (min,avg,max): %d,%d,%d", min, average, max);
for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++)
{
int32_t temper = (int32_t) (*ourtemp)[x][y];
temper -= average;
uint32_t abs_temp = abs(temper);
int color;
unsigned char character = ' ';
if(temper >= 0)
color = COLOR_RED;
else
color = COLOR_BLUE;
for(int i = 0; i < NUM_LIMITS; i++)
{
if(temp_limits[i].limit < abs_temp)
character = temp_limits[i].character;
else break;
}
if( character != ' ')
{
putch(x + 16,y + 16,character,color);
}
} }
} }
gotoxy (0,52); gotoxy (50,4);
cprintf("block address 0x%x, flags 0x%08x",blockaddr, bflags.whole); cprintf("block address 0x%x, flags 0x%08x",blockaddr, bflags.whole);
gotoxy (0,53); gotoxy (50,5);
cprintf("dirty bit: %d, twiddle: %d",dirtybit,twiddle); cprintf("dirty bit: %d, twiddle: %d",dirtybit,twiddle);
gotoxy (0,54); gotoxy (50,6);
cprintf ("d - dig veins, o - dump map block, z - toggle dirty bit"); cprintf ("d - dig veins, o - dump map block, z - toggle dirty bit");
gotoxy (50,7);
cprintf ("b - no temperature, n - temperature 1, m - temperature 2");
wrefresh(stdscr); wrefresh(stdscr);
} }
pDF = 0; pDF = 0;

@ -1053,11 +1053,13 @@ size=212
Map stuff Map stuff
========= =========
<Address name="map_data">0x016AD718</Address> <Address name="map_data">0x016AD718</Address>
<Offset name="v_vein">0x08</Offset> <Offset name="map_data_vein_vector">0x08</Offset>
<Offset name="type">0x009A</Offset> <Offset name="map_data_type">0x009A</Offset>
<Offset name="designation">0x029C</Offset> <Offset name="map_data_designation">0x029C</Offset>
<Offset name="occupancy">0x069c</Offset> <Offset name="map_data_occupancy">0x069c</Offset>
<Offset name="biome_stuffs">0x1D9C</Offset> <Offset name="map_data_temperature1_offset">0x159c</Offset>
<Offset name="map_data_temperature2_offset">0x179c</Offset>
<Offset name="map_data_biome_stuffs">0x1D9C</Offset>
<!-- <!--
map_data_map_x_offset 0x0058 map_data_map_x_offset 0x0058
map_data_map_y_offset 0x005A map_data_map_y_offset 0x005A

@ -36,6 +36,7 @@ int main (void)
bool end = false; bool end = false;
cout << "Welcome to the liquid spawner. type 'help' for a list of available commands, 'q' to quit." << endl; cout << "Welcome to the liquid spawner. type 'help' for a list of available commands, 'q' to quit." << endl;
string mode="magma"; string mode="magma";
string brush="point";
string flowmode="f+"; string flowmode="f+";
int amount = 7; int amount = 7;
while(!end) while(!end)
@ -55,6 +56,9 @@ int main (void)
<< "f. - don't change flow state (read state in flow mode)" << endl << "f. - don't change flow state (read state in flow mode)" << endl
<< "f- - make the spawned liquid static" << endl << "f- - make the spawned liquid static" << endl
<< "0-7 - set liquid amount" << endl << "0-7 - set liquid amount" << endl
<< "Brush:" << endl
<< "point - single tile" << endl
<< "block - block with cursor in it" << endl
<< "Other:" << endl << "Other:" << endl
<< "q - quit" << endl << "q - quit" << endl
<< "help - print this list of commands" << endl << "help - print this list of commands" << endl
@ -76,6 +80,14 @@ int main (void)
{ {
mode = "flowbits"; mode = "flowbits";
} }
else if(command == "point")
{
brush = "point";
}
else if(command == "block")
{
brush = "block";
}
else if(command == "q") else if(command == "q")
{ {
end = true; end = true;
@ -132,12 +144,27 @@ 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);
if(mode != "flowbits") if(brush == "point")
designations[x%16][y%16].bits.flow_size = amount; {
if(mode == "magma") if(mode != "flowbits")
designations[x%16][y%16].bits.liquid_type = DFHack::liquid_magma; designations[x%16][y%16].bits.flow_size = amount;
else if(mode == "water") if(mode == "magma")
designations[x%16][y%16].bits.liquid_type = DFHack::liquid_water; designations[x%16][y%16].bits.liquid_type = DFHack::liquid_magma;
else if(mode == "water")
designations[x%16][y%16].bits.liquid_type = DFHack::liquid_water;
}
else
{
for(uint32_t xx = 0; xx < 16; xx++) for(uint32_t yy = 0; yy < 16; yy++)
{
if(mode != "flowbits")
designations[xx][yy].bits.flow_size = amount;
if(mode == "magma")
designations[xx][yy].bits.liquid_type = DFHack::liquid_magma;
else if(mode == "water")
designations[xx][yy].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 :)