diff --git a/library/DFProcess_C.cpp b/library/DFProcess_C.cpp index 3a07329f8..b660a2706 100644 --- a/library/DFProcess_C.cpp +++ b/library/DFProcess_C.cpp @@ -25,6 +25,7 @@ distribution. #include #include #include +#include #include using namespace std; diff --git a/library/DFTypes_C.cpp b/library/DFTypes_C.cpp index d87352c8a..33919904b 100644 --- a/library/DFTypes_C.cpp +++ b/library/DFTypes_C.cpp @@ -28,6 +28,7 @@ distribution. #include #include #include +#include #include using namespace std; @@ -169,153 +170,4 @@ UNREG_MACRO(FeatureMap, alloc_featuremap_buffer_callback) #ifdef __cplusplus } -#endif - -void BuildDescriptorList(std::vector & src, c_creaturetype_descriptor** dest) -{ - c_creaturetype_descriptor* descriptor = NULL; - - descriptor = (c_creaturetype_descriptor*)calloc(src.size(), sizeof(c_creaturetype_descriptor)); - - for(uint32_t i = 0; i < src.size(); i++) - { - uint32_t castes_size = src[i].castes.size(); - c_creaturetype_descriptor* current = &descriptor[i]; - - current->castesCount = castes_size; - current->caste_descriptors = (c_creaturecaste_descriptor*)calloc(castes_size, sizeof(c_creaturecaste_descriptor)); - - for(uint32_t j = 0; j < castes_size; j++) - { - uint32_t color_size = src[i].castes[j].ColorModifier.size(); - c_creaturecaste_descriptor* current_caste = ¤t->caste_descriptors[j]; - - current_caste->colorModifierLength = color_size; - current_caste->color_descriptors = (c_colormodifier_descriptor*)calloc(color_size, sizeof(c_colormodifier_descriptor)); - - for(uint32_t k = 0; k < color_size; k++) - { - c_colormodifier_descriptor* current_color = ¤t_caste->color_descriptors[k]; - - current_color->colorlistLength = src[i].castes[j].ColorModifier[k].colorlist.size(); - } - - current_caste->bodypartLength = src[i].castes[j].bodypart.size(); - } - - current->extractCount = src[i].extract.size(); - } - - *dest = descriptor; -} - -void FreeDescriptorList(c_creaturetype_descriptor* d, uint32_t length) -{ - for(uint32_t i = 0; i < length; i++) - { - c_creaturetype_descriptor* desc = &d[i]; - - for(uint32_t j = 0; j < desc->castesCount; j++) - free(desc->caste_descriptors[j].color_descriptors); - - free(desc->caste_descriptors); - } - - free(d); -} - -int CreatureTypeConvert(std::vector & src, c_creaturetype** out_buf) -{ - if(src.size() <= 0) - return 0; - else if(alloc_creaturetype_buffer_callback == NULL) - return -1; - else - { - c_creaturetype_descriptor* descriptor; - c_creaturetype* buf; - - BuildDescriptorList(src, &descriptor); - - ((*alloc_creaturetype_buffer_callback)(out_buf, descriptor, src.size())); - - FreeDescriptorList(descriptor, src.size()); - - if(out_buf == NULL) - return -1; - - buf = out_buf[0]; - - for(uint32_t i = 0; i < src.size(); i++) - { - c_creaturetype* current = &(buf[i]); - - memset(current->rawname, '\0', 128); - strncpy(current->rawname, src[i].rawname, 128); - - for(uint32_t j = 0; j < current->castesCount; j++) - { - c_creaturecaste* current_caste = ¤t->castes[j]; - t_creaturecaste* src_caste = &src[i].castes[j]; - - memset(current_caste->rawname, '\0', 128); - memset(current_caste->singular, '\0', 128); - memset(current_caste->plural, '\0', 128); - memset(current_caste->adjective, '\0', 128); - - strncpy(current_caste->rawname, src_caste->rawname, 128); - strncpy(current_caste->singular, src_caste->singular, 128); - strncpy(current_caste->plural, src_caste->plural, 128); - strncpy(current_caste->adjective, src_caste->adjective, 128); - - for(uint32_t k = 0; k < src[i].castes[j].ColorModifier.size(); k++) - { - c_colormodifier* current_color = ¤t_caste->colorModifier[k]; - - memset(current_color->part, '\0', 128); - strncpy(current_color->part, src_caste->ColorModifier[k].part, 128); - - copy(src_caste->ColorModifier[k].colorlist.begin(), src_caste->ColorModifier[k].colorlist.end(), current_color->colorlist); - current_color->colorlistLength = src_caste->ColorModifier[k].colorlist.size(); - - current_color->startdate = src_caste->ColorModifier[k].startdate; - current_color->enddate = src_caste->ColorModifier[k].enddate; - } - - current_caste->colorModifierLength = src_caste->ColorModifier.size(); - - copy(src_caste->bodypart.begin(), src_caste->bodypart.end(), current_caste->bodypart); - current_caste->bodypartLength = src_caste->bodypart.size(); - - current_caste->strength = src_caste->strength; - current_caste->agility = src_caste->agility; - current_caste->toughness = src_caste->toughness; - current_caste->endurance = src_caste->endurance; - current_caste->recuperation = src_caste->recuperation; - current_caste->disease_resistance = src_caste->disease_resistance; - current_caste->analytical_ability = src_caste->analytical_ability; - current_caste->focus = src_caste->focus; - current_caste->willpower = src_caste->willpower; - current_caste->creativity = src_caste->creativity; - current_caste->intuition = src_caste->intuition; - current_caste->patience = src_caste->patience; - current_caste->memory = src_caste->memory; - current_caste->linguistic_ability = src_caste->linguistic_ability; - current_caste->spatial_sense = src_caste->spatial_sense; - current_caste->musicality = src_caste->musicality; - current_caste->kinesthetic_sense = src_caste->kinesthetic_sense; - } - - copy(src[i].extract.begin(), src[i].extract.end(), current->extract); - current->extractCount = src[i].extract.size(); - - current->tile_character = src[i].tile_character; - - current->tilecolor.fore = src[i].tilecolor.fore; - current->tilecolor.back = src[i].tilecolor.back; - current->tilecolor.bright = src[i].tilecolor.bright; - } - - return 1; - } -} +#endif \ No newline at end of file diff --git a/library/include/DFHack.h b/library/include/DFHack.h index d0c3d7aaa..07db7af0c 100644 --- a/library/include/DFHack.h +++ b/library/include/DFHack.h @@ -7,6 +7,8 @@ * \defgroup grp_cwrap C Wrapper */ +#pragma once + // Defines #ifdef __GNUC__ #define DEPRECATED(func) func __attribute__ ((deprecated)) diff --git a/library/include/DFHack_C.h b/library/include/DFHack_C.h index b23457fda..6bbd38d72 100644 --- a/library/include/DFHack_C.h +++ b/library/include/DFHack_C.h @@ -22,24 +22,18 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once #ifndef DFHACK_C_API #define DFHACK_C_API #include "dfhack/DFPragma.h" -#include -#include -#include -#include -#include +namespace DFHack {}; +using namespace DFHack; -#include "dfhack/DFGlobal.h" #include "dfhack/DFExport.h" #include "dfhack/DFIntegers.h" - -using namespace DFHack; - typedef void DFHackObject; #ifdef __cplusplus diff --git a/library/include/dfhack-c/Common.h b/library/include/dfhack-c/Common.h new file mode 100644 index 000000000..49e38fd02 --- /dev/null +++ b/library/include/dfhack-c/Common.h @@ -0,0 +1,51 @@ +/* + * 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 DFHACK_C_API +#define DFHACK_C_API + +#define HBUILD(a) a ## BufferCallback +#define HREG_MACRO(type_name, type) DFHACK_EXPORT void HBUILD(Register ## type_name) (int (*funcptr)(type, uint32_t)); + +#define HUNREG_MACRO(type_name) DFHACK_EXPORT void HBUILD(Unregister ## type_name) (); + +#include "dfhack/DFPragma.h" + +#include "dfhack/DFExport.h" +#include "dfhack/DFIntegers.h" + +typedef void DFHackObject; + +#ifdef __cplusplus + +namespace DFHack {}; +using namespace DFHack; +extern "C" { + #endif + // some global stuff here + #ifdef __cplusplus +} +#endif + +#endif diff --git a/library/include/dfhack-c/DFContext_C.h b/library/include/dfhack-c/DFContext_C.h index d990196a8..9f33b885b 100644 --- a/library/include/dfhack-c/DFContext_C.h +++ b/library/include/dfhack-c/DFContext_C.h @@ -25,7 +25,7 @@ distribution. #ifndef DFHACK_C_CONTEXT #define DFHACK_C_CONTEXT -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #ifdef __cplusplus extern "C" { diff --git a/library/include/dfhack-c/DFProcess_C.h b/library/include/dfhack-c/DFProcess_C.h index e63b748fb..13d31aea3 100644 --- a/library/include/dfhack-c/DFProcess_C.h +++ b/library/include/dfhack-c/DFProcess_C.h @@ -25,7 +25,7 @@ distribution. #ifndef PROCESS_C_API #define PROCESS_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack/DFProcess.h" #ifdef __cplusplus diff --git a/library/include/dfhack-c/DFTileTypes_C.h b/library/include/dfhack-c/DFTileTypes_C.h index f54989e0d..3d23dccb0 100644 --- a/library/include/dfhack-c/DFTileTypes_C.h +++ b/library/include/dfhack-c/DFTileTypes_C.h @@ -25,7 +25,7 @@ distribution. #ifndef TILETYPES_C_API #define TILETYPES_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack/DFTileTypes.h" #ifdef __cplusplus diff --git a/library/include/dfhack-c/DFTypes_C.h b/library/include/dfhack-c/DFTypes_C.h index b65134717..95a11ee70 100644 --- a/library/include/dfhack-c/DFTypes_C.h +++ b/library/include/dfhack-c/DFTypes_C.h @@ -25,13 +25,12 @@ distribution. #ifndef TYPES_C_API #define TYPES_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "DFProcess_C.h" #include "dfhack/DFTypes.h" #include "dfhack/modules/Maps.h" #include "dfhack/modules/Materials.h" #include "dfhack/modules/Gui.h" -//#include "dfhack/DFTileTypes.h" #define HBUILD(a) a ## BufferCallback #define HREG_MACRO(type_name, type) DFHACK_EXPORT void HBUILD(Register ## type_name) (int (*funcptr)(type, uint32_t)); @@ -259,10 +258,10 @@ DFHACK_EXPORT void RegisterFeatureMapBufferCallback(int (*funcptr)(c_featuremap_ #ifdef __cplusplus } #endif - +/* void BuildDescriptorList(std::vector & src, c_creaturetype_descriptor** dest); void FreeDescriptorList(c_creaturetype_descriptor* d, uint32_t length); int CreatureTypeConvert(std::vector &, c_creaturetype**); - +*/ #endif diff --git a/library/include/dfhack-c/modules/Buildings_C.h b/library/include/dfhack-c/modules/Buildings_C.h index 54c8d98d1..772be4b76 100644 --- a/library/include/dfhack-c/modules/Buildings_C.h +++ b/library/include/dfhack-c/modules/Buildings_C.h @@ -25,7 +25,7 @@ distribution. #ifndef BUILDINGS_C_API #define BUILDINGS_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack/DFTypes.h" #include "dfhack/modules/Buildings.h" #include "dfhack-c/DFTypes_C.h" diff --git a/library/include/dfhack-c/modules/Constructions_C.h b/library/include/dfhack-c/modules/Constructions_C.h index f339b6bcc..53456bbf3 100644 --- a/library/include/dfhack-c/modules/Constructions_C.h +++ b/library/include/dfhack-c/modules/Constructions_C.h @@ -25,7 +25,7 @@ distribution. #ifndef CONSTRUCTIONS_C_API #define CONSTRUCTIONS_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack/DFTypes.h" #include "dfhack/modules/Constructions.h" diff --git a/library/include/dfhack-c/modules/Creatures_C.h b/library/include/dfhack-c/modules/Creatures_C.h index 34d145bde..b3bbcae81 100644 --- a/library/include/dfhack-c/modules/Creatures_C.h +++ b/library/include/dfhack-c/modules/Creatures_C.h @@ -25,7 +25,7 @@ distribution. #ifndef CREATURES_C_API #define CREATURES_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack/DFTypes.h" #include "dfhack-c/DFTypes_C.h" #include "dfhack/modules/Materials.h" diff --git a/library/include/dfhack-c/modules/Gui_C.h b/library/include/dfhack-c/modules/Gui_C.h index f10f23b4c..e1014258b 100644 --- a/library/include/dfhack-c/modules/Gui_C.h +++ b/library/include/dfhack-c/modules/Gui_C.h @@ -25,7 +25,7 @@ distribution. #ifndef GUI_C_API #define GUI_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack/DFTypes.h" #include "dfhack/modules/Gui.h" diff --git a/library/include/dfhack-c/modules/Items_C.h b/library/include/dfhack-c/modules/Items_C.h index 5c61513f7..2aa90cc3d 100644 --- a/library/include/dfhack-c/modules/Items_C.h +++ b/library/include/dfhack-c/modules/Items_C.h @@ -25,7 +25,7 @@ distribution. #ifndef ITEMS_C_API #define ITEMS_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack/DFProcess.h" #include "dfhack-c/DFTypes_C.h" #include "dfhack/modules/Items.h" diff --git a/library/include/dfhack-c/modules/Maps_C.h b/library/include/dfhack-c/modules/Maps_C.h index 7e759083b..bb605936d 100644 --- a/library/include/dfhack-c/modules/Maps_C.h +++ b/library/include/dfhack-c/modules/Maps_C.h @@ -25,7 +25,7 @@ distribution. #ifndef MAPS_C_API #define MAPS_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack/DFTypes.h" #include "dfhack/modules/Maps.h" diff --git a/library/include/dfhack-c/modules/Materials_C.h b/library/include/dfhack-c/modules/Materials_C.h index 82f426ca7..ca10e2152 100644 --- a/library/include/dfhack-c/modules/Materials_C.h +++ b/library/include/dfhack-c/modules/Materials_C.h @@ -25,7 +25,7 @@ distribution. #ifndef MATERIALS_C_API #define MATERIALS_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack-c/DFTypes_C.h" #include "dfhack/modules/Materials.h" diff --git a/library/include/dfhack-c/modules/Translation_C.h b/library/include/dfhack-c/modules/Translation_C.h index 79a9fbd17..87665f454 100644 --- a/library/include/dfhack-c/modules/Translation_C.h +++ b/library/include/dfhack-c/modules/Translation_C.h @@ -25,7 +25,7 @@ distribution. #ifndef TRANSLATION_C_API #define TRANSLATION_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack/DFTypes.h" #include "dfhack-c/DFTypes_C.h" #include "dfhack/modules/Translation.h" diff --git a/library/include/dfhack-c/modules/Vegetation_C.h b/library/include/dfhack-c/modules/Vegetation_C.h index 017d30a7b..acc00d7a1 100644 --- a/library/include/dfhack-c/modules/Vegetation_C.h +++ b/library/include/dfhack-c/modules/Vegetation_C.h @@ -25,7 +25,7 @@ distribution. #ifndef VEGETATION_C_API #define VEGETATION_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack/DFTypes.h" #include "dfhack/modules/Vegetation.h" diff --git a/library/include/dfhack-c/modules/WindowIO_C.h b/library/include/dfhack-c/modules/WindowIO_C.h index 2051dee6a..42c485d0f 100644 --- a/library/include/dfhack-c/modules/WindowIO_C.h +++ b/library/include/dfhack-c/modules/WindowIO_C.h @@ -25,7 +25,7 @@ distribution. #ifndef WINDOWIO_C_API #define WINDOWIO_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack/modules/WindowIO.h" #ifdef __cplusplus diff --git a/library/include/dfhack-c/modules/World_C.h b/library/include/dfhack-c/modules/World_C.h index 184d32aca..d111f402f 100644 --- a/library/include/dfhack-c/modules/World_C.h +++ b/library/include/dfhack-c/modules/World_C.h @@ -25,7 +25,7 @@ distribution. #ifndef WORLD_C_API #define WORLD_C_API -#include "DFHack_C.h" +#include "dfhack-c/Common.h" #include "dfhack/modules/World.h" #ifdef __cplusplus diff --git a/library/include/dfhack/DFContext.h b/library/include/dfhack/DFContext.h index c7f8e53b1..7c5518157 100644 --- a/library/include/dfhack/DFContext.h +++ b/library/include/dfhack/DFContext.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef CONTEXT_H_INCLUDED #define CONTEXT_H_INCLUDED diff --git a/library/include/dfhack/DFContextManager.h b/library/include/dfhack/DFContextManager.h index b06036a37..c70638ffd 100644 --- a/library/include/dfhack/DFContextManager.h +++ b/library/include/dfhack/DFContextManager.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef CONTEXTMANAGER_H_INCLUDED #define CONTEXTMANAGER_H_INCLUDED diff --git a/library/include/dfhack/DFError.h b/library/include/dfhack/DFError.h index bcb9685c7..ff270d262 100644 --- a/library/include/dfhack/DFError.h +++ b/library/include/dfhack/DFError.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef ERROR_H_INCLUDED #define ERROR_H_INCLUDED diff --git a/library/include/dfhack/DFExport.h b/library/include/dfhack/DFExport.h index bbdb2f348..797177df7 100644 --- a/library/include/dfhack/DFExport.h +++ b/library/include/dfhack/DFExport.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifdef LINUX_BUILD #ifndef DFHACK_EXPORT #define DFHACK_EXPORT __attribute__ ((visibility("default"))) diff --git a/library/include/dfhack/DFGlobal.h b/library/include/dfhack/DFGlobal.h deleted file mode 100644 index 3fdc35716..000000000 --- a/library/include/dfhack/DFGlobal.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef DFHACK_GLOBAL -#define DFHACK_GLOBAL -#include "DFExport.h" - -// globals, if any, should be placed here. - -namespace DFHack -{ - // extern DFHACK_EXPORT TYPE NAME; -} -#endif diff --git a/library/include/dfhack/DFIntegers.h b/library/include/dfhack/DFIntegers.h index cb745b251..6e4c6384f 100644 --- a/library/include/dfhack/DFIntegers.h +++ b/library/include/dfhack/DFIntegers.h @@ -7,6 +7,9 @@ stdint.h is part of the C99 standard. It's ancient and simply should be there. F You can turn off the include by defining SKIP_DFHACK_STDINT */ + +#pragma once + #ifndef SKIP_DFHACK_STDINT #ifndef _MSC_VER #include diff --git a/library/include/dfhack/DFMiscUtils.h b/library/include/dfhack/DFMiscUtils.h index 4cee41bbc..230e6f530 100644 --- a/library/include/dfhack/DFMiscUtils.h +++ b/library/include/dfhack/DFMiscUtils.h @@ -1,3 +1,5 @@ +#pragma once + #ifndef DF_MISCUTILS #define DF_MISCUTILS #include diff --git a/library/include/dfhack/DFModule.h b/library/include/dfhack/DFModule.h index 41f7dee6a..1e547abad 100644 --- a/library/include/dfhack/DFModule.h +++ b/library/include/dfhack/DFModule.h @@ -1,4 +1,3 @@ - /* www.sourceforge.net/projects/dfhack Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf @@ -23,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef MODULE_H_INCLUDED #define MODULE_H_INCLUDED diff --git a/library/include/dfhack/DFPragma.h b/library/include/dfhack/DFPragma.h index fb0d395c4..74735ca50 100644 --- a/library/include/dfhack/DFPragma.h +++ b/library/include/dfhack/DFPragma.h @@ -1,3 +1,5 @@ +#pragma once + #ifndef DFHACK_TRANQUILITY #define DFHACK_TRANQUILITY diff --git a/library/include/dfhack/DFProcess.h b/library/include/dfhack/DFProcess.h index 4b2d01bc1..f8c12a22f 100644 --- a/library/include/dfhack/DFProcess.h +++ b/library/include/dfhack/DFProcess.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef PROCESS_H_INCLUDED #define PROCESS_H_INCLUDED diff --git a/library/include/dfhack/DFProcessEnumerator.h b/library/include/dfhack/DFProcessEnumerator.h index 16be66dca..228219727 100644 --- a/library/include/dfhack/DFProcessEnumerator.h +++ b/library/include/dfhack/DFProcessEnumerator.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef PROCESSMANAGER_H_INCLUDED #define PROCESSMANAGER_H_INCLUDED diff --git a/library/include/dfhack/DFTileTypes.h b/library/include/dfhack/DFTileTypes.h index 37fd78cf1..ccb40bb3c 100644 --- a/library/include/dfhack/DFTileTypes.h +++ b/library/include/dfhack/DFTileTypes.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef TILETYPES_H_INCLUDED #define TILETYPES_H_INCLUDED diff --git a/library/include/dfhack/DFTypes.h b/library/include/dfhack/DFTypes.h index d5a72e6e7..3983122f8 100644 --- a/library/include/dfhack/DFTypes.h +++ b/library/include/dfhack/DFTypes.h @@ -22,14 +22,18 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef TYPES_H_INCLUDED #define TYPES_H_INCLUDED #include "DFPragma.h" #include "DFExport.h" +#ifdef __cplusplus namespace DFHack { +#endif struct t_matglossPair { @@ -44,7 +48,7 @@ struct junk_fill { uint8_t data[SIZE]; }; - + enum EFFECT_TYPE { EFF_MIASMA=0, @@ -205,6 +209,7 @@ struct t_attrib uint32_t field_18; }; +#ifdef __cplusplus struct t_level { uint32_t level; @@ -213,4 +218,6 @@ struct t_level }; }// namespace DFHack +#endif + #endif // TYPES_H_INCLUDED diff --git a/library/include/dfhack/DFVector.h b/library/include/dfhack/DFVector.h index d6c04eb5d..cbe32d8c9 100644 --- a/library/include/dfhack/DFVector.h +++ b/library/include/dfhack/DFVector.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef DFVECTOR_H_INCLUDED #define DFVECTOR_H_INCLUDED diff --git a/library/include/dfhack/VersionInfo.h b/library/include/dfhack/VersionInfo.h index 414be9b2c..9b9184b0d 100644 --- a/library/include/dfhack/VersionInfo.h +++ b/library/include/dfhack/VersionInfo.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef MEMINFO_H_INCLUDED #define MEMINFO_H_INCLUDED diff --git a/library/include/dfhack/VersionInfoFactory.h b/library/include/dfhack/VersionInfoFactory.h index 76fe7ad21..e424fc7bc 100644 --- a/library/include/dfhack/VersionInfoFactory.h +++ b/library/include/dfhack/VersionInfoFactory.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef MEMINFO_MANAGER_H_INCLUDED #define MEMINFO_MANAGER_H_INCLUDED diff --git a/library/include/dfhack/extra/MapExtras.h b/library/include/dfhack/extra/MapExtras.h index a03558707..60dee4881 100644 --- a/library/include/dfhack/extra/MapExtras.h +++ b/library/include/dfhack/extra/MapExtras.h @@ -1,3 +1,4 @@ +#pragma once #ifndef MAPEXTRAS_H #define MAPEXTRAS_H diff --git a/library/include/dfhack/modules/Buildings.h b/library/include/dfhack/modules/Buildings.h index a92cd02de..f30e8b495 100644 --- a/library/include/dfhack/modules/Buildings.h +++ b/library/include/dfhack/modules/Buildings.h @@ -1,17 +1,17 @@ +#pragma once #ifndef CL_MOD_BUILDINGS #define CL_MOD_BUILDINGS -/* -* Buildings - also includes zones and stockpiles -*/ -#include "dfhack/DFExport.h" -#include "dfhack/DFModule.h" /** - * \defgroup grp_buildings Building module parts + * \defgroup grp_buildings Building module parts - also includes zones and stockpiles * @ingroup grp_modules */ +#include "dfhack/DFExport.h" +#include "dfhack/DFModule.h" +#ifdef __cplusplus namespace DFHack { +#endif /** * Structure for holding a read DF building object * \ingroup grp_buildings @@ -20,21 +20,17 @@ namespace DFHack { uint32_t origin; uint32_t vtable; - uint32_t x1; uint32_t y1; - uint32_t x2; uint32_t y2; - uint32_t z; - t_matglossPair material; - uint32_t type; // FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed) }; - + +#ifdef __cplusplus class DFContextShared; /** * The Buildings module - allows reading DF buildings @@ -50,15 +46,17 @@ namespace DFHack // read one building at offset bool Read (const uint32_t index, t_building & building); bool Finish(); - + // read a vector of names bool ReadCustomWorkshopTypes(std::map & btypes); // returns -1 on error, >= 0 for real value int32_t GetCustomWorkshopType(t_building & building); - + private: struct Private; Private *d; }; } +#endif // __cplusplus + #endif diff --git a/library/include/dfhack/modules/Constructions.h b/library/include/dfhack/modules/Constructions.h index a6b07e79d..0b5c61691 100644 --- a/library/include/dfhack/modules/Constructions.h +++ b/library/include/dfhack/modules/Constructions.h @@ -1,3 +1,4 @@ +#pragma once #ifndef CL_MOD_CONSTRUCTIONS #define CL_MOD_CONSTRUCTIONS /* diff --git a/library/include/dfhack/modules/Creatures.h b/library/include/dfhack/modules/Creatures.h index 4f1ee296f..1585692ba 100644 --- a/library/include/dfhack/modules/Creatures.h +++ b/library/include/dfhack/modules/Creatures.h @@ -1,3 +1,4 @@ +#pragma once #ifndef CL_MOD_CREATURES #define CL_MOD_CREATURES /* diff --git a/library/include/dfhack/modules/Engravings.h b/library/include/dfhack/modules/Engravings.h index 98ad4e099..82aee38c7 100644 --- a/library/include/dfhack/modules/Engravings.h +++ b/library/include/dfhack/modules/Engravings.h @@ -1,3 +1,4 @@ +#pragma once #ifndef CL_MOD_ENGRAVINGS #define CL_MOD_ENGRAVINGS /* diff --git a/library/include/dfhack/modules/Gui.h b/library/include/dfhack/modules/Gui.h index 6f709a980..2865f5413 100644 --- a/library/include/dfhack/modules/Gui.h +++ b/library/include/dfhack/modules/Gui.h @@ -1,3 +1,4 @@ +#pragma once #ifndef CL_MOD_GUI #define CL_MOD_GUI diff --git a/library/include/dfhack/modules/Items.h b/library/include/dfhack/modules/Items.h index 8940b6c95..11e59f77f 100644 --- a/library/include/dfhack/modules/Items.h +++ b/library/include/dfhack/modules/Items.h @@ -1,3 +1,4 @@ +#pragma once #ifndef CL_MOD_ITEMS #define CL_MOD_ITEMS diff --git a/library/include/dfhack/modules/Maps.h b/library/include/dfhack/modules/Maps.h index 0a3852bbf..acda66473 100644 --- a/library/include/dfhack/modules/Maps.h +++ b/library/include/dfhack/modules/Maps.h @@ -2,6 +2,7 @@ M A P S Read and write DF's map *******************************************************************************/ +#pragma once #ifndef CL_MOD_MAPS #define CL_MOD_MAPS diff --git a/library/include/dfhack/modules/Materials.h b/library/include/dfhack/modules/Materials.h index f21446cc7..07e8c40f4 100644 --- a/library/include/dfhack/modules/Materials.h +++ b/library/include/dfhack/modules/Materials.h @@ -1,3 +1,4 @@ +#pragma once #ifndef CL_MOD_MATERIALS #define CL_MOD_MATERIALS /** diff --git a/library/include/dfhack/modules/Translation.h b/library/include/dfhack/modules/Translation.h index 8e253fae4..4c4ee0194 100644 --- a/library/include/dfhack/modules/Translation.h +++ b/library/include/dfhack/modules/Translation.h @@ -1,3 +1,4 @@ +#pragma once #ifndef CL_MOD_TRANSLATION #define CL_MOD_TRANSLATION /** diff --git a/library/include/dfhack/modules/Vegetation.h b/library/include/dfhack/modules/Vegetation.h index 50a5747fd..77285bde4 100644 --- a/library/include/dfhack/modules/Vegetation.h +++ b/library/include/dfhack/modules/Vegetation.h @@ -1,3 +1,4 @@ +#pragma once #ifndef CL_MOD_VEGETATION #define CL_MOD_VEGETATION /** @@ -26,10 +27,6 @@ namespace DFHack uint16_t x; // +0x70 uint16_t y; // +0x72 uint16_t z; // +0x74 - /* - junk_fill<0xA> junk; - uint32_t flags; // +0x80 maybe? - */ uint32_t address; }; diff --git a/library/include/dfhack/modules/WindowIO.h b/library/include/dfhack/modules/WindowIO.h index 4e05e6e9b..f0fda8b98 100644 --- a/library/include/dfhack/modules/WindowIO.h +++ b/library/include/dfhack/modules/WindowIO.h @@ -21,7 +21,7 @@ must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ - +#pragma once #ifndef KEYS_H_INCLUDED #define KEYS_H_INCLUDED diff --git a/library/include/dfhack/modules/World.h b/library/include/dfhack/modules/World.h index 33514aeea..3ba0babd0 100644 --- a/library/include/dfhack/modules/World.h +++ b/library/include/dfhack/modules/World.h @@ -1,3 +1,4 @@ +#pragma once #ifndef CL_MOD_WORLD #define CL_MOD_WORLD diff --git a/library/modules/Buildings_C.cpp b/library/modules/Buildings_C.cpp index b22eb8565..bf7b0a306 100644 --- a/library/modules/Buildings_C.cpp +++ b/library/modules/Buildings_C.cpp @@ -22,8 +22,11 @@ must not be misrepresented as being the original software. distribution. */ -#include "dfhack-c/modules/Buildings_C.h" +#include +#include +#include using namespace std; +#include "dfhack-c/modules/Buildings_C.h" #ifdef __cplusplus extern "C" { @@ -31,42 +34,38 @@ extern "C" { int Buildings_Start(DFHackObject* b_Ptr, uint32_t* numBuildings) { - if(b_Ptr != NULL) - { - return ((DFHack::Buildings*)b_Ptr)->Start(*numBuildings); - } - - return -1; + 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; + 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; + 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; + if(b_Ptr != NULL) + { + return ((DFHack::Buildings*)b_Ptr)->GetCustomWorkshopType(*building); + } + return -1; } t_customWorkshop* Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr) @@ -80,19 +79,18 @@ t_customWorkshop* Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr) if(!((DFHack::Buildings*)b_Ptr)->ReadCustomWorkshopTypes(bTypes)) return NULL; - - (*alloc_customWorkshop_buffer_callback)(&cw_Ptr, bTypes.size()); - - if(cw_Ptr == NULL) - return NULL; - + + (*alloc_customWorkshop_buffer_callback)(&cw_Ptr, bTypes.size()); + + if(cw_Ptr == NULL) + return NULL; + 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 cw_Ptr; } diff --git a/library/modules/Constructions_C.cpp b/library/modules/Constructions_C.cpp index 03e89ca23..a77ba7fc7 100644 --- a/library/modules/Constructions_C.cpp +++ b/library/modules/Constructions_C.cpp @@ -21,7 +21,10 @@ must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ - +#include +#include +#include +using namespace std; #include "dfhack-c/modules/Constructions_C.h" #ifdef __cplusplus diff --git a/library/modules/Creatures_C.cpp b/library/modules/Creatures_C.cpp index e0605d25c..719377e9d 100644 --- a/library/modules/Creatures_C.cpp +++ b/library/modules/Creatures_C.cpp @@ -21,14 +21,14 @@ 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/modules/Creatures_C.h" - +#include +#include #include #include - using namespace std; +#include "dfhack-c/modules/Creatures_C.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/library/modules/Gui_C.cpp b/library/modules/Gui_C.cpp index 8c6ed777b..a6739b8b8 100644 --- a/library/modules/Gui_C.cpp +++ b/library/modules/Gui_C.cpp @@ -22,6 +22,11 @@ must not be misrepresented as being the original software. distribution. */ +#include +#include +#include +using namespace std; + #include "dfhack-c/modules/Gui_C.h" #include "dfhack-c/DFTypes_C.h" #ifdef __cplusplus diff --git a/library/modules/Items_C.cpp b/library/modules/Items_C.cpp index 7b366aece..05ead2929 100644 --- a/library/modules/Items_C.cpp +++ b/library/modules/Items_C.cpp @@ -21,6 +21,10 @@ must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ +#include +#include +#include +using namespace std; #include "dfhack-c/modules/Items_C.h" diff --git a/library/modules/Materials_C.cpp b/library/modules/Materials_C.cpp index 20642888f..5e95f715b 100644 --- a/library/modules/Materials_C.cpp +++ b/library/modules/Materials_C.cpp @@ -21,13 +21,168 @@ must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ - +#include +#include +#include +#include +#include +using namespace std; #include "dfhack-c/modules/Materials_C.h" #ifdef __cplusplus extern "C" { #endif +void BuildDescriptorList(std::vector & src, c_creaturetype_descriptor** dest) +{ + c_creaturetype_descriptor* descriptor = NULL; + + descriptor = (c_creaturetype_descriptor*)calloc(src.size(), sizeof(c_creaturetype_descriptor)); + + for(uint32_t i = 0; i < src.size(); i++) + { + uint32_t castes_size = src[i].castes.size(); + c_creaturetype_descriptor* current = &descriptor[i]; + + current->castesCount = castes_size; + current->caste_descriptors = (c_creaturecaste_descriptor*)calloc(castes_size, sizeof(c_creaturecaste_descriptor)); + + for(uint32_t j = 0; j < castes_size; j++) + { + uint32_t color_size = src[i].castes[j].ColorModifier.size(); + c_creaturecaste_descriptor* current_caste = ¤t->caste_descriptors[j]; + + current_caste->colorModifierLength = color_size; + current_caste->color_descriptors = (c_colormodifier_descriptor*)calloc(color_size, sizeof(c_colormodifier_descriptor)); + + for(uint32_t k = 0; k < color_size; k++) + { + c_colormodifier_descriptor* current_color = ¤t_caste->color_descriptors[k]; + + current_color->colorlistLength = src[i].castes[j].ColorModifier[k].colorlist.size(); + } + + current_caste->bodypartLength = src[i].castes[j].bodypart.size(); + } + + current->extractCount = src[i].extract.size(); + } + + *dest = descriptor; +} + +void FreeDescriptorList(c_creaturetype_descriptor* d, uint32_t length) +{ + for(uint32_t i = 0; i < length; i++) + { + c_creaturetype_descriptor* desc = &d[i]; + + for(uint32_t j = 0; j < desc->castesCount; j++) + free(desc->caste_descriptors[j].color_descriptors); + + free(desc->caste_descriptors); + } + + free(d); +} + +int CreatureTypeConvert(std::vector & src, c_creaturetype** out_buf) +{ + if(src.size() <= 0) + return 0; + else if(alloc_creaturetype_buffer_callback == NULL) + return -1; + else + { + c_creaturetype_descriptor* descriptor; + c_creaturetype* buf; + + BuildDescriptorList(src, &descriptor); + + ((*alloc_creaturetype_buffer_callback)(out_buf, descriptor, src.size())); + + FreeDescriptorList(descriptor, src.size()); + + if(out_buf == NULL) + return -1; + + buf = out_buf[0]; + + for(uint32_t i = 0; i < src.size(); i++) + { + c_creaturetype* current = &(buf[i]); + + memset(current->rawname, '\0', 128); + strncpy(current->rawname, src[i].rawname, 128); + + for(uint32_t j = 0; j < current->castesCount; j++) + { + c_creaturecaste* current_caste = ¤t->castes[j]; + t_creaturecaste* src_caste = &src[i].castes[j]; + + memset(current_caste->rawname, '\0', 128); + memset(current_caste->singular, '\0', 128); + memset(current_caste->plural, '\0', 128); + memset(current_caste->adjective, '\0', 128); + + strncpy(current_caste->rawname, src_caste->rawname, 128); + strncpy(current_caste->singular, src_caste->singular, 128); + strncpy(current_caste->plural, src_caste->plural, 128); + strncpy(current_caste->adjective, src_caste->adjective, 128); + + for(uint32_t k = 0; k < src[i].castes[j].ColorModifier.size(); k++) + { + c_colormodifier* current_color = ¤t_caste->colorModifier[k]; + + memset(current_color->part, '\0', 128); + strncpy(current_color->part, src_caste->ColorModifier[k].part, 128); + + copy(src_caste->ColorModifier[k].colorlist.begin(), src_caste->ColorModifier[k].colorlist.end(), current_color->colorlist); + current_color->colorlistLength = src_caste->ColorModifier[k].colorlist.size(); + + current_color->startdate = src_caste->ColorModifier[k].startdate; + current_color->enddate = src_caste->ColorModifier[k].enddate; + } + + current_caste->colorModifierLength = src_caste->ColorModifier.size(); + + copy(src_caste->bodypart.begin(), src_caste->bodypart.end(), current_caste->bodypart); + current_caste->bodypartLength = src_caste->bodypart.size(); + + current_caste->strength = src_caste->strength; + current_caste->agility = src_caste->agility; + current_caste->toughness = src_caste->toughness; + current_caste->endurance = src_caste->endurance; + current_caste->recuperation = src_caste->recuperation; + current_caste->disease_resistance = src_caste->disease_resistance; + current_caste->analytical_ability = src_caste->analytical_ability; + current_caste->focus = src_caste->focus; + current_caste->willpower = src_caste->willpower; + current_caste->creativity = src_caste->creativity; + current_caste->intuition = src_caste->intuition; + current_caste->patience = src_caste->patience; + current_caste->memory = src_caste->memory; + current_caste->linguistic_ability = src_caste->linguistic_ability; + current_caste->spatial_sense = src_caste->spatial_sense; + current_caste->musicality = src_caste->musicality; + current_caste->kinesthetic_sense = src_caste->kinesthetic_sense; + } + + copy(src[i].extract.begin(), src[i].extract.end(), current->extract); + current->extractCount = src[i].extract.size(); + + current->tile_character = src[i].tile_character; + + current->tilecolor.fore = src[i].tilecolor.fore; + current->tilecolor.back = src[i].tilecolor.back; + current->tilecolor.bright = src[i].tilecolor.bright; + } + + return 1; + } +} + + int Materials_ReadInorganicMaterials(DFHackObject* mat) { if(mat != NULL) diff --git a/library/modules/Translation_C.cpp b/library/modules/Translation_C.cpp index b11acd586..23b07b24c 100644 --- a/library/modules/Translation_C.cpp +++ b/library/modules/Translation_C.cpp @@ -26,6 +26,7 @@ distribution. #include #include +#include using namespace std; diff --git a/library/modules/WindowIO_C.cpp b/library/modules/WindowIO_C.cpp index c265a4190..51dd92eab 100644 --- a/library/modules/WindowIO_C.cpp +++ b/library/modules/WindowIO_C.cpp @@ -27,8 +27,8 @@ distribution. #include using namespace std; +#include "dfhack-c/Common.h" #include "dfhack/DFIntegers.h" -#include "DFHack_C.h" #include "dfhack/modules/WindowIO.h" #include "dfhack-c/modules/WindowIO_C.h" diff --git a/library/modules/World_C.cpp b/library/modules/World_C.cpp index dc14c9019..37e034ccd 100644 --- a/library/modules/World_C.cpp +++ b/library/modules/World_C.cpp @@ -22,7 +22,10 @@ must not be misrepresented as being the original software. distribution. */ -#include "DFHack_C.h" +#include +#include +using namespace std; +#include "dfhack-c/Common.h" #include "dfhack/modules/World.h" #include "dfhack-c/modules/World_C.h" #include "dfhack-c/DFTypes_C.h" diff --git a/library/private/ContextShared.h b/library/private/ContextShared.h index e9485e013..727bb8a0e 100644 --- a/library/private/ContextShared.h +++ b/library/private/ContextShared.h @@ -22,9 +22,7 @@ must not be misrepresented as being the original software. distribution. */ -/* -* WARNING: Only include from API modules -*/ +#pragma once #ifndef APIPRIVATE_H_INCLUDED #define APIPRIVATE_H_INCLUDED diff --git a/library/private/Internal.h b/library/private/Internal.h index 4d7380cc1..4c1d714a4 100644 --- a/library/private/Internal.h +++ b/library/private/Internal.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef DFCOMMONINTERNAL_H_INCLUDED #define DFCOMMONINTERNAL_H_INCLUDED @@ -39,9 +41,6 @@ distribution. #define _FILE_OFFSET_BITS 64 #endif -// one file for globals -#include "dfhack/DFGlobal.h" - // one file for telling the MSVC compiler where it can shove its pointless warnings #include "dfhack/DFPragma.h" diff --git a/library/private/LinuxProcess.h b/library/private/LinuxProcess.h index 6ece1c69c..4b35006ba 100644 --- a/library/private/LinuxProcess.h +++ b/library/private/LinuxProcess.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef LINUX_PROCESS_H_INCLUDED #define LINUX_PROCESS_H_INCLUDED diff --git a/library/private/MicrosoftSTL.h b/library/private/MicrosoftSTL.h index a25ee1797..7ff2ddce2 100644 --- a/library/private/MicrosoftSTL.h +++ b/library/private/MicrosoftSTL.h @@ -22,7 +22,7 @@ must not be misrepresented as being the original software. distribution. */ -#include +#pragma once namespace DFHack { class Process; diff --git a/library/private/ModuleFactory.h b/library/private/ModuleFactory.h index 309a4d86a..40a122a24 100644 --- a/library/private/ModuleFactory.h +++ b/library/private/ModuleFactory.h @@ -22,6 +22,8 @@ distribution. */ +#pragma once + #ifndef MODULE_FACTORY_H_INCLUDED #define MODULE_FACTORY_H_INCLUDED diff --git a/library/private/PlatformInternal.h b/library/private/PlatformInternal.h index ab7eab6c4..f33b53e5e 100644 --- a/library/private/PlatformInternal.h +++ b/library/private/PlatformInternal.h @@ -22,6 +22,8 @@ * distribution. */ +#pragma once + #ifndef DFPLATFORMINTERNAL_H_INCLUDED #define DFPLATFORMINTERNAL_H_INCLUDED diff --git a/library/private/SHMProcess.h b/library/private/SHMProcess.h index 28b5c6e80..b4e005ec3 100644 --- a/library/private/SHMProcess.h +++ b/library/private/SHMProcess.h @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#pragma once + #ifndef SHM_PROCESS_H_INCLUDED #define SHM_PROCESS_H_INCLUDED diff --git a/tools/playground/dftry.cpp b/tools/playground/dftry.cpp index 98ae5a288..c6b159926 100644 --- a/tools/playground/dftry.cpp +++ b/tools/playground/dftry.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include using namespace std; diff --git a/tools/supported/deramp.cpp b/tools/supported/deramp.cpp index 659fd05f7..1f92717f4 100644 --- a/tools/supported/deramp.cpp +++ b/tools/supported/deramp.cpp @@ -23,7 +23,6 @@ int main (void) //DFHack::TileRow *ptile; int32_t oldT, newT; - int16_t t; bool dirty= false; int count=0;