Started removing C++-isms from C wrapper. Removed DFGlobal.h

develop
Petr Mrázek 2011-04-10 13:12:28 +02:00
parent c1deee768e
commit 1d35044db3
67 changed files with 359 additions and 258 deletions

@ -25,6 +25,7 @@ distribution.
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <string> #include <string>
#include <map>
#include <cstring> #include <cstring>
using namespace std; using namespace std;

@ -28,6 +28,7 @@ distribution.
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
#include <algorithm> #include <algorithm>
using namespace std; using namespace std;
@ -169,153 +170,4 @@ UNREG_MACRO(FeatureMap, alloc_featuremap_buffer_callback)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
void BuildDescriptorList(std::vector<t_creaturetype> & 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 = &current->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 = &current_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<t_creaturetype> & 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 = &current->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 = &current_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;
}
}

@ -7,6 +7,8 @@
* \defgroup grp_cwrap C Wrapper * \defgroup grp_cwrap C Wrapper
*/ */
#pragma once
// Defines // Defines
#ifdef __GNUC__ #ifdef __GNUC__
#define DEPRECATED(func) func __attribute__ ((deprecated)) #define DEPRECATED(func) func __attribute__ ((deprecated))

@ -22,24 +22,18 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef DFHACK_C_API #ifndef DFHACK_C_API
#define DFHACK_C_API #define DFHACK_C_API
#include "dfhack/DFPragma.h" #include "dfhack/DFPragma.h"
#include <cstdio> namespace DFHack {};
#include <string> using namespace DFHack;
#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"
using namespace DFHack;
typedef void DFHackObject; typedef void DFHackObject;
#ifdef __cplusplus #ifdef __cplusplus

@ -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

@ -25,7 +25,7 @@ distribution.
#ifndef DFHACK_C_CONTEXT #ifndef DFHACK_C_CONTEXT
#define DFHACK_C_CONTEXT #define DFHACK_C_CONTEXT
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -25,7 +25,7 @@ distribution.
#ifndef PROCESS_C_API #ifndef PROCESS_C_API
#define PROCESS_C_API #define PROCESS_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#ifdef __cplusplus #ifdef __cplusplus

@ -25,7 +25,7 @@ distribution.
#ifndef TILETYPES_C_API #ifndef TILETYPES_C_API
#define TILETYPES_C_API #define TILETYPES_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack/DFTileTypes.h" #include "dfhack/DFTileTypes.h"
#ifdef __cplusplus #ifdef __cplusplus

@ -25,13 +25,12 @@ distribution.
#ifndef TYPES_C_API #ifndef TYPES_C_API
#define TYPES_C_API #define TYPES_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "DFProcess_C.h" #include "DFProcess_C.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Maps.h" #include "dfhack/modules/Maps.h"
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "dfhack/modules/Gui.h" #include "dfhack/modules/Gui.h"
//#include "dfhack/DFTileTypes.h"
#define HBUILD(a) a ## BufferCallback #define HBUILD(a) a ## BufferCallback
#define HREG_MACRO(type_name, type) DFHACK_EXPORT void HBUILD(Register ## type_name) (int (*funcptr)(type, uint32_t)); #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 #ifdef __cplusplus
} }
#endif #endif
/*
void BuildDescriptorList(std::vector<t_creaturetype> & src, c_creaturetype_descriptor** dest); void BuildDescriptorList(std::vector<t_creaturetype> & src, c_creaturetype_descriptor** dest);
void FreeDescriptorList(c_creaturetype_descriptor* d, uint32_t length); void FreeDescriptorList(c_creaturetype_descriptor* d, uint32_t length);
int CreatureTypeConvert(std::vector<t_creaturetype> &, c_creaturetype**); int CreatureTypeConvert(std::vector<t_creaturetype> &, c_creaturetype**);
*/
#endif #endif

@ -25,7 +25,7 @@ distribution.
#ifndef BUILDINGS_C_API #ifndef BUILDINGS_C_API
#define BUILDINGS_C_API #define BUILDINGS_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Buildings.h" #include "dfhack/modules/Buildings.h"
#include "dfhack-c/DFTypes_C.h" #include "dfhack-c/DFTypes_C.h"

