first commit
parent
fdd33ad7c2
commit
31bd401a78
@ -0,0 +1,75 @@
|
||||
/*
|
||||
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 MATERIALS_C_API
|
||||
#define MATERIALS_C_API
|
||||
|
||||
#include "Export.h"
|
||||
#include "integers.h"
|
||||
#include "DFTypes.h"
|
||||
#include "modules/Materials.h"
|
||||
#include "DFHackAPI_C.h"
|
||||
|
||||
using namespace DFHack;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DFHACK_EXPORT int Materials_ReadInorganicMaterials(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_ReadOrganicMaterials(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_ReadWoodMaterials(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_ReadPlantMaterials(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_ReadCreatureTypes(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_ReadCreatureTypesEx(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_ReadDescriptorColors(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_ReadOthers(DFHackObject* mat);
|
||||
|
||||
DFHACK_EXPORT void Materials_ReadAllMaterials(DFHackObject* mat);
|
||||
|
||||
DFHACK_EXPORT const char* Materials_getDescription(DFHackObject* mat, t_material* material);
|
||||
|
||||
DFHACK_EXPORT int Materials_getInorganicSize(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_getOrganicSize(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_getTreeSize(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_getPlantSize(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_getRaceSize(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_getRaceExSize(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_getColorSize(DFHackObject* mat);
|
||||
DFHACK_EXPORT int Materials_getOtherSize(DFHackObject* mat);
|
||||
|
||||
DFHACK_EXPORT int Materials_getInorganic(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int));
|
||||
DFHACK_EXPORT int Materials_getOrganic(DFHackObject* mat, void* (*t_matgloss_buffer_create)( int));
|
||||
DFHACK_EXPORT int Materials_getTree(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int));
|
||||
DFHACK_EXPORT int Materials_getPlant(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int));
|
||||
DFHACK_EXPORT int Materials_getRace(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int));
|
||||
// DFHACK_EXPORT int Materials_getRaceEx(DFHackObject* mat, t_creaturetype* (*t_creaturetype_buffer_create)(int));
|
||||
DFHACK_EXPORT int Materials_getColor(DFHackObject* mat, void* (*t_descriptor_color_buffer_create)(int));
|
||||
DFHACK_EXPORT int Materials_getOther(DFHackObject* mat, void* (*t_matglossOther_buffer_create)(int));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,412 @@
|
||||
/*
|
||||
www.sourceforge.net/projects/dfhack
|
||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product documentation
|
||||
would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and
|
||||
must not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*/
|
||||
|
||||
#include "integers.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "DFCommonInternal.h"
|
||||
#include "modules/Materials.h"
|
||||
#include "modules/Materials_C.h"
|
||||
|
||||
using namespace DFHack;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int Materials_ReadInorganicMaterials(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->ReadInorganicMaterials();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_ReadOrganicMaterials(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->ReadOrganicMaterials();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_ReadWoodMaterials(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->ReadWoodMaterials();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_ReadPlantMaterials(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->ReadPlantMaterials();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_ReadCreatureTypes(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->ReadCreatureTypes();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_ReadCreatureTypesEx(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->ReadCreatureTypesEx();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_ReadDescriptorColors(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->ReadDescriptorColors();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_ReadOthers(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->ReadOthers();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Materials_ReadAllMaterials(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
((DFHack::Materials*)mat)->ReadAllMaterials();
|
||||
}
|
||||
}
|
||||
|
||||
const char* Materials_getDescription(DFHackObject* mat, t_material* material)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
std::string description = ((DFHack::Materials*)mat)->getDescription(*material);
|
||||
|
||||
return description.c_str();
|
||||
}
|
||||
|
||||
return "\0";
|
||||
}
|
||||
|
||||
//vector size getters
|
||||
|
||||
int Materials_getInorganicSize(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->inorganic.size();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_getOrganicSize(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->organic.size();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_getTreeSize(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->tree.size();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_getPlantSize(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->plant.size();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_getRaceSize(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->race.size();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_getRaceExSize(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->raceEx.size();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_getColorSize(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->color.size();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_getOtherSize(DFHackObject* mat)
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
return ((DFHack::Materials*)mat)->other.size();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//vector getters
|
||||
|
||||
int Materials_getInorganic(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int))
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
DFHack::Materials* materials = (DFHack::Materials*)mat;
|
||||
|
||||
if(materials->inorganic.size() > 0)
|
||||
{
|
||||
t_matgloss* buf = (t_matgloss*)((*t_matgloss_buffer_create)(materials->inorganic.size()));
|
||||
|
||||
if(buf != NULL)
|
||||
{
|
||||
copy(materials->inorganic.begin(), materials->inorganic.end(), buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_getOrganic(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int))
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
DFHack::Materials* materials = (DFHack::Materials*)mat;
|
||||
|
||||
if(materials->organic.size() > 0)
|
||||
{
|
||||
t_matgloss* buf = (t_matgloss*)((*t_matgloss_buffer_create)(materials->organic.size()));
|
||||
|
||||
if(buf != NULL)
|
||||
{
|
||||
copy(materials->organic.begin(), materials->organic.end(), buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_getTree(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int))
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
DFHack::Materials* materials = (DFHack::Materials*)mat;
|
||||
|
||||
if(materials->tree.size() > 0)
|
||||
{
|
||||
t_matgloss* buf = (t_matgloss*)((*t_matgloss_buffer_create)(materials->tree.size()));
|
||||
|
||||
if(buf != NULL)
|
||||
{
|
||||
copy(materials->tree.begin(), materials->tree.end(), buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_getPlant(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int))
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
DFHack::Materials* materials = (DFHack::Materials*)mat;
|
||||
|
||||
if(materials->plant.size() > 0)
|
||||
{
|
||||
t_matgloss* buf = (t_matgloss*)((*t_matgloss_buffer_create)(materials->plant.size()));
|
||||
|
||||
if(buf != NULL)
|
||||
{
|
||||
copy(materials->plant.begin(), materials->plant.end(), buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_getRace(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int))
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
DFHack::Materials* materials = (DFHack::Materials*)mat;
|
||||
|
||||
if(materials->race.size() > 0)
|
||||
{
|
||||
t_matgloss* buf = (t_matgloss*)((*t_matgloss_buffer_create)(materials->race.size()));
|
||||
|
||||
if(buf != NULL)
|
||||
{
|
||||
copy(materials->race.begin(), materials->race.end(), buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//race_ex getter goes here...
|
||||
|
||||
int Materials_getColor(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int))
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
DFHack::Materials* materials = (DFHack::Materials*)mat;
|
||||
|
||||
if(materials->color.size() > 0)
|
||||
{
|
||||
t_descriptor_color* buf = (t_descriptor_color*)((*t_matgloss_buffer_create)(materials->color.size()));
|
||||
|
||||
if(buf != NULL)
|
||||
{
|
||||
copy(materials->color.begin(), materials->color.end(), buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Materials_getOther(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int))
|
||||
{
|
||||
if(mat != NULL)
|
||||
{
|
||||
DFHack::Materials* materials = (DFHack::Materials*)mat;
|
||||
|
||||
if(materials->other.size() > 0)
|
||||
{
|
||||
t_matglossOther* buf = (t_matglossOther*)((*t_matgloss_buffer_create)(materials->other.size()));
|
||||
|
||||
if(buf != NULL)
|
||||
{
|
||||
copy(materials->other.begin(), materials->other.end(), buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue