Merge branch 'master' of git://github.com/peterix/dfhack
						commit
						0083cfe347
					
				| @ -0,0 +1,58 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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 BUILDINGS_C_API | ||||
| #define BUILDINGS_C_API | ||||
| 
 | ||||
| #include "Export.h" | ||||
| #include "integers.h" | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Buildings.h" | ||||
| #include "DFHackAPI_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| struct t_customWorkshop | ||||
| { | ||||
| 	uint32_t index; | ||||
| 	char name[256]; | ||||
| }; | ||||
| 
 | ||||
| DFHACK_EXPORT int Buildings_Start(DFHackObject* b_Ptr, uint32_t* numBuildings); | ||||
| DFHACK_EXPORT int Buildings_Finish(DFHackObject* b_Ptr); | ||||
| 
 | ||||
| DFHACK_EXPORT int Buildings_Read(DFHackObject* b_Ptr, const uint32_t index, t_building* building); | ||||
| 
 | ||||
| DFHACK_EXPORT int Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr, void* (*t_customWorkshop_buffer_create)(uint32_t)); | ||||
| DFHACK_EXPORT int Buildings_GetCustomWorkshopType(DFHackObject* b_Ptr, t_building* building); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif | ||||
| @ -0,0 +1,49 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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 CONSTRUCTIONS_C_API | ||||
| #define CONSTRUCTIONS_C_API | ||||
| 
 | ||||
| #include "Export.h" | ||||
| #include "integers.h" | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Constructions.h" | ||||
| #include "DFHackAPI_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| DFHACK_EXPORT int Constructions_Start(DFHackObject* c_Ptr, uint32_t* numConstructions); | ||||
| DFHACK_EXPORT int Constructions_Finish(DFHackObject* c_Ptr); | ||||
| 
 | ||||
| DFHACK_EXPORT int Constructions_Read(DFHackObject* c_Ptr, const uint32_t index, t_construction* construction); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif | ||||
| @ -0,0 +1,60 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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 CREATURES_C_API | ||||
| #define CREATURES_C_API | ||||
| 
 | ||||
| #include "Export.h" | ||||
| #include "integers.h" | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Materials.h" | ||||
| #include "modules/Creatures.h" | ||||
| #include "DFHackAPI_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| DFHACK_EXPORT int Creatures_Start(DFHackObject* cPtr, uint32_t* numCreatures); | ||||
| DFHACK_EXPORT int Creatures_Finish(DFHackObject* cPtr); | ||||
| 
 | ||||
| DFHACK_EXPORT int32_t Creatures_ReadCreatureInBox(DFHackObject* cPtr, 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); | ||||
| 
 | ||||
| DFHACK_EXPORT int Creatures_ReadCreature(DFHackObject* cPtr, const int32_t index, t_creature* furball); | ||||
| DFHACK_EXPORT int Creatures_WriteLabors(DFHackObject* cPtr, const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]); | ||||
| 
 | ||||
| DFHACK_EXPORT uint32_t Creatures_GetDwarfRaceIndex(DFHackObject* cPtr); | ||||
| DFHACK_EXPORT int32_t Creatures_GetDwarfCivId(DFHackObject* cPtr); | ||||
| 
 | ||||
| DFHACK_EXPORT int Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball, t_material* (*t_material_buffer_create)(int)); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif | ||||
| @ -0,0 +1,48 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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 ITEMS_C_API | ||||
| #define ITEMS_C_API | ||||
| 
 | ||||
| #include "Export.h" | ||||
| #include "integers.h" | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Items.h" | ||||
| #include "DFHackAPI_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| DFHACK_EXPORT char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObject* mats, char* (*char_buffer_create)(int)); | ||||
| DFHACK_EXPORT char* Items_getItemClass(DFHackObject* items, int32_t index, char* (*char_buffer_create)(int)); | ||||
| DFHACK_EXPORT int Items_getItemData(DFHackObject* items, uint32_t itemptr, t_item* item); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif | ||||
| @ -0,0 +1,86 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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 MAPS_C_API | ||||
| #define MAPS_C_API | ||||
| 
 | ||||
| #include "Export.h" | ||||
| #include "integers.h" | ||||
| #include <vector> | ||||
| #include <map> | ||||
| #include <string> | ||||
| 
 | ||||
| using namespace std; | ||||
| 
 | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Maps.h" | ||||
| #include "DFHackAPI_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| DFHACK_EXPORT int Maps_Start(DFHackObject* maps); | ||||
| DFHACK_EXPORT int Maps_Finish(DFHackObject* maps); | ||||
| 
 | ||||
| DFHACK_EXPORT void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z); | ||||
| DFHACK_EXPORT int Maps_isValidBlock(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); | ||||
| 
 | ||||
| DFHACK_EXPORT uint32_t Maps_getBlockPtr(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); | ||||
| 
 | ||||
| DFHACK_EXPORT int Maps_ReadBlock40d(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, mapblock40d* buffer); | ||||
| 
 | ||||
| DFHACK_EXPORT int Maps_ReadTileTypes(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, tiletypes40d* buffer); | ||||
| DFHACK_EXPORT int Maps_WriteTileTypes(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, tiletypes40d* buffer); | ||||
| 
 | ||||
| DFHACK_EXPORT int Maps_ReadDesignations(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, designations40d* buffer); | ||||
| DFHACK_EXPORT int Maps_WriteDesignations(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, designations40d* buffer); | ||||
| 
 | ||||
| DFHACK_EXPORT int Maps_ReadTemperatures(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_temperatures* temp1, t_temperatures* temp2); | ||||
| DFHACK_EXPORT int Maps_WriteTemperatures(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_temperatures* temp1, t_temperatures* temp2); | ||||
| 
 | ||||
| DFHACK_EXPORT int Maps_ReadOccupancy(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, occupancies40d* buffer); | ||||
| DFHACK_EXPORT int Maps_WriteOccupancy(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, occupancies40d* buffer); | ||||
| 
 | ||||
| DFHACK_EXPORT int Maps_ReadDirtyBit(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, int* dirtybit); | ||||
| DFHACK_EXPORT int Maps_WriteDirtyBit(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, int dirtybit); | ||||
| 
 | ||||
| DFHACK_EXPORT int Maps_ReadFeatures(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, int16_t* local, int16_t* global); | ||||
| DFHACK_EXPORT int Maps_WriteLocalFeature(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, int16_t local); | ||||
| DFHACK_EXPORT int Maps_WriteEmptyLocalFeature(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); | ||||
| DFHACK_EXPORT int Maps_WriteGlobalFeature(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, int16_t local); | ||||
| DFHACK_EXPORT int Maps_WriteEmptyGlobalFeature(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); | ||||
| 
 | ||||
| DFHACK_EXPORT int Maps_ReadBlockFlags(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_blockflags* blockflags); | ||||
| DFHACK_EXPORT int Maps_WriteBlockFlags(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_blockflags blockflags); | ||||
| 
 | ||||
| DFHACK_EXPORT int Maps_ReadRegionOffsets(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, biome_indices40d* buffer); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif | ||||
| @ -0,0 +1,50 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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 TRANSLATION_C_API | ||||
| #define TRANSLATION_C_API | ||||
| 
 | ||||
| #include "Export.h" | ||||
| #include "integers.h" | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Translation.h" | ||||
| #include "DFHackAPI_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| DFHACK_EXPORT int Translation_Start(DFHackObject* trans); | ||||
| DFHACK_EXPORT int Translation_Finish(DFHackObject* trans); | ||||
| 
 | ||||
| DFHACK_EXPORT char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int)); | ||||
| DFHACK_EXPORT char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int)); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif | ||||
| @ -0,0 +1,49 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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 VEGETATION_C_API | ||||
| #define VEGETATION_C_API | ||||
| 
 | ||||
| #include "Export.h" | ||||
| #include "integers.h" | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Vegetation.h" | ||||
| #include "DFHackAPI_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| DFHACK_EXPORT int Vegetation_Start(DFHackObject* veg, uint32_t* numTrees); | ||||
| DFHACK_EXPORT int Vegetation_Finish(DFHackObject* veg); | ||||
| 
 | ||||
| DFHACK_EXPORT int Vegetation_Read(DFHackObject* veg, const uint32_t index, t_tree* shrubbery); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif | ||||
| @ -0,0 +1,116 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| #include "integers.h" | ||||
| #include <string> | ||||
| #include <map> | ||||
| #include "stdio.h" | ||||
| 
 | ||||
| using namespace std; | ||||
| 
 | ||||
| #include "DFCommonInternal.h" | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Buildings.h" | ||||
| #include "modules/Buildings_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| int Buildings_Start(DFHackObject* b_Ptr, uint32_t* numBuildings) | ||||
| { | ||||
| 	if(b_Ptr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Buildings*)b_Ptr)->Start(*numBuildings); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Buildings_Finish(DFHackObject* b_Ptr) | ||||
| { | ||||
| 	if(b_Ptr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Buildings*)b_Ptr)->Finish(); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Buildings_Read(DFHackObject* b_Ptr, const uint32_t index, t_building* building) | ||||
| { | ||||
| 	if(b_Ptr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Buildings*)b_Ptr)->Read(index, *building); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Buildings_GetCustomWorkshopType(DFHackObject* b_Ptr, t_building* building) | ||||
| { | ||||
| 	if(b_Ptr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Buildings*)b_Ptr)->GetCustomWorkshopType(*building); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr, void* (*t_customWorkshop_buffer_create)(uint32_t)) | ||||
| { | ||||
| 	if(b_Ptr != NULL) | ||||
| 	{ | ||||
| 		int i; | ||||
| 		t_customWorkshop* cw_Ptr; | ||||
| 		map<uint32_t, string> bTypes; | ||||
| 		map<uint32_t, string>::iterator bIter; | ||||
| 		 | ||||
| 		bool result = ((DFHack::Buildings*)b_Ptr)->ReadCustomWorkshopTypes(bTypes); | ||||
| 		 | ||||
| 		if(!result) | ||||
| 			return 0; | ||||
| 		 | ||||
| 		cw_Ptr = (t_customWorkshop*)((*t_customWorkshop_buffer_create)(bTypes.size())); | ||||
| 		 | ||||
| 		for(i = 0, bIter = bTypes.begin(); bIter != bTypes.end(); bIter++, i++) | ||||
| 		{ | ||||
| 			cw_Ptr[i].index = (*bIter).first; | ||||
| 			 | ||||
| 			size_t length = (*bIter).second.copy(cw_Ptr[i].name, 256); | ||||
| 			 | ||||
| 			cw_Ptr[i].name[length] = '\0'; | ||||
| 		} | ||||
| 		 | ||||
| 		return 1; | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| @ -0,0 +1,70 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| #include "integers.h" | ||||
| 
 | ||||
| #include "DFCommonInternal.h" | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Constructions.h" | ||||
| #include "modules/Constructions_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| int Constructions_Start(DFHackObject* c_Ptr, uint32_t* numConstructions) | ||||
| { | ||||
| 	if(c_Ptr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Constructions*)c_Ptr)->Start(*numConstructions); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Constructions_Finish(DFHackObject* c_Ptr) | ||||
| { | ||||
| 	if(c_Ptr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Constructions*)c_Ptr)->Finish(); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Constructions_Read(DFHackObject* c_Ptr, const uint32_t index, t_construction* construction) | ||||
| { | ||||
| 	if(c_Ptr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Constructions*)c_Ptr)->Read(index, *construction); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| @ -0,0 +1,143 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| #include "Export.h" | ||||
| #include "integers.h" | ||||
| #include <string> | ||||
| #include <vector> | ||||
| #include <algorithm> | ||||
| 
 | ||||
| using namespace std; | ||||
| 
 | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Materials.h" | ||||
| #include "modules/Creatures.h" | ||||
| #include "modules/Creatures_C.h" | ||||
| #include "DFHackAPI_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| int Creatures_Start(DFHackObject* cPtr, uint32_t* numCreatures) | ||||
| { | ||||
| 	if(cPtr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Creatures*)cPtr)->Start(*numCreatures); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Creatures_Finish(DFHackObject* cPtr) | ||||
| { | ||||
| 	if(cPtr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Creatures*)cPtr)->Finish(); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int32_t Creatures_ReadCreatureInBox(DFHackObject* cPtr, 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) | ||||
| { | ||||
| 	if(cPtr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Creatures*)cPtr)->ReadCreatureInBox(index, *furball, x1, y1, z1, x2, y2, z2); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Creatures_ReadCreature(DFHackObject* cPtr, const int32_t index, t_creature* furball) | ||||
| { | ||||
| 	if(cPtr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Creatures*)cPtr)->ReadCreature(index, *furball); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Creatures_WriteLabors(DFHackObject* cPtr, const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]) | ||||
| { | ||||
| 	if(cPtr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Creatures*)cPtr)->WriteLabors(index, labors); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| uint32_t Creatures_GetDwarfRaceIndex(DFHackObject* cPtr) | ||||
| { | ||||
| 	if(cPtr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Creatures*)cPtr)->GetDwarfRaceIndex(); | ||||
| 	} | ||||
| 	 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| int32_t Creatures_GetDwarfCivId(DFHackObject* cPtr) | ||||
| { | ||||
| 	if(cPtr != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Creatures*)cPtr)->GetDwarfCivId(); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball, t_material* (*t_material_buffer_create)(int)) | ||||
| { | ||||
| 	if(cPtr != NULL) | ||||
| 	{ | ||||
| 		std::vector<t_material> mat; | ||||
| 		 | ||||
| 		if(((DFHack::Creatures*)cPtr)->ReadJob(furball, mat)) | ||||
| 		{ | ||||
| 			t_material* buf = (*t_material_buffer_create)(mat.size()); | ||||
| 			 | ||||
| 			if(buf != NULL) | ||||
| 			{ | ||||
| 				copy(mat.begin(), mat.end(), buf); | ||||
| 				 | ||||
| 				return 1; | ||||
| 			} | ||||
| 			else | ||||
| 				return -1; | ||||
| 		} | ||||
| 		else | ||||
| 			return 0; | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| @ -0,0 +1,109 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| #include "integers.h" | ||||
| #include <string> | ||||
| 
 | ||||
| using namespace std; | ||||
| 
 | ||||
| #include "DFCommonInternal.h" | ||||
| #include "DFTypes.h" | ||||
| #include "DFHackAPI.h" | ||||
| #include "modules/Materials.h" | ||||
| #include "modules/Items.h" | ||||
| #include "modules/Items_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObject* mats, char* (*char_buffer_create)(int)) | ||||
| { | ||||
| 	if(items != NULL && mats != NULL) | ||||
| 	{ | ||||
| 		std::string desc = ((DFHack::Items*)items)->getItemDescription(itemptr, (DFHack::Materials*)mats); | ||||
| 		 | ||||
| 		if(desc.size() > 0) | ||||
| 		{ | ||||
| 			char* buf = (*char_buffer_create)(desc.size()); | ||||
| 			 | ||||
| 			if(buf != NULL) | ||||
| 			{ | ||||
| 				size_t len = desc.copy(buf, desc.size()); | ||||
| 				 | ||||
| 				if(len > 0) | ||||
| 					buf[len] = '\0'; | ||||
| 				else | ||||
| 					buf[0] = '\0'; | ||||
| 			} | ||||
| 			 | ||||
| 			return buf; | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	return NULL; | ||||
| } | ||||
| 
 | ||||
| char* Items_getItemClass(DFHackObject* items, int32_t index, char* (*char_buffer_create)(int)) | ||||
| { | ||||
| 	if(items != NULL) | ||||
| 	{ | ||||
| 		std::string iclass = ((DFHack::Items*)items)->getItemClass(index); | ||||
| 		 | ||||
| 		if(iclass.size() > 0) | ||||
| 		{ | ||||
| 			char* buf = (*char_buffer_create)(iclass.size()); | ||||
| 			 | ||||
| 			if(buf != NULL) | ||||
| 			{ | ||||
| 				size_t len = iclass.copy(buf, iclass.size()); | ||||
| 				 | ||||
| 				if(len > 0) | ||||
| 					buf[len] = '\0'; | ||||
| 				else | ||||
| 					buf[0] = '\0'; | ||||
| 			} | ||||
| 			 | ||||
| 			return buf; | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	return NULL; | ||||
| } | ||||
| 
 | ||||
| int Items_getItemData(DFHackObject* items, uint32_t itemptr, t_item* item) | ||||
| { | ||||
| 	if(items != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Items*)items)->getItemData(itemptr, *item); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| @ -0,0 +1,285 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| #include "integers.h" | ||||
| #include <vector> | ||||
| #include <map> | ||||
| #include <string> | ||||
| 
 | ||||
| using namespace std; | ||||
| 
 | ||||
| #include "DFCommonInternal.h" | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Maps.h" | ||||
| #include "modules/Maps_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| int Maps_Start(DFHackObject* maps) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->Start(); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_Finish(DFHackObject* maps) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->Finish(); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		((DFHack::Maps*)maps)->getSize(*x, *y, *z); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| int Maps_isValidBlock(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->isValidBlock(x, y, z); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| uint32_t Maps_getBlockPtr(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->getBlockPtr(x, y, z); | ||||
| 	} | ||||
| 	 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| int Maps_ReadBlock40d(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, mapblock40d* buffer) | ||||
| { | ||||
| 	if(maps != NULL && buffer != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->ReadBlock40d(x, y, z, buffer); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_ReadTileTypes(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, tiletypes40d* buffer) | ||||
| { | ||||
| 	if(maps != NULL && buffer != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->ReadTileTypes(x, y, z, buffer); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_WriteTileTypes(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, tiletypes40d* buffer) | ||||
| { | ||||
| 	if(maps != NULL && buffer != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->WriteTileTypes(x, y, z, buffer); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_ReadDesignations(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, designations40d* buffer) | ||||
| { | ||||
| 	if(maps != NULL && buffer != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->ReadDesignations(x, y, z, buffer); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_WriteDesignations(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, designations40d* buffer) | ||||
| { | ||||
| 	if(maps != NULL && buffer != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->WriteDesignations(x, y, z, buffer); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_ReadTemperatures(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_temperatures* temp1, t_temperatures* temp2) | ||||
| { | ||||
| 	if(maps != NULL && temp1 != NULL && temp2 != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->ReadTemperatures(x, y, z, temp1, temp2); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_WriteTemperatures(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_temperatures* temp1, t_temperatures* temp2) | ||||
| { | ||||
| 	if(maps != NULL && temp1 != NULL && temp2 != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->WriteTemperatures(x, y, z, temp1, temp2); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_ReadOccupancy(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, occupancies40d* buffer) | ||||
| { | ||||
| 	if(maps != NULL && buffer != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->ReadOccupancy(x, y, z, buffer); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_WriteOccupancy(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, occupancies40d* buffer) | ||||
| { | ||||
| 	if(maps != NULL && buffer != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->WriteOccupancy(x, y, z, buffer); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_ReadDirtyBit(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, int* dirtybit) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		bool bit; | ||||
| 		 | ||||
| 		int result = ((DFHack::Maps*)maps)->ReadDirtyBit(x, y, z, bit); | ||||
| 		 | ||||
| 		*dirtybit = bit; | ||||
| 		 | ||||
| 		return result; | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_WriteDirtyBit(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, int dirtybit) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->WriteDirtyBit(x, y, z, (bool)dirtybit); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_ReadFeatures(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, int16_t* local, int16_t* global) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->ReadFeatures(x, y, z, *local, *global); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_WriteLocalFeature(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, int16_t local) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->WriteLocalFeature(x, y, z, local); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_WriteEmptyLocalFeature(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->WriteLocalFeature(x, y, z, -1); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| int Maps_WriteGlobalFeature(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, int16_t local) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->WriteGlobalFeature(x, y, z, local); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_WriteEmptyGlobalFeature(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->WriteGlobalFeature(x, y, z, -1); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| int Maps_ReadBlockFlags(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_blockflags* blockflags) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->ReadBlockFlags(x, y, z, *blockflags); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_WriteBlockFlags(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_blockflags blockflags) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->WriteBlockFlags(x, y, z, blockflags); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Maps_ReadRegionOffsets(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, biome_indices40d* buffer) | ||||
| { | ||||
| 	if(maps != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Maps*)maps)->ReadRegionOffsets(x, y, z, buffer); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| @ -0,0 +1,121 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| #include "integers.h" | ||||
| #include <string> | ||||
| 
 | ||||
| using namespace std; | ||||
| 
 | ||||
| #include "DFCommonInternal.h" | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Translation.h" | ||||
| #include "modules/Translation_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| int Translation_Start(DFHackObject* trans) | ||||
| { | ||||
| 	if(trans != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Translation*)trans)->Start(); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Translation_Finish(DFHackObject* trans) | ||||
| { | ||||
| 	if(trans != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Translation*)trans)->Finish(); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int)) | ||||
| { | ||||
| 	if(trans != NULL) | ||||
| 	{ | ||||
| 		std::string nameTrans = ((DFHack::Translation*)trans)->TranslateName(*name, true); | ||||
| 		 | ||||
| 		if(nameTrans.size() > 0) | ||||
| 		{ | ||||
| 			char* buf = (*char_buffer_create)(nameTrans.size()); | ||||
| 			 | ||||
| 			if(buf != NULL) | ||||
| 			{ | ||||
| 				size_t len = nameTrans.copy(buf, nameTrans.size()); | ||||
| 				 | ||||
| 				if(len > 0)			 | ||||
| 					buf[len] = '\0'; | ||||
| 				else | ||||
| 					buf[0] = '\0'; | ||||
| 			} | ||||
| 			 | ||||
| 			return buf; | ||||
| 		} | ||||
| 		else | ||||
| 			return NULL; | ||||
| 	} | ||||
| 	 | ||||
| 	return NULL; | ||||
| } | ||||
| 
 | ||||
| char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int)) | ||||
| { | ||||
| 	if(trans != NULL) | ||||
| 	{ | ||||
| 		std::string nameTrans = ((DFHack::Translation*)trans)->TranslateName(*name, false); | ||||
| 		 | ||||
| 		if(nameTrans.size() > 0) | ||||
| 		{ | ||||
| 			char* buf = (*char_buffer_create)(nameTrans.size()); | ||||
| 			 | ||||
| 			if(buf != NULL) | ||||
| 			{ | ||||
| 				size_t len = nameTrans.copy(buf, nameTrans.size()); | ||||
| 				 | ||||
| 				if(len > 0)			 | ||||
| 					buf[len] = '\0'; | ||||
| 				else | ||||
| 					buf[0] = '\0'; | ||||
| 			} | ||||
| 			 | ||||
| 			return buf; | ||||
| 		} | ||||
| 		else | ||||
| 			return NULL; | ||||
| 	} | ||||
| 	 | ||||
| 	return NULL; | ||||
| } | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| @ -0,0 +1,69 @@ | ||||
| /*
 | ||||
| www.sourceforge.net/projects/dfhack | ||||
| Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild | ||||
| 
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| #include "integers.h" | ||||
| #include "DFCommonInternal.h" | ||||
| #include "DFTypes.h" | ||||
| #include "modules/Vegetation.h" | ||||
| #include "modules/Vegetation_C.h" | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| int Vegetation_Start(DFHackObject* veg, uint32_t* numTrees) | ||||
| { | ||||
| 	if(veg != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Vegetation*)veg)->Start(*numTrees); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Vegetation_Finish(DFHackObject* veg) | ||||
| { | ||||
| 	if(veg != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Vegetation*)veg)->Finish(); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| int Vegetation_Read(DFHackObject* veg, const uint32_t index, t_tree* shrubbery) | ||||
| { | ||||
| 	if(veg != NULL) | ||||
| 	{ | ||||
| 		return ((DFHack::Vegetation*)veg)->Read(index, *shrubbery); | ||||
| 	} | ||||
| 	 | ||||
| 	return -1; | ||||
| } | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| @ -0,0 +1,47 @@ | ||||
| from ctypes import * | ||||
| from pydftypes import * | ||||
| import util | ||||
| 
 | ||||
| libdfhack.Buildings_GetCustomWorkshopType.argtypes = [ c_void_p, POINTER(CustomWorkshop) ] | ||||
| 
 | ||||
| def Buildings(object): | ||||
|     def __init__(self, ptr): | ||||
|         self._b_ptr = ptr | ||||
| 
 | ||||
|     def start(self): | ||||
|         num = c_uint() | ||||
| 
 | ||||
|         if libdfhack.Buildings_Start(self._b_ptr, byref(num)) > 0: | ||||
|             return int(num.value) | ||||
|         else: | ||||
|             return -1 | ||||
| 
 | ||||
|     def finish(self): | ||||
|         return libdfhack.Buildings_Finish(self._b_ptr) > 0 | ||||
| 
 | ||||
|     def read(self, index): | ||||
|         b = Building() | ||||
| 
 | ||||
|         if libdfhack.Buildings_Read(self._b_ptr, c_uint(index), byref(b)) > 0: | ||||
|             return b | ||||
|         else: | ||||
|             return None | ||||
| 
 | ||||
|     def read_custom_workshop_types(self): | ||||
|         def read_callback(count): | ||||
|             allocated = util._allocate_array(CustomWorkshop, count) | ||||
|              | ||||
|             workshop_types = allocated[0] | ||||
| 
 | ||||
|             return allocated[1] | ||||
| 
 | ||||
|         workshop_types = None | ||||
|         callback = _arr_create_func(read_callback) | ||||
| 
 | ||||
|         if libdfhack.Buildings_ReadCustomWorkshopTypes(self._b_ptr, callback) > 0: | ||||
|             return workshop_types | ||||
|         else: | ||||
|             return None | ||||
| 
 | ||||
|     def get_custom_workshop_type(self, custom_workshop): | ||||
|         return libdfhack.Buildings_GetCustomWorkshopType(self._b_ptr, byref(custom_workshop)) | ||||
| @ -0,0 +1,25 @@ | ||||
| from ctypes import * | ||||
| from pydftypes import * | ||||
| 
 | ||||
| class Constructions(object): | ||||
|     def __init__(self, ptr): | ||||
|         self._c_ptr = ptr | ||||
| 
 | ||||
|     def start(self): | ||||
|         num = c_uint() | ||||
| 
 | ||||
|         if libdfhack.Constructions_Start(self._c_ptr, byref(num)) > 0: | ||||
|             return int(num.value) | ||||
|         else: | ||||
|             return -1 | ||||
| 
 | ||||
|     def finish(self): | ||||
|         return libdfhack.Constructions_Finish(self._c_ptr) > 0 | ||||
| 
 | ||||
|     def read(self, index): | ||||
|         c = Construction() | ||||
| 
 | ||||
|         if libdfhack.Constructions_Read(self._c_ptr, c_uint(index), byref(c)) > 0: | ||||
|             return c | ||||
|         else: | ||||
|             return None | ||||
| @ -0,0 +1,75 @@ | ||||
| from ctypes import * | ||||
| from pydftypes import libdfhack, Creature, Material | ||||
| import util | ||||
| 
 | ||||
| libdfhack.Creatures_WriteLabors.argtypes = [ c_void_p, c_uint, POINTER(c_ubyte) ] | ||||
| 
 | ||||
| class Creatures(object): | ||||
|     def __init__(self, ptr): | ||||
|         print ptr | ||||
|         self._c_ptr = ptr | ||||
| 
 | ||||
|         self._d_race_index = None | ||||
|         self._d_civ_id = None | ||||
| 
 | ||||
|     def start(self): | ||||
|         n = c_uint(0) | ||||
| 
 | ||||
|         if libdfhack.Creatures_Start(self._c_ptr, byref(n)) > 0: | ||||
|             return int(n.value) | ||||
|         else: | ||||
|             return -1 | ||||
| 
 | ||||
|     def finish(self): | ||||
|         return libdfhack.Creatures_Finish(self._c_ptr) > 0 | ||||
| 
 | ||||
|     def read_creature(self, index): | ||||
|         c = Creature() | ||||
| 
 | ||||
|         if libdfhack.Creatures_ReadCreature(self._c_ptr, c_int(index), byref(c)) > 0: | ||||
|             return c | ||||
|         else: | ||||
|             return None | ||||
| 
 | ||||
|     def read_creature_in_box(self, index, pos1, pos2): | ||||
|         c = Creature() | ||||
| 
 | ||||
|         x1, y1, z1 = c_uint(pos1[0]), c_uint(pos1[1]), c_uint(pos1[2]) | ||||
|         x2, y2, z2 = c_uint(pos2[0]), c_uint(pos2[1]), c_uint(pos2[2]) | ||||
| 
 | ||||
|         retval = libdfhack.Creatures_ReadCreatureInBox(self._c_ptr, byref(c), x1, y1, z1, x2, y2, z2) | ||||
| 
 | ||||
|         return (retval, c) | ||||
| 
 | ||||
|     def write_labors(self, index, labors): | ||||
|         return libdfhack.Creatures_WriteLabors(self._c_ptr, c_uint(index), labors) > 0 | ||||
| 
 | ||||
|     def read_job(self, creature): | ||||
|         def read_callback(count): | ||||
|             allocated = util._allocate_array(Material, count) | ||||
| 
 | ||||
|             jobs = allocated[0] | ||||
| 
 | ||||
|             return allocated[1] | ||||
| 
 | ||||
|         jobs = None | ||||
|         callback = _arr_create_func(read_callback) | ||||
| 
 | ||||
|         if libdfhack.Creatures_ReadJob(self._c_ptr, byref(creature), callback) > 0: | ||||
|             return jobs | ||||
|         else: | ||||
|             return None | ||||
| 
 | ||||
|     @property | ||||
|     def dwarf_race_index(self): | ||||
|         if self._d_race_index is None: | ||||
|             self._d_race_index = int(libdfhack.Creatures_GetDwarfRaceIndex(self._c_ptr).value) | ||||
| 
 | ||||
|         return self._d_race_index | ||||
| 
 | ||||
|     @property | ||||
|     def dwarf_civ_id(self): | ||||
|         if self._d_civ_id is None: | ||||
|             self._d_civ_id = int(libdfhack.Creatures_GetDwarfCivId(self._c_ptr).value) | ||||
| 
 | ||||
|         return self._d_civ_id | ||||
| @ -0,0 +1,162 @@ | ||||
| from ctypes import * | ||||
| from pydftypes import * | ||||
| 
 | ||||
| 
 | ||||
| libdfhack.API_Alloc.restype = c_void_p | ||||
| libdfhack.API_Free.argtypes = [ c_void_p ] | ||||
| 
 | ||||
| libdfhack.API_getMemoryInfo.restype = c_void_p | ||||
| libdfhack.API_getProcess.restype = c_void_p | ||||
| libdfhack.API_getWindow.restype = c_void_p | ||||
| 
 | ||||
| libdfhack.API_getCreatures.restype = c_void_p | ||||
| libdfhack.API_getMaps.restype = c_void_p | ||||
| libdfhack.API_getGui.restype = c_void_p | ||||
| libdfhack.API_getPosition.restype = c_void_p | ||||
| libdfhack.API_getMaterials.restype = c_void_p | ||||
| libdfhack.API_getTranslation.restype = c_void_p | ||||
| libdfhack.API_getVegetation.restype = c_void_p | ||||
| libdfhack.API_getBuildings.restype = c_void_p | ||||
| libdfhack.API_getConstructions.restype = c_void_p | ||||
| libdfhack.API_getItems.restype = c_void_p | ||||
| 
 | ||||
| class API(object): | ||||
|     def __init__(self, memory_path): | ||||
|         self._api_ptr = libdfhack.API_Alloc(create_string_buffer(memory_path)) | ||||
| 
 | ||||
|         self._pos_obj = None | ||||
|         self._mat_obj = None | ||||
|         self._map_obj = None | ||||
|         self._veg_obj = None | ||||
|         self._build_obj = None | ||||
|         self._con_obj = None | ||||
|         self._gui_obj = None | ||||
|         self._tran_obj = None | ||||
|         self._item_obj = None | ||||
|         self._creature_obj = None | ||||
| 
 | ||||
|     def __del__(self): | ||||
|         libdfhack.API_Free(self._api_ptr) | ||||
| 
 | ||||
|     def attach(self): | ||||
|         return libdfhack.API_Attach(self._api_ptr) > 0 | ||||
| 
 | ||||
|     def detach(self): | ||||
|         return libdfhack.API_Detach(self._api_ptr) > 0 | ||||
| 
 | ||||
|     def suspend(self): | ||||
|         return libdfhack.API_Suspend(self._api_ptr) > 0 | ||||
| 
 | ||||
|     def resume(self): | ||||
|         return libdfhack.API_Resume(self._api_ptr) > 0 | ||||
| 
 | ||||
|     def force_resume(self): | ||||
|         return libdfhack.API_ForceResume(self._api_ptr) > 0 | ||||
| 
 | ||||
|     def async_suspend(self): | ||||
|         return libdfhack.API_AsyncSuspend(self._api_ptr) > 0 | ||||
| 
 | ||||
|     @property | ||||
|     def is_attached(self): | ||||
|         return libdfhack.API_isAttached(self._api_ptr) > 0 | ||||
| 
 | ||||
|     @property | ||||
|     def is_suspended(self): | ||||
|         return libdfhack.API_isSuspended(self._api_ptr) > 0 | ||||
| 
 | ||||
|     @property | ||||
|     def position(self): | ||||
|         import position | ||||
|         if self._pos_obj is None: | ||||
|             self._pos_obj = position.Position(libdfhack.API_getPosition(self._api_ptr)) | ||||
| 
 | ||||
|         return self._pos_obj | ||||
| 
 | ||||
|     @property | ||||
|     def materials(self): | ||||
|         import materials | ||||
|         if self._mat_obj is None: | ||||
|             self._mat_obj = materials.Materials(libdfhack.API_getMaterials(self._api_ptr)) | ||||
| 
 | ||||
|         return self._mat_obj | ||||
| 
 | ||||
|     @property | ||||
|     def maps(self): | ||||
|         import maps | ||||
|         if self._map_obj is None: | ||||
|             self._map_obj = maps.Maps(libdfhack.API_getMaps(self._api_ptr)) | ||||
| 
 | ||||
|         return self._map_obj | ||||
| 
 | ||||
|     @property | ||||
|     def vegetation(self): | ||||
|         import vegetation | ||||
|         if self._veg_obj is None: | ||||
|             self._veg_obj = vegetation.Vegetation(libdfhack.API_getVegetation(self._api_ptr)) | ||||
| 
 | ||||
|         return self._veg_obj | ||||
| 
 | ||||
|     @property | ||||
|     def buildings(self): | ||||
|         import buildings | ||||
|         if self._build_obj is None: | ||||
|             self._build_obj = buildings.Buildings(libdfhack.API_getBuildings(self._api_ptr)) | ||||
| 
 | ||||
|         return self._build_obj | ||||
| 
 | ||||
|     @property | ||||
|     def creatures(self): | ||||
|         import creatures | ||||
|         if self._creature_obj is None: | ||||
|             self._creature_obj = creatures.Creatures(libdfhack.API_getCreatures(self._api_ptr)) | ||||
| 
 | ||||
|         return self._creature_obj | ||||
| 
 | ||||
|     @property | ||||
|     def gui(self): | ||||
|         import gui | ||||
|         if self._gui_obj is None: | ||||
|             self._gui_obj = gui.Gui(libdfhack.API_getGui(self._api_ptr)) | ||||
| 
 | ||||
|         return self._gui_obj | ||||
| 
 | ||||
|     @property | ||||
|     def items(self): | ||||
|         import items | ||||
|         if self._item_obj is None: | ||||
|             self._item_obj = items.Items(libdfhack.API_getItems(self._api_ptr)) | ||||
| 
 | ||||
|         return self._item_obj | ||||
| 
 | ||||
|     @property | ||||
|     def translation(self): | ||||
|         import translation | ||||
|         if self._tran_obj is None: | ||||
|             self._tran_obj = translation.Translation(libdfhack.API_getTranslation(self._api_ptr)) | ||||
| 
 | ||||
|         return self._tran_obj | ||||
| 
 | ||||
| def reveal(): | ||||
|     df = API("Memory.xml") | ||||
|     df.attach() | ||||
| 
 | ||||
|     m = df.maps | ||||
| 
 | ||||
|     m.start() | ||||
| 
 | ||||
|     m_x, m_y, m_z = m.size | ||||
| 
 | ||||
|     for x in xrange(m_x): | ||||
|         for y in xrange(m_y): | ||||
|             for z in xrange(m_z): | ||||
|                 if m.is_valid_block(x, y, z): | ||||
|                     d = m.read_designations(x, y, z) | ||||
| 
 | ||||
|                     for i in d: | ||||
|                         for j in i: | ||||
|                             j.bits.hidden = 0 | ||||
| 
 | ||||
|                     m.write_designations(x, y, z, d) | ||||
| 
 | ||||
|     m.finish() | ||||
|     df.detach() | ||||
| @ -0,0 +1,97 @@ | ||||
| #found this in the cookbook:  http://code.activestate.com/recipes/576415/ | ||||
| 
 | ||||
| from ctypes import c_uint | ||||
| 
 | ||||
| class C_EnumerationType(type(c_uint)): | ||||
|     def __new__(metacls, name, bases, dictionary): | ||||
|         if not "_members_" in dictionary: | ||||
|             _members_ = {} | ||||
| 
 | ||||
|             for key, value in dictionary.iteritems(): | ||||
|                 if not key.startswith("_"): | ||||
|                     _members_[key] = value | ||||
| 
 | ||||
|             dictionary["_members_"] = _members_ | ||||
| 
 | ||||
|         cls = type(c_uint).__new__(metacls, name, bases, dictionary) | ||||
| 
 | ||||
|         for key, value in cls._members_.iteritems(): | ||||
|             globals()[key] = value | ||||
| 
 | ||||
|         return cls | ||||
| 
 | ||||
|     def __contains__(self, value): | ||||
|         return value in self._members_.values() | ||||
| 
 | ||||
|     def __repr__(self): | ||||
|         return "<Enumeration %s>" % self.__name__ | ||||
| 
 | ||||
| class C_Enumeration(c_uint): | ||||
|     __metaclass__ = C_EnumerationType | ||||
|     _members_ = {} | ||||
| 
 | ||||
|     def __init__(self, value): | ||||
|         for key, value in self._members_.iteritems(): | ||||
|             if v == value: | ||||
|                 self.name = key | ||||
|                 break | ||||
|         else: | ||||
|             raise ValueError("No enumeration member with value %r" % value) | ||||
| 
 | ||||
|         c_uint.__init__(self, value) | ||||
| 
 | ||||
|     def __repr__(self): | ||||
|         return "<member %s=%d of %r>" % (self.name, self.value, self.__class__) | ||||
| 
 | ||||
|     @classmethod | ||||
|     def from_param(cls, param): | ||||
|         if isinstance(param, C_Enumeration): | ||||
|             if param.__class__ != cls: | ||||
|                 raise ValueError("Cannot mix enumeration members") | ||||
|             else: | ||||
|                 return param | ||||
|         else: | ||||
|             return cls(param) | ||||
| 
 | ||||
| FeatureType = C_EnumerationType("FeatureType", | ||||
|                                 (c_uint,), | ||||
|                                 {"Other" : 0, | ||||
|                                  "Adamantine_Tube" : 1, | ||||
|                                  "Underworld" : 2, | ||||
|                                  "Hell_Temple" : 3}) | ||||
| 
 | ||||
| BiomeOffset = C_EnumerationType("BiomeOffset", | ||||
|                                 (c_uint,), | ||||
|                                 {"NorthWest" : 0, | ||||
|                                  "North" : 1, | ||||
|                                  "NorthEast" : 2, | ||||
|                                  "West" : 3, | ||||
|                                  "Here" : 4, | ||||
|                                  "East" : 5, | ||||
|                                  "SouthWest" : 6, | ||||
|                                  "South" : 7, | ||||
|                                  "SouthEast" : 8, | ||||
|                                  "BiomeCount" : 9}) | ||||
| 
 | ||||
| TrafficType = C_EnumerationType("TrafficType", | ||||
|                                 (c_uint,), | ||||
|                                 {"Normal" : 0, | ||||
|                                  "Low" : 1, | ||||
|                                  "High" : 2, | ||||
|                                  "Restricted" : 3}) | ||||
| 
 | ||||
| DesignationType = C_EnumerationType("DesignationType", | ||||
|                                     (c_uint,), | ||||
|                                     {"No" : 0, | ||||
|                                      "Default" : 1, | ||||
|                                      "UD_Stair" : 2, | ||||
|                                      "Channel" : 3, | ||||
|                                      "Ramp" : 4, | ||||
|                                      "D_Stair" : 5, | ||||
|                                      "U_Stair" : 6, | ||||
|                                      "Whatever" : 7}) | ||||
| 
 | ||||
| LiquidType = C_EnumerationType("LiquidType", | ||||
|                                (c_uint,), | ||||
|                                {"Water" : 0, | ||||
|                                 "Magma" : 1}) | ||||
| @ -0,0 +1,25 @@ | ||||
| from ctypes import * | ||||
| from pydfhack import libdfhack, ViewScreen | ||||
| 
 | ||||
| libdfhack.Gui_ReadViewScreen.argtypes = [ c_void_p, c_void_p ] | ||||
| 
 | ||||
| class Gui(object): | ||||
|     def __init__(self, ptr): | ||||
|         self._gui_ptr = ptr | ||||
| 
 | ||||
|     def start(self): | ||||
|         return libdfhack.Gui_Start(self._gui_ptr) | ||||
| 
 | ||||
|     def finish(self): | ||||
|         return libdfhack.Gui_Finish(self._gui_ptr) | ||||
| 
 | ||||
|     def read_pause_state(self): | ||||
|         return libdfhack.Gui_ReadPauseState(self._pos_ptr) > 0 | ||||
| 
 | ||||
|     def read_view_screen(self): | ||||
|         s = ViewScreen() | ||||
| 
 | ||||
|         if libdfhack.Gui_ReadViewScreen(self._gui_ptr, byref(s)) > 0: | ||||
|             return s | ||||
|         else: | ||||
|             return None | ||||
| @ -0,0 +1,33 @@ | ||||
| from ctypes import * | ||||
| from pydftypes import * | ||||
| 
 | ||||
| libdfhack.Items_getItemDescription.argtypes = [ c_void_p, c_uint, c_void_ptr, _arr_create_func ] | ||||
| libdfhack.Items_getItemDescription.restype = c_char_p | ||||
| libdfhack.Items_getItemClass.argtypes = [ c_void_p, c_int, _arr_create_func ] | ||||
| libdfhack.Item_getItemClass.restype = c_char_p | ||||
| 
 | ||||
| class Items(object): | ||||
|     def __init__(self, ptr): | ||||
|         self._i_ptr = ptr | ||||
| 
 | ||||
|     def get_item_description(self, itemptr, materials): | ||||
|         def get_callback(count): | ||||
|             item_string = create_string_buffer(count) | ||||
| 
 | ||||
|             return byref(item_string) | ||||
| 
 | ||||
|         item_string = None | ||||
|         callback = _arr_create_func(get_callback) | ||||
| 
 | ||||
|         return libdfhack.Items_getItemDescription(self._i_ptr, itemptr, materials, callback) | ||||
| 
 | ||||
|     def get_item_class(self, index): | ||||
|         def get_callback(count): | ||||
|             item_string = create_string_buffer(count) | ||||
| 
 | ||||
|             return byref(item_string) | ||||
| 
 | ||||
|         item_string = None | ||||
|         callback = _arr_create_func(get_callback) | ||||
| 
 | ||||
|         return libdfhack.Items_getItemClass(self._i_ptr, index, callback) | ||||
| @ -0,0 +1,163 @@ | ||||
| from ctypes import * | ||||
| from pydftypes import libdfhack | ||||
| from util import _uintify | ||||
| 
 | ||||
| libdfhack.Maps_getSize.argtypes = [ c_void_p, uint_ptr, uint_ptr, uint_ptr ] | ||||
| libdfhack.Maps_ReadTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ] | ||||
| libdfhack.Maps_WriteTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ] | ||||
| libdfhack.Maps_ReadDesignations.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Designations40d) ] | ||||
| libdfhack.Maps_WriteDesignations.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Designations40d) ] | ||||
| libdfhack.Maps_ReadTemperatures.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Temperatures) ] | ||||
| libdfhack.Maps_WriteTemperatures.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Temperatures) ] | ||||
| libdfhack.Maps_ReadOccupancy.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Occupancies40d) ] | ||||
| libdfhack.Maps_WriteOccupancy.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Occupancies40d) ] | ||||
| libdfhack.Maps_ReadRegionOffsets.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(BiomeIndices40d) ] | ||||
| 
 | ||||
| class Maps(object): | ||||
|     def __init__(self, ptr): | ||||
|         self._map_ptr = ptr | ||||
| 
 | ||||
|     def start(self): | ||||
|         return libdfhack.Maps_Start(self._map_ptr) > 0 | ||||
| 
 | ||||
|     def finish(self): | ||||
|         return libdfhack.Maps_Finish(self._map_ptr) > 0 | ||||
| 
 | ||||
|     def is_valid_block(self, x, y, z): | ||||
|         return libdfhack.Maps_isValidBlock(self._map_ptr, *_uintify(x, y, z)) > 0 | ||||
| 
 | ||||
|     def read_tile_types(self, x, y, z): | ||||
|         tt = TileTypes40d() | ||||
| 
 | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
| 
 | ||||
|         if libdfhack.Maps_ReadTileTypes(self._map_ptr, ux, uy, uz, tt) > 0: | ||||
|             return tt | ||||
|         else: | ||||
|             return None | ||||
| 
 | ||||
|     def write_tile_types(self, x, y, z, tt): | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
|          | ||||
|         return libdfhack.Maps_WriteTileTypes(self._map_ptr,  ux, uy, uz, tt) > 0 | ||||
| 
 | ||||
|     def read_designations(self, x, y, z): | ||||
|         d = Designations40d() | ||||
| 
 | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
| 
 | ||||
|         if libdfhack.Maps_ReadDesignations(self._map_ptr, ux, uy, uz, d) > 0: | ||||
|             return d | ||||
|         else: | ||||
|             return None | ||||
| 
 | ||||
|     def write_designations(self, x, y, z, d): | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
|          | ||||
|         return libdfhack.Maps_WriteDesignations(self._map_ptr, ux, uy, uz, d) > 0 | ||||
| 
 | ||||
|     def read_temperatures(self, x, y, z): | ||||
|         t = Temperatures() | ||||
| 
 | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
| 
 | ||||
|         if libdfhack.Maps_ReadDesignations(self._map_ptr, ux, uy, uz, t) > 0: | ||||
|             return t | ||||
|         else: | ||||
|             return None | ||||
| 
 | ||||
|     def write_temperatures(self, x, y, z, t): | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
|          | ||||
|         return libdfhack.Maps_WriteDesignations(self._map_ptr, ux, uy, uz, t) > 0 | ||||
| 
 | ||||
|     def read_occupancy(self, x, y, z): | ||||
|         o = Occupancies40d() | ||||
| 
 | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
| 
 | ||||
|         if libdfhack.Maps_ReadDesignations(self._map_ptr, ux, uy, uz, o) > 0: | ||||
|             return o | ||||
|         else: | ||||
|             return None | ||||
| 
 | ||||
|     def write_designations(self, x, y, z, o): | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
|          | ||||
|         return libdfhack.Maps_WriteDesignations(self._map_ptr, ux, uy, uz, o) > 0 | ||||
| 
 | ||||
|     def read_dirty_bit(self, x, y, z): | ||||
|         bit = c_int(0) | ||||
| 
 | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
| 
 | ||||
|         if libdfhack.Maps_ReadDirtyBit(self._map_ptr, ux, uy, uz, byref(bit)) > 0: | ||||
|             if bit > 0: | ||||
|                 return True | ||||
|             else: | ||||
|                 return False | ||||
|         else: | ||||
|             return None | ||||
| 
 | ||||
|     def write_dirty_bit(self, x, y, z, dirty): | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
|          | ||||
|         return libdfhack.Maps_WriteDirtyBit(self._map_ptr, ux, uy, uz, c_int(dirty)) > 0 | ||||
| 
 | ||||
|     def read_features(self, x, y, z): | ||||
|         lf = c_short() | ||||
|         gf = c_short() | ||||
| 
 | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
| 
 | ||||
|         libdfhack.Maps_ReadFeatures(self._map_ptr, ux, uy, uz, byref(lf), byref(fg)) | ||||
| 
 | ||||
|         return (lf, gf) | ||||
| 
 | ||||
|     def write_local_feature(self, x, y, z, local_feature = -1): | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
|          | ||||
|         return libdfhack.Maps_WriteLocalFeature(self._map_ptr, ux, uy, uz, c_short(local_feature)) > 0 | ||||
| 
 | ||||
|     def write_global_feature(self, x, y, z, global_feature = -1): | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
|          | ||||
|         return libdfhack.Maps_WriteGlobalFeature(self._map_ptr, ux, uy, uz, c_short(global_feature)) > 0 | ||||
| 
 | ||||
|     def read_block_flags(self, x, y, z): | ||||
|         bf = BlockFlags() | ||||
| 
 | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
| 
 | ||||
|         if libdfhack.Maps_ReadBlockFlags(self._map_ptr, ux, uy, uz, byref(bf)) > 0: | ||||
|             return bf | ||||
|         else: | ||||
|             return None | ||||
| 
 | ||||
|     def write_block_flags(self, x, y, z, block_flags): | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
|          | ||||
|         return libdfhack.Maps_WriteBlockFlags(self._map_ptr, ux, uy, uz, block_flags) > 0 | ||||
| 
 | ||||
|     def read_region_offsets(self, x, y, z): | ||||
|         bi = BiomeIndices40d() | ||||
| 
 | ||||
|         ux, uy, uz = _uintify(x, y, z) | ||||
| 
 | ||||
|         if libdfhack.Maps_ReadRegionOffsets(self._map_ptr, ux, uy, uz, byref(bi)) > 0: | ||||
|             return bi | ||||
|         else: | ||||
|             return None | ||||
| 
 | ||||
|     @property | ||||
|     def size(self): | ||||
|         x = c_uint() | ||||
|         y = c_uint() | ||||
|         z = c_uint() | ||||
| 
 | ||||
|         retval = libdfhack.Maps_getSize(self._map_ptr, byref(x), byref(y), byref(z)) | ||||
| 
 | ||||
|         if retval > 0: | ||||
|             return (int(x.value), int(y.value), int(z.value)) | ||||
|         else: | ||||
|             return (-1, -1, -1) | ||||
| @ -0,0 +1,141 @@ | ||||
| from ctypes import * | ||||
| from pydftypes import libdfhack | ||||
| from util import * | ||||
| 
 | ||||
| _get_arg_types = [ c_void_p, _arr_create_func ] | ||||
| 
 | ||||
| libdfhack.Materials_getInorganic.argtypes = _get_arg_types | ||||
| libdfhack.Materials_getOrganic.argtypes = _get_arg_types | ||||
| libdfhack.Materials_getTree.argtypes = _get_arg_types | ||||
| libdfhack.Materials_getPlant.argtypes = _get_arg_types | ||||
| libdfhack.Materials_getRace.argtypes = _get_arg_types | ||||
| #libdfhack.Materials_getRaceEx.argtypes = _get_arg_types | ||||
| libdfhack.Materials_getColor.argtypes = _get_arg_types | ||||
| libdfhack.Materials_getOther.argtypes = _get_arg_types | ||||
| 
 | ||||
| class Materials(object): | ||||
|     def __init__(self, ptr): | ||||
|         self._mat_ptr = ptr | ||||
| 
 | ||||
|         self.inorganic = None | ||||
|         self.organic = None | ||||
|         self.tree = None | ||||
|         self.plant = None | ||||
|         self.race = None | ||||
|         self.race_ex = None | ||||
|         self.color = None | ||||
|         self.other = None | ||||
| 
 | ||||
|     def read_inorganic(self): | ||||
|         return libdfhack.Materials_ReadInorganicMaterials(self._mat_ptr) | ||||
| 
 | ||||
|     def read_organic(self): | ||||
|         return libdfhack.Materials_ReadOrganicMaterials(self._mat_ptr) | ||||
| 
 | ||||
|     def read_wood(self): | ||||
|         return libdfhack.Materials_ReadWoodMaterials(self._mat_ptr) | ||||
| 
 | ||||
|     def read_plant(self): | ||||
|         return libdfhack.Materials_ReadPlantMaterials(self._mat_ptr) | ||||
| 
 | ||||
|     def read_creature_types(self): | ||||
|         return libdfhack.Materials_ReadCreatureTypes(self._mat_ptr) | ||||
| 
 | ||||
|     def read_creature_types_ex(self): | ||||
|         return libdfhack.Materials_ReadCreatureTypesEx(self._mat_ptr) | ||||
| 
 | ||||
|     def read_descriptor_colors(self): | ||||
|         return libdfhack.Materials_ReadDescriptorColors(self._mat_ptr) | ||||
| 
 | ||||
|     def read_others(self): | ||||
|         return libdfhack.Materials_ReadOthers(self._mat_ptr) | ||||
| 
 | ||||
|     def read_all(self): | ||||
|         libdfhack.Materials_ReadAllMaterials(self._mat_ptr) | ||||
| 
 | ||||
|     def get_description(self, material): | ||||
|         return libdfhack.Materials_getDescription(self._mat_ptr, byref(material)) | ||||
| 
 | ||||
|     def update_inorganic_cache(self): | ||||
|         def update_callback(count): | ||||
|             allocated = _allocate_array(Matgloss, count) | ||||
| 
 | ||||
|             self.inorganic = allocated[0] | ||||
| 
 | ||||
|             return allocated[1] | ||||
| 
 | ||||
|         callback = _arr_create_func(update_callback) | ||||
| 
 | ||||
|         return libdfhack.Materials_getInorganic(self._mat_ptr, callback) | ||||
| 
 | ||||
|     def update_organic_cache(self): | ||||
|         def update_callback(count): | ||||
|             allocated = _allocate_array(Matgloss, count) | ||||
| 
 | ||||
|             self.organic = allocated[0] | ||||
| 
 | ||||
|             return allocated[1] | ||||
| 
 | ||||
|         callback = _arr_create_func(update_callback) | ||||
| 
 | ||||
|         return libdfhack.Materials_getOrganic(self._mat_ptr, callback) | ||||
| 
 | ||||
|     def update_tree_cache(self): | ||||
|         def update_callback(count): | ||||
|             allocated = _allocate_array(Matgloss, count) | ||||
| 
 | ||||
|             self.tree = allocated[0] | ||||
| 
 | ||||
|             return allocated[1] | ||||
| 
 | ||||
|         callback = _arr_create_func(update_callback) | ||||
| 
 | ||||
|         return libdfhack.Materials_getTree(self._mat_ptr, callback) | ||||
| 
 | ||||
|     def update_plant_cache(self): | ||||
|         def update_callback(count): | ||||
|             allocated = _allocate_array(Matgloss, count) | ||||
| 
 | ||||
|             self.plant = allocated[0] | ||||
| 
 | ||||
|             return allocated[1] | ||||
| 
 | ||||
|         callback = _arr_create_func(update_callback) | ||||
| 
 | ||||
|         return libdfhack.Materials_getPlant(self._mat_ptr, callback) | ||||
| 
 | ||||
|     def update_race_cache(self): | ||||
|         def update_callback(count): | ||||
|             allocated = _allocate_array(Matgloss, count) | ||||
| 
 | ||||
|             self.race = allocated[0] | ||||
| 
 | ||||
|             return allocated[1] | ||||
| 
 | ||||
|         callback = _arr_create_func(update_callback) | ||||
| 
 | ||||
|         return libdfhack.Materials_getRace(self._mat_ptr, callback) | ||||
| 
 | ||||
|     def update_color_cache(self): | ||||
|         def update_callback(count): | ||||
|             allocated = _allocate_array(DescriptorColor, count) | ||||
| 
 | ||||
|             self.color = allocated[0] | ||||
|              | ||||
|             return allocated[1] | ||||
| 
 | ||||
|         callback = _arr_create_func(update_callback) | ||||
| 
 | ||||
|         return libdfhack.Materials_getColor(self._mat_ptr, callback) | ||||
| 
 | ||||
|     def update_other_cache(self): | ||||
|         def update_callback(count): | ||||
|             allocated = _allocate_array(MatglossOther, count) | ||||
| 
 | ||||
|             self.other = allocated[0] | ||||
|              | ||||
|             return allocated[1] | ||||
| 
 | ||||
|         callback = _arr_create_func(update_callback) | ||||
| 
 | ||||
|         return libdfhack.Materials_getOther(self._mat_ptr, callback) | ||||
| @ -0,0 +1,43 @@ | ||||
| from ctypes import * | ||||
| from pydftypes import libdfhack | ||||
| 
 | ||||
| class Position(object): | ||||
|     def __init__(self, ptr): | ||||
|         self._pos_ptr = ptr | ||||
| 
 | ||||
|         self._vx, self._vy, self._vz = c_int(), c_int(), c_int() | ||||
|         self._cx, self._cy, self._cz = c_int(), c_int(), c_int() | ||||
|         self._ww, self._wh = c_int(), c_int() | ||||
| 
 | ||||
|     def get_view_coords(self): | ||||
|         if libdfhack.Position_getViewCoords(self._pos_ptr, byref(self._vx), byref(self._vy), byref(self._vz)) > 0: | ||||
|             return (self._vx.value, self._vy.value, self._vz.value) | ||||
|         else: | ||||
|             return (-1, -1, -1) | ||||
| 
 | ||||
|     def set_view_coords(self, v_coords): | ||||
|         self._vx.value, self._vy.value, self._vz.value = v_coords | ||||
| 
 | ||||
|         libdfhack.Position_setViewCoords(self._pos_ptr, self._vx, self._vy, self._vz) | ||||
| 
 | ||||
|     view_coords = property(get_view_coords, set_view_coords) | ||||
|      | ||||
|     def get_cursor_coords(self): | ||||
|         if libdfhack.Position_getCursorCoords(self._pos_ptr, byref(self._cx), byref(self._cy), byref(self._cz)) > 0: | ||||
|             return (self._cx.value, self._cy.value, self._cz.value) | ||||
|         else: | ||||
|             return (-1, -1, -1) | ||||
| 
 | ||||
|     def set_cursor_coords(self, c_coords): | ||||
|         self._cx.value, self._cy.value, self_cz.value = c_coords | ||||
| 
 | ||||
|         libdfhack.Position_setCursorCoords(self._pos_ptr, self._cx, self._cy, self._cz) | ||||
| 
 | ||||
|     cursor_coords = property(get_cursor_coords, set_cursor_coords) | ||||
| 
 | ||||
|     @property | ||||
|     def window_size(self): | ||||
|         if libdfhack.Position_getWindowSize(self._pos_ptr, byref(self._ww), byref(self._wh)) > 0: | ||||
|             return (self._ww.value, self._wh.value) | ||||
|         else: | ||||
|             return (-1, -1) | ||||
| @ -0,0 +1,200 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
| from ctypes import Structure, Union, c_uint | ||||
| from enum import * | ||||
| 
 | ||||
| class DesignationStruct(Structure): | ||||
|     _fields_ = [("flow_size", c_uint, 3), | ||||
|                 ("pile", c_uint, 1), | ||||
|                 ("dig", DesignationType, 3), | ||||
|                 ("smooth", c_uint, 2), | ||||
|                 ("hidden", c_uint, 1), | ||||
|                 ("geolayer_index", c_uint, 4), | ||||
|                 ("light", c_uint, 1), | ||||
|                 ("subterranean", c_uint, 1), | ||||
|                 ("skyview", c_uint, 1), | ||||
|                 ("biome", c_uint, 4), | ||||
|                 ("liquid_type", c_uint, 1), | ||||
|                 ("water_table", c_uint, 1), | ||||
|                 ("rained", c_uint, 1), | ||||
|                 ("traffic", c_uint, 2), | ||||
|                 ("flow_forbid", c_uint, 1), | ||||
|                 ("liquid_static", c_uint, 1), | ||||
|                 ("feature_local", c_uint, 1), | ||||
|                 ("feature_global", c_uint, 1), | ||||
|                 ("liquid_character", c_uint, 2)] | ||||
| 
 | ||||
| class DesignationFlags(Union): | ||||
|     _fields_ = [("whole", c_uint, 32), | ||||
|                 ("bits", DesignationStruct)] | ||||
|      | ||||
|     def __init__(self, initial = 0): | ||||
|             self.whole = initial | ||||
|      | ||||
|     def __int__(self): | ||||
|         return self.whole | ||||
| 
 | ||||
| class OccupancyStruct(Structure): | ||||
|     _fields_ = [("building", c_uint, 3), | ||||
|                 ("unit", c_uint, 1), | ||||
|                 ("unit_grounded", c_uint, 1), | ||||
|                 ("item", c_uint, 1), | ||||
|                 ("splatter", c_uint, 26)] | ||||
| 
 | ||||
| class OccupancyFlags(Union): | ||||
|     _fields_ = [("whole", c_uint, 32), | ||||
|                 ("bits", OccupancyStruct)] | ||||
| 
 | ||||
|     def __init__(self, initial = 0): | ||||
|         self.whole = initial | ||||
|      | ||||
|     def __int__(self): | ||||
|         return self.whole | ||||
| 
 | ||||
| class CreatureStruct1(Structure): | ||||
|     _fields_ = [("move_state", c_uint, 1), | ||||
|                 ("dead", c_uint, 1), | ||||
|                 ("has_mood", c_uint, 1), | ||||
|                 ("had_mood", c_uint, 1), | ||||
|                 ("marauder", c_uint, 1), | ||||
|                 ("drowning", c_uint, 1), | ||||
|                 ("merchant", c_uint, 1), | ||||
|                 ("forest", c_uint, 1), | ||||
|                 ("left", c_uint, 1), | ||||
|                 ("rider", c_uint, 1), | ||||
|                 ("incoming", c_uint, 1), | ||||
|                 ("diplomat", c_uint, 1), | ||||
|                 ("zombie", c_uint, 1), | ||||
|                 ("skeleton", c_uint, 1), | ||||
|                 ("can_swap", c_uint, 1), | ||||
|                 ("on_ground", c_uint, 1), | ||||
|                 ("projectile", c_uint, 1), | ||||
|                 ("active_invader", c_uint, 1), | ||||
|                 ("hidden_in_ambush", c_uint, 1), | ||||
|                 ("invader_origin", c_uint, 1), | ||||
|                 ("coward", c_uint, 1), | ||||
|                 ("hidden_ambusher", c_uint, 1), | ||||
|                 ("invades", c_uint, 1), | ||||
|                 ("check_flows", c_uint, 1), | ||||
|                 ("ridden", c_uint, 1), | ||||
|                 ("caged", c_uint, 1), | ||||
|                 ("tame", c_uint, 1), | ||||
|                 ("chained", c_uint, 1), | ||||
|                 ("royal_guard", c_uint, 1), | ||||
|                 ("fortress_guard", c_uint, 1), | ||||
|                 ("suppress_wield", c_uint, 1), | ||||
|                 ("important_historical_figure", c_uint, 1)] | ||||
| 
 | ||||
| class CreatureFlags1(Union): | ||||
|     _fields_ = [("whole", c_uint, 32), | ||||
|                 ("bits", CreatureStruct1)] | ||||
| 
 | ||||
|     def __init__(self, initial = 0): | ||||
|         self.whole = initial | ||||
|      | ||||
|     def __int__(self): | ||||
|         return self.whole | ||||
| 
 | ||||
| class CreatureStruct2(Structure): | ||||
|     _fields_ = [("swimming", c_uint, 1), | ||||
|                 ("sparring", c_uint, 1), | ||||
|                 ("no_notify", c_uint, 1), | ||||
|                 ("unused", c_uint, 1), | ||||
|                 ("calculated_nerves", c_uint, 1), | ||||
|                 ("calculated_bodyparts", c_uint, 1), | ||||
|                 ("important_historical_figure", c_uint, 1), | ||||
|                 ("killed", c_uint, 1), | ||||
|                 ("cleanup_1", c_uint, 1), | ||||
|                 ("cleanup_2", c_uint, 1), | ||||
|                 ("cleanup_3", c_uint, 1), | ||||
|                 ("for_trade", c_uint, 1), | ||||
|                 ("trade_resolved", c_uint, 1), | ||||
|                 ("has_breaks", c_uint, 1), | ||||
|                 ("gutted", c_uint, 1), | ||||
|                 ("circulatory_spray", c_uint, 1), | ||||
|                 ("locked_in_for_trading", c_uint, 1), | ||||
|                 ("slaughter", c_uint, 1), | ||||
|                 ("underworld", c_uint, 1), | ||||
|                 ("resident", c_uint, 1), | ||||
|                 ("cleanup_4", c_uint, 1), | ||||
|                 ("calculated_insulation", c_uint, 1), | ||||
|                 ("visitor_uninvited", c_uint, 1), | ||||
|                 ("visitor", c_uint, 1), | ||||
|                 ("calculated_inventory", c_uint, 1), | ||||
|                 ("vision_good", c_uint, 1), | ||||
|                 ("vision_damaged", c_uint, 1), | ||||
|                 ("vision_missing", c_uint, 1), | ||||
|                 ("breathing_good", c_uint, 1), | ||||
|                 ("breathing_problem", c_uint, 1), | ||||
|                 ("roaming_wilderness_population_source", c_uint, 1), | ||||
|                 ("roaming_wilderness_population_source_not_a_map_feature", c_uint, 1)] | ||||
| 
 | ||||
| class CreatureFlags2(Union): | ||||
|     _fields_ = [("whole", c_uint, 32), | ||||
|                 ("bits", CreatureStruct2)] | ||||
| 
 | ||||
|     def __init__(self, initial = 0): | ||||
|         self.whole = initial | ||||
|      | ||||
|     def __int__(self): | ||||
|         return self.whole | ||||
| 
 | ||||
| class ItemStruct(Structure): | ||||
|     _fields_ = [("on_ground", c_uint, 1), | ||||
|                 ("in_job", c_uint, 1), | ||||
|                 ("in_inventory", c_uint, 1), | ||||
|                 ("u_ngrd1", c_uint, 1), | ||||
|                 ("in_workshop", c_uint, 1), | ||||
|                 ("u_ngrd2", c_uint, 1), | ||||
|                 ("u_ngrd3", c_uint, 1), | ||||
|                 ("rotten", c_uint, 1), | ||||
|                 ("unk1", c_uint, 1), | ||||
|                 ("u_ngrd4", c_uint, 1), | ||||
|                 ("unk2", c_uint, 1), | ||||
|                 ("u_ngrd5", c_uint, 1), | ||||
|                 ("unk3", c_uint, 1), | ||||
|                 ("u_ngrd6", c_uint, 1), | ||||
|                 ("narrow", c_uint, 1), | ||||
|                 ("u_ngrd7", c_uint, 1), | ||||
|                 ("worn", c_uint, 1), | ||||
|                 ("unk4", c_uint, 1), | ||||
|                 ("u_ngrd8", c_uint, 1), | ||||
|                 ("forbid", c_uint, 1), | ||||
|                 ("unk5", c_uint, 1), | ||||
|                 ("dump", c_uint, 1), | ||||
|                 ("on_fire", c_uint, 1), | ||||
|                 ("melt", c_uint, 1), | ||||
|                 ("hidden", c_uint, 1), | ||||
|                 ("u_ngrd9", c_uint, 1), | ||||
|                 ("unk6", c_uint, 1), | ||||
|                 ("unk7", c_uint, 1), | ||||
|                 ("unk8", c_uint, 1), | ||||
|                 ("unk9", c_uint, 1), | ||||
|                 ("unk10", c_uint, 1), | ||||
|                 ("unk11", c_uint, 1)] | ||||
| 
 | ||||
| class ItemFlags(Union): | ||||
|     _fields_ = [("whole", c_uint, 32), | ||||
|                 ("bits", ItemStruct)] | ||||
| 
 | ||||
|     def __init__(self, initial = 0): | ||||
|         self.whole = initial | ||||
|      | ||||
|     def __int__(self): | ||||
|         return self.whole | ||||
| 
 | ||||
| class BlockFlagStruct(Structure): | ||||
|     _fields_ = [("designated", c_uint, 1), | ||||
|                 ("unk_1", c_uint, 1), | ||||
|                 ("liquid_1", c_uint, 1), | ||||
|                 ("liquid_2", c_uint, 1), | ||||
|                 ("unk_2", c_uint, 28)] | ||||
| 
 | ||||
| class BlockFlags(Union): | ||||
|     _fields_ = [("whole", c_uint, 32), | ||||
|                 ("bits", BlockFlagStruct)] | ||||
|      | ||||
|     def __init__(self, inital = 0): | ||||
|         self.whole = initial | ||||
|      | ||||
|     def __int__(self): | ||||
|         return self.whole | ||||
| @ -0,0 +1,258 @@ | ||||
| from ctypes import * | ||||
| from collections import namedtuple | ||||
| from pydfhackflags import * | ||||
| from enum import * | ||||
| 
 | ||||
| libdfhack = cdll.libdfhack | ||||
| 
 | ||||
| int_ptr = POINTER(c_int) | ||||
| uint_ptr = POINTER(c_uint) | ||||
| 
 | ||||
| _arr_create_func = CFUNCTYPE(c_void_p, c_int) | ||||
| 
 | ||||
| TileTypes40d = ((c_int * 16) * 16) | ||||
| BiomeIndices40d = c_ubyte * 16 | ||||
| Temperatures = ((c_ushort * 16) * 16) | ||||
| Designations40d = ((DesignationFlags * 16) * 16) | ||||
| Occupancies40d = ((OccupancyFlags * 16) * 16) | ||||
| 
 | ||||
| class Position2D(Structure): | ||||
|     _fields_ = [("x", c_ushort), | ||||
|                 ("y", c_ushort)] | ||||
| 
 | ||||
| class PlaneCoord(Union): | ||||
|     _fields_ = [("xy", c_uint), | ||||
|                 ("dim", Position2D)] | ||||
| 
 | ||||
|     def __cmp__(self, other): | ||||
|         if isinstance(other, PlaneCoord): | ||||
|             return self.xy - other.xy | ||||
|         else: | ||||
|             raise TypeError("argument must be of type %s" % type(self)) | ||||
| 
 | ||||
| class Feature(Structure): | ||||
|     _fields_ = [("type", FeatureType), | ||||
|                 ("main_material", c_short), | ||||
|                 ("sub_material", c_short), | ||||
|                 ("discovered", c_byte), | ||||
|                 ("origin", c_uint)] | ||||
| 
 | ||||
| class Vein(Structure): | ||||
|     _fields_ = [("vtable", c_uint), | ||||
|                 ("type", c_int), | ||||
|                 ("assignment", c_short * 16), | ||||
|                 ("flags", c_uint), | ||||
|                 ("address_of", c_uint)] | ||||
| 
 | ||||
| class FrozenLiquidVein(Structure): | ||||
|     _fields_ = [("vtable", c_uint), | ||||
|                 ("tiles", TileTypes40d), | ||||
|                 ("address_of", c_uint)] | ||||
| 
 | ||||
| class SpatterVein(Structure): | ||||
|     _fields_ = [("vtable", c_uint), | ||||
|                 ("mat1", c_ushort), | ||||
|                 ("unk1", c_ushort), | ||||
|                 ("mat2", c_uint), | ||||
|                 ("mat3", c_ushort), | ||||
|                 ("intensity", ((c_ubyte * 16) * 16)), | ||||
|                 ("address_of", c_uint)] | ||||
| 
 | ||||
| class MapBlock40d(Structure): | ||||
|     _fields_ = [("tiletypes", TileTypes40d), | ||||
|                 ("designation", Designations40d), | ||||
|                 ("occupancy", Occupancies40d), | ||||
|                 ("biome_indices", BiomeIndices40d), | ||||
|                 ("origin", c_uint), | ||||
|                 ("blockflags", BlockFlags), | ||||
|                 ("global_feature", c_short), | ||||
|                 ("local_feature", c_short)] | ||||
|                  | ||||
| 
 | ||||
| class ViewScreen(Structure): | ||||
|     _fields_ = [("type", c_int)] | ||||
| 
 | ||||
| class Matgloss(Structure): | ||||
|     _fields_ = [("id", c_char * 128), | ||||
|                 ("fore", c_byte), | ||||
|                 ("back", c_byte), | ||||
|                 ("bright", c_byte), | ||||
|                 ("name", c_char * 128)] | ||||
| 
 | ||||
| class MatglossPair(Structure): | ||||
|     _fields_ = [("type", c_short), | ||||
|                 ("index", c_int)] | ||||
| 
 | ||||
| class DescriptorColor(Structure): | ||||
|     _fields_ = [("id", c_char * 128), | ||||
|                 ("r", c_float), | ||||
|                 ("v", c_float), | ||||
|                 ("b", c_float), | ||||
|                 ("name", c_char * 128)] | ||||
| 
 | ||||
| class MatglossOther(Structure): | ||||
|     _fields_ = [("rawname", c_char * 128)] | ||||
| 
 | ||||
| class Building(Structure): | ||||
|     _fields_ = [("origin", c_uint), | ||||
|                 ("vtable", c_uint), | ||||
|                 ("x1", c_uint), | ||||
|                 ("y1", c_uint), | ||||
|                 ("x2", c_uint), | ||||
|                 ("y2", c_uint), | ||||
|                 ("z", c_uint), | ||||
|                 ("material", MatglossPair), | ||||
|                 ("type", c_uint)] | ||||
| 
 | ||||
| class CustomWorkshop(Structure): | ||||
|     _fields_ = [("index", c_uint), | ||||
|                 ("name", c_char * 256)] | ||||
| 
 | ||||
| class Construction(Structure): | ||||
|     _fields_ = [("x", c_ushort), | ||||
|                 ("y", c_ushort), | ||||
|                 ("z", c_ushort), | ||||
|                 ("form", c_ushort), | ||||
|                 ("unk_8", c_ushort), | ||||
|                 ("mat_type", c_ushort), | ||||
|                 ("mat_idx", c_ushort), | ||||
|                 ("unk3", c_ushort), | ||||
|                 ("unk4", c_ushort), | ||||
|                 ("unk5", c_ushort), | ||||
|                 ("unk6", c_uint), | ||||
|                 ("origin", c_uint)] | ||||
| 
 | ||||
| class Tree(Structure): | ||||
|     _fields_ = [("type", c_ushort), | ||||
|                 ("material", c_ushort), | ||||
|                 ("x", c_ushort), | ||||
|                 ("y", c_ushort), | ||||
|                 ("z", c_ushort), | ||||
|                 ("address", c_uint)] | ||||
| 
 | ||||
| class Material(Structure): | ||||
|     _fields_ = [("itemType", c_short), | ||||
|                 ("subType", c_short), | ||||
|                 ("subIndex", c_short), | ||||
|                 ("index", c_int), | ||||
|                 ("flags", c_uint)] | ||||
| 
 | ||||
| class Skill(Structure): | ||||
|     _fields_ = [("id", c_ushort), | ||||
|                 ("experience", c_uint), | ||||
|                 ("rating", c_ushort)] | ||||
| 
 | ||||
| class Job(Structure): | ||||
|     _fields_ = [("active", c_byte), | ||||
|                 ("jobId", c_uint), | ||||
|                 ("jobType", c_ubyte), | ||||
|                 ("occupationPtr", c_uint)] | ||||
| 
 | ||||
| class Like(Structure): | ||||
|     _fields_ = [("type", c_short), | ||||
|                 ("itemClass", c_short), | ||||
|                 ("itemIndex", c_short), | ||||
|                 ("material", MatglossPair), | ||||
|                 ("active", c_byte)] | ||||
| 
 | ||||
| class Attribute(Structure): | ||||
|     _fields_ = [("level", c_uint), | ||||
|                 ("field_4", c_uint), | ||||
|                 ("field_8", c_uint), | ||||
|                 ("field_C", c_uint), | ||||
|                 ("leveldiff", c_uint), | ||||
|                 ("field_14", c_uint), | ||||
|                 ("field_18", c_uint)] | ||||
| 
 | ||||
| class Name(Structure): | ||||
|     _fields_ = [("first_name", (c_char * 128)), | ||||
|                 ("nickname", (c_char * 128)), | ||||
|                 ("words", (c_int * 7)), | ||||
|                 ("parts_of_speech", (c_ushort * 7)), | ||||
|                 ("language", c_uint), | ||||
|                 ("has_name", c_byte)] | ||||
| 
 | ||||
| class Note(Structure): | ||||
|     _fields_ = [("symbol", c_char), | ||||
|                 ("foreground", c_ushort), | ||||
|                 ("background", c_ushort), | ||||
|                 ("name", (c_char * 128)), | ||||
|                 ("x", c_ushort), | ||||
|                 ("y", c_ushort), | ||||
|                 ("z", c_ushort)] | ||||
| 
 | ||||
| class Settlement(Structure): | ||||
|     _fields_ = [("origin", c_uint), | ||||
|                 ("name", Name), | ||||
|                 ("world_x", c_short), | ||||
|                 ("world_y", c_short), | ||||
|                 ("local_x1", c_short), | ||||
|                 ("local_x2", c_short), | ||||
|                 ("local_y1", c_short), | ||||
|                 ("local_y2", c_short)] | ||||
| 
 | ||||
| _NUM_CREATURE_TRAITS = 30 | ||||
| _NUM_CREATURE_LABORS = 102 | ||||
| 
 | ||||
| class Soul(Structure): | ||||
|     _fields_ = [("numSkills", c_ubyte), | ||||
|                 ("skills", (Skill * 256)), | ||||
|                 ("traits", (c_ushort * _NUM_CREATURE_TRAITS)), | ||||
|                 ("analytical_ability", Attribute), | ||||
|                 ("focus", Attribute), | ||||
|                 ("willpower", Attribute), | ||||
|                 ("creativity", Attribute), | ||||
|                 ("intuition", Attribute), | ||||
|                 ("patience", Attribute), | ||||
|                 ("memory", Attribute), | ||||
|                 ("linguistic_ability", Attribute), | ||||
|                 ("spatial_sense", Attribute), | ||||
|                 ("musicality", Attribute), | ||||
|                 ("kinesthetic_sense", Attribute), | ||||
|                 ("empathy", Attribute), | ||||
|                 ("social_awareness", Attribute)] | ||||
| 
 | ||||
| _MAX_COLORS = 15 | ||||
| 
 | ||||
| class Creature(Structure): | ||||
|     _fields_ = [("origin", c_uint), | ||||
|                 ("x", c_ushort), | ||||
|                 ("y", c_ushort), | ||||
|                 ("z", c_ushort), | ||||
|                 ("race", c_uint), | ||||
|                 ("civ", c_int), | ||||
|                 ("flags1", CreatureFlags1), | ||||
|                 ("flags2", CreatureFlags2), | ||||
|                 ("name", Name), | ||||
|                 ("mood", c_short), | ||||
|                 ("mood_skill", c_short), | ||||
|                 ("artifact_name", Name), | ||||
|                 ("profession", c_ubyte), | ||||
|                 ("custom_profession", (c_char * 128)), | ||||
|                 ("labors", (c_ubyte * _NUM_CREATURE_LABORS)), | ||||
|                 ("current_job", Job), | ||||
|                 ("happiness", c_uint), | ||||
|                 ("id", c_uint), | ||||
|                 ("strength", Attribute), | ||||
|                 ("agility", Attribute), | ||||
|                 ("toughness", Attribute), | ||||
|                 ("endurance", Attribute), | ||||
|                 ("recuperation", Attribute), | ||||
|                 ("disease_resistance", Attribute), | ||||
|                 ("squad_leader_id", c_int), | ||||
|                 ("sex", c_ubyte), | ||||
|                 ("caste", c_ushort), | ||||
|                 ("pregnancy_timer", c_uint), | ||||
|                 ("has_default_soul", c_byte), | ||||
|                 ("defaultSoul", Soul), | ||||
|                 ("nbcolors", c_uint), | ||||
|                 ("color", (c_uint * _MAX_COLORS))] | ||||
| 
 | ||||
| class CreatureExtract(Structure): | ||||
|     _fields_ = [("rawname", (c_char * 128))] | ||||
| 
 | ||||
| class BodyPart(Structure): | ||||
|     _fields_ = [("id", (c_char * 128)), | ||||
|                 ("category", (c_char * 128)), | ||||
|                 ("single", (c_char * 128)), | ||||
|                 ("plural", (c_char * 128))] | ||||
| @ -0,0 +1,14 @@ | ||||
| from ctypes import * | ||||
| 
 | ||||
| def _uintify(x, y, z): | ||||
|     return (c_uint(x), c_uint(y), c_uint(z)) | ||||
| 
 | ||||
| def _allocate_array(t_type, count): | ||||
|     arr_type = t_type * count | ||||
| 
 | ||||
|     arr = arr_type() | ||||
| 
 | ||||
|     ptr = c_void_p() | ||||
|     ptr = addressof(arr) | ||||
| 
 | ||||
|     return (arr, ptr) | ||||
| @ -0,0 +1,25 @@ | ||||
| from ctypes import * | ||||
| from pydftypes import libdfhack, Tree | ||||
| 
 | ||||
| class Vegetation(object): | ||||
|     def __init__(self, ptr): | ||||
|         self._v_ptr = ptr | ||||
| 
 | ||||
|     def start(self): | ||||
|         n = c_uint(0) | ||||
|          | ||||
|         if libdfhack.Vegetation_Start(self._v_ptr, byref(n)) > 0: | ||||
|             return int(n.value) | ||||
|         else: | ||||
|             return -1 | ||||
| 
 | ||||
|     def finish(self): | ||||
|         return libdfhack.Vegetation_Finish(self._v_ptr) > 0 | ||||
| 
 | ||||
|     def read(self, index): | ||||
|         t = Tree() | ||||
| 
 | ||||
|         if libdfhack.Vegetation_Read(self._v_ptr, c_uint(index), byref(t)) > 0: | ||||
|             return t | ||||
|         else: | ||||
|             return None | ||||
		Loading…
	
		Reference in New Issue