diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 648868335..9a8dfb791 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -59,7 +59,7 @@ TARGET_LINK_LIBRARIES(dfvecc dfhack) IF(UNIX) # veinlook - look at the map... sort of ADD_EXECUTABLE(dfveinlook veinlook.cpp) - TARGET_LINK_LIBRARIES(dfveinlook dfhack ncurses) + TARGET_LINK_LIBRARIES(dfveinlook dfhack ncursesw) ENDIF(UNIX) # renamer - change the custom names and professions of creatures, sends keys to df directly diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index 911e13170..5b085757a 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -15,13 +15,15 @@ using namespace std; #include using namespace DFHack; #include -#include +#include #include #include +#include string error; API * pDF = 0; + static void finish(int sig); int gotoxy(int x, int y) @@ -36,6 +38,12 @@ int putch(int x, int y, int znak, int color) mvwaddch(stdscr, y, x, znak); attroff(COLOR_PAIR(color)); } +int putwch(int x, int y, int znak, int color) +{ + attron(COLOR_PAIR(color)); + mvwaddch(stdscr, y, x, znak); + attroff(COLOR_PAIR(color)); +} /* enum TileClass { @@ -71,6 +79,11 @@ int puttile(int x, int y, int tiletype, int color) znak = ' '; break; case WALL: + attron(COLOR_PAIR(color)); + mvwaddwstr(stdscr, y, x, L"\u2593"); + attroff(COLOR_PAIR(color)); + //znak = ; + return 0; case FORTIFICATION: znak = '#'; break; @@ -235,7 +248,7 @@ main(int argc, char *argv[]) /* initialize your non-curses data structures here */ signal(SIGINT, finish); /* arrange interrupts to terminate */ - + setlocale(LC_ALL,""); initscr(); /* initialize the curses library */ keypad(stdscr, TRUE); /* enable keyboard mapping */ nonl(); /* tell curses not to do NL->CR/NL on output */ @@ -279,6 +292,7 @@ main(int argc, char *argv[]) materials.clear(); mapblock40d blocks[3][3]; vector stonetypes; + vector effects; vector< vector > layerassign; vector veinVector; vector IceVeinVector; @@ -402,14 +416,26 @@ main(int argc, char *argv[]) memset(blocks,0,sizeof(blocks)); veinVector.clear(); IceVeinVector.clear(); + effects.clear(); dirtybit = 0; // Supend, read/write data DF.Suspend(); + uint32_t effectnum; + if(DF.InitReadEffects(effectnum)) + { + for(uint32_t i = 0; i < effectnum;i++) + { + t_effect_df40d effect; + DF.ReadEffect(i,effect); + effects.push_back(effect); + } + } for(int i = -1; i <= 1; i++) for(int j = -1; j <= 1; j++) { mapblock40d * Block = &blocks[i+1][j+1]; + if(DF.isValidBlock(cursorX+i,cursorY+j,cursorZ)) { DF.ReadBlock40d(cursorX+i,cursorY+j,cursorZ, Block); @@ -463,17 +489,35 @@ main(int argc, char *argv[]) { int color = COLOR_BLACK; color = pickColor(Block->tiletypes[x][y]); - if(Block->designaton[x][y].bits.hidden) - { + if(!Block->designaton[x][y].bits.hidden) + /*{ puttile(x+(i+1)*16,y+(j+1)*16,Block->tiletypes[x][y], color); } - else + else*/ { attron(A_STANDOUT); puttile(x+(i+1)*16,y+(j+1)*16,Block->tiletypes[x][y], color); attroff(A_STANDOUT); } } + // print effects for the center tile + + if(i == 0 && j == 0) + { + for(uint zz = 0; zz < effects.size();zz++) + { + if(effects[zz].z == cursorZ && !effects[zz].isHidden) + { + // block coords to tile coords + uint16_t x = effects[zz].x - (cursorX * 16); + uint16_t y = effects[zz].y - (cursorY * 16); + if(x < 16 && y < 16) + { + putch(x + 16,y + 16,'@',COLOR_WHITE); + } + } + } + } } gotoxy(0,48); cprintf("arrow keys, PGUP, PGDN = navigate"); @@ -500,6 +544,10 @@ main(int argc, char *argv[]) //iterate through the bits for (uint32_t k = 0; k< 16;k++) { + if(tileTypeTable[blocks[1][1].tiletypes[k][j]].m != VEIN) + continue; + if(blocks[1][1].designaton[k][j].bits.hidden) + continue; // and the bit array with a one-bit mask, check if the bit is set bool set = !!(((1 << k) & veinVector[realvein].assignment[j]) >> k); if(set) diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index f2d31b21d..345190834 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -124,6 +124,7 @@ public: bool constructionsInited; bool buildingsInited; + bool effectsInited; bool vegetationInited; bool creaturesInited; bool cursorWindowInited; @@ -141,6 +142,7 @@ public: DfVector *p_cre; DfVector *p_cons; DfVector *p_bld; + DfVector *p_effect; DfVector *p_veg; DfVector *p_itm; DfVector *p_notes; @@ -174,12 +176,15 @@ API::API (const string path_to_xml) d->constructionsInited = false; d->creaturesInited = false; d->buildingsInited = false; + d->effectsInited = false; d->vegetationInited = false; d->cursorWindowInited = false; d->viewSizeInited = false; d->itemsInited = false; d->notesInited = false; d->hotkeyInited = false; + d->namesInited = false; + d->nameTablesInited = false; d->pm = NULL; d->shm_start = 0; d->maps_module = 0; @@ -854,6 +859,55 @@ void API::FinishReadBuildings() d->buildingsInited = false; } +bool API::InitReadEffects ( uint32_t & numeffects ) +{ + if(d->effectsInited) + FinishReadEffects(); + int effects = d->offset_descriptor->getAddress ("effects_vector"); + d->effectsInited = true; + d->p_effect = new DfVector (d->p->readVector (effects, 4)); + numeffects = d->p_effect->getSize(); + return true; +} + +bool API::ReadEffect(const int32_t index, t_effect_df40d & effect) +{ + if(!d->effectsInited) + return false; + if(index >= d->p_effect->getSize()) + return false; + + // read pointer from vector at position + uint32_t temp = * (uint32_t *) d->p_effect->at (index); + //read effect from memory + g_pProcess->read (temp, sizeof (t_effect_df40d), (uint8_t *) &effect); + return true; +} + +// use with care! +bool API::WriteEffect(const int32_t index, const t_effect_df40d & effect) +{ + if(!d->effectsInited) + return false; + if(index >= d->p_effect->getSize()) + return false; + // read pointer from vector at position + uint32_t temp = * (uint32_t *) d->p_effect->at (index); + // write effect to memory + g_pProcess->write(temp,sizeof(t_effect_df40d), (uint8_t *) &effect); + return true; +} + +void API::FinishReadEffects() +{ + if(d->p_effect) + { + delete d->p_effect; + d->p_effect = NULL; + } + d->effectsInited = false; +} + //TODO: maybe do construction reading differently - this could go slow with many of them. // returns number of constructions, prepares a vector, returns total number of constructions diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index e54d49a4b..842977107 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -165,6 +165,11 @@ namespace DFHack bool InitReadBuildings ( uint32_t & numbuildings ); bool ReadBuilding(const int32_t index, t_building & building); void FinishReadBuildings(); + + bool InitReadEffects ( uint32_t & numeffects ); + bool ReadEffect(const int32_t index, t_effect_df40d & effect); + bool WriteEffect(const int32_t index, const t_effect_df40d & effect); + void FinishReadEffects(); bool InitReadVegetation( uint32_t & numplants ); bool ReadVegetation(const int32_t index, t_tree_desc & shrubbery); diff --git a/library/DFProcess-linux-SHM.cpp b/library/DFProcess-linux-SHM.cpp index 2f224c8b4..2a3ed4787 100644 --- a/library/DFProcess-linux-SHM.cpp +++ b/library/DFProcess-linux-SHM.cpp @@ -103,7 +103,8 @@ bool SHMProcess::Private::SetAndWait (uint32_t state) SHMCMD = state; while (SHMCMD == state) { - if(cnt == 10000)// check if the other process is still there, don't hammer the kernel too much. + // check if the other process is still there + if(cnt == 10000) { if(!AreLocksOk()) { @@ -135,7 +136,8 @@ bool SHMProcess::Private::SetAndWait (uint32_t state) } /* -Yeah. with no way to synchronize things (locks are slow, the OS doesn't give us enough control over scheduling) +Yeah. with no way to synchronize things (locks are slow, the OS doesn't give us +enough control over scheduling) we end up with this silly thing */ bool SHMProcess::SetAndWait (uint32_t state) diff --git a/library/DFTypes.h b/library/DFTypes.h index bc369bb3e..6c6f3871e 100644 --- a/library/DFTypes.h +++ b/library/DFTypes.h @@ -31,6 +31,28 @@ distribution. namespace DFHack { +template +struct junk_fill +{ + uint8_t data[SIZE]; + /* + void Dump() + { + cout< unk4; + uint8_t canCreateNew;//?? + uint8_t isHidden; +}; + // raw struct t_construction_df40d { diff --git a/output/Memory.xml b/output/Memory.xml index 2fc809da7..c4851e740 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1895,9 +1895,11 @@ 4f55a1dcc326786271f221de23c425b5 + 022b933926e08da49c6df8649295f2b7 +
0x0893F2D0
8f55a6250f2550e28535b79db43d5f1a @@ -1930,6 +1932,7 @@
0x08fa2d50
0x08fa2d54
0x08fa2d58
+
0x08947438
777e7d674d8908042307994cb75250ff @@ -1962,6 +1965,7 @@
0x09049cf0
0x09049cf4
0x09049cf8
+
0x089EE3D8
04c3ad13c657f59ba6fc135e156d721d @@ -1994,6 +1998,7 @@
0x09048d10
0x09048d14
0x09048d18
+
0x089ED3F8