develop
Petr Mrázek 2010-05-29 23:39:59 +02:00
commit fa0d881e16
31 changed files with 434 additions and 242 deletions

@ -92,6 +92,8 @@ modules/Position_C.cpp
modules/Materials_C.cpp modules/Materials_C.cpp
modules/Translation_C.cpp modules/Translation_C.cpp
modules/Vegetation_C.cpp modules/Vegetation_C.cpp
modules/WindowIO_C.cpp
modules/World_C.cpp
) )
SET(PROJECT_HDRS_LINUX SET(PROJECT_HDRS_LINUX

@ -41,31 +41,31 @@ using namespace DFHack;
extern "C" { extern "C" {
#endif #endif
int8_t* (*alloc_byte_buffer_callback)(uint32_t) = NULL; int (*alloc_byte_buffer_callback)(int8_t*, uint32_t) = NULL;
int16_t* (*alloc_short_buffer_callback)(uint32_t) = NULL; int (*alloc_short_buffer_callback)(int16_t*, uint32_t) = NULL;
int32_t* (*alloc_int_buffer_callback)(uint32_t) = NULL; int (*alloc_int_buffer_callback)(int32_t*, uint32_t) = NULL;
uint8_t* (*alloc_ubyte_buffer_callback)(uint32_t) = NULL; int (*alloc_ubyte_buffer_callback)(uint8_t*, uint32_t) = NULL;
uint16_t* (*alloc_ushort_buffer_callback)(uint32_t) = NULL; int (*alloc_ushort_buffer_callback)(uint16_t*, uint32_t) = NULL;
uint32_t* (*alloc_uint_buffer_callback)(uint32_t) = NULL; int (*alloc_uint_buffer_callback)(uint32_t*, uint32_t) = NULL;
char* (*alloc_char_buffer_callback)(uint32_t) = NULL; int (*alloc_char_buffer_callback)(char*, uint32_t) = NULL;
t_matgloss* (*alloc_matgloss_buffer_callback)(int) = NULL; int (*alloc_matgloss_buffer_callback)(t_matgloss*, uint32_t) = NULL;
t_descriptor_color* (*alloc_descriptor_buffer_callback)(int) = NULL; int (*alloc_descriptor_buffer_callback)(t_descriptor_color*, uint32_t) = NULL;
t_matglossOther* (*alloc_matgloss_other_buffer_callback)(int) = NULL; int (*alloc_matgloss_other_buffer_callback)(t_matglossOther*, uint32_t) = NULL;
c_colormodifier* (*alloc_empty_colormodifier_callback)(void) = NULL; int (*alloc_empty_colormodifier_callback)(c_colormodifier*) = NULL;
c_colormodifier* (*alloc_colormodifier_callback)(const char*, uint32_t) = NULL; int (*alloc_colormodifier_callback)(c_colormodifier*, const char*, uint32_t) = NULL;
c_colormodifier* (*alloc_colormodifier_buffer_callback)(uint32_t) = NULL; int (*alloc_colormodifier_buffer_callback)(c_colormodifier*, uint32_t) = NULL;
c_creaturecaste* (*alloc_empty_creaturecaste_callback)(void) = NULL; int (*alloc_empty_creaturecaste_callback)(c_creaturecaste*)= NULL;
c_creaturecaste* (*alloc_creaturecaste_callback)(const char*, const char*, const char*, const char*, uint32_t, uint32_t) = NULL; int (*alloc_creaturecaste_callback)(c_creaturecaste*, const char*, const char*, const char*, const char*, uint32_t, uint32_t) = NULL;
c_creaturecaste* (*alloc_creaturecaste_buffer_callback)(uint32_t) = NULL; int (*alloc_creaturecaste_buffer_callback)(c_creaturecaste*, uint32_t) = NULL;
c_creaturetype* (*alloc_empty_creaturetype_callback)(void) = NULL; int (*alloc_empty_creaturetype_callback)(c_creaturetype*) = NULL;
c_creaturetype* (*alloc_creaturetype_callback)(const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t) = NULL; int (*alloc_creaturetype_callback)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t) = NULL;
c_creaturetype* (*alloc_creaturetype_buffer_callback)(uint32_t) = NULL; int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, uint32_t) = NULL;
#ifdef __cplusplus #ifdef __cplusplus
} }
@ -76,7 +76,7 @@ int ColorListConvert(t_colormodifier* src, c_colormodifier* dest)
if(src == NULL) if(src == NULL)
return -1; return -1;
dest = ((*alloc_colormodifier_callback)(src->part, src->colorlist.size())); ((*alloc_colormodifier_callback)(dest, src->part, src->colorlist.size()));
copy(src->colorlist.begin(), src->colorlist.end(), dest->colorlist); copy(src->colorlist.begin(), src->colorlist.end(), dest->colorlist);
@ -88,7 +88,7 @@ int CreatureCasteConvert(t_creaturecaste* src, c_creaturecaste* dest)
if(src == NULL) if(src == NULL)
return -1; return -1;
dest = ((*alloc_creaturecaste_callback)(src->rawname, src->singular, src->plural, src->adjective, src->ColorModifier.size(), src->bodypart.size())); ((*alloc_creaturecaste_callback)(dest, src->rawname, src->singular, src->plural, src->adjective, src->ColorModifier.size(), src->bodypart.size()));
for(int i = 0; i < dest->colorModifierLength; i++) for(int i = 0; i < dest->colorModifierLength; i++)
ColorListConvert(&src->ColorModifier[i], &dest->ColorModifier[i]); ColorListConvert(&src->ColorModifier[i], &dest->ColorModifier[i]);
@ -103,7 +103,7 @@ int CreatureTypeConvert(t_creaturetype* src, c_creaturetype* dest)
if(src == NULL) if(src == NULL)
return -1; return -1;
dest = ((*alloc_creaturetype_callback)(src->rawname, src->castes.size(), src->extract.size(), src->tile_character, src->tilecolor.fore, src->tilecolor.back, src->tilecolor.bright)); ((*alloc_creaturetype_callback)(dest, src->rawname, src->castes.size(), src->extract.size(), src->tile_character, src->tilecolor.fore, src->tilecolor.back, src->tilecolor.bright));
for(int i = 0; i < dest->castesCount; i++) for(int i = 0; i < dest->castesCount; i++)
CreatureCasteConvert(&src->castes[i], &dest->castes[i]); CreatureCasteConvert(&src->castes[i], &dest->castes[i]);