@ -25,7 +25,7 @@ distribution.
#ifndef CONSTRUCTIONS_C_API #ifndef CONSTRUCTIONS_C_API
#define CONSTRUCTIONS_C_API #define CONSTRUCTIONS_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Constructions.h" #include "dfhack/modules/Constructions.h"

@ -25,7 +25,7 @@ distribution.
#ifndef CREATURES_C_API #ifndef CREATURES_C_API
#define CREATURES_C_API #define CREATURES_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack-c/DFTypes_C.h" #include "dfhack-c/DFTypes_C.h"
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"

@ -25,7 +25,7 @@ distribution.
#ifndef GUI_C_API #ifndef GUI_C_API
#define GUI_C_API #define GUI_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Gui.h" #include "dfhack/modules/Gui.h"

@ -25,7 +25,7 @@ distribution.
#ifndef ITEMS_C_API #ifndef ITEMS_C_API
#define ITEMS_C_API #define ITEMS_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack-c/DFTypes_C.h" #include "dfhack-c/DFTypes_C.h"
#include "dfhack/modules/Items.h" #include "dfhack/modules/Items.h"

@ -25,7 +25,7 @@ distribution.
#ifndef MAPS_C_API #ifndef MAPS_C_API
#define MAPS_C_API #define MAPS_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Maps.h" #include "dfhack/modules/Maps.h"

@ -25,7 +25,7 @@ distribution.
#ifndef MATERIALS_C_API #ifndef MATERIALS_C_API
#define MATERIALS_C_API #define MATERIALS_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack-c/DFTypes_C.h" #include "dfhack-c/DFTypes_C.h"
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"

@ -25,7 +25,7 @@ distribution.
#ifndef TRANSLATION_C_API #ifndef TRANSLATION_C_API
#define TRANSLATION_C_API #define TRANSLATION_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack-c/DFTypes_C.h" #include "dfhack-c/DFTypes_C.h"
#include "dfhack/modules/Translation.h" #include "dfhack/modules/Translation.h"

@ -25,7 +25,7 @@ distribution.
#ifndef VEGETATION_C_API #ifndef VEGETATION_C_API
#define VEGETATION_C_API #define VEGETATION_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Vegetation.h" #include "dfhack/modules/Vegetation.h"

@ -25,7 +25,7 @@ distribution.
#ifndef WINDOWIO_C_API #ifndef WINDOWIO_C_API
#define WINDOWIO_C_API #define WINDOWIO_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack/modules/WindowIO.h" #include "dfhack/modules/WindowIO.h"
#ifdef __cplusplus #ifdef __cplusplus

@ -25,7 +25,7 @@ distribution.
#ifndef WORLD_C_API #ifndef WORLD_C_API
#define WORLD_C_API #define WORLD_C_API
#include "DFHack_C.h" #include "dfhack-c/Common.h"
#include "dfhack/modules/World.h" #include "dfhack/modules/World.h"
#ifdef __cplusplus #ifdef __cplusplus

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef CONTEXT_H_INCLUDED #ifndef CONTEXT_H_INCLUDED
#define CONTEXT_H_INCLUDED #define CONTEXT_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef CONTEXTMANAGER_H_INCLUDED #ifndef CONTEXTMANAGER_H_INCLUDED
#define CONTEXTMANAGER_H_INCLUDED #define CONTEXTMANAGER_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef ERROR_H_INCLUDED #ifndef ERROR_H_INCLUDED
#define ERROR_H_INCLUDED #define ERROR_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifdef LINUX_BUILD #ifdef LINUX_BUILD
#ifndef DFHACK_EXPORT #ifndef DFHACK_EXPORT
#define DFHACK_EXPORT __attribute__ ((visibility("default"))) #define DFHACK_EXPORT __attribute__ ((visibility("default")))

@ -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

@ -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 You can turn off the include by defining SKIP_DFHACK_STDINT
*/ */
#pragma once
#ifndef SKIP_DFHACK_STDINT #ifndef SKIP_DFHACK_STDINT
#ifndef _MSC_VER #ifndef _MSC_VER
#include <stdint.h> #include <stdint.h>

@ -1,3 +1,5 @@
#pragma once
#ifndef DF_MISCUTILS #ifndef DF_MISCUTILS
#define DF_MISCUTILS #define DF_MISCUTILS
#include <iostream> #include <iostream>

@ -1,4 +1,3 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf 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. distribution.
*/ */
#pragma once
#ifndef MODULE_H_INCLUDED #ifndef MODULE_H_INCLUDED
#define MODULE_H_INCLUDED #define MODULE_H_INCLUDED

@ -1,3 +1,5 @@
#pragma once
#ifndef DFHACK_TRANQUILITY #ifndef DFHACK_TRANQUILITY
#define DFHACK_TRANQUILITY #define DFHACK_TRANQUILITY

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef PROCESS_H_INCLUDED #ifndef PROCESS_H_INCLUDED
#define PROCESS_H_INCLUDED #define PROCESS_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef PROCESSMANAGER_H_INCLUDED #ifndef PROCESSMANAGER_H_INCLUDED
#define PROCESSMANAGER_H_INCLUDED #define PROCESSMANAGER_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef TILETYPES_H_INCLUDED #ifndef TILETYPES_H_INCLUDED
#define TILETYPES_H_INCLUDED #define TILETYPES_H_INCLUDED

@ -22,14 +22,18 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef TYPES_H_INCLUDED #ifndef TYPES_H_INCLUDED
#define TYPES_H_INCLUDED #define TYPES_H_INCLUDED
#include "DFPragma.h" #include "DFPragma.h"
#include "DFExport.h" #include "DFExport.h"
#ifdef __cplusplus
namespace DFHack namespace DFHack
{ {
#endif
struct t_matglossPair struct t_matglossPair
{ {
@ -44,7 +48,7 @@ struct junk_fill
{ {
uint8_t data[SIZE]; uint8_t data[SIZE];
}; };
enum EFFECT_TYPE enum EFFECT_TYPE
{ {
EFF_MIASMA=0, EFF_MIASMA=0,
@ -205,6 +209,7 @@ struct t_attrib
uint32_t field_18; uint32_t field_18;
}; };
#ifdef __cplusplus
struct t_level struct t_level
{ {
uint32_t level; uint32_t level;
@ -213,4 +218,6 @@ struct t_level
}; };
}// namespace DFHack }// namespace DFHack
#endif
#endif // TYPES_H_INCLUDED #endif // TYPES_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef DFVECTOR_H_INCLUDED #ifndef DFVECTOR_H_INCLUDED
#define DFVECTOR_H_INCLUDED #define DFVECTOR_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef MEMINFO_H_INCLUDED #ifndef MEMINFO_H_INCLUDED
#define MEMINFO_H_INCLUDED #define MEMINFO_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef MEMINFO_MANAGER_H_INCLUDED #ifndef MEMINFO_MANAGER_H_INCLUDED
#define MEMINFO_MANAGER_H_INCLUDED #define MEMINFO_MANAGER_H_INCLUDED

@ -1,3 +1,4 @@
#pragma once
#ifndef MAPEXTRAS_H #ifndef MAPEXTRAS_H
#define MAPEXTRAS_H #define MAPEXTRAS_H

@ -1,17 +1,17 @@
#pragma once
#ifndef CL_MOD_BUILDINGS #ifndef CL_MOD_BUILDINGS
#define 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 * @ingroup grp_modules
*/ */
#include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
#ifdef __cplusplus
namespace DFHack namespace DFHack
{ {
#endif
/** /**
* Structure for holding a read DF building object * Structure for holding a read DF building object
* \ingroup grp_buildings * \ingroup grp_buildings
@ -20,21 +20,17 @@ namespace DFHack
{ {
uint32_t origin; uint32_t origin;
uint32_t vtable; uint32_t vtable;
uint32_t x1; uint32_t x1;
uint32_t y1; uint32_t y1;
uint32_t x2; uint32_t x2;
uint32_t y2; uint32_t y2;
uint32_t z; uint32_t z;
t_matglossPair material; t_matglossPair material;
uint32_t type; 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) // 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; class DFContextShared;
/** /**
* The Buildings module - allows reading DF buildings * The Buildings module - allows reading DF buildings
@ -50,15 +46,17 @@ namespace DFHack
// read one building at offset // read one building at offset
bool Read (const uint32_t index, t_building & building); bool Read (const uint32_t index, t_building & building);
bool Finish(); bool Finish();
// read a vector of names // read a vector of names
bool ReadCustomWorkshopTypes(std::map <uint32_t, std::string> & btypes); bool ReadCustomWorkshopTypes(std::map <uint32_t, std::string> & btypes);
// returns -1 on error, >= 0 for real value // returns -1 on error, >= 0 for real value
int32_t GetCustomWorkshopType(t_building & building); int32_t GetCustomWorkshopType(t_building & building);
private: private:
struct Private; struct Private;
Private *d; Private *d;
}; };
} }
#endif // __cplusplus
#endif #endif

@ -1,3 +1,4 @@
#pragma once
#ifndef CL_MOD_CONSTRUCTIONS #ifndef CL_MOD_CONSTRUCTIONS
#define CL_MOD_CONSTRUCTIONS #define CL_MOD_CONSTRUCTIONS
/* /*

@ -1,3 +1,4 @@
#pragma once
#ifndef CL_MOD_CREATURES #ifndef CL_MOD_CREATURES
#define CL_MOD_CREATURES #define CL_MOD_CREATURES
/* /*

@ -1,3 +1,4 @@
#pragma once
#ifndef CL_MOD_ENGRAVINGS #ifndef CL_MOD_ENGRAVINGS
#define CL_MOD_ENGRAVINGS #define CL_MOD_ENGRAVINGS
/* /*

@ -1,3 +1,4 @@
#pragma once
#ifndef CL_MOD_GUI #ifndef CL_MOD_GUI
#define CL_MOD_GUI #define CL_MOD_GUI

@ -1,3 +1,4 @@
#pragma once
#ifndef CL_MOD_ITEMS #ifndef CL_MOD_ITEMS
#define CL_MOD_ITEMS #define CL_MOD_ITEMS

@ -2,6 +2,7 @@
M A P S M A P S
Read and write DF's map Read and write DF's map
*******************************************************************************/ *******************************************************************************/
#pragma once
#ifndef CL_MOD_MAPS #ifndef CL_MOD_MAPS
#define CL_MOD_MAPS #define CL_MOD_MAPS

@ -1,3 +1,4 @@
#pragma once
#ifndef CL_MOD_MATERIALS #ifndef CL_MOD_MATERIALS
#define CL_MOD_MATERIALS #define CL_MOD_MATERIALS
/** /**

@ -1,3 +1,4 @@
#pragma once
#ifndef CL_MOD_TRANSLATION #ifndef CL_MOD_TRANSLATION
#define CL_MOD_TRANSLATION #define CL_MOD_TRANSLATION
/** /**

@ -1,3 +1,4 @@
#pragma once
#ifndef CL_MOD_VEGETATION #ifndef CL_MOD_VEGETATION
#define CL_MOD_VEGETATION #define CL_MOD_VEGETATION
/** /**
@ -26,10 +27,6 @@ namespace DFHack
uint16_t x; // +0x70 uint16_t x; // +0x70
uint16_t y; // +0x72 uint16_t y; // +0x72
uint16_t z; // +0x74 uint16_t z; // +0x74
/*
junk_fill<0xA> junk;
uint32_t flags; // +0x80 maybe?
*/
uint32_t address; uint32_t address;
}; };

@ -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 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#pragma once
#ifndef KEYS_H_INCLUDED #ifndef KEYS_H_INCLUDED
#define KEYS_H_INCLUDED #define KEYS_H_INCLUDED

@ -1,3 +1,4 @@
#pragma once
#ifndef CL_MOD_WORLD #ifndef CL_MOD_WORLD
#define CL_MOD_WORLD #define CL_MOD_WORLD

@ -22,8 +22,11 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "dfhack-c/modules/Buildings_C.h" #include <string>
#include <map>
#include <vector>
using namespace std; using namespace std;
#include "dfhack-c/modules/Buildings_C.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -31,42 +34,38 @@ extern "C" {
int Buildings_Start(DFHackObject* b_Ptr, uint32_t* numBuildings) int Buildings_Start(DFHackObject* b_Ptr, uint32_t* numBuildings)
{ {
if(b_Ptr != NULL) if(b_Ptr != NULL)
{ {
return ((DFHack::Buildings*)b_Ptr)->Start(*numBuildings); return ((DFHack::Buildings*)b_Ptr)->Start(*numBuildings);
} }
return -1;
return -1;
} }
int Buildings_Finish(DFHackObject* b_Ptr) int Buildings_Finish(DFHackObject* b_Ptr)
{ {
if(b_Ptr != NULL) if(b_Ptr != NULL)
{ {
return ((DFHack::Buildings*)b_Ptr)->Finish(); return ((DFHack::Buildings*)b_Ptr)->Finish();
} }
return -1;
return -1;
} }
int Buildings_Read(DFHackObject* b_Ptr, const uint32_t index, t_building* building) int Buildings_Read(DFHackObject* b_Ptr, const uint32_t index, t_building* building)
{ {
if(b_Ptr != NULL) if(b_Ptr != NULL)
{ {
return ((DFHack::Buildings*)b_Ptr)->Read(index, *building); return ((DFHack::Buildings*)b_Ptr)->Read(index, *building);
} }
return -1;
return -1;
} }
int Buildings_GetCustomWorkshopType(DFHackObject* b_Ptr, t_building* building) int Buildings_GetCustomWorkshopType(DFHackObject* b_Ptr, t_building* building)
{ {
if(b_Ptr != NULL) if(b_Ptr != NULL)
{ {
return ((DFHack::Buildings*)b_Ptr)->GetCustomWorkshopType(*building); return ((DFHack::Buildings*)b_Ptr)->GetCustomWorkshopType(*building);
} }
return -1;
return -1;
} }
t_customWorkshop* Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr) 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)) if(!((DFHack::Buildings*)b_Ptr)->ReadCustomWorkshopTypes(bTypes))
return NULL; return NULL;
(*alloc_customWorkshop_buffer_callback)(&cw_Ptr, bTypes.size()); (*alloc_customWorkshop_buffer_callback)(&cw_Ptr, bTypes.size());
if(cw_Ptr == NULL) if(cw_Ptr == NULL)
return NULL; return NULL;
for(i = 0, bIter = bTypes.begin(); bIter != bTypes.end(); bIter++, i++) for(i = 0, bIter = bTypes.begin(); bIter != bTypes.end(); bIter++, i++)
{ {
cw_Ptr[i].index = (*bIter).first; cw_Ptr[i].index = (*bIter).first;
size_t length = (*bIter).second.copy(cw_Ptr[i].name, 256); size_t length = (*bIter).second.copy(cw_Ptr[i].name, 256);
cw_Ptr[i].name[length] = '\0'; cw_Ptr[i].name[length] = '\0';
} }
return cw_Ptr; return cw_Ptr;
} }

@ -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 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#include <string>
#include <map>
#include <vector>
using namespace std;
#include "dfhack-c/modules/Constructions_C.h" #include "dfhack-c/modules/Constructions_C.h"
#ifdef __cplusplus #ifdef __cplusplus

@ -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 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#include <string>
#include "dfhack-c/modules/Creatures_C.h" #include <map>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
using namespace std; using namespace std;
#include "dfhack-c/modules/Creatures_C.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

@ -22,6 +22,11 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include <string>
#include <map>
#include <vector>
using namespace std;
#include "dfhack-c/modules/Gui_C.h" #include "dfhack-c/modules/Gui_C.h"
#include "dfhack-c/DFTypes_C.h" #include "dfhack-c/DFTypes_C.h"
#ifdef __cplusplus #ifdef __cplusplus

@ -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 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#include <string>
#include <map>
#include <vector>
using namespace std;
#include "dfhack-c/modules/Items_C.h" #include "dfhack-c/modules/Items_C.h"

@ -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 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
#include "dfhack-c/modules/Materials_C.h" #include "dfhack-c/modules/Materials_C.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void BuildDescriptorList(std::vector<t_creaturetype> & 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 = &current->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 = &current_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<t_creaturetype> & 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 = &current->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 = &current_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) int Materials_ReadInorganicMaterials(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)

@ -26,6 +26,7 @@ distribution.
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
using namespace std; using namespace std;

@ -27,8 +27,8 @@ distribution.
#include <string> #include <string>
using namespace std; using namespace std;
#include "dfhack-c/Common.h"
#include "dfhack/DFIntegers.h" #include "dfhack/DFIntegers.h"
#include "DFHack_C.h"
#include "dfhack/modules/WindowIO.h" #include "dfhack/modules/WindowIO.h"
#include "dfhack-c/modules/WindowIO_C.h" #include "dfhack-c/modules/WindowIO_C.h"

@ -22,7 +22,10 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "DFHack_C.h" #include <vector>
#include <map>
using namespace std;
#include "dfhack-c/Common.h"
#include "dfhack/modules/World.h" #include "dfhack/modules/World.h"
#include "dfhack-c/modules/World_C.h" #include "dfhack-c/modules/World_C.h"
#include "dfhack-c/DFTypes_C.h" #include "dfhack-c/DFTypes_C.h"

@ -22,9 +22,7 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
/* #pragma once
* WARNING: Only include from API modules
*/
#ifndef APIPRIVATE_H_INCLUDED #ifndef APIPRIVATE_H_INCLUDED
#define APIPRIVATE_H_INCLUDED #define APIPRIVATE_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef DFCOMMONINTERNAL_H_INCLUDED #ifndef DFCOMMONINTERNAL_H_INCLUDED
#define DFCOMMONINTERNAL_H_INCLUDED #define DFCOMMONINTERNAL_H_INCLUDED
@ -39,9 +41,6 @@ distribution.
#define _FILE_OFFSET_BITS 64 #define _FILE_OFFSET_BITS 64
#endif #endif
// one file for globals
#include "dfhack/DFGlobal.h"
// one file for telling the MSVC compiler where it can shove its pointless warnings // one file for telling the MSVC compiler where it can shove its pointless warnings
#include "dfhack/DFPragma.h" #include "dfhack/DFPragma.h"

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef LINUX_PROCESS_H_INCLUDED #ifndef LINUX_PROCESS_H_INCLUDED
#define LINUX_PROCESS_H_INCLUDED #define LINUX_PROCESS_H_INCLUDED

@ -22,7 +22,7 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include <string> #pragma once
namespace DFHack { namespace DFHack {
class Process; class Process;

@ -22,6 +22,8 @@
distribution. distribution.
*/ */
#pragma once
#ifndef MODULE_FACTORY_H_INCLUDED #ifndef MODULE_FACTORY_H_INCLUDED
#define MODULE_FACTORY_H_INCLUDED #define MODULE_FACTORY_H_INCLUDED

@ -22,6 +22,8 @@
* distribution. * distribution.
*/ */
#pragma once
#ifndef DFPLATFORMINTERNAL_H_INCLUDED #ifndef DFPLATFORMINTERNAL_H_INCLUDED
#define DFPLATFORMINTERNAL_H_INCLUDED #define DFPLATFORMINTERNAL_H_INCLUDED

@ -22,6 +22,8 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#pragma once
#ifndef SHM_PROCESS_H_INCLUDED #ifndef SHM_PROCESS_H_INCLUDED
#define SHM_PROCESS_H_INCLUDED #define SHM_PROCESS_H_INCLUDED

@ -1,6 +1,6 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <strstream> #include <sstream>
#include <DFHack.h> #include <DFHack.h>
using namespace std; using namespace std;

@ -23,7 +23,6 @@ int main (void)
//DFHack::TileRow *ptile; //DFHack::TileRow *ptile;
int32_t oldT, newT; int32_t oldT, newT;
int16_t t;
bool dirty= false; bool dirty= false;
int count=0; int count=0;