2009-10-04 07:08:20 -06:00
|
|
|
/*
|
|
|
|
www.sourceforge.net/projects/dfhack
|
|
|
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SIMPLEAPI_H_INCLUDED
|
|
|
|
#define SIMPLEAPI_H_INCLUDED
|
|
|
|
|
2010-02-26 14:22:10 -07:00
|
|
|
#include "Tranquility.h"
|
2009-11-13 20:46:56 -07:00
|
|
|
#include "Export.h"
|
2009-10-04 07:08:20 -06:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2009-12-12 12:52:30 -07:00
|
|
|
#include <map>
|
2009-10-23 12:05:42 -06:00
|
|
|
#include "integers.h"
|
2009-11-22 07:43:53 -07:00
|
|
|
#include "DFTileTypes.h"
|
2010-02-26 14:22:10 -07:00
|
|
|
#include "DFTypes.h"
|
2009-12-22 14:19:39 -07:00
|
|
|
#include "DFWindow.h"
|
2009-10-04 07:08:20 -06:00
|
|
|
|
2009-11-10 20:37:28 -07:00
|
|
|
namespace DFHack
|
2009-10-04 07:08:20 -06:00
|
|
|
{
|
2009-11-13 20:46:56 -07:00
|
|
|
class memory_info;
|
2009-11-14 21:25:00 -07:00
|
|
|
class Process;
|
2009-11-13 20:46:56 -07:00
|
|
|
class DFHACK_EXPORT API
|
|
|
|
{
|
|
|
|
class Private;
|
|
|
|
Private * const d;
|
|
|
|
public:
|
2010-02-26 14:22:10 -07:00
|
|
|
API(const std::string path_to_xml);
|
2009-11-13 20:46:56 -07:00
|
|
|
~API();
|
|
|
|
bool Attach();
|
|
|
|
bool Detach();
|
|
|
|
bool isAttached();
|
2009-12-12 21:43:06 -07:00
|
|
|
|
|
|
|
//true if paused, false if not
|
|
|
|
bool ReadPauseState();
|
|
|
|
|
2010-01-18 09:44:24 -07:00
|
|
|
// read the DF menu view state (stock screen, unit screen, other screens
|
2009-12-12 12:52:30 -07:00
|
|
|
bool ReadViewScreen(t_viewscreen &);
|
|
|
|
|
2010-01-18 09:44:24 -07:00
|
|
|
// read the DF menu state (designation menu ect)
|
|
|
|
uint32_t ReadMenuState();
|
2009-11-16 09:47:22 -07:00
|
|
|
|
2009-11-18 18:48:18 -07:00
|
|
|
// stop DF from executing
|
2009-11-16 09:47:22 -07:00
|
|
|
bool Suspend();
|
2010-01-01 19:25:21 -07:00
|
|
|
// stop DF from executing, asynchronous, use with polling
|
|
|
|
bool AsyncSuspend();
|
2009-11-18 18:48:18 -07:00
|
|
|
// resume DF
|
2009-11-16 09:47:22 -07:00
|
|
|
bool Resume();
|
2009-11-18 18:48:18 -07:00
|
|
|
/**
|
2009-12-12 21:43:06 -07:00
|
|
|
* Force resume
|
2009-11-18 18:48:18 -07:00
|
|
|
* be careful with this one
|
|
|
|
*/
|
|
|
|
bool ForceResume();
|
2009-11-16 09:47:22 -07:00
|
|
|
bool isSuspended();
|
2009-11-13 20:46:56 -07:00
|
|
|
/**
|
|
|
|
* Matgloss. next four methods look very similar. I could use two and move the processing one level up...
|
|
|
|
* I'll keep it like this, even with the code duplication as it will hopefully get more features and separate data types later.
|
|
|
|
* Yay for nebulous plans for a rock survey tool that tracks how much of which metal could be smelted from available resorces
|
|
|
|
*/
|
2010-02-26 14:22:10 -07:00
|
|
|
bool ReadStoneMatgloss(std::vector<t_matgloss> & output);
|
|
|
|
bool ReadWoodMatgloss (std::vector<t_matgloss> & output);
|
|
|
|
bool ReadMetalMatgloss(std::vector<t_matgloss> & output);
|
|
|
|
bool ReadPlantMatgloss(std::vector<t_matgloss> & output);
|
|
|
|
bool ReadPlantMatgloss (std::vector<t_matglossPlant> & plants);
|
|
|
|
bool ReadCreatureMatgloss(std::vector<t_matgloss> & output);
|
2009-11-13 20:46:56 -07:00
|
|
|
|
|
|
|
// read region surroundings, get their vectors of geolayers so we can do translation (or just hand the translation table to the client)
|
|
|
|
// returns an array of 9 vectors of indices into stone matgloss
|
|
|
|
/**
|
|
|
|
Method for reading the geological surrounding of the currently loaded region.
|
|
|
|
assign is a reference to an array of nine vectors of unsigned words that are to be filled with the data
|
|
|
|
array is indexed by the BiomeOffset enum
|
|
|
|
|
|
|
|
I omitted resolving the layer matgloss in this API, because it would
|
|
|
|
introduce overhead by calling some method for each tile. You have to do it
|
|
|
|
yourself. First get the stuff from ReadGeology and then for each block get
|
|
|
|
the RegionOffsets. For each tile get the real region from RegionOffsets and
|
|
|
|
cross-reference it with the geology stuff (region -- array of vectors, depth --
|
|
|
|
vector). I'm thinking about turning that Geology stuff into a
|
|
|
|
two-dimensional array with static size.
|
|
|
|
|
|
|
|
this is the algorithm for applying matgloss:
|
|
|
|
void DfMap::applyGeoMatgloss(Block * b)
|
2009-10-04 07:08:20 -06:00
|
|
|
{
|
2009-11-13 20:46:56 -07:00
|
|
|
// load layer matgloss
|
|
|
|
for(int x_b = 0; x_b < BLOCK_SIZE; x_b++)
|
2009-10-04 07:08:20 -06:00
|
|
|
{
|
2009-11-13 20:46:56 -07:00
|
|
|
for(int y_b = 0; y_b < BLOCK_SIZE; y_b++)
|
|
|
|
{
|
|
|
|
int geolayer = b->designation[x_b][y_b].bits.geolayer_index;
|
|
|
|
int biome = b->designation[x_b][y_b].bits.biome;
|
|
|
|
b->material[x_b][y_b].type = Mat_Stone;
|
|
|
|
b->material[x_b][y_b].index = v_geology[b->RegionOffsets[biome]][geolayer];
|
|
|
|
}
|
2009-10-04 07:08:20 -06:00
|
|
|
}
|
|
|
|
}
|
2009-11-13 20:46:56 -07:00
|
|
|
*/
|
2010-02-26 14:22:10 -07:00
|
|
|
bool ReadGeology( std::vector < std::vector <uint16_t> >& assign );
|
2009-11-13 20:46:56 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* BLOCK DATA
|
|
|
|
*/
|
|
|
|
/// allocate and read pointers to map blocks
|
|
|
|
bool InitMap();
|
|
|
|
/// destroy the mapblock cache
|
|
|
|
bool DestroyMap();
|
|
|
|
/// get size of the map in tiles
|
|
|
|
void getSize(uint32_t& x, uint32_t& y, uint32_t& z);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return false/0 on failure, buffer allocated by client app, 256 items long
|
|
|
|
*/
|
|
|
|
bool isValidBlock(uint32_t blockx, uint32_t blocky, uint32_t blockz);
|
2010-02-17 18:10:39 -07:00
|
|
|
/**
|
|
|
|
* Get the address of a block or 0 if block is not valid
|
|
|
|
*/
|
2010-02-27 17:25:04 -07:00
|
|
|
uint32_t getBlockPtr (uint32_t blockx, uint32_t blocky, uint32_t blockz);
|
2009-11-13 20:46:56 -07:00
|
|
|
|
2010-03-04 16:05:01 -07:00
|
|
|
bool ReadBlock40d(uint32_t blockx, uint32_t blocky, uint32_t blockz, mapblock40d * buffer);
|
|
|
|
|
2009-11-13 20:46:56 -07:00
|
|
|
bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); // 256 * sizeof(uint16_t)
|
|
|
|
bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); // 256 * sizeof(uint16_t)
|
|
|
|
|
|
|
|
bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t)
|
|
|
|
bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer);
|
|
|
|
|
|
|
|
bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t)
|
|
|
|
bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t)
|
2010-02-20 08:33:30 -07:00
|
|
|
|
|
|
|
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);
|
2010-02-20 04:58:52 -07:00
|
|
|
|
2009-11-13 20:46:56 -07:00
|
|
|
/// read region offsets of a block
|
|
|
|
bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer); // 16 * sizeof(uint8_t)
|
|
|
|
|
|
|
|
/// read aggregated veins of a block
|
2010-02-26 14:22:10 -07:00
|
|
|
bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, std::vector <t_vein> & veins, std::vector <t_frozenliquidvein>& ices);
|
2009-11-13 20:46:56 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Buildings, constructions, plants, all pretty straighforward. InitReadBuildings returns all the building types as a mapping between a numeric values and strings
|
|
|
|
*/
|
2010-02-11 14:08:39 -07:00
|
|
|
bool InitReadConstructions( uint32_t & numconstructions );
|
2010-02-27 17:25:04 -07:00
|
|
|
bool ReadConstruction(const int32_t index, t_construction & construction);
|
2009-11-13 20:46:56 -07:00
|
|
|
void FinishReadConstructions();
|
|
|
|
|
2010-02-13 09:19:11 -07:00
|
|
|
bool InitReadBuildings ( uint32_t & numbuildings );
|
2010-02-27 17:25:04 -07:00
|
|
|
bool ReadBuilding(const int32_t index, t_building & building);
|
2009-11-13 20:46:56 -07:00
|
|
|
void FinishReadBuildings();
|
|
|
|
|
2010-02-11 14:08:39 -07:00
|
|
|
bool InitReadVegetation( uint32_t & numplants );
|
2010-02-27 17:25:04 -07:00
|
|
|
bool ReadVegetation(const int32_t index, t_tree_desc & shrubbery);
|
2009-11-13 20:46:56 -07:00
|
|
|
void FinishReadVegetation();
|
|
|
|
|
2010-02-13 09:19:11 -07:00
|
|
|
bool InitReadCreatures( uint32_t & numcreatures );
|
2009-12-12 21:43:06 -07:00
|
|
|
/// returns index of creature actually read or -1 if no creature can be found
|
2010-02-27 17:25:04 -07:00
|
|
|
int32_t ReadCreatureInBox(const int32_t index, t_creature & furball,
|
|
|
|
const uint16_t x1, const uint16_t y1,const uint16_t z1,
|
|
|
|
const uint16_t x2, const uint16_t y2,const uint16_t z2);
|
|
|
|
bool ReadCreature(const int32_t index, t_creature & furball);
|
2009-11-13 20:46:56 -07:00
|
|
|
void FinishReadCreatures();
|
|
|
|
|
2010-02-27 17:25:04 -07:00
|
|
|
void ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target);
|
|
|
|
void WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source);
|
2009-11-13 20:46:56 -07:00
|
|
|
|
|
|
|
bool InitViewAndCursor();
|
2010-02-17 16:33:08 -07:00
|
|
|
|
2010-02-18 10:06:32 -07:00
|
|
|
bool InitReadNotes( uint32_t & numnotes );
|
2010-02-27 17:25:04 -07:00
|
|
|
bool ReadNote(const int32_t index, t_note & note);
|
2010-02-18 10:06:32 -07:00
|
|
|
void FinishReadNotes();
|
2010-02-17 19:08:54 -07:00
|
|
|
|
2010-02-26 14:22:10 -07:00
|
|
|
bool InitReadSettlements( uint32_t & numsettlements );
|
2010-02-27 17:25:04 -07:00
|
|
|
bool ReadSettlement(const int32_t index, t_settlement & settlement);
|
2010-02-26 14:22:10 -07:00
|
|
|
bool ReadCurrentSettlement(t_settlement & settlement);
|
2010-02-22 19:25:57 -07:00
|
|
|
void FinishReadSettlements();
|
|
|
|
|
2010-02-18 10:06:32 -07:00
|
|
|
bool InitReadHotkeys( );
|
|
|
|
bool ReadHotkeys(t_hotkey hotkeys[]);
|
2009-11-13 20:46:56 -07:00
|
|
|
|
|
|
|
bool getViewCoords (int32_t &x, int32_t &y, int32_t &z);
|
2010-02-27 17:25:04 -07:00
|
|
|
bool setViewCoords (const int32_t x, const int32_t y, const int32_t z);
|
2009-11-13 20:46:56 -07:00
|
|
|
|
|
|
|
bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z);
|
2010-02-27 17:25:04 -07:00
|
|
|
bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z);
|
2009-11-17 20:35:43 -07:00
|
|
|
|
2009-12-12 21:43:06 -07:00
|
|
|
/// This returns false if there is nothing under the cursor, it puts the addresses in a vector if there is
|
2010-02-26 14:22:10 -07:00
|
|
|
bool getCurrentCursorCreatures(std::vector<uint32_t> &addresses);
|
2009-12-12 12:52:30 -07:00
|
|
|
|
2009-11-17 20:35:43 -07:00
|
|
|
bool InitViewSize();
|
|
|
|
bool getWindowSize(int32_t & width, int32_t & height);
|
2010-02-26 14:22:10 -07:00
|
|
|
/* unimplemented
|
2009-11-17 20:35:43 -07:00
|
|
|
bool setWindowSize(const int32_t & width, const int32_t & height);
|
2010-02-26 14:22:10 -07:00
|
|
|
*/
|
2009-11-17 20:35:43 -07:00
|
|
|
|
2010-02-27 17:25:04 -07:00
|
|
|
bool getItemIndexesInBox(std::vector<uint32_t> &indexes,
|
|
|
|
const uint16_t x1, const uint16_t y1, const uint16_t z1,
|
|
|
|
const uint16_t x2, const uint16_t y2, const uint16_t z2);
|
2009-11-13 20:46:56 -07:00
|
|
|
/*
|
|
|
|
// FIXME: add a real creature class, move these
|
|
|
|
string getLastName(const uint32_t &index, bool);
|
|
|
|
string getSquadName(const uint32_t &index, bool);
|
|
|
|
string getProfession(const uint32_t &index);
|
|
|
|
string getCurrentJob(const uint32_t &index);
|
|
|
|
vector<t_skill> getSkills(const uint32_t &index);
|
|
|
|
vector<t_trait> getTraits(const uint32_t &index);
|
|
|
|
vector<t_labor> getLabors(const uint32_t &index);
|
|
|
|
*/
|
2010-03-04 23:02:41 -07:00
|
|
|
bool InitReadNameTables (std::vector< std::vector<std::string> > & translations , std::vector< std::vector<std::string> > & foreign_languages);
|
2009-11-13 20:46:56 -07:00
|
|
|
void FinishReadNameTables();
|
2009-11-17 07:52:47 -07:00
|
|
|
|
2010-03-04 23:02:41 -07:00
|
|
|
std::string TranslateName(const t_name & name,const std::vector< std::vector<std::string> > & translations ,const std::vector< std::vector<std::string> > & foreign_languages, bool inEnglish=true);
|
2009-12-31 19:14:41 -07:00
|
|
|
|
2010-02-27 17:25:04 -07:00
|
|
|
void WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]);
|
2009-12-31 19:14:41 -07:00
|
|
|
|
2010-02-11 14:08:39 -07:00
|
|
|
bool InitReadItems(uint32_t & numitems);
|
2010-02-27 17:25:04 -07:00
|
|
|
bool ReadItem(const uint32_t index, t_item & item);
|
2009-11-17 07:52:47 -07:00
|
|
|
void FinishReadItems();
|
2010-02-25 05:41:57 -07:00
|
|
|
|
2010-02-22 15:34:20 -07:00
|
|
|
memory_info *getMemoryInfo();
|
2009-11-14 21:25:00 -07:00
|
|
|
Process * getProcess();
|
2009-12-22 14:19:39 -07:00
|
|
|
DFWindow * getWindow();
|
2009-12-31 19:30:35 -07:00
|
|
|
/*
|
|
|
|
// FIXME: BAD!
|
|
|
|
bool ReadAllMatgloss(vector< vector< string > > & all);
|
|
|
|
*/
|
2010-02-26 14:22:10 -07:00
|
|
|
bool ReadItemTypes(std::vector< std::vector< t_itemType > > & itemTypes);
|
2009-11-13 20:46:56 -07:00
|
|
|
};
|
2009-11-11 18:05:07 -07:00
|
|
|
} // namespace DFHack
|
2009-10-04 07:08:20 -06:00
|
|
|
#endif // SIMPLEAPI_H_INCLUDED
|