@ -25,12 +25,20 @@ distribution.
#ifndef DFHACK_C_API #ifndef DFHACK_C_API
#define DFHACK_C_API #define DFHACK_C_API
typedef void DFHackObject; #include <cstdio>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include "dfhack/DFGlobal.h"
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h" #include "dfhack/DFIntegers.h"
#include "dfhack-c/DFContext_C.h"
#include "dfhack-c/DFTypes_C.h" using namespace std;
using namespace DFHack;
typedef void DFHackObject;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -25,10 +25,7 @@ distribution.
#ifndef DFHACK_C_CONTEXT #ifndef DFHACK_C_CONTEXT
#define DFHACK_C_CONTEXT #define DFHACK_C_CONTEXT
#include "dfhack/DFExport.h" #include "DFHack_C.h"
#include "dfhack/DFIntegers.h"
typedef void DFHackObject;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -25,30 +25,27 @@ distribution.
#ifndef TYPES_C_API #ifndef TYPES_C_API
#define TYPES_C_API #define TYPES_C_API
#include "dfhack/DFExport.h" #include "DFHack_C.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
DFHACK_EXPORT extern int8_t* (*alloc_byte_buffer_callback)(uint32_t); DFHACK_EXPORT extern int (*alloc_byte_buffer_callback)(int8_t*, uint32_t);
DFHACK_EXPORT extern int16_t* (*alloc_short_buffer_callback)(uint32_t); DFHACK_EXPORT extern int (*alloc_short_buffer_callback)(int16_t*, uint32_t);
DFHACK_EXPORT extern int32_t* (*alloc_int_buffer_callback)(uint32_t); DFHACK_EXPORT extern int (*alloc_int_buffer_callback)(int32_t*, uint32_t);
DFHACK_EXPORT extern uint8_t* (*alloc_ubyte_buffer_callback)(uint32_t); DFHACK_EXPORT extern int (*alloc_ubyte_buffer_callback)(uint8_t*, uint32_t);
DFHACK_EXPORT extern uint16_t* (*alloc_ushort_buffer_callback)(uint32_t); DFHACK_EXPORT extern int (*alloc_ushort_buffer_callback)(uint16_t*, uint32_t);
DFHACK_EXPORT extern uint32_t* (*alloc_uint_buffer_callback)(uint32_t); DFHACK_EXPORT extern int (*alloc_uint_buffer_callback)(uint32_t*, uint32_t);
DFHACK_EXPORT extern char* (*alloc_char_buffer_callback)(uint32_t); DFHACK_EXPORT extern int (*alloc_char_buffer_callback)(char*, uint32_t);
DFHACK_EXPORT extern t_matgloss* (*alloc_matgloss_buffer_callback)(int); DFHACK_EXPORT extern int (*alloc_matgloss_buffer_callback)(t_matgloss*, uint32_t);
DFHACK_EXPORT extern t_descriptor_color* (*alloc_descriptor_buffer_callback)(int); DFHACK_EXPORT extern int (*alloc_descriptor_buffer_callback)(t_descriptor_color*, uint32_t);
DFHACK_EXPORT extern t_matglossOther* (*alloc_matgloss_other_buffer_callback)(int); DFHACK_EXPORT extern int (*alloc_matgloss_other_buffer_callback)(t_matglossOther*, uint32_t);
struct c_colormodifier struct c_colormodifier
{ {
@ -57,9 +54,9 @@ struct c_colormodifier
uint32_t colorlistLength; uint32_t colorlistLength;
}; };
DFHACK_EXPORT extern c_colormodifier* (*alloc_empty_colormodifier_callback)(void); DFHACK_EXPORT extern int (*alloc_empty_colormodifier_callback)(c_colormodifier*);
DFHACK_EXPORT extern c_colormodifier* (*alloc_colormodifier_callback)(const char*, uint32_t); DFHACK_EXPORT extern int (*alloc_colormodifier_callback)(c_colormodifier*, const char*, uint32_t);
DFHACK_EXPORT extern c_colormodifier* (*alloc_colormodifier_buffer_callback)(uint32_t); DFHACK_EXPORT extern int (*alloc_colormodifier_buffer_callback)(c_colormodifier*, uint32_t);
struct c_creaturecaste struct c_creaturecaste
{ {
@ -75,9 +72,9 @@ struct c_creaturecaste
uint32_t bodypartLength; uint32_t bodypartLength;
}; };
DFHACK_EXPORT extern c_creaturecaste* (*alloc_empty_creaturecaste_callback)(void); DFHACK_EXPORT extern int (*alloc_empty_creaturecaste_callback)(c_creaturecaste*);
DFHACK_EXPORT extern c_creaturecaste* (*alloc_creaturecaste_callback)(const char*, const char*, const char*, const char*, uint32_t, uint32_t); DFHACK_EXPORT extern int (*alloc_creaturecaste_callback)(c_creaturecaste*, const char*, const char*, const char*, const char*, uint32_t, uint32_t);
DFHACK_EXPORT extern c_creaturecaste* (*alloc_creaturecaste_buffer_callback)(uint32_t); DFHACK_EXPORT extern int (*alloc_creaturecaste_buffer_callback)(c_creaturecaste*, uint32_t);
struct c_creaturetype struct c_creaturetype
{ {
@ -99,9 +96,9 @@ struct c_creaturetype
} tilecolor; } tilecolor;
}; };
DFHACK_EXPORT extern c_creaturetype* (*alloc_empty_creaturetype_callback)(void); DFHACK_EXPORT extern int (*alloc_empty_creaturetype_callback)(c_creaturetype*);
DFHACK_EXPORT extern c_creaturetype* (*alloc_creaturetype_callback)(const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t); DFHACK_EXPORT extern int (*alloc_creaturetype_callback)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t);
DFHACK_EXPORT extern c_creaturetype* (*alloc_creaturetype_buffer_callback)(uint32_t); DFHACK_EXPORT extern int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, uint32_t);
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -25,13 +25,9 @@ distribution.
#ifndef BUILDINGS_C_API #ifndef BUILDINGS_C_API
#define BUILDINGS_C_API #define BUILDINGS_C_API
#include "dfhack/DFExport.h" #include "DFHack_C.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Buildings.h" #include "dfhack/modules/Buildings.h"
#include "DFHack_C.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -25,13 +25,9 @@ distribution.
#ifndef CONSTRUCTIONS_C_API #ifndef CONSTRUCTIONS_C_API
#define CONSTRUCTIONS_C_API #define CONSTRUCTIONS_C_API
#include "dfhack/DFExport.h" #include "DFHack_C.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Constructions.h" #include "dfhack/modules/Constructions.h"
#include "DFHack_C.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -25,15 +25,11 @@ distribution.
#ifndef CREATURES_C_API #ifndef CREATURES_C_API
#define CREATURES_C_API #define CREATURES_C_API
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "DFHack_C.h" #include "DFHack_C.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "dfhack/modules/Creatures.h" #include "dfhack/modules/Creatures.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

@ -25,11 +25,9 @@ distribution.
#ifndef GUI_C_API #ifndef GUI_C_API
#define GUI_C_API #define GUI_C_API
#include "dfhack/DFExport.h" #include "DFHack_C.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Gui.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -25,15 +25,10 @@ distribution.
#ifndef ITEMS_C_API #ifndef ITEMS_C_API
#define ITEMS_C_API #define ITEMS_C_API
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "Internal.h"
using namespace DFHack;
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Items.h"
#include "DFHack_C.h" #include "DFHack_C.h"
#include "dfhack/DFProcess.h"
#include "dfhack-c/DFTypes_C.h"
#include "dfhack/modules/Items.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -25,19 +25,9 @@ distribution.
#ifndef MAPS_C_API #ifndef MAPS_C_API
#define MAPS_C_API #define MAPS_C_API
#include "dfhack/DFExport.h" #include "DFHack_C.h"
#include "dfhack/DFIntegers.h"
#include <vector>
#include <map>
#include <string>
using namespace std;
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Maps.h" #include "dfhack/modules/Maps.h"
#include "DFHack_C.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -25,14 +25,9 @@ distribution.
#ifndef MATERIALS_C_API #ifndef MATERIALS_C_API
#define MATERIALS_C_API #define MATERIALS_C_API
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h"
#include "DFHack_C.h" #include "DFHack_C.h"
#include "dfhack-c/DFTypes_C.h" #include "dfhack-c/DFTypes_C.h"
#include "dfhack/modules/Materials.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -25,8 +25,8 @@ distribution.
#ifndef POSITION_C_API #ifndef POSITION_C_API
#define POSITION_C_API #define POSITION_C_API
#include "dfhack/DFExport.h"
#include "DFHack_C.h" #include "DFHack_C.h"
#include "dfhack/modules/Position.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -25,13 +25,9 @@ distribution.
#ifndef TRANSLATION_C_API #ifndef TRANSLATION_C_API
#define TRANSLATION_C_API #define TRANSLATION_C_API
#include "dfhack/DFExport.h" #include "DFHack_C.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Translation.h" #include "dfhack/modules/Translation.h"
#include "DFHack_C.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -25,13 +25,9 @@ distribution.
#ifndef VEGETATION_C_API #ifndef VEGETATION_C_API
#define VEGETATION_C_API #define VEGETATION_C_API
#include "dfhack/DFExport.h" #include "DFHack_C.h"
#include "dfhack/DFIntegers.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Vegetation.h" #include "dfhack/modules/Vegetation.h"
#include "DFHack_C.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -0,0 +1,43 @@
/*
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 WINDOWIO_C_API
#define WINDOWIO_C_API
#include "DFHack_C.h"
#include "dfhack/modules/WindowIO.h"
#ifdef __cplusplus
extern "C" {
#endif
DFHACK_EXPORT int WindowIO_TypeStr(DFHackObject* window, const char* input, int delay, bool useShift);
DFHACK_EXPORT int WindowIO_TypeSpecial(DFHackObject* window, t_special command, int count, int delay);
#ifdef __cplusplus
}
#endif
#endif

@ -0,0 +1,47 @@
/*
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 WORLD_C_API
#define WORLD_C_API
#include "DFHack_C.h"
#include "dfhack/modules/World.h"
#ifdef __cplusplus
extern "C" {
#endif
DFHACK_EXPORT int World_Start(DFHackObject* world);
DFHACK_EXPORT int World_Finish(DFHackObject* world);
DFHACK_EXPORT int World_ReadCurrentTick(DFHackObject* world, uint32_t* tick);
DFHACK_EXPORT int World_ReadCurrentYear(DFHackObject* world, uint32_t* year);
DFHACK_EXPORT int World_ReadCurrentMonth(DFHackObject* world, uint32_t* month);
DFHACK_EXPORT int World_ReadCurrentDay(DFHackObject* world, uint32_t* day);
#ifdef __cplusplus
}
#endif
#endif

@ -22,20 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "dfhack/DFIntegers.h"
#include <string>
#include <map>
#include "stdio.h"
using namespace std;
#include "Internal.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Buildings.h"
#include "dfhack-c/modules/Buildings_C.h" #include "dfhack-c/modules/Buildings_C.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

@ -22,15 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "dfhack/DFIntegers.h"
#include "Internal.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Constructions.h"
#include "dfhack-c/modules/Constructions_C.h" #include "dfhack-c/modules/Constructions_C.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

@ -22,21 +22,7 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Creatures.h"
#include "dfhack-c/modules/Creatures_C.h" #include "dfhack-c/modules/Creatures_C.h"
#include "DFHack_C.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -21,16 +21,8 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#include <vector>
#include <string>
#include "DFHack_C.h"
#include "dfhack-c/modules/Gui_C.h"
#include "dfhack/DFIntegers.h"
#include "Internal.h"
#include "dfhack/modules/Gui.h"
using namespace DFHack; #include "dfhack-c/modules/Gui_C.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -22,25 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include <map>
#include <vector>
#include <string>
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
#include "DFHack_C.h"
#include "dfhack/DFTypes.h"
using namespace std;
using namespace DFHack;
#include "dfhack/DFProcess.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Items.h"
#include "dfhack-c/DFTypes_C.h"
#include "dfhack-c/modules/Items_C.h" #include "dfhack-c/modules/Items_C.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

@ -22,20 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "dfhack/DFIntegers.h"
#include <vector>
#include <map>
#include <string>
using namespace std;
#include "Internal.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Maps.h"
#include "dfhack-c/modules/Maps_C.h" #include "dfhack-c/modules/Maps_C.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

@ -22,21 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "dfhack/DFIntegers.h"
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#include "Internal.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h"
#include "dfhack-c/DFTypes_C.h"
#include "dfhack-c/modules/Materials_C.h" #include "dfhack-c/modules/Materials_C.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -233,7 +220,9 @@ t_matgloss* Materials_getInorganic(DFHackObject* mat)
if(materials->inorganic.size() > 0) if(materials->inorganic.size() > 0)
{ {
t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->inorganic.size())); t_matgloss* buf;
((*alloc_matgloss_buffer_callback)(buf, materials->inorganic.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -255,7 +244,9 @@ t_matgloss* Materials_getOrganic(DFHackObject* mat)
if(materials->organic.size() > 0) if(materials->organic.size() > 0)
{ {
t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->organic.size())); t_matgloss* buf;
((*alloc_matgloss_buffer_callback)(buf, materials->organic.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -277,7 +268,9 @@ t_matgloss* Materials_getTree(DFHackObject* mat)
if(materials->tree.size() > 0) if(materials->tree.size() > 0)
{ {
t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->tree.size())); t_matgloss* buf;
((*alloc_matgloss_buffer_callback)(buf, materials->tree.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -299,7 +292,9 @@ t_matgloss* Materials_getPlant(DFHackObject* mat)
if(materials->plant.size() > 0) if(materials->plant.size() > 0)
{ {
t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->plant.size())); t_matgloss* buf;
((*alloc_matgloss_buffer_callback)(buf, materials->plant.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -321,7 +316,9 @@ t_matgloss* Materials_getRace(DFHackObject* mat)
if(materials->race.size() > 0) if(materials->race.size() > 0)
{ {
t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->race.size())); t_matgloss* buf;
((*alloc_matgloss_buffer_callback)(buf, materials->race.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -345,7 +342,9 @@ c_creaturetype* Materials_getRaceEx(DFHackObject* mat)
if(matSize > 0) if(matSize > 0)
{ {
c_creaturetype* buf = ((*alloc_creaturetype_buffer_callback)(matSize)); c_creaturetype* buf;
((*alloc_creaturetype_buffer_callback)(buf, matSize));
if(buf != NULL) if(buf != NULL)
{ {
@ -368,7 +367,9 @@ t_descriptor_color* Materials_getColor(DFHackObject* mat)
if(materials->color.size() > 0) if(materials->color.size() > 0)
{ {
t_descriptor_color* buf = ((*alloc_descriptor_buffer_callback)(materials->color.size())); t_descriptor_color* buf;
((*alloc_descriptor_buffer_callback)(buf, materials->color.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -390,7 +391,9 @@ t_matglossOther* Materials_getOther(DFHackObject* mat)
if(materials->other.size() > 0) if(materials->other.size() > 0)
{ {
t_matglossOther* buf = ((*alloc_matgloss_other_buffer_callback)(materials->other.size())); t_matglossOther* buf;
((*alloc_matgloss_other_buffer_callback)(buf, materials->other.size()));
if(buf != NULL) if(buf != NULL)
{ {

@ -22,15 +22,7 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include <vector>
#include <string>
#include "dfhack-c/modules/Position_C.h" #include "dfhack-c/modules/Position_C.h"
#include "dfhack/DFIntegers.h"
#include "Internal.h"
#include "dfhack/modules/Position.h"
using namespace DFHack;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -0,0 +1,64 @@
/*
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.
*/
using namespace std;
#include "dfhack/DFIntegers.h"
#include "DFHack.h"
#include "DFHack_C.h"
#include "dfhack/modules/WindowIO.h"
#include "dfhack-c/modules/WindowIO_C.h"
using namespace DFHack;
#ifdef __cplusplus
extern "C" {
#endif
int WindowIO_TypeStr(DFHackObject* window, const char* input, int delay, bool useShift)
{
if(window != NULL)
{
((DFHack::WindowIO*)window)->TypeStr(input, delay, useShift);
return 1;
}
return -1;
}
int WindowIO_TypeSpecial(DFHackObject* window, t_special command, int count, int delay)
{
if(window != NULL)
{
((DFHack::WindowIO*)window)->TypeSpecial(command, count, delay);
return 1;
}
return -1;
}
#ifdef __cplusplus
}
#endif

@ -0,0 +1,105 @@
/*
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 "DFHack_C.h"
#include "dfhack/modules/World.h"
#include "dfhack-c/modules/World_C.h"
#ifdef __cplusplus
extern "C" {
#endif
int World_Start(DFHackObject* world)
{
if(world != NULL)
{
if(((DFHack::World*)world)->Start())
return 1;
else
return 0;
}
return -1;
}
int World_Finish(DFHackObject* world)
{
if(world != NULL)
{
if(((DFHack::World*)world)->Finish())
return 1;
else
return 0;
}
return -1;
}
int World_ReadCurrentTick(DFHackObject* world, uint32_t* tick)
{
if(world != NULL)
{
*tick = ((DFHack::World*)world)->ReadCurrentTick();
return 1;
}
return -1;
}
int World_ReadCurrentYear(DFHackObject* world, uint32_t* year)
{
if(world != NULL)
{
*year = ((DFHack::World*)world)->ReadCurrentYear();
return 1;
}
return -1;
}
int World_ReadCurrentMonth(DFHackObject* world, uint32_t* month)
{
if(world != NULL)
{
*month = ((DFHack::World*)world)->ReadCurrentMonth();
return 1;
}
return -1;
}
int World_ReadCurrentDay(DFHackObject* world, uint32_t* day)
{
if(world != NULL)
{
*day = ((DFHack::World*)world)->ReadCurrentDay();
return 1;
}
return -1;
}
#ifdef __cplusplus
}
#endif

@ -170,7 +170,9 @@ class Context(object):
return self._tran_obj return self._tran_obj
def reveal(): def reveal():
df = API("Memory.xml") df_cm = ContextManager("Memory.xml")
df = df_cm.get_single_context()
df.attach() df.attach()
m = df.maps m = df.maps
@ -193,3 +195,11 @@ def reveal():
m.finish() m.finish()
df.detach() df.detach()
def resume():
df_cm = ContextManager("Memory.xml")
df = df_cm.get_single_context()
df.attach()
df.force_resume()
df.detach()

@ -1,6 +1,6 @@
from ctypes import * from ctypes import *
from pydftypes import libdfhack from pydftypes import *
from util import _uintify from util import _uintify, uint_ptr
libdfhack.Maps_getSize.argtypes = [ c_void_p, uint_ptr, uint_ptr, uint_ptr ] 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_ReadTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ]

@ -87,12 +87,15 @@ class Matgloss(Structure):
("bright", c_byte), ("bright", c_byte),
("name", c_char * 128)] ("name", c_char * 128)]
def _alloc_matgloss_buffer_callback(count): def _alloc_matgloss_buffer_callback(ptr, count):
allocated = _allocate_array(Matgloss, count) allocated = _allocate_array(Matgloss, count)
return allocated[1] ptr = addressof(allocated[0])
libdfhack.alloc_matgloss_buffer_callback = CFUNCTYPE(POINTER(Matgloss), c_int)(_alloc_matgloss_buffer_callback) return 1
_matgloss_functype = CFUNCTYPE(c_int, POINTER(Matgloss), c_uint)
libdfhack.alloc_matgloss_buffer_callback = _matgloss_functype(_alloc_matgloss_buffer_callback)
class MatglossPair(Structure): class MatglossPair(Structure):
_fields_ = [("type", c_short), _fields_ = [("type", c_short),
@ -105,12 +108,15 @@ class DescriptorColor(Structure):
("b", c_float), ("b", c_float),
("name", c_char * 128)] ("name", c_char * 128)]
def _alloc_descriptor_buffer_callback(count): def _alloc_descriptor_buffer_callback(ptr, count):
allocated = _allocate_array(DescriptorColor, count) allocated = _allocate_array(DescriptorColor, count)
return allocated[1] ptr = addressof(allocated[0])
return 1
libdfhack.alloc_descriptor_buffer_callback = CFUNCTYPE(POINTER(DescriptorColor), c_int)(_alloc_descriptor_buffer_callback) _descriptor_functype = CFUNCTYPE(c_int, POINTER(DescriptorColor), c_uint)
libdfhack.alloc_descriptor_buffer_callback = _descriptor_functype(_alloc_descriptor_buffer_callback)
class MatglossOther(Structure): class MatglossOther(Structure):
_fields_ = [("rawname", c_char * 128)] _fields_ = [("rawname", c_char * 128)]
@ -118,9 +124,12 @@ class MatglossOther(Structure):
def _alloc_matgloss_other_buffer_callback(count): def _alloc_matgloss_other_buffer_callback(count):
allocated = _allocate_array(MatglossOther, count) allocated = _allocate_array(MatglossOther, count)
return allocated[1] ptr = addressof(allocated[0])
libdfhack.alloc_matgloss_other_buffer_callback = CFUNCTYPE(POINTER(MatglossOther), c_int)(_alloc_matgloss_other_buffer_callback) return 1
_matgloss_other_functype = CFUNCTYPE(c_int, POINTER(MatglossOther), c_uint)
libdfhack.alloc_matgloss_other_buffer_callback = _matgloss_other_functype(_alloc_matgloss_other_buffer_callback)
class Building(Structure): class Building(Structure):
_fields_ = [("origin", c_uint), _fields_ = [("origin", c_uint),
@ -297,7 +306,10 @@ class ColorModifier(Structure):
ColorModifierPtr = POINTER(ColorModifier) ColorModifierPtr = POINTER(ColorModifier)
def _alloc_empty_colormodifier_callback(): def _alloc_empty_colormodifier_callback(ptr):
return ColorModifierPtr(ColorModifier()) ptr = ColorModifierPtr(ColorModifier())
return 1
libdfhack.alloc_empty_colormodifier_callback = CFUNCTYPE(ColorModifierPtr)(_alloc_empty_colormodifier_callback) _empty_colormodifier_functype = CFUNCTYPE(c_int, ColorModifierPtr)
libdfhack.alloc_empty_colormodifier_callback = _empty_colormodifier_functype(_alloc_empty_colormodifier_callback)

@ -1,5 +1,8 @@
from ctypes import * from ctypes import *
uint_ptr = POINTER(c_uint)
int_ptr = POINTER(c_int)
def _uintify(x, y, z): def _uintify(x, y, z):
return (c_uint(x), c_uint(y), c_uint(z)) return (c_uint(x), c_uint(y), c_uint(z))
@ -13,54 +16,75 @@ def _allocate_array(t_type, count):
return (arr, ptr) return (arr, ptr)
def _alloc_int_buffer(count): def _alloc_int_buffer(ptr, count):
a = _allocate_array(c_int, count) a = _allocate_array(c_int, count)
return a[1] ptr = addressof(a[0])
return 1
alloc_int_buffer = CFUNCTYPE(POINTER(c_int), c_uint)(_alloc_int_buffer) _int_functype = CFUNCTYPE(c_int, POINTER(c_int), c_uint)
alloc_int_buffer = _int_functype(_alloc_int_buffer)
def _alloc_uint_buffer(count): def _alloc_uint_buffer(ptr, count):
a = _allocate_array(c_uint, count) a = _allocate_array(c_uint, count)
return a[1] ptr = addressof(a[0])
return 1
alloc_uint_buffer = CFUNCTYPE(POINTER(c_uint), c_uint)(_alloc_uint_buffer) _uint_functype = CFUNCTYPE(c_int, POINTER(c_uint), c_uint)
alloc_uint_buffer = _uint_functype(_alloc_uint_buffer)
def _alloc_short_buffer(count): def _alloc_short_buffer(ptr, count):
a = _allocate_array(c_short, count) a = _allocate_array(c_short, count)
return a[1] ptr = addressof(a[0])
alloc_short_buffer = CFUNCTYPE(POINTER(c_short), c_uint)(_alloc_short_buffer) return 1
def _alloc_ushort_buffer(count): _short_functype = CFUNCTYPE(c_int, POINTER(c_short), c_uint)
alloc_short_buffer = _short_functype(_alloc_short_buffer)
def _alloc_ushort_buffer(ptr, count):
a = _allocate_array(c_ushort, count) a = _allocate_array(c_ushort, count)
return a[1] ptr = addressof(a[0])
return 1
alloc_ushort_buffer = CFUNCTYPE(POINTER(c_ushort), c_uint)(_alloc_ushort_buffer) _ushort_functype = CFUNCTYPE(c_int, POINTER(c_ushort), c_uint)
alloc_ushort_buffer = _ushort_functype(_alloc_ushort_buffer)
def _alloc_byte_buffer(count): def _alloc_byte_buffer(ptr, count):
a = _allocate_array(c_byte, count) a = _allocate_array(c_byte, count)
return a[1] ptr = addressof(a[0])
alloc_byte_buffer = CFUNCTYPE(POINTER(c_byte), c_uint)(_alloc_byte_buffer) return 1
def _alloc_ubyte_buffer(count): _byte_functype = CFUNCTYPE(c_int, POINTER(c_byte), c_uint)
alloc_byte_buffer = _byte_functype(_alloc_byte_buffer)
def _alloc_ubyte_buffer(ptr, count):
a = _allocate_array(c_ubyte, count) a = _allocate_array(c_ubyte, count)
return a[1] ptr = addressof(a[0])
return 1
alloc_ubyte_buffer = CFUNCTYPE(POINTER(c_ubyte), c_uint)(_alloc_ubyte_buffer) _ubyte_functype = CFUNCTYPE(c_int, POINTER(c_ubyte), c_uint)
alloc_ubyte_buffer = _ubyte_functype(_alloc_ubyte_buffer)
def _alloc_char_buffer(count): def _alloc_char_buffer(ptr, count):
c = create_string_buffer(count) c = create_string_buffer(count)
ptr = c_void_p() if ptr is None:
ptr = c_void_p
ptr = addressof(c) ptr = addressof(c)
return ptr return 1
alloc_char_buffer = CFUNCTYPE(POINTER(c_char), c_uint)(_alloc_char_buffer) _char_functype = CFUNCTYPE(c_int, POINTER(c_char), c_uint)
alloc_char_buffer = _char_functype(_alloc_char_buffer)